lajoiema
asked on
Modifying mail body with Lotus Script
I have a requirement to have a lotus script agent, move the first 5 lines of the mail body to the end of the body.
I have an agent that forwards my e-mails and I would like to format the body for quicker viewing on a PDA.
On some occasions (depending on subject content), I would like to remove the first 5 lines all together.
Here's the code that I'm using:
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim forward As NotesDocument
Dim forwardaddress As String
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
forwardaddress = "recipient@test.com" 'set to the address that you would like
to forward mail to
Set db = s.currentdatabase
Set doc = s.DocumentContext
Set forward = New NotesDocument(db)
Call doc.CopyAllItems(forward, True)
Set rtitem = forward.GetFirstItem( "Body" )
Dim newtext As String
Set rtnav = rtitem.CreateNavigator
Call rtnav.FindFirstElement(RTE LEM_TYPE_T EXTPARAGRA PH) 'navigation element in
order to place header in front of body text
Dim nn As New NotesName(doc.GetItemValue ("From")(0 )) 'determines if this is
an internal message or not
Dim cc As New NotesName(doc.GetItemValue ("CopyTo") (0))
Dim sto As New NotesName(doc.GetItemValue ("SendTo") (0))
'Set up a header that will be attached to the email which specifies additional
info about the original email
Dim testcopy As String
If doc.GetItemValue("CopyTo") (0) = "" Then
testcopy = "no one."
Else
Forall x In doc.GetItemValue("CopyTo")
If testcopy = Null Then
testcopy = x
Else
testcopy = testcopy + x + ", "
End If
End Forall
End If
If nn.IsHierarchical Then 'if it is then get their internet address
If nn.Addr821 <> Null Then 'if they have one then use this as the from
address
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + sto.Addr821 + " and
copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo ")
Call forward.RemoveItem("BlindC opyTo")
Call forward.ReplaceItemValue(" From", nn.Addr821)
Call forward.Save( True, True )
Else
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + sto.Addr821 + " and
copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo ")
Call forward.RemoveItem("BlindC opyTo")
Call forward.ReplaceItemValue(" iNetFrom", nn.Addr821)
Call forward.Save( True, True )
End If 'otherwise if this is an internal message and the internet address of
that user is not populated, use the agent signer's return address
Else
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + doc.GetItemValue
("SendTo")(0) + " and copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo ")
Call forward.RemoveItem("BlindC opyTo")
Call forward.ReplaceItemValue(" iNetFrom", doc.GetItemValue("From")
(0)) 'otherwise this came in from the internet, so just use the from address
as the inetfrom
Call forward.Save( True, True )
End If
forward.Send False, forwardaddress
Call forward.RemovePermanently( True)
End Sub
I have an agent that forwards my e-mails and I would like to format the body for quicker viewing on a PDA.
On some occasions (depending on subject content), I would like to remove the first 5 lines all together.
Here's the code that I'm using:
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim forward As NotesDocument
Dim forwardaddress As String
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
forwardaddress = "recipient@test.com" 'set to the address that you would like
to forward mail to
Set db = s.currentdatabase
Set doc = s.DocumentContext
Set forward = New NotesDocument(db)
Call doc.CopyAllItems(forward, True)
Set rtitem = forward.GetFirstItem( "Body" )
Dim newtext As String
Set rtnav = rtitem.CreateNavigator
Call rtnav.FindFirstElement(RTE
order to place header in front of body text
Dim nn As New NotesName(doc.GetItemValue
an internal message or not
Dim cc As New NotesName(doc.GetItemValue
Dim sto As New NotesName(doc.GetItemValue
'Set up a header that will be attached to the email which specifies additional
info about the original email
Dim testcopy As String
If doc.GetItemValue("CopyTo")
testcopy = "no one."
Else
Forall x In doc.GetItemValue("CopyTo")
If testcopy = Null Then
testcopy = x
Else
testcopy = testcopy + x + ", "
End If
End Forall
End If
If nn.IsHierarchical Then 'if it is then get their internet address
If nn.Addr821 <> Null Then 'if they have one then use this as the from
address
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + sto.Addr821 + " and
copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo
Call forward.RemoveItem("BlindC
Call forward.ReplaceItemValue("
Call forward.Save( True, True )
Else
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + sto.Addr821 + " and
copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo
Call forward.RemoveItem("BlindC
Call forward.ReplaceItemValue("
Call forward.Save( True, True )
End If 'otherwise if this is an internal message and the internet address of
that user is not populated, use the agent signer's return address
Else
Call rtitem.BeginInsert(rtnav)
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendText( "Original message sent to " + doc.GetItemValue
("SendTo")(0) + " and copies were sent to " + testcopy)
Call rtitem.AddNewLine( 3 )
Call rtitem.EndInsert
Call forward.RemoveItem("CopyTo
Call forward.RemoveItem("BlindC
Call forward.ReplaceItemValue("
(0)) 'otherwise this came in from the internet, so just use the from address
as the inetfrom
Call forward.Save( True, True )
End If
forward.Send False, forwardaddress
Call forward.RemovePermanently(
End Sub
ASKER
Depending on the e-mail, we get the following lines at the top of the e-mail:
************************** ********** ********** ********
* Confidential
*
* blah blah ... explains why it's confidential
* blah blah
************************** ********** ********** *********
...
mail text
This forces a lot of scrolling at the top of the message on the PDA.
**************************
* Confidential
*
* blah blah ... explains why it's confidential
* blah blah
**************************
...
mail text
This forces a lot of scrolling at the top of the message on the PDA.
Would it be a problem to discard all text formatting (bold, indents etc?), since it's going to a PDA anyway? If it isn't a problem, then you could use the FormattedText-property of a NotesRichTextItem, search for "*************" followed by newline twice, and delete the part in between them.
Can't you add the disclaimer at the end of the body ?
~Hemanth
~Hemanth
BTW, where is this disclaimer originated from ?
ASKER
The disclaimer is a generic corporate message for sensative e-mails ...
I do not have control on location of disclaimer (out of my league!!!)
sjef bosman: can you show me an example lotus script that would delete an area between 2 lines. I do not care if I loose the formatting ... thanks!
I do not have control on location of disclaimer (out of my league!!!)
sjef bosman: can you show me an example lotus script that would delete an area between 2 lines. I do not care if I loose the formatting ... thanks!
A quicky then, so there may be errors. This section reads the Body item from the original mail, skips two lines with "*********" and copies the rest to the new mail in a normal text-field (it doesn't have to be rich-text):
Dim s As String
Dim pos1 As Integer
Dim pos2 As Integer
Dim x As Integer
Set rtitem= doc.GetFirstItem("Body")
s= rtitem.GetFormattedText
pos1= Instr(s, "********") ' assume 8 is enough
If pos1>0 Then
x= Instr(pos1, s, Chr$(13))
If x<=0 Then Exit Sub ' never happens...
x= Instr(x, s, "********") ' second line
If x>0 Then
pos2= Instr(x, Chr$(13))
If pos2<=0 Then Exit Sub
' if only the text after the disclaimer is required, then pos2 will be enough
Call forward.ReplaceItemValue(" Body", Mid$(s, pos2+1) ' skip the CR
Dim s As String
Dim pos1 As Integer
Dim pos2 As Integer
Dim x As Integer
Set rtitem= doc.GetFirstItem("Body")
s= rtitem.GetFormattedText
pos1= Instr(s, "********") ' assume 8 is enough
If pos1>0 Then
x= Instr(pos1, s, Chr$(13))
If x<=0 Then Exit Sub ' never happens...
x= Instr(x, s, "********") ' second line
If x>0 Then
pos2= Instr(x, Chr$(13))
If pos2<=0 Then Exit Sub
' if only the text after the disclaimer is required, then pos2 will be enough
Call forward.ReplaceItemValue("
ASKER
Do I need to save after the Call forward.ReplaceItemValue(" Body", Mid$(s, pos2+1)?
The problem with "s= rtitem.GetFormattedText" is that I loose the attachments.
Can I do this directly in the rich text body?
The problem with "s= rtitem.GetFormattedText" is that I loose the attachments.
Can I do this directly in the rich text body?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Could you please also define what you mean by a "line", as in "the first 5 lines"?