]> git.notmuchmail.org Git - notmuch/commitdiff
Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch...
authorAndreas Amann <a.amann@ucc.ie>
Sun, 8 May 2011 21:14:33 +0000 (23:14 +0200)
committerCarl Worth <cworth@cworth.org>
Thu, 2 Jun 2011 04:41:24 +0000 (21:41 -0700)
When a Subject field contained encoded CRLF sequences, these sequences
would appear unfiltered in the output of notmuch search. This confused
the notmuch emacs interface leading to "Unexpected Output"
messages. This is now fixed by replacing all characters with ASCII
code less than 32 with a question mark.

Signed-off-by: Jameson Graef Rollins <jrollins@finestructure.net>
notmuch-search.c

index 69af6171b3461f9528460676c308749dad0e1ca3..530cecc343b9f928517176a830d1662874609574 100644 (file)
@@ -111,6 +111,20 @@ format_item_id_text (unused (const void *ctx),
     printf ("%s%s", item_type, item_id);
 }
 
     printf ("%s%s", item_type, item_id);
 }
 
+static char *
+sanitize_string (const void *ctx, const char *str)
+{
+    char *out, *loop;
+
+    loop = out = talloc_strdup (ctx, str);
+
+    for (; *loop; loop++) {
+       if ((unsigned char)(*loop) < 32)
+           *loop = '?';
+    }
+    return out;
+}
+
 static void
 format_thread_text (const void *ctx,
                    const char *thread_id,
 static void
 format_thread_text (const void *ctx,
                    const char *thread_id,
@@ -120,13 +134,17 @@ format_thread_text (const void *ctx,
                    const char *authors,
                    const char *subject)
 {
                    const char *authors,
                    const char *subject)
 {
+    void *ctx_quote = talloc_new (ctx);
+
     printf ("thread:%s %12s [%d/%d] %s; %s",
            thread_id,
            notmuch_time_relative_date (ctx, date),
            matched,
            total,
     printf ("thread:%s %12s [%d/%d] %s; %s",
            thread_id,
            notmuch_time_relative_date (ctx, date),
            matched,
            total,
-           authors,
-           subject);
+           sanitize_string (ctx_quote, authors),
+           sanitize_string (ctx_quote, subject));
+
+    talloc_free (ctx_quote);
 }
 
 static void
 }
 
 static void