ó
Ú"wTc        	   @   sy  d  Z  d d d d d d d d d	 g	 Z d
 d l Z d
 d l Z d
 d l Z d
 d l Z d
 d l Z d
 d l Z d
 d l	 Td
 d l
 Td
 d l Td e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   su  Classes implementing destinations (files, directories, or programs getmail
can deliver mail to).

Currently implemented:

  Maildir
  Mboxrd
  MDA_qmaillocal (deliver though qmail-local as external MDA)
  MDA_external (deliver through an arbitrary external MDA)
  MultiSorter (deliver to a selection of maildirs/mbox files based on matching
    recipient address patterns)
t   DeliverySkeletont   Maildirt   Mboxrdt   MDA_qmaillocalt   MDA_externalt   MultiDestinationBaset   MultiDestinationt   MultiSorterBaset   MultiSorteriÿÿÿÿN(   t   *c           B   s/   e  Z d  Z d „  Z d „  Z e e d „ Z RS(   sÉ  Base class for implementing message-delivery classes.

    Sub-classes should provide the following data attributes and methods:

      _confitems - a tuple of dictionaries representing the parameters the class
                   takes.  Each dictionary should contain the following key,
                   value pairs:
                     - name - parameter name
                     - type - a type function to compare the parameter value
                     against (i.e. str, int, bool)
                     - default - optional default value.  If not preseent, the
                     parameter is required.

      __str__(self) - return a simple string representing the class instance.

      showconf(self) - log a message representing the instance and configuration
                       from self._confstring().

      initialize(self) - process instantiation parameters from self.conf.
                         Raise getmailConfigurationError on errors.  Do any
                         other validation necessary, and set self.__initialized
                         when done.

      retriever_info(self, retriever) - extract information from retriever and
                        store it for use in message deliveries.

      _deliver_message(self, msg, delivered_to, received) - accept the message
                        and deliver it, returning a string describing the
                        result.

    See the Maildir class for a good, simple example.
    c         K   s|   t  j |  |  y |  j ƒ  Wn# t k
 rC } t d | ƒ ‚ n Xd  |  _ d  |  _ d  |  _ d  |  _	 |  j
 j d ƒ d  S(   Ns+   missing required configuration parameter %ss   done
(   t   ConfigurableBaset   __init__t
   initializet   KeyErrort   getmailConfigurationErrort   Nonet   received_fromt   received_witht   received_byt	   retrievert   logt   trace(   t   selft   argst   o(    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   I   s    				c         C   s>   |  j  j ƒ  | j |  _ | j |  _ | j |  _ | |  _ d  S(   N(   R   R   R   R   R   R   (   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   retriever_infoW   s
    c         C   sD   |  j  j ƒ  |  j | _ |  j | _ |  j | _ |  j | | | ƒ S(   N(   R   R   R   R   R   t   _deliver_message(   R   t   msgt   delivered_tot   received(    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   deliver_message^   s
    (   t   __name__t
   __module__t   __doc__R   R   t   TrueR   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR    (   s    		c        
   B   s   e  Z d  Z e d d d e ƒ e d d ƒ e d d d e d d ƒ e d d d e d d ƒ f Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z RS(   s¦   Maildir destination.

    Parameters:

      path - path to maildir, which will be expanded for leading '~/' or
      '~USER/', as well as environment variables.
    t   namet   configparsert   requiredt   patht   usert   defaultt   filemodet   0600c         C   sz   |  j  j ƒ  t ƒ  |  _ d |  _ y! t |  j d d ƒ |  j d <Wn0 t k
 ru } t d |  j d | f ƒ ‚ n Xd  S(   Ni    R)   i   s   filemode %s not valid: %s(	   R   R   t   localhostnamet   hostnamet   dcountt   intt   conft
   ValueErrorR   (   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   u   s    	!c         C   s   |  j  j ƒ  d |  j d S(   Ns
   Maildir %sR&   (   R   R   R/   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   __str__   s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   Maildir(%s)
(   R   t   infot   _confstring(   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   showconfƒ   s    c   
      C   s5  yà t  j d k rp | r+ t d	 | | ƒ n  t  j ƒ  d k rL t d ƒ ‚ n  t  j ƒ  d k rp t d ƒ ‚ qp n  t |  j d | j	 | | ƒ |  j
 |  j |  j d ƒ } | j | ƒ | j ƒ  t  j | j ƒ  ƒ t  j d ƒ WnN t k
 r0}	 | j d |	 ƒ | j ƒ  t  j | j ƒ  ƒ t  j d ƒ n Xd	 S(
   s7   Delivery method run in separate child process.
        t   posixi    s   refuse to deliver mail as roots   refuse to deliver mail as GID 0R&   R)   s$   maildir delivery process failed (%s)i   N(   t   osR#   t   change_uidgidR   t   geteuidR   t   getegidt   deliver_maildirR/   t   flattenR,   R-   t   writet   flusht   fsynct   filenot   _exitt   StandardError(
   R   t   uidt   gidR   R   R   t   stdoutt   stderrt   fR   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   __deliver_message_maildir†   s,    

c         C   sÇ  |  j  j ƒ  d  } d  } |  j d } t j d k r§ | r§ t | ƒ t j ƒ  k r§ t | ƒ } t | ƒ } | d k r† t	 d ƒ ‚ n  | d k r¤ t	 d ƒ ‚ q¤ q§ n  |  j
 ƒ  t j ƒ  } t j ƒ  } t j ƒ  }	 |	 sý |  j | | | | | | | ƒ n  |  j  j d |	 ƒ |  j |	 ƒ }
 | j d ƒ | j d ƒ | j ƒ  j ƒ  } | j ƒ  j ƒ  } |  j  j d |	 |
 f ƒ |
 s„| r t d |	 |
 | f ƒ ‚ n  |  j d	 7_ |  j  j d
 | ƒ |  S(   NR'   R5   i    s   refuse to deliver mail as roots   refuse to deliver mail as GID 0s   spawned child %d
s&   maildir delivery process %d exited %d
s"   maildir delivery %d error (%d, %s)i   s   maildir file %s(   R   R   R   R/   R6   R#   t   uid_of_userR8   t
   gid_of_uidR   t   _prepare_childt   tempfilet   TemporaryFilet   forkt!   _Maildir__deliver_message_maildirt   debugt   _wait_for_childt   seekt   readt   stript   getmailDeliveryErrorR-   (   R   R   R   R   RB   RC   R'   RD   RE   t   childpidt   exitcodet   outt   err(    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   ¦   sF    
N(   R   R    R!   t   ConfInstancet   Falset   ConfMaildirPatht
   ConfStringR   t
   _confitemsR   R1   R4   RN   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   f   s   	
			 c        
   B   s   e  Z d  Z e d d d e ƒ e d d ƒ e d d d e d d ƒ e d d d e d d ƒ f Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z RS(   sÕ  mboxrd destination with fcntl-style locking.

    Parameters:

      path - path to mboxrd file, which will be expanded for leading '~/'
      or '~USER/', as well as environment variables.

    Note the differences between various subtypes of mbox format (mboxrd, mboxo,
    mboxcl, mboxcl2) and differences in locking; see the following for details:
    http://qmail.org/man/man5/mbox.html
    http://groups.google.com/groups?selm=4ivk9s%24bok%40hustle.rahul.net
    R#   R$   R%   R&   t   locktypeR(   t   lockfR'   c         C   s>   |  j  j ƒ  |  j d d k r: t d |  j d ƒ ‚ n  d  S(   NR^   R_   t   flocks   unknown mbox lock type: %s(   R_   R`   (   R   R   R/   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   ë   s    c         C   s   |  j  j ƒ  d |  j d S(   Ns	   Mboxrd %sR&   (   R   R   R/   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   ñ   s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   Mboxrd(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4   õ   s    c         C   sE  yðt  j d k rp | r+ t d | | ƒ n  t  j ƒ  d k rL t d ƒ ‚ n  t  j ƒ  d k rp t d ƒ ‚ qp n  t  j j |  j	 d ƒ s£ t
 d |  j	 d ƒ ‚ n  t  j j |  j	 d ƒ sÖ t
 d |  j	 d ƒ ‚ n  t  j |  j	 d t  j ƒ } t  j | ƒ }	 t  j | d ƒ }
 t |
 |  j	 d	 ƒ |
 j d d ƒ |
 j ƒ  } | r‡| j d
 ƒ r‡t |
 |  j	 d	 ƒ t
 d |  j	 d ƒ ‚ n  |
 j d d ƒ yÑ |
 j | j | | d t d t ƒt  j ƒ |
 j ƒ  t  j | ƒ t  j | ƒ } y' t  j |  j	 d |	 j | j f ƒ Wn= t k
 rR} | j d ƒ | j ƒ  t  j | j ƒ  ƒ n Xt |
 |  j	 d	 ƒ Wnw t  k
 rá} y  |
 j! s™|
 j" |	 j# ƒ n  Wn$ t$ k
 r°‚  n t% k
 rÀn Xt
 d |  j	 d | f ƒ ‚ n Xt  j& d ƒ WnN t% k
 r@} | j d | ƒ | j ƒ  t  j | j ƒ  ƒ t  j& d ƒ n Xd S(   s7   Delivery method run in separate child process.
        R5   i    s   refuse to deliver mail as roots   refuse to deliver mail as GID 0R&   s   mboxrd does not exist (%s)s   not an mboxrd file (%s)s   r+bR^   s   From i   t   include_fromt   mangle_froms%   failed to updated mtime/atime of mboxs.   failure writing message to mbox file "%s" (%s)s!   mbox delivery process failed (%s)i   N('   R6   R#   R7   R   R8   R   R9   R&   t   existsR/   RT   t   isfilet   opent   O_RDWRt   fstatt   fdopent	   lock_fileRQ   t   readlinet
   startswitht   unlock_fileR<   R;   R"   t   linesepR=   R>   t   utimet   st_atimet   st_mtimet   OSErrorR?   t   IOErrort   closedt   truncatet   st_sizet   KeyboardInterruptRA   R@   (   R   RB   RC   R   R   R   RD   RE   t   fdt
   status_oldRF   t
   first_linet
   status_newR   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   __deliver_message_mboxø   st    

	
c         C   s×  |  j  j ƒ  d  } d  } t j |  j d ƒ } |  j d } t j d k r½ | r„ t | ƒ t j ƒ  k r„ t | ƒ } t	 | ƒ } n  | d k rŸ t
 d ƒ ‚ n  | d k r½ t
 d ƒ ‚ q½ n  |  j ƒ  t j ƒ  } t j ƒ  }	 t j ƒ  }
 |
 s|  j | | | | | | |	 ƒ n  |  j  j d |
 ƒ |  j |
 ƒ } | j d ƒ |	 j d ƒ | j ƒ  j ƒ  } |	 j ƒ  j ƒ  } |  j  j d |
 | f ƒ | sš| r¶t d	 |
 | | f ƒ ‚ n  | rÓ|  j  j d
 | ƒ n  |  S(   NR&   R'   R5   i    s   refuse to deliver mail as roots   refuse to deliver mail as GID 0s   spawned child %d
s%   mboxrd delivery process %d exited %d
s!   mboxrd delivery %d error (%d, %s)s   mbox delivery: %s(   R   R   R   R6   t   statR/   R#   RH   R8   RI   R   RJ   RK   RL   RM   t   _Mboxrd__deliver_message_mboxRO   RP   RQ   RR   RS   RT   (   R   R   R   R   RB   RC   t   st_mboxR'   RD   RE   RU   RV   RW   RX   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   P  sH    
N(   R   R    R!   RY   RZ   t   ConfMboxPathR\   R   R]   R   R1   R4   R}   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   ×   s   				Xc           B   sj  e  Z d  Z e d d d e ƒ e d d d e d d ƒ e d d d e d e j e	 j
 ƒ  ƒ j ƒ e d d d e d d ƒ e d d	 d e d e j e	 j
 ƒ  ƒ j ƒ e d d
 d e d e ƒ  ƒ e d d d e d d ƒ e d d d e d d ƒ e d d d e d d ƒ e d d d e d e ƒ e d d d e d e ƒ f Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s6  qmail-local MDA destination.

    Passes the message to qmail-local for delivery.  qmail-local is invoked as:

      qmail-local -nN user homedir local dash ext domain sender defaultdelivery

    Parameters (all optional):

      qmaillocal - complete path to the qmail-local binary.  Defaults
                to "/var/qmail/bin/qmail-local".

      user - username supplied to qmail-local as the "user" argument.  Defaults
            to the login name of the current effective user ID.  If supplied,
            getmail will also change the effective UID to that of the user
            before running qmail-local.

      group - If supplied, getmail will change the effective GID to that of the
            named group before running qmail-local.

      homedir - complete path to the directory supplied to qmail-local as the
            "homedir" argument. Defaults to the home directory of the current
            effective user ID.

      localdomain - supplied to qmail-local as the "domain" argument.  Defaults
            to localhostname().

      defaultdelivery - supplied to qmail-local as the "defaultdelivery"
            argument.  Defaults to "./Maildir/".

      conf-break - supplied to qmail-local as the "dash" argument and used to
            calculate ext from local.  Defaults to "-".

      localpart_translate - a string representing a Python 2-tuple of strings
            (i.e. "('foo', 'bar')"). If supplied, the retrieved message
            recipient address will have any leading instance of "foo" replaced
            with "bar" before being broken into "local" and "ext" for qmail-
            local (according to the values of "conf-break" and "user").  This
            can be used to add or remove a prefix of the address.

      strip_delivered_to - if set, existing Delivered-To: header fields will be
            removed from the message before processing by qmail-local.  This may
            be necessary to prevent qmail-local falsely detecting a looping
            message if (for instance) the system retrieving messages otherwise
            believes it has the same domain name as the POP server.
            Inappropriate use, however, may cause message loops.

      allow_root_commands (boolean, optional) - if set, external commands are
            allowed when running as root.  The default is not to allow such
            behaviour.

    For example, if getmail is run as user "exampledotorg", which has virtual
    domain "example.org" delegated to it with a virtualdomains entry of
    "example.org:exampledotorg", and messages are retrieved with envelope
    recipients like "trimtext-localpart@example.org", the messages could be
    properly passed to qmail-local with a localpart_translate value of
    "('trimtext-', '')" (and perhaps a defaultdelivery value of
    "./Maildirs/postmaster/" or similar).
    R#   R$   R%   t
   qmaillocalR(   s   /var/qmail/bin/qmail-localR'   t   groupt   homedirt   localdomaint   defaultdeliverys
   ./Maildir/s
   conf-breakt   -t   localpart_translates   ('', '')t   strip_delivered_tot   allow_root_commandsc         C   s   |  j  j ƒ  d  S(   N(   R   R   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   Ó  s    c         C   s   |  j  j ƒ  d |  j ƒ  S(   Ns   MDA_qmaillocal %s(   R   R   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   Ö  s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   MDA_qmaillocal(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4   Ú  s    c   
      C   s÷  y¢|  j  d |  j  d d |  j  d |  j  d | d | d | d |  j  d | d	 |  j  d
 f } |  j j d t | ƒ ƒ |  j  d r¡ | j d ƒ d  } n  t j ƒ  } | j | j	 | | ƒ ƒ | j
 ƒ  t j | j ƒ  ƒ | j d ƒ t j | j ƒ  d ƒ t j | j ƒ  d ƒ t j | j ƒ  d ƒ t |  j |  j  d |  j  d ƒ t j ƒ  d k swt j ƒ  d k r”|  j  d r”t d ƒ ‚ n  t j | Œ  WnN t k
 rò}	 | j d |	 ƒ | j
 ƒ  t j | j ƒ  ƒ t j d ƒ n Xd  S(   NR€   s   --R'   R‚   t   localt   dasht   extRƒ   t   senderR„   s   about to execl() with args %s
R‡   s   delivered-toi    i   i   R   Rˆ   s>   refuse to invoke external commands as root or GID 0 by defaults   exec of qmail-local failed (%s)i   (   R/   R   RO   t   strt   remove_headerR   RK   RL   R<   R;   R=   R6   R>   R?   RQ   t   dup2t   change_usergroupR8   R9   R   t   execlRA   R@   (
   R   R   t   msginfoR   R   RD   RE   R   t   msgfileR   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   _deliver_qmaillocalÝ  s:    	
!$
c         C   sî  |  j  j ƒ  |  j ƒ  | j d  k r5 t d ƒ ‚ n  i | j d 6d j | j j ƒ  j	 d ƒ d  ƒ d 6} |  j  j
 d | d ƒ |  j d \ } } | s¢ | r| d j | ƒ rî |  j  j
 d | | f ƒ | | d t | ƒ | d <q|  j  j
 d	 | ƒ n  |  j  j
 d
 | d ƒ |  j d | d k rz|  j d | d <|  j d j | d j	 |  j d ƒ d ƒ | d <n d | d <d | d <|  j  j
 d | d | d f ƒ t j ƒ  } t j ƒ  } t j ƒ  }	 |	 sù|  j | | | | | | ƒ n  |  j  j
 d |	 ƒ |  j |	 ƒ }
 | j d ƒ | j d ƒ | j ƒ  j ƒ  } | j ƒ  j ƒ  } |  j  j
 d |	 |
 f ƒ |
 d k r™t d |	 | f ƒ ‚ n" |
 r»t d |	 |
 | f ƒ ‚ n  | rÚ| rÚd | | f } n | pã| } d | S(   NsX   MDA_qmaillocal destination requires a message source that preserves the message envelopeRŒ   t   @iÿÿÿÿR‰   s%   recipient: extracted local-part "%s"
R†   s$   recipient: translating "%s" to "%s"
s/   recipient: does not start with xlate_from "%s"
s&   recipient: translated local-part "%s"
s
   conf-breakRŠ   i   R‹   t    s)   recipient: set dash to "%s", ext to "%s"
s   spawned child %d
i    s   qmail-local %d exited %d
io   s#   qmail-local %d temporary error (%s)s   qmail-local %d error (%d, %s)s   %s:%ss   MDA_qmaillocal (%s)(   R   R   RJ   t	   recipientR   R   RŒ   t   joint   lowert   splitRO   R/   Rk   t   lenRK   RL   R6   RM   R”   RP   RQ   RR   RS   RT   (   R   R   R   R   R’   t
   xlate_fromt   xlate_toRD   RE   RU   RV   RW   RX   R2   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR     sf    

)(

N(   R   R    R!   RY   RZ   t   ConfFileR\   t   pwdt   getpwuidR6   R8   t   pw_nameR   t   ConfDirectoryt   pw_dirR+   t   ConfTupleOfStringst   ConfBoolR]   R   R1   R4   R”   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   „  s,   :				.c           B   sï   e  Z d  Z e d d d e ƒ e d d ƒ e d d d e d d ƒ e d d d e d d ƒ e d d	 d e d d ƒ e	 d d
 d e d e ƒ e	 d d d e d e ƒ e	 d d d e d e ƒ f Z
 d „  Z d „  Z d „  Z d „  Z d „  Z RS(   se  Arbitrary external MDA destination.

    Parameters:

      path - path to the external MDA binary.

      unixfrom - (boolean) whether to include a Unix From_ line at the beginning
                 of the message.  Defaults to False.

      arguments - a valid Python tuple of strings to be passed as arguments to
                  the command.  The following replacements are available if
                  supported by the retriever:

                    %(sender) - envelope return path
                    %(recipient) - recipient address
                    %(domain) - domain-part of recipient address
                    %(local) - local-part of recipient address
                    %(mailbox) - for IMAP retrievers, the name of the 
                        server-side mailbox/folder the message was retrieved
                        from.  Will be empty for POP.

                  Warning: the text of these replacements is taken from the
                  message and is therefore under the control of a potential
                  attacker. DO NOT PASS THESE VALUES TO A SHELL -- they may
                  contain unsafe shell metacharacters or other hostile
                  constructions.

                  example:

                    path = /path/to/mymda
                    arguments = ('--demime', '-f%(sender)', '--', '%(recipient)')

      user (string, optional) - if provided, the external command will be run as
            the specified user.  This requires that the main getmail process
            have permission to change the effective user ID.

      group (string, optional) -  if provided, the external command will be run
            with the specified group ID.  This requires that the main getmail
            process have permission to change the effective group ID.

      allow_root_commands (boolean, optional) - if set, external commands are
            allowed when running as root.  The default is not to allow such
            behaviour.

      ignore_stderr (boolean, optional) - if set, getmail will not consider the
            program writing to stderr to be an error.  The default is False.
    R#   R$   R%   R&   t	   argumentsR(   s   ()R'   R   Rˆ   t   unixfromt   ignore_stderrc         C   sš   |  j  j ƒ  t j j |  j d ƒ |  j d <t j |  j d t j ƒ sc t d |  j d ƒ ‚ n  t	 |  j d ƒ t
 k r– t d |  j d ƒ ‚ n  d  S(   NR&   t   commands   %s not executableR¦   s2   incorrect arguments format; see documentation (%s)(   R   R   R6   R&   t   basenameR/   t   accesst   X_OKR   t   typet   tuple(   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   Ž  s     c         C   s(   |  j  j ƒ  d |  j d |  j ƒ  f S(   Ns   MDA_external %s (%s)R©   (   R   R   R/   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   š  s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   MDA_external(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4   Ÿ  s    c         C   s!  y¿t  j ƒ  } | j | j | | d |  j d ƒƒ | j ƒ  t j | j ƒ  ƒ | j	 d ƒ t j
 | j ƒ  d ƒ t j
 | j ƒ  d ƒ t j
 | j ƒ  d ƒ t |  j |  j d |  j d ƒ t j ƒ  d k sæ t j ƒ  d k r|  j d rt d	 ƒ ‚ n  |  j d
 |  j d
 g } |  j j p,d | d <xa |  j d D]R }	 t |	 ƒ }	 x0 | j ƒ  D]" \ }
 } |	 j d |
 | ƒ }	 q`W| j |	 ƒ qAW|  j j d t | ƒ ƒ t j | Œ  Wn[ t k
 r} | j d |  j d | f ƒ | j ƒ  t j | j ƒ  ƒ t j d ƒ n Xd  S(   NRa   R§   i    i   i   R'   R   Rˆ   s>   refuse to invoke external commands as root or GID 0 by defaultR&   R–   t   mailboxR¦   s   %%(%s)s   about to execl() with args %s
s   exec of command %s failed (%s)R©   i   (   RK   RL   R<   R;   R/   R=   R6   R>   R?   RQ   R   R   R   R8   R9   R   R   t   mailbox_selectedt   expand_user_varst   itemst   replacet   appendRO   R   R‘   RA   R@   (   R   R   R’   R   R   RD   RE   R“   R   t   argt   keyt   valueR   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   _deliver_command¢  s<    
!$	
c         C   s  |  j  j ƒ  |  j ƒ  i  } | j | d <| j d  k rŒ | j | d <| j j ƒ  j d ƒ d | d <d j | j j d ƒ d  ƒ | d <n  |  j  j	 d | ƒ t
 j ƒ  } t
 j ƒ  } t j ƒ  } | sé |  j | | | | | | ƒ n  |  j  j	 d | ƒ |  j | ƒ } | j d	 ƒ | j d	 ƒ | j ƒ  j ƒ  }	 | j ƒ  j ƒ  }
 |  j  j	 d
 |  j d | | f ƒ | ršt d |  j d | | |
 f ƒ ‚ nS |
 rí|  j d sÐt d |  j d | |
 f ƒ ‚ n  |  j  j d |  |
 f ƒ n  d |  j d |	 f S(   NRŒ   R—   R•   iÿÿÿÿt   domainR‰   s   msginfo "%s"
s   spawned child %d
i    s   command %s %d exited %d
R©   s   command %s %d error (%d, %s)R¨   s!   command %s %d wrote to stderr: %ss   command %s: %ss   MDA_external command %s (%s)(   R   R   RJ   RŒ   R—   R   R™   Rš   R˜   RO   RK   RL   R6   RM   R¸   RP   RQ   RR   RS   R/   RT   R2   (   R   R   R   R   R’   RD   RE   RU   RV   RW   RX   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   Ì  sD    
 & N(   R   R    R!   RY   RZ   Rž   R¤   R\   R   R¥   R]   R   R1   R4   R¸   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   S  s   /				*c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   så  Base class for destinations which hand messages off to other
    destinations.

    Sub-classes must provide the following attributes and methods:

      conf - standard ConfigurableBase configuration dictionary

      log - getmailcore.logging.Logger() instance

    In addition, sub-classes must populate the following list provided by
    this base class:

      _destinations - a list of all destination objects messages could be
                      handed to by this class.
    c   
      C   sû  t  | ƒ } | j d ƒ rx| j d ƒ rx| d d !} | |  j d j ƒ  k rc t d | ƒ ‚ n  |  j j d | ƒ |  j d j | d ƒ } |  j j d	 | ƒ t	 ƒ  j | d  ƒ } t | ƒ sÞ t d
 | | f ƒ ‚ n  i |  j d d 6} xZ |  j d j | ƒ D]B \ } } | d k r'q	n  |  j j d | | f ƒ | | | <q	W|  j j d | | f ƒ | |   }	 n | j d ƒ s–| j d ƒ r·| j d ƒ r·t d | ƒ }	 n@ | j d ƒ sÕ| j d ƒ rçt d | ƒ }	 n t d | ƒ ‚ |	 S(   Nt   [t   ]i   iÿÿÿÿR$   s:   destination specifies section name %s which does not exists     getting destination for %s
R­   s       type="%s"
sG   configuration file section %s specifies incorrect destination type (%s)s       parameter %s="%s"
s.       instantiating destination %s with args %s
t   /t   .R&   s/   specified destination %s not of recognized type(   s   types   configparser(   R±   Rk   t   endswithR/   t   sectionsR   R   RO   t   gett   globalsR   t   callableR²   R   R   (
   R   R&   t   pt   destsectionnamet   destination_typet   destination_funct   destination_argsR#   R·   t   dest(    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   _get_destination  s@    	#-c         C   s   |  j  j ƒ  g  |  _ d  S(   N(   R   R   t   _destinations(   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   7  s    c         C   sB   |  j  j ƒ  t j |  | ƒ x |  j D] } | j | ƒ q' Wd S(   sK   Override base class to pass this to the encapsulated destinations.
        N(   R   R   R    R   RÊ   (   R   R   t   destination(    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   ;  s    (   R   R    R!   RÉ   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   þ  s   	(	c           B   s_   e  Z d  Z e d d d e ƒ e d d ƒ f Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s  Send messages to one or more other destination objects unconditionally.

    Parameters:

      destinations - a tuple of strings, each specifying a destination that
                messages should be delivered to.  These strings will be expanded
                for leading "~/" or "~user/" and environment variables,
                then interpreted as maildir/mbox/other-destination-section.
    R#   R$   R%   t   destinationsc         C   s¼   |  j  j ƒ  t j |  ƒ g  |  j d D] } t | ƒ ^ q( } x] | D]U } y |  j | ƒ } Wn) t k
 r‹ } t d | | f ƒ ‚ n X|  j j	 | ƒ qG W|  j s¸ t d ƒ ‚ n  d  S(   NRÌ   s   %s destination error %ss   no destinations specified(
   R   R   R   R   R/   R±   RÉ   R   RÊ   R´   (   R   t   itemt   destsRÈ   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   T  s    &	c         C   sL   |  j  j ƒ  d } x2 |  j D]' } | r6 | d 7} n  | d | 7} q W| S(   s0   Override the base class implementation.
        R–   s   , s   %s(   R   R   RÊ   (   R   t
   confstringRÈ   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR3   b  s    c         C   s   |  j  j ƒ  d |  j ƒ  S(   Ns   MultiDestination (%s)(   R   R   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   m  s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   MultiDestination(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4   q  s    c         C   s8   |  j  j ƒ  x$ |  j D] } | j | | | ƒ q W|  S(   N(   R   R   RÊ   R   (   R   R   R   R   RÈ   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   t  s    (   R   R    R!   RY   RZ   R¤   R]   R   R3   R1   R4   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   E  s   					c           B   s    e  Z d  Z d „  Z d „  Z RS(   s@   Base class for multiple destinations with address matching.
    c         C   sÒ  |  j  j ƒ  t j |  ƒ |  j |  j d ƒ |  _ |  j j |  j ƒ g  |  _	 yV|  j d } t
 | ƒ d k r© t | d ƒ t k r© t | d ƒ t k r© | f } n  xm | D]e } t | ƒ t k ot
 | ƒ d k ot | d ƒ t k ot | d ƒ t k s° t d ƒ ‚ q° q° Wxˆ | D]€ \ } } y |  j | ƒ } Wn) t k
 rj} t d | | f ƒ ‚ n X|  j	 j t j | t j ƒ | f ƒ |  j j | ƒ q WWn& t j k
 rÍ} t d | ƒ ‚ n Xd  S(	   NR(   t   localsi   i    i   s,   invalid syntax for locals; see documentations   pattern %s destination error %ss   invalid regular expression %s(   R   R   R   R   RÉ   R/   R(   RÊ   R´   t   targetsR›   R­   R   R®   R   t   ret   compilet
   IGNORECASEt   error(   R   t   _localsRÍ   t   patternR&   RÈ   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR     s2    	($,%c         C   sO   |  j  j ƒ  d |  j } x. |  j D]# \ } } | d | j | f 7} q$ W| S(   sY   
        Override the base class implementation; locals isn't readable that way.
        s
   default=%ss   , %s->%s(   R   R   R(   RÑ   R×   (   R   RÏ   R×   RË   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR3     s
    (   R   R    R!   R   R3   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   {  s   	c        	   B   se   e  Z d  Z e d d d e ƒ e d d ƒ e d d d e d d ƒ f Z d „  Z d „  Z	 d	 „  Z
 RS(
   s8  Multiple destination with envelope recipient address matching.

    Parameters:

      default - the default destination.  Messages not matching any
                "local" patterns (see below) will be delivered here.

      locals - an optional tuple of items, each being a 2-tuple of quoted
            strings. Each quoted string pair is a regular expression and a
            maildir/mbox/other destination. In the general case, an email
            address is a valid regular expression. Each pair is on a separate
            line; the second and subsequent lines need to have leading
            whitespace to be considered a continuation of the "locals"
            configuration.  If the recipient address matches a given pattern, it
            will be delivered to the corresponding destination.  A destination
            is assumed to be a maildir if it starts with a dot or slash and ends
            with a slash. A destination is assumed to be an mboxrd file if it
            starts with a dot or a slash and does not end with a slash.  A
            destination may also be specified by section name, i.e.
            "[othersectionname]". Multiple patterns may match a given recipient
            address; the message will be delivered to /all/ destinations with
            matching patterns.  Patterns are matched case-insensitively.

            example:

             default = /home/kellyw/Mail/postmaster/
             locals = (
               ("jason@example.org", "/home/jasonk/Maildir/"),
               ("sales@example.org", "/home/karlyk/Mail/sales"),
               ("abuse@(example.org|example.net)", "/home/kellyw/Mail/abuse/"),
               ("^(jeff|jefferey)(\.s(mith)?)?@.*$", "[jeff-mail-delivery]"),
               ("^.*@(mail.)?rapinder.example.org$", "/home/rapinder/Maildir/")
               )

               In it's simplest form, locals is merely a list of pairs of email
               addresses and corresponding maildir/mbox paths.  Don't worry
               about the details of regular expressions if you aren't familiar
               with them.
    R#   R$   R%   R(   RÐ   s   ()c         C   s   |  j  j ƒ  d |  j ƒ  S(   Ns   MultiSorter (%s)(   R   R   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   Ö  s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   MultiSorter(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4   Ú  s    c         C   s7  |  j  j ƒ  g  } | j d  k r: |  j r: t d ƒ ‚ n  x |  j D]„ \ } } |  j  j d | j | j f ƒ | j | j ƒ rD |  j  j d | j | f ƒ | j	 | | | ƒ | j
 t | ƒ ƒ qD qD W| s/|  j rþ |  j  j d | j |  j f ƒ n |  j  j d |  j ƒ d |  j j	 | | | ƒ Sd | S(   Nsh   MultiSorter recipient matching requires a retriever (message source) that preserves the message envelopes)   checking recipient %s against pattern %s
s   recipient %s matched target %s
s+   recipient %s not matched; using default %s
s   using default %s
s   MultiSorter (default %s)s   MultiSorter (%s)(   R   R   R—   R   RÑ   R   RO   R×   t   searchR   R´   R   R(   (   R   R   R   R   t   matchedR×   RÈ   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   Ý  s*    	(   R   R    R!   RY   RZ   R\   t   ConfTupleOfTupleOfStringsR]   R1   R4   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR   ¨  s   '		t   MultiGuesserc        	   B   se   e  Z d  Z e d d d e ƒ e d d ƒ e d d d e d d ƒ f Z d „  Z d „  Z	 d	 „  Z
 RS(
   s°   Multiple destination with header field address matching.

    Parameters:

      default - see MultiSorter for definition.

      locals - see MultiSorter for definition.

    R#   R$   R%   R(   RÐ   s   ()c         C   s   |  j  j ƒ  d |  j ƒ  S(   Ns   MultiGuesser (%s)(   R   R   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR1   	  s    c         C   s   |  j  j d |  j ƒ  ƒ d  S(   Ns   MultiGuesser(%s)
(   R   R2   R3   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR4     s    c         C   sâ  |  j  j ƒ  g  } g  } d d d d d d f } x± | D]© } xf | D]^ } |  j  j d | ƒ | j g  t j j | j | g  ƒ ƒ D] \ }	 }
 |
 r„ |
 ^ q„ ƒ qE W| rÑ |  j  j d t | ƒ | f ƒ Pq8 |  j  j d ƒ q8 Wx˜ |  j	 D] \ } } x~ | D]v }
 |  j  j d |
 | j
 f ƒ | j |
 ƒ r|  j  j d |
 | f ƒ | j | | | ƒ | j t | ƒ ƒ PqqWqï W| sÚ|  j	 r©|  j  j d |  j ƒ n |  j  j d |  j ƒ d |  j j | | | ƒ Sd | S(   Ns   delivered-tos   envelope-tos   x-envelope-tos   apparently-tos	   resent-tos	   resent-ccs
   resent-bcct   tot   cct   bccs*   looking for addresses in %s header fields
s!   found total of %d addresses (%s)
s   no addresses found, continuing
s'   checking address %s against pattern %s
s   address %s matched target %s
s'   no addresses matched; using default %s
s   using default %s
s   MultiGuesser (default %s)s   MultiGuesser (%s)(   s   delivered-to(   s   envelope-to(   s   x-envelope-to(   s   apparently-to(   s	   resent-tos	   resent-ccs
   resent-bcc(   RÜ   RÝ   RÞ   (   R   R   RO   t   extendt   emailt   Utilst   getaddressest   get_allR›   RÑ   R×   RØ   R   R´   R   R(   (   R   R   R   R   RÙ   t   header_addrst
   fieldnamest   fieldst   fieldR#   t   addrR×   RÈ   (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyR     sP    			(   R   R    R!   RY   RZ   R\   RÚ   R]   R1   R4   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyRÛ   ù  s   			(   R!   t   __all__R6   RÒ   RK   t   typest   email.UtilsRà   RŸ   t   getmailcore.exceptionst   getmailcore.utilitiest   getmailcore.baseclassesR
   R    t   ForkingBaseR   R   R   R   R   R   R   R   RÛ   (    (    (    s<   /usr/lib/python2.7/dist-packages/getmailcore/destinations.pyt   <module>   s8   	


>q­Ï«G6-Q