Link to home
Create AccountLog in
Avatar of JLVarona
JLVarona

asked on

Extract images from Lotus Notes email and move them to a folder

I want to be able to extract embedded images from a Lotus Notes email based on size and be able to move it to a folder within the same database. I have all the logic to extract the embedded objects and is working fine:

            If vNotesDocument.HasEmbedded And vNotesDocument.HasItem("$File") Then

                mobjNotesRichTextItem = vNotesDocument.GetFirstItem("Body")

               For Each Me.mobjNotesEmbeddedObject In mobjNotesRichTextItem.EmbeddedObjects

                    pAttachedFilePath = pAttachedFileDirectory & "\" & pEmbeddedObjectName

                    Call mobjNotesEmbeddedObject.ExtractFile(pAttachedFilePath)

                    'Want to move the extracted image to a folder within this database at this point

                Next

            End If


Thank you in advance.
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Can you explain some more about your question, and what you want to achieve? I get the idea that there is a misunderstanding here: a folder in a Notes database is not the same as a folder on a disk. A Notes folder can contain (references to) Notes documents, but never files. All you can do is store the image file in a newly created document in the same database, and link that document to the folder.

Or do you want to store those images as Design elements??

What's the ultimate goal, why do you want to store images separately?
Avatar of JLVarona
JLVarona

ASKER

Let me explain, there are attached images that I would like to get rid of from emails which I have found to be below 25K in size. Signatures, smileys and so on that are irrelavant to the extraction process that I am doing. The emails and attached documents are been extracted and stored in FileNet storage. Of course we do not want to store there these other images. So the idea is to extract these images and make them available for viewing somehow in a folder in Lotus Notes. This is the easyiest way for the user responsible for this mailbox to review them and keep track of this.

I can drop them to a directory with no problem, but I want to make them available to the user since he/she would not have access to a directory on a server. All this code is been run as a process on the server and scheduled to run every 5 minutes.

I understand what your saying so something along those lines where the images are stored in a newly created document and then a link to that document in a folder I think would work.

Thank you for your help.
Nope, I don't see how that could work. Once you move an image to some other document you cannot show it in the original document, unless you change the design of the database.

But there may be a different solution if you want to conserve disk space on your Domino mail server: activate DAOS. It will move all images files and other attachments from documents to disk, outside the physical database.

If that's not what you want, you could study the way Notes and Domino handle the export to DXL. When a document is exported to DXL, the result is an XML file that represents the whole document, with all its fields.

PS I still don't quite understand your process, what you're exporting, and all that every 5 minutes...
Let me further explain. This process extracts emails from the inbox and stores the body of the email and any attachments to a Storage medium called FileNet. These documents are indexed by claim numbers and all pertinent information for the claim is also made available for later retrieval through another front end called Kwikwork. This is done for legal reasons as I work for an insurance company and all comunications with the customers must be documented. All this code is currently working and in production. I really can't make this any clearer.

Now, I need to eliminate irrelevant images that sometimes come with the email such as small images used as signatures and so on. Not eliminating them causes them to be indexed and stored unecessaraly. I have found that these images are small (under 25k) so using this as my trigger I can eliminate them. But I need to have the user be able to see what has been eliminated. For that I need to drop them in a folder somehow in the same database. So I've been thinking alone the lines of creating an email document to which I can add these images and drop them in a folder. There are two already in place, one containing "Processed" emails where the emails are moved to after uploading and another named "Rejected" for those that do not meet certain criterieas.

So that question becomes, how can I create an email in code and add images to it? With this I can take it from there, thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thank you I will work on that last piece of code, will let you know how that goes. As for the "flaws", I do handle inline images and is why I can not remove all of them and why I've gone with the option to remove only those below 25k. That should take care of images that are not relevant.
The solution was to build a document and attach all the rejected images meeting my criteria which was anything below 7k. I created a method to handle this.

 Public Sub BuildRejectedImageDocument(ByRef vDataRow As DataRow, ByVal vPutInFolder As String)

        Dim pSubstring As String
        Dim pAttachmentPaths As String

        mobjNotesDocument = mobjNotesDatabase.CreateDocument()
        mobjNotesDocument.ReplaceItemValue("Form", "Memo")
        mobjNotesDocument.ReplaceItemValue("SendTo", vDataRow.Item(strcLotusInBoxView.SendToColName))
        mobjNotesDocument.ReplaceItemValue("SendBy", vDataRow.Item(strcLotusInBoxView.FromColName))
        mobjNotesDocument.ReplaceItemValue("Subject", vDataRow.Item(strcLotusInBoxView.SubjectColName))

        Dim mobjNotesRichTextItem As NotesRichTextItem

        mobjNotesRichTextItem = mobjNotesDocument.CreateRichTextItem("Body")

        Call mobjNotesRichTextItem.AppendText("Attached are all the rejected images from this email." & _
                            Environment.NewLine & Environment.NewLine)

        'Comma delimeted paths to attachment files
        If vDataRow.Item(strcLotusInBoxView.AttachmentPathsColName).ToString.Trim <> String.Empty Then

            pAttachmentPaths = vDataRow.Item(strcLotusInBoxView.AttachmentPathsColName)

            For Each pSubstring In pAttachmentPaths.Split(",")

                If pSubstring.Trim <> String.Empty Then
                    Call mobjNotesRichTextItem.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", pSubstring, "Attachment")
                End If

            Next

        End If

        mobjNotesDocument.Save(True, False)
        mobjNotesDocument.PutInFolder("Processed Mail\Rejected Images", True)

    End Sub