1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2000-2003 Ximian Inc.
5 * Authors: Michael Zucchi <notzed@ximian.com>
6 * Jeffrey Stedfast <fejj@ximian.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #ifndef _CAMEL_MIME_UTILS_H
25 #define _CAMEL_MIME_UTILS_H
30 #endif /* __cplusplus */
35 /* maximum recommended size of a line from camel_header_fold() */
36 #define CAMEL_FOLD_SIZE (77)
37 /* maximum hard size of a line from camel_header_fold() */
38 #define CAMEL_FOLD_MAX_SIZE (998)
40 #define CAMEL_UUDECODE_STATE_INIT (0)
41 #define CAMEL_UUDECODE_STATE_BEGIN (1 << 16)
42 #define CAMEL_UUDECODE_STATE_END (1 << 17)
43 #define CAMEL_UUDECODE_STATE_MASK (CAMEL_UUDECODE_STATE_BEGIN | CAMEL_UUDECODE_STATE_END)
45 /* note, if you change this, make sure you change the 'encodings' array in camel-mime-part.c */
46 typedef enum _CamelTransferEncoding {
47 CAMEL_TRANSFER_ENCODING_DEFAULT,
48 CAMEL_TRANSFER_ENCODING_7BIT,
49 CAMEL_TRANSFER_ENCODING_8BIT,
50 CAMEL_TRANSFER_ENCODING_BASE64,
51 CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE,
52 CAMEL_TRANSFER_ENCODING_BINARY,
53 CAMEL_TRANSFER_ENCODING_UUENCODE,
54 CAMEL_TRANSFER_NUM_ENCODINGS
55 } CamelTransferEncoding;
57 /* a list of references for this message */
58 struct _camel_header_references {
59 struct _camel_header_references *next;
63 struct _camel_header_param {
64 struct _camel_header_param *next;
69 /* describes a content-type */
73 struct _camel_header_param *params;
74 unsigned int refcount;
77 /* a raw rfc822 header */
78 /* the value MUST be US-ASCII */
79 struct _camel_header_raw {
80 struct _camel_header_raw *next;
83 int offset; /* in file, if known */
86 typedef struct _CamelContentDisposition {
88 struct _camel_header_param *params;
89 unsigned int refcount;
90 } CamelContentDisposition;
92 enum _camel_header_address_t {
93 HEADER_ADDRESS_NONE, /* uninitialised */
98 struct _camel_header_address {
99 struct _camel_header_address *next;
100 enum _camel_header_address_t type;
104 struct _camel_header_address *members;
106 unsigned int refcount;
109 /* MUST be called before everything else */
110 void camel_mime_utils_init(void);
113 struct _camel_header_address *camel_header_address_new (void);
114 struct _camel_header_address *camel_header_address_new_name (const char *name, const char *addr);
115 struct _camel_header_address *camel_header_address_new_group (const char *name);
116 void camel_header_address_ref (struct _camel_header_address *);
117 void camel_header_address_unref (struct _camel_header_address *);
118 void camel_header_address_set_name (struct _camel_header_address *, const char *name);
119 void camel_header_address_set_addr (struct _camel_header_address *, const char *addr);
120 void camel_header_address_set_members (struct _camel_header_address *, struct _camel_header_address *group);
121 void camel_header_address_add_member (struct _camel_header_address *, struct _camel_header_address *member);
122 void camel_header_address_list_append_list (struct _camel_header_address **l, struct _camel_header_address **h);
123 void camel_header_address_list_append (struct _camel_header_address **, struct _camel_header_address *);
124 void camel_header_address_list_clear (struct _camel_header_address **);
126 struct _camel_header_address *camel_header_address_decode (const char *in, const char *charset);
127 struct _camel_header_address *camel_header_mailbox_decode (const char *in, const char *charset);
129 char *camel_header_address_list_encode (struct _camel_header_address *a);
131 char *camel_header_address_list_format (struct _camel_header_address *a);
133 /* structured header prameters */
134 struct _camel_header_param *camel_header_param_list_decode (const char *in);
135 char *camel_header_param (struct _camel_header_param *p, const char *name);
136 struct _camel_header_param *camel_header_set_param (struct _camel_header_param **l, const char *name, const char *value);
137 void camel_header_param_list_format_append (GString *out, struct _camel_header_param *p);
138 char *camel_header_param_list_format (struct _camel_header_param *p);
139 void camel_header_param_list_free (struct _camel_header_param *p);
141 /* Content-Type header */
142 CamelContentType *camel_content_type_new (const char *type, const char *subtype);
143 CamelContentType *camel_content_type_decode (const char *in);
144 void camel_content_type_unref (CamelContentType *ct);
145 void camel_content_type_ref (CamelContentType *ct);
146 const char *camel_content_type_param (CamelContentType *t, const char *name);
147 void camel_content_type_set_param (CamelContentType *t, const char *name, const char *value);
148 int camel_content_type_is (CamelContentType *ct, const char *type, const char *subtype);
149 char *camel_content_type_format (CamelContentType *ct);
150 char *camel_content_type_simple (CamelContentType *ct);
152 /* DEBUGGING function */
153 void camel_content_type_dump (CamelContentType *ct);
155 /* Content-Disposition header */
156 CamelContentDisposition *camel_content_disposition_decode (const char *in);
157 void camel_content_disposition_ref (CamelContentDisposition *);
158 void camel_content_disposition_unref (CamelContentDisposition *);
159 char *camel_content_disposition_format (CamelContentDisposition *d);
161 /* decode the contents of a content-encoding header */
162 char *camel_content_transfer_encoding_decode (const char *in);
165 void camel_header_raw_append (struct _camel_header_raw **list, const char *name, const char *value, int offset);
166 void camel_header_raw_append_parse (struct _camel_header_raw **list, const char *header, int offset);
167 const char *camel_header_raw_find (struct _camel_header_raw **list, const char *name, int *offset);
168 const char *camel_header_raw_find_next (struct _camel_header_raw **list, const char *name, int *offset, const char *last);
169 void camel_header_raw_replace (struct _camel_header_raw **list, const char *name, const char *value, int offset);
170 void camel_header_raw_remove (struct _camel_header_raw **list, const char *name);
171 void camel_header_raw_fold (struct _camel_header_raw **list);
172 void camel_header_raw_clear (struct _camel_header_raw **list);
174 char *camel_header_raw_check_mailing_list (struct _camel_header_raw **list);
177 char *camel_header_address_fold (const char *in, size_t headerlen);
178 char *camel_header_fold (const char *in, size_t headerlen);
179 char *camel_header_unfold (const char *in);
181 /* decode a header which is a simple token */
182 char *camel_header_token_decode (const char *in);
184 int camel_header_decode_int (const char **in);
186 /* decode/encode a string type, like a subject line */
187 char *camel_header_decode_string (const char *in, const char *default_charset);
188 char *camel_header_encode_string (const unsigned char *in);
190 /* encode a phrase, like the real name of an address */
191 char *camel_header_encode_phrase (const unsigned char *in);
193 /* decode an email date field into a GMT time, + optional offset */
194 time_t camel_header_decode_date (const char *in, int *saveoffset);
195 char *camel_header_format_date (time_t time, int offset);
197 /* decode a message id */
198 char *camel_header_msgid_decode (const char *in);
199 char *camel_header_contentid_decode (const char *in);
201 /* generate msg id */
202 char *camel_header_msgid_generate (void);
204 /* decode a References or In-Reply-To header */
205 struct _camel_header_references *camel_header_references_inreplyto_decode (const char *in);
206 struct _camel_header_references *camel_header_references_decode (const char *in);
207 void camel_header_references_list_clear (struct _camel_header_references **list);
208 void camel_header_references_list_append_asis (struct _camel_header_references **list, char *ref);
209 int camel_header_references_list_size (struct _camel_header_references **list);
210 struct _camel_header_references *camel_header_references_dup (const struct _camel_header_references *list);
212 /* decode content-location */
213 char *camel_header_location_decode (const char *in);
215 const char *camel_transfer_encoding_to_string (CamelTransferEncoding encoding);
216 CamelTransferEncoding camel_transfer_encoding_from_string (const char *string);
218 /* decode the mime-type header */
219 void camel_header_mime_decode (const char *in, int *maj, int *min);
221 /* do incremental base64/quoted-printable (de/en)coding */
222 size_t camel_base64_decode_step (unsigned char *in, size_t len, unsigned char *out, int *state, unsigned int *save);
224 size_t camel_base64_encode_step (unsigned char *in, size_t len, gboolean break_lines, unsigned char *out, int *state, int *save);
225 size_t camel_base64_encode_close (unsigned char *in, size_t len, gboolean break_lines, unsigned char *out, int *state, int *save);
227 size_t camel_uudecode_step (unsigned char *in, size_t len, unsigned char *out, int *state, guint32 *save);
229 size_t camel_uuencode_step (unsigned char *in, size_t len, unsigned char *out, unsigned char *uubuf, int *state,
231 size_t camel_uuencode_close (unsigned char *in, size_t len, unsigned char *out, unsigned char *uubuf, int *state,
234 size_t camel_quoted_decode_step (unsigned char *in, size_t len, unsigned char *out, int *savestate, int *saveme);
236 size_t camel_quoted_encode_step (unsigned char *in, size_t len, unsigned char *out, int *state, int *save);
237 size_t camel_quoted_decode_close (unsigned char *in, size_t len, unsigned char *out, int *state, int *save);
239 char *camel_base64_encode_simple (const char *data, size_t len);
240 size_t camel_base64_decode_simple (char *data, size_t len);
244 #endif /* __cplusplus */
246 #endif /* ! _CAMEL_MIME_UTILS_H */