Commit 04334427 043344271a4bb538d5a044c6757ea8617bb506ad by Sergey Poznyakoff

Improve maidag, add testsuite.

* configure.ac: Add maidag/tests
* maidag/Makefile.am (SUBDIRS): Add tests.
* maidag/deliver.c (make_tmp): Write a
message delimiter.
(is_remote_url, is_mailer_url): Remove.
(deliver_url): Allow for URLs without user name.
* maidag/lmtp.c (lmtp_set_privs): Empty group list
means do not switch to any groups.
* maidag/maidag.c (mda_mode): New variable.
(options): New option --mda.
(cb_group, cb2_group): Create the list even if it is empty.
(main): Handle --mda.

* maidag/tests/.gitignore: New file.
* maidag/tests/Makefile.am: New file.
* maidag/tests/atlocal.in: New file.
* maidag/tests/input.msg: New file.
* maidag/tests/lmtp.at: New file.
* maidag/tests/mda.at: New file.
* maidag/tests/testsuite.at: New file.
* maidag/tests/url-mbox.at: New file.
* maidag/tests/input.msg: New file.
1 parent 72b33638
......@@ -1214,6 +1214,7 @@ AC_ARG_WITH([mh-bindir],
AC_CONFIG_TESTDIR(libmailutils/tests)
AC_CONFIG_TESTDIR(testsuite)
AC_CONFIG_TESTDIR(frm/tests)
AC_CONFIG_TESTDIR(maidag/tests)
AC_CONFIG_TESTDIR(messages/tests)
AC_CONFIG_TESTDIR(readmsg/tests)
AC_CONFIG_TESTDIR(sieve/tests)
......@@ -1224,6 +1225,8 @@ AC_CONFIG_FILES([libmailutils/tests/Makefile
testsuite/atlocal
frm/tests/Makefile
frm/tests/atlocal
maidag/tests/Makefile
maidag/tests/atlocal
messages/tests/Makefile
messages/tests/atlocal
readmsg/tests/Makefile
......
......@@ -15,8 +15,7 @@
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
INCLUDES = -I${top_srcdir} @MU_APP_COMMON_INCLUDES@ @GUILE_INCLUDES@ \
@PYTHON_INCLUDES@
SUBDIRS = . tests
sbin_PROGRAMS=maidag
maidag_SOURCES=\
......@@ -51,6 +50,9 @@ maidag_LDADD = \
@MU_COMMON_LIBRARIES@\
@TCPWRAP_LIBRARIES@
INCLUDES = -I${top_srcdir} @MU_APP_COMMON_INCLUDES@ @GUILE_INCLUDES@ \
@PYTHON_INCLUDES@
install-exec-hook:
for i in $(sbin_PROGRAMS); do\
chown root:mail $(DESTDIR)$(sbindir)/$$i;\
......
......@@ -90,7 +90,9 @@ make_tmp (const char *from)
free (buf);
rc = mu_stream_copy (out, in, 0, NULL);
if (rc == 0)
/* Write out message delimiter */
mu_stream_write (out, "\n", 1, NULL);
mu_stream_destroy (&in);
if (rc)
{
......@@ -347,26 +349,6 @@ deliver_to_user (mu_mailbox_t mbox, mu_message_t msg,
return failed ? exit_code : 0;
}
static int
is_remote_url (mu_url_t url)
{
const char *scheme;
int rc = mu_url_sget_scheme (url, &scheme);
return rc == 0 && strncmp (scheme, "remote+", 7) == 0;
}
static int
is_mailer_url (mu_url_t url)
{
mu_record_t record = NULL;
int (*pfn) (mu_mailer_t) = NULL;
return mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE,
&record, NULL) == 0
&& mu_record_get_mailer (record, &pfn) == 0
&& pfn;
}
int
deliver_url (mu_url_t url, mu_message_t msg, const char *name, char **errp)
{
......@@ -491,18 +473,7 @@ deliver (mu_message_t msg, char *dest_id, char **errp)
}
status = mu_url_sget_user (url, &name);
if (status == MU_ERR_NOENT)
{
if (!is_mailer_url (url) && !is_remote_url (url))
{
maidag_error (_("no user name"));
if (errp)
asprintf (errp, "no such user");
exit_code = EX_NOUSER;
return EX_NOUSER;
}
else
name = NULL;
}
name = NULL;
else if (status)
{
maidag_error (_("%s: cannot get user name from url: %s"),
......
......@@ -607,7 +607,14 @@ lmtp_set_privs ()
mu_iterator_t itr;
int rc;
mu_list_count (lmtp_groups, &size);
rc = mu_list_count (lmtp_groups, &size);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_list_count", NULL, rc);
return EX_UNAVAILABLE;
}
if (size == 0)
return 0; /* nothing to do */
gidset = calloc (size, sizeof (gidset[0]));
if (!gidset)
{
......
......@@ -18,6 +18,8 @@
#include "maidag.h"
int mda_mode; /* Force local MDA mode even if not started as
root */
int multiple_delivery; /* Don't return errors when delivering to multiple
recipients */
int ex_quota_tempfail; /* Return temporary failure if mailbox quota is
......@@ -74,6 +76,7 @@ static char args_doc[] = N_("[recipient...]");
#define FOREGROUND_OPTION 260
#define URL_OPTION 261
#define TRANSCRIPT_OPTION 262
#define MDA_OPTION 263
static struct argp_option options[] =
{
......@@ -87,6 +90,8 @@ static struct argp_option options[] =
{ "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
N_("runs in daemon mode with a maximum of NUMBER children"), GRID + 1 },
{ "url", URL_OPTION, 0, 0, N_("deliver to given URLs"), GRID + 1 },
{ "mda", MDA_OPTION, 0, 0, N_("force MDA mode even if not started as root"),
GRID + 1 },
{ "from", 'f', N_("EMAIL"), 0,
N_("specify the sender's name"), GRID + 1 },
{ NULL, 'r', NULL, OPTION_ALIAS, NULL },
......@@ -216,6 +221,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
mu_argp_node_list_new (lst, "listen", arg);
break;
case MDA_OPTION:
mda_mode = 1;
break;
case TRANSCRIPT_OPTION:
maidag_transcript = 1;
break;
......@@ -292,23 +301,25 @@ cb_debug (mu_debug_t debug, void *data, mu_config_value_t *val)
static int
cb2_group (mu_debug_t debug, const char *gname, void *data)
{
mu_list_t *plist = data;
mu_list_t list = data;
struct group *group;
if (!*plist)
mu_list_create (plist);
group = getgrnam (gname);
if (!group)
mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("unknown group: %s"), gname);
else
mu_list_append (*plist, (void*)group->gr_gid);
mu_list_append (list, (void*)group->gr_gid);
return 0;
}
static int
cb_group (mu_debug_t debug, void *data, mu_config_value_t *arg)
{
return mu_cfg_string_value_cb (debug, arg, cb2_group, data);
mu_list_t *plist = data;
if (!*plist)
mu_list_create (plist);
return mu_cfg_string_value_cb (debug, arg, cb2_group, *plist);
}
static struct mu_kwd forward_checks[] = {
......@@ -540,9 +551,11 @@ main (int argc, char *argv[])
exit (EX_CONFIG);
current_uid = getuid ();
if (!lmtp_mode && current_uid == 0)
mda_mode = 1;
if (log_to_stderr == -1)
log_to_stderr = url_option || (!lmtp_mode && (current_uid != 0));
log_to_stderr = url_option || (!lmtp_mode && !mda_mode);
mu_diag_get_debug (&debug);
if (!log_to_stderr)
......@@ -571,7 +584,7 @@ main (int argc, char *argv[])
}
else
{
if (current_uid)
if (!mda_mode)
{
if (url_option)
{
......@@ -582,7 +595,7 @@ main (int argc, char *argv[])
static char *s_argv[2];
struct mu_auth_data *auth = mu_get_auth_by_uid (current_uid);
if (!current_uid)
if (!auth)
{
mu_error (_("cannot get username"));
return EX_UNAVAILABLE;
......
atconfig
atlocal
package.m4
testsuite
testsuite.dir
testsuite.log
# This file is part of GNU Mailutils.
# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 input.msg
DISTCLEANFILES = atconfig $(check_SCRIPTS)
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
## ------------ ##
## package.m4. ##
## ------------ ##
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
$(AM_V_GEN){ \
echo '# Signature of the current package.'; \
echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
} >$(srcdir)/package.m4
#
## ------------ ##
## Test suite. ##
## ------------ ##
TESTSUITE_AT = \
lmtp.at\
mda.at\
testsuite.at\
url-mbox.at
TESTSUITE = $(srcdir)/testsuite
M4=m4
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): package.m4 $(TESTSUITE_AT) $(top_srcdir)/testsuite/testsuite.inc
$(AM_V_GEN)$(AUTOTEST) -I $(srcdir) -I $(top_srcdir)/testsuite testsuite.at -o $@.tmp
$(AM_V_at)mv $@.tmp $@
atconfig: $(top_builddir)/config.status
cd $(top_builddir) && ./config.status tests/$@
clean-local:
@test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
check-local: atconfig atlocal $(TESTSUITE)
@$(SHELL) $(TESTSUITE)
# Run the test suite on the *installed* tree.
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
# @configure_input@ -*- shell-script -*-
# Configurable variable values for Mailutils test suite.
# Copyright (C) 2004, 2010 Free Software Foundation, Inc.
PATH=@abs_builddir@:@abs_top_builddir@/maidag:$top_srcdir:$srcdir:$PATH
From: "Lemuel Gulliver, esq." <gulliver@example.net>
To: root
Subject: Travels into several remote Nations of the World
A LETTER from Capt. Gulliver, to his Cousin Sympson
I HOPE you will be ready to own publickly, whenever you shall be called
to it, that by your great and frequent Urgency you prevailed on me to
publish a very loose and uncorrect Account of my Travels; with Direction
to hire some young Gentlemen of either University to put them in Order,
and correct the Style, as my Cousin Dampier did by my Advice, in his
Book called A Voyage round the World. But I do not remember I gave you
Power to consent that any thing should be omitted, and much less that any
thing should be inserted: therefore, as to the latter, I do here renounce
every thing of that Kind; particularly a Paragraph about her Majesty the
late Queen Anne, of most pious and glorious Memory; although I did
reverence and esteem her more than any of human Species. But you, or
your Interpolator, ought to have considered, that as it was not my
Inclination, so was it not decent to praise any Animal of our Composition
before my Master Houyhnhnm: And besides the Fact was altogether false;
for to my Knowledge, being in England during some Part of her Majesty's
Reign, she did govern by a chief Minister; nay, even by two successively;
the first whereof was the Lord of Godolphin, and the second the Lord of
Oxford; so that you have made me say the thing that was not. Likewise, in
the Account of the Academy of Projectors, and several Passages of my
Discourse to my Master Houyhnhnm, you have either omitted some
material Circumstances, or minced or changed them in such a Manner, that
I do hardly know mine own Work. When I formerly hinted to you
something of this in a Letter, you were pleased to answer that you were
afraid of giving Offense; that People in Power were very watchful over the
Press, and apt not only to interpret, but to punish every thing which looked
like an Innuendo (as I think you called it.) But pray, how could that which
I spoke so many Years ago, and at about five Thousand leagues distance, in
another Reign, be applied to any of the Yahoos who now are said to govern
the Herd; especially at a time when I little thought on or feared the
Unhappiness of living under them. Have not I the most reason to complain,
when I see these very Yahoos carried by Houyhnhnms in a Vehicle, as if
these were Brutes, and those the rational Creatures? And indeed, to avoid
so monstrous and detestable a Sight was one principal Motive of my
Retirement hither.
Thus much I thought proper to tell you in Relation to yourself, and to the
Trust I reposed in you.
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils 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.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([LMTP mode])
AT_KEYWORDS([maidag lmtp])
m4_pushdef([tocrlf],[dnl
$abs_top_builddir/libmailutils/tests/fltst crlf encode read])
AT_CHECK([
AT_DATA([session_start],[LHLO localhost
MAIL FROM:<gulliver@example.net>
RCPT TO:<root@localhost>
DATA
])
AT_DATA([session_end],[.
QUIT
])
echo ENVELOPE > expout
cat $abs_top_srcdir/maidag/tests/input.msg >> expout
echo "" >> expout
cat session_start $abs_top_srcdir/maidag/tests/input.msg session_end | tocrlf > session || exit $?
mkdir spool
maidag MAIDAG_OPTIONS --set 'group=()' --lmtp < session >transcript || exit $?
sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/root
cat transcript | tr -d '\r' | sed '/...-/d;s/ .*//' >&2
],
[0],
[expout],
[220
250
250
250
354
250
221
])
AT_CLEANUP
m4_popdef([tocrlf])
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils 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.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([MDA mode])
AT_KEYWORDS([maidag mda0])
AT_CHECK([
echo ENVELOPE > expout
cat $abs_top_srcdir/maidag/tests/input.msg >> expout
echo "" >> expout
mkdir spool
maidag MAIDAG_OPTIONS --mda --from gulliver@example.net root < dnl
$abs_top_srcdir/maidag/tests/input.msg || exit $?
sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/root
],
[0],
[expout])
AT_CLEANUP
#
AT_SETUP([MDA mode, explicit envelope])
AT_KEYWORDS([maidag mda1])
AT_CHECK([
echo "From gulliver Thu Oct 7 19:10:57 2010" > expout
cat $abs_top_srcdir/maidag/tests/input.msg >> expout
mkdir spool
maidag MAIDAG_OPTIONS --mda --from gulliver@example.net root < expout || exit $?
echo "" >> expout
cat spool/root
],
[0],
[expout])
AT_CLEANUP
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils 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.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
m4_include([testsuite.inc])
m4_define([MAIDAG_OPTIONS],[dnl
--no-site-config dnl
--no-user-config dnl
--set '|mailbox|mailbox-pattern='`pwd`/spool/'${user}' dnl
--set .auth.authorization=system dnl
--stderr])
AT_INIT
AT_TESTED([maidag])
MUT_VERSION(maidag)
m4_include([mda.at])
m4_include([lmtp.at])
m4_include([url-mbox.at])
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GNU Mailutils 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.
#
# GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([URL mode])
AT_KEYWORDS([maidag url-mbox url])
AT_CHECK([
echo ENVELOPE > expout
cat $abs_top_srcdir/maidag/tests/input.msg >> expout
echo "" >> expout
mkdir spool
maidag MAIDAG_OPTIONS --from 'gulliver@example.net' --url mbox:spool/out < dnl
$abs_top_srcdir/maidag/tests/input.msg || exit $?
sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/out
],
[0],
[expout])
AT_CLEANUP
\ No newline at end of file