[Commits] [SCM] claws branch, master, updated. 3.9.0-164-gaa8ccdb

mones at claws-mail.org mones at claws-mail.org
Sun Mar 31 03:40:37 CEST 2013


The branch master of project "claws" (Claws Mail) has been updated
       via  aa8ccdb0f6e887a4cb68150883eb7d6faf0cc1f5 (commit)
       via  a79ce24f9f5079e2cdd470e4b124321647ba6da6 (commit)
       via  fe709cce38ba0f99759752102c1012f2fc0f265f (commit)
      from  a839f1b6111f9a5b9af50fee05095607853530b2 (commit)


- Log -----------------------------------------------------------------
commit aa8ccdb0f6e887a4cb68150883eb7d6faf0cc1f5
Author: Ricardo Mones <ricardo at mones.org>
Date:   Wed Mar 27 18:36:23 2013 +0100

    Add block address matching pattern feature
    
    Should fix bug #2340 'Create block list'.

diff --git a/src/plugins/address_keeper/address_keeper.c b/src/plugins/address_keeper/address_keeper.c
index 085f8b6..be4f053 100644
--- a/src/plugins/address_keeper/address_keeper.c
+++ b/src/plugins/address_keeper/address_keeper.c
@@ -88,18 +88,42 @@ gchar *get_comment_from_addr(const gchar *addr)
 }
 
 /**
+ * Checks an address for matching a blocked address pattern.
+ *
+ * @param addr The full address.
+ * @param blocked The regexp matching blocked addresses.
+ *
+ * @return TRUE if given address matches any of the patterns, FALSE otherwise.
+ */
+gboolean matches_blocked_address(const gchar *addr, MatcherList *blocked)
+{
+	if (blocked != NULL) {
+		MsgInfo info;
+
+		info.subject = addr;
+		return matcherlist_match(blocked, &info);
+	}
+	return FALSE;
+}
+
+/**
  * Saves an address to the configured addressbook folder if not known.
  *
  * @param abf The address book file containing target folder.
  * @param folder The address book folder where addresses are added.
  * @param addr The address to be added.
+ * @param blocked The regexp matching blocked addresses.
  */
-void keep_if_unknown(AddressBookFile * abf, ItemFolder * folder, gchar *addr)
+void keep_if_unknown(AddressBookFile * abf, ItemFolder * folder, gchar *addr, MatcherList *blocked)
 {
 	gchar *clean_addr = NULL;
 	gchar *keepto = addkeeperprefs.addressbook_folder;
 
 	debug_print("checking addr '%s'\n", addr);
+	if (matches_blocked_address(addr, blocked)) {
+		debug_print("addr '%s' is blocked by regexp\n", addr);
+		return;
+	}
 	clean_addr = g_strdup(addr);
 	extract_address(clean_addr);
 	start_address_completion(NULL);
@@ -146,6 +170,7 @@ static gboolean addrk_before_send_hook(gpointer source, gpointer data)
 	const gchar *to_hdr;
 	const gchar *cc_hdr;
 	const gchar *bcc_hdr;
+	MatcherList *blocked = NULL;
 
 	debug_print("address_keeper invoked!\n");
 	if (compose->batch)
@@ -170,6 +195,12 @@ static gboolean addrk_before_send_hook(gpointer source, gpointer data)
 	cc_hdr = prefs_common_translated_header_name("Cc:");
 	bcc_hdr = prefs_common_translated_header_name("Bcc:");
 
+	if (addkeeperprefs.block_matching_addrs != NULL
+			&& addkeeperprefs.block_matching_addrs[0] != '\0') {
+		blocked = matcherlist_new_from_lines(addkeeperprefs.block_matching_addrs, FALSE);
+		if (blocked == NULL)
+			g_warning("couldn't allocate matcher");
+	}
 	for (cur = compose->header_list; cur != NULL; cur = cur->next) {
 		gchar *header;
 		gchar *entry;
@@ -183,20 +214,22 @@ static gboolean addrk_before_send_hook(gpointer source, gpointer data)
 		if (*entry != '\0') {
 			if (!g_ascii_strcasecmp(header, to_hdr)
 				&& addkeeperprefs.keep_to_addrs == TRUE) {
-				keep_if_unknown(abf, folder, entry);
+				keep_if_unknown(abf, folder, entry, blocked);
 			}
 			if (!g_ascii_strcasecmp(header, cc_hdr)
 				&& addkeeperprefs.keep_cc_addrs == TRUE) {
-				keep_if_unknown(abf, folder, entry);
+				keep_if_unknown(abf, folder, entry, blocked);
 			}
 			if (!g_ascii_strcasecmp(header, bcc_hdr)
 				&& addkeeperprefs.keep_bcc_addrs == TRUE) {
-				keep_if_unknown(abf, folder, entry);
+				keep_if_unknown(abf, folder, entry, blocked);
 			}
 		}
 		g_free(header);
 		g_free(entry);
-	}	
+	}
+	if (blocked != NULL)	
+		matcherlist_free(blocked);
 
 	return FALSE;	/* continue sending */
 }
diff --git a/src/plugins/address_keeper/address_keeper_prefs.c b/src/plugins/address_keeper/address_keeper_prefs.c
index 3e322d0..3ecf7f5 100644
--- a/src/plugins/address_keeper/address_keeper_prefs.c
+++ b/src/plugins/address_keeper/address_keeper_prefs.c
@@ -47,6 +47,7 @@ struct AddressKeeperPrefsPage
 	GtkWidget *keep_to_addrs_check;
 	GtkWidget *keep_cc_addrs_check;
 	GtkWidget *keep_bcc_addrs_check;
+	GtkWidget *block_matching_addrs;
 };
 
 struct AddressKeeperPrefsPage addkeeperprefs_page;
@@ -60,6 +61,8 @@ static PrefParam param[] = {
          P_BOOL, NULL, NULL, NULL},
 	{"keep_bcc_addrs", "FALSE", &addkeeperprefs.keep_bcc_addrs,
          P_BOOL, NULL, NULL, NULL},
+	{"block_matching_addrs", "", &addkeeperprefs.block_matching_addrs,
+	 P_STRING, NULL, NULL, NULL},
 	{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -88,8 +91,12 @@ static void addkeeper_prefs_create_widget_func(PrefsPage * _page,
 	GtkWidget *keep_to_checkbox;
 	GtkWidget *keep_cc_checkbox;
 	GtkWidget *keep_bcc_checkbox;
+	GtkWidget *blocked_frame;
+	GtkWidget *blocked_vbox;
+	GtkWidget *blocked_scrolledwin;
 	GtkWidget *hbox;
 	GtkWidget *vbox;
+	GtkTextBuffer *buffer;
 
 	vbox = gtk_vbox_new(FALSE, 6);
 	hbox = gtk_hbox_new(FALSE, 6);
@@ -149,6 +156,24 @@ static void addkeeper_prefs_create_widget_func(PrefsPage * _page,
 	gtk_widget_show(keep_bcc_checkbox);
 
 	page->keep_bcc_addrs_check = keep_bcc_checkbox;
+
+	blocked_vbox = gtkut_get_options_frame(vbox, &blocked_frame, _("Exclude addresses matching the following regular expressions (one per line):"));
+	gtk_container_set_border_width(GTK_CONTAINER(blocked_frame), 6);
+
+	page->block_matching_addrs = gtk_text_view_new();
+	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->block_matching_addrs));
+	gtk_text_buffer_set_text(buffer, addkeeperprefs.block_matching_addrs, -1);
+	
+	blocked_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_policy
+		(GTK_SCROLLED_WINDOW (blocked_scrolledwin),
+		 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type
+		(GTK_SCROLLED_WINDOW (blocked_scrolledwin), GTK_SHADOW_IN);
+
+	gtk_container_add(GTK_CONTAINER(blocked_scrolledwin), page->block_matching_addrs);
+	gtk_widget_set_size_request(page->block_matching_addrs, -1, 72);
+	gtk_box_pack_start(GTK_BOX(blocked_vbox), blocked_scrolledwin, FALSE, FALSE, 0);
 	
 	gtk_widget_show_all(vbox);
 
@@ -189,6 +214,9 @@ static void addkeeper_prefs_save_func(PrefsPage * _page)
 {
 	struct AddressKeeperPrefsPage *page = (struct AddressKeeperPrefsPage *) _page;
 	const gchar *text;
+	GtkTextBuffer *buffer;
+	GtkTextIter start, end;
+
 	text = gtk_entry_get_text(GTK_ENTRY(page->addressbook_folder));
 	addkeeperprefs.addressbook_folder = g_strdup(text);
 	addkeeperprefs.keep_to_addrs = gtk_toggle_button_get_active(
@@ -197,13 +225,25 @@ static void addkeeper_prefs_save_func(PrefsPage * _page)
 		GTK_TOGGLE_BUTTON(page->keep_cc_addrs_check));
 	addkeeperprefs.keep_bcc_addrs = gtk_toggle_button_get_active(
 		GTK_TOGGLE_BUTTON(page->keep_bcc_addrs_check));
+
+	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->block_matching_addrs));
+	gtk_text_buffer_get_start_iter(buffer, &start);
+	gtk_text_buffer_get_end_iter(buffer, &end);
+	text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+	g_free(addkeeperprefs.block_matching_addrs);
+	addkeeperprefs.block_matching_addrs = g_malloc(2 * strlen(text) + 1);
+	pref_get_escaped_pref(addkeeperprefs.block_matching_addrs, text);
+
 	addkeeper_save_config();
+	g_free(addkeeperprefs.block_matching_addrs);
+	addkeeperprefs.block_matching_addrs = text;
 }
 
 void address_keeper_prefs_init(void)
 {
 	static gchar *path[3];
 	gchar *rcpath;
+	gchar *tmp;
 	
 	path[0] = _("Plugins");
 	path[1] = _("Address Keeper");
@@ -214,6 +254,11 @@ void address_keeper_prefs_init(void)
 	prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
 	g_free(rcpath);
 
+	tmp = g_malloc(strlen(addkeeperprefs.block_matching_addrs) + 1);
+	pref_get_unescaped_pref(tmp, addkeeperprefs.block_matching_addrs);
+	g_free(addkeeperprefs.block_matching_addrs);
+	addkeeperprefs.block_matching_addrs = tmp;
+
 	addkeeperprefs_page.page.path = path;
 	addkeeperprefs_page.page.create_widget = addkeeper_prefs_create_widget_func;
 	addkeeperprefs_page.page.destroy_widget = addkeeper_prefs_destroy_widget_func;
diff --git a/src/plugins/address_keeper/address_keeper_prefs.h b/src/plugins/address_keeper/address_keeper_prefs.h
index 30541c0..9f1ea8c 100644
--- a/src/plugins/address_keeper/address_keeper_prefs.h
+++ b/src/plugins/address_keeper/address_keeper_prefs.h
@@ -27,10 +27,11 @@ typedef struct _AddressKeeperPrefs AddressKeeperPrefs;
 
 struct _AddressKeeperPrefs
 {
-	gchar		 *addressbook_folder;
+	gchar		*addressbook_folder;
 	gboolean	keep_to_addrs;
 	gboolean	keep_cc_addrs;
 	gboolean	keep_bcc_addrs;
+	gchar		*block_matching_addrs;
 };
 
 extern AddressKeeperPrefs addkeeperprefs;

commit a79ce24f9f5079e2cdd470e4b124321647ba6da6
Author: Ricardo Mones <ricardo at mones.org>
Date:   Wed Mar 27 10:23:50 2013 +0100

    Use new generalized function for matcher list

diff --git a/src/plugins/attachwarner/attachwarner.c b/src/plugins/attachwarner/attachwarner.c
index 91f7a46..e4d19a9 100644
--- a/src/plugins/attachwarner/attachwarner.c
+++ b/src/plugins/attachwarner/attachwarner.c
@@ -1,7 +1,7 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail Team
- * Copyright (C) 2006-2012 Ricardo Mones
+ * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2006-2013 Ricardo Mones
  *
  * 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
@@ -35,99 +35,6 @@
 /** Identifier for the hook. */
 static guint hook_id;
 
-#ifdef G_OS_UNIX
-/**
- * Builds a single regular expresion from an array of srings.
- *
- * @param strings The lines containing the different sub-regexp.
- *
- * @return The newly allocated regexp.
- */
-static gchar *build_complete_regexp(gchar **strings)
-{
-	int i = 0;
-	gchar *expr = NULL;
-	while (strings && strings[i] && *strings[i]) {
-		int old_len = expr ? strlen(expr):0;
-		int new_len = 0;
-		gchar *tmpstr = NULL;
-
-		if (g_utf8_validate(strings[i], -1, NULL))
-			tmpstr = g_strdup(strings[i]);
-		else
-			tmpstr = conv_codeset_strdup(strings[i], 
-					conv_get_locale_charset_str_no_utf8(),
-				 	CS_INTERNAL);
-
-		if (strstr(tmpstr, "\n"))
-			*(strstr(tmpstr, "\n")) = '\0';
-
-		new_len = strlen(tmpstr);
-
-		expr = g_realloc(expr, 
-			expr ? (old_len + strlen("|()") + new_len + 1)
-			     : (strlen("()") + new_len + 1));
-		
-		if (old_len) {
-			strcpy(expr + old_len, "|(");
-			strcpy(expr + old_len + 2, tmpstr);
-			strcpy(expr + old_len + 2 + new_len, ")");
-		} else {
-			strcpy(expr+old_len, "(");
-			strcpy(expr+old_len + 1, tmpstr);
-			strcpy(expr+old_len + 1 + new_len, ")");
-		}
-		g_free(tmpstr);
-		i++;
-	}
-	return expr;
-}
-#endif
-/**
- * Creates the matcher.
- *
- * @return A newly allocated regexp matcher or null if no memory is available.
- */
-MatcherList * new_matcherlist(void)
-{
-	MatcherProp *m = NULL;
-	GSList *matchers = NULL;
-	gchar **strings = g_strsplit(attwarnerprefs.match_strings, "\n", -1);
-
-#ifdef G_OS_UNIX
-	gchar *expr = NULL;
-	expr = build_complete_regexp(strings);
-	debug_print("building matcherprop for expr '%s'\n", expr?expr:"NULL");
-	
-	m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_REGEXP, 
-			    expr, 0);
-	if (m == NULL) {
-		/* print error message */
-		debug_print("failed to allocate memory for matcherprop\n");
-	} else {
-		matchers = g_slist_append(matchers, m);
-	}
-
-	g_free(expr);
-#else
-	int i = 0;
-	while (strings && strings[i] && *strings[i]) {
-		m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_MATCHCASE, 
-			    strings[i], 0);
-		if (m == NULL) {
-			/* print error message */
-			debug_print("failed to allocate memory for matcherprop\n");
-		} else {
-			matchers = g_slist_append(matchers, m);
-		}
-		i++;
-	}
-#endif
-	g_strfreev(strings);
-
-	return matcherlist_new(matchers, FALSE);
-}
-
 static AttachWarnerMention *aw_matcherlist_string_match(MatcherList *matchers, gchar *str, gchar *sig_separator)
 {
 	MsgInfo info;
@@ -204,7 +111,7 @@ AttachWarnerMention *are_attachments_mentioned(Compose *compose)
 	AttachWarnerMention *mention = NULL;
 	MatcherList *matchers = NULL;
 
-	matchers = new_matcherlist();
+	matchers = matcherlist_new_from_lines(attwarnerprefs.match_strings, FALSE);
 
 	if (matchers == NULL) {
 		g_warning("couldn't allocate matcher");

commit fe709cce38ba0f99759752102c1012f2fc0f265f
Author: Ricardo Mones <ricardo at mones.org>
Date:   Wed Mar 27 10:12:55 2013 +0100

    Generalize matcher list building from lines
    
    New function "matcherlist_new_from_lines" to build the MatcherList
    required to match one or more regexps from a newline-separated string.
    
    Seen previously a specific internal function of AttachWarner plugin.

diff --git a/src/matcher.c b/src/matcher.c
index 19fa12a..c95655c 100644
--- a/src/matcher.c
+++ b/src/matcher.c
@@ -1134,6 +1134,103 @@ MatcherList *matcherlist_new(GSList *matchers, gboolean bool_and)
 	return cond;
 }
 
+#ifdef G_OS_UNIX
+/*!
+ *\brief	Builds a single regular expresion from an array of srings.
+ *
+ *\param	strings The lines containing the different sub-regexp.
+ *
+ *\return	The newly allocated regexp string.
+ */
+static gchar *build_complete_regexp(gchar **strings)
+{
+	int i = 0;
+	gchar *expr = NULL;
+	while (strings && strings[i] && *strings[i]) {
+		int old_len = expr ? strlen(expr):0;
+		int new_len = 0;
+		gchar *tmpstr = NULL;
+
+		if (g_utf8_validate(strings[i], -1, NULL))
+			tmpstr = g_strdup(strings[i]);
+		else
+			tmpstr = conv_codeset_strdup(strings[i], 
+					conv_get_locale_charset_str_no_utf8(),
+				 	CS_INTERNAL);
+
+		if (strstr(tmpstr, "\n"))
+			*(strstr(tmpstr, "\n")) = '\0';
+
+		new_len = strlen(tmpstr);
+
+		expr = g_realloc(expr, 
+			expr ? (old_len + strlen("|()") + new_len + 1)
+			     : (strlen("()") + new_len + 1));
+		
+		if (old_len) {
+			strcpy(expr + old_len, "|(");
+			strcpy(expr + old_len + 2, tmpstr);
+			strcpy(expr + old_len + 2 + new_len, ")");
+		} else {
+			strcpy(expr+old_len, "(");
+			strcpy(expr+old_len + 1, tmpstr);
+			strcpy(expr+old_len + 1 + new_len, ")");
+		}
+		g_free(tmpstr);
+		i++;
+	}
+	return expr;
+}
+#endif
+
+/*!
+ *\brief	Create a new list of matchers from a multi-line string
+ *
+ *\param	lines String with "\n"-separated expressions
+ *\param	bool_and Operator
+ *
+ *\return	MatcherList * New matcher list
+ */
+MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
+{
+	MatcherProp *m = NULL;
+	GSList *matchers = NULL;
+	gchar **strings = g_strsplit(lines, "\n", -1);
+
+#ifdef G_OS_UNIX
+	gchar *expr = NULL;
+	expr = build_complete_regexp(strings);
+	debug_print("building matcherprop for expr '%s'\n", expr?expr:"NULL");
+	
+	m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_REGEXP, 
+			    expr, 0);
+	if (m == NULL) {
+		/* print error message */
+		debug_print("failed to allocate memory for matcherprop\n");
+	} else {
+		matchers = g_slist_append(matchers, m);
+	}
+
+	g_free(expr);
+#else
+	int i = 0;
+	while (strings && strings[i] && *strings[i]) {
+		m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_MATCHCASE, 
+			    strings[i], 0);
+		if (m == NULL) {
+			/* print error message */
+			debug_print("failed to allocate memory for matcherprop\n");
+		} else {
+			matchers = g_slist_append(matchers, m);
+		}
+		i++;
+	}
+#endif
+	g_strfreev(strings);
+
+	return matcherlist_new(matchers, bool_and);
+}
+
 /*!
  *\brief	Frees a list of matchers
  *
diff --git a/src/matcher.h b/src/matcher.h
index 56b0d96..13542a6 100644
--- a/src/matcher.h
+++ b/src/matcher.h
@@ -162,6 +162,8 @@ MatcherProp *matcherprop_copy		(const MatcherProp *src);
 
 MatcherList * matcherlist_new		(GSList		*matchers, 
 					 gboolean	bool_and);
+MatcherList * matcherlist_new_from_lines(gchar		*lines,
+					 gboolean	bool_and);
 void matcherlist_free			(MatcherList	*cond);
 
 MatcherList *matcherlist_parse		(gchar		**str);

-----------------------------------------------------------------------

Summary of changes:
 src/matcher.c                                     |   97 ++++++++++++++++++++
 src/matcher.h                                     |    2 +
 src/plugins/address_keeper/address_keeper.c       |   43 ++++++++-
 src/plugins/address_keeper/address_keeper_prefs.c |   45 +++++++++
 src/plugins/address_keeper/address_keeper_prefs.h |    3 +-
 src/plugins/attachwarner/attachwarner.c           |   99 +--------------------
 6 files changed, 187 insertions(+), 102 deletions(-)


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list