Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
32ea42e1
Commit
32ea42e1
authored
Jan 05, 2010
by
Maurits van Rees
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed possible TypeError while sending multipart emails.
parent
e957ad47
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
10 deletions
+113
-10
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/Products/MailHost/MailHost.py
src/Products/MailHost/MailHost.py
+25
-10
src/Products/MailHost/tests/testMailHost.py
src/Products/MailHost/tests/testMailHost.py
+86
-0
No files found.
doc/CHANGES.rst
View file @
32ea42e1
...
@@ -11,6 +11,8 @@ Zope 2.12.3 (unreleased)
...
@@ -11,6 +11,8 @@ Zope 2.12.3 (unreleased)
Bugs Fixed
Bugs Fixed
++++++++++
++++++++++
- Fixed possible TypeError while sending multipart emails.
- Also look for ZEXP imports within the clienthome directory. This
- Also look for ZEXP imports within the clienthome directory. This
provides a place to put imports that won't be clobbered by buildout
provides a place to put imports that won't be clobbered by buildout
in a buildout-based Zope instance.
in a buildout-based Zope instance.
...
...
src/Products/MailHost/MailHost.py
View file @
32ea42e1
...
@@ -417,16 +417,31 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None,
...
@@ -417,16 +417,31 @@ def _mungeHeaders(messageText, mto=None, mfrom=None, subject=None,
# we don't use get_content_type because that has a default
# we don't use get_content_type because that has a default
# value of 'text/plain'
# value of 'text/plain'
mo.set_type(msg_type)
mo.set_type(msg_type)
charset_match = CHARSET_RE.search(mo['Content-Type'] or '')
if not mo.is_multipart():
if charset and not charset_match:
charset_match = CHARSET_RE.search(mo['Content-Type'] or '')
# Don't change the charset if already set
if charset and not charset_match:
# This encodes the payload automatically based on the default
# Don't change the charset if already set
# encoding for the charset
# This encodes the payload automatically based on the default
mo.set_charset(charset)
# encoding for the charset
elif charset_match and not charset:
mo.set_charset(charset)
# If a charset parameter was provided use it for header encoding below,
elif charset_match and not charset:
# Otherwise, try to use the charset provided in the message.
# If a charset parameter was provided use it for header encoding below,
charset = charset_match.groups()[0]
# Otherwise, try to use the charset provided in the message.
charset = charset_match.groups()[0]
else:
# Do basically the same for each payload as for the complete
# multipart message.
for index, payload in enumerate(mo.get_payload()):
if not isinstance(payload, Message):
payload = message_from_string(payload)
charset_match = CHARSET_RE.search(payload['Content-Type'] or '')
if payload.get_filename() is None:
# No binary file
if charset and not charset_match:
payload.set_charset(charset)
elif charset_match and not charset:
charset = charset_match.groups()[0]
mo.get_payload()[index] = payload
# Parameters given will *always* override headers in the messageText.
# Parameters given will *always* override headers in the messageText.
# This is so that you can't override or add to subscribers by adding
# This is so that you can't override or add to subscribers by adding
...
...
src/Products/MailHost/tests/testMailHost.py
View file @
32ea42e1
...
@@ -518,6 +518,92 @@ A M\xc3\xa9ssage""")
...
@@ -518,6 +518,92 @@ A M\xc3\xa9ssage""")
statusTemplate
=
'check_status'
)
statusTemplate
=
'check_status'
)
self
.
failUnlessEqual
(
result
,
'Message Sent'
)
self
.
failUnlessEqual
(
result
,
'Message Sent'
)
def
testSendMultiPartAlternativeMessage
(
self
):
msg
=
(
"""
\
Content-Type: multipart/alternative; boundary="===============0490954888=="
MIME-Version: 1.0
Date: Sun, 27 Aug 2006 17:00:00 +0200
Subject: My multipart email
To: Foo Bar <foo@domain.com>
From: sender@domain.com
--===============0490954888==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
This is plain text.
--===============0490954888==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
<p>This is html.</p>
--===============0490954888==--
"""
)
mailhost
=
self
.
_makeOne
(
'MailHost'
)
# Specifying a charset for the header may have unwanted side
# effects in the case of multipart mails.
# (TypeError: expected string or buffer)
mailhost
.
send
(
msg
,
charset
=
'utf-8'
)
self
.
assertEqual
(
mailhost
.
sent
,
msg
)
def
testSendMultiPartMixedMessage
(
self
):
msg
=
(
"""
\
Content-Type: multipart/mixed; boundary="XOIedfhf+7KOe/yw"
Content-Disposition: inline
MIME-Version: 1.0
Date: Sun, 27 Aug 2006 17:00:00 +0200
Subject: My multipart email
To: Foo Bar <foo@domain.com>
From: sender@domain.com
--XOIedfhf+7KOe/yw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
This is a test with as attachment OFS/www/new.gif.
--XOIedfhf+7KOe/yw
Content-Type: image/gif
Content-Disposition: attachment; filename="new.gif"
Content-Transfer-Encoding: base64
R0lGODlhCwAQAPcAAP8A/wAAAFBQUICAgMDAwP8AAIAAQAAAoABAgIAAgEAAQP//AP//gACA
gECAgP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAALABAAAAg7AAEIFKhgoEGC
CwoeRKhwoYKEBhVIfLgg4UQAFCtqbJixYkOEHg9SHDmQJEmMEBkS/IiR5cKXMGPKDAgAOw==
--XOIedfhf+7KOe/yw
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="test.txt"
Content-Transfer-Encoding: quoted-printable
D=EDt =EFs =E9=E9n test
--XOIedfhf+7KOe/yw--
"""
)
mailhost
=
self
.
_makeOne
(
'MailHost'
)
# Specifying a charset for the header may have unwanted side
# effects in the case of multipart mails.
# (TypeError: expected string or buffer)
mailhost
.
send
(
msg
,
charset
=
'utf-8'
)
self
.
assertEqual
(
mailhost
.
sent
,
msg
)
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment