This commit is contained in:
Hocuri
2020-06-08 21:14:50 +02:00
committed by holger krekel
parent acb42982b7
commit 84be82c670
4 changed files with 82 additions and 50 deletions

6
Cargo.lock generated
View File

@@ -932,7 +932,7 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "email"
version = "0.0.21"
source = "git+https://github.com/deltachat/rust-email#ace12ee6f8e054dd890589f588d0311604fc25f0"
source = "git+https://github.com/Hocuri/rust-email#6c903a5b1dd91acb191af2987ca29c28bb733c56"
dependencies = [
"base64 0.11.0",
"chrono",
@@ -1602,7 +1602,7 @@ dependencies = [
[[package]]
name = "lettre"
version = "0.9.2"
source = "git+https://github.com/deltachat/lettre#12e4f22d8d691fb5d1606e4c9034f5d4d9ba635b"
source = "git+https://github.com/Hocuri/lettre#05a94e82269e3d85b7b7b5b88e779daf4f6343db"
dependencies = [
"fast_chemail",
"log",
@@ -1611,7 +1611,7 @@ dependencies = [
[[package]]
name = "lettre_email"
version = "0.9.2"
source = "git+https://github.com/deltachat/lettre#12e4f22d8d691fb5d1606e4c9034f5d4d9ba635b"
source = "git+https://github.com/Hocuri/lettre#05a94e82269e3d85b7b7b5b88e779daf4f6343db"
dependencies = [
"base64 0.11.0",
"email",

View File

@@ -1780,7 +1780,7 @@ mod tests {
use crate::chat::ChatVisibility;
use crate::chatlist::Chatlist;
use crate::message::Message;
use crate::test_utils::{dummy_context, TestContext};
use crate::test_utils::{configured_offline_context, dummy_context};
#[test]
fn test_hex_hash() {
@@ -1876,23 +1876,6 @@ mod tests {
assert!(!is_msgrmsg_rfc724_mid(&t.ctx, "nonexistant@message.id").await);
}
async fn configured_offline_context() -> TestContext {
let t = dummy_context().await;
t.ctx
.set_config(Config::Addr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::Configured, Some("1"))
.await
.unwrap();
t
}
static MSGRMSG: &[u8] = b"From: Bob <bob@example.org>\n\
To: alice@example.org\n\
Chat-Version: 1.0\n\

View File

@@ -1207,6 +1207,11 @@ pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::chatlist::Chatlist;
use crate::dc_receive_imf::dc_receive_imf;
use crate::mimeparser::*;
use crate::test_utils::configured_offline_context;
use crate::test_utils::TestContext;
#[test]
fn test_render_email_address() {
@@ -1243,8 +1248,10 @@ mod tests {
Address::new_mailbox_with_name(display_name.to_string(), addr.to_string())
);
// Addresses should not be unnecessarily be encoded, see https://github.com/deltachat/deltachat-core-rust/issues/1575:
assert_eq!(s, "a space <x@y.org>");
}
#[test]
fn test_render_rfc724_mid() {
assert_eq!(
@@ -1288,25 +1295,6 @@ mod tests {
assert!(needs_encoding("foo bar"));
}
use crate::test_utils::{dummy_context, TestContext};
async fn configured_offline_context() -> TestContext {
let t = dummy_context().await;
t.ctx
.set_config(Config::Addr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::Configured, Some("1"))
.await
.unwrap();
t
}
#[async_std::test]
async fn test_subject() {
// 1.: Receive a mail from an MUA or Delta Chat
@@ -1419,35 +1407,79 @@ mod tests {
}
async fn msg_to_subject_str(imf_raw: &[u8]) -> String {
use crate::chatlist::Chatlist;
use crate::dc_receive_imf::dc_receive_imf;
let t = configured_offline_context().await;
t.ctx
let new_msg = incoming_msg_to_reply_msg(imf_raw, &t.ctx).await;
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false)
.await
.unwrap();
mf.subject_str().await
}
// Creates a mimefactory for a message that replies "Hi" to the incoming message in `imf_raw`.
async fn incoming_msg_to_reply_msg(imf_raw: &[u8], context: &Context) -> Message {
context
.set_config(Config::ShowEmails, Some("2"))
.await
.unwrap();
dc_receive_imf(&t.ctx, imf_raw, "INBOX", 1, false)
dc_receive_imf(context, imf_raw, "INBOX", 1, false)
.await
.unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
let chats = Chatlist::try_load(context, 0, None, None).await.unwrap();
let chat_id = chat::create_by_msg_id(&t.ctx, chats.get_msg_id(0).unwrap())
let chat_id = chat::create_by_msg_id(context, chats.get_msg_id(0).unwrap())
.await
.unwrap();
let mut new_msg = Message::new(Viewtype::Text);
new_msg.set_text(Some("Hi".to_string()));
new_msg.chat_id = chat_id;
chat::prepare_msg(&t.ctx, chat_id, &mut new_msg)
chat::prepare_msg(context, chat_id, &mut new_msg)
.await
.unwrap();
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false)
new_msg
}
#[async_std::test]
// This test could still be extended
async fn test_render_reply() {
let t = configured_offline_context().await;
let context = &t.ctx;
let msg = incoming_msg_to_reply_msg(
b"From: Charlie <charlie@example.org>\n\
To: alice@example.org\n\
Subject: Chat: hello\n\
Chat-Version: 1.0\n\
Message-ID: <2223@example.org>\n\
Date: Sun, 22 Mar 2020 22:37:56 +0000\n\
\n\
hello\n",
context,
)
.await;
let mimefactory = MimeFactory::from_msg(&t.ctx, &msg, false).await.unwrap();
let recipients = mimefactory.recipients();
assert_eq!(recipients, vec!["charlie@example.org"]);
let rendered_msg = mimefactory.render().await.unwrap();
let mail = mailparse::parse_mail(&rendered_msg.message).unwrap();
assert_eq!(
mail.headers
.iter()
.find(|h| h.get_key() == "MIME-Version")
.unwrap()
.get_value(),
"1.0"
);
let _mime_msg = MimeMessage::from_bytes(context, &rendered_msg.message)
.await
.unwrap();
mf.subject_str().await
}
}

View File

@@ -40,6 +40,23 @@ pub(crate) async fn dummy_context() -> TestContext {
test_context().await
}
pub(crate) async fn configured_offline_context() -> TestContext {
let t = dummy_context().await;
t.ctx
.set_config(Config::Addr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
.await
.unwrap();
t.ctx
.set_config(Config::Configured, Some("1"))
.await
.unwrap();
t
}
/// Load a pre-generated keypair for alice@example.com from disk.
///
/// This saves CPU cycles by avoiding having to generate a key.