]> khamidou — GitHub mirrors - kite.git/commitdiff
display names of peoples in the thread
authorkarim hamidou <khamidou@gmail.com>
Sun, 5 Jan 2014 19:05:28 +0000 (20:05 +0100)
committerkarim hamidou <khamidou@gmail.com>
Sun, 5 Jan 2014 19:05:28 +0000 (20:05 +0100)
src/back/kite/filterdaemon.py
src/back/kite/maildir.py
src/back/kite/server.py
src/front/app/partials/mailbox.html

index 9d72380ab1d592c0db5563e61bfdf967be4a3aa2..517577ef967348ac05999c4239ad06a3e3aee038 100755 (executable)
@@ -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):
index 31f291457e120702aee3cea16d4d242e0fcc80a6..202508ecc8371f0e1e2516de0be38e4ebcd23b61 100644 (file)
@@ -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
 
index 89003944b266d698620a140a2353188e5806029a..e5a733fb2b0fb1c4c7a6157efc07a6ee2e1c562a 100755 (executable)
@@ -9,7 +9,7 @@ from maildir import *
 
 @route('/kite/<user>/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/<user>/mail/<id>')
 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": [], 
index 0f28a9eccea21c8220bc844df8d536b78b9a179c..b0d5694e944d3e6d0d677073a9b8d0dc8262a886 100644 (file)
             </tr>
             <tr ng-repeat="thread in threads | orderBy:'-date':reverse ">
                     <td>
-                        <span ng-show="thread.name">
-                            {{thread.name}} ({{thread.from}})
+                        <span ng-show="thread.creator.name">
+                            {{thread.creator.name}}
+                            <span ng-show="thread.lastreplyfrom.name">
+                                , {{thread.lastreplyfrom.name}}
+                            </span>
+                            <span ng-hide="thread.lastreplyfrom.name">
+                                , {{thread.lastreplyfrom.address}}
+                            </span>
+
                         </span>
-                        <span ng-hide="thread.name">
-                            {{ thread.from }}
+                        <span ng-hide="thread.creator.name">
+                            {{ thread.creator.address }}
                         </span>
                     </td>
                     <td>