mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
push down unsafe from whole-function to expressions
This commit is contained in:
@@ -105,15 +105,15 @@ impl<'a> MimeParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn parse(&mut self, body: &[u8]) -> Result<(), Error> {
|
pub fn parse(&mut self, body: &[u8]) -> Result<(), Error> {
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|
||||||
let r = mailmime_parse(
|
let r = unsafe { mailmime_parse(
|
||||||
body.as_ptr() as *const libc::c_char,
|
body.as_ptr() as *const libc::c_char,
|
||||||
body.len(),
|
body.len(),
|
||||||
&mut index,
|
&mut index,
|
||||||
&mut self.mimeroot,
|
&mut self.mimeroot,
|
||||||
);
|
) };
|
||||||
|
|
||||||
if r == MAILIMF_NO_ERROR as libc::c_int && !self.mimeroot.is_null() {
|
if r == MAILIMF_NO_ERROR as libc::c_int && !self.mimeroot.is_null() {
|
||||||
let (encrypted, signatures, gossipped_addr) =
|
let (encrypted, signatures, gossipped_addr) =
|
||||||
@@ -121,11 +121,11 @@ impl<'a> MimeParser<'a> {
|
|||||||
self.encrypted = encrypted;
|
self.encrypted = encrypted;
|
||||||
self.signatures = signatures;
|
self.signatures = signatures;
|
||||||
self.gossipped_addr = gossipped_addr;
|
self.gossipped_addr = gossipped_addr;
|
||||||
self.parse_mime_recursive(self.mimeroot);
|
unsafe { self.parse_mime_recursive(self.mimeroot) } ;
|
||||||
|
|
||||||
if let Some(field) = self.lookup_field("Subject") {
|
if let Some(field) = self.lookup_field("Subject") {
|
||||||
if (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int {
|
if unsafe { (*field).fld_type } == MAILIMF_FIELD_SUBJECT as libc::c_int {
|
||||||
let subj = (*(*field).fld_data.fld_subject).sbj_value;
|
let subj = unsafe { (*(*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);
|
||||||
}
|
}
|
||||||
@@ -284,21 +284,21 @@ impl<'a> MimeParser<'a> {
|
|||||||
let mut index_0 = 0;
|
let mut index_0 = 0;
|
||||||
let dn_field_c = CString::new(dn_field).unwrap_or_default();
|
let dn_field_c = CString::new(dn_field).unwrap_or_default();
|
||||||
|
|
||||||
if mailimf_mailbox_list_parse(
|
if unsafe { mailimf_mailbox_list_parse(
|
||||||
dn_field_c.as_ptr(),
|
dn_field_c.as_ptr(),
|
||||||
strlen(dn_field_c.as_ptr()),
|
strlen(dn_field_c.as_ptr()),
|
||||||
&mut index_0,
|
&mut index_0,
|
||||||
&mut mb_list,
|
&mut mb_list,
|
||||||
) == MAILIMF_NO_ERROR as libc::c_int
|
) } == MAILIMF_NO_ERROR as libc::c_int
|
||||||
&& !mb_list.is_null()
|
&& !mb_list.is_null()
|
||||||
{
|
{
|
||||||
if let Some(dn_to_addr) = wrapmime::mailimf_find_first_addr(mb_list) {
|
if let Some(dn_to_addr) = wrapmime::mailimf_find_first_addr(mb_list) {
|
||||||
if let Some(from_field) = self.lookup_field("From") {
|
if let Some(from_field) = self.lookup_field("From") {
|
||||||
if (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int
|
if unsafe { (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int
|
||||||
&& !(*from_field).fld_data.fld_from.is_null()
|
&& !(*from_field).fld_data.fld_from.is_null() }
|
||||||
{
|
{
|
||||||
let from_addr = wrapmime::mailimf_find_first_addr(
|
let from_addr = wrapmime::mailimf_find_first_addr(
|
||||||
(*(*from_field).fld_data.fld_from).frm_mb_list,
|
unsafe { (*(*from_field).fld_data.fld_from).frm_mb_list },
|
||||||
);
|
);
|
||||||
if let Some(from_addr) = from_addr {
|
if let Some(from_addr) = from_addr {
|
||||||
if from_addr == dn_to_addr {
|
if from_addr == dn_to_addr {
|
||||||
@@ -310,7 +310,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mailimf_mailbox_list_free(mb_list);
|
unsafe { mailimf_mailbox_list_free(mb_list) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ pub fn try_decrypt(
|
|||||||
in_out_message: *mut Mailmime,
|
in_out_message: *mut Mailmime,
|
||||||
) -> Result<(bool, HashSet<String>, HashSet<String>)> {
|
) -> Result<(bool, HashSet<String>, HashSet<String>)> {
|
||||||
// just a pointer into mailmime structure, must not be freed
|
// just a pointer into mailmime structure, must not be freed
|
||||||
let imffields = unsafe { mailmime_find_mailimf_fields(in_out_message) };
|
let imffields = wrapmime::mailmime_find_mailimf_fields(in_out_message);
|
||||||
ensure!(
|
ensure!(
|
||||||
!in_out_message.is_null() && !imffields.is_null(),
|
!in_out_message.is_null() && !imffields.is_null(),
|
||||||
"corrupt invalid mime inputs"
|
"corrupt invalid mime inputs"
|
||||||
|
|||||||
@@ -175,21 +175,21 @@ pub fn mailimf_find_field(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*the result is a pointer to mime, must not be freed*/
|
/*the result is a pointer to mime, must not be freed*/
|
||||||
pub unsafe fn mailmime_find_mailimf_fields(mime: *mut Mailmime) -> *mut mailimf_fields {
|
pub fn mailmime_find_mailimf_fields(mime: *mut Mailmime) -> *mut mailimf_fields {
|
||||||
if mime.is_null() {
|
if mime.is_null() {
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
|
|
||||||
match (*mime).mm_type as _ {
|
match unsafe { (*mime).mm_type as _ } {
|
||||||
MAILMIME_MULTIPLE => {
|
MAILMIME_MULTIPLE => {
|
||||||
for cur_data in (*(*mime).mm_data.mm_multipart.mm_mp_list).into_iter() {
|
for cur_data in unsafe { (*(*mime).mm_data.mm_multipart.mm_mp_list).into_iter() } {
|
||||||
let header = mailmime_find_mailimf_fields(cur_data as *mut _);
|
let header = mailmime_find_mailimf_fields(cur_data as *mut _);
|
||||||
if !header.is_null() {
|
if !header.is_null() {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MAILMIME_MESSAGE => return (*mime).mm_data.mm_message.mm_fields,
|
MAILMIME_MESSAGE => return unsafe { (*mime).mm_data.mm_message.mm_fields },
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user