Open brong opened 21 years ago
From: Christian Schulte
I tried to install the contrib/sieve-spamassassin patches but they did not work out of the box with cvs-2.2! These are the diffs to all involved files for a cvs-2.2 installation! In order to get the whole thing compiled after applying these changes, one has to specify -DSPAMASSASSIN=1 to the compiler except for sieve-lex.l, sieve.y and imapoptions.
From: Christian Schulte
===================================================================
RCS file: /cvs/src/cyrus/imap/lmtpd.c,v
retrieving revision 1.99.2.19
diff -r1.99.2.19 lmtpd.c
113a114,123
> #ifdef SPAMASSASSIN
>
> / spam stuff /
>
> / This is in script_data, but the spam callback can't get to it /
> / so we put a copy here /
> char username; / Username of mailbox /
> int spam_result_valid; / != 0 iff spam result is valid /
> int spam_result; / != iff message is spam /
> #endif / SPAMASSASSIN /
893a904,1066
> #ifdef SPAMASSASSIN
> / spam support /
>
> static int
> getline (int s, char buf, int len)
> {
> char bp = buf;
> int ret = 1;
> char ch;
>
> while ((ret = read (s, &ch, 1)) == 1 && ch != '\n') {
> if (len > 0) {
> bp++ = ch;
> len--;
> }
> }
> if (len > 0)
> bp = '\0';
> return (buf != bp);
> }
>
>
> static int
> full_write (int s, char buf, int len)
> {
> int total;
> int ret;
>
> for (total = 0; total < len; total += ret) {
> ret = write (s, buf + total, len - total);
> if (ret < 0)
> return 0;
> }
> return total == len;
> }
>
> static int
> read_response (int s, int result)
> {
> char is_spam[6];
> char buf[1024];
> int major;
> int minor;
> int response;
> float score;
> float threshold;
>
> if (! getline (s, buf, sizeof (buf))) {
> syslog (LOG_ERR, "read_response: response getline failed");
> return SIEVE_FAIL;
> }
> if (sscanf (buf, "SPAMD/%d.%d %d %s", &major, &minor, &response) != 3) {
> syslog (LOG_ERR, "read_response: response sscanf failed, buf: %s",
> buf);
> return SIEVE_FAIL;
> }
> if (major < 1 || (major == 1 && minor < 1)) {
> syslog (LOG_ERR, "read_response: bad spamd version: %d.%d",
> major, minor);
> return SIEVE_FAIL;
> }
> if (! getline (s, buf, sizeof (buf))) {
> syslog (LOG_ERR, "read_response: header getline failed");
> return SIEVE_FAIL;
> }
> if (sscanf (buf, "Spam: %5s ; %f / %f", is_spam, &score, &threshold) != 3) {
> syslog (LOG_ERR, "read_response: header sscanf failed, buf: %s",
> buf);
> return SIEVE_FAIL;
> }
>
> result = ! strcmp(is_spam, "True");
> return SIEVE_OK;
> }
>
> int spam (void mc, int is_spam)
> {
> mydata_t d = (mydata_t ) mc;
> message_data_t m = d->m;
> int s;
> struct sockaddr_in addr;
> struct hostent host;
> char header[128];
> int max_size = config_getint (IMAPOPT_SPAMD_MAX_SIZE);
> const char hostname = config_getstring (IMAPOPT_SPAMD_HOST);
> int port = config_getint (IMAPOPT_SPAMD_PORT);
> char msg_buf;
> int ret;
>
> / Assume message isn't spam if it is larger than max_size /
> if (m->size > max_size) {
> syslog (LOG_INFO, "spam: skipping message bigger than %d", max_size);
> return SIEVE_FAIL;
> }
>
> memset (&addr, 0, sizeof(addr));
> addr.sin_family = AF_INET;
> addr.sin_port = htons(port);
>
> if ((host = gethostbyname (hostname)) == NULL) {
> syslog (LOG_ERR, "spam: gethostbyname failed");
> return SIEVE_FAIL;
> }
> memcpy (&addr.sin_addr, host->h_addr, sizeof (addr.sin_addr));
>
> if((s = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
> syslog (LOG_ERR, "spam: socket failed");
> return SIEVE_FAIL;
> }
>
> if (connect (s, (const struct sockaddr ) &addr, sizeof (addr)) < 0) {
> syslog (LOG_ERR, "spam: connect failed");
> close (s);
> return SIEVE_FAIL;
> }
>
> if ((msg_buf = malloc (m->size)) == NULL) {
> syslog (LOG_ERR, "spam: malloc(%d) failed", m->size);
> close (s);
> return SIEVE_FAIL;
> }
> rewind (m->f);
> if (fread (msg_buf, 1, m->size, m->f) != m->size || ferror (m->f)) {
> syslog (LOG_ERR, "spam: read message failed");
> free (msg_buf);
> close (s);
> return SIEVE_FAIL;
> }
>
> if (d->username) {
> snprintf (header, sizeof (header),
> "CHECK SPAMC/1.2\r\nUser: %s\r\nContent-length: %d\r\n\r\n",
> d->username, m->size);
> }
> else {
> snprintf (header, sizeof (header),
> "CHECK SPAMC/1.2\r\nContent-length: %d\r\n\r\n", m->size);
> }
> if (! full_write (s, header, strlen (header))) {
> syslog (LOG_ERR, "spam: write header failed");
> free (msg_buf);
> close (s);
> return SIEVE_FAIL;
> }
> if (! full_write (s, msg_buf, m->size)) {
> syslog (LOG_ERR, "spam: write message failed");
> free (msg_buf);
> close (s);
> return SIEVE_FAIL;
> }
>
> shutdown (s, SHUT_WR);
> ret = read_response (s, is_spam);
> shutdown (s, SHUT_RD);
>
> free (msg_buf);
> close (s);
>
> syslog(LOG_DEBUG, "spam result: %d\n", ret);
> return ret;
> }
> #endif / SPAMASSASSIN /
>
986a1160,1167
> #ifdef SPAMASSASSIN
> res = sieve_register_spam(sieve_interp, &spam);
> if (res != SIEVE_OK) {
> syslog(LOG_ERR, "sieve_register_spam() returns %d\n", res);
> fatal("sieve_register_spam()", EC_SOFTWARE);
> }
>
> #endif / SPAMASSASSIN /
1155c1336,1340
> #ifdef SPAMASSASSIN > / Make a copy of mailbox username for spam stuff / > mydata.username = sdata->username; > #endif SPAMASSASSIN
=================================================================== RCS file: /cvs/src/cyrus/imap/Attic/imapoptions,v retrieving revision 1.1.4.14 diff -r1.1.4.14 imapoptions 537a538,546 > { "spamd_host", "127.0.0.1", STRING } > / The host on which spamassassins spamd listens / > > { "spamd_port", 783, INT } > / The port on which spamassassins spamd listens / > > { "spamd_max_size", 256000, INT } > / The maximum message size in bytes for which spamchecking will get bypassed / >
===================================================================
RCS file: /cvs/src/sieve/interp.c,v
retrieving revision 1.22
diff -r1.22 interp.c
145a146,154
> #ifdef SPAMASSASSIN
> int sieve_register_spam(sieve_interp_t interp, sieve_spam f)
> {
> interp->spam = f;
>
> return SIEVE_OK;
> }
>
> #endif / SPAMASSASSIN /
=================================================================== RCS file: /cvs/src/sieve/interp.h,v retrieving revision 1.7 diff -r1.7 interp.h 37a38,40 > #ifdef SPAMASSASSIN > sieve_spam spam; > #endif / SPAMASSASSIN */
> #ifdef SPAMASSASSIN > case SPAM: > { > int is_spam; 441a454,459 > if (i->spam == NULL || i->spam (m, &is_spam) != SIEVE_OK) > break; > res = is_spam; > } > #endif / SPAMASSASSIN / > }
=================================================================== RCS file: /cvs/src/sieve/script.h,v retrieving revision 1.7.4.1 diff -r1.7.4.1 script.h 49a50,52 > #ifdef SPAMASSASSIN > int spam : 1; > #endif / SPAMASSASSIN /
=================================================================== RCS file: /cvs/src/sieve/sieve-lex.l,v retrieving revision 1.20 diff -r1.20 sieve-lex.l 93a94 > <INITIAL>spam return SPAM;
=================================================================== RCS file: /cvs/src/sieve/sieve.y,v retrieving revision 1.19.4.2 diff -r1.19.4.2 sieve.y 146a147 > %token SPAM 415a417,421 > | SPAM { if (!parse_script->support.spam) { > yyerror("spam not required"); > YYERROR; > } > $$ = new_test(SPAM); }
===================================================================
RCS file: /cvs/src/cyrus/timsieved/scripttest.c,v
retrieving revision 1.18
diff -r1.18 scripttest.c
173a174,181
> #ifdef SPAMASSASSIN
> res = sieve_register_spam(i, (sieve_spam ) &foo);
> if (res != SIEVE_OK) {
> syslog (LOG_ERR, "sieve_register_spam() returns %d\n", res);
> return TIMSIEVE_FAIL;
> }
>
> #endif / SPAMASSASSIN */
=================================================================== RCS file: /cvs/src/sieve/sieve_interface.h,v retrieving revision 1.17 diff -r1.17 sieve_interface.h 52a53,56 > #ifdef SPAMASSASSIN > typedef int sieve_spam(void message_context, int is_spam); > > #endif / SPAMASSASSIN / 123a128,130 > #ifdef SPAMASSASSIN > int sieve_register_spam(sieve_interp_t interp, sieve_spam f); > #endif / SPAMASSASSIN /
From: Rob Siemborski
I don't think these patches work with 2.2, they don't support bytecode, for example.
Also, I'm not sure how to deal with the bytecode situation cleanly for a contrib patch like this, maybe it should just pick a high numbered opcode or something.
Then again, there is a draft out for a sieve spam extention currently. I'm pretty sure its likely to fluctuate though.
From: Bron Gondwana
Batch moving bugs that won't be in 2.5
From: Christian Schulte Bugzilla-Id: 1742 Version: 2.2.x Owner: Ken Murchison