server: address lint
This commit is contained in:
parent
ecc0a88341
commit
501ee417c9
@ -1,29 +1,16 @@
|
|||||||
use std::{
|
use std::io::{Cursor, Read};
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
fs::File,
|
|
||||||
io::{Cursor, Read},
|
|
||||||
};
|
|
||||||
|
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use chrono::{TimeZone, Utc};
|
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_content_type, parse_mail, MailHeader, MailHeaderMap, ParsedMail};
|
||||||
use memmap::MmapOptions;
|
|
||||||
use quick_xml::de::from_str as xml_from_str;
|
use quick_xml::de::from_str as xml_from_str;
|
||||||
use sqlx::{types::Json, PgPool};
|
use tracing::{error, info, warn};
|
||||||
use tracing::{error, info, info_span, instrument, warn};
|
|
||||||
|
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
compute_offset_limit,
|
|
||||||
error::ServerError,
|
error::ServerError,
|
||||||
graphql::{
|
graphql::{Attachment, Body, DispositionType, Email, Html, PlainText, UnhandledContentType},
|
||||||
Attachment, Body, Corpus, DispositionType, Email, EmailThread, Header, Html, Message,
|
linkify_html,
|
||||||
PlainText, Tag, Thread, ThreadSummary, UnhandledContentType,
|
|
||||||
},
|
|
||||||
linkify_html, InlineStyle, Query, SanitizeHtml, Transformer,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const APPLICATION_GZIP: &'static str = "application/gzip";
|
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_HTML: &'static str = "text/html";
|
||||||
const TEXT_PLAIN: &'static str = "text/plain";
|
const TEXT_PLAIN: &'static str = "text/plain";
|
||||||
|
|
||||||
const MAX_RAW_MESSAGE_SIZE: usize = 100_000;
|
|
||||||
|
|
||||||
pub fn email_addresses(
|
pub fn email_addresses(
|
||||||
_path: &str,
|
_path: &str,
|
||||||
m: &ParsedMail,
|
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() {
|
if decoder.read_to_string(&mut xml).is_ok() {
|
||||||
match parse_dmarc_report(&xml) {
|
match parse_dmarc_report(&xml) {
|
||||||
Ok(report) => {
|
Ok(report) => {
|
||||||
return Ok((Body::html(format!(
|
return Ok((
|
||||||
"<div class=\"dmarc-report\">DMARC report summary:<br>{}</div>",
|
Body::html(format!(
|
||||||
report
|
"<div class=\"dmarc-report\">DMARC report summary:<br>{}</div>",
|
||||||
)), Some(xml)));
|
report
|
||||||
|
)),
|
||||||
|
Some(xml),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Ok((Body::html(format!(
|
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
|
// 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,
|
// show the fanciest they can display. For this program, the priority is text/html, text/plain,
|
||||||
// then give up.
|
// 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![
|
let handled_types = vec![
|
||||||
MULTIPART_ALTERNATIVE,
|
MULTIPART_ALTERNATIVE,
|
||||||
MULTIPART_MIXED,
|
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)),
|
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> {
|
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 std::io::Cursor;
|
||||||
|
|
||||||
|
use quick_xml::{
|
||||||
|
events::{BytesText, Event},
|
||||||
|
reader::Reader,
|
||||||
|
writer::Writer,
|
||||||
|
};
|
||||||
|
|
||||||
let mut reader = Reader::from_str(xml_input);
|
let mut reader = Reader::from_str(xml_input);
|
||||||
reader.config_mut().trim_text(true);
|
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) => {
|
Ok(event) => {
|
||||||
writer.write_event(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();
|
buf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = writer.into_inner().into_inner();
|
let result = writer.into_inner().into_inner();
|
||||||
Ok(String::from_utf8(result)?)
|
Ok(String::from_utf8(result)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,13 +4,10 @@ use std::{
|
|||||||
io::{Cursor, Read},
|
io::{Cursor, Read},
|
||||||
};
|
};
|
||||||
|
|
||||||
use askama::Template;
|
|
||||||
use chrono::{TimeZone, Utc};
|
|
||||||
use letterbox_notmuch::Notmuch;
|
use letterbox_notmuch::Notmuch;
|
||||||
use letterbox_shared::{compute_color, Rule};
|
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 memmap::MmapOptions;
|
||||||
use quick_xml::de::from_str as xml_from_str;
|
|
||||||
use sqlx::{types::Json, PgPool};
|
use sqlx::{types::Json, PgPool};
|
||||||
use tracing::{error, info, info_span, instrument, warn};
|
use tracing::{error, info, info_span, instrument, warn};
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
@ -20,8 +17,8 @@ use crate::{
|
|||||||
email_extract::*,
|
email_extract::*,
|
||||||
error::ServerError,
|
error::ServerError,
|
||||||
graphql::{
|
graphql::{
|
||||||
Attachment, Body, Corpus, DispositionType, Email, EmailThread, Header, Html, Message,
|
Attachment, Body, Corpus, EmailThread, Header, Html, Message, PlainText, Tag, Thread,
|
||||||
PlainText, Tag, Thread, ThreadSummary, UnhandledContentType,
|
ThreadSummary, UnhandledContentType,
|
||||||
},
|
},
|
||||||
linkify_html, InlineStyle, Query, SanitizeHtml, Transformer,
|
linkify_html, InlineStyle, Query, SanitizeHtml, Transformer,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user