KMime

kmime_parsers.h
1 /*
2  kmime_parsers.h
3 
4  KMime, the KDE Internet mail/usenet news message library.
5  SPDX-FileCopyrightText: 2001 the KMime authors.
6  See file AUTHORS for details
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 #pragma once
11 
12 #include <QByteArray>
13 #include <QVector>
14 
15 namespace KMime
16 {
17 
18 namespace Parser
19 {
20 
21 /** Helper-class: splits a multipart-message into single
22  parts as described in RFC 2046
23  @internal
24 */
25 class MultiPart
26 {
27 public:
28  MultiPart(const QByteArray &src, const QByteArray &boundary);
29 
30  Q_REQUIRED_RESULT bool parse();
31  Q_REQUIRED_RESULT QVector<QByteArray> parts() const
32  {
33  return m_parts;
34  }
35  Q_REQUIRED_RESULT QByteArray preamble() const
36  {
37  return m_preamble;
38  }
39  Q_REQUIRED_RESULT QByteArray epilouge() const
40  {
41  return m_epilouge;
42  }
43 
44 private:
45  QByteArray m_src;
46  const QByteArray m_boundary;
47  QByteArray m_preamble;
48  QByteArray m_epilouge;
49  QVector<QByteArray> m_parts;
50 };
51 
52 /** Helper-class: abstract base class of all parsers for
53  non-mime binary data (uuencoded, yenc)
54  @internal
55 */
57 {
58 public:
59  explicit NonMimeParser(const QByteArray &src);
60  virtual ~NonMimeParser();
61  virtual bool parse() = 0;
62  Q_REQUIRED_RESULT bool isPartial() const
63  {
64  return (m_partNr > -1 && m_totalNr > -1 && m_totalNr != 1);
65  }
66  Q_REQUIRED_RESULT int partialNumber() const
67  {
68  return m_partNr;
69  }
70  Q_REQUIRED_RESULT int partialCount() const
71  {
72  return m_totalNr;
73  }
74  Q_REQUIRED_RESULT bool hasTextPart() const
75  {
76  return (m_text.length() > 1);
77  }
78  Q_REQUIRED_RESULT QByteArray textPart() const
79  {
80  return m_text;
81  }
82  Q_REQUIRED_RESULT QVector<QByteArray> binaryParts() const
83  {
84  return m_bins;
85  }
86  Q_REQUIRED_RESULT QVector<QByteArray> filenames() const
87  {
88  return m_filenames;
89  }
90  Q_REQUIRED_RESULT QVector<QByteArray> mimeTypes() const
91  {
92  return m_mimeTypes;
93  }
94 
95 protected:
96  static QByteArray guessMimeType(const QByteArray &fileName);
97 
98  QByteArray m_src, m_text;
99  QVector<QByteArray> m_bins, m_filenames, m_mimeTypes;
100  int m_partNr, m_totalNr;
101 };
102 
103 /** Helper-class: tries to extract the data from a possibly
104  uuencoded message
105  @internal
106 */
107 class UUEncoded : public NonMimeParser
108 {
109 public:
110  UUEncoded(const QByteArray &src, const QByteArray &subject);
111 
112  Q_REQUIRED_RESULT bool parse() override;
113 
114 private:
115  QByteArray m_subject;
116 };
117 
118 /** Helper-class: tries to extract the data from a possibly
119  yenc encoded message
120  @internal
121 */
123 {
124 public:
125  explicit YENCEncoded(const QByteArray &src);
126 
127  Q_REQUIRED_RESULT bool parse() override;
128 
129 private:
130  static bool yencMeta(QByteArray &src, const QByteArray &name, int *value);
131 };
132 
133 } // namespace Parser
134 
135 } // namespace KMime
136 
Helper-class: tries to extract the data from a possibly uuencoded message.
static QByteArray guessMimeType(const QByteArray &fileName)
try to guess the mimetype from the file-extension
Helper-class: tries to extract the data from a possibly yenc encoded message.
Helper-class: splits a multipart-message into single parts as described in RFC 2046.
Definition: kmime_parsers.h:25
int length() const const
Helper-class: abstract base class of all parsers for non-mime binary data (uuencoded,...
Definition: kmime_parsers.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 03:58:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.