[git] GpgOL - branch, master, updated. gpgol-2.0.5-8-g08a7a0d

by Andre Heinecke cvs at cvs.gnupg.org
Tue Jan 9 16:17:56 CET 2018


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  08a7a0db7169ec6ab0abc2468fdcd16a8e06d4ce (commit)
      from  df029bca0eecd11f78bd0ef95360d0f37cb4b9d5 (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 08a7a0db7169ec6ab0abc2468fdcd16a8e06d4ce
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Tue Jan 9 16:12:55 2018 +0100

    Cache recipients trough oom and add fallbacks
    
    * src/mail.cpp (Mail::update_oom_data): Also cache recipients
    from oom.
    (Mail::Mail): Initialize cached recipients.
    (Mail::~Mail): Free cached recipients.
    (Mail::take_cached_recipients): New.
    * src/mail.h: Update accordingly.
    * src/message.cpp (get_recipients): Improve logging.
    (sign_encrypt): Use cached recipients.
    * src/oomhelp.cpp (get_oom_object): Tune down error.
    (get_recipient_addr_fallbacks): New.
    (get_oom_recipients): Improve with more fallbacks.
    * src/oomhelp.h (PR_EMS_AB_PROXY_ADDRESSES_DASL): Define.
    
    --
    This is a blind fix as I can't reproduce scenarios where
    this is necessary. Probably with exchange address books etc.
    Adding more fallbacks should not hurt the current uses
    where it would stop after the first lookup is successful.
    
    GnuPG-Bug-Id: T3616

diff --git a/src/mail.cpp b/src/mail.cpp
index 114e65c..7f709eb 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -132,6 +132,7 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_crypto_flags(0),
     m_cached_html_body(nullptr),
     m_cached_plain_body(nullptr),
+    m_cached_recipients(nullptr),
     m_type(MSGTYPE_UNKNOWN),
     m_do_inline(false),
     m_is_gsuite(false)
@@ -199,6 +200,9 @@ Mail::~Mail()
     }
   xfree (m_cached_html_body);
   xfree (m_cached_plain_body);
+  for (int i = 0; m_cached_recipients && m_cached_recipients[i]; ++i)
+      xfree (m_cached_recipients[i]);
+  xfree (m_cached_recipients);
   gpgrt_lock_unlock (&dtor_lock);
 }
 
@@ -1142,23 +1146,30 @@ Mail::update_oom_data ()
   LPDISPATCH sender = NULL;
   log_debug ("%s:%s", SRCNAME, __func__);
 
-  /* Update the body format. */
-  m_is_html_alternative = get_oom_int (m_mailitem, "BodyFormat") > 1;
-
-  /* Store the body. It was not obvious for me (aheinecke) how
-     to access this through MAPI. */
-  if (m_is_html_alternative)
+  if (!is_crypto_mail())
     {
-      log_debug ("%s:%s: Is html alternative mail.", SRCNAME, __func__);
-      xfree (m_cached_html_body);
-      m_cached_html_body = get_oom_string (m_mailitem, "HTMLBody");
+      /* Update the body format. */
+      m_is_html_alternative = get_oom_int (m_mailitem, "BodyFormat") > 1;
+
+      /* Store the body. It was not obvious for me (aheinecke) how
+         to access this through MAPI. */
+      if (m_is_html_alternative)
+        {
+          log_debug ("%s:%s: Is html alternative mail.", SRCNAME, __func__);
+          xfree (m_cached_html_body);
+          m_cached_html_body = get_oom_string (m_mailitem, "HTMLBody");
+        }
+      xfree (m_cached_plain_body);
+      m_cached_plain_body = get_oom_string (m_mailitem, "Body");
+
+      for (int i = 0; m_cached_recipients && m_cached_recipients[i]; ++i)
+          xfree (m_cached_recipients[i]);
+      xfree (m_cached_recipients);
+      m_cached_recipients = get_recipients ();
     }
-  xfree (m_cached_plain_body);
-  m_cached_plain_body = get_oom_string (m_mailitem, "Body");
   /* For some reason outlook may store the recipient address
      in the send using account field. If we have SMTP we prefer
      the SenderEmailAddress string. */
-
   if (is_crypto_mail ())
     {
       /* This is the case where we are reading a mail and not composing.
@@ -2394,3 +2405,11 @@ Mail::needs_encrypt() const
 {
   return m_needs_encrypt;
 }
+
+char **
+Mail::take_cached_recipients()
+{
+  char **ret = m_cached_recipients;
+  m_cached_recipients = nullptr;
+  return ret;
+}
diff --git a/src/mail.h b/src/mail.h
index 28b4bb5..48141b3 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -314,6 +314,11 @@ public:
   */
   char *take_cached_plain_body ();
 
+  /** Get the cached recipients. It is updated in update_oom_data.
+      Caller takes ownership of the list and has to free it.
+  */
+  char **take_cached_recipients ();
+
   /** Returns 1 if the mail was encrypted, 2 if signed, 3 if both.
       Only valid after decrypt_verify.
   */
@@ -358,6 +363,7 @@ private:
   std::string m_sender;
   char *m_cached_html_body; /* Cached html body. */
   char *m_cached_plain_body; /* Cached plain body. */
+  char **m_cached_recipients;
   msgtype_t m_type; /* Our messagetype as set in mapi */
   std::shared_ptr <ParseController> m_parser;
   GpgME::VerificationResult m_verify_result;
diff --git a/src/message.cpp b/src/message.cpp
index 08a38de..8e63c0d 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -32,6 +32,7 @@
 #include "display.h"
 #include "message.h"
 #include "gpgolstr.h"
+#include "mail.h"
 
 
 /* Wrapper around UlRelease with error checking. */
@@ -1040,6 +1041,9 @@ get_recipients (LPMESSAGE message)
               found_one = true;
               break;
 
+            case PT_ERROR:
+              log_debug ("%s:%s: proptag=0x%08lx is error",
+                         SRCNAME, __func__, val.ulPropTag);
             default:
               log_debug ("%s:%s: proptag=0x%08lx not supported\n",
                          SRCNAME, __func__, val.ulPropTag);
@@ -1086,9 +1090,16 @@ sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd, int signflag,
               const char *sender, Mail* mail)
 {
   gpg_error_t err;
-  char **recipients;
+  char **recipients = nullptr;
 
-  recipients = get_recipients (message);
+  if (mail)
+    {
+      recipients = mail->take_cached_recipients ();
+    }
+  if (!recipients)
+    {
+      recipients = get_recipients (message);
+    }
   if (!recipients || !recipients[0])
     {
       MessageBox (hwnd, _("No recipients to encrypt to are given"),
diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index 2141c9c..45013b4 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -317,7 +317,7 @@ get_oom_object (LPDISPATCH pStart, const char *fullname)
         SysFreeString (parmstr);
       if (hr != S_OK || vtResult.vt != VT_DISPATCH)
         {
-          log_debug ("%s:%s:       error: '%s' p=%p vt=%d hr=0x%x argErr=0x%x",
+          log_debug ("%s:%s: failure: '%s' p=%p vt=%d hr=0x%x argErr=0x%x",
                      SRCNAME, __func__,
                      name, vtResult.pdispVal, vtResult.vt, (unsigned int)hr,
                      (unsigned int)argErr);
@@ -329,7 +329,7 @@ get_oom_object (LPDISPATCH pStart, const char *fullname)
 
       pObj = vtResult.pdispVal;
     }
-  log_debug ("%s:%s:       error: no object", SRCNAME, __func__);
+  log_debug ("%s:%s: no object", SRCNAME, __func__);
   return NULL;
 }
 
@@ -1072,6 +1072,64 @@ get_pa_int (LPDISPATCH pDisp, const char *property, int *rInt)
   return 0;
 }
 
+/* Helper for additional fallbacks in recipient lookup */
+static char *
+get_recipient_addr_fallbacks (LPDISPATCH recipient)
+{
+  LPDISPATCH addr_entry = get_oom_object (recipient, "AddressEntry");
+
+  if (!addr_entry)
+    {
+      log_debug ("%s:%s: Failed to find AddressEntry",
+                 SRCNAME, __func__);
+      return nullptr;
+    }
+
+  /* Maybe check for type here? We are pretty sure that we are exchange */
+
+  /* According to MSDN Message Boards the PR_EMS_AB_PROXY_ADDRESSES_DASL
+     is more avilable then the SMTP Address. */
+  char *ret = get_pa_string (addr_entry, PR_EMS_AB_PROXY_ADDRESSES_DASL);
+  if (ret)
+    {
+      log_debug ("%s:%s: Found recipient through AB_PROXY: %s",
+                 SRCNAME, __func__, ret);
+
+      char *smtpbegin = strstr(ret, "SMTP:");
+      if (smtpbegin == ret)
+        {
+          ret += 5;
+        }
+      gpgol_release (addr_entry);
+      return ret;
+    }
+  else
+    {
+      log_debug ("%s:%s: Failed AB_PROXY lookup.",
+                 SRCNAME, __func__);
+    }
+
+  LPDISPATCH ex_user = get_oom_object (addr_entry, "GetExchangeUser");
+  gpgol_release (addr_entry);
+  if (!ex_user)
+    {
+      log_debug ("%s:%s: Failed to find ExchangeUser",
+                 SRCNAME, __func__);
+      return nullptr;
+    }
+
+  ret = get_oom_string (ex_user, "PrimarySmtpAddress");
+  gpgol_release (ex_user);
+  if (ret)
+    {
+      log_debug ("%s:%s: Found recipient through exchange user primary smtp address: %s",
+                 SRCNAME, __func__, ret);
+      return ret;
+    }
+
+  return nullptr;
+}
+
 /* Gets a malloced NULL terminated array of recipent strings from
    an OOM recipients Object. */
 char **
@@ -1103,22 +1161,26 @@ get_oom_recipients (LPDISPATCH recipients)
                      SRCNAME, __func__, i);
           break;
         }
-      else
+      char *resolved = get_pa_string (recipient, PR_SMTP_ADDRESS_DASL);
+      if (resolved)
         {
-          char *address,
-               *resolved;
-          address = get_oom_string (recipient, "Address");
-          resolved = get_pa_string (recipient, PR_SMTP_ADDRESS_DASL);
-          if (resolved)
-            {
-              xfree (address);
-              recipientAddrs[i-1] = resolved;
-              continue;
-            }
-          log_debug ("%s:%s: Failed to look up SMTP Address;",
-                     SRCNAME, __func__);
-          recipientAddrs[i-1] = address;
+          recipientAddrs[i-1] = resolved;
+          gpgol_release (recipient);
+          continue;
         }
+      /* No PR_SMTP_ADDRESS first fallback */
+      resolved = get_recipient_addr_fallbacks (recipient);
+      gpgol_release (recipient);
+      if (resolved)
+        {
+          recipientAddrs[i-1] = resolved;
+          continue;
+        }
+
+      char *address = get_oom_string (recipient, "Address");
+      log_debug ("%s:%s: Failed to look up Address probably EX addr is returned",
+                 SRCNAME, __func__);
+      recipientAddrs[i-1] = address;
     }
   return recipientAddrs;
 }
diff --git a/src/oomhelp.h b/src/oomhelp.h
index e719b79..1008860 100644
--- a/src/oomhelp.h
+++ b/src/oomhelp.h
@@ -85,6 +85,11 @@ DEFINE_OLEGUID(IID_IOleWindow,                0x00000114, 0, 0);
   "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
 #endif
 
+#ifndef PR_EMS_AB_PROXY_ADDRESSES_DASL
+#define PR_EMS_AB_PROXY_ADDRESSES_DASL \
+  "http://schemas.microsoft.com/mapi/proptag/0x800F101E"
+#endif
+
 #ifndef PR_ATTACHMENT_HIDDEN_DASL
 #define PR_ATTACHMENT_HIDDEN_DASL \
   "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"

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

Summary of changes:
 src/mail.cpp    | 43 ++++++++++++++++++--------
 src/mail.h      |  6 ++++
 src/message.cpp | 15 +++++++--
 src/oomhelp.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++----------
 src/oomhelp.h   |  5 +++
 5 files changed, 133 insertions(+), 30 deletions(-)


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




More information about the Gnupg-commits mailing list