def get_server(self, in_receive=False): """Returns logged in POP3 connection object.""" args = { "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "password": self.password, "use_imap": self.use_imap } if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error), e: if in_receive and (e.message == "-ERR authentication failed" or "log in via your web browser" in e.message): # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error(description=_( 'Authentication failed while receiving emails from Email Account {0}. Message from server: {1}' .format(self.name, e.message))) return None else: frappe.throw(e.message)
def get_server(self, in_receive=False): """Returns logged in POP3 connection object.""" args = { "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "password": self.password, "use_imap": self.use_imap } if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error), e: if in_receive and e.message=="-ERR authentication failed": # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error( description=_('Authentication failed while receiving emails from Email Account {0}'.format(self.name)) ) return None else: frappe.throw(e.message)
def get_server(self, in_receive=False): """Returns logged in POP3 connection object.""" if frappe.cache().get_value("workers:no-internet") == True: return None args = { "email_account":self.name, "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "password": self.password, "use_imap": self.use_imap, "uid_validity":self.uid_validity, "uidnext":self.uidnext, "no_remaining":self.no_remaining } if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error), e: if in_receive and ("authentication failed" in e.message.lower() or "log in via your web browser" in e.message.lower()): # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error( description=_('Authentication failed while receiving emails from Email Account {0}. Message from server: {1}'.format(self.name, e.message)) ) return None else: frappe.throw(e.message)
def get_incoming_server(self, in_receive=False): """Returns logged in POP3/IMAP connection object.""" args = frappe._dict({ "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "use_imap": self.use_imap }) if self.password: args.password = self.get_password() if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error), e: message = e.message.lower().replace(" ","") if in_receive and any(map(lambda t: t in message, ['authenticationfail', 'loginviayourwebbrowser', #abbreviated to work with both failure and failed 'loginfailed', 'err[auth]', 'errtemporaryerror'])): #temporary error to deal with godaddy # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error( description=_('Authentication failed while receiving emails from Email Account {0}. Message from server: {1}'.format(self.name, e.message)) ) return None else: frappe.throw(e.message)
def get_incoming_server(self, in_receive=False, email_sync_rule="UNSEEN"): """Returns logged in POP3/IMAP connection object.""" if frappe.cache().get_value("workers:no-internet") == True: return None args = frappe._dict({ "email_account": self.name, "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "use_imap": self.use_imap, "email_sync_rule": email_sync_rule, "uid_validity": self.uidvalidity, "incoming_port": get_port(self), "initial_sync_count": self.initial_sync_count or 100 }) if self.password: args.password = self.get_password() if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error) as e: message = e.message.lower().replace(" ", "") if in_receive and any( map( lambda t: t in message, [ 'authenticationfail', 'loginviayourwebbrowser', #abbreviated to work with both failure and failed 'loginfailed', 'err[auth]', 'errtemporaryerror' ])): #temporary error to deal with godaddy # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error(description=_( 'Authentication failed while receiving emails from Email Account {0}. Message from server: {1}' ).format(self.name, e.message)) return None else: frappe.throw(e.message) except socket.error: if in_receive: # timeout while connecting, see receive.py connect method description = frappe.message_log.pop( ) if frappe.message_log else "Socket Error" if test_internet(): self.db_set("no_failed", self.no_failed + 1) if self.no_failed > 2: self.handle_incoming_connect_error( description=description) else: frappe.cache().set_value("workers:no-internet", True) return None else: raise if not in_receive: if self.use_imap: email_server.imap.logout() # reset failed attempts count self.set_failed_attempts_count(0) return email_server
def get_incoming_server(self, in_receive=False, email_sync_rule="UNSEEN"): """Returns logged in POP3/IMAP connection object.""" if frappe.cache().get_value("workers:no-internet") == True: return None args = frappe._dict({ "email_account":self.name, "host": self.email_server, "use_ssl": self.use_ssl, "username": getattr(self, "login_id", None) or self.email_id, "use_imap": self.use_imap, "email_sync_rule": email_sync_rule, "uid_validity": self.uidvalidity, "initial_sync_count": self.initial_sync_count or 100 }) if self.password: args.password = self.get_password() if not args.get("host"): frappe.throw(_("{0} is required").format("Email Server")) email_server = EmailServer(frappe._dict(args)) try: email_server.connect() except (error_proto, imaplib.IMAP4.error) as e: message = e.message.lower().replace(" ","") if in_receive and any(map(lambda t: t in message, ['authenticationfail', 'loginviayourwebbrowser', #abbreviated to work with both failure and failed 'loginfailed', 'err[auth]', 'errtemporaryerror'])): #temporary error to deal with godaddy # if called via self.receive and it leads to authentication error, disable incoming # and send email to system manager self.handle_incoming_connect_error( description=_('Authentication failed while receiving emails from Email Account {0}. Message from server: {1}'.format(self.name, e.message)) ) return None else: frappe.throw(e.message) except socket.error: if in_receive: # timeout while connecting, see receive.py connect method description = frappe.message_log.pop() if frappe.message_log else "Socket Error" if test_internet(): self.db_set("no_failed", self.no_failed + 1) if self.no_failed > 2: self.handle_incoming_connect_error(description=description) else: frappe.cache().set_value("workers:no-internet", True) return None else: raise if not in_receive: if self.use_imap: email_server.imap.logout() # reset failed attempts count self.set_failed_attempts_count(0) return email_server