Example #1
0
 def test_arg(self, EA):
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda: 'user')
     ]
     assert_equal(identify_sender(None, 'arg', None, None), 'user')
     EA.get.assert_called_once_with(email='arg', confirmed=True)
Example #2
0
 def test_no_header(self, EA, User):
     anon = User.anonymous()
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         None, mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda:'user')]
     assert_equal(identify_sender(None, 'arg', {}, None), anon)
     assert_equal(EA.get.call_args_list, [mock.call(email='arg', confirmed=True)])
Example #3
0
 def test_no_match(self, EA, User):
     anon = User.anonymous()
     EA.canonical = lambda e: e
     EA.get.side_effect = [None, None]
     assert_equal(
         identify_sender(None, 'arg', {'From': 'from'}, None), anon)
     assert_equal(EA.get.call_args_list,
                  [mock.call(email='arg', confirmed=True), mock.call(email='from')])
Example #4
0
 def test_header(self, EA):
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         None, mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda:'user')]
     assert_equal(
         identify_sender(None, 'arg', {'From': 'from'}, None), 'user')
     assert_equal(EA.get.call_args_list,
                  [mock.call(email='arg', confirmed=True), mock.call(email='from')])
Example #5
0
 def test_no_match(self, EA, User):
     anon = User.anonymous()
     EA.canonical = lambda e: e
     EA.get.side_effect = [None, None]
     assert_equal(identify_sender(None, 'arg', {'From': 'from'}, None),
                  anon)
     assert_equal(
         EA.get.call_args_list,
         [mock.call(email='arg', confirmed=True),
          mock.call(email='from')])
Example #6
0
 def test_no_header(self, EA, User):
     anon = User.anonymous()
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         None,
         mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda: 'user')
     ]
     assert_equal(identify_sender(None, 'arg', {}, None), anon)
     assert_equal(EA.get.call_args_list,
                  [mock.call(email='arg', confirmed=True)])
Example #7
0
 def test_header(self, EA):
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         None,
         mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda: 'user')
     ]
     assert_equal(identify_sender(None, 'arg', {'From': 'from'}, None),
                  'user')
     assert_equal(
         EA.get.call_args_list,
         [mock.call(email='arg', confirmed=True),
          mock.call(email='from')])
Example #8
0
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)
Example #9
0
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:
Example #10
0
 def test_arg(self, EA):
     EA.canonical = lambda e: e
     EA.get.side_effect = [
         mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda:'user')]
     assert_equal(identify_sender(None, 'arg', None, None), 'user')
     EA.get.assert_called_once_with(email='arg', confirmed=True)