diff --git a/src/recipient.cpp b/src/recipient.cpp
index 798a99b..2e7a9eb 100644
--- a/src/recipient.cpp
+++ b/src/recipient.cpp
@@ -1,81 +1,126 @@
/* @file recipient.cpp
* @brief Information about a recipient.
*
* Copyright (C) 2020, 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 "recipient.h"
#include "debug.h"
+#include "cpphelp.h"
#include
-Recipient::Recipient(const char *addr, int type)
+Recipient::Recipient(const char *addr, int type) : m_index (-1)
{
TSTART;
if (addr)
{
m_mbox = GpgME::UserID::addrSpecFromString (addr);
}
setType (type);
if (!m_mbox.size ())
{
log_error ("%s:%s: Recipient constructed without valid addr",
SRCNAME, __func__);
m_type = invalidType;
}
TRETURN;
}
+Recipient::Recipient(const Recipient &other)
+{
+ m_type = other.type();
+ m_mbox = other.mbox();
+ m_keys = other.keys();
+ m_index = other.index();
+}
+
Recipient::Recipient() : m_type (invalidType)
{
}
void
Recipient::setType (int type)
{
if (type > olBCC || type < olOriginator)
{
log_error ("%s:%s: Invalid recipient type %i",
SRCNAME, __func__, type);
m_type = invalidType;
}
m_type = static_cast (type);
}
void
Recipient::setKeys (const std::vector &keys)
{
m_keys = keys;
}
std::string
Recipient::mbox () const
{
return m_mbox;
}
Recipient::recipientType
Recipient::type () const
{
return m_type;
}
std::vector
Recipient::keys () const
{
return m_keys;
}
+
+void
+Recipient::setIndex (int i)
+{
+ m_index = i;
+}
+
+int
+Recipient::index () const
+{
+ return m_index;
+}
+
+void
+Recipient::dump (const std::vector &recps)
+{
+ log_data ("--- Begin recipient dump ---");
+ if (recps.empty())
+ {
+ log_data ("Empty recipient list.");
+ }
+ for (const auto &recp: recps)
+ {
+ log_data ("Type: %i Mail: '%s'", recp.type (), recp.mbox ().c_str ());
+ for (const auto &key: recp.keys ())
+ {
+ log_data ("Key: %s: %s", to_cstr (key.protocol ()),
+ key.primaryFingerprint ());
+ }
+ if (recp.keys().empty())
+ {
+ log_data ("unresolved");
+ }
+ }
+ log_data ("--- End recipient dump ---");
+}
diff --git a/src/recipient.h b/src/recipient.h
index 5031ab2..0b1cf4d 100644
--- a/src/recipient.h
+++ b/src/recipient.h
@@ -1,59 +1,66 @@
/* @file recipient.h
* @brief Information about a recipient.
*
* Copyright (C) 2020, 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 RECIPIENT_H
#define RECIPIENT_H
#include
#include
namespace GpgME
{
class Key;
} // namespace GpgME
class Recipient
{
public:
- Recipient ();
- explicit Recipient (const char *addr, int type);
+ Recipient ();
+ Recipient (const Recipient &other);
+ explicit Recipient (const char *addr, int type);
- enum recipientType
- {
- olOriginator = 0, /* Originator (sender) of the Item */
- olCC = 2, /* Specified in the CC property */
- olTo = 1, /* Specified in the To property */
- olBCC = 3, /* BCC */
- invalidType = -1, /* indicates that the type was not set or the
- recipient is somehow invalid */
- };
+ enum recipientType
+ {
+ olOriginator = 0, /* Originator (sender) of the Item */
+ olCC = 2, /* Specified in the CC property */
+ olTo = 1, /* Specified in the To property */
+ olBCC = 3, /* BCC */
+ invalidType = -1, /* indicates that the type was not set or the
+ recipient is somehow invalid */
+ };
- void setKeys (const std::vector &keys);
- std::vector keys () const;
+ void setKeys (const std::vector &keys);
+ std::vector keys () const;
- std::string mbox () const;
- recipientType type () const;
- void setType (int type);
+ std::string mbox () const;
+ recipientType type () const;
+ void setType (int type);
+ void setIndex (int index);
+ int index() const;
+
+ /* For debugging */
+ static void dump(const std::vector &recps);
private:
std::string m_mbox;
recipientType m_type;
std::vector m_keys;
+ int m_index;
};
#endif