mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
@@ -450,6 +450,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
dellocations\n\
|
dellocations\n\
|
||||||
getlocations [<contact-id>]\n\
|
getlocations [<contact-id>]\n\
|
||||||
send <text>\n\
|
send <text>\n\
|
||||||
|
send-garbage\n\
|
||||||
sendimage <file> [<text>]\n\
|
sendimage <file> [<text>]\n\
|
||||||
sendfile <file>\n\
|
sendfile <file>\n\
|
||||||
draft [<text>]\n\
|
draft [<text>]\n\
|
||||||
@@ -948,6 +949,15 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
bail!("Sending failed.");
|
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" => {
|
"sendempty" => {
|
||||||
ensure!(!sel_chat.is_null(), "No chat selected.");
|
ensure!(!sel_chat.is_null(), "No chat selected.");
|
||||||
if 0 != dc_send_text_msg(
|
if 0 != dc_send_text_msg(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Usage: cargo run --example repl --release -- <databasefile>
|
//! Usage: cargo run --example repl --release -- <databasefile>
|
||||||
//! All further options can be set using the set-command (type ? for help).
|
//! All further options can be set using the set-command (type ? for help).
|
||||||
|
#![feature(ptr_cast)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate deltachat;
|
extern crate deltachat;
|
||||||
@@ -290,7 +291,7 @@ const DB_COMMANDS: [&'static str; 11] = [
|
|||||||
"housekeeping",
|
"housekeeping",
|
||||||
];
|
];
|
||||||
|
|
||||||
const CHAT_COMMANDS: [&'static str; 24] = [
|
const CHAT_COMMANDS: [&'static str; 25] = [
|
||||||
"listchats",
|
"listchats",
|
||||||
"listarchived",
|
"listarchived",
|
||||||
"chat",
|
"chat",
|
||||||
@@ -308,6 +309,7 @@ const CHAT_COMMANDS: [&'static str; 24] = [
|
|||||||
"dellocations",
|
"dellocations",
|
||||||
"getlocations",
|
"getlocations",
|
||||||
"send",
|
"send",
|
||||||
|
"send-garbage",
|
||||||
"sendimage",
|
"sendimage",
|
||||||
"sendfile",
|
"sendfile",
|
||||||
"draft",
|
"draft",
|
||||||
|
|||||||
@@ -976,6 +976,11 @@ pub unsafe fn dc_send_text_msg(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Err(err) = as_str_safe(text_to_send) {
|
||||||
|
warn!(context, 0, "{}", err);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let mut msg = dc_msg_new(context, 10);
|
let mut msg = dc_msg_new(context, 10);
|
||||||
(*msg).text = dc_strdup(text_to_send);
|
(*msg).text = dc_strdup(text_to_send);
|
||||||
let ret = dc_send_msg(context, chat_id, msg);
|
let ret = dc_send_msg(context, chat_id, msg);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::fs;
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use chrono::{Local, TimeZone};
|
use chrono::{Local, TimeZone};
|
||||||
|
use failure::format_err;
|
||||||
use mmime::mailimf_types::*;
|
use mmime::mailimf_types::*;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
@@ -1563,13 +1564,16 @@ pub fn to_string_lossy(s: *const libc::c_char) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
|
pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
|
||||||
|
as_str_safe(s).unwrap_or_else(|err| panic!("{}", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_str_safe<'a>(s: *const libc::c_char) -> Result<&'a str, failure::Error> {
|
||||||
assert!(!s.is_null(), "cannot be used on null pointers");
|
assert!(!s.is_null(), "cannot be used on null pointers");
|
||||||
|
|
||||||
let cstr = unsafe { CStr::from_ptr(s) };
|
let cstr = unsafe { CStr::from_ptr(s) };
|
||||||
|
|
||||||
cstr.to_str().unwrap_or_else(|err| {
|
cstr.to_str()
|
||||||
panic!("Non utf8 string: '{:?}' ({:?})", cstr.to_bytes(), err);
|
.map_err(|err| format_err!("Non utf8 string: '{:?}' ({:?})", cstr.to_bytes(), err))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a C `*char` pointer to a [std::path::Path] slice.
|
/// Convert a C `*char` pointer to a [std::path::Path] slice.
|
||||||
|
|||||||
Reference in New Issue
Block a user