Fallback to MAPI SubmitMessage if OOM Send fails
authorAndre Heinecke <aheinecke@intevation.de>
Thu, 6 Sep 2018 09:54:34 +0000 (11:54 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Thu, 6 Sep 2018 10:00:49 +0000 (12:00 +0200)
* src/common.h (ERR_SEND_FALLBACK_FAILED): New error code.
* src/windowmessages.cpp (gpgol_window_proc): Fallback to SubmitMessage
on OOM Send failure.

--
This is a workaround for a strange case where the write
in the send event fails. This happens for example if
office documents are attached to a mail. In that
case we can fallback to MAPI as we already do when
Outlooks internal Sign / Encrypt is selected.
Maybe we could be so bold as to always send over
MAPI.

GnuPG-Bug-Id: T4131
(cherry picked from commit 8fb3524262283c77a91f7e6c615d97f426455332)

src/common.h
src/windowmessages.cpp

index 52099fd..583a63a 100644 (file)
@@ -123,6 +123,7 @@ void i18n_init (void);
 #define ERR_WANTS_SEND_INLINE_BODY 3
 #define ERR_INLINE_BODY_TO_BODY 4
 #define ERR_INLINE_BODY_INV_STATE 5
+#define ERR_SEND_FALLBACK_FAILED 6
 #ifdef __cplusplus
 }
 #endif
index e9ec1e5..e0c5bab 100644 (file)
@@ -163,10 +163,33 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                              SRCNAME, __func__, mail);
                 }
               // Finaly this should pass.
-              invoke_oom_method (mail->item (), "Send", NULL);
+              if (invoke_oom_method (mail->item (), "Send", NULL))
+                {
+                  log_error ("%s:%s: Send failed for %p. "
+                             "Trying SubmitMessage instead.",
+                             SRCNAME, __func__, mail);
+                  auto mail_message = get_oom_base_message (mail->item());
+                  // It's important we use the _base_ message here.
+                  mapi_save_changes (mail_message,
+                                     KEEP_OPEN_READWRITE | FORCE_SAVE);
+                  HRESULT hr = mail_message->SubmitMessage(0);
+                  gpgol_release (mail_message);
+
+                  if (hr == S_OK)
+                    {
+                      do_in_ui_thread_async (CLOSE, (LPVOID) mail);
+                    }
+                  else
+                    {
+                      log_error ("%s:%s: SubmitMessage Failed hr=0x%lx.",
+                                 SRCNAME, __func__, hr);
+                      gpgol_bug (mail->getWindow (),
+                                 ERR_SEND_FALLBACK_FAILED);
+                    }
+                }
               log_debug ("%s:%s:  Send for %p completed.",
                          SRCNAME, __func__, mail);
-              mail->releaseCurrentItem();
+              mail->releaseCurrentItem ();
               break;
             }
           case (BRING_TO_FRONT):