mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
some things
This commit is contained in:
@@ -33,7 +33,7 @@ pub struct MimeParser<'a, 'b> {
|
|||||||
pub parts: Vec<Part>,
|
pub parts: Vec<Part>,
|
||||||
mail: Option<mailparse::ParsedMail<'b>>,
|
mail: Option<mailparse::ParsedMail<'b>>,
|
||||||
pub mimeroot: *mut Mailmime,
|
pub mimeroot: *mut Mailmime,
|
||||||
pub header: HashMap<String, *mut mailimf_field>,
|
pub header: HashMap<String, String>,
|
||||||
pub header_root: *mut mailimf_fields,
|
pub header_root: *mut mailimf_fields,
|
||||||
pub header_protected: *mut mailimf_fields,
|
pub header_protected: *mut mailimf_fields,
|
||||||
pub subject: Option<String>,
|
pub subject: Option<String>,
|
||||||
@@ -347,16 +347,10 @@ impl<'a, 'b> MimeParser<'a, 'b> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or_else(|| self.mail.as_ref().unwrap());
|
.unwrap_or_else(|| self.mail.as_ref().unwrap());
|
||||||
|
|
||||||
let ctype = mailparse::parse_content_type(
|
println!("ctype {:?}", mail.ctype);
|
||||||
&self
|
|
||||||
.lookup_field("Content-Type")
|
|
||||||
.unwrap()
|
|
||||||
.get_value()
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(protected_headers) = ctype.params.get("protected-headers") {
|
if mail.ctype.params.get("protected-headers").is_some() {
|
||||||
if mail.subparts.is_empty() && ctype.mimetype == "text/rfc822-headers" {
|
if mail.subparts.is_empty() && mail.ctype.mimetype == "text/rfc822-headers" {
|
||||||
info!(
|
info!(
|
||||||
self.context,
|
self.context,
|
||||||
"Protected headers found in text/rfc822-headers attachment: Will be ignored.",
|
"Protected headers found in text/rfc822-headers attachment: Will be ignored.",
|
||||||
@@ -365,23 +359,18 @@ impl<'a, 'b> MimeParser<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.header_protected.is_null() {
|
if self.header_protected.is_null() {
|
||||||
// TODO:
|
// use the most outer protected header - this is typically
|
||||||
|
// created in sync with the normal, unprotected header
|
||||||
|
|
||||||
// /* use the most outer protected header - this is typically
|
if let Some(part) = mail.subparts.first() {
|
||||||
// created in sync with the normal, unprotected header */
|
let raw = part.get_body_raw().unwrap();
|
||||||
// let mut dummy = 0;
|
if let Ok((protected_headers, _)) = mailparse::parse_headers(&raw) {
|
||||||
// if mailimf_envelope_and_optional_fields_parse(
|
drop(mail); // I have won against the borrow checker!!!!11
|
||||||
// mime.mm_mime_start,
|
hash_header(&mut self.header, &protected_headers);
|
||||||
// mime.mm_length,
|
} else {
|
||||||
// &mut dummy,
|
warn!(self.context, "Protected headers parsing error.",);
|
||||||
// &mut self.header_protected,
|
}
|
||||||
// ) != MAILIMF_NO_ERROR as libc::c_int
|
}
|
||||||
// || self.header_protected.is_null()
|
|
||||||
// {
|
|
||||||
// warn!(self.context, "Protected headers parsing error.",);
|
|
||||||
// } else {
|
|
||||||
// hash_header(&mut self.header, self.header_protected);
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
self.context,
|
self.context,
|
||||||
@@ -390,6 +379,10 @@ impl<'a, 'b> MimeParser<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mail = omail
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or_else(|| self.mail.as_ref().unwrap());
|
||||||
|
|
||||||
// single = multipart/* only one
|
// single = multipart/* only one
|
||||||
// multiple = multipart/* multiple
|
// multiple = multipart/* multiple
|
||||||
// message = text/rfc822
|
// message = text/rfc822
|
||||||
@@ -554,11 +547,13 @@ impl<'a, 'b> MimeParser<'a, 'b> {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// any_part_added
|
// any_part_added
|
||||||
unimplemented!()
|
// unimplemented!()
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_single_part_if_known(&mut self, omail: Option<mailparse::ParsedMail<'_>>) -> bool {
|
fn add_single_part_if_known(&mut self, omail: Option<mailparse::ParsedMail<'_>>) -> bool {
|
||||||
unimplemented!()
|
false
|
||||||
|
// unimplemented!()
|
||||||
// // return true if a part was added
|
// // return true if a part was added
|
||||||
// let (mime_type, msg_type, raw_mime) = mailmime_get_mime_type(mime);
|
// let (mime_type, msg_type, raw_mime) = mailmime_get_mime_type(mime);
|
||||||
|
|
||||||
@@ -900,50 +895,14 @@ pub struct Part {
|
|||||||
pub param: Params,
|
pub param: Params,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn hash_header(out: &mut HashMap<String, *mut mailimf_field>, in_0: *const mailimf_fields) {
|
fn hash_header(out: &mut HashMap<String, String>, fields: &[mailparse::MailHeader<'_>]) {
|
||||||
if in_0.is_null() {
|
for field in fields {
|
||||||
return;
|
if let Ok(key) = field.get_key() {
|
||||||
}
|
|
||||||
|
|
||||||
for cur in (*(*in_0).fld_list).into_iter() {
|
|
||||||
let field = cur as *mut mailimf_field;
|
|
||||||
// TODO match on enums /rtn
|
|
||||||
|
|
||||||
let key = match (*field).fld_type as libc::c_uint {
|
|
||||||
MAILIMF_FIELD_RETURN_PATH => Some("Return-Path".to_string()),
|
|
||||||
MAILIMF_FIELD_ORIG_DATE => Some("Date".to_string()),
|
|
||||||
MAILIMF_FIELD_FROM => Some("From".to_string()),
|
|
||||||
MAILIMF_FIELD_SENDER => Some("Sender".to_string()),
|
|
||||||
MAILIMF_FIELD_REPLY_TO => Some("Reply-To".to_string()),
|
|
||||||
MAILIMF_FIELD_TO => Some("To".to_string()),
|
|
||||||
MAILIMF_FIELD_CC => Some("Cc".to_string()),
|
|
||||||
MAILIMF_FIELD_BCC => Some("Bcc".to_string()),
|
|
||||||
MAILIMF_FIELD_MESSAGE_ID => Some("Message-ID".to_string()),
|
|
||||||
MAILIMF_FIELD_IN_REPLY_TO => Some("In-Reply-To".to_string()),
|
|
||||||
MAILIMF_FIELD_REFERENCES => Some("References".to_string()),
|
|
||||||
MAILIMF_FIELD_SUBJECT => Some("Subject".to_string()),
|
|
||||||
MAILIMF_FIELD_OPTIONAL_FIELD => {
|
|
||||||
// MAILIMF_FIELD_OPTIONAL_FIELD
|
|
||||||
let optional_field = (*field).fld_data.fld_optional_field;
|
|
||||||
// XXX the optional field sometimes contains invalid UTF8
|
|
||||||
// which should not happen (according to the mime standard).
|
|
||||||
// This might point to a bug in our mime parsing/processing
|
|
||||||
// logic. As mmime/dc_mimeparser is scheduled fore replacement
|
|
||||||
// anyway we just use a lossy conversion.
|
|
||||||
|
|
||||||
if !optional_field.is_null() {
|
|
||||||
Some(to_string_lossy((*optional_field).fld_name))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
if let Some(key) = key {
|
|
||||||
if !out.contains_key(&key) || // key already exists, only overwrite known types (protected headers)
|
if !out.contains_key(&key) || // key already exists, only overwrite known types (protected headers)
|
||||||
(*field).fld_type != MAILIMF_FIELD_OPTIONAL_FIELD as i32 || key.starts_with("Chat-")
|
key.starts_with("Chat-")
|
||||||
{
|
{
|
||||||
out.insert(key, field);
|
// TODO: only overwrite known fields
|
||||||
|
out.insert(key, field.get_value().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user