mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -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) {
|
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)) {
|
if (equalsIgnoreCase(get(i), key)) {
|
||||||
return get(i + 1);
|
return get(i + 1);
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ public class ImapResponseParser {
|
|||||||
return false;
|
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))) {
|
if (equalsIgnoreCase(key, get(i))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -443,7 +443,7 @@ public class ImapResponseParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getKeyIndex(Object key) {
|
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))) {
|
if (equalsIgnoreCase(key, get(i))) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -1655,13 +1655,16 @@ public class ImapStore extends Store {
|
|||||||
|
|
||||||
if (fetchList.containsKey("BODY")) {
|
if (fetchList.containsKey("BODY")) {
|
||||||
int index = fetchList.getKeyIndex("BODY") + 2;
|
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
|
// Check if there's an origin octet
|
||||||
if (result instanceof String) {
|
if (result instanceof String) {
|
||||||
String originOctet = (String)result;
|
String originOctet = (String) result;
|
||||||
if (originOctet.startsWith("<")) {
|
if (originOctet.startsWith("<") && (index + 1) < size) {
|
||||||
result = fetchList.getObject(index + 1);
|
result = fetchList.getObject(index + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,36 @@ public class ImapResponseParserTest extends TestCase {
|
|||||||
assertEquals("token2", respTextCode.get(1));
|
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) {
|
private ImapResponseParser createParser(String response) {
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(response.getBytes());
|
ByteArrayInputStream in = new ByteArrayInputStream(response.getBytes());
|
||||||
PeekableInputStream pin = new PeekableInputStream(in);
|
PeekableInputStream pin = new PeekableInputStream(in);
|
||||||
|
Loading…
Reference in New Issue
Block a user