[gmime: 16/23] Autocrypt: restructure g_mime_message_get_autocrypt_headers
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime: 16/23] Autocrypt: restructure g_mime_message_get_autocrypt_headers
- Date: Sun, 29 Oct 2017 14:17:00 +0000 (UTC)
commit 795d618cfe469168a3b2f9696f6ba6e357274d87
Author: Daniel Kahn Gillmor <dkg fifthhorseman net>
Date: Mon Oct 23 15:33:06 2017 -0400
Autocrypt: restructure g_mime_message_get_autocrypt_headers
Getting gossiped Autocrypt headers (introductions from a third party)
is similar to getting Autocrypt headers about the sender, but with a
few minor differences. We abstract out the work of picking up the
headers here, to make it easier to implement retrieving gossiped
headers, which will happen in a subsequent patch.
Note that MUAs that handle gossiped headers will need distinct logic
for dealing with gossiped headers instead of "From:" Autocrypt
headers, so it makes sense that they would expect a different API call
to retrieve the gossiped headers.
gmime/gmime-message.c | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gmime/gmime-message.c b/gmime/gmime-message.c
index 9e14504..ece367c 100644
--- a/gmime/gmime-message.c
+++ b/gmime/gmime-message.c
@@ -1184,6 +1184,11 @@ g_mime_message_get_body (GMimeMessage *message)
}
+static GMimeAutocryptHeaderList *
+_get_autocrypt_headers (GMimeMessage *message, gint actype, GDateTime *now, const char *matchheader,
+ InternetAddressList *addresses, gboolean keep_incomplete);
+
+
/**
* g_mime_message_get_autocrypt_headers:
* @message: a #GMimeMessage object.
@@ -1224,15 +1229,21 @@ g_mime_message_get_body (GMimeMessage *message)
GMimeAutocryptHeaderList *
g_mime_message_get_autocrypt_headers (GMimeMessage *message, gint actype, GDateTime *now)
{
+ return _get_autocrypt_headers (message, actype, now, "autocrypt",
message->addrlists[GMIME_ADDRESS_TYPE_FROM], TRUE);
+}
+
+
+static GMimeAutocryptHeaderList *
+_get_autocrypt_headers (GMimeMessage *message, gint actype, GDateTime *now, const char *matchheader,
+ InternetAddressList *addresses, gboolean keep_incomplete)
+{
g_return_val_if_fail (GMIME_IS_MESSAGE (message), NULL);
if (actype != 1)
return NULL;
-
+
GMimeObject *mime_part = GMIME_OBJECT (message);
int i;
- InternetAddressList *addresses = message->addrlists[GMIME_ADDRESS_TYPE_FROM];
-
GMimeAutocryptHeaderList *ret = g_mime_autocrypt_header_list_new ();
guint count = g_mime_autocrypt_header_list_add_missing_addresses (ret, addresses);
if (!count)
@@ -1245,7 +1256,7 @@ g_mime_message_get_autocrypt_headers (GMimeMessage *message, gint actype, GDateT
GMimeHeaderList *headers = g_mime_object_get_header_list(mime_part);
for (i = 0; i < g_mime_header_list_get_count (headers); i++) {
GMimeHeader *header = g_mime_header_list_get_header_at (headers, i);
- if (g_ascii_strcasecmp ("autocrypt", header->name) == 0) {
+ if (g_ascii_strcasecmp (matchheader, header->name) == 0) {
GMimeAutocryptHeader *ah = g_mime_autocrypt_header_new_from_string
(g_mime_header_get_value (header));
if (!ah || ah->actype != actype || ! g_mime_autocrypt_header_is_complete (ah))
goto done;
@@ -1279,6 +1290,9 @@ g_mime_message_get_autocrypt_headers (GMimeMessage *message, gint actype, GDateT
ah->actype = actype;
}
}
+
+ if (!keep_incomplete)
+ g_mime_autocrypt_header_list_remove_incomplete (ret);
if (newnow)
g_date_time_unref (newnow);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]