Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 105,415 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,852 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Extracting Quoted-Printable from EML File

 
Reply to this topicStart new topic

Extracting Quoted-Printable from EML File

siza
post 2 Jul, 2008 - 03:06 AM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 1

I am trying extract attachments from EML files. I have no issue extracting Bas64 encoded attachments using System.Convert.FromBase64String but when it comes to QP I am stuck. The Attachments tend to be PDF. I have tried encoding a PDF into QP and writing the output to a text file, and then decoding back to a PDF with no success. Has anyone any pointers please ... any help would be greatly appreciated smile.gif

I am using the following two routines which I found on the web
Private Sub cmdEncode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEncode.Click
Dim lReadFS As New FileStream(txtSourceEncode.Text, FileMode.Open)
Dim lSR As New System.IO.StreamReader(lReadFS, System.Text.Encoding.Default, True, _Buffer_size)

Dim lWriteFS As New FileStream(txtDestinationEncode.Text, FileMode.Create)
Dim lSW As New StreamWriter(lWriteFS)

Dim s As String = ""

Dim Line As String = lSR.ReadLine
While Not Line Is Nothing
s = QPEncode(Line.ToCharArray) + vbCrLf
lSW.Write(s)
Line = lSR.ReadLine
End While

lSR.Close()
lSW.Close()
lReadFS.Close()
lWriteFS.Close()
End Sub

Private Sub cmdDecode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDecode.Click
Dim lReadFS As New FileStream(txtSourceDecode.Text, FileMode.Open)
Dim lSR As New System.IO.StreamReader(lReadFS, System.Text.Encoding.Default, True, _Buffer_size)

Dim lWriteFS As New FileStream(txtDestinationDecode.Text, FileMode.Create)
Dim lSW As New StreamWriter(lWriteFS)

Dim s As String = ""

Dim Line As String = lSR.ReadLine
While Not Line Is Nothing
s = QPDecode(Line.ToCharArray) + vbCrLf
lSW.Write(s)
Line = lSR.ReadLine
End While

lSR.Close()
lSW.Close()
lReadFS.Close()
lWriteFS.Close()
End Sub

Private Function QPEncode(ByVal Chars() As Char) As String
Dim i As Integer
Dim Ascii As Integer
Dim EncodedChar As String = ""
Dim ReturnString As New StringBuilder
For i = 0 To Chars.Length - 1
Ascii = Asc(Chars(i))
If Ascii < 32 Or Ascii = 61 Or Ascii > 126 Then
EncodedChar = Hex(Ascii).ToUpper
If EncodedChar.Length = 1 Then EncodedChar = "0" & EncodedChar
ReturnString.Append("=" & EncodedChar)
Else
ReturnString.Append(Chars(i))
End If
Next
Return ReturnString.ToString
End Function

Private Function QPDecode(ByVal Chars() As Char) As String
Dim i As Integer
Dim ReturnString As New StringBuilder
For i = 0 To Chars.Length - 1
If Chars(i) = "=" Then
Dim TheValue As String
If Chars(i + 1) = "0" Then
TheValue = Chars(i + 2)
Else
TheValue = Chars(i + 1) & Chars(i + 2)
End If
Dim IntValue As Integer = Val("&H" & TheValue)
If TheValue = Hex(IntValue) Then
ReturnString.Append(Chr(IntValue))
i += 2
Else
ReturnString.Append(Chars(i))
End If
Else
ReturnString.Append(Chars(i))
End If
Next
Return ReturnString.ToString
End Function


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/20/08 06:02AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month