mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 13:56:30 +03:00
refactor: use enum for system messages
This commit is contained in:
committed by
holger krekel
parent
0346dd15d9
commit
c0747bf68d
@@ -11,11 +11,13 @@ use mmime::mailmime_types_helper::*;
|
||||
use mmime::mailmime_write_mem::*;
|
||||
use mmime::mmapstring::*;
|
||||
use mmime::other::*;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use crate::chat::{self, Chat};
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::context::{get_version_str, Context};
|
||||
use crate::dc_mimeparser::SystemMessage;
|
||||
use crate::dc_strencode::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::e2ee::*;
|
||||
@@ -529,7 +531,12 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
||||
}
|
||||
|
||||
/* build header etc. */
|
||||
let command = factory.msg.param.get_int(Param::Cmd).unwrap_or_default();
|
||||
let command = factory
|
||||
.msg
|
||||
.param
|
||||
.get_int(Param::Cmd)
|
||||
.and_then(SystemMessage::from_i32)
|
||||
.unwrap_or_default();
|
||||
if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
@@ -546,181 +553,202 @@ pub unsafe fn dc_mimefactory_render(context: &Context, factory: &mut dc_mimefact
|
||||
dc_encode_header_words(name.as_ptr()),
|
||||
),
|
||||
);
|
||||
if command == DC_CMD_MEMBER_REMOVED_FROM_GROUP {
|
||||
let email_to_remove = factory
|
||||
.msg
|
||||
.param
|
||||
.get(Param::Arg)
|
||||
.unwrap_or_default()
|
||||
.strdup();
|
||||
if strlen(email_to_remove) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Chat-Group-Member-Removed\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
email_to_remove,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if command == DC_CMD_MEMBER_ADDED_TO_GROUP {
|
||||
let msg = &factory.msg;
|
||||
do_gossip = 1;
|
||||
let email_to_add = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
if strlen(email_to_add) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Chat-Group-Member-Added\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
email_to_add,
|
||||
),
|
||||
);
|
||||
grpimage = chat.param.get(Param::ProfileImage);
|
||||
}
|
||||
if 0 != msg.param.get_int(Param::Arg2).unwrap_or_default() & 0x1 {
|
||||
info!(
|
||||
context,
|
||||
"sending secure-join message \'{}\' >>>>>>>>>>>>>>>>>>>>>>>>>",
|
||||
"vg-member-added",
|
||||
);
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Secure-Join\x00" as *const u8 as *const libc::c_char),
|
||||
strdup(b"vg-member-added\x00" as *const u8 as *const libc::c_char),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if command == DC_CMD_GROUPNAME_CHANGED {
|
||||
let msg = &factory.msg;
|
||||
|
||||
let value_to_add = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Chat-Group-Name-Changed\x00" as *const u8 as *const libc::c_char,
|
||||
),
|
||||
value_to_add,
|
||||
),
|
||||
);
|
||||
} else if command == DC_CMD_GROUPIMAGE_CHANGED {
|
||||
let msg = &factory.msg;
|
||||
grpimage = msg.param.get(Param::Arg);
|
||||
if grpimage.is_none() {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char),
|
||||
dc_strdup(b"0\x00" as *const u8 as *const libc::c_char),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if command == DC_CMD_LOCATION_STREAMING_ENABLED {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Chat-Content\x00" as *const u8 as *const libc::c_char),
|
||||
strdup(
|
||||
b"location-streaming-enabled\x00" as *const u8 as *const libc::c_char,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if command == DC_CMD_AUTOCRYPT_SETUP_MESSAGE {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Autocrypt-Setup-Message\x00" as *const u8 as *const libc::c_char),
|
||||
strdup(b"v1\x00" as *const u8 as *const libc::c_char),
|
||||
),
|
||||
);
|
||||
placeholdertext = factory
|
||||
.context
|
||||
.stock_str(StockMessage::AcSetupMsgBody)
|
||||
.strdup();
|
||||
}
|
||||
if command == DC_CMD_SECUREJOIN_MESSAGE {
|
||||
let msg = &factory.msg;
|
||||
let step = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
if strlen(step) > 0 {
|
||||
info!(
|
||||
context,
|
||||
"sending secure-join message \'{}\' >>>>>>>>>>>>>>>>>>>>>>>>>",
|
||||
as_str(step),
|
||||
);
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Secure-Join\x00" as *const u8 as *const libc::c_char),
|
||||
step,
|
||||
),
|
||||
);
|
||||
let param2 = msg.param.get(Param::Arg2).unwrap_or_default().strdup();
|
||||
if strlen(param2) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
if strcmp(
|
||||
step,
|
||||
b"vg-request-with-auth\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0
|
||||
|| strcmp(
|
||||
step,
|
||||
b"vc-request-with-auth\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
) == 0
|
||||
{
|
||||
match command {
|
||||
SystemMessage::Unknown | SystemMessage::LocationOnly => {}
|
||||
SystemMessage::MemberRemovedFromGroup => {
|
||||
let email_to_remove = factory
|
||||
.msg
|
||||
.param
|
||||
.get(Param::Arg)
|
||||
.unwrap_or_default()
|
||||
.strdup();
|
||||
if strlen(email_to_remove) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Secure-Join-Auth\x00" as *const u8 as *const libc::c_char,
|
||||
)
|
||||
} else {
|
||||
strdup(
|
||||
b"Secure-Join-Invitenumber\x00" as *const u8
|
||||
b"Chat-Group-Member-Removed\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
)
|
||||
},
|
||||
param2,
|
||||
),
|
||||
);
|
||||
),
|
||||
email_to_remove,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
let fingerprint = msg.param.get(Param::Arg3).unwrap_or_default().strdup();
|
||||
if strlen(fingerprint) > 0 {
|
||||
SystemMessage::MemberAddedToGroup => {
|
||||
let msg = &factory.msg;
|
||||
do_gossip = 1;
|
||||
let email_to_add = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
if strlen(email_to_add) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Chat-Group-Member-Added\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
email_to_add,
|
||||
),
|
||||
);
|
||||
grpimage = chat.param.get(Param::ProfileImage);
|
||||
}
|
||||
if 0 != msg.param.get_int(Param::Arg2).unwrap_or_default() & 0x1 {
|
||||
info!(
|
||||
context,
|
||||
"sending secure-join message \'{}\' >>>>>>>>>>>>>>>>>>>>>>>>>",
|
||||
"vg-member-added",
|
||||
);
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Secure-Join\x00" as *const u8 as *const libc::c_char),
|
||||
strdup(
|
||||
b"vg-member-added\x00" as *const u8 as *const libc::c_char,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
SystemMessage::GroupNameChanged => {
|
||||
let msg = &factory.msg;
|
||||
|
||||
let value_to_add = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Secure-Join-Fingerprint\x00" as *const u8
|
||||
b"Chat-Group-Name-Changed\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
fingerprint,
|
||||
value_to_add,
|
||||
),
|
||||
);
|
||||
}
|
||||
let grpid = match msg.param.get(Param::Arg4) {
|
||||
Some(id) => id.strdup(),
|
||||
None => std::ptr::null_mut(),
|
||||
};
|
||||
if !grpid.is_null() {
|
||||
SystemMessage::GroupImageChanged => {
|
||||
let msg = &factory.msg;
|
||||
grpimage = msg.param.get(Param::Arg);
|
||||
if grpimage.is_none() {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
||||
),
|
||||
dc_strdup(b"0\x00" as *const u8 as *const libc::c_char),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
SystemMessage::LocationStreamingEnabled => {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Chat-Content\x00" as *const u8 as *const libc::c_char),
|
||||
strdup(
|
||||
b"location-streaming-enabled\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
SystemMessage::AutocryptSetupMessage => {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Secure-Join-Group\x00" as *const u8 as *const libc::c_char,
|
||||
b"Autocrypt-Setup-Message\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
grpid,
|
||||
strdup(b"v1\x00" as *const u8 as *const libc::c_char),
|
||||
),
|
||||
);
|
||||
placeholdertext = factory
|
||||
.context
|
||||
.stock_str(StockMessage::AcSetupMsgBody)
|
||||
.strdup();
|
||||
}
|
||||
SystemMessage::SecurejoinMessage => {
|
||||
let msg = &factory.msg;
|
||||
let step = msg.param.get(Param::Arg).unwrap_or_default().strdup();
|
||||
if strlen(step) > 0 {
|
||||
info!(
|
||||
context,
|
||||
"sending secure-join message \'{}\' >>>>>>>>>>>>>>>>>>>>>>>>>",
|
||||
as_str(step),
|
||||
);
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(b"Secure-Join\x00" as *const u8 as *const libc::c_char),
|
||||
step,
|
||||
),
|
||||
);
|
||||
let param2 = msg.param.get(Param::Arg2).unwrap_or_default().strdup();
|
||||
if strlen(param2) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
if strcmp(
|
||||
step,
|
||||
b"vg-request-with-auth\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
) == 0
|
||||
|| strcmp(
|
||||
step,
|
||||
b"vc-request-with-auth\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
) == 0
|
||||
{
|
||||
strdup(
|
||||
b"Secure-Join-Auth\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
)
|
||||
} else {
|
||||
strdup(
|
||||
b"Secure-Join-Invitenumber\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
)
|
||||
},
|
||||
param2,
|
||||
),
|
||||
);
|
||||
}
|
||||
let fingerprint =
|
||||
msg.param.get(Param::Arg3).unwrap_or_default().strdup();
|
||||
if strlen(fingerprint) > 0 {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Secure-Join-Fingerprint\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
fingerprint,
|
||||
),
|
||||
);
|
||||
}
|
||||
let grpid = match msg.param.get(Param::Arg4) {
|
||||
Some(id) => id.strdup(),
|
||||
None => std::ptr::null_mut(),
|
||||
};
|
||||
if !grpid.is_null() {
|
||||
mailimf_fields_add(
|
||||
imf_fields,
|
||||
mailimf_field_new_custom(
|
||||
strdup(
|
||||
b"Secure-Join-Group\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
),
|
||||
grpid,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(grpimage) = grpimage {
|
||||
info!(factory.context, "setting group image '{}'", grpimage);
|
||||
let mut meta = dc_msg_new_untyped();
|
||||
@@ -1079,7 +1107,13 @@ unsafe fn get_subject(
|
||||
} else {
|
||||
b"\x00" as *const u8 as *const libc::c_char
|
||||
};
|
||||
if msg.param.get_int(Param::Cmd).unwrap_or_default() == DC_CMD_AUTOCRYPT_SETUP_MESSAGE {
|
||||
if msg
|
||||
.param
|
||||
.get_int(Param::Cmd)
|
||||
.and_then(SystemMessage::from_i32)
|
||||
.unwrap_or_default()
|
||||
== SystemMessage::AutocryptSetupMessage
|
||||
{
|
||||
ret = context.stock_str(StockMessage::AcSetupMsgSubject).strdup()
|
||||
} else if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup {
|
||||
ret = format!(
|
||||
|
||||
Reference in New Issue
Block a user