[git] GpgOL - branch, master, updated. gpgol-1.3.0-15-g94b3317

by Andre Heinecke cvs at cvs.gnupg.org
Wed Dec 2 20:43:07 CET 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, master has been updated
       via  94b331747d84196f524b633c2a23568cb0b69359 (commit)
       via  c5e7483db0565a62efbed13dac8b87131182b27c (commit)
       via  4b4fc8482c4cf62f459b3f0c194c4ed7d5114b77 (commit)
       via  6a2ff276b11b3100b4d64f8c5308dfa0c48de211 (commit)
      from  14e06fe2500a1735b2089b03231e45e63a6f40fb (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 94b331747d84196f524b633c2a23568cb0b69359
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Dec 2 20:32:56 2015 +0100

    Add revert support for PGP MulitpartEncrypted
    
    * src/mimemaker.c (restore_msg_from_moss): Create a mosstmpl
      attachment. Currently only works for PGP MultipartEncrypted.
    * src/mimemaker.h: Add prototype.
    * src/oomhelp.h: Add DASL for attachment MIME tag.
    * src/revert.cpp (finalize_mapi): Dont restore message class.
      (gpgol_mailitem_revert): Collect info first. Then work. Handle
      MOSS attachments. Do Magic.
    
    --
    For S/MIME we will want to add an option to also restore the
    message class. The important thing here is how the message
    class is mangled to trigger the SMIME.MultipartSigned behavior
    without visibly changing the icon in the message list.

diff --git a/src/mimemaker.c b/src/mimemaker.c
index 0641dff..461d1e3 100644
--- a/src/mimemaker.c
+++ b/src/mimemaker.c
@@ -1,5 +1,6 @@
 /* mimemaker.c - Construct MIME message out of a MAPI
- *	Copyright (C) 2007, 2008 g10 Code GmbH
+ *    Copyright (C) 2007, 2008 g10 Code GmbH
+ *    Copyright (C) 2015 Intevation GmbH
  *
  * This file is part of GpgOL.
  *
@@ -39,6 +40,7 @@
 #include "engine.h"
 #include "mapihelp.h"
 #include "mimemaker.h"
+#include "oomhelp.h"
 
 static const char oid_mimetag[] =
     {0x2A, 0x86, 0x48, 0x86, 0xf7, 0x14, 0x03, 0x0a, 0x04};
@@ -1995,3 +1997,77 @@ mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
   xfree (my_sender);
   return result;
 }
+
+int
+restore_msg_from_moss (LPMESSAGE message, LPDISPATCH moss_att,
+                       msgtype_t type, char *msgcls)
+{
+  struct sink_s sinkmem;
+  sink_t sink = &sinkmem;
+  char *orig = NULL;
+  int err = -1;
+  char boundary[BOUNDARYSIZE+1];
+
+  LPATTACH new_attach = create_mapi_attachment (message,
+                                                sink);
+  log_debug ("Restore message from moss called.");
+  if (!new_attach)
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+  // TODO MORE
+  if (type == MSGTYPE_SMIME)
+    {
+      create_top_encryption_header (sink, PROTOCOL_SMIME, boundary);
+    }
+  else
+    {
+      create_top_encryption_header (sink, PROTOCOL_OPENPGP, boundary);
+    }
+
+  orig = get_pa_string (moss_att, PR_ATTACH_DATA_BIN_DASL);
+
+  if (!orig)
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  if (write_string (sink, orig))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  if (*boundary && write_boundary (sink, boundary, 1))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  if (close_mapi_attachment (&new_attach, sink))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  /* Set a special property so that we are later able to identify
+     messages signed or encrypted by us.  */
+  if (mapi_set_sig_status (message, "@"))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  if (mapi_set_gpgol_msg_class (message, msgcls))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      goto done;
+    }
+
+  err = 0;
+done:
+  xfree (orig);
+  return err;
+}
diff --git a/src/mimemaker.h b/src/mimemaker.h
index 187e80e..f483120 100644
--- a/src/mimemaker.h
+++ b/src/mimemaker.h
@@ -58,6 +58,15 @@ int sink_encryption_write (sink_t encsink, const void *data, size_t datalen);
 int write_buffer_for_cb (void *opaque, const void *data, size_t datalen);
 int write_buffer (sink_t sink, const void *data, size_t datalen);
 
+/** @brief Try to restore a message from the moss attachment.
+  *
+  * Try to turn the moss attachment back into a Mail that other
+  * MUAs could handle. Uses all the tricks available to archive
+  * that. Returns 0 on success.
+  */
+int restore_msg_from_moss (LPMESSAGE message, LPDISPATCH moss_att,
+                           msgtype_t type, char *msgcls);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/oomhelp.h b/src/oomhelp.h
index 66cff65..aad7f7d 100644
--- a/src/oomhelp.h
+++ b/src/oomhelp.h
@@ -93,7 +93,8 @@ DEFINE_OLEGUID(IID_IOleWindow,                0x00000114, 0, 0);
   "http://schemas.microsoft.com/mapi/proptag/0x1000001F"
 #define PR_ATTACHMENT_HIDDEN_DASL \
   "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"
-
+#define PR_ATTACH_MIME_TAG_DASL \
+  "http://schemas.microsoft.com/mapi/proptag/0x370E001F"
 #ifdef __cplusplus
 extern "C" {
 #if 0
diff --git a/src/revert.cpp b/src/revert.cpp
index 62a574f..714da94 100644
--- a/src/revert.cpp
+++ b/src/revert.cpp
@@ -29,6 +29,7 @@
 #include "oomhelp.h"
 #include "mapihelp.h"
 #include "message.h"
+#include "mimemaker.h"
 
 
 /* Wrapper around UlRelease with error checking. */
@@ -235,40 +236,12 @@ gpgol_message_revert (LPMESSAGE message, LONG do_save, ULONG save_flags)
 
 /* Helper method for mailitem_revert to add changes on the mapi side
    and save them. */
-static int finalize_mapi (LPMESSAGE message, char *msgcls)
+static int finalize_mapi (LPMESSAGE message)
 {
-  char * oldmsgcls = NULL;
   HRESULT hr;
-  SPropValue prop;
   SPropTagArray proparray;
   ULONG tag_id;
-  if (mapi_save_changes (message, FORCE_SAVE | KEEP_OPEN_READWRITE))
-    {
-      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
-      return -1;
-    }
-  oldmsgcls = mapi_get_old_message_class (message);
-  if (!oldmsgcls)
-    {
-      /* No saved message class, mangle the actual class.  */
-      if (!strcmp (msgcls, "IPM.Note.GpgOL.ClearSigned")
-          || !strcmp (msgcls, "IPM.Note.GpgOL.PGPMessage") )
-        msgcls[8] = 0;
-      else
-        memcpy (msgcls+9, "SMIME", 5);
-      oldmsgcls = msgcls;
-      msgcls = NULL;
-    }
-  /* Change the message class. */
-  prop.ulPropTag = PR_MESSAGE_CLASS_A;
-  prop.Value.lpszA = oldmsgcls;
-  hr = message->SetProps (1, &prop, NULL);
-  if (hr)
-    {
-      log_error ("%s:%s: can't set message class to `%s': hr=%#lx\n",
-                 SRCNAME, __func__, oldmsgcls, hr);
-      return -1;
-    }
+
   if (get_gpgollastdecrypted_tag (message, &tag_id))
     {
       log_error ("%s:%s: can't getlastdecrypted tag",
@@ -284,6 +257,15 @@ static int finalize_mapi (LPMESSAGE message, char *msgcls)
                  SRCNAME, __func__);
       return -1;
     }
+
+  /* Save the changes. */
+  if (mapi_save_changes (message,
+                         FORCE_SAVE | KEEP_OPEN_READWRITE))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      return -1;
+    }
+
   return 0;
 }
 
@@ -312,6 +294,11 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
   int count = 0;
   LONG result = -1;
   msgtype_t msgtype;
+  int body_restored = 0;
+  LPDISPATCH *to_delete = NULL;
+  int del_cnt = 0;
+  LPDISPATCH to_restore = NULL;
+  int mosstmpl_found = 0;
 
   /* Check whether we need to care about this message.  */
   msgcls = get_pa_string (mailitem, PR_MESSAGE_CLASS_W_DASL);
@@ -323,7 +310,7 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
       xfree (msgcls);
       log_error ("%s:%s: Message processed but not our class. Bug.",
                  SRCNAME, __func__);
-      return 0;  /* Not one of our message classes.  */
+      return -1;
     }
 
   message = get_oom_base_message (mailitem);
@@ -344,20 +331,15 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
     }
   msgtype = mapi_get_message_type (message);
 
-  if (msgtype != MSGTYPE_GPGOL_PGP_MESSAGE)
+  if (msgtype != MSGTYPE_GPGOL_PGP_MESSAGE &&
+      msgtype != MSGTYPE_GPGOL_MULTIPART_ENCRYPTED)
     {
       log_error ("%s:%s: Revert not supported for msgtype: %i",
                  SRCNAME, __func__, msgtype);
       goto done;
     }
-
   count = get_oom_int (attachments, "Count");
-
-  if (count < 1)
-    {
-      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
-      goto done;
-    }
+  to_delete = (LPDISPATCH*) xmalloc (count * sizeof (LPDISPATCH));
 
   /* Yes the items start at 1! */
   for (i = 1; i <= count; i++)
@@ -406,55 +388,126 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
                   RELDISP (attachment);
                   goto done;
                 }
+              body_restored = 1;
               xfree (body);
+              to_delete[del_cnt++] = attachment;
+              break;
             } /* No break we also want to delete that. */
-          case ATTACHTYPE_FROMMOSS:
-          case ATTACHTYPE_FROMMOSS_DEC:
+          case ATTACHTYPE_MOSS:
             {
-              if (invoke_oom_method (attachment, "Delete", NULL))
+              char *mime_tag = get_pa_string (attachment,
+                                              PR_ATTACH_MIME_TAG_DASL);
+              if (mime_tag && !strcmp (mime_tag, "application/octet-stream"))
                 {
-                  log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
-                  RELDISP (attachment);
-                  goto done;
+                  to_restore = attachment;
+                }
+              else
+                {
+                  log_oom ("%s:%s: Skipping attachment with tag: %s", SRCNAME,
+                           __func__, mime_tag);
                 }
-              i--;
-              count--;
+              xfree (mime_tag);
+              to_delete[del_cnt++] = attachment;
               break;
             }
-          case ATTACHTYPE_MOSS:
+          case ATTACHTYPE_FROMMOSS:
+          case ATTACHTYPE_FROMMOSS_DEC:
             {
-              VARIANT value;
-              VariantInit (&value);
-              value.vt = VT_BOOL;
-              value.boolVal = VARIANT_FALSE;
-              if (set_pa_variant (attachment, PR_ATTACHMENT_HIDDEN_DASL,
-                                  &value))
-                {
-                  log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
-                  RELDISP (attachment);
-                  goto done;
-                }
-              put_oom_string (mailitem, "Body", "");
+              to_delete[del_cnt++] = attachment;
+              break;
+            }
+          case ATTACHTYPE_MOSSTEMPL:
+            /* This is a newly created attachment containing a MIME structure
+               other clients could handle */
+            {
+              mosstmpl_found = 1;
               break;
             }
           default:
             log_error ("%s:%s: Unknown attachment type: %i",
                        SRCNAME, __func__, att_type);
         }
-      RELDISP (attachment);
     }
 
-  if (finalize_mapi (message, msgcls))
+  if (to_restore && !mosstmpl_found)
     {
-      log_error ("%s:%s: Finalize failed.",
-                 SRCNAME, __func__);
-      goto done;
+      log_debug ("%s:%s: Restoring from MOSS.", SRCNAME, __func__);
+      if (restore_msg_from_moss (message, to_restore, msgtype,
+                                 msgcls))
+        {
+          log_error ("%s:%s: Error: %i", SRCNAME, __func__,
+                     __LINE__);
+        }
+      else
+        {
+          to_restore = NULL;
+        }
     }
+  if (to_restore || mosstmpl_found)
+    {
+      HRESULT hr;
+      SPropValue prop;
+      /* Message was either restored or the only attachment is the
+         mosstmplate in which case we need to activate the
+         MultipartSigned magic.*/
+      prop.ulPropTag = PR_MESSAGE_CLASS_A;
+      // TODO handle disabled S/MIME and smime messages.
+      prop.Value.lpszA =
+        (char*) "IPM.Note.InfoPathForm.GpgOL.SMIME.MultipartSigned";
+      hr = HrSetOneProp (message, &prop);
+      if (hr)
+        {
+          log_error ("%s:%s: error setting the message class: hr=%#lx\n",
+                     SRCNAME, __func__, hr);
+          goto done;
+        }
+    }
+
   result = 0;
 done:
-  RELDISP (message);
-  xfree (msgcls);
+
+  /* Do the deletion body wipe even on error. */
+
+  for (i = 0; i < del_cnt; i++)
+    {
+      LPDISPATCH attachment = to_delete[i];
+
+      if (attachment == to_restore)
+        {
+          /* If restoring failed to restore is still set. In that case
+             do not delete the MOSS attachment to avoid data loss. */
+          continue;
+        }
+      /* Delete the attachments that are marked to delete */
+      if (invoke_oom_method (attachment, "Delete", NULL))
+        {
+          log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+          result = -1;
+        }
+    }
+  if (!body_restored && put_oom_string (mailitem, "Body", ""))
+    {
+      log_error ("%s:%s: Error: %i", SRCNAME, __func__, __LINE__);
+      result = -1;
+    }
+
+  for (i = 0; i < del_cnt; i++)
+    {
+      RELDISP (to_delete[i]);
+    }
+
+  xfree (to_delete);
   RELDISP (attachments);
+  xfree (msgcls);
+
+  if (!result && finalize_mapi (message))
+    {
+      log_error ("%s:%s: Finalize failed.",
+                 SRCNAME, __func__);
+      result = -1;
+    }
+
+  RELDISP (message);
 
   return result;
 }

commit c5e7483db0565a62efbed13dac8b87131182b27c
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Dec 2 20:31:10 2015 +0100

    Move some debug output into debug_oom
    
    * src/oomhelp.cpp (get_oom_object): Be quieter by default.

diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index 3a5de17..df2eda4 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -139,8 +139,8 @@ get_oom_object (LPDISPATCH pStart, const char *fullname)
   LPDISPATCH pObj = pStart;
   LPDISPATCH pDisp = NULL;
 
-  log_debug ("%s:%s: looking for %p->`%s'",
-             SRCNAME, __func__, pStart, fullname);
+  log_oom ("%s:%s: looking for %p->`%s'",
+           SRCNAME, __func__, pStart, fullname);
 
   while (pObj)
     {
@@ -171,7 +171,7 @@ get_oom_object (LPDISPATCH pStart, const char *fullname)
         return NULL;  /* The object has no IDispatch interface.  */
       if (!*fullname)
         {
-          log_debug ("%s:%s:         got %p",SRCNAME, __func__, pDisp);
+          log_oom ("%s:%s:         got %p",SRCNAME, __func__, pDisp);
           return pDisp; /* Ready.  */
         }
       

commit 4b4fc8482c4cf62f459b3f0c194c4ed7d5114b77
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Dec 2 19:59:53 2015 +0100

    Fix view of sent mails with S/MIME disabled
    
    * src/mapihelp.cpp (mapi_change_message_class): Respect overrides
      even with S/MIME disabled.
    
    --
    I don't see why this would be a problem with S/MIME disabled and
    I hope that it was originally a typo. We need the override to
    force Outlook to reconsider the data of sent mails.

diff --git a/src/mapihelp.cpp b/src/mapihelp.cpp
index 4c7fbe1..8815b08 100644
--- a/src/mapihelp.cpp
+++ b/src/mapihelp.cpp
@@ -1228,7 +1228,7 @@ mapi_change_message_class (LPMESSAGE message, int sync_override)
           newvalue = change_message_class_ipm_note_smime_multipartsigned
             (message);
         }
-      else if (opt.enable_smime && sync_override && have_override
+      else if (sync_override && have_override
                && !strncmp (s, "IPM.Note.GpgOL", 14) && (!s[14]||s[14] =='.'))
         {
           /* In case the original message class is not yet an GpgOL

commit 6a2ff276b11b3100b4d64f8c5308dfa0c48de211
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Tue Dec 1 16:09:50 2015 +0100

    Disable MIME style support for clearsigned mails
    
    * src/mapihelp.cpp (get_msgcls_from_pgp_lines): Disable clearsigned
      detection for Outlook 2010 and later
    
    --
    As we don't and probably won't handle this in revert we better
    not touch it at all to avoid removing the signature information.

diff --git a/src/mapihelp.cpp b/src/mapihelp.cpp
index 45fe276..4c7fbe1 100644
--- a/src/mapihelp.cpp
+++ b/src/mapihelp.cpp
@@ -619,7 +619,10 @@ get_msgcls_from_pgp_lines (LPMESSAGE message)
     {
       if (!strncmp (p, "-----BEGIN PGP ", 15))
         {
-          if (!strncmp (p+15, "SIGNED MESSAGE-----", 19)
+          /* Enabling clearsigned detection for Outlook 2010 and later
+             would result in data loss as the signature is not reverted. */
+          if (g_ol_version_major < 14
+              && !strncmp (p+15, "SIGNED MESSAGE-----", 19)
               && trailing_ws_p (p+15+19))
             msgcls = xstrdup ("IPM.Note.GpgOL.ClearSigned");
           else if (!strncmp (p+15, "MESSAGE-----", 12)

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

Summary of changes:
 src/mapihelp.cpp |   7 ++-
 src/mimemaker.c  |  78 ++++++++++++++++++++++-
 src/mimemaker.h  |   9 +++
 src/oomhelp.cpp  |   6 +-
 src/oomhelp.h    |   3 +-
 src/revert.cpp   | 187 +++++++++++++++++++++++++++++++++++--------------------
 6 files changed, 216 insertions(+), 74 deletions(-)


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




More information about the Gnupg-commits mailing list