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 no...@apache.org on 2006/11/29 12:54:48 UTC
svn commit: r480543 - in /james/server/trunk/src: conf/
java/org/apache/james/ java/org/apache/james/remotemanager/
java/org/apache/james/services/ java/org/apache/james/transport/mailets/
test/org/apache/james/imapserver/mock/ test/org/apache/james/te...
Author: norman
Date: Wed Nov 29 03:54:46 2006
New Revision: 480543
URL: http://svn.apache.org/viewvc?view=rev&rev=480543
Log:
Add support for virtualhosting. See JAMES-716
Modified:
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/James.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
james/server/trunk/src/java/org/apache/james/services/MailServer.java
james/server/trunk/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
james/server/trunk/src/test/org/apache/james/imapserver/mock/MockMailServer.java
james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Wed Nov 29 03:54:46 2006
@@ -92,6 +92,9 @@
<repository destinationURL="mailboxmanager://users/" type="MAIL" />
</inboxRepository>
-->
+
+ <!-- Set to true to support virtualHosting -->
+ <enableVirtualHosting> false </enableVirtualHosting>
</James>
<!-- Experimental IMAP support -->
Modified: james/server/trunk/src/java/org/apache/james/James.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/James.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/java/org/apache/james/James.java (original)
+++ james/server/trunk/src/java/org/apache/james/James.java Wed Nov 29 03:54:46 2006
@@ -173,6 +173,9 @@
private FileSystem fileSystem;
private DomainList domains;
+
+ private boolean virtualHosting = false;
+
/**
* @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
@@ -248,6 +251,13 @@
inboxRootURL = conf.getChild("inboxRepository").getChild("repository").getAttribute("destinationURL");
getLogger().info("Private Repository LocalInbox opened");
+
+ Configuration virtualHostingConfig = conf.getChild("enableVirtualHosting");
+ if (virtualHostingConfig != null ) {
+ virtualHosting = virtualHostingConfig.getValueAsBoolean(false);
+ }
+
+ getLogger().info("VirtualHosting supported: " + virtualHosting);
// Add this to comp
compMgr.put( MailServer.ROLE, this);
@@ -501,6 +511,10 @@
*/
public synchronized MailRepository getUserInbox(String userName) {
MailRepository userInbox = null;
+
+ if (virtualHosting == false && (userName.indexOf("@") < 0) == false) {
+ userName = userName.split("@")[0];
+ }
userInbox = (MailRepository) mailboxes.get(userName);
@@ -520,11 +534,18 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Retrieving and caching inbox for " + userName );
}
- StringBuffer destinationBuffer =
- new StringBuffer(192)
- .append(inboxRootURL)
- .append(userName)
- .append("/");
+
+ StringBuffer destinationBuffer = new StringBuffer(192);
+
+ if (virtualHosting == true && inboxRootURL.startsWith("file://") && !(userName.indexOf("@") < 0)) {
+ String userArgs[] = userName.split("@");
+
+ // build the url like : file://var/mail/inboxes/domain/username/
+ destinationBuffer.append(inboxRootURL).append(userArgs[1]).append("/").append(userArgs[0]).append("/");
+ } else {
+ destinationBuffer.append(inboxRootURL).append(userName).append("/");
+ }
+
String destination = destinationBuffer.toString();
try {
// Copy the inboxRepository configuration and modify the destinationURL
@@ -733,10 +754,14 @@
* @see org.apache.mailet.MailetContext#isLocalEmail(org.apache.mailet.MailAddress)
*/
public boolean isLocalEmail(MailAddress mailAddress) {
+ String userName = mailAddress.toString();
if (!isLocalServer(mailAddress.getHost())) {
return false;
}
- return localusers.contains(mailAddress.getUser());
+ if (virtualHosting == false) {
+ userName = mailAddress.getUser();
+ }
+ return localusers.contains(userName);
}
/**
@@ -882,5 +907,12 @@
MailImpl m = new MailImpl(getId(),sender,recipients,msg);
localDeliveryMailet.service(m);
ContainerUtil.dispose(m);
+ }
+
+ /**
+ * @see org.apache.james.services.MailServer#supportVirtualHosting()
+ */
+ public boolean supportVirtualHosting() {
+ return virtualHosting;
}
}
Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java Wed Nov 29 03:54:46 2006
@@ -320,6 +320,19 @@
String response = responseBuffer.toString();
writeLoggedResponse(response);
} else {
+ if((username.indexOf("@") < 0) == false) {
+ if(theConfigData.getMailServer().supportVirtualHosting() == false) {
+ out.println("Virtualhosting not supported");
+ out.flush();
+ return true;
+ }
+ String domain = username.split("@")[1];
+ if (theConfigData.getDomainListManagement().containsDomain(domain) == false) {
+ out.println("Domain not exists: " + domain);
+ out.flush();
+ return true;
+ }
+ }
success = users.addUser(username, passwd);
}
if ( success ) {
@@ -439,12 +452,28 @@
* @param argument the argument passed in with the command
*/
private boolean doLISTUSERS(String argument) {
- writeLoggedResponse("Existing accounts " + users.countUsers());
- for (Iterator it = users.list(); it.hasNext();) {
- writeLoggedResponse("user: " + (String) it.next());
+ if (argument == null) {
+ writeLoggedResponse("Existing accounts " + users.countUsers());
+ for (Iterator it = users.list(); it.hasNext();) {
+ writeLoggedResponse("user: " + (String) it.next());
+ }
+ out.flush();
+ return true;
+ } else {
+ if(theConfigData.getMailServer().supportVirtualHosting() == false) {
+ out.println("Virtualhosting not supported");
+ out.flush();
+ return true;
+ }
+
+ ArrayList userList = getDomainUserList(argument);
+ writeLoggedResponse("Existing accounts from domain " + argument + " " + userList.size());
+ for (int i = 0; i <userList.size(); i++) {
+ writeLoggedResponse("user: " + userList.get(i));
+ }
+ out.flush();
+ return true;
}
- out.flush();
- return true;
}
/**
@@ -454,8 +483,19 @@
* @param argument the argument passed in with the command
*/
private boolean doCOUNTUSERS(String argument) {
- writeLoggedFlushedResponse("Existing accounts " + users.countUsers());
- return true;
+ if (argument == null) {
+ writeLoggedFlushedResponse("Existing accounts " + users.countUsers());
+ return true;
+ } else {
+ if(theConfigData.getMailServer().supportVirtualHosting() == false) {
+ out.println("Virtualhosting not supported");
+ out.flush();
+ return true;
+ }
+
+ writeLoggedFlushedResponse("Existing accounts for domain " + argument + " " + getDomainUserList(argument).size());
+ return true;
+ }
}
/**
@@ -1685,5 +1725,24 @@
out.flush();
}
return true;
+ }
+
+ /**
+ * Return an ArrayList which contains all usernames for the given domain
+ *
+ * @param domain the domain
+ * @return ArrayList which contains the users
+ */
+ private ArrayList getDomainUserList(String domain) {
+ ArrayList userList = new ArrayList();
+
+ for (Iterator it = users.list(); it.hasNext();) {
+ String user = (String) it.next();
+ if (user.endsWith(domain)) {
+ userList.add(user);
+ }
+ }
+
+ return userList;
}
}
Modified: james/server/trunk/src/java/org/apache/james/services/MailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/MailServer.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/MailServer.java (original)
+++ james/server/trunk/src/java/org/apache/james/services/MailServer.java Wed Nov 29 03:54:46 2006
@@ -136,4 +136,11 @@
* @return true if server is local, i.e. serviced by this mail context
*/
boolean isLocalServer(String serverName);
+
+ /**
+ * Return true if virtualHosting support is enabled, otherwise false
+ *
+ * @return true or false
+ */
+ boolean supportVirtualHosting();
}
Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/ToMultiRepository.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/ToMultiRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/ToMultiRepository.java Wed Nov 29 03:54:46 2006
@@ -214,7 +214,7 @@
throw new IllegalArgumentException(
"Mail message to be spooled cannot be null.");
}
- username = recipient.getUser();
+ username = recipient.toString();
Collection recipients = new HashSet();
recipients.add(recipient);
Modified: james/server/trunk/src/test/org/apache/james/imapserver/mock/MockMailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/mock/MockMailServer.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/mock/MockMailServer.java (original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/mock/MockMailServer.java Wed Nov 29 03:54:46 2006
@@ -60,5 +60,9 @@
{
throw new RuntimeException("not implemented");
}
+
+ public boolean supportVirtualHosting() {
+ return false;
+ }
}
Modified: james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java (original)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java Wed Nov 29 03:54:46 2006
@@ -55,6 +55,9 @@
private HashMap inboxes;
+ private boolean virtualHosting;
+
+
public MockUsersRepository getUsersRepository() {
return m_users;
}
@@ -111,6 +114,7 @@
if (inboxes==null) {
return null;
} else {
+ if ((userName.indexOf("@") < 0) == false && supportVirtualHosting() == false) userName = userName.split("@")[0];
return (MailRepository) inboxes.get(userName);
}
@@ -182,6 +186,14 @@
public MailRepository getSentMailsRepository() {
return mails;
+ }
+
+ public void setVirtualHosting(boolean virtualHosting) {
+ this.virtualHosting = virtualHosting;
+ }
+
+ public boolean supportVirtualHosting() {
+ return virtualHosting;
}
}
Modified: james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java?view=diff&rev=480543&r1=480542&r2=480543
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java Wed Nov 29 03:54:46 2006
@@ -221,6 +221,20 @@
assertDeliveryWorked(mail, expectedMails);
}
*/
+
+ public void testSimpleDeliveryVirtualHosting() throws MessagingException {
+ //enable virtual hosting
+ mockMailServer.setVirtualHosting(true);
+ Mailet m = getMailet(null);
+
+ Mail mail = createMail(new String[] {"virtual@hosting"});
+ m.service(mail);
+
+ HashMap expectedMails = new HashMap();
+ expectedMails.put("virtual@hosting", new String[] {"virtual@hosting"});
+
+ assertDeliveryWorked(mail, expectedMails);
+ }
/**
* @throws ParseException
@@ -232,6 +246,10 @@
mockUsersRepository.setForceUseJamesUser();
mockUsersRepository.addUser("localuser", "password");
mockUsersRepository.addUser("aliasedUser", "pass2");
+
+ // VirtualHosting
+ mockUsersRepository.addUser("virtual@hosting","pass");
+
DefaultJamesUser u = (DefaultJamesUser) mockUsersRepository.getUserByName("aliasedUser");
u.setAliasing(true);
u.setAlias("localuser");
@@ -254,6 +272,7 @@
mailboxes = new HashMap();
mailboxes.put("localuser", new InMemorySpoolRepository());
mailboxes.put("aliasedUser", new InMemorySpoolRepository());
+ mailboxes.put("virtual@hosting",new InMemorySpoolRepository());
Iterator mbi = mailboxes.keySet().iterator();
while (mbi.hasNext()) {
String mboxName = (String) mbi.next();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org