📄 bogoconfig.c
字号:
** The functions will exit if there's an error, for example if ** there are leftover command line arguments. */static void process_arglist(int argc, char **argv, priority_t precedence, int pass){ ex_t exitcode; if (pass != PASS_1_CLI) { optind = opterr = 1;#ifdef __EMX__ optind = 0;#endif /* don't use #ifdef here: */#if HAVE_DECL_OPTRESET optreset = 1;#endif } while (1) { int option; int option_index = 0; int this_option_optind = optind ? optind : 1; const char *name; option = getopt_long(argc, argv, OPTIONS, longopts_bogofilter, &option_index); if (option == -1) break; name = (option_index == 0) ? argv[this_option_optind] : longopts_bogofilter[option_index].name;#ifdef EXCESSIVE_DEBUG if (getenv("BOGOFILTER_DEBUG_OPTIONS")) { fprintf(stderr, "config: option=%c (%d), optind=%d, opterr=%d, optarg=%s\n", isprint((unsigned char)option) ? option : '_', option, optind, opterr, optarg ? optarg : "(null)"); }#endif process_arg(option, name, optarg, precedence, pass); } if (pass == PASS_1_CLI) { if (run_type == RUN_UNKNOWN) run_type = RUN_NORMAL; } if (pass == PASS_3_CLI) { exitcode = validate_args(); if (exitcode) exit(exitcode); if (bulk_mode == B_NORMAL && optind < argc) { fprintf(stderr, "Extra arguments given, first: %s. Aborting.\n", argv[optind]); exit(EX_ERROR); } if (inv_terse_mode) { verbose = max(1, verbose); /* force printing */ set_terse_mode_format(inv_terse_mode); } } return;}void process_arg(int option, const char *name, const char *val, priority_t precedence, arg_pass_t pass){ switch (option) { case '?': if (pass == PASS_1_CLI) fprintf(stderr, "Unknown option '%s'.\n", name); break; case 'b': bulk_mode = B_STDIN; fpin = NULL; /* Ensure that input file isn't stdin */ break; case 'B': bulk_mode = B_CMDLINE; break; case 'c': case O_CONFIG_FILE: if (pass == PASS_1_CLI) { if (!read_config_file(val, false, !quiet, PR_CFG_USER, longopts_bogofilter)) { fprintf(stderr, "Cannot open %s: %s\n", val, strerror(errno)); exit(EX_ERROR); } } /*@fallthrough@*/ /* fall through to suppress reading config files */ case 'C': if (pass == PASS_1_CLI) suppress_config_file = true; break; case O_USER_CONFIG_FILE: user_config_file = get_string(name, val); break; case 'D': dbgout = stdout; break; case 'e': case O_HAM_TRUE: nonspam_exits_zero = true; break; case 'h': help(stdout); exit(EX_OK); case 'I': if (pass == PASS_1_CLI) bogoreader_name(val); break; case 'L': logtag = xstrdup(val); /*@fallthrough@*/ case 'l': logflag = true; break; case 'M': mbox_mode = true; break; case 'n': run_type = check_run_type(REG_GOOD, REG_SPAM | UNREG_GOOD); break; case 'N': run_type = check_run_type(UNREG_GOOD, REG_GOOD | UNREG_SPAM); break; case 'O': if (pass == PASS_1_CLI) xstrlcpy(outfname, val, sizeof(outfname)); break; case 'p': passthrough = true; break; case 'q': quiet = true; break; case 'Q': if (pass == PASS_1_CLI) query += 1; break; case 'R': Rtable = true; break; case 's': run_type = check_run_type(REG_SPAM, REG_GOOD | UNREG_SPAM); break; case 'S': run_type = check_run_type(UNREG_SPAM, REG_SPAM | UNREG_GOOD); break; case 'u': run_type |= RUN_UPDATE; break; case 'U': unsure_stats = (val == NULL) ? true : get_bool(name, val); break; case 'v': if (pass == PASS_1_CLI) verbose++; break; case 'x': set_debug_mask( val ); break; case 'X': set_bogotest( val ); break; case 'y': /* date as YYYYMMDD */ { const char *str = val ? val : optarg; YYYYMMDD date = string_to_date(str); if (date != 0 && date < 19990000) { fprintf(stderr, "Date format for '-y' option is YYYYMMDD\n"); exit(EX_ERROR); } set_date( date ); break; } case ':': fprintf(stderr, "Option %s requires an argument.\n", name); exit(EX_ERROR); case '-': if (pass == PASS_3_CLI) process_config_option(val, true, precedence, longopts_bogofilter); break; case 'd': if (pass != PASS_1_CLI) set_wordlist_dir(val, precedence); break; case O_NS_ESF: if (pass != PASS_1_CLI) get_double(name, val, &ns_esf); break; case O_SP_ESF: if (pass != PASS_1_CLI) get_double(name, val, &sp_esf); break; case 'H': header_line_markup = (val == NULL) ? false : get_bool(name, val); break; case 'k': db_cachesize=atoi(val); break; case 'm': if (pass != PASS_1_CLI) { comma_parse(option, val, &min_dev, &robs, &robx); if (DEBUG_CONFIG(1)) fprintf(dbgout, "md %6.4f, rs %6.4f, rx %6.4f\n", min_dev, robs, robx); } break; case O_MIN_DEV: if (pass != PASS_1_CLI) get_double(name, val, &min_dev); break; case O_ROBS: if (pass != PASS_1_CLI) get_double(name, val, &robs); break; case O_ROBX: if (pass != PASS_1_CLI) get_double(name, val, &robx); break; case 'o': if (pass != PASS_1_CLI) { comma_parse(option, val, &spam_cutoff, &ham_cutoff, NULL); if (DEBUG_CONFIG(1)) fprintf(dbgout, "sc %6.4f, hc %6.4f\n", spam_cutoff, ham_cutoff); } break; case O_SPAM_CUTOFF: if (pass != PASS_1_CLI) get_double(name, val, &spam_cutoff); break; case O_HAM_CUTOFF: if (pass != PASS_1_CLI) get_double(name, val, &ham_cutoff); break; case 't': terse = true; break; case 'T': /* invariant terse mode */ terse = true; if (pass == PASS_1_CLI) inv_terse_mode += 1; break; case 'V': print_version(); exit(EX_OK); case O_BLOCK_ON_SUBNETS: block_on_subnets = get_bool(name, val); break; case O_CHARSET_DEFAULT: charset_default = get_string(name, val); break; case O_HEADER_FORMAT: header_format = get_string(name, val); break; case O_LOG_HEADER_FORMAT: log_header_format = get_string(name, val); break; case O_LOG_UPDATE_FORMAT: log_update_format = get_string(name, val); break; case O_MAX_TOKEN_LEN: max_token_len=atoi(val); break; case O_MIN_TOKEN_LEN: min_token_len=atoi(val); break; case O_MAX_MULTI_TOKEN_LEN: max_multi_token_len=atoi(val); break; case O_MULTI_TOKEN_COUNT: multi_token_count=atoi(val); break; case O_REPLACE_NONASCII_CHARACTERS: replace_nonascii_characters = get_bool(name, val); break; case O_SPAMICITY_FORMATS: set_spamicity_formats(val); break; case O_SPAMICITY_TAGS: set_spamicity_tags(val); break; case O_SPAM_HEADER_NAME: spam_header_name = get_string(name, val); break; case O_SPAM_SUBJECT_TAG: spam_subject_tag = get_string(name, val); break; case O_STATS_IN_HEADER: stats_in_header = get_bool(name, val); break; case O_TERSE: terse = get_bool(name, val); break; case O_TERSE_FORMAT: terse_format = get_string(name, val); break; case O_THRESH_UPDATE: get_double(name, val, &thresh_update); break; case O_TIMESTAMP: timestamp_tokens = get_bool(name, val); break; case O_UNSURE_SUBJECT_TAG: unsure_subject_tag = get_string(name, val); break; case O_UNICODE: encoding = get_bool(name, val) ? E_UNICODE : E_RAW; break; case O_WORDLIST: configure_wordlist(val); break; case O_DB_TRANSACTION: eTransaction = get_txn(name, val); break; default:#ifndef DISABLE_TRANSACTIONS if (!dsm_options_bogofilter(option, name, val))#endif { fprintf(stderr, "Invalid option '%s'.\n", name); exit(EX_ERROR); } }}#define Q1 if (query >= 1)#define Q2 if (query >= 2)#define YN(b) (b ? "Yes" : "No")#define NB(b) ((b != NULL && *b != '\0') ? b : "''")rc_t query_config(void){ Q1 fprintf(stdout, "# %s version %s\n", progname, version); Q1 fprintf(stdout, "\n"); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "robx", robx, robx); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "robs", robs, robs); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "min_dev", min_dev, min_dev); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "ham_cutoff", ham_cutoff, ham_cutoff); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "spam_cutoff", spam_cutoff, spam_cutoff); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "ns_esf", ns_esf, ns_esf); Q1 fprintf(stdout, "%-11s = %0.6f # (%8.2e)\n", "sp_esf", sp_esf, sp_esf); Q1 fprintf(stdout, "\n"); Q1 fprintf(stdout, "%-17s = %s\n", "block-on-subnets", YN(block_on_subnets)); Q1 fprintf(stdout, "%-17s = %s\n", "encoding", (encoding != E_UNICODE) ? "raw" : "utf-8"); Q1 fprintf(stdout, "%-17s = %s\n", "charset-default", charset_default); Q1 fprintf(stdout, "%-17s = %s\n", "replace-nonascii-characters", YN(replace_nonascii_characters)); Q2 fprintf(stdout, "%-17s = %s\n", "no-header-tags", YN(header_line_markup)); Q1 fprintf(stdout, "%-17s = %s\n", "stats-in-header", YN(stats_in_header)); Q2 fprintf(stdout, "%-17s = %s\n", "report-unsure", YN(unsure_stats)); Q1 fprintf(stdout, "%-17s = %0.6f\n", "thresh-update", thresh_update); Q1 fprintf(stdout, "%-17s = %s\n", "timestamp", YN(timestamp_tokens)); Q2 fprintf(stdout, "%-17s = %ld\n", "timestamp-date", (long int)today); Q1 fprintf(stdout, "\n"); Q1 fprintf(stdout, "%-17s = %s\n", "spam-header-name", spam_header_name); Q1 fprintf(stdout, "%-17s = %s\n", "spam-subject-tag", NB(spam_subject_tag)); Q1 fprintf(stdout, "%-17s = %s\n", "unsure-subject-tag", NB(unsure_subject_tag)); Q2 fprintf(stdout, "%-18s = %s\n", "syslog-tag", NB(logtag)); Q1 fprintf(stdout, "%-17s = %s\n", "header-format", header_format); Q1 fprintf(stdout, "%-17s = %s\n", "terse-format", terse_format); Q1 fprintf(stdout, "%-17s = %s\n", "log-header-format", log_header_format); Q1 fprintf(stdout, "%-17s = %s\n", "log-update-format", log_update_format); Q1 display_tag_array("spamicity-tags ", spamicity_tags); Q1 display_tag_array("spamicity-formats", spamicity_formats); Q2 fprintf(stdout, "\n"); Q2 fprintf(stdout, "%-18s = %s\n", "no-config-file", YN(suppress_config_file)); Q2 fprintf(stdout, "%-18s = %s\n", "config-file", NB(config_file_name)); Q2 fprintf(stdout, "%-18s = %s\n", "user-config-file", NB(user_config_file)); Q2 fprintf(stdout, "\n"); Q2 fprintf(stdout, "%-18s = %s\n", "bogofilter-dir", bogohome); Q2 display_wordlists(word_lists, "%-18s "); Q2 fprintf(stdout, "\n");#ifndef DISABLE_TRANSACTIONS Q2 fprintf(stdout, "%-18s = %lu\n", "db-cachesize", (unsigned long)db_cachesize);#ifdef ENABLE_TRANSACTIONS#ifdef HAVE_DECL_DB_CREATE Q2 fprintf(stdout, "%-18s = %s\n", "db-log-autoremove", YN(db_log_autoremove));#ifdef FUTURE_DB_OPTIONS Q2 fprintf(stdout, "%-18s = %s\n", "db-log-txn-durable", YN(db_txn_durable));#endif#endif#endif#endif return RC_OK;}static void display_tag_array(const char *label, FIELD *array){ int i; int count = (ham_cutoff < EPS) ? 2 : 3; fprintf(stdout, "%s =", label); for (i = 0; i < count; i += 1) fprintf(stdout, "%s %s", (i == 0) ? "" : ",", array[i]); fprintf(stdout, "\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -