Compare commits
49 Commits
letterbox-
...
letterbox-
| Author | SHA1 | Date | |
|---|---|---|---|
| 17ad5b3b0b | |||
| 285b2f1591 | |||
| 1537333e76 | |||
| 285ff1d098 | |||
| 1563bf05a3 | |||
| 458aab3167 | |||
| 492e420337 | |||
| 330f9b1763 | |||
| ad904ac1c0 | |||
| 20f125bda5 | |||
| cf99e75ab8 | |||
| 54fc1e7962 | |||
| b187edc23b | |||
| fdafba3eeb | |||
| c5fe9f67d2 | |||
| ff970acf79 | |||
| 2f9bc17873 | |||
| 7e82f4ce97 | |||
| 5bb4f010d3 | |||
| 0af630acbe | |||
| d3d350e159 | |||
| 4013e4a7bf | |||
| b63171ea98 | |||
| 1c6ef02d11 | |||
| 32e5837dbf | |||
| 38234d4d18 | |||
| f609a3c122 | |||
| 440a630414 | |||
| ebda258750 | |||
| f766b3d529 | |||
| 96d927d416 | |||
| 60543b7e5d | |||
| 97a7bb6083 | |||
| c493857188 | |||
| 21f344b01c | |||
| 78f6d87c03 | |||
| 6edad4e8f2 | |||
| 8b06950cb8 | |||
| 34417131b0 | |||
| d63e72ad35 | |||
| 33c0a106b7 | |||
| 030d1c2ebe | |||
| e386d7e74e | |||
| 55e38e96a0 | |||
| 7f47fe8de6 | |||
| 3889b855a5 | |||
| 2c1c7abf0a | |||
| 9452a2b014 | |||
| 0df97a7b76 |
40
.github/copilot-instructions.md
vendored
Normal file
40
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copilot/AI Agent Instructions for Letterbox
|
||||
|
||||
## Project Overview
|
||||
- **Letterbox** is a Rust monorepo for a mail/newsreader system with a web frontend and a Rocket/GraphQL backend.
|
||||
- Major crates: `server` (backend, Rocket+async-graphql), `web` (Seed-based WASM frontend), `notmuch` (mail integration), `shared` (common types), `procmail2notmuch` (migration/utility).
|
||||
- Data flows: Email/news data is indexed and queried via the backend, exposed to the frontend via GraphQL. SQLx/Postgres is used for persistence. Notmuch and custom SQL are both used for mail storage/search.
|
||||
|
||||
## Key Workflows
|
||||
- **Development**: Use `dev.sh` to launch a tmux session with live-reloading for both frontend (`trunk serve`) and backend (`cargo watch ... run`).
|
||||
- **Build/Release**: Use `just patch|minor|major` for versioned releases (runs SQLx prepare, bumps versions, pushes). `Makefile`'s `release` target does similar steps.
|
||||
- **Frontend**: In `web/`, use `cargo make serve` and `cargo make watch` for local dev. See `web/README.md` for Seed-specific details.
|
||||
- **Backend**: In `server/`, run with `cargo run` or via the tmux/dev.sh workflow. SQL migrations are in `server/migrations/`.
|
||||
|
||||
## Project Conventions & Patterns
|
||||
- **GraphQL**: All API boundaries are defined in `server/src/graphql.rs`. Use the `Query`, `Mutation`, and `Subscription` roots. Types are defined with `async-graphql` derive macros.
|
||||
- **HTML Sanitization**: See `server/src/lib.rs` for custom HTML/CSS sanitization and transformation logic (e.g., `Transformer` trait, `sanitize_html`).
|
||||
- **Tag/Query Parsing**: The `Query` struct in `server/src/lib.rs` parses user queries into filters for notmuch/newsreader/tantivy.
|
||||
- **Shared Types**: Use the `shared` crate for types and helpers shared between frontend and backend.
|
||||
- **Custom SQL**: Raw SQL queries are in `server/sql/`. Use these for complex queries not handled by SQLx macros.
|
||||
- **Feature Flags**: The `tantivy` feature enables full-text search via Tantivy. Check for `#[cfg(feature = "tantivy")]` in backend code.
|
||||
|
||||
## Integration Points
|
||||
- **Notmuch**: Integrated via the `notmuch` crate for mail indexing/search.
|
||||
- **Postgres**: Used for newsreader and other persistent data (see `server/migrations/`).
|
||||
- **GraphQL**: All client-server communication is via GraphQL endpoints defined in the backend.
|
||||
- **Seed/Trunk**: Frontend is built with Seed (Rust/WASM) and served via Trunk.
|
||||
|
||||
## Examples
|
||||
- To add a new GraphQL query, update `server/src/graphql.rs` and expose it in the `QueryRoot`.
|
||||
- To add a new frontend page, add a module in `web/src/` and register it in the Seed app's router.
|
||||
- To run the full dev environment: `./dev.sh` (requires tmux, trunk, cargo-watch, etc.).
|
||||
|
||||
## References
|
||||
- See `web/README.md` for frontend/Seed workflow details.
|
||||
- See `Justfile` and `Makefile` for release/versioning automation.
|
||||
- See `server/src/lib.rs` and `server/src/graphql.rs` for backend architecture and conventions.
|
||||
- See `server/sql/` for custom SQL queries.
|
||||
|
||||
---
|
||||
If any conventions or workflows are unclear, please ask for clarification or check the referenced files for examples.
|
||||
1162
Cargo.lock
generated
1162
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@ authors = ["Bill Thiede <git@xinu.tv>"]
|
||||
edition = "2021"
|
||||
license = "UNLICENSED"
|
||||
publish = ["xinu"]
|
||||
version = "0.17.41"
|
||||
version = "0.17.45"
|
||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -3,4 +3,11 @@
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
,
|
||||
"packageRules": [
|
||||
{
|
||||
"matchPackageNames": ["wasm-bindgen"],
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ futures = "0.3.31"
|
||||
headers = "0.4.0"
|
||||
html-escape = "0.2.13"
|
||||
ical = "0.11"
|
||||
letterbox-notmuch = { path = "../notmuch", version = "0.17.41", registry = "xinu" }
|
||||
letterbox-shared = { path = "../shared", version = "0.17.41", registry = "xinu" }
|
||||
letterbox-notmuch = { path = "../notmuch", version = "0.17.45", registry = "xinu" }
|
||||
letterbox-shared = { path = "../shared", version = "0.17.45", registry = "xinu" }
|
||||
linkify = "0.10.0"
|
||||
lol_html = "2.3.0"
|
||||
mailparse = "0.16.1"
|
||||
@@ -56,7 +56,7 @@ urlencoding = "2.1.3"
|
||||
#xtracing = { git = "http://git-private.h.xinu.tv/wathiede/xtracing.git" }
|
||||
#xtracing = { path = "../../xtracing" }
|
||||
xtracing = { version = "0.3.2", registry = "xinu" }
|
||||
zip = "4.3.0"
|
||||
zip = "5.0.0"
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
use askama::Template;
|
||||
use chrono::{Datelike, Local, LocalResult, TimeZone, Utc};
|
||||
use chrono::{Datelike, LocalResult, TimeZone, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use mailparse::{parse_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail};
|
||||
use quick_xml::de::from_str as xml_from_str;
|
||||
@@ -17,9 +17,11 @@ use crate::{
|
||||
const APPLICATION_GZIP: &'static str = "application/gzip";
|
||||
|
||||
const APPLICATION_ZIP: &'static str = "application/zip";
|
||||
const APPLICATION_TLSRPT_GZIP: &'static str = "application/tlsrpt+gzip";
|
||||
const IMAGE_JPEG: &'static str = "image/jpeg";
|
||||
const IMAGE_PJPEG: &'static str = "image/pjpeg";
|
||||
const IMAGE_PNG: &'static str = "image/png";
|
||||
const MESSAGE_DELIVERY_STATUS: &'static str = "message/delivery-status";
|
||||
const MESSAGE_RFC822: &'static str = "message/rfc822";
|
||||
const MULTIPART_ALTERNATIVE: &'static str = "multipart/alternative";
|
||||
const MULTIPART_MIXED: &'static str = "multipart/mixed";
|
||||
@@ -641,115 +643,186 @@ pub fn extract_gzip(m: &ParsedMail) -> Result<(Body, Option<String>), ServerErro
|
||||
Ok((extract_unhandled(m)?, None))
|
||||
}
|
||||
|
||||
pub fn extract_report(m: &ParsedMail, _part_addr: &mut Vec<String>) -> Result<Body, ServerError> {
|
||||
let mut html_part = None;
|
||||
let mut tlsrpt_part = None;
|
||||
pub fn extract_report(m: &ParsedMail, part_addr: &mut Vec<String>) -> Result<Body, ServerError> {
|
||||
let mut parts = Vec::new();
|
||||
|
||||
for (idx, sp) in m.subparts.iter().enumerate() {
|
||||
part_addr.push(idx.to_string());
|
||||
|
||||
for sp in &m.subparts {
|
||||
match sp.ctype.mimetype.as_str() {
|
||||
TEXT_HTML => html_part = Some(sp.get_body()?),
|
||||
"application/tlsrpt+gzip" => tlsrpt_part = Some(sp.get_body_raw()?),
|
||||
_ => {} // Ignore other parts for now
|
||||
}
|
||||
}
|
||||
|
||||
let tlsrpt_summary_html = if let Some(gz_bytes) = tlsrpt_part {
|
||||
let mut decoder = flate2::read::GzDecoder::new(&gz_bytes[..]);
|
||||
let mut buffer = Vec::new();
|
||||
if decoder.read_to_end(&mut buffer).is_ok() {
|
||||
if let Ok(json_str) = String::from_utf8(buffer) {
|
||||
match serde_json::from_str::<TlsRpt>(&json_str) {
|
||||
Ok(tlsrpt) => {
|
||||
let formatted_tlsrpt = FormattedTlsRpt {
|
||||
organization_name: tlsrpt.organization_name,
|
||||
date_range: FormattedTlsRptDateRange {
|
||||
start_datetime: tlsrpt.date_range.start_datetime,
|
||||
end_datetime: tlsrpt.date_range.end_datetime,
|
||||
},
|
||||
contact_info: tlsrpt.contact_info.unwrap_or_else(|| "".to_string()),
|
||||
report_id: tlsrpt.report_id,
|
||||
policies: tlsrpt
|
||||
.policies
|
||||
.into_iter()
|
||||
.map(|policy| FormattedTlsRptPolicy {
|
||||
policy: FormattedTlsRptPolicyDetails {
|
||||
policy_type: policy.policy.policy_type,
|
||||
policy_string: policy.policy.policy_string,
|
||||
policy_domain: policy.policy.policy_domain,
|
||||
mx_host: policy
|
||||
.policy
|
||||
.mx_host
|
||||
.unwrap_or_else(|| Vec::new())
|
||||
.into_iter()
|
||||
.map(|mx| match mx {
|
||||
MxHost::String(s) => FormattedTlsRptMxHost {
|
||||
hostname: s,
|
||||
failure_count: 0,
|
||||
result_type: "".to_string(),
|
||||
},
|
||||
MxHost::Object(o) => FormattedTlsRptMxHost {
|
||||
hostname: o.hostname,
|
||||
failure_count: o.failure_count,
|
||||
result_type: o.result_type,
|
||||
},
|
||||
})
|
||||
.collect(),
|
||||
APPLICATION_TLSRPT_GZIP => {
|
||||
let gz_bytes = sp.get_body_raw()?;
|
||||
let mut decoder = flate2::read::GzDecoder::new(&gz_bytes[..]);
|
||||
let mut buffer = Vec::new();
|
||||
if decoder.read_to_end(&mut buffer).is_ok() {
|
||||
if let Ok(json_str) = String::from_utf8(buffer) {
|
||||
match serde_json::from_str::<TlsRpt>(&json_str) {
|
||||
Ok(tlsrpt) => {
|
||||
let formatted_tlsrpt = FormattedTlsRpt {
|
||||
organization_name: tlsrpt.organization_name,
|
||||
date_range: FormattedTlsRptDateRange {
|
||||
start_datetime: tlsrpt.date_range.start_datetime,
|
||||
end_datetime: tlsrpt.date_range.end_datetime,
|
||||
},
|
||||
summary: policy.summary,
|
||||
failure_details: policy
|
||||
.failure_details
|
||||
.unwrap_or_else(|| Vec::new())
|
||||
contact_info: tlsrpt
|
||||
.contact_info
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
report_id: tlsrpt.report_id,
|
||||
policies: tlsrpt
|
||||
.policies
|
||||
.into_iter()
|
||||
.map(|detail| FormattedTlsRptFailureDetails {
|
||||
result_type: detail.result_type,
|
||||
sending_mta_ip: detail
|
||||
.sending_mta_ip
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
receiving_ip: detail
|
||||
.receiving_ip
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
receiving_mx_hostname: detail
|
||||
.receiving_mx_hostname
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
failed_session_count: detail.failed_session_count,
|
||||
additional_info: detail
|
||||
.additional_info
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
failure_reason_code: detail
|
||||
.failure_reason_code
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
.map(|policy| FormattedTlsRptPolicy {
|
||||
policy: FormattedTlsRptPolicyDetails {
|
||||
policy_type: policy.policy.policy_type,
|
||||
policy_string: policy.policy.policy_string,
|
||||
policy_domain: policy.policy.policy_domain,
|
||||
mx_host: policy
|
||||
.policy
|
||||
.mx_host
|
||||
.unwrap_or_else(|| Vec::new())
|
||||
.into_iter()
|
||||
.map(|mx| match mx {
|
||||
MxHost::String(s) => {
|
||||
FormattedTlsRptMxHost {
|
||||
hostname: s,
|
||||
failure_count: 0,
|
||||
result_type: "".to_string(),
|
||||
}
|
||||
}
|
||||
MxHost::Object(o) => {
|
||||
FormattedTlsRptMxHost {
|
||||
hostname: o.hostname,
|
||||
failure_count: o.failure_count,
|
||||
result_type: o.result_type,
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
summary: policy.summary,
|
||||
failure_details: policy
|
||||
.failure_details
|
||||
.unwrap_or_else(|| Vec::new())
|
||||
.into_iter()
|
||||
.map(|detail| FormattedTlsRptFailureDetails {
|
||||
result_type: detail.result_type,
|
||||
sending_mta_ip: detail
|
||||
.sending_mta_ip
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
receiving_ip: detail
|
||||
.receiving_ip
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
receiving_mx_hostname: detail
|
||||
.receiving_mx_hostname
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
failed_session_count: detail
|
||||
.failed_session_count,
|
||||
additional_info: detail
|
||||
.additional_info
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
failure_reason_code: detail
|
||||
.failure_reason_code
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
.collect(),
|
||||
};
|
||||
let template = TlsReportTemplate {
|
||||
report: &formatted_tlsrpt,
|
||||
};
|
||||
template.render().unwrap_or_else(|e| format!("<div class=\"tlsrpt-error\">Failed to render TLS report template: {}</div>", e))
|
||||
};
|
||||
let template = TlsReportTemplate {
|
||||
report: &formatted_tlsrpt,
|
||||
};
|
||||
let html = template.render().unwrap_or_else(|e| format!("<div class=\"tlsrpt-error\">Failed to render TLS report template: {}</div>", e));
|
||||
parts.push(Body::html(html));
|
||||
}
|
||||
Err(e) => {
|
||||
let html = format!(
|
||||
"<div class=\"tlsrpt-error\">Failed to parse TLS report JSON: {}</div>",
|
||||
e
|
||||
);
|
||||
parts.push(Body::html(html));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let html = format!("<div class=\"tlsrpt-error\">Failed to convert decompressed data to UTF-8.</div>");
|
||||
parts.push(Body::html(html));
|
||||
}
|
||||
} else {
|
||||
let html =
|
||||
format!("<div class=\"tlsrpt-error\">Failed to decompress data.</div>");
|
||||
parts.push(Body::html(html));
|
||||
}
|
||||
}
|
||||
MESSAGE_RFC822 => {
|
||||
parts.push(extract_rfc822(&sp, part_addr)?);
|
||||
}
|
||||
TEXT_HTML => {
|
||||
let body = sp.get_body()?;
|
||||
parts.push(Body::html(body));
|
||||
}
|
||||
MESSAGE_DELIVERY_STATUS => {
|
||||
let body = extract_delivery_status(sp)?;
|
||||
parts.push(body);
|
||||
}
|
||||
TEXT_PLAIN => {
|
||||
let body = sp.get_body()?;
|
||||
parts.push(Body::text(body));
|
||||
}
|
||||
_ => {
|
||||
// For any other content type, try to extract the body using the general extract_body function
|
||||
match extract_body(sp, part_addr) {
|
||||
Ok(body) => parts.push(body),
|
||||
Err(_) => {
|
||||
// If extraction fails, create an unhandled content type body
|
||||
let msg = format!(
|
||||
"Unhandled report subpart content type: {}\n{}",
|
||||
sp.ctype.mimetype,
|
||||
sp.get_body()
|
||||
.unwrap_or_else(|_| "Failed to get body".to_string())
|
||||
);
|
||||
parts.push(Body::UnhandledContentType(UnhandledContentType {
|
||||
text: msg,
|
||||
content_tree: render_content_type_tree(sp),
|
||||
}));
|
||||
}
|
||||
Err(e) => format!(
|
||||
"<div class=\"tlsrpt-error\">Failed to parse TLS report JSON: {}</div>",
|
||||
e
|
||||
),
|
||||
}
|
||||
} else {
|
||||
format!("<div class=\"tlsrpt-error\">Failed to convert decompressed data to UTF-8.</div>")
|
||||
}
|
||||
} else {
|
||||
format!("<div class=\"tlsrpt-error\">Failed to decompressed data.</div>")
|
||||
}
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let final_html = if let Some(html) = html_part {
|
||||
format!("{}<hr>{} ", html, tlsrpt_summary_html)
|
||||
} else {
|
||||
tlsrpt_summary_html
|
||||
};
|
||||
part_addr.pop();
|
||||
}
|
||||
|
||||
Ok(Body::html(final_html))
|
||||
if parts.is_empty() {
|
||||
return Ok(Body::html(
|
||||
"<div class=\"report-error\">No report content found</div>".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// Add <hr> tags between subparts for better visual separation
|
||||
let html = parts
|
||||
.iter()
|
||||
.map(|p| match p {
|
||||
Body::PlainText(PlainText { text, .. }) => {
|
||||
format!(
|
||||
r#"<p class="view-part-text-plain font-mono whitespace-pre-line">{}</p>"#,
|
||||
linkify_html(&html_escape::encode_text(text).trim_matches('\n'))
|
||||
)
|
||||
}
|
||||
Body::Html(Html { html, .. }) => html.clone(),
|
||||
Body::UnhandledContentType(UnhandledContentType { text, .. }) => {
|
||||
format!(
|
||||
r#"<p class="view-part-unhandled">{}</p>"#,
|
||||
linkify_html(&html_escape::encode_text(text).trim_matches('\n'))
|
||||
)
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("<hr>\n");
|
||||
|
||||
Ok(Body::html(html))
|
||||
}
|
||||
|
||||
pub fn extract_delivery_status(m: &ParsedMail) -> Result<Body, ServerError> {
|
||||
Ok(Body::text(m.get_body()?))
|
||||
}
|
||||
|
||||
pub fn extract_unhandled(m: &ParsedMail) -> Result<Body, ServerError> {
|
||||
@@ -1837,39 +1910,42 @@ pub fn render_ical_summary(ical_data: &str) -> Result<String, ServerError> {
|
||||
}
|
||||
}
|
||||
|
||||
// Always use America/Los_Angeles for Google Calendar events if no TZID is present
|
||||
let event_tz: Tz = tzid
|
||||
.as_deref()
|
||||
.unwrap_or("America/Los_Angeles")
|
||||
.parse()
|
||||
.unwrap_or(chrono_tz::America::Los_Angeles);
|
||||
|
||||
// Parse start/end as chrono DateTime
|
||||
let (local_fmt_start, local_fmt_end, event_days, recurrence_display) =
|
||||
if let Some(dtstart) = dtstart {
|
||||
let tz: Tz = tzid
|
||||
.as_deref()
|
||||
.unwrap_or("UTC")
|
||||
.parse()
|
||||
.unwrap_or(chrono_tz::UTC);
|
||||
let fallback = chrono::DateTime::<chrono::Utc>::from_timestamp(0, 0)
|
||||
.map(|dt| dt.with_timezone(&tz))
|
||||
.map(|dt| dt.with_timezone(&event_tz))
|
||||
.unwrap_or_else(|| {
|
||||
tz.with_ymd_and_hms(1970, 1, 1, 0, 0, 0)
|
||||
event_tz
|
||||
.with_ymd_and_hms(1970, 1, 1, 0, 0, 0)
|
||||
.single()
|
||||
.unwrap_or_else(|| tz.timestamp_opt(0, 0).single().unwrap())
|
||||
.unwrap_or_else(|| event_tz.timestamp_opt(0, 0).single().unwrap())
|
||||
});
|
||||
let start = parse_ical_datetime_tz(dtstart, tz).unwrap_or(fallback);
|
||||
let start = parse_ical_datetime_tz(dtstart, event_tz).unwrap_or(fallback);
|
||||
let end = dtend
|
||||
.and_then(|d| parse_ical_datetime_tz(d, tz))
|
||||
.and_then(|d| parse_ical_datetime_tz(d, event_tz))
|
||||
.unwrap_or(start);
|
||||
let local_start = start.with_timezone(&Local);
|
||||
let local_end = end.with_timezone(&Local);
|
||||
// Use the event's TZ for all calendar grid/highlighting logic
|
||||
let allday =
|
||||
dtstart.len() == 8 && (dtend.map(|s| s.len() == 8).unwrap_or(false));
|
||||
let fmt_start = if allday {
|
||||
local_start.format("%a %b %e, %Y").to_string()
|
||||
start.format("%a %b %e, %Y").to_string()
|
||||
} else {
|
||||
local_start.format("%-I:%M %p %a %b %e, %Y").to_string()
|
||||
start.format("%-I:%M %p %a %b %e, %Y").to_string()
|
||||
};
|
||||
let fmt_end = if allday {
|
||||
local_end.format("%a %b %e, %Y").to_string()
|
||||
end.format("%a %b %e, %Y").to_string()
|
||||
} else {
|
||||
local_end.format("%-I:%M %p %a %b %e, %Y").to_string()
|
||||
end.format("%-I:%M %p %a %b %e, %Y").to_string()
|
||||
};
|
||||
// All calendar grid and event_days logic below uses start/end in event's TZ
|
||||
|
||||
// Recurrence support: parse RRULE and generate event_days accordingly
|
||||
let mut days = vec![];
|
||||
@@ -2144,6 +2220,39 @@ fn parse_ical_datetime_tz(dt: &str, tz: Tz) -> Option<chrono::DateTime<Tz>> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn google_calendar_email_thursday_highlights_thursday() {
|
||||
use mailparse::parse_mail;
|
||||
let raw_email = include_str!("../../server/testdata/google-calendar-example-thursday.eml");
|
||||
let parsed = parse_mail(raw_email.as_bytes()).expect("parse_mail");
|
||||
let mut part_addr = vec![];
|
||||
let body = extract_body(&parsed, &mut part_addr).expect("extract_body");
|
||||
let meta = extract_calendar_metadata_from_mail(&parsed, &body);
|
||||
// Assert detection as Google Calendar
|
||||
assert!(meta.is_google_calendar_event);
|
||||
let html = meta.body_html.expect("body_html");
|
||||
|
||||
// Print event date info for debugging
|
||||
for part in parsed.subparts.iter() {
|
||||
if part.ctype.mimetype == TEXT_CALENDAR {
|
||||
if let Ok(ical) = part.get_body() {
|
||||
println!("ICAL data: {}", ical);
|
||||
if let Some(start) = ical.lines().find(|l| l.starts_with("DTSTART:")) {
|
||||
println!("Start date: {}", start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("Rendered HTML: {}", html);
|
||||
|
||||
// Look for September 11 (Thursday) being highlighted
|
||||
// The calendar should show Sept 11 highlighted with background:#ffd700 and the correct data-event-day
|
||||
assert!(html.contains(r#"data-event-day="2025-09-11""#));
|
||||
assert!(html.contains(r#"background:#ffd700"#));
|
||||
|
||||
// Since 1:00 AM UTC on Friday 9/12 is 6:00 PM PDT on Thursday 9/11, verify times are correct
|
||||
assert!(html.contains("6:00 PM Thu Sep 11, 2025"));
|
||||
}
|
||||
use super::*;
|
||||
#[test]
|
||||
fn google_calendar_email_3_single_event_metadata() {
|
||||
|
||||
@@ -74,13 +74,7 @@
|
||||
{% for week in all_days|batch(7) %}
|
||||
<tr>
|
||||
{% for day in week %}
|
||||
{% if event_days.contains(day) && today.is_some() && today.unwrap() == day %}
|
||||
<td
|
||||
data-event-day="{{ day.format("%Y-%m-%d") }}"
|
||||
style="background:#ffd700; color:#222; font-weight:bold; border:2px solid #2196f3; border-radius:4px; text-align:center; box-shadow:0 0 0 2px #2196f3;">
|
||||
{{ day.day() }}
|
||||
</td>
|
||||
{% elif event_days.contains(day) %}
|
||||
{% if event_days.contains(day) %}
|
||||
<td
|
||||
data-event-day="{{ day.format("%Y-%m-%d") }}"
|
||||
style="background:#ffd700; color:#222; font-weight:bold; border:1px solid #aaa; border-radius:4px; text-align:center;">
|
||||
|
||||
175
server/testdata/google-calendar-example-thursday.eml
vendored
Normal file
175
server/testdata/google-calendar-example-thursday.eml
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
Return-Path: <couchmoney+caf_=gmail=xinu.tv@gmail.com>
|
||||
Delivered-To: bill@xinu.tv
|
||||
Received: from phx.xinu.tv [74.207.253.222]
|
||||
by nixos-01.h.xinu.tv with IMAP (fetchmail-6.5.1)
|
||||
for <wathiede@localhost> (single-drop); Thu, 11 Sep 2025 12:27:35 -0700 (PDT)
|
||||
Received: from phx.xinu.tv
|
||||
by phx.xinu.tv with LMTP
|
||||
id CqRrBqciw2hiKicAJR8clQ
|
||||
(envelope-from <couchmoney+caf_=gmail=xinu.tv@gmail.com>)
|
||||
for <bill@xinu.tv>; Thu, 11 Sep 2025 12:27:35 -0700
|
||||
X-Original-To: gmail@xinu.tv
|
||||
Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a00:1450:4864:20::130; helo=mail-lf1-x130.google.com; envelope-from=couchmoney+caf_=gmail=xinu.tv@gmail.com; receiver=xinu.tv
|
||||
Authentication-Results: phx.xinu.tv;
|
||||
dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=dc+iKaXd;
|
||||
dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=kf8o8wAd
|
||||
Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130])
|
||||
by phx.xinu.tv (Postfix) with ESMTPS id D7E2D80037
|
||||
for <gmail@xinu.tv>; Thu, 11 Sep 2025 12:27:33 -0700 (PDT)
|
||||
Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-55f716e25d9so1141446e87.1
|
||||
for <gmail@xinu.tv>; Thu, 11 Sep 2025 12:27:33 -0700 (PDT)
|
||||
ARC-Seal: i=2; a=rsa-sha256; t=1757618852; cv=pass;
|
||||
d=google.com; s=arc-20240605;
|
||||
b=MZ+1JfQuPR9luCCxiZNUeqSEpjt1vLuM3bTRCaal/W0NBxkCH0y5v9WfPR0KJ2BPb1
|
||||
Rtnt/5ayDtmsLf8l6yTTVsBlFYW70ehqXWMD10MMcDEMvnib4KKDAacGaSmijAK4cYGq
|
||||
FOU9CGNY986OMXMk54TD9NF3fkKDIKcAoh81D6at5/DE3Puuxofq0vZmtmVqQBNKG169
|
||||
REkhcDpkXTMs/4rJpmZwXp2HbjD84avusBwSlYIQUWsBgO4g7THHjoR4Uk56cek9aEds
|
||||
ip8IkTO6KRFe6u8FebQsZ/Q9sSAK3pheMExWFVMha9Y0XhACVOZiV600zRCPS9MNHhYw
|
||||
XEaA==
|
||||
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
|
||||
h=to:from:subject:date:message-id:auto-submitted:sender:reply-to
|
||||
:mime-version:dkim-signature:dkim-signature:delivered-to;
|
||||
bh=mVNsDGUAhSGrAIoTy8PIfvCBxBB4yaBy/VZH8i3gPl4=;
|
||||
fh=WnbwIlqFRbBot/H7TyqablNBDgXRuegsgjC3piothTI=;
|
||||
b=aYMo5f7VI2b4CiAvLELRJ9zM3dF7ZH8FEqmoAtCcfPHrT9kLLCnriuyXG1R6sC3eoR
|
||||
++boT29xoScVroIlfcI77Ty7N5X1fawOABkVDWWt7z5w4WhiesT0klxw5nINj9hnLBiK
|
||||
22nrMevpRpFtmuDO7cle78lSAFZoZuyv+aXCK9RnLKvIm2JuXRrvU8LivxbbpNB4gNl0
|
||||
hE1jsGuZm1SOJ54SRLwwa4HpSiOJV2x2txTtPCzmvE/LZvNESPjfi3Y2u7gaR87OzkNs
|
||||
gNi5Xoc+D908zBsmcYKpUYiQcPL79s3DfNwYFIs/rR8Z2xgaHbFD/YmqRUmCEeNLv7o2
|
||||
RR8g==;
|
||||
darn=xinu.tv
|
||||
ARC-Authentication-Results: i=2; mx.google.com;
|
||||
dkim=pass header.i=@google.com header.s=20230601 header.b=dc+iKaXd;
|
||||
dkim=pass header.i=@gmail.com header.s=20230601 header.b=kf8o8wAd;
|
||||
spf=pass (google.com: domain of tconvertino@gmail.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=tconvertino@gmail.com;
|
||||
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com;
|
||||
dara=pass header.i=@gmail.com
|
||||
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
|
||||
d=1e100.net; s=20230601; t=1757618852; x=1758223652;
|
||||
h=to:from:subject:date:message-id:auto-submitted:sender:reply-to
|
||||
:mime-version:dkim-signature:dkim-signature:delivered-to
|
||||
:x-forwarded-for:x-forwarded-to:x-gm-message-state:from:to:cc
|
||||
:subject:date:message-id:reply-to;
|
||||
bh=mVNsDGUAhSGrAIoTy8PIfvCBxBB4yaBy/VZH8i3gPl4=;
|
||||
b=GKJkb+LmE79XIMEhHRvoCodKS+GBTOCShzMe06Q+zKxUZFHi6XMg8GqteuXQO9LVbw
|
||||
nPUVN4QO2Hvqch0xzjbc0ryyMOD0u7HqpDUAEZCzamFXIfsX6hZXKLhFqy4YomtsG3os
|
||||
TCOWBGLqwu7KalfOVg2p+csOR68i0mGyBII1sKcL9vUv9kIQJZxQKHGkuIc48cf6tbUB
|
||||
L+mkVbMwXLSbpuTJszPmIVZV5o0K52KN+2QoLcmXGfw0mUOnjNI0oSovdbPg4SSDZ3cw
|
||||
iIsC9vjvtCSFS3pf+Fp807s+Zjh5P6xeSxGU57qhC+HT9kTzIioh5EqKnGqcskDTqrI1
|
||||
uCiQ==
|
||||
X-Forwarded-Encrypted: i=2; AJvYcCUfSSA2sT31daRt2+W7dAD9YPx1gqa4JFpVuqCtxVtjqbKfKhOX/EcDQiECQ4BEWjmAP+IqTQ==@xinu.tv
|
||||
X-Gm-Message-State: AOJu0Ywn7D0BjTaGiM/UFG0WhGuyYGfpLijg+ouhrOaGZzSREyTcRa37
|
||||
XA3bzQ/LKTpzWhhh01GMwnigmELbWdIVr/BeRLVCuJdh+m+JBMgnAjBTIDs9RF3/xfR7rpG7VOB
|
||||
6k+ugF+8QRKB4BcL2t8MvfJD03CkrzuhhvUtFTRHopcSZrkqzh8GOJayq42VveQ==
|
||||
X-Received: by 2002:a05:6512:3b24:b0:55f:6580:818c with SMTP id 2adb3069b0e04-57050fe2fa3mr165340e87.46.1757618851553;
|
||||
Thu, 11 Sep 2025 12:27:31 -0700 (PDT)
|
||||
X-Forwarded-To: gmail@xinu.tv
|
||||
X-Forwarded-For: couchmoney@gmail.com gmail@xinu.tv
|
||||
Delivered-To: couchmoney@gmail.com
|
||||
Received: by 2002:a05:6504:d09:b0:2c3:f6c4:ad72 with SMTP id c9csp3388833lty;
|
||||
Thu, 11 Sep 2025 12:27:29 -0700 (PDT)
|
||||
X-Received: by 2002:a05:6602:36ce:b0:889:b536:779b with SMTP id ca18e2360f4ac-8903378d714mr78653239f.7.1757618849269;
|
||||
Thu, 11 Sep 2025 12:27:29 -0700 (PDT)
|
||||
ARC-Seal: i=1; a=rsa-sha256; t=1757618849; cv=none;
|
||||
d=google.com; s=arc-20240605;
|
||||
b=Ln2bufZfSNhR/NmMPrG2QFdtvupjJtLDQnFvsL8HTPn+Dlrt5ff+6k6Wpupab/5mS7
|
||||
hXjtVD0jnryGUiM5h+SNjxwzNPM3PBoueTpAzzBkjHQqMxJVpspgsGJUVOWAVRBWtWo
|
||||
39qFyoP0vhzGRWDAuAFV+4VDhsvH7GL8lTrZCSMzrngTadmEdJ5haUIQOa50KFUn5HrK
|
||||
1r12gayb+TaGaWfQfDo0Me689T8MQnS0ITUuzgvFxfgHZBz3h+IPnC0hrlhdziGovETo
|
||||
GvHzgCCtiVzu6rop6VMLjLuAYmmT9+jZ3GjSRb+078C9cJR17YpguOC14Cyv4od1Tf7y
|
||||
RFiQ==;
|
||||
dara=google.com
|
||||
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
|
||||
h=to:from:subject:date:message-id:auto-submitted:sender:reply-to
|
||||
:mime-version:dkim-signature:dkim-signature;
|
||||
bh=mVNsDGUAhSGrAIoTy8PIfvCBxBB4yaBy/VZH8i3gPl4=;
|
||||
fh=mbzrMIWIgWMC0ni1xEx+ViW4J0RLAdLdPT2cX81nTlk=;
|
||||
b=JRkHr3CKSkCrafdLzBRtaBOGNl3/0ZSTtgubaNXtvhAiIqRqiQYocfLnVM6N/9sH7O
|
||||
byTXYaRoaRLw/35WM+QTFGP3zUGRkM3eO4UVS/utVIss1IVLDjfmZHalqLYl8RokW5br
|
||||
89Z/xYIyjTE7WUdy6uMSrExCNm5VWjO/qcMKsE5s5oDbXdSLaUYxLTurICM3LQksGkCY
|
||||
wiAWaDDqK14+uhEhW5AyEnebDSYhL9U8UadIv+eK6Ng9q1kwOUzxICRQXEyUtnKhaDKJ
|
||||
eZ1Qe1mp1CjCulr+I15fz3VwUJ6W1cv6cytcxPbu4p5GPn2gb2hS1eR81HVTL6V1Sp5G
|
||||
NdDQ==;
|
||||
dara=google.com
|
||||
ARC-Authentication-Results: i=1; mx.google.com;
|
||||
dkim=pass header.i=@google.com header.s=20230601 header.b=dc+iKaXd;
|
||||
dkim=pass header.i=@gmail.com header.s=20230601 header.b=kf8o8wAd;
|
||||
spf=pass (google.com: domain of tconvertino@gmail.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=tconvertino@gmail.com;
|
||||
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com;
|
||||
dara=pass header.i=@gmail.com
|
||||
Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73])
|
||||
by mx.google.com with SMTPS id ca18e2360f4ac-88f2ea1122asor117632339f.3.2025.09.11.12.27.29
|
||||
for <couchmoney@gmail.com>
|
||||
(Google Transport Security);
|
||||
Thu, 11 Sep 2025 12:27:29 -0700 (PDT)
|
||||
Received-SPF: pass (google.com: domain of tconvertino@gmail.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73;
|
||||
Authentication-Results: mx.google.com;
|
||||
dkim=pass header.i=@google.com header.s=20230601 header.b=dc+iKaXd;
|
||||
dkim=pass header.i=@gmail.com header.s=20230601 header.b=kf8o8wAd;
|
||||
spf=pass (google.com: domain of tconvertino@gmail.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=tconvertino@gmail.com;
|
||||
dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com;
|
||||
dara=pass header.i=@gmail.com
|
||||
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
|
||||
d=google.com; s=20230601; t=1757618849; x=1758223649; dara=google.com;
|
||||
h=to:from:subject:date:message-id:auto-submitted:sender:reply-to
|
||||
:mime-version:from:to:cc:subject:date:message-id:reply-to;
|
||||
bh=mVNsDGUAhSGrAIoTy8PIfvCBxBB4yaBy/VZH8i3gPl4=;
|
||||
b=dc+iKaXdFyqu6K0MIgk848QuwpQXvwzwlEVkxmjuCWvn9DzanMbYn5QJRyRTKilRna
|
||||
BZ7gJSPriHUHcJd4fVKgGuCaQg0TxenCwm+0R64oB1xcDLfonayo/nCrFqEcCLHNmi7x
|
||||
lTyWGJ0rLw6nKazxtcCdIbDhVgiE7/fXNI89w6XFp6pcKLl48yFIoCG1f6uY4iQ7QqNU
|
||||
hLHzjmlzjTi58xFLao7SizZ0lr7E5cHXKHp1Ls/hkDzzcY0Y+O5+3r+NQw4MtpHTcY6/
|
||||
kQlg6OhyMx8PTu4cuepQKXLHV4aFaNJbDQTp8wew4xPIgi7pm2p6hb6C3GgwY6ptOvLd
|
||||
wuag==
|
||||
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
|
||||
d=gmail.com; s=20230601; t=1757618849; x=1758223649; dara=google.com;
|
||||
h=to:from:subject:date:message-id:auto-submitted:sender:reply-to
|
||||
:mime-version:from:to:cc:subject:date:message-id:reply-to;
|
||||
bh=mVNsDGUAhSGrAIoTy8PIfvCBxBB4yaBy/VZH8i3gPl4=;
|
||||
b=kf8o8wAd5DSU/NC7SDiuIoohCu+/7wTjWyQqDYbBjUFGaBaYdj6aD5JWNQ1KEA2W8o
|
||||
E+Qy2ymyrzodKa1eOsQX2UDAYKOKpdxMWvx1u19+SC3Dp8DP4puRMrL2ObiSEMLCuOvz
|
||||
Mxmkd+ZUP72EhVuQwK1iSm04/cjQaMsSiPhvSBaxXMaaarwlKeOoCoIo+qC/Z9emiBBv
|
||||
Gk0sQcLA+CByvsxuvD9GInSA0rdoZ0ijhSb0Y475Hieam1QQqy/fhe8lgujzhXNFoIbR
|
||||
5EA9GE0VV9PDoNanaT+u954YeOFBL2YZ5gm2gHltw8tBI98LKnC42Pa3qyMznBa2dI2Q
|
||||
A0RQ==
|
||||
X-Google-Smtp-Source: AGHT+IGmC5/03nTVMeYJBoq1R/BiA19iH0DFaZyyImB3W8mtgjdn+XqIFK1fC8aTwWRXQmsr71Xo0cmkgx6hjPvicQ/d
|
||||
MIME-Version: 1.0
|
||||
X-Received: by 2002:a05:6602:380d:b0:887:4c93:f12c with SMTP id
|
||||
ca18e2360f4ac-8903596aca3mr58994639f.17.1757618848817; Thu, 11 Sep 2025
|
||||
12:27:28 -0700 (PDT)
|
||||
Reply-To: tconvertino@gmail.com
|
||||
Sender: Google Calendar <calendar-notification@google.com>
|
||||
Auto-Submitted: auto-generated
|
||||
Message-ID: <calendar-01d5e8a0-fad7-450b-9758-a16472bf2aa8@google.com>
|
||||
Date: Thu, 11 Sep 2025 19:27:28 +0000
|
||||
Subject: Canceled event: Scout Babysits @ Thu Sep 11, 2025 6pm - 9pm (PDT) (Family)
|
||||
From: tconvertino@gmail.com
|
||||
To: couchmoney@gmail.com
|
||||
Content-Type: multipart/mixed; boundary="000000000000226b77063e8b878d"
|
||||
|
||||
--000000000000226b77063e8b878d
|
||||
Content-Type: text/calendar; charset="UTF-8"; method=CANCEL
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Google Inc//Google Calendar 70.9054//EN
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:CANCEL
|
||||
X-GOOGLE-CALID:g66m0feuqsao8l1c767pvvcg4k@group.calendar.google.com
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20250912T010000Z
|
||||
DTEND:20250912T040000Z
|
||||
DTSTAMP:20250911T192728Z
|
||||
UID:4ang6172d1t7782sn2hmi30fgi@google.com
|
||||
CREATED:20250901T224707Z
|
||||
DESCRIPTION:
|
||||
LAST-MODIFIED:20250911T192728Z
|
||||
LOCATION:
|
||||
SEQUENCE:1
|
||||
STATUS:CANCELLED
|
||||
SUMMARY:Scout Babysits
|
||||
TRANSP:OPAQUE
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
|
||||
--000000000000226b77063e8b878d--
|
||||
@@ -12,7 +12,7 @@ version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
build-info = "0.0.41"
|
||||
letterbox-notmuch = { path = "../notmuch", version = "0.17.41", registry = "xinu" }
|
||||
letterbox-notmuch = { path = "../notmuch", version = "0.17.45", registry = "xinu" }
|
||||
regex = "1.11.1"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
sqlx = "0.8.5"
|
||||
|
||||
@@ -12,7 +12,7 @@ version.workspace = true
|
||||
build-info-build = "0.0.41"
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.50"
|
||||
#wasm-bindgen-test = "0.3.50"
|
||||
|
||||
[dependencies]
|
||||
console_error_panic_hook = "0.1.7"
|
||||
@@ -33,7 +33,7 @@ wasm-bindgen = "=0.2.100"
|
||||
uuid = { version = "1.16.0", features = [
|
||||
"js",
|
||||
] } # direct dep to set js feature, prevents Rng issues
|
||||
letterbox-shared = { path = "../shared/", version = "0.17.41", registry = "xinu" }
|
||||
letterbox-shared = { path = "../shared/", version = "0.17.45", registry = "xinu" }
|
||||
seed_hooks = { version = "0.4.1", registry = "xinu" }
|
||||
strum_macros = "0.27.1"
|
||||
gloo-console = "0.3.0"
|
||||
|
||||
@@ -1058,6 +1058,8 @@ fn message_render(msg: &ShowThreadQueryThreadOnEmailThreadMessages, open: bool)
|
||||
},
|
||||
) => div![
|
||||
C!["view-part-text-html"],
|
||||
// If there isn't any HTML tags, treat more like plain text
|
||||
IF!(!(contents.contains('<') && contents.contains('>')) => C!["whitespace-pre-line"]),
|
||||
raw![contents],
|
||||
IF!(!msg.attachments.is_empty() => render_attachements(&msg.attachments)),
|
||||
view_content_tree(&content_tree),
|
||||
|
||||
Reference in New Issue
Block a user