fixed aerogramme tests
This commit is contained in:
parent
0d667a3030
commit
b66b9f75fe
1 changed files with 28 additions and 22 deletions
|
@ -1309,18 +1309,22 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::cryptoblob;
|
use crate::cryptoblob;
|
||||||
use crate::mail::unique_ident;
|
use crate::mail::unique_ident;
|
||||||
use imap_codec::codec::Encode;
|
use imap_codec::encode::Encoder;
|
||||||
use imap_codec::imap_types::fetch::Section;
|
use imap_codec::imap_types::fetch::Section;
|
||||||
|
use imap_codec::imap_types::response::Response;
|
||||||
|
use imap_codec::ResponseCodec;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mailview_body_ext() -> Result<()> {
|
fn mailview_body_ext() -> Result<()> {
|
||||||
let ap = AttributesProxy::new(
|
let ap = AttributesProxy::new(
|
||||||
&MacroOrMessageDataItemNames::FetchAttributes(vec![MessageDataItemName::BodyExt {
|
&MacroOrMessageDataItemNames::MessageDataItemNames(vec![
|
||||||
|
MessageDataItemName::BodyExt {
|
||||||
section: Some(Section::Header(None)),
|
section: Some(Section::Header(None)),
|
||||||
partial: None,
|
partial: None,
|
||||||
peek: false,
|
peek: false,
|
||||||
}]),
|
},
|
||||||
|
]),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1340,13 +1344,13 @@ mod tests {
|
||||||
let rfc822 = b"Subject: hello\r\nFrom: a@a.a\r\nTo: b@b.b\r\nDate: Thu, 12 Oct 2023 08:45:28 +0000\r\n\r\nhello world";
|
let rfc822 = b"Subject: hello\r\nFrom: a@a.a\r\nTo: b@b.b\r\nDate: Thu, 12 Oct 2023 08:45:28 +0000\r\n\r\nhello world";
|
||||||
let content = FetchedMail::new_from_message(eml_codec::parse_message(rfc822)?.1);
|
let content = FetchedMail::new_from_message(eml_codec::parse_message(rfc822)?.1);
|
||||||
|
|
||||||
let mut mv = MailView {
|
let mv = MailView {
|
||||||
ids: &ids,
|
ids: &ids,
|
||||||
content,
|
content,
|
||||||
meta: &meta,
|
meta: &meta,
|
||||||
flags: &flags,
|
flags: &flags,
|
||||||
};
|
};
|
||||||
let res_body = mv.filter(&ap)?;
|
let (res_body, _seen) = mv.filter(&ap)?;
|
||||||
|
|
||||||
let fattr = match res_body {
|
let fattr = match res_body {
|
||||||
Body::Data(Data::Fetch {
|
Body::Data(Data::Fetch {
|
||||||
|
@ -1356,10 +1360,10 @@ mod tests {
|
||||||
_ => Err(anyhow!("Not a fetch body")),
|
_ => Err(anyhow!("Not a fetch body")),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
assert_eq!(fattr.len(), 1);
|
assert_eq!(fattr.as_ref().len(), 1);
|
||||||
|
|
||||||
let (sec, _orig, _data) = match &fattr[0] {
|
let (sec, _orig, _data) = match &fattr.as_ref()[0] {
|
||||||
MessageDataItemName::BodyExt {
|
MessageDataItem::BodyExt {
|
||||||
section,
|
section,
|
||||||
origin,
|
origin,
|
||||||
data,
|
data,
|
||||||
|
@ -1408,22 +1412,24 @@ mod tests {
|
||||||
for pref in prefixes.iter() {
|
for pref in prefixes.iter() {
|
||||||
println!("{}", pref);
|
println!("{}", pref);
|
||||||
let txt = fs::read(format!("{}.eml", pref))?;
|
let txt = fs::read(format!("{}.eml", pref))?;
|
||||||
let exp = fs::read(format!("{}.dovecot.body", pref))?;
|
let oracle = fs::read(format!("{}.dovecot.body", pref))?;
|
||||||
let message = eml_codec::parse_message(&txt).unwrap().1;
|
let message = eml_codec::parse_message(&txt).unwrap().1;
|
||||||
|
|
||||||
let mut resp = Vec::new();
|
let test_repr = Response::Data(Data::Fetch {
|
||||||
MessageDataItemName::Body(build_imap_email_struct(&message.child)?)
|
seq: NonZeroU32::new(1).unwrap(),
|
||||||
.encode(&mut resp)
|
items: NonEmptyVec::from(MessageDataItem::Body(build_imap_email_struct(
|
||||||
.unwrap();
|
&message.child,
|
||||||
|
)?)),
|
||||||
|
});
|
||||||
|
let test_bytes = ResponseCodec::new().encode(&test_repr).dump();
|
||||||
|
let test_str = String::from_utf8_lossy(&test_bytes).to_lowercase();
|
||||||
|
|
||||||
let resp_str = String::from_utf8_lossy(&resp).to_lowercase();
|
let oracle_str =
|
||||||
|
format!("* 1 FETCH {}\r\n", String::from_utf8_lossy(&oracle)).to_lowercase();
|
||||||
|
|
||||||
let exp_no_parenthesis = &exp[1..exp.len() - 1];
|
println!("aerogramme: {}\n\ndovecot: {}\n\n", test_str, oracle_str);
|
||||||
let exp_str = String::from_utf8_lossy(exp_no_parenthesis).to_lowercase();
|
|
||||||
|
|
||||||
println!("aerogramme: {}\n\ndovecot: {}\n\n", resp_str, exp_str);
|
|
||||||
//println!("\n\n {} \n\n", String::from_utf8_lossy(&resp));
|
//println!("\n\n {} \n\n", String::from_utf8_lossy(&resp));
|
||||||
assert_eq!(resp_str, exp_str);
|
assert_eq!(test_str, oracle_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue