#3447: Email Notification: Local users, Reply-To, Message-Id (patch)
-------------------------------+--------------------------------------------
 Reporter:  [EMAIL PROTECTED]  |       Owner:  jonas
     Type:  enhancement        |      Status:  new  
 Priority:  normal             |   Milestone:       
Component:  general            |     Version:  0.9.6
 Severity:  trivial            |    Keywords:       
-------------------------------+--------------------------------------------
 Patch components:

 1) I use Trac on Linux system, where I use UNIX usernames for web auth.
 With this patch and new boolean configuration option, my users do not have
 to fill-in their e-mail address to be notified (they're concated
 automatically for them).

 2) Reply-To header is added to message only when reply-to configuration
 option is given (for nicer e-mail displaying).

 3) 'trac.' is prepended to Message-Id for quick distinguish in maillog.

 So far, patch is unix specific (uses module pwd).

 Thanks for consideration,

 Vlada

 Patch:

 {{{
 #!diff
 --- Notify.py.orig      2006-07-21 14:55:35.000000000 +0200
 +++ Notify.py   2006-07-21 15:29:11.000000000 +0200
 @@ -21,11 +21,11 @@
  from trac.web.main import populate_hdf

  import md5
  import time
  import smtplib
 +import pwd

  class Notify:
      """Generic notification class for Trac. Subclass this to implement
      different methods."""

 @@ -132,11 +132,12 @@
          msg['X-Trac-Project'] =  projname
          msg['X-URL'] =  self.config.get('project','url')
          msg['Subject'] = Header(self.subject, 'utf-8')
          msg['From'] = '%s <%s>' % (projname, self.from_email)
          msg['Sender'] = self.from_email
 -        msg['Reply-To'] = self.replyto_email
 +        if self.replyto_email:
 +            msg['Reply-To'] = self.replyto_email
          msg['To'] = rcpt
          msg['Date'] = formatdate()
          for hdr in mime_headers.keys():
              msg[hdr] = mime_headers[hdr]
          self.env.log.debug("Sending SMTP notification to %s on port %d"
 @@ -268,10 +269,12 @@
      def get_recipients(self, tktid):
          notify_reporter = self.config.getbool('notification',
                                                'always_notify_reporter')
          notify_owner = self.config.getbool('notification',
                                             'always_notify_owner')
 +        fallback_local_email = self.config.getbool('notification',
 +
 'fallback_local_email')

          recipients = self.prev_cc
          cursor = self.db.cursor()

          # Harvest email addresses from the cc, reporter, and owner fields
 @@ -297,15 +300,22 @@
          if acc:
              recipients += acc.replace(',', ' ').split()

          # now convert recipients into email addresses where necessary
          emails = []
 +        recip_local_hostname = self.from_email[self.from_email.find('@')
 + 1:]
          for recipient in recipients:
              if recipient.find('@') >= 0:
                  emails.append(recipient)
              elif self.email_map.has_key(recipient):
                  emails.append(self.email_map[recipient])
 +            elif fallback_local_email:
 +                try:
 +                  pwd.getpwnam(recipient)
 +                  emails.append(recipient + '@' + recip_local_hostname)
 +                except KeyError:
 +                  pass

          # Remove duplicates
          result = []
          for e in emails:
              if e not in result:
 @@ -316,11 +326,11 @@
          """Generate a predictable, but sufficiently unique message ID."""
          s = '%s.%08d.%d.%s' % (self.config.get('project', 'url'),
                                 int(self.ticket.id), modtime, rcpt)
          dig = md5.new(s).hexdigest()
          host = self.from_email[self.from_email.find('@') + 1:]
 -        msgid = '<[EMAIL PROTECTED]>' % (len(s), dig, host)
 +        msgid = '<[EMAIL PROTECTED]>' % (len(s), dig, host)
          return msgid

      def send(self, rcpt):
          hdrs = {}
          hdrs['Message-ID'] = self.get_message_id(rcpt, self.modtime)
 }}}

-- 
Ticket URL: <http://trac.edgewall.org/ticket/3447>
The Trac Project <http://trac.edgewall.com/>
_______________________________________________
Trac-Tickets mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac-tickets

Reply via email to