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
Labels
Merge Requests
138
Merge Requests
138
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
b65e3c26
Commit
b65e3c26
authored
Feb 01, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testNotificationTool: py3
parent
d8430b71
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
13 deletions
+16
-13
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testNotificationTool.py
...eItem/portal_components/test.erp5.testNotificationTool.py
+16
-13
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testNotificationTool.py
View file @
b65e3c26
...
...
@@ -34,10 +34,11 @@ from AccessControl.SecurityManagement import getSecurityManager
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.utils
import
DummyMailHost
import
email
import
six
from
email.header
import
decode_header
,
make_header
from
email.utils
import
parseaddr
# Copied from
ERP5Type/patches/CMFMailI
n.py
# Copied from
bt5/erp5_egov/TestTemplateItem/testEGovMixi
n.py
def
decode_email
(
file_
):
# Prepare result
theMail
=
{
...
...
@@ -47,22 +48,22 @@ def decode_email(file_):
'headers'
:
{}
}
# Get Message
msg
=
email
.
message_from_string
(
file_
)
msg
=
email
.
message_from_string
(
file_
.
decode
()
)
# Back up original file
theMail
[
'__original__'
]
=
file_
# Recode headers to UTF-8 if needed
for
key
,
value
in
msg
.
items
():
for
key
,
value
in
six
.
iteritems
(
msg
):
decoded_value_list
=
decode_header
(
value
)
unicode_value
=
make_header
(
decoded_value_list
)
# TODO PY3
new_value
=
unicode_value
.
__unicode__
().
encode
(
'utf-8'
)
new_value
=
make_header
(
decoded_value_list
)
if
six
.
PY2
:
# Recode headers to UTF-8 if needed
new_value
=
new_value
.
__unicode__
().
encode
(
'utf-8'
)
theMail
[
'headers'
][
key
.
lower
()]
=
new_value
# Filter mail addresses
for
header
in
(
'resent-to'
,
'resent-from'
,
'resent-cc'
,
'resent-sender'
,
'to'
,
'from'
,
'cc'
,
'sender'
,
'reply-to'
):
header_field
=
theMail
[
'headers'
].
get
(
header
)
if
header_field
:
theMail
[
'headers'
][
header
]
=
parseaddr
(
header_field
)[
1
]
theMail
[
'headers'
][
header
]
=
parseaddr
(
header_field
.
encode
()
)[
1
]
# Get attachments
body_found
=
0
for
part
in
msg
.
walk
():
...
...
@@ -78,11 +79,13 @@ def decode_email(file_):
elif
content_type
==
'message/rfc822'
:
continue
elif
content_type
in
(
"text/plain"
,
"text/html"
):
charset
=
part
.
get_content_charset
()
charset
=
part
.
get_content_charset
()
or
'utf-8'
payload
=
part
.
get_payload
(
decode
=
True
)
#LOG('CMFMailIn -> ',0,'charset: %s, payload: %s' % (charset,payload))
if
charset
:
payload
=
unicode
(
payload
,
charset
).
encode
(
'utf-8'
)
payload
=
payload
.
decode
(
charset
)
if
six
.
PY2
:
payload
=
payload
.
encode
(
'utf-8'
)
if
body_found
:
# Keep the content type
theMail
[
'attachment_list'
].
append
((
file_name
,
...
...
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