diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/otp/nodehelper.h')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/otp/nodehelper.h | 263 |
1 files changed, 0 insertions, 263 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/otp/nodehelper.h b/framework/src/domain/mime/mimetreeparser/otp/nodehelper.h deleted file mode 100644 index 40c62a75..00000000 --- a/framework/src/domain/mime/mimetreeparser/otp/nodehelper.h +++ /dev/null | |||
@@ -1,263 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net | ||
3 | Copyright (c) 2009 Andras Mantia <andras@kdab.net> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along | ||
16 | with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #ifndef __MIMETREEPARSER_NODEHELPER_H__ | ||
21 | #define __MIMETREEPARSER_NODEHELPER_H__ | ||
22 | |||
23 | #include "partmetadata.h" | ||
24 | #include "enums.h" | ||
25 | |||
26 | #include <KMime/Message> | ||
27 | |||
28 | #include <QList> | ||
29 | #include <QMap> | ||
30 | #include <QSet> | ||
31 | |||
32 | class QUrl; | ||
33 | class QTextCodec; | ||
34 | |||
35 | namespace MimeTreeParser | ||
36 | { | ||
37 | class AttachmentTemporaryFilesDirs; | ||
38 | namespace Interface | ||
39 | { | ||
40 | class BodyPartMemento; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | namespace MimeTreeParser | ||
45 | { | ||
46 | |||
47 | /** | ||
48 | * @author Andras Mantia <andras@kdab.net> | ||
49 | */ | ||
50 | class NodeHelper: public QObject | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | public: | ||
54 | NodeHelper(); | ||
55 | |||
56 | ~NodeHelper(); | ||
57 | |||
58 | void setNodeProcessed(KMime::Content *node, bool recurse); | ||
59 | void setNodeUnprocessed(KMime::Content *node, bool recurse); | ||
60 | bool nodeProcessed(KMime::Content *node) const; | ||
61 | void clear(); | ||
62 | void forceCleanTempFiles(); | ||
63 | |||
64 | void setEncryptionState(const KMime::Content *node, const KMMsgEncryptionState state); | ||
65 | KMMsgEncryptionState encryptionState(const KMime::Content *node) const; | ||
66 | |||
67 | void setSignatureState(const KMime::Content *node, const KMMsgSignatureState state); | ||
68 | KMMsgSignatureState signatureState(const KMime::Content *node) const; | ||
69 | |||
70 | KMMsgSignatureState overallSignatureState(KMime::Content *node) const; | ||
71 | KMMsgEncryptionState overallEncryptionState(KMime::Content *node) const; | ||
72 | |||
73 | void setPartMetaData(KMime::Content *node, const PartMetaData &metaData); | ||
74 | PartMetaData partMetaData(KMime::Content *node); | ||
75 | |||
76 | /** | ||
77 | * Set the 'Content-Type' by mime-magic from the contents of the body. | ||
78 | * If autoDecode is true the decoded body will be used for mime type | ||
79 | * determination (this does not change the body itself). | ||
80 | */ | ||
81 | void magicSetType(KMime::Content *node, bool autoDecode = true); | ||
82 | |||
83 | /** Attach an extra node to an existing node */ | ||
84 | void attachExtraContent(KMime::Content *topLevelNode, KMime::Content *content); | ||
85 | |||
86 | /** Get the extra nodes attached to the @param topLevelNode and all sub-nodes of @param topLevelNode */ | ||
87 | QList<KMime::Content *> extraContents(KMime::Content *topLevelNode) const; | ||
88 | |||
89 | /** Return a modified message (node tree) starting from @param topLevelNode that has the original nodes and the extra nodes. | ||
90 | The caller has the responsibility to delete the new message. | ||
91 | */ | ||
92 | KMime::Message *messageWithExtraContent(KMime::Content *topLevelNode); | ||
93 | |||
94 | /** Get a QTextCodec suitable for this message part */ | ||
95 | const QTextCodec *codec(KMime::Content *node); | ||
96 | |||
97 | /** Set the charset the user selected for the message to display */ | ||
98 | void setOverrideCodec(KMime::Content *node, const QTextCodec *codec); | ||
99 | |||
100 | Interface::BodyPartMemento *bodyPartMemento(KMime::Content *node, const QByteArray &which) const; | ||
101 | |||
102 | void setBodyPartMemento(KMime::Content *node, const QByteArray &which, | ||
103 | Interface::BodyPartMemento *memento); | ||
104 | |||
105 | // A flag to remember if the node was embedded. This is useful for attachment nodes, the reader | ||
106 | // needs to know if they were displayed inline or not. | ||
107 | bool isNodeDisplayedEmbedded(KMime::Content *node) const; | ||
108 | void setNodeDisplayedEmbedded(KMime::Content *node, bool displayedEmbedded); | ||
109 | |||
110 | // Same as above, but this time determines if the node was hidden or not | ||
111 | bool isNodeDisplayedHidden(KMime::Content *node) const; | ||
112 | void setNodeDisplayedHidden(KMime::Content *node, bool displayedHidden); | ||
113 | |||
114 | /** | ||
115 | * Writes the given message part to a temporary file and returns the | ||
116 | * name of this file or QString() if writing failed. | ||
117 | */ | ||
118 | QString writeNodeToTempFile(KMime::Content *node); | ||
119 | |||
120 | /** | ||
121 | * Returns the temporary file path and name where this node was saved, or an empty url | ||
122 | * if it wasn't saved yet with writeNodeToTempFile() | ||
123 | */ | ||
124 | QUrl tempFileUrlFromNode(const KMime::Content *node); | ||
125 | |||
126 | /** | ||
127 | * Creates a temporary dir for saving attachments, etc. | ||
128 | * Will be automatically deleted when another message is viewed. | ||
129 | * @param param Optional part of the directory name. | ||
130 | */ | ||
131 | QString createTempDir(const QString ¶m = QString()); | ||
132 | |||
133 | /** | ||
134 | * Cleanup the attachment temp files | ||
135 | */ | ||
136 | void removeTempFiles(); | ||
137 | |||
138 | /** | ||
139 | * Add a file to the list of managed temporary files | ||
140 | */ | ||
141 | void addTempFile(const QString &file); | ||
142 | |||
143 | // Get a href in the form attachment:<nodeId>?place=<place>, used by ObjectTreeParser and | ||
144 | // UrlHandlerManager. | ||
145 | QString asHREF(const KMime::Content *node, const QString &place) const; | ||
146 | KMime::Content *fromHREF(const KMime::Message::Ptr &mMessage, const QUrl &href) const; | ||
147 | |||
148 | /** | ||
149 | * @return true if this node is a child or an encapsulated message | ||
150 | */ | ||
151 | static bool isInEncapsulatedMessage(KMime::Content *node); | ||
152 | |||
153 | /** | ||
154 | * Returns the charset for the given node. If no charset is specified | ||
155 | * for the node, the defaultCharset() is returned. | ||
156 | */ | ||
157 | static QByteArray charset(KMime::Content *node); | ||
158 | |||
159 | /** | ||
160 | * Return a QTextCodec for the specified charset. | ||
161 | * This function is a bit more tolerant, than QTextCodec::codecForName | ||
162 | */ | ||
163 | static const QTextCodec *codecForName(const QByteArray &_str); | ||
164 | |||
165 | /** | ||
166 | * Returns a usable filename for a node, that can be the filename from the | ||
167 | * content disposition header, or if that one is empty, the name from the | ||
168 | * content type header. | ||
169 | */ | ||
170 | static QString fileName(const KMime::Content *node); | ||
171 | |||
172 | /** | ||
173 | * Fixes an encoding received by a KDE function and returns the proper, | ||
174 | * MIME-compilant encoding name instead. | ||
175 | * @see encodingForName | ||
176 | */ | ||
177 | static QString fixEncoding(const QString &encoding); //TODO(Andras) move to a utility class? | ||
178 | |||
179 | /** | ||
180 | * Drop-in replacement for KCharsets::encodingForName(). The problem with | ||
181 | * the KCharsets function is that it returns "human-readable" encoding names | ||
182 | * like "ISO 8859-15" instead of valid encoding names like "ISO-8859-15". | ||
183 | * This function fixes this by replacing whitespace with a hyphen. | ||
184 | */ | ||
185 | static QString encodingForName(const QString &descriptiveName); //TODO(Andras) move to a utility class? | ||
186 | |||
187 | /** | ||
188 | * Return a list of the supported encodings | ||
189 | * @param usAscii if true, US-Ascii encoding will be prepended to the list. | ||
190 | */ | ||
191 | static QStringList supportedEncodings(bool usAscii); //TODO(Andras) move to a utility class? | ||
192 | |||
193 | QString fromAsString(KMime::Content *node) const; | ||
194 | |||
195 | KMime::Content *decryptedNodeForContent(KMime::Content *content) const; | ||
196 | |||
197 | /** | ||
198 | * This function returns the unencrypted message that is based on @p originalMessage. | ||
199 | * All encrypted MIME parts are removed and replaced by their decrypted plain-text versions. | ||
200 | * Encrypted parts that are within signed parts are not replaced, since that would invalidate | ||
201 | * the signature. | ||
202 | * | ||
203 | * This only works if the message was run through ObjectTreeParser::parseObjectTree() with the | ||
204 | * currrent NodeHelper before, because parseObjectTree() actually decrypts the message and stores | ||
205 | * the decrypted nodes by calling attachExtraContent(). | ||
206 | * | ||
207 | * @return the unencrypted message or an invalid pointer if the original message didn't contain | ||
208 | * a part that needed to be modified. | ||
209 | */ | ||
210 | KMime::Message::Ptr unencryptedMessage(const KMime::Message::Ptr &originalMessage); | ||
211 | |||
212 | /** | ||
213 | * Returns a list of attachments of attached extra content nodes. | ||
214 | * This is mainly useful is order to get attachments of encrypted messages. | ||
215 | * Note that this does not include attachments from the primary node tree. | ||
216 | * @see KMime::Content::attachments(). | ||
217 | */ | ||
218 | QVector<KMime::Content *> attachmentsOfExtraContents() const; | ||
219 | |||
220 | Q_SIGNALS: | ||
221 | void update(MimeTreeParser::UpdateMode); | ||
222 | |||
223 | private: | ||
224 | Q_DISABLE_COPY(NodeHelper) | ||
225 | bool unencryptedMessage_helper(KMime::Content *node, QByteArray &resultingData, bool addHeaders, | ||
226 | int recursionLevel = 1); | ||
227 | |||
228 | void mergeExtraNodes(KMime::Content *node); | ||
229 | void cleanFromExtraNodes(KMime::Content *node); | ||
230 | |||
231 | /** Creates a persistent index string that bridges the gap between the | ||
232 | permanent nodes and the temporary ones. | ||
233 | |||
234 | Used internally for robust indexing. | ||
235 | **/ | ||
236 | QString persistentIndex(const KMime::Content *node) const; | ||
237 | |||
238 | /** Translates the persistentIndex into a node back | ||
239 | |||
240 | node: any node of the actually message to what the persistentIndex is interpreded | ||
241 | **/ | ||
242 | KMime::Content *contentFromIndex(KMime::Content *node, const QString &persistentIndex) const; | ||
243 | |||
244 | private: | ||
245 | QList<KMime::Content *> mProcessedNodes; | ||
246 | QList<KMime::Content *> mNodesUnderProcess; | ||
247 | QMap<const KMime::Content *, KMMsgEncryptionState> mEncryptionState; | ||
248 | QMap<const KMime::Content *, KMMsgSignatureState> mSignatureState; | ||
249 | QSet<KMime::Content *> mDisplayEmbeddedNodes; | ||
250 | QSet<KMime::Content *> mDisplayHiddenNodes; | ||
251 | QTextCodec *mLocalCodec; | ||
252 | QMap<KMime::Content *, const QTextCodec *> mOverrideCodecs; | ||
253 | QMap<QString, QMap<QByteArray, Interface::BodyPartMemento *> > mBodyPartMementoMap; | ||
254 | QMap<KMime::Content *, PartMetaData> mPartMetaDatas; | ||
255 | QMap<KMime::Message::Content *, QList<KMime::Content *> > mExtraContents; | ||
256 | AttachmentTemporaryFilesDirs *mAttachmentFilesDir; | ||
257 | |||
258 | friend class NodeHelperTest; | ||
259 | }; | ||
260 | |||
261 | } | ||
262 | |||
263 | #endif | ||