Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main/java/org/jvnet/mimepull/MIMEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ public class MIMEConfig {
File tempDir;
String prefix;
String suffix;
String headerEncoding;

private MIMEConfig(boolean parseEagerly, int chunkSize,
long inMemoryThreshold, String dir, String prefix, String suffix) {
private MIMEConfig(boolean parseEagerly, int chunkSize, long inMemoryThreshold,
String dir, String prefix, String suffix, String headerEncoding) {
this.parseEagerly = parseEagerly;
this.chunkSize = chunkSize;
this.memoryThreshold = inMemoryThreshold;
this.prefix = prefix;
this.suffix = suffix;
this.headerEncoding = headerEncoding;
setDir(dir);
}

public MIMEConfig() {
this(false, DEFAULT_CHUNK_SIZE, DEFAULT_MEMORY_THRESHOLD, null,
DEFAULT_FILE_PREFIX, null);
DEFAULT_FILE_PREFIX, null, null);
}

boolean isParseEagerly() {
Expand Down Expand Up @@ -133,6 +135,10 @@ String getTempFileSuffix() {
return suffix;
}

public void setHeaderEncoding(String headerEncoding) {
this.headerEncoding = headerEncoding;
}

/**
* @param directory
* temp directory
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/jvnet/mimepull/MIMEParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MIMEParser implements Iterable<MIMEEvent> {
private static final Logger LOGGER = Logger.getLogger(MIMEParser.class.getName());

private static final String HEADER_ENCODING = "ISO8859-1";

// Actually, the grammar doesn't support whitespace characters
// after boundary. But the mail implementation checks for it.
// We will only check for these many whitespace characters after boundary
Expand Down Expand Up @@ -101,6 +101,7 @@ private enum STATE {START_MESSAGE, SKIP_PREAMBLE, START_PART, HEADERS, BODY, END
private byte[] buf;
private int len;
private boolean bol; // beginning of the line
private String headerEncoding;

/*
* Parses the MIME content. At the EOF, it also closes input stream
Expand All @@ -111,6 +112,7 @@ private enum STATE {START_MESSAGE, SKIP_PREAMBLE, START_PART, HEADERS, BODY, END
bl = bndbytes.length;
this.config = config;
gss = new int[bl];
this.headerEncoding = config.headerEncoding != null ? config.headerEncoding : HEADER_ENCODING;
compileBoundaryPattern();

// \r\n + boundary + "--\r\n" + lots of LWSP
Expand Down Expand Up @@ -357,7 +359,7 @@ private static byte[] getBytes(String s) {
return bytes;
}

/**
/**
* Boyer-Moore search method. Copied from java.util.regex.Pattern.java
*
* Pre calculates arrays needed to generate the bad character
Expand Down Expand Up @@ -512,7 +514,7 @@ public String readLine() throws IOException {
return null;
}

String hdr = new String(buf, offset, hdrLen, HEADER_ENCODING);
String hdr = new String(buf, offset, hdrLen, headerEncoding);
offset += hdrLen+lwsp;
return hdr;
}
Expand Down