bbottema / simple-java-mail

Simple API, Complex Emails (Jakarta Mail smtp wrapper)

Home Page:http://www.simplejavamail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NamedDataSource should implement EncodingAware

ben-manes opened this issue · comments

When attaching a file, the content-type is inferred by MimeBodyPart by reading from the input stream. This occurs twice per attachment before the data is written out, resulting in 3 http calls. If the DataSource implements javax.mail.EncodingAware then this used if the result is non-null. When the file type is known, such as a pdf, this should avoid the extra hops. Unfortunately the given DataSource is decorated by NamedDataSource, so this optimization is not possible.

What about this?

class NamedDataSource implements DataSource, EncodingAware {
	
	(..)
	
	@Override
	public String getEncoding() {
		return (this.dataSource instanceof EncodingAware) ? ((EncodingAware) this.dataSource).getEncoding() : null;
	}
}

Yep, that is what I envisioned.

Released in 5.0.2.