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