aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/imap')
-rw-r--r--camel/providers/imap/.cvsignore7
-rw-r--r--camel/providers/imap/Makefile.am48
-rw-r--r--camel/providers/imap/camel-imap-auth.c195
-rw-r--r--camel/providers/imap/camel-imap-auth.h39
-rw-r--r--camel/providers/imap/camel-imap-command.c406
-rw-r--r--camel/providers/imap/camel-imap-command.h58
-rw-r--r--camel/providers/imap/camel-imap-folder.c850
-rw-r--r--camel/providers/imap/camel-imap-folder.h77
-rw-r--r--camel/providers/imap/camel-imap-provider.c113
-rw-r--r--camel/providers/imap/camel-imap-store.c788
-rw-r--r--camel/providers/imap/camel-imap-store.h88
-rw-r--r--camel/providers/imap/camel-imap-stream.c220
-rw-r--r--camel/providers/imap/camel-imap-stream.h71
-rw-r--r--camel/providers/imap/camel-imap-summary.c147
-rw-r--r--camel/providers/imap/camel-imap-summary.h63
-rw-r--r--camel/providers/imap/camel-imap-utils.c688
-rw-r--r--camel/providers/imap/camel-imap-utils.h53
-rw-r--r--camel/providers/imap/libcamelimap.urls1
18 files changed, 0 insertions, 3912 deletions
diff --git a/camel/providers/imap/.cvsignore b/camel/providers/imap/.cvsignore
deleted file mode 100644
index fd6b811c68..0000000000
--- a/camel/providers/imap/.cvsignore
+++ /dev/null
@@ -1,7 +0,0 @@
-.deps
-Makefile
-Makefile.in
-.libs
-.deps
-*.lo
-*.la
diff --git a/camel/providers/imap/Makefile.am b/camel/providers/imap/Makefile.am
deleted file mode 100644
index 19646f1960..0000000000
--- a/camel/providers/imap/Makefile.am
+++ /dev/null
@@ -1,48 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-libcamelimapincludedir = $(includedir)/camel
-
-
-providerdir = $(pkglibdir)/camel-providers/$(VERSION)
-
-provider_LTLIBRARIES = libcamelimap.la
-provider_DATA = libcamelimap.urls
-
-INCLUDES = -I.. \
- -I$(srcdir)/.. \
- -I$(top_srcdir)/camel \
- -I$(top_srcdir)/intl \
- -I$(top_srcdir)/libibex \
- -I$(top_srcdir)/e-util \
- -I$(top_srcdir) \
- -I$(includedir) \
- $(GTK_INCLUDEDIR) \
- $(KRB4_CFLAGS) \
- -DG_LOG_DOMAIN=\"camel-imap-provider\"
-
-libcamelimap_la_SOURCES = \
- camel-imap-auth.c \
- camel-imap-command.c \
- camel-imap-folder.c \
- camel-imap-provider.c \
- camel-imap-store.c \
- camel-imap-summary.c \
- camel-imap-utils.c
-
-libcamelimapinclude_HEADERS = \
- camel-imap-auth.h \
- camel-imap-command.h \
- camel-imap-folder.h \
- camel-imap-store.h \
- camel-imap-stream.h \
- camel-imap-summary.h \
- camel-imap-utils.h
-
-libcamelimap_la_LDFLAGS = $(KRB4_LDFLAGS) -version-info 0:0:0
-
-EXTRA_DIST = libcamelimap.urls
-
-
-
-
-
diff --git a/camel/providers/imap/camel-imap-auth.c b/camel/providers/imap/camel-imap-auth.c
deleted file mode 100644
index 3bf1af6535..0000000000
--- a/camel/providers/imap/camel-imap-auth.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-auth.c: IMAP AUTHENTICATE implementations */
-
-/*
- * Authors: Dan Winship <danw@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-#include <config.h>
-
-#include <string.h>
-
-#ifdef HAVE_KRB4
-#include <krb.h>
-/* MIT krb4 des.h #defines _. Sigh. We don't need it. */
-#undef _
-#endif
-
-#include "camel-exception.h"
-#include "camel-mime-utils.h"
-
-#include "camel-imap-auth.h"
-#include "camel-imap-command.h"
-#include "camel-imap-utils.h"
-
-static char *
-base64_encode_simple (const char *data, int len)
-{
- unsigned char *out;
- int state = 0, outlen;
- unsigned int save = 0;
-
- out = g_malloc (len * 4 / 3 + 5);
- outlen = base64_encode_close ((unsigned char *)data, len, FALSE,
- out, &state, &save);
- out[outlen] = '\0';
- return (char *)out;
-}
-
-static int
-base64_decode_simple (char *data, int len)
-{
- int state = 0;
- unsigned int save = 0;
-
- return base64_decode_step ((unsigned char *)data, len,
- (unsigned char *)data, &state, &save);
-}
-
-#ifdef HAVE_KRB4
-#define IMAP_KERBEROS_V4_PROTECTION_NONE 1
-#define IMAP_KERBEROS_V4_PROTECTION_INTEGRITY 2
-#define IMAP_KERBEROS_V4_PROTECTION_PRIVACY 4
-
-gboolean
-imap_try_kerberos_v4_auth (CamelImapStore *store, CamelException *ex)
-{
- CamelImapResponse *response;
- char *resp, *data;
- int status, len;
- char *inst, *realm, *buf, *username;
- guint32 nonce_n, nonce_h, plus1;
- struct hostent *h;
- KTEXT_ST authenticator;
- CREDENTIALS credentials;
- des_cblock session;
- des_key_schedule schedule;
-
- /* The kickoff. */
- response = camel_imap_command (store, NULL, ex,
- "AUTHENTICATE KERBEROS_V4");
- if (!response)
- return FALSE;
- resp = camel_imap_response_extract_continuation (response, ex);
- if (!resp)
- return FALSE;
- data = imap_next_word (resp);
-
- /* First server response is a base64-encoded 32-bit random number
- * ("nonce") in network byte order.
- */
- if (strlen (data) != 8 || base64_decode_simple (data, 8) != 4) {
- g_free (resp);
- goto lose;
- }
- memcpy (&nonce_n, data, 4);
- g_free (resp);
- nonce_h = ntohl (nonce_n);
-
- /* Our response is an authenticator including that number. */
- h = camel_service_gethost (CAMEL_SERVICE (store), ex);
- if (!h)
- goto lose;
- inst = g_strndup (h->h_name, strcspn (h->h_name, "."));
- g_strdown (inst);
- realm = g_strdup (krb_realmofhost (h->h_name));
- status = krb_mk_req (&authenticator, "imap", inst, realm, nonce_h);
- if (status == KSUCCESS) {
- status = krb_get_cred ("imap", inst, realm, &credentials);
- memcpy (session, credentials.session, sizeof (session));
- memset (&credentials, 0, sizeof (credentials));
- }
- g_free (inst);
- g_free (realm);
-
- if (status != KSUCCESS) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Could not get Kerberos ticket:\n%s"),
- krb_err_txt[status]);
- goto lose;
- }
- des_key_sched (&session, schedule);
-
- buf = base64_encode_simple (authenticator.dat, authenticator.length);
- response = camel_imap_command_continuation (store, ex, buf);
- g_free (buf);
- if (!response)
- goto lose;
- resp = camel_imap_response_extract_continuation (response, ex);
- if (!resp)
- goto lose;
- data = imap_next_word (resp);
-
- len = strlen (data);
- base64_decode_simple (data, strlen (data));
-
- /* This one is encrypted. */
- des_ecb_encrypt ((des_cblock *)data, (des_cblock *)data, schedule, 0);
-
- /* Check that the returned value is the original nonce plus one. */
- memcpy (&plus1, data, 4);
- if (ntohl (plus1) != nonce_h + 1) {
- g_free (resp);
- goto lose;
- }
-
- /* "the fifth octet contain[s] a bit-mask specifying the
- * protection mechanisms supported by the server"
- */
- if (!(data[4] & IMAP_KERBEROS_V4_PROTECTION_NONE)) {
- g_warning ("Server does not support `no protection' :-(");
- g_free (resp);
- goto lose;
- }
- g_free (resp);
-
- username = CAMEL_SERVICE (store)->url->user;
- len = strlen (username) + 9;
- len += 8 - len % 8;
- data = g_malloc0 (len);
- memcpy (data, &nonce_n, 4);
- data[4] = IMAP_KERBEROS_V4_PROTECTION_NONE;
- data[5] = data[6] = data[7] = 0;
- strcpy (data + 8, username);
-
- des_pcbc_encrypt ((des_cblock *)data, (des_cblock *)data, len,
- schedule, &session, 1);
- memset (&session, 0, sizeof (session));
- buf = base64_encode_simple (data, len);
- g_free (data);
-
- response = camel_imap_command_continuation (store, ex, buf);
- if (!response)
- goto lose;
- camel_imap_response_free (response);
- return TRUE;
-
- lose:
- memset (&session, 0, sizeof (session));
-
- /* Get the server out of "waiting for continuation data" mode.
- */
- response = camel_imap_command_continuation (store, NULL, "*");
- if (response)
- camel_imap_response_free (response);
-
- return FALSE;
-}
-#endif /* HAVE_KRB4 */
diff --git a/camel/providers/imap/camel-imap-auth.h b/camel/providers/imap/camel-imap-auth.h
deleted file mode 100644
index fbbc5ef709..0000000000
--- a/camel/providers/imap/camel-imap-auth.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-auth.h: IMAP AUTHENTICATE implementations */
-
-/*
- * Authors:
- * Dan Winship <danw@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef CAMEL_IMAP_AUTH_H
-#define CAMEL_IMAP_AUTH_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include "camel-imap-store.h"
-
-gboolean imap_try_kerberos_v4_auth (CamelImapStore *store, CamelException *ex);
-gboolean imap_try_gssapi_auth (CamelImapStore *store, CamelException *ex);
-
-#endif /* CAMEL_IMAP_AUTH_H */
diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c
deleted file mode 100644
index e9808d5a1f..0000000000
--- a/camel/providers/imap/camel-imap-command.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-command.c: IMAP command sending/parsing routines */
-
-/*
- * Authors:
- * Dan Winship <danw@helixcode.com>
- * Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include "camel-imap-command.h"
-#include "camel-imap-utils.h"
-#include "camel-imap-folder.h"
-#include <camel/camel-exception.h>
-
-static char *imap_read_untagged (CamelImapStore *store, char *line,
- CamelException *ex);
-static CamelImapResponse *imap_read_response (CamelImapStore *store,
- CamelException *ex);
-
-/**
- * camel_imap_command: Send a command to a IMAP server and get a response
- * @store: the IMAP store
- * @folder: The folder to perform the operation in (or %NULL if not
- * relevant).
- * @ex: a CamelException
- * @fmt: a printf-style format string, followed by arguments
- *
- * This function makes sure that @folder (if non-%NULL) is the
- * currently-selected folder on @store and then sends the IMAP command
- * specified by @fmt and the following arguments. It then reads the
- * server's response(s) and parses the final result.
- *
- * As a special case, if @fmt is %NULL, it will just select @folder
- * and return the response from doing so.
- *
- * Return value: %NULL if an error occurred (in which case @ex will
- * be set). Otherwise, a CamelImapResponse describing the server's
- * response, which the caller must free with camel_imap_response_free().
- **/
-CamelImapResponse *
-camel_imap_command (CamelImapStore *store, CamelFolder *folder,
- CamelException *ex, const char *fmt, ...)
-{
- gchar *cmdbuf;
- va_list ap;
-
- /* Check for current folder */
- if (folder && (!fmt || folder != store->current_folder)) {
- CamelImapResponse *response;
-
- store->current_folder = NULL;
- response = camel_imap_command (store, NULL, ex,
- "SELECT \"%s\"",
- folder->full_name);
- if (!response)
- return NULL;
- store->current_folder = folder;
-
- if (!fmt)
- return response;
-
- camel_imap_response_free (response);
- }
-
- /* Send the command */
- va_start (ap, fmt);
- cmdbuf = g_strdup_vprintf (fmt, ap);
- va_end (ap);
-
- camel_remote_store_send_string (CAMEL_REMOTE_STORE (store), ex,
- "A%.5d %s\r\n", store->command++,
- cmdbuf);
- g_free (cmdbuf);
- if (camel_exception_is_set (ex))
- return NULL;
-
- /* Read the response. */
- return imap_read_response (store, ex);
-}
-
-/**
- * camel_imap_command_continuation: Send more command data to the IMAP server
- * @store: the IMAP store
- * @ex: a CamelException
- * @cmdbuf: buffer containing the response/request data
- *
- * This method is for sending continuing responses to the IMAP server
- * after camel_imap_command returns a CAMEL_IMAP_PLUS response.
- *
- * Return value: as for camel_imap_command()
- **/
-CamelImapResponse *
-camel_imap_command_continuation (CamelImapStore *store, CamelException *ex,
- const char *cmdbuf)
-{
- if (camel_remote_store_send_string (CAMEL_REMOTE_STORE (store), ex,
- "%s\r\n", cmdbuf) < 0)
- return NULL;
-
- return imap_read_response (store, ex);
-}
-
-/* Read the response to an IMAP command. */
-static CamelImapResponse *
-imap_read_response (CamelImapStore *store, CamelException *ex)
-{
- CamelImapResponse *response;
- int number, exists = 0;
- GArray *expunged = NULL;
- char *respbuf, *retcode, *word, *p;
-
- /* Read first line */
- if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store),
- &respbuf, ex) < 0)
- return NULL;
-
- response = g_new0 (CamelImapResponse, 1);
- response->untagged = g_ptr_array_new ();
-
- /* Check for untagged data */
- while (!strncmp (respbuf, "* ", 2)) {
- /* Read the rest of the response if it is multi-line. */
- respbuf = imap_read_untagged (store, respbuf, ex);
- if (camel_exception_is_set (ex))
- break;
-
- /* If it starts with a number, we might deal with
- * it ourselves.
- */
- word = imap_next_word (respbuf);
- number = strtoul (word, &p, 10);
- if (p != word && store->current_folder) {
- word = imap_next_word (p);
- if (!g_strcasecmp (word, "EXISTS")) {
- exists = number;
- g_free (respbuf);
- goto next;
- } else if (!g_strcasecmp (word, "EXPUNGE")) {
- if (!expunged) {
- expunged = g_array_new (FALSE, FALSE,
- sizeof (int));
- }
- g_array_append_val (expunged, number);
- g_free (respbuf);
- goto next;
- }
- } else {
- if (!g_strncasecmp (word, "BYE", 3)) {
- /* connection was lost, no more data to fetch */
- store->connected = FALSE;
- g_free (respbuf);
- respbuf = NULL;
- break;
- }
- }
-
- g_ptr_array_add (response->untagged, respbuf);
- next:
- if (camel_remote_store_recv_line (
- CAMEL_REMOTE_STORE (store), &respbuf, ex) < 0)
- break;
- }
-
- /* Update the summary */
- if (store->current_folder && (exists > 0 || expunged)) {
- camel_imap_folder_changed (store->current_folder, exists,
- expunged, NULL);
- }
- if (expunged)
- g_array_free (expunged, TRUE);
-
- if (!respbuf || camel_exception_is_set (ex)) {
- camel_imap_response_free (response);
- return NULL;
- }
-
- response->status = respbuf;
-
- /* Check for OK or continuation response. */
- if (!strncmp (respbuf, "+ ", 2))
- return response;
- retcode = imap_next_word (respbuf);
- if (!strncmp (retcode, "OK", 2))
- return response;
-
- /* We should never get BAD, or anything else but +, OK, or NO
- * for that matter.
- */
- if (strncmp (retcode, "NO", 2) != 0) {
- g_warning ("Unexpected response from IMAP server: %s",
- respbuf);
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Unexpected response from IMAP "
- "server: %s"), respbuf);
- camel_imap_response_free (response);
- return NULL;
- }
-
- retcode = imap_next_word (retcode);
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("IMAP command failed: %s"),
- retcode ? retcode : _("Unknown error"));
- camel_imap_response_free (response);
- return NULL;
-}
-
-/* Given a line that is the start of an untagged response, read and
- * return the complete response. (This will be a no-op if the line
- * in question doesn't end with a literal.)
- *
- * FIXME: this won't deal with multiple literals in a single response.
- */
-static char *
-imap_read_untagged (CamelImapStore *store, char *line, CamelException *ex)
-{
- int fulllen, length, left, i;
- GPtrArray *data;
- char *end, *p;
-
- p = strrchr (line, '{');
- if (!p)
- return line;
-
- length = strtoul (p + 1, &end, 10);
- if (*end != '}' || *(end + 1) || end == p + 1)
- return line;
-
- fulllen = length + strlen (line) + 1;
-
- /* OK. We have a literal. @length is the length including CRLF
- * pairs, which camel_remote_store_recv_line won't return.
- */
- data = g_ptr_array_new ();
- g_ptr_array_add (data, line);
- left = length;
- while (1) {
- if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (store),
- &line, ex) < 0) {
- for (i = 0; i < data->len; i++)
- g_free (data->pdata[i]);
- g_ptr_array_free (data, TRUE);
- return NULL;
- }
- g_ptr_array_add (data, line);
-
- if (left <= 0)
- break;
-
- left -= strlen (line) + 2;
-
- /* The output string will have only LF, not CRLF, so
- * decrement the length by one.
- */
- length--;
- }
-
- /* Add the length of the post-literal line. */
- fulllen += strlen (line);
-
- /* 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 with CRs, therefore
- * overwriting the old value with the new value cannot cause
- * an overrun.
- */
- sprintf (p, "{%d}", length);
-
- /* Now reassemble the data. */
- p = line = g_malloc (fulllen + 1);
- for (i = 0; i < data->len; i++) {
- length = strlen (data->pdata[i]);
- memcpy (p, data->pdata[i], length);
- g_free (data->pdata[i]);
- p += length;
- *p++ = '\n';
- }
- *p = '\0';
- g_ptr_array_free (data, TRUE);
- return line;
-}
-
-
-/**
- * camel_imap_response_free:
- * response: a CamelImapResponse:
- *
- * Frees all of the data in @response.
- **/
-void
-camel_imap_response_free (CamelImapResponse *response)
-{
- int i;
-
- if (!response)
- return;
- for (i = 0; i < response->untagged->len; i++)
- g_free (response->untagged->pdata[i]);
- g_ptr_array_free (response->untagged, TRUE);
- g_free (response->status);
- g_free (response);
-}
-
-/**
- * camel_imap_response_extract:
- * @response: the response data returned from camel_imap_command
- * @type: the response type to extract
- * @ex: a CamelException
- *
- * This checks that @response contains a single untagged response of
- * type @type and returns just that response data. If @response
- * doesn't contain the right information, the function will set @ex and
- * return %NULL. Either way, @response will be freed.
- *
- * Return value: the desired response string, which the caller must free.
- **/
-char *
-camel_imap_response_extract (CamelImapResponse *response, const char *type,
- CamelException *ex)
-{
- 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;
-
- g_free (response->untagged->pdata[i]);
- }
-
- if (i < response->untagged->len) {
- resp = response->untagged->pdata[i];
- for (i++; i < response->untagged->len; i++)
- g_free (response->untagged->pdata[i]);
- } else {
- resp = NULL;
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("IMAP server response did not contain "
- "%s information"), type);
- }
-
- g_ptr_array_free (response->untagged, TRUE);
- g_free (response->status);
- g_free (response);
- return resp;
-}
-
-/**
- * camel_imap_response_extract_continuation:
- * @response: the response data returned from camel_imap_command
- * @ex: a CamelException
- *
- * This checks that @response contains a continuation response, and
- * returns just that data. If @response doesn't contain a continuation
- * response, the function will set @ex and return %NULL. Either way,
- * @response will be freed.
- *
- * Return value: the desired response string, which the caller must free.
- **/
-char *
-camel_imap_response_extract_continuation (CamelImapResponse *response,
- CamelException *ex)
-{
- char *status;
-
- if (response->status && !strncmp (response->status, "+ ", 2)) {
- status = response->status;
- response->status = NULL;
- camel_imap_response_free (response);
- return status;
- }
-
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Unexpected OK response from IMAP server: %s"),
- response->status);
- camel_imap_response_free (response);
- return NULL;
-}
diff --git a/camel/providers/imap/camel-imap-command.h b/camel/providers/imap/camel-imap-command.h
deleted file mode 100644
index 38e290c379..0000000000
--- a/camel/providers/imap/camel-imap-command.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-command.h: IMAP command sending/parsing routines */
-
-/*
- * Authors:
- * Dan Winship <danw@helixcode.com>
- * Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-
-#ifndef CAMEL_IMAP_COMMAND_H
-#define CAMEL_IMAP_COMMAND_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include "camel-imap-store.h"
-
-typedef struct {
- GPtrArray *untagged;
- char *status;
-} CamelImapResponse;
-
-CamelImapResponse *camel_imap_command (CamelImapStore *store,
- CamelFolder *folder,
- CamelException *ex,
- const char *fmt, ...);
-CamelImapResponse *camel_imap_command_continuation (CamelImapStore *store,
- CamelException *ex,
- const char *cmdbuf);
-
-void camel_imap_response_free (CamelImapResponse *response);
-char *camel_imap_response_extract (CamelImapResponse *response,
- const char *type,
- CamelException *ex);
-char *camel_imap_response_extract_continuation (CamelImapResponse *response,
- CamelException *ex);
-
-#endif /* CAMEL_IMAP_COMMAND_H */
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
deleted file mode 100644
index a4b8b459de..0000000000
--- a/camel/providers/imap/camel-imap-folder.c
+++ /dev/null
@@ -1,850 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-folder.c: Abstract class for an imap folder */
-
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <ctype.h>
-
-#include <gal/util/e-util.h>
-
-#include "camel-imap-folder.h"
-#include "camel-imap-command.h"
-#include "camel-imap-store.h"
-#include "camel-imap-stream.h"
-#include "camel-imap-summary.h"
-#include "camel-imap-utils.h"
-#include "string-utils.h"
-#include "camel-stream.h"
-#include "camel-stream-fs.h"
-#include "camel-stream-mem.h"
-#include "camel-stream-buffer.h"
-#include "camel-data-wrapper.h"
-#include "camel-mime-message.h"
-#include "camel-stream-filter.h"
-#include "camel-mime-filter-from.h"
-#include "camel-mime-filter-crlf.h"
-#include "camel-exception.h"
-#include "camel-mime-utils.h"
-
-#define d(x) x
-
-#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
-
-static CamelFolderClass *parent_class = NULL;
-
-static void imap_finalize (CamelObject *object);
-static void imap_refresh_info (CamelFolder *folder, CamelException *ex);
-static void imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
-static const char *imap_get_full_name (CamelFolder *folder);
-static void imap_expunge (CamelFolder *folder, CamelException *ex);
-
-/* message counts */
-static gint imap_get_message_count (CamelFolder *folder);
-static gint imap_get_unread_message_count (CamelFolder *folder);
-
-/* message manipulation */
-static CamelMimeMessage *imap_get_message (CamelFolder *folder, const gchar *uid,
- CamelException *ex);
-static void imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
- const CamelMessageInfo *info, CamelException *ex);
-static void imap_copy_message_to (CamelFolder *source, const char *uid,
- CamelFolder *destination, CamelException *ex);
-static void imap_move_message_to (CamelFolder *source, const char *uid,
- CamelFolder *destination, CamelException *ex);
-
-/* summary info */
-static GPtrArray *imap_get_uids (CamelFolder *folder);
-static GPtrArray *imap_get_summary (CamelFolder *folder);
-static const CamelMessageInfo *imap_get_message_info (CamelFolder *folder, const char *uid);
-
-static void imap_update_summary (CamelFolder *folder, int first, int last,
- CamelException *ex);
-
-/* searching */
-static GPtrArray *imap_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex);
-
-/* flag methods */
-static guint32 imap_get_message_flags (CamelFolder *folder, const char *uid);
-static void imap_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set);
-static gboolean imap_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name);
-static void imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name,
- gboolean value);
-
-
-static void
-camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class)
-{
- CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_imap_folder_class);
-
- parent_class = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
- /* virtual method definition */
-
- /* virtual method overload */
- camel_folder_class->refresh_info = imap_refresh_info;
- camel_folder_class->sync = imap_sync;
- camel_folder_class->expunge = imap_expunge;
- camel_folder_class->get_full_name = imap_get_full_name;
-
- camel_folder_class->get_uids = imap_get_uids;
- camel_folder_class->free_uids = camel_folder_free_nop;
-
- camel_folder_class->get_message_count = imap_get_message_count;
- camel_folder_class->get_unread_message_count = imap_get_unread_message_count;
- camel_folder_class->get_message = imap_get_message;
- camel_folder_class->append_message = imap_append_message;
- camel_folder_class->copy_message_to = imap_copy_message_to;
- camel_folder_class->move_message_to = imap_move_message_to;
-
- camel_folder_class->get_summary = imap_get_summary;
- camel_folder_class->get_message_info = imap_get_message_info;
- camel_folder_class->free_summary = camel_folder_free_nop;
-
- camel_folder_class->search_by_expression = imap_search_by_expression;
-
- camel_folder_class->get_message_flags = imap_get_message_flags;
- camel_folder_class->set_message_flags = imap_set_message_flags;
- camel_folder_class->get_message_user_flag = imap_get_message_user_flag;
- camel_folder_class->set_message_user_flag = imap_set_message_user_flag;
-}
-
-static void
-camel_imap_folder_init (gpointer object, gpointer klass)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object);
- CamelFolder *folder = CAMEL_FOLDER (object);
-
- folder->has_summary_capability = TRUE;
- folder->has_search_capability = TRUE;
-
- imap_folder->summary = NULL;
-}
-
-CamelType
-camel_imap_folder_get_type (void)
-{
- static CamelType camel_imap_folder_type = CAMEL_INVALID_TYPE;
-
- if (camel_imap_folder_type == CAMEL_INVALID_TYPE) {
- camel_imap_folder_type =
- camel_type_register (CAMEL_FOLDER_TYPE, "CamelImapFolder",
- sizeof (CamelImapFolder),
- sizeof (CamelImapFolderClass),
- (CamelObjectClassInitFunc) camel_imap_folder_class_init,
- NULL,
- (CamelObjectInitFunc) camel_imap_folder_init,
- (CamelObjectFinalizeFunc) imap_finalize);
- }
-
- return camel_imap_folder_type;
-}
-
-CamelFolder *
-camel_imap_folder_new (CamelStore *parent, const char *folder_name,
- const char *short_name, const char *summary_file,
- CamelException *ex)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (parent);
- CamelFolder *folder = CAMEL_FOLDER (camel_object_new (camel_imap_folder_get_type ()));
- CamelImapFolder *imap_folder = (CamelImapFolder *)folder;
- CamelImapResponse *response;
- const char *resp;
- guint32 validity = 0;
- int i;
-
- camel_folder_construct (folder, parent, folder_name, short_name);
-
- response = camel_imap_command (imap_store, folder, ex, NULL);
- if (!response) {
- camel_object_unref ((CamelObject *)folder);
- return NULL;
- }
-
- for (i = 0; i < response->untagged->len; i++) {
- resp = response->untagged->pdata[i] + 2;
- if (!g_strncasecmp (resp, "FLAGS ", 6)) {
- folder->permanent_flags =
- imap_parse_flag_list (resp + 6);
- } else if (!g_strncasecmp (resp, "OK [PERMANENTFLAGS ", 19)) {
- folder->permanent_flags =
- imap_parse_flag_list (resp + 19);
- } else if (!g_strncasecmp (resp, "OK [UIDVALIDITY ", 16)) {
- validity = strtoul (resp + 16, NULL, 10);
- } else if (isdigit ((unsigned char)*resp)) {
- unsigned long num = strtoul (resp, (char **)&resp, 10);
-
- if (!g_strncasecmp (resp, " EXISTS", 7))
- imap_folder->exists = num;
- }
- }
- camel_imap_response_free (response);
-
- imap_folder->summary = camel_imap_summary_new (summary_file, validity);
- if (!imap_folder->summary) {
- camel_object_unref (CAMEL_OBJECT (folder));
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Could not load summary for %s"),
- folder_name);
- return NULL;
- }
-
- imap_refresh_info (folder, ex);
- if (camel_exception_is_set (ex)) {
- camel_object_unref (CAMEL_OBJECT (folder));
- return NULL;
- }
-
- return folder;
-}
-
-static void
-imap_finalize (CamelObject *object)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object);
-
- camel_object_unref ((CamelObject *)imap_folder->summary);
-}
-
-static void
-imap_refresh_info (CamelFolder *folder, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelImapResponse *response;
- struct {
- char *uid;
- guint32 flags;
- } *new;
- char *resp, *uid, *p, *flags;
- int i, seq, summary_len;
- CamelMessageInfo *info;
- gboolean folder_changed = FALSE;
-
- if (imap_folder->exists == 0) {
- if (camel_folder_summary_count != 0) {
- camel_folder_summary_clear (imap_folder->summary);
- camel_object_trigger_event (CAMEL_OBJECT (folder),
- "folder_changed", NULL);
- }
- return;
- }
-
- /* Get UIDs and flags of all messages. */
- response = camel_imap_command (store, folder, ex,
- "FETCH 1:%d (UID FLAGS)",
- imap_folder->exists);
- if (!response)
- return;
-
- new = g_malloc0 (imap_folder->exists * sizeof (*new));
- for (i = 0; i < response->untagged->len; i++) {
- resp = response->untagged->pdata[i];
-
- seq = strtoul (resp + 2, &resp, 10);
- if (g_strncasecmp (resp, " FETCH ", 7) != 0)
- continue;
-
- uid = e_strstrcase (resp, "UID ");
- if (uid) {
- uid += 4;
- strtoul (uid, &p, 10);
- new[seq - 1].uid = g_strndup (uid, p - uid);
- }
-
- flags = e_strstrcase (resp, "FLAGS ");
- if (flags) {
- flags += 6;
- new[seq - 1].flags = imap_parse_flag_list (flags);
- }
- }
-
- /* If we find a UID in the summary that doesn't correspond to
- * the UID in the folder, that it means the message was
- * deleted on the server, so we remove it from the summary.
- */
- summary_len = camel_folder_summary_count (imap_folder->summary);
- for (i = 0; i < summary_len && i < imap_folder->exists; i++) {
- info = camel_folder_summary_index (imap_folder->summary, i);
-
- /* Shouldn't happen, but... */
- if (!new[i].uid)
- continue;
-
- if (strcmp (info->uid, new[i].uid) != 0) {
- camel_folder_summary_remove (imap_folder->summary,
- info);
- folder_changed = TRUE;
- i--;
- summary_len--;
- continue;
- }
-
- /* Update summary flags */
- if (info->flags != new[i].flags) {
- info->flags = new[i].flags;
- camel_object_trigger_event (CAMEL_OBJECT (folder),
- "message_changed",
- info->uid);
- }
-
- g_free (new[i].uid);
- }
-
- /* Remove any leftover cached summary messages. */
- while (summary_len > i + 1) {
- camel_folder_summary_remove_index (imap_folder->summary,
- --summary_len);
- folder_changed = TRUE;
- }
-
- /* Add any new folder messages. */
- if (i < imap_folder->exists) {
- /* Fetch full summary for the remaining messages. */
- imap_update_summary (folder, i + 1, imap_folder->exists, ex);
- folder_changed = TRUE;
-
- while (i < imap_folder->exists)
- g_free (new[i++].uid);
- }
- g_free (new);
-
- if (folder_changed) {
- camel_object_trigger_event (CAMEL_OBJECT (folder),
- "folder_changed", NULL);
- }
-}
-
-static void
-imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelImapResponse *response;
- int i, max;
-
- /* Set the flags on any messages that have changed this session */
- max = camel_folder_summary_count (imap_folder->summary);
- for (i = 0; i < max; i++) {
- CamelMessageInfo *info;
-
- info = camel_folder_summary_index (imap_folder->summary, i);
- if (info->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) {
- char *flags;
-
- flags = imap_create_flag_list (info->flags);
- if (flags) {
- response = camel_imap_command (
- store, folder, ex,
- "UID STORE %s FLAGS.SILENT %s",
- info->uid, flags);
- g_free (flags);
- if (!response)
- return;
- camel_imap_response_free (response);
- }
- info->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
- }
- }
-
- if (expunge) {
- response = camel_imap_command (store, folder, ex, "EXPUNGE");
- camel_imap_response_free (response);
- }
-
- camel_folder_summary_save (imap_folder->summary);
-}
-
-static void
-imap_expunge (CamelFolder *folder, CamelException *ex)
-{
- imap_sync (folder, TRUE, ex);
-}
-
-static const char *
-imap_get_full_name (CamelFolder *folder)
-{
- CamelURL *url = ((CamelService *)folder->parent_store)->url;
- int len;
-
- if (!url->path || !*url->path || !strcmp (url->path, "/"))
- return folder->full_name;
- len = strlen (url->path + 1);
- if (!strncmp (url->path + 1, folder->full_name, len) &&
- strlen (folder->full_name) > len + 1)
- return folder->full_name + len + 1;
- return folder->full_name;
-}
-
-static gint
-imap_get_message_count (CamelFolder *folder)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
-
- return camel_folder_summary_count (imap_folder->summary);
-}
-
-static gint
-imap_get_unread_message_count (CamelFolder *folder)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelMessageInfo *info;
- int i, max, count = 0;
-
- max = camel_folder_summary_count (imap_folder->summary);
- for (i = 0; i < max; i++) {
- info = camel_folder_summary_index (imap_folder->summary, i);
- if (!(info->flags & CAMEL_MESSAGE_SEEN))
- count++;
- }
-
- return count;
-}
-
-static void
-imap_append_message (CamelFolder *folder, CamelMimeMessage *message,
- const CamelMessageInfo *info, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
- CamelImapResponse *response;
- CamelStream *memstream;
- CamelMimeFilter *crlf_filter;
- CamelStreamFilter *streamfilter;
- GByteArray *ba;
- char *flagstr, *result;
-
- /* create flag string param */
- if (info && info->flags)
- flagstr = imap_create_flag_list (info->flags);
- else
- flagstr = NULL;
-
- /* FIXME: We could avoid this if we knew how big the message was. */
- memstream = camel_stream_mem_new ();
- ba = g_byte_array_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (memstream), ba);
-
- streamfilter = camel_stream_filter_new_with_stream (memstream);
- crlf_filter = camel_mime_filter_crlf_new (
- CAMEL_MIME_FILTER_CRLF_ENCODE,
- CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
- camel_stream_filter_add (streamfilter, crlf_filter);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message),
- CAMEL_STREAM (streamfilter));
- camel_object_unref (CAMEL_OBJECT (streamfilter));
- camel_object_unref (CAMEL_OBJECT (crlf_filter));
- camel_object_unref (CAMEL_OBJECT (memstream));
-
- response = camel_imap_command (store, NULL, ex, "APPEND %s%s%s {%d}",
- folder->full_name, flagstr ? " " : "",
- flagstr ? flagstr : "", ba->len);
- g_free (flagstr);
-
- if (!response) {
- g_byte_array_free (ba, TRUE);
- return;
- }
- result = camel_imap_response_extract_continuation (response, ex);
- if (!result) {
- g_byte_array_free (ba, TRUE);
- return;
- }
- g_free (result);
-
- /* send the rest of our data - the mime message */
- g_byte_array_append (ba, "\0", 3);
- response = camel_imap_command_continuation (store, ex, ba->data);
- g_byte_array_free (ba, TRUE);
- if (!response)
- return;
- camel_imap_response_free (response);
-}
-
-static void
-imap_copy_message_to (CamelFolder *source, const char *uid,
- CamelFolder *destination, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
- CamelImapResponse *response;
-
- response = camel_imap_command (store, source, ex, "UID COPY %s \"%s\"",
- uid, destination->full_name);
- camel_imap_response_free (response);
-
- /* FIXME: This should go away once folder_changed is being
- * emitted by camel_imap_folder_changed on appends again.
- */
- if (!camel_exception_is_set (ex)) {
- camel_object_trigger_event (CAMEL_OBJECT (destination),
- "folder_changed", NULL);
- }
-}
-
-static void
-imap_move_message_to (CamelFolder *source, const char *uid,
- CamelFolder *destination, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (source->parent_store);
- CamelImapResponse *response;
-
- response = camel_imap_command (store, source, ex, "UID COPY %s \"%s\"",
- uid, destination->full_name);
- camel_imap_response_free (response);
-
- if (camel_exception_is_set (ex))
- return;
-
- /* FIXME: This should go away once folder_changed is being
- * emitted by camel_imap_folder_changed on appends again.
- */
- camel_object_trigger_event (CAMEL_OBJECT (destination),
- "folder_changed", NULL);
-
- camel_folder_delete_message (source, uid);
-}
-
-static GPtrArray *
-imap_get_uids (CamelFolder *folder)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- const CamelMessageInfo *info;
- GPtrArray *array;
- int i, count;
-
- count = camel_folder_summary_count (imap_folder->summary);
-
- array = g_ptr_array_new ();
- g_ptr_array_set_size (array, count);
-
- for (i = 0; i < count; i++) {
- info = camel_folder_summary_index (imap_folder->summary, i);
- array->pdata[i] = g_strdup (info->uid);
- }
-
- return array;
-}
-
-static CamelMimeMessage *
-imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
- CamelImapResponse *response;
- CamelStream *msgstream;
- CamelMimeMessage *msg;
- char *result, *mesg, *p;
- int len;
-
- response = camel_imap_command (store, folder, ex,
- "UID FETCH %s RFC822", uid);
- if (!response)
- return NULL;
- result = camel_imap_response_extract (response, "FETCH", ex);
- if (!result)
- return NULL;
-
- p = strstr (result, "RFC822");
- if (p) {
- p += 7;
- mesg = imap_parse_nstring (&p, &len);
- }
- if (!p) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not find message body in FETCH "
- "response."));
- g_free (result);
- return NULL;
- }
- g_free (result);
-
- msgstream = camel_stream_mem_new_with_buffer (mesg, len);
- msg = camel_mime_message_new ();
- camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg),
- msgstream);
- camel_object_unref (CAMEL_OBJECT (msgstream));
- g_free (mesg);
-
- return msg;
-}
-
-/**
- * imap_protocol_get_summary_specifier
- *
- * Make a data item specifier for the header lines we need,
- * appropriate to the server level.
- *
- * IMAP4rev1: UID FLAGS BODY.PEEK[HEADER.FIELDS (SUBJECT FROM .. IN-REPLY-TO)]
- * IMAP4: UID FLAGS RFC822.HEADER.LINES (SUBJECT FROM .. IN-REPLY-TO)
- **/
-static char *
-imap_protocol_get_summary_specifier (CamelImapStore *store)
-{
- char *sect_begin, *sect_end;
- char *headers_wanted = "SUBJECT FROM TO CC DATE MESSAGE-ID REFERENCES IN-REPLY-TO";
-
- if (store->server_level >= IMAP_LEVEL_IMAP4REV1) {
- sect_begin = "BODY.PEEK[HEADER.FIELDS";
- sect_end = "]";
- } else {
- sect_begin = "RFC822.HEADER.LINES";
- sect_end = "";
- }
-
- return g_strdup_printf ("UID FLAGS %s (%s)%s", sect_begin,
- headers_wanted, sect_end);
-}
-
-static void
-imap_update_summary (CamelFolder *folder, int first, int last,
- CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
- CamelImapResponse *response;
- GPtrArray *headers = NULL;
- char *q, *summary_specifier;
- struct _header_raw *h = NULL;
- int i;
-
- /* If the range we're updating overlaps with the range we already
- * know about, then fetch just flags + uids first. If uids
- * aren't "right", reorder them. Update flags appropriately.
- * If that returned unknown UIDs, or we're updating unknown
- * sequence numbers, do the full fetch for those.
- */
-
- summary_specifier = imap_protocol_get_summary_specifier (store);
- if (first == last) {
- response = camel_imap_command (store, folder, ex,
- "FETCH %d (%s)", first,
- summary_specifier);
- } else {
- response = camel_imap_command (store, folder, ex,
- "FETCH %d:%d (%s)", first,
- last, summary_specifier);
- }
- g_free (summary_specifier);
-
- if (!response)
- return;
-
- headers = response->untagged;
- for (i = 0; i < headers->len; i++) {
- CamelMessageInfo *info;
- char *uid, *flags, *header;
-
- /* Grab the UID... */
- if (!(uid = strstr (headers->pdata[i], "UID "))) {
- d(fprintf (stderr, "Cannot get a uid for %d\n\n%s\n\n", i+1, (char *) headers->pdata[i]));
- break;
- }
-
- for (uid += 4; *uid && (*uid < '0' || *uid > '9'); uid++)
- ;
- for (q = uid; *q && *q >= '0' && *q <= '9'; q++)
- ;
-
- /* construct the header list */
- /* fast-forward to beginning of header info... */
- header = strchr (headers->pdata[i], '\n') + 1;
- h = NULL;
- do {
- char *line;
- int len;
-
- len = strcspn (header, "\n");
- while (header[len + 1] == ' ' ||
- header[len + 1] == '\t')
- len += 1 + strcspn (header + len + 1, "\n");
- line = g_strndup (header, len);
- header_raw_append_parse (&h, line, -1);
- g_free (line);
-
- header += len;
- } while (*header++ == '\n' && *header != '\n');
-
- /* We can't just call camel_folder_summary_add_from_parser
- * because it will assign the wrong UID, and thus get the
- * uid hash table wrong and all that. FIXME some day.
- */
- info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(imap_folder->summary)))->message_info_new(imap_folder->summary, h);
- header_raw_clear (&h);
- info->uid = g_strndup (uid, q - uid);
-
- /* now lets grab the FLAGS */
- if (!(flags = strstr (headers->pdata[i], "FLAGS "))) {
- d(fprintf (stderr, "We didn't seem to get any flags for %d...\n", i));
- } else {
- for (flags += 6; *flags && *flags != '('; flags++)
- ;
- info->flags = imap_parse_flag_list (flags);
- }
-
- camel_folder_summary_add (imap_folder->summary, info);
- }
- camel_imap_response_free (response);
-}
-
-static GPtrArray *
-imap_get_summary (CamelFolder *folder)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
-
- return imap_folder->summary->messages;
-}
-
-/* get a single message info, by uid */
-static const CamelMessageInfo *
-imap_get_message_info (CamelFolder *folder, const char *uid)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
-
- return camel_folder_summary_uid (imap_folder->summary, uid);
-}
-
-static GPtrArray *
-imap_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex)
-{
- CamelImapResponse *response;
- GPtrArray *uids = NULL;
- char *result, *sexp, *p;
-
- d(fprintf (stderr, "camel sexp: '%s'\n", expression));
- sexp = imap_translate_sexp (expression);
- d(fprintf (stderr, "imap sexp: '%s'\n", sexp));
-
- uids = g_ptr_array_new ();
-
- if (!folder->has_search_capability) {
- g_free (sexp);
- return uids;
- }
-
- response = camel_imap_command (CAMEL_IMAP_STORE (folder->parent_store),
- folder, NULL, "UID SEARCH %s", sexp);
- g_free (sexp);
- if (!response)
- return uids;
-
- result = camel_imap_response_extract (response, "SEARCH", NULL);
- if (!result)
- return uids;
-
- if ((p = strstr (result, "* SEARCH"))) {
- char *word;
-
- word = imap_next_word (p); /* word now points to SEARCH */
-
- for (word = imap_next_word (word); *word && *word != '*'; word = imap_next_word (word)) {
- gboolean word_is_numeric = TRUE;
- char *ep;
-
- /* find the end of this word and make sure it's a numeric uid */
- for (ep = word; *ep && *ep != ' ' && *ep != '\n'; ep++)
- if (*ep < '0' || *ep > '9')
- word_is_numeric = FALSE;
-
- if (word_is_numeric)
- g_ptr_array_add (uids, g_strndup (word, (gint)(ep - word)));
- }
- }
-
- g_free (result);
-
- return uids;
-}
-
-static guint32
-imap_get_message_flags (CamelFolder *folder, const char *uid)
-{
- const CamelMessageInfo *info;
-
- info = imap_get_message_info (folder, uid);
- g_return_val_if_fail (info != NULL, 0);
-
- return info->flags;
-}
-
-static void
-imap_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set)
-{
- CamelImapFolder *imap_folder = (CamelImapFolder *)folder;
- CamelMessageInfo *info;
-
- info = camel_folder_summary_uid (imap_folder->summary, uid);
- g_return_if_fail (info != NULL);
-
- if ((info->flags & set) == flags)
- return;
-
- info->flags = (info->flags & ~flags) | (set & flags) | CAMEL_MESSAGE_FOLDER_FLAGGED;
- camel_folder_summary_touch (imap_folder->summary);
-
- camel_object_trigger_event (CAMEL_OBJECT (folder), "message_changed",
- (gpointer)uid);
-}
-
-static gboolean
-imap_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name)
-{
- /* FIXME */
- return FALSE;
-}
-
-static void
-imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, gboolean value)
-{
- /* FIXME */
- camel_object_trigger_event (CAMEL_OBJECT (folder), "message_changed",
- (gpointer)uid);
-}
-
-void
-camel_imap_folder_changed (CamelFolder *folder, int exists,
- GArray *expunged, CamelException *ex)
-{
- CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
-
- if (expunged) {
- int i, id;
-
- for (i = 0; i < expunged->len; i++) {
- id = g_array_index (expunged, int, i);
- camel_folder_summary_remove_index (
- imap_folder->summary, id - 1);
- }
- camel_object_trigger_event (CAMEL_OBJECT (folder),
- "folder_changed", NULL);
- }
-
- if (exists != 0)
- imap_folder->exists = exists;
-}
diff --git a/camel/providers/imap/camel-imap-folder.h b/camel/providers/imap/camel-imap-folder.h
deleted file mode 100644
index 109cc76506..0000000000
--- a/camel/providers/imap/camel-imap-folder.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-folder.h : Abstract class for an imap folder */
-
-/*
- * Author:
- * Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-
-#ifndef CAMEL_IMAP_FOLDER_H
-#define CAMEL_IMAP_FOLDER_H 1
-
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include "camel-folder.h"
-#include <camel/camel-folder-search.h>
-
-#define CAMEL_IMAP_FOLDER_TYPE (camel_imap_folder_get_type ())
-#define CAMEL_IMAP_FOLDER(obj) (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolder))
-#define CAMEL_IMAP_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolderClass))
-#define IS_CAMEL_IMAP_FOLDER(o) (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_FOLDER_TYPE))
-
-typedef struct {
- CamelFolder parent_object;
-
- CamelFolderSummary *summary;
- int exists;
-} CamelImapFolder;
-
-
-typedef struct {
- CamelFolderClass parent_class;
-
- /* Virtual methods */
-
-} CamelImapFolderClass;
-
-
-/* public methods */
-CamelFolder *camel_imap_folder_new (CamelStore *parent,
- const char *folder_name,
- const char *short_name,
- const char *summary_file,
- CamelException *ex);
-
-void camel_imap_folder_changed (CamelFolder *folder, int exists,
- GArray *expunged, CamelException *ex);
-
-/* Standard Camel function */
-CamelType camel_imap_folder_get_type (void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_IMAP_FOLDER_H */
diff --git a/camel/providers/imap/camel-imap-provider.c b/camel/providers/imap/camel-imap-provider.c
deleted file mode 100644
index 9b962df5f4..0000000000
--- a/camel/providers/imap/camel-imap-provider.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-provider.c: imap provider registration code */
-
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-
-#include "config.h"
-#include "camel-imap-store.h"
-#include "camel-provider.h"
-#include "camel-session.h"
-#include "camel-url.h"
-
-static void add_hash (guint *hash, char *s);
-static guint imap_url_hash (gconstpointer key);
-static gint check_equal (char *s1, char *s2);
-static gint imap_url_equal (gconstpointer a, gconstpointer b);
-
-static CamelProvider imap_provider = {
- "imap",
- N_("IMAPv4"),
-
- N_("For reading and storing mail on IMAP servers."),
-
- "mail",
-
- CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
- CAMEL_PROVIDER_IS_STORAGE,
-
- CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST |
- CAMEL_URL_ALLOW_PATH | CAMEL_URL_ALLOW_AUTH,
-
- { 0, 0 },
-
- NULL
-};
-
-void
-camel_provider_module_init (CamelSession *session)
-{
- imap_provider.object_types[CAMEL_PROVIDER_STORE] =
- camel_imap_store_get_type();
-
- imap_provider.service_cache = g_hash_table_new (imap_url_hash, imap_url_equal);
-
- camel_session_register_provider (session, &imap_provider);
-}
-
-static void
-add_hash (guint *hash, char *s)
-{
- if (s)
- *hash ^= g_str_hash(s);
-}
-
-static guint
-imap_url_hash (gconstpointer key)
-{
- const CamelURL *u = (CamelURL *)key;
- guint hash = 0;
-
- add_hash (&hash, u->user);
- add_hash (&hash, u->authmech);
- add_hash (&hash, u->host);
- hash ^= u->port;
-
- return hash;
-}
-
-static gint
-check_equal (char *s1, char *s2)
-{
- if (s1 == NULL) {
- if (s2 == NULL)
- return TRUE;
- else
- return FALSE;
- }
-
- if (s2 == NULL)
- return FALSE;
-
- return strcmp (s1, s2) == 0;
-}
-
-static gint
-imap_url_equal (gconstpointer a, gconstpointer b)
-{
- const CamelURL *u1 = a, *u2 = b;
-
- return check_equal (u1->user, u2->user)
- && check_equal (u1->authmech, u2->authmech)
- && check_equal (u1->host, u2->host)
- && u1->port == u2->port;
-}
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
deleted file mode 100644
index 0a8618ff90..0000000000
--- a/camel/providers/imap/camel-imap-store.c
+++ /dev/null
@@ -1,788 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-store.c : class for an imap store */
-
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <gal/util/e-util.h>
-
-#include "camel-imap-store.h"
-#include "camel-imap-auth.h"
-#include "camel-imap-folder.h"
-#include "camel-imap-utils.h"
-#include "camel-imap-command.h"
-#include "camel-folder.h"
-#include "camel-exception.h"
-#include "camel-session.h"
-#include "camel-stream.h"
-#include "camel-stream-buffer.h"
-#include "camel-stream-fs.h"
-#include "camel-url.h"
-#include "string-utils.h"
-
-#define d(x) x
-
-/* Specified in RFC 2060 */
-#define IMAP_PORT 143
-
-static CamelRemoteStoreClass *remote_store_class = NULL;
-
-static gboolean imap_connect (CamelService *service, CamelException *ex);
-static gboolean imap_disconnect (CamelService *service, gboolean clean, CamelException *ex);
-static GList *query_auth_types_generic (CamelService *service, CamelException *ex);
-static GList *query_auth_types_connected (CamelService *service, CamelException *ex);
-static CamelFolder *get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex);
-static char *get_folder_name (CamelStore *store, const char *folder_name,
- CamelException *ex);
-static char *get_root_folder_name (CamelStore *store, CamelException *ex);
-static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
- gboolean fast, gboolean recursive,
- gboolean subscribed_only,
- CamelException *ex);
-static gboolean folder_subscribed (CamelStore *store, const char *folder_name);
-static void subscribe_folder (CamelStore *store, const char *folder_name,
- CamelException *ex);
-static void unsubscribe_folder (CamelStore *store, const char *folder_name,
- CamelException *ex);
-static void imap_keepalive (CamelRemoteStore *store);
-
-static void
-camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class)
-{
- /* virtual method overload */
- CamelServiceClass *camel_service_class =
- CAMEL_SERVICE_CLASS (camel_imap_store_class);
- CamelStoreClass *camel_store_class =
- CAMEL_STORE_CLASS (camel_imap_store_class);
- CamelRemoteStoreClass *camel_remote_store_class =
- CAMEL_REMOTE_STORE_CLASS (camel_imap_store_class);
-
- remote_store_class = CAMEL_REMOTE_STORE_CLASS(camel_type_get_global_classfuncs
- (camel_remote_store_get_type ()));
-
- /* virtual method overload */
- camel_service_class->query_auth_types_generic = query_auth_types_generic;
- camel_service_class->query_auth_types_connected = query_auth_types_connected;
- camel_service_class->connect = imap_connect;
- camel_service_class->disconnect = imap_disconnect;
-
- camel_store_class->get_folder = get_folder;
- camel_store_class->get_folder_name = get_folder_name;
- camel_store_class->get_root_folder_name = get_root_folder_name;
- camel_store_class->get_folder_info = get_folder_info;
- camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-
- camel_store_class->folder_subscribed = folder_subscribed;
- camel_store_class->subscribe_folder = subscribe_folder;
- camel_store_class->unsubscribe_folder = unsubscribe_folder;
-
- camel_remote_store_class->keepalive = imap_keepalive;
-}
-
-static gboolean
-free_sub (gpointer key, gpointer value, gpointer user_data)
-{
- g_free (key);
- return TRUE;
-}
-
-static void
-camel_imap_store_finalize (CamelObject *object)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
-
- g_hash_table_foreach_remove (imap_store->subscribed_folders,
- free_sub, NULL);
- g_hash_table_destroy (imap_store->subscribed_folders);
-}
-
-static void
-camel_imap_store_init (gpointer object, gpointer klass)
-{
- CamelRemoteStore *remote_store = CAMEL_REMOTE_STORE (object);
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (object);
- CamelStore *store = CAMEL_STORE (object);
-
- remote_store->default_port = 143;
-
- imap_store->dir_sep = '\0';
- imap_store->current_folder = NULL;
-
- store->flags = CAMEL_STORE_SUBSCRIPTIONS;
-
- imap_store->connected = FALSE;
- imap_store->subscribed_folders = g_hash_table_new (g_str_hash, g_str_equal);
-}
-
-CamelType
-camel_imap_store_get_type (void)
-{
- static CamelType camel_imap_store_type = CAMEL_INVALID_TYPE;
-
- if (camel_imap_store_type == CAMEL_INVALID_TYPE) {
- camel_imap_store_type =
- camel_type_register (CAMEL_REMOTE_STORE_TYPE, "CamelImapStore",
- sizeof (CamelImapStore),
- sizeof (CamelImapStoreClass),
- (CamelObjectClassInitFunc) camel_imap_store_class_init,
- NULL,
- (CamelObjectInitFunc) camel_imap_store_init,
- (CamelObjectFinalizeFunc) camel_imap_store_finalize);
- }
-
- return camel_imap_store_type;
-}
-
-static struct {
- const char *name;
- guint32 flag;
-} capabilities[] = {
- { "IMAP4", IMAP_CAPABILITY_IMAP4 },
- { "IMAP4REV1", IMAP_CAPABILITY_IMAP4REV1 },
- { "STATUS", IMAP_CAPABILITY_STATUS },
- { "NAMESPACE", IMAP_CAPABILITY_NAMESPACE },
- { "AUTH=KERBEROS_V4", IMAP_CAPABILITY_AUTH_KERBEROS_V4 },
- { "AUTH=GSSAPI", IMAP_CAPABILITY_AUTH_GSSAPI },
- { "UIDPLUS", IMAP_CAPABILITY_UIDPLUS },
- { "LITERAL+", IMAP_CAPABILITY_LITERALPLUS },
- { NULL, 0 }
-};
-
-static gboolean
-connect_to_server (CamelService *service, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (service);
- CamelImapResponse *response;
- char *result, *buf, *capa, *lasts;
- int i;
-
- if (!CAMEL_SERVICE_CLASS (remote_store_class)->connect (service, ex))
- return FALSE;
-
- store->command = 0;
-
- /* Read the greeting, if any. FIXME: deal with PREAUTH */
- if (camel_remote_store_recv_line (CAMEL_REMOTE_STORE (service),
- &buf, ex) < 0) {
- return FALSE;
- }
- g_free (buf);
- store->connected = TRUE;
-
- /* Find out the IMAP capabilities */
- store->capabilities = 0;
- response = camel_imap_command (store, NULL, ex, "CAPABILITY");
- if (!response)
- return FALSE;
- result = camel_imap_response_extract (response, "CAPABILITY", ex);
- if (!result)
- return FALSE;
-
- /* Skip over "* CAPABILITY". */
- capa = imap_next_word (result + 2);
-
- for (capa = strtok_r (capa, " ", &lasts); capa;
- capa = strtok_r (NULL, " ", &lasts)) {
- for (i = 0; capabilities[i].name; i++) {
- if (g_strcasecmp (capa, capabilities[i].name) == 0) {
- store->capabilities |= capabilities[i].flag;
- break;
- }
- }
- }
- g_free (result);
-
- if (store->capabilities & IMAP_CAPABILITY_IMAP4REV1) {
- store->server_level = IMAP_LEVEL_IMAP4REV1;
- store->capabilities |= IMAP_CAPABILITY_STATUS;
- } else if (store->capabilities & IMAP_CAPABILITY_IMAP4)
- store->server_level = IMAP_LEVEL_IMAP4;
- else
- store->server_level = IMAP_LEVEL_UNKNOWN;
-
- return TRUE;
-}
-
-static CamelServiceAuthType password_authtype = {
- N_("Password"),
-
- N_("This option will connect to the IMAP server using a "
- "plaintext password."),
-
- "",
- TRUE
-};
-
-#ifdef HAVE_KRB4
-static CamelServiceAuthType kerberos_v4_authtype = {
- N_("Kerberos 4"),
-
- N_("This option will connect to the IMAP server using "
- "Kerberos 4 authentication."),
-
- "KERBEROS_V4",
- FALSE
-};
-#endif
-
-static GList *
-query_auth_types_connected (CamelService *service, CamelException *ex)
-{
- GList *types;
-
- if (!connect_to_server (service, ex))
- return NULL;
-
- types = CAMEL_SERVICE_CLASS (remote_store_class)->query_auth_types_connected (service, ex);
-#ifdef HAVE_KRB4
- if (CAMEL_IMAP_STORE (service)->capabilities &
- IMAP_CAPABILITY_AUTH_KERBEROS_V4)
- types = g_list_prepend (types, &kerberos_v4_authtype);
-#endif
- return g_list_prepend (types, &password_authtype);
-}
-
-static GList *
-query_auth_types_generic (CamelService *service, CamelException *ex)
-{
- GList *types;
-
- types = CAMEL_SERVICE_CLASS (remote_store_class)->query_auth_types_generic (service, ex);
-#ifdef HAVE_KRB4
- types = g_list_prepend (types, &kerberos_v4_authtype);
-#endif
- return g_list_prepend (types, &password_authtype);
-}
-
-static gboolean
-imap_connect (CamelService *service, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (service);
- CamelSession *session = camel_service_get_session (CAMEL_SERVICE (store));
- gchar *result, *errbuf = NULL, *namespace;
- CamelImapResponse *response;
- gboolean authenticated = FALSE;
- int len;
-
- if (connect_to_server (service, ex) == 0)
- return FALSE;
-
- /* authenticate the user */
-#ifdef HAVE_KRB4
- if (service->url->authmech &&
- !g_strcasecmp (service->url->authmech, "KERBEROS_V4")) {
- if (!(store->capabilities & IMAP_CAPABILITY_AUTH_KERBEROS_V4)) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- "IMAP server %s does not "
- "support requested "
- "authentication type %s",
- service->url->host,
- service->url->authmech);
- camel_service_disconnect (service, TRUE, NULL);
- return FALSE;
- }
-
- authenticated = imap_try_kerberos_v4_auth (store, ex);
- if (camel_exception_is_set (ex)) {
- camel_service_disconnect (service, TRUE, NULL);
- return FALSE;
- }
- }
-#endif
-
- while (!authenticated) {
- if (errbuf) {
- /* We need to un-cache the password before prompting again */
- camel_session_query_authenticator (
- session, CAMEL_AUTHENTICATOR_TELL, NULL,
- TRUE, service, "password", ex);
- g_free (service->url->passwd);
- service->url->passwd = NULL;
- }
-
- if (!service->url->authmech && !service->url->passwd) {
- char *prompt;
-
- prompt = g_strdup_printf (_("%sPlease enter the IMAP "
- "password for %s@%s"),
- errbuf ? errbuf : "",
- service->url->user,
- service->url->host);
- service->url->passwd =
- camel_session_query_authenticator (
- session, CAMEL_AUTHENTICATOR_ASK,
- prompt, TRUE, service, "password", ex);
- g_free (prompt);
- g_free (errbuf);
- errbuf = NULL;
-
- if (!service->url->passwd) {
- camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
- "You didn\'t enter a password.");
- camel_service_disconnect (service, TRUE, NULL);
- return FALSE;
- }
- }
-
- response = camel_imap_command (store, NULL, ex,
- "LOGIN \"%s\" \"%s\"",
- service->url->user,
- service->url->passwd);
- if (!response) {
- errbuf = g_strdup_printf (_("Unable to authenticate "
- "to IMAP server.\n%s\n\n"),
- camel_exception_get_description (ex));
- camel_exception_clear (ex);
- } else {
- authenticated = TRUE;
- camel_imap_response_free (response);
- }
- }
-
- /* Find our storage path. */
- if (!store->storage_path) {
- store->storage_path =
- camel_session_get_storage_path (session, service, ex);
- if (camel_exception_is_set (ex))
- return FALSE;
- }
-
- /* Find the hierarchy separator for our namespace. */
- namespace = service->url->path;
- if (namespace)
- namespace++;
- else
- namespace = "";
- if (store->server_level >= IMAP_LEVEL_IMAP4REV1) {
- /* This idiom means "tell me the hierarchy separator
- * for the given path, even if that path doesn't exist.
- */
- response = camel_imap_command (store, NULL, ex,
- "LIST \"%s\" \"\"",
- namespace);
- } else {
- /* Plain IMAP4 doesn't have that idiom, so we fall back
- * to "tell me about this folder", which will fail if
- * the folder doesn't exist (eg, if namespace is "").
- */
- response = camel_imap_command (store, NULL, ex,
- "LIST \"\" \"%s\"",
- namespace);
- }
- if (!response)
- return FALSE;
-
- result = camel_imap_response_extract (response, "LIST", NULL);
- if (result) {
- imap_parse_list_response (result, NULL, &store->dir_sep, NULL);
- g_free (result);
- }
- if (!store->dir_sep)
- store->dir_sep = '/'; /* Guess */
-
- /* Generate base URL */
- store->base_url = camel_url_to_string (service->url, FALSE);
- len = strlen (store->base_url);
- if (service->url->path)
- store->base_url[len - strlen (service->url->path) + 1] = '\0';
- else {
- store->base_url = g_realloc (store->base_url, len + 2);
- store->base_url[len] = '/';
- store->base_url[len + 1] = '\0';
- }
-
- camel_remote_store_refresh_folders (CAMEL_REMOTE_STORE (store), ex);
-
- return !camel_exception_is_set (ex);
-}
-
-static gboolean
-imap_disconnect (CamelService *service, gboolean clean, CamelException *ex)
-{
- CamelImapStore *store = CAMEL_IMAP_STORE (service);
- CamelImapResponse *response;
-
- if (store->connected && clean) {
- /* send the logout command */
- response = camel_imap_command (store, NULL, ex, "LOGOUT");
- camel_imap_response_free (response);
- }
-
- store->current_folder = NULL;
-
- return CAMEL_SERVICE_CLASS (remote_store_class)->disconnect (service, clean, ex);
-}
-
-static gboolean
-imap_folder_exists (CamelImapStore *store, const char *folder_name,
- gboolean *selectable, char **short_name,
- CamelException *ex)
-{
- CamelImapResponse *response;
- char *result, sep;
- int flags;
-
- if (!g_strcasecmp (folder_name, "INBOX")) {
- if (selectable)
- *selectable = TRUE;
- if (short_name)
- *short_name = g_strdup ("INBOX");
- return TRUE;
- }
-
- response = camel_imap_command (store, NULL, ex, "LIST \"\" \"%s\"",
- folder_name);
- if (!response)
- return FALSE;
- result = camel_imap_response_extract (response, "LIST", ex);
- if (!result)
- return FALSE;
-
- if (!imap_parse_list_response (result, &flags, &sep, NULL))
- return FALSE;
-
- if (selectable)
- *selectable = !(flags & IMAP_LIST_FLAG_NOSELECT);
- if (short_name) {
- *short_name = strrchr (folder_name, sep);
- if (*short_name)
- *short_name = g_strdup (*short_name + 1);
- else
- *short_name = g_strdup (folder_name);
- }
-
- return TRUE;
-}
-
-static gboolean
-imap_create (CamelImapStore *store, const char *folder_name,
- CamelException *ex)
-{
- CamelImapResponse *response;
-
- response = camel_imap_command (store, NULL, ex, "CREATE \"%s\"",
- folder_name);
- camel_imap_response_free (response);
-
- return !camel_exception_is_set (ex);
-}
-
-static CamelFolder *
-get_folder (CamelStore *store, const char *folder_name, guint32 flags,
- CamelException *ex)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelFolder *new_folder = NULL;
- char *short_name, *summary_file, *p;
- gboolean selectable;
-
- if (!imap_folder_exists (imap_store, folder_name,
- &selectable, &short_name, ex)) {
- if ((flags & CAMEL_STORE_FOLDER_CREATE) == 0)
- return NULL;
-
- if (!imap_create (imap_store, folder_name, ex))
- return NULL;
-
- if (!imap_folder_exists (imap_store, folder_name,
- &selectable, &short_name, ex))
- return NULL;
- }
-
- if (!selectable) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
- "%s is not a selectable folder",
- folder_name);
- g_free (short_name);
- return NULL;
- }
-
- summary_file = g_strdup_printf ("%s/%s/#summary",
- imap_store->storage_path,
- folder_name);
- p = strrchr (summary_file, '/');
- *p = '\0';
- if (e_mkdir_hier (summary_file, S_IRWXU) == 0) {
- *p = '/';
- new_folder = camel_imap_folder_new (store, folder_name,
- short_name, summary_file,
- ex);
- } else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Could not create directory %s: %s"),
- summary_file, g_strerror (errno));
- }
- g_free (summary_file);
- g_free (short_name);
-
- if (camel_exception_is_set (ex))
- return NULL;
-
- return new_folder;
-}
-
-static char *
-get_folder_name (CamelStore *store, const char *folder_name,
- CamelException *ex)
-{
- /* INBOX is case-insensitive */
- if (g_strcasecmp (folder_name, "INBOX") == 0)
- return g_strdup ("INBOX");
- else
- return g_strdup (folder_name);
-}
-
-static char *
-get_root_folder_name (CamelStore *store, CamelException *ex)
-{
- return g_strdup ("");
-}
-
-static CamelFolderInfo *
-parse_list_response_as_folder_info (CamelImapStore *imap_store,
- const char *response)
-{
- CamelFolderInfo *fi;
- int flags;
- char sep, *dir, *name;
-
- if (!imap_parse_list_response (response, &flags, &sep, &dir))
- return NULL;
-
- if (sep) {
- name = strrchr (dir, sep);
- if (name && !*++name) {
- g_free (dir);
- return NULL;
- }
- }
-
- fi = g_new0 (CamelFolderInfo, 1);
- fi->full_name = dir;
- if (sep && name)
- fi->name = g_strdup (name);
- else
- fi->name = g_strdup (dir);
- if (!(flags & IMAP_LIST_FLAG_NOSELECT))
- fi->url = g_strdup_printf ("%s%s", imap_store->base_url, dir);
-
- return fi;
-}
-
-static CamelFolderInfo *
-get_folder_info (CamelStore *store, const char *top, gboolean fast,
- gboolean recursive, gboolean subscribed_only,
- CamelException *ex)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelURL *url = CAMEL_SERVICE (store)->url;
- gboolean need_inbox = FALSE;
- int i;
- CamelImapResponse *response;
- GPtrArray *folders;
- const char *name;
- char *pattern, *list;
- char *status, *p;
- CamelFolderInfo *topfi, *fi;
-
- name = top;
- if (!name) {
- need_inbox = !subscribed_only;
- if (url->path)
- name = url->path + 1;
- else
- name = "";
- }
- response = camel_imap_command (imap_store, NULL, ex,
- "LIST \"\" \"%s\"", name);
- if (!response)
- return FALSE;
- list = camel_imap_response_extract (response, "LIST", ex);
- if (!list)
- return FALSE;
- topfi = parse_list_response_as_folder_info (imap_store, list);
- g_free (list);
- if (!topfi) {
- topfi = g_new0 (CamelFolderInfo, 1);
- topfi->full_name = g_strdup (name);
- topfi->name = g_strdup (name);
- }
-
- if (!top && subscribed_only)
- pattern = g_strdup ("");
- else if (*name)
- pattern = g_strdup_printf ("%s%c", name, imap_store->dir_sep);
- else
- pattern = g_strdup (name);
- response = camel_imap_command (imap_store, NULL, ex,
- "%s \"\" \"%s%c\"",
- subscribed_only ? "LSUB" : "LIST",
- pattern, recursive ? '*' : '%');
- g_free (pattern);
- if (!response)
- return NULL;
-
- if (subscribed_only) {
- g_hash_table_foreach_remove (imap_store->subscribed_folders,
- free_sub, NULL);
- }
-
- /* Turn responses into CamelFolderInfo and remove any
- * extraneous responses.
- */
- folders = g_ptr_array_new ();
- for (i = 0; i < response->untagged->len; i++) {
- list = response->untagged->pdata[i];
- fi = parse_list_response_as_folder_info (imap_store, list);
- if (!fi)
- continue;
- g_ptr_array_add (folders, fi);
-
- if (subscribed_only) {
- g_hash_table_insert (imap_store->subscribed_folders,
- g_strdup (fi->full_name),
- GUINT_TO_POINTER (1));
- }
-
- if (!g_strcasecmp (fi->full_name, "INBOX"))
- need_inbox = FALSE;
- }
- camel_imap_response_free (response);
-
- /* Add INBOX, if necessary */
- if (need_inbox) {
- fi = g_new0 (CamelFolderInfo, 1);
- fi->full_name = g_strdup ("INBOX");
- fi->name = g_strdup ("INBOX");
- fi->url = g_strdup_printf ("%sINBOX", imap_store->base_url);
-
- g_ptr_array_add (folders, fi);
- }
-
- if (!fast) {
- /* Get read/unread counts */
- for (i = 0; i < folders->len; i++) {
- fi = folders->pdata[i];
- if (!fi->url)
- continue;
-
- response = camel_imap_command (
- imap_store, NULL, NULL,
- "STATUS \"%s\" (MESSAGES UNSEEN)",
- fi->full_name);
- if (!response)
- continue;
- status = camel_imap_response_extract (
- response, "STATUS", NULL);
- if (!status)
- continue;
-
- p = e_strstrcase (status, "MESSAGES");
- if (p)
- fi->message_count = strtoul (p + 8, NULL, 10);
- p = e_strstrcase (status, "UNSEEN");
- if (p)
- fi->unread_message_count = strtoul (p + 6, NULL, 10);
- g_free (status);
- }
- }
-
- /* And assemble */
- camel_folder_info_build (folders, topfi, imap_store->dir_sep, TRUE);
- g_ptr_array_free (folders, TRUE);
-
- /* Remove the top if it's the root of the store. */
- if (!top && !topfi->sibling && !topfi->url) {
- fi = topfi;
- topfi = topfi->child;
- fi->child = NULL;
- camel_folder_info_free (fi);
- for (fi = topfi; fi; fi = fi->sibling)
- fi->parent = NULL;
- }
-
- return topfi;
-}
-
-static gboolean
-folder_subscribed (CamelStore *store, const char *folder_name)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
-
- return g_hash_table_lookup (imap_store->subscribed_folders,
- folder_name) != NULL;
-}
-
-static void
-subscribe_folder (CamelStore *store, const char *folder_name,
- CamelException *ex)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelImapResponse *response;
-
- response = camel_imap_command (imap_store, NULL, ex,
- "SUBSCRIBE \"%s\"", folder_name);
- if (response) {
- g_hash_table_insert (imap_store->subscribed_folders,
- g_strdup (folder_name),
- GUINT_TO_POINTER (1));
- }
- camel_imap_response_free (response);
-}
-
-static void
-unsubscribe_folder (CamelStore *store, const char *folder_name,
- CamelException *ex)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelImapResponse *response;
- gpointer key, value;
-
- response = camel_imap_command (imap_store, NULL, ex,
- "UNSUBSCRIBE \"%s\"", folder_name);
- if (response) {
- g_hash_table_lookup_extended (imap_store->subscribed_folders,
- folder_name, key, value);
- g_hash_table_remove (imap_store->subscribed_folders,
- folder_name);
- g_free (key);
- }
- camel_imap_response_free (response);
-}
-
-static void
-imap_keepalive (CamelRemoteStore *store)
-{
- CamelImapStore *imap_store = CAMEL_IMAP_STORE (store);
- CamelImapResponse *response;
-
- response = camel_imap_command (imap_store, NULL, NULL, "NOOP");
- camel_imap_response_free (response);
-}
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
deleted file mode 100644
index 8fd996c420..0000000000
--- a/camel/providers/imap/camel-imap-store.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-imap-store.h : class for an imap store */
-
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-
-#ifndef CAMEL_IMAP_STORE_H
-#define CAMEL_IMAP_STORE_H 1
-
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include "camel-remote-store.h"
-
-#define CAMEL_IMAP_STORE_TYPE (camel_imap_store_get_type ())
-#define CAMEL_IMAP_STORE(obj) (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_STORE_TYPE, CamelImapStore))
-#define CAMEL_IMAP_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STORE_TYPE, CamelImapStoreClass))
-#define IS_CAMEL_IMAP_STORE(o) (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_STORE_TYPE))
-
-typedef enum {
- IMAP_LEVEL_UNKNOWN,
- IMAP_LEVEL_IMAP4,
- IMAP_LEVEL_IMAP4REV1
-} CamelImapServerLevel;
-
-#define IMAP_CAPABILITY_IMAP4 (1 << 0)
-#define IMAP_CAPABILITY_IMAP4REV1 (1 << 1)
-#define IMAP_CAPABILITY_STATUS (1 << 2)
-#define IMAP_CAPABILITY_NAMESPACE (1 << 3)
-#define IMAP_CAPABILITY_AUTH_KERBEROS_V4 (1 << 4)
-#define IMAP_CAPABILITY_AUTH_GSSAPI (1 << 5)
-#define IMAP_CAPABILITY_UIDPLUS (1 << 6)
-#define IMAP_CAPABILITY_LITERALPLUS (1 << 7)
-
-typedef struct {
- CamelRemoteStore parent_object;
-
- CamelFolder *current_folder;
-
- guint32 command;
-
- CamelImapServerLevel server_level;
- guint32 capabilities;
-
- gchar dir_sep, *storage_path, *base_url;
-
- gboolean connected;
-
- GHashTable *subscribed_folders;
-} CamelImapStore;
-
-
-typedef struct {
- CamelRemoteStoreClass parent_class;
-
-} CamelImapStoreClass;
-
-
-/* Standard Camel function */
-CamelType camel_imap_store_get_type (void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_IMAP_STORE_H */
diff --git a/camel/providers/imap/camel-imap-stream.c b/camel/providers/imap/camel-imap-stream.c
deleted file mode 100644
index 4e9ee046d7..0000000000
--- a/camel/providers/imap/camel-imap-stream.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-
-#include <config.h>
-#include "camel-imap-stream.h"
-#include "camel/camel-exception.h"
-#include <sys/types.h>
-#include <errno.h>
-#include <stdlib.h>
-
-static CamelStreamClass *parent_class = NULL;
-
-/* Returns the class for a CamelImapStream */
-#define CIS_CLASS(so) CAMEL_IMAP_STREAM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n);
-static int stream_reset (CamelStream *stream);
-static gboolean stream_eos (CamelStream *stream);
-
-static void finalize (CamelObject *object);
-
-static void
-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;
- camel_stream_class->eos = stream_eos;
-}
-
-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;
-}
-
-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),
- sizeof (CamelImapStreamClass),
- (CamelObjectClassInitFunc) camel_imap_stream_class_init,
- NULL,
- (CamelObjectInitFunc) camel_imap_stream_init,
- (CamelObjectFinalizeFunc) finalize);
- }
-
- return camel_imap_stream_type;
-}
-
-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));
-
- imap_stream->command = g_strdup (command);
-
- return CAMEL_STREAM (imap_stream);
-}
-
-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));
-}
-
-static ssize_t
-stream_read (CamelStream *stream, char *buffer, size_t n)
-{
- ssize_t nread;
-
- /* 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);
- CamelException ex;
- gchar *result, *p, *q;
- gint status, part_len;
-
- camel_exception_init (&ex);
- status = camel_imap_fetch_command (CAMEL_IMAP_STORE (folder->parent_store),
- CAMEL_FOLDER (imap_stream->folder),
- &result, &ex, "%s\r\n",
- imap_stream->command);
- /* FIXME: exception is ignored */
- camel_exception_clear (&ex);
-
- if (!result || status != CAMEL_IMAP_OK) {
- /* we got an error, dump this stuff */
- g_free (result);
- imap_stream->cache = NULL;
- camel_object_unref (CAMEL_OBJECT (imap_stream->folder));
-
- return -1;
- }
-
- /* 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 != '"' && *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;
- }
-
- /* advance to the beginning of the actual data */
- p++;
-
- /* 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;
- }
-
- imap_stream->cache = g_strndup (p, part_len);
- g_free (result);
-
- imap_stream->cache_ptr = imap_stream->cache;
- }
-
- /* we've already read this stream, so return whats in the cache */
- nread = MIN (n, strlen (imap_stream->cache_ptr));
-
- if (nread > 0) {
- memcpy (buffer, imap_stream->cache_ptr, nread);
- imap_stream->cache_ptr += nread;
- } else {
- nread = -1;
- }
-
- return nread;
-}
-
-static int
-stream_reset (CamelStream *stream)
-{
- CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream);
-
- imap_stream->cache_ptr = imap_stream->cache;
-
- return 1;
-}
-
-static gboolean
-stream_eos (CamelStream *stream)
-{
- CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream);
-
- return (imap_stream->cache_ptr && strlen (imap_stream->cache_ptr));
-}
diff --git a/camel/providers/imap/camel-imap-stream.h b/camel/providers/imap/camel-imap-stream.h
deleted file mode 100644
index 88881e7c1f..0000000000
--- a/camel/providers/imap/camel-imap-stream.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-
-#ifndef CAMEL_IMAP_STREAM_H
-#define CAMEL_IMAP_STREAM_H
-
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include <camel/camel-stream.h>
-#include "camel-imap-folder.h"
-#include "camel-imap-store.h"
-#include <sys/types.h>
-
-#define CAMEL_IMAP_STREAM_TYPE (camel_imap_stream_get_type ())
-#define CAMEL_IMAP_STREAM(obj) (CAMEL_CHECK_CAST((obj), CAMEL_IMAP_STREAM_TYPE, CamelImapStream))
-#define CAMEL_IMAP_STREAM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STREAM_TYPE, CamelImapStreamClass))
-#define CAMEL_IS_IMAP_STREAM(o) (CAMEL_CHECK_TYPE((o), CAMEL_IMAP_STREAM_TYPE))
-
-typedef struct _CamelImapStream CamelImapStream;
-typedef struct _CamelImapStreamClass CamelImapStreamClass;
-
-struct _CamelImapStream {
- CamelStream parent_object;
-
- CamelImapFolder *folder;
- char *command;
- char *cache;
- char *cache_ptr;
-};
-
-struct _CamelImapStreamClass {
- CamelStreamClass parent_class;
-
- /* Virtual methods */
-};
-
-/* Standard Camel function */
-CamelType camel_imap_stream_get_type (void);
-
-/* public methods */
-CamelStream *camel_imap_stream_new (CamelImapFolder *folder, char *command);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_IMAP_STREAM_H */
diff --git a/camel/providers/imap/camel-imap-summary.c b/camel/providers/imap/camel-imap-summary.c
deleted file mode 100644
index ebdf8b9842..0000000000
--- a/camel/providers/imap/camel-imap-summary.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2000 Helix Code Inc.
- *
- * Authors:
- * Michael Zucchi <notzed@helixcode.com>
- * Dan Winship <danw@helixcode.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#include "camel-imap-summary.h"
-#include <camel/camel-mime-message.h>
-
-#include <sys/stat.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#define CAMEL_IMAP_SUMMARY_VERSION (0x1000)
-
-static int summary_header_load (CamelFolderSummary *, FILE *);
-static int summary_header_save (CamelFolderSummary *, FILE *);
-
-static void camel_imap_summary_class_init (CamelImapSummaryClass *klass);
-static void camel_imap_summary_init (CamelImapSummary *obj);
-
-static CamelFolderSummaryClass *camel_imap_summary_parent;
-
-CamelType
-camel_imap_summary_get_type (void)
-{
- static CamelType type = CAMEL_INVALID_TYPE;
-
- if (type == CAMEL_INVALID_TYPE) {
- type = camel_type_register(
- camel_folder_summary_get_type(), "CamelImapSummary",
- sizeof (CamelImapSummary),
- sizeof (CamelImapSummaryClass),
- (CamelObjectClassInitFunc) camel_imap_summary_class_init,
- NULL,
- (CamelObjectInitFunc) camel_imap_summary_init,
- NULL);
- }
-
- return type;
-}
-
-static void
-camel_imap_summary_class_init (CamelImapSummaryClass *klass)
-{
- CamelFolderSummaryClass *cfs_class = (CamelFolderSummaryClass *) klass;
-
- camel_imap_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type()));
-
- cfs_class->summary_header_load = summary_header_load;
- cfs_class->summary_header_save = summary_header_save;
-}
-
-static void
-camel_imap_summary_init (CamelImapSummary *obj)
-{
- CamelFolderSummary *s = (CamelFolderSummary *)obj;
-
- /* subclasses need to set the right instance data sizes */
- s->message_info_size = sizeof(CamelImapMessageInfo);
- s->content_info_size = sizeof(CamelImapMessageContentInfo);
-
- /* and a unique file version */
- s->version += CAMEL_IMAP_SUMMARY_VERSION;
-}
-
-/**
- * camel_imap_summary_new:
- * @filename: the file to store the summary in.
- * @validity: the current UIDVALIDITY value of the folder
- *
- * This will create a new CamelImapSummary object and read in the
- * summary data from disk, if it exists and has the right UIDVALIDITY
- * value.
- *
- * Return value: A new CamelImapSummary object.
- **/
-CamelFolderSummary *
-camel_imap_summary_new (const char *filename, guint32 validity)
-{
- CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (
- camel_object_new (camel_imap_summary_get_type ()));
- CamelImapSummary *imap_summary = (CamelImapSummary *)summary;
-
- camel_folder_summary_set_build_content (summary, FALSE);
- camel_folder_summary_set_filename (summary, filename);
-
- if (camel_folder_summary_load (summary) == -1) {
- if (errno == ENOENT) {
- imap_summary->validity = validity;
- return summary;
- } else {
- camel_object_unref ((CamelObject *)summary);
- return NULL;
- }
- }
- if (imap_summary->validity != validity) {
- camel_folder_summary_clear (summary);
- imap_summary->validity = validity;
- }
-
- return summary;
-}
-
-
-static int
-summary_header_load (CamelFolderSummary *s, FILE *in)
-{
- CamelImapSummary *ims = CAMEL_IMAP_SUMMARY (s);
-
- if (camel_imap_summary_parent->summary_header_load (s, in) == -1)
- return -1;
-
- return camel_folder_summary_decode_uint32 (in, &ims->validity);
-}
-
-static int
-summary_header_save (CamelFolderSummary *s, FILE *out)
-{
- CamelImapSummary *ims = CAMEL_IMAP_SUMMARY(s);
-
- if (camel_imap_summary_parent->summary_header_save (s, out) == -1)
- return -1;
-
- return camel_folder_summary_encode_uint32 (out, ims->validity);
-}
diff --git a/camel/providers/imap/camel-imap-summary.h b/camel/providers/imap/camel-imap-summary.h
deleted file mode 100644
index 0b844fdd7e..0000000000
--- a/camel/providers/imap/camel-imap-summary.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2000 Helix Code Inc.
- *
- * Authors:
- * Michael Zucchi <notzed@helixcode.com>
- * Dan Winship <danw@helixcode.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef _CAMEL_IMAP_SUMMARY_H
-#define _CAMEL_IMAP_SUMMARY_H
-
-#include <camel/camel-folder-summary.h>
-#include <camel/camel-exception.h>
-
-#define CAMEL_IMAP_SUMMARY(obj) CAMEL_CHECK_CAST (obj, camel_imap_summary_get_type (), CamelImapSummary)
-#define CAMEL_IMAP_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_imap_summary_get_type (), CamelImapSummaryClass)
-#define CAMEL_IS_IMAP_SUMMARY(obj) CAMEL_CHECK_TYPE (obj, camel_imap_summary_get_type ())
-
-typedef struct _CamelImapSummary CamelImapSummary;
-typedef struct _CamelImapSummaryClass CamelImapSummaryClass;
-
-typedef struct _CamelImapMessageContentInfo {
- CamelMessageContentInfo info;
-
-} CamelImapMessageContentInfo;
-
-typedef struct _CamelImapMessageInfo {
- CamelMessageInfo info;
-
-} CamelImapMessageInfo;
-
-struct _CamelImapSummary {
- CamelFolderSummary parent;
-
- guint32 validity;
-};
-
-struct _CamelImapSummaryClass {
- CamelFolderSummaryClass parent_class;
-
-};
-
-guint camel_imap_summary_get_type (void);
-CamelFolderSummary *camel_imap_summary_new (const char *filename,
- guint32 validity);
-
-#endif /* ! _CAMEL_IMAP_SUMMARY_H */
-
diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
deleted file mode 100644
index b38024ecc6..0000000000
--- a/camel/providers/imap/camel-imap-utils.c
+++ /dev/null
@@ -1,688 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#include <gtk/gtk.h>
-#include "camel-imap-utils.h"
-#include "string-utils.h"
-#include <e-sexp.h>
-#include "camel/camel-folder-summary.h"
-
-#define d(x) x
-
-char *
-imap_next_word (const char *buf)
-{
- char *word;
-
- /* skip over current word */
- for (word = (char *)buf; *word && *word != ' '; word++);
-
- /* skip over white space */
- for ( ; *word && *word == ' '; word++);
-
- return word;
-}
-
-/**
- * imap_parse_list_response:
- * @buf: the LIST or LSUB response
- * @flags: a pointer to a variable to store the flags in, or %NULL
- * @sep: a pointer to a variable to store the hierarchy separator in, or %NULL
- * @folder: a pointer to a variable to store the folder name in, or %NULL
- *
- * Parses a LIST or LSUB response and returns the desired parts of it.
- * If @folder is non-%NULL, its value must be freed by the caller.
- *
- * Return value: whether or not the response was successfully parsed.
- **/
-gboolean
-imap_parse_list_response (const char *buf, int *flags, char *sep, char **folder)
-{
- char *word;
- int len;
-
- if (*buf != '*')
- return FALSE;
-
- word = imap_next_word (buf);
- if (g_strncasecmp (word, "LIST", 4) && g_strncasecmp (word, "LSUB", 4))
- return FALSE;
-
- /* get the flags */
- word = imap_next_word (word);
- if (*word != '(')
- return FALSE;
-
- if (flags)
- *flags = 0;
-
- word++;
- while (*word != ')') {
- len = strcspn (word, " )");
- if (flags) {
- if (!g_strncasecmp (word, "\\Noinferiors", len))
- *flags |= IMAP_LIST_FLAG_NOINFERIORS;
- else if (!g_strncasecmp (word, "\\Noselect", len))
- *flags |= IMAP_LIST_FLAG_NOSELECT;
- else if (!g_strncasecmp (word, "\\Marked", len))
- *flags |= IMAP_LIST_FLAG_MARKED;
- else if (!g_strncasecmp (word, "\\Unmarked", len))
- *flags |= IMAP_LIST_FLAG_UNMARKED;
- }
-
- word += len;
- while (*word == ' ')
- word++;
- }
-
- /* get the directory separator */
- word = imap_next_word (word);
- if (!strncmp (word, "NIL", 3)) {
- if (sep)
- *sep = '\0';
- } else if (*word++ == '"') {
- if (*word == '\\')
- word++;
- if (sep)
- *sep = *word;
- word++;
- if (*word++ != '"')
- return FALSE;
- } else
- return FALSE;
-
- if (folder) {
- /* get the folder name */
- word = imap_next_word (word);
- *folder = imap_parse_astring (&word, &len);
- return *folder != NULL;
- }
-
- return TRUE;
-}
-
-static ESExpResult *
-func_and (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- ESExpResult *r;
-
- d(fprintf (stderr, "in AND func (argc = %d)\n", argc));
- if (argc > 0) {
- char **strings;
- int i;
-
- strings = g_new (char*, argc+1);
- strings[argc] = NULL;
-
- for (i = 0; i < argc; i++) {
- GList *list_head = *list;
-
- d(fprintf (stderr, "\tAND func: %s\n", (*list) ? (char *) (*list)->data : "(null)"));
- strings[argc - (i+1)] = (*list) ? (*list)->data : g_strdup ("");
- *list = g_list_remove_link (*list, *list);
- g_list_free_1 (list_head);
- }
-
- *list = g_list_prepend (*list, g_strjoinv (" ", strings));
- d(fprintf (stderr, "%s\n", (char *) (*list)->data));
-
- for (i = 0 ; i < argc; i ++)
- g_free (strings[i]);
-
- g_free (strings);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_or (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- ESExpResult *r;
-
- d(fprintf (stderr, "in OR func (argc = %d)\n", argc));
- if (argc == 2 && (*list)->data && (*list)->next && (*list)->next->data) {
- char **strings;
- int i;
-
- strings = g_new (char*, argc+2);
- strings[0] = g_strdup ("OR");
- strings[argc+2 - 1] = NULL;
-
- for (i = 0; i < 2; i++) {
- GList *list_head = *list;
-
- d(fprintf (stderr, "\tOR func: %s\n", (*list) ? (char *) (*list)->data : "(null)"));
- strings[argc - i] = (*list) ? (*list)->data : g_strdup ("");
- *list = g_list_remove_link (*list, *list);
- g_list_free_1 (list_head);
- }
-
- *list = g_list_prepend (*list, g_strjoinv (" ", strings));
- d(fprintf (stderr, "%s\n", (char *) (*list)->data));
-
- for (i = 0 ; i < argc + 2; i ++)
- g_free (strings[i]);
-
- g_free (strings);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_not (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- ESExpResult *r;
-
- d(fprintf (stderr, "in NOT func\n"));
- /* just replace the head of the list with the NOT of it. */
- if (argc > 0) {
- char *term = (*list)->data;
-
- (*list)->data = g_strdup_printf ("NOT %s", term);
- d(fprintf (stderr, "%s\n", (char *) (*list)->data));
- g_free (term);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static char *tz_months [] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-static char *
-format_date (time_t time, int offset)
-{
- struct tm tm;
-
- time += ((offset / 100) * (60*60)) + (offset % 100)*60;
-
- d(printf("converting date %s", ctime (&time)));
-
- memcpy (&tm, gmtime (&time), sizeof (tm));
-
- return g_strdup_printf ("%d-%s-%04d",
- tm.tm_mday, tz_months[tm.tm_mon],
- tm.tm_year + 1900);
-}
-
-static ESExpResult *
-func_lt (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- char *type = (*list)->data;
- time_t date = (time_t) (argv[1])->value.number;
- ESExpResult *r;
-
- d(fprintf (stderr, "in less-than func: (%d) (%s) (%d)\n", argc, type, (int) date));
- if (argc > 0) {
- char *string, *date_str;
-
- date_str = format_date (date, 0);
-
- if (!strcmp ("SENT", type)) {
- string = g_strdup_printf ("SENTBEFORE \"%s\"", date_str);
- } else {
- string = g_strdup_printf ("BEFORE \"%s\"", date_str);
- }
-
- (*list)->data = string;
- g_free (type);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_gt (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- char *type = (*list)->data;
- time_t date = (time_t) (argv[1])->value.number;
- ESExpResult *r;
-
- d(fprintf (stderr, "in greater-than func: (%d) (%s) (%d)\n", argc, type, (int) date));
- if (argc > 0) {
- char *string, *date_str;
-
- date_str = format_date (date, 0);
-
- if (!strcmp ("SENT", type)) {
- string = g_strdup_printf ("SENTSINCE \"%s\"", date_str);
- } else {
- string = g_strdup_printf ("SINCE \"%s\"", date_str);
- }
-
- (*list)->data = string;
- g_free (type);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_eq (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- char *type = (*list)->data;
- time_t date = (time_t) (argv[1])->value.number;
- ESExpResult *r;
-
- d(fprintf (stderr, "in equal-to func: (%d) (%s) (%d)\n", argc, type, (int) date));
- if (argc > 0) {
- char *string, *date_str;
-
- date_str = format_date (date, 0);
-
- if (!strcmp ("SENT", type)) {
- string = g_strdup_printf ("SENTON \"%s\"", date_str);
- } else {
- string = g_strdup_printf ("ON \"%s\"", date_str);
- }
-
- (*list)->data = string;
- g_free (type);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_match_all (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- /* match-all doesn't have a IMAP equiv */
- ESExpResult *r;
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- char *value = (*argv)->value.string;
- ESExpResult *r;
-
- if (argc > 0) {
- char *string;
-
- string = g_strdup_printf ("BODY \"%s\"", value);
-
- *list = g_list_prepend (*list, string);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- char *header = (argv[0])->value.string;
- char *match = (argv[1])->value.string;
- ESExpResult *r;
-
- if (argc == 2) {
- char *string;
- string = g_strdup_printf ("HEADER %s \"%s\"", header, match);
-
- *list = g_list_prepend (*list, string);
- }
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_user_tag (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- /* FIXME: what do I do here? */
- ESExpResult *r;
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_user_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- /* FIXME: what do I do here? */
- ESExpResult *r;
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_get_sent_date (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- ESExpResult *r;
-
- *list = g_list_prepend (*list, g_strdup ("SENT"));
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_get_received_date (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- GList **list = data;
- ESExpResult *r;
-
- *list = g_list_prepend (*list, g_strdup ("RECEIVED"));
-
- r = e_sexp_result_new (ESEXP_RES_BOOL);
- r->value.bool = FALSE;
-
- return r;
-}
-
-static ESExpResult *
-func_get_current_date (struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
-{
- ESExpResult *r;
-
- r = e_sexp_result_new (ESEXP_RES_INT);
- r->value.number = time (NULL);
-
- return r;
-}
-
-/* builtin functions */
-static struct {
- char *name;
- ESExpFunc *func;
- int type; /* set to 1 if a function can perform shortcut evaluation, or
- doesn't execute everything, 0 otherwise */
-} symbols[] = {
- { "and", (ESExpFunc *) func_and, 0 },
- { "or", (ESExpFunc *) func_or, 0 },
- { "not", (ESExpFunc *) func_not, 0 },
- { "<", (ESExpFunc *) func_lt, 0 },
- { ">", (ESExpFunc *) func_gt, 0 },
- { "=", (ESExpFunc *) func_eq, 0 },
- { "match-all", (ESExpFunc *) func_match_all, 0 },
- { "body-contains", (ESExpFunc *) func_body_contains, 0 },
- { "header-contains", (ESExpFunc *) func_header_contains, 0 },
- { "user-tag", (ESExpFunc *) func_user_tag, 1 },
- { "user-flag", (ESExpFunc *) func_user_flag, 1 },
- { "get-sent-date", (ESExpFunc *) func_get_sent_date, 1 },
- { "get-received-date", (ESExpFunc *) func_get_received_date, 1 },
- { "get-current-date", (ESExpFunc *) func_get_current_date, 1 }
-};
-
-char *
-imap_translate_sexp (const char *expression)
-{
- ESExp *sexp;
- ESExpResult *r;
- gchar *retval;
- GList *list = NULL;
- int i;
-
- sexp = e_sexp_new ();
-
- for (i = 0; i < sizeof (symbols) / sizeof (symbols[0]); i++) {
- if (symbols[i].type == 1) {
- e_sexp_add_ifunction (sexp, 0, symbols[i].name,
- (ESExpIFunc *)symbols[i].func, &list);
- } else {
- e_sexp_add_function (sexp, 0, symbols[i].name,
- symbols[i].func, &list);
- }
- }
-
- e_sexp_input_text (sexp, expression, strlen (expression));
-
- e_sexp_parse (sexp);
-
- r = e_sexp_eval (sexp);
-
- gtk_object_unref (GTK_OBJECT (sexp));
- e_sexp_result_free (r);
-
- if (list->next) {
- g_warning ("conversion to IMAP SEARCH string failed");
- retval = NULL;
- g_list_foreach (list, (GFunc)g_free, NULL);
- } else {
- retval = list->data;
- }
-
- g_list_free (list);
-
- return retval;
-}
-
-char *
-imap_create_flag_list (guint32 flags)
-{
- GString *gstr;
- char *flag_list;
-
- gstr = g_string_new ("(");
-
- if (flags & CAMEL_MESSAGE_ANSWERED)
- g_string_append (gstr, "\\Answered ");
- if (flags & CAMEL_MESSAGE_DELETED)
- g_string_append (gstr, "\\Deleted ");
- if (flags & CAMEL_MESSAGE_DRAFT)
- g_string_append (gstr, "\\Draft ");
- if (flags & CAMEL_MESSAGE_FLAGGED)
- g_string_append (gstr, "\\Flagged ");
- if (flags & CAMEL_MESSAGE_SEEN)
- g_string_append (gstr, "\\Seen ");
-
- if (gstr->str[gstr->len - 1] == ' ')
- gstr->str[gstr->len - 1] = ')';
- else
- g_string_append_c (gstr, ')');
-
- flag_list = gstr->str;
- g_string_free (gstr, FALSE);
- return flag_list;
-}
-
-guint32
-imap_parse_flag_list (const char *flag_list)
-{
- guint32 flags = 0;
- int len;
-
- if (*flag_list++ != '(')
- return 0;
-
- while (*flag_list != ')') {
- len = strcspn (flag_list, " )");
- if (!g_strncasecmp (flag_list, "\\Answered", len))
- flags |= CAMEL_MESSAGE_ANSWERED;
- else if (!g_strncasecmp (flag_list, "\\Deleted", len))
- flags |= CAMEL_MESSAGE_DELETED;
- else if (!g_strncasecmp (flag_list, "\\Draft", len))
- flags |= CAMEL_MESSAGE_DRAFT;
- else if (!g_strncasecmp (flag_list, "\\Flagged", len))
- flags |= CAMEL_MESSAGE_FLAGGED;
- else if (!g_strncasecmp (flag_list, "\\Seen", len))
- flags |= CAMEL_MESSAGE_SEEN;
-
- flag_list += len;
- if (*flag_list == ' ')
- flag_list++;
- }
-
- return flags;
-}
-
-/**
- * imap_parse_nstring:
- * @str_p: a pointer to a string
- * @len: a pointer to an int to return the length in
- *
- * This parses an "nstring" (NIL, a quoted string, or a literal)
- * starting at *@str_p. On success, *@str_p will point to the first
- * character after the end of the nstring, and *@len will contain
- * the length of the returned string. On failure, *@str_p will be
- * set to %NULL.
- *
- * This assumes that the string is in the form returned by
- * camel_imap_command(): that line breaks are indicated by LF rather
- * than CRLF.
- *
- * Return value: the parsed string, or %NULL if a NIL or no string
- * was parsed. (In the former case, *@str_p will be %NULL; in the
- * latter, it will point to the character after the NIL.)
- **/
-char *
-imap_parse_nstring (char **str_p, int *len)
-{
- char *str = *str_p;
- char *out;
-
- if (!str)
- return NULL;
- else if (*str == '"') {
- char *p;
- int size;
-
- str++;
- size = strcspn (str, "\"") + 1;
- p = out = g_malloc (size);
-
- while (*str && *str != '"') {
- if (*str == '\\')
- str++;
- *p++ = *str++;
- if (p - out == size) {
- out = g_realloc (out, size * 2);
- p = out + size;
- size *= 2;
- }
- }
- if (*str != '"') {
- *str_p = NULL;
- g_free (out);
- return NULL;
- }
- *p = '\0';
- *str_p = str + 1;
- *len = strlen (out);
- return out;
- } else if (*str == '{') {
- *len = strtoul (str + 1, (char **)&str, 10);
- if (*str++ != '}' || *str++ != '\n' || strlen (str) < *len) {
- *str_p = NULL;
- return NULL;
- }
- out = g_strndup (str, *len);
- *str_p = str + *len;
- return out;
- } else if (!g_strncasecmp (str, "nil", 3)) {
- *str_p += 3;
- *len = 0;
- return NULL;
- } else {
- *str_p = NULL;
- return NULL;
- }
-}
-
-/**
- * imap_parse_astring:
- * @str_p: a pointer to a string
- * @len: a pointer to an int to return the length in
- *
- * This parses an "astring" (an atom, a quoted string, or a literal)
- * starting at *@str_p. On success, *@str_p will point to the first
- * character after the end of the astring, and *@len will contain
- * the length of the returned string. On failure, *@str_p will be
- * set to %NULL.
- *
- * This assumes that the string is in the form returned by
- * camel_imap_command(): that line breaks are indicated by LF rather
- * than CRLF.
- *
- * Return value: the parsed string, or %NULL if no string
- * was parsed. (In this case, *@str_p will also be %NULL.)
- **/
-char *
-imap_parse_astring (char **str_p, int *len)
-{
- char *p;
-
- if (**str_p == '{' || **str_p == '"')
- return imap_parse_nstring (str_p, len);
-
- p = *str_p;
- while (isascii ((unsigned char)*p) &&
- !strchr ("(){ \"\\%*", *p))
- p++;
-
- *len = p - *str_p;
- p = g_strndup (*str_p, *len);
- *str_p += *len;
- return p;
-}
diff --git a/camel/providers/imap/camel-imap-utils.h b/camel/providers/imap/camel-imap-utils.h
deleted file mode 100644
index d0cc05832d..0000000000
--- a/camel/providers/imap/camel-imap-utils.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Authors: Jeffrey Stedfast <fejj@helixcode.com>
- *
- * Copyright 2000 Helix Code, Inc. (www.helixcode.com)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
- *
- */
-
-#ifndef CAMEL_IMAP_UTILS_H
-#define CAMEL_IMAP_UTILS_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include <glib.h>
-
-char *imap_next_word (const char *buf);
-
-#define IMAP_LIST_FLAG_NOINFERIORS (1 << 0)
-#define IMAP_LIST_FLAG_NOSELECT (1 << 1)
-#define IMAP_LIST_FLAG_MARKED (1 << 2)
-#define IMAP_LIST_FLAG_UNMARKED (1 << 3)
-gboolean imap_parse_list_response (const char *buf, int *flags, char *sep, char **folder);
-
-char *imap_translate_sexp (const char *expression);
-
-char *imap_create_flag_list (guint32 flags);
-guint32 imap_parse_flag_list (const char *flag_list);
-
-char *imap_parse_nstring (char **str_p, int *len);
-char *imap_parse_astring (char **str_p, int *len);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_IMAP_UTILS_H */
diff --git a/camel/providers/imap/libcamelimap.urls b/camel/providers/imap/libcamelimap.urls
deleted file mode 100644
index c301c0ffac..0000000000
--- a/camel/providers/imap/libcamelimap.urls
+++ /dev/null
@@ -1 +0,0 @@
-imap