summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-08-20 17:16:30 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-09-07 10:40:54 +0200
commit7be83854b9de658114247b5f6626c55a5f16a4ec (patch)
tree0a690c85b0b02befc0bb364fdf704980fdb11ac8
parent356001dcd72dd461ec3a490b7b3d309f20021e90 (diff)
downloadkittystore-7be83854b9de658114247b5f6626c55a5f16a4ec.tar.gz
kittystore-7be83854b9de658114247b5f6626c55a5f16a4ec.tar.xz
kittystore-7be83854b9de658114247b5f6626c55a5f16a4ec.zip
Implement get_message_by_hash_from_list
-rw-r--r--kittystore/__init__.py5
-rw-r--r--kittystore/sa/kittysamodel.py1
-rw-r--r--kittystore/sa/store.py32
3 files changed, 28 insertions, 10 deletions
diff --git a/kittystore/__init__.py b/kittystore/__init__.py
index 21bb8af..7b57ce0 100644
--- a/kittystore/__init__.py
+++ b/kittystore/__init__.py
@@ -15,7 +15,7 @@ See http://www.gnu.org/copyleft/gpl.html for the full text of the
license.
"""
-__all__ = ("get_store", )
+__all__ = ("get_store", "MessageNotFound", )
def get_store(url, debug=False):
@@ -25,3 +25,6 @@ def get_store(url, debug=False):
else:
from kittystore.sa import KittySAStore
return KittySAStore(url, debug)
+
+class MessageNotFound(Exception):
+ pass
diff --git a/kittystore/sa/kittysamodel.py b/kittystore/sa/kittysamodel.py
index 0d5b0f6..20dd4c5 100644
--- a/kittystore/sa/kittysamodel.py
+++ b/kittystore/sa/kittysamodel.py
@@ -43,6 +43,7 @@ def get_table(table, metadata, create=False):
# number" which was used to identify the email in pipermail, and
# eventually setup a proper redirection.
# - use the msg_hash_id and the list_id as a primary key
+ # - add a content-type (html or text) (and an encoding field maybe? or store everything as UTF-8?)
table = Table( table, metadata,
Column('id', Integer, primary_key=True),
Column('sender', String(100), nullable=False),
diff --git a/kittystore/sa/store.py b/kittystore/sa/store.py
index 59a9f91..098d2e5 100644
--- a/kittystore/sa/store.py
+++ b/kittystore/sa/store.py
@@ -17,6 +17,7 @@ license.
import datetime
+from kittystore import MessageNotFound
from kittystore.utils import get_message_id_hash, parseaddr, parsedate
from kittystore.utils import get_ref_and_thread_id
from kittystore.sa.kittysamodel import get_class_object
@@ -149,7 +150,7 @@ class KittySAStore(object):
references=ref,
full=message.as_string(),
)
- mail.save(self.session)
+ self.session.add(mail)
return msg_id_hash
def delete_message(self, message_id):
@@ -171,6 +172,12 @@ class KittySAStore(object):
store.
:raises LookupError: if there is no such message.
"""
+ email = get_class_object(list_to_table_name(list_name), 'email',
+ self.metadata, create=False)
+ msg = self.get_message_by_id_from_list(list_name, message_id)
+ if msg is None:
+ raise MessageNotFound(list_name, message_id)
+ self.session.delete(msg)
def get_list_size(self, list_name):
""" Return the number of emails stored for a given mailing list.
@@ -190,6 +197,8 @@ class KittySAStore(object):
search for.
:returns: The message, or None if no matching message was found.
"""
+ # Not sure this is useful: a message should always be in a list
+ raise NotImplementedError
def get_message_by_hash_from_list(self, list_name, message_id_hash):
"""Return the message with the matching X-Message-ID-Hash.
@@ -198,6 +207,13 @@ class KittySAStore(object):
search for.
:returns: The message, or None if no matching message was found.
"""
+ email = get_class_object(list_to_table_name(list_name), 'email',
+ self.metadata)
+ try:
+ return self.session.query(email).filter_by(
+ stable_url_id=message_id_hash).one()
+ except NoResultFound:
+ return None
def get_message_by_id(self, message_id):
"""Return the message with a matching Message-ID.
@@ -205,6 +221,8 @@ class KittySAStore(object):
:param message_id: The Message-ID header contents to search for.
:returns: The message, or None if no matching message was found.
"""
+ # Not sure this is useful: a message should always be in a list
+ raise NotImplementedError
def get_message_by_id_from_list(self, list_name, message_id):
"""Return the message with a matching Message-ID.
@@ -216,13 +234,11 @@ class KittySAStore(object):
"""
email = get_class_object(list_to_table_name(list_name), 'email',
self.metadata)
- mail = None
try:
- mail = self.session.query(email).filter_by(
+ return self.session.query(email).filter_by(
message_id=message_id).one()
except NoResultFound:
- pass
- return mail
+ return None
def search_list_for_content(self, list_name, keyword):
""" Returns a list of email containing the specified keyword in
@@ -358,13 +374,11 @@ class KittySAStore(object):
"""
email = get_class_object(list_to_table_name(list_name), 'email',
self.metadata)
- mail = None
try:
- mail = self.session.query(email).filter_by(
+ return self.session.query(email).filter_by(
thread_id=thread_id).order_by(email.date).all()
except NoResultFound:
- pass
- return mail
+ return None
def get_thread_length(self, list_name, thread_id):
""" Return the number of email present in a thread. This thread