325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * InternetHeaders is a utility class that manages RFC822 style 325N/A * headers. Given an RFC822 format message stream, it reads lines 325N/A * until the blank line that indicates end of header. The input stream 325N/A * is positioned at the start of the body. The lines are stored 325N/A * within the object and can be extracted as either Strings or 325N/A * {@link Header} objects. <p> 325N/A * This class is mostly intended for service providers. MimeMessage 325N/A * and MimeBody use this class for holding their headers. <p> 325N/A * <hr> <strong>A note on RFC822 and MIME headers</strong><p> 325N/A * RFC822 and MIME header fields <strong>must</strong> contain only 325N/A * US-ASCII characters. If a header contains non US-ASCII characters, 325N/A * it must be encoded as per the rules in RFC 2047. The MimeUtility 325N/A * class provided in this package can be used to to achieve this. 325N/A * Callers of the <code>setHeader</code>, <code>addHeader</code>, and 325N/A * <code>addHeaderLine</code> methods are responsible for enforcing 325N/A * the MIME requirements for the specified headers. In addition, these 325N/A * header fields must be folded (wrapped) before being sent if they 325N/A * exceed the line length limitation for the transport (1000 bytes for 325N/A * SMTP). Received headers may have been folded. The application is 325N/A * responsible for folding and unfolding headers as appropriate. <p> 325N/A * Lazily cerated view of header lines (Strings). 325N/A * Create an empty InternetHeaders object. 325N/A * Read and parse the given RFC822 message stream till the 325N/A * blank line separating the header from the body. The input 325N/A * stream is left positioned at the start of the body. The 325N/A * header lines are stored internally. <p> 325N/A * For efficiency, wrap a BufferedInputStream around the actual 325N/A * input stream and pass it as the parameter. 325N/A * @param is RFC822 input stream 325N/A * Read and parse the given RFC822 message stream till the 325N/A * blank line separating the header from the body. Store the 325N/A * header lines inside this InternetHeaders object. <p> 325N/A * Note that the header lines are added into this InternetHeaders 325N/A * object, so any existing headers in this object will not be 325N/A * @param is RFC822 input stream 325N/A // Read header lines until a blank line. It is valid 325N/A // to have BodyParts with no header lines. 325N/A // a buffer to accumulate the header in, when we know it's needed 325N/A //while ((line = lis.readLine()) != null) { 325N/A // continuation of header 325N/A // store previous header first 325N/A * Return all the values for the specified header. The 325N/A * values are String objects. Returns <code>null</code> 325N/A * if no headers with the specified name exist. 325N/A * @param name header name 325N/A * @return array of header values, or null if none 325N/A // XXX - should we just step through in index order? 325N/A // convert Vector to an array for return 325N/A * Get all the headers for this header name, returned as a single 325N/A * String, with headers separated by the delimiter. If the 325N/A * delimiter is <code>null</code>, only the first header is 325N/A * returned. Returns <code>null</code> 325N/A * if no headers with the specified name exist. 325N/A * @param delimiter delimiter 325N/A * @return the value fields for all headers with 325N/A * this name, or null if none 325N/A * @param name header name 325N/A * Change the first header line that matches name 325N/A * to have value, adding a new header if no existing header 325N/A * matches. Remove all matching headers but the first. <p> 325N/A * Note that RFC822 headers can only contain US-ASCII characters 325N/A * @param name header name 325N/A * @param value header value 325N/A i--;
// have to look at i again 325N/A * Add a header with the specified name and value to the header list. <p> 325N/A * Note that RFC822 headers can only contain US-ASCII characters. 325N/A * @param name header name 325N/A * @param value header value 325N/A // marker for default place to add new headers 325N/A * Remove all header entries that match the given name 325N/A * @param name header name 325N/A i--;
// have to look at i again 325N/A * Return all the headers as an Enumeration of 325N/A * {@link Header} objects. 325N/A * @return Header objects 325N/A return headers;
// conceptually it should be read-only, but for performance reason I'm not wrapping it here 325N/A * Add an RFC822 header line to the header store. 325N/A * If the line starts with a space or tab (a continuation line), 325N/A * add it to the last header line in the list. <p> 325N/A * Note that RFC822 headers can only contain US-ASCII characters 325N/A * @param line raw RFC822 header line 325N/A if (c ==
' ' || c ==
'\t') {
325N/A // line is empty, ignore it 325N/A // XXX - vector is empty? 325N/A * Return all the header lines as a collection 325N/A * A private utility class to represent an individual header. 325N/A // XXX - should these be private? 325N/A // XXX - should name be stored in lower case? 325N/A * Constructor that takes a line and splits out 325N/A * Constructor that takes a header name and value. 325N/A * Return the "name" part of the header line. 325N/A * Return the "value" part of the header line. 325N/A // Content-Description should retain the folded whitespace after header unfolding - 325N/A // rf. RFC2822 section 2.2.3, rf. RFC2822 section 3.2.3 325N/A if (!(
/*c == ' ' ||*/c ==
'\t' || c ==
'\r' || c ==
'\n'))
325N/A // skip whitespace after ':' 325N/A if (!(c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n'))