Reliably remove a MIMEEntity

114 Views Asked by At

I have a Document in which I must create a new MIMEEntity (a field) filled with binary content. I use

MIMEEntity mimeE = doc.getMIMEEntity(fieldName);

to create it. Of course, when I repeat this with an existing document where the item is already in, I get the error that the item already exists when I save the document.

The MIMEEntity has a child entity, so my approach was to remove then prior to remove the item (which won't work and solve my problem in general);

if (mimeE != null) {
            MIMEEntity child = mimeE.getFirstChildEntity();
            while(child!=null){
                MIMEEntity ent = child.getNextEntity();
                child.remove();
                child.recycle();
                child = ent;
            }
            mimeE.remove();
            mimeE.recycle();
            doc.removeItem(fieldName);
        }

The line where I finally remove the item itself crashed the server. I have no idea how to entirely remove that item (MIME) just to fulfill Domino's needs when I create a "new" one/replacing the old one with new content).

Any best pratices for this would be appreciated.

1

There are 1 best solutions below

0
On

I found a way to securely remove my item with this:

MIMEEntity mimeE = doc.getMIMEEntity(fieldName);
        if (mimeE != null) {
            MIMEEntity mime = mimeE.getFirstChildEntity();
            if (mime != null) {
                mime.remove();
            }
        } else {
            mimeE = doc.createMIMEEntity(fieldName);
        }

        MIMEEntity mime = mimeE.createChildEntity();

Not sure if this will work in every situation though.