Page MenuHome GnuPG

gpgol-forward-patch.diff

Authored By
aheinecke
Mar 13 2018, 11:15 AM
Size
7 KB
Subscribers
None

gpgol-forward-patch.diff

diff --git a/src/application-events.cpp b/src/application-events.cpp
index c000a86..1100934 100644
--- a/src/application-events.cpp
+++ b/src/application-events.cpp
@@ -33,6 +33,7 @@
#include "oomhelp.h"
#include "mail.h"
#include "gpgoladdin.h"
+#include "windowmessages.h"
/* Application Events */
BEGIN_EVENT_SINK(ApplicationEvents, IDispatch)
@@ -91,6 +92,7 @@ EVENT_SINK_INVOKE(ApplicationEvents)
log_debug ("%s:%s: Creating mail object for item: %p",
SRCNAME, __func__, mailItem);
new Mail (mailItem);
+ do_in_ui_thread_async (INVALIDATE_LAST_MAIL, nullptr);
break;
}
case Quit:
diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index da23de4..da60c3b 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -517,7 +517,8 @@ CryptController::do_crypto ()
gpgol_message_box (nullptr,
utf8_gettext ("Failure to resolve keys."),
utf8_gettext ("GpgOL"), MB_OK);
- return ret;
+ // Error handled, return as canceled.
+ return -2;
}
if (ret == -2)
{
@@ -539,7 +540,7 @@ CryptController::do_crypto ()
{
log_error ("%s:%s: Failure to create context.",
SRCNAME, __func__);
- gpgol_message_box (nullptr,
+ gpgol_message_box (m_mail->get_window (),
"Failure to create context.",
utf8_gettext ("GpgOL"), MB_OK);
return -1;
diff --git a/src/mail.cpp b/src/mail.cpp
index ba2b501..749c209 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -748,20 +748,27 @@ do_crypt (LPVOID arg)
return 0;
}
- mail->set_window_enabled (true);
-
if (rc == -1)
{
- gpgol_message_box (nullptr,
- "Crypto failed",
+ mail->reset_crypter ();
+ crypter = nullptr;
+ gpgol_message_box (mail->get_window (),
+ utf8_gettext ("Sign / Encrypt failed.\n\n"
+ "This is usually caused by an error in your system.\n"
+ "Please refer to the Gpg4win compendium how to enable debugging in GpgOL,"
+ "or ask your Administrator for support."),
_("GpgOL"), MB_OK);
}
+
+ mail->set_window_enabled (true);
+
if (rc)
{
log_debug ("%s:%s: crypto failed for: %p with: %i",
SRCNAME, __func__, arg, rc);
mail->set_crypt_state (Mail::NoCryptMail);
mail->reset_crypter ();
+ crypter = nullptr;
gpgrt_lock_unlock (&dtor_lock);
return rc;
}
@@ -1069,9 +1076,6 @@ Mail::parsing_done()
SRCNAME, __func__);
}
- /* Invalidate UI to set the correct sig status. */
- m_parser = nullptr;
-
log_debug ("%s:%s: Delayed invalidate to update sigstate.",
SRCNAME, __func__);
CloseHandle(CreateThread (NULL, 0, delayed_invalidate_ui, (LPVOID) this, 0,
@@ -2582,6 +2586,13 @@ Mail::get_last_mail ()
// static
void
+Mail::invalidate_last_mail ()
+{
+ s_last_mail = nullptr;
+}
+
+// static
+void
Mail::locate_all_crypto_recipients()
{
if (!opt.autoresolve)
diff --git a/src/mail.h b/src/mail.h
index f8cdbab..36038bd 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -92,6 +92,8 @@ public:
*/
static Mail* get_last_mail ();
+ static void invalidate_last_mail ();
+
/** @brief looks for existing Mail objects.
@returns A reference to an existing mailitem or NULL in case none
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 2360789..5ef7138 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -480,6 +480,15 @@ EVENT_SINK_INVOKE(MailItemEvents)
if (m_mail->is_crypto_mail () && !m_mail->needs_save ())
{
+ Mail *last_mail = Mail::get_last_mail ();
+ if (Mail::is_valid_ptr (last_mail))
+ {
+ log_debug ("%s:%s: Write in the same loop as load."
+ " Pass but schedule revert.",
+ SRCNAME, __func__);
+ do_in_ui_thread_async (REVERT_MAIL, m_mail);
+ return S_OK;
+ }
/* We cancel the write event to stop outlook from excessively
syncing our changes.
if smime support is disabled and we still have an smime
diff --git a/src/windowmessages.cpp b/src/windowmessages.cpp
index b0e2311..2335110 100644
--- a/src/windowmessages.cpp
+++ b/src/windowmessages.cpp
@@ -68,6 +68,22 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
mail->locate_keys();
break;
}
+ case (REVERT_MAIL):
+ {
+ auto mail = (Mail*) ctx->data;
+ if (!Mail::is_valid_ptr (mail))
+ {
+ log_debug ("%s:%s: Revert mail for mail which is gone.",
+ SRCNAME, __func__);
+ break;
+ }
+ mail->set_needs_save (true);
+ log_debug ("%s:%s: Revert mail. Invoking save.",
+ SRCNAME, __func__);
+ invoke_oom_method (mail->item (), "Save", NULL);
+ mail->parsing_done ();
+ break;
+ }
case (INVALIDATE_UI):
{
log_debug ("%s:%s: Invalidating UI",
@@ -77,6 +93,13 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SRCNAME, __func__);
break;
}
+ case (INVALIDATE_LAST_MAIL):
+ {
+ log_debug ("%s:%s: Invalidating last mail",
+ SRCNAME, __func__);
+ Mail::invalidate_last_mail ();
+ break;
+ }
case (CLOSE):
{
auto mail = (Mail*) ctx->data;
@@ -114,6 +137,8 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
// Finaly this should pass.
invoke_oom_method (mail->item (), "Send", NULL);
+ log_debug ("%s:%s: Send for %p completed.",
+ SRCNAME, __func__, mail);
// Allow the WKS helper to queue a notification.
WKSHelper::instance()->allow_notify ();
break;
diff --git a/src/windowmessages.h b/src/windowmessages.h
index 979f0b4..56d9db8 100644
--- a/src/windowmessages.h
+++ b/src/windowmessages.h
@@ -50,6 +50,8 @@ typedef enum _gpgol_wmsg_type
CRYPTO_DONE, /* Sign / Encrypt done. */
WKS_NOTIFY, /* Show a WKS Notification. */
BRING_TO_FRONT, /* Bring the active Outlook window to the front. */
+ INVALIDATE_LAST_MAIL,
+ REVERT_MAIL,
} gpgol_wmsg_type;
typedef struct
diff --git a/src/wks-helper.cpp b/src/wks-helper.cpp
index 16d42ba..52c05c1 100644
--- a/src/wks-helper.cpp
+++ b/src/wks-helper.cpp
@@ -623,6 +623,12 @@ WKSHelper::send_mail (const std::string &mimeData) const
a Hack! :-) */
auto last_mail = Mail::get_last_mail ();
+ if (!Mail::is_valid_ptr (last_mail))
+ {
+ log_error ("%s:%s: Invalid last mail %p.",
+ SRCNAME, __func__, last_mail);
+ return -1;
+ }
last_mail->set_override_mime_data (mimeData);
last_mail->set_crypt_state (Mail::NeedsSecondAfterWrite);

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
143039

Event Timeline