Skip to content

Commit 7f2eaa1

Browse files
committed
#131: implements EncodingAware
1 parent ba743d8 commit 7f2eaa1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/org/simplejavamail/converter/internal/mimemessage/NamedDataSource.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.simplejavamail.converter.internal.mimemessage;
22

33
import javax.activation.DataSource;
4+
import javax.mail.EncodingAware;
45
import java.io.IOException;
56
import java.io.InputStream;
67
import java.io.OutputStream;
@@ -10,7 +11,7 @@
1011
/**
1112
* Allows given datasource to be renamed (from {@link javax.activation.DataHandler} perspective).
1213
*/
13-
class NamedDataSource implements DataSource {
14+
class NamedDataSource implements DataSource, EncodingAware {
1415

1516
/**
1617
* Original data source used for attachment.
@@ -69,4 +70,15 @@ public String getContentType() {
6970
public String getName() {
7071
return !valueNullOrEmpty(name) ? name : dataSource.getName();
7172
}
73+
74+
/**
75+
* Optimization to help Java Mail determine encoding for attachments.
76+
*
77+
* @return The encoding from the nested data source if it implements {@link EncodingAware} as well.
78+
* @see <a href="https://github.com/bbottema/simple-java-mail/issues/131">Bug report #131</a>
79+
*/
80+
@Override
81+
public String getEncoding() {
82+
return (this.dataSource instanceof EncodingAware) ? ((EncodingAware) this.dataSource).getEncoding() : null;
83+
}
7284
}

0 commit comments

Comments
 (0)