# HG changeset patch # User carl # Date 1183868678 25200 # Node ID 89ce226e5383b8805276fdf9633ddc3962e15649 # Parent 8d7c439bb6fa9438488e7ead552f0e2aaa32a9f1 add auto whitelisting diff -r 8d7c439bb6fa -r 89ce226e5383 src/context.cpp --- a/src/context.cpp Sat Jul 07 16:10:39 2007 -0700 +++ b/src/context.cpp Sat Jul 07 21:24:38 2007 -0700 @@ -425,6 +425,22 @@ days = d; pthread_mutex_init(&mutex, 0); need = false; + ifstream ifs; + ifs.open(fn); + if (!ifs.fail()) { + const int maxlen = 1000; + char buf[maxlen]; + while (ifs.getline(buf, maxlen)) { + char *p = strchr(buf, ' '); + if (p) { + *p = '\0'; + char *who = strdup(buf); + int when = atoi(p+1); + rcpts[who] = when; + } + } + } + ifs.close(); } @@ -434,6 +450,8 @@ for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end();) { time_t when = (*i).second; if (when < limit) { + char *who = (*i).first; + free(who); autowhite_sent::iterator j = i; j++; rcpts.erase(i); @@ -444,22 +462,23 @@ } if (need) { // dump the file - ofstream os; - os.open(fn); - if (!os.fail()) { + ofstream ofs; + ofs.open(fn); + if (!ofs.fail()) { for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) { char *who = (*i).first; int when = (*i).second; - os << who << " " << when << endl; + ofs << who << " " << when << endl; } } - os.close(); + ofs.close(); } pthread_mutex_unlock(&mutex); } void WHITELISTER::sent(char *to) { + // we take ownership of the string pthread_mutex_lock(&mutex); need = true; rcpts[to] = time(NULL); diff -r 8d7c439bb6fa -r 89ce226e5383 src/dnsbl.cpp --- a/src/dnsbl.cpp Sat Jul 07 16:10:39 2007 -0700 +++ b/src/dnsbl.cpp Sat Jul 07 21:24:38 2007 -0700 @@ -1026,8 +1026,7 @@ WHITELISTERP w = con2.find_autowhite(priv.mailaddr); if (w) { char *loto = to_lower_string(rcptaddr); - w->sent(loto); - free(loto); + w->sent(loto); // don't free it, the whitelister takes ownership of the string } // accept the recipient if (!con.get_content_filtering()) st = white;