mò ½i™Dc @sUdZddddddddd g Zd kZd kZd kZd kZd kZd kTd k Td k Tde fd „ƒYZ de e fd „ƒYZde e fd„ƒYZde e fd„ƒYZde e fd„ƒYZde fd„ƒYZdefd„ƒYZdefd„ƒYZd efd„ƒYZdefd„ƒYZd S(suClasses 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) tDeliverySkeletontMaildirtMboxrdtMDA_qmaillocalt MDA_externaltMultiDestinationBasetMultiDestinationtMultiSorterBaset MultiSorterN(t*cBs/tZdZd„Zd„Zeed„ZRS(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. cKsuti||y|iƒWn%tj o}td|ƒ‚nXd|_ d|_ d|_ |i i dƒdS(Ns+missing required configuration parameter %ssdone (tConfigurableBaset__init__tselftargst initializetKeyErrortotgetmailConfigurationErrortNonet received_fromt received_witht received_bytlogttrace(R R R((t</usr/lib/python2.4/site-packages/getmailcore/destinations.pyR Hs   cCs5|iiƒ|i|_|i|_|i|_dS(N(R RRt retrieverRRR(R R((Rtretriever_infoTs   cCsD|iiƒ|i|_|i|_|i|_|i|||ƒS(N( R RRRtmsgRRt_deliver_messaget delivered_totreceived(R RRR((Rtdeliver_messageZs     (t__name__t __module__t__doc__R RtTrueR(((RR's  c BstZdZedddeƒeddƒedddedeƒedddeddƒfZd „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. tnamet configparsertrequiredtpathtusertdefaulttfilemodet0600cCs||iiƒtƒ|_d|_y!t|iddƒ|id             (R R!R"t ConfInstancetFalsetConfMaildirPatht ConfStringRt _confitemsRR2R5ROR(((RRbs T   c BswtZdZedddeƒeddƒedddedeƒfZd„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'R(R)cCs|iiƒdS(N(R RR(R ((RRäscCs|iiƒd|idS(Ns Mboxrd %sR'(R RRR0(R ((RR2çs cCs|iid|iƒƒdS(Ns Mboxrd(%s) (R RR3R4(R ((RR5ëscCsByëtidjoe|otd||ƒntiƒdjotdƒ‚ntiƒdjotdƒ‚qxnti i |i dƒpt d|i dƒ‚nti i|i dƒpt d|i dƒ‚nti|i dtiƒ} ti| ƒ} ti| dƒ} t| ƒ| iddƒ| iƒ}|o6|d d jo%t| ƒt d|i dƒ‚n| idd ƒyÉ| i|i||d t d t ƒti!ƒ| i"ƒti#| ƒti| ƒ} y'ti%|i d| i&| i'fƒWn?t(j o3} |idƒ|i"ƒti#|i+ƒƒnXt| ƒWnt,j os} y"| i-p| i.| i/ƒnWn(t0j o ‚nt1j onXt d|i d| fƒ‚nXti2dƒWnPt1j oD} |id| ƒ|i"ƒti#|i+ƒƒti2dƒnXdS(s7Delivery method run in separate child process. R6isrefuse to deliver mail as rootsrefuse to deliver mail as GID 0R'smboxrd does not exist (%s)snot an mboxrd file (%s)sr+bisFrom it 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)iN(4R7R$R8R9RR:R;RR<R'texistsR R0RXtisfiletopentO_RDWRtfdtfstatt status_oldtfdopenR?t lock_fileRStreadlinet first_linet unlock_fileRARR>RRR#tlinesepRBRCt status_newtutimetst_atimetst_mtimetOSErrorRR@RDtIOErrortclosedttruncatetst_sizetKeyboardInterruptRFRERG(R R8R:RRRR@RGRjRfRmRdR?R((Rt__deliver_message_mboxîsj     '   " cCsç|iiƒd}d}ti|idƒ}|id} ti djoz| o5t | ƒti ƒjot | ƒ}t|ƒ}n|djotdƒ‚n|djotdƒ‚qÆn|iƒtiƒ}tiƒ} tiƒ} | p#|i||||||| ƒn|iid| ƒ|i| ƒ} |idƒ| idƒ|iƒiƒ} | iƒiƒ}|iid| | fƒ| p|ot"d | | |fƒ‚n| o|iid | ƒn|S( NR'R(R6isrefuse to deliver mail as rootsrefuse to deliver mail as GID 0sspawned child %d s%mboxrd delivery process %d exited %d s!mboxrd delivery %d error (%d, %s)smbox delivery: %s(#R RRRR8R:R7tstatR0tst_mboxR(R$RIR;RJRRKRLR@RGRMRNt_Mboxrd__deliver_message_mboxRRRRPRQRRRSRTRURVRWRX(R RRRR8RWRyR@R:RNR(RGRVRR((RRJs@            (R R!R"RYRZt ConfMboxPathR\RR]RR2R5RzR(((RRÑs <    \cBsjtZdZedddeƒedddeddƒedddedeie i ƒƒi ƒedddede ƒe dd dedeie i ƒƒiƒedd dedeƒƒedd dedd ƒedd deddƒedddeddƒedddedeƒedddedeƒf Zd„Zd„Zd„Zd„Zd„ZRS(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(tgroupthomedirt localdomaintdefaultdeliverys ./Maildir/s conf-breakt-tlocalpart_translates('', '')tstrip_delivered_totallow_root_commandscCs|iiƒdS(N(R RR(R ((RRÍscCs|iiƒd|iƒS(NsMDA_qmaillocal %s(R RRR4(R ((RR2Ðs cCs|iid|iƒƒdS(NsMDA_qmaillocal(%s) (R RR3R4(R ((RR5Ôsc Csÿy¨|id|idd|id|id|d|d|d|id|d |id f }|iid t|ƒƒ|id o|id ƒd}nt i ƒ} | i|i||ƒƒ| iƒt i| iƒƒ| idƒt i| iƒdƒt i|iƒdƒt i|iƒdƒt|i|id|idƒt iƒdjpt iƒdjo|id otdƒ‚nt i|ŒWnPtj oD}|id|ƒ|iƒt i|iƒƒt idƒnXdS(NR|s--R(R~tlocaltdashtextRtsenderR€sabout to execl() with args %s Rƒs delivered-toiiiR}R„s>refuse to invoke external commands as root or GID 0 by defaultsexec of qmail-local failed (%s)i( R R0tmsginfoR RRPtstrRt remove_headerRRR7RLtmsgfileRAR>RRBRCRDRStdup2R@RGtchange_usergroupR;R<RtexeclRFRRE( R RR‰RRR@RGR RRŒ((Rt_deliver_qmaillocal×s.a     !5 cCs|iiƒ|iƒ|idjotdƒ‚nhd|i<ddi |ii ƒi dƒd ƒ<} |ii d| dƒ|id\}}|p|of| di|ƒo:|ii d||fƒ|| dt|ƒ| drefuse to invoke external commands as root or GID 0 by defaultR'R£s%%(%s)sabout to execl() with args %s sexec of command %s failed (%s)R¥i(%R7RLRŒRARR>RRR R0RBRCRDRSRR@RGRŽRR;R<RR targtexpand_user_varsR‰titemstkeytvaluetreplacetappendRPRŠRRFRRE( R RR‰RRR@RGR«R®RR R¯RŒ((Rt_deliver_commands8   !5   c Cs¼|iiƒ|iƒh}|i|d<|idjoT|i|d<|ii ƒi dƒd|dt |ƒdjo+t |dƒtjot |dƒtjptdƒ‚q´q´WxŠ|D]‚\}}y|i|ƒ}Wn+tj o}td||fƒ‚nX|i i ti|tiƒ|fƒ|ii |ƒq)WWn(tij o}td|ƒ‚nXdS( NR)tlocalsiiis-invalid syntax for locals ; see documentationspattern %s destination error %ssinvalid regular expression %s(R RRRRRÃR0R)RÄR±ttargetst_localsRšR©RŠRÈRªRtpatternR'RÂRtretcompilet IGNORECASEterror(R RÂRÎRÈRÍRR'((RRWs.    A T %cCsO|iiƒd|i}x.|iD]#\}}|d|i|f7}q$W|S(sY Override the base class implementation; locals isn't readable that way. s default=%ss, %s->%sN(R RRR)RÊRÌRÎRÅ(R RÎRÅRÊ((RR4ss   (R R!R"RR4(((RRSs  c BsetZdZedddeƒeddƒedddeddƒfZd„Zd„Z d „Z RS( s8Multiple 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()cCs|iiƒd|iƒS(NsMultiSorter (%s)(R RRR4(R ((RR2¬s cCs|iid|iƒƒdS(NsMultiSorter(%s) (R RR3R4(R ((RR5°scCsC|iiƒg}|idjo|iotdƒ‚nx‘|iD]†\}}|ii d|i|i fƒ|i |iƒoG|ii d|i|fƒ|i |||ƒ|it|ƒƒqGqGW|pc|io$|ii d|i|ifƒn|ii d|iƒd|ii |||ƒSnd|S(NshMultiSorter recipient matching requires a retriever (message source) that preserves the message envelopes)checking recipient %s against pattern %s srecipient %s matched target %s s+recipient %s not matched; using default %s susing default %s sMultiSorter (default %s)sMultiSorter (%s)(R RRtmatchedRR“RRÌRRÎRÂRPtsearchRRRR±RŠR)(R RRRRÂRÎRÓ((RR³s"    $( R R!R"RYRZR\tConfTupleOfTupleOfStringsR]R2R5R(((RR~s '<  t MultiGuesserc BsetZdZedddeƒeddƒedddeddƒfZd„Zd„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()cCs|iiƒd|iƒS(NsMultiGuesser (%s)(R RRR4(R ((RR2Ýs cCs|iid|iƒƒdS(NsMultiGuesser(%s) (R RR3R4(R ((RR5áscCsú|iiƒg} g} ddddddf}xÀ|D]¸}xs|D]k} |iid | ƒ| i g}t i i |i| gƒƒD]\}} | o || qˆqˆ~ƒqEW| o%|iid t| ƒ| fƒPq8|iid ƒq8Wxš|iD]\} }x€| D]x} |iid| | ifƒ| i| ƒoE|iid| |fƒ|i|||ƒ| it|ƒƒPqqWqþW| pZ|io|iid|iƒn|iid|iƒd|ii|||ƒSnd| S(Ns delivered-tos envelope-tos x-envelope-tos apparently-tos resent-tos resent-ccs resent-bccttotcctbccs*looking for addresses in %s header fields s!found total of %d addresses (%s) sno addresses found, continuing s'checking address %s against pattern %s saddress %s matched target %s s'no addresses matched; using default %s susing default %s sMultiGuesser (default %s)sMultiGuesser (%s)(s delivered-to(s envelope-to(s x-envelope-to(s apparently-to(s resent-tos resent-ccs resent-bcc(R×sccRÙ(R RRRÓt header_addrst fieldnamestfieldstfieldRPtextendRÇtemailtUtilst getaddressesRtget_allR$taddrRšRÌRÎRÂRÔRRRR±RŠR)(R RRRR$RÂRÜRÛRÇRÝRÚRãRÎRÓ((RRäs< U    ( R R!R"RYRZR\RÕR]R2R5R(((RRÖÍs <  (R"t__all__R7RÏttypest email.UtilsRßRœtgetmailcore.exceptionstgetmailcore.utilitiestgetmailcore.baseclassesR Rt ForkingBaseRRRRRRRRRÖ(RRRRäRRRÖRRÏRœRRR7RßRåR((Rt? s&!     ;o­É”B6+O