def mail2project(self, message) : """relays an email message to a project""" # keep copy of original message for error handling original_message = email.message_from_string(message) #keep trac email : trac_mail = self.env.config.get('notification', 'smtp_replyto') # whether or not to email back on error email_errors = self.env.config.getbool('mail', 'email_errors', True) # lookup the message message = self.lookup(message) # get the handlers handlers = ExtensionPoint(IEmailHandler).extensions(self.env) _handlers = self.env.config.getlist('mail', 'handlers') if not _handlers: # default value _handlers = [ 'RemoveQuotes', 'ReplyToTicket', 'EmailToTicket' ] handler_dict = dict([(h.__class__.__name__, h) for h in handlers]) handlers = [handler_dict[h] for h in _handlers if h in handler_dict ] # handle the message warnings = [] #is this email treated ? email_treated = False for handler in handlers: if not handler.match(message) : continue try: email_treated = True message = handler.invoke(message, warnings) except Exception, e: # handle the error print "Exception in user code:" print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60 raise except EmailException, e: if email_errors and original_message['from']: subject = reply_subject(original_message['subject']) response = 'Subject: %s\n\n%s' % (subject, reply_body(str(e), original_message)) send_email(self.env, trac_mail, [ original_message['from'] ], response ) warnings = [] # clear warnings return else: raise
else: raise # if the message is consumed, quit processing if not message: break if not email_treated : warnings.append("Your email was not treated. It match none of the condition to be treated") # email warnings if warnings: # format warning message if len(warnings) == 1: body = warnings[0] pass else: body = "\n\n".join(["* %s" % warning.strip() for warning in warnings]) # notify the sender subject = reply_subject(original_message['subject']) response = 'Subject: %s\n\n%s' % (subject, reply_body(body, original_message)) send_email(self.env, trac_mail, [ original_message['from'] ], response )