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 <QList>
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 QList<QByteArray> parts() const { return m_parts; }
32  Q_REQUIRED_RESULT QByteArray preamble() const
33  {
34  return m_preamble;
35  }
36  Q_REQUIRED_RESULT QByteArray epilouge() const
37  {
38  return m_epilouge;
39  }
40 
41 private:
42  QByteArray m_src;
43  const QByteArray m_boundary;
44  QByteArray m_preamble;
45  QByteArray m_epilouge;
46  QList<QByteArray> m_parts;
47 };
48 
49 /** Helper-class: abstract base class of all parsers for
50  non-mime binary data (uuencoded, yenc)
51  @internal
52 */
54 {
55 public:
56  explicit NonMimeParser(const QByteArray &src);
57  virtual ~NonMimeParser();
58  virtual bool parse() = 0;
59  Q_REQUIRED_RESULT bool isPartial() const
60  {
61  return (m_partNr > -1 && m_totalNr > -1 && m_totalNr != 1);
62  }
63  Q_REQUIRED_RESULT int partialNumber() const
64  {
65  return m_partNr;
66  }
67  Q_REQUIRED_RESULT int partialCount() const
68  {
69  return m_totalNr;
70  }
71  Q_REQUIRED_RESULT bool hasTextPart() const
72  {
73  return (m_text.length() > 1);
74  }
75  Q_REQUIRED_RESULT QByteArray textPart() const
76  {
77  return m_text;
78  }
79  Q_REQUIRED_RESULT QList<QByteArray> binaryParts() const { return m_bins; }
80  Q_REQUIRED_RESULT QList<QByteArray> filenames() const {
81  return m_filenames;
82  }
83  Q_REQUIRED_RESULT QList<QByteArray> mimeTypes() const {
84  return m_mimeTypes;
85  }
86 
87 protected:
88  static QByteArray guessMimeType(const QByteArray &fileName);
89 
90  QByteArray m_src, m_text;
91  QList<QByteArray> m_bins, m_filenames, m_mimeTypes;
92  int m_partNr, m_totalNr;
93 };
94 
95 /** Helper-class: tries to extract the data from a possibly
96  uuencoded message
97  @internal
98 */
99 class UUEncoded : public NonMimeParser
100 {
101 public:
102  UUEncoded(const QByteArray &src, const QByteArray &subject);
103 
104  Q_REQUIRED_RESULT bool parse() override;
105 
106 private:
107  QByteArray m_subject;
108 };
109 
110 /** Helper-class: tries to extract the data from a possibly
111  yenc encoded message
112  @internal
113 */
115 {
116 public:
117  explicit YENCEncoded(const QByteArray &src);
118 
119  Q_REQUIRED_RESULT bool parse() override;
120 
121 private:
122  static bool yencMeta(QByteArray &src, const QByteArray &name, int *value);
123 };
124 
125 } // namespace Parser
126 
127 } // namespace KMime
128 
Helper-class: tries to extract the data from a possibly uuencoded message.
Definition: kmime_parsers.h:99
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:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 03:52:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.