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