~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/pop3/pop3-commands.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
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 "pop3-common.h"
4
4
#include "array.h"
130
130
static void cmd_list_callback(struct client *client)
131
131
{
132
132
        struct cmd_list_context *ctx = client->cmd_context;
133
 
        int ret = 1;
134
133
 
135
134
        for (; ctx->msgnum != client->messages_count; ctx->msgnum++) {
136
 
                if (ret == 0) {
 
135
                if (client->output->closed)
 
136
                        break;
 
137
                if (POP3_CLIENT_OUTPUT_FULL(client)) {
137
138
                        /* buffer full */
138
139
                        return;
139
140
                }
144
145
                                continue;
145
146
                }
146
147
 
147
 
                ret = client_send_line(client, "%u %"PRIuUOFF_T, ctx->msgnum+1,
148
 
                                       client->message_sizes[ctx->msgnum]);
149
 
                if (ret < 0)
150
 
                        break;
 
148
                client_send_line(client, "%u %"PRIuUOFF_T, ctx->msgnum+1,
 
149
                                 client->message_sizes[ctx->msgnum]);
151
150
        }
152
151
 
153
152
        client_send_line(client, ".");
197
196
pop3_search_build(struct client *client, uint32_t seq)
198
197
{
199
198
        struct mail_search_args *search_args;
 
199
        struct mail_search_arg *sarg;
200
200
 
201
201
        search_args = mail_search_build_init();
202
202
        if (seq == 0) {
203
 
                mail_search_build_add_seqset(search_args,
204
 
                                             1, client->messages_count);
 
203
                sarg = mail_search_build_add(search_args, SEARCH_SEQSET);
 
204
                sarg->value.seqset = client->all_seqs;
205
205
        } else {
206
206
                mail_search_build_add_seqset(search_args, seq, seq);
207
207
        }
223
223
        return 0;
224
224
}
225
225
 
 
226
static void client_expunge(struct client *client, struct mail *mail)
 
227
{
 
228
        if (client->deleted_kw != NULL)
 
229
                mail_update_keywords(mail, MODIFY_ADD, client->deleted_kw);
 
230
        else
 
231
                mail_expunge(mail);
 
232
        client->expunged_count++;
 
233
}
 
234
 
226
235
bool client_update_mails(struct client *client)
227
236
{
228
237
        struct mail_search_args *search_args;
251
260
                bit = 1 << (msgnum % CHAR_BIT);
252
261
                if (client->deleted_bitmask != NULL &&
253
262
                    (client->deleted_bitmask[msgnum / CHAR_BIT] & bit) != 0) {
254
 
                        mail_expunge(mail);
255
 
                        client->expunged_count++;
 
263
                        client_expunge(client, mail);
256
264
                } else if (client->seen_bitmask != NULL &&
257
265
                           (client->seen_bitmask[msgnum / CHAR_BIT] & bit) != 0) {
258
266
                        mail_update_flags(mail, MODIFY_ADD, MAIL_SEEN);
391
399
 
392
400
        if (ctx->last != '\n') {
393
401
                /* didn't end with CRLF */
394
 
                (void)o_stream_send(client->output, "\r\n", 2);
 
402
                o_stream_nsend(client->output, "\r\n", 2);
395
403
        }
396
404
 
397
405
        if (!ctx->in_body &&
398
406
            (client->set->parsed_workarounds & WORKAROUND_OE_NS_EOH) != 0) {
399
407
                /* Add the missing end of headers line. */
400
 
                (void)o_stream_send(client->output, "\r\n", 2);
 
408
                o_stream_nsend(client->output, "\r\n", 2);
401
409
        }
402
410
 
403
411
        *ctx->byte_counter +=
512
520
                        mail_update_flags(mail, MODIFY_REMOVE, MAIL_SEEN);
513
521
                (void)mailbox_search_deinit(&search_ctx);
514
522
 
515
 
                mailbox_transaction_commit(&client->trans);
 
523
                (void)mailbox_transaction_commit(&client->trans);
516
524
                client->trans = mailbox_transaction_begin(client->mailbox, 0);
517
525
        }
518
526
 
587
595
        tab[0].value = t_strdup_printf("%u", client->uid_validity);
588
596
 
589
597
        if ((client->uidl_keymask & UIDL_UID) != 0) {
590
 
                i_snprintf(uid_str, sizeof(uid_str), "%u",
591
 
                           mail->uid);
 
598
                if (i_snprintf(uid_str, sizeof(uid_str), "%u",
 
599
                               mail->uid) < 0)
 
600
                        i_unreached();
592
601
                tab[1].value = uid_str;
593
602
        }
594
603
        if ((client->uidl_keymask & UIDL_MD5) != 0) {
625
634
list_uidls_saved_iter(struct client *client, struct cmd_uidl_context *ctx)
626
635
{
627
636
        bool found = FALSE;
628
 
        int ret;
629
637
 
630
638
        while (ctx->msgnum < client->messages_count) {
631
639
                uint32_t msgnum = ctx->msgnum++;
637
645
                }
638
646
                found = TRUE;
639
647
 
640
 
                ret = client_send_line(client,
641
 
                                       ctx->list_all ? "%u %s" : "+OK %u %s",
642
 
                                       msgnum+1, client->message_uidls[msgnum]);
643
 
                if (ret < 0 || !ctx->list_all)
 
648
                client_send_line(client,
 
649
                                 ctx->list_all ? "%u %s" : "+OK %u %s",
 
650
                                 msgnum+1, client->message_uidls[msgnum]);
 
651
                if (client->output->closed || !ctx->list_all)
644
652
                        break;
645
 
                if (ret == 0) {
 
653
                if (POP3_CLIENT_OUTPUT_FULL(client)) {
646
654
                        /* output is being buffered, continue when there's
647
655
                           more space */
648
656
                        return FALSE;
660
668
static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
661
669
{
662
670
        string_t *str;
663
 
        int ret;
664
671
        bool permanent_uidl, found = FALSE;
665
672
 
666
673
        if (client->message_uidls != NULL)
684
691
                if (client->set->pop3_save_uidl && !permanent_uidl)
685
692
                        mail_update_pop3_uidl(ctx->mail, str_c(str));
686
693
 
687
 
                ret = client_send_line(client,
688
 
                                       ctx->list_all ? "%u %s" : "+OK %u %s",
689
 
                                       msgnum+1, str_c(str));
690
 
                if (ret < 0)
 
694
                client_send_line(client, ctx->list_all ? "%u %s" : "+OK %u %s",
 
695
                                 msgnum+1, str_c(str));
 
696
                if (client->output->closed)
691
697
                        break;
692
 
                if (ret == 0 && ctx->list_all) {
 
698
                if (POP3_CLIENT_OUTPUT_FULL(client) && ctx->list_all) {
693
699
                        /* output is being buffered, continue when there's
694
700
                           more space */
695
701
                        return FALSE;
714
720
        (void)list_uids_iter(client, ctx);
715
721
}
716
722
 
717
 
static void uidl_rename_duplicate(string_t *uidl, struct hash_table *prev_uidls)
 
723
HASH_TABLE_DEFINE_TYPE(uidl_counter, char *, void *);
 
724
 
 
725
static void
 
726
uidl_rename_duplicate(string_t *uidl, HASH_TABLE_TYPE(uidl_counter) prev_uidls)
718
727
{
719
 
        void *key, *value;
 
728
        char *key;
 
729
        void *value;
720
730
        unsigned int counter;
721
731
 
722
732
        while (hash_table_lookup_full(prev_uidls, str_c(uidl), &key, &value)) {
734
744
        struct mail_search_context *search_ctx;
735
745
        struct mail_search_args *search_args;
736
746
        struct mail *mail;
737
 
        struct hash_table *prev_uidls;
 
747
        HASH_TABLE_TYPE(uidl_counter) prev_uidls;
738
748
        string_t *str;
739
749
        char *uidl;
740
750
        enum mail_fetch_field wanted_fields;
755
765
 
756
766
        uidl_duplicates_rename =
757
767
                strcmp(client->set->pop3_uidl_duplicates, "rename") == 0;
758
 
        prev_uidls = hash_table_create(default_pool, default_pool, 0,
759
 
                                      str_hash, (hash_cmp_callback_t *)strcmp);
 
768
        hash_table_create(&prev_uidls, default_pool, 0, str_hash, strcmp);
760
769
        client->uidl_pool = pool_alloconly_create("message uidls", 1024);
761
770
        client->message_uidls = p_new(client->uidl_pool, const char *,
762
 
                                      client->messages_count);
 
771
                                      client->messages_count+1);
763
772
 
764
773
        str = t_str_new(128); msgnum = 0;
765
774
        while (mailbox_search_next(search_ctx, &mail)) {