tschoffelen / react-native-email-link

📭 Open an email client from React Native (for 'magic link' type functionality).
MIT License
412 stars 74 forks source link

Opening composer with Protonmail using URL scheme is not working anymore with 1.16.1 #142

Open jumantet opened 2 months ago

jumantet commented 2 months ago

here is the patch I made and which was working with the 1.15.0 version meaning, the openComposer was properly opening protonmail on compose view with all the options filled, now the protonmail opens well but not anymore the compose view. It is working well with all the other mail client.

Here is my patch :

diff --git a/node_modules/react-native-email-link/src/ios.js b/node_modules/react-native-email-link/src/ios.js
index 2e8d1ce..5ae3a75 100644
--- a/node_modules/react-native-email-link/src/ios.js
+++ b/node_modules/react-native-email-link/src/ios.js
@@ -40,6 +40,7 @@ const titles = {
  *  - airmail: https://help.airmailapp.com/en-us/article/airmail-ios-url-scheme-1q060gy/
  *  - outlook: https://stackoverflow.com/questions/32369198/i-just-want-to-open-ms-outlook-app-and-see-mailto-screen-using-url-scheme-at-ios
  *  - fastmail: https://github.com/vtourraine/ThirdPartyMailer/blob/1.8.0/Sources/ThirdPartyMailer/ThirdPartyMailClient.swift#L80
+ *  - protonmail: https://github.com/ProtonMail/ios-mail/issues/27  //MODIFICATION NM FOR PROTONMAIL
  */
 const uriParams = {
   "apple-mail": {
@@ -116,7 +117,11 @@ const uriParams = {
     body: "body",
   },
   protonmail: {
-    path: "compose",
+    to: "mailto",
+    subject: "subject",
+    body: "body",
+    cc: "cc",
+    bcc: "bcc",
   },
   seznamemail: {
     path: "mail",
@@ -135,15 +140,29 @@ const uriParams = {
  * }} options
  */
 function getUrlParams(app, options) {
-  const appParms = uriParams[app];
-  if (!appParms) {
+  const appParams = uriParams[app];
+  if (!appParams) {
     return "";
   }

-  const path = app === "apple-mail" ? options.to || "" : appParms.path;
-  const urlParams = Object.keys(appParms).reduce((params, currentParam) => {
+  const path = (app === "apple-mail") ? options.to || "" : (app === "protonmail") ? options.to && decodeURIComponent(options.to).trim().split(',')[0] || "" : appParams.path;
+
+  const urlParams = Object.keys(appParams).reduce((params, currentParam) => {
     if (options[currentParam]) {
-      params.push(`${appParms[currentParam]}=${options[currentParam]}`);
+      if (app === "protonmail") {
+        options[currentParam] = decodeURIComponent(options[currentParam]);
+        if (currentParam === "cc" && options.to && decodeURIComponent(options.to).trim().split(',').length > 1) {
+          options[currentParam] = options[currentParam] + "," + decodeURIComponent(options.to).trim().split(',').slice(1).join(',');
+        }
+        params.push(`${appParams[currentParam]}=${options[currentParam]}`);
+      } else {
+        params.push(`${appParams[currentParam]}=${options[currentParam]}`);
+      }
+    } else if (app === "protonmail" && currentParam === "cc") {
+      if (options.to && decodeURIComponent(options.to).trim().split(',').length > 1) {
+        options[currentParam] = decodeURIComponent(options.to).trim().split(',').slice(1).join(',');
+        params.push(`${appParams[currentParam]}=${options[currentParam]}`);
+      }
     }
     return params;
   }, []);
@@ -381,6 +400,9 @@ export async function openComposer(options) {
   if (app === "apple-mail") {
     // apple mail prefix to compose an email is mailto
     prefix = "mailto:";
+  } else if (app === "protonmail") {
+    // protonmail prefix to compose an email is protonmail://mailto
+    prefix = "protonmail://mailto:";
   }

   await Linking.openURL(`${prefix}${params}`);

I am using: "expo": "~51.0.31"

Is there somebody facing this new issue ?

Thanks

tschoffelen commented 2 months ago

Nice! Could you please open a pull request with this change? Happy to get it merged

pke commented 1 month ago

Is this because of a changed ProtonEmail client?

jumantet commented 1 month ago

@pke it could be indeed @tschoffelen actually it is not working anymore, that's why I open the issue :)

pke commented 1 month ago

@tschoffelen actually it is not working anymore, that's why I open the issue :)

What he meant, could you please create PR with this patch instead of posting the patch here in the issue?

jumantet commented 1 month ago

@pke but the patch is not working anymore, something should have changed in the protonmail client and wanted to know if someone who where using it is facing the same issue