mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 13:56:30 +03:00
Rename dc_mimefactory_t -> MimeFactory (#563)
Rename dc_mimefactory_t -> MimeFactory
This commit is contained in:
@@ -27,9 +27,15 @@ use crate::param::*;
|
|||||||
use crate::stock::StockMessage;
|
use crate::stock::StockMessage;
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
|
pub enum Loaded {
|
||||||
|
Nothing,
|
||||||
|
Message,
|
||||||
|
MDN, // TODO: invent more descriptive name
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[allow(non_camel_case_types)]
|
pub struct MimeFactory<'a> {
|
||||||
pub struct dc_mimefactory_t<'a> {
|
|
||||||
pub from_addr: *mut libc::c_char,
|
pub from_addr: *mut libc::c_char,
|
||||||
pub from_displayname: *mut libc::c_char,
|
pub from_displayname: *mut libc::c_char,
|
||||||
pub selfstatus: Option<String>,
|
pub selfstatus: Option<String>,
|
||||||
@@ -37,7 +43,7 @@ pub struct dc_mimefactory_t<'a> {
|
|||||||
pub recipients_addr: *mut clist,
|
pub recipients_addr: *mut clist,
|
||||||
pub timestamp: i64,
|
pub timestamp: i64,
|
||||||
pub rfc724_mid: String,
|
pub rfc724_mid: String,
|
||||||
pub loaded: dc_mimefactory_loaded_t,
|
pub loaded: Loaded,
|
||||||
pub msg: Message,
|
pub msg: Message,
|
||||||
pub chat: Option<Chat>,
|
pub chat: Option<Chat>,
|
||||||
pub increation: bool,
|
pub increation: bool,
|
||||||
@@ -45,14 +51,14 @@ pub struct dc_mimefactory_t<'a> {
|
|||||||
pub references: *mut libc::c_char,
|
pub references: *mut libc::c_char,
|
||||||
pub req_mdn: libc::c_int,
|
pub req_mdn: libc::c_int,
|
||||||
pub out: *mut MMAPString,
|
pub out: *mut MMAPString,
|
||||||
pub out_encrypted: libc::c_int,
|
pub out_encrypted: bool,
|
||||||
pub out_gossiped: libc::c_int,
|
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 error: *mut libc::c_char,
|
||||||
pub context: &'a Context,
|
pub context: &'a Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for dc_mimefactory_t<'a> {
|
impl<'a> Drop for MimeFactory<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
free(self.from_addr as *mut libc::c_void);
|
free(self.from_addr as *mut libc::c_void);
|
||||||
@@ -76,21 +82,15 @@ impl<'a> Drop for dc_mimefactory_t<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
type dc_mimefactory_loaded_t = libc::c_uint;
|
|
||||||
const DC_MF_MDN_LOADED: dc_mimefactory_loaded_t = 2;
|
|
||||||
pub const DC_MF_MSG_LOADED: dc_mimefactory_loaded_t = 1;
|
|
||||||
pub const DC_MF_NOTHING_LOADED: dc_mimefactory_loaded_t = 0;
|
|
||||||
|
|
||||||
pub unsafe fn dc_mimefactory_load_msg(
|
pub unsafe fn dc_mimefactory_load_msg(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
) -> Result<dc_mimefactory_t, Error> {
|
) -> Result<MimeFactory, Error> {
|
||||||
ensure!(msg_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id");
|
ensure!(msg_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id");
|
||||||
|
|
||||||
let msg = dc_msg_load_from_db(context, msg_id)?;
|
let msg = dc_msg_load_from_db(context, msg_id)?;
|
||||||
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
let chat = Chat::load_from_db(context, msg.chat_id)?;
|
||||||
let mut factory = dc_mimefactory_t {
|
let mut factory = MimeFactory {
|
||||||
from_addr: ptr::null_mut(),
|
from_addr: ptr::null_mut(),
|
||||||
from_displayname: ptr::null_mut(),
|
from_displayname: ptr::null_mut(),
|
||||||
selfstatus: None,
|
selfstatus: None,
|
||||||
@@ -98,7 +98,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
recipients_addr: clist_new(),
|
recipients_addr: clist_new(),
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
rfc724_mid: String::default(),
|
rfc724_mid: String::default(),
|
||||||
loaded: DC_MF_NOTHING_LOADED,
|
loaded: Loaded::Nothing,
|
||||||
msg,
|
msg,
|
||||||
chat: Some(chat),
|
chat: Some(chat),
|
||||||
increation: false,
|
increation: false,
|
||||||
@@ -106,8 +106,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
references: ptr::null_mut(),
|
references: ptr::null_mut(),
|
||||||
req_mdn: 0,
|
req_mdn: 0,
|
||||||
out: ptr::null_mut(),
|
out: ptr::null_mut(),
|
||||||
out_encrypted: 0,
|
out_encrypted: false,
|
||||||
out_gossiped: 0,
|
out_gossiped: false,
|
||||||
out_last_added_location_id: 0,
|
out_last_added_location_id: 0,
|
||||||
error: ptr::null_mut(),
|
error: ptr::null_mut(),
|
||||||
context,
|
context,
|
||||||
@@ -229,7 +229,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
factory.loaded = DC_MF_MSG_LOADED;
|
factory.loaded = Loaded::Message;
|
||||||
factory.timestamp = factory.msg.timestamp_sort;
|
factory.timestamp = factory.msg.timestamp_sort;
|
||||||
factory.rfc724_mid = factory.msg.rfc724_mid.clone();
|
factory.rfc724_mid = factory.msg.rfc724_mid.clone();
|
||||||
factory.increation = dc_msg_is_increation(&factory.msg);
|
factory.increation = dc_msg_is_increation(&factory.msg);
|
||||||
@@ -237,7 +237,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
Ok(factory)
|
Ok(factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn load_from(factory: &mut dc_mimefactory_t) {
|
unsafe fn load_from(factory: &mut MimeFactory) {
|
||||||
let context = factory.context;
|
let context = factory.context;
|
||||||
factory.from_addr = context
|
factory.from_addr = context
|
||||||
.sql
|
.sql
|
||||||
@@ -266,7 +266,7 @@ unsafe fn load_from(factory: &mut dc_mimefactory_t) {
|
|||||||
pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
) -> Result<dc_mimefactory_t, Error> {
|
) -> Result<MimeFactory, Error> {
|
||||||
if 0 == context
|
if 0 == context
|
||||||
.sql
|
.sql
|
||||||
.get_config_int(context, "mdns_enabled")
|
.get_config_int(context, "mdns_enabled")
|
||||||
@@ -280,7 +280,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
|
|
||||||
let msg = dc_msg_load_from_db(context, msg_id)?;
|
let msg = dc_msg_load_from_db(context, msg_id)?;
|
||||||
|
|
||||||
let mut factory = dc_mimefactory_t {
|
let mut factory = MimeFactory {
|
||||||
from_addr: ptr::null_mut(),
|
from_addr: ptr::null_mut(),
|
||||||
from_displayname: ptr::null_mut(),
|
from_displayname: ptr::null_mut(),
|
||||||
selfstatus: None,
|
selfstatus: None,
|
||||||
@@ -288,7 +288,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
recipients_addr: clist_new(),
|
recipients_addr: clist_new(),
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
rfc724_mid: String::default(),
|
rfc724_mid: String::default(),
|
||||||
loaded: DC_MF_NOTHING_LOADED,
|
loaded: Loaded::Nothing,
|
||||||
msg,
|
msg,
|
||||||
chat: None,
|
chat: None,
|
||||||
increation: false,
|
increation: false,
|
||||||
@@ -296,8 +296,8 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
references: ptr::null_mut(),
|
references: ptr::null_mut(),
|
||||||
req_mdn: 0,
|
req_mdn: 0,
|
||||||
out: ptr::null_mut(),
|
out: ptr::null_mut(),
|
||||||
out_encrypted: 0,
|
out_encrypted: false,
|
||||||
out_gossiped: 0,
|
out_gossiped: false,
|
||||||
out_last_added_location_id: 0,
|
out_last_added_location_id: 0,
|
||||||
error: ptr::null_mut(),
|
error: ptr::null_mut(),
|
||||||
context,
|
context,
|
||||||
@@ -330,12 +330,12 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>(
|
|||||||
load_from(&mut factory);
|
load_from(&mut factory);
|
||||||
factory.timestamp = dc_create_smeared_timestamp(factory.context);
|
factory.timestamp = dc_create_smeared_timestamp(factory.context);
|
||||||
factory.rfc724_mid = dc_create_outgoing_rfc724_mid(None, as_str(factory.from_addr));
|
factory.rfc724_mid = dc_create_outgoing_rfc724_mid(None, as_str(factory.from_addr));
|
||||||
factory.loaded = DC_MF_MDN_LOADED;
|
factory.loaded = Loaded::MDN;
|
||||||
|
|
||||||
Ok(factory)
|
Ok(factory)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefactory_t) -> bool {
|
pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut MimeFactory) -> bool {
|
||||||
let subject: *mut mailimf_subject;
|
let subject: *mut mailimf_subject;
|
||||||
let mut ok_to_continue = true;
|
let mut ok_to_continue = true;
|
||||||
let imf_fields: *mut mailimf_fields;
|
let imf_fields: *mut mailimf_fields;
|
||||||
@@ -354,9 +354,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
|||||||
let mut grpimage = None;
|
let mut grpimage = None;
|
||||||
let mut e2ee_helper = E2eeHelper::default();
|
let mut e2ee_helper = E2eeHelper::default();
|
||||||
|
|
||||||
if factory.loaded as libc::c_uint == DC_MF_NOTHING_LOADED as libc::c_int as libc::c_uint
|
if factory.loaded == Loaded::Nothing || !factory.out.is_null() {
|
||||||
|| !factory.out.is_null()
|
|
||||||
{
|
|
||||||
/*call empty() before*/
|
/*call empty() before*/
|
||||||
set_error(
|
set_error(
|
||||||
factory,
|
factory,
|
||||||
@@ -486,7 +484,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
|||||||
}
|
}
|
||||||
message = mailmime_new_message_data(0 as *mut mailmime);
|
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 as libc::c_uint == DC_MF_MSG_LOADED as libc::c_int as libc::c_uint {
|
if 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();
|
||||||
@@ -909,8 +907,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if factory.loaded as libc::c_uint == DC_MF_MDN_LOADED as libc::c_int as libc::c_uint
|
} else if factory.loaded == Loaded::MDN {
|
||||||
{
|
|
||||||
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;
|
||||||
@@ -971,8 +968,7 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
let subject_str = if factory.loaded as libc::c_uint == DC_MF_MDN_LOADED as libc::c_uint
|
let subject_str = if factory.loaded == Loaded::MDN {
|
||||||
{
|
|
||||||
let e = factory.context.stock_str(StockMessage::ReadRcpt);
|
let e = factory.context.stock_str(StockMessage::ReadRcpt);
|
||||||
format!("Chat: {}", e)
|
format!("Chat: {}", e)
|
||||||
} else {
|
} else {
|
||||||
@@ -1025,9 +1021,9 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if e2ee_helper.encryption_successfull {
|
if e2ee_helper.encryption_successfull {
|
||||||
factory.out_encrypted = 1;
|
factory.out_encrypted = true;
|
||||||
if 0 != do_gossip {
|
if 0 != do_gossip {
|
||||||
factory.out_gossiped = 1
|
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);
|
||||||
@@ -1074,7 +1070,7 @@ unsafe fn get_subject(
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn set_error(factory: *mut dc_mimefactory_t, text: *const libc::c_char) {
|
unsafe fn set_error(factory: *mut MimeFactory, text: *const libc::c_char) {
|
||||||
if factory.is_null() {
|
if factory.is_null() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/job.rs
12
src/job.rs
@@ -686,7 +686,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: u32) -> libc::c_int {
|
|||||||
.param
|
.param
|
||||||
.get_int(Param::GuranteeE2ee)
|
.get_int(Param::GuranteeE2ee)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
&& 0 == mimefactory.out_encrypted
|
&& !mimefactory.out_encrypted
|
||||||
{
|
{
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
@@ -713,7 +713,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: u32) -> libc::c_int {
|
|||||||
dc_strdup(mimefactory.from_addr) as *mut libc::c_void,
|
dc_strdup(mimefactory.from_addr) as *mut libc::c_void,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_gossiped {
|
if mimefactory.out_gossiped {
|
||||||
chat::set_gossiped_timestamp(context, mimefactory.msg.chat_id, time());
|
chat::set_gossiped_timestamp(context, mimefactory.msg.chat_id, time());
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_last_added_location_id {
|
if 0 != mimefactory.out_last_added_location_id {
|
||||||
@@ -732,7 +732,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: u32) -> libc::c_int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_encrypted
|
if mimefactory.out_encrypted
|
||||||
&& mimefactory
|
&& mimefactory
|
||||||
.msg
|
.msg
|
||||||
.param
|
.param
|
||||||
@@ -1003,7 +1003,7 @@ fn send_mdn(context: &Context, msg_id: u32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn add_smtp_job(context: &Context, action: Action, mimefactory: &dc_mimefactory_t) -> libc::c_int {
|
fn add_smtp_job(context: &Context, action: Action, mimefactory: &MimeFactory) -> libc::c_int {
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success: libc::c_int = 0i32;
|
||||||
let mut recipients: *mut libc::c_char = ptr::null_mut();
|
let mut recipients: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut param = Params::new();
|
let mut param = Params::new();
|
||||||
@@ -1033,9 +1033,7 @@ fn add_smtp_job(context: &Context, action: Action, mimefactory: &dc_mimefactory_
|
|||||||
job_add(
|
job_add(
|
||||||
context,
|
context,
|
||||||
action,
|
action,
|
||||||
(if mimefactory.loaded as libc::c_uint
|
(if mimefactory.loaded == Loaded::Message {
|
||||||
== DC_MF_MSG_LOADED as libc::c_int as libc::c_uint
|
|
||||||
{
|
|
||||||
mimefactory.msg.id
|
mimefactory.msg.id
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
|||||||
Reference in New Issue
Block a user