Implement get_headerdef method for MailHeader slices

This commit is contained in:
Alexander Krotov
2020-02-11 00:26:06 +03:00
parent f5bb57d6a6
commit c801775a39
5 changed files with 54 additions and 31 deletions

View File

@@ -3,7 +3,7 @@
use std::collections::HashSet;
use std::convert::TryFrom;
use mailparse::{MailHeaderMap, ParsedMail};
use mailparse::ParsedMail;
use num_traits::FromPrimitive;
use crate::aheader::*;
@@ -11,6 +11,7 @@ use crate::config::Config;
use crate::context::Context;
use crate::dc_tools::EmailAddress;
use crate::error::*;
use crate::headerdef::{HeaderDef, HeaderDefMap};
use crate::key::{self, Key, KeyPairUse, SignedPublicKey};
use crate::keyring::*;
use crate::peerstate::*;
@@ -124,7 +125,7 @@ pub fn try_decrypt(
) -> Result<(Option<Vec<u8>>, HashSet<String>)> {
let from = mail
.headers
.get_first_value("From")?
.get_headerdef(HeaderDef::From_)?
.and_then(|from_addr| mailparse::addrparse(&from_addr).ok())
.and_then(|from| from.extract_single_info())
.map(|from| from.addr)