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

« back to all changes in this revision

Viewing changes to pigeonhole/src/lib-sieve/plugins/mailbox/tst-mailboxexists.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
#include "lib.h"
17
17
 
18
18
#include "ext-mailbox-common.h"
19
19
 
20
 
/* 
21
 
 * Mailboxexists command 
 
20
/*
 
21
 * Mailboxexists command
22
22
 *
23
23
 * Syntax:
24
24
 *    mailboxexists <mailbox-names: string-list>
29
29
static bool tst_mailboxexists_generate
30
30
        (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
31
31
 
32
 
const struct sieve_command_def mailboxexists_test = { 
33
 
        "mailboxexists", 
34
 
        SCT_TEST, 
 
32
const struct sieve_command_def mailboxexists_test = {
 
33
        "mailboxexists",
 
34
        SCT_TEST,
35
35
        1, 0, FALSE, FALSE,
36
36
        NULL, NULL,
37
37
        tst_mailboxexists_validate,
38
 
        NULL, 
39
 
        tst_mailboxexists_generate, 
40
 
        NULL 
 
38
        NULL,
 
39
        tst_mailboxexists_generate,
 
40
        NULL
41
41
};
42
42
 
43
 
/* 
 
43
/*
44
44
 * Mailboxexists operation
45
45
 */
46
46
 
49
49
static int tst_mailboxexists_operation_execute
50
50
        (const struct sieve_runtime_env *renv, sieve_size_t *address);
51
51
 
52
 
const struct sieve_operation_def mailboxexists_operation = { 
 
52
const struct sieve_operation_def mailboxexists_operation = {
53
53
        "MAILBOXEXISTS",
54
 
        &mailbox_extension, 
55
 
        0, 
56
 
        tst_mailboxexists_operation_dump, 
57
 
        tst_mailboxexists_operation_execute 
 
54
        &mailbox_extension,
 
55
        0,
 
56
        tst_mailboxexists_operation_dump,
 
57
        tst_mailboxexists_operation_execute
58
58
};
59
59
 
60
 
/* 
61
 
 * Test validation 
 
60
/*
 
61
 * Test validation
62
62
 */
63
63
 
64
64
static bool tst_mailboxexists_validate
65
 
(struct sieve_validator *valdtr, struct sieve_command *tst) 
66
 
{               
 
65
(struct sieve_validator *valdtr, struct sieve_command *tst)
 
66
{
67
67
        struct sieve_ast_argument *arg = tst->first_positional;
68
 
        
 
68
 
69
69
        if ( !sieve_validate_positional_argument
70
70
                (valdtr, tst, arg, "mailbox-names", 1, SAAT_STRING_LIST) ) {
71
71
                return FALSE;
72
72
        }
73
 
        
 
73
 
74
74
        return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
75
75
}
76
76
 
77
 
/* 
78
 
 * Test generation 
 
77
/*
 
78
 * Test generation
79
79
 */
80
80
 
81
81
static bool tst_mailboxexists_generate
82
 
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst) 
 
82
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst)
83
83
{
84
84
        sieve_operation_emit(cgenv->sblock, tst->ext, &mailboxexists_operation);
85
85
 
87
87
        return sieve_generate_arguments(cgenv, tst, NULL);
88
88
}
89
89
 
90
 
/* 
91
 
 * Code dump 
 
90
/*
 
91
 * Code dump
92
92
 */
93
93
 
94
94
static bool tst_mailboxexists_operation_dump
96
96
{
97
97
        sieve_code_dumpf(denv, "MAILBOXEXISTS");
98
98
        sieve_code_descend(denv);
99
 
                
 
99
 
100
100
        return
101
101
                sieve_opr_stringlist_dump(denv, address, "mailbox-names");
102
102
}
103
103
 
104
 
/* 
105
 
 * Code execution 
 
104
/*
 
105
 * Code execution
106
106
 */
107
107
 
108
108
static int tst_mailboxexists_operation_execute
110
110
{
111
111
        struct sieve_stringlist *mailbox_names;
112
112
        string_t *mailbox_item;
113
 
        bool trace = FALSE; 
 
113
        bool trace = FALSE;
114
114
        bool all_exist = TRUE;
115
115
        int ret;
116
116
 
117
117
        /*
118
 
         * Read operands 
 
118
         * Read operands
119
119
         */
120
 
        
 
120
 
121
121
        /* Read notify uris */
122
122
        if ( (ret=sieve_opr_stringlist_read
123
123
                (renv, address, "mailbox-names", &mailbox_names)) <= 0 )
124
124
                return ret;
125
 
        
 
125
 
126
126
        /*
127
127
         * Perform operation
128
128
         */
138
138
                int ret;
139
139
 
140
140
                mailbox_item = NULL;
141
 
                while ( (ret=sieve_stringlist_next_item(mailbox_names, &mailbox_item)) > 0 ) 
 
141
                while ( (ret=sieve_stringlist_next_item(mailbox_names, &mailbox_item)) > 0 )
142
142
                        {
143
143
                        struct mail_namespace *ns;
144
144
                        const char *mailbox = str_c(mailbox_item);
148
148
                        ns = mail_namespace_find(renv->scriptenv->user->namespaces, mailbox);
149
149
                        if ( ns == NULL) {
150
150
                                if ( trace ) {
151
 
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' not found", 
 
151
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' not found",
152
152
                                                str_sanitize(mailbox, 80));
153
153
                                }
154
154
 
160
160
                        box = mailbox_alloc(ns->list, mailbox, 0);
161
161
                        if ( mailbox_open(box) < 0 ) {
162
162
                                if ( trace ) {
163
 
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' cannot be opened", 
 
163
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' cannot be opened",
164
164
                                                str_sanitize(mailbox, 80));
165
165
                                }
166
166
 
172
172
                        /* Also fail when it is readonly */
173
173
                        if ( mailbox_is_readonly(box) ) {
174
174
                                if ( trace ) {
175
 
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' is read-only", 
 
175
                                        sieve_runtime_trace(renv, 0, "mailbox `%s' is read-only",
176
176
                                                str_sanitize(mailbox, 80));
177
177
                                }
178
178
 
184
184
                        /* FIXME: check acl for 'p' or 'i' ACL permissions as required by RFC */
185
185
 
186
186
                        if ( trace ) {
187
 
                                sieve_runtime_trace(renv, 0, "mailbox `%s' exists", 
 
187
                                sieve_runtime_trace(renv, 0, "mailbox `%s' exists",
188
188
                                        str_sanitize(mailbox, 80));
189
189
                        }
190
190
 
191
191
                        /* Close mailbox */
192
192
                        mailbox_free(&box);
193
193
                }
194
 
        
 
194
 
195
195
                if ( ret < 0 ) {
196
196
                        sieve_runtime_trace_error(renv, "invalid mailbox name item");
197
197
                        return SIEVE_EXEC_BIN_CORRUPT;
204
204
                else
205
205
                        sieve_runtime_trace(renv, 0, "some mailboxes are unavailable");
206
206
        }
207
 
        
 
207
 
208
208
        sieve_interpreter_set_test_result(renv->interp, all_exist);
209
209
        return SIEVE_EXEC_OK;
210
210
}