]> git.notmuchmail.org Git - notmuch/blobdiff - database.cc
notmuch setup/new: Print progress once per second instead of after 1000 files.
[notmuch] / database.cc
index 71246eb456115ade91ee9b47b89629850ab32e11..d7cd26c7656d2fd6fb85464d8c1c582d96ee11af 100644 (file)
@@ -106,6 +106,7 @@ prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
     { "type", "T" },
     { "ref", "XREFERENCE" },
     { "timestamp", "XTIMESTAMP" },
+    { "contact", "XCONTACT" }
 };
 
 prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
@@ -114,6 +115,13 @@ prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
     { "id", "Q" }
 };
 
+prefix_t PROBABILISTIC_PREFIX[]= {
+    { "from", "XFROM" },
+    { "to", "XTO" },
+    { "attachment", "XATTACHMENT" },
+    { "subject", "XSUBJECT"}
+};
+
 int
 _internal_error (const char *format, ...)
 {
@@ -121,6 +129,7 @@ _internal_error (const char *format, ...)
 
     va_start (va_args, format);
 
+    fprintf (stderr, "Internal error: ");
     vfprintf (stderr, format, va_args);
 
     exit (1);
@@ -141,6 +150,10 @@ _find_prefix (const char *name)
        if (strcmp (name, BOOLEAN_PREFIX_EXTERNAL[i].name) == 0)
            return BOOLEAN_PREFIX_EXTERNAL[i].prefix;
 
+    for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++)
+       if (strcmp (name, PROBABILISTIC_PREFIX[i].name) == 0)
+           return PROBABILISTIC_PREFIX[i].prefix;
+
     INTERNAL_ERROR ("No prefix exists for '%s'\n", name);
 
     return "";
@@ -478,14 +491,24 @@ notmuch_database_open (const char *path)
        notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
                                                           Xapian::DB_CREATE_OR_OPEN);
        notmuch->query_parser = new Xapian::QueryParser;
+       notmuch->term_gen = new Xapian::TermGenerator;
+       notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
+
        notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
        notmuch->query_parser->set_database (*notmuch->xapian_db);
+       notmuch->query_parser->set_stemmer (Xapian::Stem ("english"));
+       notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);
 
        for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {
            prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];
            notmuch->query_parser->add_boolean_prefix (prefix->name,
                                                       prefix->prefix);
        }
+
+       for (i = 0; i < ARRAY_SIZE (PROBABILISTIC_PREFIX); i++) {
+           prefix_t *prefix = &PROBABILISTIC_PREFIX[i];
+           notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);
+       }
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred: %s\n",
                 error.get_msg().c_str());
@@ -508,6 +531,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
 {
     notmuch->xapian_db->flush ();
 
+    delete notmuch->term_gen;
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
     talloc_free (notmuch);
@@ -857,7 +881,25 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
                                           (char *) NULL);
 
     try {
-       /* The first order of business is to find/create a message ID. */
+       /* Before we do any real work, (especially before doing a
+        * potential SHA-1 computation on the entire file's contents),
+        * let's make sure that what we're looking at looks like an
+        * actual email message.
+        */
+       from = notmuch_message_file_get_header (message_file, "from");
+       subject = notmuch_message_file_get_header (message_file, "subject");
+       to = notmuch_message_file_get_header (message_file, "to");
+
+       if (from == NULL &&
+           subject == NULL &&
+           to == NULL)
+       {
+           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
+           goto DONE;
+       }
+
+       /* Now that we're sure it's mail, the first order of business
+        * is to find a message ID (or else create one ourselves). */
 
        header = notmuch_message_file_get_header (message_file, "message-id");
        if (header) {
@@ -914,19 +956,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
        date = notmuch_message_file_get_header (message_file, "date");
        _notmuch_message_set_date (message, date);
 
-       from = notmuch_message_file_get_header (message_file, "from");
-       subject = notmuch_message_file_get_header (message_file, "subject");
-       to = notmuch_message_file_get_header (message_file, "to");
+       _notmuch_message_index_file (message, filename);
 
-       if (from == NULL &&
-           subject == NULL &&
-           to == NULL)
-       {
-           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
-           goto DONE;
-       } else {
-           _notmuch_message_sync (message);
-       }
+       _notmuch_message_sync (message);
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred: %s.\n",
                 error.get_msg().c_str());