I have a question about converting a TYPE_COMPOSITE body item to text. The C API functions that I know of for this purpose are NSFItemConvertToText, NSFItemConvertValueToText, and ConvertItemToText. I was using ConvertItemToText, but it didn’t quite do what I wanted when there were objects (e.g. images) embedded in the body. If there was a JPG embedded in the body then it would return all of the text of the body (before and after the picture). I could deal with this. If, however, there was a BMP embedded in the body then it would only return the text up until the first BMP.
I discovered that when a BMP is embedded in the message, there are actually multiple body items, which makes sense. So, for example, in a simple case there might be three body items, one for the text before the image, one for the image, and one for the text after the image. After I discovered this I was able to change the code to iterate over all the items, convert each to text, and then combine them all for the final body (using NSFItemInfo, NSFItemInfoNext, and NSFItemConvertValueToText).
My main question is if there is a better way to do this. I would like to be able to do something like insert text that tells the recipient that an inline image has been removed. I can sort of do this for the bitmaps (e.g. if the text value is blank then something is missing), but I don’t know how to figure out if a JPG was removed. In a perfect world, I would actually make any embedded images attachments so that the recipient still had access to them, but I don’t know if that’s possible.
Anyone have any ideas?
Thanks,
Schuyler
Subject: Convert body to text using C API
Rather than iterating through items, which is a very high level view, you could iterate through CD records using the NSFItemInfo and NSFItemInfoNext, but also using EnumCompositeBuffer. This would give you every CD record, and you could extract the text from the CDTEXT records and insert your own marks for images, tables, etc. This would be a much more granular approach without being a lot more work.
Subject: RE: Convert body to text using C API
Thanks, Ben, that approach does seem to allow me much greater control without being too much more work. I was even able to pull out JPEGs and GIFs and add them as regular attachments, which was more than I expected to be able to offer this iteration of my plug-in. I have an issue with bitmaps though. When I embed a bitmap, it results in a series of bitmap specific CD records instead of the generic image CD records (e.g. CDBITMAPHEADER, CDBITMAPSEGMENT, CDCOLORTABLE, CDPATTERNTABLE). Because this data is in a Notes proprietary format, I can’t simply dump the data to a file and then attach it. As I see it, I have two options: understand and parse this format and create a regular BMP file, or convert the bitmap to a GIF using ConvertNotesBitmap.
Ultimately, I’d rather preserve the file format of the images, but I’m ok with converting bitmaps to GIFs if it’s easy to do. I’m not sure I understand how to use the bitmap conversion functions though, and I can’t find any examples anywhere. My impression is that I will create a callback routine that does the actual writing of the converted data (e.g. dump to file), and when I call ConvertNotesBitmap it will call my callback as many times as necessary. Before I can call ConvertNotesBitmap, I need to call ConvertNotesBitmapRead to create a context. I pass the CD record to the Read function, and I know I should start by passing the CDBITMAPHEADER record. My main question is, do I call ConvertNotesBitmapRead and then ConvertNotesBitmap for every CD record of the graphic? If it’s going to pass converted bytes to my callback when I call ConvertNotesBitmap, how could it possibly know how to convert the image before it has read things like the pattern table? Instead, am I supposed to call ConvertNotesBitmapRead once for every CD record, and then after the last record call ConvertNotesBitmap once?
Thanks in advance,
Schuyler
Subject: RE: Convert body to text using C API
Actually I can answer my own question this time. It works the way I guessed. You call ConvertNotesBitmapRead for all of the relevant CD records first. Then, after the last bitmap CD record you call ConvertNotesBitmap and it will pass the bytes to your callback.
Schuyler