james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From charl...@apache.org
Subject cvs commit: jakarta-james/src/org/apache/james/dnsserver DNSServer.java DNSServer.xinfo
Date Fri, 11 May 2001 09:16:02 GMT
charlesb    01/05/11 02:16:01

  Added:       src/java/org/apache/james/core AvalonMailStore.java
                        AvalonMailStore.xinfo AvalonUsersStore.java
                        AvalonUsersStore.xinfo EnhancedMimeMessage.java
                        JamesMimeMessage.java
                        JamesMimeMessageInputStream.java MailImpl.java
                        MailetConfigImpl.java MatcherConfigImpl.java
               src/java/org/apache/james/dnsserver DNSServer.java
                        DNSServer.xinfo
  Removed:     src/org/apache/james/core AvalonMailStore.java
                        AvalonMailStore.xinfo AvalonUsersStore.java
                        AvalonUsersStore.xinfo EnhancedMimeMessage.java
                        JamesMimeMessage.java
                        JamesMimeMessageInputStream.java MailImpl.java
                        MailetConfigImpl.java MatcherConfigImpl.java
               src/org/apache/james/dnsserver DNSServer.java
                        DNSServer.xinfo
  Log:
  Moving from src/org to src/java/org
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/java/org/apache/james/core/AvalonMailStore.java
  
  Index: AvalonMailStore.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.core;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.james.services.MailRepository;
  import org.apache.james.services.MailStore;
  import org.apache.log.LogKit;
  import org.apache.log.Logger;
  import org.apache.avalon.phoenix.Block;
  
  /**
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   *
   * Provides Registry of mail repositories. A mail repository is uniquely identified 
   * by destinationURL, type and model.
   */
  public class AvalonMailStore
      extends AbstractLoggable
      implements Block, Composable, Configurable, MailStore, Initializable {
  
      private static final String REPOSITORY_NAME = "Repository";
      private static long id;
      // map of [destinationURL + type]->Repository
      private HashMap repositories;
      // map of [destinationURL + type]->model
      private HashMap models;
      // map of [protocol(destinationURL) + type + model]->classname of repository;
      private HashMap classes;
      protected Configuration          configuration;
      protected ComponentManager       componentManager;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          this.componentManager = componentManager;
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          this.configuration = configuration;
      }
  
      public void initialize()
          throws Exception {
  
          getLogger().info("JamesMailStore init...");
          repositories = new HashMap();
          models = new HashMap();
          classes = new HashMap();
          Configuration[] registeredClasses
              = configuration.getChild("repositories").getChildren("repository");
          for ( int i = 0; i < registeredClasses.length; i++ )
          {
              registerRepository((Configuration) registeredClasses[i]);
          }
          getLogger().info("James MailStore ...init");
      }
  
      public synchronized void registerRepository(Configuration repConf)
          throws ConfigurationException {
          String className = repConf.getAttribute("class");
          getLogger().info("Registering Repository " + className);
          Configuration[] protocols
              = repConf.getChild("protocols").getChildren("protocol");
          Configuration[] types = repConf.getChild("types").getChildren("type");
          Configuration[] models
              = repConf.getChild("models").getChildren("model");
          for ( int i = 0; i < protocols.length; i++ )
          {
              String protocol = protocols[i].getValue();
  
              for ( int j = 0; j < types.length; j++ )
              {
                  String type = types[j].getValue();
  
                  for ( int k = 0; k < models.length; k++ )
                  {
                      String model = models[k].getValue();
                      String key = protocol + type + model;
                      classes.put(key, className);
                      getLogger().info("Registered class: " + key+"->"+className);
                  }
              }
          }
      }
  
      public void release(Component component)
      {
      }
  
      public synchronized Component select(Object hint) throws ComponentException
      {
  
          Configuration repConf = null;
          try {
              repConf = (Configuration) hint;
          } catch (ClassCastException cce) {
              throw new ComponentException("hint is of the wrong type. Must be a Configuration", cce);
          }
          String destination = null;
          String protocol = null;
          try {
              destination = repConf.getAttribute("destinationURL");
              int idx = destination.indexOf(':');
              if ( idx == -1 )
                  throw new ComponentException
                      ("destination is malformed. Must be a valid URL: "+destination);
              protocol = destination.substring(0,idx);
          } catch (ConfigurationException ce) {
              throw new ComponentException("Malformed configuration has no destinationURL attribute", ce);
          }
  
          try
          {
              String type = repConf.getAttribute("type");
              String repID = destination + type;
              MailRepository reply = (MailRepository) repositories.get(repID);
              String model = (String) repConf.getAttribute("model");
              if (reply != null) {
                  if (models.get(repID).equals(model)) {
                      getLogger().debug("obtained repository: "+repID+","+reply.getClass());
                      return (Component)reply;
                  } else {
                      throw new ComponentException("There is already another repository with the same destination and type but with different model");
                  }
              } else {
                  String repClass = (String) classes.get( protocol + type + model );
  
                  getLogger().debug( "Need instance of " + repClass +
                                     " to handle: " + protocol + "," + type + "," +model );
  
                  try {
                      reply = (MailRepository) Class.forName(repClass).newInstance();
                     if (reply instanceof Loggable) {
  		       setupLogger(reply);
                      }
                      if (reply instanceof Configurable) {
                          ((Configurable) reply).configure(repConf);
                      }
                      if (reply instanceof Composable) {
                          ((Composable) reply).compose( componentManager );
                      }
  /*                if (reply instanceof Contextualizable) {
                    ((Contextualizable) reply).contextualize(context);
                    }*/
                      if (reply instanceof Initializable) {
                          ((Initializable) reply).initialize();
                      }
                      repositories.put(repID, reply);
                      models.put(repID, model);
                      getLogger().info("added repository: "+repID+"->"+repClass);
  		    /*                    getLogger().info( "New instance of " + repClass +
  		     *		  " created for " + destination );
                       */
                      return (Component)reply;
                  } catch (Exception e) {
                      getLogger().warn( "Exception while creating repository:" +
                                        e.getMessage(), e );
  
                      throw new
                          ComponentException( "Cannot find or init repository", e );
                  }
              }
          } catch( final ConfigurationException ce ) {
              throw new ComponentException( "Malformed configuration", ce );
          }
      }
  
      public static final String getName() {
          return REPOSITORY_NAME + id++;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/AvalonMailStore.xinfo
  
  Index: AvalonMailStore.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
  
    <meta>
  
      <contributors>
        <author name="Federico Barbier" email="fede@apache.org"/>
        <author name="Charles Benett" email="charle@benett1.demon.co.uk"/>
      </contributors>
  
    </meta>
  
    <!-- services that are offered by this block -->
    <services>
      <service name="org.apache.james.services.MailStore" version="1.0" />
    </services>
  
    <dependencies>
      <dependency>
        <role>org.apache.avalon.cornerstone.services.store.Store</role>
        <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
      </dependency>
    </dependencies>
  
  </blockinfo>
  
  
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/AvalonUsersStore.java
  
  Index: AvalonUsersStore.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.core;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Iterator;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.james.services.UsersRepository;
  import org.apache.james.services.UsersStore;
  import org.apache.avalon.phoenix.Block;
  
  /**
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   */
  public class AvalonUsersStore
      extends AbstractLoggable
      implements Block, Composable, Configurable, UsersStore, Initializable {
  
      private HashMap repositories;
      protected Configuration          configuration;
      protected ComponentManager       componentManager;
  
      public void configure( final Configuration configuration )
          throws ConfigurationException {
          this.configuration = configuration;
      }
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException {
          this.componentManager = componentManager;
      }
  
      public void initialize()
          throws Exception {
  
          getLogger().info("AvalonUsersStore init...");
          repositories = new HashMap();
  
          Configuration[] repConfs = configuration.getChildren("repository");
          for ( int i = 0; i < repConfs.length; i++ )
          {
              Configuration repConf = repConfs[i];
              String repName = repConf.getAttribute("name");
              String repClass = repConf.getAttribute("class");
  
              UsersRepository rep = (UsersRepository) Class.forName(repClass).newInstance();
  
              setupLogger((Component)rep);
  
              if (rep instanceof Composable) {
                  ((Composable) rep).compose( componentManager );
              }
  
              if (rep instanceof Configurable) {
                  ((Configurable) rep).configure(repConf);
              }
              /*
                if (rep instanceof Contextualizable) {
                ((Contextualizable) rep).contextualize(context);
                }
              */
              if (rep instanceof Initializable) {
                  ((Initializable) rep).initialize();
              }
              repositories.put(repName, rep);
              getLogger().info("UsersRepository " + repName + " started.");
          }
          getLogger().info("AvalonUsersStore ...init");
      }
  
  
      public UsersRepository getRepository(String request) {
          UsersRepository response = (UsersRepository) repositories.get(request);
          if (response == null) {
              getLogger().warn("No users repository called: " + request);
          }
          return response;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/AvalonUsersStore.xinfo
  
  Index: AvalonUsersStore.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
  
    <meta>
  
      <contributors>
        <author name="Charles Benett" email="charles@benett1.demon.co.uk"/>
      </contributors>
  
    </meta>
  
    <!-- services that are offered by this block -->
    <services>
      <service name="org.apache.james.services.UsersStore" version="1.0" />
    </services>
  
    <dependencies>
      <dependency>
        <role>org.apache.avalon.cornerstone.services.store.Store</role>
        <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
      </dependency>
    </dependencies>
  
  </blockinfo>
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/EnhancedMimeMessage.java
  
  Index: EnhancedMimeMessage.java
  ===================================================================
  package org.apache.james.core;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.Enumeration;
  import javax.mail.*;
  import javax.mail.internet.*;
  
  /**
   * EnhancedMimeMessage is a direct subclass of MimeMessage that overrides the
   * getLineCount method of javax.mail.internet.MimeMessage with one that works
   * (kind of) and adds additional methods writeContentTo and getMessageSize.
   *
   * @author <a href="mailto:charles@benett1.demon.co.uk">Charles Benett</a>
   * @version 0.1  on 14 Dec 2000
   */
  public class EnhancedMimeMessage 
      extends MimeMessage {
  
      public EnhancedMimeMessage(Session session, InputStream in)
          throws MessagingException {
          super(session, in);
      }
  
      public  EnhancedMimeMessage(MimeMessage message)
          throws MessagingException {
          super(message);
      }
  
  
      /**
       * Corrects JavaMail 1.1 version which always returns -1.
       * Only corrected for content less than 5000 bytes,
       * to avoid memory hogging.
       */
      public int getLineCount() throws MessagingException {
          if (content == null) {
              return -1;
          }
          int size = content.length; // size of byte array
          int lineCount = 0;
          if (size < 5000) {
              for (int i=0; i < size -2; i++) {
                  if (content[i] == '\r' && content[i+1] == '\n') {
                      lineCount++;
                  }
              }
              if (content[size -2] != '\r' || content[size-1] != '\n') {
                  //message has a non-empty final line.
                  lineCount++;
              }
          } else {
              lineCount = -1;
          }
          return lineCount;
      }
  
  
      /**
       * Writes content only, ie not headers, to the specified outputstream.
       */
      public void writeContentTo(OutputStream outs)
          throws java.io.IOException, MessagingException {
          int size = content.length; // size of byte array
          int chunk = 1000; //arbitrary choice - ideas welcome
          int pointer = 0;
          while (pointer < size) {
              if ((size - pointer) > chunk) {
                  outs.write(content, pointer, chunk);
              } else {
                  outs.write(content, pointer, size-pointer);
              }
              pointer += chunk;
          }
      }
  
      /**
       * Returns size of message, ie headers and content. Current implementation
       * actually returns number of characters in headers plus number of bytes
       * in the internal content byte array.
       */
      public int getMessageSize() throws MessagingException {
          int contentSize = content.length;
          int headerSize = 0;
          Enumeration e = getAllHeaderLines();
          while (e.hasMoreElements()) {
              headerSize += ((String)e.nextElement()).length();
          }
          return headerSize + contentSize;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/JamesMimeMessage.java
  
  Index: JamesMimeMessage.java
  ===================================================================
  package org.apache.james.core;
  
  import java.io.*;
  import java.util.*;
  import javax.activation.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  
  public class JamesMimeMessage extends MimeMessage {
      MimeMessage message = null;
  
      InputStream in = null;
      boolean modified = false;
  
      public JamesMimeMessage(Session session, InputStream in) {
          super(session);
          this.in = in;
      }
  
      /**
       * Internal implementations
       */
      private synchronized void loadMessage() throws MessagingException {
          if (message != null) {
              //Another thread has already loaded this message
              return;
          }
          message = new MimeMessage(session, in);
          try {
              in.close();
          } catch (IOException ioe) {
              throw new MessagingException("Unable to parse stream: " + ioe.getMessage());
          }
      }
  
      /**
       * Special methods you can call
       */
      public boolean isModified() {
          return modified;
      }
  
      public InputStream getSourceStream() {
          return in;
      }
  
  
      /**
       * Methods that should be rewritten for optimization purposes
       */
      public void writeTo(OutputStream os) throws IOException, MessagingException {
          if (message == null) {
              loadMessage();
          }
          message.writeTo(os);
      }
  
      public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException {
          if (message == null) {
              loadMessage();
          }
          message.writeTo(os, ignoreList);
      }
  
  
      /**
       * Various reader methods
       */
  
      public Address[] getFrom() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getFrom();
      }
  
      public Address[] getRecipients(Message.RecipientType type) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getRecipients(type);
      }
  
      public Address[] getAllRecipients() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getAllRecipients();
      }
  
      public Address[] getReplyTo() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getReplyTo();
      }
  
      public String getSubject() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getSubject();
      }
  
      public Date getSentDate() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getSentDate();
      }
  
      public Date getReceivedDate() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getReceivedDate();
      }
  
      public int getSize() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getSize();
      }
  
      /**
       * Corrects JavaMail 1.1 version which always returns -1.
       * Only corrected for content less than 5000 bytes,
       * to avoid memory hogging.
       */
      public int getLineCount() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
  	int size = content.length; // size of byte array
  	int lineCount = 0;
  	if (size < 5000) {
  	    for (int i=0; i < size -1; i++) {
  		if (content[i] == '\r' && content[i+1] == '\n') {
  		    lineCount++;
  		}
  	    }
  	} else {
  	    lineCount = -1;
  	}
          return lineCount;
      }
  
      public String getContentType() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getContentType();
      }
  
      public boolean isMimeType(String mimeType) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.isMimeType(mimeType);
      }
  
      public String getDisposition() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getDisposition();
      }
  
      public String getEncoding() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getEncoding();
      }
  
      public String getContentID() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getContentID();
      }
  
      public String getContentMD5() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getContentMD5();
      }
  
      public String getDescription() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getDescription();
      }
  
      public String[] getContentLanguage() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getContentLanguage();
      }
  
      public String getMessageID() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getMessageID();
      }
  
      public String getFileName() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getFileName();
      }
  
      public InputStream getInputStream() throws IOException, MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getInputStream();
      }
  
      public DataHandler getDataHandler() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getDataHandler();
      }
  
      public Object getContent() throws IOException, MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getContent();
      }
  
      public String[] getHeader(String name) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getHeader(name);
      }
  
      public String getHeader(String name, String delimiter) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getHeader(name, delimiter);
      }
  
      public Enumeration getAllHeaders() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getAllHeaders();
      }
  
      public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getMatchingHeaders(names);
      }
  
      public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getNonMatchingHeaders(names);
      }
  
      public Enumeration getAllHeaderLines() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getAllHeaderLines();
      }
  
      public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getMatchingHeaderLines(names);
      }
  
      public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getNonMatchingHeaderLines(names);
      }
  
      public Flags getFlags() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.getFlags();
      }
  
      public boolean isSet(Flags.Flag flag) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          return message.isSet(flag);
      }
  
  
  
  
  
  
  
  
  
  
  
  
  
      /**
       * Various writer methods
       */
      public void setFrom(Address address) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setFrom(address);
      }
  
      public void setFrom() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setFrom();
      }
  
      public void addFrom(Address[] addresses) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.addFrom(addresses);
      }
  
      public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setRecipients(type, addresses);
      }
  
      public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.addRecipients(type, addresses);
      }
  
      public void setReplyTo(Address[] addresses) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setReplyTo(addresses);
      }
  
      public void setSubject(String subject) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setSubject(subject);
      }
  
      public void setSubject(String subject, String charset) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setSubject(subject, charset);
      }
  
      public void setSentDate(Date d) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setSentDate(d);
      }
  
      public void setDisposition(String disposition) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setDisposition(disposition);
      }
  
      public void setContentID(String cid) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setContentID(cid);
      }
  
      public void setContentMD5(String md5) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setContentMD5(md5);
      }
  
      public void setDescription(String description) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setDescription(description);
      }
  
      public void setDescription(String description, String charset) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setDescription(description, charset);
      }
  
      public void setContentLanguage(String[] languages) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setContentLanguage(languages);
      }
  
      public void setFileName(String filename) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setFileName(filename);
      }
  
      public void setDataHandler(DataHandler dh) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setDataHandler(dh);
      }
  
      public void setContent(Object o, String type) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setContent(o, type);
      }
  
      public void setText(String text) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setText(text);
      }
  
      public void setText(String text, String charset) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setText(text, charset);
      }
  
      public void setContent(Multipart mp) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setContent(mp);
      }
  
      public Message reply(boolean replyToAll) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          return message.reply(replyToAll);
      }
  
      public void setHeader(String name, String value) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setHeader(name, value);
      }
  
      public void addHeader(String name, String value) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.addHeader(name, value);
      }
  
      public void removeHeader(String name) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.removeHeader(name);
      }
  
      public void addHeaderLine(String line) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          message.addHeaderLine(line);
      }
  
      public void setFlags(Flags flag, boolean set) throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.setFlags(flag, set);
      }
  
      public void saveChanges() throws MessagingException {
          if (message == null) {
              loadMessage();
          }
          modified = true;
          message.saveChanges();
      }
  
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/JamesMimeMessageInputStream.java
  
  Index: JamesMimeMessageInputStream.java
  ===================================================================
  package org.apache.james.core;
  
  import java.io.*;
  
  public abstract class JamesMimeMessageInputStream extends InputStream {
      InputStream stream = null;
  
      //Loads the underlying input stream...
      protected abstract InputStream openStream() throws IOException;
  
      public int available() throws IOException {
          if (stream == null) {
              return 0;
          } else {
              return stream.available();
          }
      }
  
      public int read() throws IOException {
          if (stream == null) {
              synchronized (this) {
                  if (stream == null) {
                      stream = openStream();
                  } else {
                      //Another thread has already opened this stream
                  }
              }
          }
          return stream.read();
      }
  
      public synchronized void close() throws IOException {
          if (stream != null) {
              stream.close();
          }
          stream = null;
      }
  
      public synchronized void reset() throws IOException {
          close();
      }
  }
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/MailImpl.java
  
  Index: MailImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.core;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.mailet.*;
  
  /**
   * Wrap a MimeMessage adding routing informations (from SMTP) and same simple API.
   * @author Federico Barbieri <scoobie@systemy.it>
   * @author Serge Knystautas <sergek@lokitech.com>
   * @version 0.9
   */
  public class MailImpl implements Mail {
      //We hardcode the serialVersionUID so that from James 1.2 on,
      //  MailImpl will be deserializable (so your mail doesn't get lost)
      public static final long serialVersionUID = -4289663364703986260L;
  
      private String errorMessage;
      private String state;
      private MimeMessage message;
      private MailAddress sender;
      private Collection recipients;
      private String name;
      private String remoteHost = "localhost";
      private String remoteAddr = "127.0.0.1";
      private Date lastUpdated = new Date();
  
      public MailImpl() {
          setState(Mail.DEFAULT);
      }
  
      public MailImpl(String name, MailAddress sender, Collection recipients) {
          this();
          this.name = name;
          this.sender = sender;
          this.recipients = recipients;
      }
  
      public MailImpl(String name, MailAddress sender, Collection recipients, InputStream messageIn)
      throws MessagingException {
          this(name, sender, recipients);
          this.setMessage(messageIn);
      }
  
      public MailImpl(String name, MailAddress sender, Collection recipients, MimeMessage message) {
          this(name, sender, recipients);
          this.setMessage(message);
      }
  
      public void clean() {
          message = null;
      }
  
      public Mail duplicate() {
          try {
              return new MailImpl(name, sender, recipients, getMessage());
          } catch (MessagingException me) {
          }
          return (Mail) null;
      }
  
      public Mail duplicate(String newName) {
          try {
              return new MailImpl(newName, sender, recipients, getMessage());
          } catch (MessagingException me) {
          }
          return (Mail) null;
      }
  
      public String getErrorMessage() {
          return errorMessage;
      }
  
      public MimeMessage getMessage() throws MessagingException {
          return message;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  
      public Collection getRecipients() {
          return recipients;
      }
  
      public MailAddress getSender() {
          return sender;
      }
  
      public String getState() {
          return state;
      }
  
      public String getRemoteHost() {
          return remoteHost;
      }
  
      public String getRemoteAddr() {
          return remoteAddr;
      }
  
      public Date getLastUpdated() {
          return lastUpdated;
      }
  
      private void parse(InputStream messageIn) throws MessagingException {
          if (messageIn != null) {
              message = new EnhancedMimeMessage(Session.getDefaultInstance(System.getProperties(), null), messageIn);
          } else {
  	    throw new MessagingException("Attempt to parse null input stream.");
  	}
      }
  
      /**
       * <p>Return the size of the message including its headers.
       * MimeMessage.getSize() method only returns the size of the
       * message body.</p>
       *
       * <p>Note: this size is not guaranteed to be accurate - see Sun's
       * documentation of MimeMessage.getSize().</p>
       *
       * @return approximate size of full message including headers.
       *
       * @author Stuart Roebuck <stuart.roebuck@adolos.co.uk>
       */
      public int getSize() throws MessagingException {
          //SK: Should probably eventually store this as a locally
          //  maintained value (so we don't have to load and reparse
          //  messages each time).
          int size = message.getSize();
          Enumeration e = message.getAllHeaders();
          while (e.hasMoreElements()) {
              size += ((Header)e.nextElement()).toString().length();
           }
          return size;
       }
  
      private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
          try {
              sender = new MailAddress((String) in.readObject());
          } catch (ParseException pe) {
              throw new IOException("Error parsing sender address: " + pe.getMessage());
          }
          recipients = (Collection) in.readObject();
          state = (String) in.readObject();
          errorMessage = (String) in.readObject();
          name = (String) in.readObject();
          remoteHost = (String) in.readObject();
          remoteAddr = (String) in.readObject();
          lastUpdated = (Date) in.readObject();
      }
  
      public void setErrorMessage(String msg) {
          this.errorMessage = msg;
      }
  
      public void setMessage(InputStream in) throws MessagingException {
          this.message = new JamesMimeMessage(Session.getDefaultInstance(System.getProperties(), null), in);
      }
  
      public void setMessage(MimeMessage message) {
          this.message = message;
      }
  
      public void setRecipients(Collection recipients) {
          this.recipients = recipients;
      }
  
      public void setSender(MailAddress sender) {
          this.sender = sender;
      }
  
      public void setState(String state) {
          this.state = state;
      }
  
      public void setRemoteHost(String remoteHost) {
          this.remoteHost = remoteHost;
      }
  
      public void setRemoteAddr(String remoteAddr) {
          this.remoteAddr = remoteAddr;
      }
  
      public void setLastUpdated(Date lastUpdated) {
          this.lastUpdated = lastUpdated;
      }
  
      public void writeMessageTo(OutputStream out) throws IOException, MessagingException {
          if (message != null) {
              message.writeTo(out);
          } else {
  	    throw new MessagingException("No message set for this MailImpl.");
  	}
      }
  
      private void writeObject(java.io.ObjectOutputStream out) throws IOException {
          //System.err.println("saving object");
          lastUpdated = new Date();
          out.writeObject(sender.toString());
          out.writeObject(recipients);
          out.writeObject(state);
          out.writeObject(errorMessage);
          out.writeObject(name);
          out.writeObject(remoteHost);
          out.writeObject(remoteAddr);
          out.writeObject(lastUpdated);
      }
  
      public Mail bounce(String message) throws MessagingException {
  
          //This sends a message to the james component that is a bounce of the sent message
          MimeMessage original = getMessage();
          MimeMessage reply = (MimeMessage) original.reply(false);
          reply.setSubject("Re: " + original.getSubject());
          Collection recipients = new HashSet();
          recipients.add(getSender());
          InternetAddress addr[] = {new InternetAddress(getSender().toString())};
          reply.setRecipients(Message.RecipientType.TO, addr);
          reply.setFrom(new InternetAddress(getRecipients().iterator().next().toString()));
          reply.setText(message);
          reply.setHeader("Message-Id", "replyTo-" + getName());
  
          return new MailImpl("replyTo-" + getName(), new MailAddress(getRecipients().iterator().next().toString()), recipients, reply);
      }
  
      public void writeContentTo(OutputStream out, int lines)
             throws IOException, MessagingException {
          String line;
          BufferedReader br;
          if(message != null) {
              br = new BufferedReader(new InputStreamReader(message.getInputStream()));
              while(lines-- > 0) {
                  if((line = br.readLine()) == null)  break;
                  line += "\r\n";
                  out.write(line.getBytes());
              }
          } else {
  	    throw new MessagingException("No message set for this MailImpl.");
  	}
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/MailetConfigImpl.java
  
  Index: MailetConfigImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.core;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.mailet.*;
  
  /**
   *
   * @author Serge Knystautas <sergek@lokitech.com>
   */
  public class MailetConfigImpl implements MailetConfig {
      private MailetContext mailetContext;
      private String name;
      //This would probably be better.
      //Properties params = new Properties();
      //Instead, we're tied to the Configuration object
      private Configuration configuration;
  
      public MailetConfigImpl() {
  
      }
  
      public String getInitParameter(String name) {
          try {
              String result = null;
  
              final Configuration[] values = configuration.getChildren( name );
              for ( int i = 0; i < values.length; i++ )
              {
                  if (result == null) {
                      result = "";
                  } else {
                      result += ",";
                  }
                  Configuration conf = values[i];
                  result += conf.getValue();
              }
              return result;
              //return params.getProperty(name);
          } catch (ConfigurationException ce) {
              throw new RuntimeException("Embedded configuration exception was: " + ce.getMessage());
          }
  
      }
  
      public Iterator getInitParameterNames() {
          throw new RuntimeException("Not yet implemented");
          //return params.keySet().iterator();
      }
  
      public MailetContext getMailetContext() {
          return mailetContext;
      }
  
      public void setMailetContext(MailetContext newContext) {
          mailetContext = newContext;
      }
  
      public void setConfiguration(Configuration newConfiguration) {
          configuration = newConfiguration;
      }
  
      public String getMailetName() {
          return name;
      }
  
      public void setMailetName(String newName) {
          name = newName;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/core/MatcherConfigImpl.java
  
  Index: MatcherConfigImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.core;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.mailet.*;
  
  /**
   *
   * @author Serge Knystautas <sergek@lokitech.com>
   */
  public class MatcherConfigImpl implements MatcherConfig {
      private String condition;
      private String name;
      private MailetContext context;
  
      public String getCondition() {
          return condition;
      }
  
      public void setCondition(String newCondition) {
          condition = newCondition;
      }
  
      public String getMatcherName() {
          return name;
      }
  
      public void setMatcherName(String newName) {
          name = newName;
      }
  
      public MailetContext getMailetContext() {
          return context;
      }
  
      public void setMailetContext(MailetContext newContext) {
          context = newContext;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/dnsserver/DNSServer.java
  
  Index: DNSServer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.james.dnsserver;
  
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Comparator;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.Vector;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.james.transport.Resources;
  import org.apache.avalon.phoenix.Block;
  import org.xbill.DNS.*;
  
  /**
   * @version 1.0.0, 18/06/2000
   * @author  Serge Knystautas <sergek@lokitech.com>
   */
  public class DNSServer
      extends AbstractLoggable
      implements Block, Configurable, Initializable, 
      org.apache.james.services.DNSServer {
  
      private Resolver resolver;
      private Cache cache;
      private byte dnsCredibility;
      private Collection servers = new Vector();
  
      public void configure( final Configuration configuration )
          throws ConfigurationException {
  
          // Get this servers that this block will use for lookups
          final Configuration serversConfiguration = configuration.getChild( "servers" );
          final Configuration[] serverConfigurations =
              serversConfiguration.getChildren( "server" );
  
          for ( int i = 0; i < serverConfigurations.length; i++ )
          {
              servers.add( serverConfigurations[ i ].getValue() );
          }
  
          final boolean authoritative =
              configuration.getChild( "authoritative" ).getValueAsBoolean( false );
          dnsCredibility = authoritative ? Credibility.AUTH_ANSWER : Credibility.NONAUTH_ANSWER;
      }
  
      public void initialize()
          throws Exception {
  
          getLogger().info("DNSServer init...");
  
          if (servers.isEmpty()) {
              try {
                  servers.add( InetAddress.getLocalHost().getHostName() );
              } catch ( UnknownHostException ue ) {
                  servers.add( "127.0.0.1" );
              }
          }
  
          for (Iterator i = servers.iterator(); i.hasNext(); ) {
              getLogger().info("DNS Servers is: " + i.next());
          }
  
          //Create the extended resolver...
          final String serversArray[] = (String[])servers.toArray(new String[0]);
          resolver = new ExtendedResolver( serversArray );
  
          cache = new Cache ();
  
          getLogger().info("DNSServer ...init end");
      }
  
      public Collection findMXRecords(String hostname) {
          Record answers[] = rawDNSLookup(hostname, false, Type.MX);
  
          Collection servers = new Vector ();
          try {
              if (answers == null) {
                  return servers;
              }
  
              MXRecord mxAnswers[] = new MXRecord[answers.length];
              for (int i = 0; i < answers.length; i++) {
                  mxAnswers[i] = (MXRecord)answers[i];
              }
  
              Comparator prioritySort = new Comparator () {
                      public int compare (Object a, Object b) {
                          MXRecord ma = (MXRecord)a;
                          MXRecord mb = (MXRecord)b;
                          return ma.getPriority () - mb.getPriority ();
                      }
                  };
  
              Arrays.sort(mxAnswers, prioritySort);
  
              for (int i = 0; i < mxAnswers.length; i++) {
                  servers.add(mxAnswers[i].getTarget ().toString ());
              }
              return servers;
          } finally {
              //If we found no results, we'll add the original domain name if
              //it's a valid DNS entry
              if (servers.size () == 0) {
                  try {
                      InetAddress.getByName(hostname);
                      servers.add(hostname);
                  } catch (UnknownHostException uhe) {
                  }
              }
          }
      }
  
      private Record[] rawDNSLookup(String namestr, boolean querysent, short type) {
          Name name = new Name(namestr);
          short dclass = DClass.IN;
  
          Record [] answers;
          int answerCount = 0, n = 0;
          Enumeration e;
  
          SetResponse cached = cache.lookupRecords(name, type, dclass, dnsCredibility);
          if (cached.isSuccessful()) {
              RRset [] rrsets = cached.answers();
              answerCount = 0;
              for (int i = 0; i < rrsets.length; i++) {
                  answerCount += rrsets[i].size();
              }
  
              answers = new Record[answerCount];
  
              for (int i = 0; i < rrsets.length; i++) {
                  e = rrsets[i].rrs();
                  while (e.hasMoreElements()) {
                      Record r = (Record)e.nextElement();
                      answers[n++] = r;
                  }
              }
          }
          else if (cached.isNegative()) {
              return null;
          }
          else if (querysent) {
              return null;
          }
          else {
              Record question = Record.newRecord(name, type, dclass);
              org.xbill.DNS.Message query = org.xbill.DNS.Message.newQuery(question);
              org.xbill.DNS.Message response;
  
              try {
                  response = resolver.send(query);
              }
              catch (Exception ex) {
                  return null;
              }
  
              short rcode = response.getHeader().getRcode();
              if (rcode == Rcode.NOERROR || rcode == Rcode.NXDOMAIN) {
                  cache.addMessage(response);
              }
  
              if (rcode != Rcode.NOERROR) {
                  return null;
              }
  
              return rawDNSLookup(namestr, true, Type.MX);
          }
  
          return answers;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/dnsserver/DNSServer.xinfo
  
  Index: DNSServer.xinfo
  ===================================================================
  <?xml version="1.0"?>
  
  <blockinfo>
    <services>
      <service name="org.apache.james.services.DNSServer" version="1.0"/>
    </services>
  
    <dependencies>
    </dependencies>  
  </blockinfo>
  
  
  

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


Mime
View raw message