summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 15:38:25 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:51 +0300
commit8a070873932c957619f7ead2acad2afd5efffb1f (patch)
treefa46abae70fbf51d891590467b59fed886cf6ec9
parentd772d10d6632018f884595d85cacc37ba94caede (diff)
add testing crate with emailparse bin
-rw-r--r--Cargo.toml2
-rw-r--r--melib/src/email/attachments.rs9
-rw-r--r--testing/Cargo.toml13
-rw-r--r--testing/src/email_parse.rs24
4 files changed, 45 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 552f8f2a..19cfd818 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,4 +21,4 @@ lto = true
debug = true
[workspace]
-members = ["melib", "ui", "debug_printer"]
+members = ["melib", "ui", "debug_printer", "testing"]
diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs
index aed43135..95c9462c 100644
--- a/melib/src/email/attachments.rs
+++ b/melib/src/email/attachments.rs
@@ -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))
+ }
+ )
}
}
diff --git a/testing/Cargo.toml b/testing/Cargo.toml
new file mode 100644
index 00000000..4a8e5184
--- /dev/null
+++ b/testing/Cargo.toml
@@ -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 = "*" }
diff --git a/testing/src/email_parse.rs b/testing/src/email_parse.rs
new file mode 100644
index 00000000..b29000cc
--- /dev/null
+++ b/testing/src/email_parse.rs
@@ -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(())
+}