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