mirror of https://github.com/djcb/mu.git
store: expose maildirs() method
This gets the current list of maildirs by asking the scanner to do a file-system search.
This commit is contained in:
parent
f5beea2eb2
commit
e52030c049
|
@ -39,6 +39,7 @@
|
|||
#include "mu-store.hh"
|
||||
#include "mu-query.hh"
|
||||
#include "mu-xapian-db.hh"
|
||||
#include "index/mu-scanner.hh"
|
||||
|
||||
#include "utils/mu-error.hh"
|
||||
|
||||
|
@ -630,3 +631,21 @@ Store::parse_query(const std::string& expr, bool xapian) const
|
|||
return q.parse(expr, xapian);
|
||||
}, std::string{});
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string>
|
||||
Store::maildirs() const
|
||||
{
|
||||
std::vector<std::string> mdirs;
|
||||
const auto prefix_size = root_maildir().size();
|
||||
Scanner::Handler handler = [&](const std::string& path, auto&& _1, auto&& _2) {
|
||||
mdirs.emplace_back(path.substr(prefix_size));
|
||||
return true;
|
||||
};
|
||||
|
||||
Scanner scanner{root_maildir(), handler, Scanner::Mode::MaildirsOnly};
|
||||
scanner.start();
|
||||
std::sort(mdirs.begin(), mdirs.end());
|
||||
|
||||
return mdirs;
|
||||
}
|
||||
|
|
|
@ -426,6 +426,17 @@ public:
|
|||
*/
|
||||
bool empty() const { return xapian_db().empty(); }
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of maildirs, that is, the list of maildirs
|
||||
* under root_maildir, without file-system prefix.
|
||||
*
|
||||
* This does a file-system scan.
|
||||
*
|
||||
* @return list of maildirs
|
||||
*/
|
||||
std::vector<std::string> maildirs() const;
|
||||
|
||||
/*
|
||||
* _almost_ private
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue