From 2c5a9bc2278c0922807316a0a63d84cd0333f545 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 27 Jul 2000 23:11:11 +0000 Subject: Added camel-imap-utils.[c,h] 2000-07-27 Jeffrey Stedfast * 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 --- camel/providers/imap/camel-imap-utils.c | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 camel/providers/imap/camel-imap-utils.c (limited to 'camel/providers/imap/camel-imap-utils.c') 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 + * + * 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 +#include + +#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; +} -- cgit v1.2.3