Have a lib-ui/lib-ui.h
[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 parameter_t {
93     struct parameter_t *next;
94     char *attribute;
95     char *value;
96 } parameter_t;
97
98 DO_INIT(parameter_t, parameter);
99 static inline void parameter_wipe(parameter_t *param) {
100     p_delete(&param->attribute);
101     p_delete(&param->value);
102 }
103
104 DO_NEW(parameter_t, parameter);
105 DO_DELETE(parameter_t, parameter);
106 DO_SLIST(parameter_t, parameter, parameter_delete);
107
108 char *parameter_getval(parameter_t *, const char *);
109 void parameter_setval(parameter_t **, const char *, const char *);
110 void parameter_delval(parameter_t ** p, const char *);
111 void parameter_set_boundary(parameter_t **);
112
113 int parameter_equal(const parameter_t *, const parameter_t *);
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 #endif
141     BUFFER *spam;
142     string_list_t *references;             /* message references (in reverse order) */
143     string_list_t *in_reply_to;            /* in-reply-to header content */
144     string_list_t *userhdrs;               /* user defined headers */
145     unsigned int irt_changed:1;   /* In-Reply-To changed to link/break threads */
146     unsigned int refs_changed:1;  /* References changed to break thread */
147 } ENVELOPE;
148
149 DO_INIT(ENVELOPE, envelope);
150 void envelope_wipe(ENVELOPE*);
151
152 DO_NEW(ENVELOPE, envelope);
153 DO_DELETE(ENVELOPE, envelope);
154
155 /****************************************************************************/
156 /* rfc822 content-*                                                         */
157 /****************************************************************************/
158
159 /* Information that helps in determing the Content-* of an attachment */
160 typedef struct content {
161     long hibin;                   /* 8-bit characters */
162     long lobin;                   /* unprintable 7-bit chars (eg., control chars) */
163     long crlf;                    /* '\r' and '\n' characters */
164     long ascii;                   /* number of ascii chars */
165     long linemax;                 /* length of the longest line in the file */
166     unsigned int space:1;         /* whitespace at the end of lines? */
167     unsigned int binary:1;        /* long lines, or CR not in CRLF pair */
168     unsigned int from:1;          /* has a line beginning with "From "? */
169     unsigned int dot:1;           /* has a line consisting of a single dot? */
170     unsigned int cr:1;            /* has CR, even when in a CRLF pair */
171 } CONTENT;
172
173
174 /****************************************************************************/
175 /* rfc822 Bodies                                                            */
176 /****************************************************************************/
177
178 typedef struct body {
179     struct body *next;            /* next attachment in the list */
180
181     char *xtype;                  /* content-type if x-unknown */
182     char *subtype;                /* content-type subtype */
183     parameter_t *parameter;         /* parameters of the content-type */
184     char *description;            /* content-description */
185     char *form_name;              /* Content-Disposition form-data name param */
186     off_t hdr_offset;             /* offset in stream where the headers begin.
187                                    * this info is used when invoking metamail,
188                                    * where we need to send the headers of the
189                                    * attachment
190                                    */
191     off_t offset;                 /* offset where the actual data begins */
192     off_t length;                 /* length (in bytes) of attachment */
193     char *filename;               /* when sending a message, this is the file
194                                    * to which this structure refers
195                                    */
196     char *d_filename;             /* filename to be used for the 
197                                    * content-disposition header.
198                                    * If NULL, filename is used 
199                                    * instead.
200                                    */
201     char *file_charset;           /* charset of attached file */
202     CONTENT *content;             /* structure used to store detailed info about
203                                    * the content of the attachment.  this is used
204                                    * to determine what content-transfer-encoding
205                                    * is required when sending mail.
206                                    */
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 static inline BODY *body_init(BODY *b) {
251     b->disposition = DISPATTACH;
252     b->use_disp = 1;
253     return b;
254 }
255 void body_wipe(BODY *);
256
257 DO_NEW(BODY, body);
258 DO_DELETE(BODY, body);
259 DO_SLIST(BODY, body, body_delete);
260
261
262 /****************************************************************************/
263 /* rfc822 Headers                                                           */
264 /****************************************************************************/
265
266 typedef struct header {
267     unsigned int security:11;     /* bit 0-6: flags, bit 7,8: application.
268 see: crypt.h pgplib.h, smime.h */
269
270     unsigned int mime:1;          /* has a MIME-Version header? */
271     unsigned int flagged:1;       /* marked important? */
272     unsigned int tagged:1;
273     unsigned int appended:1;      /* has been saved */
274     unsigned int purged:1;        /* bypassing the trash folder */
275     unsigned int deleted:1;
276     unsigned int changed:1;
277     unsigned int attach_del:1;    /* has an attachment marked for deletion */
278     unsigned int old:1;
279     unsigned int read:1;
280     unsigned int expired:1;       /* already expired? */
281     unsigned int superseded:1;    /* got superseded? */
282     unsigned int replied:1;
283     unsigned int subject_changed:1;       /* used for threading */
284     unsigned int threaded:1;      /* used for threading */
285     unsigned int display_subject:1;       /* used for threading */
286     unsigned int recip_valid:1;   /* is_recipient is valid */
287     unsigned int active:1;        /* message is not to be removed */
288     unsigned int trash:1;         /* message is marked as trashed on disk.
289                                    * This flag is used by the maildir_trash
290                                    * option.
291                                    */
292
293     /* timezone of the sender of this message */
294     unsigned int zhours:5;
295     unsigned int zminutes:6;
296     unsigned int zoccident:1;
297
298     /* bits used for caching when searching */
299     unsigned int searched:1;
300     unsigned int matched:1;
301
302     /* tells whether the attach count is valid */
303     unsigned int attach_valid:1;
304
305     /* the following are used to support collapsing threads  */
306     unsigned int collapsed:1;     /* is this message part of a collapsed thread? */
307     unsigned int limited:1;       /* is this message in a limited view?  */
308     size_t num_hidden;            /* number of hidden messages in this view */
309
310     short recipient;              /* user_is_recipient()'s return value, cached */
311
312     int pair;                     /* color-pair to use when displaying in the index */
313
314     time_t date_sent;             /* time when the message was sent (UTC) */
315     time_t received;              /* time when the message was placed in the mailbox */
316     off_t offset;                 /* where in the stream does this message begin? */
317     int lines;                    /* how many lines in the body of this message? */
318     int index;                    /* the absolute (unsorted) message number */
319     int msgno;                    /* number displayed to the user */
320     int virtual;                  /* virtual message number */
321     int score;
322     ENVELOPE *env;                /* envelope information */
323     BODY *content;                /* list of MIME parts */
324     char *path;
325 #ifdef USE_NNTP
326     int article_num;
327 #endif
328
329     char *tree;                   /* character string to print thread tree */
330     struct thread *thread;
331
332     short attach_total;
333
334     int refno;                    /* message number on server */
335     void *data;                   /* driver-specific data */
336
337     char *maildir_flags;          /* unknown maildir flags */
338 } HEADER;
339
340 DO_INIT(HEADER, header);
341 void header_wipe(HEADER *);
342
343 DO_NEW(HEADER, header);
344 DO_DELETE(HEADER, header);
345
346 #endif /* MUTT_LIB_MIME_MIME_TYPES_H */