Skip to content

deliverMessage throws InvalidMessageException with names that have quotes in it #65

@fibbers

Description

@fibbers

Describe the bug
When sending a message via the Java library with a recipient-name that has quotes in it, the library doesn't escape it and the API returns an error.

I have to escape the name myself with name.replace("\"", "\\\""), but it would be nice if the library does that for you.

To Reproduce

// this name could be from a database for example, or from an http request
String name = "A (company)name containing a \" for example";
String emailAddress = "[email protected]";

Message message = new Message();
// set required fields, e.g. from and body, and then:
message.setTo(Map.of(name, emailAddress));

ApiClient apiClient = Postmark.getApiClient(..);
apiClient.deliverMessage(message);

this throws:

com.postmarkapp.postmark.client.exception.InvalidMessageException: Error parsing 'To': Unclosed quoted string: "A (company)name containing a " for example"<[email protected]>
	at com.postmarkapp.postmark.client.HttpClientErrorHandler.throwErrorBasedOnStatusCode(HttpClientErrorHandler.java:37)
	at com.postmarkapp.postmark.client.HttpClientHandler.execute(HttpClientHandler.java:67)
	at com.postmarkapp.postmark.client.ApiClient.deliverMessage(ApiClient.java:67)

Expected behavior
It would be nice when using the library as follows, that from/to/cc/bcc recipient names are encoded or escaped automatically:

  • message.setFrom(name, address)
  • message.setTo(Map.of(name, address))
  • message.setCc(Map.of(name, address))
  • message.setBcc(Map.of(name, address))

Java (please complete the following information):

  • I'm using version 1.11.1 of the library in Java 21
  • Environment used: Linux/MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions