3

I'm developing an Lotus Notes plug-in for Notes 8.5.2 that saves the attachments from an eMail to the Harddisk. But when I try to read the attachment names from a Notes document I always get the same string containing the first attachment name + some junk data.

protected Vector<String> getAttachmentNames() throws NotesException,
        IOException {
    Vector<String> attachmentNames = new Vector<String>();
    Item item = null;
    Enumeration<?> itemsEnum = mailDoc.getItems().elements();
    while (itemsEnum.hasMoreElements()) {
        item = (Item) itemsEnum.nextElement();
        if (item.getType() == Item.ATTACHMENT) {
            attachmentNames.add(getAttachmentNameOf(item));
        }
    }
    return attachmentNames;
}

protected String getAttachmentNameOf(Item item) throws NotesException,
        IOException {
    return getAttachmentName(item.getValueString());
}

getAttachmentName only does some string formatting to generate a unique filename.

Trellmor
  • 634
  • 1
  • 7
  • 15

2 Answers2

1

An "attachment" can not only be of the type ATTACHMENT, but also EMBEDDEDOBJECT, ...

Try to find all RichTextItems, get all the EmbeddedObjects from each of these items ( nrt.getEmbeddedObjects()) and then get the name of the embedded object (eo.getName()).

bluish
  • 26,356
  • 27
  • 122
  • 180
leyrer
  • 1,444
  • 7
  • 9
  • Thanks for the tip, but I just found my mistake (I think). I'm doing 3 things: Saving the mail text, saving the mail as an .eml file and saving all attachments. To save the mail as an .eml file I'm converting it to mime `mailDoc.convertToMIME(2);` and write the mime parts to the hard drive. If I export the attachments before converting the mail to mime it works, if i export them afterwards it fails. – Trellmor Jan 31 '12 at 17:47
1

Something to be aware of. MIME attachments are not always recognized as document attachments. So while you can see it in the notes client, you will not be able to programmatically access it.

The following tech note details it more and how to resolve it.

http://www-01.ibm.com/support/docview.wss?rs=463&&uid=swg21219985

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
  • Sounds like my problem, I converted the message to MIME before saving the attachments. Saving the attachments before converting to MIME works. Thanks for the link, something to watch out for. – Trellmor Feb 01 '12 at 08:27