[Commits] attachwarner.c 1.1.2.18 1.1.2.19 attachwarner.h 1.1.2.7 1.1.2.8

mones at claws-mail.org mones at claws-mail.org
Thu Oct 20 00:32:21 CEST 2011


Update of /home/claws-mail/plugins/attachwarner/src
In directory claws-mail:/tmp/cvs-serv6995/src

Modified Files:
      Tag: gtk2
	attachwarner.c attachwarner.h 
Log Message:
2011-10-19 [mones]	0.2.22cvs3

	* src/attachwarner.c
	* src/attachwarner.h
		Implement new small feature: show mail context which
		has triggered the alert of a missing attachment.
		Probably fixes Ubuntu request #190201 

Index: attachwarner.c
===================================================================
RCS file: /home/claws-mail/plugins/attachwarner/src/Attic/attachwarner.c,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -d -r1.1.2.18 -r1.1.2.19
--- attachwarner.c	12 Dec 2010 18:27:59 -0000	1.1.2.18
+++ attachwarner.c	19 Oct 2011 22:32:19 -0000	1.1.2.19
@@ -1,7 +1,7 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2010 Hiroyuki Yamamoto and the Claws Mail Team
- * Copyright (C) 2006-2010 Ricardo Mones
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2006-2011 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
@@ -121,17 +121,21 @@
 	return matcherlist_new(matchers, FALSE);
 }
 
-static gboolean aw_matcherlist_string_match(MatcherList *matchers, gchar *str)
+static AttachWarnerMention *aw_matcherlist_string_match(MatcherList *matchers, gchar *str)
 {
 	MsgInfo info;
+	int i = 0;
 	gboolean ret = FALSE;
+	gchar **lines = NULL;
+	AttachWarnerMention *awm = NULL; 
 
+	if (str == NULL || *str == '\0') {
+		return awm;
+	}
+	
+	lines = g_strsplit(str, "\n", -1);
 	if (attwarnerprefs.skip_quotes
-		&& *str != '\0'
 		&& *prefs_common_get_prefs()->quote_chars != '\0') {
-
-		gchar **lines = g_strsplit(str, "\n", -1);
-		int i;
 		debug_print("checking without quotes\n");
 		for (i = 0; lines[i] != NULL && ret == FALSE; i++) {
 			if (line_has_quote_char(lines[i], 
@@ -142,15 +146,24 @@
 				debug_print("line %d: %d\n", i, ret);
 			}
 		}
-		g_strfreev(lines);
 	} else {
-		info.subject = str;
 		debug_print("checking with quotes\n");
-		ret = matcherlist_match(matchers, &info);
-		debug_print("ret %d\n", ret);
+		for (i = 0; lines[i] != NULL && ret == FALSE; i++) {
+			debug_print("testing line %d\n", i);
+			info.subject = lines[i];
+			ret = matcherlist_match(matchers, &info);
+			debug_print("line %d: %d\n", i, ret);
+		}
+	}
+	if (ret != FALSE) {
+                awm = g_new0(AttachWarnerMention, 1);
+		awm->line = i; /* usual humans count lines from 1 */
+		awm->context = g_strdup(lines[i - 1]);
+		debug_print("found at line %d, context \"%s\"\n", awm->line, awm->context);
 	}
+	g_strfreev(lines);
 
-	return ret;
+	return awm;
 }
 
 /**
@@ -158,15 +171,16 @@
  *
  * @param compose The composer object to inspect.
  *
- * @return TRUE if attachment references are found, FALSE otherwise.
+ * @return A pointer to an AttachWarnerMention if attachment references
+ * are found, or NULL otherwise.
  */
-gboolean are_attachments_mentioned(Compose *compose)
+AttachWarnerMention *are_attachments_mentioned(Compose *compose)
 {
 	GtkTextView *textview = NULL;
 	GtkTextBuffer *textbuffer = NULL;
 	GtkTextIter start, end;
 	gchar *text = NULL;
-	gboolean mentioned = FALSE;
+	AttachWarnerMention *mention = NULL;
 	MatcherList *matchers = NULL;
 
 	matchers = new_matcherlist();
@@ -184,15 +198,13 @@
 
 	debug_print("checking text for attachment mentions\n");
 	if (text != NULL) {
-		mentioned = aw_matcherlist_string_match(matchers, text);
-		debug_print("check done, result %d\n", mentioned);
+		mention = aw_matcherlist_string_match(matchers, text);
 		g_free(text);
 	}	
-
 	if (matchers != NULL)
 		matcherlist_free(matchers);
 	debug_print("done\n");
-	return mentioned;
+	return mention;
 }
 
 /**
@@ -251,7 +263,7 @@
 static gboolean attwarn_before_send_hook(gpointer source, gpointer data)
 {
 	Compose *compose = (Compose *)source;
-	gboolean askuser = FALSE;
+	AttachWarnerMention *mention = NULL;
 
 	debug_print("attachwarner invoked\n");
 	if (compose->batch)
@@ -260,9 +272,8 @@
 	if (do_not_check_redirect_forward(compose->mode))
 		return FALSE;
 
-	askuser = (does_not_have_attachments(compose)
-		   && are_attachments_mentioned(compose));
-	if (askuser) { 
+	mention = are_attachments_mentioned(compose); 
+	if (does_not_have_attachments(compose) && mention != NULL) { 
 		AlertValue aval;
 		gchar *button_label;
 		gchar *message;
@@ -274,7 +285,9 @@
 			button_label = _("+_Queue");
 
 		message = g_strdup_printf(
-				_("An attachment is mentioned in the mail you're sending, but no file was attached. %s it anyway?"),
+				_("An attachment is mentioned in the mail you're sending, but no file was attached. Mention appears on line %d, which begins with text: <span weight=\"bold\">%.20s</span>…\n\n%s it anyway?"),
+				mention->line,
+				mention->context,
 				compose->sending?_("Send"):_("Queue"));
 		aval = alertpanel(_("Attachment warning"), message,
 				  GTK_STOCK_CANCEL, button_label, NULL);
@@ -282,6 +295,11 @@
 		if (aval != G_ALERTALTERNATE)
 			return TRUE;
 	}
+	if (mention != NULL) {
+		if (mention->context != NULL)
+			g_free(mention->context);
+		g_free(mention);
+	}
 
 	return FALSE;	/* continue sending */
 }

Index: attachwarner.h
===================================================================
RCS file: /home/claws-mail/plugins/attachwarner/src/Attic/attachwarner.h,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -d -r1.1.2.7 -r1.1.2.8
--- attachwarner.h	12 Dec 2010 18:28:00 -0000	1.1.2.7
+++ attachwarner.h	19 Oct 2011 22:32:19 -0000	1.1.2.8
@@ -1,7 +1,7 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2010 Hiroyuki Yamamoto and the Claws Mail Team
- * Copyright (C) 2006-2010 Ricardo Mones
+ * Copyright (C) 1999-2011 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2006-2011 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
@@ -33,10 +33,16 @@
 #include "alertpanel.h"
 #include "gettext.h"
 
+struct _AttachWarnerMention {
+	int line;
+	gchar *context;
+};
+
+typedef struct _AttachWarnerMention AttachWarnerMention;
 
 MatcherProp *	new_matcherprop		  (void);
 gboolean 	matcherprop_string_match  (MatcherProp *mp, gchar *str);
-gboolean 	are_attachments_mentioned (Compose *compose);
+AttachWarnerMention *are_attachments_mentioned (Compose *compose);
 gboolean 	does_not_have_attachments (Compose *compose);
 
 gint 		plugin_init	  	  (gchar **error);



More information about the Commits mailing list