Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a7d9bdfa
Commit
a7d9bdfa
authored
Dec 22, 1998
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A few other docstring fixes, most importantly to be a little nicer to
Emacs ;-)
parent
4c4bec86
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
54 deletions
+59
-54
Lib/smtplib.py
Lib/smtplib.py
+59
-54
No files found.
Lib/smtplib.py
View file @
a7d9bdfa
...
@@ -8,7 +8,7 @@ ESMTP support, test code and doc fixes added by
...
@@ -8,7 +8,7 @@ ESMTP support, test code and doc fixes added by
Better RFC 821 compliance (MAIL and RCPT, and CRLF in data)
Better RFC 821 compliance (MAIL and RCPT, and CRLF in data)
by Carey Evans <c.evans@clear.net.nz>, for picky mail servers.
by Carey Evans <c.evans@clear.net.nz>, for picky mail servers.
(This was modified from the Python 1.5 library HTTP lib.)
This was modified from the Python 1.5 library HTTP lib.
This should follow RFC 821 (SMTP) and RFC 1869 (ESMTP).
This should follow RFC 821 (SMTP) and RFC 1869 (ESMTP).
...
@@ -20,23 +20,23 @@ and MAIL commands!
...
@@ -20,23 +20,23 @@ and MAIL commands!
Example:
Example:
>>> import smtplib
>>> import smtplib
>>> s=smtplib.SMTP("localhost")
>>> s=smtplib.SMTP("localhost")
>>> print s.help()
>>> print s.help()
This is Sendmail version 8.8.4
This is Sendmail version 8.8.4
Topics:
Topics:
HELO EHLO MAIL RCPT DATA
HELO EHLO MAIL RCPT DATA
RSET NOOP QUIT HELP VRFY
RSET NOOP QUIT HELP VRFY
EXPN VERB ETRN DSN
EXPN VERB ETRN DSN
For more info use "HELP <topic>".
For more info use "HELP <topic>".
To report bugs in the implementation send email to
To report bugs in the implementation send email to
sendmail-bugs@sendmail.org.
sendmail-bugs@sendmail.org.
For local information send email to Postmaster at your site.
For local information send email to Postmaster at your site.
End of HELP info
End of HELP info
>>> s.putcmd("vrfy","someone@here")
>>> s.putcmd("vrfy","someone@here")
>>> s.getreply()
>>> s.getreply()
(250, "Somebody OverHere <somebody@here.my.org>")
(250, "Somebody OverHere <somebody@here.my.org>")
>>> s.quit()
>>> s.quit()
'''
'''
...
@@ -57,8 +57,8 @@ SMTPDataError="Error transmitting message data"
...
@@ -57,8 +57,8 @@ SMTPDataError="Error transmitting message data"
def
quoteaddr
(
addr
):
def
quoteaddr
(
addr
):
"""Quote a subset of the email addresses defined by RFC 821.
"""Quote a subset of the email addresses defined by RFC 821.
Should be able to handle anything rfc822.parseaddr can handle.
"""
Should be able to handle anything rfc822.parseaddr can handle.
"""
m
=
None
m
=
None
try
:
try
:
m
=
rfc822
.
parseaddr
(
addr
)[
1
]
m
=
rfc822
.
parseaddr
(
addr
)[
1
]
...
@@ -74,7 +74,8 @@ def quotedata(data):
...
@@ -74,7 +74,8 @@ def quotedata(data):
"""Quote data for email.
"""Quote data for email.
Double leading '.', and change Unix newline '
\
n
', or Mac '
\
r
' into
Double leading '.', and change Unix newline '
\
n
', or Mac '
\
r
' into
Internet CRLF end-of-line."""
Internet CRLF end-of-line.
"""
return
re
.
sub
(
r'(?m)^\
.
', '
..
',
return
re
.
sub
(
r'(?m)^\
.
', '
..
',
re.sub(r'
(
?
:
\
r
\
n
|
\
n
|
\
r
(
?!
\
n
))
', CRLF, data))
re.sub(r'
(
?
:
\
r
\
n
|
\
n
|
\
r
(
?!
\
n
))
', CRLF, data))
...
@@ -105,8 +106,8 @@ class SMTP:
...
@@ -105,8 +106,8 @@ class SMTP:
For method docs, see each method'
s
docstrings
.
In
general
,
there
is
For method docs, see each method'
s
docstrings
.
In
general
,
there
is
a
method
of
the
same
name
to
perform
each
SMTP
command
,
and
there
a
method
of
the
same
name
to
perform
each
SMTP
command
,
and
there
is
a
method
called
'sendmail'
that
will
do
an
entire
mail
is
a
method
called
'sendmail'
that
will
do
an
entire
mail
transaction
.
"""
transaction
.
"""
debuglevel = 0
debuglevel = 0
file = None
file = None
helo_resp = None
helo_resp = None
...
@@ -116,9 +117,9 @@ class SMTP:
...
@@ -116,9 +117,9 @@ class SMTP:
def __init__(self, host = '', port = 0):
def __init__(self, host = '', port = 0):
"""
Initialize
a
new
instance
.
"""
Initialize
a
new
instance
.
If
specified
,
`
host
' is the name of the remote host to which
If
specified
,
`
host
' is the name of the remote host to which
to
to connect. If specified, `port'
specifies
the
port
to
which
connect. If specified, `port'
specifies
the
port
to
which
to
connect
.
to
connect
.
By
default
,
smtplib
.
SMTP_PORT
is
used
.
By
default
,
smtplib
.
SMTP_PORT
is
used
.
"""
"""
self.esmtp_features = {}
self.esmtp_features = {}
...
@@ -127,8 +128,8 @@ class SMTP:
...
@@ -127,8 +128,8 @@ class SMTP:
def set_debuglevel(self, debuglevel):
def set_debuglevel(self, debuglevel):
"""
Set
the
debug
output
level
.
"""
Set
the
debug
output
level
.
A
non
-
false
value
results
in
debug
messages
for
connection
and
A
non
-
false
value
results
in
debug
messages
for
connection
and
for
all
for
all
messages
sent
to
and
received
from
the
server
.
messages
sent
to
and
received
from
the
server
.
"""
"""
self.debuglevel = debuglevel
self.debuglevel = debuglevel
...
@@ -140,8 +141,8 @@ class SMTP:
...
@@ -140,8 +141,8 @@ class SMTP:
there is no port specified, that suffix will be stripped off and the
there is no port specified, that suffix will be stripped off and the
number interpreted as the port number to use.
number interpreted as the port number to use.
Note:
This method is automatically invoked by __init__,
Note:
This method is automatically invoked by __init__, if a host is
if a host is
specified during instantiation.
specified during instantiation.
"""
"""
if not port:
if not port:
...
@@ -171,8 +172,7 @@ class SMTP:
...
@@ -171,8 +172,7 @@ class SMTP:
raise SMTPServerDisconnected
raise SMTPServerDisconnected
def putcmd(self, cmd, args=""):
def putcmd(self, cmd, args=""):
"""
Send
a
command
to
the
server
.
"""
Send
a
command
to
the
server
.
"""
"""
str = '%s %s%s' % (cmd, args, CRLF)
str = '%s %s%s' % (cmd, args, CRLF)
self.send(str)
self.send(str)
...
@@ -180,11 +180,12 @@ class SMTP:
...
@@ -180,11 +180,12 @@ class SMTP:
"""
Get
a
reply
from
the
server
.
"""
Get
a
reply
from
the
server
.
Returns
a
tuple
consisting
of
:
Returns
a
tuple
consisting
of
:
-
server
response
code
(
e
.
g
.
'250'
,
or
such
,
if
all
goes
well
)
Note
:
returns
-
1
if
it
can
't read response code.
-
server
response
code
(
e
.
g
.
'250'
,
or
such
,
if
all
goes
well
)
- server response string corresponding to response code
Note
:
returns
-
1
if
it
can
't read response code.
(note : multiline responses converted to a single,
multiline string)
- server response string corresponding to response code (multiline
responses are converted to a single, multiline string).
"""
"""
resp=[]
resp=[]
self.file = self.sock.makefile('rb')
self.file = self.sock.makefile('rb')
...
@@ -207,30 +208,33 @@ class SMTP:
...
@@ -207,30 +208,33 @@ class SMTP:
return errcode, errmsg
return errcode, errmsg
def docmd(self, cmd, args=""):
def docmd(self, cmd, args=""):
""" Send a command, and return its response code """
"""Send a command, and return its response code."""
self.putcmd(cmd,args)
self.putcmd(cmd,args)
(code,msg)=self.getreply()
(code,msg)=self.getreply()
return code
return code
# std smtp commands
# std smtp commands
def helo(self, name=''):
def helo(self, name=''):
""" SMTP '
helo
' command. Hostname to send for this command
"""SMTP '
helo
' command.
defaults to the FQDN of the local host """
Hostname to send for this command defaults to the FQDN of the local
host.
"""
name=string.strip(name)
name=string.strip(name)
if len(name)==0:
if len(name)==0:
name=socket.gethostbyaddr(socket.gethostname())[0]
name=socket.gethostbyaddr(socket.gethostname())[0]
self.putcmd("helo",name)
self.putcmd("helo",name)
(code,msg)=self.getreply()
(code,msg)=self.getreply()
self.helo_resp=msg
self.helo_resp=msg
return code
return code
def ehlo(self, name=''):
def ehlo(self, name=''):
""" SMTP '
ehlo
' command. Hostname to send for this command
""" SMTP '
ehlo
' command.
defaults to the FQDN of the local host. """
Hostname to send for this command defaults to the FQDN of the local
host.
"""
name=string.strip(name)
name=string.strip(name)
if len(name)==0:
if len(name)==0:
name=socket.gethostbyaddr(socket.gethostname())[0]
name=socket.gethostbyaddr(socket.gethostname())[0]
self.putcmd("ehlo",name)
self.putcmd("ehlo",name)
(code,msg)=self.getreply()
(code,msg)=self.getreply()
# According to RFC1869 some (badly written)
# According to RFC1869 some (badly written)
...
@@ -258,23 +262,24 @@ class SMTP:
...
@@ -258,23 +262,24 @@ class SMTP:
return self.esmtp_features.has_key(string.lower(opt))
return self.esmtp_features.has_key(string.lower(opt))
def help(self, args=''):
def help(self, args=''):
"""SMTP '
help
' command. Returns help text from server."""
"""SMTP '
help
' command.
Returns help text from server."""
self.putcmd("help", args)
self.putcmd("help", args)
(code,msg)=self.getreply()
(code,msg)=self.getreply()
return msg
return msg
def rset(self):
def rset(self):
"""SMTP '
rset
' command
. R
esets session."""
"""SMTP '
rset
' command
-- r
esets session."""
code=self.docmd("rset")
code=self.docmd("rset")
return code
return code
def noop(self):
def noop(self):
"""SMTP '
noop
' command
. D
oesn'
t
do
anything
:
>
"""
"""SMTP '
noop
' command
-- d
oesn'
t
do
anything
:
>
"""
code=self.docmd("noop")
code=self.docmd("noop")
return code
return code
def mail(self,sender,options=[]):
def mail(self,sender,options=[]):
"""
SMTP
'mail'
command
.
B
egins
mail
xfer
session
.
"""
"""
SMTP
'mail'
command
--
b
egins
mail
xfer
session
.
"""
optionlist = ''
optionlist = ''
if options and self.does_esmtp:
if options and self.does_esmtp:
optionlist = string.join(options, ' ')
optionlist = string.join(options, ' ')
...
@@ -282,7 +287,7 @@ class SMTP:
...
@@ -282,7 +287,7 @@ class SMTP:
return self.getreply()
return self.getreply()
def rcpt(self,recip,options=[]):
def rcpt(self,recip,options=[]):
"""
SMTP
'rcpt'
command
.
I
ndicates
1
recipient
for
this
mail
.
"""
"""
SMTP
'rcpt'
command
--
i
ndicates
1
recipient
for
this
mail
.
"""
optionlist = ''
optionlist = ''
if options and self.does_esmtp:
if options and self.does_esmtp:
optionlist = string.join(options, ' ')
optionlist = string.join(options, ' ')
...
@@ -290,7 +295,7 @@ class SMTP:
...
@@ -290,7 +295,7 @@ class SMTP:
return self.getreply()
return self.getreply()
def data(self,msg):
def data(self,msg):
"""
SMTP
'DATA'
command
.
S
ends
message
data
to
server
.
"""
SMTP
'DATA'
command
--
s
ends
message
data
to
server
.
Automatically
quotes
lines
beginning
with
a
period
per
rfc821
.
Automatically
quotes
lines
beginning
with
a
period
per
rfc821
.
"""
"""
self.putcmd("data")
self.putcmd("data")
...
@@ -306,14 +311,14 @@ class SMTP:
...
@@ -306,14 +311,14 @@ class SMTP:
return code
return code
def verify(self, address):
def verify(self, address):
"""
SMTP
'verify'
command
.
C
hecks
for
address
validity
.
"""
"""
SMTP
'verify'
command
--
c
hecks
for
address
validity
.
"""
self.putcmd("vrfy", quoteaddr(address))
self.putcmd("vrfy", quoteaddr(address))
return self.getreply()
return self.getreply()
# a.k.a.
# a.k.a.
vrfy=verify
vrfy=verify
def expn(self, address):
def expn(self, address):
"""
SMTP
'verify'
command
.
C
hecks
for
address
validity
.
"""
"""
SMTP
'verify'
command
--
c
hecks
for
address
validity
.
"""
self.putcmd("expn", quoteaddr(address))
self.putcmd("expn", quoteaddr(address))
return self.getreply()
return self.getreply()
...
...
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