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.
This commit is contained in:
Jake Nelson 2023-06-09 16:18:49 -04:00 committed by GitHub
parent 713bb4e9e1
commit dc61f088c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -29,13 +29,20 @@
using namespace Mu; using namespace Mu;
const std::string rfc822SpecialCharacters = "()<>@,;:\\\".[]";
std::string std::string
Contact::display_name() const Contact::display_name() const
{ {
auto needs_quoting= [](const std::string& n) { auto needs_quoting= [](const std::string& n) {
for (auto& c: n) for (auto& c: n){
if (c == ',' || c == '"') // 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 true;
}
}
return false; return false;
}; };