You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/09/18 23:45:03 UTC
svn commit: r696828 [20/32] - in /james/protocols/imap/trunk:
api/src/main/java/org/apache/james/api/imap/
api/src/main/java/org/apache/james/api/imap/display/
api/src/main/java/org/apache/james/api/imap/imap4rev1/
api/src/main/java/org/apache/james/ap...
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/Header.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/Header.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/Header.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/Header.java Thu Sep 18 14:44:56 2008
@@ -34,62 +34,66 @@
import org.apache.james.mailboxmanager.torque.om.MessageHeader;
final class Header implements MessageResult.Header, MessageResult.Content {
- private final String name;
- private final String value;
- private final long size;
-
- public Header(final MessageHeader header) {
- this(header.getField(), header.getValue());
- }
-
- public Header(String name, String value) {
- this.name = name;
- this.value = value;
- size = name.length() + value.length() + 2;
- }
-
- public Content getContent() throws MessagingException {
- return this;
- }
-
- public String getName() throws MailboxManagerException {
- return name;
- }
-
- public String getValue() throws MailboxManagerException {
- return value;
- }
+ private final String name;
- public long size() {
- return size;
- }
+ private final String value;
- public void writeTo(StringBuffer buffer) {
-// TODO: sort out encoding
- for (int i=0; i<name.length();i++) {
- buffer.append((char)(byte) name.charAt(i));
- }
- buffer.append(':');
- buffer.append(' ');
- for (int i=0; i<value.length();i++) {
- buffer.append((char)(byte) value.charAt(i));
- }
- }
+ private final long size;
- public void writeTo(WritableByteChannel channel) throws IOException {
- writeAll(channel, MessageRowUtils.US_ASCII.encode(name));
- ByteBuffer buffer = ByteBuffer.wrap(MessageRowUtils.BYTES_HEADER_FIELD_VALUE_SEP);
- writeAll(channel, buffer);
- writeAll(channel, MessageRowUtils.US_ASCII.encode(value));
- }
-
- private void writeAll(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
- while (channel.write(buffer) > 0) {
- // write more
- }
- }
-
- public String toString() {
- return "[HEADER " + name + ": " + value + "]";
- }
- }
\ No newline at end of file
+ public Header(final MessageHeader header) {
+ this(header.getField(), header.getValue());
+ }
+
+ public Header(String name, String value) {
+ this.name = name;
+ this.value = value;
+ size = name.length() + value.length() + 2;
+ }
+
+ public Content getContent() throws MessagingException {
+ return this;
+ }
+
+ public String getName() throws MailboxManagerException {
+ return name;
+ }
+
+ public String getValue() throws MailboxManagerException {
+ return value;
+ }
+
+ public long size() {
+ return size;
+ }
+
+ public void writeTo(StringBuffer buffer) {
+ // TODO: sort out encoding
+ for (int i = 0; i < name.length(); i++) {
+ buffer.append((char) (byte) name.charAt(i));
+ }
+ buffer.append(':');
+ buffer.append(' ');
+ for (int i = 0; i < value.length(); i++) {
+ buffer.append((char) (byte) value.charAt(i));
+ }
+ }
+
+ public void writeTo(WritableByteChannel channel) throws IOException {
+ writeAll(channel, MessageRowUtils.US_ASCII.encode(name));
+ ByteBuffer buffer = ByteBuffer
+ .wrap(MessageRowUtils.BYTES_HEADER_FIELD_VALUE_SEP);
+ writeAll(channel, buffer);
+ writeAll(channel, MessageRowUtils.US_ASCII.encode(value));
+ }
+
+ private void writeAll(WritableByteChannel channel, ByteBuffer buffer)
+ throws IOException {
+ while (channel.write(buffer) > 0) {
+ // write more
+ }
+ }
+
+ public String toString() {
+ return "[HEADER " + name + ": " + value + "]";
+ }
+}
\ No newline at end of file
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageRowUtils.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageRowUtils.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageRowUtils.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageRowUtils.java Thu Sep 18 14:44:56 2008
@@ -47,21 +47,25 @@
public class MessageRowUtils {
- public static final byte[] BYTES_NEW_LINE = {0x0D, 0x0A};
- public static final byte[] BYTES_HEADER_FIELD_VALUE_SEP = {0x3A, 0x20};
+ public static final byte[] BYTES_NEW_LINE = { 0x0D, 0x0A };
+
+ public static final byte[] BYTES_HEADER_FIELD_VALUE_SEP = { 0x3A, 0x20 };
+
static final Charset US_ASCII = Charset.forName("US-ASCII");
-
+
/**
* Converts {@link MessageRow} to {@link MessageFlags}.
- * @param messageRows <code>Collectio</code> of {@link MessageRow},
- * not null
+ *
+ * @param messageRows
+ * <code>Collectio</code> of {@link MessageRow}, not null
* @return <code>MessageFlags</code>, not null
* @throws TorqueException
*/
- public static MessageFlags[] toMessageFlags(final Collection messageRows) throws TorqueException {
+ public static MessageFlags[] toMessageFlags(final Collection messageRows)
+ throws TorqueException {
final MessageFlags[] results = new MessageFlags[messageRows.size()];
- int i=0;
- for (final Iterator it=messageRows.iterator(); it.hasNext();) {
+ int i = 0;
+ for (final Iterator it = messageRows.iterator(); it.hasNext();) {
MessageRow row = (MessageRow) it.next();
final Flags flags = row.getMessageFlags().getFlagsObject();
final long uid = row.getUid();
@@ -70,11 +74,12 @@
return results;
}
- public static List createHeaders(MessageRow messageRow) throws TorqueException {
+ public static List createHeaders(MessageRow messageRow)
+ throws TorqueException {
final List headers = getSortedHeaders(messageRow);
-
+
final List results = new ArrayList(headers.size());
- for (Iterator it=headers.iterator();it.hasNext();) {
+ for (Iterator it = headers.iterator(); it.hasNext();) {
final MessageHeader messageHeader = (MessageHeader) it.next();
final Header header = new Header(messageHeader);
results.add(header);
@@ -82,47 +87,54 @@
return results;
}
- private static List getSortedHeaders(MessageRow messageRow) throws TorqueException {
- final List headers=messageRow.getMessageHeaders();
+ private static List getSortedHeaders(MessageRow messageRow)
+ throws TorqueException {
+ final List headers = messageRow.getMessageHeaders();
Collections.sort(headers, new Comparator() {
-
+
public int compare(Object one, Object two) {
- return ((MessageHeader) one).getLineNumber() - ((MessageHeader)two).getLineNumber();
+ return ((MessageHeader) one).getLineNumber()
+ - ((MessageHeader) two).getLineNumber();
}
-
+
});
return headers;
}
- public static Content createBodyContent(MessageRow messageRow) throws TorqueException {
- final MessageBody body = (MessageBody) messageRow.getMessageBodys().get(0);
+ public static Content createBodyContent(MessageRow messageRow)
+ throws TorqueException {
+ final MessageBody body = (MessageBody) messageRow.getMessageBodys()
+ .get(0);
final byte[] bytes = body.getBody();
final ByteContent result = new ByteContent(bytes);
return result;
}
- public static Content createFullContent(final MessageRow messageRow, List headers) throws TorqueException {
+ public static Content createFullContent(final MessageRow messageRow,
+ List headers) throws TorqueException {
if (headers == null) {
headers = createHeaders(messageRow);
}
- final MessageBody body = (MessageBody) messageRow.getMessageBodys().get(0);
+ final MessageBody body = (MessageBody) messageRow.getMessageBodys()
+ .get(0);
final byte[] bytes = body.getBody();
final FullContent results = new FullContent(bytes, headers);
return results;
}
- public static MessageResult loadMessageResult(final MessageRow messageRow, final FetchGroup fetchGroup)
- throws TorqueException, MailboxManagerException {
-
+ public static MessageResult loadMessageResult(final MessageRow messageRow,
+ final FetchGroup fetchGroup) throws TorqueException,
+ MailboxManagerException {
+
MessageResultImpl messageResult = new MessageResultImpl();
messageResult.setUid(messageRow.getUid());
if (fetchGroup != null) {
int content = fetchGroup.content();
if ((content & FetchGroup.FLAGS) > 0) {
- org.apache.james.mailboxmanager.torque.om.MessageFlags messageFlags
- = messageRow.getMessageFlags();
- if (messageFlags!=null) {
- messageResult.setFlags(messageFlags.getFlagsObject());
+ org.apache.james.mailboxmanager.torque.om.MessageFlags messageFlags = messageRow
+ .getMessageFlags();
+ if (messageFlags != null) {
+ messageResult.setFlags(messageFlags.getFlagsObject());
}
content -= FetchGroup.FLAGS;
}
@@ -162,44 +174,55 @@
return messageResult;
}
- private static void addMimeDescriptor(MessageRow messageRow, MessageResultImpl messageResult) throws TorqueException {
- try {
- MessageResult.MimeDescriptor descriptor = MimeDescriptorImpl.build(toInput(messageRow));
+ private static void addMimeDescriptor(MessageRow messageRow,
+ MessageResultImpl messageResult) throws TorqueException {
+ try {
+ MessageResult.MimeDescriptor descriptor = MimeDescriptorImpl
+ .build(toInput(messageRow));
messageResult.setMimeDescriptor(descriptor);
} catch (IOException e) {
throw new TorqueException("Cannot parse message", e);
}
}
- private static void addFullContent(final MessageRow messageRow, MessageResultImpl messageResult) throws TorqueException, MailboxManagerException {
+ private static void addFullContent(final MessageRow messageRow,
+ MessageResultImpl messageResult) throws TorqueException,
+ MailboxManagerException {
final List headers = messageResult.getHeaders();
final Content content = createFullContent(messageRow, headers);
messageResult.setFullContent(content);
}
- private static void addBody(final MessageRow messageRow, MessageResultImpl messageResult) throws TorqueException {
+ private static void addBody(final MessageRow messageRow,
+ MessageResultImpl messageResult) throws TorqueException {
final Content content = createBodyContent(messageRow);
messageResult.setBody(content);
}
- private static void addHeaders(final MessageRow messageRow, MessageResultImpl messageResult) throws TorqueException {
+ private static void addHeaders(final MessageRow messageRow,
+ MessageResultImpl messageResult) throws TorqueException {
final List headers = createHeaders(messageRow);
messageResult.setHeaders(headers);
}
- private static void addPartContent(final FetchGroup fetchGroup, MessageRow row,
- MessageResultImpl messageResult) throws TorqueException, MailboxManagerException, IOException, MimeException {
+ private static void addPartContent(final FetchGroup fetchGroup,
+ MessageRow row, MessageResultImpl messageResult)
+ throws TorqueException, MailboxManagerException, IOException,
+ MimeException {
Collection partContent = fetchGroup.getPartContentDescriptors();
if (partContent != null) {
for (Iterator it = partContent.iterator(); it.hasNext();) {
- FetchGroup.PartContentDescriptor descriptor = (FetchGroup.PartContentDescriptor) it.next();
+ FetchGroup.PartContentDescriptor descriptor = (FetchGroup.PartContentDescriptor) it
+ .next();
addPartContent(descriptor, row, messageResult);
}
}
}
-
- private static void addPartContent(FetchGroup.PartContentDescriptor descriptor, MessageRow row,
- MessageResultImpl messageResult) throws TorqueException, MailboxManagerException, IOException, MimeException {
+
+ private static void addPartContent(
+ FetchGroup.PartContentDescriptor descriptor, MessageRow row,
+ MessageResultImpl messageResult) throws TorqueException,
+ MailboxManagerException, IOException, MimeException {
final MimePath mimePath = descriptor.path();
final int content = descriptor.content();
if ((content & MessageResult.FetchGroup.FULL_CONTENT) > 0) {
@@ -218,8 +241,9 @@
addMimeHeaders(row, messageResult, mimePath);
}
}
-
- private static PartContentBuilder build(int[] path, final MessageRow row) throws IOException, MimeException, TorqueException {
+
+ private static PartContentBuilder build(int[] path, final MessageRow row)
+ throws IOException, MimeException, TorqueException {
final InputStream stream = toInput(row);
PartContentBuilder result = new PartContentBuilder();
result.parse(stream);
@@ -236,9 +260,11 @@
return result;
}
- public static InputStream toInput(final MessageRow row) throws TorqueException {
+ public static InputStream toInput(final MessageRow row)
+ throws TorqueException {
final List headers = getSortedHeaders(row);
- final StringBuffer headersToString = new StringBuffer(headers.size()*50);
+ final StringBuffer headersToString = new StringBuffer(
+ headers.size() * 50);
for (Iterator it = headers.iterator(); it.hasNext();) {
MessageHeader header = (MessageHeader) it.next();
headersToString.append(header.getField());
@@ -247,19 +273,22 @@
headersToString.append("\r\n");
}
headersToString.append("\r\n");
-
+
byte[] bodyContent = row.getBodyContent();
- final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent);
+ final MessageInputStream stream = new MessageInputStream(
+ headersToString, bodyContent);
return stream;
}
-
+
private static final class MessageInputStream extends InputStream {
private final StringBuffer headers;
+
private final ByteBuffer bodyContent;
-
+
private int headerPosition = 0;
-
- public MessageInputStream(final StringBuffer headers, final byte[] bodyContent) {
+
+ public MessageInputStream(final StringBuffer headers,
+ final byte[] bodyContent) {
super();
this.headers = headers;
this.bodyContent = ByteBuffer.wrap(bodyContent);
@@ -269,16 +298,16 @@
final int result;
if (headerPosition < headers.length()) {
result = headers.charAt(headerPosition++);
- } else if (bodyContent.hasRemaining() ){
+ } else if (bodyContent.hasRemaining()) {
result = bodyContent.get();
} else {
result = -1;
}
return result;
}
-
+
}
-
+
private static final int[] path(MimePath mimePath) {
final int[] result;
if (mimePath == null) {
@@ -288,8 +317,10 @@
}
return result;
}
-
- private static void addHeaders(MessageRow row, MessageResultImpl messageResult, MimePath mimePath) throws TorqueException, IOException, MimeException {
+
+ private static void addHeaders(MessageRow row,
+ MessageResultImpl messageResult, MimePath mimePath)
+ throws TorqueException, IOException, MimeException {
final int[] path = path(mimePath);
if (path == null) {
addHeaders(row, messageResult);
@@ -299,8 +330,10 @@
messageResult.setHeaders(mimePath, headers.iterator());
}
}
-
- private static void addMimeHeaders(MessageRow row, MessageResultImpl messageResult, MimePath mimePath) throws TorqueException, IOException, MimeException {
+
+ private static void addMimeHeaders(MessageRow row,
+ MessageResultImpl messageResult, MimePath mimePath)
+ throws TorqueException, IOException, MimeException {
final int[] path = path(mimePath);
if (path == null) {
addHeaders(row, messageResult);
@@ -311,7 +344,9 @@
}
}
- private static void addBodyContent(MessageRow row, MessageResultImpl messageResult, MimePath mimePath) throws TorqueException, IOException, MimeException {
+ private static void addBodyContent(MessageRow row,
+ MessageResultImpl messageResult, MimePath mimePath)
+ throws TorqueException, IOException, MimeException {
final int[] path = path(mimePath);
if (path == null) {
addBody(row, messageResult);
@@ -321,16 +356,20 @@
messageResult.setBodyContent(mimePath, content);
}
}
-
- private static void addMimeBodyContent(MessageRow row, MessageResultImpl messageResult, MimePath mimePath) throws TorqueException, IOException, MimeException {
+
+ private static void addMimeBodyContent(MessageRow row,
+ MessageResultImpl messageResult, MimePath mimePath)
+ throws TorqueException, IOException, MimeException {
final int[] path = path(mimePath);
final PartContentBuilder builder = build(path, row);
final Content content = builder.getMimeBodyContent();
messageResult.setMimeBodyContent(mimePath, content);
}
- private static void addFullContent(MessageRow row, MessageResultImpl messageResult, MimePath mimePath)
- throws TorqueException, MailboxManagerException, IOException, MimeException {
+ private static void addFullContent(MessageRow row,
+ MessageResultImpl messageResult, MimePath mimePath)
+ throws TorqueException, MailboxManagerException, IOException,
+ MimeException {
final int[] path = path(mimePath);
if (path == null) {
addFullContent(row, messageResult);
@@ -342,23 +381,24 @@
}
/**
- * Gets a comparator that evaluates {@link MessageRow}'s
- * on the basis of their UIDs.
+ * Gets a comparator that evaluates {@link MessageRow}'s on the basis of
+ * their UIDs.
+ *
* @return {@link Comparator}, not null
*/
public static Comparator getUidComparator() {
return UidComparator.INSTANCE;
}
-
+
private static final class UidComparator implements Comparator {
private static final UidComparator INSTANCE = new UidComparator();
-
+
public int compare(Object one, Object two) {
final MessageRow rowOne = (MessageRow) one;
final MessageRow rowTwo = (MessageRow) two;
- final int result = (int)(rowOne.getUid() - rowTwo.getUid());
+ final int result = (int) (rowOne.getUid() - rowTwo.getUid());
return result;
}
-
+
}
}
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearcher.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearcher.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearcher.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearcher.java Thu Sep 18 14:44:56 2008
@@ -33,20 +33,24 @@
import org.apache.james.mime4j.parser.MimeTokenStream;
/**
- * Searches an email for content.
- * This class should be safe for use by concurrent threads.
+ * Searches an email for content. This class should be safe for use by
+ * concurrent threads.
*/
class MessageSearcher {
-
+
private Log logger;
-
+
private CharSequence searchContent = null;
+
private boolean isCaseInsensitive = false;
+
private boolean includeHeaders = false;
-
- public MessageSearcher() {}
-
- public MessageSearcher(CharSequence searchContent, boolean isCaseInsensitive, boolean includeHeaders) {
+
+ public MessageSearcher() {
+ }
+
+ public MessageSearcher(CharSequence searchContent,
+ boolean isCaseInsensitive, boolean includeHeaders) {
super();
this.searchContent = searchContent;
this.isCaseInsensitive = isCaseInsensitive;
@@ -55,8 +59,8 @@
/**
* Is the search to include headers?
- * @return true if header values are included,
- * false otherwise
+ *
+ * @return true if header values are included, false otherwise
*/
public boolean isIncludeHeaders() {
return includeHeaders;
@@ -64,8 +68,9 @@
/**
* Sets whether the search should include headers.
- * @param true if header values are included,
- * false otherwise
+ *
+ * @param true
+ * if header values are included, false otherwise
*/
public synchronized void setIncludeHeaders(boolean includesHeaders) {
this.includeHeaders = includesHeaders;
@@ -73,47 +78,54 @@
/**
* Is this search case insensitive?
- * @return true if the search should be case insensitive,
- * false otherwise
+ *
+ * @return true if the search should be case insensitive, false otherwise
*/
public boolean isCaseInsensitive() {
return isCaseInsensitive;
}
-
+
/**
* Sets whether the search should be case insensitive.
- * @param isCaseInsensitive true for case insensitive searches,
- * false otherwise
+ *
+ * @param isCaseInsensitive
+ * true for case insensitive searches, false otherwise
*/
public synchronized void setCaseInsensitive(boolean isCaseInsensitive) {
this.isCaseInsensitive = isCaseInsensitive;
}
-
+
/**
* Gets the content to be searched for.
+ *
* @return search content, initially null
*/
public CharSequence getSearchContent() {
return searchContent;
}
-
+
/**
* Sets the content sought.
- * @param searchContent content sought
+ *
+ * @param searchContent
+ * content sought
*/
public synchronized void setSearchContent(CharSequence searchContent) {
this.searchContent = searchContent;
}
-
+
/**
* Is {@link #getSearchContent()} found in the given input?
- * @param input <code>InputStream</code> containing an email
- * @return true if the content exists and the stream contains the content,
- * false otherwise
+ *
+ * @param input
+ * <code>InputStream</code> containing an email
+ * @return true if the content exists and the stream contains the content,
+ * false otherwise
* @throws IOException
* @throws MimeException
*/
- public boolean isFoundIn(final InputStream input) throws IOException, MimeException {
+ public boolean isFoundIn(final InputStream input) throws IOException,
+ MimeException {
final boolean includeHeaders;
final CharSequence searchContent;
final boolean isCaseInsensitive;
@@ -128,14 +140,16 @@
logger.debug("Nothing to search for. ");
result = false;
} else {
- final CharBuffer buffer = createBuffer(searchContent, isCaseInsensitive);
- result = parse(input, isCaseInsensitive, includeHeaders, buffer);
+ final CharBuffer buffer = createBuffer(searchContent,
+ isCaseInsensitive);
+ result = parse(input, isCaseInsensitive, includeHeaders, buffer);
}
return result;
}
- private boolean parse(final InputStream input, final boolean isCaseInsensitive,
- final boolean includeHeaders, final CharBuffer buffer) throws IOException, MimeException {
+ private boolean parse(final InputStream input,
+ final boolean isCaseInsensitive, final boolean includeHeaders,
+ final CharBuffer buffer) throws IOException, MimeException {
try {
boolean result = false;
MimeTokenStream parser = new MimeTokenStream();
@@ -146,11 +160,13 @@
case MimeTokenStream.T_BODY:
case MimeTokenStream.T_PREAMBLE:
case MimeTokenStream.T_EPILOGUE:
- result = checkBody(isCaseInsensitive, buffer, result, parser);
+ result = checkBody(isCaseInsensitive, buffer, result,
+ parser);
break;
case MimeTokenStream.T_FIELD:
if (includeHeaders) {
- result = checkHeader(isCaseInsensitive, buffer, result, parser);
+ result = checkHeader(isCaseInsensitive, buffer,
+ result, parser);
}
break;
}
@@ -166,7 +182,9 @@
return false;
}
- private boolean checkHeader(final boolean isCaseInsensitive, final CharBuffer buffer, boolean result, MimeTokenStream parser) throws IOException {
+ private boolean checkHeader(final boolean isCaseInsensitive,
+ final CharBuffer buffer, boolean result, MimeTokenStream parser)
+ throws IOException {
final String value = parser.getFieldValue();
final StringReader reader = new StringReader(value);
if (isFoundIn(reader, buffer, isCaseInsensitive)) {
@@ -175,7 +193,9 @@
return result;
}
- private boolean checkBody(final boolean isCaseInsensitive, final CharBuffer buffer, boolean result, MimeTokenStream parser) throws IOException {
+ private boolean checkBody(final boolean isCaseInsensitive,
+ final CharBuffer buffer, boolean result, MimeTokenStream parser)
+ throws IOException {
final Reader reader = parser.getReader();
if (isFoundIn(reader, buffer, isCaseInsensitive)) {
result = true;
@@ -183,12 +203,13 @@
return result;
}
- private CharBuffer createBuffer(final CharSequence searchContent, final boolean isCaseInsensitive) {
+ private CharBuffer createBuffer(final CharSequence searchContent,
+ final boolean isCaseInsensitive) {
final CharBuffer buffer;
if (isCaseInsensitive) {
final int length = searchContent.length();
buffer = CharBuffer.allocate(length);
- for (int i=0;i<length;i++) {
+ for (int i = 0; i < length; i++) {
final char next = searchContent.charAt(i);
final char upperCase = Character.toUpperCase(next);
buffer.put(upperCase);
@@ -199,24 +220,25 @@
}
return buffer;
}
-
- protected void handle(Exception e) throws IOException, MimeException {
+
+ protected void handle(Exception e) throws IOException, MimeException {
final Log logger = getLogger();
logger.warn("Cannot read MIME body.");
logger.debug("Failed to read body.", e);
}
-
- private boolean isFoundIn(final Reader reader, final CharBuffer buffer, final boolean isCaseInsensitive) throws IOException {
+
+ private boolean isFoundIn(final Reader reader, final CharBuffer buffer,
+ final boolean isCaseInsensitive) throws IOException {
boolean result = false;
int read;
while (!result && (read = reader.read()) != -1) {
- final char next;
- if (isCaseInsensitive) {
- next = Character.toUpperCase((char) read);
- } else {
- next = (char) read;
- }
- result = matches(buffer, next);
+ final char next;
+ if (isCaseInsensitive) {
+ next = Character.toUpperCase((char) read);
+ } else {
+ next = (char) read;
+ }
+ result = matches(buffer, next);
}
return result;
}
@@ -224,14 +246,14 @@
private boolean matches(final CharBuffer buffer, final char next) {
boolean result = false;
if (buffer.hasRemaining()) {
- final boolean partialMatch = (buffer.position() > 0);
+ final boolean partialMatch = (buffer.position() > 0);
final char matching = buffer.get();
if (next != matching) {
buffer.rewind();
if (partialMatch) {
result = matches(buffer, next);
}
- }
+ }
} else {
result = true;
}
@@ -242,7 +264,7 @@
if (logger == null) {
logger = LogFactory.getLog(MessageSearcher.class);
}
- return logger;
+ return logger;
}
public final void setLogger(Log logger) {
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearches.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearches.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearches.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageSearches.java Thu Sep 18 14:44:56 2008
@@ -49,10 +49,11 @@
* Uility methods to help perform search operations.
*/
class MessageSearches {
-
+
private Log log;
+
private boolean isCustomLog = false;
-
+
public final Log getLog() {
if (log == null) {
log = LogFactory.getLog(MessageSearches.class);
@@ -67,19 +68,23 @@
/**
* Does the row match the given criteria?
- * @param query <code>SearchQuery</code>, not null
- * @param row <code>MessageRow</code>, not null
- * @return true if the row matches the given criteria,
- * false otherwise
+ *
+ * @param query
+ * <code>SearchQuery</code>, not null
+ * @param row
+ * <code>MessageRow</code>, not null
+ * @return true if the row matches the given criteria, false otherwise
* @throws TorqueException
*/
- public boolean isMatch(final SearchQuery query, final MessageRow row) throws TorqueException {
+ public boolean isMatch(final SearchQuery query, final MessageRow row)
+ throws TorqueException {
final List criteria = query.getCriterias();
final Collection recentMessageUids = query.getRecentMessageUids();
boolean result = true;
if (criteria != null) {
for (Iterator it = criteria.iterator(); it.hasNext();) {
- final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it.next();
+ final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it
+ .next();
if (!isMatch(criterion, row, recentMessageUids)) {
result = false;
break;
@@ -88,16 +93,19 @@
}
return result;
}
-
+
/**
* Does the row match the given criterion?
- * @param query <code>SearchQuery.Criterion</code>, not null
- * @param row <code>MessageRow</code>, not null
- * @return true if the row matches the given criterion,
- * false otherwise
+ *
+ * @param query
+ * <code>SearchQuery.Criterion</code>, not null
+ * @param row
+ * <code>MessageRow</code>, not null
+ * @return true if the row matches the given criterion, false otherwise
* @throws TorqueException
*/
- public boolean isMatch(SearchQuery.Criterion criterion, MessageRow row, final Collection recentMessageUids) throws TorqueException {
+ public boolean isMatch(SearchQuery.Criterion criterion, MessageRow row,
+ final Collection recentMessageUids) throws TorqueException {
final boolean result;
if (criterion instanceof SearchQuery.InternalDateCriterion) {
result = matches((SearchQuery.InternalDateCriterion) criterion, row);
@@ -108,43 +116,52 @@
} else if (criterion instanceof SearchQuery.UidCriterion) {
result = matches((SearchQuery.UidCriterion) criterion, row);
} else if (criterion instanceof SearchQuery.FlagCriterion) {
- result = matches((SearchQuery.FlagCriterion) criterion, row, recentMessageUids);
+ result = matches((SearchQuery.FlagCriterion) criterion, row,
+ recentMessageUids);
} else if (criterion instanceof SearchQuery.TextCriterion) {
result = matches((SearchQuery.TextCriterion) criterion, row);
} else if (criterion instanceof SearchQuery.AllCriterion) {
result = true;
} else if (criterion instanceof SearchQuery.ConjunctionCriterion) {
- result = matches((SearchQuery.ConjunctionCriterion) criterion, row, recentMessageUids);
+ result = matches((SearchQuery.ConjunctionCriterion) criterion, row,
+ recentMessageUids);
} else {
throw new UnsupportedSearchException();
}
return result;
}
-
-
- private boolean matches(SearchQuery.TextCriterion criterion, MessageRow row) throws TorqueException {
+
+ private boolean matches(SearchQuery.TextCriterion criterion, MessageRow row)
+ throws TorqueException {
try {
- final SearchQuery.ContainsOperator operator = criterion.getOperator();
+ final SearchQuery.ContainsOperator operator = criterion
+ .getOperator();
final String value = operator.getValue();
final int type = criterion.getType();
switch (type) {
- case SearchQuery.TextCriterion.BODY: return bodyContains(value, row);
- case SearchQuery.TextCriterion.FULL_MESSAGE: return messageContains(value, row);
- default: throw new UnsupportedSearchException();
+ case SearchQuery.TextCriterion.BODY:
+ return bodyContains(value, row);
+ case SearchQuery.TextCriterion.FULL_MESSAGE:
+ return messageContains(value, row);
+ default:
+ throw new UnsupportedSearchException();
}
} catch (IOException e) {
throw new TorqueException(e);
}
}
-
- private boolean bodyContains(String value, MessageRow row) throws TorqueException, IOException, MimeException {
+
+ private boolean bodyContains(String value, MessageRow row)
+ throws TorqueException, IOException, MimeException {
final InputStream input = MessageRowUtils.toInput(row);
final boolean result = isInMessage(value, input, false);
return result;
}
- private boolean isInMessage(String value, final InputStream input, boolean header) throws IOException, MimeException {
- final MessageSearcher searcher = new MessageSearcher(value, true, header);
+ private boolean isInMessage(String value, final InputStream input,
+ boolean header) throws IOException, MimeException {
+ final MessageSearcher searcher = new MessageSearcher(value, true,
+ header);
if (isCustomLog) {
searcher.setLogger(log);
}
@@ -152,27 +169,36 @@
return result;
}
- private boolean messageContains(String value, MessageRow row) throws TorqueException, IOException, MimeException {
+ private boolean messageContains(String value, MessageRow row)
+ throws TorqueException, IOException, MimeException {
final InputStream input = MessageRowUtils.toInput(row);
final boolean result = isInMessage(value, input, true);
return result;
}
- private boolean matches(SearchQuery.ConjunctionCriterion criterion, MessageRow row, final Collection recentMessageUids) throws TorqueException {
+ private boolean matches(SearchQuery.ConjunctionCriterion criterion,
+ MessageRow row, final Collection recentMessageUids)
+ throws TorqueException {
final int type = criterion.getType();
final List criteria = criterion.getCriteria();
switch (type) {
- case SearchQuery.ConjunctionCriterion.NOR: return nor(criteria, row, recentMessageUids);
- case SearchQuery.ConjunctionCriterion.OR: return or(criteria, row, recentMessageUids);
- case SearchQuery.ConjunctionCriterion.AND: return and(criteria, row, recentMessageUids);
- default: return false;
+ case SearchQuery.ConjunctionCriterion.NOR:
+ return nor(criteria, row, recentMessageUids);
+ case SearchQuery.ConjunctionCriterion.OR:
+ return or(criteria, row, recentMessageUids);
+ case SearchQuery.ConjunctionCriterion.AND:
+ return and(criteria, row, recentMessageUids);
+ default:
+ return false;
}
}
-
- private boolean and(final List criteria, final MessageRow row, final Collection recentMessageUids) throws TorqueException {
+
+ private boolean and(final List criteria, final MessageRow row,
+ final Collection recentMessageUids) throws TorqueException {
boolean result = true;
for (Iterator it = criteria.iterator(); it.hasNext();) {
- final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it.next();
+ final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it
+ .next();
final boolean matches = isMatch(criterion, row, recentMessageUids);
if (!matches) {
result = false;
@@ -181,11 +207,13 @@
}
return result;
}
-
- private boolean or(final List criteria, final MessageRow row, final Collection recentMessageUids) throws TorqueException {
+
+ private boolean or(final List criteria, final MessageRow row,
+ final Collection recentMessageUids) throws TorqueException {
boolean result = false;
for (Iterator it = criteria.iterator(); it.hasNext();) {
- final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it.next();
+ final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it
+ .next();
final boolean matches = isMatch(criterion, row, recentMessageUids);
if (matches) {
result = true;
@@ -194,11 +222,13 @@
}
return result;
}
-
- private boolean nor(final List criteria, final MessageRow row, final Collection recentMessageUids) throws TorqueException {
+
+ private boolean nor(final List criteria, final MessageRow row,
+ final Collection recentMessageUids) throws TorqueException {
boolean result = true;
for (Iterator it = criteria.iterator(); it.hasNext();) {
- final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it.next();
+ final SearchQuery.Criterion criterion = (SearchQuery.Criterion) it
+ .next();
final boolean matches = isMatch(criterion, row, recentMessageUids);
if (matches) {
result = false;
@@ -208,7 +238,9 @@
return result;
}
- private boolean matches(SearchQuery.FlagCriterion criterion, MessageRow row, final Collection recentMessageUids) throws TorqueException {
+ private boolean matches(SearchQuery.FlagCriterion criterion,
+ MessageRow row, final Collection recentMessageUids)
+ throws TorqueException {
final SearchQuery.BooleanOperator operator = criterion.getOperator();
final boolean isSet = operator.isSet();
final Flags.Flag flag = criterion.getFlag();
@@ -217,9 +249,9 @@
if (flag == Flags.Flag.ANSWERED) {
result = isSet == messageFlags.getAnswered();
} else if (flag == Flags.Flag.SEEN) {
- result = isSet == messageFlags.getSeen();
+ result = isSet == messageFlags.getSeen();
} else if (flag == Flags.Flag.DRAFT) {
- result = isSet == messageFlags.getDraft();
+ result = isSet == messageFlags.getDraft();
} else if (flag == Flags.Flag.FLAGGED) {
result = isSet == messageFlags.getFlagged();
} else if (flag == Flags.Flag.RECENT) {
@@ -232,8 +264,9 @@
}
return result;
}
-
- private boolean matches(SearchQuery.UidCriterion criterion, MessageRow row) throws TorqueException {
+
+ private boolean matches(SearchQuery.UidCriterion criterion, MessageRow row)
+ throws TorqueException {
final SearchQuery.InOperator operator = criterion.getOperator();
final NumericRange[] ranges = operator.getRange();
final long uid = row.getUid();
@@ -248,15 +281,18 @@
}
return result;
}
-
- private boolean matches(SearchQuery.HeaderCriterion criterion, MessageRow row) throws TorqueException {
+
+ private boolean matches(SearchQuery.HeaderCriterion criterion,
+ MessageRow row) throws TorqueException {
final SearchQuery.HeaderOperator operator = criterion.getOperator();
final String headerName = criterion.getHeaderName();
final boolean result;
if (operator instanceof SearchQuery.DateOperator) {
- result = matches((SearchQuery.DateOperator) operator, headerName, row);
+ result = matches((SearchQuery.DateOperator) operator, headerName,
+ row);
} else if (operator instanceof SearchQuery.ContainsOperator) {
- result = matches((SearchQuery.ContainsOperator)operator, headerName, row);
+ result = matches((SearchQuery.ContainsOperator) operator,
+ headerName, row);
} else if (operator instanceof SearchQuery.ExistsOperator) {
result = exists(headerName, row);
} else {
@@ -265,7 +301,8 @@
return result;
}
- private boolean exists(String headerName, MessageRow row) throws TorqueException {
+ private boolean exists(String headerName, MessageRow row)
+ throws TorqueException {
boolean result = false;
final List headers = row.getMessageHeaders();
for (Iterator it = headers.iterator(); it.hasNext();) {
@@ -279,7 +316,9 @@
return result;
}
- private boolean matches(final SearchQuery.ContainsOperator operator, final String headerName, final MessageRow row) throws TorqueException {
+ private boolean matches(final SearchQuery.ContainsOperator operator,
+ final String headerName, final MessageRow row)
+ throws TorqueException {
final String text = operator.getValue().toUpperCase();
boolean result = false;
final List headers = row.getMessageHeaders();
@@ -299,7 +338,9 @@
return result;
}
- private boolean matches(final SearchQuery.DateOperator operator, final String headerName, final MessageRow row) throws TorqueException {
+ private boolean matches(final SearchQuery.DateOperator operator,
+ final String headerName, final MessageRow row)
+ throws TorqueException {
final int day = operator.getDay();
final int month = operator.getMonth();
final int year = operator.getYear();
@@ -312,18 +353,23 @@
final int isoFieldValue = toISODate(value);
final int type = operator.getType();
switch (type) {
- case SearchQuery.DateOperator.AFTER: return iso < isoFieldValue;
- case SearchQuery.DateOperator.BEFORE: return iso > isoFieldValue;
- case SearchQuery.DateOperator.ON: return iso == isoFieldValue;
- default: throw new UnsupportedSearchException();
+ case SearchQuery.DateOperator.AFTER:
+ return iso < isoFieldValue;
+ case SearchQuery.DateOperator.BEFORE:
+ return iso > isoFieldValue;
+ case SearchQuery.DateOperator.ON:
+ return iso == isoFieldValue;
+ default:
+ throw new UnsupportedSearchException();
}
} catch (ParseException e) {
return false;
- }
+ }
}
}
- private String headerValue(final String headerName, final MessageRow row) throws TorqueException {
+ private String headerValue(final String headerName, final MessageRow row)
+ throws TorqueException {
final List headers = row.getMessageHeaders();
String value = null;
for (Iterator it = headers.iterator(); it.hasNext();) {
@@ -340,73 +386,89 @@
private int toISODate(String value) throws ParseException {
final StringReader reader = new StringReader(value);
final DateTime dateTime = new DateTimeParser(reader).parseAll();
- final int isoFieldValue = toISODate(dateTime.getDay(), dateTime.getMonth(), dateTime.getYear());
+ final int isoFieldValue = toISODate(dateTime.getDay(), dateTime
+ .getMonth(), dateTime.getYear());
return isoFieldValue;
}
-
- private boolean matches(SearchQuery.SizeCriterion criterion, MessageRow row) throws UnsupportedSearchException {
+
+ private boolean matches(SearchQuery.SizeCriterion criterion, MessageRow row)
+ throws UnsupportedSearchException {
final SearchQuery.NumericOperator operator = criterion.getOperator();
final int size = row.getSize();
final long value = operator.getValue();
final int type = operator.getType();
switch (type) {
- case SearchQuery.NumericOperator.LESS_THAN: return size < value;
- case SearchQuery.NumericOperator.GREATER_THAN: return size > value;
- case SearchQuery.NumericOperator.EQUALS: return size == value;
- default: throw new UnsupportedSearchException();
+ case SearchQuery.NumericOperator.LESS_THAN:
+ return size < value;
+ case SearchQuery.NumericOperator.GREATER_THAN:
+ return size > value;
+ case SearchQuery.NumericOperator.EQUALS:
+ return size == value;
+ default:
+ throw new UnsupportedSearchException();
}
}
-
- private boolean matches(SearchQuery.InternalDateCriterion criterion, MessageRow row) throws UnsupportedSearchException {
+
+ private boolean matches(SearchQuery.InternalDateCriterion criterion,
+ MessageRow row) throws UnsupportedSearchException {
final SearchQuery.DateOperator operator = criterion.getOperator();
final boolean result = matchesInternalDate(operator, row);
return result;
}
- private boolean matchesInternalDate(final SearchQuery.DateOperator operator, final MessageRow row) throws UnsupportedSearchException {
+ private boolean matchesInternalDate(
+ final SearchQuery.DateOperator operator, final MessageRow row)
+ throws UnsupportedSearchException {
final int day = operator.getDay();
final int month = operator.getMonth();
final int year = operator.getYear();
final Date internalDate = row.getInternalDate();
final int type = operator.getType();
switch (type) {
- case SearchQuery.DateOperator.ON: return on(day, month, year, internalDate);
- case SearchQuery.DateOperator.BEFORE: return before(day, month, year, internalDate);
- case SearchQuery.DateOperator.AFTER: return after(day, month, year, internalDate);
- default: throw new UnsupportedSearchException();
+ case SearchQuery.DateOperator.ON:
+ return on(day, month, year, internalDate);
+ case SearchQuery.DateOperator.BEFORE:
+ return before(day, month, year, internalDate);
+ case SearchQuery.DateOperator.AFTER:
+ return after(day, month, year, internalDate);
+ default:
+ throw new UnsupportedSearchException();
}
}
-
- private boolean on(final int day, final int month, final int year, final Date date) {
+
+ private boolean on(final int day, final int month, final int year,
+ final Date date) {
final Calendar gmt = getGMT();
gmt.setTime(date);
- return day == gmt.get(Calendar.DAY_OF_MONTH)
- && month == (gmt.get(Calendar.MONTH) + 1)
- && year == gmt.get(Calendar.YEAR);
+ return day == gmt.get(Calendar.DAY_OF_MONTH)
+ && month == (gmt.get(Calendar.MONTH) + 1)
+ && year == gmt.get(Calendar.YEAR);
}
-
- private boolean before(final int day, final int month, final int year, final Date date) {
+
+ private boolean before(final int day, final int month, final int year,
+ final Date date) {
return toISODate(date) < toISODate(day, month, year);
}
-
- private boolean after(final int day, final int month, final int year, final Date date) {
+
+ private boolean after(final int day, final int month, final int year,
+ final Date date) {
return toISODate(date) > toISODate(day, month, year);
}
-
+
private int toISODate(final Date date) {
final Calendar gmt = getGMT();
gmt.setTime(date);
final int day = gmt.get(Calendar.DAY_OF_MONTH);
- final int month = (gmt.get(Calendar.MONTH) + 1);
+ final int month = (gmt.get(Calendar.MONTH) + 1);
final int year = gmt.get(Calendar.YEAR);
final int result = toISODate(day, month, year);
return result;
}
-
+
private Calendar getGMT() {
return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.UK);
}
-
+
private static int toISODate(final int day, final int month, final int year) {
final int result = (year * 10000) + (month * 100) + day;
return result;
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageUtils.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageUtils.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageUtils.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageUtils.java Thu Sep 18 14:44:56 2008
@@ -28,26 +28,31 @@
*
*/
public class MessageUtils {
-
+
private static final int BYTE_STREAM_CAPACITY = 8182;
+
private static final int BYTE_BUFFER_SIZE = 4096;
+
public static final byte CR = 0x0D;
+
public static final byte LF = 0x0A;
-
+
/**
- * Counts the number of <code>CR</code>'s and <code>LF</code>'s
- * which do are part of <code>CRLF</code>s.
- * @param contents bytes, not null
+ * Counts the number of <code>CR</code>'s and <code>LF</code>'s which
+ * do are part of <code>CRLF</code>s.
+ *
+ * @param contents
+ * bytes, not null
* @return the number of lines which are not normal <code>CRLF</code>
*/
public static long countUnnormalLines(final byte[] contents) {
int count = 0;
if (contents != null) {
final int length = contents.length;
- for (int i=0;i<length;i++) {
+ for (int i = 0; i < length; i++) {
byte current = contents[i];
if (current == CR) {
- final int next = i+1;
+ final int next = i + 1;
if (next < length) {
if (contents[next] != LF) {
count++;
@@ -55,8 +60,8 @@
} else {
count++;
}
- } else if (current == LF) {
- final int last = i-1;
+ } else if (current == LF) {
+ final int last = i - 1;
if (last >= 0) {
if (contents[last] != CR) {
count++;
@@ -69,16 +74,20 @@
}
return count;
}
-
+
/**
- * Writes bytes into the buffer using naive encoding
- * and converts isolated LF and CR to CRLF.
- * @param contents bytes to write, not null
- * @param buffer <code>StringBuffer</code> sink, not null
+ * Writes bytes into the buffer using naive encoding and converts isolated
+ * LF and CR to CRLF.
+ *
+ * @param contents
+ * bytes to write, not null
+ * @param buffer
+ * <code>StringBuffer</code> sink, not null
*/
- public static void normalisedWriteTo(final byte[] contents, final StringBuffer buffer) {
+ public static void normalisedWriteTo(final byte[] contents,
+ final StringBuffer buffer) {
char last = 0;
- for (int i=0;i<contents.length;i++) {
+ for (int i = 0; i < contents.length; i++) {
final char current = (char) contents[i];
if (current == '\n') {
if (last == '\r') {
@@ -101,13 +110,14 @@
}
public static byte[] toByteArray(InputStream is) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(BYTE_STREAM_CAPACITY);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(
+ BYTE_STREAM_CAPACITY);
byte[] buf = new byte[BYTE_BUFFER_SIZE];
int read;
while ((read = is.read(buf)) > 0) {
baos.write(buf, 0, read);
}
-
+
final byte[] bytes = baos.toByteArray();
return bytes;
}
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MimeDescriptorImpl.java Thu Sep 18 14:44:56 2008
@@ -35,9 +35,11 @@
import org.apache.james.mime4j.parser.RecursionMode;
public class MimeDescriptorImpl implements MessageResult.MimeDescriptor {
-
- public static MimeDescriptorImpl build(final InputStream stream) throws IOException {
- final MimeTokenStream parser = MimeTokenStream.createMaximalDescriptorStream();
+
+ public static MimeDescriptorImpl build(final InputStream stream)
+ throws IOException {
+ final MimeTokenStream parser = MimeTokenStream
+ .createMaximalDescriptorStream();
parser.parse(stream);
parser.setRecursionMode(RecursionMode.M_NO_RECURSE);
return createDescriptor(parser);
@@ -47,14 +49,16 @@
final MimeTokenStream parser) throws IOException, MimeException {
int next = parser.next();
final Collection headers = new ArrayList();
- while (next != MimeTokenStream.T_BODY && next != MimeTokenStream.T_END_OF_STREAM
+ while (next != MimeTokenStream.T_BODY
+ && next != MimeTokenStream.T_END_OF_STREAM
&& next != MimeTokenStream.T_START_MULTIPART) {
if (next == MimeTokenStream.T_FIELD) {
- headers.add(new Header(parser.getFieldName(), parser.getFieldValue().trim()));
+ headers.add(new Header(parser.getFieldName(), parser
+ .getFieldValue().trim()));
}
next = parser.next();
- }
-
+ }
+
final MimeDescriptorImpl mimeDescriptorImpl;
switch (next) {
case MimeTokenStream.T_BODY:
@@ -72,11 +76,15 @@
}
private static MimeDescriptorImpl compositePartDescriptor(
- final MimeTokenStream parser, final Collection headers) throws IOException {
- MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
- MimeDescriptorImpl mimeDescriptor = createDescriptor(0, 0, descriptor, null, headers);
+ final MimeTokenStream parser, final Collection headers)
+ throws IOException {
+ MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser
+ .getBodyDescriptor();
+ MimeDescriptorImpl mimeDescriptor = createDescriptor(0, 0, descriptor,
+ null, headers);
int next = parser.next();
- while (next != MimeTokenStream.T_END_MULTIPART && next != MimeTokenStream.T_END_OF_STREAM) {
+ while (next != MimeTokenStream.T_END_MULTIPART
+ && next != MimeTokenStream.T_END_OF_STREAM) {
if (next == MimeTokenStream.T_START_BODYPART) {
mimeDescriptor.addPart(createDescriptor(parser));
}
@@ -84,45 +92,52 @@
}
return mimeDescriptor;
}
-
+
private static MimeDescriptorImpl simplePartDescriptor(
- final MimeTokenStream parser, final Collection headers) throws IOException {
- MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
+ final MimeTokenStream parser, final Collection headers)
+ throws IOException {
+ MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser
+ .getBodyDescriptor();
final MimeDescriptorImpl mimeDescriptorImpl;
- if ("message".equalsIgnoreCase(descriptor.getMediaType()) && "rfc822".equalsIgnoreCase(descriptor.getSubType())) {
- final CountingInputStream messageStream = new CountingInputStream(parser.getDecodedInputStream());
+ if ("message".equalsIgnoreCase(descriptor.getMediaType())
+ && "rfc822".equalsIgnoreCase(descriptor.getSubType())) {
+ final CountingInputStream messageStream = new CountingInputStream(
+ parser.getDecodedInputStream());
MimeDescriptorImpl embeddedMessageDescriptor = build(messageStream);
final int octetCount = messageStream.getOctetCount();
final int lineCount = messageStream.getLineCount();
-
- mimeDescriptorImpl = createDescriptor(octetCount, lineCount, descriptor, embeddedMessageDescriptor, headers);
+
+ mimeDescriptorImpl = createDescriptor(octetCount, lineCount,
+ descriptor, embeddedMessageDescriptor, headers);
} else {
final InputStream body = parser.getInputStream();
long bodyOctets = 0;
long lines = 0;
- for (int n=body.read();n>=0;n=body.read()) {
+ for (int n = body.read(); n >= 0; n = body.read()) {
if (n == '\r') {
lines++;
}
bodyOctets++;
}
-
- mimeDescriptorImpl = createDescriptor(bodyOctets, lines, descriptor, null, headers);
+
+ mimeDescriptorImpl = createDescriptor(bodyOctets, lines,
+ descriptor, null, headers);
}
return mimeDescriptorImpl;
}
private static MimeDescriptorImpl createDescriptor(long bodyOctets,
- long lines, MaximalBodyDescriptor descriptor, MimeDescriptor embeddedMessage, final Collection headers) {
+ long lines, MaximalBodyDescriptor descriptor,
+ MimeDescriptor embeddedMessage, final Collection headers) {
final String contentDescription = descriptor.getContentDescription();
final String contentId = descriptor.getContentId();
-
+
final String subType = descriptor.getSubType();
final String type = descriptor.getMediaType();
final String transferEncoding = descriptor.getTransferEncoding();
final Collection contentTypeParameters = new ArrayList();
final Map valuesByName = descriptor.getContentTypeParameters();
- for (final Iterator it=valuesByName.keySet().iterator(); it.hasNext(); ) {
+ for (final Iterator it = valuesByName.keySet().iterator(); it.hasNext();) {
final String name = (String) it.next();
final String value = (String) valuesByName.get(name);
contentTypeParameters.add(new Header(name, value));
@@ -130,7 +145,7 @@
final String codeset = descriptor.getCharset();
Header header;
if (codeset == null) {
- if ("TEXT".equals(type)) {
+ if ("TEXT".equals(type)) {
header = new Header("charset", "us-ascii");
} else {
header = null;
@@ -147,38 +162,59 @@
}
final List languages = descriptor.getContentLanguage();
final String disposition = descriptor.getContentDispositionType();
- final Map dispositionParams = descriptor.getContentDispositionParameters();
+ final Map dispositionParams = descriptor
+ .getContentDispositionParameters();
final Collection parts = new ArrayList();
final String location = descriptor.getContentLocation();
final String md5 = descriptor.getContentMD5Raw();
- final MimeDescriptorImpl mimeDescriptorImpl = new MimeDescriptorImpl(bodyOctets, contentDescription, contentId, lines, subType, type, transferEncoding,
- headers, contentTypeParameters, languages, disposition, dispositionParams, embeddedMessage, parts,
- location, md5);
+ final MimeDescriptorImpl mimeDescriptorImpl = new MimeDescriptorImpl(
+ bodyOctets, contentDescription, contentId, lines, subType,
+ type, transferEncoding, headers, contentTypeParameters,
+ languages, disposition, dispositionParams, embeddedMessage,
+ parts, location, md5);
return mimeDescriptorImpl;
}
-
+
private final long bodyOctets;
+
private final String contentDescription;
+
private final String contentId;
+
private final long lines;
+
private final String subType;
+
private final String type;
+
private final String transferEncoding;
+
private final List languages;
+
private final Collection headers;
+
private final Collection contentTypeParameters;
+
private final String disposition;
+
private final Map dispositionParams;
+
private final MessageResult.MimeDescriptor embeddedMessage;
+
private final Collection parts;
+
private final String location;
+
private final String md5;
-
- public MimeDescriptorImpl(final long bodyOctets, final String contentDescription, final String contentId,
- final long lines, final String subType, final String type, final String transferEncoding, final Collection headers,
- final Collection contentTypeParameters, final List languages, String disposition, Map dispositionParams,
- final MimeDescriptor embeddedMessage, final Collection parts, final String location,
- final String md5) {
+
+ public MimeDescriptorImpl(final long bodyOctets,
+ final String contentDescription, final String contentId,
+ final long lines, final String subType, final String type,
+ final String transferEncoding, final Collection headers,
+ final Collection contentTypeParameters, final List languages,
+ String disposition, Map dispositionParams,
+ final MimeDescriptor embeddedMessage, final Collection parts,
+ final String location, final String md5) {
super();
this.type = type;
this.bodyOctets = bodyOctets;
@@ -245,7 +281,7 @@
private void addPart(MimeDescriptor descriptor) {
parts.add(descriptor);
}
-
+
public List getLanguages() {
return languages;
}
@@ -269,10 +305,11 @@
private static final class CountingInputStream extends InputStream {
private final InputStream in;
-
+
private int lineCount;
+
private int octetCount;
-
+
private CountingInputStream(InputStream in) {
super();
this.in = in;
@@ -280,7 +317,7 @@
public int read() throws IOException {
int next = in.read();
- if (next >0) {
+ if (next > 0) {
octetCount++;
if (next == '\r') {
lineCount++;
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/OrFetchGroup.java Thu Sep 18 14:44:56 2008
@@ -27,11 +27,11 @@
* Wraps a fetch group and ORs content.
*/
public final class OrFetchGroup implements FetchGroup {
-
private final FetchGroup delegate;
+
private final int or;
-
+
public OrFetchGroup(final FetchGroup delegate, final int or) {
super();
this.delegate = delegate;
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/PartContentBuilder.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/PartContentBuilder.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/PartContentBuilder.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/PartContentBuilder.java Thu Sep 18 14:44:56 2008
@@ -30,38 +30,45 @@
import org.apache.james.mime4j.parser.MimeTokenStream;
public class PartContentBuilder {
-
+
private static final byte[] EMPTY = {};
-
+
private MimeTokenStream parser;
+
private boolean empty = false;
+
private boolean topLevel = true;
-
+
public PartContentBuilder() {
parser = new MimeTokenStream();
}
-
+
public void markEmpty() {
empty = true;
}
-
+
public void parse(final InputStream in) {
parser.setRecursionMode(MimeTokenStream.M_RECURSE);
parser.parse(in);
topLevel = true;
}
-
+
private void skipToStartOfInner(int position) throws IOException {
final int state = parser.next();
switch (state) {
- case MimeTokenStream.T_START_MULTIPART: break;
- case MimeTokenStream.T_START_MESSAGE: break;
- case MimeTokenStream.T_END_OF_STREAM: throw new PartNotFoundException(position);
- case MimeTokenStream.T_END_BODYPART: throw new PartNotFoundException(position);
- default: skipToStartOfInner(position);
+ case MimeTokenStream.T_START_MULTIPART:
+ break;
+ case MimeTokenStream.T_START_MESSAGE:
+ break;
+ case MimeTokenStream.T_END_OF_STREAM:
+ throw new PartNotFoundException(position);
+ case MimeTokenStream.T_END_BODYPART:
+ throw new PartNotFoundException(position);
+ default:
+ skipToStartOfInner(position);
}
}
-
+
public void to(int position) throws IOException {
try {
if (topLevel) {
@@ -69,7 +76,7 @@
} else {
skipToStartOfInner(position);
}
- for (int count=0;count<position;) {
+ for (int count = 0; count < position;) {
final int state = parser.next();
switch (state) {
case MimeTokenStream.T_BODY:
@@ -81,7 +88,7 @@
count++;
break;
case MimeTokenStream.T_START_MULTIPART:
- if (count>0 && count<position) {
+ if (count > 0 && count < position) {
ignoreInnerMessage();
}
break;
@@ -89,31 +96,31 @@
throw new PartNotFoundException(position);
}
}
- }
- catch (IllegalStateException e) {
+ } catch (IllegalStateException e) {
throw new PartNotFoundException(position, e);
}
}
-
+
private void ignoreInnerMessage() throws IOException {
- for (int state = parser.next(); state != MimeTokenStream.T_END_MULTIPART; state = parser.next()) {
+ for (int state = parser.next(); state != MimeTokenStream.T_END_MULTIPART; state = parser
+ .next()) {
switch (state) {
case MimeTokenStream.T_END_OF_STREAM:
throw new UnexpectedEOFException();
-
+
case MimeTokenStream.T_START_MULTIPART:
ignoreInnerMessage();
break;
}
}
}
-
+
public Content getFullContent() throws IOException {
final List headers = getMimeHeaders();
final byte[] content = mimeBodyContent();
return new FullContent(content, headers);
}
-
+
public Content getMessageBodyContent() throws IOException {
final byte[] content = messageBodyContent();
return new ByteContent(content);
@@ -125,8 +132,7 @@
content = EMPTY;
} else {
boolean valid;
- try
- {
+ try {
advancedToMessage();
valid = true;
} catch (UnexpectedEOFException e) {
@@ -135,9 +141,9 @@
}
if (valid) {
parser.setRecursionMode(MimeTokenStream.M_FLAT);
- for ( int state = parser.getState();
- state != MimeTokenStream.T_BODY && state != MimeTokenStream.T_START_MULTIPART;
- state = parser.next()) {
+ for (int state = parser.getState(); state != MimeTokenStream.T_BODY
+ && state != MimeTokenStream.T_START_MULTIPART; state = parser
+ .next()) {
if (state == MimeTokenStream.T_END_OF_STREAM) {
valid = false;
break;
@@ -154,7 +160,7 @@
}
return content;
}
-
+
public Content getMimeBodyContent() throws IOException {
final byte[] content = mimeBodyContent();
return new ByteContent(content);
@@ -167,9 +173,9 @@
} else {
parser.setRecursionMode(MimeTokenStream.M_FLAT);
boolean valid = true;
- for ( int state = parser.getState();
- state != MimeTokenStream.T_BODY && state != MimeTokenStream.T_START_MULTIPART;
- state = parser.next()) {
+ for (int state = parser.getState(); state != MimeTokenStream.T_BODY
+ && state != MimeTokenStream.T_START_MULTIPART; state = parser
+ .next()) {
if (state == MimeTokenStream.T_END_OF_STREAM) {
valid = false;
break;
@@ -183,18 +189,19 @@
}
return content;
}
-
+
public List getMimeHeaders() throws IOException {
final List results;
if (empty) {
results = Collections.EMPTY_LIST;
} else {
results = new ArrayList();
- for (int state = parser.getState(); state != MimeTokenStream.T_END_HEADER; state = parser.next()) {
+ for (int state = parser.getState(); state != MimeTokenStream.T_END_HEADER; state = parser
+ .next()) {
switch (state) {
case MimeTokenStream.T_END_OF_STREAM:
throw new UnexpectedEOFException();
-
+
case MimeTokenStream.T_FIELD:
final String fieldValue = parser.getFieldValue().trim();
final String fieldName = parser.getFieldName();
@@ -206,24 +213,25 @@
}
return results;
}
-
+
public List getMessageHeaders() throws IOException {
final List results;
if (empty) {
results = Collections.EMPTY_LIST;
} else {
results = new ArrayList();
- try
- {
+ try {
advancedToMessage();
-
- for (int state = parser.getState(); state != MimeTokenStream.T_END_HEADER; state = parser.next()) {
+
+ for (int state = parser.getState(); state != MimeTokenStream.T_END_HEADER; state = parser
+ .next()) {
switch (state) {
case MimeTokenStream.T_END_OF_STREAM:
throw new IOException("Unexpected EOF");
-
+
case MimeTokenStream.T_FIELD:
- final String fieldValue = parser.getFieldValue().trim();
+ final String fieldValue = parser.getFieldValue()
+ .trim();
final String fieldName = parser.getFieldName();
Header header = new Header(fieldName, fieldValue);
results.add(header);
@@ -238,28 +246,29 @@
}
private void advancedToMessage() throws IOException {
- for (int state = parser.getState(); state != MimeTokenStream.T_START_MESSAGE; state = parser.next()) {
+ for (int state = parser.getState(); state != MimeTokenStream.T_START_MESSAGE; state = parser
+ .next()) {
if (state == MimeTokenStream.T_END_OF_STREAM) {
throw new UnexpectedEOFException();
}
}
}
-
+
public static final class UnexpectedEOFException extends MimeException {
private static final long serialVersionUID = -3755637466593055796L;
public UnexpectedEOFException() {
super("Unexpected EOF");
- }
+ }
}
-
+
public static final class PartNotFoundException extends MimeException {
private static final long serialVersionUID = 7519976990944851574L;
-
+
private final int position;
-
+
public PartNotFoundException(int position) {
this(position, null);
}
@@ -268,10 +277,10 @@
super("Part " + position + " not found.", e);
this.position = position;
}
-
+
public final int getPosition() {
return position;
}
-
+
}
}
Modified: james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueCriteriaBuilder.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueCriteriaBuilder.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueCriteriaBuilder.java (original)
+++ james/protocols/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueCriteriaBuilder.java Thu Sep 18 14:44:56 2008
@@ -29,27 +29,33 @@
class TorqueCriteriaBuilder {
private final Criteria masterCriteria;
+
private boolean headersJoin = false;
+
private boolean flagsJoin = false;
-
+
public TorqueCriteriaBuilder() {
masterCriteria = new Criteria();
}
-
+
public Criteria getCriteria() {
return masterCriteria;
}
-
+
public void andHeaderContains(final String header, final String value) {
joinHeaders();
- final Criteria.Criterion nameCriterion = masterCriteria.getNewCriterion(MessageHeaderPeer.FIELD, header, Criteria.EQUAL);
+ final Criteria.Criterion nameCriterion = masterCriteria
+ .getNewCriterion(MessageHeaderPeer.FIELD, header,
+ Criteria.EQUAL);
if (value != null) {
- final Criteria.Criterion valueCriterion = masterCriteria.getNewCriterion(MessageHeaderPeer.VALUE, value, Criteria.LIKE);
+ final Criteria.Criterion valueCriterion = masterCriteria
+ .getNewCriterion(MessageHeaderPeer.VALUE, value,
+ Criteria.LIKE);
nameCriterion.and(valueCriterion);
}
masterCriteria.add(nameCriterion);
}
-
+
public void andFlag(Flag flag, boolean value) {
joinFlags();
if (Flag.ANSWERED.equals(flag)) {
@@ -66,19 +72,21 @@
masterCriteria.add(MessageFlagsPeer.SEEN, value);
}
}
-
+
public void joinFlags() {
if (!flagsJoin) {
flagsJoin = true;
- masterCriteria.addJoin(MessageRowPeer.MAILBOX_ID, MessageFlagsPeer.MAILBOX_ID);
+ masterCriteria.addJoin(MessageRowPeer.MAILBOX_ID,
+ MessageFlagsPeer.MAILBOX_ID);
masterCriteria.addJoin(MessageRowPeer.UID, MessageFlagsPeer.UID);
}
}
-
+
public void joinHeaders() {
if (!headersJoin) {
headersJoin = true;
- masterCriteria.addJoin(MessageRowPeer.MAILBOX_ID, MessageHeaderPeer.MAILBOX_ID);
+ masterCriteria.addJoin(MessageRowPeer.MAILBOX_ID,
+ MessageHeaderPeer.MAILBOX_ID);
masterCriteria.addJoin(MessageRowPeer.UID, MessageHeaderPeer.UID);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org