From d6416fca5e4aad2fc48f373e3814d1794bf9d3de Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 2 Jul 2023 10:04:01 +0300 Subject: [PATCH] cli: add mu-cmd-{add,mkdir-remove}.cc Missing from previous. --- mu/mu-cmd-add.cc | 38 ++++++++++++++++++++++++++++++++++++++ mu/mu-cmd-mkdir.cc | 37 +++++++++++++++++++++++++++++++++++++ mu/mu-cmd-remove.cc | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 mu/mu-cmd-add.cc create mode 100644 mu/mu-cmd-mkdir.cc create mode 100644 mu/mu-cmd-remove.cc diff --git a/mu/mu-cmd-add.cc b/mu/mu-cmd-add.cc new file mode 100644 index 000000000..f30d61050 --- /dev/null +++ b/mu/mu-cmd-add.cc @@ -0,0 +1,38 @@ +/* +** Copyright (C) 2023 Dirk-Jan C. Binnema +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#include "config.h" +#include "mu-cmd.hh" + +using namespace Mu; + +Result +Mu::mu_cmd_add(Mu::Store& store, const Options& opts) +{ + for (auto&& file: opts.add.files) { + const auto docid{store.add_message(file)}; + if (!docid) + return Err(docid.error()); + else + g_debug("added message @ %s, docid=%u", + file.c_str(), docid.value()); + } + + return Ok(); +} diff --git a/mu/mu-cmd-mkdir.cc b/mu/mu-cmd-mkdir.cc new file mode 100644 index 000000000..3fedf495b --- /dev/null +++ b/mu/mu-cmd-mkdir.cc @@ -0,0 +1,37 @@ +/* +** Copyright (C) 2023 Dirk-Jan C. Binnema +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#include "config.h" +#include "mu-cmd.hh" + +#include "mu-maildir.hh" + +using namespace Mu; + +Mu::Result +Mu::mu_cmd_mkdir(const Options& opts) +{ + for (auto&& dir: opts.mkdir.dirs) { + if (auto&& res = + maildir_mkdir(dir, opts.mkdir.mode); !res) + return res; + } + + return Ok(); +} diff --git a/mu/mu-cmd-remove.cc b/mu/mu-cmd-remove.cc new file mode 100644 index 000000000..8e0455b19 --- /dev/null +++ b/mu/mu-cmd-remove.cc @@ -0,0 +1,38 @@ +/* +** Copyright (C) 2023 Dirk-Jan C. Binnema +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#include "config.h" +#include "mu-cmd.hh" + +using namespace Mu; + +Result +Mu::mu_cmd_remove(Mu::Store& store, const Options& opts) +{ + for (auto&& file: opts.remove.files) { + const auto res = store.remove_message(file); + if (!res) + return Err(Error::Code::File, "failed to remove %s", file.c_str()); + else + g_debug("removed message @ %s", file.c_str()); + } + + return Ok(); +} +