From 8166a79e3f93d69d6c46dfa21b7a8e059e85b832 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 28 Mar 2021 14:45:28 +0200 Subject: [PATCH] new: move mail into cur --- Cargo.lock | 24 ++++++++++++++++++++---- src/bin/new.rs | 13 ++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e1bd0f..817a931 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,8 +19,11 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "ascii_table" -version = "3.0.2" -source = "git+https://gitlab.com/arnekeller/ascii-table.git?branch=master#7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b" +version = "4.0.0-alpha" +source = "git+https://gitlab.com/arnekeller/ascii-table.git?branch=master#2d485d6b3408ed8ef2629b6be14189a312d8c60c" +dependencies = [ + "unicode-width", +] [[package]] name = "autocfg" @@ -472,14 +475,21 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", + "wasi", "winapi", ] +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -498,6 +508,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasm-bindgen" version = "0.2.72" diff --git a/src/bin/new.rs b/src/bin/new.rs index 386de64..dadf14f 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -12,11 +12,12 @@ fn show_listing(mailbox: &str) -> Result<()> { let maildir = get_maildir(mailbox)?; let mut rows = Vec::new(); - for mut mail in maildir.list_new_sorted(Box::new(|name| { + let mut seen = Vec::new(); + for mut maile in maildir.list_new_sorted(Box::new(|name| { // sort by UID name.splitn(2, '_').nth(1).map(|x| x.parse().unwrap_or(0)).unwrap_or(0) })) { - match mail.as_mut().map(|x| x.parsed()) { + match maile.as_mut().map(|x| x.parsed()) { Ok(Ok(mail)) => { let headers = mail.get_headers(); let from = headers.get_all_values("From").join(" "); @@ -27,6 +28,7 @@ fn show_listing(mailbox: &str) -> Result<()> { dt.format("%Y-%m-%d %H:%M").to_string() }).unwrap_or(date); rows.push(vec![from, subj, date]); + seen.push(maile.as_ref().unwrap().id().to_owned()); } Ok(Err(e)) => { println!("error parsing mail: {:?}", e); @@ -51,7 +53,12 @@ fn show_listing(mailbox: &str) -> Result<()> { column.max_width = usize::MAX; ascii_table.columns.insert(i, column); } - ascii_table.print(rows); + ascii_table.print(rows); // prints a 0 if empty :) + + // only after the user saw the new mail, move it out of 'new' + for seen in seen { + maildir.move_new_to_cur(&seen)?; + } Ok(()) }