LOCAL loMail, loRootFolder loMail = CREATEOBJECT( 'sesOutlook' ) IF VARTYPE( loMail ) = 'O' WITH loMail loRootFolder = .oNameSpace.Folders(1) IF .ReadMail( loRootFolder ) SET DATASESSION TO loMail.DataSessionID SELECT SaveMail BROWSE LAST ENDIF ENDWITH ENDIF RETURNHere is the code for the ReadMail() method of the class:
*** The ReadMail Method goes through all the Outlook folders recursively and save all *** of the mailItems to the table OlMail.dbf. If the message has any attachments, *** it then calls the SaveAttachments method to save the attachment as a file on disk and *** insert a record with the name of the file into OlAttach.dbf along with a foreign key *** to the message in OlMail.dbf LOCAL loItems, loItem, loFolders, loFolder *** Get a local referenece to the collection of of items in the current folder loItems = toFolder.Items *** Process all the items in the current folder *** If it is a mail item, save it and process the attachments IF VARTYPE( loItems ) = 'O' FOR EACH loItem IN loItems IF loItem.Class = 43 && olMail *** Add a record to the messages table *** store list of recipients as well lnCount = loItem.Recipients.Count m.lcRecip = '' FOR lnRecip = 1 TO lnCount loRecipient = loItem.Recipients[ lnRecip ] m.lcRecip = m.lcRecip + loRecipient.Name + ': ' + loRecipient.Address + CHR( 13 ) + CHR( 10 ) ENDFOR *** First see if the sender name actually IS an e-mail address IF '@' $ loItem.SenderName m.lcSenderEm2 = loItem.SenderName else if empty(loItem.To) *** don't reply - this is just a draft m.lcSenderEm2 = "Draft" else loReply = loItem.Reply() loRecip = loReply.Recipients[ 1 ] m.lcSenderEm2 = IIF( NOT EMPTY( loRecip.Address ), loRecip.Address, loRecip.Name ) endif ENDIF INSERT INTO SaveMail ( omInDate, omSender, omSubject, omBody, omFolder, omRecip, omSenderEm, omSenderEm2 ) ; VALUES ( loItem.ReceivedTime, loItem.SenderName, loItem.Subject, loItem.Body, toFolder.Name, m.lcRecip, m.lcSenderEm, m.lcSenderEm2 ) *** Now see if we have attachments IF loItem.Attachments.Count > 0 This.SaveAttachments( loItem ) ENDIF ENDIF ENDFOR ENDIF *** Now see if this folder has folders to process IF toFolder.Class = 2 && olFolder loFolders = toFolder.Folders FOR EACH loFolder IN loFolders This.ReadMail( loFolder ) ENDFOR ENDIF RETURN