]> khamidou — GitHub mirrors - kite.git/commitdiff
read individual emails
authorkarim hamidou <khamidou@gmail.com>
Fri, 25 Oct 2013 19:22:49 +0000 (21:22 +0200)
committerkarim hamidou <khamidou@gmail.com>
Fri, 25 Oct 2013 19:22:49 +0000 (21:22 +0200)
src/back/kite/maildir.py
src/back/kite/server.py

index 46402c1e9e764e9aed9737933891268dc6ffabfe..3b11cc868c05a88d63b3154e2f9bc4ff1d9b9c3d 100644 (file)
@@ -6,12 +6,15 @@ def read_mail(path):
 
 def get_mails(mdir):
     l = []
+    count = 0
     for id, msg in mdir.iteritems():
         msg_obj = {}
         msg_obj["from"] = msg.getheaders('From')[0]
         msg_obj["to"] = msg.getheaders('To')[0]
         msg_obj["subject"] = msg.getheaders('Subject')[0]
-        msg_obj["contents"] = msg.getheaders('Subject')[0]
+        msg_obj["contents"] = msg.fp.read()
+        msg_obj["id"] = count
+        count += 1
         l.append(msg_obj)
     return l
 
index 916f945544ad85b258f145eb04e54a4e2304f518..01eda2414f3054b19ade3408cf60df1b28c487aa 100644 (file)
@@ -9,4 +9,11 @@ def index(user):
             mdir = read_mail("/home/kite/Maildir")
             return json.dumps(get_mails(mdir))
 
+@route('/kite/<user>/mail/<id>')
+def index(user, id):
+            response.content_type = "application/json"
+            mdir = read_mail("/home/kite/Maildir")
+            id = int(id)
+            return json.dumps(get_mails(mdir)[id])
+
 bottle.run(host='localhost', port='8080')