Skip to content

Commit

Permalink
Update to require libnotmuch >= 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Jun 6, 2024
1 parent 3a0e97d commit a7c8ab5
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 96 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ message (STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION}")
# check for required packages and libraries
#
find_package( Notmuch REQUIRED )
if (Notmuch_INDEX_FILE_API)
add_definitions ( -DHAVE_NOTMUCH_INDEX_FILE )
if (NOT Notmuch_VERSION VERSION_GREATER_EQUAL "5.4")
message (FATAL_ERROR "libnotmuch >= 5.4 must be installed.")
endif()

find_package ( PkgConfig REQUIRED )
Expand Down
2 changes: 0 additions & 2 deletions cmake/FindNotmuch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Notmuch_INCLUDE_DIRS - the Notmuch include directories
# Notmuch_LIBRARIES - link these to use Notmuch
# Notmuch_GMIME_VERSION - the GMime version notmuch was linked against
# Notmuch_INDEX_FILE_API - whether Notmuch has the notmuch_database_index_file() API

include (LibFindMacros)

Expand Down Expand Up @@ -65,7 +64,6 @@ libfind_process (Notmuch) # will set Notmuch_FOUND, Notmuch_INCLUDE_DIRS and Not
include (CheckSymbolExists)
set (CMAKE_REQUIRED_INCLUDES ${Notmuch_INCLUDE_DIR})
set (CMAKE_REQUIRED_LIBRARIES ${Notmuch_LIBRARY})
check_symbol_exists (notmuch_database_index_file notmuch.h Notmuch_INDEX_FILE_API)

# GMime version notmuch was linked against
include (GetPrerequisites)
Expand Down
4 changes: 2 additions & 2 deletions src/astroid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ namespace Astroid {
return m_config->config.get_child(id);
}

const boost::property_tree::ptree& Astroid::notmuch_config () const {
return m_config->notmuch_config;
const boost::filesystem::path& Astroid::notmuch_config () const {
return m_config->notmuch_config_path;
}

const StandardPaths& Astroid::standard_paths() const {
Expand Down
3 changes: 2 additions & 1 deletion src/astroid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# include <boost/property_tree/ptree.hpp>
# include <boost/program_options.hpp>
# include <boost/log/trivial.hpp>
# include <boost/filesystem.hpp>

# define LOG(x) BOOST_LOG_TRIVIAL(x)
# define warn warning
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace Astroid {


const boost::property_tree::ptree& config (const std::string& path=std::string()) const;
const boost::property_tree::ptree& notmuch_config () const;
const boost::filesystem::path& notmuch_config () const;
const StandardPaths& standard_paths() const;
RuntimePaths& runtime_paths() const;
bool has_notmuch_config ();
Expand Down
12 changes: 3 additions & 9 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,11 @@ namespace Astroid {
config.put ("poll.interval", 0);
config.put ("accounts.charlie.gpgkey", "[email protected]");
config.put ("mail.send_delay", 0);
std::string test_nmcfg_path;
if (getenv ("ASTROID_BUILD_DIR")) {
test_nmcfg_path = (current_path () / path ("tests/mail/test_config")).string();
notmuch_config_path = (current_path () / path ("tests/mail/test_config"));
} else {
test_nmcfg_path = (Resource::get_exe_dir () / path ("tests/mail/test_config")).string();
notmuch_config_path = (Resource::get_exe_dir () / path ("tests/mail/test_config")).string();
}
boost::property_tree::read_ini (test_nmcfg_path, notmuch_config);
has_notmuch_config = true;
return;
}
Expand Down Expand Up @@ -370,8 +368,7 @@ namespace Astroid {
std_paths.attach_dir = Utils::expand(bfs::path (config.get<string>("editor.attachment_directory")));
run_paths.attach_dir = std_paths.attach_dir;

/* read notmuch config */
bfs::path notmuch_config_path;
/* search for notmuch config file */
char * notmuch_config_env = getenv ("NOTMUCH_CONFIG");
if (notmuch_config_env) {
notmuch_config_path = Utils::expand(bfs::path (notmuch_config_env));
Expand All @@ -380,9 +377,6 @@ namespace Astroid {
}

if (is_regular_file (notmuch_config_path)) {
boost::property_tree::read_ini (
notmuch_config_path.c_str(),
notmuch_config);
has_notmuch_config = true;
} else {
has_notmuch_config = false;
Expand Down
4 changes: 2 additions & 2 deletions src/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ namespace Astroid {
void write_back_config ();

ptree config;
ptree notmuch_config;
bool has_notmuch_config;
bfs::path notmuch_config_path;
bool has_notmuch_config = false;

const int CONFIG_VERSION = 11;

Expand Down
73 changes: 44 additions & 29 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ namespace Astroid {
std::vector<ustring> Db::tags;

bfs::path Db::path_db;
bfs::path Db::path_config;

void Db::init () {
const ptree& config = astroid->notmuch_config ();
path_config = astroid->notmuch_config ();

const char * home = getenv ("HOME");
if (home == NULL) {
Expand All @@ -51,44 +52,46 @@ namespace Astroid {
throw database_error ("db: error: no notmuch config file found.");
}

ustring db_path;
try {
db_path = ustring (config.get<string> ("database.path"));
} catch (const boost::property_tree::ptree_bad_path &ex) {
throw database_error ("db: error: no database path specified");
notmuch_database_t *dbh = NULL;
char *error_message = NULL;
notmuch_status_t s = notmuch_database_load_config (NULL,
path_config.c_str (),
NULL, &dbh, &error_message);

if (error_message != NULL) {
LOG (error) << "db: " << error_message;
free (error_message);

if (s == NOTMUCH_STATUS_NO_DATABASE) {
notmuch_database_destroy (dbh);
throw database_error ("db: error: no database path specified");
}

throw database_error ("db: error: could not open notmuch config file");
}

const char *db_path = notmuch_config_get (dbh, NOTMUCH_CONFIG_DATABASE_PATH);
LOG (info) << "db path: " << db_path;

path_db = Utils::expand (path (db_path));
path_db = Utils::expand (path (ustring (db_path)));
path_db = absolute (path_db);

ustring excluded_tags_s;
try {
excluded_tags_s = config.get<string> ("search.exclude_tags");
} catch (const boost::property_tree::ptree_bad_path &ex) {
throw database_error ("db: error: no search.exclude_tags defined in notmuch-config");
}
excluded_tags = VectorUtils::split_and_trim (excluded_tags_s, ";");
const char *excluded_tags_s = notmuch_config_get (dbh, NOTMUCH_CONFIG_EXCLUDE_TAGS);
excluded_tags = VectorUtils::split_and_trim (ustring (excluded_tags_s), ";");
sort (excluded_tags.begin (), excluded_tags.end ());

// TODO: find a better way to handle sent_tags, probably via AccountManager?
ustring sent_tags_s = astroid->config().get<std::string> ("mail.sent_tags");
sent_tags = VectorUtils::split_and_trim (sent_tags_s, ",");
sort (sent_tags.begin (), sent_tags.end ());

try {
maildir_synchronize_flags = config.get<bool> ("maildir.synchronize_flags");
} catch (const boost::property_tree::ptree_bad_path &ex) {
throw database_error ("db: error: no maildir.maildir_synchronize_flags defined in notmuch-config");
} catch (const boost::property_tree::ptree_bad_data &ex) {
ustring bad_data_s = config.get<string> ("maildir.synchronize_flags");
if (bad_data_s != "") {
LOG (error) << "db: error: bad argument '" << bad_data_s << "' "
<< "for maildir.maildir_synchronize_flags in notmuch-config "
<< "(expected yes/no)";
}
notmuch_bool_t sync_flags_b;
s = notmuch_config_get_bool (dbh, NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS, &sync_flags_b);
if (s == NOTMUCH_STATUS_SUCCESS) {
maildir_synchronize_flags = sync_flags_b;
}

notmuch_database_destroy (dbh);
}

Db::Db (DbMode _mode) {
Expand Down Expand Up @@ -126,11 +129,17 @@ namespace Astroid {
* it is done.
*/
do {
s = notmuch_database_open (
char *error_message = NULL;
s = notmuch_database_open_with_config (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_WRITE,
&nm_db);
path_config.c_str(),
NULL, &nm_db, &error_message);

if (error_message != NULL) {
LOG (error) << "db: " << error_message;
free (error_message);
}
if (s == NOTMUCH_STATUS_XAPIAN_EXCEPTION) {
LOG (error) << "db: error: could not open db r/w, waited " <<
time << " of maximum " <<
Expand Down Expand Up @@ -165,11 +174,17 @@ namespace Astroid {
int time = 0;

do {
s = notmuch_database_open (
char *error_message = NULL;
s = notmuch_database_open_with_config (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
path_config.c_str(),
NULL, &nm_db, &error_message);

if (error_message != NULL) {
LOG (error) << "db: " << error_message;
free (error_message);
}
if (s == NOTMUCH_STATUS_XAPIAN_EXCEPTION) {
LOG (error) << "db: error: could not open db r/o, waited " <<
time << " of maximum " <<
Expand Down
21 changes: 1 addition & 20 deletions src/db.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@
# include "config.hh"
# include "proto.hh"

/* there was a bit of a round-dance of with the _st versions of these returning
* to the old name, but with different signature */
# if (LIBNOTMUCH_MAJOR_VERSION < 5)
# define notmuch_query_search_threads(x,y) notmuch_query_search_threads_st(x,y)
# define notmuch_query_count_threads(x,y) notmuch_query_count_threads_st(x,y)
# define notmuch_query_search_messages(x,y) notmuch_query_search_messages_st(x,y)
# define notmuch_query_count_messages(x,y) notmuch_query_count_messages_st(x,y)
# endif

/* Rewrite deprecated function calls in libnotmuch 5.4+, whilst still keeping
* backwards compat with 5.3. */
# if (LIBNOTMUCH_MAJOR_VERSION >= 5 && LIBNOTMUCH_MINOR_VERSION >= 4)
# define notmuch_database_open(p, m, d) \
notmuch_database_open_with_config(p, m, "", NULL, d, NULL)
# endif

# ifndef HAVE_NOTMUCH_INDEX_FILE
# define notmuch_database_index_file(d,f,o,m) notmuch_database_add_message(d,f,m)
# endif

namespace Astroid {
class NotmuchItem : public Glib::Object {
public:
Expand Down Expand Up @@ -170,6 +150,7 @@ namespace Astroid {
static bool maildir_synchronize_flags;
static void init ();
static bfs::path path_db;
static bfs::path path_config;

private:
/*
Expand Down
8 changes: 4 additions & 4 deletions tests/test_notmuch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ BOOST_AUTO_TEST_SUITE(Notmuch)
notmuch_database_t * nm_db;

notmuch_status_t s =
notmuch_database_open (
notmuch_database_open_with_config (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
NULL, NULL, &nm_db, NULL);


BOOST_CHECK (s == NOTMUCH_STATUS_SUCCESS);
Expand Down Expand Up @@ -76,10 +76,10 @@ BOOST_AUTO_TEST_SUITE(Notmuch)
notmuch_database_t * nm_db;

notmuch_status_t s =
notmuch_database_open (
notmuch_database_open_with_config (
path_db.c_str(),
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
"", NULL, &nm_db, NULL);


BOOST_CHECK (s == NOTMUCH_STATUS_SUCCESS);
Expand Down
29 changes: 6 additions & 23 deletions tests/test_notmuch_standalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@

// Build with: g++ test_notmuch_standalone.cc -o test_notmuch_standalone -lnotmuch


/* there was a bit of a round-dance of with the _st versions of these returning
* to the old name, but with different signature */
# if (LIBNOTMUCH_MAJOR_VERSION < 5)
# define notmuch_query_search_threads(x,y) notmuch_query_search_threads_st(x,y)
# define notmuch_query_count_threads(x,y) notmuch_query_count_threads_st(x,y)
# define notmuch_query_search_messages(x,y) notmuch_query_search_messages_st(x,y)
# define notmuch_query_count_messages(x,y) notmuch_query_count_messages_st(x,y)
# endif

/* Rewrite deprecated function calls in libnotmuch 5.4+, whilst still keeping
* backwards compat with 5.3. */
# if (LIBNOTMUCH_MAJOR_VERSION >= 5 && LIBNOTMUCH_MINOR_VERSION >= 4)
# define notmuch_database_open(p, m, d) \
notmuch_database_open_with_config(p, m, "", NULL, d, NULL)
# endif

using std::cout;
using std::endl;

Expand All @@ -32,10 +15,10 @@ int main () {
notmuch_database_t * nm_db;

notmuch_status_t s =
notmuch_database_open (
notmuch_database_open_with_config (
path_db,
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_ONLY,
&nm_db);
"", NULL, &nm_db, NULL);

(void) (s);

Expand Down Expand Up @@ -115,10 +98,10 @@ int main () {
* continue loading the original query */
notmuch_database_t * nm_db2;

s = notmuch_database_open (
s = notmuch_database_open_with_config (
path_db,
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_WRITE,
&nm_db2);
"", NULL, &nm_db2, NULL);


char qry_s[256];
Expand Down Expand Up @@ -159,10 +142,10 @@ int main () {
notmuch_database_close (nm_db2);

/* re-add unread tag */
s = notmuch_database_open (
s = notmuch_database_open_with_config (
path_db,
notmuch_database_mode_t::NOTMUCH_DATABASE_MODE_READ_WRITE,
&nm_db2);
"", NULL, &nm_db2, NULL);



Expand Down
2 changes: 0 additions & 2 deletions tests/test_open_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ BOOST_AUTO_TEST_SUITE(DbTest)
BOOST_AUTO_TEST_CASE(open_confirm)
{
setup ();
const_cast<ptree&>(astroid->notmuch_config()).put ("database.path", "tests/mail/test_mail");

Db * db;

Expand All @@ -33,7 +32,6 @@ BOOST_AUTO_TEST_SUITE(DbTest)
BOOST_AUTO_TEST_CASE(open_rw)
{
setup ();
const_cast<ptree&>(astroid->notmuch_config()).put ("database.path", "tests/mail/test_mail");

Db * db;

Expand Down

0 comments on commit a7c8ab5

Please sign in to comment.