Changeset 221


Ignore:
Timestamp:
10/10/08 14:35:48 (15 years ago)
Author:
bas
Message:

email2trac.py.in:

  • closes ticket #87, #74
  • added a more general function email_header_acl()
    • so we can enable black/white lists on every email header field
  • Added white_list option
  • removed MAILER-DAEMON@ from black_list. No defaults anymore
  • add patches from hju at jochenkuhl dot de to enable alternate template config for trac 0.11
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r220 r221  
    282282                        return False
    283283
    284 
    285         def blacklisted_from(self):
    286                 """
    287                 This function wil check if the email address is in the black list
    288                 """
     284        def email_header_acl(self, keyword, header_field, default):
     285                """
     286                This function wil check if the email address is allowed or denied
     287                to send mail to the ticket list
     288            """
    289289                try:
    290                         black_list = self.parameters['black_list']
     290                        mail_addresses = self.parameters[keyword]
     291
     292                        # Check if we have an empty string
     293                        #
     294                        if not mail_addresses:
     295                                return default
     296
    291297                except KeyError, detail:
    292                         black_list = 'MAILER-DAEMON@'
    293 
    294                 black_list = string.split(black_list, ',')     
    295                 if not black_list.count('MAILER-DAEMON@'):
    296                         black_list.append('MAILER-DAEMON@')
    297 
    298                 for entry in black_list:       
     298                        if self.DEBUG > 2 :
     299                                print '%s not defined, all messages are allowed.' %(keyword)
     300
     301                        return default
     302
     303                mail_addresses = string.split(mail_addresses, ',')
     304
     305                for entry in mail_addresses:
    299306                        entry = entry.strip()
    300                         FROM_RE = re.compile(entry, re.VERBOSE|re.IGNORECASE)
    301                         result =  FROM_RE.search(self.email_addr)
     307                        TO_RE = re.compile(entry, re.VERBOSE|re.IGNORECASE)
     308                        result =  TO_RE.search(header_field)
    302309                        if result:
    303310                                return True
     
    404411
    405412                self.email_from = self.email_to_unicode(message['from'])
    406                 self.author, self.email_addr  = email.Utils.parseaddr(self.email_from)
     413                self.author, self.mail_addr  = email.Utils.parseaddr(self.email_from)
    407414
    408415                # Maybe for later user
     
    783790                m = email.message_from_file(fp)
    784791                if not m:
     792                        if self.DEBUG:
     793                                print "This is not a valid email message format"
    785794                        return
    786795
     
    792801                self.get_sender_info(m)
    793802
    794                 if self.blacklisted_from():
    795                         if self.DEBUG > 1 :
    796                                 print 'Message rejected : From: in blacklist'
    797                         return False
     803       
     804                if not self.email_header_acl('white_list', self.email_addr, True):
     805                        if self.DEBUG > 1 :
     806                                print 'Message rejected : %s not in white list' %(self.email_addr)
     807                        return False
     808
     809                if self.email_header_acl('black_list', self.email_addr, False):
     810                        if self.DEBUG > 1 :
     811                                print 'Message rejected : %s in black list' %(self.email_addr)
     812                        return False
    798813
    799814                # If drop the message
     
    960975
    961976                        if self.notify_template:
    962                                 tn.template_name = self.notify_template;
     977                                if self.VERSION == 0.11:
     978                                        from trac.web.chrome import Chrome
     979                                        #if not new:
     980                                        #       tn.template_name += ".update"
     981                                        tn.template = Chrome(tn.env).load_template(tn.template_name, method='text')
     982                                               
     983                                else:
     984                                        tn.template_name = self.notify_template;
    963985
    964986                        tn.notify(tkt, new, modtime)
Note: See TracChangeset for help on using the changeset viewer.