diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-29 15:52:09 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-29 15:52:09 +0200 |
commit | d737e33b5ac4a09ada10de70b78b866481d69cba (patch) | |
tree | 35570d745b126d5b29d7ebccba1204e0811da735 /src/mail/user.rs | |
parent | b95028f89e4db7c3158fab3b71ea56a742daba21 (diff) | |
download | aerogramme-d737e33b5ac4a09ada10de70b78b866481d69cba.tar.gz aerogramme-d737e33b5ac4a09ada10de70b78b866481d69cba.zip |
Rename MailIdent to UniqueIdent and use those to identify mailboxes
Diffstat (limited to 'src/mail/user.rs')
-rw-r--r-- | src/mail/user.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/mail/user.rs b/src/mail/user.rs index e2b33e2..7b51623 100644 --- a/src/mail/user.rs +++ b/src/mail/user.rs @@ -9,6 +9,7 @@ use rusoto_s3::S3Client; use crate::login::{Credentials, StorageCredentials}; use crate::mail::mailbox::Mailbox; +use crate::mail::unique_ident::UniqueIdent; pub struct User { pub username: String, @@ -36,21 +37,29 @@ impl User { /// Opens an existing mailbox given its IMAP name. pub async fn open_mailbox(&self, name: &str) -> Result<Option<Arc<Mailbox>>> { + // TODO: handle mailbox names, mappings, renaming, etc + let id = match name { + "INBOX" => UniqueIdent([0u8; 24]), + _ => panic!("Only INBOX exists for now"), + }; + + let cache_key = (self.creds.storage.clone(), id); + { let cache = MAILBOX_CACHE.cache.lock().unwrap(); - if let Some(mb) = cache.get(&self.creds.storage).and_then(Weak::upgrade) { + if let Some(mb) = cache.get(&cache_key).and_then(Weak::upgrade) { return Ok(Some(mb)); } } - let mb = Arc::new(Mailbox::open(&self.creds, name).await?); + let mb = Arc::new(Mailbox::open(&self.creds, id).await?); let mut cache = MAILBOX_CACHE.cache.lock().unwrap(); - if let Some(concurrent_mb) = cache.get(&self.creds.storage).and_then(Weak::upgrade) { - drop(mb); // we worked for nothing but at least we didn't starve someone else + if let Some(concurrent_mb) = cache.get(&cache_key).and_then(Weak::upgrade) { + drop(mb); // we worked for nothing but at least we didn't starve someone else Ok(Some(concurrent_mb)) } else { - cache.insert(self.creds.storage.clone(), Arc::downgrade(&mb)); + cache.insert(cache_key, Arc::downgrade(&mb)); Ok(Some(mb)) } } @@ -74,7 +83,7 @@ impl User { // ---- Mailbox cache ---- struct MailboxCache { - cache: std::sync::Mutex<HashMap<StorageCredentials, Weak<Mailbox>>>, + cache: std::sync::Mutex<HashMap<(StorageCredentials, UniqueIdent), Weak<Mailbox>>>, } impl MailboxCache { |