Solved

MIME spec./library wanted

Posted on 2000-02-19
6
158 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

13 Experts available now in Live!

Get 1:1 Help Now