mirror of
https://gitlab.com/mailcat-devs/mailcat.git
synced 2025-12-20 09:53:26 +01:00
Use mime crate
This commit is contained in:
parent
e046318a2e
commit
19981b4671
3 changed files with 13 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -176,6 +176,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"clap",
|
||||
"mailparse",
|
||||
"mime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -189,6 +190,12 @@ dependencies = [
|
|||
"quoted_printable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
|
|
|
|||
|
|
@ -12,3 +12,4 @@ anyhow = "1.0.42"
|
|||
chrono = "0.4.19"
|
||||
clap = { version = "3.0.0-beta.2", features = ["derive"] }
|
||||
mailparse = "0.13.5"
|
||||
mime = "0.3.16"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use mailparse::{DispositionType, MailParseError, ParsedMail};
|
||||
use mailparse::{DispositionType, ParsedMail};
|
||||
|
||||
pub trait ParsedMailEx {
|
||||
fn is_attachment(&self) -> bool;
|
||||
|
||||
fn get_body_text(&self) -> Result<Option<String>, MailParseError>;
|
||||
fn get_body_text(&self) -> Result<Option<String>, anyhow::Error>;
|
||||
}
|
||||
|
||||
impl<'a> ParsedMailEx for ParsedMail<'a> {
|
||||
|
|
@ -11,11 +11,12 @@ impl<'a> ParsedMailEx for ParsedMail<'a> {
|
|||
self.get_content_disposition().disposition == DispositionType::Attachment
|
||||
}
|
||||
|
||||
fn get_body_text(&self) -> Result<Option<String>, MailParseError> {
|
||||
fn get_body_text(&self) -> Result<Option<String>, anyhow::Error> {
|
||||
let mimetype: mime::Mime = self.ctype.mimetype.parse()?;
|
||||
if self.is_attachment() {
|
||||
return Ok(None);
|
||||
}
|
||||
if self.ctype.mimetype == "text/plain" {
|
||||
if mimetype == mime::TEXT_PLAIN {
|
||||
return Ok(Some(self.get_body()?));
|
||||
}
|
||||
for subpart in &self.subparts {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue