You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sa...@apache.org on 2014/11/24 18:33:45 UTC
svn commit: r1641428 - in
/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src:
main/java/javax/mail/internet/ test/java/javax/mail/internet/
Author: salyh
Date: Mon Nov 24 17:33:45 2014
New Revision: 1641428
URL: http://svn.apache.org/r1641428
Log:
Fix GERONIMO-5842 and GERONIMO-6480
Modified:
geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/AddressParser.java
geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/MimeBodyPart.java
geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/InternetAddressTest.java
geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java
Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/AddressParser.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/AddressParser.java?rev=1641428&r1=1641427&r2=1641428&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/AddressParser.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/AddressParser.java Mon Nov 24 17:33:45 2014
@@ -20,7 +20,6 @@
package javax.mail.internet;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
@@ -782,7 +781,7 @@ class AddressParser {
StringBuffer value = new StringBuffer();
// save the start position for the token.
- int startPosition = position;
+ //int startPosition = position;
// step over the quote delimiter.
nextChar();
@@ -981,7 +980,7 @@ class AddressParser {
int phraseCount = 0;
AddressToken token = tokens.nextRealToken();
- // now scan to the semi color, ensuring we have only word or comment tokens.
+ // now scan to the colon, ensuring we have only word or comment tokens.
while (token.type != COLON) {
// only these tokens are allowed here.
if (token.type != ATOM && token.type != QUOTED_LITERAL) {
@@ -1033,19 +1032,17 @@ class AddressParser {
* @exception AddressException
*/
private void validateGroupMailbox(TokenStream tokens) throws AddressException {
- AddressToken first = tokens.nextRealToken();
+ AddressToken token = tokens.nextRealToken();
// is this just a null address in the list? then push the terminator back and return.
- if (first.type == COMMA || first.type == SEMICOLON) {
- tokens.pushToken(first);
+ if (token.type == COMMA || token.type == SEMICOLON) {
+ tokens.pushToken(token);
return;
}
- // now we need to scan ahead to see if we can determine the type.
- AddressToken token = first;
-
+ final AddressToken firstToken = token;
// we need to scan forward to figure out what sort of address this is.
- while (first != null) {
+ while (token != null) {
switch (token.type) {
// until we know the context, these are all just ignored.
case QUOTED_LITERAL:
@@ -1055,8 +1052,7 @@ class AddressParser {
// a LEFT_ANGLE indicates we have a full RFC822 mailbox form. The leading phrase
// is the personal info. The address is inside the brackets.
case LEFT_ANGLE:
- tokens.pushToken(first);
- validatePhrase(tokens, false);
+ validatePhrase(tokens.section(firstToken, token), false);
validateRouteAddr(tokens, true);
return;
@@ -1066,7 +1062,7 @@ class AddressParser {
// we've hit an "@" as the first non-word token. This is probably a simple address in
// the form "user@domain".
case AT_SIGN:
- tokens.pushToken(first);
+ tokens.pushToken(firstToken);
validateAddressSpec(tokens);
return;
@@ -1075,7 +1071,7 @@ class AddressParser {
case COMMA:
// this is the end of the group...handle it like a comma for now.
case SEMICOLON:
- tokens.pushToken(first);
+ tokens.pushToken(firstToken);
validateAddressSpec(tokens);
return;
@@ -1278,22 +1274,25 @@ class AddressParser {
* is a series of "words" separated by ".".
*/
private void validateLocalPart(TokenStream tokens) throws AddressException {
+
while (true) {
// get the token.
- AddressToken token = tokens.nextRealToken();
+ final AddressToken token1 = tokens.nextRealToken();
- // this must be either an atom or a literal.
- if (token.type != ATOM && token.type != QUOTED_LITERAL) {
- illegalAddress("Invalid local part", token);
+ // this must be either an atom or a literal or a period (GERONIMO-5842)
+ if (token1.type != ATOM && token1.type != QUOTED_LITERAL && token1.type != PERIOD) {
+
+ illegalAddress("Invalid local part", token1);
}
// get the next token (white space and comments ignored)
- token = tokens.nextRealToken();
- // if this is a period, we continue parsing
- if (token.type != PERIOD) {
- tokens.pushToken(token);
- // return the token
+ final AddressToken token2 = tokens.nextRealToken();
+ tokens.pushToken(token2); //do not consume this token
+ // if we encounter a @ sign or the end of the token return
+ if (token2.type == AT_SIGN || token2.type == COMMA || token2.type == SEMICOLON || token2.type == END_OF_TOKENS) {
return;
+ } else if(token2.type == ATOM && (token1.type != PERIOD)) {
+ illegalAddress("Invalid local part", token2);
}
}
}
@@ -1521,15 +1520,15 @@ class AddressParser {
private static final byte FLG_SPECIAL = 1;
private static final byte FLG_CONTROL = 2;
- private static final byte FLG_SPACE = 4;
+ //private static final byte FLG_SPACE = 4;
- private static boolean isSpace(char ch) {
+ /*private static boolean isSpace(char ch) {
if (ch > '\u007f') {
return false;
} else {
return (CHARMAP[ch] & FLG_SPACE) != 0;
}
- }
+ }*/
/**
* Quick test to see if a character is an allowed atom character
Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/MimeBodyPart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/MimeBodyPart.java?rev=1641428&r1=1641427&r2=1641428&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/MimeBodyPart.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/MimeBodyPart.java Mon Nov 24 17:33:45 2014
@@ -37,7 +37,6 @@ import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.HeaderTokenizer.Token;
-import javax.swing.text.AbstractDocument.Content;
import org.apache.geronimo.mail.util.ASCIIUtil;
import org.apache.geronimo.mail.util.SessionUtil;
@@ -46,8 +45,8 @@ import org.apache.geronimo.mail.util.Ses
* @version $Rev$ $Date$
*/
public class MimeBodyPart extends BodyPart implements MimePart {
- // constants for accessed properties
- private static final String MIME_DECODEFILENAME = "mail.mime.decodefilename";
+ // constants for accessed properties
+ protected static final String MIME_DECODEFILENAME = "mail.mime.decodefilename";
private static final String MIME_ENCODEFILENAME = "mail.mime.encodefilename";
private static final String MIME_SETDEFAULTTEXTCHARSET = "mail.mime.setdefaulttextcharset";
private static final String MIME_SETCONTENTTYPEFILENAME = "mail.mime.setcontenttypefilename";
@@ -355,9 +354,12 @@ public class MimeBodyPart extends BodyPa
// The Sun implementation appears to update the Content-type name parameter too, based on
// another system property
if (SessionUtil.getBooleanProperty(MIME_SETCONTENTTYPEFILENAME, true)) {
- ContentType type = new ContentType(getContentType());
- type.setParameter("name", name);
- setHeader("Content-Type", type.toString());
+ String currentContentType = getSingleHeader("Content-Type");
+ if(currentContentType !=null) { //GERONIMO-6480
+ ContentType type = new ContentType(getContentType());
+ type.setParameter("name", name);
+ setHeader("Content-Type", type.toString());
+ }
}
}
Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/InternetAddressTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/InternetAddressTest.java?rev=1641428&r1=1641427&r2=1641428&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/InternetAddressTest.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/InternetAddressTest.java Mon Nov 24 17:33:45 2014
@@ -19,6 +19,7 @@
package javax.mail.internet;
+import junit.framework.Assert;
import junit.framework.TestCase;
import java.net.InetAddress;
@@ -31,7 +32,7 @@ import javax.mail.Session;
* @version $Rev$ $Date$
*/
public class InternetAddressTest extends TestCase {
- private InternetAddress address;
+ //private InternetAddress address;
public void testQuotedLiterals() throws Exception {
parseHeaderTest("\"Foo\t\n\\\\\\\"\" <fo...@apache.org>", true, "foo@apache.org", "Foo\t\n\\\"", "\"Foo\t\n\\\\\\\"\" <fo...@apache.org>", false);
@@ -441,6 +442,17 @@ public class InternetAddressTest extends
assertEquals(InternetAddress.getLocalAddress(session), new InternetAddress("tester@incubator.apache.org"));
}
+
+ public void testGERONIMO5842() throws AddressException {
+ InternetAddress[] addresses = InternetAddress.parse("k..allen@apache.org");
+ Assert.assertNotNull(addresses);
+ Assert.assertEquals(1, addresses.length);
+ addresses[0].validate();
+
+ InternetAddress.parse("k..@apache.org");
+ InternetAddress.parse("k....@apache.org");
+ InternetAddress.parse("k...allen...@apache.org");
+ }
private InternetAddress[] getGroup(String address, boolean strict) throws AddressException
{
@@ -449,9 +461,9 @@ public class InternetAddressTest extends
}
- protected void setUp() throws Exception {
+ /*protected void setUp() throws Exception {
address = new InternetAddress();
- }
+ }*/
private void parseHeaderTest(String address, boolean strict, String resultAddr, String personal, String toString, boolean group) throws Exception
{
@@ -479,14 +491,14 @@ public class InternetAddressTest extends
validateAddress(new InternetAddress(address), resultAddr, personal, toString, group);
}
- private void constructorErrorTest(String address, boolean strict) throws Exception
+ /*private void constructorErrorTest(String address, boolean strict) throws Exception
{
try {
InternetAddress foo = new InternetAddress(address, strict);
fail("Expected AddressException");
} catch (AddressException e) {
}
- }
+ }*/
private void parseTest(String address, boolean strict, String resultAddr, String personal, String toString, boolean group) throws Exception
{
@@ -495,14 +507,14 @@ public class InternetAddressTest extends
validateAddress(addresses[0], resultAddr, personal, toString, group);
}
- private void parseErrorTest(String address, boolean strict) throws Exception
+ /*private void parseErrorTest(String address, boolean strict) throws Exception
{
try {
InternetAddress.parse(address, strict);
fail("Expected AddressException");
} catch (AddressException e) {
}
- }
+ }*/
private void parseDefaultTest(String address, String resultAddr, String personal, String toString, boolean group) throws Exception
{
@@ -511,14 +523,14 @@ public class InternetAddressTest extends
validateAddress(addresses[0], resultAddr, personal, toString, group);
}
- private void parseDefaultErrorTest(String address) throws Exception
+ /*private void parseDefaultErrorTest(String address) throws Exception
{
try {
InternetAddress.parse(address);
fail("Expected AddressException");
} catch (AddressException e) {
}
- }
+ }*/
private void validateTest(String address) throws Exception {
InternetAddress test = new InternetAddress();
Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java?rev=1641428&r1=1641427&r2=1641428&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/test/java/javax/mail/internet/MimeBodyPartTest.java Mon Nov 24 17:33:45 2014
@@ -102,6 +102,10 @@ public class MimeBodyPartTest extends Te
part.setDescription(complexSubject, "UTF-8");
assertEquals(part.getDescription(), complexSubject);
assertEquals(part.getHeader("Content-Description", null), MimeUtility.encodeText(complexSubject, "UTF-8", null));
+
+ part.setDescription(mungedSubject, "UTF-8");
+ assertEquals(part.getDescription(), mungedSubject);
+ assertEquals(part.getHeader("Content-Description", null), MimeUtility.encodeText(mungedSubject, "UTF-8", null));
part.setDescription(null);
assertNull(part.getDescription());
@@ -109,6 +113,7 @@ public class MimeBodyPartTest extends Te
public void testSetFileName() throws Exception {
MimeBodyPart part = new MimeBodyPart();
+ part.addHeader("Content-Type", "application/octet-stream"); //GERONIMO-6480
part.setFileName("test.dat");
assertEquals("test.dat", part.getFileName());