aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-07-07 16:30:53 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-07-07 16:30:53 +0200
commite10d3987e2d84ef8499bb41910e129db2a9c2b9a (patch)
tree7d5a5325445a4d57f0a44bb5c5f89e298ac42812
parent0030a4d8b7c09b45ea7320236d8755792c7ba35b (diff)
downloadaerogramme-e10d3987e2d84ef8499bb41910e129db2a9c2b9a.tar.gz
aerogramme-e10d3987e2d84ef8499bb41910e129db2a9c2b9a.zip
Correctly count lines + bytes
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/imap/mailbox_view.rs18
3 files changed, 14 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d21e88b..b2d5365 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index 3f16605..5398f34 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/imap/mailbox_view.rs b/src/imap/mailbox_view.rs
index 0a83984..29fb98a 100644
--- a/src/imap/mailbox_view.rs
+++ b/src/imap/mailbox_view.rs
@@ -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() {