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

« back to all changes in this revision

Viewing changes to src/imap/imap-sort.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
 
/* Implementation of draft-ietf-imapext-sort-10 sorting algorithm.
4
 
   Pretty messy code actually, adding any sort types requires care.
5
 
   This is pretty fast however and takes only as much memory as needed to be
6
 
   reasonably fast. */
7
 
 
8
 
#include "common.h"
9
 
#include "array.h"
10
 
#include "hash.h"
11
 
#include "ostream.h"
12
 
#include "str.h"
13
 
#include "imap-base-subject.h"
14
 
#include "mail-storage.h"
15
 
#include "message-address.h"
16
 
#include "imap-sort.h"
17
 
 
18
 
#include <stdlib.h>
19
 
 
20
 
#define MAX_WANTED_HEADERS 10
21
 
#define STRBUF_SIZE 1024
22
 
 
23
 
#define IS_SORT_STRING(type) \
24
 
        ((type) == MAIL_SORT_CC || (type) == MAIL_SORT_FROM || \
25
 
         (type) == MAIL_SORT_SUBJECT || (type) == MAIL_SORT_TO)
26
 
 
27
 
#define IS_SORT_TIME(type) \
28
 
        ((type) == MAIL_SORT_ARRIVAL || (type) == MAIL_SORT_DATE)
29
 
 
30
 
struct sort_context {
31
 
        enum mail_sort_type sort_program[MAX_SORT_PROGRAM_SIZE];
32
 
 
33
 
        struct mailbox *box;
34
 
        struct ostream *output;
35
 
        string_t *str;
36
 
 
37
 
        bool written;
38
 
};
39
 
 
40
 
int imap_sort(struct client_command_context *cmd, const char *charset,
41
 
              struct mail_search_arg *args,
42
 
              const enum mail_sort_type *sort_program)
43
 
{
44
 
        struct client *client = cmd->client;
45
 
        const char *wanted_headers[2];
46
 
        enum mail_fetch_field wanted_fields;
47
 
        struct mail_search_context *search_ctx;
48
 
        struct mailbox_transaction_context *t;
49
 
        struct mailbox_header_lookup_ctx *headers_ctx;
50
 
        struct mail *mail;
51
 
        string_t *str;
52
 
        bool written = FALSE;
53
 
        int ret;
54
 
 
55
 
        wanted_fields = 0;
56
 
        wanted_headers[0] = wanted_headers[1] = NULL;
57
 
        switch (*sort_program & MAIL_SORT_MASK) {
58
 
        case MAIL_SORT_ARRIVAL:
59
 
                wanted_fields = MAIL_FETCH_RECEIVED_DATE;
60
 
                break;
61
 
        case MAIL_SORT_CC:
62
 
                wanted_headers[0] = "Cc";
63
 
                break;
64
 
        case MAIL_SORT_DATE:
65
 
                wanted_fields = MAIL_FETCH_DATE;
66
 
                break;
67
 
        case MAIL_SORT_FROM:
68
 
                wanted_headers[0] = "From";
69
 
                break;
70
 
        case MAIL_SORT_SIZE:
71
 
                wanted_fields = MAIL_FETCH_VIRTUAL_SIZE;
72
 
                break;
73
 
        case MAIL_SORT_SUBJECT:
74
 
                wanted_headers[0] = "Subject";
75
 
                break;
76
 
        case MAIL_SORT_TO:
77
 
                wanted_headers[0] = "To";
78
 
                break;
79
 
        }
80
 
 
81
 
        headers_ctx = wanted_headers[0] == NULL ? NULL :
82
 
                mailbox_header_lookup_init(client->mailbox, wanted_headers);
83
 
 
84
 
        t = mailbox_transaction_begin(client->mailbox, 0);
85
 
        search_ctx = mailbox_search_init(t, charset, args, sort_program);
86
 
 
87
 
        str = t_str_new(STRBUF_SIZE);
88
 
        str_append(str, "* SORT");
89
 
 
90
 
        mail = mail_alloc(t, wanted_fields, headers_ctx);
91
 
        while (mailbox_search_next(search_ctx, mail) > 0) {
92
 
                if (str_len(str) >= STRBUF_SIZE-MAX_INT_STRLEN) {
93
 
                        o_stream_send(client->output, str_data(str),
94
 
                                      str_len(str));
95
 
                        str_truncate(str, 0);
96
 
                        written = TRUE;
97
 
                }
98
 
                str_printfa(str, " %u", cmd->uid ? mail->uid : mail->seq);
99
 
        }
100
 
        ret = mailbox_search_deinit(&search_ctx);
101
 
        mail_free(&mail);
102
 
 
103
 
        if (mailbox_transaction_commit(&t) < 0)
104
 
                ret = -1;
105
 
 
106
 
        if (written || ret == 0) {
107
 
                str_append(str, "\r\n");
108
 
                o_stream_send(client->output, str_data(str), str_len(str));
109
 
        }
110
 
 
111
 
        if (headers_ctx != NULL)
112
 
                mailbox_header_lookup_deinit(&headers_ctx);
113
 
        return ret;
114
 
}