use std::{
collections::HashMap,
io::Read,
sync::{Arc, Mutex},
};
use flate2::bufread::GzDecoder;
use melib::{mbox::*, Envelope, Result};
#[test]
fn test_mbox_parse() {
fn gz_to_string(bytes: &'static [u8]) -> String {
let mut gz = GzDecoder::new(bytes);
let mut s = String::new();
gz.read_to_string(&mut s).unwrap();
s
}
{
let sha1dc_diet_op = gz_to_string(
include_bytes!("../data/PATCH-Put-sha1dc-on-a-diet_op.mbox.gz").as_slice(),
);
let sha1dc_diet_thread =
gz_to_string(include_bytes!("../data/PATCH-Put-sha1dc-on-a-diet.mbox.gz").as_slice());
let message_iter = MessageIterator {
index: Arc::new(Mutex::new(HashMap::default())),
input: sha1dc_diet_thread.as_bytes(),
offset: 0,
file_offset: 0,
format: MboxFormat::MboxRd,
is_crlf: false,
};
let envelopes: Vec<Envelope> = message_iter.collect::<Result<Vec<_>>>().unwrap();
assert_eq!(envelopes.len(), 36);
let mut original_post: Vec<Envelope> = MessageIterator {
index: Arc::new(Mutex::new(HashMap::default())),
input: sha1dc_diet_op.as_bytes(),
offset: 0,
file_offset: 0,
format: MboxFormat::MboxRd,
is_crlf: false,
}
.collect::<Result<Vec<_>>>()
.unwrap();
assert_eq!(original_post.len(), 1);
let original_post = original_post.pop().unwrap();
assert_eq!(&original_post, &envelopes[0]);
}
{
let git_am_op = gz_to_string(
include_bytes!("../data/git-am-breakage-with-MIME-decoding_op.mbox.gz").as_slice(),
);
let git_am_thread = gz_to_string(
include_bytes!("../data/git-am-breakage-with-MIME-decoding.mbox.gz").as_slice(),
);
let message_iter = MessageIterator {
index: Arc::new(Mutex::new(HashMap::default())),
input: git_am_thread.as_bytes(),
offset: 0,
file_offset: 0,
format: MboxFormat::MboxRd,
is_crlf: false,
};
let envelopes: Vec<Envelope> = message_iter.collect::<Result<Vec<_>>>().unwrap();
assert_eq!(envelopes.len(), 7);
let mut original_post: Vec<Envelope> = MessageIterator {
index: Arc::new(Mutex::new(HashMap::default())),
input: git_am_op.as_bytes(),
offset: 0,
file_offset: 0,
format: MboxFormat::MboxRd,
is_crlf: false,
}
.collect::<Result<Vec<_>>>()
.unwrap();
assert_eq!(original_post.len(), 1);
let original_post = original_post.pop().unwrap();
assert_eq!(&original_post, &envelopes[0]);
}
}