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

« back to all changes in this revision

Viewing changes to src/imap/cmd-thread.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
1
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "common.h"
4
 
#include "buffer.h"
 
4
#include "str.h"
 
5
#include "ostream.h"
5
6
#include "commands.h"
6
 
#include "imap-search.h"
7
 
#include "imap-thread.h"
 
7
#include "imap-search-args.h"
 
8
#include "mail-thread.h"
 
9
 
 
10
static int imap_thread_write(struct mail_thread_iterate_context *iter,
 
11
                             string_t *str, bool root)
 
12
{
 
13
        const struct mail_thread_child_node *node;
 
14
        struct mail_thread_iterate_context *child_iter;
 
15
        unsigned int count;
 
16
        int ret = 0;
 
17
 
 
18
        count = mail_thread_iterate_count(iter);
 
19
        if (count == 0)
 
20
                return 0;
 
21
 
 
22
        if (count == 1 && !root) {
 
23
                /* only one child - special case to avoid extra paranthesis */
 
24
                node = mail_thread_iterate_next(iter, &child_iter);
 
25
                str_printfa(str, "%u", node->uid);
 
26
                if (child_iter != NULL) {
 
27
                        str_append_c(str, ' ');
 
28
                        T_BEGIN {
 
29
                                ret = imap_thread_write(child_iter, str, FALSE);
 
30
                        } T_END;
 
31
                        if (mail_thread_iterate_deinit(&child_iter) < 0)
 
32
                                return -1;
 
33
                }
 
34
                return ret;
 
35
        }
 
36
 
 
37
        while ((node = mail_thread_iterate_next(iter, &child_iter)) != NULL) {
 
38
                if (child_iter == NULL) {
 
39
                        /* no children */
 
40
                        str_printfa(str, "(%u)", node->uid);
 
41
                } else {
 
42
                        /* node with children */
 
43
                        str_append_c(str, '(');
 
44
                        if (node->uid != 0)
 
45
                                str_printfa(str, "%u ", node->uid);
 
46
                        T_BEGIN {
 
47
                                ret = imap_thread_write(child_iter, str, FALSE);
 
48
                        } T_END;
 
49
                        if (mail_thread_iterate_deinit(&child_iter) < 0 ||
 
50
                            ret < 0)
 
51
                                return -1;
 
52
                        str_append_c(str, ')');
 
53
                }
 
54
        }
 
55
        return 0;
 
56
}
 
57
 
 
58
static int
 
59
imap_thread_write_reply(struct mail_thread_context *ctx, string_t *str,
 
60
                        enum mail_thread_type thread_type, bool write_seqs)
 
61
{
 
62
        struct mail_thread_iterate_context *iter;
 
63
        int ret;
 
64
 
 
65
        iter = mail_thread_iterate_init(ctx, thread_type, write_seqs);
 
66
        str_append(str, "* THREAD ");
 
67
        T_BEGIN {
 
68
                ret = imap_thread_write(iter, str, TRUE);
 
69
        } T_END;
 
70
        if (mail_thread_iterate_deinit(&iter) < 0)
 
71
                ret = -1;
 
72
 
 
73
        str_append(str, "\r\n");
 
74
        return ret;
 
75
}
 
76
 
 
77
static int imap_thread(struct client_command_context *cmd,
 
78
                       struct mail_search_args *search_args,
 
79
                       enum mail_thread_type thread_type)
 
80
{
 
81
        struct mail_thread_context *ctx;
 
82
        string_t *str;
 
83
        int ret;
 
84
 
 
85
        i_assert(thread_type == MAIL_THREAD_REFERENCES ||
 
86
                 thread_type == MAIL_THREAD_REFS);
 
87
 
 
88
        str = str_new(default_pool, 1024);
 
89
        ret = mail_thread_init(cmd->client->mailbox,
 
90
                               search_args, &ctx);
 
91
        if (ret == 0) {
 
92
                ret = imap_thread_write_reply(ctx, str, thread_type,
 
93
                                              !cmd->uid);
 
94
                mail_thread_deinit(&ctx);
 
95
        }
 
96
 
 
97
        if (ret == 0) {
 
98
                (void)o_stream_send(cmd->client->output,
 
99
                                    str_data(str), str_len(str));
 
100
        }
 
101
        str_free(&str);
 
102
        return ret;
 
103
}
8
104
 
9
105
bool cmd_thread(struct client_command_context *cmd)
10
106
{
11
107
        struct client *client = cmd->client;
12
 
        enum mail_thread_type threading;
13
 
        struct mail_search_arg *sargs;
 
108
        enum mail_thread_type thread_type;
 
109
        struct mail_search_args *sargs;
14
110
        const struct imap_arg *args;
15
 
        int args_count;
16
 
        pool_t pool;
17
 
        const char *error, *charset, *str;
 
111
        const char *charset, *str;
 
112
        int ret;
18
113
 
19
 
        args_count = imap_parser_read_args(cmd->parser, 0, 0, &args);
20
 
        if (args_count == -2)
 
114
        if (!client_read_args(cmd, 0, 0, &args))
21
115
                return FALSE;
22
 
        client->input_lock = NULL;
23
 
 
24
 
        if (args_count < 3) {
25
 
                client_send_command_error(cmd, args_count < 0 ? NULL :
26
 
                                          "Missing or invalid arguments.");
27
 
                return TRUE;
28
 
        }
29
116
 
30
117
        if (!client_verify_open_mailbox(cmd))
31
118
                return TRUE;
37
124
        }
38
125
 
39
126
        str = IMAP_ARG_STR(args);
40
 
        if (strcasecmp(str, "REFERENCES") == 0)
41
 
                threading = MAIL_THREAD_REFERENCES;
42
 
        else if (strcasecmp(str, "ORDEREDSUBJECT") == 0) {
43
 
                client_send_command_error(cmd,
44
 
                        "ORDEREDSUBJECT threading is currently not supported.");
45
 
                return TRUE;
46
 
        } else {
 
127
        if (!mail_thread_type_parse(str, &thread_type)) {
47
128
                client_send_command_error(cmd, "Unknown thread algorithm.");
48
129
                return TRUE;
49
130
        }
51
132
 
52
133
        /* charset */
53
134
        if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
54
 
                client_send_command_error(cmd,
55
 
                                          "Invalid charset argument.");
 
135
                client_send_command_error(cmd, "Invalid charset argument.");
56
136
                return TRUE;
57
137
        }
58
138
        charset = IMAP_ARG_STR(args);
59
139
        args++;
60
140
 
61
 
        pool = pool_alloconly_create("mail_search_args", 2048);
 
141
        ret = imap_search_args_build(cmd, args, charset, &sargs);
 
142
        if (ret <= 0)
 
143
                return ret < 0;
62
144
 
63
 
        sargs = imap_search_args_build(pool, client->mailbox, args, &error);
64
 
        if (sargs == NULL) {
65
 
                /* error in search arguments */
66
 
                client_send_tagline(cmd, t_strconcat("BAD ", error, NULL));
67
 
        } else if (imap_thread(cmd, charset, sargs, threading) == 0) {
68
 
                pool_unref(&pool);
69
 
                return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
70
 
                                (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
71
 
                                0, "OK Thread completed.");
72
 
        } else {
 
145
        ret = imap_thread(cmd, sargs, thread_type);
 
146
        mail_search_args_unref(&sargs);
 
147
        if (ret < 0) {
73
148
                client_send_storage_error(cmd,
74
149
                                          mailbox_get_storage(client->mailbox));
 
150
                return TRUE;
75
151
        }
76
152
 
77
 
        pool_unref(&pool);
78
 
        return TRUE;
 
153
        return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST |
 
154
                        (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES),
 
155
                        0, "OK Thread completed.");
79
156
}