email: Split sender into both sendmail's -F and -f
authorW. Trevor King <wking@tremily.us>
Thu, 17 Jul 2014 20:04:10 +0000 (13:04 -0700)
committerW. Trevor King <wking@tremily.us>
Mon, 1 Sep 2014 21:21:03 +0000 (14:21 -0700)
Use -F for the name and -f for the address, instead of passing the
composite "name <address>" to -f.  Only the address is used in the
SMTP envelope [1,2], so most mailers will probably ignore -F.  For
example, Postfix only uses it when there is no 'From' header in the
message itself [3].

The old behavior broke some sendmail implementation that assumed the
whole -f argument was an address (reportedly OpenSMTPD).  I haven't
noticed one of these sendmail implementions myself, but they'll create
envelope senders like:

  MAIL FROM:<"foobar <abc>" <foo@bar>>

when we only want:

  MAIL FROM:<foo@bar>

[1]: http://tools.ietf.org/html/rfc2821#section-3.3
[2]: http://tools.ietf.org/html/rfc2821#section-4.1.1.2
[3]: http://www.postfix.org/sendmail.1.html

Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/email.py

index bee9e0364f8b9c3a351267b4b5e6509b25c13e70..9972607f70fe7274016cffe1cf60f68528cb5136 100644 (file)
@@ -324,11 +324,12 @@ def sendmail_send(sender, recipient, message, config=None, section='DEFAULT'):
         config = _config.CONFIG
     message_bytes = _flatten(message)
     sendmail = config.get(section, 'sendmail')
+    sender_name,sender_addr = _parseaddr(sender)
     _LOG.debug(
         'sending message to {} via {}'.format(recipient, sendmail))
     try:
         p = _subprocess.Popen(
-            [sendmail, '-f', sender, recipient],
+            [sendmail, '-F', sender_name, '-f', sender_addr, recipient],
             stdin=_subprocess.PIPE, stdout=_subprocess.PIPE,
             stderr=_subprocess.PIPE)
         stdout,stderr = p.communicate(message_bytes)