mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +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 anyhow::{bail, ensure, Context as _, Result};
|
||||
use async_std::fs;
|
||||
use chrono::TimeZone;
|
||||
use lettre_email::{mime, Address, Header, MimeMultipartType, PartBuilder};
|
||||
|
||||
@@ -1183,7 +1184,7 @@ impl<'a> MimeFactory<'a> {
|
||||
|
||||
if self.attach_selfavatar {
|
||||
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(
|
||||
"Chat-User-Avatar".into(),
|
||||
format!("base64:{}", avatar),
|
||||
@@ -1366,7 +1367,7 @@ async fn build_body_file(
|
||||
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 mail = PartBuilder::new()
|
||||
@@ -1378,9 +1379,9 @@ async fn build_body_file(
|
||||
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 body = std::fs::read(blob.to_abs_path())?;
|
||||
let body = fs::read(blob.to_abs_path()).await?;
|
||||
let encoded_body = wrapped_base64_encode(&body);
|
||||
Ok(encoded_body)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user