[git] GpgOL - branch, master, updated. gpgol-2.0.5-14-g707250c

by Andre Heinecke cvs at cvs.gnupg.org
Thu Jan 11 16:47:51 CET 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG extension for MS Outlook".

The branch, master has been updated
       via  707250ce6151a504f9143776cec2d6f09f4a80e4 (commit)
       via  090e2a0cb2fffad534544119604bfa454e90c016 (commit)
      from  a6eeeaaa902a80aec50fe3fbc42f09683a8b4f36 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 707250ce6151a504f9143776cec2d6f09f4a80e4
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Jan 11 16:40:31 2018 +0100

    Add special sauce for Outlook S/MIME code interact
    
    * src/mailitem-events.cpp (EVENT_SINK_INVOKE): Check if after
    encryption msgclass is not gpgol on MAPI Message and activate
    Hack if otherwise.
    * src/windowmessage.cpp (delayed_close, CLOSE): New.
    * src/windowmessage.h: Update Accordingly.
    
    --
    If somehow S/MIME is involved in Outlook, even if the S/MIME sign
    button is just toggled and untoggled, Outlook changes behavior.
    When that happened Send would send the plain text mail instead
    of the encrypted mail.
    
    Now this here is very much experimental programming:
     When the S/MIME Code is somehow involved the Message in MAPI
     (not the base message) is not correctly updated and shows the
     original IPM.Note message class. We detect that now.
     If that happens we use super low level MAPI to submit our
     constructed base message and then cancel the send / close the
     composer.
    
    GnuPG-Bug-Id: T3656

diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 88bac05..8d42e81 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -23,6 +23,7 @@
 #include "eventsink.h"
 #include "eventsinks.h"
 #include "mymapi.h"
+#include "mymapitags.h"
 #include "oomhelp.h"
 #include "ocidl.h"
 #include "windowmessages.h"
@@ -336,8 +337,8 @@ EVENT_SINK_INVOKE(MailItemEvents)
                          SRCNAME, __func__, m_mail);
           if (!m_mail->needs_crypto ())
             {
-             log_debug ("%s:%s: No crypto neccessary. Passing send for unencrypted %p",
-                        SRCNAME, __func__, m_mail);
+             log_debug ("%s:%s: No crypto neccessary. Passing send for %p obj %p",
+                        SRCNAME, __func__, m_mail, m_object);
              break;
             }
 
@@ -349,6 +350,7 @@ EVENT_SINK_INVOKE(MailItemEvents)
            }
           m_mail->update_oom_data ();
           m_mail->set_needs_encrypt (true);
+
           invoke_oom_method (m_object, "Save", NULL);
           if (m_mail->crypto_successful ())
             {
@@ -376,29 +378,75 @@ EVENT_SINK_INVOKE(MailItemEvents)
                       break;
                     }
 
-                  if (!m_mail->wipe (true))
+                  if (m_mail->wipe (true))
                     {
-                      log_debug ("%s:%s: Wipe succeded. %p.",
-                                 SRCNAME, __func__, m_object);
-
-                      log_debug ("%s:%s: Passing send event for message %p.",
+                      log_debug ("%s:%s: Cancel send for %p.",
                                 SRCNAME, __func__, m_object);
+                      wchar_t *title = utf8_to_wchar (_("GpgOL: Encryption not possible!"));
+                      wchar_t *msg = utf8_to_wchar (_(
+                      "Outlook returned an error when trying to send the encrypted mail.\n\n"
+                      "Please restart Outlook and try again.\n\n"
+                      "If it still fails consider using an encrypted attachment or\n"
+                      "switching to PGP/Inline in GpgOL's options."));
+                      MessageBoxW (get_active_hwnd(), msg, title,
+                                   MB_ICONERROR | MB_OK);
+                      xfree (msg);
+                      xfree (title);
+                      *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
+                      return S_OK;
+                    }
+                    {
+                      /* Now we adress T3656 if Outlooks internal S/MIME is somehow
+                       * mixed in (even if it is enabled and then disabled) it might
+                       * cause strange behavior in that it sends the plain message
+                       * and not the encrypted message. Tests have shown that we can
+                       * bypass that by calling submit message on our base
+                       * message.
+                       *
+                       * We do this conditionally as our other way of using OOM
+                       * to send is proven to work and we don't want to mess
+                       * with it.
+                       */
+                      // Get the Message class.
+                      HRESULT hr;
+                      LPSPropValue propval = NULL;
+
+                      LPMESSAGE message = get_oom_message (m_object);
+                      hr = HrGetOneProp ((LPMAPIPROP)message, PR_MESSAGE_CLASS_A, &propval);
+                      gpgol_release (message);
+                      if (FAILED (hr))
+                        {
+                          log_error ("%s:%s: HrGetOneProp() failed: hr=%#lx\n",
+                                     SRCNAME, __func__, hr);
+                          gpgol_release (message);
+                          break;
+                        }
+                      if (propval->Value.lpszA && !strstr (propval->Value.lpszA, "GpgOL"))
+                        {
+                          // Does not have a message class by us.
+                          log_debug ("%s:%s: Message %p - No GpgOL Message class after encryption.",
+                                    SRCNAME, __func__, m_object);
+                          log_debug ("%s:%s: Message %p - Activating T3656 Workaround",
+                                    SRCNAME, __func__, m_object);
+                          message = get_oom_base_message (m_object);
+                          mapi_save_changes (message, KEEP_OPEN_READWRITE | FORCE_SAVE);
+                          message->SubmitMessage(0);
+                          gpgol_release (message);
+
+                          // Cancel send
+                          *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
+
+                          // Close the composer and trigger unloads
+                          CloseHandle(CreateThread (NULL, 0, close_mail, (LPVOID) m_mail, 0,
+                                                    NULL));
+                        }
+                      MAPIFreeBuffer (propval);
+                    }
+
+                  if (*(parms->rgvarg[0].pboolVal) == VARIANT_TRUE)
+                    {
                       break;
                     }
-                  log_debug ("%s:%s: Cancel send for %p.",
-                            SRCNAME, __func__, m_object);
-                  wchar_t *title = utf8_to_wchar (_("GpgOL: Encryption not possible!"));
-                  wchar_t *msg = utf8_to_wchar (_(
-                  "Outlook returned an error when trying to send the encrypted mail.\n\n"
-                  "Please restart Outlook and try again.\n\n"
-                  "If it still fails consider using an encrypted attachment or\n"
-                  "switching to PGP/Inline in GpgOL's options."));
-                  MessageBoxW (get_active_hwnd(), msg, title,
-                               MB_ICONERROR | MB_OK);
-                  xfree (msg);
-                  xfree (title);
-                  *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
-                  return S_OK;
                 }
               log_debug ("%s:%s: Passing send event for message %p.",
                          SRCNAME, __func__, m_object);
@@ -454,6 +502,8 @@ EVENT_SINK_INVOKE(MailItemEvents)
               *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
             }
 
+          log_debug ("%s:%s: Passing write event. Subject: %s Body: %s MsgCls: %s",
+                     SRCNAME, __func__, m_mail->get_subject().c_str(), m_mail->get_body().c_str(), get_oom_string (m_object, "MessageClass"));
           log_debug ("%s:%s: Passing write event.",
                      SRCNAME, __func__);
           m_mail->set_needs_save (false);
diff --git a/src/windowmessages.cpp b/src/windowmessages.cpp
index 1259496..f44b9df 100644
--- a/src/windowmessages.cpp
+++ b/src/windowmessages.cpp
@@ -76,6 +76,18 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                          SRCNAME, __func__);
               break;
             }
+          case (CLOSE):
+            {
+              auto mail = (Mail*) ctx->data;
+              if (!Mail::is_valid_ptr (mail))
+                {
+                  log_debug ("%s:%s: Close for mail which is gone.",
+                             SRCNAME, __func__);
+                  break;
+                }
+              Mail::close (mail);
+              break;
+            }
           default:
             log_debug ("Unknown msg");
         }
@@ -255,3 +267,10 @@ delayed_invalidate_ui (LPVOID)
   gpgrt_lock_unlock(&invalidate_lock);
   return 0;
 }
+
+DWORD WINAPI
+close_mail (LPVOID mail)
+{
+  do_in_ui_thread (CLOSE, mail);
+  return 0;
+}
diff --git a/src/windowmessages.h b/src/windowmessages.h
index cc1cb62..f53ecd4 100644
--- a/src/windowmessages.h
+++ b/src/windowmessages.h
@@ -42,6 +42,7 @@ typedef enum _gpgol_wmsg_type
                       to the mail object. */
   RECIPIENT_ADDED = 3, /* A recipient was added. Data should be ptr
                           to mail */
+  CLOSE = 4, /* Send the message in the next event loop. */
 } gpgol_wmsg_type;
 
 typedef struct
@@ -73,6 +74,9 @@ create_message_hook();
 DWORD WINAPI
 delayed_invalidate_ui (LPVOID);
 
+DWORD WINAPI
+close_mail (LPVOID);
+
 void add_explorer (LPDISPATCH explorer);
 void remove_explorer (LPDISPATCH explorer);
 

commit 090e2a0cb2fffad534544119604bfa454e90c016
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Jan 11 14:25:33 2018 +0100

    Revert increased verbosity for T3656
    
    --
    The bug is now reproducable. It depends on Outlooks S/MIME settings.

diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 35d9c10..88bac05 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -332,8 +332,8 @@ EVENT_SINK_INVOKE(MailItemEvents)
              If this encryption is successful and we pass the send
              as then the encrypted data is sent.
            */
-          log_debug ("%s:%s: Send : %p item %p",
-                     SRCNAME, __func__, m_object, m_mail);
+          log_oom_extra ("%s:%s: Send : %p",
+                         SRCNAME, __func__, m_mail);
           if (!m_mail->needs_crypto ())
             {
              log_debug ("%s:%s: No crypto neccessary. Passing send for unencrypted %p",
@@ -349,14 +349,6 @@ EVENT_SINK_INVOKE(MailItemEvents)
            }
           m_mail->update_oom_data ();
           m_mail->set_needs_encrypt (true);
-          log_debug ("%s:%s: Send : %p item %p needs encrypt. Calling save.",
-                     SRCNAME, __func__, m_mail, m_object);
-          log_debug ("%s:%s: Send : %p Setting uuid.",
-                     SRCNAME, __func__, m_mail);
-          m_mail->set_uuid ();
-          log_debug ("%s:%s: Send : %p has subject: %s.",
-                     SRCNAME, __func__, m_mail, m_mail->get_subject ().c_str());
-
           invoke_oom_method (m_object, "Save", NULL);
           if (m_mail->crypto_successful ())
             {
@@ -389,9 +381,8 @@ EVENT_SINK_INVOKE(MailItemEvents)
                       log_debug ("%s:%s: Wipe succeded. %p.",
                                  SRCNAME, __func__, m_object);
 
-                      const auto uuid = m_mail->get_uuid ();
-                      log_debug ("%s:%s: Passing send event for message %p uuid: %s.",
-                                SRCNAME, __func__, m_object, uuid.empty() ? "null" : uuid.c_str ());
+                      log_debug ("%s:%s: Passing send event for message %p.",
+                                SRCNAME, __func__, m_object);
                       break;
                     }
                   log_debug ("%s:%s: Cancel send for %p.",
@@ -409,22 +400,22 @@ EVENT_SINK_INVOKE(MailItemEvents)
                   *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
                   return S_OK;
                 }
-              log_debug ("%s:%s: Passing send event for encrypted message %p item %p.",
-                         SRCNAME, __func__, m_object, m_mail);
+              log_debug ("%s:%s: Passing send event for message %p.",
+                         SRCNAME, __func__, m_object);
               break;
             }
           else
             {
-              log_debug ("%s:%s: Message %p cancelling send - crypto failed item %p.",
-                         SRCNAME, __func__, m_object, m_mail);
+              log_debug ("%s:%s: Message %p cancelling send - crypto failed.",
+                         SRCNAME, __func__, m_object);
               *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
             }
           return S_OK;
         }
       case Write:
         {
-          log_debug ("%s:%s: Write : %p",
-                     SRCNAME, __func__, m_mail);
+          log_oom_extra ("%s:%s: Write : %p",
+                         SRCNAME, __func__, m_mail);
           /* This is a bit strange. We sometimes get multiple write events
              without a read in between. When we access the message in
              the second event it fails and if we cancel the event outlook
@@ -463,29 +454,20 @@ EVENT_SINK_INVOKE(MailItemEvents)
               *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
             }
 
-          const auto uuid = m_mail->get_uuid ();
-          log_debug ("%s:%s: Passing write event for message %p mailitem %p uuid: %s subject: %s",
-                     SRCNAME, __func__, m_object, m_mail, uuid.empty() ? "null" : uuid.c_str (),
-                     m_mail->get_subject ().c_str());
+          log_debug ("%s:%s: Passing write event.",
+                     SRCNAME, __func__);
           m_mail->set_needs_save (false);
           break;
         }
       case AfterWrite:
         {
-          log_debug ("%s:%s: AfterWrite : %p",
+          log_oom_extra ("%s:%s: AfterWrite : %p",
                          SRCNAME, __func__, m_mail);
           if (m_mail->needs_encrypt ())
             {
-              log_debug ("%s:%s: Mail needs encrypt: %p",
-                             SRCNAME, __func__, m_mail);
               m_mail->encrypt_sign ();
               return S_OK;
             }
-          else
-            {
-              log_debug ("%s:%s: Mail does not need encrypt: %p",
-                         SRCNAME, __func__, m_mail);
-            }
           break;
         }
       case Close:
diff --git a/src/mimemaker.cpp b/src/mimemaker.cpp
index 17b64d4..057df95 100644
--- a/src/mimemaker.cpp
+++ b/src/mimemaker.cpp
@@ -86,8 +86,6 @@ sink_std_write (sink_t sink, const void *data, size_t datalen)
   if (!data)
     return 0;  /* Flush - nothing to do here.  */
 
-  log_debug ("Sink write: %.*s", (int)datalen, (char*)data);
-
   hr = stream->Write(data, datalen, NULL);
   if (hr)
     {

-----------------------------------------------------------------------

Summary of changes:
 src/mailitem-events.cpp | 130 ++++++++++++++++++++++++++++++------------------
 src/mimemaker.cpp       |   2 -
 src/windowmessages.cpp  |  19 +++++++
 src/windowmessages.h    |   4 ++
 4 files changed, 104 insertions(+), 51 deletions(-)


hooks/post-receive
-- 
GnuPG extension for MS Outlook
http://git.gnupg.org




More information about the Gnupg-commits mailing list