Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2015 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package javax.mail.internet;
import java.util.*;
import java.io.*;
import com.sun.mail.util.PropUtil;
import com.sun.mail.util.ASCIIUtility;
/**
* This class holds MIME parameters (attribute-value pairs).
* The mail.mime.encodeparameters and
* mail.mime.decodeparameters System properties
* control whether encoded parameters, as specified by
* RFC 2231,
* are supported. By default, such encoded parameters are
* supported.
*
* Also, in the current implementation, setting the System property
* mail.mime.decodeparameters.strict to "true"
* will cause a ParseException to be thrown for errors
* detected while decoding encoded parameters. By default, if any
* decoding errors occur, the original (undecoded) string is used.
*
* The current implementation supports the System property
* mail.mime.parameters.strict, which if set to false
* when parsing a parameter list allows parameter values
* to contain whitespace and other special characters without
* being quoted; the parameter value ends at the next semicolon.
* If set to true (the default), parameter values are required to conform
* to the MIME specification and must be quoted if they contain whitespace
* or special characters.
*
* @author John Mani
* @author Bill Shannon
*/
public class ParameterList {
/**
* The map of name, value pairs.
* The value object is either a String, for unencoded
* values, or a Value object, for encoded values,
* or a MultiValue object, for multi-segment parameters,
* or a LiteralValue object for strings that should not be encoded.
*
* We use a LinkedHashMap so that parameters are (as much as
* possible) kept in the original order. Note however that
* multi-segment parameters (see below) will appear in the
* position of the first seen segment and orphan segments
* will all move to the end.
*/
// keep parameters in order
private Map list = new LinkedHashMap();
/**
* A set of names for multi-segment parameters that we
* haven't processed yet. Normally such names are accumulated
* during the inital parse and processed at the end of the parse,
* but such names can also be set via the set method when the
* IMAP provider accumulates pre-parsed pieces of a parameter list.
* (A special call to the set method tells us when the IMAP provider
* is done setting parameters.)
*
* A multi-segment parameter is defined by RFC 2231. For example,
* "title*0=part1; title*1=part2", which represents a parameter
* named "title" with value "part1part2".
*
* Note also that each segment of the value might or might not be
* encoded, indicated by a trailing "*" on the parameter name.
* If any segment is encoded, the first segment must be encoded.
* Only the first segment contains the charset and language
* information needed to decode any encoded segments.
*
* RFC 2231 introduces many possible failure modes, which we try
* to handle as gracefully as possible. Generally, a failure to
* decode a parameter value causes the non-decoded parameter value
* to be used instead. Missing segments cause all later segments
* to be appear as independent parameters with names that include
* the segment number. For example, "title*0=part1; title*1=part2;
* title*3=part4" appears as two parameters named "title" and "title*3".
*/
private Set multisegmentNames;
/**
* A map containing the segments for all not-yet-processed
* multi-segment parameters. The map is indexed by "name*seg".
* The value object is either a String or a Value object.
* The Value object is not decoded during the initial parse
* because the segments may appear in any order and until the
* first segment appears we don't know what charset to use to
* decode the encoded segments. The segments are hex decoded
* in order, combined into a single byte array, and converted
* to a String using the specified charset in the
* combineMultisegmentNames method.
*/
private Map slist;
/**
* MWB 3BView: The name of the last parameter added to the map.
* Used for the AppleMail hack.
*/
private String lastName = null;
private static final boolean encodeParameters =
PropUtil.getBooleanSystemProperty("mail.mime.encodeparameters", true);
private static final boolean decodeParameters =
PropUtil.getBooleanSystemProperty("mail.mime.decodeparameters", true);
private static final boolean decodeParametersStrict =
PropUtil.getBooleanSystemProperty(
"mail.mime.decodeparameters.strict", false);
private static final boolean applehack =
PropUtil.getBooleanSystemProperty("mail.mime.applefilenames", false);
private static final boolean windowshack =
PropUtil.getBooleanSystemProperty("mail.mime.windowsfilenames", false);
private static final boolean parametersStrict =
PropUtil.getBooleanSystemProperty("mail.mime.parameters.strict", true);
private static final boolean splitLongParameters =
PropUtil.getBooleanSystemProperty(
"mail.mime.splitlongparameters", true);
/**
* A struct to hold an encoded value.
* A parsed encoded value is stored as both the
* decoded value and the original encoded value
* (so that toString will produce the same result).
* An encoded value that is set explicitly is stored
* as the original value and the encoded value, to
* ensure that get will return the same value that
* was set.
*/
private static class Value {
String value;
String charset;
String encodedValue;
}
/**
* A struct to hold a literal value that shouldn't be further encoded.
*/
private static class LiteralValue {
String value;
}
/**
* A struct for a multi-segment parameter. Each entry in the
* List is either a String or a Value object. When all the
* segments are present and combined in the combineMultisegmentNames
* method, the value field contains the combined and decoded value.
* Until then the value field contains an empty string as a placeholder.
*/
private static class MultiValue extends ArrayList