summaryrefslogtreecommitdiffstats
path: root/libkmime/kmime_parsers.h
blob: b16b0b6a7b1ac9e24647b8fae07b0a0c87301a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
    kmime_parsers.h

    KMime, the KDE internet mail/usenet news message library.
    Copyright (c) 2001 the KMime authors.
    See file AUTHORS for details

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/
#ifndef __KMIME_PARSERS__
#define __KMIME_PARSERS__

#include <tqvaluelist.h>
#include <tqcstring.h>
#include <tqstrlist.h>

namespace KMime {

namespace Parser {

/** Helper-class: splits a multipart-message into single
    parts as described in RFC 2046
    @internal
*/
class MultiPart {
  
public:
  MultiPart(const TQCString &src, const TQCString &boundary);
  ~MultiPart() {};
  
  bool parse();
  TQValueList<TQCString> parts()    { return p_arts; }
  TQCString preamble()     { return p_reamble; }
  TQCString epilouge()     { return e_pilouge; }
  
protected:
  TQCString s_rc, b_oundary, p_reamble, e_pilouge;
  TQValueList<TQCString> p_arts;
};


/** Helper-class: abstract base class of all parsers for
    non-mime binary data (uuencoded, yenc)
    @internal
*/
class NonMimeParser {

public:
  NonMimeParser(const TQCString &src);
  virtual ~NonMimeParser() {};
  virtual bool parse() = 0;
  bool isPartial()            { return (p_artNr>-1 && t_otalNr>-1 && t_otalNr!=1); }
  int partialNumber()         { return p_artNr; }
  int partialCount()          { return t_otalNr; }
  bool hasTextPart()          { return (t_ext.length()>1); }
  TQCString textPart()         { return t_ext; }
  TQStrList binaryParts()       { return b_ins; }
  TQStrList filenames()         { return f_ilenames; }
  TQStrList mimeTypes()         { return m_imeTypes; }

protected:
  static TQCString guessMimeType(const TQCString& fileName);

  TQCString s_rc, t_ext;
  TQStrList b_ins, f_ilenames, m_imeTypes;
  int p_artNr, t_otalNr;
};


/** Helper-class: tries to extract the data from a possibly
    uuencoded message
    @internal
*/
class UUEncoded : public NonMimeParser {

public:
  UUEncoded(const TQCString &src, const TQCString &subject);  

  virtual bool parse();

protected:
  TQCString s_ubject;  
};



/** Helper-class: tries to extract the data from a possibly
    yenc encoded message
    @internal
*/
class YENCEncoded : public NonMimeParser {

public:
  YENCEncoded(const TQCString &src);  

  virtual bool parse();      
  TQValueList<TQByteArray> binaryParts()       { return b_ins; }
    
protected:
  TQValueList<TQByteArray> b_ins;
  static bool yencMeta( TQCString& src, const TQCString& name, int* value);
};


} // namespace Parser

} // namespace KMime

#endif // __KMIME_PARSERS__