summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-30 12:41:08 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-03 11:10:59 +0100
commitb44778a6c835c86a8c1ba7c373aaac08db4557a2 (patch)
tree764424eb4129f709bf17d9af9d7897494f776558
parentba17174e9482503c089ff9d6deab96c0f1168022 (diff)
Add flags module for flags representation as strong types
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/lib.rs1
-rw-r--r--lib/domain/libimagmail/src/mailflags.rs80
2 files changed, 81 insertions, 0 deletions
diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs
index b3d5785b..2334a74f 100644
--- a/lib/domain/libimagmail/src/lib.rs
+++ b/lib/domain/libimagmail/src/lib.rs
@@ -56,6 +56,7 @@ module_entry_path_mod!("mail");
pub mod config;
pub mod hasher;
pub mod mail;
+pub mod mailflags;
pub mod mid;
pub mod store;
pub mod util;
diff --git a/lib/domain/libimagmail/src/mailflags.rs b/lib/domain/libimagmail/src/mailflags.rs
new file mode 100644
index 00000000..ad8d6c52
--- /dev/null
+++ b/lib/domain/libimagmail/src/mailflags.rs
@@ -0,0 +1,80 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::fmt::{Display, Result as FmtResult, Formatter};
+use std::str::FromStr;
+
+use failure::Fallible as Result;
+use failure::Error;
+
+/// Message flags
+///
+/// As defined by https://cr.yp.to/proto/maildir.html with strong typing
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub enum MailFlag {
+ /// Flag "P" (passed): the user has resent/forwarded/bounced this message to someone else.
+ Passed,
+
+ /// Flag "R" (replied): the user has replied to this message.
+ Replied,
+
+ /// Flag "S" (seen): the user has viewed this message, though perhaps he didn't read all the way through it.
+ Seen,
+
+ /// Flag "T" (trashed): the user has moved this message to the trash; the trash will be emptied by a later user action.
+ Trashed,
+
+ /// Flag "D" (draft): the user considers this message a draft; toggled at user discretion.
+ Draft,
+
+ /// Flag "F" (flagged): user-defined flag; toggled at user discretion.
+ Flagged,
+}
+
+impl FromStr for MailFlag {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<MailFlag> {
+ match s {
+ "P" => Ok(MailFlag::Passed),
+ "R" => Ok(MailFlag::Replied),
+ "S" => Ok(MailFlag::Seen),
+ "T" => Ok(MailFlag::Trashed),
+ "D" => Ok(MailFlag::Draft),
+ "F" => Ok(MailFlag::Flagged),
+ _ => Err(format_err!("Unknown message flag: '{}'", s)),
+ }
+ }
+}
+
+impl Display for MailFlag {
+ fn fmt(&self, f: &mut Formatter) -> FmtResult {
+ let s = match self {
+ MailFlag::Passed => "Passed",
+ MailFlag::Replied => "Replied",
+ MailFlag::Seen => "Seen",
+ MailFlag::Trashed => "Trashed",
+ MailFlag::Draft => "Draft",
+ MailFlag::Flagged => "Flagged",
+ };
+
+ write!(f, "{}", s)
+ }
+}
+