# Path: stackalytics/processor/mls.py
# LOG = logging.getLogger(__name__)
# EMAIL_HEADER_PATTERN = ('From \S+(?: at \S+)?\s+'
#                         '\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}(?::\d{2})?'
#                         '(?:\s+\S+)?\s+\d{4}.*?\n')
# MAIL_BOX_PATTERN = re.compile(
#     '^' + EMAIL_HEADER_PATTERN +
#     'From: (?P<author_email>\S+(?: at \S+))'
#     '(?:\W+(?P<author_name>\w+(?:\s\w+)*))?.*?\n'
#     'Date: (?P<date>.*?)\n'
#     'Subject: (?P<subject>.*?)(?=\n\S+:)'
#     '.*?Message-ID: (?P<message_id>\S+)\n'
#     '\n(?P<body>.*?)\n'
#     '(?=' + EMAIL_HEADER_PATTERN + 'From: )',
#     flags=re.MULTILINE | re.DOTALL)
# MESSAGE_PATTERNS = {
#     'bug_id': re.compile(r'https://bugs.launchpad.net/bugs/(?P<id>\d+)',
#                          re.IGNORECASE),
#     'blueprint_id': re.compile(r'https://blueprints.launchpad.net/'
#                                r'(?P<module>[^\/]+)/\+spec/(?P<id>[a-z0-9-]+)',
#                                re.IGNORECASE),
# }
# TRAILING_RECORD = ('From ishakhat at mirantis.com  Tue Sep 17 07:30:43 2013\n'
#                    'From: ')
# def _get_mail_archive_links(uri):
# def _uri_content_changed(uri, runtime_storage_inst):
# def _optimize_body(email_body):
# def _retrieve_mails(uri):
# def log(uri, runtime_storage_inst):


import re
import mock
import testtools
from stackalytics.processor import mls
Good morning Gary!

test works :)

From sorlando at nicira.com  Tue Jul 17 07:30:43 2012
From: sorlando at nicira.com (Salvatore Orlando)
            '''
        match = re.search(mls.MAIL_BOX_PATTERN, content)
        self.assertTrue(match)
        self.assertEqual('sorlando at nicira.com', match.group(1))
        self.assertEqual('Salvatore Orlando', match.group(2))
        self.assertEqual('Tue, 17 Jul 2012 00:30:43 -0700', match.group(3))
        self.assertEqual('[openstack-dev] [nova] [pci device passthrough] '
                         'fails with\n "NameError: global name \'_\' is not '
                         'defined"', match.group(4))
        self.assertEqual('<CAGR=i3htLvDOdh5u6mxqmo0zVP1eKKYAxAhj='
                         'e1-rpQWZOiF6Q@gmail.com>', match.group(5))
        self.assertEqual('Good morning Gary!\n\ntest works :)\n',
                         match.group(6))

    @mock.patch('stackalytics.processor.utils.read_gzip_from_uri')
    @mock.patch('stackalytics.processor.mls._get_mail_archive_links')
    @mock.patch('stackalytics.processor.mls._uri_content_changed')
    def test_log(self, mock_uri_content_changed, mock_get_mail_archive_links,
                 mock_read_gzip_from_uri):
        mock_uri_content_changed.return_value = True
        mock_get_mail_archive_links.return_value = ['link']
        mock_read_gzip_from_uri.return_value = EMAIL_CONTENT
        mock_rsi = mock.Mock()


# Path: stackalytics/processor/mls.py
# LOG = logging.getLogger(__name__)
# EMAIL_HEADER_PATTERN = ('From \S+(?: at \S+)?\s+'
#                         '\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}(?::\d{2})?'
#                         '(?:\s+\S+)?\s+\d{4}.*?\n')
# MAIL_BOX_PATTERN = re.compile(
#     '^' + EMAIL_HEADER_PATTERN +
#     'From: (?P<author_email>\S+(?: at \S+))'
#     '(?:\W+(?P<author_name>\w+(?:\s\w+)*))?.*?\n'
#     'Date: (?P<date>.*?)\n'
#     'Subject: (?P<subject>.*?)(?=\n\S+:)'
#     '.*?Message-ID: (?P<message_id>\S+)\n'
#     '\n(?P<body>.*?)\n'
#     '(?=' + EMAIL_HEADER_PATTERN + 'From: )',
#     flags=re.MULTILINE | re.DOTALL)
# MESSAGE_PATTERNS = {
#     'bug_id': re.compile(r'https://bugs.launchpad.net/bugs/(?P<id>\d+)',
#                          re.IGNORECASE),
#     'blueprint_id': re.compile(r'https://blueprints.launchpad.net/'
#                                r'(?P<module>[^\/]+)/\+spec/(?P<id>[a-z0-9-]+)',
#                                re.IGNORECASE),
# }
# TRAILING_RECORD = ('From ishakhat at mirantis.com  Tue Sep 17 07:30:43 2013\n'
#                    'From: ')
# def _get_mail_archive_links(uri):
# def _uri_content_changed(uri, runtime_storage_inst):
# def _optimize_body(email_body):
# def _retrieve_mails(uri):
# def log(uri, runtime_storage_inst):


# Path: stackalytics/tests/unit/test_mls.py
import re
import mock
import testtools
from stackalytics.processor import mls

Good morning Gary!

test works :)

From sorlando at nicira.com  Tue Jul 17 07:30:43 2012
From: sorlando at nicira.com (Salvatore Orlando)
            '''
        match = re.search(mls.MAIL_BOX_PATTERN, content)
        self.assertTrue(match)
        self.assertEqual('sorlando at nicira.com', match.group(1))
        self.assertEqual('Salvatore Orlando', match.group(2))
        self.assertEqual('Tue, 17 Jul 2012 00:30:43 -0700', match.group(3))
        self.assertEqual('[openstack-dev] [nova] [pci device passthrough] '
                         'fails with\n "NameError: global name \'_\' is not '
                         'defined"', match.group(4))
        self.assertEqual('<CAGR=i3htLvDOdh5u6mxqmo0zVP1eKKYAxAhj='
                         'e1-rpQWZOiF6Q@gmail.com>', match.group(5))
        self.assertEqual('Good morning Gary!\n\ntest works :)\n',
                         match.group(6))

    @mock.patch('stackalytics.processor.utils.read_gzip_from_uri')
    @mock.patch('stackalytics.processor.mls._get_mail_archive_links')
    @mock.patch('stackalytics.processor.mls._uri_content_changed')
    def test_log(self, mock_uri_content_changed, mock_get_mail_archive_links,
                 mock_read_gzip_from_uri):
        mock_uri_content_changed.return_value = True
        mock_get_mail_archive_links.return_value = ['link']
        mock_read_gzip_from_uri.return_value = EMAIL_CONTENT
        mock_rsi = mock.Mock()


        emails = list(mls.log('uri', mock_rsi))