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

spring-integration-mail: RFC5322 conforming messages containing multiple values in from or reply-to headers cannot be transformed #3560

Closed
dl1ely opened this issue May 5, 2021 · 2 comments · Fixed by #3562

Comments

@dl1ely
Copy link

dl1ely commented May 5, 2021

In what version(s) of Spring Integration are you seeing this issue?

spring-integration-mail:5.4.5

Describe the bug

https://github.com/spring-projects/spring-integration/blob/main/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/MailUtils.java#L52 and https://github.com/spring-projects/spring-integration/blob/main/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/MailUtils.java#L56 expect a single address, and throw an exception org.springframework.messaging.MessagingException: conversion of MailMessage headers failed; nested exception is java.lang.IllegalStateException: expected a single value but received an Array in https://github.com/spring-projects/spring-integration/blob/main/spring-integration-mail/src/main/java/org/springframework/integration/mail/support/MailUtils.java#L69 while RFC 5322 https://tools.ietf.org/html/rfc5322#section-3.6.2 allows for a comma separated list of "mailbox specifications" (for from) or "addresses" (for reply-to). Messages that conform to RFC 5322 cannot be transformed successfully.

To Reproduce

This was just a find after an analysis of production log error messages when receiving mails. It should be reproducible with mail messages containing multiple values in the from or reply-to fields according to RFC 5322.

Expected behavior

from and reply-to header fields should support multiple comma-separated addresses, be extracted successfully and copied to the AbstractIntegrationMessageBuilder at https://github.com/spring-projects/spring-integration/blob/main/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java#L83

Inbound mail messages conforming to RFC 5322 should be transformable without throwing an exception. Currently, this leads to cases where we are not able to successfully receive RFC5322 conforming inbound mail.

@dl1ely dl1ely added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels May 5, 2021
@dl1ely
Copy link
Author

dl1ely commented May 5, 2021

Section 3.6.2 of RFC 5322 has been updated by RFC 6854 https://tools.ietf.org/html/rfc6854#section-2.1 but this does not change the problem described. Still from and reply-to may contain comma separated lists of addresses.

@artembilan
Copy link
Member

Yes, we definitely need to follow an RFC, but it is hard to fix it without a breaking change since MailHeaders.FROM & MailHeaders.REPLY_TO were there for a while and definitely expected to be as a single value.

As a "soft" fix I suggest to convert an array of those values back to the comma-delimited single entry, so it won't be a breaking change for existing apps.

In the future major version we probably can revise it in favor of handy array as it is expected by RFC.

If this makes sense, I'll raise a PR with an appropriate back-port to supported versions.

@artembilan artembilan added in: mail and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels May 5, 2021
@artembilan artembilan added this to the 5.5 GA milestone May 5, 2021
artembilan added a commit to artembilan/spring-integration that referenced this issue May 5, 2021
Fixes spring-projects#3560

According RFC 5322 `FROM` and `REPLY-TO` received mail message can be
as an array of addresses.

* Fix `MailUtils` to present those arrays as comma-delimited strings for
Spring message headers
* Fix tests to deal already with several addresses for `FROM` mime header.

In the future we may change the logic to map those mime headers to arrays
as it states according the mentioned RFC

**Cherry-pick to `5.4.x` & `5.3.x`**
garyrussell pushed a commit that referenced this issue May 5, 2021
Fixes #3560

According RFC 5322 `FROM` and `REPLY-TO` received mail message can be
as an array of addresses.

* Fix `MailUtils` to present those arrays as comma-delimited strings for
Spring message headers
* Fix tests to deal already with several addresses for `FROM` mime header.

In the future we may change the logic to map those mime headers to arrays
as it states according the mentioned RFC

**Cherry-pick to `5.4.x` & `5.3.x`**
garyrussell pushed a commit that referenced this issue May 5, 2021
Fixes #3560

According RFC 5322 `FROM` and `REPLY-TO` received mail message can be
as an array of addresses.

* Fix `MailUtils` to present those arrays as comma-delimited strings for
Spring message headers
* Fix tests to deal already with several addresses for `FROM` mime header.

In the future we may change the logic to map those mime headers to arrays
as it states according the mentioned RFC

**Cherry-pick to `5.4.x` & `5.3.x`**
garyrussell pushed a commit that referenced this issue May 5, 2021
Fixes #3560

According RFC 5322 `FROM` and `REPLY-TO` received mail message can be
as an array of addresses.

* Fix `MailUtils` to present those arrays as comma-delimited strings for
Spring message headers
* Fix tests to deal already with several addresses for `FROM` mime header.

In the future we may change the logic to map those mime headers to arrays
as it states according the mentioned RFC

**Cherry-pick to `5.4.x` & `5.3.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants