Exemplo n.º 1
0
def get_email():
    emailID = request.args.get("id")
    emailObj = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, emailID, emailID)
    if emailObj is None:
        return "Email %s not found." % emailID
    pMail = json.loads(emailObj[0])
    return pMail["message"]
Exemplo n.º 2
0
def mark_email_unread():
    email = json.loads(request.data)
    mail = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    pMail = json.loads(mail[0])
    pMail["read"] = False
    emailJSON = json.dumps(pMail, sort_keys=True, indent=4, separators=(",", ": "))
    db.zremrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    db.zadd("mail:%s:inbox" % current_user.user, emailJSON, email["id"])
    return "Success"
Exemplo n.º 3
0
def get_emails():
    mail = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, "+inf", "-inf")
    parsedMail = {}
    if len(mail) > 0:
        session["recent_id"] = json.loads(mail[0])["id"]
    for email in mail:
        pMail = json.loads(email)
        parsedMail[pMail["id"]] = pMail
    return jsonify(parsedMail)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def categorize_email():
    email = json.loads(request.data)
    mail = db.zrevrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    pMail = json.loads(mail[0])
    oldCategory = pMail["category"]
    pMail["category"] = email["category"]
    pMail["categorized"] = True
    emailJSON = json.dumps(pMail, sort_keys=True, indent=4, separators=(",", ": "))
    db.zremrangebyscore("mail:%s:inbox" % current_user.user, email["id"], email["id"])
    db.zadd("mail:%s:inbox" % current_user.user, emailJSON, email["id"])
    db.smove(
        "mail:%s:%s" % (current_user.user, oldCategory),
        "mail:%s:%s" % (current_user.user, pMail["category"]),
        email["id"],
    )
    return "Success"
Exemplo n.º 7
0
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"