Mercurial > hg-stable
comparison hgext/notify.py @ 7116:e981725da3fe
notify: mime-encode messages
- addresses will be properly encoded
- message bodies will also be encoded as we are not sending
patches that are meant to be applied
- update test output
- adapt test-keyword to ignore the new headers
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Sat, 12 Jul 2008 19:12:18 +0100 |
parents | a3fd4aa154af |
children | 9df67ee30ef5 |
comparison
equal
deleted
inserted
replaced
7115:c5c2d43b01da | 7116:e981725da3fe |
---|---|
104 self.ui.readsections(cfg, 'usersubs', 'reposubs') | 104 self.ui.readsections(cfg, 'usersubs', 'reposubs') |
105 self.repo = repo | 105 self.repo = repo |
106 self.stripcount = int(self.ui.config('notify', 'strip', 0)) | 106 self.stripcount = int(self.ui.config('notify', 'strip', 0)) |
107 self.root = self.strip(self.repo.root) | 107 self.root = self.strip(self.repo.root) |
108 self.domain = self.ui.config('notify', 'domain') | 108 self.domain = self.ui.config('notify', 'domain') |
109 self.charsets = mail._charsets(self.ui) | |
109 self.subs = self.subscribers() | 110 self.subs = self.subscribers() |
110 | 111 |
111 mapfile = self.ui.config('notify', 'style') | 112 mapfile = self.ui.config('notify', 'style') |
112 template = (self.ui.config('notify', hooktype) or | 113 template = (self.ui.config('notify', hooktype) or |
113 self.ui.config('notify', 'template')) | 114 self.ui.config('notify', 'template')) |
154 subs[self.fixmail(user)] = 1 | 155 subs[self.fixmail(user)] = 1 |
155 for pat, users in self.ui.configitems('reposubs'): | 156 for pat, users in self.ui.configitems('reposubs'): |
156 if fnmatch.fnmatch(self.repo.root, pat): | 157 if fnmatch.fnmatch(self.repo.root, pat): |
157 for user in users.split(','): | 158 for user in users.split(','): |
158 subs[self.fixmail(user)] = 1 | 159 subs[self.fixmail(user)] = 1 |
159 return util.sort(subs) | 160 subs = util.sort(subs) |
161 return [mail.addressencode(self.ui, s, self.charsets) for s in subs] | |
160 | 162 |
161 def url(self, path=None): | 163 def url(self, path=None): |
162 return self.ui.config('web', 'baseurl') + (path or self.root) | 164 return self.ui.config('web', 'baseurl') + (path or self.root) |
163 | 165 |
164 def node(self, node): | 166 def node(self, node): |
178 '''send message.''' | 180 '''send message.''' |
179 | 181 |
180 p = email.Parser.Parser() | 182 p = email.Parser.Parser() |
181 msg = p.parsestr(data) | 183 msg = p.parsestr(data) |
182 | 184 |
183 def fix_subject(): | 185 # store sender and subject |
186 sender, subject = msg['From'], msg['Subject'] | |
187 # create fresh mime message from msg body | |
188 text = msg.get_payload() | |
189 # for notification prefer readability over data precision | |
190 msg = mail.mimeencode(self.ui, text, self.charsets) | |
191 | |
192 def fix_subject(subject): | |
184 '''try to make subject line exist and be useful.''' | 193 '''try to make subject line exist and be useful.''' |
185 | 194 |
186 subject = msg['Subject'] | |
187 if not subject: | 195 if not subject: |
188 if count > 1: | 196 if count > 1: |
189 subject = _('%s: %d new changesets') % (self.root, count) | 197 subject = _('%s: %d new changesets') % (self.root, count) |
190 else: | 198 else: |
191 changes = self.repo.changelog.read(node) | 199 changes = self.repo.changelog.read(node) |
192 s = changes[4].lstrip().split('\n', 1)[0].rstrip() | 200 s = changes[4].lstrip().split('\n', 1)[0].rstrip() |
193 subject = '%s: %s' % (self.root, s) | 201 subject = '%s: %s' % (self.root, s) |
194 maxsubject = int(self.ui.config('notify', 'maxsubject', 67)) | 202 maxsubject = int(self.ui.config('notify', 'maxsubject', 67)) |
195 if maxsubject and len(subject) > maxsubject: | 203 if maxsubject and len(subject) > maxsubject: |
196 subject = subject[:maxsubject-3] + '...' | 204 subject = subject[:maxsubject-3] + '...' |
197 del msg['Subject'] | 205 msg['Subject'] = mail.headencode(self.ui, subject, self.charsets) |
198 msg['Subject'] = subject | 206 |
199 | 207 def fix_sender(sender): |
200 def fix_sender(): | |
201 '''try to make message have proper sender.''' | 208 '''try to make message have proper sender.''' |
202 | 209 |
203 sender = msg['From'] | |
204 if not sender: | 210 if not sender: |
205 sender = self.ui.config('email', 'from') or self.ui.username() | 211 sender = self.ui.config('email', 'from') or self.ui.username() |
206 if '@' not in sender or '@localhost' in sender: | 212 if '@' not in sender or '@localhost' in sender: |
207 sender = self.fixmail(sender) | 213 sender = self.fixmail(sender) |
208 del msg['From'] | 214 msg['From'] = mail.addressencode(self.ui, sender, self.charsets) |
209 msg['From'] = sender | |
210 | 215 |
211 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") | 216 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
212 fix_subject() | 217 fix_subject(subject) |
213 fix_sender() | 218 fix_sender(sender) |
214 | 219 |
215 msg['X-Hg-Notification'] = 'changeset ' + short(node) | 220 msg['X-Hg-Notification'] = 'changeset ' + short(node) |
216 if not msg['Message-Id']: | 221 if not msg['Message-Id']: |
217 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % | 222 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % |
218 (short(node), int(time.time()), | 223 (short(node), int(time.time()), |