async def do_fetch(self, cmd: FetchCommand): if not cmd.uid: self.selected.hide_expunged = True messages, updates = await self.session.fetch_messages( self.selected, cmd.sequence_set, frozenset(cmd.attributes)) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') msg_attrs = MessageAttributes(msg, self.selected) fetch_data = msg_attrs.get_all(cmd.attributes) resp.add_untagged(FetchResponse(msg_seq, fetch_data)) return resp, updates
async def do_fetch(self, cmd: FetchCommand) -> _CommandRet: if not cmd.uid: self.selected.hide_expunged = True set_seen = any(attr.set_seen for attr in cmd.attributes) messages, updates = await self.session.fetch_messages( self.selected, cmd.sequence_set, set_seen) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') msg_attrs = MessageAttributes(msg, self.selected, cmd.attributes) fetch_resp = FetchResponse(msg_seq, msg_attrs, writing_hook=msg_attrs.load_hook()) resp.add_untagged(fetch_resp) return resp, updates
async def do_search(self, cmd: SearchCommand): if not cmd.uid: self.selected.hide_expunged = True messages, updates = await self.session.search_mailbox( self.selected, cmd.keys) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') msg_ids: List[int] = [] for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') if cmd.uid: msg_ids.append(msg.uid) else: msg_ids.append(msg_seq) resp.add_untagged(SearchResponse(msg_ids)) return resp, updates
async def do_search(self, cmd: SearchCommand) -> _CommandRet: if not cmd.uid: self.selected.hide_expunged = True messages, updates = await self.session.search_mailbox( self.selected, cmd.keys) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') msg_ids: List[int] = [] for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') if cmd.uid: msg_ids.append(msg.uid) else: msg_ids.append(msg_seq) resp.add_untagged(SearchResponse(msg_ids)) return resp, updates
async def do_store(self, cmd: StoreCommand): if not cmd.uid: self.selected.hide_expunged = True if cmd.silent: self.selected.silence(cmd.sequence_set, cmd.flag_set, cmd.mode) messages, updates = await self.session.update_flags( self.selected, cmd.sequence_set, cmd.flag_set, cmd.mode) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') session_flags = self.selected.session_flags for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') elif cmd.silent: continue flags = msg.get_flags(session_flags) fetch_data: List[Tuple[FetchAttribute, MaybeBytes]] = [ (_flags_attr, ListP(flags, sort=True))] if cmd.uid: fetch_data.append((_uid_attr, Number(msg.uid))) resp.add_untagged(FetchResponse(msg_seq, fetch_data)) return resp, updates
async def do_store(self, cmd: StoreCommand) -> _CommandRet: if not cmd.uid: self.selected.hide_expunged = True if cmd.silent: self.selected.silence(cmd.sequence_set, cmd.flag_set, cmd.mode) messages, updates = await self.session.update_flags( self.selected, cmd.sequence_set, cmd.flag_set, cmd.mode) resp = ResponseOk(cmd.tag, cmd.command + b' completed.') session_flags = self.selected.session_flags for msg_seq, msg in messages: if msg.expunged: resp.code = ResponseCode.of(b'EXPUNGEISSUED') elif cmd.silent: continue flags = msg.get_flags(session_flags) fetch_data: List[FetchValue] = [ FetchValue.of(_flags_attr, ListP(flags, sort=True))] if cmd.uid: fetch_data.append( FetchValue.of(_uid_attr, Number(msg.uid))) resp.add_untagged(FetchResponse(msg_seq, fetch_data)) return resp, updates