aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-store.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-08-12 09:36:31 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-08-12 09:36:31 +0800
commit0d074947b910663afcd24fd740bb26a6ae7fc56d (patch)
tree776037030d5197b10c230865d6d1c8b379f76d31 /camel/providers/imap/camel-imap-store.c
parent966a555f470d58fc41b3f0ad3ee8cbf0e024e5b9 (diff)
downloadgsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar.gz
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar.bz2
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar.lz
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar.xz
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.tar.zst
gsoc2013-evolution-0d074947b910663afcd24fd740bb26a6ae7fc56d.zip
New convenience function for multi-transactional commands (opening
2000-08-11 Jeffrey Stedfast <fejj@helixcode.com> * providers/imap/camel-imap-store.c (camel_imap_command_preliminary): New convenience function for multi-transactional commands (opening request) (camel_imap_command_continuation): New convenience function for multi-transactional commands (followup data) svn path=/trunk/; revision=4762
Diffstat (limited to 'camel/providers/imap/camel-imap-store.c')
-rw-r--r--camel/providers/imap/camel-imap-store.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 374107250d..6eb03e9db4 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -968,3 +968,180 @@ camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **
return status;
}
+
+/**
+ * camel_imap_command_preliminary: Send a preliminary command to the
+ * IMAP server.
+ * @store: the IMAP store
+ * @ret: a pointer to return the full server response in
+ * @cmdid: a pointer to return the command identifier (for use in
+ * camel_imap_command_continuation)
+ * @fmt: a printf-style format string, followed by arguments
+ *
+ * This camel method sends a preliminary IMAP command specified by
+ * @fmt and the following arguments to the IMAP store specified by
+ * @store. This function is meant for use with multi-transactional
+ * IMAP communications like Kerberos authentication and APPEND.
+ *
+ * If the caller passed a non-NULL pointer for @ret,
+ * camel_imap_command_preliminary will set it to point to a buffer
+ * containing the rest of the response from the IMAP server. The
+ * caller function is responsible for freeing @ret.
+ *
+ * Return value: one of CAMEL_IMAP_PLUS or CAMEL_IMAP_FAIL
+ *
+ * Note: on success (CAMEL_IMAP_PLUS), you will need to follow up with
+ * a camel_imap_command_continuation call.
+ **/
+gint
+camel_imap_command_preliminary (CamelImapStore *store, char **ret, char **cmdid, char *fmt, ...)
+{
+ gchar *cmdbuf, *respbuf;
+ gint status = CAMEL_IMAP_OK;
+ va_list app;
+
+ /* Create the command */
+ *cmdid = g_strdup_printf ("A%.5d", store->command++);
+ va_start (app, fmt);
+ cmdbuf = g_strdup_vprintf (fmt, app);
+ va_end (app);
+
+ d(fprintf (stderr, "sending : %s %s\r\n", *cmdid, cmdbuf));
+
+ if (camel_stream_printf (store->ostream, "%s %s\r\n", *cmdid, cmdbuf) == -1) {
+ g_free (cmdbuf);
+
+ if (ret)
+ *ret = g_strdup (strerror (errno));
+
+ return CAMEL_IMAP_FAIL;
+ }
+ g_free (cmdbuf);
+
+ respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream));
+
+ if (respbuf) {
+ switch (*respbuf) {
+ case '+':
+ status = CAMEL_IMAP_PLUS;
+ break;
+ default:
+ status = camel_imap_status (*cmdid, respbuf);
+ }
+
+ if (ret)
+ *ret = g_strdup (imap_next_word (respbuf));
+ } else {
+ status = CAMEL_IMAP_FAIL;
+ if (ret)
+ *ret = NULL;
+ }
+
+ return status;
+}
+
+/**
+ * camel_imap_command_continuation: Handle another transaction with the IMAP
+ * server and possibly get a multi-line response.
+ * @store: the IMAP store
+ * @cmdid: The command identifier returned from camel_imap_command_preliminary
+ * @ret: a pointer to return the full server response in
+ * @cstream: a CamelStream containing a continuation response.
+ *
+ * This method is for sending continuing responses to the IMAP server. Meant
+ * to be used as a followup to camel_imap_command_preliminary.
+ *
+ * Return value: one of CAMEL_IMAP_PLUS (command requires additional data),
+ * CAMEL_IMAP_OK (command executed successfully),
+ * CAMEL_IMAP_NO (operational error message),
+ * CAMEL_IMAP_BAD (error message from the server), or
+ * CAMEL_IMAP_FAIL (a protocol-level error occurred, and Camel is uncertain
+ * of the result of the command.)
+ **/
+gint
+camel_imap_command_continuation (CamelImapStore *store, char *cmdid, char **ret, CamelStream *cstream)
+{
+ gint len = 0, status = CAMEL_IMAP_OK;
+ gchar *respbuf;
+ GPtrArray *data;
+ int i;
+
+ d(fprintf (stderr, "sending continuation stream\r\n"));
+
+ if (camel_stream_write_to_stream (cstream, store->ostream) == -1) {
+ *ret = g_strdup (strerror (errno));
+
+ return CAMEL_IMAP_FAIL;
+ }
+
+ data = g_ptr_array_new ();
+
+ while (TRUE) {
+ CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream);
+
+ respbuf = camel_stream_buffer_read_line (stream);
+ if (!respbuf || *respbuf == '+' || !strncmp (respbuf, cmdid, strlen (cmdid))) {
+ /* IMAP's last response starts with our command id */
+ d(fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"));
+
+ break;
+ }
+
+ d(fprintf (stderr, "received: %s\n", respbuf));
+
+ g_ptr_array_add (data, respbuf);
+ len += strlen (respbuf) + 1;
+ }
+
+ if (respbuf) {
+ switch (*respbuf) {
+ case '+':
+ status = CAMEL_IMAP_PLUS;
+ break;
+ default:
+ g_ptr_array_add (data, respbuf);
+ len += strlen (respbuf) + 1;
+
+ status = camel_imap_status (cmdid, respbuf);
+ }
+ } else {
+ status = CAMEL_IMAP_FAIL;
+ }
+
+ if (status == CAMEL_IMAP_OK || status == CAMEL_IMAP_PLUS) {
+ char *p;
+
+ *ret = g_malloc0 (len + 1);
+
+ for (i = 0, p = *ret; i < data->len; i++) {
+ char *ptr, *datap;
+
+ datap = (char *) data->pdata[i];
+ ptr = (*datap == '.') ? datap + 1 : datap;
+ len = strlen (ptr);
+ memcpy (p, ptr, len);
+ p += len;
+ *p++ = '\n';
+ }
+ *p = '\0';
+ } else {
+ if (status != CAMEL_IMAP_FAIL && respbuf) {
+ char *word;
+
+ word = imap_next_word (respbuf);
+
+ if (*respbuf == '-')
+ *ret = g_strdup (word);
+ else
+ *ret = g_strdup (imap_next_word (word));
+ } else {
+ *ret = NULL;
+ }
+ }
+
+ for (i = 0; i < data->len; i++)
+ g_free (data->pdata[i]);
+ g_ptr_array_free (data, TRUE);
+
+ return status;
+}