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}. ...@@ -211,6 +211,16 @@ For more information, please see @xref{reply_regex function}.
211 @subsubsection Differences in MH Program Behavior 211 @subsubsection Differences in MH Program Behavior
212 212
213 @table @command 213 @table @command
214 @item anno
215
216 The prompt in interactive mode is @samp{Component name:}, instead
217 of @samp{Enter component name:} displayed by the RAND @command{anno}.
218
219 If a @option{-component field} is not specified and standard input
220 is not connected to a terminal, @command{anno} does not display
221 the prompt before reading the component from the standard input.
222 RAND @command{anno} displays the prompt anyway.
223
214 @item burst 224 @item burst
215 225
216 The utility is able to burst both RFC 934 digest messages and MIME 226 The utility is able to burst both RFC 934 digest messages and MIME
......
...@@ -109,7 +109,7 @@ main (int argc, char **argv) ...@@ -109,7 +109,7 @@ main (int argc, char **argv)
109 mu_mailbox_t mbox; 109 mu_mailbox_t mbox;
110 mh_msgset_t msgset; 110 mh_msgset_t msgset;
111 size_t len; 111 size_t len;
112 112
113 MU_APP_INIT_NLS (); 113 MU_APP_INIT_NLS ();
114 114
115 mh_argp_init (); 115 mh_argp_init ();
...@@ -120,11 +120,37 @@ main (int argc, char **argv) ...@@ -120,11 +120,37 @@ main (int argc, char **argv)
120 120
121 if (!component) 121 if (!component)
122 { 122 {
123 size_t n; 123 mu_stream_t in;
124 size_t size = 0;
125 char *p;
124 126
125 printf (_("Component name: ")); 127 rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
126 if (getline (&component, &n, stdin) <= 0 || *component == 0) 128 if (rc)
127 exit (1); 129 {
130 mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
131 exit (1);
132 }
133
134 if (isatty (0))
135 {
136 printf (_("Component name: "));
137 fflush (stdout);
138 }
139 rc = mu_stream_getline (in, &component, &size, NULL);
140 mu_stream_destroy (&in);
141 if (rc)
142 {
143 mu_error (_("error reading input stream: %s"), mu_strerror (rc));
144 exit (1);
145 }
146 p = mu_str_stripws (component);
147 if (*p == 0)
148 {
149 mu_error (_("invalid component name"));
150 exit (1);
151 }
152 if (p > component)
153 memmove (component, p, strlen (p) + 1);
128 } 154 }
129 155
130 if (!anno_text && !anno_date) 156 if (!anno_text && !anno_date)
......
...@@ -40,9 +40,19 @@ char mh_list_format[] = ...@@ -40,9 +40,19 @@ char mh_list_format[] =
40 "%<(zero)%17(decode(friendly{from}))%>" 40 "%<(zero)%17(decode(friendly{from}))%>"
41 " %(decode{subject})%<{body}<<%{body}>>%>"; 41 " %(decode{subject})%<{body}<<%{body}>>%>";
42 42
43 /* Make sure stdin is open. If not, connect it to /dev/null. */
44 static void
45 mh_ensure_stdin ()
46 {
47 int fd = open ("/dev/null", O_RDONLY);
48 if (fd != 0)
49 close (fd);
50 }
51
43 void 52 void
44 mh_init () 53 mh_init ()
45 { 54 {
55 mh_ensure_stdin ();
46 /* Register all mailbox and mailer formats */ 56 /* Register all mailbox and mailer formats */
47 mu_register_all_formats (); 57 mu_register_all_formats ();
48 #ifdef WITH_TLS 58 #ifdef WITH_TLS
......
...@@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac ...@@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
39 ## ------------ ## 39 ## ------------ ##
40 40
41 TESTSUITE_AT = \ 41 TESTSUITE_AT = \
42 anno.at\
42 folder.at\ 43 folder.at\
43 inc.at\ 44 inc.at\
44 mark.at\ 45 mark.at\
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2010 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3, or (at
7 # your option) any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
16
17 m4_pushdef[MH_KEYWORDS],[anno])
18
19 MH_CHECK([anno],[anno00],[
20 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
21 echo "Current-Folder: inbox" > Mail/context
22 echo "cur: 1" > Mail/inbox/.mh_sequences
23 echo Replied | anno || exit $?
24 sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
25 ],
26 [0],
27 [REPLIED
28 ])
29
30 MH_CHECK([anno -component],[anno01 anno-component],[
31 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
32 echo "Current-Folder: inbox" > Mail/context
33 anno -component Replied 1 || exit $?
34 sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
35 ],
36 [0],
37 [REPLIED
38 ])
39
40 MH_CHECK([anno -component -text],[anno02 anno-component-text],[
41 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
42 echo "Current-Folder: inbox" > Mail/context
43 anno -component Replied -text OK 1 || exit $?
44 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
45 ],
46 [0],
47 [Replied: OK
48 Replied: DATE
49 ])
50
51 MH_CHECK([anno -component -text -nodate],[anno03 anno-component-text-nodate],[
52 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
53 echo "Current-Folder: inbox" > Mail/context
54 anno -component Replied -text OK -nodate 1 || exit $?
55 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
56 ],
57 [0],
58 [Replied: OK
59 ])
60
61 m4_popdef[MH_KEYWORDS])
62 # End of anno.at
...@@ -51,3 +51,4 @@ m4_include([mhparam.at]) ...@@ -51,3 +51,4 @@ m4_include([mhparam.at])
51 m4_include([refile.at]) 51 m4_include([refile.at])
52 m4_include([mhpath.at]) 52 m4_include([mhpath.at])
53 m4_include([mhl.at]) 53 m4_include([mhl.at])
54 m4_include([anno.at])
......