From 45331a38ddec3708a6f319448e81e7fd570e1292 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ho=C3=A0=20Vi=C3=AAt=20Dinh?= Date: Fri, 5 Dec 2003 11:03:04 +0000 Subject: [PATCH] quote arguments before giving them to command line. fixed quote of string in matcher/processing/filtering rules. allows decryption to return a new whole MIME message structure. --- src/common/utils.c | 58 +++++++++++ src/common/utils.h | 3 + src/filtering.c | 42 ++------ src/filtering.h | 1 - src/matcher.c | 191 +++++++++++++++++++++++++------------ src/matcher.h | 2 + src/matcher_parser_lex.l | 15 +-- src/matcher_parser_parse.y | 106 ++++++++++---------- src/messageview.c | 14 ++- src/prefs_actions.c | 1 + src/prefs_filtering.c | 19 ++-- src/privacy.c | 28 +++--- src/privacy.h | 2 +- 13 files changed, 300 insertions(+), 182 deletions(-) diff --git a/src/common/utils.c b/src/common/utils.c index 13901e8b8..d0d02a935 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -3666,3 +3666,61 @@ gchar *generate_msgid(const gchar *address, gchar *buf, gint len) g_free(addr); return buf; } + + +/* + quote_cmd_argument() + + return a quoted string safely usable in argument of a command. + + code is extracted and adapted from etPan! project -- DINH V. HoĆ . +*/ + +gint quote_cmd_argument(gchar * result, guint size, + const gchar * path) +{ + const gchar * p; + gchar * result_p; + guint remaining; + + result_p = result; + remaining = size; + + for(p = path ; * p != '\0' ; p ++) { + + if (isalnum(* p) || (* p == '/')) { + if (remaining > 0) { + * result_p = * p; + result_p ++; + remaining --; + } + else { + result[size - 1] = '\0'; + return -1; + } + } + else { + if (remaining >= 2) { + * result_p = '\\'; + result_p ++; + * result_p = * p; + result_p ++; + remaining -= 2; + } + else { + result[size - 1] = '\0'; + return -1; + } + } + } + if (remaining > 0) { + * result_p = '\0'; + } + else { + result[size - 1] = '\0'; + return -1; + } + + return 0; +} + diff --git a/src/common/utils.h b/src/common/utils.h index 6851f667c..8f53dc005 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -434,4 +434,7 @@ gint g_int_compare (gconstpointer a, gconstpointer b); gchar *generate_msgid (const gchar *address, gchar *buf, gint len); gchar *generate_mime_boundary (const gchar *prefix); +gint quote_cmd_argument(gchar * result, guint size, + const gchar * path); + #endif /* __UTILS_H__ */ diff --git a/src/filtering.c b/src/filtering.c index bf516d2d5..40290ad63 100644 --- a/src/filtering.c +++ b/src/filtering.c @@ -65,10 +65,8 @@ FilteringAction * filteringaction_new(int type, int account_id, action->account_id = account_id; if (destination) { action->destination = g_strdup(destination); - action->unesc_destination = matcher_unescape_str(g_strdup(destination)); } else { action->destination = NULL; - action->unesc_destination = NULL; } action->labelcolor = labelcolor; action->score = score; @@ -80,8 +78,6 @@ void filteringaction_free(FilteringAction * action) g_return_if_fail(action); if (action->destination) g_free(action->destination); - if (action->unesc_destination) - g_free(action->unesc_destination); g_free(action); } @@ -109,10 +105,6 @@ static FilteringAction * filteringaction_copy(FilteringAction * src) new->destination = g_strdup(src->destination); else new->destination = NULL; - if (src->unesc_destination) - new->unesc_destination = g_strdup(src->unesc_destination); - else - new->unesc_destination = NULL; new->labelcolor = src->labelcolor; return new; @@ -126,10 +118,6 @@ FilteringProp * filteringprop_copy(FilteringProp *src) new = g_new0(FilteringProp, 1); new->matchers = g_new0(MatcherList, 1); -#if 0 - new->action = g_new0(FilteringAction, 1); -#endif - for (tmp = src->matchers->matchers; tmp != NULL && tmp->data != NULL;) { MatcherProp *matcher = (MatcherProp *)tmp->data; @@ -140,19 +128,6 @@ FilteringProp * filteringprop_copy(FilteringProp *src) new->matchers->bool_and = src->matchers->bool_and; -#if 0 - new->action->type = src->action->type; - new->action->account_id = src->action->account_id; - if (src->action->destination) - new->action->destination = g_strdup(src->action->destination); - else - new->action->destination = NULL; - if (src->action->unesc_destination) - new->action->unesc_destination = g_strdup(src->action->unesc_destination); - else - new->action->unesc_destination = NULL; - new->action->labelcolor = src->action->labelcolor; -#endif new->action_list = NULL; for (tmp = src->action_list ; tmp != NULL ; tmp = tmp->next) { @@ -285,7 +260,7 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info) return val == 0 ? TRUE : FALSE; case MATCHACTION_EXECUTE: - cmd = matching_build_command(action->unesc_destination, info); + cmd = matching_build_command(action->destination, info); if (cmd == NULL) return FALSE; else { @@ -388,10 +363,6 @@ static gboolean filter_msginfo(GSList * filtering_list, MsgInfo * info) if (filtering_match_condition(filtering, info)) { applied = filtering_apply_rule(filtering, info, &final); -#if 0 - if (TRUE == (final = filtering_is_final_action(filtering))) - break; -#endif if (final) break; } @@ -414,7 +385,8 @@ gboolean filter_message_by_msginfo(GSList *flist, MsgInfo *info) gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *action) { const gchar *command_str; - + gchar * quoted_dest; + command_str = get_matchparser_tab_str(action->type); if (command_str == NULL) @@ -424,7 +396,9 @@ gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *act case MATCHACTION_MOVE: case MATCHACTION_COPY: case MATCHACTION_EXECUTE: - g_snprintf(dest, destlen, "%s \"%s\"", command_str, action->destination); + quoted_dest = matcher_quote_str(action->destination); + g_snprintf(dest, destlen, "%s \"%s\"", command_str, quoted_dest); + g_free(quoted_dest); return dest; case MATCHACTION_DELETE: @@ -442,7 +416,9 @@ gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *act case MATCHACTION_REDIRECT: case MATCHACTION_FORWARD: case MATCHACTION_FORWARD_AS_ATTACHMENT: - g_snprintf(dest, destlen, "%s %d \"%s\"", command_str, action->account_id, action->destination); + quoted_dest = matcher_quote_str(action->destination); + g_snprintf(dest, destlen, "%s %d \"%s\"", command_str, action->account_id, quoted_dest); + g_free(quoted_dest); return dest; case MATCHACTION_COLOR: diff --git a/src/filtering.h b/src/filtering.h index 61425b6cc..f604686c4 100644 --- a/src/filtering.h +++ b/src/filtering.h @@ -29,7 +29,6 @@ struct _FilteringAction { gint type; gint account_id; gchar *destination; - gchar *unesc_destination; /* for exec cmd line */ gint labelcolor; gint score; }; diff --git a/src/matcher.c b/src/matcher.c index edaffe14f..1d4325dae 100644 --- a/src/matcher.c +++ b/src/matcher.c @@ -28,6 +28,7 @@ #include "intl.h" #include "matcher_parser.h" #include "prefs_gtk.h" +#include /*! *\brief Keyword lookup element @@ -193,6 +194,7 @@ gint get_matchparser_tab_id(const gchar *str) * *\return gchar * Newly allocated string with escaped characters */ +#if 0 gchar *matcher_escape_str(const gchar *str) { register const gchar *walk; @@ -220,6 +222,7 @@ gchar *matcher_escape_str(const gchar *str) *reswalk = 0; return res; } +#endif /*! *\brief Unescape string by replacing escaped char sequences @@ -233,6 +236,7 @@ gchar *matcher_escape_str(const gchar *str) * *\return gchar * Pointer to changed buffer */ +#if 0 gchar *matcher_unescape_str(gchar *str) { gchar *tmp = alloca(strlen(str) + 1); @@ -271,6 +275,7 @@ gchar *matcher_unescape_str(gchar *str) *dst = 0; return str; } +#endif /* **************** data structure allocation **************** */ @@ -360,6 +365,7 @@ MatcherProp *matcherprop_copy(const MatcherProp *src) *\return MatcherProp * Pointer to newly allocated matcher * structure */ +#if 0 MatcherProp *matcherprop_unquote_new(gint criteria, const gchar *header, gint matchtype, const gchar *expr, int value) @@ -379,7 +385,7 @@ MatcherProp *matcherprop_unquote_new(gint criteria, const gchar *header, return prop; } - +#endif /* ************** match ******************************/ @@ -1060,6 +1066,68 @@ gboolean matcherlist_match(MatcherList *matchers, MsgInfo *info) return result; } + +static gint quote_filter_str(gchar * result, guint size, + const gchar * path) +{ + const gchar * p; + gchar * result_p; + guint remaining; + + result_p = result; + remaining = size; + + for(p = path ; * p != '\0' ; p ++) { + + if ((* p != '\"') || (* p != '\\')) { + if (remaining > 0) { + * result_p = * p; + result_p ++; + remaining --; + } + else { + result[size - 1] = '\0'; + return -1; + } + } + else { + if (remaining >= 2) { + * result_p = '\\'; + result_p ++; + * result_p = * p; + result_p ++; + remaining -= 2; + } + else { + result[size - 1] = '\0'; + return -1; + } + } + } + if (remaining > 0) { + * result_p = '\0'; + } + else { + result[size - 1] = '\0'; + return -1; + } + + return 0; +} + + +gchar * matcher_quote_str(const gchar * src) +{ + gchar * res; + gint len; + + len = strlen(src) * 2 + 1; + res = g_malloc(len); + quote_filter_str(res, len, src); + + return res; +} + /*! *\brief Convert a matcher structure to a string * @@ -1073,8 +1141,8 @@ gchar *matcherprop_to_string(MatcherProp *matcher) const gchar *criteria_str; const gchar *matchtype_str; int i; - gchar *expr; - + gchar * quoted_expr; + criteria_str = NULL; for (i = 0; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)); i++) { if (matchparser_tab[i].id == matcher->criteria) @@ -1115,9 +1183,10 @@ gchar *matcherprop_to_string(MatcherProp *matcher) return g_strdup(criteria_str); case MATCHCRITERIA_TEST: case MATCHCRITERIA_NOT_TEST: - expr = matcher_escape_str(matcher->expr); - matcher_str = g_strdup_printf("%s \"%s\"", criteria_str, expr); - g_free((gpointer) expr); + quoted_expr = matcher_quote_str(matcher->expr); + matcher_str = g_strdup_printf("%s \"%s\"", + criteria_str, quoted_expr); + g_free(quoted_expr); return matcher_str; } @@ -1135,17 +1204,22 @@ gchar *matcherprop_to_string(MatcherProp *matcher) case MATCHTYPE_MATCHCASE: case MATCHTYPE_REGEXP: case MATCHTYPE_REGEXPCASE: - expr = matcher_escape_str(matcher->expr); - if (matcher->header) + quoted_expr = matcher_quote_str(matcher->expr); + if (matcher->header) { + gchar * quoted_header; + + quoted_header = matcher_quote_str(matcher->header); matcher_str = g_strdup_printf ("%s \"%s\" %s \"%s\"", - criteria_str, matcher->header, - matchtype_str, expr); + criteria_str, quoted_header, + matchtype_str, quoted_expr); + g_free(quoted_header); + } else matcher_str = g_strdup_printf ("%s %s \"%s\"", criteria_str, - matchtype_str, expr); - g_free((gpointer) expr); + matchtype_str, quoted_expr); + g_free(quoted_expr); break; } @@ -1190,8 +1264,27 @@ gchar *matcherlist_to_string(const MatcherList *matchers) return result; } + #define STRLEN_ZERO(s) ((s) ? strlen(s) : 0) #define STRLEN_DEFAULT(s,d) ((s) ? strlen(s) : STRLEN_ZERO(d)) + +static void add_str_default(gchar ** dest, + const gchar * s, const gchar * d) +{ + gchar quoted_str[4096]; + const gchar * str; + + if (s != NULL) + str = s; + else + str = d; + + quote_cmd_argument(quoted_str, sizeof(quoted_str), str); + strcpy(* dest, quoted_str); + + (* dest) += strlen(* dest); +} + /* matching_build_command() - preferably cmd should be unescaped */ /*! *\brief Build the command line to execute @@ -1254,21 +1347,25 @@ gchar *matching_build_command(const gchar *cmd, MsgInfo *info) size += STRLEN_DEFAULT(info->references, no_references) - 2; break; case 'F': /* file */ - filename = folder_item_fetch_msg(info->folder, - info->msgnum); + if (filename != NULL) + filename = folder_item_fetch_msg(info->folder, info->msgnum); if (filename == NULL) { g_warning("filename is not set"); return NULL; } - else + else { size += strlen(filename) - 2; + } break; } s++; } else s++; } + + /* as the string can be quoted, we double the result */ + size *= 2; processed_cmd = g_new0(gchar, size); s = cmd; @@ -1283,65 +1380,40 @@ gchar *matching_build_command(const gchar *cmd, MsgInfo *info) p++; break; case 's': /* subject */ - if (info->subject != NULL) - strcpy(p, info->subject); - else - strcpy(p, no_subject); - p += strlen(p); + add_str_default(&p, info->subject, + no_subject); break; case 'f': /* from */ - if (info->from != NULL) - strcpy(p, info->from); - else - strcpy(p, no_from); - p += strlen(p); + add_str_default(&p, info->from, + no_from); break; case 't': /* to */ - if (info->to != NULL) - strcpy(p, info->to); - else - strcpy(p, no_to); - p += strlen(p); + add_str_default(&p, info->to, + no_to); break; case 'c': /* cc */ - if (info->cc != NULL) - strcpy(p, info->cc); - else - strcpy(p, no_cc); - p += strlen(p); + add_str_default(&p, info->cc, + no_cc); break; case 'd': /* date */ - if (info->date != NULL) - strcpy(p, info->date); - else - strcpy(p, no_date); - p += strlen(p); + add_str_default(&p, info->date, + no_date); break; case 'i': /* message-id */ - if (info->msgid != NULL) - strcpy(p, info->msgid); - else - strcpy(p, no_msgid); - p += strlen(p); + add_str_default(&p, info->msgid, + no_msgid); break; case 'n': /* newsgroups */ - if (info->newsgroups != NULL) - strcpy(p, info->newsgroups); - else - strcpy(p, no_newsgroups); - p += strlen(p); + add_str_default(&p, info->newsgroups, + no_newsgroups); break; case 'r': /* references */ - if (info->references != NULL) - strcpy(p, info->references); - else - strcpy(p, no_references); - p += strlen(p); + add_str_default(&p, info->references, + no_references); break; case 'F': /* file */ - strcpy(p, filename); - p += strlen(p); - g_free(filename); + if (filename != NULL) + add_str_default(&p, filename, NULL); break; default: *p = '%'; @@ -1358,7 +1430,8 @@ gchar *matching_build_command(const gchar *cmd, MsgInfo *info) s++; } } - + g_free(filename); + return processed_cmd; } #undef STRLEN_DEFAULT diff --git a/src/matcher.h b/src/matcher.h index d75bfa35b..59021d4f4 100644 --- a/src/matcher.h +++ b/src/matcher.h @@ -175,4 +175,6 @@ gchar *matching_build_command (const gchar *cmd, void prefs_matcher_read_config (void); void prefs_matcher_write_config (void); +gchar * matcher_quote_str(const gchar * src); + #endif diff --git a/src/matcher_parser_lex.l b/src/matcher_parser_lex.l index 1fcdb70b7..12b421bd9 100644 --- a/src/matcher_parser_lex.l +++ b/src/matcher_parser_lex.l @@ -76,15 +76,6 @@ void matcher_parser_init(void) BEGIN(string); string_buf_ptr = string_buf; } - /* alfons - OK, the new attempt is to just swallow - * *EVERYTHING* and make sure everything is escaped - * when actually performing things. */ -\\\" { - /* take care of escaped \" because this means the - * quote char should be skipped */ - add_char('\\'); - add_char('\"'); - } \" { /* get out of the state: string ends. */ BEGIN(0); @@ -92,11 +83,15 @@ void matcher_parser_init(void) yylval.str = string_buf; return MATCHER_STRING; } - /* put everything else in the output. */ +\\. { + /* take care of quoted characters */ + add_char(yytext[1]); + } . { add_char(yytext[0]); } \[[^\[\]]*\] { + /* for section name in configuration file */ BEGIN(0); yylval.str = yytext + 1; yytext[strlen(yytext) - 1] = '\0'; diff --git a/src/matcher_parser_parse.y b/src/matcher_parser_parse.y index b11fc2d3b..c84a8bc58 100644 --- a/src/matcher_parser_parse.y +++ b/src/matcher_parser_parse.y @@ -434,105 +434,105 @@ MATCHER_ALL gint criteria = 0; criteria = MATCHCRITERIA_ALL; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_UNREAD { gint criteria = 0; criteria = MATCHCRITERIA_UNREAD; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_UNREAD { gint criteria = 0; criteria = MATCHCRITERIA_NOT_UNREAD; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NEW { gint criteria = 0; criteria = MATCHCRITERIA_NEW; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_NEW { gint criteria = 0; criteria = MATCHCRITERIA_NOT_NEW; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_MARKED { gint criteria = 0; criteria = MATCHCRITERIA_MARKED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_MARKED { gint criteria = 0; criteria = MATCHCRITERIA_NOT_MARKED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_DELETED { gint criteria = 0; criteria = MATCHCRITERIA_DELETED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_DELETED { gint criteria = 0; criteria = MATCHCRITERIA_NOT_DELETED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_REPLIED { gint criteria = 0; criteria = MATCHCRITERIA_REPLIED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_REPLIED { gint criteria = 0; criteria = MATCHCRITERIA_NOT_REPLIED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_FORWARDED { gint criteria = 0; criteria = MATCHCRITERIA_FORWARDED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_FORWARDED { gint criteria = 0; criteria = MATCHCRITERIA_NOT_FORWARDED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_LOCKED { gint criteria = 0; criteria = MATCHCRITERIA_LOCKED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_LOCKED { gint criteria = 0; criteria = MATCHCRITERIA_NOT_LOCKED; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_COLORLABEL MATCHER_INTEGER { @@ -543,7 +543,7 @@ MATCHER_ALL value = strtol($2, NULL, 10); if (value < 0) value = 0; else if (value > MAX_COLORLABELS) value = MAX_COLORLABELS; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_NOT_COLORLABEL MATCHER_INTEGER { @@ -554,21 +554,21 @@ MATCHER_ALL value = strtol($2, NULL, 0); if (value < 0) value = 0; else if (value > MAX_COLORLABELS) value = MAX_COLORLABELS; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_IGNORE_THREAD { gint criteria = 0; criteria = MATCHCRITERIA_IGNORE_THREAD; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_NOT_IGNORE_THREAD { gint criteria = 0; criteria = MATCHCRITERIA_NOT_IGNORE_THREAD; - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, 0); + prop = matcherprop_new(criteria, NULL, 0, NULL, 0); } | MATCHER_SUBJECT match_type MATCHER_STRING { @@ -577,7 +577,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_SUBJECT; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_SUBJECT match_type MATCHER_STRING { @@ -586,7 +586,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_SUBJECT; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_FROM match_type MATCHER_STRING { @@ -595,7 +595,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_FROM; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_FROM match_type MATCHER_STRING { @@ -604,7 +604,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_FROM; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_TO match_type MATCHER_STRING { @@ -613,7 +613,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_TO; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_TO match_type MATCHER_STRING { @@ -622,7 +622,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_TO; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_CC match_type MATCHER_STRING { @@ -631,7 +631,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_CC; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_CC match_type MATCHER_STRING { @@ -640,7 +640,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_CC; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_TO_OR_CC match_type MATCHER_STRING { @@ -649,7 +649,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_TO_OR_CC; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING { @@ -658,7 +658,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_AGE_GREATER MATCHER_INTEGER { @@ -667,7 +667,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_AGE_GREATER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_AGE_LOWER MATCHER_INTEGER { @@ -676,7 +676,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_AGE_LOWER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_NEWSGROUPS match_type MATCHER_STRING { @@ -685,7 +685,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NEWSGROUPS; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING { @@ -694,7 +694,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_NEWSGROUPS; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_INREPLYTO match_type MATCHER_STRING { @@ -703,7 +703,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_INREPLYTO; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING { @@ -712,7 +712,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_INREPLYTO; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_REFERENCES match_type MATCHER_STRING { @@ -721,7 +721,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_REFERENCES; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_REFERENCES match_type MATCHER_STRING { @@ -730,7 +730,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_REFERENCES; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_SCORE_GREATER MATCHER_INTEGER { @@ -739,7 +739,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_SCORE_GREATER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_SCORE_LOWER MATCHER_INTEGER { @@ -748,7 +748,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_SCORE_LOWER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_SCORE_EQUAL MATCHER_INTEGER { @@ -757,7 +757,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_SCORE_EQUAL; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_SIZE_GREATER MATCHER_INTEGER { @@ -765,7 +765,7 @@ MATCHER_ALL gint value = 0; criteria = MATCHCRITERIA_SIZE_GREATER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_SIZE_SMALLER MATCHER_INTEGER { @@ -773,7 +773,7 @@ MATCHER_ALL gint value = 0; criteria = MATCHCRITERIA_SIZE_SMALLER; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_SIZE_EQUAL MATCHER_INTEGER { @@ -781,7 +781,7 @@ MATCHER_ALL gint value = 0; criteria = MATCHCRITERIA_SIZE_EQUAL; value = strtol($2, NULL, 0); - prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); } | MATCHER_HEADER MATCHER_STRING { @@ -793,7 +793,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_HEADER; expr = $2; - prop = matcherprop_unquote_new(criteria, header, match_type, expr, 0); + prop = matcherprop_new(criteria, header, match_type, expr, 0); g_free(header); } | MATCHER_NOT_HEADER MATCHER_STRING @@ -806,7 +806,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_HEADER; expr = $2; - prop = matcherprop_unquote_new(criteria, header, match_type, expr, 0); + prop = matcherprop_new(criteria, header, match_type, expr, 0); g_free(header); } | MATCHER_HEADERS_PART match_type MATCHER_STRING @@ -816,7 +816,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_HEADERS_PART; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING { @@ -825,7 +825,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_HEADERS_PART; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_MESSAGE match_type MATCHER_STRING { @@ -834,7 +834,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_MESSAGE; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_MESSAGE match_type MATCHER_STRING { @@ -843,7 +843,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_MESSAGE; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_BODY_PART match_type MATCHER_STRING { @@ -852,7 +852,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_BODY_PART; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_NOT_BODY_PART match_type MATCHER_STRING { @@ -861,7 +861,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_BODY_PART; expr = $3; - prop = matcherprop_unquote_new(criteria, NULL, match_type, expr, 0); + prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } | MATCHER_TEST MATCHER_STRING { @@ -870,7 +870,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_TEST; expr = $2; - prop = matcherprop_unquote_new(criteria, NULL, 0, expr, 0); + prop = matcherprop_new(criteria, NULL, 0, expr, 0); } | MATCHER_NOT_TEST MATCHER_STRING { @@ -879,7 +879,7 @@ MATCHER_ALL criteria = MATCHCRITERIA_NOT_TEST; expr = $2; - prop = matcherprop_unquote_new(criteria, NULL, 0, expr, 0); + prop = matcherprop_new(criteria, NULL, 0, expr, 0); } ; diff --git a/src/messageview.c b/src/messageview.c index d0ad10b43..f70850a33 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -646,7 +646,8 @@ void messageview_show(MessageView *messageview, MsgInfo *msginfo, { gchar *file; MimeInfo *mimeinfo, *encinfo; - + MimeInfo * decrypted; + g_return_if_fail(msginfo != NULL); mimeinfo = procmime_scan_message(msginfo); @@ -654,10 +655,17 @@ void messageview_show(MessageView *messageview, MsgInfo *msginfo, while ((encinfo = find_encrypted_part(mimeinfo)) != NULL) { debug_print("decrypting message part\n"); - if (privacy_mimeinfo_decrypt(encinfo) < 0) + decrypted = privacy_mimeinfo_decrypt(encinfo); + if (decrypted == NULL) { + break; + } + else if (procmime_mimeinfo_parent(decrypted) == NULL) { + procmime_mimeinfo_free_all(mimeinfo); + mimeinfo = decrypted; break; + } } - + file = procmsg_get_message_file_path(msginfo); if (!file) { g_warning("can't get message file path.\n"); diff --git a/src/prefs_actions.c b/src/prefs_actions.c index 5068a7be7..8fc33110e 100644 --- a/src/prefs_actions.c +++ b/src/prefs_actions.c @@ -621,6 +621,7 @@ static void prefs_actions_ok(GtkWidget *widget, gpointer data) { GtkItemFactory *ifactory; MainWindow *mainwin = (MainWindow *)data; + GtkItemFactoryEntry ifentry = {NULL, NULL, NULL, 0, ""}; prefs_actions_write_config(); ifactory = gtk_item_factory_from_widget(mainwin->menubar); diff --git a/src/prefs_filtering.c b/src/prefs_filtering.c index 51db83aae..46e757f9f 100644 --- a/src/prefs_filtering.c +++ b/src/prefs_filtering.c @@ -108,8 +108,6 @@ void prefs_filtering_open(GSList ** p_processing, const gchar *header, const gchar *key) { - gchar *esckey; - if (prefs_rc_is_readonly(FILTERING_RC)) return; @@ -128,12 +126,9 @@ void prefs_filtering_open(GSList ** p_processing, gtk_window_set_title (GTK_WINDOW(filtering.window), _("Filtering/Processing configuration")); - esckey = matcher_escape_str(key); - p_processing_list = p_processing; - prefs_filtering_set_dialog(header, esckey); - g_free(esckey); + prefs_filtering_set_dialog(header, key); gtk_widget_show(filtering.window); @@ -619,9 +614,15 @@ static void prefs_filtering_set_dialog(const gchar *header, const gchar *key) prefs_filtering_reset_dialog(); if (header && key) { - gchar *match_str = g_strconcat(header, " ", - get_matchparser_tab_str(MATCHTYPE_MATCHCASE), - " \"", key, "\"", NULL); + gchar * quoted_key; + gchar *match_str; + + quoted_key = matcher_quote_str(key); + + match_str = g_strconcat(header, " ", get_matchparser_tab_str(MATCHTYPE_MATCHCASE), + " \"", quoted_key, "\"", NULL); + g_free(quoted_key); + gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), match_str); g_free(match_str); } diff --git a/src/privacy.c b/src/privacy.c index 76a3cd162..72bdc4d05 100644 --- a/src/privacy.c +++ b/src/privacy.c @@ -190,31 +190,33 @@ gboolean privacy_mimeinfo_is_encrypted(MimeInfo *mimeinfo) return FALSE; } -static gint decrypt(MimeInfo *mimeinfo, PrivacySystem *system) +static MimeInfo * decrypt(MimeInfo *mimeinfo, PrivacySystem *system) { MimeInfo *decryptedinfo, *parentinfo; gint childnumber; - g_return_val_if_fail(system->decrypt != NULL, -1); + g_return_val_if_fail(system->decrypt != NULL, NULL); decryptedinfo = system->decrypt(mimeinfo); if (decryptedinfo == NULL) - return -1; + return NULL; parentinfo = procmime_mimeinfo_parent(mimeinfo); - childnumber = g_node_child_index(parentinfo->node, mimeinfo); - - procmime_mimeinfo_free_all(mimeinfo); - - g_node_insert(parentinfo->node, childnumber, decryptedinfo->node); - - return 0; + if (parentinfo != NULL) { + childnumber = g_node_child_index(parentinfo->node, mimeinfo); + + procmime_mimeinfo_free_all(mimeinfo); + + g_node_insert(parentinfo->node, childnumber, + decryptedinfo->node); + } + return decryptedinfo; } -gint privacy_mimeinfo_decrypt(MimeInfo *mimeinfo) +MimeInfo * privacy_mimeinfo_decrypt(MimeInfo *mimeinfo) { GSList *cur; - g_return_val_if_fail(mimeinfo != NULL, FALSE); + g_return_val_if_fail(mimeinfo != NULL, NULL); for(cur = systems; cur != NULL; cur = g_slist_next(cur)) { PrivacySystem *system = (PrivacySystem *) cur->data; @@ -223,5 +225,5 @@ gint privacy_mimeinfo_decrypt(MimeInfo *mimeinfo) return decrypt(mimeinfo, system); } - return -1; + return NULL; } diff --git a/src/privacy.h b/src/privacy.h index 53891e9b9..f04f04e87 100644 --- a/src/privacy.h +++ b/src/privacy.h @@ -47,7 +47,7 @@ gchar *privacy_mimeinfo_sig_info_short (MimeInfo *); gchar *privacy_mimeinfo_sig_info_full (MimeInfo *); gboolean privacy_mimeinfo_is_encrypted (MimeInfo *); -gint privacy_mimeinfo_decrypt (MimeInfo *); +MimeInfo * privacy_mimeinfo_decrypt (MimeInfo *); struct _PrivacySystem { gchar *name; -- 2.25.1