Merge pull request #62 from pitiphong-p/imap_sort

Add support for SORT command defined in IMAP RFC 5256
dvh-chacham15-master
DINH Viêt Hoà 10 years ago
commit aa74cb36be

@ -8,6 +8,12 @@
/* Begin PBXBuildFile section */
365DFFD215D1C93100F2DD85 /* xgmmsgid.c in Sources */ = {isa = PBXBuildFile; fileRef = 365DFFD115D1C93100F2DD85 /* xgmmsgid.c */; };
8A75ECDA17040F92007F9972 /* mailimap_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECD917040F91007F9972 /* mailimap_sort.c */; };
8A75ECDB17040F92007F9972 /* mailimap_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECD917040F91007F9972 /* mailimap_sort.c */; };
8A75ECDC17040F92007F9972 /* mailimap_sort.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECD917040F91007F9972 /* mailimap_sort.c */; };
8A75ECE6170414BA007F9972 /* mailimap_sort_types.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECE5170414B8007F9972 /* mailimap_sort_types.c */; };
8A75ECE7170414BA007F9972 /* mailimap_sort_types.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECE5170414B8007F9972 /* mailimap_sort_types.c */; };
8A75ECE8170414BA007F9972 /* mailimap_sort_types.c in Sources */ = {isa = PBXBuildFile; fileRef = 8A75ECE5170414B8007F9972 /* mailimap_sort_types.c */; };
C60E7B9A16C3809400A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
C60E7B9D16C3809C00A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
C60E7B9E16C3809D00A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
@ -557,6 +563,10 @@
/* Begin PBXFileReference section */
365DFFD115D1C93100F2DD85 /* xgmmsgid.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = xgmmsgid.c; sourceTree = "<group>"; };
365DFFD815D1CF1800F2DD85 /* xgmmsgid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xgmmsgid.h; sourceTree = "<group>"; };
8A75ECD917040F91007F9972 /* mailimap_sort.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mailimap_sort.c; sourceTree = "<group>"; };
8A75ECDD17040FBD007F9972 /* mailimap_sort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mailimap_sort.h; sourceTree = "<group>"; };
8A75ECE5170414B8007F9972 /* mailimap_sort_types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mailimap_sort_types.c; sourceTree = "<group>"; };
8A75ECEA170414E9007F9972 /* mailimap_sort_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mailimap_sort_types.h; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* libetpan.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = libetpan.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C60E7B9816C3809400A25BF4 /* enable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = enable.c; sourceTree = "<group>"; };
@ -1503,6 +1513,10 @@
C6F61F731701409B0073032E /* xgmthrid.h */,
C6667DED1342ACCD00969A8E /* xlist.c */,
C6667DEE1342ACCD00969A8E /* xlist.h */,
8A75ECD917040F91007F9972 /* mailimap_sort.c */,
8A75ECDD17040FBD007F9972 /* mailimap_sort.h */,
8A75ECE5170414B8007F9972 /* mailimap_sort_types.c */,
8A75ECEA170414E9007F9972 /* mailimap_sort_types.h */,
);
path = imap;
sourceTree = "<group>";
@ -2017,6 +2031,8 @@
C64BB21816E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21B16E2FC2F000DB34C /* qresync.c in Sources */,
C6F61F741701409B0073032E /* xgmthrid.c in Sources */,
8A75ECDA17040F92007F9972 /* mailimap_sort.c in Sources */,
8A75ECE6170414BA007F9972 /* mailimap_sort_types.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2195,6 +2211,8 @@
C64BB21A16E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21D16E2FC2F000DB34C /* qresync.c in Sources */,
C6F61F761701409B0073032E /* xgmthrid.c in Sources */,
8A75ECDC17040F92007F9972 /* mailimap_sort.c in Sources */,
8A75ECE8170414BA007F9972 /* mailimap_sort_types.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2373,6 +2391,8 @@
C64BB21916E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21C16E2FC2F000DB34C /* qresync.c in Sources */,
C6F61F751701409B0073032E /* xgmthrid.c in Sources */,
8A75ECDB17040F92007F9972 /* mailimap_sort.c in Sources */,
8A75ECE7170414BA007F9972 /* mailimap_sort_types.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -112,6 +112,8 @@ libetpan_version.h
..\src\low-level\imap\mailimap_print.h
..\src\low-level\imap\mailimap_sender.h
..\src\low-level\imap\mailimap_socket.h
..\src\low-level\imap\mailimap_sort.h
..\src\low-level\imap\mailimap_sort_types.h
..\src\low-level\imap\mailimap_ssl.h
..\src\low-level\imap\mailimap_types.h
..\src\low-level\imap\mailimap_types_helper.h

@ -45,7 +45,8 @@ etpaninclude_HEADERS = \
xlist.h xgmlabels.h xgmmsgid.h xgmthrid.h \
mailimap_id.h mailimap_id_types.h \
enable.h condstore.h condstore_types.h \
qresync.h qresync_types.h
qresync.h qresync_types.h \
mailimap_sort.h mailimap_sort_types.h
AM_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_srcdir)/src/data-types
@ -94,5 +95,6 @@ libimap_la_SOURCES = \
mailimap_id_parser.h mailimap_id_parser.c \
enable.h enable.c \
condstore.h condstore.c condstore_types.h condstore_types.c condstore_private.h \
qresync.h qresync.c qresync_types.h qresync_types.c qresync_private.h
qresync.h qresync.c qresync_types.h qresync_types.c qresync_private.h \
mailimap_sort.c mailimap_sort_types.c

@ -53,6 +53,7 @@
#include "enable.h"
#include "condstore.h"
#include "qresync.h"
#include "mailimap_sort.h"
/*
the list of registered extensions (struct mailimap_extension_api *)
@ -75,7 +76,8 @@ static struct mailimap_extension_api * internal_extension_list[] = {
&mailimap_extension_id,
&mailimap_extension_enable,
&mailimap_extension_condstore,
&mailimap_extension_qresync
&mailimap_extension_qresync,
&mailimap_extension_sort
};
LIBETPAN_EXPORT

@ -24,7 +24,8 @@ enum {
MAILIMAP_EXTENSION_ID, /* ID */
MAILIMAP_EXTENSION_ENABLE, /* ENABLE */
MAILIMAP_EXTENSION_CONDSTORE, /* CONDSTORE */
MAILIMAP_EXTENSION_QRESYNC /* QRESYNC */
MAILIMAP_EXTENSION_QRESYNC, /* QRESYNC */
MAILIMAP_EXTENSION_SORT /* SORT */
};

@ -6333,6 +6333,46 @@ mailimap_mailbox_data_search_parse(mailstream * fd, MMAPString * buffer,
return MAILIMAP_NO_ERROR;
}
static int
mailimap_mailbox_data_sort_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
size_t final_token;
clist * number_list;
int r;
cur_token = * indx;
r = mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "SORT");
if (r != MAILIMAP_NO_ERROR)
return r;
final_token = cur_token;
number_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &number_list,
(mailimap_struct_parser *)
mailimap_nz_number_alloc_parse,
(mailimap_struct_destructor *)
mailimap_number_alloc_free,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR)
final_token = cur_token;
}
* result = number_list;
* indx = final_token;
return MAILIMAP_NO_ERROR;
}
/*
"STATUS" SP mailbox SP "("
[status-att SP number *(SP status-att SP number)] ")"

@ -130,10 +130,6 @@ static int mailimap_password_send(mailstream * fd, const char * pass);
static int mailimap_quoted_char_send(mailstream * fd, char ch);
static int mailimap_search_key_send(mailstream * fd,
struct mailimap_search_key * key);
static int
mailimap_section_send(mailstream * fd,
struct mailimap_section * section);
@ -1945,7 +1941,7 @@ mailimap_uid_search_send(mailstream * fd, const char * charset,
*/
static int mailimap_search_key_send(mailstream * fd,
int mailimap_search_key_send(mailstream * fd,
struct mailimap_search_key * key)
{
int r;
@ -2348,6 +2344,7 @@ int mailimap_mod_sequence_value_send(mailstream * fd, uint64_t modseq)
return mailimap_token_send(fd, modseqstr);
}
/*
=> section = "[" [section-spec] "]"
*/

@ -113,6 +113,10 @@ int
mailimap_uid_search_send(mailstream * fd, const char * charset,
struct mailimap_search_key * key);
int mailimap_search_key_send(mailstream * fd,
struct mailimap_search_key * key);
int
mailimap_select_send(mailstream * fd, const char * mb, int condstore);

@ -0,0 +1,428 @@
//
// mailimap_sort.c
// libetpan
//
// Created by Pitiphong Phongpattranont on 28/3/56 BE.
//
//
#include "mailimap_sort.h"
#include <stdlib.h>
#include "mailimap.h"
#include "mailimap_extension.h"
#include "mailimap_extension_types.h"
#include "mailimap_sender.h"
#include "mailimap_parser.h"
#include "mailimap_keywords.h"
#include "mailimap_sender.h"
enum {
MAILIMAP_SORT_TYPE_SORT
};
int
mailimap_sort_send(mailstream * fd, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey);
int
mailimap_uid_sort_send(mailstream * fd, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey);
int mailimap_sort_key_send(mailstream * fd,
struct mailimap_sort_key * key);
static int
mailimap_sort_extension_parse(int calling_parser, mailstream * fd,
MMAPString * buffer, size_t * indx,
struct mailimap_extension_data ** result,
size_t progr_rate, progress_function * progr_fun);
static void
mailimap_sort_extension_data_free(struct mailimap_extension_data * ext_data);
LIBETPAN_EXPORT
struct mailimap_extension_api mailimap_extension_sort = {
/* name */ "SORT",
/* extension_id */ MAILIMAP_EXTENSION_SORT,
/* parser */ mailimap_sort_extension_parse,
/* free */ mailimap_sort_extension_data_free
};
LIBETPAN_EXPORT
int
mailimap_sort(mailimap * session, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey,
clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = mailimap_send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_sort_send(session->imap_stream, charset, key, searchkey);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (mailimap_read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = mailimap_parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
clist * sort_result = NULL;
clistiter * cur = NULL;
for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
cur != NULL; cur = clist_next(cur)) {
struct mailimap_extension_data * ext_data;
ext_data = (struct mailimap_extension_data *) clist_content(cur);
if (ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_SORT) {
if (sort_result == NULL) {
sort_result = ext_data->ext_data;
ext_data->ext_data = NULL;
ext_data->ext_type = -1;
}
}
}
clist_foreach(session->imap_response_info->rsp_extension_list,
(clist_func) mailimap_extension_data_free, NULL);
clist_free(session->imap_response_info->rsp_extension_list);
session->imap_response_info->rsp_extension_list = NULL;
if (sort_result == NULL) {
return MAILIMAP_ERROR_EXTENSION;
}
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
break;
default:
mailimap_search_result_free(sort_result);
return MAILIMAP_ERROR_EXTENSION;
}
mailimap_response_free(response);
* result = sort_result;
return MAILIMAP_NO_ERROR;
}
LIBETPAN_EXPORT
int
mailimap_uid_sort(mailimap * session, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey,
clist ** result)
{
struct mailimap_response * response;
int r;
int error_code;
if (session->imap_state != MAILIMAP_STATE_SELECTED)
return MAILIMAP_ERROR_BAD_STATE;
r = mailimap_send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_uid_sort_send(session->imap_stream, charset, key, searchkey);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_crlf_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mailstream_flush(session->imap_stream) == -1)
return MAILIMAP_ERROR_STREAM;
if (mailimap_read_line(session) == NULL)
return MAILIMAP_ERROR_STREAM;
r = mailimap_parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
clistiter * cur = NULL;
clist * sort_result = NULL;
for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
cur != NULL; cur = clist_next(cur)) {
struct mailimap_extension_data * ext_data;
ext_data = (struct mailimap_extension_data *) clist_content(cur);
if (ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_SORT) {
if (sort_result == NULL) {
sort_result = ext_data->ext_data;
ext_data->ext_data = NULL;
ext_data->ext_type = -1;
}
}
}
clist_foreach(session->imap_response_info->rsp_extension_list,
(clist_func) mailimap_extension_data_free, NULL);
clist_free(session->imap_response_info->rsp_extension_list);
session->imap_response_info->rsp_extension_list = NULL;
if (sort_result == NULL) {
return MAILIMAP_ERROR_EXTENSION;
}
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
break;
default:
mailimap_search_result_free(sort_result);
return MAILIMAP_ERROR_EXTENSION;
}
mailimap_response_free(response);
* result = sort_result;
return MAILIMAP_NO_ERROR;
}
LIBETPAN_EXPORT
void mailimap_sort_result_free(clist * search_result)
{
clist_foreach(search_result, (clist_func) free, NULL);
clist_free(search_result);
}
int
mailimap_sort_send(mailstream * fd, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey)
{
int r;
r = mailimap_token_send(fd, "SORT");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_oparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_sort_key_send(fd, key);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_cparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
if (charset != NULL) {
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_astring_send(fd, charset);
if (r != MAILIMAP_NO_ERROR)
return r;
}
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
if (searchkey != NULL) {
r = mailimap_search_key_send(fd, searchkey);
if (r != MAILIMAP_NO_ERROR)
return r;
}
return MAILIMAP_NO_ERROR;
}
int
mailimap_uid_sort_send(mailstream * fd, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey)
{
int r;
r = mailimap_token_send(fd, "UID");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
return mailimap_sort_send(fd, charset, key, searchkey);
}
int mailimap_sort_key_send(mailstream * fd,
struct mailimap_sort_key * key)
{
int r;
if (key->sortk_is_reverse) {
r = mailimap_token_send(fd, "REVERSE");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
}
switch (key->sortk_type) {
case MAILIMAP_SORT_KEY_ARRIVAL:
return mailimap_token_send(fd, "ARRIVAL");
case MAILIMAP_SORT_KEY_CC:
return mailimap_token_send(fd, "CC");
case MAILIMAP_SORT_KEY_DATE:
return mailimap_token_send(fd, "DATE");
case MAILIMAP_SORT_KEY_FROM:
return mailimap_token_send(fd, "FROM");
case MAILIMAP_SORT_KEY_SIZE:
return mailimap_token_send(fd, "SIZE");
case MAILIMAP_SORT_KEY_SUBJECT:
return mailimap_token_send(fd, "SUBJECT");
case MAILIMAP_SORT_KEY_TO:
return mailimap_token_send(fd, "TO");
case MAILIMAP_SORT_KEY_MULTIPLE:
r = mailimap_struct_spaced_list_send(fd, key->sortk_multiple,
(mailimap_struct_sender *)
mailimap_sort_key_send);
return MAILIMAP_NO_ERROR;
default:
/* should not happend */
return MAILIMAP_ERROR_INVAL;
}
}
static int
mailimap_number_list_data_sort_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
clist ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
clist * number_list;
int r;
int res;
size_t final_token;
cur_token = * indx;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "SORT");
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
final_token = cur_token;
number_list = NULL;
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r == MAILIMAP_NO_ERROR) {
r = mailimap_struct_spaced_list_parse(fd, buffer, &cur_token, &number_list,
(mailimap_struct_parser *)
mailimap_nz_number_alloc_parse,
(mailimap_struct_destructor *)
mailimap_number_alloc_free,
progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR) {
final_token = cur_token;
}
}
* result = number_list;
* indx = final_token;
return MAILIMAP_NO_ERROR;
}
static int
mailimap_sort_extension_parse(int calling_parser, mailstream * fd,
MMAPString * buffer, size_t * indx,
struct mailimap_extension_data ** result,
size_t progr_rate, progress_function * progr_fun)
{
int r;
clist * number_list = NULL;
struct mailimap_extension_data * ext_data;
void * data;
int type;
size_t cur_token;
cur_token = * indx;
switch (calling_parser)
{
case MAILIMAP_EXTENDED_PARSER_RESPONSE_DATA:
case MAILIMAP_EXTENDED_PARSER_MAILBOX_DATA:
r = mailimap_number_list_data_sort_parse(fd, buffer, &cur_token,
&number_list, progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR) {
type = MAILIMAP_SORT_TYPE_SORT;
data = number_list;
}
if (r != MAILIMAP_NO_ERROR) {
return r;
}
ext_data = mailimap_extension_data_new(&mailimap_extension_sort,
type, data);
if (ext_data == NULL) {
if (number_list != NULL)
mailimap_mailbox_data_search_free(number_list);
return MAILIMAP_ERROR_MEMORY;
}
* result = ext_data;
* indx = cur_token;
return MAILIMAP_NO_ERROR;
default:
/* return a MAILIMAP_ERROR_PARSE if the extension
doesn't extend calling_parser. */
return MAILIMAP_ERROR_PARSE;
}
}
static void
mailimap_sort_extension_data_free(struct mailimap_extension_data * ext_data)
{
if (ext_data->ext_data != NULL) {
mailimap_mailbox_data_search_free((clist *) ext_data->ext_data);
}
free(ext_data);
}

@ -0,0 +1,102 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2011 - DINH Viet Hoa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef libetpan_mailimap_sort_h
#define libetpan_mailimap_sort_h
#ifdef __cplusplus
extern "C" {
#endif
#include <libetpan/libetpan-config.h>
#include <libetpan/mailimap_extension.h>
#include <libetpan/mailimap_sort_types.h>
LIBETPAN_EXPORT
extern struct mailimap_extension_api mailimap_extension_sort;
/*
mailimap_sort()
All mails that match the given criteria will be returned
their numbers sorted by the given sorting criteria in the result list.
@param session IMAP session
@param charset This indicates the charset of the strings that appears
in the searching criteria
@param key This is the searching criteria
@param result The result is a clist of (uint32_t *) and will be
stored in (* result).
@return the return code is one of MAILIMAP_ERROR_XXX or
MAILIMAP_NO_ERROR codes
*/
LIBETPAN_EXPORT
int
mailimap_sort(mailimap * session, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey,
clist ** result);
/*
mailimap_uid_sort()
All mails that match the given criteria will be returned
their unique identifiers sorted by the given sorting criteria in the result list.
@param session IMAP session
@param charset This indicates the charset of the strings that appears
in the searching criteria
@param key This is the sorting criteria
@param searchkey This is the searching criteria
@param result The result is a clist of (uint32_t *) and will be
stored in (* result).
@return the return code is one of MAILIMAP_ERROR_XXX or
MAILIMAP_NO_ERROR codes
*/
LIBETPAN_EXPORT
int
mailimap_uid_sort(mailimap * session, const char * charset,
struct mailimap_sort_key * key, struct mailimap_search_key * searchkey,
clist ** result);
LIBETPAN_EXPORT
void mailimap_sort_result_free(clist * search_result);
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,121 @@
//
// mailimap_sort_types.c
// libetpan
//
// Created by Pitiphong Phongpattranont on 28/3/56 BE.
//
//
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "mailimap_sort_types.h"
#include "mmapstring.h"
#include "mail.h"
#include "mailimap_extension.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
struct mailimap_sort_key *
mailimap_sort_key_new(int sortk_type,
_Bool is_reverse,
clist * sortk_multiple) {
struct mailimap_sort_key * key;
key = malloc(sizeof(* key));
if (key == NULL)
return NULL;
key->sortk_type = sortk_type;
key->sortk_is_reverse = is_reverse;
if (sortk_type == MAILIMAP_SORT_KEY_MULTIPLE) {
key->sortk_multiple = sortk_multiple;
}
return key;
}
void mailimap_sort_key_free(struct mailimap_sort_key * key) {
if (key->sortk_type == MAILIMAP_SORT_KEY_MULTIPLE) {
clist_foreach(key->sortk_multiple,
(clist_func) mailimap_sort_key_free, NULL);
clist_free(key->sortk_multiple);
}
free(key);
}
struct mailimap_sort_key *
mailimap_sort_key_new_arrival(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_ARRIVAL, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_cc(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_CC, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_date(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_DATE, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_from(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_FROM, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_size(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_SIZE, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_subject(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_SUBJECT, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_to(_Bool is_reverse) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_TO, is_reverse, NULL);
}
struct mailimap_sort_key *
mailimap_sort_key_new_multiple(clist * keys) {
return mailimap_sort_key_new(MAILIMAP_SORT_KEY_MULTIPLE, false, keys);
}
struct mailimap_sort_key *
mailimap_sort_key_new_multiple_empty(void)
{
clist * list;
list = clist_new();
if (list == NULL)
return NULL;
return mailimap_sort_key_new_multiple(list);
}
int
mailimap_sort_key_multiple_add(struct mailimap_sort_key * keys,
struct mailimap_sort_key * key_item)
{
int r;
r = clist_append(keys->sortk_multiple, key_item);
if (r < 0)
return MAILIMAP_ERROR_MEMORY;
return MAILIMAP_NO_ERROR;
}

@ -0,0 +1,111 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2011 - DINH Viet Hoa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef MAILIMAP_SORT_TYPES_H
#define MAILIMAP_SORT_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef WIN32
#include <inttypes.h>
#endif
#include "mailimap_types.h"
/* this is the condition of the SORT operation */
enum {
MAILIMAP_SORT_KEY_ARRIVAL,
MAILIMAP_SORT_KEY_CC,
MAILIMAP_SORT_KEY_DATE,
MAILIMAP_SORT_KEY_FROM,
MAILIMAP_SORT_KEY_SIZE,
MAILIMAP_SORT_KEY_SUBJECT,
MAILIMAP_SORT_KEY_TO,
MAILIMAP_SORT_KEY_MULTIPLE
};
struct mailimap_sort_key {
int sortk_type;
_Bool sortk_is_reverse;
clist * sortk_multiple; /* list of (struct mailimap_sort_key *) */
};
LIBETPAN_EXPORT
struct mailimap_sort_key *
mailimap_sort_key_new(int sortk_type,
_Bool is_reverse,
clist * sortk_multiple);
LIBETPAN_EXPORT
void mailimap_sort_key_free(struct mailimap_sort_key * key);
struct mailimap_sort_key *
mailimap_sort_key_new_arrival(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_cc(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_date(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_from(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_size(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_subject(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_to(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_multiple(clist * keys);
struct mailimap_sort_key *
mailimap_sort_key_new_multiple_empty(void);
int
mailimap_sort_key_multiple_add(struct mailimap_sort_key * keys,
struct mailimap_sort_key * key_item);
#ifdef __cplusplus
}
#endif
#endif

@ -44,6 +44,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
/* ************************************************************************* */
/* ************************************************************************* */
@ -2848,9 +2849,6 @@ void mailimap_search_key_free(struct mailimap_search_key * key)
struct mailimap_status_att_list *
mailimap_status_att_list_new(clist * att_list)
{

@ -509,6 +509,7 @@ extern "C" {
#include <libetpan/libetpan-config.h>
#include <libetpan/mailstream.h>
#include <libetpan/clist.h>
#include <stdbool.h>
/*
@ -2995,7 +2996,6 @@ mailimap_search_key_new(int sk_type,
LIBETPAN_EXPORT
void mailimap_search_key_free(struct mailimap_search_key * key);
/*
mailimap_status_att_list is a list of mailbox STATUS request type

@ -671,6 +671,39 @@ mailimap_search_key_multiple_add(struct mailimap_search_key * keys,
struct mailimap_search_key * key_item);
struct mailimap_sort_key *
mailimap_sort_key_new_arrival(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_cc(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_date(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_from(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_size(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_subject(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_to(_Bool is_reverse);
struct mailimap_sort_key *
mailimap_sort_key_new_multiple(clist * keys);
struct mailimap_sort_key *
mailimap_sort_key_new_multiple_empty(void);
int
mailimap_sort_key_multiple_add(struct mailimap_sort_key * keys,
struct mailimap_sort_key * key_item);
/*
this function creates an empty list of flags
*/

Loading…
Cancel
Save