Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
0d88e7a0
Commit
0d88e7a0
authored
Jul 06, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MailTemplates: merge monkey-patch
parent
015af31a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
114 deletions
+32
-114
product/ERP5Type/ZopePatch.py
product/ERP5Type/ZopePatch.py
+0
-1
product/ERP5Type/patches/MailTemplates.py
product/ERP5Type/patches/MailTemplates.py
+0
-110
product/MailTemplates/BaseMailTemplate.py
product/MailTemplates/BaseMailTemplate.py
+32
-3
No files found.
product/ERP5Type/ZopePatch.py
View file @
0d88e7a0
...
...
@@ -56,7 +56,6 @@ from Products.ERP5Type.patches import PersistentMapping
from
Products.ERP5Type.patches
import
DateTimePatch
from
Products.ERP5Type.patches
import
PythonScript
from
Products.ERP5Type.patches
import
MailHost
from
Products.ERP5Type.patches
import
MailTemplates
from
Products.ERP5Type.patches
import
http_server
from
Products.ERP5Type.patches
import
memcache_client
from
Products.ERP5Type.patches
import
StateChangeInfoPatch
...
...
product/ERP5Type/patches/MailTemplates.py
deleted
100644 → 0
View file @
015af31a
#!/usr/bin/python
# Copyright (c) 2005 Simplistix Ltd
#
# This Software is released under the MIT License:
# http://www.opensource.org/licenses/mit-license.html
# See license.txt for more details.
"""
this patch is based on MailTemplates 1.1.0
it will only try to encode() text if it's of type unicode
"""
try
:
from
Products.MailTemplates
import
BaseMailTemplate
except
ImportError
:
BaseMailTemplate
=
None
from
email.Header
import
Header
from
email.Utils
import
make_msgid
,
formataddr
,
getaddresses
if
BaseMailTemplate
is
not
None
:
def
_process_utf8
(
self
,
kw
):
# sort out what encoding we're going to use
encoding
=
kw
.
get
(
'encoding'
,
self
.
getProperty
(
'encoding'
,
BaseMailTemplate
.
default_encoding
))
text
=
self
.
__class__
.
__bases__
[
1
].
__call__
(
self
,
**
kw
)
# ZPT adds newline at the end, but it breaks backward compatibility.
# So I remove it.
if
text
and
text
[
-
1
]
==
'
\
n
'
:
text
=
text
[:
-
1
]
if
not
self
.
html
()
and
isinstance
(
text
,
unicode
):
text
=
text
.
encode
(
encoding
,
'replace'
)
# now turn the result into a MIMEText object
msg
=
BaseMailTemplate
.
MIMEText
(
text
.
replace
(
'
\
r
'
,
''
),
self
.
content_type
.
split
(
'/'
)[
1
],
encoding
)
# sort out what headers and addresses we're going to use
headers
=
{}
values
=
{}
# headers from the headers property
for
header
in
getattr
(
self
,
'headers'
,()):
name
,
value
=
header
.
split
(
':'
,
1
)
headers
[
name
]
=
value
# headers from the headers parameter
headers_param
=
kw
.
get
(
'headers'
,{})
headers
.
update
(
headers_param
)
# values and some specific headers
for
key
,
header
in
((
'mfrom'
,
'From'
),
(
'mto'
,
'To'
),
(
'mcc'
,
'Cc'
),
(
'mbcc'
,
'Bcc'
),
(
'subject'
,
'Subject'
)):
value
=
kw
.
get
(
key
,
headers_param
.
get
(
header
,
getattr
(
self
,
key
,
headers
.
get
(
header
))))
if
value
is
not
None
:
values
[
key
]
=
value
# turn some sequences in coma-seperated strings
if
isinstance
(
value
,
(
tuple
,
list
)):
value
=
', '
.
join
(
value
)
# make sure we have no unicode headers
if
isinstance
(
value
,
unicode
):
value
=
value
.
encode
(
encoding
)
if
key
==
'subject'
:
try
:
# Try to keep header non encoded
value
=
Header
(
value
.
encode
(
"ascii"
))
except
UnicodeDecodeError
:
value
=
Header
(
value
,
"UTF-8"
)
else
:
value_list
=
getaddresses
([
value
])
dest_list
=
[]
for
name
,
email
in
value_list
:
try
:
name
=
Header
(
name
.
encode
(
"ascii"
))
except
UnicodeDecodeError
:
name
=
Header
(
name
,
"UTF-8"
)
dest_list
.
append
(
formataddr
((
name
.
encode
(),
email
)))
value
=
", "
.
join
(
dest_list
)
headers
[
header
]
=
value
# check required values have been supplied
errors
=
[]
for
param
in
(
'mfrom'
,
'mto'
):
if
not
values
.
get
(
param
):
errors
.
append
(
param
)
if
errors
:
raise
TypeError
(
'The following parameters were required by not specified: '
+
(
', '
.
join
(
errors
)
))
# add date header
headers
[
'Date'
]
=
BaseMailTemplate
.
DateTime
().
rfc822
()
# add message-id header
headers
[
'Message-ID'
]
=
make_msgid
()
# turn headers into an ordered list for predictable header order
keys
=
headers
.
keys
()
keys
.
sort
()
return
msg
,
values
,[(
key
,
headers
[
key
])
for
key
in
keys
]
BaseMailTemplate
.
BaseMailTemplate
.
_process
=
_process_utf8
product/MailTemplates/BaseMailTemplate.py
View file @
0d88e7a0
...
...
@@ -9,8 +9,10 @@ import rfc822
from
AccessControl
import
ClassSecurityInfo
from
DateTime
import
DateTime
from
email.Header
import
Header
from
email.MIMEMultipart
import
MIMEMultipart
from
email.MIMEText
import
MIMEText
from
email.Utils
import
make_msgid
,
formataddr
,
getaddresses
from
App.class_init
import
default__class_init__
as
InitializeClass
from
App.Common
import
package_home
...
...
@@ -42,7 +44,11 @@ class BaseMailTemplate:
self
.
getProperty
(
'encoding'
,
default_encoding
))
text
=
self
.
__class__
.
__bases__
[
1
].
__call__
(
self
,
**
kw
)
if
not
self
.
html
():
# ZPT adds newline at the end, but it breaks backward compatibility.
# So I remove it.
if
text
.
endswith
(
'
\
n
'
):
text
=
text
[:
-
1
]
if
not
self
.
html
()
and
isinstance
(
text
,
unicode
):
text
=
text
.
encode
(
encoding
,
'replace'
)
# now turn the result into a MIMEText object
msg
=
MIMEText
(
...
...
@@ -73,16 +79,36 @@ class BaseMailTemplate:
headers
.
get
(
header
))))
if
value
is
not
None
:
values
[
key
]
=
value
# turn some sequences in coma-seperated strings
if
isinstance
(
value
,
tuple
)
or
isinstance
(
value
,
list
):
if
isinstance
(
value
,
(
tuple
,
list
)
):
value
=
', '
.
join
(
value
)
# make sure we have no unicode headers
if
isinstance
(
value
,
unicode
):
value
=
value
.
encode
(
encoding
)
if
key
==
'subject'
:
try
:
# Try to keep header non encoded
value
=
Header
(
value
.
encode
(
"ascii"
))
except
UnicodeDecodeError
:
value
=
Header
(
value
,
"UTF-8"
)
else
:
value_list
=
getaddresses
([
value
])
dest_list
=
[]
for
name
,
email
in
value_list
:
try
:
name
=
Header
(
name
.
encode
(
"ascii"
))
except
UnicodeDecodeError
:
name
=
Header
(
name
,
"UTF-8"
)
dest_list
.
append
(
formataddr
((
name
.
encode
(),
email
)))
value
=
", "
.
join
(
dest_list
)
headers
[
header
]
=
value
# check required values have been supplied
errors
=
[]
for
param
in
(
'mfrom'
,
'mto'
,
'subject'
):
for
param
in
(
'mfrom'
,
'mto'
):
if
not
values
.
get
(
param
):
errors
.
append
(
param
)
if
errors
:
...
...
@@ -92,6 +118,9 @@ class BaseMailTemplate:
))
# add date header
headers
[
'Date'
]
=
DateTime
().
rfc822
()
# do not let the MTA to generate the Message-ID:
# we want to have it stored in ERP5, for mail threading
headers
[
'Message-ID'
]
=
make_msgid
()
# turn headers into an ordered list for predictable header order
keys
=
headers
.
keys
()
keys
.
sort
()
...
...
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