Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implemented Gmail X-GM-LABELS extension

  • Loading branch information...
commit 01b2aedbd3ff8febe85beb7227f81895bb2eee3a 1 parent e23e23e
@dinhviethoa dinhviethoa authored
View
10 build-mac/libetpan.xcodeproj/project.pbxproj
@@ -359,6 +359,9 @@
C69AB2DA1054704000F32FBD /* uidplus_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = C6F9EA1D105335BC0059C3BA /* uidplus_parser.c */; };
C69AB2DC1054704000F32FBD /* uidplus_sender.c in Sources */ = {isa = PBXBuildFile; fileRef = C6F9EA1F105335BC0059C3BA /* uidplus_sender.c */; };
C69AB2DE1054704000F32FBD /* uidplus_types.c in Sources */ = {isa = PBXBuildFile; fileRef = C6F9EA21105335BC0059C3BA /* uidplus_types.c */; };
+ C69AD25F14AB2062003D04D5 /* xgmlabels.c in Sources */ = {isa = PBXBuildFile; fileRef = C6CE9B1514AA9C8900D20BA6 /* xgmlabels.c */; };
+ C6CE9B1614AA9C8B00D20BA6 /* xgmlabels.c in Sources */ = {isa = PBXBuildFile; fileRef = C6CE9B1514AA9C8900D20BA6 /* xgmlabels.c */; };
+ C6CE9B1914AA9C9D00D20BA6 /* xgmlabels.h in Headers */ = {isa = PBXBuildFile; fileRef = C6CE9B1814AA9C9C00D20BA6 /* xgmlabels.h */; };
C6DC671C1083CDA000FA050B /* acl.h in Headers */ = {isa = PBXBuildFile; fileRef = C6DC66931083CDA000FA050B /* acl.h */; settings = {ATTRIBUTES = (Public, ); }; };
C6DC671D1083CDA000FA050B /* acl_types.h in Headers */ = {isa = PBXBuildFile; fileRef = C6DC66941083CDA000FA050B /* acl_types.h */; settings = {ATTRIBUTES = (Public, ); }; };
C6DC671E1083CDA000FA050B /* annotatemore.h in Headers */ = {isa = PBXBuildFile; fileRef = C6DC66951083CDA000FA050B /* annotatemore.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -707,6 +710,8 @@
C68C6205130FFE7E00F16728 /* quota.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = quota.h; sourceTree = "<group>"; };
C69AAFB51054298E00F32FBD /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
C69AB10A10546FE500F32FBD /* libetpan.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libetpan.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ C6CE9B1514AA9C8900D20BA6 /* xgmlabels.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xgmlabels.c; sourceTree = "<group>"; };
+ C6CE9B1814AA9C9C00D20BA6 /* xgmlabels.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xgmlabels.h; sourceTree = "<group>"; };
C6DC66931083CDA000FA050B /* acl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = acl.h; sourceTree = "<group>"; };
C6DC66941083CDA000FA050B /* acl_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = acl_types.h; sourceTree = "<group>"; };
C6DC66951083CDA000FA050B /* annotatemore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = annotatemore.h; sourceTree = "<group>"; };
@@ -1887,6 +1892,8 @@
C6F9EA22105335BC0059C3BA /* uidplus_types.h */,
C6667DED1342ACCD00969A8E /* xlist.c */,
C6667DEE1342ACCD00969A8E /* xlist.h */,
+ C6CE9B1514AA9C8900D20BA6 /* xgmlabels.c */,
+ C6CE9B1814AA9C9C00D20BA6 /* xgmlabels.h */,
);
path = imap;
sourceTree = "<group>";
@@ -2379,6 +2386,7 @@
C68C620D130FFE7E00F16728 /* quota.h in Headers */,
C6667DF01342ACCD00969A8E /* xlist.h in Headers */,
C6EFB8791433F1F300F805C0 /* mailstream_cfstream.h in Headers */,
+ C6CE9B1914AA9C9D00D20BA6 /* xgmlabels.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2621,6 +2629,7 @@
C6517A0E130E86D3004ADD56 /* namespace_sender.c in Sources */,
C6667DEF1342ACCD00969A8E /* xlist.c in Sources */,
C6EFB8781433F1F300F805C0 /* mailstream_cfstream.c in Sources */,
+ C6CE9B1614AA9C8B00D20BA6 /* xgmlabels.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2787,6 +2796,7 @@
C6517A10130E86D3004ADD56 /* namespace_sender.c in Sources */,
C6667DF11342ACCD00969A8E /* xlist.c in Sources */,
C6EFB87A1433F1F300F805C0 /* mailstream_cfstream.c in Sources */,
+ C69AD25F14AB2062003D04D5 /* xgmlabels.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
5 src/low-level/imap/Makefile.am
@@ -42,7 +42,7 @@ etpaninclude_HEADERS = \
quota.h quota_parser.h quota_sender.h quota_types.h \
idle.h \
namespace.h namespace_parser.h namespace_sender.h namespace_types.h \
- xlist.h
+ xlist.h xgmlabels.h
AM_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_srcdir)/src/data-types
@@ -81,4 +81,5 @@ libimap_la_SOURCES = \
namespace_parser.c namespace_parser.h \
namespace_sender.c namespace_sender.h \
namespace_types.c namespace_types.h \
- xlist.c xlist.h
+ xlist.c xlist.h \
+ xgmlabels.c xgmlabels.h
View
1  src/low-level/imap/mailimap.h
@@ -55,6 +55,7 @@ extern "C" {
#include <libetpan/quota.h>
#include <libetpan/namespace.h>
#include <libetpan/xlist.h>
+#include <libetpan/xgmlabels.h>
/*
mailimap_connect()
View
2  src/low-level/imap/mailimap_extension.c
@@ -46,6 +46,7 @@
#include "quota.h"
#include "namespace.h"
#include "xlist.h"
+#include "xgmlabels.h"
/*
the list of registered extensions (struct mailimap_extension_api *)
@@ -62,6 +63,7 @@ static struct mailimap_extension_api * internal_extension_list[] = {
&mailimap_extension_quota,
&mailimap_extension_namespace,
&mailimap_extension_xlist,
+ &mailimap_extension_xgmlabels,
};
LIBETPAN_EXPORT
View
6 src/low-level/imap/mailimap_extension_types.h
@@ -13,7 +13,8 @@ enum {
MAILIMAP_EXTENSION_UIDPLUS, /* UIDPLUS */
MAILIMAP_EXTENSION_QUOTA, /* quota */
MAILIMAP_EXTENSION_NAMESPACE, /* namespace */
- MAILIMAP_EXTENSION_XLIST /* XLIST (Gmail and Zimbra have this) */
+ MAILIMAP_EXTENSION_XLIST, /* XLIST (Gmail and Zimbra have this) */
+ MAILIMAP_EXTENSION_XGMLABELS /* X-GM-LABELS (Gmail) */
};
@@ -25,7 +26,8 @@ enum {
enum {
MAILIMAP_EXTENDED_PARSER_RESPONSE_DATA,
MAILIMAP_EXTENDED_PARSER_RESP_TEXT_CODE,
- MAILIMAP_EXTENDED_PARSER_MAILBOX_DATA
+ MAILIMAP_EXTENDED_PARSER_MAILBOX_DATA,
+ MAILIMAP_EXTENDED_PARSER_FETCH_DATA
};
/*
View
13 src/low-level/imap/mailimap_parser.c
@@ -7457,6 +7457,7 @@ mailimap_msg_att_item_parse_progress(mailstream * fd, MMAPString * buffer,
int type;
struct mailimap_msg_att_dynamic * msg_att_dynamic;
struct mailimap_msg_att_static * msg_att_static;
+ struct mailimap_extension_data * msg_att_extension;
size_t cur_token;
struct mailimap_msg_att_item * item;
int r;
@@ -7466,6 +7467,7 @@ mailimap_msg_att_item_parse_progress(mailstream * fd, MMAPString * buffer,
msg_att_dynamic = NULL;
msg_att_static = NULL;
+ msg_att_extension = NULL;
type = MAILIMAP_MSG_ATT_ITEM_ERROR; /* XXX - removes a gcc warning */
@@ -7484,12 +7486,19 @@ mailimap_msg_att_item_parse_progress(mailstream * fd, MMAPString * buffer,
type = MAILIMAP_MSG_ATT_ITEM_STATIC;
}
+ if (r == MAILIMAP_ERROR_PARSE) {
+ r = mailimap_extension_data_parse(MAILIMAP_EXTENDED_PARSER_FETCH_DATA,
+ fd, buffer, &cur_token, &msg_att_extension, progr_rate, progr_fun);
+ if (r == MAILIMAP_NO_ERROR)
+ type = MAILIMAP_MSG_ATT_ITEM_EXTENSION;
+ }
+
if (r != MAILIMAP_NO_ERROR) {
res = r;
goto err;
}
- item = mailimap_msg_att_item_new(type, msg_att_dynamic, msg_att_static);
+ item = mailimap_msg_att_item_new(type, msg_att_dynamic, msg_att_static, msg_att_extension);
if (item == NULL) {
res = MAILIMAP_ERROR_MEMORY;
goto free;
@@ -7501,6 +7510,8 @@ mailimap_msg_att_item_parse_progress(mailstream * fd, MMAPString * buffer,
return MAILIMAP_NO_ERROR;
free:
+ if (msg_att_extension != NULL)
+ mailimap_extension_data_free(msg_att_extension);
if (msg_att_dynamic != NULL)
mailimap_msg_att_dynamic_free(msg_att_dynamic);
if (msg_att_static != NULL)
View
6 src/low-level/imap/mailimap_sender.c
@@ -1247,6 +1247,12 @@ static int mailimap_fetch_att_send(mailstream * fd,
}
return MAILIMAP_NO_ERROR;
+ case MAILIMAP_FETCH_ATT_EXTENSION:
+ r = mailimap_token_send(fd, fetch_att->att_extension);
+ if (r != MAILIMAP_NO_ERROR)
+ return r;
+ return MAILIMAP_NO_ERROR;
+
default:
/* should not happen */
return MAILIMAP_ERROR_INVAL;
View
14 src/low-level/imap/mailimap_types.c
@@ -1586,7 +1586,8 @@ mailimap_message_data_free(struct mailimap_message_data * msg_data)
struct mailimap_msg_att_item *
mailimap_msg_att_item_new(int att_type,
struct mailimap_msg_att_dynamic * att_dyn,
- struct mailimap_msg_att_static * att_static)
+ struct mailimap_msg_att_static * att_static,
+ struct mailimap_extension_data * att_extension_data)
{
struct mailimap_msg_att_item * item;
@@ -1602,6 +1603,9 @@ mailimap_msg_att_item_new(int att_type,
case MAILIMAP_MSG_ATT_ITEM_STATIC:
item->att_data.att_static = att_static;
break;
+ case MAILIMAP_MSG_ATT_ITEM_EXTENSION:
+ item->att_data.att_extension_data = att_extension_data;
+ break;
}
return item;
@@ -1617,6 +1621,9 @@ mailimap_msg_att_item_free(struct mailimap_msg_att_item * item)
case MAILIMAP_MSG_ATT_ITEM_STATIC:
mailimap_msg_att_static_free(item->att_data.att_static);
break;
+ case MAILIMAP_MSG_ATT_ITEM_EXTENSION:
+ mailimap_extension_data_free(item->att_data.att_extension_data);
+ break;
}
free(item);
}
@@ -2558,7 +2565,7 @@ void mailimap_date_free(struct mailimap_date * date)
struct mailimap_fetch_att *
mailimap_fetch_att_new(int att_type, struct mailimap_section * att_section,
- uint32_t att_offset, uint32_t att_size)
+ uint32_t att_offset, uint32_t att_size, char * att_extension)
{
struct mailimap_fetch_att * fetch_att;
@@ -2569,12 +2576,15 @@ mailimap_fetch_att_new(int att_type, struct mailimap_section * att_section,
fetch_att->att_section = att_section;
fetch_att->att_offset = att_offset;
fetch_att->att_size = att_size;
+ fetch_att->att_extension = att_extension;
return fetch_att;
}
void mailimap_fetch_att_free(struct mailimap_fetch_att * fetch_att)
{
+ if (fetch_att->att_extension != NULL)
+ free(fetch_att->att_extension);
if (fetch_att->att_section != NULL)
mailimap_section_free(fetch_att->att_section);
free(fetch_att);
View
26 src/low-level/imap/mailimap_types.h
@@ -1824,21 +1824,24 @@ mailimap_message_data_free(struct mailimap_message_data * msg_data);
enum {
MAILIMAP_MSG_ATT_ITEM_ERROR, /* on parse error */
MAILIMAP_MSG_ATT_ITEM_DYNAMIC, /* dynamic message attributes (flags) */
- MAILIMAP_MSG_ATT_ITEM_STATIC /* static messages attributes
+ MAILIMAP_MSG_ATT_ITEM_STATIC, /* static messages attributes
(message content) */
+ MAILIMAP_MSG_ATT_ITEM_EXTENSION /* extension data */
};
/*
mailimap_msg_att_item is a message attribute
- type is the type of message attribute, the value can be
- MAILIMAP_MSG_ATT_ITEM_DYNAMIC or MAILIMAP_MSG_ATT_ITEM_STATIC
+ MAILIMAP_MSG_ATT_ITEM_DYNAMIC, MAILIMAP_MSG_ATT_ITEM_STATIC or MAILIMAP_MSG_ATT_ITEM_EXTENSION
- - msg_att_dyn is a dynamic message attribute when type is
+ - att_dyn is a dynamic message attribute when type is
MAILIMAP_MSG_ATT_ITEM_DYNAMIC
- - msg_att_static is a static message attribute when type is
+ - att_static is a static message attribute when type is
MAILIMAP_MSG_ATT_ITEM_STATIC
+
+ - att_extension_data is an extension data.
*/
struct mailimap_msg_att_item {
@@ -1846,13 +1849,15 @@ struct mailimap_msg_att_item {
union {
struct mailimap_msg_att_dynamic * att_dyn; /* can be NULL */
struct mailimap_msg_att_static * att_static; /* can be NULL */
+ struct mailimap_extension_data * att_extension_data; /* can be NULL */
} att_data;
};
struct mailimap_msg_att_item *
mailimap_msg_att_item_new(int att_type,
struct mailimap_msg_att_dynamic * att_dyn,
- struct mailimap_msg_att_static * att_static);
+ struct mailimap_msg_att_static * att_static,
+ struct mailimap_extension_data * att_extension_data);
void
mailimap_msg_att_item_free(struct mailimap_msg_att_item * item);
@@ -2659,8 +2664,9 @@ enum {
additional information */
MAILIMAP_FETCH_ATT_UID, /* to fetch the unique identifier */
MAILIMAP_FETCH_ATT_BODY_SECTION, /* to fetch a given part */
- MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION /* to fetch a given part without
+ MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, /* to fetch a given part without
marking the message as read */
+ MAILIMAP_FETCH_ATT_EXTENSION
};
@@ -2673,7 +2679,8 @@ enum {
MAILIMAP_FETCH_ATT_RFC822_HEADER, MAILIMAP_FETCH_ATT_RFC822_SIZE,
MAILIMAP_FETCH_ATT_RFC822_TEXT, MAILIMAP_FETCH_ATT_BODY,
MAILIMAP_FETCH_ATT_BODYSTRUCTURE, MAILIMAP_FETCH_ATT_UID,
- MAILIMAP_FETCH_ATT_BODY_SECTION or MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION
+ MAILIMAP_FETCH_ATT_BODY_SECTION, MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION,
+ MAILIMAP_FETCH_ATT_EXTENSION
- section is the location of the part to fetch if type is
MAILIMAP_FETCH_ATT_BODY_SECTION or MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION
@@ -2681,6 +2688,8 @@ enum {
- offset is the first byte to fetch in the given part
- size is the maximum size of the part to fetch
+
+ - att_extension: keyword to send when MAILIMAP_FETCH_ATT_EXTENSION is used
*/
struct mailimap_fetch_att {
@@ -2688,12 +2697,13 @@ struct mailimap_fetch_att {
struct mailimap_section * att_section;
uint32_t att_offset;
uint32_t att_size;
+ char * att_extension; /* can be NULL */
};
LIBETPAN_EXPORT
struct mailimap_fetch_att *
mailimap_fetch_att_new(int att_type, struct mailimap_section * att_section,
- uint32_t att_offset, uint32_t att_size);
+ uint32_t att_offset, uint32_t att_size, char * att_extension);
LIBETPAN_EXPORT
View
33 src/low-level/imap/mailimap_types_helper.c
@@ -497,73 +497,73 @@ mailimap_section_new_part_text(struct mailimap_section_part * part)
struct mailimap_fetch_att *
mailimap_fetch_att_new_envelope(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_ENVELOPE, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_ENVELOPE, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_flags(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_FLAGS, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_FLAGS, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_internaldate(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_INTERNALDATE, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_INTERNALDATE, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_rfc822(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_rfc822_header(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_HEADER, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_HEADER, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_rfc822_size(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_SIZE, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_SIZE, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_rfc822_text(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_TEXT, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_TEXT, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_body(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_bodystructure(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODYSTRUCTURE, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODYSTRUCTURE, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_uid(void)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_UID, NULL, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_UID, NULL, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_body_section(struct mailimap_section * section)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_SECTION, section, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_SECTION, section, 0, 0, NULL);
}
struct mailimap_fetch_att *
mailimap_fetch_att_new_body_peek_section(struct mailimap_section * section)
{
- return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, section, 0, 0);
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, section, 0, 0, NULL);
}
struct mailimap_fetch_att *
@@ -571,7 +571,7 @@ mailimap_fetch_att_new_body_section_partial(struct mailimap_section * section,
uint32_t offset, uint32_t size)
{
return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_SECTION, section,
- offset, size);
+ offset, size, NULL);
}
struct mailimap_fetch_att *
@@ -579,9 +579,14 @@ mailimap_fetch_att_new_body_peek_section_partial(struct mailimap_section * secti
uint32_t offset, uint32_t size)
{
return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, section,
- offset, size);
+ offset, size, NULL);
}
+struct mailimap_fetch_att *
+mailimap_fetch_att_new_extension(char * ext_keyword)
+{
+ return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_EXTENSION, NULL, 0, 0, ext_keyword);
+}
struct mailimap_fetch_type *
View
7 src/low-level/imap/mailimap_types_helper.h
@@ -320,6 +320,13 @@ mailimap_fetch_att_new_body_peek_section_partial(struct mailimap_section * secti
uint32_t offset, uint32_t size);
/*
+ creates a mailimap_fetch_att extension
+*/
+
+struct mailimap_fetch_att *
+ mailimap_fetch_att_new_extension(char * ext_keyword);
+
+/*
this function creates a mailimap_fetch_type structure to request
(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE) of a message
*/
View
286 src/low-level/imap/xgmlabels.c
@@ -0,0 +1,286 @@
+/*
+ * 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 "xgmlabels.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "clist.h"
+#include "mailimap_types_helper.h"
+#include "mailimap_extension.h"
+#include "mailimap_keywords.h"
+#include "mailimap_parser.h"
+
+struct mailimap_fetch_att * mailimap_fetch_att_new_xgmlabels(void)
+{
+ char * keyword;
+ struct mailimap_fetch_att * att;
+
+ keyword = strdup("X-GM-LABELS");
+ if (keyword == NULL)
+ return NULL;
+
+ att = mailimap_fetch_att_new_extension(keyword);
+ if (att == NULL) {
+ free(keyword);
+ return NULL;
+ }
+
+ return att;
+}
+
+int mailimap_has_xgmlabels(mailimap * session)
+{
+ return mailimap_has_extension(session, "X-GM-EXT-1");
+}
+
+struct mailimap_msg_att_xgmlabels * mailimap_msg_att_xgmlabels_new(clist * att_labels)
+{
+ struct mailimap_msg_att_xgmlabels * att;
+
+ att = malloc(sizeof(* att));
+ if (att == NULL)
+ return NULL;
+
+ att->att_labels = att_labels;
+
+ return att;
+}
+
+void mailimap_msg_att_xgmlabels_free(struct mailimap_msg_att_xgmlabels * att)
+{
+ clistiter * cur;
+
+ for(cur = clist_begin(att->att_labels) ; cur != NULL ; cur = clist_next(cur)) {
+ char * label;
+
+ label = clist_content(cur);
+ free(label);
+ }
+ clist_free(att->att_labels);
+ free(att);
+}
+
+struct mailimap_msg_att_xgmlabels * mailimap_msg_att_xgmlabels_new_empty(void)
+{
+ clist * list;
+ struct mailimap_msg_att_xgmlabels * att;
+
+ list = clist_new();
+ if (list == NULL)
+ return NULL;
+
+ att = mailimap_msg_att_xgmlabels_new(list);
+ if (att == NULL) {
+ clist_free(att->att_labels);
+ free(att);
+ return NULL;
+ }
+
+ return att;
+}
+
+int mailimap_msg_att_xgmlabels_add(struct mailimap_msg_att_xgmlabels * att, char * label)
+{
+ return clist_append(att->att_labels, label);
+}
+
+enum {
+ MAILIMAP_XGMLABELS_TYPE_XGMLABELS
+};
+
+/* extension data structure */
+
+static int
+mailimap_xgmlabels_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_xgmlabels_extension_data_free(struct mailimap_extension_data * ext_data);
+
+LIBETPAN_EXPORT
+struct mailimap_extension_api mailimap_extension_xgmlabels = {
+ /* name */ "X-GM-lABELS",
+ /* extension_id */ MAILIMAP_EXTENSION_XGMLABELS,
+ /* parser */ mailimap_xgmlabels_extension_parse,
+ /* free */ mailimap_xgmlabels_extension_data_free
+};
+
+static int mailimap_xgmlabels_parse(mailstream * fd,
+ MMAPString * buffer, size_t * indx,
+ clist ** result)
+{
+ size_t cur_token;
+ clist * list;
+ int r;
+ int res;
+
+ cur_token = * indx;
+
+ r = mailimap_oparenth_parse(fd, buffer, &cur_token);
+ if (r != MAILIMAP_NO_ERROR) {
+ res = r;
+ goto err;
+ }
+
+ r = mailimap_struct_spaced_list_parse(fd, buffer,
+ &cur_token, &list,
+ (mailimap_struct_parser * ) mailimap_astring_parse,
+ (mailimap_struct_destructor * ) mailimap_astring_free,
+ 0, NULL);
+ if (r == MAILIMAP_ERROR_PARSE) {
+ list = clist_new();
+ if (list == NULL) {
+ res = MAILIMAP_ERROR_MEMORY;
+ goto err;
+ }
+ }
+ else if (r != MAILIMAP_NO_ERROR) {
+ res = r;
+ goto err;
+ }
+
+ r = mailimap_cparenth_parse(fd, buffer, &cur_token);
+ if (r != MAILIMAP_NO_ERROR) {
+ res = r;
+ goto free_list;
+ }
+
+ * indx = cur_token;
+ * result = list;
+
+ return MAILIMAP_NO_ERROR;
+
+free_list:
+ clist_foreach(list, (clist_func) mailimap_astring_free, NULL);
+ clist_free(list);
+err:
+ return res;
+}
+
+static int fetch_data_xgmlabels_parse(mailstream * fd,
+ MMAPString * buffer, size_t * indx,
+ struct mailimap_msg_att_xgmlabels ** result)
+{
+ size_t cur_token;
+ struct mailimap_msg_att_xgmlabels * att;
+ clist * label_list;
+ int r;
+
+ cur_token = * indx;
+
+ r = mailimap_token_case_insensitive_parse(fd, buffer,
+ &cur_token, "X-GM-LABELS");
+ if (r != MAILIMAP_NO_ERROR)
+ return r;
+
+ r = mailimap_space_parse(fd, buffer, &cur_token);
+ if (r != MAILIMAP_NO_ERROR)
+ return r;
+
+ r = mailimap_xgmlabels_parse(fd, buffer, &cur_token, &label_list);
+ if (r != MAILIMAP_NO_ERROR)
+ return r;
+
+ att = mailimap_msg_att_xgmlabels_new(label_list);
+ if (att == NULL) {
+ clist_foreach(label_list, (clist_func) mailimap_astring_free, NULL);
+ clist_free(label_list);
+ return MAILIMAP_ERROR_MEMORY;
+ }
+
+ * indx = cur_token;
+ * result = att;
+
+ return MAILIMAP_NO_ERROR;
+}
+
+static int
+mailimap_xgmlabels_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 type;
+ struct mailimap_msg_att_xgmlabels * att;
+ void * data;
+ struct mailimap_extension_data * ext_data;
+ int r;
+
+ cur_token = * indx;
+
+ switch (calling_parser)
+ {
+ case MAILIMAP_EXTENDED_PARSER_FETCH_DATA:
+ att = NULL;
+ r = fetch_data_xgmlabels_parse(fd, buffer, &cur_token, &att);
+ if (r != MAILIMAP_NO_ERROR)
+ return r;
+
+ type = MAILIMAP_XGMLABELS_TYPE_XGMLABELS;
+ data = att;
+
+ ext_data = mailimap_extension_data_new(&mailimap_extension_xgmlabels,
+ type, data);
+ if (ext_data == NULL) {
+ if (att != NULL)
+ mailimap_msg_att_xgmlabels_free(att);
+ return MAILIMAP_ERROR_MEMORY;
+ }
+
+ * result = ext_data;
+ * indx = cur_token;
+
+ return MAILIMAP_NO_ERROR;
+
+ default:
+ return MAILIMAP_ERROR_PARSE;
+ }
+}
+
+static void
+mailimap_xgmlabels_extension_data_free(struct mailimap_extension_data * ext_data)
+{
+ if (ext_data == NULL)
+ return;
+
+ if (ext_data->ext_data != NULL) {
+ if (ext_data->ext_type == MAILIMAP_XGMLABELS_TYPE_XGMLABELS) {
+ mailimap_msg_att_xgmlabels_free((struct mailimap_msg_att_xgmlabels *) ext_data->ext_data);
+ }
+ }
+ free(ext_data);
+}
View
71 src/low-level/imap/xgmlabels.h
@@ -0,0 +1,71 @@
+/*
+ * 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 XGMLABELS_H
+#define XGMLABELS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <libetpan/libetpan-config.h>
+#include <libetpan/mailimap_extension.h>
+
+ struct mailimap_msg_att_xgmlabels {
+ clist * att_labels; /* != NULL */
+ };
+
+ LIBETPAN_EXPORT
+ extern struct mailimap_extension_api mailimap_extension_xgmlabels;
+
+ LIBETPAN_EXPORT
+ struct mailimap_fetch_att * mailimap_fetch_att_new_xgmlabels(void);
+
+ LIBETPAN_EXPORT
+ int mailimap_has_xgmlabels(mailimap * session);
+
+ LIBETPAN_EXPORT
+ struct mailimap_msg_att_xgmlabels * mailimap_msg_att_xgmlabels_new(clist * att_labels);
+
+ LIBETPAN_EXPORT
+ struct mailimap_msg_att_xgmlabels * mailimap_msg_att_xgmlabels_new_empty(void);
+
+ LIBETPAN_EXPORT
+ int mailimap_msg_att_xgmlabels_add(struct mailimap_msg_att_xgmlabels * att, char * label);
+
+ LIBETPAN_EXPORT void mailimap_msg_att_xgmlabels_free(struct mailimap_msg_att_xgmlabels * att);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.