Parses `Autocrypt-Gossip` headers from the email, saves the keys into the `public_keys` table, and returns them in a HashMap . `from`: The address which sent the message currently being parsed
(
context: &Context,
from: &str,
recipients: &[SingleInfo],
gossip_headers: Vec<String>,
)
| 2089 | /// |
| 2090 | /// * `from`: The address which sent the message currently being parsed |
| 2091 | async fn parse_gossip_headers( |
| 2092 | context: &Context, |
| 2093 | from: &str, |
| 2094 | recipients: &[SingleInfo], |
| 2095 | gossip_headers: Vec<String>, |
| 2096 | ) -> Result<BTreeMap<String, GossipedKey>> { |
| 2097 | // XXX split the parsing from the modification part |
| 2098 | let mut gossiped_keys: BTreeMap<String, GossipedKey> = Default::default(); |
| 2099 | |
| 2100 | for value in &gossip_headers { |
| 2101 | let header = match Aheader::from_str(value) { |
| 2102 | Ok(header) => header, |
| 2103 | Err(err) => { |
| 2104 | warn!(context, "Failed parsing Autocrypt-Gossip header: {}", err); |
| 2105 | continue; |
| 2106 | } |
| 2107 | }; |
| 2108 | |
| 2109 | if !recipients |
| 2110 | .iter() |
| 2111 | .any(|info| addr_cmp(&info.addr, &header.addr)) |
| 2112 | { |
| 2113 | warn!( |
| 2114 | context, |
| 2115 | "Ignoring gossiped \"{}\" as the address is not in To/Cc list.", &header.addr, |
| 2116 | ); |
| 2117 | continue; |
| 2118 | } |
| 2119 | if addr_cmp(from, &header.addr) { |
| 2120 | // Non-standard, might not be necessary to have this check here |
| 2121 | warn!( |
| 2122 | context, |
| 2123 | "Ignoring gossiped \"{}\" as it equals the From address", &header.addr, |
| 2124 | ); |
| 2125 | continue; |
| 2126 | } |
| 2127 | |
| 2128 | import_public_key(context, &header.public_key) |
| 2129 | .await |
| 2130 | .context("Failed to import Autocrypt-Gossip key")?; |
| 2131 | |
| 2132 | let gossiped_key = GossipedKey { |
| 2133 | public_key: header.public_key, |
| 2134 | |
| 2135 | verified: header.verified, |
| 2136 | }; |
| 2137 | gossiped_keys.insert(header.addr.to_lowercase(), gossiped_key); |
| 2138 | } |
| 2139 | |
| 2140 | Ok(gossiped_keys) |
| 2141 | } |
| 2142 | |
| 2143 | /// Message Disposition Notification (RFC 8098) |
| 2144 | #[derive(Debug)] |
no test coverage detected