Browse Source

add testing crate with emailparse bin

tags/pre-alpha-0.0
Manos Pitsidianakis 9 months ago
parent
commit
8a07087393
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
4 changed files with 45 additions and 3 deletions
  1. +1
    -1
      Cargo.toml
  2. +7
    -2
      melib/src/email/attachments.rs
  3. +13
    -0
      testing/Cargo.toml
  4. +24
    -0
      testing/src/email_parse.rs

+ 1
- 1
Cargo.toml View File

@@ -21,4 +21,4 @@ lto = true
debug = true

[workspace]
members = ["melib", "ui", "debug_printer"]
members = ["melib", "ui", "debug_printer", "testing"]

+ 7
- 2
melib/src/email/attachments.rs View File

@@ -53,11 +53,16 @@ pub struct Attachment {

impl fmt::Debug for Attachment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Attachment {{\n content_type: {:?},\n content_transfer_encoding: {:?},\n raw: Vec of {} bytes\n, body:\n{}\n }}",
write!(f, "Attachment {{\n content_type: {:?},\n content_transfer_encoding: {:?},\n raw: Vec of {} bytes\n, body:\n{}\n}}",
self.content_type,
self.content_transfer_encoding,
self.raw.len(),
str::from_utf8(&self.raw).unwrap())
{
let mut text = Vec::with_capacity(4096);
self.get_text_recursive(&mut text);
std::str::from_utf8(&text).map(|r| r.to_string()).unwrap_or_else(|e| format!("Unicode error {}", e))
}
)
}
}



+ 13
- 0
testing/Cargo.toml View File

@@ -0,0 +1,13 @@
[package]
name = "testing"
version = "0.0.1" #:version
authors = []
workspace = ".."

[[bin]]
name = "emailparse"
path = "src/email_parse.rs"


[dependencies]
melib = { path = "../melib", version = "*" }

+ 24
- 0
testing/src/email_parse.rs View File

@@ -0,0 +1,24 @@
extern crate melib;
use melib::*;

use melib::Result;

fn main() -> Result<()> {
for i in std::env::args().skip(1) {
println!("i is {}", i);
let filename = std::path::PathBuf::from(i);

if filename.is_file() {
let buffer = std::fs::read_to_string(&filename).expect(&format!(
"Something went wrong reading the file {}",
filename.display()
));
let env = Envelope::from_bytes(&buffer.as_bytes()).expect("Couldn't parse email");
debug!("Env is {:#?}", env);
debug!(env.body_bytes(buffer.as_bytes()));
} else {
println!("it's not a file");
}
}
Ok(())
}

Loading…
Cancel
Save