Reverse sort messages
Some checks failed
continuous-integration/drone/push Build is failing

That way they also end up sorted in the feed.

Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
Jacob Kiers 2024-06-26 00:12:42 +02:00
parent 6dea6429f8
commit bee592b5d4

View File

@ -1,3 +1,4 @@
use std::io::Write;
use std::{
collections::HashMap,
error::Error,
@ -6,7 +7,6 @@ use std::{
path::PathBuf,
vec::IntoIter,
};
use std::io::Write;
use imap::Session;
use rustls_connector::RustlsConnector;
@ -66,7 +66,11 @@ impl EmailReader for DataDirectoryMessageReader {
})
.map(|i| Message::new(i.0, i.1));
let iter = items.collect::<Vec<Message>>().into_iter();
let mut items = items.collect::<Vec<Message>>();
items.sort_by_key(|m| m.get_parsed().unwrap().date().unwrap().to_owned());
let items = items.into_iter().rev().collect::<Vec<_>>();
let iter = items.into_iter();
Box::new(iter)
}
@ -107,7 +111,11 @@ impl ImapReader {
let sequence_sets = items.chunks(100);
for set in sequence_sets {
let sequence_set = set.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(",");
let sequence_set = set
.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(",");
print!("Fetching {} messages...", set.len());
let _ = std::io::stdout().flush();
@ -166,7 +174,11 @@ impl EmailReader for ImapReader {
.iter()
.map(|i| Message::new(i.0.to_owned(), i.1.to_owned()));
let iter = items.collect::<Vec<Message>>().into_iter();
let mut items = items.collect::<Vec<_>>();
items.sort_by_key(|m| m.get_parsed().unwrap().date().unwrap().to_owned());
let items = items.into_iter().rev().collect::<Vec<_>>();
let iter = items.into_iter();
Box::new(iter)
}