Commit f5374bc2 f5374bc2ff9bb95dd94668eb8a5fb54c88c30f22 by Sergey Poznyakoff

send: fix draftfolder support; add testsuite

* examples/mta.c (mta_send): Don't print trailing spaces instead of
empty lines.
* mh/send.c: Redo draftfolder support.
(read_mts_profile): If MTSTAILOR environment variable is set,
it names the mtstailor file to use instead of the standard ones.
* mh/tests/send.at: New file.
* mh/tests/Makefile.am (TESTSUITE_AT): Add send.at
* mh/tests/testsuite.at (MH_SETUP): Set MTSTAILOR.
(MH_MTSTAILOR): New macro
Include send.at
1 parent edbe6c56
......@@ -348,7 +348,9 @@ mta_send (mu_message_t msg)
{
if (newline)
{
fprintf (diag, "%4lu: ", (unsigned long) line);
fprintf (diag, "%4lu:", (unsigned long) line);
if (buffer[i] != '\n')
fputc (' ', diag);
newline = 0;
}
fputc (buffer[i], diag);
......@@ -837,4 +839,3 @@ mta_smtp (int argc, char **argv)
return 0;
}
......
......@@ -101,7 +101,8 @@ struct mh_option mh_option[] = {
};
static int use_draft; /* Use the prepared draft */
static const char *draft_folder; /* Use this draft folder */
static const char *draftfolder; /* Use this draft folder */
static char *draftmessage = "cur";
static int reformat_recipients; /* --format option */
static int forward_notice; /* Forward the failure notice to the sender,
--forward flag */
......@@ -133,11 +134,6 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
break;
case ARG_ALIAS:
mh_alias_read (arg, 1);
break;
......@@ -156,17 +152,15 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_DRAFTFOLDER:
draft_folder = arg;
draftfolder = arg;
break;
case ARG_NODRAFTFOLDER:
draft_folder = NULL;
draftfolder = NULL;
break;
case ARG_DRAFTMESSAGE:
if (!draft_folder)
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
draftmessage = arg;
break;
case ARG_FILTER:
......@@ -295,7 +289,7 @@ check_file (char *name)
{
struct list_elt *elt;
mu_message_t msg;
char *file_name = mh_expand_name (draft_folder, name, 0);
char *file_name = mh_expand_name (draftfolder, name, 0);
msg = mh_file_to_message (NULL, file_name);
if (!msg)
......@@ -322,16 +316,23 @@ read_mts_profile ()
const char *p;
char *hostname = NULL;
int rc;
mu_property_t local_profile;
name = mh_expand_name (MHLIBDIR, "mtstailor", 0);
mts_profile = mh_read_property_file (name, 1);
name = getenv ("MTSTAILOR");
if (name)
mts_profile = mh_read_property_file (name, 1);
else
{
mu_property_t local_profile;
name = mh_expand_name (MHLIBDIR, "mtstailor", 0);
mts_profile = mh_read_property_file (name, 1);
name = mu_tilde_expansion ("~/.mtstailor", "/", NULL);
local_profile = mh_read_property_file (name, 1);
name = mu_tilde_expansion ("~/.mtstailor", "/", NULL);
local_profile = mh_read_property_file (name, 1);
mh_property_merge (mts_profile, local_profile);
mu_property_destroy (&local_profile);
mh_property_merge (mts_profile, local_profile);
mu_property_destroy (&local_profile);
}
rc = mu_property_aget_value (mts_profile, "localname", &hostname);
if (rc == MU_ERR_NOENT)
......@@ -343,7 +344,7 @@ read_mts_profile ()
exit (1);
}
}
else
else if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_aget_value", "localname", rc);
exit (1);
......@@ -738,42 +739,13 @@ _action_send (void *item, void *data)
return 0;
}
static int
do_send (int argc, char **argv)
{
int i, rc;
char *p;
/* Verify all arguments */
for (i = 0; i < argc; i++)
if (check_file (argv[i]))
return 1;
/* Process the mtstailor file and detach from the console if
required */
read_mts_profile ();
if (background && daemon (0, 0) < 0)
{
mu_error (_("cannot switch to background: %s"), mu_strerror (errno));
return 1;
}
/* Prepend url specifier to the folder dir. We won't need this
when the default format becomes configurable */
mu_asprintf (&p, "mh:%s", mu_folder_directory ());
mu_set_folder_directory (p);
free (p);
/* Finally, do the work */
rc = mu_list_do (mesg_list, _action_send, NULL);
return rc;
}
int
main (int argc, char **argv)
{
mu_mailbox_t mbox = NULL;
int index;
char *p;
int rc;
MU_APP_INIT_NLS ();
......@@ -786,42 +758,90 @@ main (int argc, char **argv)
argc -= index;
argv += index;
if (argc == 0)
if (draftfolder)
{
struct stat st;
static char *xargv[2];
if (draft_folder)
mh_msgset_t msgset;
mu_url_t url;
const char *path;
size_t i;
mbox = mh_open_folder (draftfolder, 1);
mh_msgset_parse (mbox, &msgset, argc, argv, draftmessage);
mu_mailbox_get_url (mbox, &url);
mu_url_sget_path (url, &path);
if ((rc = mu_list_create (&mesg_list)))
{
mu_error (_("cannot create message list: %s"), mu_strerror (rc));
exit (1);
}
for (i = 0; i < msgset.count; i++)
{
mh_msgset_t msgset;
mu_mailbox_t mbox;
mu_url_t url;
const char *path;
struct list_elt *elt;
size_t uid;
mbox = mh_open_folder (draft_folder, 1);
mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
mu_mailbox_get_url (mbox, &url);
mu_url_sget_path (url, &path);
xargv[0] = mu_make_file_name (path,
mu_umaxtostr (0, msgset.list[0]));
mu_mailbox_destroy (&mbox);
mh_msgset_free (&msgset);
elt = xmalloc (sizeof *elt);
mu_mailbox_get_message (mbox, msgset.list[i], &elt->msg);
mu_message_get_uid (elt->msg, &uid);
elt->file_name =
mu_make_file_name (path, mu_umaxtostr (0, uid));
rc = mu_list_append (mesg_list, elt);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc);
exit (1);
}
}
else
xargv[0] = mh_draft_name ();
if (stat (xargv[0], &st))
mh_msgset_free (&msgset);
}
else
{
int i;
if (argc == 0)
{
mu_diag_funcall (MU_DIAG_ERROR, "stat", xargv[0], errno);
return 1;
char *xargv[2];
struct stat st;
xargv[0] = mh_draft_name ();
if (stat (xargv[0], &st))
{
mu_diag_funcall (MU_DIAG_ERROR, "stat", xargv[0], errno);
return 1;
}
if (!use_draft && !mh_usedraft (xargv[0]))
exit (0);
xargv[1] = NULL;
argv = xargv;
argc = 1;
}
for (i = 0; i < argc; i++)
if (check_file (argv[i]))
return 1;
}
if (!use_draft && !mh_usedraft (xargv[0]))
exit (0);
xargv[1] = NULL;
argv = xargv;
argc = 1;
/* Process the mtstailor file and detach from the console if
required */
read_mts_profile ();
if (background && daemon (0, 0) < 0)
{
mu_error (_("cannot switch to background: %s"), mu_strerror (errno));
return 1;
}
return do_send (argc, argv);
/* Prepend url specifier to the folder dir. We won't need this
when the default format becomes configurable */
mu_asprintf (&p, "mh:%s", mu_folder_directory ());
mu_set_folder_directory (p);
free (p);
/* Finally, do the work */
rc = mu_list_do (mesg_list, _action_send, NULL);
mu_mailbox_destroy (&mbox);
return !!rc;
}
......
......@@ -55,6 +55,7 @@ TESTSUITE_AT = \
mhseq.at\
pick.at\
scan.at\
send.at\
refile.at\
repl.at\
rmf.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/>.
m4_pushdef([MH_KEYWORDS],[send])
MH_CHECK([send file],[send00 send-file],[
MH_MTSTAILOR()
AT_DATA([input],
[From: mhtester@example.net
To: gray@example.net
Subject: Send file test
------
Message body
])
send ./input || exit $?
sed 's/: Date: .*/: Date: now/' $MTA_DIAG
find . -name ,input
],
[0],
[ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.net>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.net>
4: Subject: Send file test
5:
6: Message body
END OF MESSAGE
./,input
])
MH_CHECK([send files],[send01 send-files],[
MH_MTSTAILOR()
AT_DATA([input.1],
[From: mhtester@example.net
To: gray@example.net
Subject: Send file test 1
------
Message body 1
])
AT_DATA([input.2],
[From: mhtester@example.net
To: gray@example.org
Subject: Send file test 2
------
Message body 2
])
MTA_APPEND=1
export MTA_APPEND
send ./input.1 ./input.2 || exit $?
sed 's/: Date: .*/: Date: now/' $MTA_DIAG
find . -name ',input.[[12]]'
],
[0],
[ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.net>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.net>
4: Subject: Send file test 1
5:
6: Message body 1
END OF MESSAGE
ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.org>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.org>
4: Subject: Send file test 2
5:
6: Message body 2
END OF MESSAGE
./,input.1
./,input.2
])
MH_CHECK([send -draft],[send02 send-draft],[
MH_MTSTAILOR()
AT_DATA([Mail/draft],
[From: mhtester@example.net
To: gray@example.net
Subject: Send file test
------
Message body
])
send -draft || exit $?
sed 's/: Date: .*/: Date: now/' $MTA_DIAG
echo == Mail/,draft ==
cat Mail/,draft
],
[0],
[ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.net>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.net>
4: Subject: Send file test
5:
6: Message body
END OF MESSAGE
== Mail/,draft ==
From: mhtester@example.net
To: gray@example.net
Subject: Send file test
------
Message body
])
MH_CHECK([send -draftfolder],
[send03 send-draftfolder draftfolder draftmessage],[
MH_MTSTAILOR()
mkdir Mail/drafts
AT_DATA([Mail/drafts/2],
[From: mhtester@example.net
To: gray@example.net
Subject: Draftfolder test
Message body
])
echo "cur: 2" > Mail/drafts/.mh_sequences
send -draftfolder +drafts || echo $?
sed 's/: Date: .*/: Date: now/' $MTA_DIAG
],
[0],
[ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.net>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.net>
4: Subject: Draftfolder test
5:
6: Message body
END OF MESSAGE
])
MH_CHECK([send -draftmessage],
[send04 send-draftmessage draftfolder draftmessage],[
MH_MTSTAILOR()
mkdir Mail/drafts
AT_DATA([Mail/drafts/2],
[From: mhtester@example.net
To: gray@example.net
Subject: Draftfolder test
Message body
])
AT_DATA([Mail/drafts/5],
[From: mhtester@example.net
To: gray@example.org
Subject: Draftmessage test
Message body
])
echo "cur: 2" > Mail/drafts/.mh_sequences
send -draftfolder +drafts -draftmessage 5 || echo $?
sed 's/: Date: .*/: Date: now/' $MTA_DIAG
],
[0],
[ENVELOPE FROM: mhtester@example.net
ENVELOPE TO: <gray@example.org>
0: X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
1: Date: now
2: From: mhtester@example.net
3: To: <gray@example.org>
4: Subject: Draftmessage test
5:
6: Message body
END OF MESSAGE
])
m4_popdef([MH_KEYWORDS])
# End of send.at
......@@ -25,9 +25,25 @@ cat > $MH <<EOT
Path: $curdir/Mail
mhetcdir: $abs_top_srcdir/mh/etc
EOT
MTSTAILOR=$curdir/mtstailor
export MTSTAILOR
exec <&-
])
m4_define([MH_MTSTAILOR],[
cat > $MTSTAILOR <<EOT
localname: darkstar
localdomain: example.net
username: mhtester
url: sendmail://$abs_top_srcdir/examples/mta
EOT
MTA_DIAG=$curdir/mta.diag
export MTA_DIAG
MTA_DOMAIN=example.net
export MTA_DOMAIN
])
m4_define([MH_KEYWORDS])
dnl --------------------------------------------------------------
......@@ -64,3 +80,4 @@ m4_include([comp.at])
m4_include([forw.at])
m4_include([repl.at])
m4_include([mhn.at])
m4_include([send.at])
......