message-contact: remove control characters from names
I.e., issue #2216.
This commit is contained in:
@ -34,11 +34,11 @@ struct _InternetAddressList;
|
||||
|
||||
namespace Mu {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the hash value for a lowercase value of s; useful for email-addresses
|
||||
*
|
||||
*
|
||||
* @param s a string
|
||||
*
|
||||
*
|
||||
* @return a hash value.
|
||||
*/
|
||||
size_t lowercase_hash(const std::string& s);
|
||||
@ -66,11 +66,10 @@ struct MessageContact {
|
||||
* @param message_date_ data for the message for this contact
|
||||
*/
|
||||
MessageContact(const std::string& email_, const std::string& name_ = "",
|
||||
Type type_ = Type::Unknown, time_t message_date_ = 0)
|
||||
Type type_ = Type::Unknown, time_t message_date_ = 0)
|
||||
: email{email_}, name{name_}, type{type_},
|
||||
message_date{message_date_}, personal{}, frequency{1}, tstamp{}
|
||||
{
|
||||
}
|
||||
{ cleanup_name(); }
|
||||
|
||||
/**
|
||||
* Construct a new MessageContact
|
||||
@ -83,13 +82,12 @@ struct MessageContact {
|
||||
* @param tstamp_ timestamp for last change
|
||||
*/
|
||||
MessageContact(const std::string& email_, const std::string& name_,
|
||||
time_t message_date_, bool personal_, size_t freq_,
|
||||
int64_t tstamp_)
|
||||
time_t message_date_, bool personal_, size_t freq_,
|
||||
int64_t tstamp_)
|
||||
: email{email_}, name{name_}, type{Type::Unknown},
|
||||
message_date{message_date_}, personal{personal_}, frequency{freq_},
|
||||
tstamp{tstamp_}
|
||||
{
|
||||
}
|
||||
{ cleanup_name();}
|
||||
|
||||
/**
|
||||
* Get the "display name" for this contact; basically, if there's a
|
||||
@ -100,19 +98,19 @@ struct MessageContact {
|
||||
* @return the display name
|
||||
*/
|
||||
std::string display_name() const;
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Operator==; based on the hash values (ie. lowercase e-mail address)
|
||||
*
|
||||
*
|
||||
* @param rhs some other MessageContact
|
||||
*
|
||||
*
|
||||
* @return true orf false.
|
||||
*/
|
||||
bool operator== (const MessageContact& rhs) const noexcept {
|
||||
return hash() == rhs.hash();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get a hash-value for this contact, which gets lazily calculated. This
|
||||
* is for use with container classes. This uses the _lowercase_ email
|
||||
* address.
|
||||
@ -126,7 +124,7 @@ struct MessageContact {
|
||||
}
|
||||
return cached_hash;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* data members
|
||||
*/
|
||||
@ -135,11 +133,17 @@ struct MessageContact {
|
||||
std::string name; /**< Name for this contact; can be empty. */
|
||||
Type type{Type::Unknown}; /**< Type of contact */
|
||||
::time_t message_date; /**< date of the message from which the
|
||||
* contact originates */
|
||||
* contact originates */
|
||||
bool personal; /**< A personal message? */
|
||||
size_t frequency; /**< Frequency of this contact */
|
||||
int64_t tstamp; /**< Timestamp for this contact */
|
||||
|
||||
private:
|
||||
void cleanup_name() { // replace control characters by spaces.
|
||||
for (auto& c: name)
|
||||
if (iscntrl(c))
|
||||
c = ' ';
|
||||
}
|
||||
};
|
||||
|
||||
using MessageContacts = std::vector<MessageContact>;
|
||||
@ -156,7 +160,7 @@ using MessageContacts = std::vector<MessageContact>;
|
||||
*/
|
||||
MessageContacts
|
||||
make_message_contacts(/*const*/ struct _InternetAddressList* addr_lst,
|
||||
MessageContact::Type type, ::time_t message_date);
|
||||
MessageContact::Type type, ::time_t message_date);
|
||||
|
||||
/**
|
||||
* Create a sequence of MessageContact objects from an InternetAddressList
|
||||
@ -172,7 +176,7 @@ make_message_contacts(const std::string& addrs,
|
||||
MessageContact::Type type, ::time_t message_date);
|
||||
} // namespace Mu
|
||||
|
||||
/**
|
||||
/**
|
||||
* Implement our hash int std::
|
||||
*/
|
||||
template<> struct std::hash<Mu::MessageContact> {
|
||||
|
||||
Reference in New Issue
Block a user