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 334E9431FBC for ; Wed, 13 Jan 2010 04:44:04 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.087 X-Spam-Level: X-Spam-Status: No, score=-1.087 tagged_above=-999 required=5 tests=[AWL=1.511, BAYES_00=-2.599, UNPARSEABLE_RELAY=0.001] autolearn=ham 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 anE1GmzE2gCh for ; Wed, 13 Jan 2010 04:44:02 -0800 (PST) Received: from n22a.bullet.mail.mud.yahoo.com (n22a.bullet.mail.mud.yahoo.com [68.142.207.188]) by olra.theworths.org (Postfix) with SMTP id B2079431FAE for ; Wed, 13 Jan 2010 04:44:02 -0800 (PST) Received: from [68.142.200.226] by n22.bullet.mail.mud.yahoo.com with NNFMP; 13 Jan 2010 12:44:01 -0000 Received: from [68.142.201.68] by t7.bullet.mud.yahoo.com with NNFMP; 13 Jan 2010 12:44:01 -0000 Received: from [127.0.0.1] by omp420.mail.mud.yahoo.com with NNFMP; 13 Jan 2010 12:44:01 -0000 X-Yahoo-Newman-Id: 918721.23716.bm@omp420.mail.mud.yahoo.com Received: (qmail 32816 invoked from network); 13 Jan 2010 12:44:01 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.br; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; b=L4ecY78JyH8EnrFnww3cwqKLK2x1Giuhwfa+ubjw1+bbKc+TMvzYhR5cclyQU4/2IStsVUwF9Suqgfmw2OBP6Xn8zVmDlbdnGRuFcJho0TeYmBZfcAMazwj/+E+HSvtElnEaxsUNWhw5ApEN2Zt5u5HOBNlfqVR8kr8QDIfUmyE= ; Received: from 201.86.186.97.dynamic.adsl.gvt.net.br (fcarrijo@201.86.186.97 with login) by smtp133.mail.mud.yahoo.com with SMTP; 13 Jan 2010 04:44:01 -0800 PST X-Yahoo-SMTP: NgkT36eswBAymTD26_IxCjMQ0A5a X-YMail-OSG: 0GbjW3UVM1lVpikYnUhIOuKh47iVb6SZHuKJQxRFLfFprwq59pJJKECJk3dWNuoiPUriHgbjyIcBk3mdoPwk24n4bSvc1_JRUFbozTJqNLhufW0pzFiCjIiY8JpheQRtbvQC0d1eLVWjYCdWSKD11IvoDZeC3YXax8rynupc5IBvDzVrfjuRiIHEH2rh5EaQSKw.89DtLZNnhUqQCwAlFlLdqLCPahuzhi2oYrKT.bce7AN9HFjYErR2b5bPWBEdKK41AcySIFsYdp5RXUDryu9SBU3VJW.XFrDoPoRZBeFzxA2lZTBvwe1KHmZmHRQFpWvEpL5tNKqIH.EQk9TT8ZXQslduEJjMLxqE2YTfxaBf6SAgGA-- X-Yahoo-Newman-Property: ymail-3 From: Fernando Carrijo To: Ali Polatel , notmuch@notmuchmail.org In-Reply-To: References: Date: Wed, 13 Jan 2010 10:44:09 -0200 Message-ID: <874omq6up2.fsf@yahoo.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [notmuch] [RFC/PATCH] Add search-files command 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: Wed, 13 Jan 2010 12:44:04 -0000 Hi Ali, On Wed, 13 Jan 2010 12:24:22 +0200, Ali Polatel wrote: > This command can be used to integrate notmuch with other MUAs as a > searching client. The idea is simple, a simple script could get > search-terms as argument and create a "virtual" maildir which has > symbolic links to files output by search-files command. This is similar > to nmzmail. > --- > Makefile.local | 1 + > notmuch-client.h | 3 + > notmuch-search-files.c | 107 ++++++++++++++++++++++++++++++++++++++++++= ++++++ > notmuch.c | 13 ++++++ > 4 files changed, 124 insertions(+), 0 deletions(-) > create mode 100644 notmuch-search-files.c >=20 > diff --git a/Makefile.local b/Makefile.local > index 933ff4c..78bc25d 100644 > --- a/Makefile.local > +++ b/Makefile.local > @@ -12,6 +12,7 @@ notmuch_client_srcs =3D \ > notmuch-reply.c \ > notmuch-restore.c \ > notmuch-search.c \ > + notmuch-search-files.c \ > notmuch-search-tags.c \ > notmuch-setup.c \ > notmuch-show.c \ > diff --git a/notmuch-client.h b/notmuch-client.h > index 77766de..d505d30 100644 > --- a/notmuch-client.h > +++ b/notmuch-client.h > @@ -96,6 +96,9 @@ int > notmuch_search_command (void *ctx, int argc, char *argv[]); >=20=20 > int > +notmuch_search_files_command (void *ctx, int argc, char *argv[]); > + > +int > notmuch_setup_command (void *ctx, int argc, char *argv[]); >=20=20 > int > diff --git a/notmuch-search-files.c b/notmuch-search-files.c > new file mode 100644 > index 0000000..b48783a > --- /dev/null > +++ b/notmuch-search-files.c > @@ -0,0 +1,107 @@ > +/* notmuch - Not much of an email program, (just index and search) > + * > + * Copyright =C2=A9 2009 Carl Worth I almost certainly should not be speaking in the name of Carl, but a few weeks ago he replied with the following words to a message which somehow raised the discussion of copyright holding in notmuch source code: "Please feel free to retain your own copyright. I certainly don't deserve anything being assigned to me." The message-id of his reply is: 873a34tf8b.fsf@yoom.home.cworth.org, just in the case you want to check the context in which it occurred. > + * > + * This program is free software: you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation, either version 3 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program. If not, see http://www.gnu.org/licenses/ . > + * > + * Author: Ali Polatel > + */ > + > +#include "notmuch-client.h" > + > +static void > +do_search_files (notmuch_query_t *query) > +{ > + notmuch_message_t *message; > + notmuch_messages_t *messages; > + > + for (messages =3D notmuch_query_search_messages (query); > + notmuch_messages_has_more (messages); > + notmuch_messages_advance (messages)) > + { > + message =3D notmuch_messages_get (messages); > + printf ("%s\n", notmuch_message_get_filename (message)); > + notmuch_message_destroy(message); > + } > +} > + > +int > +notmuch_search_files_command (void *ctx, int argc, char *argv[]) > +{ > + notmuch_config_t *config; > + notmuch_database_t *notmuch; > + notmuch_query_t *query; > + char *query_str; > + char *opt; > + notmuch_sort_t sort =3D NOTMUCH_SORT_NEWEST_FIRST; > + int i; > + > + for (i =3D 0; i < argc && argv[i][0] =3D=3D '-'; i++) { > + if (strcmp (argv[i], "--") =3D=3D 0) { > + i++; > + break; > + } > + if (STRNCMP_LITERAL (argv[i], "--sort=3D") =3D=3D 0) { > + opt =3D argv[i] + sizeof ("--sort=3D") - 1; > + if (strcmp (opt, "oldest-first") =3D=3D 0) { > + sort =3D NOTMUCH_SORT_OLDEST_FIRST; > + } else if (strcmp (opt, "newest-first") =3D=3D 0) { > + sort =3D NOTMUCH_SORT_NEWEST_FIRST; > + } else { > + fprintf (stderr, "Invalid value for --sort: %s\n", opt); > + return 1; > + } > + } else { > + fprintf (stderr, "Unrecognized option: %s\n", argv[i]); > + return 1; > + } > + } > + > + argc -=3D i; > + argv +=3D i; > + > + config =3D notmuch_config_open (ctx, NULL, NULL); > + if (config =3D=3D NULL) > + return 1; > + > + notmuch =3D notmuch_database_open (notmuch_config_get_database_path = (config), > + NOTMUCH_DATABASE_MODE_READ_ONLY); > + if (notmuch =3D=3D NULL) > + return 1; > + > + query_str =3D query_string_from_args (ctx, argc, argv); > + if (query_str =3D=3D NULL) { > + fprintf (stderr, "Out of memory.\n"); > + return 1; > + } > + if (*query_str =3D=3D '\0') { > + fprintf (stderr, "Error: notmuch search-files requires at least one sea= rch term.\n"); Could we break this line so that it did not go beyond the column limit set by the coding conventions? Maybe we should go one step further and import the file CODING_STYLE from cairo into notmuch's repository. > + return 1; > + } > + > + query =3D notmuch_query_create (notmuch, query_str); > + if (query =3D=3D NULL) { > + fprintf (stderr, "Out of memory\n"); > + return 1; > + } > + > + notmuch_query_set_sort (query, sort); > + > + do_search_files (query); > + > + notmuch_query_destroy (query); > + notmuch_database_close (notmuch); It is not something of major importance, but I realized that the function notmuch_config_close is only being called when notmuch is executed with no arguments. As we know, the kernel shall close all open file descriptors upon program termination, but wouldn't it be better if we did it explicitly? Or did I overlook something? Kind regards, Fernando Carrijo. > + > + return 0; > +} > diff --git a/notmuch.c b/notmuch.c > index 87479f8..4907339 100644 > --- a/notmuch.c > +++ b/notmuch.c > @@ -165,6 +165,19 @@ command_t commands[] =3D { > "\n" > "\t\tSee \"notmuch help search-terms\" for details of the search\n" > "\t\tterms syntax." }, > + { "search-files", notmuch_search_files_command, > + "[options...] [...]", > + "\t\tSearch for filenames matching the given search terms.", > + "\t\tSupported options for search-files include:\n" > + "\n" > + "\t\t--sort=3D(newest-first|oldest-first)\n" > + "\n" > + "\t\t\tPresent results in either chronological order\n" > + "\t\t\t(oldest-first) or reverse chronological order\n" > + "\t\t\t(newest-first), which is the default.\n" > + "\n" > + "\t\tSee \"notmuch help search-terms\" for details of the search\n" > + "\t\tterms syntax." }, > { "show", notmuch_show_command, > " [...]", > "\t\tShow all messages matching the search terms.", > --=20 > 1.6.6 >=20 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch