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