[PATCH 2b/2] configure: print info about required gmime 2.4 or 2.6 versions
[notmuch-archives.git] / f9 / 2007f9a5e0bcb0ebf57d9946f3566f406326b1
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 5A86F431FB6\r
6         for <notmuch@notmuchmail.org>; Mon, 31 Oct 2011 14:18:27 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id BJm5avjV6kbW for <notmuch@notmuchmail.org>;\r
17         Mon, 31 Oct 2011 14:18:26 -0700 (PDT)\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
19         [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 4E9A1429E29\r
22         for <notmuch@notmuchmail.org>; Mon, 31 Oct 2011 14:18:24 -0700 (PDT)\r
23 Received: by bkbzs8 with SMTP id zs8so4069839bkb.26\r
24         for <notmuch@notmuchmail.org>; Mon, 31 Oct 2011 14:18:21 -0700 (PDT)\r
25 Received: by 10.204.9.211 with SMTP id m19mr2654817bkm.92.1320095901236;\r
26         Mon, 31 Oct 2011 14:18:21 -0700 (PDT)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id k13sm16686618fah.0.2011.10.31.14.18.19\r
30         (version=SSLv3 cipher=OTHER); Mon, 31 Oct 2011 14:18:20 -0700 (PDT)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [RFC PATCH v2 2/3] cli: add options --first and --maxitems to notmuch\r
34         search\r
35 Date: Mon, 31 Oct 2011 23:18:09 +0200\r
36 Message-Id:\r
37  <e3440dc1ad040137074b1db5ff3882c987234b0e.1320093940.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1320093940.git.jani@nikula.org>\r
40 References: <cover.1320093940.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1320093940.git.jani@nikula.org>\r
42 References: <cover.1320093940.git.jani@nikula.org>\r
43 Cc: amdragon@mit.edu\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Mon, 31 Oct 2011 21:18:27 -0000\r
57 \r
58 Add options --first=[-]N and --maxitems=M to notmuch search to determine\r
59 the first result and maximum number of results to display.\r
60 \r
61 Option --maxitems=M limits the maximum number of results to display to M.\r
62 \r
63 Option --first=[-]N skips the first N results; with the leading '-' skip\r
64 until the Nth result from the end (showing a total of N results if within\r
65 bounds of the total number of results and not limited with --maxitems).\r
66 \r
67 Note that --first with a negative N for thread or summary output requires\r
68 counting the number of matching threads in advance, which is a heavy\r
69 operation.\r
70 \r
71 Signed-off-by: Jani Nikula <jani@nikula.org>\r
72 ---\r
73  notmuch-search.c |   67 ++++++++++++++++++++++++++++++++++++++++++++---------\r
74  1 files changed, 55 insertions(+), 12 deletions(-)\r
75 \r
76 diff --git a/notmuch-search.c b/notmuch-search.c\r
77 index 6f04d9a..ceef6ac 100644\r
78 --- a/notmuch-search.c\r
79 +++ b/notmuch-search.c\r
80 @@ -194,13 +194,20 @@ static int\r
81  do_search_threads (const search_format_t *format,\r
82                    notmuch_query_t *query,\r
83                    notmuch_sort_t sort,\r
84 -                  output_t output)\r
85 +                  output_t output,\r
86 +                  int first,\r
87 +                  unsigned int maxitems)\r
88  {\r
89      notmuch_thread_t *thread;\r
90      notmuch_threads_t *threads;\r
91      notmuch_tags_t *tags;\r
92      time_t date;\r
93      int first_thread = 1;\r
94 +    unsigned int i, start;\r
95 +\r
96 +    if (first < 0)\r
97 +       first += notmuch_query_count_threads (query);\r
98 +    start = first < 0 ? 0 : first;\r
99  \r
100      threads = notmuch_query_search_threads (query);\r
101      if (threads == NULL)\r
102 @@ -208,17 +215,23 @@ do_search_threads (const search_format_t *format,\r
103  \r
104      fputs (format->results_start, stdout);\r
105  \r
106 -    for (;\r
107 -        notmuch_threads_valid (threads);\r
108 -        notmuch_threads_move_to_next (threads))\r
109 +    for (i = 0;\r
110 +        notmuch_threads_valid (threads) &&\r
111 +            (!maxitems || i < start + maxitems);\r
112 +        notmuch_threads_move_to_next (threads), i++)\r
113      {\r
114         int first_tag = 1;\r
115  \r
116 +       thread = notmuch_threads_get (threads);\r
117 +\r
118 +       if (i < start) {\r
119 +           notmuch_thread_destroy (thread);\r
120 +           continue;\r
121 +       }\r
122 +\r
123         if (! first_thread)\r
124             fputs (format->item_sep, stdout);\r
125  \r
126 -       thread = notmuch_threads_get (threads);\r
127 -\r
128         if (output == OUTPUT_THREADS) {\r
129             format->item_id (thread, "thread:",\r
130                              notmuch_thread_get_thread_id (thread));\r
131 @@ -271,12 +284,20 @@ do_search_threads (const search_format_t *format,\r
132  static int\r
133  do_search_messages (const search_format_t *format,\r
134                     notmuch_query_t *query,\r
135 -                   output_t output)\r
136 +                   output_t output,\r
137 +                   int first,\r
138 +                   unsigned int maxitems)\r
139  {\r
140      notmuch_message_t *message;\r
141      notmuch_messages_t *messages;\r
142      notmuch_filenames_t *filenames;\r
143      int first_message = 1;\r
144 +    unsigned int i, start;\r
145 +\r
146 +    if (first < 0)\r
147 +       first += notmuch_query_count_messages(query);\r
148 +\r
149 +    start = first < 0 ? 0 : first;\r
150  \r
151      messages = notmuch_query_search_messages (query);\r
152      if (messages == NULL)\r
153 @@ -284,10 +305,14 @@ do_search_messages (const search_format_t *format,\r
154  \r
155      fputs (format->results_start, stdout);\r
156  \r
157 -    for (;\r
158 -        notmuch_messages_valid (messages);\r
159 -        notmuch_messages_move_to_next (messages))\r
160 +    for (i = 0;\r
161 +        notmuch_messages_valid (messages) &&\r
162 +            (!maxitems || i < start + maxitems);\r
163 +        notmuch_messages_move_to_next (messages), i++)\r
164      {\r
165 +       if (i < start)\r
166 +           continue;\r
167 +\r
168         message = notmuch_messages_get (messages);\r
169  \r
170         if (output == OUTPUT_FILES) {\r
171 @@ -394,6 +419,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
172      const search_format_t *format = &format_text;\r
173      int i, ret;\r
174      output_t output = OUTPUT_SUMMARY;\r
175 +    unsigned int maxitems = 0;\r
176 +    int first = 0;\r
177  \r
178      argc--; argv++; /* skip subcommand argument */\r
179  \r
180 @@ -412,6 +439,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
181                 fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
182                 return 1;\r
183             }\r
184 +       } else if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {\r
185 +           char *p;\r
186 +           opt = argv[i] + sizeof ("--first=") - 1;\r
187 +           first = strtol(opt, &p, 10);\r
188 +           if (*opt == '\0' || p == opt || *p != '\0') {\r
189 +               fprintf (stderr, "Invalid value for --first: %s\n", opt);\r
190 +               return 1;\r
191 +           }\r
192 +       } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {\r
193 +           char *p;\r
194 +           opt = argv[i] + sizeof ("--maxitems=") - 1;\r
195 +           maxitems = strtoul(opt, &p, 10);\r
196 +           if (*opt == '\0' || p == opt || *p != '\0') {\r
197 +               fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);\r
198 +               return 1;\r
199 +           }\r
200         } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
201             opt = argv[i] + sizeof ("--format=") - 1;\r
202             if (strcmp (opt, "text") == 0) {\r
203 @@ -478,11 +521,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
204      default:\r
205      case OUTPUT_SUMMARY:\r
206      case OUTPUT_THREADS:\r
207 -       ret = do_search_threads (format, query, sort, output);\r
208 +       ret = do_search_threads (format, query, sort, output, first, maxitems);\r
209         break;\r
210      case OUTPUT_MESSAGES:\r
211      case OUTPUT_FILES:\r
212 -       ret = do_search_messages (format, query, output);\r
213 +       ret = do_search_messages (format, query, output, first, maxitems);\r
214         break;\r
215      case OUTPUT_TAGS:\r
216         ret = do_search_tags (notmuch, format, query);\r
217 -- \r
218 1.7.5.4\r
219 \r