Solved

MIME spec./library wanted

Posted on 2000-02-19
6
161 Views
Last Modified: 2010-05-02
Where can I get the MIME lib. from Internet?

OR

Where can I get the implementation /alogrith information of
MIME ?
0
Comment
Question by:cstsang
  • 3
  • 3
6 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 120 total points
ID: 2537885
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
 
LVL 7

Author Comment

by:cstsang
ID: 2539344
Adjusted points to 125
0
 
LVL 7

Author Comment

by:cstsang
ID: 2539345
Well!thank you very much.
Whether this code can encode the Chinese?

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 14

Expert Comment

by:mcrider
ID: 2539364
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
 
LVL 7

Author Comment

by:cstsang
ID: 2539675
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2539694
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question