DIR *queuedir;
struct dirent *dp;
char *fromname, *toname, *reptoname, *from, *to, *repto;
- char *mailname = NULL;
char *ch;
struct stat st;
- int err = 0, qfd;
+ int errn = 0, qfd;
time_t t, bouncelife;
bool ret = true;
struct mail mail;
opendirat(ml->fd, qfd, queuedir, "queue");
while((dp = readdir(queuedir)) != NULL) {
- if(fstatat(qfd, dp->d_name, &st, 0) < 0) {
- log(" - Could not stat(queue/%s): %s",
- dp->d_name, strerror(errno));
- ret = false;
+ /* we might have deleted some files like the "mail.*" */
+ if(fstatat(qfd, dp->d_name, &st, 0) < 0)
continue;
- }
if(!S_ISREG(st.st_mode))
continue;
if(strchr(dp->d_name, '.')) {
- mailname = xstrdup(dp->d_name);
+ char *mailname = xstrdup(dp->d_name);
ch = strrchr(mailname, '.');
MY_ASSERT(ch);
*ch = '\0';
xasprintf(&toname, "%s.reciptto", dp->d_name);
xasprintf(&reptoname, "%s.reply-to", dp->d_name);
+ errn = 0;
from = ctrlvalue(qfd, fromname);
if (from == NULL)
- err = errno;
+ errn = errno;
to = ctrlvalue(qfd, toname);
- free(fromname);
- free(toname);
- if((from == NULL && err == ENOENT) ||
+ if((from == NULL && errn == ENOENT) ||
(to == NULL && errno == ENOENT)) {
/* only delete old files to avoid deleting
mail currently being sent */
unlinkat(qfd, reptoname, 0);
}
}
- free(mailname);
free(reptoname);
+ free(fromname);
+ free(toname);
continue;
}
-
repto = ctrlvalue(qfd, reptoname);
- free(reptoname);
/* before we try again, check and see if it's old */
bouncelife = ctrltimet(ml->ctrlfd, "bouncelife", BOUNCELIFE);
dp->d_name, strerror(errno));
ret = false;
}
- free(mailname);
+ /* avoid leaving orphans */
+ unlinkat(qfd, fromname, 0);
+ unlinkat(qfd, toname, 0);
+ unlinkat(qfd, reptoname, 0);
free(from);
free(to);
free(repto);
mail.to = to;
mail.from = from;
mail.replyto = repto;
- mail.fp = fopen(mailname, "r");
- if (send_single_mail(&mail, ml, false))
- save_queue(mailname, &mail);
- else
- unlink(mailname);
+ int mailfd = openat(qfd, dp->d_name, O_RDONLY);
+ mail.fp = fdopen(mailfd, "r");
+ if (mail.fp == NULL)
+ err(1, "merde");
+ if (send_single_mail(&mail, ml, false)) {
+ unlinkat(qfd, dp->d_name, 0);
+ unlinkat(qfd, fromname, 0);
+ unlinkat(qfd, toname, 0);
+ unlinkat(qfd, reptoname, 0);
+ }
+ free(reptoname);
+ free(fromname);
+ free(toname);
fclose(mail.fp);
}
. $(atf_get_srcdir)/test_env.sh
+mlmmjmaintd=$(command -v mlmmj-maintd)
+
tests_init \
nolongerbouncing \
discarded \
basics_9 \
basics_10 \
basics_11 \
- resend_requeue
+ resend_requeue \
+ resend_queue
nolongerbouncing_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
mkdir -p lists/ml/bounce
discarded_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
basics_0_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
basics_1_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_2_body()
{
test $(id -u) = 0 && atf_skip "Can only be run as non-root"
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_3_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_4_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_5_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_6_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_7_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_8_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_9_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_10_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
basics_11_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
digests_0_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
digests_1_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
digests_2_body()
{
test $(id -u) = 0 && atf_skip "Can only be run as non-root"
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
digests_3_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
digests_4_body()
{
test $(id -u) = 0 && atf_skip "Can only be run as non-root"
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml lists/ml
echo test@mlmmjtest > lists/ml/control/listaddress
unsub_bouncers_0_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_1_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo test@mlmmjtest > list/control/listaddress
unsub_bouncers_2_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo test@mlmmjtest > list/control/listaddress
unsub_bouncers_3_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo test@mlmmjtest > list/control/listaddress
unsub_bouncers_4_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
# filename should contain a = to be properly treated
unsub_bouncers_5_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_6_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_7_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
mkdir lists
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_8_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_9_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
unsub_bouncers_10_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
init_ml list
echo "test@test" > list/control/listaddress
resend_requeue_body()
{
- mlmmjmaintd=$(command -v mlmmj-maintd)
atf_check $srcdir/fakesmtpd
trap kill_fakesmtp EXIT TERM
init_ml list
atf_check -s exit:1 test -f mail-4.txt
atf_check -s exit:1 test -d list/requeue/1
}
+
+resend_queue_body()
+{
+ atf_check $srcdir/fakesmtpd
+ trap kill_fakesmtp EXIT TERM
+ init_ml list
+ echo "test@test" > list/control/listaddress
+ echo "25678" > list/control/smtpport
+ echo "heloname" > list/control/smtphelo
+ touch list/queue/file
+
+ # no .mailfrom, no.reciptto no.reply-to but recent
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:1 test -f mail-1.txt
+ atf_check -s exit:0 test -f list/queue/file
+
+ touch -t 000101010101 list/queue/file
+ # no .mailfrom, no.reciptto no.reply-to but recent
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:1 test -f mail-1.txt
+ atf_check -s exit:1 test -f list/queue/file
+
+ touch -t 000101010101 list/queue/file
+ echo "bla" > list/queue/file.mailfrom
+ # no.reciptto no.reply-to old recent
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:1 test -f mail-1.txt
+ atf_check -s exit:1 test -f list/queue/file
+ atf_check -s exit:1 test -f list/queue/file.mailfrom
+
+ touch -t 000101010101 list/queue/file
+ echo "bla" > list/queue/file.mailfrom
+ touch list/queue/file.reply-to
+ # no.reciptto no.reply-to old recent
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:1 test -f list/queue/file
+ atf_check -s exit:1 test -f list/queue/file.mailfrom
+ atf_check -s exit:1 test -f list/queue/file.reply-to
+
+ touch -t 000101010101 list/queue/file
+ echo "bla" > list/queue/file.mailfrom
+ echo "meh" > list/queue/file.reciptto
+ touch list/queue/file.reply-to
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:1 test -f list/queue/file
+ atf_check -s exit:1 test -f list/queue/file.mailfrom
+ atf_check -s exit:1 test -f list/queue/file.reciptto
+ atf_check -s exit:1 test -f list/queue/file.reply-to
+
+ touch list/queue/file
+ touch list/queue/file.mailfrom
+ echo "meh" > list/queue/file.reciptto
+ touch list/queue/file.reply-to
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:0 test -f list/queue/file
+ atf_check -s exit:0 test -f list/queue/file.mailfrom
+ atf_check -s exit:0 test -f list/queue/file.reciptto
+ atf_check -s exit:0 test -f list/queue/file.reply-to
+
+ touch list/queue/file
+ touch list/queue/file.mailfrom
+ touch list/queue/file.reciptto
+ touch list/queue/file.reply-to
+ atf_check $mlmmjmaintd -L list -F
+ atf_check -s exit:0 test -f list/queue/file
+ atf_check -s exit:0 test -f list/queue/file.mailfrom
+ atf_check -s exit:0 test -f list/queue/file.reciptto
+ atf_check -s exit:0 test -f list/queue/file.reply-to
+
+ # actually send the queued email
+ cat > list/queue/file <<EOF
+From: plop
+To: bla
+Subject: hey
+
+Body
+EOF
+ echo "bob@test1" > list/queue/file.mailfrom
+ echo "bob@test2" > list/queue/file.reciptto
+ rm list/queue/file.reply-to
+ atf_check $mlmmjmaintd -L list -F
+ cat > expected.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<bob@test1>\r
+RCPT TO:<bob@test2>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: hey\r
+\r
+Body\r
+\r
+.\r
+QUIT\r
+EOF
+ atf_check -o file:expected.txt cat mail-1.txt
+ atf_check -s exit:1 test -f mail-2.txt
+ atf_check -s exit:1 test -f list/queue/file
+ atf_check -s exit:1 test -f list/queue/file.mailfrom
+ atf_check -s exit:1 test -f list/queue/file.reciptto
+
+ # actually send the queued email with reply-to
+ cat > list/queue/file <<EOF
+From: plop
+To: bla
+Subject: hey
+
+Body
+EOF
+ echo "bob@test1" > list/queue/file.mailfrom
+ echo "bob@test2" > list/queue/file.reciptto
+ echo "jane@test2" > list/queue/file.reply-to
+ rm list/queue/file.reply-to
+ atf_check $mlmmjmaintd -L list -F
+ cat > expected.txt <<EOF
+EHLO heloname\r
+MAIL FROM:<bob@test1>\r
+RCPT TO:<bob@test2>\r
+DATA\r
+From: plop\r
+To: bla\r
+Subject: hey\r
+\r
+Body\r
+\r
+.\r
+QUIT\r
+EOF
+ atf_check -o file:expected.txt cat mail-2.txt
+ atf_check -s exit:1 test -f mail-3.txt
+ atf_check -s exit:1 test -f list/queue/file
+ atf_check -s exit:1 test -f list/queue/file.mailfrom
+ atf_check -s exit:1 test -f list/queue/file.reciptto
+ atf_check -s exit:1 test -f list/queue/file.reply-to
+}