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 Marinus van Zyl <ma...@communitysms.com> on 2004/09/19 19:33:08 UTC

Different Inbox Accounts for the same email name but different domains on One James email server

Hi, this is my first time posting, hope it goes through!

I'm running a Java application integrated with James, with maillets and Jetty, and host different domains on one box, including the email server for different Small to Medium Enterprises.

My main problem with James was when 2 different clients wanted the same user name, e.g. 'marketing' or 'admin', but for their own domain names. James can normally not do this.

I've tried creating a user with the full email address as the username, e.g. admin@communitysms.com instead of admin.
This works everywhere except in one place, which is when the received email is stored. There it always takes the first bit of the recipient address (admin), and stores it in that user's inbox.

So, the following change to the storeMail function of the org.apache.james.James class, changes that. It looks to see if the full recipient address is in fact a user name. If it is, it keeps the full recipient name as the user name when storing, otherwise it takes only the first bit (which is the default behavior), so it is compatible with other james systems.

So, 
 . . . . . .
           originalUsername = recipient.getUser();

 . . . . . .
is replaced by 
 . . . . . .
           if(localusers.containsCaseInsensitive(recipient.toString()))
           {
               originalUsername = recipient.toString();
           }
           else
           {
               originalUsername = recipient.getUser();
           } 

 . . . . . .
and
 . . . . . .
         username = recipient.getUser();

 . . . . . .
is replaced by 
 . . . . . .
           if(localusers.containsCaseInsensitive(recipient.toString()))
           {
               username = recipient.toString();
           }
           else
           {
               username = recipient.getUser();
           } 

 . . . . . .
Here follows the full function code:

 . . . . . .

    public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage message)
        throws MessagingException {
        String username;
        if (recipient == null) {
            throw new IllegalArgumentException("Recipient for mail to be spooled cannot be null.");
        }
        if (message == null) {
            throw new IllegalArgumentException("Mail message to be spooled cannot be null.");
        }
        if (ignoreCase) {
           String originalUsername = null;
           if(localusers.containsCaseInsensitive(recipient.toString()))
           {
               originalUsername = recipient.toString();
           }
           else
           {
               originalUsername = recipient.getUser();
           } 
          
            username = localusers.getRealName(originalUsername);
            if (username == null) {
                StringBuffer errorBuffer =
                    new StringBuffer(128)
                        .append("The inbox for user ")
                        .append(originalUsername)
                        .append(" was not found on this server.");
                throw new MessagingException(errorBuffer.toString());
            }
        } else {
           if(localusers.containsCaseInsensitive(recipient.toString()))
           {
               username = recipient.toString();
           }
           else
           {
               username = recipient.getUser();
           } 
        }
        
        JamesUser user;
        if (enableAliases || enableForwarding) {
            user = (JamesUser) localusers.getUserByName(username);
            if (enableAliases && user.getAliasing()) {
                username = user.getAlias();
            }
            // Forwarding takes precedence over local aliases
            if (enableForwarding && user.getForwarding()) {
                MailAddress forwardTo = user.getForwardingDestination();
                if (forwardTo == null) {
                    StringBuffer errorBuffer =
                        new StringBuffer(128)
                            .append("Forwarding was enabled for ")
                            .append(username)
                            .append(" but no forwarding address was set for this account.");
                    throw new MessagingException(errorBuffer.toString());
                }
                Collection recipients = new HashSet();
                recipients.add(forwardTo);
                try {
                    sendMail(sender, recipients, message);
                    if (getLogger().isInfoEnabled()) {
                        StringBuffer logBuffer =
                            new StringBuffer(128)
                                    .append("Mail for ")
                                    .append(username)
                                    .append(" forwarded to ")
                                    .append(forwardTo.toString());
                        getLogger().info(logBuffer.toString());
                    }
                    return;
                } catch (MessagingException me) {
                    if (getLogger().isErrorEnabled()) {
                        StringBuffer logBuffer =
                            new StringBuffer(128)
                                    .append("Error forwarding mail to ")
                                    .append(forwardTo.toString())
                                    .append("attempting local delivery");
                        getLogger().error(logBuffer.toString());
                    }
                    throw me;
                }
            }
        }

        Collection recipients = new HashSet();
        recipients.add(recipient);
        MailImpl mailImpl = new MailImpl(getId(), sender, recipients, message);
        MailRepository userInbox = getUserInbox(username);
        if (userInbox == null) {
            StringBuffer errorBuffer =
                new StringBuffer(128)
                    .append("The inbox for user ")
                    .append(username)
                    .append(" was not found on this server.");
            throw new MessagingException(errorBuffer.toString());
        }
        userInbox.store(mailImpl);
    }

 . . . . .

Thank you for James, it is a great product. I hope this contributes a little bit.

Regards,

            +
marinus
    van Zyl

RE: Different Inbox Accounts for the same email name but different domains on One James email server

Posted by "Noel J. Bergman" <no...@devtech.com>.
> 2 different clients wanted the same user name,
> e.g. 'marketing' or 'admin', but for their own domain names.

See the VirtualUserTable mailets.

	--- Noel


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