cli: replace use of g_mime_message_get_recipients
authorDavid Bremner <david@tethera.net>
Sat, 6 May 2017 11:41:14 +0000 (08:41 -0300)
committerDavid Bremner <david@tethera.net>
Fri, 14 Jul 2017 20:58:09 +0000 (17:58 -0300)
This function, and associated enum, have been renamed and generalized
in gmime-3.0.

notmuch-reply.c
notmuch-show.c
util/gmime-extra.c
util/gmime-extra.h

index ceb1d231e6c85a7b6d23dedc81a5d8ad861c2e0e..4c1dd56024698041f1c97bca50347ffca8cace2e 100644 (file)
@@ -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;
index 1a72d12f68cab3980b4273d8de8b917b39c9dbc4..1f359a917a2fcb4196912fe45102c3326fa18da2 100644 (file)
@@ -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);
index 8590c55d184b747799f7a30b545963e748f5de10..8f9e77a1bb2a930bc3fd5271ff4791f72309bd59 100644 (file)
@@ -32,6 +32,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)
 {
@@ -74,6 +87,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)
 {
index 04d630260259094ee5e7e527a24b4417d3c86275..fef4f4252ed11a7a40445946edeffc81fdf931f0 100644 (file)
@@ -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