Ticket #3057: bcc.patch
| File bcc.patch, 5.2 KB (added by eblot, 3 years ago) |
|---|
-
trac/ticket/notification.py
183 183 for author,ticket in cursor: 184 184 torecipients.append(author) 185 185 186 # Add smtp_always_cc address187 acc = self.config.get('notification', 'smtp_always_cc')188 if acc:189 ccrecipients += acc.replace(',', ' ').split()190 191 186 return (torecipients, ccrecipients) 192 187 193 188 def get_message_id(self, rcpt, modtime=0): -
trac/notification.py
50 50 """Reply-To address to use in notification emails.""") 51 51 52 52 smtp_always_cc = Option('notification', 'smtp_always_cc', '', 53 """Email address(es) to always send notifications to.""") 53 """Email address(es) to always send notifications to, 54 addresses can be see by all recipients (Cc:).""") 54 55 56 smtp_always_bcc = Option('notification', 'smtp_always_bcc', '', 57 """Email address(es) to always send notifications to, 58 addresses do not appear publicly (Bcc:). (''since 0.10'').""") 59 55 60 mime_encoding = Option('notification', 'mime_encoding', 'base64', 56 61 """Specify the MIME encoding scheme for emails (''since 0.10'').""") 57 62 58 allow_public_cc = BoolOption('notification', 'allow_public_cc', 'false',59 """Recipients can see email addresses of other CC'ed recipients 60 (''since 0.10'').""")63 use_public_cc = BoolOption('notification', 'use_public_cc', 'false', 64 """Recipients can see email addresses of other CC'ed recipients. 65 (''since 0.10'').""") 61 66 62 maxheaderlen = Option('notification', 'maxheaderlen', '78') 67 maxheaderlen = Option('notification', 'maxheaderlen', '78', 68 """Maximum length of SMTP headers. (''since 0.10'').""") 63 69 64 70 65 71 class Notify(object): … … 243 249 from email.Utils import formatdate, formataddr 244 250 body = self.hdf.render(self.template_name) 245 251 projname = self.config.get('project', 'name') 246 public_cc = self.config.getbool('notification', ' allow_public_cc')252 public_cc = self.config.getbool('notification', 'use_public_cc') 247 253 headers = {} 248 254 headers['X-Mailer'] = 'Trac %s, by Edgewall Software' % __version__ 249 255 headers['X-Trac-Version'] = __version__ … … 253 259 headers['From'] = (projname, self.from_email) 254 260 headers['Sender'] = self.from_email 255 261 headers['Reply-To'] = self.replyto_email 256 # Format and remove invalid addresses 257 toaddrs = filter(lambda x: x, \ 258 [self.get_smtp_address(addr) for addr in torcpts]) 259 ccaddrs = filter(lambda x: x, \ 260 [self.get_smtp_address(addr) for addr in ccrcpts]) 261 # Remove duplicates 262 totmp = [] 263 cctmp = [] 264 for addr in toaddrs: 265 if addr not in totmp: 266 totmp.append(addr) 267 for addr in [c for c in ccaddrs if c not in totmp]: 268 if addr not in cctmp: 269 cctmp.append(addr) 270 (toaddrs, ccaddrs) = (totmp, cctmp) 262 263 def build_addresses(rcpts): 264 """Format and remove invalid addresses""" 265 return filter(lambda x: x, \ 266 [self.get_smtp_address(addr) for addr in rcpts]) 267 268 def remove_dup(rcpts, all): 269 """Remove duplicates""" 270 tmp = [] 271 for rcpt in rcpts: 272 if not rcpt in all: 273 tmp.append(rcpt) 274 all.append(rcpt) 275 return (tmp, all) 276 277 toaddrs = build_addresses(torcpts) 278 ccaddrs = build_addresses(ccrcpts) 279 accparam = self.config.get('notification', 'smtp_always_cc') 280 accaddrs = accparam and \ 281 build_addresses(accparam.replace(',', ' ').split()) or [] 282 bccparam = self.config.get('notification', 'smtp_always_bcc') 283 bccaddrs = bccparam and \ 284 build_addresses(bccparam.replace(',', ' ').split()) or [] 285 286 recipients = [] 287 (toaddrs, recipients) = remove_dup(toaddrs, recipients) 288 (ccaddrs, recipients) = remove_dup(ccaddrs, recipients) 289 (accaddrs, recipients) = remove_dup(accaddrs, recipients) 290 (bccaddrs, recipients) = remove_dup(bccaddrs, recipients) 291 292 pcc = accaddrs 293 if public_cc: 294 pcc += ccaddrs 271 295 if toaddrs: 272 296 headers['To'] = ', '.join(toaddrs) 273 if p ublic_cc:274 headers['Cc'] = ', '.join( ccaddrs)297 if pcc: 298 headers['Cc'] = ', '.join(pcc) 275 299 headers['Date'] = formatdate() 276 300 charset = 'utf-8' 277 301 if not self._pref_encoding: … … 290 314 msg.set_charset(self._charset) 291 315 self.add_headers(msg, headers); 292 316 self.add_headers(msg, mime_headers); 293 recipients = toaddrs + ccaddrs294 317 self.env.log.debug("Sending SMTP notification to %s on port %d to %s" 295 318 % (self.smtp_server, self.smtp_port, recipients)) 296 319 msgtext = msg.as_string()
