~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/imap/imap-search-args.c

  • Committer: Bazaar Package Importer
  • Author(s): CHuck Short, Chuck Short
  • Date: 2009-11-06 00:47:29 UTC
  • mfrom: (4.1.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106004729-i39n7v9e7d4h51f6
Tags: 1:1.2.6-1ubuntu1
* 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 restrictions
    - 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 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
   + debian/patches/dovecot-postfix.conf.diff:
     + 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.
   + debian/rules:
     - Create emtpy stamp.h.in files in dovecot-sieve/ and dovecot-managesieve/
       if they're not there since empty files are not included in the diff.gz 
       file.
   + Add SMTP-AUTH support for Outlook (login auth mechanism)
   + Dropped:
     - debian/patches/security-CVE-2009-3235: Applied upstream.
     - debian/patches/fix-pop3-assertion.dpatch: Applied upstream.
     - dovecot-sieve and dovecot-managesieve: Use the debian patches instead.

  [Chuck Short]
  - Updated dovecot-sieve to 0.1.13.
  - Updated dovecot-managesieve to 0.11.9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "common.h"
 
4
#include "mail-storage.h"
 
5
#include "mail-search-build.h"
 
6
#include "imap-search-args.h"
 
7
#include "imap-parser.h"
 
8
#include "imap-seqset.h"
 
9
 
 
10
#include <stdlib.h>
 
11
 
 
12
struct search_build_data {
 
13
        pool_t pool;
 
14
        struct mailbox *box;
 
15
        const char *error;
 
16
};
 
17
 
 
18
static bool search_args_have_searchres(struct mail_search_arg *sargs)
 
19
{
 
20
        for (; sargs != NULL; sargs = sargs->next) {
 
21
                switch (sargs->type) {
 
22
                case SEARCH_UIDSET:
 
23
                        if (strcmp(sargs->value.str, "$") == 0)
 
24
                                return TRUE;
 
25
                        break;
 
26
                case SEARCH_SUB:
 
27
                case SEARCH_OR:
 
28
                        if (search_args_have_searchres(sargs->value.subargs))
 
29
                                return TRUE;
 
30
                        break;
 
31
                default:
 
32
                        break;
 
33
                }
 
34
        }
 
35
        return FALSE;
 
36
}
 
37
 
 
38
int imap_search_args_build(struct client_command_context *cmd,
 
39
                           const struct imap_arg *args, const char *charset,
 
40
                           struct mail_search_args **search_args_r)
 
41
{
 
42
        struct mail_search_args *sargs;
 
43
        const char *error;
 
44
 
 
45
        if (args->type == IMAP_ARG_EOL) {
 
46
                client_send_command_error(cmd, "Missing search parameters");
 
47
                return -1;
 
48
        }
 
49
 
 
50
        if (mail_search_build_from_imap_args(args, charset,
 
51
                                             &sargs, &error) < 0) {
 
52
                client_send_command_error(cmd, error);
 
53
                return -1;
 
54
        }
 
55
 
 
56
        if (search_args_have_searchres(sargs->args)) {
 
57
                if (client_handle_search_save_ambiguity(cmd))
 
58
                        return 0;
 
59
        }
 
60
 
 
61
        mail_search_args_init(sargs, cmd->client->mailbox, TRUE,
 
62
                              &cmd->client->search_saved_uidset);
 
63
        *search_args_r = sargs;
 
64
        return 1;
 
65
}
 
66
 
 
67
static bool
 
68
msgset_is_valid(ARRAY_TYPE(seq_range) *seqset, uint32_t messages_count)
 
69
{
 
70
        const struct seq_range *range;
 
71
        unsigned int count;
 
72
 
 
73
        /* when there are no messages, all messagesets are invalid.
 
74
           if there's at least one message:
 
75
            - * gives seq1 = seq2 = (uint32_t)-1
 
76
            - n:* should work if n <= messages_count
 
77
            - n:m or m should work if m <= messages_count
 
78
        */
 
79
        range = array_get(seqset, &count);
 
80
        if (count == 0 || messages_count == 0)
 
81
                return FALSE;
 
82
 
 
83
        if (range[count-1].seq2 == (uint32_t)-1) {
 
84
                if (range[count-1].seq1 > messages_count &&
 
85
                    range[count-1].seq1 != (uint32_t)-1)
 
86
                        return FALSE;
 
87
        } else {
 
88
                if (range[count-1].seq2 > messages_count)
 
89
                        return FALSE;
 
90
        }
 
91
        return TRUE;
 
92
}
 
93
 
 
94
static int imap_search_get_msgset_arg(struct client_command_context *cmd,
 
95
                                      const char *messageset,
 
96
                                      struct mail_search_args **args_r,
 
97
                                      const char **error_r)
 
98
{
 
99
        struct mail_search_args *args;
 
100
 
 
101
        args = mail_search_build_init();
 
102
        args->args = p_new(args->pool, struct mail_search_arg, 1);
 
103
        args->args->type = SEARCH_SEQSET;
 
104
        p_array_init(&args->args->value.seqset, args->pool, 16);
 
105
        if (imap_seq_set_parse(messageset, &args->args->value.seqset) < 0 ||
 
106
            !msgset_is_valid(&args->args->value.seqset,
 
107
                             cmd->client->messages_count)) {
 
108
                *error_r = "Invalid messageset";
 
109
                return -1;
 
110
        }
 
111
        *args_r = args;
 
112
        return 0;
 
113
}
 
114
 
 
115
static int
 
116
imap_search_get_uidset_arg(struct client_command_context *cmd,
 
117
                           const char *uidset, struct mail_search_args **args_r,
 
118
                           const char **error_r)
 
119
{
 
120
        struct mail_search_args *args;
 
121
 
 
122
        args = mail_search_build_init();
 
123
        args->args = p_new(args->pool, struct mail_search_arg, 1);
 
124
        args->args->type = SEARCH_UIDSET;
 
125
        p_array_init(&args->args->value.seqset, cmd->pool, 16);
 
126
        if (imap_seq_set_parse(uidset, &args->args->value.seqset) < 0) {
 
127
                *error_r = "Invalid uidset";
 
128
                return -1;
 
129
        }
 
130
 
 
131
        *args_r = args;
 
132
        return 0;
 
133
}
 
134
 
 
135
int imap_search_get_seqset(struct client_command_context *cmd,
 
136
                           const char *set, bool uid,
 
137
                           struct mail_search_args **search_args_r)
 
138
{
 
139
        int ret;
 
140
 
 
141
        ret = imap_search_get_anyset(cmd, set, uid, search_args_r);
 
142
        if (ret > 0) {
 
143
                mail_search_args_init(*search_args_r,
 
144
                                      cmd->client->mailbox, TRUE,
 
145
                                      &cmd->client->search_saved_uidset);
 
146
        }
 
147
        return ret;
 
148
}
 
149
 
 
150
static int imap_search_get_searchres(struct client_command_context *cmd,
 
151
                                     struct mail_search_args **search_args_r)
 
152
{
 
153
        struct mail_search_args *search_args;
 
154
 
 
155
        if (client_handle_search_save_ambiguity(cmd))
 
156
                return 0;
 
157
 
 
158
        search_args = mail_search_build_init();
 
159
        search_args->args = p_new(search_args->pool, struct mail_search_arg, 1);
 
160
        if (array_is_created(&cmd->client->search_saved_uidset)) {
 
161
                search_args->args->type = SEARCH_UIDSET;
 
162
                p_array_init(&search_args->args->value.seqset,
 
163
                             search_args->pool,
 
164
                             array_count(&cmd->client->search_saved_uidset));
 
165
                array_append_array(&search_args->args->value.seqset,
 
166
                                   &cmd->client->search_saved_uidset);
 
167
        } else {
 
168
                /* $ not set yet, match nothing */
 
169
                search_args->args->type = SEARCH_ALL;
 
170
                search_args->args->not = TRUE;
 
171
        }
 
172
        *search_args_r = search_args;
 
173
        return 1;
 
174
}
 
175
 
 
176
int imap_search_get_anyset(struct client_command_context *cmd,
 
177
                           const char *set, bool uid,
 
178
                           struct mail_search_args **search_args_r)
 
179
{
 
180
        const char *error = NULL;
 
181
        int ret;
 
182
 
 
183
        if (strcmp(set, "$") == 0) {
 
184
                /* SEARCHRES extension: replace $ with the last saved
 
185
                   search result */
 
186
                return imap_search_get_searchres(cmd, search_args_r);
 
187
        }
 
188
        if (!uid) {
 
189
                ret = imap_search_get_msgset_arg(cmd, set, search_args_r,
 
190
                                                 &error);
 
191
        } else {
 
192
                ret = imap_search_get_uidset_arg(cmd, set, search_args_r,
 
193
                                                 &error);
 
194
        }
 
195
        if (ret < 0) {
 
196
                client_send_command_error(cmd, error);
 
197
                return -1;
 
198
        }
 
199
        return 1;
 
200
}