コード例 #1
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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"]
コード例 #2
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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"
コード例 #3
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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)
コード例 #4
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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)
コード例 #5
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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)
コード例 #6
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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"
コード例 #7
0
ファイル: sigma.py プロジェクト: dylanrhodes/sigma
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"