You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2020/10/07 11:54:58 UTC
svn commit: r1882300 - in /geronimo/specs/trunk: ./
geronimo-javamail_1.6_spec/
geronimo-javamail_1.6_spec/src/main/java/javax/mail/
geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/
geronimo-javamail_1.6_spec/src/test/java/javax/mail/ gero...
Author: jlmonteiro
Date: Wed Oct 7 11:54:57 2020
New Revision: 1882300
URL: http://svn.apache.org/viewvc?rev=1882300&view=rev
Log:
GERONIMO-6783 Add geronimo-javamail_1.6_spec
https://github.com/apache/geronimo-specs/pull/17
Thanks Cesar
Modified:
geronimo/specs/trunk/geronimo-javamail_1.6_spec/README.txt
geronimo/specs/trunk/geronimo-javamail_1.6_spec/pom.xml
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Flags.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Folder.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/MailSessionDefinition.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Multipart.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Part.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Service.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Session.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/UIDFolder.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetAddress.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetHeaders.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MailDateFormat.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeBodyPart.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMessage.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMultipart.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimePart.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeUtility.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParameterList.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParseException.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/FlagsTest.java
geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/internet/MimeMessageTest.java
geronimo/specs/trunk/pom.xml
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/README.txt
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/README.txt?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/README.txt (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/README.txt Wed Oct 7 11:54:57 2020
@@ -1,10 +1,11 @@
-JavaMail Specification 1.6
+JavaMail Specification 1.5
==========================
-These classes are based on the JavaMailTM API Design Specification Version 1.6 which can be found here:
-o https://github.com/eclipse-ee4j/mail
+These classes are based on the JavaMailTM API Design Specification Version 1.5 which can be found here:
+o https://javamail.java.net/nonav/docs/JavaMail-1.5.pdf
+o http://download.oracle.com/otn-pub/jcp/java_mail-1_5-mrel2-spec/javamail-1.5.0-javadocs.zip
-The classes represent the JavaMail API and contain implementations of the
+The classes represent the JavaMail API and contain implementations of the
classes found in the javax.mail packages. In order to function correctly,
these classes require:
@@ -13,9 +14,9 @@ o J2SE 5.0/JDK 1.5 or newer
o Implementations of the JavaMail providers to deal with pop/imap/etc.
(You may use this with the geronimo-mail implementation or write your own)
-This contains no JavaDoc: see
+This contains no JavaDoc: see
https://java.net/projects/javamail/pages/Home
- http://docs.oracle.com/javaee/8/api/
+ http://docs.oracle.com/javaee/7/api/
for more information on how to use JavaMail to send messages.
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/pom.xml?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/pom.xml Wed Oct 7 11:54:57 2020
@@ -26,8 +26,8 @@
<parent>
<groupId>org.apache.geronimo.genesis</groupId>
- <artifactId>genesis-java8-flava</artifactId>
- <version>2.3</version>
+ <artifactId>genesis-java7-flava</artifactId>
+ <version>2.4</version>
</parent>
<groupId>org.apache.geronimo.specs</groupId>
@@ -103,17 +103,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.9</version>
- <configuration>
- <source>1.8</source>
- <additionalparam>-Xdoclint:none</additionalparam>
+ <source>1.7</source>
+ <target>1.7</target>
</configuration>
</plugin>
<plugin>
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Flags.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Flags.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Flags.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Flags.java Wed Oct 7 11:54:57 2020
@@ -20,7 +20,9 @@
package javax.mail;
import java.io.Serializable;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Set;
/**
* Representation of flags that may be associated with a message.
@@ -81,13 +83,13 @@ public class Flags implements Cloneable,
// the Serialized form of this class required the following two fields to be persisted
// this leads to a specific type of implementation
private int system_flags;
- private final Hashtable user_flags;
+ private final Hashtable<String, String> user_flags;
/**
* Construct a Flags instance with no flags set.
*/
public Flags() {
- user_flags = new Hashtable();
+ user_flags = new Hashtable<>();
}
/**
@@ -96,7 +98,7 @@ public class Flags implements Cloneable,
*/
public Flags(final Flag flag) {
system_flags = flag.mask;
- user_flags = new Hashtable();
+ user_flags = new Hashtable<>();
}
/**
@@ -105,7 +107,7 @@ public class Flags implements Cloneable,
*/
public Flags(final Flags flags) {
system_flags = flags.system_flags;
- user_flags = new Hashtable(flags.user_flags);
+ user_flags = new Hashtable<>(flags.user_flags);
}
/**
@@ -114,7 +116,7 @@ public class Flags implements Cloneable,
* @param name the user flag to set
*/
public Flags(final String name) {
- user_flags = new Hashtable();
+ user_flags = new Hashtable<>();
user_flags.put(name.toLowerCase(), name);
}
@@ -295,4 +297,51 @@ public class Flags implements Cloneable,
public void remove(final String name) {
user_flags.remove(name.toLowerCase());
}
+
+ /**
+ * Remove any flags <strong>not</strong> in the given Flags object.
+ * Useful for clearing flags not supported by a server. If the
+ * given Flags object includes the Flags.Flag.USER flag, all user
+ * flags in this Flags object are retained.
+ *
+ * @param f the flags to keep
+ * @return true if this Flags object changed
+ * @since JavaMail 1.6
+ */
+ public boolean retainAll(Flags f) {
+ boolean changed = false;
+
+ if (this.system_flags != f.system_flags) {
+ this.system_flags = f.system_flags;
+ changed = true;
+ }
+
+ final Set<String> keys = new HashSet<>(this.user_flags.keySet());
+ for (final String user_flag : keys) {
+ if (! f.user_flags.containsKey(user_flag)) {
+ this.user_flags.remove(user_flag);
+ changed = true;
+ }
+ }
+
+ return changed;
+ }
+
+ /**
+ * Clear all of the system flags.
+ *
+ * @since JavaMail 1.6
+ */
+ public void clearSystemFlags() {
+ this.system_flags = 0;
+ }
+
+ /**
+ * Clear all of the user flags.
+ *
+ * @since JavaMail 1.6
+ */
+ public void clearUserFlags() {
+ this.user_flags.clear();
+ }
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Folder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Folder.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Folder.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Folder.java Wed Oct 7 11:54:57 2020
@@ -50,7 +50,7 @@ import javax.mail.search.SearchTerm;
*
* @version $Rev$ $Date$
*/
-public abstract class Folder {
+public abstract class Folder implements AutoCloseable {
/**
* Flag that indicates that a folder can contain messages.
*/
@@ -746,4 +746,27 @@ public abstract class Folder {
// tee it up and let it rip.
queue.queueEvent(event, (List)listeners.clone());
}
+
+ /**
+ * Close this Folder and expunge deleted messages. <p>
+ *
+ * A CLOSED ConnectionEvent is delivered to any ConnectionListeners
+ * registered on this Folder. Note that the folder is closed even
+ * if this method terminates abnormally by throwing a
+ * MessagingException. <p>
+ *
+ * This method supports the {@link java.lang.AutoCloseable AutoCloseable}
+ * interface. <p>
+ *
+ * This implementation calls <code>close(true)</code>.
+ *
+ * @exception IllegalStateException if this folder is not opened
+ * @exception MessagingException for other failures
+ * @see javax.mail.event.ConnectionEvent
+ * @since JavaMail 1.6
+ */
+ @Override
+ public void close() throws MessagingException {
+ close(true);
+ }
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/MailSessionDefinition.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/MailSessionDefinition.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/MailSessionDefinition.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/MailSessionDefinition.java Wed Oct 7 11:54:57 2020
@@ -19,6 +19,7 @@
package javax.mail;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@@ -40,6 +41,7 @@ import java.lang.annotation.Target;
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
+@Repeatable(MailSessionDefinitions.class)
public @interface MailSessionDefinition {
/**
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Multipart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Multipart.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Multipart.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Multipart.java Wed Oct 7 11:54:57 2020
@@ -32,7 +32,7 @@ public abstract class Multipart {
/**
* Vector of sub-parts.
*/
- protected Vector parts = new Vector();
+ protected Vector<BodyPart> parts = new Vector<>();
/**
* The content type of this multipart object; defaults to "multipart/mixed"
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Part.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Part.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Part.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Part.java Wed Oct 7 11:54:57 2020
@@ -59,7 +59,7 @@ public interface Part {
* @return An Enumeration containing all of the current Header objects.
* @exception MessagingException
*/
- public abstract Enumeration getAllHeaders() throws MessagingException;
+ public abstract Enumeration<Header> getAllHeaders() throws MessagingException;
/**
* Return a content object for this Part. The
@@ -166,7 +166,7 @@ public interface Part {
* @return An Enumeration of Header objects containing the matching headers.
* @exception MessagingException
*/
- public abstract Enumeration getMatchingHeaders(String[] names) throws MessagingException;
+ public abstract Enumeration<Header> getMatchingHeaders(String[] names) throws MessagingException;
/**
* Return an Enumeration of all Headers except those that match the names
@@ -179,11 +179,11 @@ public interface Part {
* in the exclusion list.
* @exception MessagingException
*/
- public abstract Enumeration getNonMatchingHeaders(String[] names) throws MessagingException;
+ public abstract Enumeration<Header> getNonMatchingHeaders(String[] names) throws MessagingException;
/**
* Return the size of this part, or -1 if the size
- * cannot be reliably determined.
+ * cannot be reliably determined.
*
* Note: the returned size does not take into account
* internal encodings, nor is it an estimate of
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Service.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Service.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Service.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Service.java Wed Oct 7 11:54:57 2020
@@ -21,6 +21,7 @@ package javax.mail;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.EventListener;
import java.util.List;
import java.util.Vector;
@@ -31,7 +32,7 @@ import javax.mail.event.MailEvent;
/**
* @version $Rev$ $Date$
*/
-public abstract class Service {
+public abstract class Service implements AutoCloseable {
/**
* The session from which this service was created.
*/
@@ -401,7 +402,7 @@ public abstract class Service {
return url == null ? super.toString() : url.toString();
}
- protected void queueEvent(final MailEvent event, final Vector listeners) {
+ protected void queueEvent(final MailEvent event, final Vector<? extends EventListener> listeners) {
// if there are no listeners to dispatch this to, don't put it on the queue.
// This allows us to delay creating the queue (and its new thread) until
// we
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Session.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Session.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Session.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/Session.java Wed Oct 7 11:54:57 2020
@@ -552,17 +552,25 @@ public final class Session {
private ProviderInfo loadProviders(final ClassLoader cl) {
// we create a merged map from reading all of the potential address map entries. The locations
// searched are:
- // 1. java.home/lib/javamail.address.map
+ // 0. java.home/conf/javamail.address.map
+ // 1. java.home/lib/javamail.address.map
// 2. META-INF/javamail.address.map
// 3. META-INF/javamail.default.address.map
//
+ // JDK 1.9 adds a new <java.home>/conf directory to hold configuration
+ // files that were previously stored in <java.home>/lib. When using
+ // JavaMail on JDK 1.9, it should look for its (optional) configuration
+ // files in the <java.home>/conf directory.
final ProviderInfo info = new ProviderInfo();
// NOTE: Unlike the addressMap, we process these in the defined order. The loading routine
// will not overwrite entries if they already exist in the map.
try {
- final File file = new File(System.getProperty("java.home"), "lib/javamail.providers");
+ File file = new File(System.getProperty("java.home"), "conf/javamail.providers");
+ if (!file.exists()){
+ file = new File(System.getProperty("java.home"), "lib/javamail.providers");
+ }
final InputStream is = new FileInputStream(file);
try {
loadProviders(info, is);
@@ -732,9 +740,15 @@ public final class Session {
private static Map loadAddressMap(final ClassLoader cl) {
// we create a merged map from reading all of the potential address map entries. The locations
// searched are:
- // 1. java.home/lib/javamail.address.map
+ // 0. java.home/conf/javamail.address.map
+ // 1. java.home/lib/javamail.address.map
// 2. META-INF/javamail.address.map
// 3. META-INF/javamail.default.address.map
+ //
+ // JDK 1.9 adds a new <java.home>/conf directory to hold configuration
+ // files that were previously stored in <java.home>/lib. When using
+ // JavaMail on JDK 1.9, it should look for its (optional) configuration
+ // files in the <java.home>/conf directory.
//
// if all of the above searches fail, we just set up some "default" defaults.
@@ -787,7 +801,10 @@ public final class Session {
try {
- final File file = new File(System.getProperty("java.home"), "lib/javamail.address.map");
+ File file = new File(System.getProperty("java.home"), "conf/javamail.address.map");
+ if (!file.exists()) {
+ file = new File(System.getProperty("java.home"), "lib/javamail.address.map");
+ }
final InputStream is = new FileInputStream(file);
try {
// load as a property file
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/UIDFolder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/UIDFolder.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/UIDFolder.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/UIDFolder.java Wed Oct 7 11:54:57 2020
@@ -30,6 +30,23 @@ public interface UIDFolder {
public static final long LASTUID = -1;
/**
+ * The largest value possible for a UID, a 32-bit unsigned integer.
+ * This can be used to fetch all new messages by keeping track of the
+ * last UID that was seen and using:
+ * <blockquote><pre>
+ *
+ * Folder f = store.getFolder("whatever");
+ * UIDFolder uf = (UIDFolder)f;
+ * Message[] newMsgs =
+ * uf.getMessagesByUID(lastSeenUID + 1, UIDFolder.MAXUID);
+ *
+ * </pre></blockquote><p>
+ *
+ * @since JavaMail 1.6
+ */
+ public static final long MAXUID = 0xffffffffL;
+
+ /**
* Get the UID validity value for this Folder.
*
* @return The current UID validity value, as a long.
@@ -97,6 +114,24 @@ public interface UIDFolder {
public abstract long getUID(Message message) throws MessagingException;
/**
+ * Returns the predicted UID that will be assigned to the
+ * next message that is appended to this folder.
+ * Messages might be appended to the folder after this value
+ * is retrieved, causing this value to be out of date.
+ * This value might only be updated when a folder is first opened.
+ * Note that messages may have been appended to the folder
+ * while it was open and thus this value may be out of
+ * date. <p>
+ *
+ * If the value is unknown, -1 is returned. <p>
+ *
+ * @return the UIDNEXT value, or -1 if unknown
+ * @exception MessagingException for failures
+ * @since JavaMail 1.6
+ */
+ public long getUIDNext() throws MessagingException;
+
+ /**
* Special profile item used for fetching UID information.
*/
public static class FetchProfileItem extends FetchProfile.Item {
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetAddress.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetAddress.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetAddress.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetAddress.java Wed Oct 7 11:54:57 2020
@@ -22,6 +22,7 @@ package javax.mail.internet;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
import javax.mail.Address;
import javax.mail.Session;
@@ -573,4 +574,105 @@ public class InternetAddress extends Add
final AddressParser parser = new AddressParser(formatAddress(address), AddressParser.STRICT);
parser.validateAddress();
}
+
+ /**
+ * Convert the given array of InternetAddress objects into
+ * a comma separated sequence of address strings. The
+ * resulting string contains Unicode characters. <p>
+ *
+ * @param addresses array of InternetAddress objects
+ * @exception ClassCastException if any address object in the
+ * given array is not an InternetAddress object.
+ * Note that this is a RuntimeException.
+ * @return comma separated string of addresses
+ * @since JavaMail 1.6
+ */
+ public static String toUnicodeString(Address[] addresses) {
+ return toUnicodeString(addresses, 0);
+ }
+
+ /**
+ * Convert the given array of InternetAddress objects into
+ * a comma separated sequence of address strings. The
+ * resulting string contains Unicode characters. <p>
+ *
+ * The 'used' parameter specifies the number of character positions
+ * already taken up in the field into which the resulting address
+ * sequence string is to be inserted. It is used to determine the
+ * line-break positions in the resulting address sequence string.
+ *
+ * @param addresses array of InternetAddress objects
+ * @param used number of character positions already used, in
+ * the field into which the address string is to
+ * be inserted.
+ * @exception ClassCastException if any address object in the
+ * given array is not an InternetAddress object.
+ * Note that this is a RuntimeException.
+ * @return comma separated string of addresses
+ * @Since JavaMail 1.6
+ */
+ public static String toUnicodeString(Address[] addresses, int used) {
+
+ if (addresses == null || addresses.length == 0) {
+ return null;
+ }
+
+ boolean sawNonAsciiCharacters = false;
+
+ if (addresses.length == 1) {
+
+ String converted = ((InternetAddress)addresses[0]).toUnicodeString();
+ if (MimeUtility.verifyAscii(converted) != MimeUtility.ALL_ASCII){
+ sawNonAsciiCharacters = true;
+ converted = new String(converted.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
+
+ }
+
+ if (used + converted.length() > 72) {
+ converted = "\r\n " + converted;
+ }
+
+ if(sawNonAsciiCharacters){
+ return new String(converted.getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
+ }
+
+ return converted;
+ } else {
+ final StringBuffer buf = new StringBuffer(addresses.length * 32);
+ for (int i = 0; i < addresses.length; i++) {
+
+ String converted = ((InternetAddress)addresses[0]).toUnicodeString();
+
+ if (MimeUtility.verifyAscii(converted) != MimeUtility.ALL_ASCII){
+ sawNonAsciiCharacters = true;
+ converted = new String(converted.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
+
+ }
+
+ if (i == 0) {
+ if (used + converted.length() + 1 > 72) {
+ buf.append("\r\n ");
+ used = 2;
+ }
+ } else {
+ if (used + converted.length() + 1 > 72) {
+ buf.append(",\r\n ");
+ used = 2;
+ } else {
+ buf.append(", ");
+ used += 2;
+ }
+ }
+ buf.append(converted);
+ used += converted.length();
+ }
+
+ String finalString = buf.toString();
+
+ if(sawNonAsciiCharacters){
+ return new String(finalString.getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
+ }
+ return finalString;
+ }
+ }
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetHeaders.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetHeaders.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetHeaders.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/InternetHeaders.java Wed Oct 7 11:54:57 2020
@@ -22,6 +22,7 @@ package javax.mail.internet;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
@@ -38,7 +39,7 @@ import javax.mail.MessagingException;
*/
public class InternetHeaders {
// the list of headers (to preserve order);
- protected List headers = new ArrayList();
+ protected List<InternetHeader> headers = new ArrayList();
/**
* Create an empty InternetHeaders
@@ -82,30 +83,49 @@ public class InternetHeaders {
* Create a new InternetHeaders initialized by reading headers from the
* stream.
*
- * @param in
- * the RFC822 input stream to load from
- * @throws MessagingException
- * if there is a problem pasring the stream
+ * @param in RFC822 input stream
+ * @param allowUtf8 if UTF-8 encoded headers are allowed
+ * @exception MessagingException if there is a problem parsing the stream
+ * @since JavaMail 1.6
+ */
+ public InternetHeaders(final InputStream in, boolean allowUtf8) throws MessagingException {
+ load(in, allowUtf8);
+ }
+
+ /**
+ * Create a new InternetHeaders initialized by reading headers from the
+ * stream.
+ *
+ * @param in the RFC822 input stream to load from
+ * @throws MessagingException if there is a problem parsing the stream
+ *
*/
public InternetHeaders(final InputStream in) throws MessagingException {
- load(in);
+ load(in, false);
}
/**
- * Read and parse the supplied stream and add all headers to the current
- * set.
+ * Read and parse the given RFC822 message stream till the
+ * blank line separating the header from the body. Store the
+ * header lines inside this InternetHeaders object. The order
+ * of header lines is preserved.
*
- * @param in
- * the RFC822 input stream to load from
- * @throws MessagingException
- * if there is a problem pasring the stream
+ * Note that the header lines are added into this InternetHeaders
+ * object, so any existing headers in this object will not be
+ * affected. Headers are added to the end of the existing list
+ * of headers, in order.
+ *
+ * @param is RFC822 input stream
+ * @param allowUtf8 if UTF-8 encoded headers are allowed
+ * @exception MessagingException for any I/O error reading the stream
+ * @since JavaMail 1.6
*/
- public void load(final InputStream in) throws MessagingException {
+ public void load(InputStream is, boolean allowUtf8) throws MessagingException {
try {
final StringBuffer buffer = new StringBuffer(128);
String line;
// loop until we hit the end or a null line
- while ((line = readLine(in)) != null) {
+ while ((line = readLine(is, allowUtf8)) != null) {
// lines beginning with white space get special handling
if (line.startsWith(" ") || line.startsWith("\t")) {
// this gets handled using the logic defined by
@@ -114,14 +134,12 @@ public class InternetHeaders {
// to the last header in the headers list
if (buffer.length() == 0) {
addHeaderLine(line);
- }
- else {
+ } else {
// preserve the line break and append the continuation
buffer.append("\r\n");
buffer.append(line);
}
- }
- else {
+ } else {
// if we have a line pending in the buffer, flush it
if (buffer.length() > 0) {
addHeaderLine(buffer.toString());
@@ -141,6 +159,17 @@ public class InternetHeaders {
}
}
+ /**
+ * Read and parse the supplied stream and add all headers to the current
+ * set.
+ *
+ * @param in the RFC822 input stream to load from
+ * @throws MessagingException if there is a problem pasring the stream
+ */
+ public void load(final InputStream in) throws MessagingException {
+ load(in, false);
+ }
+
/**
* Read a single line from the input stream
@@ -149,7 +178,7 @@ public class InternetHeaders {
*
* @return The string value of the line (without line separators)
*/
- private String readLine(final InputStream in) throws IOException {
+ private String readLine(final InputStream in, boolean allowUtf8) throws IOException {
final StringBuffer buffer = new StringBuffer(128);
int c;
@@ -175,7 +204,13 @@ public class InternetHeaders {
return null;
}
- return buffer.toString();
+ String finalString = buffer.toString();
+
+ if(allowUtf8){
+ return new String(finalString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
+ }
+
+ return finalString;
}
@@ -425,8 +460,8 @@ public class InternetHeaders {
*
* @return an Enumeration<Header> containing all headers
*/
- public Enumeration getAllHeaders() {
- final List result = new ArrayList();
+ public Enumeration<Header> getAllHeaders() {
+ final List<Header> result = new ArrayList<>();
for (int i = 0; i < headers.size(); i++) {
final InternetHeader header = (InternetHeader)headers.get(i);
@@ -469,8 +504,8 @@ public class InternetHeaders {
/**
* Return all matching Header objects.
*/
- public Enumeration getMatchingHeaders(final String[] names) {
- final List result = new ArrayList();
+ public Enumeration<Header> getMatchingHeaders(final String[] names) {
+ final List<Header> result = new ArrayList<>();
for (int i = 0; i < headers.size(); i++) {
final InternetHeader header = (InternetHeader)headers.get(i);
@@ -489,8 +524,8 @@ public class InternetHeaders {
/**
* Return all non matching Header objects.
*/
- public Enumeration getNonMatchingHeaders(final String[] names) {
- final List result = new ArrayList();
+ public Enumeration<Header> getNonMatchingHeaders(final String[] names) {
+ final List<Header> result = new ArrayList<>();
for (int i = 0; i < headers.size(); i++) {
final InternetHeader header = (InternetHeader)headers.get(i);
@@ -544,21 +579,21 @@ public class InternetHeaders {
/**
* Return all the header lines as an Enumeration of Strings.
*/
- public Enumeration getAllHeaderLines() {
+ public Enumeration<String> getAllHeaderLines() {
return new HeaderLineEnumeration(getAllHeaders());
}
/**
* Return all matching header lines as an Enumeration of Strings.
*/
- public Enumeration getMatchingHeaderLines(final String[] names) {
+ public Enumeration<String> getMatchingHeaderLines(final String[] names) {
return new HeaderLineEnumeration(getMatchingHeaders(names));
}
/**
* Return all non-matching header lines.
*/
- public Enumeration getNonMatchingHeaderLines(final String[] names) {
+ public Enumeration<String> getNonMatchingHeaderLines(final String[] names) {
return new HeaderLineEnumeration(getNonMatchingHeaders(names));
}
@@ -697,10 +732,10 @@ public class InternetHeaders {
}
}
- private static class HeaderLineEnumeration implements Enumeration {
- private final Enumeration headers;
+ private static class HeaderLineEnumeration implements Enumeration<String> {
+ private final Enumeration<Header> headers;
- public HeaderLineEnumeration(final Enumeration headers) {
+ public HeaderLineEnumeration(final Enumeration<Header> headers) {
this.headers = headers;
}
@@ -708,7 +743,7 @@ public class InternetHeaders {
return headers.hasMoreElements();
}
- public Object nextElement() {
+ public String nextElement() {
final Header h = (Header) headers.nextElement();
return h.getName() + ": " + h.getValue();
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MailDateFormat.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MailDateFormat.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MailDateFormat.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MailDateFormat.java Wed Oct 7 11:54:57 2020
@@ -19,9 +19,11 @@
package javax.mail.internet;
+import java.text.DateFormatSymbols;
import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParseException;
+import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -95,8 +97,89 @@ public class MailDateFormat extends Simp
public void setNumberFormat(final NumberFormat format) {
throw new UnsupportedOperationException();
}
-
-
+
+ /**
+ * This method always throws an UnsupportedOperationException and
+ * should not be used because RFC 2822 mandates a specific pattern.
+ *
+ * @throws UnsupportedOperationException if this method is invoked
+ * @since JavaMail 1.6
+ */
+ @Override
+ public void applyLocalizedPattern(String pattern) {
+ throw new UnsupportedOperationException("Method "
+ + "applyLocalizedPattern() shouldn't be called");
+ }
+
+ /**
+ * This method always throws an UnsupportedOperationException and
+ * should not be used because RFC 2822 mandates a specific pattern.
+ *
+ * @throws UnsupportedOperationException if this method is invoked
+ * @since JavaMail 1.6
+ */
+ @Override
+ public void applyPattern(String pattern) {
+ throw new UnsupportedOperationException("Method "
+ + "applyPattern() shouldn't be called");
+ }
+
+ /**
+ * This method always throws an UnsupportedOperationException and
+ * should not be used because RFC 2822 mandates another strategy
+ * for interpreting 2-digits years.
+ *
+ * @return the start of the 100-year period into which two digit
+ * years are parsed
+ * @throws UnsupportedOperationException if this method is invoked
+ * @since JavaMail 1.6
+ */
+ @Override
+ public Date get2DigitYearStart() {
+ throw new UnsupportedOperationException("Method "
+ + "get2DigitYearStart() shouldn't be called");
+ }
+
+ /**
+ * This method always throws an UnsupportedOperationException and
+ * should not be used because RFC 2822 mandates another strategy
+ * for interpreting 2-digits years.
+ *
+ * @throws UnsupportedOperationException if this method is invoked
+ * @since JavaMail 1.6
+ */
+ @Override
+ public void set2DigitYearStart(Date startDate) {
+ throw new UnsupportedOperationException("Method "
+ + "set2DigitYearStart() shouldn't be called");
+ }
+
+ /**
+ * This method always throws an UnsupportedOperationException and
+ * should not be used because RFC 2822 mandates specific date
+ * format symbols.
+ *
+ * @throws UnsupportedOperationException if this method is invoked
+ * @since JavaMail 1.6
+ */
+ @Override
+ public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols) {
+ throw new UnsupportedOperationException("Method "
+ + "setDateFormatSymbols() shouldn't be called");
+ }
+
+ /**
+ * Overrides Cloneable.
+ *
+ * @return a clone of this instance
+ * @since JavaMail 1.6
+ */
+ @Override
+ public MailDateFormat clone() {
+ return (MailDateFormat) super.clone();
+ }
+
+
// utility class for handling date parsing issues
class MailDateParser {
// our list of defined whitespace characters
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeBodyPart.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeBodyPart.java Wed Oct 7 11:54:57 2020
@@ -32,12 +32,7 @@ import java.util.Enumeration;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
-import javax.mail.BodyPart;
-import javax.mail.EncodingAware;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
+import javax.mail.*;
import javax.mail.internet.HeaderTokenizer.Token;
import org.apache.geronimo.mail.util.ASCIIUtil;
@@ -529,15 +524,15 @@ public class MimeBodyPart extends BodyPa
headers.removeHeader(name);
}
- public Enumeration getAllHeaders() throws MessagingException {
+ public Enumeration<Header> getAllHeaders() throws MessagingException {
return headers.getAllHeaders();
}
- public Enumeration getMatchingHeaders(final String[] name) throws MessagingException {
+ public Enumeration<Header> getMatchingHeaders(final String[] name) throws MessagingException {
return headers.getMatchingHeaders(name);
}
- public Enumeration getNonMatchingHeaders(final String[] name) throws MessagingException {
+ public Enumeration<Header> getNonMatchingHeaders(final String[] name) throws MessagingException {
return headers.getNonMatchingHeaders(name);
}
@@ -545,15 +540,15 @@ public class MimeBodyPart extends BodyPa
headers.addHeaderLine(line);
}
- public Enumeration getAllHeaderLines() throws MessagingException {
+ public Enumeration<String> getAllHeaderLines() throws MessagingException {
return headers.getAllHeaderLines();
}
- public Enumeration getMatchingHeaderLines(final String[] names) throws MessagingException {
+ public Enumeration<String> getMatchingHeaderLines(final String[] names) throws MessagingException {
return headers.getMatchingHeaderLines(names);
}
- public Enumeration getNonMatchingHeaderLines(final String[] names) throws MessagingException {
+ public Enumeration<String> getNonMatchingHeaderLines(final String[] names) throws MessagingException {
return headers.getNonMatchingHeaderLines(names);
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMessage.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMessage.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMessage.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMessage.java Wed Oct 7 11:54:57 2020
@@ -36,15 +36,7 @@ import java.util.List;
import java.util.Map;
import javax.activation.DataHandler;
-import javax.mail.Address;
-import javax.mail.Flags;
-import javax.mail.Folder;
-import javax.mail.IllegalWriteException;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
-import javax.mail.Session;
+import javax.mail.*;
import javax.mail.internet.HeaderTokenizer.Token;
import org.apache.geronimo.mail.util.ASCIIUtil;
@@ -64,6 +56,8 @@ public class MimeMessage extends Message
// static used to ensure message ID uniqueness
private static int messageID = 0;
+ // is UTF-8 allowed in headers?
+ private boolean allowUtf8 = false;
/**
* Extends {@link javax.mail.Message.RecipientType} to support addition recipient types.
@@ -1407,15 +1401,15 @@ public class MimeMessage extends Message
* @return An Enumeration of the message headers.
* @exception MessagingException
*/
- public Enumeration getAllHeaders() throws MessagingException {
+ public Enumeration<Header> getAllHeaders() throws MessagingException {
return headers.getAllHeaders();
}
- public Enumeration getMatchingHeaders(final String[] names) throws MessagingException {
+ public Enumeration<Header> getMatchingHeaders(final String[] names) throws MessagingException {
return headers.getMatchingHeaders(names);
}
- public Enumeration getNonMatchingHeaders(final String[] names) throws MessagingException {
+ public Enumeration<Header> getNonMatchingHeaders(final String[] names) throws MessagingException {
return headers.getNonMatchingHeaders(names);
}
@@ -1423,15 +1417,15 @@ public class MimeMessage extends Message
headers.addHeaderLine(line);
}
- public Enumeration getAllHeaderLines() throws MessagingException {
+ public Enumeration<String> getAllHeaderLines() throws MessagingException {
return headers.getAllHeaderLines();
}
- public Enumeration getMatchingHeaderLines(final String[] names) throws MessagingException {
+ public Enumeration<String> getMatchingHeaderLines(final String[] names) throws MessagingException {
return headers.getMatchingHeaderLines(names);
}
- public Enumeration getNonMatchingHeaderLines(final String[] names) throws MessagingException {
+ public Enumeration<String> getNonMatchingHeaderLines(final String[] names) throws MessagingException {
return headers.getNonMatchingHeaderLines(names);
}
@@ -1507,6 +1501,12 @@ public class MimeMessage extends Message
final DataHandler handler = getDataHandler();
try {
+ //RFC 2822 requires a Date header. The MimeMessage.updateHeaders method
+ //now sets the Date header if it's not already set
+ if (getSentDate() == null) {
+ setSentDate(new Date());
+ }
+
// figure out the content type. If not set, we'll need to figure this out.
String type = dh.getContentType();
// we might need to reconcile the content type and our explicitly set type
@@ -1618,7 +1618,7 @@ public class MimeMessage extends Message
*/
protected InternetHeaders createInternetHeaders(final InputStream in) throws MessagingException {
// internet headers has a constructor for just this purpose
- return new InternetHeaders(in);
+ return new InternetHeaders(in, allowUtf8);
}
/**
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMultipart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMultipart.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMultipart.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeMultipart.java Wed Oct 7 11:54:57 2020
@@ -149,6 +149,7 @@ public class MimeMultipart extends Multi
*
* @param dataSource the DataSource to use
* @throws MessagingException
+ * @throws ParseException
*/
public MimeMultipart(final DataSource dataSource) throws MessagingException {
ds = dataSource;
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimePart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimePart.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimePart.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimePart.java Wed Oct 7 11:54:57 2020
@@ -30,7 +30,7 @@ import javax.mail.Part;
public interface MimePart extends Part {
public abstract void addHeaderLine(String line) throws MessagingException;
- public abstract Enumeration getAllHeaderLines() throws MessagingException;
+ public abstract Enumeration<String> getAllHeaderLines() throws MessagingException;
public abstract String getContentID() throws MessagingException;
@@ -43,10 +43,10 @@ public interface MimePart extends Part {
public abstract String getHeader(String header, String delimiter)
throws MessagingException;
- public abstract Enumeration getMatchingHeaderLines(String[] names)
+ public abstract Enumeration<String> getMatchingHeaderLines(String[] names)
throws MessagingException;
- public abstract Enumeration getNonMatchingHeaderLines(String[] names)
+ public abstract Enumeration<String> getNonMatchingHeaderLines(String[] names)
throws MessagingException;
public abstract void setContentLanguage(String[] languages)
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeUtility.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeUtility.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeUtility.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/MimeUtility.java Wed Oct 7 11:54:57 2020
@@ -60,6 +60,10 @@ public class MimeUtility {
private static final String MIME_DECODE_TEXT_STRICT = "mail.mime.decodetext.strict";
private static final String MIME_FOLDTEXT = "mail.mime.foldtext";
private static final int FOLD_THRESHOLD = 76;
+ static final int ALL_ASCII = 1;
+ static final int MOSTLY_ASCII = 2;
+ static final int MOSTLY_NONASCII = 3;
+
private MimeUtility() {
}
@@ -1292,6 +1296,39 @@ public class MimeUtility {
}
return newString.toString();
}
+
+ /**
+ * Verifies if a given string contains non US-ASCII characters
+ *
+ * @param s The String
+ * @return ALL_ASCII if all characters in the string belong to the US-ASCII
+ * character. MOSTLY_ASCII if more than half of the available characters are
+ * US-ASCII characters. Else MOSTLY_NONASCII.
+ */
+ static int verifyAscii(String s) {
+ int ascii_characters = 0;
+ int non_ascii_characters = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ if (nonascii((int) s.charAt(i))) {
+ non_ascii_characters++;
+ } else {
+ ascii_characters++;
+ }
+ }
+
+ if (non_ascii_characters == 0) {
+ return ALL_ASCII;
+ } else if (ascii_characters > non_ascii_characters) {
+ return MOSTLY_ASCII;
+ } else {
+ return MOSTLY_NONASCII;
+ }
+ }
+
+ static final boolean nonascii (int a){
+ return a >= 0177 || (a < 040 && a != '\r' && a != '\n' && a != '\t');
+ }
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParameterList.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParameterList.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParameterList.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParameterList.java Wed Oct 7 11:54:57 2020
@@ -397,7 +397,7 @@ public class ParameterList {
_parameters.remove(name);
}
- public Enumeration getNames() {
+ public Enumeration<String> getNames() {
return Collections.enumeration(_parameters.keySet());
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParseException.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParseException.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParseException.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/main/java/javax/mail/internet/ParseException.java Wed Oct 7 11:54:57 2020
@@ -23,6 +23,8 @@ import javax.mail.MessagingException;
/**
* @version $Rev$ $Date$
+ * The exception thrown due to an error in parsing RFC822
+ * or MIME headers, including multipart bodies.
*/
public class ParseException extends MessagingException {
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/FlagsTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/FlagsTest.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/FlagsTest.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/FlagsTest.java Wed Oct 7 11:54:57 2020
@@ -19,10 +19,7 @@
package javax.mail;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import junit.framework.TestCase;
@@ -153,4 +150,69 @@ public class FlagsTest extends TestCase
assertTrue(other != flags);
assertEquals(other, flags);
}
+
+ public void testClearSystemFlags() {
+ Flags f = new Flags();
+ f.add(Flags.Flag.ANSWERED);
+ f.add(Flags.Flag.DELETED);
+ f.add(Flags.Flag.DRAFT);
+ f.add(Flags.Flag.FLAGGED);
+ f.add(Flags.Flag.RECENT);
+ f.add(Flags.Flag.SEEN);
+ f.add("TEST");
+
+ f.clearSystemFlags();
+
+ assertEquals(0, f.getSystemFlags().length);
+ assertEquals(1, f.getUserFlags().length);
+ assertEquals("TEST", f.getUserFlags()[0]);
+ }
+
+ public void testClearuserFlags() {
+ Flags f = new Flags();
+ f.add(Flags.Flag.ANSWERED);
+ f.add(Flags.Flag.DELETED);
+ f.add(Flags.Flag.DRAFT);
+ f.add(Flags.Flag.FLAGGED);
+ f.add(Flags.Flag.RECENT);
+ f.add(Flags.Flag.SEEN);
+ f.add("TEST");
+
+ f.clearUserFlags();
+
+ assertEquals(6, f.getSystemFlags().length);
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.ANSWERED));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.DELETED));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.DRAFT));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.FLAGGED));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.RECENT));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.SEEN));
+ assertEquals(0, f.getUserFlags().length);
+ }
+
+ public void testRetainAllFlags() {
+ Flags f = new Flags();
+ f.add(Flags.Flag.ANSWERED);
+ f.add(Flags.Flag.DELETED);
+ f.add(Flags.Flag.DRAFT);
+ f.add(Flags.Flag.FLAGGED);
+ f.add(Flags.Flag.RECENT);
+ f.add(Flags.Flag.SEEN);
+ f.add("TEST");
+ f.add("FLAG");
+
+ Flags retain = new Flags();
+ retain.add(Flags.Flag.SEEN);
+ retain.add(Flags.Flag.ANSWERED);
+ retain.add("TEST");
+ retain.add("SUPER IMPORTANT");
+
+ f.retainAll(retain);
+
+ assertEquals(2, f.getSystemFlags().length);
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.ANSWERED));
+ assertTrue(Arrays.asList(f.getSystemFlags()).contains(Flags.Flag.SEEN));
+ assertEquals(1, f.getUserFlags().length);
+ assertEquals("TEST", f.getUserFlags()[0]);
+ }
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/internet/MimeMessageTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/internet/MimeMessageTest.java?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/internet/MimeMessageTest.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.6_spec/src/test/java/javax/mail/internet/MimeMessageTest.java Wed Oct 7 11:54:57 2020
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.text.ParseException;
+import java.util.Date;
import java.util.Properties;
import javax.activation.CommandMap;
@@ -456,6 +458,20 @@ public class MimeMessageTest extends Tes
assertEquals(type.getParameter("charset"), "UTF-8");
}
+ public void testAddDateinUpdateHeaders() throws MessagingException, ParseException {
+ final MimeMessage msg = new MimeMessage(session);
+ msg.updateHeaders();
+
+ final String[] dateHeader = msg.getHeader("Date");
+ assertNotNull(dateHeader);
+ assertEquals(1, dateHeader.length);
+
+ final Date date = new MailDateFormat().parse(dateHeader[0]);
+ final Date now = new Date();
+
+ // this should be within 5 seconds
+ assertTrue((now.getTime() - date.getTime()) < 5000);
+ }
@Override
Modified: geronimo/specs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/pom.xml?rev=1882300&r1=1882299&r2=1882300&view=diff
==============================================================================
--- geronimo/specs/trunk/pom.xml (original)
+++ geronimo/specs/trunk/pom.xml Wed Oct 7 11:54:57 2020
@@ -157,7 +157,7 @@
<!-- EL 3.0 NONE -->
<module>geronimo-jms_2.0_spec</module>
<module>geronimo-jta_1.2_spec</module>
- <!-- JavaMail 1.6 NONE -->
+ <module>geronimo-javamail_1.6_spec</module>
<!-- Connectors 1.7 NONE -->
<!-- Web Services 1.4 NONE -->
<module>geronimo-jaxrpc_1.1_spec</module>