Skip to content

Commit

Permalink
#131: implements EncodingAware
Browse files Browse the repository at this point in the history
  • Loading branch information
bbottema committed Mar 10, 2018
1 parent ba743d8 commit 7f2eaa1
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.simplejavamail.converter.internal.mimemessage;

import javax.activation.DataSource;
import javax.mail.EncodingAware;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -10,7 +11,7 @@
/**
* Allows given datasource to be renamed (from {@link javax.activation.DataHandler} perspective).
*/
class NamedDataSource implements DataSource {
class NamedDataSource implements DataSource, EncodingAware {

/**
* Original data source used for attachment.
Expand Down Expand Up @@ -69,4 +70,15 @@ public String getContentType() {
public String getName() {
return !valueNullOrEmpty(name) ? name : dataSource.getName();
}

/**
* Optimization to help Java Mail determine encoding for attachments.
*
* @return The encoding from the nested data source if it implements {@link EncodingAware} as well.
* @see <a href="https://github.com/bbottema/simple-java-mail/issues/131">Bug report #131</a>
*/
@Override
public String getEncoding() {
return (this.dataSource instanceof EncodingAware) ? ((EncodingAware) this.dataSource).getEncoding() : null;
}
}

0 comments on commit 7f2eaa1

Please sign in to comment.