~ubuntu-branches/ubuntu/quantal/dovecot/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-06-29 09:21:32 UTC
  • mfrom: (4.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20100629092132-q4pr5lfuvmjqou19
Tags: 1:1.2.12-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  + Add mail-stack-delivery as per server-maverick-mail-integration spec:
   - Update debian/rules
   - Convert existing package to a dummy package and add new binary in debian/control
   - Update maintainer scripts.
   - Move previously installed backups and config files to new package name
     space in preinst
   - Add new debian/mail-stack-delivery.prerm to handle downgrades
   - Rename debian/dovecot-postfix.* to debian/mail-stack-delivery.*
  + 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/*.
  + Add ufw integration:
    - Created debian/dovecot-common.ufw.profile.
    - debian/rules: install profile.
    - debian/control: suggest ufw.
  + debian/{control,rules}: enable PIE hardening.
  + debian/control: Update Vcs-* headers.
  + Add SMTP-AUTH support for Outlook (login auth mechanism) 
  + debian/dovecot-common.dirs: Added usr/share/doc/dovecot-common
  + debian/patches/fix-dovecot-config-parser.patch: Fix ordering of external config 
    files. (LP: #597818)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        (struct sieve_validator *valdtr, struct sieve_command *tst);
30
30
static bool tst_date_generate
31
31
        (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
32
 
 
 
32
 
33
33
/* Date test
34
34
 *
35
35
 * Syntax:
42
42
        (struct sieve_validator *valdtr, const struct sieve_extension *ext,
43
43
                struct sieve_command_registration *cmd_reg);
44
44
 
45
 
const struct sieve_command_def date_test = { 
46
 
        "date", 
47
 
        SCT_TEST, 
 
45
const struct sieve_command_def date_test = {
 
46
        "date",
 
47
        SCT_TEST,
48
48
        3, 0, FALSE, FALSE,
49
49
        tst_date_registered,
50
 
        NULL, 
51
 
        tst_date_validate, 
52
 
        tst_date_generate, 
53
 
        NULL 
 
50
        NULL,
 
51
        tst_date_validate,
 
52
        tst_date_generate,
 
53
        NULL
54
54
};
55
55
 
56
56
/* Currentdate test
57
 
 * 
 
57
 *
58
58
 * Syntax:
59
59
 *    currentdate [":zone" <time-zone: string>]
60
60
 *                [COMPARATOR] [MATCH-TYPE]
65
65
        (struct sieve_validator *valdtr, const struct sieve_extension *ext,
66
66
                struct sieve_command_registration *cmd_reg);
67
67
 
68
 
const struct sieve_command_def currentdate_test = { 
69
 
        "currentdate", 
70
 
        SCT_TEST, 
 
68
const struct sieve_command_def currentdate_test = {
 
69
        "currentdate",
 
70
        SCT_TEST,
71
71
        2, 0, FALSE, FALSE,
72
72
        tst_currentdate_registered,
73
 
        NULL, 
74
 
        tst_date_validate, 
75
 
        tst_date_generate, 
76
 
        NULL 
 
73
        NULL,
 
74
        tst_date_validate,
 
75
        tst_date_generate,
 
76
        NULL
77
77
};
78
78
 
79
 
/* 
80
 
 * Tagged arguments 
 
79
/*
 
80
 * Tagged arguments
81
81
 */
82
82
 
83
83
/* Forward declarations */
107
107
        tag_zone_generate
108
108
};
109
109
 
110
 
/* 
111
 
 * Date operation 
 
110
/*
 
111
 * Date operation
112
112
 */
113
113
 
114
114
static bool tst_date_operation_dump
116
116
static int tst_date_operation_execute
117
117
        (const struct sieve_runtime_env *renv, sieve_size_t *address);
118
118
 
119
 
const struct sieve_operation_def date_operation = { 
 
119
const struct sieve_operation_def date_operation = {
120
120
        "DATE",
121
121
        &date_extension,
122
122
        EXT_DATE_OPERATION_DATE,
123
 
        tst_date_operation_dump, 
124
 
        tst_date_operation_execute 
 
123
        tst_date_operation_dump,
 
124
        tst_date_operation_execute
125
125
};
126
126
 
127
 
const struct sieve_operation_def currentdate_operation = { 
 
127
const struct sieve_operation_def currentdate_operation = {
128
128
        "CURRENTDATE",
129
129
        &date_extension,
130
130
        EXT_DATE_OPERATION_CURRENTDATE,
131
 
        tst_date_operation_dump, 
132
 
        tst_date_operation_execute 
 
131
        tst_date_operation_dump,
 
132
        tst_date_operation_execute
133
133
};
134
134
 
135
135
/*
180
180
                /* Check it */
181
181
                if ( sieve_argument_is_string_literal(*arg) ) {
182
182
                        const char *zone = sieve_ast_argument_strc(*arg);
183
 
        
 
183
 
184
184
                        if ( !ext_date_parse_timezone(zone, NULL) ) {
185
185
                                sieve_argument_validate_warning(valdtr, *arg,
186
186
                                        "specified :zone argument '%s' is not a valid timezone",
187
187
                                        str_sanitize(zone, 40));
188
 
                        }               
 
188
                        }
189
189
                }
190
 
        
 
190
 
191
191
                /* Assign tag parameters */
192
192
                tag->parameters = *arg;
193
193
                *arg = sieve_ast_arguments_detach(*arg,1);
194
 
        } 
 
194
        }
195
195
 
196
196
        cmd->data = (void *) TRUE;
197
197
 
198
198
        return TRUE;
199
199
}
200
200
 
201
 
/* 
202
 
 * Test registration 
 
201
/*
 
202
 * Test registration
203
203
 */
204
204
 
205
205
static bool tst_date_registered
206
206
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
207
 
        struct sieve_command_registration *cmd_reg) 
 
207
        struct sieve_command_registration *cmd_reg)
208
208
{
209
209
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR);
210
210
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE);
219
219
 
220
220
static bool tst_currentdate_registered
221
221
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
222
 
        struct sieve_command_registration *cmd_reg) 
 
222
        struct sieve_command_registration *cmd_reg)
223
223
{
224
224
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_MATCH_OPT_COMPARATOR);
225
225
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_MATCH_OPT_MATCH_TYPE);
230
230
        return TRUE;
231
231
}
232
232
 
233
 
/* 
234
 
 * Validation 
 
233
/*
 
234
 * Validation
235
235
 */
236
 
 
 
236
 
237
237
static bool tst_date_validate
238
 
(struct sieve_validator *valdtr, struct sieve_command *tst) 
 
238
(struct sieve_validator *valdtr, struct sieve_command *tst)
239
239
{
240
240
        struct sieve_ast_argument *arg = tst->first_positional;
241
241
        unsigned int arg_offset = 0 ;
242
 
        const struct sieve_match_type mcht_default = 
 
242
        const struct sieve_match_type mcht_default =
243
243
                SIEVE_MATCH_TYPE_DEFAULT(is_match_type);
244
 
        const struct sieve_comparator cmp_default = 
 
244
        const struct sieve_comparator cmp_default =
245
245
                SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator);
246
 
                
 
246
 
247
247
        /* Check header name */
248
248
 
249
249
        if ( sieve_command_is(tst, date_test) ) {
253
253
                        (valdtr, tst, arg, "header name", 1, SAAT_STRING) ) {
254
254
                        return FALSE;
255
255
                }
256
 
        
 
256
 
257
257
                if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
258
258
                        return FALSE;
259
259
 
269
269
                (valdtr, tst, arg, "date part", arg_offset + 1, SAAT_STRING) ) {
270
270
                return FALSE;
271
271
        }
272
 
        
 
272
 
273
273
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
274
274
                return FALSE;
275
275
 
276
276
        arg = sieve_ast_argument_next(arg);
277
277
 
278
278
        /* Check key list */
279
 
                
 
279
 
280
280
        if ( !sieve_validate_positional_argument
281
281
                (valdtr, tst, arg, "key list", arg_offset + 2, SAAT_STRING_LIST) ) {
282
282
                return FALSE;
284
284
 
285
285
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
286
286
                return FALSE;
287
 
        
 
287
 
288
288
        /* Validate the key argument to a specified match type */
289
289
        return sieve_match_type_validate
290
 
                (valdtr, tst, arg, &mcht_default, &cmp_default); 
 
290
                (valdtr, tst, arg, &mcht_default, &cmp_default);
291
291
}
292
292
 
293
 
/* 
294
 
 * Code generation 
 
293
/*
 
294
 * Code generation
295
295
 */
296
296
 
297
297
static bool tst_date_generate
298
 
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) 
 
298
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst)
299
299
{
300
300
        if ( sieve_command_is(tst, date_test) )
301
301
                sieve_operation_emit(cgenv->sbin, tst->ext, &date_operation);
304
304
        else
305
305
                i_unreached();
306
306
 
307
 
        /* Generate arguments */        
 
307
        /* Generate arguments */
308
308
        return sieve_generate_arguments(cgenv, tst, NULL);
309
309
}
310
310
 
320
320
        return sieve_generate_argument_parameters(cgenv, cmd, arg);
321
321
}
322
322
 
323
 
/* 
324
 
 * Code dump 
 
323
/*
 
324
 * Code dump
325
325
 */
326
326
 
327
327
static bool tst_date_operation_dump
333
333
 
334
334
        sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(op));
335
335
        sieve_code_descend(denv);
336
 
        
 
336
 
337
337
        /* Handle any optional arguments */
338
338
  do {
339
339
                if ( !sieve_match_dump_optional_operands(denv, address, &opt_code) )
346
346
                        if ( !sieve_operand_read(denv->sbin, address, &operand) ) {
347
347
                                sieve_code_dumpf(denv, "ERROR: INVALID OPERAND");
348
348
                                return FALSE;
349
 
                        }                               
 
349
                        }
350
350
 
351
351
                        if ( sieve_operand_is_omitted(&operand) ) {
352
352
                                sieve_code_dumpf(denv, "zone: ORIGINAL");
366
366
                return FALSE;
367
367
 
368
368
        return
369
 
                sieve_opr_string_dump(denv, address, "date part") && 
 
369
                sieve_opr_string_dump(denv, address, "date part") &&
370
370
                sieve_opr_stringlist_dump(denv, address, "key list");
371
371
}
372
372
 
373
 
/* 
374
 
 * Code execution 
 
373
/*
 
374
 * Code execution
375
375
 */
376
376
 
377
377
static int tst_date_operation_execute
378
378
(const struct sieve_runtime_env *renv, sieve_size_t *address)
379
 
{       
 
379
{
380
380
        const struct sieve_operation *op = &renv->oprtn;
381
381
        bool result = TRUE, zone_specified = FALSE, got_date = FALSE, matched = FALSE;
382
382
        int opt_code = 0;
383
383
        const struct sieve_message_data *msgdata = renv->msgdata;
384
 
        struct sieve_match_type mcht = 
 
384
        struct sieve_match_type mcht =
385
385
                SIEVE_MATCH_TYPE_DEFAULT(is_match_type);
386
 
        struct sieve_comparator cmp = 
 
386
        struct sieve_comparator cmp =
387
387
                SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator);
388
388
        struct sieve_operand operand;
389
389
        struct sieve_match_context *mctx;
394
394
        const char *part_value;
395
395
        int local_zone = 0, original_zone = 0, wanted_zone = 0;
396
396
        int ret;
397
 
        
 
397
 
398
398
        /* Read optional operands */
399
399
        do {
400
400
                if ( (ret=sieve_match_read_optional_operands
440
440
                sieve_runtime_trace_error(renv, "invalid date-part operand");
441
441
                return SIEVE_EXEC_BIN_CORRUPT;
442
442
        }
443
 
                
 
443
 
444
444
        /* Read key-list */
445
445
        if ( (key_list=sieve_opr_stringlist_read(renv, address)) == NULL ) {
446
446
                sieve_runtime_trace_error(renv, "invalid key-list operand");
462
462
                /* Get date from the message */
463
463
 
464
464
                /* Read first header
465
 
                 *   NOTE: need something for index extension to hook into some time. 
 
465
                 *   NOTE: need something for index extension to hook into some time.
466
466
                 */
467
467
                if ( (ret=mail_get_first_header
468
468
                        (msgdata->mail, str_c(header_name), &header_value)) > 0 ) {
474
474
                                date_string = header_value;
475
475
                        else {
476
476
                                /* Delimited by ';', e.g. a Received: header */
477
 
                                date_string++; 
 
477
                                date_string++;
478
478
                        }
479
479
 
480
480
                        /* Parse the date value */
499
499
 
500
500
                if ( !zone_specified )
501
501
                        wanted_zone = local_zone;
502
 
                else if ( zone == NULL 
 
502
                else if ( zone == NULL
503
503
                        || !ext_date_parse_timezone(str_c(zone), &wanted_zone) ) {
504
504
 
505
505
                        /* FIXME: warn about parse failures */
520
520
        }
521
521
 
522
522
        /* Initialize match */
523
 
        mctx = sieve_match_begin(renv->interp, &mcht, &cmp, NULL, key_list);    
524
 
        
525
 
        if ( got_date && part_value != NULL ) {         
 
523
        mctx = sieve_match_begin(renv->interp, &mcht, &cmp, NULL, key_list);
 
524
 
 
525
        if ( got_date && part_value != NULL ) {
526
526
                /* Match value */
527
527
                if ( (ret=sieve_match_value(mctx, part_value, strlen(part_value))) < 0 )
528
528
                        result = FALSE;
531
531
        }
532
532
 
533
533
        /* Finish match */
534
 
        if ( (ret=sieve_match_end(&mctx)) < 0 ) 
 
534
        if ( (ret=sieve_match_end(&mctx)) < 0 )
535
535
                result = FALSE;
536
536
        else
537
537
                matched = ( ret > 0 || matched );
538
 
        
 
538
 
539
539
        /* Set test result for subsequent conditional jump */
540
540
        if ( result ) {
541
541
                sieve_interpreter_set_test_result(renv->interp, matched);
542
542
                return SIEVE_EXEC_OK;
543
 
        }       
 
543
        }
544
544
 
545
545
        sieve_runtime_trace_error(renv, "invalid string-list item");
546
546
        return SIEVE_EXEC_BIN_CORRUPT;