cleaning filtering and new filtering action : bouncing
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Mon, 19 Nov 2001 22:49:13 +0000 (22:49 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Mon, 19 Nov 2001 22:49:13 +0000 (22:49 +0000)
ChangeLog.claws
configure.in
src/filtering.c
src/matcher.c
src/matcher.h
src/matcher_parser_parse.y
src/prefs_filtering.c
src/prefs_scoring.c
src/scoring.c

index 5ed35f6..027dd2b 100644 (file)
@@ -1,3 +1,15 @@
+2001-11-19 [hoa]       0.6.5claws23
+
+       * src/filtering.c
+       * src/prefs_scoring.c
+       * src/matcher.[ch]
+       * src/scoring.c
+               cleaning code
+
+       * src/matcher_parser_parse.y
+       * src/prefs_filtering.c
+               bouncing
+
 2001-11-19 [alfons]    0.6.5claws22
 
        more of my old things into claws
index cd0e82a..6e55ced 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws22
+EXTRA_VERSION=claws23
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index 3c5cbd5..fcf7f70 100644 (file)
@@ -75,111 +75,6 @@ void filteringaction_free(FilteringAction * action)
        g_free(action);
 }
 
-/*
-FilteringAction * filteringaction_parse(gchar ** str)
-{
-       FilteringAction * action;
-       gchar * tmp;
-       gchar * destination = NULL;
-       gint account_id = 0;
-       gint key;
-       gint labelcolor = 0;
-
-       tmp = * str;
-
-       key = matcher_parse_keyword(&tmp);
-
-       switch (key) {
-       case MATCHACTION_MOVE:
-       case MATCHACTION_COPY:
-       case MATCHACTION_EXECUTE:
-               destination = matcher_parse_str(&tmp);
-               if (tmp == NULL) {
-                       * str = NULL;
-                       return NULL;
-               }
-               break;
-       case MATCHACTION_DELETE:
-               break;
-       case MATCHACTION_MARK:
-               break;
-       case MATCHACTION_MARK_AS_READ:
-               break;
-       case MATCHACTION_UNMARK:
-               break;
-       case MATCHACTION_MARK_AS_UNREAD:
-               break;
-       case MATCHACTION_FORWARD:
-       case MATCHACTION_FORWARD_AS_ATTACHMENT:
-               account_id = matcher_parse_number(&tmp);
-               if (tmp == NULL) {
-                       * str = NULL;
-                       return NULL;
-               }
-
-               destination = matcher_parse_str(&tmp);
-               if (tmp == NULL) {
-                       * str = NULL;
-                       return NULL;
-               }
-
-               break;
-       case MATCHACTION_COLOR:
-               labelcolor = matcher_parse_number(&tmp);
-               if (tmp == NULL) {
-                       *str = NULL;
-                       return NULL;
-               }
-
-               break;
-       default:
-               * str = NULL;
-               return NULL;
-       }
-
-       * str = tmp;
-
-       action = filteringaction_new(key, account_id, destination, labelcolor);
-
-       return action;
-}
-
-FilteringProp * filteringprop_parse(gchar ** str)
-{
-       gchar * tmp;
-       gint key;
-       FilteringProp * filtering;
-       MatcherList * matchers;
-       FilteringAction * action;
-       
-       tmp = * str;
-
-       matchers = matcherlist_parse(&tmp);
-       if (tmp == NULL) {
-               * str = NULL;
-               return NULL;
-       }
-
-       if (tmp == NULL) {
-               matcherlist_free(matchers);
-               * str = NULL;
-               return NULL;
-       }
-
-       action = filteringaction_parse(&tmp);
-       if (tmp == NULL) {
-               matcherlist_free(matchers);
-               * str = NULL;
-               return NULL;
-       }
-
-       filtering = filteringprop_new(matchers, action);
-
-       * str = tmp;
-       return filtering;
-}
-*/
-
 FilteringProp * filteringprop_new(MatcherList * matchers,
                                  FilteringAction * action)
 {
@@ -570,6 +465,25 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                gtk_widget_destroy(compose->window);
                return FALSE;
 
+       case MATCHACTION_BOUNCE:
+
+               account = account_find_from_id(action->account_id);
+               compose = compose_bounce(account, info);
+               if (compose->account->protocol == A_NNTP)
+                       break;
+               else
+                       compose_entry_append(compose, action->destination,
+                                            COMPOSE_TO);
+
+               val = compose_send(compose);
+               if (val == 0) {
+                       gtk_widget_destroy(compose->window);
+                       return TRUE;
+               }
+
+               gtk_widget_destroy(compose->window);
+               return FALSE;
+
        case MATCHACTION_EXECUTE:
 
                cmd = matching_build_command(action->destination, info);
@@ -610,6 +524,7 @@ static gboolean filteringprop_apply(FilteringProp * filtering, MsgInfo * info,
                                               folder_table))) {
                        action_str = filteringaction_to_string(buf, sizeof buf, filtering->action);
                        g_warning(_("action %s could not be applied"), action_str);
+                       g_free(action_str);
                }
 
                switch(filtering->action->type) {
@@ -624,6 +539,7 @@ static gboolean filteringprop_apply(FilteringProp * filtering, MsgInfo * info,
                case MATCHACTION_MARK_AS_UNREAD:
                case MATCHACTION_FORWARD:
                case MATCHACTION_FORWARD_AS_ATTACHMENT:
+               case MATCHACTION_BOUNCE:
                        return FALSE; /* MsgInfo still valid for message */
                default:
                        return FALSE;
@@ -877,6 +793,7 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                /* UNCONTINUABLE */
                case MATCHACTION_FORWARD:
                case MATCHACTION_FORWARD_AS_ATTACHMENT:
+               case MATCHACTION_BOUNCE:
                case MATCHACTION_MOVE:
                case MATCHACTION_DELETE:
                        stop = TRUE;
@@ -941,7 +858,7 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                /* U N C O N T I N U A B L E */
                
                else if (MATCHACTION_FORWARD == ACTION
-               ||       MATCHACTION_FORWARD_AS_ATTACHMENT == ACTION) {
+                        || MATCHACTION_FORWARD_AS_ATTACHMENT == ACTION) {
                        debug_print("*** performing forward\n");
 
                        /* forwarding messages is complicated because there's currently no 
@@ -984,6 +901,37 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                        gtk_widget_destroy(compose->window);
                        break;
                }                       
+               else if (MATCHACTION_BOUNCE == ACTION) {
+                       if (0 > (msgnum = folder_item_add_msg(default_folder, filename, FALSE))) {
+                               debug_print(_("Rule failed: could not forward\n"));
+                               copy_to_inbox_too = TRUE;
+                               continue;
+                       }
+                               
+                       /* grab the dropped message */
+                       fwd_msg_name = folder_item_fetch_msg(default_folder, msgnum);
+
+                       fwd_msg = procheader_parse(fwd_msg_name, tmp, TRUE);
+
+                       fwd_msg->folder = default_folder;
+                       fwd_msg->msgnum = msgnum;
+
+                       /* do the compose_XXX stuff */
+                       account = account_find_from_id(ma_tail->action->account_id);
+                       compose = compose_bounce(account, fwd_msg);
+                       if (compose->account->protocol == A_NNTP)
+                               break;
+                       else
+                               compose_entry_append(compose, ma_tail->action->destination,
+                                                    COMPOSE_TO);
+
+                       compose_send(compose);
+
+                       procmsg_msginfo_free(fwd_msg);
+                       
+                       gtk_widget_destroy(compose->window);
+                       break;
+               }                       
                else if (MATCHACTION_DELETE == ACTION) {
                        debug_print("*** performing delete\n");
                        copy_to_inbox_too = FALSE;
@@ -1085,62 +1033,6 @@ void filter_incoming_message(FolderItem *default_folder, const gchar *file_name,
 
 
 
-/*
-void prefs_filtering_read_config(void)
-{
-
-       gchar *rcpath;
-       FILE *fp;
-       gchar buf[PREFSBUFSIZE];
-
-       debug_print(_("Reading filtering configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-                            FILTERING_RC, NULL);
-       if ((fp = fopen(rcpath, "r")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
-               g_free(rcpath);
-               prefs_filtering = NULL;
-               return;
-       }
-       g_free(rcpath);
-       */
-       /* remove all filtering */
-       /*
-       while (prefs_filtering != NULL) {
-               FilteringProp * filtering =
-                       (FilteringProp *) prefs_filtering->data;
-               filteringprop_free(filtering);
-               prefs_filtering = g_slist_remove(prefs_filtering, filtering);
-       }
-
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               FilteringProp * filtering;
-               gchar * tmp;
-
-               g_strchomp(buf);
-
-               if ((*buf != '#') && (*buf != '\0')) {
-                       tmp = buf;
-                       filtering = filteringprop_parse(&tmp);
-                       if (tmp != NULL) {
-                               prefs_filtering =
-                                       g_slist_append(prefs_filtering,
-                                                      filtering);
-                       }
-                       else {
-       */
-                               /* debug */
-       /*
-                               g_warning(_("syntax error : %s\n"), buf);
-                       }
-               }
-       }
-
-       fclose(fp);
-}
-*/
-
 gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *action)
 {
        gchar *command_str;
@@ -1165,6 +1057,7 @@ gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *act
                g_snprintf(dest, destlen, "%s", command_str);
                return dest;
 
+       case MATCHACTION_BOUNCE:
        case MATCHACTION_FORWARD:
        case MATCHACTION_FORWARD_AS_ATTACHMENT:
                g_snprintf(dest, destlen, "%s %d \"%s\"", command_str, action->account_id, action->destination); 
@@ -1174,6 +1067,10 @@ gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *act
                g_snprintf(dest, destlen, "%s %d", command_str, action->labelcolor);
                return dest;  
 
+               g_snprintf(dest, destlen, "%s %d \"%s\"", command_str,
+                          action->account_id, action->destination);
+               return dest;
+
        default:
                return NULL;
        }
@@ -1202,50 +1099,6 @@ gchar * filteringprop_to_string(FilteringProp * prop)
        return filtering_str;
 }
 
-void prefs_filtering_write_config(void)
-{
-       /*
-       gchar *rcpath;
-       PrefFile *pfile;
-       GSList *cur;
-       FilteringProp * prop;
-
-       debug_print(_("Writing filtering configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTERING_RC, NULL);
-
-       if ((pfile = prefs_write_open(rcpath)) == NULL) {
-               g_warning(_("failed to write configuration to file\n"));
-               g_free(rcpath);
-               return;
-       }
-
-       for (cur = global_processing; cur != NULL; cur = cur->next) {
-               gchar *filtering_str;
-
-               prop = (FilteringProp *) cur->data;
-               filtering_str = filteringprop_to_string(prop);
-               
-               if (fputs(filtering_str, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
-                       g_free(rcpath);
-                       g_free(filtering_str);
-                       return;
-               }
-               g_free(filtering_str);
-       }
-
-       g_free(rcpath);
-
-       if (prefs_write_close(pfile) < 0) {
-               g_warning(_("failed to write configuration to file\n"));
-               return;
-       }
-       */
-}
-
 void prefs_filtering_free(GSList * prefs_filtering)
 {
        while (prefs_filtering != NULL) {
index 3742204..0b64105 100644 (file)
@@ -117,344 +117,28 @@ static MatchParser matchparser_tab[] = {
        {MATCHACTION_BOUNCE, "bounce"}
 };
 
-gchar * get_matchparser_tab_str(gint id)
-{
-       gint i;
-
-       for(i = 0 ; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)) ;
-           i++) {
-               if (matchparser_tab[i].id == id)
-                       return matchparser_tab[i].str;
-       }
-       return NULL;
-}
-
-
-
 /*
   syntax for matcher
 
-  header "x-mailing" match "toto"
-  subject match "regexp" & to regexp "regexp"
-  subject match "regexp" | to regexpcase "regexp" | age_sup 5
- */
-
-#if 0
-static gboolean matcher_is_blank(gchar ch);
-
-/* ******************* parser *********************** */
-
-static gboolean matcher_is_blank(gchar ch)
-{
-       return (ch == ' ') || (ch == '\t');
-}
-
-/* parse for one condition */
-
-MatcherProp * matcherprop_parse(gchar ** str)
-{
-       MatcherProp * prop;
-       gchar * tmp;
-       gint key;
-       gint value;
-       gchar * expr;
-       gint match;
-       gchar * header = NULL;
-       
-       tmp = * str;
-       key = matcher_parse_keyword(&tmp);
-       if (tmp == NULL) {
-               * str = NULL;
-               return NULL;
-       }
-
-       switch (key) {
-       case MATCHCRITERIA_AGE_LOWER:
-       case MATCHCRITERIA_AGE_GREATER:
-       case MATCHCRITERIA_SCORE_LOWER:
-       case MATCHCRITERIA_SCORE_GREATER:
-       case MATCHCRITERIA_SCORE_EQUAL:
-               value = matcher_parse_number(&tmp);
-               if (tmp == NULL) {
-                       * str = NULL;
-                       return NULL;
-               }
-               *str = tmp;
-
-               prop = matcherprop_new(key, NULL, 0, NULL, value);
-
-               return prop;
-
-       case MATCHCRITERIA_ALL:
-       case MATCHCRITERIA_UNREAD:
-       case MATCHCRITERIA_NOT_UNREAD:
-       case MATCHCRITERIA_NEW:
-       case MATCHCRITERIA_NOT_NEW:
-       case MATCHCRITERIA_MARKED:
-       case MATCHCRITERIA_NOT_MARKED:
-       case MATCHCRITERIA_DELETED:
-       case MATCHCRITERIA_NOT_DELETED:
-       case MATCHCRITERIA_REPLIED:
-       case MATCHCRITERIA_NOT_REPLIED:
-       case MATCHCRITERIA_FORWARDED:
-       case MATCHCRITERIA_NOT_FORWARDED:
-               prop = matcherprop_new(key, NULL, 0, NULL, 0);
-               *str = tmp;
-
-               return prop;
+  header "x-mailing" match "toto" score -10
+  subject match "regexp" & to regexp "regexp" score 50
+  subject match "regexp" | to regexpcase "regexp" | age_sup 5 score 30
 
-       case MATCHCRITERIA_SUBJECT:
-       case MATCHCRITERIA_NOT_SUBJECT:
-       case MATCHCRITERIA_FROM:
-       case MATCHCRITERIA_NOT_FROM:
-       case MATCHCRITERIA_TO:
-       case MATCHCRITERIA_NOT_TO:
-       case MATCHCRITERIA_CC:
-       case MATCHCRITERIA_NOT_CC:
-       case MATCHCRITERIA_TO_OR_CC:
-       case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
-       case MATCHCRITERIA_NEWSGROUPS:
-       case MATCHCRITERIA_NOT_NEWSGROUPS:
-       case MATCHCRITERIA_INREPLYTO:
-       case MATCHCRITERIA_NOT_REFERENCES:
-       case MATCHCRITERIA_REFERENCES:
-       case MATCHCRITERIA_NOT_INREPLYTO:
-       case MATCHCRITERIA_MESSAGE:
-       case MATCHCRITERIA_NOT_MESSAGE:
-       case MATCHCRITERIA_EXECUTE:
-       case MATCHCRITERIA_NOT_EXECUTE:
-       case MATCHCRITERIA_HEADERS_PART:
-       case MATCHCRITERIA_NOT_HEADERS_PART:
-       case MATCHCRITERIA_BODY_PART:
-       case MATCHCRITERIA_NOT_BODY_PART:
-       case MATCHCRITERIA_HEADER:
-       case MATCHCRITERIA_NOT_HEADER:
-               if ((key == MATCHCRITERIA_HEADER) || (key == MATCHCRITERIA_NOT_HEADER)) {
-                       header = matcher_parse_str(&tmp);
-                       if (tmp == NULL) {
-                               * str = NULL;
-                               return NULL;
-                       }
-               }
-
-               match = matcher_parse_keyword(&tmp);
-               if (tmp == NULL) {
-                       if (header)
-                               g_free(header);
-                       * str = NULL;
-                       return NULL;
-               }
-
-               switch(match) {
-               case MATCHCRITERIA_REGEXP:
-               case MATCHCRITERIA_REGEXPCASE:
-                       expr = matcher_parse_regexp(&tmp);
-                       if (tmp == NULL) {
-                               if (header)
-                                       g_free(header);
-                               * str = NULL;
-                               return NULL;
-                       }
-                       *str = tmp;
-                       prop = matcherprop_new(key, header, match, expr, 0);
-                       g_free(expr);
-
-                       return prop;
-               case MATCHCRITERIA_MATCH:
-               case MATCHCRITERIA_MATCHCASE:
-                       expr = matcher_parse_str(&tmp);
-                       if (tmp == NULL) {
-                               if (header)
-                                       g_free(header);
-                               * str = NULL;
-                               return NULL;
-                       }
-                       *str = tmp;
-                       prop = matcherprop_new(key, header, match, expr, 0);
-                       g_free(expr);
-
-                       return prop;
-               default:
-                       if (header)
-                               g_free(header);
-                       * str = NULL;
-                       return NULL;
-               }
-       default:
-               * str = NULL;
-               return NULL;
-       }
-}
+*/
 
-gint matcher_parse_keyword(gchar ** str)
+gchar * get_matchparser_tab_str(gint id)
 {
-       gchar * p;
-       gchar * dup;
-       gchar * start;
        gint i;
-       gint match;
-
-       dup = alloca(strlen(* str) + 1);
-       p = dup;
-       strcpy(dup, * str);
-
-       while (matcher_is_blank(*p))
-               p++;
-
-       start = p;
 
-       while (!matcher_is_blank(*p) && (*p != '\0'))
-               p++;
-       
-       match = -1;
        for(i = 0 ; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)) ;
            i++) {
-               if ((strlen(matchparser_tab[i].str) == p - start) &&
-                   (strncasecmp(matchparser_tab[i].str, start,
-                                p - start) == 0)) {
-                               match = i;
-                               break;
-                       }
-       }
-
-       if (match == -1) {
-               * str = NULL;
-               return 0;
-       }
-
-       *p = '\0';
-
-       *str += p - dup + 1;
-       return matchparser_tab[match].id;
-}
-
-gint matcher_parse_number(gchar ** str)
-{
-       gchar * p;
-       gchar * dup;
-       gchar * start;
-
-       dup = alloca(strlen(* str) + 1);
-       p = dup;
-       strcpy(dup, * str);
-
-       while (matcher_is_blank(*p))
-               p++;
-
-       start = p;
-
-       if (!isdigit(*p) && *p != '-' && *p != '+') {
-               *str = NULL;
-               return 0;
-       }
-       if (*p == '-' || *p == '+')
-               p++;
-       while (isdigit(*p))
-               p++;
-
-       *p = '\0';
-
-       *str += p - dup + 1;
-       return atoi(start);
-}
-
-gboolean matcher_parse_boolean_op(gchar ** str)
-{
-       gchar * p;
-
-       p = * str;
-
-       while (matcher_is_blank(*p))
-               p++;
-
-       if (*p == '|') {
-               *str += p - * str + 1;
-               return FALSE;
-       }
-       else if (*p == '&') {
-               *str += p - * str + 1;
-               return TRUE;
-       }
-       else {
-               *str = NULL;
-               return FALSE;
-       }
-}
-
-gchar * matcher_parse_regexp(gchar ** str)
-{
-       gchar * p;
-       gchar * dup;
-       gchar * start;
-
-       dup = alloca(strlen(* str) + 1);
-       p = dup;
-       strcpy(dup, * str);
-
-       while (matcher_is_blank(*p))
-               p++;
-
-       if (*p != '/') {
-               * str = NULL;
-               return NULL;
-       }
-
-       p ++;
-       start = p;
-       while (*p != '/') {
-               if (*p == '\\')
-                       p++;
-               p++;
+               if (matchparser_tab[i].id == id)
+                       return matchparser_tab[i].str;
        }
-       *p = '\0';
-
-       *str += p - dup + 2;
-       return g_strdup(start);
+       return NULL;
 }
-#endif
-
-/* matcher_parse_str() - parses a string until it hits a 
- * terminating \". to unescape characters use \. The string
- * should not be used directly: matcher_unescape_str() 
- * returns a string that can be used directly. */
-#if 0
-gchar * matcher_parse_str(gchar ** str)
-{
-       gchar * p;
-       gchar * dup;
-       gchar * start;
-       gchar * dest;
-
-       dup = alloca(strlen(* str) + 1);
-       p = dup;
-       strcpy(dup, * str);
 
-       while (matcher_is_blank(*p))
-               p++;
 
-       if (*p != '"') {
-               * str = NULL;
-               return NULL;
-       }
-       
-       p ++;
-       start = p;
-       dest = p;
-
-       for ( ; *p && *p != '\"'; p++, dest++) {
-               if (*p == '\\') {
-                       *dest++ = *p++;
-                       *dest = *p;
-               }
-               else 
-                       *dest = *p;
-       }
-       *dest = '\0';
-       
-       *str += dest - dup + 2;
-       return g_strdup(start);
-}
-#endif
 
 gchar *matcher_unescape_str(gchar *str)
 {
@@ -679,63 +363,6 @@ gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info)
 /* ********************* MatcherList *************************** */
 
 
-/* parse for a list of conditions */
-
-/*
-MatcherList * matcherlist_parse(gchar ** str)
-{
-       gchar * tmp;
-       MatcherProp * matcher;
-       GSList * matchers_list = NULL;
-       gboolean bool_and = TRUE;
-       gchar * save;
-       MatcherList * cond;
-       gboolean main_bool_and = TRUE;
-       GSList * l;
-
-       tmp = * str;
-
-       matcher = matcherprop_parse(&tmp);
-
-       if (tmp == NULL) {
-               * str = NULL;
-               return NULL;
-       }
-       matchers_list = g_slist_append(matchers_list, matcher);
-       while (matcher) {
-               save = tmp;
-               bool_and = matcher_parse_boolean_op(&tmp);
-               if (tmp == NULL) {
-                       tmp = save;
-                       matcher = NULL;
-               }
-               else {
-                       main_bool_and = bool_and;
-                       matcher = matcherprop_parse(&tmp);
-                       if (tmp != NULL) {
-                               matchers_list =
-                                       g_slist_append(matchers_list, matcher);
-                       }
-                       else {
-                               for(l = matchers_list ; l != NULL ;
-                                   l = g_slist_next(l))
-                                       matcherprop_free((MatcherProp *)
-                                                        l->data);
-                               g_slist_free(matchers_list);
-                               * str = NULL;
-                               return NULL;
-                       }
-               }
-       }
-
-       cond = matcherlist_new(matchers_list, main_bool_and);
-
-       * str = tmp;
-
-       return cond;
-}
-*/
-
 MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and)
 {
        MatcherList * cond;
@@ -1129,46 +756,6 @@ gboolean matcherlist_match(MatcherList * matchers, MsgInfo * info)
        return result;
 }
 
-#if 0
-static void matcherprop_print(MatcherProp * matcher)
-{
-  int i;
-
-       if (matcher == NULL) {
-               printf("no matcher\n");
-               return;
-       }
-
-       switch (matcher->matchtype) {
-       case MATCHCRITERIA_MATCH:
-               printf("match\n");
-               break;
-       case MATCHCRITERIA_REGEXP:
-               printf("regexp\n");
-               break;
-       case MATCHCRITERIA_MATCHCASE:
-               printf("matchcase\n");
-               break;
-       case MATCHCRITERIA_REGEXPCASE:
-               printf("regexpcase\n");
-               break;
-       }
-
-       for(i = 0 ; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)) ;
-           i++) {
-               if (matchparser_tab[i].id == matcher->criteria)
-                       printf("%s\n", matchparser_tab[i].str);
-       }
-
-       if (matcher->expr)
-               printf("expr : %s\n", matcher->expr);
-
-       printf("age: %i\n", matcher->value;
-
-       printf("compiled : %s\n", matcher->preg != NULL ? "yes" : "no");
-       printf("error: %i\n",  matcher->error);
-}
-#endif
 
 gchar * matcherprop_to_string(MatcherProp * matcher)
 {
@@ -1227,6 +814,8 @@ gchar * matcherprop_to_string(MatcherProp * matcher)
        switch (matcher->matchtype) {
        case MATCHTYPE_MATCH:
        case MATCHTYPE_MATCHCASE:
+       case MATCHTYPE_REGEXP:
+       case MATCHTYPE_REGEXPCASE:
                count = 0;
                for(p = matcher->expr; *p != 0 ; p++)
                        if (*p == '\"') count ++;
@@ -1257,6 +846,7 @@ gchar * matcherprop_to_string(MatcherProp * matcher)
                
                break;
 
+               /*
        case MATCHTYPE_REGEXP:
        case MATCHTYPE_REGEXPCASE:
 
@@ -1271,6 +861,7 @@ gchar * matcherprop_to_string(MatcherProp * matcher)
                                                matchtype_str, matcher->expr);
 
                break;
+               */
        }
 
        return matcher_str;
index 50f6fac..f342c8b 100644 (file)
@@ -77,81 +77,6 @@ enum {
        MATCHERBOOL_AND,
 };
 
-#if 0
-enum {
-       /* msginfo flags */
-       MATCHING_ALL,
-       MATCHING_UNREAD,
-       MATCHING_NOT_UNREAD,
-       MATCHING_NEW,
-       MATCHING_NOT_NEW,
-       MATCHING_MARKED,
-       MATCHING_NOT_MARKED,
-       MATCHING_DELETED,
-       MATCHING_NOT_DELETED,
-       MATCHING_REPLIED,
-       MATCHING_NOT_REPLIED,
-       MATCHING_FORWARDED,
-       MATCHING_NOT_FORWARDED,
-
-       /* msginfo headers */
-       MATCHING_SUBJECT,
-       MATCHING_NOT_SUBJECT,
-       MATCHING_FROM,
-       MATCHING_NOT_FROM,
-       MATCHING_TO,
-       MATCHING_NOT_TO,
-       MATCHING_CC,
-       MATCHING_NOT_CC,
-       MATCHING_TO_OR_CC,
-       MATCHING_NOT_TO_AND_NOT_CC,
-       MATCHING_AGE_GREATER,
-       MATCHING_AGE_LOWER,
-       MATCHING_NEWSGROUPS,
-       MATCHING_NOT_NEWSGROUPS,
-       MATCHING_INREPLYTO,
-       MATCHING_NOT_INREPLYTO,
-       MATCHING_REFERENCES,
-       MATCHING_NOT_REFERENCES,
-       MATCHING_SCORE_GREATER,
-       MATCHING_SCORE_LOWER,
-       MATCHING_SCORE_EQUAL,
-
-       /* file content */
-       MATCHING_HEADER,
-       MATCHING_NOT_HEADER,
-       MATCHING_MESSAGE,
-       MATCHING_NOT_MESSAGE,
-       MATCHING_HEADERS_PART,
-       MATCHING_NOT_HEADERS_PART,
-       MATCHING_BODY_PART,
-       MATCHING_NOT_BODY_PART,
-       MATCHING_EXECUTE,
-       MATCHING_NOT_EXECUTE,
-
-       /* scoring */
-       MATCHING_SCORE,
-
-       /* filtering */
-       MATCHING_ACTION_MOVE,
-       MATCHING_ACTION_COPY,
-       MATCHING_ACTION_DELETE,
-       MATCHING_ACTION_MARK,
-       MATCHING_ACTION_MARK_AS_READ,
-       MATCHING_ACTION_UNMARK,
-       MATCHING_ACTION_MARK_AS_UNREAD,
-       MATCHING_ACTION_FORWARD,
-       MATCHING_ACTION_FORWARD_AS_ATTACHMENT,
-       MATCHING_ACTION_COLOR,
-       /* MATCHING_ACTION_EXECUTE, */
-
-       MATCHING_MATCH,
-       MATCHING_REGEXP,
-       MATCHING_MATCHCASE,
-       MATCHING_REGEXPCASE
-};
-#endif
-
 gchar * get_matchparser_tab_str(gint id);
 MatcherProp * matcherprop_new(gint criteria, gchar * header,
                              gint matchtype, gchar * expr,
index 979a544..55ac707 100644 (file)
@@ -784,6 +784,17 @@ MATCHER_EXECUTE MATCHER_STRING
        destination = $3;
        action = filteringaction_new(action_type, account_id, destination, 0);
 }
+| MATCHER_BOUNCE MATCHER_INTEGER MATCHER_STRING
+{
+       gchar * destination = NULL;
+       gint action_type = 0;
+       gint account_id = 0;
+
+       action_type = MATCHACTION_BOUNCE;
+       account_id = $2;
+       destination = $3;
+       action = filteringaction_new(action_type, account_id, destination, 0);
+}
 | MATCHER_COLOR MATCHER_INTEGER
 {
        gint action_type = 0;
index 9b728c0..ec53221 100644 (file)
@@ -127,7 +127,8 @@ enum {
        ACTION_FORWARD = 7,
        ACTION_FORWARD_AS_ATTACHMENT = 8,
        ACTION_EXECUTE = 9,
-       ACTION_COLOR = 10
+       ACTION_COLOR = 10,
+       ACTION_BOUNCE = 11
 };
 
 static gint get_sel_from_list(GtkList * list)
@@ -221,6 +222,7 @@ static gchar * action_text [] = {
        N_("Mark as unread"),
        N_("Forward"), 
        N_("Forward as attachment"), 
+       N_("Bounce"), 
        N_("Execute"),
        N_("Color")
 };
@@ -773,6 +775,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        case ACTION_COPY:
        case ACTION_FORWARD:
        case ACTION_FORWARD_AS_ATTACHMENT:
+       case ACTION_BOUNCE:
        case ACTION_EXECUTE:
                destination = gtk_entry_get_text(GTK_ENTRY(filtering.dest_entry));
                if (*destination == '\0') {
@@ -792,7 +795,6 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        
        action = filteringaction_new(action_type, account_id, destination, labelcolor);
 
-       /* tmp = cond_str; */
        cond = matcher_parser_get_cond(cond_str);
 
        if (cond == NULL) {
@@ -958,6 +960,13 @@ static void prefs_filtering_select_set(FilteringProp * prop)
                gtk_list_select_item(GTK_LIST(filtering.account_list),
                                     list_id);
                break;
+       case MATCHACTION_BOUNCE:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_BOUNCE);
+               list_id = get_list_id_from_account_id(action->account_id);
+               gtk_list_select_item(GTK_LIST(filtering.account_list),
+                                    list_id);
+               break;
        case MATCHACTION_EXECUTE:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_EXECUTE);
@@ -988,7 +997,6 @@ static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
                                row, 0, &filtering_str))
                return;
        
-       /* tmp = filtering_str; */
        prop = matcher_parser_get_filtering(filtering_str);
        if (prop == NULL)
                return;
@@ -1141,6 +1149,17 @@ static void prefs_filtering_action_select(GtkList *list,
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
+       case ACTION_BOUNCE:
+               gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_show(filtering.dest_entry);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_label);
+               gtk_widget_hide(filtering.exec_label);
+               gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
+               break;
        case ACTION_EXECUTE:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
@@ -1184,18 +1203,12 @@ static void prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
 static void prefs_filtering_ok(void)
 {
        prefs_filtering_set_list();
-       /*
-       prefs_filtering_write_config();
-       */
        prefs_matcher_write_config();
        prefs_filtering_close();
 }
 
 static void prefs_filtering_cancel(void)
 {
-       /*
-       prefs_filtering_read_config();
-       */
        prefs_matcher_read_config();
        prefs_filtering_close();
 }
index b1d2ec7..dfd0226 100644 (file)
@@ -454,7 +454,6 @@ static void prefs_scoring_set_list(void)
        while (gtk_clist_get_text(GTK_CLIST(scoring.cond_clist),
                                  row, 0, &scoring_str)) {
                if (strcmp(scoring_str, _("(New)")) != 0) {
-                       /* tmp = scoring_str; */
                        prop = matcher_parser_get_scoring(scoring_str);
                        if (prop != NULL)
                                prefs_scoring = g_slist_append(prefs_scoring,
@@ -529,7 +528,6 @@ static void prefs_scoring_condition_define(void)
        if (*cond_str != '\0') {
                gchar * tmp;
                
-               /* tmp = cond_str; */
                matchers = matcher_parser_get_cond(cond_str);
                if (matchers == NULL)
                        alertpanel_error(_("Match string is not valid."));
@@ -566,7 +564,6 @@ static void prefs_scoring_register_cb(void)
        }
 
        score = atoi(score_str);
-       /* tmp = cond_str; */
        cond = matcher_parser_get_cond(cond_str);
 
        if (cond == NULL) {
@@ -612,7 +609,6 @@ static void prefs_scoring_substitute_cb(void)
        }
 
        score = atoi(score_str);
-       /* tmp = cond_str; */
        cond = matcher_parser_get_cond(cond_str);
 
        if (cond == NULL) {
@@ -717,7 +713,6 @@ static void prefs_scoring_select(GtkCList *clist, gint row, gint column,
                                row, 0, &scoring_str))
                return;
 
-       /* tmp = scoring_str; */
        prop = matcher_parser_get_scoring(scoring_str);
        if (prop == NULL)
                return;
index 6f075a3..2101527 100644 (file)
 
 GSList * global_scoring = NULL;
 
-#if 0
-ScoringProp * scoringprop_parse(gchar ** str)
-{
-       gchar * tmp;
-       gint key;
-       ScoringProp * scoring;
-       gint score;
-       MatcherList * matchers;
-
-       tmp = * str;
-
-       matchers = matcherlist_parse(&tmp);
-       if (tmp == NULL) {
-               * str = NULL;
-               return NULL;
-       }
-
-       key = matcher_parse_keyword(&tmp);
-
-       if (tmp == NULL) {
-               matcherlist_free(matchers);
-               * str = NULL;
-               return NULL;
-       }
-
-       if (key != MATCHACTION_SCORE) {
-               matcherlist_free(matchers);
-               * str = NULL;
-               return NULL;
-       }
-
-       score = matcher_parse_number(&tmp);
-
-       if (tmp == NULL) {
-               matcherlist_free(matchers);
-               * str = NULL;
-               return NULL;
-       }
-
-       scoring = scoringprop_new(matchers, score);
-
-       * str = tmp;
-       return scoring;
-}
-#endif
-
 ScoringProp * scoringprop_new(MatcherList * matchers, int score)
 {
        ScoringProp * scoring;
@@ -107,25 +61,6 @@ gint score_message(GSList * scoring_list, MsgInfo * info)
        return score;
 }
 
-#if 0
-static void scoringprop_print(ScoringProp * prop)
-{
-       GSList * l;
-
-       if (prop == NULL) {
-               printf("no scoring\n");
-               return;
-       }
-
-       printf("----- scoring ------\n");
-       for(l = prop->matchers ; l != NULL ; l = g_slist_next(l)) {
-               matcherprop_print((MatcherProp *) l->data);
-       }
-       printf("cond: %s\n", prop->bool_and ? "and" : "or");
-       printf("score: %i\n", prop->score);
-}
-#endif
-
 /*
   syntax for scoring config
 
@@ -158,170 +93,6 @@ gchar * scoringprop_to_string(ScoringProp * prop)
        return scoring_str;
 }
 
-
-void prefs_scoring_read_config(void)
-{
-       /*
-       gchar *rcpath;
-       FILE *fp;
-       gchar buf[PREFSBUFSIZE];
-       GSList * prefs_scoring = NULL;
-       FolderItem * item = NULL;
-
-       debug_print(_("Reading headers configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, SCORING_RC, NULL);
-       if ((fp = fopen(rcpath, "r")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
-               g_free(rcpath);
-               prefs_scoring = NULL;
-               return;
-       }
-       g_free(rcpath);
-
-       prefs_scoring_clear();
-
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               ScoringProp * scoring;
-               gchar * tmp;
-
-               g_strchomp(buf);
-
-               if (g_strcasecmp(buf, "[global]") == 0) {
-                       if (item != NULL) {
-                               item->prefs->scoring = prefs_scoring;
-                               item = NULL;
-                               prefs_scoring = global_scoring;
-                       }
-               }
-               else if ((*buf == '[') && buf[strlen(buf) - 1] == ']') {
-                       gchar * id;
-
-                       if (item == NULL)
-                               global_scoring = prefs_scoring;
-                       else
-                               item->prefs->scoring = prefs_scoring;
-
-                       id = buf + 1;
-                       id[strlen(id) - 1] = '\0';
-
-                       item = folder_find_item_from_identifier(id);
-                       if (item == NULL)
-                               prefs_scoring = global_scoring;
-                       else
-                               prefs_scoring = item->prefs->scoring;
-               }
-               else if ((*buf != '#') && (*buf != '\0')) {
-                       tmp = buf;
-                       scoring = scoringprop_parse(&tmp);
-                       if (tmp != NULL) {
-                               prefs_scoring = g_slist_append(prefs_scoring,
-                                                              scoring);
-                       }
-                       else {
-                               g_warning(_("syntax error : %s\n"), buf);
-                       }
-               }
-       }
-
-       if (item == NULL)
-               global_scoring = prefs_scoring;
-       else
-               item->prefs->scoring = prefs_scoring;
-
-       fclose(fp);
-       */
-}
-
-/*
-static void prefs_scoring_write(FILE * fp, GSList * prefs_scoring)
-{
-       GSList * cur;
-
-       for (cur = prefs_scoring; cur != NULL; cur = cur->next) {
-               gchar *scoring_str;
-               ScoringProp * prop;
-
-               prop = (ScoringProp *) cur->data;
-               scoring_str = scoringprop_to_string(prop);
-               if (fputs(scoring_str, fp) == EOF ||
-                   fputc('\n', fp) == EOF) {
-                       FILE_OP_ERROR("scoring config", "fputs || fputc");
-                       g_free(scoring_str);
-                       return;
-               }
-               g_free(scoring_str);
-       }
-}
-
-static gboolean prefs_scoring_write_func(GNode *node, gpointer data)
-{
-       FolderItem *item = node->data;
-       FILE * fp = data;
-
-       if (item->prefs->scoring != NULL) {
-               gchar * id = folder_item_get_identifier(item);
-
-               fprintf(fp, "[%s]\n", id);
-               g_free(id);
-
-               prefs_scoring_write(fp, item->prefs->scoring);
-
-               fputc('\n', fp);
-       }
-
-       return FALSE;
-}
-
-static void prefs_scoring_save(FILE * fp)
-{
-       GList * cur;
-
-       fputs("[global]\n", fp);
-       prefs_scoring_write(fp, global_scoring);
-       fputc('\n', fp);
-
-       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
-               Folder *folder;
-
-               folder = (Folder *) cur->data;
-               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
-                               prefs_scoring_write_func, fp);
-       }
-}
-*/
-
-/*
-void prefs_scoring_write_config(void)
-{
-       gchar *rcpath;
-       PrefFile *pfile;
-       GSList *cur;
-       ScoringProp * prop;
-
-       debug_print(_("Writing scoring configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, SCORING_RC, NULL);
-
-       if ((pfile = prefs_write_open(rcpath)) == NULL) {
-               g_warning(_("failed to write configuration to file\n"));
-               g_free(rcpath);
-               return;
-       }
-
-
-       prefs_scoring_save(pfile->fp);
-
-       g_free(rcpath);
-
-       if (prefs_write_close(pfile) < 0) {
-               g_warning(_("failed to write configuration to file\n"));
-               return;
-       }
-}
-*/
-
-
 void prefs_scoring_free(GSList * prefs_scoring)
 {
        while (prefs_scoring != NULL) {