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 Bernd Fondermann <be...@googlemail.com> on 2006/12/12 12:40:42 UTC

Re: svn commit: r480586 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/services/ java/org/apache/james/smtpserver/core/filter/ java/org/apache/james/transport/mailets/ test/org/apache/james/imapserver/mock/ test/org/

Hi Norman,

does this actually work? if the mail server configuration is changed
from one hostname to the other or the list of domain names is
reordered, doesn't this mean all accounts become invalidated or users
have access to the mail of others?

also, I find expressions like
   if(((ManageableDomainList) domains).addDomain(defaultDomain) != false)
to be very hard to read, especially the "!= false" clause.

Bernd

On 11/29/06, norman@apache.org <no...@apache.org> wrote:
> Author: norman
> Date: Wed Nov 29 06:49:51 2006
> New Revision: 480586
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=480586
> Log:
> Allow to specify a defaultDomain which get added to a recipient if no localpart is given
> Correct the classes to use the right defaultDomain
>
> 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/services/MailServer.java
>     james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
>     james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java
>     james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.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
>
> 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=480586&r1=480585&r2=480586
> ==============================================================================
> --- james/server/trunk/src/conf/james-config.xml (original)
> +++ james/server/trunk/src/conf/james-config.xml Wed Nov 29 06:49:51 2006
> @@ -93,8 +93,14 @@
>        </inboxRepository>
>        -->
>
> -      <!-- Set to true to support virtualHosting -->
> +      <!-- Set to true to support virtualHosting. If virtualHosting support is enabled the server will accept thread every user independ on -->
> +      <!-- domain level. -->
>        <enableVirtualHosting> false </enableVirtualHosting>
> +
> +      <!-- Set the default domain which will be used if an email is send to a recipient without a domain part -->
> +      <!-- If not defaultdomain is set the first domain of the DomainList get used -->
> +      <defaultDomain> localhost </defaultDomain>
> +
>     </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=480586&r1=480585&r2=480586
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/James.java (original)
> +++ james/server/trunk/src/java/org/apache/james/James.java Wed Nov 29 06:49:51 2006
> @@ -75,6 +75,7 @@
>  import java.util.HashSet;
>  import java.util.Hashtable;
>  import java.util.Iterator;
> +import java.util.List;
>  import java.util.Locale;
>  import java.util.Map;
>  import java.util.Vector;
> @@ -175,6 +176,8 @@
>      private DomainList domains;
>
>      private boolean virtualHosting = false;
> +
> +    private String defaultDomain = null;
>
>
>      /**
> @@ -258,6 +261,13 @@
>          }
>
>          getLogger().info("VirtualHosting supported: " + virtualHosting);
> +
> +        Configuration defaultDomainConfig = conf.getChild("defaultDomain");
> +        if (defaultDomainConfig != null ) {
> +            defaultDomain = defaultDomainConfig.getValue(null);
> +        }
> +
> +        getLogger().info("Defaultdomain: " + defaultDomain);
>
>          // Add this to comp
>          compMgr.put( MailServer.ROLE, this);
> @@ -340,12 +350,20 @@
>      }
>
>      private void initializeServernamesAndPostmaster() throws ConfigurationException, ParseException {
> -
> +        String defaultDomain = getDefaultDomain();
> +        if (domains.containsDomain(defaultDomain) == false) {
> +            if (domains instanceof ManageableDomainList) {
> +                if(((ManageableDomainList) domains).addDomain(defaultDomain) != false) {
> +                    throw new ConfigurationException("Configured defaultdomain could not get added to DomainList");
> +                }
> +            } else {
> +                throw new ConfigurationException("Configured defaultDomain not exist in DomainList");
> +            }
> +        }
>          serverNames = domains.getDomains();
>
>          if (serverNames == null || serverNames.size() == 0) throw new ConfigurationException("No domainnames configured");
>
> -        String defaultDomain = (String) serverNames.iterator().next();
>          // used by RemoteDelivery for HELO
>          attributes.put(Constants.DEFAULT_DOMAIN, defaultDomain);
>
> @@ -914,5 +932,21 @@
>       */
>      public boolean supportVirtualHosting() {
>          return virtualHosting;
> +    }
> +
> +    /**
> +     * @see org.apache.james.services.MailServer#getDefaultDomain()
> +     */
> +    public String getDefaultDomain() {
> +        if (defaultDomain == null) {
> +            List domainList = domains.getDomains();
> +            if (domainList == null || domainList.isEmpty()) {
> +                return "localhost";
> +            } else {
> +                return (String) domainList.get(0);
> +            }
> +        } else {
> +            return defaultDomain;
> +        }
>      }
>  }
>
> 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=480586&r1=480585&r2=480586
> ==============================================================================
> --- 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 06:49:51 2006
> @@ -143,4 +143,12 @@
>       * @return true or false
>       */
>      boolean supportVirtualHosting();
> +
> +    /**
> +     * Return the default domain which will get used to deliver mail to if only the localpart
> +     * was given on rcpt to.
> +     *
> +     * @return the defaultdomain
> +     */
> +    String getDefaultDomain();
>  }
>
> Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java?view=diff&rev=480586&r1=480585&r2=480586
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java (original)
> +++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java Wed Nov 29 06:49:51 2006
> @@ -159,7 +159,7 @@
>              } else {
>
>                  if (sender.indexOf("@") < 0) {
> -                    sender = sender + "@localhost";
> +                    sender = sender + "@" + session.getConfigurationData().getMailServer().getDefaultDomain();
>                  }
>
>                  try {
>
> Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java?view=diff&rev=480586&r1=480585&r2=480586
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java (original)
> +++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java Wed Nov 29 06:49:51 2006
> @@ -118,7 +118,8 @@
>              }
>
>              if (recipient.indexOf("@") < 0) {
> -                recipient = recipient + "@localhost";
> +                // set the default domain
> +                recipient = recipient + "@" + session.getConfigurationData().getMailServer().getDefaultDomain();
>              }
>
>              try {
>
> Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
> URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java?view=diff&rev=480586&r1=480585&r2=480586
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java (original)
> +++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java Wed Nov 29 06:49:51 2006
> @@ -107,7 +107,7 @@
>                          }
>
>                          try {
> -                            MailAddress target = (targetAddress.indexOf('@') < 0) ? new MailAddress(targetAddress, "localhost")
> +                            MailAddress target = (targetAddress.indexOf('@') < 0) ? new MailAddress(targetAddress, (String) getMailetContext().getAttribute(Constants.DEFAULT_DOMAIN))
>                                  : new MailAddress(targetAddress);
>
>                              //Mark this source address as an address to remove from the recipient list
>
> 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=480586&r1=480585&r2=480586
> ==============================================================================
> --- 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 06:49:51 2006
> @@ -65,4 +65,8 @@
>          return false;
>      }
>
> +    public String getDefaultDomain() {
> +        return "localhost";
> +    }
> +
>  }
>
> 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=480586&r1=480585&r2=480586
> ==============================================================================
> --- 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 06:49:51 2006
> @@ -195,6 +195,10 @@
>      public boolean supportVirtualHosting() {
>          return virtualHosting;
>      }
> +
> +    public String getDefaultDomain() {
> +        return "localhost";
> +    }
>  }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>

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