~ubuntu-dev/ubuntu/lucid/dovecot/lucid-201002101901

« back to all changes in this revision

Viewing changes to libsieve/src/lib-sieve/plugins/date/tst-date.c

  • Committer: Chuck Short
  • Date: 2010-01-21 20:21:25 UTC
  • mfrom: (4.1.11 squeeze)
  • Revision ID: zulcss@ubuntu.com-20100121202125-pme73o491kfwj5nc
* Merge from debian testing, remaining changes:
  + Add new binary pkg dovecot-postfix that integrates postfix and dovecot
    automatically: (LP: #164837)
  + debian/control:
    - add new binary with short description
    - set Architecture all for dovecot-postfix (LP: #329878)
  + debian/dovecot-postfix.postinst:
    - create initial certificate symlinks to snakeoil.
    - set up postfix with postconf to:
      - use Maildir/ as the default mailbox.
      - use dovecot as the sasl authentication server.
      - use dovecot LDA (deliver).
      - use tls for smtp{d} services.
    - fix certificates paths in postfix' main.cf
    - add reject_unauth_destination to postfix' recipient restrictions
    - add reject_unknown_sender_domain to postfix' sender restriction
    - rename configuration name on remove, delete on purge
    - restart dovecot after linking certificates
    - handle use case when postfix is unconfigurated
  + debian/dovecot-postfix.dirs: create backup directory for postfix's config
    configuration
  + restart postfix and dovecot.
  + debian/dovecot-postfix.postrm:
    - remove all dovecot related configuration from postfix.
    - restart postfix and dovecot.
  + debian/dovecot-common.init:
    - check if /etc/dovecot/dovecot-postfix.conf exists and use it
      as the configuration file if so.
  + debian/patches/warning-ubuntu-postfix.dpatch
    - add warning about dovecot-postfix.conf in dovecot default
      configuration file
  + debian/patches/dovecot-postfix.conf.diff:
    - Ubuntu server custom changes to the default dovecot configuration for
      better interfation with postfix.
    - enable sieve plugin.
    - Ubuntu server custom changes to the default dovecot configuration for
      better integration with postfix:
      - enable imap, pop3, imaps, pop3s and managesieve by default.
      - enable dovecot LDA (deliver).
      - enable SASL auth socket in postfix private directory
   + debian/rules:
     - copy, patch and install dovecot-postfix.conf in /etc/dovecot/.
     - build architecure independent packages too
   + Use Snakeoil SSL certificates by default.
     - debian/control: Depend on ssl-cert.
     - debian/patches/ssl-cert-snakeoil.dpatch: Change default SSL cert
       paths to snakeoil.
     - debian/dovecot-common.postinst: Relax grep for SSL_* a bit.
   + Add autopkgtest to debian/tests/*.
   + Fast TearDown: Update the lsb init header to not stop in level 6.
   + Add ufw integration:
     - Created debian/dovecot-common.ufw.profile.
     - debian/rules: install profile.
     - debian/control: suggest ufw.
   + debian/{control,rules}: enable PIE hardening.
   + dovecot-imapd, dovecot-pop3: Replaces dovecot-common (<< 1:1.1). (LP: #254721)
   + debian/control: Update Vcs-* headers.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
* New upstream release.
* debian/patches/gold-fix.patch: Removed. Fixed upstream.
* Moved libexec to lib corrections in dovecot-managesieve.patch and
  dovecot-managesieve-dist.patch to dovecot-example.patch
* debian/patches/dovecot-mboxlocking.patch: Regenerated to avoid FTBFS
  when quilt isn't installed.
* debian/patches/quota-mountpoint.patch: Removed. Not needed anymore.
* debian/patches/dovecot-quota.patch: Removed. Quotas aren't properly
  enabled unless mail_plugins = quota imap_quota.
* debian/patches/gold-fix.patch: Fixed configure script to build even
  with binutils-gold or --no-add-needed linker flag (Closes: #554306)
* debian/dovecot-common.init: fixed LSB headers. Thanks to Pascal Volk.
  (Closes: #558040)
* debian/changelog: added CVE references to previous changelog entry.
* debian/rules: checked up the build system. It's not fragile anymore.
  (Closes: 493803)
* debian/dovecot-common.postinst: Now invoking dpkg-reconfigure
  on dovecot-common is enough to generate new certificates
  if the previous ones were removed. (Closes: #545582)
* debian/rules: No longer install convert-tool in /usr/bin.
  It isn't an user utility and it should stay in /usr/lib/dovecot
  like all other similar tool.
* New upstream release. (Closes: #557601)
* [SECURITY] Fixes local information disclosure and denial of service.
  (see: http://www.dovecot.org/list/dovecot-news/2009-November/000143.html
  and CVE-2009-3897)
* Added myself to uploaders.
* Switched to the new source format "3.0 (quilt)":
  - removed dpatch from build-depends
  - removed debian/README.source because now we use only standard
    dpkg features
  - regenerated all patches
* Prepared to switch to multi-origin source:
  - recreated dovecot-libsieve.patch and dovecot-managesieve-dist.patch
    starting from the upstream tarball
  - removed all autotools related build-depends and build-conflict
  - renamed dovecot-libsieve and dovecot-managesieve directories
    to libsieve and managesieve.
* debian/rules: Moved the configuration of libsieve and managesieve from
  the build phase to the configuration phase
* Added dovecot-dbg package  with debugging symbols.  Thanks Stephan Bosch.
  (Closes: #554710)
* Fixed some stray libexec'isms in the default configuration.
* New upstream release.
* debian/dovecot-common.init:
  - use $CONF when starting the daemon. (Closes: #549944)
  - always output start/stop messages. (Closes: #523810)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
 
2
 */
 
3
 
 
4
#include "lib.h"
 
5
#include "str-sanitize.h"
 
6
#include "message-date.h"
 
7
 
 
8
#include "sieve-common.h"
 
9
#include "sieve-commands.h"
 
10
#include "sieve-code.h"
 
11
#include "sieve-comparators.h"
 
12
#include "sieve-match-types.h"
 
13
#include "sieve-address-parts.h"
 
14
#include "sieve-validator.h"
 
15
#include "sieve-generator.h"
 
16
#include "sieve-interpreter.h"
 
17
#include "sieve-dump.h"
 
18
#include "sieve-match.h"
 
19
 
 
20
#include "ext-date-common.h"
 
21
 
 
22
#include <time.h>
 
23
 
 
24
/*
 
25
 * Tests
 
26
 */
 
27
 
 
28
static bool tst_date_validate
 
29
        (struct sieve_validator *valdtr, struct sieve_command_context *tst);
 
30
static bool tst_date_generate
 
31
        (const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
 
32
 
 
33
/* Address test
 
34
 *
 
35
 * Syntax:
 
36
 *    date [<":zone" <time-zone: string>> / ":originalzone"]
 
37
 *         [COMPARATOR] [MATCH-TYPE] <header-name: string>
 
38
 *         <date-part: string> <key-list: string-list>
 
39
 */
 
40
 
 
41
static bool tst_date_registered
 
42
        (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg);
 
43
 
 
44
const struct sieve_command date_test = { 
 
45
        "date", 
 
46
        SCT_TEST, 
 
47
        3, 0, FALSE, FALSE,
 
48
        tst_date_registered,
 
49
        NULL, 
 
50
        tst_date_validate, 
 
51
        tst_date_generate, 
 
52
        NULL 
 
53
};
 
54
 
 
55
/* Currentdate test
 
56
 * 
 
57
 * Syntax:
 
58
 *    currentdate [":zone" <time-zone: string>]
 
59
 *                [COMPARATOR] [MATCH-TYPE]
 
60
 *                <date-part: string> <key-list: string-list>
 
61
 */
 
62
 
 
63
static bool tst_currentdate_registered
 
64
        (struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg);
 
65
 
 
66
const struct sieve_command currentdate_test = { 
 
67
        "currentdate", 
 
68
        SCT_TEST, 
 
69
        2, 0, FALSE, FALSE,
 
70
        tst_currentdate_registered,
 
71
        NULL, 
 
72
        tst_date_validate, 
 
73
        tst_date_generate, 
 
74
        NULL 
 
75
};
 
76
 
 
77
/* 
 
78
 * Tagged arguments 
 
79
 */
 
80
 
 
81
/* Forward declarations */
 
82
 
 
83
static bool tag_zone_validate
 
84
        (struct sieve_validator *validator, struct sieve_ast_argument **arg,
 
85
                struct sieve_command_context *cmd);
 
86
static bool tag_zone_generate
 
87
        (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg,
 
88
                struct sieve_command_context *cmd);
 
89
 
 
90
/* Argument objects */
 
91
 
 
92
static const struct sieve_argument date_zone_tag = {
 
93
        "zone",
 
94
        NULL, NULL,
 
95
        tag_zone_validate,
 
96
        NULL,
 
97
        tag_zone_generate
 
98
};
 
99
 
 
100
static const struct sieve_argument date_originalzone_tag = {
 
101
        "originalzone",
 
102
        NULL, NULL,
 
103
        tag_zone_validate,
 
104
        NULL,
 
105
        tag_zone_generate
 
106
};
 
107
 
 
108
/* 
 
109
 * Address operation 
 
110
 */
 
111
 
 
112
static bool tst_date_operation_dump
 
113
        (const struct sieve_operation *op, 
 
114
                const struct sieve_dumptime_env *denv, sieve_size_t *address);
 
115
static int tst_date_operation_execute
 
116
        (const struct sieve_operation *op, 
 
117
                const struct sieve_runtime_env *renv, sieve_size_t *address);
 
118
 
 
119
const struct sieve_operation date_operation = { 
 
120
        "DATE",
 
121
        &date_extension,
 
122
        EXT_DATE_OPERATION_DATE,
 
123
        tst_date_operation_dump, 
 
124
        tst_date_operation_execute 
 
125
};
 
126
 
 
127
const struct sieve_operation currentdate_operation = { 
 
128
        "CURRENTDATE",
 
129
        &date_extension,
 
130
        EXT_DATE_OPERATION_CURRENTDATE,
 
131
        tst_date_operation_dump, 
 
132
        tst_date_operation_execute 
 
133
};
 
134
 
 
135
/*
 
136
 * Optional operands
 
137
 */
 
138
 
 
139
enum tst_date_optional {
 
140
        OPT_DATE_ZONE = SIEVE_MATCH_OPT_LAST,
 
141
        OPT_DATE_LAST
 
142
};
 
143
 
 
144
/*
 
145
 * Tag implementation
 
146
 */
 
147
 
 
148
static bool tag_zone_validate
 
149
(struct sieve_validator *validator, struct sieve_ast_argument **arg,
 
150
    struct sieve_command_context *cmd)
 
151
{
 
152
        struct sieve_ast_argument *tag = *arg;
 
153
 
 
154
        if ( (bool) cmd->data ) {
 
155
                if ( cmd->command == &date_test ) {
 
156
                        sieve_argument_validate_error(validator, *arg,
 
157
                                "multiple :zone or :originalzone arguments specified for "
 
158
                                "the currentdate test");
 
159
                } else {
 
160
                        sieve_argument_validate_error(validator, *arg,
 
161
                                "multiple :zone arguments specified for the currentdate test");
 
162
                }
 
163
                return FALSE;
 
164
        }
 
165
 
 
166
        /* Skip tag */
 
167
        *arg = sieve_ast_argument_next(*arg);
 
168
 
 
169
        /* :content tag has a string-list argument */
 
170
        if ( tag->argument == &date_zone_tag ) {
 
171
 
 
172
                /* Check syntax:
 
173
                 *   :zone <time-zone: string>
 
174
                 */
 
175
                if ( !sieve_validate_tag_parameter
 
176
                        (validator, cmd, tag, *arg, SAAT_STRING) ) {
 
177
                        return FALSE;
 
178
                }
 
179
 
 
180
                /* Check it */
 
181
                if ( sieve_argument_is_string_literal(*arg) ) {
 
182
                        const char *zone = sieve_ast_argument_strc(*arg);
 
183
        
 
184
                        if ( !ext_date_parse_timezone(zone, NULL) ) {
 
185
                                sieve_argument_validate_warning(validator, *arg,
 
186
                                        "specified :zone argument '%s' is not a valid timezone",
 
187
                                        str_sanitize(zone, 40));
 
188
                        }               
 
189
                }
 
190
        
 
191
                /* Assign tag parameters */
 
192
                tag->parameters = *arg;
 
193
                *arg = sieve_ast_arguments_detach(*arg,1);
 
194
        } 
 
195
 
 
196
        cmd->data = (void *) TRUE;
 
197
 
 
198
        return TRUE;
 
199
}
 
200
 
 
201
/* 
 
202
 * Test registration 
 
203
 */
 
204
 
 
205
static bool tst_date_registered
 
206
(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg) 
 
207
{
 
208
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR);
 
209
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE);
 
210
 
 
211
        sieve_validator_register_tag
 
212
                (valdtr, cmd_reg, &date_zone_tag, OPT_DATE_ZONE);
 
213
        sieve_validator_register_tag
 
214
                (valdtr, cmd_reg, &date_originalzone_tag, OPT_DATE_ZONE);
 
215
 
 
216
        return TRUE;
 
217
}
 
218
 
 
219
static bool tst_currentdate_registered
 
220
(struct sieve_validator *valdtr, struct sieve_command_registration *cmd_reg) 
 
221
{
 
222
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR);
 
223
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE);
 
224
 
 
225
        sieve_validator_register_tag
 
226
                (valdtr, cmd_reg, &date_zone_tag, OPT_DATE_ZONE);
 
227
 
 
228
        return TRUE;
 
229
}
 
230
 
 
231
/* 
 
232
 * Validation 
 
233
 */
 
234
 
 
235
static bool tst_date_validate
 
236
        (struct sieve_validator *valdtr, struct sieve_command_context *tst) 
 
237
{
 
238
        struct sieve_ast_argument *arg = tst->first_positional;
 
239
        unsigned int arg_offset = 0 ;
 
240
                
 
241
        /* Check header name */
 
242
 
 
243
        if ( tst->command == &date_test ) {
 
244
                arg_offset = 1;
 
245
 
 
246
                if ( !sieve_validate_positional_argument
 
247
                        (valdtr, tst, arg, "header name", 1, SAAT_STRING) ) {
 
248
                        return FALSE;
 
249
                }
 
250
        
 
251
                if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
252
                        return FALSE;
 
253
 
 
254
                if ( !sieve_command_verify_headers_argument(valdtr, arg) )
 
255
            return FALSE;
 
256
 
 
257
                arg = sieve_ast_argument_next(arg);
 
258
        }
 
259
 
 
260
        /* Check date part */
 
261
 
 
262
        if ( !sieve_validate_positional_argument
 
263
                (valdtr, tst, arg, "date part", arg_offset + 1, SAAT_STRING) ) {
 
264
                return FALSE;
 
265
        }
 
266
        
 
267
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
268
                return FALSE;
 
269
 
 
270
        arg = sieve_ast_argument_next(arg);
 
271
 
 
272
        /* Check key list */
 
273
                
 
274
        if ( !sieve_validate_positional_argument
 
275
                (valdtr, tst, arg, "key list", arg_offset + 2, SAAT_STRING_LIST) ) {
 
276
                return FALSE;
 
277
        }
 
278
 
 
279
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
 
280
                return FALSE;
 
281
        
 
282
        /* Validate the key argument to a specified match type */
 
283
        return sieve_match_type_validate
 
284
                (valdtr, tst, arg, &is_match_type, &i_ascii_casemap_comparator); 
 
285
}
 
286
 
 
287
/* 
 
288
 * Code generation 
 
289
 */
 
290
 
 
291
static bool tst_date_generate
 
292
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *tst) 
 
293
{
 
294
        if ( tst->command == &date_test )
 
295
                sieve_operation_emit_code(cgenv->sbin, &date_operation);
 
296
        else if ( tst->command == &currentdate_test )
 
297
                sieve_operation_emit_code(cgenv->sbin, &currentdate_operation);
 
298
        else
 
299
                i_unreached();
 
300
 
 
301
        /* Generate arguments */        
 
302
        return sieve_generate_arguments(cgenv, tst, NULL);
 
303
}
 
304
 
 
305
static bool tag_zone_generate
 
306
(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg,
 
307
    struct sieve_command_context *cmd)
 
308
{
 
309
        struct sieve_ast_argument *param = arg->parameters;
 
310
 
 
311
        if ( param == NULL ) {
 
312
                sieve_opr_omitted_emit(cgenv->sbin);
 
313
                return TRUE;
 
314
        }
 
315
 
 
316
        if ( param->argument != NULL && param->argument->generate != NULL )
 
317
                return param->argument->generate(cgenv, param, cmd);
 
318
 
 
319
        return FALSE;   
 
320
}
 
321
 
 
322
/* 
 
323
 * Code dump 
 
324
 */
 
325
 
 
326
static bool tst_date_operation_dump
 
327
(const struct sieve_operation *op,      
 
328
        const struct sieve_dumptime_env *denv, sieve_size_t *address)
 
329
{
 
330
        int opt_code = 0;
 
331
        const struct sieve_operand *operand;
 
332
 
 
333
        sieve_code_dumpf(denv, "%s", op->mnemonic);
 
334
        sieve_code_descend(denv);
 
335
        
 
336
        /* Handle any optional arguments */
 
337
  do {
 
338
                if ( !sieve_match_dump_optional_operands(denv, address, &opt_code) )
 
339
                        return FALSE;
 
340
 
 
341
                switch ( opt_code ) {
 
342
                case SIEVE_MATCH_OPT_END:
 
343
                        break;
 
344
                case OPT_DATE_ZONE:
 
345
                        operand = sieve_operand_read(denv->sbin, address);
 
346
                        if ( operand == NULL ) {
 
347
                                sieve_code_dumpf(denv, "ERROR: INVALID OPERAND");
 
348
                                return FALSE;
 
349
                        }                               
 
350
 
 
351
                        if ( sieve_operand_is_omitted(operand) ) {
 
352
                                sieve_code_dumpf(denv, "zone: ORIGINAL");
 
353
                        } else {
 
354
                                if ( !sieve_opr_string_dump_data
 
355
                                        (denv, operand, address, "zone") )
 
356
                                        return FALSE;
 
357
                        }
 
358
                        break;
 
359
    default:
 
360
                        return FALSE;
 
361
                }
 
362
        } while ( opt_code != SIEVE_MATCH_OPT_END );
 
363
 
 
364
        if ( op == &date_operation &&
 
365
                !sieve_opr_string_dump(denv, address, "header name") )
 
366
                return FALSE;
 
367
 
 
368
        return
 
369
                sieve_opr_string_dump(denv, address, "date part") && 
 
370
                sieve_opr_stringlist_dump(denv, address, "key list");
 
371
}
 
372
 
 
373
/* 
 
374
 * Code execution 
 
375
 */
 
376
 
 
377
static int tst_date_operation_execute
 
378
(const struct sieve_operation *op, 
 
379
        const struct sieve_runtime_env *renv, sieve_size_t *address)
 
380
{       
 
381
        bool result = TRUE, zone_specified = FALSE, got_date = FALSE, matched = FALSE;
 
382
        int opt_code = 0;
 
383
        const struct sieve_message_data *msgdata = renv->msgdata;
 
384
        const struct sieve_comparator *cmp = &i_ascii_casemap_comparator;
 
385
        const struct sieve_match_type *mtch = &is_match_type;
 
386
        const struct sieve_operand *operand;
 
387
        struct sieve_match_context *mctx;
 
388
        string_t *header_name = NULL, *date_part = NULL, *zone = NULL;
 
389
        struct sieve_coded_stringlist *key_list;
 
390
        time_t date_value, local_time;
 
391
        struct tm *date_tm;
 
392
        const char *part_value;
 
393
        int local_zone = 0, original_zone = 0, wanted_zone = 0;
 
394
        int ret;
 
395
        
 
396
        /* Read optional operands */
 
397
        do {
 
398
                if ( (ret=sieve_match_read_optional_operands
 
399
                        (renv, address, &opt_code, &cmp, &mtch)) <= 0 )
 
400
                        return ret;
 
401
 
 
402
                switch ( opt_code ) {
 
403
                case SIEVE_MATCH_OPT_END:
 
404
                        break;
 
405
                case OPT_DATE_ZONE:
 
406
                        operand = sieve_operand_read(renv->sbin, address);
 
407
                        if ( operand == NULL ) {
 
408
                                sieve_runtime_trace_error(renv, "invalid operand");
 
409
                                return SIEVE_EXEC_BIN_CORRUPT;
 
410
                        }
 
411
 
 
412
                        if ( !sieve_operand_is_omitted(operand) ) {
 
413
                                if ( !sieve_opr_string_read_data
 
414
                                        (renv, operand, address, &zone) ) {
 
415
                                        sieve_runtime_trace_error(renv, "invalid zone operand");
 
416
                                        return SIEVE_EXEC_BIN_CORRUPT;
 
417
                                }
 
418
                        }
 
419
 
 
420
                        zone_specified = TRUE;
 
421
                        break;
 
422
                default:
 
423
                        sieve_runtime_trace_error(renv, "unknown optional operand");
 
424
                        return SIEVE_EXEC_BIN_CORRUPT;
 
425
                }
 
426
        } while ( opt_code != SIEVE_MATCH_OPT_END );
 
427
 
 
428
 
 
429
        if ( op == &date_operation ) {
 
430
                /* Read header name */
 
431
                if ( !sieve_opr_string_read(renv, address, &header_name) ) {
 
432
                        sieve_runtime_trace_error(renv, "invalid header-name operand");
 
433
                        return SIEVE_EXEC_BIN_CORRUPT;
 
434
                }
 
435
        }
 
436
 
 
437
        /* Read date part */
 
438
        if ( !sieve_opr_string_read(renv, address, &date_part) ) {
 
439
                sieve_runtime_trace_error(renv, "invalid date-part operand");
 
440
                return SIEVE_EXEC_BIN_CORRUPT;
 
441
        }
 
442
                
 
443
        /* Read key-list */
 
444
        if ( (key_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
 
445
                sieve_runtime_trace_error(renv, "invalid key-list operand");
 
446
                return SIEVE_EXEC_BIN_CORRUPT;
 
447
        }
 
448
 
 
449
        /* Perform test */
 
450
 
 
451
        sieve_runtime_trace(renv, "%s test", op->mnemonic);
 
452
 
 
453
        /* Get the date value */
 
454
 
 
455
        local_time = ext_date_get_current_date(renv, &local_zone);
 
456
 
 
457
        if ( op ==      &date_operation ) {
 
458
                const char *header_value;
 
459
                const char *date_string;
 
460
 
 
461
                /* Get date from the message */
 
462
 
 
463
                /* Read first header
 
464
                 *   NOTE: need something for index extension to hook into some time. 
 
465
                 */
 
466
                if ( (ret=mail_get_first_header
 
467
                        (msgdata->mail, str_c(header_name), &header_value)) > 0 ) {
 
468
 
 
469
                        /* Extract the date string value */
 
470
                        date_string = strrchr(header_value, ';');
 
471
                        if ( date_string == NULL )
 
472
                                /* Direct header value */
 
473
                                date_string = header_value;
 
474
                        else {
 
475
                                /* Delimited by ';', e.g. a Received: header */
 
476
                                date_string++; 
 
477
                        }
 
478
 
 
479
                        /* Parse the date value */
 
480
                        if ( message_date_parse((const unsigned char *) date_string,
 
481
                                strlen(date_string), &date_value, &original_zone) ) {
 
482
                                got_date = TRUE;
 
483
                        }
 
484
                }
 
485
        } else if ( op == &currentdate_operation ) {
 
486
                /* Use time stamp recorded at the time the script first started */
 
487
 
 
488
                date_value = local_time;
 
489
                original_zone = local_zone;
 
490
                got_date = TRUE;
 
491
 
 
492
        } else {
 
493
                i_unreached();
 
494
        }
 
495
 
 
496
        if ( got_date ) {
 
497
                /* Apply wanted timezone */
 
498
 
 
499
                if ( !zone_specified )
 
500
                        wanted_zone = local_zone;
 
501
                else if ( zone == NULL 
 
502
                        || !ext_date_parse_timezone(str_c(zone), &wanted_zone) ) {
 
503
 
 
504
                        /* FIXME: warn about parse failures */
 
505
                        wanted_zone = original_zone;
 
506
                }
 
507
 
 
508
                date_value += wanted_zone * 60;
 
509
 
 
510
                /* Convert timestamp to struct tm */
 
511
 
 
512
                if ( (date_tm=gmtime(&date_value)) == NULL ) {
 
513
                        got_date = FALSE;
 
514
                } else {
 
515
                        /* Extract the date part */
 
516
                        part_value = ext_date_part_extract
 
517
                                (str_c(date_part), date_tm, wanted_zone);
 
518
                }
 
519
        }
 
520
 
 
521
        /* Initialize match */
 
522
        mctx = sieve_match_begin(renv->interp, mtch, cmp, NULL, key_list);      
 
523
        
 
524
        if ( got_date && part_value != NULL ) {         
 
525
                /* Match value */
 
526
                if ( (ret=sieve_match_value(mctx, part_value, strlen(part_value))) < 0 )
 
527
                        result = FALSE;
 
528
                else
 
529
                        matched = ret > 0;
 
530
        }
 
531
 
 
532
        /* Finish match */
 
533
        if ( (ret=sieve_match_end(&mctx)) < 0 ) 
 
534
                result = FALSE;
 
535
        else
 
536
                matched = ( ret > 0 || matched );
 
537
        
 
538
        /* Set test result for subsequent conditional jump */
 
539
        if ( result ) {
 
540
                sieve_interpreter_set_test_result(renv->interp, matched);
 
541
                return SIEVE_EXEC_OK;
 
542
        }       
 
543
 
 
544
        sieve_runtime_trace_error(renv, "invalid string-list item");
 
545
        return SIEVE_EXEC_BIN_CORRUPT;
 
546
}