From 9b7d999fd52dc3410b97ca831238b084650be1b3 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 12 Jul 2022 15:59:13 +0200 Subject: Implement STATUS --- src/mail/unique_ident.rs | 8 +++++++- src/mail/user.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/mail') diff --git a/src/mail/unique_ident.rs b/src/mail/unique_ident.rs index 19de6fc..267f66e 100644 --- a/src/mail/unique_ident.rs +++ b/src/mail/unique_ident.rs @@ -16,7 +16,7 @@ use crate::time::now_msec; /// required by Aerogramme. /// Their main property is to be unique without having to rely /// on synchronization between IMAP processes. -#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct UniqueIdent(pub [u8; 24]); struct IdentGenerator { @@ -78,6 +78,12 @@ impl std::fmt::Display for UniqueIdent { } } +impl std::fmt::Debug for UniqueIdent { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", hex::encode(self.0)) + } +} + impl FromStr for UniqueIdent { type Err = &'static str; diff --git a/src/mail/user.rs b/src/mail/user.rs index e80931f..fd858d3 100644 --- a/src/mail/user.rs +++ b/src/mail/user.rs @@ -71,7 +71,10 @@ impl User { /// Opens an existing mailbox given its IMAP name. pub async fn open_mailbox(&self, name: &str) -> Result>> { let (mut list, ct) = self.load_mailbox_list().await?; - eprintln!("List of mailboxes: {:?}", &list.0); + eprintln!("List of mailboxes:"); + for ent in list.0.iter() { + eprintln!(" - {:?}", ent); + } if let Some((uidvalidity, Some(mbid))) = list.get_mailbox(name) { let mb_opt = self.open_mailbox_by_id(mbid, uidvalidity).await?; @@ -88,6 +91,12 @@ impl User { } } + /// Check whether mailbox exists + pub async fn has_mailbox(&self, name: &str) -> Result { + let (list, _ct) = self.load_mailbox_list().await?; + Ok(list.has_mailbox(name)) + } + /// Creates a new mailbox in the user's IMAP namespace. pub async fn create_mailbox(&self, name: &str) -> Result<()> { if name.ends_with(MAILBOX_HIERARCHY_DELIMITER) { -- cgit v1.2.3