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 ba...@apache.org on 2005/08/25 00:01:16 UTC
svn commit: r239947 - in /james/server/trunk/src/java/org/apache/james:
Constants.java James.java transport/mailets/LocalDelivery.java
Author: bago
Date: Wed Aug 24 15:01:10 2005
New Revision: 239947
URL: http://svn.apache.org/viewcvs?rev=239947&view=rev
Log:
Moved the storeMail code from James (MailetContext) to remoteDelivery (also part of JAMES-392).
1) we don't use MailetContext.storeMail anymore and we can safely remove that deprecated method.
2) we can now override enableAliases/enableForwarding in the local LocalDelivery configuration.
Modified:
james/server/trunk/src/java/org/apache/james/Constants.java
james/server/trunk/src/java/org/apache/james/James.java
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
Modified: james/server/trunk/src/java/org/apache/james/Constants.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/Constants.java?rev=239947&r1=239946&r2=239947&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/Constants.java (original)
+++ james/server/trunk/src/java/org/apache/james/Constants.java Wed Aug 24 15:01:10 2005
@@ -62,4 +62,22 @@
*/
public static final String AVALON_COMPONENT_MANAGER = "AVALON_COMP_MGR";
+ /**
+ * Context key used to store the enableAliases configuration for the default
+ * LocalUsers Repository.
+ */
+ public static final String DEFAULT_ENABLE_ALIASES = "JAMES_DEFAULT_ENABLE_ALIASES";
+
+ /**
+ * Context key used to store the enableForwarding configuration for the default
+ * LocalUsers Repository.
+ */
+ public static final String DEFAULT_ENABLE_FORWARDING = "JAMES_DEFAULT_ENABLE_FORWARDING";
+
+ /**
+ * Context key used to store the ignoreCase configuration for the
+ * UserRepository
+ */
+ public static final String DEFAULT_IGNORE_USERNAME_CASE = "JAMES_DEFAULT_IGNORE_USERNAME_CASE";
+
}
Modified: james/server/trunk/src/java/org/apache/james/James.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/James.java?rev=239947&r1=239946&r2=239947&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/James.java (original)
+++ james/server/trunk/src/java/org/apache/james/James.java Wed Aug 24 15:01:10 2005
@@ -38,7 +38,6 @@
import org.apache.james.core.MailHeaders;
import org.apache.james.core.MailImpl;
import org.apache.james.services.DNSServer;
-import org.apache.james.services.JamesUser;
import org.apache.james.services.MailRepository;
import org.apache.james.services.MailServer;
import org.apache.james.services.SpoolRepository;
@@ -146,16 +145,6 @@
private boolean ignoreCase;
/**
- * Whether to enable aliasing for users on this server
- */
- private boolean enableAliases;
-
- /**
- * Whether to enable forwarding for users on this server
- */
- private boolean enableForwarding;
-
- /**
* The number of mails generated. Access needs to be synchronized for
* thread safety and to ensure that all threads see the latest value.
*/
@@ -333,8 +322,11 @@
Configuration userNamesConf = conf.getChild("usernames");
ignoreCase = userNamesConf.getAttributeAsBoolean("ignoreCase", false);
- enableAliases = userNamesConf.getAttributeAsBoolean("enableAliases", false);
- enableForwarding = userNamesConf.getAttributeAsBoolean("enableForwarding", false);
+ boolean enableAliases = userNamesConf.getAttributeAsBoolean("enableAliases", false);
+ boolean enableForwarding = userNamesConf.getAttributeAsBoolean("enableForwarding", false);
+ attributes.put(Constants.DEFAULT_ENABLE_ALIASES,new Boolean(enableAliases));
+ attributes.put(Constants.DEFAULT_ENABLE_FORWARDING,new Boolean(enableForwarding));
+ attributes.put(Constants.DEFAULT_IGNORE_USERNAME_CASE,new Boolean(ignoreCase));
//Get localusers
try {
@@ -687,89 +679,6 @@
return postmaster;
}
- 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 = 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 {
- 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);
- }
-
/**
* Return the major version number for the server
*
@@ -883,4 +792,14 @@
}
return dnsServer.getSMTPHostAddresses(domainName);
}
+
+ /**
+ * This method has been moved to LocalDelivery (the only client of the method).
+ * Now we can safely remove it from the Mailet API and from this implementation of MailetContext.
+ *
+ * @see org.apache.mailet.MailetContext#storeMail(org.apache.mailet.MailAddress, org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)
+ */
+ public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException {
+ throw new UnsupportedOperationException("store mail is no more allowed for MailetContext: please take a reference to the user inbox Repository and store there.");
+ }
}
Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java?rev=239947&r1=239946&r2=239947&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java Wed Aug 24 15:01:10 2005
@@ -17,6 +17,15 @@
package org.apache.james.transport.mailets;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.james.Constants;
+import org.apache.james.James;
+import org.apache.james.core.MailImpl;
+import org.apache.james.services.JamesUser;
+import org.apache.james.services.MailRepository;
+import org.apache.james.services.MailServer;
+import org.apache.james.services.UsersRepository;
import org.apache.mailet.RFC2822Headers;
import org.apache.mailet.GenericMailet;
@@ -25,13 +34,12 @@
import javax.mail.Header;
import javax.mail.MessagingException;
-import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetHeaders;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;
@@ -42,6 +50,38 @@
*/
public class LocalDelivery extends GenericMailet {
/**
+ * The number of mails generated. Access needs to be synchronized for
+ * thread safety and to ensure that all threads see the latest value.
+ */
+ private static long count;
+
+ /**
+ * The mailserver reference
+ */
+ private MailServer mailServer;
+
+ /**
+ * The user repository for this mail server. Contains all the users with inboxes
+ * on this server.
+ */
+ private UsersRepository localusers;
+
+ /**
+ * Whether to enable aliasing for users on this server
+ */
+ private boolean enableAliases;
+
+ /**
+ * Whether to enable forwarding for users on this server
+ */
+ private boolean enableForwarding;
+
+ /**
+ * Whether to ignore case when looking up user names on this server
+ */
+ private boolean ignoreCase;
+
+ /**
* Delivers a mail to a local mailbox.
*
* @param mail the mail being processed
@@ -72,7 +112,7 @@
// Add qmail's de facto standard Delivered-To header
message.addHeader("Delivered-To", recipient.toString());
- getMailetContext().storeMail(mail.getSender(), recipient, message);
+ storeMail(mail.getSender(), recipient, message);
if (i.hasNext()) {
// Remove headers but leave all placeholders
@@ -111,4 +151,146 @@
public String getMailetInfo() {
return "Local Delivery Mailet";
}
+
+
+ /**
+ * This method has been moved here from James.java when we removed it from the MailetContext
+ * (2005/08/24)
+ *
+ * @param sender
+ * @param recipient
+ * @param message
+ * @throws MessagingException
+ */
+ 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 = 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 {
+ 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 {
+ getMailetContext().sendMail(sender, recipients, message);
+ StringBuffer logBuffer =
+ new StringBuffer(128)
+ .append("Mail for ")
+ .append(username)
+ .append(" forwarded to ")
+ .append(forwardTo.toString());
+ getMailetContext().log(logBuffer.toString());
+ return;
+ } catch (MessagingException me) {
+ StringBuffer logBuffer =
+ new StringBuffer(128)
+ .append("Error forwarding mail to ")
+ .append(forwardTo.toString())
+ .append("attempting local delivery");
+ getMailetContext().log(logBuffer.toString());
+ throw me;
+ }
+ }
+ }
+
+ Collection recipients = new HashSet();
+ recipients.add(recipient);
+ MailImpl mailImpl = new MailImpl(getId(), sender, recipients, message);
+ MailRepository userInbox = mailServer.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);
+ }
+
+
+ /**
+ * Return a new mail id.
+ *
+ * @return a new mail id
+ */
+ public String getId() {
+ long localCount = -1;
+ synchronized (James.class) {
+ localCount = count++;
+ }
+ StringBuffer idBuffer =
+ new StringBuffer(64)
+ .append("Mail")
+ .append(System.currentTimeMillis())
+ .append("-")
+ .append(localCount);
+ return idBuffer.toString();
+ }
+
+ /**
+ * @see org.apache.mailet.GenericMailet#init()
+ */
+ public void init() throws MessagingException {
+ super.init();
+ ServiceManager compMgr = (ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
+
+ try {
+ // Instantiate the a MailRepository for outgoing mails
+ mailServer = (MailServer) compMgr.lookup(MailServer.ROLE);
+ localusers = (UsersRepository) compMgr.lookup(UsersRepository.ROLE);
+ } catch (ServiceException cnfe) {
+ log("Failed to retrieve Store component:" + cnfe.getMessage());
+ } catch (Exception e) {
+ log("Failed to retrieve Store component:" + e.getMessage());
+ }
+
+ String enAliases = getInitParameter("enableAliases");
+ String enForward = getInitParameter("enableForwarding");
+
+ if (enAliases == null || enAliases.length()==0) {
+ enableAliases = ((Boolean) getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_ALIASES)).booleanValue();
+ } else enableAliases = new Boolean(enAliases).booleanValue();
+
+ if (enForward == null || enForward.length()==0) {
+ enableForwarding = ((Boolean) getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_FORWARDING)).booleanValue();
+ } else enableForwarding = new Boolean(enForward).booleanValue();
+
+ ignoreCase = ((Boolean) getMailetContext().getAttribute(Constants.DEFAULT_IGNORE_USERNAME_CASE)).booleanValue();
+
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: LocalDelivery changes (Was: svn commit: r239947)
Posted by Danny Angus <da...@gmail.com>.
On 24/08/05, Stefano Bagnara <ap...@bago.org> wrote:
> Please look at the change and answer this questions:
>
> 1) Should I move the enableAliases/enableForward directly to the
> LocalDelivery?
Yes.
I'm +1 for anything that allows configurations which were limited to
being set once in James but used many times to being refactored to
many to many, which means moving them nearer the point of use.
Of course it also makes sense sometimes to retain a global default.
And we've always applied the principle of least surprise when
considering config questions, try to think through the questions that
will arise when people upgrade, and take that into account when you
make config file format changes. This usually means make it work by
default like it did before unless the users choose to change it.
> I'm not sure that trying to achieve backward compatibility in the config.xml
> is a good idea (we would need a lot of junk in the code and in the config to
> do that).
I understand that. But work through what would be needed to break
this, documentation etc is part of this consideration.
> Please note that I already changed the place where you have to
> declare mailetpackages/matcherpackages and the place you declare the main
> spool repository.
Yeah I noticed, you will have to be prepared to document this and
support it on the users list when the questions flood in.
> 2) IgnoreCase is instead used more than once and by more clients (Not only
> LocalDelivery) and so I was thinking that we should move this configuration
> to the UserRepository interface. Should I do that?
It is a global setting, the rfc (I forget) makes user parts case
sensitive, we offer the choice to
ignore this globally, anything else would (IMO) just be confusing.
What benefit would the chnage bring?
> 3) Should I remove the deprecated method storeMail from MailetContext now?
> We also have a few other deprecated methods
...
> previous release IMHO we can safely remove all of them: do you agree?
Only if the next release is going to be a Major one (i.e. 3.x not 2.x)
> 4) With this change I could split the LocalDelivery in 2 different new
> mailets (leave LocalDelivery for backward compatibility) and create a
> LocalUsersAliasingForwarding mailet that just apply aliasing and forwarding
> for the mails processed and a LocalDelivery that simply deliver the message
> to a repository named like the destination of the message being processed
> (with no lookup on users). This would allow much more flexible
> Configurations.
+1 This is good, and paves the way for richer v'hosting.
> 5) I can add configurations to the LocalDelivery (or the 2 new mailets) in
> order to be able to use a different UserRepository (different from the
> LocalUsers) or a different inboxes repositories by allowing local
> "overriding" configurations: what do you think?
+1 Yes, this also is good, and also supports richer v'hosting support.
(The third thing is to modify pop3 & imap handlers to implement
combinations of IP address reverse dns and username naming convention
to fudge that part.)
d.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: Deprecating / removing methods
Posted by Stefano Bagnara <ap...@bago.org>.
> > Considering they were already deprecated in the previous
> release IMHO
> > we can safely remove all of them: do you agree?
>
> No. We have many users out there who customize JAMES and who
> have their own matchers/mailets, and we only know the tip of
> the iceberg. We should consider removing deprecated methods
> when we (a) have published a replacement, and (b) have a
> major version change, e.g., version 2 to version 3.
So I can safely do that for methods deprecated in 1.x releases and add a
comment to every other deprecated methods so that we don't forget to remove
them for the 3.0 release.
If we see that we have many of them we could consider jumping to 3.0 instead
of trying to release this 2.3.0.
IMHO if we want to release a 2.3.0 we should try to do it NOW, or even
better on a release of a few weeks ago (before the block assembly
refactoring). BTW there is no version/release versioning explanation on the
websites saying that only major releases will change the APIs and IIRC from
2.1 to 2.2 Mailet APIs have been changed by also removing methods/classes.
My vote goes for 2.3.0 at the end of this refactoring and for API changes
with removed methods, but I'm not against any other release cycle. When you
or another pmc will start doing the release manager for the next release
I'll look at the release proposal.
Stefano
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Deprecating / removing methods
Posted by "Noel J. Bergman" <no...@devtech.com>.
> Considering they were already deprecated in the previous release
> IMHO we can safely remove all of them: do you agree?
No. We have many users out there who customize JAMES and who have their own
matchers/mailets, and we only know the tip of the iceberg. We should
consider removing deprecated methods when we (a) have published a
replacement, and (b) have a major version change, e.g., version 2 to version
3.
--- Noel
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
LocalDelivery changes (Was: svn commit: r239947)
Posted by Stefano Bagnara <ap...@bago.org>.
> Moved the storeMail code from James (MailetContext) to
> remoteDelivery (also part of JAMES-392).
> 1) we don't use MailetContext.storeMail anymore and we can
> safely remove that deprecated method.
> 2) we can now override enableAliases/enableForwarding in the
> local LocalDelivery configuration.
Please look at the change and answer this questions:
1) Should I move the enableAliases/enableForward directly to the
LocalDelivery?
For backward compatibility I chose to put them from the "James" config to
the mailcontext attributes so that LocalDelivery can lookup this values but
I'm almost convinced that it would be better to move the 2 informations to
the localdelivery only.
I'm not sure that trying to achieve backward compatibility in the config.xml
is a good idea (we would need a lot of junk in the code and in the config to
do that). Please note that I already changed the place where you have to
declare mailetpackages/matcherpackages and the place you declare the main
spool repository.
2) IgnoreCase is instead used more than once and by more clients (Not only
LocalDelivery) and so I was thinking that we should move this configuration
to the UserRepository interface. Should I do that?
3) Should I remove the deprecated method storeMail from MailetContext now?
We also have a few other deprecated methods
"UserRepository.getAttributes(String name)",
"AbstractRedirect.getExistingReturnPath(Mail mail)",
Resources.USERS_MANAGER, Resources.MAIL_SERVER, Resources.TRANSPORT,
Resources.TMP_REPOSITORY, IOUtil.bufferedCopy,
JdbcDataSource.killAllConnections, JdbcDataSource.killConnection,
RFC822DateFormat.toString. Considering they were already deprecated in the
previous release IMHO we can safely remove all of them: do you agree?
4) With this change I could split the LocalDelivery in 2 different new
mailets (leave LocalDelivery for backward compatibility) and create a
LocalUsersAliasingForwarding mailet that just apply aliasing and forwarding
for the mails processed and a LocalDelivery that simply deliver the message
to a repository named like the destination of the message being processed
(with no lookup on users). This would allow much more flexible
Configurations.
5) I can add configurations to the LocalDelivery (or the 2 new mailets) in
order to be able to use a different UserRepository (different from the
LocalUsers) or a different inboxes repositories by allowing local
"overriding" configurations: what do you think?
You can see the diff in the previous svn commit 239947 or here:
http://issues.apache.org/jira/browse/JAMES-392?page=all
Stefano
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: svn commit: r239947 - in /james/server/trunk/src/java/org/apache/james: Constants.java James.java transport/mailets/LocalDelivery.java
Posted by Stefano Bagnara <ap...@bago.org>.
Does anyone know why this commit didn't appear in
http://issues.apache.org/jira/browse/JAMES-392?page=all
Stefano
> -----Messaggio originale-----
> Inviato: giovedì 25 agosto 2005 0.01
> A: server-cvs@james.apache.org
> Oggetto: svn commit: r239947 - in
> /james/server/trunk/src/java/org/apache/james: Constants.java
> James.java transport/mailets/LocalDelivery.java
>
> Author: bago
> Date: Wed Aug 24 15:01:10 2005
> New Revision: 239947
>
> URL: http://svn.apache.org/viewcvs?rev=239947&view=rev
> Log:
> Moved the storeMail code from James (MailetContext) to
> remoteDelivery (also part of JAMES-392).
> 1) we don't use MailetContext.storeMail anymore and we can
> safely remove that deprecated method.
> 2) we can now override enableAliases/enableForwarding in the
> local LocalDelivery configuration.
>
> Modified:
> james/server/trunk/src/java/org/apache/james/Constants.java
> james/server/trunk/src/java/org/apache/james/James.java
[...]
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org