> So, it appears that there is no easy way to move a message 
> from one state to another in my given situation (I have 
> messages in a "myqueue" directory, in a myprocessor state and 
> I would like to move it to the spool directory with a root state)

I use the following ToSpoolRepository that allow you to move a mail to a
specified Spool repository and to a specific processor (state).
Consider this code for the latest trunk. You have to probably change the
"Store mailstore = (Store)
compMgr.lookup("org.apache.avalon.cornerstone.services.store.Store");" to
use the MailStore interface and it's own fully qualified service name (IIRC:
org.apache.james.core.MailStore).
MAYBE: "MailStore mailstore = (MailStore)
compMgr.lookup("org.apache.james.core.MailStore");"

public class ToSpoolRepository extends GenericMailet {

  /**
   * The name of the processor to which this mailet forwards mail
   */
  String processor;

  /**
   * The error message to attach to the forwarded message
   */
  String noticeText = null;

  /**
     * The repository where this mailet stores mail.
     */
    private MailRepository repository;

    /**
     * Whether this mailet should allow mails to be processed by additional
mailets
     * or mark it as finished.
     */
    private boolean passThrough = false;

    /**
     * The path to the repository
     */
    private String repositoryPath;

    /**
     * Initialize the mailet, loading configuration information.
     */
    public void init() throws MailetException {
        repositoryPath = getInitParameter("repositoryPath");
        try {
            passThrough = new
Boolean(getInitParameter("passThrough")).booleanValue();
        } catch (Exception e) {
            // Ignore exception, default to false
        }

        ServiceManager compMgr =
(ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_M
ANAGER);
        try {
            Store mailstore = (Store)
compMgr.lookup("org.apache.avalon.cornerstone.services.store.Store");
            DefaultConfiguration mailConf
                = new DefaultConfiguration("repository",
"generated:ToRepository");
            mailConf.setAttribute("destinationURL", repositoryPath);
            mailConf.setAttribute("type", "SPOOL");
            mailConf.setAttribute("CACHEKEYS", getInitParameter("CACHEKEYS")
== null ? "TRUE" : getInitParameter("CACHEKEYS"));
            repository = (MailRepository) mailstore.select(mailConf);
        } catch (ServiceException cnfe) {
            log("Failed to retrieve Store component:" + cnfe.getMessage());
        } catch (Exception e) {
            log("Failed to retrieve Store component:" + e.getMessage());
        }

        processor = getInitParameter("processor");
        noticeText = getInitParameter("notice");

    }

    /**
     * Store a mail in a particular repository.
     *
     * @param mail the mail to process
     */
    public void service(Mail genericmail) throws
javax.mail.MessagingException {
        MailImpl mail = (MailImpl)genericmail;
        StringBuffer logBuffer =
            new StringBuffer(160)
                    .append("Storing mail ")
                    .append(mail.getName())
                    .append(" in ")
                    .append(repositoryPath);
        log(logBuffer.toString());
        String prevState = mail.getState();
        if (processor!=null) mail.setState(processor);
        if (noticeText != null) {
            if (mail.getErrorMessage() == null) {
                mail.setErrorMessage(noticeText);
            } else {
                StringBuffer errorMessageBuffer =
                    new StringBuffer(256)
                            .append(mail.getErrorMessage())
                            .append("\r\n")
                            .append(noticeText);
                mail.setErrorMessage(errorMessageBuffer.toString());
            }
        }
        repository.store(mail);
        if (!passThrough) {
            mail.setState(Mail.GHOST);
        } else {
            mail.setState(prevState);
        }
    }

    /**
     * Return a string describing this mailet.
     *
     * @return a string describing this mailet
     */
    public String getMailetInfo() {
        return "ToSpoolRepository Mailet";
    }
} 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to