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
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')