##// END OF EJS Templates
templater: move email function to util
Matt Mackall -
r5975:75d9fe70 default
parent child Browse files
Show More
@@ -69,7 +69,7 b' def __gather(ui, repo, node1, node2):'
69 modified, added, removed, deleted, unknown = changes
69 modified, added, removed, deleted, unknown = changes
70
70
71 who = repo.changelog.read(node2)[1]
71 who = repo.changelog.read(node2)[1]
72 who = templater.email(who) # get the email of the person
72 who = util.email(who) # get the email of the person
73
73
74 mmap1 = repo.manifest.read(repo.changelog.read(node1)[0])
74 mmap1 = repo.manifest.read(repo.changelog.read(node1)[0])
75 mmap2 = repo.manifest.read(repo.changelog.read(node2)[0])
75 mmap2 = repo.manifest.read(repo.changelog.read(node2)[0])
@@ -282,7 +282,7 b' class bugzilla(object):'
282 root=self.repo.root,
282 root=self.repo.root,
283 webroot=webroot(self.repo.root))
283 webroot=webroot(self.repo.root))
284 data = self.ui.popbuffer()
284 data = self.ui.popbuffer()
285 self.add_comment(bugid, data, templater.email(ctx.user()))
285 self.add_comment(bugid, data, util.email(ctx.user()))
286
286
287 def hook(ui, repo, hooktype, node=None, **kwargs):
287 def hook(ui, repo, hooktype, node=None, **kwargs):
288 '''add comment to bugzilla for each changeset that refers to a
288 '''add comment to bugzilla for each changeset that refers to a
@@ -135,7 +135,7 b' class notifier(object):'
135 def fixmail(self, addr):
135 def fixmail(self, addr):
136 '''try to clean up email addresses.'''
136 '''try to clean up email addresses.'''
137
137
138 addr = templater.email(addr.strip())
138 addr = util.email(addr.strip())
139 if self.domain:
139 if self.domain:
140 a = addr.find('@localhost')
140 a = addr.find('@localhost')
141 if a != -1:
141 if a != -1:
@@ -231,7 +231,7 b' class notifier(object):'
231 else:
231 else:
232 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
232 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
233 (len(self.subs), count))
233 (len(self.subs), count))
234 mail.sendmail(self.ui, templater.email(msg['From']),
234 mail.sendmail(self.ui, util.email(msg['From']),
235 self.subs, msgtext)
235 self.subs, msgtext)
236
236
237 def diff(self, node, ref):
237 def diff(self, node, ref):
@@ -6,7 +6,7 b''
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 from i18n import _
8 from i18n import _
9 import os, smtplib, templater, util, socket
9 import os, smtplib, util, socket
10
10
11 def _smtp(ui):
11 def _smtp(ui):
12 '''build an smtp connection and return a function to send mail'''
12 '''build an smtp connection and return a function to send mail'''
@@ -50,8 +50,8 b' def _smtp(ui):'
50 def _sendmail(ui, sender, recipients, msg):
50 def _sendmail(ui, sender, recipients, msg):
51 '''send mail using sendmail.'''
51 '''send mail using sendmail.'''
52 program = ui.config('email', 'method')
52 program = ui.config('email', 'method')
53 cmdline = '%s -f %s %s' % (program, templater.email(sender),
53 cmdline = '%s -f %s %s' % (program, util.email(sender),
54 ' '.join(map(templater.email, recipients)))
54 ' '.join(map(util.email, recipients)))
55 ui.note(_('sending mail: %s\n') % cmdline)
55 ui.note(_('sending mail: %s\n') % cmdline)
56 fp = os.popen(cmdline, 'w')
56 fp = os.popen(cmdline, 'w')
57 fp.write(msg)
57 fp.write(msg)
@@ -214,12 +214,6 b' def domain(author):'
214 if f >= 0: author = author[:f]
214 if f >= 0: author = author[:f]
215 return author
215 return author
216
216
217 def email(author):
218 '''get email of author.'''
219 r = author.find('>')
220 if r == -1: r = None
221 return author[author.find('<')+1:r]
222
223 def person(author):
217 def person(author):
224 '''get name of author, or else username.'''
218 '''get name of author, or else username.'''
225 f = author.find('<')
219 f = author.find('<')
@@ -257,7 +251,7 b' common_filters = {'
257 "age": age,
251 "age": age,
258 "date": lambda x: util.datestr(x),
252 "date": lambda x: util.datestr(x),
259 "domain": domain,
253 "domain": domain,
260 "email": email,
254 "email": util.email,
261 "escape": lambda x: cgi.escape(x, True),
255 "escape": lambda x: cgi.escape(x, True),
262 "fill68": lambda x: fill(x, width=68),
256 "fill68": lambda x: fill(x, width=68),
263 "fill76": lambda x: fill(x, width=76),
257 "fill76": lambda x: fill(x, width=76),
@@ -1636,6 +1636,12 b' def shortuser(user):'
1636 user = user[:f]
1636 user = user[:f]
1637 return user
1637 return user
1638
1638
1639 def email(author):
1640 '''get email of author.'''
1641 r = author.find('>')
1642 if r == -1: r = None
1643 return author[author.find('<')+1:r]
1644
1639 def ellipsis(text, maxlength=400):
1645 def ellipsis(text, maxlength=400):
1640 """Trim string to at most maxlength (default: 400) characters."""
1646 """Trim string to at most maxlength (default: 400) characters."""
1641 if len(text) <= maxlength:
1647 if len(text) <= maxlength:
General Comments 0
You need to be logged in to leave comments. Login now