james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Markus Wiederkehr (JIRA)" <server-...@james.apache.org>
Subject [jira] Commented: (MIME4J-72) Provide a means to dispose a Message
Date Thu, 09 Oct 2008 20:44:44 GMT

    [ https://issues.apache.org/jira/browse/MIME4J-72?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638384#action_12638384

Markus Wiederkehr commented on MIME4J-72:

There are two issues that are somewhat related.

1) With Oleg's version the visitor cannot decide how deep it wants to go into the message
hierarchy. To give you an example let's assume you are interested in processing multipart/mixed
messages but you wish to ignore multipart/alternative or multipart/related. Or assume you
want to process PDF attachments but not in inner (forwarded) messages.

With my implementation the visitor decides whether to visit inner Bodies / Entities or not.
Oleg's version gives the visitor no choice because the traversal is hard-coded into Message
/ Multipart.

2) Regardless of RFC 1521 Message/Multipart/BodyPart/Body is the structure of a Mime4j Message
object. Let's assume you wanted to copy a message. It could be done like this:

class CopyVisitor extends AbstractEntityVisitor {
    private Stack stack = new Stack();

    public void beginMessage(Message message) {
        Message copy = new Message();
        copyHeader(message, copy);

        if (!stack.isEmpty())
            ((Entity) stack.peek()).setBody(copy);

    public void endMessage(Message message) {

    // analogous for Multipart and BodyPart.

    public void visitBody(Body body) {
        // called for all body implementations except Message and Multipart
        Body copy = copyBody(body);
        ((Entity) stack.peek()).setBody(copy);

    private Header copyHeader(Entity source, Entity target) { ... } 
    private Body copyBody(Body body) { ... } 

You could also write visitors that copy certain bodies of a message, remove other bodies or
replace certain bodies with post-processed versions.

Of course this could also be done with a visitor that distinguishes between Entity and Body
alone. But it would require a lot more is-instanceof checks..

> Provide a means to dispose a Message
> ------------------------------------
>                 Key: MIME4J-72
>                 URL: https://issues.apache.org/jira/browse/MIME4J-72
>             Project: JAMES Mime4j
>          Issue Type: Improvement
>    Affects Versions: 0.5
>            Reporter: Markus Wiederkehr
>            Assignee: Robert Burrell Donkin
>         Attachments: entityvisitor.patch, mime4j-disposable.patch, mime4j-dispose-finalize.patch,
mime4j-dispose-no-clutter.patch, mime4j-dispose-visitor.patch
> Currently an org.apache.james.mime4j.message.Message uses temporary files to store text
and binary attachments of the message. Unfortunately a Message cannot be disposed of explicitly.
Even when it eventually gets garbage collected the temp files continue to exist until the
VM exits.
> If the VM runs for a long time and a lot of e-mails get processed this can become a major
> For this reason I think that class Entity and interface Body should both have a method
to dispose of the object. Multipart should dispatch a dispose-call to its list of body parts.
A BodyPart should dispose of its body and concrete Body implementation such as TempFileTextBody
should ultimately invoke delete() on the backing TempFile.
> Last but not least SimpleTempStorage$SimpleTempFile should not silently ignore delete-calls.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org

View raw message