1 ///###//////////////////////////////////////////////////////////////////////// 2 // 3 // Burton Computer Corporation 4 // http://www.burton-computer.com 5 // http://www.cooldevtools.com 6 // $Id: AutoTrainMailMessageReader.h 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 #ifndef _AutoTrainMessageReader_h 32 #define _AutoTrainMessageReader_h 33 34 #include <deque> 35 #include <fstream> 36 #include "File.h" 37 #include "AbstractMailMessageReader.h" 38 #include "MailMessageReaderFactory.h" 39 40 class AutoTrainMailMessageReader : public AbstractMailMessageReader 41 { 42 public: 43 AutoTrainMailMessageReader(); 44 ~AutoTrainMailMessageReader(); 45 46 void addMailboxFile(bool is_spam, const string &path); 47 48 OWNED MailMessage *readMessage(); 49 messageWasSpam()50 bool messageWasSpam() 51 { 52 return m_messageWasSpam; 53 } 54 messageFile()55 const File &messageFile() 56 { 57 return m_messageFile; 58 } 59 60 private: 61 /// Not implemented. 62 AutoTrainMailMessageReader(const AutoTrainMailMessageReader &); 63 64 /// Not implemented. 65 AutoTrainMailMessageReader& operator=(const AutoTrainMailMessageReader &); 66 67 private: 68 bool shouldUseSpam(); 69 long countMessagesInFile(const string &path); 70 void openFile(const string &path, 71 Ptr<AbstractMailMessageReader> &reader); 72 bool readMessage(deque<string> &paths, 73 string &path, 74 Ptr<AbstractMailMessageReader> &reader, 75 Ptr<MailMessage> &message); 76 bool readMessage(bool is_spam, 77 Ptr<MailMessage> &message); 78 79 private: 80 long m_spamCount; 81 long m_totalCount; 82 deque<string> m_spamPaths; 83 deque<string> m_goodPaths; 84 MailMessageReaderFactory m_readerFactory; 85 86 bool m_messageWasSpam; 87 File m_messageFile; 88 string m_spamPath; 89 string m_goodPath; 90 Ptr<AbstractMailMessageReader> m_spamReader; 91 Ptr<AbstractMailMessageReader> m_goodReader; 92 }; 93 94 #endif // _AutoTrainMailMessageReader_h 95