aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-03-25 08:42:05 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-03-25 08:42:05 +0800
commit2e125b7af652bb9be0dfc262c0cbe207f83211bf (patch)
tree476e647880da150c9ac58bfc735ef19141ec54ff /camel
parent69b905b91592bb4b704682a0e57af838f621e9f6 (diff)
downloadgsoc2013-evolution-2e125b7af652bb9be0dfc262c0cbe207f83211bf.tar.gz
gsoc2013-evolution-2e125b7af652bb9be0dfc262c0cbe207f83211bf.tar.zst
gsoc2013-evolution-2e125b7af652bb9be0dfc262c0cbe207f83211bf.zip
New convenience wrapper function. (engine_parse_status): Fixed to handle
2004-03-24 Jeffrey Stedfast <fejj@ximian.com> * providers/imap4/camel-imap-engine.c (camel_imap_engine_literal): New convenience wrapper function. (engine_parse_status): Fixed to handle literal mailbox strings. * providers/imap4/camel-imap-command.c (camel_imap_command_newv): Changed how %L works - create the CamelIMAPLiteral for our caller instead of expecting them to create it for us. We can autodetect what type of object (stream vs data-wrapper) the literal is, so it's trivial to do. svn path=/trunk/; revision=25179
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog12
-rw-r--r--camel/providers/imap4/camel-imap-command.c21
-rw-r--r--camel/providers/imap4/camel-imap-engine.c54
-rw-r--r--camel/providers/imap4/camel-imap-engine.h1
4 files changed, 79 insertions, 9 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 413374d135..ed10e180b2 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,15 @@
+2004-03-24 Jeffrey Stedfast <fejj@ximian.com>
+
+ * providers/imap4/camel-imap-engine.c (camel_imap_engine_literal):
+ New convenience wrapper function.
+ (engine_parse_status): Fixed to handle literal mailbox strings.
+
+ * providers/imap4/camel-imap-command.c (camel_imap_command_newv):
+ Changed how %L works - create the CamelIMAPLiteral for our caller
+ instead of expecting them to create it for us. We can autodetect
+ what type of object (stream vs data-wrapper) the literal is, so
+ it's trivial to do.
+
2004-03-23 Jeffrey Stedfast <fejj@ximian.com>
* providers/imap/camel-imap-folder.c (imap_get_message): Reworked
diff --git a/camel/providers/imap4/camel-imap-command.c b/camel/providers/imap4/camel-imap-command.c
index 4dfcb8faee..73f1f97096 100644
--- a/camel/providers/imap4/camel-imap-command.c
+++ b/camel/providers/imap4/camel-imap-command.c
@@ -195,11 +195,10 @@ camel_imap_command_newv (CamelIMAPEngine *engine, CamelIMAPFolder *imap_folder,
if (ch == '%') {
CamelIMAPLiteral *literal;
CamelIMAPFolder *folder;
- CamelDataWrapper *wrapper;
- CamelStream *stream;
unsigned int u;
char *string;
size_t len;
+ void *obj;
int c, d;
g_string_append_len (str, start, format - start - 1);
@@ -232,7 +231,22 @@ camel_imap_command_newv (CamelIMAPEngine *engine, CamelIMAPFolder *imap_folder,
break;
case 'L':
/* Literal */
- literal = va_arg (args, CamelIMAPLiteral *);
+ obj = va_arg (args, void *);
+
+ literal = g_new (CamelIMAPLiteral, 1);
+ if (CAMEL_IS_DATA_WRAPPER (obj)) {
+ literal->type = CAMEL_IMAP_LITERAL_WRAPPER;
+ literal->literal.wrapper = obj;
+ } else if (CAMEL_IS_STREAM (obj)) {
+ literal->type = CAMEL_IMAP_LITERAL_STREAM;
+ literal->literal.stream = obj;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ camel_object_ref (obj);
+
+ /* FIXME: take advantage of LITERAL+? */
len = camel_imap_literal_length (literal);
g_string_append_printf (str, "{%u}\r\n", len);
@@ -327,7 +341,6 @@ void
camel_imap_command_unref (CamelIMAPCommand *ic)
{
CamelIMAPCommandPart *part, *next;
- CamelIMAPLiteral *literal;
int i;
if (ic == NULL)
diff --git a/camel/providers/imap4/camel-imap-engine.c b/camel/providers/imap4/camel-imap-engine.c
index 36d2e42f9e..e7d6ce5899 100644
--- a/camel/providers/imap4/camel-imap-engine.c
+++ b/camel/providers/imap4/camel-imap-engine.c
@@ -579,6 +579,7 @@ engine_parse_status (CamelIMAPEngine *engine, CamelException *ex)
{
camel_imap_token_t token;
char *mailbox;
+ size_t len;
int type;
if (camel_imap_engine_next_token (engine, &token, ex) == -1)
@@ -592,7 +593,9 @@ engine_parse_status (CamelIMAPEngine *engine, CamelException *ex)
mailbox = g_strdup (token.v.qstring);
break;
case CAMEL_IMAP_TOKEN_LITERAL:
- /* FIXME: can this happen? if so implement it */
+ if (camel_imap_engine_literal (engine, (unsigned char **) &mailbox, &len, err) == -1)
+ return -1;
+ break;
default:
fprintf (stderr, "Unexpected token in IMAP untagged STATUS response: %s%c\n",
token.token == CAMEL_IMAP_TOKEN_NIL ? "NIL" : "",
@@ -1582,7 +1585,7 @@ camel_imap_engine_eat_line (CamelIMAPEngine *engine, CamelException *ex)
int
camel_imap_engine_line (CamelIMAPEngine *engine, unsigned char **line, size_t *len, CamelException *ex)
{
- GByteArray *linebuf;
+ GByteArray *linebuf = NULL;
unsigned char *buf;
size_t buflen;
int retval;
@@ -1591,7 +1594,7 @@ camel_imap_engine_line (CamelIMAPEngine *engine, unsigned char **line, size_t *l
linebuf = g_byte_array_new ();
while ((retval = camel_imap_stream_line (engine->istream, &buf, &buflen)) > 0) {
- if (line != NULL)
+ if (linebuf != NULL)
g_byte_array_append (linebuf, buf, buflen);
}
@@ -1600,13 +1603,13 @@ camel_imap_engine_line (CamelIMAPEngine *engine, unsigned char **line, size_t *l
_("IMAP server %s unexpectedly disconnected: %s"),
engine->url->host, errno ? g_strerror (errno) : _("Unknown"));
- if (line != NULL)
+ if (linebuf != NULL)
g_byte_array_free (linebuf, TRUE);
return -1;
}
- if (line != NULL) {
+ if (linebuf != NULL) {
g_byte_array_append (linebuf, buf, buflen);
*line = linebuf->data;
@@ -1619,6 +1622,47 @@ camel_imap_engine_line (CamelIMAPEngine *engine, unsigned char **line, size_t *l
}
+int
+camel_imap_engine_literal (CamelIMAPEngine *engine, unsigned char **literal, size_t *len, CamelException *ex)
+{
+ GByteArray *literalbuf = NULL;
+ unsigned char *buf;
+ size_t buflen;
+ int retval;
+
+ if (literal != NULL)
+ literalbuf = g_byte_array_new ();
+
+ while ((retval = camel_imap_stream_literal (engine->istream, &buf, &buflen)) > 0) {
+ if (literalbuf != NULL)
+ g_byte_array_append (literalbuf, buf, buflen);
+ }
+
+ if (retval == -1) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("IMAP server %s unexpectedly disconnected: %s"),
+ engine->url->host, errno ? g_strerror (errno) : _("Unknown"));
+
+ if (literalbuf != NULL)
+ g_byte_array_free (literalbuf, TRUE);
+
+ return -1;
+ }
+
+ if (literalbuf != NULL) {
+ g_byte_array_append (literalbuf, buf, buflen);
+ g_byte_array_append (literalbuf, "", 1);
+
+ *literal = literalbuf->data;
+ *len = literalbuf->len - 1;
+
+ g_byte_array_free (literalbuf, FALSE);
+ }
+
+ return 0;
+}
+
+
void
camel_imap_resp_code_free (CamelIMAPRespCode *rcode)
{
diff --git a/camel/providers/imap4/camel-imap-engine.h b/camel/providers/imap4/camel-imap-engine.h
index fd125b05d1..6612693243 100644
--- a/camel/providers/imap4/camel-imap-engine.h
+++ b/camel/providers/imap4/camel-imap-engine.h
@@ -207,6 +207,7 @@ void camel_imap_engine_handle_untagged (CamelIMAPEngine *engine, CamelException
/* stream wrapper utility functions */
int camel_imap_engine_next_token (CamelIMAPEngine *engine, struct _camel_imap_token_t *token, CamelException *ex);
int camel_imap_engine_line (CamelIMAPEngine *engine, unsigned char **line, size_t *len, CamelException *ex);
+int camel_imap_engine_literal (CamelIMAPEngine *engine, unsigned char **literal, size_t *len, CamelException *ex);
int camel_imap_engine_eat_line (CamelIMAPEngine *engine, CamelException *ex);