summaryrefslogtreecommitdiff
path: root/libsieve/tests.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-11-14 07:17:14 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-11-14 07:17:14 +0000
commit8b018cd915e124676e1c38c7736d680ca18bc031 (patch)
treef527a5c61c938670432cd943b87e8e4656549f09 /libsieve/tests.c
parent7ce94cbd90c52e0b72e021f1058f6291ae47ed0d (diff)
downloadmailutils-8b018cd915e124676e1c38c7736d680ca18bc031.tar.gz
mailutils-8b018cd915e124676e1c38c7736d680ca18bc031.tar.bz2
Implemented true, false, exists and size.
Diffstat (limited to 'libsieve/tests.c')
-rw-r--r--libsieve/tests.c69
1 files changed, 58 insertions, 11 deletions
diff --git a/libsieve/tests.c b/libsieve/tests.c
index 8d09a00d9..371e86edb 100644
--- a/libsieve/tests.c
+++ b/libsieve/tests.c
@@ -37,45 +37,92 @@
#define TAG_OVER 9
int
-sieve_test_address (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_address (sieve_machine_t mach, list_t args, list_t tags)
{
return 0;
}
int
-sieve_test_header (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_header (sieve_machine_t mach, list_t args, list_t tags)
{
return 0;
}
int
-sieve_test_envelope (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_envelope (sieve_machine_t mach, list_t args, list_t tags)
{
return 0;
}
int
-sieve_test_size (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_size (sieve_machine_t mach, list_t args, list_t tags)
{
- return 0;
+ int rc;
+ sieve_runtime_tag_t *tag = NULL;
+ size_t size;
+
+ sieve_value_t *val = sieve_value_get (args, 0);
+ if (!val)
+ {
+ sieve_error (mach, "size: can't get argument!");
+ sieve_abort (mach);
+ }
+
+ message_size (sieve_get_message (mach), &size);
+ list_get (tags, 0, (void **)&tag);
+ if (!tag)
+ rc = size == val->v.number;
+ else if (tag->tag == TAG_OVER)
+ rc = size > val->v.number;
+ else if (tag->tag == TAG_UNDER)
+ rc = size < val->v.number;
+
+ return rc;
}
int
-sieve_test_true (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_true (sieve_machine_t mach, list_t args, list_t tags)
{
- return 0;
+ if (mach->debug_level & MU_SIEVE_DEBUG_TRACE)
+ sieve_debug (mach, "TRUE\n");
+ return 1;
}
int
-sieve_test_false (sieve_machine_t *mach, list_t args, list_t tags)
+sieve_test_false (sieve_machine_t mach, list_t args, list_t tags)
{
+ if (mach->debug_level & MU_SIEVE_DEBUG_TRACE)
+ sieve_debug (mach, "FALSE\n");
return 0;
}
int
-sieve_test_exists (sieve_machine_t *mach, list_t args, list_t tags)
+_test_exists (void *item, void *data)
{
- return 0;
+ header_t hdr = data;
+ size_t n;
+
+ return header_get_value (hdr, (char*)item, NULL, 0, &n);
+}
+
+int
+sieve_test_exists (sieve_machine_t mach, list_t args, list_t tags)
+{
+ header_t header = NULL;
+ sieve_value_t *val;
+
+ if (mach->debug_level & MU_SIEVE_DEBUG_TRACE)
+ sieve_debug (mach, "EXISTS\n");
+
+ message_get_header (sieve_get_message (mach), &header);
+ val = sieve_value_get (args, 0);
+ if (!val)
+ {
+ sieve_error (mach, "exists: can't get argument!");
+ sieve_abort (mach);
+ }
+
+ return list_do (val->v.list, _test_exists, header) == 0;
}
#define ADDRESS_PART \
@@ -142,7 +189,7 @@ void
sieve_register_standard_tests ()
{
sieve_register_test ("false", sieve_test_false, NULL, NULL, 1);
- sieve_register_test ("true", sieve_test_false, NULL, NULL, 1);
+ sieve_register_test ("true", sieve_test_true, NULL, NULL, 1);
sieve_register_test ("address", sieve_test_address,
address_req_args, address_tags, 1);
sieve_register_test ("size", sieve_test_size,

Return to:

Send suggestions and report system problems to the System administrator.