Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fibbers opened this issue Oct 11, 2024 · 0 comments · May be fixed by #66
Open

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

fibbers opened this issue Oct 11, 2024 · 0 comments · May be fixed by #66

Comments

@fibbers
Copy link

fibbers commented Oct 11, 2024

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 = "dummy@example.com";

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"<dummy@example.com>
	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
@fibbers fibbers linked a pull request Oct 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant