1 ///###////////////////////////////////////////////////////////////////////////
2 //
3 // Burton Computer Corporation
4 // http://www.burton-computer.com
5 // http://www.cooldevtools.com
6 // $Id: AutoPurger.cc 272 2007-01-06 19:37:27Z brian $
7 //
8 // Copyright (C) 2007 Burton Computer Corporation
9 // ALL RIGHTS RESERVED
10 //
11 // This program is open source software; you can redistribute it
12 // and/or modify it under the terms of the Q Public License (QPL)
13 // version 1.0. Use of this software in whole or in part, including
14 // linking it (modified or unmodified) into other programs is
15 // subject to the terms of the QPL.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // Q Public License for more details.
21 //
22 // You should have received a copy of the Q Public License
23 // along with this program; see the file LICENSE.txt.  If not, visit
24 // the Burton Computer Corporation or CoolDevTools web site
25 // QPL pages at:
26 //
27 //    http://www.burton-computer.com/qpl.html
28 //    http://www.cooldevtools.com/qpl.html
29 //
30 
31 #include "CleanupManager.h"
32 #include "CommandConfig.h"
33 #include "ConfigManager.h"
34 #include "FrequencyDB.h"
35 #include "SpamFilter.h"
36 #include "AutoPurger.h"
37 
AutoPurger(const ConfigManager & config,SpamFilter & filter,int junk_count)38 AutoPurger::AutoPurger(const ConfigManager &config,
39                        SpamFilter &filter,
40                        int junk_count)
41   : m_cleaner(new CleanupManager(junk_count, -1)), // -1 forces today's to be removed too
42     m_db(filter.getDB()),
43     m_messageCount(0),
44     m_messagesPerPurge(config.commandConfig()->messagesPerPurge())
45 {
46 }
47 
~AutoPurger()48 AutoPurger::~AutoPurger()
49 {
50 }
51 
disable()52 void AutoPurger::disable()
53 {
54   m_messagesPerPurge = 0;
55 }
56 
processedMessage()57 void AutoPurger::processedMessage()
58 {
59   if (m_messagesPerPurge > 0) {
60     ++m_messageCount;
61     if (m_messageCount % m_messagesPerPurge == 0) {
62       m_db->sweepOutOldTerms(*m_cleaner);
63     }
64   }
65 }
66 
finish()67 void AutoPurger::finish()
68 {
69   if (m_messagesPerPurge > 0) {
70     if (m_messageCount % m_messagesPerPurge != 0) {
71       m_db->sweepOutOldTerms(*m_cleaner);
72     }
73   }
74 }
75