]> rtime.felk.cvut.cz Git - notmuch.git/blobdiff - notmuch-search.c
fixup Quote printed addresses
[notmuch.git] / notmuch-search.c
index 7ca8125a31c6016c5d22bc706ecf0894270c1cc0..0bcf8c84c7ad5106bf96203536273a86d50fd380 100644 (file)
@@ -304,17 +304,14 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
     sprinter_t *format = opt->format;
 
     if (format->is_text_printer) {
-       char *mailbox_str;
+       InternetAddress * ia = internet_address_mailbox_new (name, addr);
+       /* mailbox_str has the name part quoted if necessary. Compare
+        * 'John Doe <john@doe.com>' vs. '"Doe, John" <john@doe.com>' */
+       char *mailbox_str = internet_address_to_string (ia, FALSE);
 
-       if (name && *name)
-           mailbox_str = talloc_asprintf (format, "%s <%s>", name, addr);
-       else
-           mailbox_str = talloc_strdup (format, addr);
+       if (! mailbox_str)
+           INTERNAL_ERROR("Out of memory");
 
-       if (! mailbox_str) {
-           fprintf (stderr, "Error: out of memory\n");
-           return;
-       }
        if (count > 0) {
            format->integer (format, count);
            format->string (format, "\t");
@@ -322,7 +319,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
        format->string (format, mailbox_str);
        format->separator (format);
 
-       talloc_free (mailbox_str);
+       g_free (mailbox_str);
     } else {
        format->begin_map (format);
        format->map_key (format, "name");