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