// Copyright (c) 2020 Proton Technologies AG // // This file is part of ProtonMail Bridge. // // ProtonMail Bridge is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ProtonMail Bridge is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with ProtonMail Bridge. If not, see . package message import ( "net/mail" "testing" ) func TestRFC822AddressFormat(t *testing.T) { //nolint[funlen] tests := []struct { address string expected []string }{ { " normal name ", []string{ "\"normal name\" ", }, }, { " \"comma, name\" ", []string{ "\"comma, name\" ", }, }, { " name (ignore comment)", []string{ "\"name\" ", }, }, { " name (ignore comment) , (Comment as name) username2@server.com", []string{ "\"name\" ", "", }, }, { " normal name , (comment)All.(around)address@(the)server.com", []string{ "\"normal name\" ", "", }, }, { " normal name , All.(\"comma, in comment\")address@(the)server.com", []string{ "\"normal name\" ", "", }, }, { " \"normal name\" , \"comma, name\" ", []string{ "\"normal name\" ", "\"comma, name\" ", }, }, { " \"comma, one\" , \"comma, two\" ", []string{ "\"comma, one\" ", "\"comma, two\" ", }, }, { " \"comma, name\" , another, name ", []string{ "\"comma, name\" ", "\"another, name\" ", }, }, } for _, data := range tests { uncommented := parseAddressComment(data.address) result, err := mail.ParseAddressList(uncommented) if err != nil { t.Errorf("Can not parse '%s' created from '%s': %v", uncommented, data.address, err) } if len(result) != len(data.expected) { t.Errorf("Wrong parsing of '%s' created from '%s': expected '%s' but have '%+v'", uncommented, data.address, data.expected, result) } for i, result := range result { if data.expected[i] != result.String() { t.Errorf("Wrong parsing\nof %q\ncreated from %q:\nexpected %q\nbut have %q", uncommented, data.address, data.expected, result.String()) } } } }