[git] GpgOL - branch, master, updated. gpgol-1.2.0-78-ga3fba91

by Andre Heinecke cvs at cvs.gnupg.org
Fri Oct 30 16:49:16 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  a3fba91652d00c1f38bdf30e2028ddc4ac7fe9ab (commit)
       via  8d8f8c604dffd08d95a100524d88d8d72c15a0fc (commit)
      from  9207e8fb039b4dd4fc9c8e924f46fe9e1f223da0 (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 a3fba91652d00c1f38bdf30e2028ddc4ac7fe9ab
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Oct 30 16:48:30 2015 +0100

    Release detached event sink.
    
    * src/mail.cpp (Mail::~Mail): Release detached mail event sink.

diff --git a/src/mail.cpp b/src/mail.cpp
index 67dfbd5..232183a 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -114,6 +114,7 @@ Mail::~Mail()
   std::map<LPDISPATCH, Mail *>::iterator it;
 
   detach_MailItemEvents_sink (m_event_sink);
+  m_event_sink->Release ();
 
   it = g_mail_map.find(m_mailitem);
   if (it != g_mail_map.end())

commit 8d8f8c604dffd08d95a100524d88d8d72c15a0fc
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Oct 30 16:41:07 2015 +0100

    Enable sender handling for Exchange Accounts
    
    * src/mail.cpp (Mail::update_sender): New. Updates sender address
      from OOM.
      (Mail::get_sender): New. Access the sender.
      (Mail::do_crypt): Pass sender to crypto functions.
    * src/mail.h: Update accordingly.
    * src/mailitem-events.cpp (EVENT_SINK_INVOKE): Update sender on send
      event.
    * src/message.cpp, src/message.h, src/mimemaker.c, src/mimemaker.h:
      Add optional sender parameter to crypto functions and use it.
    
    --
    In the after write event we can't use OOM methods so we can't look
    up the sender over the session. This makes it neccessary to save
    the sender address beforehand as I could not find any way to get this
    information through MAPI (probably over the MAPISession).

diff --git a/src/mail.cpp b/src/mail.cpp
index 1e7d9bc..67dfbd5 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -63,7 +63,8 @@ Mail::Mail (LPDISPATCH mailitem) :
     m_mailitem(mailitem),
     m_processed(false),
     m_needs_wipe(false),
-    m_crypt_successful(false)
+    m_crypt_successful(false),
+    m_sender(NULL)
 {
   if (get_mail_for_item (mailitem))
     {
@@ -222,17 +223,17 @@ Mail::do_crypto ()
       log_debug ("%s:%s: Sign / Encrypting message",
                  SRCNAME, __func__);
       err = message_sign_encrypt (message, PROTOCOL_UNKNOWN,
-                                  NULL);
+                                  NULL, get_sender ());
     }
   else if (flags == 2)
     {
       err = message_sign (message, PROTOCOL_UNKNOWN,
-                          NULL);
+                          NULL, get_sender ());
     }
   else if (flags == 1)
     {
       err = message_encrypt (message, PROTOCOL_UNKNOWN,
-                             NULL);
+                             NULL, get_sender ());
     }
   else
     {
@@ -280,3 +281,38 @@ Mail::wipe ()
   m_needs_wipe = false;
   return 0;
 }
+
+int
+Mail::update_sender ()
+{
+  LPDISPATCH sender = NULL;
+  sender = get_oom_object (m_mailitem, "Session.CurrentUser");
+
+  xfree (m_sender);
+
+  if (!sender)
+    {
+      log_error ("%s:%s: Failed to get sender object.",
+                 SRCNAME, __func__);
+      return -1;
+    }
+  m_sender = get_pa_string (sender, PR_SMTP_ADDRESS_DASL);
+
+  if (!m_sender)
+    {
+      log_error ("%s:%s: Failed to get smtp address of sender.",
+                 SRCNAME, __func__);
+      return -1;
+    }
+  return 0;
+}
+
+const char *
+Mail::get_sender ()
+{
+  if (!m_sender)
+    {
+      update_sender();
+    }
+  return m_sender;
+}
diff --git a/src/mail.h b/src/mail.h
index 019e9bb..fc9ca21 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -96,12 +96,30 @@ public:
    * @returns 0 on success; */
   int wipe ();
 
+  /** @brief update the sender address.
+   *
+   * For Exchange 2013 at least we don't have any other way to get the
+   * senders SMTP address then through the object model. So we have to
+   * store the sender address for later events that do not allow us to
+   * access the OOM but enable us to work with the underlying MAPI structure.
+   *
+   * @returns 0 on success */
+  int update_sender ();
+
+  /** @brief get sender SMTP address (UTF-8 encoded).
+   *
+   * If the sender address has not been set through update_sender this
+   * calls update_sender before returning the sender.
+   *
+   * @returns A reference to the utf8 sender address. Or NULL. */
+  const char *get_sender ();
+
 private:
   LPDISPATCH m_mailitem;
   LPDISPATCH m_event_sink;
-  char * m_sender_addr;
   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. */
+  char *m_sender;
 };
 #endif // MAIL_H
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index e187d60..910eabf 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -173,6 +173,7 @@ EVENT_SINK_INVOKE(MailItemEvents)
                m_send_seen = false;
                break;
             }
+          m_mail->update_sender ();
           m_send_seen = true;
           log_debug ("%s:%s: Message %p cancelling send to let us do crypto.",
                      SRCNAME, __func__, m_object);
diff --git a/src/message.cpp b/src/message.cpp
index 34dd48f..7ddd896 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -1213,7 +1213,8 @@ release_recipient_array (char **recipients)
 
 
 static int
-sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd, int signflag)
+sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd, int signflag,
+              const char *sender)
 {
   gpg_error_t err;
   char **recipients;
@@ -1229,9 +1230,11 @@ sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd, int signflag)
   else
     {
       if (signflag)
-        err = mime_sign_encrypt (message, hwnd, protocol, recipients);
+        err = mime_sign_encrypt (message, hwnd, protocol, recipients,
+                                 sender);
       else
-        err = mime_encrypt (message, hwnd, protocol, recipients);
+        err = mime_encrypt (message, hwnd, protocol, recipients,
+                            sender);
       if (gpg_err_code (err) == GPG_ERR_NO_DATA)
         {
           MessageBox (hwnd, _("Encrypting or signing an empty message "
@@ -1254,11 +1257,12 @@ sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd, int signflag)
 
 /* Sign the MESSAGE.  */
 int 
-message_sign (LPMESSAGE message, protocol_t protocol, HWND hwnd)
+message_sign (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+              const char *sender)
 {
   gpg_error_t err;
 
-  err = mime_sign (message, hwnd, protocol);
+  err = mime_sign (message, hwnd, protocol, sender);
   if (gpg_err_code (err) == GPG_ERR_NO_DATA)
     {
       MessageBox (hwnd, _("Encrypting or signing an empty message "
@@ -1280,17 +1284,19 @@ message_sign (LPMESSAGE message, protocol_t protocol, HWND hwnd)
 
 /* Encrypt the MESSAGE.  */
 int 
-message_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd)
+message_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+                 const char *sender)
 {
-  return sign_encrypt (message, protocol, hwnd, 0);
+  return sign_encrypt (message, protocol, hwnd, 0, sender);
 }
 
 
 /* Sign+Encrypt the MESSAGE.  */
 int 
-message_sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd)
+message_sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+                      const char *sender)
 {
-  return sign_encrypt (message, protocol, hwnd, 1);
+  return sign_encrypt (message, protocol, hwnd, 1, sender);
 }
 
 
diff --git a/src/message.h b/src/message.h
index 7331e99..cd743bb 100644
--- a/src/message.h
+++ b/src/message.h
@@ -34,9 +34,12 @@ int message_verify (LPMESSAGE message, msgtype_t msgtype, int force,
                     HWND hwnd);
 int message_decrypt (LPMESSAGE message, msgtype_t msgtype, int force, 
                      HWND hwnd);
-int message_sign (LPMESSAGE message, protocol_t protocol, HWND hwnd);
-int message_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd);
-int message_sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd);
+int message_sign (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+                  const char *sender = NULL);
+int message_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+                     const char *sender = NULL);
+int message_sign_encrypt (LPMESSAGE message, protocol_t protocol, HWND hwnd,
+                          const char *sender = NULL);
 
 
 #endif /*MESSAGE_H*/
diff --git a/src/mimemaker.c b/src/mimemaker.c
index 6ddb19d..0d4ddee 100644
--- a/src/mimemaker.c
+++ b/src/mimemaker.c
@@ -1155,7 +1155,7 @@ create_top_signing_header (char *buffer, size_t buflen, protocol_t protocol,
 static int
 do_mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
               mapi_attach_item_t **r_att_table, sink_t tmpsink,
-              unsigned int session_number)
+              unsigned int session_number, const char *sender)
 {
   int result = -1;
   int rc;
@@ -1172,7 +1172,7 @@ do_mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
   char top_header[BOUNDARYSIZE+200];
   engine_filter_t filter = NULL;
   struct databuf_s sigbuffer;
-  char *sender = NULL;
+  char *my_sender = NULL;
 
   *r_att_table = NULL;
 
@@ -1222,8 +1222,11 @@ do_mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
       }
     }
 
-  sender = mapi_get_sender (message);
-  if (engine_sign_start (filter, hwnd, protocol, sender, &protocol))
+  if (sender)
+    my_sender = xstrdup (sender);
+  else
+    my_sender = mapi_get_sender (message);
+  if (engine_sign_start (filter, hwnd, protocol, my_sender, &protocol))
     goto failure;
 
   protocol = check_protocol (protocol);
@@ -1402,7 +1405,7 @@ do_mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
   else
     *r_att_table = att_table;
   xfree (sigbuffer.buf);
-  xfree (sender);
+  xfree (my_sender);
   return result;
 }
 
@@ -1414,13 +1417,14 @@ do_mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
    keep the original message intact but there is no 100% guarantee for
    it. */
 int
-mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol)
+mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
+           const char *sender)
 {
   int result = -1;
   mapi_attach_item_t *att_table;
 
   result = do_mime_sign (message, hwnd, protocol, &att_table, 0,
-                         engine_new_session_number ());
+                         engine_new_session_number (), sender);
   if (!result)
     {
       if (!finalize_message (message, att_table, protocol, 0))
@@ -1604,7 +1608,8 @@ create_top_encryption_header (sink_t sink, protocol_t protocol, char *boundary)
 /* Encrypt the MESSAGE.  */
 int
 mime_encrypt (LPMESSAGE message, HWND hwnd,
-              protocol_t protocol, char **recipients)
+              protocol_t protocol, char **recipients,
+              const char *sender)
 {
   int result = -1;
   int rc;
@@ -1619,7 +1624,7 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
   char *body = NULL;
   int n_att_usable;
   engine_filter_t filter = NULL;
-  char *sender = NULL;
+  char *my_sender = NULL;
 
   memset (sink, 0, sizeof *sink);
   memset (encsink, 0, sizeof *encsink);
@@ -1662,9 +1667,12 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
     xfree (tmp);
   }
 
-  sender = mapi_get_sender (message);
+  if (sender)
+    my_sender = xstrdup (sender);
+  else
+    my_sender = mapi_get_sender (message);
   if (engine_encrypt_prepare (filter, hwnd, protocol, 0,
-                              sender, recipients, &protocol))
+                              my_sender, recipients, &protocol))
     goto failure;
   if (engine_encrypt_start (filter, 0))
     goto failure;
@@ -1743,7 +1751,7 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
   cancel_mapi_attachment (&attach, sink);
   xfree (body);
   mapi_release_attach_table (att_table);
-  xfree (sender);
+  xfree (my_sender);
   return result;
 }
 
@@ -1753,7 +1761,8 @@ mime_encrypt (LPMESSAGE message, HWND hwnd,
 /* Sign and Encrypt the MESSAGE.  */
 int
 mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
-                   protocol_t protocol, char **recipients)
+                   protocol_t protocol, char **recipients,
+                   const char *sender)
 {
   int result = -1;
   int rc = 0;
@@ -1770,7 +1779,7 @@ mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
   mapi_attach_item_t *att_table = NULL;
   engine_filter_t filter = NULL;
   unsigned int session_number;
-  char *sender = NULL;
+  char *my_sender = NULL;
 
   memset (sink, 0, sizeof *sink);
   memset (encsink, 0, sizeof *encsink);
@@ -1842,10 +1851,13 @@ mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
     xfree (tmp);
   }
 
-  sender = mapi_get_sender (message);
+  if (sender)
+    my_sender = xstrdup (sender);
+  else
+    my_sender = mapi_get_sender (message);
   if ((rc=engine_encrypt_prepare (filter, hwnd,
                                   protocol, ENGINE_FLAG_SIGN_FOLLOWS,
-                                  sender, recipients, &protocol)))
+                                  my_sender, recipients, &protocol)))
     goto failure;
 
   protocol = check_protocol (protocol);
@@ -1859,7 +1871,7 @@ mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
      the signature.  Note that the protocol to use is taken from the
      encryption operation. */
   if (do_mime_sign (message, hwnd, protocol, &att_table, tmpsink,
-                    session_number))
+                    session_number, sender))
     goto failure;
 
   /* Now send the actual ENCRYPT command.  This split up between
@@ -1958,6 +1970,6 @@ mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
   if (tmpstream)
     IStream_Release (tmpstream);
   mapi_release_attach_table (att_table);
-  xfree (sender);
+  xfree (my_sender);
   return result;
 }
diff --git a/src/mimemaker.h b/src/mimemaker.h
index fa7eca7..187e80e 100644
--- a/src/mimemaker.h
+++ b/src/mimemaker.h
@@ -44,11 +44,14 @@ struct sink_s
 /*   } b64; */
 };
 
-int mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol);
+int mime_sign (LPMESSAGE message, HWND hwnd, protocol_t protocol,
+               const char *sender);
 int mime_encrypt (LPMESSAGE message, HWND hwnd,
-                  protocol_t protocol, char **recipients);
+                  protocol_t protocol, char **recipients,
+                  const char *sender);
 int mime_sign_encrypt (LPMESSAGE message, HWND hwnd,
-                       protocol_t protocol, char **recipients);
+                       protocol_t protocol, char **recipients,
+                       const char *sender);
 int sink_std_write (sink_t sink, const void *data, size_t datalen);
 int sink_file_write (sink_t sink, const void *data, size_t datalen);
 int sink_encryption_write (sink_t encsink, const void *data, size_t datalen);

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

Summary of changes:
 src/mail.cpp            | 45 +++++++++++++++++++++++++++++++++++++++++----
 src/mail.h              | 20 +++++++++++++++++++-
 src/mailitem-events.cpp |  1 +
 src/message.cpp         | 24 +++++++++++++++---------
 src/message.h           |  9 ++++++---
 src/mimemaker.c         | 48 ++++++++++++++++++++++++++++++------------------
 src/mimemaker.h         |  9 ++++++---
 7 files changed, 118 insertions(+), 38 deletions(-)


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




More information about the Gnupg-commits mailing list