diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 0e72396d1..cabd0a2ba 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -450,6 +450,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E dellocations\n\ getlocations []\n\ send \n\ + send-garbage\n\ sendimage []\n\ sendfile \n\ draft []\n\ @@ -948,6 +949,16 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E bail!("Sending failed."); } } + "send-garbage" => { + ensure!(!sel_chat.is_null(), "No chat selected."); + let msg = b"\xff\x00"; // NUL-terminated C-string, that is malformed utf-8 + if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), msg.as_ptr().cast()) { + println!("Malformed utf-8 succesfully send. Not nice."); + } else { + bail!("Garbage sending failed, as expected."); + } + + } "sendempty" => { ensure!(!sel_chat.is_null(), "No chat selected."); if 0 != dc_send_text_msg( diff --git a/examples/repl/main.rs b/examples/repl/main.rs index 28f923c3f..7cc700af8 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -3,6 +3,7 @@ //! //! Usage: cargo run --example repl --release -- //! All further options can be set using the set-command (type ? for help). +#![feature(ptr_cast)] #[macro_use] extern crate deltachat; @@ -290,7 +291,7 @@ const DB_COMMANDS: [&'static str; 11] = [ "housekeeping", ]; -const CHAT_COMMANDS: [&'static str; 24] = [ +const CHAT_COMMANDS: [&'static str; 25] = [ "listchats", "listarchived", "chat", @@ -308,6 +309,7 @@ const CHAT_COMMANDS: [&'static str; 24] = [ "dellocations", "getlocations", "send", + "send-garbage", "sendimage", "sendfile", "draft",