def get_category_unread(): category = request.args.get("category") mail = db.smembers("mail:%s:%s" % (current_user.user, category)) unread = 0 for emailID in mail: emailObj = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID) pMail = json.loads(emailObj[0]) if not pMail["read"]: unread += 1 response = {"unread": unread, "category": category} return jsonify(response)
def get_category_summary(): category = request.args.get("category") mail = db.smembers("mail:%s:%s" % (current_user.user, category)) summaries = {} for emailID in mail: emailObj = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID) pMail = json.loads(emailObj[0]) if not pMail["read"]: summaries[pMail["id"]] = {"summary": pMail["summary"], "from": pMail["from"], "subject": pMail["subject"]} response = {"category": category, "emails": summaries} return jsonify(response)
def delete_category(): category = json.loads(request.data)["category"] newCategory = 1 mail = db.smembers("mail:%s:%s" % (current_user.user, category)) print mail for emailID in mail: # Move email in Redis print db.smove( "mail:%s:%s" % (current_user.user, category), "mail:%s:%s" % (current_user.user, newCategory), emailID ) # Change category in object emailObj = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID) pMail = json.loads(emailObj[0]) pMail["category"] = newCategory emailJSON = json.dumps(pMail, sort_keys=True, indent=4, separators=(",", ": ")) print db.zremrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID) print db.zadd("mail:%s:inbox" % current_user.user, emailJSON, emailID) return "Success"
msg['subject'] = ('NoSubj' if (msg['Subject'] == None or msg['Subject'].encode('utf-8') == "".encode('utf-8')) else msg['Subject']) msg['to'] = ('NoTo' if (msg['To'] == None) else msg['To']) plain = {'plain_body': extract_body_text(msg).encode('utf-8'), 'subject': msg['subject']} # TODO set unread email = {'id': msgid, 'from': msg['From'], 'to': msg['To'], 'subject': msg['Subject'], 'date': msg['Date'], 'cc': msg['CC'], 'read': False, 'message': body, 'categorized': False, 'summary': shorten(plain), 'archived': False} trained = db.get("user:%s:trained" % user) if trained == "true": email['category'] = int(classify(msg, user)) else: email['category'] = 1 emailJSON = json.dumps(email, sort_keys=True, indent=4, separators=(',', ': ')) db.zadd("mail:%s:inbox" % user, emailJSON, msgid) db.sadd("mail:%s:%s" % (user, email['category']), msgid) server.logout() parser = Parser() argparser = argparse.ArgumentParser() argparser.add_argument("-u", "--username", help="The username for the desired account") args = argparser.parse_args() if args.username: get_email(args.username) else: users = db.smembers("user:users") for user in users: print user subprocess.Popen(["/home/jmvldz/sigma/python_env/bin/python", "grab-emails.py", "-u", user])