diff --git a/lib/message/mu-contact.cc b/lib/message/mu-contact.cc index d507be69..acf91230 100644 --- a/lib/message/mu-contact.cc +++ b/lib/message/mu-contact.cc @@ -29,24 +29,22 @@ using namespace Mu; -static bool -needs_quoting(const std::string& name) -{ - for (auto& c: name) - if (c == ',' || c == '"') - return true; - return false; -} - std::string -Contact::display_name(bool quote) const +Contact::display_name() const { + auto needs_quoting= [](const std::string& n) { + for (auto& c: n) + if (c == ',' || c == '"') + return true; + return false; + }; + if (name.empty()) return email; - else if (!quote || !needs_quoting(name)) + else if (!needs_quoting(name)) return name + " <" + email + '>'; else - return address_rfc2047(*this); + return Mu::quote(name) + " <" + email + '>'; } static Regex email_rx; @@ -196,7 +194,7 @@ test_encode() g_assert_cmpuint(c.tstamp,==,768); g_assert_cmpuint(c.message_date,==,345); - assert_equal(c.display_name(true), + assert_equal(c.display_name(), "\"Ali, Muhammad \\\"The Greatest\\\"\" "); } diff --git a/lib/message/mu-contact.hh b/lib/message/mu-contact.hh index 7d6d4ee3..d417d4ec 100644 --- a/lib/message/mu-contact.hh +++ b/lib/message/mu-contact.hh @@ -83,18 +83,15 @@ struct Contact { { cleanup_name();} /** - * Get the "display name" for this contact; basically, if there's a - * non-empty name, it's - * Jane Doe - * otherwise it's just the e-mail address. + * Get the "display name" for this contact: * - * @param quote_if_needed if true, handle quoting of the name-part as - * well. This is useful when the address is to be used directly in - * emails. + * If there's a non-empty name, it's Jane Doe + * otherwise it's just the e-mail address. Names with commas are quoted + * (with the quotes escaped). * * @return the display name */ - std::string display_name(bool quote_if_needed=false) const; + std::string display_name() const; /** diff --git a/lib/message/test-mu-message.cc b/lib/message/test-mu-message.cc index 18de990f..36c73fcd 100644 --- a/lib/message/test-mu-message.cc +++ b/lib/message/test-mu-message.cc @@ -546,7 +546,7 @@ cmVmCjM1NjE4CiUlRU9GCg== g_assert_cmpuint(message->cc().size(),==, 1); assert_equal(message->cc().at(0).email, "Mickey.Mueller@example.com"); assert_equal(message->cc().at(0).name, "Müller, Mickey"); - assert_equal(message->cc().at(0).display_name(), "Müller, Mickey "); + assert_equal(message->cc().at(0).display_name(), "\"Müller, Mickey\" "); g_assert_true(message->bcc().empty()); assert_equal(message->subject(), "Purkutyöurakka"); diff --git a/mu/mu-cmd-cfind.cc b/mu/mu-cmd-cfind.cc index dcd14c36..25fb1298 100644 --- a/mu/mu-cmd-cfind.cc +++ b/mu/mu-cmd-cfind.cc @@ -225,7 +225,7 @@ output_json(ItemType itype, OptContact contact, const Options& opts) " \"frequency\" : %zu\n", contact->email.c_str(), name.c_str(), - Mu::quote(contact->display_name(true)).c_str(), + Mu::quote(contact->display_name()).c_str(), contact->message_date, time_to_string("%FT%TZ", contact->message_date, true/*utc*/).c_str(), contact->personal ? "true" : "false",