Defect #30785

Mail handler does not ignore emails sent from emission email address if Setting.mail_from includes display name

Added by Go MAEDA 11 months ago. Updated 11 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Email receiving
Target version:4.0.2
Resolution:Fixed Affected version:

Description

According to the comment at source:tags/4.0.1/app/models/mail_handler.rb#L93, mail handler is supposed to ignore emails sent from emission email address (Setting.mail_from). It behaves as expected if Setting.mail_from only includes an email address like "". However, it does not ignore the emails if Setting.mail_from includes a display name like "Joe Bloggs <>". The reason is that the code at source:tags/4.0.1/app/models/mail_handler.rb#L94 don't assume the format other than "".

  • OK: joe@example.com
  • NG: <joe@example.com>
  • NG: Joe Bloggs <joe@example.com>
  • NG: joe@example.com (Joe Bloggs)

30785-fix.diff Magnifier (2.05 KB) Go MAEDA, 2019-02-12 13:06

30785-fix-v2.patch Magnifier (1.92 KB) Go MAEDA, 2019-02-17 06:01


Related issues

Related to Redmine - Defect #14792: Don't add a display name and extra angle brackets in List... Closed

Associated revisions

Revision 17862
Added by Go MAEDA 11 months ago

Fix: Mail handler does not ignore emails sent from emission email address if Setting.mail_from includes display name (#30785).

Patch by Go MAEDA.

Revision 17863
Added by Go MAEDA 11 months ago

Merged r17862 from trunk to 4.0-stable (#30785).

Revision 17878
Added by Go MAEDA 11 months ago

Reverts r17862.

Revision 17879
Added by Go MAEDA 11 months ago

Mail handler does not ignore emails sent from emission email address if Setting.mail_from includes display name (#30785).

Patch by Go MAEDA.

Revision 17880
Added by Go MAEDA 11 months ago

Merged r17878 and r17879 from trunk to 4.0-stable (#30785).

History

#1 Updated by Go MAEDA 11 months ago

  • Related to Defect #14792: Don't add a display name and extra angle brackets in List-Id header field added

#2 Updated by Go MAEDA 11 months ago

This fix works for ordinary email addresses.

Index: app/models/mail_handler.rb
===================================================================
--- app/models/mail_handler.rb    (revision 17853)
+++ app/models/mail_handler.rb    (working copy)
@@ -91,7 +91,7 @@
     @handler_options = options
     sender_email = email.from.to_a.first.to_s.strip
     # Ignore emails received from the application emission address to avoid hell cycles
-    if sender_email.casecmp(Setting.mail_from.to_s.strip) == 0
+    if sender_email.casecmp(Setting.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\)|\s)/, '')) == 0
       if logger
         logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" 
       end

#3 Updated by Go MAEDA 11 months ago

  • File 30785-fix.diff added

Here is a patch to fix this issue.

The patch adds a new method Setting.mail_from_addess to extract an email address from the value of Setting.mail_from. I think it is useful to fix #14792 and implement #5913.

#4 Updated by Go MAEDA 11 months ago

  • File deleted (30785-fix.diff)

#5 Updated by Go MAEDA 11 months ago

#6 Updated by Go MAEDA 11 months ago

  • Target version set to 4.0.2

Setting the target version to 4.0.2.

#7 Updated by Go MAEDA 11 months ago

  • Subject changed from Mail handler may not ignore emails sent from emission email address to Mail handler does not ignore emails sent from emission email address if Setting.mail_from includes display name
  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed.

#8 Updated by Go MAEDA 11 months ago

  • Status changed from Resolved to Closed

#9 Updated by Go MAEDA 11 months ago

  • Status changed from Closed to Reopened

Go MAEDA wrote:

The patch adds a new method Setting.mail_from_addess to extract an email address from the value of Setting.mail_from. I think it is useful to fix #14792 and implement #5913.

#5913 and #14792 have been fixed without using newly added Setting.mail_from_addess method. Only MailHandler#receive uses the method now and I don't think other methods will use it in the future.

Therefore, I think r17862 should be reverted before releasing Redmine 4.0.2 and this issue should be fixed like the following:

diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 9298e1b12..aed977bbd 100755
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -91,7 +91,7 @@ class MailHandler < ActionMailer::Base
     @handler_options = options
     sender_email = email.from.to_a.first.to_s.strip
     # Ignore emails received from the application emission address to avoid hell cycles
-    if sender_email.casecmp(Setting.mail_from.to_s.strip) == 0
+    if sender_email.casecmp(Setting.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\))/, '').strip) == 0
       if logger
         logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" 
       end

#10 Updated by Go MAEDA 11 months ago

Go MAEDA wrote:

Therefore, I think r17862 should be reverted before releasing Redmine 4.0.2 and this issue should be fixed like the following:

[...]

Attaching a new patch. This patch can be applied after reverting r17862.

#11 Updated by Go MAEDA 11 months ago

  • Status changed from Reopened to Closed

Reverted r17862 and applied the new patch in r17879.

Also available in: Atom PDF