def _test(self, to_parse, expected, wrap=True): if wrap: # convenience - expected value should be wrapped in another tuple expected = (expected,) if not isinstance(to_parse, list): to_parse = [to_parse] output = parse_response(to_parse) self.assertSequenceEqual(output, expected)
def _test(self, to_parse, expected, wrap=True): if wrap: # convenience - expected value should be wrapped in another tuple expected = (expected, ) if not isinstance(to_parse, list): to_parse = [to_parse] output = parse_response(to_parse) self.assertSequenceEqual(output, expected)
def handle_store(self, tag, rest, uid): # XXX - no idea if these responses are correct - but our imap client # doesn't actually use the return codes so it doesn't really matter... spec, sub, params = parse_response([rest]) if sub=="+FLAGS": for seq, msg in self._get_matching_messages(spec, uid): self.current_mbox.add_flags(msg, params) self.send_untagged_response("%d FETCH (FLAGS (%s))" % (msg.uid, " ".join(params))) self.send_positive_response(tag, "STORE added flags") else: raise ValueError("Unsupported store type '%s'" % (sub,))
def _do_handle_select(self, cmdname, tag, rest, uid): name = decode_imap_utf7(parse_response([rest])[0]) self.current_mbox = None for mbox in self.imap.mailboxes: if name == mbox.name: self.current_mbox = mbox self.send_untagged_response(str(mbox.get_message_count()) + ' EXISTS') self.send_untagged_response(str(mbox.get_recent_count()) + ' RECENT') self.send_untagged_response('FLAGS (%s)' % ' '.join(mbox.flags)) self.send_positive_response(None, '[UIDVALIDITY %d]' % mbox.get_uid_validity()) self.send_positive_response(tag, '%s worked' % cmdname) break else: self.send_negative_response(tag, 'no such mailbox %r' % name)
def handle_login(self, tag, rest, uid): if self.server.testcase.max_logins is not None and \ self.server.testcase.num_current_logins >= self.server.testcase.max_logins: self.server.testcase.num_failed_logins += 1 self.send_negative_response(tag, "too many concurrent connections") return if self.server.testcase.num_transient_auth_errors: self.server.testcase.num_transient_auth_errors -= 1 self.server.testcase.num_failed_logins += 1 self.send_negative_response(tag, "transient auth failure...") return username, password = parse_response([rest]) if self.imap.login(username, password): self.server.testcase.num_current_logins += 1 self.send_positive_response(tag, 'LOGIN completed') else: self.send_negative_response(tag, 'LOGIN failed') if getattr(self.server.testcase, 'is_disconnect_after_login_test', False): return True
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')
def handle_fetch(self, tag, rest, uid): spec, flags = parse_response([rest]) if isinstance(spec, int): # just an int was specified items = [spec] else: # a comma-sep'd list of messages - each may be a simple int, or # an int:int range. items = [spec.split(",")] for (seq, msg) in enumerate(self.current_mbox.messages): for item in items: if ':' in item: first, second = [int(x) for x in items.split(":")] else: first = second = item check = msg.uid if uid else seq if check >= first and check <= second: # yay - matches. self._spew_message(seq, msg, flags, uid) break self.send_positive_response(tag, "FETCH worked")
def handle_fetch(self, tag, rest, uid): spec, flags = parse_response([rest]) for seq, msg in self._get_matching_messages(spec, uid): self._spew_message(seq, msg, flags, uid) self.send_positive_response(tag, "FETCH worked")