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

Cypht: Warn the user when the number of email recipients exceeds the limit. #561

Conversation

NasserNgandu
Copy link
Contributor

…limit.

Pullrequest

Issues

  • None

Checklist

  • None

How2Test

  • None

Todo

  • None

@NasserNgandu
Copy link
Contributor Author

@NasserNgandu
Copy link
Contributor Author

The commit launches an alert if the number of recipients of an email exceeds 20, in the To, Cc and Bcc fields.

@NasserNgandu NasserNgandu changed the title Cypht: Warn the user when the number of email recipients exceeds the … Cypht: Warn the user when the number of email recipients exceeds the limit. Apr 22, 2022
@jasonmunro
Copy link
Member

Not sure I understand this PR - Why is 20 the limit?

@marclaporte
Copy link
Member

Here is context: #531

@jasonmunro
Copy link
Member

@NasserNgandu I appreciate you working on this but I think I want to solve this differently. I'm waiting for @marclaporte to confirm, but I believe we want this warning to trigger when you reply to a message or load a draft message, not when a user is typing in addresses. I came up with the following change that I think does what we want here. Also note that when you add notices in JavaScript they cannot be translated without some extra work, but adding notices from PHP is automatically translated.

diff --git a/modules/smtp/modules.php b/modules/smtp/modules.php
index 9f4ea132..32fbd122 100644
--- a/modules/smtp/modules.php
+++ b/modules/smtp/modules.php
@@ -8,6 +8,7 @@

 if (!defined('DEBUG_MODE')) { die(); }

+define('MAX_RECIPIENT_WARNING', 20);
 require APP_PATH.'modules/smtp/hm-smtp.php';
 require APP_PATH.'modules/smtp/hm-mime-message.php';

@@ -25,6 +26,7 @@ class Hm_Handler_load_smtp_reply_to_details extends Hm_Handler_Module {
             );
             $reply_details = $this->session->get($cache_name, false);
             if ($reply_details) {
+                recip_count_check($reply_details['msg_headers'], $this);
                 $this->out('reply_details', $reply_details);
             }
         }
@@ -94,6 +96,7 @@ class Hm_Handler_load_smtp_is_imap_draft extends Hm_Handler_Module {
                 }

                 if ($imap_draft) {
+                    recip_count_check($imap_draft, $this);
                     $this->out('draft_id', $this->request->get['uid']);
                     $this->out('imap_draft', $imap_draft);
                 }
@@ -1935,3 +1938,21 @@ function default_smtp_server($user_config, $session, $request, $config, $user, $
     $session->set('user_data', $user_data);
     Hm_Debug::add('Default SMTP server added');
 }}
+
+/**
+ * @subpackage smtp/functions
+ */
+if (!hm_exists('recip_count_check')) {
+function recip_count_check($headers, $omod) {
+    $headers = lc_headers($headers);
+    $recip_count = 0;
+    if (array_key_exists('to', $headers) && $headers['to']) {
+        $recip_count += count(process_address_fld($headers['to']));
+    }
+    if (array_key_exists('cc', $headers) && $headers['cc']) {
+        $recip_count += count(process_address_fld($headers['cc']));
+    }
+    if ($recip_count > MAX_RECIPIENT_WARNING) {
+        Hm_Msgs::add('ERRMessage contains more than the maximum number of recipients, proceed with caution');
+    }
+}}

@jasonmunro
Copy link
Member

I added the above so I'm closing this. Thanks again for working on it!

@jasonmunro jasonmunro closed this Jul 19, 2022
@NasserNgandu
Copy link
Contributor Author

OK. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants