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