diff options
author | saturneric <[email protected]> | 2024-11-28 16:40:45 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-11-28 16:40:52 +0000 |
commit | cee0ce904196e19e5726ac0f811c200aa8d9351b (patch) | |
tree | 7893d1421047f8d5b9a0cebe3723f7683d565fb0 | |
parent | feat: support decrypt & verify email (diff) | |
download | GpgFrontend-cee0ce904196e19e5726ac0f811c200aa8d9351b.tar.gz GpgFrontend-cee0ce904196e19e5726ac0f811c200aa8d9351b.zip |
fix: solve issues on ui
m--------- | modules | 0 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 766 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 3 |
3 files changed, 411 insertions, 358 deletions
diff --git a/modules b/modules -Subproject 3d5d465219ec95bf4f213186e0522e0185e1326 +Subproject 36eab07eb0429b9204d41532ca6f838c722ec4f diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 8d4611ac..25a02ba5 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -356,55 +356,67 @@ void MainWindow::slot_import_key_from_edit() { } void MainWindow::slot_verify_email_by_eml_data(const QByteArray& buffer) { - Module::TriggerEvent( - "EMAIL_VERIFY_EML_DATA", - { - {"eml_data", QString::fromLatin1(buffer.toBase64())}, - {"channel", - QString::number(m_key_list_->GetCurrentGpgContextChannel())}, - }, - [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "EMAIL_VERIFY_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to verify email, " - << "error message: " << p["err"]; - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - return; - } - - if (p.contains("signature") && p.contains("mime")) { - slot_verify_email_by_eml_data_result_helper(p); - } - - LOG_E() << "mime or signature data is missing"; + CommonUtils::WaitForOpera( + this, tr("Verifying"), [this, buffer](const OperaWaitingHd& hd) { + Module::TriggerEvent( + "EMAIL_VERIFY_EML_DATA", + { + {"eml_data", QString::fromLatin1(buffer.toBase64())}, + {"channel", + QString::number(m_key_list_->GetCurrentGpgContextChannel())}, + }, + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "EMAIL_VERIFY_EML_DATA callback: " << i << ei; + + // end waiting dialog + hd(); + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to verify email, " + << "error message: " << p["err"]; + + if (p["ret"] == "-2") { + QString detailed_error = p["err"]; + + QString info = + tr("# EML Data Error\n\n" + "The provided EML data does not conform to the " + "structure described in RFC 3156 and cannot be " + "validated.\n\n" + "Details: %1\n\n" + "What is EML Data?\n" + "EML is a file format used to represent email " + "messages. " + "It typically contains the entire contents of an " + "email, " + "including headers, " + "body text, attachments, and metadata. In order to " + "validate " + "the email properly, it is necessary to provide the " + "complete, original EML " + "data.\n\n" + "For more information about the expected EML " + "structure, " + "please refer to the RFC 3156 standard:\n" + "%2\n\n" + "Please ensure the EML data follows the standard and " + "try " + "again.") + .arg(detailed_error) + .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); + slot_refresh_info_board(-2, info); + } + + return; + } + + if (p.contains("signature") && p.contains("mime")) { + slot_verify_email_by_eml_data_result_helper(p); + } + + LOG_E() << "mime or signature data is missing"; + }); }); } @@ -672,47 +684,56 @@ void MainWindow::SlotEncryptEML() { } auto buffer = edit_->CurPlainText().toUtf8(); - Module::TriggerEvent( - "EMAIL_ENCRYPT_EML_DATA", - { - {"body_data", QString::fromLatin1(buffer.toBase64())}, - {"channel", - QString::number(m_key_list_->GetCurrentGpgContextChannel())}, - {"encrypt_keys", checked_keys.join(';')}, - }, - [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "EMAIL_ENCRYPT_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (!p["eml_data"].isEmpty()) { - edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); - } - - if (!p["capsule_id"].isEmpty()) { - auto v = UIModuleManager::GetInstance().GetCapsule( - p.value("capsule_id", "")); - - try { - auto encr_result = std::any_cast<GpgEncryptResult>(v); - auto result_analyse = GpgEncryptResultAnalyse( - m_key_list_->GetCurrentGpgContextChannel(), GPG_ERR_NO_ERROR, - encr_result); - result_analyse.Analyse(); - slot_result_analyse_show_helper(result_analyse); - - } catch (const std::bad_any_cast& e) { - LOG_E() << "capsule" << p["capsule_id"] - << "convert to real type failed" << e.what(); - } - } - - LOG_E() << "mime or signature data is missing"; + CommonUtils::WaitForOpera( + this, tr("Encrypting"), + [this, buffer, checked_keys](const OperaWaitingHd& hd) { + Module::TriggerEvent( + "EMAIL_ENCRYPT_EML_DATA", + { + {"body_data", QString::fromLatin1(buffer.toBase64())}, + {"channel", + QString::number(m_key_list_->GetCurrentGpgContextChannel())}, + {"encrypt_keys", checked_keys.join(';')}, + }, + + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "EMAIL_ENCRYPT_EML_DATA callback: " << i << ei; + + // close waiting dialog + hd(); + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to decrypt email, " + << "error message: " << p["err"]; + + return; + } + + if (!p["eml_data"].isEmpty()) { + edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); + } + + if (!p["capsule_id"].isEmpty()) { + auto v = UIModuleManager::GetInstance().GetCapsule( + p.value("capsule_id", "")); + + try { + auto encr_result = std::any_cast<GpgEncryptResult>(v); + auto result_analyse = GpgEncryptResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, encr_result); + result_analyse.Analyse(); + slot_result_analyse_show_helper(result_analyse); + + } catch (const std::bad_any_cast& e) { + LOG_E() << "capsule" << p["capsule_id"] + << "convert to real type failed" << e.what(); + } + } + + LOG_E() << "mime or signature data is missing"; + }); }); } @@ -734,74 +755,84 @@ void MainWindow::SlotSignEML() { auto buffer = edit_->CurPlainText().toUtf8(); - Module::TriggerEvent( - "EMAIL_SIGN_EML_DATA", - { - {"body_data", QString::fromLatin1(buffer.toBase64())}, - {"channel", - QString::number(m_key_list_->GetCurrentGpgContextChannel())}, - {"sign_key", checked_keys.front()}, - }, - [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "EMAIL_SIGN_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - if (!p["eml_data"].isEmpty()) { - edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); - } - - if (!p["capsule_id"].isEmpty()) { - auto v = UIModuleManager::GetInstance().GetCapsule( - p.value("capsule_id", "")); - - try { - auto sign_result = std::any_cast<GpgSignResult>(v); - auto result_analyse = - GpgSignResultAnalyse(m_key_list_->GetCurrentGpgContextChannel(), - GPG_ERR_NO_ERROR, sign_result); - result_analyse.Analyse(); - slot_result_analyse_show_helper(result_analyse); - - } catch (const std::bad_any_cast& e) { - LOG_E() << "capsule" << p["capsule_id"] - << "convert to real type failed" << e.what(); - } - } - - LOG_E() << "mime or signature data is missing"; + CommonUtils::WaitForOpera( + this, tr("Signing"), + [this, buffer, checked_keys](const OperaWaitingHd& hd) { + Module::TriggerEvent( + "EMAIL_SIGN_EML_DATA", + { + {"body_data", QString::fromLatin1(buffer.toBase64())}, + {"channel", + QString::number(m_key_list_->GetCurrentGpgContextChannel())}, + {"sign_key", checked_keys.front()}, + }, + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "EMAIL_SIGN_EML_DATA callback: " << i << ei; + + // close waiting dialog + hd(); + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to decrypt email, " + << "error message: " << p["err"]; + + return; + } + + if (p["ret"] == "-2") { + QString detailed_error = p["err"]; + + QString info = + tr("# EML Data Error\n\n" + "The provided EML data does not conform to the " + "structure described in RFC 3156 and cannot be " + "validated.\n\n" + "Details: %1\n\n" + "What is EML Data?\n" + "EML is a file format used to represent email messages. " + "It typically contains the entire contents of an email, " + "including headers, " + "body text, attachments, and metadata. In order to " + "validate " + "the email properly, it is necessary to provide the " + "complete, original EML " + "data.\n\n" + "For more information about the expected EML structure, " + "please refer to the RFC 3156 standard:\n" + "%2\n\n" + "Please ensure the EML data follows the standard and " + "try " + "again.") + .arg(detailed_error) + .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); + slot_refresh_info_board(-2, info); + } + + if (!p["eml_data"].isEmpty()) { + edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); + } + + if (!p["capsule_id"].isEmpty()) { + auto v = UIModuleManager::GetInstance().GetCapsule( + p.value("capsule_id", "")); + + try { + auto sign_result = std::any_cast<GpgSignResult>(v); + auto result_analyse = GpgSignResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, sign_result); + result_analyse.Analyse(); + slot_result_analyse_show_helper(result_analyse); + + } catch (const std::bad_any_cast& e) { + LOG_E() << "capsule" << p["capsule_id"] + << "convert to real type failed" << e.what(); + } + } + + LOG_E() << "mime or signature data is missing"; + }); }); } @@ -840,85 +871,95 @@ void MainWindow::SlotEncryptSignEML() { auto buffer = edit_->CurPlainText().toUtf8(); - Module::TriggerEvent( - "EMAIL_ENCRYPT_SIGN_EML_DATA", - { - {"body_data", QString::fromLatin1(buffer.toBase64())}, - {"channel", - QString::number(m_key_list_->GetCurrentGpgContextChannel())}, - {"sign_key", signer_keys.front()}, - {"encrypt_keys", checked_keys.front()}, - }, - [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "EMAIL_ENCRYPT_SIGN_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - if (!p["eml_data"].isEmpty()) { - edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); - } - - if (!p["sign_capsule_id"].isEmpty() && - !p["encr_capsule_id"].isEmpty()) { - auto v1 = UIModuleManager::GetInstance().GetCapsule( - p.value("sign_capsule_id", "")); - auto v2 = UIModuleManager::GetInstance().GetCapsule( - p.value("encr_capsule_id", "")); - - try { - auto sign_result = std::any_cast<GpgSignResult>(v1); - auto encr_result = std::any_cast<GpgSignResult>(v1); - auto sign_result_analyse = - GpgSignResultAnalyse(m_key_list_->GetCurrentGpgContextChannel(), - GPG_ERR_NO_ERROR, sign_result); - auto encr_result_analyse = - GpgSignResultAnalyse(m_key_list_->GetCurrentGpgContextChannel(), - GPG_ERR_NO_ERROR, sign_result); - - sign_result_analyse.Analyse(); - encr_result_analyse.Analyse(); - slot_result_analyse_show_helper(sign_result_analyse, - encr_result_analyse); - - } catch (const std::bad_any_cast& e) { - LOG_E() << "capsule" << p["capsule_id"] - << "convert to real type failed" << e.what(); - } - } - - LOG_E() << "mime or signature data is missing"; + CommonUtils::WaitForOpera( + this, tr("Encrypting and Signing"), + [this, buffer, checked_keys, signer_keys](const OperaWaitingHd& hd) { + Module::TriggerEvent( + "EMAIL_ENCRYPT_SIGN_EML_DATA", + { + {"body_data", QString::fromLatin1(buffer.toBase64())}, + {"channel", + QString::number(m_key_list_->GetCurrentGpgContextChannel())}, + {"sign_key", signer_keys.front()}, + {"encrypt_keys", checked_keys.front()}, + }, + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "EMAIL_ENCRYPT_SIGN_EML_DATA callback: " << i << ei; + + // close waiting dialog + hd(); + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to decrypt email, " + << "error message: " << p["err"]; + + return; + } + + if (p["ret"] == "-2") { + QString detailed_error = p["err"]; + + QString info = + tr("# EML Data Error\n\n" + "The provided EML data does not conform to the " + "structure described in RFC 3156 and cannot be " + "validated.\n\n" + "Details: %1\n\n" + "What is EML Data?\n" + "EML is a file format used to represent email messages. " + "It typically contains the entire contents of an email, " + "including headers, " + "body text, attachments, and metadata. In order to " + "validate " + "the email properly, it is necessary to provide the " + "complete, original EML " + "data.\n\n" + "For more information about the expected EML structure, " + "please refer to the RFC 3156 standard:\n" + "%2\n\n" + "Please ensure the EML data follows the standard and " + "try " + "again.") + .arg(detailed_error) + .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); + slot_refresh_info_board(-2, info); + } + + if (!p["eml_data"].isEmpty()) { + edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); + } + + if (!p["sign_capsule_id"].isEmpty() && + !p["encr_capsule_id"].isEmpty()) { + auto v1 = UIModuleManager::GetInstance().GetCapsule( + p.value("sign_capsule_id", "")); + auto v2 = UIModuleManager::GetInstance().GetCapsule( + p.value("encr_capsule_id", "")); + + try { + auto sign_result = std::any_cast<GpgSignResult>(v1); + auto encr_result = std::any_cast<GpgSignResult>(v1); + auto sign_result_analyse = GpgSignResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, sign_result); + auto encr_result_analyse = GpgSignResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, sign_result); + + sign_result_analyse.Analyse(); + encr_result_analyse.Analyse(); + slot_result_analyse_show_helper(sign_result_analyse, + encr_result_analyse); + + } catch (const std::bad_any_cast& e) { + LOG_E() << "capsule" << p["capsule_id"] + << "convert to real type failed" << e.what(); + } + } + + LOG_E() << "mime or signature data is missing"; + }); }); } @@ -927,125 +968,138 @@ void MainWindow::SlotDecryptVerifyEML() { auto buffer = edit_->CurPlainText().toUtf8(); - Module::TriggerEvent( - "EMAIL_DECRYPT_VERIFY_EML_DATA", - { - {"eml_data", QString::fromLatin1(buffer.toBase64())}, - {"channel", - QString::number(m_key_list_->GetCurrentGpgContextChannel())}, - }, - [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, - Module::Event::Params p) { - LOG_D() << "EMAIL_DECRYPT_VERIFY_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); - - const auto mime = QByteArray::fromBase64(p["mime"].toLatin1()); - const auto signature = - QByteArray::fromBase64(p["signature"].toLatin1()); - const auto part_mime_content_hash = p["mime_hash"]; - const auto prm_micalg_value = p["micalg"]; - - auto timestamp = p.value("datetime", "-1").toLongLong(); - auto datetime = tr("None"); - if (timestamp > 0) { - datetime = - QLocale().toString(QDateTime::fromMSecsSinceEpoch(timestamp)); - } - - QString email_info; - email_info.append("# E-Mail Information\n\n"); - email_info.append(QString("- %1: %2\n") - .arg(tr("From")) - .arg(p.value("from", tr("Unknown")))); - email_info.append(QString("- %1: %2\n") - .arg(tr("To")) - .arg(p.value("to", tr("Unknown")))); - email_info.append(QString("- %1: %2\n") - .arg(tr("Subject")) - .arg(p.value("subject", tr("None")))); - email_info.append( - QString("- %1: %2\n").arg(tr("CC")).arg(p.value("cc", tr("None")))); - email_info.append(QString("- %1: %2\n") - .arg(tr("BCC")) - .arg(p.value("bcc", tr("None")))); - email_info.append(QString("- %1: %2\n").arg(tr("Date")).arg(datetime)); - - email_info.append("\n"); - email_info.append("# OpenPGP Information\n\n"); - email_info.append(QString("- %1: %2\n") - .arg(tr("Signed EML Data Hash (SHA1)")) - .arg(part_mime_content_hash)); - email_info.append(QString("- %1: %2\n") - .arg(tr("Message Integrity Check Algorithm")) - .arg(prm_micalg_value)); - email_info.append("\n"); - - if (!p["decr_capsule_id"].isEmpty() && - !p["verify_capsule_id"].isEmpty()) { - auto v1 = UIModuleManager::GetInstance().GetCapsule( - p.value("decr_capsule_id", "")); - auto v2 = UIModuleManager::GetInstance().GetCapsule( - p.value("verify_capsule_id", "")); - - try { - auto decr_result = std::any_cast<GpgDecryptResult>(v1); - auto verify_result = std::any_cast<GpgVerifyResult>(v2); - auto decr_result_analyse = GpgDecryptResultAnalyse( - m_key_list_->GetCurrentGpgContextChannel(), GPG_ERR_NO_ERROR, - decr_result); - auto verify_result_analyse = GpgVerifyResultAnalyse( - m_key_list_->GetCurrentGpgContextChannel(), GPG_ERR_NO_ERROR, - verify_result); - - decr_result_analyse.Analyse(); - verify_result_analyse.Analyse(); - slot_refresh_info_board( - std::min(decr_result_analyse.GetStatus(), - verify_result_analyse.GetStatus()), - email_info + decr_result_analyse.GetResultReport() + - verify_result_analyse.GetResultReport()); - - } catch (const std::bad_any_cast& e) { - LOG_E() << "capsule" << p["capsule_id"] - << "convert to real type failed" << e.what(); - } - } - - LOG_E() << "mime or signature data is missing"; + CommonUtils::WaitForOpera( + this, tr("Decrypting and Verifying"), + [this, buffer](const OperaWaitingHd& hd) { + Module::TriggerEvent( + "EMAIL_DECRYPT_VERIFY_EML_DATA", + { + {"eml_data", QString::fromLatin1(buffer.toBase64())}, + {"channel", + QString::number(m_key_list_->GetCurrentGpgContextChannel())}, + }, + [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, + Module::Event::Params p) { + LOG_D() << "EMAIL_DECRYPT_VERIFY_EML_DATA callback: " << i << ei; + + // close waiting dialog + hd(); + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to decrypt email, " + << "error message: " << p["err"]; + + return; + } + + if (p["ret"] == "-2") { + QString detailed_error = p["err"]; + + QString info = + tr("# EML Data Error\n\n" + "The provided EML data does not conform to the " + "structure described in RFC 3156 and cannot be " + "validated.\n\n" + "Details: %1\n\n" + "What is EML Data?\n" + "EML is a file format used to represent email messages. " + "It typically contains the entire contents of an email, " + "including headers, " + "body text, attachments, and metadata. In order to " + "validate " + "the email properly, it is necessary to provide the " + "complete, original EML " + "data.\n\n" + "For more information about the expected EML structure, " + "please refer to the RFC 3156 standard:\n" + "%2\n\n" + "Please ensure the EML data follows the standard and " + "try " + "again.") + .arg(detailed_error) + .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); + slot_refresh_info_board(-2, info); + } + + edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); + + const auto mime = QByteArray::fromBase64(p["mime"].toLatin1()); + const auto signature = + QByteArray::fromBase64(p["signature"].toLatin1()); + const auto part_mime_content_hash = p["mime_hash"]; + const auto prm_micalg_value = p["micalg"]; + + auto timestamp = p.value("datetime", "-1").toLongLong(); + auto datetime = tr("None"); + if (timestamp > 0) { + datetime = QLocale().toString( + QDateTime::fromMSecsSinceEpoch(timestamp)); + } + + QString email_info; + email_info.append("# E-Mail Information\n\n"); + email_info.append(QString("- %1: %2\n") + .arg(tr("From")) + .arg(p.value("from", tr("Unknown")))); + email_info.append(QString("- %1: %2\n") + .arg(tr("To")) + .arg(p.value("to", tr("Unknown")))); + email_info.append(QString("- %1: %2\n") + .arg(tr("Subject")) + .arg(p.value("subject", tr("None")))); + email_info.append(QString("- %1: %2\n") + .arg(tr("CC")) + .arg(p.value("cc", tr("None")))); + email_info.append(QString("- %1: %2\n") + .arg(tr("BCC")) + .arg(p.value("bcc", tr("None")))); + email_info.append( + QString("- %1: %2\n").arg(tr("Date")).arg(datetime)); + + email_info.append("\n"); + email_info.append("# OpenPGP Information\n\n"); + email_info.append(QString("- %1: %2\n") + .arg(tr("Signed EML Data Hash (SHA1)")) + .arg(part_mime_content_hash)); + email_info.append( + QString("- %1: %2\n") + .arg(tr("Message Integrity Check Algorithm")) + .arg(prm_micalg_value)); + email_info.append("\n"); + + if (!p["decr_capsule_id"].isEmpty() && + !p["verify_capsule_id"].isEmpty()) { + auto v1 = UIModuleManager::GetInstance().GetCapsule( + p.value("decr_capsule_id", "")); + auto v2 = UIModuleManager::GetInstance().GetCapsule( + p.value("verify_capsule_id", "")); + + try { + auto decr_result = std::any_cast<GpgDecryptResult>(v1); + auto verify_result = std::any_cast<GpgVerifyResult>(v2); + auto decr_result_analyse = GpgDecryptResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, decr_result); + auto verify_result_analyse = GpgVerifyResultAnalyse( + m_key_list_->GetCurrentGpgContextChannel(), + GPG_ERR_NO_ERROR, verify_result); + + decr_result_analyse.Analyse(); + verify_result_analyse.Analyse(); + slot_refresh_info_board( + std::min(decr_result_analyse.GetStatus(), + verify_result_analyse.GetStatus()), + email_info + decr_result_analyse.GetResultReport() + + verify_result_analyse.GetResultReport()); + + } catch (const std::bad_any_cast& e) { + LOG_E() << "capsule" << p["capsule_id"] + << "convert to real type failed" << e.what(); + } + } + + LOG_E() << "mime or signature data is missing"; + }); }); } diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index ea80cb58..998b4245 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -156,8 +156,7 @@ void FilePage::update_main_basical_opera_menu(const QString& selected_path) { } if (info.isFile() && (info.suffix() == "sig" || info.suffix() == "gpg" || - info.suffix() == "pgp" || info.suffix() == "asc" || - info.suffix() == "eml")) { + info.suffix() == "pgp" || info.suffix() == "asc")) { operation_type |= MainWindow::OperationMenu::kVerify; } |