~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/imap/cmd-create.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "imap-common.h"
4
4
#include "imap-resp-code.h"
7
7
 
8
8
bool cmd_create(struct client_command_context *cmd)
9
9
{
10
 
        enum mailbox_name_status status;
11
10
        struct mail_namespace *ns;
12
 
        const char *mailbox, *storage_name;
 
11
        const char *mailbox, *orig_mailbox;
13
12
        struct mailbox *box;
14
13
        bool directory;
15
14
        size_t len;
18
17
        if (!client_read_string_args(cmd, 1, &mailbox))
19
18
                return FALSE;
20
19
 
21
 
        ns = client_find_namespace(cmd, mailbox, &storage_name, NULL);
 
20
        orig_mailbox = mailbox;
 
21
        ns = client_find_namespace(cmd, &mailbox);
22
22
        if (ns == NULL)
23
23
                return TRUE;
24
24
 
25
 
        len = strlen(mailbox);
26
 
        if (len == 0 || mailbox[len-1] != ns->sep)
 
25
        len = strlen(orig_mailbox);
 
26
        if (len == 0 || orig_mailbox[len-1] != mail_namespace_get_sep(ns))
27
27
                directory = FALSE;
28
 
        else if (*storage_name == '\0') {
29
 
                client_send_tagline(cmd, "NO ["IMAP_RESP_CODE_ALREADYEXISTS
30
 
                                    "] Namespace already exists.");
31
 
                return TRUE;
32
 
        } else {
 
28
        else {
33
29
                /* name ends with hierarchy separator - client is just
34
30
                   informing us that it wants to create children under this
35
31
                   mailbox. */
36
32
                directory = TRUE;
37
 
                storage_name = t_strndup(storage_name, strlen(storage_name)-1);
38
 
                mailbox = t_strndup(mailbox, len-1);
39
 
        }
40
 
 
41
 
        ns = client_find_namespace(cmd, mailbox, &storage_name, &status);
42
 
        if (ns == NULL)
43
 
                return TRUE;
44
 
        switch (status) {
45
 
        case MAILBOX_NAME_VALID:
46
 
                break;
47
 
        case MAILBOX_NAME_EXISTS_DIR:
48
 
                if (!directory)
49
 
                        break;
50
 
                /* fall through */
51
 
        case MAILBOX_NAME_EXISTS_MAILBOX:
52
 
        case MAILBOX_NAME_INVALID:
53
 
        case MAILBOX_NAME_NOINFERIORS:
54
 
                client_fail_mailbox_name_status(cmd, mailbox, NULL, status);
55
 
                return TRUE;
56
 
        }
57
 
 
58
 
        box = mailbox_alloc(ns->list, storage_name, 0);
 
33
 
 
34
                /* drop separator from mailbox. it's already dropped when
 
35
                   WORKAROUND_TB_EXTRA_MAILBOX_SEP is enabled */
 
36
                if (len == strlen(mailbox))
 
37
                        mailbox = t_strndup(mailbox, len-1);
 
38
        }
 
39
 
 
40
        box = mailbox_alloc(ns->list, mailbox, 0);
59
41
        if (mailbox_create(box, NULL, directory) < 0)
60
42
                client_send_storage_error(cmd, mailbox_get_storage(box));
61
43
        else