EML export (with Keybd CRTL+SHIFT+S)

It appears that every now and then people are asking about the EML export.I’ve spent the last 2 days researching this on every forum possible and have concluded that I want to try this in Lotusscript with the keybd commands.

I have seen the EML export code that has been floating around for years… it is waaay too involved for me. I also saw a cool class called DXLexporter (again waaay over my head).

I cobbled together the below code which kinda works, I realize that I’m mixing oil and water…I just can’t tell how to get out of this jam.

I think I’m confusing UI with traditional database commands that run in the background. Or possibly my problem is that I’m not shifting ‘focus’ to the opened ‘view’ which my keystrokes are intended for.

If someone can help me out of this jam then I will modify this code snippet to cycle through my entire mail file (5,000 docs) to save each doc to a folder as EML files. I may even get creative and add an index string to the file names so the folder is sortable.

Thanks in advance for any help!

Sub Initialize

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Set db = session.CurrentDatabase

Set collection = db.AllDocuments

Set doc= collection.GetFirstDocument

Set stream = session.CreateStream

For x = 1 To 3 ’ dev test on the first 3 emails

Set uidoc = ws.EditDocument(False,doc)

ws.ViewRefresh

REM Simulate CRTL+SHIFT+S for SaveAs prompt in UI for EML export

keybd_event 17,0,0,0 ’ CRTL

keybd_event 16,0,0,0 ’ SHIFT

keybd_event 83,0,0,0 ’ S

keybd_event 17,0,2,0 ’ CRTL

keybd_event 16,0,2,0 ’ SHIFT

keybd_event 83,0,2,0 ’ S

keybd_event 13,0,0,0 ’ ENTER

keybd_event 13,0,2,0 ’

Set doc= collection.GetNextDocument(doc)

Next

End Sub

Right now this opens three emails in their own views. And on the last email I get the save as box but the ENTER doesn’t appear to fire.

Subject: EML export (with Keybd CRTL+SHIFT+S)

keybd_event isn’t part of Lotusscript, it’s a call to user32.dll (in other words, you’re using raw Win32 system calls). That means that you need to to a Declare Sub to tell Lotusscript where keybd_event lives:

Declare Sub keybd_event Lib “user32.dll” (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer, Byval dwExtraInfo As Integer)

That’s not optional. However, I HIGHLY discourage using this code for anything that’s meant to happen more than once, since all it takes is for an unexpected background notification (or something similar) to happen, and all of a sudden you’ve got a blind monkey hammering away on the keyboard who ain’t gonna quit until he’s hit 15000 keys (including hitting Enter 5000 times in situations where Ctrl+Shift+S does nothing, not even raising an error) no matter what that does.