1 ///###////////////////////////////////////////////////////////////////////////
2 //
3 // Burton Computer Corporation
4 // http://www.burton-computer.com
5 // http://www.cooldevtools.com
6 // $Id: TraditionalMailMessageParser.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 _TraditionalMailMessageParser_h
32 #define _TraditionalMailMessageParser_h
33 
34 #include "Message.h"
35 #include "MailMessage.h"
36 #include "RegularExpression.h"
37 #include "AbstractTokenReceiver.h"
38 #include "AbstractMailMessageParser.h"
39 
40 class AbstractTokenizer;
41 class ParserConfig;
42 class MessageHeader;
43 class MimeDecoder;
44 
45 class TraditionalMailMessageParser : public AbstractMailMessageParser, public AbstractTokenReceiver
46 {
47 public:
48   TraditionalMailMessageParser(ParserConfig *config);
49   virtual ~TraditionalMailMessageParser();
50 
51   virtual OWNED Message *parseMailMessage(MailMessage *source);
52 
53   void receiveToken(const string &prefix, const string &token);
54 
55 protected:
56   virtual void addDerivedTerms(const string &prefix,
57                                const string &token);
58   virtual void addTokenParts(const string &prefix,
59                              const string &token);
60 
61 private:
62   void addTerm(const string &prefix,
63                const string &term,
64                int flags);
65   bool isPhrase(const string &token);
66   void parseHeader(const MessageHeader *header,
67                    MimeDecoder *decoder);
68   void parseHtmlBodyText(const AbstractMultiLineString *text);
69   void parsePlainBodyText(const AbstractMultiLineString *text);
70   void parseBodyText(MailMessage *source);
71   void parseCharset(MailMessage *source,
72                     const string &prefix);
73   virtual void parseHeaders(MailMessage *source);
74   virtual void parseBody(MailMessage *source);
75   virtual OWNED AbstractTokenizer *createTokenizer();
76 
77 private:
78   string m_prefix;
79   Ptr<Message> m_message;
80   Ptr<AbstractTokenizer> m_textTokenizer;
81   Ptr<AbstractTokenizer> m_htmlTokenizer;
82   RegularExpression m_ipRegex;
83 
84   ParserConfig *m_config;
85 };
86 
87 #endif
88