aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-04-28 23:49:03 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-04-28 23:49:03 +0200
commit4a33cd02bef5fba633d99cf0e8f5ca55a25e8384 (patch)
treed35356f1cd59480941d18b0cc9e3ec5369214881 /src
parent78fc967b36d83c1a29bf15f3e8686feaf842b68b (diff)
downloadmail-4a33cd02bef5fba633d99cf0e8f5ca55a25e8384.tar.gz
try look for sent messages
Diffstat (limited to 'src')
-rw-r--r--src/main.rs12
-rw-r--r--src/state/threads.rs39
2 files changed, 23 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs
index 3f71050..58c084e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,17 +15,7 @@ fn main() {
// hide the cursor
let mut screen = termion::cursor::HideCursor::from(screen);
- let mut threads = {
- // open database
- let db = crate::db::open(notmuch::DatabaseMode::ReadOnly).unwrap();
-
- // get threads
- let query = db.create_query("tag:inbox").unwrap();
- let threads = query.search_threads().unwrap();
-
- Threads::from_query(Some(String::from("tag:inbox")), threads)
- };
-
+ let threads = Threads::from_query(String::from("tag:inbox"));
threads.init(&mut screen);
let client = Client::new(State::Threads(threads));
diff --git a/src/state/threads.rs b/src/state/threads.rs
index b6fddbb..be566e5 100644
--- a/src/state/threads.rs
+++ b/src/state/threads.rs
@@ -9,7 +9,7 @@ pub struct Threads {
threads: Vec<Thread>,
i: usize,
- query: Option<String>,
+ query: String,
}
pub struct Thread {
@@ -42,29 +42,29 @@ impl<'d, 'q> Thread {
}
}
-impl<'d, 'q> Threads {
- pub fn from_query(query: Option<String>, threads: notmuch::Threads<'d, 'q>) -> Self {
- Self {
- threads: threads.map(Thread::new).collect(),
+impl Threads {
+ pub fn from_query(query: String) -> Self {
+ let mut res = Self {
+ threads: Vec::new(),
i: 0,
query,
- }
+ };
+ res.reload();
+ res
}
pub fn reload(&mut self) {
- if let Some(query) = &self.query {
- self.threads = db::open(DatabaseMode::ReadOnly)
- .unwrap()
- .create_query(query)
- .unwrap()
- .search_threads()
- .unwrap()
- .map(Thread::new)
- .collect();
- }
+ self.threads = db::open(DatabaseMode::ReadOnly)
+ .unwrap()
+ .create_query(&self.query)
+ .unwrap()
+ .search_threads()
+ .unwrap()
+ .map(Thread::new)
+ .collect();
}
- pub fn init<W: Write>(&mut self, out: &mut W) {
+ pub fn init<W: Write>(&self, out: &mut W) {
draw(&self, out);
}
@@ -80,6 +80,11 @@ impl<'d, 'q> Threads {
Key::Char('i') => {
self.threads[self.i].remove_tag("inbox");
}
+ Key::Char('s') => {
+ let sent = Threads::from_query(String::from("tag:sent"));
+ sent.init(out);
+ return Some(State::Threads(sent));
+ }
Key::Char('r') => self.reload(),
_ => (),
}