Commit c0220170 c02201707fd4664252ba0e3fe93d3018ec816c89 by Sergey Poznyakoff

anno: Minor improvements.

* mh/mh_init.c (mh_init): Make sure stdin is open.
* mh/anno.c (main): Use mu_stream_t to read the answer from stdin.
Do not display prompt if stdin is not connected to a tty.
* mh/tests/anno.at: New testcase.
* mh/tests/Makefile.am (TESTSUITE_AT): Add anno.at
* mh/tests/testsuite.at: Include anno.at.

* doc/texinfo/mu-mh.texi: Document the changes in the behavior of anno.
1 parent 13c94193
......@@ -211,6 +211,16 @@ For more information, please see @xref{reply_regex function}.
@subsubsection Differences in MH Program Behavior
@table @command
@item anno
The prompt in interactive mode is @samp{Component name:}, instead
of @samp{Enter component name:} displayed by the RAND @command{anno}.
If a @option{-component field} is not specified and standard input
is not connected to a terminal, @command{anno} does not display
the prompt before reading the component from the standard input.
RAND @command{anno} displays the prompt anyway.
@item burst
The utility is able to burst both RFC 934 digest messages and MIME
......
......@@ -109,7 +109,7 @@ main (int argc, char **argv)
mu_mailbox_t mbox;
mh_msgset_t msgset;
size_t len;
MU_APP_INIT_NLS ();
mh_argp_init ();
......@@ -120,11 +120,37 @@ main (int argc, char **argv)
if (!component)
{
size_t n;
mu_stream_t in;
size_t size = 0;
char *p;
printf (_("Component name: "));
if (getline (&component, &n, stdin) <= 0 || *component == 0)
exit (1);
rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
if (rc)
{
mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
exit (1);
}
if (isatty (0))
{
printf (_("Component name: "));
fflush (stdout);
}
rc = mu_stream_getline (in, &component, &size, NULL);
mu_stream_destroy (&in);
if (rc)
{
mu_error (_("error reading input stream: %s"), mu_strerror (rc));
exit (1);
}
p = mu_str_stripws (component);
if (*p == 0)
{
mu_error (_("invalid component name"));
exit (1);
}
if (p > component)
memmove (component, p, strlen (p) + 1);
}
if (!anno_text && !anno_date)
......
......@@ -40,9 +40,19 @@ char mh_list_format[] =
"%<(zero)%17(decode(friendly{from}))%>"
" %(decode{subject})%<{body}<<%{body}>>%>";
/* Make sure stdin is open. If not, connect it to /dev/null. */
static void
mh_ensure_stdin ()
{
int fd = open ("/dev/null", O_RDONLY);
if (fd != 0)
close (fd);
}
void
mh_init ()
{
mh_ensure_stdin ();
/* Register all mailbox and mailer formats */
mu_register_all_formats ();
#ifdef WITH_TLS
......
......@@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
## ------------ ##
TESTSUITE_AT = \
anno.at\
folder.at\
inc.at\
mark.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],[anno])
MH_CHECK([anno],[anno00],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "Current-Folder: inbox" > Mail/context
echo "cur: 1" > Mail/inbox/.mh_sequences
echo Replied | anno || exit $?
sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
],
[0],
[REPLIED
])
MH_CHECK([anno -component],[anno01 anno-component],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "Current-Folder: inbox" > Mail/context
anno -component Replied 1 || exit $?
sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
],
[0],
[REPLIED
])
MH_CHECK([anno -component -text],[anno02 anno-component-text],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "Current-Folder: inbox" > Mail/context
anno -component Replied -text OK 1 || exit $?
sed -n '3,$d;/Replied/{s/Replied: [[A-Z][a-z][a-z], [0-9][0-9] [A-Z][a-z][a-z] [0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] .*]/Replied: DATE/;p}' Mail/inbox/1
],
[0],
[Replied: OK
Replied: DATE
])
MH_CHECK([anno -component -text -nodate],[anno03 anno-component-text-nodate],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo "Current-Folder: inbox" > Mail/context
anno -component Replied -text OK -nodate 1 || exit $?
sed -n '3,$d;/Replied/{s/Replied: [[A-Z][a-z][a-z], [0-9][0-9] [A-Z][a-z][a-z] [0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] .*]/Replied: DATE/;p}' Mail/inbox/1
],
[0],
[Replied: OK
])
m4_popdef[MH_KEYWORDS])
# End of anno.at
......@@ -51,3 +51,4 @@ m4_include([mhparam.at])
m4_include([refile.at])
m4_include([mhpath.at])
m4_include([mhl.at])
m4_include([anno.at])
......