#6412
Support 2
Moderator

Below is some example source code which will copy selected message info to clipboard or to a file. You will need to edit the code to change modes, for example set the COPY_TO_CLIPBOARD value to the following features:

A) TRUE = Copy to clipboard
B) FALSE = Save to a file

code:


'--------------------------------------------------------------------------------

Const CAPTION = "Formativ Business Solutions"
HRT = Chr(13) & Chr(10)

'--------------------------------------------------------------------------------
' Main Line processing
'--------------------------------------------------------------------------------
Sub Main(Client, GWEvent)

dim messageList

' Change the value to (TRUE = Copy to clipboard, FALSE = Save to a file)
Const COPY_TO_CLIPBOARD = TRUE
set messageList = Utilities.StringList

On Error Resume Next
' If we selected more then one messages
If Client.ClientState.SelectedMessages.Count > 1 then
for x = 1 to Client.ClientState.SelectedMessages.Count
Set iMsg = Client.ClientState.SelectedMessages.Item(x)
call ExtractMessageInfo(messageList, iMsg)
set iMsg = Nothing
next
Else
' If only one message selected
Set iMsg = Client.ClientState.CommandMessage
If iMsg is Nothing then
call MsgBox ("Message(s) not selected.", 64, CAPTION)
exit sub
Else
call ExtractMessageInfo(messageList, iMsg)
End If
End If


' Copy the messages details into clipboard
if COPY_TO_CLIPBOARD then
CopyToClipboard(messageList)
else
SaveInToFile(messageList)
end if

set iMsg = nothing
set messageList = nothing
End Sub

'--------------------------------------------------------------------------------
' Extract message details and store in a string list
'--------------------------------------------------------------------------------
Sub ExtractMessageInfo(messageList, iMsg)

with messageList
.Add(iMsg.Subject & HRT & iMsg.Sender.DisplayName & HRT & iMsg.Sender.EmailAddress & HRT &_
iMsg.CreationDate & HRT & iMsg.BodyText)
end with

End Sub

'--------------------------------------------------------------------------------
' Copy to clipbord
' Note: You can use Utilities.FromClipBoard to get the value from the clipboard.
'--------------------------------------------------------------------------------
Sub CopyToClipboard(messageList)

Utilities.ToClipBoard(messageList.Text)
call MsgBox ("Messages details copied to clipboard.", 64, CAPTION)

End Sub

'--------------------------------------------------------------------------------
' Save into a file
' Create a text file in the formativ default data folder and write the details in.
'--------------------------------------------------------------------------------
Sub SaveInToFile(messageList)

dim iFSO

FILE_NAME = Utilities.GetDataDirectory & "Test.txt"

Set iFSO = CreateObject("Scripting.FileSystemObject")
Call iFSO.CreateTextFile(FILE_NAME, True)
call Utilities.SaveStringToFile(messageList.Text, FILE_NAME, TRUE)

set iFSO = nothing

call MsgBox (FILE_NAME & " - file created.", 64, CAPTION)

End Sub


I hope this helps and let us know if you have any further questions.

Regards,

Advansys Support