static void setHeaders(final Email email, final Message message)
			throws UnsupportedEncodingException, MessagingException {
		// add headers (for raw message headers we need to 'fold' them using MimeUtility
		for (final Map.Entry<String, String> header : email.getHeaders().entrySet()) {
			final String headerName = header.getKey();
			final String headerValue = MimeUtility.encodeText(header.getValue(), CHARACTER_ENCODING, null);
			final String foldedHeaderValue = MimeUtility.fold(headerName.length() + 2, headerValue);
			message.addHeader(header.getKey(), foldedHeaderValue);
		}
		
		if (email.isUseDispositionNotificationTo()) {
			final Recipient dispositionTo = checkNonEmptyArgument(email.getDispositionNotificationTo(), "dispositionNotificationTo");
			final Address address = new InternetAddress(dispositionTo.getAddress(), dispositionTo.getName(), CHARACTER_ENCODING);
			message.setHeader("Disposition-Notification-To", address.toString());
		}
		
		if (email.isUseReturnReceiptTo()) {
			final Recipient returnReceiptTo = checkNonEmptyArgument(email.getReturnReceiptTo(), "returnReceiptTo");
			final Address address = new InternetAddress(returnReceiptTo.getAddress(), returnReceiptTo.getName(), CHARACTER_ENCODING);
			message.setHeader("Return-Receipt-To", address.toString());
		}
	}
static void setHeaders ( final Email email , final Message message ) throws UnsupportedEncodingException , MessagingException { for ( final Map . Entry < String , String > header : email . getHeaders ( ) . entrySet ( ) ) { final String headerName = header . getKey ( ) ; final String headerValue = MimeUtility . encodeText ( header . getValue ( ) , CHARACTER_ENCODING , null ) ; final String foldedHeaderValue = MimeUtility . fold ( headerName . length ( ) + 2 , headerValue ) ; message . addHeader ( header . getKey ( ) , foldedHeaderValue ) ; } if ( email . isUseDispositionNotificationTo ( ) ) { final Recipient dispositionTo = checkNonEmptyArgument ( email . getDispositionNotificationTo ( ) , "dispositionNotificationTo" ) ; final Address address = new InternetAddress ( dispositionTo . getAddress ( ) , dispositionTo . getName ( ) , CHARACTER_ENCODING ) ; message . setHeader ( "Disposition-Notification-To" , address . toString ( ) ) ; } if ( email . isUseReturnReceiptTo ( ) ) { final Recipient returnReceiptTo = checkNonEmptyArgument ( email . getReturnReceiptTo ( ) , "returnReceiptTo" ) ; final Address address = new InternetAddress ( returnReceiptTo . getAddress ( ) , returnReceiptTo . getName ( ) , CHARACTER_ENCODING ) ; message . setHeader ( "Return-Receipt-To" , address . toString ( ) ) ; } }
Sets all headers on the {@link Message} instance. Since we're not using a high-level JavaMail method, the JavaMail library says we need to do
some encoding and 'folding' manually, to get the value right for the headers (see {@link MimeUtility}.
<p>
Furthermore sets the notification flags <code>Disposition-Notification-To</code> and <code>Return-Receipt-To</code> if provided. It used
JavaMail's built in method for producing an RFC compliant email address (see {@link InternetAddress#toString()}).

@param email   The message in which the headers are defined.
@param message The {@link Message} on which to set the raw, encoded and folded headers.
@throws UnsupportedEncodingException See {@link MimeUtility#encodeText(String, String, String)}
@throws MessagingException           See {@link Message#addHeader(String, String)}
@see MimeUtility#encodeText(String, String, String)
@see MimeUtility#fold(int, String)