[git] GpgOL - branch, async-enc, updated. gpgol-2.0.6-41-gc513358
by Andre Heinecke
cvs at cvs.gnupg.org
Fri Feb 16 16:31:39 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 c5133586929626685ac6ceef57e775ac7761cdb0 (commit)
via d483d0d02d99cd4b5b76213e17876e00bd6d6268 (commit)
via 087562b5f4f6f72143efa59b9aea4582b1a10028 (commit)
via 5c188d6a800675dc7b9017c257a0f2b757b9eb71 (commit)
from 573661d09c07b67680be17418e13fcfa960c4a2d (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 c5133586929626685ac6ceef57e775ac7761cdb0
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Feb 16 16:30:25 2018 +0100
Implement WKS-Client request sending
* src/wks-helper.cpp (WKSHelper::send_mail): New.
* src/wks-helper.h: Update accordingly.
--
This basically works. But there is a big issue. Somehow
the SendUsingAccount setting does not work so it always
sends out the mails with the default account.
diff --git a/src/wks-helper.cpp b/src/wks-helper.cpp
index 49e6dbe..3dbc31d 100644
--- a/src/wks-helper.cpp
+++ b/src/wks-helper.cpp
@@ -24,8 +24,10 @@
#include "oomhelp.h"
#include "windowmessages.h"
#include "overlay.h"
+#include "mail.h"
#include <map>
+#include <sstream>
#include <unistd.h>
@@ -299,8 +301,8 @@ WKSHelper::notify (const char *cBox) const
void
WKSHelper::start_publish (const std::string &mbox) const
{
- Overlay (get_active_hwnd (),
- std::string (_("Creating registration request...")));
+// Overlay (get_active_hwnd (),
+// std::string (_("Creating registration request...")));
log_debug ("%s:%s: Start publish for '%s'",
SRCNAME, __func__, mbox.c_str ());
@@ -354,7 +356,7 @@ WKSHelper::start_publish (const std::string &mbox) const
SRCNAME, __func__, err.code(), err.asString());
return;
}
- auto data = mystdout.toString ();
+ const auto data = mystdout.toString ();
if (data.empty ())
{
@@ -367,6 +369,9 @@ WKSHelper::start_publish (const std::string &mbox) const
log_debug ("%s:%s: WKS client: returned '%s'",
SRCNAME, __func__, data.c_str ());
+
+ send_mail (data);
+
return;
}
@@ -387,3 +392,82 @@ WKSHelper::update_state (const std::string &mbox, WKSState state) const
}
gpgrt_lock_unlock (&wks_lock);
}
+
+void
+WKSHelper::send_mail (const std::string &mimeData) const
+{
+ std::istringstream ss(mimeData);
+
+ std::string from;
+ std::string to;
+ std::string subject;
+ std::string withoutHeaders;
+
+ std::getline (ss, from);
+ std::getline (ss, to);
+ std::getline (ss, subject);
+
+ if (from.compare (0, 6, "From: ") || to.compare (0, 4, "To: "),
+ subject.compare (0, 9, "Subject: "))
+ {
+ log_error ("%s:%s: Invalid mime data..",
+ SRCNAME, __func__);
+ return;
+ }
+
+ std::getline (ss, withoutHeaders, '\0');
+
+ from.erase (0, 6);
+ to.erase (0, 4);
+ subject.erase (0, 9);
+
+ rtrim (from);
+ rtrim (to);
+ rtrim (subject);
+
+ LPDISPATCH mail = create_mail ();
+
+ if (!mail)
+ {
+ log_error ("%s:%s: Failed to create mail for request.",
+ SRCNAME, __func__);
+ return;
+ }
+
+ if (put_oom_string (mail, "Subject", subject.c_str ()))
+ {
+ TRACEPOINT;
+ gpgol_release (mail);
+ return;
+ }
+
+ if (put_oom_string (mail, "To", to.c_str ()))
+ {
+ TRACEPOINT;
+ gpgol_release (mail);
+ return;
+ }
+
+ LPDISPATCH account = get_account_for_mail (from.c_str ());
+ if (account)
+ {
+ log_debug ("%s:%s: Changing account.",
+ SRCNAME, __func__);
+ put_oom_disp (mail, "SendUsingAccount", account);
+ }
+
+ /* Now we have a problem. The created LPDISPATCH pointer has
+ a different value then the one with which we saw the ItemLoad
+ event. But we want to get the mail object. So,.. surpise
+ a Hack! :-) */
+ auto last_mail = Mail::get_last_mail ();
+
+ last_mail->set_override_mime_data (mimeData);
+ last_mail->set_crypt_state (Mail::NeedsSecondAfterWrite);
+
+ invoke_oom_method (mail, "Save", NULL);
+ invoke_oom_method (mail, "Send", NULL);
+
+ log_debug ("%s:%s: Publish successful",
+ SRCNAME, __func__);
+}
diff --git a/src/wks-helper.h b/src/wks-helper.h
index 2f55a3f..efd36f5 100644
--- a/src/wks-helper.h
+++ b/src/wks-helper.h
@@ -88,6 +88,9 @@ public:
/** Update or insert a state in the static maps. */
void update_state (const std::string &mbox, WKSState state) const;
+ /** Create / Build Mail */
+ void send_mail (const std::string &mimeData) const;
+
private:
time_t get_check_time (const std::string &mbox) const;
commit d483d0d02d99cd4b5b76213e17876e00bd6d6268
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Feb 16 16:29:11 2018 +0100
Add oom helper to create mail and handle accounts
* src/oomhelp.cpp (create_mail): Create a new mail.
(get_account_for_mail): Get an account for a mail address.
(put_oom_disp): New.
* src/oomhelp.h: Update accordingly.
diff --git a/src/oomhelp.cpp b/src/oomhelp.cpp
index ce444d7..a72bace 100644
--- a/src/oomhelp.cpp
+++ b/src/oomhelp.cpp
@@ -533,6 +533,40 @@ put_oom_string (LPDISPATCH pDisp, const char *name, const char *string)
return 0;
}
+/* Set the property NAME to DISP. */
+int
+put_oom_disp (LPDISPATCH pDisp, const char *name, LPDISPATCH disp)
+{
+ HRESULT hr;
+ DISPID dispid_put = DISPID_PROPERTYPUT;
+ DISPID dispid;
+ DISPPARAMS dispparams;
+ VARIANT aVariant[1];
+ EXCEPINFO execpinfo;
+
+ init_excepinfo (&execpinfo);
+ dispid = lookup_oom_dispid (pDisp, name);
+ if (dispid == DISPID_UNKNOWN)
+ return -1;
+
+ dispparams.rgvarg = aVariant;
+ dispparams.rgvarg[0].vt = VT_DISPATCH | VT_BYREF;
+ dispparams.rgvarg[0].pdispVal = disp;
+ dispparams.cArgs = 1;
+ dispparams.rgdispidNamedArgs = &dispid_put;
+ dispparams.cNamedArgs = 1;
+ hr = pDisp->Invoke (dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
+ DISPATCH_PROPERTYPUT, &dispparams,
+ NULL, &execpinfo, NULL);
+ if (hr != S_OK)
+ {
+ log_debug ("%s:%s: Putting '%s' failed: %#lx",
+ SRCNAME, __func__, name, hr);
+ dump_excepinfo (execpinfo);
+ return -1;
+ }
+ return 0;
+}
/* Get the boolean property NAME of the object PDISP. Returns False if
not found or if it is not a boolean property. */
@@ -1777,3 +1811,92 @@ get_active_hwnd ()
return hwnd;
}
+
+LPDISPATCH
+create_mail ()
+{
+ LPDISPATCH app = GpgolAddin::get_instance ()->get_application ();
+
+ if (!app)
+ {
+ TRACEPOINT;
+ return nullptr;
+ }
+
+ VARIANT var;
+ VariantInit (&var);
+ VARIANT argvars[1];
+ DISPPARAMS args;
+ VariantInit (&argvars[0]);
+ argvars[0].vt = VT_I2;
+ argvars[0].intVal = 0;
+ args.cArgs = 1;
+ args.cNamedArgs = 0;
+ args.rgvarg = argvars;
+
+ LPDISPATCH ret = nullptr;
+
+ if (invoke_oom_method_with_parms (app, "CreateItem", &var, &args))
+ {
+ log_error ("%s:%s: Failed to create mailitem.",
+ SRCNAME, __func__);
+ return ret;
+ }
+
+ ret = var.pdispVal;
+ return ret;
+}
+
+LPDISPATCH
+get_account_for_mail (const char *mbox)
+{
+ LPDISPATCH app = GpgolAddin::get_instance ()->get_application ();
+
+ if (!app)
+ {
+ TRACEPOINT;
+ return nullptr;
+ }
+
+ LPDISPATCH accounts = get_oom_object (app, "Session.Accounts");
+
+ if (!accounts)
+ {
+ TRACEPOINT;
+ return nullptr;
+ }
+
+ int count = get_oom_int (accounts, "Count");
+ for (int i = 1; i <= count; i++)
+ {
+ std::string item = std::string ("Item(") + std::to_string (i) + ")";
+
+ LPDISPATCH account = get_oom_object (accounts, item.c_str ());
+
+ if (!account)
+ {
+ TRACEPOINT;
+ continue;
+ }
+ char *smtpAddr = get_oom_string (account, "SmtpAddress");
+
+ if (!smtpAddr)
+ {
+ TRACEPOINT;
+ continue;
+ }
+ if (!stricmp (mbox, smtpAddr))
+ {
+ gpgol_release (accounts);
+ xfree (smtpAddr);
+ return account;
+ }
+ xfree (smtpAddr);
+ }
+ gpgol_release (accounts);
+
+ log_error ("%s:%s: Failed to find account for '%s'.",
+ SRCNAME, __func__, mbox);
+
+ return nullptr;
+}
diff --git a/src/oomhelp.h b/src/oomhelp.h
index 1008860..0c8789c 100644
--- a/src/oomhelp.h
+++ b/src/oomhelp.h
@@ -141,6 +141,9 @@ int put_oom_int (LPDISPATCH pDisp, const char *name, int value);
/* Set the property NAME to STRING. */
int put_oom_string (LPDISPATCH pDisp, const char *name, const char *string);
+/* Set the property NAME to DISP. */
+int put_oom_disp (LPDISPATCH pDisp, const char *name, LPDISPATCH value);
+
/* Get the boolean property NAME of the object PDISP. */
int get_oom_bool (LPDISPATCH pDisp, const char *name);
@@ -320,6 +323,11 @@ get_unique_id (LPDISPATCH mail, int create, const char* uuid);
through FindWindow and the caption. Does not use IOleWindow
because that was unreliable somhow. */
HWND get_active_hwnd (void);
+
+/* Create a new mailitem and return it */
+LPDISPATCH create_mail (void);
+
+LPDISPATCH get_account_for_mail (const char *mbox);
#ifdef __cplusplus
}
#endif
commit 087562b5f4f6f72143efa59b9aea4582b1a10028
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Feb 16 16:27:38 2018 +0100
Make it possible to get the last created mail
* src/mail.cpp (Mail::get_last_mail): New.
* src/mail.h: Update accordingly.
--
This makes it easy to get a reference to our internal Mail
object for example if a mail was created programatically
as the returned DISPATCH pointer differ.
diff --git a/src/mail.cpp b/src/mail.cpp
index 6d8a0f4..00b42d3 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -62,6 +62,8 @@ static std::map<LPDISPATCH, Mail*> g_mail_map;
static std::map<std::string, Mail*> g_uid_map;
static std::set<std::string> uids_searched;
+static Mail *s_last_mail;
+
static bool
in_de_vs_mode()
{
@@ -159,6 +161,7 @@ Mail::Mail (LPDISPATCH mailitem) :
return;
}
g_mail_map.insert (std::pair<LPDISPATCH, Mail *> (mailitem, this));
+ s_last_mail = this;
}
GPGRT_LOCK_DEFINE(dtor_lock);
@@ -2701,3 +2704,14 @@ Mail::check_inline_response ()
return m_is_inline_response;
}
+
+// static
+Mail *
+Mail::get_last_mail ()
+{
+ if (!s_last_mail || !is_valid_ptr (s_last_mail))
+ {
+ s_last_mail = nullptr;
+ }
+ return s_last_mail;
+}
diff --git a/src/mail.h b/src/mail.h
index 929c509..53c0e23 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -86,6 +86,12 @@ public:
*/
static Mail* get_mail_for_uuid (const char *uuid);
+ /** @brief Get the last created mail.
+
+ @returns A reference to the last created mail or null.
+ */
+ static Mail* get_last_mail ();
+
/** @brief looks for existing Mail objects.
@returns A reference to an existing mailitem or NULL in case none
commit 5c188d6a800675dc7b9017c257a0f2b757b9eb71
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Feb 16 16:25:32 2018 +0100
Add possibility to override mime struct for mail
* src/cryptcontroller.cpp (update_mail_mapi): Prefer override mime.
* src/mail.cpp (Mail::set_override_mime, Mail::get_override_mime):
New.
(Mail::update_crypt_mapi): Create dummy crypter for overidden mime.
diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index a510978..e2e4570 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -822,7 +822,13 @@ CryptController::update_mail_mapi ()
PROTOCOL_SMIME :
PROTOCOL_OPENPGP;
int rc = 0;
- if (m_sign && m_encrypt)
+ /* Do we have override MIME ? */
+ const auto overrideMime = m_mail->get_override_mime_data ();
+ if (!overrideMime.empty())
+ {
+ rc = write_string (sink, overrideMime.c_str ());
+ }
+ else if (m_sign && m_encrypt)
{
rc = create_encrypt_attach (sink, protocol, m_output);
}
diff --git a/src/mail.cpp b/src/mail.cpp
index c86eac5..6d8a0f4 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -2561,10 +2561,21 @@ Mail::update_crypt_mapi()
}
if (!m_crypter)
{
- log_error ("%s:%s: No crypter.",
- SRCNAME, __func__);
- m_crypt_state = NoCryptMail;
- return;
+ if (!m_mime_data.empty())
+ {
+ log_debug ("%s:%s: Have override mime data creating dummy crypter",
+ SRCNAME, __func__);
+ m_crypter = std::shared_ptr <CryptController> (new CryptController (this, false,
+ false,
+ false, GpgME::UnknownProtocol));
+ }
+ else
+ {
+ log_error ("%s:%s: No crypter.",
+ SRCNAME, __func__);
+ m_crypt_state = NoCryptMail;
+ return;
+ }
}
if (m_crypter->update_mail_mapi ())
diff --git a/src/mail.h b/src/mail.h
index acc783b..929c509 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -421,6 +421,13 @@ public:
on error. */
void reset_crypter () { m_crypter = nullptr; }
+ /** Set special crypto mime data that should be used as the
+ mime structure when sending. */
+ void set_override_mime_data (const std::string &data) {m_mime_data = data;}
+
+ /** Get the mime data that should be used when sending. */
+ std::string get_override_mime_data () const { return m_mime_data; }
+
private:
void update_categories ();
void update_body ();
@@ -460,5 +467,6 @@ private:
CryptState m_crypt_state;
HWND m_window;
bool m_is_inline_response;
+ std::string m_mime_data;
};
#endif // MAIL_H
-----------------------------------------------------------------------
Summary of changes:
src/cryptcontroller.cpp | 8 +++-
src/mail.cpp | 33 +++++++++++--
src/mail.h | 14 ++++++
src/oomhelp.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++++++
src/oomhelp.h | 8 ++++
src/wks-helper.cpp | 90 +++++++++++++++++++++++++++++++++--
src/wks-helper.h | 3 ++
7 files changed, 271 insertions(+), 8 deletions(-)
hooks/post-receive
--
GnuPG extension for MS Outlook
http://git.gnupg.org
More information about the Gnupg-commits
mailing list