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
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
f9986388
Commit
f9986388
authored
Feb 01, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testNotificationTool: py3
parent
2fd59e9e
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 @
f9986388
...
@@ -34,10 +34,11 @@ from AccessControl.SecurityManagement import getSecurityManager
...
@@ -34,10 +34,11 @@ from AccessControl.SecurityManagement import getSecurityManager
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.utils
import
DummyMailHost
from
Products.ERP5Type.tests.utils
import
DummyMailHost
import
email
import
email
import
six
from
email.header
import
decode_header
,
make_header
from
email.header
import
decode_header
,
make_header
from
email.utils
import
parseaddr
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_
):
def
decode_email
(
file_
):
# Prepare result
# Prepare result
theMail
=
{
theMail
=
{
...
@@ -47,22 +48,22 @@ def decode_email(file_):
...
@@ -47,22 +48,22 @@ def decode_email(file_):
'headers'
:
{}
'headers'
:
{}
}
}
# Get Message
# Get Message
msg
=
email
.
message_from_string
(
file_
)
msg
=
email
.
message_from_string
(
file_
.
decode
()
)
# Back up original file
# Back up original file
theMail
[
'__original__'
]
=
file_
theMail
[
'__original__'
]
=
file_
# Recode headers to UTF-8 if needed
for
key
,
value
in
six
.
iteritems
(
msg
):
for
key
,
value
in
msg
.
items
():
decoded_value_list
=
decode_header
(
value
)
decoded_value_list
=
decode_header
(
value
)
unicode_value
=
make_header
(
decoded_value_list
)
new_value
=
make_header
(
decoded_value_list
)
# TODO PY3
if
six
.
PY2
:
new_value
=
unicode_value
.
__unicode__
().
encode
(
'utf-8'
)
# Recode headers to UTF-8 if needed
new_value
=
new_value
.
__unicode__
().
encode
(
'utf-8'
)
theMail
[
'headers'
][
key
.
lower
()]
=
new_value
theMail
[
'headers'
][
key
.
lower
()]
=
new_value
# Filter mail addresses
# Filter mail addresses
for
header
in
(
'resent-to'
,
'resent-from'
,
'resent-cc'
,
'resent-sender'
,
for
header
in
(
'resent-to'
,
'resent-from'
,
'resent-cc'
,
'resent-sender'
,
'to'
,
'from'
,
'cc'
,
'sender'
,
'reply-to'
):
'to'
,
'from'
,
'cc'
,
'sender'
,
'reply-to'
):
header_field
=
theMail
[
'headers'
].
get
(
header
)
header_field
=
theMail
[
'headers'
].
get
(
header
)
if
header_field
:
if
header_field
:
theMail
[
'headers'
][
header
]
=
parseaddr
(
header_field
)[
1
]
theMail
[
'headers'
][
header
]
=
parseaddr
(
header_field
.
encode
()
)[
1
]
# Get attachments
# Get attachments
body_found
=
0
body_found
=
0
for
part
in
msg
.
walk
():
for
part
in
msg
.
walk
():
...
@@ -78,11 +79,13 @@ def decode_email(file_):
...
@@ -78,11 +79,13 @@ def decode_email(file_):
elif
content_type
==
'message/rfc822'
:
elif
content_type
==
'message/rfc822'
:
continue
continue
elif
content_type
in
(
"text/plain"
,
"text/html"
):
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
)
payload
=
part
.
get_payload
(
decode
=
True
)
#LOG('CMFMailIn -> ',0,'charset: %s, payload: %s' % (charset,payload))
#LOG('CMFMailIn -> ',0,'charset: %s, payload: %s' % (charset,payload))
if
charset
:
if
charset
:
payload
=
unicode
(
payload
,
charset
).
encode
(
'utf-8'
)
payload
=
payload
.
decode
(
charset
)
if
six
.
PY2
:
payload
=
payload
.
encode
(
'utf-8'
)
if
body_found
:
if
body_found
:
# Keep the content type
# Keep the content type
theMail
[
'attachment_list'
].
append
((
file_name
,
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