message-contact: remove control characters from names
I.e., issue #2216.
This commit is contained in:
@ -139,12 +139,33 @@ test_ctor_02()
|
||||
g_assert_true(c.personal);
|
||||
g_assert_cmpuint(c.frequency,==,13);
|
||||
g_assert_cmpuint(c.tstamp,==,12345);
|
||||
assert_equal(c.name, "Blinky");
|
||||
g_assert_cmpuint(c.message_date,==,1645215014);
|
||||
|
||||
assert_equal(c.display_name(), "Blinky <bar@example.com>");
|
||||
}
|
||||
|
||||
static void
|
||||
test_ctor_03()
|
||||
{
|
||||
MessageContact c{
|
||||
"bar@example.com",
|
||||
"Bli\nky",
|
||||
1645215014,
|
||||
true, /* personal */
|
||||
13, /*freq*/
|
||||
12345 /* tstamp */
|
||||
};
|
||||
|
||||
assert_equal(c.email, "bar@example.com");
|
||||
assert_equal(c.name, "Bli ky");
|
||||
g_assert_true(c.personal);
|
||||
g_assert_cmpuint(c.frequency,==,13);
|
||||
g_assert_cmpuint(c.tstamp,==,12345);
|
||||
g_assert_cmpuint(c.message_date,==,1645215014);
|
||||
|
||||
assert_equal(c.display_name(), "Bli ky <bar@example.com>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
@ -173,6 +194,7 @@ main(int argc, char* argv[])
|
||||
|
||||
g_test_add_func("/lib/message-contacts/ctor-01", test_ctor_01);
|
||||
g_test_add_func("/lib/message-contacts/ctor-02", test_ctor_02);
|
||||
g_test_add_func("/lib/message-contacts/ctor-cleanup", test_ctor_cleanup);
|
||||
g_test_add_func("/lib/message-contacts/make-contacts", test_make_contacts);
|
||||
|
||||
return g_test_run();
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user