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