Return-Path: X-Original-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Delivered-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2C1B54711 for ; Mon, 6 Jun 2011 15:24:41 +0000 (UTC) Received: (qmail 49705 invoked by uid 500); 6 Jun 2011 15:24:41 -0000 Delivered-To: apmail-james-mime4j-dev-archive@james.apache.org Received: (qmail 49640 invoked by uid 500); 6 Jun 2011 15:24:40 -0000 Mailing-List: contact mime4j-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mime4j-dev@james.apache.org Delivered-To: mailing list mime4j-dev@james.apache.org Received: (qmail 49632 invoked by uid 99); 6 Jun 2011 15:24:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 15:24:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jun 2011 15:24:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 673D423889C5; Mon, 6 Jun 2011 15:24:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1132671 - in /james/mime4j/trunk/dom/src: main/java/org/apache/james/mime4j/field/ test/java/org/apache/james/mime4j/field/ Date: Mon, 06 Jun 2011 15:24:12 -0000 To: mime4j-dev@james.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110606152412.673D423889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Mon Jun 6 15:24:11 2011 New Revision: 1132671 URL: http://svn.apache.org/viewvc?rev=1132671&view=rev Log: MIME4J-197: added lenient implementations of ContentLocationField and MimeVersionField Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java (with props) james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java (with props) james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java (with props) james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java (with props) james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java (with props) james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java (with props) Removed: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/FieldTest.java Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java?rev=1132671&r1=1132670&r2=1132671&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java (original) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLanguageFieldLenientImpl.java Mon Jun 6 15:24:11 2011 @@ -49,6 +49,7 @@ public class ContentLanguageFieldLenient private void parse() { parsed = true; + languages = new ArrayList(); RawField f = getRawField(); ByteSequence buf = f.getRaw(); int pos = f.getDelimiterIdx() + 1; @@ -60,7 +61,6 @@ public class ContentLanguageFieldLenient buf = ContentUtil.encode(body); pos = 0; } - languages = new ArrayList(); ParserCursor cursor = new ParserCursor(pos, buf.length()); for (;;) { String token = RawFieldParser.parseToken(buf, cursor, DELIM); Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java?rev=1132671&r1=1132670&r2=1132671&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java (original) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java Mon Jun 6 15:24:11 2011 @@ -29,7 +29,7 @@ import org.apache.james.mime4j.stream.Fi import org.apache.james.mime4j.stream.FieldParser; /** - * Represents a Content-Transfer-Encoding field. + * Represents a Content-Location field. */ public class ContentLocationFieldImpl extends AbstractField implements ContentLocationField { Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java (added) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,89 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import org.apache.james.mime4j.codec.DecodeMonitor; +import org.apache.james.mime4j.dom.field.ContentLocationField; +import org.apache.james.mime4j.stream.Field; +import org.apache.james.mime4j.stream.FieldParser; +import org.apache.james.mime4j.stream.ParserCursor; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.CharsetUtil; +import org.apache.james.mime4j.util.ContentUtil; + +/** + * Represents a Content-Location field. + */ +public class ContentLocationFieldLenientImpl extends AbstractField implements ContentLocationField { + + private final static int[] DELIM = new int[] {}; + + private boolean parsed = false; + private String location; + + ContentLocationFieldLenientImpl(Field rawField, DecodeMonitor monitor) { + super(rawField, monitor); + } + + private void parse() { + parsed = true; + location = null; + RawField f = getRawField(); + ByteSequence buf = f.getRaw(); + int pos = f.getDelimiterIdx() + 1; + if (buf == null) { + String body = f.getBody(); + if (body == null) { + return; + } + buf = ContentUtil.encode(body); + pos = 0; + } + ParserCursor cursor = new ParserCursor(pos, buf.length()); + String token = RawFieldParser.parseValue(buf, cursor, DELIM); + StringBuilder sb = new StringBuilder(token.length()); + for (int i = 0; i < token.length(); i++) { + char ch = token.charAt(i); + if (!CharsetUtil.isWhitespace(ch)) { + sb.append(ch); + } + } + this.location = sb.toString(); + } + + public String getLocation() { + if (!parsed) { + parse(); + } + return location; + } + + public static final FieldParser PARSER = new FieldParser() { + + public ContentLocationField parse(final Field rawField, final DecodeMonitor monitor) { + return new ContentLocationFieldLenientImpl(rawField, monitor); + } + + }; + +} + Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldLenientImpl.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java?rev=1132671&r1=1132670&r2=1132671&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java (original) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DefaultFieldParser.java Mon Jun 6 15:24:11 2011 @@ -103,6 +103,7 @@ public class DefaultFieldParser extends } public DefaultFieldParser() { + super(UnstructuredFieldImpl.PARSER); setFieldParser(FieldName.CONTENT_TYPE, ContentTypeFieldImpl.PARSER); setFieldParser(FieldName.CONTENT_LENGTH, @@ -124,19 +125,19 @@ public class DefaultFieldParser extends setFieldParser(FieldName.MIME_VERSION, MimeVersionFieldImpl.PARSER); - final FieldParser dateTimeParser = DateTimeFieldImpl.PARSER; + FieldParser dateTimeParser = DateTimeFieldImpl.PARSER; setFieldParser(FieldName.DATE, dateTimeParser); setFieldParser(FieldName.RESENT_DATE, dateTimeParser); - final FieldParser mailboxListParser = MailboxListFieldImpl.PARSER; + FieldParser mailboxListParser = MailboxListFieldImpl.PARSER; setFieldParser(FieldName.FROM, mailboxListParser); setFieldParser(FieldName.RESENT_FROM, mailboxListParser); - final FieldParser mailboxParser = MailboxFieldImpl.PARSER; + FieldParser mailboxParser = MailboxFieldImpl.PARSER; setFieldParser(FieldName.SENDER, mailboxParser); setFieldParser(FieldName.RESENT_SENDER, mailboxParser); - final FieldParser addressListParser = AddressListFieldImpl.PARSER; + FieldParser addressListParser = AddressListFieldImpl.PARSER; setFieldParser(FieldName.TO, addressListParser); setFieldParser(FieldName.RESENT_TO, addressListParser); setFieldParser(FieldName.CC, addressListParser); Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java?rev=1132671&r1=1132670&r2=1132671&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java (original) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/DelegatingFieldParser.java Mon Jun 6 15:24:11 2011 @@ -24,15 +24,20 @@ import java.util.Map; import org.apache.james.mime4j.codec.DecodeMonitor; import org.apache.james.mime4j.dom.field.ParsedField; -import org.apache.james.mime4j.dom.field.UnstructuredField; import org.apache.james.mime4j.stream.Field; import org.apache.james.mime4j.stream.FieldParser; public class DelegatingFieldParser implements FieldParser { - private static final FieldParser DEFAULT_PARSER = UnstructuredFieldImpl.PARSER; - private Map> parsers = new HashMap>(); + private final FieldParser defaultParser; + private final Map> parsers; + public DelegatingFieldParser(final FieldParser defaultParser) { + super(); + this.defaultParser = defaultParser; + this.parsers = new HashMap>(); + } + /** * Sets the parser used for the field named name. * @param name the name of the field @@ -45,7 +50,7 @@ public class DelegatingFieldParser imple public FieldParser getParser(final String name) { final FieldParser field = parsers.get(name.toLowerCase()); if (field == null) { - return DEFAULT_PARSER; + return defaultParser; } return field; } Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java?rev=1132671&r1=1132670&r2=1132671&view=diff ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java (original) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/LenientFieldParser.java Mon Jun 6 15:24:11 2011 @@ -88,6 +88,7 @@ public class LenientFieldParser extends } public LenientFieldParser() { + super(UnstructuredFieldImpl.PARSER); setFieldParser(FieldName.CONTENT_TYPE, ContentTypeFieldLenientImpl.PARSER); // lenient setFieldParser(FieldName.CONTENT_LENGTH, @@ -105,9 +106,9 @@ public class LenientFieldParser extends setFieldParser(FieldName.CONTENT_LANGUAGE, ContentLanguageFieldLenientImpl.PARSER); // lenient setFieldParser(FieldName.CONTENT_LOCATION, - ContentLocationFieldImpl.PARSER); + ContentLocationFieldLenientImpl.PARSER); // lenient setFieldParser(FieldName.MIME_VERSION, - MimeVersionFieldImpl.PARSER); + MimeVersionFieldImpl.PARSER); // lenient final FieldParser dateTimeParser = DateTimeFieldImpl.PARSER; setFieldParser(FieldName.DATE, dateTimeParser); Added: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java (added) +++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,112 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import org.apache.james.mime4j.codec.DecodeMonitor; +import org.apache.james.mime4j.dom.field.MimeVersionField; +import org.apache.james.mime4j.stream.Field; +import org.apache.james.mime4j.stream.FieldParser; +import org.apache.james.mime4j.stream.ParserCursor; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.ContentUtil; + +/** + * Represents a MIME-Version field. + */ +public class MimeVersionFieldLenientImpl extends AbstractField implements MimeVersionField { + + private final static int FULL_STOP = '.'; + private final static int[] DELIM1 = new int[] { FULL_STOP }; + private final static int[] DELIM2 = new int[] {}; + + + public static final int DEFAULT_MINOR_VERSION = 0; + public static final int DEFAULT_MAJOR_VERSION = 1; + + private boolean parsed = false; + private int major = DEFAULT_MAJOR_VERSION; + private int minor = DEFAULT_MINOR_VERSION; + + MimeVersionFieldLenientImpl(Field rawField, DecodeMonitor monitor) { + super(rawField, monitor); + } + + private void parse() { + parsed = true; + major = DEFAULT_MAJOR_VERSION; + minor = DEFAULT_MINOR_VERSION; + RawField f = getRawField(); + ByteSequence buf = f.getRaw(); + int pos = f.getDelimiterIdx() + 1; + if (buf == null) { + String body = f.getBody(); + if (body == null) { + return; + } + buf = ContentUtil.encode(body); + pos = 0; + } + ParserCursor cursor = new ParserCursor(pos, buf.length()); + String token1 = RawFieldParser.parseValue(buf, cursor, DELIM1); + try { + major = Integer.parseInt(token1); + if (major < 0) { + major = 0; + } + } catch (NumberFormatException ex) { + } + if (!cursor.atEnd() && buf.byteAt(cursor.getPos()) == FULL_STOP) { + cursor.updatePos(cursor.getPos() + 1); + } + String token2 = RawFieldParser.parseValue(buf, cursor, DELIM2); + try { + minor = Integer.parseInt(token2); + if (minor < 0) { + minor = 0; + } + } catch (NumberFormatException ex) { + } + } + + public int getMinorVersion() { + if (!parsed) { + parse(); + } + return minor; + } + + public int getMajorVersion() { + if (!parsed) { + parse(); + } + return major; + } + + public static final FieldParser PARSER = new FieldParser() { + + public MimeVersionField parse(final Field rawField, final DecodeMonitor monitor) { + return new MimeVersionFieldLenientImpl(rawField, monitor); + } + + }; + +} Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/field/MimeVersionFieldLenientImpl.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java (added) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,63 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import org.apache.james.mime4j.MimeException; +import org.apache.james.mime4j.dom.field.ContentLocationField; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.ContentUtil; + +import junit.framework.TestCase; + +public class ContentLocationFieldTest extends TestCase { + + static ContentLocationField parse(final String s) throws MimeException { + ByteSequence raw = ContentUtil.encode(s); + RawField rawField = RawFieldParser.DEFAULT.parseField(raw); + return ContentLocationFieldImpl.PARSER.parse(rawField, null); + } + + public void testGetSimpleLocation() throws Exception { + ContentLocationField f = parse("Content-Location: stuff"); + String location = f.getLocation(); + assertEquals("stuff", location); + } + + public void testGetQuotedLocation() throws Exception { + ContentLocationField f = parse("Content-Location: \" stuff \""); + String location = f.getLocation(); + assertEquals("stuff", location); + } + + public void testGetLocationWithBlanks() throws Exception { + ContentLocationField f = parse("Content-Location: this / that \t/what not"); + String location = f.getLocation(); + assertEquals("this/that/whatnot", location); + } + + public void testGetLocationWithCommens() throws Exception { + ContentLocationField f = parse("Content-Location: this(blah) / that (yada) /what not"); + String location = f.getLocation(); + assertEquals("this/that/whatnot", location); + } + +} Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java (added) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,63 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import org.apache.james.mime4j.MimeException; +import org.apache.james.mime4j.dom.field.ContentLocationField; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.ContentUtil; + +import junit.framework.TestCase; + +public class LenientContentLocationFieldTest extends TestCase { + + static ContentLocationField parse(final String s) throws MimeException { + ByteSequence raw = ContentUtil.encode(s); + RawField rawField = RawFieldParser.DEFAULT.parseField(raw); + return ContentLocationFieldLenientImpl.PARSER.parse(rawField, null); + } + + public void testGetSimpleLocation() throws Exception { + ContentLocationField f = parse("Content-Location: stuff"); + String location = f.getLocation(); + assertEquals("stuff", location); + } + + public void testGetQuotedLocation() throws Exception { + ContentLocationField f = parse("Content-Location: \" stuff \""); + String location = f.getLocation(); + assertEquals("stuff", location); + } + + public void testGetLocationWithBlanks() throws Exception { + ContentLocationField f = parse("Content-Location: this / that \t/what not"); + String location = f.getLocation(); + assertEquals("this/that/whatnot", location); + } + + public void testGetLocationWithCommens() throws Exception { + ContentLocationField f = parse("Content-Location: this(blah) / that (yada) /what not"); + String location = f.getLocation(); + assertEquals("this/that/whatnot", location); + } + +} Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientContentLocationFieldTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java (added) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,92 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import junit.framework.TestCase; + +import org.apache.james.mime4j.MimeException; +import org.apache.james.mime4j.dom.field.MimeVersionField; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.ContentUtil; + +public class LenientMimeVersionParserTest extends TestCase { + + static MimeVersionField parse(final String s) throws MimeException { + ByteSequence raw = ContentUtil.encode(s); + RawField rawField = RawFieldParser.DEFAULT.parseField(raw); + return MimeVersionFieldLenientImpl.PARSER.parse(rawField, null); + } + + static void check(String input, int expectedMajorVersion, int expectedMinorVersion) throws Exception { + MimeVersionField f = parse("MIME-Version: " + input); + assertEquals("Major version number", expectedMajorVersion, f.getMajorVersion()); + assertEquals("Minor version number", expectedMinorVersion, f.getMinorVersion()); + } + + public void testPlainLine() throws Exception { + check("2.4", 2, 4); + check("25.344", 25, 344); + check("0.1", 0, 1); + check("123234234.0", 123234234, 0); + } + + public void testLineWithComments() throws Exception { + check("2(A comment).4", 2, 4); + check("2(.8).4", 2, 4); + check("(A comment)2.4", 2, 4); + check("2.4(A comment)", 2, 4); + check("2.(A comment)4", 2, 4); + } + + public void testLineWithNestedComments() throws Exception { + check("2(4.45 ( Another ()comment () blah (Wobble(mix)))Whatever).4", 2, 4); + } + + public void testMalformed1() throws Exception { + MimeVersionField f = parse("MIME-Version: 5 "); + assertEquals(5, f.getMajorVersion()); + assertEquals(MimeVersionFieldImpl.DEFAULT_MINOR_VERSION, f.getMinorVersion()); + assertNull(f.getParseException()); + } + + public void testMalformed2() throws Exception { + MimeVersionField f = parse("MIME-Version: 5. "); + assertEquals(5, f.getMajorVersion()); + assertEquals(MimeVersionFieldImpl.DEFAULT_MINOR_VERSION, f.getMinorVersion()); + assertNull(f.getParseException()); + } + + public void testMalformed3() throws Exception { + MimeVersionField f = parse("MIME-Version: .5 "); + assertEquals(MimeVersionFieldImpl.DEFAULT_MAJOR_VERSION, f.getMajorVersion()); + assertEquals(5, f.getMinorVersion()); + assertNull(f.getParseException()); + } + + public void testMalformed4() throws Exception { + MimeVersionField f = parse("MIME-Version: crap "); + assertEquals(MimeVersionFieldImpl.DEFAULT_MAJOR_VERSION, f.getMajorVersion()); + assertEquals(MimeVersionFieldImpl.DEFAULT_MINOR_VERSION, f.getMinorVersion()); + assertNull(f.getParseException()); + } + +} Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/LenientMimeVersionParserTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java?rev=1132671&view=auto ============================================================================== --- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java (added) +++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java Mon Jun 6 15:24:11 2011 @@ -0,0 +1,71 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mime4j.field; + +import junit.framework.TestCase; + +import org.apache.james.mime4j.MimeException; +import org.apache.james.mime4j.dom.field.MimeVersionField; +import org.apache.james.mime4j.stream.RawField; +import org.apache.james.mime4j.stream.RawFieldParser; +import org.apache.james.mime4j.util.ByteSequence; +import org.apache.james.mime4j.util.ContentUtil; + +public class MimeVersionParserTest extends TestCase { + + static MimeVersionField parse(final String s) throws MimeException { + ByteSequence raw = ContentUtil.encode(s); + RawField rawField = RawFieldParser.DEFAULT.parseField(raw); + return MimeVersionFieldImpl.PARSER.parse(rawField, null); + } + + static void check(String input, int expectedMajorVersion, int expectedMinorVersion) throws Exception { + MimeVersionField f = parse("MIME-Version: " + input); + assertEquals("Major version number", expectedMajorVersion, f.getMajorVersion()); + assertEquals("Minor version number", expectedMinorVersion, f.getMinorVersion()); + } + + public void testPlainLine() throws Exception { + check("2.4", 2, 4); + check("25.344", 25, 344); + check("0.1", 0, 1); + check("123234234.0", 123234234, 0); + } + + public void testLineWithComments() throws Exception { + check("2(A comment).4", 2, 4); + check("2(.8).4", 2, 4); + check("(A comment)2.4", 2, 4); + check("2.4(A comment)", 2, 4); + check("2.(A comment)4", 2, 4); + } + + public void testLineWithNestedComments() throws Exception { + check("2(4.45 ( Another ()comment () blah (Wobble(mix)))Whatever).4", 2, 4); + } + + public void testEmptyLine() throws Exception { + MimeVersionField f = parse("MIME-Version: (This is just a comment)"); + assertEquals(MimeVersionFieldImpl.DEFAULT_MAJOR_VERSION, f.getMajorVersion()); + assertEquals(MimeVersionFieldImpl.DEFAULT_MINOR_VERSION, f.getMinorVersion()); + assertNotNull(f.getParseException()); + } + +} Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/field/MimeVersionParserTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain