small detail in m_dirname.
[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   OPTDELETEUNTAG,
256   OPTDELSP,
257   OPTDIGESTCOLLAPSE,
258   OPTDUPTHREADS,
259   OPTEDITHDRS,
260   OPTENCODEFROM,
261   OPTENVFROM,
262   OPTFASTREPLY,
263   OPTFCCATTACH,
264   OPTFCCCLEAR,
265   OPTFOLLOWUPTO,
266   OPTFORCEBUFFYCHECK,
267   OPTFORCENAME,
268   OPTFORWDECODE,
269   OPTFORWQUOTE,
270 #ifdef USE_HCACHE
271   OPTHCACHEVERIFY,
272 #ifdef HAVE_QDBM
273   OPTHCACHECOMPRESS,
274 #endif /* HAVE_QDBM */
275 #endif
276   OPTHDRS,
277   OPTHEADER,
278   OPTHELP,
279   OPTHIDDENHOST,
280   OPTHIDELIMITED,
281   OPTHIDEMISSING,
282   OPTHIDETHREADSUBJECT,
283   OPTHIDETOPLIMITED,
284   OPTHIDETOPMISSING,
285   OPTIGNORELISTREPLYTO,
286   OPTIMAPCHECKSUBSCRIBED,
287   OPTIMAPLSUB,
288   OPTIMAPPASSIVE,
289   OPTIMAPPEEK,
290   OPTIMAPSERVERNOISE,
291 #if defined(USE_SSL) || defined(USE_GNUTLS)
292 # ifndef USE_GNUTLS
293   OPTSSLSYSTEMCERTS,
294   OPTSSLV2,
295 # endif /* !USE_GNUTLS */
296   OPTSSLV3,
297   OPTTLSV1,
298   OPTSSLFORCETLS,
299 #endif /* USE_SSL || USE_GNUTLS */
300   OPTIMPLICITAUTOVIEW,
301   OPTINCLUDEONLYFIRST,
302   OPTKEEPFLAGGED,
303   OPTMAILCAPSANITIZE,
304   OPTMAILDIRTRASH,
305   OPTMARKERS,
306   OPTMARKOLD,
307   OPTMBOXPANE,
308   OPTMENUSCROLL,                /* scroll menu instead of implicit next-page */
309   OPTMENUMOVEOFF,
310   OPTMETAKEY,                   /* interpret ALT-x as ESC-x */
311   OPTMETOO,
312   OPTMHPURGE,
313   OPTMIMEFORWDECODE,
314 #ifdef USE_NNTP
315   OPTMIMESUBJECT,               /* encode subject line with RFC2047 */
316 #endif
317   OPTNARROWTREE,
318   OPTPAGERSTOP,
319   OPTPIPEDECODE,
320   OPTPIPESPLIT,
321   OPTPOPAUTHTRYALL,
322   OPTPOPLAST,
323   OPTPRINTDECODE,
324   OPTPRINTSPLIT,
325   OPTPROMPTAFTER,
326   OPTQUOTEEMPTY,
327   OPTQUOTEQUOTED,
328   OPTREADONLY,
329   OPTREPLYSELF,
330   OPTRESOLVE,
331   OPTREVALIAS,
332   OPTREVNAME,
333   OPTREVREAL,
334   OPTRFC2047PARAMS,
335   OPTSAVEADDRESS,
336   OPTSAVEEMPTY,
337   OPTSAVENAME,
338   OPTSCORE,
339   OPTSIGDASHES,
340   OPTSIGONTOP,
341   OPTSORTRE,
342   OPTSPAMSEP,
343   OPTSTATUSONTOP,
344   OPTSTRICTMAILTO,
345   OPTSTRICTMIME,
346   OPTSTRICTTHREADS,
347   OPTSTRIPWAS,
348   OPTSTUFFQUOTED,
349   OPTSUSPEND,
350   OPTTEXTFLOWED,
351   OPTTHOROUGHSRC,
352   OPTTHREADRECEIVED,
353   OPTTILDE,
354   OPTUNCOLLAPSEJUMP,
355   OPTUSE8BITMIME,
356   OPTUSEDOMAIN,
357   OPTUSEFROM,
358   OPTUSEGPGAGENT,
359 #ifdef HAVE_LIBIDN
360   OPTUSEIDN,
361 #endif
362 #ifdef HAVE_GETADDRINFO
363   OPTUSEIPV6,
364 #endif
365   OPTWAITKEY,
366   OPTWEED,
367   OPTWRAP,
368   OPTWRAPSEARCH,
369   OPTWRITEBCC,                  /* write out a bcc header? */
370   OPTXMAILER,
371   OPTXMAILTO,                   /* 1 if $edit_header is forcebly set */
372   OPTXTERMSETTITLES,
373
374   OPTCRYPTUSEGPGME,
375
376   /* PGP options */
377
378   OPTCRYPTAUTOSIGN,
379   OPTCRYPTAUTOENCRYPT,
380   OPTCRYPTAUTOPGP,
381   OPTCRYPTAUTOSMIME,
382   OPTCRYPTREPLYENCRYPT,
383   OPTCRYPTREPLYSIGN,
384   OPTCRYPTREPLYSIGNENCRYPTED,
385   OPTCRYPTTIMESTAMP,
386   OPTSMIMEISDEFAULT,
387   OPTASKCERTLABEL,
388   OPTSDEFAULTDECRYPTKEY,
389   OPTPGPIGNORESUB,
390   OPTPGPCHECKEXIT,
391   OPTPGPLONGIDS,
392   OPTPGPAUTODEC,
393   OPTPGPRETAINABLESIG,
394   OPTPGPSTRICTENC,
395   OPTFORWDECRYPT,
396   OPTPGPSHOWUNUSABLE,
397   OPTPGPAUTOINLINE,
398   OPTPGPREPLYINLINE,
399
400   /* news options */
401
402 #ifdef USE_NNTP
403   OPTSHOWNEWNEWS,
404   OPTSHOWONLYUNREAD,
405   OPTSAVEUNSUB,
406   OPTLOADDESC,
407   OPTXCOMMENTTO,
408 #endif                          /* USE_NNTP */
409
410   /* pseudo options */
411
412   OPTAUXSORT,                   /* (pseudo) using auxillary sort function */
413   OPTFORCEREFRESH,              /* (pseudo) refresh even during macros */
414   OPTNOCURSES,                  /* (pseudo) when sending in batch mode */
415   OPTNEEDREDRAW,                /* (pseudo) to notify caller of a submenu */
416   OPTSEARCHREVERSE,             /* (pseudo) used by ci_search_command */
417   OPTMSGERR,                    /* (pseudo) used by mutt_error/mutt_message */
418   OPTSEARCHINVALID,             /* (pseudo) used to invalidate the search pat */
419   OPTSIGNALSBLOCKED,            /* (pseudo) using by mutt_block_signals () */
420   OPTSYSSIGNALSBLOCKED,         /* (pseudo) using by mutt_block_signals_system () */
421   OPTNEEDRESORT,                /* (pseudo) used to force a re-sort */
422   OPTRESORTINIT,                /* (pseudo) used to force the next resort to be from scratch */
423   OPTVIEWATTACH,                /* (pseudo) signals that we are viewing attachments */
424   OPTFORCEREDRAWINDEX,          /* (pseudo) used to force a redraw in the main index */
425   OPTFORCEREDRAWPAGER,          /* (pseudo) used to force a redraw in the pager */
426   OPTSORTSUBTHREADS,            /* (pseudo) used when $sort_aux changes */
427   OPTNEEDRESCORE,               /* (pseudo) set when the `score' command is used */
428   OPTATTACHMSG,                 /* (pseudo) used by attach-message */
429   OPTHIDEREAD,                  /* (pseudo) whether or not hide read messages */
430   OPTKEEPQUIET,                 /* (pseudo) shut up the message and refresh
431                                  *          functions while we are executing an
432                                  *          external program.
433                                  */
434   OPTMENUCALLER,                /* (pseudo) tell menu to give caller a take */
435   OPTREDRAWTREE,                /* (pseudo) redraw the thread tree */
436   OPTPGPCHECKTRUST,             /* (pseudo) used by pgp_select_key () */
437   OPTDONTHANDLEPGPKEYS,         /* (pseudo) used to extract PGP keys */
438   OPTUNBUFFEREDINPUT,           /* (pseudo) don't use key buffer */
439
440 #ifdef USE_NNTP
441   OPTNEWS,                      /* (pseudo) used to change reader mode */
442   OPTNEWSSEND,                  /* (pseudo) used to change behavior when posting */
443   OPTNEWSCACHE,                 /* (pseudo) used to indicate if news cache exist */
444 #endif
445   OPTSHORTENHIERARCHY,          /* set when to shorten "hierarchies" in the sidebar */
446   OPTSIDEBARNEWMAILONLY,
447   OPTMAX
448 };
449
450 #define mutt_bit_alloc(n) p_new(char, (n + 7) / 8)
451 #define mutt_bit_set(v,n) v[n/8] |= (1 << (n % 8))
452 #define mutt_bit_unset(v,n) v[n/8] &= ~(1 << (n % 8))
453 #define mutt_bit_toggle(v,n) v[n/8] ^= (1 << (n % 8))
454 #define mutt_bit_isset(v,n) (v[n/8] & (1 << (n % 8)))
455
456 #define set_option(x) mutt_bit_set(Options,x)
457 #define unset_option(x) mutt_bit_unset(Options,x)
458 #define toggle_option(x) mutt_bit_toggle(Options,x)
459 #define option(x) mutt_bit_isset(Options,x)
460
461 int mutt_matches_ignore (const char *, string_list_t *);
462
463 void mutt_init (int, string_list_t *);
464
465 typedef struct thread {
466   unsigned int fake_thread:1;
467   unsigned int duplicate_thread:1;
468   unsigned int sort_children:1;
469   unsigned int check_subject:1;
470   unsigned int visible:1;
471   unsigned int deep:1;
472   unsigned int subtree_visible:2;
473   unsigned int next_subtree_visible:1;
474   struct thread *parent;
475   struct thread *child;
476   struct thread *next;
477   struct thread *prev;
478   HEADER *message;
479   HEADER *sort_key;
480 } THREAD;
481
482 typedef struct compress_info compress_info;
483 typedef struct pattern_t pattern_t;
484
485 typedef struct {
486   char *path;
487   FILE *fp;
488   time_t mtime;
489   time_t mtime_cur;             /* used with maildir folders */
490   off_t size;
491   off_t vsize;
492   char *pattern;                /* limit pattern string */
493   pattern_t *limit_pattern;     /* compiled limit pattern */
494   HEADER **hdrs;
495   HEADER *last_tag;             /* last tagged msg. used to link threads */
496   THREAD *tree;                 /* top of thread tree */
497   HASH *id_hash;                /* hash table by msg id */
498   HASH *subj_hash;              /* hash table by subject */
499   HASH *thread_hash;            /* hash table for threading */
500   int *v2r;                     /* mapping from virtual to real msgno */
501   int hdrmax;                   /* number of pointers in hdrs */
502   int msgcount;                 /* number of messages in the mailbox */
503   int vcount;                   /* the number of virtual messages */
504   int tagged;                   /* how many messages are tagged? */
505   int new;                      /* how many new messages? */
506   int unread;                   /* how many unread messages? */
507   int deleted;                  /* how many deleted messages */
508   int appended;                 /* how many saved messages? */
509   int flagged;                  /* how many flagged messages */
510   int msgnotreadyet;            /* which msg "new" in pager, -1 if none */
511   void *data;                   /* driver specific data */
512
513   short magic;                  /* mailbox type */
514
515   compress_info *cinfo;         /* compressed mbox module private data */
516   char *realpath;               /* path to compressed mailbox */
517
518   unsigned int locked:1;        /* is the mailbox locked? */
519   unsigned int changed:1;       /* mailbox has been modified */
520   unsigned int readonly:1;      /* don't allow changes to the mailbox */
521   unsigned int dontwrite:1;     /* dont write the mailbox on close */
522   unsigned int append:1;        /* mailbox is opened in append mode */
523   unsigned int quiet:1;         /* inhibit status messages? */
524   unsigned int collapsed:1;     /* are all threads collapsed? */
525   unsigned int closing:1;       /* mailbox is being closed */
526   unsigned int counting:1;      /* do we just want to cound? */
527 } CONTEXT;
528
529 /* for attachment counter */
530 typedef struct {
531   char *major;
532   int major_int;
533   const char *minor;
534   regex_t minor_rx;
535 } ATTACH_MATCH;
536
537 /* Flags for mutt_count_body_parts() */
538 #define M_PARTS_TOPLEVEL (1<<0) /* is the top-level part */
539 #define M_PARTS_RECOUNT (1<<1) /* force recount */
540
541 #include "protos.h"
542 #include "globals.h"
543
544 #endif /* !_MUTT_H */