diff --git a/src/Makefile.am b/src/Makefile.am
index 06dfd33..5ec8e10 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,123 +1,124 @@
# Makefile.am - makefile for GPGol
# Copyright (C) 2005 g10 Code GmbH
# Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik
# Software engineering by Intevation GmbH
# Copyright (C) 2018 Intevation GmbH
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## Process this file with automake to produce Makefile.in
SUBDIRS = icons
bin_PROGRAMS = gpgol
EXTRA_DIST = \
versioninfo.rc.in mapi32.def Outlook.gpl \
dialogs.rc
EXEEXT = .dll
AM_CFLAGS = $(GPGME_CFLAGS) -shared
AM_CXXFLAGS = $(GPGME_CFLAGS) $(LIBASSUAN_CFLAGS) -shared -std=c++14
AM_CXXFLAGS += $(GPGMEPP_CXXFLAGS) -D_FILE_OFFSET_BITS=64
gpgol_SOURCES = \
addin-options.cpp addin-options.h \
addressbook.cpp addressbook.h \
application-events.cpp \
attachment.h attachment.cpp \
categorymanager.h categorymanager.cpp \
common.h common.cpp \
common_indep.h common_indep.c \
cpphelp.cpp cpphelp.h \
cryptcontroller.cpp cryptcontroller.h \
debug.h debug.cpp \
dialogs.h \
dispcache.h dispcache.cpp \
eventsink.h \
eventsinks.h \
explorer-events.cpp \
explorers-events.cpp \
filetype.c filetype.h \
folder-events.cpp \
gmime-table-private.h \
gpgoladdin.cpp gpgoladdin.h \
gpgol.def \
gpgol-ids.h \
keycache.cpp keycache.h \
mail.h mail.cpp \
mailitem-events.cpp \
main.c \
mapihelp.cpp mapihelp.h \
mapierr.cpp mapierr.h \
memdbg.cpp memdbg.h \
mimedataprovider.cpp mimedataprovider.h \
mimemaker.cpp mimemaker.h \
mlang-charset.cpp mlang-charset.h \
mymapi.h \
mymapitags.h \
olflange.cpp olflange.h \
oomhelp.cpp oomhelp.h \
overlay.cpp overlay.h \
parsecontroller.cpp parsecontroller.h \
parsetlv.h parsetlv.c \
recipient.h recipient.cpp \
+ recipientmanager.h recipientmanager.cpp \
resource.rc \
revert.cpp revert.h \
rfc2047parse.h rfc2047parse.c \
rfc822parse.c rfc822parse.h \
ribbon-callbacks.cpp ribbon-callbacks.h \
w32-gettext.cpp w32-gettext.h \
windowmessages.h windowmessages.cpp \
wks-helper.cpp wks-helper.h \
xmalloc.h
#treeview_SOURCES = treeview.c
# W32API 3.2 comes with an unusable libmapi32.a. We build our own
# version. Note the omission of -k (--kill-at) from the DLLTOOL
# command line. We also create our own virtual copies to the _static_
# versions of GPGME and gpg-error, because we want to link to them
# statically, and not dynamically (otherwise Outlook would not find
# them).
gpgol_DEPENDENCIES = libmapi32.a libgpg-error.a libgpgme.a libassuan.a libgpgmepp.a
if BUILD_W64
DLLTOOLFLAGS64=--as-flags=--64 -m i386:x86-64
endif
libmapi32.a: mapi32.def
$(DLLTOOL) $(DLLTOOLFLAGS64) --output-lib $@ --def $<
libgpg-error.a:
ln -s $$($(GPG_ERROR_CONFIG) --prefix)/lib/libgpg-error.a .
libgpgme.a:
ln -s $$($(GPGME_CONFIG) --prefix)/lib/libgpgme.a .
libassuan.a:
ln -s $$($(LIBASSUAN_CONFIG) --prefix)/lib/libassuan.a .
libgpgmepp.a:
ln -s $$($(GPGME_CONFIG) --prefix)/lib/libgpgmepp.a .
clean-local:
rm -f libmapi32.a libgpg-error.a libgpgme.a libassuan.a libgpgmepp.a
gpgol_LDFLAGS = -static-libgcc -static-libstdc++
gpgol_LDADD = $(srcdir)/gpgol.def \
-L . -lgpgmepp -lgpgme -lassuan -lgpg-error \
-lmapi32 -lshell32 -lgdi32 -lcomdlg32 \
-lole32 -loleaut32 -lws2_32 -ladvapi32 \
-luuid -lgdiplus -lrpcrt4
resource.o: resource.rc versioninfo.rc dialogs.rc dialogs.h
.rc.o:
$(WINDRES) -I $(srcdir) -I . -I .. `test -f '$<' || echo '$(srcdir)/'`$< $@
diff --git a/src/recipientmanager.cpp b/src/recipientmanager.cpp
new file mode 100644
index 0000000..836a8f6
--- /dev/null
+++ b/src/recipientmanager.cpp
@@ -0,0 +1,140 @@
+/* @file recipientmanager.cpp
+ * @brief Manage the recipients of a mail to send multiple mails to
+ * different recipients.
+ *
+ * Copyright (C) 2021 g10 Code GmbH
+ *
+ * This file is part of GpgOL.
+ *
+ * GpgOL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GpgOL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see .
+ */
+
+#include "config.h"
+#include "recipientmanager.h"
+#include "common.h"
+
+static std::vector
+getKeysForProtocol (const std::vector keys, GpgME::Protocol proto)
+{
+ std::vector ret;
+
+ std::copy_if (keys.begin(), keys.end(),
+ std::back_inserter (ret),
+ [proto] (const auto &k)
+ {
+ return k.protocol () == proto;
+ });
+
+ return ret;
+}
+
+RecipientManager::RecipientManager (const RecpList &recps,
+ const std::vector &signing_keys)
+{
+ TSTART;
+ log_dbg ("Recipient manager ctor");
+ Recipient::dump (recps);
+
+ if (signing_keys.size () > 2)
+ {
+ log_dbg ("Signing with multiple keys is not supported.");
+ for (const auto &key: signing_keys)
+ {
+ if (key.protocol () == GpgME::OpenPGP)
+ {
+ m_pgpSigKey = key;
+ }
+ else if (key.protocol () == GpgME::CMS)
+ {
+ m_cmsSigKey = key;
+ }
+ else
+ {
+ STRANGEPOINT;
+ }
+ }
+ }
+
+ if (!opt.splitBCCMails && !opt.combinedOpsEnabled)
+ {
+ /* Nothing to do */
+ m_recp_lists.push_back (recps);
+ TRETURN;
+ }
+
+ /* First collect all BCC recpients and put all others in a
+ list. */
+ Recipient originator;
+ RecpList normalRecps;
+ RecpList bccRecps;
+ for (const auto &recp: recps)
+ {
+ if (recp.type () == Recipient::olOriginator)
+ {
+ originator = recp;
+ normalRecps.push_back (recp);
+ }
+ else if (recp.type () == Recipient::olBCC && opt.splitBCCMails)
+ {
+ bccRecps.push_back (recp);
+ }
+ else
+ {
+ normalRecps.push_back (recp);
+ }
+ }
+
+ if (originator.isNull())
+ {
+ log_err ("Failed to find orginator");
+ TRETURN;
+ }
+
+ /* Split the normal recipients by protocol */
+ m_recp_lists.push_back (normalRecps);
+
+ /* For each BCC recipient also split by protocol */
+ log_dbg ("Splitting of %i BCC recipients.", (int) bccRecps.size());
+
+ for (const auto &recp: bccRecps)
+ {
+ RecpList list;
+ list.push_back (originator);
+ list.push_back (recp);
+ m_recp_lists.push_back (list);
+ }
+ (void) getKeysForProtocol;
+}
+
+int
+RecipientManager::getRequiredMails() const
+{
+ return (int) m_recp_lists.size ();
+}
+
+RecpList
+RecipientManager::getRecipients (int x, GpgME::Key &signing_key) const
+{
+ if (x >= m_recp_lists.size () || x < 0)
+ {
+ log_err ("Invalid index for recpients: %i", x);
+ return RecpList ();
+ }
+ RecpList ret = m_recp_lists[x];
+ if (ret.size() && ret[0].keys().size())
+ {
+ signing_key = (ret[0].keys()[0].protocol () == GpgME::CMS ? m_cmsSigKey : m_pgpSigKey);
+ }
+ return ret;
+}
diff --git a/src/recipientmanager.h b/src/recipientmanager.h
new file mode 100644
index 0000000..6733cba
--- /dev/null
+++ b/src/recipientmanager.h
@@ -0,0 +1,55 @@
+/* @file recipientmanager.h
+ * @brief Manage the recipients of a mail to send multiple mails to
+ * different recipients.
+ *
+ * Copyright (C) 2021 g10 Code GmbH
+ *
+ * This file is part of GpgOL.
+ *
+ * GpgOL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GpgOL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see .
+ */
+#ifndef RECIPIENTMANAGER_H
+#define RECIPIENTMANAGER_H
+
+#include "recipient.h"
+#include
+
+#include
+
+typedef std::vector RecpList;
+
+class RecipientManager
+{
+public:
+ /* Build a recipient manager with resolved recipients.
+
+ The recipient manager calculates how many mails need to
+ be sent to fulfil all requirements regarding split options.
+ */
+ RecipientManager (const RecpList &recipients,
+ const std::vector &signing_keys);
+
+ /* Returns the number of mails required to send */
+ int getRequiredMails () const;
+
+ /* Returns the recipients and the signing key for mail X */
+ RecpList getRecipients (int x, GpgME::Key &signing_key) const;
+
+private:
+ std::vector m_recp_lists;
+ GpgME::Key m_pgpSigKey,
+ m_cmsSigKey;
+};
+
+#endif // RECIPIENTMANAGER_H