continue the include dance
[apps/madmutt.git] / mutt.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 2004 g10 Code GmbH
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10
11 #ifndef _MUTT_H
12 #define _MUTT_H
13
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17
18 #include <stdio.h>
19 #include <limits.h>
20 #include <signal.h>
21
22 #ifndef _POSIX_PATH_MAX
23 #include <posix1_lim.h>
24 #endif
25
26 #include <lib-lib/buffer.h>
27 #include <lib-lib/hash.h>
28 #include <lib-lib/list.h>
29 #include <lib-lib/rx.h>
30
31 #include <lib-mime/mime.h>
32
33 #define MUTT_VERSION (VERSION)
34
35 /* nifty trick I stole from ELM 2.5alpha. */
36 #ifdef MAIN_C
37 #define WHERE
38 #define INITVAL(x) = x
39 #else
40 #define WHERE extern
41 #define INITVAL(x)
42 #endif
43
44 typedef struct {
45   int ch;                       /* raw key pressed */
46   int op;                       /* function op */
47 } event_t;
48
49 /* flags for mutt_FormatString() */
50 typedef enum {
51   M_FORMAT_FORCESUBJ = (1 << 0),        /* print the subject even if unchanged */
52   M_FORMAT_TREE = (1 << 1),     /* draw the thread tree */
53   M_FORMAT_MAKEPRINT = (1 << 2),        /* make sure that all chars are printable */
54   M_FORMAT_OPTIONAL = (1 << 3),
55   M_FORMAT_STAT_FILE = (1 << 4),        /* used by mutt_attach_fmt */
56   M_FORMAT_ARROWCURSOR = (1 << 5),      /* reserve space for arrow_cursor */
57   M_FORMAT_INDEX = (1 << 6)     /* this is a main index entry */
58 } format_flag;
59
60 /* types for mutt_add_hook() */
61 #define M_FOLDERHOOK    1
62 #define M_MBOXHOOK      (1<<1)
63 #define M_SENDHOOK      (1<<2)
64 #define M_FCCHOOK       (1<<3)
65 #define M_SAVEHOOK      (1<<4)
66 #define M_CHARSETHOOK   (1<<5)
67 #define M_ICONVHOOK     (1<<6)
68 #define M_MESSAGEHOOK   (1<<7)
69 #define M_CRYPTHOOK     (1<<8)
70 #define M_ACCOUNTHOOK   (1<<9)
71 #define M_REPLYHOOK     (1<<10)
72 #define M_SEND2HOOK     (1<<11)
73
74 #define M_OPENHOOK      (1<<12)
75 #define M_APPENDHOOK    (1<<13)
76 #define M_CLOSEHOOK     (1<<14)
77
78 /* tree characters for linearize_tree and print_enriched_string */
79 #define M_TREE_LLCORNER         1
80 #define M_TREE_ULCORNER         2
81 #define M_TREE_LTEE             3
82 #define M_TREE_HLINE            4
83 #define M_TREE_VLINE            5
84 #define M_TREE_SPACE            6
85 #define M_TREE_RARROW           7
86 #define M_TREE_STAR             8
87 #define M_TREE_HIDDEN           9
88 #define M_TREE_EQUALS           10
89 #define M_TREE_TTEE             11
90 #define M_TREE_BTEE             12
91 #define M_TREE_MISSING          13
92 #define M_TREE_MAX              14
93
94 #define M_THREAD_COLLAPSE       (1<<0)
95 #define M_THREAD_UNCOLLAPSE     (1<<1)
96 #define M_THREAD_GET_HIDDEN     (1<<2)
97 #define M_THREAD_UNREAD         (1<<3)
98 #define M_THREAD_NEXT_UNREAD    (1<<4)
99
100 enum {
101   /* modes for mutt_view_attachment() */
102   M_REGULAR = 1,
103   M_MAILCAP,
104   M_AS_TEXT,
105
106   /* action codes used by mutt_set_flag() and mutt_pattern_function() */
107   M_ALL,
108   M_NONE,
109   M_NEW,
110   M_OLD,
111   M_REPLIED,
112   M_READ,
113   M_UNREAD,
114   M_DELETE,
115   M_UNDELETE,
116   M_DELETED,
117   M_APPENDED,
118   M_PURGED,
119   M_FLAG,
120   M_TAG,
121   M_UNTAG,
122   M_LIMIT,
123   M_EXPIRED,
124   M_SUPERSEDED,
125
126   /* actions for mutt_pattern_comp/mutt_pattern_exec */
127   M_AND,
128   M_OR,
129   M_TO,
130   M_CC,
131   M_COLLAPSED,
132   M_SUBJECT,
133   M_FROM,
134   M_DATE,
135   M_DATE_RECEIVED,
136   M_DUPLICATED,
137   M_UNREFERENCED,
138   M_ID,
139   M_BODY,
140   M_HEADER,
141   M_HORMEL,
142   M_WHOLE_MSG,
143   M_SENDER,
144   M_MESSAGE,
145   M_SCORE,
146   M_SIZE,
147   M_REFERENCE,
148   M_RECIPIENT,
149   M_LIST,
150   M_SUBSCRIBED_LIST,
151   M_PERSONAL_RECIP,
152   M_PERSONAL_FROM,
153   M_ADDRESS,
154   M_CRYPT_SIGN,
155   M_CRYPT_VERIFIED,
156   M_CRYPT_ENCRYPT,
157   M_PGP_KEY,
158   M_XLABEL,
159   M_MIMEATTACH,
160 #ifdef USE_NNTP
161   M_NEWSGROUPS,
162 #endif
163   M_REALNAME,
164   M_MULTIPART,
165
166   /* Options for Mailcap lookup */
167   M_EDIT,
168   M_COMPOSE,
169   M_PRINT,
170   M_AUTOVIEW,
171
172   /* options for socket code */
173   M_NEW_SOCKET,
174 #ifdef USE_SSL
175   M_NEW_SSL_SOCKET,
176 #endif
177
178   /* Options for mutt_save_attachment */
179   M_SAVE_APPEND,
180   M_SAVE_OVERWRITE
181 };
182
183 /* possible arguments to set_quadoption() */
184 enum {
185   M_NO,
186   M_YES,
187   M_ASKNO,
188   M_ASKYES
189 };
190
191 /* quad-option vars */
192 enum {
193   OPT_ABORT,
194   OPT_ATTACH,
195   OPT_BOUNCE,
196   OPT_COPY,
197   OPT_DELETE,
198   OPT_FORWEDIT,
199   OPT_INCLUDE,
200   OPT_IMAPRECONNECT,
201   OPT_MFUPTO,
202   OPT_MIMEFWD,
203   OPT_MIMEFWDREST,
204   OPT_MOVE,
205   OPT_PGPMIMEAUTO,              /* ask to revert to PGP/MIME when inline fails */
206   OPT_POPDELETE,
207   OPT_POPRECONNECT,
208   OPT_POSTPONE,
209   OPT_PRINT,
210   OPT_QUIT,
211   OPT_REPLYTO,
212   OPT_RECALL,
213 #if defined(USE_SSL) || defined(USE_GNUTLS)
214   OPT_SSLSTARTTLS,
215 #endif
216   OPT_SUBJECT,
217   OPT_VERIFYSIG,                /* verify PGP signatures */
218   OPT_LISTREPLY,
219 #ifdef USE_NNTP
220   OPT_TOMODERATED,
221   OPT_NNTPRECONNECT,
222   OPT_CATCHUP,
223   OPT_FOLLOWUPTOPOSTER,
224 #endif                          /* USE_NNTP */
225
226   /* THIS MUST BE THE LAST VALUE. */
227   OPT_MAX
228 };
229
230 /* flags to ci_send_message() */
231 #define SENDREPLY       (1<<0)
232 #define SENDGROUPREPLY  (1<<1)
233 #define SENDLISTREPLY   (1<<2)
234 #define SENDFORWARD     (1<<3)
235 #define SENDPOSTPONED   (1<<4)
236 #define SENDBATCH       (1<<5)
237 #define SENDKEY         (1<<6)
238 #define SENDRESEND      (1<<7)
239 #define SENDNEWS        (1<<8)
240
241 /* flags to _mutt_select_file() */
242 #define M_SEL_BUFFY     (1<<0)
243 #define M_SEL_MULTI     (1<<1)
244 #define M_SEL_FOLDER    (1<<2)
245
246 /* flags for parse_spam_list */
247 #define M_SPAM          1
248 #define M_NOSPAM        2
249
250 /* boolean vars */
251 enum {
252   OPTALLOW8BIT,
253   OPTALLOWANSI,
254   OPTARROWCURSOR,
255   OPTASCIICHARS,
256   OPTASKBCC,
257   OPTASKCC,
258   OPTASKFOLLOWUP,
259   OPTASKXCOMMENTTO,
260   OPTATTACHSPLIT,
261   OPTAUTOEDIT,
262   OPTAUTOTAG,
263   OPTBEEP,
264   OPTBEEPNEW,
265   OPTBOUNCEDELIVERED,
266   OPTBRAILLEFRIENDLY,
267   OPTCHECKNEW,
268   OPTCOLLAPSEUNREAD,
269   OPTCONFIRMAPPEND,
270   OPTCONFIRMCREATE,
271   OPTCOUNTATTACH,
272   OPTDELETEUNTAG,
273   OPTDELSP,
274   OPTDIGESTCOLLAPSE,
275   OPTDUPTHREADS,
276   OPTEDITHDRS,
277   OPTENCODEFROM,
278   OPTENVFROM,
279   OPTFASTREPLY,
280   OPTFCCATTACH,
281   OPTFCCCLEAR,
282   OPTFOLLOWUPTO,
283   OPTFORCEBUFFYCHECK,
284   OPTFORCENAME,
285   OPTFORWDECODE,
286   OPTFORWQUOTE,
287 #ifdef USE_HCACHE
288   OPTHCACHEVERIFY,
289 #ifdef HAVE_QDBM
290   OPTHCACHECOMPRESS,
291 #endif /* HAVE_QDBM */
292 #endif
293   OPTHDRS,
294   OPTHEADER,
295   OPTHELP,
296   OPTHIDDENHOST,
297   OPTHIDELIMITED,
298   OPTHIDEMISSING,
299   OPTHIDETHREADSUBJECT,
300   OPTHIDETOPLIMITED,
301   OPTHIDETOPMISSING,
302   OPTIGNORELISTREPLYTO,
303   OPTIMAPCHECKSUBSCRIBED,
304   OPTIMAPLSUB,
305   OPTIMAPPASSIVE,
306   OPTIMAPPEEK,
307   OPTIMAPSERVERNOISE,
308 #if defined(USE_SSL) || defined(USE_GNUTLS)
309 # ifndef USE_GNUTLS
310   OPTSSLSYSTEMCERTS,
311   OPTSSLV2,
312 # endif /* !USE_GNUTLS */
313   OPTSSLV3,
314   OPTTLSV1,
315   OPTSSLFORCETLS,
316 #endif /* USE_SSL || USE_GNUTLS */
317   OPTIMPLICITAUTOVIEW,
318   OPTINCLUDEONLYFIRST,
319   OPTKEEPFLAGGED,
320   OPTMAILCAPSANITIZE,
321   OPTMAILDIRTRASH,
322   OPTMARKERS,
323   OPTMARKOLD,
324   OPTMBOXPANE,
325   OPTMENUSCROLL,                /* scroll menu instead of implicit next-page */
326   OPTMENUMOVEOFF,
327   OPTMETAKEY,                   /* interpret ALT-x as ESC-x */
328   OPTMETOO,
329   OPTMHPURGE,
330   OPTMIMEFORWDECODE,
331 #ifdef USE_NNTP
332   OPTMIMESUBJECT,               /* encode subject line with RFC2047 */
333 #endif
334   OPTNARROWTREE,
335   OPTPAGERSTOP,
336   OPTPIPEDECODE,
337   OPTPIPESPLIT,
338   OPTPOPAUTHTRYALL,
339   OPTPOPLAST,
340   OPTPRINTDECODE,
341   OPTPRINTSPLIT,
342   OPTPROMPTAFTER,
343   OPTQUOTEEMPTY,
344   OPTQUOTEQUOTED,
345   OPTREADONLY,
346   OPTREPLYSELF,
347   OPTRESOLVE,
348   OPTREVALIAS,
349   OPTREVNAME,
350   OPTREVREAL,
351   OPTRFC2047PARAMS,
352   OPTSAVEADDRESS,
353   OPTSAVEEMPTY,
354   OPTSAVENAME,
355   OPTSCORE,
356   OPTSIGDASHES,
357   OPTSIGONTOP,
358   OPTSORTRE,
359   OPTSPAMSEP,
360   OPTSTATUSONTOP,
361   OPTSTRICTMAILTO,
362   OPTSTRICTMIME,
363   OPTSTRICTTHREADS,
364   OPTSTRIPWAS,
365   OPTSTUFFQUOTED,
366   OPTSUSPEND,
367   OPTTEXTFLOWED,
368   OPTTHOROUGHSRC,
369   OPTTHREADRECEIVED,
370   OPTTILDE,
371   OPTUNCOLLAPSEJUMP,
372   OPTUSE8BITMIME,
373   OPTUSEDOMAIN,
374   OPTUSEFROM,
375   OPTUSEGPGAGENT,
376 #ifdef HAVE_LIBIDN
377   OPTUSEIDN,
378 #endif
379 #ifdef HAVE_GETADDRINFO
380   OPTUSEIPV6,
381 #endif
382   OPTWAITKEY,
383   OPTWEED,
384   OPTWRAP,
385   OPTWRAPSEARCH,
386   OPTWRITEBCC,                  /* write out a bcc header? */
387   OPTXMAILER,
388   OPTXMAILTO,                   /* 1 if $edit_header is forcebly set */
389   OPTXTERMSETTITLES,
390
391   OPTCRYPTUSEGPGME,
392
393   /* PGP options */
394
395   OPTCRYPTAUTOSIGN,
396   OPTCRYPTAUTOENCRYPT,
397   OPTCRYPTAUTOPGP,
398   OPTCRYPTAUTOSMIME,
399   OPTCRYPTREPLYENCRYPT,
400   OPTCRYPTREPLYSIGN,
401   OPTCRYPTREPLYSIGNENCRYPTED,
402   OPTCRYPTTIMESTAMP,
403   OPTSMIMEISDEFAULT,
404   OPTASKCERTLABEL,
405   OPTSDEFAULTDECRYPTKEY,
406   OPTPGPIGNORESUB,
407   OPTPGPCHECKEXIT,
408   OPTPGPLONGIDS,
409   OPTPGPAUTODEC,
410 #if 0
411   OPTPGPENCRYPTSELF,
412 #endif
413   OPTPGPRETAINABLESIG,
414   OPTPGPSTRICTENC,
415   OPTFORWDECRYPT,
416   OPTPGPSHOWUNUSABLE,
417   OPTPGPAUTOINLINE,
418   OPTPGPREPLYINLINE,
419
420   /* news options */
421
422 #ifdef USE_NNTP
423   OPTSHOWNEWNEWS,
424   OPTSHOWONLYUNREAD,
425   OPTSAVEUNSUB,
426   OPTLOADDESC,
427   OPTXCOMMENTTO,
428 #endif                          /* USE_NNTP */
429
430   /* pseudo options */
431
432   OPTAUXSORT,                   /* (pseudo) using auxillary sort function */
433   OPTFORCEREFRESH,              /* (pseudo) refresh even during macros */
434   OPTLOCALES,                   /* (pseudo) set if user has valid locale definition */
435   OPTNOCURSES,                  /* (pseudo) when sending in batch mode */
436   OPTNEEDREDRAW,                /* (pseudo) to notify caller of a submenu */
437   OPTSEARCHREVERSE,             /* (pseudo) used by ci_search_command */
438   OPTMSGERR,                    /* (pseudo) used by mutt_error/mutt_message */
439   OPTSEARCHINVALID,             /* (pseudo) used to invalidate the search pat */
440   OPTSIGNALSBLOCKED,            /* (pseudo) using by mutt_block_signals () */
441   OPTSYSSIGNALSBLOCKED,         /* (pseudo) using by mutt_block_signals_system () */
442   OPTNEEDRESORT,                /* (pseudo) used to force a re-sort */
443   OPTRESORTINIT,                /* (pseudo) used to force the next resort to be from scratch */
444   OPTVIEWATTACH,                /* (pseudo) signals that we are viewing attachments */
445   OPTFORCEREDRAWINDEX,          /* (pseudo) used to force a redraw in the main index */
446   OPTFORCEREDRAWPAGER,          /* (pseudo) used to force a redraw in the pager */
447   OPTSORTSUBTHREADS,            /* (pseudo) used when $sort_aux changes */
448   OPTNEEDRESCORE,               /* (pseudo) set when the `score' command is used */
449   OPTATTACHMSG,                 /* (pseudo) used by attach-message */
450   OPTHIDEREAD,                  /* (pseudo) whether or not hide read messages */
451   OPTKEEPQUIET,                 /* (pseudo) shut up the message and refresh
452                                  *          functions while we are executing an
453                                  *          external program.
454                                  */
455   OPTMENUCALLER,                /* (pseudo) tell menu to give caller a take */
456   OPTREDRAWTREE,                /* (pseudo) redraw the thread tree */
457   OPTPGPCHECKTRUST,             /* (pseudo) used by pgp_select_key () */
458   OPTDONTHANDLEPGPKEYS,         /* (pseudo) used to extract PGP keys */
459   OPTUNBUFFEREDINPUT,           /* (pseudo) don't use key buffer */
460
461 #ifdef USE_NNTP
462   OPTNEWS,                      /* (pseudo) used to change reader mode */
463   OPTNEWSSEND,                  /* (pseudo) used to change behavior when posting */
464   OPTNEWSCACHE,                 /* (pseudo) used to indicate if news cache exist */
465 #endif
466   OPTSHORTENHIERARCHY,          /* set when to shorten "hierarchies" in the sidebar */
467   OPTSIDEBARNEWMAILONLY,
468   OPTMAX
469 };
470
471 #define mutt_bit_alloc(n) p_new(char, (n + 7) / 8)
472 #define mutt_bit_set(v,n) v[n/8] |= (1 << (n % 8))
473 #define mutt_bit_unset(v,n) v[n/8] &= ~(1 << (n % 8))
474 #define mutt_bit_toggle(v,n) v[n/8] ^= (1 << (n % 8))
475 #define mutt_bit_isset(v,n) (v[n/8] & (1 << (n % 8)))
476
477 #define set_option(x) mutt_bit_set(Options,x)
478 #define unset_option(x) mutt_bit_unset(Options,x)
479 #define toggle_option(x) mutt_bit_toggle(Options,x)
480 #define option(x) mutt_bit_isset(Options,x)
481
482 typedef struct spam_list_t {
483   rx_t *rx;
484   int nmatch;
485   char *template;
486   struct spam_list_t *next;
487 } SPAM_LIST;
488
489
490 #define mutt_new_spam_list() p_new(SPAM_LIST, 1)
491 void mutt_free_spam_list (SPAM_LIST **);
492
493 int mutt_matches_ignore (const char *, string_list_t *);
494
495 void mutt_init (int, string_list_t *);
496
497 typedef struct thread {
498   unsigned int fake_thread:1;
499   unsigned int duplicate_thread:1;
500   unsigned int sort_children:1;
501   unsigned int check_subject:1;
502   unsigned int visible:1;
503   unsigned int deep:1;
504   unsigned int subtree_visible:2;
505   unsigned int next_subtree_visible:1;
506   struct thread *parent;
507   struct thread *child;
508   struct thread *next;
509   struct thread *prev;
510   HEADER *message;
511   HEADER *sort_key;
512 } THREAD;
513
514
515 /* flag to mutt_pattern_comp() */
516 #define M_FULL_MSG      (1<<0)       /* enable body and header matching */
517
518 typedef enum {
519   M_MATCH_FULL_ADDRESS = 1
520 } pattern_exec_flag;
521
522 typedef struct pattern_t {
523   short op;
524   unsigned int not : 1;
525   unsigned int alladdr : 1;
526   unsigned int stringmatch : 1;
527   int min;
528   int max;
529   struct pattern_t *next;
530   struct pattern_t *child;      /* arguments to logical op */
531   char* str;
532   regex_t *rx;
533 } pattern_t;
534
535 typedef struct {
536   char *path;
537   FILE *fp;
538   time_t mtime;
539   time_t mtime_cur;             /* used with maildir folders */
540   off_t size;
541   off_t vsize;
542   char *pattern;                /* limit pattern string */
543   pattern_t *limit_pattern;     /* compiled limit pattern */
544   HEADER **hdrs;
545   HEADER *last_tag;             /* last tagged msg. used to link threads */
546   THREAD *tree;                 /* top of thread tree */
547   HASH *id_hash;                /* hash table by msg id */
548   HASH *subj_hash;              /* hash table by subject */
549   HASH *thread_hash;            /* hash table for threading */
550   int *v2r;                     /* mapping from virtual to real msgno */
551   int hdrmax;                   /* number of pointers in hdrs */
552   int msgcount;                 /* number of messages in the mailbox */
553   int vcount;                   /* the number of virtual messages */
554   int tagged;                   /* how many messages are tagged? */
555   int new;                      /* how many new messages? */
556   int unread;                   /* how many unread messages? */
557   int deleted;                  /* how many deleted messages */
558   int appended;                 /* how many saved messages? */
559   int flagged;                  /* how many flagged messages */
560   int msgnotreadyet;            /* which msg "new" in pager, -1 if none */
561   void *data;                   /* driver specific data */
562
563   short magic;                  /* mailbox type */
564
565   void *compressinfo;           /* compressed mbox module private data */
566   char *realpath;               /* path to compressed mailbox */
567
568   unsigned int locked:1;        /* is the mailbox locked? */
569   unsigned int changed:1;       /* mailbox has been modified */
570   unsigned int readonly:1;      /* don't allow changes to the mailbox */
571   unsigned int dontwrite:1;     /* dont write the mailbox on close */
572   unsigned int append:1;        /* mailbox is opened in append mode */
573   unsigned int quiet:1;         /* inhibit status messages? */
574   unsigned int collapsed:1;     /* are all threads collapsed? */
575   unsigned int closing:1;       /* mailbox is being closed */
576   unsigned int counting:1;      /* do we just want to cound? */
577 } CONTEXT;
578
579 /* for attachment counter */
580 typedef struct {
581   char *major;
582   int major_int;
583   const char *minor;
584   regex_t minor_rx;
585 } ATTACH_MATCH;
586
587 /* Flags for mutt_count_body_parts() */
588 #define M_PARTS_TOPLEVEL (1<<0) /* is the top-level part */
589 #define M_PARTS_RECOUNT (1<<1) /* force recount */
590
591 #include "protos.h"
592 #include "globals.h"
593
594 #endif /* !_MUTT_H */