プロジェクト

全般

プロフィール

Vote #79827

完了

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

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Email receiving_29
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
29
version_id:
146
issue_org_id:
30785
author_id:
332
assigned_to_id:
332
comments:
11
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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 "joe@example.com". However, it does not ignore the emails if @Setting.mail_from@ includes a display name like "Joe Bloggs joe@example.com". 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 "joe@example.com".

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

journals

--------------------------------------------------------------------------------
This fix works for ordinary email addresses.

<pre><code class="diff">
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
</code></pre>
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Setting the target version to 4.0.2.
--------------------------------------------------------------------------------
Committed.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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:

<pre><code class="diff">
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
</code></pre>
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Reverted r17862 and applied the new patch in r17879.
--------------------------------------------------------------------------------


related_issues

relates,Closed,14792,Don't add a display name and extra angle brackets in List-Id header field

Admin Redmine さんが4年以上前に更新

  • カテゴリEmail receiving_29 にセット
  • 対象バージョン4.0.2_146 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0