]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
lib/messages: Add new notmuch_message_list_t to internal interface.
[notmuch] / notmuch.c
index 339144ddd3a8a9361e5b972fa6727700f4aba217..c47e64036786afbb19a834c49cc6aedffec7a5f2 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -1,6 +1,7 @@
 /* notmuch - Not much of an email program, (just index and search)
  *
  * Copyright © 2009 Carl Worth
+ * Copyright © 2009 Keith Packard
  *
  * 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
@@ -15,7 +16,8 @@
  * 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: Carl Worth <cworth@cworth.org>
+ * Authors: Carl Worth <cworth@cworth.org>
+ *         Keith Packard <keithp@keithp.com>
  */
 
 #include "notmuch-client.h"
@@ -82,6 +84,19 @@ command_t commands[] = {
       "\t\tthe Boolean operators, but will have to be protected from\n"
       "\t\tinterpretation by the shell, (such as by putting quotation\n"
       "\t\tmarks around any parenthesized expression)." },
+    { "reply", notmuch_reply_command,
+      "<search-terms> [...]\n\n"
+      "\t\tFormats a reply from a set of existing messages.",
+      "\t\tConstructs a new message as a reply to a set of existing\n"
+      "\t\tmessages. The From: address is used as a To: address\n"
+      "\t\talong with all old To: addresses. All of the Cc: addresses\n"
+      "\t\tare copied as new Cc: addresses. An In-Reply-To: header\n"
+      "\t\twill be constructed from the name and date of the original\n"
+      "\t\tmessage, and the original Message-ID will be added to the\n"
+      "\t\tlist of References in the new message. The text of each\n"
+      "\t\tmessage (as described in the \"show\" command) will be\n"
+      "\t\tpresented, each line prefixed with \"> \" The resulting\n"
+      "\t\tmessage will be dumped to stdout." },
     { "show", notmuch_show_command,
       "<search-terms> [...]\n\n"
       "\t\tShows all messages matching the search terms.",
@@ -189,16 +204,84 @@ notmuch_help_command (unused (void *ctx), int argc, char *argv[])
             argv[0]);
     return 1;
 }
-    
+
+/* Handle the case of "notmuch" being invoked with no command
+ * argument. For now we just call notmuch_setup_command, but we plan
+ * to be more clever about this in the future.
+ */
+static int
+notmuch (void *ctx)
+{
+    notmuch_config_t *config;
+    notmuch_bool_t is_new;
+    char *db_path;
+    struct stat st;
+
+    config = notmuch_config_open (ctx, NULL, &is_new);
+
+    /* If the user has never configured notmuch, then run
+     * notmuch_setup_command which will give a nice welcome message,
+     * and interactively guide the user through the configuration. */
+    if (is_new) {
+       notmuch_config_close (config);
+       return notmuch_setup_command (ctx, 0, NULL);
+    }
+
+    /* Notmuch is already configured, but is there a database? */
+    db_path = talloc_asprintf (ctx, "%s/%s",
+                              notmuch_config_get_database_path (config),
+                              ".notmuch");
+    if (stat (db_path, &st)) {
+       notmuch_config_close (config);
+       if (errno != ENOENT) {
+           fprintf (stderr, "Error looking for notmuch database at %s: %s\n",
+                    db_path, strerror (errno));
+           return 1;
+       }
+       printf ("Notmuch is configured, but there's not yet a database at\n\n\t%s\n\n",
+               db_path);
+       printf ("You probably want to run \"notmuch new\" now to create that database.\n\n"
+               "Note that the first run of \"notmuch new\" can take a very long time\n"
+               "and that the resulting database will use roughly the same amount of\n"
+               "storage space as the email being indexed.\n\n");
+       return 0;
+    }
+
+    printf ("Notmuch is configured and appears to have a database. Excellent!\n\n"
+           "At this point you can start exploring the functionality of notmuch by\n"
+           "using commands such as:\n\n"
+           "\tnotmuch search tag:inbox\n\n"
+           "\tnotmuch search to:\"%s\"\n\n"
+           "\tnotmuch search from:\"%s\"\n\n"
+           "\tnotmuch search subject:\"my favorite things\"\n\n"
+           "See \"notmuch help search\" for more details.\n\n"
+           "You can also use \"notmuch show\" with any of the thread IDs resulting\n"
+           "from a search. Finally, you may want to explore using a more sophisticated\n"
+           "interface to notmuch such as the emacs interface implemented in notmuch.el\n"
+           "or any other interface described at http://notmuchmail.org\n\n"
+           "And don't forget to run \"notmuch new\" whenever new mail arrives.\n\n"
+           "Have fun, and may your inbox never have much mail.\n\n",
+           notmuch_config_get_user_name (config),
+           notmuch_config_get_user_primary_email (config));
+
+    notmuch_config_close (config);
+
+    return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
-    void *local = talloc_new (NULL);
+    void *local;
     command_t *command;
     unsigned int i;
 
+    local = talloc_new (NULL);
+
+    g_mime_init (0);
+
     if (argc == 1)
-       return notmuch_setup_command (local, 0, NULL);
+       return notmuch (local);
 
     for (i = 0; i < ARRAY_SIZE (commands); i++) {
        command = &commands[i];