added additionnal matching criteria
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sun, 13 May 2001 02:57:01 +0000 (02:57 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sun, 13 May 2001 02:57:01 +0000 (02:57 +0000)
ChangeLog.claws
src/defs.h
src/matcher.c
src/matcher.h
src/news.c
src/prefs_matcher.c
src/procheader.c
src/procmsg.c
src/procmsg.h

index 53cf495..7213e75 100644 (file)
@@ -1,3 +1,14 @@
+2001-05-13 [hoa]
+       * src/defs.h
+               changed version of cache
+       * src/matcher.[ch]
+       * src/prefs_matcher.c
+               added additionnal matching criteria
+       * src/procheader.c
+       * src/procmsg.[ch]
+       * src/news.c
+               added references in MsgInfo
+
 2001-05-12 [hoa]
 
        * src/defs.h
index 52204d1..2e4ffc9 100644 (file)
@@ -58,7 +58,7 @@
 #define FOLDER_LIST            "folderlist.xml"
 #define CACHE_FILE             ".sylpheed_cache"
 #define MARK_FILE              ".sylpheed_mark"
-#define CACHE_VERSION          18
+#define CACHE_VERSION          19
 #define MARK_VERSION           2
 
 #define DEFAULT_SIGNATURE      ".signature"
index 59794c8..89985b1 100644 (file)
@@ -47,6 +47,10 @@ MatchParser matchparser_tab[] = {
        {MATCHING_NOT_NEWSGROUPS, "~newsgroups"},
        {MATCHING_INREPLYTO, "inreplyto"},
        {MATCHING_NOT_INREPLYTO, "~inreplyto"},
+       {MATCHING_REFERENCES, "references"},
+       {MATCHING_NOT_REFERENCES, "~references"},
+       {MATCHING_SCORE_GREATER, "score_greater"},
+       {MATCHING_SCORE_LOWER, "score_lower"},
 
        /* content have to be read */
        {MATCHING_HEADER, "header"},
@@ -103,7 +107,7 @@ MatcherProp * matcherprop_parse(gchar ** str)
        MatcherProp * prop;
        gchar * tmp;
        gint key;
-       gint age;
+       gint value;
        gchar * expr;
        gint match;
        gchar * header = NULL;
@@ -118,14 +122,16 @@ MatcherProp * matcherprop_parse(gchar ** str)
        switch (key) {
        case MATCHING_AGE_LOWER:
        case MATCHING_AGE_GREATER:
-               age = matcher_parse_number(&tmp);
+       case MATCHING_SCORE_LOWER:
+       case MATCHING_SCORE_GREATER:
+               value = matcher_parse_number(&tmp);
                if (tmp == NULL) {
                        * str = NULL;
                        return NULL;
                }
                *str = tmp;
 
-               prop = matcherprop_new(key, NULL, 0, NULL, age);
+               prop = matcherprop_new(key, NULL, 0, NULL, value);
 
                return prop;
 
@@ -160,6 +166,8 @@ MatcherProp * matcherprop_parse(gchar ** str)
        case MATCHING_NEWSGROUPS:
        case MATCHING_NOT_NEWSGROUPS:
        case MATCHING_INREPLYTO:
+       case MATCHING_NOT_REFERENCES:
+       case MATCHING_REFERENCES:
        case MATCHING_NOT_INREPLYTO:
        case MATCHING_MESSAGE:
        case MATCHING_NOT_MESSAGE:
@@ -249,11 +257,12 @@ gint matcher_parse_keyword(gchar ** str)
        match = -1;
        for(i = 0 ; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)) ;
            i++) {
-               if (strncasecmp(matchparser_tab[i].str, start,
-                               p - start) == 0) {
-                       match = i;
-                       break;
-               }
+               if ((strlen(matchparser_tab[i].str) == p - start) &&
+                   (strncasecmp(matchparser_tab[i].str, start,
+                                p - start) == 0)) {
+                               match = i;
+                               break;
+                       }
        }
 
        if (match == -1) {
@@ -394,7 +403,7 @@ gchar * matcher_parse_str(gchar ** str)
 
 MatcherProp * matcherprop_new(gint criteria, gchar * header,
                              gint matchtype, gchar * expr,
-                             int age)
+                             int value)
 {
        MatcherProp * prop;
 
@@ -410,7 +419,7 @@ MatcherProp * matcherprop_new(gint criteria, gchar * header,
                prop->expr = NULL;
        prop->matchtype = matchtype;
        prop->preg = NULL;
-       prop->age = age;
+       prop->value = value;
        prop->error = 0;
 
        return prop;
@@ -536,10 +545,14 @@ gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info)
                || matcherprop_string_match(prop, info->cc));
        case MATCHING_AGE_GREATER:
                t = time(NULL);
-               return ((t - info->date_t) / (60 * 60 * 24)) >= prop->age;
+               return ((t - info->date_t) / (60 * 60 * 24)) >= prop->value;
        case MATCHING_AGE_LOWER:
                t = time(NULL);
-               return ((t - info->date_t) / (60 * 60 * 24)) <= prop->age;
+               return ((t - info->date_t) / (60 * 60 * 24)) <= prop->value;
+       case MATCHING_SCORE_GREATER:
+               return info->score >= prop->value;
+       case MATCHING_SCORE_LOWER:
+               return info->score <= prop->value;
        case MATCHING_NEWSGROUPS:
                return matcherprop_string_match(prop, info->newsgroups);
        case MATCHING_NOT_NEWSGROUPS:
@@ -548,6 +561,10 @@ gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info)
                return matcherprop_string_match(prop, info->inreplyto);
        case MATCHING_NOT_INREPLYTO:
                return !matcherprop_string_match(prop, info->inreplyto);
+       case MATCHING_REFERENCES:
+               return matcherprop_string_match(prop, info->references);
+       case MATCHING_NOT_REFERENCES:
+               return !matcherprop_string_match(prop, info->references);
        case MATCHING_HEADER:
        default:
                return 0;
@@ -987,7 +1004,7 @@ static void matcherprop_print(MatcherProp * matcher)
        if (matcher->expr)
                printf("expr : %s\n", matcher->expr);
 
-       printf("age: %i\n", matcher->age);
+       printf("age: %i\n", matcher->value;
 
        printf("compiled : %s\n", matcher->preg != NULL ? "yes" : "no");
        printf("error: %i\n",  matcher->error);
@@ -1017,7 +1034,9 @@ gchar * matcherprop_to_string(MatcherProp * matcher)
        switch(matcher->criteria) {
        case MATCHING_AGE_GREATER:
        case MATCHING_AGE_LOWER:
-               return g_strdup_printf("%s %i", criteria_str, matcher->age);
+       case MATCHING_SCORE_GREATER:
+       case MATCHING_SCORE_LOWER:
+               return g_strdup_printf("%s %i", criteria_str, matcher->value);
                break;
        case MATCHING_ALL:
        case MATCHING_UNREAD:
index 3cb4007..c153e8e 100644 (file)
@@ -40,6 +40,10 @@ enum {
        MATCHING_NOT_NEWSGROUPS,
        MATCHING_INREPLYTO,
        MATCHING_NOT_INREPLYTO,
+       MATCHING_REFERENCES,
+       MATCHING_NOT_REFERENCES,
+       MATCHING_SCORE_GREATER,
+       MATCHING_SCORE_LOWER,
 
        /* file content */
        MATCHING_HEADER,
@@ -76,7 +80,7 @@ struct _MatcherProp {
        int criteria;
        gchar * header;
        gchar * expr;
-       int age;
+       int value;
        regex_t * preg;
        int error;
 };
index f970e2d..d67fc95 100644 (file)
@@ -566,6 +566,7 @@ static MsgInfo *news_parse_xover(const gchar *xover_str)
        if (*msgid != '\0')
                msginfo->msgid = g_strdup(msgid);
 
+       msginfo->references = g_strdup(ref);
        eliminate_parenthesis(ref, '(', ')');
        if ((p = strrchr(ref, '<')) != NULL) {
                extract_parenthesis(p, '<', '>');
index 8e98aed..d499b94 100644 (file)
@@ -85,19 +85,23 @@ enum {
        CRITERIA_TO_OR_CC = 5,
        CRITERIA_NEWSGROUPS = 6,
        CRITERIA_INREPLYTO = 7,
-       CRITERIA_AGE_GREATER = 8,
-       CRITERIA_AGE_LOWER = 9,
-       CRITERIA_HEADER = 10,
-       CRITERIA_HEADERS_PART = 11,
-       CRITERIA_BODY_PART = 12,
-       CRITERIA_MESSAGE = 13,
-
-       CRITERIA_UNREAD = 14,
-       CRITERIA_NEW = 15,
-       CRITERIA_MARKED = 16,
-       CRITERIA_DELETED = 17,
-       CRITERIA_REPLIED = 18,
-       CRITERIA_FORWARDED = 19
+       CRITERIA_REFERENCES = 8,
+       CRITERIA_AGE_GREATER = 9,
+       CRITERIA_AGE_LOWER = 10,
+       CRITERIA_HEADER = 11,
+       CRITERIA_HEADERS_PART = 12,
+       CRITERIA_BODY_PART = 13,
+       CRITERIA_MESSAGE = 14,
+
+       CRITERIA_UNREAD = 15,
+       CRITERIA_NEW = 16,
+       CRITERIA_MARKED = 17,
+       CRITERIA_DELETED = 18,
+       CRITERIA_REPLIED = 19,
+       CRITERIA_FORWARDED = 20,
+
+       CRITERIA_SCORE_GREATER = 21,
+       CRITERIA_SCORE_LOWER = 22
 };
 
 enum {
@@ -130,13 +134,14 @@ gchar * predicate_flag_text [] = {
 gchar * criteria_text [] = {
        "All messages", "Subject",
        "From", "To", "Cc", "To or Cc",
-       "Newsgroups", "In reply to",
+       "Newsgroups", "In reply to", "References",
        "Age greater than", "Age lower than",
        "Header", "Headers part",
        "Body part", "Whole message",
        "Unread flag", "New flag",
        "Marked flag", "Deleted flag",
-       "Replied flag", "Forwarded flag"
+       "Replied flag", "Forwarded flag",
+       "Score greater than", "Score lower than"
 };
 
 gint get_sel_from_list(GtkList * list)
@@ -702,10 +707,16 @@ static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
                return MATCHING_NEWSGROUPS;
        case CRITERIA_INREPLYTO:
                return MATCHING_INREPLYTO;
+       case CRITERIA_REFERENCES:
+               return MATCHING_REFERENCES;
        case CRITERIA_AGE_GREATER:
                return MATCHING_AGE_GREATER;
        case CRITERIA_AGE_LOWER:
                return MATCHING_AGE_LOWER;
+       case CRITERIA_SCORE_GREATER:
+               return MATCHING_SCORE_GREATER;
+       case CRITERIA_SCORE_LOWER:
+               return MATCHING_SCORE_LOWER;
        case CRITERIA_HEADER:
                return MATCHING_HEADER;
        case CRITERIA_HEADERS_PART:
@@ -748,6 +759,8 @@ static gint prefs_matcher_not_criteria(gint matcher_criteria)
                return MATCHING_NOT_NEWSGROUPS;
        case MATCHING_INREPLYTO:
                return MATCHING_NOT_INREPLYTO;
+       case MATCHING_REFERENCES:
+               return MATCHING_NOT_REFERENCES;
        case MATCHING_HEADER:
                return MATCHING_NOT_HEADER;
        case MATCHING_HEADERS_PART:
@@ -773,8 +786,8 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        gboolean case_sensitive;
        gchar * header;
        gchar * expr;
-       gint age;
-       gchar * age_str;
+       gint value;
+       gchar * value_str;
 
        value_criteria = get_sel_from_list(GTK_LIST(matcher.criteria_list));
 
@@ -803,6 +816,7 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        case CRITERIA_TO_OR_CC:
        case CRITERIA_NEWSGROUPS:
        case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
        case CRITERIA_HEADERS_PART:
        case CRITERIA_BODY_PART:
        case CRITERIA_MESSAGE:
@@ -829,7 +843,7 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
 
        header = NULL;
        expr = NULL;
-       age = 0;
+       value = 0;
 
        switch (value_criteria) {
        case CRITERIA_ALL:
@@ -848,6 +862,7 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
        case CRITERIA_TO_OR_CC:
        case CRITERIA_NEWSGROUPS:
        case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
        case CRITERIA_HEADERS_PART:
        case CRITERIA_BODY_PART:
        case CRITERIA_MESSAGE:
@@ -863,14 +878,16 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
 
        case CRITERIA_AGE_GREATER:
        case CRITERIA_AGE_LOWER:
-               age_str = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
+       case CRITERIA_SCORE_GREATER:
+       case CRITERIA_SCORE_LOWER:
+               value_str = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
 
-               if (*age_str == '\0') {
-                   alertpanel_error(_("Age is not set."));
+               if (*value_str == '\0') {
+                   alertpanel_error(_("Value is not set."));
                    return NULL;
                }
 
-               age = atoi(age_str);
+               value = atoi(value_str);
 
                break;
 
@@ -892,7 +909,8 @@ static MatcherProp * prefs_matcher_dialog_to_matcher()
                break;
        }
 
-       matcherprop =  matcherprop_new(criteria, header, matchtype, expr, age);
+       matcherprop =  matcherprop_new(criteria, header, matchtype,
+                                      expr, value);
 
        return matcherprop;
 }
@@ -1084,6 +1102,13 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
                                     CRITERIA_INREPLYTO);
                break;
 
+       case MATCHING_NOT_REFERENCES:
+               negative_cond = TRUE;
+       case MATCHING_REFERENCES:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_REFERENCES);
+               break;
+
        case MATCHING_NOT_TO_AND_NOT_CC:
                negative_cond = TRUE;
        case MATCHING_TO_OR_CC:
@@ -1128,6 +1153,16 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
                gtk_list_select_item(GTK_LIST(matcher.criteria_list),
                                     CRITERIA_AGE_LOWER);
                break;
+
+       case MATCHING_SCORE_GREATER:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_SCORE_GREATER);
+               break;
+
+       case MATCHING_SCORE_LOWER:
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    CRITERIA_SCORE_LOWER);
+               break;
        }
        
        switch(prop->criteria) {
@@ -1141,6 +1176,7 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
        case MATCHING_NOT_TO_AND_NOT_CC:
        case MATCHING_NOT_NEWSGROUPS:
        case MATCHING_NOT_INREPLYTO:
+       case MATCHING_NOT_REFERENCES:
        case MATCHING_NOT_HEADERS_PART:
        case MATCHING_NOT_BODY_PART:
        case MATCHING_NOT_MESSAGE:
@@ -1151,6 +1187,7 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
        case MATCHING_TO_OR_CC:
        case MATCHING_NEWSGROUPS:
        case MATCHING_INREPLYTO:
+       case MATCHING_REFERENCES:
        case MATCHING_HEADERS_PART:
        case MATCHING_BODY_PART:
        case MATCHING_MESSAGE:
@@ -1159,7 +1196,9 @@ static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
 
        case MATCHING_AGE_GREATER:
        case MATCHING_AGE_LOWER:
-               gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), itos(prop->age));
+       case MATCHING_SCORE_GREATER:
+       case MATCHING_SCORE_LOWER:
+               gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), itos(prop->value));
                break;
 
        case MATCHING_NOT_HEADER:
@@ -1246,6 +1285,7 @@ static void prefs_matcher_criteria_select(GtkList *list,
        case CRITERIA_TO_OR_CC:
        case CRITERIA_NEWSGROUPS:
        case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
        case CRITERIA_HEADERS_PART:
        case CRITERIA_BODY_PART:
        case CRITERIA_MESSAGE:
@@ -1264,6 +1304,8 @@ static void prefs_matcher_criteria_select(GtkList *list,
 
        case CRITERIA_AGE_GREATER:
        case CRITERIA_AGE_LOWER:
+       case CRITERIA_SCORE_GREATER:
+       case CRITERIA_SCORE_LOWER:
                gtk_widget_set_sensitive(matcher.header_combo, FALSE);
                gtk_widget_set_sensitive(matcher.header_label, FALSE);
                gtk_widget_set_sensitive(matcher.value_label, TRUE);
index 8148317..49a03b5 100644 (file)
@@ -548,6 +548,7 @@ MsgInfo *procheader_parse(const gchar *file, MsgFlags flags, gboolean full)
                        break;
                case H_REFERENCES:
                        if (!reference) {
+                               msginfo->references = g_strdup(hp);
                                eliminate_parenthesis(hp, '(', ')');
                                if ((p = strrchr(hp, '<')) != NULL &&
                                    strchr(p + 1, '>') != NULL) {
index 13b4bfa..065a154 100644 (file)
@@ -234,6 +234,7 @@ GSList *procmsg_read_cache(FolderItem *item, gboolean scan_file)
                READ_CACHE_DATA(msginfo->subject, fp);
                READ_CACHE_DATA(msginfo->msgid, fp);
                READ_CACHE_DATA(msginfo->inreplyto, fp);
+               READ_CACHE_DATA(msginfo->references, fp);
 
                MSG_SET_FLAGS(msginfo->flags, default_flags);
 
@@ -363,6 +364,7 @@ void procmsg_write_cache(MsgInfo *msginfo, FILE *fp)
        WRITE_CACHE_DATA(msginfo->subject, fp);
        WRITE_CACHE_DATA(msginfo->msgid, fp);
        WRITE_CACHE_DATA(msginfo->inreplyto, fp);
+       WRITE_CACHE_DATA(msginfo->references, fp);
 }
 
 void procmsg_write_flags(MsgInfo *msginfo, FILE *fp)
@@ -755,6 +757,7 @@ MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo)
        MEMBDUP(xface);
        MEMBDUP(dispositionnotificationto);
        MEMBDUP(returnreceiptto);
+       MEMBDUP(references);
 
        MEMBCOPY(score);
        MEMBCOPY(threadscore);
@@ -766,6 +769,7 @@ void procmsg_msginfo_free(MsgInfo *msginfo)
 {
        if (msginfo == NULL) return;
 
+       g_free(msginfo->references);
        g_free(msginfo->returnreceiptto);
        g_free(msginfo->dispositionnotificationto);
        g_free(msginfo->xface);
index 0f65c47..d1ac5cd 100644 (file)
@@ -125,6 +125,8 @@ struct _MsgInfo
        gchar *dispositionnotificationto;
        gchar *returnreceiptto;
 
+       gchar *references;
+
        gint score;
        gint threadscore;