mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
IMAP: handle 507 InsufficientStorage error
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1377 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
7807ec7fd4
commit
0d7dd47db2
35
src/java/davmail/exception/InsufficientStorageException.java
Normal file
35
src/java/davmail/exception/InsufficientStorageException.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.exception;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HttpException with 507 Insufficient Storage status.
|
||||||
|
*/
|
||||||
|
public class InsufficientStorageException extends HttpException {
|
||||||
|
/**
|
||||||
|
* HttpException with 507 Insufficient Storage status.
|
||||||
|
*
|
||||||
|
* @param message exception message
|
||||||
|
*/
|
||||||
|
public InsufficientStorageException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ import davmail.Settings;
|
|||||||
import davmail.exception.DavMailAuthenticationException;
|
import davmail.exception.DavMailAuthenticationException;
|
||||||
import davmail.exception.DavMailException;
|
import davmail.exception.DavMailException;
|
||||||
import davmail.exception.HttpNotFoundException;
|
import davmail.exception.HttpNotFoundException;
|
||||||
|
import davmail.exception.InsufficientStorageException;
|
||||||
import davmail.exchange.ExchangeSession;
|
import davmail.exchange.ExchangeSession;
|
||||||
import davmail.exchange.VObject;
|
import davmail.exchange.VObject;
|
||||||
import davmail.exchange.XMLStreamUtil;
|
import davmail.exchange.XMLStreamUtil;
|
||||||
@ -2055,8 +2056,20 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
int code = httpClient.executeMethod(putmethod);
|
int code = httpClient.executeMethod(putmethod);
|
||||||
|
|
||||||
if (code != HttpStatus.SC_OK && code != HttpStatus.SC_CREATED) {
|
if (code != HttpStatus.SC_OK && code != HttpStatus.SC_CREATED) {
|
||||||
|
// first delete draft message
|
||||||
|
if (!davProperties.isEmpty()) {
|
||||||
|
try {
|
||||||
|
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, messageUrl);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.warn("Unable to delete draft message");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (code == HttpStatus.SC_INSUFFICIENT_STORAGE) {
|
||||||
|
throw new InsufficientStorageException(putmethod.getStatusText());
|
||||||
|
} else {
|
||||||
throw new DavMailException("EXCEPTION_UNABLE_TO_CREATE_MESSAGE", messageUrl, code, ' ', putmethod.getStatusLine());
|
throw new DavMailException("EXCEPTION_UNABLE_TO_CREATE_MESSAGE", messageUrl, code, ' ', putmethod.getStatusLine());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw new IOException(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -26,6 +26,7 @@ import davmail.Settings;
|
|||||||
import davmail.exception.DavMailException;
|
import davmail.exception.DavMailException;
|
||||||
import davmail.exception.HttpForbiddenException;
|
import davmail.exception.HttpForbiddenException;
|
||||||
import davmail.exception.HttpNotFoundException;
|
import davmail.exception.HttpNotFoundException;
|
||||||
|
import davmail.exception.InsufficientStorageException;
|
||||||
import davmail.exchange.ExchangeSession;
|
import davmail.exchange.ExchangeSession;
|
||||||
import davmail.exchange.ExchangeSessionFactory;
|
import davmail.exchange.ExchangeSessionFactory;
|
||||||
import davmail.ui.tray.DavGatewayTray;
|
import davmail.ui.tray.DavGatewayTray;
|
||||||
@ -446,8 +447,12 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
MimeMessage mimeMessage = new MimeMessage(null, new SharedByteArrayInputStream(buffer));
|
MimeMessage mimeMessage = new MimeMessage(null, new SharedByteArrayInputStream(buffer));
|
||||||
|
|
||||||
String messageName = UUID.randomUUID().toString() + ".EML";
|
String messageName = UUID.randomUUID().toString() + ".EML";
|
||||||
|
try {
|
||||||
session.createMessage(folderName, messageName, properties, mimeMessage);
|
session.createMessage(folderName, messageName, properties, mimeMessage);
|
||||||
sendClient(commandId + " OK APPEND completed");
|
sendClient(commandId + " OK APPEND completed");
|
||||||
|
} catch (InsufficientStorageException e) {
|
||||||
|
sendClient(commandId + " NO " + e.getMessage());
|
||||||
|
}
|
||||||
} else if ("idle".equalsIgnoreCase(command) && imapIdleDelay > 0) {
|
} else if ("idle".equalsIgnoreCase(command) && imapIdleDelay > 0) {
|
||||||
sendClient("+ idling ");
|
sendClient("+ idling ");
|
||||||
// clear cache before going to idle mode
|
// clear cache before going to idle mode
|
||||||
|
@ -27,6 +27,7 @@ import javax.mail.Session;
|
|||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMAP tests, an instance of DavMail Gateway must be available
|
* IMAP tests, an instance of DavMail Gateway must be available
|
||||||
@ -70,18 +71,14 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
|
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
|
||||||
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
||||||
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBanner() throws IOException {
|
|
||||||
String banner = socketReader.readLine();
|
String banner = socketReader.readLine();
|
||||||
assertNotNull(banner);
|
assertNotNull(banner);
|
||||||
}
|
|
||||||
|
|
||||||
public void testLogin() throws IOException {
|
|
||||||
writeLine(". LOGIN " + Settings.getProperty("davmail.username").replaceAll("\\\\", "\\\\\\\\") + ' ' + Settings.getProperty("davmail.password"));
|
writeLine(". LOGIN " + Settings.getProperty("davmail.username").replaceAll("\\\\", "\\\\\\\\") + ' ' + Settings.getProperty("davmail.password"));
|
||||||
assertEquals(". OK Authenticated", socketReader.readLine());
|
assertEquals(". OK Authenticated", socketReader.readLine());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testListFolders() throws IOException {
|
public void testListFolders() throws IOException {
|
||||||
writeLine(". LSUB \"\" \"*\"");
|
writeLine(". LSUB \"\" \"*\"");
|
||||||
@ -98,11 +95,6 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreDelete() throws IOException {
|
|
||||||
writeLine(". UID STORE 10 +FLAGS (\\Deleted)");
|
|
||||||
readFullAnswer(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUidSearchUnDeleted() throws IOException {
|
public void testUidSearchUnDeleted() throws IOException {
|
||||||
writeLine(". UID SEARCH UNDELETED");
|
writeLine(". UID SEARCH UNDELETED");
|
||||||
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
||||||
@ -125,8 +117,42 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
readFullAnswer(".");
|
readFullAnswer(".");
|
||||||
writeLine(". CREATE testfolder");
|
writeLine(". CREATE testfolder");
|
||||||
assertEquals(". OK folder created", readFullAnswer("."));
|
assertEquals(". OK folder created", readFullAnswer("."));
|
||||||
|
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();
|
||||||
|
for (int i=0;i<10*1024*1024;i++) {
|
||||||
|
randomText.append((char)('a'+random.nextInt(26)));
|
||||||
|
}
|
||||||
|
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("."));
|
||||||
|
System.out.println("Create time: "+(System.currentTimeMillis()-start)+" ms");
|
||||||
|
writeLine(". NOOP");
|
||||||
|
assertEquals(". OK NOOP completed", readFullAnswer("."));
|
||||||
|
start = System.currentTimeMillis();
|
||||||
|
writeLine(". UID FETCH 1:* (RFC822.SIZE BODY.TEXT)");
|
||||||
|
readFullAnswer(".");
|
||||||
|
System.out.println("Fetch time: "+(System.currentTimeMillis()-start)+" ms");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testSelectFolder() throws IOException {
|
public void testSelectFolder() throws IOException {
|
||||||
writeLine(". SELECT testfolder");
|
writeLine(". SELECT testfolder");
|
||||||
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
||||||
@ -269,4 +295,13 @@ public class TestImap extends AbstractDavMailTestCase {
|
|||||||
writeLine(". LOGOUT");
|
writeLine(". LOGOUT");
|
||||||
assertEquals("* BYE Closing connection", socketReader.readLine());
|
assertEquals("* BYE Closing connection", socketReader.readLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user