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 * Pull parser for the MIME messages. Applications can use pull API to continue 325N/A * the parsing MIME messages lazily. 325N/A * MIMEParser parser = ... 325N/A * Iterator<MIMEEvent> it = parser.iterator(); 325N/A * while(it.hasNext()) { 325N/A * MIMEEvent event = it.next(); 325N/A * @author Jitendra Kotamraju 325N/A // Actually, the grammar doesn't support whitespace characters 325N/A // after boundary. But the mail implementation checks for it. 325N/A // We will only check for these many whitespace characters after boundary 325N/A private final int[]
bcs =
new int[
128];
// BnM algo: Bad Character Shift table 325N/A private final int[]
gss;
// BnM algo : Good Suffix Shift table 325N/A * Have we parsed the data from our InputStream yet? 325N/A * Read and process body partsList until we see the 325N/A * terminating boundary line (or EOF). 325N/A private boolean bol;
// beginning of the line 325N/A * Parses the MIME content. At the EOF, it also closes input stream 325N/A // \r\n + boundary + "--\r\n" + lots of LWSP 325N/A * Returns iterator for the parsing events. Use the iterator to advance 325N/A * @return iterator for parsing events 325N/A * Collects the headers for the current part by parsing mesage stream. 325N/A * @return headers for the current part 325N/A * Reads and saves the part of the current attachment part's content. 325N/A * At the end of this method, buf should have the remaining data 325N/A * @return a chunk of the part's content 325N/A // No boundary is found 325N/A // Should we throw exception as there is no closing boundary ? But some impl 325N/A // like SAAJ do not throw excpetion. 325N/A // throw new MIMEParsingException("Reached EOF, but there is no closing MIME boundary."); 325N/A // Is it at the start of a line ? 325N/A // Consider all the whitespace in boundary+whitespace+"\r\n" 325N/A // Check for \n or \r\n in boundary+whitespace+"\n" or boundary+whitespace+"\r\n" 325N/A // Should we throw exception as there is no closing boundary ? But some impl 325N/A // like SAAJ do not throw excpetion. 325N/A //throw new MIMEParsingException("Reached EOF, but there is no closing MIME boundary."); 325N/A // Some more data needed to determine if it is indeed a proper boundary 325N/A * Returns a chunk from the original buffer. A new buffer is 325N/A * created with the remaining bytes. 325N/A * @param chunkSize create a chunk with these many bytes 325N/A * @param remaining bytes from the end of the buffer that need to be copied to 325N/A * the beginning of the new buffer 325N/A // create a new buf and adjust it without this chunk 325N/A * Skips the preamble to find the first attachment part 325N/A // No boundary is found 325N/A // Consider all the whitespace boundary+whitespace+"\r\n" 325N/A // Check for \n or \r\n 325N/A * Pre calculates arrays needed to generate the bad character 325N/A * shift and the good suffix shift. Only the last seven bits 325N/A * are used to see if chars match; This keeps the tables small 325N/A * and covers the heavily used ASCII range, but occasionally 325N/A * results in an aliased match for the bad character shift. 325N/A // Precalculate part of the bad character shift 325N/A // It is a table for where in the pattern each 325N/A // lower 7-bit value occurs 325N/A // Precalculate the good suffix shift 325N/A // i is the shift amount being considered 325N/A // j is the beginning index of suffix being considered 325N/A // Testing for good suffix 325N/A // src[j..len] is a good suffix 325N/A // No match. The array has already been 325N/A // filled up with correct values before. 325N/A // This fills up the remaining of optoSft 325N/A // any suffix can not have larger shift amount 325N/A // then its sub-suffix. Why??? 325N/A // Set the guard value because of unicode compression 325N/A * Finds the boundary in the given buffer using Boyer-Moore algo. 325N/A * @param mybuf boundary to be searched in this mybuf 325N/A * @param off start index in mybuf 325N/A * @param len number of bytes in mybuf 325N/A * @return -1 if there is no match or index where the match starts 325N/A // Loop over all possible match positions in text 325N/A // Loop over pattern from right to left 325N/A // Shift search to the right by the maximum of the 325N/A // bad character shift and the good suffix shift 325N/A // Entire pattern matched starting at off 325N/A * Fills the remaining buf to the full capacity 325N/A * Read a line containing only ASCII characters from the input 325N/A * stream. A line is terminated by a CR or NL or CR-NL sequence. 325N/A * A common error is a CR-CR-NL sequence, which will also terminate 325N/A * The line terminator is not returned as part of the returned 325N/A * String. Returns null if no data is available. <p> 325N/A * This class is similar to the deprecated 325N/A * <code>DataInputStream.readLine()</code>