def index(user, id): try: threads_index = DatetimeCabinet("/home/kite/threads.db") thread = None except IOError: response.status = 400 return # FIXME: use an index for threads entries ? for thr in threads_index[user]["threads_index"]: if thr["id"] == id: thread = thr if thread == None: abort(404, "Thread not found.") thread["unread"] = False threads_index.sync() response.content_type = "application/json" ret_json = { "messages": [], "subject": thread["subject"], "date": thread["date"], "id": thread["id"] } mdir = read_mail("/home/kite/Maildirs/%s" % user) for mail_id in thread["messages"]: ret_json["messages"].append(get_email(mdir, mail_id)) return serialize_json(ret_json, protection=False)
def index(user, id): try: threads_index = DatetimeCabinet("/home/kite/threads.db") thread = None except IOError: response.status = 400 return # FIXME: use an index for threads entries ? for thr in threads_index[user]["threads_index"]: if thr["id"] == id: thread = thr if thread == None: abort(404, "Thread not found.") thread["unread"] = False threads_index.sync() response.content_type = "application/json" ret_json = {"messages": [], "subject": thread["subject"], "date": thread["date"], "id": thread["id"] } mdir = read_mail("/home/kite/Maildirs/%s" % user) for mail_id in thread["messages"]: ret_json["messages"].append(get_email(mdir, mail_id)) return serialize_json(ret_json, protection=False)
def auth_user(username, password): usersdb = DatetimeCabinet("/home/kite/users.db") if username not in usersdb: return False user = usersdb[username] print user["password"] if user["password"] != password: return False return True
def index(user): try: threads_index = DatetimeCabinet("/home/kite/threads.db") except IOError: abort(500, "Invalid thread") return ret_threads = [] try: threads = threads_index[user]["threads_index"] except KeyError: threads = [] for thread in threads: ret_threads.append(thread) response.content_type = "application/json" return serialize_json(ret_threads, protection=False)
def add_kite_user(username, password): usersdb = DatetimeCabinet("/home/kite/users.db") usersdb[username] = {"password": password} # FIXME: hash password usersdb.sync()
"dirty": True, "unread_count": 0 } process_new_email( event["path"], self.threads_index[username]["threads_index"]) self.threads_index[username]["dirty"] = True self.threads_index[username]["unread_count"] += 1 except IOError as e: # This may be a Postfix/Dovecot temporary file. Ignore it. print "caught ioerror %s" % e.strerror pass time.sleep(EVENTS_QUEUE_PROCESSING_DELAY) if __name__ == "__main__": path = sys.argv[1] print "Watching %s..." % path threads_index = DatetimeCabinet("/home/kite/threads.db") watcher_thread = WatcherThread(path) processor_thread = ProcessorThread(path, threads_index) dumper_thread = DumperThread(path, threads_index) processor_thread.start() watcher_thread.start() dumper_thread.start()