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
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)
# 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):
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]
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
@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:]:
@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
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": [],
</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>