001 /*
002 * Copyright 2010 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.hs.mail.imap.message.builder;
017
018 import java.util.LinkedList;
019
020 import javax.mail.Flags;
021
022 import com.hs.mail.imap.message.SequenceRange;
023 import com.hs.mail.imap.message.request.ImapRequest;
024 import com.hs.mail.imap.message.request.StoreRequest;
025 import com.hs.mail.imap.parser.Token;
026 import com.hs.mail.imap.server.codec.DecoderUtils;
027 import com.hs.mail.imap.server.codec.ImapMessage;
028
029 /**
030 *
031 * @author Won Chul Doh
032 * @since Jan 28, 2010
033 *
034 */
035 public class StoreRequestBuilder extends AbstractUidRequestBuilder {
036
037 @Override
038 public ImapRequest createRequest(String tag, String command,
039 ImapMessage message, boolean useUID) {
040 LinkedList<Token> tokens = message.getTokens();
041 SequenceRange[] sequenceSet = parseSequenceSet(tokens);
042 Token token = tokens.remove();
043 char c = token.value.charAt(0);
044 Boolean sign = null;
045 if (c == '+') {
046 sign = new Boolean(true);
047 } else if (c == '-') {
048 sign = new Boolean(false);
049 }
050 boolean silent = token.value.indexOf('.') > 0;
051 Flags flags = parseFlagList(tokens);
052 if (flags == null) {
053 flags = new Flags();
054 while (!tokens.isEmpty()) {
055 token = tokens.remove();
056 DecoderUtils.decodeFlagList(token.value, flags);
057 }
058 }
059 return new StoreRequest(tag, command, sequenceSet, sign, silent, flags,
060 useUID);
061 }
062
063 }