From: karim hamidou Date: Sun, 5 Jan 2014 19:05:28 +0000 (+0100) Subject: display names of peoples in the thread X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4d8c6d5fe9cb7fca4d1581b2782fffa252bbe1ad;p=kite.git display names of peoples in the thread --- diff --git a/src/back/kite/filterdaemon.py b/src/back/kite/filterdaemon.py index 9d72380..517577e 100755 --- a/src/back/kite/filterdaemon.py +++ b/src/back/kite/filterdaemon.py @@ -20,6 +20,7 @@ import threads import headers import users from jsonfile import JsonFile +import maildir # The architecture is pretty simple. This program is multithreaded. # One thread is the producer. It uses inotify to detect changes to the @@ -78,7 +79,12 @@ def process_new_email(path, threads_index): with open(path, "r") as fd: parser = email.parser.HeaderParser() email_headers = parser.parse(fd) - subject = email_headers.get("Subject") + + subject = email_headers["subject"] + from_field = {} + from_field["name"], from_field["address"] = email.utils.parseaddr(email_headers["From"]) + to_field = {} + to_field["addresses"] = email.utils.getaddresses(email_headers["to"]) if subject != None: subject = headers.cleanup_subject(subject) @@ -92,10 +98,16 @@ def process_new_email(path, threads_index): # create a new thread thread = threads.create_thread_structure() thread["subject"] = subject + thread["creator"] = from_field msg_id = os.path.basename(path) thread["messages"].append(msg_id) thread["date"] = datetime.datetime.utcnow() + thread["unread"] = True + + if from_field["address"] != thread["creator"]["address"]: + thread["lastreplyfrom"] = from_field + threads_index.insert(0, thread) class ProcessorThread(threading.Thread): diff --git a/src/back/kite/maildir.py b/src/back/kite/maildir.py index 31f2914..202508e 100644 --- a/src/back/kite/maildir.py +++ b/src/back/kite/maildir.py @@ -6,8 +6,9 @@ def read_mail(path): mdir = mailbox.Maildir(path) return mdir -def extract_email(msg): - """Extract all the interesting fields from an email""" +def extract_email_headers(msg): + """Extract headers from email""" + msg_obj = {} msg_obj["from"] = {} from_field = msg.getheaders('From')[0] @@ -17,6 +18,12 @@ def extract_email(msg): msg_obj["subject"] = msg.getheaders('Subject')[0] msg_obj["date"] = msg.getheaders('Date')[0] + + return msg_obj + +def extract_email(msg): + """Extract all the interesting fields from an email""" + msg_obj = extract_email_headers(msg) msg_obj["contents"] = msg.fp.read() return msg_obj diff --git a/src/back/kite/server.py b/src/back/kite/server.py index 8900394..e5a733f 100755 --- a/src/back/kite/server.py +++ b/src/back/kite/server.py @@ -9,7 +9,7 @@ from maildir import * @route('/kite//mail') def index(user): - # FIXME: input sanitization + # FIXME: input sanitization - check permissions for user threads_index = JsonFile("/home/kite/Maildirs/%s/threads_index.json" % user) ret_threads = [] for thread in threads_index.data[-50:]: @@ -20,7 +20,7 @@ def index(user): @route('/kite//mail/') def index(user, id): - # FIXME: input sanitization + # FIXME: input sanitization check perms threads_index = JsonFile("/home/kite/Maildirs/%s/threads_index.json" % user) thread = None @@ -31,6 +31,9 @@ def index(user, id): if thread == None: abort(404, "Thread not found.") + thr["unread"] = False + threads_index.save() # FIXME: race condition here + response.content_type = "application/json" ret_json = {"messages": [], diff --git a/src/front/app/partials/mailbox.html b/src/front/app/partials/mailbox.html index 0f28a9e..b0d5694 100644 --- a/src/front/app/partials/mailbox.html +++ b/src/front/app/partials/mailbox.html @@ -15,11 +15,18 @@ - - {{thread.name}} ({{thread.from}}) + + {{thread.creator.name}} + + , {{thread.lastreplyfrom.name}} + + + , {{thread.lastreplyfrom.address}} + + - - {{ thread.from }} + + {{ thread.creator.address }}