o ¯bn(ã@sdZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZmZddlmZd Zej d ¡Zd Zd ZeejƒZeed ZGdd„dƒZdd„ZedƒZdd„Z Gdd„dƒZ!dd„Z"dd„Z#da$dd„Z%dd„Z&dd „Z'd!d"„Z(d#d$„Z)dS)%z4 Implementation module for the I{mailmail} command. éN)Ú ConfigParser)ÚStringIO)Úversion)Úreactor)ÚLoggerÚtextFileLogObserver)Úsmtpz /etc/mailmailz~/.twisted/mailmailz 127.0.0.1zSubject: Failed Message Delivery Message delivery failed. The following occurred: %s -- The Twisted sendmail application. )Úobserverc@seZdZdZdS)ÚOptionsat Store the values of the parsed command-line options to the I{mailmail} script. @type to: L{list} of L{str} @ivar to: The addresses to which to deliver this message. @type sender: L{str} @ivar sender: The address from which this message is being sent. @type body: C{file} @ivar body: The object from which the message is to be read. N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú?/usr/lib/python3/dist-packages/twisted/mail/scripts/mailmail.pyr (sr cCs&zt ¡WStyt ¡YSw©N)ÚosÚgetloginÚ BaseExceptionÚgetpassÚgetuserrrrrr8s    ÿrzUnsupported option.c Cs²tƒ}dd„|Dƒ|_tƒ|_d|vrtdtƒtƒ‚d|vr!t‚d|vr't‚d|vr<|| d¡d|_|j  |j¡d |vsDd |vrFt‚d |vrNd |_ nd |_ d|vrYd |_ nd |_ d|vsdd|vrhd |_ nd |_ d|vrqt‚d|vr€d |_ |j|_ g|_nd |_ g|_gggggdœ}tƒ} d}tj ¡}| ¡sžnM| dd¡}|d ¡}|j rÇ|dvrÇ|j tj |d¡dg¡|dkrÆd}n|dkrÖtj |d¡d|_||vrã|| |d¡|rê| |¡q’|dsù| d|j›d¡|ds|jstdƒ‚| d d |j¡¡¡|ds"| d t ¡›d¡| |¡|j rE|j D]}z |j  |¡Wq.t yDYq.w| !dd¡t| "¡tj #¡ƒ|_$|S)!NcSsg|] }| d¡s|‘qS)ú-)Ú startswith)Ú.0ÚerrrÚ Dsz parseOptions..z --versionzmailmail version:z-bpz-bsz-Féz-iz-oiz-odbTFz-odfz-oepz-epz-omz-t)ÚfromÚtoÚccÚbccÚdatez: r)rrr r rzFrom: z rzNo recipients specified.zTo: {} z, r!zDate: )%r rrÚsenderÚprintrÚ SystemExitÚ_unsupportedOptionÚindexÚremoveÚ backgroundÚ printErrorsÚrecipientsFromHeadersÚexcludeAddressesÚexludeAddressesrÚsysÚstdinÚreadlineÚstripÚsplitÚlowerÚextendÚemailÚutilsÚ parseaddrÚappendÚwriteÚformatÚjoinrÚ rfc822daterÚseekÚgetvalueÚreadÚbody) ÚargvÚoÚrequiredHeadersÚbufferr8ÚlineÚhdrsÚhdrÚarrrÚ parseOptionsBsš û   € ì    ÿ rHc@seZdZdZdd„ZdS)Ú Configurationaí @ivar allowUIDs: A list of UIDs which are allowed to send mail. @ivar allowGIDs: A list of GIDs which are allowed to send mail. @ivar denyUIDs: A list of UIDs which are not allowed to send mail. @ivar denyGIDs: A list of GIDs which are not allowed to send mail. @type defaultAccess: L{bool} @ivar defaultAccess: L{True} if access will be allowed when no other access control rule matches or L{False} if it will be denied in that case. @ivar useraccess: Either C{'allow'} to check C{allowUID} first or C{'deny'} to check C{denyUID} first. @ivar groupaccess: Either C{'allow'} to check C{allowGID} first or C{'deny'} to check C{denyGID} first. @ivar identities: A L{dict} mapping hostnames to credentials to use when sending mail to that host. @ivar smarthost: L{None} or a hostname through which all outgoing mail will be sent. @ivar domain: L{None} or the hostname with which to identify ourselves when connecting to an MTA. cCs@g|_g|_g|_g|_d|_d|_i|_d|_d|_d|_ dS)NÚdenyT) Ú allowUIDsÚdenyUIDsÚ allowGIDsÚdenyGIDsÚ useraccessÚ groupaccessÚ identitiesÚ smarthostÚdomainÚ defaultAccess)ÚselfrrrÚ__init__Øs zConfiguration.__init__N)r r r rrVrrrrrI¼s rIc CsÚtƒ}t |tj¡s |Stƒ}| |¡|j}|j}|j}|j }d||fd||ffD]y\}}} |  |¡r£d|fd| ffD]>\} } |  || ¡rz|  || ¡rz|  || ¡  d¡D]$} zt| ƒ} Wntystjd|d ¡|| dYqUw|  | ¡qUq<|  |d ¡} d d „d d „|   d¡DƒDƒ} | ddkrt||dƒq*t||dƒq*|  d ¡rÌ| d ¡D]\}}|  dd¡}t|ƒdkrÆtjd|dq®||j|<q®|  d¡rë|  dd¡rÞ|  dd¡|_|  dd¡rë|  dd¡|_|S)NrOrPÚallowrJú,z6Illegal {prefix}ID in [{section}] section: {sectionID}r)ÚprefixÚsectionÚ sectionIDÚordercSóg|]}| ¡‘qSr)r1©rÚsrrrrózloadConfig..cSr]r)r2r^rrrrr`Úidentityú:réz.Illegal entry in [identity] section: {section})rZÚ addressesrRÚdefault_domain)rIrÚaccessÚR_OKrr>rKrLrMrNÚ has_sectionÚ has_optionÚgetr1ÚintÚ ValueErrorÚ_logÚerrorÚupperr7ÚsetattrÚitemsÚlenrQrRrS)ÚpathÚcÚpÚauÚduÚagÚdgrZrGÚdÚmodeÚLr[r\ÚhostÚupÚpartsrrrÚ loadConfigçsZ      ûÿ €   €       r€cCs t ¡dSr©rÚstop)ÚresultrrrÚsuccess,s r„cCst ¡|adSr)rr‚Úfailed)ÚfrrrÚfailure3sr‡cCs.t ||j|j|j¡}| tt¡t  ¡dSr) rÚsendmailr"rr?Ú addCallbacksr„r‡rÚrun)r}ÚoptionsÚidentrzrrrrˆ9s  rˆcCsf|jg}d tjdtj d¡¡}tƒ}|j|dtt |  ¡ƒ}t  d|||¡}|  dd„¡dS)Nz2"Internally Generated Message ({})"rÚascii©ÚfileÚ localhostcSst ¡Srr)Ú_rrrÚHszsenderror..) r"r9r-r@rÚDNSNAMEÚdecoderÚprintTracebackÚ ERROR_FMTr=rˆÚaddBoth)r‡r‹Ú recipientr"rnr?rzrrrÚ senderror?sÿ r™cCs¦t ¡}t ¡}|jdkr||jvrdS||jvrdSn||jvr#dS||jvr*dS|jdkrA||jvr6dS||jvr=dS|j S||jvrHdS||jvrOdS|j S)NrJTF) rÚgetuidÚgetgidrOrLrKrPrNrMrT)ÚconfÚuidÚgidrrrrJKs.   ÿ      û rJcCsÂttjdd…ƒ}ttƒ}ttƒ}t|ƒst|ƒr t d¡dS|j p'|j p't }|j   ¡}|  |j ¡|jr;|jt_n|jrB|jt_t|||ƒtr_|jrXtjtjdtdƒ‚tt|ƒdSdS)NrzPermission deniedrŽ)rHr-r@r€Ú GLOBAL_CFGÚ LOCAL_CFGrJrmrnrRÚ SMARTHOSTrQÚcopyÚupdaterSrr“rˆr…r)r•Ústderrr$r™)rAÚgConfÚlConfr}rŒrrrrŠhs(     ûrŠ)*rÚ email.utilsr4rrr-Ú configparserrÚiorÚtwisted.copyrightrÚtwisted.internetrÚtwisted.loggerrrÚ twisted.mailrrŸrsÚ expanduserr r¡r–r¤Ú _logObserverrmr rr$r%rHrIr€r„r…r‡rˆr™rJrŠrrrrÚs<       z+E