From c3692cadeca91892f9e3433a47362c9759b0d310 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 2 Dec 2023 16:34:44 -0800 Subject: [PATCH] server: add id and header to ShowThreadQuery API --- server/src/graphql.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/src/graphql.rs b/server/src/graphql.rs index a17e719..19e1ef8 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -47,6 +47,8 @@ pub struct Thread { #[derive(Debug, SimpleObject)] pub struct Message { + // Message-ID for message, prepend `id:` to search in notmuch + pub id: String, // First From header found in email pub from: Option, // All To headers found in email @@ -57,12 +59,20 @@ pub struct Message { pub subject: Option, // Parsed Date header, if found and valid pub timestamp: Option, + // Headers + pub headers: Vec
, // The body contents pub body: Body, // On disk location of message pub path: String, } +#[derive(Debug, SimpleObject)] +pub struct Header { + key: String, + value: String, +} + #[derive(Debug)] pub struct UnhandledContentType { text: String, @@ -266,8 +276,10 @@ impl QueryRoot { .field("contentTree") .exists(); let mut messages = Vec::new(); - for path in nm.files(&thread_id)? { + for (path, id) in std::iter::zip(nm.files(&thread_id)?, nm.message_ids(&thread_id)?) { let path = path?; + let id = id?; + info!("{id}\nfile: {path}"); let file = File::open(&path)?; let mmap = unsafe { MmapOptions::new().map(&file)? }; let m = parse_mail(&mmap)?; @@ -310,12 +322,22 @@ impl QueryRoot { }), b => b, }; + let headers = m + .headers + .iter() + .map(|h| Header { + key: h.get_key(), + value: h.get_value(), + }) + .collect(); messages.push(Message { + id, from, to, cc, subject, timestamp, + headers, body, path, });