]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
MAIL_FETCH_UIDL_BACKEND crashed with non-maildir backends. Changed the API a
authorTimo Sirainen <tss@iki.fi>
Sat, 31 May 2008 10:47:11 +0000 (13:47 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 31 May 2008 10:47:11 +0000 (13:47 +0300)
bit and fixed/cleaned/optimized POP3 UIDL listing a bit.

--HG--
branch : HEAD

src/lib-storage/index/index-mail.c
src/lib-storage/index/maildir/maildir-mail.c
src/pop3/commands.c

index 447f7f5251eb3c11cf564f7c333548d77cf8ecae..82079b68a36d4c6a24eb5a8f84c8a68556d55cee 100644 (file)
@@ -991,6 +991,7 @@ int index_mail_get_special(struct mail *_mail,
                return 0;
        case MAIL_FETCH_FROM_ENVELOPE:
        case MAIL_FETCH_UIDL_FILE_NAME:
+       case MAIL_FETCH_UIDL_BACKEND:
                *value_r = "";
                return 0;
        case MAIL_FETCH_HEADER_MD5:
index 31ba4aed5fb7e39eb27f5749bb6136b19fa623d9..1eaf6aba787a40e842391beee020ee74876646bf 100644 (file)
@@ -430,12 +430,8 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
        } else if (field == MAIL_FETCH_UIDL_BACKEND) {
                uidl = maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid,
                                        MAILDIR_UIDLIST_REC_EXT_POP3_UIDL);
-               if (uidl != NULL) {
-                       *value_r = uidl;
-                       return 0;
-               } else {
-                       return -1;
-               }
+               *value_r = uidl != NULL ? uidl : "";
+               return 0;
        }
 
        return index_mail_get_special(_mail, field, value_r);
index d74a70c011c1c88add26e0ef22e92b490dd1aa1e..76fc7999aed7f928efb38b03699fde3bdf4aa6ef 100644 (file)
@@ -506,6 +506,49 @@ struct cmd_uidl_context {
        struct mail_search_seqset seqset;
 };
 
+static void pop3_get_uid(struct cmd_uidl_context *ctx,
+                        struct var_expand_table *tab, string_t *str)
+{
+       char uid_str[MAX_INT_STRLEN];
+       const char *uidl;
+
+       if (mail_get_special(ctx->mail, MAIL_FETCH_UIDL_BACKEND, &uidl) == 0 &&
+           *uidl != '\0') {
+               str_append(str, uidl);
+               return;
+       }
+
+       if (reuse_xuidl &&
+           mail_get_first_header(ctx->mail, "X-UIDL", &uidl) > 0) {
+               str_append(str, uidl);
+               return;
+       }
+
+       if ((uidl_keymask & UIDL_UID) != 0) {
+               i_snprintf(uid_str, sizeof(uid_str), "%u",
+                          ctx->mail->uid);
+               tab[1].value = uid_str;
+       }
+       if ((uidl_keymask & UIDL_MD5) != 0) {
+               if (mail_get_special(ctx->mail, MAIL_FETCH_HEADER_MD5,
+                                    &tab[2].value) < 0 ||
+                   *tab[2].value == '\0') {
+                       /* broken */
+                       i_fatal("UIDL: Header MD5 not found");
+               }
+       }
+       if ((uidl_keymask & UIDL_FILE_NAME) != 0) {
+               if (mail_get_special(ctx->mail,
+                                    MAIL_FETCH_UIDL_FILE_NAME,
+                                    &tab[3].value) < 0 ||
+                   *tab[3].value == '\0') {
+                       /* broken */
+                       i_fatal("UIDL: File name not found");
+               }
+       }
+       var_expand(str, uidl_format, tab);
+}
+
 static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
 {
        static struct var_expand_table static_tab[] = {
@@ -517,8 +560,6 @@ static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
        };
        struct var_expand_table *tab;
        string_t *str;
-       char uid_str[MAX_INT_STRLEN];
-       const char *uidl;
        int ret;
        bool found = FALSE;
 
@@ -536,41 +577,11 @@ static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
                }
                found = TRUE;
 
-               if ((uidl_keymask & UIDL_UID) != 0) {
-                       i_snprintf(uid_str, sizeof(uid_str), "%u",
-                                  ctx->mail->uid);
-                       tab[1].value = uid_str;
-               }
-               if ((uidl_keymask & UIDL_MD5) != 0) {
-                       if (mail_get_special(ctx->mail, MAIL_FETCH_HEADER_MD5,
-                                            &tab[2].value) < 0 ||
-                           *tab[2].value == '\0') {
-                               /* broken */
-                               i_fatal("UIDL: Header MD5 not found");
-                       }
-               }
-               if ((uidl_keymask & UIDL_FILE_NAME) != 0) {
-                       if (mail_get_special(ctx->mail,
-                                            MAIL_FETCH_UIDL_FILE_NAME,
-                                            &tab[3].value) < 0 ||
-                           *tab[3].value == '\0') {
-                               /* broken */
-                               i_fatal("UIDL: File name not found");
-                       }
-               }
-
                str_truncate(str, 0);
                str_printfa(str, ctx->message == 0 ? "%u " : "+OK %u ",
                            ctx->mail->seq);
-               
-               if (mail_get_special(ctx->mail, MAIL_FETCH_UIDL_BACKEND,
-                                    &uidl) == 0)
-                       str_append(str, uidl);
-               else if (reuse_xuidl &&
-                        mail_get_first_header(ctx->mail, "X-UIDL", &uidl) > 0)
-                       str_append(str, uidl);
-               else
-                       var_expand(str, uidl_format, tab);
+               pop3_get_uid(ctx, tab, str);
+
                ret = client_send_line(client, "%s", str_c(str));
                if (ret < 0)
                        break;