^c P>dZddlmZddlmZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZmZmZmZmZddlmZmZdZiZejeZeddd edd d edd d edd d eddd eddd eddd eddd eddd eddd eddd eddd eddd eddd eddd eddd eddd edd d edd!d edd"d d#Zd$ZdeiZ Gd%d&Z!d)d'Z"d(Z#dS)*ahooks for sending email push notifications This extension implements hooks to send email notifications when changesets are sent from or received by the local repository. First, enable the extension as explained in :hg:`help extensions`, and register the hook you want to run. ``incoming`` and ``changegroup`` hooks are run when changesets are received, while ``outgoing`` hooks are for changesets sent to another repository:: [hooks] # one email for each incoming changeset incoming.notify = python:hgext.notify.hook # one email for all incoming changesets changegroup.notify = python:hgext.notify.hook # one email for all outgoing changesets outgoing.notify = python:hgext.notify.hook This registers the hooks. To enable notification, subscribers must be assigned to repositories. The ``[usersubs]`` section maps multiple repositories to a given recipient. The ``[reposubs]`` section maps multiple recipients to a single repository:: [usersubs] # key is subscriber email, value is a comma-separated list of repo patterns user@host = pattern [reposubs] # key is repo pattern, value is a comma-separated list of subscriber emails pattern = user@host A ``pattern`` is a ``glob`` matching the absolute path to a repository, optionally combined with a revset expression. A revset expression, if present, is separated from the glob by a hash. Example:: [reposubs] */widgets#branch(release) = qa-team@example.com This sends to ``qa-team@example.com`` whenever a changeset on the ``release`` branch triggers a notification in any repository ending in ``widgets``. In order to place them under direct user management, ``[usersubs]`` and ``[reposubs]`` sections may be placed in a separate ``hgrc`` file and incorporated by reference:: [notify] config = /path/to/subscriptionsfile Notifications will not be sent until the ``notify.test`` value is set to ``False``; see below. Notifications content can be tweaked with the following configuration entries: notify.test If ``True``, print messages to stdout instead of sending them. Default: True. notify.sources Space-separated list of change sources. Notifications are activated only when a changeset's source is in this list. Sources may be: :``serve``: changesets received via http or ssh :``pull``: changesets received via ``hg pull`` :``unbundle``: changesets received via ``hg unbundle`` :``push``: changesets sent or received via ``hg push`` :``bundle``: changesets sent via ``hg unbundle`` Default: serve. notify.strip Number of leading slashes to strip from url paths. By default, notifications reference repositories with their absolute path. ``notify.strip`` lets you turn them into relative paths. For example, ``notify.strip=3`` will change ``/long/path/repository`` into ``repository``. Default: 0. notify.domain Default email domain for sender or recipients with no explicit domain. It is also used for the domain part of the ``Message-Id`` when using ``notify.messageidseed``. notify.messageidseed Create deterministic ``Message-Id`` headers for the mails based on the seed and the revision identifier of the first commit in the changeset. notify.style Style file to use when formatting emails. notify.template Template to use when formatting emails. notify.incoming Template to use when run as an incoming hook, overriding ``notify.template``. notify.outgoing Template to use when run as an outgoing hook, overriding ``notify.template``. notify.changegroup Template to use when running as a changegroup hook, overriding ``notify.template``. notify.maxdiff Maximum number of diff lines to include in notification email. Set to 0 to disable the diff, or -1 to include all of it. Default: 300. notify.maxdiffstat Maximum number of diffstat lines to include in notification email. Set to -1 to include all of it. Default: -1. notify.maxsubject Maximum number of characters in email's subject line. Default: 67. notify.diffstat Set to True to include a diffstat before diff content. Default: True. notify.showfunc If set, override ``diff.showfunc`` for the diff content. Default: None. notify.merge If True, send notifications for merge changesets. Default: True. notify.mbox If set, append mails to this mbox file instead of sending. Default: None. notify.fromauthor If set, use the committer of the first changeset in a changegroup for the "From" field of the notification mail. If not set, take the user from the pushing repo. Default: False. notify.reply-to-predecessor (EXPERIMENTAL) If set and the changeset has a predecessor in the repository, try to thread the notification mail with the predecessor. This adds the "In-Reply-To" header to the notification mail with a reference to the predecessor with the smallest revision number. Mail threads can still be torn, especially when changesets are folded. This option must be used in combination with ``notify.messageidseed``. If set, the following entries will also be used to customize the notifications: email.from Email ``From`` address to use if none can be found in the generated email content. web.baseurl Root repository URL to combine with repository paths when making references. See also ``notify.strip``. N)_) encodingerror logcmdutilmailobsutilpatchpycompat registrarutil)dateutil stringutilsships-with-hg-corenotify changegroup)defaultconfigdiffstatTdomain messageidseed fromauthorsincomingmaxdiffi, maxdiffstat maxsubjectCmboxmergeoutgoingreply-to-predecessorFsourcessserveshowfuncstripstyletemplatetests Subject: changeset in {webroot}: {desc|firstline|strip} From: {author} changeset {node|short} in {root} details: {baseurl}{webroot}?cmd=changeset;node={node|short} description: {desc|tabindent|strip} sx changeset {node|short} in {root} details: {baseurl}{webroot}?cmd=changeset;node={node|short} summary: {desc|firstline} cDeZdZdZdZdZdZdZdZdZ dZ d d Z d S) notifierzemail notification class.c|||_|jdd}|r|j|ddg||_t |jdd|_||jj|_|jdd|_|jdd|_ |j dd |_ tj |j|_||_|j dd |_|j dd |_|jdd |_|j dd |_|jr(|js!t+jt/d|j |j dd |_d}|jd|p|jdd}|s|jdd}|s#|s!t0|pt4}t7j||}t7j|j|j||_dS)Nrrusersubsreposubs)sectionsr"rrr%rr!rrs=notify.reply-to-predecessor used without notify.messageidseedsdiffr$r#)uiconfig readconfigrepoint stripcountstriprootdomainmbox configbooltestr _charsetscharsets subscriberssubsmergeshowfunc messageidseedreplyrAbortr deftemplatesgetsingle_templater templatespecchangesettemplatert)selfr,r/hooktypecfgmapfiletemplatespecs ./usr/lib/python3/dist-packages/hgext/notify.py__init__znotifier.__init__@sagnnY 22  I G  sk;-G  H H H dgnnYAABBJJty~.. gnnY :: GNN9g66 G&&y':: tw// $$&& W'' 8<< **9kBB !W^^I7GHHW'' 3JKK : d0 +,  =  G..w DDDM7>>)X66 $'.. {; ;  :gnnY99G Ex E#''11D_H&x99.tw 4HHctj|}|j}|dkr4|d}|dkrn||dzd}|dz}|dk4|S)z?strip leading slashes from local path, turn into web-safe path.r/rN)r pconvertr1find)rGpathcountcs rMr2znotifier.striphsj}T""aii $ABwwA=D QJE aii  rOctj|}|jr6|d}|dkr |d|}d|vr |dz|jzS|S)z try to clean up email addresses. @localhostrN@)remailr2r4rT)rGaddras rMfixmailznotifier.fixmailusn -- ; 1 -((ABwwBQBx4d{T[00 rOct}jdD]\}}|dD]}}d|vr|dd\}}nd}t jjj|r*| ||f~jdD]\}}d|vr|dd\}}nd}t jjj|rB|dD],}| ||f-fdt|DS)z;return list of email addresses of subscribers to this repo.r),#rRNr*cfg|]-\}}tjj|jj|f.S)r addressencoder,r9r7).0srrGs rM z(notifier.subscribers..sI   1 DM49 E Eq I   rO) setr, configitemssplitfnmatchr/r3r2addr^sorted)rGr;userpatspatrevsuserss` rMr:znotifier.subscriberssuu'--k:: 9 9JD$zz$'' 9 93;; # $ 2 2ICD?49>399;;??9HHdll400$7888  9'--k:: 9 9JCs{{IIdA.. TTty~s33 9!KK--99DHHdll400$78888    t     rOc |js't|dkrdS|jj|f||jdd|jj |j d|dS)z6format one changeset, unless it is a suppressed merge.rRFswebsbaseurl)changesbaseurlr3webrootT) r<lenparentsrFshow changesetr,r-r/r3)rGctxpropss rMnodez notifier.nodesz c#++--001445  MMOOGNN6:66I       trOcd|jdd}||vS)z|dd |||j? dS)!z send message.Ns %r and %d:rs3notify: no subscribers to selected repo and revset FromSubjectT)decodes%a, %d %b %Y %H:%M:%S %1%2)formatDaterRs%s: %d new changesets s%s: %srrsemailsfromrZrYz changeset %szX-Hg-Notificationz Message-Idcfg|]-}|k|%|.Src)r~)rectx2r|has_nodeunfis rMrhz!notifier.send..sG388::%%((4..%T %%%rOc*|SN)rev)r|s rMznotifier.send.. srO)keyz In-Reply-Toz, Tos*notify: sending %d subscribers %d changes )r5)@rir;rmr/rrrrRepoLookupErrorrxr,debugr parsebytes emailerrorsMessageParseErrorr@ headdecode is_multipartitems get_payload mimeencoder9r7r strfromlocalr datestrrr3 descriptionlstriprkrstripr0r-rellipsis headencodeusernamer^rd messageidr4r>r? unfiltered changelogindexrrallpredecessorsobsstorer~minjoinrnas_byteswriteendswithstatussendmail emailutils parseaddrr5)rGr|rVdatar;subrLrrmsginstsendersubjectheaderspayloadkvrf maxsubject predecessorspredmsgtextrrs ` @@rMsendz notifier.sendsTuu  IC|  y~~mT37799EE(    4yy    t99>> GMMG    F $/$''CC, $ $ $+d## # $Vi.  _V,,F  og..G KY!! iikkGooTo22G/$'7DM49MMC  1A+  $A B B B  F  5qyy455E8JJOO%%,,..44UA>>qAHHJJ#ty!n4 =AABB  ? )':>>G GWdmTY  I  MW^^Hg66L$':J:J:L:LF v  &!8!8\\&))F( GVT]DI  F $2C#7  <  P )#t{D>> a<< F q[[S^^g55CDDC GMM#Y 99 : : :!(7(+II  J GMM!677#i..H I I I  ejj++,,,,,rOr) __name__ __module__ __qualname____doc__rNr2r^r:r~rrrrcrOrMr'r'=s##&I&I&IP         0   ((( sssj#-#-#-#-#-#-rOr'c t|||}||}|js|d|jzdS||r|d|zdS|d}d} d} |dks|dkr|j| D]} | || r"| d z } | s||  } ?|| z }| td | || dd fz|| r|||d n| |vr| |si| | td | |dd fzdS| d z } ||| s| } || z }|d d} | r| rdd| z|g}| r||| |dSdS)zsend email notifications to interested subscribers. if used as changegroup hook, send one email for all changesets in changegroup. else send one email per changeset.s(notify: no subscribers to repository %s Ns,notify: changes have source "%s" - skipping rOrrr)startrRs1notify: suppressing notification for merge %d:%s stiprrrsFrom: %s)r'rr;rr3r pushbufferrrrrr~ro popbuffernoterhexrr-rr) r,r/rHr~rkwargsnr|rrVauthorr fromauthors rMhookrGs T8$$A //  D !C 6 =FGGG||F AFJKKKMMOOO D E F>!!X%<%<>&&SWWYY&77 Cvvd3i   .!#Y^^--F &KLLDIMMOOCRC012   & FF3V % % % d  vvc{{  LLNNN GGGHH7799cggiin-.    F   s  XXZZFBLLNND9m44J 8*8zz;/677 ! sE4     !!rOc|r|r|}n%tjtj}|r]t j||z}dtj| dd|fz}nKd|ttj t| j|fz}tj|S)Ns @s)r strtolocalsocketgetfqdnhashlibsha512rr sysbytes hexdigestr0timehashr/r3r)r|r4r>host messagehashrs rMrrs 5-5"6>#3#344  nSWWYY%>?? !  k3355crc: ; ; %  (      ! !  +    + ++rO)NN)$r email.errorserrorsr email.utilsutilsrrlrrrmercurial.i18nr mercurialrrrrrr r r r mercurial.utilsr r testedwith configtable configitemrrCmultiple_templaterAr'rrrcrOrMrs{TTl#"""""                        #  !Y !+ . .                                                                                FHH% G-G-G-G-G-G-G-G-T6!6!6!6!r,,,,,rO