aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-utils.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-01-03 06:07:44 +0800
committerDan Winship <danw@src.gnome.org>2001-01-03 06:07:44 +0800
commitb1a4da002f0414ceb1c8f579edba47c600762a9c (patch)
tree5e6d7f9807ab82ecfe4c74a789ba05ccda3d2063 /camel/providers/imap/camel-imap-utils.c
parenta8b13bc0443aa150a3c007ea5e6bc48cc8ebbc51 (diff)
downloadgsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar.gz
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar.bz2
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar.lz
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar.xz
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.tar.zst
gsoc2013-evolution-b1a4da002f0414ceb1c8f579edba47c600762a9c.zip
IMAP randomness.
* providers/imap/camel-imap-stream.[ch]: Remove. To be replaced. * providers/imap/Makefile.am (libcamelimapinclude_HEADERS): Remove camel-imap-stream.h * providers/imap/camel-imap-utils.c (imap_parse_flag_list): Take a char ** instead of char *, to return the position at the end of parsing like the string parsing functions. (imap_parse_string_generic): New function to parse a string, nstring, or astring. (imap_parse_nstring, imap_parse_astring): Now macros (imap_parse_string): Added * providers/imap/camel-imap-folder.h: Remove the "exists" field from CamelImapFolder. * providers/imap/camel-imap-folder.c: Remove unused include of camel-imap-stream.h. (camel_imap_folder_init): Remove no-longer-relevant summary initialization. (camel_imap_folder_new): Update for imap_parse_flag_list change, exists removal, and imap_rescan. (imap_rescan): New function that does most of the work of the old imap_refresh_info, but taking "exists" as an argument instead of getting it from the folder. Also calls camel_imap_folder_changed to do the summary updating and signalling, rather than duplicating that code. (imap_refresh_info): Just call imap_rescan (using the size of the folder summary as "exists"). (imap_update_summary): Update for imap_parse_flag_list change (camel_imap_folder_changed): Update for "exists" change. svn path=/trunk/; revision=7216
Diffstat (limited to 'camel/providers/imap/camel-imap-utils.c')
-rw-r--r--camel/providers/imap/camel-imap-utils.c93
1 files changed, 44 insertions, 49 deletions
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
index 3e3f4af031..1b4aaba499 100644
--- a/camel/providers/imap/camel-imap-utils.c
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -155,15 +155,18 @@ imap_create_flag_list (guint32 flags)
}
guint32
-imap_parse_flag_list (const char *flag_list)
+imap_parse_flag_list (char **flag_list_p)
{
+ char *flag_list = *flag_list_p;
guint32 flags = 0;
int len;
- if (*flag_list++ != '(')
+ if (*flag_list++ != '(') {
+ *flag_list_p = NULL;
return 0;
+ }
- while (*flag_list != ')') {
+ while (*flag_list && *flag_list != ')') {
len = strcspn (flag_list, " )");
if (!g_strncasecmp (flag_list, "\\Answered", len))
flags |= CAMEL_MESSAGE_ANSWERED;
@@ -180,20 +183,40 @@ imap_parse_flag_list (const char *flag_list)
if (*flag_list == ' ')
flag_list++;
}
-
+
+ if (*flag_list++ != ')') {
+ *flag_list_p = NULL;
+ return 0;
+ }
+
+ *flag_list_p = flag_list;
return flags;
}
+static char imap_atom_specials[128] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
+};
+#define imap_is_atom_char(ch) (isascii (ch) && !imap_atom_specials[ch])
+
/**
- * imap_parse_nstring:
+ * imap_parse_string_generic:
* @str_p: a pointer to a string
* @len: a pointer to an int to return the length in
+ * @type: type of string (#IMAP_STRING, #IMAP_ASTRING, or #IMAP_NSTRING)
+ * to parse.
*
- * This parses an "nstring" (NIL, a quoted string, or a literal)
- * starting at *@str_p. On success, *@str_p will point to the first
- * character after the end of the nstring, and *@len will contain
- * the length of the returned string. On failure, *@str_p will be
- * set to %NULL.
+ * This parses an IMAP "string" (quoted string or literal), "nstring"
+ * (NIL or string), or "astring" (atom or string) starting at *@str_p.
+ * On success, *@str_p will point to the first character after the end
+ * of the string, and *@len will contain the length of the returned
+ * string. On failure, *@str_p will be set to %NULL.
*
* This assumes that the string is in the form returned by
* camel_imap_command(): that line breaks are indicated by LF rather
@@ -204,7 +227,7 @@ imap_parse_flag_list (const char *flag_list)
* latter, it will point to the character after the NIL.)
**/
char *
-imap_parse_nstring (char **str_p, int *len)
+imap_parse_string_generic (char **str_p, int *len, int type)
{
char *str = *str_p;
char *out;
@@ -248,10 +271,19 @@ imap_parse_nstring (char **str_p, int *len)
out = g_strndup (str, *len);
*str_p = str + *len;
return out;
- } else if (!g_strncasecmp (str, "nil", 3)) {
+ } else if (type == IMAP_NSTRING && !g_strncasecmp (str, "nil", 3)) {
*str_p += 3;
*len = 0;
return NULL;
+ } else if (type == IMAP_ASTRING &&
+ imap_is_atom_char ((unsigned char)*str)) {
+ while (imap_is_atom_char ((unsigned char)*str))
+ str++;
+
+ *len = str - *str_p;
+ str = g_strndup (*str_p, *len);
+ *str_p += *len;
+ return str;
} else {
*str_p = NULL;
return NULL;
@@ -259,43 +291,6 @@ imap_parse_nstring (char **str_p, int *len)
}
/**
- * imap_parse_astring:
- * @str_p: a pointer to a string
- * @len: a pointer to an int to return the length in
- *
- * This parses an "astring" (an atom, a quoted string, or a literal)
- * starting at *@str_p. On success, *@str_p will point to the first
- * character after the end of the astring, and *@len will contain
- * the length of the returned string. On failure, *@str_p will be
- * set to %NULL.
- *
- * This assumes that the string is in the form returned by
- * camel_imap_command(): that line breaks are indicated by LF rather
- * than CRLF.
- *
- * Return value: the parsed string, or %NULL if no string
- * was parsed. (In this case, *@str_p will also be %NULL.)
- **/
-char *
-imap_parse_astring (char **str_p, int *len)
-{
- char *p;
-
- if (**str_p == '{' || **str_p == '"')
- return imap_parse_nstring (str_p, len);
-
- p = *str_p;
- while (isascii ((unsigned char)*p) &&
- !strchr ("(){ \"\\%*", *p))
- p++;
-
- *len = p - *str_p;
- p = g_strndup (*str_p, *len);
- *str_p += *len;
- return p;
-}
-
-/**
* imap_quote_string:
* @str: the string to quote, which must not contain CR or LF
*