Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jumantet opened this issue Aug 28, 2024 · 6 comments
Labels

Comments

@jumantet
Copy link

jumantet commented Aug 28, 2024

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
Copy link
Owner

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

@pke
Copy link
Contributor

pke commented Sep 24, 2024

Is this because of a changed ProtonEmail client?

@jumantet
Copy link
Author

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

@pke
Copy link
Contributor

pke commented Sep 25, 2024

@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
Copy link
Author

@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

Copy link

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants