summaryrefslogtreecommitdiff
path: root/java/org/gnu/emacs/EmacsOpenActivity.java
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2023-10-19 16:19:18 +0800
committerPo Lu <luangruo@yahoo.com>2023-10-19 16:19:36 +0800
commite84e0cfb38282921eadbf0e4a1e08466ab787235 (patch)
tree32bf4b20c4a3273fd10c663f215fde4a2d491f7c /java/org/gnu/emacs/EmacsOpenActivity.java
parent77755706f086ac3d8d1fc560aee4a29e0fb64c77 (diff)
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/org/gnu/emacs/EmacsOpenActivity.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;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
+import android.os.Parcelable;
import android.util.Log;
@@ -67,6 +68,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.util.List;
+
public final class EmacsOpenActivity extends Activity
implements DialogInterface.OnClickListener,
DialogInterface.OnCancelListener
@@ -396,6 +399,7 @@ public final class EmacsOpenActivity extends Activity
Finally, display any error message, transfer the focus to an
Emacs frame, and finish the activity. */
+ @SuppressWarnings ("deprecation") /* getParcelableExtra */
@Override
public void
onCreate (Bundle savedInstanceState)
@@ -407,6 +411,11 @@ public final class EmacsOpenActivity extends Activity
ParcelFileDescriptor fd;
byte[] names;
String errorBlurb, scheme;
+ String subjectString, textString, attachmentString;
+ CharSequence tem;
+ String tem1;
+ StringBuilder builder;
+ List<Parcelable> list;
super.onCreate (savedInstanceState);
@@ -425,6 +434,7 @@ public final class EmacsOpenActivity extends Activity
if (action.equals ("android.intent.action.VIEW")
|| action.equals ("android.intent.action.EDIT")
|| action.equals ("android.intent.action.PICK")
+ || action.equals ("android.intent.action.SEND")
|| action.equals ("android.intent.action.SENDTO"))
{
/* Obtain the URI of the action. */
@@ -452,8 +462,110 @@ public final class EmacsOpenActivity extends Activity
/* Escape the special characters $ and " before enclosing
the string within the `message-mailto' wrapper. */
fileName = uri.toString ();
- fileName.replace ("\"", "\\\"").replace ("$", "\\$");
- fileName = "(message-mailto \"" + fileName + "\")";
+ fileName = (fileName
+ .replace ("\\", "\\\\")
+ .replace ("\"", "\\\"")
+ .replace ("$", "\\$"));
+ fileName = "(message-mailto \"" + fileName + "\" ";
+
+ /* Parse the intent itself to ascertain if any
+ non-standard subject, body, or something else of the
+ like is set. Such fields, non-standard as they are,
+ yield to fields provided within the URL itself; refer
+ to message-mailto. */
+
+ textString = attachmentString = subjectString = "()";
+
+ tem = intent.getCharSequenceExtra (Intent.EXTRA_SUBJECT);
+
+ if (tem != null)
+ subjectString = ("\"" + (tem.toString ()
+ .replace ("\\", "\\\\")
+ .replace ("\"", "\\\"")
+ .replace ("$", "\\$"))
+ + "\" ");
+
+ tem = intent.getCharSequenceExtra (Intent.EXTRA_TEXT);
+
+ if (tem != null)
+ textString = ("\"" + (tem.toString ()
+ .replace ("\\", "\\\\")
+ .replace ("\"", "\\\"")
+ .replace ("$", "\\$"))
+ + "\" ");
+
+ /* Producing a list of attachments is prey to two
+ mannerisms of the system: in the first instance, these
+ attachments are content URIs which don't allude to
+ their content types; and in the second instance, they
+ are either a list of such URIs or one individual URI,
+ subject to the type of the intent itself. */
+
+ if (Intent.ACTION_SEND.equals (action))
+ {
+ /* The attachment in this case is a single content
+ URI. */
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
+ uri = intent.getParcelableExtra (Intent.EXTRA_STREAM,
+ Uri.class);
+ else
+ uri = intent.getParcelableExtra (Intent.EXTRA_STREAM);
+
+ if (uri != null
+ && (scheme = uri.getScheme ()) != null
+ && scheme.equals ("content"))
+ {
+ tem1 = EmacsService.buildContentName (uri);
+ attachmentString = ("'(\"" + (tem1.replace ("\\", "\\\\")
+ .replace ("\"", "\\\"")
+ .replace ("$", "\\$"))
+ + "\")");
+ }
+ }
+ else
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
+ list
+ = intent.getParcelableArrayListExtra (Intent.EXTRA_STREAM,
+ Parcelable.class);
+ else
+ list
+ = intent.getParcelableArrayListExtra (Intent.EXTRA_STREAM);
+
+ if (list != null)
+ {
+ builder = new StringBuilder ("'(");
+
+ for (Parcelable parcelable : list)
+ {
+ if (!(parcelable instanceof Uri))
+ continue;
+
+ uri = (Uri) parcelable;
+
+ if (uri != null
+ && (scheme = uri.getScheme ()) != null
+ && scheme.equals ("content"))
+ {
+ tem1 = EmacsService.buildContentName (uri);
+ builder.append ("\"");
+ builder.append (tem1.replace ("\\", "\\\\")
+ .replace ("\"", "\\\"")
+ .replace ("$", "\\$"));
+ builder.append ("\"");
+ }
+ }
+
+ builder.append (")");
+ attachmentString = builder.toString ();
+ }
+ }
+
+ fileName += subjectString;
+ fileName += textString;
+ fileName += attachmentString;
+ fileName += ")";
/* Execute emacsclient in order to execute this code. */
currentActivity = this;