add and adapt Thomas Link's subject simplification patch
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 23 Dec 2001 14:30:06 +0000 (14:30 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 23 Dec 2001 14:30:06 +0000 (14:30 +0000)
ChangeLog.claws
configure.in
src/Makefile.am
src/folder.c
src/folder.h
src/folderview.c
src/prefs_folder_item.c
src/prefs_folder_item.h
src/string_match.c [new file with mode: 0644]
src/string_match.h [new file with mode: 0644]
src/summaryview.c

index e3228af..a1ea508 100644 (file)
@@ -1,3 +1,17 @@
+2001-12-23 [alfons]    0.6.6claws12
+
+       * src/Makefile.am
+       * src/summaryview.c
+       * src/string_match.[ch]         ** NEW **
+       * src/folderview.[ch]
+       * src/headerview.h
+       * src/folder.[ch]
+       * src/prefs_folder_item.[ch]
+               add subject simplification to strip out strings from
+               a subject line (esp. handy for mailing lists). 
+               (original patch by by Thomas Link <t.link.tmp200101@gmx.net>,
+               but slightly changed things for better integration.)
+
 2001-12-23 [alfons]    0.6.6claws11
 
        * src/mainwindow.c
index 36fb11b..f4a26f6 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws11
+EXTRA_VERSION=claws12
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index e7548f3..dcfea69 100644 (file)
@@ -124,7 +124,8 @@ sylpheed_SOURCES = \
        quote_fmt_parse.y quote_fmt.h \
        gtkspell.c gtkspell.h gtkxtext.h \
        matcher_parser_lex.l matcher_parser_lex.h \
-       matcher_parser_parse.y matcher_parser.h
+       matcher_parser_parse.y matcher_parser.h \
+       string_match.h string_match.c
 
 BUILT_SOURCES = \
        quote_fmt_lex.c \
index 93edfc1..ab44655 100644 (file)
@@ -42,6 +42,7 @@
 #include "account.h"
 #include "prefs_account.h"
 #include "mbox_folder.h"
+#include "prefs_folder_item.h"
 
 #include <sys/stat.h>
 #include <sys/types.h>
index adfe9e6..fd611ce 100644 (file)
@@ -33,10 +33,11 @@ typedef struct _IMAPFolder  IMAPFolder;
 typedef struct _NewsFolder     NewsFolder;
 typedef struct _FolderItem     FolderItem;
 
+#include "prefs_folder_item.h"
+
 #include "prefs_account.h"
 #include "session.h"
 #include "procmsg.h"
-#include "prefs_folder_item.h"
 
 #define FOLDER(obj)            ((Folder *)obj)
 #define FOLDER_TYPE(obj)       (FOLDER(obj)->type)
index 0fb1cce..b8fd33a 100644 (file)
@@ -2352,7 +2352,9 @@ static void folderview_processing_cb(FolderView *folderview, guint action,
        prefs_filtering_open(item);
 }
 
-static void folderview_property_cb(FolderView *folderview, guint action, GtkWidget *widget) {
+static void folderview_property_cb(FolderView *folderview, guint action, 
+                                  GtkWidget *widget) 
+{
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
 
@@ -2362,10 +2364,11 @@ static void folderview_property_cb(FolderView *folderview, guint action, GtkWidg
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       prefs_folder_item_create(item);
+       prefs_folder_item_create(folderview, item);
 }
 
-void folderview_set_target_folder_color(gint color_op) {
+void folderview_set_target_folder_color(gint color_op) 
+{
        gint firstone = 1;
        GList *list;
        FolderView *folderview;
index 4fd86bf..05a038f 100644 (file)
 #include "defs.h"
 #include "folder.h"
 #include "prefs_folder_item.h"
+#include "folderview.h"
 #include "summaryview.h"
 #include "menu.h"
 #include "account.h"
 #include "prefs.h"
 #include "manage_window.h"
+#include "utils.h"
 
 PrefsFolderItem tmp_prefs;
 
 struct PrefsFolderItemDialog
 {
+       FolderView *folderview;
        FolderItem *item;
        GtkWidget *window;
        GtkWidget *checkbtn_request_return_receipt;
        GtkWidget *checkbtn_save_copy_to_folder;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_simplify_subject;
+       GtkWidget *entry_simplify_subject;
        GtkWidget *checkbtn_folder_chmod;
        GtkWidget *entry_folder_chmod;
        GtkWidget *checkbtn_enable_default_account;
@@ -75,6 +80,10 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"default_to", "", &tmp_prefs.default_to, P_STRING,
         NULL, NULL, NULL},
+       {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
+        NULL, NULL, NULL},
+       {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
+        NULL, NULL, NULL},
        {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
         NULL, NULL, NULL},
        {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
@@ -88,13 +97,22 @@ static PrefParam param[] = {
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
-void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, struct PrefsFolderItemDialog *dialog);
-void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
-void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
-void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
-void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
-void prefs_folder_item_default_account_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
-gint prefs_folder_item_chmod_mode(gchar *folder_chmod);
+void prefs_folder_item_delete_cb               (GtkWidget *widget, GdkEventAny *event, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_cancel_cb               (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_ok_cb                   (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_default_to_cb           (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_simplify_subject_cb     (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_folder_chmod_cb         (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_default_account_cb      (GtkWidget *widget, 
+                                                struct PrefsFolderItemDialog *dialog);
+gint prefs_folder_item_chmod_mode              (gchar *folder_chmod);
+
 
 void prefs_folder_item_read_config(FolderItem * item)
 {
@@ -182,6 +200,8 @@ PrefsFolderItem * prefs_folder_item_new(void)
        tmp_prefs.request_return_receipt = FALSE;
        tmp_prefs.enable_default_to = FALSE;
        tmp_prefs.default_to = NULL;
+       tmp_prefs.enable_simplify_subject = FALSE;
+       tmp_prefs.simplify_subject_regexp = NULL;
        tmp_prefs.enable_folder_chmod = FALSE;
        tmp_prefs.folder_chmod = 0;
        tmp_prefs.enable_default_account = FALSE;
@@ -234,7 +254,8 @@ gint prefs_folder_item_get_sort_type(FolderItem * item)
 #define SAFE_STRING(str) \
        (str) ? (str) : ""
 
-void prefs_folder_item_create(FolderItem *item) {
+void prefs_folder_item_create(void *folderview, FolderItem *item) 
+{
        struct PrefsFolderItemDialog *dialog;
        guint rowcount;
        gchar *folder_identifier, *infotext;
@@ -250,6 +271,8 @@ void prefs_folder_item_create(FolderItem *item) {
        GtkWidget *checkbtn_save_copy_to_folder;
        GtkWidget *checkbtn_default_to;
        GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_simplify_subject;
+       GtkWidget *entry_simplify_subject;
        GtkWidget *checkbtn_folder_chmod;
        GtkWidget *entry_folder_chmod;
        GtkWidget *checkbtn_enable_default_account;
@@ -265,7 +288,8 @@ void prefs_folder_item_create(FolderItem *item) {
        gint account_index, index;
 
        dialog = g_new0(struct PrefsFolderItemDialog, 1);
-       dialog->item = item;
+       dialog->folderview = folderview;
+       dialog->item       = item;
 
        /* Window */
        window = gtk_window_new (GTK_WINDOW_DIALOG);
@@ -292,23 +316,29 @@ void prefs_folder_item_create(FolderItem *item) {
        folder_identifier = folder_item_get_identifier(item);
        infotext = g_strconcat(_("Folder Property for "), folder_identifier, NULL);
        infolabel = gtk_label_new(infotext);
-       gtk_table_attach(GTK_TABLE(table), infolabel, 0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), infolabel, 0, 2, rowcount, 
+                        rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
        gtk_widget_show(infolabel);
        rowcount++;
 
        /* Request Return Receipt */
-       checkbtn_request_return_receipt = gtk_check_button_new_with_label(_("Request Return Receipt"));
+       checkbtn_request_return_receipt = gtk_check_button_new_with_label
+               (_("Request Return Receipt"));
        gtk_widget_show(checkbtn_request_return_receipt);
-       gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_request_return_receipt, 
+                        0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, 
+                        GTK_SHRINK, 0, 0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
                                     item->ret_rcpt ? TRUE : FALSE);
 
        rowcount++;
 
        /* Save Copy to Folder */
-       checkbtn_save_copy_to_folder = gtk_check_button_new_with_label(_("Save copy of outgoing messages to this folder instead of outbox"));
+       checkbtn_save_copy_to_folder = gtk_check_button_new_with_label
+               (_("Save copy of outgoing messages to this folder instead of outbox"));
        gtk_widget_show(checkbtn_save_copy_to_folder);
-       gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_save_copy_to_folder, 0, 2, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_save_copy_to_folder),
                                     item->prefs->save_copy_to_folder ? TRUE : FALSE);
 
@@ -317,8 +347,10 @@ void prefs_folder_item_create(FolderItem *item) {
        /* Default To */
        checkbtn_default_to = gtk_check_button_new_with_label(_("Default To: "));
        gtk_widget_show(checkbtn_default_to);
-       gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), item->prefs->enable_default_to);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_default_to, 0, 1, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), 
+                                    item->prefs->enable_default_to);
        gtk_signal_connect(GTK_OBJECT(checkbtn_default_to), "toggled",
                            GTK_SIGNAL_FUNC(prefs_folder_item_default_to_cb), dialog);
 
@@ -331,19 +363,44 @@ void prefs_folder_item_create(FolderItem *item) {
 
        rowcount++;
 
+       /* Simplify Subject */
+       checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
+       gtk_widget_show(checkbtn_simplify_subject);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject), 
+                                    item->prefs->enable_simplify_subject);
+       gtk_signal_connect(GTK_OBJECT(checkbtn_simplify_subject), "toggled",
+                          GTK_SIGNAL_FUNC(prefs_folder_item_simplify_subject_cb), dialog);
+
+       entry_simplify_subject = gtk_entry_new();
+       gtk_widget_show(entry_simplify_subject);
+       gtk_table_attach_defaults(GTK_TABLE(table), entry_simplify_subject, 1, 2, 
+                                 rowcount, rowcount + 1);
+       gtk_editable_set_editable(GTK_EDITABLE(entry_simplify_subject), 
+                                 item->prefs->enable_simplify_subject);
+       gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject), 
+                          SAFE_STRING(item->prefs->simplify_subject_regexp));
+
+       rowcount++;
+
        /* Folder chmod */
        checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
        gtk_widget_show(checkbtn_folder_chmod);
-       gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
 
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), item->prefs->enable_folder_chmod);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), 
+                                    item->prefs->enable_folder_chmod);
        gtk_signal_connect(GTK_OBJECT(checkbtn_folder_chmod), "toggled",
                            GTK_SIGNAL_FUNC(prefs_folder_item_folder_chmod_cb), dialog);
 
        entry_folder_chmod = gtk_entry_new();
        gtk_widget_show(entry_folder_chmod);
-       gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, rowcount, rowcount + 1);
-       gtk_editable_set_editable(GTK_EDITABLE(entry_folder_chmod), item->prefs->enable_folder_chmod);
+       gtk_table_attach_defaults(GTK_TABLE(table), entry_folder_chmod, 1, 2, 
+                                 rowcount, rowcount + 1);
+       gtk_editable_set_editable(GTK_EDITABLE(entry_folder_chmod), 
+                                 item->prefs->enable_folder_chmod);
        if (item->prefs->folder_chmod) {
                gchar *buf;
 
@@ -357,14 +414,17 @@ void prefs_folder_item_create(FolderItem *item) {
        /* Default account */
        checkbtn_enable_default_account = gtk_check_button_new_with_label(_("Default account: "));
        gtk_widget_show(checkbtn_enable_default_account);
-       gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), item->prefs->enable_default_account);
+       gtk_table_attach(GTK_TABLE(table), checkbtn_enable_default_account, 0, 1, 
+                        rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_account), 
+                                    item->prefs->enable_default_account);
        gtk_signal_connect(GTK_OBJECT(checkbtn_enable_default_account), "toggled",
                            GTK_SIGNAL_FUNC(prefs_folder_item_default_account_cb), dialog);
 
        optmenu_default_account = gtk_option_menu_new ();
        gtk_widget_show (optmenu_default_account);
-       gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, rowcount, rowcount + 1);
+       gtk_table_attach_defaults(GTK_TABLE(table), optmenu_default_account, 1, 2, 
+                                 rowcount, rowcount + 1);
        optmenu_default_account_menu = gtk_menu_new ();
 
        account_list = account_get_list();
@@ -381,7 +441,7 @@ void prefs_folder_item_create(FolderItem *item) {
                index++;                        
        }
 
-       dialog->item->prefs->default_account=item->prefs->default_account;
+       dialog->item->prefs->default_account = item->prefs->default_account;
 
        optmenu=GTK_OPTION_MENU(optmenu_default_account);
        gtk_option_menu_set_menu(optmenu, optmenu_default_account_menu);
@@ -400,7 +460,8 @@ void prefs_folder_item_create(FolderItem *item) {
        gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
                                &cancel_btn, _("Cancel"), NULL, NULL);
        gtk_widget_show(confirm_area);
-       gtk_table_attach_defaults(GTK_TABLE(table), confirm_area, 0, 2, rowcount, rowcount + 1);
+       gtk_table_attach_defaults(GTK_TABLE(table), confirm_area, 0, 2, 
+                                 rowcount, rowcount + 1);
        gtk_widget_grab_default(ok_btn);
        gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
                            GTK_SIGNAL_FUNC(prefs_folder_item_ok_cb), dialog);
@@ -412,6 +473,8 @@ void prefs_folder_item_create(FolderItem *item) {
        dialog->checkbtn_save_copy_to_folder = checkbtn_save_copy_to_folder;
        dialog->checkbtn_default_to = checkbtn_default_to;
        dialog->entry_default_to = entry_default_to;
+       dialog->checkbtn_simplify_subject = checkbtn_simplify_subject;
+       dialog->entry_simplify_subject = entry_simplify_subject;
        dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
        dialog->entry_folder_chmod = entry_folder_chmod;
        dialog->checkbtn_enable_default_account = checkbtn_enable_default_account;
@@ -422,24 +485,38 @@ void prefs_folder_item_create(FolderItem *item) {
        gtk_widget_show(window);
 }
 
-void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) {
+void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) 
+{
        gtk_widget_destroy(dialog->window);
        g_free(dialog);
 }
 
-void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+void prefs_folder_item_cancel_cb(GtkWidget *widget, 
+                                struct PrefsFolderItemDialog *dialog) 
+{
        prefs_folder_item_destroy(dialog);
 }
 
-void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, struct PrefsFolderItemDialog *dialog) {
+void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, 
+                                struct PrefsFolderItemDialog *dialog) 
+{
        prefs_folder_item_destroy(dialog);
 }
 
-void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+void prefs_folder_item_ok_cb(GtkWidget *widget, 
+                            struct PrefsFolderItemDialog *dialog) 
+{
        gchar *buf;
        PrefsFolderItem *prefs = dialog->item->prefs;
        GtkWidget *menu;
        GtkWidget *menuitem;
+       gboolean   old_simplify_val;
+       gchar     *old_simplify_str;
+
+       g_return_if_fail(prefs != NULL);
+
+       old_simplify_val = prefs->enable_simplify_subject;
+       old_simplify_str = prefs->simplify_subject_regexp;
 
        prefs->request_return_receipt = 
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_request_return_receipt));
@@ -454,6 +531,18 @@ void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *di
        g_free(prefs->default_to);
        prefs->default_to = 
            gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
+
+       prefs->enable_simplify_subject =
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject));
+       prefs->simplify_subject_regexp = 
+           gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_simplify_subject), 0, -1);
+
+       if (prefs->enable_simplify_subject != old_simplify_val ||  
+           0 != strcmp2(prefs->simplify_subject_regexp, old_simplify_str)) 
+               summary_show(dialog->folderview->summaryview, dialog->item, TRUE);
+               
+       if (old_simplify_str) g_free(old_simplify_str);
+
        prefs->enable_folder_chmod = 
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
        buf = gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod), 0, -1);
@@ -466,21 +555,30 @@ void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *di
        menuitem = gtk_menu_get_active(GTK_MENU(menu));
        prefs->default_account = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(menuitem)));
 
+
        prefs_folder_item_save_config(dialog->item);
        prefs_folder_item_destroy(dialog);
 }
 
-void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
+{
        gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_default_to),
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to)));
 }
 
+void prefs_folder_item_simplify_subject_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
+{
+       gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_simplify_subject),
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_simplify_subject)));
+}
+
 void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
        gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_folder_chmod),
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod)));
 }
 
-gint prefs_folder_item_chmod_mode(gchar *folder_chmod) {
+gint prefs_folder_item_chmod_mode(gchar *folder_chmod) 
+{
        gint newmode = 0;
        gchar *tmp;
 
@@ -492,7 +590,9 @@ gint prefs_folder_item_chmod_mode(gchar *folder_chmod) {
 
        return newmode;
 }
-void prefs_folder_item_default_account_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+
+void prefs_folder_item_default_account_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) 
+{
        gtk_widget_set_sensitive(dialog->optmenu_default_account,
            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_enable_default_account)));
 }
index 31fa3ff..0892293 100644 (file)
@@ -47,6 +47,8 @@ struct _PrefsFolderItem {
        gboolean request_return_receipt;
        gboolean enable_default_to;
        gchar *default_to;
+       gboolean enable_simplify_subject;
+       gchar *simplify_subject_regexp;
        gboolean enable_folder_chmod;
        gint folder_chmod;
        gboolean enable_default_account;
@@ -56,6 +58,10 @@ struct _PrefsFolderItem {
 
 typedef struct _PrefsFolderItem PrefsFolderItem;
 
+/* CLAWS: due a messed up circular header references using 
+ * void *. but this is *REALLY* a folderview */ 
+void prefs_folder_item_create (void *folderview, FolderItem *item); 
+
 void prefs_folder_item_read_config(FolderItem * item);
 void prefs_folder_item_save_config(FolderItem * item);
 void prefs_folder_item_set_config(FolderItem * item,
diff --git a/src/string_match.c b/src/string_match.c
new file mode 100644 (file)
index 0000000..2e4ca3c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Sylpheed -- regexp pattern matching utilities
+ * Copyright (C) 2001 Thomas Link, Hiroyuki Yamamoto
+ *
+ * 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 "string_match.h"
+
+
+int string_match_regexp(char * txt, char * rexp,
+                       int size, regmatch_t matches[],
+                       int cflags, int eflags)
+{
+       regex_t re;
+       int problem;
+
+       problem = regcomp(&re, rexp, cflags);  
+       if (problem == 0) {
+               problem = regexec(&re, txt, size, matches, eflags);
+       }
+       regfree(&re);
+       return problem == 0;
+}
+
+int string_remove_match(char * txt, char * rexp, int cflags, int eflags)
+{
+       regmatch_t matches[STRING_MATCH_MR_SIZE];
+       int foundp;
+
+       if (strlen(txt) > 0 && strlen(rexp) > 0) {
+               foundp = string_match_regexp(txt, rexp, STRING_MATCH_MR_SIZE, 
+                                            matches, cflags, eflags);
+       } else {
+               return -1;
+       }
+
+       if (foundp && matches[0].rm_so != -1 && matches[0].rm_eo != -1) {
+               if (matches[0].rm_so == matches[0].rm_eo) {
+                       /* in case the match is an empty string */
+                       return matches[0].rm_so + 1;
+               } else {
+                       strcpy(txt + matches[0].rm_so, txt + matches[0].rm_eo);
+                       return matches[0].rm_so;
+               }
+       } else {
+               return -1;
+       }
+}
+
+int string_remove_all_matches(char * txt, char * rexp, int cflags, int eflags)
+{
+       int pos = 0;
+       int pos0 = pos;
+
+       while (pos0 >= 0 && pos < strlen(txt) && strlen(txt) > 0) {
+               /* printf("%s %d:%d\n", txt, pos0, pos); */
+               pos0 = string_remove_match(txt + pos, rexp, cflags, eflags);
+               if (pos0 >= 0) {
+                       pos = pos + pos0;
+               }
+       }
+       return pos;
+}
diff --git a/src/string_match.h b/src/string_match.h
new file mode 100644 (file)
index 0000000..a338894
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sylpheed -- regexp pattern matching utilities
+ * Copyright (C) 2001 Thomas Link, Hiroyuki Yamamoto
+ *
+ * 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 __STRING_MATCH_H__
+#define __STRING_MATCH_H__
+
+#include <stdio.h>
+#include <regex.h>
+
+
+/* the size used for regexec in string_remove_match */
+/* this is probably not the most clever way to define this here, though */
+#define STRING_MATCH_MR_SIZE 30
+
+
+/* match a REXP in TXT, return non-zero if found */
+/* for documentation of SIZE, MATCHES, CFLAGS, and EFLAGS see "man regex" */
+/* MATCHES will be updated by regexec */
+int string_match_regexp(char * txt, char * rexp, \
+                       int size, regmatch_t matches[], \
+                       int cflags, int eflags);
+
+/* remove substring matching REXP from TXT. Destructive! */
+/* for documentation of CFLAGS and EFLAGS see "man regex" */
+/* returns -1 = not found; N = next find pos */
+/* if the match is an empty string (e.g. "x\?"), the find position will
+   be increased by 1 */
+int string_remove_match(char * txt, char * rexp, int cflags, int eflags);
+
+/* remove all substrings matching REXP from TXT. Destructive! */
+/* for documentation of CFLAGS and EFLAGS see "man regex" */
+/* returns position of last replacement (i.e. TXT has been modified up
+   to this position, use this as the starting point for further mangling) */
+int string_remove_all_matches(char * txt, char * rexp, int cflags, int eflags);
+
+
+#endif
index bdb37e6..f40a31e 100644 (file)
@@ -81,6 +81,7 @@
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "filtering.h"
+#include "string_match.h"
 
 #define STATUSBAR_PUSH(mainwin, str) \
 { \
@@ -241,6 +242,9 @@ static void summary_unthread_for_exec_func  (GtkCTree       *ctree,
                                                 GtkCTreeNode   *node,
                                                 gpointer        data);
 
+void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
+                             GSList * mlist);
+
 void summary_processing(SummaryView *summaryview, GSList * mlist);
 static void summary_filter_func                (GtkCTree               *ctree,
                                         GtkCTreeNode           *node,
@@ -803,6 +807,14 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                mlist = not_killed;
        }
 
+       if (item->prefs->enable_simplify_subject
+           && item->prefs->simplify_subject_regexp != NULL
+           && strlen(item->prefs->simplify_subject_regexp) != 0) {
+               summary_simplify_subject(summaryview, 
+                                        item->prefs->simplify_subject_regexp,
+                                        mlist);
+       }
+
        STATUSBAR_POP(summaryview->mainwin);
 
        /* set ctree and hash table from the msginfo list
@@ -3600,6 +3612,16 @@ static void summary_unthread_for_exec_func(GtkCTree *ctree, GtkCTreeNode *node,
        }
 }
 
+void summary_simplify_subject(SummaryView *summaryview, gchar * rexp,
+                             GSList * mlist)
+{
+       GSList * cur;
+       for(cur = mlist ; cur != NULL ; cur = cur->next) {
+               MsgInfo * msginfo = (MsgInfo *) cur->data;
+               string_remove_all_matches(msginfo->subject, rexp, 0, 0);
+       }
+}
+
 void summary_processing(SummaryView *summaryview, GSList * mlist)
 {
        GSList * processing_list;