diff options
author | John Denker <jsd@av8n.com> | 2012-07-19 23:27:34 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-07-19 23:27:34 -0700 |
commit | ed7b4fbb1101641b26aad3e3376fca8586f66f09 (patch) | |
tree | 143e0a94ffb85165091165684a7c5e479f8be5da | |
parent | 7756dc94224fdc5dce70e15231f13915be979b0f (diff) |
implement probation period
-rw-r--r-- | tools/greylist.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/tools/greylist.c b/tools/greylist.c index 613c1a4..1e62e93 100644 --- a/tools/greylist.c +++ b/tools/greylist.c @@ -23,6 +23,8 @@ const int hour(60*minute); const int day(24*hour); const int minimum_age(5*minute); +const int maximum_age(32*day); +const int probation(4*hour); const int sa_good = 0; const int bug_bait_grey = 1; // qmail_queue and spamc have similar interpretations here: @@ -73,9 +75,16 @@ string time_out(const int ttt){ int min((ttt / 60) % 60); int hr(ttt / 3600); stringstream foo; - foo << hr - << ":" << setw(2) << setfill('0') << min - << ":" << setw(2) << setfill('0') << sec; + int didsome(0); + if (hr) { + foo << hr << ":"; + didsome++; + } + if (didsome || min){ + foo << setw(didsome?2:1) << setfill('0') << min << ":"; + didsome++; + } + foo << setw(didsome?2:1) << setfill('0') << sec; return foo.str(); } @@ -102,10 +111,18 @@ void scan(const string p){ int ac_age = now.tv_sec - mystat.st_atime; cout << setw(10) << time_out(mod_age) << " " << setw(10) << time_out(ac_age); - if (mod_age < minimum_age) { + if (mod_age - ac_age < minimum_age // early bird, or completely unused + && mod_age > probation) { // did not diligently resubmit + cout << " disprobation"; + if (mod_age != ac_age) cout << "!"; + } else if (mod_age < minimum_age) { cout << " young"; } else if (mod_age == ac_age) { cout << " unused"; + } else if (mod_age > maximum_age) { + cout << " expired"; + } else { + cout << " OK"; } } cout << '\n'; @@ -209,12 +226,16 @@ int whatsit::doit(){ update("early bird", mod_orig, now); return(bug_bait_grey); } - if (ac_age < 32*day) { - update("returning customer", mod_orig, now); - return 0; + if (mod_age - ac_age < minimum_age // early bird, or completely unused + && mod_age > probation) { // did not diligently resubmit + update("disprobation", now, now); + return(bug_bait_grey); } - -// here if it is too old: - update("too old, starting over", now, now); - return(bug_bait_grey); -}
\ No newline at end of file + if (ac_age > maximum_age) { + update("too old, starting over", now, now); + return(bug_bait_grey); + } +// if all checks are passed, must be OK: + update("returning customer", mod_orig, now); + return 0; +} |