Browse Source

Ability to SEARCH using LITERAL+ (part of the fix for https://github.com/MailCore/mailcore2/issues/421)

merge-experiment
Hoa V. DINH 8 years ago
parent
commit
6ea5ecb9c3
6 changed files with 810 additions and 791 deletions
  1. +61
    -93
      src/low-level/imap/condstore.c
  2. +8
    -0
      src/low-level/imap/condstore.h
  3. +11
    -148
      src/low-level/imap/mailimap.c
  4. +42
    -0
      src/low-level/imap/mailimap.h
  5. +679
    -549
      src/low-level/imap/mailimap_sender.c
  6. +9
    -1
      src/low-level/imap/mailimap_sender.h

+ 61
- 93
src/low-level/imap/condstore.c View File

@ -331,44 +331,61 @@ struct mailimap_search_key * mailimap_search_key_new_modseq(struct mailimap_flag
return key;
}
int mailimap_search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
static int search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key,
int uid_enabled, int literalplus_enabled,
clist ** result, uint64_t * p_mod_sequence_value)
{
struct mailimap_response * response;
int r;
int error_code;
struct mailimap_condstore_search * search_data;
clistiter * cur;
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_search_send(session->imap_stream, charset, key);
if (literalplus_enabled) {
if (uid_enabled) {
r = mailimap_uid_search_literalplus_send(session->imap_stream, charset, key);
}
else {
r = mailimap_search_literalplus_send(session->imap_stream, charset, key);
}
}
else {
if (uid_enabled) {
r = mailimap_uid_search_send(session->imap_stream, charset, key);
}
else {
r = mailimap_search_send(session->imap_stream, charset, key);
}
}
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;
search_data = 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 = clist_content(cur);
if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
continue;
@ -376,12 +393,12 @@ int mailimap_search_modseq(mailimap * session, const char * charset,
if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA) {
continue;
}
search_data = ext_data->ext_data;
ext_data->ext_data = NULL;
break;
}
if (search_data == NULL) {
* result = session->imap_response_info->rsp_search_result;
if (p_mod_sequence_value != NULL) {
@ -395,98 +412,49 @@ int mailimap_search_modseq(mailimap * session, const char * charset,
search_data->cs_search_result = NULL;
mailimap_condstore_search_free(search_data);
}
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_SEARCH;
if (uid_enabled) {
return MAILIMAP_ERROR_UID_SEARCH;
}
else {
return MAILIMAP_ERROR_SEARCH;
}
}
}
int mailimap_uid_search_modseq(mailimap * session, const char * charset,
int mailimap_search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
{
struct mailimap_response * response;
int r;
int error_code;
struct mailimap_condstore_search * search_data;
clistiter * cur;
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_search_send(session->imap_stream, charset, key);
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;
search_data = 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 = clist_content(cur);
if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
continue;
}
if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA) {
continue;
}
search_data = ext_data->ext_data;
ext_data->ext_data = NULL;
break;
}
if (search_data == NULL) {
* result = session->imap_response_info->rsp_search_result;
if (p_mod_sequence_value != NULL) {
* p_mod_sequence_value = 0;
}
session->imap_response_info->rsp_search_result = NULL;
}
else {
* result = search_data->cs_search_result;
if (p_mod_sequence_value != NULL) {
* p_mod_sequence_value = search_data->cs_modseq_value;
}
search_data->cs_search_result = NULL;
mailimap_condstore_search_free(search_data);
}
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
return search_modseq(session, charset, key, 0, 0, result, p_mod_sequence_value);
}
mailimap_response_free(response);
int mailimap_uid_search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
{
return search_modseq(session, charset, key, 1, 0, result, p_mod_sequence_value);
}
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
LIBETPAN_EXPORT
int mailimap_search_literalplus_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
{
return search_modseq(session, charset, key, 0, 1, result, p_mod_sequence_value);
}
default:
return MAILIMAP_ERROR_UID_SEARCH;
}
LIBETPAN_EXPORT
int mailimap_uid_search_literalplus_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
{
return search_modseq(session, charset, key, 1, 1, result, p_mod_sequence_value);
}
int mailimap_select_condstore(mailimap * session, const char * mb, uint64_t * p_mod_sequence_value)


+ 8
- 0
src/low-level/imap/condstore.h View File

@ -77,6 +77,14 @@ LIBETPAN_EXPORT
int mailimap_uid_search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
LIBETPAN_EXPORT
int mailimap_search_literalplus_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
LIBETPAN_EXPORT
int mailimap_uid_search_literalplus_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
LIBETPAN_EXPORT
int mailimap_select_condstore(mailimap * session, const char * mb, uint64_t * p_mod_sequence_value);


+ 11
- 148
src/low-level/imap/mailimap.c View File

@ -1964,53 +1964,7 @@ int
mailimap_search(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
#if 0
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_search_send(session->imap_stream, charset, key);
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;
* result = session->imap_response_info->rsp_search_result;
session->imap_response_info->rsp_search_result = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_SEARCH;
}
#else
return mailimap_search_modseq(session, charset, key, result, NULL);
#endif
}
LIBETPAN_EXPORT
@ -2018,53 +1972,19 @@ int
mailimap_uid_search(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
#if 0
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_search_send(session->imap_stream, charset, key);
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;
* result = session->imap_response_info->rsp_search_result;
session->imap_response_info->rsp_search_result = NULL;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
return mailimap_uid_search_modseq(session, charset, key, result, NULL);
}
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
LIBETPAN_EXPORT int mailimap_search_literalplus(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
return mailimap_search_literalplus_modseq(session, charset, key, result, NULL);
}
default:
return MAILIMAP_ERROR_UID_SEARCH;
}
#else
return mailimap_uid_search_modseq(session, charset, key, result, NULL);
#endif
LIBETPAN_EXPORT int mailimap_uid_search_literalplus(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result)
{
return mailimap_uid_search_literalplus_modseq(session, charset, key, result, NULL);
}
LIBETPAN_EXPORT
@ -2074,62 +1994,6 @@ void mailimap_search_result_free(clist * search_result)
clist_free(search_result);
}
#if 0
LIBETPAN_EXPORT
int
mailimap_select(mailimap * session, const char * mb)
{
struct mailimap_response * response;
int r;
int error_code;
if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
(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_select_send(session->imap_stream, mb);
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;
if (session->imap_selection_info != NULL)
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = mailimap_selection_info_new();
r = mailimap_parse_response(session, &response);
if (r != MAILIMAP_NO_ERROR)
return r;
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
session->imap_state = MAILIMAP_STATE_SELECTED;
return MAILIMAP_NO_ERROR;
default:
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = NULL;
session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
return MAILIMAP_ERROR_SELECT;
}
}
#else
LIBETPAN_EXPORT
int
mailimap_select(mailimap * session, const char * mb)
@ -2137,7 +2001,6 @@ mailimap_select(mailimap * session, const char * mb)
uint64_t dummy;
return mailimap_select_condstore_optional(session, mb, 0, &dummy);
}
#endif
LIBETPAN_EXPORT
int


+ 42
- 0
src/low-level/imap/mailimap.h View File

@ -489,6 +489,48 @@ int
mailimap_uid_search(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result);
/*
mailimap_search_literalplus()
All mails that match the given criteria will be returned
their numbers in the result list.
LITERAL+ feature will be used to send strings.
@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_search_literalplus(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result);
/*
mailimap_uid_search_literalplus()
All mails that match the given criteria will be returned
their numbers in the result list.
LITERAL+ feature will be used to send strings.
@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_uid_search_literalplus(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result);
/*
mailimap_search_result_free()


+ 679
- 549
src/low-level/imap/mailimap_sender.c
File diff suppressed because it is too large
View File


+ 9
- 1
src/low-level/imap/mailimap_sender.h View File

@ -118,10 +118,18 @@ int
mailimap_uid_search_send(mailstream * fd, const char * charset,
struct mailimap_search_key * key);
int mailimap_search_literalplus_send(mailstream * fd, const char * charset,
struct mailimap_search_key * key);
int mailimap_uid_search_literalplus_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_search_key_literalplus_send(mailstream * fd,
struct mailimap_search_key * key);
int
mailimap_select_send(mailstream * fd, const char * mb, int condstore);


Loading…
Cancel
Save