Table of Contents
24.3.1 Class Mime
The class Mime (gb.mime) provides you with seven constants and two methods.
The methods are necessary because, according to RFC 5322, you may only use characters from the 7-bit ASCII character set for a text e-mail. For all other contents, such as images - in an HTML e-mail or in the attachment - you must, according to RFC 2046 to RFC 2048, specify the coding method used for the characters of a MimeMessage part of the type MimePart in (special) header fields of an e-mail as MimeMessage. This is where the Multipurpose Internet Mail Extensions (MIME) come into play as an extension of the data format for e-mails.
With the two methods
- Decode ( Data As String, Encoding As Integer )
- Encode ( Data As String, Encoding As Integer )
you can use
- encode text or other data to be sent, such as images or archives, into a MimeMessage part of type MimePart or
- decode a MimeMessage part of type MimePart into a text part or a multimedia object.
Use the second parameter 'Encoding' to specify the encoding method to be used → Table 24.3.1.1.
24.3.1.1 Constants
The Mime class has these seven constants for specifying the method by which text is encoded or decoded:
| constant | value | description |
|---|---|---|
| Default | 0 | This constant represents text encoded according to the standard procedure. |
| 7Bit | 1 | This constant represents 7bit coded text (ASCII). |
| 8Bit | 2 | This constant represents 8bit encoded text. |
| Binary | 3 | This constant represents binary coded text. |
| Base64 | 4 | This constant represents text encoded with the Base64 method. |
| QuotedPrintable | 5 | This constant represents text encoded with the QuotedPrintable method. |
| UUEncode | 6 | This constant represents text encoded with the UUEncoding method. |
Table 24.3.1.1 : Constants of the class Mime
Information on the QuotedPrintable and UUEncode encodings can be found here:
24.3.1.2 Methods
The Mime class has only two methods:
| Method | ReturnType | Description |
|---|---|---|
| Decode ( Data As String, Encoding As Integer ) | String | The function decodes the data ('Data') that was originally encoded using the encoding method specified in the 'Encoding' parameter. |
| Encode ( Data As String, Encoding As Integer ) | String | The function encodes the data ('Data') with the encoding method given by the parameter 'Encoding'. |
Table 24.3.1.2.1 : Methods of the class Mime
Notes:
- The 'Encoding' parameter can be any constant from the Mime class → Table 24.3.1.1.1.
- If you use the SMTPClient class to send an email with attachments, then you do not necessarily need to worry about encoding the email message and the attachments (optional). This is done automatically by the Mime class for many Mime types.
- In contrast, displaying an EMail, including the optionally sent attachments, requires parsing the EMail consisting of several parts (→ class MimePart) (→ class MimeMessage).
24.3.1.3 Example text encoding
This is the original text:
Hallo, das Kapitel 24.3.1 Mime (gb.mime) ist abgeschlossen und wurde heute veröffentlicht. Mit flottem Gruß Hans
and here you will find the encodings of the above text in Base64, QuotedPrintable and UUEncode one after the other:
Base64
SGFsbG8sCgpkYXMgS2FwaXRlbCAyNC4zLjEgTWltZSAoZ2IubWltZSkgaXN0IGFiZ2VzY2hsb3Nz ZW4gdW5kIHd1cmRlIGhldXRlIHZlcsO2ZmZlbnRsaWNodC4KCk1pdCBmbG90dGVtIEdydcOfCgpI YW5z
QuotedPrintable
Hallo, das Kapitel 24.3.1 Mime (gb.mime) ist abgeschlossen und wurde heute ver=C3= =B6ffentlicht. Mit flottem Gru=C3=9F Hans
UUEncode
M2&%L;&\L"@ID87,@2V%P:71E;"`R-"XS+C$@36EM92`H9V(N;6EM92D@:7-T
M(&%B9V5S8VAL;W-S96X@=6YD('=U<F1E(&AE=71E('9E<L.V9F9E;G1L:6-H

