From cf8db42ff883c5452998b0d8f57c2394abec42db Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 21 Jan 2002 23:28:20 +0000 Subject: As a temporary solution, just printf ("\a"); to make a beep :-) 2002-01-21 Jeffrey Stedfast * camel-filter-driver.c (do_beep): As a temporary solution, just printf ("\a"); to make a beep :-) * providers/imap/camel-imap-command.c (imap_command_strdup_vprintf): Encode the mailbox to UTF-7 here. * providers/imap/camel-imap-utils.c (imap_parse_list_response): Decode the mailbox name as we parse the list response. (imap_mailbox_decode): It's only an illegal mailbox name if it didn't switch back to US-ASCII mode. svn path=/trunk/; revision=15421 --- camel/providers/imap/camel-imap-command.c | 14 ++++-- camel/providers/imap/camel-imap-store.c | 3 +- camel/providers/imap/camel-imap-utils.c | 79 ++++++++++++++++++------------- camel/providers/imap/camel-imap-utils.h | 10 ++-- 4 files changed, 65 insertions(+), 41 deletions(-) (limited to 'camel/providers/imap') diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c index 3afb9af82f..6a2382b3c8 100644 --- a/camel/providers/imap/camel-imap-command.c +++ b/camel/providers/imap/camel-imap-command.c @@ -588,12 +588,14 @@ camel_imap_response_extract (CamelImapStore *store, int len = strlen (type), i; char *resp; + len = strlen (type); + for (i = 0; i < response->untagged->len; i++) { resp = response->untagged->pdata[i]; /* Skip "* ", and initial sequence number, if present */ strtoul (resp + 2, &resp, 10); if (*resp == ' ') - resp = imap_next_word (resp); + resp = (char *) imap_next_word (resp); if (!g_strncasecmp (resp, type, len)) break; @@ -741,8 +743,14 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, case 'S': case 'F': string = args->pdata[i++]; - if (*p == 'F') - string = imap_namespace_concat (store, string); + if (*p == 'F') { + char *mailbox; + + mailbox = imap_namespace_concat (store, string); + string = imap_mailbox_encode (mailbox, strlen (mailbox)); + g_free (mailbox); + } + if (store->capabilities & IMAP_CAPABILITY_LITERALPLUS) { op += sprintf (op, "{%d+}\r\n%s", strlen (string), string); diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c index cee990ee6b..a1a8daa3c1 100644 --- a/camel/providers/imap/camel-imap-store.c +++ b/camel/providers/imap/camel-imap-store.c @@ -624,9 +624,10 @@ imap_connect_online (CamelService *service, CamelException *ex) CamelImapStore *store = CAMEL_IMAP_STORE (service); CamelDiscoStore *disco_store = CAMEL_DISCO_STORE (service); CamelImapResponse *response; - int i, flags, len; char *result, *name, *path; FILE *storeinfo; + int i, flags; + size_t len; CAMEL_IMAP_STORE_LOCK (store, command_lock); if (!connect_to_server (service, ex) || diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c index 746aec2167..91d2efb702 100644 --- a/camel/providers/imap/camel-imap-utils.c +++ b/camel/providers/imap/camel-imap-utils.c @@ -33,13 +33,13 @@ #define d(x) x -char * +const char * imap_next_word (const char *buf) { - char *word; + const char *word; /* skip over current word */ - for (word = (char *)buf; *word && *word != ' '; word++); + for (word = buf; *word && *word != ' '; word++); /* skip over white space */ for ( ; *word && *word == ' '; word++); @@ -63,8 +63,8 @@ imap_next_word (const char *buf) gboolean imap_parse_list_response (CamelImapStore *store, const char *buf, int *flags, char *sep, char **folder) { - char *word; - int len; + const char *word; + size_t len; if (*buf != '*') return FALSE; @@ -117,22 +117,34 @@ imap_parse_list_response (CamelImapStore *store, const char *buf, int *flags, ch return FALSE; if (folder) { - char *real_name; - int n_len; + char *astring, *mailbox; + size_t nlen; /* get the folder name */ word = imap_next_word (word); - real_name = imap_parse_astring (&word, &len); - n_len = strlen (store->namespace); - if (!strncmp (real_name, store->namespace, n_len)) - *folder = g_strdup (real_name + n_len); - else if (!g_strcasecmp (real_name, "INBOX")) { - *folder = g_strdup (real_name); + astring = imap_parse_astring ((char **) &word, &len); + if (!astring) + return FALSE; + + mailbox = imap_mailbox_decode (astring, strlen (astring)); + g_free (astring); + if (!mailbox) + return FALSE; + + nlen = strlen (store->namespace); + + if (!strncmp (mailbox, store->namespace, nlen)) { + /* strip off the namespace */ + if (nlen > 0) + memmove (mailbox, mailbox + nlen, (len - nlen) + 1); + *folder = mailbox; + } else if (!g_strcasecmp (mailbox, "INBOX")) { + *folder = mailbox; } else { - g_warning ("IMAP folder name \"%s\" does not begin with \"%s\"", real_name, store->namespace); - *folder = g_strdup (real_name); + g_warning ("IMAP folder name \"%s\" does not begin with \"%s\"", mailbox, store->namespace); + *folder = mailbox; } - g_free (real_name); + return *folder != NULL; } @@ -174,10 +186,8 @@ imap_parse_folder_name (CamelImapStore *store, const char *folder_name) continue; } - if (*p == store->dir_sep) { - /* FIXME: decode mailbox */ + if (*p == store->dir_sep) g_ptr_array_add (heirarchy, g_strndup (folder_name, p - folder_name)); - } p++; } @@ -276,7 +286,7 @@ static char imap_atom_specials[128] = { /** * imap_parse_string_generic: * @str_p: a pointer to a string - * @len: a pointer to an int to return the length in + * @len: a pointer to a size_t to return the length in * @type: type of string (#IMAP_STRING, #IMAP_ASTRING, or #IMAP_NSTRING) * to parse. * @@ -295,7 +305,7 @@ static char imap_atom_specials[128] = { * latter, it will point to the character after the NIL.) **/ char * -imap_parse_string_generic (char **str_p, int *len, int type) +imap_parse_string_generic (char **str_p, size_t *len, int type) { char *str = *str_p; char *out; @@ -304,7 +314,7 @@ imap_parse_string_generic (char **str_p, int *len, int type) return NULL; else if (*str == '"') { char *p; - int size; + size_t size; str++; size = strcspn (str, "\"") + 1; @@ -476,7 +486,7 @@ imap_parse_body (char **body_p, CamelFolder *folder, char *body = *body_p; CamelMessageContentInfo *child; CamelContentType *type; - int len; + size_t len; if (!body || *body++ != '(') { *body_p = NULL; @@ -533,7 +543,7 @@ imap_parse_body (char **body_p, CamelFolder *folder, /* single part */ char *main_type, *subtype; char *id, *description, *encoding; - guint32 size; + guint32 size = 0; main_type = imap_parse_string (&body, &len); skip_char (&body, ' '); @@ -815,7 +825,7 @@ imap_uid_array_free (GPtrArray *arr) char * imap_concat (CamelImapStore *imap_store, const char *prefix, const char *suffix) { - int len; + size_t len; len = strlen (prefix); if (len == 0 || prefix[len - 1] == imap_store->dir_sep) @@ -833,7 +843,7 @@ imap_namespace_concat (CamelImapStore *store, const char *name) else return g_strdup (""); } - + if (!g_strcasecmp (name, "INBOX")) return g_strdup ("INBOX"); @@ -841,7 +851,7 @@ imap_namespace_concat (CamelImapStore *store, const char *name) g_warning ("Trying to concat NULL namespace to \"%s\"!", name); return g_strdup (name); } - + return imap_concat (store, store->namespace, name); } @@ -859,7 +869,7 @@ enum { #define encode_mode(c) (is_usascii (c) ? MODE_USASCII : (c) == '&' ? MODE_AMPERSAND : MODE_MODUTF7) char * -imap_mailbox_encode (const unsigned char *in, int inlen) +imap_mailbox_encode (const unsigned char *in, size_t inlen) { const unsigned char *start, *inptr, *inend; unsigned char *mailbox, *m, *mend; @@ -981,7 +991,7 @@ imap_mailbox_encode (const unsigned char *in, int inlen) char * -imap_mailbox_decode (const unsigned char *in, int inlen) +imap_mailbox_decode (const unsigned char *in, size_t inlen) { const unsigned char *start, *inptr, *inend; unsigned char *mailbox, *m, *mend; @@ -1033,7 +1043,7 @@ imap_mailbox_decode (const unsigned char *in, int inlen) conv = iconv (cd, &inbuf, &buflen, &outbuf, &outleft); if (conv == (size_t) -1) { - g_warning ("error decoding mailbox from UTF-7!"); + g_warning ("error decoding mailbox: %.*s", inlen, in); } iconv (cd, NULL, NULL, NULL, NULL); @@ -1082,7 +1092,7 @@ imap_mailbox_decode (const unsigned char *in, int inlen) conv = iconv (cd, &inbuf, &buflen, &outbuf, &outleft); if (conv == (size_t) -1) { - g_warning ("error decoding mailbox from UTF-7!"); + g_warning ("error decoding mailbox: %.*s", inlen, in); } iconv (cd, NULL, NULL, NULL, NULL); @@ -1090,8 +1100,11 @@ imap_mailbox_decode (const unsigned char *in, int inlen) } } } else { - /* illegal encoded mailbox... */ - g_warning ("illegal mailbox name encountered!"); + if (mode_switch == '-') { + /* illegal encoded mailbox... */ + g_warning ("illegal mailbox name encountered: %.*s", inlen, in); + } + memcpy (m, start, inptr - start); m += (inptr - start); } diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h index bedc604116..924b71c119 100644 --- a/camel/providers/imap/camel-imap-utils.h +++ b/camel/providers/imap/camel-imap-utils.h @@ -28,10 +28,12 @@ extern "C" { #pragma } #endif /* __cplusplus }*/ +#include + #include "camel-folder-summary.h" #include "camel-imap-types.h" -char *imap_next_word (const char *buf); +const char *imap_next_word (const char *buf); #define IMAP_LIST_FLAG_NOINFERIORS (1 << 0) #define IMAP_LIST_FLAG_NOSELECT (1 << 1) @@ -49,7 +51,7 @@ guint32 imap_parse_flag_list (char **flag_list); enum { IMAP_STRING, IMAP_NSTRING, IMAP_ASTRING }; -char *imap_parse_string_generic (char **str_p, int *len, int type); +char *imap_parse_string_generic (char **str_p, size_t *len, int type); #define imap_parse_string(str_p, len_p) \ imap_parse_string_generic (str_p, len_p, IMAP_STRING) @@ -72,8 +74,8 @@ void imap_uid_array_free (GPtrArray *arr); char *imap_concat (CamelImapStore *imap_store, const char *prefix, const char *suffix); char *imap_namespace_concat (CamelImapStore *store, const char *name); -char *imap_mailbox_encode (const unsigned char *in, int inlen); -char *imap_mailbox_decode (const unsigned char *in, int inlen); +char *imap_mailbox_encode (const unsigned char *in, size_t inlen); +char *imap_mailbox_decode (const unsigned char *in, size_t inlen); #ifdef __cplusplus } -- cgit v1.2.3