def route_email(peer, mailfrom, rcpttos, data): ''' Route messages according to their destination: <topic>@<mount_point>.<subproj2>.<subproj1>.<project>.projects.domain.net gets sent to c.app.handle_message(topic, message) ''' try: msg = mail_util.parse_message(data) except Exception: # pragma no cover log.exception('Parse Error: (%r,%r,%r)', peer, mailfrom, rcpttos) return if mail_util.is_autoreply(msg): log.info('Skipping autoreply message: %s', msg['headers']) return mail_user = mail_util.identify_sender(peer, mailfrom, msg['headers'], msg) with h.push_config(c, user=mail_user): log.info('Received email from %s', c.user.username) # For each of the addrs, determine the project/app and route # appropriately for addr in rcpttos: try: userpart, project, app = mail_util.parse_address(addr) with h.push_config(c, project=project, app=app): if not app.has_access(c.user, userpart): log.info('Access denied for %s to mailbox %s', c.user, userpart) elif not c.app.config.options.get('AllowEmailPosting', True): log.info("Posting from email is not enabled") else: if msg['multipart']: msg_hdrs = msg['headers'] for part in msg['parts']: if part.get('content_type', '').startswith('multipart/'): continue msg = dict(headers=dict( msg_hdrs, **part['headers']), message_id=part['message_id'], in_reply_to=part['in_reply_to'], references=part['references'], filename=part['filename'], content_type=part['content_type'], payload=part['payload']) c.app.handle_message(userpart, msg) else: c.app.handle_message(userpart, msg) except exc.MailError as e: log.error('Error routing email to %s: %s', addr, e) except Exception: log.exception('Error routing mail to %s', addr)
def route_email( peer, mailfrom, rcpttos, data): ''' Route messages according to their destination: <topic>@<mount_point>.<subproj2>.<subproj1>.<project>.projects.domain.net gets sent to c.app.handle_message(topic, message) ''' try: msg = mail_util.parse_message(data) except: # pragma no cover log.exception('Parse Error: (%r,%r,%r)', peer, mailfrom, rcpttos) return if mail_util.is_autoreply(msg): log.info('Skipping autoreply message: %s', msg['headers']) return mail_user = mail_util.identify_sender(peer, mailfrom, msg['headers'], msg) with h.push_config(c, user=mail_user): log.info('Received email from %s', c.user.username) # For each of the addrs, determine the project/app and route # appropriately for addr in rcpttos: try: userpart, project, app = mail_util.parse_address(addr) with h.push_config(c, project=project, app=app): if not app.has_access(c.user, userpart): log.info('Access denied for %s to mailbox %s', c.user, userpart) elif not c.app.config.options.get('AllowEmailPosting', True): log.info("Posting from email is not enabled") else: if msg['multipart']: msg_hdrs = msg['headers'] for part in msg['parts']: if part.get('content_type', '').startswith('multipart/'): continue msg = dict( headers=dict(msg_hdrs, **part['headers']), message_id=part['message_id'], in_reply_to=part['in_reply_to'], references=part['references'], filename=part['filename'], content_type=part['content_type'], payload=part['payload']) c.app.handle_message(userpart, msg) else: c.app.handle_message(userpart, msg) except exc.MailError, e: log.error('Error routing email to %s: %s', addr, e) except:
def test_boxtrapper_cpanel(self): self.msg['headers']['Preference'] = 'auto_reply' self.msg['headers']['X-Precedence'] = 'auto_reply' self.msg['headers']['X-Autorespond'] = 'auto_reply' assert_true(is_autoreply(self.msg))
def test_domain_technologies_control(self): self.msg['headers']['X-AutoReply-From'] = 'something' self.msg['headers']['X-Mail-Autoreply'] = 'something' assert_true(is_autoreply(self.msg))
def test_communicate_pro(self): self.msg['headers']['X-Autogenerated'] = 'Forward' assert_true(is_autoreply(self.msg))
def test_mailtraq(self): self.msg['headers']['X-POST-MessageClass'] = '9; Autoresponder' assert_true(is_autoreply(self.msg))
def test_firstclass(self): self.msg['headers']['X-FC-MachineGenerated'] = 'true' assert_true(is_autoreply(self.msg))
def test_gmail(self): self.msg['headers']['Auto-Submitted'] = 'auto-replied' self.msg['headers']['Precedence'] = 'bulk' self.msg['headers']['X-Autoreply'] = 'yes' assert_true(is_autoreply(self.msg))
def test_qmail(self): self.msg['headers']['Delivered-To'] = 'Autoresponder' assert_true(is_autoreply(self.msg))
def test_return_path(self): self.msg['headers']['Return-Path'] = '<>' assert_true(is_autoreply(self.msg))
def test_empty(self): assert_false(is_autoreply(self.msg))