Cleanup. Implemented QRESYNC.

dvh-chacham15-master
DINH Viet Hoa 10 years ago
parent 4fed119b52
commit 6069b7bb97

@ -11,6 +11,12 @@
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 */; };
C64BB21816E2FC2F000DB34C /* qresync_types.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21416E2FC2F000DB34C /* qresync_types.c */; };
C64BB21916E2FC2F000DB34C /* qresync_types.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21416E2FC2F000DB34C /* qresync_types.c */; };
C64BB21A16E2FC2F000DB34C /* qresync_types.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21416E2FC2F000DB34C /* qresync_types.c */; };
C64BB21B16E2FC2F000DB34C /* qresync.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21616E2FC2F000DB34C /* qresync.c */; };
C64BB21C16E2FC2F000DB34C /* qresync.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21616E2FC2F000DB34C /* qresync.c */; };
C64BB21D16E2FC2F000DB34C /* qresync.c in Sources */ = {isa = PBXBuildFile; fileRef = C64BB21616E2FC2F000DB34C /* qresync.c */; };
C64EA7B716A00CA700778456 /* xgmmsgid.c in Sources */ = {isa = PBXBuildFile; fileRef = 365DFFD115D1C93100F2DD85 /* xgmmsgid.c */; };
C64EA7B816A00CA700778456 /* xgmmsgid.c in Sources */ = {isa = PBXBuildFile; fileRef = 365DFFD115D1C93100F2DD85 /* xgmmsgid.c */; };
C64EA7C116A00CC500778456 /* mailimap_id_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = C64EA7B916A00CC100778456 /* mailimap_id_parser.c */; };
@ -552,6 +558,11 @@
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>"; };
C60E7B9916C3809400A25BF4 /* enable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = enable.h; sourceTree = "<group>"; };
C64BB21416E2FC2F000DB34C /* qresync_types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = qresync_types.c; sourceTree = "<group>"; };
C64BB21516E2FC2F000DB34C /* qresync_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = qresync_types.h; sourceTree = "<group>"; };
C64BB21616E2FC2F000DB34C /* qresync.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = qresync.c; sourceTree = "<group>"; };
C64BB21716E2FC2F000DB34C /* qresync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = qresync.h; sourceTree = "<group>"; };
C64BB21E16E32CDB000DB34C /* qresync_private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = qresync_private.h; sourceTree = "<group>"; };
C64EA7B916A00CC100778456 /* mailimap_id_parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mailimap_id_parser.c; sourceTree = "<group>"; };
C64EA7BA16A00CC100778456 /* mailimap_id_parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mailimap_id_parser.h; sourceTree = "<group>"; };
C64EA7BB16A00CC200778456 /* mailimap_id_sender.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mailimap_id_sender.c; sourceTree = "<group>"; };
@ -1458,6 +1469,11 @@
C6517A0B130E86D3004ADD56 /* namespace_sender.h */,
C6517A06130E86C6004ADD56 /* namespace_types.c */,
C6517A05130E86C6004ADD56 /* namespace_types.h */,
C64BB21616E2FC2F000DB34C /* qresync.c */,
C64BB21716E2FC2F000DB34C /* qresync.h */,
C64BB21E16E32CDB000DB34C /* qresync_private.h */,
C64BB21416E2FC2F000DB34C /* qresync_types.c */,
C64BB21516E2FC2F000DB34C /* qresync_types.h */,
C6E57200110376F200897274 /* quota.c */,
C6E57201110376F200897274 /* quota.h */,
C6E571FA110376F200897274 /* quota_parser.c */,
@ -1991,6 +2007,8 @@
C60E7B9A16C3809400A25BF4 /* enable.c in Sources */,
C6635C3A16DFF10E0066276E /* condstore_types.c in Sources */,
C6635C3B16DFF10E0066276E /* condstore.c in Sources */,
C64BB21816E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21B16E2FC2F000DB34C /* qresync.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2166,6 +2184,8 @@
C60E7B9E16C3809D00A25BF4 /* enable.c in Sources */,
C6CC501616E11074001E7392 /* condstore.c in Sources */,
C6CC501816E1107A001E7392 /* condstore_types.c in Sources */,
C64BB21A16E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21D16E2FC2F000DB34C /* qresync.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2341,6 +2361,8 @@
C60E7B9D16C3809C00A25BF4 /* enable.c in Sources */,
C6CC501516E11074001E7392 /* condstore.c in Sources */,
C6CC501716E11079001E7392 /* condstore_types.c in Sources */,
C64BB21916E2FC2F000DB34C /* qresync_types.c in Sources */,
C64BB21C16E2FC2F000DB34C /* qresync.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -44,7 +44,8 @@ etpaninclude_HEADERS = \
namespace.h namespace_parser.h namespace_sender.h namespace_types.h \
xlist.h xgmlabels.h xgmmsgid.h \
mailimap_id.h mailimap_id_types.h \
enable.h condstore.h condstore_types.h
enable.h condstore.h condstore_types.h \
qresync.h qresync_types.h
AM_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_srcdir)/src/data-types
@ -91,5 +92,6 @@ libimap_la_SOURCES = \
mailimap_id_sender.h mailimap_id_sender.c \
mailimap_id_parser.h mailimap_id_parser.c \
enable.h enable.c \
condstore.h condstore.c condstore_types.h condstore_types.c
condstore.h condstore.c condstore_types.h condstore_types.c \
qresync.h qresync.c qresync_types.h qresync_types.c

@ -156,9 +156,6 @@ void mailimap_acl_myrights_data_free(struct
void
mailimap_acl_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
switch (ext_data->ext_type)
{
case MAILIMAP_ACL_TYPE_ACL_DATA:

@ -377,9 +377,6 @@ int mailimap_annotatemore_entry_att_list_add(
void
mailimap_annotatemore_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
switch (ext_data->ext_type)
{
case MAILIMAP_ANNOTATEMORE_TYPE_ANNOTATE_DATA:

@ -1,3 +1,34 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2013 - 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.
*/
#include "condstore.h"
#include "condstore_private.h"
@ -10,6 +41,8 @@
#include "condstore_types.h"
#include "mailimap_keywords.h"
#include "mailimap_parser.h"
#include "qresync.h"
#include "qresync_private.h"
/*
capability =/ "CONDSTORE"
@ -118,13 +151,6 @@
attr-flag-keyword = atom
*/
enum {
MAILIMAP_CONDSTORE_TYPE_FETCH_DATA,
MAILIMAP_CONDSTORE_TYPE_RESP_TEXT_CODE,
MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA,
MAILIMAP_CONDSTORE_TYPE_STATUS_INFO
};
static void
mailimap_condstore_extension_data_free(struct mailimap_extension_data * ext_data);
@ -256,81 +282,8 @@ int mailimap_fetch_changedsince(mailimap * session,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value,
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_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mod_sequence_value != 0) {
r = mailimap_space_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_oparenth_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_token_send(session->imap_stream, "CHANGEDSINCE");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mod_sequence_value_send(session->imap_stream, mod_sequence_value);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_cparenth_send(session->imap_stream);
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_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
if (clist_count(* result) == 0) {
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
}
else {
error_code = MAILIMAP_RESP_COND_STATE_OK;
}
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
mailimap_fetch_list_free(* result);
return MAILIMAP_ERROR_FETCH;
}
return mailimap_fetch_qresync_vanished(session, set, fetch_type, mod_sequence_value, 0,
result, NULL);
}
int mailimap_uid_fetch_changedsince(mailimap * session,
@ -338,82 +291,8 @@ int mailimap_uid_fetch_changedsince(mailimap * session,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value,
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_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
if (mod_sequence_value != 0) {
r = mailimap_space_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_oparenth_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_token_send(session->imap_stream, "CHANGEDSINCE");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(session->imap_stream);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mod_sequence_value_send(session->imap_stream, mod_sequence_value);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_cparenth_send(session->imap_stream);
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_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
if (clist_count(* result) == 0) {
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
}
else {
error_code = MAILIMAP_RESP_COND_STATE_OK;
}
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
mailimap_fetch_list_free(* result);
return MAILIMAP_ERROR_UID_FETCH;
}
return mailimap_uid_fetch_qresync_vanished(session, set, fetch_type, mod_sequence_value, 0,
result, NULL);
}
struct mailimap_fetch_att * mailimap_fetch_att_new_modseq(void)
@ -434,19 +313,6 @@ struct mailimap_fetch_att * mailimap_fetch_att_new_modseq(void)
return att;
}
struct mailimap_msg_att_modseq * mailimap_msg_att_modseq_new(uint64_t mod_sequence_value)
{
struct mailimap_msg_att_modseq * att;
att = malloc(sizeof(* att));
if (att == NULL)
return NULL;
att->att_modseq = mod_sequence_value;
return att;
}
struct mailimap_search_key * mailimap_search_key_new_modseq(struct mailimap_flag * entry_name,
int entry_type_req,
uint64_t modseq_valzer)
@ -1049,7 +915,7 @@ static int
MAILIMAP_CONDSTORE_TYPE_FETCH_DATA, fetch_data);
if (ext_data == NULL) {
mailimap_condstore_fetch_mod_resp_free(fetch_data);
return MAILIMAP_NO_ERROR;
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
@ -1067,7 +933,7 @@ static int
MAILIMAP_CONDSTORE_TYPE_RESP_TEXT_CODE, resptextcode);
if (ext_data == NULL) {
mailimap_condstore_resptextcode_free(resptextcode);
return MAILIMAP_NO_ERROR;
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
@ -1085,7 +951,7 @@ static int
MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA, search_data);
if (ext_data == NULL) {
mailimap_condstore_search_free(search_data);
return MAILIMAP_NO_ERROR;
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
@ -1103,7 +969,7 @@ static int
MAILIMAP_CONDSTORE_TYPE_STATUS_INFO, status_info);
if (ext_data == NULL) {
mailimap_condstore_status_info_free(status_info);
return MAILIMAP_NO_ERROR;
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
@ -1117,9 +983,6 @@ static int
static void
mailimap_condstore_extension_data_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
switch (ext_data->ext_type) {
case MAILIMAP_CONDSTORE_TYPE_FETCH_DATA:
mailimap_condstore_fetch_mod_resp_free(ext_data->ext_data);

@ -69,9 +69,6 @@ int mailimap_uid_fetch_changedsince(mailimap * session,
LIBETPAN_EXPORT
struct mailimap_fetch_att * mailimap_fetch_att_new_modseq(void);
LIBETPAN_EXPORT
struct mailimap_msg_att_modseq * mailimap_msg_att_modseq_new(uint64_t mod_sequence_value);
LIBETPAN_EXPORT
int mailimap_search_modseq(mailimap * session, const char * charset,
struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);

@ -1,7 +1,45 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2013 - 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 CONDSTORE_PRIVATE_H
#define CONDSTORE_PRIVATE_H
enum {
MAILIMAP_CONDSTORE_TYPE_FETCH_DATA,
MAILIMAP_CONDSTORE_TYPE_RESP_TEXT_CODE,
MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA,
MAILIMAP_CONDSTORE_TYPE_STATUS_INFO
};
int mailimap_examine_condstore_optional(mailimap * session, const char * mb,
int condstore, uint64_t * p_mod_sequence_value);

@ -1,3 +1,34 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2013 - 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.
*/
#include "condstore_types.h"
#include <stdlib.h>

@ -1,3 +1,34 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2013 - 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 CONDSTORE_TYPE_H
#define CONDSTORE_TYPE_H
@ -14,10 +45,6 @@ enum {
MAILIMAP_CONDSTORE_RESPTEXTCODE_MODIFIED
};
struct mailimap_msg_att_modseq {
uint64_t att_modseq;
};
struct mailimap_condstore_resptextcode {
int cs_type;
union {

@ -190,9 +190,6 @@ int mailimap_has_enable(mailimap * session)
static void
mailimap_enable_extension_data_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
if (ext_data->ext_data != NULL) {
mailimap_capability_data_free((struct mailimap_capability_data *) ext_data->ext_data);
}
@ -209,32 +206,50 @@ static int mailimap_enable_parse(mailstream * fd, MMAPString * buffer,
int r;
int res;
struct mailimap_capability_data * capabilities;
clist * cap_list;
cur_token = * indx;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "ENABLE");
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "ENABLED");
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
goto err;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
r = mailimap_capability_list_parse(fd, buffer, &cur_token,
&cap_list,
progr_rate, progr_fun);
if (r == MAILIMAP_ERROR_PARSE) {
cap_list = clist_new();
if (cap_list == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto err;
}
r = MAILIMAP_NO_ERROR;
}
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
goto err;
}
r = mailimap_capability_data_parse(fd, buffer, &cur_token, &capabilities,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
capabilities = mailimap_capability_data_new(cap_list);
if (capabilities == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free_list;
}
* result = capabilities;
* indx = cur_token;
return MAILIMAP_NO_ERROR;
free_list:
if (cap_list) {
clist_foreach(cap_list, (clist_func) mailimap_capability_free, NULL);
clist_free(cap_list);
}
err:
return res;
}
static int

@ -361,15 +361,8 @@ static void mailbox_data_store(mailimap * session,
}
break;
case MAILIMAP_MAILBOX_DATA_EXTENSION_DATA:
if (session->imap_response_info) {
r = clist_append(session->imap_response_info->rsp_extension_list,
mb_data->mbd_data.mbd_extension);
if (r == 0)
mb_data->mbd_data.mbd_extension = NULL;
else {
/* TODO must handle error case */
}
}
mailimap_extension_data_store(session, &mb_data->mbd_data.mbd_extension);
break;
}
}

@ -60,6 +60,7 @@ extern "C" {
#include <libetpan/xgmlabels.h>
#include <libetpan/xgmmsgid.h>
#include <libetpan/condstore.h>
#include <libetpan/qresync.h>
/*
mailimap_connect()

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

@ -2,6 +2,10 @@
#define MAILIMAP_EXTENSION_TYPES_H
#include <libetpan/mailstream.h>
struct mailimap_extension_data;
/*
this is the list of known extensions with the purpose to
get integer identifers for the extensions.
@ -18,7 +22,8 @@ enum {
MAILIMAP_EXTENSION_XGMMSGID, /* X-GM-MSGID (Gmail) */
MAILIMAP_EXTENSION_ID, /* ID */
MAILIMAP_EXTENSION_ENABLE, /* ENABLE */
MAILIMAP_EXTENSION_CONDSTORE /* CONDSTORE */
MAILIMAP_EXTENSION_CONDSTORE, /* CONDSTORE */
MAILIMAP_EXTENSION_QRESYNC /* QRESYNC */
};

@ -119,9 +119,6 @@ int mailimap_id(mailimap * session, struct mailimap_id_params_list * client_iden
static void mailimap_id_ext_data_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
if (ext_data->ext_data != NULL) {
mailimap_id_params_list_free(ext_data->ext_data);
}

@ -3891,7 +3891,7 @@ mailimap_capability_parse(mailstream * fd, MMAPString * buffer,
SP capability *(SP capability)
*/
static int mailimap_capability_list_parse(mailstream * fd,
int mailimap_capability_list_parse(mailstream * fd,
MMAPString * buffer,
size_t * indx,
clist ** result,
@ -11047,8 +11047,8 @@ int mailimap_set_parse(mailstream * fd,
cur_token = * indx;
r = mailimap_struct_list_parse(fd, buffer, indx, &item_list,
' ', (mailimap_struct_parser *) mailimap_set_item_parse, (mailimap_struct_destructor *)mailimap_set_item_free,
r = mailimap_struct_list_parse(fd, buffer, &cur_token, &item_list,
',', (mailimap_struct_parser *) mailimap_set_item_parse, (mailimap_struct_destructor *)mailimap_set_item_free,
0, NULL);
if (r != MAILIMAP_NO_ERROR)
return r;

@ -183,6 +183,13 @@ int mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t progr_rate,
progress_function * progr_fun);
int mailimap_capability_list_parse(mailstream * fd,
MMAPString * buffer,
size_t * indx,
clist ** result,
size_t progr_rate,
progress_function * progr_fun);
int mailimap_status_att_parse(mailstream * fd, MMAPString * buffer,
size_t * indx, int * result);

@ -126,8 +126,6 @@ static int
mailimap_header_list_send(mailstream * fd,
struct mailimap_header_list * header_list);
static int mailimap_number_send(mailstream * fd, uint32_t number);
static int mailimap_password_send(mailstream * fd, const char * pass);
static int mailimap_quoted_char_send(mailstream * fd, char ch);
@ -1709,7 +1707,7 @@ int mailimap_mailbox_send(mailstream * fd, const char * mb)
; (0 < n < 4,294,967,296)
*/
static int mailimap_number_send(mailstream * fd, uint32_t number)
int mailimap_number_send(mailstream * fd, uint32_t number)
{
int r;

@ -190,6 +190,8 @@ int mailimap_cparenth_send(mailstream * fd);
int mailimap_mod_sequence_value_send(mailstream * fd, uint64_t modseq);
int mailimap_number_send(mailstream * fd, uint32_t number);
#ifdef __cplusplus
}
#endif

@ -131,9 +131,6 @@ int mailimap_namespace(mailimap * session, struct mailimap_namespace_data ** res
static void
mailimap_namespace_extension_data_free(struct mailimap_extension_data * ext_data)
{
if (ext_data == NULL)
return;
if (ext_data->ext_data != NULL) {
mailimap_namespace_data_free((struct mailimap_namespace_data *) ext_data->ext_data);
}

@ -0,0 +1,689 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2013 - 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.
*/
#include "qresync.h"
#include "qresync_private.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "mailimap_sender.h"
#include "mailimap.h"
#include "condstore.h"
#include "condstore_private.h"
#include "mailimap_keywords.h"
#include "mailimap_parser.h"
/*
capability =/ "QRESYNC"
select-param = "QRESYNC" SP "(" uidvalidity SP
mod-sequence-value [SP known-uids]
[SP seq-match-data] ")"
;; conforms to the generic select-param
;; syntax defined in [IMAPABNF]
seq-match-data = "(" known-sequence-set SP known-uid-set ")"
uidvalidity = nz-number
known-uids = sequence-set
;; sequence of UIDs, "*" is not allowed
known-sequence-set = sequence-set
;; set of message numbers corresponding to
;; the UIDs in known-uid-set, in ascending order.
;; * is not allowed.
known-uid-set = sequence-set
;; set of UIDs corresponding to the messages in
;; known-sequence-set, in ascending order.
;; * is not allowed.
message-data =/ expunged-resp
expunged-resp = "VANISHED" [SP "(EARLIER)"] SP known-uids
rexpunges-fetch-mod = "VANISHED"
;; VANISHED UID FETCH modifier conforms
;; to the fetch-modifier syntax
;; defined in [IMAPABNF]. It is only
;; allowed in the UID FETCH command.
resp-text-code =/ "CLOSED"
*/
enum {
MAILIMAP_QRESYNC_TYPE_VANISHED,
MAILIMAP_QRESYNC_TYPE_RESPTEXTCODE
};
static void
mailimap_qresync_extension_data_free(struct mailimap_extension_data * ext_data);
static int
mailimap_qresync_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);
struct mailimap_extension_api mailimap_extension_qresync = {
/* name */ "QRESYNC",
/* extension_id */ MAILIMAP_EXTENSION_QRESYNC,
/* parser */ mailimap_qresync_extension_parse,
/* free */ mailimap_qresync_extension_data_free
};
int mailimap_select_qresync_send(mailstream * fd, const char * mb,
uint32_t uidvalidity, uint64_t modseq_value,
struct mailimap_set * known_uids,
struct mailimap_set * seq_match_data_sequences,
struct mailimap_set * seq_match_data_uids)
{
int r;
/*
select-param = "QRESYNC" SP "(" uidvalidity SP
mod-sequence-value [SP known-uids]
[SP seq-match-data] ")"
*/
r = mailimap_token_send(fd, "SELECT");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mailbox_send(fd, mb);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_token_send(fd, "QRESYNC");
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_number_send(fd, uidvalidity);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mod_sequence_value_send(fd, modseq_value);
if (r != MAILIMAP_NO_ERROR)
return r;
if (known_uids != NULL) {
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_set_send(fd, known_uids);
if (r != MAILIMAP_NO_ERROR)
return r;
}
if ((seq_match_data_sequences != NULL) && (seq_match_data_uids != NULL)) {
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
/* seq-match-data = "(" known-sequence-set SP known-uid-set ")" */
r = mailimap_oparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_set_send(fd, seq_match_data_sequences);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_set_send(fd, seq_match_data_uids);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_cparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
}
r = mailimap_cparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
}
static struct mailimap_qresync_vanished * get_vanished(mailimap * session)
{
struct mailimap_qresync_vanished * vanished;
clistiter * cur;
vanished = 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_QRESYNC) {
continue;
}
if (ext_data->ext_type != MAILIMAP_QRESYNC_TYPE_VANISHED) {
continue;
}
vanished = ext_data->ext_data;
ext_data->ext_data = NULL;
break;
}
return vanished;
}
static uint64_t get_mod_sequence_value(mailimap * session)
{
uint64_t mod_sequence_value;
clistiter * cur;
mod_sequence_value = 0;
for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
struct mailimap_extension_data * ext_data;
struct mailimap_condstore_resptextcode * resptextcode;
ext_data = clist_content(cur);
if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
continue;
}
if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_RESP_TEXT_CODE) {
continue;
}
resptextcode = ext_data->ext_data;
switch (resptextcode->cs_type) {
case MAILIMAP_CONDSTORE_RESPTEXTCODE_HIGHESTMODSEQ:
mod_sequence_value = resptextcode->cs_data.cs_modseq_value;
break;
case MAILIMAP_CONDSTORE_RESPTEXTCODE_NOMODSEQ:
mod_sequence_value = 0;
break;
}
}
return mod_sequence_value;
}
int mailimap_select_qresync(mailimap * session, const char * mb,
uint32_t uidvalidity, uint64_t modseq_value,
struct mailimap_set * known_uids,
struct mailimap_set * seq_match_data_sequences,
struct mailimap_set * seq_match_data_uids,
clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished,
uint64_t * p_mod_sequence_value)
{
struct mailimap_response * response;
int r;
int error_code;
uint64_t mod_sequence_value;
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_qresync_send(session->imap_stream, mb, uidvalidity, modseq_value,
known_uids, seq_match_data_sequences, seq_match_data_uids);
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;
* fetch_result = session->imap_response_info->rsp_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
if (p_vanished != NULL) {
* p_vanished = get_vanished(session);
}
mod_sequence_value = get_mod_sequence_value(session);
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;
* p_mod_sequence_value = mod_sequence_value;
return MAILIMAP_NO_ERROR;
default:
mailimap_selection_info_free(session->imap_selection_info);
session->imap_selection_info = NULL;
session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
* p_mod_sequence_value = mod_sequence_value;
if (* fetch_result != NULL) {
mailimap_fetch_list_free(* fetch_result);
}
if (* p_vanished != NULL) {
mailimap_qresync_vanished_free(* p_vanished);
}
return MAILIMAP_ERROR_SELECT;
}
}
int mailimap_fetch_qresync(mailimap * session,
struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value,
clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished)
{
return mailimap_fetch_qresync_vanished(session, set, fetch_type, mod_sequence_value, 1,
fetch_result, p_vanished);
}
static int send_fetch_param(mailstream * fd, uint64_t mod_sequence_value, int vanished)
{
int r;
if (mod_sequence_value == 0)
return MAILIMAP_NO_ERROR;
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_token_send(fd, "CHANGEDSINCE");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_mod_sequence_value_send(fd, mod_sequence_value);
if (r != MAILIMAP_NO_ERROR)
return r;
if (vanished) {
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_token_send(fd, "VANISHED");
if (r != MAILIMAP_NO_ERROR)
return r;
}
r = mailimap_cparenth_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
}
int mailimap_fetch_qresync_vanished(mailimap * session,
struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value, int vanished,
clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished)
{
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_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
r = send_fetch_param(session->imap_stream, mod_sequence_value, vanished);
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;
* fetch_result = session->imap_response_info->rsp_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
if (p_vanished != NULL) {
* p_vanished = get_vanished(session);
}
if (clist_count(* fetch_result) == 0) {
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
}
else {
error_code = MAILIMAP_RESP_COND_STATE_OK;
}
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
if (* fetch_result != NULL) {
mailimap_fetch_list_free(* fetch_result);
}
if (* p_vanished != NULL) {
mailimap_qresync_vanished_free(* p_vanished);
}
return MAILIMAP_ERROR_FETCH;
}
}
int mailimap_uid_fetch_qresync(mailimap * session,
struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value,
clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished)
{
return mailimap_uid_fetch_qresync_vanished(session, set, fetch_type, mod_sequence_value, 1,
fetch_result, p_vanished);
}
int mailimap_uid_fetch_qresync_vanished(mailimap * session,
struct mailimap_set * set,
struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value, int vanished,
clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished)
{
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_fetch_send(session->imap_stream, set, fetch_type);
if (r != MAILIMAP_NO_ERROR)
return r;
r = send_fetch_param(session->imap_stream, mod_sequence_value, vanished);
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;
}
* fetch_result = session->imap_response_info->rsp_fetch_list;
session->imap_response_info->rsp_fetch_list = NULL;
if (p_vanished != NULL) {
* p_vanished = get_vanished(session);
}
if (clist_count(* fetch_result) == 0) {
error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
}
else {
error_code = MAILIMAP_RESP_COND_STATE_OK;
}
mailimap_response_free(response);
switch (error_code) {
case MAILIMAP_RESP_COND_STATE_OK:
return MAILIMAP_NO_ERROR;
default:
if (* fetch_result != NULL) {
mailimap_fetch_list_free(* fetch_result);
}
if (* p_vanished != NULL) {
mailimap_qresync_vanished_free(* p_vanished);
}
return MAILIMAP_ERROR_UID_FETCH;
}
}
int mailimap_has_qresync(mailimap * session)
{
return mailimap_has_extension(session, "QRESYNC");
}
static void
mailimap_qresync_extension_data_free(struct mailimap_extension_data * ext_data)
{
switch (ext_data->ext_type) {
case MAILIMAP_QRESYNC_TYPE_VANISHED:
if (ext_data->ext_data != NULL) {
mailimap_qresync_vanished_free(ext_data->ext_data);
}
break;
case MAILIMAP_QRESYNC_TYPE_RESPTEXTCODE:
if (ext_data->ext_data != NULL) {
mailimap_qresync_resptextcode_free(ext_data->ext_data);
}
break;
}
free(ext_data);
}
static int resp_text_code_parse(mailstream * fd,
MMAPString * buffer, size_t * indx,
struct mailimap_qresync_resptextcode ** result);
static int vanished_parse(mailstream * fd,
MMAPString * buffer, size_t * indx,
struct mailimap_qresync_vanished ** result);
static int
mailimap_qresync_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)
{
size_t cur_token;
int r;
cur_token = * indx;
switch (calling_parser) {
case MAILIMAP_EXTENDED_PARSER_RESP_TEXT_CODE: {
struct mailimap_qresync_resptextcode * resptextcode;
struct mailimap_extension_data * ext_data;
r = resp_text_code_parse(fd, buffer, &cur_token, &resptextcode);
if (r != MAILIMAP_NO_ERROR)
return r;
ext_data = mailimap_extension_data_new(&mailimap_extension_qresync,
MAILIMAP_QRESYNC_TYPE_RESPTEXTCODE, resptextcode);
if (ext_data == NULL) {
mailimap_qresync_resptextcode_free(resptextcode);
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
return MAILIMAP_NO_ERROR;
}
case MAILIMAP_EXTENDED_PARSER_RESPONSE_DATA: {
struct mailimap_qresync_vanished * vanished;
struct mailimap_extension_data * ext_data;
r = vanished_parse(fd, buffer, &cur_token, &vanished);
if (r != MAILIMAP_NO_ERROR)
return r;
ext_data = mailimap_extension_data_new(&mailimap_extension_qresync,
MAILIMAP_QRESYNC_TYPE_VANISHED, vanished);
if (ext_data == NULL) {
mailimap_qresync_vanished_free(vanished);
return MAILIMAP_ERROR_MEMORY;
}
* indx = cur_token;
* result = ext_data;
return MAILIMAP_NO_ERROR;
}
}
return MAILIMAP_ERROR_PARSE;
}
static int resp_text_code_parse(mailstream * fd,
MMAPString * buffer, size_t * indx,
struct mailimap_qresync_resptextcode ** result)
{
int r;
size_t cur_token;
cur_token = * indx;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "CLOSED");
if (r == MAILIMAP_NO_ERROR) {
struct mailimap_qresync_resptextcode * resptextcode;
resptextcode = mailimap_qresync_resptextcode_new(MAILIMAP_QRESYNC_RESPTEXTCODE_CLOSED);
if (resptextcode == NULL)
return MAILIMAP_ERROR_MEMORY;
* indx = cur_token;
*