Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
751774c2
Kaydet (Commit)
751774c2
authored
Agu 09, 2012
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[py3] Fixed mail tests with Python 3
üst
5f8da527
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
message.py
django/core/mail/message.py
+17
-17
tests.py
tests/regressiontests/mail/tests.py
+0
-0
No files found.
django/core/mail/message.py
Dosyayı görüntüle @
751774c2
...
...
@@ -11,11 +11,10 @@ from email.mime.multipart import MIMEMultipart
from
email.mime.base
import
MIMEBase
from
email.header
import
Header
from
email.utils
import
formatdate
,
getaddresses
,
formataddr
,
parseaddr
from
io
import
BytesIO
from
django.conf
import
settings
from
django.core.mail.utils
import
DNS_NAME
from
django.utils.encoding
import
smart_bytes
,
force_text
from
django.utils.encoding
import
force_text
from
django.utils
import
six
...
...
@@ -83,34 +82,34 @@ def forbid_multi_line_headers(name, val, encoding):
if
'
\n
'
in
val
or
'
\r
'
in
val
:
raise
BadHeaderError
(
"Header values can't contain newlines (got
%
r for header
%
r)"
%
(
val
,
name
))
try
:
val
=
val
.
encode
(
'ascii'
)
val
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
if
name
.
lower
()
in
ADDRESS_HEADERS
:
val
=
', '
.
join
(
sanitize_address
(
addr
,
encoding
)
for
addr
in
getaddresses
((
val
,)))
else
:
val
=
str
(
Header
(
val
,
encoding
)
)
val
=
Header
(
val
,
encoding
)
.
encode
(
)
else
:
if
name
.
lower
()
==
'subject'
:
val
=
Header
(
val
)
return
s
mart_bytes
(
name
),
val
val
=
Header
(
val
)
.
encode
()
return
s
tr
(
name
),
val
def
sanitize_address
(
addr
,
encoding
):
if
isinstance
(
addr
,
six
.
string_types
):
addr
=
parseaddr
(
force_text
(
addr
))
nm
,
addr
=
addr
nm
=
str
(
Header
(
nm
,
encoding
)
)
nm
=
Header
(
nm
,
encoding
)
.
encode
(
)
try
:
addr
=
addr
.
encode
(
'ascii'
)
addr
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
# IDN
if
'@'
in
addr
:
localpart
,
domain
=
addr
.
split
(
'@'
,
1
)
localpart
=
str
(
Header
(
localpart
,
encoding
))
domain
=
domain
.
encode
(
'idna'
)
domain
=
domain
.
encode
(
'idna'
)
.
decode
(
'ascii'
)
addr
=
'@'
.
join
([
localpart
,
domain
])
else
:
addr
=
str
(
Header
(
addr
,
encoding
)
)
addr
=
Header
(
addr
,
encoding
)
.
encode
(
)
return
formataddr
((
nm
,
addr
))
...
...
@@ -132,7 +131,7 @@ class SafeMIMEText(MIMEText):
This overrides the default as_string() implementation to not mangle
lines that begin with 'From '. See bug #13433 for details.
"""
fp
=
Bytes
IO
()
fp
=
six
.
String
IO
()
g
=
Generator
(
fp
,
mangle_from_
=
False
)
g
.
flatten
(
self
,
unixfrom
=
unixfrom
)
return
fp
.
getvalue
()
...
...
@@ -156,7 +155,7 @@ class SafeMIMEMultipart(MIMEMultipart):
This overrides the default as_string() implementation to not mangle
lines that begin with 'From '. See bug #13433 for details.
"""
fp
=
Bytes
IO
()
fp
=
six
.
String
IO
()
g
=
Generator
(
fp
,
mangle_from_
=
False
)
g
.
flatten
(
self
,
unixfrom
=
unixfrom
)
return
fp
.
getvalue
()
...
...
@@ -210,8 +209,7 @@ class EmailMessage(object):
def
message
(
self
):
encoding
=
self
.
encoding
or
settings
.
DEFAULT_CHARSET
msg
=
SafeMIMEText
(
smart_bytes
(
self
.
body
,
encoding
),
self
.
content_subtype
,
encoding
)
msg
=
SafeMIMEText
(
self
.
body
,
self
.
content_subtype
,
encoding
)
msg
=
self
.
_create_message
(
msg
)
msg
[
'Subject'
]
=
self
.
subject
msg
[
'From'
]
=
self
.
extra_headers
.
get
(
'From'
,
self
.
from_email
)
...
...
@@ -293,7 +291,7 @@ class EmailMessage(object):
basetype
,
subtype
=
mimetype
.
split
(
'/'
,
1
)
if
basetype
==
'text'
:
encoding
=
self
.
encoding
or
settings
.
DEFAULT_CHARSET
attachment
=
SafeMIMEText
(
smart_bytes
(
content
,
encoding
)
,
subtype
,
encoding
)
attachment
=
SafeMIMEText
(
content
,
subtype
,
encoding
)
else
:
# Encode non-text attachments with base64.
attachment
=
MIMEBase
(
basetype
,
subtype
)
...
...
@@ -313,9 +311,11 @@ class EmailMessage(object):
attachment
=
self
.
_create_mime_attachment
(
content
,
mimetype
)
if
filename
:
try
:
filename
=
filename
.
encode
(
'ascii'
)
filename
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
filename
=
(
'utf-8'
,
''
,
filename
.
encode
(
'utf-8'
))
if
not
six
.
PY3
:
filename
=
filename
.
encode
(
'utf-8'
)
filename
=
(
'utf-8'
,
''
,
filename
)
attachment
.
add_header
(
'Content-Disposition'
,
'attachment'
,
filename
=
filename
)
return
attachment
...
...
tests/regressiontests/mail/tests.py
Dosyayı görüntüle @
751774c2
This diff is collapsed.
Click to expand it.
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