Ϫf1dZddlZddlmZddlmZmZddlmZddl m Z m Z m Z m Z mZddlmZGdd ej"ej$ZGd d Zd Zy) z0 Support for creating mail servers with twistd. N)internet)checkersstrcred) endpoints)aliasmailmaildirrelay relaymanager)usageceZdZdZdZgdgdgZgdgdgdgdgZd d d Zejd eji Z dZ dZ dZdZeZdZeZdZeZdZeZdZeZdZeZdZeZdZdZy)Optionsa An options list parser for twistd mail. @type synopsis: L{bytes} @ivar synopsis: A description of options for use in the usage message. @type optParameters: L{list} of L{list} of (0) L{bytes}, (1) L{bytes}, (2) L{object}, (3) L{bytes}, (4) L{None} or callable which takes L{bytes} and returns L{object} @ivar optParameters: Information about supported parameters. See L{Options } for details. @type optFlags: L{list} of L{list} of (0) L{bytes}, (1) L{bytes} or L{None}, (2) L{bytes} @ivar optFlags: Information about supported flags. See L{Options } for details. @type _protoDefaults: L{dict} mapping L{bytes} to L{int} @ivar _protoDefaults: A mapping of default service to port. @type compData: L{Completions } @ivar compData: Metadata for the shell tab completion system. @type longdesc: L{bytes} @ivar longdesc: A long description of the plugin for use in the usage message. @type service: L{MailService} @ivar service: The email service. @type last_domain: L{IDomain} provider or L{None} @ivar last_domain: The most recently specified domain. z [options])r RNz[Relay messages according to their envelope 'To', using the given path as a queue directory.)hostnameHNz.The hostname by which to identify this server.)esmtpEz!Use RFC 1425/1869 SMTP extensions)disable-anonymousNz+Disallow non-authenticated SMTP connections)zno-pop3Nz Disable the default POP3 server.)zno-smtpNz Disable the default SMTP server.iiY)pop3smtpr) optActionsa An SMTP / POP3 email server plugin for twistd. Examples: 1. SMTP and POP server twistd mail --maildirdbmdomain=example.com=/tmp/example.com --user=joe=password Starts an SMTP server that only accepts emails to joe@example.com and saves them to /tmp/example.com. Also starts a POP mail server which will allow a client to log in using username: joe@example.com and password: password and collect any email that has been saved in /tmp/example.com. 2. SMTP relay twistd mail --relay=/tmp/mail_queue Starts an SMTP server that accepts emails to any email address and relays them to an appropriate remote SMTP server. Queued emails will be temporarily stored in /tmp/mail_queue. ctjj|tj|_d|_|jD]}g||< y)z: Parse options and create a mail service. N)r r__init__r MailServiceservice last_domain_protoDefaults)selfrs 2/usr/lib/python3/dist-packages/twisted/mail/tap.pyrzOptions.__init__ksL  t$'') ** GDM c`ddlm}||jtj||y)a Add an endpoint to a service. @type service: L{bytes} @param service: A service, either C{b'smtp'} or C{b'pop3'}. @type description: L{bytes} @param description: An endpoint description string or a TCP port number. rreactorN)twisted.internetr#appendrserverFromString)rr descriptionr#s r addEndpointzOptions.addEndpointus& - W Y77MNr c(|jd|y)z Add a POP3 port listener on the specified endpoint. You can listen on multiple ports by specifying multiple --pop3 options. rNr(rr's ropt_pop3zOptions.opt_pop3 -r c(|jd|y)z Add an SMTP port listener on the specified endpoint. You can listen on multiple ports by specifying multiple --smtp options. rNr*r+s ropt_smtpzOptions.opt_smtpr-r c|jr'|jjd|jytjd)zM Make the most recently specified domain the default domain. z2Specify a domain before specifying using --defaultN)rr addDomainr UsageErrorrs r opt_defaultzOptions.opt_defaults9    LL " "2t'7'7 8""#WX Xr cB |jd\}}t j |j tjj||_ |j j||jy#t$rtjdwxYw)a; Generate an SMTP/POP3 virtual domain. This option requires an argument of the form 'NAME=PATH' where NAME is the DNS domain name for which email will be accepted and where PATH is a the filesystem path to a Maildir folder. [Example: 'example.com=/tmp/example.com'] =z>Argument to --maildirdbmdomain must be of the form 'name=path'N) split ValueErrorr r3r MaildirDirdbmDomainrospathabspathrr2)rdomainnamer<s ropt_maildirdbmdomainzOptions.opt_maildirdbmdomains c*JD$ #66 LL"''//$/  tT%5%56 ""P  s A??Bc |jdd\}}|jr|jj ||ytjd#t$rtjdwxYw)zG Add a user and password to the last specified domain. r7z6Argument to --user must be of the form 'user=password'z(Specify a domain before specifying usersN)r8r9r r3raddUser)r user_passuserpasswords ropt_userzOptions.opt_usersu &__S!4ND(       $ $T8 4""#MN N ""H  s AA4c&d|j_y)z@ Send undeliverable messages to the postmaster. rBN)r postmasterr4s ropt_bounce_to_postmasterz Options.opt_bounce_to_postmasters'(#r c*|jtjj|jrt j |j j|}|jj||j jj|t|j j|jytj|jjjdtjd)zR Specify an aliases(5) file to use for the last specified domain. Nz does not support alias filesz*Specify a domain before specifying aliases)rrIAliasableDomain providedByr loadAliasFilerdomains setAliasGroupmonitor monitorFile AliasUpdaterr r3 __class____name__)rfilenamealiasess r opt_aliaseszOptions.opt_aliasess    '$$//0@0@A--dll.B.BHM  ..w7 $$00l4<<+?+?AQAQR&&''11::= ""#OP Pr cr||r||S|d|zrgStj||j|gS)a Return a list of endpoints for the specified service, constructing defaults if necessary. If no endpoints were configured for the service and the protocol was not explicitly disabled with a I{--no-*} option, a default endpoint for the service is created. @type reactor: L{IReactorTCP } provider @param reactor: If any endpoints are created, the reactor with which they are created. @type service: L{bytes} @param service: The type of service for which to retrieve endpoints, either C{b'pop3'} or C{b'smtp'}. @rtype: L{list} of L{IStreamServerEndpoint } provider @return: The endpoints for the specified service as configured by the command line parameters. zno-)rTCP4ServerEndpointr)rr#rs r _getEndpointszOptions._getEndpointssK. == %'/ "I00$:M:Mg:VWX Xr cddlm}|dr|dtjdd|vr/|dD]'}|jj j |)|ds7|jj j tjd }|jD]}|j||||<||sd }!|stjd y) z Check the validity of the specified set of options and configure authentication. @raise UsageError: When the set of options is invalid. rr"rrNz--esmtp requires --hostname credCheckersrFTz You cannot disable all protocols) r$r#r r3r smtpPortalregisterCheckerrAllowAnonymousAccessrr[)rr#chanythingrs r postOptionszOptions.postOptions s - =T*-5""#@A A T !>* < ''77; <'( LL # # 3 3H4Q4Q4S T** G ..w@DMG} ""#EF Fr N)rU __module__ __qualname____doc__synopsis optParametersoptFlagsrr CompletionsCompleteHostnamescompDatalongdescrr(r,opt_pr/opt_sr5opt_Dr@opt_drGopt_urJopt_brXopt_Ar[rcr rrrs DH  R M <R== HN !u  Z9P9P9P9R,STHH4 O. E. EY E7* !E O E( %EQ& E YDGr rceZdZdZdZdZy)rSz A callable object which updates the aliases for a domain from an aliases(5) file. @ivar domains: See L{__init__}. @ivar domain: See L{__init__}. c ||_||_y)z @type domains: L{dict} mapping L{bytes} to L{IDomain} provider @param domains: A mapping of domain name to domain object @type domain: L{IAliasableDomain} provider @param domain: The domain to update. N)rOr>)rrOr>s rrzAliasUpdater.__init__2s  r cv|jjtj|j|y)z Update the aliases for a domain from an aliases(5) file. @type new: L{bytes} @param new: The name of an aliases(5) file. N)r>rPrrNrO)rnews r__call__zAliasUpdater.__call__=s' !!%"5"5dllC"HIr N)rUrdrerfrrzrur rrSrS)s Jr rSc|dr'tj}|jj}n&tj}|jj }|dr+|d}t jj|st j||jjtj|tj|j}||jj}|dr|xjdz c_|xj|dfz c_tj |d}|j#|j|jj$j'||drU|jj)}|dD]3}t+j,||} | j#|j5|dr||}|dr|d|_|j.f|_|drd|jz|_|dD]3}t+j,||} | j#|j5|jS)a Configure a service for operating a mail server. The returned service may include POP3 servers, SMTP servers, or both, depending on the configuration passed in. If there are multiple servers, they will share all of their non-network state (i.e. the same user accounts are available on all of them). @type config: L{Options } @param config: Configuration options specifying which servers to include in the returned service and where they should keep mail data. @rtype: L{IService } provider @return: A service which contains the requested mail servers. rr )NNrrBrr)r SmartHostESMTPRelayingManagerrgetESMTPFactorySmartHostSMTPRelayingManagergetSMTPFactoryr;r<isdirmkdirsetQueueQueuer DomainQueuerqueuefArgsRelayStateHelpersetServiceParentrOsetDefaultDomaingetPOP3FactoryrStreamServerEndpointServicer>) configrmType smtpFactorydirdefaultmanagerhelperfendpointsvcs r makeServicerGs g;;nn44 ::nn33  gWoww}}S! HHSM 2 23 78$$V^^4--. '? MM\ )M &,.. ..w:///8 f~ NN ) ) +v 1H66xCC   0 1f~ M * j)AHxxkAG '?"QWW,AGv 1H66xCC   0 1 >>r )rfr;twisted.applicationr twisted.credrrr$r twisted.mailrrr r r twisted.pythonr rAuthOptionMixinrSrrur rrsO  (*&BB SGemmW44SGlJJ<9r