o k`:A@sddlmZddlmZmZmZmZmZddlm Z m Z m Z ddl m Z mZmZgdZGddde ZGdd d e ZGd d d e ZGd d d e ZGddde ZGddde ZddZddZGdddeZGddde ZdS)) defaultdict) BoolOption ConfigSectionExtensionOption ListOptionOption) Component InterfaceExtensionPoint)as_boollazyto_list) IEmailAddressResolverIEmailDecorator IEmailSenderINotificationDistributorINotificationFormatterINotificationSubscriberNotificationEventNotificationSystem get_target_idparse_subscriber_configc@ eZdZdZddZddZdS)rz=Deliver events over some transport (i.e. messaging protocol).cCdS)z+Return a list of supported transport names.Nrrr7/usr/lib/python3/dist-packages/trac/notification/api.py transports$z#INotificationDistributor.transportscCr)aKDistribute the notification event. :param transport: the name of a supported transport :param recipients: a list of (sid, authenticated, address, format) tuples, where either `sid` or `address` can be `None` :param event: a `NotificationEvent` Nr) transport recipientseventrrr distribute'rz#INotificationDistributor.distributeN)__name__ __module__ __qualname____doc__rr!rrrrr!s rc@r)rz?Convert events into messages appropriate for a given transport.cCr)zReturn a list of supported styles. :param transport: the name of a transport :return: a list of tuples (style, realm) Nr)rrrrget_supported_styles5rz+INotificationFormatter.get_supported_stylescCr)ahConvert the event to an appropriate message. :param transport: the name of a transport :param style: the name of a supported style :return: The return type of this method depends on transport and must be compatible with the `INotificationDistributor` that handles messages for this transport. Nr)rstyler rrrformat<rzINotificationFormatter.formatN)r"r#r$r%r&r(rrrrr2s rc@s0eZdZdZddZddZddZdd Zd S) rz!Subscribe to notification events.cCr)aqReturn a list of subscriptions that match the given event. :param event: a `NotificationEvent` :return: a list of tuples (class, distributor, sid, authenticated, address, format, priority, adverb), where small `priority` values override larger ones and `adverb` is either 'always' or 'never'. Nr)r rrrmatchesJrzINotificationSubscriber.matchescCr)zsz)parse_subscriber_config..key)copyupdaterdictsplitlenstripget isinstancer:intboolr listr items setdefaultappendvaluessort)rawsubscriptionsrequired_attrsoptional_attrs known_attrsbynameoptionrEpartsr8 attributeknownbyclass attributesrHrWrrrrsB           rc@seZdZdZdddZdS)ra~All data related to a particular notification event. :param realm: the resource realm (e.g. 'ticket' or 'wiki') :param category: the kind of event that happened to the resource (e.g. 'created', 'changed' or 'deleted') :param target: the resource model (e.g. Ticket or WikiPage) or `None` :param time: the `datetime` when the event happened cCs"||_||_||_||_||_dSN)realmcategoryr;timeauthor)selfrfrgr;rhrirrr__init__s  zNotificationEvent.__init__N)rd)r"r#r$r%rkrrrrrs rc@sXeZdZeddeddZeddddZeddd d Z edd d d Z eddddZ eddd dZ e ddd dddZe ddd dddZeddd dZe ddd ddZe ddd ddZeddd d!Zedd"dd#Zedd$dd%Zedd&d'd(Zedd)d*d+Zed,d-ZeeZeeZed.d/Z d0d1Z!d2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&dS)?r notification email_senderSmtpEmailSendera4Name of the component implementing `IEmailSender`. This component is used by the notification system to send emails. Trac currently provides `SmtpEmailSender` for connecting to an SMTP server, and `SendmailEmailSender` for running a `sendmail`-compatible executable. smtp_enabledfalsezEnable email notification. smtp_fromztrac@localhostzSender address to use in notification emails. At least one of `smtp_from` and `smtp_replyto` must be set, otherwise Trac refuses to send notification mails.smtp_from_namerdz*Sender name to use in notification emails.smtp_from_authoraUse the author of the change as the sender in notification emails (e.g. reporter of a new ticket, author of a comment). If the author hasn't set an email address, `smtp_from` and `smtp_from_name` are used instead. (''since 1.0'') smtp_replytozReply-To address to use in notification emails. At least one of `smtp_from` and `smtp_replyto` must be set, otherwise Trac refuses to send notification mails.smtp_always_cc), zComma-separated list of email addresses to always send notifications to. Addresses can be seen by all recipients (Cc:).)sepdocsmtp_always_bcczComma-separated list of email addresses to always send notifications to. Addresses are not public (Bcc:). smtp_default_domainaDefault host/domain to append to addresses that do not specify one. Fully qualified addresses are not modified. The default domain is appended to all username/login for which an email address cannot be found in the user settings.ignore_domainszComma-separated list of domains that should not be considered part of email addresses (for usernames with Kerberos domains).)ry admit_domainszuComma-separated list of domains that should be considered as valid for email addresses (such as localdomain). mime_encodingnoneaSpecifies the MIME encoding scheme for emails. Supported values are: `none`, the default value which uses 7-bit encoding if the text is plain ASCII or 8-bit otherwise. `base64`, which works with any kind of content but may cause some issues with touchy anti-spam/anti-virus engine. `qp` or `quoted-printable`, which works best for european languages (more compact than base64) if 8-bit encoding cannot be used. use_public_cczAddresses in the To and Cc fields are visible to all recipients. If this option is disabled, recipients are put in the Bcc list. use_short_addraPermit email address without a host/domain (i.e. username only). The SMTP server should accept those addresses, and either append a FQDN or use local delivery. See also `smtp_default_domain`. Do not use this option with a public SMTP server. smtp_subject_prefix __default__zText to prepend to subject line of notification emails. If the setting is not defined, then `[$project_name]` is used as the prefix. If no prefix is desired, then specifying an empty option will disable it. message_id_hashmd5zMHash algorithm to create unique Message-ID header. ''(since 1.0.13)''znotification-subscriberaKThe notifications subscriptions are controlled by plugins. All `INotificationSubscriber` components are in charge. These components may allow to be configured via this section in the `trac.ini` file. See TracNotification for more details. Available subscribers: [[SubscriberList]] cCs|j}t|Sre)notification_subscriber_sectionoptionsr)rjrYrrrsubscriber_defaultsGs z&NotificationSystem.subscriber_defaultsccs6|j|D]}||d|d|d|dfVqdS)Nr?r(r@rA)r)rjklassdrrrr,Ls z(NotificationSystem.default_subscriptionscCs|jdd|p dS)Nrlzdefault_format.z text/plain)configrO)rjrrrrget_default_formatQs z%NotificationSystem.get_default_formatcCs&ddlm}||j|||p||S)Nr)get_preferred_format)trac.notification.prefsrenvr)rjr.r/rrrrrrUs  z'NotificationSystem.get_preferred_formatcCs|j|||dS)z&Send message to recipients via e-mail.N)rmr6)rjr5rr2rrr send_email[szNotificationSystem.send_emailcCs||||dS)z_Distribute an event to all subscriptions. :param event: a `NotificationEvent` N)distribute_event subscriptions)rjr rrrnotify_szNotificationSystem.notifyc Csi}|D]"\}}}}}||i} |||f} | | vrq|p#||||| | <q|jD]} | D]}||vrHdd||D} | || |q0q*dS)a$Distribute a event to all subscriptions. :param event: a `NotificationEvent` :param subscriptions: a list of tuples (sid, authenticated, address, transport, format) where either sid or address can be `None` cSs(g|]\}}|d|d|d|fqS)rrCr).0kr(rrr ysz7NotificationSystem.distribute_event..N)rUr distributorsrrTr!) rjr rpackagesr.r/addressrr(packagerHr?rrrrrfs&     z#NotificationSystem.distribute_eventc csg}|jD]+}|jdkr$||jD]}|dd||Dqq|dd||Dqt|ddd}d}|D]:\}}} } } } } }|| | f|krPq>|d krg|jd | | ||| | | || fVn |jd | | ||| rx|| | f}q>dS) zReturn all subscriptions for a given event. :return: a list of (sid, authenticated, address, transport, format) batchmodifycs|]}|r|VqdSrerrxrrr z3NotificationSystem.subscriptions..csrrerrrrrrrcSs,|d|ddur dn|d|d|dfS)NrCrrdr)vrrrrFs z2NotificationSystem.subscriptions..rGNr>z3Adding (%s [%s]) for 'always' on rule (%s) for (%s)z4Ignoring (%s [%s]) for 'never' on rule (%s) for (%s)) subscribersrgget_ticket_change_eventsrextendr)sortedlogdebug)rjr r subscriber ticket_eventorderedprevious_combinationrulerr.authaddrfmtpriorArrrr~s6   z NotificationSystem.subscriptionsN)(r"r#r$rrrmrrorrqrrrsrtrsmtp_always_cc_listsmtp_always_bcc_listr{ignore_domains_listadmit_domains_listr~rrrrrrr rrrrr rr,rrrrrrrrrrrs      rN) collectionsr trac.configrrrrr trac.corerr r trac.utilr r r __all__rrrrrrrrobjectrrrrrrs #  +