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 da...@apache.org on 2002/11/27 04:24:20 UTC
cvs commit: jakarta-james/proposals/imap2/test/org/apache/james/imapserver Subscribe.test Subscribe2.test TestAuthenticated.java
darrell 2002/11/26 19:24:20
Modified: proposals/imap2/java/org/apache/james/imapserver
ImapHost.java JamesImapHost.java
proposals/imap2/java/org/apache/james/imapserver/commands
ImapCommandFactory.java LsubCommand.java
proposals/imap2/test/org/apache/james/imapserver
Subscribe.test Subscribe2.test
TestAuthenticated.java
Added: proposals/imap2/java/org/apache/james/imapserver/commands
SubscribeCommand.java UnsubscribeCommand.java
Log:
Imap Proposal:
* implemented SUBSCRIBE and UNSUBSCRIBE
Revision Changes Path
1.2 +3 -3 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/ImapHost.java
Index: ImapHost.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/ImapHost.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ImapHost.java 22 Nov 2002 02:09:50 -0000 1.1
+++ ImapHost.java 27 Nov 2002 03:24:19 -0000 1.2
@@ -238,10 +238,10 @@
/**
* Unsubscribes from a given mailbox.
*
- * @param username String representation of an email address
+ * @param user String representation of an email address
* @param mailbox String representation of a mailbox name.
*/
- void unsubscribe( String username, String mailbox )
+ void unsubscribe( User user, String mailbox )
throws MailboxException;
}
1.3 +81 -13 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/JamesImapHost.java
Index: JamesImapHost.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/JamesImapHost.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JamesImapHost.java 26 Nov 2002 14:53:47 -0000 1.2
+++ JamesImapHost.java 27 Nov 2002 03:24:19 -0000 1.3
@@ -17,6 +17,8 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.StringTokenizer;
+import java.util.Map;
+import java.util.HashMap;
/**
* An initial implementation of an ImapHost. By default, uses,
@@ -31,15 +33,18 @@
implements ImapHost, ImapConstants
{
private ImapStore store;
+ private MailboxSubscriptions subscriptions;
public JamesImapHost()
{
store = new InMemoryStore();
+ subscriptions = new MailboxSubscriptions();
}
public JamesImapHost( ImapStore store )
{
this.store = store;
+ subscriptions = new MailboxSubscriptions();
}
public char getHierarchyDelimiter()
@@ -170,14 +175,15 @@
store.renameMailbox( existingMailbox, newMailboxName );
}
+ /** @see ImapHost#listSubscribedMailboxes */
public Collection listSubscribedMailboxes( User user,
String mailboxPattern )
throws MailboxException
{
- throw new MailboxException( "Subscriptions not implemented" );
-// return listMailboxes( user, mailboxPattern, true );
+ return listMailboxes( user, mailboxPattern, true );
}
+ /** @see ImapHost#listMailboxes */
public Collection listMailboxes( User user,
String mailboxPattern )
throws MailboxException
@@ -187,7 +193,6 @@
/**
* Partial implementation of list functionality.
- * TODO: Handle subscriptions (currently ignored)
* TODO: Handle wildcards anywhere in mailbox pattern
* (currently only supported as last character of pattern)
* @see org.apache.james.imapserver.ImapHost#listMailboxes
@@ -207,15 +212,17 @@
while ( iter.hasNext() ) {
ImapMailbox mailbox = ( ImapMailbox ) iter.next();
- // Sets the mailbox to null if it's not viewable.
- mailbox = checkViewable( mailbox );
-
// TODO check subscriptions.
if ( subscribedOnly ) {
- // if not subscribed
- mailbox = null;
+ if ( ! subscriptions.isSubscribed( user, mailbox ) ) {
+ // if not subscribed
+ mailbox = null;
+ }
}
+ // Sets the mailbox to null if it's not viewable.
+ mailbox = checkViewable( mailbox );
+
if ( mailbox != null ) {
mailboxes.add( mailbox );
}
@@ -224,16 +231,20 @@
return mailboxes;
}
- public void subscribe( User user, String mailbox )
+ /** @see ImapHost#subscribe */
+ public void subscribe( User user, String mailboxName )
throws MailboxException
{
- // TODO implement
+ ImapMailbox mailbox = getMailbox( user, mailboxName, true );
+ subscriptions.subscribe( user, mailbox );
}
- public void unsubscribe( String username, String mailbox )
+ /** @see ImapHost#unsubscribe */
+ public void unsubscribe( User user, String mailboxName )
throws MailboxException
{
- // TODO implement
+ ImapMailbox mailbox = getMailbox( user, mailboxName, true );
+ subscriptions.unsubscribe( user, mailbox );
}
/**
@@ -267,6 +278,63 @@
return USER_NAMESPACE + HIERARCHY_DELIMITER + userName +
HIERARCHY_DELIMITER + mailboxName;
}
+ }
+ }
+
+ /**
+ * Handles all user subscriptions.
+ * TODO make this a proper class
+ * TODO persist
+ */
+ private class MailboxSubscriptions
+ {
+ private Map userSubs = new HashMap();
+
+ /**
+ * Subscribes the user to the mailbox.
+ * TODO should this fail if already subscribed?
+ * @param user The user making the subscription
+ * @param mailbox The mailbox to subscribe
+ * @throws MailboxException ??? doesn't yet.
+ */
+ void subscribe( User user, ImapMailbox mailbox )
+ throws MailboxException
+ {
+ getUserSubs( user ).add( mailbox.getFullName() );
+ }
+
+ /**
+ * Unsubscribes the user from this mailbox.
+ * TODO should this fail if not already subscribed?
+ * @param user The user making the request.
+ * @param mailbox The mailbox to unsubscribe
+ * @throws MailboxException ?? doesn't yet
+ */
+ void unsubscribe( User user, ImapMailbox mailbox )
+ throws MailboxException
+ {
+ getUserSubs( user ).remove( mailbox.getFullName() );
+ }
+
+ /**
+ * Returns whether the user is subscribed to the specified mailbox.
+ * @param user The user to test.
+ * @param mailbox The mailbox to test.
+ * @return <code>true</code> if the user is subscribed.
+ */
+ boolean isSubscribed( User user, ImapMailbox mailbox )
+ {
+ return getUserSubs( user ).contains( mailbox.getFullName() );
+ }
+
+ private Collection getUserSubs( User user )
+ {
+ Collection subs = (Collection)userSubs.get( user.getUserName() );
+ if ( subs == null ) {
+ subs = new ArrayList();
+ userSubs.put( user.getUserName(), subs );
+ }
+ return subs;
}
}
1.3 +4 -3 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/ImapCommandFactory.java
Index: ImapCommandFactory.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/ImapCommandFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImapCommandFactory.java 26 Nov 2002 14:53:48 -0000 1.2
+++ ImapCommandFactory.java 27 Nov 2002 03:24:20 -0000 1.3
@@ -49,12 +49,13 @@
_imapCommands.put( CreateCommand.NAME, CreateCommand.class );
_imapCommands.put( DeleteCommand.NAME, DeleteCommand.class );
_imapCommands.put( RenameCommand.NAME, RenameCommand.class );
-// _imapCommands.put( "SUBSCRIBE", SubscribeCommand.class );
-// _imapCommands.put( "UNSUBSCRIBE", UnsubscribeCommand.class );
+ _imapCommands.put( SubscribeCommand.NAME, SubscribeCommand.class );
+ _imapCommands.put( UnsubscribeCommand.NAME, UnsubscribeCommand.class );
_imapCommands.put( ListCommand.NAME, ListCommand.class );
_imapCommands.put( LsubCommand.NAME, LsubCommand.class );
_imapCommands.put( StatusCommand.NAME, StatusCommand.class );
// _imapCommands.put( "APPEND", AppendCommand.class );
+
// // RFC2342 NAMESPACE
// _imapCommands.put( "NAMESPACE", NamespaceCommand.class );
// // RFC2086 GETACL, SETACL, DELETEACL, LISTRIGHTS, MYRIGHTS
1.2 +2 -2 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/LsubCommand.java
Index: LsubCommand.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/LsubCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LsubCommand.java 22 Nov 2002 02:09:51 -0000 1.1
+++ LsubCommand.java 27 Nov 2002 03:24:20 -0000 1.2
@@ -18,7 +18,7 @@
*
* @version $Revision$
*/
-public class LsubCommand extends ListCommand
+class LsubCommand extends ListCommand
{
public static final String NAME = "LSUB";
1.1 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/SubscribeCommand.java
Index: SubscribeCommand.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.imapserver.commands;
import org.apache.james.imapserver.ImapRequestLineReader;
import org.apache.james.imapserver.ImapResponse;
import org.apache.james.imapserver.ImapSession;
import org.apache.james.imapserver.ProtocolException;
import org.apache.james.imapserver.store.ImapMailbox;
import org.apache.james.imapserver.store.MailboxException;
/**
* Handles processeing for the SUBSCRIBE imap command.
*
* @author Darrell DeBoer <da...@apache.org>
*
* @version $Revision: 1.1 $
*/
class SubscribeCommand extends CommandTemplate
{
public static final String NAME = "SUBSCRIBE";
public static final String ARGS = "<mailbox>";
/** @see CommandTemplate#doProcess */
protected void doProcess( ImapRequestLineReader request,
ImapResponse response,
ImapSession session )
throws ProtocolException, MailboxException
{
String mailboxName = parser.mailbox( request );
parser.endLine( request );
session.getHost().subscribe( session.getUser(), mailboxName );
session.unsolicitedResponses( response );
response.commandComplete( this );
}
/** @see ImapCommand#getName */
public String getName()
{
return NAME;
}
/** @see CommandTemplate#getArgSyntax */
public String getArgSyntax()
{
return ARGS;
}
}
/*
6.1.2. NOOP Command
Arguments: none
Responses: no specific responses for this command (but see below)
Result: OK - noop completed
BAD - command unknown or arguments invalid
The NOOP command always succeeds. It does nothing.
Since any command can return a status update as untagged data, the
NOOP command can be used as a periodic poll for new messages or
message status updates during a period of inactivity. The NOOP
command can also be used to reset any inactivity autologout timer
on the server.
Example: C: a002 NOOP
S: a002 OK NOOP completed
. . .
C: a047 NOOP
S: * 22 EXPUNGE
S: * 23 EXISTS
S: * 3 RECENT
S: * 14 FETCH (FLAGS (\Seen \Deleted))
S: a047 OK NOOP completed
*/
1.1 jakarta-james/proposals/imap2/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java
Index: UnsubscribeCommand.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.imapserver.commands;
import org.apache.james.imapserver.ImapRequestLineReader;
import org.apache.james.imapserver.ImapResponse;
import org.apache.james.imapserver.ImapSession;
import org.apache.james.imapserver.ProtocolException;
import org.apache.james.imapserver.store.ImapMailbox;
import org.apache.james.imapserver.store.MailboxException;
/**
* Handles processeing for the UNSUBSCRIBE imap command.
*
* @author Darrell DeBoer <da...@apache.org>
*
* @version $Revision: 1.1 $
*/
class UnsubscribeCommand extends CommandTemplate
{
public static final String NAME = "UNSUBSCRIBE";
public static final String ARGS = "<mailbox>";
/** @see CommandTemplate#doProcess */
protected void doProcess( ImapRequestLineReader request,
ImapResponse response,
ImapSession session )
throws ProtocolException, MailboxException
{
String mailboxName = parser.mailbox( request );
parser.endLine( request );
session.getHost().unsubscribe( session.getUser(), mailboxName );
session.unsolicitedResponses( response );
response.commandComplete( this );
}
/** @see ImapCommand#getName */
public String getName()
{
return NAME;
}
/** @see CommandTemplate#getArgSyntax */
public String getArgSyntax()
{
return ARGS;
}
}
/*
6.1.2. NOOP Command
Arguments: none
Responses: no specific responses for this command (but see below)
Result: OK - noop completed
BAD - command unknown or arguments invalid
The NOOP command always succeeds. It does nothing.
Since any command can return a status update as untagged data, the
NOOP command can be used as a periodic poll for new messages or
message status updates during a period of inactivity. The NOOP
command can also be used to reset any inactivity autologout timer
on the server.
Example: C: a002 NOOP
S: a002 OK NOOP completed
. . .
C: a047 NOOP
S: * 22 EXPUNGE
S: * 23 EXISTS
S: * 3 RECENT
S: * 14 FETCH (FLAGS (\Seen \Deleted))
S: a047 OK NOOP completed
*/
1.2 +15 -23 jakarta-james/proposals/imap2/test/org/apache/james/imapserver/Subscribe.test
Index: Subscribe.test
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/imapserver/Subscribe.test,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Subscribe.test 22 Nov 2002 02:09:52 -0000 1.1
+++ Subscribe.test 27 Nov 2002 03:24:20 -0000 1.2
@@ -5,7 +5,7 @@
S: a01 OK SUBSCRIBE completed
C: a01 LSUB "" "*"
-S: * LSUB (\Unmarked) "." test
+S: \* LSUB \(\) \"\.\" test
S: a01 OK LSUB completed
C: a01 SUBSCRIBE test.subfolder
@@ -14,48 +14,40 @@
C: a01 SUBSCRIBE test1.subfolder1
S: a01 OK SUBSCRIBE completed
+# LIST All subscribed
C: a01 LSUB "" "*"
-SUB: 1
-S: * LSUB (\Unmarked) "." test
-S: * LSUB (\Unmarked) "." test.subfolder
-S: * LSUB (\Unmarked) "." test1.subfolder1
-SUB: 1
+SUB {
+S: \* LSUB \(\) \"\.\" test
+S: \* LSUB \(\) \"\.\" test\.subfolder
+S: \* LSUB \(\) \"\.\" test1\.subfolder1
+}
S: a01 OK LSUB completed
-// LIST All subscribed
-C: a01 LSUB "" "*"
-SUB: 1
-S: * LSUB (\Unmarked) "." test
-S: * LSUB (\Unmarked) "." test.subfolder
-S: * LSUB (\Unmarked) "." test1.subfolder1
-SUB: 1
-S: a01 OK LSUB completed
-
-// LIST A subset of subscribed
+# LIST A subset of subscribed
C: a01 LSUB "test" "sub*"
-S: * LSUB (\Unmarked) "." test.subfolder
+S: \* LSUB \(\) \"\.\" test\.subfolder
S: a01 OK LSUB completed
-// Unsubscribe from a parent mailbox, make sure that test.subfolder is still subscribed.
+# Unsubscribe from a parent mailbox, make sure that test.subfolder is still subscribed.
C: a01 UNSUBSCRIBE test
S: a01 OK UNSUBSCRIBE completed
C: a01 LSUB "test" "sub*"
-S: * LSUB (\Unmarked) "." test.subfolder
+S: \* LSUB \(\) \"\.\" test\.subfolder
S: a01 OK LSUB completed
-// Attempt to unsubscribe from a mailbox that isn't subscribed
+# Attempt to unsubscribe from a mailbox that isn't subscribed
C: a01 UNSUBSCRIBE test1
S: a01 OK UNSUBSCRIBE completed
C: a01 UNSUBSCRIBE test.subfolder
S: a01 OK UNSUBSCRIBE completed
-// Leave test1.subfolder1 subscribed for next test
-// LIST All subscribed
+# Leave test1.subfolder1 subscribed for next test
+# LIST All subscribed
C: a01 LSUB "" "*"
-S: * LSUB (\Unmarked) "." test1.subfolder1
+S: \* LSUB \(\) \"\.\" test1\.subfolder1
S: a01 OK LSUB completed
1.2 +3 -3 jakarta-james/proposals/imap2/test/org/apache/james/imapserver/Subscribe2.test
Index: Subscribe2.test
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/imapserver/Subscribe2.test,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Subscribe2.test 22 Nov 2002 02:09:52 -0000 1.1
+++ Subscribe2.test 27 Nov 2002 03:24:20 -0000 1.2
@@ -1,7 +1,7 @@
-// Make sure subscriptions are carried into new login sessions.
-// Subscribed to "test1.subfolder1" after test file Subscribe.test
+# Make sure subscriptions are carried into new login sessions.
+# Subscribed to "test1.subfolder1" after test file Subscribe.test
C: a01 LSUB "" "*"
-S: * LSUB (\Unmarked) "." test1.subfolder1
+S: \* LSUB \(\) \"\.\" test1\.subfolder1
S: a01 OK LSUB completed
C: a01 UNSUBSCRIBE test1.subfolder1
1.5 +2 -0 jakarta-james/proposals/imap2/test/org/apache/james/imapserver/TestAuthenticated.java
Index: TestAuthenticated.java
===================================================================
RCS file: /home/cvs/jakarta-james/proposals/imap2/test/org/apache/james/imapserver/TestAuthenticated.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestAuthenticated.java 27 Nov 2002 02:24:10 -0000 1.4
+++ TestAuthenticated.java 27 Nov 2002 03:24:20 -0000 1.5
@@ -61,6 +61,8 @@
suite.addTest( new TestAuthenticated( "ListMailboxes" ) );
suite.addTest( new TestAuthenticated( "Status" ) );
suite.addTest( new TestAuthenticated( "StringArgs" ) );
+ suite.addTest( new TestAuthenticated( "Subscribe" ) );
+ suite.addTest( new TestAuthenticated( "Subscribe2" ) );
// Run delete last, because many of the tests depend on created mailboxes.
suite.addTest( new TestAuthenticated( "Delete" ) );
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>