added IMAP ENABLE extension.

dvh-chacham15-master
DINH Viet Hoa 10 years ago
parent 9ae5172518
commit c5344f1e34

@ -12,6 +12,11 @@
365DFFDB15D1CF6D00F2DD85 /* xgmmsgid.h in Headers */ = {isa = PBXBuildFile; fileRef = 365DFFDA15D1CF6D00F2DD85 /* xgmmsgid.h */; settings = {ATTRIBUTES = (Public, ); }; };
365DFFDF15D1F2F800F2DD85 /* mailstream_cfstream.h in Headers */ = {isa = PBXBuildFile; fileRef = 365DFFDE15D1F2F800F2DD85 /* mailstream_cfstream.h */; settings = {ATTRIBUTES = (Public, ); }; };
365DFFE515D1F3CD00F2DD85 /* xgmlabels.h in Headers */ = {isa = PBXBuildFile; fileRef = 365DFFE415D1F3CD00F2DD85 /* xgmlabels.h */; settings = {ATTRIBUTES = (Public, ); }; };
C60E7B9A16C3809400A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
C60E7B9B16C3809500A25BF4 /* enable.h in Headers */ = {isa = PBXBuildFile; fileRef = C60E7B9916C3809400A25BF4 /* enable.h */; };
C60E7B9D16C3809C00A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
C60E7B9E16C3809D00A25BF4 /* enable.c in Sources */ = {isa = PBXBuildFile; fileRef = C60E7B9816C3809400A25BF4 /* enable.c */; };
C60E7BA016C380D300A25BF4 /* enable.h in Headers */ = {isa = PBXBuildFile; fileRef = C60E7B9F16C380D300A25BF4 /* enable.h */; settings = {ATTRIBUTES = (Public, ); }; };
C6451AFE1083D316003135FD /* mailimf_write.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F9EA32105335BC0059C3BA /* mailimf_write.h */; };
C6451AFF1083D316003135FD /* mhdriver_cached.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F9E913105335BC0059C3BA /* mhdriver_cached.h */; };
C6451B001083D316003135FD /* mhdriver_types.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F9E91A105335BC0059C3BA /* mhdriver_types.h */; };
@ -892,6 +897,9 @@
365DFFE415D1F3CD00F2DD85 /* xgmlabels.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xgmlabels.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>"; };
C60E7B9916C3809400A25BF4 /* enable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = enable.h; sourceTree = "<group>"; };
C60E7B9F16C380D300A25BF4 /* enable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = enable.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>"; };
@ -1515,6 +1523,7 @@
C6DC66921083CDA000FA050B /* libetpan */ = {
isa = PBXGroup;
children = (
C60E7B9F16C380D300A25BF4 /* enable.h */,
C6DC66931083CDA000FA050B /* acl.h */,
C6DC66941083CDA000FA050B /* acl_types.h */,
C6DC66951083CDA000FA050B /* annotatemore.h */,
@ -2054,6 +2063,8 @@
C6F9E9D3105335BC0059C3BA /* imap */ = {
isa = PBXGroup;
children = (
C60E7B9816C3809400A25BF4 /* enable.c */,
C60E7B9916C3809400A25BF4 /* enable.h */,
C64EA7B916A00CC100778456 /* mailimap_id_parser.c */,
C64EA7BA16A00CC100778456 /* mailimap_id_parser.h */,
C64EA7BB16A00CC200778456 /* mailimap_id_sender.c */,
@ -2633,6 +2644,8 @@
C64EA7C816A00CC500778456 /* mailimap_id_sender.h in Headers */,
C64EA7CC16A00CC500778456 /* mailimap_id_types.h in Headers */,
C64EA7D016A00CC500778456 /* mailimap_id.h in Headers */,
C60E7B9B16C3809500A25BF4 /* enable.h in Headers */,
C60E7BA016C380D300A25BF4 /* enable.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2919,6 +2932,7 @@
C64EA7C516A00CC500778456 /* mailimap_id_sender.c in Sources */,
C64EA7C916A00CC500778456 /* mailimap_id_types.c in Sources */,
C64EA7CD16A00CC500778456 /* mailimap_id.c in Sources */,
C60E7B9A16C3809400A25BF4 /* enable.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -3091,6 +3105,7 @@
C64EA7C716A00CC500778456 /* mailimap_id_sender.c in Sources */,
C64EA7CB16A00CC500778456 /* mailimap_id_types.c in Sources */,
C64EA7CF16A00CC500778456 /* mailimap_id.c in Sources */,
C60E7B9E16C3809D00A25BF4 /* enable.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -3263,6 +3278,7 @@
C64EA7C616A00CC500778456 /* mailimap_id_sender.c in Sources */,
C64EA7CA16A00CC500778456 /* mailimap_id_types.c in Sources */,
C64EA7CE16A00CC500778456 /* mailimap_id.c in Sources */,
C60E7B9D16C3809C00A25BF4 /* enable.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -43,7 +43,8 @@ etpaninclude_HEADERS = \
idle.h \
namespace.h namespace_parser.h namespace_sender.h namespace_types.h \
xlist.h xgmlabels.h xgmmsgid.h \
mailimap_id.h mailimap_id_types.h
mailimap_id.h mailimap_id_types.h \
enable.h
AM_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_srcdir)/src/data-types
@ -88,4 +89,6 @@ libimap_la_SOURCES = \
mailimap_id.h mailimap_id.c \
mailimap_id_types.h mailimap_id_types.c \
mailimap_id_sender.h mailimap_id_sender.c \
mailimap_id_parser.h mailimap_id_parser.c
mailimap_id_parser.h mailimap_id_parser.c \
enable.h enable.c

@ -0,0 +1,288 @@
/*
* 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.
*/
#include "enable.h"
#include <stdlib.h>
#include "mailimap_parser.h"
#include "mailimap_sender.h"
#include "mailimap.h"
#include "mailimap_keywords.h"
enum {
MAILIMAP_ENABLE_TYPE_ENABLE
};
static int
mailimap_enable_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_enable_extension_data_free(struct mailimap_extension_data * ext_data);
LIBETPAN_EXPORT
struct mailimap_extension_api mailimap_extension_enable = {
/* name */ "ENABLE",
/* extension_id */ MAILIMAP_EXTENSION_ENABLE,
/* parser */ mailimap_enable_extension_parse,
/* free */ mailimap_enable_extension_data_free
};
/*
"ENABLE" 1*(SP capability)
*/
static int mailimap_capability_info_send(mailstream * fd, struct mailimap_capability * cap)
{
int r;
switch (cap->cap_type) {
case MAILIMAP_CAPABILITY_AUTH_TYPE:
r = mailimap_token_send(fd, "AUTH=");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_token_send(fd, cap->cap_data.cap_auth_type);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
case MAILIMAP_CAPABILITY_NAME:
r = mailimap_token_send(fd, cap->cap_data.cap_name);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
default:
return MAILIMAP_ERROR_INVAL;
}
}
static int mailimap_capability_data_send(mailstream * fd, struct mailimap_capability_data * capabilities)
{
return mailimap_struct_spaced_list_send(fd, capabilities->cap_list,
(mailimap_struct_sender *) mailimap_capability_info_send);
}
static int mailimap_enable_send(mailstream * fd, struct mailimap_capability_data * capabilities)
{
int r;
r = mailimap_token_send(fd, "ENABLE");
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_space_send(fd);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_capability_data_send(fd, capabilities);
if (r != MAILIMAP_NO_ERROR)
return r;
return MAILIMAP_NO_ERROR;
}
LIBETPAN_EXPORT
int mailimap_enable(mailimap * session, struct mailimap_capability_data * capabilities,
struct mailimap_capability_data ** result)
{
struct mailimap_response * response;
int r;
int error_code;
clistiter * cur;
struct mailimap_capability_data * cap_data;
if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
return MAILIMAP_ERROR_BAD_STATE;
r = mailimap_send_current_tag(session);
if (r != MAILIMAP_NO_ERROR)
return r;
r = mailimap_enable_send(session->imap_stream, capabilities);
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;
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_capability_data * cap_data;
ext_data = clist_content(cur);
if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_ENABLE) {
continue;
}
if (ext_data->ext_type != MAILIMAP_ENABLE_TYPE_ENABLE) {
continue;
}
cap_data = ext_data->ext_data;
ext_data->ext_data = NULL;
break;
}
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:
* result = cap_data;
return MAILIMAP_NO_ERROR;
default:
mailimap_capability_data_free(cap_data);
return MAILIMAP_ERROR_EXTENSION;
}
}
LIBETPAN_EXPORT
int mailimap_has_enable(mailimap * session)
{
return mailimap_has_extension(session, "ENABLE");
}
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);
}
free(ext_data);
}
static int mailimap_enable_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
struct mailimap_capability_data ** result,
size_t progr_rate,
progress_function * progr_fun)
{
size_t cur_token;
int r;
int res;
struct mailimap_capability_data * capabilities;
cur_token = * indx;
r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "ENABLE");
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
r = mailimap_space_parse(fd, buffer, &cur_token);
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
r = mailimap_capability_data_parse(fd, buffer, &cur_token, &capabilities,
progr_rate, progr_fun);
if (r != MAILIMAP_NO_ERROR) {
res = r;
return r;
}
* result = capabilities;
* indx = cur_token;
return MAILIMAP_NO_ERROR;
}
static int
mailimap_enable_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;
struct mailimap_capability_data * capabilities = 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:
r = mailimap_enable_parse(fd, buffer, &cur_token,
&capabilities, progr_rate, progr_fun);
if (r == MAILIMAP_NO_ERROR) {
type = MAILIMAP_ENABLE_TYPE_ENABLE;
data = capabilities;
}
if (r != MAILIMAP_NO_ERROR) {
return r;
}
ext_data = mailimap_extension_data_new(&mailimap_extension_enable,
type, data);
if (ext_data == NULL) {
if (capabilities != NULL)
mailimap_capability_data_free(capabilities);
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;
}
}

@ -0,0 +1,56 @@
/*
* 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 ENABLE_H
#define ENABLE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <libetpan/mailimap_extension.h>
LIBETPAN_EXPORT
extern struct mailimap_extension_api mailimap_extension_enable;
LIBETPAN_EXPORT
int mailimap_enable(mailimap * session, struct mailimap_capability_data * capabilities,
struct mailimap_capability_data ** result);
LIBETPAN_EXPORT
int mailimap_has_enable(mailimap * session);
#ifdef __cplusplus
}
#endif
#endif

@ -55,6 +55,7 @@ extern "C" {
#include <libetpan/quota.h>
#include <libetpan/namespace.h>
#include <libetpan/mailimap_id.h>
#include <libetpan/enable.h>
#include <libetpan/xlist.h>
#include <libetpan/xgmlabels.h>
#include <libetpan/xgmmsgid.h>

@ -49,6 +49,7 @@
#include "xgmlabels.h"
#include "xgmmsgid.h"
#include "mailimap_id.h"
#include "enable.h"
/*
the list of registered extensions (struct mailimap_extension_api *)
@ -67,7 +68,8 @@ static struct mailimap_extension_api * internal_extension_list[] = {
&mailimap_extension_xlist,
&mailimap_extension_xgmlabels,
&mailimap_extension_xgmmsgid,
&mailimap_extension_id
&mailimap_extension_id,
&mailimap_extension_enable
};
LIBETPAN_EXPORT

@ -16,7 +16,8 @@ enum {
MAILIMAP_EXTENSION_XLIST, /* XLIST (Gmail and Zimbra have this) */
MAILIMAP_EXTENSION_XGMLABELS, /* X-GM-LABELS (Gmail) */
MAILIMAP_EXTENSION_XGMMSGID, /* X-GM-MSGID (Gmail) */
MAILIMAP_EXTENSION_ID /* ID */
MAILIMAP_EXTENSION_ID, /* ID */
MAILIMAP_EXTENSION_ENABLE /* ENABLE */
};

@ -274,14 +274,6 @@ mailimap_capability_parse(mailstream * fd, MMAPString * buffer,
static int
mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
struct mailimap_capability_data ** result,
size_t progr_rate,
progress_function * progr_fun);
/*
static gboolean mailimap_date_day_parse(mailstream * fd,
MMAPString * buffer,
@ -3934,7 +3926,7 @@ static int mailimap_capability_list_parse(mailstream * fd,
return MAILIMAP_NO_ERROR;
}
static int
int
mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
struct mailimap_capability_data ** result,
@ -3943,19 +3935,12 @@ mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
{
size_t cur_token;
clist * cap_list;
#if 0
clist * cap_list_2;
#endif
struct mailimap_capability_data * cap_data;
int r;
int res;
cur_token = * indx;
cap_list = NULL;
#if 0
cap_list_2 = NULL;
#endif
r = mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "CAPABILITY");
@ -3967,29 +3952,11 @@ mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
r = mailimap_capability_list_parse(fd, buffer, &cur_token,
&cap_list,
progr_rate, progr_fun);
if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE)) {
res = r;
goto err;
}
#if 0
if (!mailimap_space_parse(fd, buffer, &cur_token)) {
res = r;
goto free_list;
}
if (!mailimap_token_case_insensitive_parse(fd, buffer,
&cur_token, "IMAP4rev1"))
goto free_list;
r = mailimap_capability_list_parse(fd, buffer, &cur_token,
&cap_list_2,
progr_rate, progr_fun);
cap_list = g_list_concat(cap_list, cap_list_2);
#endif
cap_data = mailimap_capability_data_new(cap_list);
if (cap_data == NULL) {
res = MAILIMAP_ERROR_MEMORY;

@ -177,6 +177,12 @@ mailimap_struct_multiple_parse(mailstream * fd, MMAPString * buffer,
size_t progr_rate,
progress_function * progr_fun);
int mailimap_capability_data_parse(mailstream * fd, MMAPString * buffer,
size_t * indx,
struct mailimap_capability_data ** result,
size_t progr_rate,
progress_function * progr_fun);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save