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.Date;
019 import java.util.LinkedList;
020
021 import javax.mail.Flags;
022
023 import com.hs.mail.imap.message.request.AppendRequest;
024 import com.hs.mail.imap.message.request.ImapRequest;
025 import com.hs.mail.imap.parser.ParseException;
026 import com.hs.mail.imap.parser.Token;
027 import com.hs.mail.imap.server.codec.DecoderUtils;
028 import com.hs.mail.imap.server.codec.ImapMessage;
029
030 /**
031 *
032 * @author Won Chul Doh
033 * @since Jan 28, 2010
034 *
035 */
036 public class AppendRequestBuilder extends ImapRequestBuilder {
037
038 @Override
039 public ImapRequest createRequest(String tag, String command,
040 ImapMessage message) {
041 LinkedList<Token> tokens = message.getTokens();
042 Token token = tokens.remove();
043 String mailbox = token.value;
044 Flags flags = parseFlagList(tokens);
045 Date datetime = null;
046 token = tokens.remove();
047 if (token.type == Token.Type.DATE_TIME) {
048 try {
049 datetime = DecoderUtils.parseDateTime(token.value);
050 } catch (Exception e) {
051 throw new ParseException(tag, e);
052 }
053 } else {
054 datetime = new Date();
055 }
056 return new AppendRequest(tag, command, mailbox, flags, datetime,
057 message.getLiteral());
058 }
059
060 }