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
ed5f5118
Commit
ed5f5118
authored
Jan 31, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Jul 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CRM py3
parent
496614a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
27 deletions
+39
-27
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.EmailDocument.py
...lateItem/portal_components/document.erp5.EmailDocument.py
+7
-4
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.File.py
...umentTemplateItem/portal_components/document.erp5.File.py
+3
-1
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.MailMessageMixin.py
...lateItem/portal_components/mixin.erp5.MailMessageMixin.py
+29
-22
No files found.
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.EmailDocument.py
View file @
ed5f5118
...
...
@@ -49,9 +49,10 @@ except ImportError:
"""
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_
x
from
email
import
message_from_string
as
message_from_
bytes
else
:
from
email
import
message_from_bytes
as
message_from_x
from
email
import
message_from_bytes
from
email.utils
import
parsedate_tz
,
mktime_tz
DEFAULT_TEXT_FORMAT
=
'text/html'
...
...
@@ -162,7 +163,7 @@ class EmailDocument(TextDocument, MailMessageMixin):
# store it in 'data' property.
result
=
getattr
(
self
,
'_v_message'
,
None
)
if
result
is
None
:
data
=
self
.
getData
(
)
data
=
bytes
(
self
.
getData
()
or
b''
)
if
not
data
:
# Generated a mail message temporarily to provide backward compatibility.
document_type_list
=
list
(
self
.
getPortalEmbeddedDocumentTypeList
())
+
list
(
self
.
getPortalDocumentTypeList
())
...
...
@@ -174,7 +175,9 @@ class EmailDocument(TextDocument, MailMessageMixin):
content_type
=
self
.
getContentType
(),
embedded_file_list
=
self
.
getAggregateValueList
(
portal_type
=
document_type_list
),
)
result
=
message_from_x
(
data
)
if
six
.
PY3
:
data
=
data
.
encode
()
result
=
message_from_bytes
(
data
)
self
.
_v_message
=
result
return
result
...
...
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.File.py
View file @
ed5f5118
...
...
@@ -198,9 +198,9 @@ class File(Document, OFS_File):
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getMimeTypeAndContent'
)
def
getMimeTypeAndContent
(
self
):
# type: () -> tuple[str, bytes]
"""This method returns a tuple which contains mimetype and content."""
from
erp5.component.document.EmailDocument
import
MimeTypeException
# return a tuple (mime_type, data)
content
=
None
mime_type
=
self
.
getContentType
()
...
...
@@ -222,6 +222,8 @@ class File(Document, OFS_File):
elif
getattr
(
self
,
'getBaseData'
,
None
)
is
not
None
:
content
=
self
.
getBaseData
()
if
isinstance
(
content
,
six
.
text_type
):
content
=
content
.
encode
(
'utf-8'
)
if
content
and
not
isinstance
(
content
,
bytes
):
content
=
bytes
(
content
)
...
...
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.MailMessageMixin.py
View file @
ed5f5118
...
...
@@ -40,22 +40,24 @@ import six
filename_regexp
=
'name="([^"]*)"'
def
testCharsetAndConvert
(
text_content
,
content_type
,
encoding
):
try
:
if
encoding
is
not
None
:
text_content
=
text_content
.
decode
(
encoding
)
else
:
if
six
.
PY2
:
text_content
=
text_content
.
decode
().
encode
(
'utf-8'
)
except
(
UnicodeDecodeError
,
LookupError
):
encoding
=
guessEncodingFromText
(
text_content
,
content_type
)
if
encoding
is
not
None
:
try
:
if
not
isinstance
(
text_content
,
six
.
text_type
):
try
:
if
encoding
is
not
None
:
text_content
=
text_content
.
decode
(
encoding
)
except
(
UnicodeDecodeError
,
LookupError
):
# TODO: errors= repr ?
else
:
text_content
=
text_content
.
decode
()
if
six
.
PY2
:
text_content
=
text_content
.
encode
(
'utf-8'
)
except
(
UnicodeDecodeError
,
LookupError
):
encoding
=
guessEncodingFromText
(
text_content
,
content_type
)
if
encoding
is
not
None
:
try
:
text_content
=
text_content
.
decode
(
encoding
)
except
(
UnicodeDecodeError
,
LookupError
):
# TODO: errors= repr ?
text_content
=
repr
(
text_content
)[
1
:
-
1
]
else
:
text_content
=
repr
(
text_content
)[
1
:
-
1
]
else
:
text_content
=
repr
(
text_content
)[
1
:
-
1
]
return
text_content
,
encoding
...
...
@@ -118,18 +120,21 @@ class MailMessageMixin:
result
=
{}
for
(
name
,
value
)
in
self
.
_getMessage
().
items
():
try
:
decoded_header
=
decode_header
(
value
)
decoded_header
_parts
=
decode_header
(
value
)
except
HeaderParseError
as
error_message
:
decoded_header
=
()
decoded_header
_parts
=
()
LOG
(
'MailMessageMixin.getContentInformation'
,
INFO
,
'Failed to decode %s header of %s with error: %s'
%
(
name
,
self
.
getPath
(),
error_message
))
for
text
,
encoding
in
decoded_header
:
text
,
encoding
=
testCharsetAndConvert
(
text
,
'text/plain'
,
encoding
)
if
name
in
result
:
result
[
name
]
=
'%s %s'
%
(
result
[
name
],
text
)
else
:
result
[
name
]
=
text
header_parts
=
[]
for
text
,
encoding
in
decoded_header_parts
:
text
,
_
=
testCharsetAndConvert
(
text
,
'text/plain'
,
encoding
)
header_parts
.
append
(
text
)
if
six
.
PY3
:
result
[
name
]
=
''
.
join
(
header_parts
)
else
:
# https://bugs.python.org/issue1079
result
[
name
]
=
' '
.
join
(
header_parts
)
return
result
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getAttachmentInformationList'
)
...
...
@@ -215,6 +220,8 @@ class MailMessageMixin:
encoding
=
part_encoding
,
index
=
index
)
# add index to generate
# a unique cache key per attachment
if
six
.
PY3
:
content
=
content
.
encode
()
else
:
content
=
part
.
get_payload
(
decode
=
1
)
return
content
...
...
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