]> git.notmuchmail.org Git - notmuch/blob - notmuch-new.c
notmuch.el: Add a binding ('r') to reply to the current message.
[notmuch] / notmuch-new.c
1 /* notmuch - Not much of an email program, (just index and search)
2  *
3  * Copyright © 2009 Carl Worth
4  *
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.
9  *
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.
14  *
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/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #include "notmuch-client.h"
22
23 static void
24 tag_inbox_and_unread (notmuch_message_t *message)
25 {
26     notmuch_message_add_tag (message, "inbox");
27     notmuch_message_add_tag (message, "unread");
28 }
29
30 int
31 notmuch_new_command (unused (void *ctx),
32                      unused (int argc), unused (char *argv[]))
33 {
34     notmuch_database_t *notmuch;
35     const char *mail_directory;
36     add_files_state_t add_files_state;
37     double elapsed;
38     struct timeval tv_now;
39     int ret = 0;
40
41     notmuch = notmuch_database_open (NULL);
42     if (notmuch == NULL) {
43         ret = 1;
44         goto DONE;
45     }
46
47     mail_directory = notmuch_database_get_path (notmuch);
48
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);
56
57     ret = add_files (notmuch, mail_directory, &add_files_state);
58
59     gettimeofday (&tv_now, NULL);
60     elapsed = notmuch_time_elapsed (add_files_state.tv_start,
61                                     tv_now);
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);
67         if (elapsed > 1) {
68             printf (" (%d files/sec.).                 \n",
69                     (int) (add_files_state.processed_files / elapsed));
70         } else {
71             printf (".                    \n");
72         }
73     }
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");
79     } else {
80         printf ("No new mail---and that's not much.\n");
81     }
82
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");
88     }
89
90     if (ret) {
91         printf ("\nNote: At least one error was encountered: %s\n",
92                 notmuch_status_to_string (ret));
93     }
94
95   DONE:
96     if (notmuch)
97         notmuch_database_close (notmuch);
98
99     return ret;
100 }