Address harvest recurse folders.
authorMatch Grun <match@dimensional.com>
Sat, 20 Apr 2002 03:35:55 +0000 (03:35 +0000)
committerMatch Grun <match@dimensional.com>
Sat, 20 Apr 2002 03:35:55 +0000 (03:35 +0000)
src/addressbook.c
src/addressbook.h
src/addrgather.c
src/addrgather.h
src/addrharvest.c
src/addrharvest.h
src/mainwindow.c
src/summaryview.c
src/summaryview.h

index a0a7501..00323e0 100644 (file)
@@ -3967,18 +3967,22 @@ static void addressbook_import_pine_cb() {
 }
 
 /*
- * Gather addresses.
+ * Harvest addresses.
  * Enter: folderItem Folder to import.
+ *        sourceInd  Source indicator: FALSE - Folder, TRUE - Messages.
  *        msgList    List of message numbers, or NULL to process folder.
  */
-void addressbook_gather( FolderItem *folderItem, GList *msgList ) {
+void addressbook_harvest(
+       FolderItem *folderItem, gboolean sourceInd, GList *msgList )
+{
        AddressDataSource *ds = NULL;
        AdapterDSource *ads = NULL;
        AddressBookFile *abf = NULL;
        AdapterInterface *adapter;
        GtkCTreeNode *newNode;
 
-       abf = addrgather_dlg_execute( folderItem, _addressIndex_, msgList );
+       abf = addrgather_dlg_execute(
+               folderItem, _addressIndex_, sourceInd, msgList );
        if( abf ) {
                ds = addrindex_index_add_datasource(
                        _addressIndex_, ADDR_IF_BOOK, abf );
index 6d03c22..cc9ca94 100644 (file)
@@ -41,6 +41,7 @@ gboolean addressbook_add_contact      ( const gchar   *name,
 gboolean addressbook_load_completion   ( gint (*callBackFunc) ( const gchar *, const gchar *, const gchar * ) );
 
 void addressbook_gather                        ( FolderItem *folderItem,
+                                         gboolean sourceInd,
                                          GList *msgList );
 
 #endif /* __ADDRESSBOOK_H__ */
index 7bf7c65..ab4f764 100644 (file)
 typedef enum {
        FIELD_COL_HEADER = 0,
        FIELD_COL_COUNT  = 1
-} AddrGather_FieldColPos;
+} AddrHarvest;
 
 /*
 * The dialog.
 */
-static struct _AddrGather_Dlg_ {
+static struct _AddrHarvest {
        GtkWidget *window;
        GtkWidget *notebook;
        GtkWidget *labelFolder;
        GtkWidget *entryBook;
        GtkWidget *checkHeader[ NUM_FIELDS ];
        GtkWidget *spinbtnFolder;
+       GtkWidget *checkRecurse;
        GtkWidget *btnOk;
        GtkWidget *btnCancel;
        GtkWidget *statusbar;
@@ -166,6 +167,9 @@ static gboolean addrgather_dlg_harvest() {
                gtk_toggle_button_get_active(
                        GTK_TOGGLE_BUTTON(addrgather_dlg.checkHeader[i]) ) );
        }
+       addrharvest_set_recurse( harvester,
+               gtk_toggle_button_get_active(
+                       GTK_TOGGLE_BUTTON( addrgather_dlg.checkRecurse ) ) );
 
        if( addrharvest_check_header( harvester ) == FALSE ) {
                addrgather_dlg_status_show(
@@ -174,6 +178,8 @@ static gboolean addrgather_dlg_harvest() {
                return FALSE;
        }
 
+       /* Go fer it */
+       addrgather_dlg_status_show( _( "Busy harvesting addresses..." ) );
        sz = gtk_spin_button_get_value_as_int(
                GTK_SPIN_BUTTON( addrgather_dlg.spinbtnFolder ) );
        addrharvest_set_folder_size( harvester, sz );
@@ -275,15 +281,21 @@ static void addrgather_page_warning( gint pageNum, gchar *pageLbl ) {
 
        /* First row */
        top++;
-       label = gtk_label_new(_("No folder was selected."));
+       label = gtk_label_new( _("No folder or message was selected." ) );
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
-       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_LEFT );
+       gtk_misc_set_alignment( GTK_MISC(label), 0, 0.5 );
 
        /* Second row */
        top++;
-       label = gtk_label_new(_("Please select a folder to process from the folder list."));
-       gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
-       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+       label = gtk_label_new( _(
+                       "Please select a folder to process from the folder\n"
+                       "list. Alternatively, select one or messages from\n"
+                       "the message list." ) );
+
+       gtk_table_attach( GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
+       gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_LEFT );
+       gtk_misc_set_alignment( GTK_MISC(label), 0, 0.5 );
 }
 
 /*
@@ -303,6 +315,7 @@ static void addrgather_page_fields( gint pageNum, gchar *pageLbl ) {
        GtkWidget *checkHeader[ NUM_FIELDS ];
        GtkWidget *spinbtnFolder;
        GtkObject *adjFolder;
+       GtkWidget *checkRecurse;
        gint top;
        gint i;
 
@@ -380,9 +393,16 @@ static void addrgather_page_fields( gint pageNum, gchar *pageLbl ) {
                addrgather_dlg.checkHeader[i] = checkHeader[i];
        }
 
+       /* Recurse folders */
+       top += 4;
+       checkRecurse = gtk_check_button_new_with_label( _("Include sub-folders" ) );
+       gtk_table_attach( GTK_TABLE(table), checkRecurse, 0, 2, top, (top + 1),
+                       GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0 );
+
        addrgather_dlg.labelFolder   = labelFolder;
        addrgather_dlg.entryBook     = entryBook;
        addrgather_dlg.spinbtnFolder = spinbtnFolder;
+       addrgather_dlg.checkRecurse  = checkRecurse;
 }
 
 /*
@@ -500,7 +520,7 @@ static void addrgather_dlg_create( void ) {
        addrgather_dlg.btnCancel  = btnCancel;
        addrgather_dlg.statusbar  = statusbar;
        addrgather_dlg.status_cid = gtk_statusbar_get_context_id(
-               GTK_STATUSBAR(statusbar), "Gather E-Mail Address Dialog" );
+               GTK_STATUSBAR(statusbar), "Harvest E-Mail Address Dialog" );
 
        /* Create notebook pages */
        addrgather_page_warning( PAGE_WARNING, _( "Warning" ) );
@@ -510,14 +530,16 @@ static void addrgather_dlg_create( void ) {
 }
 
 /*
- * Gather addresses main window.
+ * Harvest addresses main window.
  * Enter: folderItem Source folder.
  *        addrIndex  Address index.
+ *        sourceInd  Source indicator: FALSE - Folder, TRUE - Messages.
  *        msgList    List of message numbers, or NULL to process folder.
  * Return: Populated address book file, or NULL if none created.
  */
 AddressBookFile *addrgather_dlg_execute(
-       FolderItem *folderItem, AddressIndex *addrIndex, GList *msgList )
+       FolderItem *folderItem, AddressIndex *addrIndex, gboolean sourceInd,
+       GList *msgList )
 {
        gboolean errFlag;
        gint i;
@@ -558,25 +580,36 @@ AddressBookFile *addrgather_dlg_execute(
                gtk_widget_grab_default( addrgather_dlg.btnOk );
                errFlag = FALSE;
        }
-       else {
-               gtk_notebook_set_page(
-                       GTK_NOTEBOOK(addrgather_dlg.notebook), PAGE_WARNING );
-               gtk_widget_set_sensitive( addrgather_dlg.btnOk, FALSE );
-               gtk_widget_grab_default( addrgather_dlg.btnCancel );
-       }
 
-       if( msgList ) {
+       /* Apply window title */
+       if( sourceInd ) {
                gtk_window_set_title( GTK_WINDOW(addrgather_dlg.window),
-                       _("Gather E-Mail Addresses - from Selected Messages") );
+                       _("Harvest E-Mail Addresses - from Selected Messages") );
+               gtk_widget_set_sensitive( addrgather_dlg.checkRecurse, FALSE );
+               if( msgList == NULL ) {
+                       errFlag = TRUE;
+               }
        }
        else {
                gtk_window_set_title( GTK_WINDOW(addrgather_dlg.window),
-                       _("Gather E-Mail Addresses - from Folder") );
+                       _("Harvest E-Mail Addresses - from Folder") );
+               gtk_widget_set_sensitive( addrgather_dlg.checkRecurse, TRUE );
        }
+       gtk_toggle_button_set_active(
+               GTK_TOGGLE_BUTTON( addrgather_dlg.checkRecurse ), FALSE );
+
        addrgather_dlg_status_show( "" );
        gtk_widget_show( addrgather_dlg.window );
 
-       gtk_widget_grab_focus( addrgather_dlg.entryBook );
+       if( errFlag ) {
+               gtk_notebook_set_page(
+                       GTK_NOTEBOOK(addrgather_dlg.notebook), PAGE_WARNING );
+               gtk_widget_set_sensitive( addrgather_dlg.btnOk, FALSE );
+               gtk_widget_grab_default( addrgather_dlg.btnCancel );
+       }
+       else {
+               gtk_widget_grab_focus( addrgather_dlg.entryBook );
+       }
        manage_window_set_transient( GTK_WINDOW(addrgather_dlg.window) );
        gtk_main();
 
index c50d9ae..88ab8fa 100644 (file)
@@ -27,6 +27,7 @@
 /* Function prototypes */
 AddressBookFile *addrgather_dlg_execute( FolderItem *folderItem,
                                         AddressIndex *addrIndex,
+                                        gboolean sourceInd,
                                         GList *msgList );
 
 #endif /* __ADDR_GATHER_H__ */
index c06d717..4a75163 100644 (file)
@@ -49,6 +49,9 @@ static gchar *_headerTo_       = HEADER_TO;
 #define REM_NAME_STRING  "(E-mail)"
 #define REM_NAME_STRING2 "(E-mail 2)"
 
+/* Directories to ignore */
+#define DIR_IGNORE ".\t..\t.sylpheed_mark\t.sylpheed_cache"
+
 /*
  * Header entry.
  */
@@ -176,6 +179,18 @@ void addrharvest_set_folder_size(
        }
 }
 
+/*
+ * Specify folder recursion.
+ * Entry: harvester Harvester object.
+ *        value     TRUE to process sub-folders, FALSE to process folder only.
+ */
+void addrharvest_set_recurse(
+       AddressHarvester* harvester, const gboolean value )
+{
+       g_return_if_fail( harvester != NULL );
+       harvester->folderRecurse = value;
+}
+
 /*
  * Search (case insensitive) for header entry with specified name.
  * Enter: harvester Harvester.
@@ -712,6 +727,81 @@ static gint addrharvest_readfile(
        return MGU_SUCCESS;
 }
 
+/*
+ * Read all files in specified directory into address book. Directories are
+ * traversed recursively if necessary.
+ * Enter:  harvester Harvester object.
+ *         cache     Address cache to load.
+ *         msgList   List of message numbers, or NULL to process folder.
+ *         dir       Directory to process.
+ */
+static void addrharvest_harvest_dir(
+       AddressHarvester *harvester, AddressCache *cache, GList *listHdr,
+       gchar *dir )
+{
+       DIR *dp;
+       struct dirent *d;
+       struct stat s;
+       gint num;
+
+       if( ( dp = opendir( dir ) ) == NULL ) {
+               return;
+       }
+
+       /* Process directory */
+       chdir( dir );
+       while( ( d = readdir( dp ) ) != NULL ) {
+               stat( d->d_name, &s );
+               if( S_ISDIR( s.st_mode ) ) {
+                       if( harvester->folderRecurse ) {
+                               if( strstr( DIR_IGNORE, d->d_name ) != NULL )
+                                       continue;
+                               addrharvest_harvest_dir(
+                                       harvester, cache, listHdr, d->d_name );
+                       }
+               }
+               if( S_ISREG( s.st_mode ) ) {
+                       if( ( num = to_number( d->d_name ) ) >= 0 ) {
+                               addrharvest_readfile(
+                                       harvester, d->d_name, cache, listHdr );
+                       }
+               }
+       }
+       chdir( ".." );
+       closedir( dp );
+}
+
+/*
+ * Read list of files in specified directory into address book.
+ * Enter:  harvester Harvester object.
+ *         cache     Address cache to load.
+ *         msgList   List of message numbers, or NULL to process folder.
+ */
+static void addrharvest_harvest_list(
+       AddressHarvester *harvester, AddressCache *cache, GList *listHdr,
+       GList *msgList )
+{
+       DIR *dp;
+       gint num;
+       GList *node;
+       gchar msgNum[ MSGNUM_BUFFSIZE ];
+
+       if( ( dp = opendir( harvester->path ) ) == NULL ) {
+               return;
+       }
+
+       /* Process message list */
+       chdir( harvester->path );
+       node = msgList;
+       while( node ) {
+               num = GPOINTER_TO_UINT( node->data );
+               sprintf( msgNum, "%d", num );
+               addrharvest_readfile( harvester, msgNum, cache, listHdr );
+               node = g_list_next( node );
+       }
+       closedir( dp );
+}
+
 /*
  * ============================================================================
  * Read all files in specified directory into address book.
@@ -725,13 +815,8 @@ gint addrharvest_harvest(
        AddressHarvester *harvester, AddressCache *cache, GList *msgList )
 {
        gint retVal;
-       DIR *dp;
-       struct dirent *d;
-       struct stat s;
-       gint num;
        GList *node;
        GList *listHdr;
-       gchar msgNum[ MSGNUM_BUFFSIZE ];
 
        retVal = MGU_BAD_ARGS;
        g_return_val_if_fail( harvester != NULL, retVal );
@@ -742,16 +827,6 @@ gint addrharvest_harvest(
        addrcache_clear( cache );
        cache->dataRead = FALSE;
 
-       if( chdir( harvester->path ) < 0 ) {
-               /* printf( "Error changing dir\n" ); */
-               return retVal;
-       }
-
-       if( ( dp = opendir( harvester->path ) ) == NULL ) {
-               /* printf( "Error opening dir\n" ); */
-               return retVal;
-       }
-
        /* Build list of headers of interest */
        listHdr = NULL;
        node = harvester->headerTable;
@@ -769,33 +844,15 @@ gint addrharvest_harvest(
                node = g_list_next( node );
        }
 
+       /* Process directory/files */
        if( msgList == NULL ) {
-               /* Process directory */
-               while( ( d = readdir( dp ) ) != NULL ) {
-                       stat( d->d_name, &s );
-                       if( S_ISREG( s.st_mode ) ) {
-                               if( ( num = to_number( d->d_name ) ) >= 0 ) {
-                                       addrharvest_readfile(
-                                               harvester, d->d_name, cache, listHdr );
-                               }
-                       }
-               }
+               addrharvest_harvest_dir( harvester, cache, listHdr, harvester->path );
        }
        else {
-               /* Process message list */
-               node = msgList;
-               while( node ) {
-                       num = GPOINTER_TO_UINT( node->data );
-                       sprintf( msgNum, "%d", num );
-                       addrharvest_readfile(
-                               harvester, msgNum, cache, listHdr );
-                       node = g_list_next( node );
-               }
+               addrharvest_harvest_list( harvester, cache, listHdr, msgList );
        }
        mgu_free_dlist( listHdr );
 
-       closedir( dp );
-
        /* Mark cache */
        cache->modified = FALSE;
        cache->dataRead = TRUE;
index 061fcce..b66d442 100644 (file)
@@ -44,6 +44,7 @@ struct _AddressHarvester {
        GHashTable *dupTable;
        gint       folderSize;
        gint       retVal;
+       gboolean   folderRecurse;
 };
 
 /* Function prototypes */
@@ -56,6 +57,8 @@ void addrharvest_set_folder_size      ( AddressHarvester* harvester,
 void addrharvest_set_header            ( AddressHarvester* harvester,
                                          const gchar *name,
                                          const gboolean value );
+void addrharvest_set_recurse           ( AddressHarvester* harvester,
+                                         const gboolean value );
 gint addrharvest_get_count             ( AddressHarvester* harvester,
                                          const gchar *name );
 void addrharvest_print                 ( AddressHarvester *harvester,
index 24c6c49..7d2c443 100644 (file)
@@ -457,11 +457,11 @@ static void key_pressed (GtkWidget *widget,
 
 static void set_toolbar_style(MainWindow *mainwin);
 
-static void addr_gather_cb      ( MainWindow  *mainwin,
+static void addr_harvest_cb     ( MainWindow  *mainwin,
                                   guint       action,
                                   GtkWidget   *widget );
 
-static void addr_gather_msg_cb  ( MainWindow  *mainwin,
+static void addr_harvest_msg_cb         ( MainWindow  *mainwin,
                                   guint       action,
                                   GtkWidget   *widget );
 
@@ -682,9 +682,11 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
        {N_("/_Tools/Add sender to address boo_k"),
                                                NULL, add_address_cb, 0, NULL},
-       {N_("/_Tools/_Gather addresses"),       NULL, NULL, 0, "<Branch>"},
-       {N_("/_Tools/_Gather addresses/from _Folder..."),       NULL, addr_gather_cb, 0, NULL},
-       {N_("/_Tools/_Gather addresses/from _Messages..."),     NULL, addr_gather_msg_cb, 0, NULL},
+       {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
+       {N_("/_Tools/_Harvest addresses/from _Folder..."),
+                                               NULL, addr_harvest_cb, 0, NULL},
+       {N_("/_Tools/_Harvest addresses/from _Messages..."),
+                                               NULL, addr_harvest_msg_cb, 0, NULL},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/_Filter messages"),                NULL, filter_cb, 0, NULL},
        {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
@@ -1608,7 +1610,7 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
 
                {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
                {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
-               {"/Tools/Gather addresses"          , M_TARGET_EXIST|M_UNLOCKED},
+               {"/Tools/Harvest addresses"         , M_UNLOCKED},
                {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
                {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
                {"/Tools/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
@@ -3111,23 +3113,23 @@ static void set_toolbar_style(MainWindow *mainwin)
 }
 
 /*
- * Gather addresses for selected folder.
+ * Harvest addresses for selected folder.
  */
-static void addr_gather_cb( MainWindow *mainwin,
+static void addr_harvest_cb( MainWindow *mainwin,
                            guint action,
                            GtkWidget *widget )
 {
-       addressbook_gather( mainwin->summaryview->folder_item, NULL );
+       addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
 }
 
 /*
- * Gather addresses for selected messages in summary view.
+ * Harvest addresses for selected messages in summary view.
  */
-static void addr_gather_msg_cb( MainWindow *mainwin,
+static void addr_harvest_msg_cb( MainWindow *mainwin,
                            guint action,
                            GtkWidget *widget )
 {
-       summary_gather_address( mainwin->summaryview );
+       summary_harvest_address( mainwin->summaryview );
 }
 
 /*
index 5e8410a..a57656a 100644 (file)
@@ -5293,9 +5293,9 @@ void summary_reflect_prefs_pixmap_theme(SummaryView *summaryview)
 }
 
 /*
- * Gather addresses for selected messages in summary view.
+ * Harvest addresses for selected messages in summary view.
  */
-void summary_gather_address( SummaryView *summaryview ) {
+void summary_harvest_address( SummaryView *summaryview ) {
        GtkCTree *ctree = GTK_CTREE( summaryview->ctree );
        GList *cur;
        GList *msgList;
@@ -5306,7 +5306,7 @@ void summary_gather_address( SummaryView *summaryview ) {
                msginfo = gtk_ctree_node_get_row_data( ctree, GTK_CTREE_NODE(cur->data) );
                msgList = g_list_append( msgList, GUINT_TO_POINTER( msginfo->msgnum ) );
        }
-       addressbook_gather( summaryview->folder_item, msgList );
+       addressbook_harvest( summaryview->folder_item, TRUE, msgList );
        g_list_free( msgList );
 }
 
index 79214dd..47c710e 100644 (file)
@@ -263,6 +263,6 @@ void summary_toggle_view_real       (SummaryView    *summaryview);
 
 void summary_reflect_prefs_pixmap_theme(SummaryView *summaryview);
 
-void summary_gather_address    ( SummaryView *summaryview );
+void summary_harvest_address   ( SummaryView *summaryview );
 
 #endif /* __SUMMARY_H__ */