Use UIDs instead of sequence numbers

The previous scheme caused some messages to not produce notifications
when message sequence numbers were re-used. UIDs are never re-used, so
this is not an issue.
This commit is contained in:
Jon Gjengset 2017-05-15 16:24:05 -04:00
parent 71dc1da551
commit ce57248de2
No known key found for this signature in database
GPG Key ID: D64AC9D67176DC71

View File

@ -186,12 +186,12 @@ fn main() {
let tx = tx.clone();
thread::spawn(move || {
// Keep track of all the e-mails we have already notified about
let mut notified = HashSet::new();
let mut last_notified = 0;
loop {
// check current state of inbox
let mut unseen = imap_socket
.run_command_and_read_response("SEARCH UNSEEN")
.run_command_and_read_response("UID SEARCH UNSEEN 1:*")
.unwrap();
// remove last line of response (OK Completed)
@ -203,7 +203,8 @@ fn main() {
let unseen = unseen.split_whitespace().skip(2);
for uid in unseen.take_while(|&e| e != "" && e != "Completed") {
if let Ok(uid) = usize::from_str_radix(uid, 10) {
if notified.insert(uid) {
if uid > last_notified {
last_notified = uid;
uids.push(format!("{}", uid));
}
num_unseen += 1;
@ -235,7 +236,9 @@ fn main() {
false
};
let lines = imap_socket.fetch(&uids.join(","), "RFC822.HEADER").unwrap();
let lines = imap_socket
.uid_fetch(&uids.join(","), "RFC822.HEADER")
.unwrap();
let mut message = Vec::new();
for line in &lines {
if line.starts_with("* ") {