Differential D3140 Diff 8050 plugins/messageviewer/bodypartformatter/gnupgwks/gnupgwksmessagepart.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/messageviewer/bodypartformatter/gnupgwks/gnupgwksmessagepart.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify it | ||||
5 | under the terms of the GNU Library General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||||
7 | option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||||
12 | License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
17 | 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "gnupgwksmessagepart.h" | ||||
21 | | ||||
22 | #include <MimeTreeParser/BodyPart> | ||||
23 | #include <KMime/Content> | ||||
24 | | ||||
25 | | ||||
26 | GnuPGWKSMessagePart::GnuPGWKSMessagePart(MimeTreeParser::Interface::BodyPart *part) | ||||
27 | : mPart(part) | ||||
28 | , mType(UnknownType) | ||||
29 | { | ||||
30 | parseContent(part->content()); | ||||
31 | } | ||||
32 | | ||||
33 | GnuPGWKSMessagePart::ConfirmationType GnuPGWKSMessagePart::confirmationType() const | ||||
34 | { | ||||
35 | return mType; | ||||
36 | } | ||||
37 | | ||||
38 | QString GnuPGWKSMessagePart::address() const | ||||
39 | { | ||||
40 | return mAddress; | ||||
41 | } | ||||
42 | | ||||
43 | QString GnuPGWKSMessagePart::sender() const | ||||
44 | { | ||||
45 | return mSender; | ||||
46 | } | ||||
47 | | ||||
48 | QString GnuPGWKSMessagePart::fingerprint() const | ||||
49 | { | ||||
50 | return mFingerprint; | ||||
51 | } | ||||
52 | | ||||
53 | QString GnuPGWKSMessagePart::nonce() const | ||||
54 | { | ||||
55 | return mNonce; | ||||
56 | } | ||||
57 | | ||||
58 | KMime::Content *GnuPGWKSMessagePart::node() const | ||||
59 | { | ||||
60 | return mPart->content(); | ||||
61 | } | ||||
62 | | ||||
63 | MimeTreeParser::Interface::BodyPart *GnuPGWKSMessagePart::part() const | ||||
64 | { | ||||
65 | return mPart; | ||||
66 | } | ||||
67 | | ||||
68 | GnuPGWKSMessagePart::ConfirmationType GnuPGWKSMessagePart::stringToType(const QStringRef &str) | ||||
69 | { | ||||
70 | if (str == QLatin1String("confirmation-request")) { | ||||
71 | return ConfirmationRequest; | ||||
72 | } else if (str == QLatin1String("confirmation-response")) { | ||||
73 | return ConfirmationResponse; | ||||
74 | } else { | ||||
75 | return UnknownType; | ||||
76 | } | ||||
77 | } | ||||
78 | | ||||
79 | void GnuPGWKSMessagePart::parseContent(KMime::Content *node) | ||||
80 | { | ||||
81 | const auto text = QString::fromUtf8(node->decodedContent()); | ||||
82 | const auto lines = text.split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||||
83 | // https://tools.ietf.org/id/draft-koch-openpgp-webkey-service-02.txt | ||||
84 | // sections 4.3 and 4.4 | ||||
85 | for (const auto &line : lines) { | ||||
86 | if (line.startsWith(QLatin1String("type:"))) { | ||||
87 | mType = stringToType(line.midRef(sizeof("type:") - 1).trimmed()); | ||||
88 | } else if (line.startsWith(QLatin1String("sender:"))) { | ||||
89 | mSender = line.midRef(sizeof("sender:") - 1).trimmed().toString(); | ||||
90 | } else if (line.startsWith(QLatin1String("address:"))) { | ||||
91 | mAddress = line.midRef(sizeof("address:") - 1).trimmed().toString(); | ||||
92 | } else if (line.startsWith(QLatin1String("fingerprint:"))) { | ||||
93 | mFingerprint = line.midRef(sizeof("fingerprint:") - 1).trimmed().toString(); | ||||
94 | } else if (line.startsWith(QLatin1String("nonce:"))) { | ||||
95 | mNonce = line.midRef(sizeof("nonce:") - 1).trimmed().toString(); | ||||
96 | } | ||||
97 | } | ||||
98 | } |