Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
vauxoo-dev
odoo
Commits
200bfec8
Commit
200bfec8
authored
May 30, 2016
by
ysantiago
Committed by
Moisés López - https://www.vauxoo.com/
May 30, 2016
Browse files
[REF] base: Allow attach image
parent
d6b3c1d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
openerp/addons/base/ir/ir_mail_server.py
View file @
200bfec8
...
...
@@ -8,6 +8,7 @@ from email.mime.base import MIMEBase
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
email.utils
import
COMMASPACE
,
formataddr
,
formatdate
,
getaddresses
,
make_msgid
import
base64
import
logging
import
re
import
smtplib
...
...
@@ -259,6 +260,34 @@ class IrMailServer(models.Model):
:rtype: email.message.Message (usually MIMEMultipart)
:return: the new RFC2822 email message
"""
ftemplate
=
'__image-%s__'
fcounter
=
0
attachments
=
attachments
or
[]
pattern
=
re
.
compile
(
r
'"data:image/png;base64,[^"]*"'
)
pos
=
0
new_body
=
''
while
True
:
match
=
pattern
.
search
(
body
,
pos
)
if
not
match
:
break
s
=
match
.
start
()
e
=
match
.
end
()
data
=
body
[
s
+
len
(
'"data:image/png;base64,'
):
e
-
1
]
new_body
+=
body
[
pos
:
s
]
fname
=
ftemplate
%
fcounter
fcounter
+=
1
attachments
.
append
(
(
fname
,
base64
.
b64decode
(
data
))
)
new_body
+=
'"cid:%s"'
%
fname
pos
=
e
new_body
+=
body
[
pos
:]
body
=
new_body
email_from
=
email_from
or
tools
.
config
.
get
(
'email_from'
)
assert
email_from
,
"You must either provide a sender address explicitly or configure "
\
"a global sender address in the server configuration or with the "
\
...
...
@@ -328,6 +357,7 @@ class IrMailServer(models.Model):
# so we fix it by using RFC2047 encoding for the filename instead.
part
.
set_param
(
'name'
,
filename_rfc2047
)
part
.
add_header
(
'Content-Disposition'
,
'attachment'
,
filename
=
filename_rfc2047
)
part
.
add_header
(
'Content-ID'
,
'<%s>'
%
filename_rfc2047
)
# NEW STUFF
part
.
set_payload
(
fcontent
)
Encoders
.
encode_base64
(
part
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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