static Map<String, String> decodeRFC2231(String header) {
public static Map<String, String> decodeRFC2231(String header) {
    static Map<String, String> decodeRFC2231(String header) {        if (header == null)            return null;        header = header.trim();        RFC2231Data rfc2231 = new RFC2231Data();        Map<String, String> attrs = new HashMap<String, String>();        boolean escaped = false;        for (int i = 0, count = header.length(); i < count; i++) {            char c = header.charAt(i);            if (rfc2231.state == RFC2231State.SLOP) {                if (c == ';' || c == '\n' || c == '\r')                    rfc2231.setState(RFC2231State.PARAM);            } else if (c == '\r' || c == '\n') {                if (!attrs.isEmpty() || rfc2231.value.length() > 0) {                    rfc2231.saveToMap(attrs);                    rfc2231.setState(RFC2231State.PARAM);                }                // otherwise, it's just folding and we can effectively just ignore the CR/LF            } else if (rfc2231.state == RFC2231State.PARAM) {                if (c == '=')                    rfc2231.setState(RFC2231State.EQUALS);                else if (c == '*')                    rfc2231.setState(RFC2231State.EXTENDED);                else if (c != ' ' && c != '\t')                    rfc2231.addKeyChar(c);            } else if (rfc2231.state == RFC2231State.VALUE) {                if (c != ';' && c != ' ' && c != '\t') {                    rfc2231.addValueChar(c);                } else {                    rfc2231.saveToMap(attrs);                    rfc2231.setState(c == ';' ? RFC2231State.PARAM : RFC2231State.SLOP);                }            } else if (rfc2231.state == RFC2231State.QVALUE) {                if (!escaped && c == '\\') {                    escaped = true;                } else if (escaped || c != '"') {                    rfc2231.addValueChar(c);  escaped = false;                } else {                    rfc2231.saveToMap(attrs);                    rfc2231.setState(RFC2231State.SLOP);                }            } else if (rfc2231.state == RFC2231State.EQUALS) {                if (c == ';') {                    rfc2231.saveToMap(attrs);                    rfc2231.setState(RFC2231State.PARAM);                } if (c == '"') {                    escaped = false;                    rfc2231.setState(RFC2231State.QVALUE);                } else {                    rfc2231.addValueChar(c);                    rfc2231.setState(RFC2231State.VALUE);                }            } else if (rfc2231.state == RFC2231State.EXTENDED) {                if (c >= '0' && c <= '9') {                    if (c != '0')                        rfc2231.setContinued();                    rfc2231.setState(RFC2231State.CONTINUED);                } else if (c == '=') {                    rfc2231.setEncoded();                    rfc2231.setState(rfc2231.continued ? RFC2231State.VALUE : RFC2231State.CHARSET);                }            } else if (rfc2231.state == RFC2231State.CONTINUED) {                if (c == '=')                    rfc2231.setState(RFC2231State.EQUALS);                else if (c == '*')                    rfc2231.setState(RFC2231State.EXTENDED);                else if (c >= '0' && c <= '9')                    rfc2231.setContinued();            } else if (rfc2231.state == RFC2231State.CHARSET) {                if (c == '\'')                    rfc2231.setState(RFC2231State.LANG);                else                    rfc2231.addCharsetChar(c);            } else if (rfc2231.state == RFC2231State.LANG) {                if (c == '\'')                    rfc2231.setState(RFC2231State.VALUE);            }        }        rfc2231.saveToMap(attrs);        return attrs;    }