diff options
author | Dan Winship <danw@src.gnome.org> | 2000-03-23 00:55:28 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-03-23 00:55:28 +0800 |
commit | 07baaeb9c606395a98853be164b04b56560f547a (patch) | |
tree | 89e381f6da58cc9d497fff7e99b0522290dac3e0 | |
parent | af50786d6f38bccab9b4ec69a5268668cb440191 (diff) | |
download | gsoc2013-evolution-07baaeb9c606395a98853be164b04b56560f547a.tar.gz gsoc2013-evolution-07baaeb9c606395a98853be164b04b56560f547a.tar.zst gsoc2013-evolution-07baaeb9c606395a98853be164b04b56560f547a.zip |
fill this in partially make camel_pop3_command return the text after
* providers/pop3/camel-pop3-folder.c: fill this in partially
* providers/pop3/camel-pop3-store.c: make camel_pop3_command
return the text after "+OK"/"-ERR" and add a separate
camel_pop3_get_additional_data to get the message body or
whatever. Also make them take a CamelPop3Store rather than
a CamelStreamBuffer.
svn path=/trunk/; revision=2143
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/providers/pop3/.cvsignore | 6 | ||||
-rw-r--r-- | camel/providers/pop3/Makefile.am | 28 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-folder.c | 156 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-folder.h | 7 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.c | 74 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.h | 3 |
7 files changed, 258 insertions, 25 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 8214ed4a8b..527325a93f 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,12 @@ +2000-03-22 Dan Winship <danw@helixcode.com> + + * providers/pop3/camel-pop3-folder.c: fill this in partially + * providers/pop3/camel-pop3-store.c: make camel_pop3_command + return the text after "+OK"/"-ERR" and add a separate + camel_pop3_get_additional_data to get the message body or + whatever. Also make them take a CamelPop3Store rather than + a CamelStreamBuffer. + 2000-03-22 Matt Loper <matt@helixcode.com> * camel-formatter.c (debug): Disabled some useless debug diff --git a/camel/providers/pop3/.cvsignore b/camel/providers/pop3/.cvsignore new file mode 100644 index 0000000000..7d926a5545 --- /dev/null +++ b/camel/providers/pop3/.cvsignore @@ -0,0 +1,6 @@ +Makefile +Makefile.in +.libs +.deps +*.lo +*.la diff --git a/camel/providers/pop3/Makefile.am b/camel/providers/pop3/Makefile.am new file mode 100644 index 0000000000..c587983ffc --- /dev/null +++ b/camel/providers/pop3/Makefile.am @@ -0,0 +1,28 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = + +libcamelpop3includedir = $(includedir)/camel + +providerdir = $(pkglibdir)/camel-providers/$(VERSION) + +provider_LTLIBRARIES = libcamelpop3.la + +INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ + -I$(top_srcdir)/intl \ + $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ + -I$(srcdir)/../mbox + +libcamelpop3_la_SOURCES = \ + camel-pop3-folder.c \ + camel-pop3-provider.c \ + camel-pop3-store.c + +libcamelpop3include_HEADERS = \ + camel-pop3-folder.h \ + camel-pop3-store.h + + +libcamelpop3_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) + +EXTRA_DIST = diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c new file mode 100644 index 0000000000..f5dd28e596 --- /dev/null +++ b/camel/providers/pop3/camel-pop3-folder.c @@ -0,0 +1,156 @@ +/* -*- 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@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 + */ + +#include "camel-pop3-folder.h" + +#define CF_CLASS (o) (CAMEL_FOLDER_CLASS (GTK_OBJECT (o)->klass)) + +static gboolean has_message_number_capability (CamelFolder *folder); +static CamelMimeMessage *get_message_by_number (CamelFolder *folder, + gint number, + CamelException *ex); +static gint get_message_count (CamelFolder *folder, CamelException *ex); + + +static void +camel_pop3_folder_class_init (CamelPop3FolderClass *camel_pop3_folder_class) +{ + CamelFolderClass *camel_folder_class = + CAMEL_FOLDER_CLASS (camel_pop3_folder_class); + + /* virtual method overload */ + camel_folder_class->has_message_number_capability = + has_message_number_capability; + camel_folder_class->get_message_by_number = + get_message_by_number; + camel_folder_class->get_message_count = + get_message_count; +} + + + +static void +camel_pop3_folder_init (gpointer object, gpointer klass) +{ + CamelFolder *folder = CAMEL_FOLDER (object); + + folder->can_hold_messages = TRUE; + folder->can_hold_folders = FALSE; + + /* Hi. I'm CamelPop3Folder. I'm useless. */ + folder->has_summary_capability = FALSE; + folder->has_uid_capability = FALSE; + folder->has_search_capability = FALSE; +} + + + + +GtkType +camel_pop3_folder_get_type (void) +{ + static GtkType camel_pop3_folder_type = 0; + + if (!camel_pop3_folder_type) { + GtkTypeInfo camel_pop3_folder_info = + { + "CamelPop3Folder", + sizeof (CamelPop3Folder), + sizeof (CamelPop3FolderClass), + (GtkClassInitFunc) camel_pop3_folder_class_init, + (GtkObjectInitFunc) camel_pop3_folder_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + camel_pop3_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_pop3_folder_info); + } + + return camel_pop3_folder_type; +} + + +CamelFolder *camel_pop3_folder_new (CamelStore *parent, CamelException *ex) +{ + CamelFolder *folder = + CAMEL_FOLDER (gtk_object_new (camel_pop3_folder_get_type ())); + + CF_CLASS (folder)->init (folder, parent, NULL, "inbox", '/', ex); + return folder; +} + +static gboolean +has_message_number_capability (CamelFolder *folder) +{ + return TRUE; +} + +static CamelMimeMessage * +get_message_by_number (CamelFolder *folder, gint number, CamelException *ex) +{ + int status; + char *body; + + status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), + NULL, "RETR %d", number); + if (status != CAMEL_POP3_OK) { + CamelService *service = CAMEL_SERVICE (folder->parent_store); + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + "Could not retrieve message from POP " + "server %s: %s.", service->url->host, + status == CAMEL_POP3_ERR ? result : + "Unknown error"); + g_free (result); + return -1; + } + + /* XXX finish this */ + return NULL +} + + +static gint get_message_count (CamelFolder *folder, CamelException *ex); +{ + int status, count; + char *result; + + status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), + &result, "STAT"); + if (status != CAMEL_POP3_OK) { + CamelService *service = CAMEL_SERVICE (folder->parent_store); + camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, + "Could not get message count from POP " + "server %s: %s.", service->url->host, + status == CAMEL_POP3_ERR ? result : + "Unknown error"); + g_free (result); + return -1; + } + + count = atoi (result); + g_free (result); + return count; +} diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h index 4af0801ab8..eb62e23658 100644 --- a/camel/providers/pop3/camel-pop3-folder.h +++ b/camel/providers/pop3/camel-pop3-folder.h @@ -46,12 +46,6 @@ extern "C" { typedef struct { CamelFolder parent_object; - CamelFolderSummary *summary; - /* the external summary is intended to be read by callers */ - - CamelPop3Summary *internal_summary; /* internal summary object */ - GList *uid_array; - } CamelPop3Folder; @@ -65,6 +59,7 @@ typedef struct { /* public methods */ +CamelFolder *camel_pop3_folder_new (CamelStore *parent, CamelException *ex); /* Standard Gtk function */ GtkType camel_pop3_folder_get_type (void); diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c index 5e5e9fe4e9..ece5171c2b 100644 --- a/camel/providers/pop3/camel-pop3-store.c +++ b/camel/providers/pop3/camel-pop3-store.c @@ -45,7 +45,9 @@ -static gboolean _connect (CamelService *service, CamelException *ex); +static gboolean connect (CamelService *service, CamelException *ex); +static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name, + CamelException *ex); static void @@ -53,9 +55,15 @@ 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); /* virtual method overload */ - camel_service_class->connect = _connect; + camel_service_class->connect = connect; + + camel_store_class->get_root_folder = camel_pop3_folder_new; + camel_store_class->get_default_folder = camel_pop3_folder_new; + camel_store_class->get_folder = get_folder; } @@ -171,16 +179,16 @@ _connect (CamelService *service, CamelException *ex) for (s = md5sum, d = md5asc; d < md5asc + 32; s++, d += 2) sprintf(d, "%.2x", *s); - status = camel_pop3_command(store->stream, NULL, "APOP %s %s", + status = camel_pop3_command(store, NULL, "APOP %s %s", service->url->user, md5asc); } g_free(buf); if (status != CAMEL_POP3_OK ) { - status = camel_pop3_command(store->stream, NULL, "USER %s", + status = camel_pop3_command(store, NULL, "USER %s", service->url->user); if (status == CAMEL_POP3_OK) { - status = camel_pop3_command(store->stream, NULL, + status = camel_pop3_command(store, NULL, "PASS %s", pass); } } @@ -195,9 +203,22 @@ _connect (CamelService *service, CamelException *ex) return TRUE; } +static CamelFolder *get_folder (CamelStore *store, const gchar *folder_name, + CamelException *ex) +{ + if (!strcasecmp (folder_name, "inbox")) + return camel_pop3_folder_new (store, ex); + else { + camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, + "No such folder `%s'.", folder_name); + return NULL; + } +} + int -camel_pop3_command (CamelStreamBuffer *stream, char **ret, char *fmt, ...) +camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...) { + CamelStreamBuffer *stream = store->stream; char *cmdbuf, *respbuf; va_list ap; int status, i; @@ -220,35 +241,52 @@ camel_pop3_command (CamelStreamBuffer *stream, char **ret, char *fmt, ...) status = CAMEL_POP3_ERR; else status = CAMEL_POP3_FAIL; + + if (ret) { + if (status != CAMEL_POP3_FAIL) { + *ret = strchr (respbuf, ' '); + if (*ret) + *ret = g_strdup (ret + 1); + } else + *ret = NULL; + } g_free (respbuf); - if (status != CAMEL_POP3_OK || !ret) - return status; + return status; +} + +char * +camel_pop3_command_get_additional_data (CamelPop3Store *store) +{ + CamelStreamBuffer *stream = store->stream; + GPtrArray *data; + char *buf; + int i, status = CAMEL_POP3_OK; - /* Read the additional data. */ data = g_ptr_array_new (); while (1) { - respbuf = camel_stream_buffer_read_line (stream); - if (!respbuf) { + buf = camel_stream_buffer_read_line (stream); + if (!buf) { status = CAMEL_POP3_FAIL; break; } - if (!strcmp (respbuf, ".")) + if (!strcmp (buf, ".")) break; - if (*respbuf == '.') - memmove (respbuf, respbuf + 1, strlen (respbuf)); - g_ptr_array_add (data, respbuf); + if (*buf == '.') + memmove (buf, buf + 1, strlen (buf)); + g_ptr_array_add (data, buf); } if (status == CAMEL_POP3_OK) { g_ptr_array_add (data, NULL); - *ret = g_strjoinv ("\n", (char **)data->pdata); - } + buf = g_strjoinv ("\n", (char **)data->pdata); + } else + buf = NULL; for (i = 0; i < data->len; i++) g_free (data->pdata[i]); g_ptr_array_free (data, TRUE); - return status; + return buf; } diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h index bf99cfd8b4..ecb37250da 100644 --- a/camel/providers/pop3/camel-pop3-store.h +++ b/camel/providers/pop3/camel-pop3-store.h @@ -62,7 +62,8 @@ typedef struct { /* support functions */ enum { CAMEL_POP3_OK, CAMEL_POP3_ERR, CAMEL_POP3_FAIL }; -int camel_pop3_command (CamelStreamBuffer *stream, char **ret, char *fmt, ...); +int camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...); +char *camel_pop3_command_get_additional_data (CamelPop3Store *store); /* Standard Gtk function */ GtkType camel_pop3_store_get_type (void); |