aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/pop3
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/pop3')
-rw-r--r--camel/providers/pop3/.cvsignore10
-rw-r--r--camel/providers/pop3/Makefile.am40
-rw-r--r--camel/providers/pop3/camel-pop3-engine.c367
-rw-r--r--camel/providers/pop3/camel-pop3-engine.h127
-rw-r--r--camel/providers/pop3/camel-pop3-folder.c557
-rw-r--r--camel/providers/pop3/camel-pop3-folder.h81
-rw-r--r--camel/providers/pop3/camel-pop3-provider.c107
-rw-r--r--camel/providers/pop3/camel-pop3-store.c634
-rw-r--r--camel/providers/pop3/camel-pop3-store.h79
-rw-r--r--camel/providers/pop3/camel-pop3-stream.c468
-rw-r--r--camel/providers/pop3/camel-pop3-stream.h69
-rw-r--r--camel/providers/pop3/libcamelpop3.urls1
12 files changed, 0 insertions, 2540 deletions
diff --git a/camel/providers/pop3/.cvsignore b/camel/providers/pop3/.cvsignore
deleted file mode 100644
index ddf4c8b28d..0000000000
--- a/camel/providers/pop3/.cvsignore
+++ /dev/null
@@ -1,10 +0,0 @@
-Makefile
-Makefile.in
-.libs
-.deps
-*.lo
-*.la
-*.bb
-*.bbg
-*.da
-*.gcov
diff --git a/camel/providers/pop3/Makefile.am b/camel/providers/pop3/Makefile.am
deleted file mode 100644
index 4ce92eac2d..0000000000
--- a/camel/providers/pop3/Makefile.am
+++ /dev/null
@@ -1,40 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-libcamelpop3includedir = $(includedir)/camel
-
-camel_provider_LTLIBRARIES = libcamelpop3.la
-camel_provider_DATA = libcamelpop3.urls
-
-INCLUDES = \
- -I.. \
- -I$(srcdir)/.. \
- -I$(srcdir)/../../.. \
- -I$(includedir) \
- -I$(top_srcdir)/intl \
- -I$(top_srcdir)/camel \
- -I$(top_srcdir)/e-util \
- $(CAMEL_CFLAGS) \
- $(GNOME_INCLUDEDIR) \
- $(KRB4_CFLAGS) \
- $(GTK_INCLUDEDIR) \
- -DG_LOG_DOMAIN=\"camel-pop3-provider\"
-
-libcamelpop3_la_SOURCES = \
- camel-pop3-engine.c \
- camel-pop3-folder.c \
- camel-pop3-provider.c \
- camel-pop3-stream.c \
- camel-pop3-store.c
-
-libcamelpop3include_HEADERS = \
- camel-pop3-engine.h \
- camel-pop3-folder.h \
- camel-pop3-stream.h \
- camel-pop3-store.h
-
-
-libcamelpop3_la_LDFLAGS = $(KRB4_LDFLAGS) -version-info 0:0:0
-
-libcamelpop3_la_LIBADD = $(top_builddir)/e-util/libeutil.la
-
-EXTRA_DIST = libcamelpop3.urls
diff --git a/camel/providers/pop3/camel-pop3-engine.c b/camel/providers/pop3/camel-pop3-engine.c
deleted file mode 100644
index 1783520b7c..0000000000
--- a/camel/providers/pop3/camel-pop3-engine.c
+++ /dev/null
@@ -1,367 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*-
- *
- * Author:
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-
-#include <glib.h>
-
-#include "camel-pop3-engine.h"
-#include "camel-pop3-stream.h"
-#include <camel/camel-service.h>
-#include <camel/camel-sasl.h>
-
-/* max 'outstanding' bytes in output stream, so we can't deadlock waiting
- for the server to accept our data when pipelining */
-#define CAMEL_POP3_SEND_LIMIT (1024)
-
-
-extern int camel_verbose_debug;
-#define dd(x) (camel_verbose_debug?(x):0)
-
-static void get_capabilities(CamelPOP3Engine *pe, int read_greeting);
-
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_POP3_ENGINE_CLASS(CAMEL_OBJECT_GET_CLASS(so))
-
-static void
-camel_pop3_engine_class_init (CamelPOP3EngineClass *camel_pop3_engine_class)
-{
- parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
-}
-
-static void
-camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass)
-{
- e_dlist_init(&pe->active);
- e_dlist_init(&pe->queue);
- e_dlist_init(&pe->done);
- pe->state = CAMEL_POP3_ENGINE_DISCONNECT;
-}
-
-static void
-camel_pop3_engine_finalise(CamelPOP3Engine *pe)
-{
- /* FIXME: Also flush/free any outstanding requests, etc */
-
- if (pe->stream)
- camel_object_unref((CamelObject *)pe->stream);
-}
-
-CamelType
-camel_pop3_engine_get_type (void)
-{
- static CamelType camel_pop3_engine_type = CAMEL_INVALID_TYPE;
-
- if (camel_pop3_engine_type == CAMEL_INVALID_TYPE) {
- camel_pop3_engine_type = camel_type_register(camel_object_get_type(),
- "CamelPOP3Engine",
- sizeof( CamelPOP3Engine ),
- sizeof( CamelPOP3EngineClass ),
- (CamelObjectClassInitFunc) camel_pop3_engine_class_init,
- NULL,
- (CamelObjectInitFunc) camel_pop3_engine_init,
- (CamelObjectFinalizeFunc) camel_pop3_engine_finalise );
- }
-
- return camel_pop3_engine_type;
-}
-
-/**
- * camel_pop3_engine_new:
- * @source: source stream
- *
- * Returns a NULL stream. A null stream is always at eof, and
- * always returns success for all reads and writes.
- *
- * Return value: the stream
- **/
-CamelPOP3Engine *
-camel_pop3_engine_new(CamelStream *source)
-{
- CamelPOP3Engine *pe;
-
- pe = (CamelPOP3Engine *)camel_object_new(camel_pop3_engine_get_type ());
-
- pe->stream = (CamelPOP3Stream *)camel_pop3_stream_new(source);
- pe->state = CAMEL_POP3_ENGINE_AUTH;
-
- get_capabilities(pe, TRUE);
-
- return pe;
-}
-
-
-/**
- * camel_pop3_engine_reget_capabilities:
- * @engine: pop3 engine
- *
- * Regets server capabilities (needed after a STLS command is issued for example).
- **/
-void
-camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine)
-{
- g_return_if_fail (CAMEL_IS_POP3_ENGINE (engine));
-
- get_capabilities (engine, FALSE);
-}
-
-
-/* TODO: read implementation too?
- etc? */
-struct {
- char *cap;
- guint32 flag;
-} capa[] = {
- { "APOP" , CAMEL_POP3_CAP_APOP },
- { "TOP" , CAMEL_POP3_CAP_TOP },
- { "UIDL", CAMEL_POP3_CAP_UIDL },
- { "PIPELINING", CAMEL_POP3_CAP_PIPE },
- { "STLS", CAMEL_POP3_CAP_STLS }, /* STARTTLS */
-};
-
-static void
-cmd_capa(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
-{
- unsigned char *line, *tok, *next;
- unsigned int len;
- int ret;
- int i;
- CamelServiceAuthType *auth;
-
- dd(printf("cmd_capa\n"));
-
- do {
- ret = camel_pop3_stream_line(stream, &line, &len);
- if (ret >= 0) {
- if (strncmp(line, "SASL ", 5) == 0) {
- tok = line+5;
- dd(printf("scanning tokens '%s'\n", tok));
- while (tok) {
- next = strchr(tok, ' ');
- if (next)
- *next++ = 0;
- auth = camel_sasl_authtype(tok);
- if (auth) {
- dd(printf("got auth type '%s'\n", tok));
- pe->auth = g_list_prepend(pe->auth, auth);
- } else {
- dd(printf("unsupported auth type '%s'\n", tok));
- }
- tok = next;
- }
- } else {
- for (i=0;i<sizeof(capa)/sizeof(capa[0]);i++) {
- if (strcmp(capa[i].cap, line) == 0)
- pe->capa |= capa[i].flag;
- }
- }
- }
- } while (ret>0);
-}
-
-static void
-get_capabilities(CamelPOP3Engine *pe, int read_greeting)
-{
- CamelPOP3Command *pc;
- unsigned char *line, *apop, *apopend;
- unsigned int len;
- extern CamelServiceAuthType camel_pop3_password_authtype;
- extern CamelServiceAuthType camel_pop3_apop_authtype;
-
- if (read_greeting) {
- /* first, read the greeting */
- if (camel_pop3_stream_line(pe->stream, &line, &len) == -1
- || strncmp(line, "+OK", 3) != 0)
- return;
-
- if ((apop = strchr(line+3, '<'))
- && (apopend = strchr(apop, '>'))) {
- apopend[1] = 0;
- pe->apop = g_strdup(apop);
- pe->capa = CAMEL_POP3_CAP_APOP;
- pe->auth = g_list_append(pe->auth, &camel_pop3_apop_authtype);
- }
- }
-
- pe->auth = g_list_prepend(pe->auth, &camel_pop3_password_authtype);
-
- pc = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_capa, NULL, "CAPA\r\n");
- while (camel_pop3_engine_iterate(pe, pc) > 0)
- ;
- camel_pop3_engine_command_free(pe, pc);
-}
-
-/* returns true if the command was sent, false if it was just queued */
-static int
-engine_command_queue(CamelPOP3Engine *pe, CamelPOP3Command *pc)
-{
- if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pc->data)) > CAMEL_POP3_SEND_LIMIT)
- && pe->current != NULL) {
- e_dlist_addtail(&pe->queue, (EDListNode *)pc);
- return FALSE;
- } else {
- /* ??? */
- if (camel_stream_write((CamelStream *)pe->stream, pc->data, strlen(pc->data)) == -1) {
- e_dlist_addtail(&pe->queue, (EDListNode *)pc);
- return FALSE;
- }
-
- pe->sentlen += strlen(pc->data);
-
- pc->state = CAMEL_POP3_COMMAND_DISPATCHED;
-
- if (pe->current == NULL)
- pe->current = pc;
- else
- e_dlist_addtail(&pe->active, (EDListNode *)pc);
-
- return TRUE;
- }
-}
-
-/* returns -1 on error (sets errno), 0 when no work to do, or >0 if work remaining */
-int
-camel_pop3_engine_iterate(CamelPOP3Engine *pe, CamelPOP3Command *pcwait)
-{
- unsigned char *p;
- unsigned int len;
- CamelPOP3Command *pc, *pw, *pn;
-
- if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK)
- return 0;
-
- pc = pe->current;
- if (pc == NULL)
- return 0;
-
- /* LOCK */
-
- if (camel_pop3_stream_line(pe->stream, &pe->line, &pe->linelen) == -1)
- return -1;
-
- p = pe->line;
- switch (p[0]) {
- case '+':
- dd(printf("Got + response\n"));
- if (pc->flags & CAMEL_POP3_COMMAND_MULTI) {
- pc->state = CAMEL_POP3_COMMAND_DATA;
- camel_pop3_stream_set_mode(pe->stream, CAMEL_POP3_STREAM_DATA);
-
- if (pc->func)
- pc->func(pe, pe->stream, pc->func_data);
-
- /* Make sure we get all data before going back to command mode */
- while (camel_pop3_stream_getd(pe->stream, &p, &len) > 0)
- ;
- camel_pop3_stream_set_mode(pe->stream, CAMEL_POP3_STREAM_LINE);
- } else {
- pc->state = CAMEL_POP3_COMMAND_OK;
- }
- break;
- case '-':
- pc->state = CAMEL_POP3_COMMAND_ERR;
- break;
- default:
- /* what do we do now? f'knows! */
- g_warning("Bad server response: %s\n", p);
- errno = EIO;
- return -1;
- }
-
- e_dlist_addtail(&pe->done, (EDListNode *)pc);
- pe->sentlen -= strlen(pc->data);
-
- /* Set next command */
- pe->current = (CamelPOP3Command *)e_dlist_remhead(&pe->active);
-
- /* check the queue for sending any we can now send also */
- pw = (CamelPOP3Command *)pe->queue.head;
- pn = pw->next;
- while (pn) {
- if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pw->data)) > CAMEL_POP3_SEND_LIMIT)
- && pe->current != NULL)
- break;
-
- if (camel_stream_write((CamelStream *)pe->stream, pw->data, strlen(pw->data)) == -1)
- return -1;
-
- e_dlist_remove((EDListNode *)pw);
-
-
- pe->sentlen += strlen(pw->data);
- pw->state = CAMEL_POP3_COMMAND_DISPATCHED;
-
- if (pe->current == NULL)
- pe->current = pw;
- else
- e_dlist_addtail(&pe->active, (EDListNode *)pw);
-
- pw = pn;
- pn = pn->next;
- }
-
- /* UNLOCK */
-
- if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK)
- return 0;
-
- return pe->current==NULL?0:1;
-}
-
-CamelPOP3Command *
-camel_pop3_engine_command_new(CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, void *data, const char *fmt, ...)
-{
- CamelPOP3Command *pc;
- va_list ap;
-
- pc = g_malloc0(sizeof(*pc));
- pc->func = func;
- pc->func_data = data;
- pc->flags = flags;
-
- va_start(ap, fmt);
- pc->data = g_strdup_vprintf(fmt, ap);
- pc->state = CAMEL_POP3_COMMAND_IDLE;
-
- /* TODO: what abou write errors? */
- engine_command_queue(pe, pc);
-
- return pc;
-}
-
-void
-camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc)
-{
- if (pe->current != pc)
- e_dlist_remove((EDListNode *)pc);
- g_free(pc->data);
- g_free(pc);
-}
diff --git a/camel/providers/pop3/camel-pop3-engine.h b/camel/providers/pop3/camel-pop3-engine.h
deleted file mode 100644
index 6b1f0cee1e..0000000000
--- a/camel/providers/pop3/camel-pop3-engine.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2001 Ximian Inc.
- *
- * Authors: Michael Zucchi <notzed@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_POP3_ENGINE_H
-#define _CAMEL_POP3_ENGINE_H
-
-#include <camel/camel-object.h>
-#include "e-util/e-msgport.h"
-#include "camel-pop3-stream.h"
-
-#define CAMEL_POP3_ENGINE(obj) CAMEL_CHECK_CAST (obj, camel_pop3_engine_get_type (), CamelPOP3Engine)
-#define CAMEL_POP3_ENGINE_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_engine_get_type (), CamelPOP3EngineClass)
-#define CAMEL_IS_POP3_ENGINE(obj) CAMEL_CHECK_TYPE (obj, camel_pop3_engine_get_type ())
-
-typedef struct _CamelPOP3EngineClass CamelPOP3EngineClass;
-typedef struct _CamelPOP3Engine CamelPOP3Engine;
-typedef struct _CamelPOP3Command CamelPOP3Command;
-
-/* pop 3 connection states, actually since we're given a connected socket, we always start in auth state */
-typedef enum {
- CAMEL_POP3_ENGINE_DISCONNECT = 0,
- CAMEL_POP3_ENGINE_AUTH,
- CAMEL_POP3_ENGINE_TRANSACTION,
- CAMEL_POP3_ENGINE_UPDATE,
-} camel_pop3_engine_t;
-
-/* state of a command */
-typedef enum {
- CAMEL_POP3_COMMAND_IDLE = 0, /* command created or queued, not yet sent (e.g. non pipelined server) */
- CAMEL_POP3_COMMAND_DISPATCHED, /* command sent to server */
-
- /* completion codes */
- CAMEL_POP3_COMMAND_OK, /* plain ok response */
- CAMEL_POP3_COMMAND_DATA, /* processing command response */
- CAMEL_POP3_COMMAND_ERR, /* error response */
-} camel_pop3_command_t;
-
-/* flags for command types */
-enum {
- CAMEL_POP3_COMMAND_SIMPLE = 0, /* dont expect multiline response */
- CAMEL_POP3_COMMAND_MULTI = 1, /* expect multiline response */
-};
-
-/* flags for server options */
-enum {
- CAMEL_POP3_CAP_APOP = 1<<0,
- CAMEL_POP3_CAP_UIDL = 1<<1,
- CAMEL_POP3_CAP_SASL = 1<<2,
- CAMEL_POP3_CAP_TOP = 1<<3,
- CAMEL_POP3_CAP_PIPE = 1<<4,
- CAMEL_POP3_CAP_STLS = 1<<5
-};
-
-typedef void (*CamelPOP3CommandFunc)(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data);
-
-struct _CamelPOP3Command {
- struct _CamelPOP3Command *next;
- struct _CamelPOP3Command *prev;
-
- guint32 flags;
- camel_pop3_command_t state;
-
- CamelPOP3CommandFunc func;
- void *func_data;
-
- int data_size;
- char *data;
-};
-
-struct _CamelPOP3Engine {
- CamelObject parent;
-
- camel_pop3_engine_t state;
-
- GList *auth; /* authtypes supported */
-
- guint32 capa; /* capabilities */
- char *apop; /* apop time string */
-
- unsigned char *line; /* current line buffer */
- unsigned int linelen;
-
- struct _CamelPOP3Stream *stream;
-
- unsigned int sentlen; /* data sent (so we dont overflow network buffer) */
-
- EDList active; /* active commands */
- EDList queue; /* queue of waiting commands */
- EDList done; /* list of done commands, awaiting free */
-
- CamelPOP3Command *current; /* currently busy (downloading) response */
-};
-
-struct _CamelPOP3EngineClass {
- CamelObjectClass parent_class;
-};
-
-guint camel_pop3_engine_get_type (void);
-
-CamelPOP3Engine *camel_pop3_engine_new (CamelStream *source);
-
-void camel_pop3_engine_reget_capabilities (CamelPOP3Engine *engine);
-
-void camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc);
-
-int camel_pop3_engine_iterate (CamelPOP3Engine *pe, CamelPOP3Command *pc);
-
-CamelPOP3Command *camel_pop3_engine_command_new (CamelPOP3Engine *pe, guint32 flags, CamelPOP3CommandFunc func, void *data, const char *fmt, ...);
-
-#endif /* ! _CAMEL_POP3_ENGINE_H */
diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c
deleted file mode 100644
index 777f81fe9b..0000000000
--- a/camel/providers/pop3/camel-pop3-folder.c
+++ /dev/null
@@ -1,557 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-pop3-folder.c : class for a pop3 folder */
-
-/*
- * Authors:
- * Dan Winship <danw@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 2002 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include "camel-pop3-folder.h"
-#include "camel-pop3-store.h"
-#include "camel-exception.h"
-#include "camel-stream-mem.h"
-#include "camel-stream-filter.h"
-#include "camel-mime-message.h"
-#include "camel-operation.h"
-#include "camel-data-cache.h"
-
-#include <e-util/md5-utils.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-#define d(x)
-
-#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(o)))
-static CamelFolderClass *parent_class;
-
-static void pop3_finalize (CamelObject *object);
-static void pop3_refresh_info (CamelFolder *folder, CamelException *ex);
-static void pop3_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
-static gint pop3_get_message_count (CamelFolder *folder);
-static GPtrArray *pop3_get_uids (CamelFolder *folder);
-static CamelMimeMessage *pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex);
-static void pop3_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set);
-
-static void
-camel_pop3_folder_class_init (CamelPOP3FolderClass *camel_pop3_folder_class)
-{
- CamelFolderClass *camel_folder_class =
- CAMEL_FOLDER_CLASS (camel_pop3_folder_class);
-
- parent_class = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs (camel_folder_get_type ()));
-
- /* virtual method overload */
- camel_folder_class->refresh_info = pop3_refresh_info;
- camel_folder_class->sync = pop3_sync;
-
- camel_folder_class->get_message_count = pop3_get_message_count;
- camel_folder_class->get_uids = pop3_get_uids;
- camel_folder_class->free_uids = camel_folder_free_shallow;
-
- camel_folder_class->get_message = pop3_get_message;
- camel_folder_class->set_message_flags = pop3_set_message_flags;
-}
-
-CamelType
-camel_pop3_folder_get_type (void)
-{
- static CamelType camel_pop3_folder_type = CAMEL_INVALID_TYPE;
-
- if (!camel_pop3_folder_type) {
- camel_pop3_folder_type = camel_type_register (CAMEL_FOLDER_TYPE, "CamelPOP3Folder",
- sizeof (CamelPOP3Folder),
- sizeof (CamelPOP3FolderClass),
- (CamelObjectClassInitFunc) camel_pop3_folder_class_init,
- NULL,
- NULL,
- (CamelObjectFinalizeFunc) pop3_finalize);
- }
-
- return camel_pop3_folder_type;
-}
-
-void
-pop3_finalize (CamelObject *object)
-{
- CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (object);
- CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_folder->uids->pdata;
- int i;
-
- for (i=0;i<pop3_folder->uids->len;i++,fi++) {
- g_free(fi[0]->uid);
- g_free(fi[0]);
- }
-
- g_ptr_array_free(pop3_folder->uids, TRUE);
-}
-
-CamelFolder *
-camel_pop3_folder_new (CamelStore *parent, CamelException *ex)
-{
- CamelFolder *folder;
-
- d(printf("opening pop3 INBOX folder\n"));
-
- folder = CAMEL_FOLDER (camel_object_new (CAMEL_POP3_FOLDER_TYPE));
- camel_folder_construct (folder, parent, "inbox", "inbox");
-
- /* mt-ok, since we dont have the folder-lock for new() */
- camel_folder_refresh_info (folder, ex);/* mt-ok */
- if (camel_exception_is_set (ex)) {
- camel_object_unref (CAMEL_OBJECT (folder));
- folder = NULL;
- }
-
- return folder;
-}
-
-static CamelPOP3FolderInfo *
-id_to_fi(CamelPOP3Folder *folder, guint32 id)
-{
- int i;
- CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)folder->uids->pdata;
- int len = folder->uids->len;
-
- for (i=0;i<len;i++, fi++)
- if (fi[0]->id == id)
- return fi[0];
-
- return NULL;
-}
-
-static CamelPOP3FolderInfo *
-uid_to_fi(CamelPOP3Folder *folder, const char *uid)
-{
- int i;
- CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)folder->uids->pdata;
- int len = folder->uids->len;
-
- for (i=0;i<len;i++,fi++)
- if (fi[0]->uid && strcmp(fi[0]->uid, uid) == 0)
- return fi[0];
-
- return NULL;
-}
-
-static int
-fi_to_index(CamelPOP3Folder *folder, CamelPOP3FolderInfo *fin)
-{
- int i;
- CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)folder->uids->pdata;
- int len = folder->uids->len;
-
- for (i=0;i<len;i++,fi++)
- if (fi[0] == fin)
- return i;
-
- return -1;
-}
-
-/* create a uid from md5 of 'top' output */
-static void
-cmd_builduid(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
-{
- CamelPOP3FolderInfo *fi = data;
- MD5Context md5;
- unsigned char *start;
- unsigned int len;
- unsigned char digest[16];
- int ret;
-
- /* TODO; somehow work out the limit and use that for proper progress reporting
- We need a pointer to the folder perhaps? */
- camel_operation_progress_count(NULL, fi->id);
-
- md5_init(&md5);
- do {
- ret = camel_pop3_stream_getd(stream, &start, &len);
- if (ret >= 0)
- md5_update(&md5, start, len);
- } while (ret > 0);
- md5_final(&md5, digest);
- fi->uid = base64_encode_simple (digest, 16);
-
- d(printf("building uid for id '%d' = '%s'\n", fi->id, fi->uid));
-}
-
-static void
-cmd_list(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
-{
- int ret;
- unsigned int len, id, size;
- unsigned char *line;
- CamelFolder *folder = data;
- CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
- CamelPOP3FolderInfo *fi;
-
- do {
- ret = camel_pop3_stream_line(stream, &line, &len);
- if (ret>=0) {
- if (sscanf(line, "%u %u", &id, &size) == 2) {
- fi = g_malloc0(sizeof(*fi));
- fi->size = size;
- fi->id = id;
- if ((pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) == 0)
- fi->cmd = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_builduid, fi, "TOP %u 0\r\n", id);
- g_ptr_array_add(((CamelPOP3Folder *)folder)->uids, fi);
- }
- }
- } while (ret>0);
-}
-
-static void
-cmd_uidl(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
-{
- int ret;
- unsigned int len;
- unsigned char *line;
- char uid[1025];
- unsigned int id, i=0;
- CamelPOP3FolderInfo *fi;
- CamelPOP3Folder *folder = data;
-
- do {
- ret = camel_pop3_stream_line(stream, &line, &len);
- if (ret>=0) {
- if (strlen(line) > 1024)
- line[1024] = 0;
- if (sscanf(line, "%u %s", &id, uid) == 2) {
- fi = id_to_fi(folder, id);
- if (fi) {
- /* fixme: dreadfully inefficient */
- i = fi_to_index(folder, fi);
- camel_operation_progress(NULL, (i+1) * 100 / folder->uids->len);
- fi->uid = g_strdup(uid);
- } else {
- g_warning("ID %u (uid: %s) not in previous LIST output", id, uid);
- }
- }
- }
- } while (ret>0);
-}
-
-static void
-pop3_refresh_info (CamelFolder *folder, CamelException *ex)
-{
- CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
- CamelPOP3Folder *pop3_folder = (CamelPOP3Folder *) folder;
- CamelPOP3Command *pcl, *pcu = NULL;
- int i;
-
- camel_operation_start (NULL, _("Retrieving POP summary"));
-
- pop3_folder->uids = g_ptr_array_new ();
-
- pcl = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_list, folder, "LIST\r\n");
- if (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) {
- pcu = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_uidl, folder, "UIDL\r\n");
- }
- while ((i = camel_pop3_engine_iterate(pop3_store->engine, NULL)) > 0)
- ;
-
- if (i == -1) {
- if (errno == EINTR)
- camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("User cancelled"));
- else
- camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get POP summary: %s"), strerror(errno));
- }
-
- /* TODO: check every id has a uid & commands returned OK too? */
-
- /* Free any commands we created along the way */
- if (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) {
- camel_pop3_engine_command_free(pop3_store->engine, pcu);
- } else {
- for (i=0;i<pop3_folder->uids->len;i++) {
- CamelPOP3FolderInfo *fi = pop3_folder->uids->pdata[i];
- if (fi->cmd) {
- camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
- fi->cmd = NULL;
- }
- }
- }
-
- camel_operation_end (NULL);
- return;
-}
-
-static void
-pop3_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
-{
- CamelPOP3Folder *pop3_folder;
- CamelPOP3Store *pop3_store;
- int i;
- CamelPOP3FolderInfo *fi;
-
- if (!expunge)
- return;
-
- pop3_folder = CAMEL_POP3_FOLDER (folder);
- pop3_store = CAMEL_POP3_STORE (folder->parent_store);
-
- camel_operation_start(NULL, _("Expunging deleted messages"));
-
- for (i = 0; i < pop3_folder->uids->len; i++) {
- fi = pop3_folder->uids->pdata[i];
- /* busy already? wait for that to finish first */
- if (fi->cmd) {
- while (camel_pop3_engine_iterate(pop3_store->engine, fi->cmd) > 0)
- ;
- camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
- fi->cmd = NULL;
- }
-
- if (fi->flags & CAMEL_MESSAGE_DELETED) {
- fi->cmd = camel_pop3_engine_command_new(pop3_store->engine, 0, NULL, NULL, "DELE %u\r\n", fi->id);
-
- /* also remove from cache */
- if (pop3_store->cache && fi->uid)
- camel_data_cache_remove(pop3_store->cache, "cache", fi->uid, NULL);
- }
- }
-
- for (i = 0; i < pop3_folder->uids->len; i++) {
- fi = pop3_folder->uids->pdata[i];
- /* wait for delete commands to finish */
- if (fi->cmd) {
- while (camel_pop3_engine_iterate(pop3_store->engine, fi->cmd) > 0)
- ;
- camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
- fi->cmd = NULL;
- }
- camel_operation_progress(NULL, (i+1) * 100 / pop3_folder->uids->len);
- }
-
- camel_operation_end(NULL);
-
- camel_pop3_store_expunge (pop3_store, ex);
-}
-
-static void
-cmd_tocache(CamelPOP3Engine *pe, CamelPOP3Stream *stream, void *data)
-{
- CamelPOP3FolderInfo *fi = data;
- char buffer[2048];
- int w = 0, n;
-
- /* What if it fails? */
-
- /* We write an '*' to the start of the stream to say its not complete yet */
- /* This should probably be part of the cache code */
- if ((n = camel_stream_write(fi->stream, "*", 1)) == -1)
- goto done;
-
- while ((n = camel_stream_read((CamelStream *)stream, buffer, sizeof(buffer))) > 0) {
- n = camel_stream_write(fi->stream, buffer, n);
- if (n == -1)
- break;
-
- w += n;
- if (w > fi->size)
- w = fi->size;
- camel_operation_progress(NULL, (w * 100) / fi->size);
- }
-
- /* it all worked, output a '#' to say we're a-ok */
- if (n != -1) {
- camel_stream_reset(fi->stream);
- n = camel_stream_write(fi->stream, "#", 1);
- }
-done:
- if (n == -1) {
- fi->err = errno;
- g_warning("POP3 retrieval failed: %s", strerror(errno));
- } else {
- fi->err = 0;
- }
-
- camel_object_unref((CamelObject *)fi->stream);
- fi->stream = NULL;
-}
-
-static CamelMimeMessage *
-pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex)
-{
- CamelMimeMessage *message = NULL;
- CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store);
- CamelPOP3Folder *pop3_folder = (CamelPOP3Folder *)folder;
- CamelPOP3Command *pcr;
- CamelPOP3FolderInfo *fi;
- char buffer[1];
- int ok, i;
- CamelStream *stream = NULL;
-
- fi = uid_to_fi(pop3_folder, uid);
- if (fi == NULL) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
- _("No message with uid %s"), uid);
- return NULL;
- }
-
- /* Sigh, most of the crap in this function is so that the cancel button
- returns the proper exception code. Sigh. */
-
- camel_operation_start_transient(NULL, _("Retrieving POP message %d"), fi->id);
-
- /* If we have an oustanding retrieve message running, wait for that to complete
- & then retrieve from cache, otherwise, start a new one, and similar */
-
- if (fi->cmd != NULL) {
- while ((i = camel_pop3_engine_iterate(pop3_store->engine, fi->cmd)) > 0)
- ;
-
- if (i == -1)
- fi->err = errno;
-
- /* getting error code? */
- ok = fi->cmd->state == CAMEL_POP3_COMMAND_DATA;
- camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
- fi->cmd = NULL;
-
- if (fi->err != 0) {
- if (fi->err == EINTR)
- camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("User cancelled"));
- else
- camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"), uid, strerror(fi->err));
- goto fail;
- }
- }
-
- /* check to see if we have safely written flag set */
- if (pop3_store->cache == NULL
- || (stream = camel_data_cache_get(pop3_store->cache, "cache", fi->uid, NULL)) == NULL
- || camel_stream_read(stream, buffer, 1) != 1
- || buffer[0] != '#') {
-
- /* Initiate retrieval, if disk backing fails, use a memory backing */
- if (pop3_store->cache == NULL
- || (stream = camel_data_cache_add(pop3_store->cache, "cache", fi->uid, NULL)) == NULL)
- stream = camel_stream_mem_new();
-
- /* ref it, the cache storage routine unref's when done */
- camel_object_ref((CamelObject *)stream);
- fi->stream = stream;
- fi->err = EIO;
- pcr = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_tocache, fi, "RETR %u\r\n", fi->id);
-
- /* Also initiate retrieval of all following messages, assume we'll be receiving them */
- if (pop3_store->cache != NULL) {
- i = fi_to_index(pop3_folder, fi)+1;
- for (;i<pop3_folder->uids->len;i++) {
- CamelPOP3FolderInfo *pfi = pop3_folder->uids->pdata[i];
-
- if (pfi->uid && pfi->cmd == NULL) {
- pfi->stream = camel_data_cache_add(pop3_store->cache, "cache", pfi->uid, NULL);
- if (pfi->stream) {
- pfi->err = EIO;
- pfi->cmd = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI,
- cmd_tocache, pfi, "RETR %u\r\n", pfi->id);
- }
- }
- }
- }
-
- /* now wait for the first one to finish */
- while ((i = camel_pop3_engine_iterate(pop3_store->engine, pcr)) > 0)
- ;
-
- if (i == -1)
- fi->err = errno;
-
- /* getting error code? */
- ok = pcr->state == CAMEL_POP3_COMMAND_DATA;
- camel_pop3_engine_command_free(pop3_store->engine, pcr);
- camel_stream_reset(stream);
-
- /* Check to see we have safely written flag set */
- if (fi->err != 0) {
- if (fi->err == EINTR)
- camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("User cancelled"));
- else
- camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"), uid, strerror(fi->err));
- goto done;
- }
-
- if (camel_stream_read(stream, buffer, 1) != 1
- || buffer[0] != '#') {
- camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
- _("Cannot get message %s: %s"), uid, _("Unknown reason"));
- goto done;
- }
- }
-
- message = camel_mime_message_new ();
- if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)message, stream) == -1) {
- if (errno == EINTR)
- camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("User cancelled"));
- else
- camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"), uid, strerror(errno));
- camel_object_unref((CamelObject *)message);
- message = NULL;
- }
-done:
- camel_object_unref((CamelObject *)stream);
-fail:
- camel_operation_end(NULL);
-
- return message;
-}
-
-static void
-pop3_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set)
-{
- CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder);
- CamelPOP3FolderInfo *fi;
-
- fi = uid_to_fi(pop3_folder, uid);
- if (fi)
- fi->flags = (fi->flags & ~flags) | (set & flags);
-}
-
-static gint
-pop3_get_message_count (CamelFolder *folder)
-{
- CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder);
-
- return pop3_folder->uids->len;
-}
-
-static GPtrArray *
-pop3_get_uids (CamelFolder *folder)
-{
- CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder);
- GPtrArray *uids = g_ptr_array_new();
- CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_folder->uids->pdata;
- int i;
-
- for (i=0;i<pop3_folder->uids->len;i++,fi++) {
- if (fi[0]->uid)
- g_ptr_array_add(uids, fi[0]->uid);
- }
-
- return uids;
-}
diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h
deleted file mode 100644
index 55eb1d253b..0000000000
--- a/camel/providers/pop3/camel-pop3-folder.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-pop3-folder.h : Class for a POP3 folder */
-
-/*
- * Authors:
- * Dan Winship <danw@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 2002 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_POP3_FOLDER_H
-#define CAMEL_POP3_FOLDER_H 1
-
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include "camel-folder.h"
-
-#define CAMEL_POP3_FOLDER_TYPE (camel_pop3_folder_get_type ())
-#define CAMEL_POP3_FOLDER(obj) (CAMEL_CHECK_CAST((obj), CAMEL_POP3_FOLDER_TYPE, CamelPOP3Folder))
-#define CAMEL_POP3_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_POP3_FOLDER_TYPE, CamelPOP3FolderClass))
-#define CAMEL_IS_POP3_FOLDER(o) (CAMEL_CHECK_TYPE((o), CAMEL_POP3_FOLDER_TYPE))
-
-typedef struct {
- guint32 id;
- guint32 size;
- guint32 flags;
- char *uid;
- int err;
- struct _CamelPOP3Command *cmd;
- struct _CamelStream *stream;
-} CamelPOP3FolderInfo;
-
-
-typedef struct {
- CamelFolder parent_object;
-
- GPtrArray *uids;
-
-} CamelPOP3Folder;
-
-
-
-typedef struct {
- CamelFolderClass parent_class;
-
- /* Virtual methods */
-
-} CamelPOP3FolderClass;
-
-
-/* public methods */
-CamelFolder *camel_pop3_folder_new (CamelStore *parent, CamelException *ex);
-
-/* Standard Camel function */
-CamelType camel_pop3_folder_get_type (void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_POP3_FOLDER_H */
diff --git a/camel/providers/pop3/camel-pop3-provider.c b/camel/providers/pop3/camel-pop3-provider.c
deleted file mode 100644
index f68784fbd1..0000000000
--- a/camel/providers/pop3/camel-pop3-provider.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-pop3-provider.c: pop3 provider registration code */
-
-/*
- * Authors :
- * Dan Winship <danw@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 2000 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "camel-pop3-store.h"
-#include "camel-provider.h"
-#include "camel-session.h"
-#include "camel-url.h"
-#include "camel-sasl.h"
-
-CamelProviderConfEntry pop3_conf_entries[] = {
- { CAMEL_PROVIDER_CONF_SECTION_START, NULL, NULL,
- N_("Message storage") },
- { CAMEL_PROVIDER_CONF_CHECKBOX, "keep_on_server", NULL,
- N_("Leave messages on server"), "0" },
-#ifdef NOT_FOR_1_0
- { CAMEL_PROVIDER_CONF_CHECKSPIN, "delete_after", "UNIMPLEMENTED",
- N_("Delete after %s day(s)"), "0:1:7:365" },
-#endif
- { CAMEL_PROVIDER_CONF_SECTION_END },
- { CAMEL_PROVIDER_CONF_END }
-};
-
-static CamelProvider pop3_provider = {
- "pop",
-
- N_("POP"),
-
- N_("For connecting to and downloading mail from POP servers."),
-
- "mail",
-
- CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
- CAMEL_PROVIDER_SUPPORTS_SSL,
-
- CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
-
- pop3_conf_entries,
-
- /* ... */
-};
-
-CamelServiceAuthType camel_pop3_password_authtype = {
- N_("Password"),
-
- N_("This option will connect to the POP server using a plaintext "
- "password. This is the only option supported by many POP servers."),
-
- "",
- TRUE
-};
-
-CamelServiceAuthType camel_pop3_apop_authtype = {
- "APOP",
-
- N_("This option will connect to the POP server using an encrypted "
- "password via the APOP protocol. This may not work for all users "
- "even on servers that claim to support it."),
-
- "+APOP",
- TRUE
-};
-
-void
-camel_provider_module_init (CamelSession *session)
-{
- CamelServiceAuthType *auth;
-
- pop3_provider.object_types[CAMEL_PROVIDER_STORE] = camel_pop3_store_get_type();
- pop3_provider.service_cache = g_hash_table_new(camel_url_hash, camel_url_equal);
- pop3_provider.url_hash = camel_url_hash;
- pop3_provider.url_equal = camel_url_equal;
-
- pop3_provider.authtypes = camel_sasl_authtype_list (FALSE);
- auth = camel_sasl_authtype("LOGIN");
- if (auth)
- pop3_provider.authtypes = g_list_prepend(pop3_provider.authtypes, auth);
- pop3_provider.authtypes = g_list_prepend(pop3_provider.authtypes, &camel_pop3_apop_authtype);
- pop3_provider.authtypes = g_list_prepend(pop3_provider.authtypes, &camel_pop3_password_authtype);
-
- camel_session_register_provider(session, &pop3_provider);
-}
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
deleted file mode 100644
index 515e982b95..0000000000
--- a/camel/providers/pop3/camel-pop3-store.c
+++ /dev/null
@@ -1,634 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-pop3-store.c : class for a pop3 store */
-
-/*
- * Authors:
- * Dan Winship <danw@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 2000-2002 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "camel-operation.h"
-
-#include "camel-pop3-store.h"
-#include "camel-pop3-folder.h"
-#include "camel-stream-buffer.h"
-#include "camel-session.h"
-#include "camel-exception.h"
-#include "camel-url.h"
-#include "e-util/md5-utils.h"
-#include "camel-pop3-engine.h"
-#include "camel-sasl.h"
-#include "camel-data-cache.h"
-#include "camel-tcp-stream.h"
-#include "camel-tcp-stream-raw.h"
-#ifdef HAVE_NSS
-#include "camel-tcp-stream-ssl.h"
-#include <prnetdb.h>
-#endif
-#ifdef HAVE_OPENSSL
-#include "camel-tcp-stream-openssl.h"
-#endif
-
-/* Specified in RFC 1939 */
-#define POP3_PORT 110
-
-static CamelStoreClass *parent_class = NULL;
-
-static void finalize (CamelObject *object);
-
-static gboolean pop3_connect (CamelService *service, CamelException *ex);
-static gboolean pop3_disconnect (CamelService *service, gboolean clean, CamelException *ex);
-static GList *query_auth_types (CamelService *service, CamelException *ex);
-
-static CamelFolder *get_folder (CamelStore *store, const char *folder_name,
- guint32 flags, CamelException *ex);
-
-static void init_trash (CamelStore *store);
-static CamelFolder *get_trash (CamelStore *store, CamelException *ex);
-
-static void
-camel_pop3_store_class_init (CamelPOP3StoreClass *camel_pop3_store_class)
-{
- CamelServiceClass *camel_service_class =
- CAMEL_SERVICE_CLASS (camel_pop3_store_class);
- CamelStoreClass *camel_store_class =
- CAMEL_STORE_CLASS (camel_pop3_store_class);
-
- parent_class = CAMEL_STORE_CLASS (camel_type_get_global_classfuncs (camel_store_get_type ()));
-
- /* virtual method overload */
- camel_service_class->query_auth_types = query_auth_types;
- camel_service_class->connect = pop3_connect;
- camel_service_class->disconnect = pop3_disconnect;
-
- camel_store_class->get_folder = get_folder;
- camel_store_class->init_trash = init_trash;
- camel_store_class->get_trash = get_trash;
-}
-
-
-
-static void
-camel_pop3_store_init (gpointer object, gpointer klass)
-{
- ;
-}
-
-CamelType
-camel_pop3_store_get_type (void)
-{
- static CamelType camel_pop3_store_type = CAMEL_INVALID_TYPE;
-
- if (!camel_pop3_store_type) {
- camel_pop3_store_type = camel_type_register (CAMEL_STORE_TYPE,
- "CamelPOP3Store",
- sizeof (CamelPOP3Store),
- sizeof (CamelPOP3StoreClass),
- (CamelObjectClassInitFunc) camel_pop3_store_class_init,
- NULL,
- (CamelObjectInitFunc) camel_pop3_store_init,
- finalize);
- }
-
- return camel_pop3_store_type;
-}
-
-static void
-finalize (CamelObject *object)
-{
- CamelPOP3Store *pop3_store = CAMEL_POP3_STORE (object);
-
- /* force disconnect so we dont have it run later, after we've cleaned up some stuff */
- /* SIGH */
-
- camel_service_disconnect((CamelService *)pop3_store, TRUE, NULL);
-
- if (pop3_store->engine)
- camel_object_unref((CamelObject *)pop3_store->engine);
- if (pop3_store->cache)
- camel_object_unref((CamelObject *)pop3_store->cache);
-}
-
-enum {
- USE_SSL_NEVER,
- USE_SSL_ALWAYS,
- USE_SSL_WHEN_POSSIBLE
-};
-
-static gboolean
-connect_to_server (CamelService *service, int ssl_mode, int try_starttls, int *stls_support, CamelException *ex)
-{
- CamelPOP3Store *store = CAMEL_POP3_STORE (service);
- CamelStream *tcp_stream;
- CamelPOP3Command *pc;
- struct hostent *h;
- int clean_quit;
- int ret, port;
-
- h = camel_service_gethost (service, ex);
- if (!h)
- return FALSE;
-
- port = service->url->port ? service->url->port : 110;
-
-#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
- /* FIXME: check for "always" and "when-possible" to support STARTTLS */
- if (camel_url_get_param (service->url, "use_ssl")) {
- if (!try_starttls)
- port = service->url->port ? service->url->port : 995;
-#ifdef HAVE_NSS
- /* this is the preferred SSL implementation */
- if (try_starttls)
- tcp_stream = camel_tcp_stream_ssl_new_raw (service, service->url->host);
- else
- tcp_stream = camel_tcp_stream_ssl_new (service, service->url->host);
-#else
- /* use openssl... */
- if (try_starttls)
- tcp_stream = camel_tcp_stream_openssl_new_raw (service, service->url->host);
- else
- tcp_stream = camel_tcp_stream_openssl_new (service, service->url->host);
-#endif /* HAVE_NSS */
- } else {
- tcp_stream = camel_tcp_stream_raw_new ();
- }
-#else
- tcp_stream = camel_tcp_stream_raw_new ();
-#endif /* HAVE_NSS || HAVE_OPENSSL */
-
- ret = camel_tcp_stream_connect (CAMEL_TCP_STREAM (tcp_stream), h, port);
- camel_free_host (h);
- if (ret == -1) {
- if (errno == EINTR)
- camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
- _("Connection cancelled"));
- else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s (port %d): %s"),
- service->url->host ? service->url->host : _("(unknown host)"),
- port, g_strerror (errno));
- return FALSE;
- }
-
- /* parent class connect initialization */
- if (CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex) == FALSE) {
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
- return FALSE;
- }
-
- store->engine = camel_pop3_engine_new (tcp_stream);
-
- if (stls_support)
- *stls_support = store->engine->capa & CAMEL_POP3_CAP_STLS;
-
-#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
- if (store->engine) {
- if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
- if (store->engine->capa & CAMEL_POP3_CAP_STLS)
- goto starttls;
- } else if (ssl_mode == USE_SSL_ALWAYS) {
- if (try_starttls) {
- if (store->engine->capa & CAMEL_POP3_CAP_STLS) {
- /* attempt to toggle STARTTLS mode */
- goto starttls;
- } else {
- /* server doesn't support STARTTLS, abort */
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to POP server %s in secure mode: %s"),
- service->url->host, _("SSL/TLS extension not supported."));
- /* we have the possibility of quitting cleanly here */
- clean_quit = TRUE;
- goto stls_exception;
- }
- }
- }
- }
-#endif /* HAVE_NSS || HAVE_OPENSSL */
-
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
-
- return store->engine != NULL;
-
-#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
- starttls:
- /* as soon as we send a STLS command, all hope is lost of a clean QUIT if problems arise */
- clean_quit = FALSE;
-
- pc = camel_pop3_engine_command_new (store->engine, 0, NULL, NULL, "STLS\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
- ;
-
- ret = pc->state == CAMEL_POP3_COMMAND_OK;
- camel_pop3_engine_command_free (store->engine, pc);
-
- if (ret == FALSE) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to POP server %s in secure mode: %s"),
- service->url->host, store->engine->line);
- goto stls_exception;
- }
-
- /* Okay, now toggle SSL/TLS mode */
-#ifdef HAVE_NSS
- ret = camel_tcp_stream_ssl_enable_ssl (CAMEL_TCP_STREAM_SSL (tcp_stream));
-#else /* HAVE_OPENSSL */
- ret = camel_tcp_stream_openssl_enable_ssl (CAMEL_TCP_STREAM_OPENSSL (tcp_stream));
-#endif
-
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
-
- if (ret == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to connect to POP server %s in secure mode: %s"),
- service->url->host, _("SSL negotiations failed"));
- goto stls_exception;
- }
-
- /* rfc2595, section 4 states that after a successful STLS
- command, the client MUST discard prior CAPA responses */
- camel_pop3_engine_reget_capabilities (store->engine);
-
- return TRUE;
-
- stls_exception:
- if (clean_quit) {
- /* try to disconnect cleanly */
- pc = camel_pop3_engine_command_new (store->engine, 0, NULL, NULL, "QUIT\r\n");
- while (camel_pop3_engine_iterate (store->engine, NULL) > 0)
- ;
- camel_pop3_engine_command_free (store->engine, pc);
- }
-
- camel_object_unref (CAMEL_OBJECT (store->engine));
- camel_object_unref (CAMEL_OBJECT (tcp_stream));
- store->engine = NULL;
-
- return FALSE;
-#endif /* HAVE_NSS || HAVE_OPENSSL */
-}
-
-static struct {
- char *value;
- int mode;
-} ssl_options[] = {
- { "", USE_SSL_ALWAYS },
- { "always", USE_SSL_ALWAYS },
- { "when-possible", USE_SSL_WHEN_POSSIBLE },
- { "never", USE_SSL_NEVER },
- { NULL, USE_SSL_NEVER },
-};
-
-#define EXCEPTION_RETRY(ex) (camel_exception_get_id (ex) != CAMEL_EXCEPTION_USER_CANCEL && \
- camel_exception_get_id (ex) != CAMEL_EXCEPTION_SERVICE_UNAVAILABLE)
-
-static gboolean
-connect_to_server_wrapper (CamelService *service, CamelException *ex)
-{
-#if defined (HAVE_NSS) || defined (HAVE_OPENSSL)
- const char *use_ssl;
- int stls_supported;
- int i, ssl_mode;
-
- use_ssl = camel_url_get_param (service->url, "use_ssl");
- if (use_ssl) {
- for (i = 0; ssl_options[i].value; i++)
- if (!strcmp (ssl_options[i].value, use_ssl))
- break;
- ssl_mode = ssl_options[i].mode;
- } else
- ssl_mode = USE_SSL_NEVER;
-
- if (ssl_mode == USE_SSL_ALWAYS) {
- /* First try STARTTLS */
- if (!connect_to_server (service, ssl_mode, TRUE, &stls_supported, ex) &&
- !stls_supported && EXCEPTION_RETRY (ex)) {
- /* STARTTLS is unavailable - okay, now try old-style SSL */
- camel_exception_clear (ex);
- return connect_to_server (service, ssl_mode, FALSE, NULL, ex);
- }
-
- return TRUE;
- } else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) {
- /* If the server supports STARTTLS, use it */
- return connect_to_server (service, ssl_mode, TRUE, NULL, ex);
- } else {
- /* User doesn't care about SSL */
- return connect_to_server (service, ssl_mode, FALSE, NULL, ex);
- }
-#else
- return connect_to_server (service, USE_SSL_NEVER, FALSE, NULL, ex);
-#endif
-}
-
-extern CamelServiceAuthType camel_pop3_password_authtype;
-extern CamelServiceAuthType camel_pop3_apop_authtype;
-
-static GList *
-query_auth_types (CamelService *service, CamelException *ex)
-{
- CamelPOP3Store *store = CAMEL_POP3_STORE (service);
- GList *types = NULL;
-
- types = CAMEL_SERVICE_CLASS (parent_class)->query_auth_types (service, ex);
- if (camel_exception_is_set (ex))
- return NULL;
-
- if (connect_to_server_wrapper (service, NULL)) {
- types = g_list_concat(types, g_list_copy(store->engine->auth));
- pop3_disconnect (service, TRUE, NULL);
- } else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to POP server on %s"),
- service->url->host);
- }
-
- return types;
-}
-
-/**
- * camel_pop3_store_expunge:
- * @store: the store
- * @ex: a CamelException
- *
- * Expunge messages from the store. This will result in the connection
- * being closed, which may cause later commands to fail if they can't
- * reconnect.
- **/
-void
-camel_pop3_store_expunge (CamelPOP3Store *store, CamelException *ex)
-{
- CamelPOP3Command *pc;
-
- pc = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "QUIT\r\n");
- while (camel_pop3_engine_iterate(store->engine, NULL) > 0)
- ;
- camel_pop3_engine_command_free(store->engine, pc);
-
- camel_service_disconnect (CAMEL_SERVICE (store), FALSE, ex);
-}
-
-static int
-try_sasl(CamelPOP3Store *store, const char *mech, CamelException *ex)
-{
- CamelPOP3Stream *stream = store->engine->stream;
- unsigned char *line, *resp;
- CamelSasl *sasl;
- unsigned int len;
- int ret;
-
- sasl = camel_sasl_new("pop3", mech, (CamelService *)store);
- if (sasl == NULL) {
- camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Unable to connect to POP server.\n"
- "No support for requested "
- "authentication mechanism."));
- return -1;
- }
-
- if (camel_stream_printf((CamelStream *)stream, "AUTH %s\r\n", mech) == -1)
- goto ioerror;
-
- while (1) {
- if (camel_pop3_stream_line(stream, &line, &len) == -1)
- goto ioerror;
- if (strncmp(line, "+OK", 3) == 0)
- break;
- if (strncmp(line, "-ERR", 4) == 0) {
- camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("SASL `%s' Login failed: %s"), mech, line);
- goto done;
- }
- /* If we dont get continuation, or the sasl object's run out of work, or we dont get a challenge,
- its a protocol error, so fail, and try reset the server */
- if (strncmp(line, "+ ", 2) != 0
- || camel_sasl_authenticated(sasl)
- || (resp = camel_sasl_challenge_base64(sasl, line+2, ex)) == NULL) {
- camel_stream_printf((CamelStream *)stream, "*\r\n");
- camel_pop3_stream_line(stream, &line, &len);
- camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("SASL Protocol error"));
- goto done;
- }
-
- ret = camel_stream_printf((CamelStream *)stream, "%s\r\n", resp);
- g_free(resp);
- if (ret == -1)
- goto ioerror;
-
- }
- camel_object_unref((CamelObject *)sasl);
- return 0;
-
-ioerror:
- camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("I/O Error: %s"), strerror(errno));
-done:
- camel_object_unref((CamelObject *)sasl);
- return -1;
-}
-
-static gboolean
-pop3_try_authenticate (CamelService *service, const char *errmsg,
- CamelException *ex)
-{
- CamelPOP3Store *store = (CamelPOP3Store *)service;
- int status;
- CamelPOP3Command *pcu = NULL, *pcp = NULL;
-
- /* override, testing only */
- /*printf("Forcing authmech to 'login'\n");
- service->url->authmech = g_strdup("LOGIN");*/
-
- if (!service->url->passwd) {
- char *prompt;
-
- prompt = g_strdup_printf (_("%sPlease enter the POP password for %s@%s"),
- errmsg ? errmsg : "",
- service->url->user,
- service->url->host);
- service->url->passwd = camel_session_get_password (camel_service_get_session (service),
- prompt, TRUE, service, "password", ex);
- g_free (prompt);
- if (!service->url->passwd)
- return FALSE;
- }
-
- if (!service->url->authmech) {
- /* pop engine will take care of pipelining ability */
- pcu = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "USER %s\r\n", service->url->user);
- pcp = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "PASS %s\r\n", service->url->passwd);
- } else if (strcmp(service->url->authmech, "+APOP") == 0 && store->engine->apop) {
- char *secret, md5asc[33], *d;
- unsigned char md5sum[16], *s;
-
- secret = alloca(strlen(store->engine->apop)+strlen(service->url->passwd)+1);
- sprintf(secret, "%s%s", store->engine->apop, service->url->passwd);
- md5_get_digest(secret, strlen (secret), md5sum);
-
- for (s = md5sum, d = md5asc; d < md5asc + 32; s++, d += 2)
- sprintf (d, "%.2x", *s);
-
- pcp = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "APOP %s %s\r\n", service->url->user, md5asc);
- } else {
- CamelServiceAuthType *auth;
- GList *l;
-
- l = store->engine->auth;
- while (l) {
- auth = l->data;
- if (strcmp(auth->authproto, service->url->authmech) == 0)
- return try_sasl(store, service->url->authmech, ex) == -1;
- l = l->next;
- }
-
- camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Unable to connect to POP server.\n"
- "No support for requested "
- "authentication mechanism."));
- return FALSE;
- }
-
- while (camel_pop3_engine_iterate(store->engine, pcp) > 0)
- ;
- status = pcp->state != CAMEL_POP3_COMMAND_OK;
- if (status) {
- camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
- _("Unable to connect to POP server.\nError sending password: %s"),
- store->engine->line);
- }
- camel_pop3_engine_command_free(store->engine, pcp);
-
- if (pcu)
- camel_pop3_engine_command_free(store->engine, pcu);
-
- return status;
-}
-
-static gboolean
-pop3_connect (CamelService *service, CamelException *ex)
-{
- char *errbuf = NULL;
- gboolean tryagain;
- CamelPOP3Store *store = (CamelPOP3Store *)service;
-
- if (store->cache == NULL) {
- char *root;
-
- root = camel_session_get_storage_path(service->session, service, ex);
- if (root) {
- store->cache = camel_data_cache_new(root, 0, ex);
- g_free(root);
- if (store->cache) {
- /* Default cache expiry - 1 week or not visited in a day */
- camel_data_cache_set_expire_age(store->cache, 60*60*24*7);
- camel_data_cache_set_expire_access(store->cache, 60*60*24);
- }
- }
- }
-
- if (!connect_to_server_wrapper (service, ex))
- return FALSE;
-
- camel_exception_clear (ex);
- do {
- if (camel_exception_is_set (ex)) {
- errbuf = g_strdup_printf ("%s\n\n", camel_exception_get_description (ex));
- camel_exception_clear (ex);
-
- /* Uncache the password before prompting again. */
- camel_session_forget_password (camel_service_get_session (service),
- service, "password", ex);
- g_free (service->url->passwd);
- service->url->passwd = NULL;
- }
-
- tryagain = pop3_try_authenticate (service, errbuf, ex);
- g_free (errbuf);
- errbuf = NULL;
- } while (tryagain);
-
- if (camel_exception_is_set (ex)) {
- camel_service_disconnect (service, TRUE, ex);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-pop3_disconnect (CamelService *service, gboolean clean, CamelException *ex)
-{
- CamelPOP3Store *store = CAMEL_POP3_STORE (service);
-
- if (clean) {
- CamelPOP3Command *pc;
-
- pc = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "QUIT\r\n");
- while (camel_pop3_engine_iterate(store->engine, NULL) > 0)
- ;
- camel_pop3_engine_command_free(store->engine, pc);
- }
-
- if (!CAMEL_SERVICE_CLASS (parent_class)->disconnect (service, clean, ex))
- return FALSE;
-
- camel_object_unref((CamelObject *)store->engine);
- store->engine = NULL;
-
- return TRUE;
-}
-
-static CamelFolder *
-get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex)
-{
- if (strcasecmp (folder_name, "inbox") != 0) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
- _("No such folder `%s'."), folder_name);
- return NULL;
- }
- return camel_pop3_folder_new (store, ex);
-}
-
-static void
-init_trash (CamelStore *store)
-{
- /* no-op */
- ;
-}
-
-static CamelFolder *
-get_trash (CamelStore *store, CamelException *ex)
-{
- /* no-op */
- return NULL;
-}
diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h
deleted file mode 100644
index 3b9b1f7ae1..0000000000
--- a/camel/providers/pop3/camel-pop3-store.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-pop3-store.h : class for an pop3 store */
-
-/*
- * Authors:
- * Dan Winship <danw@ximian.com>
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright (C) 2000-2002 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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_POP3_STORE_H
-#define CAMEL_POP3_STORE_H 1
-
-
-#ifdef __cplusplus
-extern "C" {
-#pragma }
-#endif /* __cplusplus }*/
-
-#include <camel/camel-types.h>
-#include <camel/camel-store.h>
-#include "camel-pop3-engine.h"
-
-#define CAMEL_POP3_STORE_TYPE (camel_pop3_store_get_type ())
-#define CAMEL_POP3_STORE(obj) (CAMEL_CHECK_CAST((obj), CAMEL_POP3_STORE_TYPE, CamelPOP3Store))
-#define CAMEL_POP3_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_POP3_STORE_TYPE, CamelPOP3StoreClass))
-#define CAMEL_IS_POP3_STORE(o) (CAMEL_CHECK_TYPE((o), CAMEL_POP3_STORE_TYPE))
-
-
-typedef struct {
- CamelStore parent_object;
-
- CamelPOP3Engine *engine; /* pop processing engine */
-
- struct _CamelDataCache *cache;
-} CamelPOP3Store;
-
-
-
-typedef struct {
- CamelStoreClass parent_class;
-
-} CamelPOP3StoreClass;
-
-
-/* public methods */
-void camel_pop3_store_expunge (CamelPOP3Store *store, CamelException *ex);
-
-/* support functions */
-enum { CAMEL_POP3_OK, CAMEL_POP3_ERR, CAMEL_POP3_FAIL };
-int camel_pop3_command (CamelPOP3Store *store, char **ret, CamelException *ex, char *fmt, ...);
-char *camel_pop3_command_get_additional_data (CamelPOP3Store *store, int total, CamelException *ex);
-
-/* Standard Camel function */
-CamelType camel_pop3_store_get_type (void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* CAMEL_POP3_STORE_H */
-
-
diff --git a/camel/providers/pop3/camel-pop3-stream.c b/camel/providers/pop3/camel-pop3-stream.c
deleted file mode 100644
index 5b0dd979ca..0000000000
--- a/camel/providers/pop3/camel-pop3-stream.c
+++ /dev/null
@@ -1,468 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*-
- *
- * Author:
- * Michael Zucchi <notzed@ximian.com>
- *
- * Copyright 2002 Ximian, Inc. (www.ximian.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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
- */
-
-/* This is *identical* to the camel-nntp-stream, so should probably
- work out a way to merge them */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-
-#include <glib.h>
-
-#include "camel-pop3-stream.h"
-
-extern int camel_verbose_debug;
-#define dd(x) (camel_verbose_debug?(x):0)
-
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelStream */
-#define CS_CLASS(so) CAMEL_POP3_STREAM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
-
-#define CAMEL_POP3_STREAM_SIZE (4096)
-#define CAMEL_POP3_STREAM_LINE (1024) /* maximum line size */
-
-static int
-stream_fill(CamelPOP3Stream *is)
-{
- int left = 0;
-
- if (is->source) {
- left = is->end - is->ptr;
- memcpy(is->buf, is->ptr, left);
- is->end = is->buf + left;
- is->ptr = is->buf;
- left = camel_stream_read(is->source, is->end, CAMEL_POP3_STREAM_SIZE - (is->end - is->buf));
- if (left > 0) {
- is->end += left;
- is->end[0] = '\n';
- return is->end - is->ptr;
- } else {
- dd(printf("POP3_STREAM_FILL(ERROR): '%s'\n", strerror(errno)));
- return -1;
- }
- }
-
- return 0;
-}
-
-static ssize_t
-stream_read(CamelStream *stream, char *buffer, size_t n)
-{
- CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
- char *o, *oe;
- unsigned char *p, *e, c;
- int state;
-
- if (is->mode != CAMEL_POP3_STREAM_DATA || n == 0)
- return 0;
-
- o = buffer;
- oe = buffer + n;
- state = is->state;
-
- /* Need to copy/strip '.'s and whatnot */
- p = is->ptr;
- e = is->end;
-
- switch(state) {
- state_0:
- case 0: /* start of line, always read at least 3 chars */
- while (e - p < 3) {
- is->ptr = p;
- if (stream_fill(is) == -1)
- return -1;
- p = is->ptr;
- e = is->end;
- }
- if (p[0] == '.') {
- if (p[1] == '\r' && p[2] == '\n') {
- is->ptr = p+3;
- is->mode = CAMEL_POP3_STREAM_EOD;
- is->state = 0;
- dd(printf("POP3_STREAM_READ(%d):\n%.*s\n", o-buffer, o-buffer, buffer));
- return o-buffer;
- }
- p++;
- }
- state = 1;
- /* FALLS THROUGH */
- case 1: /* looking for next sol */
- while (o < oe) {
- c = *p++;
- if (c == '\n') {
- /* end of input sentinal check */
- if (p > e) {
- is->ptr = e;
- if (stream_fill(is) == -1)
- return -1;
- p = is->ptr;
- e = is->end;
- } else {
- *o++ = '\n';
- state = 0;
- goto state_0;
- }
- } else if (c != '\r') {
- *o++ = c;
- }
- }
- break;
- }
-
- is->ptr = p;
- is->state = state;
-
- dd(printf("POP3_STREAM_READ(%d):\n%.*s\n", o-buffer, o-buffer, buffer));
-
- return o-buffer;
-}
-
-static ssize_t
-stream_write(CamelStream *stream, const char *buffer, size_t n)
-{
- CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
-
- dd(printf("POP3_STREAM_WRITE(%d):\n%.*s\n", n, (int)n, buffer));
-
- return camel_stream_write(is->source, buffer, n);
-}
-
-static int
-stream_close(CamelStream *stream)
-{
- /* nop? */
- return 0;
-}
-
-static int
-stream_flush(CamelStream *stream)
-{
- /* nop? */
- return 0;
-}
-
-static gboolean
-stream_eos(CamelStream *stream)
-{
- CamelPOP3Stream *is = (CamelPOP3Stream *)stream;
-
- return is->mode != CAMEL_POP3_STREAM_DATA;
-}
-
-static int
-stream_reset(CamelStream *stream)
-{
- /* nop? reset literal mode? */
- return 0;
-}
-
-static void
-camel_pop3_stream_class_init (CamelStreamClass *camel_pop3_stream_class)
-{
- CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_pop3_stream_class;
-
- parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
-
- /* virtual method definition */
- camel_stream_class->read = stream_read;
- camel_stream_class->write = stream_write;
- camel_stream_class->close = stream_close;
- camel_stream_class->flush = stream_flush;
- camel_stream_class->eos = stream_eos;
- camel_stream_class->reset = stream_reset;
-}
-
-static void
-camel_pop3_stream_init(CamelPOP3Stream *is, CamelPOP3StreamClass *isclass)
-{
- /* +1 is room for appending a 0 if we need to for a line */
- is->ptr = is->end = is->buf = g_malloc(CAMEL_POP3_STREAM_SIZE+1);
- is->lineptr = is->linebuf = g_malloc(CAMEL_POP3_STREAM_LINE+1);
- is->lineend = is->linebuf + CAMEL_POP3_STREAM_LINE;
-
- /* init sentinal */
- is->ptr[0] = '\n';
-
- is->state = 0;
- is->mode = CAMEL_POP3_STREAM_LINE;
-}
-
-static void
-camel_pop3_stream_finalise(CamelPOP3Stream *is)
-{
- g_free(is->buf);
- g_free(is->linebuf);
- if (is->source)
- camel_object_unref((CamelObject *)is->source);
-}
-
-CamelType
-camel_pop3_stream_get_type (void)
-{
- static CamelType camel_pop3_stream_type = CAMEL_INVALID_TYPE;
-
- if (camel_pop3_stream_type == CAMEL_INVALID_TYPE) {
- camel_pop3_stream_type = camel_type_register( camel_stream_get_type(),
- "CamelPOP3Stream",
- sizeof( CamelPOP3Stream ),
- sizeof( CamelPOP3StreamClass ),
- (CamelObjectClassInitFunc) camel_pop3_stream_class_init,
- NULL,
- (CamelObjectInitFunc) camel_pop3_stream_init,
- (CamelObjectFinalizeFunc) camel_pop3_stream_finalise );
- }
-
- return camel_pop3_stream_type;
-}
-
-/**
- * camel_pop3_stream_new:
- *
- * Returns a NULL stream. A null stream is always at eof, and
- * always returns success for all reads and writes.
- *
- * Return value: the stream
- **/
-CamelStream *
-camel_pop3_stream_new(CamelStream *source)
-{
- CamelPOP3Stream *is;
-
- is = (CamelPOP3Stream *)camel_object_new(camel_pop3_stream_get_type ());
- camel_object_ref((CamelObject *)source);
- is->source = source;
-
- return (CamelStream *)is;
-}
-
-/* Get one line from the pop3 stream */
-int
-camel_pop3_stream_line(CamelPOP3Stream *is, unsigned char **data, unsigned int *len)
-{
- register unsigned char c, *p, *o, *oe;
- int newlen, oldlen;
- unsigned char *e;
-
- if (is->mode == CAMEL_POP3_STREAM_EOD) {
- *data = is->linebuf;
- *len = 0;
- return 0;
- }
-
- o = is->linebuf;
- oe = is->lineend - 1;
- p = is->ptr;
- e = is->end;
-
- /* Data mode, convert leading '..' to '.', and stop when we reach a solitary '.' */
- if (is->mode == CAMEL_POP3_STREAM_DATA) {
- /* need at least 3 chars in buffer */
- while (e-p < 3) {
- is->ptr = p;
- if (stream_fill(is) == -1)
- return -1;
- p = is->ptr;
- e = is->end;
- }
-
- /* check for isolated '.\r\n' or begging of line '.' */
- if (p[0] == '.') {
- if (p[1] == '\r' && p[2] == '\n') {
- is->ptr = p+3;
- is->mode = CAMEL_POP3_STREAM_EOD;
- *data = is->linebuf;
- *len = 0;
- is->linebuf[0] = 0;
-
- dd(printf("POP3_STREAM_LINE(END)\n"));
-
- return 0;
- }
- p++;
- }
- }
-
- while (1) {
- while (o < oe) {
- c = *p++;
- if (c == '\n') {
- /* sentinal? */
- if (p> e) {
- is->ptr = e;
- if (stream_fill(is) == -1)
- return -1;
- p = is->ptr;
- e = is->end;
- } else {
- is->ptr = p;
- *data = is->linebuf;
- *len = o - is->linebuf;
- *o = 0;
-
- dd(printf("POP3_STREAM_LINE(%d): '%s'\n", *len, *data));
-
- return 1;
- }
- } else if (c != '\r') {
- *o++ = c;
- }
- }
-
- /* limit this for bad server data? */
- oldlen = o - is->linebuf;
- newlen = (is->lineend - is->linebuf) * 3 / 2;
- is->lineptr = is->linebuf = g_realloc(is->linebuf, newlen);
- is->lineend = is->linebuf + newlen;
- oe = is->lineend - 1;
- o = is->linebuf + oldlen;
- }
-
- return -1;
-}
-
-/* returns -1 on error, 0 if last lot of data, >0 if more remaining */
-int camel_pop3_stream_gets(CamelPOP3Stream *is, unsigned char **start, unsigned int *len)
-{
- int max;
- unsigned char *end;
-
- *len = 0;
-
- max = is->end - is->ptr;
- if (max == 0) {
- max = stream_fill(is);
- if (max <= 0)
- return max;
- }
-
- *start = is->ptr;
- end = memchr(is->ptr, '\n', max);
- if (end)
- max = (end - is->ptr) + 1;
- *start = is->ptr;
- *len = max;
- is->ptr += max;
-
- dd(printf("POP3_STREAM_GETS(%s,%d): '%.*s'\n", end==NULL?"more":"last", *len, (int)*len, *start));
-
- return end == NULL?1:0;
-}
-
-void camel_pop3_stream_set_mode(CamelPOP3Stream *is, camel_pop3_stream_mode_t mode)
-{
- is->mode = mode;
-}
-
-/* returns -1 on erorr, 0 if last data, >0 if more data left */
-int camel_pop3_stream_getd(CamelPOP3Stream *is, unsigned char **start, unsigned int *len)
-{
- unsigned char *p, *e, *s;
- int state;
-
- *len = 0;
-
- if (is->mode == CAMEL_POP3_STREAM_EOD)
- return 0;
-
- if (is->mode == CAMEL_POP3_STREAM_LINE) {
- g_warning("pop3_stream reading data in line mode\n");
- return 0;
- }
-
- state = is->state;
- p = is->ptr;
- e = is->end;
-
- while (e - p < 3) {
- is->ptr = p;
- if (stream_fill(is) == -1)
- return -1;
- p = is->ptr;
- e = is->end;
- }
-
- s = p;
-
- do {
- switch(state) {
- case 0:
- /* check leading '.', ... */
- if (p[0] == '.') {
- if (p[1] == '\r' && p[2] == '\n') {
- is->ptr = p+3;
- *len = p-s;
- *start = s;
- is->mode = CAMEL_POP3_STREAM_EOD;
- is->state = 0;
-
- dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "last", *len, (int)*len, *start));
-
- return 0;
- }
-
- /* If at start, just skip '.', else return data upto '.' but skip it */
- if (p == s) {
- s++;
- p++;
- } else {
- is->ptr = p+1;
- *len = p-s;
- *start = s;
- is->state = 1;
-
- dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (int)*len, *start));
-
- return 1;
- }
- }
- state = 1;
- case 1:
- /* Scan for sentinal */
- while ((*p++)!='\n')
- ;
-
- if (p > e) {
- p = e;
- } else {
- state = 0;
- }
- break;
- }
- } while ((e-p) >= 3);
-
- is->state = state;
- is->ptr = p;
- *len = p-s;
- *start = s;
-
- dd(printf("POP3_STREAM_GETD(%s,%d): '%.*s'\n", "more", *len, (int)*len, *start));
-
- return 1;
-}
diff --git a/camel/providers/pop3/camel-pop3-stream.h b/camel/providers/pop3/camel-pop3-stream.h
deleted file mode 100644
index 2baf48d21d..0000000000
--- a/camel/providers/pop3/camel-pop3-stream.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2002 Ximian Inc.
- *
- * Authors: Michael Zucchi <notzed@ximian.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-/* This is *identical* to the camel-nntp-stream, so should probably
- work out a way to merge them */
-
-#ifndef _CAMEL_POP3_STREAM_H
-#define _CAMEL_POP3_STREAM_H
-
-#include <camel/camel-stream.h>
-
-#define CAMEL_POP3_STREAM(obj) CAMEL_CHECK_CAST (obj, camel_pop3_stream_get_type (), CamelPOP3Stream)
-#define CAMEL_POP3_STREAM_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_pop3_stream_get_type (), CamelPOP3StreamClass)
-#define CAMEL_IS_POP3_STREAM(obj) CAMEL_CHECK_TYPE (obj, camel_pop3_stream_get_type ())
-
-typedef struct _CamelPOP3StreamClass CamelPOP3StreamClass;
-typedef struct _CamelPOP3Stream CamelPOP3Stream;
-
-typedef enum {
- CAMEL_POP3_STREAM_LINE,
- CAMEL_POP3_STREAM_DATA,
- CAMEL_POP3_STREAM_EOD, /* end of data, acts as if end of stream */
-} camel_pop3_stream_mode_t;
-
-struct _CamelPOP3Stream {
- CamelStream parent;
-
- CamelStream *source;
-
- camel_pop3_stream_mode_t mode;
- int state;
-
- unsigned char *buf, *ptr, *end;
- unsigned char *linebuf, *lineptr, *lineend;
-};
-
-struct _CamelPOP3StreamClass {
- CamelStreamClass parent_class;
-};
-
-guint camel_pop3_stream_get_type (void);
-
-CamelStream *camel_pop3_stream_new (CamelStream *source);
-
-
-void camel_pop3_stream_set_mode (CamelPOP3Stream *is, camel_pop3_stream_mode_t mode);
-
-int camel_pop3_stream_line (CamelPOP3Stream *is, unsigned char **data, unsigned int *len);
-int camel_pop3_stream_gets (CamelPOP3Stream *is, unsigned char **start, unsigned int *len);
-int camel_pop3_stream_getd (CamelPOP3Stream *is, unsigned char **start, unsigned int *len);
-
-#endif /* ! _CAMEL_POP3_STREAM_H */
diff --git a/camel/providers/pop3/libcamelpop3.urls b/camel/providers/pop3/libcamelpop3.urls
deleted file mode 100644
index 7fffa4d861..0000000000
--- a/camel/providers/pop3/libcamelpop3.urls
+++ /dev/null
@@ -1 +0,0 @@
-pop