I spent a little bit of time this weekend writing a very simple listserv
servlet, and ran into some problems with the API. The problem I faced
is that servlets can get invoked based on a recipient, and the extra
work a servlet must do if there are multiple recipients. Here's an
example:
Say I'm so proud of the code I've written, I want to send a message to
[EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED] James is the mail server list, which I
am a member of and that should deliver fine. Town is a members-only
list, and I am not a member and that should bounce. Broadcast is a
non-existant listserv.
James, using the conf file, will see [EMAIL PROTECTED] as a
specified recipient and will invoke the MiniListserv (servlet) for that
mailing list. What should this servlet return if 1) the message was
successfully sent to the listserv or 2) it was bounced (invalid sender,
contained an attachment, etc...). Right now, I have to duplicate the
email address of the listserv as a servlet parameter, and try to remove
that email address from the array of recipients in the Mail object.
I don't know what is the best way to handle this as I really like how
the conf file determines the order and routing of messages to servlets,
rather than requiring each servlet to determine this. However, what if
we made the MailServlet's only method return a boolean instead of a Mail
object. Think of it as event handling... the servlet should determine
whether or not it did handle the Mail object (and this event should
die). For a listserv servlet, this would likely always be true, while
for other filtering servlets (like a virus detector) they could
optionally return true or false depending on whether they'd taken
action. The servlet engine could then track whether all recipients of
the message had been handled and trim the list of recipients itself...
after a servlet handling [EMAIL PROTECTED] returned true, the
Mail object would only specify [EMAIL PROTECTED] and
[EMAIL PROTECTED] The next servlet would handle
[EMAIL PROTECTED], and then [EMAIL PROTECTED]
would get all the way through until the server realizes this is an
incorrect address and bounces the message to that address.
Does this get very confusing for the server admin/servlet writer? I
think it would simplify things, although possibly make it difficult to
send a different message out. However, I think you cannot support
returning any Mail object. In my example, if the sender wasn't a member
of [EMAIL PROTECTED] and I returned a "bounce" email saying
you can't send messages to that list, [EMAIL PROTECTED] and
[EMAIL PROTECTED] will never get handled.
I'm not sure the best way to do this, but to enable the
org.apache.james.transport.match to do things like this, you might
include a second method called public Mail filter (Mail mail, String
condition)... the RecipientIs class would then remove recipients
according to the condition, while most Match objects would just return
null (there's no way to "partially" match). Maybe name this "trim"
instead... just an idea. This would only get invoked in the servlet
returned true. This does complicate the Match class some, but it
greatly simplifies servlets, and also means you don't have to specify
the mailing list's address in both the match parameter and as a
parameter to the servlet.
(thanks Jon for letting me use your mail server as an example. ;) )
Serge Knystautas
Loki Technologies
http://www.lokitech.com/
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/>
Problems?: [EMAIL PROTECTED]