7#include "dkimwidgetinfo.h"
8#include "dkimmanager.h"
10#include "messageviewer_dkimcheckerdebug.h"
11#include <KColorScheme>
12#include <KLocalizedString>
17using namespace MessageViewer;
18DKIMWidgetInfo::DKIMWidgetInfo(
QWidget *parent)
24 mainLayout->setContentsMargins({});
26 mLabel->setAutoFillBackground(
true);
28 mainLayout->addWidget(mLabel);
29 connect(DKIMManager::self(), &DKIMManager::result,
this, &DKIMWidgetInfo::setResult);
30 connect(DKIMManager::self(), &DKIMManager::clearInfo,
this, &DKIMWidgetInfo::clear);
34DKIMWidgetInfo::~DKIMWidgetInfo() =
default;
36void DKIMWidgetInfo::updatePalette()
42void DKIMWidgetInfo::initColors()
51MessageViewer::DKIMCheckSignatureJob::CheckSignatureResult DKIMWidgetInfo::result()
const
58 return mCurrentItemId;
63 mCurrentItemId = currentItemId;
66void DKIMWidgetInfo::setResult(
const DKIMCheckSignatureJob::CheckSignatureResult &checkResult,
Akonadi::Item::Id id)
68 if (mCurrentItemId ==
id) {
69 if (mResult != checkResult) {
70 mResult = checkResult;
76void DKIMWidgetInfo::clear()
87void DKIMWidgetInfo::updateInfo()
90 switch (mResult.status) {
91 case DKIMCheckSignatureJob::DKIMStatus::Unknown:
96 case DKIMCheckSignatureJob::DKIMStatus::Valid:
98 qCWarning(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"mResult.sdid is empty. It's a bug";
100 mLabel->
setText(
i18n(
"DKIM: valid (signed by %1)", mResult.sdid));
101 pal.
setColor(
backgroundRole(), (mResult.warning != DKIMCheckSignatureJob::DKIMWarning::Any) ? mWarningColor : mOkColor);
104 case DKIMCheckSignatureJob::DKIMStatus::Invalid:
109 case DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned:
114 case DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned:
115 mLabel->
setText(
i18n(
"DKIM: Should Be Signed by %1", mResult.sdid));
123void DKIMWidgetInfo::updateToolTip()
126 if (mResult.status == DKIMCheckSignatureJob::DKIMStatus::Invalid) {
127 switch (mResult.error) {
128 case DKIMCheckSignatureJob::DKIMError::Any:
130 case DKIMCheckSignatureJob::DKIMError::CorruptedBodyHash:
131 tooltip =
i18n(
"Body Hash was corrupted.");
133 case DKIMCheckSignatureJob::DKIMError::DomainNotExist:
134 tooltip =
i18n(
"The domain doesn't exist.");
136 case DKIMCheckSignatureJob::DKIMError::MissingFrom:
137 tooltip =
i18n(
"Missing header From.");
139 case DKIMCheckSignatureJob::DKIMError::MissingSignature:
140 tooltip =
i18n(
"Missing signature.");
142 case DKIMCheckSignatureJob::DKIMError::InvalidQueryMethod:
143 tooltip =
i18n(
"Invalid query method.");
145 case DKIMCheckSignatureJob::DKIMError::InvalidHeaderCanonicalization:
146 tooltip =
i18n(
"Invalid header canonicalization.");
148 case DKIMCheckSignatureJob::DKIMError::InvalidBodyCanonicalization:
149 tooltip =
i18n(
"Invalid body canonicalization.");
151 case DKIMCheckSignatureJob::DKIMError::InvalidBodyHashAlgorithm:
152 tooltip =
i18n(
"Unknown Body Hash Algorithm.");
154 case DKIMCheckSignatureJob::DKIMError::InvalidSignAlgorithm:
155 tooltip =
i18n(
"Signature algorithm is invalid.");
157 case DKIMCheckSignatureJob::DKIMError::PublicKeyWasRevoked:
158 tooltip =
i18n(
"The public key was revoked.");
160 case DKIMCheckSignatureJob::DKIMError::SignatureTooLarge:
161 tooltip =
i18n(
"Signature is too large.");
163 case DKIMCheckSignatureJob::DKIMError::InsupportedHashAlgorithm:
164 tooltip =
i18n(
"Hash Algorithm is unsupported.");
166 case DKIMCheckSignatureJob::DKIMError::PublicKeyTooSmall:
167 tooltip =
i18n(
"Public key is too small.");
169 case DKIMCheckSignatureJob::DKIMError::ImpossibleToVerifySignature:
170 tooltip =
i18n(
"Impossible to verify signature.");
172 case DKIMCheckSignatureJob::DKIMError::DomainI:
173 tooltip =
i18n(
"AUID must be in the same domain as SDID (s-flag set in key record).");
175 case DKIMCheckSignatureJob::DKIMError::TestKeyMode:
176 tooltip =
i18n(
"The signing domain is only testing DKIM.");
178 case DKIMCheckSignatureJob::DKIMError::ImpossibleToDownloadKey:
179 tooltip =
i18n(
"Impossible to download key.");
181 case DKIMCheckSignatureJob::DKIMError::HashAlgorithmUnsafeSha1:
182 tooltip =
i18n(
"Hash Algorithm unsafe (sha1)");
184 case DKIMCheckSignatureJob::DKIMError::IDomainError:
185 tooltip =
i18n(
"AUID is not in a subdomain of SDID");
187 case DKIMCheckSignatureJob::DKIMError::PublicKeyConversionError:
188 tooltip =
i18n(
"Problem during converting public key");
193 switch (mResult.warning) {
194 case DKIMCheckSignatureJob::DKIMWarning::Any:
196 case DKIMCheckSignatureJob::DKIMWarning::SignatureExpired:
199 case DKIMCheckSignatureJob::DKIMWarning::SignatureCreatedInFuture:
202 case DKIMCheckSignatureJob::DKIMWarning::SignatureTooSmall:
205 case DKIMCheckSignatureJob::DKIMWarning::HashAlgorithmUnsafe:
208 case DKIMCheckSignatureJob::DKIMWarning::PublicRsaKeyTooSmall:
213 if (mResult.status != DKIMCheckSignatureJob::DKIMStatus::Invalid) {
215 for (
const DKIMCheckSignatureJob::DKIMCheckSignatureAuthenticationResult &result : std::as_const(mResult.listSignatureAuthenticationResult)) {
216 switch (result.status) {
217 case DKIMCheckSignatureJob::DKIMStatus::Unknown:
219 case DKIMCheckSignatureJob::DKIMStatus::Invalid:
220 switch (result.method) {
221 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
224 case DKIMCheckSignatureJob::AuthenticationMethod::Spf:
225 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim:
226 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc:
227 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
228 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps: {
229 const QString str =
i18nc(
"method name: info about it from parsing",
231 MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method),
241 case DKIMCheckSignatureJob::DKIMStatus::NeedToBeSigned:
243 case DKIMCheckSignatureJob::DKIMStatus::EmailNotSigned:
244 switch (result.method) {
245 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
248 case DKIMCheckSignatureJob::AuthenticationMethod::Spf:
249 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim:
250 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc:
251 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
252 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps: {
253 const QString str =
i18n(
"%1: None", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method));
261 case DKIMCheckSignatureJob::DKIMStatus::Valid:
262 switch (result.method) {
263 case DKIMCheckSignatureJob::AuthenticationMethod::Unknown: {
266 case DKIMCheckSignatureJob::AuthenticationMethod::Dkim: {
268 i18n(
"%1: Valid (Signed by %2)", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method), result.sdid);
274 case DKIMCheckSignatureJob::AuthenticationMethod::Spf: {
275 const QString str =
i18nc(
"method name: info about it from parsing",
277 MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method),
285 case DKIMCheckSignatureJob::AuthenticationMethod::Auth:
286 case DKIMCheckSignatureJob::AuthenticationMethod::Dkimatps:
287 case DKIMCheckSignatureJob::AuthenticationMethod::Dmarc: {
288 const QString str =
i18n(
"%1: Valid", MessageViewer::DKIMUtil::convertAuthenticationMethodEnumToString(result.method));
302 if (mResult.listSignatureAuthenticationResult.
isEmpty()) {
306 qCDebug(MESSAGEVIEWER_DKIMCHECKER_LOG) <<
"mResult.authentication " << mResult.listSignatureAuthenticationResult;
311#include "moc_dkimwidgetinfo.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &)
void append(QList< T > &&value)
bool isEmpty() const const
void setColor(ColorGroup group, ColorRole role, const QColor &color)
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)