refactor: clean serializers

This commit is contained in:
Clément DOUIN
2026-03-31 16:55:21 +02:00
parent 8b868f6e0e
commit 6cde5dfe38
17 changed files with 159 additions and 486 deletions
+18 -1
View File
@@ -4,6 +4,7 @@ use io_jmap::rfc8621::coroutines::email_parse::{JmapEmailParse, JmapEmailParseRe
use io_stream::runtimes::std::handle;
use log::warn;
use pimalaya_toolbox::terminal::printer::Printer;
use serde::Serialize;
use crate::jmap::account::JmapAccount;
@@ -49,13 +50,15 @@ impl ParseEmailCommand {
warn!("blob `{id}` not valid MIME message, ignoring it");
}
let mut bodies = Vec::new();
for (_blob_id, email) in parsed {
if let Some(body_values) = &email.body_values {
if let Some(text_parts) = &email.text_body {
for part in text_parts {
if let Some(part_id) = &part.part_id {
if let Some(body_value) = body_values.get(part_id) {
printer.out(&body_value.value)?;
bodies.push(body_value.value.clone());
}
}
}
@@ -63,6 +66,20 @@ impl ParseEmailCommand {
}
}
printer.out(ParsedBodies { bodies })
}
}
#[derive(Serialize)]
struct ParsedBodies {
bodies: Vec<String>,
}
impl std::fmt::Display for ParsedBodies {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for body in &self.bodies {
write!(f, "{body}")?;
}
Ok(())
}
}