Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
32b1b430
Kaydet (Commit)
32b1b430
authored
Eki 06, 2002
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #572031: AUTH method LOGIN for smtplib.
üst
19cb8700
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
7 deletions
+38
-7
smtplib.py
Lib/smtplib.py
+38
-7
No files found.
Lib/smtplib.py
Dosyayı görüntüle @
32b1b430
...
...
@@ -56,6 +56,11 @@ __all__ = ["SMTPException","SMTPServerDisconnected","SMTPResponseException",
SMTP_PORT
=
25
CRLF
=
"
\r\n
"
OLDSTYLE_AUTH
=
re
.
compile
(
r"auth=(.*)"
,
re
.
I
)
def
encode_base64
(
s
,
eol
=
None
):
return
""
.
join
(
base64
.
encodestring
(
s
)
.
split
(
"
\n
"
))
# Exception classes used by this module.
class
SMTPException
(
Exception
):
"""Base class for all exceptions raised by this module."""
...
...
@@ -391,11 +396,32 @@ class SMTP:
resp
=
self
.
ehlo_resp
.
split
(
'
\n
'
)
del
resp
[
0
]
for
each
in
resp
:
# To be able to communicate with as many SMTP servers as possible,
# we have to take the old-style auth advertisement into account,
# because:
# 1) Else our SMTP feature parser gets confused.
# 2) There are some servers that only advertise the auth methods we
# support using the old style.
auth_match
=
OLDSTYLE_AUTH
.
match
(
each
)
if
auth_match
:
# This doesn't remove duplicates, but that's no problem
self
.
esmtp_features
[
"auth"
]
=
self
.
esmtp_features
.
get
(
"auth"
,
""
)
\
+
" "
+
auth_match
.
groups
(
0
)[
0
]
continue
# RFC 1869 requires a space between ehlo keyword and parameters.
# It's actually stricter, in that only spaces are allowed between
# parameters, but were not going to check for that here. Note
# that the space isn't present if there are no parameters.
m
=
re
.
match
(
r'(?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)'
,
each
)
if
m
:
feature
=
m
.
group
(
"feature"
)
.
lower
()
params
=
m
.
string
[
m
.
end
(
"feature"
):]
.
strip
()
self
.
esmtp_features
[
feature
]
=
params
if
feature
==
"auth"
:
self
.
esmtp_features
[
feature
]
=
self
.
esmtp_features
.
get
(
feature
,
""
)
\
+
" "
+
params
else
:
self
.
esmtp_features
[
feature
]
=
params
return
(
code
,
msg
)
def
has_extn
(
self
,
opt
):
...
...
@@ -494,14 +520,15 @@ class SMTP:
def
encode_cram_md5
(
challenge
,
user
,
password
):
challenge
=
base64
.
decodestring
(
challenge
)
response
=
user
+
" "
+
hmac
.
HMAC
(
password
,
challenge
)
.
hexdigest
()
return
base64
.
encodestring
(
response
)[:
-
1
]
return
encode_base64
(
response
,
eol
=
""
)
def
encode_plain
(
user
,
password
):
return
base64
.
encodestring
(
"
%
s
\0
%
s
\0
%
s"
%
(
user
,
user
,
password
))[:
-
1
]
return
encode_base64
(
"
%
s
\0
%
s
\0
%
s"
%
(
user
,
user
,
password
),
eol
=
""
)
AUTH_PLAIN
=
"PLAIN"
AUTH_CRAM_MD5
=
"CRAM-MD5"
AUTH_LOGIN
=
"LOGIN"
if
self
.
helo_resp
is
None
and
self
.
ehlo_resp
is
None
:
if
not
(
200
<=
self
.
ehlo
()[
0
]
<=
299
):
...
...
@@ -518,8 +545,7 @@ class SMTP:
# List of authentication methods we support: from preferred to
# less preferred methods. Except for the purpose of testing the weaker
# ones, we prefer stronger methods like CRAM-MD5:
preferred_auths
=
[
AUTH_CRAM_MD5
,
AUTH_PLAIN
]
#preferred_auths = [AUTH_PLAIN, AUTH_CRAM_MD5]
preferred_auths
=
[
AUTH_CRAM_MD5
,
AUTH_PLAIN
,
AUTH_LOGIN
]
# Determine the authentication method we'll use
authmethod
=
None
...
...
@@ -527,7 +553,6 @@ class SMTP:
if
method
in
authlist
:
authmethod
=
method
break
if
self
.
debuglevel
>
0
:
print
"AuthMethod:"
,
authmethod
if
authmethod
==
AUTH_CRAM_MD5
:
(
code
,
resp
)
=
self
.
docmd
(
"AUTH"
,
AUTH_CRAM_MD5
)
...
...
@@ -538,6 +563,12 @@ class SMTP:
elif
authmethod
==
AUTH_PLAIN
:
(
code
,
resp
)
=
self
.
docmd
(
"AUTH"
,
AUTH_PLAIN
+
" "
+
encode_plain
(
user
,
password
))
elif
authmethod
==
AUTH_LOGIN
:
(
code
,
resp
)
=
self
.
docmd
(
"AUTH"
,
"
%
s
%
s"
%
(
AUTH_LOGIN
,
encode_base64
(
user
,
eol
=
""
)))
if
code
!=
334
:
raise
SMTPAuthenticationError
(
code
,
resp
)
(
code
,
resp
)
=
self
.
docmd
(
encode_base64
(
password
,
eol
=
""
))
elif
authmethod
==
None
:
raise
SMTPException
(
"No suitable authentication method found."
)
if
code
not
in
[
235
,
503
]:
...
...
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