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
2008-10-24 Sergey Poznyakoff <gray@gnu.org.ua>
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.
2008-10-23 Sergey Poznyakoff <gray@gnu.org.ua>
* 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)
decode_float (&limit, arg->v.string, 3);
result = score >= limit;
}
else if (mu_sieve_tag_lookup (tags, "over", &arg))
else if (mu_sieve_tag_lookup (tags, "under", &arg))
{
decode_float (&limit, arg->v.string, 3);
result = score <= limit;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2004,
2005, 2006, 2007 Free Software Foundation, Inc.
2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -49,7 +49,10 @@ struct _file_stream
mu_off_t offset;
int tempfile;
char *filename;
/* The following three members are used for stdio streams only. */
int size_computed;
mu_stream_t cache;
mu_off_t size;
};
static void
......@@ -208,7 +211,7 @@ _stdin_file_read (mu_stream_t stream, char *optr, size_t osize,
int status = 0;
size_t nbytes;
struct _file_stream *fs = mu_stream_get_owner (stream);
int fs_offset = fs->offset;
mu_off_t fs_offset = fs->offset;
if (offset < fs_offset)
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,
int status;
size_t nbytes;
struct _file_stream *fs = mu_stream_get_owner (stream);
int fs_offset = fs->offset;
mu_off_t fs_offset = fs->offset;
if (offset < fs->offset)
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,
return status;
}
/* Used only if stream->cache is not NULL */
static int
_stdin_file_size (mu_stream_t stream, mu_off_t *psize)
{
struct _file_stream *fs = mu_stream_get_owner (stream);
if (!fs->size_computed)
{
char buf[512];
mu_off_t fs_offset = fs->offset;
size_t n;
int status;
/* Fill in the cache */
while ((status = mu_stream_read (stream, buf, sizeof (buf),
fs_offset, &n)) == 0
&& n > 0)
fs_offset += n;
fs->size = fs_offset;
fs->size_computed = 1;
}
*psize = fs->size;
return 0;
}
static int
_stdout_file_write (mu_stream_t stream, const char *iptr, size_t isize,
mu_off_t offset, size_t *nbytes)
......@@ -651,6 +679,7 @@ mu_stdio_stream_create (mu_stream_t *stream, FILE *file, int flags)
mu_stream_set_read (*stream, _stdin_file_read, fs);
mu_stream_set_readline (*stream, _stdin_file_readline, fs);
mu_stream_set_write (*stream, _stdout_file_write, fs);
mu_stream_set_size (*stream, _stdin_file_size, fs);
}
else
{
......
......@@ -215,7 +215,6 @@ struct _mu_rfc822_message
{
char *from;
char *date;
mu_off_t header_start;
mu_off_t body_start;
mu_off_t body_end;
};
......
......@@ -375,7 +375,7 @@ sieve_message (mu_sieve_machine_t mach)
mu_message_t msg;
mu_attribute_t attr;
rc = mu_stdio_stream_create (&instr, stdin, 0);
rc = mu_stdio_stream_create (&instr, stdin, MU_STREAM_SEEKABLE);
if (rc)
{
mu_error (_("Cannot create stream: %s"), mu_strerror (rc));
......