1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-12 10:42:21 -05:00

IMAP: fix double header content and optimize header fetch with Fetchmail

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2132 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2013-06-04 22:34:06 +00:00
parent 44e6900ec6
commit 8daec02f33
3 changed files with 26 additions and 19 deletions

View File

@ -1946,9 +1946,13 @@ public abstract class ExchangeSession {
// message not loaded, try to get headers only
InputStream headers = getMimeHeaders();
if (headers != null) {
if (headerNames == null) {
result = new InternetHeaders(headers).getAllHeaderLines();
} else {
result = new InternetHeaders(headers).getMatchingHeaderLines(headerNames);
}
}
}
return result;
}

View File

@ -783,7 +783,9 @@ public class ImapConnection extends AbstractConnection {
protected void loadMessage() throws IOException, MessagingException {
if (!message.isLoaded()) {
// flush current buffer
os.write(buffer.toString().getBytes());
String flushString = buffer.toString();
LOGGER.debug(flushString);
os.write(flushString.getBytes());
buffer.setLength(0);
MessageLoadThread.loadMimeMessage(message, os);
}
@ -873,7 +875,7 @@ public class ImapConnection extends AbstractConnection {
// try to parse message part index
String partIndexString = StringUtil.getToken(param, "[", "]");
if ("".equals(partIndexString) || partIndexString == null) {
if (("".equals(partIndexString) || partIndexString == null) && !"RFC822.HEADER".equals(param)) {
// write message with headers
partOutputStream = new PartialOutputStream(baos, startIndex, maxSize);
partInputStream = messageWrapper.getRawInputStream();
@ -884,9 +886,8 @@ public class ImapConnection extends AbstractConnection {
} else if ("RFC822.HEADER".equals(param) || partIndexString.startsWith("HEADER")) {
// Header requested fetch headers
String[] requestedHeaders = getRequestedHeaders(partIndexString);
if (requestedHeaders != null) {
// OSX Lion special flags request
if (requestedHeaders.length == 1 && "content-class".equals(requestedHeaders[0]) && message.contentClass != null) {
if (requestedHeaders != null && requestedHeaders.length == 1 && "content-class".equals(requestedHeaders[0]) && message.contentClass != null) {
baos.write("Content-class: ".getBytes("UTF-8"));
baos.write(message.contentClass.getBytes("UTF-8"));
baos.write(13);
@ -899,11 +900,6 @@ public class ImapConnection extends AbstractConnection {
baos.write(10);
}
}
} else {
// write headers only
partOutputStream = new PartOutputStream(baos, true, false, startIndex, maxSize);
partInputStream = messageWrapper.getRawInputStream();
}
} else {
MimePart bodyPart = messageWrapper.getMimeMessage();
String[] partIndexStrings = partIndexString.split("\\.");

View File

@ -508,4 +508,11 @@ public class TestImap extends AbstractImapTestCase {
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testDoubleHeaderFetch() throws IOException {
writeLine(". SELECT INBOX");
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
writeLine(". UID FETCH 1:* RFC822.HEADER");
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
}