1 
2 /*
3  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 2004 g10 Code GmbH
5  *
6  *     This program is free software; you can redistribute it and/or modify
7  *     it under the terms of the GNU General Public License as published by
8  *     the Free Software Foundation; either version 2 of the License, or
9  *     (at your option) any later version.
10  *
11  *     This program is distributed in the hope that it will be useful,
12  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *     GNU General Public License for more details.
15  *
16  *     You should have received a copy of the GNU General Public License
17  *     along with this program; if not, write to the Free Software
18  *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 
21 #ifndef MUTT_H
22 #define MUTT_H
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h> /* needed for SEEK_SET */
28 #endif
29 #ifdef HAVE_UNIX_H
30 # include <unix.h>   /* needed for snprintf on QNX. */
31 #endif
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <time.h>
35 #include <limits.h>
36 #include <stdarg.h>
37 #include <signal.h>
38 /* On OS X 10.5.x, wide char functions are inlined by default breaking
39  * --without-wc-funcs compilation
40  */
41 #ifdef __APPLE_CC__
42 #define _DONT_USE_CTYPE_INLINE_
43 #endif
44 #ifdef HAVE_WCHAR_H
45 # include <wchar.h>
46 #endif
47 #if defined(HAVE_WCTYPE_H) && defined(HAVE_WC_FUNCS)
48 # include <wctype.h>
49 #endif
50 
51 #ifndef _POSIX_PATH_MAX
52 #include <limits.h>
53 #endif
54 
55 #include <pwd.h>
56 #include <grp.h>
57 
58 #include "rfc822.h"
59 #include "hash.h"
60 #include "charset.h"
61 
62 #ifndef HAVE_WC_FUNCS
63 # ifdef MB_LEN_MAX
64 #  undef MB_LEN_MAX
65 # endif
66 # define MB_LEN_MAX 16
67 #endif
68 
69 #define MUTT_VERSION (VERSION)
70 
71 /* nifty trick I stole from ELM 2.5alpha. */
72 #ifdef MAIN_C
73 #define WHERE
74 #define INITVAL(x) = x
75 #else
76 #define WHERE extern
77 #define INITVAL(x)
78 #endif
79 
80 #define WHERE_DEFINED 1
81 
82 #include "mutt_regex.h"
83 
84 /* flags for mutt_enter_string() */
85 #define  M_ALIAS   1      /* do alias "completion" by calling up the alias-menu */
86 #define  M_FILE    (1<<1) /* do file completion */
87 #define  M_EFILE   (1<<2) /* do file completion, plus incoming folders */
88 #define  M_CMD     (1<<3) /* do completion on previous word */
89 #define  M_PASS    (1<<4) /* password mode (no echo) */
90 #define  M_CLEAR   (1<<5) /* clear input if printable character is pressed */
91 #define  M_COMMAND (1<<6) /* do command completion */
92 #define  M_PATTERN (1<<7) /* pattern mode - only used for history classes */
93 
94 /* flags for mutt_get_token() */
95 #define M_TOKEN_EQUAL		1	/* treat '=' as a special */
96 #define M_TOKEN_CONDENSE	(1<<1)	/* ^(char) to control chars (macros) */
97 #define M_TOKEN_SPACE		(1<<2)  /* don't treat whitespace as a term */
98 #define M_TOKEN_QUOTE		(1<<3)	/* don't interpret quotes */
99 #define M_TOKEN_PATTERN		(1<<4)	/* !)|~ are terms (for patterns) */
100 #define M_TOKEN_COMMENT		(1<<5)	/* don't reap comments */
101 #define M_TOKEN_SEMICOLON	(1<<6)	/* don't treat ; as special */
102 
103 /* flags for km_dokey() */
104 #define M_KM_UNBUFFERED 1 /* don't read from the key buffer */
105 
106 typedef struct
107 {
108   char *data;	/* pointer to data */
109   char *dptr;	/* current read/write position */
110   size_t dsize;	/* length of data */
111   int destroy;	/* destroy `data' when done? */
112 } BUFFER;
113 
114 typedef struct
115 {
116   int ch; /* raw key pressed */
117   int op; /* function op */
118 } event_t;
119 
120 /* flags for _mutt_system() */
121 #define M_DETACH_PROCESS	1	/* detach subprocess from group */
122 
123 /* flags for mutt_FormatString() */
124 typedef enum
125 {
126   M_FORMAT_FORCESUBJ	= (1<<0), /* print the subject even if unchanged */
127   M_FORMAT_TREE		= (1<<1), /* draw the thread tree */
128   M_FORMAT_MAKEPRINT	= (1<<2), /* make sure that all chars are printable */
129   M_FORMAT_OPTIONAL	= (1<<3),
130   M_FORMAT_STAT_FILE	= (1<<4), /* used by mutt_attach_fmt */
131   M_FORMAT_ARROWCURSOR	= (1<<5), /* reserve space for arrow_cursor */
132   M_FORMAT_INDEX	= (1<<6), /* this is a main index entry */
133   M_FORMAT_NOFILTER	= (1<<7)  /* do not allow filtering on this pass */
134 } format_flag;
135 
136 /* types for mutt_add_hook() */
137 #define M_FOLDERHOOK	1
138 #define M_MBOXHOOK	(1<<1)
139 #define M_SENDHOOK	(1<<2)
140 #define M_FCCHOOK	(1<<3)
141 #define M_SAVEHOOK	(1<<4)
142 #define M_CHARSETHOOK	(1<<5)
143 #define M_ICONVHOOK 	(1<<6)
144 #define M_MESSAGEHOOK	(1<<7)
145 #define M_CRYPTHOOK	(1<<8)
146 #define M_ACCOUNTHOOK	(1<<9)
147 #define M_REPLYHOOK	(1<<10)
148 #define M_SEND2HOOK     (1<<11)
149 
150 /* tree characters for linearize_tree and print_enriched_string */
151 #define M_TREE_LLCORNER		1
152 #define M_TREE_ULCORNER		2
153 #define M_TREE_LTEE		3
154 #define M_TREE_HLINE		4
155 #define M_TREE_VLINE		5
156 #define M_TREE_SPACE		6
157 #define M_TREE_RARROW		7
158 #define M_TREE_STAR		8
159 #define M_TREE_HIDDEN		9
160 #define M_TREE_EQUALS		10
161 #define M_TREE_TTEE		11
162 #define M_TREE_BTEE		12
163 #define M_TREE_MISSING		13
164 #define M_TREE_MAX		14
165 
166 #define M_THREAD_COLLAPSE	(1<<0)
167 #define M_THREAD_UNCOLLAPSE	(1<<1)
168 #define M_THREAD_GET_HIDDEN	(1<<2)
169 #define M_THREAD_UNREAD		(1<<3)
170 #define M_THREAD_NEXT_UNREAD	(1<<4)
171 
172 enum
173 {
174   /* modes for mutt_view_attachment() */
175   M_REGULAR = 1,
176   M_MAILCAP,
177   M_AS_TEXT,
178 
179   /* action codes used by mutt_set_flag() and mutt_pattern_function() */
180   M_ALL,
181   M_NONE,
182   M_NEW,
183   M_OLD,
184   M_REPLIED,
185   M_READ,
186   M_UNREAD,
187   M_DELETE,
188   M_UNDELETE,
189   M_DELETED,
190   M_FLAG,
191   M_TAG,
192   M_UNTAG,
193   M_LIMIT,
194   M_EXPIRED,
195   M_SUPERSEDED,
196 
197   /* actions for mutt_pattern_comp/mutt_pattern_exec */
198   M_AND,
199   M_OR,
200   M_THREAD,
201   M_TO,
202   M_CC,
203   M_COLLAPSED,
204   M_SUBJECT,
205   M_FROM,
206   M_DATE,
207   M_DATE_RECEIVED,
208   M_DUPLICATED,
209   M_UNREFERENCED,
210   M_ID,
211   M_BODY,
212   M_HEADER,
213   M_HORMEL,
214   M_WHOLE_MSG,
215   M_SENDER,
216   M_MESSAGE,
217   M_SCORE,
218   M_SIZE,
219   M_REFERENCE,
220   M_RECIPIENT,
221   M_LIST,
222   M_SUBSCRIBED_LIST,
223   M_PERSONAL_RECIP,
224   M_PERSONAL_FROM,
225   M_ADDRESS,
226   M_CRYPT_SIGN,
227   M_CRYPT_VERIFIED,
228   M_CRYPT_ENCRYPT,
229   M_PGP_KEY,
230   M_XLABEL,
231   M_MIMEATTACH,
232 
233   /* Options for Mailcap lookup */
234   M_EDIT,
235   M_COMPOSE,
236   M_PRINT,
237   M_AUTOVIEW,
238 
239   /* options for socket code */
240   M_NEW_SOCKET,
241 #ifdef USE_SSL_OPENSSL
242   M_NEW_SSL_SOCKET,
243 #endif
244 
245   /* Options for mutt_save_attachment */
246   M_SAVE_APPEND,
247   M_SAVE_OVERWRITE
248 };
249 
250 /* possible arguments to set_quadoption() */
251 enum
252 {
253   M_NO,
254   M_YES,
255   M_ASKNO,
256   M_ASKYES
257 };
258 
259 /* quad-option vars */
260 enum
261 {
262   OPT_ABORT,
263   OPT_BOUNCE,
264   OPT_COPY,
265   OPT_DELETE,
266   OPT_FORWEDIT,
267   OPT_FCCATTACH,
268   OPT_INCLUDE,
269   OPT_MFUPTO,
270   OPT_MIMEFWD,
271   OPT_MIMEFWDREST,
272   OPT_MOVE,
273   OPT_PGPMIMEAUTO,     /* ask to revert to PGP/MIME when inline fails */
274 #ifdef USE_POP
275   OPT_POPDELETE,
276   OPT_POPRECONNECT,
277 #endif
278   OPT_POSTPONE,
279   OPT_PRINT,
280   OPT_QUIT,
281   OPT_REPLYTO,
282   OPT_RECALL,
283 #if defined(USE_SSL)
284   OPT_SSLSTARTTLS,
285 #endif
286   OPT_SUBJECT,
287   OPT_VERIFYSIG,      /* verify PGP signatures */
288 
289   /* THIS MUST BE THE LAST VALUE. */
290   OPT_MAX
291 };
292 
293 /* flags to ci_send_message() */
294 #define SENDREPLY	(1<<0)
295 #define SENDGROUPREPLY	(1<<1)
296 #define SENDLISTREPLY	(1<<2)
297 #define SENDFORWARD	(1<<3)
298 #define SENDPOSTPONED	(1<<4)
299 #define SENDBATCH	(1<<5)
300 #define SENDMAILX	(1<<6)
301 #define SENDKEY		(1<<7)
302 #define SENDRESEND	(1<<8)
303 
304 /* flags to _mutt_select_file() */
305 #define M_SEL_BUFFY	(1<<0)
306 #define M_SEL_MULTI	(1<<1)
307 #define M_SEL_FOLDER	(1<<2)
308 
309 /* flags for parse_spam_list */
310 #define M_SPAM          1
311 #define M_NOSPAM        2
312 
313 /* boolean vars */
314 enum
315 {
316   OPTALLOW8BIT,
317   OPTALLOWANSI,
318   OPTARROWCURSOR,
319   OPTASCIICHARS,
320   OPTASKBCC,
321   OPTASKCC,
322   OPTATTACHSPLIT,
323   OPTAUTOEDIT,
324   OPTAUTOTAG,
325   OPTBEEP,
326   OPTBEEPNEW,
327   OPTBOUNCEDELIVERED,
328   OPTBRAILLEFRIENDLY,
329   OPTCHECKMBOXSIZE,
330   OPTCHECKNEW,
331   OPTCJKWIDTH,
332   OPTCOLLAPSEUNREAD,
333   OPTCONFIRMAPPEND,
334   OPTCONFIRMCREATE,
335   OPTCREATERFC2047PARAMS,
336   OPTDELETEUNTAG,
337   OPTDELETEPREFIX,
338   OPTDIGESTCOLLAPSE,
339   OPTDUPTHREADS,
340   OPTEDITHDRS,
341   OPTENCODEFROM,
342   OPTENVFROM,
343   OPTFASTREPLY,
344   OPTFCCCLEAR,
345   OPTFOLLOWUPTO,
346   OPTFORCENAME,
347   OPTFORWDECODE,
348   OPTFORWQUOTE,
349 #ifdef USE_HCACHE
350   OPTHCACHEVERIFY,
351 #if defined(HAVE_QDBM) || defined(HAVE_TC)
352   OPTHCACHECOMPRESS,
353 #endif /* HAVE_QDBM */
354 #endif
355   OPTHDRS,
356   OPTHEADER,
357   OPTHELP,
358   OPTHIDDENHOST,
359   OPTHIDELIMITED,
360   OPTHIDEMISSING,
361   OPTHIDETHREADSUBJECT,
362   OPTHIDETOPLIMITED,
363   OPTHIDETOPMISSING,
364   OPTHONORDISP,
365   OPTIGNORELWS,
366   OPTIGNORELISTREPLYTO,
367 #ifdef USE_IMAP
368   OPTIMAPCHECKSUBSCRIBED,
369   OPTIMAPIDLE,
370   OPTIMAPLSUB,
371   OPTIMAPPASSIVE,
372   OPTIMAPPEEK,
373   OPTIMAPSERVERNOISE,
374 #endif
375 #if defined(USE_SSL)
376 # ifndef USE_SSL_GNUTLS
377   OPTSSLSYSTEMCERTS,
378   OPTSSLV2,
379 # endif /* USE_SSL_GNUTLS */
380   OPTSSLV3,
381   OPTTLSV1,
382   OPTSSLFORCETLS,
383   OPTSSLVERIFYDATES,
384   OPTSSLVERIFYHOST,
385 #endif /* defined(USE_SSL) */
386   OPTIMPLICITAUTOVIEW,
387   OPTINCLUDEONLYFIRST,
388   OPTKEEPFLAGGED,
389   OPTMAILCAPSANITIZE,
390   OPTMAILCHECKRECENT,
391   OPTMAILDIRTRASH,
392   OPTMARKERS,
393   OPTMARKOLD,
394   OPTMENUSCROLL,	/* scroll menu instead of implicit next-page */
395   OPTMENUMOVEOFF,	/* allow menu to scroll past last entry */
396 #if defined(USE_IMAP) || defined(USE_POP)
397   OPTMESSAGECACHECLEAN,
398 #endif
399   OPTMETAKEY,		/* interpret ALT-x as ESC-x */
400   OPTMETOO,
401   OPTMHPURGE,
402   OPTMIMEFORWDECODE,
403   OPTNARROWTREE,
404   OPTPAGERSTOP,
405   OPTPIPEDECODE,
406   OPTPIPESPLIT,
407 #ifdef USE_POP
408   OPTPOPAUTHTRYALL,
409   OPTPOPLAST,
410 #endif
411   OPTPRINTDECODE,
412   OPTPRINTSPLIT,
413   OPTPROMPTAFTER,
414   OPTREADONLY,
415   OPTREPLYSELF,
416   OPTRESOLVE,
417   OPTREVALIAS,
418   OPTREVNAME,
419   OPTREVREAL,
420   OPTRFC2047PARAMS,
421   OPTSANITIZEJACHARS,
422   OPTSAVEADDRESS,
423   OPTSAVEEMPTY,
424   OPTSAVENAME,
425   OPTSCORE,
426   OPTSIGDASHES,
427   OPTSIGONTOP,
428   OPTSORTRE,
429   OPTSPAMSEP,
430   OPTSTATUSONTOP,
431   OPTSTRICTTHREADS,
432   OPTSUSPEND,
433   OPTTEXTFLOWED,
434   OPTTHOROUGHSRC,
435   OPTTHREADRECEIVED,
436   OPTTILDE,
437   OPTUNCOLLAPSEJUMP,
438   OPTUSE8BITMIME,
439   OPTUSEDOMAIN,
440   OPTUSEFROM,
441   OPTUSEGPGAGENT,
442 #ifdef HAVE_LIBIDN
443   OPTUSEIDN,
444 #endif
445 #ifdef HAVE_GETADDRINFO
446   OPTUSEIPV6,
447 #endif
448   OPTWAITKEY,
449   OPTWEED,
450   OPTWRAP,
451   OPTWRAPSEARCH,
452   OPTWRITEBCC,		/* write out a bcc header? */
453   OPTXMAILER,
454 
455   OPTCRYPTUSEGPGME,
456   OPTCRYPTUSEPKA,
457 
458   /* PGP options */
459 
460   OPTCRYPTAUTOSIGN,
461   OPTCRYPTAUTOENCRYPT,
462   OPTCRYPTAUTOPGP,
463   OPTCRYPTAUTOSMIME,
464   OPTCRYPTREPLYENCRYPT,
465   OPTCRYPTREPLYSIGN,
466   OPTCRYPTREPLYSIGNENCRYPTED,
467   OPTCRYPTTIMESTAMP,
468   OPTSMIMEISDEFAULT,
469   OPTASKCERTLABEL,
470   OPTSDEFAULTDECRYPTKEY,
471   OPTPGPIGNORESUB,
472   OPTPGPCHECKEXIT,
473   OPTPGPLONGIDS,
474   OPTPGPAUTODEC,
475 #if 0
476   OPTPGPENCRYPTSELF,
477 #endif
478   OPTPGPRETAINABLESIG,
479   OPTPGPSTRICTENC,
480   OPTFORWDECRYPT,
481   OPTPGPSHOWUNUSABLE,
482   OPTPGPAUTOINLINE,
483   OPTPGPREPLYINLINE,
484 
485   /* pseudo options */
486 
487   OPTAUXSORT,		/* (pseudo) using auxillary sort function */
488   OPTFORCEREFRESH,	/* (pseudo) refresh even during macros */
489   OPTLOCALES,		/* (pseudo) set if user has valid locale definition */
490   OPTNOCURSES,		/* (pseudo) when sending in batch mode */
491   OPTNEEDREDRAW,	/* (pseudo) to notify caller of a submenu */
492   OPTSEARCHREVERSE,	/* (pseudo) used by ci_search_command */
493   OPTMSGERR,		/* (pseudo) used by mutt_error/mutt_message */
494   OPTSEARCHINVALID,	/* (pseudo) used to invalidate the search pat */
495   OPTSIGNALSBLOCKED,	/* (pseudo) using by mutt_block_signals () */
496   OPTSYSSIGNALSBLOCKED,	/* (pseudo) using by mutt_block_signals_system () */
497   OPTNEEDRESORT,	/* (pseudo) used to force a re-sort */
498   OPTRESORTINIT,	/* (pseudo) used to force the next resort to be from scratch */
499   OPTVIEWATTACH,	/* (pseudo) signals that we are viewing attachments */
500   OPTFORCEREDRAWINDEX,	/* (pseudo) used to force a redraw in the main index */
501   OPTFORCEREDRAWPAGER,	/* (pseudo) used to force a redraw in the pager */
502   OPTSORTSUBTHREADS,	/* (pseudo) used when $sort_aux changes */
503   OPTNEEDRESCORE,	/* (pseudo) set when the `score' command is used */
504   OPTATTACHMSG,		/* (pseudo) used by attach-message */
505   OPTKEEPQUIET,		/* (pseudo) shut up the message and refresh
506 			 * 	    functions while we are executing an
507 			 * 	    external program.
508 			 */
509   OPTMENUCALLER,	/* (pseudo) tell menu to give caller a take */
510   OPTREDRAWTREE,	/* (pseudo) redraw the thread tree */
511   OPTPGPCHECKTRUST,	/* (pseudo) used by pgp_select_key () */
512   OPTDONTHANDLEPGPKEYS,	/* (pseudo) used to extract PGP keys */
513   OPTUNBUFFEREDINPUT,   /* (pseudo) don't use key buffer */
514 
515   OPTMAX
516 };
517 
518 #define mutt_bit_alloc(n) calloc ((n + 7) / 8, sizeof (char))
519 #define mutt_bit_set(v,n) v[n/8] |= (1 << (n % 8))
520 #define mutt_bit_unset(v,n) v[n/8] &= ~(1 << (n % 8))
521 #define mutt_bit_toggle(v,n) v[n/8] ^= (1 << (n % 8))
522 #define mutt_bit_isset(v,n) (v[n/8] & (1 << (n % 8)))
523 
524 #define set_option(x) mutt_bit_set(Options,x)
525 #define unset_option(x) mutt_bit_unset(Options,x)
526 #define toggle_option(x) mutt_bit_toggle(Options,x)
527 #define option(x) mutt_bit_isset(Options,x)
528 
529 typedef struct list_t
530 {
531   char *data;
532   struct list_t *next;
533 } LIST;
534 
535 typedef struct rx_list_t
536 {
537   REGEXP *rx;
538   struct rx_list_t *next;
539 } RX_LIST;
540 
541 typedef struct spam_list_t
542 {
543   REGEXP *rx;
544   int     nmatch;
545   char   *template;
546   struct spam_list_t *next;
547 } SPAM_LIST;
548 
549 #define mutt_new_list() safe_calloc (1, sizeof (LIST))
550 #define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST))
551 #define mutt_new_spam_list() safe_calloc (1, sizeof (SPAM_LIST))
552 void mutt_free_list (LIST **);
553 void mutt_free_rx_list (RX_LIST **);
554 void mutt_free_spam_list (SPAM_LIST **);
555 LIST *mutt_copy_list (LIST *);
556 int mutt_matches_ignore (const char *, LIST *);
557 
558 /* add an element to a list */
559 LIST *mutt_add_list (LIST *, const char *);
560 LIST *mutt_add_list_n (LIST*, const void *, size_t);
561 LIST *mutt_find_list (LIST *, const char *);
562 int mutt_remove_from_rx_list (RX_LIST **l, const char *str);
563 
564 void mutt_init (int, LIST *);
565 
566 typedef struct alias
567 {
568   struct alias *self;		/* XXX - ugly hack */
569   char *name;
570   ADDRESS *addr;
571   struct alias *next;
572   short tagged;
573   short del;
574   short num;
575 } ALIAS;
576 
577 typedef struct envelope
578 {
579   ADDRESS *return_path;
580   ADDRESS *from;
581   ADDRESS *to;
582   ADDRESS *cc;
583   ADDRESS *bcc;
584   ADDRESS *sender;
585   ADDRESS *reply_to;
586   ADDRESS *mail_followup_to;
587   char *list_post;		/* this stores a mailto URL, or nothing */
588   char *subject;
589   char *real_subj;		/* offset of the real subject */
590   char *message_id;
591   char *supersedes;
592   char *date;
593   char *x_label;
594   BUFFER *spam;
595   LIST *references;		/* message references (in reverse order) */
596   LIST *in_reply_to;		/* in-reply-to header content */
597   LIST *userhdrs;		/* user defined headers */
598 
599   unsigned int irt_changed : 1; /* In-Reply-To changed to link/break threads */
600   unsigned int refs_changed : 1; /* References changed to break thread */
601 } ENVELOPE;
602 
603 typedef struct parameter
604 {
605   char *attribute;
606   char *value;
607   struct parameter *next;
608 } PARAMETER;
609 
610 /* Information that helps in determing the Content-* of an attachment */
611 typedef struct content
612 {
613   long hibin;              /* 8-bit characters */
614   long lobin;              /* unprintable 7-bit chars (eg., control chars) */
615   long crlf;		   /* '\r' and '\n' characters */
616   long ascii;              /* number of ascii chars */
617   long linemax;            /* length of the longest line in the file */
618   unsigned int space : 1;  /* whitespace at the end of lines? */
619   unsigned int binary : 1; /* long lines, or CR not in CRLF pair */
620   unsigned int from : 1;   /* has a line beginning with "From "? */
621   unsigned int dot : 1;    /* has a line consisting of a single dot? */
622   unsigned int cr : 1;     /* has CR, even when in a CRLF pair */
623 } CONTENT;
624 
625 typedef struct body
626 {
627   char *xtype;			/* content-type if x-unknown */
628   char *subtype;                /* content-type subtype */
629   PARAMETER *parameter;         /* parameters of the content-type */
630   char *description;            /* content-description */
631   char *form_name;		/* Content-Disposition form-data name param */
632   long hdr_offset;              /* offset in stream where the headers begin.
633 				 * this info is used when invoking metamail,
634 				 * where we need to send the headers of the
635 				 * attachment
636 				 */
637   LOFF_T offset;                /* offset where the actual data begins */
638   LOFF_T length;                /* length (in bytes) of attachment */
639   char *filename;               /* when sending a message, this is the file
640 				 * to which this structure refers
641 				 */
642   char *d_filename;		/* filename to be used for the
643 				 * content-disposition header.
644 				 * If NULL, filename is used
645 				 * instead.
646 				 */
647   char *charset;                /* charset of attached file */
648   CONTENT *content;             /* structure used to store detailed info about
649 				 * the content of the attachment.  this is used
650 				 * to determine what content-transfer-encoding
651 				 * is required when sending mail.
652 				 */
653   struct body *next;            /* next attachment in the list */
654   struct body *parts;           /* parts of a multipart or message/rfc822 */
655   struct header *hdr;		/* header information for message/rfc822 */
656 
657   struct attachptr *aptr;	/* Menu information, used in recvattach.c */
658 
659   signed short attach_count;
660 
661   time_t stamp;			/* time stamp of last
662 				 * encoding update.
663 				 */
664 
665   unsigned int type : 4;        /* content-type primary type */
666   unsigned int encoding : 3;    /* content-transfer-encoding */
667   unsigned int disposition : 2; /* content-disposition */
668   unsigned int use_disp : 1;    /* Content-Disposition uses filename= ? */
669   unsigned int unlink : 1;      /* flag to indicate the the file named by
670 				 * "filename" should be unlink()ed before
671 				 * free()ing this structure
672 				 */
673   unsigned int tagged : 1;
674   unsigned int deleted : 1;	/* attachment marked for deletion */
675 
676   unsigned int noconv : 1;	/* don't do character set conversion */
677   unsigned int force_charset : 1;
678   				/* send mode: don't adjust the character
679 				 * set when in send-mode.
680 				 */
681   unsigned int is_signed_data : 1; /* A lot of MUAs don't indicate
682                                       S/MIME signed-data correctly,
683                                       e.g. they use foo.p7m even for
684                                       the name of signed data.  This
685                                       flag is used to keep track of
686                                       the actual message type.  It
687                                       gets set during the verification
688                                       (which is done if the encryption
689                                       try failed) and check by the
690                                       function to figure the type of
691                                       the message. */
692 
693   unsigned int goodsig : 1;	/* good cryptographic signature */
694   unsigned int warnsig : 1;     /* maybe good signature */
695   unsigned int badsig : 1;	/* bad cryptographic signature (needed to check encrypted s/mime-signatures) */
696 
697   unsigned int collapsed : 1;	/* used by recvattach */
698   unsigned int attach_qualifies : 1;
699 
700 } BODY;
701 
702 /* #3279: AIX defines conflicting struct thread */
703 typedef struct mutt_thread THREAD;
704 
705 typedef struct header
706 {
707   unsigned int security : 11;  /* bit 0-6: flags, bit 7,8: application.
708 				 see: crypt.h pgplib.h, smime.h */
709 
710   unsigned int mime : 1;    		/* has a MIME-Version header? */
711   unsigned int flagged : 1; 		/* marked important? */
712   unsigned int tagged : 1;
713   unsigned int deleted : 1;
714   unsigned int changed : 1;
715   unsigned int attach_del : 1; 		/* has an attachment marked for deletion */
716   unsigned int old : 1;
717   unsigned int read : 1;
718   unsigned int expired : 1; 		/* already expired? */
719   unsigned int superseded : 1; 		/* got superseded? */
720   unsigned int replied : 1;
721   unsigned int subject_changed : 1; 	/* used for threading */
722   unsigned int threaded : 1;	    	/* used for threading */
723   unsigned int display_subject : 1; 	/* used for threading */
724   unsigned int recip_valid : 1;  	/* is_recipient is valid */
725   unsigned int active : 1;	    	/* message is not to be removed */
726   unsigned int trash : 1;		/* message is marked as trashed on disk.
727 					 * This flag is used by the maildir_trash
728 					 * option.
729 					 */
730 
731   /* timezone of the sender of this message */
732   unsigned int zhours : 5;
733   unsigned int zminutes : 6;
734   unsigned int zoccident : 1;
735 
736   /* bits used for caching when searching */
737   unsigned int searched : 1;
738   unsigned int matched : 1;
739 
740   /* tells whether the attachment count is valid */
741   unsigned int attach_valid : 1;
742 
743   /* the following are used to support collapsing threads  */
744   unsigned int collapsed : 1; 	/* is this message part of a collapsed thread? */
745   unsigned int limited : 1;   	/* is this message in a limited view?  */
746   size_t num_hidden;          	/* number of hidden messages in this view */
747 
748   short recipient;		/* user_is_recipient()'s return value, cached */
749 
750   int pair; 			/* color-pair to use when displaying in the index */
751 
752   time_t date_sent;     	/* time when the message was sent (UTC) */
753   time_t received;      	/* time when the message was placed in the mailbox */
754   LOFF_T offset;          	/* where in the stream does this message begin? */
755   int lines;			/* how many lines in the body of this message? */
756   int index;			/* the absolute (unsorted) message number */
757   int msgno;			/* number displayed to the user */
758   int virtual;			/* virtual message number */
759   int score;
760   ENVELOPE *env;		/* envelope information */
761   BODY *content;		/* list of MIME parts */
762   char *path;
763 
764   char *tree;           	/* character string to print thread tree */
765   THREAD *thread;
766 
767   /* Number of qualifying attachments in message, if attach_valid */
768   short attach_total;
769 
770 #ifdef MIXMASTER
771   LIST *chain;
772 #endif
773 
774 #ifdef USE_POP
775   int refno;			/* message number on server */
776 #endif
777 
778 #if defined USE_POP || defined USE_IMAP
779   void *data;            	/* driver-specific data */
780 #endif
781 
782   char *maildir_flags;		/* unknown maildir flags */
783 } HEADER;
784 
785 struct mutt_thread
786 {
787   unsigned int fake_thread : 1;
788   unsigned int duplicate_thread : 1;
789   unsigned int sort_children : 1;
790   unsigned int check_subject : 1;
791   unsigned int visible : 1;
792   unsigned int deep : 1;
793   unsigned int subtree_visible : 2;
794   unsigned int next_subtree_visible : 1;
795   THREAD *parent;
796   THREAD *child;
797   THREAD *next;
798   THREAD *prev;
799   HEADER *message;
800   HEADER *sort_key;
801 };
802 
803 
804 /* flag to mutt_pattern_comp() */
805 #define M_FULL_MSG	(1<<0)	/* enable body and header matching */
806 
807 typedef enum {
808   M_MATCH_FULL_ADDRESS = 1
809 } pattern_exec_flag;
810 
811 typedef struct group_t
812 {
813   ADDRESS *as;
814   RX_LIST *rs;
815   char *name;
816 } group_t;
817 
818 typedef struct group_context_t
819 {
820   group_t *g;
821   struct group_context_t *next;
822 } group_context_t;
823 
824 typedef struct pattern_t
825 {
826   short op;
827   unsigned int not : 1;
828   unsigned int alladdr : 1;
829   unsigned int stringmatch : 1;
830   unsigned int groupmatch : 1;
831   unsigned int ign_case : 1;		/* ignore case for local stringmatch searches */
832   int min;
833   int max;
834   struct pattern_t *next;
835   struct pattern_t *child;		/* arguments to logical op */
836   union
837   {
838     regex_t *rx;
839     group_t *g;
840     char *str;
841   } p;
842 } pattern_t;
843 
844 /* ACL Rights */
845 enum
846 {
847   M_ACL_LOOKUP = 0,
848   M_ACL_READ,
849   M_ACL_SEEN,
850   M_ACL_WRITE,
851   M_ACL_INSERT,
852   M_ACL_POST,
853   M_ACL_CREATE,
854   M_ACL_DELMX,
855   M_ACL_DELETE,
856   M_ACL_EXPUNGE,
857   M_ACL_ADMIN,
858 
859   RIGHTSMAX
860 };
861 
862 typedef struct _context
863 {
864   char *path;
865   FILE *fp;
866   time_t mtime;
867   off_t size;
868   off_t vsize;
869   char *pattern;                /* limit pattern string */
870   pattern_t *limit_pattern;     /* compiled limit pattern */
871   HEADER **hdrs;
872   HEADER *last_tag;		/* last tagged msg. used to link threads */
873   THREAD *tree;			/* top of thread tree */
874   HASH *id_hash;		/* hash table by msg id */
875   HASH *subj_hash;		/* hash table by subject */
876   HASH *thread_hash;		/* hash table for threading */
877   int *v2r;			/* mapping from virtual to real msgno */
878   int hdrmax;			/* number of pointers in hdrs */
879   int msgcount;			/* number of messages in the mailbox */
880   int vcount;			/* the number of virtual messages */
881   int tagged;			/* how many messages are tagged? */
882   int new;			/* how many new messages? */
883   int unread;			/* how many unread messages? */
884   int deleted;			/* how many deleted messages */
885   int flagged;			/* how many flagged messages */
886   int msgnotreadyet;		/* which msg "new" in pager, -1 if none */
887 
888   short magic;			/* mailbox type */
889 
890   unsigned char rights[(RIGHTSMAX + 7)/8];	/* ACL bits */
891 
892   unsigned int locked : 1;	/* is the mailbox locked? */
893   unsigned int changed : 1;	/* mailbox has been modified */
894   unsigned int readonly : 1;    /* don't allow changes to the mailbox */
895   unsigned int dontwrite : 1;   /* dont write the mailbox on close */
896   unsigned int append : 1;	/* mailbox is opened in append mode */
897   unsigned int quiet : 1;	/* inhibit status messages? */
898   unsigned int collapsed : 1;   /* are all threads collapsed? */
899   unsigned int closing : 1;	/* mailbox is being closed */
900 
901   /* driver hooks */
902   void *data;			/* driver specific data */
903   int (*mx_close)(struct _context *);
904 } CONTEXT;
905 
906 typedef struct
907 {
908   FILE *fpin;
909   FILE *fpout;
910   char *prefix;
911   int flags;
912 } STATE;
913 
914 /* used by enter.c */
915 
916 typedef struct
917 {
918   wchar_t *wbuf;
919   size_t wbuflen;
920   size_t lastchar;
921   size_t curpos;
922   size_t begin;
923   int	 tabs;
924 } ENTER_STATE;
925 
926 /* flags for the STATE struct */
927 #define M_DISPLAY	(1<<0) /* output is displayed to the user */
928 #define M_VERIFY	(1<<1) /* perform signature verification */
929 #define M_PENDINGPREFIX (1<<2) /* prefix to write, but character must follow */
930 #define M_WEED          (1<<3) /* weed headers even when not in display mode */
931 #define M_CHARCONV	(1<<4) /* Do character set conversions */
932 #define M_PRINTING	(1<<5) /* are we printing? - M_DISPLAY "light" */
933 #define M_REPLYING	(1<<6) /* are we replying? */
934 #define M_FIRSTDONE	(1<<7) /* the first attachment has been done */
935 
936 #define state_set_prefix(s) ((s)->flags |= M_PENDINGPREFIX)
937 #define state_reset_prefix(s) ((s)->flags &= ~M_PENDINGPREFIX)
938 #define state_puts(x,y) fputs(x,(y)->fpout)
939 #define state_putc(x,y) fputc(x,(y)->fpout)
940 
941 void state_mark_attach (STATE *);
942 void state_attach_puts (const char *, STATE *);
943 void state_prefix_putc (char, STATE *);
944 int  state_printf(STATE *, const char *, ...);
945 int state_putwc (wchar_t, STATE *);
946 int state_putws (const wchar_t *, STATE *);
947 
948 /* for attachment counter */
949 typedef struct
950 {
951   char   *major;
952   int     major_int;
953   char   *minor;
954   regex_t minor_rx;
955 } ATTACH_MATCH;
956 
957 #define M_PARTS_TOPLEVEL	(1<<0)	/* is the top-level part */
958 
959 #include "ascii.h"
960 #include "protos.h"
961 #include "lib.h"
962 #include "globals.h"
963 
964 #endif /*MUTT_H*/
965