[git] GpgOL - branch, nomapi, updated. gpgol-1.4.0-114-gcb08933

by Andre Heinecke cvs at cvs.gnupg.org
Thu Oct 20 12:02:22 CEST 2016


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, nomapi has been updated
       via  cb089330c44f37412a47501660b09d09cc382c45 (commit)
       via  e1420cc2a8f0bb8c45c8253212fcc32475531f41 (commit)
       via  71b06f0662a24f66381d349d8ee8da93a33f500b (commit)
       via  b8e39830594d87a41056e7d9dd8dff2ff4904aac (commit)
       via  a4cb385ee539570d6a5d67a9c7651173905be0c3 (commit)
       via  525680f952ed3f2e361c8582f5df3a12f07defb8 (commit)
      from  ed7b79ff86d7c0a3cc1ecac2fc304fe098f29cfb (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 cb089330c44f37412a47501660b09d09cc382c45
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 12:01:35 2016 +0200

    Close thread handles immediately after creation
    
    --
    This fixes leaked handles and as we "fire & forget" our threads
    we don't need the handles anymore.

diff --git a/src/mail.cpp b/src/mail.cpp
index 572280b..efe5a29 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -95,8 +95,7 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_is_valid(false),
     m_moss_position(0),
     m_sender(NULL),
-    m_type(MSGTYPE_UNKNOWN),
-    m_parser_thread(NULL)
+    m_type(MSGTYPE_UNKNOWN)
 {
   if (get_mail_for_item (mailitem))
     {
@@ -142,11 +141,6 @@ Mail::~Mail()
 
   xfree (m_sender);
   gpgol_release(m_mailitem);
-
-  if (m_parser_thread)
-    {
-      CloseHandle (m_parser_thread);
-    }
 }
 
 Mail *
@@ -453,7 +447,6 @@ add_attachments(LPDISPATCH mail,
                      SRCNAME, __func__, att->get_display_name().c_str());
           err = 1;
         }
-      CloseHandle (hFile);
       xfree (wchar_file);
       xfree (wchar_name);
       if (err)
@@ -532,14 +525,15 @@ Mail::decrypt_verify()
   m_parser = new ParseController (cipherstream, m_type);
   gpgol_release (cipherstream);
 
-  m_parser_thread = CreateThread (NULL, 0, do_parsing, (LPVOID) this, 0,
-                                  NULL);
+  HANDLE parser_thread = CreateThread (NULL, 0, do_parsing, (LPVOID) this, 0,
+                                       NULL);
 
-  if (!m_parser_thread)
+  if (!parser_thread)
     {
       log_error ("%s:%s: Failed to create decrypt / verify thread.",
                  SRCNAME, __func__);
     }
+  CloseHandle (parser_thread);
 
   return 0;
 }
@@ -613,11 +607,6 @@ Mail::parsing_done()
   m_parser = nullptr;
   gpgoladdin_invalidate_ui ();
   TRACEPOINT;
-  if (m_parser_thread)
-    {
-      CloseHandle (m_parser_thread);
-      m_parser_thread = NULL;
-    }
   return;
 }
 
diff --git a/src/mail.h b/src/mail.h
index 1b69e2a..83c10ab 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -267,6 +267,5 @@ private:
   GpgME::Signature m_sig;
   GpgME::UserID m_uid;
   std::string m_uuid;
-  HANDLE m_parser_thread;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index e03ba0e..e4442cc 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -322,16 +322,18 @@ EVENT_SINK_INVOKE(MailItemEvents)
                      Appearently Outlook locks some methods in some events.
                      So we Create a new thread that will sleep a bit before
                      it requests to send the item again. */
-                  CreateThread (NULL, 0, request_send, (LPVOID) m_object, 0,
-                                NULL);
+                  HANDLE thread = CreateThread (NULL, 0, request_send,
+                                                (LPVOID) m_object, 0, NULL);
+                  CloseHandle (thread);
                 }
               return S_OK;
             }
           else if (m_decrypt_after_write)
             {
               char *uuid = strdup (m_mail->get_uuid ().c_str());
-              CreateThread (NULL, 0, request_decrypt, (LPVOID) uuid, 0,
-                            NULL);
+              HANDLE thread = CreateThread (NULL, 0, request_decrypt,
+                                            (LPVOID) uuid, 0, NULL);
+              CloseHandle (thread);
             }
           break;
         }

commit e1420cc2a8f0bb8c45c8253212fcc32475531f41
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 11:53:59 2016 +0200

    Fix explorer display after mail was closed
    
    * src/mailitem-events.cpp (request_decrypt): New. Request a decypt.
    (EVENT_SINK_INVOKE(MailItemEvents)): Handle decrypt_after_write.
    Don't always unload in unload.
    * src/windowmessages.cpp: Handle REQUEST_DECRYPT.
    * src/windowmessages.h: Add REQUEST_DECRYPT.
    
    --
    To prevent the question of wether or not to save the changes
    (Which would save the decrypted data without an event to
    prevent it) we save proactively. This happens by set_needs_save
    and calling save. Which will revert a mail because we never want
    to save unreverted mails.
    
    But as a side effect the mail, if opened in the explorer still will
    be reverted, too. So shown as empty. This is bad. To prevent that
    we request a decrypt in the AfterWrite event.
    
    Evil Hack: Outlook sends an Unload event after the message is closed
    This is not true our Internal Object is kept alive if it is opened
    in the explorer. So we ignore the unload event and then check in
    the window message handler that checks for decrypt again if the
    mail is currently open in the active explorer. If not we delete our
    Mail object so that the message is released.

diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index e526124..e03ba0e 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -73,6 +73,7 @@ BEGIN_EVENT_SINK(MailItemEvents, IDispatch)
 private:
   Mail * m_mail; /* The mail object related to this mailitem */
   bool m_send_seen;   /* The message is about to be submitted */
+  bool m_decrypt_after_write;
 };
 
 MailItemEvents::MailItemEvents() :
@@ -81,7 +82,8 @@ MailItemEvents::MailItemEvents() :
     m_cookie(0),
     m_ref(1),
     m_mail(NULL),
-    m_send_seen (false)
+    m_send_seen (false),
+    m_decrypt_after_write(false)
 {
 }
 
@@ -109,6 +111,19 @@ request_send (LPVOID arg)
   return 0;
 }
 
+static DWORD WINAPI
+request_decrypt (LPVOID arg)
+{
+  log_debug ("%s:%s: requesting decrypt again for: %p",
+             SRCNAME, __func__, arg);
+  if (do_in_ui_thread (REQUEST_DECRYPT, arg))
+    {
+      log_debug ("%s:%s: second decrypt failed for: %p",
+                 SRCNAME, __func__, arg);
+    }
+  return 0;
+}
+
 /* The main Invoke function. The return value of this
    function does not appear to have any effect on outlook
    although I have read in an example somewhere that you
@@ -312,21 +327,56 @@ EVENT_SINK_INVOKE(MailItemEvents)
                 }
               return S_OK;
             }
+          else if (m_decrypt_after_write)
+            {
+              char *uuid = strdup (m_mail->get_uuid ().c_str());
+              CreateThread (NULL, 0, request_decrypt, (LPVOID) uuid, 0,
+                            NULL);
+            }
           break;
         }
       case Close:
         {
           if (m_mail->is_crypto_mail ())
             {
+              /* Close. This happens when an Opened mail is closed.
+                 To prevent the question of wether or not to save the changes
+                 (Which would save the decrypted data without an event to
+                 prevent it) we save proactively. This happens by set_needs_save
+                 and calling save. Which will revert a mail because we never want
+                 to save unreverted mails.
+
+                 But as a side effect the mail, if opened in the explorer still will
+                 be reverted, too. So shown as empty. This is bad. To prevent that
+                 we request a decrypt in the AfterWrite event.
+
+                 Evil Hack: Outlook sends an Unload event after the message is closed
+                 This is not true our Internal Object is kept alive if it is opened
+                 in the explorer. So we ignore the unload event and then check in
+                 the window message handler that checks for decrypt again if the
+                 mail is currently open in the active explorer. If not we delete our
+                 Mail object so that the message is released.
+              */
               m_mail->set_needs_save (true);
+              m_decrypt_after_write = true;
               invoke_oom_method (m_object, "Save", NULL);
             }
         }
       case Unload:
         {
-          log_debug ("%s:%s: Removing Mail for message: %p.",
-                     SRCNAME, __func__, m_object);
-          delete m_mail;
+          if (!m_decrypt_after_write)
+            {
+              log_debug ("%s:%s: Removing Mail for message: %p.",
+                         SRCNAME, __func__, m_object);
+              delete m_mail;
+            }
+          else
+            {
+              /* See explanation in Close why this is not broken. */
+              log_debug ("%s:%s: Ignoring unload for message: %p.",
+                         SRCNAME, __func__, m_object);
+              m_decrypt_after_write = false;
+            }
           return S_OK;
         }
       default:
diff --git a/src/windowmessages.cpp b/src/windowmessages.cpp
index 7825e9c..d7e9fdc 100644
--- a/src/windowmessages.cpp
+++ b/src/windowmessages.cpp
@@ -23,6 +23,7 @@
 #include "common.h"
 #include "oomhelp.h"
 #include "mail.h"
+#include "gpgoladdin.h"
 
 #include <stdio.h>
 
@@ -70,7 +71,47 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                   break;
                 }
               mail->parsing_done();
+              break;
             }
+          case (REQUEST_DECRYPT):
+            {
+              char *uuid = (char *) ctx->data;
+              auto mail = Mail::get_mail_for_uuid (uuid);
+              if (!mail)
+                {
+                  log_debug ("%s:%s: Decrypt again for uuid which is gone.",
+                             SRCNAME, __func__);
+                  xfree (uuid);
+                  break;
+                }
+              /* Check if we are still in the active explorer. */
+              LPDISPATCH mailitem = get_oom_object (GpgolAddin::get_instance()->get_application (),
+                                                    "ActiveExplorer.Selection.Item(1)");
+              if (!mailitem)
+                {
+                  log_debug ("%s:%s: Decrypt again but no selected mailitem.",
+                             SRCNAME, __func__);
+                  xfree (uuid);
+                  delete mail;
+                  break;
+                }
+
+              char *active_uuid = get_unique_id (mailitem, 0);
+              if (!active_uuid || strcmp (active_uuid, uuid))
+                {
+                  log_debug ("%s:%s: UUID mismatch",
+                             SRCNAME, __func__);
+                  xfree (uuid);
+                  delete mail;
+                  break;
+                }
+              xfree (uuid);
+              xfree (active_uuid);
+
+              mail->decrypt_verify ();
+              break;
+            }
+
           break;
           default:
             log_debug ("Unknown msg");
diff --git a/src/windowmessages.h b/src/windowmessages.h
index ec66f7b..3ebefec 100644
--- a/src/windowmessages.h
+++ b/src/windowmessages.h
@@ -40,8 +40,9 @@ typedef enum _gpgol_wmsg_type
   UNKNOWN = 0,
   REQUEST_SEND_MAIL = 1, /* Request to send a mail.
                             Data should be LPMAILITEM */
-  PARSING_DONE = 2 /* A mail was parsed. Data should be a pointer
+  PARSING_DONE = 2, /* A mail was parsed. Data should be a pointer
                       to the mail object. */
+  REQUEST_DECRYPT = 3
 } gpgol_wmsg_type;
 
 typedef struct

commit 71b06f0662a24f66381d349d8ee8da93a33f500b
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 11:52:26 2016 +0200

    Revert all active mails on quit
    
    * src/application-events.cpp: Call revert_all_mails in quit event.
    
    --
    This prevents the Outlook Questions "Do you want to save the
    changes to the mails." As we save the mails first this also
    prevents the buggy Outlook / MAPI layer asymmetry that could
    lead to endless sync loops.

diff --git a/src/application-events.cpp b/src/application-events.cpp
index 44fe2b5..dbce53d 100644
--- a/src/application-events.cpp
+++ b/src/application-events.cpp
@@ -94,6 +94,11 @@ EVENT_SINK_INVOKE(ApplicationEvents)
           gpgoladdin_invalidate_ui ();
           break;
         }
+      case Quit:
+        {
+          log_debug ("%s:%s: Quit event", SRCNAME, __func__);
+          Mail::revert_all_mails();
+        }
       default:
         log_oom_extra ("%s:%s: Unhandled Event: %lx \n",
                        SRCNAME, __func__, dispid);

commit b8e39830594d87a41056e7d9dd8dff2ff4904aac
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 11:49:49 2016 +0200

    Fix revert for new attachment code
    
    * src/revert.cpp (gpgol_mailitem_revert): Delete all attachments
    not markes as MOSS.

diff --git a/src/revert.cpp b/src/revert.cpp
index 719fdfb..d33642b 100644
--- a/src/revert.cpp
+++ b/src/revert.cpp
@@ -372,17 +372,7 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
 
       if (get_pa_int (attachment, GPGOL_ATTACHTYPE_DASL, (int*) &att_type))
         {
-          if (!is_smime && msgtype != MSGTYPE_GPGOL_OPAQUE_SIGNED)
-            {
-              /* The Opaque signed attachment does not have a gpgol type
-                 for some reason. So we fake this here */
-              att_type = ATTACHTYPE_MOSSTEMPL;
-            }
-          else
-            {
-              log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
-              goto done;
-            }
+          att_type = ATTACHTYPE_FROMMOSS;
         }
 
       switch (att_type)
@@ -469,8 +459,7 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
               break;
             }
           default:
-            log_error ("%s:%s: Unknown attachment type: %i",
-                       SRCNAME, __func__, att_type);
+            to_delete[del_cnt++] = attachment;
         }
     }
 

commit a4cb385ee539570d6a5d67a9c7651173905be0c3
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 11:48:35 2016 +0200

    Save mail after revert_all_mails
    
    * src/mail.cpp (Mail::revert_all_mails): Save afterwards.
    (Mail::revert): Mark the the mail no longer needs wipe.

diff --git a/src/mail.cpp b/src/mail.cpp
index 84c39b5..572280b 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -780,6 +780,14 @@ Mail::revert_all_mails ()
         {
           log_error ("Failed to revert mail: %p ", it->first);
           err++;
+          continue;
+        }
+      it->second->set_needs_save (true);
+      if (!invoke_oom_method (it->first, "Save", NULL))
+        {
+          log_error ("Failed to save reverted mail: %p ", it->first);
+          err++;
+          continue;
         }
     }
   return err;
@@ -819,6 +827,7 @@ Mail::revert ()
     }
   /* We need to reprocess the mail next time around. */
   m_processed = false;
+  m_needs_wipe = false;
   return 0;
 }
 

commit 525680f952ed3f2e361c8582f5df3a12f07defb8
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Oct 20 11:47:18 2016 +0200

    Ensure parser thread handle is closed
    
    * src/mail.cpp (Mail::parsing_done): CloseHandle.
    (Mail::~Mail): Ditto.
    (Mail::decrypt_verify): Store handle.
    * src/mail.h: Add new member for Handle.

diff --git a/src/mail.cpp b/src/mail.cpp
index 1465836..84c39b5 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -95,7 +95,8 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_is_valid(false),
     m_moss_position(0),
     m_sender(NULL),
-    m_type(MSGTYPE_UNKNOWN)
+    m_type(MSGTYPE_UNKNOWN),
+    m_parser_thread(NULL)
 {
   if (get_mail_for_item (mailitem))
     {
@@ -141,6 +142,11 @@ Mail::~Mail()
 
   xfree (m_sender);
   gpgol_release(m_mailitem);
+
+  if (m_parser_thread)
+    {
+      CloseHandle (m_parser_thread);
+    }
 }
 
 Mail *
@@ -526,8 +532,15 @@ Mail::decrypt_verify()
   m_parser = new ParseController (cipherstream, m_type);
   gpgol_release (cipherstream);
 
-  CreateThread (NULL, 0, do_parsing, (LPVOID) this, 0,
-                NULL);
+  m_parser_thread = CreateThread (NULL, 0, do_parsing, (LPVOID) this, 0,
+                                  NULL);
+
+  if (!m_parser_thread)
+    {
+      log_error ("%s:%s: Failed to create decrypt / verify thread.",
+                 SRCNAME, __func__);
+    }
+
   return 0;
 }
 
@@ -600,6 +613,11 @@ Mail::parsing_done()
   m_parser = nullptr;
   gpgoladdin_invalidate_ui ();
   TRACEPOINT;
+  if (m_parser_thread)
+    {
+      CloseHandle (m_parser_thread);
+      m_parser_thread = NULL;
+    }
   return;
 }
 
diff --git a/src/mail.h b/src/mail.h
index 83c10ab..1b69e2a 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -267,5 +267,6 @@ private:
   GpgME::Signature m_sig;
   GpgME::UserID m_uid;
   std::string m_uuid;
+  HANDLE m_parser_thread;
 };
 #endif // MAIL_H

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

Summary of changes:
 src/application-events.cpp |  5 ++++
 src/mail.cpp               | 22 +++++++++++++---
 src/mailitem-events.cpp    | 64 +++++++++++++++++++++++++++++++++++++++++-----
 src/revert.cpp             | 15 ++---------
 src/windowmessages.cpp     | 41 +++++++++++++++++++++++++++++
 src/windowmessages.h       |  3 ++-
 6 files changed, 127 insertions(+), 23 deletions(-)


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




More information about the Gnupg-commits mailing list