54
def _parse_message(message):
55
"""Get a date and dict of an RFC822 message."""
56
parsed = email.parser.Parser().parsestr(message)
59
for key in ('from', 'to', 'subject', 'message-id'):
60
value = parsed.get(key, None)
62
message_dict[key] = value
64
date = parsed.get('date')
67
pdate = parsedate_tz(date)
68
date = datetime.datetime(
70
tzinfo=dateutil.tz.tzoffset('', pdate[9]))
73
message_dict['date'] = date.isoformat() if date is not None else None
75
return date, message_dict
54
78
class CassandraConnection(object):
56
80
def __init__(self, keyspace, host):
66
90
def _column_family(self, name):
67
91
return pycassa.ColumnFamily(self._connection, name)
69
def _parse_message(self, message):
70
"""Get a date and dict of an RFC822 message."""
71
parsed = email.parser.Parser().parsestr(message)
74
for key in ('from', 'to', 'subject', 'message-id'):
75
value = parsed.get(key, None)
77
message_dict[key] = value
79
date = parsed.get('date')
82
pdate = parsedate_tz(date)
83
date = datetime.datetime(
85
tzinfo=dateutil.tz.tzoffset('', pdate[9]))
88
message_dict['date'] = date.isoformat() if date is not None else None
90
return date, message_dict
92
93
def add_message(self, archive_uuid, message):
93
94
message_uuid = uuid.uuid4()
94
message_date, message_dict = self._parse_message(message)
95
message_date, message_dict = _parse_message(message)
95
96
message_dict['content'] = message
96
97
message_dict['date_created'] = (
97
98
datetime.datetime.utcnow().isoformat() + 'Z')