diff options
author | nobody <nobody@localhost> | 2000-05-15 12:36:44 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2000-05-15 12:36:44 +0800 |
commit | ed0a36823be616e1bc7ba9a67e437140c1f12459 (patch) | |
tree | 8e6809dc4947632fed7279523d66fcd047cada6f /camel/providers | |
parent | f8ff932ae3149c285acea3977a50596749d38584 (diff) | |
download | gsoc2013-evolution-today.tar gsoc2013-evolution-today.tar.gz gsoc2013-evolution-today.tar.bz2 gsoc2013-evolution-today.tar.lz gsoc2013-evolution-today.tar.xz gsoc2013-evolution-today.tar.zst gsoc2013-evolution-today.zip |
This commit was manufactured by cvs2svn to create tag 'today'.today
svn path=/tags/today/; revision=3041
Diffstat (limited to 'camel/providers')
64 files changed, 0 insertions, 9875 deletions
diff --git a/camel/providers/.cvsignore b/camel/providers/.cvsignore deleted file mode 100644 index 3dda72986f..0000000000 --- a/camel/providers/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile.in -Makefile diff --git a/camel/providers/MH/.cvsignore b/camel/providers/MH/.cvsignore deleted file mode 100644 index 2e7b174532..0000000000 --- a/camel/providers/MH/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile.in -Makefile -.deps -*.lo -*.la -.libs diff --git a/camel/providers/MH/Makefile.am b/camel/providers/MH/Makefile.am deleted file mode 100644 index 59662a07dd..0000000000 --- a/camel/providers/MH/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmhincludedir = $(includedir)/camel - - -lib_LTLIBRARIES = libcamelmh.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-mh-provider\" - -libcamelmh_la_SOURCES = \ - camel-mh-folder.c \ - camel-mh-provider.c \ - camel-mh-store.c \ - mh-summary.c \ - mh-uid.c \ - mh-utils.c - -libcamelmhinclude_HEADERS = \ - camel-mh-folder.h \ - camel-mh-store.h \ - mh-summary.c \ - mh-uid.h \ - mh-utils.h - - -libcamelmh_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - - -EXTRA_DIST = diff --git a/camel/providers/MH/camel-mh-folder.c b/camel/providers/MH/camel-mh-folder.c deleted file mode 100644 index f4ff8f305a..0000000000 --- a/camel/providers/MH/camel-mh-folder.c +++ /dev/null @@ -1,1022 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-folder.c : Abstract class for an email folder */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#include <config.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include "camel-mh-folder.h" -#include "camel-mh-store.h" -#include "gstring-util.h" -#include "camel-log.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "camel-folder-summary.h" -#include "gmime-utils.h" -#include "mh-utils.h" -#include "mh-uid.h" -#include "mh-summary.h" - - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelMhFolder */ -#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMHS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - - -static void _set_name(CamelFolder *folder, const gchar *name, CamelException *ex); -static void _init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex); -static gboolean _exists (CamelFolder *folder, CamelException *ex); -static gboolean _create(CamelFolder *folder, CamelException *ex); -static gboolean _delete (CamelFolder *folder, gboolean recurse, CamelException *ex); -static gboolean _delete_messages (CamelFolder *folder, CamelException *ex); -static GList *_list_subfolders (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *_get_message (CamelFolder *folder, gint number, CamelException *ex); -static gint _get_message_count (CamelFolder *folder, CamelException *ex); -static gint _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static void _expunge (CamelFolder *folder, CamelException *ex); -static void _copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex); -static void _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); -static void _close (CamelFolder *folder, gboolean expunge, CamelException *ex); - -static const gchar *_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static CamelMimeMessage *_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex); -static GList *_get_uid_list (CamelFolder *folder, CamelException *ex); - -/* some utility functions */ -static int copy_reg (const char *src_path, const char *dst_path, CamelException *ex); - -static void -camel_mh_folder_class_init (CamelMhFolderClass *camel_mh_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_mh_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_folder_class->init_with_store = _init_with_store; - camel_folder_class->set_name = _set_name; - camel_folder_class->exists = _exists; - camel_folder_class->delete = _delete; - camel_folder_class->delete_messages = _delete_messages; - camel_folder_class->list_subfolders = _list_subfolders; - camel_folder_class->get_message = _get_message; - camel_folder_class->get_message_count = _get_message_count; - camel_folder_class->append_message = _append_message; - camel_folder_class->expunge = _expunge; - camel_folder_class->copy_message_to = _copy_message_to; - camel_folder_class->open = _open; - camel_folder_class->close = _close; - camel_folder_class->get_message_uid = _get_message_uid; - camel_folder_class->get_message_by_uid = _get_message_by_uid; - camel_folder_class->get_uid_list = _get_uid_list; - -} - - - - - - - -GtkType -camel_mh_folder_get_type (void) -{ - static GtkType camel_mh_folder_type = 0; - - if (!camel_mh_folder_type) { - GtkTypeInfo camel_mh_folder_info = - { - "CamelMhFolder", - sizeof (CamelMhFolder), - sizeof (CamelMhFolderClass), - (GtkClassInitFunc) camel_mh_folder_class_init, - (GtkObjectInitFunc) NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mh_folder_type = gtk_type_unique (CAMEL_FOLDER_TYPE, &camel_mh_folder_info); - } - - return camel_mh_folder_type; -} - - - -static gint -_message_name_compare (gconstpointer a, gconstpointer b) -{ - gchar *m1 = (gchar *)a; - gchar *m2 = (gchar *)b; - gint len_diff; - - return (atoi (m1) - atoi (m2)); -} - - -static void -_init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex) -{ - /* call parent method */ - parent_class->init_with_store (folder, parent_store, ex); - - folder->can_hold_messages = TRUE; - folder->can_hold_folders = TRUE; - folder->has_summary_capability = TRUE; - folder->has_uid_capability = TRUE; - - folder->summary = NULL; - -} - - - -static void -_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - struct dirent *dir_entry; - DIR *dir_handle; - - - if (folder->open_state == FOLDER_OPEN) return; - - - /* create message list */ - /* read the whole folder and sort message names */ - dir_handle = opendir (mh_folder->directory_path); - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, mh_folder->directory_path)) - /* add the file name to the list */ - mh_folder->file_name_list = g_list_insert_sorted (mh_folder->file_name_list, - g_strdup (dir_entry->d_name), - _message_name_compare); - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - /* get (or create) uid list */ - if (!(mh_load_uid_list (mh_folder) > 0)) - mh_generate_uid_list (mh_folder); - - /* get or create summary */ - /* it is important that it comes after uid list reading/generation */ - if (!(mh_load_summary (mh_folder) > 0)) - mh_generate_summary (folder); - printf ("**** summary = %p\n", folder->summary); - -} - - - -static void -_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - - /* save uid list, if any */ - if (mh_folder->uid_array) - mh_save_uid_list (mh_folder); - - /* save summary, if any */ - if (folder->summary) - mh_save_summary (mh_folder); - - /* call parent implementation */ - parent_class->close (folder, expunge, ex); -} - - - - - -/** - * camel_mh_folder_set_name: set the name of an MH folder - * @folder: the folder to set the name - * @name: a string representing the (short) name - * - * - * - **/ -static void -_set_name (CamelFolder *folder, const gchar *name, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - const gchar *root_dir_path; - gchar *full_name; - const gchar *parent_full_name; - gchar separator; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::set_name\n"); - g_assert (folder); - g_assert (name); - g_assert (folder->parent_store); - - /* call default implementation */ - parent_class->set_name (folder, name, ex); - - if (mh_folder->directory_path) g_free (mh_folder->directory_path); - - separator = camel_store_get_separator (folder->parent_store); - root_dir_path = camel_mh_store_get_toplevel_dir (CAMEL_MH_STORE(folder->parent_store)); - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name full_name is %s\n", folder->full_name); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name root_dir_path is %s\n", root_dir_path); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::separator is %c\n", separator); - - mh_folder->directory_path = g_strdup_printf ("%s%c%s", root_dir_path, separator, folder->full_name); - - if (!camel_folder_exists (folder, ex)) return; - - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::set_name mh_folder->directory_path is %s\n", - mh_folder->directory_path); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::set_name\n"); -} - - - -static gboolean -_exists (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - struct stat stat_buf; - gint stat_error; - gboolean exists; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::exists\n"); - g_assert (folder); - - if (!mh_folder->directory_path) return FALSE; - - stat_error = stat (mh_folder->directory_path, &stat_buf); - if (stat_error == -1) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::exists when executing stat on %s, stat_error = %d\n", - mh_folder->directory_path, stat_error); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - return FALSE; - } - exists = S_ISDIR (stat_buf.st_mode); - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::exists\n"); - return exists; -} - - -static gboolean -_create (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - mode_t dir_mode = S_IRWXU; - gint mkdir_error; - - g_assert(folder); - - /* call default implementation */ - parent_class->create (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (camel_folder_exists (folder, ex)) return TRUE; - - mkdir_error = mkdir (directory_path, dir_mode); - return (mkdir_error == -1); -} - - - -static gboolean -_delete (CamelFolder *folder, gboolean recurse, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - gint rmdir_error = 0; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete (folder, recurse, ex); - /* the default implementation will care about deleting - messages first and recursing the operation if - necessary */ - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return TRUE; - - /* physically delete the directory */ - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete removing directory %s\n", directory_path); - rmdir_error = rmdir (directory_path); - if (rmdir_error == -1) { - CAMEL_LOG_WARNING ("CamelMhFolder::delete Error when removing directory %s\n", directory_path); - CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); - } - - return (rmdir_error != -1); -} - - -static gboolean -_delete_messages (CamelFolder *folder, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct stat stat_buf; - gint stat_error = 0; - gchar *entry_name; - struct dirent *dir_entry; - gint unlink_error = 0; - DIR *dir_handle; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete_messages (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return TRUE; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while ((stat_error != -1) && (unlink_error != -1) && (dir_entry != NULL)) { - - /* get the name of the next entry in the dir */ - entry_name = dir_entry->d_name; - stat_error = stat (mh_folder->directory_path, &stat_buf); - - /* is it a regular file ? */ - if ((stat_error != -1) && S_ISREG(stat_buf.st_mode)) { - /* yes, delete it */ - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::delete_messages removing file %s\n", entry_name); - unlink_error = unlink(entry_name); - - if (unlink_error == -1) { - CAMEL_LOG_WARNING ("CamelMhFolder::delete_messages Error when deleting file %s\n", - entry_name); - CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); - } - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return ((stat_error != -1) && (unlink_error != -1)); - -} - - - -static GList * -_list_subfolders (CamelFolder *folder, CamelException *ex) -{ - GList *subfolder_name_list = NULL; - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct stat stat_buf; - gint stat_error = 0; - GList *file_list; - gchar *entry_name; - gchar *full_entry_name; - struct dirent *dir_entry; - DIR *dir_handle; - - g_assert(folder); - - /* call default implementation */ - parent_class->delete_messages (folder, ex); - - directory_path = mh_folder->directory_path; - if (!directory_path) return NULL; - - if (!camel_folder_exists (folder, ex)) return NULL; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while ((stat_error != -1) && (dir_entry != NULL)) { - - /* get the name of the next entry in the dir */ - entry_name = dir_entry->d_name; - full_entry_name = g_strdup_printf ("%s/%s", mh_folder->directory_path, entry_name); - stat_error = stat (full_entry_name, &stat_buf); - g_free (full_entry_name); - - /* is it a directory ? */ - if ((stat_error != -1) && S_ISDIR (stat_buf.st_mode)) { - /* yes, add it to the list */ - if (entry_name[0] != '.') { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::list_subfolders adding %s\n", entry_name); - subfolder_name_list = g_list_append (subfolder_name_list, g_strdup (entry_name)); - } - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - - return subfolder_name_list; -} - - - - - -static void -_filename_free (gpointer data) -{ - g_free ((gchar *)data); -} - - -/* slow routine, may be optimixed, or we should use - caches if users complain */ -static CamelMimeMessage * -_get_message (CamelFolder *folder, gint number, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - gchar *message_name; - gchar *message_file_name; - CamelStream *input_stream = NULL; - CamelMimeMessage *message = NULL; - GList *message_list = NULL; - - g_assert(folder); - - - directory_path = mh_folder->directory_path; - if (!directory_path) return NULL; - - - - message_name = g_list_nth_data (mh_folder->file_name_list, number); - - if (message_name != NULL) { - CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, name = %s\n", - number, message_name); - message_file_name = g_strdup_printf ("%s/%s", directory_path, message_name); - input_stream = camel_stream_buffered_fs_new_with_name (message_file_name, CAMEL_STREAM_BUFFERED_FS_READ); - - if (input_stream != NULL) { -#warning use session field here - message = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); - gtk_object_unref (GTK_OBJECT (input_stream)); - message->message_number = number; - gtk_object_set_data_full (GTK_OBJECT (message), "filename", - g_strdup (message_name), _filename_free); - -#warning Set flags and all this stuff here - } - g_free (message_file_name); - } else - CAMEL_LOG_FULL_DEBUG ("CanelMhFolder::get_message message number = %d, not found\n", number); - - - return message; -} - - - -static gint -_get_message_count (CamelFolder *folder, CamelException *ex) -{ - - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - guint message_count = 0; - - g_assert(folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) return -1; - - if (!camel_folder_exists (folder, ex)) return 0; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) - message_count++; - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::get_message_count found %d messages\n", message_count); - return message_count; -} - - - -static gboolean -_find_next_free_message_file (CamelFolder *folder, gint *new_msg_number, gchar **new_msg_filename, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - gint last_max_message_number = 0; - gint current_message_number; - - g_assert(folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) return FALSE; - - if (!camel_folder_exists (folder, ex)) return FALSE; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) { - /* see if the message number is the biggest found */ - current_message_number = atoi (dir_entry->d_name); - if (current_message_number > last_max_message_number) - last_max_message_number = current_message_number; - } - /* read next entry */ - dir_entry = readdir (dir_handle); - } - closedir (dir_handle); - - *new_msg_number = last_max_message_number + 1; - *new_msg_filename = g_strdup_printf ("%s/%d", directory_path, *new_msg_number); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::find_next_free_message_file new message path is %s\n", - *new_msg_filename); - return TRUE; - - -} -static gint -_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - guint new_msg_number; - gchar *new_msg_filename; - CamelStream *output_stream; - gboolean error; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelMhFolder::append_message\n"); - if (!_find_next_free_message_file (folder, &new_msg_number, &new_msg_filename, ex)) - return -1; - - output_stream = camel_stream_fs_new_with_name (new_msg_filename, CAMEL_STREAM_FS_WRITE); - if (output_stream != NULL) { - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); - camel_stream_close (output_stream); - } else { - CAMEL_LOG_WARNING ("CamelMhFolder::append_message could not open %s for writing\n", - new_msg_filename); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - error = TRUE; - } - - g_free (new_msg_filename); - CAMEL_LOG_FULL_DEBUG ("Leaving CamelMhFolder::append_message\n"); - if (error) return -1; - else return new_msg_number; -} - - - - - -static void -_expunge (CamelFolder *folder, CamelException *ex) -{ - /* For the moment, we look in the folder active message - * list. I did not make my mind for the moment, should - * the gtk_object->destroy signal be used to expunge - * freed messages objects marked DELETED ? - */ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER(folder); - CamelMimeMessage *message; - GList *message_node; - gchar *fullpath; - gchar *filename; - gint unlink_error; - const gchar *directory_path; - - CAMEL_LOG_FULL_DEBUG ("Entering CamelFolder::expunge\n"); - - message_node = folder->message_list; - - directory_path = mh_folder->directory_path; - if (!directory_path) return; - - /* look in folder message list which messages - * need to be expunged */ - while ( message_node) { - message = CAMEL_MIME_MESSAGE (message_node->data); - - if (message && camel_mime_message_get_flag (message, "DELETED")) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::expunge, expunging message %d\n", message->message_number); - /* expunge the message */ - filename = gtk_object_get_data (GTK_OBJECT (message), "filename"); - fullpath = g_strdup_printf ("%s/%s", directory_path, filename); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::expunge, message fullpath is %s\n", - fullpath); - unlink_error = unlink(fullpath); - if (unlink_error != -1) { - message->expunged = TRUE; - } else { - CAMEL_LOG_WARNING ("CamelMhFolder:: could not unlink %s (message %d)\n", - fullpath, message->message_number); - CAMEL_LOG_FULL_DEBUG (" Full error text is : %s\n", strerror(errno)); - } - } - message_node = message_node->next; - CAMEL_LOG_FULL_DEBUG ("CamelFolder::expunge, examined message node %p\n", message_node); - } - - CAMEL_LOG_FULL_DEBUG ("Leaving CamelFolder::expunge\n"); -} - - -static void -_copy_message_to (CamelFolder *folder, CamelMimeMessage *message, CamelFolder *dest_folder, CamelException *ex) -{ - gchar *src_msg_filename; - guint dest_msg_number; - gchar *dest_msg_filename; - - if (IS_CAMEL_MH_FOLDER (dest_folder)) { - /*g_return_if_fail (message->parent_folder == folder);*/ - - if (!_find_next_free_message_file (dest_folder, &dest_msg_number, &dest_msg_filename, ex)) - return; - src_msg_filename = gtk_object_get_data (GTK_OBJECT (message), "fullpath"); - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::copy_to copy file %s to %s\n", src_msg_filename, dest_msg_filename); - copy_reg (src_msg_filename, dest_msg_filename, ex); - - } else - parent_class->copy_message_to (folder, message, dest_folder, ex); -} - - - -/** UID **/ - -static const gchar * -_get_message_uid (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GArray *uid_array; - gboolean found = FALSE; - MhUidCouple *uid_couple; - gchar *filename; - guint file_number; - gint i; - - /* if the message already has its uid stored, - return it */ - if (message->message_uid) - return (message->message_uid); - - /* else, it has a filename associated to it */ - filename = gtk_object_get_data (GTK_OBJECT (message), "filename"); - file_number = atoi (file_number); - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - /* look in the uid array for the file number */ - found = (uid_couple->file_number == file_number); - for (i=0; (i<uid_array->len) && (!found); i++) { - uid_couple++; - found = (uid_couple->file_number == file_number); - } - - if (found) return uid_couple->uid; - else return NULL; - -} - - -static CamelMimeMessage * -_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GArray *uid_array; - gboolean found = FALSE; - MhUidCouple *uid_couple; - gint file_number; - gchar *filename; - CamelMimeMessage *message = NULL; - CamelStream *input_stream; - int i; - - /* - * because they are constructed with md5 - * signatures, all MH uids are 16 bytes long - */ - if (strlen (uid) != 16) return NULL; - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - found = !strncmp (uid, uid_couple->uid, 16 * sizeof (guchar)); - for (i=0; (i<uid_array->len) && (!found); i++) { - uid_couple++; - found = !strncmp (uid, uid_couple->uid, 16 * sizeof (guchar)); - } - if (found) { - /* physically retrieve the message */ - file_number = uid_couple->file_number; - filename = g_strdup_printf ("%d", file_number); - input_stream = camel_stream_buffered_fs_new_with_name (filename, CAMEL_STREAM_BUFFERED_FS_READ); - - if (input_stream != NULL) { -#warning use session field here - message = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); - gtk_object_unref (GTK_OBJECT (input_stream)); - - /* set message UID in CamelMimeMessage */ - message->message_uid = g_strdup (uid); - - } - g_free (filename); - } - - return message; - -} - -static GList * -_get_uid_list (CamelFolder *folder, CamelException *ex) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - GList *uid_list; - GArray *uid_array; - MhUidCouple *uid_couple; - int i; - - uid_array = mh_folder->uid_array; - uid_couple = (MhUidCouple *)uid_array->data; - - for (i=0; i<uid_array->len; i++) { - uid_list = g_list_prepend (uid_list, uid_couple->uid); - uid_couple++; - } - - return uid_list; -} - - - - - - - - -/************************************************************************/ - -/*** Took directly from GNU fileutils-4.0 ***/ -/* Copyright (C) 89, 90, 91, 95, 96, 97, 1998 Free Software Foundation. */ -/* This may be rwritten soon. -Bertrand */ - - -/* Write LEN bytes at PTR to descriptor DESC, retrying if interrupted. - Return LEN upon success, write's (negative) error code otherwise. */ -int -full_write (int desc, const char *ptr, size_t len) -{ - int total_written; - - total_written = 0; - while (len > 0) - { - int written = write (desc, ptr, len); - if (written < 0) - { - if (errno == EINTR) - continue; - return written; - } - total_written += written; - ptr += written; - len -= written; - } - return total_written; -} - - - - -static int -copy_reg (const char *src_path, const char *dst_path, CamelException *ex) -{ - char *buf; - int buf_size; - int dest_desc; - int source_desc; - int n_read; - struct stat sb; - char *cp; - int *ip; - int return_val = 0; - off_t n_read_total = 0; - int last_write_made_hole = 0; - int make_holes = TRUE; - - source_desc = open (src_path, O_RDONLY); - if (source_desc < 0) - { - /* If SRC_PATH doesn't exist, then chances are good that the - user did something like this `cp --backup foo foo': and foo - existed to start with, but copy_internal renamed DST_PATH - with the backup suffix, thus also renaming SRC_PATH. */ - if (errno == ENOENT) - error (0, 0, "`%s' and `%s' are the same file", - src_path, dst_path); - else - error (0, errno, "%s", src_path); - - return -1; - } - - /* Create the new regular file with small permissions initially, - to not create a security hole. */ - - dest_desc = open (dst_path, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (dest_desc < 0) - { - error (0, errno, "cannot create regular file `%s'", dst_path); - return_val = -1; - goto ret2; - } - - /* Find out the optimal buffer size. */ - - if (fstat (dest_desc, &sb)) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - - buf_size = 8192; - - - - /* Make a buffer with space for a sentinel at the end. */ - - buf = (char *) alloca (buf_size + sizeof (int)); - - for (;;) - { - n_read = read (source_desc, buf, buf_size); - if (n_read < 0) - { - if (errno == EINTR) - continue; - error (0, errno, "%s", src_path); - return_val = -1; - goto ret; - } - if (n_read == 0) - break; - - n_read_total += n_read; - - ip = 0; - if (make_holes) - { - buf[n_read] = 1; /* Sentinel to stop loop. */ - - /* Find first nonzero *word*, or the word with the sentinel. */ - - ip = (int *) buf; - while (*ip++ == 0) - ; - - /* Find the first nonzero *byte*, or the sentinel. */ - - cp = (char *) (ip - 1); - while (*cp++ == 0) - ; - - /* If we found the sentinel, the whole input block was zero, - and we can make a hole. */ - - if (cp > buf + n_read) - { - /* Make a hole. */ - if (lseek (dest_desc, (off_t) n_read, SEEK_CUR) < 0L) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - last_write_made_hole = 1; - } - else - /* Clear to indicate that a normal write is needed. */ - ip = 0; - } - if (ip == 0) - { - if (full_write (dest_desc, buf, n_read) < 0) - { - error (0, errno, "%s", dst_path); - return_val = -1; - goto ret; - } - last_write_made_hole = 0; - } - } - - /* If the file ends with a `hole', something needs to be written at - the end. Otherwise the kernel would truncate the file at the end - of the last write operation. */ - - if (last_write_made_hole) - { -#if HAVE_FTRUNCATE - /* Write a null character and truncate it again. */ - if (full_write (dest_desc, "", 1) < 0 - || ftruncate (dest_desc, n_read_total) < 0) -#else - /* Seek backwards one character and write a null. */ - if (lseek (dest_desc, (off_t) -1, SEEK_CUR) < 0L - || full_write (dest_desc, "", 1) < 0) -#endif - { - error (0, errno, "%s", dst_path); - return_val = -1; - } - } - -ret: - if (close (dest_desc) < 0) - { - error (0, errno, "%s", dst_path); - return_val = -1; - } -ret2: - if (close (source_desc) < 0) - { - error (0, errno, "%s", src_path); - return_val = -1; - } - - return return_val; -} diff --git a/camel/providers/MH/camel-mh-folder.h b/camel/providers/MH/camel-mh-folder.h deleted file mode 100644 index 40800375eb..0000000000 --- a/camel/providers/MH/camel-mh-folder.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-folder.h : Abstract class for an email folder */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#ifndef CAMEL_MH_FOLDER_H -#define CAMEL_MH_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-folder.h" -/* #include "camel-store.h" */ - -#define CAMEL_MH_FOLDER_TYPE (camel_mh_folder_get_type ()) -#define CAMEL_MH_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_MH_FOLDER_TYPE, CamelMhFolder)) -#define CAMEL_MH_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MH_FOLDER_TYPE, CamelMhFolderClass)) -#define IS_CAMEL_MH_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_MH_FOLDER_TYPE)) - - -typedef struct { - CamelFolder parent_object; - - gchar *directory_path; - GList *file_name_list; - GArray *uid_array; - -} CamelMhFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelMhFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mh_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MH_FOLDER_H */ diff --git a/camel/providers/MH/camel-mh-provider.c b/camel/providers/MH/camel-mh-provider.c deleted file mode 100644 index 316b8a0797..0000000000 --- a/camel/providers/MH/camel-mh-provider.c +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-provider.c: mh provider registration code */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "config.h" -#include "camel-mh-store.h" -#include "camel-provider.h" -#include "camel-log.h" - - -static CamelProvider _mh_provider = { - (GtkType) 0, - PROVIDER_STORE, - "mh", - "Camel default mh provider", - "This is a very simple provider, mh is a bad protocol anyway", - (GModule *) NULL -}; - - - -CamelProvider * -camel_provider_module_init () -{ - _mh_provider.object_type = camel_mh_store_get_type(); - return &_mh_provider; -} diff --git a/camel/providers/MH/camel-mh-store.c b/camel/providers/MH/camel-mh-store.c deleted file mode 100644 index 60ba07f47b..0000000000 --- a/camel/providers/MH/camel-mh-store.c +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mh-store.c : class for an mh store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "camel-mh-store.h" -#include "camel-mh-folder.h" -#include "url-util.h" - -static CamelStoreClass *parent_class=NULL; - -/* Returns the class for a CamelMhStore */ -#define CMHS_CLASS(so) CAMEL_MH_STORE_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMHF_CLASS(so) CAMEL_MH_FOLDER_CLASS (GTK_OBJECT(so)->klass) - -static void _init (CamelStore *store, CamelSession *session, const gchar *url_name); -static CamelFolder *_get_folder (CamelStore *store, const gchar *folder_name); - - -static void -camel_mh_store_class_init (CamelMhStoreClass *camel_mh_store_class) -{ - CamelStoreClass *camel_store_class = CAMEL_STORE_CLASS (camel_mh_store_class); - - parent_class = gtk_type_class (camel_store_get_type ()); - - /* virtual method definition */ - /* virtual method overload */ - camel_store_class->init = _init; - camel_store_class->get_folder = _get_folder; -} - - - -static void -camel_mh_store_init (gpointer object, gpointer klass) -{ - CamelMhStore *mh_store = CAMEL_MH_STORE (object); - CamelStore *store = CAMEL_STORE (object); - - store->separator = '/'; -} - - - - -GtkType -camel_mh_store_get_type (void) -{ - static GtkType camel_mh_store_type = 0; - - if (!camel_mh_store_type) { - GtkTypeInfo camel_mh_store_info = - { - "CamelMhStore", - sizeof (CamelMhStore), - sizeof (CamelMhStoreClass), - (GtkClassInitFunc) camel_mh_store_class_init, - (GtkObjectInitFunc) camel_mh_store_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_mh_store_type = gtk_type_unique (CAMEL_STORE_TYPE, &camel_mh_store_info); - } - - return camel_mh_store_type; -} - - - - -/* These evil public functions are here for test only */ -void -camel_mh_store_set_toplevel_dir (CamelMhStore *store, const gchar *toplevel) -{ - store->toplevel_dir = g_strdup (toplevel); - CAMEL_STORE(store)->separator = '/'; -} - - -const gchar * -camel_mh_store_get_toplevel_dir (CamelMhStore *store) -{ - return store->toplevel_dir; -} - - - -static void -_init (CamelStore *store, CamelSession *session, const gchar *url_name) -{ - CamelMhStore *mh_store = CAMEL_MH_STORE (store); - Gurl *store_url; - - g_assert (url_name); - /* call parent implementation */ - parent_class->init (store, session, url_name); - - - /* find the path in the URL*/ - store_url = g_url_new (url_name); - - g_return_if_fail (store_url); - g_return_if_fail (store_url->path); - - mh_store->toplevel_dir = g_strdup (store_url->path); - g_url_free (store_url); - - - -} - - -static CamelFolder * -_get_folder (CamelStore *store, const gchar *folder_name) -{ - CamelMhFolder *new_mh_folder; - CamelFolder *new_folder; - - /* check if folder has already been created */ - /* call the standard routine for that when */ - /* it is done ... */ - - new_mh_folder = gtk_type_new (CAMEL_MH_FOLDER_TYPE); - new_folder = CAMEL_FOLDER (new_mh_folder); - - CF_CLASS (new_folder)->init_with_store (new_folder, store, NULL); - CF_CLASS (new_folder)->set_name (new_folder, folder_name, NULL); - - - return new_folder; -} diff --git a/camel/providers/MH/camel-mh-store.h b/camel/providers/MH/camel-mh-store.h deleted file mode 100644 index 924a5a6fc5..0000000000 --- a/camel/providers/MH/camel-mh-store.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mhstore.h : class for an mh store */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#ifndef CAMEL_MH_STORE_H -#define CAMEL_MH_STORE_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include "camel-store.h" - -#define CAMEL_MH_STORE_TYPE (camel_mh_store_get_type ()) -#define CAMEL_MH_STORE(obj) (GTK_CHECK_CAST((obj), CAMEL_MH_STORE_TYPE, CamelMhStore)) -#define CAMEL_MH_STORE_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MH_STORE_TYPE, CamelMhStoreClass)) -#define IS_CAMEL_MH_STORE(o) (GTK_CHECK_TYPE((o), CAMEL_MH_STORE_TYPE)) - - -typedef struct { - CamelStore parent_object; - - gchar *toplevel_dir; -} CamelMhStore; - - - -typedef struct { - CamelStoreClass parent_class; - - -} CamelMhStoreClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mh_store_get_type (void); - -void camel_mh_store_set_toplevel_dir (CamelMhStore *store, const gchar *toplevel); -const gchar *camel_mh_store_get_toplevel_dir (CamelMhStore *store); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MH_STORE_H */ - - diff --git a/camel/providers/MH/mh-summary.c b/camel/providers/MH/mh-summary.c deleted file mode 100644 index 5a964696e0..0000000000 --- a/camel/providers/MH/mh-summary.c +++ /dev/null @@ -1,290 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#include <config.h> - -#include "mh-uid.h" -#include "camel-log.h" -#include "camel-stream.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "gmime-utils.h" -#include "mh-utils.h" - -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> - -void -mh_generate_summary (CamelFolder *folder) -{ - CamelMhFolder *mh_folder = CAMEL_MH_FOLDER (folder); - CamelFolderSummary *summary; - CamelMessageInfo *message_info; - CamelFolderInfo *subfolder_info; - CamelStream *message_stream; - guint file_number; - gchar *message_fullpath; - gchar *directory_path; - GArray *header_array; - MhUidCouple *uid_couple; - Rfc822Header *cur_header; - int i; - int n_file; - GArray *uid_array; - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary entering \n"); - - g_assert (folder); - - directory_path = mh_folder->directory_path; - if (!directory_path) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary folder has no directory path\n"); - return; - } - - summary = camel_folder_summary_new (); - folder->summary = summary; - - uid_array = mh_folder->uid_array; - - if (!uid_array) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary " - "no uid list, that probably means there is " - "no message in this folder, exiting \n"); - return; - } - uid_couple = (MhUidCouple *)uid_array->data; - - for (n_file=0; n_file<uid_array->len; n_file++) { - - file_number = uid_couple->file_number; - - message_info = g_new0 (CamelMessageInfo, 1); - message_info->uid = g_new0 (guchar, 17); - strncpy (message_info->uid, uid_couple->uid, 16); - - - message_fullpath = g_strdup_printf ("%s/%d", directory_path, file_number); - message_stream = camel_stream_buffered_fs_new_with_name (message_fullpath, - CAMEL_STREAM_BUFFERED_FS_READ); - if (!message_stream) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary " - "could not open %d for reading\n", message_fullpath); - g_free (message_fullpath); - return; - } - g_free (message_fullpath); - - header_array = get_header_array_from_stream (message_stream); - gtk_object_unref (GTK_OBJECT (message_stream)); - - for (i=0; i<header_array->len; i++) { - cur_header = (Rfc822Header *)header_array->data + i; - if (!g_strcasecmp (cur_header->name, "subject")) { - message_info->subject = cur_header->value; - g_free (cur_header->name); - } else if (!g_strcasecmp (cur_header->name, "sender")) { - message_info->date = cur_header->value; - g_free (cur_header->name); - } else if (!g_strcasecmp (cur_header->name, "date")) { - message_info->date = cur_header->value; - g_free (cur_header->name); - } else { - g_free (cur_header->name); - g_free (cur_header->value); - } - } - g_array_free (header_array, TRUE); - - summary->message_info_list = g_list_append (summary->message_info_list, message_info); - - /* next message in the uid list */ - uid_couple++; - } - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::generate_summary leaving \n"); - -} - - -void -mh_save_summary (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - CamelFolderSummary *summary; - GList *msg_info_list; - CamelMessageInfo *msg_info; - gchar *directory_path = mh_folder->directory_path; - gchar *summary_file_path; - gint fd; - gint i; - gint field_lgth; - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::save_summary entering \n"); - - summary = CAMEL_FOLDER (mh_folder)->summary; - if (!summary) return; - - summary_file_path = g_strdup_printf ("%s/%s", directory_path, ".camel-summary"); - CAMEL_LOG_FULL_DEBUG ("In the process of writing %s\n", summary_file_path); - fd = open (summary_file_path, O_WRONLY | O_CREAT ); - - if (!fd) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for writing. Exiting.\n", summary_file_path); - g_free (summary_file_path); - return; - } - g_free (summary_file_path); - - msg_info_list = summary->message_info_list; - while (msg_info_list) { - msg_info = msg_info_list->data; - /* write subject */ - field_lgth = msg_info->subject ? strlen (msg_info->subject) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->subject, field_lgth); - - /* write uid */ - field_lgth = msg_info->uid ? strlen (msg_info->uid) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->uid, field_lgth); - - /* write date */ - field_lgth = msg_info->date ? strlen (msg_info->date) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->date, field_lgth); - - /* write sender */ - field_lgth = msg_info->sender ? strlen (msg_info->sender) : 0; - write (fd, &field_lgth, sizeof (gint)); - if (field_lgth) - write (fd, msg_info->sender, field_lgth); - - msg_info_list = msg_info_list->next; - - } - - close (fd); - - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::save_summary leaving \n"); - -} - - - - - -gint -mh_load_summary (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - CamelFolderSummary *summary; - CamelMessageInfo *msg_info; - gchar *directory_path = mh_folder->directory_path; - gchar *summary_file_path; - gint fd; - gint i; - gint field_lgth; - gboolean file_eof; - gint stat_error; - struct stat stat_buf; - - summary = CAMEL_FOLDER (mh_folder)->summary; - if (summary) return 1; /* should we regenerate it ? */ - - summary_file_path = g_strdup_printf ("%s/%s", directory_path, ".camel-summary"); - CAMEL_LOG_FULL_DEBUG ("In the process of reading %s\n", summary_file_path); - fd = open (summary_file_path, O_RDONLY); - /* tests if file exists */ - stat_error = stat (summary_file_path, &stat_buf); - - if (!((stat_error != -1) && S_ISREG (stat_buf.st_mode))) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for reading. Exiting.\n", summary_file_path); - g_free (summary_file_path); - return -1; - } - g_free (summary_file_path); - - for (;;) { - /* read subject */ - file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (file_eof) break; - - - /* allcate a summary if needed */ - if (!summary) - summary = camel_folder_summary_new (); - /* allocate a message info struct */ - msg_info = g_new0 (CamelMessageInfo, 1); - - if (!file_eof && (field_lgth > 0)) { - msg_info->subject = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->subject, field_lgth); - } else - msg_info->subject = NULL; - - /* read uid */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->uid = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->uid, field_lgth); - } else - msg_info->uid = NULL; - - /* read date */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->date = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->date, field_lgth); - } else - msg_info->date = NULL; - - /* read sender */ - if (!file_eof) file_eof = (read (fd, &field_lgth, sizeof (gint)) <= 0); - if (!file_eof && (field_lgth > 0)) { - msg_info->sender = g_new0 (gchar, field_lgth + 1); - read (fd, msg_info->sender, field_lgth); - } else - msg_info->sender = NULL; - - summary->message_info_list = g_list_prepend (summary->message_info_list, - msg_info); - } - - CAMEL_FOLDER (mh_folder)->summary = summary; - - close (fd); - return 1; -} - - diff --git a/camel/providers/MH/mh-summary.h b/camel/providers/MH/mh-summary.h deleted file mode 100644 index 27c9a21f60..0000000000 --- a/camel/providers/MH/mh-summary.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef MH_SUMMARY_H -#define MH_SUMMARY_H 1 - -#include <glib.h> -#include "camel-mh-folder.h" - -void mh_generate_summary (CamelFolder *folder); -void mh_save_summary (CamelMhFolder *mh_folder); -gint mh_load_summary (CamelMhFolder *mh_folder); - -#endif /* MH_SUMMARY_H */ diff --git a/camel/providers/MH/mh-uid.c b/camel/providers/MH/mh-uid.c deleted file mode 100644 index ebcccacd23..0000000000 --- a/camel/providers/MH/mh-uid.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#include <config.h> - -#include "mh-uid.h" -#include "camel-log.h" -#include "camel-stream.h" -#include "camel-stream-fs.h" -#include "camel-stream-buffered-fs.h" -#include "gmime-utils.h" -#include "md5-utils.h" -#include "mh-utils.h" - -#include <sys/stat.h> -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> - -void -mh_uid_get_for_file (gchar *filename, guchar uid[16]) -{ - CamelStream *message_stream; - GArray *header_array; - Rfc822Header *cur_header; - int i; - MD5Context ctx; - - - message_stream = camel_stream_buffered_fs_new_with_name (filename, - CAMEL_STREAM_BUFFERED_FS_READ); - header_array = get_header_array_from_stream (message_stream); - gtk_object_unref (GTK_OBJECT (message_stream)); - - md5_init (&ctx); - for (i=0; i<header_array->len; i++) { - cur_header = (Rfc822Header *)header_array->data + i; - if (!g_strcasecmp (cur_header->name, "subject")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } else if (!g_strcasecmp (cur_header->name, "sender")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } else if (!g_strcasecmp (cur_header->name, "date")) { - md5_update (&ctx, cur_header->value, strlen (cur_header->value)); - } - - g_free (cur_header->name); - g_free (cur_header->value); - - } - - g_array_free (header_array, TRUE); - - md5_final (&ctx, uid); -} - - - - -void -mh_save_uid_list (CamelMhFolder *mh_folder) -{ - GArray *uid_array; - MhUidCouple *first_uid_couple; - gchar *directory_path = mh_folder->directory_path; - gchar *uidfile_path; - int fd; - int i; - - - uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); - CAMEL_LOG_FULL_DEBUG ("In the process of writing %s\n", uidfile_path); - fd = open (uidfile_path, O_WRONLY | O_CREAT ); - - if (!fd) { - CAMEL_LOG_FULL_DEBUG ("could not open file %s for writing. Exiting.\n", uidfile_path); - g_free (uidfile_path); - return; - } - g_free (uidfile_path); - - uid_array = mh_folder->uid_array; - first_uid_couple = (MhUidCouple *)uid_array->data; - - /* write the number of uid contained in the file */ - write (fd, &(uid_array->len), sizeof (guint)); - CAMEL_LOG_FULL_DEBUG ("%d entrie present in the list\n", uid_array->len); - /* now write the array of uid self */ - write (fd, first_uid_couple, sizeof (MhUidCouple) * uid_array->len); - - close (fd); -} - - -gint -mh_load_uid_list (CamelMhFolder *mh_folder) -{ - GArray *new_uid_array; - MhUidCouple *first_uid_couple; - gchar *directory_path = mh_folder->directory_path; - gchar *uidfile_path; - int fd; - guint uid_nb; - struct stat stat_buf; - gint stat_error = 0; - - uidfile_path = g_strdup_printf ("%s/%s", directory_path, ".camel-uid-list"); - - /* tests if file exists */ - stat_error = stat (uidfile_path, &stat_buf); - - - if (!((stat_error != -1) && S_ISREG (stat_buf.st_mode))) { - CAMEL_LOG_FULL_DEBUG ("CamelMhFolder::load_uid_list " - "file %s does not exist. Exiting.\n", uidfile_path); - g_free (uidfile_path); - return -1; - } - - fd = open (uidfile_path, O_RDONLY); - g_free (uidfile_path); - if (!fd) return -1; - - if (mh_folder->uid_array) g_array_free (mh_folder->uid_array, FALSE); - - /* read the number of uids in the file */ - read (fd, &uid_nb, sizeof (guint)); - CAMEL_LOG_FULL_DEBUG ("reading %d uid_entries\n", uid_nb); - new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); - new_uid_array = g_array_set_size (new_uid_array, uid_nb); - first_uid_couple = (MhUidCouple *)new_uid_array->data; - - - read (fd, first_uid_couple, sizeof (MhUidCouple) * uid_nb); - - mh_folder->uid_array = new_uid_array; - - return 1; -} - - -gint -mh_generate_uid_list (CamelMhFolder *mh_folder) -{ - GArray *new_uid_array; - const gchar *directory_path; - struct dirent *dir_entry; - DIR *dir_handle; - gchar *msg_path; - guint msg_count; - MhUidCouple *uid_couple; - guint file_number; - - g_assert (mh_folder); - CAMEL_LOG_FULL_DEBUG ("in the process of creating uid list \n"); - directory_path = mh_folder->directory_path; - if (!directory_path) { - CAMEL_LOG_FULL_DEBUG ("folder has no directory path. Exiting\n"); - return -1; - } - - msg_count = camel_folder_get_message_count (CAMEL_FOLDER (mh_folder), NULL); - if (!msg_count) { - CAMEL_LOG_FULL_DEBUG ("no message in %s. Exiting\n", directory_path); - return -1; - } - - new_uid_array = g_array_new (FALSE, FALSE, sizeof (MhUidCouple)); - new_uid_array = g_array_set_size (new_uid_array, msg_count); - uid_couple = (MhUidCouple *)new_uid_array->data; - - dir_handle = opendir (directory_path); - - /* read first entry in the directory */ - dir_entry = readdir (dir_handle); - while (dir_entry != NULL) { - - /* tests if the entry correspond to a message file */ - if (mh_is_a_message_file (dir_entry->d_name, directory_path)) { - - /* get the uid for this message */ - msg_path = g_strdup_printf ("%s/%s", directory_path, dir_entry->d_name); - mh_uid_get_for_file (msg_path, uid_couple->uid); - g_free (msg_path); - - /* convert filename into file number */ - uid_couple->file_number = atoi (dir_entry->d_name); - uid_couple++; - } - - /* read next entry */ - dir_entry = readdir (dir_handle); - } - - closedir (dir_handle); - mh_folder->uid_array = new_uid_array; -} diff --git a/camel/providers/MH/mh-uid.h b/camel/providers/MH/mh-uid.h deleted file mode 100644 index 63dfe5b159..0000000000 --- a/camel/providers/MH/mh-uid.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef MH_UID_H -#define MH_UID_H 1 - -#include <glib.h> -#include "camel-mh-folder.h" - - -typedef struct { - gchar uid[16]; - guint file_number; -} MhUidCouple; - -void mh_uid_get_for_file (gchar *filename, guchar uid[16]); -void mh_save_uid_list (CamelMhFolder *mh_folder); -gint mh_load_uid_list (CamelMhFolder *mh_folder); -gint mh_generate_uid_list (CamelMhFolder *mh_folder); - -#endif /* MH_UID_H */ diff --git a/camel/providers/MH/mh-utils.c b/camel/providers/MH/mh-utils.c deleted file mode 100644 index 51bb84bc65..0000000000 --- a/camel/providers/MH/mh-utils.c +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include <config.h> -#include "mh-utils.h" - -#include <sys/stat.h> - -gboolean -mh_is_a_message_file (const gchar *file_name, const gchar *file_path) -{ - struct stat stat_buf; - gint stat_error = 0; - gboolean ok; - gchar *full_file_name; - int i; - - /* test if the name is a number */ - i=0; - while ((file_name[i] != '\0') && (file_name[i] >= '0') && (file_name[i] <= '9')) - i++; - if ((i==0) || (file_name[i] != '\0')) return FALSE; - - /* is it a regular file ? */ - full_file_name = g_strdup_printf ("%s/%s", file_path, file_name); - stat_error = stat (full_file_name, &stat_buf); - g_free (full_file_name); - - return ((stat_error != -1) && S_ISREG (stat_buf.st_mode)); -} - diff --git a/camel/providers/MH/mh-utils.h b/camel/providers/MH/mh-utils.h deleted file mode 100644 index 968228b0a3..0000000000 --- a/camel/providers/MH/mh-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * - * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef MH_UTILS_H -#define MH_UTILS_H 1 - -#include <glib.h> - -gboolean mh_is_a_message_file (const gchar *file_name, const gchar *file_path); - -#endif /* MH_UTILS_H */ diff --git a/camel/providers/Makefile.am b/camel/providers/Makefile.am deleted file mode 100644 index a1af905e6b..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 - -# these ones are disabled for the moment. -# MH maildir nntp 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 07f05d443b..0000000000 --- a/camel/providers/maildir/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmaildirincludedir = $(includedir)/camel - -lib_LTLIBRARIES = libcamelmaildir.la - -INCLUDES = -I.. -I$(srcdir)/.. -I$(top_srcdir)/intl -I$(top_srcdir)/camel \ - $(GTK_INCLUDEDIR) -I$(includedir) \ - -DG_LOG_DOMAIN=\"camel-maildir-provider\" - -libcamelmaildir_la_SOURCES = \ - camel-maildir-folder.c \ - camel-maildir-provider.c \ - camel-maildir-store.c - -libcamelmaildirinclude_HEADERS = \ - camel-maildir-folder.h \ - camel-maildir-store.h - -libcamelmaildir_la_LDFLAGS = -version-info 0:0:0 -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 defd6925cc..0000000000 --- a/camel/providers/mbox/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelmboxincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelmbox.la -provider_DATA = libcamelmbox.urls - -INCLUDES = -I.. \ - -I$(srcdir)/.. \ - -I$(top_srcdir)/camel \ - -I$(top_srcdir)/intl \ - -I$(top_srcdir)/libibex \ - -I$(top_srcdir)/e-util \ - -I$(top_srcdir) \ - -I$(includedir) \ - $(GTK_INCLUDEDIR) \ - -DG_LOG_DOMAIN=\"camel-mbox-provider\" - -libcamelmbox_la_SOURCES = \ - camel-mbox-folder.c \ - camel-mbox-provider.c \ - camel-mbox-store.c \ - camel-mbox-summary.c - -libcamelmboxinclude_HEADERS = \ - camel-mbox-folder.h \ - camel-mbox-store.h \ - camel-mbox-summary.h - -libcamelmbox_la_LDFLAGS = -version-info 0:0:0 -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 = libcamelmbox.urls - diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c deleted file mode 100644 index 3403271e40..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.c +++ /dev/null @@ -1,970 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */ -/* camel-mbox-folder.c : Abstract class for an email folder */ - -/* - * Authors: Bertrand Guiheneuf <bertrand@helixcode.com> - * Michael Zucchi <notzed@helixcode.com> - * - * Copyright (C) 1999, 2000 Helix Code Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#include <config.h> - -#include <stdlib.h> -#include <sys/types.h> -#include <dirent.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <fcntl.h> - -#include "camel-mbox-folder.h" -#include "camel-mbox-store.h" -#include "string-utils.h" -#include "camel-stream-fs.h" -#include "camel-mbox-summary.h" -#include "camel-data-wrapper.h" -#include "camel-mime-message.h" -#include "camel-stream-filter.h" -#include "camel-mime-filter-from.h" -#include "camel-exception.h" - -#define d(x) - -static CamelFolderClass *parent_class=NULL; - -/* Returns the class for a CamelMboxFolder */ -#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CF_CLASS(so) CAMEL_FOLDER_CLASS (GTK_OBJECT(so)->klass) -#define CMBOXS_CLASS(so) CAMEL_STORE_CLASS (GTK_OBJECT(so)->klass) - - -static void mbox_init (CamelFolder *folder, CamelStore *parent_store, - CamelFolder *parent_folder, const gchar *name, - gchar separator, CamelException *ex); - -static void mbox_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); -static void mbox_close (CamelFolder *folder, gboolean expunge, CamelException *ex); -static gboolean mbox_exists (CamelFolder *folder, CamelException *ex); -static gboolean mbox_create(CamelFolder *folder, CamelException *ex); -static gboolean mbox_delete (CamelFolder *folder, gboolean recurse, CamelException *ex); -static gboolean mbox_delete_messages (CamelFolder *folder, CamelException *ex); -static GList *mbox_list_subfolders (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *mbox_get_message_by_number (CamelFolder *folder, gint number, CamelException *ex); -static gint mbox_get_message_count (CamelFolder *folder, CamelException *ex); -static void mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex); -static GList *mbox_get_uid_list (CamelFolder *folder, CamelException *ex); -static CamelMimeMessage *mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex); - -static void mbox_expunge (CamelFolder *folder, CamelException *ex); -#if 0 -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 const CamelMessageInfo *mbox_summary_get_by_uid(CamelFolder *f, const char *uid); - -static GList *mbox_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex); - -static void mbox_finalize (GtkObject *object); - -static void -camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class) -{ - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_mbox_folder_class); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (camel_folder_class); - - parent_class = gtk_type_class (camel_folder_get_type ()); - - /* virtual method definition */ - - /* virtual method overload */ - camel_folder_class->init = mbox_init; - camel_folder_class->open = mbox_open; - camel_folder_class->close = mbox_close; - camel_folder_class->exists = mbox_exists; - camel_folder_class->create = mbox_create; - camel_folder_class->delete = mbox_delete; - camel_folder_class->delete_messages = mbox_delete_messages; - camel_folder_class->list_subfolders = mbox_list_subfolders; - camel_folder_class->get_message_by_number = mbox_get_message_by_number; - camel_folder_class->get_message_count = mbox_get_message_count; - camel_folder_class->append_message = mbox_append_message; - camel_folder_class->get_uid_list = mbox_get_uid_list; - camel_folder_class->expunge = mbox_expunge; -#if 0 - 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 = mbox_get_message_by_uid; - - camel_folder_class->search_by_expression = mbox_search_by_expression; - - camel_folder_class->get_message_info = summary_get_message_info; - camel_folder_class->summary_get_by_uid = mbox_summary_get_by_uid; - - gtk_object_class->finalize = mbox_finalize; - -} - -static void -mbox_finalize (GtkObject *object) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (object); - - g_free (mbox_folder->folder_file_path); - g_free (mbox_folder->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 -mbox_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; - - folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | - CAMEL_MESSAGE_DELETED | - CAMEL_MESSAGE_DRAFT | - CAMEL_MESSAGE_FLAGGED | - CAMEL_MESSAGE_SEEN; - - mbox_folder->summary = NULL; - mbox_folder->search = NULL; - - /* now set the name info */ - g_free (mbox_folder->folder_file_path); - g_free (mbox_folder->folder_dir_path); - g_free (mbox_folder->index_file_path); - - root_dir_path = camel_mbox_store_get_toplevel_dir (CAMEL_MBOX_STORE(folder->parent_store)); - - 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 -mbox_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - int forceindex; - struct stat st; - - /* call parent class */ - parent_class->open (folder, mode, ex); - if (camel_exception_get_id(ex)) - return; - - /* if we have no index file, force it */ - forceindex = stat(mbox_folder->index_file_path, &st) == -1; - - printf("loading ibex\n"); - mbox_folder->index = ibex_open(mbox_folder->index_file_path, O_CREAT|O_RDWR, 0600); - printf("loaded ibex\n"); - if (mbox_folder->index == NULL) { - /* yes, this isn't fatal at all */ - g_warning("Could not open/create index file: %s: indexing not performed", - strerror(errno)); - } - - /* no summary (disk or memory), and we're proverbially screwed */ - printf("loading summary\n"); - mbox_folder->summary = camel_mbox_summary_new(mbox_folder->summary_file_path, mbox_folder->folder_file_path, mbox_folder->index); - if (mbox_folder->summary == NULL - || camel_mbox_summary_load(mbox_folder->summary, forceindex) == -1) { - camel_exception_set (ex, - CAMEL_EXCEPTION_FOLDER_INVALID, /* FIXME: right error code */ - "Could not create summary"); - return; - } - printf("summary loaded\n"); -} - -static void -mbox_close (CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - - /* call parent implementation */ - parent_class->close (folder, expunge, ex); - - if (expunge) { - mbox_expunge(folder, ex); - } - - /* save index */ - if (mbox_folder->index) { - ibex_close(mbox_folder->index); - mbox_folder->index = NULL; - } - if (mbox_folder->summary) { - camel_folder_summary_save ((CamelFolderSummary *)mbox_folder->summary); - gtk_object_unref((GtkObject *)mbox_folder->summary); - mbox_folder->summary = NULL; - } - if (mbox_folder->search) { - gtk_object_unref((GtkObject *)mbox_folder->search); - mbox_folder->search = NULL; - } -} - -static void -mbox_expunge (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox = (CamelMboxFolder *)folder; - - if (camel_mbox_summary_expunge(mbox->summary) == -1) { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, /* FIXME: right error code */ - "Could not expunge: %s", strerror(errno)); - } - - /* TODO: check it actually changed */ - gtk_signal_emit_by_name((GtkObject *)folder, "folder_changed", 0); -} - -/* FIXME: clean up this snot */ -static gboolean -mbox_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 -mbox_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 -mbox_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 -mbox_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 * -mbox_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 -mbox_get_message_count (CamelFolder *folder, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - - g_assert (folder); - g_assert (mbox_folder->summary); - - return camel_folder_summary_count((CamelFolderSummary *)mbox_folder->summary); -} - -/* FIXME: this may need some tweaking for performance? */ -static void -mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - CamelStream *output_stream = NULL, *filter_stream = NULL; - CamelMimeFilter *filter_from; - struct stat st; - off_t seek = -1; - char *xev; - guint32 uid; - - if (stat(mbox_folder->folder_file_path, &st) != 0) - goto fail; - - output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDWR, 0600, ex); - if (output_stream == NULL) - goto fail; - - seek = camel_seekable_stream_seek((CamelSeekableStream *)output_stream, st.st_size, SEEK_SET, ex); - if (seek != st.st_size) - goto fail; - - /* assign a new x-evolution header/uid */ - camel_medium_remove_header((CamelMedium *)message, "X-Evolution"); - uid = camel_folder_summary_next_uid((CamelFolderSummary *)mbox_folder->summary); - xev = g_strdup_printf("%08x-%04x", uid, message->flags & 0xffff); - camel_medium_add_header((CamelMedium *)message, "X-Evolution", xev); - g_free(xev); - - /* we must write this to the non-filtered stream ... */ - if (camel_stream_write_string (output_stream, "From - \n", ex) == -1) - goto fail; - - /* and write the content to the filtering stream, that translated '\nFrom' into '\n>From' */ - filter_stream = (CamelStream *)camel_stream_filter_new_with_stream(output_stream); - filter_from = (CamelMimeFilter *)camel_mime_filter_from_new(); - camel_stream_filter_add((CamelStreamFilter *)filter_stream, filter_from); - camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), filter_stream, ex); -#warning "we still need stream_close() for this" - if (!camel_exception_is_set (ex)) - camel_stream_flush (filter_stream, ex); - - if (camel_exception_is_set (ex)) - goto fail; - - /* filter stream ref's the output stream itself, so we need to unref it too */ - gtk_object_unref (GTK_OBJECT (filter_from)); - gtk_object_unref (GTK_OBJECT (filter_stream)); - gtk_object_unref (GTK_OBJECT (output_stream)); - - /* force a summary update - will only update from the new position, if it can */ - camel_mbox_summary_update(mbox_folder->summary, seek); - return; - -fail: - if (camel_exception_is_set (ex)) { - camel_exception_setv (ex, camel_exception_get_id (ex), - "Cannot append message to mbox file: %s", - camel_exception_get_description (ex)); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot append message to mbox file: %s", - g_strerror (errno)); - } - if (filter_stream) { - /*camel_stream_close (filter_stream);*/ - gtk_object_unref ((GtkObject *)filter_stream); - } - if (output_stream) - gtk_object_unref ((GtkObject *)output_stream); - - /* make sure the file isn't munged by us */ - if (seek != -1) { - int fd = open(mbox_folder->folder_file_path, O_WRONLY, 0600); - if (fd != -1) { - ftruncate(fd, st.st_size); - close(fd); - } - } -} - -static GList * -mbox_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_folder_summary_count((CamelFolderSummary *)mbox_folder->summary); - for (i=0;i<count;i++) { - CamelMboxMessageInfo *info = (CamelMboxMessageInfo *)camel_folder_summary_index((CamelFolderSummary *)mbox_folder->summary, i); - uid_list = g_list_prepend(uid_list, g_strdup(info->info.uid)); - } - - return uid_list; -} - -static CamelMimeMessage * -mbox_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 = (CamelMboxMessageInfo *)camel_folder_summary_index((CamelFolderSummary *)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 mbox_get_message_by_uid (folder, info->info.uid, ex); -} - -/* track flag changes in the summary */ -static void -message_changed(CamelMimeMessage *m, int type, CamelMboxFolder *mf) -{ - CamelMessageInfo *info; - - printf("Message changed: %s: %d\n", m->message_uid, type); - switch (type) { - case MESSAGE_FLAGS_CHANGED: - info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, m->message_uid); - if (info) { - info->flags = m->flags | CAMEL_MESSAGE_FOLDER_FLAGGED; - camel_folder_summary_touch((CamelFolderSummary *)mf->summary); - } else - g_warning("Message changed event on message not in summary: %s", m->message_uid); - break; - default: - printf("Unhandled message change event: %d\n", type); - break; - } -} - -static CamelMimeMessage * -mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder); - CamelStream *message_stream = NULL; - CamelMimeMessage *message = NULL; - CamelMboxMessageInfo *info; - CamelMimeParser *parser = NULL; - char *buffer; - int len; - - /* get the message summary info */ - info = (CamelMboxMessageInfo *)camel_folder_summary_uid((CamelFolderSummary *)mbox_folder->summary, uid); - - if (info == NULL) { - errno = ENOENT; - goto fail; - } - - /* if this has no content, its an error in the library */ - g_assert(info->info.content); - g_assert(info->frompos != -1); - - /* where we read from */ - message_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDONLY, 0, ex); - if (message_stream == NULL) - goto fail; - - /* we use a parser to verify the message is correct, and in the correct position */ - parser = camel_mime_parser_new(); - camel_mime_parser_init_with_stream(parser, message_stream); - gtk_object_unref((GtkObject *)message_stream); - camel_mime_parser_scan_from(parser, TRUE); - - camel_mime_parser_seek(parser, info->frompos, SEEK_SET); - if (camel_mime_parser_step(parser, &buffer, &len) != HSCAN_FROM) { - g_warning("File appears truncated"); - goto fail; - } - - if (camel_mime_parser_tell_start_from(parser) != info->frompos) { - g_warning("Summary doesn't match the folder contents! eek!"); - errno = EINVAL; - goto fail; - } - - message = camel_mime_message_new(); - if (camel_mime_part_construct_from_parser((CamelMimePart *)message, parser) == -1) { - g_warning("Construction failed"); - goto fail; - } - - /* we're constructed, finish setup and clean up */ - message->folder = folder; - gtk_object_ref((GtkObject *)folder); - message->message_uid = g_strdup(uid); - message->flags = info->info.flags; - gtk_signal_connect((GtkObject *)message, "message_changed", message_changed, folder); - - gtk_object_unref((GtkObject *)parser); - - return message; - -fail: - if (camel_exception_is_set (ex)) { - camel_exception_setv (ex, camel_exception_get_id (ex), - "Cannot get message: %s", - camel_exception_get_description (ex)); - } else { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - "Cannot get message: %s", - g_strerror(errno)); - } - if (parser) - gtk_object_unref((GtkObject *)parser); - if (message) - gtk_object_unref((GtkObject *)message); - - return NULL; -} - -/* 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_folder_summary_count((CamelFolderSummary *)mbox_folder->summary); - maxcount = MIN(count, maxcount); - for (i=first;i<maxcount;i++) - g_ptr_array_add(array, camel_folder_summary_index((CamelFolderSummary *)mbox_folder->summary, i)); - - return array; -} - -/* get a single message info, by uid */ -static const CamelMessageInfo * -mbox_summary_get_by_uid(CamelFolder *f, const char *uid) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)f; - - return camel_folder_summary_uid((CamelFolderSummary *)mbox_folder->summary, uid); -} - -static GList * -mbox_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex) -{ - CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder; - - if (mbox_folder->search == NULL) { - mbox_folder->search = camel_folder_search_new(); - } - - camel_folder_search_set_folder(mbox_folder->search, folder); - if (mbox_folder->summary) - /* FIXME: dont access summary array directly? */ - camel_folder_search_set_summary(mbox_folder->search, ((CamelFolderSummary *)mbox_folder->summary)->messages); - camel_folder_search_set_body_index(mbox_folder->search, mbox_folder->index); - - return camel_folder_search_execute_expression(mbox_folder->search, expression, ex); -} diff --git a/camel/providers/mbox/camel-mbox-folder.h b/camel/providers/mbox/camel-mbox-folder.h deleted file mode 100644 index d7dc361f14..0000000000 --- a/camel/providers/mbox/camel-mbox-folder.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-folder.h : Abstract class for an email folder */ - -/* - * - * Author : Bertrand Guiheneuf <bertrand@helixcode.com> - * - * Copyright (C) 1999 Helix Code . - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - - -#ifndef CAMEL_MBOX_FOLDER_H -#define CAMEL_MBOX_FOLDER_H 1 - - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus }*/ - -#include <gtk/gtk.h> -#include <camel/camel-folder.h> -#include <camel/camel-folder-search.h> -#include <libibex/ibex.h> -#include "camel-mbox-summary.h" - -/* #include "camel-store.h" */ - -#define CAMEL_MBOX_FOLDER_TYPE (camel_mbox_folder_get_type ()) -#define CAMEL_MBOX_FOLDER(obj) (GTK_CHECK_CAST((obj), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolder)) -#define CAMEL_MBOX_FOLDER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_MBOX_FOLDER_TYPE, CamelMboxFolderClass)) -#define IS_CAMEL_MBOX_FOLDER(o) (GTK_CHECK_TYPE((o), CAMEL_MBOX_FOLDER_TYPE)) - -typedef struct { - CamelFolder parent_object; - - gchar *folder_file_path; /* contains the messages */ - gchar *summary_file_path; /* contains the messages summary */ - gchar *folder_dir_path; /* contains the subfolders */ - gchar *index_file_path; /* index of body contents */ - - ibex *index; /* index for this folder */ - CamelMboxSummary *summary; - CamelFolderSearch *search; /* used to run searches, we just use the real thing (tm) */ -} CamelMboxFolder; - - - -typedef struct { - CamelFolderClass parent_class; - - /* Virtual methods */ - -} CamelMboxFolderClass; - - -/* public methods */ - -/* Standard Gtk function */ -GtkType camel_mbox_folder_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_MBOX_FOLDER_H */ diff --git a/camel/providers/mbox/camel-mbox-provider.c b/camel/providers/mbox/camel-mbox-provider.c deleted file mode 100644 index 04ce88de12..0000000000 --- a/camel/providers/mbox/camel-mbox-provider.c +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-mbox-provider.c: mbox provider registration code */ - -/* - * Authors : - * Bertrand Guiheneuf <bertrand@helixcode.com> - * - * Copyright (C) 2000 HelixCode (www.helixcode.com). - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "config.h" -#include "camel-mbox-store.h" -#include "camel-provider.h" -#include "camel-session.h" - -static CamelProvider mbox_provider = { - "mbox", - "UNIX mbox-format mail files", - - "For reading mail delivered by the local system, and for " - "storing mail on local disk.", - - 0, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - mbox_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_mbox_store_get_type(); - - camel_session_register_provider (session, &mbox_provider); -} diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c deleted file mode 100644 index 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 56ff1cb198..0000000000 --- a/camel/providers/mbox/camel-mbox-summary.c +++ /dev/null @@ -1,733 +0,0 @@ -/* - * Copyright (C) 2000 Helix Code Inc. - * - * Authors: Michael Zucchi <notzed@helixcode.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "camel-mbox-summary.h" -#include <camel/camel-mime-message.h> - -#include <sys/stat.h> -#include <sys/uio.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -#define io(x) -#define d(x) - -#define CAMEL_MBOX_SUMMARY_VERSION (0x1000) - -struct _CamelMboxSummaryPrivate { -}; - -#define _PRIVATE(o) (((CamelMboxSummary *)(o))->priv) - -static int summary_header_load(CamelFolderSummary *, FILE *); -static int summary_header_save(CamelFolderSummary *, FILE *); - -static CamelMessageInfo * message_info_new(CamelFolderSummary *, struct _header_raw *); -static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *); -static CamelMessageInfo * message_info_load(CamelFolderSummary *, FILE *); -static int message_info_save(CamelFolderSummary *, FILE *, CamelMessageInfo *); -/*static void message_info_free(CamelFolderSummary *, CamelMessageInfo *);*/ - -static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass); -static void camel_mbox_summary_init (CamelMboxSummary *obj); -static void camel_mbox_summary_finalise (GtkObject *obj); - -static CamelFolderSummaryClass *camel_mbox_summary_parent; - -enum SIGNALS { - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -guint -camel_mbox_summary_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "CamelMboxSummary", - sizeof (CamelMboxSummary), - sizeof (CamelMboxSummaryClass), - (GtkClassInitFunc) camel_mbox_summary_class_init, - (GtkObjectInitFunc) camel_mbox_summary_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (camel_folder_summary_get_type (), &type_info); - } - - return type; -} - -static void -camel_mbox_summary_class_init (CamelMboxSummaryClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - CamelFolderSummaryClass *sklass = (CamelFolderSummaryClass *) klass; - - camel_mbox_summary_parent = gtk_type_class (camel_folder_summary_get_type ()); - - object_class->finalize = camel_mbox_summary_finalise; - - sklass->summary_header_load = summary_header_load; - sklass->summary_header_save = summary_header_save; - - sklass->message_info_new = message_info_new; - sklass->message_info_new_from_parser = message_info_new_from_parser; - sklass->message_info_load = message_info_load; - sklass->message_info_save = message_info_save; - /*sklass->message_info_free = message_info_free;*/ - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -camel_mbox_summary_init (CamelMboxSummary *obj) -{ - struct _CamelMboxSummaryPrivate *p; - struct _CamelFolderSummary *s = (CamelFolderSummary *)obj; - - p = _PRIVATE(obj) = g_malloc0(sizeof(*p)); - - /* subclasses need to set the right instance data sizes */ - s->message_info_size = sizeof(CamelMboxMessageInfo); - s->content_info_size = sizeof(CamelMboxMessageContentInfo); - - /* and a unique file version */ - s->version = CAMEL_MBOX_SUMMARY_VERSION; -} - -static void -camel_mbox_summary_finalise (GtkObject *obj) -{ - CamelMboxSummary *mbs = (CamelMboxSummary *)obj; - - g_free(mbs->folder_path); - - ((GtkObjectClass *)(camel_mbox_summary_parent))->finalize((GtkObject *)obj); -} - -/** - * camel_mbox_summary_new: - * - * Create a new CamelMboxSummary object. - * - * Return value: A new CamelMboxSummary widget. - **/ -CamelMboxSummary * -camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index) -{ - CamelMboxSummary *new = CAMEL_MBOX_SUMMARY ( gtk_type_new (camel_mbox_summary_get_type ())); - if (new) { - /* ?? */ - camel_folder_summary_set_build_content((CamelFolderSummary *)new, TRUE); - camel_folder_summary_set_filename((CamelFolderSummary *)new, filename); - new->folder_path = g_strdup(mbox_name); - new->index = index; - } - return new; -} - - -static int summary_header_load(CamelFolderSummary *s, FILE *in) -{ - CamelMboxSummary *mbs = (CamelMboxSummary *)s; - - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s, in) == -1) - return -1; - - return camel_folder_summary_decode_uint32(in, &mbs->folder_size); -} - -static int summary_header_save(CamelFolderSummary *s, FILE *out) -{ - CamelMboxSummary *mbs = (CamelMboxSummary *)s; - - if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save(s, out) == -1) - return -1; - - return camel_folder_summary_encode_uint32(out, mbs->folder_size); -} - -static int -header_evolution_decode(const char *in, guint32 *uid, guint32 *flags) -{ - char *header; - if (in - && (header = header_token_decode(in))) { - if (strlen(header) == strlen("00000000-0000") - && sscanf(header, "%08x-%04x", uid, flags) == 2) { - g_free(header); - return *uid; - } - g_free(header); - } - - return -1; -} - -static char * -header_evolution_encode(guint32 uid, guint32 flags) -{ - return g_strdup_printf("%08x-%04x", uid, flags & 0xffff); -} - -static CamelMessageInfo * message_info_new(CamelFolderSummary *s, struct _header_raw *h) -{ - CamelMessageInfo *mi; - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new(s, h); - if (mi) { - const char *xev; - guint32 uid, flags; - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - xev = header_raw_find(&h, "X-Evolution", NULL); - if (xev - && header_evolution_decode(xev, &uid, &flags) != -1) { - g_free(mi->uid); - mi->uid = g_strdup_printf("%u", uid); - mi->flags = flags; - } else { - /* to indicate it has no xev header? */ - mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED|CAMEL_MESSAGE_FOLDER_NOXEV; - mi->uid = g_strdup_printf("%u", camel_folder_summary_next_uid(s)); - } - mbi->frompos = -1; - } - return mi; -} - -static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser *mp) -{ - CamelMessageInfo *mi; - CamelMboxSummary *mbs = (CamelMboxSummary *)s; - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser(s, mp); - if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - mbi->frompos = camel_mime_parser_tell_start_from(mp); - - /* do we want to index this message as we add it, as well? */ - if (mbs->index_force - || (mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0 - || !ibex_contains_name(mbs->index, mi->uid)) { - camel_folder_summary_set_index(s, mbs->index); - } else { - camel_folder_summary_set_index(s, NULL); - } - } - return mi; -} - -static CamelMessageInfo * message_info_load(CamelFolderSummary *s, FILE *in) -{ - CamelMessageInfo *mi; - - io(printf("loading mbox message info\n")); - - mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load(s, in); - if (mi) { - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - camel_folder_summary_decode_uint32(in, &mbi->frompos); - } - return mi; -} - -static int message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi) -{ - CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi; - - io(printf("saving mbox message info\n")); - - ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save(s, out, mi); - - return camel_folder_summary_encode_uint32(out, mbi->frompos); -} - -static int -summary_rebuild(CamelMboxSummary *mbs, off_t offset) -{ - CamelMimeParser *mp; - int fd; - int ok = 0; - - printf("(re)Building summary from %d (%s)\n", (int)offset, mbs->folder_path); - - fd = open(mbs->folder_path, O_RDONLY); - mp = camel_mime_parser_new(); - camel_mime_parser_init_with_fd(mp, fd); - camel_mime_parser_scan_from(mp, TRUE); - camel_mime_parser_seek(mp, offset, SEEK_SET); - - if (offset > 0) { - if (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) { - if (camel_mime_parser_tell_start_from(mp) != offset) { - g_warning("The next message didn't start where I expected\nbuilding summary from start"); - camel_mime_parser_drop_step(mp); - offset = 0; - camel_mime_parser_seek(mp, offset, SEEK_SET); - camel_folder_summary_clear((CamelFolderSummary *)mbs); - } else { - camel_mime_parser_unstep(mp); - } - } else { - gtk_object_unref((GtkObject *)mp); - /* end of file - no content? */ - return 0; - } - } - - while (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) { - CamelMessageInfo *info; - - info = camel_folder_summary_add_from_parser((CamelFolderSummary *)mbs, mp); - if (info == NULL) { - ok = -1; - break; - } - - g_assert(camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM_END); - } - - gtk_object_unref((GtkObject *)mp); - - return ok; -} - -int -camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset) -{ - int ret; - - mbs->index_force = FALSE; - ret = summary_rebuild(mbs, offset); - -#if 0 -#warning "Saving full summary and index after every summarisation is slow ..." - if (ret != -1) { - if (camel_folder_summary_save((CamelFolderSummary *)mbs) == -1) - g_warning("Could not save summary: %s", strerror(errno)); - printf("summary saved\n"); - if (mbs->index) - ibex_save(mbs->index); - printf("ibex saved\n"); - } -#endif - return ret; -} - -int -camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex) -{ - CamelFolderSummary *s = (CamelFolderSummary *)mbs; - struct stat st; - int ret = 0; - off_t minstart; - - mbs->index_force = forceindex; - - /* is the summary out of date? */ - if (stat(mbs->folder_path, &st) == -1) { - camel_folder_summary_clear(s); - printf("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno)); - return -1; - } - - if (forceindex || camel_folder_summary_load(s) == -1) { - camel_folder_summary_clear(s); - ret = summary_rebuild(mbs, 0); - } else { - minstart = st.st_size; -#if 0 - /* find out the first unindexed message ... */ - /* TODO: For this to work, it has to check that the message is - indexable, and contains content ... maybe it cannot be done - properly? */ - for (i=0;i<camel_folder_summary_count(s);i++) { - CamelMessageInfo *mi = camel_folder_summary_index(s, i); - if (!ibex_contains_name(mbs->index, mi->uid)) { - minstart = ((CamelMboxMessageInfo *)mi)->frompos; - printf("Found unindexed message: %s\n", mi->uid); - break; - } - } -#endif - /* is the summary uptodate? */ - if (st.st_size == mbs->folder_size && st.st_mtime == s->time) { - printf("Summary time and date match mbox\n"); - if (minstart < st.st_size) { - /* FIXME: Only clear the messages and reindex from this point forward */ - camel_folder_summary_clear(s); - ret = summary_rebuild(mbs, 0); - } - } else { - if (mbs->folder_size < st.st_size) { - printf("Index is for a smaller mbox\n"); - if (minstart < mbs->folder_size) { - /* FIXME: only make it rebuild as necessary */ - camel_folder_summary_clear(s); - ret = summary_rebuild(mbs, 0); - } else { - ret = summary_rebuild(mbs, mbs->folder_size); - } - } else { - printf("index is for a bigger mbox\n"); - camel_folder_summary_clear(s); - ret = summary_rebuild(mbs, 0); - } - } - } - - if (ret != -1) { - mbs->folder_size = st.st_size; - s->time = st.st_mtime; - printf("saving summary\n"); - if (camel_folder_summary_save(s) == -1) - g_warning("Could not save summary: %s", strerror(errno)); - printf("summary saved\n"); - if (mbs->index) - ibex_save(mbs->index); - printf("ibex saved\n"); - } - - return ret; -} - -static int -header_write(int fd, struct _header_raw *header, char *xevline) -{ - struct iovec iv[4]; - int outlen = 0, len; - - iv[1].iov_base = ":"; - iv[1].iov_len = 1; - iv[3].iov_base = "\n"; - iv[3].iov_len = 1; - - while (header) { - if (strcasecmp(header->name, "X-Evolution")) { - iv[0].iov_base = header->name; - iv[0].iov_len = strlen(header->name); - iv[2].iov_base = header->value; - iv[2].iov_len = strlen(header->value); - - do { - len = writev(fd, iv, 4); - } while (len == -1 && errno == EINTR); - - if (len == -1) - return -1; - outlen += len; - } - header = header->next; - } - - iv[0].iov_base = "X-Evolution: "; - iv[0].iov_len = strlen(iv[0].iov_base); - iv[1].iov_base = xevline; - iv[1].iov_len = strlen(xevline); - iv[2].iov_base = "\n\n"; - iv[2].iov_len = 2; - - do { - len = writev(fd, iv, 3); - } while (len == -1 && errno == EINTR); - - if (len == -1) - return -1; - - outlen += 1; - - d(printf("Wrote %d bytes of headers\n", outlen)); - - return outlen; -} - -static int -copy_block(int fromfd, int tofd, off_t start, size_t bytes) -{ - char buffer[4096]; - int written = 0; - - d(printf("writing %d bytes ... ", bytes)); - - if (lseek(fromfd, start, SEEK_SET) != start) - return -1; - - while (bytes>0) { - int toread, towrite; - - toread = bytes; - if (bytes>4096) - toread = 4096; - else - toread = bytes; - do { - towrite = read(fromfd, buffer, toread); - } while (towrite == -1 && errno == EINTR); - - if (towrite == -1) - return -1; - - /* check for 'end of file' */ - if (towrite == 0) { - d(printf("end of file?\n")); - break; - } - - do { - toread = write(tofd, buffer, towrite); - } while (toread == -1 && errno == EINTR); - - if (toread == -1) - return -1; - - written += toread; - bytes -= toread; - } - - d(printf("written %d bytes\n", written)); - - return written; -} - -int -camel_mbox_summary_expunge(CamelMboxSummary *mbs) -{ - CamelMimeParser *mp=NULL; - int i, count; - CamelMboxMessageInfo *info; - CamelFolderSummary *s = (CamelFolderSummary *)mbs; - - int fd=-1, fdout=-1; - off_t offset = 0; - char *tmpname=0; - char *buffer, *xevnew = NULL; - const char *xev; - int len; - guint32 uid, flags; - int quick = TRUE, work = FALSE; - - /* make sure we're in sync */ - count = camel_folder_summary_count(s); - if (count>0) { - CamelMessageInfo *mi = camel_folder_summary_index(s, count-1); - camel_mbox_summary_update(mbs, mi->content->endpos); - } else { - camel_mbox_summary_update(mbs, 0); - } - - /* check if we have any work to do */ - d(printf("Performing expunge, %d messages in inbox\n", count)); - for (i=0;quick && i<count;i++) { - info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); - if (info->info.flags & (CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_FOLDER_NOXEV)) - quick = FALSE; - else - work |= (info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0; - } - - d(printf("Options: %s %s\n", quick?"quick":"", work?"Work":"")); - - if (quick && !work) - return 0; - - fd = open(mbs->folder_path, O_RDWR); - if (fd == -1) - return -1; - - mp = camel_mime_parser_new(); - camel_mime_parser_scan_from(mp, TRUE); - camel_mime_parser_init_with_fd(mp, fd); - - if (!quick) { - tmpname = alloca(strlen(mbs->folder_path)+5); - sprintf(tmpname, "%s.tmp", mbs->folder_path); - d(printf("Writing tmp file to %s\n", tmpname)); - retry_out: - fdout = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, 0600); - if (fdout == -1) { - if (errno == EEXIST) - if (unlink(tmpname) != -1) - goto retry_out; - tmpname = 0; - goto error; - } - } - - for (i=0;i<count;i++) { - off_t frompos, bodypos; - off_t xevoffset; - - info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i); - - g_assert(info); - - d(printf("Looking at message %s\n", info->info.uid)); - - if (info->info.flags & CAMEL_MESSAGE_DELETED) { - d(printf("Deleting %s\n", info->info.uid)); - - g_assert(!quick); - offset -= (info->info.content->endpos - info->frompos); - if (mbs->index) - ibex_unindex(mbs->index, info->info.uid); - camel_folder_summary_remove(s, (CamelMessageInfo *)info); - count--; - i--; - info = NULL; - } else if (info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_FLAGGED)) { - int xevok = FALSE; - - d(printf("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags)); - - /* find the next message, header parts */ - camel_mime_parser_seek(mp, info->frompos, SEEK_SET); - if (camel_mime_parser_step(mp, &buffer, &len) != HSCAN_FROM) - goto error; - - if (camel_mime_parser_tell_start_from(mp) != info->frompos) { - g_error("Summary/mbox mismatch, aborting expunge"); - goto error; - } - - if (camel_mime_parser_step(mp, &buffer, &len) == HSCAN_FROM_END) - goto error; - - xev = camel_mime_parser_header(mp, "X-Evolution", (int *)&xevoffset); - if (xev && header_evolution_decode(xev, &uid, &flags) != -1) { - char name[64]; - - sprintf(name, "%u", uid); - if (strcmp(name, info->info.uid)) { - d(printf("Summary mismatch, aborting leaving mailbox intact\n")); - goto error; - } - xevok = TRUE; - } - xevnew = header_evolution_encode(strtoul(info->info.uid, NULL, 10), info->info.flags); - if (quick) { - if (!xevok) { - g_error("The summary told me I had an X-Evolution header, but i dont!"); - goto error; - } - buffer = g_strdup_printf("X-Evolution: %s", xevnew); - do { - len = write(fd, buffer, strlen(buffer)); - } while (len == -1 && errno == EINTR); - g_free(buffer); - if (len == -1) { - goto error; - } - } else { - frompos = lseek(fdout, 0, SEEK_CUR); - write(fdout, "From -\n", strlen("From -\n")); - if (header_write(fdout, camel_mime_parser_headers_raw(mp), xevnew) == -1) { - d(printf("Error writing to tmp mailbox\n")); - goto error; - } - bodypos = lseek(fdout, 0, SEEK_CUR); - d(printf("pos = %d, endpos = %d, bodypos = %d\n", - info->info.content->pos, - info->info.content->endpos, - info->info.content->bodypos)); - if (copy_block(fd, fdout, info->info.content->bodypos, info->info.content->endpos - info->info.content->bodypos) == -1) { - g_warning("Cannot copy data to output fd"); - goto error; - } - info->frompos = frompos; - offset = bodypos - info->info.content->bodypos; - } - g_free(xevnew); xevnew = NULL; - camel_mime_parser_drop_step(mp); - camel_mime_parser_drop_step(mp); - } else { - d(printf("Nothing to do for this message\n")); - } - if (!quick && info!=NULL && offset!=0) { - camel_folder_summary_offset_content(info->info.content, offset); - d(printf("pos = %d, endpos = %d, bodypos = %d\n", - info->info.content->pos, - info->info.content->endpos, - info->info.content->bodypos)); - } - } - - d(printf("Closing folders\n")); - - if (close(fd) == -1) { - g_warning("Cannot close source folder: %s", strerror(errno)); - goto error; - } - - if (!quick) { - struct stat st; - - if (close(fdout) == -1) { - g_warning("Cannot close tmp folder: %s", strerror(errno)); - goto error; - } - - if (rename(tmpname, mbs->folder_path) == -1) { - g_warning("Cannot rename folder: %s", strerror(errno)); - goto error; - } - tmpname = 0; - - if (stat(mbs->folder_path, &st) == -1) - goto error; - - s->flags |= CAMEL_SUMMARY_DIRTY; - s->time = st.st_mtime; - mbs->folder_size = st.st_size; - camel_folder_summary_save(s); - if (mbs->index) - ibex_save(mbs->index); - } - - gtk_object_unref((GtkObject *)mp); - - return 0; -error: - d(printf("Error occured: %s\n", strerror(errno))); - count = errno; - - close(fd); - close(fdout); - - g_free(xevnew); - - if (tmpname) - unlink(tmpname); - if (mp) - gtk_object_unref((GtkObject *)mp); - - errno = count; - return -1; -} diff --git a/camel/providers/mbox/camel-mbox-summary.h b/camel/providers/mbox/camel-mbox-summary.h deleted file mode 100644 index 6d98fd051d..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 General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef _CAMEL_MBOX_SUMMARY_H -#define _CAMEL_MBOX_SUMMARY_H - -#include <gtk/gtk.h> -#include <camel/camel-folder-summary.h> -#include <libibex/ibex.h> - -#define CAMEL_MBOX_SUMMARY(obj) GTK_CHECK_CAST (obj, camel_mbox_summary_get_type (), CamelMboxSummary) -#define CAMEL_MBOX_SUMMARY_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_mbox_summary_get_type (), CamelMboxSummaryClass) -#define IS_CAMEL_MBOX_SUMMARY(obj) GTK_CHECK_TYPE (obj, camel_mbox_summary_get_type ()) - -typedef struct _CamelMboxSummary CamelMboxSummary; -typedef struct _CamelMboxSummaryClass CamelMboxSummaryClass; - -/* extra summary flags */ -enum { - CAMEL_MESSAGE_FOLDER_NOXEV = 1<<16, -/* CAMEL_MESSAGE_FOLDER_FLAGGED = 1<<17,*/ -}; - -typedef struct _CamelMboxMessageContentInfo { - CamelMessageContentInfo info; -} CamelMboxMessageContentInfo; - -typedef struct _CamelMboxMessageInfo { - CamelMessageInfo info; - - off_t frompos; -} CamelMboxMessageInfo; - -struct _CamelMboxSummary { - CamelFolderSummary parent; - - struct _CamelMboxSummaryPrivate *priv; - - char *folder_path; /* name of matching folder */ - size_t folder_size; /* size of the mbox file, last sync */ - - ibex *index; - int index_force; /* do we force index during creation? */ -}; - -struct _CamelMboxSummaryClass { - CamelFolderSummaryClass parent_class; -}; - -guint camel_mbox_summary_get_type (void); -CamelMboxSummary *camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index); - -/* load/check the summary */ -int camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex); -/* incremental update */ -int camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset); -/* perform a folder expunge */ -int camel_mbox_summary_expunge(CamelMboxSummary *mbs); - -#endif /* ! _CAMEL_MBOX_SUMMARY_H */ diff --git a/camel/providers/mbox/libcamelmbox.urls b/camel/providers/mbox/libcamelmbox.urls deleted file mode 100644 index e021190356..0000000000 --- a/camel/providers/mbox/libcamelmbox.urls +++ /dev/null @@ -1 +0,0 @@ -mbox diff --git a/camel/providers/nntp/.cvsignore b/camel/providers/nntp/.cvsignore deleted file mode 100644 index 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 200011c4dc..0000000000 --- a/camel/providers/nntp/Makefile.am +++ /dev/null @@ -1,33 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelnntpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelnntp.la -provider_DATA = libcamelnntp.urls - -INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -I$(srcdir)/../mbox \ - -DG_LOG_DOMAIN=\"camel-nntp-provider\" - -libcamelnntp_la_SOURCES = \ - camel-nntp-folder.c \ - camel-nntp-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 = libcamelnntp.urls diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c deleted file mode 100644 index 6fee4d2aac..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_flush (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 449de945e6..0000000000 --- a/camel/providers/nntp/camel-nntp-provider.c +++ /dev/null @@ -1,71 +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" -#include "camel-session.h" - -static CamelProvider news_provider = { - "news", - "USENET news", - - "This is a read-only provider for USENET newsgroups.", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 } -}; - -static CamelProvider nntp_provider = { - "nntp", - "USENET news via NNTP", - - "This is a provider for reading from and posting to" - "USENET newsgroups.", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - news_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_nntp_store_get_type(); - nntp_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_nntp_store_get_type(); -#ifdef NOTYET - nntp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_nntp_transport_get_type(); -#endif - - camel_session_register_provider (session", &news_provider); - camel_session_register_provider (session", &nntp_provider); -} - - - diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c deleted file mode 100644 index 639e8fa9e0..0000000000 --- a/camel/providers/nntp/camel-nntp-store.c +++ /dev/null @@ -1,473 +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; - - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - store->ostream = NULL; - store->istream = NULL; - return TRUE; -} - -/** - * camel_nntp_command: Send a command to a NNTP server. - * @store: the NNTP store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected NNTP store specified by @store. It then - * reads the server's response and parses out the status code. If - * the caller passed a non-NULL pointer for @ret, camel_nntp_command - * will set it to point to an buffer containing the rest of the - * response from the NNTP server. (If @ret was passed but there was - * no extended response, @ret will be set to NULL.) The caller must - * free this buffer when it is done with it. - * - * Return value: one of CAMEL_NNTP_OK (command executed successfully), - * CAMEL_NNTP_ERR (command encounted an error), or CAMEL_NNTP_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ -int -camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...) -{ - char *cmdbuf, *respbuf; - va_list ap; - int status; - int resp_code; - CamelException *ex; - - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - ex = camel_exception_new(); - - /* make sure we're connected */ - if (store->ostream == NULL) - nntp_connect (CAMEL_SERVICE (store), ex); - - if (camel_exception_get_id (ex)) { - camel_exception_free (ex); - return CAMEL_NNTP_FAIL; - } - - /* Send the command */ - camel_stream_write (store->ostream, cmdbuf, strlen (cmdbuf)); - g_free (cmdbuf); - camel_stream_write (store->ostream, "\r\n", 2); - - /* Read the response */ - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream)); - resp_code = atoi (respbuf); - - if (resp_code < 400) - status = CAMEL_NNTP_OK; - else if (resp_code < 500) - status = CAMEL_NNTP_ERR; - else - status = CAMEL_NNTP_FAIL; - - if (ret) { - *ret = strchr (respbuf, ' '); - if (*ret) - *ret = g_strdup (*ret + 1); - } - g_free (respbuf); - - return status; -} - -/** - * camel_nntp_command_get_additional_data: get "additional data" from - * a NNTP command. - * @store: the NNTP store - * - * This command gets the additional data returned by "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 b89ae120da..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 (!g_strcasecmp(header->name, "From")) - info.headers.sender = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "To")) - info.headers.to = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "Subject")) - info.headers.subject = g_strdup(header->value); - else if (!g_strcasecmp(header->name, "Message-ID")) - info.headers.uid = g_strdup(header->value); - else if (!g_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/nntp/libcamelnntp.urls b/camel/providers/nntp/libcamelnntp.urls deleted file mode 100644 index dee2e70f14..0000000000 --- a/camel/providers/nntp/libcamelnntp.urls +++ /dev/null @@ -1,2 +0,0 @@ -news -nntp diff --git a/camel/providers/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 f30d73e736..0000000000 --- a/camel/providers/pop3/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelpop3includedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelpop3.la -provider_DATA = libcamelpop3.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) \ - -I$(top_srcdir)/camel \ - $(KRB4_CFLAGS) \ - -DG_LOG_DOMAIN=\"camel-pop3-provider\" - -libcamelpop3_la_SOURCES = \ - camel-pop3-folder.c \ - camel-pop3-provider.c \ - camel-pop3-store.c - -libcamelpop3include_HEADERS = \ - camel-pop3-folder.h \ - camel-pop3-store.h - - -libcamelpop3_la_LDFLAGS = $(KRB4_LDFLAGS) -version-info 0:0:0 -rpath $(libdir) - -EXTRA_DIST = libcamelpop3.urls diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c deleted file mode 100644 index 838f247ac6..0000000000 --- a/camel/providers/pop3/camel-pop3-folder.c +++ /dev/null @@ -1,257 +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), ex); - if (!body) { - CamelService *service = CAMEL_SERVICE (folder->parent_store); - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not retrieve message from POP " - "server %s: %s", service->url->host, - camel_exception_get_description (ex)); - return NULL; - } - - msgstream = camel_stream_mem_new_with_buffer (body, strlen (body)); - msg = camel_mime_message_new (); - camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), - msgstream); - gtk_object_unref (GTK_OBJECT (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 dc6e2b9442..0000000000 --- a/camel/providers/pop3/camel-pop3-provider.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-pop3-provider.c: pop3 provider registration code */ - -/* - * Authors : - * Dan Winship <danw@helixcode.com> - * - * Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "config.h" -#include "camel-pop3-store.h" -#include "camel-provider.h" -#include "camel-session.h" - -static CamelProvider pop3_provider = { - "pop", - "POP", - - "For connecting to POP servers. The POP protocol can also be used " - "to retrieve mail from certain web mail providers and proprietary " - "email systems.", - - CAMEL_PROVIDER_IS_REMOTE, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - pop3_provider.object_types[CAMEL_PROVIDER_STORE] = - camel_pop3_store_get_type(); - - camel_session_register_provider (session, &pop3_provider); -} diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c deleted file mode 100644 index ddddf9f59f..0000000000 --- a/camel/providers/pop3/camel-pop3-store.c +++ /dev/null @@ -1,614 +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 - -#ifdef HAVE_KRB4 -/* Specified nowhere */ -#define KPOP_PORT 1109 - -#include <krb.h> -#endif - -static CamelServiceClass *service_class = NULL; - -static void finalize (GtkObject *object); - -static gboolean pop3_connect (CamelService *service, CamelException *ex); -static gboolean pop3_disconnect (CamelService *service, CamelException *ex); -static GList *query_auth_types (CamelService *service, CamelException *ex); -static void free_auth_types (CamelService *service, GList *authtypes); - -static 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", - - "This option will connect to the POP server using the APOP " - "protocol if possible, or a plaintext password if not.", - - "", - TRUE -}; - -#ifdef HAVE_KRB4 -static CamelServiceAuthType kpop_authtype = { - "Kerberos 4 (KPOP)", - - "This will connect to the POP server and use Kerberos 4 " - "to authenticate to it.", - - "+KPOP", - FALSE -}; -#endif - -static gboolean -try_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - int fd; - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - sin.sin_family = h->h_addrtype; - if (service->url->port) - sin.sin_port = htons (service->url->port); - else - sin.sin_port = htons (POP3_PORT); - memcpy (&sin.sin_addr, h->h_addr, sizeof (sin.sin_addr)); - - fd = socket (h->h_addrtype, SOCK_STREAM, 0); - if (fd == -1 || - connect (fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { - if (fd > -1) - close (fd); - return FALSE; - } - - close (fd); - return TRUE; -} - -static GList * -query_auth_types (CamelService *service, CamelException *ex) -{ - GList *ret = NULL; - gboolean passwd = TRUE; -#ifdef HAVE_KRB4 - gboolean kpop = TRUE; - int saved_port; -#endif - - if (service->url) { - passwd = try_connect (service, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return NULL; -#ifdef HAVE_KRB4 - saved_port = service->url->port; - service->url->port = KPOP_PORT; - kpop = try_connect (service, ex); - service->url->port = saved_port; - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return NULL; -#endif - } - - if (passwd) - ret = g_list_append (ret, &password_authtype); -#ifdef HAVE_KRB4 - if (kpop) - ret = g_list_append (ret, &kpop_authtype); -#endif - - if (!ret) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not connect to POP server on " - "%s.", service->url->host); - } - - return ret; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -/** - * 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, *msg; - CamelPop3Store *store = CAMEL_POP3_STORE (service); -#ifdef HAVE_KRB4 - gboolean kpop = (service->url->authmech && - !strcmp (service->url->authmech, "+KPOP")); -#endif - - h = camel_service_gethost (service, ex); - if (!h) - return FALSE; - - if (!service->url->authmech && !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; - if (service->url->port) - sin.sin_port = service->url->port; -#ifdef HAVE_KRB4 - else if (kpop) - sin.sin_port = KPOP_PORT; -#endif - else - sin.sin_port = POP3_PORT; - sin.sin_port = htons (sin.sin_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; - } - -#ifdef HAVE_KRB4 - if (kpop) { - KTEXT_ST ticket_st; - MSG_DAT msg_data; - CREDENTIALS cred; - Key_schedule schedule; - char *hostname; - - /* Need to copy hostname, because krb_realmofhost will - * call gethostbyname as well, and gethostbyname uses - * static storage. - */ - hostname = g_strdup (h->h_name); - status = krb_sendauth (0, fd, &ticket_st, "pop", hostname, - krb_realmofhost (hostname), 0, - &msg_data, &cred, schedule, - NULL, NULL, "KPOPV0.1"); - g_free (hostname); - if (status != KSUCCESS) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not authenticate to KPOP " - "server: %s", - krb_err_txt[status]); - close (fd); - return FALSE; - } - - if (!service->url->passwd) - service->url->passwd = g_strdup (service->url->user); - } -#endif /* HAVE_KRB4 */ - - store->ostream = camel_stream_fs_new_with_fd (fd); - store->istream = camel_stream_buffer_new (store->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting, note APOP timestamp, if any. */ - buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex); - if (!buf) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Could not read greeting from POP " - "server: %s", - camel_exception_get_description (ex)); - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - return FALSE; - } - 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. */ - 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, &msg, "APOP %s %s", - service->url->user, md5asc); - } else { - 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); - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (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); - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (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; - - gtk_object_unref (GTK_OBJECT (store->ostream)); - gtk_object_unref (GTK_OBJECT (store->istream)); - 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 (!g_strcasecmp (folder_name, "inbox")) - return g_strdup ("inbox"); - else { - camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, - "No such folder `%s'.", folder_name); - return NULL; - } -} - -static char * -get_root_folder_name (CamelStore *store, CamelException *ex) -{ - return g_strdup ("inbox"); -} - - -/** - * camel_pop3_command: Send a command to a POP3 server. - * @store: the POP3 store - * @ret: a pointer to return the full server response in - * @fmt: a printf-style format string, followed by arguments - * - * This command sends the command specified by @fmt and the following - * arguments to the connected POP3 store specified by @store. It then - * reads the server's response and parses out the status code. If - * the caller passed a non-NULL pointer for @ret, camel_pop3_command - * will set it to point to an buffer containing the rest of the - * response from the POP3 server. (If @ret was passed but there was - * no extended response, @ret will be set to NULL.) The caller must - * free this buffer when it is done with it. - * - * Return value: one of CAMEL_POP3_OK (command executed successfully), - * CAMEL_POP3_ERR (command encounted an error), or CAMEL_POP3_FAIL - * (a protocol-level error occurred, and Camel is uncertain of the - * result of the command.) - **/ -int -camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...) -{ - char *cmdbuf, *respbuf; - va_list ap; - int status; - CamelException *ex = camel_exception_new (); - - va_start (ap, fmt); - cmdbuf = g_strdup_vprintf (fmt, ap); - va_end (ap); - - /* Send the command */ - camel_stream_printf (store->ostream, ex, "%s\r\n", cmdbuf); - g_free (cmdbuf); - if (camel_exception_is_set (ex)) { - if (*ret) - *ret = g_strdup (camel_exception_get_description (ex)); - camel_exception_free (ex); - return CAMEL_POP3_FAIL; - } - - /* Read the response */ - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex); - if (camel_exception_is_set (ex)) { - if (*ret) - *ret = g_strdup (camel_exception_get_description (ex)); - camel_exception_free (ex); - return CAMEL_POP3_FAIL; - } - if (!strncmp (respbuf, "+OK", 3)) - status = CAMEL_POP3_OK; - else if (!strncmp (respbuf, "-ERR", 4)) - status = CAMEL_POP3_ERR; - else - status = CAMEL_POP3_FAIL; - - if (ret) { - if (status != CAMEL_POP3_FAIL) { - *ret = strchr (respbuf, ' '); - if (*ret) - *ret = g_strdup (*ret + 1); - } else - *ret = NULL; - } - g_free (respbuf); - - return status; -} - -/** - * camel_pop3_command_get_additional_data: get "additional data" from - * a POP3 command. - * @store: the POP3 store - * - * This command gets the additional data returned by "multi-line" POP - * commands, such as LIST, RETR, TOP, and UIDL. This command _must_ - * be called after a successful (CAMEL_POP3_OK) call to - * camel_pop3_command for a command that has a multi-line response. - * The returned data is un-byte-stuffed, and has lines termined by - * newlines rather than CR/LF pairs. - * - * Return value: the data, which the caller must free. - **/ -char * -camel_pop3_command_get_additional_data (CamelPop3Store *store, - CamelException *ex) -{ - CamelStreamBuffer *stream = CAMEL_STREAM_BUFFER (store->istream); - GPtrArray *data; - char *buf; - int i, status = CAMEL_POP3_OK; - - data = g_ptr_array_new (); - while (1) { - buf = camel_stream_buffer_read_line (stream, ex); - 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 e68f0fd142..0000000000 --- a/camel/providers/pop3/camel-pop3-store.h +++ /dev/null @@ -1,81 +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, - CamelException *ex); - -/* Standard Gtk function */ -GtkType camel_pop3_store_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CAMEL_POP3_STORE_H */ - - diff --git a/camel/providers/pop3/libcamelpop3.urls b/camel/providers/pop3/libcamelpop3.urls deleted file mode 100644 index 7fffa4d861..0000000000 --- a/camel/providers/pop3/libcamelpop3.urls +++ /dev/null @@ -1 +0,0 @@ -pop diff --git a/camel/providers/sendmail/.cvsignore b/camel/providers/sendmail/.cvsignore deleted file mode 100644 index cacc3c5d5f..0000000000 --- a/camel/providers/sendmail/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -Makefile -Makefile.in -.deps -.libs -*.lo -*.la -*.o diff --git a/camel/providers/sendmail/Makefile.am b/camel/providers/sendmail/Makefile.am deleted file mode 100644 index 511c860315..0000000000 --- a/camel/providers/sendmail/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsendmailincludedir = $(includedir)/camel - - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsendmail.la -provider_DATA = libcamelsendmail.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-sendmail-provider\" - -libcamelsendmail_la_SOURCES = \ - camel-sendmail-provider.c \ - camel-sendmail-transport.c - -libcamelsendmailinclude_HEADERS = \ - camel-sendmail-transport.h - -libcamelsendmail_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - -EXTRA_DIST = libcamelsendmail.urls diff --git a/camel/providers/sendmail/camel-sendmail-provider.c b/camel/providers/sendmail/camel-sendmail-provider.c deleted file mode 100644 index 16ebce8b12..0000000000 --- a/camel/providers/sendmail/camel-sendmail-provider.c +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-sendmail-provider.c: sendmail provider registration code */ - -/* - * Authors : - * Dan Winship <danw@helixcode.com> - * - * Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "config.h" -#include "camel-provider.h" -#include "camel-sendmail-transport.h" -#include "camel-session.h" - -static CamelProvider sendmail_provider = { - "sendmail", - "Sendmail", - - "For delivering mail by passing it to the \"sendmail\" program " - "on the local system.", - - 0, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - sendmail_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_sendmail_transport_get_type(); - - camel_session_register_provider (session, &sendmail_provider); -} - - - diff --git a/camel/providers/sendmail/camel-sendmail-transport.c b/camel/providers/sendmail/camel-sendmail-transport.c deleted file mode 100644 index a5eeff1a25..0000000000 --- a/camel/providers/sendmail/camel-sendmail-transport.c +++ /dev/null @@ -1,211 +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, ex); - gtk_object_unref (GTK_OBJECT (out)); - if (camel_exception_is_set (ex)) { - camel_exception_setv (ex, camel_exception_get_id (ex), - "Could not send message: %s", - camel_exception_get_description (ex)); - return FALSE; - } - - /* 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/sendmail/libcamelsendmail.urls b/camel/providers/sendmail/libcamelsendmail.urls deleted file mode 100644 index ccad52828e..0000000000 --- a/camel/providers/sendmail/libcamelsendmail.urls +++ /dev/null @@ -1 +0,0 @@ -sendmail diff --git a/camel/providers/smtp/.cvsignore b/camel/providers/smtp/.cvsignore deleted file mode 100644 index 09980ae6ba..0000000000 --- a/camel/providers/smtp/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la diff --git a/camel/providers/smtp/Makefile.am b/camel/providers/smtp/Makefile.am deleted file mode 100644 index b14375bfc0..0000000000 --- a/camel/providers/smtp/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = - -libcamelsmtpincludedir = $(includedir)/camel - -providerdir = $(pkglibdir)/camel-providers/$(VERSION) - -provider_LTLIBRARIES = libcamelsmtp.la -provider_DATA = libcamelsmtp.urls - -INCLUDES = \ - -I.. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../../.. \ - -I$(includedir) \ - -I$(top_srcdir)/intl \ - $(GTK_INCLUDEDIR) \ - -I$(top_srcdir)/camel \ - -DG_LOG_DOMAIN=\"camel-smtp-provider\" - -libcamelsmtp_la_SOURCES = \ - camel-smtp-provider.c \ - camel-smtp-transport.c - -libcamelsmtpinclude_HEADERS = \ - camel-smtp-transport.h - - -libcamelsmtp_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir) - -EXTRA_DIST = libcamelsmtp.urls diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c deleted file mode 100644 index c82755d481..0000000000 --- a/camel/providers/smtp/camel-smtp-provider.c +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* camel-smtp-provider.c: smtp provider registration code */ - -/* - * Authors : - * Jeffrey Stedfast <fejj@stampede.org> - * - * Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include "config.h" -#include "camel-smtp-transport.h" -#include "camel-provider.h" -#include "camel-session.h" - -static CamelProvider smtp_provider = { - "smtp", - "SMTP", - - "For delivering mail by connecting to a remote mailhub using SMTP." - "(NOT YET TESTED!)", - - 0, - - { 0, 0 } -}; - -void -camel_provider_module_init (CamelSession *session) -{ - smtp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = - camel_smtp_transport_get_type(); - - camel_session_register_provider (session, &smtp_provider); -} - - - diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c deleted file mode 100644 index 5915045bc7..0000000000 --- a/camel/providers/smtp/camel-smtp-transport.c +++ /dev/null @@ -1,703 +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> -#undef MIN -#undef MAX -#include "camel-smtp-transport.h" -#include "camel-mime-message.h" -#include "camel-stream-buffer.h" -#include "camel-stream-fs.h" -#include "camel-session.h" -#include "camel-exception.h" -#include "md5-utils.h" - -/* Specified in RFC 821 */ -#define SMTP_PORT 25 - -/* camel smtp transport class prototypes */ -static gboolean _can_send (CamelTransport *transport, CamelMedium *message); -static gboolean _send (CamelTransport *transport, CamelMedium *message, CamelException *ex); -static gboolean _send_to (CamelTransport *transport, CamelMedium *message, GList *recipients, CamelException *ex); - -/* support prototypes */ -static gboolean smtp_connect (CamelService *service, CamelException *ex); -static gboolean smtp_disconnect (CamelService *service, CamelException *ex); -static GList *esmtp_get_authtypes(gchar *buffer); -static GList *query_auth_types (CamelService *service, CamelException *ex); -static void free_auth_types (CamelService *service, GList *authtypes); -static gchar *smtp_get_email_addr_from_text (gchar *text); -static gboolean smtp_helo (CamelSmtpTransport *transport, CamelException *ex); -static gboolean smtp_mail (CamelSmtpTransport *transport, gchar *sender, CamelException *ex); -static gboolean smtp_rcpt (CamelSmtpTransport *transport, gchar *recipient, CamelException *ex); -static gboolean smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException *ex); -static gboolean smtp_rset (CamelSmtpTransport *transport, CamelException *ex); -static gboolean smtp_quit (CamelSmtpTransport *transport, CamelException *ex); - -/* private data members */ -static CamelServiceClass *service_class = NULL; -static gboolean smtp_is_esmtp = FALSE; -static struct sockaddr_in localaddr; - -static void -camel_smtp_transport_class_init (CamelSmtpTransportClass *camel_smtp_transport_class) -{ - CamelTransportClass *camel_transport_class = - CAMEL_TRANSPORT_CLASS (camel_smtp_transport_class); - CamelServiceClass *camel_service_class = - CAMEL_SERVICE_CLASS (camel_smtp_transport_class); - - service_class = gtk_type_class (camel_service_get_type ()); - - /* virtual method overload */ - camel_service_class->connect = smtp_connect; - camel_service_class->disconnect = smtp_disconnect; - camel_service_class->query_auth_types = query_auth_types; - camel_service_class->free_auth_types = free_auth_types; - - camel_transport_class->can_send = _can_send; - camel_transport_class->send = _send; - camel_transport_class->send_to = _send_to; -} - -static void -camel_smtp_transport_init (gpointer object, gpointer klass) -{ - CamelService *service = CAMEL_SERVICE (object); - - service->url_flags = CAMEL_SERVICE_URL_NEED_HOST; -} - -GtkType -camel_smtp_transport_get_type (void) -{ - static GtkType camel_smtp_transport_type = 0; - - if (!camel_smtp_transport_type) { - GtkTypeInfo camel_smtp_transport_info = - { - "CamelSmtpTransport", - sizeof (CamelSmtpTransport), - sizeof (CamelSmtpTransportClass), - (GtkClassInitFunc) camel_smtp_transport_class_init, - (GtkObjectInitFunc) camel_smtp_transport_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - camel_smtp_transport_type = gtk_type_unique (CAMEL_TRANSPORT_TYPE, &camel_smtp_transport_info); - } - - return camel_smtp_transport_type; -} - -static gboolean -smtp_connect (CamelService *service, CamelException *ex) -{ - struct hostent *h; - struct sockaddr_in sin; - gint fd; - guint32 addrlen; - 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; - } - - /* get the localaddr - needed later by smtp_helo */ - addrlen = sizeof(localaddr); - getsockname(fd, (struct sockaddr*)&localaddr, &addrlen); - - transport->ostream = camel_stream_fs_new_with_fd (fd); - transport->istream = camel_stream_buffer_new (transport->ostream, - CAMEL_STREAM_BUFFER_READ); - - /* Read the greeting, note whether the server is ESMTP and if it requests AUTH. */ - do { - /* Check for "220" */ - g_free(respbuf); - respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream), ex); - 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; - - gtk_object_unref (GTK_OBJECT (transport->ostream)); - gtk_object_unref (GTK_OBJECT (transport->istream)); - transport->ostream = NULL; - transport->istream = NULL; - - return TRUE; -} - -static GList -*esmtp_get_authtypes(gchar *buffer) -{ - GList *ret = NULL; - - return ret; -} - -static CamelServiceAuthType no_authtype = { - "No authentication required", - - "This option will connect to the SMTP server without using any " - "kind of authentication. This should be fine for connecting to " - "most SMTP servers." - - "", - FALSE -}; - -static CamelServiceAuthType cram_md5_authtype = { - "CRAM-MD5", - - "This option will connect to the SMTP server using CRAM-MD5 " - "authentication.", - - "CRAM-MD5", - TRUE -}; - -static GList -*query_auth_types (CamelService *service, CamelException *ex) -{ - /* FIXME: Re-enable this when auth types are actually - * implemented. - */ - - return NULL; -} - -static void -free_auth_types (CamelService *service, GList *authtypes) -{ - g_list_free (authtypes); -} - -static 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 = g_strdup(camel_mime_message_get_from (CAMEL_MIME_MESSAGE(message))); - if (!s) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot send message: " - "sender address not defined."); - return FALSE; - } - - sender = smtp_get_email_addr_from_text(s); - smtp_mail(smtp_transport, sender, ex); - g_free(sender); - g_free(s); - - if (!(len = g_list_length(recipients))) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "Cannot send message: " - "no recipients defined."); - return FALSE; - } - for (i = 0, r = recipients; i < len; i++, r = r->next) { - recipient = smtp_get_email_addr_from_text(r->data); - if (!smtp_rcpt(smtp_transport, recipient, ex)) { - g_free(recipient); - return FALSE; - } - g_free(recipient); - } - - if (!smtp_data(smtp_transport, message, ex)) - return FALSE; - - /* reset the service for our next transfer session */ - smtp_rset(smtp_transport, ex); - - return TRUE; -} - -static gboolean -_send (CamelTransport *transport, CamelMedium *message, - CamelException *ex) -{ - const CamelInternetAddress *to, *cc, *bcc; - GList *recipients = NULL; - guint index, len; - - to = camel_mime_message_get_recipients ((CamelMimeMessage *) message, CAMEL_RECIPIENT_TYPE_TO); - cc = camel_mime_message_get_recipients ((CamelMimeMessage *) message, CAMEL_RECIPIENT_TYPE_CC); - bcc = camel_mime_message_get_recipients ((CamelMimeMessage *) message, CAMEL_RECIPIENT_TYPE_BCC); - - /* get all of the To addresses into our recipient list */ - len = ((CamelAddress *)to)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get(to, index, NULL, &addr)) - recipients = g_list_append(recipients, g_strdup(addr)); - } - - /* get all of the Cc addresses into our recipient list */ - len = ((CamelAddress *)cc)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get(cc, index, NULL, &addr)) - recipients = g_list_append(recipients, g_strdup(addr)); - } - - /* get all of the Bcc addresses into our recipient list */ - len = ((CamelAddress *)bcc)->addresses->len; - for (index = 0; index < len; index++) { - const char *addr; - - if (camel_internet_address_get(bcc, index, NULL, &addr)) - recipients = g_list_append(recipients, g_strdup(addr)); - } - - return _send_to (transport, message, recipients, ex); -} - -static gchar -*smtp_get_email_addr_from_text (gchar *text) -{ - /* get the actual email address from the string passed and place it in addr - * we can assume the address will be in one of the following forms: - * 1) The Name <person@host.com> - * 2) <person@host.com> - * 3) person@host.com - * 4) person@host.com (The Name) - */ - - gchar *tmp, *addr = NULL; - gchar *addr_strt; /* points to start of addr */ - gchar *addr_end; /* points to end of addr */ - gchar *ptr1; - - - /* check the incoming args */ - if (!text || !*text) - return NULL; - - /* scan the string for an open brace */ - for (addr_strt = text; *addr_strt; addr_strt++) - if (*addr_strt == '<') - break; - - if (*addr_strt) { - /* we found an open brace, let's look for it's counterpart */ - for (addr_end = addr_strt; *addr_end; addr_end++) - if (*addr_end == '>') - break; - - /* if we didn't find it, or braces are empty... */ - if (!(*addr_end) || (addr_strt == addr_end - 1)) - return NULL; - - /* addr_strt points to '<' and addr_end points to '>'. - * Now let's adjust 'em slightly to point to the beginning - * and ending of the email addy - */ - addr_strt++; - addr_end--; - } else { - /* no open brace...assume type 3 or 4? */ - addr_strt = text; - - /* find the end of the email addr/string */ - for (addr_end = addr_strt; *addr_end || *addr_end == ' '; addr_end++); - - addr_end--; /* points to NULL, move it back one char */ - } - - /* now addr_strt & addr_end point to the beginning & ending of the email addy */ - - /* copy the string into addr */ - addr = g_strndup(addr_strt, (gint)(addr_end - addr_strt)); - - for (ptr1 = addr_strt; ptr1 <= addr_end; ptr1++) /* look for an '@' sign */ - if (*ptr1 == '@') - break; - - if (*ptr1 != '@') { - /* here we found out the name doesn't have an '@' part - * let's figure out what machine we're on & stick it on the end - */ - gchar hostname[MAXHOSTNAMELEN]; - - if (gethostname(hostname, MAXHOSTNAMELEN)) { - g_free(addr); - return NULL; - } - tmp = addr; - addr = g_strconcat(tmp, "@", hostname, NULL); - g_free(tmp); - } - - return addr; -} - -static gboolean -smtp_helo (CamelSmtpTransport *transport, CamelException *ex) -{ - /* say hello to the server */ - gchar *cmdbuf, *respbuf = NULL; - struct hostent *host; - - /* get the local host name */ - host = gethostbyaddr((gchar *)&localaddr.sin_addr, sizeof(localaddr.sin_addr), AF_INET); - - /* hiya server! how are you today? */ - if (smtp_is_esmtp) - cmdbuf = g_strdup_printf ("EHLO %s\r\n", host->h_name); - else - cmdbuf = g_strdup_printf ("HELO %s\r\n", host->h_name); - if ( camel_stream_write (transport->ostream, cmdbuf, strlen(cmdbuf), ex) == -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), ex); - 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), ex) == -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), ex); - 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), ex) == -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), ex); - 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), ex) == -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), ex); - 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), ex); - 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), ex) == -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, ex) == -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), ex); - 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), ex) == -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), ex); - 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), ex) == -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), ex); - 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 */ - - diff --git a/camel/providers/smtp/libcamelsmtp.urls b/camel/providers/smtp/libcamelsmtp.urls deleted file mode 100644 index ec2fc0fc16..0000000000 --- a/camel/providers/smtp/libcamelsmtp.urls +++ /dev/null @@ -1 +0,0 @@ -smtp |