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

Method get_encryption_info

src/chat.rs:1192–1229  ·  view source on GitHub ↗

Returns multi-line text summary of encryption preferences of all chat contacts. This can be used to find out if encryption is not available because keys for some users are missing or simply because the majority of the users in a group prefer plaintext emails. To get more verbose summary for a contact, including its key fingerprint, use [`Contact::get_encrinfo`].

(self, context: &Context)

Source from the content-addressed store, hash-verified

1190 ///
1191 /// To get more verbose summary for a contact, including its key fingerprint, use [`Contact::get_encrinfo`].
1192 pub async fn get_encryption_info(self, context: &Context) -> Result<String> {
1193 let chat = Chat::load_from_db(context, self).await?;
1194 if !chat.is_encrypted(context).await? {
1195 return Ok(stock_str::encr_none(context));
1196 }
1197
1198 let mut ret = stock_str::messages_are_e2ee(context) + "\n";
1199
1200 for &contact_id in get_chat_contacts(context, self)
1201 .await?
1202 .iter()
1203 .filter(|&contact_id| !contact_id.is_special())
1204 {
1205 let contact = Contact::get_by_id(context, contact_id).await?;
1206 let addr = contact.get_addr();
1207 logged_debug_assert!(
1208 context,
1209 contact.is_key_contact(),
1210 "get_encryption_info: contact {contact_id} is not a key-contact."
1211 );
1212 let fingerprint = contact
1213 .fingerprint()
1214 .context("Contact does not have a fingerprint in encrypted chat")?
1215 .human_readable();
1216 if let Some(public_key) = contact.public_key(context).await? {
1217 if let Some(relay_addrs) = addresses_from_public_key(&public_key) {
1218 let relays = relay_addrs.join(",");
1219 ret += &format!("\n{addr}({relays})\n{fingerprint}\n");
1220 } else {
1221 ret += &format!("\n{addr}\n{fingerprint}\n");
1222 }
1223 } else {
1224 ret += &format!("\n{addr}\n(key missing)\n{fingerprint}\n");
1225 }
1226 }
1227
1228 Ok(ret.trim().to_string())
1229 }
1230
1231 /// Bad evil escape hatch.
1232 ///

Callers

nothing calls this directly

Calls 12

encr_noneFunction · 0.85
messages_are_e2eeFunction · 0.85
get_chat_contactsFunction · 0.85
human_readableMethod · 0.80
public_keyMethod · 0.80
is_encryptedMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45
is_specialMethod · 0.45
get_addrMethod · 0.45
fingerprintMethod · 0.45

Tested by

no test coverage detected