?
Solved

Domino C API - replacing file objects

Posted on 2005-03-07
16
Medium Priority
?
1,054 Views
Last Modified: 2013-12-18
I'm working on an email extension for domino (libXXX.so and nXXX.dll plugin) that uses the "Lotus C API Notes/Domino 6.5" (http://www-12.lotus.com/ldd/doc/tools/c/6.5/api65ref.nsf) to mess with incoming emails (individual nsf objects - using strange functions like OSLockObject() and NSFDbReallocObject() ).

Sometimes I want to quarantine attachments, replacing the attachment with a text file (a short quarantine notice).
I can do this in (at least) 2 ways:
1) remove the attachment, and add a new one.
2) replace the attachment with the text from my text file, and modify the mime info
 
The problem with using 1) is that the old entry is removed, so when I search for the next attachment  (using NSFItemInfoNext(), the entry point is not found and ERR_ITEM_NOT_FOUND is returned - meaning that none of the remaining attachments are found).
The problem with using 2) is that I have to change the mime info and the reallocate the FILEOBJECT stuff (different length name and stuff like that). That seems to be almost impossible*.

*) Just about every memory related function in the API has a warning similar to "Calling this routine with a HANDLE that is invalid or out of range will result in a Notes PANIC halt" (a BAD server crash), so this is like programming a mine field...
0
Comment
Question by:bytta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
16 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 13476602
Use method 1), but get first the reference of the next item before removing the attachment.
0
 
LVL 4

Author Comment

by:bytta
ID: 13478264
That seems to work: partially...
-please bear in mind that this is my first month using Domino.

I'm using the syslog to monitor what's going on.
This method adds an unwanted feature - the new attachment is appended, and therefore scanned after the orginals have been scanned (nunecessary and cumbersome).
So - if I send an email with N "blacklisted" attachments, the sever logs 2*N attachments being scanned.

The problem is that the received mail has no attachments (it removes the original attachment and the mime part but the new ones are nowhere to be found - even if they were scanned in my while loop...).
When I'm done I call "NSFNoteUpdate(note_hndl, 0)" and it returns NOERROR, so they should be there...

I've tried updating the note once and twice for each attachment (after adding the file and the new mime part), but the result is the same.
Am I missing some UPDATE_xxx flags - or something basic?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13478716
I have not done email exits in CAPI, only DatabaseDriver DLLs.
But if you now have problems with the appended attachments, then why do you not do the append of the notification attachments AFTER the end of the attachments scan loop?
To be able to remove the unwanted attachments you have to collect them in the scan loop in some array or pointer list, and at the end of the scan loop you can remove them all and add only one attachments with the notification what you have done.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:bytta
ID: 13482296
Good question - I was just being verbose because the new attachments are "missing" from the final email...

I'll probably rewrite the whole loop tomorrow, but this is a rare special case that I don't want to spend too much time on (that's why I called it "an unwanted feature" ;o).

I'm much more concerned about the new attachments not showing up in the final email...
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13484548

I have not understood what exactly is the problem with the approach 2)
Why is not possible to collect the attachment names to a String.
You get the next chain element and remove the unwanted attachments.
And at the end of the loop you look for that String content and append the appropriate notification to the mail Body item.
Or is it not possible to append text to the Body item at that stage and you have to completely recreate the Body item???

0
 
LVL 4

Author Comment

by:bytta
ID: 13485295
The body item is fine and text can be appended. The problem is that it's not as easy as it sounds.

An attachment in an email note consists of 3 parts.
a) the mime part of the body. Relatively easy to change/remove.
b) the actual message. Easy to change/remove
c) A FILEOBJECT reference to the actual message http://www-12.lotus.com/ldd/doc/tools/c/6.5/api65ref.nsf/852561bd0045e8e785255b3c005a57bb/00e500ad009400ac85255ea0006d7859?OpenDocument followed by the filename. If I want to change the length of the filename I _probably_ have to use OSLockBlock(), OSMemRealloc() and all kinds of stuff. Memory in Domino can only be reallocated when the it was allocated with the MEM_GROWABLE flag so I'd rather not mess with it. And I'm really not sure how it should be done - the program must be cross-platform so I can't just hack it to work for me now.

Using methods 1) and 2) above, I always have to change a) and b). For 1) the normal way would be to delete c) (the FILEOBJECT reference) and create a new one pointing to the new document, whereas the normal way for 2) would be to modify the old one.
-- but when I think about it, I can probably "reallocate the hard way" (create a new FILEOBJECT, copy the relevant fields and delete the old one) - the structure of the email will change but I doubt it matters.

I'll probably try to implement that approach for method 2) today and let you know how it works.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13485463
Perhaps I see it easier then it is, but why do you not simply overwrite the $FILE item with null? You can invalidate the attachment anchor and let the attachment inacessible in the document.

Or if you want to save a quarantine copy of the attachment, then call the NSFNoteExtractFile and the NSFNoteDetachFile methods in sequence.

0
 
LVL 4

Author Comment

by:bytta
ID: 13486611
That's what I'm doing...
For method 1) : NSFNoteExtractFile() to get the file, NSFNoteDetachFile() to delete it, NSFDbAllocObject() & NSFItemAppendObject() to add the new notice.
For method 2) : NSFNoteExtractFile() to get the file, NSFDbReallocObject() & NSFdbWriteObject() to replace the file with the new notice.

The only problem is that damn FILEOBJECT (attachment anchor, c)), that points to the physical file ( b) ).
But I'm sure creating a new FILEOBJECT and replacing the attachment (method 2)) is the easiest way to do it - I'm sure it will work.

I'm doing other stuff today but I'll work on this tomorrow - no need to comment until I get the results from that...
0
 
LVL 4

Author Comment

by:bytta
ID: 13507342
I finally got this to work (almost)...

It turns out that I can create a new FILEOBJECT for both methods (it's safer for cross-platform compatibility than reallocating the old FILEOBJECT), so in effect there is no difference between method 1) and 2)...

I used the program "nsf_dump" from the C API samples to see what's going on.

It (probably) explains my problem: "new attachments not showing up in the final email", I think they are not shown because their MIME entry is  after the MIME_PART_EPILOG in the note.
I'll see what happens if I move the MIME_PART_EPILOG to the end of the note on changed emails.


0
 
LVL 4

Author Comment

by:bytta
ID: 13573149
OK
The problem was the MIME_BODY_PART item fields - the ones after MIME_PART_EPILOG cause weird behaviour and give me a 3F:EA error in imap, because "the note is malformed"or something... http://www-10.lotus.com/ldd/r5fixlist.nsf/0/f042f0dca530160785256ca700728e43?OpenDocument

It finally made it work by rewriting the MIME_BODY_PART pointing to the attachment, and moving the MIME_PART_EPILOG to the end of the note.

Zvonko:
Does this deserve a B or C answer rating?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13573205
No points required. You can ask for points refund here:
http://www.experts-exchange.com/Community_Support/

And for grading is my recommendation this: Never give C. Better let delete the question before giving C. If you are disappointed by the expert after several requests for clarification, then you can grade B. Otherwise give A as a sort of saying Thank You. The grading is not more and not less a way to say Thank You for the support given by Experts. The Experts are volunteers offering their free time to support others.

Following help page describes my upper grading strategy slightly differently.
That is because the help page is from the EE platform providers:
http://www.experts-exchange.com/help.jsp#hi73

Cheers,
Zvonko
0
 
LVL 4

Author Comment

by:bytta
ID: 13573550
OK - I put in a request for close.

When I had unlimited points I usually gave:
A for answer or valuable hints to correct answer,
B for some help
C when people spent some time on my question and proposed something that "should work", but doesn't

So in my book you would have been B- or C+, but now I don't have many points so I'm cheap...

But merely explaining the problem to someone pushed me towards the correct way to do it - so thanks for that...


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13573699
That's mostly the solution: trying to explain the problem to somene else.

So we have so far at least three grading strategies: yours, mine and the one from EE ;-)

See you,
Zvonko
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13574363
I have no objections.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13616690
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question