2011-09-12 19:33:06 +02:00
|
|
|
/*
|
2022-02-16 22:03:48 +01:00
|
|
|
** Copyright (C) 2008-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-01-27 07:15:08 +01:00
|
|
|
**
|
|
|
|
** 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,
|
2011-09-12 19:33:06 +02:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-01-27 07:15:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2010-01-31 11:15:00 +01:00
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2010-01-28 21:21:57 +01:00
|
|
|
#include <string.h>
|
2022-02-16 22:03:48 +01:00
|
|
|
#include <vector>
|
2022-06-28 22:24:22 +02:00
|
|
|
#include <fstream>
|
2010-01-28 21:21:57 +01:00
|
|
|
|
2020-11-03 08:58:59 +01:00
|
|
|
#include "test-mu-common.hh"
|
2020-11-28 09:15:49 +01:00
|
|
|
#include "mu-maildir.hh"
|
2022-06-29 21:19:26 +02:00
|
|
|
#include "utils/mu-result.hh"
|
2019-12-16 20:44:35 +01:00
|
|
|
#include "utils/mu-util.h"
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2020-11-28 09:15:49 +01:00
|
|
|
using namespace Mu;
|
2020-11-03 08:58:59 +01:00
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
static void
|
2022-05-09 18:34:07 +02:00
|
|
|
test_maildir_mkdir_01(void)
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int i;
|
|
|
|
gchar * tmpdir, *mdir, *tmp;
|
|
|
|
const gchar* subs[] = {"tmp", "cur", "new"};
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-05-09 18:34:07 +02:00
|
|
|
g_assert_true(!!maildir_mkdir(mdir, 0755, FALSE));
|
2010-01-27 07:15:08 +01:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
|
|
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
|
|
|
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
|
|
g_free(dir);
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint(g_access(tmp, F_OK), !=, 0);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(tmp);
|
|
|
|
g_free(tmpdir);
|
|
|
|
g_free(mdir);
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-05-09 18:34:07 +02:00
|
|
|
test_maildir_mkdir_02(void)
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int i;
|
|
|
|
gchar * tmpdir, *mdir, *tmp;
|
|
|
|
const gchar* subs[] = {"tmp", "cur", "new"};
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-05-09 18:34:07 +02:00
|
|
|
g_assert_true(!!maildir_mkdir(mdir, 0755, TRUE));
|
2010-01-27 07:15:08 +01:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
|
|
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
|
|
g_free(dir);
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint(g_access(tmp, F_OK), ==, 0);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(tmp);
|
|
|
|
g_free(tmpdir);
|
|
|
|
g_free(mdir);
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-26 11:18:17 +01:00
|
|
|
static void
|
2022-05-09 18:34:07 +02:00
|
|
|
test_maildir_mkdir_03(void)
|
2012-02-26 11:18:17 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int i;
|
|
|
|
gchar * tmpdir, *mdir, *tmp;
|
|
|
|
const gchar* subs[] = {"tmp", "cur", "new"};
|
2012-02-26 11:18:17 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
2012-02-26 11:18:17 +01:00
|
|
|
|
|
|
|
/* create part of the structure already... */
|
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* dir;
|
|
|
|
dir = g_strdup_printf("%s%ccur", mdir, G_DIR_SEPARATOR);
|
|
|
|
g_assert_cmpuint(g_mkdir_with_parents(dir, 0755), ==, 0);
|
|
|
|
g_free(dir);
|
2012-02-26 11:18:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this should still work */
|
2022-05-09 18:34:07 +02:00
|
|
|
g_assert_true(!!maildir_mkdir(mdir, 0755, FALSE));
|
2012-02-26 11:18:17 +01:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
|
|
gchar* dir;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
|
|
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
|
|
|
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
|
|
g_free(dir);
|
2012-02-26 11:18:17 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
|
|
g_assert_cmpuint(g_access(tmp, F_OK), !=, 0);
|
2012-02-26 11:18:17 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(tmp);
|
|
|
|
g_free(tmpdir);
|
|
|
|
g_free(mdir);
|
2012-02-26 11:18:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-05-09 18:34:07 +02:00
|
|
|
test_maildir_mkdir_04(void)
|
2012-02-26 11:18:17 +01:00
|
|
|
{
|
|
|
|
gchar *tmpdir, *mdir;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
tmpdir = test_mu_common_get_random_tmpdir();
|
|
|
|
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
2012-02-26 11:18:17 +01:00
|
|
|
|
|
|
|
/* create part of the structure already... */
|
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* dir;
|
|
|
|
g_assert_cmpuint(g_mkdir_with_parents(mdir, 0755), ==, 0);
|
|
|
|
dir = g_strdup_printf("%s%ccur", mdir, G_DIR_SEPARATOR);
|
|
|
|
g_assert_cmpuint(g_mkdir_with_parents(dir, 0000), ==, 0);
|
|
|
|
g_free(dir);
|
2012-02-26 11:18:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this should fail now, because cur is not read/writable */
|
2022-02-16 22:03:48 +01:00
|
|
|
if (geteuid() != 0)
|
2022-05-09 18:34:07 +02:00
|
|
|
g_assert_false(!!maildir_mkdir(mdir, 0755, false));
|
2022-02-16 22:03:48 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(tmpdir);
|
|
|
|
g_free(mdir);
|
2012-02-26 11:18:17 +01:00
|
|
|
}
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
static gboolean
|
2021-10-20 11:18:15 +02:00
|
|
|
ignore_error(const char* log_domain, GLogLevelFlags log_level, const gchar* msg, gpointer user_data)
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
|
|
|
return FALSE; /* don't abort */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-05-09 18:34:07 +02:00
|
|
|
test_maildir_mkdir_05(void)
|
2011-09-12 19:33:06 +02:00
|
|
|
{
|
2010-01-27 07:15:08 +01:00
|
|
|
/* this must fail */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_log_set_fatal_handler((GTestLogFatalFunc)ignore_error, NULL);
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2022-05-09 18:34:07 +02:00
|
|
|
g_assert_false(!!maildir_mkdir({}, 0755, true));
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-02-18 09:49:56 +01:00
|
|
|
[[maybe_unused]] static void
|
2021-10-20 11:18:15 +02:00
|
|
|
assert_matches_regexp(const char* str, const char* rx)
|
2013-05-25 18:28:40 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!g_regex_match_simple(rx, str, (GRegexCompileFlags)0, (GRegexMatchFlags)0)) {
|
|
|
|
if (g_test_verbose())
|
|
|
|
g_print("%s does not match %s", str, rx);
|
|
|
|
g_assert(0);
|
2013-05-25 18:28:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 22:03:48 +01:00
|
|
|
|
2013-05-25 18:28:40 +02:00
|
|
|
static void
|
2022-02-16 22:03:48 +01:00
|
|
|
test_determine_target_ok(void)
|
2013-05-25 18:28:40 +02:00
|
|
|
{
|
2022-02-16 22:03:48 +01:00
|
|
|
struct TestCase {
|
|
|
|
std::string old_path;
|
|
|
|
std::string root_maildir;
|
|
|
|
std::string target_maildir;
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags new_flags;
|
2022-02-16 22:03:48 +01:00
|
|
|
bool new_name;
|
|
|
|
std::string expected;
|
|
|
|
};
|
|
|
|
const std::vector<TestCase> testcases = {
|
|
|
|
TestCase{ /* change some flags */
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags::Seen | Flags::Passed,
|
2022-02-16 22:03:48 +01:00
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,PS"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* from cur -> new */
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags::New,
|
2022-02-16 22:03:48 +01:00
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/new/123456"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* from new->cur */
|
|
|
|
"/home/foo/Maildir/test/cur/123456",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags::Seen | Flags::Flagged,
|
2022-02-16 22:03:48 +01:00
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FS"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* change maildir */
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
"/test2",
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags::Flagged | Flags::Replied,
|
2022-02-16 22:03:48 +01:00
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test2/cur/123456:2,FR"
|
|
|
|
},
|
|
|
|
TestCase{ /* remove all flags */
|
|
|
|
"/home/foo/Maildir/test/new/123456",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags::None,
|
2022-02-16 22:03:48 +01:00
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto&& testcase: testcases) {
|
2022-05-09 18:34:07 +02:00
|
|
|
const auto res = maildir_determine_target(
|
2022-02-16 22:03:48 +01:00
|
|
|
testcase.old_path,
|
|
|
|
testcase.root_maildir,
|
|
|
|
testcase.target_maildir,
|
|
|
|
testcase.new_flags,
|
|
|
|
testcase.new_name);
|
|
|
|
g_assert_true(!!res);
|
|
|
|
g_assert_cmpstr(testcase.expected.c_str(), ==,
|
|
|
|
res.value().c_str());
|
2013-05-25 18:28:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 07:11:47 +02:00
|
|
|
|
2022-06-02 20:02:11 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_determine_target_fail(void)
|
|
|
|
{
|
|
|
|
struct TestCase {
|
|
|
|
std::string old_path;
|
|
|
|
std::string root_maildir;
|
|
|
|
std::string target_maildir;
|
|
|
|
Flags new_flags;
|
|
|
|
bool new_name;
|
|
|
|
std::string expected;
|
|
|
|
};
|
|
|
|
const std::vector<TestCase> testcases = {
|
|
|
|
TestCase{ /* fail: no absolute path */
|
|
|
|
"../foo/Maildir/test/cur/123456:2,FR-not-absolute",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
|
|
|
Flags::Seen | Flags::Passed,
|
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,PS"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* fail: no absolute root */
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"../foo/Maildir-not-absolute",
|
|
|
|
{},
|
|
|
|
Flags::New,
|
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/new/123456"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* fail: maildir must start with '/' */
|
|
|
|
"/home/foo/Maildir/test/cur/123456",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
"mymaildirwithoutslash",
|
|
|
|
Flags::Seen | Flags::Flagged,
|
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FS"
|
|
|
|
},
|
|
|
|
|
|
|
|
TestCase{ /* fail: path must be below maildir */
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
"/home/bar/Maildir",
|
|
|
|
"/test2",
|
|
|
|
Flags::Flagged | Flags::Replied,
|
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test2/cur/123456:2,FR"
|
|
|
|
},
|
|
|
|
TestCase{ /* fail: New cannot be combined */
|
|
|
|
"/home/foo/Maildir/test/new/123456",
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{},
|
|
|
|
Flags::New | Flags::Replied,
|
|
|
|
false,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto&& testcase: testcases) {
|
|
|
|
const auto res = maildir_determine_target(
|
|
|
|
testcase.old_path,
|
|
|
|
testcase.root_maildir,
|
|
|
|
testcase.target_maildir,
|
|
|
|
testcase.new_flags,
|
|
|
|
testcase.new_name);
|
|
|
|
g_assert_false(!!res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-31 22:43:13 +02:00
|
|
|
static void
|
|
|
|
test_maildir_get_new_path_01(void)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
std::string oldpath;
|
|
|
|
Flags flags;
|
|
|
|
std::string newpath;
|
|
|
|
} paths[] = {{"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
Flags::Replied,
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,R"},
|
|
|
|
{"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
Flags::New,
|
|
|
|
"/home/foo/Maildir/test/new/123456"},
|
|
|
|
{"/home/foo/Maildir/test/new/123456:2,FR",
|
|
|
|
(Flags::Seen | Flags::Replied),
|
|
|
|
"/home/foo/Maildir/test/cur/123456:2,RS"},
|
|
|
|
{"/home/foo/Maildir/test/new/1313038887_0.697",
|
|
|
|
(Flags::Seen | Flags::Flagged | Flags::Passed),
|
|
|
|
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"},
|
|
|
|
{"/home/foo/Maildir/test/new/1313038887_0.697:2,",
|
|
|
|
(Flags::Seen | Flags::Flagged | Flags::Passed),
|
|
|
|
"/home/foo/Maildir/test/cur/1313038887_0.697:2,FPS"},
|
|
|
|
/* note the ':2,' suffix on the new message is
|
|
|
|
* removed */
|
|
|
|
|
|
|
|
{"/home/foo/Maildir/trash/new/1312920597.2206_16.cthulhu",
|
|
|
|
Flags::Seen,
|
|
|
|
"/home/foo/Maildir/trash/cur/1312920597.2206_16.cthulhu:2,S"}};
|
|
|
|
|
|
|
|
for (int i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
const auto newpath{maildir_determine_target(paths[i].oldpath,
|
|
|
|
"/home/foo/Maildir",
|
|
|
|
{}, paths[i].flags, false)};
|
|
|
|
assert_valid_result(newpath);
|
|
|
|
assert_equal(*newpath, paths[i].newpath);
|
|
|
|
}
|
|
|
|
}
|
2011-05-06 07:11:47 +02:00
|
|
|
|
2022-05-31 22:43:13 +02:00
|
|
|
static void
|
|
|
|
test_maildir_get_new_path_02(void)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
std::string oldpath;
|
|
|
|
Flags flags;
|
|
|
|
std::string targetdir;
|
|
|
|
std::string newpath;
|
|
|
|
std::string root_maildir;
|
|
|
|
} paths[] = {{"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
Flags::Replied,
|
|
|
|
"/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,R",
|
|
|
|
"/home/foo/Maildir"},
|
|
|
|
{"/home/bar/Maildir/test/cur/123456:2,FR",
|
|
|
|
Flags::New,
|
|
|
|
"/coffee",
|
|
|
|
"/home/bar/Maildir/coffee/new/123456",
|
|
|
|
"/home/bar/Maildir"
|
|
|
|
},
|
|
|
|
{"/home/cuux/Maildir/test/new/123456",
|
|
|
|
(Flags::Seen | Flags::Replied),
|
|
|
|
"/tea",
|
|
|
|
"/home/cuux/Maildir/tea/cur/123456:2,RS",
|
|
|
|
"/home/cuux/Maildir"},
|
|
|
|
{"/home/boy/Maildir/test/new/1313038887_0.697:2,",
|
|
|
|
(Flags::Seen | Flags::Flagged | Flags::Passed),
|
|
|
|
"/stuff",
|
|
|
|
"/home/boy/Maildir/stuff/cur/1313038887_0.697:2,FPS",
|
|
|
|
"/home/boy/Maildir"}};
|
|
|
|
|
|
|
|
for (int i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
auto newpath{maildir_determine_target(paths[i].oldpath,
|
|
|
|
paths[i].root_maildir,
|
|
|
|
paths[i].targetdir,
|
|
|
|
paths[i].flags,
|
|
|
|
false)};
|
|
|
|
assert_valid_result(newpath);
|
|
|
|
assert_equal(*newpath, paths[i].newpath);
|
|
|
|
}
|
|
|
|
}
|
2011-08-13 01:25:03 +02:00
|
|
|
|
2022-05-31 22:43:13 +02:00
|
|
|
static void
|
|
|
|
test_maildir_get_new_path_custom(void)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
std::string oldpath;
|
|
|
|
Flags flags;
|
|
|
|
std::string targetdir;
|
|
|
|
std::string newpath;
|
|
|
|
std::string root_maildir;
|
|
|
|
} paths[] = {{"/home/foo/Maildir/test/cur/123456:2,FR",
|
|
|
|
Flags::Replied,
|
|
|
|
"/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,R",
|
|
|
|
"/home/foo/Maildir"},
|
|
|
|
{"/home/foo/Maildir/test/cur/123456:2,hFeRllo123",
|
|
|
|
Flags::Flagged,
|
|
|
|
"/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,F",
|
|
|
|
"/home/foo/Maildir"},
|
|
|
|
{"/home/foo/Maildir/test/cur/123456:2,abc",
|
|
|
|
Flags::Passed,
|
|
|
|
"/blabla",
|
|
|
|
"/home/foo/Maildir/blabla/cur/123456:2,P",
|
|
|
|
"/home/foo/Maildir"}};
|
|
|
|
|
|
|
|
for (int i = 0; i != G_N_ELEMENTS(paths); ++i) {
|
|
|
|
auto newpath{maildir_determine_target(paths[i].oldpath,
|
|
|
|
paths[1].root_maildir,
|
|
|
|
paths[i].targetdir,
|
|
|
|
paths[i].flags,
|
|
|
|
false)};
|
|
|
|
assert_valid_result(newpath);
|
|
|
|
assert_equal(*newpath, paths[i].newpath);
|
|
|
|
}
|
|
|
|
}
|
2011-08-13 01:25:03 +02:00
|
|
|
|
2022-05-31 22:43:13 +02:00
|
|
|
static void
|
|
|
|
test_maildir_from_path(void)
|
|
|
|
{
|
|
|
|
unsigned u;
|
2011-08-13 01:25:03 +02:00
|
|
|
|
2022-05-31 22:43:13 +02:00
|
|
|
struct {
|
|
|
|
std::string path, exp;
|
|
|
|
} cases[] = {{"/home/foo/Maildir/test/cur/123456:2,FR", "/test"},
|
|
|
|
{"/home/foo/Maildir/lala/new/1313038887_0.697:2,", "/lala"}};
|
|
|
|
|
|
|
|
for (u = 0; u != G_N_ELEMENTS(cases); ++u) {
|
|
|
|
auto mdir{maildir_from_path(cases[u].path, "/home/foo/Maildir")};
|
|
|
|
assert_valid_result(mdir);
|
|
|
|
assert_equal(*mdir, cases[u].exp);
|
|
|
|
}
|
|
|
|
}
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-06-28 22:24:22 +02:00
|
|
|
static void
|
|
|
|
test_maildir_link()
|
|
|
|
{
|
2022-06-29 21:19:26 +02:00
|
|
|
TempDir tmpdir;
|
2022-06-28 22:24:22 +02:00
|
|
|
|
2022-06-29 21:19:26 +02:00
|
|
|
assert_valid_result(maildir_mkdir(tmpdir.path() + "/foo"));
|
|
|
|
assert_valid_result(maildir_mkdir(tmpdir.path() + "/bar"));
|
2022-06-28 22:24:22 +02:00
|
|
|
|
|
|
|
const auto srcpath1 = tmpdir.path() + "/foo/cur/msg1";
|
|
|
|
const auto srcpath2 = tmpdir.path() + "/foo/new/msg2";
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream stream(srcpath1);
|
|
|
|
stream.write("cur", 3);
|
|
|
|
g_assert_true(stream.good());
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream stream(srcpath2);
|
|
|
|
stream.write("new", 3);
|
|
|
|
g_assert_true(stream.good());
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
|
2022-06-29 21:19:26 +02:00
|
|
|
assert_valid_result(maildir_link(srcpath1, tmpdir.path() + "/bar", false));
|
|
|
|
assert_valid_result(maildir_link(srcpath2, tmpdir.path() + "/bar", false));
|
2022-06-28 22:24:22 +02:00
|
|
|
|
|
|
|
const auto dstpath1 = tmpdir.path() + "/bar/cur/msg1";
|
|
|
|
const auto dstpath2 = tmpdir.path() + "/bar/new/msg2";
|
|
|
|
|
|
|
|
g_assert_true(g_access(dstpath1.c_str(), F_OK) == 0);
|
|
|
|
g_assert_true(g_access(dstpath2.c_str(), F_OK) == 0);
|
|
|
|
|
2022-06-29 21:19:26 +02:00
|
|
|
assert_valid_result(maildir_clear_links(tmpdir.path() + "/bar"));
|
2022-06-28 22:24:22 +02:00
|
|
|
g_assert_false(g_access(dstpath1.c_str(), F_OK) == 0);
|
|
|
|
g_assert_false(g_access(dstpath2.c_str(), F_OK) == 0);
|
|
|
|
}
|
|
|
|
|
2022-06-29 21:19:26 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_maildir_move(bool use_gio)
|
|
|
|
{
|
|
|
|
TempDir tmpdir;
|
|
|
|
|
|
|
|
assert_valid_result(maildir_mkdir(tmpdir.path() + "/foo"));
|
|
|
|
assert_valid_result(maildir_mkdir(tmpdir.path() + "/bar"));
|
|
|
|
|
|
|
|
const auto srcpath1 = tmpdir.path() + "/foo/cur/msg1";
|
|
|
|
const auto srcpath2 = tmpdir.path() + "/foo/new/msg2";
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream stream(srcpath1);
|
|
|
|
stream.write("cur", 3);
|
|
|
|
g_assert_true(stream.good());
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream stream(srcpath2);
|
|
|
|
stream.write("new", 3);
|
|
|
|
g_assert_true(stream.good());
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto dstpath = tmpdir.path() + "/test1";
|
|
|
|
|
|
|
|
assert_valid_result(maildir_move_message(srcpath1, dstpath, use_gio));
|
|
|
|
assert_valid_result(maildir_move_message(srcpath2, dstpath, use_gio));
|
|
|
|
|
|
|
|
|
|
|
|
//g_assert_true(g_access(dstpath.c_str(), F_OK) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_maildir_move_vanilla()
|
|
|
|
{
|
|
|
|
test_maildir_move(false/*!gio*/);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_maildir_move_gio()
|
|
|
|
{
|
|
|
|
test_maildir_move(true/*gio*/);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 07:15:08 +01:00
|
|
|
int
|
2021-10-20 11:18:15 +02:00
|
|
|
main(int argc, char* argv[])
|
2010-01-27 07:15:08 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
2010-01-27 07:15:08 +01:00
|
|
|
|
2010-01-28 21:21:57 +01:00
|
|
|
/* mu_util_maildir_mkmdir */
|
2022-05-09 18:34:07 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-mkdir-01", test_maildir_mkdir_01);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-mkdir-02", test_maildir_mkdir_02);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-mkdir-03", test_maildir_mkdir_03);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-mkdir-04", test_maildir_mkdir_04);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-mkdir-05", test_maildir_mkdir_05);
|
2012-02-26 11:18:17 +01:00
|
|
|
|
2022-02-16 22:03:48 +01:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-determine-target-ok",
|
|
|
|
test_determine_target_ok);
|
2022-06-02 20:02:11 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-determine-target-fail",
|
|
|
|
test_determine_target_fail);
|
2022-02-16 22:03:48 +01:00
|
|
|
|
|
|
|
// /* get/set flags */
|
2022-05-31 22:43:13 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-01", test_maildir_get_new_path_01);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-02", test_maildir_get_new_path_02);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-custom",
|
|
|
|
test_maildir_get_new_path_custom);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-from-path",
|
|
|
|
test_maildir_from_path);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-06-28 22:24:22 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-link", test_maildir_link);
|
2011-09-12 19:33:06 +02:00
|
|
|
|
2022-06-29 21:19:26 +02:00
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-move-vanilla", test_maildir_move_vanilla);
|
|
|
|
g_test_add_func("/mu-maildir/mu-maildir-move-gio", test_maildir_move_gio);
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
return g_test_run();
|
2010-01-27 07:15:08 +01:00
|
|
|
}
|