MimeMessageHelper encodes attachment filename if not ASCII compliant
Issue: SPR-9258
This commit is contained in:
parent
97ae403b53
commit
f8a7cf9f51
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,6 +35,7 @@ import javax.mail.internet.MimeBodyPart;
|
|||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.mail.internet.MimePart;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
@ -989,12 +990,17 @@ public class MimeMessageHelper {
|
|||
public void addAttachment(String attachmentFilename, DataSource dataSource) throws MessagingException {
|
||||
Assert.notNull(attachmentFilename, "Attachment filename must not be null");
|
||||
Assert.notNull(dataSource, "DataSource must not be null");
|
||||
try {
|
||||
MimeBodyPart mimeBodyPart = new MimeBodyPart();
|
||||
mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
|
||||
mimeBodyPart.setFileName(attachmentFilename);
|
||||
mimeBodyPart.setFileName(MimeUtility.encodeText(attachmentFilename));
|
||||
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
|
||||
getRootMimeMultipart().addBodyPart(mimeBodyPart);
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
throw new MessagingException("Failed to encode attachment filename", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an attachment to the MimeMessage, taking the content from a
|
||||
|
|
Loading…
Reference in New Issue