7 #include "dkimwidgetinfo.h"
8 #include "dkimmanager.h"
10 #include "messageviewer_dkimcheckerdebug.h"
11 #include <KColorScheme>
12 #include <KLocalizedString>
14 #include <QHBoxLayout>
17 using namespace MessageViewer;
18 DKIMWidgetInfo::DKIMWidgetInfo(
QWidget *parent)
23 mainLayout->setObjectName(QStringLiteral(
"mainLayout"));
24 mainLayout->setContentsMargins({});
26 mLabel->setAutoFillBackground(
true);
27 mLabel->setObjectName(QStringLiteral(
"label"));
28 mainLayout->addWidget(mLabel);
29 connect(DKIMManager::self(), &DKIMManager::result,
this, &DKIMWidgetInfo::setResult);
30 connect(DKIMManager::self(), &DKIMManager::clearInfo,
this, &DKIMWidgetInfo::clear);
32 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
37 DKIMWidgetInfo::~DKIMWidgetInfo() =
default;
39 void DKIMWidgetInfo::updatePalette()
45 void DKIMWidgetInfo::initColors()
54 MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult DKIMWidgetInfo::result()
const
61 return mCurrentItemId;
66 mCurrentItemId = currentItemId;
69 void DKIMWidgetInfo::setResult(
const DKIMCheckSignatureJob::CheckSignatureResult &checkResult,
Akonadi::Item::Id id)
71 if (mCurrentItemId ==
id) {
72 if (mResult != checkResult) {
73 mResult = checkResult;
79 void DKIMWidgetInfo::clear()
90 void DKIMWidgetInfo::updateInfo()
93 switch (mResult.status) {
94 case DKIMCheckSignatureJob::DKIMStatus::Unknown:
99 case DKIMCheckSignatureJob::DKIMStatus::Valid:
100 if (mResult.sdid.isEmpty()) {
101 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"mResult.sdid is empty. It's a bug";
103 mLabel->
setText(
i18n(
"DKIM: valid (signed by %1)", mResult.sdid));
104 pal.
setColor(
backgroundRole(), (mResult.warning != DKIMCheckSignatureJob::DKIMWarning::Any) ? mWarningColor : mOkColor);
107 case DKIMCheckSignatureJob::DKIMStatus::Invalid:
112 case DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned:
117 case DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned:
118 mLabel->
setText(
i18n(
"DKIM: Should Be Signed by %1", mResult.sdid));
126 void DKIMWidgetInfo::updateToolTip()
129 if (mResult.status == DKIMCheckSignatureJob::DKIMStatus::Invalid) {
130 switch (mResult.error) {
131 case DKIMCheckSignatureJob::DKIMError::Any:
133 case DKIMCheckSignatureJob::DKIMError::CorruptedBodyHash:
134 tooltip =
i18n(
"Body Hash was corrupted.");
136 case DKIMCheckSignatureJob::DKIMError::DomainNotExist:
137 tooltip =
i18n(
"The domain doesn't exist.");
139 case DKIMCheckSignatureJob::DKIMError::MissingFrom:
140 tooltip =
i18n(
"Missing header From.");
142 case DKIMCheckSignatureJob::DKIMError::MissingSignature:
143 tooltip =
i18n(
"Missing signature.");
145 case DKIMCheckSignatureJob::DKIMError::InvalidQueryMethod:
146 tooltip =
i18n(
"Invalid query method.");
148 case DKIMCheckSignatureJob::DKIMError::InvalidHeaderCanonicalization:
149 tooltip =
i18n(
"Invalid header canonicalization.");
151 case DKIMCheckSignatureJob::DKIMError::InvalidBodyCanonicalization:
152 tooltip =
i18n(
"Invalid body canonicalization.");
154 case DKIMCheckSignatureJob::DKIMError::InvalidBodyHashAlgorithm:
155 tooltip =
i18n(
"Unknown Body Hash Algorithm.");
157 case DKIMCheckSignatureJob::DKIMError::InvalidSignAlgorithm:
158 tooltip =
i18n(
"Signature algorithm is invalid.");
160 case DKIMCheckSignatureJob::DKIMError::PublicKeyWasRevoked:
161 tooltip =
i18n(
"The public key was revoked.");
163 case DKIMCheckSignatureJob::DKIMError::SignatureTooLarge:
164 tooltip =
i18n(
"Signature is too large.");
166 case DKIMCheckSignatureJob::DKIMError::InsupportedHashAlgorithm:
167 tooltip =
i18n(
"Hash Algorithm is unsupported.");
169 case DKIMCheckSignatureJob::DKIMError::PublicKeyTooSmall:
170 tooltip =
i18n(
"Public key is too small.");
172 case DKIMCheckSignatureJob::DKIMError::ImpossibleToVerifySignature:
173 tooltip =
i18n(
"Impossible to verify signature.");
175 case DKIMCheckSignatureJob::DKIMError::DomainI:
176 tooltip =
i18n(
"AUID must be in the same domain as SDID (s-flag set in key record).");
178 case DKIMCheckSignatureJob::DKIMError::TestKeyMode:
179 tooltip =
i18n(
"The signing domain is only testing DKIM.");
181 case DKIMCheckSignatureJob::DKIMError::ImpossibleToDownloadKey:
182 tooltip =
i18n(
"Impossible to download key.");
184 case DKIMCheckSignatureJob::DKIMError::HashAlgorithmUnsafeSha1:
185 tooltip =
i18n(
"Hash Algorithm unsafe (sha1)");
187 case DKIMCheckSignatureJob::DKIMError::IDomainError:
188 tooltip =
i18n(
"AUID is not in a subdomain of SDID");
190 case DKIMCheckSignatureJob::DKIMError::PublicKeyConversionError:
191 tooltip =
i18n(
"Problem during converting public key");
196 switch (mResult.warning) {
197 case DKIMCheckSignatureJob::DKIMWarning::Any:
199 case DKIMCheckSignatureJob::DKIMWarning::SignatureExpired:
202 case DKIMCheckSignatureJob::DKIMWarning::SignatureCreatedInFuture:
205 case DKIMCheckSignatureJob::DKIMWarning::SignatureTooSmall:
208 case DKIMCheckSignatureJob::DKIMWarning::HashAlgorithmUnsafe:
211 case DKIMCheckSignatureJob::DKIMWarning::PublicRsaKeyTooSmall:
216 if (mResult.status != DKIMCheckSignatureJob::DKIMStatus::Invalid) {
218 for (
const DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult &result : std::as_const(mResult.listSignatureAuthenticationResult)) {
219 switch (result.status) {
220 case DKIMCheckSignatureJob::DKIMStatus::Unknown:
222 case DKIMCheckSignatureJob::DKIMStatus::Invalid:
223 switch (result.method) {
224 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
227 case DKIMCheckSignatureJob::AuthenticationMethod::Spf:
228 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim:
229 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc:
230 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
231 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps: {
232 const QString str =
i18nc(
"method name: info about it from parsing",
234 MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method),
244 case DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned:
246 case DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned:
247 switch (result.method) {
248 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
251 case DKIMCheckSignatureJob::AuthenticationMethod::Spf:
252 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim:
253 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc:
254 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
255 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps: {
256 const QString str =
i18n(
"%1: None", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method));
264 case DKIMCheckSignatureJob::DKIMStatus::Valid:
265 switch (result.method) {
266 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
269 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim: {
271 i18n(
"%1: Valid (Signed by %2)", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method), result.sdid);
277 case DKIMCheckSignatureJob::AuthenticationMethod::Spf: {
278 const QString str =
i18nc(
"method name: info about it from parsing",
280 MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method),
288 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
289 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps:
290 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc: {
291 const QString str =
i18n(
"%1: Valid", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method));
305 if (mResult.listSignatureAuthenticationResult.isEmpty()) {
309 qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"mResult.authentication " << mResult.listSignatureAuthenticationResult;
314 bool DKIMWidgetInfo::event(
QEvent *e)
316 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)