diff options
author | nobody <nobody@localhost> | 2000-07-06 12:58:12 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2000-07-06 12:58:12 +0800 |
commit | 5e7d23492183857392e728cec05521e320ba1b29 (patch) | |
tree | 4ba00fa4856e39912c9a54ecba72de80d51d2418 /camel/providers | |
parent | 04f148f617112009091abd18b16463033dd322d0 (diff) | |
download | gsoc2013-evolution-GTKHTML_0_5.tar gsoc2013-evolution-GTKHTML_0_5.tar.gz gsoc2013-evolution-GTKHTML_0_5.tar.bz2 gsoc2013-evolution-GTKHTML_0_5.tar.lz gsoc2013-evolution-GTKHTML_0_5.tar.xz gsoc2013-evolution-GTKHTML_0_5.tar.zst gsoc2013-evolution-GTKHTML_0_5.zip |
This commit was manufactured by cvs2svn to create tag 'GTKHTML_0_5'.GTKHTML_0_5
svn path=/tags/GTKHTML_0_5/; revision=3912
Diffstat (limited to 'camel/providers')
83 files changed, 0 insertions, 13436 deletions
diff --git a/camel/providers/.cvsignore b/camel/providers/.cvsignore deleted file mode 100644 index 3dda72986f..0000000000 --- a/camel/providers/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile.in -Makefile diff --git a/camel/providers/MH/.cvsignore b/camel/providers/MH/.cvsignore deleted file mode 100644 index 2e7b174532..0000000000 --- a/camel/providers/MH/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile.in -Makefile -.deps -*.lo -*.la -.libs diff --git a/camel/providers/MH/Makefile.am b/camel/providers/MH/Makefile.am deleted file mode 100644 index 59662a07dd..0000000000 --- a/camel/providers/MH/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmhincludedir = $(includedir)/camel - - -lib_LTLIBRARIES = libcamelmh.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-mh-provider\" - -libcamelmh_la_SOURCES = \ - camel-mh-folder.c \ - camel-mh-provider.c \ - camel-mh-store.c \ - mh-summary.c \ - mh-uid.c \ - mh-utils.c - -libcamelmhinclude_HEADERS = \ - camel-mh-folder.h \ - camel-mh-store.h \ - mh-summary.c \ - mh-uid.h \ - mh-utils.h - - -libcamelmh_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - - -EXTRA_DIST = diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c deleted file mode 100644 index f4ff8f305a..0000000000 --- a/camel/providers/MH/camel-mh-folder.c +++ /dev/null @@ -1,1022 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-folder.c : Abstract class for an email folder */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 <sys/stat.h> -#include <sys/param.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include "camel-mh-folder.h" -#include "camel-mh-store.h" -#include "gstring-util.h" -#include "camel-log.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "camel-folder-summary.h" -#include "gmime-utils.h" -#include "mh-utils.h" -#include "mh-uid.h" -#include "mh-summary.h" - - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelMhFolder */ -#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMHS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - - -static void _set_name(CamelFolder *folder, const gchar *name, CamelException *ex); -static void _init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex); -static gboolean _exists (CamelFolder *folder, CamelException *ex); -static gboolean _create(CamelFolder *folder, CamelException *ex); -static gboolean _delete (CamelFolder *folder, gboolean recurse, CamelException *ex); -static gboolean _delete_messages (CamelFolder *folder, CamelException *ex); -static GList *_list_subfolders (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *_get_message (CamelFolder *folder, gint number, CamelException *ex); -static gint _get_message_count (CamelFolder *folder, CamelException *ex); -static gint _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static void _expunge (CamelFolder *folder, CamelException *ex); -static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex); -static void _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); -static void _close (CamelFolder *folder, gboolean expunge, CamelException *ex); - -static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex); -static GList *_get_uid_list (CamelFolder *folder, CamelException *ex); - -/* some utility functions */ -static int copy_reg (const char *src_path, const char *dst_path, CamelException *ex); - -static void -camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_mh_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_folder_class->init_with_store = _init_with_store; - camel_folder_class->set_name = _set_name; - camel_folder_class->exists = _exists; - camel_folder_class->delete = _delete; - camel_folder_class->delete_messages = _delete_messages; - camel_folder_class->list_subfolders = _list_subfolders; - camel_folder_class->get_message = _get_message; - camel_folder_class->get_message_count = _get_message_count; - camel_folder_class->append_message = _append_message; - camel_folder_class->expunge = _expunge; - camel_folder_class->copy_message_to = _copy_message_to; - camel_folder_class->open = _open; - camel_folder_class->close = _close; - camel_folder_class->get_message_uid = _get_message_uid; - camel_folder_class->get_message_by_uid = _get_message_by_uid; - camel_folder_class->get_uid_list = _get_uid_list; - -} - - - - - - - -GtkType -camel_mh_folder_get_type (void) -{ - static GtkType camel_mh_folder_type = 0; - - if (!camel_mh_folder_type) { - GtkTypeInfo camel_mh_folder_info = - { - "CamelMhFolder", - sizeof (CamelMhFolder), - sizeof (CamelMhFolderClass), - (GtkClassInitFunc) camel_mh_folder_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mh_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_mh_folder_info); - } - - return camel_mh_folder_type; -} - - - -static gint -_message_name_compare (gconstpointer a, gconstpointer b) -{ - gchar *m1 = (gchar *)a; - gchar *m2 = (gchar *)b; - gint len_diff; - - return (atoi (m1) - atoi (m2)); -} - - -static void -_init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex) -{ - /* call parent method */ - parent_class->init_with_store (folder, parent_store, ex); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = TRUE; - folder->has_uid_capability = TRUE; - - folder->summary = NULL; - -} - - - -static void -_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - struct dirent *dir_entry; - DIR *dir_handle; - - - if (folder->open_state == FOLDER_OPEN) return; - - - /* create message list */ - /* read the whole folder and sort message names */ - dir_handle = opendir (mh_folder->directory_path); - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, mh_folder->directory_path)) - /* add the file name to the list */ - mh_folder->file_name_list = g_list_insert_sorted (mh_folder->file_name_list, - g_strdup (dir_entry->d_name), - _message_name_compare); - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - /* get (or create) uid list */ - if (!(mh_load_uid_list (mh_folder) > 0)) - mh_generate_uid_list (mh_folder); - - /* get or create summary */ - /* it is important that it comes after uid list reading/generation */ - if (!(mh_load_summary (mh_folder) > 0)) - mh_generate_summary (folder); - printf ("**** summary = %p\n", folder->summary); - -} - - - -static void -_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - - /* save uid list, if any */ - if (mh_folder->uid_array) - mh_save_uid_list (mh_folder); - - /* save summary, if any */ - if (folder->summary) - mh_save_summary (mh_folder); - - /* call parent implementation */ - parent_class->close (folder, expunge, ex); -} - - - - - -/** - * camel_mh_folder_set_name: set the name of an MH folder - * @folder: the folder to set the name - * @name: a string representing the (short) name - * - * - * - **/ -static void -_set_name (CamelFolder *folder, const gchar *name, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - const gchar *root_dir_path; - gchar *full_name; - const gchar *parent_full_name; - gchar separator; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::set_name\n"); - g_assert (folder); - g_assert (name); - g_assert (folder->parent_store); - - /* call default implementation */ - parent_class->set_name (folder, name, ex); - - if (mh_folder->directory_path) g_free (mh_folder->directory_path); - - separator = camel_store_get_separator (folder->parent_store); - root_dir_path = camel_mh_store_get_toplevel_dir (CAMEL_MH_STORE(folder->parent_store)); - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name full_name is %s\n", folder->full_name); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name root_dir_path is %s\n", root_dir_path); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::separator is %c\n", separator); - - mh_folder->directory_path = g_strdup_printf ("%s%c%s", root_dir_path, separator, folder->full_name); - - if (!camel_folder_exists (folder, ex)) return; - - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name mh_folder->directory_path is %s\n", - mh_folder->directory_path); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::set_name\n"); -} - - - -static gboolean -_exists (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - struct stat stat_buf; - gint stat_error; - gboolean exists; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::exists\n"); - g_assert (folder); - - if (!mh_folder->directory_path) return FALSE; - - stat_error = stat (mh_folder->directory_path, &stat_buf); - if (stat_error == -1) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::exists when executing stat on %s, stat_error = %d\n", - mh_folder->directory_path, stat_error); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - return FALSE; - } - exists = S_ISDIR (stat_buf.st_mode); - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::exists\n"); - return exists; -} - - -static gboolean -_create (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - mode_t dir_mode = S_IRWXU; - gint mkdir_error; - - g_assert(folder); - - /* call default implementation */ - parent_class->create (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (camel_folder_exists (folder, ex)) return TRUE; - - mkdir_error = mkdir (directory_path, dir_mode); - return (mkdir_error == -1); -} - - - -static gboolean -_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - gint rmdir_error = 0; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete (folder, recurse, ex); - /* the default implementation will care about deleting - messages first and recursing the operation if - necessary */ - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return TRUE; - - /* physically delete the directory */ - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete removing directory %s\n", directory_path); - rmdir_error = rmdir (directory_path); - if (rmdir_error == -1) { - CAMEL_LOG_WARNING ("CamelMhFolder::delete Error when removing directory %s\n", directory_path); - CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); - } - - return (rmdir_error != -1); -} - - -static gboolean -_delete_messages (CamelFolder *folder, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct stat stat_buf; - gint stat_error = 0; - gchar *entry_name; - struct dirent *dir_entry; - gint unlink_error = 0; - DIR *dir_handle; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete_messages (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return TRUE; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while ((stat_error != -1) && (unlink_error != -1) && (dir_entry != NULL)) { - - /* get the name of the next entry in the dir */ - entry_name = dir_entry->d_name; - stat_error = stat (mh_folder->directory_path, &stat_buf); - - /* is it a regular file ? */ - if ((stat_error != -1) && S_ISREG(stat_buf.st_mode)) { - /* yes, delete it */ - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete_messages removing file %s\n", entry_name); - unlink_error = unlink(entry_name); - - if (unlink_error == -1) { - CAMEL_LOG_WARNING ("CamelMhFolder::delete_messages Error when deleting file %s\n", - entry_name); - CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); - } - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return ((stat_error != -1) && (unlink_error != -1)); - -} - - - -static GList * -_list_subfolders (CamelFolder *folder, CamelException *ex) -{ - GList *subfolder_name_list = NULL; - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct stat stat_buf; - gint stat_error = 0; - GList *file_list; - gchar *entry_name; - gchar *full_entry_name; - struct dirent *dir_entry; - DIR *dir_handle; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete_messages (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return NULL; - - if (!camel_folder_exists (folder, ex)) return NULL; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while ((stat_error != -1) && (dir_entry != NULL)) { - - /* get the name of the next entry in the dir */ - entry_name = dir_entry->d_name; - full_entry_name = g_strdup_printf ("%s/%s", mh_folder->directory_path, entry_name); - stat_error = stat (full_entry_name, &stat_buf); - g_free (full_entry_name); - - /* is it a directory ? */ - if ((stat_error != -1) && S_ISDIR (stat_buf.st_mode)) { - /* yes, add it to the list */ - if (entry_name[0] != '.') { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::list_subfolders adding %s\n", entry_name); - subfolder_name_list = g_list_append (subfolder_name_list, g_strdup (entry_name)); - } - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return subfolder_name_list; -} - - - - - -static void -_filename_free (gpointer data) -{ - g_free ((gchar *)data); -} - - -/* slow routine, may be optimixed, or we should use - caches if users complain */ -static CamelMimeMessage * -_get_message (CamelFolder *folder, gint number, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - gchar *message_name; - gchar *message_file_name; - CamelStream *input_stream = NULL; - CamelMimeMessage *message = NULL; - GList *message_list = NULL; - - g_assert(folder); - - - directory_path = mh_folder->directory_path; - if (!directory_path) return NULL; - - - - message_name = g_list_nth_data (mh_folder->file_name_list, number); - - if (message_name != NULL) { - CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, name = %s\n", - number, message_name); - message_file_name = g_strdup_printf ("%s/%s", directory_path, message_name); - input_stream = camel_stream_buffered_fs_new_with_name (message_file_name, CAMEL_STREAM_BUFFERED_FS_READ); - - if (input_stream != NULL) { -#warning use session field here - message = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); - gtk_object_unref (GTK_OBJECT (input_stream)); - message->message_number = number; - gtk_object_set_data_full (GTK_OBJECT (message), "filename", - g_strdup (message_name), _filename_free); - -#warning Set flags and all this stuff here - } - g_free (message_file_name); - } else - CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, not found\n", number); - - - return message; -} - - - -static gint -_get_message_count (CamelFolder *folder, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - guint message_count = 0; - - g_assert(folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) return -1; - - if (!camel_folder_exists (folder, ex)) return 0; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) - message_count++; - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::get_message_count found %d messages\n", message_count); - return message_count; -} - - - -static gboolean -_find_next_free_message_file (CamelFolder *folder, gint *new_msg_number, gchar **new_msg_filename, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - gint last_max_message_number = 0; - gint current_message_number; - - g_assert(folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return FALSE; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) { - /* see if the message number is the biggest found */ - current_message_number = atoi (dir_entry->d_name); - if (current_message_number > last_max_message_number) - last_max_message_number = current_message_number; - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - closedir (dir_handle); - - *new_msg_number = last_max_message_number + 1; - *new_msg_filename = g_strdup_printf ("%s/%d", directory_path, *new_msg_number); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::find_next_free_message_file new message path is %s\n", - *new_msg_filename); - return TRUE; - - -} -static gint -_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - guint new_msg_number; - gchar *new_msg_filename; - CamelStream *output_stream; - gboolean error; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::append_message\n"); - if (!_find_next_free_message_file (folder, &new_msg_number, &new_msg_filename, ex)) - return -1; - - output_stream = camel_stream_fs_new_with_name (new_msg_filename, CAMEL_STREAM_FS_WRITE); - if (output_stream != NULL) { - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); - camel_stream_close (output_stream); - } else { - CAMEL_LOG_WARNING ("CamelMhFolder::append_message could not open %s for writing\n", - new_msg_filename); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - error = TRUE; - } - - g_free (new_msg_filename); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::append_message\n"); - if (error) return -1; - else return new_msg_number; -} - - - - - -static void -_expunge (CamelFolder *folder, CamelException *ex) -{ - /* For the moment, we look in the folder active message - * list. I did not make my mind for the moment, should - * the gtk_object->destroy signal be used to expunge - * freed messages objects marked DELETED ? - */ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - CamelMimeMessage *message; - GList *message_node; - gchar *fullpath; - gchar *filename; - gint unlink_error; - const gchar *directory_path; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelFolder::expunge\n"); - - message_node = folder->message_list; - - directory_path = mh_folder->directory_path; - if (!directory_path) return; - - /* look in folder message list which messages - * need to be expunged */ - while ( message_node) { - message = CAMEL_MIME_MESSAGE (message_node->data); - - if (message && camel_mime_message_get_flag (message, "DELETED")) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::expunge, expunging message %d\n", message->message_number); - /* expunge the message */ - filename = gtk_object_get_data (GTK_OBJECT (message), "filename"); - fullpath = g_strdup_printf ("%s/%s", directory_path, filename); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::expunge, message fullpath is %s\n", - fullpath); - unlink_error = unlink(fullpath); - if (unlink_error != -1) { - message->expunged = TRUE; - } else { - CAMEL_LOG_WARNING ("CamelMhFolder:: could not unlink %s (message %d)\n", - fullpath, message->message_number); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - } - } - message_node = message_node->next; - CAMEL_LOG_FULL_DEBUG ("CamelFolder::expunge, examined message node %p\n", message_node); - } - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelFolder::expunge\n"); -} - - -static void -_copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex) -{ - gchar *src_msg_filename; - guint dest_msg_number; - gchar *dest_msg_filename; - - if (IS_CAMEL_MH_FOLDER (dest_folder)) { - /*g_return_if_fail (message->parent_folder == folder);*/ - - if (!_find_next_free_message_file (dest_folder, &dest_msg_number, &dest_msg_filename, ex)) - return; - src_msg_filename = gtk_object_get_data (GTK_OBJECT (message), "fullpath"); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::copy_to copy file %s to %s\n", src_msg_filename, dest_msg_filename); - copy_reg (src_msg_filename, dest_msg_filename, ex); - - } else - parent_class->copy_message_to (folder, message, dest_folder, ex); -} - - - -/** UID **/ - -static const gchar * -_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GArray *uid_array; - gboolean found = FALSE; - MhUidCouple *uid_couple; - gchar *filename; - guint file_number; - gint i; - - /* if the message already has its uid stored, - return it */ - if (message->message_uid) - return (message->message_uid); - - /* else, it has a filename associated to it */ - filename = gtk_object_get_data (GTK_OBJECT (message), "filename"); - file_number = atoi (file_number); - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - /* look in the uid array for the file number */ - found = (uid_couple->file_number == file_number); - for (i=0; (i<uid_array->len) && (!found); i++) { - uid_couple++; - found = (uid_couple->file_number == file_number); - } - - if (found) return uid_couple->uid; - else return NULL; - -} - - -static CamelMimeMessage * -_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GArray *uid_array; - gboolean found = FALSE; - MhUidCouple *uid_couple; - gint file_number; - gchar *filename; - CamelMimeMessage *message = NULL; - CamelStream *input_stream; - int i; - - /* - * because they are constructed with md5 - * signatures, all MH uids are 16 bytes long - */ - if (strlen (uid) != 16) return NULL; - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - found = !strncmp (uid, uid_couple->uid, 16 * sizeof (guchar)); - for (i=0; (i<uid_array->len) && (!found); i++) { - uid_couple++; - found = !strncmp (uid, uid_couple->uid, 16 * sizeof (guchar)); - } - if (found) { - /* physically retrieve the message */ - file_number = uid_couple->file_number; - filename = g_strdup_printf ("%d", file_number); - input_stream = camel_stream_buffered_fs_new_with_name (filename, CAMEL_STREAM_BUFFERED_FS_READ); - - if (input_stream != NULL) { -#warning use session field here - message = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); - gtk_object_unref (GTK_OBJECT (input_stream)); - - /* set message UID in CamelMimeMessage */ - message->message_uid = g_strdup (uid); - - } - g_free (filename); - } - - return message; - -} - -static GList * -_get_uid_list (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GList *uid_list; - GArray *uid_array; - MhUidCouple *uid_couple; - int i; - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - for (i=0; i<uid_array->len; i++) { - uid_list = g_list_prepend (uid_list, uid_couple->uid); - uid_couple++; - } - - return uid_list; -} - - - - - - - - -/************************************************************************/ - -/*** Took directly from GNU fileutils-4.0 ***/ -/* Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation. */ -/* This may be rwritten soon. -Bertrand */ - - -/* Write LEN bytes at PTR to descriptor DESC, retrying if interrupted. - Return LEN upon success, write's (negative) error code otherwise. */ -int -full_write (int desc, const char *ptr, size_t len) -{ - int total_written; - - total_written = 0; - while (len > 0) - { - int written = write (desc, ptr, len); - if (written < 0) - { - if (errno == EINTR) - continue; - return written; - } - total_written += written; - ptr += written; - len -= written; - } - return total_written; -} - - - - -static int -copy_reg (const char *src_path, const char *dst_path, CamelException *ex) -{ - char *buf; - int buf_size; - int dest_desc; - int source_desc; - int n_read; - struct stat sb; - char *cp; - int *ip; - int return_val = 0; - off_t n_read_total = 0; - int last_write_made_hole = 0; - int make_holes = TRUE; - - source_desc = open (src_path, O_RDONLY); - if (source_desc < 0) - { - /* If SRC_PATH doesn't exist, then chances are good that the - user did something like this `cp --backup foo foo': and foo - existed to start with, but copy_internal renamed DST_PATH - with the backup suffix, thus also renaming SRC_PATH. */ - if (errno == ENOENT) - error (0, 0, "`%s' and `%s' are the same file", - src_path, dst_path); - else - error (0, errno, "%s", src_path); - - return -1; - } - - /* Create the new regular file with small permissions initially, - to not create a security hole. */ - - dest_desc = open (dst_path, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (dest_desc < 0) - { - error (0, errno, "cannot create regular file `%s'", dst_path); - return_val = -1; - goto ret2; - } - - /* Find out the optimal buffer size. */ - - if (fstat (dest_desc, &sb)) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - - buf_size = 8192; - - - - /* Make a buffer with space for a sentinel at the end. */ - - buf = (char *) alloca (buf_size + sizeof (int)); - - for (;;) - { - n_read = read (source_desc, buf, buf_size); - if (n_read < 0) - { - if (errno == EINTR) - continue; - error (0, errno, "%s", src_path); - return_val = -1; - goto ret; - } - if (n_read == 0) - break; - - n_read_total += n_read; - - ip = 0; - if (make_holes) - { - buf[n_read] = 1; /* Sentinel to stop loop. */ - - /* Find first nonzero *word*, or the word with the sentinel. */ - - ip = (int *) buf; - while (*ip++ == 0) - ; - - /* Find the first nonzero *byte*, or the sentinel. */ - - cp = (char *) (ip - 1); - while (*cp++ == 0) - ; - - /* If we found the sentinel, the whole input block was zero, - and we can make a hole. */ - - if (cp > buf + n_read) - { - /* Make a hole. */ - if (lseek (dest_desc, (off_t) n_read, SEEK_CUR) < 0L) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - last_write_made_hole = 1; - } - else - /* Clear to indicate that a normal write is needed. */ - ip = 0; - } - if (ip == 0) - { - if (full_write (dest_desc, buf, n_read) < 0) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - last_write_made_hole = 0; - } - } - - /* If the file ends with a `hole', something needs to be written at - the end. Otherwise the kernel would truncate the file at the end - of the last write operation. */ - - if (last_write_made_hole) - { -#if HAVE_FTRUNCATE - /* Write a null character and truncate it again. */ - if (full_write (dest_desc, "", 1) < 0 - || ftruncate (dest_desc, n_read_total) < 0) -#else - /* Seek backwards one character and write a null. */ - if (lseek (dest_desc, (off_t) -1, SEEK_CUR) < 0L - || full_write (dest_desc, "", 1) < 0) -#endif - { - error (0, errno, "%s", dst_path); - return_val = -1; - } - } - -ret: - if (close (dest_desc) < 0) - { - error (0, errno, "%s", dst_path); - return_val = -1; - } -ret2: - if (close (source_desc) < 0) - { - error (0, errno, "%s", src_path); - return_val = -1; - } - - return return_val; -} diff --git a/camel/providers/MH/camel-mh-folder.h b/camel/providers/MH/camel-mh-folder.h deleted file mode 100644 index 40800375eb..0000000000 --- a/camel/providers/MH/camel-mh-folder.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-folder.h : Abstract class for an email folder */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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_MH_FOLDER_H -#define CAMEL_MH_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-folder.h" -/* #include "camel-store.h" */ - -#define CAMEL_MH_FOLDER_TYPE (camel_mh_folder_get_type ()) -#define CAMEL_MH_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_MH_FOLDER_TYPE, CamelMhFolder)) -#define CAMEL_MH_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MH_FOLDER_TYPE, CamelMhFolderClass)) -#define IS_CAMEL_MH_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_MH_FOLDER_TYPE)) - - -typedef struct { - CamelFolder parent_object; - - gchar *directory_path; - GList *file_name_list; - GArray *uid_array; - -} CamelMhFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelMhFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mh_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MH_FOLDER_H */ diff --git a/camel/providers/MH/camel-mh-provider.c b/camel/providers/MH/camel-mh-provider.c deleted file mode 100644 index 316b8a0797..0000000000 --- a/camel/providers/MH/camel-mh-provider.c +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-provider.c: mh provider registration code */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 "camel-mh-store.h" -#include "camel-provider.h" -#include "camel-log.h" - - -static CamelProvider _mh_provider = { - (GtkType) 0, - PROVIDER_STORE, - "mh", - "Camel default mh provider", - "This is a very simple provider, mh is a bad protocol anyway", - (GModule *) NULL -}; - - - -CamelProvider * -camel_provider_module_init () -{ - _mh_provider.object_type = camel_mh_store_get_type(); - return &_mh_provider; -} diff --git a/camel/providers/MH/camel-mh-store.c b/camel/providers/MH/camel-mh-store.c deleted file mode 100644 index 60ba07f47b..0000000000 --- a/camel/providers/MH/camel-mh-store.c +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-store.c : class for an mh store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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-mh-store.h" -#include "camel-mh-folder.h" -#include "url-util.h" - -static CamelStoreClass *parent_class=NULL; - -/* Returns the class for a CamelMhStore */ -#define CMHS_CLASS(so) CAMEL_MH_STORE_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (GTK_OBJECT(so)->klass) - -static void _init (CamelStore *store, CamelSession *session, const gchar *url_name); -static CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name); - - -static void -camel_mh_store_class_init (CamelMhStoreClass *camel_mh_store_class) -{ - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_mh_store_class); - - parent_class = gtk_type_class (camel_store_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_store_class->init = _init; - camel_store_class->get_folder = _get_folder; -} - - - -static void -camel_mh_store_init (gpointer object, gpointer klass) -{ - CamelMhStore *mh_store = CAMEL_MH_STORE (object); - CamelStore *store = CAMEL_STORE (object); - - store->separator = '/'; -} - - - - -GtkType -camel_mh_store_get_type (void) -{ - static GtkType camel_mh_store_type = 0; - - if (!camel_mh_store_type) { - GtkTypeInfo camel_mh_store_info = - { - "CamelMhStore", - sizeof (CamelMhStore), - sizeof (CamelMhStoreClass), - (GtkClassInitFunc) camel_mh_store_class_init, - (GtkObjectInitFunc) camel_mh_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mh_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_mh_store_info); - } - - return camel_mh_store_type; -} - - - - -/* These evil public functions are here for test only */ -void -camel_mh_store_set_toplevel_dir (CamelMhStore *store, const gchar *toplevel) -{ - store->toplevel_dir = g_strdup (toplevel); - CAMEL_STORE(store)->separator = '/'; -} - - -const gchar * -camel_mh_store_get_toplevel_dir (CamelMhStore *store) -{ - return store->toplevel_dir; -} - - - -static void -_init (CamelStore *store, CamelSession *session, const gchar *url_name) -{ - CamelMhStore *mh_store = CAMEL_MH_STORE (store); - Gurl *store_url; - - g_assert (url_name); - /* call parent implementation */ - parent_class->init (store, session, url_name); - - - /* find the path in the URL*/ - store_url = g_url_new (url_name); - - g_return_if_fail (store_url); - g_return_if_fail (store_url->path); - - mh_store->toplevel_dir = g_strdup (store_url->path); - g_url_free (store_url); - - - -} - - -static CamelFolder * -_get_folder (CamelStore *store, const gchar *folder_name) -{ - CamelMhFolder *new_mh_folder; - CamelFolder *new_folder; - - /* check if folder has already been created */ - /* call the standard routine for that when */ - /* it is done ... */ - - new_mh_folder = gtk_type_new (CAMEL_MH_FOLDER_TYPE); - new_folder = CAMEL_FOLDER (new_mh_folder); - - CF_CLASS (new_folder)->init_with_store (new_folder, store, NULL); - CF_CLASS (new_folder)->set_name (new_folder, folder_name, NULL); - - - return new_folder; -} diff --git a/camel/providers/MH/camel-mh-store.h b/camel/providers/MH/camel-mh-store.h deleted file mode 100644 index 924a5a6fc5..0000000000 --- a/camel/providers/MH/camel-mh-store.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mhstore.h : class for an mh store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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_MH_STORE_H -#define CAMEL_MH_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-store.h" - -#define CAMEL_MH_STORE_TYPE (camel_mh_store_get_type ()) -#define CAMEL_MH_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_MH_STORE_TYPE, CamelMhStore)) -#define CAMEL_MH_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MH_STORE_TYPE, CamelMhStoreClass)) -#define IS_CAMEL_MH_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_MH_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - - gchar *toplevel_dir; -} CamelMhStore; - - - -typedef struct { - CamelStoreClass parent_class; - - -} CamelMhStoreClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mh_store_get_type (void); - -void camel_mh_store_set_toplevel_dir (CamelMhStore *store, const gchar *toplevel); -const gchar *camel_mh_store_get_toplevel_dir (CamelMhStore *store); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MH_STORE_H */ - - diff --git a/camel/providers/MH/mh-summary.c b/camel/providers/MH/mh-summary.c deleted file mode 100644 index 5a964696e0..0000000000 --- a/camel/providers/MH/mh-summary.c +++ /dev/null @@ -1,290 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 "mh-uid.h" -#include "camel-log.h" -#include "camel-stream.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "gmime-utils.h" -#include "mh-utils.h" - -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> - -void -mh_generate_summary (CamelFolder *folder) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - CamelFolderSummary *summary; - CamelMessageInfo *message_info; - CamelFolderInfo *subfolder_info; - CamelStream *message_stream; - guint file_number; - gchar *message_fullpath; - gchar *directory_path; - GArray *header_array; - MhUidCouple *uid_couple; - Rfc822Header *cur_header; - int i; - int n_file; - GArray *uid_array; - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary entering \n"); - - g_assert (folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary folder has no directory path\n"); - return; - } - - summary = camel_folder_summary_new (); - folder->summary = summary; - - uid_array = mh_folder->uid_array; - - if (!uid_array) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary " - "no uid list, that probably means there is " - "no message in this folder, exiting \n"); - return; - } - uid_couple = (MhUidCouple *)uid_array->data; - - for (n_file=0; n_file<uid_array->len; n_file++) { - - file_number = uid_couple->file_number; - - message_info = g_new0 (CamelMessageInfo, 1); - message_info->uid = g_new0 (guchar, 17); - strncpy (message_info->uid, uid_couple->uid, 16); - - - message_fullpath = g_strdup_printf ("%s/%d", directory_path, file_number); - message_stream = camel_stream_buffered_fs_new_with_name (message_fullpath, - CAMEL_STREAM_BUFFERED_FS_READ); - if (!message_stream) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary " - "could not open %d for reading\n", message_fullpath); - g_free (message_fullpath); - return; - } - g_free (message_fullpath); - - header_array = get_header_array_from_stream (message_stream); - gtk_object_unref (GTK_OBJECT (message_stream)); - - for (i=0; i<header_array->len; i++) { - cur_header = (Rfc822Header *)header_array->data + i; - if (!g_strcasecmp (cur_header->name, "subject")) { - message_info->subject = cur_header->value; - g_free (cur_header->name); - } else if (!g_strcasecmp (cur_header->name, "sender")) { - message_info->date = cur_header->value; - g_free (cur_header->name); - } else if (!g_strcasecmp (cur_header->name, "date")) { - message_info->date = cur_header->value; - g_free (cur_header->name); - } else { - g_free (cur_header->name); - g_free (cur_header->value); - } - } - g_array_free (header_array, TRUE); - - summary->message_info_list = g_list_append (summary->message_info_list, message_info); - - /* next message in the uid list */ - uid_couple++; - } - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary leaving \n"); - -} - - -void -mh_save_summary (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - CamelFolderSummary *summary; - GList *msg_info_list; - CamelMessageInfo *msg_info; - gchar *directory_path = mh_folder->directory_path; - gchar *summary_file_path; - gint fd; - gint i; - gint field_lgth; - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::save_summary entering \n"); - - summary = CAMEL_FOLDER (mh_folder)->summary; - if (!summary) return; - - summary_file_path = g_strdup_printf ("%s/%s", directory_path, ".camel-summary"); - CAMEL_LOG_FULL_DEBUG ("In the process of writing %s\n", summary_file_path); - fd = open (summary_file_path, O_WRONLY | O_CREAT ); - - if (!fd) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for writing. Exiting.\n", summary_file_path); - g_free (summary_file_path); - return; - } - g_free (summary_file_path); - - msg_info_list = summary->message_info_list; - while (msg_info_list) { - msg_info = msg_info_list->data; - /* write subject */ - field_lgth = msg_info->subject ? strlen (msg_info->subject) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->subject, field_lgth); - - /* write uid */ - field_lgth = msg_info->uid ? strlen (msg_info->uid) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->uid, field_lgth); - - /* write date */ - field_lgth = msg_info->date ? strlen (msg_info->date) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->date, field_lgth); - - /* write sender */ - field_lgth = msg_info->sender ? strlen (msg_info->sender) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->sender, field_lgth); - - msg_info_list = msg_info_list->next; - - } - - close (fd); - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::save_summary leaving \n"); - -} - - - - - -gint -mh_load_summary (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - CamelFolderSummary *summary; - CamelMessageInfo *msg_info; - gchar *directory_path = mh_folder->directory_path; - gchar *summary_file_path; - gint fd; - gint i; - gint field_lgth; - gboolean file_eof; - gint stat_error; - struct stat stat_buf; - - summary = CAMEL_FOLDER (mh_folder)->summary; - if (summary) return 1; /* should we regenerate it ? */ - - summary_file_path = g_strdup_printf ("%s/%s", directory_path, ".camel-summary"); - CAMEL_LOG_FULL_DEBUG ("In the process of reading %s\n", summary_file_path); - fd = open (summary_file_path, O_RDONLY); - /* tests if file exists */ - stat_error = stat (summary_file_path, &stat_buf); - - if (!((stat_error != -1) && S_ISREG (stat_buf.st_mode))) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for reading. Exiting.\n", summary_file_path); - g_free (summary_file_path); - return -1; - } - g_free (summary_file_path); - - for (;;) { - /* read subject */ - file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (file_eof) break; - - - /* allcate a summary if needed */ - if (!summary) - summary = camel_folder_summary_new (); - /* allocate a message info struct */ - msg_info = g_new0 (CamelMessageInfo, 1); - - if (!file_eof && (field_lgth > 0)) { - msg_info->subject = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->subject, field_lgth); - } else - msg_info->subject = NULL; - - /* read uid */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->uid = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->uid, field_lgth); - } else - msg_info->uid = NULL; - - /* read date */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->date = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->date, field_lgth); - } else - msg_info->date = NULL; - - /* read sender */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->sender = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->sender, field_lgth); - } else - msg_info->sender = NULL; - - summary->message_info_list = g_list_prepend (summary->message_info_list, - msg_info); - } - - CAMEL_FOLDER (mh_folder)->summary = summary; - - close (fd); - return 1; -} - - diff --git a/camel/providers/MH/mh-summary.h b/camel/providers/MH/mh-summary.h deleted file mode 100644 index 27c9a21f60..0000000000 --- a/camel/providers/MH/mh-summary.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 MH_SUMMARY_H -#define MH_SUMMARY_H 1 - -#include <glib.h> -#include "camel-mh-folder.h" - -void mh_generate_summary (CamelFolder *folder); -void mh_save_summary (CamelMhFolder *mh_folder); -gint mh_load_summary (CamelMhFolder *mh_folder); - -#endif /* MH_SUMMARY_H */ diff --git a/camel/providers/MH/mh-uid.c b/camel/providers/MH/mh-uid.c deleted file mode 100644 index ebcccacd23..0000000000 --- a/camel/providers/MH/mh-uid.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 "mh-uid.h" -#include "camel-log.h" -#include "camel-stream.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "gmime-utils.h" -#include "md5-utils.h" -#include "mh-utils.h" - -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> - -void -mh_uid_get_for_file (gchar *filename, guchar uid[16]) -{ - CamelStream *message_stream; - GArray *header_array; - Rfc822Header *cur_header; - int i; - MD5Context ctx; - - - message_stream = camel_stream_buffered_fs_new_with_name (filename, - CAMEL_STREAM_BUFFERED_FS_READ); - header_array = get_header_array_from_stream (message_stream); - gtk_object_unref (GTK_OBJECT (message_stream)); - - md5_init (&ctx); - for (i=0; i<header_array->len; i++) { - cur_header = (Rfc822Header *)header_array->data + i; - if (!g_strcasecmp (cur_header->name, "subject")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } else if (!g_strcasecmp (cur_header->name, "sender")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } else if (!g_strcasecmp (cur_header->name, "date")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } - - g_free (cur_header->name); - g_free (cur_header->value); - - } - - g_array_free (header_array, TRUE); - - md5_final (&ctx, uid); -} - - - - -void -mh_save_uid_list (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - gchar *directory_path = mh_folder->directory_path; - gchar *uidfile_path; - int fd; - int i; - - - uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); - CAMEL_LOG_FULL_DEBUG ("In the process of writing %s\n", uidfile_path); - fd = open (uidfile_path, O_WRONLY | O_CREAT ); - - if (!fd) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for writing. Exiting.\n", uidfile_path); - g_free (uidfile_path); - return; - } - g_free (uidfile_path); - - uid_array = mh_folder->uid_array; - first_uid_couple = (MhUidCouple *)uid_array->data; - - /* write the number of uid contained in the file */ - write (fd, &(uid_array->len), sizeof (guint)); - CAMEL_LOG_FULL_DEBUG ("%d entrie present in the list\n", uid_array->len); - /* now write the array of uid self */ - write (fd, first_uid_couple, sizeof (MhUidCouple) * uid_array->len); - - close (fd); -} - - -gint -mh_load_uid_list (CamelMhFolder *mh_folder) -{ - GArray *new_uid_array; - MhUidCouple *first_uid_couple; - gchar *directory_path = mh_folder->directory_path; - gchar *uidfile_path; - int fd; - guint uid_nb; - struct stat stat_buf; - gint stat_error = 0; - - uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); - - /* tests if file exists */ - stat_error = stat (uidfile_path, &stat_buf); - - - if (!((stat_error != -1) && S_ISREG (stat_buf.st_mode))) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::load_uid_list " - "file %s does not exist. Exiting.\n", uidfile_path); - g_free (uidfile_path); - return -1; - } - - fd = open (uidfile_path, O_RDONLY); - g_free (uidfile_path); - if (!fd) return -1; - - if (mh_folder->uid_array) g_array_free (mh_folder->uid_array, FALSE); - - /* read the number of uids in the file */ - read (fd, &uid_nb, sizeof (guint)); - CAMEL_LOG_FULL_DEBUG ("reading %d uid_entries\n", uid_nb); - new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); - new_uid_array = g_array_set_size (new_uid_array, uid_nb); - first_uid_couple = (MhUidCouple *)new_uid_array->data; - - - read (fd, first_uid_couple, sizeof (MhUidCouple) * uid_nb); - - mh_folder->uid_array = new_uid_array; - - return 1; -} - - -gint -mh_generate_uid_list (CamelMhFolder *mh_folder) -{ - GArray *new_uid_array; - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - gchar *msg_path; - guint msg_count; - MhUidCouple *uid_couple; - guint file_number; - - g_assert (mh_folder); - CAMEL_LOG_FULL_DEBUG ("in the process of creating uid list \n"); - directory_path = mh_folder->directory_path; - if (!directory_path) { - CAMEL_LOG_FULL_DEBUG ("folder has no directory path. Exiting\n"); - return -1; - } - - msg_count = camel_folder_get_message_count (CAMEL_FOLDER (mh_folder), NULL); - if (!msg_count) { - CAMEL_LOG_FULL_DEBUG ("no message in %s. Exiting\n", directory_path); - return -1; - } - - new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); - new_uid_array = g_array_set_size (new_uid_array, msg_count); - uid_couple = (MhUidCouple *)new_uid_array->data; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) { - - /* get the uid for this message */ - msg_path = g_strdup_printf ("%s/%s", directory_path, dir_entry->d_name); - mh_uid_get_for_file (msg_path, uid_couple->uid); - g_free (msg_path); - - /* convert filename into file number */ - uid_couple->file_number = atoi (dir_entry->d_name); - uid_couple++; - } - - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - mh_folder->uid_array = new_uid_array; -} diff --git a/camel/providers/MH/mh-uid.h b/camel/providers/MH/mh-uid.h deleted file mode 100644 index 63dfe5b159..0000000000 --- a/camel/providers/MH/mh-uid.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 MH_UID_H -#define MH_UID_H 1 - -#include <glib.h> -#include "camel-mh-folder.h" - - -typedef struct { - gchar uid[16]; - guint file_number; -} MhUidCouple; - -void mh_uid_get_for_file (gchar *filename, guchar uid[16]); -void mh_save_uid_list (CamelMhFolder *mh_folder); -gint mh_load_uid_list (CamelMhFolder *mh_folder); -gint mh_generate_uid_list (CamelMhFolder *mh_folder); - -#endif /* MH_UID_H */ diff --git a/camel/providers/MH/mh-utils.c b/camel/providers/MH/mh-utils.c deleted file mode 100644 index 51bb84bc65..0000000000 --- a/camel/providers/MH/mh-utils.c +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 "mh-utils.h" - -#include <sys/stat.h> - -gboolean -mh_is_a_message_file (const gchar *file_name, const gchar *file_path) -{ - struct stat stat_buf; - gint stat_error = 0; - gboolean ok; - gchar *full_file_name; - int i; - - /* test if the name is a number */ - i=0; - while ((file_name[i] != '\0') && (file_name[i] >= '0') && (file_name[i] <= '9')) - i++; - if ((i==0) || (file_name[i] != '\0')) return FALSE; - - /* is it a regular file ? */ - full_file_name = g_strdup_printf ("%s/%s", file_path, file_name); - stat_error = stat (full_file_name, &stat_buf); - g_free (full_file_name); - - return ((stat_error != -1) && S_ISREG (stat_buf.st_mode)); -} - diff --git a/camel/providers/MH/mh-utils.h b/camel/providers/MH/mh-utils.h deleted file mode 100644 index 968228b0a3..0000000000 --- a/camel/providers/MH/mh-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * 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 MH_UTILS_H -#define MH_UTILS_H 1 - -#include <glib.h> - -gboolean mh_is_a_message_file (const gchar *file_name, const gchar *file_path); - -#endif /* MH_UTILS_H */ diff --git a/camel/providers/Makefile.am b/camel/providers/Makefile.am deleted file mode 100644 index dec31c0cb9..0000000000 --- a/camel/providers/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = mbox pop3 sendmail smtp vee imap - -# these ones are disabled for the moment. -# MH maildir nntp smtp 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 8ac7f8c1fa..0000000000 --- a/camel/providers/imap/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -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) \ - -DG_LOG_DOMAIN=\"camel-imap-provider\" - -libcamelimap_la_SOURCES = \ - camel-imap-folder.c \ - camel-imap-provider.c \ - camel-imap-store.c \ - camel-imap-stream.c - -libcamelimapinclude_HEADERS = \ - camel-imap-folder.h \ - camel-imap-store.h \ - camel-imap-stream.h - -libcamelimap_la_LDFLAGS = -version-info 0:0:0 - -EXTRA_DIST = libcamelimap.urls - - - - - diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c deleted file mode 100644 index 0b997225b9..0000000000 --- a/camel/providers/imap/camel-imap-folder.c +++ /dev/null @@ -1,1295 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ -/* camel-imap-folder.c: Abstract class for an email 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 "camel-imap-folder.h" -#include "camel-imap-store.h" -#include "camel-imap-stream.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) - -#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (GTK_OBJECT (o)->klass)) - -static CamelFolderClass *parent_class = NULL; - -static void imap_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar *separator, gboolean path_begns_with_sep, - CamelException *ex); - -static void imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex); -static gint imap_get_message_count (CamelFolder *folder, CamelException *ex); -static void imap_append_message (CamelFolder *folder, CamelMimeMessage *message, 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); -static GPtrArray *imap_get_uids (CamelFolder *folder, CamelException *ex); -static gboolean imap_parse_subfolder_line (gchar *buf, gchar **flags, gchar **sep, gchar **folder); -static GPtrArray *imap_get_subfolder_names (CamelFolder *folder, CamelException *ex); -static GPtrArray *imap_get_summary (CamelFolder *folder, CamelException *ex); -static void imap_free_summary (CamelFolder *folder, GPtrArray *array); -static CamelMimeMessage *imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex); -static void imap_delete_message (CamelFolder *folder, const gchar *uid, CamelException *ex); - -static void imap_expunge (CamelFolder *folder, CamelException *ex); - -static const CamelMessageInfo *imap_get_message_info (CamelFolder *folder, const char *uid); - -static GList *imap_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex); - -static void imap_finalize (GtkObject *object); - -/* flag methods */ -static guint32 imap_get_permanent_flags (CamelFolder *folder, CamelException *ex); -static guint32 imap_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex); -static void imap_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set, - CamelException *ex); -static gboolean imap_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name, - CamelException *ex); -static void imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, - gboolean value, CamelException *ex); - -static void -camel_imap_folder_class_init (CamelImapFolderClass *camel_imap_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_imap_folder_class); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - - /* virtual method overload */ - camel_folder_class->init = imap_init; - camel_folder_class->sync = imap_sync; - camel_folder_class->expunge = imap_expunge; - - camel_folder_class->get_uids = imap_get_uids; - camel_folder_class->get_subfolder_names = imap_get_subfolder_names; - - camel_folder_class->get_message_count = imap_get_message_count; - camel_folder_class->get_message = imap_get_message; - camel_folder_class->append_message = imap_append_message; - camel_folder_class->delete_message = imap_delete_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 = imap_free_summary; - - camel_folder_class->search_by_expression = imap_search_by_expression; - - camel_folder_class->get_permanent_flags = imap_get_permanent_flags; - 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_flags = imap_get_message_user_flags;*/ - /*camel_folder_class->set_message_user_flags = imap_set_message_user_flags;*/ - - gtk_object_class->finalize = imap_finalize; -} - -static void -camel_imap_folder_init (gpointer object, gpointer klass) -{ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object); - CamelFolder *folder = CAMEL_FOLDER (object); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = TRUE; - folder->has_search_capability = FALSE; /* default - we have to query IMAP to know for sure */ - - imap_folder->summary = NULL; - imap_folder->count = -1; -} - -GtkType -camel_imap_folder_get_type (void) -{ - static GtkType camel_imap_folder_type = 0; - - if (!camel_imap_folder_type) { - GtkTypeInfo camel_imap_folder_info = - { - "CamelImapFolder", - sizeof (CamelImapFolder), - sizeof (CamelImapFolderClass), - (GtkClassInitFunc) camel_imap_folder_class_init, - (GtkObjectInitFunc) camel_imap_folder_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_imap_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_imap_folder_info); - } - - return camel_imap_folder_type; -} - -CamelFolder * -camel_imap_folder_new (CamelStore *parent, char *folder_name, CamelException *ex) -{ - CamelFolder *folder = CAMEL_FOLDER (gtk_object_new (camel_imap_folder_get_type (), NULL)); - - CF_CLASS (folder)->init (folder, parent, NULL, folder_name, "/", FALSE, ex); - - return folder; -} - -static void -imap_finalize (GtkObject *object) -{ - /* TODO: do we need to do more here? */ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (object); - CamelMessageInfo *info; - gint i, max; - - GTK_OBJECT_CLASS (parent_class)->finalize (object); - - g_return_if_fail (imap_folder->summary != NULL); - - max = imap_folder->summary->len; - for (i = 0; i < max; i++) { - info = g_ptr_array_index (imap_folder->summary, i); - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info->uid); - g_free (info); - info = NULL; - } - - g_ptr_array_free (imap_folder->summary, TRUE); - imap_folder->summary = NULL; -} - -static void -imap_init (CamelFolder *folder, CamelStore *parent_store, CamelFolder *parent_folder, - const gchar *name, gchar *separator, gboolean path_begins_with_sep, CamelException *ex) -{ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - CamelStore *store = CAMEL_STORE (parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - int status; - char *result, *folder_path; - - /* call parent method */ - parent_class->init (folder, parent_store, parent_folder, name, separator, path_begins_with_sep, ex); - if (camel_exception_get_id (ex)) - return; - - /* we assume that the parent init - method checks for the existance of @folder */ - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = TRUE; - folder->has_search_capability = CAMEL_IMAP_STORE (store)->has_search_capability; - - /* some IMAP daemons support user-flags * - * I would not, however, rely on this feature as * - * most IMAP daemons are not 100% RFC compliant */ - folder->permanent_flags = CAMEL_MESSAGE_SEEN | - CAMEL_MESSAGE_ANSWERED | - CAMEL_MESSAGE_FLAGGED | - CAMEL_MESSAGE_DELETED | - CAMEL_MESSAGE_DRAFT | - CAMEL_MESSAGE_USER; - - - imap_folder->search = NULL; - imap_folder->summary = NULL; - - /* SELECT the IMAP mail spool */ - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "SELECT %s", folder_path); - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not SELECT %s on IMAP server %s: %s.", - folder->full_name, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - } else { - /* parse the mode we opened it in */ - } - g_free (result); - g_free (folder_path); -} - -static void -imap_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ -#if 0 - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - gint i, max; - - /* uhhh...this is kinda unsafe so we'll leave it blocked out */ - if (imap_folder->summary) { - max = imap_folder->summary->len; - for (i = 0; i < max; i++) { - CamelMessageInfo *info; - - info = (CamelMessageInfo *) g_ptr_array_index (imap_folder->summary, i); - if (info->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) { - char *flags; - - flags = g_strconcat (info->flags & CAMEL_MESSAGE_SEEN ? "\\Seen " : "", - info->flags & CAMEL_MESSAGE_DRAFT ? "\\Draft " : "", - info->flags & CAMEL_MESSAGE_DELETED ? "\\Deleted " : "", - info->flags & CAMEL_MESSAGE_DELETED ? "\\Answered " : "", - NULL); - if (*flags) { - gchar *result; - gint s; - - *(flags + strlen (flags) - 1) = '\0'; - s = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), - folder, &result, - "UID STORE %s FLAGS.SILENT (%s)", - info->uid, flags); - - if (s != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not set flags on message %s on IMAP " - "server %s: %s.", info->uid, - service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - return; - } - - g_free(result); - } - g_free (flags); - } - } - } -#endif - - if (expunge) - imap_expunge (folder, ex); -} - -static void -imap_expunge (CamelFolder *folder, CamelException *ex) -{ - gchar *result; - gint status; - - g_return_if_fail (folder != NULL); - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "EXPUNGE"); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not EXPUNGE from IMAP server %s: %s.", - service->url->host, - status == CAMEL_IMAP_ERR && result ? result : - "Unknown error"); - g_free (result); - return; - } - - g_free (result); -} - -#if 0 -static gboolean -imap_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ - /* TODO: code this & what should this do? delete messages or the folder? */ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - gboolean folder_already_exists; - - g_return_val_if_fail (folder != NULL, FALSE); - - /* check if the folder object exists */ - - /* in the case where the folder does not exist, - return immediatly */ - folder_already_exists = camel_folder_exists (folder, ex); - if (camel_exception_get_id (ex)) - return FALSE; - - if (!folder_already_exists) - return TRUE; - - /* call default implementation. - It should delete the messages in the folder - and recurse the operation to subfolders */ - parent_class->delete (folder, recurse, ex); - if (camel_exception_get_id (ex)) - return FALSE; - - if (!(folder->full_name || folder->name)) { - camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "invalid folder path. Use set_name ?"); - return FALSE; - } - - /* delete the directory - we must start with the leaves and work - back to the root if we are to delete recursively */ - - /* TODO: Finish this... */ - - return TRUE; -} -#endif - -static gint -imap_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - CamelStore *store = CAMEL_STORE (folder->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *msg_count, *folder_path; - gint status; - - g_return_val_if_fail (folder != NULL, -1); - - /* If we already have a count, return */ - if (imap_folder->count != -1) - return imap_folder->count; - - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "STATUS %s (MESSAGES)", folder_path); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get message count for %s from IMAP " - "server %s: %s.", folder_path, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return -1; - } - g_free (folder_path); - - /* parse out the message count - should come in the form: "* STATUS <folder> (MESSAGES <count>)\r\n" */ - if (result && *result == '*') { - if ((msg_count = strstr (result, "MESSAGES")) != NULL) { - msg_count += strlen ("MESSAGES") + 1; - - for ( ; *msg_count == ' '; msg_count++); - - /* we should now be pointing to the message count */ - imap_folder->count = atoi (msg_count); - } - } - g_free (result); - - return imap_folder->count; -} - -static void -imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelStore *store = CAMEL_STORE (folder->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - CamelStreamMem *mem; - gchar *result, *folder_path; - gint status; - - g_return_if_fail (folder != NULL); - g_return_if_fail (message != NULL); - - /* write the message to a CamelStreamMem so we can get it's size */ - mem = CAMEL_STREAM_MEM (camel_stream_mem_new ()); - if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (mem)) == -1) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not APPEND message to IMAP server %s: %s.", - service->url->host, - g_strerror (errno)); - - return; - } - - mem->buffer = g_byte_array_append (mem->buffer, g_strdup ("\r\n"), 3); - - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - /* FIXME: len isn't really correct I don't think, we need to filter and possibly other things */ - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), - folder, &result, - "APPEND %s (\\Seen) {%d}\r\n%s", - folder_path, mem->buffer->len - 1, mem->buffer->data); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not APPEND message to IMAP server %s: %s.", - service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return; - } - - g_free (result); - g_free (folder_path); -} - -static void -imap_copy_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex) -{ - CamelStore *store = CAMEL_STORE (source->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - char *result, *folder_path; - int status; - - if (url && url->path && *(url->path + 1) && strcmp (destination->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, destination->full_name); - else - folder_path = g_strdup (destination->full_name); - - status = camel_imap_command (CAMEL_IMAP_STORE (store), NULL, &result, - "COPY %s %s", uid, folder_path); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not COPY message %s to %s on IMAP server %s: %s.", - uid, folder_path, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return; - } - - g_free (result); - g_free (folder_path); -} - -/* FIXME: Duplication of code! */ -static void -imap_move_message_to (CamelFolder *source, const char *uid, CamelFolder *destination, CamelException *ex) -{ - CamelStore *store = CAMEL_STORE (source->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - CamelMessageInfo *info; - char *result, *folder_path; - int status; - - if (url && url->path && *(url->path + 1) && strcmp (destination->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, destination->full_name); - else - folder_path = g_strdup (destination->full_name); - - status = camel_imap_command (CAMEL_IMAP_STORE (store), NULL, &result, - "COPY %s %s", uid, folder_path); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not COPY message %s to %s on IMAP server %s: %s.", - uid, folder_path, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return; - } - - g_free (result); - g_free (folder_path); - - if (!(info = (CamelMessageInfo *)imap_get_message_info (source, uid))) { - CamelService *service = CAMEL_SERVICE (store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not set flags for message %s on IMAP server %s: %s", - uid, service->url->host, "Unknown error"); - return; - } - - info->flags |= CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED; -} - -static GPtrArray * -imap_get_uids (CamelFolder *folder, CamelException *ex) -{ - CamelMessageInfo *info; - GPtrArray *array, *infolist; - gint i, count; - - infolist = imap_get_summary (folder, ex); - count = infolist->len; - - array = g_ptr_array_new (); - g_ptr_array_set_size (array, count); - for (i = 0; i < count; i++) { - info = (CamelMessageInfo *) g_ptr_array_index (infolist, i); - array->pdata[i] = g_strdup (info->uid); - } - - imap_free_summary (folder, infolist); - - return array; -} - -static gboolean -imap_parse_subfolder_line (gchar *buf, gchar **flags, gchar **sep, gchar **folder) -{ - gchar *ptr, *eptr; - - *flags = NULL; - *sep = NULL; - *folder = NULL; - - if (strncasecmp (buf, "* LIST", 6)) - return FALSE; - - ptr = strstr (buf + 6, "("); - if (!ptr) - return FALSE; - - ptr++; - eptr = strstr (ptr, ")"); - if (!eptr) - return FALSE; - - *flags = g_strndup (ptr, (gint)(eptr - ptr)); - - ptr = strstr (eptr, "\""); - if (!ptr) - return FALSE; - - ptr++; - eptr = strstr (ptr, "\""); - if (!eptr) - return FALSE; - - *sep = g_strndup (ptr, (gint)(eptr - ptr)); - - ptr = eptr + 1; - *folder = g_strdup (ptr); - g_strstrip (*folder); - - return TRUE; -} - -static GPtrArray * -imap_get_subfolder_names (CamelFolder *folder, CamelException *ex) -{ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - CamelStore *store = CAMEL_STORE (folder->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - GPtrArray *listing; - gint status; - gchar *result, *folder_path; - - g_return_val_if_fail (folder != NULL, g_ptr_array_new()); - - if (imap_folder->count != -1) - return g_ptr_array_new (); - - if (url && url->path) { - if (!strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup (url->path + 1); - else - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - } else { - folder_path = g_strdup (folder->full_name); - } - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "LIST \"\" \"%s%s\"", folder_path, - *folder_path ? "/*" : "*"); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get subfolder listing from IMAP " - "server %s: %s.", service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return g_ptr_array_new (); - } - - /* parse out the subfolders */ - listing = g_ptr_array_new (); - if (result) { - char *ptr = result; - - while (ptr && *ptr == '*') { - gchar *flags, *sep, *folder, *buf, *end, *f; - gboolean ret; - - for (end = ptr; *end && *end != '\n'; end++); - buf = g_strndup (ptr, (gint)(end - ptr)); - ptr = end; - - ret = imap_parse_subfolder_line (buf, &flags, &sep, &folder); - g_free (buf); - - if (!ret || (flags && strstr (flags, "NoSelect"))) { - g_free (flags); - g_free (sep); - g_free (folder); - - if (*ptr == '\n') - ptr++; - - continue; - } - g_free (flags); - - /* chop out the folder prefix */ - if (*folder_path && !strncmp (folder, folder_path, strlen (folder_path))) { - f = folder + strlen (folder_path) + 1; - memmove (folder, f, strlen (f) + 1); - } - printf ("adding folder: %s\n", folder); - - g_ptr_array_add (listing, folder); - - g_free (sep); /* TODO: decide if we really need dir_sep */ - - if (*ptr == '\n') - ptr++; - } - } - g_free (result); - g_free (folder_path); - - return listing; -} - -static void -imap_delete_message (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMessageInfo *info; - - if (!(info = (CamelMessageInfo *)imap_get_message_info (folder, uid))) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not set flags for message %s on IMAP server %s: %s", - uid, service->url->host, "Unknown error"); - return; - } - - info->flags |= CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED; -} - -static CamelMimeMessage * -imap_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelStream *msgstream; - /*CamelStreamFilter *f_stream;*/ - /*CamelMimeFilter *filter;*/ - CamelMimeMessage *msg; - /*CamelMimePart *part;*/ - gchar *result, *header, *body, *mesg, *p, *q; - int id, status, part_len; - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "UID FETCH %s BODY.PEEK[HEADER]", uid); - - if (!result || status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not fetch message %s on IMAP server %s: %s", - uid, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - return camel_mime_message_new (); - } - - for (p = result; *p && *p != '{' && *p != '\n'; p++); - if (*p != '{') { - g_free (result); - return camel_mime_message_new (); - } - - part_len = atoi (p + 1); - for ( ; *p && *p != '\n'; p++); - if (*p != '\n') { - g_free (result); - return camel_mime_message_new (); - } - - /* calculate the new part-length */ - for (q = p; *q && (q - p) <= part_len; q++) { - if (*q == '\n') - part_len--; - } - - header = g_strndup (p, part_len); - - g_free (result); - printf ("*** We got the header ***\n"); - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "UID FETCH %s BODY[TEXT]", uid); - - if (!result || status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not fetch message %s on IMAP server %s: %s", - uid, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (header); - return camel_mime_message_new (); - } - - for (p = result; *p && *p != '{' && *p != '\n'; p++); - if (*p != '{') { - g_free (result); - g_free (header); - return camel_mime_message_new (); - } - - part_len = atoi (p + 1); - for ( ; *p && *p != '\n'; p++); - if (*p != '\n') { - g_free (result); - g_free (header); - return camel_mime_message_new (); - } - - /* calculate the new part-length */ - for (q = p; *q && (q - p) <= part_len; q++) { - if (*q == '\n') - part_len--; - } - - body = g_strndup (p, part_len); - - g_free (result); - printf ("*** We got the body ***\n"); - - mesg = g_strdup_printf ("%s\n%s", header, body); - g_free (header); - g_free (body); - printf ("*** We got the mesg ***\n"); - - fprintf (stderr, "Message:\n%s\n", mesg); - - msgstream = camel_stream_mem_new_with_buffer (mesg, strlen (mesg) + 1); -#if 0 - f_stream = camel_stream_filter_new_with_stream (msgstream); - filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS); - id = camel_stream_filter_add (f_stream, CAMEL_MIME_FILTER (filter)); -#endif - msg = camel_mime_message_new (); - printf ("*** We created the camel_mime_message ***\n"); - - camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), msgstream); -#if 0 - camel_stream_filter_remove (f_stream, id); - camel_stream_close (CAMEL_STREAM (f_stream)); -#endif - gtk_object_unref (GTK_OBJECT (msgstream)); - /*gtk_object_unref (GTK_OBJECT (f_stream));*/ - - printf ("*** We're returning... ***\n"); - - return msg; - -#if 0 - CamelStream *imap_stream; - CamelStream *msgstream; - CamelStreamFilter *f_stream; /* will be used later w/ crlf filter */ - CamelMimeFilter *filter; /* crlf/dot filter */ - CamelMimeMessage *msg; - CamelMimePart *part; - CamelDataWrapper *cdw; - gchar *cmdbuf; - int id; - - /* TODO: fetch the correct part, get rid of the hard-coded stuff */ - cmdbuf = g_strdup_printf ("UID FETCH %s BODY[TEXT]", uid); - imap_stream = camel_imap_stream_new (CAMEL_IMAP_FOLDER (folder), cmdbuf); - g_free (cmdbuf); - - - /* Temp hack - basically we read in the entire message instead of getting a part as it's needed */ - msgstream = camel_stream_mem_new (); - camel_stream_write_to_stream (CAMEL_STREAM (imap_stream), msgstream); - gtk_object_unref (GTK_OBJECT (imap_stream)); - - f_stream = camel_stream_filter_new_with_stream (msgstream); - filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_DECODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS); - id = camel_stream_filter_add (f_stream, CAMEL_MIME_FILTER (filter)); - - msg = camel_mime_message_new (); - - /*cdw = camel_data_wrapper_new ();*/ - /*camel_data_wrapper_construct_from_stream (cdw, CAMEL_STREAM (f_stream));*/ - camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), CAMEL_STREAM (f_stream)); - - camel_stream_filter_remove (f_stream, id); - camel_stream_close (CAMEL_STREAM (f_stream)); - gtk_object_unref (GTK_OBJECT (msgstream)); - gtk_object_unref (GTK_OBJECT (f_stream)); - - /*camel_data_wrapper_set_mime_type (cdw, "text/plain");*/ - - /*camel_medium_set_content_object (CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER (cdw));*/ - /*gtk_object_unref (GTK_OBJECT (cdw));*/ - - return msg; -#endif -} - -/* This probably shouldn't go here...but it will for now */ -static gchar * -get_header_field (gchar *header, gchar *field) -{ - gchar *part, *index, *p, *q; - - index = strstrcase (header, field); - if (index == NULL) - return NULL; - - p = index + strlen (field) + 1; - for (q = p; *q; q++) - if (*q == '\n' && (*(q + 1) != ' ' || *(q + 1) != '\t')) - break; - - part = g_strndup (p, (gint)(q - p)); - - /* it may be wrapped on multiple lines, so lets strip out \n's */ - for (p = part; *p; ) { - if (*p == '\r' || *p == '\n') - memmove(p, p + 1, strlen (p) - 1); - else - p++; - } - - return part; -} - -GPtrArray * -imap_get_summary (CamelFolder *folder, CamelException *ex) -{ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - GPtrArray *array = NULL; - CamelMessageInfo *info; - gint num, i = 0, status = 0; - char *result, *datestr, *p, *q; - - if (imap_folder->summary) - return imap_folder->summary; - - num = imap_get_message_count (folder, ex); - - array = g_ptr_array_new (); - - for (i = 1; i <= num; i++) { - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "FETCH %d BODY.PEEK[HEADER]", i); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get summary for %s on IMAP server %s: %s", - folder->full_name, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - break; - } - - info = g_malloc0 (sizeof (CamelMessageInfo)); - info->subject = get_header_field (result, "\nSubject:"); - info->to = get_header_field (result, "\nTo:"); - info->from = get_header_field (result, "\nFrom:"); - - datestr = get_header_field (result, "\nDate:"); - info->date_sent = header_decode_date (datestr, NULL); - g_free (datestr); - g_free (result); - - /* now to get the UID */ - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "FETCH %d UID", i); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get summary for %s on IMAP server %s: %s", - folder->full_name, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - if (!result || *result != '*') { - g_free (result); - fprintf (stderr, "Warning: UID for message %d not found\n", i); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - p = strchr (result, '('); - if (!p || strncasecmp (p + 1, "UID", 3)) { - g_free (result); - fprintf (stderr, "Warning: UID for message %d not found\n", i); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - for (p += 4; *p && (*p < '0' || *p > '9'); p++); /* advance to <uid> */ - for (q = p; *q && *q != ')' && *q != ' '; q++); /* find the end of the <uid> */ - info->uid = g_strndup (p, (gint)(q - p)); - printf ("*** info->uid = %s\n", info->uid); - g_free (result); - - /* now to get the flags */ - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "FETCH %d FLAGS", i); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get summary for %s on IMAP server %s: %s", - folder->full_name, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - if (!result || *result != '*') { - g_free (result); - fprintf (stderr, "Warning: FLAGS for message %d not found\n", i); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - p = strchr (result, '(') + 1; - if (strncasecmp (p, "FLAGS", 5)) { - g_free (result); - fprintf (stderr, "Warning: FLAGS for message %d not found\n", i); - - g_free (info->subject); - g_free (info->to); - g_free (info->from); - g_free (info); - info = NULL; - - break; - } - - /* now we gotta parse for the flags */ - info->flags = 0; - if (strstr (p, "\\Seen")) - info->flags |= CAMEL_MESSAGE_SEEN; - if (strstr (p, "\\Answered")) - info->flags |= CAMEL_MESSAGE_ANSWERED; - if (strstr (p, "\\Flagged")) - info->flags |= CAMEL_MESSAGE_FLAGGED; - if (strstr (p, "\\Deleted")) - info->flags |= CAMEL_MESSAGE_DELETED; - if (strstr (p, "\\Draft")) - info->flags |= CAMEL_MESSAGE_DRAFT; - - g_free (result); - - g_ptr_array_add (array, info); - } - - imap_folder->summary = array; - - return array; -} - -void -imap_free_summary (CamelFolder *folder, GPtrArray *array) -{ - /* no-op */ - return; -} - -/* 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); - CamelMessageInfo *info = NULL; - char *result, *datestr, *p; - int status; - - /* lets first check to see if we have the message info cached */ - if (imap_folder->summary) { - int max, i; - - max = imap_folder->summary->len; - for (i = 0; i < max; i++) { - info = g_ptr_array_index (imap_folder->summary, i); - if (!strcmp(info->uid, uid)) - return info; - } - } - - /* we don't have a cached copy, so fetch it */ - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "UID FETCH %s BODY.PEEK[HEADER]", uid); - - if (status != CAMEL_IMAP_OK) { - g_free (result); - return NULL; - } - - info = g_malloc0 (sizeof (CamelMessageInfo)); - info->subject = get_header_field (result, "\nSubject:"); - info->to = get_header_field (result, "\nTo:"); - info->from = get_header_field (result, "\nFrom:"); - - datestr = get_header_field (result, "\nDate:"); - info->date_sent = header_decode_date (datestr, NULL); - g_free (datestr); - - info->uid = g_strdup (uid); - g_free (result); - - /* now to get the flags */ - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "UID FETCH %s FLAGS", uid); - - if (status != CAMEL_IMAP_OK) { - g_free (result); - fprintf (stderr, "Warning: Error getting FLAGS for message %s\n", uid); - - return info; /* I guess we should return what we got so far? */ - } - - if (!result || *result != '*') { - g_free (result); - fprintf (stderr, "Warning: FLAGS for message %s not found\n", uid); - - return info; /* I guess we should return what we got so far? */ - } - - p = strchr (result, '(') + 1; - if (strncasecmp (p, "FLAGS", 5)) { - g_free (result); - fprintf (stderr, "Warning: FLAGS for message %s not found\n", uid); - - return info; /* I guess we should return what we got so far? */ - } - - /* now we gotta parse for the flags */ - info->flags = 0; - if (strstr (p, "\\Seen")) - info->flags |= CAMEL_MESSAGE_SEEN; - if (strstr (p, "\\Answered")) - info->flags |= CAMEL_MESSAGE_ANSWERED; - if (strstr (p, "\\Flagged")) - info->flags |= CAMEL_MESSAGE_FLAGGED; - if (strstr (p, "\\Deleted")) - info->flags |= CAMEL_MESSAGE_DELETED; - if (strstr (p, "\\Draft")) - info->flags |= CAMEL_MESSAGE_DRAFT; - - g_free (result); - - /* since we didn't have it cached, lets add it to our cache */ - if (imap_folder->summary) { - g_ptr_array_add (imap_folder->summary, info); - } else { - imap_folder->summary = g_ptr_array_new (); - g_ptr_array_add (imap_folder->summary, info); - } - - return info; -} - -static GList * -imap_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex) -{ - return NULL; -#if 0 - /* NOTE: This is experimental code... */ - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - char *result; - int status; - - if (!imap_folder->has_search_capability) - return NULL; - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), folder, - &result, "SEARCH %s", expression); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get summary for %s on IMAP server %s: %s", - folder->full_name, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - return NULL; - } - - /* now to parse @result */ -#endif -} - -static guint32 -imap_get_permanent_flags (CamelFolder *folder, CamelException *ex) -{ - /* return permamnant flags */ - return folder->permanent_flags; -} - -static guint32 -imap_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex) -{ - CamelMessageInfo *info; - - if (!(info = (CamelMessageInfo *)imap_get_message_info (folder, uid))) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get flags for message %s on IMAP server %s: %s", - uid, service->url->host, "Unknown error"); - return 0; - } - - return info->flags; -} - -static void -imap_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set, CamelException *ex) -{ - CamelMessageInfo *info; - - if (!(info = (CamelMessageInfo *)imap_get_message_info (folder, uid))) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not set flags for message %s on IMAP server %s: %s", - uid, service->url->host, "Unknown error"); - return; - } - - info->flags = (info->flags & ~flags) | (set & flags) | CAMEL_MESSAGE_FOLDER_FLAGGED; -} - -static gboolean -imap_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name, CamelException *ex) -{ - return FALSE; -} - -static void -imap_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, gboolean value, CamelException *ex) -{ - return; -} diff --git a/camel/providers/imap/camel-imap-folder.h b/camel/providers/imap/camel-imap-folder.h deleted file mode 100644 index 17f6d505d2..0000000000 --- a/camel/providers/imap/camel-imap-folder.h +++ /dev/null @@ -1,74 +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 <gtk/gtk.h> -#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) (GTK_CHECK_CAST((obj), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolder)) -#define CAMEL_IMAP_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_IMAP_FOLDER_TYPE, CamelImapFolderClass)) -#define IS_CAMEL_IMAP_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_IMAP_FOLDER_TYPE)) - -typedef struct { - CamelFolder parent_object; - - CamelFolderSearch *search; /* used to run searches */ - GPtrArray *summary; - gint count; -} CamelImapFolder; - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelImapFolderClass; - - -/* public methods */ -CamelFolder *camel_imap_folder_new (CamelStore *parent, char *folder_name, - CamelException *ex); -void camel_imap_folder_set_namespace (CamelFolder *folder, gchar *namespace); - -/* Standard Gtk function */ -GtkType 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 b9d8c74847..0000000000 --- a/camel/providers/imap/camel-imap-provider.c +++ /dev/null @@ -1,109 +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", - "IMAPv4", - - "For reading and storing mail on IMAP servers.", - - "mail", - - 0, - - { 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 75da7529b3..0000000000 --- a/camel/providers/imap/camel-imap-store.c +++ /dev/null @@ -1,740 +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 <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-imap-store.h" -#include "camel-imap-folder.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" - -/* Specified in RFC 2060 */ -#define IMAP_PORT 143 - -static CamelServiceClass *service_class = NULL; - -static void finalize (GtkObject *object); -static gboolean imap_create (CamelFolder *folder, CamelException *ex); -static gboolean imap_connect (CamelService *service, CamelException *ex); -static gboolean imap_disconnect (CamelService *service, CamelException *ex); -static GList *query_auth_types (CamelService *service, CamelException *ex); -static void free_auth_types (CamelService *service, GList *authtypes); -static char *get_name (CamelService *service, gboolean brief); -static CamelFolder *get_folder (CamelStore *store, const char *folder_name, gboolean create, - CamelException *ex); -static char *get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); -static int camel_imap_status (char *cmdid, char *respbuf); - -static void -camel_imap_store_class_init (CamelImapStoreClass *camel_imap_store_class) -{ - /* virtual method overload */ - GtkObjectClass *object_class = - GTK_OBJECT_CLASS (camel_imap_store_class); - CamelServiceClass *camel_service_class = - CAMEL_SERVICE_CLASS (camel_imap_store_class); - CamelStoreClass *camel_store_class = - CAMEL_STORE_CLASS (camel_imap_store_class); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - object_class->finalize = finalize; - - camel_service_class->connect = imap_connect; - camel_service_class->disconnect = imap_disconnect; - camel_service_class->query_auth_types = query_auth_types; - camel_service_class->free_auth_types = free_auth_types; - camel_service_class->get_name = get_name; - - camel_store_class->get_folder = get_folder; - camel_store_class->get_folder_name = get_folder_name; -} - -static void -camel_imap_store_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - CamelStore *store = CAMEL_STORE (object); - - service->url_flags = (CAMEL_SERVICE_URL_NEED_USER | CAMEL_SERVICE_URL_NEED_HOST); - - store->folders = g_hash_table_new (g_str_hash, g_str_equal); -} - -GtkType -camel_imap_store_get_type (void) -{ - static GtkType camel_imap_store_type = 0; - - if (!camel_imap_store_type) { - GtkTypeInfo camel_imap_store_info = - { - "CamelImapStore", - sizeof (CamelImapStore), - sizeof (CamelImapStoreClass), - (GtkClassInitFunc) camel_imap_store_class_init, - (GtkObjectInitFunc) camel_imap_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_imap_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_imap_store_info); - } - - return camel_imap_store_type; -} - -static void -finalize (GtkObject *object) -{ - CamelException ex; - - camel_exception_init (&ex); - imap_disconnect (CAMEL_SERVICE (object), &ex); - camel_exception_clear (&ex); -} - -static CamelServiceAuthType password_authtype = { - "Password", - - "This option will connect to the IMAP server using a " - "plaintext password.", - - "", - TRUE -}; - -static gboolean -try_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - gint fd; - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - sin.sin_family = h->h_addrtype; - sin.sin_port = htons (service->url->port ? service->url->port : IMAP_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - - /* We don't want to set a CamelException here */ - - if (fd > -1) - close (fd); - - return FALSE; - } - - close (fd); - return TRUE; -} - -static GList * -query_auth_types (CamelService *service, CamelException *ex) -{ - GList *ret = NULL; - gboolean passwd = TRUE; - - - if (service->url) { - passwd = try_connect (service, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return NULL; - } - - if (passwd) - ret = g_list_append (ret, &password_authtype); - - if (!ret) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to IMAP server on " - "%s.", service->url->host); - } - - return ret; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -static char * -get_name (CamelService *service, gboolean brief) -{ - if (brief) - return g_strdup_printf ("IMAP server %s", service->url->host); - else { - return g_strdup_printf ("IMAP service for %s on %s", - service->url->user, - service->url->host); - } -} - -static gboolean -imap_connect (CamelService *service, CamelException *ex) -{ - CamelImapStore *store = CAMEL_IMAP_STORE (service); - struct hostent *h; - struct sockaddr_in sin; - gint fd, status; - gchar *buf, *msg, *result, *errbuf = NULL; - gboolean authenticated = FALSE; - - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - /* connect to the IMAP server */ - sin.sin_family = h->h_addrtype; - if (service->url->port) - sin.sin_port = htons(service->url->port); - else - sin.sin_port = htons(IMAP_PORT); - - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to %s (port %s): %s", - service->url->host, service->url->port, - strerror(errno)); - if (fd > -1) - close (fd); - - return FALSE; - } - - store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); - store->command = 0; - - /* Read the greeting, if any. */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - if (!buf) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not read greeting from IMAP " - "server: %s", - camel_exception_get_description (ex)); - - imap_disconnect (service, ex); - return FALSE; - } - g_free (buf); - - /* authenticate the user */ - while (!authenticated) { - if (errbuf) { - /* We need to un-cache the password before prompting again */ - camel_session_query_authenticator (camel_service_get_session (service), - CAMEL_AUTHENTICATOR_TELL, NULL, - TRUE, service, "password", ex); - g_free (service->url->passwd); - service->url->passwd = NULL; - } - - if (!service->url->authmech && !service->url->passwd) { - gchar *prompt; - - prompt = g_strdup_printf ("%sPlease enter the IMAP password for %s@%s", - errbuf ? errbuf : "", service->url->user, h->h_name); - service->url->passwd = - camel_session_query_authenticator (camel_service_get_session (service), - CAMEL_AUTHENTICATOR_ASK, prompt, - TRUE, service, "password", ex); - g_free (prompt); - g_free (errbuf); - errbuf = NULL; - - if (!service->url->passwd) { - imap_disconnect (service, ex); - return FALSE; - } - } - - status = camel_imap_command (store, NULL, &msg, "LOGIN \"%s\" \"%s\"", - service->url->user, - service->url->passwd); - - if (status != CAMEL_IMAP_OK) { - errbuf = g_strdup_printf ("Unable to authenticate to IMAP server.\n" - "Error sending password: %s\n\n", - msg ? msg : "(Unknown)"); - } else { - g_message ("IMAP Service sucessfully authenticated user %s", service->url->user); - authenticated = TRUE; - } - } - - /* Now lets find out the IMAP capabilities */ - status = camel_imap_command_extended (store, NULL, &result, "CAPABILITY"); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (store); - - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get capabilities on IMAP server %s: %s.", - service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - } - - if (strstrcase (result, "SEARCH")) - store->has_search_capability = TRUE; - else - store->has_search_capability = FALSE; - - g_free (result); - - fprintf (stderr, "IMAP provider does%shave SEARCH support\n", store->has_search_capability ? " " : "n't "); - - service_class->connect (service, ex); - - return TRUE; -} - -static gboolean -imap_disconnect (CamelService *service, CamelException *ex) -{ - CamelImapStore *store = CAMEL_IMAP_STORE (service); - - if (!service->connected) - return TRUE; - - if (!service_class->disconnect (service, ex)) - return FALSE; - - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - store->ostream = NULL; - store->istream = NULL; - - return TRUE; -} - -const gchar * -camel_imap_store_get_toplevel_dir (CamelImapStore *store) -{ - CamelURL *url = CAMEL_SERVICE (store)->url; - - g_assert (url != NULL); - return url->path; -} - -static gboolean -imap_folder_exists (CamelFolder *folder) -{ - CamelStore *store = CAMEL_STORE (folder->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *folder_path; - gint status; - - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - printf ("doing an EXAMINE...\n"); - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), NULL, - &result, "EXAMINE %s", folder_path); - - if (status != CAMEL_IMAP_OK) { - g_free (result); - g_free (folder_path); - return FALSE; - } - g_free (folder_path); - g_free (result); - - return TRUE; -} - -static gboolean -imap_create (CamelFolder *folder, CamelException *ex) -{ - CamelStore *store = CAMEL_STORE (folder->parent_store); - CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *result, *folder_path; - gint status; - - g_return_val_if_fail (folder != NULL, FALSE); - - if (!(folder->full_name || folder->name)) { - camel_exception_set (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "invalid folder path. Use set_name ?"); - return FALSE; - } - - if (!strcmp (folder->full_name, "INBOX")) - return TRUE; - - if (imap_folder_exists (folder)) - return TRUE; - - /* create the directory for the subfolder */ - if (url && url->path && *(url->path + 1) && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), NULL, - &result, "CREATE %s", folder_path); - - if (status != CAMEL_IMAP_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not CREATE %s on IMAP server %s: %s.", - folder_path, service->url->host, - status == CAMEL_IMAP_ERR ? result : - "Unknown error"); - g_free (result); - g_free (folder_path); - return FALSE; - } - g_free (folder_path); - g_free (result); - - return TRUE; -} - -static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) -{ - CamelFolder *new_folder; - char *folder_path; - - g_return_val_if_fail (store != NULL, NULL); - g_return_val_if_fail (folder_name != NULL, NULL); - - if (!strcmp (folder_name, "/")) - folder_path = g_strdup ("INBOX"); - else - folder_path = g_strdup (folder_name); - - new_folder = camel_imap_folder_new (store, folder_path, ex); - - if (create && !imap_create (new_folder, ex)) { - return NULL; - } - - return new_folder; -} - -static gchar * -get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) -{ - return g_strdup (folder_name); -} - -static int -camel_imap_status (char *cmdid, char *respbuf) -{ - char *retcode; - - if (respbuf) { - retcode = strstr (respbuf, cmdid); - if (retcode) { - retcode += strlen (cmdid) + 1; - - if (!strncmp (retcode, "OK", 2)) - return CAMEL_IMAP_OK; - else if (!strncmp (retcode, "NO", 2)) - return CAMEL_IMAP_ERR; - } - } - - return CAMEL_IMAP_FAIL; -} - -/** - * camel_imap_command: Send a command to a IMAP server. - * @store: the IMAP store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected IMAP store specified by @store. It then - * reads the server's response and parses out the status code. If - * the caller passed a non-NULL pointer for @ret, camel_imap_command - * will set it to point to an buffer containing the rest of the - * response from the IMAP server. (If @ret was passed but there was - * no extended response, @ret will be set to NULL.) The caller must - * free this buffer when it is done with it. - * - * Return value: one of CAMEL_IMAP_OK (command executed successfully), - * CAMEL_IMAP_ERR (command encounted an error), or CAMEL_IMAP_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ -gint -camel_imap_command (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...) -{ - CamelURL *url = CAMEL_SERVICE (store)->url; - gchar *cmdbuf, *respbuf; - gchar *cmdid; - va_list ap; - gint status = CAMEL_IMAP_OK; - - if (folder && store->current_folder != folder && strncmp (fmt, "STATUS", 6) && - strncmp (fmt, "CREATE", 5) && strcmp (fmt, "CAPABILITY")) { - /* We need to select the correct mailbox first */ - char *r, *folder_path; - int s; - - if (url && url->path && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - s = camel_imap_command_extended (store, folder, &r, "SELECT %s", folder_path); - g_free (folder_path); - if (s != CAMEL_IMAP_OK) { - *ret = r; - return s; - } else { - /* parse the read-write mode */ -#if 0 - char *p; - - p = strstr (result, "\n"); - while (p) { - if (*(p + 1) == '*') - p = strstr (p, "\n"); - else - break; - } - - if (p) { - if (strstrcase (p, "READ-WRITE")) - mode = - } -#endif - } - - store->current_folder = folder; - } - - /* create the command */ - cmdid = g_strdup_printf ("A%.5d", store->command++); - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - fprintf (stderr, "sending : %s %s\r\n", cmdid, cmdbuf); - fflush (stderr); - - if (camel_stream_printf (store->ostream, "%s %s\r\n", cmdid, cmdbuf) == -1) { - g_free (cmdbuf); - g_free (cmdid); - if (*ret) - *ret = g_strdup (strerror (errno)); - return CAMEL_IMAP_FAIL; - } - g_free (cmdbuf); - - /* Read the response */ - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - if (respbuf == NULL) { - if (*ret) - *ret = g_strdup (strerror (errno)); - return CAMEL_IMAP_FAIL; - } - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - fflush (stderr); - - status = camel_imap_status (cmdid, respbuf); - g_free (cmdid); - - if (ret) { - if (status != CAMEL_IMAP_FAIL) { - *ret = strchr (respbuf, ' '); - if (*ret) - *ret = g_strdup (*ret + 1); - } else - *ret = NULL; - } - g_free (respbuf); - - return status; -} - -/** - * camel_imap_command_extended: Send a command to a IMAP server and get - * a multi-line response. - * @store: the IMAP store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected IMAP store specified by @store. It then - * reads the server's response and parses out the status code. - * Camel_imap_command_extended will set it to point to a buffer containing the - * response from the IMAP server. (If @ret was passed but there was The caller - * must free this buffer when it is done with it. - * - * This command gets the additional data returned by "multi-line" IMAP - * commands, such as SELECT, LIST, LSUB, and various other commands. - * The returned data is un-byte-stuffed, and has lines termined by - * newlines rather than CR/LF pairs. - * - * Return value: one of CAMEL_IMAP_OK (command executed successfully), - * CAMEL_IMAP_ERR (command encounted an error), or CAMEL_IMAP_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ - -gint -camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...) -{ - CamelURL *url = CAMEL_SERVICE (CAMEL_STORE (store))->url; - CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream); - GPtrArray *data; - gchar *cmdid, *cmdbuf, *respbuf; - va_list app; - gint len = 0, status = CAMEL_IMAP_OK; - - if (folder && store->current_folder != folder && strncmp (fmt, "SELECT", 6) && - strncmp (fmt, "EXAMINE", 7) && strncmp (fmt, "STATUS", 6) && - strncmp (fmt, "CREATE", 6) && strcmp (fmt, "CAPABILITY")) { - /* We need to select the correct mailbox first */ - char *r, *folder_path; - int s; - - if (url && url->path && strcmp (folder->full_name, "INBOX")) - folder_path = g_strdup_printf ("%s/%s", url->path + 1, folder->full_name); - else - folder_path = g_strdup (folder->full_name); - - s = camel_imap_command_extended (store, folder, &r, "SELECT %s", folder_path); - g_free (folder_path); - if (s != CAMEL_IMAP_OK) { - *ret = r; - return s; - } - - store->current_folder = folder; - } - - /* Create the command */ - cmdid = g_strdup_printf ("A%.5d", store->command++); - va_start (app, fmt); - cmdbuf = g_strdup_vprintf (fmt, app); - va_end (app); - - fprintf (stderr, "sending : %s %s\r\n", cmdid, cmdbuf); - - if (camel_stream_printf (store->ostream, "%s %s\r\n", cmdid, cmdbuf) == -1) { - g_free (cmdbuf); - g_free (cmdid); - - *ret = g_strdup (strerror (errno)); - - return CAMEL_IMAP_FAIL; - } - g_free (cmdbuf); - - data = g_ptr_array_new (); - - while (1) { - respbuf = camel_stream_buffer_read_line (stream); - if (!respbuf || !strncmp(respbuf, cmdid, strlen(cmdid)) ) { - /* IMAP's last response starts with our command id */ - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - break; - } - - fprintf (stderr, "received: %s\n", respbuf); - - g_ptr_array_add (data, respbuf); - len += strlen (respbuf) + 1; - } - - if (respbuf) { - g_ptr_array_add (data, respbuf); - len += strlen (respbuf) + 1; - - status = camel_imap_status (cmdid, respbuf); - } else { - status = CAMEL_IMAP_FAIL; - } - g_free (cmdid); - - if (status == CAMEL_IMAP_OK) { - char *p; - int i; - - *ret = g_malloc0 (len + 1); - - for (i = 0, p = *ret; i < data->len; i++) { - char *ptr, *datap; - - datap = (char *) data->pdata[i]; - ptr = (*datap == '.') ? datap + 1 : datap; - len = strlen (ptr); - memcpy (p, ptr, len); - p += len; - *p++ = '\n'; - } - *p = '\0'; - } else { - if (status != CAMEL_IMAP_FAIL && respbuf) - *ret = g_strdup (strchr (respbuf, ' ' + 1)); - else - *ret = NULL; - } - - g_ptr_array_free (data, TRUE); - - return status; -} diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h deleted file mode 100644 index d0ec78bf44..0000000000 --- a/camel/providers/imap/camel-imap-store.h +++ /dev/null @@ -1,85 +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 <gtk/gtk.h> -#include "camel-store.h" - -#define CAMEL_IMAP_STORE_TYPE (camel_imap_store_get_type ()) -#define CAMEL_IMAP_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_IMAP_STORE_TYPE, CamelImapStore)) -#define CAMEL_IMAP_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STORE_TYPE, CamelImapStoreClass)) -#define IS_CAMEL_IMAP_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_IMAP_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - - CamelFolder *current_folder; - CamelStream *istream, *ostream; - - guint32 command; - - gboolean has_search_capability; -} CamelImapStore; - - - -typedef struct { - CamelStoreClass parent_class; - -} CamelImapStoreClass; - - -/* public methods */ -void camel_imap_store_open (CamelImapStore *store, CamelException *ex); -void camel_imap_store_close (CamelImapStore *store, gboolean expunge, CamelException *ex); - -/* support functions */ - -enum { CAMEL_IMAP_OK, CAMEL_IMAP_ERR, CAMEL_IMAP_FAIL }; - -gint camel_imap_command (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...); -gint camel_imap_command_extended (CamelImapStore *store, CamelFolder *folder, char **ret, char *fmt, ...); - -/* Standard Gtk function */ -GtkType camel_imap_store_get_type (void); - -const gchar *camel_imap_store_get_toplevel_dir (CamelImapStore *store); - -#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 74d46eb95c..0000000000 --- a/camel/providers/imap/camel-imap-stream.c +++ /dev/null @@ -1,181 +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 <sys/types.h> -#include <errno.h> - -static CamelStreamClass *parent_class = NULL; - -/* Returns the class for a CamelImapStream */ -#define CIS_CLASS(so) CAMEL_IMAP_STREAM_CLASS (GTK_OBJECT(so)->klass) - -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 (GtkObject *object); - -static void -camel_imap_stream_class_init (CamelImapStreamClass *camel_imap_stream_class) -{ - CamelStreamClass *camel_stream_class = - CAMEL_STREAM_CLASS (camel_imap_stream_class); - GtkObjectClass *gtk_object_class = - GTK_OBJECT_CLASS (camel_imap_stream_class); - - parent_class = gtk_type_class (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; - - gtk_object_class->finalize = finalize; -} - -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; -} - -GtkType -camel_imap_stream_get_type (void) -{ - static GtkType camel_imap_stream_type = 0; - - if (!camel_imap_stream_type) { - GtkTypeInfo camel_imap_stream_info = - { - "CamelImapStream", - sizeof (CamelImapStream), - sizeof (CamelImapStreamClass), - (GtkClassInitFunc) camel_imap_stream_class_init, - (GtkObjectInitFunc) camel_imap_stream_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_imap_stream_type = gtk_type_unique (camel_stream_get_type (), &camel_imap_stream_info); - } - - return camel_imap_stream_type; -} - -CamelStream * -camel_imap_stream_new (CamelImapFolder *folder, char *command) -{ - CamelImapStream *imap_stream; - - imap_stream = gtk_type_new (camel_imap_stream_get_type ()); - - imap_stream->folder = folder; - gtk_object_ref (GTK_OBJECT (imap_stream->folder)); - - imap_stream->command = g_strdup (command); - - return CAMEL_STREAM (imap_stream); -} - -static void -finalize (GtkObject *object) -{ - CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (object); - - g_free (imap_stream->cache); - g_free (imap_stream->command); - - if (imap_stream->folder) - gtk_object_unref (GTK_OBJECT (imap_stream->folder)); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - -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); - gint status; - - status = camel_imap_command_extended (CAMEL_IMAP_STORE (folder->parent_store), - CAMEL_FOLDER (imap_stream->folder), - &imap_stream->cache, "%s", - imap_stream->command); - - if (status != CAMEL_IMAP_OK) { - /* we got an error, dump this stuff */ - g_free (imap_stream->cache); - imap_stream->cache = NULL; - - return -1; - } - - /* we don't need the folder anymore... */ - gtk_object_unref (GTK_OBJECT (imap_stream->folder)); - - 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 2a6e2fc723..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) (GTK_CHECK_CAST((obj), CAMEL_IMAP_STREAM_TYPE, CamelImapStream)) -#define CAMEL_IMAP_STREAM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STREAM_TYPE, CamelImapStreamClass)) -#define CAMEL_IS_IMAP_STREAM(o) (GTK_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 Gtk function */ -GtkType 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/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 diff --git a/camel/providers/maildir/.cvsignore b/camel/providers/maildir/.cvsignore deleted file mode 100644 index 2e7b174532..0000000000 --- a/camel/providers/maildir/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile.in -Makefile -.deps -*.lo -*.la -.libs diff --git a/camel/providers/maildir/Makefile.am b/camel/providers/maildir/Makefile.am deleted file mode 100644 index 4dd4f999b2..0000000000 --- a/camel/providers/maildir/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmaildirincludedir = $(includedir)/camel - -lib_LTLIBRARIES = libcamelmaildir.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(top_srcdir)/intl -I$(top_srcdir)/camel \ - $(GTK_INCLUDEDIR) -I$(includedir) \ - -DG_LOG_DOMAIN=\"camel-maildir-provider\" - -libcamelmaildir_la_SOURCES = \ - camel-maildir-folder.c \ - camel-maildir-provider.c \ - camel-maildir-store.c - -libcamelmaildirinclude_HEADERS = \ - camel-maildir-folder.h \ - camel-maildir-store.h - -libcamelmaildir_la_LDFLAGS = -version-info 0:0:0 - -EXTRA_DIST = diff --git a/camel/providers/maildir/camel-maildir-folder.c b/camel/providers/maildir/camel-maildir-folder.c deleted file mode 100644 index 2cb81f3e81..0000000000 --- a/camel/providers/maildir/camel-maildir-folder.c +++ /dev/null @@ -1,802 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-maildir-folder.c : camel-folder subclass for maildir folders */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . - * - * 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 - */ - -/* - * AUTHORS : Jukka Zitting - * - */ - - -#include <config.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <errno.h> -#include <time.h> -#include <string.h> -#include "camel-maildir-folder.h" -#include "camel-maildir-store.h" -#include "camel-stream-fs.h" -#include "camel-log.h" - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelMaildirFolder */ -#define CMAILDIRF_CLASS(so) CAMEL_MAILDIR_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMAILDIRS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - -static void _init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex); -static void _set_name (CamelFolder *folder, const gchar *name, CamelException *ex); -static gboolean _exists (CamelFolder *folder, CamelException *ex); -static gboolean _create (CamelFolder *folder, CamelException *ex); -static gboolean _delete (CamelFolder *folder, gboolean recurse, CamelException *ex); -static gboolean _delete_messages (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *_get_message (CamelFolder *folder, gint number, CamelException *ex); -static gint _get_message_count (CamelFolder *folder, CamelException *ex); -static void _expunge (CamelFolder *folder, CamelException *ex); -static GList *_list_subfolders (CamelFolder *folder, CamelException *ex); - -/* fs utility functions */ -static DIR * _xopendir (const gchar *path); -static gboolean _xstat (const gchar *path, struct stat *buf); -static gboolean _xmkdir (const gchar *path); -static gboolean _xrename (const gchar *from, const gchar *to); -static gboolean _xunlink (const gchar *path); -static gboolean _xrmdir (const gchar *path); -/* ** */ - -static void -camel_maildir_folder_class_init (CamelMaildirFolderClass *camel_maildir_folder_class) -{ - CamelFolderClass *camel_folder_class = - CAMEL_FOLDER_CLASS (camel_maildir_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_folder_class->init_with_store = _init_with_store; - camel_folder_class->set_name = _set_name; - camel_folder_class->exists = _exists; - camel_folder_class->create = _create; - camel_folder_class->delete = _delete; - camel_folder_class->delete_messages = _delete_messages; - camel_folder_class->expunge = _expunge; - camel_folder_class->get_message = _get_message; - camel_folder_class->get_message_count = _get_message_count; - camel_folder_class->list_subfolders = _list_subfolders; -} - -GtkType -camel_maildir_folder_get_type (void) -{ - static GtkType camel_maildir_folder_type = 0; - - if (!camel_maildir_folder_type) { - GtkTypeInfo camel_maildir_folder_info = - { - "CamelMaildirFolder", - sizeof (CamelMaildirFolder), - sizeof (CamelMaildirFolderClass), - (GtkClassInitFunc) camel_maildir_folder_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_maildir_folder_type = - gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_maildir_folder_info); - } - - return camel_maildir_folder_type; -} - - - - - - -/** - * CamelMaildirFolder::init_with_store: initializes the folder object - * @folder: folder object to initialize - * @parent_store: parent store object of the folder - * - * Simply tells that the folder can contain messages but not subfolders. - * Perhaps we'll later implement subfolders too... - */ -static void -_init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex) -{ - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::init_with_store\n"); - g_assert (folder); - g_assert (parent_store); - - /* call parent method */ - parent_class->init_with_store (folder, parent_store, ex); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = FALSE; - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::init_with_store\n"); -} - -/** - * CamelMaildirFolder::set_name: sets the name of the folder - * @folder: folder object - * @name: name of the folder - * - * Sets the name of the folder object. The existence of a folder with - * the given name is not checked in this function. - */ -static void -_set_name (CamelFolder *folder, const gchar *name, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder; - CamelMaildirStore *maildir_store; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::set_name\n"); - g_assert (folder); - g_assert (name); - g_assert (folder->parent_store); - - maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - maildir_store = CAMEL_MAILDIR_STORE (folder->parent_store); - - /* call default implementation */ - parent_class->set_name (folder, name, ex); - - if (maildir_folder->directory_path) - g_free (maildir_folder->directory_path); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::set_name full_name is %s\n", folder->full_name); - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::set_name toplevel_dir is %s\n", maildir_store->toplevel_dir); - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::set_name separator is %c\n", camel_store_get_separator (folder->parent_store)); - - if (folder->full_name && folder->full_name[0]) - maildir_folder->directory_path = - g_strconcat (maildir_store->toplevel_dir, G_DIR_SEPARATOR_S, - folder->full_name, NULL); - else - maildir_folder->directory_path = g_strdup (maildir_store->toplevel_dir); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::set_name: name set to %s\n", name); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::set_name\n"); -} - -/** - * CamelMaildirFolder::exists: tests whether the named maildir exists - * @folder: folder object - * - * A created maildir folder object doesn't necessarily exist yet in the - * filesystem. This function checks whether the maildir exists. - * The structure of the maildir is stated in the maildir.5 manpage. - * - * maildir.5: - * A directory in maildir format has three subdirectories, - * all on the same filesystem: tmp, new, and cur. - * - * Return value: TRUE if the maildir exists, FALSE otherwise - */ -static gboolean -_exists (CamelFolder *folder, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - static const gchar *dir[3] = { "new", "cur", "tmp" }; - gint i; - struct stat statbuf; - const gchar *maildir; - gchar *path; - gboolean rv = TRUE; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::exists\n"); - g_assert (folder); - g_return_val_if_fail (maildir_folder->directory_path, FALSE); - - maildir = maildir_folder->directory_path; - - CAMEL_LOG_FULL_DEBUG ("CamelMailFolder::exists: checking maildir %s\n", - maildir); - - /* check whether the toplevel directory exists */ - rv = _xstat (maildir, &statbuf) && S_ISDIR (statbuf.st_mode); - - /* check whether the maildir subdirectories exist */ - for (i = 0; rv && i < 3; i++) { - path = g_strconcat (maildir, G_DIR_SEPARATOR_S, dir[i], NULL); - - rv = _xstat (path, &statbuf) && S_ISDIR (statbuf.st_mode); - - g_free (path); - } - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::exists: %s\n", - (rv) ? "maildir found" : "maildir not found"); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::exists\n"); - return rv; -} - -/** - * CamelMaildirFolder::create: creates the named maildir - * @folder: folder object - * - * A created maildir folder object doesn't necessarily exist yet in the - * filesystem. This function creates the maildir if it doesn't yet exist. - * The structure of the maildir is stated in the maildir.5 manpage. - * - * maildir.5: - * A directory in maildir format has three subdirectories, - * all on the same filesystem: tmp, new, and cur. - * - * Return value: TRUE if the maildir existed already or was created, - * FALSE otherwise - */ -static gboolean -_create (CamelFolder *folder, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - static const gchar *dir[3] = { "new", "cur", "tmp" }; - gint i; - const gchar *maildir; - gchar *path; - gboolean rv = TRUE; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::create\n"); - g_assert (folder); - - /* check whether the maildir already exists */ - if (camel_folder_exists (folder, ex)) return TRUE; - - maildir = maildir_folder->directory_path; - - CAMEL_LOG_FULL_DEBUG ("CamelMailFolder::create: creating maildir %s\n", - maildir); - - /* create the toplevel directory */ - rv = _xmkdir (maildir); - - /* create the maildir subdirectories */ - for (i = 0; rv && i < 3; i++) { - path = g_strconcat (maildir, G_DIR_SEPARATOR_S, dir[i], NULL); - - rv = _xmkdir (path); - - g_free (path); - } - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::create: %s\n", - rv ? "maildir created" : "an error occurred"); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::create\n"); - return rv; -} - -/** - * CamelMaildirFolder::delete: delete the maildir folder - * @folder: the folder object - * @recurse: - * - * This function empties and deletes the maildir folder. The subdirectories - * "tmp", "cur", and "new" are removed first and then the toplevel maildir - * directory is deleted. All files from the directories are deleted as well, - * so you should be careful when using this function. If a subdirectory cannot - * be deleted, then the operation it is stopped. Thus if an error occurs, the - * maildir directory won't be removed, but it might no longer be a valid maildir. - */ -static gboolean -_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - static const gchar *dir[3] = { "new", "cur", "tmp" }; - gint i; - const gchar *maildir; - gchar *path; - gboolean rv = TRUE; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::create\n"); - g_assert (folder); - - /* check whether the maildir already exists */ - if (!camel_folder_exists (folder, ex)) return TRUE; - - maildir = maildir_folder->directory_path; - - CAMEL_LOG_FULL_DEBUG ("CamelMailFolder::delete: deleting maildir %s\n", - maildir); - - /* delete the maildir subdirectories */ - for (i = 0; rv && i < 3; i++) { - path = g_strconcat (maildir, G_DIR_SEPARATOR_S, dir[i], NULL); - - rv = _xrmdir (path); - - g_free (path); - } - - /* create the toplevel directory */ - if (rv) - rv = _xrmdir (maildir); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::delete: %s\n", - rv ? "maildir deleted" : "an error occurred"); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::delete\n"); - return rv; -} - -/** - * CamelMaildirFolder::delete_messages: empty the maildir folder - * @folder: the folder object - * - * This function empties the maildir folder. All messages from the - * "cur" subdirectory are deleted. If a message cannot be deleted, then - * it is just skipped and the rest of the messages are still deleted. - * Files with names starting with a dot are skipped as described in the - * maildir.5 manpage. - * - * maildir.5: - * It is a good idea for readers to skip all filenames in new - * and cur starting with a dot. Other than this, readers - * should not attempt to parse filenames. - * - * Return value: FALSE on error and if some messages could not be deleted. - * TRUE otherwise. - */ -static gboolean -_delete_messages (CamelFolder *folder, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - const gchar *maildir; - gchar *curdir, *file; - DIR *dir_handle; - struct dirent *dir_entry; - gboolean rv = TRUE; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::delete_messages\n"); - g_assert (folder); - - /* call default implementation */ - parent_class->delete_messages (folder, ex); - - /* Check if the folder didn't exist */ - if (!camel_folder_exists (folder, ex)) return TRUE; - - maildir = maildir_folder->directory_path; - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::delete_messages: " - "deleting messages from %s\n", maildir); - - /* delete messages from the maildir subdirectory "cur" */ - curdir = g_strconcat (maildir, G_DIR_SEPARATOR_S, "cur", NULL); - - dir_handle = _xopendir (curdir); - if (dir_handle) { - while ((dir_entry = readdir (dir_handle))) { - if (dir_entry->d_name[0] == '.') continue; - file = g_strconcat (curdir, G_DIR_SEPARATOR_S, - dir_entry->d_name, NULL); - - if (!_xunlink (file)) rv = FALSE; - - g_free (file); - } - closedir (dir_handle); - } else - rv = FALSE; - - g_free (curdir); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::delete_messages: %s\n", - rv ? "messages deleted" : "an error occurred"); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::delete_messages\n"); - return rv; -} - -/** - * CamelMaildirFolder::get_message: get a message from maildir - * @folder: the folder object - * @number: number of the message within the folder - * - * Return value: the message, NULL on error - */ -static CamelMimeMessage * -_get_message (CamelFolder *folder, gint number, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER(folder); - DIR *dir_handle; - struct dirent *dir_entry; - CamelStream *stream; - CamelMimeMessage *message = NULL; - const gchar *maildir; - gchar *curdir, *file = NULL; - gint count = -1; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::get_message\n"); - g_assert(folder); - - /* Check if the folder exists */ - if (!camel_folder_exists (folder, ex)) return NULL; - - maildir = maildir_folder->directory_path; - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::get_message: " - "getting message #%d from %s\n", number, maildir); - - /* Count until the desired message is reached */ - curdir = g_strconcat (maildir, G_DIR_SEPARATOR_S, "cur", NULL); - if ((dir_handle = _xopendir (curdir))) { - while ((count < number) && (dir_entry = readdir (dir_handle))) - if (dir_entry->d_name[0] != '.') count++; - - if (count == number) - file = g_strconcat (curdir, G_DIR_SEPARATOR_S, - dir_entry->d_name, NULL); - - closedir (dir_handle); - } - g_free (curdir); - if (!file) return NULL; - - /* Create the message object */ - message = camel_mime_message_new (); - stream = camel_stream_fs_new_with_name (file, CAMEL_STREAM_FS_READ); - - if (!message || !stream) { - g_free (file); - if (stream) gtk_object_unref (GTK_OBJECT (stream)); - if (message) gtk_object_unref (GTK_OBJECT (message)); - return NULL; - } - - camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (message), - stream); - gtk_object_unref (GTK_OBJECT (stream)); - gtk_object_set_data_full (GTK_OBJECT (message), - "fullpath", file, g_free); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::get_message: " - "message %p created from %s\n", message, file); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::get_message\n"); - return message; -} - -/** - * CamelMaildirFolder::get_message_count: count messages in maildir - * @folder: the folder object - * - * Returns the number of messages in the maildir folder. New messages - * are included in this count. - * - * Return value: number of messages in the maildir, -1 on error - */ -static gint -_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER(folder); - const gchar *maildir; - gchar *newdir, *curdir, *newfile, *curfile; - DIR *dir_handle; - struct dirent *dir_entry; - guint count = 0; - - CAMEL_LOG_FULL_DEBUG ("Entering " - "CamelMaildirFolder::get_message_count\n"); - g_assert(folder); - - /* check if the maildir exists */ - if (!camel_folder_exists (folder, ex)) return -1; - - maildir = maildir_folder->directory_path; - - newdir = g_strconcat (maildir, G_DIR_SEPARATOR_S, "new", NULL); - curdir = g_strconcat (maildir, G_DIR_SEPARATOR_S, "cur", NULL); - - /* Check new messages */ - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::get_message_count: " - "getting new messages from %s\n", newdir); - if ((dir_handle = _xopendir (newdir))) { - while ((dir_entry = readdir (dir_handle))) { - if (dir_entry->d_name[0] == '.') continue; - newfile = g_strconcat (newdir, G_DIR_SEPARATOR_S, - dir_entry->d_name, NULL); - curfile = g_strconcat (curdir, G_DIR_SEPARATOR_S, - dir_entry->d_name, ":2,", NULL); - - _xrename (newfile, curfile); - - g_free (curfile); - g_free (newfile); - } - closedir (dir_handle); - } - - /* Count messages */ - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::get_message_count: " - "counting messages in %s\n", curdir); - if ((dir_handle = _xopendir (curdir))) { - while ((dir_entry = readdir (dir_handle))) - if (dir_entry->d_name[0] != '.') count++; - closedir (dir_handle); - } - - g_free (curdir); - g_free (newdir); - - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::get_message_count: " - " found %d messages\n", count); - CAMEL_LOG_FULL_DEBUG ("Leaving " - "CamelMaildirFolder::get_message_count\n"); - return count; -} - - - - -/** - * CamelMaildirFolder::expunge: expunge messages marked as deleted - * @folder: the folder object - * - * Physically deletes the messages marked as deleted in the folder. - */ -static void -_expunge (CamelFolder *folder, CamelException *ex) -{ - CamelMimeMessage *message; - GList *node; - gchar *fullpath; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::expunge\n"); - g_assert(folder); - - /* expunge messages marked for deletion */ - for (node = folder->message_list; node; node = g_list_next(node)) { - message = CAMEL_MIME_MESSAGE (node->data); - if (!message) { - CAMEL_LOG_WARNING ("CamelMaildirFolder::expunge: " - "null message in node %p\n", node); - continue; - } - - if (camel_mime_message_get_flag (message, "DELETED")) { - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::expunge: " - "expunging message #%d\n", - message->message_number); - - /* expunge the message */ - fullpath = gtk_object_get_data (GTK_OBJECT (message), - "fullpath"); - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::expunge: " - "message fullpath is %s\n", - fullpath); - - if (_xunlink (fullpath)) - message->expunged = TRUE; - } else { - CAMEL_LOG_FULL_DEBUG ("CamelMaildirFolder::expunge: " - "skipping message #%d\n", - message->message_number); - } - } - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::expunge\n"); -} - - - - -/** - * CamelMaildirFolder::list_subfolders: return a list of subfolders - * @folder: the folder object - * - * Returns the names of the maildir subfolders in a list. - * - * Return value: list of subfolder names - */ -static GList * -_list_subfolders (CamelFolder *folder, CamelException *ex) -{ - CamelMaildirFolder *maildir_folder = CAMEL_MAILDIR_FOLDER (folder); - const gchar *maildir; - gchar *subdir; - struct stat statbuf; - struct dirent *dir_entry; - DIR *dir_handle; - GList *subfolders = NULL; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMaildirFolder::list_subfolders\n"); - g_assert (folder); - - /* check if the maildir exists */ - if (!camel_folder_exists (folder, ex)) return NULL; - - /* scan through the maildir toplevel directory */ - maildir = maildir_folder->directory_path; - if ((dir_handle = _xopendir (maildir))) { - while ((dir_entry = readdir (dir_handle))) { - if (dir_entry->d_name[0] == '.') continue; - if (strcmp (dir_entry->d_name, "new") == 0) continue; - if (strcmp (dir_entry->d_name, "cur") == 0) continue; - if (strcmp (dir_entry->d_name, "tmp") == 0) continue; - - subdir = g_strconcat (maildir, G_DIR_SEPARATOR_S, - dir_entry->d_name, NULL); - - if (_xstat (subdir, &statbuf) - && S_ISDIR (statbuf.st_mode)) - subfolders = - g_list_append ( - subfolders, - g_strdup (dir_entry->d_name)); - - g_free (subdir); - } - closedir (dir_handle); - } - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMaildirFolder::list_subfolders\n"); - return subfolders; -} - - - - - - - -/* - * fs utility function - * - */ - -static DIR * -_xopendir (const gchar *path) -{ - DIR *handle; - g_assert (path); - - handle = opendir (path); - if (!handle) { - CAMEL_LOG_WARNING ("ERROR: opendir (%s);\n", path); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - } - - return handle; -} - -static gboolean -_xstat (const gchar *path, struct stat *buf) -{ - gint stat_error; - g_assert (path); - g_assert (buf); - - stat_error = stat (path, buf); - if (stat_error == 0) { - return TRUE; - } else if (errno == ENOENT) { - buf->st_mode = 0; - return TRUE; - } else { - CAMEL_LOG_WARNING ("ERROR: stat (%s, %p);\n", path, buf); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } -} - -static gboolean -_xmkdir (const gchar *path) -{ - g_assert (path); - - if (mkdir (path, S_IRWXU) == -1) { - CAMEL_LOG_WARNING ("ERROR: mkdir (%s, S_IRWXU);\n", path); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } - - return TRUE; -} - -static gboolean -_xrename (const gchar *from, const gchar *to) -{ - g_assert (from); - g_assert (to); - - if (rename (from, to) == 0) { - return TRUE; - } else { - CAMEL_LOG_WARNING ("ERROR: rename (%s, %s);\n", from, to); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } -} - -static gboolean -_xunlink (const gchar *path) -{ - g_assert (path); - - if (unlink (path) == 0) { - return TRUE; - } else if (errno == ENOENT) { - return TRUE; - } else { - CAMEL_LOG_WARNING ("ERROR: unlink (%s);\n", path); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } -} - -static gboolean -_xrmdir (const gchar *path) -{ - DIR *dir_handle; - struct dirent *dir_entry; - gchar *file; - struct stat statbuf; - g_assert (path); - - dir_handle = opendir (path); - if (!dir_handle && errno == ENOENT) { - return TRUE; - } else if (!dir_handle) { - CAMEL_LOG_WARNING ("ERROR: opendir (%s);\n", path); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } - - while ((dir_entry = readdir (dir_handle))) { - file = g_strconcat (path, G_DIR_SEPARATOR_S, dir_entry->d_name, - NULL); - if (_xstat (file, &statbuf) && S_ISREG (statbuf.st_mode)) - _xunlink (file); - g_free (file); - } - - closedir (dir_handle); - - if (rmdir (path) == 0) { - return TRUE; - } else if (errno == ENOENT) { - return TRUE; - } else { - CAMEL_LOG_WARNING ("ERROR: rmdir (%s);\n", path); - CAMEL_LOG_FULL_DEBUG (" Full error text is: (%d) %s\n", - errno, strerror(errno)); - return FALSE; - } -} - -/** *** **/ - diff --git a/camel/providers/maildir/camel-maildir-folder.h b/camel/providers/maildir/camel-maildir-folder.h deleted file mode 100644 index 5997da2011..0000000000 --- a/camel/providers/maildir/camel-maildir-folder.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-maildir-folder.h : Abstract class for an email folder */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . - * - * 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_MAILDIR_FOLDER_H -#define CAMEL_MAILDIR_FOLDER_H 1 - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-folder.h" -/* #include "camel-store.h" */ - -#define CAMEL_MAILDIR_FOLDER_TYPE (camel_maildir_folder_get_type ()) -#define CAMEL_MAILDIR_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_MAILDIR_FOLDER_TYPE, CamelMaildirFolder)) -#define CAMEL_MAILDIR_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MAILDIR_FOLDER_TYPE, CamelMaildirFolderClass)) -#define IS_CAMEL_MAILDIR_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_MAILDIR_FOLDER_TYPE)) - - -typedef struct { - CamelFolder parent_object; - - gchar *directory_path; -} CamelMaildirFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelMaildirFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_maildir_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MAILDIR_FOLDER_H */ diff --git a/camel/providers/maildir/camel-maildir-provider.c b/camel/providers/maildir/camel-maildir-provider.c deleted file mode 100644 index cd5521adc0..0000000000 --- a/camel/providers/maildir/camel-maildir-provider.c +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-maildir-provider.c: maildir provider registration code */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . - * - * 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 "camel-maildir-store.h" -#include "camel-provider.h" -#include "camel-log.h" - - -static CamelProvider _maildir_provider = { - (GtkType) 0, - PROVIDER_STORE, - "maildir", - "Maildir provider for Camel", - "This maildir provider is based on the default MH provider of Camel", - (GModule *) NULL -}; - - - -CamelProvider * -camel_provider_module_init () -{ - _maildir_provider.object_type = camel_maildir_store_get_type(); - return &_maildir_provider; -} diff --git a/camel/providers/maildir/camel-maildir-store.c b/camel/providers/maildir/camel-maildir-store.c deleted file mode 100644 index 8f37494003..0000000000 --- a/camel/providers/maildir/camel-maildir-store.c +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-maildir-store.c : class for an maildir store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . - * - * 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-maildir-store.h" -#include "camel-maildir-folder.h" -#include "url-util.h" - -static CamelStoreClass *parent_class=NULL; - -/* Returns the class for a CamelMaildirStore */ -#define CMAILDIRS_CLASS(so) CAMEL_MAILDIR_STORE_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMAILDIRF_CLASS(so) CAMEL_MAILDIR_FOLDER_CLASS (GTK_OBJECT(so)->klass) - -static void _init (CamelStore *store, CamelSession *session, - const gchar *url_name); -static CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name); - -static void -camel_maildir_store_class_init ( - CamelMaildirStoreClass *camel_maildir_store_class) -{ - CamelStoreClass *camel_store_class = - CAMEL_STORE_CLASS (camel_maildir_store_class); - - parent_class = gtk_type_class (camel_store_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_store_class->init = _init; - camel_store_class->get_folder = _get_folder; -} - -static void -camel_maildir_store_init (gpointer object, gpointer klass) -{ - CamelMaildirStore *maildir_store = CAMEL_MAILDIR_STORE (object); - CamelStore *store = CAMEL_STORE (object); - - store->separator = G_DIR_SEPARATOR; -} - -GtkType -camel_maildir_store_get_type (void) -{ - static GtkType camel_maildir_store_type = 0; - - if (!camel_maildir_store_type) { - GtkTypeInfo camel_maildir_store_info = - { - "CamelMaildirStore", - sizeof (CamelMaildirStore), - sizeof (CamelMaildirStoreClass), - (GtkClassInitFunc) camel_maildir_store_class_init, - (GtkObjectInitFunc) camel_maildir_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_maildir_store_type = - gtk_type_unique (CAMEL_STORE_TYPE, - &camel_maildir_store_info); - } - - return camel_maildir_store_type; -} - -static void -_init (CamelStore *store, CamelSession *session, const gchar *url_name) -{ - CamelMaildirStore *maildir_store = CAMEL_MAILDIR_STORE (store); - Gurl *store_url; - g_assert (url_name); - - /* call parent implementation */ - parent_class->init (store, session, url_name); - - /* find the path in the URL*/ - store_url = g_url_new (url_name); - - g_return_if_fail (store_url); - g_return_if_fail (store_url->path); - - maildir_store->toplevel_dir = g_strdup (store_url->path); - - g_url_free (store_url); -} - -static CamelFolder * -_get_folder (CamelStore *store, const gchar *folder_name) -{ - CamelMaildirStore *maildir_store = CAMEL_MAILDIR_STORE (store); - CamelMaildirFolder *new_maildir_folder; - CamelFolder *new_folder; - - new_maildir_folder = gtk_type_new (CAMEL_MAILDIR_FOLDER_TYPE); - new_folder = CAMEL_FOLDER (new_maildir_folder); - - CF_CLASS (new_folder)->init_with_store (new_folder, store, NULL); - CF_CLASS (new_folder)->set_name (new_folder, folder_name, NULL); - - return new_folder; -} diff --git a/camel/providers/maildir/camel-maildir-store.h b/camel/providers/maildir/camel-maildir-store.h deleted file mode 100644 index 1a95ed1436..0000000000 --- a/camel/providers/maildir/camel-maildir-store.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-maildirstore.h : class for an maildir store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> . - * - * 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_MAILDIR_STORE_H -#define CAMEL_MAILDIR_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-store.h" - -#define CAMEL_MAILDIR_STORE_TYPE (camel_maildir_store_get_type ()) -#define CAMEL_MAILDIR_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_MAILDIR_STORE_TYPE, CamelMaildirStore)) -#define CAMEL_MAILDIR_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MAILDIR_STORE_TYPE, CamelMaildirStoreClass)) -#define IS_CAMEL_MAILDIR_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_MAILDIR_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - - gchar *toplevel_dir; -} CamelMaildirStore; - - - -typedef struct { - CamelStoreClass parent_class; - - -} CamelMaildirStoreClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_maildir_store_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MAILDIR_STORE_H */ - - diff --git a/camel/providers/mbox/.cvsignore b/camel/providers/mbox/.cvsignore deleted file mode 100644 index fd6b811c68..0000000000 --- a/camel/providers/mbox/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -Makefile -Makefile.in -.libs -.deps -*.lo -*.la diff --git a/camel/providers/mbox/Makefile.am b/camel/providers/mbox/Makefile.am deleted file mode 100644 index 0c9330340b..0000000000 --- a/camel/providers/mbox/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmboxincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelmbox.la -provider_DATA = libcamelmbox.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) \ - -DG_LOG_DOMAIN=\"camel-mbox-provider\" - -libcamelmbox_la_SOURCES = \ - camel-mbox-folder.c \ - camel-mbox-provider.c \ - camel-mbox-store.c \ - camel-mbox-summary.c - -libcamelmboxinclude_HEADERS = \ - camel-mbox-folder.h \ - camel-mbox-store.h \ - camel-mbox-summary.h - -libcamelmbox_la_LDFLAGS = -version-info 0:0:0 - -libcamelmbox_la_LIBADD = $(top_builddir)/e-util/libeutil.la $(top_builddir)/libibex/libibex.la $(UNICODE_LIBS) -#libcamelmbox_la_LIBADD = $(top_builddir)/libibex/libibex.la $(UNICODE_LIBS) - -EXTRA_DIST = libcamelmbox.urls - diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c deleted file mode 100644 index d7ee9c2376..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.c +++ /dev/null @@ -1,594 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ -/* camel-mbox-folder.c : Abstract class for an email folder */ - -/* - * Authors: Bertrand Guiheneuf <bertrand@helixcode.com> - * Michael Zucchi <notzed@helixcode.com> - * - * Copyright (C) 1999, 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 "camel-mbox-folder.h" -#include "camel-mbox-store.h" -#include "string-utils.h" -#include "camel-stream-fs.h" -#include "camel-mbox-summary.h" -#include "camel-data-wrapper.h" -#include "camel-mime-message.h" -#include "camel-stream-filter.h" -#include "camel-mime-filter-from.h" -#include "camel-exception.h" - -#define d(x) - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelMboxFolder */ -#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMBOXS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - - -static void mbox_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar *separator, gboolean path_begins_with_sep, - CamelException *ex); - -static void mbox_sync (CamelFolder *folder, gboolean expunge, CamelException *ex); -static gint mbox_get_message_count (CamelFolder *folder, CamelException *ex); -static void mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static GPtrArray *mbox_get_uids (CamelFolder *folder, CamelException *ex); -static GPtrArray *mbox_get_subfolder_names (CamelFolder *folder, CamelException *ex); -static GPtrArray *mbox_get_summary (CamelFolder *folder, CamelException *ex); -static void mbox_free_summary (CamelFolder *folder, GPtrArray *array); -static CamelMimeMessage *mbox_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex); - -static void mbox_expunge (CamelFolder *folder, CamelException *ex); - -static void mbox_delete_message (CamelFolder *folder, const gchar *uid, CamelException *ex); - -static const CamelMessageInfo *mbox_get_message_info (CamelFolder *folder, const char *uid); - -static GList *mbox_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex); - -static guint32 mbox_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex); -static void mbox_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set, CamelException *ex); -static gboolean mbox_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name, CamelException *ex); -static void mbox_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, gboolean value, CamelException *ex); - - -static void mbox_finalize (GtkObject *object); - -static void -camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_mbox_folder_class); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - - /* virtual method overload */ - camel_folder_class->init = mbox_init; - camel_folder_class->sync = mbox_sync; - camel_folder_class->get_message_count = mbox_get_message_count; - camel_folder_class->append_message = mbox_append_message; - camel_folder_class->get_uids = mbox_get_uids; - camel_folder_class->get_subfolder_names = mbox_get_subfolder_names; - camel_folder_class->get_summary = mbox_get_summary; - camel_folder_class->free_summary = mbox_free_summary; - camel_folder_class->expunge = mbox_expunge; - - camel_folder_class->get_message = mbox_get_message; - camel_folder_class->delete_message = mbox_delete_message; - - camel_folder_class->search_by_expression = mbox_search_by_expression; - - camel_folder_class->get_message_info = mbox_get_message_info; - - camel_folder_class->get_message_flags = mbox_get_message_flags; - camel_folder_class->set_message_flags = mbox_set_message_flags; - camel_folder_class->get_message_user_flag = mbox_get_message_user_flag; - camel_folder_class->set_message_user_flag = mbox_set_message_user_flag; - - gtk_object_class->finalize = mbox_finalize; - -} - -static void -mbox_finalize (GtkObject *object) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (object); - - g_free (mbox_folder->folder_file_path); - g_free (mbox_folder->summary_file_path); - g_free (mbox_folder->folder_dir_path); - g_free (mbox_folder->index_file_path); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - -GtkType -camel_mbox_folder_get_type (void) -{ - static GtkType camel_mbox_folder_type = 0; - - if (!camel_mbox_folder_type) { - GtkTypeInfo camel_mbox_folder_info = - { - "CamelMboxFolder", - sizeof (CamelMboxFolder), - sizeof (CamelMboxFolderClass), - (GtkClassInitFunc) camel_mbox_folder_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mbox_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_mbox_folder_info); - } - - return camel_mbox_folder_type; -} - -static void -mbox_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, gchar *separator, - gboolean path_begins_with_sep, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - const gchar *root_dir_path; - gchar *real_name; - int forceindex; - struct stat st; - - /* call parent method */ - parent_class->init (folder, parent_store, parent_folder, - name, separator, path_begins_with_sep, ex); - if (camel_exception_get_id (ex)) - return; - - /* we assume that the parent init - method checks for the existance of @folder */ - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = TRUE; - folder->has_search_capability = TRUE; - - folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | - CAMEL_MESSAGE_DELETED | - CAMEL_MESSAGE_DRAFT | - CAMEL_MESSAGE_FLAGGED | - CAMEL_MESSAGE_SEEN | - CAMEL_MESSAGE_USER; - /* FIXME: we don't actually preserve user flags right now. */ - - mbox_folder->summary = NULL; - mbox_folder->search = NULL; - - /* now set the name info */ - g_free (mbox_folder->folder_file_path); - g_free (mbox_folder->folder_dir_path); - g_free (mbox_folder->index_file_path); - - root_dir_path = camel_mbox_store_get_toplevel_dir (CAMEL_MBOX_STORE(folder->parent_store)); - - real_name = g_basename (folder->full_name); - mbox_folder->folder_file_path = g_strdup_printf ("%s/%s", root_dir_path, real_name); - mbox_folder->summary_file_path = g_strdup_printf ("%s/%s-ev-summary", root_dir_path, real_name); - mbox_folder->folder_dir_path = g_strdup_printf ("%s/%s.sdb", root_dir_path, real_name); - mbox_folder->index_file_path = g_strdup_printf ("%s/%s.ibex", root_dir_path, real_name); - - /* if we have no index file, force it */ - forceindex = stat(mbox_folder->index_file_path, &st) == -1; - - mbox_folder->index = ibex_open(mbox_folder->index_file_path, O_CREAT|O_RDWR, 0600); - if (mbox_folder->index == NULL) { - /* yes, this isn't fatal at all */ - g_warning("Could not open/create index file: %s: indexing not performed", - strerror(errno)); - } - - /* no summary (disk or memory), and we're proverbially screwed */ - mbox_folder->summary = camel_mbox_summary_new (mbox_folder->summary_file_path, - mbox_folder->folder_file_path, mbox_folder->index); - if (mbox_folder->summary == NULL - || camel_mbox_summary_load(mbox_folder->summary, forceindex) == -1) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, /* FIXME: right error code */ - "Could not create summary"); - return; - } -} - -static void -mbox_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - if (expunge) - mbox_expunge (folder, ex); - else - camel_mbox_summary_sync (mbox_folder->summary, FALSE, ex); - - /* save index */ - if (mbox_folder->index) - ibex_save(mbox_folder->index); - if (mbox_folder->summary) - camel_folder_summary_save (CAMEL_FOLDER_SUMMARY (mbox_folder->summary)); -} - -static void -mbox_expunge (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox = CAMEL_MBOX_FOLDER (folder); - - camel_mbox_summary_sync (mbox->summary, TRUE, ex); - - /* TODO: check it actually changed */ - gtk_signal_emit_by_name (GTK_OBJECT (folder), "folder_changed", 0); -} - -static gint -mbox_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - g_assert (folder); - g_assert (mbox_folder->summary); - - return camel_folder_summary_count (CAMEL_FOLDER_SUMMARY (mbox_folder->summary)); -} - -/* FIXME: this may need some tweaking for performance? */ -static void -mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - CamelStream *output_stream = NULL, *filter_stream = NULL; - CamelMimeFilter *filter_from = NULL; - struct stat st; - off_t seek = -1; - char *xev, last; - guint32 uid; - - if (stat (mbox_folder->folder_file_path, &st) != 0) - goto fail; - - output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDWR, 0600); - if (output_stream == NULL) - goto fail; - - if (st.st_size) { - seek = camel_seekable_stream_seek ((CamelSeekableStream *)output_stream, st.st_size - 1, SEEK_SET); - if (++seek != st.st_size) - goto fail; - - /* If the mbox doesn't end with a newline, fix that. */ - if (camel_stream_read (output_stream, &last, 1) != 1) - goto fail; - if (last != '\n') - camel_stream_write (output_stream, "\n", 1); - } else - seek = 0; - - /* assign a new x-evolution header/uid */ - camel_medium_remove_header (CAMEL_MEDIUM (message), "X-Evolution"); - uid = camel_folder_summary_next_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary)); - xev = g_strdup_printf ("%08x-0000", uid); - camel_medium_add_header (CAMEL_MEDIUM (message), "X-Evolution", xev); - g_print ("%s -- %s\n", __FUNCTION__, xev); - g_free (xev); - - /* we must write this to the non-filtered stream ... */ - if (camel_stream_write_string (output_stream, "From - \n") == -1) - goto fail; - - /* and write the content to the filtering stream, that translated '\nFrom' into '\n>From' */ - filter_stream = (CamelStream *)camel_stream_filter_new_with_stream (output_stream); - filter_from = (CamelMimeFilter *)camel_mime_filter_from_new (); - camel_stream_filter_add ((CamelStreamFilter *)filter_stream, filter_from); - if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), filter_stream) == -1) - goto fail; - - if (camel_stream_close (filter_stream) == -1) - goto fail; - - /* filter stream ref's the output stream itself, so we need to unref it too */ - gtk_object_unref (GTK_OBJECT (filter_from)); - gtk_object_unref (GTK_OBJECT (filter_stream)); - gtk_object_unref (GTK_OBJECT (output_stream)); - - /* force a summary update - will only update from the new position, if it can */ - if (camel_mbox_summary_update (mbox_folder->summary, seek) == 0) - gtk_signal_emit_by_name (GTK_OBJECT (folder), "folder_changed", 0); - return; - -fail: - if (camel_exception_is_set (ex)) { - camel_exception_setv (ex, camel_exception_get_id (ex), - "Cannot append message to mbox file: %s", - camel_exception_get_description (ex)); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot append message to mbox file: %s", - g_strerror (errno)); - } - if (filter_stream) { - /*camel_stream_close (filter_stream);*/ - gtk_object_unref (GTK_OBJECT (filter_stream)); - } - if (output_stream) - gtk_object_unref (GTK_OBJECT (output_stream)); - - if (filter_from) - gtk_object_unref (GTK_OBJECT (filter_from)); - - /* make sure the file isn't munged by us */ - if (seek != -1) { - int fd = open (mbox_folder->folder_file_path, O_WRONLY, 0600); - - if (fd != -1) { - ftruncate (fd, st.st_size); - close(fd); - } - } -} - -static GPtrArray * -mbox_get_uids (CamelFolder *folder, CamelException *ex) -{ - GPtrArray *array; - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - int i, count; - - count = camel_folder_summary_count (CAMEL_FOLDER_SUMMARY (mbox_folder->summary)); - array = g_ptr_array_new (); - g_ptr_array_set_size (array, count); - for (i = 0; i < count; i++) { - CamelMboxMessageInfo *info = (CamelMboxMessageInfo *) camel_folder_summary_index ( - CAMEL_FOLDER_SUMMARY (mbox_folder->summary), i); - array->pdata[i] = g_strdup (info->info.uid); - } - - return array; -} - -static GPtrArray * -mbox_get_subfolder_names (CamelFolder *folder, CamelException *ex) -{ - /* No subfolders. */ - return g_ptr_array_new (); -} - -static void -mbox_delete_message (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMessageInfo *info; - CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder); - - info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid); - if (info) { - info->flags |= CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED; - camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary)); - } -} - -static CamelMimeMessage * -mbox_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - CamelStream *message_stream = NULL; - CamelMimeMessage *message = NULL; - CamelMboxMessageInfo *info; - CamelMimeParser *parser = NULL; - char *buffer; - int len; - - /* get the message summary info */ - info = (CamelMboxMessageInfo *)camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary), uid); - - if (info == NULL) { - errno = ENOENT; - goto fail; - } - - /* if this has no content, its an error in the library */ - g_assert (info->info.content); - g_assert (info->frompos != -1); - - /* where we read from */ - message_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDONLY, 0); - if (message_stream == NULL) - goto fail; - - /* we use a parser to verify the message is correct, and in the correct position */ - parser = camel_mime_parser_new (); - camel_mime_parser_init_with_stream (parser, message_stream); - gtk_object_unref (GTK_OBJECT (message_stream)); - camel_mime_parser_scan_from (parser, TRUE); - - camel_mime_parser_seek (parser, info->frompos, SEEK_SET); - if (camel_mime_parser_step (parser, &buffer, &len) != HSCAN_FROM) { - g_warning ("File appears truncated"); - goto fail; - } - - if (camel_mime_parser_tell_start_from (parser) != info->frompos) { - g_warning ("Summary doesn't match the folder contents! eek!\n" - " expecting offset %ld got %ld", (long int)info->frompos, - (long int)camel_mime_parser_tell_start_from (parser)); - errno = EINVAL; - goto fail; - } - - message = camel_mime_message_new (); - if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (message), parser) == -1) { - g_warning ("Construction failed"); - goto fail; - } - gtk_object_unref (GTK_OBJECT (parser)); - - return message; - -fail: - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "Cannot get message: %s", - g_strerror(errno)); - - if (parser) - gtk_object_unref (GTK_OBJECT (parser)); - if (message) - gtk_object_unref (GTK_OBJECT (message)); - - return NULL; -} - -GPtrArray * -mbox_get_summary (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - return CAMEL_FOLDER_SUMMARY (mbox_folder->summary)->messages; -} - -void -mbox_free_summary (CamelFolder *folder, GPtrArray *array) -{ - /* no-op */ -} - -/* get a single message info, by uid */ -static const CamelMessageInfo * -mbox_get_message_info (CamelFolder *folder, const char *uid) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - return camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary), uid); -} - -static GList * -mbox_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - if (mbox_folder->search == NULL) { - mbox_folder->search = camel_folder_search_new (); - } - - camel_folder_search_set_folder (mbox_folder->search, folder); - if (mbox_folder->summary) { - /* FIXME: dont access summary array directly? */ - camel_folder_search_set_summary (mbox_folder->search, - CAMEL_FOLDER_SUMMARY (mbox_folder->summary)->messages); - } - - camel_folder_search_set_body_index (mbox_folder->search, mbox_folder->index); - - return camel_folder_search_execute_expression (mbox_folder->search, expression, ex); -} - -static guint32 -mbox_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex) -{ - CamelMessageInfo *info; - CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder); - - info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid); - if (info) { - return info->flags; - } else { - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "No such message %s in %s.", uid, - folder->name); - return 0; - } -} - -static void -mbox_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, - guint32 set, CamelException *ex) -{ - CamelMessageInfo *info; - CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder); - - info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid); - if (info) { - info->flags = (info->flags & ~flags) | (set & flags) | - CAMEL_MESSAGE_FOLDER_FLAGGED; - camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary)); - - gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "No such message %s in %s.", uid, - folder->name); - } -} - -static gboolean -mbox_get_message_user_flag (CamelFolder *folder, const char *uid, - const char *name, CamelException *ex) -{ - CamelMessageInfo *info; - CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder); - - info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid); - if (info) - return camel_flag_get (&info->user_flags, name); - else { - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "No such message %s in %s.", uid, - folder->name); - return FALSE; - } -} - -static void mbox_set_message_user_flag (CamelFolder *folder, const char *uid, - const char *name, gboolean value, - CamelException *ex) -{ - CamelMessageInfo *info; - CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder); - - info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid); - if (info) { - camel_flag_set (&info->user_flags, name, value); - info->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED; - camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary)); - gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "No such message %s in %s.", uid, - folder->name); - } -} diff --git a/camel/providers/mbox/camel-mbox-folder.h b/camel/providers/mbox/camel-mbox-folder.h deleted file mode 100644 index d7dc361f14..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-folder.h : Abstract class for an email folder */ - -/* - * - * Author : Bertrand Guiheneuf <bertrand@helixcode.com> - * - * Copyright (C) 1999 Helix Code . - * - * 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_MBOX_FOLDER_H -#define CAMEL_MBOX_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include <camel/camel-folder.h> -#include <camel/camel-folder-search.h> -#include <libibex/ibex.h> -#include "camel-mbox-summary.h" - -/* #include "camel-store.h" */ - -#define CAMEL_MBOX_FOLDER_TYPE (camel_mbox_folder_get_type ()) -#define CAMEL_MBOX_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolder)) -#define CAMEL_MBOX_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolderClass)) -#define IS_CAMEL_MBOX_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_MBOX_FOLDER_TYPE)) - -typedef struct { - CamelFolder parent_object; - - gchar *folder_file_path; /* contains the messages */ - gchar *summary_file_path; /* contains the messages summary */ - gchar *folder_dir_path; /* contains the subfolders */ - gchar *index_file_path; /* index of body contents */ - - ibex *index; /* index for this folder */ - CamelMboxSummary *summary; - CamelFolderSearch *search; /* used to run searches, we just use the real thing (tm) */ -} CamelMboxFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelMboxFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mbox_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MBOX_FOLDER_H */ diff --git a/camel/providers/mbox/camel-mbox-provider.c b/camel/providers/mbox/camel-mbox-provider.c deleted file mode 100644 index de206f18ef..0000000000 --- a/camel/providers/mbox/camel-mbox-provider.c +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-provider.c: mbox provider registration code */ - -/* - * Authors : - * Bertrand Guiheneuf <bertrand@helixcode.com> - * - * Copyright (C) 2000 HelixCode (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 "config.h" -#include "camel-mbox-store.h" -#include "camel-provider.h" -#include "camel-session.h" -#include "camel-url.h" - -static CamelProvider mbox_provider = { - "mbox", - "UNIX mbox-format mail files", - - "For reading mail delivered by the local system, and for " - "storing mail on local disk.", - - "mail", - - 0, - - { 0, 0 }, - - NULL -}; - -void -camel_provider_module_init (CamelSession *session) -{ - mbox_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_mbox_store_get_type(); - - mbox_provider.service_cache = g_hash_table_new (camel_url_hash, camel_url_equal); - - camel_session_register_provider (session, &mbox_provider); -} diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c deleted file mode 100644 index 19b7c54612..0000000000 --- a/camel/providers/mbox/camel-mbox-store.c +++ /dev/null @@ -1,244 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-store.c : class for an mbox store */ - -/* - * - * Copyright (C) 2000 Helix Code, Inc. <bertrand@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 <config.h> - -#include <sys/stat.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> - -#include "camel-mbox-store.h" -#include "camel-mbox-folder.h" -#include "camel-exception.h" -#include "camel-url.h" - -/* Returns the class for a CamelMboxStore */ -#define CMBOXS_CLASS(so) CAMEL_MBOX_STORE_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (GTK_OBJECT(so)->klass) - -static char *get_name (CamelService *service, gboolean brief); -static CamelFolder *get_folder (CamelStore *store, const char *folder_name, - gboolean create, CamelException *ex); -static void delete_folder (CamelStore *store, const char *folder_name, - CamelException *ex); -static char *get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex); - -static void -camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class) -{ - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_mbox_store_class); - CamelServiceClass *camel_service_class = CAMEL_SERVICE_CLASS (camel_mbox_store_class); - - /* virtual method overload */ - camel_service_class->get_name = get_name; - - camel_store_class->get_folder = get_folder; - camel_store_class->delete_folder = delete_folder; - camel_store_class->get_folder_name = get_folder_name; -} - -static void -camel_mbox_store_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - CamelStore *store = CAMEL_STORE (object); - - service->url_flags = CAMEL_SERVICE_URL_NEED_PATH; - - /* mbox names are filenames, so they are case-sensitive. */ - store->folders = g_hash_table_new (g_str_hash, g_str_equal); -} - -GtkType -camel_mbox_store_get_type (void) -{ - static GtkType camel_mbox_store_type = 0; - - if (!camel_mbox_store_type) { - GtkTypeInfo camel_mbox_store_info = - { - "CamelMboxStore", - sizeof (CamelMboxStore), - sizeof (CamelMboxStoreClass), - (GtkClassInitFunc) camel_mbox_store_class_init, - (GtkObjectInitFunc) camel_mbox_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mbox_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_mbox_store_info); - } - - return camel_mbox_store_type; -} - -const gchar * -camel_mbox_store_get_toplevel_dir (CamelMboxStore *store) -{ - CamelURL *url = CAMEL_SERVICE (store)->url; - - g_assert (url != NULL); - return url->path; -} - -static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, gboolean create, - CamelException *ex) -{ - CamelFolder *new_folder; - char *name; - struct stat st; - - name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path, - folder_name); - - if (stat (name, &st) == -1) { - int fd; - - if (errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not open folder `%s':" - "\n%s", folder_name, - g_strerror (errno)); - g_free (name); - return NULL; - } - if (!create) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - "Folder `%s' does not exist.", - folder_name); - g_free (name); - return NULL; - } - - fd = open (name, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); - g_free (name); - if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not create folder `%s':" - "\n%s", folder_name, - g_strerror (errno)); - return NULL; - } - close (fd); - } else if (!S_ISREG (st.st_mode)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - "`%s' is not a regular file.", - name); - g_free (name); - return NULL; - } - - new_folder = gtk_type_new (CAMEL_MBOX_FOLDER_TYPE); - - CF_CLASS (new_folder)->init (new_folder, store, NULL, - folder_name, "/", TRUE, ex); - - return new_folder; -} - -static void -delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) -{ - char *name, *name2; - struct stat st; - int status; - - name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path, - folder_name); - if (stat (name, &st) == -1) { - if (errno == ENOENT) { - /* file doesn't exist - it's kinda like deleting it ;-) */ - g_free (name); - return; - } - - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not delete folder `%s':\n%s", - folder_name, g_strerror (errno)); - g_free (name); - return; - } - - if (!S_ISREG (st.st_mode)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - "`%s' is not a regular file.", name); - g_free (name); - return; - } - - if (st.st_size != 0) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_NON_EMPTY, - "Folder `%s' is not empty. Not deleted.", - folder_name); - g_free (name); - return; - } - - /* Delete index and summary first, then the main file. */ - name2 = g_strdup_printf ("%s.ibex", name); - status = unlink (name2); - g_free (name2); - if (status == 0 || errno == ENOENT) { - name2 = g_strdup_printf ("%s-ev-summary", name); - status = unlink (name2); - g_free (name2); - } - if (status == 0 || errno == ENOENT) - status = unlink (name); - g_free (name); - - if (status == -1 && errno != ENOENT) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not delete folder `%s':\n%s", - folder_name, g_strerror (errno)); - } -} - -static char * -get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) -{ - /* For now, we don't allow hieararchy. FIXME. */ - if (strchr (folder_name + 1, '/')) { - camel_exception_set (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - "Mbox folders may not be nested."); - return NULL; - } - - return *folder_name == '/' ? g_strdup (folder_name) : - g_strdup_printf ("/%s", folder_name); -} - -static char * -get_name (CamelService *service, gboolean brief) -{ - if (brief) - return g_strdup (service->url->path); - else - return g_strdup_printf ("Local mail file %s", service->url->path); -} diff --git a/camel/providers/mbox/camel-mbox-store.h b/camel/providers/mbox/camel-mbox-store.h deleted file mode 100644 index 06a971ada4..0000000000 --- a/camel/providers/mbox/camel-mbox-store.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-store.h : class for an mbox store */ - -/* - * - * Copyright (C) 2000 Helix Code, Inc. <bertrand@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_MBOX_STORE_H -#define CAMEL_MBOX_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-store.h" - -#define CAMEL_MBOX_STORE_TYPE (camel_mbox_store_get_type ()) -#define CAMEL_MBOX_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_MBOX_STORE_TYPE, CamelMboxStore)) -#define CAMEL_MBOX_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MBOX_STORE_TYPE, CamelMboxStoreClass)) -#define IS_CAMEL_MBOX_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_MBOX_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - -} CamelMboxStore; - - - -typedef struct { - CamelStoreClass parent_class; - -} CamelMboxStoreClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mbox_store_get_type (void); - -const gchar *camel_mbox_store_get_toplevel_dir (CamelMboxStore *store); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MBOX_STORE_H */ - - diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c deleted file mode 100644 index 5af28a63e1..0000000000 --- a/camel/providers/mbox/camel-mbox-summary.c +++ /dev/null @@ -1,817 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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-mbox-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 io(x) -#define d(x) - -#define CAMEL_MBOX_SUMMARY_VERSION (0x1000) - -struct _CamelMboxSummaryPrivate { -}; - -#define _PRIVATE(o) (((CamelMboxSummary *)(o))->priv) - -static int summary_header_load (CamelFolderSummary *, FILE *); -static int summary_header_save (CamelFolderSummary *, FILE *); - -static CamelMessageInfo * message_info_new (CamelFolderSummary *, struct _header_raw *); -static CamelMessageInfo * message_info_new_from_parser (CamelFolderSummary *, CamelMimeParser *); -static CamelMessageInfo * message_info_load (CamelFolderSummary *, FILE *); -static int message_info_save (CamelFolderSummary *, FILE *, CamelMessageInfo *); -/*static void message_info_free (CamelFolderSummary *, CamelMessageInfo *);*/ - -static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass); -static void camel_mbox_summary_init (CamelMboxSummary *obj); -static void camel_mbox_summary_finalise (GtkObject *obj); - -static CamelFolderSummaryClass *camel_mbox_summary_parent; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -camel_mbox_summary_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "CamelMboxSummary", - sizeof (CamelMboxSummary), - sizeof (CamelMboxSummaryClass), - (GtkClassInitFunc) camel_mbox_summary_class_init, - (GtkObjectInitFunc) camel_mbox_summary_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (camel_folder_summary_get_type (), &type_info); - } - - return type; -} - -static void -camel_mbox_summary_class_init (CamelMboxSummaryClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass; - - camel_mbox_summary_parent = gtk_type_class (camel_folder_summary_get_type ()); - - object_class->finalize = camel_mbox_summary_finalise; - - sklass->summary_header_load = summary_header_load; - sklass->summary_header_save = summary_header_save; - - sklass->message_info_new = message_info_new; - sklass->message_info_new_from_parser = message_info_new_from_parser; - sklass->message_info_load = message_info_load; - sklass->message_info_save = message_info_save; - /*sklass->message_info_free = message_info_free;*/ - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -camel_mbox_summary_init (CamelMboxSummary *obj) -{ - struct _CamelMboxSummaryPrivate *p; - struct _CamelFolderSummary *s = (CamelFolderSummary *)obj; - - p = _PRIVATE(obj) = g_malloc0(sizeof(*p)); - - /* subclasses need to set the right instance data sizes */ - s->message_info_size = sizeof(CamelMboxMessageInfo); - s->content_info_size = sizeof(CamelMboxMessageContentInfo); - - /* and a unique file version */ - s->version += CAMEL_MBOX_SUMMARY_VERSION; -} - -static void -camel_mbox_summary_finalise (GtkObject *obj) -{ - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (obj); - - g_free (mbs->folder_path); - - ((GtkObjectClass *)(camel_mbox_summary_parent))->finalize(GTK_OBJECT (obj)); -} - -/** - * camel_mbox_summary_new: - * - * Create a new CamelMboxSummary object. - * - * Return value: A new CamelMboxSummary widget. - **/ -CamelMboxSummary * -camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index) -{ - CamelMboxSummary *new = CAMEL_MBOX_SUMMARY (gtk_type_new (camel_mbox_summary_get_type ())); - - if (new) { - /* ?? */ - camel_folder_summary_set_build_content (CAMEL_FOLDER_SUMMARY (new), TRUE); - camel_folder_summary_set_filename (CAMEL_FOLDER_SUMMARY (new), filename); - new->folder_path = g_strdup (mbox_name); - new->index = index; - } - return new; -} - -static int -summary_header_load (CamelFolderSummary *s, FILE *in) -{ - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); - - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load (s, in) == -1) - return -1; - - return camel_folder_summary_decode_uint32 (in, &mbs->folder_size); -} - -static int -summary_header_save (CamelFolderSummary *s, FILE *out) -{ - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); - - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save (s, out) == -1) - return -1; - - return camel_folder_summary_encode_uint32 (out, mbs->folder_size); -} - -static int -header_evolution_decode (const char *in, guint32 *uid, guint32 *flags) -{ - char *header; - - if (in && (header = header_token_decode(in))) { - if (strlen (header) == strlen ("00000000-0000") - && sscanf (header, "%08x-%04x", uid, flags) == 2) { - g_free (header); - return *uid; - } - g_free (header); - } - - return -1; -} - -static char * -header_evolution_encode (guint32 uid, guint32 flags) -{ - return g_strdup_printf ("%08x-%04x", uid, flags & 0xffff); -} - -static CamelMessageInfo * -message_info_new (CamelFolderSummary *s, struct _header_raw *h) -{ - CamelMessageInfo *mi; - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new (s, h); - if (mi) { - const char *xev; - guint32 uid, flags; - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - xev = header_raw_find (&h, "X-Evolution", NULL); - if (xev && header_evolution_decode(xev, &uid, &flags) != -1) { - g_free (mi->uid); - mi->uid = g_strdup_printf ("%u", uid); - mi->flags = flags; - } else { - /* to indicate it has no xev header? */ - mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED | CAMEL_MESSAGE_FOLDER_NOXEV; - mi->uid = g_strdup_printf ("%u", camel_folder_summary_next_uid (s)); - } - mbi->frompos = -1; - } - - return mi; -} - -static CamelMessageInfo * -message_info_new_from_parser (CamelFolderSummary *s, CamelMimeParser *mp) -{ - CamelMessageInfo *mi; - CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s); - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser (s, mp); - if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - mbi->frompos = camel_mime_parser_tell_start_from (mp); - - /* do we want to index this message as we add it, as well? */ - if (mbs->index_force - || (mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0 - || !ibex_contains_name(mbs->index, mi->uid)) { - - camel_folder_summary_set_index (s, mbs->index); - } else { - camel_folder_summary_set_index (s, NULL); - } - } - - return mi; -} - -static CamelMessageInfo * -message_info_load (CamelFolderSummary *s, FILE *in) -{ - CamelMessageInfo *mi; - - io (printf ("loading mbox message info\n")); - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load (s, in); - if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - camel_folder_summary_decode_uint32 (in, &mbi->frompos); - } - - return mi; -} - -static int -message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi) -{ - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - io (printf ("saving mbox message info\n")); - - ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save (s, out, mi); - - return camel_folder_summary_encode_uint32 (out, mbi->frompos); -} - -static int -summary_rebuild (CamelMboxSummary *mbs, off_t offset) -{ - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); - CamelMimeParser *mp; - int fd; - int ok = 0; - - fd = open (mbs->folder_path, O_RDONLY); - if (fd == -1) { - printf ("%s failed to open: %s", mbs->folder_path, strerror (errno)); - return -1; - } - - mp = camel_mime_parser_new (); - camel_mime_parser_init_with_fd (mp, fd); - camel_mime_parser_scan_from (mp, TRUE); - camel_mime_parser_seek (mp, offset, SEEK_SET); - - if (offset > 0) { - if (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) { - if (camel_mime_parser_tell_start_from (mp) != offset) { - g_warning ("The next message didn't start where I expected\nbuilding summary from start"); - camel_mime_parser_drop_step (mp); - offset = 0; - camel_mime_parser_seek (mp, offset, SEEK_SET); - camel_folder_summary_clear (CAMEL_FOLDER_SUMMARY (mbs)); - } else { - camel_mime_parser_unstep (mp); - } - } else { - gtk_object_unref (GTK_OBJECT (mp)); - /* end of file - no content? */ - return -1; - } - } - - while (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) { - CamelMessageInfo *info; - - info = camel_folder_summary_add_from_parser (CAMEL_FOLDER_SUMMARY (mbs), mp); - if (info == NULL) { - printf ("Could not build info from file?\n"); - ok = -1; - break; - } - - g_assert (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM_END); - } - - gtk_object_unref (GTK_OBJECT (mp)); - - /* update the file size/mtime in the summary */ - if (ok != -1) { - struct stat st; - - if (stat (mbs->folder_path, &st) == 0) { - mbs->folder_size = st.st_size; - s->time = st.st_mtime; - } - } - - return ok; -} - -int -camel_mbox_summary_update (CamelMboxSummary *mbs, off_t offset) -{ - int ret; - - mbs->index_force = FALSE; - ret = summary_rebuild (mbs, offset); - -#if 0 -#warning "Saving full summary and index after every summarisation is slow ..." - if (ret != -1) { - if (camel_folder_summary_save((CamelFolderSummary *)mbs) == -1) - g_warning("Could not save summary: %s", strerror(errno)); - if (mbs->index) - ibex_save(mbs->index); - } -#endif - return ret; -} - -int -camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex) -{ - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); - struct stat st; - int ret = 0; - off_t minstart; - - mbs->index_force = forceindex; - - /* is the summary out of date? */ - if (stat (mbs->folder_path, &st) == -1) { - camel_folder_summary_clear (s); - printf ("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno)); - return -1; - } - - if (forceindex || camel_folder_summary_load (s) == -1) { - printf ("REBUILDING SUMMARY: %s\n", - forceindex ? "Summary non-existent." : "Summary load failed."); - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); - } else { - minstart = st.st_size; -#if 0 - /* find out the first unindexed message ... */ - /* TODO: For this to work, it has to check that the message is - indexable, and contains content ... maybe it cannot be done - properly? */ - for (i=0;i<camel_folder_summary_count(s);i++) { - CamelMessageInfo *mi = camel_folder_summary_index(s, i); - if (!ibex_contains_name(mbs->index, mi->uid)) { - minstart = ((CamelMboxMessageInfo *)mi)->frompos; - printf("Found unindexed message: %s\n", mi->uid); - break; - } - } -#endif - /* is the summary uptodate? */ - if (st.st_size == mbs->folder_size && st.st_mtime == s->time) { - if (minstart < st.st_size) { - /* FIXME: Only clear the messages and reindex from this point forward */ - printf ("REBUILDING SUMMARY: Index file is incomplete.\n"); - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); - } - } else { - if (mbs->folder_size < st.st_size) { - printf ("REBUILDING SUMMARY: Summary is for a smaller mbox\n"); - if (minstart < mbs->folder_size) { - /* FIXME: only make it rebuild as necessary */ - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); - } else { - ret = summary_rebuild (mbs, mbs->folder_size); - } - } else { - if (mbs->folder_size > st.st_size) - printf ("REBUILDING_SUMMARY: Summary is for a bigger mbox\n"); - else - printf ("REBUILDING SUMMARY: Summary is for an older mbox\n"); - camel_folder_summary_clear (s); - ret = summary_rebuild (mbs, 0); - } - } - } - - if (ret != -1) { - mbs->folder_size = st.st_size; - s->time = st.st_mtime; - if (camel_folder_summary_save (s) == -1) - g_warning("Could not save summary: %s", strerror (errno)); - if (mbs->index) - ibex_save (mbs->index); - } - - return ret; -} - -static int -header_write (int fd, struct _header_raw *header, char *xevline) -{ - struct iovec iv[4]; - int outlen = 0, len; - - iv[1].iov_base = ":"; - iv[1].iov_len = 1; - iv[3].iov_base = "\n"; - iv[3].iov_len = 1; - - while (header) { - if (strcasecmp (header->name, "X-Evolution")) { - iv[0].iov_base = header->name; - iv[0].iov_len = strlen(header->name); - iv[2].iov_base = header->value; - iv[2].iov_len = strlen(header->value); - - do { - len = writev(fd, iv, 4); - } while (len == -1 && errno == EINTR); - - if (len == -1) - return -1; - outlen += len; - } - header = header->next; - } - - iv[0].iov_base = "X-Evolution: "; - iv[0].iov_len = strlen (iv[0].iov_base); - iv[1].iov_base = xevline; - iv[1].iov_len = strlen (xevline); - iv[2].iov_base = "\n\n"; - iv[2].iov_len = 2; - - do { - len = writev (fd, iv, 3); - } while (len == -1 && errno == EINTR); - - if (len == -1) - return -1; - - outlen += 1; - - d(printf ("Wrote %d bytes of headers\n", outlen)); - - return outlen; -} - -static int -copy_block(int fromfd, int tofd, off_t start, size_t bytes) -{ - char buffer[4096]; - int written = 0; - - d(printf ("writing %d bytes ... ", bytes)); - - if (lseek(fromfd, start, SEEK_SET) != start) - return -1; - - while (bytes > 0) { - int toread, towrite; - - toread = bytes; - if (bytes > 4096) - toread = 4096; - else - toread = bytes; - do { - towrite = read (fromfd, buffer, toread); - } while (towrite == -1 && errno == EINTR); - - if (towrite == -1) - return -1; - - /* check for 'end of file' */ - if (towrite == 0) { - d(printf ("end of file?\n")); - break; - } - - do { - toread = write (tofd, buffer, towrite); - } while (toread == -1 && errno == EINTR); - - if (toread == -1) - return -1; - - written += toread; - bytes -= toread; - } - - d(printf ("written %d bytes\n", written)); - - return written; -} - -int -camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException *ex) -{ - CamelMimeParser *mp = NULL; - int i, count; - CamelMboxMessageInfo *info; - CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs); - int fd = -1, fdout = -1; - off_t offset = 0; - char *tmpname = NULL; - char *buffer, *xevnew = NULL; - const char *xev; - int len; - guint32 uid, flags; - int quick = TRUE, work = FALSE; - struct stat st; - - /* make sure we're in sync */ - count = camel_folder_summary_count (s); - if (count > 0) { - CamelMessageInfo *mi = camel_folder_summary_index (s, count - 1); - camel_mbox_summary_update (mbs, mi->content->endpos); - } else { - camel_mbox_summary_update (mbs, 0); - } - - /* check if we have any work to do */ - d(printf ("Performing sync, %d messages in inbox\n", count)); - for (i = 0; quick && i < count; i++) { - info = (CamelMboxMessageInfo *)camel_folder_summary_index (s, i); - if ((expunge && (info->info.flags & CAMEL_MESSAGE_DELETED)) || - (info->info.flags & CAMEL_MESSAGE_FOLDER_NOXEV)) - quick = FALSE; - else - work |= (info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0; - } - - d(printf ("Options: %s %s %s\n", expunge ? "expunge" : "", quick ? "quick" : "", work ? "Work" : "")); - - if (quick && !work) - return 0; - - fd = open (mbs->folder_path, O_RDWR); - if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not open summary %s", mbs->folder_path); - return -1; - } - - mp = camel_mime_parser_new (); - camel_mime_parser_scan_from (mp, TRUE); - camel_mime_parser_init_with_fd (mp, fd); - - if (!quick) { - tmpname = alloca (strlen (mbs->folder_path) + 5); - sprintf (tmpname, "%s.tmp", mbs->folder_path); - d(printf ("Writing tmp file to %s\n", tmpname)); - retry_out: - fdout = open (tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600); - if (fdout == -1) { - if (errno == EEXIST) - if (unlink(tmpname) != -1) - goto retry_out; - - free (tmpname); - tmpname = NULL; - g_warning ("Something failed (yo!)"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot open temporary mailbox: %s", strerror (errno)); - goto error; - } - } - - for (i = 0; i < count; i++) { - off_t frompos, bodypos, lastpos; - /* This has to be an int, not an off_t, because that's - * what camel_mime_parser_header returns... FIXME. - */ - int xevoffset; - - info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); - - g_assert (info); - - d(printf ("Looking at message %s\n", info->info.uid)); - - if (expunge && info->info.flags & CAMEL_MESSAGE_DELETED) { - d(printf ("Deleting %s\n", info->info.uid)); - - g_assert (!quick); - offset -= (info->info.content->endpos - info->frompos); - if (mbs->index) - ibex_unindex (mbs->index, info->info.uid); - camel_folder_summary_remove (s, (CamelMessageInfo *)info); - count--; - i--; - info = NULL; - } else if (info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV | CAMEL_MESSAGE_FOLDER_FLAGGED)) { - int xevok = FALSE; - - d(printf ("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags)); - - /* find the next message, header parts */ - camel_mime_parser_seek (mp, info->frompos, SEEK_SET); - if (camel_mime_parser_step (mp, &buffer, &len) != HSCAN_FROM) { - g_warning ("camel_mime_parser_step failed (1)"); - goto error; - } - - if (camel_mime_parser_tell_start_from (mp) != info->frompos) { - g_warning ("Summary/mbox mismatch, aborting sync"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Summary mismatch, aborting sync"); - goto error; - } - - if (camel_mime_parser_step (mp, &buffer, &len) == HSCAN_FROM_END) { - g_warning ("camel_mime_parser_step failed (2)"); - goto error; - } - - /* Check if the X-Evolution header is valid. */ - - xev = camel_mime_parser_header (mp, "X-Evolution", &xevoffset); - if (xev && header_evolution_decode (xev, &uid, &flags) != -1) - xevok = TRUE; - - xevnew = header_evolution_encode (strtoul (info->info.uid, NULL, 10), info->info.flags & 0xffff); - if (quick) { - if (!xevok) { - g_warning ("The summary told me I had an X-Evolution header, but i dont!"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Summary mismatch, X-Evolution header missing"); - goto error; - } - buffer = g_strdup_printf ("X-Evolution: %s", xevnew); - lastpos = lseek (fd, 0, SEEK_CUR); - lseek (fd, xevoffset, SEEK_SET); - do { - len = write (fd, buffer, strlen (buffer)); - } while (len == -1 && errno == EINTR); - lseek (fd, lastpos, SEEK_SET); - g_free (buffer); - if (len == -1) { - g_warning ("Yahoo! len == -1"); - goto error; - } - } else { - frompos = lseek (fdout, 0, SEEK_CUR); - write (fdout, "From -\n", strlen("From -\n")); - if (header_write (fdout, camel_mime_parser_headers_raw (mp), xevnew) == -1) { - d(printf ("Error writing to tmp mailbox\n")); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Error writing to temp mailbox: %s", - strerror (errno)); - goto error; - } - bodypos = lseek (fdout, 0, SEEK_CUR); - d(printf ("pos = %d, endpos = %d, bodypos = %d\n", - (int) info->info.content->pos, - (int) info->info.content->endpos, - (int) info->info.content->bodypos)); - if (copy_block (fd, fdout, info->info.content->bodypos, - info->info.content->endpos - info->info.content->bodypos) == -1) { - g_warning ("Cannot copy data to output fd"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot copy data to output fd: %s", - strerror (errno)); - goto error; - } - info->frompos = frompos; - offset = bodypos - info->info.content->bodypos; - } - info->info.flags &= 0xffff; - g_free (xevnew); - xevnew = NULL; - camel_mime_parser_drop_step (mp); - camel_mime_parser_drop_step (mp); - } else { - if (!quick) { - if (copy_block (fd, fdout, info->frompos, - info->info.content->endpos - info->frompos) == -1) { - g_warning ("Cannot copy data to output fd"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot copy data to output fd: %s", - strerror (errno)); - goto error; - } - /* update from pos here? */ - info->frompos += offset; - } else { - d(printf ("Nothing to do for this message\n")); - } - } - if (!quick && info != NULL && offset != 0) { - d(printf ("offsetting content: %d\n", (int) offset)); - camel_folder_summary_offset_content (info->info.content, offset); - d(printf ("pos = %d, endpos = %d, bodypos = %d\n", - (int) info->info.content->pos, - (int) info->info.content->endpos, - (int) info->info.content->bodypos)); - } - } - - d(printf ("Closing folders\n")); - - if (close (fd) == -1) { - g_warning ("Cannot close source folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not close source folder %s: %s", - mbs->folder_path, strerror (errno)); - goto error; - } - - if (!quick) { - if (close (fdout) == -1) { - g_warning ("Cannot close tmp folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not close temp folder: %s", - strerror (errno)); - goto error; - } - - if (rename (tmpname, mbs->folder_path) == -1) { - g_warning ("Cannot rename folder: %s", strerror (errno)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not rename folder: %s", - strerror (errno)); - goto error; - } - tmpname = NULL; - - if (mbs->index) - ibex_save (mbs->index); - } - - if (stat (mbs->folder_path, &st) == -1) { - g_warning ("Hmm... stat(mbs->folder_path, &st) == -1"); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Unknown error: %s", - strerror (errno)); - goto error; - } - - camel_folder_summary_touch (s); - s->time = st.st_mtime; - mbs->folder_size = st.st_size; - camel_folder_summary_save (s); - - gtk_object_unref (GTK_OBJECT (mp)); - - return 0; - error: - if (fd != -1) - close (fd); - - if (fdout != -1) - close (fdout); - - g_free (xevnew); - - if (tmpname) - unlink (tmpname); - if (mp) - gtk_object_unref (GTK_OBJECT (mp)); - - return -1; -} - - - - - diff --git a/camel/providers/mbox/camel-mbox-summary.h b/camel/providers/mbox/camel-mbox-summary.h deleted file mode 100644 index fb31002320..0000000000 --- a/camel/providers/mbox/camel-mbox-summary.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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_MBOX_SUMMARY_H -#define _CAMEL_MBOX_SUMMARY_H - -#include <gtk/gtk.h> -#include <camel/camel-folder-summary.h> -#include <camel/camel-exception.h> -#include <libibex/ibex.h> - -#define CAMEL_MBOX_SUMMARY(obj) GTK_CHECK_CAST (obj, camel_mbox_summary_get_type (), CamelMboxSummary) -#define CAMEL_MBOX_SUMMARY_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_mbox_summary_get_type (), CamelMboxSummaryClass) -#define IS_CAMEL_MBOX_SUMMARY(obj) GTK_CHECK_TYPE (obj, camel_mbox_summary_get_type ()) - -typedef struct _CamelMboxSummary CamelMboxSummary; -typedef struct _CamelMboxSummaryClass CamelMboxSummaryClass; - -/* extra summary flags */ -enum { - CAMEL_MESSAGE_FOLDER_NOXEV = 1<<17, -}; - -typedef struct _CamelMboxMessageContentInfo { - CamelMessageContentInfo info; -} CamelMboxMessageContentInfo; - -typedef struct _CamelMboxMessageInfo { - CamelMessageInfo info; - - off_t frompos; -} CamelMboxMessageInfo; - -struct _CamelMboxSummary { - CamelFolderSummary parent; - - struct _CamelMboxSummaryPrivate *priv; - - char *folder_path; /* name of matching folder */ - size_t folder_size; /* size of the mbox file, last sync */ - - ibex *index; - int index_force; /* do we force index during creation? */ -}; - -struct _CamelMboxSummaryClass { - CamelFolderSummaryClass parent_class; -}; - -guint camel_mbox_summary_get_type (void); -CamelMboxSummary *camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index); - -/* load/check the summary */ -int camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex); -/* incremental update */ -int camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset); -/* perform a folder sync or expunge, if needed */ -int camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException *ex); - -#endif /* ! _CAMEL_MBOX_SUMMARY_H */ - diff --git a/camel/providers/mbox/libcamelmbox.urls b/camel/providers/mbox/libcamelmbox.urls deleted file mode 100644 index e021190356..0000000000 --- a/camel/providers/mbox/libcamelmbox.urls +++ /dev/null @@ -1 +0,0 @@ -mbox diff --git a/camel/providers/nntp/.cvsignore b/camel/providers/nntp/.cvsignore deleted file mode 100644 index 1f5b9d35fb..0000000000 --- a/camel/providers/nntp/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -.deps -Makefile -Makefile.in -.libs -.deps -*.lo -*.la -test-newsrc diff --git a/camel/providers/nntp/Makefile.am b/camel/providers/nntp/Makefile.am deleted file mode 100644 index a205f5bb83..0000000000 --- a/camel/providers/nntp/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelnntpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelnntp.la -provider_DATA = libcamelnntp.urls - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -I$(srcdir)/../mbox \ - -DG_LOG_DOMAIN=\"camel-nntp-provider\" - -libcamelnntp_la_SOURCES = \ - camel-nntp-folder.c \ - camel-nntp-newsrc.c \ - camel-nntp-provider.c \ - camel-nntp-store.c \ - camel-nntp-utils.c - -libcamelnntpinclude_HEADERS = \ - camel-nntp-folder.h \ - camel-nntp-newsrc.h \ - camel-nntp-store.h - -libcamelnntp_la_LDFLAGS = -version-info 0:0:0 - -EXTRA_DIST = libcamelnntp.urls - -noinst_PROGRAMS = test-newsrc - -LDADD = \ - $(top_builddir)/camel/libcamel.la \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/libibex/libibex.la \ - $(GNOME_LIBDIR) \ - $(GNOMEUI_LIBS) $(INTLLIBS) $(EXTRA_GNOME_LIBS) -# $(BONOBO_LIBS) - -test_newsrc_LDADD = libcamelnntp.la $(LDADD) diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c deleted file mode 100644 index a3cfc49d26..0000000000 --- a/camel/providers/nntp/camel-nntp-folder.c +++ /dev/null @@ -1,469 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-folder.c : Abstract class for an email folder */ - -/* - * Author : Chris Toshok <toshok@helixcode.com> - * - * Copyright (C) 2000 Helix Code . - * - * 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 "camel-folder-summary.h" -#include "camel-nntp-store.h" -#include "camel-nntp-folder.h" -#include "camel-nntp-store.h" -#include "camel-nntp-utils.h" - -#include "string-utils.h" -#include "camel-stream-mem.h" -#include "camel-stream-buffer.h" -#include "camel-data-wrapper.h" -#include "camel-mime-message.h" -#include "camel-folder-summary.h" - -#include "camel-exception.h" - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelNNTPFolder */ -#define CNNTPF_CLASS(so) CAMEL_NNTP_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CNNTPS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - - -static void _check_get_or_maybe_generate_summary_file (CamelNNTPFolder *nntp_folder, - CamelException *ex); - -static void -nntp_folder_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar *separator, gboolean path_begins_with_sep, - CamelException *ex) -{ - const gchar *root_dir_path; - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - - /* call parent method */ - parent_class->init (folder, parent_store, parent_folder, - name, separator, path_begins_with_sep, - ex); - if (camel_exception_get_id (ex)) return; - - /* set flags */ - - if (!strcmp (name, "/")) { - /* the root folder is the only folder that has "subfolders" */ - folder->can_hold_folders = TRUE; - folder->can_hold_messages = FALSE; - } - else { - folder->can_hold_folders = FALSE; - folder->can_hold_messages = TRUE; - folder->has_summary_capability = TRUE; - } - - /* XX */ - nntp_folder->group_name = g_strdup (strrchr (name, '/') + 1); - -#if 0 - /* get (or create) uid list */ - if (!(nntp_load_uid_list (nntp_folder) > 0)) - nntp_generate_uid_list (nntp_folder); -#endif - - root_dir_path = camel_nntp_store_get_toplevel_dir (CAMEL_NNTP_STORE(folder->parent_store)); - - nntp_folder->summary_file_path = g_strdup_printf ("%s/%s-ev-summary", - root_dir_path, nntp_folder->group_name); -} - -static void -nntp_folder_sync (CamelFolder *folder, gboolean expunge, - CamelException *ex) -{ - camel_folder_summary_save (CAMEL_NNTP_FOLDER(folder)->summary); -} - -static const gchar * -nntp_folder_get_name (CamelFolder *folder) -{ - g_assert(0); - return NULL; -} - -static const gchar * -nntp_folder_get_full_name (CamelFolder *folder) -{ - g_assert(0); - return NULL; -} - -static CamelFolder* -nntp_folder_get_subfolder (CamelFolder *folder, - const gchar *folder_name, - gboolean create, - CamelException *ex) -{ - g_assert (0); - return NULL; -} - -static gint -nntp_folder_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER(folder); - - g_assert (folder); - g_assert (nntp_folder->summary); - - return camel_folder_summary_count(nntp_folder->summary); -} - -static guint32 -nntp_folder_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - CamelMessageInfo *info = camel_folder_summary_uid (nntp_folder->summary, uid); - - return info->flags; -} - -static void -nntp_folder_set_message_flags (CamelFolder *folder, const char *uid, - guint32 flags, guint32 set, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - CamelMessageInfo *info = camel_folder_summary_uid (nntp_folder->summary, uid); - - info->flags = set; - - camel_folder_summary_touch (nntp_folder->summary); - if (set & CAMEL_MESSAGE_SEEN) { - CamelNNTPStore *store; - CamelException *ex; - - ex = camel_exception_new (); - store = CAMEL_NNTP_STORE (camel_folder_get_parent_store (folder, ex)); - camel_exception_free (ex); - - camel_nntp_newsrc_mark_article_read (store->newsrc, - nntp_folder->group_name, - 1 /* XXX */); - } -} - -static const gchar* -nntp_folder_get_message_uid (CamelFolder *folder, - CamelMimeMessage *message, - CamelException *ex) -{ - g_assert (0); - return NULL; -} - -static CamelMimeMessage * -nntp_folder_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelStream *nntp_istream; - CamelStream *message_stream; - CamelMimeMessage *message = NULL; - CamelStore *parent_store; - char *buf; - int buf_len; - int buf_alloc; - int status; - gboolean done; - - /* get the parent store */ - parent_store = camel_folder_get_parent_store (folder, ex); - if (camel_exception_get_id (ex)) { - return NULL; - } - - status = camel_nntp_command (CAMEL_NNTP_STORE( parent_store ), NULL, "ARTICLE %s", uid); - - nntp_istream = CAMEL_NNTP_STORE (parent_store)->istream; - - /* if the uid was not found, raise an exception and return */ - if (status != CAMEL_NNTP_OK) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "message %s not found.", - uid); - return NULL; - } - - /* XXX ick ick ick. read the entire message into a buffer and - then create a stream_mem for it. */ - buf_alloc = 2048; - buf_len = 0; - buf = malloc(buf_alloc); - done = FALSE; - - buf[0] = 0; - - while (!done) { - char *line = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER ( nntp_istream )); - int line_length; - - /* XXX check exception */ - - line_length = strlen ( line ); - - if (!strcmp(line, ".")) { - done = TRUE; - g_free (line); - } - else { - if (buf_len + line_length > buf_alloc) { - buf_alloc *= 2; - buf = realloc (buf, buf_alloc); - } - strcat(buf, line); - strcat(buf, "\n"); - buf_len += strlen(line) + 1; - g_free (line); - } - } - - /* create a stream bound to the message */ - message_stream = camel_stream_mem_new_with_buffer(buf, buf_len); - - message = camel_mime_message_new (); - if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)message, message_stream) == -1) { - gtk_object_unref ((GtkObject *)message); - gtk_object_unref ((GtkObject *)message_stream); - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INVALID_UID, /* XXX */ - "Could not create message for uid %s.", uid); - - return NULL; - } - gtk_object_unref ((GtkObject *)message_stream); - - /* init other fields? */ - gtk_object_ref((GtkObject *)folder); - -#if 0 - gtk_signal_connect((GtkObject *)message, "message_changed", message_changed, folder); -#endif - - return message; -} - -static void -nntp_folder_delete_message_by_uid (CamelFolder *folder, - const gchar *uid, - CamelException *ex) -{ - g_assert (0); -} - -static GPtrArray * -nntp_folder_get_uids (CamelFolder *folder, - CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - GPtrArray *message_info_array, *out; - CamelMessageInfo *message_info; - int i; - - message_info_array = nntp_folder->summary->messages; - - out = g_ptr_array_new (); - g_ptr_array_set_size (out, message_info_array->len); - - for (i=0; i<message_info_array->len; i++) { - message_info = (CamelMessageInfo *)(message_info_array->pdata) + i; - out->pdata[i] = g_strdup (message_info->uid); - } - - return out; -} - -static void -nntp_folder_free_uids (CamelFolder *folder, - GPtrArray *array) -{ - int i; - for (i = 0; i < array->len; i ++) { - g_free (g_ptr_array_index (array, i)); - } - g_ptr_array_free (array, TRUE /* XXX? */); -} - -static GPtrArray * -nntp_folder_get_summary (CamelFolder *folder, - CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - _check_get_or_maybe_generate_summary_file (nntp_folder, ex); - - return nntp_folder->summary->messages; -} - -static void -nntp_folder_free_summary (CamelFolder *folder, - GPtrArray *summary) -{ - g_assert (0); -} - -static GPtrArray * -nntp_folder_get_subfolder_names (CamelFolder *folder, CamelException *ex) -{ - if (!strcmp (folder->name, "/")) { - CamelStore *store = camel_folder_get_parent_store (folder, ex); - GPtrArray *array = camel_nntp_newsrc_get_subscribed_group_names (CAMEL_NNTP_STORE (store)->newsrc); - return array; - } - else { - return NULL; - } -} - -static void -nntp_folder_free_subfolder_names (CamelFolder *folder, GPtrArray *subfolders) -{ - if (subfolders) { - CamelException *ex = camel_exception_new (); - CamelStore *store = camel_folder_get_parent_store (folder, ex); - camel_nntp_newsrc_free_group_names (CAMEL_NNTP_STORE (store)->newsrc, subfolders); - camel_exception_free (ex); - } -} - -static GList* -nntp_folder_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex) -{ - g_assert (0); - return NULL; -} - -static const CamelMessageInfo* -nntp_folder_summary_get_by_uid (CamelFolder *folder, const char *uid) -{ - g_assert(0); - return NULL; -} - -static void -nntp_folder_finalize (GtkObject *object) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (object); - - g_free (nntp_folder->summary_file_path); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -camel_nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_nntp_folder_class); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - - /* virtual method overload */ - camel_folder_class->init = nntp_folder_init; - camel_folder_class->sync = nntp_folder_sync; - camel_folder_class->get_name = nntp_folder_get_name; - camel_folder_class->get_full_name = nntp_folder_get_full_name; - camel_folder_class->get_subfolder = nntp_folder_get_subfolder; - camel_folder_class->get_message_count = nntp_folder_get_message_count; - camel_folder_class->set_message_flags = nntp_folder_set_message_flags; - camel_folder_class->get_message_flags = nntp_folder_get_message_flags; - camel_folder_class->get_message_uid = nntp_folder_get_message_uid; - camel_folder_class->get_message_by_uid = nntp_folder_get_message_by_uid; - camel_folder_class->delete_message_by_uid = nntp_folder_delete_message_by_uid; - camel_folder_class->get_uids = nntp_folder_get_uids; - camel_folder_class->free_uids = nntp_folder_free_uids; - camel_folder_class->get_summary = nntp_folder_get_summary; - camel_folder_class->free_summary = nntp_folder_free_summary; - camel_folder_class->get_subfolder_names = nntp_folder_get_subfolder_names; - camel_folder_class->free_subfolder_names = nntp_folder_free_subfolder_names; - camel_folder_class->search_by_expression = nntp_folder_search_by_expression; - camel_folder_class->summary_get_by_uid = nntp_folder_summary_get_by_uid; - - gtk_object_class->finalize = nntp_folder_finalize; - -} - -GtkType -camel_nntp_folder_get_type (void) -{ - static GtkType camel_nntp_folder_type = 0; - - if (!camel_nntp_folder_type) { - GtkTypeInfo camel_nntp_folder_info = - { - "CamelNNTPFolder", - sizeof (CamelNNTPFolder), - sizeof (CamelNNTPFolderClass), - (GtkClassInitFunc) camel_nntp_folder_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_nntp_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_nntp_folder_info); - } - - return camel_nntp_folder_type; -} - - -/* internal method used to : - - test for the existence of a summary file - - test the sync between the summary and the newsgroup - - load the summary or create it if necessary -*/ -static void -_check_get_or_maybe_generate_summary_file (CamelNNTPFolder *nntp_folder, - CamelException *ex) -{ - CamelFolder *folder = CAMEL_FOLDER (nntp_folder); - - nntp_folder->summary = camel_folder_summary_new (); - camel_folder_summary_set_filename (nntp_folder->summary, nntp_folder->summary_file_path); - - if (-1 == camel_folder_summary_load (nntp_folder->summary)) { - /* Bad or nonexistant summary file */ - camel_nntp_get_headers (CAMEL_FOLDER( folder )->parent_store, nntp_folder, ex); - if (camel_exception_get_id (ex)) - return; - - /* XXX check return value */ - camel_folder_summary_save (nntp_folder->summary); - } -} diff --git a/camel/providers/nntp/camel-nntp-folder.h b/camel/providers/nntp/camel-nntp-folder.h deleted file mode 100644 index f6c04bb005..0000000000 --- a/camel/providers/nntp/camel-nntp-folder.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-folder.h : NNTP group (folder) support. */ - -/* - * - * Author : Chris Toshok <toshok@helixcode.com> - * - * Copyright (C) 2000 Helix Code . - * - * 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_NNTP_FOLDER_H -#define CAMEL_NNTP_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-folder.h" - -/* #include "camel-store.h" */ - -#define CAMEL_NNTP_FOLDER_TYPE (camel_nntp_folder_get_type ()) -#define CAMEL_NNTP_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_NNTP_FOLDER_TYPE, CamelNNTPFolder)) -#define CAMEL_NNTP_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_NNTP_FOLDER_TYPE, CamelNNTPFolderClass)) -#define IS_CAMEL_NNTP_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_NNTP_FOLDER_TYPE)) - - -typedef struct { - CamelFolder parent_object; - - gchar *group_name; - gchar *summary_file_path; /* contains the messages summary */ - CamelFolderSummary *summary; -} CamelNNTPFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelNNTPFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_nntp_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_NNTP_FOLDER_H */ diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c deleted file mode 100644 index fc0f4c2a1a..0000000000 --- a/camel/providers/nntp/camel-nntp-newsrc.c +++ /dev/null @@ -1,461 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-newsrc.c - .newsrc parsing/regurgitating code */ -/* - * - * Copyright (C) 2000 Helix Code, Inc. <toshok@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 <config.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <glib.h> -#include "camel-nntp-newsrc.h" - -typedef struct { - guint low; - guint high; -} ArticleRange; - -typedef struct { - char *name; - GArray *ranges; - gboolean subscribed; -} NewsrcGroup; - -struct CamelNNTPNewsrc { - gchar *filename; - GHashTable *groups; - GHashTable *subscribed_groups; - gboolean dirty; -} ; - -static NewsrcGroup * -camel_nntp_newsrc_group_add (CamelNNTPNewsrc *newsrc, char *group_name, gboolean subscribed) -{ - NewsrcGroup *new_group = g_malloc(sizeof(NewsrcGroup)); - - new_group->name = g_strdup(group_name); - new_group->subscribed = subscribed; - new_group->ranges = g_array_new (FALSE, FALSE, sizeof (ArticleRange)); - - g_hash_table_insert (newsrc->groups, new_group->name, new_group); - if (subscribed) - g_hash_table_insert (newsrc->subscribed_groups, new_group->name, new_group); - - newsrc->dirty = TRUE; - - return new_group; -} - -static long -camel_nntp_newsrc_group_get_highest_article_read(CamelNNTPNewsrc *newsrc, NewsrcGroup *group) -{ - if (group->ranges->len == 0) - return 0; - - return g_array_index(group->ranges, ArticleRange, group->ranges->len - 1).high; -} - -static void -camel_nntp_newsrc_group_mark_range_read(CamelNNTPNewsrc *newsrc, NewsrcGroup *group, long low, long high) -{ - int i; - - if (group->ranges->len == 1 - && g_array_index (group->ranges, ArticleRange, 0).low == 0 - && g_array_index (group->ranges, ArticleRange, 0).high == 0) { - g_array_index (group->ranges, ArticleRange, 0).low = low; - g_array_index (group->ranges, ArticleRange, 0).high = high; - - newsrc->dirty = TRUE; - } - else { - ArticleRange tmp_range; - - for (i = 0; i < group->ranges->len; i ++) { - guint range_low = g_array_index (group->ranges, ArticleRange, i).low; - guint range_high = g_array_index (group->ranges, ArticleRange, i).high; - - /* if it's already part of a range, return immediately. */ - if (low >= range_low && - low <= range_high && - high >= range_low && - high <= range_high) { - return; - } - /* if we have a new lower bound for this range, set it. */ - else if (low <= range_low - && high >= range_low - && high <= range_high) { - g_array_index (group->ranges, ArticleRange, i).low = low; - newsrc->dirty = TRUE; - return; - } - /* if we have a new upper bound for this range, set it. */ - else if (high >= range_high - && low >= range_low - && low <= range_high) { - g_array_index (group->ranges, ArticleRange, i).high = high; - newsrc->dirty = TRUE; - return; - } - /* if we would be inserting another range that - starts one index higher than an existing - one, make the upper value of the existing - range the upper value of the new one. */ - else if (low == range_high + 1) { - g_array_index (group->ranges, ArticleRange, i).high = high; - newsrc->dirty = TRUE; - return; - } - /* if we would be inserting another range that - ends one index lower than an existing one, - group the existing range by setting its low - to the new low */ - else if (high == range_low - 1) { - g_array_index (group->ranges, ArticleRange, i).low = low; - newsrc->dirty = TRUE; - return; - } - /* if the range lies entirely outside another - range, doesn't coincide with it's - endpoints, and has lower values, insert it - into the middle of the list. */ - else if (low < range_low - && high < range_low) { - tmp_range.low = low; - tmp_range.high = high; - - group->ranges = g_array_insert_val (group->ranges, i, tmp_range); - newsrc->dirty = TRUE; - - return; - } - } - - /* if we made it here, the range needs to go at the end */ - tmp_range.low = low; - tmp_range.high = high; - group->ranges = g_array_append_val (group->ranges, tmp_range); - newsrc->dirty = TRUE; - } -} - -int -camel_nntp_newsrc_get_highest_article_read (CamelNNTPNewsrc *newsrc, char *group_name) -{ - NewsrcGroup *group; - - group = g_hash_table_lookup (newsrc->groups, group_name); - - return camel_nntp_newsrc_group_get_highest_article_read (newsrc, group); -} - -void -camel_nntp_newsrc_mark_article_read (CamelNNTPNewsrc *newsrc, char *group_name, int num) -{ - camel_nntp_newsrc_mark_range_read (newsrc, group_name, num, num); -} - -void -camel_nntp_newsrc_mark_range_read(CamelNNTPNewsrc *newsrc, char *group_name, long low, long high) -{ - NewsrcGroup *group; - - /* swap them if they're in the wrong order. */ - if (low > high) { - long tmp; - - tmp = high; - high = low; - low = tmp; - } - - group = g_hash_table_lookup (newsrc->groups, group_name); - - camel_nntp_newsrc_group_mark_range_read (newsrc, group, low, high); -} - -gboolean -camel_nntp_newsrc_article_is_read (CamelNNTPNewsrc *newsrc, char *group_name, long num) -{ - int i; - NewsrcGroup *group; - - group = g_hash_table_lookup (newsrc->groups, group_name); - - for (i = 0; i < group->ranges->len; i++) { - if (num >= g_array_index (group->ranges, ArticleRange, i).low && - num <= g_array_index (group->ranges, ArticleRange, i).high) { - return TRUE; - } - } - - return FALSE; -} - -struct newsrc_ptr_array { - GPtrArray *ptr_array; - gboolean subscribed_only; -}; - -static void -get_group_foreach (char *group_name, NewsrcGroup *group, struct newsrc_ptr_array *npa) -{ - if (group->subscribed || !npa->subscribed_only) { - g_ptr_array_add (npa->ptr_array, group_name); - } -} - -GPtrArray * -camel_nntp_newsrc_get_subscribed_group_names (CamelNNTPNewsrc *newsrc) -{ - struct newsrc_ptr_array npa; - - npa.ptr_array = g_ptr_array_new(); - npa.subscribed_only = TRUE; - - g_hash_table_foreach (newsrc->subscribed_groups, - (GHFunc)get_group_foreach, &npa); - - return npa.ptr_array; -} - -GPtrArray * -camel_nntp_newsrc_get_all_group_names (CamelNNTPNewsrc *newsrc) -{ - struct newsrc_ptr_array npa; - - npa.ptr_array = g_ptr_array_new(); - npa.subscribed_only = FALSE; - - g_hash_table_foreach (newsrc->groups, - (GHFunc)get_group_foreach, &npa); - - return npa.ptr_array; -} - -void -camel_nntp_newsrc_free_group_names (CamelNNTPNewsrc *newsrc, GPtrArray *group_names) -{ - g_ptr_array_free (group_names, TRUE); -} - -struct newsrc_fp { - CamelNNTPNewsrc *newsrc; - FILE *fp; -}; - -static void -camel_nntp_newsrc_write_group_line(gpointer key, NewsrcGroup *group, struct newsrc_fp *newsrc_fp) -{ - CamelNNTPNewsrc *newsrc; - FILE *fp; - int i; - int line_length = 0; - - fp = newsrc_fp->fp; - newsrc = newsrc_fp->newsrc; - - fprintf (fp, "%s%c", group->name, group->subscribed ? ':' : '!'); - - line_length += strlen(group->name) + 1; - - if (group->ranges->len == 1 - && g_array_index (group->ranges, ArticleRange, 0).low == 0 - && g_array_index (group->ranges, ArticleRange, 0).high == 0) { - fprintf (fp, "\n"); - - return; /* special case since our parsing code will insert this - bogus range if there were no read articles. The code - to add a range is smart enough to remove this one if we - ever mark an article read, but we still need to deal with - it if that code doesn't get hit. */ - } - - fprintf (fp, " "); - line_length += 1; - - for (i = 0; i < group->ranges->len; i ++) { - char range_buffer[100]; - guint low = g_array_index (group->ranges, ArticleRange, i).low; - guint high = g_array_index (group->ranges, ArticleRange, i).high; - - if (low == high) - sprintf(range_buffer, "%d", low); - else if (low == high - 1) - sprintf(range_buffer, "%d,%d", low, high); - else - sprintf(range_buffer, "%d-%d", low, high); - - if (i != group->ranges->len - 1) - strcat(range_buffer, ","); - - /* this constant (991) gives the same line breaking as faried's .newsrc file */ - if (line_length + strlen(range_buffer) > 991 /*XXX*/) { - char range_buffer2[101]; - int num_to_print = 991 - line_length; - - strcpy(range_buffer2, range_buffer); - range_buffer2[num_to_print] = '!'; - range_buffer2[num_to_print+1] = '\n'; - range_buffer2[num_to_print+2] = '\0'; - - fprintf (fp, range_buffer2); - - fprintf (fp, range_buffer + num_to_print); - - line_length = strlen(range_buffer) - num_to_print; - } - else { - fprintf (fp, range_buffer); - line_length += strlen(range_buffer); - } - } - - fprintf (fp, "\n"); -} - -void -camel_nntp_newsrc_write_to_file(CamelNNTPNewsrc *newsrc, FILE *fp) -{ - struct newsrc_fp newsrc_fp; - - newsrc_fp.newsrc = newsrc; - newsrc_fp.fp = fp; - - g_hash_table_foreach (newsrc->groups, - (GHFunc)camel_nntp_newsrc_write_group_line, - &newsrc_fp); -} - -void -camel_nntp_newsrc_write(CamelNNTPNewsrc *newsrc) -{ - FILE *fp; - - if (!newsrc->dirty) - return; - - if ((fp = fopen(newsrc->filename, "w")) == NULL) { - g_warning ("Couldn't open newsrc file '%s'.\n", newsrc->filename); - return; - } - - camel_nntp_newsrc_write_to_file(newsrc, fp); - - fclose(fp); -} - -static void -camel_nntp_newsrc_parse_line(CamelNNTPNewsrc *newsrc, char *line) -{ - char *p, sep, *comma, *dash; - gboolean is_subscribed; - NewsrcGroup *group; - - p = strchr(line, ':'); - - if (p) { - is_subscribed = TRUE; - } - else { - p = strchr(line, '!'); - if (p) - is_subscribed = FALSE; - else - return; /* bogus line. */ - } - - sep = *p; - *p = '\0'; - - group = camel_nntp_newsrc_group_add (newsrc, line, is_subscribed); - - *p = sep; - - p++; - - do { - guint high, low; - - comma = strchr(p, ','); - - if (comma) - *comma = '\0'; - - dash = strchr(p, '-'); - - if (!dash) { /* there wasn't a dash. must be just one number */ - high = low = atol(p); - } - else { /* there was a dash. */ - *dash = '\0'; - low = atol(p); - *dash = '-'; - p = dash + 1; - high = atol(p); - } - - camel_nntp_newsrc_group_mark_range_read (newsrc, group, low, high); - - if (comma) { - *comma = ','; - p = comma + 1; - } - - } while(comma); -} - -#define MAX_LINE_LENGTH 1500 -#define BUFFER_LENGTH (20 * MAX_LINE_LENGTH) - -CamelNNTPNewsrc * -camel_nntp_newsrc_read_for_server (const char *server) -{ - FILE *fp; - char buf[BUFFER_LENGTH]; - CamelNNTPNewsrc *newsrc = g_new0(CamelNNTPNewsrc, 1); - - newsrc->filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server); - newsrc->groups = g_hash_table_new (g_str_hash, g_str_equal); - newsrc->subscribed_groups = g_hash_table_new (g_str_hash, g_str_equal); - - if ((fp = fopen(newsrc->filename, "r")) == NULL) { - g_free (newsrc->filename); - g_free (newsrc); - return NULL; - } - - while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) { - /* we silently ignore (and lose!) lines longer than 20 * 1500 chars. - Too bad for them. */ - while(strlen(buf) < sizeof(buf) - && buf[strlen(buf) - 2] == '!') { - fgets(&buf[strlen(buf) - 2], MAX_LINE_LENGTH, fp); - } - - camel_nntp_newsrc_parse_line(newsrc, buf); - } - - fclose(fp); - - return newsrc; -} diff --git a/camel/providers/nntp/camel-nntp-newsrc.h b/camel/providers/nntp/camel-nntp-newsrc.h deleted file mode 100644 index 3f4be6de8d..0000000000 --- a/camel/providers/nntp/camel-nntp-newsrc.h +++ /dev/null @@ -1,27 +0,0 @@ - -#ifndef _CAMEL_NNTP_NEWSRC_H_ -#define _CAMEL_NNTP_NEWSRC_H_ - -#include <stdio.h> -#include "glib.h" - -typedef struct CamelNNTPNewsrc CamelNNTPNewsrc; - -int camel_nntp_newsrc_get_highest_article_read (CamelNNTPNewsrc *newsrc, char *group_name); -void camel_nntp_newsrc_mark_article_read (CamelNNTPNewsrc *newsrc, - char *group_name, int num); -void camel_nntp_newsrc_mark_range_read (CamelNNTPNewsrc *newsrc, - char *group_name, long low, long high); - -gboolean camel_nntp_newsrc_article_is_read (CamelNNTPNewsrc *newsrc, - char *group_name, long num); - -GPtrArray *camel_nntp_newsrc_get_subscribed_group_names (CamelNNTPNewsrc *newsrc); -GPtrArray *camel_nntp_newsrc_get_all_group_names (CamelNNTPNewsrc *newsrc); -void camel_nntp_newsrc_free_group_names (CamelNNTPNewsrc *newsrc, GPtrArray *group_names); - -void camel_nntp_newsrc_write_to_file (CamelNNTPNewsrc *newsrc, FILE *fp); -void camel_nntp_newsrc_write (CamelNNTPNewsrc *newsrc); -CamelNNTPNewsrc *camel_nntp_newsrc_read_for_server (const char *server); - -#endif /* _CAMEL_NNTP_NEWSRC_H_ */ diff --git a/camel/providers/nntp/camel-nntp-provider.c b/camel/providers/nntp/camel-nntp-provider.c deleted file mode 100644 index 4afc8c7c97..0000000000 --- a/camel/providers/nntp/camel-nntp-provider.c +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-provider.c: nntp provider registration code */ - -/* - * Authors : - * Chris Toshok <toshok@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 "config.h" -#include "camel-nntp-store.h" -#include "camel-provider.h" -#include "camel-session.h" - -static CamelProvider news_provider = { - "news", - "USENET news", - - "This is a read-only provider for USENET newsgroups.", - - "news", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 } -}; - -static CamelProvider nntp_provider = { - "nntp", - "USENET news via NNTP", - - "This is a provider for reading from and posting to" - "USENET newsgroups.", - - "news", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - news_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_nntp_store_get_type(); -#ifdef NOTYET - nntp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_nntp_transport_get_type(); -#endif - - camel_session_register_provider (session, &news_provider); - camel_session_register_provider (session, &nntp_provider); -} - - - diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c deleted file mode 100644 index 03ab14ccdb..0000000000 --- a/camel/providers/nntp/camel-nntp-store.c +++ /dev/null @@ -1,496 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-store.c : class for an nntp store */ - -/* - * - * Copyright (C) 2000 Helix Code, Inc. <toshok@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 <config.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <dirent.h> -#include <sys/stat.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "libgnome/libgnome.h" - -#include "camel-folder-summary.h" -#include "camel-nntp-store.h" -#include "camel-nntp-folder.h" -#include "camel-stream-buffer.h" -#include "camel-stream-fs.h" -#include "camel-exception.h" -#include "camel-url.h" -#include "string-utils.h" - -#define NNTP_PORT 119 - -static CamelServiceClass *service_class = NULL; - -/* Returns the class for a CamelNNTPStore */ -#define CNNTPS_CLASS(so) CAMEL_NNTP_STORE_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CNNTPF_CLASS(so) CAMEL_NNTP_FOLDER_CLASS (GTK_OBJECT(so)->klass) - -static gboolean nntp_connect (CamelService *service, CamelException *ex); -static gboolean nntp_disconnect (CamelService *service, CamelException *ex); - -static CamelFolder * -nntp_store_get_folder (CamelStore *store, const gchar *folder_name, - gboolean get_folder, CamelException *ex) -{ - CamelNNTPFolder *new_nntp_folder; - CamelFolder *new_folder; - CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store); - - /* if we haven't already read our .newsrc, read it now */ - if (!nntp_store->newsrc) - nntp_store->newsrc = camel_nntp_newsrc_read_for_server (CAMEL_SERVICE(store)->url->host); - - /* check if folder has already been created */ - /* call the standard routine for that when */ - /* it is done ... */ - - new_nntp_folder = gtk_type_new (CAMEL_NNTP_FOLDER_TYPE); - new_folder = CAMEL_FOLDER (new_nntp_folder); - - /* XXX We shouldn't be passing NULL here, but it's equivalent to - * what was there before, and there's no - * CamelNNTPFolder::get_subfolder yet anyway... - */ - CF_CLASS (new_folder)->init (new_folder, store, NULL, - folder_name, ".", FALSE, ex); - - return new_folder; -} - - -static char * -nntp_store_get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex) -{ - return g_strdup (folder_name); -} - -static char * -nntp_store_get_name (CamelService *service, gboolean brief) -{ - /* Same info for long and brief... */ - return g_strdup_sprintf ("USENET news via %s", service->url->host); -} - - -static void -camel_nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class) -{ - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_nntp_store_class); - CamelServiceClass *camel_store_class = CAMEL_SERVICE_CLASS (camel_nntp_store_class); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - camel_service_class->get_name = nntp_store_get_name; - - camel_store_class->get_folder = nntp_store_get_folder; - camel_store_class->get_folder_name = nntp_store_get_folder_name; -} - - - -static void -camel_nntp_store_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - - service->url_flags = CAMEL_SERVICE_URL_NEED_HOST; -} - -GtkType -camel_nntp_store_get_type (void) -{ - static GtkType camel_nntp_store_type = 0; - - if (!camel_nntp_store_type) { - GtkTypeInfo camel_nntp_store_info = - { - "CamelNNTPStore", - sizeof (CamelNNTPStore), - sizeof (CamelNNTPStoreClass), - (GtkClassInitFunc) camel_nntp_store_class_init, - (GtkObjectInitFunc) camel_nntp_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_nntp_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_nntp_store_info); - } - - return camel_nntp_store_type; -} - -/** - * camel_nntp_store_open: Connect to the server if we are currently - * disconnected. - * @store: the store - * @ex: a CamelException - * - **/ -void -camel_nntp_store_open (CamelNNTPStore *store, CamelException *ex) -{ - CamelService *service = CAMEL_SERVICE (store); - if (!camel_service_is_connected (service)) - nntp_connect (service, ex); -} - -/** - * camel_nntp_store_close: Close the connection to the server - * @store: the store - * @ex: a CamelException - * - **/ -void -camel_nntp_store_close (CamelNNTPStore *store, gboolean expunge, - CamelException *ex) -{ - camel_nntp_command (store, NULL, "QUIT"); - - nntp_disconnect (CAMEL_SERVICE (store), ex); -} - -static gboolean -nntp_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - int fd; - char *buf; - CamelNNTPStore *store = CAMEL_NNTP_STORE (service); - - if (!service_class->connect (service, ex)) - return FALSE; - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - sin.sin_family = h->h_addrtype; - sin.sin_port = htons (service->url->port ? service->url->port : NNTP_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || - connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to %s (port %s): %s", - service->url->host, service->url->port, - strerror(errno)); - if (fd > -1) - close (fd); - return FALSE; - } - - store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - if (!buf) { - return -1; - } - - g_free (buf); - - /* get a list of extensions that the server supports */ - if (CAMEL_NNTP_OK == camel_nntp_command (store, NULL, "LIST EXTENSIONS")) { - char *ext_response = camel_nntp_command_get_additional_data(store); - - g_free (ext_response); - } - - return TRUE; -} - -static gboolean -nntp_disconnect (CamelService *service, CamelException *ex) -{ - CamelNNTPStore *store = CAMEL_NNTP_STORE (service); - - if (!service->connected) - return TRUE; - - if (!service_class->disconnect (service, ex)) - return FALSE; - - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - store->ostream = NULL; - store->istream = NULL; - return TRUE; -} - -/** - * camel_nntp_command: Send a command to a NNTP server. - * @store: the NNTP store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected NNTP store specified by @store. It then - * reads the server's response and parses out the status code. If - * the caller passed a non-NULL pointer for @ret, camel_nntp_command - * will set it to point to an buffer containing the rest of the - * response from the NNTP server. (If @ret was passed but there was - * no extended response, @ret will be set to NULL.) The caller must - * free this buffer when it is done with it. - * - * Return value: one of CAMEL_NNTP_OK (command executed successfully), - * CAMEL_NNTP_ERR (command encounted an error), or CAMEL_NNTP_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ -int -camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...) -{ - char *cmdbuf, *respbuf; - va_list ap; - int status; - int resp_code; - CamelException *ex; - - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - ex = camel_exception_new(); - - /* make sure we're connected */ - if (store->ostream == NULL) - nntp_connect (CAMEL_SERVICE (store), ex); - - if (camel_exception_get_id (ex)) { - camel_exception_free (ex); - return CAMEL_NNTP_FAIL; - } - - /* Send the command */ - camel_stream_write (store->ostream, cmdbuf, strlen (cmdbuf)); - g_free (cmdbuf); - camel_stream_write (store->ostream, "\r\n", 2); - - /* Read the response */ - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - resp_code = atoi (respbuf); - - if (resp_code < 400) - status = CAMEL_NNTP_OK; - else if (resp_code < 500) - status = CAMEL_NNTP_ERR; - else - status = CAMEL_NNTP_FAIL; - - if (ret) { - *ret = strchr (respbuf, ' '); - if (*ret) - *ret = g_strdup (*ret + 1); - } - g_free (respbuf); - - return status; -} - -/** - * camel_nntp_command_get_additional_data: get "additional data" from - * a NNTP command. - * @store: the NNTP store - * - * This command gets the additional data returned by - * This command gets the additional data returned by "multi-line" POP - * commands, such as LIST, RETR, TOP, and UIDL. This command _must_ - * be called after a successful (CAMEL_NNTP_OK) call to - * camel_nntp_command for a command that has a multi-line response. - * The returned data is un-byte-stuffed, and has lines termined by - * newlines rather than CR/LF pairs. - * - * Return value: the data, which the caller must free. - **/ -char * -camel_nntp_command_get_additional_data (CamelNNTPStore *store) -{ - CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream); - GPtrArray *data; - char *buf; - int i, status = CAMEL_NNTP_OK; - - data = g_ptr_array_new (); - while (1) { - buf = camel_stream_buffer_read_line (stream); - if (!buf) { - status = CAMEL_NNTP_FAIL; - break; - } - - if (!strcmp (buf, ".")) - break; - if (*buf == '.') - memmove (buf, buf + 1, strlen (buf)); - g_ptr_array_add (data, buf); - } - - if (status == CAMEL_NNTP_OK) { - /* Append an empty string to the end of the array - * so when we g_strjoinv it, we get a "\n" after - * the last real line. - */ - g_ptr_array_add (data, ""); - g_ptr_array_add (data, NULL); - buf = g_strjoinv ("\n", (char **)data->pdata); - } else - buf = NULL; - - for (i = 0; i < data->len - 2; i++) - g_free (data->pdata[i]); - g_ptr_array_free (data, TRUE); - - return buf; -} - -void -camel_nntp_store_subscribe_group (CamelStore *store, - const gchar *group_name) -{ - gchar *root_dir = camel_nntp_store_get_toplevel_dir(CAMEL_NNTP_STORE(store)); - char *ret = NULL; - CamelException *ex = camel_exception_new(); - - if (camel_exception_get_id (ex)) { - g_free (root_dir); - camel_exception_free (ex); - return; - } - - if (CAMEL_NNTP_OK == camel_nntp_command ( CAMEL_NNTP_STORE (store), - &ret, "GROUP %s", group_name)) { - /* we create an empty summary file here, so that when - the group is opened we'll know we need to build it. */ - gchar *summary_file; - int fd; - summary_file = g_strdup_printf ("%s/%s-ev-summary", root_dir, group_name); - - fd = open (summary_file, O_CREAT | O_RDWR, 0666); - close (fd); - - g_free (summary_file); - } - if (ret) g_free (ret); - - g_free (root_dir); - camel_exception_free (ex); -} - -void -camel_nntp_store_unsubscribe_group (CamelStore *store, - const gchar *group_name) -{ - gchar *root_dir = camel_nntp_store_get_toplevel_dir(CAMEL_NNTP_STORE(store)); - gchar *summary_file; - - summary_file = g_strdup_printf ("%s/%s-ev-summary", root_dir, group_name); - if (g_file_exists (summary_file)) - unlink (summary_file); - g_free (summary_file); - - g_free (root_dir); -} - -GList * -camel_nntp_store_list_subscribed_groups(CamelStore *store) -{ - GList *group_name_list = NULL; - struct stat stat_buf; - gint stat_error = 0; - gchar *entry_name; - gchar *full_entry_name; - gchar *real_group_name; - struct dirent *dir_entry; - DIR *dir_handle; - gchar *root_dir = camel_nntp_store_get_toplevel_dir(CAMEL_NNTP_STORE(store)); - - dir_handle = opendir (root_dir); - g_return_val_if_fail (dir_handle, NULL); - - /* read the first entry in the directory */ - dir_entry = readdir (dir_handle); - while ((stat_error != -1) && (dir_entry != NULL)) { - - /* get the name of the next entry in the dir */ - entry_name = dir_entry->d_name; - full_entry_name = g_strdup_printf ("%s/%s", root_dir, entry_name); - stat_error = stat (full_entry_name, &stat_buf); - g_free (full_entry_name); - - /* is it a normal file ending in -ev-summary ? */ - if ((stat_error != -1) && S_ISREG (stat_buf.st_mode)) { - gboolean summary_suffix_found; - - real_group_name = string_prefix (entry_name, "-ev-summary", - &summary_suffix_found); - - if (summary_suffix_found) - /* add the folder name to the list */ - group_name_list = g_list_append (group_name_list, - real_group_name); - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return group_name_list; -} - -gchar * -camel_nntp_store_get_toplevel_dir (CamelNNTPStore *store) -{ - CamelURL *url = CAMEL_SERVICE (store)->url; - char *news_dir; - char *top_dir; - - g_assert(url != NULL); - - news_dir = gnome_util_prepend_user_home ("evolution/news"); - - top_dir = g_strdup_printf( "%s/%s", - news_dir, - url->host ); - - g_free (news_dir); - - return top_dir; -} diff --git a/camel/providers/nntp/camel-nntp-store.h b/camel/providers/nntp/camel-nntp-store.h deleted file mode 100644 index 9d4d6edebc..0000000000 --- a/camel/providers/nntp/camel-nntp-store.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-store.h : class for an nntp store */ - -/* - * - * Copyright (C) 2000 Helix Code, Inc. <toshok@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_NNTP_STORE_H -#define CAMEL_NNTP_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-store.h" -#include "camel-nntp-newsrc.h" - -#define CAMEL_NNTP_STORE_TYPE (camel_nntp_store_get_type ()) -#define CAMEL_NNTP_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_NNTP_STORE_TYPE, CamelNNTPStore)) -#define CAMEL_NNTP_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_NNTP_STORE_TYPE, CamelNNTPStoreClass)) -#define IS_CAMEL_NNTP_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_NNTP_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - -#define CAMEL_NNTP_EXT_XOVER 0x01 - guint32 extensions; - - CamelNNTPNewsrc *newsrc; - - CamelStream *istream, *ostream; -} CamelNNTPStore; - - - -typedef struct { - CamelStoreClass parent_class; - -} CamelNNTPStoreClass; - - -/* public methods */ -void camel_nntp_store_open (CamelNNTPStore *store, CamelException *ex); -void camel_nntp_store_close (CamelNNTPStore *store, gboolean expunge, - CamelException *ex); - -void camel_nntp_store_subscribe_group (CamelStore *store, const gchar *group_name); -void camel_nntp_store_unsubscribe_group (CamelStore *store, const gchar *group_name); -GList *camel_nntp_store_list_subscribed_groups(CamelStore *store); - -gchar *camel_nntp_store_get_toplevel_dir (CamelNNTPStore *store); - -/* support functions */ -enum { CAMEL_NNTP_OK, CAMEL_NNTP_ERR, CAMEL_NNTP_FAIL }; -int camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...); -char *camel_nntp_command_get_additional_data (CamelNNTPStore *store); - -/* Standard Gtk function */ -GtkType camel_nntp_store_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_NNTP_STORE_H */ - - diff --git a/camel/providers/nntp/camel-nntp-utils.c b/camel/providers/nntp/camel-nntp-utils.c deleted file mode 100644 index ae1f676cc3..0000000000 --- a/camel/providers/nntp/camel-nntp-utils.c +++ /dev/null @@ -1,210 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-utils.c : utilities used by the nntp code. */ - -/* - * Author : Chris Toshok <toshok@helixcode.com> - * - * Copyright (C) 2000 Helix Code . - * - * 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-folder-summary.h" -#include "camel-nntp-folder.h" -#include "camel-nntp-store.h" -#include "camel-nntp-utils.h" -#include "camel-stream-buffer.h" -#include "camel-stream-mem.h" - -#include <stdlib.h> -#include <string.h> - -static void -get_XOVER_headers(CamelNNTPStore *nntp_store, CamelFolder *folder, - int first_message, int last_message, CamelException *ex) -{ - int status; - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - - status = camel_nntp_command (nntp_store, NULL, - "XOVER %d-%d", - first_message, - last_message); - - if (status == CAMEL_NNTP_OK) { - CamelStream *nntp_istream = nntp_store->istream; - gboolean done = FALSE; - - while (!done) { - char *line; - - line = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER ( nntp_istream )); - - if (*line == '.') { - done = TRUE; - } - else { - CamelMessageInfo *new_info = g_new0(CamelMessageInfo, 1); - char **split_line = g_strsplit (line, "\t", 7); - - new_info->subject = g_strdup(split_line[1]); - new_info->from = g_strdup(split_line[2]); - new_info->to = g_strdup(nntp_folder->group_name); - new_info->date_sent = header_decode_date(split_line[3], NULL); -#if 0 - /* XXX do we need to fill in both dates? */ - new_info->headers.date_received = g_strdup(split_line[3]); -#endif - new_info->size = atoi(split_line[5]); - new_info->uid = g_strdup(split_line[4]); - g_strfreev (split_line); - - camel_folder_summary_add (nntp_folder->summary, new_info); - } - g_free (line); - } - } -} - -#if 0 -static GArray* -get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder, - int first_message, int last_message, CamelException *ex) -{ - int i; - int status; - - for (i = first_message; i < last_message; i ++) { - status = camel_nntp_command (nntp_store, NULL, - "HEAD %d", i); - - if (status == CAMEL_NNTP_OK) { - gboolean done = FALSE; - char *buf; - int buf_len; - int buf_alloc; - int h; - CamelStream *header_stream; - GArray *header_array; - CamelStream *nntp_istream; - CamelMessageInfo *new_info = g_new0(CamelMessageInfo, 1); - - buf_alloc = 2048; - buf_len = 0; - buf = malloc(buf_alloc); - done = FALSE; - - buf[0] = 0; - - nntp_istream = nntp_store->istream; - - while (!done) { - char *line; - int line_length; - - line = camel_stream_buffer_read_line ( - CAMEL_STREAM_BUFFER ( nntp_istream )); - line_length = strlen ( line ); - - if (*line == '.') { - done = TRUE; - } - else { - if (buf_len + line_length > buf_alloc) { - buf_alloc *= 2; - buf = realloc (buf, buf_alloc); - } - strcat(buf, line); - strcat(buf, "\n"); - buf_len += strlen(line); - g_free (line); - } - } - - /* create a stream from which to parse the headers */ - header_stream = camel_stream_mem_new_with_buffer(buf, - buf_len, - CAMEL_STREAM_MEM_READ); - - header_array = get_header_array_from_stream (header_stream); - - memset (&info, 0, sizeof(info)); - - for (h = 0; h < header_array->len; h ++) { - Rfc822Header *header = &((Rfc822Header*)header_array->data)[h]; - if (!g_strcasecmp(header->name, "From")) - new_info->from = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "To")) - new_info->to = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "Subject")) - new_info->subject = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "Message-ID")) - new_info->uid = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "Date")) { - new_info->date_sent = header_decode_date (header->value); -#if 0 - new_info->date_sent = g_strdup(header->value); - new_info->date_received = g_strdup(header->value); -#endif - } - } - - camel_folder_summary_add (nntp_folder->summary, new_info); - } - else if (status == CAMEL_NNTP_FAIL) { - /* nasty things are afoot */ - g_warning ("failure doing HEAD\n"); - break; - } - } -} -#endif - -void -camel_nntp_get_headers (CamelStore *store, - CamelNNTPFolder *nntp_folder, - CamelException *ex) -{ - CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store); - CamelFolder *folder = CAMEL_FOLDER (nntp_folder); - char *ret; - int first_message, nb_message, last_message; - int status; - - status = camel_nntp_command (nntp_store, &ret, - "GROUP %s", CAMEL_NNTP_FOLDER (folder)->group_name); - - sscanf (ret, "%d %d %d", &nb_message, &first_message, &last_message); - g_free (ret); - - if (status != CAMEL_NNTP_OK) { - /* XXX throw invalid group exception */ - printf ("invalid group\n"); - return; - } - -#if 0 - if (nntp_store->extensions & CAMEL_NNTP_EXT_XOVER) { -#endif - get_XOVER_headers (nntp_store, folder, first_message, last_message, ex); -#if 0 - } - else { - get_HEAD_headers (nntp_store, folder, first_message, last_message, ex); - } -#endif -} - diff --git a/camel/providers/nntp/camel-nntp-utils.h b/camel/providers/nntp/camel-nntp-utils.h deleted file mode 100644 index f28697c744..0000000000 --- a/camel/providers/nntp/camel-nntp-utils.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-utils.h : Utilities for the NNTP provider */ - -/* - * - * Author : Chris Toshok <toshok@helixcode.com> - * - * Copyright (C) 1999 Helix Code . - * - * 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_NNTP_UTILS_H -#define CAMEL_NNTP_UTILS_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -void camel_nntp_get_headers (CamelStore *store, CamelNNTPFolder *nntp_folder, CamelException *ex); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_NNTP_UTILS_H */ diff --git a/camel/providers/nntp/libcamelnntp.urls b/camel/providers/nntp/libcamelnntp.urls deleted file mode 100644 index dee2e70f14..0000000000 --- a/camel/providers/nntp/libcamelnntp.urls +++ /dev/null @@ -1,2 +0,0 @@ -news -nntp diff --git a/camel/providers/nntp/test-newsrc.c b/camel/providers/nntp/test-newsrc.c deleted file mode 100644 index c4b985e565..0000000000 --- a/camel/providers/nntp/test-newsrc.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <glib.h> -#include "camel-nntp-newsrc.h" - -int -main(int argc, char *argv[]) -{ - CamelNNTPNewsrc *newsrc = camel_nntp_newsrc_read_for_server (argv[1]); - camel_nntp_newsrc_write_to_file (newsrc, stdout); -} diff --git a/camel/providers/pop3/.cvsignore b/camel/providers/pop3/.cvsignore deleted file mode 100644 index 7d926a5545..0000000000 --- a/camel/providers/pop3/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile -Makefile.in -.libs -.deps -*.lo -*.la diff --git a/camel/providers/pop3/Makefile.am b/camel/providers/pop3/Makefile.am deleted file mode 100644 index 1c15981411..0000000000 --- a/camel/providers/pop3/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelpop3includedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelpop3.la -provider_DATA = libcamelpop3.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) \ - -I$(top_srcdir)/camel \ - $(KRB4_CFLAGS) \ - -DG_LOG_DOMAIN=\"camel-pop3-provider\" - -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 = $(KRB4_LDFLAGS) -version-info 0:0:0 - -EXTRA_DIST = libcamelpop3.urls diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c deleted file mode 100644 index fbfb8c6129..0000000000 --- a/camel/providers/pop3/camel-pop3-folder.c +++ /dev/null @@ -1,336 +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@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" -#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 <stdlib.h> -#include <string.h> - -#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (GTK_OBJECT (o)->klass)) -static CamelFolderClass *parent_class; - -static void pop3_finalize (GtkObject *object); - -static void pop3_sync (CamelFolder *folder, gboolean expunge, - CamelException *ex); - -static gint pop3_get_message_count (CamelFolder *folder, CamelException *ex); -static GPtrArray *pop3_get_uids (CamelFolder *folder, CamelException *ex); -static void pop3_free_uids (CamelFolder *folder, GPtrArray *uids); -static CamelMimeMessage *pop3_get_message (CamelFolder *folder, - const char *uid, - CamelException *ex); -static void pop3_delete_message (CamelFolder *folder, const char *uid, - 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); - GtkObjectClass *object_class = - GTK_OBJECT_CLASS (camel_pop3_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method overload */ - 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 = pop3_free_uids; - - camel_folder_class->get_message = pop3_get_message; - camel_folder_class->delete_message = pop3_delete_message; - - object_class->finalize = pop3_finalize; -} - -static void -camel_pop3_folder_init (gpointer object, gpointer klass) -{ - CamelPop3Folder *pop3_folder = CAMEL_POP3_FOLDER (object); - CamelFolder *folder = CAMEL_FOLDER (object); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = FALSE; - folder->has_summary_capability = FALSE; - folder->has_search_capability = FALSE; - - pop3_folder->uids = NULL; -} - -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; -} - -void -pop3_finalize (GtkObject *object) -{ - CamelPop3Folder *pop3_folder = CAMEL_POP3_FOLDER (object); - - g_ptr_array_free (pop3_folder->uids, TRUE); -} - -CamelFolder * -camel_pop3_folder_new (CamelStore *parent, CamelException *ex) -{ - CamelFolder *folder = - CAMEL_FOLDER (gtk_object_new (camel_pop3_folder_get_type (), - NULL)); - - CF_CLASS (folder)->init (folder, parent, NULL, "inbox", "/", TRUE, ex); - return folder; -} - -static void -pop3_sync (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - if (expunge) - camel_pop3_store_expunge (CAMEL_POP3_STORE (folder->parent_store), ex); -} - -static GPtrArray * -parse_listing (int count, char *data) -{ - GPtrArray *ans; - char *p; - int index, len; - - ans = g_ptr_array_new (); - g_ptr_array_set_size (ans, count); - - p = data; - while (*p) { - index = strtoul (p, &p, 10); - len = strcspn (p, "\n"); - if (index <= count && *p == ' ') - ans->pdata[index - 1] = g_strndup (p + 1, len - 1); - p += len; - if (*p == '\n') - p++; - } - - for (index = 0; index < count; index++) { - if (ans->pdata[index] == NULL) { - g_ptr_array_free (ans, TRUE); - return NULL; - } - } - - return ans; -} - -static int -uid_to_number (CamelFolder *folder, const char *uid, CamelException *ex) -{ - CamelPop3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder); - int i; - - if (!pop3_get_uids (folder, ex)) - return -1; - - for (i = 0; i < pop3_folder->uids->len; i++) { - if (!strcmp (uid, pop3_folder->uids->pdata[i])) - return i + 1; - } - - return -1; -} - - -static CamelMimeMessage * -pop3_get_message (CamelFolder *folder, const char *uid, CamelException *ex) -{ - int status, num; - char *result, *body; - CamelStream *msgstream; - CamelMimeMessage *msg; - - num = uid_to_number (folder, uid, ex); - if (num == -1) - return NULL; - - status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - &result, "RETR %d", num); - 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 NULL; - } - g_free (result); - - body = camel_pop3_command_get_additional_data (CAMEL_POP3_STORE (folder->parent_store), ex); - if (!body) { - 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, - camel_exception_get_description (ex)); - return NULL; - } - - msgstream = camel_stream_mem_new_with_buffer (body, strlen (body)); - g_free (body); - - msg = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), CAMEL_STREAM (msgstream)); - - gtk_object_unref (GTK_OBJECT (msgstream)); - - return msg; -} - -static void -pop3_delete_message (CamelFolder *folder, const char *uid, - CamelException *ex) -{ - int status, num; - char *resp; - - num = uid_to_number (folder, uid, ex); - if (num == -1) - return; - - status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - &resp, "DELE %d", num); - if (status != CAMEL_POP3_OK) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "Unable to delete message %s%s%s", - uid, resp ? ": " : "", - resp ? resp : ""); - } - g_free (resp); -} - -static gint -pop3_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelPop3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder); - - if (!pop3_get_uids (folder, ex)) - return -1; - - return pop3_folder->uids->len; -} - -static GPtrArray * -pop3_get_uids (CamelFolder *folder, CamelException *ex) -{ - CamelPop3Store *pop3_store = CAMEL_POP3_STORE (folder->parent_store); - CamelPop3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder); - int count, status; - char *data; - - if (pop3_folder->uids) - return pop3_folder->uids; - - status = camel_pop3_command (pop3_store, &data, "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, - data ? data : "Unknown error"); - g_free (data); - return NULL; - } - - count = atoi (data); - g_free (data); - - if (pop3_store->supports_uidl != FALSE) { - status = camel_pop3_command (pop3_store, NULL, "UIDL"); - if (status != CAMEL_POP3_OK) - pop3_store->supports_uidl = FALSE; - } - - if (pop3_store->supports_uidl == FALSE) { - int i; - - pop3_folder->uids = g_ptr_array_new (); - g_ptr_array_set_size (pop3_folder->uids, count); - - for (i = 0; i < count; i++) { - pop3_folder->uids->pdata[i] = - g_strdup_printf ("%d", i + 1); - } - - return pop3_folder->uids; - } - - data = camel_pop3_command_get_additional_data (pop3_store, ex); - if (camel_exception_is_set (ex)) - return NULL; - - pop3_folder->uids = parse_listing (count, data); - g_free (data); - - if (!pop3_folder->uids) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "UID listing from server was " - "incomplete."); - } - - return pop3_folder->uids; -} - -static void -pop3_free_uids (CamelFolder *folder, GPtrArray *uids) -{ - ; -} - diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h deleted file mode 100644 index 874c7a3a04..0000000000 --- a/camel/providers/pop3/camel-pop3-folder.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-pop3-folder.h : Class for a POP3 folder */ - -/* - * Author: - * 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 - */ - - -#ifndef CAMEL_POP3_FOLDER_H -#define CAMEL_POP3_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-folder.h" - -#define CAMEL_POP3_FOLDER_TYPE (camel_pop3_folder_get_type ()) -#define CAMEL_POP3_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_POP3_FOLDER_TYPE, CamelPop3Folder)) -#define CAMEL_POP3_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_POP3_FOLDER_TYPE, CamelPop3FolderClass)) -#define IS_CAMEL_POP3_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_POP3_FOLDER_TYPE)) - - -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 Gtk function */ -GtkType 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 4ccb06058f..0000000000 --- a/camel/providers/pop3/camel-pop3-provider.c +++ /dev/null @@ -1,58 +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@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 "config.h" -#include "camel-pop3-store.h" -#include "camel-provider.h" -#include "camel-session.h" -#include "camel-url.h" - -static CamelProvider pop3_provider = { - "pop", - "POP", - - "For connecting to POP servers. The POP protocol can also be used " - "to retrieve mail from certain web mail providers and proprietary " - "email systems.", - - "mail", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 }, - - NULL -}; - -void -camel_provider_module_init (CamelSession *session) -{ - 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); - - 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 e1f2f5f59b..0000000000 --- a/camel/providers/pop3/camel-pop3-store.c +++ /dev/null @@ -1,742 +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@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 "config.h" - -#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-pop3-store.h" -#include "camel-pop3-folder.h" -#include "camel-stream-buffer.h" -#include "camel-stream-fs.h" -#include "camel-session.h" -#include "camel-exception.h" -#include "camel-url.h" -#include "md5-utils.h" - -/* Specified in RFC 1939 */ -#define POP3_PORT 110 - -#ifdef HAVE_KRB4 -/* Specified nowhere */ -#define KPOP_PORT 1109 - -#include <krb.h> -#endif - -static CamelServiceClass *service_class = NULL; - -static void finalize (GtkObject *object); - -static gboolean pop3_connect (CamelService *service, CamelException *ex); -static gboolean pop3_disconnect (CamelService *service, CamelException *ex); -static GList *query_auth_types (CamelService *service, CamelException *ex); -static void free_auth_types (CamelService *service, GList *authtypes); -static char *get_name (CamelService *service, gboolean brief); - -static CamelFolder *get_folder (CamelStore *store, const char *folder_name, - gboolean create, 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 int pop3_get_response (CamelPop3Store *store, char **ret); - - -static void -camel_pop3_store_class_init (CamelPop3StoreClass *camel_pop3_store_class) -{ - GtkObjectClass *object_class = - GTK_OBJECT_CLASS (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); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - object_class->finalize = finalize; - - camel_service_class->connect = pop3_connect; - camel_service_class->disconnect = pop3_disconnect; - camel_service_class->query_auth_types = query_auth_types; - camel_service_class->free_auth_types = free_auth_types; - camel_service_class->get_name = get_name; - - 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; -} - - - -static void -camel_pop3_store_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - - service->url_flags = (CAMEL_SERVICE_URL_NEED_USER | CAMEL_SERVICE_URL_NEED_HOST); -} - -GtkType -camel_pop3_store_get_type (void) -{ - static GtkType camel_pop3_store_type = 0; - - if (!camel_pop3_store_type) { - GtkTypeInfo camel_pop3_store_info = - { - "CamelPop3Store", - sizeof (CamelPop3Store), - sizeof (CamelPop3StoreClass), - (GtkClassInitFunc) camel_pop3_store_class_init, - (GtkObjectInitFunc) camel_pop3_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_pop3_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_pop3_store_info); - } - - return camel_pop3_store_type; -} - -static void -finalize (GtkObject *object) -{ - CamelPop3Store *pop3_store = CAMEL_POP3_STORE (object); - CamelException ex; - - camel_exception_init (&ex); - pop3_disconnect (CAMEL_SERVICE (object), &ex); - camel_exception_clear (&ex); - - if (pop3_store->apop_timestamp) - g_free (pop3_store->apop_timestamp); -} - -static CamelServiceAuthType password_authtype = { - "Password", - - "This option will connect to the POP server using a plaintext " - "password. This is the only option supported by many POP servers.", - - "", - TRUE -}; - -static CamelServiceAuthType apop_authtype = { - "APOP", - - "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 -}; - -#ifdef HAVE_KRB4 -static CamelServiceAuthType kpop_authtype = { - "Kerberos 4 (KPOP)", - - "This will connect to the POP server and use Kerberos 4 " - "to authenticate to it.", - - "+KPOP", - FALSE -}; -#endif - -static gboolean -connect_to_server (CamelService *service, gboolean real, CamelException *ex) -{ - CamelPop3Store *store = CAMEL_POP3_STORE (service); - struct hostent *h; - struct sockaddr_in sin; - int fd, status; - char *buf, *apoptime, *apopend; -#ifdef HAVE_KRB4 - gboolean kpop = (service->url->port == KPOP_PORT); -#endif - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - sin.sin_family = h->h_addrtype; - if (service->url->port) - sin.sin_port = htons (service->url->port); - else - sin.sin_port = htons (POP3_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || - connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - if (real) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to %s: %s", - h->h_name, g_strerror(errno)); - } - if (fd > -1) - close (fd); - return FALSE; - } - -#ifdef HAVE_KRB4 - if (kpop) { - KTEXT_ST ticket_st; - MSG_DAT msg_data; - CREDENTIALS cred; - Key_schedule schedule; - char *hostname; - - /* Need to copy hostname, because krb_realmofhost will - * call gethostbyname as well, and gethostbyname uses - * static storage. - */ - hostname = g_strdup (h->h_name); - status = krb_sendauth (0, fd, &ticket_st, "pop", hostname, - krb_realmofhost (hostname), 0, - &msg_data, &cred, schedule, - NULL, NULL, "KPOPV0.1"); - g_free (hostname); - if (status != KSUCCESS) { - if (real) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not authenticate " - "to KPOP server: %s", - krb_err_txt[status]); - } - close (fd); - return FALSE; - } - - if (!service->url->passwd) - service->url->passwd = g_strdup (service->url->user); - } -#endif /* HAVE_KRB4 */ - - store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting, check status */ - status = pop3_get_response (store, &buf); - if (status != CAMEL_POP3_OK) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "%s: %s", status == CAMEL_POP3_ERR ? - "Error connecting to POP server" : - "Error reading greeting from POP server", - buf); - g_free (buf); - pop3_disconnect (service, ex); - return FALSE; - } - - apoptime = strchr (buf, '<'); - apopend = apoptime ? strchr (apoptime, '>') : NULL; - if (apopend) { - store->apop_timestamp = g_strndup (apoptime, - apopend - apoptime + 1); - memmove (apoptime, apopend + 1, strlen (apopend + 1)); - } - store->implementation = buf; - - /* Check extensions */ - store->login_delay = -1; - store->supports_top = -1; - store->supports_uidl = -1; - store->expires = -1; - - status = camel_pop3_command (store, NULL, "CAPA"); - if (status == CAMEL_POP3_OK) { - char *p; - int len; - - buf = camel_pop3_command_get_additional_data (store, ex); - if (camel_exception_is_set (ex)) { - pop3_disconnect (service, ex); - return FALSE; - } - - p = buf; - while (*p) { - len = strcspn (p, "\n"); - if (!strncmp (p, "IMPLEMENTATION ", 15)) { - g_free (store->implementation); - store->implementation = - g_strndup (p + 15, len - 15); - } else if (len == 3 && !strncmp (p, "TOP", 3)) - store->supports_top = TRUE; - else if (len == 4 && !strncmp (p, "UIDL", 4)) - store->supports_uidl = TRUE; - else if (!strncmp (p, "LOGIN-DELAY ", 12)) - store->login_delay = atoi (p + 12); - else if (!strncmp (p, "EXPIRE NEVER", 12)) - store->expires = FALSE; - else if (!strncmp (p, "EXPIRE ", 7)) - store->expires = TRUE; - - p += len; - if (*p) - p++; - } - - g_free (buf); - } - - return TRUE; -} - -static GList * -query_auth_types (CamelService *service, CamelException *ex) -{ - CamelPop3Store *store = CAMEL_POP3_STORE (service); - GList *ret = NULL; - gboolean passwd = TRUE, apop = TRUE; -#ifdef HAVE_KRB4 - gboolean kpop = TRUE; - int saved_port; -#endif - - if (service->url && !service->url->empty) { - passwd = connect_to_server (service, FALSE, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return NULL; - apop = store->apop_timestamp != NULL; - if (passwd) - pop3_disconnect (service, ex); -#ifdef HAVE_KRB4 - saved_port = service->url->port; - service->url->port = KPOP_PORT; - kpop = connect_to_server (service, FALSE, ex); - service->url->port = saved_port; - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return NULL; - if (kpop) - pop3_disconnect (service, ex); -#endif - } - - if (passwd) - ret = g_list_append (ret, &password_authtype); - if (apop) - ret = g_list_append (ret, &apop_authtype); -#ifdef HAVE_KRB4 - if (kpop) - ret = g_list_append (ret, &kpop_authtype); -#endif - - if (!ret) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to POP server on " - "%s.", service->url->host); - } - - return ret; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -static char * -get_name (CamelService *service, gboolean brief) -{ - if (brief) - return g_strdup_printf ("POP server %s", service->url->host); - else { - return g_strdup_printf ("POP service for %s on %s", - service->url->user, - service->url->host); - } -} - - -/** - * 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) -{ - camel_pop3_command (store, NULL, "QUIT"); - pop3_disconnect (CAMEL_SERVICE (store), ex); -} - -static gboolean -pop3_connect (CamelService *service, CamelException *ex) -{ - CamelPop3Store *store = CAMEL_POP3_STORE (service); - int status; - char *msg, *errbuf = NULL; - gboolean authenticated = FALSE; - gboolean auth_supported = TRUE; - gboolean kpop = FALSE; - -#ifdef HAVE_KRB4 - kpop = (service->url->authmech && - !strcmp (service->url->authmech, "+KPOP")); - - if (kpop && service->url->port == 0) - service->url->port = KPOP_PORT; -#endif - - if (!connect_to_server (service, TRUE, ex)) - return FALSE; - - while (auth_supported && !authenticated) { - if (errbuf) { - /* We need to un-cache the password before prompting again */ - camel_session_query_authenticator (camel_service_get_session (service), - CAMEL_AUTHENTICATOR_TELL, NULL, - TRUE, service, "password", ex); - g_free (service->url->passwd); - service->url->passwd = NULL; - } - - /* The KPOP code will have set the password to be the username - * in connect_to_server. Password and APOP are the only other - * cases, and they both need a password. - */ - if (!service->url->passwd) { - char *prompt; - - prompt = g_strdup_printf ("%sPlease enter the POP3 password for %s@%s", - errbuf ? errbuf : "", - service->url->user, - service->url->host); - g_free (errbuf); - errbuf = NULL; - service->url->passwd = camel_session_query_authenticator ( - camel_service_get_session (service), - CAMEL_AUTHENTICATOR_ASK, prompt, TRUE, - service, "password", ex); - - g_free (prompt); - if (!service->url->passwd) { - pop3_disconnect (service, ex); - return FALSE; - } - } - - if (!service->url->authmech || kpop) { - status = camel_pop3_command (store, &msg, "USER %s", service->url->user); - if (status != CAMEL_POP3_OK) { - if (kpop) - goto lose; - - errbuf = g_strdup_printf ("Unable to connect to POP server.\n" - "Error sending username: %s\n\n", - msg ? msg : "(Unknown)"); - - g_free (msg); - continue; - } - g_free (msg); - - status = camel_pop3_command (store, &msg, "PASS %s", service->url->passwd); - } else if (!strcmp (service->url->authmech, "+APOP") - && store->apop_timestamp) { - char *secret, md5asc[33], *d; - unsigned char md5sum[16], *s; - - secret = g_strdup_printf ("%s%s", store->apop_timestamp, service->url->passwd); - md5_get_digest (secret, strlen (secret), md5sum); - g_free (secret); - - for (s = md5sum, d = md5asc; d < md5asc + 32; s++, d += 2) - sprintf (d, "%.2x", *s); - - status = camel_pop3_command (store, &msg, "APOP %s %s", service->url->user, md5asc); - } else { - camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, - "No support for requested authentication mechanism."); - - auth_supported = FALSE; - goto lose; - } - - if (status != CAMEL_POP3_OK) { - errbuf = g_strdup_printf ("Unable to connect to POP server.\n" - "Error sending password: %s\n\n", - msg ? msg : "(Unknown)"); - - g_free (msg); - continue; - } - - g_free (msg); - authenticated = TRUE; - } - - g_free (errbuf); - - service_class->connect (service, ex); - return TRUE; - - lose: - /* Uncache the password. */ - camel_session_query_authenticator (camel_service_get_session (service), - CAMEL_AUTHENTICATOR_TELL, NULL, - TRUE, service, "password", ex); - - if (auth_supported && !authenticated) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, - "Unable to authenticate to POP server: %s", - msg ? msg : "(Unknown)"); - } - - g_free (errbuf); - - pop3_disconnect (service, ex); - return FALSE; -} - -static gboolean -pop3_disconnect (CamelService *service, CamelException *ex) -{ - CamelPop3Store *store = CAMEL_POP3_STORE (service); - - if (!service_class->disconnect (service, ex)) - return FALSE; - - if (store->ostream) { - gtk_object_unref (GTK_OBJECT (store->ostream)); - store->ostream = NULL; - } - if (store->istream) { - gtk_object_unref (GTK_OBJECT (store->istream)); - store->istream = NULL; - } - - if (store->apop_timestamp) { - g_free (store->apop_timestamp); - store->apop_timestamp = NULL; - } - - return TRUE; -} - -static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, - gboolean create, CamelException *ex) -{ - CamelService *service = CAMEL_SERVICE (store); - - if (!camel_service_is_connected (service)) { - if (!camel_service_connect (service, ex)) - return NULL; - } - return camel_pop3_folder_new (store, ex); -} - -static char * -get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex) -{ - if (!g_strcasecmp (folder_name, "inbox")) - return g_strdup ("inbox"); - else { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "No such folder `%s'.", folder_name); - return NULL; - } -} - -static char * -get_root_folder_name (CamelStore *store, CamelException *ex) -{ - return g_strdup ("inbox"); -} - - -/** - * camel_pop3_command: Send a command to a POP3 server. - * @store: the POP3 store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected POP3 store specified by @store. It then - * reads the server's response and parses out the status code. If - * the caller passed a non-NULL pointer for @ret, camel_pop3_command - * will set it to point to an buffer containing the rest of the - * response from the POP3 server. (If @ret was passed but there was - * no extended response, @ret will be set to NULL.) The caller must - * free this buffer when it is done with it. - * - * Return value: one of CAMEL_POP3_OK (command executed successfully), - * CAMEL_POP3_ERR (command encounted an error), or CAMEL_POP3_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ -int -camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...) -{ - char *cmdbuf; - va_list ap; - - if (!store->ostream) { - CamelException ex; - - camel_exception_init (&ex); - if (!camel_service_connect (CAMEL_SERVICE (store), &ex)) { - if (ret) - *ret = g_strdup (camel_exception_get_description (&ex)); - camel_exception_clear (&ex); - return CAMEL_POP3_FAIL; - } - } - - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - /* Send the command */ - if (camel_stream_printf (store->ostream, "%s\r\n", cmdbuf) == -1) { - g_free (cmdbuf); - if (*ret) - *ret = g_strdup(strerror(errno)); - return CAMEL_POP3_FAIL; - } - g_free (cmdbuf); - - return pop3_get_response (store, ret); -} - -static int -pop3_get_response (CamelPop3Store *store, char **ret) -{ - char *respbuf; - int status; - - respbuf = camel_stream_buffer_read_line ( - CAMEL_STREAM_BUFFER (store->istream)); - if (respbuf == NULL) { - if (ret) - *ret = g_strdup(strerror(errno)); - return CAMEL_POP3_FAIL; - } - if (!strncmp (respbuf, "+OK", 3)) - status = CAMEL_POP3_OK; - else if (!strncmp (respbuf, "-ERR", 4)) - 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); - - return status; -} - -/** - * camel_pop3_command_get_additional_data: get "additional data" from - * a POP3 command. - * @store: the POP3 store - * - * This command gets the additional data returned by "multi-line" POP - * commands, such as LIST, RETR, TOP, and UIDL. This command _must_ - * be called after a successful (CAMEL_POP3_OK) call to - * camel_pop3_command for a command that has a multi-line response. - * The returned data is un-byte-stuffed, and has lines termined by - * newlines rather than CR/LF pairs. - * - * Return value: the data, which the caller must free. - **/ -char * -camel_pop3_command_get_additional_data (CamelPop3Store *store, CamelException *ex) -{ - CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream); - GPtrArray *data; - char *buf, *p; - int i, len = 0, status = CAMEL_POP3_OK; - - data = g_ptr_array_new (); - while (1) { - buf = camel_stream_buffer_read_line (stream); - if (!buf) { - status = CAMEL_POP3_FAIL; - break; - } - - if (!strcmp (buf, ".")) - break; - - g_ptr_array_add (data, buf); - len += strlen (buf) + 1; - } - g_free (buf); - - if (status == CAMEL_POP3_OK) { - buf = g_malloc0 (len + 1); - - for (i = 0, p = buf; i < data->len; i++) { - char *ptr, *datap; - - datap = (char *) data->pdata[i]; - ptr = (*datap == '.') ? datap + 1 : datap; - len = strlen (ptr); - memcpy (p, ptr, len); - p += len; - *p++ = '\n'; - } - *p = '\0'; - } else - buf = NULL; - - for (i = 0; i < data->len; i++) - g_free (data->pdata[i]); - g_ptr_array_free (data, TRUE); - - return buf; -} diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h deleted file mode 100644 index 74174a32f2..0000000000 --- a/camel/providers/pop3/camel-pop3-store.h +++ /dev/null @@ -1,82 +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@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_POP3_STORE_H -#define CAMEL_POP3_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-types.h" -#include "camel-store.h" - -#define CAMEL_POP3_STORE_TYPE (camel_pop3_store_get_type ()) -#define CAMEL_POP3_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_POP3_STORE_TYPE, CamelPop3Store)) -#define CAMEL_POP3_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_POP3_STORE_TYPE, CamelPop3StoreClass)) -#define IS_CAMEL_POP3_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_POP3_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - - CamelStream *istream, *ostream; - char *apop_timestamp, *implementation; - gboolean supports_top, supports_uidl, expires; - int login_delay; - -} 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, char *fmt, ...); -char *camel_pop3_command_get_additional_data (CamelPop3Store *store, - CamelException *ex); - -/* Standard Gtk function */ -GtkType camel_pop3_store_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_POP3_STORE_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 diff --git a/camel/providers/sendmail/.cvsignore b/camel/providers/sendmail/.cvsignore deleted file mode 100644 index cacc3c5d5f..0000000000 --- a/camel/providers/sendmail/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -Makefile -Makefile.in -.deps -.libs -*.lo -*.la -*.o diff --git a/camel/providers/sendmail/Makefile.am b/camel/providers/sendmail/Makefile.am deleted file mode 100644 index 5df527435f..0000000000 --- a/camel/providers/sendmail/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsendmailincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsendmail.la -provider_DATA = libcamelsendmail.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-sendmail-provider\" - -libcamelsendmail_la_SOURCES = \ - camel-sendmail-provider.c \ - camel-sendmail-transport.c - -libcamelsendmailinclude_HEADERS = \ - camel-sendmail-transport.h - -libcamelsendmail_la_LDFLAGS = -version-info 0:0:0 - -EXTRA_DIST = libcamelsendmail.urls diff --git a/camel/providers/sendmail/camel-sendmail-provider.c b/camel/providers/sendmail/camel-sendmail-provider.c deleted file mode 100644 index 3b0b35dd72..0000000000 --- a/camel/providers/sendmail/camel-sendmail-provider.c +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-sendmail-provider.c: sendmail provider registration code */ - -/* - * 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 "config.h" -#include "camel-provider.h" -#include "camel-sendmail-transport.h" -#include "camel-session.h" -#include "camel-url.h" - -static CamelProvider sendmail_provider = { - "sendmail", - "Sendmail", - - "For delivering mail by passing it to the \"sendmail\" program " - "on the local system.", - - "mail", - - 0, - - { 0, 0 }, - - NULL -}; - -void -camel_provider_module_init (CamelSession *session) -{ - sendmail_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_sendmail_transport_get_type(); - - sendmail_provider.service_cache = g_hash_table_new (camel_url_hash, camel_url_equal); - - camel_session_register_provider (session, &sendmail_provider); -} - - - diff --git a/camel/providers/sendmail/camel-sendmail-transport.c b/camel/providers/sendmail/camel-sendmail-transport.c deleted file mode 100644 index 3facc42676..0000000000 --- a/camel/providers/sendmail/camel-sendmail-transport.c +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-sendmail-transport.c: Sendmail-based transport class. */ - -/* - * - * Author : - * Dan Winship <danw@helixcode.com> - * - * Copyright 2000 Helix Code, Inc. (http://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 <config.h> - -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/wait.h> -#include <unistd.h> -#include <string.h> - -#include "camel-sendmail-transport.h" -#include "camel-mime-message.h" -#include "camel-data-wrapper.h" -#include "camel-stream-fs.h" -#include "camel-exception.h" - -static char *get_name (CamelService *service, gboolean brief); - -static gboolean _can_send (CamelTransport *transport, CamelMedium *message); -static gboolean _send (CamelTransport *transport, CamelMedium *message, - CamelException *ex); -static gboolean _send_to (CamelTransport *transport, CamelMedium *message, - GList *recipients, CamelException *ex); - - -static void -camel_sendmail_transport_class_init (CamelSendmailTransportClass *camel_sendmail_transport_class) -{ - CamelTransportClass *camel_transport_class = - CAMEL_TRANSPORT_CLASS (camel_sendmail_transport_class); - CamelServiceClass *camel_service_class = - CAMEL_SERVICE_CLASS (camel_sendmail_transport_class); - - /* virtual method overload */ - camel_service_class->get_name = get_name; - - camel_transport_class->can_send = _can_send; - camel_transport_class->send = _send; - camel_transport_class->send_to = _send_to; -} - -GtkType -camel_sendmail_transport_get_type (void) -{ - static GtkType camel_sendmail_transport_type = 0; - - if (!camel_sendmail_transport_type) { - GtkTypeInfo camel_sendmail_transport_info = - { - "CamelSendmailTransport", - sizeof (CamelSendmailTransport), - sizeof (CamelSendmailTransportClass), - (GtkClassInitFunc) camel_sendmail_transport_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_sendmail_transport_type = gtk_type_unique (CAMEL_TRANSPORT_TYPE, &camel_sendmail_transport_info); - } - - return camel_sendmail_transport_type; -} - - -static gboolean -_can_send (CamelTransport *transport, CamelMedium *message) -{ - return CAMEL_IS_MIME_MESSAGE (message); -} - - -static gboolean -_send_internal (CamelMedium *message, char **argv, CamelException *ex) -{ - int fd[2], nullfd, wstat; - sigset_t mask, omask; - CamelStream *out; - pid_t pid; - - g_assert (CAMEL_IS_MIME_MESSAGE (message)); - - if (pipe (fd) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not create pipe to sendmail: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - - /* Block SIGCHLD so the calling application doesn't notice - * sendmail exiting before we do. - */ - sigemptyset (&mask); - sigaddset (&mask, SIGCHLD); - sigprocmask (SIG_BLOCK, &mask, &omask); - - pid = fork (); - switch (pid) { - case -1: - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not fork sendmail: " - "%s: mail not sent", g_strerror (errno)); - sigprocmask (SIG_SETMASK, &omask, NULL); - return FALSE; - - case 0: - /* Child process */ - nullfd = open ("/dev/null", O_RDWR); - dup2 (fd[0], STDIN_FILENO); - dup2 (nullfd, STDOUT_FILENO); - dup2 (nullfd, STDERR_FILENO); - close (nullfd); - close (fd[1]); - - execv (SENDMAIL_PATH, argv); - _exit (255); - } - - /* Parent process. Write the message out. */ - close (fd[0]); - out = camel_stream_fs_new_with_fd (fd[1]); - if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), out) == -1 - || camel_stream_close(out) == -1) { - gtk_object_unref (GTK_OBJECT (out)); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not send message: %s", - strerror(errno)); - return FALSE; - } - gtk_object_unref (GTK_OBJECT (out)); - - /* Wait for sendmail to exit. */ - while (waitpid (pid, &wstat, 0) == -1 && errno == EINTR) - ; - sigprocmask (SIG_SETMASK, &omask, NULL); - - if (!WIFEXITED (wstat)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "sendmail exited with signal %s: " - "mail not sent.", - g_strsignal (WTERMSIG (wstat))); - return FALSE; - } else if (WEXITSTATUS (wstat) != 0) { - if (WEXITSTATUS (wstat) == 255) { - camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, - "Could not execute " - SENDMAIL_PATH ": mail not sent."); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "sendmail exited with status " - "%d: mail not sent.", - WEXITSTATUS (wstat)); - } - return FALSE; - } - - return TRUE; -} - -static gboolean -_send_to (CamelTransport *transport, CamelMedium *message, - GList *recipients, CamelException *ex) -{ - GList *r; - char **argv; - int i, len; - gboolean status; - - len = g_list_length (recipients); - argv = g_malloc ((len + 4) * sizeof (char *)); - argv[0] = "sendmail"; - argv[1] = "-i"; - argv[2] = "--"; - - for (i = 1, r = recipients; i <= len; i++, r = r->next) - argv[i + 2] = r->data; - argv[i + 2] = NULL; - - status = _send_internal (message, argv, ex); - g_free (argv); - return status; -} - -static gboolean -_send (CamelTransport *transport, CamelMedium *message, - CamelException *ex) -{ - char *argv[4] = { "sendmail", "-t", "-i", NULL }; - - return _send_internal (message, argv, ex); -} - -static char * -get_name (CamelService *service, gboolean brief) -{ - if (brief) - return g_strdup ("sendmail"); - else - return g_strdup ("Mail delivery via the sendmail program"); -} diff --git a/camel/providers/sendmail/camel-sendmail-transport.h b/camel/providers/sendmail/camel-sendmail-transport.h deleted file mode 100644 index 3f3714584a..0000000000 --- a/camel/providers/sendmail/camel-sendmail-transport.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-sendmail-transport.h: Sendmail-based transport class */ - -/* - * - * Author : - * Dan Winship <danw@helixcode.com> - * - * Copyright 2000 Helix Code, Inc. (http://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_SENDMAIL_TRANSPORT_H -#define CAMEL_SENDMAIL_TRANSPORT_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include "camel-transport.h" - -#define CAMEL_SENDMAIL_TRANSPORT_TYPE (camel_sendmail_transport_get_type ()) -#define CAMEL_SENDMAIL_TRANSPORT(obj) (GTK_CHECK_CAST((obj), CAMEL_SENDMAIL_TRANSPORT_TYPE, CamelSendmailTransport)) -#define CAMEL_SENDMAIL_TRANSPORT_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_SENDMAIL_TRANSPORT_TYPE, CamelSendmailTransportClass)) -#define CAMEL_IS_SENDMAIL_TRANSPORT(o) (GTK_CHECK_TYPE((o), CAMEL_SENDMAIL_TRANSPORT_TYPE)) - - -typedef struct { - CamelTransport parent_object; - -} CamelSendmailTransport; - - -typedef struct { - CamelTransportClass parent_class; - -} CamelSendmailTransportClass; - - -/* Standard Gtk function */ -GtkType camel_sendmail_transport_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_SENDMAIL_TRANSPORT_H */ diff --git a/camel/providers/sendmail/libcamelsendmail.urls b/camel/providers/sendmail/libcamelsendmail.urls deleted file mode 100644 index ccad52828e..0000000000 --- a/camel/providers/sendmail/libcamelsendmail.urls +++ /dev/null @@ -1 +0,0 @@ -sendmail diff --git a/camel/providers/smtp/.cvsignore b/camel/providers/smtp/.cvsignore deleted file mode 100644 index 09980ae6ba..0000000000 --- a/camel/providers/smtp/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la diff --git a/camel/providers/smtp/Makefile.am b/camel/providers/smtp/Makefile.am deleted file mode 100644 index 32fa210131..0000000000 --- a/camel/providers/smtp/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsmtpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsmtp.la -provider_DATA = libcamelsmtp.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) \ - -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-smtp-provider\" - -libcamelsmtp_la_SOURCES = \ - camel-smtp-provider.c \ - camel-smtp-transport.c - -libcamelsmtpinclude_HEADERS = \ - camel-smtp-transport.h - - -libcamelsmtp_la_LDFLAGS = -version-info 0:0:0 - -EXTRA_DIST = libcamelsmtp.urls diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c deleted file mode 100644 index 1d18e445cc..0000000000 --- a/camel/providers/smtp/camel-smtp-provider.c +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-smtp-provider.c: smtp provider registration code */ - -/* - * Authors : - * Jeffrey Stedfast <fejj@stampede.org> - * - * 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 "config.h" -#include "camel-smtp-transport.h" -#include "camel-provider.h" -#include "camel-session.h" -#include "camel-url.h" - -static CamelProvider smtp_provider = { - "smtp", - "SMTP", - - "For delivering mail by connecting to a remote mailhub using SMTP.", - - "mail", - - 0, - - { 0, 0 }, - - NULL -}; - -void -camel_provider_module_init (CamelSession *session) -{ - smtp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_smtp_transport_get_type(); - - smtp_provider.service_cache = g_hash_table_new (camel_url_hash, camel_url_equal); - - camel_session_register_provider (session, &smtp_provider); -} - - - diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c deleted file mode 100644 index 6188015bc8..0000000000 --- a/camel/providers/smtp/camel-smtp-transport.c +++ /dev/null @@ -1,800 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-smtp-transport.c : class for a smtp transport */ - -/* - * Authors: - * 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 - */ - -#include "config.h" - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#undef MIN -#undef MAX -#include "camel-mime-filter-crlf.h" -#include "camel-stream-filter.h" -#include "camel-smtp-transport.h" -#include "camel-mime-message.h" -#include "camel-stream-buffer.h" -#include "camel-stream-fs.h" -#include "camel-session.h" -#include "camel-exception.h" -#include "md5-utils.h" - -/* Specified in RFC 821 */ -#define SMTP_PORT 25 - -/* camel smtp transport class prototypes */ -static gboolean _can_send (CamelTransport *transport, CamelMedium *message); -static gboolean _send (CamelTransport *transport, CamelMedium *message, CamelException *ex); -static gboolean _send_to (CamelTransport *transport, CamelMedium *message, GList *recipients, CamelException *ex); - -/* support prototypes */ -static gboolean smtp_connect (CamelService *service, CamelException *ex); -static gboolean smtp_disconnect (CamelService *service, CamelException *ex); -static GList *esmtp_get_authtypes(gchar *buffer); -static GList *query_auth_types (CamelService *service, CamelException *ex); -static void free_auth_types (CamelService *service, GList *authtypes); -static char *get_name (CamelService *service, gboolean brief); -static gchar *smtp_get_email_addr_from_text (gchar *text); -static gboolean smtp_helo (CamelSmtpTransport *transport, CamelException *ex); -static gboolean smtp_mail (CamelSmtpTransport *transport, gchar *sender, CamelException *ex); -static gboolean smtp_rcpt (CamelSmtpTransport *transport, gchar *recipient, CamelException *ex); -static gboolean smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException *ex); -static gboolean smtp_rset (CamelSmtpTransport *transport, CamelException *ex); -static gboolean smtp_quit (CamelSmtpTransport *transport, CamelException *ex); - -/* private data members */ -static CamelServiceClass *service_class = NULL; - -static void -camel_smtp_transport_class_init (CamelSmtpTransportClass *camel_smtp_transport_class) -{ - CamelTransportClass *camel_transport_class = - CAMEL_TRANSPORT_CLASS (camel_smtp_transport_class); - CamelServiceClass *camel_service_class = - CAMEL_SERVICE_CLASS (camel_smtp_transport_class); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - camel_service_class->connect = smtp_connect; - camel_service_class->disconnect = smtp_disconnect; - camel_service_class->query_auth_types = query_auth_types; - camel_service_class->free_auth_types = free_auth_types; - camel_service_class->get_name = get_name; - - camel_transport_class->can_send = _can_send; - camel_transport_class->send = _send; - camel_transport_class->send_to = _send_to; -} - -static void -camel_smtp_transport_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - - service->url_flags = CAMEL_SERVICE_URL_NEED_HOST; -} - -GtkType -camel_smtp_transport_get_type (void) -{ - static GtkType camel_smtp_transport_type = 0; - - if (!camel_smtp_transport_type) { - GtkTypeInfo camel_smtp_transport_info = - { - "CamelSmtpTransport", - sizeof (CamelSmtpTransport), - sizeof (CamelSmtpTransportClass), - (GtkClassInitFunc) camel_smtp_transport_class_init, - (GtkObjectInitFunc) camel_smtp_transport_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_smtp_transport_type = gtk_type_unique (CAMEL_TRANSPORT_TYPE, &camel_smtp_transport_info); - } - - return camel_smtp_transport_type; -} - -static gboolean -smtp_connect (CamelService *service, CamelException *ex) -{ - CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service); - struct hostent *h; - struct sockaddr_in sin; - gint fd, num, i; - guint32 addrlen; - gchar *pass = NULL, *respbuf = NULL; - - - if (!service_class->connect (service, ex)) - return FALSE; - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - /* set some smtp transport defaults */ - transport->smtp_is_esmtp = FALSE; - transport->esmtp_supported_authtypes = NULL; - - sin.sin_family = h->h_addrtype; - sin.sin_port = htons (service->url->port ? service->url->port : SMTP_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to %s (port %s): %s", - service->url->host, service->url->port, - strerror(errno)); - if (fd > -1) - close (fd); - g_free (pass); - return FALSE; - } - - /* get the localaddr - needed later by smtp_helo */ - addrlen = sizeof (transport->localaddr); - getsockname (fd, (struct sockaddr*)&transport->localaddr, &addrlen); - - transport->ostream = camel_stream_fs_new_with_fd (fd); - transport->istream = camel_stream_buffer_new (transport->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting, note whether the server is ESMTP and if it requests AUTH. */ - do { - /* Check for "220" */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - if ( !respbuf || strncmp (respbuf, "220", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Welcome response error: " - "%s: possibly non-fatal", - g_strerror (errno)); - return FALSE; - } - if (strstr (respbuf, "ESMTP")) - transport->smtp_is_esmtp = TRUE; - } while ( *(respbuf+3) == '-' ); /* if we got "220-" then loop again */ - g_free (respbuf); - - /* send HELO (or EHLO, depending on the service type) */ - if (!transport->smtp_is_esmtp) { - /* If we did not auto-detect ESMTP, we should still send EHLO */ - transport->smtp_is_esmtp = TRUE; - if (!smtp_helo (transport, ex)) { - /* Okay, apprently this server doesn't support ESMTP */ - transport->smtp_is_esmtp = FALSE; - smtp_helo (transport, ex); - } - } else { - smtp_helo (transport, ex); - } - - /* check to see if AUTH is required, if so...then AUTH ourselves */ - if (transport->smtp_is_esmtp && transport->esmtp_supported_authtypes) { - /* not really supported yet, but we can at least show what auth types are supported */ - fprintf (stderr, "camel-smtp-transport::connect(): %s requires AUTH\n", service->url->host); - num = g_list_length (transport->esmtp_supported_authtypes); - - for (i = 0; i < num; i++) - fprintf (stderr, "\nSupported AUTH: %s\n\n", - (gchar *) g_list_nth_data (transport->esmtp_supported_authtypes, i)); - - g_list_free (transport->esmtp_supported_authtypes); - transport->esmtp_supported_authtypes = NULL; - } else { - fprintf (stderr, "\ncamel-smtp-transport::connect(): provider does not use AUTH\n\n"); - } - - return TRUE; -} - -static gboolean -smtp_disconnect (CamelService *service, CamelException *ex) -{ - CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service); - - if (!service->connected) - return TRUE; - - /* send the QUIT command to the SMTP server */ - smtp_quit(transport, ex); - - if (!service_class->disconnect (service, ex)) - return FALSE; - - g_free (transport->esmtp_supported_authtypes); - transport->esmtp_supported_authtypes = NULL; - gtk_object_unref (GTK_OBJECT (transport->ostream)); - gtk_object_unref (GTK_OBJECT (transport->istream)); - transport->ostream = NULL; - transport->istream = NULL; - - return TRUE; -} - -static GList -*esmtp_get_authtypes (gchar *buffer) -{ - GList *ret = NULL; - gchar *start, *end; - - if (!(start = strstr (buffer, "AUTH"))) - return NULL; - - /* advance to the first token */ - for (start += 4; *start && *start != ' ' && *start != '='; start++); - - for ( ; *start; ) { - /* advance to the end of the token */ - for (end = start; *end && *end != ' '; end++); - - ret = g_list_append (ret, g_strndup (start, end - start)); - - /* advance to the next token */ - for (start = end; *start && *start != ' '; start++); - } - - return ret; -} - -static CamelServiceAuthType no_authtype = { - "No authentication required", - - "This option will connect to the SMTP server without using any " - "kind of authentication. This should be fine for connecting to " - "most SMTP servers." - - "", - FALSE -}; - -static CamelServiceAuthType cram_md5_authtype = { - "CRAM-MD5", - - "This option will connect to the SMTP server using CRAM-MD5 " - "authentication.", - - "CRAM-MD5", - TRUE -}; - -static GList -*query_auth_types (CamelService *service, CamelException *ex) -{ - /* FIXME: Re-enable this when auth types are actually - * implemented. - */ - - return NULL; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -static char * -get_name (CamelService *service, gboolean brief) -{ - if (brief) - return g_strdup_printf ("SMTP server %s", service->url->host); - else { - return g_strdup_printf ("SMTP mail delivery via %s", - service->url->host); - } -} - -static gboolean -_can_send (CamelTransport *transport, CamelMedium *message) -{ - return CAMEL_IS_MIME_MESSAGE (message); -} - -static gboolean -_send_to (CamelTransport *transport, CamelMedium *message, - GList *recipients, CamelException *ex) -{ - GList *r; - gchar *recipient, *s, *sender; - guint i, len; - CamelSmtpTransport *smtp_transport = CAMEL_SMTP_TRANSPORT (transport); - - s = g_strdup(camel_mime_message_get_from (CAMEL_MIME_MESSAGE (message))); - if (!s) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot send message: " - "sender address not defined."); - return FALSE; - } - - sender = smtp_get_email_addr_from_text (s); - smtp_mail (smtp_transport, sender, ex); - g_free (sender); - g_free (s); - - if (!(len = g_list_length(recipients))) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot send message: " - "no recipients defined."); - return FALSE; - } - - for (i = 0, r = recipients; i < len; i++, r = r->next) { - recipient = smtp_get_email_addr_from_text (r->data); - if (!smtp_rcpt (smtp_transport, recipient, ex)) { - g_free (recipient); - return FALSE; - } - g_free (recipient); - } - - if (!smtp_data (smtp_transport, message, ex)) - return FALSE; - - /* reset the service for our next transfer session */ - smtp_rset (smtp_transport, ex); - - return TRUE; -} - -static gboolean -_send (CamelTransport *transport, CamelMedium *message, - CamelException *ex) -{ - const CamelInternetAddress *to, *cc, *bcc; - GList *recipients = NULL; - guint index, len; - - to = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_TO); - cc = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_CC); - bcc = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_BCC); - - /* get all of the To addresses into our recipient list */ - len = CAMEL_ADDRESS (to)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get (to, index, NULL, &addr)) - recipients = g_list_append (recipients, g_strdup (addr)); - } - - /* get all of the Cc addresses into our recipient list */ - len = CAMEL_ADDRESS (cc)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get (cc, index, NULL, &addr)) - recipients = g_list_append (recipients, g_strdup (addr)); - } - - /* get all of the Bcc addresses into our recipient list */ - len = CAMEL_ADDRESS (bcc)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get (bcc, index, NULL, &addr)) - recipients = g_list_append (recipients, g_strdup (addr)); - } - - return _send_to (transport, message, recipients, ex); -} - -static gchar -*smtp_get_email_addr_from_text (gchar *text) -{ - /* get the actual email address from the string passed and place it in addr - * we can assume the address will be in one of the following forms: - * 1) The Name <person@host.com> - * 2) <person@host.com> - * 3) person@host.com - * 4) person@host.com (The Name) - */ - - gchar *tmp, *addr = NULL; - gchar *addr_strt; /* points to start of addr */ - gchar *addr_end; /* points to end of addr */ - gchar *ptr1; - - - /* check the incoming args */ - if (!text || !*text) - return NULL; - - /* scan the string for an open brace */ - for (addr_strt = text; *addr_strt; addr_strt++) - if (*addr_strt == '<') - break; - - if (*addr_strt) { - /* we found an open brace, let's look for it's counterpart */ - for (addr_end = addr_strt; *addr_end; addr_end++) - if (*addr_end == '>') - break; - - /* if we didn't find it, or braces are empty... */ - if (!(*addr_end) || (addr_strt == addr_end - 1)) - return NULL; - - /* addr_strt points to '<' and addr_end points to '>'. - * Now let's adjust 'em slightly to point to the beginning - * and ending of the email addy - */ - addr_strt++; - addr_end--; - } else { - /* no open brace...assume type 3 or 4? */ - addr_strt = text; - - /* find the end of the email addr/string */ - for (addr_end = addr_strt; *addr_end || *addr_end == ' '; addr_end++); - - addr_end--; /* points to NULL, move it back one char */ - } - - /* now addr_strt & addr_end point to the beginning & ending of the email addy */ - - /* copy the string into addr */ - addr = g_strndup (addr_strt, (gint)(addr_end - addr_strt + 1)); - - for (ptr1 = addr_strt; ptr1 <= addr_end; ptr1++) /* look for an '@' sign */ - if (*ptr1 == '@') - break; - - if (*ptr1 != '@') { - /* here we found out the name doesn't have an '@' part - * let's figure out what machine we're on & stick it on the end - */ - gchar hostname[MAXHOSTNAMELEN]; - - if (gethostname (hostname, MAXHOSTNAMELEN)) { - g_free (addr); - return NULL; - } - tmp = addr; - addr = g_strconcat (tmp, "@", hostname, NULL); - g_free (tmp); - } - - return addr; -} - -static gboolean -smtp_helo (CamelSmtpTransport *transport, CamelException *ex) -{ - /* say hello to the server */ - gchar *cmdbuf, *respbuf = NULL; - struct hostent *host; - - /* get the local host name */ - host = gethostbyaddr ((gchar *)&transport->localaddr.sin_addr, sizeof (transport->localaddr.sin_addr), AF_INET); - - /* hiya server! how are you today? */ - if (transport->smtp_is_esmtp) - cmdbuf = g_strdup_printf ("EHLO %s\r\n", host && host->h_name ? host->h_name : - inet_ntoa (transport->localaddr.sin_addr)); - else - cmdbuf = g_strdup_printf ("HELO %s\r\n", host && host->h_name ? host->h_name : - inet_ntoa (transport->localaddr.sin_addr)); - - fprintf (stderr, "sending : %s", cmdbuf); - if ( camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "HELO request timed out: " - "%s: non-fatal", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - do { - /* Check for "250" */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if ( !respbuf || strncmp (respbuf, "250", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "HELO response error: " - "%s: non-fatal", - g_strerror (errno)); - return FALSE; - } - if (transport->smtp_is_esmtp && strstr (respbuf, "AUTH")) { - /* parse for supported AUTH types */ - g_strchomp (respbuf); - transport->esmtp_supported_authtypes = esmtp_get_authtypes (respbuf); - } - } while ( *(respbuf+3) == '-' ); /* if we got "250-" then loop again */ - g_free (respbuf); - - return TRUE; -} - -static gboolean -smtp_mail (CamelSmtpTransport *transport, gchar *sender, CamelException *ex) -{ - /* we gotta tell the smtp server who we are. (our email addy) */ - gchar *cmdbuf, *respbuf = NULL; - - /* enclose address in <>'s since some SMTP daemons *require* that */ - cmdbuf = g_strdup_printf ("MAIL FROM: <%s>\r\n", sender); - - fprintf (stderr, "sending : %s", cmdbuf); - - if ( camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "MAIL FROM request timed out: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - do { - /* Check for "250 Sender OK..." */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if ( !respbuf || strncmp (respbuf, "250", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "MAIL FROM response error: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - } while ( *(respbuf+3) == '-' ); /* if we got "250-" then loop again */ - g_free (respbuf); - - return TRUE; -} - -static gboolean -smtp_rcpt (CamelSmtpTransport *transport, gchar *recipient, CamelException *ex) -{ - /* we gotta tell the smtp server who we are going to be sending - * our email to */ - gchar *cmdbuf, *respbuf = NULL; - - /* enclose address in <>'s since some SMTP daemons *require* that */ - cmdbuf = g_strdup_printf ("RCPT TO: <%s>\r\n", recipient); - - fprintf (stderr, "sending : %s", cmdbuf); - - if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "RCPT TO request timed out: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - do { - /* Check for "250 Sender OK..." */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if ( !respbuf || strncmp (respbuf, "250", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "RCPT TO response error: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - } while ( *(respbuf+3) == '-' ); /* if we got "250-" then loop again */ - g_free (respbuf); - - return TRUE; -} - -static gboolean -smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException *ex) -{ - /* now we can actually send what's important :p */ - gchar *cmdbuf, *respbuf = NULL; - CamelStreamFilter *filtered_stream; - CamelMimeFilter *mimefilter; - gint id; - - /* enclose address in <>'s since some SMTP daemons *require* that */ - cmdbuf = g_strdup ("DATA\r\n"); - - fprintf (stderr, "sending : %s", cmdbuf); - - if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA request timed out: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if (!respbuf || strncmp (respbuf, "354", 3) ) { - /* we should have gotten instructions on how to use the DATA command: - * 354 Enter mail, end with "." on a line by itself - */ - g_free (respbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA response error: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - - /* setup stream filtering */ - mimefilter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS); - filtered_stream = camel_stream_filter_new_with_stream (transport->ostream); - id = camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (mimefilter)); - - if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (filtered_stream)) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA send timed out: message termination: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - - camel_stream_filter_remove (filtered_stream, id); - camel_stream_flush (CAMEL_STREAM(filtered_stream)); - gtk_object_unref (GTK_OBJECT(filtered_stream)); - - /* terminate the message body */ - - fprintf (stderr, "sending : \\r\\n.\\r\\n\n"); - - if (camel_stream_write (transport->ostream, "\r\n.\r\n", 5) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA send timed out: message termination: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - - do { - /* Check for "250 Sender OK..." */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if (!respbuf || strncmp (respbuf, "250", 3)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA response error: message termination: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - } while (*(respbuf+3) == '-'); /* if we got "250-" then loop again */ - g_free (respbuf); - - return TRUE; -} - -static gboolean -smtp_rset (CamelSmtpTransport *transport, CamelException *ex) -{ - /* we are going to reset the smtp server (just to be nice) */ - gchar *cmdbuf, *respbuf = NULL; - - cmdbuf = g_strdup ("RSET\r\n"); - - fprintf (stderr, "sending : %s", cmdbuf); - - if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "RSET request timed out: " - "%s", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - do { - /* Check for "250" */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if (!respbuf || strncmp (respbuf, "250", 3)) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "RSET response error: " - "%s", - g_strerror (errno)); - return FALSE; - } - } while ( *(respbuf+3) == '-' ); /* if we got "250-" then loop again */ - g_free (respbuf); - - return TRUE; -} - -static gboolean -smtp_quit (CamelSmtpTransport *transport, CamelException *ex) -{ - /* we are going to reset the smtp server (just to be nice) */ - gchar *cmdbuf, *respbuf = NULL; - - cmdbuf = g_strdup ("QUIT\r\n"); - - fprintf (stderr, "sending : %s", cmdbuf); - - if ( camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { - g_free (cmdbuf); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "QUIT request timed out: " - "%s: non-fatal", - g_strerror (errno)); - return FALSE; - } - g_free (cmdbuf); - - do { - /* Check for "221" */ - g_free (respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream)); - - fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - - if ( !respbuf || strncmp (respbuf, "221", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "QUIT response error: " - "%s: non-fatal", - g_strerror (errno)); - return FALSE; - } - } while ( *(respbuf+3) == '-' ); /* if we got "221-" then loop again */ - g_free (respbuf); - - return TRUE; -} diff --git a/camel/providers/smtp/camel-smtp-transport.h b/camel/providers/smtp/camel-smtp-transport.h deleted file mode 100644 index c11b8b4738..0000000000 --- a/camel/providers/smtp/camel-smtp-transport.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-smtp-transport.h : class for an smtp transfer */ - -/* - * Authors: - * Jeffrey Stedfast <fejj@stampede.org> - * - * 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_SMTP_TRANSPORT_H -#define CAMEL_SMTP_TRANSPORT_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include "camel-transport.h" - -#define CAMEL_SMTP_TRANSPORT_TYPE (camel_smtp_transport_get_type ()) -#define CAMEL_SMTP_TRANSPORT(obj) (GTK_CHECK_CAST((obj), CAMEL_SMTP_TRANSPORT_TYPE, CamelSmtpTransport)) -#define CAMEL_SMTP_TRANSPORT_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_SMTP_TRANSPORT_TYPE, CamelSmtpTransportClass)) -#define IS_CAMEL_SMTP_TRANSPORT(o) (GTK_CHECK_TYPE((o), CAMEL_SMTP_TRANSPORT_TYPE)) - - -typedef struct { - CamelTransport parent_object; - - CamelStream *istream, *ostream; - - gboolean smtp_is_esmtp; - - struct sockaddr_in localaddr; - - GList *esmtp_supported_authtypes; - -} CamelSmtpTransport; - - - -typedef struct { - CamelTransportClass parent_class; - -} CamelSmtpTransportClass; - - -/* Standard Gtk function */ -GtkType camel_smtp_transport_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_SMTP_TRANSPORT_H */ - - diff --git a/camel/providers/smtp/libcamelsmtp.urls b/camel/providers/smtp/libcamelsmtp.urls deleted file mode 100644 index ec2fc0fc16..0000000000 --- a/camel/providers/smtp/libcamelsmtp.urls +++ /dev/null @@ -1 +0,0 @@ -smtp diff --git a/camel/providers/vee/.cvsignore b/camel/providers/vee/.cvsignore deleted file mode 100644 index fd6b811c68..0000000000 --- a/camel/providers/vee/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -Makefile -Makefile.in -.libs -.deps -*.lo -*.la diff --git a/camel/providers/vee/Makefile.am b/camel/providers/vee/Makefile.am deleted file mode 100644 index 849d6ae2e8..0000000000 --- a/camel/providers/vee/Makefile.am +++ /dev/null @@ -1,39 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelveeincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelvee.la -provider_DATA = libcamelvee.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) \ - -DG_LOG_DOMAIN=\"camel-vee-provider\" - -libcamelvee_la_SOURCES = \ - camel-vee-folder.c \ - camel-vee-provider.c \ - camel-vee-store.c - -libcamelveeinclude_HEADERS = \ - camel-vee-folder.h \ - camel-vee-store.h - -libcamelvee_la_LDFLAGS = -version-info 0:0:0 - -libcamelvee_la_LIBADD = $(top_builddir)/e-util/libeutil.la $(top_builddir)/libibex/libibex.la $(UNICODE_LIBS) -#libcamelvee_la_LIBADD = $(top_builddir)/libibex/libibex.la $(UNICODE_LIBS) - -EXTRA_DIST = libcamelvee.urls - diff --git a/camel/providers/vee/camel-vee-folder.c b/camel/providers/vee/camel-vee-folder.c deleted file mode 100644 index 9df922c832..0000000000 --- a/camel/providers/vee/camel-vee-folder.c +++ /dev/null @@ -1,587 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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-exception.h" -#include "camel-vee-folder.h" -#include "camel-folder-summary.h" -#include "camel-mime-message.h" - -#include <string.h> - -/* our message info includes the parent folder */ -typedef struct _CamelVeeMessageInfo { - CamelMessageInfo info; - CamelFolder *folder; -} CamelVeeMessageInfo; - -struct _CamelVeeFolderPrivate { - GList *folders; -}; - -#define _PRIVATE(o) (((CamelVeeFolder *)(o))->priv) - -static void vee_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar *separator, gboolean path_begins_with_sep, - CamelException *ex); - -static GPtrArray *vee_get_uids (CamelFolder *folder, CamelException *ex); -GPtrArray *vee_get_summary (CamelFolder *folder, CamelException *ex); -void vee_free_summary (CamelFolder *folder, GPtrArray *array); - -static gint vee_get_message_count (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *vee_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex); - -static const CamelMessageInfo *vee_get_message_info (CamelFolder *folder, const char *uid); -static GList *vee_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex); - -static guint32 vee_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex); -static void vee_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set, CamelException *ex); -static gboolean vee_get_message_user_flag (CamelFolder *folder, const char *uid, const char *name, CamelException *ex); -static void vee_set_message_user_flag (CamelFolder *folder, const char *uid, const char *name, gboolean value, CamelException *ex); - - -static void camel_vee_folder_class_init (CamelVeeFolderClass *klass); -static void camel_vee_folder_init (CamelVeeFolder *obj); -static void camel_vee_folder_finalise (GtkObject *obj); - -static void vee_folder_build(CamelVeeFolder *vf, CamelException *ex); -static void vee_folder_build_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex); - -static CamelFolderClass *camel_vee_folder_parent; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -camel_vee_folder_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "CamelVeeFolder", - sizeof (CamelVeeFolder), - sizeof (CamelVeeFolderClass), - (GtkClassInitFunc) camel_vee_folder_class_init, - (GtkObjectInitFunc) camel_vee_folder_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (camel_folder_get_type (), &type_info); - } - - return type; -} - -static void -camel_vee_folder_class_init (CamelVeeFolderClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - CamelFolderClass *folder_class = (CamelFolderClass *) klass; - - camel_vee_folder_parent = gtk_type_class (camel_folder_get_type ()); - - printf("vfolder class init\n"); - - folder_class->init = vee_init; - - folder_class->get_uids = vee_get_uids; - folder_class->get_summary = vee_get_summary; - folder_class->free_summary = vee_free_summary; - folder_class->get_message = vee_get_message; - - folder_class->get_message_info = vee_get_message_info; - - folder_class->get_message_count = vee_get_message_count; - folder_class->search_by_expression = vee_search_by_expression; - - folder_class->get_message_flags = vee_get_message_flags; - folder_class->set_message_flags = vee_set_message_flags; - folder_class->get_message_user_flag = vee_get_message_user_flag; - folder_class->set_message_user_flag = vee_set_message_user_flag; - - object_class->finalize = camel_vee_folder_finalise; - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -camel_vee_folder_init (CamelVeeFolder *obj) -{ - struct _CamelVeeFolderPrivate *p; - - printf("vfolder init\n"); - - p = _PRIVATE(obj) = g_malloc0(sizeof(*p)); -} - -static void -camel_vee_folder_finalise (GtkObject *obj) -{ - CamelVeeFolder *vf = (CamelVeeFolder *)obj; - struct _CamelVeeFolderPrivate *p = _PRIVATE(vf); - GList *node; - - node = p->folders; - while (node) { - CamelFolder *f = node->data; - gtk_object_unref((GtkObject *)f); - node = g_list_next(node); - } - - ((GtkObjectClass *)(camel_vee_folder_parent))->finalize((GtkObject *)obj); -} - -/** - * camel_vee_folder_new: - * - * Create a new CamelVeeFolder object. - * - * Return value: A new CamelVeeFolder widget. - **/ -CamelVeeFolder * -camel_vee_folder_new (void) -{ - CamelVeeFolder *new = CAMEL_VEE_FOLDER ( gtk_type_new (camel_vee_folder_get_type ())); - return new; -} - -static void -folder_changed(CamelFolder *sub, int type, CamelVeeFolder *vf) -{ - CamelException *ex; - - printf("subfolder changed!!, re-searching\n"); - - ex = camel_exception_new(); - vee_folder_build_folder(vf, sub, ex); - camel_exception_free(ex); - /* FIXME: should only raise follow-on event if the result changed */ - gtk_signal_emit_by_name((GtkObject *)vf, "folder_changed", 0); -} - -/* track flag changes in the summary */ -static void -message_changed(CamelFolder *f, const char *uid, CamelVeeFolder *mf) -{ - const CamelMessageInfo *info; - CamelMessageInfo *vinfo; - CamelFlag *flag; - char *vuid; - - printf("VMessage changed: %s\n", uid); - info = camel_folder_get_message_info(f, uid); - - vuid = g_strdup_printf("%p:%s", f, uid); - vinfo = (CamelMessageInfo *)vee_get_message_info((CamelFolder *)mf, vuid); - if (info && vinfo) { - vinfo->flags = info->flags; - camel_flag_list_free(&vinfo->user_flags); - flag = info->user_flags; - while (flag) { - camel_flag_set(&vinfo->user_flags, flag->name, TRUE); - flag = flag->next; - } - gtk_signal_emit_by_name((GtkObject *)mf, "message_changed", vinfo->uid); - } - g_free(vuid); -} - -void -camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub) -{ - struct _CamelVeeFolderPrivate *p = _PRIVATE(vf); - CamelException *ex; - - gtk_object_ref((GtkObject *)sub); - p->folders = g_list_append(p->folders, sub); - - gtk_signal_connect((GtkObject *)sub, "folder_changed", folder_changed, vf); - gtk_signal_connect((GtkObject *)sub, "message_changed", message_changed, vf); - - ex = camel_exception_new(); - vee_folder_build_folder(vf, sub, ex); - camel_exception_free(ex); - /* FIXME: should only raise follow-on event if the result changed */ - gtk_signal_emit_by_name((GtkObject *)vf, "folder_changed", 0); -} - - -static void vee_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar *separator, gboolean path_begins_with_sep, - CamelException *ex) -{ - CamelVeeFolder *vf = (CamelVeeFolder *)folder; - char *namepart, *searchpart; - - namepart = g_strdup(name); - searchpart = strchr(namepart, '?'); - if (searchpart == NULL) { - /* no search, no result! */ - searchpart = "(body-contains \"=some-invalid_string-sequence=xx\")"; - } else { - *searchpart++ = 0; - } - - camel_vee_folder_parent->init (folder, parent_store, parent_folder, name, separator, TRUE, ex); - if (camel_exception_get_id (ex)) - return; - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = FALSE; - folder->has_summary_capability = TRUE; - folder->has_search_capability = TRUE; - - /* FIXME: what to do about user flags if the subfolder doesn't support them? */ - folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | - CAMEL_MESSAGE_DELETED | - CAMEL_MESSAGE_DRAFT | - CAMEL_MESSAGE_FLAGGED | - CAMEL_MESSAGE_SEEN; - - vf->messages = g_ptr_array_new(); - vf->messages_uid = g_hash_table_new(g_str_hash, g_str_equal); - - vf->expression = g_strdup_printf("(or\n (match-all (user-flag \"%s\"))\n %s\n)", namepart, searchpart); - vf->vname = g_strdup(namepart); - - printf("VFolder expression is %s\n", vf->expression); - printf("VFolder full name = %s\n", camel_folder_get_full_name(folder)); - - g_free(namepart); - - vee_folder_build(vf, ex); -} - -static gint vee_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelVeeFolder *vf = (CamelVeeFolder *)folder; - - return vf->messages->len; -} - -static gboolean -get_real_message (CamelFolder *folder, const char *uid, - CamelFolder **out_folder, const char **out_uid, - CamelException *ex) -{ - CamelVeeMessageInfo *mi; - - mi = (CamelVeeMessageInfo *)vee_get_message_info(folder, uid); - if (mi == NULL) { - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "No such message %s in %s", uid, - folder->name); - return FALSE; - } - - *out_folder = mi->folder; - *out_uid = strchr(mi->info.uid, ':')+1; - return TRUE; -} - -static CamelMimeMessage *vee_get_message (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - const char *real_uid; - CamelFolder *real_folder; - - if (!get_real_message (folder, uid, &real_folder, &real_uid, ex)) - return NULL; - - return camel_folder_get_message (real_folder, real_uid, ex); -} - -GPtrArray *vee_get_summary (CamelFolder *folder, CamelException *ex) -{ - CamelVeeFolder *vf = (CamelVeeFolder *)folder; - - return vf->messages; -} - -void vee_free_summary (CamelFolder *folder, GPtrArray *array) -{ - /* no op */ -} - -static const CamelMessageInfo *vee_get_message_info (CamelFolder *f, const char *uid) -{ - CamelVeeFolder *vf = (CamelVeeFolder *)f; - - return g_hash_table_lookup(vf->messages_uid, uid); -} - -static GPtrArray *vee_get_uids (CamelFolder *folder, CamelException *ex) -{ - GPtrArray *result; - int i; - CamelVeeFolder *vf = (CamelVeeFolder *)folder; - - result = g_ptr_array_new (); - g_ptr_array_set_size (result, vf->messages->len); - for (i=0;i<vf->messages->len;i++) { - CamelMessageInfo *mi = g_ptr_array_index(vf->messages, i); - result->pdata[i] = g_strdup(mi->uid); - } - - return result; -} - -static GList * -vee_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex) -{ - GList *result = NULL, *node; - char *expr; - CamelVeeFolder *vf = (CamelVeeFolder *)folder; - struct _CamelVeeFolderPrivate *p = _PRIVATE(vf); - - expr = g_strdup_printf("(and %s %s)", vf->expression, expression); - node = p->folders; - while (node) { - CamelFolder *f = node->data; - GList *matches, *match; - matches = camel_folder_search_by_expression(f, vf->expression, ex); - match = matches; - while (match) { - char *uid = match->data; - result = g_list_prepend(result, g_strdup_printf("%p:%s", f, uid)); - match = g_list_next(match); - } - g_list_free(matches); - node = g_list_next(node); - } - return result; -} - -static guint32 -vee_get_message_flags(CamelFolder *folder, const char *uid, CamelException *ex) -{ - const char *real_uid; - CamelFolder *real_folder; - - if (!get_real_message (folder, uid, &real_folder, &real_uid, ex)) - return 0; - - return camel_folder_get_message_flags(real_folder, real_uid, ex); -} - -static void -vee_set_message_flags(CamelFolder *folder, const char *uid, guint32 flags, - guint32 set, CamelException *ex) -{ - const char *real_uid; - CamelFolder *real_folder; - - if (!get_real_message (folder, uid, &real_folder, &real_uid, ex)) - return; - - camel_folder_set_message_flags(real_folder, real_uid, flags, set, ex); -} - -static gboolean -vee_get_message_user_flag(CamelFolder *folder, const char *uid, - const char *name, CamelException *ex) -{ - const char *real_uid; - CamelFolder *real_folder; - - if (!get_real_message (folder, uid, &real_folder, &real_uid, ex)) - return FALSE; - - return camel_folder_get_message_user_flag(real_folder, real_uid, name, ex); -} - -static void -vee_set_message_user_flag(CamelFolder *folder, const char *uid, - const char *name, gboolean value, - CamelException *ex) -{ - const char *real_uid; - CamelFolder *real_folder; - - if (!get_real_message (folder, uid, &real_folder, &real_uid, ex)) - return; - - return camel_folder_set_message_user_flag(real_folder, real_uid, name, value, ex); -} - - -/* - need incremental update, based on folder. - Need to watch folders for changes and update accordingly. -*/ - -/* this does most of the vfolder magic */ -static void -vee_folder_build(CamelVeeFolder *vf, CamelException *ex) -{ - struct _CamelVeeFolderPrivate *p = _PRIVATE(vf); - GList *node; - - GPtrArray *messages; - GHashTable *messages_uid; - - { - int i; - - for (i=0;i<vf->messages->len;i++) { - CamelVeeMessageInfo *mi = g_ptr_array_index(vf->messages, i); - g_free(mi->info.subject); - g_free(mi->info.to); - g_free(mi->info.from); - g_free(mi->info.uid); - camel_flag_list_free(&mi->info.user_flags); - g_free(mi); - } - } - - printf("building folder expression: %s\n", vf->expression); - - messages = g_ptr_array_new(); - messages_uid = g_hash_table_new(g_str_hash, g_str_equal); - - node = p->folders; - while (node) { - GList *matches, *match; - CamelFolder *f = node->data; - CamelVeeMessageInfo *mi; - const CamelMessageInfo *info; - CamelFlag *flag; - - printf("searching folder: (%s)%s\n", - gtk_type_name(((GtkObject *)f)->klass->type), - camel_folder_get_full_name(f)); - - matches = camel_folder_search_by_expression(f, vf->expression, ex); - match = matches; - while (match) { - info = camel_folder_get_message_info(f, match->data); - if (info) { - mi = g_malloc0(sizeof(*mi)); - mi->info.subject = g_strdup(info->subject); - mi->info.to = g_strdup(info->to); - mi->info.from = g_strdup(info->from); - mi->info.uid = g_strdup_printf("%p:%s", f, info->uid); - mi->info.flags = info->flags; - mi->info.size = info->size; - mi->info.date_sent = info->date_sent; - mi->info.date_received = info->date_received; - flag = info->user_flags; - while (flag) { - camel_flag_set(&mi->info.user_flags, flag->name, TRUE); - flag = flag->next; - } - mi->info.content = NULL; - mi->folder = f; - g_ptr_array_add(messages, mi); - g_hash_table_insert(messages_uid, mi->info.uid, mi); - } - match = g_list_next(match); - } - g_list_free(matches); - node = g_list_next(node); - } - - printf("search complete\n"); - - g_ptr_array_free(vf->messages, TRUE); - vf->messages = messages; - g_hash_table_destroy(vf->messages_uid); - vf->messages_uid = messages_uid; -} - - -/* build query contents for a single folder */ -static void -vee_folder_build_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex) -{ - GList *matches, *match; - CamelFolder *f = source; - CamelVeeMessageInfo *mi; - const CamelMessageInfo *info; - CamelFlag *flag; - - GPtrArray *messages; - GHashTable *messages_uid; - - { - int i; - - for (i=0;i<vf->messages->len;i++) { - CamelVeeMessageInfo *mi = g_ptr_array_index(vf->messages, i); - if (mi->folder == source) { - g_hash_table_remove(vf->messages_uid, mi->info.uid); - g_ptr_array_remove_index_fast(vf->messages, i); - - g_free(mi->info.subject); - g_free(mi->info.to); - g_free(mi->info.from); - g_free(mi->info.uid); - camel_flag_list_free(&mi->info.user_flags); - g_free(mi); - i--; - } - } - } - - messages = vf->messages; - messages_uid = vf->messages_uid; - - matches = camel_folder_search_by_expression(f, vf->expression, ex); - match = matches; - while (match) { - info = camel_folder_get_message_info(f, match->data); - if (info) { - mi = g_malloc0(sizeof(*mi)); - mi->info.subject = g_strdup(info->subject); - mi->info.to = g_strdup(info->to); - mi->info.from = g_strdup(info->from); - mi->info.uid = g_strdup_printf("%p:%s", f, info->uid); - mi->info.flags = info->flags; - mi->info.size = info->size; - mi->info.date_sent = info->date_sent; - mi->info.date_received = info->date_received; - flag = info->user_flags; - while (flag) { - camel_flag_set(&mi->info.user_flags, flag->name, TRUE); - flag = flag->next; - } - mi->info.content = NULL; - mi->folder = f; - g_ptr_array_add(messages, mi); - g_hash_table_insert(messages_uid, mi->info.uid, mi); - } - match = g_list_next(match); - } - g_list_free(matches); -} - - -/* - - (match-folder "folder1" "folder2") - - */ diff --git a/camel/providers/vee/camel-vee-folder.h b/camel/providers/vee/camel-vee-folder.h deleted file mode 100644 index ea2a82a25b..0000000000 --- a/camel/providers/vee/camel-vee-folder.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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_VEE_FOLDER_H -#define _CAMEL_VEE_FOLDER_H - -#include <gtk/gtk.h> -#include <camel/camel-folder.h> - -#define CAMEL_VEE_FOLDER(obj) GTK_CHECK_CAST (obj, camel_vee_folder_get_type (), CamelVeeFolder) -#define CAMEL_VEE_FOLDER_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_vee_folder_get_type (), CamelVeeFolderClass) -#define IS_CAMEL_VEE_FOLDER(obj) GTK_CHECK_TYPE (obj, camel_vee_folder_get_type ()) - -typedef struct _CamelVeeFolder CamelVeeFolder; -typedef struct _CamelVeeFolderClass CamelVeeFolderClass; - -struct _CamelVeeFolder { - CamelFolder parent; - - struct _CamelVeeFolderPrivate *priv; - - char *expression; /* query expression */ - char *vname; /* local name */ - CamelFolder *local; /* local storage for folder */ - - /* FIXME: Move this to a summary object??? */ - GPtrArray *messages; /* message info's */ - GHashTable *messages_uid; -}; - -struct _CamelVeeFolderClass { - CamelFolderClass parent_class; -}; - -guint camel_vee_folder_get_type (void); -CamelVeeFolder *camel_vee_folder_new (void); - -void camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub); - -#endif /* ! _CAMEL_VEE_FOLDER_H */ diff --git a/camel/providers/vee/camel-vee-provider.c b/camel/providers/vee/camel-vee-provider.c deleted file mode 100644 index e36e7fcff1..0000000000 --- a/camel/providers/vee/camel-vee-provider.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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 "config.h" -#include "camel-vee-store.h" -#include "camel-provider.h" -#include "camel-session.h" -#include "camel-url.h" - -static CamelProvider vee_provider = { - "vfolder", - "Virtual folder email provider", - - "For reading mail as a query of another set of folders", - - "vfolder", - - 0, - - { 0, 0 }, - - NULL -}; - -void -camel_provider_module_init (CamelSession *session) -{ - vee_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_vee_store_get_type(); - - vee_provider.service_cache = g_hash_table_new (camel_url_hash, camel_url_equal); - - camel_session_register_provider (session, &vee_provider); -} diff --git a/camel/providers/vee/camel-vee-store.c b/camel/providers/vee/camel-vee-store.c deleted file mode 100644 index ecc37982e4..0000000000 --- a/camel/providers/vee/camel-vee-store.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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-vee-store.h" -#include "camel-vee-folder.h" - -static CamelFolder *vee_get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex); -static char *vee_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); - -struct _CamelVeeStorePrivate { -}; - -#define _PRIVATE(o) (((CamelVeeStore *)(o))->priv) - -static void camel_vee_store_class_init (CamelVeeStoreClass *klass); -static void camel_vee_store_init (CamelVeeStore *obj); -static void camel_vee_store_finalise (GtkObject *obj); - -static CamelStoreClass *camel_vee_store_parent; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -camel_vee_store_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "CamelVeeStore", - sizeof (CamelVeeStore), - sizeof (CamelVeeStoreClass), - (GtkClassInitFunc) camel_vee_store_class_init, - (GtkObjectInitFunc) camel_vee_store_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (camel_store_get_type (), &type_info); - } - - return type; -} - -static void - -camel_vee_store_class_init (CamelVeeStoreClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - CamelStoreClass *store_class = (CamelStoreClass *) klass; - - camel_vee_store_parent = gtk_type_class (camel_store_get_type ()); - - /* virtual method overload */ - store_class->get_folder = vee_get_folder; - store_class->get_folder_name = vee_get_folder_name; - - object_class->finalize = camel_vee_store_finalise; - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -camel_vee_store_init (CamelVeeStore *obj) -{ - struct _CamelVeeStorePrivate *p; - - p = _PRIVATE(obj) = g_malloc0(sizeof(*p)); -} - -static void -camel_vee_store_finalise (GtkObject *obj) -{ - ((GtkObjectClass *)(camel_vee_store_parent))->finalize((GtkObject *)obj); -} - -/** - * camel_vee_store_new: - * - * Create a new CamelVeeStore object. - * - * Return value: A new CamelVeeStore widget. - **/ -CamelVeeStore * -camel_vee_store_new (void) -{ - CamelVeeStore *new = CAMEL_VEE_STORE ( gtk_type_new (camel_vee_store_get_type ())); - return new; -} - -static CamelFolder * -vee_get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) -{ - CamelFolder *folder; - - folder = gtk_type_new (camel_vee_folder_get_type()); - - printf("my type is: %s\n", gtk_type_name(((GtkObject *)folder)->klass->type)); - - ((CamelFolderClass *)((GtkObject *)folder)->klass)->init (folder, store, NULL, folder_name, "/", TRUE, ex); - return folder; -} - -static char * -vee_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) -{ - return g_strdup(folder_name); -} - diff --git a/camel/providers/vee/camel-vee-store.h b/camel/providers/vee/camel-vee-store.h deleted file mode 100644 index 848769296a..0000000000 --- a/camel/providers/vee/camel-vee-store.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@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_VEE_STORE_H -#define _CAMEL_VEE_STORE_H - -#include <gtk/gtk.h> -#include <camel/camel-store.h> - -#define CAMEL_VEE_STORE(obj) GTK_CHECK_CAST (obj, camel_vee_store_get_type (), CamelVeeStore) -#define CAMEL_VEE_STORE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_vee_store_get_type (), CamelVeeStoreClass) -#define IS_CAMEL_VEE_STORE(obj) GTK_CHECK_TYPE (obj, camel_vee_store_get_type ()) - -typedef struct _CamelVeeStore CamelVeeStore; -typedef struct _CamelVeeStoreClass CamelVeeStoreClass; - -struct _CamelVeeStore { - CamelStore parent; - - struct _CamelVeeStorePrivate *priv; -}; - -struct _CamelVeeStoreClass { - CamelStoreClass parent_class; -}; - -guint camel_vee_store_get_type (void); -CamelVeeStore *camel_vee_store_new (void); - -#endif /* ! _CAMEL_VEE_STORE_H */ diff --git a/camel/providers/vee/libcamelvee.urls b/camel/providers/vee/libcamelvee.urls deleted file mode 100644 index 6fa58dadb5..0000000000 --- a/camel/providers/vee/libcamelvee.urls +++ /dev/null @@ -1 +0,0 @@ -vfolder |