mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-15 20:07:57 +08:00
refactor: replace --select by --no-select
This commit is contained in:
@@ -17,7 +17,7 @@ use serde::Serialize;
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
envelope::list::{decode_mime, format_address},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Get a single IMAP envelope.
|
||||
@@ -28,9 +28,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct GetEnvelopeCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
#[arg(name = "id", value_name = "ID")]
|
||||
@@ -43,9 +43,9 @@ pub struct GetEnvelopeCommand {
|
||||
impl GetEnvelopeCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalArg, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalArg, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// List IMAP envelopes from the given mailbox.
|
||||
@@ -31,9 +31,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ListEnvelopesCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalArg,
|
||||
pub mailbox_name: MailboxNameOptionalArg,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of envelopes.
|
||||
#[arg(short, long, default_value = "1:*")]
|
||||
@@ -46,9 +46,9 @@ pub struct ListEnvelopesCommand {
|
||||
impl ListEnvelopesCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Search IMAP messages by criteria.
|
||||
@@ -48,9 +48,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SearchEnvelopesCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// Search query (e.g., "from:alice unseen").
|
||||
#[arg(name = "query", value_name = "QUERY", default_value = "all")]
|
||||
@@ -64,9 +64,9 @@ pub struct SearchEnvelopesCommand {
|
||||
impl SearchEnvelopesCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SortEnvelopesCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalArg,
|
||||
pub mailbox_name: MailboxNameOptionalArg,
|
||||
|
||||
/// Sort criteria (e.g., "date", "from", "subject", "size").
|
||||
#[arg(short = 'S', long, default_value = "date")]
|
||||
@@ -57,7 +57,7 @@ pub struct SortEnvelopesCommand {
|
||||
impl SortEnvelopesCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
// SELECT mailbox
|
||||
let mut arg = None;
|
||||
|
||||
@@ -17,7 +17,7 @@ use serde::{Serialize, Serializer};
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
envelope::{list::decode_mime, search::parse_query},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Thread IMAP messages by algorithm.
|
||||
@@ -31,9 +31,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ThreadEnvelopesCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// Threading algorithm (orderedsubject or references).
|
||||
#[arg(short = 'A', long, default_value = "references")]
|
||||
@@ -51,9 +51,9 @@ pub struct ThreadEnvelopesCommand {
|
||||
impl ThreadEnvelopesCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Add IMAP flag(s) to message(s).
|
||||
@@ -22,9 +22,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct AddFlagsCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of messages (e.g., "1", "1,2,3", "1:*").
|
||||
#[arg(value_name = "SEQUENCE")]
|
||||
@@ -41,9 +41,9 @@ pub struct AddFlagsCommand {
|
||||
impl AddFlagsCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ListFlagsCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl ListFlagsCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
@@ -12,7 +12,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Remove IMAP flag(s) from message(s).
|
||||
@@ -22,9 +22,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct RemoveFlagsCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of messages (e.g., "1", "1,2,3", "1:*").
|
||||
#[arg(name = "sequence_set", value_name = "SEQUENCE")]
|
||||
@@ -41,9 +41,9 @@ pub struct RemoveFlagsCommand {
|
||||
impl RemoveFlagsCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Set IMAP flag(s) on message(s), replacing any existing flags.
|
||||
@@ -22,9 +22,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SetFlagsCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of messages (e.g., "1", "1,2,3", "1:*").
|
||||
#[arg(name = "sequence_set", value_name = "SEQUENCE")]
|
||||
@@ -41,9 +41,9 @@ pub struct SetFlagsCommand {
|
||||
impl SetFlagsCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
+28
-36
@@ -2,50 +2,51 @@ use clap::Parser;
|
||||
|
||||
const INBOX: &str = "INBOX";
|
||||
|
||||
/// The optional mailbox name argument parser.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MailboxNameOptionalArg {
|
||||
/// The name of the mailbox.
|
||||
#[arg(name = "mailbox_name", value_name = "MAILBOX", default_value = INBOX)]
|
||||
pub inner: String,
|
||||
}
|
||||
|
||||
impl Default for MailboxNameOptionalArg {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
inner: INBOX.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The optional mailbox name flag parser.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MailboxNameOptionalFlag {
|
||||
/// The name of the mailbox.
|
||||
#[arg(long = "mailbox", short = 'm')]
|
||||
#[arg(name = "mailbox_name", value_name = "NAME", default_value = INBOX)]
|
||||
pub name: String,
|
||||
pub inner: String,
|
||||
}
|
||||
|
||||
impl Default for MailboxNameOptionalFlag {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: INBOX.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The optional mailbox name argument parser.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MailboxNameOptionalArg {
|
||||
/// The name of the mailbox.
|
||||
#[arg(name = "mailbox_name", value_name = "MAILBOX", default_value = INBOX)]
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Default for MailboxNameOptionalArg {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: INBOX.to_owned(),
|
||||
inner: INBOX.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MailboxSelectFlag {
|
||||
/// Select the given mailbox before performing the current action.
|
||||
pub struct MailboxNoSelectFlag {
|
||||
/// Do not select the given mailbox before performing the current
|
||||
/// action.
|
||||
///
|
||||
/// This argument can be omitted when stateful IMAP sessions are
|
||||
/// used, for example with:
|
||||
/// This argument is useful when stateful IMAP sessions are used,
|
||||
/// for example with Sirup CLI:
|
||||
///
|
||||
/// https://github.com/pimalaya/sirup
|
||||
#[arg(long = "select", default_value_t)]
|
||||
#[arg(name = "mailbox_select")]
|
||||
pub r#true: bool,
|
||||
#[arg(long = "no-select", default_value_t)]
|
||||
#[arg(name = "mailbox_no_select")]
|
||||
pub inner: bool,
|
||||
}
|
||||
|
||||
/// The required mailbox name argument parser.
|
||||
@@ -53,16 +54,7 @@ pub struct MailboxSelectFlag {
|
||||
pub struct MailboxNameArg {
|
||||
/// The name of the mailbox.
|
||||
#[arg(name = "mailbox_name", value_name = "MAILBOX")]
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// The optional source mailbox name flag parser.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SourceMailboxNameOptionalFlag {
|
||||
/// The name of the source mailbox.
|
||||
#[arg(long = "mailbox", short = 'm')]
|
||||
#[arg(name = "source_mailbox_name", value_name = "SOURCE", default_value = INBOX)]
|
||||
pub name: String,
|
||||
pub inner: String,
|
||||
}
|
||||
|
||||
/// The target mailbox name argument parser.
|
||||
@@ -70,5 +62,5 @@ pub struct SourceMailboxNameOptionalFlag {
|
||||
pub struct TargetMailboxNameArg {
|
||||
/// The name of the target mailbox.
|
||||
#[arg(name = "target_mailbox_name", value_name = "TARGET")]
|
||||
pub name: String,
|
||||
pub inner: String,
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct CreateMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl CreateMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapCreate::new(imap.context, mailbox);
|
||||
|
||||
@@ -13,13 +13,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct DeleteMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl DeleteMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapDelete::new(imap.context, mailbox);
|
||||
|
||||
@@ -6,7 +6,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameArg, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameArg, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Expunge the given mailbox.
|
||||
@@ -16,17 +16,17 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ExpungeMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
}
|
||||
|
||||
impl ExpungeMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameArg, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameArg, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Shortcut for marking as deleted all envelopes then expunging the
|
||||
@@ -20,17 +20,17 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct PurgeMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
}
|
||||
|
||||
impl PurgeMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -15,17 +15,16 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct RenameMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub from: MailboxNameArg,
|
||||
|
||||
pub mailbox_source_name: MailboxNameArg,
|
||||
#[command(flatten)]
|
||||
pub to: TargetMailboxNameArg,
|
||||
pub mailbox_dest_name: TargetMailboxNameArg,
|
||||
}
|
||||
|
||||
impl RenameMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let from = self.from.name.try_into()?;
|
||||
let to = self.to.name.try_into()?;
|
||||
let from = self.mailbox_source_name.inner.try_into()?;
|
||||
let to = self.mailbox_dest_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapRename::new(imap.context, from, to);
|
||||
|
||||
@@ -17,13 +17,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SelectMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl SelectMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
@@ -20,13 +20,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct StatusMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl StatusMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
let item_names = vec![
|
||||
StatusDataItemName::Messages,
|
||||
StatusDataItemName::Recent,
|
||||
|
||||
@@ -13,13 +13,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct SubscribeMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl SubscribeMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSubscribe::new(imap.context, mailbox);
|
||||
|
||||
@@ -13,13 +13,13 @@ use crate::imap::{account::ImapAccount, mailbox::arg::MailboxNameArg};
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct UnsubscribeMailboxCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameArg,
|
||||
pub mailbox_name: MailboxNameArg,
|
||||
}
|
||||
|
||||
impl UnsubscribeMailboxCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapUnsubscribe::new(imap.context, mailbox);
|
||||
|
||||
@@ -9,7 +9,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag, TargetMailboxNameArg},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag, TargetMailboxNameArg},
|
||||
};
|
||||
|
||||
/// Copy IMAP message(s) to the given mailbox.
|
||||
@@ -19,15 +19,15 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct CopyMessageCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of messages (e.g., "1", "1,2,3", "1:*").
|
||||
#[arg(name = "sequence_set", value_name = "SEQUENCE")]
|
||||
pub sequence_set: String,
|
||||
#[command(flatten)]
|
||||
pub destination: TargetMailboxNameArg,
|
||||
pub mailbox_dest_name: TargetMailboxNameArg,
|
||||
|
||||
/// Use sequence numbers instead of UIDs.
|
||||
#[arg(long)]
|
||||
@@ -37,9 +37,9 @@ pub struct CopyMessageCommand {
|
||||
impl CopyMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
@@ -53,7 +53,7 @@ impl CopyMessageCommand {
|
||||
}
|
||||
|
||||
let sequence_set = self.sequence_set.as_str().try_into()?;
|
||||
let destination: Mailbox = self.destination.name.try_into()?;
|
||||
let destination: Mailbox = self.mailbox_dest_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapCopy::new(imap.context, sequence_set, destination, !self.seq);
|
||||
|
||||
@@ -37,7 +37,7 @@ pub enum ExportType {
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ExportMessageCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
#[arg(name = "id", value_name = "ID")]
|
||||
@@ -63,7 +63,7 @@ pub struct ExportMessageCommand {
|
||||
impl ExportMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
// SELECT mailbox
|
||||
let mut arg = None;
|
||||
|
||||
@@ -14,7 +14,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Get a message and display its structure.
|
||||
@@ -24,9 +24,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct GetMessageCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
pub id: u32,
|
||||
@@ -38,12 +38,12 @@ pub struct GetMessageCommand {
|
||||
impl GetMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
let Some(id) = NonZeroU32::new(self.id) else {
|
||||
bail!("ID must be non-zero");
|
||||
};
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag, TargetMailboxNameArg},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag, TargetMailboxNameArg},
|
||||
};
|
||||
|
||||
/// Move message(s) to the given mailbox.
|
||||
@@ -20,15 +20,15 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MoveMessageCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The sequence set of messages (e.g., "1", "1,2,3", "1:*").
|
||||
#[arg(name = "sequence_set", value_name = "SEQUENCE")]
|
||||
pub sequence_set: String,
|
||||
#[command(flatten)]
|
||||
pub destination: TargetMailboxNameArg,
|
||||
pub mailbox_dest_name: TargetMailboxNameArg,
|
||||
|
||||
/// Use sequence numbers instead of UIDs.
|
||||
#[arg(long)]
|
||||
@@ -38,9 +38,9 @@ pub struct MoveMessageCommand {
|
||||
impl MoveMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
@@ -54,7 +54,7 @@ impl MoveMessageCommand {
|
||||
}
|
||||
|
||||
let sequence_set = self.sequence_set.as_str().try_into()?;
|
||||
let destination: Mailbox<'static> = self.destination.name.try_into()?;
|
||||
let destination: Mailbox<'static> = self.mailbox_dest_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapMove::new(imap.context, sequence_set, destination, !self.seq);
|
||||
|
||||
@@ -13,7 +13,7 @@ use serde::Serialize;
|
||||
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag},
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag},
|
||||
};
|
||||
|
||||
/// Read message content.
|
||||
@@ -23,9 +23,9 @@ use crate::imap::{
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ReadMessageCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox: MailboxNameOptionalFlag,
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
pub select: MailboxSelectFlag,
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
#[arg(name = "id", value_name = "ID")]
|
||||
@@ -47,9 +47,9 @@ pub struct ReadMessageCommand {
|
||||
impl ReadMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ pub struct SaveMessageCommand {
|
||||
impl SaveMessageCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox: Mailbox<'static> = self.mailbox.name.try_into()?;
|
||||
let mailbox: Mailbox<'static> = self.mailbox.inner.try_into()?;
|
||||
let message = if stdin().is_terminal() || printer.is_json() {
|
||||
self.message
|
||||
.join(" ")
|
||||
|
||||
Reference in New Issue
Block a user