aboutsummaryrefslogtreecommitdiff
path: root/src/mail
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail')
-rw-r--r--src/mail/incoming.rs44
-rw-r--r--src/mail/mailbox.rs60
-rw-r--r--src/mail/mod.rs2
-rw-r--r--src/mail/uidindex.rs8
-rw-r--r--src/mail/user.rs24
5 files changed, 79 insertions, 59 deletions
diff --git a/src/mail/incoming.rs b/src/mail/incoming.rs
index 26ca52a..290f1b3 100644
--- a/src/mail/incoming.rs
+++ b/src/mail/incoming.rs
@@ -68,7 +68,7 @@ async fn incoming_mail_watch_process_internal(
let wait_new_mail = async {
loop {
- match k2v_wait_value_changed(&k2v, &INCOMING_PK, &INCOMING_WATCH_SK, &prev_ct)
+ match k2v_wait_value_changed(&k2v, INCOMING_PK, INCOMING_WATCH_SK, &prev_ct)
.await
{
Ok(cv) => break cv,
@@ -104,7 +104,7 @@ async fn incoming_mail_watch_process_internal(
info!("User still available");
// If INBOX no longer is same mailbox, open new mailbox
- let inbox_id = rx_inbox_id.borrow().clone();
+ let inbox_id = *rx_inbox_id.borrow();
if let Some((id, uidvalidity)) = inbox_id {
if Some(id) != inbox.as_ref().map(|b| b.id) {
match user.open_mailbox_by_id(id, uidvalidity).await {
@@ -145,10 +145,12 @@ async fn handle_incoming_mail(
inbox: &Arc<Mailbox>,
lock_held: &watch::Receiver<bool>,
) -> Result<()> {
- let mut lor = ListObjectsV2Request::default();
- lor.bucket = user.creds.storage.bucket.clone();
- lor.max_keys = Some(1000);
- lor.prefix = Some("incoming/".into());
+ let lor = ListObjectsV2Request {
+ bucket: user.creds.storage.bucket.clone(),
+ max_keys: Some(1000),
+ prefix: Some("incoming/".into()),
+ ..Default::default()
+ };
let mails_res = s3.list_objects_v2(lor).await?;
for object in mails_res.contents.unwrap_or_default() {
@@ -178,9 +180,11 @@ async fn move_incoming_message(
let object_key = format!("incoming/{}", id);
// 1. Fetch message from S3
- let mut gor = GetObjectRequest::default();
- gor.bucket = user.creds.storage.bucket.clone();
- gor.key = object_key.clone();
+ let gor = GetObjectRequest {
+ bucket: user.creds.storage.bucket.clone(),
+ key: object_key.clone(),
+ ..Default::default()
+ };
let get_result = s3.get_object(gor).await?;
// 1.a decrypt message key from headers
@@ -218,9 +222,11 @@ async fn move_incoming_message(
.await?;
// 3 delete from incoming
- let mut dor = DeleteObjectRequest::default();
- dor.bucket = user.creds.storage.bucket.clone();
- dor.key = object_key.clone();
+ let dor = DeleteObjectRequest {
+ bucket: user.creds.storage.bucket.clone(),
+ key: object_key.clone(),
+ ..Default::default()
+ };
s3.delete_object(dor).await?;
Ok(())
@@ -441,15 +447,17 @@ impl EncryptedMessage {
sodiumoxide::crypto::sealedbox::seal(self.key.as_ref(), &creds.public_key);
let key_header = base64::encode(&encrypted_key);
- let mut por = PutObjectRequest::default();
- por.bucket = creds.storage.bucket.clone();
- por.key = format!("incoming/{}", gen_ident().to_string());
- por.metadata = Some(
+ let por = PutObjectRequest {
+ bucket: creds.storage.bucket.clone(),
+ key: format!("incoming/{}", gen_ident()),
+ metadata: Some(
[(MESSAGE_KEY.to_string(), key_header)]
.into_iter()
.collect::<HashMap<_, _>>(),
- );
- por.body = Some(self.encrypted_body.clone().into());
+ ),
+ body: Some(self.encrypted_body.clone().into()),
+ ..Default::default()
+ };
s3_client.put_object(por).await?;
// Update watch key to signal new mail
diff --git a/src/mail/mailbox.rs b/src/mail/mailbox.rs
index a37c9ed..445dcfd 100644
--- a/src/mail/mailbox.rs
+++ b/src/mail/mailbox.rs
@@ -156,6 +156,7 @@ impl Mailbox {
/// Move an email from an other Mailbox to this mailbox
/// (use this when possible, as it allows for a certain number of storage optimizations)
+ #[allow(dead_code)]
pub async fn move_from(&self, from: &Mailbox, uuid: UniqueIdent) -> Result<()> {
if self.id == from.id {
bail!("Cannot copy move same mailbox");
@@ -178,6 +179,8 @@ impl Mailbox {
// Non standard but common flags:
// https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
struct MailboxInternal {
+ // 2023-05-15 will probably be used later.
+ #[allow(dead_code)]
id: UniqueIdent,
bucket: String,
mail_path: String,
@@ -256,9 +259,11 @@ impl MailboxInternal {
}
async fn fetch_full(&self, id: UniqueIdent, message_key: &Key) -> Result<Vec<u8>> {
- let mut gor = GetObjectRequest::default();
- gor.bucket = self.bucket.clone();
- gor.key = format!("{}/{}", self.mail_path, id);
+ let gor = GetObjectRequest {
+ bucket: self.bucket.clone(),
+ key: format!("{}/{}", self.mail_path, id),
+ ..Default::default()
+ };
let obj_res = self.s3.get_object(gor).await?;
@@ -266,7 +271,7 @@ impl MailboxInternal {
let mut buf = Vec::with_capacity(obj_res.content_length.unwrap_or(128) as usize);
obj_body.into_async_read().read_to_end(&mut buf).await?;
- Ok(cryptoblob::open(&buf, &message_key)?)
+ cryptoblob::open(&buf, message_key)
}
// ---- Functions for changing the mailbox ----
@@ -292,17 +297,19 @@ impl MailboxInternal {
ident: Option<UniqueIdent>,
flags: &[Flag],
) -> Result<(ImapUidvalidity, ImapUid)> {
- let ident = ident.unwrap_or_else(|| gen_ident());
+ let ident = ident.unwrap_or_else(gen_ident);
let message_key = gen_key();
futures::try_join!(
async {
// Encrypt and save mail body
let message_blob = cryptoblob::seal(mail.raw, &message_key)?;
- let mut por = PutObjectRequest::default();
- por.bucket = self.bucket.clone();
- por.key = format!("{}/{}", self.mail_path, ident);
- por.body = Some(message_blob.into());
+ let por = PutObjectRequest {
+ bucket: self.bucket.clone(),
+ key: format!("{}/{}", self.mail_path, ident),
+ body: Some(message_blob.into()),
+ ..Default::default()
+ };
self.s3.put_object(por).await?;
Ok::<_, anyhow::Error>(())
},
@@ -349,11 +356,13 @@ impl MailboxInternal {
futures::try_join!(
async {
// Copy mail body from previous location
- let mut cor = CopyObjectRequest::default();
- cor.bucket = self.bucket.clone();
- cor.key = format!("{}/{}", self.mail_path, ident);
- cor.copy_source = format!("{}/{}", self.bucket, s3_key);
- cor.metadata_directive = Some("REPLACE".into());
+ let cor = CopyObjectRequest {
+ bucket: self.bucket.clone(),
+ key: format!("{}/{}", self.mail_path, ident),
+ copy_source: format!("{}/{}", self.bucket, s3_key),
+ metadata_directive: Some("REPLACE".into()),
+ ..Default::default()
+ };
self.s3.copy_object(cor).await?;
Ok::<_, anyhow::Error>(())
},
@@ -393,9 +402,11 @@ impl MailboxInternal {
futures::try_join!(
async {
// Delete mail body from S3
- let mut dor = DeleteObjectRequest::default();
- dor.bucket = self.bucket.clone();
- dor.key = format!("{}/{}", self.mail_path, ident);
+ let dor = DeleteObjectRequest{
+ bucket: self.bucket.clone(),
+ key: format!("{}/{}", self.mail_path, ident),
+ ..Default::default()
+ };
self.s3.delete_object(dor).await?;
Ok::<_, anyhow::Error>(())
},
@@ -422,6 +433,8 @@ impl MailboxInternal {
Ok(new_id)
}
+ #[allow(dead_code)]
+ // 2023-05-15 will probably be used later
async fn move_from(&mut self, from: &mut MailboxInternal, id: UniqueIdent) -> Result<()> {
self.copy_internal(from, id, id).await?;
from.delete(id).await?;
@@ -450,10 +463,13 @@ impl MailboxInternal {
futures::try_join!(
async {
// Copy mail body from S3
- let mut cor = CopyObjectRequest::default();
- cor.bucket = self.bucket.clone();
- cor.key = format!("{}/{}", self.mail_path, new_id);
- cor.copy_source = format!("{}/{}/{}", from.bucket, from.mail_path, source_id);
+ let cor = CopyObjectRequest{
+ bucket: self.bucket.clone(),
+ key: format!("{}/{}", self.mail_path, new_id),
+ copy_source: format!("{}/{}/{}", from.bucket, from.mail_path, source_id),
+ ..Default::default()
+ };
+
self.s3.copy_object(cor).await?;
Ok::<_, anyhow::Error>(())
},
@@ -491,7 +507,7 @@ fn dump(uid_index: &Bayou<UidIndex>) {
s.table.get(ident).cloned().unwrap().1.join(", ")
);
}
- println!("");
+ println!();
}
// ----
diff --git a/src/mail/mod.rs b/src/mail/mod.rs
index 3b0ae73..80c348a 100644
--- a/src/mail/mod.rs
+++ b/src/mail/mod.rs
@@ -9,6 +9,8 @@ pub mod user;
// Internet Message Format
// aka RFC 822 - RFC 2822 - RFC 5322
+// 2023-05-15 don't want to refactor this struct now.
+#[allow(clippy::upper_case_acronyms)]
pub struct IMF<'a> {
raw: &'a [u8],
parsed: mail_parser::Message<'a>,
diff --git a/src/mail/uidindex.rs b/src/mail/uidindex.rs
index 43d6507..956b194 100644
--- a/src/mail/uidindex.rs
+++ b/src/mail/uidindex.rs
@@ -73,9 +73,9 @@ impl UidIndex {
// INTERNAL functions to keep state consistent
- fn reg_email(&mut self, ident: UniqueIdent, uid: ImapUid, flags: &Vec<Flag>) {
+ fn reg_email(&mut self, ident: UniqueIdent, uid: ImapUid, flags: &[Flag]) {
// Insert the email in our table
- self.table.insert(ident, (uid, flags.clone()));
+ self.table.insert(ident, (uid, flags.to_owned()));
// Update the indexes/caches
self.idx_by_uid.insert(uid, ident);
@@ -205,7 +205,7 @@ impl FlagIndex {
fn new() -> Self {
Self(HashMap::new())
}
- fn insert(&mut self, uid: ImapUid, flags: &Vec<Flag>) {
+ fn insert(&mut self, uid: ImapUid, flags: &[Flag]) {
flags.iter().for_each(|flag| {
self.0
.entry(flag.clone())
@@ -213,7 +213,7 @@ impl FlagIndex {
.insert(uid);
});
}
- fn remove(&mut self, uid: ImapUid, flags: &Vec<Flag>) -> () {
+ fn remove(&mut self, uid: ImapUid, flags: &[Flag]) {
for flag in flags.iter() {
if let Some(set) = self.0.get_mut(flag) {
set.remove(&uid);
diff --git a/src/mail/user.rs b/src/mail/user.rs
index d921e6d..44e0081 100644
--- a/src/mail/user.rs
+++ b/src/mail/user.rs
@@ -257,7 +257,7 @@ impl User {
let saved;
let (inbox_id, inbox_uidvalidity) = match list.create_mailbox(INBOX) {
CreatedMailbox::Created(i, v) => {
- self.save_mailbox_list(&list, ct.clone()).await?;
+ self.save_mailbox_list(list, ct.clone()).await?;
saved = true;
(i, v)
}
@@ -334,23 +334,17 @@ impl MailboxList {
}
fn has_mailbox(&self, name: &str) -> bool {
- match self.0.get(name) {
- Some(MailboxListEntry {
- id_lww: (_, Some(_)),
- ..
- }) => true,
- _ => false,
- }
+ matches!(self.0.get(name), Some(MailboxListEntry {
+ id_lww: (_, Some(_)),
+ ..
+ }))
}
fn get_mailbox(&self, name: &str) -> Option<(ImapUidvalidity, Option<UniqueIdent>)> {
- match self.0.get(name) {
- None => None,
- Some(MailboxListEntry {
- id_lww: (_, mailbox_id),
- uidvalidity,
- }) => Some((*uidvalidity, *mailbox_id)),
- }
+ self.0.get(name).map(|MailboxListEntry {
+ id_lww: (_, mailbox_id),
+ uidvalidity,
+ }| (*uidvalidity, *mailbox_id))
}
/// Ensures mailbox `name` maps to id `id`.