Correctly count lines + bytes

This commit is contained in:
Quentin 2022-07-07 16:30:53 +02:00
parent 0030a4d8b7
commit e10d3987e2
Signed by: quentin
GPG Key ID: E9602264D639FF68
3 changed files with 14 additions and 8 deletions

2
Cargo.lock generated
View File

@ -1335,7 +1335,7 @@ dependencies = [
[[package]]
name = "mail-parser"
version = "0.4.8"
source = "git+https://github.com/superboum/mail-parser?branch=feature/last_part_offset#c227527d2613d33ea1342f85c635134134222736"
source = "git+https://github.com/superboum/mail-parser?branch=feature/no_decode#0fe5fe071f25016d9c1232eb452c0c4bbfa8a445"
dependencies = [
"encoding_rs",
"serde",

View File

@ -20,7 +20,7 @@ itertools = "0.10"
lazy_static = "1.4"
ldap3 = { version = "0.10", default-features = false, features = ["tls"] }
log = "0.4"
mail-parser = { git = "https://github.com/superboum/mail-parser", branch = "feature/last_part_offset" }
mail-parser = { git = "https://github.com/superboum/mail-parser", branch = "feature/no_decode" }
pretty_env_logger = "0.4"
rusoto_core = "0.48.0"
rusoto_credential = "0.48.0"

View File

@ -568,7 +568,7 @@ fn build_imap_email_struct<'a>(
specific: SpecificFields::Text {
subtype,
number_of_lines: u32::try_from(
bp.get_text_contents().lines().count(),
Cursor::new(bp.body_raw.as_ref()).lines().count(),
)?,
},
},
@ -785,9 +785,7 @@ fn attrs_to_params<'a>(bp: &impl MimeHeaders<'a>) -> (SpecialAttrs, Vec<(IString
/// Takes mail-parser headers and build imap-codec BasicFields
/// Return some special informations too
fn headers_to_basic_fields<'a>(
bp: &(impl BodyPart<'a> + MimeHeaders<'a>),
) -> Result<(SpecialAttrs, BasicFields)> {
fn headers_to_basic_fields<'a, T>(bp: &'a Part<T>) -> Result<(SpecialAttrs<'a>, BasicFields)> {
let (attrs, parameter_list) = attrs_to_params(bp);
let bf = BasicFields {
@ -816,7 +814,7 @@ fn headers_to_basic_fields<'a>(
.flatten()
.unwrap_or(unchecked_istring("7bit")),
size: u32::try_from(bp.len())?,
size: u32::try_from(bp.body_raw.len())?,
};
Ok((attrs, bf))
@ -839,7 +837,15 @@ mod tests {
"tests/emails/dxflrs/0002_mime",
"tests/emails/dxflrs/0003_mime-in-mime",
"tests/emails/dxflrs/0004_msg-in-msg",
"tests/emails/dxflrs/0005_mail-parser-readme", // broken
//"tests/emails/dxflrs/0005_mail-parser-readme", // no consensus on how to parse
//"tests/emails/rfc/000", // broken
//"tests/emails/rfc/001", // broken
//"tests/emails/rfc/002", // broken: dovecot adds \r when it is missing and count is as
// a character. Difference on how lines are counted too.
//"tests/emails/rfc/003", // broken for the same reason
//"tests/emails/thirdparty/000",
//"tests/emails/thirdparty/001",
//"tests/emails/thirdparty/002",
];
for pref in prefixes.iter() {