summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2008-10-23 22:48:39 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2008-10-23 22:48:39 +0000
commit887d5d3f4426883a200e530a890588b29ce4a2e5 (patch)
tree669b01331c4b38526803c1df256ffeb4c8e764d3
parentcd3010fc6d05da8a4fa5cfacf13e14b923976620 (diff)
downloadmailutils-887d5d3f4426883a200e530a890588b29ce4a2e5.tar.gz
mailutils-887d5d3f4426883a200e530a890588b29ce4a2e5.tar.bz2
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.
-rw-r--r--ChangeLog15
-rw-r--r--libsieve/extensions/spamd.c2
-rw-r--r--mailbox/file_stream.c35
-rw-r--r--mailbox/message_stream.c1
-rw-r--r--sieve/sieve.c2
5 files changed, 49 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d46dad629..02437b5a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
diff --git a/libsieve/extensions/spamd.c b/libsieve/extensions/spamd.c
index 571c56f42..bfd42835b 100644
--- a/libsieve/extensions/spamd.c
+++ b/libsieve/extensions/spamd.c
@@ -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;
diff --git a/mailbox/file_stream.c b/mailbox/file_stream.c
index 47ff5d9dc..e7cc97788 100644
--- a/mailbox/file_stream.c
+++ b/mailbox/file_stream.c
@@ -1,6 +1,6 @@
/* 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
{
diff --git a/mailbox/message_stream.c b/mailbox/message_stream.c
index a4e9a2c8c..066d7890a 100644
--- a/mailbox/message_stream.c
+++ b/mailbox/message_stream.c
@@ -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;
};
diff --git a/sieve/sieve.c b/sieve/sieve.c
index d62e6a59a..a7c180da0 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -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));

Return to:

Send suggestions and report system problems to the System administrator.