• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

MIME spec./library wanted

Where can I get the MIME lib. from Internet?

OR

Where can I get the implementation /alogrith information of
MIME ?
0
cstsang
Asked:
cstsang
  • 3
  • 3
1 Solution
 
mcriderCommented:
Here are two funtions that will do Base64 Encoding and Decoding.  They are Base64Encode and Base64Decode.  Open the mime encoded file and read the encoded data into a string and call Base64Decode.  It will an unencoded string.  Write this data to a new file.


By the way, this is worth alot more than 25 points... ;-)



Cheers!


THE CODE:

    Public Function Base64Decode(Source As String) As String
        Dim iVal As Long
        Dim jVal As Long
        Dim kVal As Long
        Dim B64 As Variant
        Dim sIndex As Long
        Dim BinString As String
        Dim Bin As String
        Dim Bch As Integer
        Dim Bstring As String
        Dim Bout As String
       
        sIndex = 0
        B64 = Array("000000", "000001", "000010", "000011", "000100", "000101", "000110", "000111", _
                    "001000", "001001", "001010", "001011", "001100", "001101", "001110", "001111", _
                    "010000", "010001", "010010", "010011", "010100", "010101", "010110", "010111", _
                    "011000", "011001", "011010", "011011", "011100", "011101", "011110", "011111", _
                    "100000", "100001", "100010", "100011", "100100", "100101", "100110", "100111", _
                    "101000", "101001", "101010", "101011", "101100", "101101", "101110", "101111", _
                    "110000", "110001", "110010", "110011", "110100", "110101", "110110", "110111", _
                    "111000", "111001", "111010", "111011", "111100", "111101", "111110", "111111")
        For iVal = 1 To Len(Source) - 1
            Bch = Asc(Mid$(Source, iVal, 1))
            Select Case Bch
                Case 65 To 90:  BinString = BinString + B64(Bch - 65)
                Case 97 To 122: BinString = BinString + B64(Bch - 71)
                Case 48 To 57:  BinString = BinString + B64(Bch + 4)
                Case 43:        BinString = BinString + B64(62)
                Case 47:        BinString = BinString + B64(63)
            End Select
        Next iVal
        Bch = Asc(Right$(Source, 1))
        Select Case Bch
            Case 65 To 90:  Bstring = B64(Bch - 65)
            Case 97 To 122: Bstring = B64(Bch - 71)
            Case 48 To 57:  Bstring = B64(Bch + 4)
            Case 43:        Bstring = B64(62)
            Case 47:        Bstring = B64(63)
        End Select
       
        jVal = 8 - (Len(BinString) Mod 8)
        BinString = BinString + Right$(Bstring, jVal)
        kVal = Len(BinString)
        For jVal = 1 To kVal Step 8
            Bout = Bout + Chr$(BinDec(Mid(BinString, jVal, 8)))
        Next jVal
        Base64Decode = Bout
    End Function
    Public Function Base64Encode(Source As String) As String
        Dim iVal As Long, jVal As Long, kVal As Long, DecVal As Byte
        Dim BinString As String, Temp As String
        Dim B64 As Variant
       
        B64 = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", _
                    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", _
                    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", _
                    "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", _
                    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/")
        For iVal = 1 To Len(Source)
            DecVal = Asc(Mid(Source, iVal, 1))
            For jVal = 7 To 0 Step -1
                If DecVal And (2 ^ jVal) Then
                    BinString = BinString & "1"
                Else
                    BinString = BinString & "0"
                End If
            Next jVal
        Next iVal
        kVal = Len(BinString)
        For jVal = 1 To kVal Step 6
            Temp = Temp & B64(BinDec(Mid(BinString, jVal, 6)))
        Next jVal
    Base64Encode = Temp
    End Function
    Function BinDec(Source As String) As Long
        Dim iVal As Long
        Dim jVal As Long
        Dim kVal As Long
        jVal = 1
        kVal = 0
        For iVal = Len(Source) To 1 Step -1
            If Mid$(Source, iVal, 1) And "1" Then kVal = kVal + jVal
            jVal = jVal * 2
        Next iVal
        BinDec = kVal
    End Function
0
 
cstsangAuthor Commented:
Adjusted points to 125
0
 
cstsangAuthor Commented:
Well!thank you very much.
Whether this code can encode the Chinese?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mcriderCommented:
It doesn't matter... It can encode and decode any file... Text files, JPGs, Gifs, etc...

Thanks for the points! Glad I could help!


Cheers!
0
 
cstsangAuthor Commented:
In fact, I am writing an email program.
Can you tell me the format of email content?
From this time, I have completed the send email part.
However,how can I pack the attachment and the email content together?

thank you very much
0
 
mcriderCommented:
Basically, all you have to do is encode your attachment and send it as part of the body of the message... MIME encoding is alot tricker than UUENCODING... With MIME, you have to deal with putting headers together... If you don't have to support MIME, I wouldn't...


There are a couple of examples here at http://www.planet-source-code.com 

Go to the Visual Basic section and then search for mime


Cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now