X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fplugins%2Fattachwarner%2Fattachwarner.c;h=4dd8f96eccf39e1a8809c1a1fc0b85f2e819bf81;hp=91f7a46cd317c37a5fe830078080b5f30767160f;hb=be36f031fa3f722c5dbce3dedb33429fadade08a;hpb=99bb49956e8efde944310a6528000f5a25e6e8df diff --git a/src/plugins/attachwarner/attachwarner.c b/src/plugins/attachwarner/attachwarner.c index 91f7a46cd..4dd8f96ec 100644 --- a/src/plugins/attachwarner/attachwarner.c +++ b/src/plugins/attachwarner/attachwarner.c @@ -1,7 +1,6 @@ /* * 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) 2006-2015 Ricardo Mones 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 @@ -14,8 +13,7 @@ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * along with this program. If not, see . */ #ifdef HAVE_CONFIG_H @@ -35,99 +33,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 +109,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, attwarnerprefs.case_sensitive); if (matchers == NULL) { g_warning("couldn't allocate matcher"); @@ -298,21 +203,28 @@ static gboolean attwarn_before_send_hook(gpointer source, gpointer data) AlertValue aval; gchar *button_label; gchar *message; + gchar *bold_text; debug_print("user has to decide\n"); if (compose->sending) - button_label = _("+_Send"); + button_label = g_strconcat("+", _("_Send"), NULL); else - button_label = _("+_Queue"); + button_label = g_strconcat("+", _("_Queue"), NULL); + bold_text = g_strdup_printf("%.20s...", + mention->context); message = g_strdup_printf( - _("An attachment is mentioned in the mail you're sending, but no file was attached. Mention appears on line %d, which begins with text: %.20s...\n\n%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: %s\n\n%s"), mention->line, - mention->context, - compose->sending?_("Send"):_("Queue")); + bold_text, + compose->sending?_("Send it anyway?"):_("Queue it anyway?")); aval = alertpanel(_("Attachment warning"), message, GTK_STOCK_CANCEL, button_label, NULL); g_free(message); + g_free(bold_text); + g_free(button_label); if (aval != G_ALERTALTERNATE) return TRUE; }