diff --git a/core/src/main/java/hudson/tasks/MailSender.java b/core/src/main/java/hudson/tasks/MailSender.java index d7ac5eac2e..5c9fcec1a1 100644 --- a/core/src/main/java/hudson/tasks/MailSender.java +++ b/core/src/main/java/hudson/tasks/MailSender.java @@ -69,12 +69,22 @@ public class MailSender { * If true, individuals will receive e-mails regarding who broke the build. */ private boolean sendToIndividuals; + + /** + * The charset to use for the text and subject. + */ + private String charSet; public MailSender(String recipients, boolean dontNotifyEveryUnstableBuild, boolean sendToIndividuals) { + this(recipients, dontNotifyEveryUnstableBuild, sendToIndividuals, "UTF-8"); + } + + public MailSender(String recipients, boolean dontNotifyEveryUnstableBuild, boolean sendToIndividuals, String charSet) { this.recipients = recipients; this.dontNotifyEveryUnstableBuild = dontNotifyEveryUnstableBuild; this.sendToIndividuals = sendToIndividuals; + this.charSet = charSet; } public boolean execute(AbstractBuild build, BuildListener listener) throws InterruptedException { @@ -156,10 +166,10 @@ public class MailSender { private MimeMessage createBackToNormalMail(AbstractBuild build, String subject, BuildListener listener) throws MessagingException { MimeMessage msg = createEmptyMail(build, listener); - msg.setSubject(getSubject(build, Messages.MailSender_BackToNormalMail_Subject(subject)),MAIL_CHARSET); + msg.setSubject(getSubject(build, Messages.MailSender_BackToNormalMail_Subject(subject)),charSet); StringBuilder buf = new StringBuilder(); appendBuildUrl(build, buf); - msg.setText(buf.toString(),MAIL_CHARSET); + msg.setText(buf.toString(),charSet); return msg; } @@ -180,14 +190,14 @@ public class MailSender { } } - msg.setSubject(getSubject(build, subject),MAIL_CHARSET); + msg.setSubject(getSubject(build, subject),charSet); StringBuilder buf = new StringBuilder(); // Link to project changes summary for "still unstable" if this or last build has changes if (still && !(build.getChangeSet().isEmptySet() && prev.getChangeSet().isEmptySet())) appendUrl(Util.encode(build.getProject().getUrl()) + "changes", buf); else appendBuildUrl(build, buf); - msg.setText(buf.toString(), MAIL_CHARSET); + msg.setText(buf.toString(), charSet); return msg; } @@ -206,7 +216,7 @@ public class MailSender { private MimeMessage createFailureMail(AbstractBuild build, BuildListener listener) throws MessagingException, InterruptedException { MimeMessage msg = createEmptyMail(build, listener); - msg.setSubject(getSubject(build, Messages.MailSender_FailureMail_Subject()),MAIL_CHARSET); + msg.setSubject(getSubject(build, Messages.MailSender_FailureMail_Subject()),charSet); StringBuilder buf = new StringBuilder(); appendBuildUrl(build, buf); @@ -283,7 +293,7 @@ public class MailSender { buf.append(Messages.MailSender_FailureMail_FailedToAccessBuildLog()).append("\n\n").append(Functions.printThrowable(e)); } - msg.setText(buf.toString(),MAIL_CHARSET); + msg.setText(buf.toString(),charSet); return msg; } @@ -384,10 +394,6 @@ public class MailSender { private static final int MAX_LOG_LINES = Integer.getInteger(MailSender.class.getName()+".maxLogLines",250); - /** - * The charset to use for the text and subject. - */ - private static final String MAIL_CHARSET = "UTF-8"; /** * Sometimes the outcome of the previous build affects the e-mail we send, hence this checkpoint. diff --git a/core/src/main/java/hudson/tasks/Mailer.java b/core/src/main/java/hudson/tasks/Mailer.java index 10412a0d25..31170ec38a 100644 --- a/core/src/main/java/hudson/tasks/Mailer.java +++ b/core/src/main/java/hudson/tasks/Mailer.java @@ -93,12 +93,13 @@ public class Mailer extends Notifier { private transient String from; private transient String subject; private transient boolean failureOnly; + private transient String charSet; @Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException { if(debug) listener.getLogger().println("Running mailer"); - return new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals) { + return new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals, charSet) { /** Check whether a path (/-separated) will be archived. */ @Override public boolean artifactMatches(String path, AbstractBuild build) { @@ -184,6 +185,11 @@ public class Mailer extends Notifier { */ private String smtpPort; + /** + * The charset to use for the text and subject. + */ + private String charSet; + /** * Used to keep track of number test e-mails. */ @@ -282,6 +288,10 @@ public class Mailer extends Notifier { } smtpPort = nullify(json.getString("smtpPort")); useSsl = json.getBoolean("useSsl"); + charSet = json.getString("charSet"); + if (charSet == null || charSet.length() == 0) + charSet = "UTF-8"; + save(); return true; } @@ -320,6 +330,12 @@ public class Mailer extends Notifier { public String getSmtpPort() { return smtpPort; } + + public String getCharSet() { + String c = charSet; + if (c == null || c.length() == 0) c = "UTF-8"; + return c; + } public void setDefaultSuffix(String defaultSuffix) { this.defaultSuffix = defaultSuffix; @@ -349,6 +365,10 @@ public class Mailer extends Notifier { public void setSmtpPort(String smtpPort) { this.smtpPort = smtpPort; } + + public void setCharSet(String charSet) { + this.charSet = charSet; + } public void setSmtpAuth(String userName, String password) { this.smtpAuthUsername = userName; @@ -490,7 +510,7 @@ public class Mailer extends Notifier { public static class ConverterImpl extends XStream2.PassthruConverter { public ConverterImpl(XStream2 xstream) { super(xstream); } @Override protected void callback(Mailer m, UnmarshallingContext context) { - if (m.from != null || m.subject != null || m.failureOnly) + if (m.from != null || m.subject != null || m.failureOnly || m.charSet != null) OldDataMonitor.report(context, "1.10"); } } diff --git a/core/src/main/resources/hudson/tasks/Mailer/global.jelly b/core/src/main/resources/hudson/tasks/Mailer/global.jelly index e9f62770e3..4ed395ea1c 100644 --- a/core/src/main/resources/hudson/tasks/Mailer/global.jelly +++ b/core/src/main/resources/hudson/tasks/Mailer/global.jelly @@ -52,7 +52,10 @@ THE SOFTWARE. + + + - + diff --git a/core/src/main/resources/hudson/tasks/Mailer/global_ja.properties b/core/src/main/resources/hudson/tasks/Mailer/global_ja.properties index 73ddedb04d..fc089514a2 100644 --- a/core/src/main/resources/hudson/tasks/Mailer/global_ja.properties +++ b/core/src/main/resources/hudson/tasks/Mailer/global_ja.properties @@ -30,4 +30,5 @@ Use\ SMTP\ Authentication=SMTP\u8a8d\u8a3c User\ Name=\u30e6\u30fc\u30b6\u30fc\u540d Password=\u30d1\u30b9\u30ef\u30fc\u30c9 Use\ SSL=SSL -SMTP\ Port=SMTP\u30dd\u30fc\u30c8 \ No newline at end of file +SMTP\ Port=SMTP\u30dd\u30fc\u30c8 +Char\ Set=\u6587\u5b57\u30bb\u30c3\u30c8 \ No newline at end of file