diff --git a/src/recipient.cpp b/src/recipient.cpp
index 9ec0e08..b196d01 100644
--- a/src/recipient.cpp
+++ b/src/recipient.cpp
@@ -1,187 +1,193 @@
/* @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 "mimemaker.h"
#include
Recipient::Recipient(const char *addr,
const char *name, int type):
m_index (-1)
{
TSTART;
if (addr)
{
m_mbox = GpgME::UserID::addrSpecFromString (addr);
m_addr = addr;
}
setType (type);
if (!m_mbox.size ())
{
log_error ("%s:%s: Recipient constructed without valid addr",
SRCNAME, __func__);
m_type = invalidType;
}
if (name && !strcmp (name, addr))
{
m_name = name;
}
TRETURN;
}
Recipient::Recipient(const char *addr, int type):
Recipient(addr, nullptr, type)
{
}
Recipient::Recipient(const Recipient &other)
{
m_type = other.type();
m_mbox = other.mbox();
m_keys = other.keys();
m_index = other.index();
m_name = other.name();
m_addr = other.addr();
}
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 ---");
}
std::string
Recipient::encodedDisplayName () const
{
std::string ret;
if (m_name.empty())
{
char *encoded = utf8_to_rfc2047b (m_addr.c_str ());
if (encoded)
{
ret = encoded;
xfree (encoded);
}
return ret;
}
std::string displayName = m_name;
if (GpgME::UserID::addrSpecFromString (m_name.c_str ()) !=
m_addr)
{
displayName += std::string (" <") + m_addr + std::string (">");
}
char *encDisp = utf8_to_rfc2047b (displayName.c_str ());
if (encDisp)
{
ret = encDisp;
xfree (encDisp);
}
return ret;
}
std::string
Recipient::name () const
{
return m_name;
}
std::string
Recipient::addr () const
{
return m_addr;
}
+
+bool
+Recipient::isNull () const
+{
+ return m_type == invalidType;
+}
diff --git a/src/recipient.h b/src/recipient.h
index ae61eb9..5446fb1 100644
--- a/src/recipient.h
+++ b/src/recipient.h
@@ -1,74 +1,75 @@
/* @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 ();
Recipient (const Recipient &other);
explicit Recipient (const char *addr, int type);
explicit Recipient (const char *addr, const char *name, 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 */
};
void setKeys (const std::vector &keys);
std::vector keys () const;
std::string mbox () const;
std::string name () const;
std::string addr () const;
recipientType type () const;
void setType (int type);
void setIndex (int index);
int index() const;
+ bool isNull() const;
/* Returns an RFC2047 encoded name / email pair of the recipient. */
std::string encodedDisplayName () const;
/* For debugging */
static void dump(const std::vector &recps);
private:
std::string m_mbox;
std::string m_name;
std::string m_addr;
recipientType m_type;
std::vector m_keys;
int m_index;
};
#endif