Skip to content

Commit

Permalink
[JENKINS-26758] Fix MimeMessageBuilder charset
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanblanchard committed Feb 4, 2015
1 parent 4f5996f commit 85d729d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/jenkins/plugins/mailer/tasks/MimeMessageBuilder.java
Expand Up @@ -29,6 +29,7 @@
import hudson.tasks.Mailer;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.main.modules.instance_identity.InstanceIdentity;

Expand All @@ -39,10 +40,13 @@
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.AddressException;
import javax.mail.internet.HeaderTokenizer;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import java.io.UnsupportedEncodingException;
import java.security.interfaces.RSAPublicKey;
import java.util.Date;
Expand Down Expand Up @@ -161,7 +165,7 @@ public MimeMessage buildMimeMessage() throws MessagingException, UnsupportedEnco

setJenkinsInstanceIdent(msg);

msg.setContent("", mimeType);
msg.setContent("", contentType());
if (StringUtils.isNotBlank(from)) {
msg.setFrom(toNormalizedAddress(from));
}
Expand Down Expand Up @@ -212,12 +216,16 @@ private void addBody(MimeMessage msg) throws MessagingException {
Multipart multipart = new MimeMultipart();
BodyPart bodyPart = new MimeBodyPart();

bodyPart.setContent(body, mimeType);
bodyPart.setContent(body, contentType());
multipart.addBodyPart(bodyPart);
msg.setContent(multipart);
}
}

private String contentType() {
return String.format("%s; charset=%s", mimeType, MimeUtility.quote(charset, HeaderTokenizer.MIME));
}

private void addRecipients(MimeMessage msg) throws UnsupportedEncodingException, MessagingException {
addRecipients(msg, to, Message.RecipientType.TO);
addRecipients(msg, cc, Message.RecipientType.CC);
Expand Down

0 comments on commit 85d729d

Please sign in to comment.