diff --git a/mmime/src/display.rs b/mmime/src/display.rs index 77e3a185d..92841d589 100644 --- a/mmime/src/display.rs +++ b/mmime/src/display.rs @@ -50,10 +50,7 @@ pub unsafe fn display_mime(mut mime: *mut Mailmime) { } MAILMIME_MESSAGE => { if !(*mime).mm_data.mm_message.mm_fields.is_null() { - if !(*(*(*mime).mm_data.mm_message.mm_fields).fld_list) - .first - .is_null() - { + if !(*(*mime).mm_data.mm_message.mm_fields).0.is_empty() { println!("headers begin"); display_fields((*mime).mm_data.mm_message.mm_fields); println!("headers end"); @@ -279,59 +276,44 @@ unsafe fn display_cc(mut cc: *mut mailimf_cc) { unsafe fn display_subject(mut subject: *mut mailimf_subject) { print!("{}", CStr::from_ptr((*subject).sbj_value).to_str().unwrap()); } -unsafe fn display_field(mut field: *mut mailimf_field) { - match (*field).fld_type { - 9 => { +unsafe fn display_field(field: &mailimf_field) { + match *field { + mailimf_field::OrigDate(date) => { print!("Date: "); - display_orig_date((*field).fld_data.fld_orig_date); + display_orig_date(date); println!(""); } - 10 => { + mailimf_field::From(from) => { print!("From: "); - display_from((*field).fld_data.fld_from); + display_from(from); println!(""); } - 13 => { + mailimf_field::To(to) => { print!("To: "); - display_to((*field).fld_data.fld_to); + display_to(to); println!(""); } - 14 => { + mailimf_field::Cc(cc) => { print!("Cc: "); - display_cc((*field).fld_data.fld_cc); + display_cc(cc); println!(""); } - 19 => { + mailimf_field::Subject(subject) => { print!("Subject: "); - display_subject((*field).fld_data.fld_subject); + display_subject(subject); println!(""); } - 16 => { + mailimf_field::MessageId(message_id) => { println!( "Message-ID: {}", - CStr::from_ptr((*(*field).fld_data.fld_message_id).mid_value) - .to_str() - .unwrap(), + CStr::from_ptr((*message_id).mid_value).to_str().unwrap(), ); } _ => {} }; } -unsafe fn display_fields(mut fields: *mut mailimf_fields) { - let mut cur: *mut clistiter = 0 as *mut clistiter; - cur = (*(*fields).fld_list).first; - while !cur.is_null() { - let mut f: *mut mailimf_field = 0 as *mut mailimf_field; - f = (if !cur.is_null() { - (*cur).data - } else { - 0 as *mut libc::c_void - }) as *mut mailimf_field; +unsafe fn display_fields(fields: *mut mailimf_fields) { + for f in &(*fields).0 { display_field(f); - cur = if !cur.is_null() { - (*cur).next - } else { - 0 as *mut clistcell - } } } diff --git a/mmime/src/mailimf/mod.rs b/mmime/src/mailimf/mod.rs index 8656fcc6b..d3d577bcd 100644 --- a/mmime/src/mailimf/mod.rs +++ b/mmime/src/mailimf/mod.rs @@ -199,39 +199,20 @@ pub unsafe fn mailimf_fields_parse( ) -> libc::c_int { let mut current_block: u64; let mut cur_token: size_t = 0; - let mut list: *mut clist = 0 as *mut clist; + let mut list = Vec::new(); let mut fields: *mut mailimf_fields = 0 as *mut mailimf_fields; let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; - list = 0 as *mut clist; + list.clear(); + r = mailimf_struct_multiple_parse( message, length, &mut cur_token, &mut list, - ::std::mem::transmute::< - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut *mut mailimf_field, - ) -> libc::c_int, - >, - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut libc::c_void, - ) -> libc::c_int, - >, - >(Some(mailimf_field_parse)), - ::std::mem::transmute::< - Option ()>, - Option libc::c_int>, - >(Some(mailimf_field_free)), + Some(mailimf_field_parse), + None, ); /* if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) { @@ -245,13 +226,8 @@ pub unsafe fn mailimf_fields_parse( current_block = 11050875288958768710; } 1 => { - list = clist_new(); - if list.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - current_block = 6724962012950341805; - } else { - current_block = 11050875288958768710; - } + list.clear(); + current_block = 11050875288958768710; } _ => { res = r; @@ -260,39 +236,24 @@ pub unsafe fn mailimf_fields_parse( } match current_block { 11050875288958768710 => { - fields = mailimf_fields_new(list); - if fields.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - if !list.is_null() { - clist_foreach( - list, - ::std::mem::transmute::< - Option ()>, - clist_func, - >(Some(mailimf_field_free)), - 0 as *mut libc::c_void, - ); - clist_free(list); - } - } else { - *result = fields; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } + *result = mailimf_fields_new(list); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } _ => {} } return res; } + unsafe fn mailimf_field_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut mailimf_field, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut mailimf_field, ) -> libc::c_int { - let mut current_block: u64; - let mut cur_token: size_t = 0; - let mut type_0: libc::c_int = 0; + let mut cur_token = *indx; + let try_optional = false; + let mut return_path: *mut mailimf_return = 0 as *mut mailimf_return; let mut resent_date: *mut mailimf_orig_date = 0 as *mut mailimf_orig_date; let mut resent_from: *mut mailimf_from = 0 as *mut mailimf_from; @@ -315,440 +276,283 @@ unsafe fn mailimf_field_parse( let mut comments: *mut mailimf_comments = 0 as *mut mailimf_comments; let mut keywords: *mut mailimf_keywords = 0 as *mut mailimf_keywords; let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field; - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; - let mut guessed_type: libc::c_int = 0; + + let guessed_type = guess_header_type(message, length, cur_token); + let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; - cur_token = *indx; - return_path = 0 as *mut mailimf_return; - resent_date = 0 as *mut mailimf_orig_date; - resent_from = 0 as *mut mailimf_from; - resent_sender = 0 as *mut mailimf_sender; - resent_to = 0 as *mut mailimf_to; - resent_cc = 0 as *mut mailimf_cc; - resent_bcc = 0 as *mut mailimf_bcc; - resent_msg_id = 0 as *mut mailimf_message_id; - orig_date = 0 as *mut mailimf_orig_date; - from = 0 as *mut mailimf_from; - sender = 0 as *mut mailimf_sender; - reply_to = 0 as *mut mailimf_reply_to; - to = 0 as *mut mailimf_to; - cc = 0 as *mut mailimf_cc; - bcc = 0 as *mut mailimf_bcc; - message_id = 0 as *mut mailimf_message_id; - in_reply_to = 0 as *mut mailimf_in_reply_to; - references = 0 as *mut mailimf_references; - subject = 0 as *mut mailimf_subject; - comments = 0 as *mut mailimf_comments; - keywords = 0 as *mut mailimf_keywords; - optional_field = 0 as *mut mailimf_optional_field; - guessed_type = guess_header_type(message, length, cur_token); - type_0 = MAILIMF_FIELD_NONE as libc::c_int; + match guessed_type { 9 => { r = mailimf_orig_date_parse(message, length, &mut cur_token, &mut orig_date); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = MAILIMF_FIELD_ORIG_DATE as libc::c_int; - current_block = 9846950269610550213; + *result = mailimf_field::OrigDate(orig_date); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 10 => { r = mailimf_from_parse(message, length, &mut cur_token, &mut from); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::From(from); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 11 => { r = mailimf_sender_parse(message, length, &mut cur_token, &mut sender); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Sender(sender); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 12 => { r = mailimf_reply_to_parse(message, length, &mut cur_token, &mut reply_to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ReplyTo(reply_to); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 13 => { r = mailimf_to_parse(message, length, &mut cur_token, &mut to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::To(to); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 14 => { r = mailimf_cc_parse(message, length, &mut cur_token, &mut cc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Cc(cc); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 15 => { r = mailimf_bcc_parse(message, length, &mut cur_token, &mut bcc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Bcc(bcc); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 16 => { r = mailimf_message_id_parse(message, length, &mut cur_token, &mut message_id); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::MessageId(message_id); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 17 => { r = mailimf_in_reply_to_parse(message, length, &mut cur_token, &mut in_reply_to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::InReplyTo(in_reply_to); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 18 => { r = mailimf_references_parse(message, length, &mut cur_token, &mut references); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::References(references); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 19 => { r = mailimf_subject_parse(message, length, &mut cur_token, &mut subject); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Subject(subject); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 20 => { r = mailimf_comments_parse(message, length, &mut cur_token, &mut comments); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Comments(comments); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 21 => { r = mailimf_keywords_parse(message, length, &mut cur_token, &mut keywords); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::Keywords(keywords); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 1 => { r = mailimf_return_parse(message, length, &mut cur_token, &mut return_path); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ReturnPath(return_path); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 2 => { r = mailimf_resent_date_parse(message, length, &mut cur_token, &mut resent_date); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentDate(resent_date); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 3 => { r = mailimf_resent_from_parse(message, length, &mut cur_token, &mut resent_from); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentFrom(resent_from); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 4 => { r = mailimf_resent_sender_parse(message, length, &mut cur_token, &mut resent_sender); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentSender(resent_sender); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 5 => { r = mailimf_resent_to_parse(message, length, &mut cur_token, &mut resent_to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentTo(resent_to); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 6 => { r = mailimf_resent_cc_parse(message, length, &mut cur_token, &mut resent_cc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentCc(resent_cc); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 7 => { r = mailimf_resent_bcc_parse(message, length, &mut cur_token, &mut resent_bcc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentBcc(resent_bcc); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } 8 => { r = mailimf_resent_msg_id_parse(message, length, &mut cur_token, &mut resent_msg_id); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 9846950269610550213; + *result = mailimf_field::ResentMsgId(resent_msg_id); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 9846950269610550213; + try_optional = true; } else { - /* do nothing */ - res = r; - current_block = 10956553358380301606; + return r; } } _ => { - current_block = 9846950269610550213; + try_optional = true; } } - match current_block { - 9846950269610550213 => { - if type_0 == MAILIMF_FIELD_NONE as libc::c_int { - r = mailimf_optional_field_parse( - message, - length, - &mut cur_token, - &mut optional_field, - ); - if r != MAILIMF_NO_ERROR as libc::c_int { - res = r; - current_block = 10956553358380301606; - } else { - type_0 = MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int; - current_block = 2920409193602730479; - } - } else { - current_block = 2920409193602730479; - } - match current_block { - 10956553358380301606 => {} - _ => { - field = mailimf_field_new( - type_0, - return_path, - resent_date, - resent_from, - resent_sender, - resent_to, - resent_cc, - resent_bcc, - resent_msg_id, - orig_date, - from, - sender, - reply_to, - to, - cc, - bcc, - message_id, - in_reply_to, - references, - subject, - comments, - keywords, - optional_field, - ); - if field.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - if !return_path.is_null() { - mailimf_return_free(return_path); - } - if !resent_date.is_null() { - mailimf_orig_date_free(resent_date); - } - if !resent_from.is_null() { - mailimf_from_free(resent_from); - } - if !resent_sender.is_null() { - mailimf_sender_free(resent_sender); - } - if !resent_to.is_null() { - mailimf_to_free(resent_to); - } - if !resent_cc.is_null() { - mailimf_cc_free(resent_cc); - } - if !resent_bcc.is_null() { - mailimf_bcc_free(resent_bcc); - } - if !resent_msg_id.is_null() { - mailimf_message_id_free(resent_msg_id); - } - if !orig_date.is_null() { - mailimf_orig_date_free(orig_date); - } - if !from.is_null() { - mailimf_from_free(from); - } - if !sender.is_null() { - mailimf_sender_free(sender); - } - if !reply_to.is_null() { - mailimf_reply_to_free(reply_to); - } - if !to.is_null() { - mailimf_to_free(to); - } - if !cc.is_null() { - mailimf_cc_free(cc); - } - if !bcc.is_null() { - mailimf_bcc_free(bcc); - } - if !message_id.is_null() { - mailimf_message_id_free(message_id); - } - if !in_reply_to.is_null() { - mailimf_in_reply_to_free(in_reply_to); - } - if !references.is_null() { - mailimf_references_free(references); - } - if !subject.is_null() { - mailimf_subject_free(subject); - } - if !comments.is_null() { - mailimf_comments_free(comments); - } - if !keywords.is_null() { - mailimf_keywords_free(keywords); - } - if !optional_field.is_null() { - mailimf_optional_field_free(optional_field); - } - } else { - *result = field; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } - } - } + + if try_optional { + r = mailimf_optional_field_parse(message, length, &mut cur_token, &mut optional_field); + if r != MAILIMF_NO_ERROR as libc::c_int { + return r; } - _ => {} + *result = mailimf_field::OptionalField(optional_field); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } - return res; + + res } + unsafe fn mailimf_optional_field_parse( mut message: *const libc::c_char, mut length: size_t, @@ -3917,8 +3721,9 @@ unsafe fn mailimf_keywords_parse( } } } - return res; + res } + unsafe fn mailimf_comments_parse( mut message: *const libc::c_char, mut length: size_t, @@ -4027,7 +3832,7 @@ pub unsafe fn mailimf_references_parse( ) -> libc::c_int { let mut references: *mut mailimf_references = 0 as *mut mailimf_references; let mut cur_token: size_t = 0; - let mut msg_id_list: *mut clist = 0 as *mut clist; + let mut msg_id_list = Vec::new(); let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; @@ -4053,7 +3858,8 @@ pub unsafe fn mailimf_references_parse( if r != MAILIMF_NO_ERROR as libc::c_int { res = r } else { - references = mailimf_references_new(msg_id_list); + // references = mailimf_references_new(msg_id_list); + panic!("implement me correctly"); if references.is_null() { res = MAILIMF_ERROR_MEMORY as libc::c_int } else { @@ -4062,15 +3868,10 @@ pub unsafe fn mailimf_references_parse( return MAILIMF_NO_ERROR as libc::c_int; } } - clist_foreach( - msg_id_list, - ::std::mem::transmute::< - Option ()>, - clist_func, - >(Some(mailimf_msg_id_free)), - 0 as *mut libc::c_void, - ); - clist_free(msg_id_list); + + for el in &msg_id_list { + mailimf_msg_id_free(*el); + } } } } @@ -4078,45 +3879,26 @@ pub unsafe fn mailimf_references_parse( } pub unsafe fn mailimf_msg_id_list_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut clist, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut Vec<*mut libc::c_char>, ) -> libc::c_int { - return mailimf_struct_multiple_parse( + mailimf_struct_multiple_parse( message, length, indx, result, - ::std::mem::transmute::< - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut *mut libc::c_char, - ) -> libc::c_int, - >, - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut libc::c_void, - ) -> libc::c_int, - >, - >(Some(mailimf_unstrict_msg_id_parse)), - ::std::mem::transmute::< - Option ()>, - Option libc::c_int>, - >(Some(mailimf_msg_id_free)), - ); + Some(mailimf_unstrict_msg_id_parse), + Some(mailimf_msg_id_free), + ) } + unsafe fn mailimf_unstrict_msg_id_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut libc::c_char, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut *mut libc::c_char, ) -> libc::c_int { let mut msgid: *mut libc::c_char = 0 as *mut libc::c_char; let mut cur_token: size_t = 0; @@ -4383,93 +4165,65 @@ pub unsafe fn mailimf_atom_parse( } return res; } -unsafe fn mailimf_struct_multiple_parse( +unsafe fn mailimf_struct_multiple_parse( mut message: *const libc::c_char, mut length: size_t, mut indx: *mut size_t, - mut result: *mut *mut clist, + mut result: &mut Vec, mut parser: Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut libc::c_void, - ) -> libc::c_int, + unsafe fn(_: *const libc::c_char, _: size_t, _: *mut size_t, _: &mut T) -> libc::c_int, >, - mut destructor: Option libc::c_int>, + mut destructor: Option, ) -> libc::c_int { let mut current_block: u64; - let mut struct_list: *mut clist = 0 as *mut clist; + let mut struct_list = Vec::new(); let mut cur_token: size_t = 0; - let mut value: *mut libc::c_void = 0 as *mut libc::c_void; + let mut value: T; + let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; - r = parser.expect("non-null function pointer")( - message, - length, - &mut cur_token, - &mut value as *mut *mut libc::c_void as *mut libc::c_void, - ); + r = parser.expect("non-null function pointer")(message, length, &mut cur_token, &mut value); if r != MAILIMF_NO_ERROR as libc::c_int { res = r } else { - struct_list = clist_new(); - if struct_list.is_null() { - destructor.expect("non-null function pointer")(value); - res = MAILIMF_ERROR_MEMORY as libc::c_int - } else { - r = clist_insert_after(struct_list, (*struct_list).last, value); - if r < 0i32 { - destructor.expect("non-null function pointer")(value); - res = MAILIMF_ERROR_MEMORY as libc::c_int - } else { - loop { - r = parser.expect("non-null function pointer")( - message, - length, - &mut cur_token, - &mut value as *mut *mut libc::c_void as *mut libc::c_void, - ); - if r != MAILIMF_NO_ERROR as libc::c_int { - if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 11057878835866523405; - break; - } - res = r; - current_block = 8222683242185098763; - break; - } else { - r = clist_insert_after(struct_list, (*struct_list).last, value); - if !(r < 0i32) { - continue; - } - destructor.expect("non-null function pointer")(value); - res = MAILIMF_ERROR_MEMORY as libc::c_int; - current_block = 8222683242185098763; - break; - } - } - match current_block { - 8222683242185098763 => {} - _ => { - *result = struct_list; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } - } - } - clist_foreach( - struct_list, - ::std::mem::transmute::< - Option libc::c_int>, - clist_func, - >(destructor), - 0 as *mut libc::c_void, + struct_list.push(value); + loop { + r = parser.expect("non-null function pointer")( + message, + length, + &mut cur_token, + &mut value, ); - clist_free(struct_list); + if r != MAILIMF_NO_ERROR as libc::c_int { + if r == MAILIMF_ERROR_PARSE as libc::c_int { + current_block = 11057878835866523405; + break; + } + res = r; + current_block = 8222683242185098763; + break; + } else { + struct_list.push(value); + continue; + } + } + match current_block { + 8222683242185098763 => {} + _ => { + *result = struct_list; + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; + } + } + + if let Some(destructor) = destructor { + for el in &struct_list { + destructor(*el); + } } } + return res; } unsafe fn mailimf_in_reply_to_parse( @@ -4480,7 +4234,7 @@ unsafe fn mailimf_in_reply_to_parse( ) -> libc::c_int { let mut in_reply_to: *mut mailimf_in_reply_to = 0 as *mut mailimf_in_reply_to; let mut cur_token: size_t = 0; - let mut msg_id_list: *mut clist = 0 as *mut clist; + let mut msg_id_list = Vec::new(); let mut res: libc::c_int = 0; let mut r: libc::c_int = 0; cur_token = *indx; @@ -4506,7 +4260,8 @@ unsafe fn mailimf_in_reply_to_parse( if r != MAILIMF_NO_ERROR as libc::c_int { res = r } else { - in_reply_to = mailimf_in_reply_to_new(msg_id_list); + // in_reply_to = mailimf_in_reply_to_new(msg_id_list); + panic!("implement me correctly"); if in_reply_to.is_null() { res = MAILIMF_ERROR_MEMORY as libc::c_int } else { @@ -4515,15 +4270,9 @@ unsafe fn mailimf_in_reply_to_parse( return MAILIMF_NO_ERROR as libc::c_int; } } - clist_foreach( - msg_id_list, - ::std::mem::transmute::< - Option ()>, - clist_func, - >(Some(mailimf_msg_id_free)), - 0 as *mut libc::c_void, - ); - clist_free(msg_id_list); + for el in &msg_id_list { + mailimf_msg_id_free(*el); + } } } } @@ -5130,71 +4879,49 @@ pub unsafe fn mailimf_envelope_fields_parse( ) -> libc::c_int { let mut current_block: u64; let mut cur_token: size_t = 0; - let mut list: *mut clist = 0 as *mut clist; let mut fields: *mut mailimf_fields = 0 as *mut mailimf_fields; let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; - list = clist_new(); - if list.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int - } else { - loop { - let mut elt: *mut mailimf_field = 0 as *mut mailimf_field; - r = mailimf_envelope_field_parse(message, length, &mut cur_token, &mut elt); + let mut list = Vec::new(); + + loop { + let mut elt: mailimf_field; + r = mailimf_envelope_field_parse(message, length, &mut cur_token, &mut elt); + if r == MAILIMF_NO_ERROR as libc::c_int { + list.push(elt); + continue; + } else if r == MAILIMF_ERROR_PARSE as libc::c_int { + r = mailimf_ignore_field_parse(message, length, &mut cur_token); if r == MAILIMF_NO_ERROR as libc::c_int { - r = clist_insert_after(list, (*list).last, elt as *mut libc::c_void); - if !(r < 0i32) { - continue; - } - res = MAILIMF_ERROR_MEMORY as libc::c_int; - current_block = 894413572976700158; - break; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - r = mailimf_ignore_field_parse(message, length, &mut cur_token); - if r == MAILIMF_NO_ERROR as libc::c_int { - continue; - } - /* do nothing */ - if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 2719512138335094285; - break; - } - res = r; - current_block = 894413572976700158; - break; - } else { - res = r; - current_block = 894413572976700158; + continue; + } + /* do nothing */ + if r == MAILIMF_ERROR_PARSE as libc::c_int { + current_block = 2719512138335094285; break; } - } - match current_block { - 2719512138335094285 => { - fields = mailimf_fields_new(list); - if fields.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int - } else { - *result = fields; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } - } - _ => {} - } - if !list.is_null() { - clist_foreach( - list, - ::std::mem::transmute:: ()>, clist_func>( - Some(mailimf_field_free), - ), - 0 as *mut libc::c_void, - ); - clist_free(list); + res = r; + current_block = 894413572976700158; + break; + } else { + res = r; + current_block = 894413572976700158; + break; } } - return res; + match current_block { + 2719512138335094285 => { + *result = mailimf_fields_new(list); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; + } + _ => {} + } + + res } + /* mailimf_ignore_field_parse will skip the given field @@ -5302,12 +5029,11 @@ static int mailimf_ftext_parse(const char * message, size_t length, } */ unsafe fn mailimf_envelope_field_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut mailimf_field, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut mailimf_field, ) -> libc::c_int { - let mut current_block: u64; let mut cur_token: size_t = 0; let mut type_0: libc::c_int = 0; let mut orig_date: *mut mailimf_orig_date = 0 as *mut mailimf_orig_date; @@ -5322,252 +5048,100 @@ unsafe fn mailimf_envelope_field_parse( let mut references: *mut mailimf_references = 0 as *mut mailimf_references; let mut subject: *mut mailimf_subject = 0 as *mut mailimf_subject; let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field; - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; - let mut guessed_type: libc::c_int = 0; - let mut r: libc::c_int = 0; - let mut res: libc::c_int = 0; - cur_token = *indx; - orig_date = 0 as *mut mailimf_orig_date; - from = 0 as *mut mailimf_from; - sender = 0 as *mut mailimf_sender; - reply_to = 0 as *mut mailimf_reply_to; - to = 0 as *mut mailimf_to; - cc = 0 as *mut mailimf_cc; - bcc = 0 as *mut mailimf_bcc; - message_id = 0 as *mut mailimf_message_id; - in_reply_to = 0 as *mut mailimf_in_reply_to; - references = 0 as *mut mailimf_references; - subject = 0 as *mut mailimf_subject; - optional_field = 0 as *mut mailimf_optional_field; - guessed_type = guess_header_type(message, length, cur_token); - type_0 = MAILIMF_FIELD_NONE as libc::c_int; + + let mut r = 0; + + let mut cur_token = *indx; + let guessed_type = guess_header_type(message, length, cur_token); + + let mut try_optional = false; + match guessed_type { 9 => { r = mailimf_orig_date_parse(message, length, &mut cur_token, &mut orig_date); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::OrigDate(orig_date); + *indx = cur_token; } } 10 => { r = mailimf_from_parse(message, length, &mut cur_token, &mut from); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::From(from); + *indx = cur_token; } } 11 => { r = mailimf_sender_parse(message, length, &mut cur_token, &mut sender); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::Sender(sender); + *indx = cur_token; } } 12 => { r = mailimf_reply_to_parse(message, length, &mut cur_token, &mut reply_to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::ReplyTo(reply_to); + *indx = cur_token; } } 13 => { r = mailimf_to_parse(message, length, &mut cur_token, &mut to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::To(to); + *indx = cur_token; } } 14 => { r = mailimf_cc_parse(message, length, &mut cur_token, &mut cc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::Cc(cc); + *indx = cur_token; } } 15 => { r = mailimf_bcc_parse(message, length, &mut cur_token, &mut bcc); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::Bcc(bcc); + *indx = cur_token; } } 16 => { r = mailimf_message_id_parse(message, length, &mut cur_token, &mut message_id); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::MessageId(message_id); + *indx = cur_token; } } 17 => { r = mailimf_in_reply_to_parse(message, length, &mut cur_token, &mut in_reply_to); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::InReplyTo(in_reply_to); + *indx = cur_token; } } 18 => { r = mailimf_references_parse(message, length, &mut cur_token, &mut references); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::References(references); + *indx = cur_token; } } 19 => { r = mailimf_subject_parse(message, length, &mut cur_token, &mut subject); if r == MAILIMF_NO_ERROR as libc::c_int { - type_0 = guessed_type; - current_block = 4488496028633655612; - } else if r == MAILIMF_ERROR_PARSE as libc::c_int { - current_block = 4488496028633655612; - } else { - /* do nothing */ - res = r; - current_block = 15605017197726313499; + *result = mailimf_field::Subject(subject); + *indx = cur_token; } } _ => { - current_block = 4488496028633655612; + r = MAILIMF_ERROR_PARSE as libc::c_int; } } - match current_block { - 4488496028633655612 => { - if type_0 == MAILIMF_FIELD_NONE as libc::c_int { - res = MAILIMF_ERROR_PARSE as libc::c_int - } else { - field = mailimf_field_new( - type_0, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - orig_date, - from, - sender, - reply_to, - to, - cc, - bcc, - message_id, - in_reply_to, - references, - subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - optional_field, - ); - if field.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - if !orig_date.is_null() { - mailimf_orig_date_free(orig_date); - } - if !from.is_null() { - mailimf_from_free(from); - } - if !sender.is_null() { - mailimf_sender_free(sender); - } - if !reply_to.is_null() { - mailimf_reply_to_free(reply_to); - } - if !to.is_null() { - mailimf_to_free(to); - } - if !cc.is_null() { - mailimf_cc_free(cc); - } - if !bcc.is_null() { - mailimf_bcc_free(bcc); - } - if !message_id.is_null() { - mailimf_message_id_free(message_id); - } - if !in_reply_to.is_null() { - mailimf_in_reply_to_free(in_reply_to); - } - if !references.is_null() { - mailimf_references_free(references); - } - if !subject.is_null() { - mailimf_subject_free(subject); - } - if !optional_field.is_null() { - mailimf_optional_field_free(optional_field); - } - } else { - *result = field; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } - } - } - _ => {} - } - return res; + + r } + /* mailimf_envelope_fields will parse the given fields (Date, From, Sender, Reply-To, To, Cc, Bcc, Message-ID, In-Reply-To, @@ -5592,39 +5166,19 @@ pub unsafe fn mailimf_envelope_and_optional_fields_parse( ) -> libc::c_int { let mut current_block: u64; let mut cur_token: size_t = 0; - let mut list: *mut clist = 0 as *mut clist; + let mut list: Vec = Vec::new(); let mut fields: *mut mailimf_fields = 0 as *mut mailimf_fields; let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; - list = 0 as *mut clist; + r = mailimf_struct_multiple_parse( message, length, &mut cur_token, &mut list, - ::std::mem::transmute::< - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut *mut mailimf_field, - ) -> libc::c_int, - >, - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut libc::c_void, - ) -> libc::c_int, - >, - >(Some(mailimf_envelope_or_optional_field_parse)), - ::std::mem::transmute::< - Option ()>, - Option libc::c_int>, - >(Some(mailimf_field_free)), + Some(mailimf_envelope_or_optional_field_parse), + None, ); match r { 0 => { @@ -5632,13 +5186,8 @@ pub unsafe fn mailimf_envelope_and_optional_fields_parse( current_block = 11050875288958768710; } 1 => { - list = clist_new(); - if list.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - current_block = 7755940856643933760; - } else { - current_block = 11050875288958768710; - } + list.clear(); + current_block = 11050875288958768710; } _ => { res = r; @@ -5647,35 +5196,21 @@ pub unsafe fn mailimf_envelope_and_optional_fields_parse( } match current_block { 11050875288958768710 => { - fields = mailimf_fields_new(list); - if fields.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - if !list.is_null() { - clist_foreach( - list, - ::std::mem::transmute::< - Option ()>, - clist_func, - >(Some(mailimf_field_free)), - 0 as *mut libc::c_void, - ); - clist_free(list); - } - } else { - *result = fields; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } + *result = mailimf_fields_new(list); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } _ => {} } - return res; + + res } + unsafe fn mailimf_envelope_or_optional_field_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut mailimf_field, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut mailimf_field, ) -> libc::c_int { let mut r: libc::c_int = 0; let mut cur_token: size_t = 0; @@ -5690,38 +5225,10 @@ unsafe fn mailimf_envelope_or_optional_field_parse( if r != MAILIMF_NO_ERROR as libc::c_int { return r; } - field = mailimf_field_new( - MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - optional_field, - ); - if field.is_null() { - mailimf_optional_field_free(optional_field); - return MAILIMF_ERROR_MEMORY as libc::c_int; - } - *result = field; + + *result = mailimf_field::OptionalField(optional_field); *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; + MAILIMF_NO_ERROR as libc::c_int } /* @@ -5746,39 +5253,19 @@ pub unsafe fn mailimf_optional_fields_parse( ) -> libc::c_int { let mut current_block: u64; let mut cur_token: size_t = 0; - let mut list: *mut clist = 0 as *mut clist; + let mut list = Vec::new(); let mut fields: *mut mailimf_fields = 0 as *mut mailimf_fields; let mut r: libc::c_int = 0; let mut res: libc::c_int = 0; cur_token = *indx; - list = 0 as *mut clist; + r = mailimf_struct_multiple_parse( message, length, &mut cur_token, &mut list, - ::std::mem::transmute::< - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut *mut mailimf_field, - ) -> libc::c_int, - >, - Option< - unsafe fn( - _: *const libc::c_char, - _: size_t, - _: *mut size_t, - _: *mut libc::c_void, - ) -> libc::c_int, - >, - >(Some(mailimf_only_optional_field_parse)), - ::std::mem::transmute::< - Option ()>, - Option libc::c_int>, - >(Some(mailimf_field_free)), + Some(mailimf_only_optional_field_parse), + None, ); match r { 0 => { @@ -5786,13 +5273,8 @@ pub unsafe fn mailimf_optional_fields_parse( current_block = 11050875288958768710; } 1 => { - list = clist_new(); - if list.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - current_block = 4409055091581443388; - } else { - current_block = 11050875288958768710; - } + list.clear(); + current_block = 11050875288958768710; } _ => { res = r; @@ -5801,77 +5283,33 @@ pub unsafe fn mailimf_optional_fields_parse( } match current_block { 11050875288958768710 => { - fields = mailimf_fields_new(list); - if fields.is_null() { - res = MAILIMF_ERROR_MEMORY as libc::c_int; - if !list.is_null() { - clist_foreach( - list, - ::std::mem::transmute::< - Option ()>, - clist_func, - >(Some(mailimf_field_free)), - 0 as *mut libc::c_void, - ); - clist_free(list); - } - } else { - *result = fields; - *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; - } + *result = mailimf_fields_new(list); + *indx = cur_token; + return MAILIMF_NO_ERROR as libc::c_int; } _ => {} } - return res; + res } + unsafe fn mailimf_only_optional_field_parse( - mut message: *const libc::c_char, - mut length: size_t, - mut indx: *mut size_t, - mut result: *mut *mut mailimf_field, + message: *const libc::c_char, + length: size_t, + indx: *mut size_t, + result: &mut mailimf_field, ) -> libc::c_int { let mut r: libc::c_int = 0; let mut cur_token: size_t = 0; - let mut optional_field: *mut mailimf_optional_field = 0 as *mut mailimf_optional_field; - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; + let mut optional_field = std::ptr::null_mut(); cur_token = *indx; r = mailimf_optional_field_parse(message, length, &mut cur_token, &mut optional_field); if r != MAILIMF_NO_ERROR as libc::c_int { return r; } - field = mailimf_field_new( - MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - optional_field, - ); - if field.is_null() { - mailimf_optional_field_free(optional_field); - return MAILIMF_ERROR_MEMORY as libc::c_int; - } - *result = field; + + *result = mailimf_field::OptionalField(optional_field); *indx = cur_token; - return MAILIMF_NO_ERROR as libc::c_int; + MAILIMF_NO_ERROR as libc::c_int } pub unsafe fn mailimf_custom_string_parse( diff --git a/mmime/src/mailimf/types.rs b/mmime/src/mailimf/types.rs index 2e860a8a8..79832546e 100644 --- a/mmime/src/mailimf/types.rs +++ b/mmime/src/mailimf/types.rs @@ -134,100 +134,70 @@ pub struct mailimf_message { pub msg_fields: *mut mailimf_fields, pub msg_body: *mut mailimf_body, } -/* - mailimf_fields is a list of header fields - - fld_list is a list of header fields -*/ -#[derive(Copy, Clone)] -#[repr(C)] -pub struct mailimf_fields { - pub fld_list: *mut clist, +/// List of header field. +#[derive(Debug, Clone)] +pub struct mailimf_fields(pub Vec); + +#[derive(Debug, Clone)] +pub enum mailimf_field { + ReturnPath(*mut mailimf_return), + ResentDate(*mut mailimf_orig_date), + ResentFrom(*mut mailimf_from), + ResentSender(*mut mailimf_sender), + ResentTo(*mut mailimf_to), + ResentCc(*mut mailimf_cc), + ResentBcc(*mut mailimf_bcc), + ResentMsgId(*mut mailimf_message_id), + OrigDate(*mut mailimf_orig_date), + From(*mut mailimf_from), + Sender(*mut mailimf_sender), + ReplyTo(*mut mailimf_reply_to), + To(*mut mailimf_to), + Cc(*mut mailimf_cc), + Bcc(*mut mailimf_bcc), + MessageId(*mut mailimf_message_id), + InReplyTo(*mut mailimf_in_reply_to), + References(*mut mailimf_references), + Subject(*mut mailimf_subject), + Comments(*mut mailimf_comments), + Keywords(*mut mailimf_keywords), + OptionalField(*mut mailimf_optional_field), } -/* - mailimf_field is a field - - fld_type is the type of the field - - - fld_data.fld_return_path is the parsed content of the Return-Path - field if type is MAILIMF_FIELD_RETURN_PATH - - - fld_data.fld_resent_date is the parsed content of the Resent-Date field - if type is MAILIMF_FIELD_RESENT_DATE - - - fld_data.fld_resent_from is the parsed content of the Resent-From field - - - fld_data.fld_resent_sender is the parsed content of the Resent-Sender field - - - fld_data.fld_resent_to is the parsed content of the Resent-To field - - - fld_data.fld_resent_cc is the parsed content of the Resent-Cc field - - - fld_data.fld_resent_bcc is the parsed content of the Resent-Bcc field - - - fld_data.fld_resent_msg_id is the parsed content of the Resent-Message-ID - field - - - fld_data.fld_orig_date is the parsed content of the Date field - - - fld_data.fld_from is the parsed content of the From field - - - fld_data.fld_sender is the parsed content of the Sender field - - - fld_data.fld_reply_to is the parsed content of the Reply-To field - - - fld_data.fld_to is the parsed content of the To field - - - fld_data.fld_cc is the parsed content of the Cc field - - - fld_data.fld_bcc is the parsed content of the Bcc field - - - fld_data.fld_message_id is the parsed content of the Message-ID field - - - fld_data.fld_in_reply_to is the parsed content of the In-Reply-To field - - - fld_data.fld_references is the parsed content of the References field - - - fld_data.fld_subject is the content of the Subject field - - - fld_data.fld_comments is the content of the Comments field - - - fld_data.fld_keywords is the parsed content of the Keywords field - - - fld_data.fld_optional_field is an other field and is not parsed -*/ -#[derive(Copy, Clone)] -#[repr(C)] -pub struct mailimf_field { - pub fld_type: libc::c_int, - pub fld_data: unnamed_1, -} -#[derive(Copy, Clone)] -#[repr(C)] -pub union unnamed_1 { - pub fld_return_path: *mut mailimf_return, - pub fld_resent_date: *mut mailimf_orig_date, - pub fld_resent_from: *mut mailimf_from, - pub fld_resent_sender: *mut mailimf_sender, - pub fld_resent_to: *mut mailimf_to, - pub fld_resent_cc: *mut mailimf_cc, - pub fld_resent_bcc: *mut mailimf_bcc, - pub fld_resent_msg_id: *mut mailimf_message_id, - pub fld_orig_date: *mut mailimf_orig_date, - pub fld_from: *mut mailimf_from, - pub fld_sender: *mut mailimf_sender, - pub fld_reply_to: *mut mailimf_reply_to, - pub fld_to: *mut mailimf_to, - pub fld_cc: *mut mailimf_cc, - pub fld_bcc: *mut mailimf_bcc, - pub fld_message_id: *mut mailimf_message_id, - pub fld_in_reply_to: *mut mailimf_in_reply_to, - pub fld_references: *mut mailimf_references, - pub fld_subject: *mut mailimf_subject, - pub fld_comments: *mut mailimf_comments, - pub fld_keywords: *mut mailimf_keywords, - pub fld_optional_field: *mut mailimf_optional_field, +impl Drop for mailimf_field { + fn drop(&mut self) { + use mailimf_field::*; + unsafe { + match self { + ReturnPath(p) => mailimf_return_free(*p), + OrigDate(d) => mailimf_orig_date_free(*d), + ResentFrom(r) => mailimf_from_free(*r), + ResentSender(r) => mailimf_sender_free(*r), + ResentTo(r) => mailimf_to_free(*r), + ResentCc(r) => mailimf_cc_free(*r), + ResentBcc(r) => mailimf_bcc_free(*r), + ResentMsgId(r) => mailimf_message_id_free(*r), + OrigDate(d) => mailimf_orig_date_free(*d), + From(f) => mailimf_from_free(*f), + Sender(s) => mailimf_sender_free(*s), + ReplyTo(t) => mailimf_reply_to_free(*t), + To(t) => mailimf_to_free(*t), + Cc(c) => mailimf_cc_free(*c), + Bcc(c) => mailimf_bcc_free(*c), + MessageId(m) => mailimf_message_id_free(*m), + InReplyTo(i) => mailimf_in_reply_to_free(*i), + References(r) => mailimf_references_free(*r), + Subject(s) => mailimf_subject_free(*s), + Comments(c) => mailimf_comments_free(*c), + Keywords(k) => mailimf_keywords_free(*k), + OptionalField(o) => mailimf_optional_field_free(*o), + _ => {} + } + } + } } + /* mailimf_optional_field is a non-parsed field @@ -634,93 +604,15 @@ pub unsafe fn mailimf_message_free(mut message: *mut mailimf_message) { mailimf_fields_free((*message).msg_fields); free(message as *mut libc::c_void); } -#[no_mangle] -pub unsafe fn mailimf_fields_free(mut fields: *mut mailimf_fields) { - if !(*fields).fld_list.is_null() { - clist_foreach( - (*fields).fld_list, - ::std::mem::transmute:: ()>, clist_func>( - Some(mailimf_field_free), - ), - 0 as *mut libc::c_void, - ); - clist_free((*fields).fld_list); + +pub unsafe fn mailimf_fields_free(fields: *mut mailimf_fields) { + if fields.is_null() { + return; } - free(fields as *mut libc::c_void); -} -#[no_mangle] -pub unsafe fn mailimf_field_free(mut field: *mut mailimf_field) { - match (*field).fld_type { - 1 => { - mailimf_return_free((*field).fld_data.fld_return_path); - } - 2 => { - mailimf_orig_date_free((*field).fld_data.fld_resent_date); - } - 3 => { - mailimf_from_free((*field).fld_data.fld_resent_from); - } - 4 => { - mailimf_sender_free((*field).fld_data.fld_resent_sender); - } - 5 => { - mailimf_to_free((*field).fld_data.fld_resent_to); - } - 6 => { - mailimf_cc_free((*field).fld_data.fld_resent_cc); - } - 7 => { - mailimf_bcc_free((*field).fld_data.fld_resent_bcc); - } - 8 => { - mailimf_message_id_free((*field).fld_data.fld_resent_msg_id); - } - 9 => { - mailimf_orig_date_free((*field).fld_data.fld_orig_date); - } - 10 => { - mailimf_from_free((*field).fld_data.fld_from); - } - 11 => { - mailimf_sender_free((*field).fld_data.fld_sender); - } - 12 => { - mailimf_reply_to_free((*field).fld_data.fld_reply_to); - } - 13 => { - mailimf_to_free((*field).fld_data.fld_to); - } - 14 => { - mailimf_cc_free((*field).fld_data.fld_cc); - } - 15 => { - mailimf_bcc_free((*field).fld_data.fld_bcc); - } - 16 => { - mailimf_message_id_free((*field).fld_data.fld_message_id); - } - 17 => { - mailimf_in_reply_to_free((*field).fld_data.fld_in_reply_to); - } - 18 => { - mailimf_references_free((*field).fld_data.fld_references); - } - 19 => { - mailimf_subject_free((*field).fld_data.fld_subject); - } - 20 => { - mailimf_comments_free((*field).fld_data.fld_comments); - } - 21 => { - mailimf_keywords_free((*field).fld_data.fld_keywords); - } - 22 => { - mailimf_optional_field_free((*field).fld_data.fld_optional_field); - } - _ => {} - } - free(field as *mut libc::c_void); + + let _ = Box::from_raw(fields); } + #[no_mangle] pub unsafe fn mailimf_optional_field_free(mut opt_field: *mut mailimf_optional_field) { mailimf_field_name_free((*opt_field).fld_name); @@ -853,88 +745,11 @@ pub unsafe fn mailimf_path_free(mut path: *mut mailimf_path) { } free(path as *mut libc::c_void); } -#[no_mangle] -pub unsafe fn mailimf_fields_new(mut fld_list: *mut clist) -> *mut mailimf_fields { - let mut fields: *mut mailimf_fields = 0 as *mut mailimf_fields; - fields = malloc(::std::mem::size_of::() as libc::size_t) as *mut mailimf_fields; - if fields.is_null() { - return 0 as *mut mailimf_fields; - } - (*fields).fld_list = fld_list; - return fields; -} -#[no_mangle] -pub unsafe fn mailimf_field_new( - mut fld_type: libc::c_int, - mut fld_return_path: *mut mailimf_return, - mut fld_resent_date: *mut mailimf_orig_date, - mut fld_resent_from: *mut mailimf_from, - mut fld_resent_sender: *mut mailimf_sender, - mut fld_resent_to: *mut mailimf_to, - mut fld_resent_cc: *mut mailimf_cc, - mut fld_resent_bcc: *mut mailimf_bcc, - mut fld_resent_msg_id: *mut mailimf_message_id, - mut fld_orig_date: *mut mailimf_orig_date, - mut fld_from: *mut mailimf_from, - mut fld_sender: *mut mailimf_sender, - mut fld_reply_to: *mut mailimf_reply_to, - mut fld_to: *mut mailimf_to, - mut fld_cc: *mut mailimf_cc, - mut fld_bcc: *mut mailimf_bcc, - mut fld_message_id: *mut mailimf_message_id, - mut fld_in_reply_to: *mut mailimf_in_reply_to, - mut fld_references: *mut mailimf_references, - mut fld_subject: *mut mailimf_subject, - mut fld_comments: *mut mailimf_comments, - mut fld_keywords: *mut mailimf_keywords, - mut fld_optional_field: *mut mailimf_optional_field, -) -> *mut mailimf_field { - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; - field = malloc(::std::mem::size_of::() as libc::size_t) as *mut mailimf_field; - if field.is_null() { - return 0 as *mut mailimf_field; - } - (*field).fld_type = fld_type; - match fld_type { - 1 => (*field).fld_data.fld_return_path = fld_return_path, - 2 => (*field).fld_data.fld_resent_date = fld_resent_date, - 3 => (*field).fld_data.fld_resent_from = fld_resent_from, - 4 => (*field).fld_data.fld_resent_sender = fld_resent_sender, - 5 => (*field).fld_data.fld_resent_to = fld_resent_to, - 6 => (*field).fld_data.fld_resent_cc = fld_resent_cc, - 7 => (*field).fld_data.fld_resent_bcc = fld_resent_bcc, - 8 => (*field).fld_data.fld_resent_msg_id = fld_resent_msg_id, - 9 => (*field).fld_data.fld_orig_date = fld_orig_date, - 10 => (*field).fld_data.fld_from = fld_from, - 11 => (*field).fld_data.fld_sender = fld_sender, - 12 => (*field).fld_data.fld_reply_to = fld_reply_to, - 13 => (*field).fld_data.fld_to = fld_to, - 14 => (*field).fld_data.fld_cc = fld_cc, - 15 => (*field).fld_data.fld_bcc = fld_bcc, - 16 => (*field).fld_data.fld_message_id = fld_message_id, - 17 => (*field).fld_data.fld_in_reply_to = fld_in_reply_to, - 18 => (*field).fld_data.fld_references = fld_references, - 19 => (*field).fld_data.fld_subject = fld_subject, - 20 => (*field).fld_data.fld_comments = fld_comments, - 21 => (*field).fld_data.fld_keywords = fld_keywords, - 22 => (*field).fld_data.fld_optional_field = fld_optional_field, - _ => {} - } - return field; -} +pub unsafe fn mailimf_fields_new(fld_list: Vec) -> *mut mailimf_fields { + let fields = mailimf_fields(fld_list); -#[no_mangle] -pub unsafe fn mailimf_field_new_subject(fld_subject: *mut mailimf_subject) -> *mut mailimf_field { - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; - field = malloc(::std::mem::size_of::() as libc::size_t) as *mut mailimf_field; - if field.is_null() { - return 0 as *mut mailimf_field; - } - (*field).fld_type = MAILIMF_FIELD_SUBJECT as libc::c_int; - (*field).fld_data.fld_subject = fld_subject; - - field + Box::into_raw(Box::new(fields)) } #[no_mangle] @@ -1037,7 +852,7 @@ pub unsafe fn mailimf_in_reply_to_new(mut mid_list: *mut clist) -> *mut mailimf_ } /* != NULL */ #[no_mangle] -pub unsafe fn mailimf_references_new(mut mid_list: *mut clist) -> *mut mailimf_references { +pub unsafe fn mailimf_references_new(mid_list: *mut clist) -> *mut mailimf_references { let mut ref_0: *mut mailimf_references = 0 as *mut mailimf_references; ref_0 = malloc(::std::mem::size_of::() as libc::size_t) as *mut mailimf_references; diff --git a/mmime/src/mailimf/types_helper.rs b/mmime/src/mailimf/types_helper.rs index 8701559b1..5b34dcdb7 100644 --- a/mmime/src/mailimf/types_helper.rs +++ b/mmime/src/mailimf/types_helper.rs @@ -6,18 +6,9 @@ use crate::other::*; this function creates a new mailimf_fields structure with no fields */ pub unsafe fn mailimf_fields_new_empty() -> *mut mailimf_fields { - let mut list: *mut clist = 0 as *mut clist; - let mut fields_list: *mut mailimf_fields = 0 as *mut mailimf_fields; - list = clist_new(); - if list.is_null() { - return 0 as *mut mailimf_fields; - } - fields_list = mailimf_fields_new(list); - if fields_list.is_null() { - return 0 as *mut mailimf_fields; - } - return fields_list; + mailimf_fields_new(Vec::new()) } + /* this function adds a field to the mailimf_fields structure @@ -54,31 +45,7 @@ pub unsafe fn mailimf_field_new_custom( let mut field: *mut mailimf_field = 0 as *mut mailimf_field; opt_field = mailimf_optional_field_new(name, value); if !opt_field.is_null() { - field = mailimf_field_new( - MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - opt_field, - ); + field = mailimf_field::OptionalField(opt_field); if field.is_null() { mailimf_optional_field_free(opt_field); } else { diff --git a/mmime/src/mailmime/content.rs b/mmime/src/mailmime/content.rs index c41ec180f..f17a66e4a 100644 --- a/mmime/src/mailmime/content.rs +++ b/mmime/src/mailmime/content.rs @@ -1243,30 +1243,21 @@ unsafe fn mailmime_preamble_parse( *indx = cur_token; return MAILIMF_NO_ERROR as libc::c_int; } -unsafe fn remove_unparsed_mime_headers(mut fields: *mut mailimf_fields) { - let mut cur: *mut clistiter = 0 as *mut clistiter; - cur = (*(*fields).fld_list).first; - while !cur.is_null() { - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; - let mut delete: libc::c_int = 0; - field = (if !cur.is_null() { - (*cur).data - } else { - 0 as *mut libc::c_void - }) as *mut mailimf_field; - match (*field).fld_type { - 22 => { - delete = 0i32; +unsafe fn remove_unparsed_mime_headers(fields: *mut mailimf_fields) { + (*fields).0.retain(|field| { + let mut delete = false; + + match field { + mailimf_field::OptionalField(data) => { + delete = false; if strncasecmp( - (*(*field).fld_data.fld_optional_field).fld_name, + data.fld_name, b"Content-\x00" as *const u8 as *const libc::c_char, 8i32 as libc::size_t, ) == 0i32 { let mut name: *mut libc::c_char = 0 as *mut libc::c_char; - name = (*(*field).fld_data.fld_optional_field) - .fld_name - .offset(8isize); + name = data.fld_name.offset(8isize); if strcasecmp(name, b"Type\x00" as *const u8 as *const libc::c_char) == 0i32 || strcasecmp( name, @@ -1280,35 +1271,22 @@ unsafe fn remove_unparsed_mime_headers(mut fields: *mut mailimf_fields) { || strcasecmp(name, b"Language\x00" as *const u8 as *const libc::c_char) == 0i32 { - delete = 1i32 + delete = true; } } else if strcasecmp( - (*(*field).fld_data.fld_optional_field).fld_name, + data.fld_name, b"MIME-Version\x00" as *const u8 as *const libc::c_char, ) == 0i32 { - delete = 1i32 - } - if 0 != delete { - cur = clist_delete((*fields).fld_list, cur); - mailimf_field_free(field); - } else { - cur = if !cur.is_null() { - (*cur).next - } else { - 0 as *mut clistcell - } - } - } - _ => { - cur = if !cur.is_null() { - (*cur).next - } else { - 0 as *mut clistcell + delete = true; } } + _ => {} } - } + + // retain keeps everything true + !delete + }); } pub unsafe fn mailmime_extract_boundary( diff --git a/mmime/src/other.rs b/mmime/src/other.rs index 1ef8492c4..1741c5858 100644 --- a/mmime/src/other.rs +++ b/mmime/src/other.rs @@ -431,7 +431,6 @@ pub unsafe fn mailimf_fields_add_data( let mut imf_references: *mut mailimf_references = 0 as *mut mailimf_references; let mut imf_in_reply_to: *mut mailimf_in_reply_to = 0 as *mut mailimf_in_reply_to; let mut imf_subject: *mut mailimf_subject = 0 as *mut mailimf_subject; - let mut field: *mut mailimf_field = 0 as *mut mailimf_field; let mut r: libc::c_int = 0; imf_date = 0 as *mut mailimf_orig_date; imf_from = 0 as *mut mailimf_from; @@ -444,68 +443,18 @@ pub unsafe fn mailimf_fields_add_data( imf_references = 0 as *mut mailimf_references; imf_in_reply_to = 0 as *mut mailimf_in_reply_to; imf_subject = 0 as *mut mailimf_subject; - field = 0 as *mut mailimf_field; + if !date.is_null() { imf_date = mailimf_orig_date_new(date); if imf_date.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_ORIG_DATE as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - imf_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::OrigDate(imf_date); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 2719512138335094285; - } + current_block = 2719512138335094285; } } } else { @@ -518,62 +467,12 @@ pub unsafe fn mailimf_fields_add_data( if imf_from.is_null() { current_block = 13813460800808168376; } else { - field = mailimf_field_new( - MAILIMF_FIELD_FROM as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - imf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::From(imf_from); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 3275366147856559585; - } + current_block = 3275366147856559585; } } } else { @@ -588,62 +487,12 @@ pub unsafe fn mailimf_fields_add_data( if imf_sender.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_SENDER as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - imf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::Sender(imf_sender); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 15090052786889560393; - } + current_block = 15090052786889560393; } } } else { @@ -658,62 +507,12 @@ pub unsafe fn mailimf_fields_add_data( if imf_reply_to.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_REPLY_TO as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - imf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::ReplyTo(imf_reply_to); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 10150597327160359210; - } + current_block = 10150597327160359210; } } } else { @@ -728,62 +527,12 @@ pub unsafe fn mailimf_fields_add_data( if imf_to.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_TO as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - imf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::To(imf_to); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 17233182392562552756; - } + current_block = 17233182392562552756; } } } else { @@ -798,62 +547,12 @@ pub unsafe fn mailimf_fields_add_data( if imf_cc.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_CC as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - imf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = 16539016819803454162; + let field = mailimf_field::Cc(imf_cc); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int { + current_block = 13813460800808168376; } else { - r = mailimf_fields_add(fields, field); - if r != MAILIMF_NO_ERROR as libc::c_int { - current_block = 13813460800808168376; - } else { - current_block = 12930649117290160518; - } + current_block = 12930649117290160518; } } } else { @@ -868,69 +567,14 @@ pub unsafe fn mailimf_fields_add_data( if imf_bcc.is_null() { current_block = 16539016819803454162; } else { - field = mailimf_field_new( - MAILIMF_FIELD_BCC as libc::c_int, - 0 as *mut mailimf_return, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - 0 as *mut mailimf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_orig_date, - 0 as *mut mailimf_from, - 0 as *mut mailimf_sender, - 0 as *mut mailimf_reply_to, - 0 as *mut mailimf_to, - 0 as *mut mailimf_cc, - imf_bcc, - 0 as *mut mailimf_message_id, - 0 as *mut mailimf_in_reply_to, - 0 as *mut mailimf_references, - 0 as *mut mailimf_subject, - 0 as *mut mailimf_comments, - 0 as *mut mailimf_keywords, - 0 as *mut mailimf_optional_field, - ); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { + let field = mailimf_field::Bcc(imf_bcc); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int + { current_block = - 16539016819803454162; + 13813460800808168376; } else { - r = mailimf_fields_add( - fields, field, - ); - if r != MAILIMF_NO_ERROR - as libc::c_int - { - current_block = - 13813460800808168376; - } else { - current_block = - 7858101417678297991; - } + current_block = 7858101417678297991; } } } else { @@ -947,114 +591,21 @@ pub unsafe fn mailimf_fields_add_data( current_block = 16539016819803454162; } else { - field = - mailimf_field_new(MAILIMF_FIELD_MESSAGE_ID - as - libc::c_int, - 0 - as - *mut mailimf_return, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_reply_to, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - imf_msg_id, - 0 - as - *mut mailimf_in_reply_to, - 0 - as - *mut mailimf_references, - 0 - as - *mut mailimf_subject, - 0 - as - *mut mailimf_comments, - 0 - as - *mut mailimf_keywords, - 0 - as - *mut mailimf_optional_field); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { - current_block = - 16539016819803454162; - } else { - r = mailimf_fields_add( - fields, field, + let field = + mailimf_field::MessageId( + imf_msg_id, ); - if r != MAILIMF_NO_ERROR - as libc::c_int - { - current_block - = - 13813460800808168376; - } else { - current_block - = - 15514718523126015390; - } + r = mailimf_fields_add( + fields, field, + ); + if r != MAILIMF_NO_ERROR + as libc::c_int + { + current_block = + 13813460800808168376; + } else { + current_block = + 15514718523126015390; } } } else { @@ -1076,120 +627,24 @@ pub unsafe fn mailimf_fields_add_data( = 16539016819803454162; } else { - field + let field = - mailimf_field_new(MAILIMF_FIELD_IN_REPLY_TO - as - libc::c_int, - 0 - as - *mut mailimf_return, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_reply_to, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - imf_in_reply_to, - 0 - as - *mut mailimf_references, - 0 - as - *mut mailimf_subject, - 0 - as - *mut mailimf_comments, - 0 - as - *mut mailimf_keywords, - 0 - as - *mut mailimf_optional_field); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() { + mailimf_field::InReplyTo( + imf_in_reply_to, + ); + r = mailimf_fields_add( + fields, field, + ); + if r != MAILIMF_NO_ERROR + as libc::c_int + { current_block - = - 16539016819803454162; - } else { - r - = - mailimf_fields_add(fields, - field); - if r - != - MAILIMF_NO_ERROR - as - libc::c_int - { - current_block = 13813460800808168376; - } else { - current_block + } else { + current_block = 15587532755333643506; - } } } } else { @@ -1212,109 +667,15 @@ pub unsafe fn mailimf_fields_add_data( = 16539016819803454162; } else { - field + let field = - mailimf_field_new(MAILIMF_FIELD_REFERENCES - as - libc::c_int, - 0 - as - *mut mailimf_return, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_reply_to, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_in_reply_to, - imf_references, - 0 - as - *mut mailimf_subject, - 0 - as - *mut mailimf_comments, - 0 - as - *mut mailimf_keywords, - 0 - as - *mut mailimf_optional_field); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field - .is_null() - { - current_block - = - 16539016819803454162; - } else { - r + mailimf_field::References( + imf_references); + r = mailimf_fields_add(fields, field); - if r + if r != MAILIMF_NO_ERROR as @@ -1327,7 +688,7 @@ pub unsafe fn mailimf_fields_add_data( current_block = 7301440000599063274; - } + } } } else { @@ -1349,131 +710,28 @@ pub unsafe fn mailimf_fields_add_data( => { if !subject.is_null() - { + { imf_subject = mailimf_subject_new(subject); if imf_subject.is_null() - { + { current_block = 16539016819803454162; } else { - field - = - mailimf_field_new(MAILIMF_FIELD_SUBJECT - as - libc::c_int, - 0 - as - *mut mailimf_return, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_orig_date, - 0 - as - *mut mailimf_from, - 0 - as - *mut mailimf_sender, - 0 - as - *mut mailimf_reply_to, - 0 - as - *mut mailimf_to, - 0 - as - *mut mailimf_cc, - 0 - as - *mut mailimf_bcc, - 0 - as - *mut mailimf_message_id, - 0 - as - *mut mailimf_in_reply_to, - 0 - as - *mut mailimf_references, - imf_subject, - 0 - as - *mut mailimf_comments, - 0 - as - *mut mailimf_keywords, - 0 - as - *mut mailimf_optional_field); - /* return-path */ - /* resent date */ - /* resent from */ - /* resent sender */ - /* resent to */ - /* resent cc */ - /* resent bcc */ - /* resent msg id */ - /* date */ - /* from */ - /* sender */ - /* reply-to */ - /* to */ - /* cc */ - /* bcc */ - /* message id */ - /* in reply to */ - /* references */ - /* subject */ - /* comments */ - /* keywords */ - /* optional field */ - if field.is_null() - { + let field = + mailimf_field::Subject(imf_subject); + r = mailimf_fields_add(fields, field); + if r != MAILIMF_NO_ERROR as libc::c_int + { current_block = - 16539016819803454162; + 13813460800808168376; } else { - r + current_block = - mailimf_fields_add(fields, - field); - if r - != - MAILIMF_NO_ERROR - as - libc::c_int - { - current_block - = - 13813460800808168376; - } else { - current_block - = - 10153752038087260855; - } + 10153752038087260855; } } } else { @@ -1520,15 +778,6 @@ pub unsafe fn mailimf_fields_add_data( } _ => {} } - match current_block { - 13813460800808168376 => { - if !field.is_null() { - detach_field(field); - mailimf_field_free(field); - } - } - _ => {} - } detach_free_fields( imf_date, imf_from, @@ -1542,7 +791,7 @@ pub unsafe fn mailimf_fields_add_data( imf_references, imf_subject, ); - return MAILIMF_ERROR_MEMORY as libc::c_int; + MAILIMF_ERROR_MEMORY } unsafe fn detach_free_fields( @@ -1577,11 +826,6 @@ unsafe fn detach_free_fields( }; } -unsafe fn detach_field(mut field: *mut mailimf_field) { - (*field).fld_type = MAILIMF_FIELD_NONE as libc::c_int; - mailimf_field_free(field); -} - unsafe fn detach_free_common_fields( mut imf_date: *mut mailimf_orig_date, mut imf_from: *mut mailimf_from,