[git] GpgOL - branch, master, updated. gpgol-2.0.5-9-g39f1abc

by Andre Heinecke cvs at cvs.gnupg.org
Wed Jan 10 12:38:17 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  39f1abce90094bdbb03c38bb3aadf0db1d8147e6 (commit)
      from  08a7a0db7169ec6ab0abc2468fdcd16a8e06d4ce (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 39f1abce90094bdbb03c38bb3aadf0db1d8147e6
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Jan 10 12:32:16 2018 +0100

    Change PGP/Inline behavior
    
    * src/mail.cpp (Mail::append_to_inline_body): New.
    (Mail::inline_body_to_body): Put cached body into oom body.
    * src/mail.h: Update accordingly.
    * src/mailitem-events.cpp (EVENT_SINK_INVOKE): Call inline_body_to_body.
    * src/mimemaker.cpp (sink_string_write): New.
    (finalize_message): Don't change message class for inline.
    (create_top_encryption_header): No MIME header for inline.
    (mime_encrypt): Use sink_string_write if inline.
    
    --
    Instead of our nice trick to do the S/MIME to MIME conversion
    with a text/plain part we now update the body. This is because
    Exchange Online did not like our trick. The new code should
    be a bit more robust.
    
    And yes caching stuff in the mail object is my hammer.
    
    GnuPG-Bug-Id: T3662

diff --git a/src/mail.cpp b/src/mail.cpp
index 7f709eb..39342b1 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -2413,3 +2413,21 @@ Mail::take_cached_recipients()
   m_cached_recipients = nullptr;
   return ret;
 }
+
+void
+Mail::append_to_inline_body (const std::string &data)
+{
+  m_inline_body += data;
+}
+
+int
+Mail::inline_body_to_body()
+{
+  if (m_inline_body.empty())
+    {
+      return 0;
+    }
+  int ret = put_oom_string (m_mailitem, "Body", m_inline_body.c_str ());
+  m_inline_body = std::string();
+  return ret;
+}
diff --git a/src/mail.h b/src/mail.h
index 48141b3..42052e2 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -340,6 +340,13 @@ public:
 
   /** Check if the mail should be encrypted "inline" */
   bool should_inline_crypt () const {return m_do_inline;}
+
+  /** Append data to a cached inline body. Helper to do this
+     on MAPI level and later add it through OOM */
+  void append_to_inline_body (const std::string &data);
+
+  /** Set the inline body as OOM body property. */
+  int inline_body_to_body ();
 private:
   void update_categories ();
   void update_body ();
@@ -374,5 +381,6 @@ private:
   std::string m_orig_body;
   bool m_do_inline;
   bool m_is_gsuite; /* Are we on a gsuite account */
+  std::string m_inline_body;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index ae4aa66..88bac05 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -360,6 +360,14 @@ EVENT_SINK_INVOKE(MailItemEvents)
                 {
                   log_debug ("%s:%s: Body found after encryption %p.",
                             SRCNAME, __func__, m_object);
+                  if (m_mail->should_inline_crypt ())
+                    {
+                      if (m_mail->inline_body_to_body ())
+                        {
+                          log_debug ("%s:%s: Inline body to body failed %p.",
+                                    SRCNAME, __func__, m_object);
+                        }
+                    }
                   const auto body = m_mail->get_body();
                   if (body.size() > 10 && !strncmp (body.c_str(), "-----BEGIN", 10))
                     {
diff --git a/src/mimemaker.cpp b/src/mimemaker.cpp
index fe8d4b5..057df95 100644
--- a/src/mimemaker.cpp
+++ b/src/mimemaker.cpp
@@ -95,6 +95,14 @@ sink_std_write (sink_t sink, const void *data, size_t datalen)
   return 0;
 }
 
+int
+sink_string_write (sink_t sink, const void *data, size_t datalen)
+{
+  Mail *mail = static_cast<Mail *>(sink->cb_data);
+  mail->append_to_inline_body (std::string((char*)data, datalen));
+  return 0;
+}
+
 /* Write method used with a sink_t that contains a file object.  */
 int
 sink_file_write (sink_t sink, const void *data, size_t datalen)
@@ -1139,7 +1147,7 @@ static int
 finalize_message (LPMESSAGE message, mapi_attach_item_t *att_table,
                   protocol_t protocol, int encrypt, bool is_inline = false)
 {
-  HRESULT hr;
+  HRESULT hr = 0;
   SPropValue prop;
   SPropTagArray proparray;
 
@@ -1154,7 +1162,13 @@ finalize_message (LPMESSAGE message, mapi_attach_item_t *att_table,
       prop.Value.lpszA = strdup ("IPM.Note.InfoPathForm.GpgOLS.SMIME.MultipartSigned");
     }
 
-  hr = message->SetProps(1, &prop, NULL);
+  if (!is_inline)
+    {
+      /* For inline we stick with IPM.Note because Exchange Online would
+         error out if we tried our S/MIME conversion trick with a text
+         plain message */
+      hr = message->SetProps(1, &prop, NULL);
+    }
   xfree(prop.Value.lpszA);
   if (hr)
     {
@@ -1875,6 +1889,10 @@ create_top_encryption_header (sink_t sink, protocol_t protocol, char *boundary,
   if (is_inline)
     {
       *boundary = 0;
+      rc = 0;
+      /* This would be nice and worked for Google Sync but it failed
+         for Microsoft Exchange Online *sigh* so we put the body
+         instead into the oom body property and stick with IPM Note.
       rc = write_multistring (sink,
                               "MIME-Version: 1.0\r\n"
                               "Content-Type: text/plain;\r\n"
@@ -1882,6 +1900,7 @@ create_top_encryption_header (sink_t sink, protocol_t protocol, char *boundary,
                               "Content-Transfer-Encoding: 7BIT\r\n"
                               "\r\n",
                               NULL);
+     */
     }
   else if (protocol == PROTOCOL_SMIME)
     {
@@ -1939,7 +1958,7 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
 {
   int result = -1;
   int rc;
-  LPATTACH attach;
+  LPATTACH attach = nullptr;
   struct sink_s sinkmem;
   sink_t sink = &sinkmem;
   struct sink_s encsinkmem;
@@ -1955,10 +1974,6 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
   memset (sink, 0, sizeof *sink);
   memset (encsink, 0, sizeof *encsink);
 
-  attach = create_mapi_attachment (message, sink);
-  if (!attach)
-    return -1;
-
   /* Get the attachment info and the body.  We need to do this before
      creating the engine's filter because sending the cancel to
      the engine with nothing for the engine to process.  Will result
@@ -1999,6 +2014,18 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
       is_inline = false;
     }
 
+  if (!is_inline || !mail)
+    {
+      attach = create_mapi_attachment (message, sink);
+      if (!attach)
+        return -1;
+    }
+  else
+    {
+      sink->cb_data = mail;
+      sink->writefnc = sink_string_write;
+    }
+
   /* Prepare the encryption.  We do this early as it is quite common
      that some recipient keys are not available and thus the
      encryption will fail early. */
@@ -2081,7 +2108,7 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
   if (*boundary && (rc = write_boundary (sink, boundary, 1)))
     goto failure;
 
-  if (close_mapi_attachment (&attach, sink))
+  if (attach && close_mapi_attachment (&attach, sink))
     goto failure;
 
   if (finalize_message (message, att_table, protocol, 1, is_inline))
@@ -2091,7 +2118,10 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
 
  failure:
   engine_cancel (filter);
-  cancel_mapi_attachment (&attach, sink);
+  if (attach)
+    {
+      cancel_mapi_attachment (&attach, sink);
+    }
   xfree (body);
   mapi_release_attach_table (att_table);
   xfree (my_sender);

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

Summary of changes:
 src/mail.cpp            | 18 ++++++++++++++++++
 src/mail.h              |  8 ++++++++
 src/mailitem-events.cpp |  8 ++++++++
 src/mimemaker.cpp       | 48 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 73 insertions(+), 9 deletions(-)


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




More information about the Gnupg-commits mailing list