cull_gmail/
eol_action.rs

1use std::fmt;
2
3/// End of life action
4/// - Trash - move the message to the trash to be automatically deleted by Google
5/// - Delete - delete the message immediately without allowing rescue from trash
6#[derive(Debug, Default, Clone)]
7pub enum EolAction {
8    #[default]
9    /// Move the message to the trash
10    Trash,
11    /// Delete the message immediately
12    Delete,
13}
14
15impl fmt::Display for EolAction {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            EolAction::Trash => write!(f, "trash"),
19            EolAction::Delete => write!(f, "delete"),
20        }
21    }
22}
23
24impl EolAction {
25    /// Parse a string to a valid  `EolAction` variant or return `None`.
26    pub fn parse(str: &str) -> Option<EolAction> {
27        match str.to_lowercase().as_str() {
28            "trash" => Some(EolAction::Trash),
29            "delete" => Some(EolAction::Delete),
30            _ => None,
31        }
32    }
33}