def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = webnotes.conn.get_value("Job Applicant", {"email_id": mail.from_email}, "name") if name: applicant = webnotes.bean("Job Applicant", name) if applicant.doc.status!="Rejected": applicant.doc.status = "Open" applicant.doc.save() else: name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = webnotes.bean({ "creation": mail.date, "doctype":"Job Applicant", "applicant_name": name, "email_id": mail.from_email, "status": "Open" }) applicant.insert() mail.save_attachments_in_doc(applicant.doc) make(content=mail.content, sender=mail.from_email, subject=mail.subject or "No Subject", doctype="Job Applicant", name=applicant.doc.name, sent_or_received="Received")
def add_support_communication(subject, content, sender, docname=None, mail=None): if docname: ticket = webnotes.bean("Support Ticket", docname) ticket.doc.status = 'Open' ticket.ignore_permissions = True ticket.doc.save() else: ticket = webnotes.bean([decode_dict({ "doctype":"Support Ticket", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open", })]) ticket.ignore_permissions = True ticket.insert() make(content=content, sender=sender, subject = subject, doctype="Support Ticket", name=ticket.doc.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket.doc) return ticket
def process_message(self, mail): if mail.from_email == self.email_settings.fields.get('support_email'): return thread_id = mail.get_thread_id() ticket = None new_ticket = False if thread_id and webnotes.conn.exists("Support Ticket", thread_id): ticket = webnotes.bean("Support Ticket", thread_id) ticket.doc.status = 'Open' ticket.doc.save() else: ticket = webnotes.bean([{ "doctype":"Support Ticket", "description": mail.content, "subject": mail.mail["Subject"], "raised_by": mail.from_email, "content_type": mail.content_type, "status": "Open" }]) ticket.insert() new_ticket = True mail.save_attachments_in_doc(ticket.doc) make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject, doctype="Support Ticket", name=ticket.doc.name, lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date) if new_ticket and cint(self.email_settings.send_autoreply) and \ "mailer-daemon" not in mail.from_email.lower(): self.send_auto_reply(ticket.doc)
def process_message(self, mail): if mail.from_email == self.email_settings.fields.get('support_email'): return thread_id = mail.get_thread_id() ticket = None if thread_id and webnotes.conn.exists("Support Ticket", thread_id): ticket = webnotes.model_wrapper("Support Ticket", thread_id) ticket.doc.status = 'Open' ticket.doc.save() else: ticket = webnotes.model_wrapper([{ "doctype": "Support Ticket", "description": mail.content, "subject": mail.mail["Subject"], "raised_by": mail.from_email, "content_type": mail.content_type, "status": "Open" }]) ticket.insert() if cint(self.email_settings.send_autoreply): if "mailer-daemon" not in mail.from_email.lower(): self.send_auto_reply(ticket.doc) mail.save_attachments_in_doc(ticket.doc) make(content=mail.content, sender=mail.from_email, doctype="Support Ticket", name=ticket.doc.name, lead=ticket.doc.lead, contact=ticket.doc.contact)
def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = webnotes.conn.get_value("Lead", {"email_id": mail.from_email}, "name") if name: lead = webnotes.model_wrapper("Lead", name) lead.doc.status = "Open" lead.doc.save() else: lead = webnotes.model_wrapper({ "doctype": "Lead", "lead_name": mail.from_real_name or mail.from_email, "email_id": mail.from_email, "status": "Open", "source": "Email" }) lead.insert() mail.save_attachments_in_doc(lead.doc) make(content=mail.content, sender=mail.from_email, doctype="Lead", name=lead.doc.name, lead=lead.doc.name)
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): def set_status(doctype, name): w = webnotes.bean(doctype, name) w.ignore_permissions = True w.doc.status = is_system_user and "Replied" or status w.doc.save() if mail: mail.save_attachments_in_doc(w.doc) lead_name = webnotes.conn.get_value("Lead", {"email_id": sender}) contact_name = webnotes.conn.get_value("Contact", {"email_id": sender}) is_system_user = webnotes.conn.get_value("Profile", sender) if not (lead_name or contact_name): # none, create a new Lead lead = webnotes.bean({ "doctype":"Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.insert() lead_name = lead.doc.name make(content=content, sender=sender, subject=subject, lead=lead_name, contact=contact_name, date=date) if contact_name: set_status("Contact", contact_name) elif lead_name: set_status("Lead", lead_name)
def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = webnotes.conn.get_value("Job Applicant", {"email_id": mail.from_email}, "name") if name: applicant = webnotes.model_wrapper("Job Applicant", name) if applicant.doc.status!="Rejected": applicant.doc.status = "Open" applicant.doc.save() else: name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = webnotes.model_wrapper({ "doctype":"Job Applicant", "applicant_name": name, "email_id": mail.from_email, "status": "Open" }) applicant.insert() mail.save_attachments_in_doc(applicant.doc) make(content=mail.content, sender=mail.from_email, doctype="Job Applicant", name=applicant.doc.name, set_lead=False)
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): def set_status(doctype, name): w = webnotes.bean(doctype, name) w.ignore_permissions = True w.doc.status = is_system_user and "Replied" or status w.doc.save() if mail: mail.save_attachments_in_doc(w.doc) lead_name = webnotes.conn.get_value("Lead", {"email_id": sender}) contact_name = webnotes.conn.get_value("Contact", {"email_id": sender}) is_system_user = webnotes.conn.get_value("Profile", sender) if not (lead_name or contact_name): # none, create a new Lead lead = webnotes.bean({ "doctype":"Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.insert() lead_name = lead.doc.name make(content=content, sender=sender, subject=subject, lead=lead_name, contact=contact_name, date=date) if contact_name: set_status("Contact", contact_name) elif lead_name: set_status("Lead", lead_name)
def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = webnotes.conn.get_value("Job Applicant", {"email_id": mail.from_email}, "name") if name: applicant = webnotes.bean("Job Applicant", name) if applicant.doc.status != "Rejected": applicant.doc.status = "Open" applicant.doc.save() else: name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = webnotes.bean({ "creation": mail.date, "doctype": "Job Applicant", "applicant_name": name, "email_id": mail.from_email, "status": "Open" }) applicant.insert() mail.save_attachments_in_doc(applicant.doc) make(content=mail.content, sender=mail.from_email, subject=mail.subject or "No Subject", doctype="Job Applicant", name=applicant.doc.name, sent_or_received="Received")
def add_reply(ticket, message): if not message: raise webnotes.throw(_("Please write something")) bean = webnotes.bean("Support Ticket", ticket) if bean.doc.raised_by != webnotes.session.user: raise webnotes.throw(_("You are not allowed to reply to this ticket."), webnotes.PermissionError) from core.doctype.communication.communication import make make(content=message, sender=bean.doc.raised_by, subject = bean.doc.subject, doctype="Support Ticket", name=bean.doc.name, date=today())
def add_support_communication(subject, content, sender, docname=None, mail=None): qr="select customer,employee_id from `tabInstallation Note` where name="+subject+" " res=webnotes.conn.sql(qr) w="select status,user_id from `tabEmployee` where name='%s'"%(res[0][1]); t=webnotes.conn.sql(w) q=" select territory from `tabCustomer` where name='%s'"%(res[0][0]); r=webnotes.conn.sql(q) w=" select parent from `tabDefaultValue` where defkey = '%s' and defvalue = '%s'"%('territory',r[0][0]) a=webnotes.conn.sql(w) if t[0][0] == 'Active': assigned_to=t[0][1] assigned_to_higher_level=a[0][0] else: assigned_to=a[0][0] assigned_to_higher_level=a[0][0] if docname: ticket = webnotes.bean("Support Ticket", docname) ticket.doc.status = 'Open' ticket.ignore_permissions = True ticket.doc.save() else: ticket = webnotes.bean([decode_dict({ "doctype":"Support Ticket", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open" #"assigned_to":assigned_to, #"assigned_to_higher_level":assigned_to_higher_level })]) ticket.ignore_permissions = True ticket.insert() make(content=content, sender=sender, subject = subject, doctype="Support Ticket", name=ticket.doc.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket.doc) return ticket
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): lead_name = webnotes.conn.get_value("Lead", {"email_id": sender}) contact_name = webnotes.conn.get_value("Contact", {"email_id": sender}) if not (lead_name or contact_name): # none, create a new Lead lead = webnotes.bean({ "doctype":"Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.insert() lead_name = lead.doc.name parent_doctype = "Contact" if contact_name else "Lead" parent_name = contact_name or lead_name message = make(content=content, sender=sender, subject=subject, doctype = parent_doctype, name = parent_name, date=date) if mail: # save attachments to parent if from mail bean = webnotes.bean(parent_doctype, parent_name) mail.save_attachments_in_doc(bean.doc)
def process_message(self, mail): name = self.get_existing_application(mail.from_email) if name: applicant = webnotes.model_wrapper("Job Applicant", name) else: applicant = webnotes.model_wrapper({ "doctype":"Job Applicant", "applicant_name": mail.from_real_name or mail.from_email, "email_id": mail.from_email }) applicant.insert() mail.save_attachments_in_doc(applicant.doc) make(content=mail.content, sender=mail.from_email, doctype="Job Applicant", name=applicant.doc.name, set_lead=False)
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): lead_name = webnotes.conn.get_value("Lead", {"email_id": sender}) contact_name = webnotes.conn.get_value("Contact", {"email_id": sender}) if not (lead_name or contact_name): # none, create a new Lead lead = webnotes.bean({ "doctype":"Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.insert() lead_name = lead.doc.name parent_doctype = "Contact" if contact_name else "Lead" parent_name = contact_name or lead_name message = make(content=content, sender=sender, subject=subject, doctype = parent_doctype, name = parent_name, date=date, sent_or_received="Received") if mail: # save attachments to parent if from mail bean = webnotes.bean(parent_doctype, parent_name) mail.save_attachments_in_doc(bean.doc)
def add_email_communication(subject, content, sender, email_date,email_id,email_uid,docname=None, mail=None): print 'in email communtn method' print subject print"------------------------------------------------------" print sender print"------------------------------------------------------" print content print"------------email from profile------------------------------------------" # print 'mail.content_type' # print mail.content_type # email_name = webnotes.conn.get("Profile", {"email": email}) # print email_name if docname: email = webnotes.bean("Email Inbox", docname) #email.doc.status = 'Open' email.ignore_permissions = True email.doc.save() else: email = webnotes.bean([decode_dict({ "doctype":"Email Inbox", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open", "owner":email_id, "email_date":email_date, "email_uid":email_uid, "Flag":"Unread" })]) email.ignore_permissions = True email.insert() print 'email object' print email.doc.name make(content=content, sender=sender, subject = subject, doctype="Email Inbox", name=email.doc.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: print "in the mail" mail.save_attachments_in_doc(email.doc) return email
def send_message(subject="Website Query", message="", sender="", status="Open"): if not message: webnotes.response["message"] = 'Please write something' return if not sender: webnotes.response["message"] = 'Email Id Required' return # make lead / communication name = webnotes.conn.get_value("Lead", {"email_id": sender}, "name") if name: lead = webnotes.model_wrapper("Lead", name) lead.doc.status = status lead.ignore_permissions = True lead.save() else: lead = webnotes.model_wrapper({ "doctype": "Lead", "lead_name": sender, "email_id": sender, "status": status, "source": "Website" }) lead.ignore_permissions = True lead.insert() make(content=message, sender=sender, subject=subject, doctype="Lead", name=lead.doc.name, lead=lead.doc.name) # guest method, cap max writes per hour if webnotes.conn.sql("""select count(*) from `tabCommunication` where TIMEDIFF(NOW(), modified) < '01:00:00'""" )[0][0] > max_communications_per_hour: webnotes.response[ "message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" return webnotes.response["message"] = 'Thank You'
def process_message(self, mail): if mail.from_email == self.email_settings.fields.get('support_email'): return thread_id = mail.get_thread_id() ticket = None new_ticket = False if thread_id and webnotes.conn.exists("Support Ticket", thread_id): ticket = webnotes.bean("Support Ticket", thread_id) ticket.doc.status = 'Open' ticket.doc.save() else: ticket = webnotes.bean([ decode_dict({ "doctype": "Support Ticket", "description": mail.content, "subject": mail.subject, "raised_by": mail.from_email, "content_type": mail.content_type, "status": "Open", }) ]) ticket.insert() new_ticket = True mail.save_attachments_in_doc(ticket.doc) make(content=mail.content, sender=mail.from_email, subject=ticket.doc.subject, doctype="Support Ticket", name=ticket.doc.name, date=mail.date) if new_ticket and cint(self.email_settings.send_autoreply) and \ "mailer-daemon" not in mail.from_email.lower(): self.send_auto_reply(ticket.doc)
def send_message(subject="Website Query", message="", sender="", status="Open"): if not message: webnotes.response["message"] = 'Please write something' return if not sender: webnotes.response["message"] = 'Email Id Required' return # make lead / communication name = webnotes.conn.get_value("Lead", {"email_id": sender}, "name") if name: lead = webnotes.model_wrapper("Lead", name) lead.doc.status = status lead.ignore_permissions = True lead.save() else: lead = webnotes.model_wrapper({ "doctype":"Lead", "lead_name": sender, "email_id": sender, "status": status, "source": "Website" }) lead.ignore_permissions = True lead.insert() make(content=message, sender=sender, subject=subject, doctype="Lead", name=lead.doc.name, lead=lead.doc.name) # guest method, cap max writes per hour if webnotes.conn.sql("""select count(*) from `tabCommunication` where TIMEDIFF(NOW(), modified) < '01:00:00'""")[0][0] > max_communications_per_hour: webnotes.response["message"] = "Sorry: we believe we have received an unreasonably high number of requests of this kind. Please try later" return webnotes.response["message"] = 'Thank You'
def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = webnotes.conn.get_value("Lead", {"email_id": mail.from_email}, "name") if name: lead = webnotes.model_wrapper("Lead", name) lead.doc.status = "Open" lead.doc.save() else: lead = webnotes.model_wrapper( { "doctype": "Lead", "lead_name": mail.from_real_name or mail.from_email, "email_id": mail.from_email, "status": "Open", "source": "Email", } ) lead.insert() mail.save_attachments_in_doc(lead.doc) make(content=mail.content, sender=mail.from_email, doctype="Lead", name=lead.doc.name, lead=lead.doc.name)
def add_support_communication(subject, content, sender, docname=None, mail=None): if docname: ticket = webnotes.bean("Support Ticket", docname) ticket.doc.status = 'Open' ticket.ignore_permissions = True ticket.doc.save() else: ticket = webnotes.bean([ decode_dict({ "doctype": "Support Ticket", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open", }) ]) ticket.ignore_permissions = True ticket.insert() make(content=content, sender=sender, subject=subject, doctype="Support Ticket", name=ticket.doc.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket.doc) return ticket
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = "[Blank Email]", "text/plain" if mail.text_content: content, content_type = mail.text_content, "text/plain" else: content, content_type = mail.html_content, "text/html" thread_list = mail.get_thread_id() email_id = mail.mail["From"] if "<" in mail.mail["From"]: import re re_result = re.findall("(?<=\<)(\S+)(?=\>)", mail.mail["From"]) if re_result and re_result[0]: email_id = re_result[0] from webnotes.utils import decode_email_header full_email_id = decode_email_header(mail.mail["From"]) for thread_id in thread_list: exists = webnotes.conn.sql( """\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """, (thread_id, "(" + email_id + ")"), ) if exists and exists[0] and exists[0][0]: st = webnotes.get_obj("Support Ticket", thread_id) from core.doctype.communication.communication import make make( content=content, sender=full_email_id, doctype="Support Ticket", name=thread_id, lead=st.doc.lead, contact=st.doc.contact, ) st.doc.status = "Open" st.doc.save() update_feed(st, "on_update") # extract attachments self.save_attachments(st.doc, mail.attachments) return from webnotes.model.doctype import get_property opts = get_property("Support Ticket", "options", "naming_series") # new ticket from webnotes.model.doc import Document d = Document("Support Ticket") d.description = content d.subject = decode_email_header(mail.mail["Subject"]) d.raised_by = full_email_id d.content_type = content_type d.status = "Open" d.naming_series = opts and opts.split("\n")[0] or "SUP" try: d.save(1) try: # extract attachments self.save_attachments(d, mail.attachments) except Exception, e: self.description += "\n\n[Did not pull attachment]" except: d.description = "Unable to extract message" d.save(1) else: # send auto reply if cint(self.email_settings.send_autoreply): if "mailer-daemon" not in d.raised_by.lower(): self.send_auto_reply(d)
"content_type": mail.content_type if mail else None, "owner":email_id, "email_date":email_date, "email_uid":email_uid, "Flag":"Unread" })]) except Exception, e: print e raise # print "after" # print email # print email.name email.ignore_permissions = True email.insert() print 'email object' print email.doc.name make(content=content, sender=sender, subject = subject, doctype="Sent Mail", name=email.doc.name, date=mail.date if mail else today(), sent_or_received="Sent") if mail: print "in the mail" mail.save_attachments_in_doc(email.doc) return email