1#ifndef ZOIDBERG_MAIL_ENCODING_H
2#define ZOIDBERG_MAIL_ENCODING_H
3/* mail encoding - mail de-/encoding functions (base64 and friends)
4**
5** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
6*/
7
8
9#include <size_t.h>
10#include <sys/types.h>
11
12
13#define B_MAIL_NULL_CONVERSION ((uint32) -1)
14#define B_MAIL_UTF8_CONVERSION ((uint32) -2)
15// For specifying the UTF-8 character set when converting to/from UTF-8.
16#define B_MAIL_US_ASCII_CONVERSION ((uint32) -3)
17// Plain 7 bit ASCII character set.  A subset of UTF-8, but some mail software
18// specifies it so we need to recognize it.
19
20#define BASE64_LINELENGTH 76
21
22typedef enum {
23	base64 				= 'b',
24	quoted_printable 	= 'q',
25	seven_bit			= '7',
26	eight_bit			= '8',
27	uuencode			= 'u', // Invalid to encode something using uuencode.
28	null_encoding		= 0,   // For not changing existing settings.
29	no_encoding			= -1
30} mail_encoding;
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36ssize_t encode(mail_encoding encoding, char *out, const char *in,
37	off_t length, int headerMode);
38	// boolean headerMode only matters for quoted_printable and base64.
39ssize_t decode(mail_encoding encoding, char *out, const char *in, off_t length,
40	int underscore_is_space);
41	// the value of underscore_is_space only matters for quoted_printable.
42
43ssize_t max_encoded_length(mail_encoding encoding, off_t cur_length);
44mail_encoding encoding_for_cte(const char *content_transfer_encoding);
45
46ssize_t	encode_base64(char *out, const char *in, off_t length, int headerMode);
47ssize_t	decode_base64(char *out, const char *in, off_t length);
48
49ssize_t	encode_qp(char *out, const char *in, off_t length, int headerMode);
50ssize_t	decode_qp(char *out, const char *in, off_t length, int underscore_is_space);
51	//---underscore_is_space should be 1 if and only if you are decoding a header field
52
53ssize_t	uu_decode(char *out, const char *in, off_t length);
54
55#ifdef __cplusplus
56}
57#endif
58
59#endif	/* ZOIDBERG_MAIL_ENCODING_H */
60