List of usage examples for javax.mail.internet HeaderTokenizer HeaderTokenizer
public HeaderTokenizer(String header, String delimiters, boolean skipComments)
From source file:immf.Util.java
public static String getParameter(String header, String name) { HeaderTokenizer tokenizer = new HeaderTokenizer(header, HeaderTokenizer.MIME, true); HeaderTokenizer.Token token;// w ww. ja v a 2 s . c o m StringBuffer sb = new StringBuffer(); // It is specified in first encoded-part. Encoding encoding = new Encoding(); String n; String v; try { while (true) { token = tokenizer.next(); if (token.getType() == HeaderTokenizer.Token.EOF) break; if (token.getType() != ';') continue; token = tokenizer.next(); checkType(token); n = token.getValue(); token = tokenizer.next(); if (token.getType() != '=') { throw new ParseException("Illegal token : " + token.getValue()); } token = tokenizer.next(); checkType(token); v = token.getValue(); if (n.equalsIgnoreCase(name)) { // It is not divided and is not encoded. return v; } int index = name.length(); if (!n.startsWith(name) || n.charAt(index) != '*') { // another parameter continue; } // be folded, or be encoded int lastIndex = n.length() - 1; if (n.charAt(lastIndex) == '*') { sb.append(decodeRFC2231(v, encoding)); } else { sb.append(v); } if (index == lastIndex) { // not folding break; } } return new String(sb); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } throw new InternalError(); }