N
u9c       sK    d  Z  ( * k Z + k Z , k Z - k Z . k Z 0 d Z 1 d Z 4 d e f d     YZ	 7 d e	 f d     YZ
 ? d e	 f d     YZ M d	 e f d
     YZ Y d e f d     YZ f d e f d     YZ i d e f d     YZ l d e f d     YZ o d   Z  d   Z  d f  d     YZ e d j o k Z k Z d   Z e d  Z e i e d  d  Z d GHd Z xA d o6 e i i   Z e o Pn 	e e Z qW
d e e  GHe d   Z e i  d  e i! e e e  e i"   n d! S("   s  SMTP/ESMTP client class.

Author: The Dragon De Monsyne <dragondm@integral.org>
ESMTP support, test code and doc fixes added by
    Eric S. Raymond <esr@thyrsus.com>
Better RFC 821 compliance (MAIL and RCPT, and CRLF in data)
    by Carey Evans <c.evans@clear.net.nz>, for picky mail servers.
   
This was modified from the Python 1.5 library HTTP lib.

This should follow RFC 821 (SMTP) and RFC 1869 (ESMTP).

Notes:

Please remember, when doing ESMTP, that the names of the SMTP service
extensions are NOT the same thing as the option keywords for the RCPT
and MAIL commands!

Example:

  >>> import smtplib
  >>> s=smtplib.SMTP("localhost")
  >>> print s.help()
  This is Sendmail version 8.8.4
  Topics:
      HELO    EHLO    MAIL    RCPT    DATA
      RSET    NOOP    QUIT    HELP    VRFY
      EXPN    VERB    ETRN    DSN
  For more info use "HELP <topic>".
  To report bugs in the implementation send email to
      sendmail-bugs@sendmail.org.
  For local information send email to Postmaster at your site.
  End of HELP info
  >>> s.putcmd("vrfy","someone@here")
  >>> s.getreply()
  (250, "Somebody OverHere <somebody@here.my.org>")
  >>> s.quit()
i   s   
s   SMTPExceptionc      s   4 d  Z  5 RS(   s4   Base class for all exceptions raised by this module.(   s   __doc__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPException4 s   	s   SMTPServerDisconnectedc      s   7 d  Z  = RS(   s   Not connected to any SMTP server.

    This exception is raised when the server unexpectedly disconnects,
    or when an attempt is made to use the SMTP instance before
    connecting it to a server.
    (   s   __doc__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPServerDisconnected7 s   	s   SMTPResponseExceptionc      s   ? d  Z  F H d   Z RS(   s2  Base class for all exceptions that include an SMTP error code.

    These exceptions are generated in some instances when the SMTP
    server returns an error code.  The error code is stored in the
    `smtp_code' attribute of the error, and the `smtp_error' attribute
    is set to the error message.
    c    s1   H I | |  _ J | |  _ K | | f |  _ d  S(   N(   s   codes   selfs	   smtp_codes   msgs
   smtp_errors   args(   s   selfs   codes   msgs+   /usr/lib/python1.5/site-packages/smtplib.pys   __init__H s   (   s   __doc__s   __init__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPResponseException? s   	s   SMTPSenderRefusedc      s   M d  Z  Q S d   Z RS(   s   Sender address refused.
    In addition to the attributes set by on all SMTPResponseException
    exceptions, this sets `sender' to the string that the SMTP refused
    c    s@   S T | |  _ U | |  _ V | |  _ W | | | f |  _ d  S(   N(   s   codes   selfs	   smtp_codes   msgs
   smtp_errors   senders   args(   s   selfs   codes   msgs   senders+   /usr/lib/python1.5/site-packages/smtplib.pys   __init__S s   (   s   __doc__s   __init__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPSenderRefusedM s   	s   SMTPRecipientsRefusedc      s   Y d  Z  ^ ` d   Z RS(   s   All recipient  addresses refused.
    The errors for each recipient are accessable thru the attribute
    'recipients', which is a dictionary of exactly the same sort as 
    SMTP.sendmail() returns.  
    c    s"   ` a | |  _  b | f |  _ d  S(   N(   s
   recipientss   selfs   args(   s   selfs
   recipientss+   /usr/lib/python1.5/site-packages/smtplib.pys   __init__` s   (   s   __doc__s   __init__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPRecipientsRefusedY s   	s   SMTPDataErrorc      s   f d  Z  g RS(   s'   The SMTP server didn't accept the data.(   s   __doc__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPDataErrorf s   	s   SMTPConnectErrorc      s   i d  Z  j RS(   s%   Error during connection establishment(   s   __doc__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPConnectErrori s   	s   SMTPHeloErrorc      s   l d  Z  m RS(   s!   The server refused our HELO reply(   s   __doc__(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTPHeloErrorl s   	c    sm   o s t t  } u y v t i |   d } Wn w t j
 o
 x n Xy | o { |  Sn } d | Sd S(   s   Quote a subset of the email addresses defined by RFC 821.

    Should be able to handle anything rfc822.parseaddr can handle.
    i   s   <%s>N(   s   Nones   ms   rfc822s	   parseaddrs   addrs   AttributeError(   s   addrs   ms+   /usr/lib/python1.5/site-packages/smtplib.pys	   quoteaddro s   	c    s2      t  i d d  t  i d t |    Sd S(   s   Quote data for email.

    Double leading '.', and change Unix newline '
', or Mac '' into
    Internet CRLF end-of-line.
    s   (?m)^\.s   ..s   (?:\r\n|\n|\r(?!\n))N(   s   res   subs   CRLFs   data(   s   datas+   /usr/lib/python1.5/site-packages/smtplib.pys	   quotedata s   s   SMTPc      sg   d  Z    d Z  e Z  e Z  e Z  d Z  d d d  Z  d   Z  d d d  Z	  d   Z
  d d  Z  d	   Z d d
  Z d d  Z (d d  Z Fd   Z Jd d  Z Pd   Z Td   Z Xg  d  Z `g  d  Z hd   Z |d   Z e Z d   Z g  g  d  Z d   Z d   Z RS(   s  This class manages a connection to an SMTP or ESMTP server.
    SMTP Objects:
        SMTP objects have the following attributes:    
            helo_resp 
                This is the message given by the server in responce to the 
                most recent HELO command.
                
            ehlo_resp
                This is the message given by the server in responce to the 
                most recent EHLO command. This is usually multiline.

            does_esmtp 
                This is a True value _after you do an EHLO command_, if the
                server supports ESMTP.

            esmtp_features 
                This is a dictionary, which, if the server supports ESMTP,
                will  _after you do an EHLO command_, contain the names of the
                SMTP service  extentions this server supports, and their 
                parameters (if any).
                Note, all extention names are mapped to lower case in the 
                dictionary. 

        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 
            is a method called 'sendmail' that will do an entire mail 
            transaction.
    i    c    se      h  |  _  | oE  |  i | |  \ } }  | d j o  t | |   n n d S(   sE  Initialize a new instance.

        If specified, `host' is the name of the remote host to which to
        connect.  If specified, `port' specifies the port to which to connect.
        By default, smtplib.SMTP_PORT is used.  An SMTPConnectError is
        raised if the specified `host' doesn't respond correctly.

        i   N(   s   selfs   esmtp_featuress   hosts   connects   ports   codes   msgs   SMTPConnectError(   s   selfs   hosts   ports   codes   msgs+   /usr/lib/python1.5/site-packages/smtplib.pys   __init__ s   
s    c    s      | |  _  d S(   s   Set the debug output level.

        A non-false value results in debug messages for connection and for all
        messages sent to and received from the server.

        N(   s
   debuglevels   self(   s   selfs
   debuglevels+   /usr/lib/python1.5/site-packages/smtplib.pys   set_debuglevel s   c    sa     | o  t i | d  }  | d j oi  | |  | | d f \ } }  y  t i |  } Wn(  t i j
 o  t i d  n Xn n  | o  t	 } n  t i t i
 t i  |  _  |  i d j o  d G| | f GHn  |  i i | |   |  i   \ } }  |  i d j o  d G| GHn  | | f Sd S(   sp  Connect to a host on a given port.

        If the hostname ends with a colon (`:') followed by a number, and
        there is no port specified, that suffix will be stripped off and the
        number interpreted as the port number to use.

        Note: This method is automatically invoked by __init__, if a host is
        specified during instantiation.

        s   :i    i   s   nonnumeric ports   connect:N(   s   ports   strings   finds   hosts   is   atois
   atoi_errors   sockets   errors	   SMTP_PORTs   AF_INETs   SOCK_STREAMs   selfs   socks
   debuglevels   connects   getreplys   codes   msg(   s   selfs   hosts   ports   is   codes   msgs+   /usr/lib/python1.5/site-packages/smtplib.pys   connect s&   
!    s	   localhostc    s      |  i d j o  d G| GHn  |  i oI  y  |  i i |  Wn(  t i j
 o  t d   n Xn  t d   d S(   s   Send `str' to the server.i    s   send:s   Server not connecteds   please run connect() firstN(   s   selfs
   debuglevels   strs   socks   sends   sockets   errors   SMTPServerDisconnected(   s   selfs   strs+   /usr/lib/python1.5/site-packages/smtplib.pys   send s    c    s0      d | | t f }  |  i |  d S(   s   Send a command to the server.s   %s %s%sN(   s   cmds   argss   CRLFs   strs   selfs   send(   s   selfs   cmds   argss   strs+   /usr/lib/python1.5/site-packages/smtplib.pys   putcmd s   c    s     g  }  |  i t j o  |  i i d  |  _ n  x  d o  |  i i   }  | d j o   |  i   t	 d   n |  i
 d j o d G| GHn | i t i | d   | d  } y t i |  } Wn$ 	t j
 o 
d } Pn X| d d !d	 j o Pn qD Wt i | d
  } |  i
 d j o d | | f GHn | | f Sd S(   s  Get a reply from the server.
        
        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 string corresponding to response code (multiline
            responses are converted to a single, multiline string).

        Raises SMTPServerDisconnected if end-of-file is reached.
        s   rbi   s    s   Connection unexpectedly closedi    s   reply:i   i   s   -s   
s   reply: retcode (%s); Msg: %sN(   s   resps   selfs   files   Nones   socks   makefiles   readlines   lines   closes   SMTPServerDisconnecteds
   debuglevels   appends   strings   strips   codes   atois   errcodes
   ValueErrors   joins   errmsg(   s   selfs   resps   lines   codes   errcodes   errmsgs+   /usr/lib/python1.5/site-packages/smtplib.pys   getreply s2   	 
 
	c    s*   |  i | |  |  i   Sd S(   s-   Send a command, and return its response code.N(   s   selfs   putcmds   cmds   argss   getreply(   s   selfs   cmds   argss+   /usr/lib/python1.5/site-packages/smtplib.pys   docmds   c    s    t  i |  } !t |  d j o  "t i t i    d } n #|  i d |  $|  i	   \ } } %| |  _ &| | f Sd S(   sw   SMTP 'helo' command.
        Hostname to send for this command defaults to the FQDN of the local
        host.
        i    s   heloN(   s   strings   strips   names   lens   sockets   gethostbyaddrs   gethostnames   selfs   putcmds   getreplys   codes   msgs	   helo_resp(   s   selfs   names   codes   msgs+   /usr/lib/python1.5/site-packages/smtplib.pys   helos    c 	   s  (,-t  i |  } .t |  d j o  /t i t i    d } n 0|  i d |  1|  i	   \ } } 5| d j o t |  d j o 6t d   n 7| |  _ 8| d j o 9| | f Sn :d |  _ <t  i |  i d  } =| d =>x | d >rv } ?t i d |  } @| oQ At  i | i d   } Bt  i | i  | i d   } C| |  i | <n qWD| | f Sd	 S(
   sx    SMTP 'ehlo' command.
        Hostname to send for this command defaults to the FQDN of the local
        host.
        i    s   ehloi   s   Server not connectedi   s   
s&   (?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*)s   featureN(   s   strings   strips   names   lens   sockets   gethostbyaddrs   gethostnames   selfs   putcmds   getreplys   codes   msgs   SMTPServerDisconnecteds	   ehlo_resps
   does_esmtps   splits   resps   eachs   res   matchs   ms   lowers   groups   features   ends   paramss   esmtp_features(	   s   selfs   names   codes   msgs   resps   eachs   ms   features   paramss+   /usr/lib/python1.5/site-packages/smtplib.pys   ehlo(s,    $
 	
"c    s&   FGH|  i i t i |   Sd S(   s7   Does the server support a given SMTP service extension?N(   s   selfs   esmtp_featuress   has_keys   strings   lowers   opt(   s   selfs   opts+   /usr/lib/python1.5/site-packages/smtplib.pys   has_extnFs   c    s*   JLM|  i d |  N|  i   Sd S(   s;   SMTP 'help' command.
        Returns help text from server.s   helpN(   s   selfs   putcmds   argss   getreply(   s   selfs   argss+   /usr/lib/python1.5/site-packages/smtplib.pys   helpJs   c    s   PQR|  i d  Sd S(   s&   SMTP 'rset' command -- resets session.s   rsetN(   s   selfs   docmd(   s   selfs+   /usr/lib/python1.5/site-packages/smtplib.pys   rsetPs   c    s   TUV|  i d  Sd S(   s-   SMTP 'noop' command -- doesn't do anything :>s   noopN(   s   selfs   docmd(   s   selfs+   /usr/lib/python1.5/site-packages/smtplib.pys   noopTs   c    sp   XYZd } [| o |  i o \t i | d  } n ]|  i d d t |  | f  ^|  i	   Sd S(   s0   SMTP 'mail' command -- begins mail xfer session.s    s    s   mails
   FROM:%s %sN(
   s
   optionlists   optionss   selfs
   does_esmtps   strings   joins   putcmds	   quoteaddrs   senders   getreply(   s   selfs   senders   optionss
   optionlists+   /usr/lib/python1.5/site-packages/smtplib.pys   mailXs   	#c    st   `abd } c| o |  i o dd t i | d  } n e|  i d d t |  | f  f|  i	   Sd S(   s;   SMTP 'rcpt' command -- indicates 1 recipient for this mail.s    s    s   rcpts   TO:%s%sN(
   s
   optionlists   optionss   selfs
   does_esmtps   strings   joins   putcmds	   quoteaddrs   recips   getreply(   s   selfs   recips   optionss
   optionlists+   /usr/lib/python1.5/site-packages/smtplib.pys   rcpt`s   	#c    s   hop|  i d  q|  i   \ } } r|  i d j o rd G| | f GHn s| d j o tt | |   n| v|  i t |   w|  i d t
 t
 f  x|  i   \ } } y|  i d j o yd G| | f GHn z| | f Sd S(   sI  SMTP 'DATA' command -- sends message data to server. 

        Automatically quotes lines beginning with a period per rfc821.
        Raises SMTPDataError if there is an unexpected reply to the
        DATA command; the return value from this method is the final
        response code received when the all data is sent.
        s   datai    s   data:ib  s   %s.%sN(   s   selfs   putcmds   getreplys   codes   repls
   debuglevels   SMTPDataErrors   sends	   quotedatas   msgs   CRLF(   s   selfs   msgs   codes   repls+   /usr/lib/python1.5/site-packages/smtplib.pys   datahs     c    s0   |}~|  i d t |   |  i   Sd S(   s5   SMTP 'verify' command -- checks for address validity.s   vrfyN(   s   selfs   putcmds	   quoteaddrs   addresss   getreply(   s   selfs   addresss+   /usr/lib/python1.5/site-packages/smtplib.pys   verify|s   c    s0   |  i d t |   |  i   Sd S(   s5   SMTP 'verify' command -- checks for address validity.s   expnN(   s   selfs   putcmds	   quoteaddrs   addresss   getreply(   s   selfs   addresss+   /usr/lib/python1.5/site-packages/smtplib.pys   expns   c    s  |  i t j o |  i t j o d |  i   d j o
 d j n oQ |  i   \ } } d | j o
 d j n o t | |   n n n g  } |  i
 o_ |  i d  o | i d t |   n x# | d r }	 | i |	  q Wn |  i | |  \ } } | d j o& |  i   t | | |   n h  }
 t |  t i j o | g } n xb | d rU } |  i | |  \ } } | d j o
 | d j o | | f |
 | <n qWt |
  t |  j o  |  i   t |
   n |  i |  \ } } | d j o# |  i   t | |   n |
 Sd S(	   s	  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 bare
                             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
        one recipient. It returns a dictionary, with one entry for each
        recipient that was refused.  Each entry contains a tuple of
        the SMTP error code and the accompanying error message sent by
        the server.

        This method may raise the following exceptions:

         SMTPHeloError          The server didn't reply properly to
                                the helo greeting. 
         SMTPRecipientsRefused  The server rejected for ALL recipients
                                (no mail was sent).
         SMTPSenderRefused      The server didn't accept the from_addr.
         SMTPDataError          The server replied with an unexpected
                                error code (other than a refusal of
                                a recipient).

        Note: the connection will be open even after an exception is raised.

        Example:
      
         >>> import smtplib
         >>> s=smtplib.SMTP("localhost")
         >>> tolist=["one@one.org","two@two.org","three@three.org","four@four.org"]
         >>> msg = '''
         ... From: Me@my.org
         ... Subject: testin'...
         ...
         ... This is a test '''
         >>> s.sendmail("me@my.org",tolist,msg)
         { "three@three.org" : ( 550 ,"User unknown" ) }
         >>> s.quit()
        
        In the above example, the message was accepted for delivery to three
        of the four addresses, and one was rejected, with the error code
        550. If all addresses are accepted, then the method will return an
        empty dictionary.

        i   i    i+  s   sizes   size=i   i   N(    s   selfs	   helo_resps   Nones	   ehlo_resps   ehlos   helos   codes   resps   SMTPHeloErrors
   esmtp_optss
   does_esmtps   has_extns   appends   lens   msgs   mail_optionss   options   mails	   from_addrs   rsets   SMTPSenderRefuseds   senderrss   types   to_addrss   typess
   StringTypes   eachs   rcpts   rcpt_optionss   SMTPRecipientsRefuseds   datas   SMTPDataError(   s   selfs	   from_addrs   to_addrss   msgs   mail_optionss   rcpt_optionss   codes   resps
   esmtp_optss   options   senderrss   eachs+   /usr/lib/python1.5/site-packages/smtplib.pys   sendmailsB   9#,"	 		 	c    sd   |  i o |  i i   n t |  _ |  i o |  i i   n t |  _ d S(   s(   Close the connection to the SMTP server.N(   s   selfs   files   closes   Nones   sock(   s   selfs+   /usr/lib/python1.5/site-packages/smtplib.pys   closes   c    s'   |  i d  |  i   d S(   s   Terminate the SMTP session.s   quitN(   s   selfs   docmds   close(   s   selfs+   /usr/lib/python1.5/site-packages/smtplib.pys   quits   (   s   __doc__s
   debuglevels   Nones   files	   helo_resps	   ehlo_resps
   does_esmtps   __init__s   set_debuglevels   connects   sends   putcmds   getreplys   docmds   helos   ehlos   has_extns   helps   rsets   noops   mails   rcpts   datas   verifys   vrfys   expns   sendmails   closes   quit(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   SMTP s8   							(	_
s   __main__c    s7   t  i i |  d  t i t  i i    Sd  S(   Ns   : (   s   syss   stdouts   writes   prompts   strings   strips   stdins   readline(   s   prompts+   /usr/lib/python1.5/site-packages/smtplib.pys   prompts   s   Froms   Tos   ,s   Enter message, end with ^D:s    i   s   Message length is s	   localhostN(#   s   __doc__s   sockets   strings   res   rfc822s   typess	   SMTP_PORTs   CRLFs	   Exceptions   SMTPExceptions   SMTPServerDisconnecteds   SMTPResponseExceptions   SMTPSenderRefuseds   SMTPRecipientsRefuseds   SMTPDataErrors   SMTPConnectErrors   SMTPHeloErrors	   quoteaddrs	   quotedatas   SMTPs   __name__s   syss   prompts   fromaddrs   splitfieldss   toaddrss   msgs   stdins   readlines   lines   lens   servers   set_debuglevels   sendmails   quit(    s+   /usr/lib/python1.5/site-packages/smtplib.pys   ?( sJ   								 s	 
