reformat mailbox.rs and add security
This commit is contained in:
parent
0048b43f27
commit
69428eaf25
1 changed files with 22 additions and 8 deletions
|
@ -1,7 +1,9 @@
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use k2v_client::K2vClient;
|
use k2v_client::K2vClient;
|
||||||
use k2v_client::{BatchReadOp, Filter, K2vValue};
|
use k2v_client::{BatchReadOp, Filter, K2vValue};
|
||||||
use rusoto_s3::{CopyObjectRequest, DeleteObjectRequest, GetObjectRequest, PutObjectRequest, S3Client, S3};
|
use rusoto_s3::{
|
||||||
|
CopyObjectRequest, DeleteObjectRequest, GetObjectRequest, PutObjectRequest, S3Client, S3,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
@ -303,9 +305,24 @@ impl MailboxInternal {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn copy_internal(&mut self, from: &MailboxInternal, source_id: UniqueIdent, new_id: UniqueIdent) -> Result<()> {
|
async fn copy_internal(
|
||||||
let flags = from.uid_index.state()
|
&mut self,
|
||||||
.table.get(&source_id).ok_or(anyhow!("Source mail not found"))?.1.clone();
|
from: &MailboxInternal,
|
||||||
|
source_id: UniqueIdent,
|
||||||
|
new_id: UniqueIdent,
|
||||||
|
) -> Result<()> {
|
||||||
|
if self.bucket != from.bucket || self.encryption_key != from.encryption_key {
|
||||||
|
bail!("Message to be copied/moved does not belong to same account.");
|
||||||
|
}
|
||||||
|
|
||||||
|
let flags = from
|
||||||
|
.uid_index
|
||||||
|
.state()
|
||||||
|
.table
|
||||||
|
.get(&source_id)
|
||||||
|
.ok_or(anyhow!("Source mail not found"))?
|
||||||
|
.1
|
||||||
|
.clone();
|
||||||
|
|
||||||
futures::try_join!(
|
futures::try_join!(
|
||||||
async {
|
async {
|
||||||
|
@ -329,10 +346,7 @@ impl MailboxInternal {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Add mail to Bayou mail index
|
// Add mail to Bayou mail index
|
||||||
let add_mail_op = self
|
let add_mail_op = self.uid_index.state().op_mail_add(new_id, flags);
|
||||||
.uid_index
|
|
||||||
.state()
|
|
||||||
.op_mail_add(new_id, flags);
|
|
||||||
self.uid_index.push(add_mail_op).await?;
|
self.uid_index.push(add_mail_op).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue