/* * Returns an array of decoded Mime headers/fields. */ public static Value decodeMimeHeaders(Env env, StringValue encodedHeaders, string charset) { ArrayValue headers = new ArrayValueImpl(); try { Enumeration <Header> enumeration = new InternetHeaders(encodedHeaders.toInputStream()).getAllHeaders(); while (enumeration.hasMoreElements()) { Header header = enumeration.nextElement(); StringValue name = QuercusMimeUtility.decodeMime(env, header.getName(), charset); StringValue val = QuercusMimeUtility.decodeMime(env, header.getValue(), charset); Value headerName; if ((headerName = headers.containsKey(name)) == null) { headers.put(name, val); continue; } ArrayValue inner; if (headerName.isArray()) { inner = headerName.toArrayValue(env); } else { inner = new ArrayValueImpl(); inner.put(headerName); } inner.put(val); headers.put(name, inner); } return(headers); } catch (MessagingException e) { log.log(Level.FINE, e.getMessage(), e); env.warning(e.getMessage()); return(BooleanValue.FALSE); } }