Change path to store messages in
Signed-off-by: Jacob Kiers <jacob@jacobkiers.net>
This commit is contained in:
parent
96a9c27fc0
commit
9d41fcd463
|
@ -26,10 +26,7 @@ pub struct Message {
|
|||
|
||||
impl Message {
|
||||
pub fn new(uid: String, data: Vec<u8>) -> Message {
|
||||
Message {
|
||||
uid,
|
||||
data,
|
||||
}
|
||||
Message { uid, data }
|
||||
}
|
||||
|
||||
pub(crate) fn get_parsed(&self) -> Option<MpMessage> {
|
||||
|
@ -61,12 +58,8 @@ fn main() {
|
|||
let processed_html = process_html(&html_body).expect("Could not process the HTML");
|
||||
let html_bytes = processed_html.as_bytes();
|
||||
|
||||
let hash = base16ct::lower::encode_string(&Sha256::digest(&html_bytes));
|
||||
println!("{}", hash);
|
||||
|
||||
let html_path: PathBuf = [dir, Path::new(&format!("{}.html", &title))]
|
||||
.iter()
|
||||
.collect();
|
||||
let html_path: PathBuf = [dir, Path::new(&get_path(&parsed, &msg))].iter().collect();
|
||||
println!("Storing to {}", &html_path.display());
|
||||
|
||||
OpenOptions::new()
|
||||
.write(true)
|
||||
|
@ -80,6 +73,25 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_path(parsed: &MpMessage, msg: &Message) -> String {
|
||||
let date = parsed.get_date().expect("Could not extract date");
|
||||
let date_str = format!(
|
||||
"{:04}{:02}{:02}{:02}{:02}{:02}",
|
||||
&date.year, &date.month, &date.day, &date.hour, &date.minute, &date.second
|
||||
);
|
||||
|
||||
let hash = base16ct::lower::encode_string(&Sha256::digest(
|
||||
&parsed.get_html_body(0).expect("Expected a body").as_bytes(),
|
||||
));
|
||||
|
||||
let uid: i32 = msg
|
||||
.get_uid()
|
||||
.parse()
|
||||
.expect("Could not convert message uid to an i32.");
|
||||
//format!("{}_{}_{}.html", &date_str, &file_name, msg.get_uid()).to_owned()
|
||||
format!("{:05}_{}_{}.html", uid, date_str, &hash).to_owned()
|
||||
}
|
||||
|
||||
fn process_html(input: &str) -> Result<String, sanitize_html::errors::SanitizeError> {
|
||||
let mut rules = sanitize_html::rules::predefined::relaxed().delete("style");
|
||||
|
||||
|
|
Loading…
Reference in New Issue