Example #1
0
def config_quill():
    with Store(STORE) as s:
        s["quill_url"] = request.form.get("quill_url")
        s["quill_token"] = request.form.get("quill_token")
        s["reply"] = request.form.get("reply")

    return redirect(url_for("quill_panel"))
Example #2
0
def is_whitelisted(body):
    # Read configuration and short circuit.
    with Store(STORE) as s:
        if not s["enabled"]:
            return True

        whitelist = s["whitelist"]

    return is_whitelisted_internal(body, whitelist=whitelist)
Example #3
0
def set_template():
    key = request.form.get("key", None)
    if key is None or key.strip() == "":
        return redirect(url_for("templates_panel"))

    with Store(STORE) as s:
        s["templates"][key] = request.form.get("value")

    return redirect(url_for("templates_panel"))
Example #4
0
    def triggered_callback(body, argv, reply_object):
        if len(argv) >= 2:
            command = argv[1]

            with Store(STORE) as s:
                if command in s["templates"] and s["enabled"]:
                    reply = s["templates"][command]
                    reply_email(reply_object, reply)

                    return
Example #5
0
    def raw_callback(parsed, raw, reply_object):
        print "[SR] Smartreply Callback!"
        with Store(STORE) as s:
            if not s['enabled']:
                return

            body = "null"
            for part in parsed.parts:
                if str(part) == "(text/plain)":
                    body = part.body.encode('ascii', 'ignore')

            print "[SR] Parsed body to:", body

            if body == "null":
                return

            body = EmailReplyParser.parse_reply(body)

            email_message = email.message_from_string(raw)

            print "[SR] To", email_message['To']

            sent_to = None

            for e in s['email']:
                if e in email_message['To']:
                    sent_to = e

            if sent_to is None:
                return

            p = model.predict_proba([body])[0]

            confidence = np.max(p)
            class_ = model.classes_[np.argmax(p)]

            templates = load_config('templates')['templates']

            print "[SR] Confidence %.2f, Class: %s" % (confidence, class_)

            if confidence > float(s['threshold']) and class_ in templates:
                if s['mock']:
                    reply = "<b>(Team Only, Confidence: %.2f)</b><br><br>" % confidence
                    reply += templates[class_]
                    reply_email(reply_object, reply, reply_one=sent_to)
                else:
                    reply = templates[class_]
                    reply_email(reply_object, reply)

                return
Example #6
0
    def triggered_callback(body, argv, reply_object):
        if len(argv) >= 3:
            command = argv[1]
            email = argv[2]

            with Store(STORE) as s:
                if command == "whitelist" and s["enabled"]:
                    at = s["quill_token"]
                    ep = s["quill_url"]

                    already_whitelisted = get_wl(at, ep)
                    if email not in already_whitelisted:
                        post_wl(already_whitelisted + [email], at, ep)

                    reply = s["reply"].format(email=email)

                    # Modify reply object to include whitelisted email.
                    reply_object["all_recipients"].append(("", email))
                    reply_email(reply_object, reply)

                    return
Example #7
0
def config_sr():
    with Store(STORE) as s:
        s['threshold'] = request.form.get('threshold')
        s['email'] = request.form.get('email').split(',')

    return redirect(url_for('smart_reply_panel'))
Example #8
0
def stats_panel():
    with Store(STORE) as s:
        times = s["num_emails"]
        hours = int(round((times * 5) / 60.0))

    return render_template("stats.html", menu=get_menu(), times=times, hours=hours)
Example #9
0
def mod_stats_number(n):
    with Store(STORE) as s:
        s["num_emails"] = n

    return "OK, new number is: " + str(n)
Example #10
0
def disable_sr_mock():
    with Store(STORE) as s:
        s['mock'] = False
    return "OK"
Example #11
0
 def triggered_callback(body, argv, reply_object):
     # Let's simply increment our counter.
     with Store(STORE) as s:
         s["num_emails"] += 1
Example #12
0
def enable_quill():
    with Store(STORE) as s:
        s["enabled"] = True
    return "OK"
Example #13
0
def enable_sr_mock():
    with Store(STORE) as s:
        s['mock'] = True
    return "OK"
Example #14
0
def disable_quill():
    with Store(STORE) as s:
        s["enabled"] = False
    return "OK"
Example #15
0
def enable_templates():
    with Store(STORE) as s:
        s["enabled"] = True
    return "OK"
Example #16
0
def enable_whitelist():
    with Store(STORE) as s:
        s["enabled"] = True
    return "OK"
Example #17
0
def config_whitelist():
    with Store(STORE) as s:
        s["whitelist"] = request.form.get("whitelist").split()

    return redirect(url_for("whitelist_panel"))
Example #18
0
def disable_whitelist():
    with Store(STORE) as s:
        s["enabled"] = False
    return "OK"
Example #19
0
def disable_templates():
    with Store(STORE) as s:
        s["enabled"] = False
    return "OK"
Example #20
0
def enable_sr():
    with Store(STORE) as s:
        s['enabled'] = True
    return "OK"
Example #21
0
def delete_template(key):
    with Store(STORE) as s:
        del s.store["templates"][key]

    return redirect(url_for("templates_panel"))
Example #22
0
def disable_sr():
    with Store(STORE) as s:
        s['enabled'] = False
    return "OK"