[svn] GpgOL - r315 - in trunk: . forms po src

svn author wk cvs at cvs.gnupg.org
Tue Nov 3 13:01:24 CET 2009


Author: wk
Date: 2009-11-03 13:01:24 +0100 (Tue, 03 Nov 2009)
New Revision: 315

Added:
   trunk/forms/gpgol-cs_en.cfg
   trunk/forms/gpgol-ms_en.cfg
   trunk/forms/gpgol_en.cfg
   trunk/src/mailitem.cpp
   trunk/src/mailitem.h
Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/TODO
   trunk/forms/Makefile.am
   trunk/po/de.po
   trunk/po/sv.po
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/cmdbarcontrols.h
   trunk/src/common.h
   trunk/src/display.cpp
   trunk/src/display.h
   trunk/src/ext-commands.cpp
   trunk/src/inspectors.cpp
   trunk/src/inspectors.h
   trunk/src/item-events.cpp
   trunk/src/main.c
   trunk/src/message-events.cpp
   trunk/src/message.cpp
   trunk/src/message.h
   trunk/src/myexchext.h
   trunk/src/olflange.cpp
   trunk/src/oomhelp.cpp
   trunk/src/oomhelp.h
   trunk/src/revert.cpp
Log:
The new icon code is ready.  However the whiole module needs a lot
more testing because I rewrote a lot of code.


[The diff below has been truncated]

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/ChangeLog	2009-11-03 12:01:24 UTC (rev 315)
@@ -1,3 +1,7 @@
+2009-11-02  Werner Koch  <wk at g10code.com>
+
+	* forms/Makefile.am (cfg_english): New.
+
 2009-10-30  Werner Koch  <wk at g10code.com>
 
 	* forms/Makefile.am (icons): Udpate all icons.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/ChangeLog	2009-11-03 12:01:24 UTC (rev 315)
@@ -1,3 +1,27 @@
+2009-11-03  Werner Koch  <wk at g10code.com>
+
+	* inspectors.cpp (deregister_inspector): Delete the buttons.
+	(set_one_button): New.
+	(set_inspector_composer_flags): Also set toolbar buttons.
+	* oomhelp.cpp (del_oom_button): New.
+
+2009-11-02  Werner Koch  <wk at g10code.com>
+
+	* mailitem.cpp, mailitem.h: New.
+
+	* inspectors.cpp (get_message_from_button): New.
+	(get_inspector_from_instid): New.
+	(proc_inspector_button_click): Implement missing commands.
+
+	* message.cpp (message_display_handler): Change to take an
+	LPMESSAGE argument.
+	* display.cpp (update_display): Replace the eecb arg by an
+	inspector object.
+	* message-events.cpp (OnReadComplete): Adjust for changes.
+
+	* oomhelp.cpp (get_oom_iunknown): New.
+	* revert.cpp (gpgol_folder_revert): Change to work without an eecb.
+
 2009-10-30  Werner Koch  <wk at g10code.com>
 
 	* oomhelp.cpp (get_oom_control_bytag): Fix silly bug.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/NEWS	2009-11-03 12:01:24 UTC (rev 315)
@@ -1,7 +1,7 @@
 Noteworthy changes for version 1.1.0
 ===================================================
 
- * Replaced some ECF code by direct OOM code.  This was required to
+ * Replaced most ECE code by direct OOM code.  This was required to
    support better icons; i.e. icons not limited to a 16 color palette.
 
  * New icons.

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/TODO	2009-11-03 12:01:24 UTC (rev 315)
@@ -15,5 +15,3 @@
   presented file names and decrypt them only on OpenSzFile.  Need to
   find some documentation first.
 
-* We need to use the micalg as returned by the UI-server.
-

Modified: trunk/forms/Makefile.am
===================================================================
--- trunk/forms/Makefile.am	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/forms/Makefile.am	2009-11-03 12:01:24 UTC (rev 315)
@@ -13,9 +13,11 @@
 
 icons = encr-l.ico encr-s.ico sign-l.ico sign-s.ico
 
-cfg_german = gpgol_de.cfg gpgol-ms_de.cfg gpgol-cs_de.cfg 
+cfg_german  = gpgol_de.cfg gpgol-ms_de.cfg gpgol-cs_de.cfg 
+cfg_english = gpgol_en.cfg gpgol-ms_en.cfg gpgol-cs_en.cfg 
 
-dist_pkgdata_DATA = $(icons) $(cfg_german)
+dist_pkgdata_DATA = $(icons) $(cfg_german) $(cfg_english)
 
 
 
+

Added: trunk/forms/gpgol-cs_en.cfg
===================================================================
--- trunk/forms/gpgol-cs_en.cfg	                        (rev 0)
+++ trunk/forms/gpgol-cs_en.cfg	2009-11-03 12:01:24 UTC (rev 315)
@@ -0,0 +1,35 @@
+[Description]
+MessageClass=IPM.Note.GpgOL.ClearSigned
+DesignerRuntimeGuid={0006F020-0000-0000-C000-000000000046}
+CLSID={00061033-0000-0000-C000-000000000046}
+DisplayName=Form for class IPM.Note.GpgOL.MultipartSigned
+Category=Standard
+Subcategory=Formular
+Comment=
+LargeIcon=sign-l.ico
+SmallIcon=sign-s.ico
+VersionMajor=1
+VersionMinor=0
+Locale=eng
+Hidden=1
+Owner=Public Domain
+
+[Properties]
+
+[Verbs]
+Verb1=1
+
+[Verb.1]
+DisplayName=&Open
+Code=0
+Flags=0
+Attribs=2
+
+[Extensions]
+Extensions1=1
+
+[Extension.1]
+Type=30
+NmidPropset={00020D0C-0000-0000-C000-000000000046}
+NmidInteger=1
+Value=1011111111111111

Added: trunk/forms/gpgol-ms_en.cfg
===================================================================
--- trunk/forms/gpgol-ms_en.cfg	                        (rev 0)
+++ trunk/forms/gpgol-ms_en.cfg	2009-11-03 12:01:24 UTC (rev 315)
@@ -0,0 +1,35 @@
+[Description]
+MessageClass=IPM.Note.GpgOL.MultipartSigned
+DesignerRuntimeGuid={0006F020-0000-0000-C000-000000000046}
+CLSID={00061033-0000-0000-C000-000000000046}
+DisplayName=Form for class IPM.Note.GpgOL.MultipartSigned
+Category=Standard
+Subcategory=Formular
+Comment=
+LargeIcon=sign-l.ico
+SmallIcon=sign-s.ico
+VersionMajor=1
+VersionMinor=0
+Locale=eng
+Hidden=1
+Owner=Public Domain
+
+[Properties]
+
+[Verbs]
+Verb1=1
+
+[Verb.1]
+DisplayName=&Open
+Code=0
+Flags=0
+Attribs=2
+
+[Extensions]
+Extensions1=1
+
+[Extension.1]
+Type=30
+NmidPropset={00020D0C-0000-0000-C000-000000000046}
+NmidInteger=1
+Value=1011111111111111

Added: trunk/forms/gpgol_en.cfg
===================================================================
--- trunk/forms/gpgol_en.cfg	                        (rev 0)
+++ trunk/forms/gpgol_en.cfg	2009-11-03 12:01:24 UTC (rev 315)
@@ -0,0 +1,36 @@
+[Description]
+MessageClass=IPM.Note.GpgOL
+DesignerRuntimeGuid={0006F020-0000-0000-C000-000000000046}
+CLSID={00061033-0000-0000-C000-000000000046}
+DisplayName=Form for class IPM.Note.GpgOL
+Category=Standard
+Subcategory=Formular
+Comment=
+LargeIcon=encr-l.ico
+SmallIcon=encr-s.ico
+VersionMajor=1
+VersionMinor=0
+Locale=eng
+Hidden=1
+Owner=Public Domain
+
+[Properties]
+
+[Verbs]
+Verb1=1
+
+[Verb.1]
+DisplayName=&Open
+Code=0
+Flags=0
+Attribs=2
+
+[Extensions]
+Extensions1=1
+
+[Extension.1]
+Type=30
+NmidPropset={00020D0C-0000-0000-C000-000000000046}
+NmidInteger=1
+Value=1011111111111111
+

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/sv.po  [not shown]
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/Makefile.am	2009-11-03 12:01:24 UTC (rev 315)
@@ -71,6 +71,7 @@
 	oomhelp.cpp oomhelp.h eventsink.h \
 	explorers.cpp explorers.h \
 	inspectors.cpp inspectors.h \
+	mailitem.cpp mailitem.h \
 	cmdbarcontrols.cpp cmdbarcontrols.h \
 	w32-gettext.c w32-gettext.h 
 

Modified: trunk/src/cmdbarcontrols.h
===================================================================
--- trunk/src/cmdbarcontrols.h	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/cmdbarcontrols.h	2009-11-03 12:01:24 UTC (rev 315)
@@ -31,7 +31,10 @@
 struct IOOMCommandBarButton;
 typedef IOOMCommandBarButton *LPOOMCOMMANDBARBUTTON;
 
+struct GpgolCommandBarButtonEvents;
+typedef GpgolCommandBarButtonEvents *LPGPGOLCOMMANDBARBUTTONEVENTS;
 
+
 EXTERN_C const IID IID_IOOMCommandBarButtonEvents;
 #undef INTERFACE
 #define INTERFACE  IOOMCommandBarButtonEvents
@@ -57,6 +60,7 @@
 
 
 LPDISPATCH install_GpgolCommandBarButtonEvents_sink (LPDISPATCH button);
+void       detach_GpgolCommandBarButtonEvents_sink (LPDISPATCH sink);
 
 
 

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/common.h	2009-11-03 12:01:24 UTC (rev 315)
@@ -169,6 +169,7 @@
 #define DBG_COMMANDS       (1<<6)
 #define DBG_MIME_PARSER    (1<<7)
 #define DBG_MIME_DATA      (1<<8)
+#define DBG_OOM            (1<<9)
 
 /* Macros to used in conditionals to enable debug output.  */
 #define debug_commands    (opt.enable_debug & DBG_COMMANDS)

Modified: trunk/src/display.cpp
===================================================================
--- trunk/src/display.cpp	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/display.cpp	2009-11-03 12:01:24 UTC (rev 315)
@@ -215,7 +215,7 @@
 /* Update the display with TEXT using the message MSG.  Return 0 on
    success. */
 int
-update_display (HWND hwnd, void *exchange_cb, int is_sensitive,
+update_display (HWND hwnd, LPDISPATCH inspector, int is_sensitive,
                 bool is_html, const char *text)
 {
   HWND window;
@@ -245,28 +245,27 @@
         SetWindowTextA (window, text);
       return 0;
     }
-  else if (exchange_cb && !opt.compat.no_oom_write)
+  else if (inspector && !opt.compat.no_oom_write)
     {
-      LPDISPATCH obj;
       int rc;
+      LPDISPATCH item;
 
       log_debug ("%s:%s: updating display using OOM\n", SRCNAME, __func__);
       
-      obj = get_eecb_object ((LPEXCHEXTCALLBACK)exchange_cb);
-      if (!obj)
+      item = get_oom_object (inspector, "get_CurrentItem");
+      if (item)
         {
-          log_error ("%s:%s: Object not found via EECB\n", SRCNAME, __func__);
-          return -1;
+          if (is_html)
+            {
+              /* Bug in OL 2002 and 2003 - as a workaround set the body
+                 first to empty. */
+              put_oom_string (item, "Body", "");
+            }
+          rc = put_oom_string (item, is_html? "HTMLBody":"Body", text);
+          item->Release ();
         }
-
-      if (is_html)
-        {
-          /* Bug in OL 2002 and 2003 - as a workaround set the body
-             first to empty. */
-          put_oom_string (obj, "Body", "");
-        }
-      rc = put_oom_string (obj, is_html? "HTMLBody":"Body", text);
-      obj->Release ();
+      else
+        rc = -1;
       return rc;
     }
   else

Modified: trunk/src/display.h
===================================================================
--- trunk/src/display.h	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/display.h	2009-11-03 12:01:24 UTC (rev 315)
@@ -25,7 +25,7 @@
 char *add_html_line_endings (const char *body);
 
 int is_inspector_display (HWND hwnd);
-int update_display (HWND hwnd, void *exchange_cb, int is_sensitive,
+int update_display (HWND hwnd, LPDISPATCH inspector, int is_sensitive,
                     bool is_html, const char *text);
 
 int set_message_body (LPMESSAGE message, const char *string, bool is_html);

Modified: trunk/src/ext-commands.cpp
===================================================================
--- trunk/src/ext-commands.cpp	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/ext-commands.cpp	2009-11-03 12:01:24 UTC (rev 315)
@@ -37,7 +37,6 @@
 #include "olflange.h"
 #include "message.h"
 #include "engine.h"
-#include "revert.h"
 #include "ext-commands.h"
 #include "explorers.h"
 #include "inspectors.h"
@@ -283,8 +282,7 @@
           if (force_encrypt)
             encrypt = true;
           
-          /* FIXME:  ove that to the inspector activation.  */
-          //set_crypto_flags (eecb, sign, encrypt);
+          set_crypto_flags (eecb, sign, encrypt);
         }
       xfree (draft_info);
     }

Modified: trunk/src/inspectors.cpp
===================================================================
--- trunk/src/inspectors.cpp	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/inspectors.cpp	2009-11-03 12:01:24 UTC (rev 315)
@@ -27,11 +27,14 @@
 #include "common.h"
 #include "oomhelp.h"
 #include "myexchext.h"
-#include "inspectors.h"
+#include "mapihelp.h"
+#include "message.h"
 #include "dialogs.h"  /* IDB_xxx */
 #include "cmdbarcontrols.h"
-
 #include "eventsink.h"
+#include "inspectors.h"
+#include "mailitem.h"
+#include "revert.h"
 
 
 /* Event sink for an Inspectors collection object.  */
@@ -72,7 +75,6 @@
   STDMETHOD_ (void, Close) (THIS_);
   STDMETHOD_ (void, Deactivate) (THIS_);
   bool m_first_activate_seen;
-  unsigned long m_serialno;
 EVENT_SINK_CTOR(GpgolInspectorEvents)
 {
   m_first_activate_seen = false;
@@ -109,7 +111,6 @@
 struct button_list_s
 {
   struct button_list_s *next;
-  unsigned long serialno; /* of the inspector.  */
   LPDISPATCH sink;
   LPDISPATCH button;
   int instid;
@@ -126,16 +127,13 @@
   /* We are pretty lame and keep all inspectors in a linked list.  */
   struct inspector_info_s *next;
 
+  /* The event sink object.  This is used by the event methods to
+     locate the inspector object.  */
+  LPGPGOLINSPECTOREVENTS eventsink;
+
   /* The inspector object.  */
   LPOOMINSPECTOR inspector;
 
-  /* Our serial number for the inspector.  */
-  unsigned long serialno;
-
-  /* The event sink object.  This is used by the event methods to
-     locate the inspector object.  */
-  LPOOMINSPECTOREVENTS eventsink;
-
   /* A list of all the buttons.  */
   button_list_t buttons;
 
@@ -147,9 +145,8 @@
 static HANDLE all_inspectors_lock;
 
 
-static void add_inspector_controls (LPOOMINSPECTOR inspector, 
-                                    unsigned long serialno);
-static void update_crypto_info (LPDISPATCH button);
+static void add_inspector_controls (LPOOMINSPECTOR inspector);
+static void update_crypto_info (LPDISPATCH inspector);
 
 
 
@@ -197,30 +194,13 @@
 }
 
 
-/* Return a new serial number for an inspector.  These serial numbers
-   are used to make the button tags unique.  */
-static unsigned long
-create_inspector_serial (void)
-{
-  static long serial;
-  long n;
-
-  /* Avoid returning 0 because we use that value as Nil.  */
-  while (!(n = InterlockedIncrement (&serial)))
-    ;
-  return (unsigned long)n;
-}
-
-
 /* Add SINK and BUTTON to the list at LISTADDR.  The list takes
    ownership of SINK and BUTTON, thus the caller may not use OBJ or
-   OBJ2 after this call.  If TAG must be given without the
-   serialnumber suffix.  SERIALNO is the serialno of the correspnding
-   inspector.  */
+   OBJ2 after this call.  TAG must be given without the '#' marked
+   suffix.  */
 static void
 move_to_button_list (button_list_t *listaddr, 
-                     LPDISPATCH sink, LPDISPATCH button, 
-                     const char *tag, unsigned long serialno)
+                     LPDISPATCH sink, LPDISPATCH button, const char *tag)
 {
   button_list_t item;
   int instid;
@@ -237,28 +217,29 @@
   item->sink = sink;
   item->button = button;
   item->instid = instid;
-  item->serialno = serialno;
   strcpy (item->tag, tag);
   item->next = *listaddr;
   *listaddr = item;
 }
 
 
-/* Register the inspector object INSPECTOR along with its event SINK.  */
+/* Register the inspector object INSPECTOR with its event SINK.  */
 static void
-register_inspector (LPOOMINSPECTOR inspector, LPGPGOLINSPECTOREVENTS sink)
+register_inspector (LPGPGOLINSPECTOREVENTS sink, LPOOMINSPECTOR inspector)
 {
   inspector_info_t item;
 
+  log_debug ("%s:%s: Called (sink=%p, inspector=%p)",
+             SRCNAME, __func__, sink, inspector);
   item = (inspector_info_t)xcalloc (1, sizeof *item);
   lock_all_inspectors ();
-  inspector->AddRef ();
-  item->inspector = inspector;
-  item->serialno = sink->m_serialno = create_inspector_serial ();
 
   sink->AddRef ();
   item->eventsink = sink;
 
+  inspector->AddRef ();
+  item->inspector = inspector;
+
   item->next = all_inspectors;
   all_inspectors = item;
 
@@ -268,11 +249,13 @@
 
 /* Deregister the inspector with the event SINK.  */
 static void
-deregister_inspector (LPOOMINSPECTOREVENTS sink)
+deregister_inspector (LPGPGOLINSPECTOREVENTS sink)
 {
   inspector_info_t r, rprev;
   button_list_t ol, ol2;
 
+  log_debug ("%s:%s: Called (sink=%p)", SRCNAME, __func__, sink);
+
   if (!sink)
     return;
 
@@ -293,21 +276,28 @@
       log_error ("%s:%s: inspector not registered", SRCNAME, __func__);
       return;
     }
-  r->eventsink->Release ();
-  r->eventsink = NULL;
-  if (r->inspector)
-    r->inspector->Release ();
 
+  detach_GpgolInspectorEvents_sink (r->eventsink);
+
   for (ol = r->buttons; ol; ol = ol2)
     {
       ol2 = ol->next;
       if (ol->sink)
-        ol->sink->Release ();
+        {
+          detach_GpgolCommandBarButtonEvents_sink (ol->sink);
+          ol->sink->Release ();
+        }
       if (ol->button)
-        ol->button->Release ();
+        {
+          del_oom_button (ol->button);
+          ol->button->Release ();
+        }
       xfree (ol);
     }
 
+  r->inspector->Release ();
+  r->eventsink->Release ();
+
   xfree (r);
 }
 
@@ -333,39 +323,40 @@
 }
 
 
-/* Return the serialno of INSPECTOR or 0 if not found.  */
-static unsigned long
-get_serialno (LPDISPATCH inspector)
+/* Return the button with TAG and assigned to INSPECTOR.  TAG must be
+   given without the suffix.  Returns NULL if not found.  */
+static LPDISPATCH
+get_button (LPDISPATCH inspector, const char *tag)
 {
-  unsigned int result = 0;
+  LPDISPATCH result = NULL;
   inspector_info_t iinfo;
+  button_list_t ol;
 
-  /* FIXME: This might not bet reliable.  We merely compare the
-     pointer and not something like an Instance Id.  We should check
-     whether this is sufficient or whether to track the inspectors
-     with different hack.  For example we could add an invisible menu
-     entry and scan for that entry to get the serial number serial
-     number of it.  A better option would be to add a custom property
-     to the inspector, but that seems not supported - we could of
-     course add it to a button then. */ 
   lock_all_inspectors ();
 
   for (iinfo = all_inspectors; iinfo; iinfo = iinfo->next)
     if (iinfo->inspector == inspector)
       {
-        result = iinfo->serialno;
+        for (ol = iinfo->buttons; ol; ol = ol->next)
+          if (ol->tag && !strcmp (ol->tag, tag))
+            {
+              result = ol->button;
+              if (result)
+                result->AddRef ();
+              break;
+            }
         break;
       }
-
+  
   unlock_all_inspectors ();
   return result;
 }
 
 
-/* Return the button with TAG and assigned to the isnpector with
-   SERIALNO.  Return NULL if not found.  */
+/* Search through all objects and find the inspector which has a
+   button with the instance id INSTID.  Returns NULL if not found.  */
 static LPDISPATCH
-get_button (unsigned long serialno, const char *tag)
+get_inspector_from_instid (int instid)
 {
   LPDISPATCH result = NULL;
   inspector_info_t iinfo;
@@ -374,18 +365,14 @@
   lock_all_inspectors ();
 
   for (iinfo = all_inspectors; iinfo; iinfo = iinfo->next)
-    if (iinfo->serialno == serialno)
-      {
-        for (ol = iinfo->buttons; ol; ol = ol->next)
-          if (ol->tag && !strcmp (ol->tag, tag))
-            {
-              result = ol->button;
-              if (result)
-                result->AddRef ();
-              break;
-            }
-        break;
-      }
+    for (ol = iinfo->buttons; ol; ol = ol->next)
+      if (ol->instid == instid)
+        {
+          result = iinfo->inspector;
+          if (result)
+            result->AddRef ();
+          break;
+        }
   
   unlock_all_inspectors ();
   return result;
@@ -393,9 +380,8 @@
 
 
 /* Search through all objects and find the inspector which has a
-   button with the instanceId INSTID.  The find the button with TAG in
-   that inspector and return it.  Caller must release the returned
-   button.  Returns NULL if not found.  */
+   button with the instanceId INSTID.  Theb find the button with TAG
+   in that inspector and return it.  Returns NULL if not found.  */
 static LPDISPATCH
 get_button_by_instid_and_tag (int instid, const char *tag)
 {
@@ -428,8 +414,6 @@
 }
 
 
-
-
 /* The method called by outlook for each new inspector.  Note that
    Outlook sometimes reuses Inspectro objects thus this event is not
    an indication for a newly opened Inspector.  */
@@ -437,16 +421,19 @@
 GpgolInspectorsEvents::NewInspector (LPOOMINSPECTOR inspector)
 {
   LPDISPATCH obj;
-  log_debug ("%s:%s: Called", SRCNAME, __func__);
 
+  log_debug ("%s:%s: Called (this=%p, inspector=%p)",
+             SRCNAME, __func__, this, inspector);
+
   /* It has been said that INSPECTOR here a "weak" reference. This may
      mean that the object has not been fully initialized.  So better
      take some care here and also take an additional reference.  */
+
   inspector->AddRef ();
   obj = install_GpgolInspectorEvents_sink ((LPDISPATCH)inspector);
   if (obj)
     {
-      register_inspector (inspector, (LPGPGOLINSPECTOREVENTS)obj);
+      register_inspector ((LPGPGOLINSPECTOREVENTS)obj, inspector);
       obj->Release ();
     }
   inspector->Release ();
@@ -458,10 +445,12 @@
 STDMETHODIMP_(void)
 GpgolInspectorEvents::Close (void)
 {
-  log_debug ("%s:%s: Called", SRCNAME, __func__);
-  /* Deregister the inspector and free outself.  */
+  log_debug ("%s:%s: Called (this=%p)", SRCNAME, __func__, this );
+
+  /* Deregister the inspector.  */
   deregister_inspector (this);
-  this->Release ();
+  /* We don't release ourself because we already dropped the initial
+     reference after doing a register_inspector.  */
 }
 
 
@@ -469,11 +458,11 @@
 STDMETHODIMP_(void)
 GpgolInspectorEvents::Activate (void)
 {
-  LPDISPATCH obj, button;
   LPOOMINSPECTOR inspector;
+  // LPDISPATCH obj, obj2;
 
-  log_debug ("%s:%s: Called", SRCNAME, __func__);
-
+  log_debug ("%s:%s: Called (this=%p)", SRCNAME, __func__, this);
+  
   /* Note: It is easier to use the registered inspector object than to
      find the inspector object in the ALL_INSPECTORS list.  The
      ALL_INSPECTORS list primarly useful to keep track of additional
@@ -484,6 +473,7 @@
       return;
     }
   inspector = (LPOOMINSPECTOR)m_object;
+  inspector->AddRef ();
 
   /* If this is the first activate for the inspector, we add the
      controls.  We do it only now to be sure that everything has been
@@ -492,23 +482,19 @@
   if (!m_first_activate_seen)
     {
       m_first_activate_seen = true;
-      add_inspector_controls (inspector, m_serialno);
+      add_inspector_controls (inspector);
+      // obj = get_oom_object (inspector, "get_CurrentItem");
+      // if (obj)
+      //   {
+      //     obj2 = install_GpgolItemEvents_sink (obj);
+      //     if (obj2)
+      //       obj2->Release ();
+      //     obj->Release ();
+      //   }
     }
   
-  /* Update the crypt info.  */
-  obj = get_oom_object (inspector, "CommandBars");
-  if (!obj)
-    log_error ("%s:%s: CommandBars not found", SRCNAME, __func__);
-  else
-    {
-      button = get_button (m_serialno, "GpgOL_Inspector_Crypto_Info");
-      obj->Release ();
-      if (button)
-        {
-          update_crypto_info (button);
-          button->Release ();
-        }
-    }
+  update_crypto_info (inspector);
+  inspector->Release ();
 }
 
 
@@ -516,7 +502,7 @@
 STDMETHODIMP_(void)
 GpgolInspectorEvents::Deactivate (void)
 {
-  log_debug ("%s:%s: Called", SRCNAME, __func__);
+  log_debug ("%s:%s: Called (this=%p)", SRCNAME, __func__, this);
 
 }
 
@@ -551,16 +537,8 @@
 {
   LPDISPATCH button;
   int rc = 0;
-  unsigned long serialno;
 
-  serialno = get_serialno (inspector);
-  if (!serialno)
-    {
-      log_error ("%s:%s: S/n not found", SRCNAME, __func__);
-      return -1;
-    }
-
-  button = get_button (serialno, "GpgOL_Inspector_Sign");
+  button = get_button (inspector, "GpgOL_Inspector_Sign");
   if (!button)
     {
       log_error ("%s:%s: Sign button not found", SRCNAME, __func__);
@@ -572,7 +550,7 @@
       button->Release ();
     }
 
-  button = get_button (serialno, "GpgOL_Inspector_Encrypt");
+  button = get_button (inspector, "GpgOL_Inspector_Encrypt");
   if (!button)
     {
       log_error ("%s:%s: Encrypt button not found", SRCNAME, __func__);
@@ -591,59 +569,59 @@
 }
 
 
-/* Set the flags for the inspector; i.e. whether to sign or encrypt a
-   message.  Returns 0 on success.  */
-int
-set_inspector_composer_flags (LPDISPATCH inspector, bool sign, bool encrypt)
+static int
+set_one_button (LPDISPATCH inspector, const char *tag, bool down)
 {
   LPDISPATCH button;
   int rc = 0;
-  unsigned long serialno;
 
-  serialno = get_serialno (inspector);
-  if (!serialno)
-    {
-      log_error ("%s:%s: S/n not found", SRCNAME, __func__);
-      return -1;
-    }
-
-  button = get_button (serialno, "GpgOL_Inspector_Sign");
+  button = get_button (inspector, tag);
   if (!button)
     {
-      log_error ("%s:%s: Sign button not found", SRCNAME, __func__);
+      log_error ("%s:%s: `%s' not found", SRCNAME, __func__, tag);
       rc = -1;
     }
   else
     {
-      if (put_oom_int (button, "State", sign? msoButtonDown : msoButtonUp))
+      if (put_oom_int (button, "State", down? msoButtonDown : msoButtonUp))
         rc = -1;
       button->Release ();
     }
+  return rc;
+}
 
-  button = get_button (serialno, "GpgOL_Inspector_Encrypt");
-  if (!button)
-    {
-      log_error ("%s:%s: Encrypt button not found", SRCNAME, __func__);
-      rc = -1;
-    }
-  else
-    {
-      if (put_oom_int (button, "State", encrypt? msoButtonDown : msoButtonUp))
-        rc = -1;
-      button->Release ();
-    }
-  
+
+
+/* Set the flags for the inspector; i.e. whether to sign or encrypt a
+   message.  Returns 0 on success.  */
+int
+set_inspector_composer_flags (LPDISPATCH inspector, bool sign, bool encrypt)
+{
+  int rc = 0;
+
+  if (set_one_button (inspector, "GpgOL_Inspector_Sign", sign))
+    rc = -1;
+  if (set_one_button (inspector, "GpgOL_Inspector_Sign at t", sign))
+    rc = -1;
+  if (set_one_button (inspector, "GpgOL_Inspector_Encrypt", encrypt))
+    rc = -1;
+  if (set_one_button (inspector, "GpgOL_Inspector_Encrypt at t", encrypt))
+    rc = -1;
+
   return rc;
 }
 
 
 /* Helper to make the tag unique.  */
 static const char *
-add_tag (LPDISPATCH control, unsigned long serialno, const char *value)
+add_tag (LPDISPATCH control, const char *value)
 {
+  int instid;
+  
   char buf[256];
   
-  snprintf (buf, sizeof buf, "%s#%lu", value, serialno);
+  instid = get_oom_int (control, "InstanceId");
+  snprintf (buf, sizeof buf, "%s#%d", value, instid);
   put_oom_string (control, "Tag", buf);
   return value;
 }
@@ -651,7 +629,7 @@
 
 /* Add all the controls.  */
 static void
-add_inspector_controls (LPOOMINSPECTOR inspector, unsigned long serialno)
+add_inspector_controls (LPOOMINSPECTOR inspector)
 {
   static
   LPDISPATCH obj, controls, button;
@@ -660,7 +638,6 @@
   const char *tag;
   int in_composer;
 
-
   log_debug ("%s:%s: Enter", SRCNAME, __func__);
 
   /* Check whether we are in composer or read mode.  */
@@ -678,7 +655,7 @@
           button = opt.disable_gpgol? NULL : add_oom_button (controls);
           if (button)
             {
-              tag = add_tag (button, serialno, "GpgOL_Inspector_Encrypt");
+              tag = add_tag (button, "GpgOL_Inspector_Encrypt");
               put_oom_bool (button, "BeginGroup", true);
               put_oom_int (button, "Style", msoButtonIconAndCaption );
               put_oom_string (button, "Caption",
@@ -686,19 +663,19 @@
               put_oom_icon (button, IDB_ENCRYPT, 16);
               
               obj = install_GpgolCommandBarButtonEvents_sink (button);
-              move_to_button_list (&buttonlist, obj, button, tag, serialno);
+              move_to_button_list (&buttonlist, obj, button, tag);
             }
           
           button = opt.disable_gpgol? NULL : add_oom_button (controls);
           if (button)
             {
-              tag = add_tag (button, serialno, "GpgOL_Inspector_Sign");
+              tag = add_tag (button, "GpgOL_Inspector_Sign");
               put_oom_int (button, "Style", msoButtonIconAndCaption );
               put_oom_string (button, "Caption", _("&sign message with GnuPG"));
               put_oom_icon (button, IDB_SIGN, 16);
               
               obj = install_GpgolCommandBarButtonEvents_sink (button);
-              move_to_button_list (&buttonlist, obj, button, tag, serialno);
+              move_to_button_list (&buttonlist, obj, button, tag);
             }
           
           controls->Release ();
@@ -716,49 +693,49 @@
       button = in_composer? NULL : add_oom_button (controls);
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Verify");
+          tag = add_tag (button, "GpgOL_Inspector_Verify");
           put_oom_int (button, "Style", msoButtonIconAndCaption );
           put_oom_string (button, "Caption", _("GpgOL Decrypt/Verify"));
           put_oom_icon (button, IDB_DECRYPT_VERIFY, 16);
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       button = opt.enable_debug? add_oom_button (controls) : NULL;
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Debug-0");
+          tag = add_tag (button, "GpgOL_Inspector_Debug-0");
           put_oom_int (button, "Style", msoButtonCaption );
           put_oom_string (button, "Caption",
                           "GpgOL Debug-0 (display crypto info)");
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       button = opt.enable_debug? add_oom_button (controls) : NULL;
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Debug-1");
+          tag = add_tag (button, "GpgOL_Inspector_Debug-1");
           put_oom_int (button, "Style", msoButtonCaption );
           put_oom_string (button, "Caption",
-                          "GpgOL Debug-1 (open_inspector)");
+                          "GpgOL Debug-1 (not used)");
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       button = opt.enable_debug? add_oom_button (controls) : NULL;
       if (button)
         {
-          tag = add_tag (button, serialno,"GpgOL_Inspector_Debug-2");
+          tag = add_tag (button, "GpgOL_Inspector_Debug-2");
           put_oom_int (button, "Style", msoButtonCaption );
           put_oom_string (button, "Caption",
                           "GpgOL Debug-2 (change message class)");
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       controls->Release ();
@@ -777,38 +754,38 @@
                 ? NULL : add_oom_button (controls));
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Encrypt at t");
+          tag = add_tag (button, "GpgOL_Inspector_Encrypt at t");
           put_oom_int (button, "Style", msoButtonIcon );
           put_oom_string (button, "Caption", _("Encrypt message with GnuPG"));
           put_oom_icon (button, IDB_ENCRYPT, 16);
           put_oom_int (button, "State", msoButtonMixed );
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       button = (opt.disable_gpgol || !in_composer
                 ? NULL : add_oom_button (controls));
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Sign at t");
+          tag = add_tag (button, "GpgOL_Inspector_Sign at t");
           put_oom_int (button, "Style", msoButtonIcon);
           put_oom_string (button, "Caption", _("Sign message with GnuPG"));
           put_oom_icon (button, IDB_SIGN, 16);
           put_oom_int (button, "State", msoButtonDown);
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       button = in_composer? NULL : add_oom_button (controls);
       if (button)
         {
-          tag = add_tag (button, serialno, "GpgOL_Inspector_Crypto_Info");
+          tag = add_tag (button, "GpgOL_Inspector_Crypto_Info");
           put_oom_int (button, "Style", msoButtonIcon);
           
           obj = install_GpgolCommandBarButtonEvents_sink (button);
-          move_to_button_list (&buttonlist, obj, button, tag, serialno);
+          move_to_button_list (&buttonlist, obj, button, tag);
         }
 
       controls->Release ();
@@ -844,91 +821,141 @@
 
 /* Update the crypto info icon.  */
 static void
-update_crypto_info (LPDISPATCH button)
+update_crypto_info (LPDISPATCH inspector)
 {
-  LPDISPATCH inspector;
-  char *msgcls = NULL;;
-  const char *s;
-  int in_composer = 0;
-  int is_encrypted = 0;
-  int is_signed = 0;
-  const char *tooltip;
-  int iconrc;
+  HRESULT hr;
+  LPDISPATCH button;
+  const char *tooltip = "";
+  int iconrc = -1;
 
-  /* FIXME: We should store the information retrieved by old
-     versions via mapi_get_message_type and mapi_test_sig_status
-     in UserProperties and use them instead of a direct lookup of
-     the messageClass.  */
-
-  inspector = get_oom_object (button, "get_Parent.get_Parent.get_CurrentItem");
-  if (inspector)
+  button = get_button (inspector, "GpgOL_Inspector_Crypto_Info");
+  if (!button)
     {
-      msgcls = get_oom_string (inspector, "MessageClass");
-      in_composer = is_inspector_in_composer_mode (inspector);
-      inspector->Release ();
+      log_error ("%s:%s: Crypto Info button not found", SRCNAME, __func__);
+      return;
     }
-  if (msgcls)
+
+  if (!is_inspector_in_composer_mode (inspector))
     {
-      log_debug ("%s:%s: message class is `%s'", SRCNAME, __func__, msgcls);
-      if (!strncmp (msgcls, "IPM.Note.GpgOL", 14) 
-          && (!msgcls[14] || msgcls[14] == '.'))
+      LPDISPATCH obj;
+      LPUNKNOWN unknown;
+      LPMESSAGE message = NULL;
+
+      obj = get_oom_object (inspector, "get_CurrentItem");
+      if (obj)
         {
-          s = msgcls + 14;
-          if (!*s)
-            ;
-          else if (!strcmp (s, ".MultipartSigned"))
-            is_signed = 1;
-          else if (!strcmp (s, ".MultipartEncrypted"))
-            is_encrypted = 1;
-          else if (!strcmp (s, ".OpaqueSigned"))
-            is_signed = 1;
-          else if (!strcmp (s, ".OpaqueEncrypted"))
-            is_encrypted = 1;
-          else if (!strcmp (s, ".ClearSigned"))
-            is_signed = 1;
-          else if (!strcmp (s, ".PGPMessage"))
-            is_encrypted = 1;
+          unknown = get_oom_iunknown (obj, "MAPIOBJECT");
+          if (!unknown)
+            log_error ("%s:%s: error getting MAPI object", SRCNAME, __func__);
+          else
+            {
+              hr = unknown->QueryInterface (IID_IMessage, (void**)&message);
+              if (hr != S_OK || !message)
+                {
+                  message = NULL;
+                  log_error ("%s:%s: error getting IMESSAGE: hr=%#lx",
+                             SRCNAME, __func__, hr);
+                }
+              unknown->Release ();
+            }
+          obj->Release ();
         }
-      
-      /*FIXME: check something like mail_test_sig_status to see
-        whether it is an encrypted and signed message.  */
-      
-      if (in_composer)
+      if (message)
         {
-          tooltip = "";
-          iconrc = -1;
+          int is_encrypted = 0;
+          int is_signed = 0;
+          
+          switch (mapi_get_message_type (message))
+            {
+            case MSGTYPE_GPGOL_MULTIPART_ENCRYPTED:
+            case MSGTYPE_GPGOL_OPAQUE_ENCRYPTED:
+            case MSGTYPE_GPGOL_PGP_MESSAGE:
+              is_encrypted = 1;
+              if ( mapi_test_sig_status (message) )
+                is_signed = 1;
+              break;
+            case MSGTYPE_GPGOL:
+            case MSGTYPE_SMIME:
+            case MSGTYPE_UNKNOWN:
+              break;
+            default:
+              is_signed = 1;
+              break;
+            }
+          
+          if (is_signed && is_encrypted)
+            {
+              tooltip =  _("This is a signed and encrypted message.\n"
+                           "Click for more information. ");
+              iconrc = IDB_DECRYPT_VERIFY;
+            }
+          else if (is_signed)
+            {
+              tooltip =  _("This is a signed message.\n"
+                           "Click for more information. ");
+              iconrc = IDB_VERIFY;
+            }
+          else if (is_encrypted)
+            {
+              tooltip =  _("This is an encrypted message.\n"
+                           "Click for more information. ");
+              iconrc = IDB_DECRYPT;
+            }
+          
+          message->Release ();
         }
-      else if (is_signed && is_encrypted)
+    }
+
+  put_oom_string (button, "TooltipText", tooltip);
+  if (iconrc != -1)
+    put_oom_icon (button, iconrc, 16);
+  put_oom_bool (button, "Visible", (iconrc != -1));
+  button->Release ();
+}
+
+
+/* Return the MAPI message object of then inspector from a button's
+   instance id. */
+static LPMESSAGE
+get_message_from_button (unsigned long instid, LPDISPATCH *r_inspector)
+{
+  HRESULT hr;
+  LPDISPATCH inspector, obj;
+  LPUNKNOWN  unknown;
+  LPMESSAGE message = NULL;
+  
+  if (r_inspector)
+    *r_inspector = NULL;
+  inspector = get_inspector_from_instid (instid);
+  if (inspector)
+    {
+      obj = get_oom_object (inspector, "get_CurrentItem");
+      if (!obj)
+        log_error ("%s:%s: error getting CurrentItem", SRCNAME, __func__);
+      else
         {
-          tooltip =  _("This is a signed and encrypted message.\n"
-                       "Click for more information. ");
-          iconrc = IDB_DECRYPT_VERIFY;
+          unknown = get_oom_iunknown (obj, "MAPIOBJECT");
+          if (!unknown)
+            log_error ("%s:%s: error getting MAPI object", SRCNAME, __func__);
+          else
+            {
+              hr = unknown->QueryInterface (IID_IMessage, (void**)&message);
+              if (hr != S_OK || !message)
+                {
+                  message = NULL;
+                  log_error ("%s:%s: error getting IMESSAGE: hr=%#lx",
+                             SRCNAME, __func__, hr);
+                }
+              unknown->Release ();
+            }
+          obj->Release ();
         }
-      else if (is_signed)
-        {
-          tooltip =  _("This is a signed message.\n"
-                       "Click for more information. ");
-          iconrc = IDB_VERIFY;
-        }
-      else if (is_encrypted)
-        {
-          tooltip =  _("This is an encrypted message.\n"
-                       "Click for more information. ");
-          iconrc = IDB_DECRYPT;
-        }
+      if (r_inspector)
+        *r_inspector = inspector;
       else
-        {
-          tooltip = "";
-          iconrc = -1;
-        }
-      
-      put_oom_string (button, "TooltipText", tooltip);
-      if (iconrc != -1)
-        put_oom_icon (button, iconrc, 16);
-      put_oom_bool (button, "Visible", (iconrc != -1));
-      
-      xfree (msgcls);
+        inspector->Release ();
     }
+  return message;
 }
 
 
@@ -949,7 +976,7 @@
   mem2str (tag2, tag, sizeof tag2 - 2);
   p = strchr (tag2, '#');
   if (p)
-    *p = 0;  /* Strip the serialno suffix.  */
+    *p = 0;  /* Strip the instance id suffix.  */
   if (*tag2 && tag2[1] && !strcmp (tag2+strlen(tag2)-2, "@t"))
     tag2[strlen(tag2)-2] = 0; /* Remove the "@t".  */
   else
@@ -973,6 +1000,9 @@
 void
 proc_inspector_button_click (LPDISPATCH button, const char *tag, int instid)
 {
+  LPMESSAGE message;
+  HWND hwnd = NULL; /* Fixme  */
+
   if (!tagcmp (tag, "GpgOL_Inspector_Encrypt"))
     {  
       toggle_button (button, tag, instid);
@@ -981,85 +1011,65 @@
     {  
       toggle_button (button, tag, instid);
     }
-  else if (!tagcmp (tag, "GpgOL_Inspector_Verify"))
+  else if (!tagcmp (tag, "GpgOL_Inspector_Verify")
+           || !tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
     {
-      /* FIXME: We need to invoke decrypt/verify again. */
-    }
-  else if (!tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
-    {
-      /* FIXME: We should invoke the decrypt/verify again. */
-      update_crypto_info (button);
-#if 0 /* This is the code we used to use.  */
-      log_debug ("%s:%s: command CryptoState called\n", SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
+      LPDISPATCH inspector;
+
+      message = get_message_from_button (instid, &inspector);
+      if (message)
         {
           if (message_incoming_handler (message, hwnd, true))
-            message_display_handler (eecb, hwnd);
-	}
-      else
-        log_debug_w32 (hr, "%s:%s: command CryptoState failed", 
-                       SRCNAME, __func__);
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-#endif
+            message_display_handler (message, inspector, hwnd);
+          message->Release ();
+        }
+      if (inspector)
+        {
+          update_crypto_info (inspector);
+          inspector->Release ();
+        }
     }
   else if (!tagcmp (tag, "GpgOL_Inspector_Debug-0"))
     {
-      /* Show crypto info.  */
       log_debug ("%s:%s: command Debug0 (showInfo) called\n",
                  SRCNAME, __func__);
-      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      // if (SUCCEEDED (hr))
-      //   {
-      //     message_show_info (message, hwnd);
-      //   }
-      // ul_release (message, __func__, __LINE__);
-      // ul_release (mdb, __func__, __LINE__);
+      message = get_message_from_button (instid, NULL);
+      if (message)
+        {
+          message_show_info (message, hwnd);
+          message->Release ();
+        }
     }
   else if (!tagcmp (tag, "GpgOL_Inspector_Debug-1"))
     {
-      /* Open inspector.  */
-      log_debug ("%s:%s: command Debug1 (open inspector) called\n",
+      log_debug ("%s:%s: command Debug1 (not used) called\n",
                  SRCNAME, __func__);
-      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      // if (SUCCEEDED (hr))
-      //   {
-      //     open_inspector (eecb, message);
-      //   }
-      // ul_release (message, __func__, __LINE__);
-      // ul_release (mdb, __func__, __LINE__);
     }
   else if (!tagcmp (tag, "GpgOL_Inspector_Debug-2"))
     {
-      /* Change message class.  */
       log_debug ("%s:%s: command Debug2 (change message class) called", 
                  SRCNAME, __func__);
-      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      // if (SUCCEEDED (hr))
-      //   {
-      //     /* We sync here. */
-      //     mapi_change_message_class (message, 1);
-      //   }
-      // ul_release (message, __func__, __LINE__);
-      // ul_release (mdb, __func__, __LINE__);
+      message = get_message_from_button (instid, NULL);
+      if (message)
+        {
+          /* We sync here. */
+          mapi_change_message_class (message, 1);
+          message->Release ();
+        }
     }
   else if (!tagcmp (tag, "GpgOL_Inspector_Debug-3"))
     {
       log_debug ("%s:%s: command Debug3 (revert_message_class) called", 
                  SRCNAME, __func__);
-      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      // if (SUCCEEDED (hr))
-      //   {
-      //     int rc = gpgol_message_revert (message, 1, 
-      //                                    KEEP_OPEN_READWRITE|FORCE_SAVE);
-      //     log_debug ("%s:%s: gpgol_message_revert returns %d\n", 
-      //                SRCNAME, __func__, rc);
-      //   }
-      // ul_release (message, __func__, __LINE__);
-      // ul_release (mdb, __func__, __LINE__);
+      message = get_message_from_button (instid, NULL);
+      if (message)
+        {
+          int rc = gpgol_message_revert (message, 1, 
+                                         KEEP_OPEN_READWRITE|FORCE_SAVE);
+          log_debug ("%s:%s: gpgol_message_revert returns %d\n", 
+                     SRCNAME, __func__, rc);
+          message->Release ();
+        }
     }
 
-
-
 }

Modified: trunk/src/inspectors.h
===================================================================
--- trunk/src/inspectors.h	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/inspectors.h	2009-11-03 12:01:24 UTC (rev 315)
@@ -118,9 +118,11 @@
 };
 
 
+/* Create a new sink and attach it to OBJECT.  */
 LPDISPATCH install_GpgolInspectorsEvents_sink (LPDISPATCH object);
 
 LPDISPATCH install_GpgolInspectorEvents_sink (LPDISPATCH object);
+void detach_GpgolInspectorEvents_sink (LPDISPATCH sink);
 
 
 void proc_inspector_button_click (LPDISPATCH button,

Modified: trunk/src/item-events.cpp
===================================================================
--- trunk/src/item-events.cpp	2009-10-30 21:44:43 UTC (rev 314)
+++ trunk/src/item-events.cpp	2009-11-03 12:01:24 UTC (rev 315)
@@ -135,18 +135,33 @@
 STDMETHODIMP 
 GpgolItemEvents::OnOpenComplete (LPEXCHEXTCALLBACK eecb, ULONG flags)
 {
+  HRESULT hr;
+  
   log_debug ("%s:%s: received, flags=%#lx", SRCNAME, __func__, flags);
 
   /* If the message has been processed by us (i.e. in OnOpen), we now
      use our own display code.  */
   if (!flags && m_processed)
     {
+      LPMDB mdb = NULL;
+      LPMESSAGE message = NULL;
       HWND hwnd = NULL;
 
       if (FAILED (eecb->GetWindow (&hwnd)))
         hwnd = NULL;
-      if (message_display_handler (eecb, hwnd))
-        m_wasencrypted = true;
+      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
+      if (hr != S_OK || !message) 
+        log_error ("%s:%s: error getting message: hr=%#lx",
+                   SRCNAME, __func__, hr);
+      else
+        {
+          if (message_display_handler (message, hwnd))
+            m_wasencrypted = true;
+        }
+      if (message)
+        message->Release ();
+      if (mdb)
+        mdb->Release ();
     }
   
   return S_FALSE;

Added: trunk/src/mailitem.cpp
===================================================================
--- trunk/src/mailitem.cpp	                        (rev 0)
+++ trunk/src/mailitem.cpp	2009-11-03 12:01:24 UTC (rev 315)
@@ -0,0 +1,133 @@
+/* mailitem.cpp - Code to handle the Outlook MailItem
+ *	Copyright (C) 2009 g10 Code GmbH
+ * 
+ * This file is part of GpgOL.
+ * 
+ * GpgOL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * GpgOL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <windows.h>
+#include <olectl.h>
+
+#include "common.h"
+#include "oomhelp.h"
+#include "eventsink.h"
+#include "mailitem.h"
+
+
+/* Subclass of ItemEvents so that we can hook into the events.  */
+BEGIN_EVENT_SINK(GpgolItemEvents, IOOMItemEvents)
+  STDMETHOD(Read)(THIS_ );
+  STDMETHOD(Write)(THIS_ PBOOL cancel);
+  STDMETHOD(Open)(THIS_ PBOOL cancel);
+  STDMETHOD(Close)(THIS_ PBOOL cancel);
+EVENT_SINK_DEFAULT_CTOR(GpgolItemEvents)
+EVENT_SINK_DEFAULT_DTOR(GpgolItemEvents)
+EVENT_SINK_INVOKE(GpgolItemEvents)
+{
+  HRESULT hr;
+  (void)lcid; (void)riid; (void)result; (void)exepinfo; (void)argerr;
+
+  switch (dispid)
+    {
+    case 0xf001:
+      if (!(flags & DISPATCH_METHOD))
+        goto badflags;
+      if (parms->cArgs != 0)
+        hr = DISP_E_BADPARAMCOUNT;
+      else
+        {
+          Read ();
+          hr = S_OK;
+        }
+      break;
+
+    case 0xf004:
+      if (!(flags & DISPATCH_METHOD))
+        goto badflags;
+      if (!parms) 
+        hr = DISP_E_PARAMNOTOPTIONAL;
+      else if (parms->cArgs != 1)
+        hr = DISP_E_BADPARAMCOUNT;
+      else if (parms->rgvarg[0].vt != (VT_BOOL|VT_BYREF))
+        hr = DISP_E_BADVARTYPE;
+      else
+        {
+          BOOL cancel_default = !!*parms->rgvarg[0].pboolVal;
+          switch (dispid)
+            {
+            case 0xf002: Write (&cancel_default); break;
+            case 0xf003: Open (&cancel_default); break;
+            case 0xf004: Close (&cancel_default); break;
+            }
+          *parms->rgvarg[0].pboolVal = (cancel_default 
+                                        ? VARIANT_TRUE:VARIANT_FALSE);
+          hr = S_OK;
+        }
+      break;
+
+    badflags:
+    default:
+      hr = DISP_E_MEMBERNOTFOUND;
+    }
+  return hr;
+}
+END_EVENT_SINK(GpgolItemEvents, IID_IOOMItemEvents)
+
+
+/* This is the event sink for a read event.  */
+STDMETHODIMP
+GpgolItemEvents::Read (void)




More information about the Gnupg-commits mailing list