Added to configure charset option of Mailer.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@29822 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
cactusman committed 2010-04-06 14:58:59 +00:00
1 parent 6197c8848f
commit b2bd8ceae2
4 files changed
+44 -14

No files matched your search

+16 -10
View File
@@ -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.
+22 -2
View File
@@ -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<Mailer> {
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");
}
}