PR: 14046 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273522 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -96,6 +96,8 @@ Other changes: | |||
| * new task <attrib> to change file attributes on Windows systems. | |||
| * MailLogger now sets the Date header correctly. | |||
| Changes from Ant 1.5.1Beta1 to 1.5.1 | |||
| ==================================== | |||
| @@ -64,6 +64,7 @@ import java.util.StringTokenizer; | |||
| import org.apache.tools.ant.BuildEvent; | |||
| import org.apache.tools.ant.DefaultLogger; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.util.DateUtils; | |||
| import org.apache.tools.ant.util.StringUtils; | |||
| import org.apache.tools.mail.MailMessage; | |||
| @@ -218,6 +219,7 @@ public class MailLogger extends DefaultLogger { | |||
| private void sendMail(String mailhost, int port, String from, String toList, | |||
| String subject, String message) throws IOException { | |||
| MailMessage mailMessage = new MailMessage(mailhost, port); | |||
| mailMessage.setHeader("Date", DateUtils.getDateForHeader()); | |||
| mailMessage.from(from); | |||
| @@ -53,14 +53,10 @@ | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.email; | |||
| import java.text.DateFormat; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Locale; | |||
| import java.util.TimeZone; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.util.DateUtils; | |||
| /** | |||
| * Base class for the various emailing implementations. | |||
| @@ -81,9 +77,6 @@ abstract class Mailer { | |||
| protected Task task; | |||
| protected boolean includeFileNames = false; | |||
| private static DateFormat df = | |||
| new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US); | |||
| /** | |||
| * Sets the mail server | |||
| * | |||
| @@ -209,27 +202,7 @@ abstract class Mailer { | |||
| * @since Ant 1.5 | |||
| */ | |||
| protected final String getDate() { | |||
| Calendar cal = Calendar.getInstance(); | |||
| TimeZone tz = cal.getTimeZone(); | |||
| int offset = tz.getOffset(cal.get(Calendar.ERA), | |||
| cal.get(Calendar.YEAR), | |||
| cal.get(Calendar.MONTH), | |||
| cal.get(Calendar.DAY_OF_MONTH), | |||
| cal.get(Calendar.DAY_OF_WEEK), | |||
| cal.get(Calendar.MILLISECOND)); | |||
| StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+"); | |||
| offset = Math.abs(offset); | |||
| int hours = offset / (60 * 60 * 1000); | |||
| int minutes = offset / (60 * 1000) - 60 * hours; | |||
| if (hours < 10) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(hours); | |||
| if (minutes < 10) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(minutes); | |||
| return df.format(cal.getTime()) + tzMarker.toString(); | |||
| return DateUtils.getDateForHeader(); | |||
| } | |||
| } | |||
| @@ -59,6 +59,7 @@ import java.text.MessageFormat; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import java.util.Locale; | |||
| import java.util.TimeZone; | |||
| /** | |||
| @@ -94,6 +95,12 @@ public final class DateUtils { | |||
| public static final String ISO8601_TIME_PATTERN | |||
| = "HH:mm:ss"; | |||
| /** | |||
| * Format used for SMTP (and probably other) Date headers. | |||
| */ | |||
| public static final DateFormat DATE_HEADER_FORMAT | |||
| = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ", Locale.US); | |||
| // code from Magesh moved from DefaultLogger and slightly modified | |||
| private static final MessageFormat MINUTE_SECONDS | |||
| @@ -219,4 +226,34 @@ public final class DateUtils { | |||
| } | |||
| return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7; | |||
| } | |||
| /** | |||
| * Returns the current Date in a format suitable for a SMTP date | |||
| * header. | |||
| * | |||
| * @since Ant 1.5.2 | |||
| */ | |||
| public static String getDateForHeader() { | |||
| Calendar cal = Calendar.getInstance(); | |||
| TimeZone tz = cal.getTimeZone(); | |||
| int offset = tz.getOffset(cal.get(Calendar.ERA), | |||
| cal.get(Calendar.YEAR), | |||
| cal.get(Calendar.MONTH), | |||
| cal.get(Calendar.DAY_OF_MONTH), | |||
| cal.get(Calendar.DAY_OF_WEEK), | |||
| cal.get(Calendar.MILLISECOND)); | |||
| StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+"); | |||
| offset = Math.abs(offset); | |||
| int hours = offset / (60 * 60 * 1000); | |||
| int minutes = offset / (60 * 1000) - 60 * hours; | |||
| if (hours < 10) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(hours); | |||
| if (minutes < 10) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(minutes); | |||
| return DATE_HEADER_FORMAT.format(cal.getTime()) + tzMarker.toString(); | |||
| } | |||
| } | |||