Messagelib

dkimauthenticationstatusinfoconverter.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
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"
13 using namespace MessageViewer;
14 
15 DKIMAuthenticationStatusInfoConverter::DKIMAuthenticationStatusInfoConverter() = default;
16 
17 DKIMAuthenticationStatusInfoConverter::~DKIMAuthenticationStatusInfoConverter() = default;
18 
19 MessageViewer::DKIMAuthenticationStatusInfo DKIMAuthenticationStatusInfoConverter::statusInfo() const
20 {
21  return mStatusInfo;
22 }
23 
24 void DKIMAuthenticationStatusInfoConverter::setStatusInfo(const MessageViewer::DKIMAuthenticationStatusInfo &statusInfo)
25 {
26  mStatusInfo = statusInfo;
27 }
28 
29 QVector<DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult> DKIMAuthenticationStatusInfoConverter::convert() const
30 {
32  const QVector<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 == QLatin1String("none")) {
39  convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned;
40  } else if (infoResult == QLatin1String("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 == QLatin1String("fail") || infoResult == QLatin1String("policy") || infoResult == QLatin1String("neutral")
61  || infoResult == QLatin1String("permerror")) {
62  convertedResult.status = DKIMCheckSignatureJob::DKIMStatus::Invalid;
63  if (!info.reason.isEmpty()) {
64  convertedResult.errorStr = info.reason;
65  }
66  } else if (infoResult == QLatin1String("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(const T &value)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.