@@ -86,7 +86,8 @@ def get_customer_supplier(args=None): | |||||
def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', send_me_a_copy=False): | def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', send_me_a_copy=False): | ||||
from json import loads | from json import loads | ||||
footer = None | |||||
if sent_via: | if sent_via: | ||||
if hasattr(sent_via, "get_sender"): | if hasattr(sent_via, "get_sender"): | ||||
d.sender = sent_via.get_sender(d) or d.sender | d.sender = sent_via.get_sender(d) or d.sender | ||||
@@ -94,10 +95,12 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s | |||||
d.subject = sent_via.get_subject(d) | d.subject = sent_via.get_subject(d) | ||||
if hasattr(sent_via, "get_content"): | if hasattr(sent_via, "get_content"): | ||||
d.content = sent_via.get_content(d) | d.content = sent_via.get_content(d) | ||||
footer = set_portal_link(sent_via, d) | |||||
from webnotes.utils.email_lib.smtp import get_email | from webnotes.utils.email_lib.smtp import get_email | ||||
mail = get_email(d.recipients, sender=d.sender, subject=d.subject, | mail = get_email(d.recipients, sender=d.sender, subject=d.subject, | ||||
msg=d.content) | |||||
msg=d.content, footer=footer) | |||||
if send_me_a_copy: | if send_me_a_copy: | ||||
mail.cc.append(d.sender) | mail.cc.append(d.sender) | ||||
@@ -113,6 +116,36 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s | |||||
raise_exception=True) | raise_exception=True) | ||||
mail.send() | mail.send() | ||||
def set_portal_link(sent_via, comm): | |||||
"""set portal link in footer""" | |||||
from webnotes.webutils import is_portal_enabled, get_portal_links | |||||
from webnotes.utils import get_url | |||||
import urllib | |||||
footer = None | |||||
if is_portal_enabled(): | |||||
portal_opts = get_portal_links().get(sent_via.doc.doctype) | |||||
if portal_opts: | |||||
if (sent_via.doc.email or sent_via.doc.email_id or sent_via.doc.contact_email) \ | |||||
not in comm.recipients: | |||||
valid = False | |||||
else: | |||||
valid = True | |||||
if portal_opts.get("conditions"): | |||||
for fieldname, val in portal_opts["conditions"].items(): | |||||
if sent_via.doc.fields.get(fieldname) != val: | |||||
valid = False | |||||
break | |||||
if valid: | |||||
url = "%s/%s?name=%s" % (get_url(), portal_opts["page"], | |||||
urllib.quote(sent_via.doc.name)) | |||||
footer = """<!-- Portal Link --><hr> | |||||
<a href="%s" target="_blank">View this on our website</a>""" % url | |||||
return footer | |||||
def get_user(doctype, txt, searchfield, start, page_len, filters): | def get_user(doctype, txt, searchfield, start, page_len, filters): | ||||
from controllers.queries import get_match_cond | from controllers.queries import get_match_cond | ||||
@@ -83,7 +83,6 @@ wn.views.CommunicationList = Class.extend({ | |||||
doc._sender = doc.sender.replace(/</, "<").replace(/>/, ">"); | doc._sender = doc.sender.replace(/</, "<").replace(/>/, ">"); | ||||
doc.content = doc.content.split("-----"+wn._("In response to")+"-----")[0]; | doc.content = doc.content.split("-----"+wn._("In response to")+"-----")[0]; | ||||
doc.content = doc.content.split("-----"+wn._("Original Message")+"-----")[0]; | doc.content = doc.content.split("-----"+wn._("Original Message")+"-----")[0]; | ||||
doc.content = doc.content.split("<!-- Portal Link -->")[0]; | |||||
}, | }, | ||||
make_line: function(doc) { | make_line: function(doc) { | ||||
@@ -289,7 +288,6 @@ wn.views.CommunicationComposer = Class.extend({ | |||||
? cur_frm.communication_view.list | ? cur_frm.communication_view.list | ||||
: []; | : []; | ||||
var signature = wn.boot.profile.email_signature || ""; | var signature = wn.boot.profile.email_signature || ""; | ||||
var portal_link = this.setup_portal_link(); | |||||
if(!wn.utils.is_html(signature)) { | if(!wn.utils.is_html(signature)) { | ||||
signature = signature.replace(/\n/g, "<br>"); | signature = signature.replace(/\n/g, "<br>"); | ||||
@@ -300,8 +298,7 @@ wn.views.CommunicationComposer = Class.extend({ | |||||
} | } | ||||
var reply = (this.message || "") | var reply = (this.message || "") | ||||
+ "<p></p>" + signature | |||||
+ "<p></p>" + portal_link; | |||||
+ "<p></p>" + signature; | |||||
if(comm_list.length > 0) { | if(comm_list.length > 0) { | ||||
fields.content.set_input(reply | fields.content.set_input(reply | ||||
@@ -312,31 +309,6 @@ wn.views.CommunicationComposer = Class.extend({ | |||||
fields.content.set_input(reply); | fields.content.set_input(reply); | ||||
} | } | ||||
}, | }, | ||||
setup_portal_link: function() { | |||||
var me = this; | |||||
var portal_link = ""; | |||||
var show_portal_link = wn.boot.portal_links[this.doc.doctype] && | |||||
!(wn.boot.website_settings && cint(wn.boot.website_settings.disable_signup)); | |||||
if(show_portal_link) { | |||||
var portal_args = wn.boot.portal_links[this.doc.doctype]; | |||||
var valid = true; | |||||
if(portal_args.conditions) { | |||||
$.each(portal_args.conditions, function(k, v) { | |||||
if(me.doc[k] !== v) valid = false; | |||||
}); | |||||
} | |||||
if(valid) { | |||||
// set portal link | |||||
portal_link = repl("%(location)s/%(page)s?name=%(name)s", { | |||||
location: window.location.origin, | |||||
page: portal_args["page"], | |||||
name: encodeURIComponent(this.doc.name) | |||||
}); | |||||
portal_link = '<!-- Portal Link -->--<br><a href="'+portal_link+'" target="_blank">View this on our website</a>'; | |||||
} | |||||
} | |||||
return portal_link; | |||||
}, | |||||
setup_autosuggest: function() { | setup_autosuggest: function() { | ||||
var me = this; | var me = this; | ||||
@@ -44,9 +44,6 @@ def get_bootinfo(): | |||||
bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from | bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from | ||||
tabPage where ifnull(icon,'')!=''"""))) | tabPage where ifnull(icon,'')!=''"""))) | ||||
# portal links for sending in email | |||||
bootinfo.portal_links = webnotes.webutils.get_portal_links() | |||||
add_home_page(bootinfo, doclist) | add_home_page(bootinfo, doclist) | ||||
add_allowed_pages(bootinfo) | add_allowed_pages(bootinfo) | ||||
load_translations(bootinfo) | load_translations(bootinfo) | ||||
@@ -52,8 +52,6 @@ def get_formatted_email(user): | |||||
def extract_email_id(email): | def extract_email_id(email): | ||||
"""fetch only the email part of the email id""" | """fetch only the email part of the email id""" | ||||
from email.utils import parseaddr | from email.utils import parseaddr | ||||
if ',' in email and email.count("@")==1: | |||||
email = email.split(",")[-1] | |||||
fullname, email_id = parseaddr(email) | fullname, email_id = parseaddr(email) | ||||
if isinstance(email_id, basestring) and not isinstance(email_id, unicode): | if isinstance(email_id, basestring) and not isinstance(email_id, unicode): | ||||
email_id = email_id.decode("utf-8", "ignore") | email_id = email_id.decode("utf-8", "ignore") | ||||
@@ -817,14 +815,19 @@ def get_base_path(): | |||||
import conf | import conf | ||||
import os | import os | ||||
return os.path.dirname(os.path.abspath(conf.__file__)) | return os.path.dirname(os.path.abspath(conf.__file__)) | ||||
def get_url(): | |||||
import startup | |||||
if hasattr(startup, "get_url"): | |||||
url = startup.get_url() | |||||
else: | |||||
url = get_request_site_address() | |||||
return url | |||||
def get_url_to_form(doctype, name, base_url=None, label=None): | def get_url_to_form(doctype, name, base_url=None, label=None): | ||||
if not base_url: | if not base_url: | ||||
try: | |||||
from startup import get_url | |||||
base_url = get_url() | |||||
except ImportError: | |||||
base_url = get_request_site_address() | |||||
base_url = get_url() | |||||
if not label: label = name | if not label: label = name | ||||
@@ -12,12 +12,12 @@ import conf | |||||
from webnotes import msgprint | from webnotes import msgprint | ||||
from webnotes.utils import cint | from webnotes.utils import cint | ||||
def get_email(recipients, sender='', msg='', subject='[No Subject]', text_content = None): | |||||
def get_email(recipients, sender='', msg='', subject='[No Subject]', text_content = None, footer=None): | |||||
"""send an html email as multipart with attachments and all""" | """send an html email as multipart with attachments and all""" | ||||
email = EMail(sender, recipients, subject) | email = EMail(sender, recipients, subject) | ||||
if (not '<br>' in msg) and (not '<p>' in msg) and (not '<div' in msg): | if (not '<br>' in msg) and (not '<p>' in msg) and (not '<div' in msg): | ||||
msg = msg.replace('\n', '<br>') | msg = msg.replace('\n', '<br>') | ||||
email.set_html(msg, text_content) | |||||
email.set_html(msg, text_content, footer=footer) | |||||
return email | return email | ||||
@@ -50,10 +50,10 @@ class EMail: | |||||
self.cc = [] | self.cc = [] | ||||
self.html_set = False | self.html_set = False | ||||
def set_html(self, message, text_content = None): | |||||
def set_html(self, message, text_content = None, footer=None): | |||||
"""Attach message in the html portion of multipart/alternative""" | """Attach message in the html portion of multipart/alternative""" | ||||
message = message + self.get_footer() | |||||
message = message + self.get_footer(footer) | |||||
# this is the first html part of a multi-part message, | # this is the first html part of a multi-part message, | ||||
# convert to text well | # convert to text well | ||||
@@ -100,11 +100,11 @@ class EMail: | |||||
self.msg_root.attach(part) | self.msg_root.attach(part) | ||||
def get_footer(self): | |||||
def get_footer(self, footer=None): | |||||
"""append a footer (signature)""" | """append a footer (signature)""" | ||||
import startup | import startup | ||||
footer = "" | |||||
footer = footer or "" | |||||
footer += webnotes.conn.get_value('Control Panel',None,'mail_footer') or '' | footer += webnotes.conn.get_value('Control Panel',None,'mail_footer') or '' | ||||
footer += getattr(startup, 'mail_footer', '') | footer += getattr(startup, 'mail_footer', '') | ||||
@@ -161,19 +161,12 @@ class EMail: | |||||
def validate(self): | def validate(self): | ||||
"""validate the email ids""" | """validate the email ids""" | ||||
from webnotes.utils import validate_email_add, extract_email_id | |||||
from webnotes.utils import validate_email_add | |||||
def _validate(email): | def _validate(email): | ||||
"""validate an email field""" | """validate an email field""" | ||||
if email: | |||||
if "," in email: | |||||
email = email.split(",")[-1] | |||||
if not validate_email_add(email): | |||||
# try extracting the email part and set as sender | |||||
new_email = extract_email_id(email) | |||||
if not (new_email and validate_email_add(new_email)): | |||||
webnotes.msgprint("%s is not a valid email id" % email, | |||||
raise_exception = 1) | |||||
email = new_email | |||||
if email and not validate_email_add(email): | |||||
webnotes.msgprint("%s is not a valid email id" % email, | |||||
raise_exception = 1) | |||||
return email | return email | ||||
if not self.sender: | if not self.sender: | ||||
@@ -245,3 +245,14 @@ def get_portal_links(): | |||||
} | } | ||||
return portal_args | return portal_args | ||||
_is_portal_enabled = None | |||||
def is_portal_enabled(): | |||||
global _is_portal_enabled | |||||
if _is_portal_enabled is None: | |||||
_is_portal_enabled = True | |||||
if webnotes.utils.cint(webnotes.conn.get_value("Website Settings", | |||||
"Website Settings", "disable_signup")): | |||||
_is_portal_enabled = False | |||||
return _is_portal_enabled |