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