mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 21:37:55 +08:00
refactor: clean serializers
This commit is contained in:
+18
-1
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user