mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-16 20:57:53 +08:00
refactor: clean serializers
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use clap::Parser;
|
||||
use io_jmap::{
|
||||
rfc8620::coroutines::blob_download::{JmapBlobDownload, JmapBlobDownloadResult},
|
||||
rfc8620::types::session::capabilities,
|
||||
rfc8620::{
|
||||
coroutines::blob_download::{JmapBlobDownload, JmapBlobDownloadResult},
|
||||
types::session::capabilities::{self, MAIL},
|
||||
},
|
||||
rfc8621::coroutines::email_get::{JmapEmailGet, JmapEmailGetResult},
|
||||
};
|
||||
use io_stream::runtimes::std::handle;
|
||||
@@ -52,7 +54,7 @@ impl ExportEmailCommand {
|
||||
let account_id = jmap
|
||||
.session
|
||||
.primary_accounts
|
||||
.get(capabilities::MAIL)
|
||||
.get(MAIL)
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or("");
|
||||
let blob_id = emails
|
||||
|
||||
@@ -6,10 +6,14 @@ use std::{
|
||||
use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
use io_jmap::{
|
||||
rfc8620::coroutines::blob_upload::{JmapBlobUpload, JmapBlobUploadResult},
|
||||
rfc8620::types::session::capabilities,
|
||||
rfc8621::coroutines::email_import::{JmapEmailImport, JmapEmailImportResult},
|
||||
rfc8621::types::email::EmailImport,
|
||||
rfc8620::{
|
||||
coroutines::blob_upload::{JmapBlobUpload, JmapBlobUploadResult},
|
||||
types::session::capabilities::{self, MAIL},
|
||||
},
|
||||
rfc8621::{
|
||||
coroutines::email_import::{JmapEmailImport, JmapEmailImportResult},
|
||||
types::email::EmailImport,
|
||||
},
|
||||
};
|
||||
use io_stream::runtimes::std::handle;
|
||||
use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
@@ -64,7 +68,7 @@ impl ImportEmailCommand {
|
||||
let account_id = jmap
|
||||
.session
|
||||
.primary_accounts
|
||||
.get(capabilities::MAIL)
|
||||
.get(MAIL)
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or("");
|
||||
let url: Url = jmap
|
||||
|
||||
+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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,6 @@ impl JmapEmailQueryCommand {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct EmailsTable {
|
||||
#[serde(skip)]
|
||||
pub preset: String,
|
||||
|
||||
Reference in New Issue
Block a user