Edgewall Software
Modify

Ticket #3447 (closed enhancement: wontfix)

Opened 6 years ago

Last modified 3 years ago

[patch] Email Notification: Local users, Reply-To, Message-Id

Reported by: tuttle@… Owned by: jonas
Priority: normal Milestone:
Component: ticket system Version: 0.9.6
Severity: trivial Keywords: notification email
Cc: tuttle@…
Release Notes:
API Changes:

Description

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:

  • Notify.py

    old new (this hunk was shorter than expected) 
    2121from trac.web.main import populate_hdf 
    2222 
    2323import md5 
    2424import time 
    2525import smtplib 
     26import pwd 
    2627 
    2728class Notify: 
    2829    """Generic notification class for Trac. Subclass this to implement 
    2930    different methods.""" 
    3031 
     
    132132        msg['X-Trac-Project'] =  projname 
    133133        msg['X-URL'] =  self.config.get('project','url') 
    134134        msg['Subject'] = Header(self.subject, 'utf-8') 
    135135        msg['From'] = '%s <%s>' % (projname, self.from_email) 
    136136        msg['Sender'] = self.from_email 
    137         msg['Reply-To'] = self.replyto_email 
     137        if self.replyto_email: 
     138            msg['Reply-To'] = self.replyto_email 
    138139        msg['To'] = rcpt 
    139140        msg['Date'] = formatdate() 
    140141        for hdr in mime_headers.keys(): 
    141142            msg[hdr] = mime_headers[hdr] 
    142143        self.env.log.debug("Sending SMTP notification to %s on port %d" 
     
    268269    def get_recipients(self, tktid): 
    269270        notify_reporter = self.config.getbool('notification', 
    270271                                              'always_notify_reporter') 
    271272        notify_owner = self.config.getbool('notification', 
    272273                                           'always_notify_owner') 
     274        fallback_local_email = self.config.getbool('notification', 
     275                                                   'fallback_local_email') 
    273276 
    274277        recipients = self.prev_cc 
    275278        cursor = self.db.cursor() 
    276279 
    277280        # Harvest email addresses from the cc, reporter, and owner fields 
     
    297300        if acc: 
    298301            recipients += acc.replace(',', ' ').split() 
    299302 
    300303        # now convert recipients into email addresses where necessary 
    301304        emails = [] 
     305        recip_local_hostname = self.from_email[self.from_email.find('@') + 1:] 
    302306        for recipient in recipients: 
    303307            if recipient.find('@') >= 0: 
    304308                emails.append(recipient) 
    305309            elif self.email_map.has_key(recipient): 
    306310                emails.append(self.email_map[recipient]) 
     311            elif fallback_local_email: 
     312                try: 
     313                  pwd.getpwnam(recipient) 
     314                  emails.append(recipient + '@' + recip_local_hostname) 
     315                except KeyError: 
     316                  pass 
    307317 
    308318        # Remove duplicates 
    309319        result = [] 
    310320        for e in emails: 
    311321            if e not in result: 
     
    316326        """Generate a predictable, but sufficiently unique message ID.""" 
    317327        s = '%s.%08d.%d.%s' % (self.config.get('project', 'url'), 
    318328                               int(self.ticket.id), modtime, rcpt) 
    319329        dig = md5.new(s).hexdigest() 
    320330        host = self.from_email[self.from_email.find('@') + 1:] 
    321         msgid = '<%03d.%s@%s>' % (len(s), dig, host) 
     331        msgid = '<trac.%03d.%s@%s>' % (len(s), dig, host) 
    322332        return msgid 
    323333 
    324334    def send(self, rcpt): 
    325335        hdrs = {} 
    326336        hdrs['Message-ID'] = self.get_message_id(rcpt, self.modtime) 

Attachments

Change History

comment:1 Changed 6 years ago by eblot

  • Component changed from general to ticket system

Some comments:

  • As long as it is platform-specific, there are few chances that the patch get merged. It would prevent Trac from running on other platforms (Windows, ...)
  • Further changes in the 0.9.x branch are now mostly for security fixes. It is unlikely that new enhancement/features get merged into this branch. 0.10 is due soon, so non-security patches would better fit this upcoming release.
  • I'm not sure to understand the call to pwd.getpwnam(), as you do not make use of the results (?)
  • Notifications for 0.10 have been reworked, and a feature that looks like the fallback email option is already available.

comment:2 in reply to: ↑ description Changed 6 years ago by Markus Tacker <m@…>

Replying to tuttle@sandbox.cz:

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).

notification.use_short_addr exists for that:
See TracIni.

comment:3 Changed 5 years ago by anonymous

This is a duplicate of #395

comment:4 Changed 5 years ago by sid

  • Keywords notification email added
  • Summary changed from Email Notification: Local users, Reply-To, Message-Id (patch) to [patch] Email Notification: Local users, Reply-To, Message-Id

No, it is not a duplicate of #395.

comment:5 Changed 5 years ago by eblot

Well, either the ticket is about a patch, and should be closed as wontfix because the patch will never get merged (several issues, and not aligned on a supported Trac release), or the ticket is about missing features, and I do not think changing the summary was really required in this later case.

I think it should be closed.

comment:6 Changed 5 years ago by cboos

  • Resolution set to wontfix
  • Status changed from new to closed

Agreed, closing.

To tuttle@…: please have a look at the existing notification topics, and see if you can contribute to other topics (e.g. point 1. is somewhat related to #1359, although more general)

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from jonas. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.