diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-07-28 07:11:11 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-07-28 07:11:11 +0800 |
commit | 2c5a9bc2278c0922807316a0a63d84cd0333f545 (patch) | |
tree | e5a46c5e39fb278a3cb2b49eb00fc0f55e8ad8ce /camel/providers/imap/camel-imap-utils.c | |
parent | 1bf9e439824ee6a2aa721aa05859200da89cbc9b (diff) | |
download | gsoc2013-evolution-2c5a9bc2278c0922807316a0a63d84cd0333f545.tar.gz gsoc2013-evolution-2c5a9bc2278c0922807316a0a63d84cd0333f545.tar.zst gsoc2013-evolution-2c5a9bc2278c0922807316a0a63d84cd0333f545.zip |
Added camel-imap-utils.[c,h]
2000-07-27 Jeffrey Stedfast <fejj@helixcode.com>
* providers/imap/Makefile.am: Added camel-imap-utils.[c,h]
* providers/imap/camel-imap-utils.[c,h]: Utilities for parsing
server responses for use in both camel-imap-store.c and
camel-imap-folder.c
* providers/imap/camel-imap-folder.c (imap_get_summary_internal):
Free all the pointers in the headers array.
(imap_get_subfolder_names_internal): Updated to use
imap_parse_list_response
(imap_parse_subfolder_list): Removed in favor of
imap_parse_list_response
* providers/imap/camel-imap-store.c (camel_imap_command_extended):
Free all the pointers in the data array.
(imap_connect): Updated to use imap_parse_list_response and fixed
a leak
(folder_is_selectable): Updated.
svn path=/trunk/; revision=4400
Diffstat (limited to 'camel/providers/imap/camel-imap-utils.c')
-rw-r--r-- | camel/providers/imap/camel-imap-utils.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c new file mode 100644 index 0000000000..6560481505 --- /dev/null +++ b/camel/providers/imap/camel-imap-utils.c @@ -0,0 +1,97 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@helixcode.com> + * + * Copyright 2000 Helix Code, Inc. (www.helixcode.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include <stdio.h> +#include <string.h> + +#include "camel-imap-utils.h" +#include "string-utils.h" + +#define d(x) x + +char * +imap_next_word (char *buf) +{ + char *word; + + /* skip over current word */ + for (word = buf; *word && *word != ' '; word++); + + /* skip over white space */ + for ( ; *word && *word == ' '; word++); + + return word; +} + +gboolean +imap_parse_list_response (char *buf, char *namespace, char **flags, char **sep, char **folder) +{ + char *word, *ep, *f; + + *flags = NULL; + *sep = NULL; + *folder = NULL; + + if (*buf != '*') + return FALSE; + + word = imap_next_word (buf); + if (g_strncasecmp (word, "LIST", 4) && g_strncasecmp (word, "LSUB", 4)) + return FALSE; + + /* get the flags */ + word = imap_next_word (word); + if (*word != '(') + return FALSE; + + word++; + for (ep = word; *ep && *ep != ')'; ep++); + if (*ep != ')') + return FALSE; + + *flags = g_strndup (word, (gint)(ep - word)); + + /* get the directory separator */ + word = imap_next_word (ep); + if (*word) { + for (ep = word; *ep && *ep != ' '; ep++); + *sep = g_strndup (word, (gint)(ep - word)); + string_unquote (*sep); + } else { + return FALSE; + } + + /* get the folder name */ + word = imap_next_word (word); + *folder = g_strdup (word); + g_strstrip (*folder); + + /* chop out the folder prefix */ + if (*namespace && !strncmp (*folder, namespace, strlen (namespace))) { + f = *folder + strlen (namespace) + strlen (*sep); + memmove (*folder, f, strlen (f) + 1); + } + + string_unquote (*folder); /* unquote the mailbox if it's quoted */ + + return TRUE; +} |