You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2007/11/13 13:57:53 UTC
svn commit: r594520 [8/10] - in
/geronimo/javamail/trunk/geronimo-javamail_1.4: ./
geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/authentication/
geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handl...
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageSize.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageSize.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageSize.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import javax.mail.MessagingException;
+
+public class IMAPMessageText extends IMAPFetchBodyPart {
+ // the header data
+ protected byte[] data;
+
+ /**
+ * Construct a top-level TEXT data item.
+ *
+ * @param data The data for the message text.
+ *
+ * @exception MessagingException
+ */
+ public IMAPMessageText(byte[] data) throws MessagingException {
+ this(new IMAPBodySection(IMAPBodySection.TEXT), data);
+ }
+
+
+ public IMAPMessageText(IMAPBodySection section, byte[] data) throws MessagingException {
+ super(TEXT, section);
+ this.data = data;
+ }
+
+ /**
+ * Retrieved the header data.
+ *
+ * @return The header data.
+ */
+ public byte[] getContent() {
+ return data;
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMessageText.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import javax.mail.MessagingException;
+
+import org.apache.geronimo.javamail.store.imap.Rights;
+
+/**
+ * Utility class to aggregate status responses for a mailbox.
+ */
+public class IMAPMyRightsResponse extends IMAPUntaggedResponse {
+ public String mailbox;
+ public Rights rights;
+
+ public IMAPMyRightsResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException {
+ super("MYRIGHTS", data);
+
+ mailbox = source.readEncodedString();
+ rights = new Rights(source.readString());
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPMyRightsResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+/**
+ * Util class to represent a NAMESPACE response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class IMAPNamespace {
+ // the namespace prefix
+ public String prefix;
+ // the namespace hierarchy delimiter
+ public char separator = '\0';
+
+ public IMAPNamespace(IMAPResponseTokenizer source) throws MessagingException {
+ source.checkLeftParen();
+ // read the two that make up the response and ...
+ prefix = source.readString();
+ String delim = source.readString();
+ // if the delimiter is not a null string, grab the first character.
+ if (delim.length() != 0) {
+ separator = delim.charAt(0);
+ }
+ source.checkRightParen();
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespace.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+import org.apache.geronimo.javamail.store.imap.connection.IMAPResponseTokenizer.Token;
+import org.apache.geronimo.javamail.util.ResponseFormatException;
+
+/**
+ * Util class to represent a NAMESPACE response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class IMAPNamespaceResponse extends IMAPUntaggedResponse {
+ // the personal namespaces defined
+ public List personalNamespaces;
+ // the other use name spaces this user has access to.
+ public List otherUserNamespaces;
+ // the list of shared namespaces
+ public List sharedNamespaces;
+
+ // construct a default IMAPNamespace response for return when the server doesn't support this.
+ public IMAPNamespaceResponse()
+ {
+ super("NAMESPACE", null);
+ // fill in default lists to simplify processing
+ personalNamespaces = Collections.EMPTY_LIST;
+ otherUserNamespaces = Collections.EMPTY_LIST;
+ sharedNamespaces = Collections.EMPTY_LIST;
+ }
+
+ /**
+ * Construct a LIST response item. This can be either
+ * a response from a LIST command or an LSUB command,
+ * and will be tagged accordingly.
+ *
+ * @param type The type of resonse (LIST or LSUB).
+ * @param data The raw response data.
+ * @param source The tokenizer source.
+ *
+ * @exception MessagingException
+ */
+ public IMAPNamespaceResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException {
+ super("NAMESPACE", data);
+ // the namespace response is a set of 3 items, which will be either NIL or a "list of lists".
+ // if the item exists, then there will be a set of list parens, with 1 or more subitems inside.
+ // Each of the subitems will consist of a namespace prefix and the hierarchy delimiter for that
+ // particular namespace.
+ personalNamespaces = parseNamespace(source);
+ otherUserNamespaces = parseNamespace(source);
+ sharedNamespaces = parseNamespace(source);
+ }
+
+ private List parseNamespace(IMAPResponseTokenizer source) throws MessagingException {
+ Token token = source.next(true);
+ // is this token the NIL token?
+ if (token.getType() == Token.NIL) {
+ // no items at this position.
+ return null;
+ }
+ if (token.getType() != '(') {
+ throw new ResponseFormatException("Missing '(' in response");
+ }
+
+ // ok, we're processing a namespace list. Create a list and populate it with IMAPNamespace
+ // items.
+
+ List namespaces = new ArrayList();
+
+ while (source.notListEnd()) {
+ namespaces.add(new IMAPNamespace(source));
+ }
+ // this should always pass, since it terminated the loop
+ source.checkRightParen();
+ return namespaces;
+ }
+}
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPNamespaceResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+/**
+ * Util class to represent an untagged response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+public class IMAPOkResponse extends IMAPUntaggedResponse {
+ // the response status value
+ protected List status;
+ // any message following the response
+ protected String message;
+
+ /**
+ * Create a reply object from a server response line (normally, untagged). This includes
+ * doing the parsing of the response line.
+ *
+ * @param response The response line used to create the reply object.
+ */
+ public IMAPOkResponse(String keyword, List status, String message, byte [] response) {
+ super(keyword, response);
+ this.status = status;
+ this.message = message;
+ }
+
+ /**
+ * Get the response code included with the OK
+ * response.
+ *
+ * @return The string name of the response code.
+ */
+ public String getResponseCode() {
+ return getKeyword();
+ }
+
+ /**
+ * Return the status argument values associated with
+ * this status response.
+ *
+ * @return The status value information, as a list of tokens.
+ */
+ public List getStatus() {
+ return status;
+ }
+
+ /**
+ * Get any trailing message associated with this
+ * status response.
+ *
+ * @return
+ */
+ public String getMessage() {
+ return message;
+ }
+}
+
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPOkResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import javax.mail.Flags;
+import javax.mail.MessagingException;
+
+/**
+ * Util class to represent an untagged response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+public class IMAPPermanentFlagsResponse extends IMAPUntaggedResponse {
+ // the response flags value
+ public Flags flags;
+ /**
+ * Create a reply object from a server response line (normally, untagged). This includes
+ * doing the parsing of the response line.
+ *
+ * @param response The response line used to create the reply object.
+ */
+ public IMAPPermanentFlagsResponse(byte [] response, IMAPResponseTokenizer source) throws MessagingException {
+ super("PERMANENTFLAGS", response);
+ flags = source.readFlagList();
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPPermanentFlagsResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.MessagingException;
+import javax.mail.Quota;
+
+/**
+ * Util class to represent a list response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class IMAPQuotaResponse extends IMAPUntaggedResponse {
+ // the returned quota item
+ public Quota quota;
+
+ /**
+ * Construct a LIST response item. This can be either
+ * a response from a LIST command or an LSUB command,
+ * and will be tagged accordingly.
+ *
+ * @param type The type of resonse (LIST or LSUB).
+ * @param data The raw response data.
+ * @param source The tokenizer source.
+ *
+ * @exception MessagingException
+ */
+ public IMAPQuotaResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException {
+ super("QUOTA", data);
+
+ // first token is the root name, which can be either an atom or a string.
+ String tokenName = source.readString();
+
+ // create a quota item for this
+ quota = new Quota(tokenName);
+
+ source.checkLeftParen();
+
+ List resources = new ArrayList();
+
+ while (source.notListEnd()) {
+ // quotas are returned as a set of triplets. The first element is the
+ // resource name, followed by the current usage and the limit value.
+ Quota.Resource resource = new Quota.Resource(source.readAtom(), source.readLong(), source.readLong());
+ resources.add(resource);
+ }
+
+ quota.resources = (Quota.Resource[])resources.toArray(new Quota.Resource[resources.size()]);
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+/**
+ * Util class to represent a list response from a IMAP server
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class IMAPQuotaRootResponse extends IMAPUntaggedResponse {
+ // the mailbox this applies to
+ public String mailbox;
+ // The list of quota roots
+ public List roots;
+
+
+ /**
+ * Construct a LIST response item. This can be either
+ * a response from a LIST command or an LSUB command,
+ * and will be tagged accordingly.
+ *
+ * @param type The type of resonse (LIST or LSUB).
+ * @param data The raw response data.
+ * @param source The tokenizer source.
+ *
+ * @exception MessagingException
+ */
+ public IMAPQuotaRootResponse(byte[] data, IMAPResponseTokenizer source) throws MessagingException {
+ super("QUOTAROOT", data);
+
+ // first token is the mailbox
+ mailbox = source.readEncodedString();
+ // get the root name list as the remainder of the command.
+ roots = source.readStrings();
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPQuotaRootResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+import javax.mail.MessagingException;
+
+/**
+ * Base class for all response messages.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IMAPResponse {
+ // The original (raw) response data
+ protected byte[] response;
+
+ /**
+ * Create a response object from a server response line (normally, untagged). This includes
+ * doing the parsing of the response line.
+ *
+ * @param response The response line used to create the reply object.
+ */
+ protected IMAPResponse(byte [] response) {
+ // set this as the current message and parse.
+ this.response = response;
+ }
+
+ /**
+ * Retrieve the raw response line data for this
+ * response message. Normally, this will be a complete
+ * single line response, unless there are quoted
+ * literals in the response data containing octet
+ * data.
+ *
+ * @return The byte array containing the response information.
+ */
+ public byte[] getResponseData() {
+ return response;
+ }
+
+ /**
+ * Return the response message as a string value.
+ * This is intended for debugging purposes only. The
+ * response data might contain octet data that
+ * might not convert to character data appropriately.
+ *
+ * @return The string version of the response.
+ */
+ public String toString() {
+ return new String(response);
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Simple extension to the ByteArrayOutputStream to allow inspection
+ * of the data while it is being accumulated.
+ */
+public class IMAPResponseBuffer extends ByteArrayOutputStream {
+
+ public IMAPResponseBuffer() {
+ super();
+ }
+
+
+ /**
+ * Read a character from the byte array output stream buffer
+ * at the give position.
+ *
+ * @param index The requested index.
+ *
+ * @return The byte at the target index, or -1 if the index is out of
+ * bounds.
+ */
+ public int read(int index) {
+ if (index >= size()) {
+ return -1;
+ }
+ return buf[index];
+ }
+
+ /**
+ * Read a buffer of data from the output stream's accumulator
+ * buffer. This will copy the data into a target byte arrain.
+ *
+ * @param buffer The target byte array for returning the data.
+ * @param offset The offset of the source data within the output stream buffer.
+ * @param length The desired length.
+ *
+ * @return The count of bytes transferred into the buffer.
+ */
+ public int read(byte[] buffer, int offset, int length) {
+
+ int available = size() - offset;
+ length = Math.min(length, available);
+ // nothing to return? quit now.
+ if (length <= 0) {
+ return 0;
+ }
+ System.arraycopy(buf, offset, buffer, 0, length);
+ return length;
+ }
+
+ /**
+ * Search backwards through the buffer for a given byte.
+ *
+ * @param target The search character.
+ *
+ * @return The index relative to the buffer start of the given byte.
+ * Returns -1 if not found.
+ */
+ public int lastIndex(byte target) {
+ for (int i = size() - 1; i > 0; i--) {
+ if (buf[i] == target) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+
+ /**
+ * Return the last byte written to the output stream. Returns
+ * -1 if the stream is empty.
+ *
+ * @return The last byte written (or -1 if the stream is empty).
+ */
+ public int lastByte() {
+ if (size() > 0) {
+ return buf[size() - 1];
+ }
+ return -1;
+ }
+
+
+ /**
+ * Retrieve an IMAP literal length value from the buffer. We
+ * have a literal length value IFF the last characters written
+ * to the buffer have the form "{nnnn}". This returns the
+ * integer value of the info inside the curly braces. Returns -1
+ * if a valid literal length is not found.
+ *
+ * @return A literal length value, or -1 if we don't have a literal
+ * signature at the end.
+ */
+ public int getLiteralLength() {
+ // was the last byte before the line break the close of the literal length?
+ if (lastByte() == '}') {
+ // locate the length start
+ int literalStart = lastIndex((byte)'{');
+ // no matching start, this can't be a literal.
+ if (literalStart == -1) {
+ return -1;
+ }
+
+ String lenString = new String(buf, literalStart + 1, size() - (literalStart + 2));
+ try {
+ return Integer.parseInt(lenString);
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ }
+ }
+ // not a literal
+ return -1;
+ }
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseBuffer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java?rev=594520&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java Tue Nov 13 04:57:39 2007
@@ -0,0 +1,392 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.javamail.store.imap.connection;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.mail.MessagingException;
+import javax.mail.event.FolderEvent;
+
+import org.apache.geronimo.javamail.store.imap.connection.IMAPResponseTokenizer.Token;
+import org.apache.geronimo.javamail.util.ConnectionException;
+
+public class IMAPResponseStream {
+ protected final int BUFFER_SIZE = 1024;
+
+ // our source input stream
+ protected InputStream in;
+ // The response buffer
+ IMAPResponseBuffer out;
+ // the buffer array
+ protected byte[] buffer = new byte[BUFFER_SIZE];
+ // the current buffer position
+ int position;
+ // the current buffer read length
+ int length;
+
+ public IMAPResponseStream(InputStream in) {
+ this.in = in;
+ out = new IMAPResponseBuffer();
+ }
+
+ public int read() throws IOException {
+ // if we can't read any more, that's an EOF condition.
+ if (!fillBufferIfNeeded()) {
+ return -1;
+ }
+ // just grab the next character
+ return buffer[position++];
+ }
+
+ protected boolean fillBufferIfNeeded() throws IOException {
+ // used up all of the data in the buffer?
+ if (position >= length) {
+ int readLength = 0;
+ // a read from a network connection can return 0 bytes,
+ // so we need to be prepared to handle a spin loop.
+ while (readLength == 0) {
+ readLength = in.read(buffer, 0, buffer.length);
+ }
+ // we may have hit the EOF. Indicate the read failure
+ if (readLength == -1) {
+ return false;
+ }
+ // set our new buffer positions.
+ position = 0;
+ length = readLength;
+ }
+ return true;
+ }
+
+
+ /**
+ * Read a single response line from the input stream, returning
+ * a parsed and processed response line.
+ *
+ * @return A parsed IMAPResponse item using the response data.
+ * @exception MessagingException
+ */
+ public IMAPResponse readResponse() throws MessagingException
+ {
+ // reset our accumulator
+ out.reset();
+ // now read a buffer of data
+ byte[] data = readData();
+
+ // and create a tokenizer for parsing this down.
+ IMAPResponseTokenizer tokenizer = new IMAPResponseTokenizer(data);
+ // get the first token.
+ Token token = tokenizer.next();
+
+ int type = token.getType();
+
+ // a continuation response. This will terminate a response set.
+ if (type == Token.CONTINUATION) {
+ return new IMAPContinuationResponse(data);
+ }
+ // unsolicited response. There are multiple forms of these, which might actually be
+ // part of the response for the last issued command.
+ else if (type == Token.UNTAGGED) {
+ // step to the next token, which will give us the type
+ token = tokenizer.next();
+ // if the token is numeric, then this is a size response in the
+ // form "* nn type"
+ if (token.isType(Token.NUMERIC)) {
+ int size = token.getInteger();
+
+ token = tokenizer.next();
+
+ String keyword = token.getValue();
+
+ // FETCH responses require fairly complicated parsing. Other
+ // size/message updates are fairly generic.
+ if (keyword.equals("FETCH")) {
+ return new IMAPFetchResponse(size, data, tokenizer);
+ }
+ return new IMAPSizeResponse(keyword, size, data);
+ }
+
+ // this needs to be an ATOM type, which will tell us what format this untagged
+ // response is in. There are many different untagged formats, some general, some
+ // specific to particular command types.
+ if (token.getType() != Token.ATOM) {
+ throw new MessagingException("Unknown server response: " + new String(data));
+ }
+
+ String keyword = token.getValue();
+ // many response are in the form "* OK [keyword value] message".
+ if (keyword.equals("OK")) {
+ return parseUntaggedOkResponse(data, tokenizer);
+ }
+ // preauth status response
+ else if (keyword.equals("PREAUTH")) {
+ return new IMAPServerStatusResponse("PREAUTH", tokenizer.getRemainder(), data);
+ }
+ // preauth status response
+ else if (keyword.equals("BYE")) {
+ return new IMAPServerStatusResponse("BYE", tokenizer.getRemainder(), data);
+ }
+ else if (keyword.equals("BAD")) {
+ // these are generally ignored.
+ return new IMAPServerStatusResponse("BAD", tokenizer.getRemainder(), data);
+ }
+ else if (keyword.equals("NO")) {
+ // these are generally ignored.
+ return new IMAPServerStatusResponse("NO", tokenizer.getRemainder(), data);
+ }
+ // a complex CAPABILITY response
+ else if (keyword.equals("CAPABILITY")) {
+ return new IMAPCapabilityResponse(tokenizer, data);
+ }
+ // a complex LIST response
+ else if (keyword.equals("LIST")) {
+ return new IMAPListResponse("LIST", data, tokenizer);
+ }
+ // a complex FLAGS response
+ else if (keyword.equals("FLAGS")) {
+ // parse this into a flags set.
+ return new IMAPFlagsResponse(data, tokenizer);
+ }
+ // a complex LSUB response (identical in format to LIST)
+ else if (keyword.equals("LSUB")) {
+ return new IMAPListResponse("LSUB", data, tokenizer);
+ }
+ // a STATUS response, which will contain a list of elements
+ else if (keyword.equals("STATUS")) {
+ return new IMAPStatusResponse(data, tokenizer);
+ }
+ // SEARCH requests return an variable length list of message matches.
+ else if (keyword.equals("SEARCH")) {
+ return new IMAPSearchResponse(data, tokenizer);
+ }
+ // ACL requests return an variable length list of ACL values .
+ else if (keyword.equals("ACL")) {
+ return new IMAPACLResponse(data, tokenizer);
+ }
+ // LISTRIGHTS requests return a variable length list of RIGHTS values .
+ else if (keyword.equals("LISTRIGHTS")) {
+ return new IMAPListRightsResponse(data, tokenizer);
+ }
+ // MYRIGHTS requests return a list of user rights for a mailbox name.
+ else if (keyword.equals("MYRIGHTS")) {
+ return new IMAPMyRightsResponse(data, tokenizer);
+ }
+ // QUOTAROOT requests return a list of mailbox quota root names
+ else if (keyword.equals("QUOTAROOT")) {
+ return new IMAPQuotaRootResponse(data, tokenizer);
+ }
+ // QUOTA requests return a list of quota values for a root name
+ else if (keyword.equals("QUOTA")) {
+ return new IMAPQuotaResponse(data, tokenizer);
+ }
+ else if (keyword.equals("NAMESPACE")) {
+ return new IMAPNamespaceResponse(data, tokenizer);
+ }
+ }
+ // begins with a word, this should be the tagged response from the last command.
+ else if (type == Token.ATOM) {
+ String tag = token.getValue();
+ token = tokenizer.next();
+ String status = token.getValue();
+ // primary information in one of these is the status field, which hopefully
+ // is 'OK'
+ return new IMAPTaggedResponse(tag, status, tokenizer.getRemainder(), data);
+ }
+ throw new MessagingException("Unknown server response: " + new String(data));
+ }
+
+ /**
+ * Parse an unsolicited OK status response. These
+ * responses are of the form:
+ *
+ * * OK [keyword arguments ...] message
+ *
+ * The part in the brackets are optional, but
+ * most OK messages will have some sort of update.
+ *
+ * @param data The raw message data
+ * @param tokenizer The tokenizer being used for this message.
+ *
+ * @return An IMAPResponse instance for this message.
+ */
+ private IMAPResponse parseUntaggedOkResponse(byte [] data, IMAPResponseTokenizer tokenizer) throws MessagingException {
+ Token token = tokenizer.peek();
+ // we might have an optional value here
+ if (token.getType() != '[') {
+ // this has no tagging item, so there's nothing to be processed
+ // later.
+ return new IMAPOkResponse("OK", null, tokenizer.getRemainder(), data);
+ }
+ // skip over the "[" token
+ tokenizer.next();
+ token = tokenizer.next();
+ String keyword = token.getValue();
+
+ // Permanent flags gets special handling
+ if (keyword.equals("PERMANENTFLAGS")) {
+ return new IMAPPermanentFlagsResponse(data, tokenizer);
+ }
+
+ ArrayList arguments = new ArrayList();
+
+ // strip off all of the argument tokens until the "]" list terminator.
+ token = tokenizer.next();
+ while (token.getType() != ']') {
+ arguments.add(token);
+ token = tokenizer.next();
+ }
+ // this has a tagged keyword and arguments that will be processed later.
+ return new IMAPOkResponse(keyword, arguments, tokenizer.getRemainder(), data);
+ }
+
+
+ /**
+ * Read a "line" of server response data. An individual line
+ * may span multiple line breaks, depending on syntax implications.
+ *
+ * @return
+ * @exception MessagingException
+ */
+ public byte[] readData() throws MessagingException {
+ // reset out buffer accumulator
+ out.reset();
+ // read until the end of the response into our buffer.
+ readBuffer();
+ // get the accumulated data.
+ return out.toByteArray();
+ }
+
+ /**
+ * Read a buffer of data. This accumulates the data into a
+ * ByteArrayOutputStream, terminating the processing at a line
+ * break. This also handles line breaks that are the result
+ * of literal continuations in the stream.
+ *
+ * @exception MessagingException
+ * @exception IOException
+ */
+ public void readBuffer() throws MessagingException {
+ while (true) {
+ int ch = nextByte();
+ // potential end of line? Check the next character, and if it is an end of line,
+ // we need to do literal processing.
+ if (ch == '\r') {
+ int next = nextByte();
+ if (next == '\n') {
+ // had a line break, which might be part of a literal marker. Check for the signature,
+ // and if we found it, continue with the next line. In any case, we're done with processing here.
+ checkLiteral();
+ return;
+ }
+ }
+ // write this to the buffer.
+ out.write(ch);
+ }
+ }
+
+
+ /**
+ * Check the line just read to see if we're processing a line
+ * with a literal value. Literals are encoded as "{length}\r\n",
+ * so if we've read up to the line break, we can check to see
+ * if we need to continue reading.
+ *
+ * If a literal marker is found, we read that many characters
+ * from the reader without looking for line breaks. Once we've
+ * read the literal data, we just read the rest of the line
+ * as normal (which might also end with a literal marker).
+ *
+ * @exception MessagingException
+ */
+ public void checkLiteral() throws MessagingException {
+ try {
+ // see if we have a literal length signature at the end.
+ int length = out.getLiteralLength();
+
+ // -1 means no literal length, so we're done reading this particular response.
+ if (length == -1) {
+ return;
+ }
+
+ // we need to write out the literal line break marker.
+ out.write('\r');
+ out.write('\n');
+
+ // have something we're supposed to read for the literal?
+ if (length > 0) {
+ byte[] bytes = new byte[length];
+
+ int offset = 0;
+
+ // The InputStream can return less than the requested length if it needs to block.
+ // This may take a couple iterations to get everything, particularly if it's long.
+ while (length > 0) {
+ int read = -1;
+ try {
+ read = in.read(bytes, offset, length);
+ } catch (IOException e) {
+ throw new MessagingException("Unexpected read error on server connection", e);
+ }
+ // premature EOF we can't ignore.
+ if (read == -1) {
+ throw new MessagingException("Unexpected end of stream");
+ }
+ length -= read;
+ offset += read;
+ }
+
+ // write this out to the output stream.
+ out.write(bytes);
+ }
+ // Now that we have the literal data, we need to read the rest of the response line (which might contain
+ // additional literals). Just recurse on the line reading logic.
+ readBuffer();
+ } catch (IOException e) {
+ e.printStackTrace();
+ // this is a byte array output stream...should never happen
+ }
+ }
+
+
+ /**
+ * Get the next byte from the input stream, handling read errors
+ * and EOF conditions as MessagingExceptions.
+ *
+ * @return The next byte read from the stream.
+ * @exception MessagingException
+ */
+ protected int nextByte() throws MessagingException {
+ try {
+ int next = in.read();
+ if (next == -1) {
+ throw new MessagingException("Read error on IMAP server connection");
+ }
+ return next;
+ } catch (IOException e) {
+ throw new MessagingException("Unexpected error on server stream", e);
+ }
+ }
+
+
+}
+
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/store/imap/connection/IMAPResponseStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain