示例#1
0
文件: compat.py 项目: pkdevbox/trac
 def format_header(self, key, name, email=None):
     header = create_header(key, name, self._charset)
     if not email:
         return header
     else:
         header = str(header).replace("\\", r"\\").replace('"', r"\"")
         return '"%s" <%s>' % (header, email)
示例#2
0
 def format_header(self, key, name, email=None):
     header = create_header(key, name, self._charset)
     if not email:
         return header
     else:
         header = str(header).replace('\\', r'\\') \
                             .replace('"', r'\"')
         return '"%s" <%s>' % (header, email)
示例#3
0
 def decorate_message(self, event, message, charset):
     if event.realm != 'ticket':
         return
     from_email = self._get_from_email(event)
     if event.category == 'batchmodify':
         tickets = sort_tickets_by_priority(self.env, event.target)
         subject = self._format_subj_batchmodify(tickets)
         targetid = ','.join(map(str, tickets))
         msgid = self._get_message_id(targetid, from_email, event.time)
     else:
         subject = self._format_subj(event)
         ticket = event.target
         targetid = '%08d' % ticket.id
         more = ticket['reporter'] or ''
         msgid = self._get_message_id(targetid, from_email, None, more)
         url = self.env.abs_href.ticket(ticket.id)
         if event.category != 'created':
             set_header(message, 'In-Reply-To', msgid, charset)
             set_header(message, 'References', msgid, charset)
             msgid = self._get_message_id(targetid, from_email, event.time,
                                          more)
             cnum = ticket.get_comment_number(event.time)
             if cnum is not None:
                 url += '#comment:%d' % cnum
         set_header(message, 'X-Trac-Ticket-ID', ticket.id, charset)
         set_header(message, 'X-Trac-Ticket-URL', url, charset)
         # When owner, reporter and updater are listed in the Cc header,
         # move the address to To header.
         if NotificationSystem(self.env).use_public_cc:
             to_addrs = set()
             matcher = RecipientMatcher(self.env)
             for rcpt in ticket['owner'], ticket['reporter'], event.author:
                 rcpt = matcher.match_recipient(rcpt)
                 if not rcpt:
                     continue
                 addr = rcpt[2]
                 if addr:
                     to_addrs.add(addr)
             if to_addrs:
                 cc_addrs = get_message_addresses(message, 'Cc')
                 to_addrs &= set(addr for name, addr in cc_addrs)
             if to_addrs:
                 cc_header = ', '.join(create_header('Cc', (name, addr),
                                                     charset)
                                       for name, addr in cc_addrs
                                       if addr not in to_addrs)
                 if cc_header:
                     set_header(message, 'Cc', cc_header, charset)
                 elif 'Cc' in message:
                     del message['Cc']
                 to_header = ', '.join(sorted(to_addrs))
                 set_header(message, 'To', to_header, charset)
     set_header(message, 'Subject', subject, charset)
     set_header(message, 'Message-ID', msgid, charset)