move more things in the lib-mime
[apps/madmutt.git] / lib-mime / mime.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * Copyright notice from original mutt:
21  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
22  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
23  *
24  * This file is part of mutt-ng, see http://www.muttng.org/.
25  * It's licensed under the GNU General Public License,
26  * please see the file GPL in the top level source directory.
27  */
28
29 #ifndef MUTT_LIB_MIME_MIME_H
30 #define MUTT_LIB_MIME_MIME_H
31
32 #if HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <stdlib.h>
37 #include <stdio.h>
38
39 #include "mime-types.h"
40 #include "mime-token.h"
41
42 extern const char MimeSpecials[];
43 extern const char *BodyTypes[];
44 extern const char *BodyEncodings[];
45
46 /* MIME encoding/decoding global vars */
47
48 #define is_multipart(x) \
49     ((x)->type == TYPEMULTIPART \
50      || ((x)->type == TYPEMESSAGE && \
51          ((!mime_which_token((x)->subtype, -1) == MIME_RFC822) \
52          || !mime_which_token((x)->subtype, -1) == MIME_NEWS)))
53
54 #define TYPE(X) ((X->type == TYPEOTHER) && (X->xtype != NULL) ? X->xtype : BodyTypes[(X->type)])
55 #define ENCODING(X) BodyEncodings[(X)]
56
57 int url_parse_mailto(ENVELOPE *e, char **body, const char *src);
58
59 /****************************************************************************/
60 /* RFC 1524                                                                 */
61 /*                   A User Agent Configuration Mechanism                   */
62 /*                  For Multimedia Mail Format Information                  */
63 /****************************************************************************/
64
65 typedef struct rfc1524_entry {
66     char *command;
67     char *testcommand;
68     char *composecommand;
69     char *composetypecommand;
70     char *editcommand;
71     char *printcommand;
72     char *nametemplate;
73     char *convert;
74
75     unsigned needsterminal:1; /* endwin() and system */
76     unsigned copiousoutput:1; /* needs pager, basically */
77 } rfc1524_entry;
78
79 DO_INIT(rfc1524_entry, rfc1524_entry);
80 void rfc1524_entry_wipe(rfc1524_entry *);
81
82 DO_NEW(rfc1524_entry, rfc1524_entry);
83 DO_DELETE(rfc1524_entry, rfc1524_entry);
84
85 int rfc1524_expand_command(BODY *, const char *, const char *, char *, int);
86 int rfc1524_expand_filename(char *, char *, char *, ssize_t);
87 int rfc1524_mailcap_lookup(BODY *, char *, rfc1524_entry *, int);
88 int rfc1524_mailcap_isneeded(BODY *);
89
90 /****************************************************************************/
91 /* RFC 822                                                                  */
92 /*                Standard for ARPA Internet Text Messages                  */
93 /****************************************************************************/
94
95 extern const char RFC822Specials[];
96
97 ssize_t mutt_read_rfc822_line(FILE*, char**, ssize_t*);
98 string_list_t *mutt_parse_references(char *, int);
99 int mutt_check_encoding(const char *);
100 int mutt_check_mime_type(const char *);
101 void mutt_parse_content_type(char *, BODY *);
102 BODY *mutt_read_mime_header (FILE *, int);
103 void mutt_parse_part(FILE *, BODY *);
104 BODY *mutt_parse_messageRFC822(FILE *, BODY *);
105 BODY *mutt_parse_multipart(FILE *, const char *, off_t, int);
106 string_list_t **mutt_parse_rfc822_line(ENVELOPE *, HEADER *, char *line, char *p,
107                                        short weed, short do_2047, string_list_t **);
108 ENVELOPE *mutt_read_rfc822_header(FILE *, HEADER *, short, short);
109 int mutt_count_body_parts (HEADER *hdr, int flags);
110
111 int mutt_is_multipart_encrypted(BODY *);
112 int mutt_is_multipart_signed(BODY *);
113 int mutt_is_application_pgp(BODY *);
114 int mutt_is_application_smime(BODY *);
115 int mutt_is_text_part(BODY *);
116
117 /*** addresses ***/
118
119 address_t *mutt_parse_adrlist(address_t *, const char *);
120 address_t *address_dup(const address_t *addr);
121 address_t *address_list_dup(const address_t *addr);
122 void rfc822_qualify(address_t *, const char *);
123
124 address_t *rfc822_parse_adrlist(address_t *, const char *s);
125
126 ssize_t rfc822_write_address(char *, ssize_t, address_t *, int);
127 ssize_t rfc822_write_address_single(char *, ssize_t, address_t *, int);
128 ssize_t rfc822_strcpy(char *, ssize_t, const char *, const char *);
129
130 /****************************************************************************/
131 /* RFC 2047                                                                 */
132 /*       MIME (Multipurpose Internet Mail Extensions) Part Three:           */
133 /*             Message Header Extensions for Non-ASCII Text                 */
134 /****************************************************************************/
135
136 char *mutt_choose_charset(const char *fromcode, const char *charsets,
137                           char *u, ssize_t ulen, char **d, ssize_t *dlen);
138
139 void rfc2047_encode_string(char **);
140 void rfc2047_encode_adrlist(address_t *, const char *);
141
142 void rfc2047_decode(char **);
143 void rfc2047_decode_adrlist(address_t *);
144 void rfc2047_decode_envelope(ENVELOPE* e);
145
146 /****************************************************************************/
147 /* RFC 2231                                                                 */
148 /*             MIME Parameter Value and Encoded Word Extensions:            */
149 /*               Character Sets, Languages, and Continuations               */
150 /****************************************************************************/
151
152 int  rfc2231_encode_string(char **);
153 void rfc2231_decode_parameters(parameter_t **);
154
155 #endif /* MUTT_LIB_MIME_MIME_H */