[git] GpgOL - branch, async-enc, updated. gpgol-2.0.6-5-gf622470

by Andre Heinecke cvs at cvs.gnupg.org
Tue Jan 30 15:21:29 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, async-enc has been updated
       via  f622470a3a291cd8d39e9dc45fa5d6496e66089d (commit)
      from  e789048f47fccab444df477f6e82ece69fa2a8b4 (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 f622470a3a291cd8d39e9dc45fa5d6496e66089d
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Tue Jan 30 15:17:48 2018 +0100

    Make MIME encrypt work in the new way
    
    * src/cryptcontroller.cpp (CryptController::update_mail_mapi):
    Do actual update.
    (create_encrypt_attach): Helper to set up the right attachment.
    (write_data): Helper to write GpgME::Data to a sink.
    * src/mail.cpp (Mail::update_crypt_mapi): Call update_mail_mapi.
    * src/mimemaker.cpp, src/mimemaker.h: Export some more helpers.

diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index ebb18bb..c950cdf 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -275,11 +275,127 @@ CryptController::do_crypto ()
   return 0;
 }
 
+static int
+write_data (sink_t sink, GpgME::Data &data)
+{
+  if (!sink || !sink->writefnc)
+    {
+      return -1;
+    }
+
+  char buf[4096];
+  size_t nread;
+  data.seek (0, SEEK_SET);
+  while ((nread = data.read (buf, 4096)) > 0)
+    {
+      sink->writefnc (sink, buf, nread);
+    }
+
+  return 0;
+}
+
+static int
+create_encrypt_attach (sink_t sink, protocol_t protocol,
+                       GpgME::Data &encryptedData)
+{
+  char boundary[BOUNDARYSIZE+1];
+  int rc = create_top_encryption_header (sink, protocol, boundary,
+                                         false);
+  // From here on use goto failure pattern.
+  if (rc)
+    {
+      log_error ("%s:%s: Failed to create top header.",
+                 SRCNAME, __func__);
+      return rc;
+    }
+
+  rc = write_data (sink, encryptedData);
+  if (rc)
+    {
+      log_error ("%s:%s: Failed to create top header.",
+                 SRCNAME, __func__);
+      return rc;
+    }
+
+  /* Write the final boundary (for OpenPGP) and finish the attachment.  */
+  if (*boundary && (rc = write_boundary (sink, boundary, 1)))
+    {
+      log_error ("%s:%s: Failed to write boundary.",
+                 SRCNAME, __func__);
+    }
+  return rc;
+}
+
 int
 CryptController::update_mail_mapi ()
 {
   log_debug ("%s:%s:", SRCNAME, __func__);
-  return 0;
+
+  if (m_inline)
+    {
+      // Nothing to do for inline.
+      return 0;
+    }
+
+  LPMESSAGE message = get_oom_base_message (m_mail->item());
+  if (!message)
+    {
+      log_error ("%s:%s: Failed to obtain message.",
+                 SRCNAME, __func__);
+      return -1;
+    }
+
+  mapi_attach_item_t *att_table = mapi_create_attach_table (message, 0);
+
+  // Set up the sink object for our MSOXSMIME attachment.
+  struct sink_s sinkmem;
+  sink_t sink = &sinkmem;
+  memset (sink, 0, sizeof *sink);
+  sink->cb_data = &m_input;
+  sink->writefnc = sink_data_write;
+
+  LPATTACH attach = create_mapi_attachment (message, sink);
+  if (!attach)
+    {
+      log_error ("%s:%s: Failed to create moss attach.",
+                 SRCNAME, __func__);
+      gpgol_release (message);
+      return -1;
+    }
+
+  protocol_t protocol = m_proto == GpgME::CMS ?
+                                   PROTOCOL_SMIME :
+                                   PROTOCOL_OPENPGP;
+  int rc = 0;
+  if (m_encrypt)
+    {
+      rc = create_encrypt_attach (sink, protocol, m_output);
+    }
+
+  // Close our attachment
+  if (!rc)
+    {
+      rc = close_mapi_attachment (&attach, sink);
+    }
+
+  // Set message class etc.
+  if (!rc)
+    {
+      rc = finalize_message (message, att_table, protocol, 1, false);
+    }
+
+  // only on error.
+  if (rc)
+    {
+      cancel_mapi_attachment (&attach, sink);
+    }
+
+  // cleanup
+  mapi_release_attach_table (att_table);
+  gpgol_release (attach);
+  gpgol_release (message);
+
+  return rc;
 }
 
 std::string
diff --git a/src/mail.cpp b/src/mail.cpp
index 27ec8ff..0b270e0 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -2510,7 +2510,32 @@ Mail::update_crypt_mapi()
 {
   log_debug ("%s:%s: Update crypt mapi",
              SRCNAME, __func__);
-  m_crypt_state = WantsSend;
+  if (m_crypt_state != NeedsUpdateInMAPI)
+    {
+      log_debug ("%s:%s: invalid state %i",
+                 SRCNAME, __func__, m_crypt_state);
+      return;
+    }
+  if (!m_crypter)
+    {
+      log_error ("%s:%s: No crypter.",
+                 SRCNAME, __func__);
+      m_crypt_state = NoCryptMail;
+      return;
+    }
+
+  if (m_crypter->update_mail_mapi ())
+    {
+      log_error ("%s:%s: Failed to update MAPI after crypt",
+                 SRCNAME, __func__);
+      m_crypt_state = NoCryptMail;
+    }
+  else
+    {
+      m_crypt_state = WantsSend;
+    }
+  // We don't need the crypter anymore.
+  m_crypter = nullptr;
 }
 
 void
diff --git a/src/mimemaker.cpp b/src/mimemaker.cpp
index 1f9de4e..d638fb2 100644
--- a/src/mimemaker.cpp
+++ b/src/mimemaker.cpp
@@ -152,7 +152,7 @@ check_protocol (protocol_t protocol)
    to is stored at STREAM and the attachment object itself is
    returned.  The caller needs to call SaveChanges.  Returns NULL on
    failure in which case STREAM will be set to NULL.  */
-static LPATTACH
+LPATTACH
 create_mapi_attachment (LPMESSAGE message, sink_t sink)
 {
   HRESULT hr;
@@ -304,7 +304,7 @@ write_multistring (sink_t sink, const char *text1, ...)
 
 /* Helper to write a boundary to the output sink.  The leading LF
    will be written as well.  */
-static int
+int
 write_boundary (sink_t sink, const char *boundary, int lastone)
 {
   int rc = write_string (sink, "\r\n--");
@@ -1084,7 +1084,7 @@ delete_all_attachments (LPMESSAGE message, mapi_attach_item_t *table)
    SINK needs to be passed as well and will also be closed.  Note that
    the address of ATTACH is expected so that the fucntion can set it
    to NULL. */
-static int
+int
 close_mapi_attachment (LPATTACH *attach, sink_t sink)
 {
   HRESULT hr;
@@ -1121,7 +1121,7 @@ close_mapi_attachment (LPATTACH *attach, sink_t sink)
    SINK needs to be passed as well and will also be closed.  Note that
    the address of ATTACH is expected so that the fucntion can set it
    to NULL. */
-static void
+void
 cancel_mapi_attachment (LPATTACH *attach, sink_t sink)
 {
   LPSTREAM stream = sink ? (LPSTREAM) sink->cb_data : NULL;
@@ -1143,9 +1143,9 @@ cancel_mapi_attachment (LPATTACH *attach, sink_t sink)
 
 
 /* Do the final processing for a message. */
-static int
+int
 finalize_message (LPMESSAGE message, mapi_attach_item_t *att_table,
-                  protocol_t protocol, int encrypt, bool is_inline = false)
+                  protocol_t protocol, int encrypt, bool is_inline)
 {
   HRESULT hr = 0;
   SPropValue prop;
@@ -1883,9 +1883,9 @@ sink_encryption_write_b64 (sink_t encsink, const void *data, size_t datalen)
 /* Helper from mime_encrypt.  BOUNDARY is a buffer of at least
    BOUNDARYSIZE+1 bytes which will be set on return from that
    function.  */
-static int
+int
 create_top_encryption_header (sink_t sink, protocol_t protocol, char *boundary,
-                              bool is_inline = false)
+                              bool is_inline)
 {
   int rc;
 
diff --git a/src/mimemaker.h b/src/mimemaker.h
index 2896a60..cbf83a8 100644
--- a/src/mimemaker.h
+++ b/src/mimemaker.h
@@ -76,6 +76,20 @@ int count_usable_attachments (mapi_attach_item_t *table);
 int add_body_and_attachments (sink_t sink, LPMESSAGE message,
                               mapi_attach_item_t *att_table, Mail *mail,
                               const char *body, int n_att_usable);
+int create_top_encryption_header (sink_t sink, protocol_t protocol, char *boundary,
+                              bool is_inline = false);
+
+/* Helper to write a boundary to the output sink.  The leading LF
+   will be written as well.  */
+int write_boundary (sink_t sink, const char *boundary, int lastone);
+
+LPATTACH create_mapi_attachment (LPMESSAGE message, sink_t sink);
+int close_mapi_attachment (LPATTACH *attach, sink_t sink);
+int finalize_message (LPMESSAGE message, mapi_attach_item_t *att_table,
+                      protocol_t protocol, int encrypt, bool is_inline = false);
+void cancel_mapi_attachment (LPATTACH *attach, sink_t sink);
+
+
 #ifdef __cplusplus
 }
 #endif

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

Summary of changes:
 src/cryptcontroller.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/mail.cpp            |  27 ++++++++++-
 src/mimemaker.cpp       |  16 +++----
 src/mimemaker.h         |  14 ++++++
 4 files changed, 165 insertions(+), 10 deletions(-)


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




More information about the Gnupg-commits mailing list