1/*
2 kmime_parsers.h
3
4 KMime, the KDE Internet mail/usenet news message library.
5 Copyright (c) 2001 the KMime authors.
6 See file AUTHORS for details
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23#ifndef __KMIME_PARSERS__
24#define __KMIME_PARSERS__
25
26#include<QByteArray>
27#include<QList>
28
29namespace KMime {
30
31namespace Parser {
32
33/** Helper-class: splits a multipart-message into single
34 parts as described in RFC 2046
35 @internal
36*/
37class MultiPart
38{
39 public:
40 MultiPart( const QByteArray &src, const QByteArray &boundary );
41 ~MultiPart() {}
42
43 bool parse();
44 QList<QByteArray> parts()
45 { return p_arts; }
46 QByteArray preamble()
47 { return p_reamble; }
48 QByteArray epilouge()
49 { return e_pilouge; }
50
51 protected:
52 QByteArray s_rc, b_oundary, p_reamble, e_pilouge;
53 QList<QByteArray> p_arts;
54};
55
56/** Helper-class: abstract base class of all parsers for
57 non-mime binary data (uuencoded, yenc)
58 @internal
59*/
60class NonMimeParser
61{
62 public:
63 explicit NonMimeParser( const QByteArray &src );
64 virtual ~NonMimeParser() {}
65 virtual bool parse() = 0;
66 bool isPartial()
67 {
68 return ( p_artNr > -1 && t_otalNr > -1 && t_otalNr != 1 );
69 }
70 int partialNumber()
71 { return p_artNr; }
72 int partialCount()
73 { return t_otalNr; }
74 bool hasTextPart()
75 { return ( t_ext.length() > 1 ); }
76 QByteArray textPart()
77 { return t_ext; }
78 QList<QByteArray> binaryParts()
79 { return b_ins; }
80 QList<QByteArray> filenames()
81 { return f_ilenames; }
82 QList<QByteArray> mimeTypes()
83 { return m_imeTypes; }
84
85 protected:
86 static QByteArray guessMimeType( const QByteArray &fileName );
87
88 QByteArray s_rc, t_ext;
89 QList<QByteArray> b_ins, f_ilenames, m_imeTypes;
90 int p_artNr, t_otalNr;
91};
92
93/** Helper-class: tries to extract the data from a possibly
94 uuencoded message
95 @internal
96*/
97class UUEncoded : public NonMimeParser
98{
99 public:
100 UUEncoded( const QByteArray &src, const QByteArray &subject );
101
102 virtual bool parse();
103
104 protected:
105 QByteArray s_ubject;
106};
107
108/** Helper-class: tries to extract the data from a possibly
109 yenc encoded message
110 @internal
111*/
112class YENCEncoded : public NonMimeParser
113{
114 public:
115 explicit YENCEncoded( const QByteArray &src );
116
117 virtual bool parse();
118 QList<QByteArray> binaryParts()
119 { return b_ins; }
120
121 protected:
122 QList<QByteArray> b_ins;
123 static bool yencMeta( QByteArray &src, const QByteArray &name, int *value );
124};
125
126} // namespace Parser
127
128} // namespace KMime
129
130#endif // __KMIME_PARSERS__
131