Compare commits

..

No commits in common. "2307aa144f267cf7008dfb4055fe3cfc362f82f5" and "199669d302aafb5558119fb5b528c6007c95247b" have entirely different histories.

3 changed files with 10 additions and 67 deletions

View File

@ -32,14 +32,6 @@ struct Args {
#[arg(short, long, default_value_t = 10)] #[arg(short, long, default_value_t = 10)]
top_n: usize, top_n: usize,
/// Include subpart headers keys in fingerprint
#[arg(short, long)]
include_header_keys: bool,
/// Include subpart params in fingerprint
#[arg(long)]
include_params: bool,
/// List of input directories to recursively search /// List of input directories to recursively search
input_dir: String, input_dir: String,
} }
@ -76,12 +68,7 @@ fn main() -> anyhow::Result<()> {
if should_skip(&arg) { if should_skip(&arg) {
return None; return None;
} }
match parse( match parse(&arg, youngest) {
&arg,
youngest,
args.include_header_keys,
args.include_params,
) {
Ok(Some(h)) => Some((h, arg)), Ok(Some(h)) => Some((h, arg)),
// Skip old emails // Skip old emails
Ok(None) => return None, Ok(None) => return None,
@ -129,12 +116,7 @@ fn main() -> anyhow::Result<()> {
} }
// If the date in the email is before youngest Ok(None) will be returned. // If the date in the email is before youngest Ok(None) will be returned.
fn parse<P: AsRef<Path>>( fn parse<P: AsRef<Path>>(path: P, youngest: i64) -> Result<Option<String>, EmailError> {
path: P,
youngest: i64,
include_header_keys: bool,
include_params: bool,
) -> Result<Option<String>, EmailError> {
let file = File::open(&path)?; let file = File::open(&path)?;
let mmap = unsafe { MmapOptions::new().map(&file)? }; let mmap = unsafe { MmapOptions::new().map(&file)? };
let m = parse_mail(&mmap)?; let m = parse_mail(&mmap)?;
@ -149,7 +131,5 @@ fn parse<P: AsRef<Path>>(
return Ok(None); return Ok(None);
} }
//println!("{}: {:#?}", path.as_ref().display(), m.ctype); //println!("{}: {:#?}", path.as_ref().display(), m.ctype);
Ok(Some( Ok(Some(fingerprint(&m).join("\n")))
fingerprint(&m, include_header_keys, include_params).join("\n"),
))
} }

View File

@ -9,14 +9,6 @@ use memmap::MmapOptions;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Args { struct Args {
/// Include subpart headers keys in fingerprint
#[arg(short, long)]
include_header_keys: bool,
/// Include subpart params in fingerprint
#[arg(long)]
include_params: bool,
/// List of files to summarize /// List of files to summarize
paths: Vec<String>, paths: Vec<String>,
} }
@ -31,10 +23,7 @@ fn main() -> anyhow::Result<()> {
.headers .headers
.get_first_value("subject") .get_first_value("subject")
.unwrap_or("(NO SUBJECT)".to_owned()); .unwrap_or("(NO SUBJECT)".to_owned());
println!( println!("{subject}: {path}\n{}", fingerprint(&m).join("\n"));
"{subject}: {path}\n{}",
fingerprint(&m, args.include_header_keys, args.include_params).join("\n")
);
} }
Ok(()) Ok(())
} }

View File

@ -65,41 +65,15 @@ pub fn should_skip(path: &str) -> bool {
SKIP_FILES.contains(&filename) SKIP_FILES.contains(&filename)
} }
pub fn fingerprint( pub fn fingerprint(pm: &ParsedMail<'_>) -> Vec<String> {
pm: &ParsedMail<'_>, fingerprint_rec(pm, 0)
include_header_keys: bool,
include_params: bool,
) -> Vec<String> {
fingerprint_rec(pm, include_header_keys, include_params, 0)
}
fn fingerprint_rec(
pm: &ParsedMail<'_>,
include_header_keys: bool,
include_params: bool,
depth: usize,
) -> Vec<String> {
let indent = " ".repeat(depth * 2);
let mut parts = vec![format!("{}{}", indent, pm.ctype.mimetype)];
if include_header_keys {
parts.push(format!("{indent}Headers:"));
for k in &pm.headers {
parts.push(format!("{indent} {}", k.get_key()));
}
}
if include_params {
for (k, v) in &pm.ctype.params {
parts.push(format!("{indent} {k}: {v}"));
}
} }
fn fingerprint_rec(pm: &ParsedMail<'_>, depth: usize) -> Vec<String> {
let mut v = vec![format!("{}{}", " ".repeat(depth * 2), pm.ctype.mimetype)];
for c in &pm.subparts { for c in &pm.subparts {
parts.extend(fingerprint_rec( v.extend(fingerprint_rec(&c, depth + 1));
&c,
include_header_keys,
include_params,
depth + 1,
));
} }
parts v
} }
#[cfg(test)] #[cfg(test)]