move more things in the lib-mime
[apps/madmutt.git] / lib-mime / mime-types.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 /*
21  * Copyright notice from original mutt:
22  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
23  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
24  *
25  * This file is part of mutt-ng, see http://www.muttng.org/.
26  * It's licensed under the GNU General Public License,
27  * please see the file GPL in the top level source directory.
28  */
29
30 #ifndef MUTT_LIB_MIME_MIME_TYPES_H
31 #define MUTT_LIB_MIME_MIME_TYPES_H
32
33 #include <lib-lib/mem.h>
34 #include <lib-lib/buffer.h>
35 #include <lib-lib/list.h>
36
37 /* Content-Type */
38 enum {
39     TYPEOTHER,
40     TYPEAUDIO,
41     TYPEAPPLICATION,
42     TYPEIMAGE,
43     TYPEMESSAGE,
44     TYPEMODEL,
45     TYPEMULTIPART,
46     TYPETEXT,
47     TYPEVIDEO,
48     TYPEANY
49 };
50
51 /* Content-Transfer-Encoding */
52 enum {
53     ENCOTHER,
54     ENC7BIT,
55     ENC8BIT,
56     ENCQUOTEDPRINTABLE,
57     ENCBASE64,
58     ENCBINARY,
59     ENCUUENCODED,
60 };
61
62 /* Content-Disposition values */
63 enum {
64     DISPINLINE,
65     DISPATTACH,
66     DISPFORMDATA
67 };
68
69 /****************************************************************************/
70 /* rfc822 addresses                                                         */
71 /****************************************************************************/
72
73 typedef struct address_t {
74     struct address_t *next;
75     char *personal;               /* real name of address */
76     char *mailbox;                /* mailbox and host address */
77     int group;                    /* group mailbox? */
78 } address_t;
79
80 DO_INIT(address_t, address);
81 static inline void address_wipe(address_t *addr) {
82     p_delete(&addr->personal);
83     p_delete(&addr->mailbox);
84 }
85
86 DO_NEW(address_t, address);
87 DO_DELETE(address_t, address);
88 DO_SLIST(address_t, address, address_delete);
89
90 /****************************************************************************/
91 /* rfc822 header parameters                                                 */
92 /****************************************************************************/
93
94 typedef struct parameter_t {
95     struct parameter_t *next;
96     char *attribute;
97     char *value;
98 } parameter_t;
99
100 DO_INIT(parameter_t, parameter);
101 static inline void parameter_wipe(parameter_t *param) {
102     p_delete(&param->attribute);
103     p_delete(&param->value);
104 }
105
106 DO_NEW(parameter_t, parameter);
107 DO_DELETE(parameter_t, parameter);
108 DO_SLIST(parameter_t, parameter, parameter_delete);
109
110 char *parameter_getval(parameter_t *, const char *);
111 void parameter_setval(parameter_t **, const char *, const char *);
112 void parameter_delval(parameter_t ** p, const char *);
113 void parameter_set_boundary(parameter_t **);
114
115 int parameter_equal(const parameter_t *, const parameter_t *);
116
117 /****************************************************************************/
118 /* rfc822 envelopes                                                         */
119 /****************************************************************************/
120
121 typedef struct envelope_t {
122     address_t *return_path;
123     address_t *from;
124     address_t *to;
125     address_t *cc;
126     address_t *bcc;
127     address_t *sender;
128     address_t *reply_to;
129     address_t *mail_followup_to;
130     char *list_post;              /* this stores a mailto URL, or nothing */
131     char *subject;
132     char *real_subj;              /* offset of the real subject */
133     char *message_id;
134     char *supersedes;
135     char *date;
136     char *x_label;
137     char *organization;
138 #ifdef USE_NNTP
139     char *newsgroups;
140     char *xref;
141     char *followup_to;
142     char *x_comment_to;
143 #endif
144     BUFFER *spam;
145     string_list_t *references;             /* message references (in reverse order) */
146     string_list_t *in_reply_to;            /* in-reply-to header content */
147     string_list_t *userhdrs;               /* user defined headers */
148     unsigned int irt_changed:1;   /* In-Reply-To changed to link/break threads */
149     unsigned int refs_changed:1;  /* References changed to break thread */
150 } ENVELOPE;
151
152 DO_INIT(ENVELOPE, envelope);
153 void envelope_wipe(ENVELOPE*);
154
155 DO_NEW(ENVELOPE, envelope);
156 DO_DELETE(ENVELOPE, envelope);
157
158 /****************************************************************************/
159 /* rfc822 content-*                                                         */
160 /****************************************************************************/
161
162 /* Information that helps in determing the Content-* of an attachment */
163 typedef struct content {
164     long hibin;                   /* 8-bit characters */
165     long lobin;                   /* unprintable 7-bit chars (eg., control chars) */
166     long crlf;                    /* '\r' and '\n' characters */
167     long ascii;                   /* number of ascii chars */
168     long linemax;                 /* length of the longest line in the file */
169     unsigned int space:1;         /* whitespace at the end of lines? */
170     unsigned int binary:1;        /* long lines, or CR not in CRLF pair */
171     unsigned int from:1;          /* has a line beginning with "From "? */
172     unsigned int dot:1;           /* has a line consisting of a single dot? */
173     unsigned int cr:1;            /* has CR, even when in a CRLF pair */
174 } CONTENT;
175
176
177 /****************************************************************************/
178 /* rfc822 Bodies                                                            */
179 /****************************************************************************/
180
181 typedef struct body {
182     struct body *next;            /* next attachment in the list */
183
184     char *xtype;                  /* content-type if x-unknown */
185     char *subtype;                /* content-type subtype */
186     parameter_t *parameter;         /* parameters of the content-type */
187     char *description;            /* content-description */
188     char *form_name;              /* Content-Disposition form-data name param */
189     off_t hdr_offset;             /* offset in stream where the headers begin.
190                                    * this info is used when invoking metamail,
191                                    * where we need to send the headers of the
192                                    * attachment
193                                    */
194     off_t offset;                 /* offset where the actual data begins */
195     off_t length;                 /* length (in bytes) of attachment */
196     char *filename;               /* when sending a message, this is the file
197                                    * to which this structure refers
198                                    */
199     char *d_filename;             /* filename to be used for the 
200                                    * content-disposition header.
201                                    * If NULL, filename is used 
202                                    * instead.
203                                    */
204     char *file_charset;           /* charset of attached file */
205     CONTENT *content;             /* structure used to store detailed info about
206                                    * the content of the attachment.  this is used
207                                    * to determine what content-transfer-encoding
208                                    * is required when sending mail.
209                                    */
210     struct body *parts;           /* parts of a multipart or message/rfc822 */
211     struct header *hdr;           /* header information for message/rfc822 */
212
213     struct attachptr *aptr;       /* Menu information, used in recvattach.c */
214
215     signed short attach_count;
216
217     time_t stamp;                 /* time stamp of last
218                                    * encoding update.
219                                    */
220
221     unsigned int type:4;          /* content-type primary type */
222     unsigned int encoding:3;      /* content-transfer-encoding */
223     unsigned int disposition:2;   /* content-disposition */
224     unsigned int use_disp:1;      /* Content-Disposition uses filename= ? */
225     unsigned int unlink:1;        /* flag to indicate the the file named by
226                                    * "filename" should be unlink()ed before
227                                    * free()ing this structure
228                                    */
229     unsigned int tagged:1;
230     unsigned int deleted:1;       /* attachment marked for deletion */
231
232     unsigned int noconv:1;        /* don't do character set conversion */
233     unsigned int force_charset:1; /* send mode: don't adjust the character set
234                                      when in send-mode. */
235     unsigned int is_signed_data:1; /* A lot of MUAs don't indicate S/MIME
236                                       signed-data correctly, e.g. they use
237                                       foo.p7m even for the name of signed
238                                       data.  This flag is used to keep track
239                                       of the actual message type.  It gets set
240                                       during the verification (which is done
241                                       if the encryption try failed) and check
242                                       by the function to figure the type of
243                                       the message. */
244
245     unsigned int goodsig:1;       /* good cryptographic signature */
246     unsigned int warnsig:1;       /* maybe good signature */
247     unsigned int badsig:1;        /* bad cryptographic signature (needed to check encrypted s/mime-signatures) */
248
249     unsigned int collapsed:1;     /* used by recvattach */
250     unsigned int attach_qualifies:1;
251 } BODY;
252
253 static inline BODY *body_init(BODY *b) {
254     b->disposition = DISPATTACH;
255     b->use_disp = 1;
256     return b;
257 }
258 void body_wipe(BODY *);
259
260 DO_NEW(BODY, body);
261 DO_DELETE(BODY, body);
262 DO_SLIST(BODY, body, body_delete);
263
264
265 /****************************************************************************/
266 /* rfc822 Headers                                                           */
267 /****************************************************************************/
268
269 typedef struct header {
270     unsigned int security:11;     /* bit 0-6: flags, bit 7,8: application.
271 see: crypt.h pgplib.h, smime.h */
272
273     unsigned int mime:1;          /* has a MIME-Version header? */
274     unsigned int flagged:1;       /* marked important? */
275     unsigned int tagged:1;
276     unsigned int appended:1;      /* has been saved */
277     unsigned int purged:1;        /* bypassing the trash folder */
278     unsigned int deleted:1;
279     unsigned int changed:1;
280     unsigned int attach_del:1;    /* has an attachment marked for deletion */
281     unsigned int old:1;
282     unsigned int read:1;
283     unsigned int expired:1;       /* already expired? */
284     unsigned int superseded:1;    /* got superseded? */
285     unsigned int replied:1;
286     unsigned int subject_changed:1;       /* used for threading */
287     unsigned int threaded:1;      /* used for threading */
288     unsigned int display_subject:1;       /* used for threading */
289     unsigned int recip_valid:1;   /* is_recipient is valid */
290     unsigned int active:1;        /* message is not to be removed */
291     unsigned int trash:1;         /* message is marked as trashed on disk.
292                                    * This flag is used by the maildir_trash
293                                    * option.
294                                    */
295
296     /* timezone of the sender of this message */
297     unsigned int zhours:5;
298     unsigned int zminutes:6;
299     unsigned int zoccident:1;
300
301     /* bits used for caching when searching */
302     unsigned int searched:1;
303     unsigned int matched:1;
304
305     /* tells whether the attach count is valid */
306     unsigned int attach_valid:1;
307
308     /* the following are used to support collapsing threads  */
309     unsigned int collapsed:1;     /* is this message part of a collapsed thread? */
310     unsigned int limited:1;       /* is this message in a limited view?  */
311     size_t num_hidden;            /* number of hidden messages in this view */
312
313     short recipient;              /* user_is_recipient()'s return value, cached */
314
315     int pair;                     /* color-pair to use when displaying in the index */
316
317     time_t date_sent;             /* time when the message was sent (UTC) */
318     time_t received;              /* time when the message was placed in the mailbox */
319     off_t offset;                 /* where in the stream does this message begin? */
320     int lines;                    /* how many lines in the body of this message? */
321     int index;                    /* the absolute (unsorted) message number */
322     int msgno;                    /* number displayed to the user */
323     int virtual;                  /* virtual message number */
324     int score;
325     ENVELOPE *env;                /* envelope information */
326     BODY *content;                /* list of MIME parts */
327     char *path;
328 #ifdef USE_NNTP
329     int article_num;
330 #endif
331
332     char *tree;                   /* character string to print thread tree */
333     struct thread *thread;
334
335     short attach_total;
336
337 #ifdef MIXMASTER
338     string_list_t *chain;
339 #endif
340
341     int refno;                    /* message number on server */
342     void *data;                   /* driver-specific data */
343
344     char *maildir_flags;          /* unknown maildir flags */
345 } HEADER;
346
347 DO_INIT(HEADER, header);
348 void header_wipe(HEADER *);
349
350 DO_NEW(HEADER, header);
351 DO_DELETE(HEADER, header);
352
353 #endif /* MUTT_LIB_MIME_MIME_TYPES_H */