talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit cd4249b27a444c8cae26a23bf681461ce31db5ad
parent a83f97812174c6ba20697b1db26e36c289f59519
Author: Oliver Lowe <o@olowe.co>
Date:   Mon,  4 Aug 2025 17:12:14 +0700

Drop mutt and alpine address book import

Maybe can bring it back later. But lots of code for a once-off operation

Diffstat:
Msrc/Makefile.am | 8--------
Msrc/addressbook.c | 84-------------------------------------------------------------------------------
Dsrc/importmutt.c | 304-------------------------------------------------------------------------------
Dsrc/importmutt.h | 30------------------------------
Dsrc/importpine.c | 304-------------------------------------------------------------------------------
Dsrc/importpine.h | 30------------------------------
Dsrc/mutt.c | 563-------------------------------------------------------------------------------
Dsrc/mutt.h | 69---------------------------------------------------------------------
Dsrc/pine.c | 663-------------------------------------------------------------------------------
Dsrc/pine.h | 72------------------------------------------------------------------------
10 files changed, 0 insertions(+), 2127 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -51,10 +51,6 @@ orig_abook_source = \ editvcard.c \ exphtmldlg.c \ exporthtml.c \ - importmutt.c \ - importpine.c \ - mutt.c \ - pine.c \ vcard.c abook_source = $(orig_abook_source) @@ -81,10 +77,6 @@ abook_headers = \ exphtmldlg.h \ exporthtml.h \ file_checker.h \ - importmutt.h \ - importpine.h \ - mutt.h \ - pine.h \ vcard.h claws_mail_SOURCES = \ diff --git a/src/addressbook.c b/src/addressbook.c @@ -65,8 +65,6 @@ #include "editgroup.h" #include "editaddress.h" #include "editbook.h" -#include "importmutt.h" -#include "importpine.h" #include "manual.h" #include "addrquery.h" @@ -305,8 +303,6 @@ static void addressbook_list_select_remove ( AddrItemObject *aio ); static void addressbook_find_duplicates_cb ( GtkAction *action, gpointer data ); static void addressbook_edit_custom_attr_cb ( GtkAction *action, gpointer data ); -static void addressbook_import_mutt_cb ( GtkAction *action, gpointer data ); -static void addressbook_import_pine_cb ( GtkAction *action, gpointer data ); static void addressbook_export_html_cb ( GtkAction *action, gpointer data ); static void addressbook_select_all_cb ( GtkAction *action, gpointer data ); static void addressbook_clip_cut_cb ( GtkAction *action, gpointer data ); @@ -394,9 +390,6 @@ static GtkActionEntry addressbook_entries[] = {"Address/Mailto", NULL, N_("_Mail To"), "<control>M", NULL, G_CALLBACK(addressbook_mail_to_cb) }, {"Address/Merge", NULL, N_("_Merge"), "<control>E", NULL, G_CALLBACK(addressbook_merge_cb) }, - - {"Tools/ImportMutt", NULL, N_("Import M_utt file..."), NULL, NULL, G_CALLBACK(addressbook_import_mutt_cb) }, - {"Tools/ImportPine", NULL, N_("Import _Pine file..."), NULL, NULL, G_CALLBACK(addressbook_import_pine_cb) }, {"Tools/---", NULL, "---", NULL, NULL, NULL }, {"Tools/ExportHTML", NULL, N_("Export _HTML..."), NULL, NULL, G_CALLBACK(addressbook_export_html_cb) }, {"Tools/FindDuplicates", NULL, N_("Find duplicates..."), NULL, NULL, G_CALLBACK(addressbook_find_duplicates_cb) }, @@ -892,8 +885,6 @@ static void addressbook_create(void) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Edit", "Mailto", "Address/Mailto", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Edit", "Merge", "Address/Merge", GTK_UI_MANAGER_MENUITEM) - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ImportMutt", "Tools/ImportMutt", GTK_UI_MANAGER_MENUITEM) - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ImportPine", "Tools/ImportPine", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ExportHTML", "Tools/ExportHTML", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR) @@ -5057,81 +5048,6 @@ gboolean addressbook_peek_folder_exists( gchar *folderpath, return folder_path_match.matched; } - -/** - * Import MUTT file. - */ -static void addressbook_import_mutt_cb( GtkAction *action, gpointer data ) { - AddressDataSource *ds = NULL; - AdapterDSource *ads = NULL; - AddressBookFile *abf = NULL; - AdapterInterface *adapter; - GtkCMCTreeNode *newNode; - - adapter = addrbookctl_find_interface( ADDR_IF_BOOK ); - if( adapter ) { - if( adapter->treeNode ) { - abf = addressbook_imp_mutt( _addressIndex_ ); - if( abf ) { - ds = addrindex_index_add_datasource( - _addressIndex_, ADDR_IF_BOOK, abf ); - ads = addressbook_create_ds_adapter( - ds, ADDR_BOOK, NULL ); - addressbook_ads_set_name( - ads, addrbook_get_name( abf ) ); - newNode = addressbook_add_object( - adapter->treeNode, - ADDRESS_OBJECT(ads) ); - if( newNode ) { - gtk_sctree_select( GTK_SCTREE(addrbook.ctree), - newNode ); - addrbook.treeSelected = newNode; - } - - /* Notify address completion */ - invalidate_address_completion(); - } - } - } -} - -/** - * Import Pine file. - */ -static void addressbook_import_pine_cb( GtkAction *action, gpointer data ) { - AddressDataSource *ds = NULL; - AdapterDSource *ads = NULL; - AddressBookFile *abf = NULL; - AdapterInterface *adapter; - GtkCMCTreeNode *newNode; - - adapter = addrbookctl_find_interface( ADDR_IF_BOOK ); - if( adapter ) { - if( adapter->treeNode ) { - abf = addressbook_imp_pine( _addressIndex_ ); - if( abf ) { - ds = addrindex_index_add_datasource( - _addressIndex_, ADDR_IF_BOOK, abf ); - ads = addressbook_create_ds_adapter( - ds, ADDR_BOOK, NULL ); - addressbook_ads_set_name( - ads, addrbook_get_name( abf ) ); - newNode = addressbook_add_object( - adapter->treeNode, - ADDRESS_OBJECT(ads) ); - if( newNode ) { - gtk_sctree_select( GTK_SCTREE(addrbook.ctree), - newNode ); - addrbook.treeSelected = newNode; - } - - /* Notify address completion */ - invalidate_address_completion(); - } - } - } -} - /** * Harvest addresses. * \param folderItem Folder to import. diff --git a/src/importmutt.c b/src/importmutt.c @@ -1,304 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2022 the Claws Mail team and Match Grun - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -/* - * Import Mutt address book data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "addrbook.h" -#include "addressbook.h" -#include "addressitem.h" -#include "gtkutils.h" -#include "prefs_common.h" -#include "manage_window.h" -#include "mgutils.h" -#include "mutt.h" -#include "filesel.h" - -#define IMPORTMUTT_GUESS_NAME "MUTT Import" - -static struct _ImpMutt_Dlg { - GtkWidget *window; - GtkWidget *file_entry; - GtkWidget *name_entry; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *statusbar; - gint status_cid; -} impmutt_dlg; - -static struct _AddressFileSelection _imp_mutt_file_selector_; -static AddressBookFile *_importedBook_; -static AddressIndex *_imp_addressIndex_; - -/* -* Edit functions. -*/ -static void imp_mutt_status_show( gchar *msg ) { - if( impmutt_dlg.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(impmutt_dlg.statusbar), impmutt_dlg.status_cid ); - if( msg ) { - gtk_statusbar_push( GTK_STATUSBAR(impmutt_dlg.statusbar), impmutt_dlg.status_cid, msg ); - } - } -} - -static gboolean imp_mutt_import_file( gchar *sName, gchar *sFile ) { - gboolean retVal = FALSE; - gchar *newFile; - AddressBookFile *abf = NULL; - MuttFile *mdf = NULL; - - if( _importedBook_ ) { - addrbook_free_book( _importedBook_ ); - } - - abf = addrbook_create_book(); - addrbook_set_path( abf, _imp_addressIndex_->filePath ); - addrbook_set_name( abf, sName ); - newFile = addrbook_guess_next_file( abf ); - addrbook_set_file( abf, newFile ); - g_free( newFile ); - - /* Import data from file */ - mdf = mutt_create(); - mutt_set_file( mdf, sFile ); - if( mutt_import_data( mdf, abf->addressCache ) == MGU_SUCCESS ) { - addrbook_save_data( abf ); - _importedBook_ = abf; - retVal = TRUE; - } - else { - addrbook_free_book( abf ); - } - - mutt_free(mdf); - - return retVal; -} - -static void imp_mutt_ok( GtkWidget *widget, gboolean *cancelled ) { - gchar *sName; - gchar *sFile; - gchar *sMsg = NULL; - gboolean errFlag = FALSE; - - sFile = gtk_editable_get_chars( GTK_EDITABLE(impmutt_dlg.file_entry), 0, -1 ); - g_strstrip( sFile ); - gtk_entry_set_text( GTK_ENTRY(impmutt_dlg.file_entry), sFile ); - - sName = gtk_editable_get_chars( GTK_EDITABLE(impmutt_dlg.name_entry), 0, -1 ); - g_strstrip( sName ); - gtk_entry_set_text( GTK_ENTRY(impmutt_dlg.name_entry), sName ); - - if( *sFile == '\0'|| strlen( sFile ) < 1 ) { - sMsg = _( "Please select a file." ); - errFlag = TRUE; - } - - if( *sName == '\0'|| strlen( sName ) < 1 ) { - if( ! errFlag ) sMsg = _( "Address book name must be supplied." ); - errFlag = TRUE; - } - - if( errFlag ) { - imp_mutt_status_show( sMsg ); - } - else { - /* Import the file */ - if( imp_mutt_import_file( sName, sFile ) ) { - *cancelled = FALSE; - gtk_main_quit(); - } - else { - imp_mutt_status_show( _( "Error importing MUTT file." ) ); - } - } - - g_free( sFile ); - g_free( sName ); - -} - -static void imp_mutt_cancel( GtkWidget *widget, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); -} - -static void imp_mutt_file_select_create( AddressFileSelection *afs ) { - gchar *file = filesel_select_file_open(_("Select MUTT File"), NULL); - - if (file == NULL) - afs->cancelled = TRUE; - else { - afs->cancelled = FALSE; - gtk_entry_set_text( GTK_ENTRY(impmutt_dlg.file_entry), file ); - g_free(file); - } -} - -static void imp_mutt_file_select( void ) { - imp_mutt_file_select_create( & _imp_mutt_file_selector_ ); -} - -static gint imp_mutt_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); - return TRUE; -} - -static gboolean imp_mutt_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) { - if (event && event->keyval == GDK_KEY_Escape) { - *cancelled = TRUE; - gtk_main_quit(); - } - return FALSE; -} - -static void imp_mutt_create( gboolean *cancelled ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *file_entry; - GtkWidget *name_entry; - GtkWidget *hbbox; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *file_btn; - GtkWidget *statusbar; - GtkWidget *hsbox; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "importmutt"); - gtk_widget_set_size_request(window, 450, -1); - gtk_container_set_border_width( GTK_CONTAINER(window), 0 ); - gtk_window_set_title( GTK_WINDOW(window), _("Import MUTT file into Address Book") ); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(imp_mutt_delete_event), cancelled); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(imp_mutt_key_pressed), cancelled); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - name_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), name_entry, 1, 0, 1, 1); - gtk_widget_set_hexpand(name_entry, TRUE); - gtk_widget_set_halign(name_entry, GTK_ALIGN_FILL); - - /* Second row */ - label = gtk_label_new(_("File")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - file_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), file_entry, 1, 1, 1, 1); - gtk_widget_set_hexpand(file_entry, TRUE); - gtk_widget_set_halign(file_entry, GTK_ALIGN_FILL); - - file_btn = gtkut_get_browse_file_btn(_("_Browse")); - gtk_grid_attach(GTK_GRID(table), file_btn, 2, 1, 1, 1); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &cancel_btn, NULL, _("_Cancel"), - &ok_btn, NULL, _("_OK"), - NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(hbbox), 5); - gtk_widget_grab_default(ok_btn); - - g_signal_connect(G_OBJECT(ok_btn), "clicked", - G_CALLBACK(imp_mutt_ok), cancelled); - g_signal_connect(G_OBJECT(cancel_btn), "clicked", - G_CALLBACK(imp_mutt_cancel), cancelled); - g_signal_connect(G_OBJECT(file_btn), "clicked", - G_CALLBACK(imp_mutt_file_select), NULL); - - gtk_widget_show_all(vbox); - - impmutt_dlg.window = window; - impmutt_dlg.file_entry = file_entry; - impmutt_dlg.name_entry = name_entry; - impmutt_dlg.ok_btn = ok_btn; - impmutt_dlg.cancel_btn = cancel_btn; - impmutt_dlg.statusbar = statusbar; - impmutt_dlg.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Import Mutt Dialog" ); -} - -AddressBookFile *addressbook_imp_mutt( AddressIndex *addrIndex ) { - static gboolean cancelled; - gchar *muttFile; - - _importedBook_ = NULL; - _imp_addressIndex_ = addrIndex; - - if( ! impmutt_dlg.window ) - imp_mutt_create(&cancelled); - gtk_widget_grab_focus(impmutt_dlg.ok_btn); - gtk_widget_grab_focus(impmutt_dlg.file_entry); - gtk_widget_show(impmutt_dlg.window); - manage_window_set_transient(GTK_WINDOW(impmutt_dlg.window)); - gtk_window_set_modal(GTK_WINDOW(impmutt_dlg.window), TRUE); - - imp_mutt_status_show( _( "Please select a file to import." ) ); - muttFile = mutt_find_file(); - gtk_entry_set_text( GTK_ENTRY(impmutt_dlg.name_entry), IMPORTMUTT_GUESS_NAME ); - gtk_entry_set_text( GTK_ENTRY(impmutt_dlg.file_entry), muttFile ); - g_free( muttFile ); - muttFile = NULL; - - gtk_main(); - gtk_widget_hide(impmutt_dlg.window); - gtk_window_set_modal(GTK_WINDOW(impmutt_dlg.window), FALSE); - _imp_addressIndex_ = NULL; - - if (cancelled == TRUE) return NULL; - return _importedBook_; -} diff --git a/src/importmutt.h b/src/importmutt.h @@ -1,30 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Import MUTT data. - */ - -#ifndef __IMPORT_MUTT_H__ -#define __IMPORT_MUTT_H__ - -/* Function prototypes */ -AddressBookFile *addressbook_imp_mutt( AddressIndex *addrIndex ); - -#endif /* __IMPORT_MUTT_H__ */ diff --git a/src/importpine.c b/src/importpine.c @@ -1,304 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2002-2022 the Claws Mail team and Match Grun - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -/* - * Import Pine address book data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "addrbook.h" -#include "addressbook.h" -#include "addressitem.h" -#include "gtkutils.h" -#include "prefs_common.h" -#include "manage_window.h" -#include "mgutils.h" -#include "pine.h" -#include "filesel.h" - -#define IMPORTPINE_GUESS_NAME "Pine Import" - -static struct _ImpPine_Dlg { - GtkWidget *window; - GtkWidget *file_entry; - GtkWidget *name_entry; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *statusbar; - gint status_cid; -} imppine_dlg; - -static struct _AddressFileSelection _imp_pine_file_selector_; -static AddressBookFile *_importedBook_; -static AddressIndex *_imp_addressIndex_; - -/* -* Edit functions. -*/ -static void imp_pine_status_show( gchar *msg ) { - if( imppine_dlg.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(imppine_dlg.statusbar), imppine_dlg.status_cid ); - if( msg ) { - gtk_statusbar_push( GTK_STATUSBAR(imppine_dlg.statusbar), imppine_dlg.status_cid, msg ); - } - } -} - -static gboolean imp_pine_import_file( gchar *sName, gchar *sFile ) { - gboolean retVal = FALSE; - gchar *newFile; - AddressBookFile *abf = NULL; - PineFile *pdf = NULL; - - if( _importedBook_ ) { - addrbook_free_book( _importedBook_ ); - } - - abf = addrbook_create_book(); - addrbook_set_path( abf, _imp_addressIndex_->filePath ); - addrbook_set_name( abf, sName ); - newFile = addrbook_guess_next_file( abf ); - addrbook_set_file( abf, newFile ); - g_free( newFile ); - - /* Import data from file */ - pdf = pine_create(); - pine_set_file( pdf, sFile ); - if( pine_import_data( pdf, abf->addressCache ) == MGU_SUCCESS ) { - addrbook_save_data( abf ); - _importedBook_ = abf; - retVal = TRUE; - } - else { - addrbook_free_book( abf ); - } - pine_free(pdf); - - return retVal; -} - -static void imp_pine_ok( GtkWidget *widget, gboolean *cancelled ) { - gchar *sName; - gchar *sFile; - gchar *sMsg = NULL; - gboolean errFlag = FALSE; - - sFile = gtk_editable_get_chars( GTK_EDITABLE(imppine_dlg.file_entry), 0, -1 ); - g_strstrip( sFile ); - gtk_entry_set_text( GTK_ENTRY(imppine_dlg.file_entry), sFile ); - - sName = gtk_editable_get_chars( GTK_EDITABLE(imppine_dlg.name_entry), 0, -1 ); - g_strstrip( sName ); - gtk_entry_set_text( GTK_ENTRY(imppine_dlg.name_entry), sName ); - - if( *sFile == '\0'|| strlen( sFile ) < 1 ) { - sMsg = _( "Please select a file." ); - errFlag = TRUE; - } - - if( *sName == '\0'|| strlen( sName ) < 1 ) { - if( ! errFlag ) sMsg = _( "Address book name must be supplied." ); - errFlag = TRUE; - } - - if( errFlag ) { - imp_pine_status_show( sMsg ); - } - else { - /* Import the file */ - if( imp_pine_import_file( sName, sFile ) ) { - *cancelled = FALSE; - gtk_main_quit(); - } - else { - imp_pine_status_show( _( "Error importing Pine file." ) ); - } - } - - g_free( sFile ); - g_free( sName ); - -} - -static void imp_pine_cancel( GtkWidget *widget, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); -} - -static void imp_pine_file_select_create( AddressFileSelection *afs ) { - gchar *file = filesel_select_file_open(_("Select Pine File"), NULL); - - if (file == NULL) - afs->cancelled = TRUE; - else { - afs->cancelled = FALSE; - gtk_entry_set_text( GTK_ENTRY(imppine_dlg.file_entry), file ); - g_free(file); - } -} - -static void imp_pine_file_select( void ) { - imp_pine_file_select_create( & _imp_pine_file_selector_ ); -} - -static gint imp_pine_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); - return TRUE; -} - -static gboolean imp_pine_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) { - if (event && event->keyval == GDK_KEY_Escape) { - *cancelled = TRUE; - gtk_main_quit(); - } - return FALSE; -} - -static void imp_pine_create( gboolean *cancelled ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *file_entry; - GtkWidget *name_entry; - GtkWidget *hbbox; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *file_btn; - GtkWidget *statusbar; - GtkWidget *hsbox; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "importpine"); - gtk_widget_set_size_request(window, 450, -1); - gtk_container_set_border_width( GTK_CONTAINER(window), 0 ); - gtk_window_set_title( GTK_WINDOW(window), _("Import Pine file into Address Book") ); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(imp_pine_delete_event), cancelled); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(imp_pine_key_pressed), cancelled); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - name_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), name_entry, 1, 0, 1, 1); - gtk_widget_set_hexpand(name_entry, TRUE); - gtk_widget_set_halign(name_entry, GTK_ALIGN_FILL); - - /* Second row */ - label = gtk_label_new(_("File")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - file_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), file_entry, 1, 1, 1, 1); - gtk_widget_set_hexpand(file_entry, TRUE); - gtk_widget_set_halign(file_entry, GTK_ALIGN_FILL); - - file_btn = gtkut_get_browse_file_btn(_("_Browse")); - gtk_grid_attach(GTK_GRID(table), file_btn, 2, 1, 1, 1); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &cancel_btn, NULL, _("_Cancel"), - &ok_btn, NULL, _("_OK"), - NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(hbbox), 5); - gtk_widget_grab_default(ok_btn); - - g_signal_connect(G_OBJECT(ok_btn), "clicked", - G_CALLBACK(imp_pine_ok), cancelled); - g_signal_connect(G_OBJECT(cancel_btn), "clicked", - G_CALLBACK(imp_pine_cancel), cancelled); - g_signal_connect(G_OBJECT(file_btn), "clicked", - G_CALLBACK(imp_pine_file_select), NULL); - - gtk_widget_show_all(vbox); - - imppine_dlg.window = window; - imppine_dlg.file_entry = file_entry; - imppine_dlg.name_entry = name_entry; - imppine_dlg.ok_btn = ok_btn; - imppine_dlg.cancel_btn = cancel_btn; - imppine_dlg.statusbar = statusbar; - imppine_dlg.status_cid = gtk_statusbar_get_context_id( - GTK_STATUSBAR(statusbar), "Import Pine Dialog" ); -} - -AddressBookFile *addressbook_imp_pine( AddressIndex *addrIndex ) { - static gboolean cancelled; - gchar *pineFile; - - _importedBook_ = NULL; - _imp_addressIndex_ = addrIndex; - - if( ! imppine_dlg.window ) - imp_pine_create(&cancelled); - gtk_widget_grab_focus(imppine_dlg.ok_btn); - gtk_widget_grab_focus(imppine_dlg.file_entry); - gtk_widget_show(imppine_dlg.window); - manage_window_set_transient(GTK_WINDOW(imppine_dlg.window)); - gtk_window_set_modal(GTK_WINDOW(imppine_dlg.window), TRUE); - - imp_pine_status_show( _( "Please select a file to import." ) ); - pineFile = pine_find_file(); - gtk_entry_set_text( GTK_ENTRY(imppine_dlg.name_entry), IMPORTPINE_GUESS_NAME ); - gtk_entry_set_text( GTK_ENTRY(imppine_dlg.file_entry), pineFile ); - g_free( pineFile ); - pineFile = NULL; - - gtk_main(); - gtk_widget_hide(imppine_dlg.window); - gtk_window_set_modal(GTK_WINDOW(imppine_dlg.window), FALSE); - _imp_addressIndex_ = NULL; - - if (cancelled == TRUE) return NULL; - return _importedBook_; -} diff --git a/src/importpine.h b/src/importpine.h @@ -1,30 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2002-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Import Pine data. - */ - -#ifndef __IMPORT_PINE_H__ -#define __IMPORT_PINE_H__ - -/* Function prototypes */ -AddressBookFile *addressbook_imp_pine( AddressIndex *addrIndex ); - -#endif /* __IMPORT_PINE_H__ */ diff --git a/src/mutt.c b/src/mutt.c @@ -1,563 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Functions necessary to access MUTT address book file. - */ - -#include "config.h" - -#include <sys/stat.h> -#include <ctype.h> -#include <string.h> -#include <glib.h> - -#include "utils.h" -#include "mgutils.h" -#include "mutt.h" -#include "addritem.h" -#include "addrcache.h" -#include "file-utils.h" - -#define MUTT_HOME_FILE ".muttrc" -#define MUTTBUFSIZE 2048 -#define MUTT_TAG_ALIAS "alias" - -/* -* Create new object. -*/ -MuttFile *mutt_create() { - MuttFile *muttFile; - muttFile = g_new0( MuttFile, 1 ); - muttFile->path = NULL; - muttFile->file = NULL; - muttFile->retVal = MGU_SUCCESS; - muttFile->uniqTable = g_hash_table_new( g_str_hash, g_str_equal ); - muttFile->cbProgress = NULL; - return muttFile; -} - -/* -* Properties... -*/ -void mutt_set_file( MuttFile* muttFile, const gchar *value ) { - cm_return_if_fail( muttFile != NULL ); - muttFile->path = mgu_replace_string( muttFile->path, value ); - g_strstrip( muttFile->path ); -} - -/* - * Free key in table. - */ -static gint mutt_free_table_vis( gpointer key, gpointer value, gpointer data ) { - g_free( key ); - return TRUE; -} - -/* -* Free up object by releasing internal memory. -*/ -void mutt_free( MuttFile *muttFile ) { - cm_return_if_fail( muttFile != NULL ); - - /* Close file */ - if( muttFile->file ) claws_fclose( muttFile->file ); - - /* Free internal stuff */ - g_free( muttFile->path ); - - /* Free unique address table */ - g_hash_table_foreach_remove( muttFile->uniqTable, mutt_free_table_vis, NULL ); - g_hash_table_destroy( muttFile->uniqTable ); - - /* Clear pointers */ - muttFile->file = NULL; - muttFile->path = NULL; - muttFile->retVal = MGU_SUCCESS; - muttFile->uniqTable = NULL; - muttFile->cbProgress = NULL; - - /* Now release file object */ - g_free( muttFile ); -} - -/* -* Open file for read. -* return: TRUE if file opened successfully. -*/ -static gint mutt_open_file( MuttFile* muttFile ) { - if( muttFile->path ) { - muttFile->file = claws_fopen( muttFile->path, "rb" ); - if( ! muttFile->file ) { - muttFile->retVal = MGU_OPEN_FILE; - return muttFile->retVal; - } - } - else { - /* g_print( "file not specified\n" ); */ - muttFile->retVal = MGU_NO_FILE; - return muttFile->retVal; - } - - /* Setup a buffer area */ - muttFile->retVal = MGU_SUCCESS; - return muttFile->retVal; -} - -/* -* Close file. -*/ -static void mutt_close_file( MuttFile *muttFile ) { - cm_return_if_fail( muttFile != NULL ); - if( muttFile->file ) claws_fclose( muttFile->file ); - muttFile->file = NULL; -} - -/* -* Read line of text from file. -* Enter: muttFile File object. -* flagCont Continuation flag, set if back-slash character at EOL. -* Return: ptr to buffer where line starts. -*/ -static gchar *mutt_get_line( MuttFile *muttFile, gboolean *flagCont ) { - gchar buf[ MUTTBUFSIZE ]; - int ch, lch; - int i = 0, li = 0; - - *flagCont = FALSE; - if( claws_feof( muttFile->file ) ) - return NULL; - - memset(buf, 0, MUTTBUFSIZE); - - lch = '\0'; - while( i < MUTTBUFSIZE-1 ) { - ch = fgetc( muttFile->file ); - if( ch == '\0' || ch == EOF ) { - if( i == 0 ) - return NULL; - break; - } - if( ch == '\n' ) { - if( lch == '\\' ) { - /* Replace backslash with NULL */ - if( li != 0 ) - buf[li] = '\0'; - *flagCont = TRUE; - } - break; - } - buf[i] = ch; - li = i; - lch = ch; - i++; - } - buf[i]='\0'; - - /* Copy into private buffer */ - return g_strdup( buf ); -} - -/* - * Parsed address data. - */ -typedef struct _Mutt_ParsedRec_ Mutt_ParsedRec; -struct _Mutt_ParsedRec_ { - gchar *address; - gchar *name; -}; - -/* - * Free data record. - * Enter: rec Data record. - */ -static void mutt_free_rec( Mutt_ParsedRec *rec ) { - if( rec ) { - g_free( rec->address ); - g_free( rec->name ); - rec->address = NULL; - rec->name = NULL; - g_free( rec ); - } -} - -/* -* Parse recipient list for each address. -* Enter: rcpList Recipients extracted from file. -* addrCount Updated with recipient count. -* Return: Linked list of recipients. -*/ -static GSList *mutt_parse_rcplist( gchar *rcpList, gint *addrCount ) { - gchar *ptr, *pStart, *pEnd, *pAddr, *pName, *address, *name; - gchar ch; - GSList *list; - Mutt_ParsedRec *rec; - gint cnt; - - list = NULL; - cnt = 0; - pStart = rcpList; - while( pStart && *pStart ) { - ptr = pStart; - address = NULL; - pName = pAddr = NULL; - /* Chew up spaces */ - while( *ptr ) { - if( ! isspace( *ptr ) ) break; - ptr++; - } - - /* Find address */ - while( *ptr ) { - ch = *ptr; - if( ch == '(' ) { - pAddr = pName = ptr; - break; - } - if( ch == ',' ) { - pAddr = ptr; - ptr++; - break; - } - if( isspace( ch ) ) { - pAddr = ptr; - break; - } - ptr++; - } - - /* Extract address */ - if( pAddr ) { - address = g_strndup( pStart, pAddr - pStart ); - } - else { - address = g_strdup( pStart ); - } - g_strstrip( address ); - - /* Chew up spaces */ - while( *ptr ) { - ch = *ptr; - if( ch == '(' ) { - pName = ptr; - break; - } - if( ch == ',' ) { - ptr++; - break; - } - ptr++; - if( isspace( ch ) ) continue; - } - pStart = ptr; - - /* Extract name (if any) */ - if( pName ) { - /* Look for closing parens */ - pName++; - pEnd = NULL; - ptr = pName; - while( *ptr ) { - if( *ptr == ')' ) { - pEnd = ptr; - break; - } - ptr++; - } - if( pEnd ) { - name = g_strndup( pName, pEnd - pName ); - pEnd++; - if( *pEnd ) pEnd++; - } - else { - name = g_strdup( pName ); - } - g_strstrip( name ); - pStart = pEnd; - } - else { - name = g_strdup( "" ); - } - - /* New record */ - rec = g_new0( Mutt_ParsedRec, 1 ); - rec->address = address; - rec->name = name; - list = g_slist_append( list, rec ); - cnt++; - - /* mutt_print_rec( rec, stdout ); */ - } - *addrCount = cnt; - return list; -} - -/* - * Insert person and address into address cache. - * Enter: muttFile MUTT control data. - * cache Address cache. - * address E-Mail address. - * name Name. - * Return: E-Mail object, either inserted or found in hash table. - */ -static ItemEMail *mutt_insert_table( - MuttFile *muttFile, AddressCache *cache, gchar *address, - gchar *name ) -{ - ItemPerson *person; - ItemEMail *email; - gchar *key; - - /* Test whether address already in hash table */ - key = g_utf8_strdown( address, -1 ); - email = g_hash_table_lookup( muttFile->uniqTable, key ); - - if( email == NULL ) { - /* No - create person */ - person = addritem_create_item_person(); - addritem_person_set_common_name( person, name ); - addrcache_id_person( cache, person ); - addrcache_add_person( cache, person ); - - /* Add email for person */ - email = addritem_create_item_email(); - addritem_email_set_address( email, address ); - addrcache_id_email( cache, email ); - addrcache_person_add_email( cache, person, email ); - - /* Insert entry */ - g_hash_table_insert( muttFile->uniqTable, key, email ); - } - else { - /* Yes - update person with longest name */ - person = ( ItemPerson * ) ADDRITEM_PARENT(email); - if( strlen( name ) > strlen( ADDRITEM_NAME(person) ) ) { - addritem_person_set_common_name( person, name ); - } - - /* Free up */ - g_free( key ); - } - - return email; -} - -/* - * Build address book entries. - * Enter: muttFile MUTT control data. - * cache Address cache. - * aliasName Alias, - * listAddr List of address items. - * addrCount Address list count. - */ -static void mutt_build_address( - MuttFile *muttFile, AddressCache *cache, - gchar *aliasName, GSList *listAddr, gint addrCount ) -{ - GSList *node = NULL; - ItemEMail *email; - ItemGroup *group; - Mutt_ParsedRec *rec; - - group = NULL; - if( listAddr != NULL && addrCount > 1 ) { - group = addritem_create_item_group(); - addritem_group_set_name( group, aliasName ); - addrcache_id_group( cache, group ); - addrcache_add_group( cache, group ); - } - - email = NULL; - node = listAddr; - while( node ) { - rec = node->data; - - /* Insert person/email */ - email = mutt_insert_table( - muttFile, cache, rec->address, rec->name ); - - /* Add email to group */ - if( group ) { - addritem_group_add_email( group, email ); - } - - mutt_free_rec( rec ); - node = g_slist_next( node ); - } -} - -/* - * Parse address line adn build address items. - * Enter: muttFile MUTT control data. - * cache Address cache. - * line Data record. - */ -static void mutt_build_items( MuttFile *muttFile, AddressCache *cache, gchar *line ) { - GList *list, *node; - gint tCount, aCount; - gchar *aliasTag, *aliasName, *recipient; - GSList *addrList; - - /* g_print( "\nBUILD >%s<\n", line ); */ - list = mgu_parse_string( line, 3, &tCount ); - if( tCount < 3 ) { - if( list ) { - g_list_free_full( list, g_free ); - list = NULL; - } - return; - } - - aliasTag = list->data; - node = g_list_next( list ); - aliasName = node->data; - node = g_list_next( node ); - recipient = node->data; - - addrList = NULL; - if( strcmp( aliasTag, MUTT_TAG_ALIAS ) == 0 ) { - aCount = 0; - /* g_print( "aliasName :%s:\n", aliasName ); */ - /* g_print( "recipient :%s:\n", recipient ); */ - addrList = mutt_parse_rcplist( recipient, &aCount ); - /* g_print( "---\n" ); */ - mutt_build_address( muttFile, cache, aliasName, addrList, aCount ); - } - - g_list_free_full( list, g_free ); - list = NULL; - -} - -/* - * Read file data into address cache. - * Enter: muttFile MUTT control data. - * cache Address cache. - */ -static void mutt_read_file( MuttFile *muttFile, AddressCache *cache ) { - GSList *listValue = NULL; - gboolean flagEOF = FALSE, flagCont = FALSE, lastCont = FALSE; - gchar *line = NULL, *lineValue = NULL; - long posEnd = 0L; - long posCur = 0L; - - /* Find EOF for progress indicator */ - fseek( muttFile->file, 0L, SEEK_END ); - posEnd = ftell( muttFile->file ); - fseek( muttFile->file, 0L, SEEK_SET ); - - while( ! flagEOF ) { - flagCont = FALSE; - line = mutt_get_line( muttFile, &flagCont ); - - posCur = ftell( muttFile->file ); - if( muttFile->cbProgress ) { - /* Call progress indicator */ - ( muttFile->cbProgress ) ( muttFile, & posEnd, & posCur ); - } - - if( line == NULL ) flagEOF = TRUE; - if( ! lastCont ) { - /* Save data */ - lineValue = mgu_list_coalesce( listValue ); - if( lineValue ) { - mutt_build_items( muttFile, cache, lineValue ); - } - g_free( lineValue ); - lineValue = NULL; - g_slist_free_full( listValue, g_free ); - listValue = NULL; - } - lastCont = flagCont; - - /* Add line to list */ - listValue = g_slist_append( listValue, g_strdup( line ) ); - - g_free( line ); - line = NULL; - } - - /* Release data */ - g_slist_free_full( listValue, g_free ); - listValue = NULL; -} - -/* -* ============================================================================================ -* Read file into list. Main entry point -* Enter: muttFile MUTT control data. -* cache Address cache to load. -* Return: Status code. -* ============================================================================================ -*/ -gint mutt_import_data( MuttFile *muttFile, AddressCache *cache ) { - cm_return_val_if_fail( muttFile != NULL, MGU_BAD_ARGS ); - cm_return_val_if_fail( cache != NULL, MGU_BAD_ARGS ); - muttFile->retVal = MGU_SUCCESS; - addrcache_clear( cache ); - cache->dataRead = FALSE; - mutt_open_file( muttFile ); - if( muttFile->retVal == MGU_SUCCESS ) { - /* Read data into the cache */ - mutt_read_file( muttFile, cache ); - mutt_close_file( muttFile ); - - /* Mark cache */ - cache->modified = FALSE; - cache->dataRead = TRUE; - } - return muttFile->retVal; -} - -#define WORK_BUFLEN 1024 - -/* -* Attempt to find a Mutt file. -* Return: Filename, or home directory if not found, or empty string if -* no home. Filename should be g_free() when done. -*/ -gchar *mutt_find_file( void ) { - const gchar *homedir; - gchar str[ WORK_BUFLEN + 1 ]; - gint len; - FILE *fp; - - homedir = get_home_dir(); - if( ! homedir ) return g_strdup( "" ); - - strncpy( str, homedir, WORK_BUFLEN ); - len = strlen( str ); - if( len > 0 ) { - if( str[ len-1 ] != G_DIR_SEPARATOR ) { - str[ len ] = G_DIR_SEPARATOR; - str[ ++len ] = '\0'; - } - } - strncat( str, MUTT_HOME_FILE, WORK_BUFLEN - strlen(str) ); - - /* Attempt to open */ - if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) { - claws_fclose( fp ); - } - else { - /* Truncate filename */ - str[ len ] = '\0'; - } - return g_strdup( str ); -} diff --git a/src/mutt.h b/src/mutt.h @@ -1,69 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions necessary to access MUTT addressbook files. These are - * used by the MUTT E-Mail client. - */ - -#ifndef __MUTT_H__ -#define __MUTT_H__ - -#include <stdio.h> -#include <glib.h> - -#include "addrcache.h" - -/* -* Typical MUTT entry: -* -* alias alias-name email-address (friendly-name) [, email-address (friendly-name) ...] -* -* The alias-name maybe the name of an individual or the name of a group -* comprising many individuals. The alias name should not contain the space, -* comma (,) or at (@) character. The friendly-name is optional. A back-slash -* character at end-of-line may be used as a continuation character. -* -* An example: -* -* alias myhome axel@axelrose.com (Axel Rose) -* alias axe axelrose@aol.com (The Axe) -* alias buddies esr@wheres-my-mail.com (Eric Raymond), bgates@hotmail.com (Oops Lost It) -* -*/ - -/* MUTT file object */ -typedef struct _MuttFile MuttFile; -struct _MuttFile { - FILE *file; - gchar *path; - gint retVal; - GHashTable *uniqTable; - void (*cbProgress)( void *, void *, void * ); -}; - -/* Function prototypes */ -MuttFile *mutt_create ( void ); -void mutt_set_file ( MuttFile* muttFile, const gchar *value ); -void mutt_free ( MuttFile *muttFile ); -gint mutt_import_data ( MuttFile *muttFile, AddressCache *cache ); -gchar *mutt_find_file ( void ); - -#endif /* __MUTT_H__ */ - diff --git a/src/pine.c b/src/pine.c @@ -1,663 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2002-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Functions necessary to access Pine address book file. - */ - -#include "config.h" - -#include <sys/stat.h> -#include <glib.h> -#include <string.h> - -#include "utils.h" -#include "mgutils.h" -#include "pine.h" -#include "addritem.h" -#include "addrcache.h" -#include "file-utils.h" - -#define PINE_HOME_FILE ".addressbook" -#define PINEBUFSIZE 2048 -#define CHAR_QUOTE '\"' -#define CHAR_APOS '\'' -#define CHAR_COMMA ',' -#define CHAR_AT '@' - -/* -* Create new object. -*/ -PineFile *pine_create() { - PineFile *pineFile; - pineFile = g_new0( PineFile, 1 ); - pineFile->path = NULL; - pineFile->file = NULL; - pineFile->retVal = MGU_SUCCESS; - pineFile->uniqTable = g_hash_table_new( g_str_hash, g_str_equal ); - pineFile->cbProgress = NULL; - return pineFile; -} - -/* -* Properties... -*/ -void pine_set_file( PineFile* pineFile, const gchar *value ) { - cm_return_if_fail( pineFile != NULL ); - pineFile->path = mgu_replace_string( pineFile->path, value ); - g_strstrip( pineFile->path ); -} - -/* - * Free key in table. - */ -static gint pine_free_table_vis( gpointer key, gpointer value, gpointer data ) { - g_free( key ); - return TRUE; -} - -/* -* Free up object by releasing internal memory. -*/ -void pine_free( PineFile *pineFile ) { - cm_return_if_fail( pineFile != NULL ); - - /* Close file */ - if( pineFile->file ) claws_fclose( pineFile->file ); - - /* Free internal stuff */ - g_free( pineFile->path ); - - /* Free unique address table */ - g_hash_table_foreach_remove( pineFile->uniqTable, pine_free_table_vis, NULL ); - g_hash_table_destroy( pineFile->uniqTable ); - - /* Clear pointers */ - pineFile->file = NULL; - pineFile->path = NULL; - pineFile->retVal = MGU_SUCCESS; - pineFile->uniqTable = NULL; - pineFile->cbProgress = NULL; - - /* Now release file object */ - g_free( pineFile ); -} - -/* - * Open file for read. - * Enter: pineFile File object. - * return: TRUE if file opened successfully. - */ -static gint pine_open_file( PineFile* pineFile ) { - if( pineFile->path ) { - pineFile->file = claws_fopen( pineFile->path, "rb" ); - if( ! pineFile->file ) { - pineFile->retVal = MGU_OPEN_FILE; - return pineFile->retVal; - } - } - else { - /* g_print( "file not specified\n" ); */ - pineFile->retVal = MGU_NO_FILE; - return pineFile->retVal; - } - - /* Setup a buffer area */ - pineFile->retVal = MGU_SUCCESS; - return pineFile->retVal; -} - -/* - * Close file. - * Enter: pineFile File object. - */ -static void pine_close_file( PineFile *pineFile ) { - cm_return_if_fail( pineFile != NULL ); - if( pineFile->file ) claws_fclose( pineFile->file ); - pineFile->file = NULL; -} - -/* - * Read line of text from file. - * Enter: pineFile File object. - * Return: Copy of buffer. Should be g_free'd when done. - */ -static gchar *pine_read_line( PineFile *pineFile ) { - gchar buf[ PINEBUFSIZE ]; - int c, i = 0; - gchar ch; - - if( claws_feof( pineFile->file ) ) - return NULL; - - while( i < PINEBUFSIZE-1 ) { - c = fgetc( pineFile->file ); - if( c == EOF ) { - if( i == 0 ) - return NULL; - break; - } - ch = (gchar) c; - if( ch == '\0' ) { - if( i == 0 ) - return NULL; - break; - } - if( ch == '\n' ) { - break; - } - buf[i] = ch; - i++; - } - buf[i] = '\0'; - - /* Copy into private buffer */ - return g_strdup( buf ); -} - -/* - * Parsed address data. - */ -typedef struct _Pine_ParsedRec_ Pine_ParsedRec; -struct _Pine_ParsedRec_ { - gchar *nickName; - gchar *name; - gchar *address; - gchar *fcc; - gchar *comments; - gboolean isGroup; - GSList *listName; - GSList *listAddr; -}; - -/* - * Free data record. - * Enter: rec Data record. - */ -static void pine_free_rec( Pine_ParsedRec *rec ) { - if( rec ) { - g_free( rec->nickName ); - g_free( rec->name ); - g_free( rec->address ); - g_free( rec->fcc ); - g_free( rec->comments ); - g_slist_free_full( rec->listName, g_free ); - g_slist_free_full( rec->listAddr, g_free ); - rec->nickName = NULL; - rec->name = NULL; - rec->address = NULL; - rec->fcc = NULL; - rec->comments = NULL; - rec->isGroup = FALSE; - g_free( rec ); - } -} - -/* - * Clean name. - */ -static void pine_clean_name( Pine_ParsedRec *rec ) { - gchar *p; - - p = rec->name; - if( p == NULL ) return; - if( *p == '\0' ) return; - - g_strstrip( rec->name ); - if( *p == CHAR_APOS || *p == CHAR_QUOTE ) { - return; - } - - /* If embedded comma present, surround match with quotes */ - while( *p ) { - if( *p == CHAR_COMMA ) { - p = g_strdup_printf( "\"%s\"", rec->name ); - g_free( rec->name ); - rec->name = p; - return; - } - p++; - } -} - -/* - * Parse pine address record. - * Enter: buf Address record buffer. - * Return: Data record. - */ -static Pine_ParsedRec *pine_parse_record( gchar *buf ) { - Pine_ParsedRec *rec; - gchar *p, *f; - gint pos, len, i; - gchar *tmp[5]; - - for( i = 0; i < 5; i++ ) - tmp[i] = NULL; - - /* Extract tab separated values */ - rec = NULL; - pos = 0; - p = f = buf; - while( *p ) { - if( *p == '\t' ) { - len = p - f; - if( len > 0 ) { - tmp[ pos ] = g_strndup( f, len ); - f = p; - f++; - } - pos++; - } - p++; - } - - /* Extract last value */ - len = p - f; - if( len > 0 ) { - tmp[ pos++ ] = g_strndup( f, len ); - } - - /* Populate record */ - if( pos > 0 ) { - rec = g_new0( Pine_ParsedRec, 1 ); - rec->isGroup = FALSE; - for( i = 0; i < pos; i++ ) { - f = tmp[i]; - if( f ) { - g_strstrip( f ); - } - if( i == 0 ) rec->nickName = f; - else if( i == 1 ) rec->name = f; - else if( i == 2 ) rec->address = f; - else if( i == 3 ) rec->fcc = f; - else if( i == 4 ) rec->comments = f; - tmp[i] = NULL; - } - - if( rec->address != NULL ) { - /* Strip leading/trailing parens */ - p = rec->address; - if( *p == '(' ) { - len = strlen( p ) - 1; - *p = ' '; - *(p + len) = ' '; - rec->isGroup = TRUE; - } - } - } - - return rec; -} - -/* - * Parse name from email address string. - * Enter: buf Start address of buffer to process (not modified). - * atp Pointer to email at (@) character. - * ap Pointer to start of email address returned. - * ep Pointer to end of email address returned. - * Return: Parsed name or NULL if not present. This should be g_free'd - * when done. - */ -static gchar *pine_parse_name( - const gchar *buf, const gchar *atp, const gchar **ap, - const gchar **ep ) -{ - gchar *name; - const gchar *pos; - const gchar *tmp; - const gchar *bp; - gint ilen; - - name = NULL; - *ap = NULL; - *ep = NULL; - - /* Find first non-separator char */ - bp = buf; - while( TRUE ) { - if( strchr( ",; \n\r", *bp ) == NULL ) break; - bp++; - } - - /* Search back for start of name */ - tmp = atp; - pos = atp; - while( pos >= bp ) { - tmp = pos; - if( *pos == '<' ) { - /* Found start of address/end of name part */ - ilen = -1 + ( size_t ) ( pos - bp ); - name = g_strndup( bp, ilen + 1 ); - *(name + ilen + 1) = '\0'; - - /* Remove leading trailing quotes and spaces */ - mgu_str_ltc2space( name, '\"', '\"' ); - mgu_str_ltc2space( name, '\'', '\'' ); - mgu_str_ltc2space( name, '\"', '\"' ); - mgu_str_unescape( name ); - g_strstrip( name ); - break; - } - pos--; - } - *ap = tmp; - - /* Search forward for end of address */ - pos = atp + 1; - while( TRUE ) { - if( *pos == '>' ) { - pos++; - break; - } - if( strchr( ",; \'\n\r", *pos ) ) break; - pos++; - } - *ep = pos; - - return name; -} - -/* - * Parse address list. - * Enter: pineFile Pine control data. - * cache Address cache. - * rec Data record. - */ -static void pine_parse_address( PineFile *pineFile, AddressCache *cache, Pine_ParsedRec *rec ) { - const gchar *buf; - gchar addr[ PINEBUFSIZE ]; - const gchar *bp; - const gchar *ep; - gchar *atCh; - gchar *name; - gint len; - - cm_return_if_fail( rec->address != NULL ); - - buf = rec->address; - while((atCh = strchr( buf, CHAR_AT )) != NULL) { - name = pine_parse_name( buf, atCh, &bp, &ep ); - len = ( size_t ) ( ep - bp ); - strncpy( addr, bp, len ); - addr[ len ] = '\0'; - extract_address( addr ); - - if( name == NULL ) name = g_strdup( "" ); - rec->listName = g_slist_append( rec->listName, name ); - rec->listAddr = g_slist_append( rec->listAddr, g_strdup( addr ) ); - - buf = ep; - if( atCh == ep ) { - buf++; - } - } -} - -/* - * Insert person and address into address cache. - * Enter: pineFile Pine control data. - * cache Address cache. - * address E-Mail address. - * name Name. - * remarks Remarks. - * Return: E-Mail object, either inserted or found in hash table. - */ -static ItemEMail *pine_insert_table( - PineFile *pineFile, AddressCache *cache, gchar *address, - gchar *name, gchar *remarks ) -{ - ItemPerson *person; - ItemEMail *email; - gchar *key; - - cm_return_val_if_fail( address != NULL, NULL ); - - /* create an entry with empty name if needed */ - if ( name == NULL ) - name = ""; - - /* Test whether address already in hash table */ - key = g_utf8_strdown( address, -1 ); - email = g_hash_table_lookup( pineFile->uniqTable, key ); - - if( email == NULL ) { - /* No - create person */ - person = addritem_create_item_person(); - addritem_person_set_common_name( person, name ); - addrcache_id_person( cache, person ); - addrcache_add_person( cache, person ); - - /* Add email for person */ - email = addritem_create_item_email(); - addritem_email_set_address( email, address ); - addritem_email_set_remarks( email, remarks ); - addrcache_id_email( cache, email ); - addrcache_person_add_email( cache, person, email ); - - /* Insert entry */ - g_hash_table_insert( pineFile->uniqTable, key, email ); - } - else { - /* Yes - update person with longest name */ - person = ( ItemPerson * ) ADDRITEM_PARENT(email); - if( strlen( name ) > strlen( ADDRITEM_NAME(person) ) ) { - addritem_person_set_common_name( person, name ); - } - - /* Free up */ - g_free( key ); - } - - return email; -} - -/* - * Parse address line adn build address items. - * Enter: pineFile Pine control data. - * cache Address cache to load. - * line Address record. - */ -static void pine_build_items( PineFile *pineFile, AddressCache *cache, gchar *line ) { - Pine_ParsedRec *rec; - GSList *nodeAddr, *nodeName; - ItemGroup *group; - ItemEMail *email; - - rec = pine_parse_record( line ); - if( rec ) { - pine_clean_name( rec ); - pine_parse_address( pineFile, cache, rec ); - /* pine_print_rec( rec, stdout ); */ - /* g_print( "=========\n" ); */ - - if( rec->isGroup ) { - /* Create group */ - group = addritem_create_item_group(); - addritem_group_set_name( group, rec->nickName ); - addrcache_id_group( cache, group ); - addrcache_add_group( cache, group ); - - /* Add email to group */ - nodeName = rec->listName; - nodeAddr = rec->listAddr; - while( nodeAddr ) { - email = pine_insert_table( - pineFile, cache, nodeAddr->data, - nodeName->data, "" ); - - /* Add email to group */ - addritem_group_add_email( group, email ); - - nodeAddr = g_slist_next( nodeAddr ); - nodeName = g_slist_next( nodeName ); - } - } - else { - pine_insert_table( - pineFile, cache, rec->address, - rec->name, rec->comments ); - } - - pine_free_rec( rec ); - } -} - -/* - * Read file data into address cache. - * Enter: pineFile Pine control data. - * cache Address cache to load. - */ -static void pine_read_file( PineFile *pineFile, AddressCache *cache ) { - GSList *listValue = NULL; - gboolean flagEOF = FALSE, flagProc = FALSE, flagDone = FALSE; - gchar *line = NULL, *lineValue = NULL; - long posEnd = 0L; - long posCur = 0L; - - /* Find EOF for progress indicator */ - fseek( pineFile->file, 0L, SEEK_END ); - posEnd = ftell( pineFile->file ); - fseek( pineFile->file, 0L, SEEK_SET ); - - flagProc = FALSE; - while( ! flagDone ) { - if( flagEOF ) { - flagDone = TRUE; - flagProc = TRUE; - } - else { - line = pine_read_line( pineFile ); - } - - posCur = ftell( pineFile->file ); - if( pineFile->cbProgress ) { - /* Call progress indicator */ - ( pineFile->cbProgress ) ( pineFile, & posEnd, & posCur ); - } - - /* Add line to list */ - if( line == NULL ) { - flagEOF = TRUE; - } - else { - /* Check for continuation line (1 space only) */ - if( *line == ' ' ) { - g_strchug( line ); - listValue = g_slist_append( - listValue, g_strdup( line ) ); - flagProc = FALSE; - } - else { - flagProc = TRUE; - } - } - - if( flagProc ) { - if( listValue != NULL ) { - /* Process list */ - lineValue = mgu_list_coalesce( listValue ); - if( lineValue ) { - pine_build_items( - pineFile, cache, lineValue ); - } - g_free( lineValue ); - lineValue = NULL; - g_slist_free_full( listValue, g_free ); - listValue = NULL; - } - if( line != NULL ) { - /* Append to list */ - listValue = g_slist_append( - listValue, g_strdup( line ) ); - } - } - - g_free( line ); - line = NULL; - } - - /* Release data */ - g_slist_free_full( listValue, g_free ); - listValue = NULL; -} - -/* - * ============================================================================================ - * Read file into list. Main entry point - * Enter: pineFile Pine control data. - * cache Address cache to load. - * Return: Status code. - * ============================================================================================ - */ -gint pine_import_data( PineFile *pineFile, AddressCache *cache ) { - cm_return_val_if_fail( pineFile != NULL, MGU_BAD_ARGS ); - cm_return_val_if_fail( cache != NULL, MGU_BAD_ARGS ); - - pineFile->retVal = MGU_SUCCESS; - addrcache_clear( cache ); - cache->dataRead = FALSE; - pine_open_file( pineFile ); - if( pineFile->retVal == MGU_SUCCESS ) { - /* Read data into the cache */ - pine_read_file( pineFile, cache ); - pine_close_file( pineFile ); - - /* Mark cache */ - cache->modified = FALSE; - cache->dataRead = TRUE; - } - return pineFile->retVal; -} - -#define WORK_BUFLEN 1024 - -/* - * Attempt to find a Pine addressbook file. - * Return: Filename, or home directory if not found, or empty string if - * no home. Filename should be g_free() when done. - */ -gchar *pine_find_file( void ) { - const gchar *homedir; - gchar str[ WORK_BUFLEN + 1 ]; - gint len; - FILE *fp; - - homedir = get_home_dir(); - if( ! homedir ) return g_strdup( "" ); - - strncpy( str, homedir, WORK_BUFLEN ); - len = strlen( str ); - if( len > 0 ) { - if( str[ len-1 ] != G_DIR_SEPARATOR ) { - str[ len ] = G_DIR_SEPARATOR; - str[ ++len ] = '\0'; - } - } - strncat( str, PINE_HOME_FILE, WORK_BUFLEN - strlen(str) ); - - /* Attempt to open */ - if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) { - claws_fclose( fp ); - } - else { - /* Truncate filename */ - str[ len ] = '\0'; - } - return g_strdup( str ); -} diff --git a/src/pine.h b/src/pine.h @@ -1,72 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2002-2012 Match Grun and the Claws Mail team - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions necessary to access Pine addressbook files. These are - * used by the Pine E-Mail client. - */ - -#ifndef __PINE_H__ -#define __PINE_H__ - -#include <stdio.h> -#include <glib.h> - -#include "addrcache.h" - -/* -* Typical Pine simple entry: -* -* nick-name \t friendly-name \t email-address \t fcc \t comments -* -* Or for a distribution list: -* -* group-name \t friendly-name \t ( email, email, ... ) \t fcc \t comments -* -* The record is may span several lines if longer than about 80 characters. -* Pine formats subsequent line with exactly 3 spaces to indicate that the -* line is a continuation. -* -* An example: -* -* axe \t Axel Rose \t axelrose@aol.com \t \t Guitar player -* \t Axel Rose \t axelrose@aol.com \t \t Guitarist -* evilaxis \t \t (bgates@hotmail.com,shoebomber@empire.com) \t \t Axis of Evil -* -*/ - -/* Pine file object */ -typedef struct _PineFile PineFile; -struct _PineFile { - FILE *file; - gchar *path; - gint retVal; - GHashTable *uniqTable; - void (*cbProgress)( void *, void *, void * ); -}; - -/* Function prototypes */ -PineFile *pine_create ( void ); -void pine_set_file ( PineFile* pineFile, const gchar *value ); -void pine_free ( PineFile *pineFile ); -gint pine_import_data ( PineFile *pineFile, AddressCache *cache ); -gchar *pine_find_file ( void ); - -#endif /* __PINE_H__ */ -