Files
himalaya/src/domain/msg/flag_handler.rs
T
Clément DOUIN d9272917f5 clean msg flags, merge tpl entity in msg (#231)
* merge tpl entity into msg

* change envelope subject type to cow

* msg: fix save command when raw msg comes from stdin

* msg: clean flags
2021-10-23 00:17:24 +02:00

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
))
}