Author: norman Date: Fri Nov 10 00:20:30 2006 New Revision: 473249 URL: http://svn.apache.org/viewvc?view=rev&rev=473249 Log: Put the hostname and hostaddress in the mailetcontext to remove all InetAddress usage from mailets. See JAMES-643
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/AbstractRedirect.java james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java james/server/trunk/src/test/org/apache/james/JamesTest.java Modified: james/server/trunk/src/java/org/apache/james/Constants.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/Constants.java?view=diff&rev=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/java/org/apache/james/Constants.java (original) +++ james/server/trunk/src/java/org/apache/james/Constants.java Fri Nov 10 00:20:30 2006 @@ -58,5 +58,15 @@ * Avalon aware Mailets. */ public static final String AVALON_COMPONENT_MANAGER = "AVALON_COMP_MGR"; + + /** + * Key used to store the hostaddress of the localhost + */ + public static final String HOSTADDRESS = "127.0.0.1"; + + /** + * Key used to store the hostname of localhost + */ + public static final String HOSTNAME = "localhost"; } 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=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/java/org/apache/james/James.java (original) +++ james/server/trunk/src/java/org/apache/james/James.java Fri Nov 10 00:20:30 2006 @@ -259,6 +259,14 @@ java.io.File configDir = fileSystem.getFile("file://conf/"); attributes.put("confDir", configDir.getCanonicalPath()); + try { + attributes.put(Constants.HOSTADDRESS, lookupDNSServer().getLocalHost().getHostAddress()); + attributes.put(Constants.HOSTNAME, lookupDNSServer().getLocalHost().getHostName()); + } catch (java.net.UnknownHostException _) { + attributes.put(Constants.HOSTADDRESS, "127.0.0.1"); + attributes.put(Constants.HOSTNAME, "localhost"); + } + initializeLocalDeliveryMailet(); System.out.println(SOFTWARE_NAME_VERSION); Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java?view=diff&rev=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java Fri Nov 10 00:20:30 2006 @@ -44,6 +44,7 @@ import org.apache.mailet.RFC2822Headers; import org.apache.mailet.dates.RFC822DateFormat; +import org.apache.james.Constants; import org.apache.james.core.MailImpl; import org.apache.james.core.MimeMessageUtil; @@ -982,14 +983,9 @@ // We don't need to use the original Remote Address and Host, // and doing so would likely cause a loop with spam detecting // matchers. - try { - newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress()); - newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName()); - } catch (java.net.UnknownHostException _) { - newMail.setRemoteAddr("127.0.0.1"); - newMail.setRemoteHost("localhost"); - } - + newMail.setRemoteAddr(getMailetContext().getAttribute(Constants.HOSTADDRESS).toString()); + newMail.setRemoteHost(getMailetContext().getAttribute(Constants.HOSTNAME).toString()); + if (isDebug) { log("New mail - sender: " + newMail.getSender() + ", recipients: " + arrayToString(newMail.getRecipients().toArray()) 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=473249&r1=473248&r2=473249 ============================================================================== --- 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 Fri Nov 10 00:20:30 2006 @@ -21,6 +21,7 @@ package org.apache.james.transport.mailets; +import org.apache.james.Constants; import org.apache.james.core.MailImpl; import org.apache.james.util.VirtualUserTableUtil; import org.apache.mailet.GenericMailet; @@ -164,13 +165,9 @@ // duplicates the Mail object, to be able to modify the new mail keeping the original untouched MailImpl newMail = new MailImpl(mail); try { - try { - newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress()); - newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName()); - } catch (java.net.UnknownHostException _) { - newMail.setRemoteAddr("127.0.0.1"); - newMail.setRemoteHost("localhost"); - } + newMail.setRemoteAddr(getMailetContext().getAttribute(Constants.HOSTADDRESS).toString()); + newMail.setRemoteHost(getMailetContext().getAttribute(Constants.HOSTNAME).toString()); + newMail.setRecipients(recipientsToAddForward); newMail.setAttribute(MARKER, Boolean.TRUE); getMailetContext().sendMail(newMail); Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java?view=diff&rev=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java Fri Nov 10 00:20:30 2006 @@ -152,14 +152,9 @@ // We don't need to use the original Remote Address and Host, // and doing so would likely cause a loop with spam detecting // matchers. - try { - newMail.setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress()); - newMail.setRemoteHost(java.net.InetAddress.getLocalHost().getHostName()); - } catch (java.net.UnknownHostException _) { - newMail.setRemoteAddr("127.0.0.1"); - newMail.setRemoteHost("localhost"); - } - + newMail.setRemoteAddr(getMailetContext().getAttribute(Constants.HOSTADDRESS).toString()); + newMail.setRemoteHost(getMailetContext().getAttribute(Constants.HOSTNAME).toString()); + if (originalMail.getSender() == null) { if (isDebug) log("Processing a bounce request for a message with an empty reverse-path. No bounce will be sent."); Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java?view=diff&rev=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java Fri Nov 10 00:20:30 2006 @@ -860,8 +860,8 @@ PrintWriter out = new PrintWriter(sout, true); String machine = "[unknown]"; try { - InetAddress me = InetAddress.getLocalHost(); - machine = me.getHostName(); + machine = getMailetContext().getAttribute(Constants.HOSTNAME).toString(); + } catch(Exception e){ machine = "[address unknown]"; } Modified: james/server/trunk/src/test/org/apache/james/JamesTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/JamesTest.java?view=diff&rev=473249&r1=473248&r2=473249 ============================================================================== --- james/server/trunk/src/test/org/apache/james/JamesTest.java (original) +++ james/server/trunk/src/test/org/apache/james/JamesTest.java Fri Nov 10 00:20:30 2006 @@ -42,6 +42,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -126,6 +127,10 @@ DNSServer dns = new AbstractDNSServer() { public String getHostName(InetAddress addr) { return "localhost"; + } + + public InetAddress getLocalHost() throws UnknownHostException { + throw new UnknownHostException("Unknown"); } }; return dns; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]