From d737e33b5ac4a09ada10de70b78b866481d69cba Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 29 Jun 2022 15:52:09 +0200 Subject: Rename MailIdent to UniqueIdent and use those to identify mailboxes --- src/mail/mailbox.rs | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'src/mail/mailbox.rs') diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs index 9e8f0db..2e890d9 100644 --- a/src/mail/mailbox.rs +++ b/src/mail/mailbox.rs @@ -8,53 +8,40 @@ use tokio::sync::RwLock; use crate::bayou::Bayou; use crate::cryptoblob::Key; use crate::login::Credentials; -use crate::mail::mail_ident::*; use crate::mail::uidindex::*; +use crate::mail::unique_ident::*; use crate::mail::IMF; -pub struct Summary { - pub validity: ImapUidvalidity, - pub next: ImapUid, - pub exists: u32, - pub recent: u32, - pub flags: Vec, - pub unseen: Option, +pub struct Mailbox { + id: UniqueIdent, + mbox: RwLock, } -impl std::fmt::Display for Summary { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!( - f, - "uidvalidity: {}, uidnext: {}, exists: {}", - self.validity, self.next, self.exists - ) - } -} - -pub struct Mailbox(RwLock); - impl Mailbox { - pub(super) async fn open(creds: &Credentials, name: &str) -> Result { - let index_path = format!("index/{}", name); - let mail_path = format!("mail/{}", name); + pub(super) async fn open(creds: &Credentials, id: UniqueIdent) -> Result { + let index_path = format!("index/{}", id); + let mail_path = format!("mail/{}", id); let mut uid_index = Bayou::::new(creds, index_path)?; uid_index.sync().await?; - Ok(Self(RwLock::new(MailboxInternal { + let mbox = RwLock::new(MailboxInternal { + id, bucket: creds.bucket().to_string(), - key: creds.keys.master.clone(), + encryption_key: creds.keys.master.clone(), k2v: creds.k2v_client()?, s3: creds.s3_client()?, uid_index, mail_path, - }))) + }); + + Ok(Self { id, mbox }) } /// Get a clone of the current UID Index of this mailbox /// (cloning is cheap so don't hesitate to use this) pub async fn current_uid_index(&self) -> UidIndex { - self.0.read().await.uid_index.state().clone() + self.mbox.read().await.uid_index.state().clone() } /// Insert an email in the mailbox @@ -91,14 +78,15 @@ impl Mailbox { // Non standard but common flags: // https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml struct MailboxInternal { + id: UniqueIdent, bucket: String, - key: Key, + mail_path: String, + encryption_key: Key, k2v: K2vClient, s3: S3Client, uid_index: Bayou, - mail_path: String, } impl MailboxInternal { -- cgit v1.2.3