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:
parent
44e6900ec6
commit
8daec02f33
@ -1946,7 +1946,11 @@ public abstract class ExchangeSession {
|
||||
// message not loaded, try to get headers only
|
||||
InputStream headers = getMimeHeaders();
|
||||
if (headers != null) {
|
||||
result = new InternetHeaders(headers).getMatchingHeaderLines(headerNames);
|
||||
if (headerNames == null) {
|
||||
result = new InternetHeaders(headers).getAllHeaderLines();
|
||||
} else {
|
||||
result = new InternetHeaders(headers).getMatchingHeaderLines(headerNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -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,25 +886,19 @@ 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) {
|
||||
baos.write("Content-class: ".getBytes("UTF-8"));
|
||||
baos.write(message.contentClass.getBytes("UTF-8"));
|
||||
// OSX Lion special flags request
|
||||
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);
|
||||
baos.write(10);
|
||||
} else {
|
||||
Enumeration headerEnumeration = messageWrapper.getMatchingHeaderLines(requestedHeaders);
|
||||
while (headerEnumeration.hasMoreElements()) {
|
||||
baos.write(((String) headerEnumeration.nextElement()).getBytes("UTF-8"));
|
||||
baos.write(13);
|
||||
baos.write(10);
|
||||
} else {
|
||||
Enumeration headerEnumeration = messageWrapper.getMatchingHeaderLines(requestedHeaders);
|
||||
while (headerEnumeration.hasMoreElements()) {
|
||||
baos.write(((String) headerEnumeration.nextElement()).getBytes("UTF-8"));
|
||||
baos.write(13);
|
||||
baos.write(10);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// write headers only
|
||||
partOutputStream = new PartOutputStream(baos, true, false, startIndex, maxSize);
|
||||
partInputStream = messageWrapper.getRawInputStream();
|
||||
}
|
||||
} else {
|
||||
MimePart bodyPart = messageWrapper.getMimeMessage();
|
||||
|
@ -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("."));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user