mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
mimefactory: use async_std instead of std
Read files asynchronously to avoid blocking threads.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use anyhow::{bail, ensure, Context as _, Result};
|
use anyhow::{bail, ensure, Context as _, Result};
|
||||||
|
use async_std::fs;
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use lettre_email::{mime, Address, Header, MimeMultipartType, PartBuilder};
|
use lettre_email::{mime, Address, Header, MimeMultipartType, PartBuilder};
|
||||||
|
|
||||||
@@ -1183,7 +1184,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
|
|
||||||
if self.attach_selfavatar {
|
if self.attach_selfavatar {
|
||||||
match context.get_config(Config::Selfavatar).await? {
|
match context.get_config(Config::Selfavatar).await? {
|
||||||
Some(path) => match build_selfavatar_file(context, &path) {
|
Some(path) => match build_selfavatar_file(context, &path).await {
|
||||||
Ok(avatar) => headers.hidden.push(Header::new(
|
Ok(avatar) => headers.hidden.push(Header::new(
|
||||||
"Chat-User-Avatar".into(),
|
"Chat-User-Avatar".into(),
|
||||||
format!("base64:{}", avatar),
|
format!("base64:{}", avatar),
|
||||||
@@ -1366,7 +1367,7 @@ async fn build_body_file(
|
|||||||
maybe_encode_words(&filename_to_send)
|
maybe_encode_words(&filename_to_send)
|
||||||
);
|
);
|
||||||
|
|
||||||
let body = std::fs::read(blob.to_abs_path())?;
|
let body = fs::read(blob.to_abs_path()).await?;
|
||||||
let encoded_body = wrapped_base64_encode(&body);
|
let encoded_body = wrapped_base64_encode(&body);
|
||||||
|
|
||||||
let mail = PartBuilder::new()
|
let mail = PartBuilder::new()
|
||||||
@@ -1378,9 +1379,9 @@ async fn build_body_file(
|
|||||||
Ok((mail, filename_to_send))
|
Ok((mail, filename_to_send))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_selfavatar_file(context: &Context, path: &str) -> Result<String> {
|
async fn build_selfavatar_file(context: &Context, path: &str) -> Result<String> {
|
||||||
let blob = BlobObject::from_path(context, path.as_ref())?;
|
let blob = BlobObject::from_path(context, path.as_ref())?;
|
||||||
let body = std::fs::read(blob.to_abs_path())?;
|
let body = fs::read(blob.to_abs_path()).await?;
|
||||||
let encoded_body = wrapped_base64_encode(&body);
|
let encoded_body = wrapped_base64_encode(&body);
|
||||||
Ok(encoded_body)
|
Ok(encoded_body)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user