[PATCH 14/23] cli: replace use of g_mime_message_get_recipients

David Bremner david at tethera.net
Sat Jun 3 10:47:45 PDT 2017


This function, and associated enum, have been renamed and generalized
in gmime-3.0.
---
 notmuch-reply.c    | 21 +++++++++------------
 notmuch-show.c     | 17 +++++------------
 util/gmime-extra.c | 20 ++++++++++++++++++++
 util/gmime-extra.h | 22 ++++++++++++++++++++--
 4 files changed, 54 insertions(+), 26 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 29a5ab6c..f9e8431f 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -44,18 +44,15 @@ format_part_reply (GMimeStream *stream, mime_node_t *node)
 			      notmuch_message_get_header (node->envelope_file, "from"));
     } else if (GMIME_IS_MESSAGE (node->part)) {
 	GMimeMessage *message = GMIME_MESSAGE (node->part);
-	InternetAddressList *recipients;
 	char *recipients_string;
 
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-	recipients_string = internet_address_list_to_string (recipients, 0);
 	g_mime_stream_printf (stream, "> From: %s\n", g_mime_message_get_from_string (message));
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "> To: %s\n",
 				  recipients_string);
 	g_free (recipients_string);
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-	recipients_string = internet_address_list_to_string (recipients, 0);
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "> Cc: %s\n",
 				  recipients_string);
@@ -297,17 +294,17 @@ static InternetAddressList *get_sender(GMimeMessage *message)
 
 static InternetAddressList *get_to(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO);
 }
 
 static InternetAddressList *get_cc(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_CC);
 }
 
 static InternetAddressList *get_bcc(GMimeMessage *message)
 {
-    return g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC);
+    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_BCC);
 }
 
 /* Augment the recipients of 'reply' from the "Reply-to:", "From:",
@@ -338,10 +335,10 @@ add_recipients_from_message (GMimeMessage *reply,
 	InternetAddressList * (*get_header)(GMimeMessage *message);
 	GMimeRecipientType recipient_type;
     } reply_to_map[] = {
-	{ get_sender,	GMIME_RECIPIENT_TYPE_TO },
-	{ get_to,	GMIME_RECIPIENT_TYPE_TO },
-	{ get_cc,	GMIME_RECIPIENT_TYPE_CC },
-	{ get_bcc,	GMIME_RECIPIENT_TYPE_BCC },
+	{ get_sender,	GMIME_ADDRESS_TYPE_TO },
+	{ get_to,	GMIME_ADDRESS_TYPE_TO },
+	{ get_cc,	GMIME_ADDRESS_TYPE_CC },
+	{ get_bcc,	GMIME_ADDRESS_TYPE_BCC },
     };
     const char *from_addr = NULL;
     unsigned int i;
diff --git a/notmuch-show.c b/notmuch-show.c
index edc0537c..8afc5273 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -201,7 +201,6 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     /* Any changes to the JSON or S-Expression format should be
      * reflected in the file devel/schemata. */
 
-    InternetAddressList *recipients;
     char *recipients_string;
     const char *reply_to_string;
     void *local = talloc_new (sp);
@@ -214,24 +213,21 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     sp->map_key (sp, "From");
     sp->string (sp, g_mime_message_get_from_string (message));
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
     if (recipients_string) {
 	sp->map_key (sp, "To");
 	sp->string (sp, recipients_string);
 	g_free (recipients_string);
     }
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
     if (recipients_string) {
 	sp->map_key (sp, "Cc");
 	sp->string (sp, recipients_string);
 	g_free (recipients_string);
     }
 
-    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC);
-    recipients_string = internet_address_list_to_string (recipients, 0);
+    recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_BCC);
     if (recipients_string) {
 	sp->map_key (sp, "Bcc");
 	sp->string (sp, recipients_string);
@@ -512,7 +508,6 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 
     if (GMIME_IS_MESSAGE (node->part)) {
 	GMimeMessage *message = GMIME_MESSAGE (node->part);
-	InternetAddressList *recipients;
 	char *recipients_string;
 	char *date_string;
 
@@ -520,14 +515,12 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 	if (node->envelope_file)
 	    g_mime_stream_printf (stream, "%s\n", _get_one_line_summary (ctx, node->envelope_file));
 	g_mime_stream_printf (stream, "Subject: %s\n", g_mime_message_get_subject (message));
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
-	recipients_string = internet_address_list_to_string (recipients, 0);
 	g_mime_stream_printf (stream, "From: %s\n", g_mime_message_get_from_string (message));
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_TO);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "To: %s\n", recipients_string);
 	g_free (recipients_string);
-	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
-	recipients_string = internet_address_list_to_string (recipients, 0);
+	recipients_string = g_mime_message_get_address_string (message, GMIME_ADDRESS_TYPE_CC);
 	if (recipients_string)
 	    g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
 	g_free (recipients_string);
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
index 8590c55d..8f9e77a1 100644
--- a/util/gmime-extra.c
+++ b/util/gmime-extra.c
@@ -33,6 +33,19 @@ g_string_talloc_strdup (void *ctx, char *g_string)
 #if (GMIME_MAJOR_VERSION < 3)
 
 char *
+g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type)
+{
+    InternetAddressList *list = g_mime_message_get_recipients (message, type);
+    return internet_address_list_to_string (list, 0);
+}
+
+inline InternetAddressList *
+g_mime_message_get_addresses (GMimeMessage *message, GMimeRecipientType type)
+{
+    return g_mime_message_get_recipients (message, type);
+}
+
+char *
 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 {
     char *date = g_mime_message_get_date_as_string (message);
@@ -75,6 +88,13 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
 #else /* GMime >= 3.0 */
 
 char *
+g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
+{
+    InternetAddressList *list = g_mime_message_get_addresses (message, type);
+    return internet_address_list_to_string (list, NULL, 0);
+}
+
+char *
 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
 {
     GDateTime* parsed_date = g_mime_message_get_date (message);
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
index 04d63026..fef4f425 100644
--- a/util/gmime-extra.h
+++ b/util/gmime-extra.h
@@ -6,6 +6,26 @@ GMimeStream *g_mime_stream_stdout_new(void);
 
 #include <talloc.h>
 
+
+#if (GMIME_MAJOR_VERSION < 3)
+
+#define GMIME_ADDRESS_TYPE_TO GMIME_RECIPIENT_TYPE_TO
+#define GMIME_ADDRESS_TYPE_CC GMIME_RECIPIENT_TYPE_CC
+#define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
+
+
+#else /* GMime >= 3.0 */
+typedef GMimeAddressType GMimeRecipientType;
+#endif
+
+/**
+ * Return the contents of the appropriate address header as a string
+ * Should be freed using g_free
+ */
+char *g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type);
+
+InternetAddressList * g_mime_message_get_addresses (GMimeMessage *message, GMimeRecipientType type);
+
 /**
  * return talloc allocated date string
  */
@@ -30,6 +50,4 @@ InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
  * return talloc allocated reply-to string
  */
 char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
-
-
 #endif
-- 
2.11.0



More information about the notmuch mailing list