mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
d9272917f5
* merge tpl entity into msg * change envelope subject type to cow * msg: fix save command when raw msg comes from stdin * msg: clean flags
59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
//! Message flag handling module.
|
|
//!
|
|
//! This module gathers all flag actions triggered by the CLI.
|
|
|
|
use anyhow::Result;
|
|
|
|
use crate::{
|
|
domain::{Flags, ImapServiceInterface},
|
|
output::OutputServiceInterface,
|
|
};
|
|
|
|
/// Adds flags to all messages matching the given sequence range.
|
|
/// Flags are case-insensitive, and they do not need to be prefixed with `\`.
|
|
pub fn add<'a, OutputService: OutputServiceInterface, ImapService: ImapServiceInterface<'a>>(
|
|
seq_range: &'a str,
|
|
flags: Vec<&'a str>,
|
|
output: &'a OutputService,
|
|
imap: &'a mut ImapService,
|
|
) -> Result<()> {
|
|
let flags = Flags::from(flags);
|
|
imap.add_flags(seq_range, &flags)?;
|
|
output.print(format!(
|
|
r#"Flag(s) "{}" successfully added to message(s) "{}""#,
|
|
flags, seq_range
|
|
))
|
|
}
|
|
|
|
/// Removes flags from all messages matching the given sequence range.
|
|
/// Flags are case-insensitive, and they do not need to be prefixed with `\`.
|
|
pub fn remove<'a, OutputService: OutputServiceInterface, ImapService: ImapServiceInterface<'a>>(
|
|
seq_range: &'a str,
|
|
flags: Vec<&'a str>,
|
|
output: &'a OutputService,
|
|
imap: &'a mut ImapService,
|
|
) -> Result<()> {
|
|
let flags = Flags::from(flags);
|
|
imap.remove_flags(seq_range, &flags)?;
|
|
output.print(format!(
|
|
r#"Flag(s) "{}" successfully removed from message(s) "{}""#,
|
|
flags, seq_range
|
|
))
|
|
}
|
|
|
|
/// Replaces flags of all messages matching the given sequence range.
|
|
/// Flags are case-insensitive, and they do not need to be prefixed with `\`.
|
|
pub fn set<'a, OutputService: OutputServiceInterface, ImapService: ImapServiceInterface<'a>>(
|
|
seq_range: &'a str,
|
|
flags: Vec<&'a str>,
|
|
output: &'a OutputService,
|
|
imap: &'a mut ImapService,
|
|
) -> Result<()> {
|
|
let flags = Flags::from(flags);
|
|
imap.set_flags(seq_range, &flags)?;
|
|
output.print(format!(
|
|
r#"Flag(s) "{}" successfully set for message(s) "{}""#,
|
|
flags, seq_range
|
|
))
|
|
}
|