Parent Directory | Revision Log | Patch
--- spamassassin/trunk/spamc/libspamc.c 2005/05/18 12:19:41 170739 +++ spamassassin/trunk/spamc/libspamc.c 2005/05/18 12:29:42 170740 @@ -766,12 +766,12 @@ static float _locale_safe_string_to_floa static int _handle_spamd_header(struct message *m, int flags, char *buf, int len, - int *actionok) + int *didtellflags) { char is_spam[6]; char s_str[21], t_str[21]; - char is_learned[4]; - char is_reported[4]; + char didset_ret[15]; + char didremove_ret[15]; UNUSED_VARIABLE(len); @@ -818,36 +818,23 @@ _handle_spamd_header(struct message *m, } return EX_OK; } - else if (sscanf(buf, "Learned: %3s", is_learned) == 1) { - if(strcmp(is_learned, "yes") == 0 || strcmp(is_learned, "Yes") == 0) { - *actionok = 1; + else if (sscanf(buf, "DidSet: %s", didset_ret) == 1) { + if (strstr(didset_ret, "local")) { + *didtellflags |= SPAMC_SET_LOCAL; } - else if(strcmp(is_learned, "no") == 0 || strcmp(is_learned, "No") == 0) { - *actionok = 0; + if (strstr(didset_ret, "remote")) { + *didtellflags |= SPAMC_SET_REMOTE; } - else { - libspamc_log(flags, LOG_ERR, "spamd responded with bad Learned state '%s'", - buf); - return EX_PROTOCOL; - } - return EX_OK; - } - else if (sscanf(buf, "Reported: %3s", is_reported) == 1) { - if(strcmp(is_reported, "yes") == 0 || strcmp(is_reported, "Yes") == 0) { - *actionok = 1; - } - else if(strcmp(is_reported, "no") == 0 || strcmp(is_reported, "No") == 0) { - *actionok = 0; + } + else if (sscanf(buf, "DidRemove: %s", didremove_ret) == 1) { + if (strstr(didremove_ret, "local")) { + *didtellflags |= SPAMC_REMOVE_LOCAL; } - else { - libspamc_log(flags, LOG_ERR, "spamd responded with bad Reported state '%s'", - buf); - return EX_PROTOCOL; + if (strstr(didremove_ret, "remote")) { + *didtellflags |= SPAMC_REMOVE_REMOTE; } - return EX_OK; } - /* skip any other headers that may be locally defined */ return EX_OK; } @@ -1122,8 +1109,9 @@ int message_process(struct transport *tr } } -int message_learn(struct transport *tp, const char *username, int flags, - struct message *m, int learntype, int *islearned) +int message_tell(struct transport *tp, const char *username, int flags, + struct message *m, int msg_class, + uint tellflags, uint *didtellflags) { char buf[8192]; size_t bufsiz = (sizeof(buf) / sizeof(*buf)) - 4; /* bit of breathing room */ @@ -1131,7 +1119,6 @@ int message_learn(struct transport *tp, int sock = -1; int rc; char versbuf[20]; - char strlearntype[1]; float version; int response; int failureval; @@ -1163,7 +1150,7 @@ int message_learn(struct transport *tp, m->out_len = 0; /* Build spamd protocol header */ - strcpy(buf, "LEARN "); + strcpy(buf, "TELL "); len = strlen(buf); if (len + strlen(PROTOCOL_VERSION) + 2 >= bufsiz) { @@ -1175,201 +1162,50 @@ int message_learn(struct transport *tp, strcat(buf, "\r\n"); len = strlen(buf); - if ((learntype > 2) | (learntype < 0 )) { - free(m->out); - m->out = m->msg; - m->out_len = m->msg_len; - return EX_OSERR; - } - sprintf(strlearntype,"%d",learntype); - strcpy(buf + len, "Learn-type: "); - strcat(buf + len, strlearntype); - strcat(buf + len, "\r\n"); - len += strlen(buf + len); - - if (username != NULL) { - if (strlen(username) + 8 >= (bufsiz - len)) { - _use_msg_for_out(m); - return EX_OSERR; - } - strcpy(buf + len, "User: "); - strcat(buf + len, username); - strcat(buf + len, "\r\n"); - len += strlen(buf + len); + if (msg_class != 0) { + strcpy(buf + len, "Message-class: "); + if (msg_class == SPAMC_MESSAGE_CLASS_SPAM) { + strcat(buf + len, "spam\r\n"); + } + else { + strcat(buf + len, "ham\r\n"); + } + len += strlen(buf + len); + } + + if ((tellflags & SPAMC_SET_LOCAL) || (tellflags & SPAMC_SET_REMOTE)) { + int needs_comma_p = 0; + strcat(buf + len, "Set: "); + if (tellflags & SPAMC_SET_LOCAL) { + strcat(buf + len, "local"); + needs_comma_p = 1; + } + if (tellflags & SPAMC_SET_REMOTE) { + if (needs_comma_p == 1) { + strcat(buf + len, ","); + } + strcat(buf + len, "remote"); + } + strcat(buf + len, "\r\n"); + len += strlen(buf + len); + } + + if ((tellflags & SPAMC_REMOVE_LOCAL) || (tellflags & SPAMC_REMOVE_REMOTE)) { + int needs_comma_p = 0; + strcat(buf + len, "Remove: "); + if (tellflags & SPAMC_REMOVE_LOCAL) { + strcat(buf + len, "local"); + needs_comma_p = 1; + } + if (tellflags & SPAMC_REMOVE_REMOTE) { + if (needs_comma_p == 1) { + strcat(buf + len, ","); + } + strcat(buf + len, "remote"); + } + strcat(buf + len, "\r\n"); + len += strlen(buf + len); } - if ((m->msg_len > 9999999) || ((len + 27) >= (bufsiz - len))) { - _use_msg_for_out(m); - return EX_OSERR; - } - len += sprintf(buf + len, "Content-length: %d\r\n\r\n", m->msg_len); - - libspamc_timeout = m->timeout; - - if (tp->socketpath) - rc = _try_to_connect_unix(tp, &sock); - else - rc = _try_to_connect_tcp(tp, &sock); - - if (rc != EX_OK) { - _use_msg_for_out(m); - return rc; /* use the error code try_to_connect_*() gave us. */ - } - - if (flags & SPAMC_USE_SSL) { -#ifdef SPAMC_SSL - ssl = SSL_new(ctx); - SSL_set_fd(ssl, sock); - SSL_connect(ssl); -#endif - } - - /* Send to spamd */ - if (flags & SPAMC_USE_SSL) { -#ifdef SPAMC_SSL - SSL_write(ssl, buf, len); - SSL_write(ssl, m->msg, m->msg_len); -#endif - } - else { - full_write(sock, 0, buf, len); - full_write(sock, 0, m->msg, m->msg_len); - shutdown(sock, SHUT_WR); - } - - /* ok, now read and parse it. SPAMD/1.2 line first... */ - failureval = - _spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz); - if (failureval != EX_OK) { - goto failure; - } - - if (sscanf(buf, "SPAMD/%18s %d %*s", versbuf, &response) != 2) { - libspamc_log(flags, LOG_ERR, "spamd responded with bad string '%s'", buf); - failureval = EX_PROTOCOL; - goto failure; - } - - versbuf[19] = '\0'; - version = _locale_safe_string_to_float(versbuf, 20); - if (version < 1.0) { - libspamc_log(flags, LOG_ERR, "spamd responded with bad version string '%s'", - versbuf); - failureval = EX_PROTOCOL; - goto failure; - } - - m->score = 0; - m->threshold = 0; - m->is_spam = EX_TOOBIG; - *islearned = 0; - while (1) { - failureval = - _spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz); - if (failureval != EX_OK) { - goto failure; - } - - if (len == 0 && buf[0] == '\0') { - break; /* end of headers */ - } - - if (_handle_spamd_header(m, flags, buf, len, islearned) < 0) { - failureval = EX_PROTOCOL; - goto failure; - } - } - - len = 0; /* overwrite those headers */ - - shutdown(sock, SHUT_RD); - closesocket(sock); - sock = -1; - - libspamc_timeout = 0; - - return EX_OK; - - failure: - _use_msg_for_out(m); - if (sock != -1) { - closesocket(sock); - } - libspamc_timeout = 0; - - if (flags & SPAMC_USE_SSL) { -#ifdef SPAMC_SSL - SSL_free(ssl); - SSL_CTX_free(ctx); -#endif - } - return failureval; -} - - -int message_collabreport(struct transport *tp, const char *username, int flags, - struct message *m, int reporttype, int *isreported) -{ - char buf[8192]; - size_t bufsiz = (sizeof(buf) / sizeof(*buf)) - 4; /* bit of breathing room */ - size_t len; - int sock = -1; - int rc; - char versbuf[20]; - char strreporttype[1]; - float version; - int response; - int failureval; - SSL_CTX *ctx = NULL; - SSL *ssl = NULL; - SSL_METHOD *meth; - - if (flags & SPAMC_USE_SSL) { -#ifdef SPAMC_SSL - SSLeay_add_ssl_algorithms(); - meth = SSLv2_client_method(); - SSL_load_error_strings(); - ctx = SSL_CTX_new(meth); -#else - UNUSED_VARIABLE(ssl); - UNUSED_VARIABLE(meth); - UNUSED_VARIABLE(ctx); - libspamc_log(flags, LOG_ERR, "spamc not built with SSL support"); - return EX_SOFTWARE; -#endif - } - - m->is_spam = EX_TOOBIG; - if ((m->outbuf = malloc(m->max_len + EXPANSION_ALLOWANCE + 1)) == NULL) { - failureval = EX_OSERR; - goto failure; - } - m->out = m->outbuf; - m->out_len = 0; - - /* Build spamd protocol header */ - strcpy(buf, "COLLABREPORT "); - - len = strlen(buf); - if (len + strlen(PROTOCOL_VERSION) + 2 >= bufsiz) { - _use_msg_for_out(m); - return EX_OSERR; - } - - strcat(buf, PROTOCOL_VERSION); - strcat(buf, "\r\n"); - len = strlen(buf); - - if ((reporttype > 2) | (reporttype < 0 )) { - free(m->out); - m->out = m->msg; - m->out_len = m->msg_len; - return EX_OSERR; - } - sprintf(strreporttype,"%d",reporttype); - strcpy(buf + len, "CollabReport-type: "); - strcat(buf + len, strreporttype); - strcat(buf + len, "\r\n"); - len += strlen(buf + len); if (username != NULL) { if (strlen(username) + 8 >= (bufsiz - len)) { @@ -1437,7 +1273,7 @@ int message_collabreport(struct transpor version = _locale_safe_string_to_float(versbuf, 20); if (version < 1.0) { libspamc_log(flags, LOG_ERR, "spamd responded with bad version string '%s'", - versbuf); + versbuf); failureval = EX_PROTOCOL; goto failure; } @@ -1445,7 +1281,6 @@ int message_collabreport(struct transpor m->score = 0; m->threshold = 0; m->is_spam = EX_TOOBIG; - *isreported = 0; while (1) { failureval = _spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz); @@ -1457,7 +1292,7 @@ int message_collabreport(struct transpor break; /* end of headers */ } - if (_handle_spamd_header(m, flags, buf, len, isreported) < 0) { + if (_handle_spamd_header(m, flags, buf, len, didtellflags) < 0) { failureval = EX_PROTOCOL; goto failure; } @@ -1478,7 +1313,6 @@ int message_collabreport(struct transpor if (sock != -1) { closesocket(sock); } - libspamc_timeout = 0; if (flags & SPAMC_USE_SSL) { @@ -1490,8 +1324,6 @@ int message_collabreport(struct transpor return failureval; } - - void message_cleanup(struct message *m) { if (m->outbuf)
infrastructure at apache.org | ViewVC Help |
Powered by ViewVC 1.1.26 |