Messagelib

dkimauthenticationstatusinfoconverter.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
3
4 Code based on ARHParser.jsm from dkim_verifier (Copyright (c) Philippe Lieser)
5 (This software is licensed under the terms of the MIT License.)
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "dkimauthenticationstatusinfoconverter.h"
11#include "dkimutil.h"
12#include "messageviewer_dkimcheckerdebug.h"
13using namespace MessageViewer;
14
15DKIMAuthenticationStatusInfoConverter::DKIMAuthenticationStatusInfoConverter() = default;
16
17DKIMAuthenticationStatusInfoConverter::~DKIMAuthenticationStatusInfoConverter() = default;
18
19MessageViewer::DKIMAuthenticationStatusInfo DKIMAuthenticationStatusInfoConverter::statusInfo() const
20{
21 return mStatusInfo;
22}
23
24void DKIMAuthenticationStatusInfoConverter::setStatusInfo(const MessageViewer::DKIMAuthenticationStatusInfo &statusInfo)
25{
26 mStatusInfo = statusInfo;
27}
28
29QList<DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult> DKIMAuthenticationStatusInfoConverter::convert() const
30{
32 const QList<DKIMAuthenticationStatusInfo::AuthStatusInfo> lstInfo = mStatusInfo.listAuthStatusInfo();
33 for (const DKIMAuthenticationStatusInfo::AuthStatusInfo &info : lstInfo) {
34 DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult convertedResult;
35 convertedResult.method = MessageViewer::DKIMUtil::convertAuthenticationMethodStringToEnum(info.method);
36 const QString &infoResult = info.result;
37 convertedResult.infoResult = infoResult;
38 if (infoResult == QLatin1StringView("none")) {
39 convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned;
40 } else if (infoResult == QLatin1StringView("pass")) {
41 convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Valid;
42 QString sdid;
43 QString auid;
44 for (const DKIMAuthenticationStatusInfo::AuthStatusInfo::Property &prop : info.header) {
45 if (prop.type == QLatin1Char('d')) {
46 sdid = prop.value;
47 } else if (prop.type == QLatin1Char('i')) {
48 auid = prop.value;
49 }
50 }
51 if (!auid.isEmpty() || !sdid.isEmpty()) {
52 if (sdid.isEmpty()) {
53 sdid = MessageViewer::DKIMUtil::emailDomain(auid);
54 } else if (auid.isEmpty()) {
55 auid = QLatin1Char('@') + sdid;
56 }
57 convertedResult.sdid = sdid;
58 convertedResult.auid = auid;
59 }
60 } else if (infoResult == QLatin1StringView("fail") || infoResult == QLatin1StringView("policy") || infoResult == QLatin1StringView("neutral")
61 || infoResult == QLatin1StringView("permerror")) {
62 convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Invalid;
63 if (!info.reason.isEmpty()) {
64 convertedResult.errorStr = info.reason;
65 }
66 } else if (infoResult == QLatin1StringView("temperror")) {
67 convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Invalid;
68 if (!info.reason.isEmpty()) {
69 convertedResult.errorStr = info.reason;
70 }
71 } else {
72 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) << "Invalid result type " << infoResult;
73 continue;
74 }
75 lstResult.append(convertedResult);
76 }
77
78 return lstResult;
79}
void append(QList< T > &&value)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.