From dc61f088c73d098ffe5ae1736718f63706cb240b Mon Sep 17 00:00:00 2001 From: Jake Nelson Date: Fri, 9 Jun 2023 16:18:49 -0400 Subject: [PATCH] Quote Display Names which contain special characters RFC 822 and RFC 5322 define characters which require an atom be quoted when included as a word in a mailbox. --- lib/message/mu-contact.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/message/mu-contact.cc b/lib/message/mu-contact.cc index acf91230..0c25b5bc 100644 --- a/lib/message/mu-contact.cc +++ b/lib/message/mu-contact.cc @@ -29,13 +29,20 @@ using namespace Mu; +const std::string rfc822SpecialCharacters = "()<>@,;:\\\".[]"; + std::string Contact::display_name() const { auto needs_quoting= [](const std::string& n) { - for (auto& c: n) - if (c == ',' || c == '"') + for (auto& c: n){ + // RFC 822 3.3 and RFC 5322 3.2.3 defines special characters, Ascii + // Control (CTL) characters (0-31), DEL (127), and space as requiring + // quoting. + if (c <=31 || c >= 127 || c == ' ' || rfc822SpecialCharacters.find(c) != std::string::npos){ return true; + } + } return false; };