Solved

MIME spec./library wanted

Posted on 2000-02-19
6
159 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now