# HG changeset patch # User Mads Kiilerich # Date 2011-11-23 01:36:33 # Node ID ca572e94d8e7f9b125197a8a5ac542c9ad83b440 # Parent cc58c228503e97dcb405ce0b4496c8b43b59ba1a notify: add option for writing to mbox This makes it possible to test how the mails that are sent _really_ look like. diff --git a/hgext/notify.py b/hgext/notify.py --- a/hgext/notify.py +++ b/hgext/notify.py @@ -105,6 +105,9 @@ notify.diffstat 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. + If set, the following entries will also be used to customize the notifications: email.from @@ -156,6 +159,7 @@ class notifier(object): self.stripcount = int(self.ui.config('notify', 'strip', 0)) self.root = self.strip(self.repo.root) self.domain = self.ui.config('notify', 'domain') + self.mbox = self.ui.config('notify', 'mbox') self.test = self.ui.configbool('notify', 'test', True) self.charsets = mail._charsets(self.ui) self.subs = self.subscribers() @@ -288,7 +292,7 @@ class notifier(object): self.ui.status(_('notify: sending %d subscribers %d changes\n') % (len(self.subs), count)) mail.sendmail(self.ui, util.email(msg['From']), - self.subs, msgtext) + self.subs, msgtext, mbox=self.mbox) def diff(self, ctx, ref=None): diff --git a/mercurial/mail.py b/mercurial/mail.py --- a/mercurial/mail.py +++ b/mercurial/mail.py @@ -114,8 +114,8 @@ def connect(ui, mbox=None): return _smtp(ui) return lambda s, r, m: _sendmail(ui, s, r, m) -def sendmail(ui, sender, recipients, msg): - send = connect(ui) +def sendmail(ui, sender, recipients, msg, mbox=None): + send = connect(ui, mbox=mbox) return send(sender, recipients, msg) def validateconfig(ui): diff --git a/tests/test-notify.t b/tests/test-notify.t --- a/tests/test-notify.t +++ b/tests/test-notify.t @@ -113,6 +113,9 @@ 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. + If set, the following entries will also be used to customize the notifications: @@ -350,7 +353,7 @@ test merge description: merge (run 'hg update' to get a working copy) -truncate multi-byte subject +non-ascii content and truncation of multi-byte subject $ cat <> $HGRCPATH > [notify] @@ -395,3 +398,54 @@ truncate multi-byte subject a +a (run 'hg update' to get a working copy) + +long lines + + $ cat <> $HGRCPATH + > [notify] + > maxsubject = 67 + > test = False + > mbox = mbox + > EOF + $ python -c 'print "no" * 500' >> a/a + $ hg --cwd a commit -A -m "long line" + $ hg --traceback --cwd b pull ../a + pulling from ../a + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + notify: sending 2 subscribers 1 changes + (run 'hg update' to get a working copy) + $ python -c 'import sys,re; print re.sub("\n\t", " ", file("b/mbox").read()),' + From test@test.com ... ... .. ..:..:.. .... (re) + Content-Type: text/plain; charset="us-ascii" + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit + X-Test: foo + Date: * (glob) + Subject: long line + From: test@test.com + X-Hg-Notification: changeset e0be44cf638b + Message-Id: (glob) + To: baz@test.com, foo@bar + + changeset e0be44cf638b in b + description: long line + diffstat: + + a | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + + diffs (8 lines): + + diff -r 7ea05ad269dc -r e0be44cf638b a + --- a/a Thu Jan 01 00:00:00 1970 +0000 + +++ b/a Thu Jan 01 00:00:00 1970 +0000 + @@ -1,3 +1,4 @@ + a + a + a + +nononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononononono +