+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2002 by the Sylpheed Claws Team and Hiroyuki Yamamoto
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
{MATCHACTION_FORWARD_AS_ATTACHMENT, "forward_as_attachment"},
{MATCHACTION_EXECUTE, "execute"},
{MATCHACTION_COLOR, "color"},
- {MATCHACTION_BOUNCE, "bounce"},
+ {MATCHACTION_REDIRECT, "redirect"},
{MATCHACTION_DELETE_ON_SERVER, "delete_on_server"}
};
return NULL;
}
+/* matcher_escape_str() - escapes a string returns newly allocated escaped string */
+gchar *matcher_escape_str(const gchar *str)
+{
+ register const gchar *walk;
+ register int escape;
+ gchar *res;
+ register char *reswalk;
+
+ if (str == NULL)
+ return NULL;
+
+ for (escape = 0, walk = str; *walk; walk++)
+ if (*walk == '\'' || *walk == '\"')
+ escape++;
+
+ if (!escape)
+ return g_strdup(str);
+
+ reswalk = res = g_new0(gchar, (walk - str) + escape + 1);
+ for (walk = str; *walk; walk++, reswalk++) {
+ if (*walk == '\'' || *walk == '\"')
+ *reswalk++ = '\\';
+ *reswalk = *walk;
+ }
+
+ *reswalk = 0;
+ return res;
+}
+
/* matcher_unescape_str() - assumes that unescaping frees up room
* in the string, so it returns the unescaped string in the
* source */
? REG_ICASE : 0)) != 0) {
prop->error = 1;
g_free(prop->preg);
+ prop->preg = NULL;
}
}
if (prop->preg == NULL)
{
gchar * file;
gchar * cmd;
+ gint retval;
file = procmsg_get_message_file(info);
if (file == NULL)
if (cmd == NULL)
return FALSE;
- return (system(cmd) == 0);
+ retval = system(cmd);
+ debug_print("Command exit code: %d\n", retval);
+
+ return (retval == 0);
}
/* match a message and his headers, hlist can be NULL if you don't
case MATCHCRITERIA_FORWARDED:
case MATCHCRITERIA_NOT_FORWARDED:
return g_strdup(criteria_str);
+ case MATCHCRITERIA_EXECUTE:
+ case MATCHCRITERIA_NOT_EXECUTE:
+ return g_strdup_printf("%s \"%s\"", criteria_str, matcher->expr);
}
matchtype_str = NULL;
return result;
}
+#define STRLEN_ZERO(s) ((s) ? strlen(s) : 0)
+#define STRLEN_DEFAULT(s,d) ((s) ? strlen(s) : STRLEN_ZERO(d))
/* matching_build_command() - preferably cmd should be unescaped */
gchar * matching_build_command(gchar * cmd, MsgInfo * info)
{
gchar * p;
gint size;
- size = strlen(cmd) + 1;
+ const gchar *const no_subject = _("(none)") ;
+ const gchar *const no_from = _("(none)") ;
+ const gchar *const no_to = _("(none)") ;
+ const gchar *const no_cc = _("(none)") ;
+ const gchar *const no_date = _("(none)") ;
+ const gchar *const no_msgid = _("(none)") ;
+ const gchar *const no_newsgroups = _("(none)") ;
+ const gchar *const no_references = _("(none)") ;
+
+ size = STRLEN_ZERO(cmd) + 1;
while (*s != '\0') {
if (*s == '%') {
s++;
size -= 1;
break;
case 's': /* subject */
- size += strlen(info->subject) - 2;
+ size += STRLEN_DEFAULT(info->subject, no_subject) - 2;
break;
case 'f': /* from */
- size += strlen(info->from) - 2;
+ size += STRLEN_DEFAULT(info->from, no_from) - 2;
break;
case 't': /* to */
- size += strlen(info->to) - 2;
+ size += STRLEN_DEFAULT(info->to, no_to) - 2;
break;
case 'c': /* cc */
- size += strlen(info->cc) - 2;
+ size += STRLEN_DEFAULT(info->cc, no_cc) - 2;
break;
case 'd': /* date */
- size += strlen(info->date) - 2;
+ size += STRLEN_DEFAULT(info->date, no_date) - 2;
break;
case 'i': /* message-id */
- size += strlen(info->msgid) - 2;
+ size += STRLEN_DEFAULT(info->msgid, no_msgid) - 2;
break;
case 'n': /* newsgroups */
- size += strlen(info->newsgroups) - 2;
+ size += STRLEN_DEFAULT(info->newsgroups, no_newsgroups) - 2;
break;
case 'r': /* references */
- size += strlen(info->references) - 2;
+ size += STRLEN_DEFAULT(info->references, no_references) - 2;
break;
case 'F': /* file */
filename = folder_item_fetch_msg(info->folder,
if (info->subject != NULL)
strcpy(p, info->subject);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_subject);
p += strlen(p);
break;
case 'f': /* from */
if (info->from != NULL)
strcpy(p, info->from);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_from);
p += strlen(p);
break;
case 't': /* to */
if (info->to != NULL)
strcpy(p, info->to);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_to);
p += strlen(p);
break;
case 'c': /* cc */
if (info->cc != NULL)
strcpy(p, info->cc);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_cc);
p += strlen(p);
break;
case 'd': /* date */
if (info->date != NULL)
strcpy(p, info->date);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_date);
p += strlen(p);
break;
case 'i': /* message-id */
if (info->msgid != NULL)
strcpy(p, info->msgid);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_msgid);
p += strlen(p);
break;
case 'n': /* newsgroups */
if (info->newsgroups != NULL)
strcpy(p, info->newsgroups);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_newsgroups);
p += strlen(p);
break;
case 'r': /* references */
if (info->references != NULL)
strcpy(p, info->references);
else
- strcpy(p, _("(none)"));
+ strcpy(p, no_references);
p += strlen(p);
break;
case 'F': /* file */
strcpy(p, filename);
p += strlen(p);
+ g_free(filename);
break;
default:
*p = '%';
debug_print("*** exec string \"%s\"\n", processed_cmd);
return processed_cmd;
}
+#undef STRLEN_DEFAULT
+#undef STRLEN_ZERO
/* ************************************************************ */
GSList *cur;
ScoringProp * prop;
- debug_print(_("Writing matcher configuration...\n"));
+ debug_print("Writing matcher configuration...\n");
rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
MATCHER_RC, NULL);
f = fopen(rcpath, "rb");
g_free(rcpath);
- if (f != NULL)
+ if (f != NULL) {
matcher_parser_start_parsing(f);
+ fclose(f);
+ }
else {
/* previous version compatibily */