cpp: Fix addrSpec for keys without email

* lang/cpp/src/key.cpp (UserID::addrSpec): Use uid->address instead
of normalizing again.
(&operator<<(std::ostream &, const UserID &): Print it.

--
This saves a normalization and fixes the case where a user id
is just a mail address without name, in that case gpgme sets
"address" but not email. Because the email is then the name.
This commit is contained in:
Andre Heinecke 2016-12-15 11:31:14 +01:00
parent 5673f3e54a
commit 85e05537e1

View File

@ -894,7 +894,11 @@ std::string UserID::addrSpecFromString(const char *userid)
std::string UserID::addrSpec() const std::string UserID::addrSpec() const
{ {
return addrSpecFromString(email()); if (!uid || !uid->address) {
return std::string();
}
return uid->address;
} }
std::ostream &operator<<(std::ostream &os, const UserID &uid) std::ostream &operator<<(std::ostream &os, const UserID &uid)
@ -903,6 +907,7 @@ std::ostream &operator<<(std::ostream &os, const UserID &uid)
if (!uid.isNull()) { if (!uid.isNull()) {
os << "\n name: " << protect(uid.name()) os << "\n name: " << protect(uid.name())
<< "\n email: " << protect(uid.email()) << "\n email: " << protect(uid.email())
<< "\n mbox: " << uid.addrSpec()
<< "\n comment: " << protect(uid.comment()) << "\n comment: " << protect(uid.comment())
<< "\n validity: " << uid.validityAsString() << "\n validity: " << uid.validityAsString()
<< "\n revoked: " << uid.isRevoked() << "\n revoked: " << uid.isRevoked()