Results 1 to 6 of 6

Thread: Is there any VB6 tools or library for parsing eml files?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    112

    Is there any VB6 tools or library for parsing eml files?

    As the title.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,481

    Re: Is there any VB6 tools or library for parsing eml files?

    You mean as an email saved to disk?

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,880

    Re: Is there any VB6 tools or library for parsing eml files?

    Which "eml" files? Many file extensions get reused by different software for different formats.

    CDO for Windows can create and work with one format.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,880

    Re: Is there any VB6 tools or library for parsing eml files?

    Example:

    Code:
    Option Explicit
    '
    'For Windows 2000 or later. Requires a reference to:
    '
    '   Microsoft CDO For Windows Library
    '   Microsoft ActiveX Data Objects 2.5 Library
    '   tom (Text Object Model in RICHED20.dll)
    '
    'RichTextBox1: MultiLine = True, ScrollBars = rtfBoth
    '
    
    Private Const WM_USER As Long = &H400&
    Private Const EM_GETOLEINTERFACE As Long = WM_USER + 60
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private TextDocument As tom.ITextDocument
    
    Private Sub Dump(ByRef Name As String, ByRef Value As String)
        With TextDocument.Selection
            .Font.Bold = tomTrue
            .Text = Name & vbNewLine
            .Move tomParagraph, 1
            .Font.Bold = tomFalse
            .Para.SetIndents 0, 10, 10
            .Text = Value & vbNewLine
            .Move tomParagraph, 1
            .Para.SetIndents 0, 0, 0
        End With
    End Sub
    
    Private Sub Form_Load()
        Dim IUnknown As stdole.IUnknown
        Dim Message As CDO.Message
        Dim Stream As ADODB.Stream
    
        SendMessage RichTextBox1.hWnd, EM_GETOLEINTERFACE, 0, VarPtr(IUnknown)
        Set TextDocument = IUnknown
        Set Message = New CDO.Message
        Set Stream = New ADODB.Stream
        With Stream
            .Open
            .LoadFromFile "draft.eml"
            .Type = adTypeText
            .Charset = "us-ascii"
            Message.DataSource.OpenObject Stream, "_Stream"
            .Close
        End With
        'Clear any text present:
        With TextDocument.Selection
            .Expand tomStory
            .Delete tomCharacter, 0
        End With
        With Message
            Dump "From", .From
            Dump "To", .To
            Dump "Subject", .Subject
            Dump "TextBody", .TextBody
            Dump "Attachments.Count", CStr(.Attachments.Count)
        End With
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    112

    Re: Is there any VB6 tools or library for parsing eml files?

    Quote Originally Posted by Arnoutdv View Post
    You mean as an email saved to disk?
    Yes.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    112

    Re: Is there any VB6 tools or library for parsing eml files?

    Quote Originally Posted by dilettante View Post
    Example:

    Code:
    Option Explicit
    '
    'For Windows 2000 or later. Requires a reference to:
    '
    '   Microsoft CDO For Windows Library
    '   Microsoft ActiveX Data Objects 2.5 Library
    '   tom (Text Object Model in RICHED20.dll)
    '
    'RichTextBox1: MultiLine = True, ScrollBars = rtfBoth
    '
    
    Private Const WM_USER As Long = &H400&
    Private Const EM_GETOLEINTERFACE As Long = WM_USER + 60
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private TextDocument As tom.ITextDocument
    
    Private Sub Dump(ByRef Name As String, ByRef Value As String)
        With TextDocument.Selection
            .Font.Bold = tomTrue
            .Text = Name & vbNewLine
            .Move tomParagraph, 1
            .Font.Bold = tomFalse
            .Para.SetIndents 0, 10, 10
            .Text = Value & vbNewLine
            .Move tomParagraph, 1
            .Para.SetIndents 0, 0, 0
        End With
    End Sub
    
    Private Sub Form_Load()
        Dim IUnknown As stdole.IUnknown
        Dim Message As CDO.Message
        Dim Stream As ADODB.Stream
    
        SendMessage RichTextBox1.hWnd, EM_GETOLEINTERFACE, 0, VarPtr(IUnknown)
        Set TextDocument = IUnknown
        Set Message = New CDO.Message
        Set Stream = New ADODB.Stream
        With Stream
            .Open
            .LoadFromFile "draft.eml"
            .Type = adTypeText
            .Charset = "us-ascii"
            Message.DataSource.OpenObject Stream, "_Stream"
            .Close
        End With
        'Clear any text present:
        With TextDocument.Selection
            .Expand tomStory
            .Delete tomCharacter, 0
        End With
        With Message
            Dump "From", .From
            Dump "To", .To
            Dump "Subject", .Subject
            Dump "TextBody", .TextBody
            Dump "Attachments.Count", CStr(.Attachments.Count)
        End With
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            RichTextBox1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    Thank you. Dilettante. I will try the code.

    Basically it's just text files. I could just use regex. But I am thinking if there is something more standard to use for eml(email) files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width