[Zope] question on simple_send in MailHost

Andreas Jung lists at zopyx.com
Mon Jul 17 05:42:35 EDT 2006


Put this in the bugtracker...otherwise it will be lost.

-aj

--On 17. Juli 2006 11:29:07 +0200 knitti <knitti at gmail.com> wrote:

> On 7/17/06, John Schinnerer <john at eco-living.net> wrote:
>> The Zope (2.7.5) API docs for MailHost show this for simple_send:
>>
>> --------------
>> simple_send(self, mto, mfrom, subject, body):
>>
>>      Sends a message. Only To:, From: and Subject: headers can be set.
>> The arguments are:
>>
>>      mto
>>          A commaseparated string or list of recipient(s) of the message.
>>      mfrom
>>          The address of the message sender.
>>      subject
>>          The subject of the message.
>>      body
>>          The body of the message.
>> --------------
>
> a bit digging in the code on one of my installations (2.7.4) revealed,
> that Zope more or less directly invokes  SMTP.sendmail from smtplib
> of python. quote from the docs: "a list of RFC 822 to-address strings
> (a bare string will be treated as a list with 1 address)"
>
> this seems a small bug in zope (either implementation or
> documentation). for a fix, make the list yourself:
>
> yourstring.split(',')
>
> this _could_ break the RFC-conformity of the to-header of the message,
> because simple_send builds the body of the message like this:
>
> body="From: %s\nTo: %s\nSubject: %s\n\n%s" \
>         % (mfrom, mto, subject, body)
>
> which would result in
>
> To: ['me at mine.com','you at yours.com','him at his.com']
>
> which makes the message unroutable.
>
> I suggest this code for MailBase.simple_send() (Malhost.py):
>
> import types # this belongs into the import section
>
> [.. snip, in simple_send: ..]
>
> def simple_send(self, mto, mfrom, subject, body):
>     if type(mto)==types.ListType:
>         body = "From: %s\nTo: %s\nSubject: %s\n\n%s" \
>                 % (mfrom, ','.join(mto), subject, body)
>     else:
>         body = "From: %s\nTo: %s\nSubject: %s\n\n%s" \
>                 % (mfrom, mto, subject, body)
>     self._send(mfrom, mto, body)
>
> and change the documentation to accept lists and strings,
> because parsing a comma-separated list of true rfc-822
> addresses is far more complicarted than somestring.split(',')
>
> --knitti
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )



-- 
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: info at zopyx.com - Phone +49 - 7071 - 793376
E-Publishing, Python, Zope & Plone development, Consulting
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope/attachments/20060717/cdb09905/attachment.bin


More information about the Zope mailing list