The encoded word '=?ISO-8859-1?Q?' caused an IndexOutOfBoundsException to be logged...
[mime4j.git] / src / test / java / org / mime4j / decoder / DecoderUtilTest.java
blob9bfb6fb5dc509131ba928383204f2ea8aa24622f
1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
20 package org.mime4j.decoder;
22 import java.io.UnsupportedEncodingException;
24 import junit.framework.TestCase;
26 import org.apache.log4j.BasicConfigurator;
28 /**
32 * @version $Id: DecoderUtilTest.java,v 1.3 2004/11/09 12:57:40 ntherning Exp $
34 public class DecoderUtilTest extends TestCase {
36 public void setUp() {
37 BasicConfigurator.resetConfiguration();
38 BasicConfigurator.configure();
41 public void testDecodeEncodedWords() {
42 String s = "=?ISO-2022-JP?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
43 + "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
44 + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
45 + "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
46 + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
48 s = DecoderUtil.decodeEncodedWords(s);
49 System.out.println(s);
50 }*/
52 public void testDecodeB() throws UnsupportedEncodingException {
53 String s = DecoderUtil.decodeB("VGhpcyBpcyB0aGUgcGxhaW4gd"
54 + "GV4dCBtZXNzYWdlIQ==", "ISO8859-1");
55 assertEquals("This is the plain text message!", s);
59 public void testDecodeQ() throws UnsupportedEncodingException {
60 String s = DecoderUtil.decodeQ("=e1_=e2=09=E3_=E4_",
61 "ISO8859-1");
62 assertEquals("á â\tã ä ", s);
65 public void testDecodeEncodedWords() {
66 assertEquals("", DecoderUtil.decodeEncodedWords(""));
67 assertEquals("Yada yada", DecoderUtil.decodeEncodedWords("Yada yada"));
68 assertEquals(" áâã\tä",
69 DecoderUtil.decodeEncodedWords("=?iso-8859-1?Q?_=20=e1=e2=E3=09=E4?="));
70 assertEquals("Word 1 ' âã\tä'. Word 2 ' âã\tä'",
71 DecoderUtil.decodeEncodedWords("Word 1 '=?iso-8859-1?Q?_=20=e2=E3=09=E4?="
72 + "'. Word 2 '=?iso-8859-1?q?_=20=e2=E3=09=E4?='"));
73 assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=",
74 DecoderUtil.decodeEncodedWords("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?="));
75 assertEquals("A short text",
76 DecoderUtil.decodeEncodedWords("=?US-ASCII?B?QSBzaG9ydCB0ZXh0?="));
77 assertEquals("A short text again!",
78 DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?="));
79 assertEquals("", DecoderUtil.decodeEncodedWords("=?iso8859-1?Q?="));
80 assertEquals("", DecoderUtil.decodeEncodedWords("=?iso8859-1?b?="));
81 assertEquals("", DecoderUtil.decodeEncodedWords("=?ISO-8859-1?Q?"));
84 * Bug detected on June 7, 2005. Decoding the following string caused
85 * OutOfMemoryError.
87 assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));