mirror of
https://github.com/FliegendeWurst/inboxid.git
synced 2024-11-22 00:45:01 +00:00
Use UID as maildir filename
This commit is contained in:
parent
749f1c3aed
commit
dd6e75d472
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -233,8 +233,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "maildir"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6adcf4693a3c725b9c69ccf24f8ed9c6d3e7168c1a45632570d65529adc13b5e"
|
||||
dependencies = [
|
||||
"gethostname",
|
||||
"mailparse",
|
||||
|
@ -3,11 +3,12 @@ name = "inboxid"
|
||||
version = "0.1.0"
|
||||
authors = ["Arne Keller <arne.keller@posteo.de>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
imap = { version = "2.4.1", default-features = false }
|
||||
itertools = "0.10.0"
|
||||
maildir = "0.5.0"
|
||||
maildir = { path = "../maildir" }
|
||||
rustls-connector = "0.13.1"
|
||||
|
25
src/main.rs
25
src/main.rs
@ -36,6 +36,7 @@ fn fetch_inbox_top(
|
||||
// to do anything useful with the e-mails, we need to log in
|
||||
println!("logging in..");
|
||||
let mut imap_session = client.login(&user, &password).map_err(|e| e.0)?;
|
||||
println!("getting capabilities..");
|
||||
let caps = imap_session.capabilities()?;
|
||||
println!("capabilities: {}", caps.iter().map(|x| format!("{:?}", x)).join(" "));
|
||||
|
||||
@ -54,8 +55,8 @@ fn fetch_inbox_top(
|
||||
|x| {
|
||||
let mut fields = x.splitn(2, ',');
|
||||
// TODO(2038): check if mailservers still just return the mailbox creation time in seconds
|
||||
let uid_validity = fields.next().map(|x| x.parse::<u32>().ok()).unwrap_or_default().unwrap_or(0);
|
||||
let uid_last = fields.next().map(|x| x.parse::<u32>().ok()).unwrap_or_default().unwrap_or(0);
|
||||
let uid_validity = fields.next().map(|x| x.trim().parse::<u32>().ok()).unwrap_or_default().unwrap_or(0);
|
||||
let uid_last = fields.next().map(|x| x.trim().parse::<u32>().ok()).unwrap_or_default().unwrap_or(0);
|
||||
(uid_validity, uid_last)
|
||||
}
|
||||
).unwrap_or((0, 0));
|
||||
@ -63,9 +64,8 @@ fn fetch_inbox_top(
|
||||
if uid_validity != prev_uid_validity {
|
||||
fetch_range = "1:*".to_owned();
|
||||
// TODO: somehow remove invalidated messages
|
||||
// (is the maildir standard really this annoying?)
|
||||
} else if uid_next != prev_uid + 1 {
|
||||
fetch_range = format!("{}:*", prev_uid + 1)
|
||||
fetch_range = format!("{}:*", prev_uid + 1);
|
||||
} else {
|
||||
println!("no new mail.");
|
||||
imap_session.logout()?;
|
||||
@ -76,15 +76,14 @@ fn fetch_inbox_top(
|
||||
let messages = imap_session.uid_fetch(&fetch_range, "RFC822")?;
|
||||
let mut largest_uid = prev_uid;
|
||||
for mail in messages.iter() {
|
||||
largest_uid = cmp::max(largest_uid, mail.uid.unwrap());
|
||||
println!("mail {:?}", mail.uid);
|
||||
//let headers = mail.header().expect("message did not have headers!");
|
||||
let body = mail.body().unwrap_or_default();
|
||||
let mut data = Vec::new();
|
||||
//data.extend(headers);
|
||||
//data.push(b'\n');
|
||||
data.extend(body);
|
||||
maildir.store_new(&data)?;
|
||||
let uid = mail.uid.unwrap();
|
||||
largest_uid = cmp::max(largest_uid, uid);
|
||||
println!("mail {:?}", uid);
|
||||
let id = format!("{}_{}", uid_validity, uid);
|
||||
if !maildir.exists(&id).unwrap_or(false) {
|
||||
let mail_data = mail.body().unwrap_or_default();
|
||||
maildir.store_new_with_id(&id, mail_data)?;
|
||||
}
|
||||
}
|
||||
let uid = cmp::max(uid_next - 1, largest_uid);
|
||||
maildir.save_file(".uid", &format!("{},{}", uid_validity, uid))?;
|
||||
|
Loading…
Reference in New Issue
Block a user