]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added MAIL_SORT_POP3_ORDER
authorTimo Sirainen <tss@iki.fi>
Wed, 4 May 2011 09:43:16 +0000 (11:43 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 4 May 2011 09:43:16 +0000 (11:43 +0200)
src/lib-storage/index/index-sort.c
src/lib-storage/mail-storage.h

index 753b6d8a46b18a6c76537c8aff449eb30f4e1803..9e03d65da35bc952ea3d72b2c410f5eac4e05135 100644 (file)
@@ -81,6 +81,30 @@ index_sort_list_add_size(struct mail_search_sort_program *program,
                node->size = 0;
 }
 
+static uoff_t index_sort_get_pop3_order(struct mail *mail)
+{
+       const char *str;
+       uoff_t size;
+
+       if (mail_get_special(mail, MAIL_FETCH_POP3_ORDER, &str) < 0 ||
+           str_to_uoff(str, &size) < 0)
+               return (uint32_t)-1;
+       else
+               return size;
+}
+
+static void
+index_sort_list_add_pop3_order(struct mail_search_sort_program *program,
+                              struct mail *mail)
+{
+       ARRAY_TYPE(mail_sort_node_size) *nodes = program->context;
+       struct mail_sort_node_size *node;
+
+       node = array_append_space(nodes);
+       node->seq = mail->seq;
+       node->size = index_sort_get_pop3_order(mail);
+}
+
 static float index_sort_get_score(struct mail *mail)
 {
        const char *str;
@@ -283,6 +307,16 @@ index_sort_program_init(struct mailbox_transaction_context *t,
                program->context = nodes;
                break;
        }
+       case MAIL_SORT_POP3_ORDER: {
+               ARRAY_TYPE(mail_sort_node_size) *nodes;
+
+               nodes = i_malloc(sizeof(*nodes));
+               i_array_init(nodes, 128);
+               program->sort_list_add = index_sort_list_add_pop3_order;
+               program->sort_list_finish = index_sort_list_finish_size;
+               program->context = nodes;
+               break;
+       }
        default:
                i_unreached();
        }
@@ -486,6 +520,17 @@ int index_sort_node_cmp_type(struct mail *mail,
                ret = float1 < float2 ? -1 :
                        (float1 > float2 ? 1 : 0);
                break;
+       case MAIL_SORT_POP3_ORDER:
+               /* 32bit numbers would be enough, but since there is already
+                  existing code for uoff_t in sizes, just use them. */
+               mail_set_seq(mail, seq1);
+               size1 = index_sort_get_pop3_order(mail);
+               mail_set_seq(mail, seq2);
+               size2 = index_sort_get_pop3_order(mail);
+
+               ret = size1 < size2 ? -1 :
+                       (size1 > size2 ? 1 : 0);
+               break;
        case MAIL_SORT_END:
                return seq1 < seq2 ? -1 :
                        (seq1 > seq2 ? 1 : 0);
index a410c03ceef654c97cb776fec0d9d65278c39a41..32c9bc4cdfe13e621a52a79a2c7e511ada815603 100644 (file)
@@ -92,6 +92,7 @@ enum mail_sort_type {
        MAIL_SORT_SEARCH_SCORE  = 0x0080,
        MAIL_SORT_DISPLAYFROM   = 0x0100,
        MAIL_SORT_DISPLAYTO     = 0x0200,
+       MAIL_SORT_POP3_ORDER    = 0x0400,
 
        MAIL_SORT_MASK          = 0x0fff,
        MAIL_SORT_FLAG_REVERSE  = 0x1000, /* reverse this mask type */