XMailforum is a readonly knowledge archive now.

Registering as a new user or answering posts is not possible anymore.

Might the force be with you, to find here what you are looking for.

2019-09-20 - hschneider, Admin

Cookie Disclaimer: This forum uses only essential, anonymous session cookies (xmailforum*), nothing to be scared of.

XMail Forum -> Howto: Linux + Xmail + Dspam

Reply to this topicStart new topicStart Poll

> Howto: Linux + Xmail + Dspam
Sob
Posted: Jan 1 2009, 05:09 PM
Quote Post


Member
***

Group: Members
Posts: 53
Member No.: 2881
Joined: 19-April 08



The following is "works fine for me" solution. It delivers all messages, the spam is only tagged.
In theory it could be modified to start from filters.post-data.tab, instead of filters.in.tab and then it should be possible to reject spam messages before accepting them. But I don't really like this approach, because in case of false positive, the message would be lost.

Simple howto:

1) Install and configure DSPAM

You need to compile it with --enable-virtual-users and --enable-daemon (possibly optional).
In dspam.conf set:

CODE
Preference "spamAction=tag"
Preference "spamSubject=[SPAM] "


If you're running non-root XMail, don't forget to add:

CODE
Trust <xmailuser>


Run DSPAM as daemon:

CODE
/usr/bin/dspam --daemon


Test that it works:

CODE
dspam --user user@example.net --client --deliver=innocent,spam --stdout < somemessage.txt


It should output processed content of somemessage.txt

2) Install it into XMail

Create $MAIL_ROOT/filters/dspam with following content:

CODE
"/path/to/dspam-filter"[TAB]"$(RRCPT)"[TAB]"$(FILE)"


Add this line to filters.in.tab:

CODE
"*"[TAB]"*"[TAB]"::/0"[TAB]"::/0"[TAB]"dspam"


It activates DSPAM processing for all users. See XMail manual if you need it only for selected ones.

3) It should work! smile.gif

dspam-filter.c:
CODE
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

void fail(char *msg, int code) {
 //debugonly: printf("FAIL: %s\n", msg);
 exit(code);
}

int main(int iArgCount, char *pszArgs[]) {
 FILE *fdata, *fpipe, *fmail;
 char line[1024];
 char command[1024];
 char mailfile[]="/tmp/dsfilter_XXXXXX";
 char separator[]="<<MAIL-DATA>>";
 long datapos;
 int header=1;
 int len;
 int fd = -1;

 if(iArgCount!=3) fail("usage: dspam-filter <recipicient> <message file>", 0);
 if((fdata=fopen(pszArgs[2], "r+"))==NULL) fail("Can't open input file", 0);
 if((fd=mkstemp(mailfile))<0) fail("Can't create mail temporary file", 0);
 fmail=fdopen(fd, "w");
 if((fmail=fdopen(fd, "w"))==NULL) {
   unlink(mailfile);
   close(fd);
   fail("Can't open mail temporary file", 0);
 }
 //
 while(fgets(line, sizeof(line), fdata)) {
   if(!header) fputs(line, fmail);
   if(strncmp(line, separator, sizeof(separator)-1)==0) {
     header=0;
     datapos=ftell(fdata);
   }
 }
 fclose(fmail);
 //
 /* remove "--client" if you want to use DSPAM without daemon (not tested) */
 sprintf(command, "dspam --user %s --client --deliver=innocent,spam --stdout < %s",
         pszArgs[1], mailfile);
 if(!(fpipe=(FILE*)popen(command,"r"))) fail("Problems with pipe", 0);
 //
 fseek(fdata, datapos, 0);
 while(fgets(line, sizeof(line), fpipe)) {
   /* for use in filters.post-data.tab (not tested):
   if line is "X-DSPAM-Result: Spam" then:
     - optionally create .rej file with some nice "Keep your spam to yourself!" message
     - exit(5)
   */
   len=strlen(line);
   if(line[len-2]!=0x0d) {
       line[len-1]=0x0d;
       line[len+0]=0x0a;
       line[len+1]=0x00;
   }
   fputs(line, fdata);
 }
 pclose(fpipe);
 unlink(mailfile);
 //
 exit(7);
}


Compile with:

CODE
gcc -o dspam-filter dspam-filter.c

PMEmail Poster
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Fighting SPAM | Next Newest »

Reply to this topicStart new topicStart Poll