mirror of
https://github.com/FliegendeWurst/inboxid.git
synced 2024-11-24 09:55:09 +00:00
sync: also set flags
This commit is contained in:
parent
15819138f9
commit
9658862e25
@ -1,11 +1,19 @@
|
|||||||
|
use std::env;
|
||||||
|
|
||||||
use ascii_table::{Align, AsciiTable, Column};
|
use ascii_table::{Align, AsciiTable, Column};
|
||||||
use chrono::{Local, NaiveDateTime, TimeZone};
|
use chrono::{Local, NaiveDateTime, TimeZone};
|
||||||
|
use itertools::Itertools;
|
||||||
use mailparse::{MailHeaderMap, dateparse};
|
use mailparse::{MailHeaderMap, dateparse};
|
||||||
|
|
||||||
use inboxid::*;
|
use inboxid::*;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
let args = env::args().collect_vec();
|
||||||
|
if args.len() > 1 {
|
||||||
|
show_listing(&args[1])
|
||||||
|
} else {
|
||||||
show_listing("INBOX")
|
show_listing("INBOX")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_listing(mailbox: &str) -> Result<()> {
|
fn show_listing(mailbox: &str) -> Result<()> {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![feature(string_remove_matches)]
|
||||||
|
|
||||||
use std::{collections::HashMap, env};
|
use std::{collections::HashMap, env};
|
||||||
|
|
||||||
use imap::types::Flag;
|
use imap::types::Flag;
|
||||||
@ -88,7 +90,7 @@ fn sync(
|
|||||||
let maildir2 = &maildirs[mailbox];
|
let maildir2 = &maildirs[mailbox];
|
||||||
let new_id = gen_id(uid1, uid2);
|
let new_id = gen_id(uid1, uid2);
|
||||||
println!("hardlinking: {}/{} -> {}/{}", inbox, local_id, mailbox, new_id);
|
println!("hardlinking: {}/{} -> {}/{}", inbox, local_id, mailbox, new_id);
|
||||||
maildir2.store_new_from_path(&new_id, name)?;
|
maildir2.store_cur_from_path(&new_id, name)?;
|
||||||
save_mail.execute(params![mailbox, store_i64(*full_uid), message_id])?;
|
save_mail.execute(params![mailbox, store_i64(*full_uid), message_id])?;
|
||||||
} else {
|
} else {
|
||||||
to_fetch.push(uid2);
|
to_fetch.push(uid2);
|
||||||
@ -108,7 +110,7 @@ fn sync(
|
|||||||
let id = gen_id(uid_validity, uid);
|
let id = gen_id(uid_validity, uid);
|
||||||
if !maildir.exists(&id) {
|
if !maildir.exists(&id) {
|
||||||
let mail_data = mail.body().unwrap_or_default();
|
let mail_data = mail.body().unwrap_or_default();
|
||||||
maildir.store_new_with_id(&id, mail_data)?;
|
maildir.store_cur_with_id(&id, mail_data)?;
|
||||||
|
|
||||||
let headers = parse_headers(&mail_data)?.0;
|
let headers = parse_headers(&mail_data)?.0;
|
||||||
let message_id = headers.get_all_values("Message-ID").join(" ");
|
let message_id = headers.get_all_values("Message-ID").join(" ");
|
||||||
@ -119,6 +121,30 @@ fn sync(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let maildir = &maildirs[mailbox];
|
||||||
|
for message_id in remote_mails.keys() {
|
||||||
|
let (uid1, uid2, _, ref flags) = remote_mails[message_id];
|
||||||
|
let id = gen_id(uid1, uid2);
|
||||||
|
let _ = maildir.update_flags(&id, |f| {
|
||||||
|
let mut f = f.to_owned();
|
||||||
|
if flags.contains(&Flag::Seen) {
|
||||||
|
f.push('S');
|
||||||
|
} else {
|
||||||
|
f.remove_matches('S');
|
||||||
|
}
|
||||||
|
if flags.contains(&Flag::Answered) {
|
||||||
|
f.push('R');
|
||||||
|
} else {
|
||||||
|
f.remove_matches('R');
|
||||||
|
}
|
||||||
|
if flags.contains(&Flag::Flagged) {
|
||||||
|
f.push('F');
|
||||||
|
} else {
|
||||||
|
f.remove_matches('F');
|
||||||
|
}
|
||||||
|
Maildir::normalize_flags(&f)
|
||||||
|
});
|
||||||
|
}
|
||||||
let mails = all_mail.query_map(params![mailbox], |row|
|
let mails = all_mail.query_map(params![mailbox], |row|
|
||||||
Ok((load_i64(row.get::<_, i64>(0)?), row.get::<_, String>(1)?)))?
|
Ok((load_i64(row.get::<_, i64>(0)?), row.get::<_, String>(1)?)))?
|
||||||
.map(|x| x.unwrap()).collect_vec();
|
.map(|x| x.unwrap()).collect_vec();
|
||||||
@ -145,7 +171,7 @@ fn sync(
|
|||||||
let name = maildir.find_filename(&uid_name).unwrap();
|
let name = maildir.find_filename(&uid_name).unwrap();
|
||||||
maildirs[".gone"].store_new_from_path(&format!("{}_{}", mailbox, uid_name), name)?;
|
maildirs[".gone"].store_new_from_path(&format!("{}_{}", mailbox, uid_name), name)?;
|
||||||
maildir.delete(&uid_name)?;
|
maildir.delete(&uid_name)?;
|
||||||
delete_mail.execute(params![mailbox, uid])?;
|
delete_mail.execute(params![mailbox, store_i64(uid)])?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user