Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py
index c376f45..c63468e 100644
--- a/selling/doctype/lead/get_leads.py
+++ b/selling/doctype/lead/get_leads.py
@@ -9,17 +9,8 @@
 
 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
@@ -34,14 +25,13 @@
 		lead.insert()
 		lead_name = lead.doc.name
 
-	make(content=content, sender=sender, subject=subject,
+	message = 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)
-	
+	if mail:
+		# save attachments to parent if from mail
+		bean = webnotes.bean("Contact" if contact_name else "Lead", contact_name or lead_name)
+		mail.save_attachments_in_doc(bean.doc)
 
 class SalesMailbox(POP3Mailbox):	
 	def setup(self, args=None):
diff --git a/utilities/doctype/contact/contact.py b/utilities/doctype/contact/contact.py
index 89cfc8e..961bb52 100644
--- a/utilities/doctype/contact/contact.py
+++ b/utilities/doctype/contact/contact.py
@@ -7,7 +7,7 @@
 
 from utilities.transaction_base import TransactionBase
 
-class DocType(TransactionBase):	
+class DocType(TransactionBase):
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
 		self.doclist = doclist
diff --git a/website/helpers/contact.py b/website/helpers/contact.py
index 05ae4f7..35446a3 100644
--- a/website/helpers/contact.py
+++ b/website/helpers/contact.py
@@ -20,7 +20,7 @@
 
 	# make lead / communication
 	from selling.doctype.lead.get_leads import add_sales_communication
-	add_sales_communication(subject or "Website Query", message, sender, sender, 
+	message = add_sales_communication(subject or "Website Query", message, sender, sender, 
 		mail=None, status=status)
 	
 	# guest method, cap max writes per hour
@@ -29,4 +29,4 @@
 		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'
\ No newline at end of file
+	webnotes.response.status = "okay"
diff --git a/website/templates/js/contact.js b/website/templates/js/contact.js
index a28abba..caec945 100644
--- a/website/templates/js/contact.js
+++ b/website/templates/js/contact.js
@@ -26,7 +26,12 @@
 			sender: email,
 			message: message,
 			callback: function(r) {
-				msgprint(r.message);
+				if(r.status==="okay") {
+					msgprint(r.message or "Sent")
+				} else {
+					msgprint("There were errors");
+					console.log(r.exc);
+				}
 				$(':input').val('');
 			}
 		});