mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
clean part 1
This commit is contained in:
+11
-11
@@ -3,7 +3,7 @@ use clap::Subcommand;
|
||||
use pimalaya_cli::printer::Printer;
|
||||
|
||||
use crate::jmap::{
|
||||
account::JmapAccount,
|
||||
client::JmapClient,
|
||||
email::{
|
||||
copy::JmapEmailCopyCommand, delete::JmapEmailDestroyCommand,
|
||||
export::JmapEmailExportCommand, get::JmapEmailGetCommand, import::JmapEmailImportCommand,
|
||||
@@ -30,17 +30,17 @@ pub enum JmapEmailCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
pub fn execute(self, printer: &mut impl Printer, client: JmapClient) -> Result<()> {
|
||||
match self {
|
||||
Self::Get(cmd) => cmd.execute(printer, account),
|
||||
Self::Query(cmd) => cmd.execute(printer, account),
|
||||
Self::Read(cmd) => cmd.execute(printer, account),
|
||||
Self::Update(cmd) => cmd.execute(printer, account),
|
||||
Self::Delete(cmd) => cmd.execute(printer, account),
|
||||
Self::Copy(cmd) => cmd.execute(printer, account),
|
||||
Self::Export(cmd) => cmd.execute(printer, account),
|
||||
Self::Import(cmd) => cmd.execute(printer, account),
|
||||
Self::Parse(cmd) => cmd.execute(printer, account),
|
||||
Self::Get(cmd) => cmd.execute(printer, client),
|
||||
Self::Query(cmd) => cmd.execute(printer, client),
|
||||
Self::Read(cmd) => cmd.execute(printer, client),
|
||||
Self::Update(cmd) => cmd.execute(printer, client),
|
||||
Self::Delete(cmd) => cmd.execute(printer, client),
|
||||
Self::Copy(cmd) => cmd.execute(printer, client),
|
||||
Self::Export(cmd) => cmd.execute(printer, client),
|
||||
Self::Import(cmd) => cmd.execute(printer, client),
|
||||
Self::Parse(cmd) => cmd.execute(printer, client),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use clap::Parser;
|
||||
use io_jmap::rfc8621::email::EmailCopy;
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
|
||||
use crate::jmap::{account::JmapAccount, error::format_set_error};
|
||||
use crate::jmap::{client::JmapClient, error::format_set_error};
|
||||
|
||||
/// Copy JMAP emails from another account (Email/copy).
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -24,9 +24,7 @@ pub struct JmapEmailCopyCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailCopyCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let mailbox_ids: BTreeMap<String, bool> =
|
||||
self.mailbox_id.into_iter().map(|m| (m, true)).collect();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use clap::Parser;
|
||||
use io_jmap::rfc8621::email_set::JmapEmailSetArgs;
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
|
||||
use crate::jmap::{account::JmapAccount, error::format_set_error};
|
||||
use crate::jmap::{client::JmapClient, error::format_set_error};
|
||||
|
||||
/// Delete JMAP emails (Email/set destroy).
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -14,8 +14,7 @@ pub struct JmapEmailDestroyCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailDestroyCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let mut args = JmapEmailSetArgs::default();
|
||||
|
||||
for id in self.ids {
|
||||
|
||||
@@ -2,13 +2,13 @@ use std::net::TcpStream;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::Parser;
|
||||
use io_jmap::{client::JmapClient, rfc8621::capabilities::MAIL};
|
||||
use io_jmap::{client::JmapClient as InnerJmapClient, rfc8621::capabilities::MAIL};
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
use pimalaya_stream::tls::upgrade_tls;
|
||||
use pimalaya_stream::std::tls::upgrade_tls;
|
||||
use secrecy::SecretString;
|
||||
use url::Url;
|
||||
|
||||
use crate::jmap::{account::JmapAccount, session::JmapAuth};
|
||||
use crate::jmap::{client::JmapClient, session::JmapAuth};
|
||||
|
||||
/// Export a raw RFC 5322 message to stdout (Email/get + blob download).
|
||||
///
|
||||
@@ -21,13 +21,11 @@ pub struct JmapEmailExportCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailExportCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let tls = account.backend.tls.clone().try_into()?;
|
||||
let auth: JmapAuth = account.backend.auth.clone().try_into()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let tls = client.config.tls.clone().try_into()?;
|
||||
let auth: JmapAuth = client.config.auth.clone().try_into()?;
|
||||
let http_auth: SecretString = auth.into();
|
||||
|
||||
let mut client = account.new_jmap_client()?;
|
||||
|
||||
let properties = Some(vec!["id".to_owned(), "blobId".to_owned()]);
|
||||
let output = client.email_get(vec![self.id.clone()], properties, false, false, 0)?;
|
||||
|
||||
@@ -61,7 +59,7 @@ impl JmapEmailExportCommand {
|
||||
let port = download_url.port_or_known_default().unwrap_or(443);
|
||||
let tcp = TcpStream::connect((host, port))?;
|
||||
let stream = upgrade_tls(host, tcp, &tls, &[b"http/1.1"])?;
|
||||
let mut download_client = JmapClient::new(stream, http_auth);
|
||||
let mut download_client = InnerJmapClient::new(stream, http_auth);
|
||||
download_client.blob_download(&download_url)?
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use clap::Parser;
|
||||
use log::warn;
|
||||
use pimalaya_cli::printer::Printer;
|
||||
|
||||
use crate::jmap::{account::JmapAccount, email::query::EmailsTable};
|
||||
use crate::jmap::{client::JmapClient, email::query::EmailsTable};
|
||||
|
||||
/// Get JMAP emails by ID (Email/get).
|
||||
///
|
||||
@@ -16,8 +16,7 @@ pub struct JmapEmailGetCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailGetCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let output = client.email_get(self.ids.clone(), None, false, false, 0)?;
|
||||
|
||||
for id in output.not_found {
|
||||
@@ -25,8 +24,8 @@ impl JmapEmailGetCommand {
|
||||
}
|
||||
|
||||
let table = EmailsTable {
|
||||
preset: account.table_preset,
|
||||
arrangement: account.table_arrangement,
|
||||
preset: client.account.table_preset().to_string(),
|
||||
arrangement: client.account.table_arrangement(),
|
||||
emails: output.emails,
|
||||
};
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@ use std::{
|
||||
use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
use io_jmap::{
|
||||
client::JmapClient,
|
||||
client::JmapClient as InnerJmapClient,
|
||||
rfc8621::{capabilities::MAIL, email::EmailImport},
|
||||
};
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
use pimalaya_stream::tls::upgrade_tls;
|
||||
use pimalaya_stream::std::tls::upgrade_tls;
|
||||
use secrecy::SecretString;
|
||||
use url::Url;
|
||||
|
||||
use crate::jmap::{account::JmapAccount, error::format_set_error, session::JmapAuth};
|
||||
use crate::jmap::{client::JmapClient, error::format_set_error, session::JmapAuth};
|
||||
|
||||
/// Import an RFC 5322 message into a mailbox (upload + Email/import).
|
||||
///
|
||||
@@ -46,13 +46,11 @@ pub struct JmapEmailImportCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailImportCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let tls = account.backend.tls.clone().try_into()?;
|
||||
let auth: JmapAuth = account.backend.auth.clone().try_into()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let tls = client.config.tls.clone().try_into()?;
|
||||
let auth: JmapAuth = client.config.auth.clone().try_into()?;
|
||||
let http_auth: SecretString = auth.into();
|
||||
|
||||
let mut client = account.new_jmap_client()?;
|
||||
|
||||
let data: Vec<u8> = if stdin().is_terminal() || printer.is_json() {
|
||||
self.message
|
||||
.join(" ")
|
||||
@@ -85,7 +83,7 @@ impl JmapEmailImportCommand {
|
||||
let port = upload_url.port_or_known_default().unwrap_or(443);
|
||||
let tcp = TcpStream::connect((host, port))?;
|
||||
let stream = upgrade_tls(host, tcp, &tls, &[b"http/1.1"])?;
|
||||
let mut upload_client = JmapClient::new(stream, http_auth);
|
||||
let mut upload_client = InnerJmapClient::new(stream, http_auth);
|
||||
upload_client
|
||||
.blob_upload(&upload_url, "message/rfc822", data)?
|
||||
.blob_id
|
||||
|
||||
@@ -4,7 +4,7 @@ use log::warn;
|
||||
use pimalaya_cli::printer::Printer;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::jmap::account::JmapAccount;
|
||||
use crate::jmap::client::JmapClient;
|
||||
|
||||
/// Parse RFC 5322 message blobs without storing them (Email/parse).
|
||||
///
|
||||
@@ -18,8 +18,7 @@ pub struct JmapEmailParseCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailParseCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let output = client.email_parse(self.blob_ids.clone(), None)?;
|
||||
|
||||
for id in output.not_found {
|
||||
|
||||
@@ -9,7 +9,7 @@ use io_jmap::rfc8621::email::{
|
||||
use pimalaya_cli::printer::Printer;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::jmap::account::JmapAccount;
|
||||
use crate::jmap::client::JmapClient;
|
||||
|
||||
/// Query JMAP emails (Email/query + Email/get).
|
||||
///
|
||||
@@ -86,9 +86,7 @@ pub struct JmapEmailQueryCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailQueryCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let filter = {
|
||||
let f = EmailFilter {
|
||||
in_mailbox: self.mailbox,
|
||||
@@ -148,8 +146,8 @@ impl JmapEmailQueryCommand {
|
||||
)?;
|
||||
|
||||
let table = EmailsTable {
|
||||
preset: account.table_preset,
|
||||
arrangement: account.table_arrangement,
|
||||
preset: client.account.table_preset().to_string(),
|
||||
arrangement: client.account.table_arrangement(),
|
||||
emails: output.emails,
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use io_jmap::rfc8621::email::EmailAddress;
|
||||
use log::warn;
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
|
||||
use crate::jmap::account::JmapAccount;
|
||||
use crate::jmap::client::JmapClient;
|
||||
|
||||
/// Read the content of a JMAP email (Email/get with body).
|
||||
///
|
||||
@@ -21,8 +21,7 @@ pub struct JmapEmailReadCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailReadCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let output = client.email_get(self.ids.clone(), None, !self.html, self.html, 0)?;
|
||||
|
||||
for id in output.not_found {
|
||||
|
||||
@@ -5,7 +5,7 @@ use clap::Parser;
|
||||
use io_jmap::rfc8621::email_set::JmapEmailSetArgs;
|
||||
use pimalaya_cli::printer::{Message, Printer};
|
||||
|
||||
use crate::jmap::{account::JmapAccount, error::format_set_error};
|
||||
use crate::jmap::{client::JmapClient, error::format_set_error};
|
||||
|
||||
/// Update JMAP emails via patch operations (Email/set).
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -40,8 +40,7 @@ pub struct JmapEmailUpdateCommand {
|
||||
}
|
||||
|
||||
impl JmapEmailUpdateCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: JmapAccount) -> Result<()> {
|
||||
let mut client = account.new_jmap_client()?;
|
||||
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
||||
let mut args = JmapEmailSetArgs::default();
|
||||
|
||||
for id in &self.ids {
|
||||
|
||||
Reference in New Issue
Block a user