From a1dbf7e2b8b79455eedec53cc9f2221e97215a9f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 9 Aug 2001 22:48:12 +0000 Subject: A quoted string cannot contain \n's so check for those as well. 2001-08-09 Jeffrey Stedfast * providers/imap/camel-imap-utils.c (imap_parse_string_generic): A quoted string cannot contain \n's so check for those as well. (imap_atom_specials): Update this to fix bug #6553. svn path=/trunk/; revision=11845 --- camel/providers/imap/camel-imap-command.c | 128 +++++++++++++++--------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'camel/providers/imap/camel-imap-command.c') diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c index 4c84b47fbb..b5b80624ef 100644 --- a/camel/providers/imap/camel-imap-command.c +++ b/camel/providers/imap/camel-imap-command.c @@ -84,9 +84,9 @@ camel_imap_command (CamelImapStore *store, CamelFolder *folder, { va_list ap; char *cmd; - + CAMEL_IMAP_STORE_LOCK (store, command_lock); - + if (fmt) { va_start (ap, fmt); cmd = imap_command_strdup_vprintf (store, fmt, ap); @@ -101,14 +101,14 @@ camel_imap_command (CamelImapStore *store, CamelFolder *folder, cmd = imap_command_strdup_printf (store, "SELECT %F", folder->full_name); } - + if (!imap_command_start (store, folder, cmd, ex)) { g_free (cmd); CAMEL_IMAP_STORE_UNLOCK (store, command_lock); return NULL; } g_free (cmd); - + return imap_read_response (store, ex); } @@ -152,15 +152,15 @@ camel_imap_command_start (CamelImapStore *store, CamelFolder *folder, va_list ap; char *cmd; gboolean ok; - + va_start (ap, fmt); cmd = imap_command_strdup_vprintf (store, fmt, ap); va_end (ap); - + CAMEL_IMAP_STORE_LOCK (store, command_lock); ok = imap_command_start (store, folder, cmd, ex); g_free (cmd); - + if (!ok) CAMEL_IMAP_STORE_UNLOCK (store, command_lock); return ok; @@ -174,7 +174,7 @@ imap_command_start (CamelImapStore *store, CamelFolder *folder, if (folder && folder != store->current_folder) { CamelImapResponse *response; CamelException internal_ex; - + response = camel_imap_command (store, folder, ex, NULL); if (!response) return NULL; @@ -186,7 +186,7 @@ imap_command_start (CamelImapStore *store, CamelFolder *folder, return FALSE; } } - + /* Send the command */ return camel_remote_store_send_string (CAMEL_REMOTE_STORE (store), ex, "%c%.5d %s\r\n", @@ -218,7 +218,7 @@ camel_imap_command_continuation (CamelImapStore *store, const char *cmd, CAMEL_IMAP_STORE_UNLOCK (store, command_lock); return NULL; } - + return imap_read_response (store, ex); } @@ -243,17 +243,17 @@ camel_imap_command_response (CamelImapStore *store, char **response, { CamelImapResponseType type; char *respbuf; - + if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store), &respbuf, ex) < 0) { CAMEL_IMAP_STORE_UNLOCK (store, command_lock); return CAMEL_IMAP_RESPONSE_ERROR; } - + switch (*respbuf) { case '*': type = CAMEL_IMAP_RESPONSE_UNTAGGED; - + /* Read the rest of the response if it is multi-line. */ respbuf = imap_read_untagged (store, respbuf, ex); if (!respbuf) @@ -273,7 +273,7 @@ camel_imap_command_response (CamelImapStore *store, char **response, break; } *response = respbuf; - + if (type == CAMEL_IMAP_RESPONSE_ERROR || type == CAMEL_IMAP_RESPONSE_TAGGED) CAMEL_IMAP_STORE_UNLOCK (store, command_lock); @@ -286,39 +286,39 @@ imap_read_response (CamelImapStore *store, CamelException *ex) CamelImapResponse *response; CamelImapResponseType type; char *respbuf, *p; - + /* Get another lock so that when we reach the tagged * response and camel_imap_command_response unlocks, * we're still locked. This lock is owned by response * and gets unlocked when response is freed. */ CAMEL_IMAP_STORE_LOCK (store, command_lock); - + response = g_new0 (CamelImapResponse, 1); if (store->current_folder && camel_disco_store_status (CAMEL_DISCO_STORE (store)) != CAMEL_DISCO_STORE_RESYNCING) { response->folder = store->current_folder; camel_object_ref (CAMEL_OBJECT (response->folder)); } - + response->untagged = g_ptr_array_new (); while ((type = camel_imap_command_response (store, &respbuf, ex)) == CAMEL_IMAP_RESPONSE_UNTAGGED) g_ptr_array_add (response->untagged, respbuf); - + if (type == CAMEL_IMAP_RESPONSE_ERROR) { camel_imap_response_free_without_processing (store, response); return NULL; } - + response->status = respbuf; - + /* Check for OK or continuation response. */ if (*respbuf == '+') return response; p = strchr (respbuf, ' '); if (p && !g_strncasecmp (p, " OK", 3)) return response; - + /* We should never get BAD, or anything else but +, OK, or NO * for that matter. */ @@ -331,7 +331,7 @@ imap_read_response (CamelImapStore *store, CamelException *ex) camel_imap_response_free_without_processing (store, response); return NULL; } - + p += 3; if (!*p++) p = NULL; @@ -353,29 +353,29 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) GPtrArray *data; GString *str; char *end, *p, *s, *d; - + p = strrchr (line, '{'); if (!p) return line; - + data = g_ptr_array_new (); fulllen = 0; - + while (1) { str = g_string_new (line); g_free (line); fulllen += str->len; g_ptr_array_add (data, str); - + p = strrchr (str->str, '{'); if (!p) break; - + length = strtoul (p + 1, &end, 10); if (*end != '}' || *(end + 1) || end == p + 1) break; ldigits = end - (p + 1); - + /* Read the literal */ str = g_string_sized_new (length + 2); str->str[0] = '\n'; @@ -397,7 +397,7 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) goto lose; } str->str[length + 1] = '\0'; - + /* Fix up the literal, turning CRLFs into LF. Also, if * we find any embedded NULs, strip them. This is * dubious, but: @@ -411,7 +411,7 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) * inserts a NUL into the last line when it * shouldn't. */ - + s = d = str->str + 1; end = str->str + 1 + length; while (s < end) { @@ -427,7 +427,7 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) } *d = '\0'; str->len = length + 1; - + /* p points to the "{" in the line that starts the * literal. The length of the CR-less response must be * less than or equal to the length of the response @@ -437,16 +437,16 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) * GString's length would be off... */ sprintf (p, "{%0*d}", ldigits, length); - + fulllen += str->len; g_ptr_array_add (data, str); - + /* Read the next line. */ if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store), &line, ex) < 0) goto lose; } - + /* Now reassemble the data. */ p = line = g_malloc (fulllen + 1); for (i = 0; i < data->len; i++) { @@ -458,7 +458,7 @@ imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex) *p = '\0'; g_ptr_array_free (data, TRUE); return line; - + lose: for (i = 0; i < data->len; i++) g_string_free (data->pdata[i], TRUE); @@ -481,13 +481,13 @@ camel_imap_response_free (CamelImapStore *store, CamelImapResponse *response) int i, number, exists = 0; GArray *expunged = NULL; char *resp, *p; - + if (!response) return; - + for (i = 0; i < response->untagged->len; i++) { resp = response->untagged->pdata[i]; - + if (response->folder) { /* Check if it's something we need to handle. */ number = strtoul (resp + 2, &p, 10); @@ -503,10 +503,10 @@ camel_imap_response_free (CamelImapStore *store, CamelImapResponse *response) } g_free (resp); } - + g_ptr_array_free (response->untagged, TRUE); g_free (response->status); - + if (response->folder) { if (exists > 0 || expunged) { /* Update the summary */ @@ -515,10 +515,10 @@ camel_imap_response_free (CamelImapStore *store, CamelImapResponse *response) if (expunged) g_array_free (expunged, TRUE); } - + camel_object_unref (CAMEL_OBJECT (response->folder)); } - + g_free (response); CAMEL_IMAP_STORE_UNLOCK (store, command_lock); } @@ -565,18 +565,18 @@ camel_imap_response_extract (CamelImapStore *store, { int len = strlen (type), i; char *resp; - + 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); - + if (!g_strncasecmp (resp, type, len)) break; } - + if (i < response->untagged->len) { resp = response->untagged->pdata[i]; g_ptr_array_remove_index (response->untagged, i); @@ -586,7 +586,7 @@ camel_imap_response_extract (CamelImapStore *store, _("IMAP server response did not contain " "%s information"), type); } - + camel_imap_response_free (store, response); return resp; } @@ -610,14 +610,14 @@ camel_imap_response_extract_continuation (CamelImapStore *store, CamelException *ex) { char *status; - + if (response->status && *response->status == '+') { status = response->status; response->status = NULL; camel_imap_response_free (store, response); return status; } - + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, _("Unexpected OK response from IMAP server: %s"), response->status); @@ -633,9 +633,9 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, const char *p, *start; char *out, *op, *string; int num, len, i, arglen; - + args = g_ptr_array_new (); - + /* Determine the length of the data */ len = strlen (fmt); p = start = fmt; @@ -643,7 +643,7 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, p = strchr (start, '%'); if (!p) break; - + switch (*++p) { case 'd': num = va_arg (ap, int); @@ -651,14 +651,14 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, start = p + 1; len += 10; break; - + case 's': string = va_arg (ap, char *); g_ptr_array_add (args, string); start = p + 1; len += strlen (string); break; - + case 'S': case 'F': string = va_arg (ap, char *); @@ -672,11 +672,11 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, len += arglen * 2; start = p + 1; break; - + case '%': start = p; break; - + default: g_warning ("camel-imap-command is not printf. I don't " "know what '%%%c' means.", *p); @@ -684,7 +684,7 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, break; } } - + /* Now write out the string */ op = out = g_malloc (len + 1); p = start = fmt; @@ -698,18 +698,18 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, strncpy (op, start, p - start); op += p - start; } - + switch (*++p) { case 'd': num = GPOINTER_TO_INT (args->pdata[i++]); op += sprintf (op, "%d", num); break; - + case 's': string = args->pdata[i++]; op += sprintf (op, "%s", string); break; - + case 'S': case 'F': string = args->pdata[i++]; @@ -726,15 +726,15 @@ imap_command_strdup_vprintf (CamelImapStore *store, const char *fmt, if (*p == 'F') g_free (string); break; - + default: *op++ = '%'; *op++ = *p; } - + start = *p ? p + 1 : p; } - + return out; } @@ -743,10 +743,10 @@ imap_command_strdup_printf (CamelImapStore *store, const char *fmt, ...) { va_list ap; char *result; - + va_start (ap, fmt); result = imap_command_strdup_vprintf (store, fmt, ap); va_end (ap); - + return result; } -- cgit v1.2.3