aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-09-22 05:05:56 +0800
committerDan Winship <danw@src.gnome.org>2000-09-22 05:05:56 +0800
commit3af120103084dec827ae3026da10adb67fd89a79 (patch)
tree972a56ffdb6b2e7148c0c1b993093a765e415a56 /camel/providers/imap
parent08a52d10bc6dd001c42ebf3303b71460e9785210 (diff)
downloadgsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar.gz
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar.bz2
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar.lz
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar.xz
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.tar.zst
gsoc2013-evolution-3af120103084dec827ae3026da10adb67fd89a79.zip
New function to convert Camel flags to an IMAP flag_list.
* providers/imap/camel-imap-utils.c (imap_create_flag_list): New function to convert Camel flags to an IMAP flag_list. (imap_parse_flag_list): Contrariwise. * providers/imap/camel-imap-store.c (camel_imap_command_*): Make the @ret arg actually optional, as (mostly) documented. (various): Don't pass "&result" to camel_imap_command_* if we're just going to immediately free it. Don't record status if we're not going to look at it. * providers/imap/camel-imap-folder.c: Likewise. (imap_summary_free): Use camel_folder_info_free. (imap_sync): Use imap_create_flag_list. Clear CAMEL_MESSAGE_FOLDER_FLAGGED after syncing so we don't keep re-syncing. (imap_append_message): Use imap_create_flag_list. Don't leak the memstream if the append fails. (imap_move_message_to): Use camel_folder_delete_message rather than doing it by hand. (imap_get_summary_internal, imap_get_message_info_internal): Use imap_parse_flag_list and header_raw_clear. (camel_imap_folder_changed): Use camel_message_info_free. svn path=/trunk/; revision=5544
Diffstat (limited to 'camel/providers/imap')
-rw-r--r--camel/providers/imap/camel-imap-folder.c206
-rw-r--r--camel/providers/imap/camel-imap-store.c89
-rw-r--r--camel/providers/imap/camel-imap-utils.c60
-rw-r--r--camel/providers/imap/camel-imap-utils.h3
4 files changed, 135 insertions, 223 deletions
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index f0d69333ad..539b906ba6 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -133,7 +133,6 @@ camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class)
camel_folder_class->search_by_expression = imap_search_by_expression;
- /*camel_folder_class->get_permanent_flags = imap_get_permanent_flags;*/
camel_folder_class->get_message_flags = imap_get_message_flags;
camel_folder_class->set_message_flags = imap_set_message_flags;
camel_folder_class->get_message_user_flag = imap_get_message_user_flag;
@@ -208,24 +207,12 @@ camel_imap_folder_new (CamelStore *parent, char *folder_name)
static void
imap_summary_free (GPtrArray **summary)
{
- CamelMessageInfo *info;
GPtrArray *array = *summary;
- gint i, max;
+ gint i;
if (array) {
- max = array->len;
- for (i = 0; i < max; i++) {
- info = g_ptr_array_index (array, i);
- g_free (info->subject);
- g_free (info->from);
- g_free (info->to);
- g_free (info->cc);
- g_free (info->uid);
- g_free (info->message_id);
- header_references_list_clear (&info->references);
- g_free (info);
- info = NULL;
- }
+ for (i = 0; i < array->len; i++)
+ camel_folder_info_free (array->pdata[i]);
g_ptr_array_free (array, TRUE);
*summary = NULL;
@@ -290,26 +277,18 @@ imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
if (info->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) {
char *flags;
- flags = g_strconcat (info->flags & CAMEL_MESSAGE_SEEN ? "\\Seen " : "",
- info->flags & CAMEL_MESSAGE_DRAFT ? "\\Draft " : "",
- info->flags & CAMEL_MESSAGE_DELETED ? "\\Deleted " : "",
- info->flags & CAMEL_MESSAGE_ANSWERED ? "\\Answered " : "",
- NULL);
- if (*flags) {
- gchar *result;
+ flags = imap_create_flag_list (info->flags);
+ if (flags) {
gint s;
- *(flags + strlen (flags) - 1) = '\0';
- s = camel_imap_command_extended (store, folder, &result, ex,
- "UID STORE %s FLAGS.SILENT (%s)",
+ s = camel_imap_command_extended (store, folder, NULL, ex,
+ "UID STORE %s FLAGS.SILENT %s",
info->uid, flags);
-
if (s != CAMEL_IMAP_OK)
return;
-
- g_free (result);
+ g_free (flags);
}
- g_free (flags);
+ info->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
}
}
}
@@ -318,14 +297,8 @@ imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
static void
imap_expunge (CamelFolder *folder, CamelException *ex)
{
- gchar *result;
- gint status;
-
imap_sync (folder, FALSE, ex);
-
- status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder,
- &result, ex, "EXPUNGE");
- g_free (result);
+ camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, NULL, ex, "EXPUNGE");
}
static gint
@@ -420,21 +393,17 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
CamelStream *memstream;
GByteArray *ba;
- gchar *result, *cmdid;
- gchar *folder_path, *flagstr = NULL;
+ gchar *cmdid;
+ gchar *folder_path, *flagstr;
gint status;
folder_path = camel_imap_store_folder_path (store, folder->full_name);
/* create flag string param */
- if (info && info->flags) {
- flagstr = g_strconcat (" (", info->flags & CAMEL_MESSAGE_SEEN ? "\\Seen " : "",
- info->flags & CAMEL_MESSAGE_DRAFT ? "\\Draft " : "",
- info->flags & CAMEL_MESSAGE_DELETED ? "\\Answered " : "",
- NULL);
- if (flagstr)
- *(flagstr + strlen (flagstr) - 1) = ')';
- }
+ if (info && info->flags)
+ flagstr = imap_create_flag_list (info->flags);
+ else
+ flagstr = NULL;
ba = g_byte_array_new ();
memstream = camel_stream_mem_new_with_byte_array (ba);
@@ -443,24 +412,25 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, const Camel
camel_stream_write_string (memstream, "\r\n");
camel_stream_reset (memstream);
- status = camel_imap_command_preliminary (store, &cmdid, ex, "APPEND %s%s {%d}",
- folder_path, flagstr ? flagstr : "", ba->len - 2);
+ status = camel_imap_command_preliminary (store, &cmdid, ex, "APPEND %s%s%s {%d}",
+ folder_path, flagstr ? " " : "",
+ flagstr ? flagstr : "", ba->len - 2);
g_free (folder_path);
+ g_free (flagstr);
if (status != CAMEL_IMAP_PLUS) {
g_free (cmdid);
+ camel_object_unref (CAMEL_OBJECT (memstream));
return;
}
/* send the rest of our data - the mime message */
- status = camel_imap_command_continuation_with_stream (store, &result, cmdid, memstream, ex);
+ status = camel_imap_command_continuation_with_stream (store, NULL, cmdid, memstream, ex);
g_free (cmdid);
if (status != CAMEL_IMAP_OK)
return;
- g_free (result);
-
camel_object_unref (CAMEL_OBJECT (memstream));
camel_imap_folder_changed (folder, 1, NULL, ex);
}
@@ -469,19 +439,17 @@ static void
imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
- char *result, *folder_path;
+ char *folder_path;
int status;
folder_path = camel_imap_store_folder_path (store, destination->full_name);
- status = camel_imap_command_extended (store, source, &result, ex,
+ status = camel_imap_command_extended (store, source, NULL, ex,
"UID COPY %s %s", uid, folder_path);
g_free (folder_path);
if (status != CAMEL_IMAP_OK)
return;
- g_free (result);
-
camel_imap_folder_changed (destination, 1, NULL, ex);
}
@@ -490,30 +458,18 @@ static void
imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
- CamelMessageInfo *info;
- char *result, *folder_path;
+ char *folder_path;
int status;
folder_path = camel_imap_store_folder_path (store, destination->full_name);
- status = camel_imap_command_extended (store, source, &result, ex,
+ status = camel_imap_command_extended (store, source, NULL, ex,
"UID COPY %s %s", uid, folder_path);
g_free (folder_path);
if (status != CAMEL_IMAP_OK)
return;
- g_free (result);
-
- if (!(info = (CamelMessageInfo *)imap_get_message_info (source, uid))) {
- CamelService *service = CAMEL_SERVICE (store);
-
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- "Could not set flags for message %s on IMAP server %s: %s",
- uid, service->url->host, "Unknown error");
- return;
- }
-
- imap_set_message_flags (source, uid, CAMEL_MESSAGE_DELETED, ~(info->flags));
+ camel_folder_delete_message (source, uid);
camel_imap_folder_changed (destination, 1, NULL, ex);
}
@@ -521,7 +477,7 @@ imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destina
static GPtrArray *
imap_get_uids (CamelFolder *folder)
{
- CamelMessageInfo *info;
+ const CamelMessageInfo *info;
GPtrArray *array, *infolist;
gint i, count;
@@ -533,7 +489,7 @@ imap_get_uids (CamelFolder *folder)
g_ptr_array_set_size (array, count);
for (i = 0; i < count; i++) {
- info = (CamelMessageInfo *) g_ptr_array_index (infolist, i);
+ info = g_ptr_array_index (infolist, i);
array->pdata[i] = g_strdup (info->uid);
}
@@ -765,21 +721,11 @@ imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
d(fprintf (stderr, "Message:\n%s\n", mesg));
msgstream = camel_stream_mem_new_with_buffer (mesg, strlen (mesg) + 1);
-#if 0
- f_stream = camel_stream_filter_new_with_stream (msgstream);
- filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS);
- id = camel_stream_filter_add (f_stream, CAMEL_MIME_FILTER (filter));
-#endif
msg = camel_mime_message_new ();
d(fprintf (stderr, "*** We created the camel_mime_message ***\n"));
camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), msgstream);
-#if 0
- camel_stream_filter_remove (f_stream, id);
- camel_stream_close (CAMEL_STREAM (f_stream));
-#endif
camel_object_unref (CAMEL_OBJECT (msgstream));
- /*camel_object_unref (CAMEL_OBJECT (f_stream));*/
d(fprintf (stderr, "*** We're returning... ***\n"));
@@ -946,24 +892,7 @@ imap_get_summary_internal (CamelFolder *folder, CamelException *ex)
}
for (flags += 6; *flags && *flags != '('; flags++); /* advance to <flags> */
- for (q = flags; *q && *q != ')'; q++); /* find the end of <flags> */
- flags = g_strndup (flags, (gint)(q - flags + 1));
- /*d(fprintf (stderr, "*** info->flags = %s\n", flags));*/
-
- /* now we gotta parse for the flags */
- info->flags = 0;
- if (strstr (flags, "\\Seen"))
- info->flags |= CAMEL_MESSAGE_SEEN;
- if (strstr (flags, "\\Answered"))
- info->flags |= CAMEL_MESSAGE_ANSWERED;
- if (strstr (flags, "\\Flagged"))
- info->flags |= CAMEL_MESSAGE_FLAGGED;
- if (strstr (flags, "\\Deleted"))
- info->flags |= CAMEL_MESSAGE_DELETED;
- if (strstr (flags, "\\Draft"))
- info->flags |= CAMEL_MESSAGE_DRAFT;
- g_free (flags);
- flags = NULL;
+ info->flags = imap_parse_flag_list (flags);
/* construct the header list */
/* fast-forward to beginning of header info... */
@@ -1015,14 +944,7 @@ imap_get_summary_internal (CamelFolder *folder, CamelException *ex)
if (info->references == NULL)
info->references = header_references_decode (header_raw_find (&h, "in-reply-to", NULL));
- while (h) {
- struct _header_raw *next = h->next;
-
- g_free (h->name);
- g_free (h->value);
- g_free (h);
- h = next;
- }
+ header_raw_clear (&h);
g_ptr_array_add (summary, info);
g_hash_table_insert (hash, info->uid, info);
@@ -1098,24 +1020,7 @@ imap_get_message_info_internal (CamelFolder *folder, guint id, CamelException *e
}
for (flags += 6; *flags && *flags != '('; flags++); /* advance to <flags> */
- for (q = flags; *q && *q != ')'; q++); /* find the end of <flags> */
- flags = g_strndup (flags, (gint)(q - flags + 1));
- d(fprintf (stderr, "*** info->flags = %s\n", flags));
-
- /* now we gotta parse for the flags */
- info->flags = 0;
- if (strstr (flags, "\\Seen"))
- info->flags |= CAMEL_MESSAGE_SEEN;
- if (strstr (flags, "\\Answered"))
- info->flags |= CAMEL_MESSAGE_ANSWERED;
- if (strstr (flags, "\\Flagged"))
- info->flags |= CAMEL_MESSAGE_FLAGGED;
- if (strstr (flags, "\\Deleted"))
- info->flags |= CAMEL_MESSAGE_DELETED;
- if (strstr (flags, "\\Draft"))
- info->flags |= CAMEL_MESSAGE_DRAFT;
- g_free (flags);
- flags = NULL;
+ info->flags = imap_parse_flag_list (flags);
/* construct the header list */
/* fast-forward to beginning of header info... */
@@ -1167,15 +1072,7 @@ imap_get_message_info_internal (CamelFolder *folder, guint id, CamelException *e
if (info->references == NULL)
info->references = header_references_decode (header_raw_find (&h, "in-reply-to", NULL));
- while (h->next) {
- struct _header_raw *next = h->next;
-
- g_free (h->name);
- g_free (h->value);
- g_free (h);
- h = next;
- }
-
+ header_raw_clear (&h);
g_free (result);
return info;
@@ -1187,10 +1084,8 @@ imap_get_message_info (CamelFolder *folder, const char *uid)
{
CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- g_return_val_if_fail (*uid != '\0', NULL);
-
if (imap_folder->summary)
- return (CamelMessageInfo *) g_hash_table_lookup (imap_folder->summary_hash, uid);
+ return g_hash_table_lookup (imap_folder->summary_hash, uid);
return NULL;
}
@@ -1246,15 +1141,6 @@ imap_search_by_expression (CamelFolder *folder, const char *expression, CamelExc
return uids;
}
-#if 0
-static guint32
-imap_get_permanent_flags (CamelFolder *folder, CamelException *ex)
-{
- /* return permamnant flags */
- return folder->permanent_flags;
-}
-#endif
-
static guint32
imap_get_message_flags (CamelFolder *folder, const char *uid)
{
@@ -1276,7 +1162,6 @@ imap_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, gui
info->flags = (info->flags & ~flags) | (set & flags) | CAMEL_MESSAGE_FOLDER_FLAGGED;
- /*gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid);*/
camel_object_trigger_event (CAMEL_OBJECT (folder), "message_changed", (gpointer *) uid);
}
@@ -1289,7 +1174,6 @@ imap_get_message_user_flag (CamelFolder *folder, const char *uid, const char *na
static void
imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, gboolean value)
{
- /*gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid);*/
camel_object_trigger_event (CAMEL_OBJECT (folder), "message_changed", (gpointer *) uid);
}
@@ -1314,16 +1198,7 @@ camel_imap_folder_changed (CamelFolder *folder, gint recent, GPtrArray *expunged
g_hash_table_remove (imap_folder->summary_hash, info->uid);
g_ptr_array_remove_index (imap_folder->summary, id - 1);
- /* free the info data */
- g_free (info->subject);
- g_free (info->from);
- g_free (info->to);
- g_free (info->cc);
- g_free (info->uid);
- g_free (info->message_id);
- header_references_list_clear (&info->references);
- g_free (info);
- info = NULL;
+ camel_message_info_free (info);
} else {
/* Hopefully this should never happen */
d(fprintf (stderr, "imap expunge-error: message %d is out of range\n", id));
@@ -1357,15 +1232,7 @@ camel_imap_folder_changed (CamelFolder *folder, gint recent, GPtrArray *expunged
g_hash_table_insert (imap_folder->summary_hash, info->uid, info);
} else {
/* we already have a record of it */
- g_free (info->subject);
- g_free (info->from);
- g_free (info->to);
- g_free (info->cc);
- g_free (info->uid);
- g_free (info->message_id);
- header_references_list_clear (&info->references);
- g_free (info);
- info = NULL;
+ camel_message_info_free (info);
d(fprintf (stderr, "we already had message %d!!\n", i));
}
} else {
@@ -1377,6 +1244,5 @@ camel_imap_folder_changed (CamelFolder *folder, gint recent, GPtrArray *expunged
}
}
- /*gtk_signal_emit_by_name (GTK_OBJECT (folder), "folder_changed", 0);*/
camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", GINT_TO_POINTER (0));
}
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 83d46b4ac7..a55de84dda 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -296,15 +296,9 @@ static gboolean
imap_disconnect (CamelService *service, CamelException *ex)
{
CamelImapStore *store = CAMEL_IMAP_STORE (service);
- char *result;
- int status;
/* send the logout command */
- status = camel_imap_command_extended (store, NULL, &result, ex, "LOGOUT");
- if (status != CAMEL_IMAP_OK) {
- /* Oh fuck it, we're disconnecting anyway... */
- }
- g_free (result);
+ camel_imap_command_extended (store, NULL, NULL, ex, "LOGOUT");
g_free (store->dir_sep);
store->dir_sep = NULL;
@@ -378,12 +372,10 @@ imap_folder_exists (CamelImapStore *store, const char *folder_path, gboolean *se
static gboolean
imap_create (CamelImapStore *store, const char *folder_path, CamelException *ex)
{
- gchar *result;
gint status;
- status = camel_imap_command_extended (store, NULL, &result, ex,
+ status = camel_imap_command_extended (store, NULL, NULL, ex,
"CREATE %s", folder_path);
- g_free (result);
return status == CAMEL_IMAP_OK;
}
@@ -446,15 +438,8 @@ static void
imap_keepalive (CamelRemoteStore *store)
{
CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- char *result;
- int status;
- CamelException ex;
- camel_exception_init (&ex);
- status = camel_imap_command_extended (imap_store, imap_store->current_folder,
- &result, &ex, "NOOP");
- camel_exception_clear (&ex);
- g_free (result);
+ camel_imap_command_extended (imap_store, NULL, NULL, NULL, "NOOP");
}
#if 0
@@ -500,7 +485,7 @@ camel_imap_status (char *cmdid, char *respbuf)
static gint
check_current_folder (CamelImapStore *store, CamelFolder *folder, char *fmt, CamelException *ex)
{
- char *result, *folder_path;
+ char *folder_path;
int status;
/* return OK if we meet one of the following criteria:
@@ -511,14 +496,13 @@ check_current_folder (CamelImapStore *store, CamelFolder *folder, char *fmt, Cam
return CAMEL_IMAP_OK;
folder_path = camel_imap_store_folder_path (store, folder->full_name);
- status = camel_imap_command_extended (store, NULL, &result, ex, "SELECT %s", folder_path);
+ status = camel_imap_command_extended (store, NULL, NULL, ex, "SELECT %s", folder_path);
g_free (folder_path);
- if (!result || status != CAMEL_IMAP_OK) {
+ if (status != CAMEL_IMAP_OK) {
store->current_folder = NULL;
return status;
}
- g_free (result);
/* remember our currently selected folder */
store->current_folder = folder;
@@ -622,7 +606,7 @@ camel_imap_command (CamelImapStore *store, CamelFolder *folder, CamelException *
* a multi-line response.
* @store: the IMAP store
* @folder: The folder to perform the operation in
- * @ret: a pointer to return the full server response in
+ * @ret: a pointer to return the full server response in, or %NULL
* @fmt: a printf-style format string, followed by arguments
*
* This camel method sends the IMAP command specified by @fmt and the
@@ -722,7 +706,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
}
}
- if (status == CAMEL_IMAP_OK) {
+ if (status == CAMEL_IMAP_OK && ret) {
gchar *p;
/* populate the return buffer with the server response */
@@ -742,7 +726,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
}
*p = '\0';
- } else {
+ } else if (status != CAMEL_IMAP_OK) {
/* command failed */
if (respbuf) {
char *word;
@@ -758,7 +742,8 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
"IMAP command failed: Unknown");
}
- *ret = NULL;
+ if (ret)
+ *ret = NULL;
}
/* Update the summary */
@@ -786,7 +771,7 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
* a multi-line response.
* @store: the IMAP store
* @folder: The folder to perform the operation in
- * @ret: a pointer to return the full server response in
+ * @ret: a pointer to return the full server response in, or %NULL
* @fmt: a printf-style format string, followed by arguments
*
* This camel method sends the IMAP FETCH command specified by @fmt and the
@@ -950,7 +935,7 @@ camel_imap_fetch_command (CamelImapStore *store, CamelFolder *folder, char **ret
}
}
- if (status == CAMEL_IMAP_OK) {
+ if (status == CAMEL_IMAP_OK && ret) {
gchar *p;
/* populate the return buffer with the server response */
@@ -970,7 +955,7 @@ camel_imap_fetch_command (CamelImapStore *store, CamelFolder *folder, char **ret
}
*p = '\0';
- } else {
+ } else if (status != CAMEL_IMAP_OK) {
/* command failed */
if (respbuf) {
char *word;
@@ -986,7 +971,8 @@ camel_imap_fetch_command (CamelImapStore *store, CamelFolder *folder, char **ret
"IMAP command failed: Unknown");
}
- *ret = NULL;
+ if (ret)
+ *ret = NULL;
}
/* Update the summary */
@@ -1022,11 +1008,6 @@ camel_imap_fetch_command (CamelImapStore *store, CamelFolder *folder, char **ret
* @store. This function is meant for use with multi-transactional
* IMAP communications like Kerberos authentication and APPEND.
*
- * If the caller passed a non-NULL pointer for @ret,
- * camel_imap_command_preliminary will set it to point to a buffer
- * containing the rest of the response from the IMAP server. The
- * caller function is responsible for freeing @ret.
- *
* Return value: one of CAMEL_IMAP_PLUS, CAMEL_IMAP_NO, CAMEL_IMAP_BAD
* or CAMEL_IMAP_FAIL
*
@@ -1081,14 +1062,14 @@ camel_imap_command_preliminary (CamelImapStore *store, char **cmdid, CamelExcept
* server and possibly get a multi-line response.
* @store: the IMAP store
* @cmdid: The command identifier returned from camel_imap_command_preliminary
- * @ret: a pointer to return the full server response in
+ * @ret: a pointer to return the full server response in, or %NULL
* @cmdbuf: buffer containing the response/request data
*
- * This method is for sending continuing responses to the IMAP server. Meant
- * to be used as a followup to camel_imap_command_preliminary.
- * camel_imap_command_continuation will set @ret to point to a buffer
- * containing the rest of the response from the IMAP server. The
- * caller function is responsible for freeing @ret.
+ * This method is for sending continuing responses to the IMAP server.
+ * Meant to be used as a followup to camel_imap_command_preliminary.
+ * If @ret is non-%NULL camel_imap_command_continuation will set it to
+ * point to a buffer containing the rest of the response from the IMAP
+ * server. The caller function is responsible for freeing @ret.
*
* Return value: one of CAMEL_IMAP_PLUS (command requires additional data),
* CAMEL_IMAP_OK (command executed successfully),
@@ -1135,7 +1116,7 @@ camel_imap_command_continuation (CamelImapStore *store, char **ret, char *cmdid,
}
}
- if (status == CAMEL_IMAP_OK) {
+ if (status == CAMEL_IMAP_OK && ret) {
gchar *p;
/* populate the return buffer with the server response */
@@ -1155,7 +1136,7 @@ camel_imap_command_continuation (CamelImapStore *store, char **ret, char *cmdid,
}
*p = '\0';
- } else {
+ } else if (status != CAMEL_IMAP_OK) {
/* command failed */
if (respbuf) {
char *word;
@@ -1171,7 +1152,8 @@ camel_imap_command_continuation (CamelImapStore *store, char **ret, char *cmdid,
"IMAP command failed: Unknown");
}
- *ret = NULL;
+ if (ret)
+ *ret = NULL;
}
/* cleanup */
@@ -1187,14 +1169,14 @@ camel_imap_command_continuation (CamelImapStore *store, char **ret, char *cmdid,
* server and possibly get a multi-line response.
* @store: the IMAP store
* @cmdid: The command identifier returned from camel_imap_command_preliminary
- * @ret: a pointer to return the full server response in
+ * @ret: a pointer to return the full server response in, or %NULL
* @cstream: a CamelStream containing a continuation response.
*
- * This method is for sending continuing responses to the IMAP server. Meant
- * to be used as a followup to camel_imap_command_preliminary.
- * camel_imap_command_continuation will set @ret to point to a buffer
- * containing the rest of the response from the IMAP server. The
- * caller function is responsible for freeing @ret.
+ * This method is for sending continuing responses to the IMAP server.
+ * Meant to be used as a followup to camel_imap_command_preliminary.
+ * If @ret is not %NULL, camel_imap_command_continuation will set it
+ * to point to a buffer containing the rest of the response from the
+ * IMAP server. The caller function is responsible for freeing @ret.
*
* Return value: one of CAMEL_IMAP_PLUS (command requires additional data),
* CAMEL_IMAP_OK (command executed successfully),
@@ -1243,7 +1225,7 @@ camel_imap_command_continuation_with_stream (CamelImapStore *store, char **ret,
}
}
- if (status == CAMEL_IMAP_OK) {
+ if (status == CAMEL_IMAP_OK && ret) {
gchar *p;
/* populate the return buffer with the server response */
@@ -1263,7 +1245,7 @@ camel_imap_command_continuation_with_stream (CamelImapStore *store, char **ret,
}
*p = '\0';
- } else {
+ } else if (status != CAMEL_IMAP_OK) {
/* command failed */
if (respbuf) {
char *word;
@@ -1279,7 +1261,8 @@ camel_imap_command_continuation_with_stream (CamelImapStore *store, char **ret,
"IMAP command failed: Unknown error");
}
- *ret = NULL;
+ if (ret)
+ *ret = NULL;
}
/* cleanup */
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
index c32975188e..8fdc4fb5b4 100644
--- a/camel/providers/imap/camel-imap-utils.c
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -28,6 +28,7 @@
#include "camel-imap-utils.h"
#include "string-utils.h"
#include <e-sexp.h>
+#include "camel/camel-folder-summary.h"
#define d(x) x
@@ -496,3 +497,62 @@ imap_translate_sexp (const char *expression)
return retval;
}
+
+char *
+imap_create_flag_list (guint32 flags)
+{
+ GString *gstr;
+ char *flag_list;
+
+ gstr = g_string_new ("(");
+
+ if (flags & CAMEL_MESSAGE_ANSWERED)
+ g_string_append (gstr, "\\Answered ");
+ if (flags & CAMEL_MESSAGE_DELETED)
+ g_string_append (gstr, "\\Deleted ");
+ if (flags & CAMEL_MESSAGE_DRAFT)
+ g_string_append (gstr, "\\Draft ");
+ if (flags & CAMEL_MESSAGE_FLAGGED)
+ g_string_append (gstr, "\\Flagged ");
+ if (flags & CAMEL_MESSAGE_SEEN)
+ g_string_append (gstr, "\\Seen ");
+
+ if (gstr->str[gstr->len - 1] == ' ')
+ gstr->str[gstr->len - 1] = ')';
+ else
+ g_string_append_c (gstr, ')');
+
+ flag_list = gstr->str;
+ g_string_free (gstr, FALSE);
+ return flag_list;
+}
+
+guint32
+imap_parse_flag_list (const char *flag_list)
+{
+ guint32 flags = 0;
+ int len;
+
+ if (*flag_list++ != '(')
+ return 0;
+
+ while (*flag_list != ')') {
+ len = strcspn (flag_list, " )");
+ if (!g_strncasecmp (flag_list, "\\Answered", len))
+ flags |= CAMEL_MESSAGE_ANSWERED;
+ else if (!g_strncasecmp (flag_list, "\\Deleted", len))
+ flags |= CAMEL_MESSAGE_DELETED;
+ else if (!g_strncasecmp (flag_list, "\\Draft", len))
+ flags |= CAMEL_MESSAGE_DRAFT;
+ else if (!g_strncasecmp (flag_list, "\\Flagged", len))
+ flags |= CAMEL_MESSAGE_FLAGGED;
+ else if (!g_strncasecmp (flag_list, "\\Seen", len))
+ flags |= CAMEL_MESSAGE_SEEN;
+
+ flag_list += len;
+ if (*flag_list == ' ')
+ flag_list++;
+ }
+
+ return flags;
+}
diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h
index 11c6c48956..6f450fc8e8 100644
--- a/camel/providers/imap/camel-imap-utils.h
+++ b/camel/providers/imap/camel-imap-utils.h
@@ -36,6 +36,9 @@ gboolean imap_parse_list_response (char *buf, char *namespace, char **flags, cha
char *imap_translate_sexp (const char *expression);
+char *imap_create_flag_list (guint32 flags);
+guint32 imap_parse_flag_list (const char *flag_list);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */