Add matching rust implementation for Go HashMessage.

This commit is contained in:
2023-02-22 20:47:14 -08:00
parent af87a3cade
commit 7bbdaec84b
5 changed files with 180 additions and 33 deletions

View File

@@ -1,12 +1,6 @@
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::process::exit;
use std::slice::Iter;
use std::{env, error::Error, fs::File, io::prelude::*, process::exit, slice::Iter};
use mailparse::dateparse;
use mailparse::MailHeaderMap;
use mailparse::{dateparse, MailHeaderMap};
fn newline(b: &u8) -> bool {
*b == b'\n'
@@ -57,15 +51,15 @@ fn parse_mbox(mbox_bytes: &Vec<u8>) -> Result<(), Box<dyn Error>> {
let mail = mailparse::parse_mail(mail_bytes).unwrap();
println!(
"{:?} {:?} from {:?}",
match mail.headers.get_first_value("Date")? {
match mail.headers.get_first_value("Date") {
Some(date) => date,
None => "NO DATE".to_string(),
},
match mail.headers.get_first_value("Subject")? {
match mail.headers.get_first_value("Subject") {
Some(subject) => subject,
None => "NO SUBJECT".to_string(),
},
match mail.headers.get_first_value("From")? {
match mail.headers.get_first_value("From") {
Some(from) => from,
None => "NO FROM".to_string(),
},