new: move mail into cur

This commit is contained in:
FliegendeWurst 2021-03-28 14:45:28 +02:00 committed by Arne Keller
parent 545b1f7c2f
commit 8166a79e3f
2 changed files with 30 additions and 7 deletions

24
Cargo.lock generated
View File

@ -19,8 +19,11 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "ascii_table" name = "ascii_table"
version = "3.0.2" version = "4.0.0-alpha"
source = "git+https://gitlab.com/arnekeller/ascii-table.git?branch=master#7fffb5d93b8c63283fc1359ee3c6dbfcf12ed90b" source = "git+https://gitlab.com/arnekeller/ascii-table.git?branch=master#2d485d6b3408ed8ef2629b6be14189a312d8c60c"
dependencies = [
"unicode-width",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
@ -472,14 +475,21 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.43" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"wasi",
"winapi", "winapi",
] ]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.1" version = "0.2.1"
@ -498,6 +508,12 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" 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]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.72" version = "0.2.72"

View File

@ -12,11 +12,12 @@ fn show_listing(mailbox: &str) -> Result<()> {
let maildir = get_maildir(mailbox)?; let maildir = get_maildir(mailbox)?;
let mut rows = Vec::new(); 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 // sort by UID
name.splitn(2, '_').nth(1).map(|x| x.parse().unwrap_or(0)).unwrap_or(0) 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)) => { Ok(Ok(mail)) => {
let headers = mail.get_headers(); let headers = mail.get_headers();
let from = headers.get_all_values("From").join(" "); 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() dt.format("%Y-%m-%d %H:%M").to_string()
}).unwrap_or(date); }).unwrap_or(date);
rows.push(vec![from, subj, date]); rows.push(vec![from, subj, date]);
seen.push(maile.as_ref().unwrap().id().to_owned());
} }
Ok(Err(e)) => { Ok(Err(e)) => {
println!("error parsing mail: {:?}", e); println!("error parsing mail: {:?}", e);
@ -51,7 +53,12 @@ fn show_listing(mailbox: &str) -> Result<()> {
column.max_width = usize::MAX; column.max_width = usize::MAX;
ascii_table.columns.insert(i, column); 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(()) Ok(())
} }