mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Added some error checks when processing IMAP FETCH responses
This commit is contained in:
parent
4612ceb3c8
commit
0caac114a6
@ -409,7 +409,7 @@ public class ImapResponseParser {
|
||||
|
||||
|
||||
public Object getKeyedValue(Object key) {
|
||||
for (int i = 0, count = size(); i < count; i++) {
|
||||
for (int i = 0, count = size() - 1; i < count; i++) {
|
||||
if (equalsIgnoreCase(get(i), key)) {
|
||||
return get(i + 1);
|
||||
}
|
||||
@ -434,7 +434,7 @@ public class ImapResponseParser {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0, count = size(); i < count; i++) {
|
||||
for (int i = 0, count = size() - 1; i < count; i++) {
|
||||
if (equalsIgnoreCase(key, get(i))) {
|
||||
return true;
|
||||
}
|
||||
@ -443,7 +443,7 @@ public class ImapResponseParser {
|
||||
}
|
||||
|
||||
public int getKeyIndex(Object key) {
|
||||
for (int i = 0, count = size(); i < count; i++) {
|
||||
for (int i = 0, count = size() - 1; i < count; i++) {
|
||||
if (equalsIgnoreCase(key, get(i))) {
|
||||
return i;
|
||||
}
|
||||
|
@ -1655,13 +1655,16 @@ public class ImapStore extends Store {
|
||||
|
||||
if (fetchList.containsKey("BODY")) {
|
||||
int index = fetchList.getKeyIndex("BODY") + 2;
|
||||
result = fetchList.getObject(index);
|
||||
int size = fetchList.size();
|
||||
if (index < size) {
|
||||
result = fetchList.getObject(index);
|
||||
|
||||
// Check if there's an origin octet
|
||||
if (result instanceof String) {
|
||||
String originOctet = (String)result;
|
||||
if (originOctet.startsWith("<")) {
|
||||
result = fetchList.getObject(index + 1);
|
||||
// Check if there's an origin octet
|
||||
if (result instanceof String) {
|
||||
String originOctet = (String) result;
|
||||
if (originOctet.startsWith("<") && (index + 1) < size) {
|
||||
result = fetchList.getObject(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,36 @@ public class ImapResponseParserTest extends TestCase {
|
||||
assertEquals("token2", respTextCode.get(1));
|
||||
}
|
||||
|
||||
public void testImapListMethods() throws IOException {
|
||||
ImapList list = new ImapList();
|
||||
list.add("ONE");
|
||||
list.add("TWO");
|
||||
list.add("THREE");
|
||||
|
||||
assertTrue(list.containsKey("ONE"));
|
||||
assertTrue(list.containsKey("TWO"));
|
||||
assertFalse(list.containsKey("THREE"));
|
||||
assertFalse(list.containsKey("nonexistent"));
|
||||
|
||||
assertEquals("TWO", list.getKeyedValue("ONE"));
|
||||
assertEquals("THREE", list.getKeyedValue("TWO"));
|
||||
assertNull(list.getKeyedValue("THREE"));
|
||||
assertNull(list.getKeyedValue("nonexistent"));
|
||||
|
||||
assertEquals(0, list.getKeyIndex("ONE"));
|
||||
assertEquals(1, list.getKeyIndex("TWO"));
|
||||
|
||||
try {
|
||||
list.getKeyIndex("THREE");
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
} catch (IllegalArgumentException e) { /* do nothing */ }
|
||||
|
||||
try {
|
||||
list.getKeyIndex("nonexistent");
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
} catch (IllegalArgumentException e) { /* do nothing */ }
|
||||
}
|
||||
|
||||
private ImapResponseParser createParser(String response) {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(response.getBytes());
|
||||
PeekableInputStream pin = new PeekableInputStream(in);
|
||||
|
Loading…
Reference in New Issue
Block a user