diff options
Diffstat (limited to 'src/mailbox.rs')
-rw-r--r-- | src/mailbox.rs | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/src/mailbox.rs b/src/mailbox.rs index 49d8e56..249d329 100644 --- a/src/mailbox.rs +++ b/src/mailbox.rs @@ -5,12 +5,27 @@ use rusoto_s3::S3Client; use crate::bayou::Bayou; use crate::cryptoblob::Key; use crate::login::Credentials; -use crate::mail_uuid::*; +use crate::mail_ident::*; use crate::uidindex::*; +pub struct Summary { + pub validity: ImapUidvalidity, + pub next: ImapUid, + pub exists: usize, +} +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 { bucket: String, - name: String, + pub name: String, key: Key, k2v: K2vClient, @@ -20,7 +35,7 @@ pub struct Mailbox { } impl Mailbox { - pub async fn new(creds: &Credentials, name: String) -> Result<Self> { + pub fn new(creds: &Credentials, name: String) -> Result<Self> { let uid_index = Bayou::<UidIndex>::new(creds, name.clone())?; Ok(Self { @@ -33,6 +48,17 @@ impl Mailbox { }) } + pub async fn summary(&mut self) -> Result<Summary> { + self.uid_index.sync().await?; + let state = self.uid_index.state(); + + return Ok(Summary { + validity: state.uidvalidity, + next: state.uidnext, + exists: state.idx_by_uid.len(), + }); + } + pub async fn test(&mut self) -> Result<()> { self.uid_index.sync().await?; @@ -41,22 +67,22 @@ impl Mailbox { let add_mail_op = self .uid_index .state() - .op_mail_add(gen_uuid(), vec!["\\Unseen".into()]); + .op_mail_add(gen_ident(), vec!["\\Unseen".into()]); self.uid_index.push(add_mail_op).await?; dump(&self.uid_index); - if self.uid_index.state().mails_by_uid.len() > 6 { + if self.uid_index.state().idx_by_uid.len() > 6 { for i in 0..2 { - let (_, uuid) = self + let (_, ident) = self .uid_index .state() - .mails_by_uid + .idx_by_uid .iter() .skip(3 + i) .next() .unwrap(); - let del_mail_op = self.uid_index.state().op_mail_del(*uuid); + let del_mail_op = self.uid_index.state().op_mail_del(*ident); self.uid_index.push(del_mail_op).await?; dump(&self.uid_index); @@ -73,16 +99,12 @@ fn dump(uid_index: &Bayou<UidIndex>) { println!("UIDVALIDITY {}", s.uidvalidity); println!("UIDNEXT {}", s.uidnext); println!("INTERNALSEQ {}", s.internalseq); - for (uid, uuid) in s.mails_by_uid.iter() { + for (uid, ident) in s.idx_by_uid.iter() { println!( "{} {} {}", uid, - hex::encode(uuid.0), - s.mail_flags - .get(uuid) - .cloned() - .unwrap_or_default() - .join(", ") + hex::encode(ident.0), + s.table.get(ident).cloned().unwrap_or_default().1.join(", ") ); } println!(""); |