Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ private String convertRecipients(List<String> recipients) {

private String convertRecipient(String name, String address) {
StringBuilder recipientsString = new StringBuilder();
if (name != null) {
// Escape characters that otherwise cause parsing errors in the API
name = name.replace("\"", "\\\"");
}
return recipientsString.append("\"").append(name).append("\"")
.append("<").append(address).append(">").toString();
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/unit/data/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,28 @@ void simpleMessageBcccRecipientsFullName() throws IOException {

}

@Test
void recipientsWithQuotesAreEscapedProperly() {
Message message = new Message();
String nameWithQuote = "John \"Smith\"";
String email = "[email protected]";

Map<String, String> recipients = new HashMap<>();
recipients.put(nameWithQuote, email);

message.setTo(recipients);
assertEquals("\"John \\\"Smith\\\"\"<[email protected]>", message.getTo());

message.setCc(recipients);
assertEquals("\"John \\\"Smith\\\"\"<[email protected]>", message.getCc());

message.setBcc(recipients);
assertEquals("\"John \\\"Smith\\\"\"<[email protected]>", message.getBcc());

message.setFrom(nameWithQuote, email);
assertEquals("\"John \\\"Smith\\\"\"<[email protected]>", message.getFrom());
}

@Test
void attachmentException() throws IOException {
Message message = new Message();
Expand Down