[jboss-cvs] jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch ...
Andy Oliver
acoliver at jboss.org
Mon Jul 24 15:27:47 EDT 2006
User: acoliver
Date: 06/07/24 15:27:47
Modified: src/java/org/jboss/mail/imap4/commands/fetch
NilPart.java FetchPart.java BodyPart.java
MessagePropertyPart.java
Log:
IMAP works again...pieces of my (still private) BODYSTRUCTURE... I still have a lot of stuff to commit but this patch makes it easier to work with mike on folder stuff
Revision Changes Path
1.5 +4 -2 jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/NilPart.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NilPart.java
===================================================================
RCS file: /cvsroot/jboss/jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/NilPart.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- NilPart.java 1 Apr 2006 21:18:59 -0000 1.4
+++ NilPart.java 24 Jul 2006 19:27:47 -0000 1.5
@@ -52,17 +52,19 @@
*/
package org.jboss.mail.imap4.commands.fetch;
+import org.jboss.mail.imap4.commands.AbstractImapCommand;
import org.jboss.mail.mailbox.MessageData;
/**
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class NilPart extends FetchPart {
public boolean canHandle(Object req) {
return false;
}
- public String fetch(MessageData msg, Object part) {
+ public String fetch(MessageData msg, Object part, AbstractImapCommand command, StringBuffer res) {
+ this.setCommandInstance(command);
return part + " NIL";
}
}
1.6 +2 -2 jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/FetchPart.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FetchPart.java
===================================================================
RCS file: /cvsroot/jboss/jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/FetchPart.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- FetchPart.java 1 Jun 2006 21:45:27 -0000 1.5
+++ FetchPart.java 24 Jul 2006 19:27:47 -0000 1.6
@@ -57,7 +57,7 @@
import org.jboss.mail.mailbox.MessageData;
/**
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public abstract class FetchPart {
private IMAP4ProtocolInstance protocol;
@@ -65,7 +65,7 @@
public abstract boolean canHandle(Object req);
- public abstract String fetch(MessageData msg, Object part);
+ public abstract String fetch(MessageData msg, Object part, AbstractImapCommand command, StringBuffer result);
/**
* @param protocolInstance
1.8 +22 -14 jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/BodyPart.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BodyPart.java
===================================================================
RCS file: /cvsroot/jboss/jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/BodyPart.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- BodyPart.java 11 Jun 2006 14:06:23 -0000 1.7
+++ BodyPart.java 24 Jul 2006 19:27:47 -0000 1.8
@@ -58,6 +58,7 @@
import java.util.List;
import org.jboss.mail.imap4.IMAP4ProtocolInstance;
+import org.jboss.mail.imap4.commands.AbstractImapCommand;
import org.jboss.mail.mailbox.MessageData;
import org.jboss.mail.message.MailBody;
import org.jboss.mail.util.io.Copier;
@@ -65,7 +66,7 @@
// need to get MailboxManager ref in here.
/**
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class BodyPart extends FetchPart {
@@ -112,11 +113,12 @@
return ret;
}
- public String fetch(MessageData msg, Object part) {
- return part.toString() + " " + fetchHandler(msg, part);
+ public String fetch(MessageData msg, Object part, AbstractImapCommand command, StringBuffer result) {
+ this.setCommandInstance(command);
+ return part.toString() + " " + fetchHandler(msg, part, command, result);
}
- protected String fetchHandler(MessageData msg, Object part) {
+ protected String fetchHandler(MessageData msg, Object part, AbstractImapCommand command, StringBuffer res) {
String result = null;
/*
msg.getMessage().getContent(c);
@@ -153,11 +155,11 @@
BodyPartRequest breq = (BodyPartRequest) part;
if (breq.getType().size() == 0) {
- result = fetchAll(breq, msg);
+ result = fetchAll(breq, msg, res);
System.err
.println("TODO implement body part type size == 0 fetch");
} else {
- result = fetchPart(breq, clone(breq.getType()), msg);
+ result = fetchPart(breq, clone(breq.getType()), msg, res);
}
/*
@@ -203,7 +205,7 @@
*/
protected String fetchPart(BodyPartRequest breq, List types,
- MessageData part) {
+ MessageData part, StringBuffer res) {
/* ExternalContinuation c = new ExternalContinuation();
part.getContent(c);
c.sleep();
@@ -213,7 +215,7 @@
EmailContentPart content = (EmailContentPart) c.getResult();
*/
if (types.size() == 0) {
- return fetchAll(breq, part);
+ return fetchAll(breq, part, res);
}
String type = (String) types.remove(0);
@@ -337,8 +339,8 @@
return format(result.replaceAll("[\\u0080-\\uffff]", "?") + "\r\n");
}
- public String fetchAll(BodyPartRequest breq, MessageData part) {
- return format(/*getRange(breq, */fetchAllX(part)/*)*/);
+ public String fetchAll(BodyPartRequest breq, MessageData part, StringBuffer res) {
+ return format(/*getRange(breq, */fetchAllX(part, res)/*)*/);
}
public String fetchAll(MessageData part) {
@@ -387,7 +389,7 @@
return result.toString();
}*/
- public String fetchAllX(MessageData part) {
+ public String fetchAllX(MessageData part, StringBuffer res) {
/* ExternalContinuation c = new ExternalContinuation();
part.getContent(c);
c.sleep();
@@ -405,7 +407,8 @@
try {
String boundary = part.getBoundary();
OutputStream out = this.getCommandInstance().getOutputStream();
- out.write(("{" + part.getMessageSize() + "}\r\n").getBytes());
+ out.write(("* "+res +"BODY[] {" + part.getMessageSize() + "}\r\n").getBytes());
+ out.write((part.getHeader()+"\r\n").getBytes());
//out.write(part.getHeader());
for (int i = 0; i < num; i++) {
//TODO make block size parameter
@@ -428,10 +431,13 @@
bod += new String(thepart);
stream.close();
}*/
+ out.write(")\r\n".getBytes());
+ out.flush();
} catch (Exception e) {
throw new RuntimeException(e);
}
- return new String(part.getHeader());
+
+ return null;//new String(part.getHeader());
// }
}
@@ -476,7 +482,9 @@
*/
private String format(String content) {
- if (content.equals("")) {
+ if (content == null) {
+ return "";
+ } else if (content.equals("")) {
return "\"\"";
} else {
return "{" + content.length() + "}\r\n" + content;
1.6 +56 -6 jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/MessagePropertyPart.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MessagePropertyPart.java
===================================================================
RCS file: /cvsroot/jboss/jboss-mail/src/java/org/jboss/mail/imap4/commands/fetch/MessagePropertyPart.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- MessagePropertyPart.java 11 Apr 2006 17:16:52 -0000 1.5
+++ MessagePropertyPart.java 24 Jul 2006 19:27:47 -0000 1.6
@@ -52,16 +52,24 @@
*/
package org.jboss.mail.imap4.commands.fetch;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
+import org.jboss.mail.imap4.commands.AbstractImapCommand;
import org.jboss.mail.mailbox.MessageData;
+import org.jboss.mail.message.MailBody;
/**
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class MessagePropertyPart extends FetchPart {
+ private static final String TEXT_BODY = "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" ";
+ private static final String BODY_STR_HEADER = "(BODYSTRUCTURE ";
+ private static final String R_PARN = ")";
List supportedParts = Arrays
.asList(new Object[] { "ALL", "FAST", "FULL", "BODY",
"BODYSTRUCTURE", "ENVELOPE", "FLAGS", "INTERNALDATE", "UID" });
@@ -70,7 +78,8 @@
return supportedParts.contains(req);
}
- public String fetch(MessageData msg, Object part) {
+ public String fetch(MessageData msg, Object part, AbstractImapCommand command, StringBuffer res) {
+ this.setCommandInstance(command);
return part + " " + fetchHandler(msg, part);
}
@@ -84,6 +93,7 @@
} else if ("FULL".equals(part)) {
} else if ("BODYSTRUCTURE".equals(part)) {
+ // fetchBodyStructure(msg);
} else if ("ENVELOPE".equals(part)) {
} else if ("FLAGS".equals(part)) {
return fetchFlags(msg);
@@ -140,6 +150,46 @@
*/
return result;
}
+/*
+ String fetchBodyStructure(MessageData data) throws IOException {
+ List<Long> bodies = data.getBodyId();
+ if (bodies.size() > 1) {
+ return BODY_STR_HEADER+textBodyStructure(data)+R_PARN;
+ }
+ for (int i = 0; i < bodies.size(); i++) {
+ byte[] b = new byte[4096];
+ MailBody body = getProtocolInstance().getMessageBody(data, i);
+ int len = body.getSize();
+ InputStream stream = body.getInputStream();
+ BufferedInputStream bis = new BufferedInputStream(stream);
+ int bytesread = 0;
+ boolean doubleenter = false;
+ String mimeheaders = "";
+ while (bytesread < len && doubleenter == false) {
+ int read = bis.read(b);
+ String headers = new String(b);
+ int iof = headers.indexOf("\r\n\r\n");
+ if (iof > -1) {
+ doubleenter = true;
+ bytesread += (read - iof);
+ mimeheaders += headers.substring(0, iof);
+ } else {
+ bytesread += read;
+ mimeheaders += headers;
+ }
+ }
+ String[] headerlns = mimeheaders.split("\\r\\n");
+ for (int i = 0) {
+
+ }
+ }
+ return null;
+ }
+ */
+ String textBodyStructure(MessageData data) {
+ long size = getProtocolInstance().getMessageBody(data, 0).getSize();
+ return TEXT_BODY + size+ " "+ Math.max(Math.round(size/80),1)+")";
+ }
/*
String fetchBodyStructure(EmailContentPart part, boolean bodystructure) throws MailboxException {
More information about the jboss-cvs-commits
mailing list