2010-07-01 09:27:49 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2010 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
package davmail.imap;
|
|
|
|
|
|
|
|
import davmail.Settings;
|
2013-04-09 17:39:18 -04:00
|
|
|
import davmail.exchange.ExchangeSession;
|
2010-07-01 09:27:49 -04:00
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
import javax.mail.MessagingException;
|
|
|
|
import javax.mail.Session;
|
|
|
|
import javax.mail.internet.MimeMessage;
|
2012-09-04 16:41:55 -04:00
|
|
|
import javax.mail.util.SharedByteArrayInputStream;
|
2011-02-02 16:20:10 -05:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
2013-04-09 17:39:18 -04:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Locale;
|
2010-08-24 05:28:40 -04:00
|
|
|
import java.util.Random;
|
2010-07-01 09:27:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IMAP tests, an instance of DavMail Gateway must be available
|
|
|
|
*/
|
2010-10-14 17:40:00 -04:00
|
|
|
@SuppressWarnings({"JavaDoc", "UseOfSystemOutOrSystemErr"})
|
2011-02-02 16:20:10 -05:00
|
|
|
public class TestImap extends AbstractImapTestCase {
|
2010-07-01 09:27:49 -04:00
|
|
|
|
2013-04-09 17:39:18 -04:00
|
|
|
protected String getLastMonth() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.add(Calendar.MONTH, -1);
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
|
|
|
|
formatter.setTimeZone(ExchangeSession.GMT_TIMEZONE);
|
|
|
|
return formatter.format(calendar.getTime());
|
|
|
|
}
|
|
|
|
|
2010-07-29 11:42:07 -04:00
|
|
|
public void testListFolders() throws IOException {
|
|
|
|
writeLine(". LSUB \"\" \"*\"");
|
|
|
|
assertEquals(". OK LSUB completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-11-24 04:40:36 -05:00
|
|
|
public void testListSubFolders() throws IOException {
|
|
|
|
writeLine(". LIST \"\" \"INBOX*\"");
|
|
|
|
assertEquals(". OK LIST completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-07-01 09:27:49 -04:00
|
|
|
public void testSelectInbox() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2011-11-11 06:00:02 -05:00
|
|
|
public void testSelectRoot() throws IOException {
|
|
|
|
writeLine(". SELECT \"\"");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-07-01 11:07:16 -04:00
|
|
|
public void testFetchFlags() throws IOException {
|
|
|
|
writeLine(". UID FETCH 1:* (FLAGS)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-08-21 19:40:24 -04:00
|
|
|
public void testUidSearchUnDeleted() throws IOException {
|
2010-07-01 09:27:49 -04:00
|
|
|
writeLine(". UID SEARCH UNDELETED");
|
2010-07-01 10:23:31 -04:00
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
2010-08-21 19:40:24 -04:00
|
|
|
writeLine(". UID SEARCH NOT DELETED");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
2010-07-01 10:23:31 -04:00
|
|
|
}
|
|
|
|
|
2010-08-21 19:40:24 -04:00
|
|
|
public void testUidSearchdeleted() throws IOException {
|
2012-09-04 16:41:55 -04:00
|
|
|
testSelectInbox();
|
2010-07-01 10:23:31 -04:00
|
|
|
writeLine(". UID SEARCH DELETED");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
2010-07-01 09:27:49 -04:00
|
|
|
}
|
|
|
|
|
2010-07-01 11:07:16 -04:00
|
|
|
public void testStoreUndelete() throws IOException {
|
|
|
|
writeLine(". UID STORE 10 -FLAGS (\\Deleted)");
|
|
|
|
readFullAnswer(".");
|
|
|
|
}
|
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
public void testCreateFolder() throws IOException {
|
|
|
|
writeLine(". DELETE testfolder");
|
|
|
|
readFullAnswer(".");
|
|
|
|
writeLine(". CREATE testfolder");
|
|
|
|
assertEquals(". OK folder created", readFullAnswer("."));
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". SELECT testfolder");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFetchBigMessage() throws IOException, MessagingException {
|
|
|
|
testCreateFolder();
|
|
|
|
// create 10MB message
|
|
|
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
|
|
|
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
|
|
|
|
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
|
|
|
|
Random random = new Random();
|
|
|
|
StringBuilder randomText = new StringBuilder();
|
2011-02-02 16:20:10 -05:00
|
|
|
for (int i = 0; i < 10 * 1024 * 1024; i++) {
|
|
|
|
randomText.append((char) ('a' + random.nextInt(26)));
|
2010-08-24 05:28:40 -04:00
|
|
|
}
|
|
|
|
mimeMessage.setText(randomText.toString());
|
|
|
|
mimeMessage.setSubject("Big subject");
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
mimeMessage.writeTo(baos);
|
|
|
|
byte[] content = baos.toByteArray();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
writeLine(". APPEND testfolder (\\Seen \\Draft) {" + content.length + '}');
|
|
|
|
assertEquals("+ send literal data", readLine());
|
|
|
|
writeLine(new String(content));
|
|
|
|
assertEquals(". OK APPEND completed", readFullAnswer("."));
|
2011-02-02 16:20:10 -05:00
|
|
|
System.out.println("Create time: " + (System.currentTimeMillis() - start) + " ms");
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". NOOP");
|
|
|
|
assertEquals(". OK NOOP completed", readFullAnswer("."));
|
|
|
|
start = System.currentTimeMillis();
|
|
|
|
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY.TEXT)");
|
|
|
|
readFullAnswer(".");
|
2011-02-02 16:20:10 -05:00
|
|
|
System.out.println("Fetch time: " + (System.currentTimeMillis() - start) + " ms");
|
2010-08-24 05:28:40 -04:00
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
2010-08-24 05:28:40 -04:00
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
public void testSelectFolder() throws IOException {
|
|
|
|
writeLine(". SELECT testfolder");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testCreateMessage() throws IOException, MessagingException {
|
2010-08-24 05:28:40 -04:00
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
2010-07-12 02:42:09 -04:00
|
|
|
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
|
|
|
|
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
|
2010-07-02 02:37:18 -04:00
|
|
|
mimeMessage.setText("Test message");
|
|
|
|
mimeMessage.setSubject("Test subject");
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
mimeMessage.writeTo(baos);
|
|
|
|
byte[] content = baos.toByteArray();
|
2010-07-21 06:41:13 -04:00
|
|
|
writeLine(". APPEND testfolder (\\Seen \\Draft) {" + content.length + '}');
|
2010-07-02 02:37:18 -04:00
|
|
|
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));
|
2010-08-24 05:28:40 -04:00
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
assertNotNull(messageUid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testUidStoreDeletedFlag() throws IOException {
|
|
|
|
|
|
|
|
// test deleted flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " +FLAGS (\\Deleted)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Seen \\Deleted \\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
// remove deleted flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " -FLAGS (\\Deleted)");
|
|
|
|
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("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-09 08:54:00 -04:00
|
|
|
public void testUidRemoveSeenFlag() throws IOException {
|
2010-07-02 02:37:18 -04:00
|
|
|
// remove seen flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " FLAGS (\\Draft)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testUidStoreForwardedFlag() throws IOException {
|
|
|
|
// add forwarded flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " +FLAGS ($Forwarded)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft $Forwarded))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
// remove forwarded flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " -FLAGS ($Forwarded)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testUidStoreAnsweredFlag() throws IOException {
|
|
|
|
// add answered flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " +FLAGS (\\Answered)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft \\Answered))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
// remove answered flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " -FLAGS (\\Answered)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testUidStoreJunkFlag() throws IOException {
|
|
|
|
// add Junk flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " +FLAGS (Junk)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (Junk \\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
// remove Junk flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " -FLAGS (Junk)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
2010-07-09 08:54:00 -04:00
|
|
|
public void testUidStoreSeenFlag() throws IOException {
|
|
|
|
// add Junk flag
|
2010-08-24 05:28:40 -04:00
|
|
|
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("."));
|
2010-07-09 08:54:00 -04:00
|
|
|
|
|
|
|
// remove Junk flag
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID STORE " + messageUid + " -FLAGS (\\Seen)");
|
|
|
|
assertEquals(". OK STORE completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (FLAGS)");
|
|
|
|
assertEquals("* 1 FETCH (UID " + messageUid + " FLAGS (\\Draft))", readLine());
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-09 08:54:00 -04:00
|
|
|
}
|
|
|
|
|
2010-07-02 02:45:12 -04:00
|
|
|
public void testPartialFetch() throws IOException {
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID FETCH " + messageUid + " (BODY.PEEK[1.MIME])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-02 02:45:12 -04:00
|
|
|
}
|
|
|
|
|
2010-09-13 18:19:25 -04:00
|
|
|
public void testHeaderFetch() throws IOException {
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (BODY[HEADER.FIELDS (DATE SUBJECT FROM CONTENT-TYPE TO CC BCC MESSAGE-ID IN-REPLY-TO REFERENCES)])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-11-10 16:21:41 -05:00
|
|
|
public void testHeaderBodyFetch() throws IOException {
|
|
|
|
writeLine(". UID FETCH " + messageUid + " (UID BODY.PEEK[HEADER.FIELDS (Content-Type Content-Transfer-Encoding)] BODY.PEEK[TEXT]<0.2048>)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-07-09 17:25:18 -04:00
|
|
|
public void testFetchInternalDate() throws IOException {
|
2010-08-24 05:28:40 -04:00
|
|
|
writeLine(". UID FETCH " + messageUid + " (INTERNALDATE)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
2010-07-09 17:25:18 -04:00
|
|
|
}
|
|
|
|
|
2010-07-02 02:37:18 -04:00
|
|
|
|
|
|
|
public void testDeleteFolder() throws IOException {
|
|
|
|
writeLine(". DELETE testfolder");
|
2010-08-24 05:28:40 -04:00
|
|
|
assertEquals(". OK folder deleted", readFullAnswer("."));
|
2010-07-02 02:37:18 -04:00
|
|
|
}
|
|
|
|
|
2010-07-01 09:27:49 -04:00
|
|
|
public void testLogout() throws IOException {
|
|
|
|
writeLine(". LOGOUT");
|
|
|
|
assertEquals("* BYE Closing connection", socketReader.readLine());
|
2011-03-07 17:30:25 -05:00
|
|
|
assertEquals(". OK LOGOUT completed", socketReader.readLine());
|
2010-09-02 16:21:41 -04:00
|
|
|
clientSocket = null;
|
2010-07-01 09:27:49 -04:00
|
|
|
}
|
2010-08-24 05:28:40 -04:00
|
|
|
|
2010-10-02 12:16:27 -04:00
|
|
|
public void testCopyMessage() throws IOException, InterruptedException, MessagingException {
|
|
|
|
testCreateFolder();
|
|
|
|
testCreateMessage();
|
|
|
|
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("."));
|
|
|
|
|
2011-02-02 16:20:10 -05:00
|
|
|
writeLine(". UID COPY " + messageUid + " Trash");
|
2010-10-02 12:16:27 -04:00
|
|
|
assertEquals(". OK copy completed", readFullAnswer("."));
|
|
|
|
|
|
|
|
writeLine(". COPY 1 Trash");
|
|
|
|
assertEquals(". OK copy completed", readFullAnswer("."));
|
|
|
|
|
|
|
|
testDeleteFolder();
|
|
|
|
}
|
2010-10-14 17:40:00 -04:00
|
|
|
|
|
|
|
public void testFetchInboxEnvelope() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID FETCH 1:* (ENVELOPE)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFetchInboxBodyStructure() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID FETCH 1:* (BODYSTRUCTURE)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2010-11-22 04:46:19 -05:00
|
|
|
public void testFetchRfc822Header() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID FETCH 1:* (UID RFC822.HEADER RFC822.SIZE FLAGS)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testThunderbirdHeaderFetch() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID FETCH 1:* (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type)])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2011-02-02 16:20:10 -05:00
|
|
|
|
2011-06-07 16:42:25 -04:00
|
|
|
public void testSearchHeader() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID SEARCH HEADER X-TUID testvalue");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID SEARCH HEADER X-OfflineIMAP \"testvalue\"");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2011-08-29 17:04:30 -04:00
|
|
|
public void testSearchUndraft() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID SEARCH UNDRAFT");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID SEARCH DRAFT");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2011-02-02 16:20:10 -05:00
|
|
|
public void testBrokenPipe() throws IOException, InterruptedException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY.TEXT)");
|
|
|
|
socketReader.readLine();
|
|
|
|
// force close connection
|
|
|
|
clientSocket.close();
|
|
|
|
Thread.sleep(5000);
|
|
|
|
}
|
2011-11-11 06:00:02 -05:00
|
|
|
|
|
|
|
public void testSearchCharset() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine("UID SEARCH CHARSET UTF-8 (HEADER SUBJECT testé)");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testWanderLust() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". uid fetch 1:* (body.peek[header.fields (Subject From To Cc Date Message-Id References In-Reply-To Delivered-To)] rfc822.size flags)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2012-02-09 18:34:38 -05:00
|
|
|
public void testSearchSince() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID SEARCH SINCE 1-Jan-2012 UNDELETED");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSearchText() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". UID SEARCH TEXT test");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-10 05:57:22 -04:00
|
|
|
public void testDraftMessageMessageId() throws IOException, InterruptedException, MessagingException {
|
|
|
|
testCreateFolder();
|
|
|
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
2012-09-04 16:41:55 -04:00
|
|
|
mimeMessage.addHeader("to", "testto <"+Settings.getProperty("davmail.to")+">");
|
2012-05-10 05:57:22 -04:00
|
|
|
mimeMessage.setText("Test message");
|
|
|
|
mimeMessage.setSubject("Test subject");
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
mimeMessage.writeTo(baos);
|
|
|
|
byte[] content = baos.toByteArray();
|
|
|
|
writeLine(". APPEND testfolder (\\Seen \\Draft) {" + content.length + '}');
|
|
|
|
assertEquals("+ send literal data", readLine());
|
|
|
|
writeLine(new String(content));
|
|
|
|
assertEquals(". OK APPEND completed", readFullAnswer("."));
|
2011-11-11 06:00:02 -05:00
|
|
|
|
2012-05-10 05:57:22 -04:00
|
|
|
writeLine(". UID SEARCH UNDELETED (HEADER Message-ID "+mimeMessage.getMessageID().substring(1, mimeMessage.getMessageID().length()-1)+")");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
|
2012-09-04 16:41:55 -04:00
|
|
|
writeLine(". UID SEARCH (HEADER To "+Settings.getProperty("davmail.to")+")");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
|
|
|
|
writeLine(". UID SEARCH (HEADER To testto)");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
|
|
|
|
//testDeleteFolder();
|
2012-05-10 05:57:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFetchOSX() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". FETCH 1:* (FLAGS UID BODY.PEEK[HEADER.FIELDS (content-class)])");
|
|
|
|
assertEquals(". OK FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2012-05-16 12:07:35 -04:00
|
|
|
|
|
|
|
public void testFetchHeadersThunderbird() throws IOException {
|
|
|
|
testSelectInbox();
|
|
|
|
writeLine(". FETCH 1:* (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type)])");
|
|
|
|
assertEquals(". OK FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2012-09-04 16:41:55 -04:00
|
|
|
|
|
|
|
public void testInvalidMime() throws MessagingException, IOException {
|
|
|
|
testCreateFolder();
|
|
|
|
|
|
|
|
MimeMessage mimeMessage = new MimeMessage((Session) null);
|
|
|
|
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
|
|
|
|
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
|
|
|
|
mimeMessage.setText("test");
|
|
|
|
mimeMessage.setSubject("subject");
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
mimeMessage.writeTo(baos);
|
|
|
|
byte[] content = baos.toByteArray();
|
|
|
|
String invalidMessageContent = "MAIL FROM: " + Settings.getProperty("davmail.bcc") + "\n" +
|
|
|
|
"RCPT TO: " + Settings.getProperty("davmail.to") + "\n\n" + new String(content, "UTF-8");
|
|
|
|
|
|
|
|
mimeMessage = new MimeMessage((Session) null, new SharedByteArrayInputStream(invalidMessageContent.getBytes("UTF-8")));
|
|
|
|
baos = new ByteArrayOutputStream();
|
|
|
|
mimeMessage.writeTo(baos);
|
|
|
|
|
|
|
|
content = baos.toByteArray();
|
|
|
|
writeLine(". APPEND testfolder (\\Seen \\Draft) {" + 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 BODYSTRUCTURE)");
|
|
|
|
String messageLine = readLine();
|
|
|
|
int uidIndex = messageLine.indexOf("UID ") + 4;
|
|
|
|
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
assertNotNull(messageUid);
|
|
|
|
|
|
|
|
testDeleteFolder();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFetchHeadersSentThunderbird() throws IOException {
|
|
|
|
writeLine(". SELECT Sent");
|
|
|
|
//writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID SEARCH (SINCE \"01-Jun-2012\")");
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 6071:* (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type)])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:39:18 -04:00
|
|
|
public void testFetchHeadersInboxMutt() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID SEARCH (SINCE \""+getLastMonth()+"\")");
|
|
|
|
String messageLine = readLine();
|
|
|
|
int uidIndex = messageLine.indexOf(" ", "* SEARCH".length()) + 1;
|
|
|
|
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
System.out.println(messageUid);
|
|
|
|
writeLine(". UID FETCH "+messageUid+":* (UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL)])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFetchHeadersInboxOSX() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID SEARCH (SINCE \""+getLastMonth()+"\")");
|
|
|
|
String messageLine = readLine();
|
|
|
|
int uidIndex = messageLine.indexOf(" ", "* SEARCH".length()) + 1;
|
|
|
|
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
|
|
|
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
|
|
|
System.out.println(messageUid);
|
|
|
|
writeLine(". UID FETCH "+messageUid+":* (INTERNALDATE UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (date subject from to cc message-id in-reply-to references x-priority x-uniform-type-identifier x-universally-unique-identifier received-spf x-spam-status x-spam-flag)])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2013-05-14 18:39:26 -04:00
|
|
|
|
|
|
|
public void testSelectInboxTimeout() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
// simulate client timeout
|
|
|
|
try {
|
|
|
|
Thread.sleep(5000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
socketWriter.close();
|
|
|
|
System.in.read();
|
|
|
|
}
|
|
|
|
|
2013-05-28 18:10:36 -04:00
|
|
|
public void testAnotherFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* (BODY.PEEK [HEADER.FIELDS (References X-Ref X-Priority X-MSMail-Priority Importance X-MSOESRec Newsgroups)] ENVELOPE RFC822.SIZE UID FLAGS INTERNALDATE)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:34:06 -04:00
|
|
|
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("."));
|
|
|
|
}
|
|
|
|
|
2013-06-12 12:38:05 -04:00
|
|
|
public void testDoubleHeaderBodyFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 51241 BODY.PEEK[TEXT]");
|
|
|
|
String line = socketReader.readLine();
|
|
|
|
int size = 0;
|
|
|
|
while (!line.startsWith(".")) {
|
|
|
|
line = socketReader.readLine();
|
|
|
|
size += line.length()+2;
|
|
|
|
}
|
|
|
|
System.out.println("actual size "+size);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBodyHeaderFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* BODY[HEADER]");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2013-11-13 16:56:09 -05:00
|
|
|
public void testBodyTextFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* (BODY[HEADER] BODY.PEEK[TEXT])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBodyPartFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY[1])");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
|
|
|
|
2013-06-12 12:38:05 -04:00
|
|
|
public void testOutlookHeaderFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* (UID FLAGS RFC822.SIZE BODY.PEEK[HEADER] INTERNALDATE)");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2013-11-13 16:56:09 -05:00
|
|
|
|
|
|
|
public void testFullHeaderFetch() throws IOException {
|
|
|
|
writeLine(". SELECT INBOX");
|
|
|
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
|
|
|
writeLine(". UID FETCH 1:* RFC822.HEADER");
|
|
|
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
|
|
|
}
|
2010-07-01 09:27:49 -04:00
|
|
|
}
|