RE: [dspam-users] Example.c File

From: . kibble . <jelly_bean_junky@hotmail.com>
Date: Fri Sep 09 2005 - 12:40:52 EDT

Got it working, however not in a way that I totally think is right... I've
classified the message to generate the signature [&SIG] and then set it as
you pointed out was wrong in the last email.

However I'm not entirely sure why it worked before and not now... Was there
some piece of code which worked out that CTX->signature was NULL and then
reclassified the message anyways?? If this has changed, I'm curious to know
why exactly, redundant code perhaps... Only the developers will know. [Care
to shed any light in this area]

Anyway's, here what I did for future use and thank you for the help:
/** some function or another... */
        int sflag = 0;
        char * message = malloc(1);
        DSPAM_CTX * CTX = NULL; /** DSPAM Context */
        struct _ds_spam_signature SIG; /** Example signature */

        message = read_emailmem(message);

        switch (spamflag) {
                case SPAMREPT: /** set up the context for error correction as spam */
                        /** log_write(0, LOG_MAIN, "LOG: SPAMREPT function reached"); */
                        CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
DSF_CHAINED);
                        CTX = attach_ctx_dbaccess(CTX);
                        if (CTX == NULL) {
                                log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n");
                                sflag = 1;
                        }
                        CTX->classification = DSR_ISSPAM;
                        CTX->source = DSS_ERROR;
                        CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
                        break;
                case FALSEPOS: /** set up the context for error correction as innocent */
                        /** log_write(0, LOG_MAIN, "LOG: FALSEPOS function reached"); */
                        CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
DSF_SBPH | DSF_SIGNATURE | DSF_NOISE);
                        CTX = attach_ctx_dbaccess(CTX);
                        if (CTX == NULL) {
                                log_write(0, LOG_MAIN, "dspam_create failed!");
                                break;
                        }
                        CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
                        if (dspam_process(CTX, message) != 0) { /** Call DSPAM's processor with
the message text */
                                log_write(0, LOG_MAIN, "dspam_process failed!");
                                dspam_destroy(CTX);
                                break;
                        }
                        if (CTX->signature != NULL) {
                                SIG.data = malloc(CTX->signature->length);
                                if (SIG.data != NULL) {
                                        memcpy(SIG.data, CTX->signature->data, CTX->signature->length);
                                }
                        }
                        SIG.length = CTX->signature->length;

                        dspam_destroy(CTX); /** Destroy the context */
                        memset(&CTX, 0x0, sizeof(CTX));
                        free(CTX);

                        CTX = dspam_create((char *)sender_address, NULL, NULL, DSM_PROCESS,
DSF_CHAINED | DSF_SIGNATURE);
                        CTX = attach_ctx_dbaccess(CTX);
                        if (CTX == NULL) {
                                log_write(0, LOG_MAIN, "ERROR: dspam_create failed!\n");
                                sflag = 1;
                        }
                        CTX->classification = DSR_ISINNOCENT;
                        CTX->source = DSS_ERROR;
                        CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
                        CTX->signature = &SIG; /** Attach the signature to the context */
                        break;
                default: /** no reporting required, scan for spam perhaps ? */
                        log_write(0, LOG_MAIN, "report_spam -> no reporting required");
                        break;
        }

        /** log_write(0, LOG_MAIN, "LOG: Processing spam..."); */
        if (dspam_process(CTX, message) != 0) { /** Call DSPAM */
                log_write(0, LOG_MAIN, "ERROR: dspam_process failed!");
                sflag = 1;
        }

/** end of snippit */

>From: ". kibble ." <jelly_bean_junky@hotmail.com>
>To: dspam-users@lists.nuclearelephant.com
>Subject: RE: [dspam-users] Example.c File
>Date: Wed, 07 Sep 2005 22:11:47 +0100
>
>
>Excellent, thanks for the pointer, I will do this over the next few days as
>I'm away but will take the laptop with me and a copy of dspam's source code
>to review...
>
>>From: "Russ Fink" <russfink@hotmail.com>
>>To: jelly_bean_junky@hotmail.com, dspam-users@lists.nuclearelephant.com
>>Subject: RE: [dspam-users] Example.c File
>>Date: Wed, 07 Sep 2005 11:21:22 -0400
>>
>>Sorry, I have been out for a few days.
>>
>>From your code snippet, I don't see where SIG is getting populated, just
>>declared. The code sets CTX->signature to &SIG, but SIG has nothing in it
>>- just an empty structure at this point. You need to populate it using
>>the driver of MySQL.
>>
>>My advice, what I would have to do, is look at how dspam.c does it. Grep
>>for "signature" and you should find the answer.
>>
>>In generic terms, the spam "signature" is really a unique identifier
>>assigned by the back-end database implementation. In the case of sqlite3,
>>it takes a hash of the system time and date and assigns that as the
>>signature of the message. Of course, this assumes only one message is
>>processed at a given time/date, and I believe this will be changed at some
>>point in the future. The "CTX->signature" is a pointer to the signature
>>structure, which is created from this hash by a call.
>>
>>If you're using pristine mode, no signature is needed, and no signature is
>>generated.
>>
>>Spend some time with dspam.c and it should help. I think that's kinda
>>what everyone else does that programs directly to the API.
>>
>>Russ
>>
>>>>>int report_spam(int spamflag) {
>>>>>
>>>>> int sflag = 0;
>>>>> char * message = malloc(1);
>>>>> DSPAM_CTX * CTX = NULL; /** DSPAM Context */
>>>>> struct _ds_spam_signature SIG; /** Example signature */
>>>>>
>>>>> message = read_emailmem(message);
>>>>>
>>>>> switch (spamflag) {
>>>>> case SPAMREPT: /** set up the context for error correction
>>>>>as spam */
>>>>> log_write(0, LOG_MAIN, "LOG: SPAMREPT function reached");
>>>>> CTX = dspam_create((char *)sender_address, NULL, NULL,
>>>>>DSM_PROCESS, DSF_CHAINED);
>>>>> CTX = attach_ctx_dbaccess(CTX);
>>>>> if (CTX == NULL) {
>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_create
>>>>>failed!\n");
>>>>> sflag = 1;
>>>>> }
>>>>> CTX->classification = DSR_ISSPAM;
>>>>> CTX->source = DSS_ERROR;
>>>>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
>>>>> break;
>>>>> case FALSEPOS: /** set up the context for error correction
>>>>>as innocent */
>>>>> log_write(0, LOG_MAIN, "LOG: FALSEPOS function reached");
>>>>> CTX = dspam_create((char *)sender_address, NULL, NULL,
>>>>>DSM_PROCESS, DSF_CHAINED | DSF_SIGNATURE);
>>>>> CTX = attach_ctx_dbaccess(CTX);
>>>>> if (CTX == NULL) {
>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_create
>>>>>failed!\n");
>>>>> sflag = 1;
>>>>> }
>>>>> CTX->classification = DSR_ISINNOCENT;
>>>>> CTX->source = DSS_ERROR;
>>>>> CTX->algorithms = DSA_GRAHAM | DSA_BURTON | DSP_GRAHAM;
>>>>> CTX->signature = &SIG; /** Attach the signature to
>>>>>the context */
>>>>> break;
>>>>> default: /** no reporting required, scan for spam perhaps ?
>>>>>*/
>>>>> log_write(0, LOG_MAIN, "report_spam -> no reporting
>>>>>required");
>>>>> break;
>>>>> }
>>>>>
>>>>> log_write(0, LOG_MAIN, "LOG: Processing spam...");
>>>>> if (dspam_process(CTX, message) != 0) { /** Call DSPAM */
>>>>> log_write(0, LOG_MAIN, "ERROR: dspam_process failed!");
>>>>> sflag = 1;
>>>>> }
>>>>>
>>>>> log_write(0, LOG_MAIN, "ERROR: report_spam: dspam_destroy
>>>>>beginning");
>>>>> dspam_destroy(CTX); /** Destroy the context */
>>>>>
>>>>> memset(message, 0x0, sizeof(message));
>>>>> free(message);
>>>>> memset(&CTX, 0x0, sizeof(CTX));
>>>>> free(CTX);
>>>>>
>>>>> if (sflag == 0) {
>>>>> log_write(0, LOG_MAIN, "<= %s [%s] P=%s A=%s:%s",
>>>>> (char *)sender_address, (char *)sender_host_address, (char
>>>>>*)received_protocol,
>>>>> (char *)sender_host_authenticated, (char *)sender_address);
>>>>> log_write(0, LOG_MAIN, "=> (null) <%s> R=system_localuser
>>>>>T=local_delivery",
>>>>> (char *)recipients_list[0].address);
>>>>> }
>>>>>
>>>>> /** if we are reporting, which is pretty much so if you reach here,
>>>>>we blackhole the email */
>>>>> recipients_count = 0;
>>>>>
>>>>> return(sflag);
>>>>>} /** report_spam */
>>
>>
>
>_________________________________________________________________
>Be the first to hear what's new at MSN - sign up to our free newsletters!
>http://www.msn.co.uk/newsletters
>
>

_________________________________________________________________
MSN Messenger 7.5 is now out. Download it for FREE here.
http://messenger.msn.co.uk
Received on Fri Sep 9 12:42:01 2005

This archive was generated by hypermail 2.1.8 : Thu Sep 29 2005 - 13:51:29 EDT