Nothing earthshattering, just some fixes to typos and other formatting

bugs in various docstrings.
This commit is contained in:
Barry Warsaw 1998-12-22 03:02:20 +00:00
parent e96bd3f60f
commit 4c4bec86f4
1 changed files with 52 additions and 49 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/python #! /usr/bin/env python
"""SMTP/ESMTP client class.
'''SMTP/ESMTP client class.
Author: The Dragon De Monsyne <dragondm@integral.org> Author: The Dragon De Monsyne <dragondm@integral.org>
ESMTP support, test code and doc fixes added by ESMTP support, test code and doc fixes added by
@ -14,7 +15,7 @@ This should follow RFC 821 (SMTP) and RFC 1869 (ESMTP).
Notes: Notes:
Please remember, when doing ESMTP, that the names of the SMTP service Please remember, when doing ESMTP, that the names of the SMTP service
extensions are NOT the same thing as the option keyords for the RCPT extensions are NOT the same thing as the option keywords for the RCPT
and MAIL commands! and MAIL commands!
Example: Example:
@ -37,7 +38,7 @@ End of HELP info
(250, "Somebody OverHere <somebody@here.my.org>") (250, "Somebody OverHere <somebody@here.my.org>")
>>> s.quit() >>> s.quit()
""" '''
import socket import socket
import string, re import string, re
@ -102,8 +103,8 @@ class SMTP:
dictionary. dictionary.
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 preform each SMTP comand, and there a method of the same name to perform each SMTP command, and there
is a method called 'sendmail' that will do an entiere mail is a method called 'sendmail' that will do an entire mail
transaction.""" transaction."""
debuglevel = 0 debuglevel = 0
@ -135,9 +136,9 @@ class SMTP:
def connect(self, host='localhost', port = 0): def connect(self, host='localhost', port = 0):
"""Connect to a host on a given port. """Connect to a host on a given port.
If the hostname ends with a colon (`:') followed by a number, If the hostname ends with a colon (`:') followed by a number, and
and there is no port specified, that suffix will be stripped there is no port specified, that suffix will be stripped off and the
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 specified during instantiation. if a host is specified during instantiation.
@ -257,23 +258,23 @@ 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. Resets session. """ """SMTP 'rset' command. Resets session."""
code=self.docmd("rset") code=self.docmd("rset")
return code return code
def noop(self): def noop(self):
""" SMTP 'noop' command. Doesn't do anything :> """ """SMTP 'noop' command. Doesn'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. Begins mail xfer session. """ """SMTP 'mail' command. Begins 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, ' ')
@ -281,7 +282,7 @@ class SMTP:
return self.getreply() return self.getreply()
def rcpt(self,recip,options=[]): def rcpt(self,recip,options=[]):
""" SMTP 'rcpt' command. Indicates 1 recipient for this mail. """ """SMTP 'rcpt' command. Indicates 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, ' ')
@ -289,8 +290,9 @@ class SMTP:
return self.getreply() return self.getreply()
def data(self,msg): def data(self,msg):
""" SMTP 'DATA' command. Sends message data to server. """SMTP 'DATA' command. Sends 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")
(code,repl)=self.getreply() (code,repl)=self.getreply()
if self.debuglevel >0 : print "data:", (code,repl) if self.debuglevel >0 : print "data:", (code,repl)
@ -303,45 +305,44 @@ class SMTP:
if self.debuglevel >0 : print "data:", (code,msg) if self.debuglevel >0 : print "data:", (code,msg)
return code return code
def vrfy(self, address):
return self.verify(address)
def verify(self, address): def verify(self, address):
""" SMTP 'verify' command. Checks for address validity. """ """SMTP 'verify' command. Checks for address validity."""
self.putcmd("vrfy", quoteaddr(address)) self.putcmd("vrfy", quoteaddr(address))
return self.getreply() return self.getreply()
# a.k.a.
vrfy=verify
def expn(self, address): def expn(self, address):
""" SMTP 'verify' command. Checks for address validity. """ """SMTP 'verify' command. Checks for address validity."""
self.putcmd("expn", quoteaddr(address)) self.putcmd("expn", quoteaddr(address))
return self.getreply() return self.getreply()
# some useful methods
#some useful methods
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
rcpt_options=[]): rcpt_options=[]):
""" This command performs an entire mail transaction. """This command performs an entire mail transaction.
The arguments are:
- from_addr : The address sending this mail.
- to_addrs : a list of addresses to send this mail to
(a string will be treated as a list with 1 address)
- msg : the message to send.
- mail_options : list of ESMTP options (such as 8bitmime)
for the mail command
- rcpt_options : List of ESMTP options (such as DSN commands)
for all the rcpt commands
If there has been no previous EHLO or HELO command this session,
this method tries ESMTP EHLO first. If the server does ESMTP, message
size and each of the specified options will be passed to it.
If EHLO fails, HELO will be tried and ESMTP options suppressed.
This method will return normally if the mail is accepted for at least The arguments are:
one recipient. Otherwise it will throw an exception (either - from_addr : The address sending this mail.
SMTPSenderRefused, SMTPRecipientsRefused, or SMTPDataError) - to_addrs : A list of addresses to send this mail to. A bare
That is, if this method does not throw an exception, then someone string will be treated as a list with 1 address.
should get your mail. If this method does not throw an exception, - msg : The message to send.
it returns a dictionary, with one entry for each recipient that was - mail_options : List of ESMTP options (such as 8bitmime) for the
refused. mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
all the rcpt commands.
If there has been no previous EHLO or HELO command this session, this
method tries ESMTP EHLO first. If the server does ESMTP, message size
and each of the specified options will be passed to it. If EHLO
fails, HELO will be tried and ESMTP options suppressed.
This method will return normally if the mail is accepted for at least
one recipient. Otherwise it will throw an exception (either
SMTPSenderRefused, SMTPRecipientsRefused, or SMTPDataError) That is,
if this method does not throw an exception, then someone should get
your mail. If this method does not throw an exception, it returns a
dictionary, with one entry for each recipient that was refused.
Example: Example:
@ -357,11 +358,12 @@ class SMTP:
{ "three@three.org" : ( 550 ,"User unknown" ) } { "three@three.org" : ( 550 ,"User unknown" ) }
>>> s.quit() >>> s.quit()
In the above example, the message was accepted for delivery to In the above example, the message was accepted for delivery to three
three of the four addresses, and one was rejected, with the error of the four addresses, and one was rejected, with the error code
code 550. If all addresses are accepted, then the method 550. If all addresses are accepted, then the method will return an
will return an empty dictionary. empty dictionary.
"""
"""
if not self.helo_resp and not self.ehlo_resp: if not self.helo_resp and not self.ehlo_resp:
if self.ehlo() >= 400: if self.ehlo() >= 400:
self.helo() self.helo()
@ -412,6 +414,7 @@ class SMTP:
self.docmd("quit") self.docmd("quit")
self.close() self.close()
# Test the sendmail method, which tests most of the others. # Test the sendmail method, which tests most of the others.
# Note: This always sends to localhost. # Note: This always sends to localhost.
if __name__ == '__main__': if __name__ == '__main__':