1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2000-2012 Jeffrey Stedfast
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef __GMIME_ENCODINGS_H__
23 #define __GMIME_ENCODINGS_H__
26 #include <sys/types.h>
32 * GMimeContentEncoding:
33 * @GMIME_CONTENT_ENCODING_DEFAULT: Default transfer encoding.
34 * @GMIME_CONTENT_ENCODING_7BIT: 7bit text transfer encoding.
35 * @GMIME_CONTENT_ENCODING_8BIT: 8bit text transfer encoding.
36 * @GMIME_CONTENT_ENCODING_BINARY: Binary transfer encoding.
37 * @GMIME_CONTENT_ENCODING_BASE64: Base64 transfer encoding.
38 * @GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE: Quoted-printable transfer encoding.
39 * @GMIME_CONTENT_ENCODING_UUENCODE: Uuencode transfer encoding.
41 * A Content-Transfer-Encoding enumeration.
44 GMIME_CONTENT_ENCODING_DEFAULT,
45 GMIME_CONTENT_ENCODING_7BIT,
46 GMIME_CONTENT_ENCODING_8BIT,
47 GMIME_CONTENT_ENCODING_BINARY,
48 GMIME_CONTENT_ENCODING_BASE64,
49 GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE,
50 GMIME_CONTENT_ENCODING_UUENCODE
51 } GMimeContentEncoding;
55 * GMimeEncodingConstraint:
56 * @GMIME_ENCODING_CONSTRAINT_7BIT: The stream data must fit within the 7bit ASCII range.
57 * @GMIME_ENCODING_CONSTRAINT_8BIT: The stream data may have bytes with the high bit set, but no null bytes.
58 * @GMIME_ENCODING_CONSTRAINT_BINARY: The stream may contain any binary data.
60 * Used with functions like g_mime_filter_best_encoding() and
61 * g_mime_object_encode() as the 'constraint' argument. These values
62 * provide a means of letting the filter know what the encoding
63 * constraints are for the stream.
66 GMIME_ENCODING_CONSTRAINT_7BIT,
67 GMIME_ENCODING_CONSTRAINT_8BIT,
68 GMIME_ENCODING_CONSTRAINT_BINARY
69 } GMimeEncodingConstraint;
72 GMimeContentEncoding g_mime_content_encoding_from_string (const char *str);
73 const char *g_mime_content_encoding_to_string (GMimeContentEncoding encoding);
77 * GMIME_BASE64_ENCODE_LEN:
78 * @x: Length of the input data to encode
80 * Calculates the maximum number of bytes needed to base64 encode the
81 * full input buffer of length @x.
83 * Returns: the number of output bytes needed to base64 encode an input
86 #define GMIME_BASE64_ENCODE_LEN(x) ((size_t) (((((x) + 2) / 57) * 77) + 77))
90 * GMIME_QP_ENCODE_LEN:
91 * @x: Length of the input data to encode
93 * Calculates the maximum number of bytes needed to encode the full
94 * input buffer of length @x using the quoted-printable encoding.
96 * Returns: the number of output bytes needed to encode an input buffer
97 * of size @x using the quoted-printable encoding.
99 #define GMIME_QP_ENCODE_LEN(x) ((size_t) ((((x) / 24) * 74) + 74))
103 * GMIME_UUENCODE_LEN:
104 * @x: Length of the input data to encode
106 * Calculates the maximum number of bytes needed to uuencode the full
107 * input buffer of length @x.
109 * Returns: the number of output bytes needed to uuencode an input
112 #define GMIME_UUENCODE_LEN(x) ((size_t) (((((x) + 2) / 45) * 62) + 64))
116 * GMIME_UUDECODE_STATE_INIT:
118 * Initial state for the g_mime_encoding_uudecode_step() function.
120 #define GMIME_UUDECODE_STATE_INIT (0)
124 * GMIME_UUDECODE_STATE_BEGIN:
126 * State for the g_mime_encoding_uudecode_step() function, denoting that
127 * the 'begin' line has been found.
129 #define GMIME_UUDECODE_STATE_BEGIN (1 << 16)
133 * GMIME_UUDECODE_STATE_END:
135 * State for the g_mime_encoding_uudecode_step() function, denoting that
136 * the end of the UU encoded block has been found.
138 #define GMIME_UUDECODE_STATE_END (1 << 17)
139 #define GMIME_UUDECODE_STATE_MASK (GMIME_UUDECODE_STATE_BEGIN | GMIME_UUDECODE_STATE_END)
144 * @encoding: the type of encoding
145 * @uubuf: a temporary buffer needed when uuencoding data
146 * @encode: %TRUE if encoding or %FALSE if decoding
147 * @save: saved bytes from the previous step
148 * @state: current encder/decoder state
150 * A context used for encoding or decoding data.
152 typedef struct _GMimeEncoding {
153 GMimeContentEncoding encoding;
154 unsigned char uubuf[60];
161 void g_mime_encoding_init_encode (GMimeEncoding *state, GMimeContentEncoding encoding);
162 void g_mime_encoding_init_decode (GMimeEncoding *state, GMimeContentEncoding encoding);
163 void g_mime_encoding_reset (GMimeEncoding *state);
165 size_t g_mime_encoding_outlen (GMimeEncoding *state, size_t inlen);
167 size_t g_mime_encoding_step (GMimeEncoding *state, const char *inbuf, size_t inlen, char *outbuf);
168 size_t g_mime_encoding_flush (GMimeEncoding *state, const char *inbuf, size_t inlen, char *outbuf);
171 /* do incremental base64 (de/en)coding */
172 size_t g_mime_encoding_base64_decode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
173 size_t g_mime_encoding_base64_encode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
174 size_t g_mime_encoding_base64_encode_close (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
176 /* do incremental uu (de/en)coding */
177 size_t g_mime_encoding_uudecode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
178 size_t g_mime_encoding_uuencode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, unsigned char *uubuf, int *state, guint32 *save);
179 size_t g_mime_encoding_uuencode_close (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, unsigned char *uubuf, int *state, guint32 *save);
181 /* do incremental quoted-printable (de/en)coding */
182 size_t g_mime_encoding_quoted_decode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
183 size_t g_mime_encoding_quoted_encode_step (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
184 size_t g_mime_encoding_quoted_encode_close (const unsigned char *inbuf, size_t inlen, unsigned char *outbuf, int *state, guint32 *save);
189 #endif /* __GMIME_ENCODINGS_H__ */