Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/hr/doctype/job_applicant/get_job_applications.py b/hr/doctype/job_applicant/get_job_applications.py
index 4484bc5..64d7823 100644
--- a/hr/doctype/job_applicant/get_job_applications.py
+++ b/hr/doctype/job_applicant/get_job_applications.py
@@ -23,11 +23,7 @@
 class JobsMailbox(POP3Mailbox):	
 	def setup(self, args=None):
 		self.settings = args or webnotes.doc("Jobs Email Settings", "Jobs Email Settings")
-	
-	def check_mails(self):
-		return webnotes.conn.sql("select user from tabSessions where \
-			time_to_sec(timediff(now(), lastupdate)) < 1800")
-	
+		
 	def process_message(self, mail):
 		if mail.from_email == self.settings.email_id:
 			return
diff --git a/selling/doctype/lead/get_leads.py b/selling/doctype/lead/get_leads.py
index c08e5e0..08a9b1c 100644
--- a/selling/doctype/lead/get_leads.py
+++ b/selling/doctype/lead/get_leads.py
@@ -20,11 +20,11 @@
 from webnotes.utils.email_lib.receive import POP3Mailbox
 from core.doctype.communication.communication import make
 
-def add_sales_communication(subject, content, sender, real_name, mail=None):
-	def set_status_open(doctype, name):
+def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open"):
+	def set_status(doctype, name):
 		w = webnotes.model_wrapper(doctype, name)
 		w.ignore_permissions = True
-		w.doc.status = "Open"
+		w.doc.status = is_system_user and "Replied" or status
 		w.doc.save()
 		if mail:
 			mail.save_attachments_in_doc(w.doc)
@@ -32,37 +32,33 @@
 	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 is_system_user:
-		if contact_name:
-			set_status_open("Contact", contact_name)
-		elif lead_name:
-			set_status_open("Lead", lead_name)
-		else:
-			# none, create a new Lead
-			lead = webnotes.model_wrapper({
-				"doctype":"Lead",
-				"lead_name": real_name or sender,
-				"email_id": sender,
-				"status": "Open",
-				"source": "Email"
-			})
-			lead.ignore_permissions = True
-			lead.insert()
-			if mail:
-				mail.save_attachments_in_doc(lead.doc)
+
+	if not (lead_name or contact_name):
+		# none, create a new Lead
+		lead = webnotes.model_wrapper({
+			"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)
+	
+	if contact_name:
+		set_status("Contact", contact_name)
+	elif lead_name:
+		set_status("Lead", lead_name)
+	
 
 class SalesMailbox(POP3Mailbox):	
 	def setup(self, args=None):
 		self.settings = args or webnotes.doc("Sales Email Settings", "Sales Email Settings")
-	
-	def check_mails(self):
-		return webnotes.conn.sql("select user from tabSessions where \
-			time_to_sec(timediff(now(), lastupdate)) < 1800")
-	
+		
 	def process_message(self, mail):
 		if mail.from_email == self.settings.email_id:
 			return
diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py
index e0cbc07..99eaf69 100644
--- a/support/doctype/support_ticket/get_support_mails.py
+++ b/support/doctype/support_ticket/get_support_mails.py
@@ -30,12 +30,7 @@
 			"username": self.email_settings.support_username,
 			"password": self.email_settings.support_password
 		})
-	
-	def check_mails(self):
-		self.auto_close_tickets()
-		return webnotes.conn.sql("select user from tabSessions where \
-			time_to_sec(timediff(now(), lastupdate)) < 1800")
-	
+		
 	def process_message(self, mail):
 		if mail.from_email == self.email_settings.fields.get('support_email'):
 			return
diff --git a/website/helpers/contact.py b/website/helpers/contact.py
index a16e2aa..251e1f6 100644
--- a/website/helpers/contact.py
+++ b/website/helpers/contact.py
@@ -33,7 +33,8 @@
 
 	# make lead / communication
 	from selling.doctype.lead.get_leads import add_sales_communication
-	add_sales_communication(subject or "Website Query", message, sender, sender)
+	add_sales_communication(subject or "Website Query", message, sender, sender, 
+		mail=None, status=status)
 	
 	# guest method, cap max writes per hour
 	if webnotes.conn.sql("""select count(*) from `tabCommunication`