diff options
Diffstat (limited to 'camel/providers')
61 files changed, 0 insertions, 10544 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 dab6bec199..0000000000 --- a/camel/providers/MH/Makefile.am +++ /dev/null @@ -1,33 +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 - -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 7c520a8b8b..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 - -# these ones are disabled for the moment. -# MH maildir imap smtp 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 51a0d7327b..0000000000 --- a/camel/providers/maildir/Makefile.am +++ /dev/null @@ -1,23 +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) - -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 -rpath $(libdir) - -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 258c01a94e..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 - -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) - -libcamelmbox_la_SOURCES = \ - camel-mbox-folder.c \ - camel-mbox-provider.c \ - camel-mbox-store.c \ - camel-mbox-search.c \ - camel-mbox-summary.c - -libcamelmboxinclude_HEADERS = \ - camel-mbox-folder.h \ - camel-mbox-store.h \ - camel-mbox-search.h \ - camel-mbox-summary.h - -libcamelmbox_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - -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 = - diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c deleted file mode 100644 index c1920bdd1c..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.c +++ /dev/null @@ -1,893 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* 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 "gmime-utils.h" -#include "camel-mbox-search.h" -#include "camel-data-wrapper.h" -#include "camel-mime-message.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 _init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar separator, CamelException *ex); - -static void _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); -static void _close (CamelFolder *folder, gboolean expunge, 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_by_number (CamelFolder *folder, gint number, CamelException *ex); -static gint _get_message_count (CamelFolder *folder, CamelException *ex); -static void _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static GList *_get_uid_list (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex); -#if 0 -static void _expunge (CamelFolder *folder, CamelException *ex); -static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex); -static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -#endif - -GPtrArray *summary_get_message_info (CamelFolder *folder, int first, int count); - -static void _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 = _init; - camel_folder_class->open = _open; - camel_folder_class->close = _close; - 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->list_subfolders = _list_subfolders; - camel_folder_class->get_message_by_number = _get_message_by_number; - camel_folder_class->get_message_count = _get_message_count; - camel_folder_class->append_message = _append_message; - camel_folder_class->get_uid_list = _get_uid_list; -#if 0 - camel_folder_class->expunge = _expunge; - camel_folder_class->copy_message_to = _copy_message_to; - camel_folder_class->get_message_uid = _get_message_uid; -#endif - camel_folder_class->get_message_by_uid = _get_message_by_uid; - - camel_folder_class->search_by_expression = camel_mbox_folder_search_by_expression; - camel_folder_class->search_complete = camel_mbox_folder_search_complete; - camel_folder_class->search_cancel = camel_mbox_folder_search_cancel; - - camel_folder_class->get_message_info = summary_get_message_info; - - gtk_object_class->finalize = _finalize; - -} - -static void -_finalize (GtkObject *object) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (object); - - g_free (mbox_folder->folder_file_path); - g_free (mbox_folder->folder_dir_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 -_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, gchar separator, - CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - const gchar *root_dir_path; - - /* call parent method */ - parent_class->init (folder, parent_store, parent_folder, - name, separator, 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_uid_capability = TRUE; - folder->has_search_capability = TRUE; - - mbox_folder->summary = 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)); - - mbox_folder->folder_file_path = g_strdup_printf ("%s/%s", root_dir_path, folder->full_name); - mbox_folder->summary_file_path = g_strdup_printf ("%s/%s-ev-summary", root_dir_path, folder->full_name); - mbox_folder->folder_dir_path = g_strdup_printf ("%s/%s.sdb", root_dir_path, folder->full_name); - mbox_folder->index_file_path = g_strdup_printf ("%s/%s.ibex", root_dir_path, folder->full_name); -} - -static void -_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - /* call parent class */ - parent_class->open (folder, mode, ex); - if (camel_exception_get_id(ex)) - return; - - mbox_folder->index = ibex_open(mbox_folder->index_file_path, O_CREAT|O_RDWR, 0600); - if (mbox_folder->index == NULL) { - g_warning("Could not open/create index file: %s: indexing will not function", - strerror(errno)); - } - - 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_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, /* FIXME: right error code */ - "Could not create summary"); - return; - } - camel_mbox_summary_load(mbox_folder->summary); -} - -static void -_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - /* call parent implementation */ - parent_class->close (folder, expunge, ex); - - /* save index */ - if (mbox_folder->index) { - ibex_close(mbox_folder->index); - mbox_folder->index = NULL; - } - camel_mbox_summary_save (mbox_folder->summary); - camel_mbox_summary_unref (mbox_folder->summary); - mbox_folder->summary = NULL; -} - - -/* FIXME: clean up this snot */ -static gboolean -_exists (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder; - struct stat stat_buf; - gint stat_error; - gboolean exists; - - g_assert(folder != NULL); - - mbox_folder = CAMEL_MBOX_FOLDER (folder); - - /* check if the mbox file path is determined */ - if (!mbox_folder->folder_file_path) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "undetermined folder file path. Maybe use set_name ?"); - return FALSE; - } - - /* check if the mbox dir path is determined */ - if (!mbox_folder->folder_dir_path) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "undetermined folder directory path. Maybe use set_name ?"); - return FALSE; - } - - - /* we should not check for that here */ -#if 0 - /* check if the mbox directory exists */ - access_result = access (mbox_folder->folder_dir_path, F_OK); - if (access_result < 0) { - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - strerror(errno)); - return FALSE; - } - stat_error = stat (mbox_folder->folder_dir_path, &stat_buf); - if (stat_error == -1) { - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - strerror(errno)); - return FALSE; - } - exists = S_ISDIR (stat_buf.st_mode); - if (!exists) return FALSE; -#endif - - - /* check if the mbox file exists */ - stat_error = stat (mbox_folder->folder_file_path, &stat_buf); - if (stat_error == -1) - return FALSE; - - exists = S_ISREG (stat_buf.st_mode); - /* we should check the rights here */ - - return exists; -} - -/* FIXME: clean up this snot */ -static gboolean -_create (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - const gchar *folder_file_path, *folder_dir_path; - mode_t dir_mode = S_IRWXU; - gint mkdir_error; - gboolean folder_already_exists; - int creat_fd; - - g_assert(folder != NULL); - - /* call default implementation */ - parent_class->create (folder, ex); - - /* get the paths of what we need to create */ - folder_file_path = mbox_folder->folder_file_path; - folder_dir_path = mbox_folder->folder_dir_path; - - if (!(folder_file_path || folder_dir_path)) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "invalid folder path. Use set_name ?"); - return FALSE; - } - - - /* if the folder already exists, simply return */ - folder_already_exists = camel_folder_exists (folder,ex); - if (camel_exception_get_id (ex)) - return FALSE; - - if (folder_already_exists) - return TRUE; - - - /* create the directory for the subfolders */ - mkdir_error = mkdir (folder_dir_path, dir_mode); - if (mkdir_error == -1) - goto io_error; - - - /* create the mbox file */ - /* it must be rw for the user and none for the others */ - creat_fd = open (folder_file_path, - O_WRONLY | O_CREAT | O_APPEND, - 0600); - if (creat_fd == -1) - goto io_error; - - close (creat_fd); - - return TRUE; - - /* exception handling for io errors */ - io_error : - if (errno == EACCES) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "You don't have the permission to create the mbox file."); - return FALSE; - } else { - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - "Unable to create the mbox file."); - return FALSE; - } -} - - -/* FIXME: cleanup */ -static gboolean -_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - const gchar *folder_file_path, *folder_dir_path; - gint rmdir_error = 0; - gint unlink_error = 0; - gboolean folder_already_exists; - - g_assert(folder != NULL); - - /* 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); - - - /* get the paths of what we need to be deleted */ - folder_file_path = mbox_folder->folder_file_path; - folder_dir_path = mbox_folder->folder_file_path; - - if (!(folder_file_path || folder_dir_path)) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "invalid folder path. Use set_name ?"); - return FALSE; - } - - - /* physically delete the directory */ - rmdir_error = rmdir (folder_dir_path); - if (rmdir_error == -1) - switch (errno) { - case EACCES : - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "Not enough permission to delete the mbox folder"); - return FALSE; - break; - - case ENOTEMPTY : - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NON_EMPTY, - "mbox folder not empty. Cannot delete it. Maybe use recurse flag ?"); - return FALSE; - break; - default : - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - "Unable to delete the mbox folder."); - return FALSE; - } - - /* physically delete the file */ - unlink_error = unlink (folder_dir_path); - if (unlink_error == -1) - switch (errno) { - case EACCES : - case EPERM : - case EROFS : - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "Not enough permission to delete the mbox file"); - return FALSE; - break; - - case EFAULT : - case ENOENT : - case ENOTDIR : - case EISDIR : - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID_PATH, - "Invalid mbox file"); - return FALSE; - break; - - default : - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - "Unable to delete the mbox folder."); - return FALSE; - } - - - return TRUE; -} - -/* TODO: remove this */ -gboolean -_delete_messages (CamelFolder *folder, CamelException *ex) -{ - - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - const gchar *folder_file_path; - gboolean folder_already_exists; - int creat_fd; - g_assert(folder!=NULL); - - /* 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; - - - - /* get the paths of the mbox file we need to delete */ - folder_file_path = mbox_folder->folder_file_path; - - if (!folder_file_path) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "invalid folder path. Use set_name ?"); - return FALSE; - } - - - /* create the mbox file */ - /* it must be rw for the user and none for the others */ - creat_fd = open (folder_file_path, - O_WRONLY | O_TRUNC, - 0600); - if (creat_fd == -1) - goto io_error; - close (creat_fd); - - return TRUE; - - /* exception handling for io errors */ - io_error : - if (errno == EACCES) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "You don't have the permission to write in the mbox file."); - return FALSE; - } else { - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - "Unable to write in the mbox file."); - return FALSE; - } - - -} - -/* FIXME: cleanup */ -static GList * -_list_subfolders (CamelFolder *folder, CamelException *ex) -{ - GList *subfolder_name_list = NULL; - - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - const gchar *folder_dir_path; - gboolean folder_exists; - - struct stat stat_buf; - gint stat_error = 0; - gchar *entry_name; - gchar *full_entry_name; - gchar *real_folder_name; - struct dirent *dir_entry; - DIR *dir_handle; - gboolean folder_suffix_found; - - - /* check if the folder object exists */ - if (!folder) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_NULL, - "folder object is NULL"); - return FALSE; - } - - - /* in the case the folder does not exist, - raise an exception */ - folder_exists = camel_folder_exists (folder, ex); - if (camel_exception_get_id (ex)) return FALSE; - - if (!folder_exists) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "Inexistant folder."); - return FALSE; - } - - - /* get the mbox subfolders directories */ - folder_dir_path = mbox_folder->folder_file_path; - if (!folder_dir_path) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "Invalid folder path. Use set_name ?"); - return FALSE; - } - - - dir_handle = opendir (folder_dir_path); - - /* 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", folder_dir_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] != '.') { - /* if the folder is a netscape folder, remove the - ".sdb" from the name */ - real_folder_name = string_prefix (entry_name, ".sdb", &folder_suffix_found); - /* stick here the tests for other folder suffixes if any */ - - if (!folder_suffix_found) real_folder_name = g_strdup (entry_name); - - /* add the folder name to the list */ - subfolder_name_list = g_list_append (subfolder_name_list, - real_folder_name); - } - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return subfolder_name_list; - - - - /* io exception handling */ - switch (errno) { - case EACCES : - - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "Unable to list the directory. Full Error text is : %s ", - strerror (errno)); - break; - - case ENOENT : - case ENOTDIR : - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INVALID_PATH, - "Invalid mbox folder path. Full Error text is : %s ", - strerror (errno)); - break; - - default : - camel_exception_set (ex, - CAMEL_EXCEPTION_SYSTEM, - "Unable to delete the mbox folder."); - - } - - g_list_free (subfolder_name_list); - return NULL; -} - -static gint -_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - - g_assert (folder); - g_assert (mbox_folder->summary); - - return camel_mbox_summary_message_count(mbox_folder->summary); -} - -/* - This is a lazy append. - - Basically, messages are appended to the end of the mbox, and probably assigned - a new uid (they wont be if copying from a source folder which doesn't have - a uid - which wont happen with the current summariser). - - Indexing/summarising happens when the mbox is next queried. - - Should this set a flag up for subsequent updating?? -*/ - -/* FIXME: this may need some tweaking for performance? */ -static void -_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder), *source_folder; - CamelStream *output_stream; - struct stat st; - off_t seek; - char *xev; - guint32 uid; - - if (stat(mbox_folder->folder_file_path, &st) != 0) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, /* FIXME: what code? */ - "Cannot append to mbox file: %s", strerror (errno)); - return; - } - - /* are we coming from an mbox folder? then we can optimise somewhat ... */ - if (message->folder && IS_CAMEL_MBOX_FOLDER(message->folder)) { - CamelMboxMessageInfo *info; - int sfd, dfd; - off_t pos; - - /* FIXME: this is pretty ugly - we lookup the message info in the source folder, copy it, - then go back and paste in its real uid. */ - source_folder = (CamelMboxFolder *)message->folder; - info = camel_mbox_summary_uid(source_folder->summary, message->message_uid); - - d(printf("Copying message directly from %s to %s\n", source_folder->folder_file_path, mbox_folder->folder_file_path)); - d(printf("start = %d, xev = %d\n", ((CamelMboxMessageContentInfo *)info->info.content)->pos, info->xev_offset)); - - sfd = open(source_folder->folder_file_path, O_RDONLY); - dfd = open(mbox_folder->folder_file_path, O_RDWR|O_CREAT, 0600); - if (lseek(dfd, st.st_size, SEEK_SET) != st.st_size) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, /* FIXME: what code? */ - "Cannot append to mbox file: %s", strerror (errno)); - close(sfd); - close(dfd); - return; - } - write(dfd, "From - \n", strlen("From - \n")); - camel_mbox_summary_copy_block - (sfd, dfd, ((CamelMboxMessageContentInfo *)info->info.content)->pos, - ((CamelMboxMessageContentInfo *)info->info.content)->endpos - ((CamelMboxMessageContentInfo *)info->info.content)->pos); - if (info->xev_offset != -1) { - pos = st.st_size + (info->xev_offset - ((CamelMboxMessageContentInfo *)info->info.content)->pos) + strlen("From - \n"); - d(printf("Inserting new uid at %d\n", (int)pos)); - if (pos != lseek(dfd, pos, SEEK_SET)) { - ftruncate(dfd, st.st_size); - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, /* FIXME: what code? */ - "Cannot append to mbox file: %s", strerror (errno)); - close(sfd); - close(dfd); - return; - } - uid = camel_mbox_summary_next_uid(mbox_folder->summary); - xev = g_strdup_printf("X-Evolution: %08x-%04x", uid, 0); - write(dfd, xev, strlen(xev)); /* FIXME: check return */ - d(printf("header = %s\n", xev)); - g_free(xev); - } - close(sfd); - close(dfd); - return; - } - - /* its not an mbox folder, so lets do it the slow way ... */ - output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, CAMEL_STREAM_FS_WRITE); - if (output_stream == NULL) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, /* FIXME: what code? */ - "Cannot append to mbox file: %s", strerror (errno)); - return; - } - - seek = camel_seekable_stream_seek((CamelSeekableStream *)output_stream, st.st_size, SEEK_SET); - if (seek != st.st_size) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, /* FIXME: what code? */ - "Cannot seek to position in mbox file: %s", strerror (errno)); - gtk_object_unref ((GtkObject *)output_stream); - return; - } - - /* assign a new x-evolution header */ - /* FIXME: save flags? */ - camel_medium_remove_header((CamelMedium *)message, "X-Evolution"); - uid = camel_mbox_summary_next_uid(mbox_folder->summary); - xev = g_strdup_printf("%08x-%04x", uid, 0); - camel_medium_add_header((CamelMedium *)message, "X-Evolution", xev); - g_free(xev); - - camel_stream_write_string (output_stream, "From - \n"); - /* FIXME: does this return an error? IT HAS TO FOR THIS TO BE RELIABLE */ - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); - camel_stream_close (output_stream); - - /* TODO: update the summary so it knows a new message is there to summarise/index */ - /* This is only a performance improvement, the summary is *only* a cache */ - - gtk_object_unref (GTK_OBJECT (output_stream)); -} - - - - -static GList * -_get_uid_list (CamelFolder *folder, CamelException *ex) -{ - GList *uid_list = NULL; - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - int i, count; - - /* FIXME: how are these allocated strings ever free'd? */ - count = camel_mbox_summary_message_count(mbox_folder->summary); - for (i=0;i<count;i++) { - CamelMboxMessageInfo *info = camel_mbox_summary_index(mbox_folder->summary, i); - uid_list = g_list_prepend(uid_list, g_strdup(info->info.uid)); - } - - return uid_list; -} - -static CamelMimeMessage * -_get_message_by_number (CamelFolder *folder, gint number, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - CamelMboxMessageInfo *info; - - g_warning("YOUR CODE SHOULD NOT BE GETTING MESSAGES BY NUMBER, CHANGE IT"); - - info = camel_mbox_summary_index(mbox_folder->summary, number); - if (info == NULL) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "No such message %d in folder `%s'.", - number, folder->name); - return NULL; - } - - return _get_message_by_uid (folder, info->info.uid, ex); -} - -static CamelMimeMessage * -_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - CamelStream *message_stream; - CamelMimeMessage *message = NULL; - CamelStore *parent_store; - CamelMboxMessageInfo *info; - - /* get the parent store */ - parent_store = camel_folder_get_parent_store (folder, ex); - if (camel_exception_get_id (ex)) { - return NULL; - } - - /* get the message summary info */ - info = camel_mbox_summary_uid(mbox_folder->summary, uid); - - if (info == NULL) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "uid %s not found in the folder", - uid); - return NULL; - } - - /* if this has no content, its an error in the library */ - g_assert(info->info.content); - - /* FIXME: more checks below */ - /* create a stream bound to the message position/size */ - message_stream = camel_stream_fs_new_with_name_and_bounds (mbox_folder->folder_file_path, - CAMEL_STREAM_FS_READ, - ((CamelMboxMessageContentInfo *)info->info.content)->pos, - ((CamelMboxMessageContentInfo *)info->info.content)->endpos); - message = camel_mime_message_new(); -#if 1 - { - CamelMimeParser *parser; - - parser = camel_mime_parser_new(); - camel_mime_parser_init_with_stream(parser, message_stream); - camel_data_wrapper_construct_from_parser(message, parser); - gtk_object_unref((GtkObject *)parser); - gtk_object_unref((GtkObject *)message_stream); - } -#else - camel_data_wrapper_set_input_stream (CAMEL_DATA_WRAPPER (message), message_stream); -#endif - /* init other fields? */ - message->folder = folder; - gtk_object_ref((GtkObject *)folder); - message->message_uid = g_strdup(uid); - - return message; -} - -/* get message info for a range of messages */ -GPtrArray *summary_get_message_info (CamelFolder *folder, int first, int count) -{ - GPtrArray *array = g_ptr_array_new(); - int i, maxcount; - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - - maxcount = camel_mbox_summary_message_count(mbox_folder->summary); - maxcount = MAX(count, maxcount); - for (i=first;i<maxcount;i++) - g_ptr_array_add(array, g_ptr_array_index(mbox_folder->summary->messages, i)); - - return array; -} diff --git a/camel/providers/mbox/camel-mbox-folder.h b/camel/providers/mbox/camel-mbox-folder.h deleted file mode 100644 index f74c51a6c3..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.h +++ /dev/null @@ -1,82 +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-folder.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 */ - int search_id; /* next search id */ - GList *searches; /* current searches */ - - CamelMboxSummary *summary; -} 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 74c4345306..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" - - -static CamelProvider _mbox_provider = { - (GtkType) 0, - PROVIDER_STORE, - 0, - - "mbox", - "UNIX mbox-format mail files", - - "For reading mail delivered by the local system, and for " - "storing mail on local disk.", - - (GModule *) NULL -}; - -CamelProvider * -camel_provider_module_init (void); - - -CamelProvider * -camel_provider_module_init (void) -{ - _mbox_provider.object_type = camel_mbox_store_get_type(); - return &_mbox_provider; -} - - - diff --git a/camel/providers/mbox/camel-mbox-search.c b/camel/providers/mbox/camel-mbox-search.c deleted file mode 100644 index 1e134476e5..0000000000 --- a/camel/providers/mbox/camel-mbox-search.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright 2000 HelixCode (http://www.helixcode.com). - * - * Author : - * 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 <glib.h> -#include <stdio.h> -#include <time.h> -#include <string.h> - - -#include <camel/gmime-utils.h> -#include "camel/camel-mime-message.h" -#include "camel/camel-mime-part.h" -#include "camel/camel-stream.h" -#include "camel/camel-stream-fs.h" -#include "camel/camel.h" -#include "camel-mbox-folder.h" -#include "camel-mbox-summary.h" - -#include "camel-mbox-search.h" -#define HAVE_FILTER -#ifdef HAVE_FILTER -#include "e-sexp.h" - -#define HAVE_IBEX -#ifdef HAVE_IBEX -#include "ibex.h" -#endif - -#define p(x) /* parse debug */ -#define r(x) /* run debug */ -#define d(x) /* general debug */ - - -/* - - Matching operators: - - list = (body-contains string+) - bool = (body-contains string+) - Returns a list of all messages containing any of the strings in the message. - If within a match-all, then returns true for the current message. - - list = (match-all bool-expr) - Returns a list of all messages for which the bool expression is true. - The bool-expr is evaluated for each message in turn. - It is more efficient not to perform body-content comparisons inside a - match-all operator. - - int = (date-sent) - Returns a time_t of the date-sent of the message. - - bool = (header-contains string string+) - Returns true if the current message (inside a match-all operator) - has a header 'string1', which contains any of the following strings. -*/ - - -struct _searchcontext { - int id; /* id of this search */ - int cancelled; /* search cancelled? */ - - CamelFolder *folder; - -#ifdef HAVE_IBEX - ibex *index; /* index of content for this folder */ -#endif - - CamelMboxSummary *summary; - - CamelMboxMessageInfo *message_current; /* when performing a (match operation */ -}; - -struct _glib_sux_donkeys { - int count; - GPtrArray *uids; -}; -/* or, store all unique values */ -static void -g_lib_sux_htor(char *key, int value, struct _glib_sux_donkeys *fuckup) -{ - g_ptr_array_add(fuckup->uids, key); -} - -static ESExpResult * -func_body_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - ESExpResult *r; - int i, j; - struct _searchcontext *ctx = data; - - if (ctx->message_current) { - int truth = FALSE; - - r = e_sexp_result_new(ESEXP_RES_BOOL); - if (ctx->index) { - for (i=0;i<argc && !truth;i++) { - if (argv[i]->type == ESEXP_RES_STRING) { - truth = ibex_find_name(ctx->index, ctx->message_current->info.uid, argv[i]->value.string); - } else { - g_warning("Invalid type passed to body-contains match function"); - } - } - } else { - g_warning("Cannot perform indexed query with no index"); - } - r->value.bool = truth; - } else { - r = e_sexp_result_new(ESEXP_RES_ARRAY_PTR); - - if (ctx->index) { - if (argc==1) { - /* common case */ - r->value.ptrarray = ibex_find(ctx->index, argv[0]->value.string); - } else { - GHashTable *ht = g_hash_table_new(g_str_hash, g_str_equal); - GPtrArray *pa; - struct _glib_sux_donkeys lambdafoo; - - /* this sux, perform an or operation on the result(s) of each word */ - for (i=0;i<argc;i++) { - if (argv[i]->type == ESEXP_RES_STRING) { - pa = ibex_find(ctx->index, argv[i]->value.string); - for (j=0;j<pa->len;j++) { - g_hash_table_insert(ht, g_ptr_array_index(pa, j), (void *)1); - } - g_ptr_array_free(pa, FALSE); - } - } - lambdafoo.uids = g_ptr_array_new(); - g_hash_table_foreach(ht, (GHFunc)g_lib_sux_htor, &lambdafoo); - r->value.ptrarray = lambdafoo.uids; - } - } else { - r->value.ptrarray = g_ptr_array_new(); - } - } - - return r; -} - -static ESExpResult * -func_date_sent(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - ESExpResult *r; - struct _searchcontext *ctx = data; - - r = e_sexp_result_new(ESEXP_RES_INT); - - if (ctx->message_current) { - g_warning("FIXME: implement date parsing ..."); - /* r->value.number = get_date(ctx->message_current); */ - } else { - r->value.number = time(0); - } - return r; -} - - -static ESExpResult * -func_match_all(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - int i; - ESExpResult *r, *r1; - struct _searchcontext *ctx = data; - - if (argc>1) { - g_warning("match-all only takes a single argument, other arguments ignored"); - } - r = e_sexp_result_new(ESEXP_RES_ARRAY_PTR); - r->value.ptrarray = g_ptr_array_new(); - - for (i=0;i<ctx->summary->messages->len;i++) { - if (argc>0) { - ctx->message_current = g_ptr_array_index(ctx->summary->messages, i); - r1 = e_sexp_term_eval(f, argv[0]); - if (r1->type == ESEXP_RES_BOOL) { - if (r1->value.bool) - g_ptr_array_add(r->value.ptrarray, ctx->message_current->info.uid); - } else { - g_warning("invalid syntax, matches require a single bool result"); - } - e_sexp_result_free(r1); - } else { - g_ptr_array_add(r->value.ptrarray, ctx->message_current->info.uid); - } - } - ctx->message_current = NULL; - - return r; -} - -static ESExpResult * -func_header_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - ESExpResult *r; - struct _searchcontext *ctx = data; - int truth = FALSE; - - r(printf("executing header-contains\n")); - - /* are we inside a match-all? */ - if (ctx->message_current && argc>1 - && argv[0]->type == ESEXP_RES_STRING) { - char *headername, *header = NULL; - char strbuf[32]; - int i; - - /* only a subset of headers are supported .. */ - headername = argv[0]->value.string; - if (!strcasecmp(headername, "subject")) { - header = ctx->message_current->info.subject; - } else if (!strcasecmp(headername, "date")) { - sprintf(strbuf, "%d", (int)ctx->message_current->info.date_sent); - header = strbuf; - } else if (!strcasecmp(headername, "from")) { - header = ctx->message_current->info.from; - } else { - g_warning("Performing query on unknown header: %s", headername); - } - - if (header) { - for (i=1;i<argc && !truth;i++) { - if (argv[i]->type == ESEXP_RES_STRING - && strstr(header, argv[i]->value.string)) { - printf("%s got a match with %s of %s\n", ctx->message_current->info.uid, header, argv[i]->value.string); - truth = TRUE; - break; - } - } - } - } - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = truth; - - return r; -} - - -/* 'builtin' functions */ -static struct { - char *name; - ESExpFunc *func; - int type; /* set to 1 if a function can perform shortcut evaluation, or - doesn't execute everything, 0 otherwise */ -} symbols[] = { - { "body-contains", func_body_contains, 0 }, - { "date-sent", func_date_sent, 0 }, - { "match-all", (ESExpFunc *)func_match_all, 1 }, - { "header-contains", func_header_contains, 0 }, -}; - -int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, - CamelSearchFunc *func, void *data, CamelException *ex) -{ - int i; - struct _searchcontext *ctx; - GList *matches = NULL; - ESExp *f; - ESExpResult *r; - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - - /* setup our expression evaluator */ - f = e_sexp_new(); - - ctx = g_malloc0(sizeof(*ctx)); - - ctx->id = ((CamelMboxFolder *)folder)->search_id++; - - /* setup out context */ - ctx->folder = folder; - ctx->summary = mbox_folder->summary; - - if (ctx->summary == NULL || camel_exception_get_id (ex)) { - printf ("Cannot get summary\n" - "Full description : %s\n", camel_exception_get_description (ex)); - g_free(ctx); - gtk_object_unref((GtkObject *)f); - return -1; - } - - /* FIXME: the index should be global to the folder */ - ctx->message_current = NULL; - ctx->index = CAMEL_MBOX_FOLDER(folder)->index; - if (!ctx->index) { - g_warning("No folder index, searches will not function fully"); - } - - ((CamelMboxFolder *)folder)->searches = g_list_append(((CamelMboxFolder *)folder)->searches, ctx); - - for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) { - if (symbols[i].type == 1) { - e_sexp_add_ifunction(f, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, ctx); - } else { - e_sexp_add_function(f, 0, symbols[i].name, symbols[i].func, ctx); - } - } - - e_sexp_input_text(f, expression, strlen(expression)); - e_sexp_parse(f); - r = e_sexp_eval(f); - - /* now create a folder summary to return?? */ - if (r - && r->type == ESEXP_RES_ARRAY_PTR) { - d(printf("got result ...\n")); - for (i=0;i<r->value.ptrarray->len;i++) { - d(printf("adding match: %s\n", (char *)g_ptr_array_index(r->value.ptrarray, i))); - matches = g_list_prepend(matches, g_strdup(g_ptr_array_index(r->value.ptrarray, i))); - } - if (!ctx->cancelled) { - func(folder, ctx->id, TRUE, matches, data); - } - g_list_free(matches); - e_sexp_result_free(r); - } else { - printf("no result!\n"); - } - - gtk_object_unref((GtkObject *)f); - i = ctx->id; - - ((CamelMboxFolder *)folder)->searches = g_list_remove(((CamelMboxFolder *)folder)->searches, ctx); - - g_free(ctx); - - return i; -} - -static struct _searchcontext * -find_context(CamelMboxFolder *f, int id) -{ - struct _searchcontext *ctx; - GList *l; - - l = f->searches; - while (l) { - ctx = l->data; - if (ctx->id == id) { - return ctx; - } - l = g_list_next(l); - } - - return NULL; -} - -gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, int wait, CamelException *ex) -{ - struct _searchcontext *ctx; - - ctx = find_context((CamelMboxFolder *)folder, searchid); - - if (ctx) - return ctx->cancelled; - - /* if its been removed, its complete ... */ - return TRUE; -} - -void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex) -{ - struct _searchcontext *ctx; - - ctx = find_context((CamelMboxFolder *)folder, searchid); - if (ctx) { - ctx->cancelled = TRUE; - return; - } - - /* FIXME: set exception, return */ -} - -#else /* HAVE_FILTER */ - -int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, - CamelSearchFunc *func, void *data, CamelException *ex) -{ - return -1; -} - -gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, int wait, CamelException *ex) -{ - return TRUE; -} - -void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex) -{ - /* empty */ -} - -#endif /*! HAVE_FILTER */ diff --git a/camel/providers/mbox/camel-mbox-search.h b/camel/providers/mbox/camel-mbox-search.h deleted file mode 100644 index d3fe328a2c..0000000000 --- a/camel/providers/mbox/camel-mbox-search.h +++ /dev/null @@ -1,14 +0,0 @@ - -#ifndef _CAMEL_MBOX_SEARCH_H -#define _CAMEL_MBOX_SEARCH_H - -#include <glib.h> -#include "camel-mbox-folder.h" - -int camel_mbox_folder_search_by_expression(CamelFolder *folder, const char *expression, - CamelSearchFunc *func, void *data, CamelException *ex); -gboolean camel_mbox_folder_search_complete(CamelFolder *folder, int searchid, gboolean wait, CamelException *ex); -void camel_mbox_folder_search_cancel(CamelFolder *folder, int searchid, CamelException *ex); - -#endif /* ! _CAMEL_MBOX_SEARCH_H */ - diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c deleted file mode 100644 index 8db2f9338e..0000000000 --- a/camel/providers/mbox/camel-mbox-store.c +++ /dev/null @@ -1,129 +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 "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 CamelFolder *get_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); - - /* virtual method overload */ - camel_store_class->get_folder = get_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, CamelException *ex) -{ - CamelMboxFolder *new_mbox_folder; - CamelFolder *new_folder; - - new_mbox_folder = gtk_type_new (CAMEL_MBOX_FOLDER_TYPE); - new_folder = CAMEL_FOLDER (new_mbox_folder); - - /* XXX We shouldn't be passing NULL here, but it's equivalent to - * what was there before, and there's no - * CamelMboxFolder::get_subfolder yet anyway... - */ - CF_CLASS (new_folder)->init (new_folder, store, NULL, - folder_name, '/', ex); - - return new_folder; -} - -static char * -get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex) -{ - return g_strdup (folder_name); -} 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 22060bf8fe..0000000000 --- a/camel/providers/mbox/camel-mbox-summary.c +++ /dev/null @@ -1,1260 +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 Library 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 Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/uio.h> - -#include <stdio.h> -#include <string.h> - -#include <gtk/gtk.h> - -#include <camel/camel-mime-parser.h> -#include <camel/camel-mime-filter.h> -#include <camel/camel-mime-filter-basic.h> -#include <camel/camel-mime-filter-charset.h> -#include <camel/camel-mime-filter-index.h> - -#include <camel/camel-mime-utils.h> - -#include "camel-mbox-summary.h" - -#include <errno.h> -#include <ctype.h> -#include <netinet/in.h> - -#define d(x) - -#define CAMEL_MBOX_SUMMARY_VERSION 2 - -static int safe_write(int fd, char *buffer, size_t towrite); -static void camel_mbox_summary_add(CamelMboxSummary *s, CamelMboxMessageInfo *info); - -/* - Disk file format? - - message uid -message-block - date: - date received? - - subject: (unicode encoded) - from: (unicode encoded) - to: (unicode) - - content-block - -content-block - content-type: ; params; - content-id: - content-description: - content-transfer-encoding: - message-start: - header-size: - body-size: - - message-block - multipart-block - - */ - -/* pah, i dont care, its almost no code and it works, dont need a glist */ -struct _node { - struct _node *next; -}; - -static struct _node * -my_list_append(struct _node **list, struct _node *n) -{ - struct _node *ln = (struct _node *)list; - while (ln->next) - ln = ln->next; - n->next = 0; - ln->next = n; - return n; -} - -static int -my_list_size(struct _node **list) -{ - int len = 0; - struct _node *ln = (struct _node *)list; - while (ln->next) { - ln = ln->next; - len++; - } - return len; -} - -/* low-level io functions */ -static int -encode_int (FILE *out, gint32 value) -{ - int i; - - for (i=28;i>0;i-=7) { - if (value >= (1<<i)) { - unsigned int c = (value>>i) & 0x7f; - if (fputc(c, out) == -1) - return -1; - } - } - return fputc(value | 0x80, out); -} - -static gint32 -decode_int (FILE *in) -{ - gint32 value=0, v; - - /* until we get the last byte, keep decoding 7 bits at a time */ - while ( ((v = fgetc(in)) & 0x80) == 0 && v!=EOF) { - value |= v; - value <<= 7; - } - value |= (v&0x7f); - return value; -} - -static int -encode_fixed_int (FILE *out, gint32 value) -{ - guint32 save; - - save = htonl(value); - return fwrite(&save, sizeof(save), 1, out); -} - -static gint32 -decode_fixed_int (FILE *out) -{ - guint32 save; - - if (fread(&save, sizeof(save), 1, out) != -1) { - return ntohl(save); - } else { - return -1; - } -} - -/* should be sorted, for binary search */ -/* This is a tokenisation mechanism for strings written to the - summary - to save space. - This list can have at most 31 words. */ -static char * tokens[] = { - "7bit", - "8bit", - "alternative", - "application", - "base64", - "boundary", - "charset", - "filename", - "html", - "image", - "iso-8859-1", - "iso-8859-8", - "message", - "mixed", - "multipart", - "name", - "octet-stream", - "parallel", - "plain", - "quoted-printable", - "rfc822", - "text", - "us-ascii", /* 23 words */ -}; - -#define tokens_len (sizeof(tokens)/sizeof(tokens[0])) - -/* baiscally ... - 0 = null - 1-tokens_len == tokens[id-1] - >=32 string, length = n-32 -*/ - -static int -encode_string (FILE *out, char *str) -{ - if (str == NULL) { - return encode_int(out, 0); - } else { - int len = strlen(str); - int i, token=-1; - - if (len <= 16) { - char lower[32]; - - for (i=0;i<len;i++) - lower[i] = tolower(str[i]); - lower[i] = 0; - for (i=0;i<tokens_len;i++) { - if (!strcmp(tokens[i], lower)) { - token = i; - break; - } - } - } - if (token != -1) { - return encode_int(out, token+1); - } else { - if (encode_int(out, len+32) == -1) - return -1; - return fwrite(str, len, 1, out); - } - } - return 0; -} - -static char * -decode_string (FILE *in) -{ - char *ret; - int len; - - len = decode_int(in); - - if (len<32) { - if (len <= 0) { - ret = NULL; - } else if (len<= tokens_len) { - ret = g_strdup(tokens[len-1]); - } else { - g_warning("Invalid token encountered: %d", len); - ret = NULL; - } - } else if (len > 10240) { - g_warning("Got broken string header length: %d bytes", len); - ret = NULL; - } else { - len -= 32; - ret = g_malloc(len+1); - if (fread(ret, len, 1, in) == -1) { - g_free(ret); - return NULL; - } - ret[len]=0; - } - - return ret; -} - - - -/* allocation functions */ - -static void -body_part_dump(CamelMboxMessageContentInfo *bs, int depth) -{ - CamelMboxMessageContentInfo *c; - char *prefix; - - if (bs == NULL) - return; - - prefix = alloca(depth*2+1); - memset(prefix, ' ', depth*2); - prefix[depth*2]=0; - printf("%scontent-range: %d %d %d\n", prefix, (int)bs->pos, (int)bs->bodypos, (int)bs->endpos); - printf("%scontent-type: %s/%s\n", prefix, bs->info.type?bs->info.type->type:"?", bs->info.type?bs->info.type->subtype:"?"); - printf("%scontent-id: %s\n", prefix, bs->info.id); - printf("%scontent-description: %s\n", prefix, bs->info.description); - printf("%scontent-transfer-encoding: %s\n", prefix, bs->info.encoding); - c = (CamelMboxMessageContentInfo *)bs->info.childs; - while (c) { - printf("%s -- \n", prefix); - body_part_dump(c, depth+1); - c = (CamelMboxMessageContentInfo *)c->info.next; - } -} - -static void -message_struct_dump(CamelMboxMessageInfo *ms) -{ - char *tmp; - - if (ms == NULL) { - printf("Empty message?\n"); - return; - } - - printf("Subject: %s\n", ms->info.subject); - printf("From: %s\n", ms->info.from); - printf("To: %s\n", ms->info.to); - tmp = header_format_date(ms->info.date_sent, 0); - printf("Date: %s\n", tmp); - g_free(tmp); - tmp = header_format_date(ms->info.date_received, 0); - printf("Date-Received: %s\n", tmp); - g_free(tmp); - printf("UID: %08x-%04x\n", atoi(ms->info.uid), ms->info.flags); - printf(" -- content ->\n"); - body_part_dump((CamelMboxMessageContentInfo *)ms->info.content, 1); -} - -static CamelMboxMessageContentInfo * -body_part_new(CamelMimeParser *mp, CamelMboxMessageContentInfo *parent, int start, int body) -{ - CamelMboxMessageContentInfo *bs; - - bs = g_malloc0(sizeof(*bs)); - - bs->info.parent = (CamelMessageContentInfo *)parent; - - bs->info.type = camel_mime_parser_content_type(mp); - header_content_type_ref(bs->info.type); - - bs->info.id = header_msgid_decode(camel_mime_parser_header(mp, "content-id", NULL)); - bs->info.description = header_decode_string(camel_mime_parser_header(mp, "content-description", NULL)); - bs->info.encoding = header_content_encoding_decode(camel_mime_parser_header(mp, "content-transfer-encoding", NULL)); - - /* not sure what to set here? */ - bs->pos = start; - bs->bodypos = body; - bs->endpos = -1; - - if (parent) - my_list_append((struct _node **)&parent->info.childs, (struct _node *)bs); - - return bs; -} - -static CamelMboxMessageInfo * -message_struct_new(CamelMimeParser *mp, CamelMboxMessageContentInfo *parent, int start, int body, off_t xev_offset) -{ - CamelMboxMessageInfo *ms; - - ms = g_malloc0(sizeof(*ms)); - - /* FIXME: what about cc, sender vs from? */ - ms->info.subject = header_decode_string(camel_mime_parser_header(mp, "subject", NULL)); - ms->info.from = g_strdup(camel_mime_parser_header(mp, "from", NULL)); - ms->info.to = g_strdup(camel_mime_parser_header(mp, "to", NULL)); - - ms->info.date_sent = header_decode_date(camel_mime_parser_header(mp, "date", NULL), NULL); - ms->info.date_received = 0; - - ms->info.content = (CamelMessageContentInfo *)body_part_new(mp, parent, start, body); - ms->xev_offset = xev_offset; - return ms; -} - -static void -body_part_free(CamelMboxMessageContentInfo *bs) -{ - CamelMboxMessageContentInfo *c, *cn; - - c = (CamelMboxMessageContentInfo *)bs->info.childs; - while (c) { - cn = (CamelMboxMessageContentInfo *)c->info.next; - body_part_free(c); - c = cn; - } - g_free(bs->info.id); - g_free(bs->info.description); - g_free(bs->info.encoding); - header_content_type_unref(bs->info.type); - g_free(bs); -} - -static void -message_struct_free(CamelMboxMessageInfo *ms) -{ - g_free(ms->info.subject); - g_free(ms->info.to); - g_free(ms->info.from); - body_part_free((CamelMboxMessageContentInfo *)ms->info.content); - g_free(ms); -} - - -/* IO functions */ -static CamelMboxMessageContentInfo * -body_part_load(FILE *in) -{ - CamelMboxMessageContentInfo *bs = NULL, *c; - struct _header_content_type *ct; - char *type; - char *subtype; - int i, count; - - d(printf("got content-block\n")); - bs = g_malloc0(sizeof(*bs)); - bs->pos = decode_int(in); - bs->bodypos = bs->pos + decode_int(in); - bs->endpos = bs->pos + decode_int(in); - - /* do content type */ - d(printf("got content-type\n")); - type = decode_string(in); - subtype = decode_string(in); - - ct = header_content_type_new(type, subtype); - bs->info.type = ct; - count = decode_int(in); - d(printf("getting %d params\n", count)); - for (i=0;i<count;i++) { - char *name = decode_string(in); - char *value = decode_string(in); - - d(printf(" %s = \"%s\"\n", name, value)); - - header_content_type_set_param(ct, name, value); - /* FIXME: do this so we dont have to double alloc/free */ - g_free(name); - g_free(value); - } - - d(printf("got content-id\n")); - bs->info.id = decode_string(in); - d(printf("got content-description\n")); - bs->info.description = decode_string(in); - d(printf("got content-encoding\n")); - bs->info.encoding = decode_string(in); - - count = decode_int(in); - d(printf("got children, %d\n", count)); - for (i=0;i<count;i++) { - c = body_part_load(in); - if (c) { - my_list_append((struct _node **)&bs->info.childs, (struct _node *)c); - c->info.parent = (CamelMessageContentInfo *)bs; - } else { - printf("Cannot load child\n"); - } - } - - return bs; -} - -static int -body_part_save(FILE *out, CamelMboxMessageContentInfo *bs) -{ - CamelMboxMessageContentInfo *c, *cn; - struct _header_content_type *ct; - struct _header_param *hp; - - encode_int(out, bs->pos); - encode_int(out, bs->bodypos - bs->pos); - encode_int(out, bs->endpos - bs->pos); - - ct = bs->info.type; - if (ct) { - encode_string(out, ct->type); - encode_string(out, ct->subtype); - encode_int(out, my_list_size((struct _node **)&ct->params)); - hp = ct->params; - while (hp) { - encode_string(out, hp->name); - encode_string(out, hp->value); - hp = hp->next; - } - } else { - encode_string(out, NULL); - encode_string(out, NULL); - encode_int(out, 0); - } - encode_string(out, bs->info.id); - encode_string(out, bs->info.description); - encode_string(out, bs->info.encoding); - - encode_int(out, my_list_size((struct _node **)&bs->info.childs)); - - c = (CamelMboxMessageContentInfo *)bs->info.childs; - while (c) { - cn = (CamelMboxMessageContentInfo *)c->info.next; - body_part_save(out, c); - c = cn; - } - - return 0; -} - -static CamelMboxMessageInfo * -message_struct_load(FILE *in) -{ - CamelMboxMessageInfo *ms; - - ms = g_malloc0(sizeof(*ms)); - - ms->info.uid = g_strdup_printf("%u", decode_int(in)); - ms->info.flags = decode_int(in); - ms->info.date_sent = decode_int(in); - ms->info.date_received = decode_int(in); - ms->xev_offset = decode_int(in); - ms->info.subject = decode_string(in); - ms->info.from = decode_string(in); - ms->info.to = decode_string(in); - ms->info.content = (CamelMessageContentInfo *)body_part_load(in); - - return ms; -} - -static int -message_struct_save(FILE *out, CamelMboxMessageInfo *ms) -{ - encode_int(out, strtoul(ms->info.uid, NULL, 10)); - encode_int(out, ms->info.flags); - encode_int(out, ms->info.date_sent); - encode_int(out, ms->info.date_received); - encode_int(out, ms->xev_offset); - encode_string(out, ms->info.subject); - encode_string(out, ms->info.from); - encode_string(out, ms->info.to); - body_part_save(out, (CamelMboxMessageContentInfo *)ms->info.content); - - return 0; -} - -static unsigned int -header_evolution_decode(const char *in, unsigned int *uid, unsigned int *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 ~0; -} - -static int -safe_write(int fd, char *buffer, size_t towrite) -{ - size_t donelen; - size_t len; - - donelen = 0; - while (donelen < towrite) { - len = write(fd, buffer + donelen, towrite - donelen); - if (len == -1) { - if (errno == EINTR || errno == EAGAIN) - continue; - return -1; - } - donelen += len; - } - return donelen; -} - -static int -header_write(int fd, struct _header_raw *header, unsigned int uid, unsigned int flags) -{ - struct iovec iv[4]; - int outlen = 0; - - 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")) { - int len; - - 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; - } - - return outlen; -} - -/* returns -1 on error, else number of bytes written */ -int -camel_mbox_summary_copy_block(int fromfd, int tofd, off_t readpos, size_t bytes) -{ - char buffer[4096]; - int written = 0; - off_t pos, newpos; - - pos = lseek(fromfd, 0, SEEK_CUR); - if (pos == -1) - return -1; - - newpos = lseek(fromfd, readpos, SEEK_SET); - if (newpos == -1 || newpos != readpos) - goto error; - - d(printf("oldpos = %d; copying %d from %d\n", (int)pos, (int)bytes, (int)readpos)); - - while (bytes>0) { - int toread, towrite, donelen; - - toread = bytes; - if (bytes>4096) - toread = 4096; - else - toread = bytes; - reread: - towrite = read(fromfd, buffer, toread); - if (towrite == -1) { - if (errno == EINTR || errno == EAGAIN) - goto reread; - goto error; - } - - /* check for 'end of file' */ - if (towrite == 0) - break; - - if ( (donelen = safe_write(tofd, buffer, towrite)) == -1) - goto error; - - written += donelen; - bytes -= donelen; - } - - d(printf("written %d bytes\n", written)); - - newpos = lseek(fromfd, pos, SEEK_SET); - if (newpos == -1 || newpos != pos); - return -1; - - return written; - -error: - lseek(fromfd, pos, SEEK_SET); - return -1; -} - -#define SAVEIT - -static int index_folder(CamelMboxSummary *s, int startoffset) -{ - CamelMimeParser *mp; - int fd; - int fdout; - int state; - - int toplevel = FALSE; - const char *xev; - char *data; - int datalen; - - int enc_id=-1; - int chr_id=-1; - int idx_id=-1; - struct _header_content_type *ct; - int doindex=FALSE; - CamelMimeFilterCharset *mfc = NULL; - CamelMimeFilterIndex *mfi = NULL; - CamelMimeFilterBasic *mf64 = NULL, *mfqp = NULL; - - CamelMboxMessageContentInfo *body = NULL, *parent = NULL; - CamelMboxMessageInfo *message = NULL; - - int from_end = 0; /* start of message */ - int from = 0; /* start of headers */ - int last_write = 0; /* last written position */ - int eof; - int write_offset = 0; /* how much does the dest differ from the source pos */ - int old_offset = 0; - - guint32 newuid; - off_t xevoffset = -1; - - char *tmpname; - - printf("indexing %s (%s) from %d\n", s->folder_path, s->summary_path, startoffset); - - fd = open(s->folder_path, O_RDONLY); - if (fd==-1) { - perror("Can't open folder"); - return -1; - } - - tmpname = g_strdup_printf("%s.tmp", s->folder_path); - - fdout = open(tmpname, O_WRONLY|O_CREAT|O_TRUNC, 0600); - if (fdout==-1) { - perror("Can't open output"); - g_free(tmpname); - return -1; - } - - mp = camel_mime_parser_new(); - camel_mime_parser_init_with_fd(mp, fd); - camel_mime_parser_scan_from(mp, TRUE); - - /* FIXME: cleaner fail code */ - if (startoffset > 0) { - if (camel_mime_parser_seek(mp, startoffset, SEEK_SET) != startoffset) { - g_free(tmpname); - gtk_object_unref((GtkObject *)mp); - return -1; - } - } - - mfi = camel_mime_filter_index_new_ibex(s->index); - - while ( (state = camel_mime_parser_step(mp, &data, &datalen)) != HSCAN_EOF ) { - switch(state) { - case HSCAN_FROM: /* starting a new message content */ - /* save the current position */ - d(printf("from = %d\n", (int)camel_mime_parser_tell(mp))); - toplevel = FALSE; - from = camel_mime_parser_tell(mp); - break; - - case HSCAN_FROM_END: - d(printf("from-end = %d\n", (int)camel_mime_parser_tell(mp))); - d(printf("message from %d to %d\n", from_end, (int)camel_mime_parser_tell(mp))); - from_end = camel_mime_parser_tell(mp); - break; - - case HSCAN_MESSAGE: - case HSCAN_MULTIPART: - case HSCAN_HEADER: /* starting a new header */ - newuid=~0; - if (!toplevel) { - char name[32]; - unsigned int olduid, oldflags; - int headerlen; - int docopy = FALSE; - - /* check for X-Evolution header ... if its there, nothing to do (skip content) */ - xev = camel_mime_parser_header(mp, "x-evolution", &xevoffset); - if (xev) { - d(printf("An x-evolution header exists at: %d = %s\n", xevoffset + write_offset, xev)); - xevoffset = xevoffset + write_offset; - if (header_evolution_decode(xev, &olduid, &oldflags) != ~0) { - d(printf(" uid = %d = %x\n", olduid, olduid)); - newuid = olduid; -#if 0 - while (camel_mime_parser_step(mp, &data, &datalen) != HSCAN_FROM_END) - ; - break; -#endif - } else { - printf("Invalid xev header? I need to write out a new one ...\n"); - } - } - - toplevel = TRUE; - - /* assign a new uid for this message */ - if (newuid == ~0) { - newuid = s->nextuid++; - docopy = TRUE; - } else { - /* make sure we account for this uid when assigning uid's */ - /* this really needs a pre-scan pass ... *sigh* */ - camel_mbox_summary_set_uid(s, newuid); - } - - /* setup index name for this uid */ - sprintf(name, "%x", newuid); - camel_mime_filter_index_set_name(mfi, name); - /* remove all references to this name from the index */ - if (s->index) - ibex_unindex(s->index, name); - - d(printf("Message content starts at %d\n", camel_mime_parser_tell(mp))); - - if (docopy) { - /* now, copy over bits of mbox from last write, and insert the X-Evolution header (at the top of headers) */ - /* if we already have a valid x-evolution header, use that, dont need to copy */ - camel_mbox_summary_copy_block(fd, fdout, last_write, from-last_write); - last_write = from; - - headerlen = header_write(fdout, camel_mime_parser_headers_raw(mp), newuid, 0); - sprintf(name, "X-Evolution: %08x-%04x\n\n", newuid, 0); - safe_write(fdout, name, strlen(name)); - d(printf("new X-Evolution at %d\n", headerlen + from + write_offset)); - xevoffset = headerlen + from + write_offset; - old_offset = write_offset; - - write_offset += (headerlen - (camel_mime_parser_tell(mp)-from)) + strlen(name); - last_write = camel_mime_parser_tell(mp); - } - } else { - old_offset = write_offset; - } - - /* we only care about the rest for actual content parts */ - /* TODO: Cleanup, this is a huge mess */ - if (state != HSCAN_HEADER) { - if (message == NULL) { - message = message_struct_new(mp, parent, camel_mime_parser_tell_start_headers(mp)+old_offset, camel_mime_parser_tell(mp)+write_offset, xevoffset); - parent = (CamelMboxMessageContentInfo *)message->info.content; - if (newuid != ~0) { - message->info.uid = g_strdup_printf("%u", newuid); - } else { - g_warning("This shouldn't happen?"); - } - } else { - parent = body_part_new(mp, parent, camel_mime_parser_tell_start_headers(mp)+old_offset, camel_mime_parser_tell(mp)+write_offset); - } - break; - } - - if (message == NULL) { - message = message_struct_new(mp, parent, camel_mime_parser_tell_start_headers(mp)+old_offset, camel_mime_parser_tell(mp)+write_offset, xevoffset); - body = (CamelMboxMessageContentInfo *)message->info.content; - if (newuid != ~0) { - message->info.uid = g_strdup_printf("%u", newuid); - } else { - g_warning("This shouldn't happen?"); - } - } else { - body = body_part_new(mp, parent, camel_mime_parser_tell_start_headers(mp)+old_offset, camel_mime_parser_tell(mp)+write_offset); - } - - /* check headers for types that we can index */ - ct = camel_mime_parser_content_type(mp); - if (header_content_type_is(ct, "text", "*")) { - char *encoding; - const char *charset; - - /* TODO: The filters should all be cached, so they aren't recreated between - messages/message parts */ - encoding = header_content_encoding_decode(camel_mime_parser_header(mp, "content-transfer-encoding", NULL)); - if (encoding) { - if (!strcasecmp(encoding, "base64")) { - d(printf("Adding decoding filter for base64\n")); - if (mf64 == NULL) - mf64 = camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_BASE64_DEC); - enc_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)mf64); - } else if (!strcasecmp(encoding, "quoted-printable")) { - d(printf("Adding decoding filter for quoted-printable\n")); - if (mfqp == NULL) - mfqp = camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_QP_DEC); - enc_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)mfqp); - } - g_free(encoding); - } - - charset = header_content_type_param(ct, "charset"); - if (charset!=NULL - && !(strcasecmp(charset, "us-ascii")==0 - || strcasecmp(charset, "utf-8")==0)) { - d(printf("Adding conversion filter from %s to utf-8\n", charset)); - if (mfc == NULL) - mfc = camel_mime_filter_charset_new_convert(charset, "utf-8"); - if (mfc) { - chr_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)mfc); - } else { - g_warning("Cannot convert '%s' to 'utf-8', message display may be corrupt", charset); - } - } - - doindex = TRUE; - - /* and this filter actually does the indexing */ - idx_id = camel_mime_parser_filter_add(mp, (CamelMimeFilter *)mfi); - } else { - doindex = FALSE; - } - break; - - /* fixme, this needs thought *sigh* */ - case HSCAN_MESSAGE_END: - case HSCAN_MULTIPART_END: - if (parent) { - parent->endpos = camel_mime_parser_tell(mp)+write_offset; - if (parent->info.parent == NULL) { - camel_mbox_summary_add(s, message); - message = NULL; - parent = NULL; - } else { - parent = (CamelMboxMessageContentInfo *)parent->info.parent; - } - } - break; - - case HSCAN_BODY: - if (doindex) { - d(printf("Got content to index:\n%.*s", datalen, data)); - } - break; - - case HSCAN_BODY_END: - if (body) { - body->endpos = camel_mime_parser_tell(mp)+write_offset; - if (body->info.parent == NULL) { - camel_mbox_summary_add(s, message); - message = NULL; - } - } - - d(printf("end of content, removing decoders\n")); - if (enc_id != -1) { - camel_mime_parser_filter_remove(mp, enc_id); - enc_id = -1; - } - if (chr_id != -1) { - camel_mime_parser_filter_remove(mp, chr_id); - chr_id = -1; - } - if (idx_id != -1) { - camel_mime_parser_filter_remove(mp, idx_id); - idx_id = -1; - } - break; - } - } - - /* did we actually write anything out? Then rename and be done with it. */ - if (last_write>0) { - eof = camel_mime_parser_tell(mp); - camel_mbox_summary_copy_block(fd, fdout, last_write, eof-last_write); - - if (close(fdout) == -1) { - perror("Could not close output file"); - unlink(tmpname); - } else { - printf("renaming %s to %s\n", tmpname, s->folder_path); - if (rename(tmpname, s->folder_path) == -1) { - perror("Error renaming file"); - unlink(tmpname); - } - } - } else { - /* no, then dont bother touching the inbox */ - printf("No written changes to mbox, removing tmp file\n"); - close(fdout); - unlink(tmpname); - } - - close(fd); - - if (mf64) gtk_object_unref((GtkObject *)mf64); - if (mfqp) gtk_object_unref((GtkObject *)mfqp); - if (mfc) gtk_object_unref((GtkObject *)mfc); - if (mfi) gtk_object_unref((GtkObject *)mfi); - - /* force an index sync? */ - if (s->index) { - ibex_write(s->index); - } - - gtk_object_unref((GtkObject *)mp); - - /* and finally ... update the summary sync info */ - { - struct stat st; - - if (stat(s->folder_path, &st) == 0) { - s->time = st.st_mtime; - s->size = st.st_size; - } - } - - g_free(tmpname); - - return 0; -} - -CamelMboxSummary *camel_mbox_summary_new(const char *summary, const char *folder, ibex *index) -{ - CamelMboxSummary *s; - - s = g_malloc0(sizeof(*s)); - - s->dirty = TRUE; - s->folder_path = g_strdup(folder); - s->summary_path = g_strdup(summary); - /* FIXME: refcount index? */ - s->index = index; - - s->messages = g_ptr_array_new(); - s->message_uid = g_hash_table_new(g_str_hash, g_str_equal); - - /* always force an update */ - s->time = 0; - s->size = 0; - - s->nextuid = 1; - - /* TODO: force an initial load right now? */ - - return s; -} - -void camel_mbox_summary_unref(CamelMboxSummary *s) -{ - g_warning("Unimplemented function, mbox_summary_unref"); -} - -/* check that the summary is uptodate, TRUE means it is uptodate */ -int camel_mbox_summary_check(CamelMboxSummary *s) -{ - struct stat st; - - /* no folder at all? */ - if (stat(s->folder_path, &st) != 0) - return FALSE; - - return (st.st_size == s->size) && (st.st_mtime == s->time); -} - -static void camel_mbox_summary_add(CamelMboxSummary *s, CamelMboxMessageInfo *info) -{ - if (info->info.uid == NULL) { - info->info.uid = g_strdup_printf("%u", s->nextuid++); - } - if (g_hash_table_lookup(s->message_uid, info->info.uid)) { - g_error("Trying to insert message with clashing uid's"); - } - d(printf("adding %s\n", info->info.uid)); - g_ptr_array_add(s->messages, info); - g_hash_table_insert(s->message_uid, info->info.uid, info); - s->dirty = TRUE; -} - -static int summary_header_read(FILE *fp, guint32 *version, time_t *time, size_t *size, guint32 *nextuid) -{ - fseek(fp, 0, SEEK_SET); - *version = decode_fixed_int(fp); - *time = decode_fixed_int(fp); - *size = decode_fixed_int(fp); - *nextuid = decode_fixed_int(fp); - return ferror(fp); -} - -static void -summary_clear(CamelMboxSummary *s) -{ - int i; - - for (i=0;i<s->messages->len;i++) { - message_struct_free(g_ptr_array_index(s->messages, i)); - } - g_ptr_array_free(s->messages, TRUE); - g_hash_table_destroy(s->message_uid); - - s->messages = g_ptr_array_new(); - s->message_uid = g_hash_table_new(g_str_hash, g_str_equal); -} - -int camel_mbox_summary_load(CamelMboxSummary *s) -{ - struct stat st; - FILE *fp; - int i, total; - CamelMboxMessageInfo *info; - - summary_clear(s); - - if ((fp = fopen(s->summary_path, "r")) == NULL) { - g_warning("Loading non-existant summary, generating summary for folder: %s: %s", s->summary_path, strerror(errno)); - index_folder(s, 0); - camel_mbox_summary_save(s); - } else { - guint32 version, nextuid; - time_t time; - size_t size; - - if (stat(s->folder_path, &st) != 0) { - g_warning("Uh, no folder anyway, aborting"); - fclose(fp); - return -1; - } - - if (summary_header_read(fp, &version, &time, &size, &nextuid) != 0 - || version != CAMEL_MBOX_SUMMARY_VERSION) { - g_warning("Summary missing or version mismatch, reloading summary"); - fclose(fp); - index_folder(s, 0); - camel_mbox_summary_save(s); - return 0; - } - - s->nextuid = MAX(s->nextuid, nextuid); - s->time = time; - s->size = size; - total = decode_fixed_int(fp); - - if (time != st.st_mtime || size != st.st_size) { - /* if its grown, then just index the new stuff, and load the rest from the summary */ - if (size < st.st_size) { - g_warning("Indexing/summarizing from start position: %d", size); - - d(printf("loading %d items from summary file\n", total)); - for (i=0;i<total;i++) { - info = message_struct_load(fp); - if (info) { - camel_mbox_summary_add(s, info); - } else { - break; - } - } - fclose(fp); - s->dirty = FALSE; - index_folder(s, size); /* if it adds any, it'll dirtify it */ - camel_mbox_summary_save(s); - } else { - g_warning("Folder changed/smaller, reindexing everything"); - index_folder(s, 0); - camel_mbox_summary_save(s); - fclose(fp); - } - return 0; - } - - printf("loading %d items from summary file\n", total); - for (i=0;i<total;i++) { - info = message_struct_load(fp); - if (info) { - camel_mbox_summary_add(s, info); - } else { - break; - } - } - fclose(fp); - s->dirty = FALSE; - } - return 0; -} - -static int summary_header_write(FILE *fp, CamelMboxSummary *s) -{ - fseek(fp, 0, SEEK_SET); - encode_fixed_int(fp, CAMEL_MBOX_SUMMARY_VERSION); - encode_fixed_int(fp, s->time); - /* if we're dirty, then dont *really* save it ... */ - if (s->dirty) - encode_fixed_int(fp, 0); - else - encode_fixed_int(fp, s->size); - encode_fixed_int(fp, s->nextuid); - fflush(fp); - return ferror(fp); -} - -static int summary_header_save(CamelMboxSummary *s) -{ - int fd; - FILE *fp; - - fd = open(s->summary_path, O_WRONLY|O_CREAT, 0600); - if (fd == -1) - return -1; - fp = fdopen(fd, "w"); - if (fp == NULL) - return -1; - - summary_header_write(fp, s); - return fclose(fp); -} - -int camel_mbox_summary_save(CamelMboxSummary *s) -{ - int i, fd; - FILE *fp; - - printf("saving summary? %s\n", s->summary_path); - - /* FIXME: error checking */ - if (s->dirty) { - printf("yes\n"); - fd = open(s->summary_path, O_WRONLY|O_CREAT|O_TRUNC, 0600); - if (fd == -1) - return -1; - fp = fdopen(fd, "w"); - if (fp == NULL) - return -1; - - s->dirty = FALSE; - - summary_header_write(fp, s); - encode_fixed_int(fp, s->messages->len); - - printf("message count = %d\n", s->messages->len); - - for (i=0;i<s->messages->len;i++) { - message_struct_save(fp, g_ptr_array_index(s->messages, i)); - } - fclose(fp); - } else { - printf("no\n"); - } - return 0; -} - -CamelMboxMessageInfo *camel_mbox_summary_uid(CamelMboxSummary *s, const char *uid) -{ - return g_hash_table_lookup(s->message_uid, uid); -} - -CamelMboxMessageInfo *camel_mbox_summary_index(CamelMboxSummary *s, int index) -{ - return g_ptr_array_index(s->messages, index); -} - -int camel_mbox_summary_message_count(CamelMboxSummary *s) -{ - return s->messages->len; -} - -guint32 camel_mbox_summary_next_uid(CamelMboxSummary *s) -{ - guint32 uid = s->nextuid++; - - summary_header_save(s); - return uid; -} - -guint32 camel_mbox_summary_set_uid(CamelMboxSummary *s, guint32 uid) -{ - if (s->nextuid <= uid) { - s->nextuid = uid+1; - summary_header_save(s); - } - return s->nextuid; -} - -#if 0 -int main(int argc, char **argv) -{ - if (argc<2) { - printf("usage: %s mbox\n", argv[0]); - return 1; - } - - gtk_init(&argc, &argv); - - index_folder(argv[1]); - - return 0; -} -#endif diff --git a/camel/providers/mbox/camel-mbox-summary.h b/camel/providers/mbox/camel-mbox-summary.h deleted file mode 100644 index 80b59ef54f..0000000000 --- a/camel/providers/mbox/camel-mbox-summary.h +++ /dev/null @@ -1,78 +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 Library 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 Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef _CAMEL_MBOX_SUMMARY_H -#define _CAMEL_MBOX_SUMMARY_H - -#include <glib.h> -#include <camel/camel-folder.h> -#include <libibex/ibex.h> - -typedef struct { - CamelMessageContentInfo info; - - /* position in stream of this part */ - off_t pos; - off_t bodypos; - off_t endpos; -} CamelMboxMessageContentInfo; - -typedef struct { - CamelMessageInfo info; - - /* position of the xev header, if one exists */ - off_t xev_offset; -} CamelMboxMessageInfo; - -typedef struct { - int dirty; /* if anything has changed */ - - char *folder_path; - char *summary_path; - ibex *index; - - GPtrArray *messages; /* array of messages matching mbox order */ - GHashTable *message_uid; /* index to messages by uid */ - - int nextuid; - - time_t time; /* time/size of folder's last update */ - size_t size; -} CamelMboxSummary; - -CamelMboxSummary *camel_mbox_summary_new(const char *summary, const char *folder, ibex *index); -void camel_mbox_summary_unref(CamelMboxSummary *); - -int camel_mbox_summary_load(CamelMboxSummary *); -int camel_mbox_summary_save(CamelMboxSummary *); -int camel_mbox_summary_check(CamelMboxSummary *); - -guint32 camel_mbox_summary_next_uid(CamelMboxSummary *); -/* set the minimum uid */ -guint32 camel_mbox_summary_set_uid(CamelMboxSummary *s, guint32 uid); - -CamelMboxMessageInfo *camel_mbox_summary_uid(CamelMboxSummary *s, const char *uid); -CamelMboxMessageInfo *camel_mbox_summary_index(CamelMboxSummary *, int index); -int camel_mbox_summary_message_count(CamelMboxSummary *); - -/* TODO: should be in a utility library */ -int camel_mbox_summary_copy_block(int fromfd, int tofd, off_t readpos, size_t bytes); - -#endif /* ! _CAMEL_MBOX_SUMMARY_H */ diff --git a/camel/providers/nntp/.cvsignore b/camel/providers/nntp/.cvsignore deleted file mode 100644 index fd6b811c68..0000000000 --- a/camel/providers/nntp/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -Makefile -Makefile.in -.libs -.deps -*.lo -*.la diff --git a/camel/providers/nntp/Makefile.am b/camel/providers/nntp/Makefile.am deleted file mode 100644 index 2aabff29ef..0000000000 --- a/camel/providers/nntp/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelnntpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelnntp.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -I$(srcdir)/../mbox - -libcamelnntp_la_SOURCES = \ - camel-nntp-folder.c \ - camel-nntp-provider.c \ - camel-nntp-store.c \ - camel-nntp-summary.c \ - camel-nntp-utils.c - -libcamelnntpinclude_HEADERS = \ - camel-nntp-folder.h \ - camel-nntp-store.h \ - camel-nntp-summary.h - - -libcamelnntp_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - -EXTRA_DIST = diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c deleted file mode 100644 index 0c4ba1691d..0000000000 --- a/camel/providers/nntp/camel-nntp-folder.c +++ /dev/null @@ -1,686 +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-nntp-store.h" -#include "camel-nntp-folder.h" -#include "camel-nntp-store.h" -#include "camel-nntp-utils.h" -#include "camel-nntp-summary.h" - -#include "string-utils.h" -#include "camel-stream-mem.h" -#include "camel-stream-buffer.h" -#include "gmime-utils.h" -#include "camel-data-wrapper.h" -#include "camel-mime-message.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 _init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar separator, CamelException *ex); -static void _set_name(CamelFolder *folder, const gchar *name, CamelException *ex); - - -static void _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); -static void _close (CamelFolder *folder, gboolean expunge, 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_by_number (CamelFolder *folder, gint number, CamelException *ex); -static gint _get_message_count (CamelFolder *folder, CamelException *ex); -static void _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static GList *_get_uid_list (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex); -#if 0 -static void _expunge (CamelFolder *folder, CamelException *ex); -static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex); -#endif -static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); - -static void _finalize (GtkObject *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 = _init; - camel_folder_class->set_name = _set_name; - camel_folder_class->open = _open; - camel_folder_class->close = _close; - 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->list_subfolders = _list_subfolders; - camel_folder_class->get_message_by_number = _get_message_by_number; - camel_folder_class->get_message_count = _get_message_count; - camel_folder_class->get_uid_list = _get_uid_list; - camel_folder_class->get_message_by_uid = _get_message_by_uid; -#if 0 - camel_folder_class->append_message = _append_message; - camel_folder_class->expunge = _expunge; - camel_folder_class->copy_message_to = _copy_message_to; - camel_folder_class->get_message_uid = _get_message_uid; -#endif - - gtk_object_class->finalize = _finalize; - -} - - - -static void -_finalize (GtkObject *object) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (object); - - g_free (nntp_folder->summary_file_path); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - - - - - -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; -} - - - - - - -static void -_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, gchar separator, - CamelException *ex) -{ - /* call parent method */ - parent_class->init (folder, parent_store, parent_folder, - name, separator, ex); - if (camel_exception_get_id (ex)) return; - - /* we assume that the parent init - method checks for the existance of @folder */ - - if (!strcmp(name, "/")) - { - folder->has_summary_capability = FALSE; - folder->can_hold_messages = FALSE; - folder->can_hold_folders = TRUE; - } - else - { - folder->has_summary_capability = TRUE; - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - } - - folder->has_uid_capability = TRUE; - folder->has_search_capability = FALSE; - folder->summary = NULL; -} - - - -/* 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); - CamelNNTPSummary *summ = NULL; - GArray *message_info_array; - - folder->summary = NULL; - - /* Test for the existence and up-to-dateness of the summary file. */ - if (access (nntp_folder->summary_file_path, F_OK) == 0) { - summ = camel_nntp_summary_load (CAMEL_FOLDER(nntp_folder)->name, - nntp_folder->summary_file_path, ex); - if (summ) { - folder->summary = CAMEL_FOLDER_SUMMARY (summ); - } else { - /* Bad summary file */ - if (camel_exception_get_id (ex) != - CAMEL_EXCEPTION_FOLDER_SUMMARY_INVALID) - return; - camel_exception_clear (ex); - } - } - - /* In the case where the summary does not exist (or was the - * wrong version), or is not in sync with the nntp file, - * regenerate it. - */ - if (folder->summary == NULL) { - message_info_array = - camel_nntp_get_headers (CAMEL_FOLDER( folder )->parent_store, nntp_folder, ex); - if (camel_exception_get_id (ex)) - return; - - summ = CAMEL_NNTP_SUMMARY (gtk_object_new (camel_nntp_summary_get_type (), NULL)); - summ->message_info = message_info_array; - summ->nb_message = summ->message_info->len; - - folder->summary = CAMEL_FOLDER_SUMMARY (summ); - - camel_nntp_summary_save (summ, - nntp_folder->summary_file_path, ex); - } -} - - -static void -_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - - /* call parent class */ - parent_class->open (folder, mode, ex); - if (camel_exception_get_id(ex)) - return; - -#if 0 - /* get (or create) uid list */ - if (!(nntp_load_uid_list (nntp_folder) > 0)) - nntp_generate_uid_list (nntp_folder); -#endif - - _check_get_or_maybe_generate_summary_file (nntp_folder, ex); -} - - -static void -_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - CamelNNTPSummary *nntp_summary = CAMEL_NNTP_SUMMARY (folder->summary); - - /* call parent implementation */ - parent_class->close (folder, expunge, ex); - - camel_nntp_summary_save (nntp_summary, - nntp_folder->summary_file_path, ex); -} - - - - -static void -_set_name (CamelFolder *folder, const gchar *name, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - const gchar *root_dir_path; - - /* call default implementation */ - parent_class->set_name (folder, name, ex); - if (camel_exception_get_id (ex)) return; - - 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, folder->name); -} - - - - - - -static gboolean -_exists (CamelFolder *folder, CamelException *ex) -{ -#if 0 - CamelNNTPFolder *nntp_folder; - struct stat stat_buf; - gint stat_error; - gboolean exists; - - g_assert(folder != NULL); - - nntp_folder = CAMEL_NNTP_FOLDER (folder); - - /* check if the nntp summary path is determined */ - if (!nntp_folder->summary_file_path) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, - "undetermined folder summary path. Maybe use set_name ?"); - return FALSE; - } - - /* check if the nntp file exists */ - stat_error = stat (nntp_folder->summary_file_path, &stat_buf); - if (stat_error == -1) - return FALSE; - - exists = S_ISREG (stat_buf.st_mode); - /* we should check the rights here */ - - return exists; -#endif - return TRUE; -} - - - - - - - - -static gboolean -_create (CamelFolder *folder, CamelException *ex) -{ -#if 0 - CamelNNTPSummary *summary; - g_assert(folder != NULL); - - /* call default implementation */ - parent_class->create (folder, ex); - - /* create the summary object */ - summary = CAMEL_NNTP_SUMMARY (gtk_object_new (camel_nntp_summary_get_type (), NULL)); - summary->nb_message = 0; - summary->next_uid = 1; - summary->nntp_file_size = 0; - summary->message_info = g_array_new (FALSE, FALSE, sizeof (CamelNNTPSummaryInformation)); -#endif - - return TRUE; -} - - - -static gboolean -_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ -#if 0 - gboolean folder_already_exists; - - g_assert(folder != NULL); - - /* 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); -#endif - return TRUE; -} - - - - -gboolean -_delete_messages (CamelFolder *folder, CamelException *ex) -{ - - gboolean folder_already_exists; - - g_assert(folder!=NULL); - - /* 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; - - return TRUE; -} - - -static GList * -_list_subfolders (CamelFolder *folder, CamelException *ex) -{ - /* newsgroups don't have subfolders */ - return NULL; -} - - - - -static gint -_get_message_count (CamelFolder *folder, CamelException *ex) -{ - gint message_count = 0; - - g_assert (folder); - g_assert (folder->summary); - - message_count = CAMEL_NNTP_SUMMARY (folder->summary)->nb_message; - - return message_count; -} - - -#if 0 -static void -_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); -#if 0 - CamelNNTPSummary *summary = CAMEL_NNTP_SUMMARY (folder->summary); -#endif - CamelStream *output_stream; - guint32 tmp_file_size; - guint32 next_uid; - gint tmp_file_fd; - GArray *message_info_array; -#if 0 - GArray *nntp_summary_info; -#endif - gchar *tmp_message_filename; - gint fd1, fd2; - int i; - - /* write the message itself */ - output_stream = camel_stream_fs_new_with_name (tmp_message_filename, - CAMEL_STREAM_FS_WRITE); - if (output_stream != NULL) { - camel_stream_write_string (output_stream, "From - \n"); - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); - } - camel_stream_close (output_stream); - gtk_object_unref (GTK_OBJECT (output_stream)); - - /* at this point we have saved the message to a - temporary file, now, we have to add the x-evolution - field and also update the main summary */ - - /* - First : parse the nntp file, but only from the - position where the message has been added, - wich happens to be the last postion in the - nntp file before we added the message. - This position is still stored in the summary - for the moment - */ - next_uid = summary->next_uid; - tmp_file_fd = open (tmp_message_filename, O_RDONLY); - message_info_array = - camel_nntp_parse_file (tmp_file_fd, "From - ", 0, - &tmp_file_size, &next_uid, TRUE, - NULL, 0, ex); - - close (tmp_file_fd); - - /* get the value of the last available UID - as saved in the summary file, again */ - next_uid = summary->next_uid; - - /* make sure all our of message info's have 0 uid - ignore any - set elsewhere */ - for (i=0;i<message_info_array->len;i++) { - g_array_index(message_info_array, CamelNNTPParserMessageInfo, i).uid = 0; - } - - /* - OK, this is not very efficient, we should not use the same - method as for parsing an entire mail file, - but I have no time to write a simpler parser - */ -#if 0 - next_uid = camel_nntp_write_xev (nntp_folder, tmp_message_filename, - message_info_array, &tmp_file_size, next_uid, ex); - -#endif - if (camel_exception_get_id (ex)) { - /* ** FIXME : free the preparsed information */ - return; - } - -#if 0 - nntp_summary_info = - parsed_information_to_nntp_summary (message_info_array); -#endif - - /* store the number of messages as well as the summary array */ - summary->nb_message += 1; - summary->next_uid = next_uid; - - ((CamelNNTPSummaryInformation *)(nntp_summary_info->data))->position += - summary->nntp_file_size; - summary->nntp_file_size += tmp_file_size; - - camel_nntp_summary_append_entries (summary, nntp_summary_info); - g_array_free (nntp_summary_info, TRUE); - - - /* append the temporary file message to the nntp file */ - fd1 = open (tmp_message_filename, O_RDONLY); - fd2 = open (nntp_folder->folder_file_path, - O_WRONLY | O_CREAT | O_APPEND, - 0600); - - if (fd2 == -1) { - camel_exception_setv (ex, - CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "could not open the nntp folder file for appending the message\n" - "\t%s\n" - "Full error is : %s\n", - nntp_folder->folder_file_path, - strerror (errno)); - return; - } - - camel_nntp_copy_file_chunk (fd1, - fd2, - tmp_file_size, - ex); - close (fd1); - close (fd2); - - /* remove the temporary file */ - unlink (tmp_message_filename); - - g_free (tmp_message_filename); -} -#endif - - - -static GList * -_get_uid_list (CamelFolder *folder, CamelException *ex) -{ - GArray *message_info_array; - CamelNNTPSummaryInformation *message_info; - GList *uid_list = NULL; - int i; - - message_info_array = - CAMEL_NNTP_SUMMARY (folder->summary)->message_info; - - for (i=0; i<message_info_array->len; i++) { - message_info = (CamelNNTPSummaryInformation *)(message_info_array->data) + i; - uid_list = g_list_prepend (uid_list, g_strdup (message_info->headers.uid)); - } - - return uid_list; -} - - - -static CamelMimeMessage * -_get_message_by_number (CamelFolder *folder, gint number, CamelException *ex) -{ - GArray *message_info_array; - CamelNNTPSummaryInformation *message_info; - - message_info_array = - CAMEL_NNTP_SUMMARY (folder->summary)->message_info; - - if (number > message_info_array->len) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "No such message %d in folder `%s'.", - number, folder->name); - return NULL; - } - - message_info = - (CamelNNTPSummaryInformation *)(message_info_array->data) + - (number - 1); - - return _get_message_by_uid (folder, message_info->headers.uid, ex); -} - - -static CamelMimeMessage * -_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 = 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, - CAMEL_STREAM_MEM_READ); - - message = camel_mime_message_new (); - camel_data_wrapper_set_input_stream (CAMEL_DATA_WRAPPER (message), message_stream); - - return message; -} diff --git a/camel/providers/nntp/camel-nntp-folder.h b/camel/providers/nntp/camel-nntp-folder.h deleted file mode 100644 index 7029023a62..0000000000 --- a/camel/providers/nntp/camel-nntp-folder.h +++ /dev/null @@ -1,73 +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-nntp-summary.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 *summary_file_path; /* contains the messages 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-provider.c b/camel/providers/nntp/camel-nntp-provider.c deleted file mode 100644 index 5ddda3f39d..0000000000 --- a/camel/providers/nntp/camel-nntp-provider.c +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-provider.c: nntp 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-nntp-store.h" -#include "camel-provider.h" - - -static CamelProvider _nntp_provider = { - (GtkType) 0, - PROVIDER_STORE, - PROVIDER_REMOTE, - "news", - "Camel default NNTP provider", - "This is a provider that reads from a NNTP server.", - (GModule *) NULL -}; - -CamelProvider * -camel_provider_module_init (void); - - -CamelProvider * -camel_provider_module_init (void) -{ - _nntp_provider.object_type = camel_nntp_store_get_type(); - return &_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 c1a721d96c..0000000000 --- a/camel/providers/nntp/camel-nntp-store.c +++ /dev/null @@ -1,476 +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-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 CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex); -static char *_get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex); - -static gboolean nntp_connect (CamelService *service, CamelException *ex); -static gboolean nntp_disconnect (CamelService *service, CamelException *ex); - -static void -camel_nntp_store_class_init (CamelNNTPStoreClass *camel_nntp_store_class) -{ - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_nntp_store_class); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - camel_store_class->get_folder = _get_folder; - camel_store_class->get_folder_name = _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; -} - -static CamelFolder * -_get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex) -{ - CamelNNTPFolder *new_nntp_folder; - CamelFolder *new_folder; - - /* XXX */ - folder_name = "netscape.public.mozilla.announce"; - - /* 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, '/', ex); - - return new_folder; -} - - -static char * -_get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex) -{ - return g_strdup (folder_name); -} - -/** - * 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, status, apoplen; - char *buf, *apoptime, *pass; - 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 */ - - 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; - - /* Closing the buffered write stream will close the - * unbuffered read stream wrapped inside it as well. - */ - camel_stream_close (store->ostream); - gtk_object_unref (GTK_OBJECT (store->ostream)); - 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 "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(); - - camel_nntp_store_open(CAMEL_NNTP_STORE(store), ex); - - 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)) { - gchar *summary_file; - summary_file = g_strdup_printf ("%s/%s-ev-summary", root_dir, group_name); - } - 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); - - /* 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 257772d7cb..0000000000 --- a/camel/providers/nntp/camel-nntp-store.h +++ /dev/null @@ -1,85 +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" - -#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; - - 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-summary.c b/camel/providers/nntp/camel-nntp-summary.c deleted file mode 100644 index dad88b6ca4..0000000000 --- a/camel/providers/nntp/camel-nntp-summary.c +++ /dev/null @@ -1,396 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-utils.c : summary support for nntp groups. */ - -/* - * 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 "camel-exception.h" -#include "camel-nntp-folder.h" -#include "camel-nntp-summary.h" -#include "md5-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> -#include <netinet/in.h> - -static CamelFolderSummaryClass *parent_class = NULL; - -static int count_messages (CamelFolderSummary *summary); -static int count_subfolders (CamelFolderSummary *summary); -static GPtrArray *get_subfolder_info (CamelFolderSummary *summary, - int first, int count); -static GPtrArray *get_message_info (CamelFolderSummary *summary, - int first, int count); -static void finalize (GtkObject *object); - -static void -camel_nntp_summary_class_init (CamelNNTPSummaryClass *camel_nntp_summary_class) -{ - GtkObjectClass *gtk_object_class = - GTK_OBJECT_CLASS (camel_nntp_summary_class); - CamelFolderSummaryClass *camel_folder_summary_class = - CAMEL_FOLDER_SUMMARY_CLASS (camel_nntp_summary_class); - - parent_class = gtk_type_class (camel_folder_summary_get_type ()); - - /* virtual method override */ - camel_folder_summary_class->count_messages = count_messages; - camel_folder_summary_class->count_subfolders = count_subfolders; - camel_folder_summary_class->get_subfolder_info = get_subfolder_info; - camel_folder_summary_class->get_message_info = get_message_info; - - gtk_object_class->finalize = finalize; -} - - -GtkType -camel_nntp_summary_get_type (void) -{ - static GtkType camel_nntp_summary_type = 0; - - if (!camel_nntp_summary_type) { - GtkTypeInfo camel_nntp_summary_info = - { - "CamelNNTPSummary", - sizeof (CamelNNTPSummary), - sizeof (CamelNNTPSummaryClass), - (GtkClassInitFunc) camel_nntp_summary_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_nntp_summary_type = gtk_type_unique (camel_folder_summary_get_type (), &camel_nntp_summary_info); - } - - return camel_nntp_summary_type; -} - -static void -finalize (GtkObject *object) -{ - CamelNNTPSummary *summary = CAMEL_NNTP_SUMMARY (object); - CamelNNTPSummaryInformation *info; - int i; - - for (i = 0; i < summary->message_info->len; i++) { - info = &(((CamelNNTPSummaryInformation *)summary->message_info->data)[i]); - g_free (info->headers.subject); - g_free (info->headers.sender); - g_free (info->headers.to); - g_free (info->headers.sent_date); - g_free (info->headers.received_date); - g_free (info->headers.uid); - } - g_array_free (summary->message_info, TRUE); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - -static int -count_messages (CamelFolderSummary *summary) -{ - return CAMEL_NNTP_SUMMARY (summary)->nb_message; -} - -static int -count_subfolders (CamelFolderSummary *summary) -{ - return 0; -} - -static GPtrArray * -get_subfolder_info (CamelFolderSummary *summary, int first, int count) -{ - return NULL; -} - -static GPtrArray * -get_message_info (CamelFolderSummary *summary, int first, int count) -{ - CamelNNTPSummary *nntp_summary = CAMEL_NNTP_SUMMARY (summary); - CamelNNTPSummaryInformation *info; - GPtrArray *arr; - - /* XXX bounds check */ - - arr = g_ptr_array_new (); - for (; count; count--) { - info = &((CamelNNTPSummaryInformation *)nntp_summary->message_info->data)[first++]; - g_ptr_array_add (arr, info); - } - - return arr; -} - -/** - * camel_nntp_summary_save: - * @summary: - * @filename: - * @ex: - * - * save the summary into a file - **/ -void -camel_nntp_summary_save (CamelNNTPSummary *summary, const gchar *filename, - CamelException *ex) -{ - CamelNNTPSummaryInformation *msg_info; - guint cur_msg; - guint field_length; - gint fd; - gint write_result; /* XXX use this */ - guint32 data; - - fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR); - if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "could not create the nntp summary " - "file\n\t%s\nFull error is : %s\n", - filename, - strerror (errno)); - return; - } - - /* We write the file out in network byte order, not because - * that makes sense, but because it's easy. - */ - - data = htonl (CAMEL_NNTP_SUMMARY_VERSION); - write (fd, &data, sizeof (data)); - - data = htonl (summary->nb_message); - write (fd, &data, sizeof (data)); - - for (cur_msg = 0; cur_msg < summary->nb_message; cur_msg++) { - msg_info = (CamelNNTPSummaryInformation *) - (summary->message_info->data) + cur_msg; - - /* Write meta-info. */ - data = htonl (msg_info->size); - write (fd, &data, sizeof (data)); - write (fd, &msg_info->status, 1); - - /* Write subject. */ - if (msg_info->headers.subject) - field_length = strlen (msg_info->headers.subject); - else - field_length = 0; - data = htonl (field_length); - write (fd, &data, sizeof (data)); - if (msg_info->headers.subject) - write (fd, msg_info->headers.subject, field_length); - - /* Write sender. */ - if (msg_info->headers.sender) - field_length = strlen (msg_info->headers.sender); - else - field_length = 0; - data = htonl (field_length); - write (fd, &data, sizeof (data)); - if (msg_info->headers.sender) - write (fd, msg_info->headers.sender, field_length); - - /* Write sent date. */ - if (msg_info->headers.sent_date) - field_length = strlen (msg_info->headers.sent_date); - else - field_length = 0; - data = htonl (field_length); - write (fd, &data, sizeof (data)); - if (msg_info->headers.sent_date) - write (fd, msg_info->headers.sent_date, field_length); - - /* Write received date. */ - if (msg_info->headers.received_date) - field_length = strlen (msg_info->headers.received_date); - else - field_length = 0; - data = htonl (field_length); - write (fd, &data, sizeof (data)); - if (msg_info->headers.received_date) - write (fd, msg_info->headers.received_date, field_length); - - /* Write uid date. */ - if (msg_info->headers.uid) - field_length = strlen (msg_info->headers.uid); - else - field_length = 0; - data = htonl (field_length); - write (fd, &data, sizeof (data)); - if (msg_info->headers.uid) - write (fd, msg_info->headers.uid, field_length); - - } - - close (fd); -} - - - -/** - * camel_nntp_summary_load: - * @filename: - * @ex: - * - * load the summary from a file - * - * Return value: - **/ -CamelNNTPSummary * -camel_nntp_summary_load (const gchar *newsgroup, const gchar *filename, CamelException *ex) -{ - CamelNNTPSummaryInformation *msg_info; - guint cur_msg; - guint field_length; - gint fd; - CamelNNTPSummary *summary; - gint read_result; - guint32 data; - - fd = open (filename, O_RDONLY); - if (fd == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION, - "could not open the nntp summary file\n" - "\t%s\nFull error is : %s\n", - filename, strerror (errno)); - return NULL; - } - - /* Verify version number. */ - read (fd, &data, sizeof(data)); - data = ntohl (data); - - if (data != CAMEL_NNTP_SUMMARY_VERSION) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_SUMMARY_INVALID, - "This folder summary was written by " - "%s version of this software.", - data < CAMEL_NNTP_SUMMARY_VERSION ? - "an older" : "a newer"); - return NULL; - } - - summary = CAMEL_NNTP_SUMMARY (gtk_object_new (camel_nntp_summary_get_type (), NULL)); - - read (fd, &data, sizeof(data)); - summary->nb_message = ntohl (data); - - summary->message_info = - g_array_new (FALSE, FALSE, - sizeof (CamelNNTPSummaryInformation)); - g_array_set_size (summary->message_info, summary->nb_message); - - for (cur_msg = 0; cur_msg < summary->nb_message; cur_msg++) { - msg_info = (CamelNNTPSummaryInformation *) - (summary->message_info->data) + cur_msg; - - /* Read the meta-info. */ - read (fd, &data, sizeof(data)); - msg_info->size = ntohl (data); - read (fd, &msg_info->status, 1); - - /* Read the subject. */ - read (fd, &field_length, sizeof (field_length)); - field_length = ntohl (field_length); - if (field_length > 0) { - msg_info->headers.subject = - g_new0 (gchar, field_length + 1); - read (fd, msg_info->headers.subject, field_length); - } else - msg_info->headers.subject = NULL; - - /* Read the sender. */ - read (fd, &field_length, sizeof (field_length)); - field_length = ntohl (field_length); - if (field_length > 0) { - msg_info->headers.sender = - g_new0 (gchar, field_length + 1); - read (fd, msg_info->headers.sender, field_length); - } else - msg_info->headers.sender = NULL; - - msg_info->headers.to = g_strdup (newsgroup); - - /* Read the sent date field. */ - read (fd, &field_length, sizeof (field_length)); - field_length = ntohl (field_length); - if (field_length > 0) { - msg_info->headers.sent_date = - g_new0 (gchar, field_length + 1); - read (fd, msg_info->headers.sent_date, field_length); - } else - msg_info->headers.sent_date = NULL; - - /* Read the received date field. */ - read (fd, &field_length, sizeof (field_length)); - field_length = ntohl (field_length); - if (field_length > 0) { - msg_info->headers.received_date = - g_new0 (gchar, field_length + 1); - read (fd, msg_info->headers.received_date, - field_length); - } else - msg_info->headers.received_date = NULL; - - /* Read the uid field. */ - read (fd, &field_length, sizeof (field_length)); - field_length = ntohl (field_length); - if (field_length > 0) { - msg_info->headers.uid = - g_new0 (gchar, field_length + 1); - read (fd, msg_info->headers.uid, - field_length); - } else - msg_info->headers.uid = NULL; - } - - close (fd); - return summary; -} - - -/** - * camel_nntp_summary_append_entries: - * @summary: - * @entries: - * - * append an entry to a summary - **/ -void -camel_nntp_summary_append_entries (CamelNNTPSummary *summary, GArray *entries) -{ - - summary->message_info = g_array_append_vals (summary->message_info, - entries->data, - entries->len); -} diff --git a/camel/providers/nntp/camel-nntp-summary.h b/camel/providers/nntp/camel-nntp-summary.h deleted file mode 100644 index 6c54f6cb33..0000000000 --- a/camel/providers/nntp/camel-nntp-summary.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-nntp-utils.c : summary support for nntp groups. */ - -/* - * - * Author : Chris Toshok <toshok@helixcode.com> - * - * Copyright (C) 2000 Helix Code (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 NNTP_SUMMARY_H -#define NNTP_SUMMARY_H 1 - -#include <camel-folder-summary.h> - -#define CAMEL_NNTP_SUMMARY_TYPE (camel_nntp_summary_get_type ()) -#define CAMEL_NNTP_SUMMARY(obj) (GTK_CHECK_CAST((obj), CAMEL_NNTP_SUMMARY_TYPE, CamelNNTPSummary)) -#define CAMEL_NNTP_SUMMARY_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_NNTP_SUMMARY_TYPE, CamelNNTPSummaryClass)) -#define CAMEL_IS_NNTP_SUMMARY(o) (GTK_CHECK_TYPE((o), CAMEL_NNTP_SUMMARY_TYPE)) - - -#define CAMEL_NNTP_SUMMARY_VERSION 1 - - -typedef struct { - CamelMessageInfo headers; - - guint size; - guchar status; - -} CamelNNTPSummaryInformation; - - -/* this contains informations about the whole nntp file */ -typedef struct { - CamelFolderSummary parent_object; - - guint first_message; /* the first message number in the summary */ - guint nb_message; /* number of messages in the summary */ - - GArray *message_info; /* array of CamelNNTPSummaryInformation */ - -} CamelNNTPSummary; - -typedef struct { - CamelFolderSummaryClass parent_class; - -} CamelNNTPSummaryClass; - - -GtkType camel_nntp_summary_get_type (void); - -void camel_nntp_summary_save (CamelNNTPSummary *summary, - const gchar *filename, CamelException *ex); -CamelNNTPSummary * -camel_nntp_summary_load (const gchar *newsgroup, const gchar *filename, CamelException *ex); - -gboolean camel_nntp_summary_check_sync (gchar *summary_filename, - gchar *nntp_filename, - CamelException *ex); - -void camel_nntp_summary_append_entries (CamelNNTPSummary *summary, - GArray *entries); - - -#endif /* NNTP_SUMMARY_H */ diff --git a/camel/providers/nntp/camel-nntp-utils.c b/camel/providers/nntp/camel-nntp-utils.c deleted file mode 100644 index 4ee93fc572..0000000000 --- a/camel/providers/nntp/camel-nntp-utils.c +++ /dev/null @@ -1,209 +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-nntp-folder.h" -#include "camel-nntp-store.h" -#include "camel-nntp-summary.h" -#include "camel-nntp-utils.h" -#include "camel-stream-buffer.h" -#include "camel-stream-mem.h" -#include "gmime-utils.h" - -#include <stdlib.h> -#include <string.h> - -static GArray* -get_XOVER_headers(CamelNNTPStore *nntp_store, CamelFolder *folder, - int first_message, int last_message) -{ - int status; - - 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; - GArray *array; - gboolean done = FALSE; - - array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation)); - - while (!done) { - char *line; - - line = camel_stream_buffer_read_line ( - CAMEL_STREAM_BUFFER ( nntp_istream )); - - if (*line == '.') { - done = TRUE; - } - else { - CamelNNTPSummaryInformation new_info; - char **split_line = g_strsplit (line, "\t", 7); - - memset (&new_info, 0, sizeof(new_info)); - - new_info.headers.subject = g_strdup(split_line[1]); - new_info.headers.sender = g_strdup(split_line[2]); - new_info.headers.to = g_strdup(folder->name); - new_info.headers.sent_date = g_strdup(split_line[3]); - /* XXX do we need to fill in both dates? */ - new_info.headers.received_date = g_strdup(split_line[3]); - new_info.headers.size = atoi(split_line[5]); - new_info.headers.uid = g_strdup(split_line[4]); - g_strfreev (split_line); - - g_array_append_val(array, new_info); - } - g_free (line); - } - - return array; - } - - return NULL; -} - -static GArray* -get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder, - int first_message, int last_message) -{ - int i; - int status; - GArray *array; - CamelNNTPSummaryInformation info; - - array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation)); - - 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; - - 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 (!strcasecmp(header->name, "From")) - info.headers.sender = g_strdup(header->value); - else if (!strcasecmp(header->name, "To")) - info.headers.to = g_strdup(header->value); - else if (!strcasecmp(header->name, "Subject")) - info.headers.subject = g_strdup(header->value); - else if (!strcasecmp(header->name, "Message-ID")) - info.headers.uid = g_strdup(header->value); - else if (!strcasecmp(header->name, "Date")) { - info.headers.sent_date = g_strdup(header->value); - info.headers.received_date = g_strdup(header->value); - } - } - g_array_append_val(array, info); - } - else if (status == CAMEL_NNTP_FAIL) { - /* nasty things are afoot */ - g_warning ("failure doing HEAD\n"); - break; - } - } - return array; -} - -GArray * -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", folder->name); - - sscanf (ret, "%d %d %d", &nb_message, &first_message, &last_message); - g_free (ret); - - if (status != CAMEL_NNTP_OK) - return NULL; - - if (TRUE /* nntp_store->extensions & CAMEL_NNTP_EXT_XOVER */) { - return get_XOVER_headers (nntp_store, folder, first_message, last_message); - } - else { - return get_HEAD_headers (nntp_store, folder, first_message, last_message); - } -} - diff --git a/camel/providers/nntp/camel-nntp-utils.h b/camel/providers/nntp/camel-nntp-utils.h deleted file mode 100644 index 52617fa0ce..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 }*/ - -GArray *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/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 c587983ffc..0000000000 --- a/camel/providers/pop3/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelpop3includedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelpop3.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -I$(srcdir)/../mbox - -libcamelpop3_la_SOURCES = \ - camel-pop3-folder.c \ - camel-pop3-provider.c \ - camel-pop3-store.c - -libcamelpop3include_HEADERS = \ - camel-pop3-folder.h \ - camel-pop3-store.h - - -libcamelpop3_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - -EXTRA_DIST = diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c deleted file mode 100644 index cf0d1763d3..0000000000 --- a/camel/providers/pop3/camel-pop3-folder.c +++ /dev/null @@ -1,256 +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-mime-message.h" - -#include <stdlib.h> - -#define CF_CLASS(o) (CAMEL_FOLDER_CLASS (GTK_OBJECT (o)->klass)) -static CamelFolderClass *parent_class; - -static void pop3_open (CamelFolder *folder, CamelFolderOpenMode mode, - CamelException *ex); -static void pop3_close (CamelFolder *folder, gboolean expunge, - CamelException *ex); -static gboolean delete_messages (CamelFolder *folder, CamelException *ex); -static gboolean has_message_number_capability (CamelFolder *folder); -static CamelMimeMessage *get_message_by_number (CamelFolder *folder, - gint number, - CamelException *ex); -static void delete_message_by_number (CamelFolder *folder, gint number, - CamelException *ex); -static gint get_message_count (CamelFolder *folder, CamelException *ex); - - -static void -camel_pop3_folder_class_init (CamelPop3FolderClass *camel_pop3_folder_class) -{ - CamelFolderClass *camel_folder_class = - CAMEL_FOLDER_CLASS (camel_pop3_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method overload */ - camel_folder_class->open = pop3_open; - camel_folder_class->close = pop3_close; - camel_folder_class->delete_messages = delete_messages; - camel_folder_class->has_message_number_capability = - has_message_number_capability; - camel_folder_class->get_message_by_number = - get_message_by_number; - camel_folder_class->delete_message_by_number = - delete_message_by_number; - camel_folder_class->get_message_count = - get_message_count; -} - - - -static void -camel_pop3_folder_init (gpointer object, gpointer klass) -{ - CamelFolder *folder = CAMEL_FOLDER (object); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = FALSE; - - /* Hi. I'm CamelPop3Folder. I'm useless. */ - folder->has_summary_capability = FALSE; - folder->has_uid_capability = FALSE; - folder->has_search_capability = FALSE; -} - - - - -GtkType -camel_pop3_folder_get_type (void) -{ - static GtkType camel_pop3_folder_type = 0; - - if (!camel_pop3_folder_type) { - GtkTypeInfo camel_pop3_folder_info = - { - "CamelPop3Folder", - sizeof (CamelPop3Folder), - sizeof (CamelPop3FolderClass), - (GtkClassInitFunc) camel_pop3_folder_class_init, - (GtkObjectInitFunc) camel_pop3_folder_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_pop3_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_pop3_folder_info); - } - - return camel_pop3_folder_type; -} - - -CamelFolder *camel_pop3_folder_new (CamelStore *parent, CamelException *ex) -{ - CamelFolder *folder = - CAMEL_FOLDER (gtk_object_new (camel_pop3_folder_get_type (), - NULL)); - - CF_CLASS (folder)->init (folder, parent, NULL, "inbox", '/', ex); - return folder; -} - -static void -pop3_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - camel_pop3_store_open (CAMEL_POP3_STORE (folder->parent_store), ex); - if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_NONE) - parent_class->open (folder, mode, ex); -} - -static void -pop3_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - camel_pop3_store_close (CAMEL_POP3_STORE (folder->parent_store), - expunge, ex); - if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_NONE) - parent_class->close (folder, expunge, ex); -} - -static gboolean -delete_messages (CamelFolder *folder, CamelException *ex) -{ - int msgs; - gboolean status; - - msgs = get_message_count (folder, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return FALSE; - - status = TRUE; - for (; msgs > 0; msgs--) { - status = status && - (camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - NULL, "DELE %d", msgs) == - CAMEL_POP3_OK); - } - - if (!status) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Unable to delete all messages."); - } - - return status; -} - - -static gboolean -has_message_number_capability (CamelFolder *folder) -{ - return TRUE; -} - -static CamelMimeMessage * -get_message_by_number (CamelFolder *folder, gint number, CamelException *ex) -{ - int status; - char *result, *body; - CamelStream *msgstream; - CamelMimeMessage *msg; - - status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - &result, "RETR %d", number); - if (status != CAMEL_POP3_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not retrieve message from POP " - "server %s: %s.", service->url->host, - status == CAMEL_POP3_ERR ? result : - "Unknown error"); - g_free (result); - return NULL; - } - g_free (result); - - body = camel_pop3_command_get_additional_data (CAMEL_POP3_STORE (folder->parent_store)); - 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.", service->url->host); - return NULL; - } - - msgstream = camel_stream_mem_new_with_buffer (body, strlen (body), - CAMEL_STREAM_MEM_READ); - msg = camel_mime_message_new (); - camel_data_wrapper_set_input_stream (CAMEL_DATA_WRAPPER (msg), - msgstream); - - return msg; -} - -static void -delete_message_by_number (CamelFolder *folder, gint number, CamelException *ex) -{ - int status; - char *resp; - - status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - &resp, "DELE %d", number); - if (status != CAMEL_POP3_OK) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "Unable to delete message %d%s%s", - number, resp ? ": " : "", - resp ? resp : ""); - } - g_free (resp); -} - -static gint -get_message_count (CamelFolder *folder, CamelException *ex) -{ - int status, count; - char *result; - - status = camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - &result, "STAT"); - if (status != CAMEL_POP3_OK) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not get message count from POP " - "server %s: %s.", service->url->host, - status == CAMEL_POP3_ERR ? result : - "Unknown error"); - g_free (result); - return -1; - } - - count = atoi (result); - g_free (result); - return count; -} diff --git a/camel/providers/pop3/camel-pop3-folder.h b/camel/providers/pop3/camel-pop3-folder.h deleted file mode 100644 index 4199e30ead..0000000000 --- a/camel/providers/pop3/camel-pop3-folder.h +++ /dev/null @@ -1,70 +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; - -} 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 8d9d4ac94d..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" - - -static CamelProvider _pop3_provider = { - (GtkType) 0, - PROVIDER_STORE, - PROVIDER_REMOTE, - - "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.", - - (GModule *) NULL -}; - -CamelProvider * -camel_provider_module_init (void); - - -CamelProvider * -camel_provider_module_init (void) -{ - _pop3_provider.object_type = camel_pop3_store_get_type(); - return &_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 3713c086a6..0000000000 --- a/camel/providers/pop3/camel-pop3-store.c +++ /dev/null @@ -1,483 +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 "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 - -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); -static void free_auth_types (CamelService *service, GList *authtypes); - -static CamelFolder *get_folder (CamelStore *store, const char *folder_name, - 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 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_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); - 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_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) -{ - CamelException ex; - - camel_exception_init (&ex); - pop3_disconnect (CAMEL_SERVICE (object), &ex); - camel_exception_clear (&ex); -} - - -static CamelServiceAuthType password_authtype = { - "Password/APOP", - - "This option will connect to the POP server using the APOP " - "protocol if possible, or a plaintext password if not.", - - "", - TRUE -}; - -static GList -*query_auth_types (CamelService *service) -{ - GList *ret; - - ret = g_list_append (NULL, &password_authtype); - return ret; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -/** - * camel_pop3_store_open: Connect to the server if we are currently - * disconnected. - * @store: the store - * @ex: a CamelException - * - * The POP protocol does not allow deleted messages to be expunged - * except by closing the connection. Thus, camel_pop3_folder_{open,close} - * sometimes need to connect to or disconnect from the server. This - * routine reconnects to the server if we have disconnected. - * - **/ -void -camel_pop3_store_open (CamelPop3Store *store, CamelException *ex) -{ - CamelService *service = CAMEL_SERVICE (store); - - if (!camel_service_is_connected (service)) - pop3_connect (service, ex); -} - -/** - * camel_pop3_store_close: Close the connection to the server and - * possibly expunge deleted messages. - * @store: the store - * @expunge: whether or not to expunge deleted messages - * @ex: a CamelException - * - * See camel_pop3_store_open for an explanation of why this is needed. - * - **/ -void -camel_pop3_store_close (CamelPop3Store *store, gboolean expunge, - CamelException *ex) -{ - if (expunge) - camel_pop3_command (store, NULL, "QUIT"); - else - camel_pop3_command (store, NULL, "RSET"); - pop3_disconnect (CAMEL_SERVICE (store), ex); -} - -static gboolean -pop3_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - int fd, status; - char *buf, *apoptime, *apopend; - CamelPop3Store *store = CAMEL_POP3_STORE (service); - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - if (!service->url->passwd) { - char *prompt = g_strdup_printf ("Please enter the POP3 password for %s@%s", - service->url->user, h->h_name); - service->url->passwd = - camel_session_query_authenticator (camel_service_get_session (service), - prompt, TRUE, - service, "password", - ex); - g_free (prompt); - if (!service->url->passwd) - return FALSE; - } - - sin.sin_family = h->h_addrtype; - sin.sin_port = htons (service->url->port ? service->url->port : 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) { - 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, note APOP timestamp, if any. */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - if (!buf) { - camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not read greeting from POP " - "server."); - return FALSE; - camel_stream_close (store->ostream); - camel_stream_close (store->istream); - } - apoptime = strchr (buf, '<'); - apopend = apoptime ? strchr (apoptime, '>') : NULL; - if (apoptime && apopend) - apoptime = g_strndup (apoptime, apopend - apoptime + 1); - else - apoptime = NULL; - g_free (buf); - - /* Authenticate via APOP if we can, USER/PASS if we can't. */ - status = CAMEL_POP3_FAIL; - if (apoptime) { - char *secret, md5asc[32], *d; - unsigned char md5sum[16], *s; - - secret = g_strdup_printf ("%s%s", apoptime, - service->url->passwd); - md5_get_digest (secret, strlen (secret), md5sum); - g_free (apoptime); - g_free (secret); - - for (s = md5sum, d = md5asc; d < md5asc + 32; s++, d += 2) - sprintf (d, "%.2x", *s); - - status = camel_pop3_command (store, NULL, "APOP %s %s", - service->url->user, md5asc); - } - - if (status != CAMEL_POP3_OK ) { - char *msg; - - status = camel_pop3_command (store, &msg, "USER %s", - service->url->user); - if (status != CAMEL_POP3_OK) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, - "Unable to connect to POP " - "server. Error sending username:" - " %s", msg ? msg : "(Unknown)"); - g_free (msg); - camel_stream_close (store->ostream); - camel_stream_close (store->istream); - return FALSE; - } - - status = camel_pop3_command(store, &msg, "PASS %s", - service->url->passwd); - if (status != CAMEL_POP3_OK) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, - "Unable to authenticate to POP " - "server. Error sending password:" - " %s", msg ? msg : "(Unknown)"); - g_free (msg); - camel_stream_close (store->ostream); - camel_stream_close (store->istream); - return FALSE; - } - } - - service_class->connect (service, ex); - return TRUE; -} - -static gboolean -pop3_disconnect (CamelService *service, CamelException *ex) -{ - CamelPop3Store *store = CAMEL_POP3_STORE (service); - - if (!service->connected) - return TRUE; - - if (!service_class->disconnect (service, ex)) - return FALSE; - - /* Closing the buffered write stream will close the - * unbuffered read stream wrapped inside it as well. - */ - camel_stream_close (store->ostream); - gtk_object_unref (GTK_OBJECT (store->ostream)); - store->ostream = NULL; - store->istream = NULL; - return TRUE; -} - -static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, CamelException *ex) -{ - return camel_pop3_folder_new (store, ex); -} - -static char * -get_folder_name (CamelStore *store, const char *folder_name, - CamelException *ex) -{ - if (!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, *respbuf; - va_list ap; - int status; - - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - /* 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)); - 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) -{ - CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream); - GPtrArray *data; - char *buf; - int i, 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; - if (*buf == '.') - memmove (buf, buf + 1, strlen (buf)); - g_ptr_array_add (data, buf); - } - - if (status == CAMEL_POP3_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; -} diff --git a/camel/providers/pop3/camel-pop3-store.h b/camel/providers/pop3/camel-pop3-store.h deleted file mode 100644 index a4373a884a..0000000000 --- a/camel/providers/pop3/camel-pop3-store.h +++ /dev/null @@ -1,80 +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; - -} CamelPop3Store; - - - -typedef struct { - CamelStoreClass parent_class; - -} CamelPop3StoreClass; - - -/* public methods */ -void camel_pop3_store_open (CamelPop3Store *store, CamelException *ex); -void camel_pop3_store_close (CamelPop3Store *store, gboolean expunge, - 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); - -/* Standard Gtk function */ -GtkType camel_pop3_store_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_POP3_STORE_H */ - - 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 aada24aee7..0000000000 --- a/camel/providers/sendmail/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsendmailincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsendmail.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel - -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 -rpath $(libdir) - -EXTRA_DIST = diff --git a/camel/providers/sendmail/camel-sendmail-provider.c b/camel/providers/sendmail/camel-sendmail-provider.c deleted file mode 100644 index 5d3809b6f0..0000000000 --- a/camel/providers/sendmail/camel-sendmail-provider.c +++ /dev/null @@ -1,56 +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" - -static CamelProvider _sendmail_provider = { - (GtkType) 0, - PROVIDER_TRANSPORT, - 0, - - "sendmail", - "Sendmail", - - "For delivering mail by passing it to the \"sendmail\" program " - "on the local system.", - - (GModule *) NULL -}; - -CamelProvider * -camel_provider_module_init (void); - - -CamelProvider * -camel_provider_module_init (void) -{ - _sendmail_provider.object_type = camel_sendmail_transport_get_type(); - return &_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 15ba1f04e1..0000000000 --- a/camel/providers/sendmail/camel-sendmail-transport.c +++ /dev/null @@ -1,204 +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 "camel-sendmail-transport.h" -#include "camel-mime-message.h" -#include "camel-data-wrapper.h" -#include "camel-stream-fs.h" -#include "camel-exception.h" - -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); - - /* virtual method overload */ - 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]); - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), out); - camel_stream_close (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); -} 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/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 25ee71b3c0..0000000000 --- a/camel/providers/smtp/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsmtpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsmtp.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel - -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 -rpath $(libdir) - -EXTRA_DIST = diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c deleted file mode 100644 index 03ef1a9eb3..0000000000 --- a/camel/providers/smtp/camel-smtp-provider.c +++ /dev/null @@ -1,56 +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" - - -static CamelProvider _smtp_provider = { - (GtkType) 0, - PROVIDER_TRANSPORT, - 0, - - "smtp", - "SMTP", - - "For delivering mail by connecting to a remote mailhub using SMTP.", - - (GModule *) NULL -}; - -CamelProvider * -camel_provider_module_init (void); - - -CamelProvider * -camel_provider_module_init (void) -{ - _smtp_provider.object_type = camel_smtp_transport_get_type(); - return &_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 cc57e29b1d..0000000000 --- a/camel/providers/smtp/camel-smtp-transport.c +++ /dev/null @@ -1,662 +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@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 <sys/param.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 "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 ???? */ -#define SMTP_PORT 25 - -static CamelServiceClass *service_class = NULL; - -/* 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); -static void free_auth_types (CamelService *service, GList *authtypes); -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); - - -static gboolean smtp_is_esmtp = FALSE; - -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); - - /* 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_transport_class->can_send = _can_send; - camel_transport_class->send = _send; - camel_transport_class->send_to = _send_to; -} - -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) NULL, - /* 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) -{ - struct hostent *h; - struct sockaddr_in sin; - gint fd; - gchar *pass = NULL, *respbuf = NULL; - CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (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 : 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; - } - - 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")) - smtp_is_esmtp = TRUE; - if (smtp_is_esmtp && strstr(respbuf, "AUTH")) { - /* parse for supported AUTH types */ - esmtp_get_authtypes(respbuf); - } - } while ( *(respbuf+3) == '-' ); /* if we got "220-" then loop again */ - g_free(respbuf); - - /* send HELO */ - smtp_helo(transport, ex); - - 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; - - /* Closing the buffered write stream will close the - * unbuffered read stream wrapped inside it as well. - */ - camel_stream_close (transport->ostream); - gtk_object_unref (GTK_OBJECT (transport->ostream)); - transport->ostream = NULL; - transport->istream = NULL; - - return TRUE; -} - -static GList -*esmtp_get_authtypes(gchar *buffer) -{ - GList *ret = NULL; - - return ret; -} - -static CamelServiceAuthType password_authtype = { - "Password/CRAM-MD5", - - "This option will connect to the ESMTP server using the CRAM-MD5 " - "authentication if possible.", - - "", - TRUE -}; - -static GList -*query_auth_types (CamelService *service) -{ - GList *ret; - - ret = g_list_append (NULL, &password_authtype); - return ret; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -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; - CamelService *service = CAMEL_SERVICE (transport); - CamelSmtpTransport *smtp_transport = CAMEL_SMTP_TRANSPORT(transport); - - if (!camel_service_is_connected (service)) - smtp_connect (service, ex); - - s = 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) -{ - GList *to, *cc, *bcc, *recipients; - - to = camel_mime_message_get_recipients ((CamelMimeMessage *) message, "To"); - cc = camel_mime_message_get_recipients ((CamelMimeMessage *) message, "Cc"); - bcc = camel_mime_message_get_recipients ((CamelMimeMessage *) message, "Bcc"); - recipients = g_list_concat(to, cc); - recipients = g_list_concat(recipients, bcc); - g_list_free(to); - g_list_free(cc); - g_list_free(bcc); - - 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)); - - 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; - gchar localhost[MAXHOSTNAMELEN + MAXHOSTNAMELEN + 2]; - gchar domainname[MAXHOSTNAMELEN]; - - /* get the localhost name */ - memset(localhost, 0, sizeof(localhost)); - gethostname (localhost, MAXHOSTNAMELEN); - memset(domainname, 0, sizeof(domainname)); - getdomainname(domainname, MAXHOSTNAMELEN); - if (*domainname && strcmp(domainname, "(none)")) { - strcat(localhost, "."); - strcat(localhost, domainname); - } - - /* hiya server! how are you today? */ - if (smtp_is_esmtp) - cmdbuf = g_strdup_printf ("EHLO %s\r\n", localhost); - else - cmdbuf = g_strdup_printf ("HELO %s\r\n", localhost); - 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)); - if ( !respbuf || strncmp(respbuf, "250", 3) ) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "HELO response error: " - "%s: non-fatal", - g_strerror (errno)); - return FALSE; - } - } 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); - 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)); - 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); - 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)); - 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; - gchar *buf, *chunk; - CamelStream *message_stream; - - /* enclose address in <>'s since some SMTP daemons *require* that */ - cmdbuf = g_strdup("DATA\r\n"); - 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)); - 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; - } - - /* now to send the actual data */ - message_stream = camel_stream_buffer_new(CAMEL_DATA_WRAPPER (message)->output_stream, CAMEL_STREAM_BUFFER_READ); - while (1) { - /* send 1 line at a time */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER(message_stream)); - if (!buf) - break; - - /* check for a lone '.' */ - if (!strcmp(buf, ".")) - chunk = g_strconcat(buf, ".\r\n", NULL); - else - chunk = g_strconcat(buf, "\r\n", NULL); - - /* write the line */ - if ( camel_stream_write (transport->ostream, chunk, strlen(chunk)) == -1) { - g_free(chunk); - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "DATA send timed out: message body: " - "%s: mail not sent", - g_strerror (errno)); - return FALSE; - } - g_free(chunk); - } - - /* terminate the message body */ - 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)); - 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"); - 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)); - 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"); - 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)); - 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 54343e59d8..0000000000 --- a/camel/providers/smtp/camel-smtp-transport.h +++ /dev/null @@ -1,68 +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 "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; - -} 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 */ - - |