1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-client.h"
24 tag_inbox_and_unread (notmuch_message_t *message)
26 notmuch_message_add_tag (message, "inbox");
27 notmuch_message_add_tag (message, "unread");
31 notmuch_new_command (unused (void *ctx),
32 unused (int argc), unused (char *argv[]))
34 notmuch_database_t *notmuch;
35 const char *mail_directory;
36 add_files_state_t add_files_state;
38 struct timeval tv_now;
41 notmuch = notmuch_database_open (NULL);
42 if (notmuch == NULL) {
47 mail_directory = notmuch_database_get_path (notmuch);
49 add_files_state.ignore_read_only_directories = TRUE;
50 add_files_state.saw_read_only_directory = FALSE;
51 add_files_state.total_files = 0;
52 add_files_state.processed_files = 0;
53 add_files_state.added_messages = 0;
54 add_files_state.callback = tag_inbox_and_unread;
55 gettimeofday (&add_files_state.tv_start, NULL);
57 ret = add_files (notmuch, mail_directory, &add_files_state);
59 gettimeofday (&tv_now, NULL);
60 elapsed = notmuch_time_elapsed (add_files_state.tv_start,
62 if (add_files_state.processed_files) {
63 printf ("Processed %d %s in ", add_files_state.processed_files,
64 add_files_state.processed_files == 1 ?
65 "file" : "total files");
66 notmuch_time_print_formatted_seconds (elapsed);
68 printf (" (%d files/sec.). \n",
69 (int) (add_files_state.processed_files / elapsed));
74 if (add_files_state.added_messages) {
75 printf ("Added %d new %s to the database (not much, really).\n",
76 add_files_state.added_messages,
77 add_files_state.added_messages == 1 ?
78 "message" : "messages");
80 printf ("No new mail---and that's not much.\n");
83 if (elapsed > 1 && ! add_files_state.saw_read_only_directory) {
84 printf ("\nTip: If you have any sub-directories that are archives (that is,\n"
85 "they will never receive new mail), marking these directores as\n"
86 "read-only (chmod u-w /path/to/dir) will make \"notmuch new\"\n"
87 "much more efficient (it won't even look in those directories).\n");
91 printf ("\nNote: At least one error was encountered: %s\n",
92 notmuch_status_to_string (ret));
97 notmuch_database_close (notmuch);