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

"FROM:" header terminating by ; in a EML message will raise an exception in MailUtils.arrayToDelimitedString() / source.getFrom #2076

Open
DavidRobertKeller opened this issue Jan 9, 2025 · 0 comments

Comments

@DavidRobertKeller
Copy link

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

jakarta.mail-2.0.3.jar
spring.integration.core-6.3.0.RELEASE

@see spring-projects/spring-integration#9746

Describe the bug

A form header terminating by ; in a EML message raise an exception in MailUtils.arrayToDelimitedString()
For example "From: [email protected];"

To Reproduce

Send an EML message with "FROM:" header terminating by ";"
example:

...
FROM: [email protected]; <- the infamous ";" :) !
TO: [email protected]
...

And create this Bean on server side to access to mailbox using IMAPS

@Configuration
public class TestFlowConfiguration {
    
    @Bean
    TransactionSynchronizationFactory transactionSynchronizationFactory() {
        return new DefaultTransactionSynchronizationFactory(new MailTransactionProcessor());
    }
   
    @Bean
    IntegrationFlow mainIntegration(EmailProperties props,
            @Qualifier("emailTransformer") Transformer emailTransformer,
            @Qualifier("emailMessageHandler") MessageHandler messageHandler,
            @Qualifier("pseudoTransactionManager") TransactionManager transactionManager,
            @Qualifier("transactionSynchronizationFactory") TransactionSynchronizationFactory transactionSyncFactory) {
                
        // imaps
        var inbound = Mail.imapInboundAdapter(props.getMailReceiverUrl())
            .javaMailProperties(new PropertiesBuilder().put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory").get())
            .shouldMarkMessagesAsRead(props.isMarkMessagesAsRead())
            .simpleContent(false)
            .shouldDeleteMessages(props.isDeleteMessages()).userFlag(USER_FLAG)
	        .maxFetchSize(props.getMaxFetchSize())
	        .simpleContent(true)
	        .autoCloseFolder(true);
        
        return IntegrationFlow.from(inbound
                  , e -> e.poller(Pollers.fixedDelay(props.getPollRate() * 1000)
                      .transactional(transactionManager)
                      .transactionSynchronizationFactory(transactionSyncFactory)))
                   .transform(emailTransformer)
                   .handle(messageHandler).get();
    }    
}

will raise this exception :

org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:138)
... 45 more
Caused by: jakarta.mail.internet.AddressException: Illegal semicolon, not in group in string ``sender@example.com;'' at position 20
at jakarta.mail.internet.InternetAddress.parse(InternetAddress.java:1030)
at jakarta.mail.internet.InternetAddress.parseHeader(InternetAddress.java:762)
at jakarta.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:753)
at jakarta.mail.internet.MimeMessage.getFrom(MimeMessage.java:375)
at org.springframework.integration.mail.support.MailUtils.extractStandardHeaders(MailUtils.java:54)
public static Map<String, Object> extractStandardHeaders(Message source) {
		Map<String, Object> headers = new HashMap<>();
		try {
			headers.put(MailHeaders.FROM, StringUtils.arrayToCommaDelimitedString(source.getFrom()));
package jakarta.mail.internet;

class InternetAddress {
...
    /*
     * RFC822 Address parser.
     *
     * XXX - This is complex enough that it ought to be a real parser,
     *       not this ad-hoc mess, and because of that, this is not perfect.
     *
     * XXX - Deal with encoded Headers too.
     */
    @SuppressWarnings("fallthrough")
    private static InternetAddress[] parse(String s, boolean strict,
                                           boolean parseHdr) throws AddressException {
...
    }
}

Expected behavior
the "MAIL:" header must be parsed with no error

Sample

Send this EML :

From: [email protected];
To: [email protected]
Subject: Test invalid from header
Message-ID: <[email protected]>
Date: Sat, 9 Dec 2024 12:34:56 +0000

This is a simple email body.

kind regards
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant