server: add id and header to ShowThreadQuery API

This commit is contained in:
Bill Thiede 2023-12-02 16:34:44 -08:00
parent b14000952c
commit c3692cadec

View File

@ -47,6 +47,8 @@ pub struct Thread {
#[derive(Debug, SimpleObject)] #[derive(Debug, SimpleObject)]
pub struct Message { pub struct Message {
// Message-ID for message, prepend `id:<id>` to search in notmuch
pub id: String,
// First From header found in email // First From header found in email
pub from: Option<Email>, pub from: Option<Email>,
// All To headers found in email // All To headers found in email
@ -57,12 +59,20 @@ pub struct Message {
pub subject: Option<String>, pub subject: Option<String>,
// Parsed Date header, if found and valid // Parsed Date header, if found and valid
pub timestamp: Option<i64>, pub timestamp: Option<i64>,
// Headers
pub headers: Vec<Header>,
// The body contents // The body contents
pub body: Body, pub body: Body,
// On disk location of message // On disk location of message
pub path: String, pub path: String,
} }
#[derive(Debug, SimpleObject)]
pub struct Header {
key: String,
value: String,
}
#[derive(Debug)] #[derive(Debug)]
pub struct UnhandledContentType { pub struct UnhandledContentType {
text: String, text: String,
@ -266,8 +276,10 @@ impl QueryRoot {
.field("contentTree") .field("contentTree")
.exists(); .exists();
let mut messages = Vec::new(); 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 path = path?;
let id = id?;
info!("{id}\nfile: {path}");
let file = File::open(&path)?; let file = File::open(&path)?;
let mmap = unsafe { MmapOptions::new().map(&file)? }; let mmap = unsafe { MmapOptions::new().map(&file)? };
let m = parse_mail(&mmap)?; let m = parse_mail(&mmap)?;
@ -310,12 +322,22 @@ impl QueryRoot {
}), }),
b => b, b => b,
}; };
let headers = m
.headers
.iter()
.map(|h| Header {
key: h.get_key(),
value: h.get_value(),
})
.collect();
messages.push(Message { messages.push(Message {
id,
from, from,
to, to,
cc, cc,
subject, subject,
timestamp, timestamp,
headers,
body, body,
path, path,
}); });