Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-mime-parser.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
5  *  Authors: Michael Zucchi <notzed@ximian.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
23 #error "Only <camel/camel.h> can be included directly."
24 #endif
25
26 #ifndef CAMEL_MIME_PARSER_H
27 #define CAMEL_MIME_PARSER_H
28
29 #include <camel/camel-object.h>
30
31 #include <camel/camel-mime-utils.h>
32 #include <camel/camel-mime-filter.h>
33 #include <camel/camel-stream.h>
34
35 /* Stardard GObject macros */
36 #define CAMEL_TYPE_MIME_PARSER \
37         (camel_mime_parser_get_type ())
38 #define CAMEL_MIME_PARSER(obj) \
39         (G_TYPE_CHECK_INSTANCE_CAST \
40         ((obj), CAMEL_TYPE_MIME_PARSER, CamelMimeParser))
41 #define CAMEL_MIME_PARSER_CLASS(cls) \
42         (G_TYPE_CHECK_CLASS_CAST \
43         ((cls), CAMEL_TYPE_MIME_PARSER, CamelMimeParserClass))
44 #define CAMEL_IS_MIME_PARSER(obj) \
45         (G_TYPE_CHECK_INSTANCE_TYPE \
46         ((obj), CAMEL_TYPE_MIME_PARSER))
47 #define CAMEL_IS_MIME_PARSER_CLASS(cls) \
48         (G_TYPE_CHECK_CLASS_TYPE \
49         ((cls), CAMEL_TYPE_MIME_PARSER))
50 #define CAMEL_MIME_PARSER_GET_CLASS(obj) \
51         (G_TYPE_INSTANCE_GET_CLASS \
52         ((obj), CAMEL_TYPE_MIME_PARSER, CamelMimeParserClass))
53
54 G_BEGIN_DECLS
55
56 typedef struct _CamelMimeParser CamelMimeParser;
57 typedef struct _CamelMimeParserClass CamelMimeParserClass;
58 typedef struct _CamelMimeParserPrivate CamelMimeParserPrivate;
59
60 /* NOTE: if you add more states, you may need to bump the
61  * start of the END tags to 16 or 32, etc - so they are
62  * the same as the matching start tag, with a bit difference */
63 typedef enum _camel_mime_parser_state_t {
64         CAMEL_MIME_PARSER_STATE_INITIAL,
65         CAMEL_MIME_PARSER_STATE_PRE_FROM,       /* data before a 'From' line */
66         CAMEL_MIME_PARSER_STATE_FROM,           /* got 'From' line */
67         CAMEL_MIME_PARSER_STATE_HEADER,         /* toplevel header */
68         CAMEL_MIME_PARSER_STATE_BODY,           /* scanning body of message */
69         CAMEL_MIME_PARSER_STATE_MULTIPART,      /* got multipart header */
70         CAMEL_MIME_PARSER_STATE_MESSAGE,        /* rfc822 message */
71
72         CAMEL_MIME_PARSER_STATE_PART,           /* part of a multipart */
73
74         CAMEL_MIME_PARSER_STATE_END = 8,        /* bit mask for 'end' flags */
75
76         CAMEL_MIME_PARSER_STATE_EOF = 8,        /* end of file */
77         CAMEL_MIME_PARSER_STATE_PRE_FROM_END,   /* pre from end */
78         CAMEL_MIME_PARSER_STATE_FROM_END,       /* end of whole from bracket */
79         CAMEL_MIME_PARSER_STATE_HEADER_END,     /* dummy value */
80         CAMEL_MIME_PARSER_STATE_BODY_END,       /* end of message */
81         CAMEL_MIME_PARSER_STATE_MULTIPART_END,  /* end of multipart  */
82         CAMEL_MIME_PARSER_STATE_MESSAGE_END     /* end of message */
83 } camel_mime_parser_state_t;
84
85 struct _CamelMimeParser {
86         CamelObject parent;
87         CamelMimeParserPrivate *priv;
88 };
89
90 struct _CamelMimeParserClass {
91         CamelObjectClass parent_class;
92
93         void (*message) (CamelMimeParser *parser, gpointer headers);
94         void (*part) (CamelMimeParser *parser);
95         void (*content) (CamelMimeParser *parser);
96 };
97
98 GType camel_mime_parser_get_type (void);
99 CamelMimeParser *camel_mime_parser_new (void);
100
101 /* quick-fix for parser not erroring, we can find out if it had an error afterwards */
102 gint            camel_mime_parser_errno (CamelMimeParser *parser);
103
104 /* using an fd will be a little faster, but not much (over a simple stream) */
105 gint            camel_mime_parser_init_with_fd (CamelMimeParser *m, gint fd);
106 gint            camel_mime_parser_init_with_stream (CamelMimeParser *m, CamelStream *stream, GError **error);
107
108 /* get the stream or fd back of the parser */
109 CamelStream    *camel_mime_parser_stream (CamelMimeParser *parser);
110 gint            camel_mime_parser_fd (CamelMimeParser *parser);
111
112 /* scan 'From' separators? */
113 void camel_mime_parser_scan_from (CamelMimeParser *parser, gboolean scan_from);
114 /* Do we want to know about the pre-from data? */
115 void camel_mime_parser_scan_pre_from (CamelMimeParser *parser, gboolean scan_pre_from);
116
117 /* what headers to save, MUST include ^Content-Type: */
118 gint camel_mime_parser_set_header_regex (CamelMimeParser *parser, gchar *matchstr);
119
120 /* normal interface */
121 camel_mime_parser_state_t camel_mime_parser_step (CamelMimeParser *parser, gchar **databuffer, gsize *datalength);
122 void camel_mime_parser_unstep (CamelMimeParser *parser);
123 void camel_mime_parser_drop_step (CamelMimeParser *parser);
124 camel_mime_parser_state_t camel_mime_parser_state (CamelMimeParser *parser);
125 void camel_mime_parser_push_state (CamelMimeParser *mp, camel_mime_parser_state_t newstate, const gchar *boundary);
126
127 /* read through the parser */
128 gint camel_mime_parser_read (CamelMimeParser *parser, const gchar **databuffer, gint len, GError **error);
129
130 /* get content type for the current part/header */
131 CamelContentType *camel_mime_parser_content_type (CamelMimeParser *parser);
132
133 /* get/change raw header by name */
134 const gchar *camel_mime_parser_header (CamelMimeParser *m, const gchar *name, gint *offset);
135
136 /* get all raw headers. READ ONLY! */
137 struct _camel_header_raw *camel_mime_parser_headers_raw (CamelMimeParser *m);
138
139 /* get multipart pre/postface */
140 const gchar *camel_mime_parser_preface (CamelMimeParser *m);
141 const gchar *camel_mime_parser_postface (CamelMimeParser *m);
142
143 /* return the from line content */
144 const gchar *camel_mime_parser_from_line (CamelMimeParser *m);
145
146 /* add a processing filter for body contents */
147 gint camel_mime_parser_filter_add (CamelMimeParser *m, CamelMimeFilter *mf);
148 void camel_mime_parser_filter_remove (CamelMimeParser *m, gint id);
149
150 /* these should be used with caution, because the state will not
151  * track the seeked position */
152 /* FIXME: something to bootstrap the state? */
153 goffset camel_mime_parser_tell (CamelMimeParser *parser);
154 goffset camel_mime_parser_seek (CamelMimeParser *parser, goffset offset, gint whence);
155
156 goffset camel_mime_parser_tell_start_headers (CamelMimeParser *parser);
157 goffset camel_mime_parser_tell_start_from (CamelMimeParser *parser);
158 goffset camel_mime_parser_tell_start_boundary (CamelMimeParser *parser);
159
160 G_END_DECLS
161
162 #endif /* CAMEL_MIME_PARSER_H */