Domino Code Fragment

Code Name*
Text Exporter
Date*
05/12/2000
Source (or email address if you prefer)*
haughton@ifrc.org
IP address:.193.72.17.82
Description*
Type*
LotusScript
Categories*
File Input/Output
Implementation:
None (plug and play)
Required Client:
(none)
Server:
(none)
Limitations:
None
Comments:
Put this agent in a mail-in database, triggered on "when new mail arrives"
Files/Graphics attachments (if applicable): Code:
Sub Initialize
Sub Initialize event
' Written by David Haughton 14.03.00
On Error Goto Trap
Dim FileLocation As String
Dim FileName As String
Dim FileNum As Integer
Dim Session As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim Doc As Notesdocument

FileLocation="c:\directory\"

Set db = session.currentdatabase
Set view=db.getview("($Inbox)") 'use the inbox view
Set doc=view.getfirstdocument 'set the first doc in the inbox to the current document

While Not doc Is Nothing ' as long as there are doc's in the inbox
FileNum=Freefile
FileName=FileLocation + Format(Now, "YYYY-MM-DD_HH-MM-SS")+".TXT" 'first, create unique text file
Open FileName For Output As FileNum
Print #fileNum, Doc.body; 'write doc's body text to previously created text file
Close FileNum 'save and close
Call doc.PutInFolder("Processed Documents") 'put first document into folder for safe keeping
Call doc.RemoveFromFolder("($Inbox)") 'remove first document from inbox
Set doc=view.getfirstdocument 'set the next first document to the current document, as the previous one has been moved
Sleep(1) 'a one second delay will garantie a unique file name
Wend
Exit Sub
Trap:
Print (Cstr(Err) & " " & Error$)
End
End Sub