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
Carlos Ramos Carreño
erp5
Commits
af2d4ab8
Commit
af2d4ab8
authored
Feb 01, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testNotificationTool: py3
parent
2d926719
Changes
1
Hide 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 @
af2d4ab8
...
@@ -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,15 +79,17 @@ def decode_email(file_):
...
@@ -78,15 +79,17 @@ 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
,
content_type
,
payload
))
content_type
,
payload
))
else
:
else
:
theMail
[
'body'
]
=
payload
theMail
[
'body'
]
=
payload
body_found
=
1
body_found
=
1
...
@@ -94,7 +97,7 @@ def decode_email(file_):
...
@@ -94,7 +97,7 @@ def decode_email(file_):
payload
=
part
.
get_payload
(
decode
=
True
)
payload
=
part
.
get_payload
(
decode
=
True
)
# Keep the content type
# Keep the content type
theMail
[
'attachment_list'
].
append
((
file_name
,
content_type
,
theMail
[
'attachment_list'
].
append
((
file_name
,
content_type
,
payload
))
payload
))
return
theMail
return
theMail
class
TestNotificationTool
(
ERP5TypeTestCase
):
class
TestNotificationTool
(
ERP5TypeTestCase
):
...
...
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