Showing posts with label EML. Show all posts
Showing posts with label EML. Show all posts

9/07/2012

Server-side mail export - EML

The issue was: creating a server-side solution for exporting emails to EML file from different mailboxes.
The application has a settings view, where the key user can set up different mail boxes for exporting.
This is cluster ready application.

Settings
Here comes the important part of the code.
function exportEML As Boolean
        On Error GoTo ErrHdl
        Dim fileNum As Integer
        Dim mime As NotesMIMEEntity
        Dim stream As NotesStream
        Dim evalstr As String
        Dim tmp As Variant
        Dim expFileName As String
        Dim mimeType As String
        Dim mimeBoundAryStart As string
        Dim mimeBoundAryEnd As string
        ss.Convertmime = False
       
        fileNum% = FreeFile()
        Set mime = maildoc.GetMIMEentity
        If mime Is Nothing Then
            Call maildoc.ConvertToMIME(3)
            Set mime = maildoc.GetMIMEentity
        End If
        If Not mime Is Nothing Then
            Set stream = ss.Createstream()
            expFileName$ = wDir & "\" & maildoc.Universalid & ".eml"
            ...
            If Dir$(expFileName$) <> "" Then
                Kill expFileName$
            ...
            End If
            Call stream.Open(expFileName$, mime.Charset)
            
...
            mimeType = mime.Contenttype
            mimeBoundAryStart = mime.Boundarystart
            mimeBoundAryEnd = mime.Boundaryend
            Call mime.GetEntityAsText(stream)
            Set mime = mime.GetNextEntity
            While Not mime Is Nothing
                Call stream.Writetext("", 3)
                Call stream.Writetext(mime.BoundAryStart)
                Call mime.DecodeContent()
                Call mime.Encodecontent( 1727 )
                Call mime.GetentityAsText(stream)
                Call stream.Writetext(mime.BoundAryEnd)
                Set mime = mime.GetNextEntity
            Wend
            Call stream.WriteText(mimeBoundAryEnd)
            Call stream.Close()
           
...
            exportEML = True
        Else
            ...
            exportEML = False
        End If
       
ErrHdl:
        If Err Then
            Print "  Error @ " & db.Filename & " (" & db.Title & ") - " & ag.Name & " - 'function exportEml' (" & Err & ") " & Error & " - line: " & Erl
            exportEML = false
            Exit Function
        End If
    End Function