summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-09-27 23:06:15 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-09-27 23:06:15 +0200
commit9100b871f8ebe4b1517e80d1b8561158866f7383 (patch)
treed3db1107b9248e4b2b5bf92ba317ab7e8bbbe4ac /src
parent52219f0c3fa2166e48c00eb548f9701bbd0024be (diff)
add remove action
refactor to avoid deprecation warning
Diffstat (limited to 'src')
-rw-r--r--src/arguments.rs4
-rw-r--r--src/cmd.rs8
-rw-r--r--src/main.rs6
-rw-r--r--src/rfc822.rs14
4 files changed, 23 insertions, 9 deletions
diff --git a/src/arguments.rs b/src/arguments.rs
index 505cc18..bd0fdcb 100644
--- a/src/arguments.rs
+++ b/src/arguments.rs
@@ -96,6 +96,10 @@ pub enum Mode {
from: String,
to: String,
},
+ Remove {
+ subfolder: String,
+ mid: String,
+ },
}
#[derive(Parser)]
diff --git a/src/cmd.rs b/src/cmd.rs
index 364fcfb..fdb8a5f 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -26,6 +26,7 @@ pub enum Return {
Count(CountInfo),
Search(Vec<Mail>),
Move,
+ Remove,
}
pub fn serialize_to<W>(res: Result<Return>, mut write: W) -> std::io::Result<()>
@@ -56,6 +57,7 @@ where
Ok(r)
}
Return::Move => ser.serialize_unit(),
+ Return::Remove => ser.serialize_unit(),
}?;
Ok(())
}
@@ -85,6 +87,12 @@ pub fn move_mail(p: PathBuf, mid: &str, from_f: &str, to_f: &str) -> Result<()>
from.move_to(mid, &to).map_err(|e| e.into())
}
+pub fn remove_mail(p: PathBuf, sub: &str, mid: &str) -> Result<()> {
+ let md = open_submaildir(p, sub);
+ dbg!(mid);
+ md.add_flags(mid, "T").map_err(|e| e.into())
+}
+
pub fn search(_md: &Maildir, _pattern: &str) -> Result<Vec<Mail>> {
todo!()
}
diff --git a/src/main.rs b/src/main.rs
index 8a8b84e..0b216dc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,8 @@ mod rfc822;
use arguments::{Arguments, Mode};
use cmd::{
- count, folders, list, move_mail, open_submaildir, raw, read, search, serialize_to, Return,
+ count, folders, list, move_mail, open_submaildir, raw, read, remove_mail, search, serialize_to,
+ Return,
};
use error::{Error, Result};
@@ -83,6 +84,9 @@ fn main() -> std::io::Result<()> {
search(&open_submaildir(path, &subfolder), &pattern).map(Return::Search)
}
Mode::Move { mid, from, to } => move_mail(path, &mid, &from, &to).map(|()| Return::Move),
+ Mode::Remove { subfolder, mid } => {
+ remove_mail(path, &subfolder, &mid).map(|()| Return::Remove)
+ }
};
serialize_to(res, &stdout())
diff --git a/src/rfc822.rs b/src/rfc822.rs
index f6e9287..b3edca8 100644
--- a/src/rfc822.rs
+++ b/src/rfc822.rs
@@ -178,10 +178,9 @@ impl TryFrom<maildir::MailEntry> for TopMailHeader {
Ok(TopMailHeader {
byte_size: me.path().metadata()?.len(),
unread: !me.is_seen(),
- date_received: DateTime::<Utc>::from_utc(
- NaiveDateTime::from_timestamp_opt(get_received(&mut me), 0).unwrap(),
- Utc,
- ),
+ date_received: NaiveDateTime::from_timestamp_opt(get_received(&mut me), 0)
+ .unwrap()
+ .and_utc(),
message_handle: me.id().to_owned(),
head: parse_mail_header(&me.parsed()?)?,
})
@@ -278,10 +277,9 @@ fn parse_mail_header(pm: &ParsedMail) -> Result<MailHeader, maildir::MailEntryEr
match key.as_str() {
"date" => {
- mh.orig_date = DateTime::<Utc>::from_utc(
- NaiveDateTime::from_timestamp_opt(dateparse(&val)?, 0).unwrap(),
- Utc,
- )
+ mh.orig_date = NaiveDateTime::from_timestamp_opt(dateparse(&val)?, 0)
+ .unwrap()
+ .and_utc()
}
"from" => {
if !mh.from.is_empty() {