Edgewall Software

Ticket #3057: bcc.patch

File bcc.patch, 5.2 KB (added by eblot, 3 years ago)

Proposed patch - not complete, needs unit test(s)

  • trac/ticket/notification.py

     
    183183            for author,ticket in cursor: 
    184184                torecipients.append(author) 
    185185 
    186         # Add smtp_always_cc address 
    187         acc = self.config.get('notification', 'smtp_always_cc') 
    188         if acc: 
    189             ccrecipients += acc.replace(',', ' ').split() 
    190  
    191186        return (torecipients, ccrecipients) 
    192187 
    193188    def get_message_id(self, rcpt, modtime=0): 
  • trac/notification.py

     
    5050        """Reply-To address to use in notification emails.""") 
    5151 
    5252    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:).""") 
    5455 
     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 
    5560    mime_encoding = Option('notification', 'mime_encoding', 'base64', 
    5661        """Specify the MIME encoding scheme for emails (''since 0.10'').""") 
    5762 
    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'').""") 
    6166 
    62     maxheaderlen = Option('notification', 'maxheaderlen', '78') 
     67    maxheaderlen = Option('notification', 'maxheaderlen', '78', 
     68        """Maximum length of SMTP headers. (''since 0.10'').""") 
    6369 
    6470 
    6571class Notify(object): 
     
    243249        from email.Utils import formatdate, formataddr 
    244250        body = self.hdf.render(self.template_name) 
    245251        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') 
    247253        headers = {} 
    248254        headers['X-Mailer'] = 'Trac %s, by Edgewall Software' % __version__ 
    249255        headers['X-Trac-Version'] =  __version__ 
     
    253259        headers['From'] = (projname, self.from_email) 
    254260        headers['Sender'] = self.from_email 
    255261        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 
    271295        if toaddrs: 
    272296            headers['To'] = ', '.join(toaddrs) 
    273         if public_cc: 
    274             headers['Cc'] = ', '.join(ccaddrs) 
     297        if pcc: 
     298            headers['Cc'] = ', '.join(pcc) 
    275299        headers['Date'] = formatdate() 
    276300        charset = 'utf-8' 
    277301        if not self._pref_encoding: 
     
    290314        msg.set_charset(self._charset) 
    291315        self.add_headers(msg, headers); 
    292316        self.add_headers(msg, mime_headers); 
    293         recipients = toaddrs + ccaddrs 
    294317        self.env.log.debug("Sending SMTP notification to %s on port %d to %s" 
    295318                           % (self.smtp_server, self.smtp_port, recipients)) 
    296319        msgtext = msg.as_string()