[Commits] Makefile.am NONE 1.1.2.1 attachwarner.c NONE 1.1.2.1 attachwarner.h NONE 1.1.2.1 attachwarner_prefs.c NONE 1.1.2.1 attachwarner_prefs.h NONE 1.1.2.1 claws.def NONE 1.1.2.1 placeholder.txt 1.1.2.1 NONE plugin.def NONE 1.1.2.1 version.rc NONE 1.1.2.1

colin at claws-mail.org colin at claws-mail.org
Sat Feb 16 13:59:27 CET 2013


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

Added Files:
      Tag: gtk2
	Makefile.am attachwarner.c attachwarner.h attachwarner_prefs.c 
	attachwarner_prefs.h claws.def plugin.def version.rc 
Removed Files:
      Tag: gtk2
	placeholder.txt 
Log Message:
2013-02-16 [colin]	3.9.0cvs73

	* src/plugins/Makefile.am
	* src/plugins/acpi_notifier/Makefile.am
	* src/plugins/acpi_notifier/acpi_notifier.c
	* src/plugins/acpi_notifier/placeholder.txt
	* src/plugins/address_keeper/Makefile.am
	* src/plugins/address_keeper/address_keeper.c
	* src/plugins/address_keeper/address_keeper.h
	* src/plugins/address_keeper/address_keeper_prefs.c
	* src/plugins/address_keeper/address_keeper_prefs.h
	* src/plugins/address_keeper/claws.def
	* src/plugins/address_keeper/placeholder.txt
	* src/plugins/address_keeper/plugin.def
	* src/plugins/address_keeper/version.rc
	* src/plugins/attachwarner/Makefile.am
	* src/plugins/attachwarner/attachwarner.c
	* src/plugins/attachwarner/attachwarner.h
	* src/plugins/attachwarner/attachwarner_prefs.c
	* src/plugins/attachwarner/attachwarner_prefs.h
	* src/plugins/attachwarner/claws.def
	* src/plugins/attachwarner/placeholder.txt
	* src/plugins/attachwarner/plugin.def
	* src/plugins/attachwarner/version.rc
	* src/plugins/vcalendar/libical/libical/icalversion.h
	* po/POTFILES.in
	* po/bg.po
	* po/ca.po
	* po/cs.po
	* po/de.po
	* po/en_GB.po
	* po/es.po
	* po/fi.po
	* po/fr.po
	* po/hu.po
	* po/id_ID.po
	* po/it.po
	* po/ja.po
	* po/lt.po
	* po/nl.po
	* po/pl.po
	* po/pt_BR.po
	* po/pt_PT.po
	* po/ru.po
	* po/sk.po
	* po/sr.po
	* po/sv.po
	* po/uk.po
	* po/zh_CN.po
	* po/zh_TW.po
		Now do acpi_notifier, attachwarner, address_keeper

--- NEW FILE: attachwarner_prefs.h ---
/*
 * 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
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __ATTACHWARNER_PREFS__
#define __ATTACHWARNER_PREFS__

#include <glib.h>

typedef struct _AttachWarnerPrefs AttachWarnerPrefs;

struct _AttachWarnerPrefs
{
	gchar		 *match_strings;
	gboolean	 skip_quotes;
	gboolean	 skip_forwards_and_redirections;
	gboolean	 skip_signature;
};

extern AttachWarnerPrefs attwarnerprefs;
void attachwarner_prefs_init(void);
void attachwarner_prefs_done(void);

#endif

--- NEW FILE: version.rc ---
1 VERSIONINFO
 FILEVERSION 0, 0, 0, 0
 PRODUCTVERSION 0, 0, 0, 0
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "000004b0"
        BEGIN
            VALUE "FileDescription", "AtatchWarner Plugin\0"
            VALUE "FileVersion", "0.0.0.0\0"
            VALUE "ProductVersion", "0.0.0.0 Win32\0"
            VALUE "LegalCopyright", "GPL / © 1999-2008 Hiroyuki Yamamoto & The Claws Mail Team\0"
            VALUE "CompanyName", "GNU / Free Software Foundation\0"
            VALUE "ProductName", "Claws Mail\0"
//            VALUE "Comments", "\0"
//            VALUE "InternalName", "\0"
//            VALUE "LegalTrademarks", "\0"
//            VALUE "OriginalFilename", "\0"
//            VALUE "PrivateBuild", "\0"
//            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x0, 1200
    END
END

--- NEW FILE: claws.def ---
LIBRARY CLAWS-MAIL.EXE
EXPORTS
get_locale_dir
check_plugin_version
alertpanel
conv_codeset_strdup
conv_get_locale_charset_str_no_utf8
debug_print_real
debug_srcname
get_rc_dir 
hooks_register_hook
hooks_unregister_hook
line_has_quote_char
matcherlist_free
matcherlist_match
matcherlist_new
matcherprop_new
pref_get_escaped_pref
pref_get_unescaped_pref
prefs_common
prefs_file_close
prefs_file_close_revert
prefs_gtk_register_page
prefs_gtk_unregister_page
prefs_read_config
prefs_set_block_label
prefs_set_default
prefs_write_open
prefs_write_param
prefs_common_get_prefs

--- NEW FILE: attachwarner.c ---
/*
 * 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
 *
 * 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, write to the Free Software Foundation, 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "version.h"
#include "attachwarner.h"
#include "attachwarner_prefs.h"
#include "codeconv.h"
#include "prefs_common.h"

/** 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;
	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
		&& *prefs_common_get_prefs()->quote_chars != '\0') {
		debug_print("checking without quotes\n");
		for (i = 0; lines[i] != NULL && ret == FALSE; i++) {
			if(attwarnerprefs.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(attwarnerprefs.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) {
                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 awm;
}

/**
 * Looks for attachment references in the composer text.
 *
 * @param compose The composer object to inspect.
 *
 * @return A pointer to an AttachWarnerMention if attachment references
 * are found, or NULL otherwise.
 */
AttachWarnerMention *are_attachments_mentioned(Compose *compose)
{
	GtkTextView *textview = NULL;
	GtkTextBuffer *textbuffer = NULL;
	GtkTextIter start, end;
	gchar *text = NULL;
	AttachWarnerMention *mention = NULL;
	MatcherList *matchers = NULL;

	matchers = new_matcherlist();

	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 attachment mentions\n");
	if (text != NULL) {
		mention = aw_matcherlist_string_match(matchers, text, compose->account->sig_sep);
		g_free(text);
	}	
	if (matchers != NULL)
		matcherlist_free(matchers);
	debug_print("done\n");
	return mention;
}

/**
 * Looks for files attached in the composer.
 *
 * @param compose The composer object to inspect.
 *
 * @return TRUE if there is one or more files attached, FALSE otherwise.
 */
gboolean does_not_have_attachments(Compose *compose)
{
	GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
        GtkTreeModel *model;
        GtkTreeIter iter;

        model = gtk_tree_view_get_model(tree_view);

	debug_print("checking for attachments existence\n");
        if (!gtk_tree_model_get_iter_first(model, &iter))
                return TRUE;

	return FALSE;
}

/**
 * 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 (attwarnerprefs.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 attachments are mentioned or files are attached,
 *         FALSE if attachments are mentioned and no files are attached.
 */
static gboolean attwarn_before_send_hook(gpointer source, gpointer data)
{
	Compose *compose = (Compose *)source;
	AttachWarnerMention *mention = NULL;

	debug_print("attachwarner invoked\n");
	if (compose->batch)
		return FALSE;	/* do not check while queuing */

	if (do_not_check_redirect_forward(compose->mode))
		return FALSE;

	mention = are_attachments_mentioned(compose); 
	if (does_not_have_attachments(compose) && mention != NULL) { 
		AlertValue aval;
		gchar *button_label;
		gchar *message;
		
		debug_print("user has to decide\n");
		if (compose->sending)
			button_label = _("+_Send");
		else
			button_label = _("+_Queue");

		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: <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);
		g_free(message);
		if (aval != G_ALERTALTERNATE)
			return TRUE;
	}
	if (mention != NULL) {
		if (mention->context != NULL)
			g_free(mention->context);
		g_free(mention);
	}

	return FALSE;	/* continue sending */
}

/**
 * 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, _("Attach warner"), error))
		return -1;

	hook_id = hooks_register_hook(COMPOSE_CHECK_BEFORE_SEND_HOOKLIST, 
				      attwarn_before_send_hook, NULL);
	
	if (hook_id == -1) {
		*error = g_strdup(_("Failed to register check before send hook"));
		return -1;
	}

	attachwarner_prefs_init();

	debug_print("Attachment 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);
	attachwarner_prefs_done();
	debug_print("Attachment warner plugin unloaded\n");
	return TRUE;
}

/**
 * Get the name of the plugin.
 *
 * @return The plugin name (maybe translated).
 */
const gchar *plugin_name(void)
{
	return _("Attach 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 attachments is found in the "
	         "message text and no file is attached.");
}

/**
 * Get the kind of plugin.
 *
 * @return The "GTK2" constant.
 */
const gchar *plugin_type(void)
{
	return "GTK2";
}

/**
 * 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_("Attach warner")},
		  {PLUGIN_NOTHING, NULL}};

	return features;
}


--- NEW FILE: plugin.def ---
EXPORTS
        plugin_desc
        plugin_done
        plugin_init
        plugin_licence
        plugin_name
        plugin_type
	plugin_provides
        plugin_version


--- placeholder.txt DELETED ---

--- NEW FILE: attachwarner_prefs.c ---
/*
 * 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
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#include "claws-features.h"
#endif

#include <glib.h>
#include <glib/gi18n.h>

#include "attachwarner.h"

#include "defs.h"
#include "attachwarner_prefs.h"
#include "prefs_common.h"
#include "prefs_gtk.h"

#define PREFS_BLOCK_NAME "AttachWarner"

AttachWarnerPrefs attwarnerprefs;

struct AttachWarnerPrefsPage
{
	PrefsPage page;
	
	GtkWidget *regexp_text;
	GtkWidget *skip_quotes_checkbox;
	GtkWidget *skip_forwards_and_redirections;
	GtkWidget *skip_signature;
};

struct AttachWarnerPrefsPage attwarnerprefs_page;

static PrefParam param[] = {
	{"match_strings", N_("attach"), &attwarnerprefs.match_strings, P_STRING,
	 NULL, NULL, NULL},
	{"skip_quotes", "TRUE", &attwarnerprefs.skip_quotes, P_BOOL,
	 NULL, NULL, NULL},
	{"skip_forwards_and_redirections", "TRUE", &attwarnerprefs.skip_forwards_and_redirections, P_BOOL,
	 NULL, NULL, NULL},
	{"skip_signature", "TRUE", &attwarnerprefs.skip_signature, P_BOOL,
	 NULL, NULL, NULL},
	{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
};

static void attwarner_prefs_create_widget_func(PrefsPage * _page,
					   GtkWindow * window,
					   gpointer data)
{
	struct AttachWarnerPrefsPage *page = (struct AttachWarnerPrefsPage *) _page;
	GtkWidget *vbox, *hbox;;
	GtkWidget *label;
	GtkWidget *scrolledwin;
	GtkTextBuffer *buffer;
	GtkWidget *skip_quotes_checkbox;
	GtkWidget *skip_fwd_redir_checkbox;
	GtkWidget *skip_signature_checkbox;

	vbox = gtk_vbox_new(FALSE, 6);
	hbox = gtk_hbox_new(FALSE, 6);
	
	label = gtk_label_new(_("Warn when matching the following regular expressions:\n(one per line)"));
	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
	gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
	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, attwarnerprefs.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_add(GTK_CONTAINER(scrolledwin), page->regexp_text);
	gtk_widget_set_size_request(page->regexp_text, -1, 100);
	gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, FALSE, FALSE, 0);
	
	skip_quotes_checkbox = gtk_check_button_new_with_label(_("Skip quoted lines"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skip_quotes_checkbox),
	    	 attwarnerprefs.skip_quotes);
	gtk_box_pack_start(GTK_BOX(vbox), 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"));
	page->skip_quotes_checkbox = skip_quotes_checkbox;
	
	skip_fwd_redir_checkbox = gtk_check_button_new_with_label(_("Skip forwards and redirections"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skip_fwd_redir_checkbox),
	    	 attwarnerprefs.skip_forwards_and_redirections);
	gtk_box_pack_start(GTK_BOX(vbox), 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 missing attachments when forwarding or redirecting messages"));
	page->skip_forwards_and_redirections = skip_fwd_redir_checkbox;

	skip_signature_checkbox = gtk_check_button_new_with_label(_("Skip signature"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(skip_signature_checkbox),
	    	 attwarnerprefs.skip_signature);
	gtk_box_pack_start(GTK_BOX(vbox), 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;

	gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 6);
	gtk_widget_show_all(hbox);
	
	page->page.widget = hbox;
}

static void attwarner_prefs_destroy_widget_func(PrefsPage *_page)
{
}

static void attwarner_save_config(void)
{
	PrefFile *pfile;
	gchar *rcpath;

	debug_print("Saving AttachWarner 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 AttachWarner configuration to file\n");
		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 attwarner_prefs_save_func(PrefsPage * _page)
{
	struct AttachWarnerPrefsPage *page = (struct AttachWarnerPrefsPage *) _page;
	GtkTextBuffer *buffer;
	GtkTextIter start, end;
	gchar *tmp;
	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->regexp_text));
	
	g_free(attwarnerprefs.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);
	
	attwarnerprefs.match_strings = g_malloc(2*strlen(tmp)+1);
	pref_get_escaped_pref(attwarnerprefs.match_strings, tmp);

	attwarnerprefs.skip_quotes = gtk_toggle_button_get_active
			(GTK_TOGGLE_BUTTON(page->skip_quotes_checkbox));
	attwarnerprefs.skip_forwards_and_redirections = gtk_toggle_button_get_active
			(GTK_TOGGLE_BUTTON(page->skip_forwards_and_redirections));
	attwarnerprefs.skip_signature = gtk_toggle_button_get_active
			(GTK_TOGGLE_BUTTON(page->skip_signature));

	attwarner_save_config();
	g_free(attwarnerprefs.match_strings);
	attwarnerprefs.match_strings = tmp;
}

void attachwarner_prefs_init(void)
{
	static gchar *path[3];
	gchar *rcpath;
	gchar *tmp;
	
	path[0] = _("Plugins");
	path[1] = _("Attach 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(attwarnerprefs.match_strings)+1);
	pref_get_unescaped_pref(tmp, attwarnerprefs.match_strings);
	
	g_free(attwarnerprefs.match_strings);
	attwarnerprefs.match_strings = tmp;
	
	attwarnerprefs_page.page.path = path;
	attwarnerprefs_page.page.create_widget = attwarner_prefs_create_widget_func;
	attwarnerprefs_page.page.destroy_widget = attwarner_prefs_destroy_widget_func;
	attwarnerprefs_page.page.save_page = attwarner_prefs_save_func;

	prefs_gtk_register_page((PrefsPage *) &attwarnerprefs_page);
}

void attachwarner_prefs_done(void)
{
	prefs_gtk_unregister_page((PrefsPage *) &attwarnerprefs_page);
}

--- NEW FILE: Makefile.am ---
EXTRA_DIST = claws.def plugin.def version.rc

if OS_WIN32

LTRCCOMPILE = $(LIBTOOL) --mode=compile --tag=RC $(RC) \
     `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \
     sed -e 's/-I/--include-dir /g;s/-D/--define /g'`

%.lo : %.rc
	$(LTRCCOMPILE) -i $< -o $@

plugin_res = version.lo
plugin_res_ldflag = -Wl,.libs/version.o

export_symbols = -export-symbols $(srcdir)/plugin.def

plugin_deps = libclaws.a $(plugin_res) plugin.def

libclaws.a: claws.def
	$(DLLTOOL) --output-lib $@ --def $<

plugin_ldadd = -L. -lclaws

else
plugin_res =
plugin_res_ldflag =
export_symbols =
plugin_deps =
plugin_ldadd =
endif

if PLATFORM_WIN32
no_undefined = -no-undefined
else
no_undefined =
endif

if CYGWIN
cygwin_export_lib = -L$(top_builddir)/src -lclaws-mail
else
cygwin_export_lib = 
endif

plugindir = $(pkglibdir)/plugins

plugin_LTLIBRARIES = attachwarner.la

attachwarner_la_LDFLAGS = \
	$(plugin_res_ldflag) $(no_undefined) $(export_symbols) \
	-avoid-version -module \
	$(GTK_LIBS)

attachwarner_la_DEPENDENCIES = $(plugin_deps)

attachwarner_la_LIBADD = $(plugin_ldadd) $(cygwin_export_lib) \
	$(GTK_LIBS)

INCLUDES = \
	-I$(top_srcdir)/src \
	-I$(top_srcdir)/src/common \
	-I$(top_builddir)/src/common \
	-I$(top_srcdir)/src/gtk

AM_CPPFLAGS = \
	-Wall \
	$(CLAWS_MAIL_CFLAGS) \
	$(GLIB_CFLAGS) \
	$(GTK_CFLAGS) \
	-DLOCALEDIR=\""$(localedir)"\" 

attachwarner_la_SOURCES = \
	attachwarner.c attachwarner.h \
	attachwarner_prefs.c attachwarner_prefs.h


--- NEW FILE: attachwarner.h ---
/*
 * 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
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __ATTACHWARNER_H
#define __ATTACHWARNER_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 _AttachWarnerMention {
	int line;
	gchar *context;
};

typedef struct _AttachWarnerMention AttachWarnerMention;

MatcherProp *	new_matcherprop		  (void);
gboolean 	matcherprop_string_match  (MatcherProp *mp, gchar *str);
AttachWarnerMention *are_attachments_mentioned (Compose *compose);
gboolean 	does_not_have_attachments (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




More information about the Commits mailing list