if (i < 0) { if (decodeParametersStrict) throw new ParseException( "Missing charset in encoded value: " + value); return v; // not encoded correctly? return as is. if (li < 0) { if (decodeParametersStrict) throw new ParseException( "Missing language in encoded value: " + value); return v; // not encoded correctly? return as is. } catch (NumberFormatException nex) { if (decodeParametersStrict) throw new ParseException(nex.toString()); } catch (StringIndexOutOfBoundsException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString());
if (i < 0) { if (decodeParametersStrict) throw new ParseException( "Missing charset in encoded value: " + value); return v; // not encoded correctly? return as is. if (li < 0) { if (decodeParametersStrict) throw new ParseException( "Missing language in encoded value: " + value); return v; // not encoded correctly? return as is. } catch (NumberFormatException nex) { if (decodeParametersStrict) throw new ParseException(nex.toString()); } catch (StringIndexOutOfBoundsException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString());
/** * Decode the encoded bytes in value and write them to the OutputStream. */ private static void decodeBytes(String value, OutputStream os) throws ParseException, IOException { /* * Decode the ASCII characters in value * and write them to the stream. */ int i; for (i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '%') { try { String hex = value.substring(i + 1, i + 3); c = (char)Integer.parseInt(hex, 16); i += 2; } catch (NumberFormatException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString()); } catch (StringIndexOutOfBoundsException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString()); } } os.write((byte)c); } } }
/** * Decode the encoded bytes in value and write them to the OutputStream. */ private static void decodeBytes(String value, OutputStream os) throws ParseException, IOException { /* * Decode the ASCII characters in value * and write them to the stream. */ int i; for (i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '%') { try { String hex = value.substring(i + 1, i + 3); c = (char)Integer.parseInt(hex, 16); i += 2; } catch (NumberFormatException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString()); } catch (StringIndexOutOfBoundsException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString()); } } os.write((byte)c); } } }
/** * A special wrapper for a StringBuffer that keeps track of the * number of characters used in a line, wrapping to a new line * as necessary; for use by the toString method. */ private static class ToStringBuffer { private int used; // keep track of how much used on current line private StringBuffer sb = new StringBuffer(); public ToStringBuffer(int used) { this.used = used; } public void addNV(String name, String value) { sb.append("; "); used += 2; int len = name.length() + value.length() + 1; if (used + len > 76) { // overflows ... sb.append("\r\n\t"); // .. start new continuation line used = 8; // account for the starting <tab> char } sb.append(name).append('='); used += name.length() + 1; if (used + value.length() > 76) { // still overflows ... // have to fold value String s = MimeUtility.fold(used, value); sb.append(s); int lastlf = s.lastIndexOf('\n'); if (lastlf >= 0) // always true used += s.length() - lastlf - 1;
/** * A special wrapper for a StringBuffer that keeps track of the * number of characters used in a line, wrapping to a new line * as necessary; for use by the toString method. */ private static class ToStringBuffer { private int used; // keep track of how much used on current line private StringBuilder sb = new StringBuilder(); public ToStringBuffer(int used) { this.used = used; } public void addNV(String name, String value) { sb.append("; "); used += 2; int len = name.length() + value.length() + 1; if (used + len > 76) { // overflows ... sb.append("\r\n\t"); // .. start new continuation line used = 8; // account for the starting <tab> char } sb.append(name).append('='); used += name.length() + 1; if (used + value.length() > 76) { // still overflows ... // have to fold value String s = MimeUtility.fold(used, value); sb.append(s); int lastlf = s.lastIndexOf('\n'); if (lastlf >= 0) // always true used += s.length() - lastlf - 1;
throw new ParseException( "encoded word does not start with \"=?\": " + eword); throw new ParseException( "encoded word does not include charset: " + eword); String charset = eword.substring(start, pos); throw new ParseException( "encoded word does not include encoding: " + eword); String encoding = eword.substring(start, pos); throw new ParseException( "encoded word does not end with \"?=\": " + eword); } catch (IOException ioex) { throw new ParseException(ioex.toString()); } catch (IllegalArgumentException iex) {
} catch (UnsupportedEncodingException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString());
} catch (UnsupportedEncodingException ex) { if (decodeParametersStrict) throw new ParseException(ex.toString());
throw new ParseException( "encoded word does not start with \"=?\": " + eword); throw new ParseException( "encoded word does not include charset: " + eword); String charset = eword.substring(start, pos); throw new ParseException( "encoded word does not include encoding: " + eword); String encoding = eword.substring(start, pos); throw new ParseException( "encoded word does not end with \"?=\": " + eword); } catch (IOException ioex) { throw new ParseException(ioex.toString()); } catch (IllegalArgumentException iex) {
throw new ParseException("Unbalanced quoted string");
throw new ParseException("Unbalanced quoted string");
throw new ParseException("Unbalanced comments");
throw new ParseException("Unbalanced comments");
throw new ParseException("In parameter list <" + s + ">" + ", expected parameter name, " + "got \"" + tk.getValue() + "\""); throw new ParseException("In parameter list <" + s + ">" + ", expected '=', " + "got \"" + tk.getValue() + "\""); throw new ParseException("In parameter list <" + s + ">" + ", expected parameter value, " + "got \"" + tk.getValue() + "\""); list.put(lastName, value); } else { throw new ParseException("In parameter list <" + s + ">" + ", expected ';', got \"" + tk.getValue() + "\"");
throw new ParseException("In parameter list <" + s + ">" + ", expected parameter name, " + "got \"" + tk.getValue() + "\""); throw new ParseException("In parameter list <" + s + ">" + ", expected '=', " + "got \"" + tk.getValue() + "\""); throw new ParseException("In parameter list <" + s + ">" + ", expected parameter value, " + "got \"" + tk.getValue() + "\""); list.put(lastName, value); } else { throw new ParseException("In parameter list <" + s + ">" + ", expected ';', got \"" + tk.getValue() + "\"");
throw new ParseException("In Content-Type string <" + s + ">" + ", expected MIME type, got " + tk.getValue()); throw new ParseException("In Content-Type string <" + s + ">" + ", expected '/', got " + tk.getValue()); throw new ParseException("In Content-Type string <" + s + ">" + ", expected MIME subtype, got " + tk.getValue());
throw new ParseException("In Content-Type string <" + s + ">" + ", expected MIME type, got " + tk.getValue()); throw new ParseException("In Content-Type string <" + s + ">" + ", expected '/', got " + tk.getValue()); throw new ParseException("In Content-Type string <" + s + ">" + ", expected MIME subtype, got " + tk.getValue());
/** * Constructor that takes a ContentDisposition string. The String * is parsed into its constituents: dispostion and parameters. * A ParseException is thrown if the parse fails. * * @param s the ContentDisposition string. * @exception ParseException if the parse fails. * @since JavaMail 1.2 */ public ContentDisposition(String s) throws ParseException { HeaderTokenizer h = new HeaderTokenizer(s, HeaderTokenizer.MIME); HeaderTokenizer.Token tk; // First "disposition" .. tk = h.next(); if (tk.getType() != HeaderTokenizer.Token.ATOM) throw new ParseException("Expected disposition, got " + tk.getValue()); disposition = tk.getValue(); // Then parameters .. String rem = h.getRemainder(); if (rem != null) list = new ParameterList(rem); }
if (tk.getType() != HeaderTokenizer.Token.ATOM) { if (contentDispositionStrict) { throw new ParseException("Expected disposition, got " + tk.getValue());