diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-10-11 10:45:36 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-10-11 10:45:36 +0200 |
commit | 3dd710772edbb6a0cc80d629fb22677e9c43f937 (patch) | |
tree | bfa663d42dea9fc060b6b41376fc00d5d374c2d2 | |
parent | b366e589fd25a40a58f1e041370d6530b04d35fe (diff) | |
download | kittystore-3dd710772edbb6a0cc80d629fb22677e9c43f937.tar.gz kittystore-3dd710772edbb6a0cc80d629fb22677e9c43f937.tar.xz kittystore-3dd710772edbb6a0cc80d629fb22677e9c43f937.zip |
Fix archives import (interface changed)
-rw-r--r-- | kittystore/storm/store.py | 4 | ||||
-rw-r--r-- | to_sqldb.py | 18 |
2 files changed, 18 insertions, 4 deletions
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py index 5d9017c..ba811aa 100644 --- a/kittystore/storm/store.py +++ b/kittystore/storm/store.py @@ -68,8 +68,8 @@ class StormStore(object): def add_to_list(self, mlist, message): """Add the message to a specific list of the store. - :param list_name: The fully qualified list name to which the - message should be added. + :param mlist: The mailing-list object, implementing + mailman.interfaces.mailinglist.IMailingList. :param message: An email.message.Message instance containing at least a unique Message-ID header. The message will be given an X-Message-ID-Hash header, overriding any existing such diff --git a/to_sqldb.py b/to_sqldb.py index 63491cd..0527b3c 100644 --- a/to_sqldb.py +++ b/to_sqldb.py @@ -23,6 +23,14 @@ TOTALCNT = 0 KITTYSTORE_URL = 'sqlite:///' + os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "kittystore.sqlite")) +PREFIX_RE = re.compile("^\[([\w\s_-]+)\] ") + +class DummyMailingList(object): + def __init__(self, address): + self.fqdn_listname = address + self.display_name = None + + def convert_date(date_string): """ Convert the string of the date to a datetime object. """ #print date_string @@ -42,12 +50,18 @@ def to_db(mbfile, list_name, store): global TOTALCNT cnt = 0 cnt_read = 0 + mlist = DummyMailingList(list_name) for message in mailbox.mbox(mbfile): cnt_read = cnt_read + 1 #print cnt_read TOTALCNT = TOTALCNT + 1 + # Try to find the mailing-list subject prefix in the first email + if cnt_read == 1: + subject_prefix = PREFIX_RE.search(message["subject"]) + if subject_prefix: + mlist.display_name = subject_prefix.group(1) try: - msg_id_hash = store.add_to_list(list_name, message) + msg_id_hash = store.add_to_list(mlist, message) except ValueError, e: if len(e.args) != 2: raise # Regular ValueError exception @@ -58,7 +72,7 @@ def to_db(mbfile, list_name, store): print message["From"], message["Subject"], e # Database is locked time.sleep(1) - msg_id_hash = store.add_to_list(list_name, message) + msg_id_hash = store.add_to_list(mlist, message) store.flush() cnt = cnt + 1 store.commit() |