mirror of
https://github.com/chatmail/core.git
synced 2026-04-09 00:52:11 +03:00
Compare commits
6 Commits
deprecate_
...
safe-e2ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ba25f9f77 | ||
|
|
e23704486a | ||
|
|
feee340f4d | ||
|
|
a5cde0d137 | ||
|
|
b08a2b4d2c | ||
|
|
3b6e1b0aae |
@@ -296,18 +296,26 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
||||
param.server_flags &= !(DC_LP_AUTH_FLAGS as i32);
|
||||
param.server_flags |= DC_LP_AUTH_NORMAL as i32
|
||||
}
|
||||
if param.mail_security == 0 {
|
||||
param.mail_security = if param.send_port == 143 {
|
||||
2 // StartTLS
|
||||
if !dc_exactly_one_bit_set(
|
||||
param.server_flags & DC_LP_IMAP_SOCKET_FLAGS as i32,
|
||||
) {
|
||||
param.server_flags &= !(DC_LP_IMAP_SOCKET_FLAGS as i32);
|
||||
param.server_flags |= if param.send_port == 143 {
|
||||
DC_LP_IMAP_SOCKET_STARTTLS as i32
|
||||
} else {
|
||||
1 // SSL/TLS
|
||||
DC_LP_IMAP_SOCKET_SSL as i32
|
||||
}
|
||||
}
|
||||
if param.send_security == 0 {
|
||||
param.send_security = match param.send_port {
|
||||
587 => 2, // StartTLS
|
||||
25 => 3, // Plain
|
||||
_ => 1, // SSL/TLS
|
||||
if !dc_exactly_one_bit_set(
|
||||
param.server_flags & (DC_LP_SMTP_SOCKET_FLAGS as i32),
|
||||
) {
|
||||
param.server_flags &= !(DC_LP_SMTP_SOCKET_FLAGS as i32);
|
||||
param.server_flags |= if param.send_port == 587 {
|
||||
DC_LP_SMTP_SOCKET_STARTTLS as i32
|
||||
} else if param.send_port == 25 {
|
||||
DC_LP_SMTP_SOCKET_PLAIN as i32
|
||||
} else {
|
||||
DC_LP_SMTP_SOCKET_SSL as i32
|
||||
}
|
||||
}
|
||||
/* do we have a complete configuration? */
|
||||
|
||||
@@ -127,7 +127,7 @@ impl<'a> MimeParser<'a> {
|
||||
if (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int {
|
||||
let subj = (*(*field).fld_data.fld_subject).sbj_value;
|
||||
|
||||
self.subject = as_opt_str(subj).map(dc_decode_header_words);
|
||||
self.subject = as_opt_str(subj).map(dc_decode_header_words_safe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,7 +704,7 @@ impl<'a> MimeParser<'a> {
|
||||
// might be a wrongly encoded filename
|
||||
let s = to_string_lossy((*dsp_param).pa_data.pa_filename);
|
||||
// this is used only if the parts buffer stays empty
|
||||
desired_filename = dc_decode_header_words(&s)
|
||||
desired_filename = dc_decode_header_words_safe(&s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1076,7 +1076,7 @@ unsafe fn create_or_lookup_group(
|
||||
}
|
||||
|
||||
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Name") {
|
||||
grpname = Some(dc_decode_header_words(&optional_field));
|
||||
grpname = Some(dc_decode_header_words_safe(&optional_field));
|
||||
}
|
||||
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Member-Removed") {
|
||||
X_MrRemoveFromGrp = Some(optional_field);
|
||||
@@ -1965,7 +1965,7 @@ unsafe fn add_or_lookup_contact_by_addr(
|
||||
/* add addr_spec if missing, update otherwise */
|
||||
let mut display_name_dec = "".to_string();
|
||||
if !display_name_enc.is_null() {
|
||||
let tmp = dc_decode_header_words(as_str(display_name_enc));
|
||||
let tmp = as_str(dc_decode_header_words(display_name_enc));
|
||||
display_name_dec = normalize_name(&tmp);
|
||||
}
|
||||
/*can be NULL*/
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::ffi::CString;
|
||||
use std::ptr;
|
||||
|
||||
use charset::Charset;
|
||||
use libc::free;
|
||||
use libc::{free, strlen};
|
||||
use mmime::mailmime::decode::mailmime_encoded_phrase_parse;
|
||||
use mmime::other::*;
|
||||
use percent_encoding::{percent_decode, utf8_percent_encode, AsciiSet, CONTROLS};
|
||||
@@ -68,7 +68,28 @@ fn quote_word(word: &[u8]) -> String {
|
||||
* Encode/decode header words, RFC 2047
|
||||
******************************************************************************/
|
||||
|
||||
pub(crate) fn dc_decode_header_words(input: &str) -> String {
|
||||
pub unsafe fn dc_decode_header_words(in_0: *const libc::c_char) -> *mut libc::c_char {
|
||||
if in_0.is_null() {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let mut out: *mut libc::c_char = ptr::null_mut();
|
||||
let mut cur_token = 0;
|
||||
let r: libc::c_int = mailmime_encoded_phrase_parse(
|
||||
b"iso-8859-1\x00" as *const u8 as *const libc::c_char,
|
||||
in_0,
|
||||
strlen(in_0),
|
||||
&mut cur_token,
|
||||
b"utf-8\x00" as *const u8 as *const libc::c_char,
|
||||
&mut out,
|
||||
);
|
||||
if r != MAILIMF_NO_ERROR as libc::c_int || out.is_null() {
|
||||
out = dc_strdup(in_0)
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn dc_decode_header_words_safe(input: &str) -> String {
|
||||
static FROM_ENCODING: &[u8] = b"iso-8859-1\x00";
|
||||
static TO_ENCODING: &[u8] = b"utf-8\x00";
|
||||
let mut out = ptr::null_mut();
|
||||
@@ -156,31 +177,60 @@ pub fn dc_decode_ext_header(to_decode: &[u8]) -> Cow<str> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use libc::strcmp;
|
||||
use std::ffi::CStr;
|
||||
|
||||
#[test]
|
||||
fn test_dc_decode_header_words() {
|
||||
assert_eq!(
|
||||
dc_decode_header_words("=?utf-8?B?dGVzdMOkw7bDvC50eHQ=?="),
|
||||
std::string::String::from_utf8(b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt".to_vec()).unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(dc_decode_header_words("just ascii test"), "just ascii test");
|
||||
|
||||
assert_eq!(dc_encode_header_words("abcdef"), "abcdef");
|
||||
|
||||
let r = dc_encode_header_words(
|
||||
std::string::String::from_utf8(b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt".to_vec()).unwrap(),
|
||||
);
|
||||
assert!(r.starts_with("=?utf-8"));
|
||||
|
||||
assert_eq!(
|
||||
dc_decode_header_words(&r),
|
||||
std::string::String::from_utf8(b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt".to_vec()).unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
dc_decode_header_words("=?ISO-8859-1?Q?attachment=3B=0D=0A_filename=3D?= =?ISO-8859-1?Q?=22test=E4=F6=FC=2Etxt=22=3B=0D=0A_size=3D39?="),
|
||||
std::string::String::from_utf8(b"attachment;\r\n filename=\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\";\r\n size=39".to_vec()).unwrap(),
|
||||
unsafe {
|
||||
let mut buf1: *mut libc::c_char = dc_decode_header_words(
|
||||
b"=?utf-8?B?dGVzdMOkw7bDvC50eHQ=?=\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
assert_eq!(
|
||||
strcmp(
|
||||
buf1,
|
||||
b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char
|
||||
),
|
||||
0
|
||||
);
|
||||
free(buf1 as *mut libc::c_void);
|
||||
|
||||
buf1 =
|
||||
dc_decode_header_words(b"just ascii test\x00" as *const u8 as *const libc::c_char);
|
||||
assert_eq!(CStr::from_ptr(buf1).to_str().unwrap(), "just ascii test");
|
||||
free(buf1 as *mut libc::c_void);
|
||||
|
||||
assert_eq!(dc_encode_header_words("abcdef"), "abcdef");
|
||||
|
||||
let r = dc_encode_header_words(
|
||||
std::string::String::from_utf8(b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt".to_vec())
|
||||
.unwrap(),
|
||||
);
|
||||
assert!(r.starts_with("=?utf-8"));
|
||||
|
||||
buf1 = r.strdup();
|
||||
let buf2: *mut libc::c_char = dc_decode_header_words(buf1);
|
||||
assert_eq!(
|
||||
strcmp(
|
||||
buf2,
|
||||
b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char
|
||||
),
|
||||
0
|
||||
);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
|
||||
buf1 = dc_decode_header_words(
|
||||
b"=?ISO-8859-1?Q?attachment=3B=0D=0A_filename=3D?= =?ISO-8859-1?Q?=22test=E4=F6=FC=2Etxt=22=3B=0D=0A_size=3D39?=\x00" as *const u8 as *const libc::c_char
|
||||
);
|
||||
assert_eq!(
|
||||
strcmp(
|
||||
buf1,
|
||||
b"attachment;\r\n filename=\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\";\r\n size=39\x00" as *const u8 as *const libc::c_char,
|
||||
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -243,7 +293,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_dc_header_roundtrip(input: String) {
|
||||
let encoded = dc_encode_header_words(&input);
|
||||
let decoded = dc_decode_header_words(&encoded);
|
||||
let decoded = dc_decode_header_words_safe(&encoded);
|
||||
|
||||
assert_eq!(input, decoded);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,10 @@ pub struct LoginParam {
|
||||
pub mail_user: String,
|
||||
pub mail_pw: String,
|
||||
pub mail_port: i32,
|
||||
pub mail_security: i32,
|
||||
pub send_server: String,
|
||||
pub send_user: String,
|
||||
pub send_pw: String,
|
||||
pub send_port: i32,
|
||||
pub send_security: i32,
|
||||
pub server_flags: i32,
|
||||
}
|
||||
|
||||
@@ -65,40 +63,16 @@ impl LoginParam {
|
||||
let key = format!("{}server_flags", prefix);
|
||||
let server_flags = sql.get_config_int(context, key).unwrap_or_default();
|
||||
|
||||
let mail_security = match (
|
||||
server_flags & DC_LP_IMAP_SOCKET_STARTTLS,
|
||||
server_flags & DC_LP_IMAP_SOCKET_SSL,
|
||||
server_flags & DC_LP_IMAP_SOCKET_PLAIN,
|
||||
) {
|
||||
(1, 0, 0) => 2, // StartTLS
|
||||
(0, 1, 0) => 1, // SSL/TLS
|
||||
(0, 0, 1) => 3, // Plain
|
||||
_ => 0, // Automatic
|
||||
};
|
||||
|
||||
let send_security = match (
|
||||
server_flags & DC_LP_SMTP_SOCKET_FLAGS,
|
||||
server_flags & DC_LP_SMTP_SOCKET_SSL,
|
||||
server_flags & DC_LP_SMTP_SOCKET_PLAIN,
|
||||
) {
|
||||
(1, 0, 0) => 2, // StartTLS
|
||||
(0, 1, 0) => 1, // SSL/TLS
|
||||
(0, 0, 1) => 3, // Plain
|
||||
_ => 0, // Automatic
|
||||
};
|
||||
|
||||
LoginParam {
|
||||
addr: addr.to_string(),
|
||||
mail_server,
|
||||
mail_user,
|
||||
mail_pw,
|
||||
mail_port,
|
||||
mail_security,
|
||||
send_server,
|
||||
send_user,
|
||||
send_pw,
|
||||
send_port,
|
||||
send_security,
|
||||
server_flags,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user