home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "Module1"
- Dim strdata As String 'variable for included/excluded words
- Dim base64 As String
- Dim counter As Integer 'counts through included/excluded words
- Dim filenam As String 'filename of file to extract
- Dim firstline As String 'each line of .eml file
- Dim appath As String 'application & .eml file path
-
- Private Function Base64Decode(Basein As String) As String
-
- Dim counter As Integer
- Dim Temp As String
- 'For the dec. Tab
- Dim DecodeTable As Variant
- Dim Out(2) As Byte
- Dim inp(3) As Byte
-
- 'DecodeTable holds the decode tab
- DecodeTable = Array("255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "62", "255", "255", "255", "63", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "255", "255", "255", "64", "255", "255", "255", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", _
- "18", "19", "20", "21", "22", "23", "24", "25", "255", "255", "255", "255", "255", "255", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255" _
- , "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255", "255")
- 'Reads 4 Bytes in and decrypt them
-
- For counter = 1 To Len(Basein) Step 4
- '4 Bytes in -> 3 Bytes out
- inp(0) = DecodeTable(Asc(Mid$(Basein, counter, 1)))
- inp(1) = DecodeTable(Asc(Mid$(Basein, counter + 1, 1)))
- inp(2) = DecodeTable(Asc(Mid$(Basein, counter + 2, 1)))
- inp(3) = DecodeTable(Asc(Mid$(Basein, counter + 3, 1)))
- Out(0) = (inp(0) * 4) Or ((inp(1) \ 16) And &H3)
- Out(1) = ((inp(1) And &HF) * 16) Or ((inp(2) \ 4) And &HF)
- Out(2) = ((inp(2) And &H3) * 64) Or inp(3)
- '* look for "=" symbols
-
- If inp(2) = 64 Then
- 'If there are 2 characters left -> 1 binary out
- Out(0) = (inp(0) * 4) Or ((inp(1) \ 16) And &H3)
- Temp = Temp & Chr(Out(0) And &HFF)
- ElseIf inp(3) = 64 Then
- 'If there are 3 characters left -> 2 binaries out
- Out(0) = (inp(0) * 4) Or ((inp(1) \ 16) And &H3)
- Out(1) = ((inp(1) And &HF) * 16) Or ((inp(2) \ 4) And &HF)
- Temp = Temp & Chr(Out(0) And &HFF) & Chr(Out(1) And &HFF)
- Else 'Return three Bytes
- Temp = Temp & Chr(Out(0) And &HFF) & Chr(Out(1) And &HFF) & Chr(Out(2) And &HFF)
- End If
-
- Next
-
- Base64Decode = Temp
-
- End Function
-
-
- Private Sub decode()
-
- 'filenam = Mid(firstline, 8, Len(firstline) - 8) 'get filename of file to extract
- 'Line Input #2, firstline
-
- If filenam = "" Then
- decodeimbed64
- ElseIf base64 = "base64" Then
- decode64
- ElseIf Right(filenam, 4) = ".rtf" Then
- decodeRTF
- ElseIf Right(filenam, 4) = ".txt" Then
- decodeTXT
- Else
- Print #1,
- Print #1, Chr(9) + "file: " + filenam + " NOT extracted"
- Do While Not EOF(2)
- Line Input #2, firstline
- Do Until strdata = "EndofData" 'repeat until all invalid words checked
- getbadwords ' get next invalid word
- If InStr(firstline, strdata) Then Exit Do 'if line includes invalid word then exit loop
- Loop ' round again for next invalid word
- If strdata <> "EndofData" Then Exit Do
- Loop
- strdata = "NextPart"
- Exit Sub
- End If
-
- Close #3
- Print #1,
- Print #1, Chr(9) + "file: " + filenam + " extracted"
- strdata = "NextPart"
- filenam = ""
- base64 = ""
-
- End Sub
-
- Private Sub decode64()
-
- Dim bin64 As String
-
- Open appath + "\" + filenam For Output As #3 'open file to extract to
-
- While Trim(firstline) <> "" 'get rid of blank lines
- Line Input #2, firstline
- Wend
-
- While InStr(firstline, "NextPart") = Not True 'till end of data
- Line Input #2, firstline
- If (Len(firstline) Mod 4) = 0 Then 'line must be a multiple of 4
- bin64 = Base64Decode(firstline) 'call decoder
- Print #3, bin64; 'print decoded data to file
- Else
- Exit Sub
- End If
- Wend
-
- End Sub
-
- Private Sub decodeimbed64()
-
- Dim bin64 As String
-
- While Trim(firstline) <> "" 'get rid of blank lines
- Line Input #2, firstline
- Wend
-
- While InStr(firstline, "NextPart") = Not True 'till end of data
- Line Input #2, firstline
- If (Len(firstline) Mod 4) = 0 Then 'line must be a multiple of 4
- bin64 = Base64Decode(firstline) 'call decoder
- Print #1, bin64; 'print decoded data to file
- Else
- Exit Sub
- End If
- Wend
-
- End Sub
-
- Private Sub decodeRTF()
-
- Open appath + "\" + filenam For Output As #3 'open file to extract to
-
- While Trim(firstline) <> "" 'get rid of blank lines
- Line Input #2, firstline
- Wend
-
- While InStr(firstline, "NextPart") = Not True 'till end of data
- Line Input #2, firstline
- If Right(firstline, 1) = "=" Then
- Print #3, Left(firstline, Len(firstline) - 1);
- ElseIf Len(firstline) < 3 Then
- Print #3, firstline
- ElseIf Len(firstline) > 2 And Mid(firstline, Len(firstline) - 2, 1) = "=" Then
- Print #3, Left(firstline, Len(firstline) - 3);
- ElseIf InStr(firstline, "NextPart") = Not True Then
- Print #3, firstline
- End If
- Wend
-
- End Sub
-
- Private Sub decodeTXT()
-
- Open appath + "\" + filenam For Output As #3 'open file to extract to
-
- While Trim(firstline) <> "" 'get rid of blank lines
- Line Input #2, firstline
- Wend
-
- While InStr(firstline, "NextPart") = Not True 'till end of data
- Line Input #2, firstline
- If InStr(firstline, "NextPart") = Not True Then
- If Right(firstline, 1) = "=" Then
- Print #3, Left(firstline, Len(firstline) - 1)
- Else
- Print #3, firstline
- End If
- End If
- Wend
-
- End Sub
- Private Sub Main()
-
- Dim nextfile As String 'filename of .eml file
- Dim lastline As String 'checks multiple blank lines
- Dim filenum As Integer 'counts messages
-
- appath = App.Path 'sets path
- nextfile = Dir(appath + "\*.eml") 'gets first .eml filename
- strdata = "" 'initialises variable
-
- 'HEADER SECTION
-
- If nextfile <> "" Then
- Open appath + "\EHCNet3.tmp" For Output As #1 'if .eml file present open text file for writing
- Open appath + "\EHCNet3.txt" For Output As #4 'if .eml file present open index file for writing
- form1.Visible = True
- form1.Refresh
- End If
-
- Print #1,
- Print #1, "---------- End of INDEX------------------------------------" 'print mesage divider
- Print #4,
- Print #4, Chr(9) + Chr(9) + "INDEX"
- Print #4,
-
- While nextfile <> "" 'repeat until all .eml files deleted
- filenum = filenum + 1 'start counting messages
- filenam = ""
- base64 = ""
- Print #1,
- Print #1, "Message:" + Str(filenum)
- Print #1,
- Open appath + "\" + nextfile For Input As #2 'open .eml file for reading
- firstline = "firstline" 'initialise variable with dummy value
- Do Until Trim(firstline) = "" 'repeat until end of header section (first blank line)
- Line Input #2, firstline 'get each line
- Do Until strdata = "EndofData" 'repeat until all valid words checked
- getgoodwords 'get next valid word
- If InStr(firstline, strdata) Then 'if line includes word then line may be valid
- If InStr(firstline, "-To:") Or InStr(firstline, "-Date:") Then 'two more to check
- Exit Do 'and exit loop
- Else
- Print #1, firstline 'all ok - print to text file
- If InStr(firstline, "Subject:") Then Print #4, Str(filenum) + "." + Chr(9) + Right(firstline, Len(firstline) - 9)
- Exit Do
- End If
- End If
- Loop 'round again for next valid word
- strdata = "" 'reset variable
- counter = 0 'reset counter
- Loop 'round again for next line
-
- Print #1, 'print blank line then on to...
-
- 'MESSAGE SECTION
-
- lastline = ""
- Do While Not EOF(2) 'repeat until end of file
- Line Input #2, firstline 'get next line
- strdata = "" 'reset variable
- Do Until strdata = "EndofData" 'repeat until all invalid words checked
- getbadwords ' get next invalid word
- If InStr(firstline, strdata) Then Exit Do 'if line includes invalid word then exit loop
- Loop ' round again for next invalid word
- counter = 0 'reset counter
-
- If InStr(firstline, "name=") Then
- filenam = Mid(firstline, InStr(firstline, Chr(34)) + 1, Len(firstline) - InStr(firstline, Chr(34)) - 1)
- While Trim(firstline) <> ""
- Line Input #2, firstline
- If InStr(firstline, "base64") Then base64 = "base64"
- Wend
- decode
- End If
-
- If InStr(firstline, "base64") Then
- base64 = "base64"
- While Trim(firstline) <> ""
- Line Input #2, firstline
- If InStr(firstline, "name=") Then filenam = Mid(firstline, InStr(firstline, Chr(34)) + 1, Len(firstline) - InStr(firstline, Chr(34)) - 1)
- Wend
- decode
- End If
-
- If strdata = "<HTML>" Then 'if next part of message in unsuitable format then...
- Print #1, 'print blank line
- Print #1, Chr(9) + "(HTML following not printed)" 'print message
- Do While Not EOF(2)
- If InStr(firstline, "NextPart") = Not True Then
- Line Input #2, firstline
- Else
- Exit Do
- End If
- Loop
- strdata = "NextPart"
- End If
-
- If Trim(firstline) = "" And Trim(lastline) = "" Then strdata = "dummy" 'checks for second blank line
-
- If strdata = "EndofData" Then 'line valid
- If Right(firstline, 1) = "=" Then firstline = Left(firstline, Len(firstline) - 1) 'get rid of = at end of some lines
- If Right(firstline, 3) = "=20" Then firstline = Left(firstline, Len(firstline) - 3) 'get rid of =20 at end of some lines
- Print #1, Trim(firstline) 'valid word - print line
- lastline = firstline
- End If
-
- Loop
-
- Print #1, 'print blank line
- Print #1, "---------- End of Message" + Str(filenum) + " ------------------------------" 'print mesage divider
-
- Close #2 'close .eml file
-
- Kill appath + "\" + nextfile 'delete .eml file
- nextfile = Dir(appath + "\*.eml") 'get name of next .eml file
-
- Wend 'repeat for next file
-
- Close #1 'close temp file
-
- Open appath + "\EHCNet3.tmp" For Input As #1
- While Not EOF(1)
- Line Input #1, firstline
- Print #4, firstline
- Wend
-
- Close #1, #4
- Kill appath + "\EHCNet3.tmp"
-
- End 'end program
-
- End Sub
-
- Private Sub getgoodwords() 'routine to fetch 'valid' words in header section
-
- Dim alldata As String 'variable to hold all words
- Dim nextcomma As Integer 'variable to hold position of next comma in string
-
- counter = counter + 1 'sets start of search to one past last comma
- alldata = "To:,Cc:,Bcc:,From:,Date:,Subject:,EndofData," 'valid words
- nextcomma = InStr(counter + 1, alldata, ",") 'find position of next comma
- strdata = Mid(alldata, counter, nextcomma - counter) 'use this to find next word
- counter = nextcomma 'set position to search from next time
-
- End Sub
- Private Sub getbadwords() 'routine to fetch 'invalid' words
-
- Dim alldata As String 'as above for 'invalid' words in message section
- Dim nextcomma As Integer
-
- counter = counter + 1
- alldata = "multipart,DOCTYPE,Message-ID:,MIME-Version:,Content-,Status:,charset=,X-Priority,X-MSMail,X-Mailer,X-MimeOLE,NextPart,X-SMF,Multipart,Multi-Part,boundary,--------,multi-part,--- Return,--- Message,<HTML>,EndofData,"
- nextcomma = InStr(counter + 1, alldata, ",")
- strdata = Mid(alldata, counter, nextcomma - counter)
- counter = nextcomma
-
- End Sub
-