Skip to content

Commit

Permalink
JAMES-1618 Capabilities should be advertised upon TCP connection
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1720591 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
chibenwa committed Dec 17, 2015
1 parent 9f59436 commit b058f9a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package org.apache.james.managesieve.api;

public interface CapabilityAdvertiser {

String getAdvertisedCapabilities();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

package org.apache.james.managesieve.api.commands;

import org.apache.james.managesieve.api.CapabilityAdvertiser;

/**
* Core RFC 5804 Commands common to all transports
*
* @see <a href=http://tools.ietf.org/html/rfc5804#section-2>RFC 5804 Commands</a>
*/
public interface CoreCommands extends Capability, CheckScript, DeleteScript, GetScript, HaveSpace,
ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop, Unauthenticate, Logout, Authenticate, StartTLS {
ListScripts, PutScript, RenameScript, SetActive, GetActive, Noop, Unauthenticate, Logout, Authenticate, StartTLS,
CapabilityAdvertiser {

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,23 @@ public CoreProcessor(SieveRepository repository, UsersRepository usersRepository
this.authenticationProcessorMap.put(SupportedMechanism.PLAIN, new PlainAuthenticationProcessor(usersRepository));
}

@Override
public String getAdvertisedCapabilities() {
return convertCapabilityMapToString(capabilitiesBase) + "\r\n";
}

@Override
public String capability(Session session) {
return convertCapabilityMapToString(computeCapabilityMap(session)) + "\r\nOK";
}

private String convertCapabilityMapToString(Map<Capabilities, String> capabilitiesStringMap) {
return Joiner.on("\r\n").join(
Iterables.transform(computeCapabilityMap(session).entrySet(), new Function<Map.Entry<Capabilities,String>, String>() {
Iterables.transform(capabilitiesStringMap.entrySet(), new Function<Map.Entry<Capabilities,String>, String>() {
public String apply(Map.Entry<Capabilities, String> capabilitiesStringEntry) {
return computeCapabilityEntryString(capabilitiesStringEntry);
}
})) + "\r\nOK";
}));
}

private Map<Capabilities, String> computeCapabilityMap(Session session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public class ArgumentParser {
public ArgumentParser(CoreCommands core) {
this.core = core;
}


public String getAdvertisedCapabilities() {
return core.getAdvertisedCapabilities();
}

public String capability(Session session, String args) {
if (!args.trim().isEmpty()) {
return "NO \"Too many arguments: " + args + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ private String matchCommandWithImplementation(Session session, String arguments,
return "NO unknown " + command + " command";
}

public String getAdvertisedCapabilities() {
return argumentParser.getAdvertisedCapabilities();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) thr
attributes.set(ctx.getChannel(), session);
ctx.setAttachment(new ChannelManageSieveResponseWriter(ctx.getChannel()));
super.channelBound(ctx, e);
((ChannelManageSieveResponseWriter)ctx.getAttachment()).write(manageSieveProcessor.getAdvertisedCapabilities());
}

@Override
Expand Down

0 comments on commit b058f9a

Please sign in to comment.