Commit 887d5d3f 887d5d3f4426883a200e530a890588b29ce4a2e5 by Sergey Poznyakoff

Fix handling of stdin stream (in particular, in sieve).

* libsieve/extensions/spamd.c (spamd_test): Fix typo.
*  mailbox/file_stream.c (struct _file_stream): New members
size and size_computed.
(_stdin_file_read, _stdin_file_readline): Fix types of fs_offset.
(_stdin_file_size): New function.
(_stdout_file_write): Register _stdin_file_size as stream_size
method if seekable flag is set.
* mailbox/message_stream.c (struct _mu_rfc822_message): Remove
unused member.
* sieve/sieve.c (sieve_message): Create a seekable stream.
1 parent cd3010fc
1 2008-10-24 Sergey Poznyakoff <gray@gnu.org.ua>
2
3 Fix handling of stdin stream (in particular, in sieve).
4
5 * libsieve/extensions/spamd.c (spamd_test): Fix typo.
6 * mailbox/file_stream.c (struct _file_stream): New members
7 size and size_computed.
8 (_stdin_file_read, _stdin_file_readline): Fix types of fs_offset.
9 (_stdin_file_size): New function.
10 (_stdout_file_write): Register _stdin_file_size as stream_size
11 method if seekable flag is set.
12 * mailbox/message_stream.c (struct _mu_rfc822_message): Remove
13 unused member.
14 * sieve/sieve.c (sieve_message): Create a seekable stream.
15
1 2008-10-23 Sergey Poznyakoff <gray@gnu.org.ua> 16 2008-10-23 Sergey Poznyakoff <gray@gnu.org.ua>
2 17
3 * libsieve/extensions/spamd.c: New tag :user. 18 * libsieve/extensions/spamd.c: New tag :user.
......
...@@ -368,7 +368,7 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags) ...@@ -368,7 +368,7 @@ spamd_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
368 decode_float (&limit, arg->v.string, 3); 368 decode_float (&limit, arg->v.string, 3);
369 result = score >= limit; 369 result = score >= limit;
370 } 370 }
371 else if (mu_sieve_tag_lookup (tags, "over", &arg)) 371 else if (mu_sieve_tag_lookup (tags, "under", &arg))
372 { 372 {
373 decode_float (&limit, arg->v.string, 3); 373 decode_float (&limit, arg->v.string, 3);
374 result = score <= limit; 374 result = score <= limit;
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2 Copyright (C) 1999, 2000, 2001, 2002, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -49,7 +49,10 @@ struct _file_stream ...@@ -49,7 +49,10 @@ struct _file_stream
49 mu_off_t offset; 49 mu_off_t offset;
50 int tempfile; 50 int tempfile;
51 char *filename; 51 char *filename;
52 /* The following three members are used for stdio streams only. */
53 int size_computed;
52 mu_stream_t cache; 54 mu_stream_t cache;
55 mu_off_t size;
53 }; 56 };
54 57
55 static void 58 static void
...@@ -208,7 +211,7 @@ _stdin_file_read (mu_stream_t stream, char *optr, size_t osize, ...@@ -208,7 +211,7 @@ _stdin_file_read (mu_stream_t stream, char *optr, size_t osize,
208 int status = 0; 211 int status = 0;
209 size_t nbytes; 212 size_t nbytes;
210 struct _file_stream *fs = mu_stream_get_owner (stream); 213 struct _file_stream *fs = mu_stream_get_owner (stream);
211 int fs_offset = fs->offset; 214 mu_off_t fs_offset = fs->offset;
212 215
213 if (offset < fs_offset) 216 if (offset < fs_offset)
214 return mu_stream_read (fs->cache, optr, osize, offset, pnbytes); 217 return mu_stream_read (fs->cache, optr, osize, offset, pnbytes);
...@@ -269,7 +272,7 @@ _stdin_file_readline (mu_stream_t stream, char *optr, size_t osize, ...@@ -269,7 +272,7 @@ _stdin_file_readline (mu_stream_t stream, char *optr, size_t osize,
269 int status; 272 int status;
270 size_t nbytes; 273 size_t nbytes;
271 struct _file_stream *fs = mu_stream_get_owner (stream); 274 struct _file_stream *fs = mu_stream_get_owner (stream);
272 int fs_offset = fs->offset; 275 mu_off_t fs_offset = fs->offset;
273 276
274 if (offset < fs->offset) 277 if (offset < fs->offset)
275 return mu_stream_readline (fs->cache, optr, osize, offset, pnbytes); 278 return mu_stream_readline (fs->cache, optr, osize, offset, pnbytes);
...@@ -293,6 +296,31 @@ _stdin_file_readline (mu_stream_t stream, char *optr, size_t osize, ...@@ -293,6 +296,31 @@ _stdin_file_readline (mu_stream_t stream, char *optr, size_t osize,
293 return status; 296 return status;
294 } 297 }
295 298
299 /* Used only if stream->cache is not NULL */
300 static int
301 _stdin_file_size (mu_stream_t stream, mu_off_t *psize)
302 {
303 struct _file_stream *fs = mu_stream_get_owner (stream);
304
305 if (!fs->size_computed)
306 {
307 char buf[512];
308 mu_off_t fs_offset = fs->offset;
309 size_t n;
310 int status;
311
312 /* Fill in the cache */
313 while ((status = mu_stream_read (stream, buf, sizeof (buf),
314 fs_offset, &n)) == 0
315 && n > 0)
316 fs_offset += n;
317 fs->size = fs_offset;
318 fs->size_computed = 1;
319 }
320 *psize = fs->size;
321 return 0;
322 }
323
296 static int 324 static int
297 _stdout_file_write (mu_stream_t stream, const char *iptr, size_t isize, 325 _stdout_file_write (mu_stream_t stream, const char *iptr, size_t isize,
298 mu_off_t offset, size_t *nbytes) 326 mu_off_t offset, size_t *nbytes)
...@@ -651,6 +679,7 @@ mu_stdio_stream_create (mu_stream_t *stream, FILE *file, int flags) ...@@ -651,6 +679,7 @@ mu_stdio_stream_create (mu_stream_t *stream, FILE *file, int flags)
651 mu_stream_set_read (*stream, _stdin_file_read, fs); 679 mu_stream_set_read (*stream, _stdin_file_read, fs);
652 mu_stream_set_readline (*stream, _stdin_file_readline, fs); 680 mu_stream_set_readline (*stream, _stdin_file_readline, fs);
653 mu_stream_set_write (*stream, _stdout_file_write, fs); 681 mu_stream_set_write (*stream, _stdout_file_write, fs);
682 mu_stream_set_size (*stream, _stdin_file_size, fs);
654 } 683 }
655 else 684 else
656 { 685 {
......
...@@ -215,7 +215,6 @@ struct _mu_rfc822_message ...@@ -215,7 +215,6 @@ struct _mu_rfc822_message
215 { 215 {
216 char *from; 216 char *from;
217 char *date; 217 char *date;
218 mu_off_t header_start;
219 mu_off_t body_start; 218 mu_off_t body_start;
220 mu_off_t body_end; 219 mu_off_t body_end;
221 }; 220 };
......
...@@ -375,7 +375,7 @@ sieve_message (mu_sieve_machine_t mach) ...@@ -375,7 +375,7 @@ sieve_message (mu_sieve_machine_t mach)
375 mu_message_t msg; 375 mu_message_t msg;
376 mu_attribute_t attr; 376 mu_attribute_t attr;
377 377
378 rc = mu_stdio_stream_create (&instr, stdin, 0); 378 rc = mu_stdio_stream_create (&instr, stdin, MU_STREAM_SEEKABLE);
379 if (rc) 379 if (rc)
380 { 380 {
381 mu_error (_("Cannot create stream: %s"), mu_strerror (rc)); 381 mu_error (_("Cannot create stream: %s"), mu_strerror (rc));
......