aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-10-19 16:19:18 +0800
committerPo Lu2023-10-19 16:19:36 +0800
commite84e0cfb38282921eadbf0e4a1e08466ab787235 (patch)
tree32bf4b20c4a3273fd10c663f215fde4a2d491f7c /java
parent77755706f086ac3d8d1fc560aee4a29e0fb64c77 (diff)
downloademacs-e84e0cfb38282921eadbf0e4a1e08466ab787235.tar.gz
emacs-e84e0cfb38282921eadbf0e4a1e08466ab787235.zip
Relay body and attachments within Android e-mails to message-mailto
* java/org/gnu/emacs/EmacsOpenActivity.java (onCreate): Infer e-mail body and subject from its parameters and convey this information to message-mailto. * lisp/gnus/message.el (message-mailto): New arguments SUBJECT, BODY and FILE-ATTACHMENTS. (message-mailto-1): Insert these arguments as appropriate.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsOpenActivity.java116
1 files changed, 114 insertions, 2 deletions
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java b/java/org/gnu/emacs/EmacsOpenActivity.java
index 202b3c8c5dc..0c0da6acd1f 100644
--- a/java/org/gnu/emacs/EmacsOpenActivity.java
+++ b/java/org/gnu/emacs/EmacsOpenActivity.java
@@ -55,6 +55,7 @@ import android.net.Uri;
55import android.os.Build; 55import android.os.Build;
56import android.os.Bundle; 56import android.os.Bundle;
57import android.os.ParcelFileDescriptor; 57import android.os.ParcelFileDescriptor;
58import android.os.Parcelable;
58 59
59import android.util.Log; 60import android.util.Log;
60 61
@@ -67,6 +68,8 @@ import java.io.IOException;
67import java.io.InputStream; 68import java.io.InputStream;
68import java.io.UnsupportedEncodingException; 69import java.io.UnsupportedEncodingException;
69 70
71import java.util.List;
72
70public final class EmacsOpenActivity extends Activity 73public final class EmacsOpenActivity extends Activity
71 implements DialogInterface.OnClickListener, 74 implements DialogInterface.OnClickListener,
72 DialogInterface.OnCancelListener 75 DialogInterface.OnCancelListener
@@ -396,6 +399,7 @@ public final class EmacsOpenActivity extends Activity
396 Finally, display any error message, transfer the focus to an 399 Finally, display any error message, transfer the focus to an
397 Emacs frame, and finish the activity. */ 400 Emacs frame, and finish the activity. */
398 401
402 @SuppressWarnings ("deprecation") /* getParcelableExtra */
399 @Override 403 @Override
400 public void 404 public void
401 onCreate (Bundle savedInstanceState) 405 onCreate (Bundle savedInstanceState)
@@ -407,6 +411,11 @@ public final class EmacsOpenActivity extends Activity
407 ParcelFileDescriptor fd; 411 ParcelFileDescriptor fd;
408 byte[] names; 412 byte[] names;
409 String errorBlurb, scheme; 413 String errorBlurb, scheme;
414 String subjectString, textString, attachmentString;
415 CharSequence tem;
416 String tem1;
417 StringBuilder builder;
418 List<Parcelable> list;
410 419
411 super.onCreate (savedInstanceState); 420 super.onCreate (savedInstanceState);
412 421
@@ -425,6 +434,7 @@ public final class EmacsOpenActivity extends Activity
425 if (action.equals ("android.intent.action.VIEW") 434 if (action.equals ("android.intent.action.VIEW")
426 || action.equals ("android.intent.action.EDIT") 435 || action.equals ("android.intent.action.EDIT")
427 || action.equals ("android.intent.action.PICK") 436 || action.equals ("android.intent.action.PICK")
437 || action.equals ("android.intent.action.SEND")
428 || action.equals ("android.intent.action.SENDTO")) 438 || action.equals ("android.intent.action.SENDTO"))
429 { 439 {
430 /* Obtain the URI of the action. */ 440 /* Obtain the URI of the action. */
@@ -452,8 +462,110 @@ public final class EmacsOpenActivity extends Activity
452 /* Escape the special characters $ and " before enclosing 462 /* Escape the special characters $ and " before enclosing
453 the string within the `message-mailto' wrapper. */ 463 the string within the `message-mailto' wrapper. */
454 fileName = uri.toString (); 464 fileName = uri.toString ();
455 fileName.replace ("\"", "\\\"").replace ("$", "\\$"); 465 fileName = (fileName
456 fileName = "(message-mailto \"" + fileName + "\")"; 466 .replace ("\\", "\\\\")
467 .replace ("\"", "\\\"")
468 .replace ("$", "\\$"));
469 fileName = "(message-mailto \"" + fileName + "\" ";
470
471 /* Parse the intent itself to ascertain if any
472 non-standard subject, body, or something else of the
473 like is set. Such fields, non-standard as they are,
474 yield to fields provided within the URL itself; refer
475 to message-mailto. */
476
477 textString = attachmentString = subjectString = "()";
478
479 tem = intent.getCharSequenceExtra (Intent.EXTRA_SUBJECT);
480
481 if (tem != null)
482 subjectString = ("\"" + (tem.toString ()
483 .replace ("\\", "\\\\")
484 .replace ("\"", "\\\"")
485 .replace ("$", "\\$"))
486 + "\" ");
487
488 tem = intent.getCharSequenceExtra (Intent.EXTRA_TEXT);
489
490 if (tem != null)
491 textString = ("\"" + (tem.toString ()
492 .replace ("\\", "\\\\")
493 .replace ("\"", "\\\"")
494 .replace ("$", "\\$"))
495 + "\" ");
496
497 /* Producing a list of attachments is prey to two
498 mannerisms of the system: in the first instance, these
499 attachments are content URIs which don't allude to
500 their content types; and in the second instance, they
501 are either a list of such URIs or one individual URI,
502 subject to the type of the intent itself. */
503
504 if (Intent.ACTION_SEND.equals (action))
505 {
506 /* The attachment in this case is a single content
507 URI. */
508
509 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
510 uri = intent.getParcelableExtra (Intent.EXTRA_STREAM,
511 Uri.class);
512 else
513 uri = intent.getParcelableExtra (Intent.EXTRA_STREAM);
514
515 if (uri != null
516 && (scheme = uri.getScheme ()) != null
517 && scheme.equals ("content"))
518 {
519 tem1 = EmacsService.buildContentName (uri);
520 attachmentString = ("'(\"" + (tem1.replace ("\\", "\\\\")
521 .replace ("\"", "\\\"")
522 .replace ("$", "\\$"))
523 + "\")");
524 }
525 }
526 else
527 {
528 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
529 list
530 = intent.getParcelableArrayListExtra (Intent.EXTRA_STREAM,
531 Parcelable.class);
532 else
533 list
534 = intent.getParcelableArrayListExtra (Intent.EXTRA_STREAM);
535
536 if (list != null)
537 {
538 builder = new StringBuilder ("'(");
539
540 for (Parcelable parcelable : list)
541 {
542 if (!(parcelable instanceof Uri))
543 continue;
544
545 uri = (Uri) parcelable;
546
547 if (uri != null
548 && (scheme = uri.getScheme ()) != null
549 && scheme.equals ("content"))
550 {
551 tem1 = EmacsService.buildContentName (uri);
552 builder.append ("\"");
553 builder.append (tem1.replace ("\\", "\\\\")
554 .replace ("\"", "\\\"")
555 .replace ("$", "\\$"));
556 builder.append ("\"");
557 }
558 }
559
560 builder.append (")");
561 attachmentString = builder.toString ();
562 }
563 }
564
565 fileName += subjectString;
566 fileName += textString;
567 fileName += attachmentString;
568 fileName += ")";
457 569
458 /* Execute emacsclient in order to execute this code. */ 570 /* Execute emacsclient in order to execute this code. */
459 currentActivity = this; 571 currentActivity = this;