imap_client/tasks/tasks/
list.rs1use imap_next::imap_types::{
2 command::CommandBody,
3 core::QuotedChar,
4 flag::FlagNameAttribute,
5 mailbox::{ListMailbox, Mailbox},
6 response::{Data, StatusBody, StatusKind},
7};
8
9use super::TaskError;
10use crate::tasks::Task;
11
12#[derive(Clone, Debug)]
13pub struct ListTask {
14 mailbox: Mailbox<'static>,
15 mailbox_wildcard: ListMailbox<'static>,
16 output: Vec<(
17 Mailbox<'static>,
18 Option<QuotedChar>,
19 Vec<FlagNameAttribute<'static>>,
20 )>,
21}
22
23impl ListTask {
24 pub fn new(mailbox: Mailbox<'static>, mailbox_wildcard: ListMailbox<'static>) -> Self {
25 Self {
26 mailbox,
27 mailbox_wildcard,
28 output: Vec::new(),
29 }
30 }
31}
32
33impl Task for ListTask {
34 type Output = Result<
35 Vec<(
36 Mailbox<'static>,
37 Option<QuotedChar>,
38 Vec<FlagNameAttribute<'static>>,
39 )>,
40 TaskError,
41 >;
42
43 fn command_body(&self) -> CommandBody<'static> {
44 CommandBody::List {
45 reference: self.mailbox.clone(),
46 mailbox_wildcard: self.mailbox_wildcard.clone(),
47 }
48 }
49
50 fn process_data(&mut self, data: Data<'static>) -> Option<Data<'static>> {
51 if let Data::List {
52 items,
53 delimiter,
54 mailbox,
55 } = data
56 {
57 self.output.push((mailbox, delimiter, items));
58 None
59 } else {
60 Some(data)
61 }
62 }
63
64 fn process_tagged(self, status_body: StatusBody<'static>) -> Self::Output {
65 match status_body.kind {
66 StatusKind::Ok => Ok(self.output),
67 StatusKind::No => Err(TaskError::UnexpectedNoResponse(status_body)),
68 StatusKind::Bad => Err(TaskError::UnexpectedBadResponse(status_body)),
69 }
70 }
71}