Attachment '1.7.2-sendmail-expand-to.patch'

Download

   1 From e324e3d87cae19a0be8d5a03aef79bbca073fe82 Mon Sep 17 00:00:00 2001
   2 From: Eygene Ryabinkin <rea@codelabs.ru>
   3 Date: Mon, 15 Sep 2008 21:44:38 +0400
   4 Subject: [PATCH] mail/sendmail.py: new option 'expand_to' for sendmail() routine
   5 
   6 This option, when set to True, instructs sendmail() to put the
   7 actual recipient list to the To: field of the sent mail messages.
   8 Default behaviour was to put sender's e-mail and it is preserved
   9 for the compatibility.
  10 
  11 The need for this modification is simple: modern spam filters,
  12 mailing lists and mail clients are very unhappy when message has
  13 implicit destination.  For example, Mailman software holds such
  14 messages for moderator approval even if the envelope sender is
  15 whitelisted.
  16 
  17 Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
  18 ---
  19  MoinMoin/config/multiconfig.py |    1 +
  20  MoinMoin/events/emailnotify.py |   13 ++++++++-----
  21  MoinMoin/mail/sendmail.py      |    9 +++++++--
  22  MoinMoin/user.py               |    3 ++-
  23  wiki/config/wikiconfig.py      |    5 +++++
  24  5 files changed, 23 insertions(+), 8 deletions(-)
  25 
  26 diff --git a/MoinMoin/config/multiconfig.py b/MoinMoin/config/multiconfig.py
  27 index 6e8c6fd..80e27c1 100644
  28 --- a/MoinMoin/config/multiconfig.py
  29 +++ b/MoinMoin/config/multiconfig.py
  30 @@ -374,6 +374,7 @@ Lists: * bullets; 1., a. numbered items.
  31      log_timing = False # log infos about timing of actions, good to analyze load conditions
  32  
  33      mail_from = None # u'Juergen Wiki <noreply@jhwiki.org>'
  34 +    mail_expand_to = False # set to True if you want all recipients to be listed in To: field
  35      mail_login = None # "user pwd" if you need to use SMTP AUTH when using your mail server
  36      mail_smarthost = None # your SMTP mail server
  37      mail_sendmail = None # "/usr/sbin/sendmail -t -i" to not use SMTP, but sendmail
  38 diff --git a/MoinMoin/events/emailnotify.py b/MoinMoin/events/emailnotify.py
  39 index e757300..46925e4 100644
  40 --- a/MoinMoin/events/emailnotify.py
  41 +++ b/MoinMoin/events/emailnotify.py
  42 @@ -54,7 +54,7 @@ def prep_page_changed_mail(request, page, comment, email_lang, revisions, trivia
  43      return {'subject': subject, 'text': change['text'] + pagelink + change['diff']}
  44  
  45  
  46 -def send_notification(request, from_address, emails, data):
  47 +def send_notification(request, from_address, emails, data, expand_to):
  48      """ Send notification email
  49  
  50      @param emails: list of email addresses
  51 @@ -62,7 +62,7 @@ def send_notification(request, from_address, emails, data):
  52      @rtype int
  53  
  54      """
  55 -    return sendmail.sendmail(request, emails, data['subject'], data['text'], mail_from=from_address)
  56 +    return sendmail.sendmail(request, emails, data['subject'], data['text'], mail_from=from_address, expand_to=expand_to)
  57  
  58  
  59  def handle_page_change(event):
  60 @@ -79,6 +79,7 @@ def handle_page_change(event):
  61      trivial = isinstance(event, ev.TrivialPageChangedEvent)
  62      subscribers = page.getSubscribers(request, return_users=1)
  63      mail_from = page.cfg.mail_from
  64 +    expand_to = page.cfg.mail_expand_to
  65  
  66      if subscribers:
  67          recipients = set()
  68 @@ -94,7 +95,7 @@ def handle_page_change(event):
  69              names = [u.name for u in users]
  70              data = prep_page_changed_mail(request, page, comment, lang, revisions, trivial)
  71  
  72 -            if send_notification(request, mail_from, emails, data):
  73 +            if send_notification(request, mail_from, emails, data, expand_to):
  74                  recipients.update(names)
  75  
  76          if recipients:
  77 @@ -107,6 +108,7 @@ def handle_user_created(event):
  78      request = event.request
  79      sitename = request.cfg.sitename
  80      from_address = request.cfg.mail_from
  81 +    expand_to = request.cfg.mail_expand_to
  82      event_name = event.name
  83      email = event.user.email or u"NOT SET"
  84      username = event.user.name
  85 @@ -118,7 +120,7 @@ def handle_user_created(event):
  86          if usr.isSuperUser() and event_name in usr.email_subscribed_events:
  87              _ = lambda text: request.getText(text, lang=usr.language or 'en')
  88              data = notification.user_created_message(request, _, sitename, username, email)
  89 -            send_notification(request, from_address, [usr.email], data)
  90 +            send_notification(request, from_address, [usr.email], dat, expand_toa)
  91  
  92  
  93  def handle_file_attached(event):
  94 @@ -126,6 +128,7 @@ def handle_file_attached(event):
  95  
  96      names = set()
  97      from_address = event.request.cfg.mail_from
  98 +    expand_to = event.request.cfg.mail_expand_to
  99      request = event.request
 100      page = Page(request, event.pagename)
 101  
 102 @@ -151,7 +154,7 @@ def handle_file_attached(event):
 103  
 104          emails = [usr.email for usr in subscribers[lang]]
 105  
 106 -        if send_notification(request, from_address, emails, data):
 107 +        if send_notification(request, from_address, emails, data, expand_to):
 108              names.update(recipients)
 109  
 110      return notification.Success(names)
 111 diff --git a/MoinMoin/mail/sendmail.py b/MoinMoin/mail/sendmail.py
 112 index a3f7a0a..db07541 100644
 113 --- a/MoinMoin/mail/sendmail.py
 114 +++ b/MoinMoin/mail/sendmail.py
 115 @@ -43,7 +43,7 @@ def encodeAddress(address, charset):
 116          return address.encode(config.charset)
 117  
 118  
 119 -def sendmail(request, to, subject, text, mail_from=None):
 120 +def sendmail(request, to, subject, text, mail_from=None, expand_to=False):
 121      """ Create and send a text/plain message
 122  
 123      Return a tuple of success or error indicator and message.
 124 @@ -54,6 +54,8 @@ def sendmail(request, to, subject, text, mail_from=None):
 125      @param text: email body text (unicode)
 126      @param mail_from: override default mail_from
 127      @type mail_from: unicode
 128 +    @keyword expand_to: specify all recipients in the 'To' field
 129 +    @type expand_to: bool
 130      @rtype: tuple
 131      @return: (is_ok, Description of error or OK message)
 132      """
 133 @@ -92,7 +94,10 @@ def sendmail(request, to, subject, text, mail_from=None):
 134      # use the same mail_from, e.g. u"Jürgen Wiki <noreply@mywiki.org>"
 135      address = encodeAddress(mail_from, charset)
 136      msg['From'] = address
 137 -    msg['To'] = address
 138 +    if (expand_to == False):
 139 +        msg['To'] = address
 140 +    else:
 141 +        msg['To'] = ", ".join(encodeAddress(i, charset) for i in to)
 142      msg['Date'] = formatdate()
 143      msg['Message-ID'] = make_msgid()
 144      msg['Subject'] = Header(subject, charset)
 145 diff --git a/MoinMoin/user.py b/MoinMoin/user.py
 146 index 8d9918b..7ea37ee 100644
 147 --- a/MoinMoin/user.py
 148 +++ b/MoinMoin/user.py
 149 @@ -1089,6 +1089,7 @@ recovery token.
 150          subject = _('[%(sitename)s] Your wiki account data',
 151                  ) % {'sitename': self._cfg.sitename or "Wiki"}
 152          mailok, msg = sendmail.sendmail(self._request, [self.email], subject,
 153 -                                    text, mail_from=self._cfg.mail_from)
 154 +                                    text, mail_from=self._cfg.mail_from,
 155 +       	                            expand_to=self._cfg.mail_expand_to)
 156          return mailok, msg
 157  
 158 diff --git a/wiki/config/wikiconfig.py b/wiki/config/wikiconfig.py
 159 index 4befe7f..20b90f4 100644
 160 --- a/wiki/config/wikiconfig.py
 161 +++ b/wiki/config/wikiconfig.py
 162 @@ -119,6 +119,11 @@ class Config(DefaultConfig):
 163      # "user pwd" if you need to use SMTP AUTH
 164      #mail_login = ""
 165  
 166 +    # Specify all message recipients in the To: field?  It is useful
 167 +    # if destination mail reader wants explicit message recipient(s).
 168 +    # Default is to use 'mail_from' as a To: field contents.
 169 +    #mail_expand_to = False
 170 +
 171  
 172      # User interface ----------------------------------------------------
 173  
 174 -- 
 175 1.5.6.4

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-06-20 15:27:45, 4.3 KB) [[attachment:1.6.3-sendmail-expand-to.patch]]
  • [get | view] (2008-09-15 20:12:23, 7.3 KB) [[attachment:1.7.2-sendmail-expand-to.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.