2010-08-26 20:21:29 +02:00
|
|
|
/*
|
2020-11-03 08:58:59 +01:00
|
|
|
** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2010-08-26 20:21:29 +02: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,
|
2012-03-19 19:49:19 +01:00
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
2010-08-26 20:21:29 +02:00
|
|
|
*/
|
|
|
|
|
2010-12-03 19:45:01 +01:00
|
|
|
#if HAVE_CONFIG_H
|
2010-08-26 20:21:29 +02:00
|
|
|
#include "config.h"
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
2020-11-03 08:58:59 +01:00
|
|
|
#include "test-mu-common.hh"
|
2020-11-28 09:15:49 +01:00
|
|
|
#include "mu-msg.hh"
|
2019-12-16 20:44:35 +01:00
|
|
|
#include "utils/mu-str.h"
|
2022-02-19 17:57:50 +01:00
|
|
|
#include "utils/mu-utils.hh"
|
2010-08-26 20:21:29 +02:00
|
|
|
|
2020-11-28 09:15:49 +01:00
|
|
|
using namespace Mu;
|
|
|
|
|
2012-08-09 10:46:00 +02:00
|
|
|
static MuMsg*
|
2021-10-20 11:18:15 +02:00
|
|
|
get_msg(const char* path)
|
2012-08-09 10:46:00 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GError* err;
|
|
|
|
MuMsg* msg;
|
2012-08-09 10:46:00 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_test_verbose())
|
|
|
|
g_print(">> %s\n", path);
|
2012-08-09 10:46:00 +02:00
|
|
|
|
|
|
|
err = NULL;
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = mu_msg_new_from_file(path, NULL, &err);
|
2012-08-09 10:46:00 +02:00
|
|
|
|
|
|
|
if (!msg) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_printerr("failed to load %s: %s\n",
|
2022-03-20 13:12:41 +01:00
|
|
|
path,
|
|
|
|
err ? err->message : "something went wrong");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_clear_error(&err);
|
|
|
|
g_assert(0);
|
2012-08-09 10:46:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2010-08-26 20:21:29 +02:00
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_01(void)
|
2010-08-26 20:21:29 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1220863042.12663_1.mindcrime!2,S");
|
|
|
|
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "Donald Duck <gcc-help@gcc.gnu.org>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "gcc include search order");
|
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "Mickey Mouse <anon@example.com>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_msgid(msg),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"3BE9E6535E3029448670913581E7A1A20D852173@"
|
|
|
|
"emss35m06.us.lmco.com");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr(mu_msg_get_header(msg, "Mailing-List"),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"contact gcc-help-help@gcc.gnu.org; run by ezmlm");
|
|
|
|
g_assert_true(mu_msg_get_prio(msg) == Priority::Normal);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 1217530645);
|
2022-03-20 13:12:41 +01:00
|
|
|
|
2022-02-19 17:57:50 +01:00
|
|
|
const auto contacts{mu_msg_get_contacts(msg)};
|
|
|
|
g_assert_cmpuint(contacts.size(), == , 2);
|
|
|
|
g_assert_true(contacts[0].name == "Mickey Mouse");
|
|
|
|
g_assert_true(contacts[0].email == "anon@example.com");
|
|
|
|
g_assert_true(contacts[1].name == "Donald Duck");
|
|
|
|
g_assert_true(contacts[1].email == "gcc-help@gcc.gnu.org");
|
2022-03-20 13:12:41 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2010-08-26 20:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_02(void)
|
2010-08-26 20:21:29 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1220863087.12663_19.mindcrime!2,S");
|
|
|
|
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "help-gnu-emacs@gnu.org");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "Re: Learning LISP; Scheme vs elisp.");
|
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "anon@example.com");
|
|
|
|
g_assert_cmpstr(mu_msg_get_msgid(msg), ==, "r6bpm5-6n6.ln1@news.ducksburg.com");
|
|
|
|
g_assert_cmpstr(mu_msg_get_header(msg, "Errors-To"),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"help-gnu-emacs-bounces+xxxx.klub=gmail.com@gnu.org");
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::Low);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 1218051515);
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2022-02-19 17:57:50 +01:00
|
|
|
const auto contacts{mu_msg_get_contacts(msg)};
|
|
|
|
g_assert_cmpuint(contacts.size(), == , 2);
|
|
|
|
g_assert_true(contacts[0].name.empty());
|
|
|
|
g_assert_true(contacts[0].email == "anon@example.com");
|
|
|
|
g_assert_true(contacts[1].name.empty());
|
|
|
|
g_assert_true(contacts[1].email == "help-gnu-emacs@gnu.org");
|
|
|
|
|
2022-03-20 13:12:41 +01:00
|
|
|
g_print("flags: %s\n", Mu::flags_to_string(mu_msg_get_flags(msg)).c_str());
|
|
|
|
g_assert_true(mu_msg_get_flags(msg) == (Flags::Seen|Flags::MailingList));
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2010-09-10 19:37:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_03(void)
|
2010-09-10 19:37:06 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
const GSList* params;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1283599333.1840_11.cthulhu!2,");
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "Bilbo Baggins <bilbo@anotherexample.com>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "Greetings from Lothlórien");
|
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "Frodo Baggins <frodo@example.com>");
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::Normal);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 0);
|
|
|
|
g_assert_cmpstr(mu_msg_get_body_text(msg, MU_MSG_OPTION_NONE),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
|
2021-10-20 11:18:15 +02:00
|
|
|
|
|
|
|
params = mu_msg_get_body_text_content_type_parameters(msg, MU_MSG_OPTION_NONE);
|
|
|
|
g_assert_cmpuint(g_slist_length((GSList*)params), ==, 2);
|
|
|
|
|
|
|
|
g_assert_cmpstr((char*)params->data, ==, "charset");
|
2016-12-18 17:16:02 +01:00
|
|
|
params = g_slist_next(params);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr((char*)params->data, ==, "UTF-8");
|
2022-03-20 13:12:41 +01:00
|
|
|
g_assert_true(mu_msg_get_flags(msg) == (Flags::Unread));
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2010-08-26 20:21:29 +02:00
|
|
|
}
|
|
|
|
|
2010-11-20 17:41:57 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_04(void)
|
2010-11-20 17:41:57 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/mail5");
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "George Custer <gac@example.com>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "pics for you");
|
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "Sitting Bull <sb@example.com>");
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::Normal);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 0);
|
2022-02-16 21:06:00 +01:00
|
|
|
g_assert_true(mu_msg_get_flags(msg) ==
|
2022-03-20 13:12:41 +01:00
|
|
|
(Flags::HasAttachment|Flags::Unread));
|
2022-02-16 21:06:00 +01:00
|
|
|
|
|
|
|
g_assert_true(mu_msg_get_flags(msg) ==
|
2022-03-20 13:12:41 +01:00
|
|
|
(Flags::HasAttachment|Flags::Unread));
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2010-11-20 17:41:57 +01:00
|
|
|
}
|
|
|
|
|
2012-05-20 09:57:23 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_multimime(void)
|
2012-05-20 09:57:23 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
2012-05-20 09:57:23 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/multimime!2,FS");
|
2012-05-20 09:57:23 +02:00
|
|
|
/* ie., are text parts properly concatenated? */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "multimime");
|
|
|
|
g_assert_cmpstr(mu_msg_get_body_text(msg, MU_MSG_OPTION_NONE), ==, "abcdef");
|
2022-02-16 21:06:00 +01:00
|
|
|
g_assert_true(mu_msg_get_flags(msg) ==
|
2022-03-20 13:12:41 +01:00
|
|
|
(Flags::HasAttachment|Flags::Flagged|Flags::Seen));
|
2022-02-16 21:06:00 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2012-05-20 09:57:23 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 14:04:18 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_flags(void)
|
2012-06-01 14:04:18 +02:00
|
|
|
{
|
|
|
|
unsigned u;
|
|
|
|
|
|
|
|
struct {
|
2022-02-16 21:06:00 +01:00
|
|
|
const char* path;
|
2022-03-20 13:12:41 +01:00
|
|
|
Flags flags;
|
2021-10-20 11:18:15 +02:00
|
|
|
} msgflags[] = {{MU_TESTMAILDIR4 "/multimime!2,FS",
|
2022-03-20 13:12:41 +01:00
|
|
|
(Flags::Flagged | Flags::Seen |
|
|
|
|
Flags::HasAttachment)},
|
|
|
|
{MU_TESTMAILDIR4 "/special!2,Sabc",
|
|
|
|
(Flags::Seen|Flags::HasAttachment)}
|
2012-06-01 14:04:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (u = 0; u != G_N_ELEMENTS(msgflags); ++u) {
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
g_assert((msg = get_msg(msgflags[u].path)));
|
2022-02-16 21:06:00 +01:00
|
|
|
const auto flags{mu_msg_get_flags(msg)};
|
2022-03-20 13:12:41 +01:00
|
|
|
//g_print("flags: %s\n", Mu::flags_to_string(flags).c_str());
|
2022-02-16 21:06:00 +01:00
|
|
|
g_assert_true(flags == msgflags[u].flags);
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2012-06-01 14:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 20:21:10 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_umlaut(void)
|
2011-05-18 20:21:10 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1305664394.2171_402.cthulhu!2,");
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "Helmut Kröger <hk@testmu.xxx>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg), ==, "Motörhead");
|
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "Mü <testmu@testmu.xx>");
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::Normal);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 0);
|
|
|
|
|
|
|
|
mu_msg_unref(msg);
|
2011-05-18 20:21:10 +02:00
|
|
|
}
|
|
|
|
|
2011-06-23 23:24:04 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_references(void)
|
2011-06-23 23:24:04 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
const GSList* refs;
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1305664394.2171_402.cthulhu!2,");
|
2011-06-23 23:24:04 +02:00
|
|
|
refs = mu_msg_get_references(msg);
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(g_slist_length((GSList*)refs), ==, 4);
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "non-exist-01@msg.id");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "non-exist-02@msg.id");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "non-exist-03@msg.id");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "non-exist-04@msg.id");
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2011-06-23 23:24:04 +02:00
|
|
|
}
|
|
|
|
|
2011-06-30 22:43:08 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_references_dups(void)
|
2011-06-30 22:43:08 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
const GSList* refs;
|
|
|
|
const char* mlist;
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/1252168370_3.14675.cthulhu!2,S");
|
2011-06-30 22:43:08 +02:00
|
|
|
refs = mu_msg_get_references(msg);
|
|
|
|
|
|
|
|
/* make sure duplicate msg-ids are filtered out */
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(g_slist_length((GSList*)refs), ==, 6);
|
|
|
|
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "439C1136.90504@euler.org");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "4399DD94.5070309@euler.org");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "20051209233303.GA13812@gauss.org");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "439B41ED.2080402@euler.org");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "439A1E03.3090604@euler.org");
|
|
|
|
refs = g_slist_next(refs);
|
|
|
|
g_assert_cmpstr((char*)refs->data, ==, "20051211184308.GB13513@gauss.org");
|
|
|
|
|
|
|
|
mlist = mu_msg_get_mailing_list(msg);
|
|
|
|
g_assert_cmpstr(mlist, ==, "Example of List Id");
|
|
|
|
|
|
|
|
mu_msg_unref(msg);
|
2012-03-19 19:49:19 +01:00
|
|
|
}
|
2011-06-23 23:24:04 +02:00
|
|
|
|
2012-12-28 11:50:02 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_references_many(void)
|
2012-12-28 11:50:02 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
unsigned u;
|
2012-12-28 11:50:02 +01:00
|
|
|
const GSList *refs, *cur;
|
2021-10-20 11:18:15 +02:00
|
|
|
const char* expt_refs[] = {
|
2022-03-20 13:12:41 +01:00
|
|
|
"e9065dac-13c1-4103-9e31-6974ca232a89@t15g2000prt.googlegroups.com",
|
|
|
|
"87hbblwelr.fsf@sapphire.mobileactivedefense.com",
|
|
|
|
"pql248-4va.ln1@wilbur.25thandClement.com",
|
|
|
|
"ikns6r$li3$1@Iltempo.Update.UU.SE",
|
|
|
|
"8762s0jreh.fsf@sapphire.mobileactivedefense.com",
|
|
|
|
"ikqqp1$jv0$1@Iltempo.Update.UU.SE",
|
|
|
|
"87hbbjc5jt.fsf@sapphire.mobileactivedefense.com",
|
|
|
|
"ikr0na$lru$1@Iltempo.Update.UU.SE",
|
|
|
|
"tO8cp.1228$GE6.370@news.usenetserver.com",
|
|
|
|
"ikr6ks$nlf$1@Iltempo.Update.UU.SE",
|
|
|
|
"8ioh48-8mu.ln1@leafnode-msgid.gclare.org.uk"};
|
2021-10-20 11:18:15 +02:00
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR2 "/bar/cur/181736.eml");
|
2012-12-28 11:50:02 +01:00
|
|
|
refs = mu_msg_get_references(msg);
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(G_N_ELEMENTS(expt_refs), ==, g_slist_length((GSList*)refs));
|
2012-12-28 11:50:02 +01:00
|
|
|
|
|
|
|
for (cur = refs, u = 0; cur; cur = g_slist_next(cur), ++u) {
|
|
|
|
if (g_test_verbose())
|
2021-10-20 11:18:15 +02:00
|
|
|
g_print("%u. '%s' =? '%s'\n", u, (char*)cur->data, expt_refs[u]);
|
2012-12-28 11:50:02 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr((char*)cur->data, ==, expt_refs[u]);
|
2012-12-28 11:50:02 +01:00
|
|
|
}
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2012-12-28 11:50:02 +01:00
|
|
|
}
|
|
|
|
|
2011-06-15 23:49:30 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_tags(void)
|
2011-06-15 23:49:30 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
const GSList* tags;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/mail1");
|
|
|
|
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, "Julius Caesar <jc@example.com>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"Fere libenter homines id quod volunt credunt");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "John Milton <jm@example.com>");
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::High);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 1217530645);
|
|
|
|
|
|
|
|
tags = mu_msg_get_tags(msg);
|
|
|
|
g_assert_cmpstr((char*)tags->data, ==, "Paradise");
|
|
|
|
g_assert_cmpstr((char*)tags->next->data, ==, "losT");
|
|
|
|
g_assert_cmpstr((char*)tags->next->next->data, ==, "john");
|
|
|
|
g_assert_cmpstr((char*)tags->next->next->next->data, ==, "milton");
|
|
|
|
|
|
|
|
g_assert(!tags->next->next->next->next);
|
|
|
|
|
|
|
|
mu_msg_unref(msg);
|
2011-06-15 23:49:30 +02:00
|
|
|
}
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2011-06-08 07:33:30 +02:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_msg_comp_unix_programmer(void)
|
2011-06-08 07:33:30 +02:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
MuMsg* msg;
|
|
|
|
char* refs;
|
|
|
|
|
|
|
|
msg = get_msg(MU_TESTMAILDIR4 "/181736.eml");
|
|
|
|
g_assert_cmpstr(mu_msg_get_to(msg), ==, NULL);
|
|
|
|
g_assert_cmpstr(mu_msg_get_subject(msg),
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"Re: Are writes \"atomic\" to readers of the file?");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr(mu_msg_get_from(msg), ==, "Jimbo Foobarcuux <jimbo@slp53.sl.home>");
|
|
|
|
g_assert_cmpstr(mu_msg_get_msgid(msg), ==, "oktdp.42997$Te.22361@news.usenetserver.com");
|
|
|
|
|
|
|
|
refs = mu_str_from_list(mu_msg_get_references(msg), ',');
|
|
|
|
g_assert_cmpstr(refs,
|
2022-03-20 13:12:41 +01:00
|
|
|
==,
|
|
|
|
"e9065dac-13c1-4103-9e31-6974ca232a89@t15g2000prt"
|
|
|
|
".googlegroups.com,"
|
|
|
|
"87hbblwelr.fsf@sapphire.mobileactivedefense.com,"
|
|
|
|
"pql248-4va.ln1@wilbur.25thandClement.com,"
|
|
|
|
"ikns6r$li3$1@Iltempo.Update.UU.SE,"
|
|
|
|
"8762s0jreh.fsf@sapphire.mobileactivedefense.com,"
|
|
|
|
"ikqqp1$jv0$1@Iltempo.Update.UU.SE,"
|
|
|
|
"87hbbjc5jt.fsf@sapphire.mobileactivedefense.com,"
|
|
|
|
"ikr0na$lru$1@Iltempo.Update.UU.SE,"
|
|
|
|
"tO8cp.1228$GE6.370@news.usenetserver.com,"
|
|
|
|
"ikr6ks$nlf$1@Iltempo.Update.UU.SE,"
|
|
|
|
"8ioh48-8mu.ln1@leafnode-msgid.gclare.org.uk");
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(refs);
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2011-06-08 07:33:30 +02:00
|
|
|
//"jimbo@slp53.sl.home (Jimbo Foobarcuux)";
|
2022-02-13 13:32:10 +01:00
|
|
|
g_assert_true(mu_msg_get_prio(msg) /* 'low' */
|
2022-03-20 13:12:41 +01:00
|
|
|
== Priority::Normal);
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpuint(mu_msg_get_date(msg), ==, 1299603860);
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_unref(msg);
|
2011-06-08 07:33:30 +02:00
|
|
|
}
|
2011-06-15 23:49:30 +02:00
|
|
|
|
2019-12-16 20:44:35 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_str_prio_01(void)
|
2019-12-16 20:44:35 +01:00
|
|
|
{
|
2022-03-20 13:12:41 +01:00
|
|
|
g_assert_true(priority_name(Priority::Low) == "low");
|
|
|
|
g_assert_true(priority_name(Priority::Normal) == "normal");
|
|
|
|
g_assert_true(priority_name(Priority::High) == "high");
|
2019-12-16 20:44:35 +01:00
|
|
|
}
|
|
|
|
|
2022-02-13 13:32:10 +01:00
|
|
|
G_GNUC_UNUSED 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)
|
2019-12-16 20:44:35 +01:00
|
|
|
{
|
|
|
|
return FALSE; /* don't abort */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
test_mu_str_display_contact(void)
|
2019-12-16 20:44:35 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
int i;
|
2019-12-16 20:44:35 +01:00
|
|
|
struct {
|
2021-10-20 11:18:15 +02:00
|
|
|
const char* word;
|
|
|
|
const char* disp;
|
|
|
|
} words[] = {{"\"Foo Bar\" <aap@noot.mies>", "Foo Bar"},
|
2022-03-20 13:12:41 +01:00
|
|
|
{"Foo Bar <aap@noot.mies>", "Foo Bar"},
|
|
|
|
{"<aap@noot.mies>", "aap@noot.mies"},
|
|
|
|
{"foo@bar.nl", "foo@bar.nl"}};
|
2019-12-16 20:44:35 +01:00
|
|
|
|
|
|
|
for (i = 0; i != G_N_ELEMENTS(words); ++i)
|
2021-10-20 11:18:15 +02:00
|
|
|
g_assert_cmpstr(mu_str_display_contact_s(words[i].word), ==, words[i].disp);
|
2019-12-16 20:44:35 +01:00
|
|
|
}
|
|
|
|
|
2010-08-26 20:21:29 +02:00
|
|
|
int
|
2021-10-20 11:18:15 +02:00
|
|
|
main(int argc, char* argv[])
|
2010-08-26 20:21:29 +02:00
|
|
|
{
|
2011-05-19 21:24:12 +02:00
|
|
|
int rv;
|
2012-03-14 20:33:06 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
2011-05-19 21:24:12 +02:00
|
|
|
|
|
|
|
/* mu_msg_str_date */
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-msg/mu-msg-01", test_mu_msg_01);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-02", test_mu_msg_02);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-03", test_mu_msg_03);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-04", test_mu_msg_04);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-multimime", test_mu_msg_multimime);
|
2012-03-19 19:49:19 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-msg/mu-msg-flags", test_mu_msg_flags);
|
2019-12-16 20:44:35 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-msg/mu-msg-tags", test_mu_msg_tags);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-references", test_mu_msg_references);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-references_dups", test_mu_msg_references_dups);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-references_many", test_mu_msg_references_many);
|
2019-12-16 20:44:35 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-msg/mu-msg-umlaut", test_mu_msg_umlaut);
|
|
|
|
g_test_add_func("/mu-msg/mu-msg-comp-unix-programmer", test_mu_msg_comp_unix_programmer);
|
|
|
|
|
|
|
|
/* mu_str_prio */
|
|
|
|
g_test_add_func("/mu-str/mu-str-prio-01", test_mu_str_prio_01);
|
2019-12-16 20:44:35 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_test_add_func("/mu-str/mu-str-display_contact", test_mu_str_display_contact);
|
2019-12-16 20:44:35 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_log_set_handler(
|
|
|
|
NULL,
|
|
|
|
(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
|
|
|
|
(GLogFunc)black_hole,
|
|
|
|
NULL);
|
2010-11-27 15:07:24 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
rv = g_test_run();
|
2011-05-09 01:58:33 +02:00
|
|
|
|
2012-03-19 19:49:19 +01:00
|
|
|
return rv;
|
2010-08-26 20:21:29 +02:00
|
|
|
}
|