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

    MailListener api

    Rudi Vankeirsbilck Newbie

      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?