summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-10-22 15:54:00 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-10-22 15:54:00 +0200
commit06f8a0d8e58b32ce4f0f105822415267b7c7ea7e (patch)
treec66a85f389d7d85c4f5ff1ca901e7f22255979d9
parent0707603bb7793da9826b54e401cd6917918aa944 (diff)
downloadkittystore-06f8a0d8e58b32ce4f0f105822415267b7c7ea7e.tar.gz
kittystore-06f8a0d8e58b32ce4f0f105822415267b7c7ea7e.tar.xz
kittystore-06f8a0d8e58b32ce4f0f105822415267b7c7ea7e.zip
Implement necessary methods for pipermail compatibility
-rw-r--r--kittystore/scrub.py8
-rw-r--r--kittystore/storm/store.py46
2 files changed, 41 insertions, 13 deletions
diff --git a/kittystore/scrub.py b/kittystore/scrub.py
index 5d6dd0f..b009c0b 100644
--- a/kittystore/scrub.py
+++ b/kittystore/scrub.py
@@ -47,10 +47,10 @@ def guess_extension(ctype, ext):
# and .wiz are all mapped to application/msword. This sucks for finding
# the best reverse mapping. If the extension is one of the giving
# mappings, we'll trust that, otherwise we'll just guess. :/
- all = guess_all_extensions(ctype, strict=False)
- if ext in all:
+ all_exts = guess_all_extensions(ctype, strict=False)
+ if ext in all_exts:
return ext
- return all and all[0]
+ return all_exts and all_exts[0]
def get_charset(message, default="ascii", guess=False):
@@ -148,7 +148,6 @@ class Scrubber(object):
part.set_payload('')
elif ctype == 'message/rfc822':
# This part contains a submessage, so it too needs scrubbing
- submsg = part.get_payload(0)
self.save_attachment(part, part_num)
part.set_payload('')
# If the message isn't a multipart, then we'll strip it out as an
@@ -164,7 +163,6 @@ class Scrubber(object):
# ignore the part.
if payload is None:
continue
- size = len(payload)
self.save_attachment(part, part_num)
outer = False
# We still have to sanitize multipart messages to flat text because
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py
index ba811aa..ff29c83 100644
--- a/kittystore/storm/store.py
+++ b/kittystore/storm/store.py
@@ -296,6 +296,30 @@ class StormStore(object):
"""
return list(self.db.find(List.name).order_by(List.name))
+ def get_messages(self, list_name, start, end, threads=False):
+ """ Return all emails between two given dates, optionnaly selecting
+ only the thread-starting ones.
+
+ :param list_name: The name of the mailing list in which these emails
+ should be searched.
+ :param start: A datetime object representing the starting date of
+ the interval to query.
+ :param end: A datetime object representing the ending date of
+ the interval to query.
+ :returns: The list of messages.
+ """
+ conditions = [
+ Email.list_name == unicode(list_name),
+ Email.date >= start,
+ Email.date < end,
+ ]
+ if threads:
+ # Beginning of thread == No 'References' header
+ conditions.append(Email.in_reply_to == None)
+ emails = self.db.find(Email, And(*conditions)
+ ).order_by(Desc(Email.date))
+ return list(emails)
+
def get_threads(self, list_name, start, end):
""" Return all the thread-starting emails between two given dates.
@@ -307,14 +331,7 @@ class StormStore(object):
the interval to query.
:returns: The list of thread-starting messages.
"""
- # Beginning of thread == No 'References' header
- emails = self.db.find(Email, And(
- Email.list_name == unicode(list_name),
- Email.in_reply_to == None,
- Email.date >= start,
- Email.date <= end,
- )).order_by(Desc(Email.date))
- return list(emails)
+ return self.get_messages(list_name, start, end, threads=True)
def get_start_date(self, list_name):
""" Get the date of the first archived email in a list.
@@ -417,6 +434,19 @@ class StormStore(object):
"""
return self.db.find(List, List.name == unicode(list_name)).one()
+ def get_message_by_number(self, list_name, num):
+ """ Return the n-th email for the specified list.
+
+ :param list_name: The name of the mailing list in which this email
+ should be searched.
+ :param num: The email number in order received.
+ :returns: The email message.
+ """
+ result = self.db.find(Email, Email.list_name == unicode(list_name)
+ ).order_by(Email.archived_date
+ )[num:num+1].one()
+ return result
+
# Attachments