~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to pigeonhole/src/lib-sieve/ext-envelope.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file
 
1
/* Copyright (c) 2002-2013 Pigeonhole authors, see the included COPYING file
2
2
 */
3
3
 
4
4
/* Extension envelope
40
40
const struct sieve_operation_def envelope_operation;
41
41
const struct sieve_extension_def envelope_extension;
42
42
 
43
 
/* 
44
 
 * Extension 
 
43
/*
 
44
 * Extension
45
45
 */
46
46
 
47
47
static bool ext_envelope_validator_load
48
48
(const struct sieve_extension *ext, struct sieve_validator *valdtr);
49
49
 
50
 
const struct sieve_extension_def envelope_extension = { 
51
 
        "envelope", 
52
 
        NULL, NULL,
53
 
        ext_envelope_validator_load, 
54
 
        NULL, NULL, NULL, NULL, NULL,
55
 
        SIEVE_EXT_DEFINE_OPERATION(envelope_operation), 
56
 
        SIEVE_EXT_DEFINE_NO_OPERANDS 
 
50
const struct sieve_extension_def envelope_extension = {
 
51
        .name = "envelope",
 
52
        .validator_load = ext_envelope_validator_load,
 
53
        SIEVE_EXT_DEFINE_OPERATION(envelope_operation)
57
54
};
58
55
 
59
56
static bool ext_envelope_validator_load
65
62
        return TRUE;
66
63
}
67
64
 
68
 
/* 
69
 
 * Envelope test 
 
65
/*
 
66
 * Envelope test
70
67
 *
71
68
 * Syntax
72
69
 *   envelope [COMPARATOR] [ADDRESS-PART] [MATCH-TYPE]
73
 
 *     <envelope-part: string-list> <key-list: string-list>   
 
70
 *     <envelope-part: string-list> <key-list: string-list>
74
71
 */
75
72
 
76
73
static bool tst_envelope_registered
81
78
static bool tst_envelope_generate
82
79
        (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
83
80
 
84
 
static const struct sieve_command_def envelope_test = { 
85
 
        "envelope", 
86
 
        SCT_TEST, 
 
81
static const struct sieve_command_def envelope_test = {
 
82
        "envelope",
 
83
        SCT_TEST,
87
84
        2, 0, FALSE, FALSE,
88
 
        tst_envelope_registered, 
 
85
        tst_envelope_registered,
89
86
        NULL,
90
87
        tst_envelope_validate,
91
 
        NULL, 
92
 
        tst_envelope_generate, 
93
 
        NULL 
 
88
        NULL,
 
89
        tst_envelope_generate,
 
90
        NULL
94
91
};
95
92
 
96
 
/* 
97
 
 * Envelope operation 
 
93
/*
 
94
 * Envelope operation
98
95
 */
99
96
 
100
97
static bool ext_envelope_operation_dump
102
99
static int ext_envelope_operation_execute
103
100
        (const struct sieve_runtime_env *renv, sieve_size_t *address);
104
101
 
105
 
const struct sieve_operation_def envelope_operation = { 
 
102
const struct sieve_operation_def envelope_operation = {
106
103
        "ENVELOPE",
107
104
        &envelope_extension,
108
105
        0,
109
 
        ext_envelope_operation_dump, 
110
 
        ext_envelope_operation_execute 
 
106
        ext_envelope_operation_dump,
 
107
        ext_envelope_operation_execute
111
108
};
112
109
 
113
110
/*
146
143
        "to",
147
144
        _to_part_get_addresses,
148
145
        _to_part_get_values,
149
 
};      
 
146
};
150
147
 
151
148
static const struct sieve_envelope_part _auth_part = {
152
149
        "auth",
153
150
        NULL,
154
151
        _auth_part_get_values,
155
 
};      
 
152
};
156
153
 
157
154
static const struct sieve_envelope_part *_envelope_parts[] = {
158
155
        /* Required */
159
 
        &_from_part, &_to_part, 
 
156
        &_from_part, &_to_part,
160
157
 
161
158
        /* Non-standard */
162
159
        &_auth_part
174
171
                        return _envelope_parts[i];
175
172
        }
176
173
        }
177
 
        
 
174
 
178
175
        return NULL;
179
176
}
180
177
 
183
180
static const struct sieve_address *const *_from_part_get_addresses
184
181
(const struct sieve_runtime_env *renv)
185
182
{
186
 
        ARRAY_DEFINE(envelope_values, const struct sieve_address *);
 
183
        ARRAY(const struct sieve_address *) envelope_values;
187
184
        const struct sieve_address *address =
188
185
                sieve_message_get_sender_address(renv->msgctx);
189
 
        
 
186
 
190
187
        if ( address != NULL ) {
191
188
                t_array_init(&envelope_values, 2);
192
189
 
194
191
 
195
192
            (void)array_append_space(&envelope_values);
196
193
        return array_idx(&envelope_values, 0);
197
 
        } 
 
194
        }
198
195
 
199
196
        return NULL;
200
197
}
202
199
static const char *const *_from_part_get_values
203
200
(const struct sieve_runtime_env *renv)
204
201
{
205
 
        ARRAY_DEFINE(envelope_values, const char *);
 
202
        ARRAY(const char *) envelope_values;
206
203
 
207
204
        t_array_init(&envelope_values, 2);
208
205
 
218
215
static const struct sieve_address *const *_to_part_get_addresses
219
216
(const struct sieve_runtime_env *renv)
220
217
{
221
 
        ARRAY_DEFINE(envelope_values, const struct sieve_address *);
222
 
        const struct sieve_address *address = 
223
 
                sieve_message_get_orig_recipient_address(renv->msgctx); 
 
218
        ARRAY(const struct sieve_address *) envelope_values;
 
219
        const struct sieve_address *address =
 
220
                sieve_message_get_orig_recipient_address(renv->msgctx);
224
221
 
225
222
        if ( address != NULL && address->local_part != NULL ) {
226
223
                t_array_init(&envelope_values, 2);
237
234
static const char *const *_to_part_get_values
238
235
(const struct sieve_runtime_env *renv)
239
236
{
240
 
        ARRAY_DEFINE(envelope_values, const char *);
 
237
        ARRAY(const char *) envelope_values;
241
238
 
242
239
        t_array_init(&envelope_values, 2);
243
240
 
253
250
static const char *const *_auth_part_get_values
254
251
(const struct sieve_runtime_env *renv)
255
252
{
256
 
        ARRAY_DEFINE(envelope_values, const char *);
 
253
        ARRAY(const char *) envelope_values;
257
254
 
258
255
        t_array_init(&envelope_values, 2);
259
256
 
274
271
static int sieve_envelope_address_list_next_string_item
275
272
        (struct sieve_stringlist *_strlist, string_t **str_r);
276
273
static int sieve_envelope_address_list_next_item
277
 
        (struct sieve_address_list *_addrlist, struct sieve_address *addr_r, 
 
274
        (struct sieve_address_list *_addrlist, struct sieve_address *addr_r,
278
275
                string_t **unparsed_r);
279
276
static void sieve_envelope_address_list_reset
280
277
        (struct sieve_stringlist *_strlist);
289
286
        const struct sieve_address *const *cur_addresses;
290
287
        const char * const *cur_values;
291
288
 
292
 
        int value_index; 
 
289
        int value_index;
293
290
};
294
291
 
295
292
static struct sieve_address_list *sieve_envelope_address_list_create
296
293
(const struct sieve_runtime_env *renv, struct sieve_stringlist *env_parts)
297
294
{
298
295
        struct sieve_envelope_address_list *addrlist;
299
 
            
 
296
 
300
297
        addrlist = t_new(struct sieve_envelope_address_list, 1);
301
298
        addrlist->addrlist.strlist.runenv = renv;
302
299
        addrlist->addrlist.strlist.exec_status = SIEVE_EXEC_OK;
303
 
        addrlist->addrlist.strlist.next_item = 
 
300
        addrlist->addrlist.strlist.next_item =
304
301
                sieve_envelope_address_list_next_string_item;
305
302
        addrlist->addrlist.strlist.reset = sieve_envelope_address_list_reset;
306
303
        addrlist->addrlist.next_item = sieve_envelope_address_list_next_item;
307
304
        addrlist->env_parts = env_parts;
308
 
  
 
305
 
309
306
        return &addrlist->addrlist;
310
307
}
311
308
 
312
309
static int sieve_envelope_address_list_next_item
313
 
(struct sieve_address_list *_addrlist, struct sieve_address *addr_r, 
 
310
(struct sieve_address_list *_addrlist, struct sieve_address *addr_r,
314
311
        string_t **unparsed_r)
315
312
{
316
 
        struct sieve_envelope_address_list *addrlist = 
317
 
                (struct sieve_envelope_address_list *) _addrlist;       
 
313
        struct sieve_envelope_address_list *addrlist =
 
314
                (struct sieve_envelope_address_list *) _addrlist;
318
315
        const struct sieve_runtime_env *renv = _addrlist->strlist.runenv;
319
316
 
320
317
        if ( addr_r != NULL ) addr_r->local_part = NULL;
326
323
                int ret;
327
324
 
328
325
                /* Read next header value from source list */
329
 
                if ( (ret=sieve_stringlist_next_item(addrlist->env_parts, &envp_item)) 
 
326
                if ( (ret=sieve_stringlist_next_item(addrlist->env_parts, &envp_item))
330
327
                        <= 0 )
331
328
                        return ret;
332
329
 
335
332
                                "getting `%s' part from message envelope",
336
333
                                str_sanitize(str_c(envp_item), 80));
337
334
                }
338
 
                        
 
335
 
339
336
                if ( (epart=_envelope_part_find(str_c(envp_item))) != NULL ) {
340
337
                        addrlist->value_index = 0;
341
338
 
347
344
                                if ( addrlist->cur_addresses != NULL &&
348
345
                                        addrlist->cur_addresses[0] == NULL )
349
346
                                        addrlist->cur_addresses = NULL;
350
 
                        }  
 
347
                        }
351
348
 
352
349
                        if ( addrlist->cur_addresses == NULL && epart->get_values != NULL ) {
353
350
                                /* Field contains something else */
359
356
                        }
360
357
                }
361
358
        }
362
 
        
 
359
 
363
360
        /* Return next item */
364
361
        if ( addrlist->cur_addresses != NULL ) {
365
 
                const struct sieve_address *addr = 
 
362
                const struct sieve_address *addr =
366
363
                        addrlist->cur_addresses[addrlist->value_index];
367
364
 
368
365
                if ( addr->local_part == NULL ) {
369
366
                        /* Null path <> */
370
 
                        if ( unparsed_r != NULL ) 
 
367
                        if ( unparsed_r != NULL )
371
368
                                *unparsed_r = t_str_new_const("", 0);
372
369
                } else {
373
370
                        if ( addr_r != NULL )
411
408
 
412
409
        if ( addr.local_part != NULL ) {
413
410
                const char *addr_str = sieve_address_to_string(&addr);
414
 
                *str_r = t_str_new_const(addr_str, strlen(addr_str));
 
411
                if (str_r != NULL)
 
412
                        *str_r = t_str_new_const(addr_str, strlen(addr_str));
415
413
        }
416
414
 
417
415
        return 1;
420
418
static void sieve_envelope_address_list_reset
421
419
(struct sieve_stringlist *_strlist)
422
420
{
423
 
        struct sieve_envelope_address_list *addrlist = 
 
421
        struct sieve_envelope_address_list *addrlist =
424
422
                (struct sieve_envelope_address_list *)_strlist;
425
423
 
426
424
        sieve_stringlist_reset(addrlist->env_parts);
429
427
        addrlist->value_index = 0;
430
428
}
431
429
 
432
 
/* 
433
 
 * Command Registration 
 
430
/*
 
431
 * Command Registration
434
432
 */
435
433
 
436
434
static bool tst_envelope_registered
437
435
(struct sieve_validator *valdtr, const struct sieve_extension *ext ATTR_UNUSED,
438
 
        struct sieve_command_registration *cmd_reg) 
 
436
        struct sieve_command_registration *cmd_reg)
439
437
{
440
438
        /* The order of these is not significant */
441
439
        sieve_comparators_link_tag(valdtr, cmd_reg, SIEVE_AM_OPT_COMPARATOR);
442
440
        sieve_address_parts_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_ADDRESS_PART);
443
441
        sieve_match_types_link_tags(valdtr, cmd_reg, SIEVE_AM_OPT_MATCH_TYPE);
444
 
        
 
442
 
445
443
        return TRUE;
446
444
}
447
445
 
448
 
/* 
449
 
 * Validation 
 
446
/*
 
447
 * Validation
450
448
 */
451
 
 
 
449
 
452
450
static int _envelope_part_is_supported
453
451
(void *context, struct sieve_ast_argument *arg)
454
452
{
463
461
                                if ( *not_address == NULL )
464
462
                                        *not_address = epart;
465
463
                        }
466
 
                                        
 
464
 
467
465
                        return TRUE;
468
466
                }
469
 
                
 
467
 
470
468
                return FALSE;
471
 
        } 
472
 
        
 
469
        }
 
470
 
473
471
        return TRUE; /* Can't check at compile time */
474
472
}
475
473
 
476
474
static bool tst_envelope_validate
477
 
(struct sieve_validator *valdtr, struct sieve_command *tst) 
478
 
{               
 
475
(struct sieve_validator *valdtr, struct sieve_command *tst)
 
476
{
479
477
        struct sieve_ast_argument *arg = tst->first_positional;
480
478
        struct sieve_ast_argument *epart;
481
 
        struct sieve_comparator cmp_default = 
 
479
        struct sieve_comparator cmp_default =
482
480
                SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator);
483
 
        struct sieve_match_type mcht_default = 
 
481
        struct sieve_match_type mcht_default =
484
482
                SIEVE_MATCH_TYPE_DEFAULT(is_match_type);
485
483
        const struct sieve_envelope_part *not_address = NULL;
486
 
                                
 
484
 
487
485
        if ( !sieve_validate_positional_argument
488
486
                (valdtr, tst, arg, "envelope part", 1, SAAT_STRING_LIST) ) {
489
487
                return FALSE;
490
488
        }
491
 
        
 
489
 
492
490
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
493
491
                return FALSE;
494
 
                
 
492
 
495
493
        /* Check whether supplied envelope parts are supported
496
 
         *   FIXME: verify dynamic envelope parts at runtime 
 
494
         *   FIXME: verify dynamic envelope parts at runtime
497
495
         */
498
496
        epart = arg;
499
 
        if ( !sieve_ast_stringlist_map(&epart, (void *) &not_address, 
500
 
                _envelope_part_is_supported) ) {                
501
 
                
502
 
                sieve_argument_validate_error(valdtr, epart, 
503
 
                        "specified envelope part '%s' is not supported by the envelope test", 
 
497
        if ( !sieve_ast_stringlist_map(&epart, (void *) &not_address,
 
498
                _envelope_part_is_supported) ) {
 
499
 
 
500
                sieve_argument_validate_error(valdtr, epart,
 
501
                        "specified envelope part '%s' is not supported by the envelope test",
504
502
                                str_sanitize(sieve_ast_strlist_strc(epart), 64));
505
503
                return FALSE;
506
504
        }
507
505
 
508
506
        if ( not_address != NULL ) {
509
 
                struct sieve_ast_argument *addrp_arg = 
 
507
                struct sieve_ast_argument *addrp_arg =
510
508
                        sieve_command_find_argument(tst, &address_part_tag);
511
509
 
512
510
                if ( addrp_arg != NULL ) {
517
515
                return FALSE;
518
516
                }
519
517
        }
520
 
        
 
518
 
521
519
        arg = sieve_ast_argument_next(arg);
522
 
        
 
520
 
523
521
        if ( !sieve_validate_positional_argument
524
522
                (valdtr, tst, arg, "key list", 2, SAAT_STRING_LIST) ) {
525
523
                return FALSE;
526
524
        }
527
 
        
 
525
 
528
526
        if ( !sieve_validator_argument_activate(valdtr, tst, arg, FALSE) )
529
527
                return FALSE;
530
528
 
536
534
/*
537
535
 * Code generation
538
536
 */
539
 
 
 
537
 
540
538
static bool tst_envelope_generate
541
 
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) 
 
539
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
542
540
{
543
541
        (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &envelope_operation);
544
542
 
549
547
        return TRUE;
550
548
}
551
549
 
552
 
/* 
553
 
 * Code dump 
 
550
/*
 
551
 * Code dump
554
552
 */
555
 
 
 
553
 
556
554
static bool ext_envelope_operation_dump
557
555
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
558
556
{
575
573
static int ext_envelope_operation_execute
576
574
(const struct sieve_runtime_env *renv, sieve_size_t *address)
577
575
{
578
 
        struct sieve_comparator cmp = 
 
576
        struct sieve_comparator cmp =
579
577
                SIEVE_COMPARATOR_DEFAULT(i_ascii_casemap_comparator);
580
 
        struct sieve_match_type mcht = 
 
578
        struct sieve_match_type mcht =
581
579
                SIEVE_MATCH_TYPE_DEFAULT(is_match_type);
582
 
        struct sieve_address_part addrp = 
 
580
        struct sieve_address_part addrp =
583
581
                SIEVE_ADDRESS_PART_DEFAULT(all_address_part);
584
582
        struct sieve_stringlist *env_part_list, *value_list, *key_list;
585
583
        struct sieve_address_list *addr_list;
604
602
                <= 0 )
605
603
                return ret;
606
604
 
607
 
        /* 
 
605
        /*
608
606
         * Perform test
609
607
         */
610
608