Ticket #77: email2trac.diff

File email2trac.diff, 1.9 KB (added by jon.wbstr@…, 16 years ago)

Patch to add discussed features

  • email2trac.py

     
    305305
    306306                return False
    307307
     308        def allowed_recipient(self):
     309                """
     310                This function wil check if the email address is configured to receive tickets.
     311                """
     312                try:
     313                        toaddress_list = self.parameters['rcptaddress_list']
     314                except KeyError, detail:
     315                        if self.DEBUG > 2 :
     316                                print 'rcptaddress_list not defined, all messages allowed.'
     317                        return True
     318
     319                toaddress_list = string.split(toaddress_list)   
     320                for entry in toaddress_list:   
     321                        entry = entry.strip()
     322                        TO_RE = re.compile(entry, re.VERBOSE|re.IGNORECASE)
     323                        result =  TO_RE.search(self.to_email_addr)
     324                        if result:
     325                                return True
     326
     327                return False
     328
    308329        def email_to_unicode(self, message_str):
    309330                """
    310331                Email has 7 bit ASCII code, convert it to unicode with the charset
     
    405426
    406427                self.email_from = self.email_to_unicode(message['from'])
    407428                self.author, self.email_addr  = email.Utils.parseaddr(self.email_from)
     429                """
     430                Get the recipients name and email address
     431                """
     432                self.email_to = self.email_to_unicode(message['to'])
     433                self.to_name, self.to_email_addr = email.Utils.parseaddr (self.email_to)
    408434
    409435                # Maybe for later user
    410436                #self.email_from =  self.email_to_unicode(self.email_addr)
     
    794820                                print 'Message rejected : From: in blacklist'
    795821                        return False
    796822
     823                if not self.allowed_recipient():
     824                        if self.DEBUG > 1 :
     825                                print 'Message rejected : To: not permitted'
     826                        return False
     827
    797828                # If drop the message
    798829                #
    799830                if self.spam(m) == 'drop':
     
    10621093
    10631094                                os.unlink(path)
    10641095                                continue
     1096                        elif (filename == 'winmail.dat') or (filename == 'part0001.html'):
     1097                                #status = '%s\nFile %s not wanted.\n\n' \
     1098                                #       %(status, filename)
     1099
     1100                                os.unlink(path)
     1101                                continue
    10651102                        else:
    10661103                                count = count + 1
    10671104