def handle_list(self, tag, rest, uid): # If we are testing 'early premature' conection dropping, then # indicate the server should close before sending anything if getattr(self.server.testcase, 'is_disconnect_early_test', False): return True if self.server.testcase.num_transient_list_errors: self.server.testcase.num_transient_list_errors -= 1 self.send_negative_response(tag, "something transient") return directory, pattern = parse_response([rest]) assert directory == '', repr(directory) assert pattern == '*', repr(pattern) for mbox in self.imap.mailboxes: resp = ( mbox.flags, mbox.delim, encode_imap_utf7(mbox.name)) self.send_untagged_response("LIST " + collapseNestedLists(resp)) if getattr(self.server.testcase, 'is_disconnect_after_list_test', False): # disconnect *before* sending the OK response return True self.send_positive_response(tag, 'LIST completed')
else: logger.info("logging into account %r via oauth", details['id']) if do_oauth: xoauth_string = xoauth.GenerateXOauthStringFromAcctInfo('imap', details) try: ret._imap.authenticate('XOAUTH', lambda x: xoauth_string) except ret.Error, exc: raise IMAP4AuthException(account.OAUTH, exc.args[0]) else: if 'username' not in details or 'password' not in details: raise ValueError, "Account has no username or password" # XXX - is this encoding of 'username' correct? We've already determined # experimentally it is *not* correct for the password... try: ret.login(encode_imap_utf7(details['username']), details['password']) except ret.Error, exc: raise IMAP4AuthException(account.PASSWORD, exc.args[0]) account.reportStatus(brat.EVERYTHING, brat.GOOD) return ret RETRYABLE_EXCEPTIONS = (imaplib.IMAP4.abort, imaplib.IMAP4.error, socket.timeout, socket.error, IMAP4AuthException) def get_connection(account, conductor): acct_id = account.details['id'] def _on_connection_failed(exc): account.reportStatus(**failure_to_status(exc)) if not isinstance(exc, RETRYABLE_EXCEPTIONS): raise