mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
more rustifications
This commit is contained in:
@@ -60,6 +60,10 @@ const DC_GCM_ADDDAYMARKER: usize = 0x01;
|
|||||||
pub const DC_GCL_VERIFIED_ONLY: usize = 0x01;
|
pub const DC_GCL_VERIFIED_ONLY: usize = 0x01;
|
||||||
pub const DC_GCL_ADD_SELF: usize = 0x02;
|
pub const DC_GCL_ADD_SELF: usize = 0x02;
|
||||||
|
|
||||||
|
// values for DC_PARAM_FORCE_PLAINTEXT
|
||||||
|
pub(crate) const DC_FP_NO_AUTOCRYPT_HEADER: i32 = 2;
|
||||||
|
pub(crate) const DC_FP_ADD_AUTOCRYPT_HEADER: i32 = 1;
|
||||||
|
|
||||||
/// param1 is a directory where the keys are written to
|
/// param1 is a directory where the keys are written to
|
||||||
const DC_IMEX_EXPORT_SELF_KEYS: usize = 1;
|
const DC_IMEX_EXPORT_SELF_KEYS: usize = 1;
|
||||||
/// param1 is a directory where the keys are searched in and read from
|
/// param1 is a directory where the keys are searched in and read from
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
msg.param
|
msg.param
|
||||||
.set(Param::MimeType, "application/autocrypt-setup");
|
.set(Param::MimeType, "application/autocrypt-setup");
|
||||||
msg.param.set_int(Param::Cmd, 6);
|
msg.param.set_int(Param::Cmd, 6);
|
||||||
msg.param.set_int(Param::ForcePlaintext, 2);
|
msg.param
|
||||||
|
.set_int(Param::ForcePlaintext, DC_FP_NO_AUTOCRYPT_HEADER);
|
||||||
|
|
||||||
if !context
|
if !context
|
||||||
.running_state
|
.running_state
|
||||||
@@ -857,11 +858,10 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
|||||||
if entry.is_err() {
|
if entry.is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let entry = entry.unwrap();
|
let entry_fn = entry.unwrap().file_name();
|
||||||
let name_f = entry.file_name();
|
let name_f = entry_fn.to_string_lossy();
|
||||||
let name_c = name_f.to_c_string().unwrap();
|
|
||||||
|
|
||||||
match dc_get_filesuffix_lc(name_f.to_string_lossy()) {
|
match dc_get_filesuffix_lc(&name_f) {
|
||||||
Some(suffix) => {
|
Some(suffix) => {
|
||||||
if suffix != ".asc" {
|
if suffix != ".asc" {
|
||||||
continue;
|
continue;
|
||||||
@@ -871,7 +871,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let path_plus_name = dir.join(entry.file_name());
|
let path_plus_name = dir.join(&entry_fn);
|
||||||
info!(context, "Checking: {}", path_plus_name.display());
|
info!(context, "Checking: {}", path_plus_name.display());
|
||||||
|
|
||||||
free(buf.cast());
|
free(buf.cast());
|
||||||
@@ -909,12 +909,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_default = 1;
|
set_default = 1;
|
||||||
if !strstr(
|
if name_f.find("legacy").is_some() {
|
||||||
name_c.as_ptr(),
|
|
||||||
b"legacy\x00" as *const u8 as *const libc::c_char,
|
|
||||||
)
|
|
||||||
.is_null()
|
|
||||||
{
|
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
"Treating \"{}\" as a legacy private key.",
|
"Treating \"{}\" as a legacy private key.",
|
||||||
|
|||||||
@@ -49,12 +49,11 @@ pub struct MimeFactory<'a> {
|
|||||||
pub increation: bool,
|
pub increation: bool,
|
||||||
pub in_reply_to: *mut libc::c_char,
|
pub in_reply_to: *mut libc::c_char,
|
||||||
pub references: *mut libc::c_char,
|
pub references: *mut libc::c_char,
|
||||||
pub req_mdn: libc::c_int,
|
pub req_mdn: bool,
|
||||||
pub out: *mut MMAPString,
|
pub out: *mut MMAPString,
|
||||||
pub out_encrypted: bool,
|
pub out_encrypted: bool,
|
||||||
pub out_gossiped: bool,
|
pub out_gossiped: bool,
|
||||||
pub out_last_added_location_id: u32,
|
pub out_last_added_location_id: u32,
|
||||||
pub error: *mut libc::c_char,
|
|
||||||
pub context: &'a Context,
|
pub context: &'a Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,12 +73,11 @@ impl<'a> MimeFactory<'a> {
|
|||||||
increation: false,
|
increation: false,
|
||||||
in_reply_to: ptr::null_mut(),
|
in_reply_to: ptr::null_mut(),
|
||||||
references: ptr::null_mut(),
|
references: ptr::null_mut(),
|
||||||
req_mdn: 0,
|
req_mdn: false,
|
||||||
out: ptr::null_mut(),
|
out: ptr::null_mut(),
|
||||||
out_encrypted: false,
|
out_encrypted: false,
|
||||||
out_gossiped: false,
|
out_gossiped: false,
|
||||||
out_last_added_location_id: 0,
|
out_last_added_location_id: 0,
|
||||||
error: ptr::null_mut(),
|
|
||||||
context,
|
context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +102,6 @@ impl<'a> Drop for MimeFactory<'a> {
|
|||||||
if !self.out.is_null() {
|
if !self.out.is_null() {
|
||||||
mmap_string_free(self.out);
|
mmap_string_free(self.out);
|
||||||
}
|
}
|
||||||
free(self.error as *mut libc::c_void);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +207,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
.get_config_int(context, "mdns_enabled")
|
.get_config_int(context, "mdns_enabled")
|
||||||
.unwrap_or_else(|| 1)
|
.unwrap_or_else(|| 1)
|
||||||
{
|
{
|
||||||
factory.req_mdn = 1;
|
factory.req_mdn = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let row = context.sql.query_row(
|
let row = context.sql.query_row(
|
||||||
@@ -319,27 +316,13 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
Ok(factory)
|
Ok(factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory) -> bool {
|
pub unsafe fn dc_mimefactory_render(
|
||||||
let subject: *mut mailimf_subject;
|
context: &Context,
|
||||||
let mut ok_to_continue = true;
|
factory: &mut MimeFactory,
|
||||||
let imf_fields: *mut mailimf_fields;
|
) -> Result<(), Error> {
|
||||||
let mut message: *mut mailmime = ptr::null_mut();
|
|
||||||
let mut afwd_email = false;
|
|
||||||
let mut col: libc::c_int = 0;
|
|
||||||
let mut success = false;
|
|
||||||
let mut parts: libc::c_int = 0;
|
|
||||||
let mut e2ee_guaranteed = false;
|
|
||||||
let mut min_verified: libc::c_int = 0;
|
|
||||||
// 1=add Autocrypt-header (needed eg. for handshaking), 2=no Autocrypte-header (used for MDN)
|
|
||||||
let mut force_plaintext: libc::c_int = 0;
|
|
||||||
let mut do_gossip: libc::c_int = 0;
|
|
||||||
let mut grpimage = None;
|
|
||||||
let mut e2ee_helper = E2eeHelper::default();
|
|
||||||
|
|
||||||
if factory.loaded == Loaded::Nothing || !factory.out.is_null() {
|
if factory.loaded == Loaded::Nothing || !factory.out.is_null() {
|
||||||
/*call empty() before*/
|
bail!("Invalid use of mimefactory-object.");
|
||||||
set_error(factory, "Invalid use of mimefactory-object.");
|
}
|
||||||
} else {
|
|
||||||
let from: *mut mailimf_mailbox_list = mailimf_mailbox_list_new_empty();
|
let from: *mut mailimf_mailbox_list = mailimf_mailbox_list_new_empty();
|
||||||
mailimf_mailbox_list_add(
|
mailimf_mailbox_list_add(
|
||||||
from,
|
from,
|
||||||
@@ -388,14 +371,13 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
let mut in_reply_to_list: *mut clist = ptr::null_mut();
|
let mut in_reply_to_list: *mut clist = ptr::null_mut();
|
||||||
if !factory.in_reply_to.is_null() && 0 != *factory.in_reply_to.offset(0isize) as libc::c_int
|
if !factory.in_reply_to.is_null() && 0 != *factory.in_reply_to.offset(0isize) as libc::c_int {
|
||||||
{
|
|
||||||
in_reply_to_list = dc_str_to_clist(
|
in_reply_to_list = dc_str_to_clist(
|
||||||
factory.in_reply_to,
|
factory.in_reply_to,
|
||||||
b" \x00" as *const u8 as *const libc::c_char,
|
b" \x00" as *const u8 as *const libc::c_char,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
imf_fields = mailimf_fields_new_with_data_all(
|
let imf_fields = mailimf_fields_new_with_data_all(
|
||||||
mailimf_get_date(factory.timestamp as i64),
|
mailimf_get_date(factory.timestamp as i64),
|
||||||
from,
|
from,
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
@@ -418,13 +400,27 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
let headerval = format!("Delta Chat Core {}{}", version, os_part);
|
let headerval = format!("Delta Chat Core {}{}", version, os_part);
|
||||||
add_mailimf_field(imf_fields, "X-Mailer", &headerval);
|
add_mailimf_field(imf_fields, "X-Mailer", &headerval);
|
||||||
add_mailimf_field(imf_fields, "Chat-Version", "1.0");
|
add_mailimf_field(imf_fields, "Chat-Version", "1.0");
|
||||||
if 0 != factory.req_mdn {
|
if factory.req_mdn {
|
||||||
let headerval = to_string(factory.from_addr);
|
let headerval = to_string(factory.from_addr);
|
||||||
add_mailimf_field(imf_fields, "Chat-Disposition-Notification-To", &headerval);
|
add_mailimf_field(imf_fields, "Chat-Disposition-Notification-To", &headerval);
|
||||||
}
|
}
|
||||||
message = mailmime_new_message_data(0 as *mut mailmime);
|
|
||||||
|
let cleanup = |message: *mut mailmime| {
|
||||||
|
if !message.is_null() {
|
||||||
|
mailmime_free(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let message = mailmime_new_message_data(0 as *mut mailmime);
|
||||||
mailmime_set_imf_fields(message, imf_fields);
|
mailmime_set_imf_fields(message, imf_fields);
|
||||||
if factory.loaded == Loaded::Message {
|
|
||||||
|
// 1=add Autocrypt-header (needed eg. for handshaking), 2=no Autocrypte-header (used for MDN)
|
||||||
|
let mut e2ee_guaranteed = false;
|
||||||
|
let mut min_verified: libc::c_int = 0;
|
||||||
|
let mut do_gossip = false;
|
||||||
|
let mut grpimage = None;
|
||||||
|
let force_plaintext: libc::c_int;
|
||||||
|
let subject_str = match factory.loaded {
|
||||||
|
Loaded::Message => {
|
||||||
/* Render a normal message
|
/* Render a normal message
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
let chat = factory.chat.as_ref().unwrap();
|
let chat = factory.chat.as_ref().unwrap();
|
||||||
@@ -454,7 +450,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
if chat.gossiped_timestamp == 0
|
if chat.gossiped_timestamp == 0
|
||||||
|| (chat.gossiped_timestamp + (2 * 24 * 60 * 60)) < time()
|
|| (chat.gossiped_timestamp + (2 * 24 * 60 * 60)) < time()
|
||||||
{
|
{
|
||||||
do_gossip = 1
|
do_gossip = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build header etc. */
|
/* build header etc. */
|
||||||
@@ -475,7 +471,8 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
);
|
);
|
||||||
assert!(res == MAILIMF_NO_ERROR as i32);
|
assert!(res == MAILIMF_NO_ERROR as i32);
|
||||||
|
|
||||||
if command == SystemMessage::MemberRemovedFromGroup {
|
match command {
|
||||||
|
SystemMessage::MemberRemovedFromGroup => {
|
||||||
let email_to_remove = factory.msg.param.get(Param::Arg).unwrap_or_default();
|
let email_to_remove = factory.msg.param.get(Param::Arg).unwrap_or_default();
|
||||||
if !email_to_remove.is_empty() {
|
if !email_to_remove.is_empty() {
|
||||||
add_mailimf_field(
|
add_mailimf_field(
|
||||||
@@ -484,9 +481,10 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
&email_to_remove,
|
&email_to_remove,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if command == SystemMessage::MemberAddedToGroup {
|
}
|
||||||
|
SystemMessage::MemberAddedToGroup => {
|
||||||
let msg = &factory.msg;
|
let msg = &factory.msg;
|
||||||
do_gossip = 1;
|
do_gossip = true;
|
||||||
let email_to_add = msg.param.get(Param::Arg).unwrap_or_default();
|
let email_to_add = msg.param.get(Param::Arg).unwrap_or_default();
|
||||||
if !email_to_add.is_empty() {
|
if !email_to_add.is_empty() {
|
||||||
add_mailimf_field(imf_fields, "Chat-Group-Member-Added", &email_to_add);
|
add_mailimf_field(imf_fields, "Chat-Group-Member-Added", &email_to_add);
|
||||||
@@ -500,24 +498,29 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
);
|
);
|
||||||
add_mailimf_field(imf_fields, "Secure-Join", "vg-member-added");
|
add_mailimf_field(imf_fields, "Secure-Join", "vg-member-added");
|
||||||
}
|
}
|
||||||
} else if command == SystemMessage::GroupNameChanged {
|
}
|
||||||
|
SystemMessage::GroupNameChanged => {
|
||||||
let msg = &factory.msg;
|
let msg = &factory.msg;
|
||||||
let value_to_add = msg.param.get(Param::Arg).unwrap_or_default();
|
let value_to_add = msg.param.get(Param::Arg).unwrap_or_default();
|
||||||
|
|
||||||
add_mailimf_field(imf_fields, "Chat-Group-Name-Changed", &value_to_add);
|
add_mailimf_field(imf_fields, "Chat-Group-Name-Changed", &value_to_add);
|
||||||
} else if command == SystemMessage::GroupImageChanged {
|
}
|
||||||
|
SystemMessage::GroupImageChanged => {
|
||||||
let msg = &factory.msg;
|
let msg = &factory.msg;
|
||||||
grpimage = msg.param.get(Param::Arg);
|
grpimage = msg.param.get(Param::Arg);
|
||||||
if grpimage.is_none() {
|
if grpimage.is_none() {
|
||||||
add_mailimf_field(imf_fields, "Chat-Group-Image", "0");
|
add_mailimf_field(imf_fields, "Chat-Group-Image", "0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if command == SystemMessage::LocationStreamingEnabled {
|
match command {
|
||||||
|
SystemMessage::LocationStreamingEnabled => {
|
||||||
add_mailimf_field(imf_fields, "Chat-Content", "location-streaming-enabled");
|
add_mailimf_field(imf_fields, "Chat-Content", "location-streaming-enabled");
|
||||||
}
|
}
|
||||||
if command == SystemMessage::AutocryptSetupMessage {
|
SystemMessage::AutocryptSetupMessage => {
|
||||||
add_mailimf_field(imf_fields, "Autocrypt-Setup-Message", "v1");
|
add_mailimf_field(imf_fields, "Autocrypt-Setup-Message", "v1");
|
||||||
placeholdertext = Some(
|
placeholdertext = Some(
|
||||||
factory
|
factory
|
||||||
@@ -526,7 +529,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if command == SystemMessage::SecurejoinMessage {
|
SystemMessage::SecurejoinMessage => {
|
||||||
let msg = &factory.msg;
|
let msg = &factory.msg;
|
||||||
let step = msg.param.get(Param::Arg).unwrap_or_default();
|
let step = msg.param.get(Param::Arg).unwrap_or_default();
|
||||||
if !step.is_empty() {
|
if !step.is_empty() {
|
||||||
@@ -539,7 +542,8 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
if !param2.is_empty() {
|
if !param2.is_empty() {
|
||||||
add_mailimf_field(
|
add_mailimf_field(
|
||||||
imf_fields,
|
imf_fields,
|
||||||
if step == "vg-request-with-auth" || step == "vc-request-with-auth" {
|
if step == "vg-request-with-auth" || step == "vc-request-with-auth"
|
||||||
|
{
|
||||||
"Secure-Join-Auth"
|
"Secure-Join-Auth"
|
||||||
} else {
|
} else {
|
||||||
"Secure-Join-Invitenumber"
|
"Secure-Join-Invitenumber"
|
||||||
@@ -559,6 +563,8 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(grpimage) = grpimage {
|
if let Some(grpimage) = grpimage {
|
||||||
info!(factory.context, "setting group image '{}'", grpimage);
|
info!(factory.context, "setting group image '{}'", grpimage);
|
||||||
@@ -591,7 +597,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
add_mailimf_field(imf_fields, "Chat-Duration", &dur);
|
add_mailimf_field(imf_fields, "Chat-Duration", &dur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
afwd_email = factory.msg.param.exists(Param::Forwarded);
|
let afwd_email = factory.msg.param.exists(Param::Forwarded);
|
||||||
let fwdhint = if afwd_email {
|
let fwdhint = if afwd_email {
|
||||||
Some(
|
Some(
|
||||||
"---------- Forwarded message ----------\r\nFrom: Delta Chat\r\n\r\n"
|
"---------- Forwarded message ----------\r\nFrom: Delta Chat\r\n\r\n"
|
||||||
@@ -629,52 +635,34 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
);
|
);
|
||||||
let text_part = build_body_text(&message_text);
|
let text_part = build_body_text(&message_text);
|
||||||
mailmime_smart_add_part(message, text_part);
|
mailmime_smart_add_part(message, text_part);
|
||||||
parts += 1;
|
|
||||||
|
|
||||||
/* add attachment part */
|
/* add attachment part */
|
||||||
if chat::msgtype_has_file(factory.msg.type_0) {
|
if chat::msgtype_has_file(factory.msg.type_0) {
|
||||||
if !is_file_size_okay(context, &factory.msg) {
|
if !is_file_size_okay(context, &factory.msg) {
|
||||||
let error = format!(
|
cleanup(message);
|
||||||
|
bail!(
|
||||||
"Message exceeds the recommended {} MB.",
|
"Message exceeds the recommended {} MB.",
|
||||||
24 * 1024 * 1024 / 4 * 3 / 1000 / 1000,
|
24 * 1024 * 1024 / 4 * 3 / 1000 / 1000,
|
||||||
);
|
);
|
||||||
set_error(factory, &error);
|
|
||||||
ok_to_continue = false;
|
|
||||||
} else {
|
} else {
|
||||||
let (file_part, _) = build_body_file(context, &factory.msg, "");
|
let (file_part, _) = build_body_file(context, &factory.msg, "");
|
||||||
if !file_part.is_null() {
|
if !file_part.is_null() {
|
||||||
mailmime_smart_add_part(message, file_part);
|
mailmime_smart_add_part(message, file_part);
|
||||||
parts += 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ok_to_continue {
|
|
||||||
if parts == 0 {
|
|
||||||
set_error(factory, "Empty message.");
|
|
||||||
ok_to_continue = false;
|
|
||||||
} else {
|
|
||||||
if !meta_part.is_null() {
|
if !meta_part.is_null() {
|
||||||
mailmime_smart_add_part(message, meta_part);
|
mailmime_smart_add_part(message, meta_part);
|
||||||
}
|
}
|
||||||
if factory.msg.param.exists(Param::SetLatitude) {
|
if factory.msg.param.exists(Param::SetLatitude) {
|
||||||
let latitude = factory
|
let param = &factory.msg.param;
|
||||||
.msg
|
|
||||||
.param
|
|
||||||
.get_float(Param::SetLatitude)
|
|
||||||
.unwrap_or_default();
|
|
||||||
let longitude = factory
|
|
||||||
.msg
|
|
||||||
.param
|
|
||||||
.get_float(Param::SetLongitude)
|
|
||||||
.unwrap_or_default();
|
|
||||||
let kml_file = location::get_message_kml(
|
let kml_file = location::get_message_kml(
|
||||||
factory.msg.timestamp_sort,
|
factory.msg.timestamp_sort,
|
||||||
latitude,
|
param.get_float(Param::SetLatitude).unwrap_or_default(),
|
||||||
longitude,
|
param.get_float(Param::SetLongitude).unwrap_or_default(),
|
||||||
);
|
);
|
||||||
let content_type = mailmime_content_new_with_str(
|
let content_type = mailmime_content_new_with_str(
|
||||||
b"application/vnd.google-earth.kml+xml\x00" as *const u8
|
b"application/vnd.google-earth.kml+xml\x00" as *const u8 as *const libc::c_char,
|
||||||
as *const libc::c_char,
|
|
||||||
);
|
);
|
||||||
let mime_fields = mailmime_fields_new_filename(
|
let mime_fields = mailmime_fields_new_filename(
|
||||||
MAILMIME_DISPOSITION_TYPE_ATTACHMENT as libc::c_int,
|
MAILMIME_DISPOSITION_TYPE_ATTACHMENT as libc::c_int,
|
||||||
@@ -708,9 +696,13 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get_subject(context, factory.chat.as_ref(), &mut factory.msg, afwd_email)
|
||||||
}
|
}
|
||||||
}
|
Loaded::MDN => {
|
||||||
} else if factory.loaded == Loaded::MDN {
|
/* Render a MDN
|
||||||
|
*********************************************************************/
|
||||||
|
/* RFC 6522, this also requires the `report-type` parameter which is equal
|
||||||
|
to the MIME subtype of the second body part of the multipart/report */
|
||||||
let multipart: *mut mailmime =
|
let multipart: *mut mailmime =
|
||||||
mailmime_multiple_new(b"multipart/report\x00" as *const u8 as *const libc::c_char);
|
mailmime_multiple_new(b"multipart/report\x00" as *const u8 as *const libc::c_char);
|
||||||
let content: *mut mailmime_content = (*multipart).mm_content_type;
|
let content: *mut mailmime_content = (*multipart).mm_content_type;
|
||||||
@@ -761,21 +753,25 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
let mach_mime_part: *mut mailmime = mailmime_new_empty(content_type_0, mime_fields_0);
|
let mach_mime_part: *mut mailmime = mailmime_new_empty(content_type_0, mime_fields_0);
|
||||||
set_body_text(mach_mime_part, &message_text2);
|
set_body_text(mach_mime_part, &message_text2);
|
||||||
mailmime_add_part(multipart, mach_mime_part);
|
mailmime_add_part(multipart, mach_mime_part);
|
||||||
force_plaintext = 2;
|
force_plaintext = DC_FP_NO_AUTOCRYPT_HEADER;
|
||||||
} else {
|
/* currently, we do not send MDNs encrypted:
|
||||||
set_error(factory, "No message loaded.");
|
- in a multi-device-setup that is not set up properly, MDNs would disturb the communication as they
|
||||||
ok_to_continue = false;
|
are send automatically which may lead to spreading outdated Autocrypt headers.
|
||||||
}
|
- they do not carry any information but the Message-ID
|
||||||
|
- this save some KB
|
||||||
if ok_to_continue {
|
- in older versions, we did not encrypt messages to ourself when they to to SMTP - however, if these messages
|
||||||
let subject_str = if factory.loaded == Loaded::MDN {
|
are forwarded for any reasons (eg. gmail always forwards to IMAP), we have no chance to decrypt them;
|
||||||
|
this issue is fixed with 0.9.4 */
|
||||||
let e = factory.context.stock_str(StockMessage::ReadRcpt);
|
let e = factory.context.stock_str(StockMessage::ReadRcpt);
|
||||||
format!("Chat: {}", e)
|
format!("Chat: {}", e).to_string()
|
||||||
} else {
|
}
|
||||||
get_subject(context, factory.chat.as_ref(), &mut factory.msg, afwd_email)
|
_ => {
|
||||||
|
cleanup(message);
|
||||||
|
bail!("No message loaded.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
subject = mailimf_subject_new(dc_encode_header_words(subject_str));
|
let subject = mailimf_subject_new(dc_encode_header_words(subject_str));
|
||||||
mailimf_fields_add(
|
mailimf_fields_add(
|
||||||
imf_fields,
|
imf_fields,
|
||||||
mailimf_field_new(
|
mailimf_field_new(
|
||||||
@@ -804,11 +800,12 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if force_plaintext != 2 {
|
let mut e2ee_helper = E2eeHelper::default();
|
||||||
|
if force_plaintext != DC_FP_NO_AUTOCRYPT_HEADER {
|
||||||
e2ee_helper.encrypt(
|
e2ee_helper.encrypt(
|
||||||
factory.context,
|
factory.context,
|
||||||
factory.recipients_addr,
|
factory.recipients_addr,
|
||||||
force_plaintext,
|
force_plaintext == DC_FP_ADD_AUTOCRYPT_HEADER,
|
||||||
e2ee_guaranteed,
|
e2ee_guaranteed,
|
||||||
min_verified,
|
min_verified,
|
||||||
do_gossip,
|
do_gossip,
|
||||||
@@ -817,21 +814,16 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory
|
|||||||
}
|
}
|
||||||
if e2ee_helper.encryption_successfull {
|
if e2ee_helper.encryption_successfull {
|
||||||
factory.out_encrypted = true;
|
factory.out_encrypted = true;
|
||||||
if 0 != do_gossip {
|
if do_gossip {
|
||||||
factory.out_gossiped = true;
|
factory.out_gossiped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
factory.out = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
factory.out = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
|
||||||
|
let mut col: libc::c_int = 0;
|
||||||
mailmime_write_mem(factory.out, &mut col, message);
|
mailmime_write_mem(factory.out, &mut col, message);
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !message.is_null() {
|
|
||||||
mailmime_free(message);
|
|
||||||
}
|
|
||||||
e2ee_helper.thanks();
|
e2ee_helper.thanks();
|
||||||
success
|
cleanup(message);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_subject(
|
fn get_subject(
|
||||||
@@ -845,10 +837,8 @@ fn get_subject(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let chat = chat.unwrap();
|
let chat = chat.unwrap();
|
||||||
|
|
||||||
let raw_subject =
|
let raw_subject =
|
||||||
message::get_summarytext_by_raw(msg.type_0, msg.text.as_ref(), &mut msg.param, 32, context);
|
message::get_summarytext_by_raw(msg.type_0, msg.text.as_ref(), &mut msg.param, 32, context);
|
||||||
|
|
||||||
let fwd = if afwd_email { "Fwd: " } else { "" };
|
let fwd = if afwd_email { "Fwd: " } else { "" };
|
||||||
|
|
||||||
if msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage {
|
if msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage {
|
||||||
@@ -862,14 +852,6 @@ fn get_subject(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn set_error(factory: *mut MimeFactory, text: &str) {
|
|
||||||
if factory.is_null() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free((*factory).error as *mut libc::c_void);
|
|
||||||
(*factory).error = text.strdup();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn add_mailimf_field(fields: *mut mailimf_fields, name: &str, value: &str) {
|
pub unsafe fn add_mailimf_field(fields: *mut mailimf_fields, name: &str, value: &str) {
|
||||||
let field = mailimf_field_new_custom(name.strdup(), value.strdup());
|
let field = mailimf_field_new_custom(name.strdup(), value.strdup());
|
||||||
let res = mailimf_fields_add(fields, field);
|
let res = mailimf_fields_add(fields, field);
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ impl E2eeHelper {
|
|||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
recipients_addr: *const clist,
|
recipients_addr: *const clist,
|
||||||
force_unencrypted: libc::c_int,
|
force_unencrypted: bool,
|
||||||
e2ee_guaranteed: bool,
|
e2ee_guaranteed: bool,
|
||||||
min_verified: libc::c_int,
|
min_verified: libc::c_int,
|
||||||
do_gossip: libc::c_int,
|
do_gossip: bool,
|
||||||
mut in_out_message: *mut mailmime,
|
mut in_out_message: *mut mailmime,
|
||||||
) {
|
) {
|
||||||
let mut ok_to_continue = true;
|
let mut ok_to_continue = true;
|
||||||
@@ -141,7 +141,7 @@ impl E2eeHelper {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
if 0 != force_unencrypted {
|
if force_unencrypted {
|
||||||
do_encrypt = 0i32
|
do_encrypt = 0i32
|
||||||
}
|
}
|
||||||
imffields_unprotected = mailmime_find_mailimf_fields(in_out_message);
|
imffields_unprotected = mailmime_find_mailimf_fields(in_out_message);
|
||||||
@@ -168,7 +168,7 @@ impl E2eeHelper {
|
|||||||
imffields_encrypted,
|
imffields_encrypted,
|
||||||
part_to_encrypt,
|
part_to_encrypt,
|
||||||
);
|
);
|
||||||
if 0 != do_gossip {
|
if do_gossip {
|
||||||
let i_cnt = peerstates.len() as libc::c_int;
|
let i_cnt = peerstates.len() as libc::c_int;
|
||||||
if i_cnt > 1 {
|
if i_cnt > 1 {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|||||||
@@ -680,8 +680,9 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: u32) -> libc::c_int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* create message */
|
/* create message */
|
||||||
if !dc_mimefactory_render(context, &mut mimefactory) {
|
if let Err(msg) = dc_mimefactory_render(context, &mut mimefactory) {
|
||||||
message::set_msg_failed(context, msg_id, as_opt_str(mimefactory.error));
|
let e = msg.to_string();
|
||||||
|
message::set_msg_failed(context, msg_id, Some(e));
|
||||||
} else if 0
|
} else if 0
|
||||||
!= mimefactory
|
!= mimefactory
|
||||||
.msg
|
.msg
|
||||||
@@ -998,7 +999,7 @@ fn connect_to_inbox(context: &Context, inbox: &Imap) -> libc::c_int {
|
|||||||
|
|
||||||
fn send_mdn(context: &Context, msg_id: u32) {
|
fn send_mdn(context: &Context, msg_id: u32) {
|
||||||
if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } {
|
if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } {
|
||||||
if unsafe { dc_mimefactory_render(context, &mut mimefactory) } {
|
if unsafe { dc_mimefactory_render(context, &mut mimefactory) }.is_ok() {
|
||||||
add_smtp_job(context, Action::SendMdn, &mut mimefactory);
|
add_smtp_job(context, Action::SendMdn, &mut mimefactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -688,6 +688,7 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"vcard" => (Viewtype::File, "text/vcard"),
|
"vcard" => (Viewtype::File, "text/vcard"),
|
||||||
};
|
};
|
||||||
let extension: &str = &path.extension()?.to_str()?.to_lowercase();
|
let extension: &str = &path.extension()?.to_str()?.to_lowercase();
|
||||||
|
|
||||||
KNOWN.get(extension).map(|x| *x)
|
KNOWN.get(extension).map(|x| *x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user