Loading...
Searching...
No Matches
Macros | Enumerations | Functions
mail_encoding.h File Reference

Provides tools to convert data to or from a content encoding format. More...

Macros

#define B_MAIL_NULL_CONVERSION   ((uint32) -1)
 Do not specify a character set for converting, rely on autodetection instead.
 
#define B_MAIL_US_ASCII_CONVERSION   ((uint32) -3)
 Specifies the 7bit ASCII character set (a subset of UTF-8) when converting from or to 7bit.
 
#define B_MAIL_UTF8_CONVERSION   ((uint32) -2)
 Specifies the UTF-8 character set when converting from or to UTF-8.
 

Enumerations

enum  mail_encoding {
  base64 = 'b' ,
  quoted_printable = 'q' ,
  seven_bit = '7' ,
  eight_bit = '8' ,
  uuencode = 'u' ,
  null_encoding = 0 ,
  no_encoding = -1
}
 

Functions

ssize_t decode (mail_encoding encoding, char *out, const char *in, off_t length, int underscore_is_space)
 Decodes data from a certain encoding.
 
ssize_t decode_base64 (char *out, const char *in, off_t length)
 Decodes a base64 data buffer.
 
ssize_t decode_qp (char *out, const char *in, off_t length, int underscore_is_space)
 Decodes a quoted-printable data buffer.
 
ssize_t encode (mail_encoding encoding, char *out, const char *in, off_t length, int headerMode)
 Encodes data to a content encoding.
 
ssize_t encode_base64 (char *out, const char *in, off_t length, int headerMode)
 Encodes a string to base64.
 
ssize_t encode_qp (char *out, const char *in, off_t length, int headerMode)
 Encodes an input data to quoted-printable.
 
mail_encoding encoding_for_cte (const char *content_transfer_encoding)
 Returns a mail_encoding value for the content_transfer_encoding string.
 
ssize_t max_encoded_length (mail_encoding encoding, off_t cur_length)
 Returns the output size of a certain encoding, given an input data has cur_length of length.
 
ssize_t uu_decode (char *out, const char *in, off_t length)
 Decodes a uuencoded data buffer.
 

Detailed Description

Provides tools to convert data to or from a content encoding format.

The "7bit" and "8bit" encodings do not perform a binary-to-text conversion but copy the input data into an output buffer. "base64" and "quoted-printable" are as defined in RFC 2045. "uuencode" content format is as defined in the POSIX specification.

Macro Definition Documentation

◆ B_MAIL_NULL_CONVERSION

#define B_MAIL_NULL_CONVERSION   ((uint32) -1)

Do not specify a character set for converting, rely on autodetection instead.

Since
Haiku R1

◆ B_MAIL_US_ASCII_CONVERSION

#define B_MAIL_US_ASCII_CONVERSION   ((uint32) -3)

Specifies the 7bit ASCII character set (a subset of UTF-8) when converting from or to 7bit.

Since
Haiku R1

◆ B_MAIL_UTF8_CONVERSION

#define B_MAIL_UTF8_CONVERSION   ((uint32) -2)

Specifies the UTF-8 character set when converting from or to UTF-8.

Since
Haiku R1

Enumeration Type Documentation

◆ mail_encoding

Enumerator
base64 

Base64 binary-to-text encoding.

Since
Haiku R1
quoted_printable 

quoted-printable binary-to-text encoding.

Since
Haiku R1
seven_bit 

7bit encoding.

Since
Haiku R1
eight_bit 

8bit encoding.

Since
Haiku R1
uuencode 

uuencode binary-to-text encoding.

Since
Haiku R1
null_encoding 

Used to indicate the encoding, will not be changed.

Since
Haiku R1
no_encoding 

Represents an undefined encoding or no encoding at all.

Since
Haiku R1

Function Documentation

◆ decode()

ssize_t decode ( mail_encoding  encoding,
char *  out,
const char *  in,
off_t  length,
int  underscore_is_space 
)

Decodes data from a certain encoding.

Takes an input data in of length bytes and converts it back from encoding to its unencoded form into out.

This wrapper function can be used to convert an input data in base64, quoted-printable or uuencoding formats to its original form. However, if encoding is not recognized, it will not perform any operation and will return -1. On the other hand, if encoding is equal to seven_bit, eight_bit or no_encoding, it will just make a copy of the data.

underscore_is_space is only useful when converting from quoted-printable encoding, when the data is going to be decoded from a header field.

Parameters
[in]encodingInput data's encoding.
[out]outWhere the resulting data will be written to.
[in]inInput data.
[in]lengthInput data's length.
[in]underscore_is_spaceShould be equal to 1 to indicate when decoding a header field.
Returns
The amount of bytes written, or -1 if the encoding is not compatible nor recognized.
Since
Haiku R1

◆ decode_base64()

ssize_t decode_base64 ( char *  out,
const char *  in,
off_t  length 
)

Decodes a base64 data buffer.

Takes an input data in encoded in base64 of length bytes and converts it back to its unencoded form into out.

Parameters
[out]outWhere the output data will be written to.
[in]inInput data.
[in]lengthInput data's length.
Returns
The amount of bytes written.
Since
Haiku R1

◆ decode_qp()

ssize_t decode_qp ( char *  out,
const char *  in,
off_t  length,
int  underscore_is_space 
)

Decodes a quoted-printable data buffer.

Takes an input data in encoded in quoted-printable of length bytes and converts it back to its unencoded form into out.

Parameters
[out]outWhere the output data will be written to.
[in]inInput data.
[in]lengthInput data's length.
[in]underscore_is_spaceShould be equal to 1 to indicate when decoding a header field.
Returns
The amount of bytes written.
Since
Haiku R1

◆ encode()

ssize_t encode ( mail_encoding  encoding,
char *  out,
const char *  in,
off_t  length,
int  headerMode 
)

Encodes data to a content encoding.

Converts an arbitrary input data in of length bytes as encoding into out.

This wrapper function can be used to convert to base64 or quoted-printable, or in the case of using 7bit, 8bit or no_encoding, to copy the data from in to out. However, it is unable to convert the data to uuencode.

headerMode is used when the output will be used in a header, and is only used for conversions to quoted-printable or base64, ignored otherwise.

Parameters
[in]encodingTarget encoding.
[out]outWhere the output data will be written to.
[in]inInput data.
[in]lengthInput data's length.
[in]headerModeWhether the output data will be used in a header or not.
Returns
The amount of bytes written, or -1 if the encoding is not compatible nor recognized.
Since
Haiku R1

◆ encode_base64()

ssize_t encode_base64 ( char *  out,
const char *  in,
off_t  length,
int  headerMode 
)

Encodes a string to base64.

Converts an input data in of length bytes as base64 into out.

headerMode is used when the output will be used in a header, where there should not be any line breaks.

Parameters
[out]outWhere the resulting data will be written to.
[in]inInput data.
[in]lengthInput data's length.
[in]headerModeWhether the output data will be used in a header or not.
Returns
The amount of bytes written.
Since
Haiku R1

◆ encode_qp()

ssize_t encode_qp ( char *  out,
const char *  in,
off_t  length,
int  headerMode 
)

Encodes an input data to quoted-printable.

Converts an input data in of length bytes as quoted-printable into out.

headerMode is used when the output will be used in a header, where there should not be any line breaks.

Parameters
[out]outWhere the output data will be written to.
[in]inInput data.
[in]lengthInput data's length.
[in]headerModeWhether the output data will be used in a header or not.
Returns
The amount of bytes written.
Since
Haiku R1

◆ encoding_for_cte()

mail_encoding encoding_for_cte ( const char *  content_transfer_encoding)

Returns a mail_encoding value for the content_transfer_encoding string.

Parameters
[in]content_transfer_encodingA string with the name of the encoding:
- "uuencode" for mail_encoding::uuencode
- "base64" for mail_encoding::base64
- "quoted-printable" for mail_encoding::quoted_printable
- "7bit" for mail_encoding::seven_bit
- "8bit" for mail_encoding::eight_bit
- Other strings or if content_transfer_encoding is NULL return mail_encoding::no_encoding
Returns
A mail_encoding value.
Since
Haiku R1

◆ max_encoded_length()

ssize_t max_encoded_length ( mail_encoding  encoding,
off_t  cur_length 
)

Returns the output size of a certain encoding, given an input data has cur_length of length.

It can perform the calculation for base64, quoted-printable, 7bit and 8bit. If encoding is equal to no_encoding, it will just return the same value as cur_length. However, this function cannot perform the calculation for uuencode.

Parameters
[in]encodingThe target encoding.
[in]cur_lengthThe input data's length.
Returns
The amount of bytes the conversion to encoding will take if the input data is of cur_length, or -1 if the encoding is not compatible nor recognized.
Since
Haiku R1

◆ uu_decode()

ssize_t uu_decode ( char *  out,
const char *  in,
off_t  length 
)

Decodes a uuencoded data buffer.

Takes an input data in encoded in uuencode of length bytes and converts it back to its unencoded form into out.

Parameters
[out]outWhere the output data will be written to.
[in]inInput data.
[in]lengthInput data's length.
Returns
The amount of bytes written.
Since
Haiku R1