Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more extensible retrieval

  • Loading branch information...
commit 0d8071759e4b996a6096e46972aaa6f38adcbd4b 1 parent 68ba395
@azinman authored
View
6 sitebricks-mail/src/main/java/com/google/sitebricks/mail/MailClient.java
@@ -31,6 +31,8 @@
*/
boolean connect(DisconnectListener listener);
+ void setDisconnectListener(DisconnectListener listener);
+
/**
* Logs out of the current IMAP session and releases all resources, including
* executor services.
@@ -185,8 +187,10 @@
* <b>NOTE: you must call {@link #open(String)} first.</b>
*/
public ListenableFuture<List<Message>> fetch(Folder folder, int start, int end);
+ public ListenableFuture<List<Message>> fetch(Folder folder, List<Integer> seqs);
public ListenableFuture<List<Message>> fetchUids(Folder folder, List<Integer> uids);
- public ListenableFuture<List<MessageStatus>> fetchUidsHeaders(Folder folder, List<Integer> uids);
+ public ListenableFuture<List<MessageStatus>> fetchUidsHeaders(Folder folder, Collection<Integer> uids);
+ public ListenableFuture<List<MessageStatus>> fetchHeaders(Folder folder, Collection<Integer> seqs);
/**
* Watches a folder for changes. This is an implementation of the IMAP IDLE command and
View
86 sitebricks-mail/src/main/java/com/google/sitebricks/mail/NettyImapClient.java
@@ -151,6 +151,12 @@ public void operationComplete(ChannelFuture future) throws Exception {
return login();
}
+ @Override
+ public void setDisconnectListener(DisconnectListener listener) {
+ this.disconnectListener = listener;
+ }
+
+
private boolean login() {
try {
channel.write(". CAPABILITY\r\n");
@@ -620,6 +626,38 @@ private static String toUpperBound(int end) {
}
@Override
+ public ListenableFuture<List<Message>> fetch(Folder folder, List<Integer> seqs) {
+ Preconditions.checkState(mailClientHandler.isLoggedIn(),
+ "Can't execute command because client is not logged in");
+ Preconditions.checkState(!mailClientHandler.idleRequested.get(),
+ "Can't execute command while idling (are you watching a folder?)");
+
+ checkCurrentFolder(folder);
+ SettableFuture<List<Message>> valueFuture = SettableFuture.create();
+
+ StringBuilder argsBuilder = new StringBuilder();
+ // Emit ranges.
+ boolean isFirst = true;
+ for (Integer seq : seqs) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ argsBuilder.append(',');
+ }
+ argsBuilder.append(seq);
+ }
+ argsBuilder.append(" (FLAGS INTERNALDATE UID");
+ if (config.useGmailExtensions()) {
+ argsBuilder.append(" X-GM-MSGID X-GM-THRID X-GM-LABELS");
+ }
+ argsBuilder.append(" BODY.PEEK[])");
+ send(Command.FETCH_BODY, argsBuilder.toString(), valueFuture);
+
+ return valueFuture;
+ }
+
+
+ @Override
public ListenableFuture<Message> fetchUid(Folder folder, int uid) {
Preconditions.checkState(mailClientHandler.isLoggedIn(), "Can't execute command because client is not logged in");
Preconditions.checkState(!mailClientHandler.idleRequested.get(),
@@ -647,14 +685,12 @@ private static String toUpperBound(int end) {
StringBuilder argsBuilder = new StringBuilder();
// Emit ranges.
-// argsBuilder.append('(');
for (int i = 0; i < uids.size(); i++) {
int uid = uids.get(i);
argsBuilder.append(uid);
if (i < uids.size() - 1)
argsBuilder.append(',');
}
-// argsBuilder.append(')');
argsBuilder.append(" (FLAGS INTERNALDATE UID");
if (config.useGmailExtensions()) {
argsBuilder.append(" X-GM-MSGID X-GM-THRID X-GM-LABELS");
@@ -667,7 +703,40 @@ private static String toUpperBound(int end) {
@Override
- public ListenableFuture<List<MessageStatus>> fetchUidsHeaders(Folder folder, List<Integer> uids) {
+ public ListenableFuture<List<MessageStatus>> fetchHeaders(Folder folder, Collection<Integer> seqs) {
+ Preconditions.checkState(mailClientHandler.isLoggedIn(),
+ "Can't execute command because client is not logged in");
+ Preconditions.checkState(!mailClientHandler.idleRequested.get(),
+ "Can't execute command while idling (are you watching a folder?)");
+
+ checkCurrentFolder(folder);
+ SettableFuture<List<MessageStatus>> valueFuture = SettableFuture.create();
+
+ StringBuilder argsBuilder = new StringBuilder();
+ // Emit ranges.
+ boolean isFirst = true;
+ for (Integer seq : seqs) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ argsBuilder.append(',');
+ }
+ argsBuilder.append(seq);
+ }
+ argsBuilder.append(" (RFC822.SIZE FLAGS INTERNALDATE ENVELOPE UID");
+ if (config.useGmailExtensions()) {
+ argsBuilder.append(" X-GM-MSGID X-GM-THRID X-GM-LABELS");
+ }
+ argsBuilder.append(")");
+
+ send(Command.FETCH_HEADERS, argsBuilder.toString(), valueFuture);
+
+ return valueFuture;
+ }
+
+
+ @Override
+ public ListenableFuture<List<MessageStatus>> fetchUidsHeaders(Folder folder, Collection<Integer> uids) {
Preconditions.checkState(mailClientHandler.isLoggedIn(),
"Can't execute command because client is not logged in");
Preconditions.checkState(!mailClientHandler.idleRequested.get(),
@@ -679,11 +748,14 @@ private static String toUpperBound(int end) {
StringBuilder argsBuilder = new StringBuilder();
// Emit ranges.
// argsBuilder.append('(');
- for (int i = 0; i < uids.size(); i++) {
- int uid = uids.get(i);
- argsBuilder.append(uid);
- if (i < uids.size() - 1)
+ boolean isFirst = true;
+ for (Integer uid : uids) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
argsBuilder.append(',');
+ }
+ argsBuilder.append(uid);
}
// argsBuilder.append(')');
argsBuilder.append(" (RFC822.SIZE FLAGS INTERNALDATE ENVELOPE UID");
Please sign in to comment.
Something went wrong with that request. Please try again.