Edgewall Software

Ticket #464: yan.diff

File yan.diff, 1.0 KB (added by David M. Lee <dmlee@…>, 4 years ago)

Notify patch that maps usernames to email using the session information

  • trac/Notify.py

     
    133133    def get_email_addresses(self, txt): 
    134134        import email.Utils 
    135135        emails = [x[1] for x in  email.Utils.getaddresses([str(txt)])] 
    136         return filter(lambda x: x.find('@') > -1, emails) 
     136        return_addr = filter(lambda x: x.find('@') > -1, emails) 
     137        # dig email addresses out of sessions 
     138        users = filter(lambda x: x.find('@') < 0, emails) 
     139        cursor = self.db.cursor() 
     140        for user in users: 
     141            if user != 'anonymous': 
     142                cursor.execute("SELECT var_value FROM session WHERE username = '" + user + "' AND var_name = 'email' GROUP BY var_value") 
     143                row = cursor.fetchone() 
     144                if row and row[0]: 
     145                    return_addr.append(row[0]) 
     146        return return_addr 
    137147 
    138148    def begin_send(self): 
    139149        self.server = smtplib.SMTP(self.smtp_server)