Skip to content

Commit 532d591

Browse files
committed
refactor: build_body_file(): Remove guessing mimetype by file extension
Guessing mimetype is already done in `chat::prepare_msg_blob()`.
1 parent f84bb3e commit 532d591

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/mimefactory.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::e2ee::EncryptHelper;
2525
use crate::ephemeral::Timer as EphemeralTimer;
2626
use crate::key::DcKey;
2727
use crate::location;
28-
use crate::message::{self, Message, MsgId, Viewtype};
28+
use crate::message::{Message, MsgId, Viewtype};
2929
use crate::mimeparser::{is_hidden, SystemMessage};
3030
use crate::param::Param;
3131
use crate::peer_channels::create_iroh_header;
@@ -1725,18 +1725,11 @@ async fn build_body_file(context: &Context, msg: &Message) -> Result<MimePart<'s
17251725
_ => file_name,
17261726
};
17271727

1728-
/* check mimetype */
1729-
let mimetype = match msg.param.get(Param::MimeType) {
1730-
Some(mtype) => mtype.to_string(),
1731-
None => {
1732-
if let Some((_viewtype, res)) = message::guess_msgtype_from_suffix(msg) {
1733-
res.to_string()
1734-
} else {
1735-
"application/octet-stream".to_string()
1736-
}
1737-
}
1738-
};
1739-
1728+
let mimetype = msg
1729+
.param
1730+
.get(Param::MimeType)
1731+
.unwrap_or("application/octet-stream")
1732+
.to_string();
17401733
let body = fs::read(blob.to_abs_path()).await?;
17411734

17421735
// create mime part, for Content-Disposition, see RFC 2183.

src/mimefactory/mimefactory_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::chatlist::Chatlist;
1212
use crate::constants;
1313
use crate::contact::Origin;
1414
use crate::headerdef::HeaderDef;
15+
use crate::message;
1516
use crate::mimeparser::MimeMessage;
1617
use crate::receive_imf::receive_imf;
1718
use crate::test_utils::{get_chat_msg, TestContext, TestContextManager};

0 commit comments

Comments
 (0)