1 Reply Latest reply on Oct 5, 2006 1:36 PM by mikezzz

    MailListener api

    rudivankeirsbilck

      I was looking into creating my own MailListener like:

      public class BlueSpaceJBossMailListener extends BlueSpaceMessageDriveBean implements MailListener {
      /* Methods for constructing new instances. */
       public BlueSpaceJBossMailListener () {
       super();
       }
      
      /* Methods that satisfy the MailListener interface. */
       public Message send (Message message) throws MailException {
       Logger.SMAIL.debug("Message received from JBoss Mail Server.");
       Mail mail = (Mail) message;
       Logger.SMAIL.debug("Subject:" + this.getSubject(mail));
       Logger.SMAIL.debug("From:" + mail.getFrom().getRawAddress());
       Logger.SMAIL.debug("Recipients:");
       List<EnvelopedAddress> recipients = mail.getRecipients();
       for (EnvelopedAddress address : recipients) {
       Logger.SMAIL.debug (address.getType().toString() + ':' + address.getRawAddress());
       }
       return message;
       }
      
      /* Keep out! */
      /* Constants */
       /* None at this time. */
      
       protected String getSubject (Mail mail) {
       String[] subjects = mail.getHeader("Subject");
       if (subjects == null || subjects.length == 0) {
       return null;
       }
       else {
       return subjects[0];
       }
       }
      
      /* Class variables */
       /* None at this time. */
      /* Instance variables */
       /* None at this time. */
      }
      


      It's not doing anything usefull yet but anyways...

      I was wondering why a org.jboss.mail.message.Message is being passed in instead of a org.jboss.mail.message.Mail.
      Afterall, the interface is MailListener and not MessageListener and also the Message interface does not have any method so the Listener class has no other option then to cast it to something else.

      This may be splitting hairs but this does not seem like a good API to me.

      Any comments anybody?

        • 1. Re: MailListener api

          The Mail Server APIs have grown a bit organically over time and Message Interface could do with some work. The simplest solution would probably be to add relevant method signatures from the Mail class, to the Message interface.

          Patches are welcome...

          Mike.