[git] GpgOL - branch, master, updated. gpgol-1.3.0-26-gc83341b

by Andre Heinecke cvs at cvs.gnupg.org
Thu Dec 10 15:01:48 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  c83341bf492e73bea4041e91ec2a08ed6d68888a (commit)
      from  719c0b9824ba3edfb83acfb75ed264941afd4d96 (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 c83341bf492e73bea4041e91ec2a08ed6d68888a
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Dec 10 14:47:34 2015 +0100

    Reduce syncs by canceling writes
    
    * src/mail.cpp (is_smime, needs_save): New.
    * src/mail.h: Declare and add new properties.
    * src/mailitem-events.cpp (MailitemEvents::Invoke): Cancel most
      writes.
    * src/revert.cpp (mailitem_revert): Use is_smime.
    
    --
    There are nearly no cases where we want to accept a write
    event for one of our crypto mails. If we cancel the write
    our changes won't be synced to the server.
    When closing a message we have to save / revert to avoid
    the "Properties of the message have changed" dialog which
    is totally confusing to users.
    We also want to write / revert in case S/MIME is disabled
    and we've encountered an S/MIME mail that was changed
    by us.

diff --git a/src/mail.cpp b/src/mail.cpp
index 7dc02f6..72971b4 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -64,7 +64,10 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_mailitem(mailitem),
     m_processed(false),
     m_needs_wipe(false),
+    m_needs_save(false),
     m_crypt_successful(false),
+    m_is_smime(false),
+    m_is_smime_checked(false),
     m_sender(NULL)
 {
   if (get_mail_for_item (mailitem))
@@ -392,3 +395,50 @@ Mail::revert ()
   m_processed = false;
   return 0;
 }
+
+bool
+Mail::is_smime ()
+{
+  msgtype_t msgtype;
+  LPMESSAGE message;
+
+  if (m_is_smime_checked)
+    {
+      return m_is_smime;
+    }
+
+  message = get_oom_message (m_mailitem);
+
+  if (!message)
+    {
+      log_error ("%s:%s: No message?",
+                 SRCNAME, __func__);
+      return false;
+    }
+
+  msgtype = mapi_get_message_type (message);
+  m_is_smime = msgtype == MSGTYPE_GPGOL_OPAQUE_ENCRYPTED ||
+               msgtype == MSGTYPE_GPGOL_OPAQUE_SIGNED;
+
+  /* Check if it is an smime mail. Multipart signed can
+     also be true. */
+  if (!m_is_smime && msgtype == MSGTYPE_GPGOL_MULTIPART_SIGNED)
+    {
+      char *proto;
+      char *ct = mapi_get_message_content_type (message, &proto, NULL);
+      if (ct && proto)
+        {
+          m_is_smime = (!strcmp (proto, "application/pkcs7-signature") ||
+                        !strcmp (proto, "application/x-pkcs7-signature"));
+        }
+      else
+        {
+          log_error ("Protocol in multipart signed mail.");
+        }
+      xfree (proto);
+      xfree (ct);
+    }
+  RELDISP (message);
+  m_is_smime_checked  = true;
+  return m_is_smime;
+}
diff --git a/src/mail.h b/src/mail.h
index e92ebee..ff79567 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -147,12 +147,31 @@ public:
   */
   bool is_crypto_mail () { return m_processed; }
 
+  /** @brief This mail needs to be actually written.
+  *
+  * @returns true if the next write event should not be canceled.
+  */
+  bool needs_save () { return m_needs_save; }
+
+  /** @brief set the needs save state.
+  */
+  void set_needs_save (bool val) { m_needs_save = val; }
+
+  /** @brief is this mail an S/MIME mail.
+    *
+    * @returns true for smime messages.
+    */
+  bool is_smime ();
+
 private:
   LPDISPATCH m_mailitem;
   LPDISPATCH m_event_sink;
   bool m_processed,    /* The message has been porcessed by us.  */
        m_needs_wipe,   /* We have added plaintext to the mesage. */
-       m_crypt_successful; /* We successfuly performed crypto on the item. */
+       m_needs_save,   /* A property was changed but not by us. */
+       m_crypt_successful, /* We successfuly performed crypto on the item. */
+       m_is_smime, /* This is an smime mail. */
+       m_is_smime_checked; /* it was checked if this is an smime mail */
   char *m_sender;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index 3c99023..1f101a5 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -27,6 +27,13 @@
 #include "windowmessages.h"
 #include "mail.h"
 
+const wchar_t * save_props[] = {
+  L"Categories",
+  L"FlagRequest",
+  L"TaskCompletedDate",
+  L"FlagStatus",
+  NULL };
+
 
 typedef enum
   {
@@ -142,6 +149,39 @@ EVENT_SINK_INVOKE(MailItemEvents)
             }
           break;
         }
+#if 0
+      case PropertyChange:
+        {
+          wchar_t *prop_name;
+          const wchar_t **cur;
+          if (!m_mail->is_crypto_mail ())
+            {
+              break;
+            }
+          if (!parms || parms->cArgs != 1 ||
+              parms->rgvarg[0].vt != VT_BSTR ||
+              !parms->rgvarg[0].bstrVal)
+            {
+              log_error ("%s:%s: Unexpected params.",
+                         SRCNAME, __func__);
+              break;
+            }
+
+          prop_name = parms->rgvarg[0].bstrVal;
+
+          for (cur = save_props; *cur; cur++)
+            {
+              if (!wcscmp (prop_name, *cur))
+                {
+                  m_mail->set_needs_save (true);
+                  break;
+                }
+            }
+          log_oom ("%s:%s: Message %p propchange: %ls.",
+                   SRCNAME, __func__, m_object, prop_name);
+          return S_OK;
+        }
+#endif
       case Send:
         {
           /* This is the only event where we can cancel the send of an
@@ -191,11 +231,26 @@ EVENT_SINK_INVOKE(MailItemEvents)
           if (parms->cArgs != 1 || parms->rgvarg[0].vt != (VT_BOOL | VT_BYREF))
            {
              /* This happens in the weird case */
-             log_oom ("%s:%s: Uncancellable write event.",
-                      SRCNAME, __func__);
+             log_debug ("%s:%s: Uncancellable write event.",
+                        SRCNAME, __func__);
              break;
            }
 
+          if ((!opt.enable_smime && m_mail->is_smime ()) &&
+              (m_mail->is_crypto_mail () && !m_mail->needs_save ()))
+            {
+              /* We cancel the write event to stop outlook from excessively
+                 syncing our changes.
+                 if smime support is disabled and we still have an smime
+                 mail we also don't want to cancel the write event
+                 to enable reverting this mails.
+                 */
+              *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
+              log_oom ("%s:%s: Canceling write event.",
+                         SRCNAME, __func__);
+              return S_OK;
+            }
+
           if (m_mail->revert ())
             {
               /* An error cleaning the mail should not happen normally.
@@ -204,8 +259,8 @@ EVENT_SINK_INVOKE(MailItemEvents)
               log_debug ("%s:%s: Failed to remove plaintext.",
                          SRCNAME, __func__);
               *(parms->rgvarg[0].pboolVal) = VARIANT_TRUE;
-              return E_ABORT;
             }
+          m_mail->set_needs_save (false);
           break;
         }
       case AfterWrite:
@@ -231,6 +286,7 @@ EVENT_SINK_INVOKE(MailItemEvents)
         {
           if (m_mail->is_crypto_mail ())
             {
+              m_mail->set_needs_save (true);
               invoke_oom_method (m_object, "Save", NULL);
             }
         }
diff --git a/src/revert.cpp b/src/revert.cpp
index 23f2f8c..abf25f2 100644
--- a/src/revert.cpp
+++ b/src/revert.cpp
@@ -30,7 +30,7 @@
 #include "mapihelp.h"
 #include "message.h"
 #include "mimemaker.h"
-
+#include "mail.h"
 
 /* Wrapper around UlRelease with error checking. */
 static void 
@@ -292,6 +292,7 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
   LPDISPATCH to_restore = NULL;
   int mosstmpl_found = 0;
   int is_smime = 0;
+  Mail *mail = NULL;
 
   /* Check whether we need to care about this message.  */
   msgcls = get_pa_string (mailitem, PR_MESSAGE_CLASS_W_DASL);
@@ -306,6 +307,16 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
       return -1;
     }
 
+  mail = Mail::get_mail_for_item (mailitem);
+  if (!mail)
+    {
+      xfree (msgcls);
+      log_error ("%s:%s: No mail object for mailitem. Bug.",
+                 SRCNAME, __func__);
+      return -1;
+    }
+  is_smime = mail->is_smime ();
+
   message = get_oom_base_message (mailitem);
   attachments = get_oom_object (mailitem, "Attachments");
 
@@ -335,27 +346,6 @@ gpgol_mailitem_revert (LPDISPATCH mailitem)
       goto done;
     }
 
-  is_smime = msgtype == MSGTYPE_GPGOL_OPAQUE_ENCRYPTED ||
-             msgtype == MSGTYPE_GPGOL_OPAQUE_SIGNED;
-
-  /* Check if it is an smime mail. Multipart signed can
-     also be true. */
-  if (!is_smime && msgtype == MSGTYPE_GPGOL_MULTIPART_SIGNED)
-    {
-      char *proto;
-      char *ct = mapi_get_message_content_type (message, &proto, NULL);
-      if (ct && proto)
-        {
-          is_smime = (!strcmp (proto, "application/pkcs7-signature") ||
-                      !strcmp (proto, "application/x-pkcs7-signature"));
-        }
-      else
-        {
-          log_error ("Protocol in multipart signed mail.");
-        }
-      xfree (proto);
-      xfree (ct);
-    }
 
   count = get_oom_int (attachments, "Count");
   to_delete = (LPDISPATCH*) xmalloc (count * sizeof (LPDISPATCH));

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

Summary of changes:
 src/mail.cpp            | 50 +++++++++++++++++++++++++++++++++++++++
 src/mail.h              | 21 ++++++++++++++++-
 src/mailitem-events.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++---
 src/revert.cpp          | 34 ++++++++++-----------------
 4 files changed, 141 insertions(+), 26 deletions(-)


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




More information about the Gnupg-commits mailing list