4 Replies Latest reply on May 27, 2004 4:00 PM by Andrew Oliver

    Mail Lists and reworking the Mail apis

    Andrew Oliver Master

      So I've got the entity mail list stuff mostly working. There is a minor problem ATM in that it still tries to deliver the mail via the regular mail listener. I needed this to work because I need to get it running for Marc.

      This is actually just a symptom of an evolutionary model. The MailListener interface needs to be reworked. I think that mail listeners should form a chain by default:

      while (i.hasNext()) {
      mailListener = (MailListener)i.next();
      myMail = mailListener.send(myMail);
      if (myMail == null) break; //if the listener didn't leave you anything left to send go out
      }

      Thus the mail listeners *may* change the mails. I feel like the mails shouldn't change so much as the results of their normal getters should change. Meaning I feel like they should *actually* be immutable even if they don't appear such. Though I might be persuaded on that. One possible use case would be a mail merge for instance and I'm not sure such a thing could be easily achieved without a rediculous amount of memory growth. MAybe what I really want is traceability.

      I actually think send should take and return an array. This *could* (but shouldn't) be used for mail lists (shouldn't be cause expansion should happen in another thread).

      The stuff with "envelopedAddress" should go away. Instead we should have Envelope which contains Mail. The mail contains what it says is from/to/etc. The Envelope contains *who* it should actually be sent to. Thus mail listeners should actually take/receieve an array of Envelopes which have .getMail().

      The *other* case where the mails actually ARE immutable (meaning each mail listener ALWAYS gets a copy) should itself be a mail listener. ChainingMailListenerMbean takes mail listeners and clones the mail, sending it to each.

      while (i.hasNext()) {
      mailListener = (MailListener)i.next(); //one of these is the chaining mail listener
      myMail = mailListener.send(myMail);
      if (myMail == null) break; //if the listener didn't leave you anything left to send go out
      }

      ChainingMailListener {
      MailListener[] listeners; // these are not the same listeners in the main loop
      ... (all the mbean and xml wiring...
      public Envelope[] send(Envelope[] env) {
      for (int e = 0; i < env.length; e++) { // we could optimize this and send all to each listener, but you get the idea right?
      for(int l = 0; l < listeners.length; l++) {
      Envelope myEnv = env[e].deepClone();
      MailListener listener = listeners[l];
      listener.send(myEnv);
      }
      }
      }
      }


      All of the goofy wrapped mails we send could go away:

      MailAddress[] to = envelope.getTo();
      MailAddress[] originalTos = envelope.getMail().getTo();

      meaing that the listeners might add/remove/change the tos and so forth to be sent to but the "display" tos and so forth stay in the original mail. For simplicty envelopes shouldn't contain envelopes. Envelopes are not immutable.

      Any other thoughts? Don't leave me to think this stuff up myself! :-)