chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / tools / rfc822parse.h
1 /* rfc822parse.h - Simple mail and MIME parser
2  *      Copyright (C) 1999 Werner Koch, Duesseldorf
3  *      Copyright (C) 2003 g10 Code GmbH
4  *
5  * This program 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 3 of
8  * the License, or (at your option) any later version.
9  *
10  * This program 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #ifndef RFC822PARSE_H
20 #define RFC822PARSE_H
21
22 struct rfc822parse_context;
23 typedef struct rfc822parse_context *rfc822parse_t;
24
25 typedef enum
26   {
27     RFC822PARSE_OPEN = 1,
28     RFC822PARSE_CLOSE,
29     RFC822PARSE_CANCEL,
30     RFC822PARSE_T2BODY,
31     RFC822PARSE_FINISH,
32     RFC822PARSE_RCVD_SEEN,
33     RFC822PARSE_LEVEL_DOWN,
34     RFC822PARSE_LEVEL_UP,
35     RFC822PARSE_BOUNDARY,
36     RFC822PARSE_LAST_BOUNDARY,
37     RFC822PARSE_BEGIN_HEADER,
38     RFC822PARSE_PREAMBLE,
39     RFC822PARSE_EPILOGUE
40   }
41 rfc822parse_event_t;
42
43 struct rfc822parse_field_context;
44 typedef struct rfc822parse_field_context *rfc822parse_field_t;
45
46
47 typedef int (*rfc822parse_cb_t) (void *opaque,
48                                  rfc822parse_event_t event,
49                                  rfc822parse_t msg);
50
51
52 rfc822parse_t rfc822parse_open (rfc822parse_cb_t cb, void *opaque_value);
53
54 void rfc822parse_close (rfc822parse_t msg);
55
56 void rfc822parse_cancel (rfc822parse_t msg);
57 int rfc822parse_finish (rfc822parse_t msg);
58
59 int rfc822parse_insert (rfc822parse_t msg,
60                         const unsigned char *line, size_t length);
61
62 char *rfc822parse_get_field (rfc822parse_t msg, const char *name, int which,
63                              size_t *valueoff);
64
65 const char *rfc822parse_enum_header_lines (rfc822parse_t msg, void **context);
66
67 rfc822parse_field_t rfc822parse_parse_field (rfc822parse_t msg,
68                                              const char *name,
69                                              int which);
70
71 void rfc822parse_release_field (rfc822parse_field_t field);
72
73 const char *rfc822parse_query_parameter (rfc822parse_field_t ctx,
74                                          const char *attr, int lower_value);
75
76 const char *rfc822parse_query_media_type (rfc822parse_field_t ctx,
77                                           const char **subtype);
78
79 #endif /*RFC822PARSE_H */