mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-18 05:47:54 +08:00
refactor(imap): make envelope and message get/read support * as id
Refs: #583
This commit is contained in:
+10
-10
@@ -35,15 +35,15 @@ pub enum ImapCommand {
|
||||
Id(ImapIdCommand),
|
||||
|
||||
#[command(subcommand)]
|
||||
#[command(aliases = ["mboxes", "mbox"])]
|
||||
Mailboxes(ImapMailboxCommand),
|
||||
#[command(aliases = ["mbox"])]
|
||||
Mailbox(ImapMailboxCommand),
|
||||
#[command(subcommand)]
|
||||
Envelopes(ImapEnvelopeCommand),
|
||||
Envelope(ImapEnvelopeCommand),
|
||||
#[command(subcommand)]
|
||||
Flags(ImapFlagCommand),
|
||||
Flag(ImapFlagCommand),
|
||||
#[command(subcommand)]
|
||||
#[command(aliases = ["msgs", "msg"])]
|
||||
Messages(ImapMessageCommand),
|
||||
#[command(aliases = ["msg"])]
|
||||
Message(ImapMessageCommand),
|
||||
}
|
||||
|
||||
impl ImapCommand {
|
||||
@@ -56,10 +56,10 @@ impl ImapCommand {
|
||||
match self {
|
||||
Self::Id(cmd) => cmd.execute(printer, account, client),
|
||||
|
||||
Self::Envelopes(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Flags(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Mailboxes(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Messages(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Envelope(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Flag(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Mailbox(cmd) => cmd.execute(printer, account, client),
|
||||
Self::Message(cmd) => cmd.execute(printer, account, client),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ pub struct ImapEnvelopeGetCommand {
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
#[arg(name = "id", value_name = "ID")]
|
||||
pub id: u32,
|
||||
pub id: String,
|
||||
/// Use sequence numbers instead of UIDs.
|
||||
#[arg(long)]
|
||||
pub seq: bool,
|
||||
@@ -67,14 +67,10 @@ impl ImapEnvelopeGetCommand {
|
||||
client.select(mailbox)?;
|
||||
}
|
||||
|
||||
if self.id == 0 {
|
||||
bail!("ID must be non-zero");
|
||||
}
|
||||
|
||||
let item_names =
|
||||
MacroOrMessageDataItemNames::MessageDataItemNames(vec![MessageDataItemName::Envelope]);
|
||||
|
||||
let sequence_set = self.id.to_string().parse()?;
|
||||
let sequence_set = self.id.parse()?;
|
||||
let mut data = client.fetch(sequence_set, item_names, !self.seq)?;
|
||||
|
||||
let Some((_, items)) = data.pop_first() else {
|
||||
|
||||
@@ -42,7 +42,7 @@ pub struct ImapMessageGetCommand {
|
||||
pub mailbox_no_select: MailboxNoSelectFlag,
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
pub id: u32,
|
||||
pub id: String,
|
||||
/// Use sequence numbers instead of UIDs.
|
||||
#[arg(long)]
|
||||
pub seq: bool,
|
||||
@@ -51,9 +51,6 @@ pub struct ImapMessageGetCommand {
|
||||
impl ImapMessageGetCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, client: &mut ImapClient) -> Result<()> {
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
if self.id == 0 {
|
||||
bail!("ID must be non-zero");
|
||||
}
|
||||
|
||||
if !self.mailbox_no_select.inner {
|
||||
client.select(mailbox)?;
|
||||
@@ -66,7 +63,7 @@ impl ImapMessageGetCommand {
|
||||
peek: true,
|
||||
}]);
|
||||
|
||||
let sequence_set = self.id.to_string().parse()?;
|
||||
let sequence_set = self.id.parse()?;
|
||||
let mut data = client.fetch(sequence_set, item_names, !self.seq)?;
|
||||
|
||||
let Some((_, items)) = data.pop_first() else {
|
||||
|
||||
@@ -42,7 +42,7 @@ pub struct ImapMessageReadCommand {
|
||||
|
||||
/// The message UID (or sequence number with --seq).
|
||||
#[arg(name = "id", value_name = "ID")]
|
||||
pub id: u32,
|
||||
pub id: String,
|
||||
|
||||
/// Use sequence numbers instead of UIDs.
|
||||
#[arg(long)]
|
||||
@@ -61,10 +61,6 @@ impl ImapMessageReadCommand {
|
||||
client.select(mailbox)?;
|
||||
}
|
||||
|
||||
if self.id == 0 {
|
||||
bail!("ID must be non-zero");
|
||||
}
|
||||
|
||||
let item_names =
|
||||
MacroOrMessageDataItemNames::MessageDataItemNames(vec![MessageDataItemName::BodyExt {
|
||||
section: None,
|
||||
@@ -72,7 +68,7 @@ impl ImapMessageReadCommand {
|
||||
peek: true,
|
||||
}]);
|
||||
|
||||
let sequence_set = self.id.to_string().parse()?;
|
||||
let sequence_set = self.id.parse()?;
|
||||
let mut data = client.fetch(sequence_set, item_names, !self.seq)?;
|
||||
|
||||
let Some((_, items)) = data.pop_first() else {
|
||||
|
||||
Reference in New Issue
Block a user