]> git.notmuchmail.org Git - notmuch/blobdiff - lib/message.cc
lib: eliminate fprintf from _notmuch_message_file_open
[notmuch] / lib / message.cc
index a7a13cc26aa181ec94f336048385403b903d4d37..5bc7aff1386a4a7e09a461f98f7e37f86e5a3f58 100644 (file)
@@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
 
        doc_id = _notmuch_database_generate_doc_id (notmuch);
     } catch (const Xapian::Error &error) {
-       fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
+       _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
                 error.get_msg().c_str());
        notmuch->exception_reported = TRUE;
        *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
@@ -283,7 +283,7 @@ _notmuch_message_get_term (notmuch_message_t *message,
     if (i == end)
        return NULL;
 
-    std::string term = *i;
+    const std::string &term = *i;
     if (strncmp (term.c_str(), prefix, prefix_len))
        return NULL;
 
@@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
     if (unlikely (filename == NULL))
        return;
 
-    message->message_file = _notmuch_message_file_open_ctx (message, filename);
+    message->message_file = _notmuch_message_file_open_ctx (
+       _notmuch_message_database (message), message, filename);
 }
 
 const char *
@@ -467,7 +468,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)
                return talloc_strdup (message, value.c_str ());
 
        } catch (Xapian::Error &error) {
-           fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+           _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",
                     error.get_msg().c_str());
            message->notmuch->exception_reported = TRUE;
            return NULL;
@@ -641,15 +642,16 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)
        unsigned int directory_id;
        const char *direntry, *directory;
        char *colon;
+       const std::string &term = *i;
 
        /* Terminate loop at first term without desired prefix. */
-       if (strncmp ((*i).c_str (), direntry_prefix, direntry_prefix_len))
+       if (strncmp (term.c_str (), direntry_prefix, direntry_prefix_len))
            break;
 
        /* Indicate that there are filenames remaining. */
        status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
 
-       direntry = (*i).c_str ();
+       direntry = term.c_str ();
        direntry += direntry_prefix_len;
 
        directory_id = strtol (direntry, &colon, 10);
@@ -920,7 +922,7 @@ notmuch_message_get_date (notmuch_message_t *message)
     try {
        value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
     } catch (Xapian::Error &error) {
-       fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",
+       _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",
                 error.get_msg().c_str());
        message->notmuch->exception_reported = TRUE;
        return 0;
@@ -1625,3 +1627,9 @@ notmuch_message_destroy (notmuch_message_t *message)
 {
     talloc_free (message);
 }
+
+notmuch_database_t *
+_notmuch_message_database (notmuch_message_t *message)
+{
+    return message->notmuch;
+}