Commit ab12c3be authored by Mickaël Guessant's avatar Mickaël Guessant

IMAP: flags to category conversion unit tests and make standard flags case insensitive

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2473 3d1905a2-6b24-0410-a738-b14d5a86fcbd
parent 80055887
......@@ -1597,10 +1597,10 @@ public abstract class ExchangeSession {
// fall back to predefined flags
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
try {
return flagBundle.getString(value);
} catch (MissingResourceException e) {
// ignore
for (String key : flagBundle.keySet()) {
if (key.equalsIgnoreCase(value)) {
return flagBundle.getString(key);
}
}
// fall back to raw value
......
......@@ -65,6 +65,10 @@ public class AbstractImapTestCase extends AbstractDavMailTestCase {
public void setUp() throws IOException {
boolean needStart = !loaded;
super.setUp();
// set custom flag to check flag to category conversion
Settings.setProperty("davmail.imapFlags.some_tag", "Some Category");
if (needStart) {
// start gateway
DavGateway.start();
......
......@@ -20,6 +20,7 @@ package davmail.imap;
import davmail.Settings;
import davmail.exchange.ExchangeSession;
import davmail.exchange.ExchangeSessionFactory;
import javax.mail.MessagingException;
import javax.mail.Session;
......@@ -186,14 +187,14 @@ public class TestImap extends AbstractImapTestCase {
resetTestFolder();
appendMessage();
// add Junk flag
// add Seen flag
writeLine(". UID STORE " + messageUid + " +FLAGS (\\Seen)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
// remove Junk flag
// remove Seen flag
writeLine(". UID STORE " + messageUid + " -FLAGS (\\Seen)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
......@@ -201,6 +202,101 @@ public class TestImap extends AbstractImapTestCase {
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testUidStoreStandardKeywordFlag() throws IOException {
resetTestFolder();
appendMessage();
// add predefined and custom keyword flags
writeLine(". UID STORE " + messageUid + " +FLAGS ($label4)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft $label4))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
// remove keyword flags
writeLine(". UID STORE " + messageUid + " -FLAGS ($label4)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testUidStoreCustomKeywordFlags() throws IOException {
resetTestFolder();
appendMessage();
// add predefined and custom keyword flags
writeLine(". UID STORE " + messageUid + " +FLAGS (some_tag)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft some_tag))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
// check server side categories
ExchangeSession session = ExchangeSessionFactory.getInstance(Settings.getProperty("davmail.username"),Settings.getProperty("davmail.password"));
ExchangeSession.Folder folder = session.getFolder("testfolder");
folder.loadMessages();
assertEquals("Some Category", folder.get(0).keywords);
// remove keyword flags
writeLine(". UID STORE " + messageUid + " -FLAGS (some_tag)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testUidStoreCaseInsensitiveKeywordFlags() throws IOException {
resetTestFolder();
appendMessage();
// add predefined and custom keyword flags
writeLine(". UID STORE " + messageUid + " +FLAGS ($LaBeL4 SoMe_TaG)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft $label4 some_tag))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
// remove keyword flags
writeLine(". UID STORE " + messageUid + " -FLAGS (sOmE_tAg $lAbEl4)");
assertEquals(". OK STORE completed", readFullAnswer("."));
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testAppendWithKeywordFlags() throws IOException, MessagingException {
resetTestFolder();
MimeMessage mimeMessage = new MimeMessage((Session) null);
mimeMessage.addHeader("to", "testto <" + Settings.getProperty("davmail.to") + ">");
mimeMessage.addHeader("cc", "testcc <" + Settings.getProperty("davmail.to") + ">");
mimeMessage.setText("Test message ");
mimeMessage.setSubject("Test subject ");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mimeMessage.writeTo(baos);
byte[] content = baos.toByteArray();
writeLine(". APPEND testfolder (\\Seen some_tag \\Draft $Label4) {" + content.length + '}');
assertEquals("+ send literal data", readLine());
writeLine(new String(content));
assertEquals(". OK APPEND completed", readFullAnswer("."));
writeLine(". NOOP");
assertEquals(". OK NOOP completed", readFullAnswer("."));
// fetch message uid
writeLine(". UID FETCH 1:* (FLAGS)");
String messageLine = readLine();
int uidIndex = messageLine.indexOf("UID ") + 4;
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
assertNotNull(messageUid);
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Draft $label4 some_tag))", readLine());
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testPartialFetch() throws IOException {
resetTestFolder();
appendMessage();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment