Skip to content

Commit 176a89b

Browse files
committed
feat(deltachat-repl): add send-sync command
This allows to send send messages when disconnected using `send_msg_sync` to create a dedicated connection and send a single message. The command can be used for measuring the duration of SMTP connection establishment.
1 parent dd8dd2f commit 176a89b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

deltachat-repl/src/cmdline.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
358358
dellocations\n\
359359
getlocations [<contact-id>]\n\
360360
send <text>\n\
361+
send-sync <text>\n\
361362
sendempty\n\
362363
sendimage <file> [<text>]\n\
363364
sendsticker <file> [<text>]\n\
@@ -908,6 +909,23 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
908909

909910
chat::send_text_msg(&context, sel_chat.as_ref().unwrap().get_id(), msg).await?;
910911
}
912+
"send-sync" => {
913+
ensure!(sel_chat.is_some(), "No chat selected.");
914+
ensure!(!arg1.is_empty(), "No message text given.");
915+
916+
// Send message over a dedicated SMTP connection
917+
// and measure time.
918+
//
919+
// This can be used to benchmark SMTP connection establishment.
920+
let time_start = std::time::Instant::now();
921+
922+
let msg = format!("{arg1} {arg2}");
923+
let mut msg = Message::new_text(msg);
924+
chat::send_msg_sync(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?;
925+
926+
let time_needed = time_start.elapsed();
927+
println!("Sent message in {time_needed:?}.");
928+
}
911929
"sendempty" => {
912930
ensure!(sel_chat.is_some(), "No chat selected.");
913931
chat::send_text_msg(&context, sel_chat.as_ref().unwrap().get_id(), "".into()).await?;

deltachat-repl/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const DB_COMMANDS: [&str; 11] = [
179179
"housekeeping",
180180
];
181181

182-
const CHAT_COMMANDS: [&str; 38] = [
182+
const CHAT_COMMANDS: [&str; 39] = [
183183
"listchats",
184184
"listarchived",
185185
"start-realtime",
@@ -199,6 +199,7 @@ const CHAT_COMMANDS: [&str; 38] = [
199199
"dellocations",
200200
"getlocations",
201201
"send",
202+
"send-sync",
202203
"sendempty",
203204
"sendimage",
204205
"sendsticker",

0 commit comments

Comments
 (0)