From 1075cbf0535360fb10ad483355f057da16f233bb Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea@codelabs.ru>
Date: Tue, 26 Feb 2008 18:44:13 +0300
Subject: [PATCH] mail/sendmail.py: new option 'expand_to' for sendmail() routine.

This option, when set to True, instructs sendmail() to put the
actual recipient list to the To: field of the sent mail messages.
Default behaviour was to put sender's e-mail and it is preserved
for the compatibility.

The need for this modification is simple: modern spam filters,
mailing lists and mail clients are very unhappy when message has
implicit destination.  For example, Mailman software holds such
messages for moderator approval even if the envelope sender is
whitelisted.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
---
 MoinMoin/PageEditor.py         |    3 ++-
 MoinMoin/config/multiconfig.py |    3 ++-
 MoinMoin/mail/sendmail.py      |    8 +++++++-
 wiki/config/wikiconfig.py      |    5 +++++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/MoinMoin/PageEditor.py b/MoinMoin/PageEditor.py
index 38704c5..ec7e8a7 100644
--- a/MoinMoin/PageEditor.py
+++ b/MoinMoin/PageEditor.py
@@ -752,7 +752,8 @@ Try a different name.""", formatted=True, percent=True) % (wikiutil.escape(newpa
                 'pagename': self.page_name,
                 'username': self.uid_override or user.getUserIdentification(request),
             },
-            mailBody, mail_from=self.cfg.mail_from)
+            mailBody, mail_from=self.cfg.mail_from,
+            expand_to=self.cfg.mail_expand_to)
 
 
     def _notifySubscribers(self, comment, trivial):
diff --git a/MoinMoin/config/multiconfig.py b/MoinMoin/config/multiconfig.py
index 52fc17f..f0da526 100644
--- a/MoinMoin/config/multiconfig.py
+++ b/MoinMoin/config/multiconfig.py
@@ -367,7 +367,8 @@ Lists: * bullets; 1., a. numbered items.
     mail_sendmail = None # "/usr/sbin/sendmail -t -i" to not use SMTP, but sendmail
     mail_smarthost = None
     mail_from = None # u'Juergen Wiki <noreply@jhwiki.org>'
-
+    mail_expand_to = False # set to True if you want all recipients to be listed in To: field
+ 
     mail_import_subpage_template = u"$from-$date-$subject" # used for mail import
     mail_import_pagename_search = ['subject', 'to', ] # where to look for target pagename (and in which order)
     mail_import_pagename_envelope = u"%s" # use u"+ %s/" to add "+ " and "/" automatically
diff --git a/MoinMoin/mail/sendmail.py b/MoinMoin/mail/sendmail.py
index e13d32a..d4a37cf 100644
--- a/MoinMoin/mail/sendmail.py
+++ b/MoinMoin/mail/sendmail.py
@@ -49,6 +49,8 @@ def sendmail(request, to, subject, text, **kw):
     @param text: email body text (unicode)
     @keyword mail_from: override default mail_from
     @type mail_from: unicode
+    @keyword expand_to: specify all recipients in the 'To' field
+    @type expand_to: bool
     @rtype: tuple
     @return: (is_ok, Description of error or OK message)
     """
@@ -60,6 +62,7 @@ def sendmail(request, to, subject, text, **kw):
     _ = request.getText
     cfg = request.cfg
     mail_from = kw.get('mail_from', '') or cfg.mail_from
+    expand_to = kw.get('expand_to', False)
     subject = subject.encode(config.charset)
 
     # Create a text/plain body using CRLF (see RFC2822)
@@ -87,7 +90,10 @@ def sendmail(request, to, subject, text, **kw):
     # use the same mail_from, e.g. u"Jürgen Wiki <noreply@mywiki.org>"
     address = encodeAddress(mail_from, charset)
     msg['From'] = address
-    msg['To'] = address
+    if (expand_to == False):
+        msg['To'] = address
+    else:
+        msg['To'] = ", ".join(encodeAddress(i, charset) for i in to)
     msg['Date'] = formatdate()
     msg['Message-ID'] = make_msgid()
     msg['Subject'] = Header(subject, charset)
diff --git a/wiki/config/wikiconfig.py b/wiki/config/wikiconfig.py
index cd47441..15c5cd8 100644
--- a/wiki/config/wikiconfig.py
+++ b/wiki/config/wikiconfig.py
@@ -118,6 +118,11 @@ class Config(DefaultConfig):
 
     # "user pwd" if you need to use SMTP AUTH
     #mail_login = ""
+ 
+    # Specify all message recipients in the To: field?  It is useful
+    # if destination mail reader wants explicit message recipient(s).
+    # Default is to use 'mail_from' as a To: field contents.
+    #mail_expand_to = False
 
 
     # User interface ----------------------------------------------------
-- 
1.5.5.3

