mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 11:48:02 -05:00
From David Ashman : implement POP TOP command correctly
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@119 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
4ea61fcf1d
commit
ae2bd86275
@ -4,7 +4,9 @@ import davmail.AbstractConnection;
|
|||||||
import davmail.exchange.ExchangeSession;
|
import davmail.exchange.ExchangeSession;
|
||||||
import davmail.tray.DavGatewayTray;
|
import davmail.tray.DavGatewayTray;
|
||||||
|
|
||||||
|
import java.io.FilterOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -172,21 +174,19 @@ public class PopConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
} else if ("TOP".equalsIgnoreCase(command)) {
|
} else if ("TOP".equalsIgnoreCase(command)) {
|
||||||
try {
|
try {
|
||||||
int firstMessage = Integer.valueOf(tokens.
|
int message = Integer.valueOf(tokens.nextToken()) - 1;
|
||||||
nextToken()) - 1;
|
int lines = Integer.valueOf(tokens.nextToken());
|
||||||
int lastMessage = Integer.valueOf(tokens.
|
ExchangeSession.Message m = messages.get(message);
|
||||||
nextToken()) - 1;
|
sendOK("");
|
||||||
for (int i = firstMessage; i <= lastMessage; i++) {
|
m.write(new TopOutputStream(os, lines));
|
||||||
messages.get(i).printHeaders(os);
|
sendClient("");
|
||||||
sendClient("");
|
sendClient(".");
|
||||||
sendClient(".");
|
|
||||||
}
|
|
||||||
sendOK("TOP");
|
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
// can not send error to client after a socket exception
|
// can not send error to client after a socket exception
|
||||||
DavGatewayTray.warn("Client closed connection ", e);
|
DavGatewayTray.warn("Client closed connection ", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sendERR("error retreiving top of messages");
|
sendERR("error retreiving top of messages");
|
||||||
|
DavGatewayTray.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} else if ("RSET".equalsIgnoreCase(command)) {
|
} else if ("RSET".equalsIgnoreCase(command)) {
|
||||||
sendOK("RSET");
|
sendOK("RSET");
|
||||||
@ -221,4 +221,29 @@ public class PopConnection extends AbstractConnection {
|
|||||||
public void sendERR(String message) throws IOException {
|
public void sendERR(String message) throws IOException {
|
||||||
sendClient("-ERR ", message);
|
sendClient("-ERR ", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter to limit output lines to maxLines
|
||||||
|
*/
|
||||||
|
private class TopOutputStream extends FilterOutputStream {
|
||||||
|
|
||||||
|
private int maxLines;
|
||||||
|
|
||||||
|
public TopOutputStream(OutputStream os, int maxLines) {
|
||||||
|
super(os);
|
||||||
|
this.maxLines = maxLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
if (maxLines > 0) {
|
||||||
|
super.write(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == '\n') {
|
||||||
|
maxLines--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user