Link to home
Start Free TrialLog in
Avatar of chuckalicious
chuckaliciousFlag for United Kingdom of Great Britain and Northern Ireland

asked on

When Forwarding An Email (Memo form)- How Do You Get The Complete Contents Of The Body Field

I am making modifications to the memo form in the Notes mail template.

At the "QuerySend" event, I call a sub which takes the text from the body field and searches it for a particular string.

However, if the email in question is a forward, the text returned is only whatever is above the forwarded message. The text from the original email, which is being forwarded, is not returned by NotesUiDocument.fieldgettext("body").

The problem is that many of our users forward an email, but before sending, hack the email to bits and often type below the "forwarded by...." line. If they do this, I can't search their text as it isn't returned.

I imagine the answer would be to get the backend document and take the body item that way, however, at the point of QuerySend, there is no back document. I do not want to save the source at that point in case the user cancels the send of the email (ie when spellcheck triggers) and then end up not sending it.

I can't do this check in any event triggered after QuerySend because as far as I'm aware, this is my last chance to edit the uidoc contents before it becomes read only.....

I have attached the code, so you can see what I'm doing. The code is the sub that is being called at QuerySend.

The If Instr(1, body...) code is not the problem, because if I use a MsgBox to display the string item "body", it returns anything above the forwarded line.

Using something like notesdocument.fieldcontains("whateverstring") returns false if "whateverstring" is below the forward line.....

If anyone can help me get round this I'd be extremely grateful, I've been at this for ages and have got nowhere!

Would have assigned more points but I have only 75 left. Sorry


Sub ForceSignature(Source As NotesUIDocument)
	Call source.Refresh
	
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Set db = session.CurrentDatabase
	Dim ProfDoc As NotesDocument
	Dim SigString As String
	Dim Body As String
	Body = source.FieldGetText("body")
	Set ProfDoc = db.GetProfileDocument("CalendarProfile")
	SigString = ProfDoc.Signature_3(0)
	
	Call source.GotoField("body")
 
	
		If Instr(1, body, "<<sig>>", 5)>0 Then
			Call source.FindString("<<sig>>",False,False,False, False, False, False, True, True, True)
			Call source.InsertText(SigString)
		End If
	
End Sub

Open in new window

Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

You know that R7 has a built-in Disclaimer feature? Unfortunately it is a system-wide disclaimer, not user-dependent. See Adding a disclaimer to outgoing messages in the Admin Help database:

"You can add a disclaimer to the bottom of outgoing mail messages in Domino Web Access. A disclaimer is a denial or a disavowal of legal responsibility for the contents of the message. In some countries, not having a proper disclaimer on messages may result in fines leveled by regulatory agencies.
To add a disclaimer to an e-mail message, edit the mail server's Configuration Settings document and complete the fields under Disclaimer Text."

And, as you indicated yourself, the only way to fiddle with a rich-text field is to save the document and reopen it. You could save it as a temp. document, do the messy things that need to be done, and then send that temp. document. To delete it, don't call a Remove, but have all temp. documents removed by an agent (with Delete permission!) every night.
Avatar of chuckalicious

ASKER

Im not looking to add a disclaimer, it's a modification of signature manipulation.

So do you think it's not possible to get all the text?
There is the NotesRichTextNavigator object that you can use to scan the text. And you can use NotesRichTextItem.Text but that's probably not what you're looking for. All you want is to insert a signature at some specific place?
The idea is that when an email is composed, a signature "tag line" is inserted where the signature will go. Upon sending, if this tag line is found, a bespoke (non-user configurable) signature is inserted in its place.

It works perfectly well until someone does what I explained in the original post.

As I say, all I want is to get hold of the rest of the text in the body field, or at least confirmation of whether it's possible or not.

Am I correct in thinking that I cannot create a NotesRichTextItem when I only have a handle on the uiDoc?
Maybe the problem is only caused by the Instr(body... Did you ever test if FindString returns a value, for example True when found and False otherwise? There are other functions that used to be poorly documented, so I assume it is possible that there is a return value.
The Instr works fine. I have tried many different things to display what should be the entire contents of the body field, or to search the field, using uidoc.FieldContains and all return false if the string I'm looking for is below the forwarded line.

I have attached an image of the kind of thing I'm working with, which might help me explain the situation:

You can see the tag line "<<sig>>" which is above the forwarded email. The code I included finds this fine. However, if I cut the line out and paste it below the forward line, no code finds this, or any other text. This suggests to me that whatever is below the forwarded line is not in fact part of the body field, or at least not in the normal sense, which the stock Notes methods and functions can find....
image.jpg
If the text is in one rich-text field, the content is in one container with the field's name, so it should be possible to access all text using the one container. On the other hand, Notes handles this a little out of the ordinary: it creates multiple items in the document with the name Body. Normally, moving from one "physical" Body-item to the next is transparent, but there could be issues there.

I had a suggestion to use the method Compact that is available, to set all internal stuff the way it should be, so you can reach the line you need. But it won't help, I think, because your problem is with the form/uidocument, not with the document itself. The FindString does no longer work if

Otherwise, try the NotesRichTextNavigator class, and the FindFirstString method. You won't see the results on the screen, but I suppose that wouldn't matter. There are some good examples in the Help database of how to use FindFirstString.

Thanks, I'll give the navigator a shot.

I'd be interested in knowing (if you have a few minutes) if your Notes install did the same thing when trying to access the body of a new forward when trying to access the forwarded text. That would at least eliminate me making a stupid mistake!
Just a thought, don't I need to have a handle on the notesdocument before I can get a notesrichtextitem, and thus a navigator? This goes back to the original problem of not having access to the notesdocument as the uidoc hasn't been saved.
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bang on! Can't believe I didn't try commenting out the Instr!

Thanks
Heh, that's what I meant with "Maybe the problem is only caused by the Instr(body... ". Ah well, you just have to live with the fact that English is not my mother tongue.

Thanks!! :-))
I did read that bit :) However on closer inspection, it's not the Instr specifically that's causing the issue. The issue is that the string that Instr does its work on does not contain the expected data.

This would suggest that in fact uidoc.fieldgettext is the error point.

To prove this point, take my code, and do something simple like MsgBox(bodystring) where bodystring = uidoc.fieldgettext("body").

You SHOULD find that anything below the forwarded line is not displayed......
Correct.

Discussion on Instr or body or If statement closed, let's say we're both right. LOL