mirror of
https://github.com/FliegendeWurst/inboxid.git
synced 2024-11-22 00:45:01 +00:00
sync: delete mails after hardlinking
(to avoid fetching mails already downloaded)
This commit is contained in:
parent
9e746fb7d7
commit
15819138f9
@ -75,7 +75,7 @@ fn fetch_inbox_top(
|
||||
println!("mail {:?}", uid);
|
||||
let id = gen_id(uid_validity, uid);
|
||||
let uid = ((uid_validity as u64) << 32) | uid as u64;
|
||||
if !maildir.exists(&id).unwrap_or(false) {
|
||||
if !maildir.exists(&id) {
|
||||
let mail_data = mail.body().unwrap_or_default();
|
||||
maildir.store_new_with_id(&id, mail_data)?;
|
||||
|
||||
|
@ -66,6 +66,7 @@ fn sync(
|
||||
let mut all_mail = db.prepare("SELECT uid, message_id FROM mail WHERE mailbox = ?")?;
|
||||
let mut save_mail = db.prepare("INSERT INTO mail VALUES (?,?,?)")?;
|
||||
let mut maildirs: HashMap<&str, Maildir> = names.iter().map(|&x| (x, get_maildir(x).unwrap())).collect();
|
||||
let mut to_remove: HashMap<&str, _> = HashMap::new();
|
||||
for &mailbox in &names {
|
||||
let remote_mails = &remote[mailbox];
|
||||
|
||||
@ -105,7 +106,7 @@ fn sync(
|
||||
let uid = mail.uid.unwrap();
|
||||
println!("fetching: {}/{}", mailbox, uid);
|
||||
let id = gen_id(uid_validity, uid);
|
||||
if !maildir.exists(&id).unwrap_or(false) {
|
||||
if !maildir.exists(&id) {
|
||||
let mail_data = mail.body().unwrap_or_default();
|
||||
maildir.store_new_with_id(&id, mail_data)?;
|
||||
|
||||
@ -121,10 +122,20 @@ fn sync(
|
||||
let mails = all_mail.query_map(params![mailbox], |row|
|
||||
Ok((load_i64(row.get::<_, i64>(0)?), row.get::<_, String>(1)?)))?
|
||||
.map(|x| x.unwrap()).collect_vec();
|
||||
let mut removed = Vec::new();
|
||||
for (uid, message_id) in mails {
|
||||
let uid1 = (uid >> 32) as u32;
|
||||
let uid2 = ((uid << 32) >> 32) as u32;
|
||||
if !remote_mails.contains_key(&message_id) {
|
||||
removed.push((uid1, uid2, uid));
|
||||
}
|
||||
}
|
||||
if !removed.is_empty() {
|
||||
to_remove.insert(mailbox, removed);
|
||||
}
|
||||
}
|
||||
for mailbox in to_remove.keys() {
|
||||
for &(uid1, uid2, uid) in &to_remove[mailbox] {
|
||||
let uid_name = gen_id(uid1, uid2);
|
||||
println!("removing: {}/{}", mailbox, uid_name);
|
||||
if !maildirs.contains_key(".gone") {
|
||||
@ -137,7 +148,6 @@ fn sync(
|
||||
delete_mail.execute(params![mailbox, uid])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// be nice to the server and log out
|
||||
imap_session.logout()?;
|
||||
|
Loading…
Reference in New Issue
Block a user