]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/inboxrules/serv_inboxrules.c
dammit, learn to spell
[citadel.git] / citadel / server / modules / inboxrules / serv_inboxrules.c
index 889b138ff71c39e3465625d9ea49052718b3a618..5c01625af9bb447f11ecf41c438f4f4fa590e55f 100644 (file)
@@ -485,6 +485,8 @@ void inbox_do_msg(long msgnum, void *userdata) {
        int compare_compound = 0;               // Set to 1 when we are comparing both display name and email address
        int keep_message = 1;                   // Nonzero to keep the message in the inbox after processing, 0 to delete it.
        int i;
+       const char *ptr,*ptr1;                  // Temporary variables to get X-Spam-Status
+       int len;
 
        syslog(LOG_DEBUG, "inboxrules: processing message #%ld which is higher than %ld, we are in %s", msgnum, ii->lastproc, CC->room.QRname);
 
@@ -607,12 +609,28 @@ void inbox_do_msg(long msgnum, void *userdata) {
                                }
                                break;
 
+                       case field_xspamstatus:
+                               if (!IsEmptyStr(msg->cm_fields[eMessageText])) {
+                                       if ((ptr=strstr(msg->cm_fields[eMessageText],"X-Spam-Status"))!=NULL) {
+                                               len=0;
+                                               ptr1=ptr;
+                                               while (*ptr1 && (*ptr1!='\r') && (*ptr1!='\n')) {
+                                                       ptr1++;
+                                                       len++;
+                                               }
+                                               if (len && (len<SIZ)) {
+                                                       memcpy(compare_me, ptr, len);
+                                                       compare_me[len]='\0';
+                                               }
+                                       }
+                               }
+                       break;
+
                        case field_sender:
                        case field_resentfrom:
                        case field_resentto:
                        case field_xmailer:
                        case field_xspamflag:
-                       case field_xspamstatus:
 
                        default:
                                break;
@@ -644,10 +662,13 @@ void inbox_do_msg(long msgnum, void *userdata) {
                                int substring_match = 0;
                                int regex_match = 0;
                                int exact_match = 0;
+                               int rc = 0;
 
                                regex_t regex;
-                               if (regcomp(&regex, ii->rules[i].compared_value, (REG_EXTENDED | REG_ICASE | REG_NOSUB | REG_NEWLINE))) {
-                                       syslog(LOG_ERR, "inboxrules: regcomp: %m");
+                               
+                               rc = regcomp(&regex, ii->rules[i].compared_value, (REG_EXTENDED | REG_ICASE | REG_NOSUB | REG_NEWLINE));
+                               if (rc) {
+                                       syslog(LOG_ERR, "inboxrules: regcomp: error %d trying to compile \"%s\"", rc, ii->rules[i].compared_value);
                                }
 
                                if (compare_compound) {                                 // comparing a compound field such as name+address
@@ -663,7 +684,7 @@ void inbox_do_msg(long msgnum, void *userdata) {
                                                        (bmstrcasestr(compare_me, ii->rules[i].compared_value) ? 1 : 0)
                                                        + (bmstrcasestr(sep, ii->rules[i].compared_value) ? 1 : 0)
                                                ;
-                                               regex_match =
+                                               if (!rc) regex_match =
                                                        (regexec(&regex, compare_me, 0, 0, 0) ? 0 : 1)
                                                        + (regexec(&regex, sep, 0, 0, 0) ? 0 : 1)
                                                ;
@@ -672,12 +693,13 @@ void inbox_do_msg(long msgnum, void *userdata) {
                                else {                                                  // comparing a single field only
                                        exact_match = (strcasecmp(compare_me, ii->rules[i].compared_value) ? 0 : 1);
                                        substring_match = (bmstrcasestr(compare_me, ii->rules[i].compared_value) ? 1 : 0);
-                                       regex_match = (regexec(&regex, compare_me, 0, 0, 0) ? 1 : 0);
+                                       if (!rc) regex_match = (regexec(&regex, compare_me, 0, 0, 0) ? 0 : 1);
                                }
+
                                regfree(&regex);
-                               syslog(LOG_DEBUG, "substring match: %d", substring_match);
-                               syslog(LOG_DEBUG, "    regex match: %d", regex_match);
-                               syslog(LOG_DEBUG, "    exact match: %d", exact_match);
+                               syslog(LOG_DEBUG, "inboxrules: substring match: %d", substring_match);
+                               syslog(LOG_DEBUG, "inboxrules:     regex match: %d", regex_match);
+                               syslog(LOG_DEBUG, "inboxrules:     exact match: %d", exact_match);
                                switch(ii->rules[i].field_compare_op) {
                                        case fcomp_contains:
                                                rule_activated = substring_match;
@@ -796,7 +818,7 @@ void do_inbox_processing_for_user(long usernum) {
                return;                                         // config msgnum is set but that message does not exist
        }
 
-       ii = deserialize_inbox_rules(msg->cm_fields[eMesageText]);
+       ii = deserialize_inbox_rules(msg->cm_fields[eMessageText]);
        CM_Free(msg);
 
        if (ii == NULL) {
@@ -908,9 +930,9 @@ void cmd_gibr(char *argbuf) {
 
        struct CtdlMessage *msg = CtdlFetchMessage(CC->user.msgnum_inboxrules, 1);
        if (msg != NULL) {
-               if (!CM_IsEmpty(msg, eMesageText)) {
+               if (!CM_IsEmpty(msg, eMessageText)) {
                        char *token; 
-                       char *rest = msg->cm_fields[eMesageText];
+                       char *rest = msg->cm_fields[eMessageText];
                        while ((token = strtok_r(rest, "\n", &rest))) {
 
                                // for backwards compatibility, "# WEBCIT_RULE" is an alias for "rule"