talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit fc475e5920fbff0135f422bc204550bf7d7997e3
parent f498ce6112d8672875432fe1ad390a2ec0a31743
Author: paul <paul@claws-mail.org>
Date:   Tue,  8 Mar 2022 18:55:36 +0000

add keyword_warner plugin

Diffstat:
Mconfigure.ac | 16++++++++++++++++
Asrc/plugins/keyword_warner/Makefile.am | 42++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/keyword_warner/keyword_warner.c | 317+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/keyword_warner/keyword_warner.h | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/keyword_warner/keyword_warner_prefs.c | 263+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/keyword_warner/keyword_warner_prefs.h | 39+++++++++++++++++++++++++++++++++++++++
Asrc/plugins/keyword_warner/version.rc.in | 34++++++++++++++++++++++++++++++++++
7 files changed, 764 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -1108,6 +1108,10 @@ AC_ARG_ENABLE(gdata-plugin, [ --disable-gdata-plugin Do not build gdata plugin], [enable_gdata_plugin=$enableval], [enable_gdata_plugin=auto]) +AC_ARG_ENABLE(keyword_warner-plugin, + [ --disable-keyword_warner-plugin Do not build keyword_warner plugin], + [enable_keyword_warner_plugin=$enableval], [enable_keyword_warner_plugin=auto]) + AC_ARG_ENABLE(libravatar-plugin, [ --disable-libravatar-plugin Do not build libravatar plugin], [enable_libravatar_plugin=$enableval], [enable_libravatar_plugin=auto]) @@ -1622,6 +1626,15 @@ else AC_MSG_RESULT(no) fi +AC_MSG_CHECKING([whether to build keyword_warner plugin]) +if test x"$enable_keyword_warner_plugin" != xno; then + PLUGINS="$PLUGINS keyword_warner" + AC_MSG_RESULT(yes) +else + DISABLED_PLUGINS="$DISABLED_PLUGINS keyword_warner" + AC_MSG_RESULT(no) +fi + AC_MSG_CHECKING([whether to build libravatar plugin]) if test x"$enable_libravatar_plugin" != xno; then dependencies_missing="" @@ -2102,6 +2115,7 @@ AM_CONDITIONAL(BUILD_DILLO_PLUGIN, test x"$enable_dillo_plugin" != xno) AM_CONDITIONAL(BUILD_FANCY_PLUGIN, test x"$enable_fancy_plugin" != xno) AM_CONDITIONAL(BUILD_FETCHINFO_PLUGIN, test x"$enable_fetchinfo_plugin" != xno) AM_CONDITIONAL(BUILD_GDATA_PLUGIN, test x"$enable_gdata_plugin" != xno) +AM_CONDITIONAL(BUILD_KEYWORD_WARNER_PLUGIN, test x"$enable_keywordwarner_plugin" != xno) AM_CONDITIONAL(BUILD_LIBRAVATAR_PLUGIN, test x"$enable_libravatar_plugin" != xno) AM_CONDITIONAL(BUILD_LITEHTML_VIEWER_PLUGIN, test x"$enable_litehtml_viewer_plugin" != xno) AM_CONDITIONAL(BUILD_MAILMBOX_PLUGIN, test x"$enable_mailmbox_plugin" != xno) @@ -2160,6 +2174,8 @@ src/plugins/fancy/version.rc src/plugins/fetchinfo/Makefile src/plugins/fetchinfo/version.rc src/plugins/gdata/Makefile +src/plugins/keyword_warner/Makefile +src/plugins/keyword_warner/version.rc src/plugins/litehtml_viewer/Makefile src/plugins/litehtml_viewer/version.rc src/plugins/litehtml_viewer/litehtml/Makefile diff --git a/src/plugins/keyword_warner/Makefile.am b/src/plugins/keyword_warner/Makefile.am @@ -0,0 +1,42 @@ +# Copyright 1999-2022 the Claws Mail team. +# This file is part of Claws Mail package, and distributed under the +# terms of the General Public License version 3 (or later). +# See COPYING file for license details. + +include $(srcdir)/../win_plugin.mk + +IFLAGS = \ + -I$(top_builddir)/src \ + -I$(top_builddir)/src/common \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/common \ + -I$(top_srcdir)/src/gtk + +plugindir = $(pkglibdir)/plugins + +if BUILD_KEYWORD_WARNER_PLUGIN +plugin_LTLIBRARIES = keyword_warner.la +endif + +keyword_warner_la_LDFLAGS = \ + $(plugin_ldflags) \ + -avoid-version -module + +EXTRA_keyword_warner_la_DEPENDENCIES = $(plugin_extra_deps) + +keyword_warner_la_LIBADD = $(plugin_libadd) \ + $(GTK_LIBS) + +keyword_warner_la_CPPFLAGS = \ + $(IFLAGS) \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(ENCHANT_CFLAGS) + +keyword_warner_la_SOURCES = \ + keyword_warner.c \ + keyword_warner.h \ + keyword_warner_prefs.c \ + keyword_warner_prefs.h + +.PHONY: test diff --git a/src/plugins/keyword_warner/keyword_warner.c b/src/plugins/keyword_warner/keyword_warner.c @@ -0,0 +1,317 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2006-2022 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 + * the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#include "claws-features.h" +#endif + +#include <glib.h> +#include <glib/gi18n.h> + +#include "version.h" +#include "keyword_warner.h" +#include "keyword_warner_prefs.h" +#include "codeconv.h" +#include "prefs_common.h" + +/** Identifier for the hook. */ +static gulong hook_id = HOOK_NONE; + +static KeywordWarnerMention *kw_matcherlist_string_match(MatcherList *matchers, gchar *str, gchar *sig_separator) +{ + MsgInfo info; + int i = 0; + gboolean ret = FALSE; + gchar **lines = NULL; + KeywordWarnerMention *kwm = NULL; + + if (str == NULL || *str == '\0') { + return kwm; + } + + lines = g_strsplit(str, "\n", -1); + if (kwarnerprefs.skip_quotes + && *prefs_common_get_prefs()->quote_chars != '\0') { + debug_print("checking without quotes\n"); + for (i = 0; lines[i] != NULL && ret == FALSE; i++) { + if(kwarnerprefs.skip_signature + && sig_separator != NULL + && *sig_separator != '\0' + && strcmp(lines[i], sig_separator) == 0) { + debug_print("reached signature delimiter at line %d\n", i); + break; + } + if (line_has_quote_char(lines[i], + prefs_common_get_prefs()->quote_chars) == NULL) { + debug_print("testing line %d\n", i); + info.subject = lines[i]; + ret = matcherlist_match(matchers, &info); + debug_print("line %d: %d\n", i, ret); + } + } + } else { + debug_print("checking with quotes\n"); + for (i = 0; lines[i] != NULL && ret == FALSE; i++) { + if(kwarnerprefs.skip_signature + && sig_separator != NULL + && *sig_separator != '\0' + && strcmp(lines[i], sig_separator) == 0) { + debug_print("reached signature delimiter at line %d\n", i); + break; + } + 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) { + kwm = g_new0(KeywordWarnerMention, 1); + kwm->line = i; /* usual humans count lines from 1 */ + kwm->context = g_strdup(lines[i - 1]); + debug_print("found at line %d, context \"%s\"\n", kwm->line, kwm->context); + } + g_strfreev(lines); + + return kwm; +} + +/** + * Looks for keyword references in the composer text. + * + * @param compose The composer object to inspect. + * + * @return A pointer to an KeywordWarnerMention if keyword references + * are found, or NULL otherwise. + */ +KeywordWarnerMention *is_keyword_mentioned(Compose *compose) +{ + GtkTextView *textview = NULL; + GtkTextBuffer *textbuffer = NULL; + GtkTextIter start, end; + gchar *text = NULL; + KeywordWarnerMention *mention = NULL; + MatcherList *matchers = NULL; + + matchers = matcherlist_new_from_lines(kwarnerprefs.match_strings, FALSE, kwarnerprefs.case_sensitive); + + if (matchers == NULL) { + g_warning("couldn't allocate matcher"); + return FALSE; + } + + textview = GTK_TEXT_VIEW(compose->text); + textbuffer = gtk_text_view_get_buffer(textview); + gtk_text_buffer_get_start_iter(textbuffer, &start); + gtk_text_buffer_get_end_iter(textbuffer, &end); + text = gtk_text_buffer_get_text(textbuffer, &start, &end, FALSE); + + debug_print("checking text for keyword mentions\n"); + if (text != NULL) { + mention = kw_matcherlist_string_match(matchers, text, compose->account->sig_sep); + g_free(text); + } + if (matchers != NULL) + matcherlist_free(matchers); + debug_print("done\n"); + return mention; +} + +/** + * Check whether not check while redirecting or forwarding. + * + * @param mode The current compose->mode. + * + * @return TRUE for cancel further checking because it's being redirected or + * forwarded and user configured not to check, FALSE otherwise. + */ +gboolean do_not_check_redirect_forward(int mode) +{ + switch (mode) { + case COMPOSE_FORWARD: + case COMPOSE_FORWARD_AS_ATTACH: + case COMPOSE_FORWARD_INLINE: + case COMPOSE_REDIRECT: + if (kwarnerprefs.skip_forwards_and_redirections) + return TRUE; + default: + return FALSE; + } +} + +/** + * Callback function to be called before sending the mail. + * + * @param source The composer to be checked. + * @param data Additional data. + * + * @return TRUE if no keywords are mentioned, + * FALSE if keywords are mentioned. + */ +static gboolean kwarn_before_send_hook(gpointer source, gpointer data) +{ + Compose *compose = (Compose *)source; + KeywordWarnerMention *mention = NULL; + gboolean ret = FALSE; /* continue sending if FALSE */ + + debug_print("KeywordWarner invoked\n"); + if (compose->batch) + return FALSE; /* do not check while queuing */ + + if (do_not_check_redirect_forward(compose->mode)) + return FALSE; + + mention = is_keyword_mentioned(compose); + if (mention != NULL) { + AlertValue aval; + gchar *message; + gchar *bold_text; + + bold_text = g_strdup_printf("<span weight=\"bold\">%.20s</span>...", + mention->context); + message = g_strdup_printf( + _("A keyword is mentioned in the mail you're sending. " + " Mention appears on line %d, " + "which begins with text: %s\n\n%s"), + mention->line, + bold_text, + compose->sending?_("Send it anyway?"):_("Queue it anyway?")); + aval = alertpanel(_("Keyword warning"), message, + NULL, _("_Cancel"), + NULL, compose->sending ? _("_Send") : _("Queue"), + NULL, NULL, ALERTFOCUS_SECOND); + g_free(message); + g_free(bold_text); + if (aval != G_ALERTALTERNATE) + ret = TRUE; + } + if (mention != NULL) { + if (mention->context != NULL) + g_free(mention->context); + g_free(mention); + } + + return ret; +} + +/** + * Initialize plugin. + * + * @param error For storing the returned error message. + * + * @return 0 if initialization succeeds, -1 on failure. + */ +gint plugin_init(gchar **error) +{ + if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72), + VERSION_NUMERIC, "Keyword_Warner", error)) + return -1; + + hook_id = hooks_register_hook(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, + kwarn_before_send_hook, NULL); + + if (hook_id == HOOK_NONE) { + *error = g_strdup(_("Failed to register check before send hook")); + return -1; + } + + keyword_warner_prefs_init(); + + debug_print("Keyword Warner plugin loaded\n"); + + return 0; +} + +/** + * Destructor for the plugin. + * Unregister the callback function and frees matcher. + */ +gboolean plugin_done(void) +{ + hooks_unregister_hook(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, hook_id); + keyword_warner_prefs_done(); + debug_print("Keyword Warner plugin unloaded\n"); + return TRUE; +} + +/** + * Get the name of the plugin. + * + * @return The plugin name (maybe translated). + */ +const gchar *plugin_name(void) +{ + return _("Keyword_Warner"); +} + +/** + * Get the description of the plugin. + * + * @return The plugin description (maybe translated). + */ +const gchar *plugin_desc(void) +{ + return _("Warns user if some reference to keywords is found in the " + "message text."); +} + +/** + * Get the kind of plugin. + * + * @return The "GTK3" constant. + */ +const gchar *plugin_type(void) +{ + return "GTK3"; +} + +/** + * Get the license acronym the plugin is released under. + * + * @return The "GPL" constant. + */ +const gchar *plugin_licence(void) +{ + return "GPL3+"; +} + +/** + * Get the version of the plugin. + * + * @return The current version string. + */ +const gchar *plugin_version(void) +{ + return VERSION; +} + +/** + * Get the features implemented by the plugin. + * + * @return A constant PluginFeature structure with the features. + */ +struct PluginFeature *plugin_provides(void) +{ + static struct PluginFeature features[] = + { {PLUGIN_OTHER, N_("Keyword_Warner")}, + {PLUGIN_NOTHING, NULL}}; + + return features; +} + diff --git a/src/plugins/keyword_warner/keyword_warner.h b/src/plugins/keyword_warner/keyword_warner.h @@ -0,0 +1,53 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2006-2022 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 + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __KEYWORD_WARNER_H +#define __KEYWORD_WARNER_H + +#include <glib.h> + +#include "version.h" +#include "claws.h" +#include "plugin.h" +#include "utils.h" +#include "hooks.h" +#include "compose.h" +#include "matcher.h" +#include "alertpanel.h" + +struct _KeywordWarnerMention { + int line; + gchar *context; +}; + +typedef struct _KeywordWarnerMention KeywordWarnerMention; + +MatcherProp * new_matcherprop (void); +gboolean matcherprop_string_match (MatcherProp *mp, gchar *str); +KeywordWarnerMention * is_keyword_mentioned (Compose *compose); + +gint plugin_init (gchar **error); +gboolean plugin_done (void); +const gchar * plugin_name (void); +const gchar * plugin_desc (void); +const gchar * plugin_type (void); +const gchar * plugin_licence (void); +const gchar * plugin_version (void); +struct PluginFeature * plugin_provides (void); + +#endif diff --git a/src/plugins/keyword_warner/keyword_warner_prefs.c b/src/plugins/keyword_warner/keyword_warner_prefs.c @@ -0,0 +1,263 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2006-2022 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 + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#include "claws-features.h" +#endif + +#include <glib.h> +#include <glib/gi18n.h> + +#include "keyword_warner.h" + +#include "defs.h" +#include "keyword_warner_prefs.h" +#include "prefs_common.h" +#include "prefs_gtk.h" + +#define PREFS_BLOCK_NAME "Keyword_Warner" + +KeywordWarnerPrefs kwarnerprefs; + +struct KeywordWarnerPrefsPage +{ + PrefsPage page; + + GtkWidget *regexp_text; + GtkWidget *skip_quotes_checkbox; + GtkWidget *skip_forwards_and_redirections; + GtkWidget *skip_signature; + GtkWidget *case_sensitive_checkbox; +}; + +struct KeywordWarnerPrefsPage kwarnerprefs_page; + +static PrefParam param[] = { + {"match_strings", "", &kwarnerprefs.match_strings, P_STRING, + NULL, NULL, NULL}, + {"skip_quotes", "TRUE", &kwarnerprefs.skip_quotes, P_BOOL, + NULL, NULL, NULL}, + {"skip_forwards_and_redirections", "TRUE", &kwarnerprefs.skip_forwards_and_redirections, P_BOOL, + NULL, NULL, NULL}, + {"skip_signature", "TRUE", &kwarnerprefs.skip_signature, P_BOOL, + NULL, NULL, NULL}, + {"case_sensitive", "TRUE", &kwarnerprefs.case_sensitive, P_BOOL, + NULL, NULL, NULL}, + {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL} +}; + +static void keyword_warner_prefs_create_widget_func(PrefsPage * _page, + GtkWindow * window, + gpointer data) +{ + struct KeywordWarnerPrefsPage *page = (struct KeywordWarnerPrefsPage *) _page; + GtkWidget *vbox, *vbox1, *vbox2; + GtkWidget *frame; + GtkWidget *label; + GtkWidget *scrolledwin; + GtkTextBuffer *buffer; + GtkWidget *skip_quotes_checkbox; + GtkWidget *skip_fwd_redir_checkbox; + GtkWidget *skip_signature_checkbox; + GtkWidget *case_sensitive_checkbox; + + vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); + vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); + + label = gtk_label_new(_("One of the following regular expressions is matched (one per line)")); + gtk_label_set_xalign(GTK_LABEL(label), 0.0); + gtk_widget_set_margin_start(GTK_WIDGET(label), 2); + gtk_widget_set_margin_end(GTK_WIDGET(label), 0); + + case_sensitive_checkbox = gtk_check_button_new_with_label(_("Expressions are case sensitive")); + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(case_sensitive_checkbox), + kwarnerprefs.case_sensitive); + gtk_widget_show(case_sensitive_checkbox); + + CLAWS_SET_TIP(case_sensitive_checkbox, + _("Case sensitive when matching for the regular expressions in the list")); + page->case_sensitive_checkbox = case_sensitive_checkbox; + + page->regexp_text = gtk_text_view_new(); + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->regexp_text)); + gtk_text_buffer_set_text(buffer, kwarnerprefs.match_strings, -1); + + scrolledwin = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy( + GTK_SCROLLED_WINDOW (scrolledwin), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type( + GTK_SCROLLED_WINDOW (scrolledwin), GTK_SHADOW_IN); + gtk_container_set_border_width(GTK_CONTAINER(scrolledwin), 3); + + gtk_container_add(GTK_CONTAINER(scrolledwin), page->regexp_text); + gtk_widget_set_size_request(page->regexp_text, -1, 100); + + gtk_box_pack_start(GTK_BOX(vbox1), label, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox1), scrolledwin, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox1), case_sensitive_checkbox, FALSE, FALSE, 0); + + skip_quotes_checkbox = gtk_check_button_new_with_label(_("Lines starting with quotation marks")); + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(skip_quotes_checkbox), + kwarnerprefs.skip_quotes); + gtk_box_pack_start(GTK_BOX(vbox2), skip_quotes_checkbox, FALSE, FALSE, 0); + gtk_widget_show(skip_quotes_checkbox); + + CLAWS_SET_TIP(skip_quotes_checkbox, + _("Exclude quoted lines from checking for the regular " + "expressions above. Note that handmade quotes cannot " + "be distinguished from quotes generated by replying.")); + page->skip_quotes_checkbox = skip_quotes_checkbox; + + skip_fwd_redir_checkbox = gtk_check_button_new_with_label(_("Forwarded or redirected messages")); + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(skip_fwd_redir_checkbox), + kwarnerprefs.skip_forwards_and_redirections); + gtk_box_pack_start(GTK_BOX(vbox2), skip_fwd_redir_checkbox, FALSE, FALSE, 0); + gtk_widget_show(skip_fwd_redir_checkbox); + + CLAWS_SET_TIP(skip_fwd_redir_checkbox, + _("Don't check for keywords when forwarding or redirecting messages")); + page->skip_forwards_and_redirections = skip_fwd_redir_checkbox; + + skip_signature_checkbox = gtk_check_button_new_with_label(_("Signatures")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skip_signature_checkbox), + kwarnerprefs.skip_signature); + gtk_box_pack_start(GTK_BOX(vbox2), skip_signature_checkbox, FALSE, FALSE, 0); + gtk_widget_show(skip_signature_checkbox); + + CLAWS_SET_TIP(skip_signature_checkbox, + _("Exclude lines from the first signature-separator onwards " + "from checking for the regular expressions above")); + page->skip_signature = skip_signature_checkbox; + + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING); + gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER); + + PACK_FRAME (vbox, frame, _("Warn when")); + gtk_container_set_border_width(GTK_CONTAINER(vbox1), 6); + gtk_container_add(GTK_CONTAINER(frame), vbox1); + + PACK_FRAME (vbox, frame, _("Excluding")); + gtk_container_set_border_width(GTK_CONTAINER(vbox2), 6); + gtk_container_add(GTK_CONTAINER(frame), vbox2); + + gtk_widget_show_all(vbox); + + page->page.widget = vbox; +} + +static void keyword_warner_prefs_destroy_widget_func(PrefsPage *_page) +{ +} + +static void keyword_warner_save_config(void) +{ + PrefFile *pfile; + gchar *rcpath; + + debug_print("Saving Keyword Warner Page\n"); + + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); + pfile = prefs_write_open(rcpath); + g_free(rcpath); + if (!pfile || (prefs_set_block_label(pfile, PREFS_BLOCK_NAME) < 0)) + return; + + if (prefs_write_param(param, pfile->fp) < 0) { + g_warning("failed to write Keyword Warner configuration to file"); + prefs_file_close_revert(pfile); + return; + } + if (fprintf(pfile->fp, "\n") < 0) { + FILE_OP_ERROR(rcpath, "fprintf"); + prefs_file_close_revert(pfile); + } else + prefs_file_close(pfile); +} + + +static void keyword_warner_prefs_save_func(PrefsPage * _page) +{ + struct KeywordWarnerPrefsPage *page = (struct KeywordWarnerPrefsPage *) _page; + GtkTextBuffer *buffer; + GtkTextIter start, end; + gchar *tmp; + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->regexp_text)); + + g_free(kwarnerprefs.match_strings); + + gtk_text_buffer_get_start_iter(buffer, &start); + gtk_text_buffer_get_end_iter(buffer, &end); + + tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); + + kwarnerprefs.match_strings = g_malloc(2*strlen(tmp)+1); + pref_get_escaped_pref(kwarnerprefs.match_strings, tmp); + + kwarnerprefs.skip_quotes = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->skip_quotes_checkbox)); + kwarnerprefs.skip_forwards_and_redirections = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->skip_forwards_and_redirections)); + kwarnerprefs.skip_signature = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->skip_signature)); + kwarnerprefs.case_sensitive = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->case_sensitive_checkbox)); + + keyword_warner_save_config(); + g_free(kwarnerprefs.match_strings); + kwarnerprefs.match_strings = tmp; +} + +void keyword_warner_prefs_init(void) +{ + static gchar *path[3]; + gchar *rcpath; + gchar *tmp; + + path[0] = _("Plugins"); + path[1] = _("Keyword_Warner"); + path[2] = NULL; + + prefs_set_default(param); + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); + prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL); + g_free(rcpath); + + tmp = g_malloc(strlen(kwarnerprefs.match_strings)+1); + pref_get_unescaped_pref(tmp, kwarnerprefs.match_strings); + + g_free(kwarnerprefs.match_strings); + kwarnerprefs.match_strings = tmp; + + kwarnerprefs_page.page.path = path; + kwarnerprefs_page.page.create_widget = keyword_warner_prefs_create_widget_func; + kwarnerprefs_page.page.destroy_widget = keyword_warner_prefs_destroy_widget_func; + kwarnerprefs_page.page.save_page = keyword_warner_prefs_save_func; + kwarnerprefs_page.page.weight = 40.0; + + prefs_gtk_register_page((PrefsPage *) &kwarnerprefs_page); +} + +void keyword_warner_prefs_done(void) +{ + prefs_gtk_unregister_page((PrefsPage *) &kwarnerprefs_page); +} diff --git a/src/plugins/keyword_warner/keyword_warner_prefs.h b/src/plugins/keyword_warner/keyword_warner_prefs.h @@ -0,0 +1,39 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2006-2022 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 + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __KEYWORD_WARNER_PREFS__ +#define __KEYWORD_WARNER_PREFS__ + +#include <glib.h> + +typedef struct _KeywordWarnerPrefs KeywordWarnerPrefs; + +struct _KeywordWarnerPrefs +{ + gchar * match_strings; + gboolean skip_quotes; + gboolean skip_forwards_and_redirections; + gboolean skip_signature; + gboolean case_sensitive; +}; + +extern KeywordWarnerPrefs kwarnerprefs; +void keyword_warner_prefs_init(void); +void keyword_warner_prefs_done(void); + +#endif diff --git a/src/plugins/keyword_warner/version.rc.in b/src/plugins/keyword_warner/version.rc.in @@ -0,0 +1,34 @@ +#include <winver.h> + +VS_VERSION_INFO VERSIONINFO +FILEVERSION @MAJOR_VERSION@,@MINOR_VERSION@,@MICRO_VERSION@,@EXTRA_VERSION@ +PRODUCTVERSION @MAJOR_VERSION@,@MINOR_VERSION@,@MICRO_VERSION@,@EXTRA_VERSION@ +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS 0x0L +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN +// VALUE "Comments", "" + VALUE "CompanyName", "The Claws Mail Team" + VALUE "FileDescription", "Claws Mail Keyword Warner Plugin" + VALUE "FileVersion", "@VERSION@" + VALUE "InternalName", "keyword_warner" + VALUE "LegalCopyright", "GPL-3.0-or-later / © 1999-2022 The Claws Mail Team" +// VALUE "LegalTrademarks", "" + VALUE "OriginalFilename", "keyword_warner.dll" +// VALUE "PrivateBuild", "" + VALUE "ProductName", "Claws Mail" + VALUE "ProductVersion", "@GIT_VERSION@ for Windows" +// VALUE "SpecialBuild", "" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1200 + END +END