diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-09-03 17:47:14 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-09-03 17:50:54 +0300 |
commit | 016c4a978a69cc8990b5aab6c88cbac6fda57203 (patch) | |
tree | f451622ce35a0b64e52522aeef82bd3064faef06 | |
parent | ddfa689bff19d877170add6fed3381f3d5b79a8e (diff) | |
download | mailutils-016c4a978a69cc8990b5aab6c88cbac6fda57203.tar.gz mailutils-016c4a978a69cc8990b5aab6c88cbac6fda57203.tar.bz2 |
comsatd: optional argument to the --test option supplies the name of the tty to use
* NEWS: Document changes.
* comsat/action.c (open_default_tty): Remove.
(open_tty): Examine the tty device (or file) and construct a suitable
filter chain.
Use append mode when opening it.
* comsat/comsat.c: The --test option takes optional argument.
* comsat/tests/testsuite.at: Use local file instead of the tty.
* doc/texinfo/programs/comsatd.texi: Document changes.
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | comsat/action.c | 142 | ||||
-rw-r--r-- | comsat/comsat.c | 30 | ||||
-rw-r--r-- | comsat/tests/testsuite.at | 62 | ||||
-rw-r--r-- | doc/texinfo/programs/comsatd.texi | 28 |
5 files changed, 145 insertions, 124 deletions
@@ -1,7 +1,7 @@ | |||
1 | GNU mailutils NEWS -- history of user-visible changes. 2019-08-29 | 1 | GNU mailutils NEWS -- history of user-visible changes. 2019-09-03 |
2 | Copyright (C) 2002-2019 Free Software Foundation, Inc. | 2 | Copyright (C) 2002-2019 Free Software Foundation, Inc. |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
4 | 4 | ||
5 | Please send mailutils bug reports to <bug-mailutils@gnu.org>. | 5 | Please send mailutils bug reports to <bug-mailutils@gnu.org>. |
6 | 6 | ||
7 | Version 3.7.90 (git) | 7 | Version 3.7.90 (git) |
@@ -20,12 +20,17 @@ Example configuration (pop3s server): | |||
20 | tls-mode connection; | 20 | tls-mode connection; |
21 | tls { | 21 | tls { |
22 | ssl-key-file /etc/ssl/key.pem; | 22 | ssl-key-file /etc/ssl/key.pem; |
23 | ssl-certificate-file /etc/ssl/cert.pem; | 23 | ssl-certificate-file /etc/ssl/cert.pem; |
24 | } | 24 | } |
25 | 25 | ||
26 | * comsatd --test | ||
27 | |||
28 | The --test option takes optional argument: name of the tty or file to | ||
29 | use for reporting. | ||
30 | |||
26 | 31 | ||
27 | Version 3.7 - 2019-06-21 | 32 | Version 3.7 - 2019-06-21 |
28 | 33 | ||
29 | * Support for the new mailbox format - dotmail | 34 | * Support for the new mailbox format - dotmail |
30 | 35 | ||
31 | Dotmail is a replacement for traditional mbox format, proposed by | 36 | Dotmail is a replacement for traditional mbox format, proposed by |
diff --git a/comsat/action.c b/comsat/action.c index c9703f28e..b6799c481 100644 --- a/comsat/action.c +++ b/comsat/action.c | |||
@@ -173,98 +173,114 @@ expand_line (const char *str, mu_message_t msg) | |||
173 | } | 173 | } |
174 | 174 | ||
175 | const char *default_action = | 175 | const char *default_action = |
176 | #include "biff.rc.h" | 176 | #include "biff.rc.h" |
177 | ; | 177 | ; |
178 | 178 | ||
179 | /* Examine the tty to determine which filters to apply when printing | ||
180 | to it. On entry, STR is the opened stream, FLT points to an array | ||
181 | of char* with at least 3 slots, and NFLT to an integer number. | ||
182 | On success, populates FLT with the necessary filter chain, and stores | ||
183 | to *NFLT the number of used slots. On error, issues error message and | ||
184 | returns -1. | ||
185 | FLT and NFLT can be used as input to mu_filter_chain_create. | ||
186 | */ | ||
179 | static int | 187 | static int |
180 | need_crlf (mu_stream_t str) | 188 | study_tty (mu_stream_t str, char *flt[], int *nflt) |
181 | { | 189 | { |
182 | #if defined(OPOST) && defined(ONLCR) | ||
183 | mu_transport_t trans[2]; | 190 | mu_transport_t trans[2]; |
184 | struct termios tbuf; | 191 | int fd; |
192 | struct stat st; | ||
193 | int rc; | ||
194 | |||
195 | rc = mu_stream_ioctl (str, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, trans); | ||
196 | if (rc) | ||
197 | { | ||
198 | mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_ioctl", NULL, rc); | ||
199 | return rc; | ||
200 | } | ||
185 | 201 | ||
186 | if (mu_stream_ioctl (str, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET, trans)) | 202 | *nflt = 0; |
187 | return 1; /* suppose we do need it */ | 203 | fd = (int) (intptr_t) trans[0]; |
188 | if (tcgetattr ((int) (intptr_t) trans[0], &tbuf) == 0 && | 204 | if (fstat (fd, &st) == 0) |
189 | (tbuf.c_oflag & OPOST) && (tbuf.c_oflag & ONLCR)) | 205 | { |
206 | switch (st.st_mode & S_IFMT) | ||
207 | { | ||
208 | case S_IFREG: | ||
190 | return 0; | 209 | return 0; |
191 | else | 210 | |
192 | return 1; | 211 | case S_IFCHR: |
212 | flt[(*nflt)++] = "7BIT"; | ||
213 | #if defined(OPOST) && defined(ONLCR) | ||
214 | { | ||
215 | struct termios tbuf; | ||
216 | |||
217 | if (!(tcgetattr (fd, &tbuf) == 0 | ||
218 | && (tbuf.c_oflag & OPOST) && (tbuf.c_oflag & ONLCR))) | ||
219 | { | ||
220 | flt[(*nflt)++] = "+"; | ||
221 | flt[(*nflt)++] = "CRLF"; | ||
222 | } | ||
223 | } | ||
193 | #else | 224 | #else |
194 | return 1; /* Just in case */ | 225 | /* Just in case */ |
226 | flt[(*nflt)++] = "+"; | ||
227 | flt[(*nflt)++] = "CRLF"; | ||
195 | #endif | 228 | #endif |
229 | break; | ||
230 | |||
231 | case S_IFSOCK: | ||
232 | return 0; | ||
233 | |||
234 | default: | ||
235 | /* FIXME: Perhaps an error? */ | ||
236 | return 0; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | return 0; | ||
196 | } | 241 | } |
197 | 242 | ||
198 | static mu_stream_t | 243 | static mu_stream_t |
199 | _open_tty (const char *device, int argc, char **argv) | 244 | _open_tty (const char *device, int argc, char **argv) |
200 | { | 245 | { |
201 | mu_stream_t dev, base_dev, prev_stream; | 246 | mu_stream_t dev; |
202 | int status; | 247 | int status; |
248 | char *dfl_argv[4]; | ||
203 | 249 | ||
204 | status = mu_file_stream_create (&dev, device, MU_STREAM_WRITE); | 250 | status = mu_file_stream_create (&dev, device, MU_STREAM_APPEND|MU_STREAM_CREAT); |
205 | if (status) | 251 | if (status) |
206 | { | 252 | { |
207 | mu_error (_("cannot open device %s: %s"), | 253 | mu_error (_("cannot open device %s: %s"), |
208 | device, mu_strerror (status)); | 254 | device, mu_strerror (status)); |
209 | return NULL; | 255 | return NULL; |
210 | } | 256 | } |
211 | mu_stream_set_buffer (dev, mu_buffer_line, 0); | 257 | mu_stream_set_buffer (dev, mu_buffer_line, 0); |
212 | 258 | ||
213 | prev_stream = base_dev = dev; | 259 | if (argc == 0) |
214 | while (argc) | ||
215 | { | ||
216 | int i; | ||
217 | int mode; | ||
218 | int qmark; | ||
219 | char *fltname; | ||
220 | |||
221 | fltname = argv[0]; | ||
222 | if (fltname[0] == '?') | ||
223 | { | ||
224 | qmark = 1; | ||
225 | fltname++; | ||
226 | } | ||
227 | else | ||
228 | qmark = 0; | ||
229 | |||
230 | if (fltname[0] == '~') | ||
231 | { | 260 | { |
232 | mode = MU_FILTER_DECODE; | 261 | status = study_tty (dev, dfl_argv, &argc); |
233 | fltname++; | 262 | if (status) |
234 | } | 263 | return NULL; |
235 | else | 264 | argv = dfl_argv; |
236 | { | ||
237 | mode = MU_FILTER_ENCODE; | ||
238 | } | 265 | } |
239 | 266 | ||
240 | for (i = 1; i < argc; i++) | 267 | if (argc) |
241 | if (strcmp (argv[i], "+") == 0) | ||
242 | break; | ||
243 | |||
244 | if (qmark == 0 || need_crlf (base_dev)) | ||
245 | { | 268 | { |
246 | status = mu_filter_create_args (&dev, prev_stream, fltname, | 269 | mu_stream_t str; |
247 | i, (const char **)argv, | 270 | status = mu_filter_chain_create (&str, dev, |
248 | mode, MU_STREAM_WRITE); | 271 | MU_FILTER_ENCODE, MU_STREAM_WRITE, |
249 | mu_stream_unref (prev_stream); | 272 | argc, argv); |
273 | mu_stream_unref (dev); | ||
250 | if (status) | 274 | if (status) |
251 | { | 275 | { |
252 | mu_error (_("cannot open filter stream: %s"), | 276 | mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_chain_create", device, |
253 | mu_strerror (status)); | 277 | status); |
254 | return NULL; | 278 | return NULL; |
255 | } | 279 | } |
256 | prev_stream = dev; | 280 | dev = str; |
257 | } | ||
258 | argc -= i; | ||
259 | argv += i; | ||
260 | if (argc) | ||
261 | { | ||
262 | argc--; | ||
263 | argv++; | ||
264 | } | ||
265 | } | 281 | } |
266 | return dev; | 282 | return dev; |
267 | } | 283 | } |
268 | 284 | ||
269 | mu_stream_t | 285 | mu_stream_t |
270 | open_tty (const char *device, int argc, char **argv) | 286 | open_tty (const char *device, int argc, char **argv) |
@@ -272,28 +288,22 @@ open_tty (const char *device, int argc, char **argv) | |||
272 | mu_stream_t dev; | 288 | mu_stream_t dev; |
273 | 289 | ||
274 | if (!device || !*device || strcmp (device, "null") == 0) | 290 | if (!device || !*device || strcmp (device, "null") == 0) |
275 | { | 291 | { |
276 | int rc = mu_nullstream_create (&dev, MU_STREAM_WRITE); | 292 | int rc = mu_nullstream_create (&dev, MU_STREAM_WRITE); |
277 | if (rc) | 293 | if (rc) |