From d082be408a72cd7fae09c6c8ba9a823a53b1edbd Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 28 Aug 2000 23:47:21 +0000 Subject: Fixed the hack around quoted string responses - should now handle them 2000-08-28 Jeffrey Stedfast * providers/imap/camel-imap-folder.c (imap_get_message): Fixed the hack around quoted string responses - should now handle them according to the specifications in the RFC * providers/imap/camel-imap-stream.c (stream_read): Updated to match the code currently used in camel-imap-folder.c svn path=/trunk/; revision=5092 --- camel/providers/imap/camel-imap-stream.c | 78 +++++++++++++++++++------------- 1 file changed, 46 insertions(+), 32 deletions(-) (limited to 'camel/providers/imap/camel-imap-stream.c') diff --git a/camel/providers/imap/camel-imap-stream.c b/camel/providers/imap/camel-imap-stream.c index 7b885437a2..fcddd4c0b5 100644 --- a/camel/providers/imap/camel-imap-stream.c +++ b/camel/providers/imap/camel-imap-stream.c @@ -43,9 +43,9 @@ camel_imap_stream_class_init (CamelImapStreamClass *camel_imap_stream_class) { CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_imap_stream_class); - + parent_class = CAMEL_STREAM_CLASS(camel_type_get_global_classfuncs (camel_stream_get_type ())); - + /* virtual method overload */ camel_stream_class->read = stream_read; camel_stream_class->reset = stream_reset; @@ -56,7 +56,7 @@ static void camel_imap_stream_init (gpointer object, gpointer klass) { CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (object); - + imap_stream->cache = NULL; imap_stream->cache_ptr = NULL; } @@ -65,7 +65,7 @@ CamelType camel_imap_stream_get_type (void) { static CamelType camel_imap_stream_type = CAMEL_INVALID_TYPE; - + if (camel_imap_stream_type == CAMEL_INVALID_TYPE) { camel_imap_stream_type = camel_type_register (camel_stream_get_type (), "CamelImapStream", sizeof (CamelImapStream), @@ -75,7 +75,7 @@ camel_imap_stream_get_type (void) (CamelObjectInitFunc) camel_imap_stream_init, (CamelObjectFinalizeFunc) finalize); } - + return camel_imap_stream_type; } @@ -83,9 +83,9 @@ CamelStream * camel_imap_stream_new (CamelImapFolder *folder, char *command) { CamelImapStream *imap_stream; - + imap_stream = CAMEL_IMAP_STREAM(camel_object_new (camel_imap_stream_get_type ())); - + imap_stream->folder = folder; camel_object_ref (CAMEL_OBJECT (imap_stream->folder)); @@ -98,10 +98,10 @@ static void finalize (CamelObject *object) { CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (object); - + g_free (imap_stream->cache); g_free (imap_stream->command); - + if (imap_stream->folder) camel_object_unref (CAMEL_OBJECT (imap_stream->folder)); } @@ -113,7 +113,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n) /* do we want to do any IMAP specific parsing in here? If not, maybe rename to camel-stream-cache? */ CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); - + if (!imap_stream->cache) { /* We need to send the IMAP command since this is our first fetch */ CamelFolder *folder = CAMEL_FOLDER (imap_stream->folder); @@ -136,30 +136,44 @@ stream_read (CamelStream *stream, char *buffer, size_t n) /* we don't need the folder anymore... */ camel_object_unref (CAMEL_OBJECT (imap_stream->folder)); - - /* parse out the message part */ - for (p = result; *p && *p != '{' && *p != '\n'; p++); - if (*p != '{') { - g_free (result); - return -1; - } - part_len = atoi (p + 1); - for ( ; *p && *p != '\n'; p++); - if (*p != '\n') { + /* parse out the message part */ + for (p = result; *p && *p != '{' && *p != '"' && *p != '\n'; p++); + switch (*p) { + case '"': + /* a quoted string - section 4.3 */ + p++; + for (q = p; *q && *q != '"' && *q != '\n'; q++); + part_len = (gint) (q - p); + + break; + case '{': + /* a literal string - section 4.3 */ + part_len = atoi (p + 1); + for ( ; *p && *p != '\n'; p++); + if (*p != '\n') { + g_free (result); + return -1; + } + + /* calculate the new part-length */ + for (q = p; *q && (q - p) <= part_len; q++) { + if (*q == '\n') + part_len--; + } + + /* FIXME: This is a hack for IMAP daemons that send us a UID at the end of each FETCH */ + for ( ; q > p && *(q-1) != '\n'; q--, part_len--); + part_len++; + + break; + default: + /* Bad input */ g_free (result); return -1; } - /* calculate the new part-length */ - for (q = p; *q && (q - p) <= part_len; q++) { - if (*q == '\n') - part_len--; - } - /* FIXME: This is a hack for IMAP daemons that send us a UID at the end of each FETCH */ - for (q--, part_len--; q > p && *(q-1) != '\n'; q--, part_len--); - - imap_stream->cache = g_strndup (p, part_len + 1); + imap_stream->cache = g_strndup (p, part_len); g_free (result); imap_stream->cache_ptr = imap_stream->cache; @@ -174,7 +188,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n) } else { nread = -1; } - + return nread; } @@ -184,7 +198,7 @@ stream_reset (CamelStream *stream) CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); imap_stream->cache_ptr = imap_stream->cache; - + return 1; } @@ -192,6 +206,6 @@ static gboolean stream_eos (CamelStream *stream) { CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); - + return (imap_stream->cache_ptr && strlen (imap_stream->cache_ptr)); } -- cgit v1.2.3