[git] GpgOL - branch, async-enc, updated. gpgol-2.0.6-9-g26b9319

by Andre Heinecke cvs at cvs.gnupg.org
Wed Jan 31 13:23:12 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, async-enc has been updated
       via  26b931937fe139a9acd3240242e154d3789652f5 (commit)
       via  3ed205e7f9d96edfa03762c8692267f68d82ebb8 (commit)
       via  ee673d23ae83563faabe5168019092203766e670 (commit)
      from  c52f7ed9456ad1db74b09bc1eae32750b4277fee (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 26b931937fe139a9acd3240242e154d3789652f5
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Jan 31 13:20:26 2018 +0100

    Fix inline responses by making them sync
    
    * src/mail.cpp (Mail::is_inline_response),
    (Mail::check_inline_response): New.
    (do_crypt): Work sync for inline response.
    * src/mailitem-events.cpp: Work sync for inline response.
    
    --
    Its nice how we can switch between sync and async in the new
    architecture. Hopefully this does not mean double bugs ;-)
    
    Working sync for inline response is necessary because we
    can't trigger a send event programatically for inline responses.

diff --git a/src/mail.cpp b/src/mail.cpp
index 11c31a3..e9000f2 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -138,7 +138,8 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_do_inline(false),
     m_is_gsuite(false),
     m_crypt_state(NoCryptMail),
-    m_window(nullptr)
+    m_window(nullptr),
+    m_is_inline_response(false)
 {
   if (get_mail_for_item (mailitem))
     {
@@ -785,9 +786,17 @@ do_crypt (LPVOID arg)
       return rc;
     }
 
-  mail->set_crypt_state (Mail::NeedsUpdateInOOM);
-
-  do_in_ui_thread (CRYPTO_DONE, arg);
+  if (!mail->is_inline_response ())
+    {
+      mail->set_crypt_state (Mail::NeedsUpdateInOOM);
+      do_in_ui_thread (CRYPTO_DONE, arg);
+    }
+  else
+    {
+      mail->set_crypt_state (Mail::NeedsUpdateInMAPI);
+      mail->update_crypt_mapi ();
+      mail->set_crypt_state (Mail::NeedsUpdateInOOM);
+    }
   gpgrt_lock_unlock (&dtor_lock);
   return 0;
 }
@@ -1157,9 +1166,17 @@ Mail::encrypt_sign_start ()
                  SRCNAME, __func__, this);
       return -1;
     }
-  CloseHandle(CreateThread (NULL, 0, do_crypt,
-                            (LPVOID) this, 0,
-                            NULL));
+
+  if (!m_is_inline_response)
+    {
+      CloseHandle(CreateThread (NULL, 0, do_crypt,
+                                (LPVOID) this, 0,
+                                NULL));
+    }
+  else
+    {
+      do_crypt (this);
+    }
   return 0;
 }
 
@@ -2601,3 +2618,49 @@ Mail::set_window_enabled (bool value)
 
   EnableWindow (m_window, value ? TRUE : FALSE);
 }
+
+bool
+Mail::check_inline_response ()
+{
+  m_is_inline_response = false;
+  LPDISPATCH app = GpgolAddin::get_instance ()->get_application ();
+  if (!app)
+    {
+      TRACEPOINT;
+      return false;
+    }
+
+  LPDISPATCH explorer = get_oom_object (app, "ActiveExplorer");
+
+  if (!explorer)
+    {
+      TRACEPOINT;
+      return false;
+    }
+
+  LPDISPATCH inlineResponse = get_oom_object (explorer, "ActiveInlineResponse");
+  gpgol_release (explorer);
+
+  if (!inlineResponse)
+    {
+      return false;
+    }
+
+  // We have inline response
+  // Check if we are it. It's a bit naive but meh. Worst case
+  // is that we think inline response too often and do sync
+  // crypt where we could do async crypt.
+  char * inlineSubject = get_oom_string (inlineResponse, "Subject");
+  gpgol_release (inlineResponse);
+
+  const auto subject = get_subject ();
+  if (inlineResponse && !subject.empty() && !strcmp (subject.c_str (), inlineSubject))
+    {
+      log_debug ("%s:%s: Detected inline response for '%p'",
+                 SRCNAME, __func__, this);
+      m_is_inline_response = true;
+    }
+  xfree (inlineSubject);
+
+  return m_is_inline_response;
+}
diff --git a/src/mail.h b/src/mail.h
index 0b03ed9..ef0f353 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -387,6 +387,22 @@ public:
     enable. */
   void set_window_enabled (bool value);
 
+  /** Determine if the mail is an inline response.
+
+    Call check_inline_response first to update the state
+    from the OOM.
+
+    We need synchronous encryption for inline responses. */
+  bool is_inline_response () { return m_is_inline_response; }
+
+  /** Check through OOM if the current mail is an inline
+    response.
+
+    Caches the state which can then be queried through
+    is_inline_response
+  */
+  bool check_inline_response ();
+
 private:
   void update_categories ();
   void update_body ();
@@ -425,5 +441,6 @@ private:
   std::string m_inline_body;
   CryptState m_crypt_state;
   HWND m_window;
+  bool m_is_inline_response;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 7023ba7..ec38046 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -358,17 +358,35 @@ EVENT_SINK_INVOKE(MailItemEvents)
               m_mail->set_window_enabled (false);
               m_mail->set_crypt_state (Mail::NeedsFirstAfterWrite);
 
+              // Check inline response state before the write.
+              m_mail->check_inline_response ();
+
               log_debug ("%s:%s: Send event for crypto mail %p saving and starting.",
                          SRCNAME, __func__, m_mail);
               // Save the Mail
               invoke_oom_method (m_object, "Save", NULL);
 
-              // The afterwrite in the save should have triggered
-              // the encryption. We cancel send for our asyncness.
-
-              // Cancel send
-              *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
-              break;
+              if (!m_mail->is_inline_response ())
+                {
+                  // The afterwrite in the save should have triggered
+                  // the encryption. We cancel send for our asyncness.
+                  // Cancel send
+                  *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
+                  break;
+                }
+              else
+                {
+                  // For inline response we can't trigger send programatically
+                  // so we do the encryption in sync.
+                  if (m_mail->crypt_state () == Mail::NeedsUpdateInOOM)
+                    {
+                      m_mail->update_crypt_oom ();
+                    }
+                  if (m_mail->crypt_state () == Mail::NeedsSecondAfterWrite)
+                    {
+                      m_mail->set_crypt_state (Mail::WantsSend);
+                    }
+                }
             }
 
           if (m_mail->crypt_state () == Mail::WantsSend)

commit 3ed205e7f9d96edfa03762c8692267f68d82ebb8
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Jan 31 11:37:32 2018 +0100

    Reactivate T3656 workaround
    
    * src/mailitem-events.cpp: Reactivate workaround.
    
    --
    Now that we do real encryption we can activate this hack again.

diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index f4b9cac..7023ba7 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -373,7 +373,6 @@ EVENT_SINK_INVOKE(MailItemEvents)
 
           if (m_mail->crypt_state () == Mail::WantsSend)
             {
-#if 0
               /* 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
@@ -425,7 +424,6 @@ EVENT_SINK_INVOKE(MailItemEvents)
                 {
                   break;
                 }
-#endif
               log_debug ("%s:%s: Passing send event for message %p.",
                          SRCNAME, __func__, m_object);
               break;

commit ee673d23ae83563faabe5168019092203766e670
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Jan 31 11:28:43 2018 +0100

    Fix window modality of encryption
    
    * src/mail.cpp: Add new member m_window.
    (do_crypt): Renable window when done.
    (Mail::set_window_enabled): New.
    * src/mail.h: Update accordingly.
    * src/mailitem-events.cpp: Disable mail window on crypt send.
    * src/oomhelp.cpp (get_active_hwnd): Add some fallbacks.

diff --git a/src/mail.cpp b/src/mail.cpp
index 53f2890..11c31a3 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -137,7 +137,8 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_type(MSGTYPE_UNKNOWN),
     m_do_inline(false),
     m_is_gsuite(false),
-    m_crypt_state(NoCryptMail)
+    m_crypt_state(NoCryptMail),
+    m_window(nullptr)
 {
   if (get_mail_for_item (mailitem))
     {
@@ -763,7 +764,6 @@ do_crypt (LPVOID arg)
       return -1;
     }
 
-  /* This can take a while */
   int rc = crypter->do_crypto();
 
   gpgrt_lock_lock (&dtor_lock);
@@ -775,6 +775,8 @@ do_crypt (LPVOID arg)
       return 0;
     }
 
+  mail->set_window_enabled (true);
+
   if (rc)
     {
       log_debug ("%s:%s: crypto failed for: %p with: %i",
@@ -1155,7 +1157,6 @@ Mail::encrypt_sign_start ()
                  SRCNAME, __func__, this);
       return -1;
     }
-  //EnableWindow (window, FALSE);
   CloseHandle(CreateThread (NULL, 0, do_crypt,
                             (LPVOID) this, 0,
                             NULL));
@@ -2587,3 +2588,16 @@ Mail::update_crypt_oom()
   m_crypt_state = NeedsSecondAfterWrite;
   return;
 }
+
+void
+Mail::set_window_enabled (bool value)
+{
+  if (!value)
+    {
+      m_window = get_active_hwnd ();
+    }
+  log_debug ("%s:%s: enable window %p %i",
+             SRCNAME, __func__, m_window, value);
+
+  EnableWindow (m_window, value ? TRUE : FALSE);
+}
diff --git a/src/mail.h b/src/mail.h
index 8616a1e..0b03ed9 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -373,7 +373,6 @@ public:
   /** Update MAPI data after encryption. */
   void update_crypt_mapi ();
 
-  /** Update OOM data after encryption. */
   /** Update OOM data after encryption.
 
     Checks for plain text leaks and
@@ -381,6 +380,13 @@ public:
   */
   void update_crypt_oom ();
 
+  /** Enable / Disable the window of this mail.
+
+    When value is false the active window will
+    be disabled and the handle stored for a later
+    enable. */
+  void set_window_enabled (bool value);
+
 private:
   void update_categories ();
   void update_body ();
@@ -418,5 +424,6 @@ private:
   bool m_is_gsuite; /* Are we on a gsuite account */
   std::string m_inline_body;
   CryptState m_crypt_state;
+  HWND m_window;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index de06e47..f4b9cac 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -355,10 +355,11 @@ EVENT_SINK_INVOKE(MailItemEvents)
               // First contact with a mail to encrypt update
               // state and oom data.
               m_mail->update_oom_data ();
+              m_mail->set_window_enabled (false);
               m_mail->set_crypt_state (Mail::NeedsFirstAfterWrite);
 
-             log_debug ("%s:%s: Send event for crypto mail %p saving and starting.",
-                        SRCNAME, __func__, m_mail);
+              log_debug ("%s:%s: Send event for crypto mail %p saving and starting.",
+                         SRCNAME, __func__, m_mail);
               // Save the Mail
               invoke_oom_method (m_object, "Save", NULL);
 
diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index 45013b4..ce444d7 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -1749,8 +1749,16 @@ get_active_hwnd ()
   LPDISPATCH activeWindow = get_oom_object (app, "ActiveWindow");
   if (!activeWindow)
     {
-      TRACEPOINT;
-      return nullptr;
+      activeWindow = get_oom_object (app, "ActiveInspector");
+      if (!activeWindow)
+        {
+          activeWindow = get_oom_object (app, "ActiveExplorer");
+          if (!activeWindow)
+            {
+              TRACEPOINT;
+              return nullptr;
+            }
+        }
     }
 
   /* Both explorer and inspector have this. */

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

Summary of changes:
 src/mail.cpp            | 95 ++++++++++++++++++++++++++++++++++++++++++++-----
 src/mail.h              | 26 +++++++++++++-
 src/mailitem-events.cpp | 37 +++++++++++++------
 src/oomhelp.cpp         | 12 +++++--
 4 files changed, 148 insertions(+), 22 deletions(-)


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




More information about the Gnupg-commits mailing list