server: address lint

This commit is contained in:
Bill Thiede 2025-08-13 16:07:35 -07:00
parent ecc0a88341
commit 501ee417c9
2 changed files with 36 additions and 36 deletions

View File

@ -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<String>), ServerErro
if decoder.read_to_string(&mut xml).is_ok() {
match parse_dmarc_report(&xml) {
Ok(report) => {
return Ok((Body::html(format!(
"<div class=\"dmarc-report\">DMARC report summary:<br>{}</div>",
report
)), Some(xml)));
return Ok((
Body::html(format!(
"<div class=\"dmarc-report\">DMARC report summary:<br>{}</div>",
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<String>) -> Result<Body, ServerError> {
pub fn extract_alternative(
m: &ParsedMail,
part_addr: &mut Vec<String>,
) -> Result<Body, ServerError> {
let handled_types = vec![
MULTIPART_ALTERNATIVE,
MULTIPART_MIXED,
@ -437,7 +428,10 @@ pub fn extract_mixed(m: &ParsedMail, part_addr: &mut Vec<String>) -> Result<Body
}
}
};
parts.push(Body::html(format!("\n<pre>{}</pre>", html_escape::encode_text(&pretty_printed_content))));
parts.push(Body::html(format!(
"\n<pre>{}</pre>",
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<String, ServerError> {
}
pub fn pretty_print_xml_with_trimming(xml_input: &str) -> Result<String, ServerError> {
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<String, ServerE
Ok(event) => {
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)?)
}
}

View File

@ -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,
};