MCPcopy Create free account
hub / github.com/chatmail/core / from_bytes

Method from_bytes

src/mimeparser.rs:269–706  ·  view source on GitHub ↗

Parse a mime message. This method has some side-effects, such as saving blobs and saving found public keys to the database.

(context: &Context, body: &[u8])

Source from the content-addressed store, hash-verified

267 /// This method has some side-effects,
268 /// such as saving blobs and saving found public keys to the database.
269 pub(crate) async fn from_bytes(context: &Context, body: &[u8]) -> Result<Self> {
270 let mail = mailparse::parse_mail(body)?;
271
272 let timestamp_rcvd = time();
273 let mut timestamp_sent =
274 Self::get_timestamp_sent(&mail.headers, timestamp_rcvd, timestamp_rcvd);
275 let hop_info = parse_receive_headers(&mail.get_headers());
276
277 let mut headers = Default::default();
278 let mut headers_removed = HashSet::<String>::new();
279 let mut recipients = Default::default();
280 let mut past_members = Default::default();
281 let mut from = Default::default();
282 let mut list_post = Default::default();
283 let mut chat_disposition_notification_to = None;
284
285 // Parse IMF headers.
286 MimeMessage::merge_headers(
287 context,
288 &mut headers,
289 &mut headers_removed,
290 &mut recipients,
291 &mut past_members,
292 &mut from,
293 &mut list_post,
294 &mut chat_disposition_notification_to,
295 &mail,
296 );
297 headers_removed.extend(
298 headers
299 .extract_if(|k, _v| is_hidden(k))
300 .map(|(k, _v)| k.to_string()),
301 );
302
303 // Parse hidden headers.
304 let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
305 if mimetype.type_() == mime::MULTIPART
306 && mimetype.subtype().as_str() == "mixed"
307 && let Some(part) = mail.subparts.first()
308 {
309 for field in &part.headers {
310 let key = field.get_key().to_lowercase();
311 if !headers.contains_key(&key) && is_hidden(&key) || key == "message-id" {
312 headers.insert(key.to_string(), field.get_value());
313 }
314 }
315 }
316
317 // Overwrite Message-ID with X-Microsoft-Original-Message-ID.
318 // However if we later find Message-ID in the protected part,
319 // it will overwrite both.
320 if let Some(microsoft_message_id) = remove_header(
321 &mut headers,
322 HeaderDef::XMicrosoftOriginalMessageId.get_headername(),
323 &mut headers_removed,
324 ) {
325 headers.insert(
326 HeaderDef::MessageId.get_headername().to_string(),

Callers

nothing calls this directly

Calls 15

timeFunction · 0.85
parse_receive_headersFunction · 0.85
is_hiddenFunction · 0.85
remove_headerFunction · 0.85
decryptFunction · 0.85
addr_cmpFunction · 0.85
import_public_keyFunction · 0.85
load_self_public_keyringFunction · 0.85
parse_gossip_headersFunction · 0.85
parse_message_idFunction · 0.85

Tested by

no test coverage detected