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)]
pub struct Message {
// Message-ID for message, prepend `id:<id>` to search in notmuch
pub id: String,
// First From header found in email
pub from: Option<Email>,
// All To headers found in email
@ -57,12 +59,20 @@ pub struct Message {
pub subject: Option<String>,
// Parsed Date header, if found and valid
pub timestamp: Option<i64>,
// Headers
pub headers: Vec<Header>,
// 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,
});