Пример #1
0
static uint read_mailbox(const char *arg, mlhead_t *msgs)
{
    if (verbose) {
	printf("Reading %s\n", arg);
	fflush(stdout);
    }

    init_count();
    mbox_mode = true;
    bogoreader_init(1, &arg);
    while ((*reader_more)()) {
	wordhash_t *whp = NULL;
	wordhash_t *whc = wordhash_new();

	collect_words(whc);

	if (ds_path != NULL && (msgs_good + msgs_bad) == 0)
	    set_train_msg_counts(whc);

	if (whc->count == 0 && !quiet) {
	    printf("msg #%u, count is %u\n", message_count, whc->count);
	    bt_trap();
	}

	if (bogolex_file != NULL) {
	    wordhash_sort(whc);
	    lookup_words(whc);
	    write_msgcount_file(whc);
	}
	else if (whc->count != 0) {
	    if (!msg_count_file)
		whp = convert_wordhash_to_propslist(whc, train);
	    else
		whp = convert_propslist_to_countlist(whc);
	    msglist_add(msgs, whp);
	}

	update_count();
	
	if (whc != whp)
	    wordhash_free(whc);
    }

    print_final_count();

    ns_and_sp->count += message_count;
    bogoreader_fini();

    return message_count;
}
Пример #2
0
int	work_rr (
		struct error_data *errors,
		struct name_context *context,
		u_int8_t **rr,
		char **non_rr)
{
	char			first_token[MAXTOKENLENGTH];
	int				ret_code;
	int				i;
	struct scratch	scratch;

	/* Memory management clean up */
	if (*rr)
	{
		FREE (*rr);
		*rr = NULL;
	}

	if (*non_rr)
	{
		FREE (*non_rr);
		*non_rr = NULL;
	}

	if ((scratch.s_field = (u_int8_t *) MALLOC(RR_SCRATCH_LENGTH)) == NULL)
	{
		errors->ed_error_value = ERR_OUTOFMEMORY;
		return -1;
	}

	scratch.s_length = RR_SCRATCH_LENGTH;

	/* Source of data is hidden, just use GETWORD() to work my way through it */

	/* Initialize errors to 'nothing set' */
	errors->ed_error_value = ERR_UNSET;

	do
	{
		GETWORDorEOLN (ret_code, errors, first_token, sizeof(first_token), *non_rr, "First word",
						FREE_SCRATCH_UPDATE_ERRORS_AND_RETURN_NEG1);

		if (ret_code == GW_EOLN)
		{
			errors->ed_curr_line++;
			decrement_current_line();
		}
	} while (ret_code == GW_EOLN);

	/* ret_code must be GW_WORD and first_token is the first word in line */
	/*
		If the beginning of the first word is in special_chars,
		then
			get words until GW_EOLN is returned
			problem - storing the words until we MALLOC non_rr
			assemble them into *non_rr
			return ERR_OKBUTNOTRR in error structure, other ancillarys
		else
			take the first word as the name and parse the envelope
			depending on the type value, parse the remainder of the record
			no matter what happens, read tokens up through GW_EOLN
	*/

	/*
		This takes care of all the specially registered characters,
		processing and returning anything that is not an RR.
	*/
	for (i =0; i < special_count; i++)
		if (first_token[0]==special_chars[i])
		{
			/* return with
				all of the upcoming line in *non_rr,
				*rr = NULL (already is),
				errors stating OKBUTNOTRR and update its line count.
			*/
			*non_rr = collect_words (first_token);
			errors->ed_curr_line=errors->ed_curr_line+current_line();
			if (*non_rr)
				errors->ed_error_value = ERR_OKBUTNOTRR;
			else
				errors->ed_error_value = ERR_OUTOFMEMORY;
			FREE (scratch.s_field);
			return -1;
		}

	/* Now we can set about the business of parsing RR's */
	/* Two parts, the envelope, the rdata */

	ret_code = parse_record (&scratch, first_token, errors, context, non_rr);

	/* Final clean up */

	if (ret_code==0)
	{
		if ((*rr = (u_int8_t*) MALLOC (scratch.s_index))==NULL)
		{
			errors->ed_error_value = ERR_OUTOFMEMORY;
			return -1;
		}
		memcpy (*rr, scratch.s_field, scratch.s_index);
	}

	errors->ed_curr_line=errors->ed_curr_line+current_line();
	FREE (scratch.s_field);
	return ret_code;
}