mirror of
https://github.com/moparisthebest/davmail
synced 2024-08-13 16:53:51 -04:00
Fix 3150426 huge memory usage with IMAP
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1613 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
801148e890
commit
f5f83aba41
@ -1736,7 +1736,9 @@ public abstract class ExchangeSession {
|
|||||||
messageList.cachedMimeBody = mimeBody;
|
messageList.cachedMimeBody = mimeBody;
|
||||||
messageList.cachedMimeMessage = mimeMessage;
|
messageList.cachedMimeMessage = mimeMessage;
|
||||||
}
|
}
|
||||||
|
// drop curent message body to save memory
|
||||||
mimeMessage = null;
|
mimeMessage = null;
|
||||||
|
mimeBody = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
82
src/test/davmail/imap/AbstractImapTestCase.java
Normal file
82
src/test/davmail/imap/AbstractImapTestCase.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
* Copyright (C) 2011 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.AbstractDavMailTestCase;
|
||||||
|
import davmail.DavGateway;
|
||||||
|
import davmail.Settings;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract IMAP test case.
|
||||||
|
*/
|
||||||
|
public class AbstractImapTestCase extends AbstractDavMailTestCase {
|
||||||
|
static Socket clientSocket;
|
||||||
|
static BufferedWriter socketWriter;
|
||||||
|
static BufferedReader socketReader;
|
||||||
|
|
||||||
|
static String messageUid;
|
||||||
|
|
||||||
|
protected void write(String line) throws IOException {
|
||||||
|
socketWriter.write(line);
|
||||||
|
socketWriter.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeLine(String line) throws IOException {
|
||||||
|
socketWriter.write(line);
|
||||||
|
socketWriter.newLine();
|
||||||
|
socketWriter.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String readLine() throws IOException {
|
||||||
|
return socketReader.readLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String readFullAnswer(String prefix) throws IOException {
|
||||||
|
String line = socketReader.readLine();
|
||||||
|
while (!line.startsWith(prefix)) {
|
||||||
|
line = socketReader.readLine();
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws IOException {
|
||||||
|
boolean needStart = !loaded;
|
||||||
|
super.setUp();
|
||||||
|
if (needStart) {
|
||||||
|
// start gateway
|
||||||
|
DavGateway.start();
|
||||||
|
}
|
||||||
|
if (clientSocket == null) {
|
||||||
|
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
|
||||||
|
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
||||||
|
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||||
|
|
||||||
|
String banner = socketReader.readLine();
|
||||||
|
assertNotNull(banner);
|
||||||
|
|
||||||
|
writeLine(". LOGIN " + Settings.getProperty("davmail.username").replaceAll("\\\\", "\\\\\\\\") + ' ' + Settings.getProperty("davmail.password"));
|
||||||
|
assertEquals(". OK Authenticated", socketReader.readLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,71 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
package davmail.imap;
|
package davmail.imap;
|
||||||
|
|
||||||
import davmail.AbstractDavMailTestCase;
|
|
||||||
import davmail.DavGateway;
|
|
||||||
import davmail.Settings;
|
import davmail.Settings;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.*;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.net.Socket;
|
import java.io.IOException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMAP tests, an instance of DavMail Gateway must be available
|
* IMAP tests, an instance of DavMail Gateway must be available
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"JavaDoc", "UseOfSystemOutOrSystemErr"})
|
@SuppressWarnings({"JavaDoc", "UseOfSystemOutOrSystemErr"})
|
||||||
public class TestImap extends AbstractDavMailTestCase {
|
public class TestImap extends AbstractImapTestCase {
|
||||||
static Socket clientSocket;
|
|
||||||
static BufferedWriter socketWriter;
|
|
||||||
static BufferedReader socketReader;
|
|
||||||
|
|
||||||
static String messageUid;
|
|
||||||
|
|
||||||
protected void write(String line) throws IOException {
|
|
||||||
socketWriter.write(line);
|
|
||||||
socketWriter.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeLine(String line) throws IOException {
|
|
||||||
socketWriter.write(line);
|
|
||||||
socketWriter.newLine();
|
|
||||||
socketWriter.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String readLine() throws IOException {
|
|
||||||
return socketReader.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String readFullAnswer(String prefix) throws IOException {
|
|
||||||
String line = socketReader.readLine();
|
|
||||||
while (!line.startsWith(prefix)) {
|
|
||||||
line = socketReader.readLine();
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws IOException {
|
|
||||||
boolean needStart = !loaded;
|
|
||||||
super.setUp();
|
|
||||||
if (needStart) {
|
|
||||||
// start gateway
|
|
||||||
DavGateway.start();
|
|
||||||
}
|
|
||||||
if (clientSocket == null) {
|
|
||||||
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
|
|
||||||
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
|
||||||
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
|
||||||
|
|
||||||
String banner = socketReader.readLine();
|
|
||||||
assertNotNull(banner);
|
|
||||||
|
|
||||||
writeLine(". LOGIN " + Settings.getProperty("davmail.username").replaceAll("\\\\", "\\\\\\\\") + ' ' + Settings.getProperty("davmail.password"));
|
|
||||||
assertEquals(". OK Authenticated", socketReader.readLine());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListFolders() throws IOException {
|
public void testListFolders() throws IOException {
|
||||||
writeLine(". LSUB \"\" \"*\"");
|
writeLine(". LSUB \"\" \"*\"");
|
||||||
@ -138,8 +87,8 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
|
mimeMessage.addHeader("bcc", Settings.getProperty("davmail.bcc"));
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
StringBuilder randomText = new StringBuilder();
|
StringBuilder randomText = new StringBuilder();
|
||||||
for (int i=0;i<10*1024*1024;i++) {
|
for (int i = 0; i < 10 * 1024 * 1024; i++) {
|
||||||
randomText.append((char)('a'+random.nextInt(26)));
|
randomText.append((char) ('a' + random.nextInt(26)));
|
||||||
}
|
}
|
||||||
mimeMessage.setText(randomText.toString());
|
mimeMessage.setText(randomText.toString());
|
||||||
mimeMessage.setSubject("Big subject");
|
mimeMessage.setSubject("Big subject");
|
||||||
@ -151,13 +100,13 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
assertEquals("+ send literal data", readLine());
|
assertEquals("+ send literal data", readLine());
|
||||||
writeLine(new String(content));
|
writeLine(new String(content));
|
||||||
assertEquals(". OK APPEND completed", readFullAnswer("."));
|
assertEquals(". OK APPEND completed", readFullAnswer("."));
|
||||||
System.out.println("Create time: "+(System.currentTimeMillis()-start)+" ms");
|
System.out.println("Create time: " + (System.currentTimeMillis() - start) + " ms");
|
||||||
writeLine(". NOOP");
|
writeLine(". NOOP");
|
||||||
assertEquals(". OK NOOP completed", readFullAnswer("."));
|
assertEquals(". OK NOOP completed", readFullAnswer("."));
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY.TEXT)");
|
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY.TEXT)");
|
||||||
readFullAnswer(".");
|
readFullAnswer(".");
|
||||||
System.out.println("Fetch time: "+(System.currentTimeMillis()-start)+" ms");
|
System.out.println("Fetch time: " + (System.currentTimeMillis() - start) + " ms");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +274,7 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
|
messageUid = messageLine.substring(uidIndex, messageLine.indexOf(' ', uidIndex));
|
||||||
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
||||||
|
|
||||||
writeLine(". UID COPY "+messageUid+" Trash");
|
writeLine(". UID COPY " + messageUid + " Trash");
|
||||||
assertEquals(". OK copy completed", readFullAnswer("."));
|
assertEquals(". OK copy completed", readFullAnswer("."));
|
||||||
|
|
||||||
writeLine(". COPY 1 Trash");
|
writeLine(". COPY 1 Trash");
|
||||||
@ -346,15 +295,6 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFetchRfc822Header() throws IOException {
|
public void testFetchRfc822Header() throws IOException {
|
||||||
testSelectInbox();
|
testSelectInbox();
|
||||||
writeLine(". UID FETCH 1:* (UID RFC822.HEADER RFC822.SIZE FLAGS)");
|
writeLine(". UID FETCH 1:* (UID RFC822.HEADER RFC822.SIZE FLAGS)");
|
||||||
@ -366,4 +306,13 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
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)])");
|
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("."));
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
34
src/test/davmail/imap/TestImapFullSync.java
Normal file
34
src/test/davmail/imap/TestImapFullSync.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
* Copyright (C) 2011 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 java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test IMAP full sync.
|
||||||
|
*/
|
||||||
|
public class TestImapFullSync extends AbstractImapTestCase {
|
||||||
|
public void testSelectTrash() throws IOException {
|
||||||
|
writeLine(". SELECT Trash");
|
||||||
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
||||||
|
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("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user