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"))
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)
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"))
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
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
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
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'))
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)
def mod_stats_number(n): with Store(STORE) as s: s["num_emails"] = n return "OK, new number is: " + str(n)
def disable_sr_mock(): with Store(STORE) as s: s['mock'] = False return "OK"
def triggered_callback(body, argv, reply_object): # Let's simply increment our counter. with Store(STORE) as s: s["num_emails"] += 1
def enable_quill(): with Store(STORE) as s: s["enabled"] = True return "OK"
def enable_sr_mock(): with Store(STORE) as s: s['mock'] = True return "OK"
def disable_quill(): with Store(STORE) as s: s["enabled"] = False return "OK"
def enable_templates(): with Store(STORE) as s: s["enabled"] = True return "OK"
def enable_whitelist(): with Store(STORE) as s: s["enabled"] = True return "OK"
def config_whitelist(): with Store(STORE) as s: s["whitelist"] = request.form.get("whitelist").split() return redirect(url_for("whitelist_panel"))
def disable_whitelist(): with Store(STORE) as s: s["enabled"] = False return "OK"
def disable_templates(): with Store(STORE) as s: s["enabled"] = False return "OK"
def enable_sr(): with Store(STORE) as s: s['enabled'] = True return "OK"
def delete_template(key): with Store(STORE) as s: del s.store["templates"][key] return redirect(url_for("templates_panel"))
def disable_sr(): with Store(STORE) as s: s['enabled'] = False return "OK"