Пример #1
0
int call_spamc(FILE *tmp_msg, char *user, int maxsize) {
   struct message msg;
   FILE *tmp_sa_msg;
   int tmp_msg_fd;
   int err,flags,is_spam;
   struct sockaddr addr;

   tmp_msg_fd=fileno(tmp_msg);
   flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK;
   
#if WITH_DEBUG == 1
       fprintf(stderr, "SpamAssassin Check\n");
#endif

   msg.max_len=maxsize;
   msg.type=MESSAGE_NONE;
   msg.raw=(char *)malloc(msg.max_len);
   
   err=lookup_host(SPAMD_HOST, SPAMD_PORT, &addr);
   if(err!=EX_OK) {
	   fprintf(stderr, "BARF on lookup_host (%d)\n",err);
	   return;
   }
   rewind(tmp_msg);
   err=message_read(tmp_msg_fd,SPAMC_RAW_MODE, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_read (%d)\n",err);
	return;
   }
   err=message_filter(&addr, user, flags|SPAMC_CHECK_ONLY, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_filter (%d)\n",err);
	return;
   }
   is_spam=msg.is_spam;
   /* 
    * We currently run the message through the filter twice.  Becuase
    * libspamc doesn't fill in all the msg structures w/o CHECK_ONLY
    * Until this is fixed or a better workaround comes up this is how
    * it is handled (one 'check only' and one real check)
    */
   rewind(tmp_msg);
   err=message_filter(&addr, user, flags, &msg);
   if(err != EX_OK) {
	fprintf(stderr, "BARF on message_filter (%d)\n",err);
	return;
   }
   rewind(tmp_msg);
   if(err=message_write(tmp_msg_fd, &msg)<0) {
	fprintf(stderr, "BARF on message_write (%d)\n",err);
	return;
   }
   /* Restore from the original is_spam check */
   msg.is_spam = is_spam;
   if(msg.is_spam == EX_TOOBIG) msg.is_spam=0; /* Ignore Too Big errs */

   return msg.is_spam;
}
Пример #2
0
static MsgStatus msg_is_spam(FILE *fp)
{
	struct transport trans;
	struct message m;
	gboolean is_spam = FALSE;

	if (!config.enable)
		return MSG_IS_HAM;

	transport_init(&trans);
	switch (config.transport) {
	case SPAMASSASSIN_TRANSPORT_LOCALHOST:
		trans.type = TRANSPORT_LOCALHOST;
		trans.port = config.port;
		break;
	case SPAMASSASSIN_TRANSPORT_TCP:
		trans.type = TRANSPORT_TCP;
		trans.hostname = config.hostname;
		trans.port = config.port;
		break;
	case SPAMASSASSIN_TRANSPORT_UNIX:
		trans.type = TRANSPORT_UNIX;
		trans.socketpath = config.socket;
		break;
	default:
		return MSG_IS_HAM;
	}

	if (transport_setup(&trans, flags) != EX_OK) {
		log_error(LOG_PROTOCOL, _("SpamAssassin plugin couldn't connect to spamd.\n"));
		debug_print("failed to setup transport\n");
		return MSG_FILTERING_ERROR;
	}

	m.type = MESSAGE_NONE;
	m.max_len = config.max_size * 1024;
	m.timeout = config.timeout;

	if (message_read(fileno(fp), flags, &m) != EX_OK) {
		debug_print("failed to read message\n");
		message_cleanup(&m);
		return MSG_FILTERING_ERROR;
	}

	if (message_filter(&trans, config.username, flags, &m) != EX_OK) {
		log_error(LOG_PROTOCOL, _("SpamAssassin plugin filtering failed.\n"));
		debug_print("filtering the message failed\n");
		message_cleanup(&m);
		return MSG_FILTERING_ERROR;
	}

	if (m.is_spam == EX_ISSPAM)
		is_spam = TRUE;

	message_cleanup(&m);

	return is_spam ? MSG_IS_SPAM:MSG_IS_HAM;
}