~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/imap/imap-commands-util.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
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 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "array.h"
15
15
#include "imap-commands-util.h"
16
16
 
17
17
struct mail_namespace *
18
 
client_find_namespace(struct client_command_context *cmd, const char **mailbox)
 
18
client_find_namespace_full(struct client *client,
 
19
                           const char **mailbox, const char **error_r)
19
20
{
20
 
        struct mail_namespace *namespaces = cmd->client->user->namespaces;
 
21
        struct mail_namespace *namespaces = client->user->namespaces;
21
22
        struct mail_namespace *ns;
22
23
        string_t *utf8_name;
23
24
 
24
25
        utf8_name = t_str_new(64);
25
26
        if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) {
26
 
                client_send_tagline(cmd, "NO Mailbox name is not valid mUTF-7");
 
27
                *error_r = "NO Mailbox name is not valid mUTF-7";
27
28
                return NULL;
28
29
        }
29
30
 
30
31
        ns = mail_namespace_find(namespaces, str_c(utf8_name));
31
 
        if (ns == NULL) {
32
 
                client_send_tagline(cmd, t_strdup_printf(
 
32
        if ((ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0 &&
 
33
            ns->prefix_len == 0) {
 
34
                /* this matched only the autocreated prefix="" namespace.
 
35
                   give a nice human-readable error message */
 
36
                *error_r = t_strdup_printf(
33
37
                        "NO Client tried to access nonexistent namespace. "
34
38
                        "(Mailbox name should probably be prefixed with: %s)",
35
 
                        mail_namespace_find_inbox(namespaces)->prefix));
 
39
                        mail_namespace_find_inbox(namespaces)->prefix);
36
40
                return NULL;
37
41
        }
38
42
 
39
 
        if ((cmd->client->set->parsed_workarounds &
 
43
        if ((client->set->parsed_workarounds &
40
44
                        WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
41
45
            str_len(utf8_name) > 0 &&
42
46
            str_c(utf8_name)[str_len(utf8_name)-1] == mail_namespace_get_sep(ns)) {
48
52
        return ns;
49
53
}
50
54
 
 
55
struct mail_namespace *
 
56
client_find_namespace(struct client_command_context *cmd, const char **mailbox)
 
57
{
 
58
        struct mail_namespace *ns;
 
59
        const char *error;
 
60
 
 
61
        ns = client_find_namespace_full(cmd->client, mailbox, &error);
 
62
        if (ns == NULL)
 
63
                client_send_tagline(cmd, error);
 
64
        return ns;
 
65
}
 
66
 
51
67
bool client_verify_open_mailbox(struct client_command_context *cmd)
52
68
{
53
69
        if (cmd->client->mailbox != NULL)
133
149
        case MAIL_ERROR_INUSE:
134
150
                resp_code = IMAP_RESP_CODE_INUSE;
135
151
                break;
 
152
        case MAIL_ERROR_CONVERSION:
 
153
        case MAIL_ERROR_INVALIDDATA:
 
154
                break;
136
155
        }
137
156
        if (resp_code == NULL || *error_string == '[')
138
157
                return t_strconcat("NO ", error_string, NULL);
195
214
{
196
215
        const char *atom;
197
216
        enum mail_flags flag;
198
 
        ARRAY_DEFINE(keywords, const char *);
 
217
        ARRAY(const char *) keywords;
199
218
 
200
219
        *flags_r = 0;
201
220
        *keywords_r = NULL;
215
234
                        if (flag != 0 && flag != MAIL_RECENT)
216
235
                                *flags_r |= flag;
217
236
                        else {
218
 
                                client_send_tagline(cmd, t_strconcat(
219
 
                                        "BAD Invalid system flag ",
220
 
                                        atom, NULL));
 
237
                                client_send_command_error(cmd, t_strconcat(
 
238
                                        "Invalid system flag ", atom, NULL));
221
239
                                return FALSE;
222
240
                        }
223
241
                } else {
231
249
        if (array_count(&keywords) == 0)
232
250
                *keywords_r = NULL;
233
251
        else {
234
 
                (void)array_append_space(&keywords); /* NULL-terminate */
 
252
                array_append_zero(&keywords); /* NULL-terminate */
235
253
                *keywords_r = array_idx(&keywords, 0);
236
254
        }
237
255
        return TRUE;
308
326
                array_append(dest, &all_names[kw_index], 1);
309
327
        }
310
328
 
311
 
        (void)array_append_space(dest);
 
329
        array_append_zero(dest);
312
330
        return array_idx(dest, 0);
313
331
}
314
332
 
315
 
bool mailbox_equals(const struct mailbox *box1,
316
 
                    const struct mail_namespace *ns2, const char *name2)
317
 
{
318
 
        struct mail_namespace *ns1 = mailbox_get_namespace(box1);
319
 
        const char *name1;
320
 
 
321
 
        if (ns1 != ns2)
322
 
                return FALSE;
323
 
 
324
 
        name1 = mailbox_get_vname(box1);
325
 
        if (strcmp(name1, name2) == 0)
326
 
                return TRUE;
327
 
 
328
 
        return strcasecmp(name1, "INBOX") == 0 &&
329
 
                strcasecmp(name2, "INBOX") == 0;
330
 
}
331
 
 
332
333
void msgset_generator_init(struct msgset_generator_context *ctx, string_t *str)
333
334
{
334
335
        memset(ctx, 0, sizeof(*ctx));
338
339
 
339
340
void msgset_generator_next(struct msgset_generator_context *ctx, uint32_t uid)
340
341
{
341
 
        if (uid != ctx->last_uid+1) {
 
342
        i_assert(uid > 0);
 
343
 
 
344
        if (uid-1 != ctx->last_uid) {
342
345
                if (ctx->first_uid == 0)
343
346
                        ;
344
347
                else if (ctx->first_uid == ctx->last_uid)