Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 02DE2429E30 for ; Sat, 28 May 2011 14:52:26 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.921 X-Spam-Level: X-Spam-Status: No, score=-1.921 tagged_above=-999 required=5 tests=[NO_DNS_FOR_FROM=0.379, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DfMa8mC1tdMt for ; Sat, 28 May 2011 14:52:24 -0700 (PDT) Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu [131.215.239.19]) by olra.theworths.org (Postfix) with ESMTP id AB802429E39 for ; Sat, 28 May 2011 14:52:15 -0700 (PDT) Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1]) by fire-doxen-postvirus (Postfix) with ESMTP id 26A04328121; Sat, 28 May 2011 14:45:48 -0700 (PDT) X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new Received: from servo.finestructure.net (cpe-98-149-172-122.socal.res.rr.com [98.149.172.122]) (Authenticated sender: jrollins) by fire-doxen-submit (Postfix) with ESMTP id 895AE2E50EB3; Sat, 28 May 2011 14:45:43 -0700 (PDT) Received: by servo.finestructure.net (Postfix, from userid 1000) id 320DB7AC; Sat, 28 May 2011 14:52:05 -0700 (PDT) From: Jameson Graef Rollins To: Notmuch Mail Subject: [PATCH 10/25] Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search Date: Sat, 28 May 2011 14:51:45 -0700 Message-Id: <1306619520-25730-11-git-send-email-jrollins@finestructure.net> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1306619520-25730-10-git-send-email-jrollins@finestructure.net> References: <1306619520-25730-1-git-send-email-jrollins@finestructure.net> <1306619520-25730-2-git-send-email-jrollins@finestructure.net> <1306619520-25730-3-git-send-email-jrollins@finestructure.net> <1306619520-25730-4-git-send-email-jrollins@finestructure.net> <1306619520-25730-5-git-send-email-jrollins@finestructure.net> <1306619520-25730-6-git-send-email-jrollins@finestructure.net> <1306619520-25730-7-git-send-email-jrollins@finestructure.net> <1306619520-25730-8-git-send-email-jrollins@finestructure.net> <1306619520-25730-9-git-send-email-jrollins@finestructure.net> <1306619520-25730-10-git-send-email-jrollins@finestructure.net> Cc: Andreas Amann X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2011 21:52:26 -0000 From: Andreas Amann 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 --- notmuch-search.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 69af617..530cecc 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.4.4