james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From darr...@apache.org
Subject cvs commit: james-server/proposals/imap2/test/org/apache/james/imapserver ImapMailboxTest.java
Date Sun, 13 Jul 2003 12:04:29 GMT
darrell     2003/07/13 05:04:29

  Modified:    proposals/imap2 build-test.xml
               proposals/imap2/java/org/apache/james/imapserver
                        ImapResponse.java ImapSessionMailbox.java
               proposals/imap2/java/org/apache/james/imapserver/commands
                        AppendCommand.java CommandParser.java
                        FetchCommand.java StoreCommand.java
               proposals/imap2/java/org/apache/james/imapserver/store
                        ImapMailbox.java ImapMessage.java
                        InMemoryStore.java MessageFlags.java
                        SimpleImapMessage.java
               proposals/imap2/test/org/apache/james/imapserver
                        ImapMailboxTest.java
  Log:
  Replaced use of custom MessageFlags with regular javax.mail.Flags
  
  Revision  Changes    Path
  1.6       +5 -0      james-server/proposals/imap2/build-test.xml
  
  Index: build-test.xml
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/build-test.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- build-test.xml	13 Jul 2003 06:04:55 -0000	1.5
  +++ build-test.xml	13 Jul 2003 12:04:29 -0000	1.6
  @@ -173,5 +173,10 @@
               <test name="org.apache.james.imapserver.TestCompound"/>
           </junit>
       </target>
  +    
  +    <target name="build-and-test">
  +        <ant antfile="proposals/imap2/build.xml" target="main"/>
  +        <antcall target="unit-tests"/>
  +    </target>
   </project>
   
  
  
  
  1.6       +5 -4      james-server/proposals/imap2/java/org/apache/james/imapserver/ImapResponse.java
  
  Index: ImapResponse.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/ImapResponse.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ImapResponse.java	13 Jul 2003 06:04:56 -0000	1.5
  +++ ImapResponse.java	13 Jul 2003 12:04:29 -0000	1.6
  @@ -62,6 +62,7 @@
   import org.apache.james.imapserver.store.MessageFlags;
   import org.apache.james.util.InternetPrintWriter;
   
  +import javax.mail.Flags;
   import java.io.PrintWriter;
   import java.io.OutputStream;
   
  @@ -194,11 +195,11 @@
           end();
       }
   
  -    public void flagsResponse( MessageFlags flags )
  +    public void flagsResponse( Flags flags )
       {
           untagged();
           message( "FLAGS" );
  -        message( flags.format() );
  +        message( MessageFlags.format(flags) );
           end();
       }
   
  @@ -315,10 +316,10 @@
           writer.flush();
       }
   
  -    public void permanentFlagsResponse(MessageFlags flags) {
  +    public void permanentFlagsResponse(Flags flags) {
           untagged();
           message(OK);
  -        responseCode("PERMANENTFLAGS " + flags.format());
  +        responseCode("PERMANENTFLAGS " + MessageFlags.format(flags));
           end();
       }
   }
  
  
  
  1.2       +10 -9     james-server/proposals/imap2/java/org/apache/james/imapserver/ImapSessionMailbox.java
  
  Index: ImapSessionMailbox.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/ImapSessionMailbox.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ImapSessionMailbox.java	13 Jul 2003 06:04:56 -0000	1.1
  +++ ImapSessionMailbox.java	13 Jul 2003 12:04:29 -0000	1.2
  @@ -66,6 +66,7 @@
   
   import javax.mail.search.SearchTerm;
   import javax.mail.internet.MimeMessage;
  +import javax.mail.Flags;
   import java.util.List;
   import java.util.Collections;
   import java.util.LinkedList;
  @@ -82,11 +83,11 @@
           _mailbox = mailbox;
           _readonly = readonly;
           // TODO make this a weak reference (or make sure deselect() is *always* called).
  -        _mailbox.addExpungeListener(this);
  +        _mailbox.addListener(this);
       }
   
       public void deselect() {
  -        _mailbox.removeExpungeListener(this);
  +        _mailbox.removeListener(this);
           _mailbox = null;
       }
   
  @@ -137,11 +138,11 @@
           return _mailbox.getFullName();
       }
   
  -    public MessageFlags getAllowedFlags() {
  +    public Flags getAllowedFlags() {
           return _mailbox.getAllowedFlags();
       }
   
  -    public MessageFlags getPermanentFlags() {
  +    public Flags getPermanentFlags() {
           return _mailbox.getPermanentFlags();
       }
   
  @@ -173,7 +174,7 @@
           return _mailbox.getUnseenCount();
       }
   
  -    public SimpleImapMessage createMessage( MimeMessage message, MessageFlags flags, Date
internalDate ) {
  +    public SimpleImapMessage createMessage( MimeMessage message, Flags flags, Date internalDate
) {
           return _mailbox.createMessage(message, flags, internalDate);
       }
   
  @@ -209,12 +210,12 @@
           _mailbox.copyMessage(uid, toMailbox);
       }
   
  -    public void addExpungeListener(MailboxListener listener) {
  -        _mailbox.addExpungeListener(listener);
  +    public void addListener(MailboxListener listener) {
  +        _mailbox.addListener(listener);
       }
   
  -    public void removeExpungeListener(MailboxListener listener) {
  -        _mailbox.removeExpungeListener(listener);
  +    public void removeListener(MailboxListener listener) {
  +        _mailbox.removeListener(listener);
       }
   
   }
  
  
  
  1.5       +5 -5      james-server/proposals/imap2/java/org/apache/james/imapserver/commands/AppendCommand.java
  
  Index: AppendCommand.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/commands/AppendCommand.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AppendCommand.java	8 Mar 2003 21:13:55 -0000	1.4
  +++ AppendCommand.java	13 Jul 2003 12:04:29 -0000	1.5
  @@ -66,8 +66,8 @@
   import org.apache.james.imapserver.ProtocolException;
   import org.apache.james.imapserver.store.ImapMailbox;
   import org.apache.james.imapserver.store.MailboxException;
  -import org.apache.james.imapserver.store.MessageFlags;
   
  +import javax.mail.Flags;
   import javax.mail.internet.MimeMessage;
   import java.io.ByteArrayInputStream;
   import java.io.FilterInputStream;
  @@ -96,9 +96,9 @@
               throws ProtocolException, MailboxException
       {
           String mailboxName = parser.mailbox( request );
  -        MessageFlags flags = parser.optionalAppendFlags( request );
  +        Flags flags = parser.optionalAppendFlags( request );
           if ( flags == null ) {
  -            flags = new MessageFlags();
  +            flags = new Flags();
           }
           Date datetime = parser.optionalDateTime( request );
           if ( datetime == null ) {
  @@ -141,7 +141,7 @@
            * a "flag_list" argument from the request. If not, returns a
            * MessageFlags with no flags set.
            */
  -        public MessageFlags optionalAppendFlags( ImapRequestLineReader request )
  +        public Flags optionalAppendFlags( ImapRequestLineReader request )
                   throws ProtocolException
           {
               char next = request.nextWordChar();
  
  
  
  1.8       +10 -9     james-server/proposals/imap2/java/org/apache/james/imapserver/commands/CommandParser.java
  
  Index: CommandParser.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/commands/CommandParser.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CommandParser.java	8 Mar 2003 21:13:55 -0000	1.7
  +++ CommandParser.java	13 Jul 2003 12:04:29 -0000	1.8
  @@ -64,6 +64,7 @@
   import org.apache.james.imapserver.store.MessageFlags;
   import org.apache.james.util.Assert;
   
  +import javax.mail.Flags;
   import java.util.Date;
   import java.util.TimeZone;
   import java.util.List;
  @@ -352,9 +353,9 @@
       /**
        * Reads a "flags" argument from the request.
        */
  -    public MessageFlags flagList( ImapRequestLineReader request ) throws ProtocolException
  +    public Flags flagList( ImapRequestLineReader request ) throws ProtocolException
       {
  -        MessageFlags flags = new MessageFlags();
  +        Flags flags = new Flags();
           request.nextWordChar();
           consumeChar( request, '(' );
           CharacterValidator validator = new NoopCharValidator();
  @@ -371,22 +372,22 @@
           return flags;
           }
   
  -    public void setFlag( String flagString, MessageFlags flags ) throws ProtocolException
  +    public void setFlag( String flagString, Flags flags ) throws ProtocolException
       {
           if ( flagString.equalsIgnoreCase( MessageFlags.ANSWERED ) ) {
  -            flags.setAnswered( true );
  +            flags.add(Flags.Flag.ANSWERED);
           }
           else if ( flagString.equalsIgnoreCase( MessageFlags.DELETED ) ) {
  -            flags.setDeleted( true );
  +            flags.add(Flags.Flag.DELETED);
           }
           else if ( flagString.equalsIgnoreCase( MessageFlags.DRAFT ) ) {
  -            flags.setDraft( true );
  +            flags.add(Flags.Flag.DRAFT);
           }
           else if ( flagString.equalsIgnoreCase( MessageFlags.FLAGGED ) ) {
  -            flags.setFlagged( true );
  +            flags.add(Flags.Flag.FLAGGED);
           }
           else if ( flagString.equalsIgnoreCase( MessageFlags.SEEN ) ) {
  -            flags.setSeen( true );
  +            flags.add(Flags.Flag.SEEN);
           }
           else {
               throw new ProtocolException( "Invalid flag string." );
  
  
  
  1.5       +7 -6      james-server/proposals/imap2/java/org/apache/james/imapserver/commands/FetchCommand.java
  
  Index: FetchCommand.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/commands/FetchCommand.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FetchCommand.java	13 Jul 2003 06:04:56 -0000	1.4
  +++ FetchCommand.java	13 Jul 2003 12:04:29 -0000	1.5
  @@ -69,6 +69,7 @@
   import org.apache.james.imapserver.store.SimpleImapMessage;
   
   import javax.mail.MessagingException;
  +import javax.mail.Flags;
   import javax.mail.internet.MimeMessage;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  @@ -123,8 +124,8 @@
                   SimpleImapMessage imapMessage = mailbox.getMessage( uid );
                   String msgData = outputMessage( fetch, imapMessage );
                   response.fetchResponse( msn, msgData );
  -                if (imapMessage.getFlags().isRecent()) {
  -                    imapMessage.getFlags().setRecent(false);
  +                if (imapMessage.getFlags().contains(Flags.Flag.RECENT)) {
  +                    imapMessage.getFlags().remove(Flags.Flag.RECENT);
                       mailbox.updateMessage(imapMessage);
                   }
               }
  @@ -150,8 +151,8 @@
               response.append( SP );
   
               if ( fetchElement == FetchElement.FLAGS ) {
  -                MessageFlags flags = message.getFlags();
  -                response.append( flags.format() );
  +                Flags flags = message.getFlags();
  +                response.append( MessageFlags.format(flags) );
               }
               else if ( fetchElement == FetchElement.INTERNALDATE ) {
                   // TODO format properly
  @@ -191,7 +192,7 @@
                   }
   
                   if ( ! peek ) {
  -                    message.getFlags().setSeen( true );
  +                    message.getFlags().add(Flags.Flag.SEEN);
                       // TODO need to store this change.
                   }
               }
  
  
  
  1.4       +11 -8     james-server/proposals/imap2/java/org/apache/james/imapserver/commands/StoreCommand.java
  
  Index: StoreCommand.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/commands/StoreCommand.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StoreCommand.java	8 Mar 2003 21:13:55 -0000	1.3
  +++ StoreCommand.java	13 Jul 2003 12:04:29 -0000	1.4
  @@ -67,6 +67,8 @@
   import org.apache.james.imapserver.store.SimpleImapMessage;
   import org.apache.james.imapserver.store.MailboxException;
   
  +import javax.mail.Flags;
  +
   /**
    * Handles processeing for the STORE imap command.
    *
  @@ -98,7 +100,7 @@
       {
           IdSet idSet = parser.set( request );
           StoreDirective directive = parser.storeDirective( request );
  -        MessageFlags flags = parser.flagList( request );
  +        Flags flags = parser.flagList( request );
           parser.endLine( request );
   
           ImapMailbox mailbox = session.getSelected();
  @@ -116,7 +118,7 @@
   
                   if ( ! directive.isSilent() ) {
                       StringBuffer out = new StringBuffer( "FLAGS " );
  -                    out.append( imapMessage.getFlags().format() );
  +                    out.append( MessageFlags.format(imapMessage.getFlags()) );
                       response.fetchResponse( msn, out.toString() );
                   }
               }
  @@ -126,17 +128,18 @@
           response.commandComplete( this );
       }
   
  -    private void storeFlags( SimpleImapMessage imapMessage, StoreDirective directive, MessageFlags
newFlags )
  +    private void storeFlags( SimpleImapMessage imapMessage, StoreDirective directive, Flags
newFlags )
       {
  -        MessageFlags messageFlags = imapMessage.getFlags();
  +        Flags messageFlags = imapMessage.getFlags();
           if ( directive.getSign() == 0 ) {
  -            messageFlags.setAll( newFlags );
  +            messageFlags.remove(MessageFlags.ALL_FLAGS);
  +            messageFlags.add(newFlags);
           }
           else if ( directive.getSign() < 0 ) {
  -            messageFlags.removeAll( newFlags );
  +            messageFlags.remove(newFlags);
           }
           else if ( directive.getSign() > 0 ) {
  -            messageFlags.addAll( newFlags );
  +            messageFlags.add(newFlags);
           }
       }
   
  
  
  
  1.9       +7 -8      james-server/proposals/imap2/java/org/apache/james/imapserver/store/ImapMailbox.java
  
  Index: ImapMailbox.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/store/ImapMailbox.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ImapMailbox.java	13 Jul 2003 06:04:56 -0000	1.8
  +++ ImapMailbox.java	13 Jul 2003 12:04:29 -0000	1.9
  @@ -58,13 +58,12 @@
   
   package org.apache.james.imapserver.store;
   
  -import org.apache.mailet.MailRepository;
   import org.apache.james.core.MailImpl;
   
   import javax.mail.internet.MimeMessage;
   import javax.mail.search.SearchTerm;
  +import javax.mail.Flags;
   import java.util.Date;
  -import java.util.Collection;
   
   /**
    * Represents a mailbox within an {@link org.apache.james.imapserver.store.ImapStore}.
  @@ -83,9 +82,9 @@
   
       String getFullName();
   
  -    MessageFlags getAllowedFlags();
  +    Flags getAllowedFlags();
       
  -    MessageFlags getPermanentFlags();
  +    Flags getPermanentFlags();
   
       int getMessageCount();
   
  @@ -103,7 +102,7 @@
   
       int getUnseenCount();
   
  -    SimpleImapMessage createMessage( MimeMessage message, MessageFlags flags, Date internalDate
);
  +    SimpleImapMessage createMessage( MimeMessage message, Flags flags, Date internalDate
);
   
       void updateMessage( SimpleImapMessage message ) throws MailboxException;
   
  @@ -117,9 +116,9 @@
       
       void expunge() throws MailboxException;
   
  -    void addExpungeListener(MailboxListener listener);
  +    void addListener(MailboxListener listener);
   
  -    void removeExpungeListener(MailboxListener listener);
  +    void removeListener(MailboxListener listener);
   
       long[] search(SearchTerm searchTerm);
   
  
  
  
  1.6       +3 -2      james-server/proposals/imap2/java/org/apache/james/imapserver/store/ImapMessage.java
  
  Index: ImapMessage.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/store/ImapMessage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ImapMessage.java	8 Mar 2003 21:13:56 -0000	1.5
  +++ ImapMessage.java	13 Jul 2003 12:04:29 -0000	1.6
  @@ -59,6 +59,7 @@
   package org.apache.james.imapserver.store;
   
   import javax.mail.internet.MimeMessage;
  +import javax.mail.Flags;
   import java.util.Date;
   
   /**
  @@ -71,7 +72,7 @@
   {
       MimeMessage getMimeMessage();
   
  -    MessageFlags getFlags();
  +    Flags getFlags();
   
       Date getInternalDate();
   
  
  
  
  1.8       +20 -19    james-server/proposals/imap2/java/org/apache/james/imapserver/store/InMemoryStore.java
  
  Index: InMemoryStore.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/store/InMemoryStore.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- InMemoryStore.java	13 Jul 2003 06:04:56 -0000	1.7
  +++ InMemoryStore.java	13 Jul 2003 12:04:29 -0000	1.8
  @@ -65,6 +65,7 @@
   import javax.mail.internet.MimeMessage;
   import javax.mail.search.SearchTerm;
   import javax.mail.MessagingException;
  +import javax.mail.Flags;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Collections;
  @@ -89,13 +90,13 @@
           implements ImapStore, ImapConstants
   {
       private RootMailbox rootMailbox = new RootMailbox();
  -    private static MessageFlags mailboxFlags = new MessageFlags();
  +    private static final Flags PERMANENT_FLAGS = new Flags();
       static {
  -        mailboxFlags.setAnswered( true );
  -        mailboxFlags.setDeleted( true );
  -        mailboxFlags.setDraft( true );
  -        mailboxFlags.setFlagged( true );
  -        mailboxFlags.setSeen( true );
  +        PERMANENT_FLAGS.add(Flags.Flag.ANSWERED);
  +        PERMANENT_FLAGS.add(Flags.Flag.DELETED);
  +        PERMANENT_FLAGS.add(Flags.Flag.DRAFT);
  +        PERMANENT_FLAGS.add(Flags.Flag.FLAGGED);
  +        PERMANENT_FLAGS.add(Flags.Flag.SEEN);
       }
   
       public ImapMailbox getMailbox( String absoluteMailboxName )
  @@ -301,12 +302,12 @@
               return parent.getFullName() + HIERARCHY_DELIMITER_CHAR + name;
           }
   
  -        public MessageFlags getAllowedFlags()
  +        public Flags getAllowedFlags()
           {
  -            return mailboxFlags;
  +            return PERMANENT_FLAGS;
           }
   
  -        public MessageFlags getPermanentFlags() {
  +        public Flags getPermanentFlags() {
               return getAllowedFlags();
           }
   
  @@ -331,7 +332,7 @@
               Iterator iter = mailMessages.values().iterator();
               while (iter.hasNext()) {
                   SimpleImapMessage message = (SimpleImapMessage) iter.next();
  -                if (! message.getFlags().isSeen()) {
  +                if (! message.getFlags().contains(Flags.Flag.SEEN)) {
                       count++;
                   }
               }
  @@ -343,7 +344,7 @@
               Iterator iter = mailMessages.values().iterator();
               while (iter.hasNext()) {
                   SimpleImapMessage message = (SimpleImapMessage) iter.next();
  -                if (! message.getFlags().isSeen()) {
  +                if (! message.getFlags().contains(Flags.Flag.SEEN)) {
                       return message.getUid();
                   }
               }
  @@ -379,7 +380,7 @@
           }
   
           public SimpleImapMessage createMessage( MimeMessage message,
  -                                          MessageFlags flags,
  +                                          Flags flags,
                                             Date internalDate )
           {
               long uid = nextUid;
  @@ -419,7 +420,7 @@
           {
               MimeMessage message = mail.getMessage();
               Date internalDate = new Date();
  -            MessageFlags flags = new MessageFlags();
  +            Flags flags = new Flags();
               createMessage( message, flags, internalDate );
           }
   
  @@ -478,8 +479,8 @@
                   // TODO chain.
                   throw new MailboxException( "Messaging exception: " + e.getMessage() );
               }
  -            MessageFlags newFlags = new MessageFlags();
  -            newFlags.setAll( originalMessage.getFlags() );
  +            Flags newFlags = new Flags();
  +            newFlags.add( originalMessage.getFlags() );
               Date newDate = originalMessage.getInternalDate();
   
               toMailbox.createMessage( newMime, newFlags, newDate);
  @@ -491,7 +492,7 @@
               for (int i = 0; i < allUids.length; i++) {
                   long uid = allUids[i];
                   SimpleImapMessage message = getMessage(uid);
  -                if (message.getFlags().isDeleted()) {
  +                if (message.getFlags().contains(Flags.Flag.DELETED)) {
                       expungeMessage(uid);
   
                   }
  @@ -510,13 +511,13 @@
               deleteMessage(uid);
           }
   
  -        public void addExpungeListener(MailboxListener listener) {
  +        public void addListener(MailboxListener listener) {
               synchronized(_mailboxListeners) {
                   _mailboxListeners.add(listener);
               }
           }
   
  -        public void removeExpungeListener(MailboxListener listener) {
  +        public void removeListener(MailboxListener listener) {
               synchronized (_mailboxListeners) {
                   _mailboxListeners.remove(listener);
               }
  
  
  
  1.6       +19 -187   james-server/proposals/imap2/java/org/apache/james/imapserver/store/MessageFlags.java
  
  Index: MessageFlags.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/store/MessageFlags.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MessageFlags.java	8 Mar 2003 21:13:56 -0000	1.5
  +++ MessageFlags.java	13 Jul 2003 12:04:29 -0000	1.6
  @@ -58,10 +58,11 @@
   
   package org.apache.james.imapserver.store;
   
  +import javax.mail.Flags;
  +
   
   /**
    * The set of flags associated with a message.
  - * TODO - should store SEEN flag on a peruser basis (not required, but nice)
    * TODO - why not use javax.mail.Flags instead of having our own.
    *
    * <p>Reference: RFC 2060 - para 2.3
  @@ -70,57 +71,45 @@
    */
   public class MessageFlags
   {
  -
  -    public static final int ANSWERED_INDEX = 0;
  -    public static final int DELETED_INDEX = 1;
  -    public static final int DRAFT_INDEX = 2;
  -    public static final int FLAGGED_INDEX = 3;
  -    public static final int RECENT_INDEX = 4;
  -    public static final int SEEN_INDEX = 5;
  -
  -    // Array does not include seen flag
  -    private boolean[] flags = new boolean[6];
  -
  -
  +    public static final Flags ALL_FLAGS = new Flags();
  +    static {
  +        ALL_FLAGS.add(Flags.Flag.ANSWERED);
  +        ALL_FLAGS.add(Flags.Flag.DELETED);
  +        ALL_FLAGS.add(Flags.Flag.DRAFT);
  +        ALL_FLAGS.add(Flags.Flag.FLAGGED);
  +        ALL_FLAGS.add(Flags.Flag.RECENT);
  +        ALL_FLAGS.add(Flags.Flag.SEEN);
  +    }
  +    
       public static final String ANSWERED = "\\ANSWERED";
       public static final String DELETED = "\\DELETED";
       public static final String DRAFT = "\\DRAFT";
       public static final String FLAGGED = "\\FLAGGED";
       public static final String SEEN = "\\SEEN";
   
  -    public MessageFlags()
  -    {
  -        resetAll();
  -    }
  -
  -    private void resetAll()
  -    {
  -        setAll( false );
  -    }
  -
       /**
        * Returns IMAP formatted String of MessageFlags for named user
        */
  -    public String format()
  +    public static String format(Flags flags)
       {
           StringBuffer buf = new StringBuffer();
           buf.append( "(" );
  -        if ( flags[ANSWERED_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.ANSWERED) ) {
               buf.append( "\\Answered " );
           }
  -        if ( flags[DELETED_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.DELETED) ) {
               buf.append( "\\Deleted " );
           }
  -        if ( flags[DRAFT_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.DRAFT) ) {
               buf.append( "\\Draft " );
           }
  -        if ( flags[FLAGGED_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.FLAGGED) ) {
               buf.append( "\\Flagged " );
           }
  -        if ( flags[RECENT_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.RECENT) ) {
               buf.append( "\\Recent " );
           }
  -        if ( flags[SEEN_INDEX] ) {
  +        if ( flags.contains(Flags.Flag.SEEN) ) {
               buf.append( "\\Seen " );
           }
           // Remove the trailing space, if necessary.
  @@ -130,163 +119,6 @@
           }
           buf.append( ")" );
           return buf.toString();
  -    }
  -
  -    /**
  -     * Sets MessageFlags for message from IMAP-forammted string parameter.
  -     * <BR> The FLAGS<list> form overwrites existing flags, ie sets all other
  -     * flags to false.
  -     * <BR> The +FLAGS<list> form adds the flags in list to the existing flags
  -     * <BR> The -FLAGS<list> form removes the flags in list from the existing
  -     * flags
  -     * <BR> Note that the Recent flag cannot be set by user and is ignored by
  -     * this method.
  -     *
  -     * @param flagString a string formatted according to
  -     * RFC2060 store_att_flags
  -     * @return true if successful, false if not (including uninterpretable
  -     * argument)
  -     */
  -    public boolean setFlags( String flagString )
  -    {
  -        flagString = flagString.toUpperCase();
  -
  -        boolean modValue;
  -
  -        if ( flagString.startsWith( "FLAGS" ) ) {
  -            modValue = true;
  -            resetAll();
  -        }
  -        else if ( flagString.startsWith( "+FLAGS" ) ) {
  -            modValue = true;
  -        }
  -        else if ( flagString.startsWith( "-FLAGS" ) ) {
  -            modValue = false;
  -        }
  -        else {
  -            // Invalid flag string.
  -            return false;
  -        }
  -
  -        if ( flagString.indexOf( ANSWERED ) != -1 ) {
  -            flags[ANSWERED_INDEX] = modValue;
  -        }
  -        if ( flagString.indexOf( DELETED ) != -1 ) {
  -            flags[DELETED_INDEX] = modValue;
  -        }
  -        if ( flagString.indexOf( DRAFT ) != -1 ) {
  -            flags[DRAFT_INDEX] = modValue;
  -        }
  -        if ( flagString.indexOf( FLAGGED ) != -1 ) {
  -            flags[FLAGGED_INDEX] = modValue;
  -        }
  -        if ( flagString.indexOf( SEEN ) != -1 ) {
  -            flags[SEEN_INDEX] = modValue;
  -        }
  -        return true;
  -    }
  -
  -    public void setAnswered( boolean newState )
  -    {
  -        flags[ANSWERED_INDEX] = newState;
  -    }
  -
  -    public boolean isAnswered()
  -    {
  -        return flags[ANSWERED_INDEX];
  -    }
  -
  -    public void setDeleted( boolean newState )
  -    {
  -        flags[DELETED_INDEX] = newState;
  -    }
  -
  -    public boolean isDeleted()
  -    {
  -        return flags[DELETED_INDEX];
  -    }
  -
  -    public void setDraft( boolean newState )
  -    {
  -        flags[DRAFT_INDEX] = newState;
  -    }
  -
  -    public boolean isDraft()
  -    {
  -        return flags[DRAFT_INDEX];
  -    }
  -
  -    public void setFlagged( boolean newState )
  -    {
  -        flags[FLAGGED_INDEX] = newState;
  -    }
  -
  -    public boolean isFlagged()
  -    {
  -        return flags[FLAGGED_INDEX];
  -    }
  -
  -    public void setRecent( boolean newState )
  -    {
  -        flags[RECENT_INDEX] = newState;
  -    }
  -
  -    public boolean isRecent()
  -    {
  -        return flags[RECENT_INDEX];
  -    }
  -
  -    public void setSeen( boolean newState )
  -    {
  -        flags[SEEN_INDEX] = newState;
  -    }
  -
  -    public boolean isSeen()
  -    {
  -        return flags[SEEN_INDEX];
  -    }
  -
  -    public void setAll( boolean newState )
  -    {
  -        for ( int i = ANSWERED_INDEX; i <= SEEN_INDEX; i++ )
  -        {
  -            flags[i] = newState;
  -        }
  -    }
  -
  -    public void setAll( MessageFlags newFlags ) {
  -        setAnswered( newFlags.isAnswered() );
  -        setDeleted( newFlags.isDeleted() );
  -        setDraft( newFlags.isDraft() );
  -        setFlagged( newFlags.isFlagged() );
  -        setSeen( newFlags.isSeen() );
  -    }
  -
  -    public void addAll( MessageFlags toAdd ) {
  -        setFlagState( toAdd, true );
  -    }
  -
  -    public void removeAll (MessageFlags toRemove) {
  -        setFlagState( toRemove, false );
  -    }
  -
  -    private void setFlagState( MessageFlags changes, boolean setState )
  -    {
  -        if ( changes.isAnswered() ) {
  -            setAnswered( setState );
  -        }
  -        if ( changes.isDeleted() ) {
  -            setDeleted( setState );
  -        }
  -        if ( changes.isDraft() ) {
  -            setDraft( setState );
  -        }
  -        if ( changes.isFlagged() ) {
  -            setFlagged( setState );
  -        }
  -        if ( changes.isSeen() ) {
  -            setSeen( setState );
  -        }
       }
   }
   
  
  
  
  1.5       +5 -4      james-server/proposals/imap2/java/org/apache/james/imapserver/store/SimpleImapMessage.java
  
  Index: SimpleImapMessage.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/java/org/apache/james/imapserver/store/SimpleImapMessage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleImapMessage.java	8 Mar 2003 21:13:56 -0000	1.4
  +++ SimpleImapMessage.java	13 Jul 2003 12:04:29 -0000	1.5
  @@ -62,6 +62,7 @@
   
   import javax.mail.internet.MimeMessage;
   import javax.mail.MessagingException;
  +import javax.mail.Flags;
   import java.util.Date;
   
   /**
  @@ -76,12 +77,12 @@
           extends AbstractLogEnabled implements ImapMessage
   {
       private MimeMessage mimeMessage;
  -    private MessageFlags flags;
  +    private Flags flags;
       private Date internalDate;
       private long uid;
       private SimpleMessageAttributes attributes;
   
  -    SimpleImapMessage( MimeMessage mimeMessage, MessageFlags flags,
  +    SimpleImapMessage( MimeMessage mimeMessage, Flags flags,
                    Date internalDate, long uid )
       {
           this.mimeMessage = mimeMessage;
  @@ -94,7 +95,7 @@
           return mimeMessage;
       }
   
  -    public MessageFlags getFlags() {
  +    public Flags getFlags() {
           return flags;
       }
   
  
  
  
  1.5       +14 -18    james-server/proposals/imap2/test/org/apache/james/imapserver/ImapMailboxTest.java
  
  Index: ImapMailboxTest.java
  ===================================================================
  RCS file: /home/cvs/james-server/proposals/imap2/test/org/apache/james/imapserver/ImapMailboxTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ImapMailboxTest.java	8 Mar 2003 21:13:57 -0000	1.4
  +++ ImapMailboxTest.java	13 Jul 2003 12:04:29 -0000	1.5
  @@ -58,25 +58,21 @@
   
   package org.apache.james.imapserver;
   
  +import junit.framework.TestCase;
  +import org.apache.james.core.MimeMessageSource;
  +import org.apache.james.core.MimeMessageWrapper;
  +import org.apache.james.imapserver.store.ImapMailbox;
   import org.apache.james.imapserver.store.ImapStore;
   import org.apache.james.imapserver.store.InMemoryStore;
  -import org.apache.james.imapserver.store.ImapMailbox;
   import org.apache.james.imapserver.store.MailboxException;
  -import org.apache.james.imapserver.store.MessageFlags;
   import org.apache.james.imapserver.store.SimpleImapMessage;
  -import org.apache.james.core.MimeMessageSource;
  -import org.apache.james.core.MimeMessageWrapper;
  -import org.apache.james.core.MailImpl;
  -
  -import junit.framework.TestCase;
   
  +import javax.mail.Flags;
   import javax.mail.internet.MimeMessage;
  -import javax.mail.Address;
  -import java.util.Date;
  -import java.io.InputStream;
  -import java.io.IOException;
   import java.io.ByteArrayInputStream;
  -import java.net.InetAddress;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.util.Date;
   
   /**
    *
  @@ -96,8 +92,8 @@
       {
           ImapMailbox mailbox = getMailbox();
   
  -        MessageFlags flags = new MessageFlags();
  -        flags.setFlagged( true );
  +        Flags flags = new Flags();
  +        flags.add(Flags.Flag.FLAGGED);
   
           Date datetime = new Date();
           String message =
  @@ -116,8 +112,8 @@
           SimpleImapMessage imapMessage = mailbox.getMessage( uid );
   
           assertEquals( 1, mailbox.getMessageCount() );
  -        assertTrue( imapMessage.getFlags().isFlagged() );
  -        assertTrue( ! imapMessage.getFlags().isAnswered() );
  +        assertTrue( imapMessage.getFlags().contains(Flags.Flag.FLAGGED) );
  +        assertTrue( ! imapMessage.getFlags().contains(Flags.Flag.ANSWERED) );
   
           MimeMessage mime = imapMessage.getMimeMessage();
           assertEquals( "TEXT/PLAIN; CHARSET=US-ASCII", mime.getContentType() );
  @@ -127,7 +123,7 @@
   
       }
   
  -    private long appendMessage( String messageContent, MessageFlags flags,
  +    private long appendMessage( String messageContent, Flags flags,
                                   Date datetime, ImapMailbox mailbox )
       {
           MimeMessageSource source =
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message