-/* $Cambridge: exim/src/src/bmi_spam.c,v 1.2 2004/12/16 15:11:47 tom Exp $ */
-
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
-
+
/* Code for calling Brightmail AntiSpam.
Copyright (c) Tom Kistner <tom@duncanthrax.net> 2004
License: GPL */
uschar *host_address;
uschar *verdicts = NULL;
int i,j;
-
+
err = bmiInitSystem(BMI_VERSION, (char *)bmi_config_file, &system);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
err_loc = bmiErrorGetLocation(err);
for(i=0;i<recipients_count;i++) {
recipient_item *r = recipients_list + i;
BmiOptin *optin = NULL;
-
+
/* create optin object if optin string is given */
if ((r->bmi_optin != NULL) && (Ustrlen(r->bmi_optin) > 1)) {
debug_printf("passing bmiOptin string: %s\n", r->bmi_optin);
optin = NULL;
};
};
-
+
err = bmiAccumulateTO((char *)r->address, optin, message);
-
+
if (optin != NULL)
bmiOptinFree(optin);
-
+
if (bmiErrorIsFatal(err) == BMI_TRUE) {
err_loc = bmiErrorGetLocation(err);
err_type = bmiErrorGetType(err);
bmiFreeSystem(system);
return NULL;
};
-
+
/* Send message headers */
while (header_list != NULL) {
/* skip deleted headers */
bmiFreeSystem(system);
return NULL;
};
-
+
/* Send body */
data_file = fdopen(data_fd,"r");
do {
bmiFreeSystem(system);
return NULL;
};
-
-
+
+
/* End message */
err = bmiEndMessage(message);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
bmiFreeSystem(system);
return NULL;
};
-
+
/* get store for the verdict string */
verdicts = store_get(1);
*verdicts = '\0';
-
+
for ( err = bmiAccessFirstVerdict(message, &verdict);
verdict != NULL;
err = bmiAccessNextVerdict(message, verdict, &verdict) ) {
BmiErrorType err_type;
BmiVerdict *verdict = NULL;
int rc = 1; /* deliver by default */
-
+
/* always deliver when there is no verdict */
if (base64_verdict == NULL)
return 1;
}
else if (bmiVerdictDestinationIsDefault(verdict) == BMI_TRUE) {
/* deliver normally */
- rc = 1;
+ rc = 1;
}
else if (bmiVerdictAccessDestination(verdict) == NULL) {
/* do not deliver */
/* deliver to alternate location */
rc = 1;
};
-
+
bmiFreeVerdict(verdict);
return rc;
}
BmiErrorType err_type;
BmiVerdict *verdict = NULL;
uschar *rc = NULL;
-
+
/* always deliver when there is no verdict */
if (base64_verdict == NULL)
return NULL;
"bmi error [loc %d type %d]: bmiCreateVerdictFromStr() failed. [%s]", (int)err_loc, (int)err_type, base64_verdict);
return NULL;
};
-
+
err = bmiVerdictError(verdict);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
/* deliver normally due to error */
}
else if (bmiVerdictDestinationIsDefault(verdict) == BMI_TRUE) {
/* deliver normally */
- rc = NULL;
+ rc = NULL;
}
else if (bmiVerdictAccessDestination(verdict) == NULL) {
/* do not deliver */
Ustrcpy(rc, bmiVerdictAccessDestination(verdict));
rc[strlen(bmiVerdictAccessDestination(verdict))] = '\0';
};
-
+
bmiFreeVerdict(verdict);
return rc;
}
uschar *verdict_ptr;
uschar *verdict_buffer = NULL;
int sep = 0;
-
+
/* return nothing if there are no verdicts available */
if (bmi_verdicts == NULL)
return NULL;
-
+
/* allocate room for the b64 verdict string */
verdict_buffer = store_get(Ustrlen(bmi_verdicts)+1);
-
+
/* loop through verdicts */
verdict_ptr = bmi_verdicts;
while ((verdict_str = (const char *)string_nextinlist(&verdict_ptr, &sep,
verdict_buffer,
Ustrlen(bmi_verdicts)+1)) != NULL) {
-
+
/* create verdict from base64 string */
err = bmiCreateVerdictFromStr(verdict_str, &verdict);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
"bmi error [loc %d type %d]: bmiCreateVerdictFromStr() failed. [%s]", (int)err_loc, (int)err_type, verdict_str);
return NULL;
};
-
+
/* loop through rcpts for this verdict */
for ( recipient = bmiVerdictAccessFirstRecipient(verdict);
recipient != NULL;
recipient = bmiVerdictAccessNextRecipient(verdict, recipient)) {
uschar *rcpt_local_part;
uschar *rcpt_domain;
-
+
/* compare address against our subject */
rcpt_local_part = (unsigned char *)bmiRecipientAccessAddress(recipient);
rcpt_domain = Ustrchr(rcpt_local_part,'@');
/* found verdict */
bmiFreeVerdict(verdict);
return (uschar *)verdict_str;
- };
+ };
};
-
+
bmiFreeVerdict(verdict);
};
-
+
return NULL;
}
BmiErrorType err_type;
BmiVerdict *verdict = NULL;
uschar *rc = NULL;
-
+
/* always deliver when there is no verdict */
if (base64_verdict == NULL)
return NULL;
"bmi error [loc %d type %d]: bmiCreateVerdictFromStr() failed. [%s]", (int)err_loc, (int)err_type, base64_verdict);
return NULL;
};
-
+
/* create old tracker string from verdict */
err = bmiCreateOldStrFromVerdict(verdict, &rc);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
"bmi error [loc %d type %d]: bmiCreateOldStrFromVerdict() failed. [%s]", (int)err_loc, (int)err_type, base64_verdict);
return NULL;
};
-
+
bmiFreeVerdict(verdict);
return rc;
}
uschar *rule_ptr;
uschar rule_buffer[32];
int sep = 0;
-
-
+
+
/* no verdict -> no rule fired */
if (base64_verdict == NULL)
return 0;
-
+
/* create verdict from base64 string */
err = bmiCreateVerdictFromStr(CS base64_verdict, &verdict);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
"bmi error [loc %d type %d]: bmiCreateVerdictFromStr() failed. [%s]", (int)err_loc, (int)err_type, base64_verdict);
return 0;
};
-
+
err = bmiVerdictError(verdict);
if (bmiErrorIsFatal(err) == BMI_TRUE) {
/* error -> no rule fired */
bmiFreeVerdict(verdict);
return 0;
}
-
+
/* loop through numbers */
rule_ptr = option_list;
while ((rule_num = string_nextinlist(&rule_ptr, &sep,
rule_buffer, 32)) != NULL) {
int rule_int = -1;
-
+
/* try to translate to int */
- sscanf(rule_num, "%d", &rule_int);
+ (void)sscanf(rule_num, "%d", &rule_int);
if (rule_int > 0) {
debug_printf("checking rule #%d\n", rule_int);
/* check if rule fired on the message */