Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/ci-debian-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ jobs:
- image: 'debian:stable'
env:
WEBKITGTK_VERSION: '4.0'
- image: 'debian:bullseye'
env:
WEBKITGTK_VERSION: '4.0'
- image: 'ubuntu:focal'
env:
WEBKITGTK_VERSION: '4.0'
- image: 'debian:sid'
env:
WEBKITGTK_VERSION: '4.1'
- image: 'ubuntu:devel'
- image: 'ubuntu:noble'
env:
WEBKITGTK_VERSION: '4.1'
- image: 'ubuntu:noble'
- image: 'ubuntu:devel'
env:
WEBKITGTK_VERSION: '4.1'
timeout-minutes: 15
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,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 @@ -342,8 +342,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
19 changes: 3 additions & 16 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ namespace Astroid {
ptree default_config;
default_config.put ("astroid.config.version", CONFIG_VERSION);

std::string nm_cfg = path(std_paths.home / path (".notmuch-config")).string();
char* nm_env = getenv("NOTMUCH_CONFIG");
if (nm_env != NULL) {
nm_cfg.assign(nm_env, strlen(nm_env));
}
default_config.put ("astroid.notmuch_config" , nm_cfg);

default_config.put ("astroid.debug.dryrun_sending", false);

/* only show hints with a level higher than this */
Expand Down Expand Up @@ -319,13 +312,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 @@ -376,8 +367,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 @@ -386,9 +376,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
82 changes: 51 additions & 31 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,66 @@ namespace Astroid {
std::vector<ustring> Db::tags;

bfs::path Db::path_db;
const char * Db::path_config;

void Db::init () {
const ptree& config = astroid->notmuch_config ();
// NULL: notmuch searches according to notmuch-config(1) / notmuch.h:notmuch_database_open_with_config()
path_config = astroid->has_notmuch_config () ? astroid->notmuch_config().c_str() : NULL;

const char * home = getenv ("HOME");
if (home == NULL) {
LOG (error) << "db: error: HOME variable not set.";
throw invalid_argument ("db: error: HOME environment variable not set.");
}

if (!astroid->has_notmuch_config ()) {
throw database_error ("db: error: no notmuch config file found.");
notmuch_database_t *dbh = NULL;
char *error_message = NULL;
// NULL: notmuch searches according to notmuch-config(1) / notmuch.h:notmuch_database_open_with_config()
notmuch_status_t s = notmuch_database_load_config (NULL, path_config, NULL, &dbh, &error_message);

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

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");
if (s != NOTMUCH_STATUS_SUCCESS) {
notmuch_database_destroy (dbh);
const char *db_err_str;
switch (s) {
case NOTMUCH_STATUS_NO_DATABASE:
db_err_str = "db: error: no database path specified";
break;
case NOTMUCH_STATUS_NO_CONFIG:
db_err_str = "db: error: no notmuch config file found.";
break;
default:
db_err_str = "db: error: could not open notmuch config file";
}
throw database_error (db_err_str);
}

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 +134,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,
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 +179,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,
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
14 changes: 1 addition & 13 deletions src/db.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +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

# 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 @@ -163,6 +150,7 @@ namespace Astroid {
static bool maildir_synchronize_flags;
static void init ();
static bfs::path path_db;
static const char * 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, &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
22 changes: 6 additions & 16 deletions tests/test_notmuch_standalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +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

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

Expand All @@ -25,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 @@ -108,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 @@ -152,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