[git] GpgOL - branch, mime-addin, updated. gpgol-1.2.0-23-g77c1e22

by Andre Heinecke cvs at cvs.gnupg.org
Thu Sep 17 11:20:53 CEST 2015


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, mime-addin has been updated
       via  77c1e2278577792dcd398cf56ea6c522b808eeb6 (commit)
       via  bee8da4c91363c6139000d70503f7e65cb7854d9 (commit)
       via  0fcbfd7907de44d81bc0136110a20f344588e2f1 (commit)
      from  cb6c248aed297d8240b152b8f49554c48a380ef7 (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 77c1e2278577792dcd398cf56ea6c522b808eeb6
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Sep 17 11:17:55 2015 +0200

    Show body of MIME messages
    
    * src/mailitem-events.cpp (MailItemEvents::handle_after_write),
      (MailItemEvents::handle_before_read): New. Moved out of Invoke.
      (MailItemEvents::handle_read): New. Set the body to the decrypted /
      verified content.
    
    --
    This should not yet be used. The body modification in the OOM
    causes the plaintext to be persistently stored.

diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 23dc256..04f77f8 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -25,10 +25,6 @@
 #include "oomhelp.h"
 #include "ocidl.h"
 
-/* Mail Item Events */
-BEGIN_EVENT_SINK(MailItemEvents, IDispatch)
-EVENT_SINK_DEFAULT_CTOR(MailItemEvents)
-EVENT_SINK_DEFAULT_DTOR(MailItemEvents)
 typedef enum
   {
     AfterWrite = 0xFC8D,
@@ -59,6 +55,121 @@ typedef enum
     Write = 0xF002
   } MailEvent;
 
+/* Mail Item Events */
+BEGIN_EVENT_SINK(MailItemEvents, IDispatch)
+/* We are still in the class declaration */
+
+private:
+  bool m_send_seen,   /* The message is about to be submitted */
+       m_want_html,    /* Encryption of HTML is desired. */
+       m_processed,    /* The message has been porcessed by us.  */
+       m_was_encrypted; /* The original message was encrypted.  */
+
+  HRESULT handle_before_read();
+  HRESULT handle_read();
+  HRESULT handle_after_write();
+};
+
+MailItemEvents::MailItemEvents() :
+    m_object(NULL),
+    m_pCP(NULL),
+    m_cookie(0),
+    m_ref(1),
+    m_send_seen(false),
+    m_want_html(false),
+    m_processed(false)
+{
+/* The event sink default dtor closes this for us. */
+EVENT_SINK_DEFAULT_DTOR(MailItemEvents)
+
+
+HRESULT
+MailItemEvents::handle_read()
+{
+  int err;
+  int is_html, was_protected = 0;
+  char *body = NULL;
+  LPMESSAGE message = get_oom_message (m_object);
+  if (!message)
+    {
+      log_error ("%s:%s: Failed to get message \n",
+                 SRCNAME, __func__);
+      return S_OK;
+    }
+  err = mapi_get_gpgol_body_attachment (message, &body, NULL,
+                                        &is_html, &was_protected);
+  message->Release ();
+  if (err || !body)
+    {
+      log_error ("%s:%s: Failed to get body attachment of \n",
+                 SRCNAME, __func__);
+      return S_OK;
+    }
+  if (put_oom_string (m_object, is_html ? "HTMLBody" : "Body", body))
+    {
+      log_error ("%s:%s: Failed to modify body of item. \n",
+                 SRCNAME, __func__);
+    }
+
+  xfree (body);
+
+  return S_OK;
+}
+
+/* Before read is the time where we can access the underlying
+   base message. So this is where we create our attachment. */
+HRESULT
+MailItemEvents::handle_before_read()
+{
+  int err;
+  LPMESSAGE message = get_oom_base_message (m_object);
+  if (!message)
+    {
+      log_error ("%s:%s: Failed to get base message.",
+                 SRCNAME, __func__);
+      return S_OK;
+    }
+  log_oom_extra ("%s:%s: GetBaseMessage OK.",
+                 SRCNAME, __func__);
+  err = message_incoming_handler (message, get_oom_context_window (m_object),
+                                  false);
+  m_processed = (err == 1) || (err == 2);
+  m_was_encrypted = err == 2;
+
+  log_debug ("%s:%s: incoming handler status: %i",
+             SRCNAME, __func__, err);
+  message->Release ();
+}
+
+HRESULT
+MailItemEvents::handle_after_write()
+{
+  int err;
+  LPMESSAGE message = get_oom_base_message (m_object);
+  if (!message)
+    {
+      log_error ("%s:%s: Failed to get base message.",
+                 SRCNAME, __func__);
+      return S_OK;
+    }
+  log_debug ("%s:%s: Sign / Encrypting message",
+             SRCNAME, __func__);
+  /* TODO check for message flags to determine */
+  err = message_sign_encrypt (message, PROTOCOL_UNKNOWN,
+                              get_oom_context_window (m_object));
+  log_debug ("%s:%s: Sign / Encryption status: %i",
+             SRCNAME, __func__, err);
+  message->Release ();
+  if (err)
+    {
+      // TODO: I think we can still cancel the send
+      // on the MAPI level in case of errors
+      // but we have to get at the messagestore to
+      // do that.
+    }
+  return S_OK;
+}
+
 EVENT_SINK_INVOKE(MailItemEvents)
 {
   USE_INVOKE_ARGS
@@ -66,47 +177,26 @@ EVENT_SINK_INVOKE(MailItemEvents)
     {
       case BeforeRead:
         {
-          LPMESSAGE message = get_oom_base_message (m_object);
-          if (message)
+          return handle_before_read();
+        }
+      case Read:
+        {
+          if (m_processed)
             {
-              int ret;
-              log_oom_extra ("%s:%s: GetBaseMessage OK.",
-                             SRCNAME, __func__);
-              ret = message_incoming_handler (message, NULL, false);
-              log_debug ("%s:%s: incoming handler status: %i",
-                         SRCNAME, __func__, ret);
-              message->Release ();
+              return handle_read();
             }
-          break;
+          return S_OK;
         }
-      case ReadComplete:
+      case Send:
         {
-          break;
+          m_send_seen = true;
+          return S_OK;
         }
       case AfterWrite:
         {
-          LPMESSAGE message = get_oom_base_message (m_object);
-          if (message)
-            {
-              int ret;
-              log_debug ("%s:%s: Sign / Encrypting message",
-                         SRCNAME, __func__);
-              ret = message_sign_encrypt (message, PROTOCOL_UNKNOWN, NULL);
-              log_debug ("%s:%s: Sign / Encryption status: %i",
-                         SRCNAME, __func__, ret);
-              message->Release ();
-              if (ret)
-                {
-                  // VARIANT_BOOL *cancel = parms->rgvarg[0].pboolVal;
-                  // *cancel = VARIANT_TRUE;
-                  /* TODO inform the user that sending was canceled */
-                }
-            }
-          else
+          if (m_send_seen)
             {
-              log_error ("%s:%s: Failed to get base message.",
-                         SRCNAME, __func__);
-              break;
+              return handle_after_write();
             }
         }
       default:

commit bee8da4c91363c6139000d70503f7e65cb7854d9
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Sep 17 11:13:39 2015 +0200

    Split get_oom_base message in two functions
    
    * src/oomhelp.cpp (get_oom_base_message_from_mapi): New.
      (get_oom_message): Obtain the Mapi message from a Mail item.
      (get_oom_base_message): Use both functions to do the same as
      before.
    * src/oomhelp.h: Update accordingly.
    
    --
    The conversion from MailItem to MAPI Message is useful
    in itself. E.g. in a normal read event.

diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index 08db412..0b1f144 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -1004,25 +1004,28 @@ get_object_by_id (LPDISPATCH pDisp, REFIID id)
 }
 
 LPMESSAGE
-get_oom_base_message (LPDISPATCH pDisp)
+get_oom_message (LPDISPATCH mailitem)
 {
-  HRESULT hr;
-  LPDISPATCH secureItem = NULL;
-  LPUNKNOWN mapiObject = NULL;
-  LPMESSAGE message = NULL;
-  LPMAPISECUREMESSAGE secureMessage = NULL;
-
-  mapiObject = get_oom_iunknown (pDisp, "MapiObject");
-  if (!mapiObject)
+  LPUNKNOWN mapi_obj = get_oom_iunknown (mailitem, "MapiObject");
+  if (!mapi_obj)
     {
-      log_error ("%s:%s: Failed to obtain MailItem.",
+      log_error ("%s:%s: Failed to obtain MAPI Message.",
                  SRCNAME, __func__);
       return NULL;
     }
+  return (LPMESSAGE) mapi_obj;
+}
 
-  secureItem = get_object_by_id ((LPDISPATCH) mapiObject,
+static LPMESSAGE
+get_oom_base_message_from_mapi (LPDISPATCH mapi_message)
+{
+  HRESULT hr;
+  LPDISPATCH secureItem = NULL;
+  LPMESSAGE message = NULL;
+  LPMAPISECUREMESSAGE secureMessage = NULL;
+
+  secureItem = get_object_by_id (mapi_message,
                                  IID_IMAPISecureMessage);
-  mapiObject->Release ();
   if (!secureItem)
     {
       log_error ("%s:%s: Failed to obtain SecureItem.",
@@ -1047,3 +1050,19 @@ get_oom_base_message (LPDISPATCH pDisp)
 
   return message;
 }
+
+LPMESSAGE
+get_oom_base_message (LPDISPATCH mailitem)
+{
+  LPMESSAGE mapi_message = get_oom_message (mailitem);
+  LPMESSAGE ret = NULL;
+  if (!mapi_message)
+    {
+      log_error ("%s:%s: Failed to obtain mapi_message.",
+                 SRCNAME, __func__);
+      return NULL;
+    }
+  ret = get_oom_base_message_from_mapi ((LPDISPATCH)mapi_message);
+  mapi_message->Release ();
+  return ret;
+}
diff --git a/src/oomhelp.h b/src/oomhelp.h
index 69df878..7c2f967 100644
--- a/src/oomhelp.h
+++ b/src/oomhelp.h
@@ -153,6 +153,14 @@ get_pa_string (LPDISPATCH pDisp, const char *property);
 LPDISPATCH
 get_object_by_id (LPDISPATCH pDisp, REFIID id);
 
+/* Obtain the MAPI Message corresponding to the
+   Mailitem. Returns NULL on error.
+
+   The returned Message needs to be released by the
+   caller */
+LPMESSAGE
+get_oom_message (LPDISPATCH mailitem);
+
 /* Obtain the Base MAPI Message of a MailItem.
    The parameter should be a pointer to a MailItem.
    returns NULL on error.
@@ -161,7 +169,7 @@ get_object_by_id (LPDISPATCH pDisp, REFIID id);
    caller.
 */
 LPMESSAGE
-get_oom_base_message (LPDISPATCH mailItem);
+get_oom_base_message (LPDISPATCH mailitem);
 
 #ifdef __cplusplus
 }

commit 0fcbfd7907de44d81bc0136110a20f344588e2f1
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Sep 16 17:40:19 2015 +0200

    Split event handling code in different files.
    
    One file per class is better.
    
    * src/application-events.cpp: New. For the Application.
    * src/mailitem-events.cpp: New. For MailItems.
    * src/Makefile.am: Update accordingly.
    
    --
    The event handlers will grow to do more and more handling.
    
    There is still one header because the event handlers are
    basically private and only declare an install function.

diff --git a/src/Makefile.am b/src/Makefile.am
index b7c4046..c983dcc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,7 +89,8 @@ gpgol_SOURCES = \
 	ribbon-callbacks.cpp ribbon-callbacks.h \
 	parsetlv.c parsetlv.h \
 	filetype.c filetype.h \
-	eventsinks.h eventsinks.cpp
+	eventsinks.h application-events.cpp \
+	mailitem-events.cpp
 
 
 #treeview_SOURCES = treeview.c
diff --git a/src/eventsinks.cpp b/src/application-events.cpp
similarity index 56%
copy from src/eventsinks.cpp
copy to src/application-events.cpp
index de91206..b2fbc3b 100644
--- a/src/eventsinks.cpp
+++ b/src/application-events.cpp
@@ -1,4 +1,4 @@
-/* eventsinks.cpp - Event handling classes.
+/* application-events.cpp - Event handling for the application.
  *    Copyright (C) 2015 Intevation GmbH
  *
  * This file is part of GpgOL.
@@ -27,8 +27,6 @@
 #include "ocidl.h"
 #include "common.h"
 #include "oomhelp.h"
-#include "mymapi.h"
-#include "message.h"
 
 /* Application Events */
 BEGIN_EVENT_SINK(ApplicationEvents, IDispatch)
@@ -105,95 +103,3 @@ EVENT_SINK_INVOKE(ApplicationEvents)
   return S_OK;
 }
 END_EVENT_SINK(ApplicationEvents, IID_ApplicationEvents)
-
-/* Mail Item Events */
-BEGIN_EVENT_SINK(MailItemEvents, IDispatch)
-EVENT_SINK_DEFAULT_CTOR(MailItemEvents)
-EVENT_SINK_DEFAULT_DTOR(MailItemEvents)
-typedef enum
-  {
-    AfterWrite = 0xFC8D,
-    AttachmentAdd = 0xF00B,
-    AttachmentRead = 0xF00C,
-    AttachmentRemove = 0xFBAE,
-    BeforeAttachmentAdd = 0xFBB0,
-    BeforeAttachmentPreview = 0xFBAF,
-    BeforeAttachmentRead = 0xFBAB,
-    BeforeAttachmentSave = 0xF00D,
-    BeforeAttachmentWriteToTempFile = 0xFBB2,
-    BeforeAutoSave = 0xFC02,
-    BeforeCheckNames = 0xF00A,
-    BeforeDelete = 0xFA75,
-    BeforeRead = 0xFC8C,
-    Close = 0xF004,
-    CustomAction = 0xF006,
-    CustomPropertyChange = 0xF008,
-    Forward = 0xF468,
-    Open = 0xF003,
-    PropertyChange = 0xF009,
-    Read = 0xF001,
-    ReadComplete = 0xFC8F,
-    Reply = 0xFC8F,
-    ReplyAll = 0xF467,
-    Send = 0xF005,
-    Unload = 0xFBAD,
-    Write = 0xF002
-  } MailEvent;
-
-EVENT_SINK_INVOKE(MailItemEvents)
-{
-  USE_INVOKE_ARGS
-  switch(dispid)
-    {
-      case BeforeRead:
-        {
-          LPMESSAGE message = get_oom_base_message (m_object);
-          if (message)
-            {
-              int ret;
-              log_oom_extra ("%s:%s: GetBaseMessage OK.",
-                             SRCNAME, __func__);
-              ret = message_incoming_handler (message, NULL, false);
-              log_debug ("%s:%s: incoming handler status: %i",
-                         SRCNAME, __func__, ret);
-              message->Release ();
-            }
-          break;
-        }
-      case ReadComplete:
-        {
-          break;
-        }
-      case AfterWrite:
-        {
-          LPMESSAGE message = get_oom_base_message (m_object);
-          if (message)
-            {
-              int ret;
-              log_debug ("%s:%s: Sign / Encrypting message",
-                         SRCNAME, __func__);
-              ret = message_sign_encrypt (message, PROTOCOL_UNKNOWN, NULL);
-              log_debug ("%s:%s: Sign / Encryption status: %i",
-                         SRCNAME, __func__, ret);
-              message->Release ();
-              if (ret)
-                {
-                  // VARIANT_BOOL *cancel = parms->rgvarg[0].pboolVal;
-                  // *cancel = VARIANT_TRUE;
-                  /* TODO inform the user that sending was canceled */
-                }
-            }
-          else
-            {
-              log_error ("%s:%s: Failed to get base message.",
-                         SRCNAME, __func__);
-              break;
-            }
-        }
-      default:
-        log_debug ("%s:%s: Unhandled Event: %lx \n",
-                       SRCNAME, __func__, dispid);
-    }
-  return S_OK;
-}
-END_EVENT_SINK(MailItemEvents, IID_MailItemEvents)
diff --git a/src/eventsinks.cpp b/src/mailitem-events.cpp
similarity index 56%
rename from src/eventsinks.cpp
rename to src/mailitem-events.cpp
index de91206..23dc256 100644
--- a/src/eventsinks.cpp
+++ b/src/mailitem-events.cpp
@@ -1,4 +1,4 @@
-/* eventsinks.cpp - Event handling classes.
+/* mailitem-events.h - Event handling for mails.
  *    Copyright (C) 2015 Intevation GmbH
  *
  * This file is part of GpgOL.
@@ -17,94 +17,13 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-/* The event handler classes defined in this file follow the
-   general pattern that they implment the IDispatch interface
-   through the eventsink macros and handle event invocations
-   in their invoke methods.
-*/
+#include "common.h"
 #include "eventsink.h"
 #include "eventsinks.h"
-#include "ocidl.h"
-#include "common.h"
-#include "oomhelp.h"
 #include "mymapi.h"
 #include "message.h"
-
-/* Application Events */
-BEGIN_EVENT_SINK(ApplicationEvents, IDispatch)
-EVENT_SINK_DEFAULT_CTOR(ApplicationEvents)
-EVENT_SINK_DEFAULT_DTOR(ApplicationEvents)
-typedef enum
-  {
-    AdvancedSearchComplete = 0xFA6A,
-    AdvancedSearchStopped = 0xFA6B,
-    AttachmentContextMenuDisplay = 0xFB3E,
-    BeforeFolderSharingDialog = 0xFC01,
-    ContextMenuClose = 0xFBA6,
-    FolderContextMenuDisplay = 0xFB42,
-    ItemContextMenuDisplay = 0xFB41,
-    ItemLoad = 0xFBA7,
-    ItemSend = 0xF002,
-    MAPILogonComplete = 0xFA90,
-    NewMail = 0xF003,
-    NewMailEx = 0xFAB5,
-    OptionsPagesAdd = 0xF005,
-    Quit = 0xF007,
-    Reminder = 0xF004,
-    ShortcutContextMenuDisplay = 0xFB44,
-    Startup = 0xF006,
-    StoreContextMenuDisplay = 0xFB43,
-    ViewContextMenuDisplay = 0xFB40
-  } ApplicationEvent;
-
-EVENT_SINK_INVOKE(ApplicationEvents)
-{
-  USE_INVOKE_ARGS
-  switch(dispid)
-    {
-      case ItemLoad:
-        {
-          LPDISPATCH mailItem;
-          LPDISPATCH mailEventSink;
-          /* The mailItem should be the first argument */
-          if (parms->cArgs != 1 || parms->rgvarg[0].vt != VT_DISPATCH)
-            {
-              log_error ("%s:%s: ItemLoad with unexpected Arguments.",
-                         SRCNAME, __func__);
-              break;
-            }
-
-          mailItem = get_object_by_id (parms->rgvarg[0].pdispVal,
-                                       IID_MailItem);
-          if (!mailItem)
-            {
-              log_error ("%s:%s: ItemLoad event without mailitem.",
-                         SRCNAME, __func__);
-              break;
-            }
-          mailEventSink = install_MailItemEvents_sink (mailItem);
-          /* TODO figure out what we need to do with the event sink.
-             Does it need to be Released at some point? What happens
-             on unload? */
-          if (!mailEventSink)
-            {
-              log_error ("%s:%s: Failed to install MailItemEvents sink.",
-                         SRCNAME, __func__);
-            }
-          mailItem->Release ();
-          break;
-        }
-      default:
-        log_oom_extra ("%s:%s: Unhandled Event: %lx \n",
-                       SRCNAME, __func__, dispid);
-    }
-  /* We always return S_OK even on error so that outlook
-     continues to handle the event and is not disturbed
-     by our errors. There shouldn't be errors in here
-     anyway if everything works as documented. */
-  return S_OK;
-}
-END_EVENT_SINK(ApplicationEvents, IID_ApplicationEvents)
+#include "oomhelp.h"
+#include "ocidl.h"
 
 /* Mail Item Events */
 BEGIN_EVENT_SINK(MailItemEvents, IDispatch)

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

Summary of changes:
 src/Makefile.am                                |   3 +-
 src/{eventsinks.cpp => application-events.cpp} |  96 +-----------
 src/mailitem-events.cpp                        | 208 +++++++++++++++++++++++++
 src/oomhelp.cpp                                |  43 +++--
 src/oomhelp.h                                  |  10 +-
 5 files changed, 251 insertions(+), 109 deletions(-)
 rename src/{eventsinks.cpp => application-events.cpp} (56%)
 create mode 100644 src/mailitem-events.cpp


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




More information about the Gnupg-commits mailing list