mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
refactor(mmime): rustify mailmime_address
This commit is contained in:
@@ -278,17 +278,17 @@ unsafe fn display_group(mut group: *mut mailimf_group) {
|
|||||||
}
|
}
|
||||||
print!("; ");
|
print!("; ");
|
||||||
}
|
}
|
||||||
unsafe fn display_address(mut a: *mut mailimf_address) {
|
unsafe fn display_address(a: *mut mailimf_address) {
|
||||||
match (*a).ad_type {
|
match *a {
|
||||||
2 => {
|
mailimf_address::Group(data) => {
|
||||||
display_group((*a).ad_data.ad_group);
|
display_group(data);
|
||||||
}
|
}
|
||||||
1 => {
|
mailimf_address::Mailbox(data) => {
|
||||||
display_mailbox((*a).ad_data.ad_mailbox);
|
display_mailbox(data);
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn display_address_list(mut addr_list: *mut mailimf_address_list) {
|
unsafe fn display_address_list(mut addr_list: *mut mailimf_address_list) {
|
||||||
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
let mut cur: *mut clistiter = 0 as *mut clistiter;
|
||||||
cur = (*(*addr_list).ad_list).first;
|
cur = (*(*addr_list).ad_list).first;
|
||||||
|
|||||||
@@ -1665,52 +1665,38 @@ pub unsafe fn mailimf_address_list_parse(
|
|||||||
@return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
|
@return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
|
||||||
*/
|
*/
|
||||||
pub unsafe fn mailimf_address_parse(
|
pub unsafe fn mailimf_address_parse(
|
||||||
mut message: *const libc::c_char,
|
message: *const libc::c_char,
|
||||||
mut length: size_t,
|
length: size_t,
|
||||||
mut indx: *mut size_t,
|
indx: *mut size_t,
|
||||||
mut result: *mut *mut mailimf_address,
|
result: *mut *mut mailimf_address,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let mut type_0: libc::c_int = 0;
|
let mut mailbox = std::ptr::null_mut();
|
||||||
let mut cur_token: size_t = 0;
|
let mut group = std::ptr::null_mut();
|
||||||
let mut mailbox: *mut mailimf_mailbox = 0 as *mut mailimf_mailbox;
|
let mut cur_token = *indx;
|
||||||
let mut group: *mut mailimf_group = 0 as *mut mailimf_group;
|
|
||||||
let mut address: *mut mailimf_address = 0 as *mut mailimf_address;
|
let mut r = mailimf_group_parse(message, length, &mut cur_token, &mut group);
|
||||||
let mut r: libc::c_int = 0;
|
|
||||||
let mut res: libc::c_int = 0;
|
|
||||||
cur_token = *indx;
|
|
||||||
mailbox = 0 as *mut mailimf_mailbox;
|
|
||||||
group = 0 as *mut mailimf_group;
|
|
||||||
type_0 = MAILIMF_ADDRESS_ERROR as libc::c_int;
|
|
||||||
r = mailimf_group_parse(message, length, &mut cur_token, &mut group);
|
|
||||||
if r == MAILIMF_NO_ERROR as libc::c_int {
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
type_0 = MAILIMF_ADDRESS_GROUP as libc::c_int
|
// Valid group address
|
||||||
|
*indx = cur_token;
|
||||||
|
*result = mailimf_address_new_group(group);
|
||||||
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
if r == MAILIMF_ERROR_PARSE as libc::c_int {
|
||||||
r = mailimf_mailbox_parse(message, length, &mut cur_token, &mut mailbox);
|
r = mailimf_mailbox_parse(message, length, &mut cur_token, &mut mailbox);
|
||||||
if r == MAILIMF_NO_ERROR as libc::c_int {
|
if r == MAILIMF_NO_ERROR as libc::c_int {
|
||||||
type_0 = MAILIMF_ADDRESS_MAILBOX as libc::c_int
|
// Valid mailbox address
|
||||||
}
|
|
||||||
}
|
|
||||||
if r != MAILIMF_NO_ERROR as libc::c_int {
|
|
||||||
res = r
|
|
||||||
} else {
|
|
||||||
address = mailimf_address_new(type_0, mailbox, group);
|
|
||||||
if address.is_null() {
|
|
||||||
res = MAILIMF_ERROR_MEMORY as libc::c_int;
|
|
||||||
if !mailbox.is_null() {
|
|
||||||
mailimf_mailbox_free(mailbox);
|
|
||||||
}
|
|
||||||
if !group.is_null() {
|
|
||||||
mailimf_group_free(group);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*result = address;
|
|
||||||
*indx = cur_token;
|
*indx = cur_token;
|
||||||
|
mailimf_address_new_mailbox(mailbox);
|
||||||
return MAILIMF_NO_ERROR as libc::c_int;
|
return MAILIMF_NO_ERROR as libc::c_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
// Cannot parse this address
|
||||||
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mailimf_mailbox_parse will parse the given address
|
mailimf_mailbox_parse will parse the given address
|
||||||
|
|
||||||
|
|||||||
@@ -46,32 +46,14 @@ pub struct mailimf_date_time {
|
|||||||
/* if this is a group
|
/* if this is a group
|
||||||
(group_name: address1@domain1,
|
(group_name: address1@domain1,
|
||||||
address2@domain2; ) */
|
address2@domain2; ) */
|
||||||
pub const MAILIMF_ADDRESS_GROUP: libc::c_uint = 2;
|
|
||||||
/* if this is a mailbox (mailbox@domain) */
|
|
||||||
pub const MAILIMF_ADDRESS_MAILBOX: libc::c_uint = 1;
|
|
||||||
/* on parse error */
|
|
||||||
pub const MAILIMF_ADDRESS_ERROR: libc::c_uint = 0;
|
|
||||||
/*
|
|
||||||
mailimf_address is an address
|
|
||||||
|
|
||||||
- type can be MAILIMF_ADDRESS_MAILBOX or MAILIMF_ADDRESS_GROUP
|
/// An address, either for a mailbox or a group.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
- mailbox is a mailbox if type is MAILIMF_ADDRESS_MAILBOX
|
pub enum mailimf_address {
|
||||||
|
Mailbox(*mut mailimf_mailbox),
|
||||||
- group is a group if type is MAILIMF_ADDRESS_GROUP
|
Group(*mut mailimf_group),
|
||||||
*/
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct mailimf_address {
|
|
||||||
pub ad_type: libc::c_int,
|
|
||||||
pub ad_data: unnamed_0,
|
|
||||||
}
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub union unnamed_0 {
|
|
||||||
pub ad_mailbox: *mut mailimf_mailbox,
|
|
||||||
pub ad_group: *mut mailimf_group,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mailimf_group is a group
|
mailimf_group is a group
|
||||||
|
|
||||||
@@ -481,43 +463,40 @@ pub unsafe fn mailimf_date_time_new(
|
|||||||
(*date_time).dt_zone = dt_zone;
|
(*date_time).dt_zone = dt_zone;
|
||||||
return date_time;
|
return date_time;
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe fn mailimf_date_time_free(mut date_time: *mut mailimf_date_time) {
|
pub unsafe fn mailimf_date_time_free(mut date_time: *mut mailimf_date_time) {
|
||||||
free(date_time as *mut libc::c_void);
|
free(date_time as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe fn mailimf_address_new(
|
pub fn mailimf_address_new_mailbox(ad_mailbox: *mut mailimf_mailbox) -> *mut mailimf_address {
|
||||||
mut ad_type: libc::c_int,
|
let addr = mailimf_address::Mailbox(ad_mailbox);
|
||||||
mut ad_mailbox: *mut mailimf_mailbox,
|
|
||||||
mut ad_group: *mut mailimf_group,
|
Box::into_raw(Box::new(addr))
|
||||||
) -> *mut mailimf_address {
|
}
|
||||||
let mut address: *mut mailimf_address = 0 as *mut mailimf_address;
|
|
||||||
address =
|
pub fn mailimf_address_new_group(ad_group: *mut mailimf_group) -> *mut mailimf_address {
|
||||||
malloc(::std::mem::size_of::<mailimf_address>() as libc::size_t) as *mut mailimf_address;
|
let addr = mailimf_address::Group(ad_group);
|
||||||
|
|
||||||
|
Box::into_raw(Box::new(addr))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn mailimf_address_free(address: *mut mailimf_address) {
|
||||||
if address.is_null() {
|
if address.is_null() {
|
||||||
return 0 as *mut mailimf_address;
|
return;
|
||||||
}
|
}
|
||||||
(*address).ad_type = ad_type;
|
|
||||||
match ad_type {
|
let addr = Box::from_raw(address);
|
||||||
1 => (*address).ad_data.ad_mailbox = ad_mailbox,
|
|
||||||
2 => (*address).ad_data.ad_group = ad_group,
|
match *addr {
|
||||||
_ => {}
|
mailimf_address::Mailbox(data) => {
|
||||||
}
|
mailimf_mailbox_free(data);
|
||||||
return address;
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe fn mailimf_address_free(mut address: *mut mailimf_address) {
|
|
||||||
match (*address).ad_type {
|
|
||||||
1 => {
|
|
||||||
mailimf_mailbox_free((*address).ad_data.ad_mailbox);
|
|
||||||
}
|
}
|
||||||
2 => {
|
mailimf_address::Group(data) => {
|
||||||
mailimf_group_free((*address).ad_data.ad_group);
|
mailimf_group_free(data);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
free(address as *mut libc::c_void);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn mailimf_group_free(mut group: *mut mailimf_group) {
|
pub unsafe fn mailimf_group_free(mut group: *mut mailimf_group) {
|
||||||
if !(*group).grp_mb_list.is_null() {
|
if !(*group).grp_mb_list.is_null() {
|
||||||
|
|||||||
@@ -972,24 +972,24 @@ unsafe fn mailimf_address_write_driver(
|
|||||||
mut col: *mut libc::c_int,
|
mut col: *mut libc::c_int,
|
||||||
mut addr: *mut mailimf_address,
|
mut addr: *mut mailimf_address,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let mut r: libc::c_int = 0;
|
match *addr {
|
||||||
match (*addr).ad_type {
|
mailimf_address::Mailbox(mb_data) => {
|
||||||
1 => {
|
let r = mailimf_mailbox_write_driver(do_write, data, col, mb_data);
|
||||||
r = mailimf_mailbox_write_driver(do_write, data, col, (*addr).ad_data.ad_mailbox);
|
|
||||||
if r != MAILIMF_NO_ERROR as libc::c_int {
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2 => {
|
mailimf_address::Group(gr_data) => {
|
||||||
r = mailimf_group_write_driver(do_write, data, col, (*addr).ad_data.ad_group);
|
let r = mailimf_group_write_driver(do_write, data, col, gr_data);
|
||||||
if r != MAILIMF_NO_ERROR as libc::c_int {
|
if r != MAILIMF_NO_ERROR as libc::c_int {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
return MAILIMF_NO_ERROR as libc::c_int;
|
|
||||||
|
MAILIMF_NO_ERROR as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn mailimf_group_write_driver(
|
unsafe fn mailimf_group_write_driver(
|
||||||
mut do_write: Option<
|
mut do_write: Option<
|
||||||
unsafe fn(_: *mut libc::c_void, _: *const libc::c_char, _: size_t) -> libc::c_int,
|
unsafe fn(_: *mut libc::c_void, _: *const libc::c_char, _: size_t) -> libc::c_int,
|
||||||
|
|||||||
@@ -1252,20 +1252,19 @@ pub fn mailimf_get_recipients(imffields: *mut mailimf_fields) -> HashSet<String>
|
|||||||
if adr.is_null() {
|
if adr.is_null() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let adr = unsafe { *adr };
|
|
||||||
|
|
||||||
if adr.ad_type == MAILIMF_ADDRESS_MAILBOX as libc::c_int {
|
match unsafe { *adr } {
|
||||||
mailimf_get_recipients_add_addr(&mut recipients, unsafe {
|
mailimf_address::Mailbox(mailbox) => {
|
||||||
adr.ad_data.ad_mailbox
|
mailimf_get_recipients_add_addr(&mut recipients, mailbox);
|
||||||
});
|
}
|
||||||
} else if adr.ad_type == MAILIMF_ADDRESS_GROUP as libc::c_int {
|
mailimf_address::Group(group) => {
|
||||||
let group = unsafe { adr.ad_data.ad_group };
|
if !group.is_null() && unsafe { !(*group).grp_mb_list.is_null() } {
|
||||||
if !group.is_null() && unsafe { !(*group).grp_mb_list.is_null() } {
|
for cur3 in unsafe { &(*(*(*group).grp_mb_list).mb_list) } {
|
||||||
for cur3 in unsafe { &(*(*(*group).grp_mb_list).mb_list) } {
|
mailimf_get_recipients_add_addr(
|
||||||
mailimf_get_recipients_add_addr(
|
&mut recipients,
|
||||||
&mut recipients,
|
cur3 as *mut mailimf_mailbox,
|
||||||
cur3 as *mut mailimf_mailbox,
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1856,16 +1856,15 @@ unsafe fn dc_add_or_lookup_contacts_by_address_list(
|
|||||||
if adr_list.is_null() {
|
if adr_list.is_null() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut cur: *mut clistiter = (*(*adr_list).ad_list).first;
|
|
||||||
while !cur.is_null() {
|
for cur in &(*(*adr_list).ad_list) {
|
||||||
let adr: *mut mailimf_address = (if !cur.is_null() {
|
let adr = cur as *mut mailimf_address;
|
||||||
(*cur).data
|
if adr.is_null() {
|
||||||
} else {
|
continue;
|
||||||
ptr::null_mut()
|
}
|
||||||
}) as *mut mailimf_address;
|
|
||||||
if !adr.is_null() {
|
match *adr {
|
||||||
if (*adr).ad_type == MAILIMF_ADDRESS_MAILBOX as libc::c_int {
|
mailimf_address::Mailbox(mb) => {
|
||||||
let mb: *mut mailimf_mailbox = (*adr).ad_data.ad_mailbox;
|
|
||||||
if !mb.is_null() {
|
if !mb.is_null() {
|
||||||
add_or_lookup_contact_by_addr(
|
add_or_lookup_contact_by_addr(
|
||||||
context,
|
context,
|
||||||
@@ -1876,8 +1875,8 @@ unsafe fn dc_add_or_lookup_contacts_by_address_list(
|
|||||||
check_self,
|
check_self,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (*adr).ad_type == MAILIMF_ADDRESS_GROUP as libc::c_int {
|
}
|
||||||
let group: *mut mailimf_group = (*adr).ad_data.ad_group;
|
mailimf_address::Group(group) => {
|
||||||
if !group.is_null() && !(*group).grp_mb_list.is_null() {
|
if !group.is_null() && !(*group).grp_mb_list.is_null() {
|
||||||
dc_add_or_lookup_contacts_by_mailbox_list(
|
dc_add_or_lookup_contacts_by_mailbox_list(
|
||||||
context,
|
context,
|
||||||
@@ -1889,11 +1888,6 @@ unsafe fn dc_add_or_lookup_contacts_by_address_list(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = if !cur.is_null() {
|
|
||||||
(*cur).next
|
|
||||||
} else {
|
|
||||||
ptr::null_mut()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,18 +173,14 @@ impl<'a> MimeFactory<'a> {
|
|||||||
for (name, addr) in name_iter.zip(addr_iter) {
|
for (name, addr) in name_iter.zip(addr_iter) {
|
||||||
mailimf_address_list_add(
|
mailimf_address_list_add(
|
||||||
to,
|
to,
|
||||||
mailimf_address_new(
|
mailimf_address_new_mailbox(mailimf_mailbox_new(
|
||||||
MAILIMF_ADDRESS_MAILBOX as libc::c_int,
|
if !name.is_empty() {
|
||||||
mailimf_mailbox_new(
|
dc_encode_header_words(&name).strdup()
|
||||||
if !name.is_empty() {
|
} else {
|
||||||
dc_encode_header_words(&name).strdup()
|
ptr::null_mut()
|
||||||
} else {
|
},
|
||||||
ptr::null_mut()
|
addr.strdup(),
|
||||||
},
|
)),
|
||||||
addr.strdup(),
|
|
||||||
),
|
|
||||||
ptr::null_mut(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user