summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-07-15 23:19:52 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-07-15 23:19:52 +0300
commitf0a5ff382b99f39b5a4bc6da7b991390762e879a (patch)
treeee56929866a0378ccbb81c1aaadf496b7e64ad31
parenta0f754eb818dd2561ba825f1ff80df0f61652f40 (diff)
downloadmailutils-f0a5ff382b99f39b5a4bc6da7b991390762e879a.tar.gz
mailutils-f0a5ff382b99f39b5a4bc6da7b991390762e879a.tar.bz2
Test multiple transmissions over a single SMTP mailer
* configure.ac: Configure testsuite in libproto/mailer/tests. * examples/mta.c: New option -c (continuous reception). (mta_smtp): Continue accepting connections if -c is given. * libproto/mailer/Makefile.am: Add tests. * libproto/mailer/tests/.gitignore: New file. * libproto/mailer/tests/Makefile.am: New file. * libproto/mailer/tests/atlocal.in: New file. * libproto/mailer/tests/sendm.c: New file. * libproto/mailer/tests/sends.c: New file. * libproto/mailer/tests/seqsend.at: New file. * libproto/mailer/tests/testsuite.at: New file.
-rw-r--r--configure.ac1
-rw-r--r--examples/mta.c27
-rw-r--r--libproto/mailer/Makefile.am3
-rw-r--r--libproto/mailer/tests/.gitignore7
-rw-r--r--libproto/mailer/tests/Makefile.am28
-rw-r--r--libproto/mailer/tests/atlocal.in5
-rw-r--r--libproto/mailer/tests/sendm.c95
-rw-r--r--libproto/mailer/tests/sends.c94
-rw-r--r--libproto/mailer/tests/seqsend.at90
-rw-r--r--libproto/mailer/tests/testsuite.at19
10 files changed, 355 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index c25c1ad78..117c888a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1374,6 +1374,7 @@ MU_CONFIG_TESTSUITE(comsat)
MU_CONFIG_TESTSUITE(imap4d)
MU_CONFIG_TESTSUITE(mimeview)
MU_CONFIG_TESTSUITE(libmu_scm)
+MU_CONFIG_TESTSUITE(libproto/mailer)
AM_MISSING_PROG([AUTOM4TE], [autom4te])
diff --git a/examples/mta.c b/examples/mta.c
index 4ffe054e0..588447871 100644
--- a/examples/mta.c
+++ b/examples/mta.c
@@ -77,20 +77,13 @@ int foreground = 0; /* Stay in the foreground (smtp mode) */
char *from_person = NULL; /* Set the name of the `from' person */
int read_recipients = 0; /* Read the message for recipients */
int dot = 1; /* Message is terminated by a lone dot on a line */
-
+int cont_mode = 0;
mu_address_t recipients = NULL;
/* FIXME: If finalize_option is set, mta should try to finalize
received messages the way sendmail does, i.e. to add To: or
- Cc: headers, if they are missing, etc. The code to do so is
- already included, but the modified message is not reproduced
- on diagnostic output because mta_send reads it from the stream,
- which does not reflect modifications to the header.
-
- Ideally, the mu_message_get_streamref function should notice the
- change in the header (and/or the body) and return a temporary
- stream, which will read the modified values. This is left as
- as TODO for a later time. 2010-09-29, Sergey */
+ Cc: headers, if they are missing, etc. The basic code to do so
+ is already included, but not enabled by default. */
int finalize_option = 0;
int mta_stdin (int argc, char **argv);
@@ -105,7 +98,7 @@ main (int argc, char **argv)
mu_set_program_name (argv[0]);
- while ((c = getopt (argc, argv, "b:f:p:to:")) != EOF)
+ while ((c = getopt (argc, argv, "b:cf:p:to:")) != EOF)
{
switch (c)
{
@@ -126,10 +119,14 @@ main (int argc, char **argv)
}
break;
+ case 'c':
+ cont_mode = 1;
+ break;
+
case 'f':
from_person = optarg;
break;
-
+
case 'p':
port = strtoul (optarg, NULL, 0);
break;
@@ -835,7 +832,7 @@ mta_smtp (int argc, char **argv)
if (!foreground)
alarm (60);
- while (1)
+ do
{
fd_set rfds;
struct sockaddr_in his_addr;
@@ -903,6 +900,8 @@ mta_smtp (int argc, char **argv)
mu_stream_set_buffer (flt, mu_buffer_line, 0);
ostream = flt;
rc = mu_iostream_create (&str, istream, ostream);
+ mu_stream_unref (istream);
+ mu_stream_unref (ostream);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_iostream_create", NULL, rc);
@@ -911,8 +910,8 @@ mta_smtp (int argc, char **argv)
mu_stream_set_buffer (str, mu_buffer_line, 0);
smtp (str);
mu_stream_destroy (&str);
- break;
}
+ while (cont_mode);
return 0;
}
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 1378f0321..05da8b299 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -54,3 +54,6 @@ libmu_mailer_la_SOURCES = \
smtp_starttls.c\
smtp_trace.c\
smtp_url.c
+
+SUBDIRS = . tests
+
diff --git a/libproto/mailer/tests/.gitignore b/libproto/mailer/tests/.gitignore
new file mode 100644
index 000000000..f434e42d5
--- /dev/null
+++ b/libproto/mailer/tests/.gitignore
@@ -0,0 +1,7 @@
+/atconfig
+/atlocal
+/sendm
+/sends
+/testsuite
+/testsuite.dir
+/testsuite.log
diff --git a/libproto/mailer/tests/Makefile.am b/libproto/mailer/tests/Makefile.am
new file mode 100644
index 000000000..4b654be5b
--- /dev/null
+++ b/libproto/mailer/tests/Makefile.am
@@ -0,0 +1,28 @@
+# This file is part of GNU Mailutils.
+# Copyright (C) 2019-2020 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/>.
+
+include $(top_srcdir)/testsuite/testsuite.am
+
+noinst_PROGRAMS = sends sendm
+AM_CPPFLAGS = $(MU_LIB_COMMON_INCLUDES)
+LDADD = \
+ $(MU_LIB_MAILER)\
+ $(MU_LIB_AUTH)\
+ $(MU_AUTHLIBS)\
+ $(MU_LIB_MAILUTILS)
+
+TESTSUITE_AT += \
+ seqsend.at
diff --git a/libproto/mailer/tests/atlocal.in b/libproto/mailer/tests/atlocal.in
new file mode 100644
index 000000000..882a58f1f
--- /dev/null
+++ b/libproto/mailer/tests/atlocal.in
@@ -0,0 +1,5 @@
+# @configure_input@ -*- shell-script -*-
+# Configurable variable values for Mailutils test suite.
+# Copyright (C) 2004-2020 Free Software Foundation, Inc.
+
+PATH=@abs_builddir@:$top_srcdir:$srcdir:$PATH
diff --git a/libproto/mailer/tests/sendm.c b/libproto/mailer/tests/sendm.c
new file mode 100644
index 000000000..09d002a7c
--- /dev/null
+++ b/libproto/mailer/tests/sendm.c
@@ -0,0 +1,95 @@
+/*
+ * NAME
+ * sendm - send a message sequentially to several recipients in multiple
+ * transactions
+ *
+ * SYNOPSIS
+ * sendm MAILER_URL FILE RCPT [RCPT...]
+ *
+ * DESCRIPTION
+ * Creates a mailer as requested by MAILER_URL. Reads email message
+ * from the FILE and sends it sequentially to each RCPT from the command
+ * line.
+ *
+ * A new transaction is opened for each message.
+ *
+ * LICENCE
+ * Copyright (C) 2020 Free Software Foundation, inc.
+ * License GPLv3+: GNU GPL version 3 or later
+ * <http://gnu.org/licenses/gpl.html>
+ * This is free software: you are free to change and redistribute it.
+ * There is NO WARRANTY, to the extent permitted by law.
+ */
+#include <config.h>
+#include <mailutils/mailutils.h>
+
+int
+main (int argc, char **argv)
+{
+ mu_mailer_t mailer;
+ mu_stream_t str;
+ mu_message_t msg;
+ char const *mailer_url, *filename;
+ int i;
+ int rc;
+ static struct mu_address hint = { .domain = "localhost" };
+ static int hflags = MU_ADDR_HINT_DOMAIN;
+
+ mu_set_program_name (argv[0]);
+ mu_register_all_mailer_formats ();
+
+ if (argc < 4)
+ abort ();
+ mailer_url = argv[1];
+ filename = argv[2];
+
+ if ((rc = mu_mailer_create (&mailer, mailer_url)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_create", mailer_url, rc);
+ return 1;
+ }
+
+ if ((rc = mu_file_stream_create (&str, filename, MU_STREAM_READ)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_file_stream_create", filename, rc);
+ return 1;
+ }
+
+ if ((rc = mu_stream_to_message (str, &msg)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_stream_to_message", filename, rc);
+ return 1;
+ }
+
+ mu_stream_unref (str);
+
+ for (i = 3; i < argc; i++)
+ {
+ mu_address_t rcpt;
+
+ if ((rc = mu_address_create_hint (&rcpt, argv[i], &hint, hflags)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_address_create", argv[i], rc);
+ return 1;
+ }
+
+ if ((rc = mu_mailer_open (mailer, MU_STREAM_RDWR)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_open", NULL, rc);
+ return 1;
+ }
+
+ if ((rc = mu_mailer_send_message (mailer, msg, NULL, rcpt)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_send_message", argv[i], rc);
+ return 1;
+ }
+
+ mu_mailer_close (mailer);
+
+ mu_address_destroy (&rcpt);
+ }
+ mu_message_unref (msg);
+ mu_mailer_destroy (&mailer);
+ return 0;
+}
diff --git a/libproto/mailer/tests/sends.c b/libproto/mailer/tests/sends.c
new file mode 100644
index 000000000..b7f59c18c
--- /dev/null
+++ b/libproto/mailer/tests/sends.c
@@ -0,0 +1,94 @@
+/*
+ * NAME
+ * sends - send a message sequentially to several recipients in single
+ * transaction
+ *
+ * SYNOPSIS
+ * sends MAILER_URL FILE RCPT [RCPT...]
+ *
+ * DESCRIPTION
+ * Creates a mailer as requested by MAILER_URL. Reads email message
+ * from the FILE and sends it sequentially to each RCPT from the command
+ * line.
+ *
+ * All messages are sent in a single transaction.
+ *
+ * LICENCE
+ * Copyright (C) 2020 Free Software Foundation, inc.
+ * License GPLv3+: GNU GPL version 3 or later
+ * <http://gnu.org/licenses/gpl.html>
+ * This is free software: you are free to change and redistribute it.
+ * There is NO WARRANTY, to the extent permitted by law.
+ */
+#include <config.h>
+#include <mailutils/mailutils.h>
+
+int
+main (int argc, char **argv)
+{
+ mu_mailer_t mailer;
+ mu_stream_t str;
+ mu_message_t msg;
+ char const *mailer_url, *filename;
+ int i;
+ int rc;
+ static struct mu_address hint = { .domain = "localhost" };
+ static int hflags = MU_ADDR_HINT_DOMAIN;
+
+ mu_set_program_name (argv[0]);
+ mu_register_all_mailer_formats ();
+
+ if (argc < 4)
+ abort ();
+ mailer_url = argv[1];
+ filename = argv[2];
+
+ if ((rc = mu_mailer_create (&mailer, mailer_url)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_create", mailer_url, rc);
+ return 1;
+ }
+
+ if ((rc = mu_file_stream_create (&str, filename, MU_STREAM_READ)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_file_stream_create", filename, rc);
+ return 1;
+ }
+
+ if ((rc = mu_stream_to_message (str, &msg)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_stream_to_message", filename, rc);
+ return 1;
+ }
+
+ mu_stream_unref (str);
+
+ if ((rc = mu_mailer_open (mailer, MU_STREAM_RDWR)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_open", NULL, rc);
+ return 1;
+ }
+
+ for (i = 3; i < argc; i++)
+ {
+ mu_address_t rcpt;
+
+ if ((rc = mu_address_create_hint (&rcpt, argv[i], &hint, hflags)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_address_create", argv[i], rc);
+ return 1;
+ }
+
+ if ((rc = mu_mailer_send_message (mailer, msg, NULL, rcpt)) != 0)
+ {
+ mu_diag_funcall (MU_DIAG_CRIT, "mu_mailer_send_message", argv[i], rc);
+ return 1;
+ }
+
+ mu_address_destroy (&rcpt);
+ }
+ mu_mailer_close (mailer);
+ mu_mailer_destroy (&mailer);
+ mu_message_unref (msg);
+ return 0;
+}
diff --git a/libproto/mailer/tests/seqsend.at b/libproto/mailer/tests/seqsend.at
new file mode 100644
index 000000000..6ef4a556e
--- /dev/null
+++ b/libproto/mailer/tests/seqsend.at
@@ -0,0 +1,90 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2019-2020 Free Software Foundation, Inc.
+#
+# This library is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This library 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([multiple sends])
+AT_DATA([msg],[dnl
+From: mailutils@localhost
+To: root@example.org
+Subject: test
+
+test message
+])
+
+AT_DATA([expout],
+[ENVELOPE FROM: <mailutils@localhost>
+ENVELOPE TO: <gray@example.org>
+ 0: From: mailutils@localhost
+ 1: To: root@example.org
+ 2: Subject: test
+ 3:
+ 4: test message
+END OF MESSAGE
+ENVELOPE FROM: <mailutils@localhost>
+ENVELOPE TO: <root@example.org>
+ 0: From: mailutils@localhost
+ 1: To: root@example.org
+ 2: Subject: test
+ 3:
+ 4: test message
+END OF MESSAGE
+ENVELOPE FROM: <mailutils@localhost>
+ENVELOPE TO: <wheel@example.com>
+ 0: From: mailutils@localhost
+ 1: To: root@example.org
+ 2: Subject: test
+ 3:
+ 4: test message
+END OF MESSAGE
+])
+
+AT_CHECK([
+MTA_DIAG=`pwd`/mta.diag
+export MTA_DIAG
+p=`$abs_top_builddir/examples/mta -bd -c`
+test $? -eq 0 || AT_SKIP_TEST
+set -- $p
+# $1 - pid, $2 - port
+sends smtp://127.0.0.1:$2 msg gray@example.org root@example.org wheel@example.com
+ec=$?
+kill $1 >/dev/null 2>&1
+if test $ec -eq 0; then
+ cat mta.diag
+fi
+exit $ec
+],
+[0],
+[expout])
+
+AT_CHECK([
+MTA_DIAG=`pwd`/mta.diag
+export MTA_DIAG
+p=`$abs_top_builddir/examples/mta -bd -c`
+test $? -eq 0 || AT_SKIP_TEST
+set -- $p
+# $1 - pid, $2 - port
+sendm smtp://127.0.0.1:$2 msg gray@example.org root@example.org wheel@example.com
+ec=$?
+kill $1 >/dev/null 2>&1
+if test $ec -eq 0; then
+ cat mta.diag
+fi
+exit $ec
+],
+[0],
+[expout])
+
+AT_CLEANUP
+
diff --git a/libproto/mailer/tests/testsuite.at b/libproto/mailer/tests/testsuite.at
new file mode 100644
index 000000000..af6a149b5
--- /dev/null
+++ b/libproto/mailer/tests/testsuite.at
@@ -0,0 +1,19 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2019-2020 Free Software Foundation, Inc.
+#
+# This library is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This library 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include([testsuite.inc])
+AT_INIT
+m4_include([seqsend.at])

Return to:

Send suggestions and report system problems to the System administrator.