From 501ee417c9f79504a53f7b0f9cdfc3bdd8597177 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 13 Aug 2025 16:07:35 -0700 Subject: [PATCH] server: address lint --- server/src/email_extract.rs | 63 +++++++++++++++++++------------------ server/src/nm.rs | 9 ++---- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/server/src/email_extract.rs b/server/src/email_extract.rs index 38b97e9..c6c5eb2 100644 --- a/server/src/email_extract.rs +++ b/server/src/email_extract.rs @@ -1,29 +1,16 @@ -use std::{ - collections::{HashMap, HashSet}, - fs::File, - io::{Cursor, Read}, -}; +use std::io::{Cursor, Read}; use askama::Template; use chrono::{TimeZone, Utc}; -use letterbox_notmuch::Notmuch; -use letterbox_shared::{compute_color, Rule}; use mailparse::{parse_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail}; -use memmap::MmapOptions; use quick_xml::de::from_str as xml_from_str; -use sqlx::{types::Json, PgPool}; -use tracing::{error, info, info_span, instrument, warn}; - +use tracing::{error, info, warn}; use zip::ZipArchive; use crate::{ - compute_offset_limit, error::ServerError, - graphql::{ - Attachment, Body, Corpus, DispositionType, Email, EmailThread, Header, Html, Message, - PlainText, Tag, Thread, ThreadSummary, UnhandledContentType, - }, - linkify_html, InlineStyle, Query, SanitizeHtml, Transformer, + graphql::{Attachment, Body, DispositionType, Email, Html, PlainText, UnhandledContentType}, + linkify_html, }; const APPLICATION_GZIP: &'static str = "application/gzip"; @@ -40,8 +27,6 @@ const MULTIPART_REPORT: &'static str = "multipart/report"; const TEXT_HTML: &'static str = "text/html"; const TEXT_PLAIN: &'static str = "text/plain"; -const MAX_RAW_MESSAGE_SIZE: usize = 100_000; - pub fn email_addresses( _path: &str, m: &ParsedMail, @@ -161,10 +146,13 @@ pub fn extract_gzip(m: &ParsedMail) -> Result<(Body, Option), ServerErro if decoder.read_to_string(&mut xml).is_ok() { match parse_dmarc_report(&xml) { Ok(report) => { - return Ok((Body::html(format!( - "
DMARC report summary:
{}
", - report - )), Some(xml))); + return Ok(( + Body::html(format!( + "
DMARC report summary:
{}
", + report + )), + Some(xml), + )); } Err(e) => { return Ok((Body::html(format!( @@ -311,7 +299,10 @@ pub fn is_dmarc_report_filename(name: &str) -> bool { // multipart/alternative defines multiple representations of the same message, and clients should // show the fanciest they can display. For this program, the priority is text/html, text/plain, // then give up. -pub fn extract_alternative(m: &ParsedMail, part_addr: &mut Vec) -> Result { +pub fn extract_alternative( + m: &ParsedMail, + part_addr: &mut Vec, +) -> Result { let handled_types = vec![ MULTIPART_ALTERNATIVE, MULTIPART_MIXED, @@ -437,7 +428,10 @@ pub fn extract_mixed(m: &ParsedMail, part_addr: &mut Vec) -> Result{}", html_escape::encode_text(&pretty_printed_content)))); + parts.push(Body::html(format!( + "\n
{}
", + html_escape::encode_text(&pretty_printed_content) + ))); } } mt => parts.push(unhandled_html(MULTIPART_MIXED, mt)), @@ -1186,11 +1180,14 @@ pub fn parse_dmarc_report(xml: &str) -> Result { } pub fn pretty_print_xml_with_trimming(xml_input: &str) -> Result { - use quick_xml::events::{BytesText, Event}; - use quick_xml::reader::Reader; - use quick_xml::writer::Writer; use std::io::Cursor; + use quick_xml::{ + events::{BytesText, Event}, + reader::Reader, + writer::Writer, + }; + let mut reader = Reader::from_str(xml_input); reader.config_mut().trim_text(true); @@ -1207,11 +1204,17 @@ pub fn pretty_print_xml_with_trimming(xml_input: &str) -> Result { writer.write_event(event)?; } - Err(e) => return Err(ServerError::StringError(format!("XML parsing error: {}", e))), + Err(e) => { + return Err(ServerError::StringError(format!( + "XML parsing error: {}", + e + ))) + } } buf.clear(); } let result = writer.into_inner().into_inner(); Ok(String::from_utf8(result)?) -} \ No newline at end of file +} + diff --git a/server/src/nm.rs b/server/src/nm.rs index 2d4face..f9e925d 100644 --- a/server/src/nm.rs +++ b/server/src/nm.rs @@ -4,13 +4,10 @@ use std::{ io::{Cursor, Read}, }; -use askama::Template; -use chrono::{TimeZone, Utc}; use letterbox_notmuch::Notmuch; use letterbox_shared::{compute_color, Rule}; -use mailparse::{parse_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail}; +use mailparse::{parse_mail, MailHeader, MailHeaderMap}; use memmap::MmapOptions; -use quick_xml::de::from_str as xml_from_str; use sqlx::{types::Json, PgPool}; use tracing::{error, info, info_span, instrument, warn}; use zip::ZipArchive; @@ -20,8 +17,8 @@ use crate::{ email_extract::*, error::ServerError, graphql::{ - Attachment, Body, Corpus, DispositionType, Email, EmailThread, Header, Html, Message, - PlainText, Tag, Thread, ThreadSummary, UnhandledContentType, + Attachment, Body, Corpus, EmailThread, Header, Html, Message, PlainText, Tag, Thread, + ThreadSummary, UnhandledContentType, }, linkify_html, InlineStyle, Query, SanitizeHtml, Transformer, };