unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Florian Friesdorf <flo@chaoflow.net>
To: notmuch@notmuchmail.org
Cc: Andreas Amann <a.amann@ucc.ie>
Subject: [PATCH] Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search
Date: Sun,  8 May 2011 23:14:33 +0200	[thread overview]
Message-ID: <1304889273-24560-2-git-send-email-flo@chaoflow.net> (raw)
In-Reply-To: <1304889273-24560-1-git-send-email-flo@chaoflow.net>

From: Andreas Amann <a.amann@ucc.ie>

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.
---
 notmuch-search.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 5e39511..e7fc41a 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -111,6 +111,20 @@ format_item_id_text (unused (const void *ctx),
     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,
@@ -120,13 +134,17 @@ format_thread_text (const void *ctx,
 		    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,
-	    authors,
-	    subject);
+	    sanitize_string(ctx_quote, authors),
+	    sanitize_string(ctx_quote, subject));
+
+    talloc_free (ctx_quote);
 }
 
 static void
-- 
1.7.5.1

  reply	other threads:[~2011-05-08 21:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-06 23:17 [PATCH] search --format=sanitized_text Florian Friesdorf
2011-05-06 23:17 ` [PATCH] implement search --format=sanitized_text + emacs UI to use it Florian Friesdorf
2011-05-06 23:55   ` Austin Clements
2011-05-07  0:15     ` Florian Friesdorf
2011-05-07  1:06     ` Jameson Graef Rollins
2011-05-07  9:14       ` Pieter Praet
2011-05-07  9:25         ` Pieter Praet
2011-05-08 21:14       ` [PATCH] sanitize notmuch-search output - rewrapped Florian Friesdorf
2011-05-08 21:14         ` Florian Friesdorf [this message]
2011-05-08 21:40           ` [PATCH] Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search Austin Clements
2011-05-08 21:54             ` Florian Friesdorf
2011-05-08 22:02               ` Austin Clements
2011-05-08 23:12                 ` [PATCH] sanitize notmuch-search output - rewrapped Florian Friesdorf
2011-05-08 23:16                   ` Florian Friesdorf
2011-05-08 23:13                 ` [PATCH 1/2] style fixes Florian Friesdorf
2011-05-08 23:13                   ` [PATCH 2/2] test for sanitized notmuch-search output Florian Friesdorf
2011-05-08 23:58           ` [PATCH] Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search Jameson Graef Rollins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304889273-24560-2-git-send-email-flo@chaoflow.net \
    --to=flo@chaoflow.net \
    --cc=a.amann@ucc.ie \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).