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 84435429E21 for ; Fri, 6 May 2011 16:55:28 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 sSKkeQYq+PfT for ; Fri, 6 May 2011 16:55:27 -0700 (PDT) Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 6F515431FB5 for ; Fri, 6 May 2011 16:55:27 -0700 (PDT) Received: by qyk7 with SMTP id 7so23655qyk.5 for ; Fri, 06 May 2011 16:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=2je4+iH5PdpwKGYxTZeQ+1y5fHqfavG7+7g9XegRa2M=; b=sYQM4vj76VaTTShyLOKW1EDWWADQglzplxRppKBDdfOSA9ZqDPeiuWs17fJoITheOA BQrp8aDOEqCIsVyE335Z5ItkGihWgj0jFidS/hufDG9V8dIBH+WyQwYJLZR2z6gOl3nk ePy5HoijvxdpkLIFrR9CFKuQ6nKL5wE8srfFc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=LusDxLebVib1+/MngA517OY44ByfTmFycuT5olTnIsu7p7+wR7wrLiEkoEj7Dx8ErY OI20VUJYQ0lpzJHPExs+8LC/oMW3zQl8oJsaQzPBwHHUGkTQiR082xfyEoYqeaODfTQv AJQV8qns1OWk81JHLIoMVHKur8GW9omVOV5bw= MIME-Version: 1.0 Received: by 10.229.101.36 with SMTP id a36mr3014761qco.74.1304726126591; Fri, 06 May 2011 16:55:26 -0700 (PDT) Sender: amdragon@gmail.com Received: by 10.229.233.17 with HTTP; Fri, 6 May 2011 16:55:26 -0700 (PDT) In-Reply-To: <1304723846-29134-2-git-send-email-flo@chaoflow.net> References: <1304723846-29134-1-git-send-email-flo@chaoflow.net> <1304723846-29134-2-git-send-email-flo@chaoflow.net> Date: Fri, 6 May 2011 19:55:26 -0400 X-Google-Sender-Auth: yVZg5jVvvyZshUIe7a8_vyhw3Ps Message-ID: Subject: Re: [PATCH] implement search --format=sanitized_text + emacs UI to use it From: Austin Clements To: Florian Friesdorf Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: notmuch@notmuchmail.org, a.amann@ucc.ie 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: Fri, 06 May 2011 23:55:28 -0000 Perhaps text summary output should *always* do this. The text summary format is meant half for user consumption and half for emacs consumption and allowing newlines that don't indicate the end of a summary line seems bad for *both* use cases. On Fri, May 6, 2011 at 7:17 PM, Florian Friesdorf wrote: > Sanitize "Subject:" and "Author:" fields to not contain control > characters for sanitized_text format. > > When a Subject field contains 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 for the sanitized_text > format. The emacs UI uses this format. > > Thank you to Andreas Amann , who wrote the initial > patch, I just turned it into a new format. > > missing: > - man page update > - test, (works for me) > - investigate initialization warning: > CC -O2 notmuch-search.o > notmuch-search.c:98:1: warning: missing initializer > notmuch-search.c:98:1: warning: (near initialization for > 'format_sanitized_text.results_null') > --- > =A0emacs/notmuch.el | =A0 =A03 +- > =A0notmuch-search.c | =A0 58 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++++ > =A02 files changed, 60 insertions(+), 1 deletions(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index 1d683f8..9d7c212 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -879,7 +879,8 @@ The optional parameters are used as follows: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if oldest-first > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "--sort=3Doldest-first" > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "--sort=3Dnewest-first") > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0query))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "--format=3Dsanitized_text" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 query))) > =A0 =A0 =A0 =A0 =A0(set-process-sentinel proc 'notmuch-search-process-sen= tinel) > =A0 =A0 =A0 =A0 =A0(set-process-filter proc 'notmuch-search-process-filte= r)))) > =A0 =A0 (run-hooks 'notmuch-search-hook))) > diff --git a/notmuch-search.c b/notmuch-search.c > index 5e39511..d59dc44 100644 > --- a/notmuch-search.c > +++ b/notmuch-search.c > @@ -78,6 +78,26 @@ static const search_format_t format_text =3D { > =A0}; > > =A0static void > +format_thread_sanitized_text (const void *ctx, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *thr= ead_id, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const time_t da= te, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int match= ed, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int total= , > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *aut= hors, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *sub= ject); > +static const search_format_t format_sanitized_text =3D { > + =A0 =A0"", > + =A0 =A0 =A0 "", > + =A0 =A0 =A0 =A0 =A0 format_item_id_text, > + =A0 =A0 =A0 =A0 =A0 format_thread_sanitized_text, > + =A0 =A0 =A0 =A0 =A0 " (", > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 "%s", " ", > + =A0 =A0 =A0 =A0 =A0 ")", "\n", > + =A0 =A0 =A0 "", > + =A0 =A0"", > +}; > + > +static void > =A0format_item_id_json (const void *ctx, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *item_type, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *item_id); > @@ -129,6 +149,42 @@ format_thread_text (const void *ctx, > =A0 =A0 =A0 =A0 =A0 =A0subject); > =A0} > > +static char * > +sanitize_string(const void *ctx, const char *str) > +{ > + =A0 =A0char *out, *loop; > + > + =A0 =A0loop =3D out =3D talloc_strdup (ctx, str); > + > + =A0 =A0for(;*loop;loop++){ > + =A0 =A0 =A0 if ((unsigned char)(*loop) < 32) > + =A0 =A0 =A0 =A0 =A0 *loop =3D '?'; > + =A0 =A0} > + =A0 =A0return out; > +} > + > +static void > +format_thread_sanitized_text (const void *ctx, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *thr= ead_id, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const time_t da= te, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int match= ed, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int total= , > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *aut= hors, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *sub= ject) > +{ > + =A0 =A0void *ctx_quote =3D talloc_new (ctx); > + > + =A0 =A0printf ("thread:%s %12s [%d/%d] %s; %s", > + =A0 =A0 =A0 =A0 =A0 thread_id, > + =A0 =A0 =A0 =A0 =A0 notmuch_time_relative_date (ctx, date), > + =A0 =A0 =A0 =A0 =A0 matched, > + =A0 =A0 =A0 =A0 =A0 total, > + =A0 =A0 =A0 =A0 =A0 sanitize_string(ctx_quote, authors), > + =A0 =A0 =A0 =A0 =A0 sanitize_string(ctx_quote, subject)); > + > + =A0 =A0talloc_free (ctx_quote); > +} > + > =A0static void > =A0format_item_id_json (const void *ctx, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unused (const char *item_type), > @@ -378,6 +434,8 @@ notmuch_search_command (void *ctx, int argc, char *ar= gv[]) > =A0 =A0 =A0 =A0 =A0 =A0opt =3D argv[i] + sizeof ("--format=3D") - 1; > =A0 =A0 =A0 =A0 =A0 =A0if (strcmp (opt, "text") =3D=3D 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0format =3D &format_text; > + =A0 =A0 =A0 =A0 =A0 } else if (strcmp (opt, "sanitized_text") =3D=3D 0)= { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 format =3D &format_sanitized_text; > =A0 =A0 =A0 =A0 =A0 =A0} else if (strcmp (opt, "json") =3D=3D 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0format =3D &format_json; > =A0 =A0 =A0 =A0 =A0 =A0} else { > -- > 1.7.5.1 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch >