public void service(Mail mail) throws MessagingException {
DKIMSigner signer = new DKIMSigner(getSignatureTemplate(), getPrivateKey());
SignatureRecord signRecord = signer
.newSignatureRecordTemplate(getSignatureTemplate());
try {
BodyHasher bhj = signer.newBodyHasher(signRecord);
MimeMessage message = mail.getMessage();
Headers headers = new MimeMessageHeaders(message);
try {
OutputStream os = new HeaderSkippingOutputStream(bhj.getOutputStream());
if (forceCRLF) os = new CRLFOutputStream(os);
message.writeTo(os);
bhj.getOutputStream().close();
} catch (IOException e) {
throw new MessagingException("Exception calculating bodyhash: "
+ e.getMessage(), e);
}
String signatureHeader = signer.sign(headers, bhj);