PageRenderTime 51ms CodeModel.GetById 24ms app.highlight 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mutt.h

https://bitbucket.org/mutt/mutt
C Header | 1068 lines | 845 code | 107 blank | 116 comment | 8 complexity | 50094e6d5acb102cd13d6d22033d02bf MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0, LGPL-2.1
   1
   2/*
   3 * Copyright (C) 1996-2002,2010,2013 Michael R. Elkins <me@mutt.org>
   4 * Copyright (C) 2004 g10 Code GmbH
   5 * 
   6 *     This program is free software; you can redistribute it and/or modify
   7 *     it under the terms of the GNU General Public License as published by
   8 *     the Free Software Foundation; either version 2 of the License, or
   9 *     (at your option) any later version.
  10 * 
  11 *     This program is distributed in the hope that it will be useful,
  12 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 *     GNU General Public License for more details.
  15 * 
  16 *     You should have received a copy of the GNU General Public License
  17 *     along with this program; if not, write to the Free Software
  18 *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19 */ 
  20
  21#ifndef MUTT_H
  22#define MUTT_H 
  23
  24#include <stdio.h>
  25#include <stdlib.h>
  26#ifdef HAVE_UNISTD_H
  27# include <unistd.h> /* needed for SEEK_SET */
  28#endif
  29#ifdef HAVE_UNIX_H
  30# include <unix.h>   /* needed for snprintf on QNX. */
  31#endif
  32#include <sys/types.h>
  33#include <sys/stat.h>
  34#include <time.h>
  35#include <limits.h>
  36#include <stdarg.h>
  37#include <signal.h>
  38/* On OS X 10.5.x, wide char functions are inlined by default breaking
  39 * --without-wc-funcs compilation
  40 */
  41#ifdef __APPLE_CC__
  42#define _DONT_USE_CTYPE_INLINE_
  43#endif
  44#ifdef HAVE_WCHAR_H
  45# include <wchar.h>
  46#endif
  47#if defined(HAVE_WCTYPE_H) && defined(HAVE_WC_FUNCS)
  48# include <wctype.h>
  49#endif
  50
  51#ifndef _POSIX_PATH_MAX
  52#include <limits.h>
  53#endif
  54
  55/* PATH_MAX is undefined on the hurd */
  56#if !defined(PATH_MAX) && defined(_POSIX_PATH_MAX)
  57#define PATH_MAX _POSIX_PATH_MAX
  58#endif
  59
  60#include <pwd.h>
  61#include <grp.h>
  62
  63#include "rfc822.h"
  64#include "hash.h"
  65#include "charset.h"
  66
  67#ifndef HAVE_WC_FUNCS
  68# ifdef MB_LEN_MAX
  69#  undef MB_LEN_MAX
  70# endif
  71# define MB_LEN_MAX 16
  72#endif
  73
  74/* nifty trick I stole from ELM 2.5alpha. */
  75#ifdef MAIN_C
  76#define WHERE 
  77#define INITVAL(x) = x
  78#else
  79#define WHERE extern
  80#define INITVAL(x) 
  81#endif
  82
  83#define WHERE_DEFINED 1
  84
  85#include "mutt_regex.h"
  86
  87/* flags for mutt_enter_string() */
  88#define  MUTT_ALIAS   1      /* do alias "completion" by calling up the alias-menu */
  89#define  MUTT_FILE    (1<<1) /* do file completion */
  90#define  MUTT_EFILE   (1<<2) /* do file completion, plus incoming folders */
  91#define  MUTT_CMD     (1<<3) /* do completion on previous word */
  92#define  MUTT_PASS    (1<<4) /* password mode (no echo) */
  93#define  MUTT_CLEAR   (1<<5) /* clear input if printable character is pressed */
  94#define  MUTT_COMMAND (1<<6) /* do command completion */
  95#define  MUTT_PATTERN (1<<7) /* pattern mode - only used for history classes */
  96#define  MUTT_LABEL   (1<<8) /* do label completion */
  97
  98/* flags for mutt_get_token() */
  99#define MUTT_TOKEN_EQUAL      1       /* treat '=' as a special */
 100#define MUTT_TOKEN_CONDENSE   (1<<1)  /* ^(char) to control chars (macros) */
 101#define MUTT_TOKEN_SPACE      (1<<2)  /* don't treat whitespace as a term */
 102#define MUTT_TOKEN_QUOTE      (1<<3)  /* don't interpret quotes */
 103#define MUTT_TOKEN_PATTERN    (1<<4)  /* !)|~ are terms (for patterns) */
 104#define MUTT_TOKEN_COMMENT    (1<<5)  /* don't reap comments */
 105#define MUTT_TOKEN_SEMICOLON  (1<<6)  /* don't treat ; as special */
 106
 107typedef struct
 108{
 109  char *data;	/* pointer to data */
 110  char *dptr;	/* current read/write position */
 111  size_t dsize;	/* length of data */
 112  int destroy;	/* destroy `data' when done? */
 113} BUFFER;
 114
 115typedef struct
 116{
 117  int ch; /* raw key pressed */
 118  int op; /* function op */
 119} event_t;
 120
 121/* flags for _mutt_system() */
 122#define MUTT_DETACH_PROCESS	1	/* detach subprocess from group */
 123
 124/* flags for mutt_FormatString() */
 125typedef enum
 126{
 127  MUTT_FORMAT_FORCESUBJ   = (1<<0), /* print the subject even if unchanged */
 128  MUTT_FORMAT_TREE        = (1<<1), /* draw the thread tree */
 129  MUTT_FORMAT_MAKEPRINT   = (1<<2), /* make sure that all chars are printable */
 130  MUTT_FORMAT_OPTIONAL    = (1<<3),
 131  MUTT_FORMAT_STAT_FILE   = (1<<4), /* used by mutt_attach_fmt */
 132  MUTT_FORMAT_ARROWCURSOR = (1<<5), /* reserve space for arrow_cursor */
 133  MUTT_FORMAT_INDEX       = (1<<6), /* this is a main index entry */
 134  MUTT_FORMAT_NOFILTER    = (1<<7)  /* do not allow filtering on this pass */
 135} format_flag;
 136
 137/* types for mutt_add_hook() */
 138#define MUTT_FOLDERHOOK  1
 139#define MUTT_MBOXHOOK    (1<<1)
 140#define MUTT_SENDHOOK    (1<<2)
 141#define MUTT_FCCHOOK     (1<<3)
 142#define MUTT_SAVEHOOK    (1<<4)
 143#define MUTT_CHARSETHOOK (1<<5)
 144#define MUTT_ICONVHOOK   (1<<6)
 145#define MUTT_MESSAGEHOOK (1<<7)
 146#define MUTT_CRYPTHOOK   (1<<8)
 147#define MUTT_ACCOUNTHOOK (1<<9)
 148#define MUTT_REPLYHOOK   (1<<10)
 149#define MUTT_SEND2HOOK   (1<<11)
 150#ifdef USE_COMPRESSED
 151#define MUTT_OPENHOOK    (1<<12)
 152#define MUTT_APPENDHOOK  (1<<13)
 153#define MUTT_CLOSEHOOK   (1<<14)
 154#endif
 155
 156/* tree characters for linearize_tree and print_enriched_string */
 157#define MUTT_TREE_LLCORNER      1
 158#define MUTT_TREE_ULCORNER      2
 159#define MUTT_TREE_LTEE          3
 160#define MUTT_TREE_HLINE         4
 161#define MUTT_TREE_VLINE         5
 162#define MUTT_TREE_SPACE         6
 163#define MUTT_TREE_RARROW        7
 164#define MUTT_TREE_STAR          8
 165#define MUTT_TREE_HIDDEN        9
 166#define MUTT_TREE_EQUALS        10
 167#define MUTT_TREE_TTEE          11
 168#define MUTT_TREE_BTEE          12
 169#define MUTT_TREE_MISSING       13
 170#define MUTT_TREE_MAX           14
 171
 172#define MUTT_THREAD_COLLAPSE    (1<<0)
 173#define MUTT_THREAD_UNCOLLAPSE  (1<<1)
 174#define MUTT_THREAD_GET_HIDDEN  (1<<2)
 175#define MUTT_THREAD_UNREAD      (1<<3)
 176#define MUTT_THREAD_NEXT_UNREAD (1<<4)
 177
 178enum
 179{
 180  /* modes for mutt_view_attachment() */
 181  MUTT_REGULAR = 1,
 182  MUTT_MAILCAP,
 183  MUTT_AS_TEXT,
 184
 185  /* action codes used by mutt_set_flag() and mutt_pattern_function() */
 186  MUTT_ALL,
 187  MUTT_NONE,
 188  MUTT_NEW,
 189  MUTT_OLD,
 190  MUTT_REPLIED,
 191  MUTT_READ,
 192  MUTT_UNREAD,
 193  MUTT_DELETE,
 194  MUTT_UNDELETE,
 195  MUTT_PURGE,
 196  MUTT_DELETED,
 197  MUTT_FLAG,
 198  MUTT_TAG,
 199  MUTT_UNTAG,
 200  MUTT_LIMIT,
 201  MUTT_EXPIRED,
 202  MUTT_SUPERSEDED,
 203  MUTT_TRASH,
 204
 205  /* actions for mutt_pattern_comp/mutt_pattern_exec */
 206  MUTT_AND,
 207  MUTT_OR,
 208  MUTT_THREAD,
 209  MUTT_PARENT,
 210  MUTT_CHILDREN,
 211  MUTT_TO,
 212  MUTT_CC,
 213  MUTT_COLLAPSED,
 214  MUTT_SUBJECT,
 215  MUTT_FROM,
 216  MUTT_DATE,
 217  MUTT_DATE_RECEIVED,
 218  MUTT_DUPLICATED,
 219  MUTT_UNREFERENCED,
 220  MUTT_ID,
 221  MUTT_BODY,
 222  MUTT_HEADER,
 223  MUTT_HORMEL,
 224  MUTT_WHOLE_MSG,
 225  MUTT_SENDER,
 226  MUTT_MESSAGE,
 227  MUTT_SCORE,
 228  MUTT_SIZE,
 229  MUTT_REFERENCE,
 230  MUTT_RECIPIENT,
 231  MUTT_LIST,
 232  MUTT_SUBSCRIBED_LIST,
 233  MUTT_PERSONAL_RECIP,
 234  MUTT_PERSONAL_FROM,
 235  MUTT_ADDRESS,
 236  MUTT_CRYPT_SIGN,
 237  MUTT_CRYPT_VERIFIED,
 238  MUTT_CRYPT_ENCRYPT,
 239  MUTT_PGP_KEY,
 240  MUTT_XLABEL,
 241  MUTT_MIMEATTACH,
 242  
 243  /* Options for Mailcap lookup */
 244  MUTT_EDIT,
 245  MUTT_COMPOSE,
 246  MUTT_PRINT,
 247  MUTT_AUTOVIEW,
 248
 249  /* options for socket code */
 250  MUTT_NEW_SOCKET,
 251#ifdef USE_SSL_OPENSSL
 252  MUTT_NEW_SSL_SOCKET,
 253#endif
 254
 255  /* Options for mutt_save_attachment */
 256  MUTT_SAVE_APPEND,
 257  MUTT_SAVE_OVERWRITE
 258};
 259
 260/* possible arguments to set_quadoption() */
 261enum
 262{
 263  MUTT_NO,
 264  MUTT_YES,
 265  MUTT_ASKNO,
 266  MUTT_ASKYES
 267};
 268
 269/* quad-option vars */
 270enum
 271{
 272  OPT_ABORT,
 273  OPT_BOUNCE,
 274  OPT_COPY,
 275  OPT_DELETE,
 276  OPT_FORWEDIT,
 277  OPT_FCCATTACH,
 278  OPT_INCLUDE,
 279  OPT_MFUPTO,
 280  OPT_MIMEFWD,
 281  OPT_MIMEFWDREST,
 282  OPT_MOVE,
 283  OPT_PGPMIMEAUTO,     /* ask to revert to PGP/MIME when inline fails */
 284#ifdef USE_POP
 285  OPT_POPDELETE,
 286  OPT_POPRECONNECT,
 287#endif
 288  OPT_POSTPONE,
 289  OPT_PRINT,
 290  OPT_QUIT,
 291  OPT_REPLYTO,
 292  OPT_RECALL,
 293#if defined(USE_SSL)
 294  OPT_SSLSTARTTLS,
 295#endif
 296  OPT_SUBJECT,
 297  OPT_VERIFYSIG,      /* verify PGP signatures */
 298    
 299  /* THIS MUST BE THE LAST VALUE. */
 300  OPT_MAX
 301};
 302
 303/* flags to ci_send_message() */
 304#define SENDREPLY	(1<<0)
 305#define SENDGROUPREPLY	(1<<1)
 306#define SENDLISTREPLY	(1<<2)
 307#define SENDFORWARD	(1<<3)
 308#define SENDPOSTPONED	(1<<4)
 309#define SENDBATCH	(1<<5)
 310#define SENDMAILX	(1<<6)
 311#define SENDKEY		(1<<7)
 312#define SENDRESEND	(1<<8)
 313#define SENDPOSTPONEDFCC	(1<<9) /* used by mutt_get_postponed() to signal that the x-mutt-fcc header field was present */
 314#define SENDNOFREEHEADER	(1<<10)   /* Used by the -E flag */
 315#define SENDDRAFTFILE		(1<<11)   /* Used by the -H flag */
 316
 317/* flags for mutt_compose_menu() */
 318#define MUTT_COMPOSE_NOFREEHEADER (1<<0)
 319
 320/* flags to _mutt_select_file() */
 321#define MUTT_SEL_BUFFY  (1<<0)
 322#define MUTT_SEL_MULTI  (1<<1)
 323#define MUTT_SEL_FOLDER (1<<2)
 324
 325/* flags for parse_spam_list */
 326#define MUTT_SPAM          1
 327#define MUTT_NOSPAM        2
 328
 329/* boolean vars */
 330enum
 331{
 332  OPTALLOW8BIT,
 333  OPTALLOWANSI,
 334  OPTARROWCURSOR,
 335  OPTASCIICHARS,
 336  OPTASKBCC,
 337  OPTASKCC,
 338  OPTATTACHSPLIT,
 339  OPTAUTOEDIT,
 340  OPTAUTOTAG,
 341  OPTBEEP,
 342  OPTBEEPNEW,
 343  OPTBOUNCEDELIVERED,
 344  OPTBRAILLEFRIENDLY,
 345  OPTCHECKMBOXSIZE,
 346  OPTCHECKNEW,
 347  OPTCOLLAPSEUNREAD,
 348  OPTCONFIRMAPPEND,
 349  OPTCONFIRMCREATE,
 350  OPTDELETEUNTAG,
 351  OPTDIGESTCOLLAPSE,
 352  OPTDUPTHREADS,
 353  OPTEDITHDRS,
 354  OPTENCODEFROM,
 355  OPTENVFROM,
 356  OPTFASTREPLY,
 357  OPTFCCCLEAR,
 358  OPTFLAGSAFE,
 359  OPTFOLLOWUPTO,
 360  OPTFORCENAME,
 361  OPTFORWDECODE,
 362  OPTFORWQUOTE,
 363#ifdef USE_HCACHE
 364  OPTHCACHEVERIFY,
 365#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC)
 366  OPTHCACHECOMPRESS,
 367#endif /* HAVE_QDBM */
 368#endif
 369  OPTHDRS,
 370  OPTHEADER,
 371  OPTHEADERCOLORPARTIAL,
 372  OPTHELP,
 373  OPTHIDDENHOST,
 374  OPTHIDELIMITED,
 375  OPTHIDEMISSING,
 376  OPTHIDETHREADSUBJECT,
 377  OPTHIDETOPLIMITED,
 378  OPTHIDETOPMISSING,
 379  OPTHISTREMOVEDUPS,
 380  OPTHONORDISP,
 381  OPTIGNORELWS,
 382  OPTIGNORELISTREPLYTO,
 383#ifdef USE_IMAP
 384  OPTIMAPCHECKSUBSCRIBED,
 385  OPTIMAPIDLE,
 386  OPTIMAPLSUB,
 387  OPTIMAPPASSIVE,
 388  OPTIMAPPEEK,
 389  OPTIMAPSERVERNOISE,
 390#endif
 391#if defined(USE_SSL)
 392# ifndef USE_SSL_GNUTLS
 393  OPTSSLSYSTEMCERTS,
 394  OPTSSLV2,
 395# endif /* USE_SSL_GNUTLS */
 396  OPTSSLV3,
 397  OPTTLSV1,
 398  OPTTLSV1_1,
 399  OPTTLSV1_2,
 400  OPTSSLFORCETLS,
 401  OPTSSLVERIFYDATES,
 402  OPTSSLVERIFYHOST,
 403# if defined(USE_SSL_OPENSSL) && defined(HAVE_SSL_PARTIAL_CHAIN)
 404  OPTSSLVERIFYPARTIAL,
 405# endif /* USE_SSL_OPENSSL */
 406#endif /* defined(USE_SSL) */
 407  OPTIMPLICITAUTOVIEW,
 408  OPTINCLUDEONLYFIRST,
 409  OPTKEEPFLAGGED,
 410  OPTMAILCAPSANITIZE,
 411  OPTMAILCHECKRECENT,
 412  OPTMAILCHECKSTATS,
 413  OPTMAILDIRTRASH,
 414  OPTMAILDIRCHECKCUR,
 415  OPTMARKERS,
 416  OPTMARKOLD,
 417  OPTMENUSCROLL,	/* scroll menu instead of implicit next-page */
 418  OPTMENUMOVEOFF,	/* allow menu to scroll past last entry */
 419#if defined(USE_IMAP) || defined(USE_POP)
 420  OPTMESSAGECACHECLEAN,
 421#endif
 422  OPTMETAKEY,		/* interpret ALT-x as ESC-x */
 423  OPTMETOO,
 424  OPTMHPURGE,
 425  OPTMIMEFORWDECODE,
 426  OPTNARROWTREE,
 427  OPTPAGERSTOP,
 428  OPTPIPEDECODE,
 429  OPTPIPESPLIT,
 430#ifdef USE_POP
 431  OPTPOPAUTHTRYALL,
 432  OPTPOPLAST,
 433#endif
 434  OPTPOSTPONEENCRYPT,
 435  OPTPRINTDECODE,
 436  OPTPRINTSPLIT,
 437  OPTPROMPTAFTER,
 438  OPTREADONLY,
 439  OPTREFLOWSPACEQUOTES,
 440  OPTREFLOWTEXT,
 441  OPTREPLYSELF,
 442  OPTRESOLVE,
 443  OPTRESUMEDRAFTFILES,
 444  OPTRESUMEEDITEDDRAFTFILES,
 445  OPTREVALIAS,
 446  OPTREVNAME,
 447  OPTREVREAL,
 448  OPTRFC2047PARAMS,
 449  OPTSAVEADDRESS,
 450  OPTSAVEEMPTY,
 451  OPTSAVENAME,
 452  OPTSCORE,
 453#ifdef USE_SIDEBAR
 454  OPTSIDEBAR,
 455  OPTSIDEBARFOLDERINDENT,
 456  OPTSIDEBARNEWMAILONLY,
 457  OPTSIDEBARNEXTNEWWRAP,
 458  OPTSIDEBARSHORTPATH,
 459#endif
 460  OPTSIGDASHES,
 461  OPTSIGONTOP,
 462  OPTSORTRE,
 463  OPTSPAMSEP,
 464  OPTSTATUSONTOP,
 465  OPTSTRICTTHREADS,
 466  OPTSUSPEND,
 467  OPTTEXTFLOWED,
 468  OPTTHOROUGHSRC,
 469  OPTTHREADRECEIVED,
 470  OPTTILDE,
 471  OPTTSENABLED,
 472  OPTUNCOLLAPSEJUMP,
 473  OPTUNCOLLAPSENEW,
 474  OPTUSE8BITMIME,
 475  OPTUSEDOMAIN,
 476  OPTUSEFROM,
 477  OPTUSEGPGAGENT,
 478#ifdef HAVE_LIBIDN
 479  OPTIDNDECODE,
 480  OPTIDNENCODE,
 481#endif
 482#ifdef HAVE_GETADDRINFO
 483  OPTUSEIPV6,
 484#endif
 485  OPTWAITKEY,
 486  OPTWEED,
 487  OPTWRAP,
 488  OPTWRAPSEARCH,
 489  OPTWRITEBCC,		/* write out a bcc header? */
 490  OPTXMAILER,
 491
 492  OPTCRYPTUSEGPGME,
 493  OPTCRYPTUSEPKA,
 494
 495  /* PGP options */
 496  
 497  OPTCRYPTAUTOSIGN,
 498  OPTCRYPTAUTOENCRYPT,
 499  OPTCRYPTAUTOPGP,
 500  OPTCRYPTAUTOSMIME,
 501  OPTCRYPTCONFIRMHOOK,
 502  OPTCRYPTOPPORTUNISTICENCRYPT,
 503  OPTCRYPTREPLYENCRYPT,
 504  OPTCRYPTREPLYSIGN,
 505  OPTCRYPTREPLYSIGNENCRYPTED,
 506  OPTCRYPTTIMESTAMP,
 507  OPTSMIMEISDEFAULT,
 508  OPTSMIMESELFENCRYPT,
 509  OPTASKCERTLABEL,
 510  OPTSDEFAULTDECRYPTKEY,
 511  OPTPGPIGNORESUB,
 512  OPTPGPCHECKEXIT,
 513  OPTPGPLONGIDS,
 514  OPTPGPAUTODEC,
 515#if 0
 516  OPTPGPENCRYPTSELF,
 517#endif
 518  OPTPGPRETAINABLESIG,
 519  OPTPGPSELFENCRYPT,
 520  OPTPGPSTRICTENC,
 521  OPTFORWDECRYPT,
 522  OPTPGPSHOWUNUSABLE,
 523  OPTPGPAUTOINLINE,
 524  OPTPGPREPLYINLINE,
 525
 526  /* pseudo options */
 527
 528  OPTAUXSORT,		/* (pseudo) using auxiliary sort function */
 529  OPTFORCEREFRESH,	/* (pseudo) refresh even during macros */
 530  OPTLOCALES,		/* (pseudo) set if user has valid locale definition */
 531  OPTNOCURSES,		/* (pseudo) when sending in batch mode */
 532  OPTSEARCHREVERSE,	/* (pseudo) used by ci_search_command */
 533  OPTMSGERR,		/* (pseudo) used by mutt_error/mutt_message */
 534  OPTSEARCHINVALID,	/* (pseudo) used to invalidate the search pat */
 535  OPTSIGNALSBLOCKED,	/* (pseudo) using by mutt_block_signals () */
 536  OPTSYSSIGNALSBLOCKED,	/* (pseudo) using by mutt_block_signals_system () */
 537  OPTNEEDRESORT,	/* (pseudo) used to force a re-sort */
 538  OPTRESORTINIT,	/* (pseudo) used to force the next resort to be from scratch */
 539  OPTVIEWATTACH,	/* (pseudo) signals that we are viewing attachments */
 540  OPTSORTSUBTHREADS,	/* (pseudo) used when $sort_aux changes */
 541  OPTNEEDRESCORE,	/* (pseudo) set when the `score' command is used */
 542  OPTATTACHMSG,		/* (pseudo) used by attach-message */
 543  OPTKEEPQUIET,		/* (pseudo) shut up the message and refresh
 544			 * 	    functions while we are executing an
 545			 * 	    external program.
 546			 */
 547  OPTMENUCALLER,	/* (pseudo) tell menu to give caller a take */
 548  OPTREDRAWTREE,	/* (pseudo) redraw the thread tree */
 549  OPTPGPCHECKTRUST,	/* (pseudo) used by pgp_select_key () */
 550  OPTDONTHANDLEPGPKEYS,	/* (pseudo) used to extract PGP keys */
 551  OPTIGNOREMACROEVENTS, /* (pseudo) don't process macro/push/exec events while set */
 552
 553  OPTMAX
 554};
 555
 556#define mutt_bit_alloc(n) calloc ((n + 7) / 8, sizeof (char))
 557#define mutt_bit_set(v,n) v[n/8] |= (1 << (n % 8))
 558#define mutt_bit_unset(v,n) v[n/8] &= ~(1 << (n % 8))
 559#define mutt_bit_toggle(v,n) v[n/8] ^= (1 << (n % 8))
 560#define mutt_bit_isset(v,n) (v[n/8] & (1 << (n % 8)))
 561
 562#define set_option(x) mutt_bit_set(Options,x)
 563#define unset_option(x) mutt_bit_unset(Options,x)
 564#define toggle_option(x) mutt_bit_toggle(Options,x)
 565#define option(x) mutt_bit_isset(Options,x)
 566
 567typedef struct list_t
 568{
 569  char *data;
 570  struct list_t *next;
 571} LIST;
 572
 573typedef struct rx_list_t
 574{
 575  REGEXP *rx;
 576  struct rx_list_t *next;
 577} RX_LIST;
 578
 579typedef struct replace_list_t
 580{
 581  REGEXP *rx;
 582  int     nmatch;
 583  char   *template;
 584  struct replace_list_t *next;
 585} REPLACE_LIST;
 586
 587#define mutt_new_list() safe_calloc (1, sizeof (LIST))
 588#define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST))
 589#define mutt_new_replace_list() safe_calloc (1, sizeof (REPLACE_LIST))
 590void mutt_free_list (LIST **);
 591void mutt_free_rx_list (RX_LIST **);
 592void mutt_free_replace_list (REPLACE_LIST **);
 593LIST *mutt_copy_list (LIST *);
 594int mutt_matches_ignore (const char *, LIST *);
 595
 596/* add an element to a list */
 597LIST *mutt_add_list (LIST *, const char *);
 598LIST *mutt_add_list_n (LIST*, const void *, size_t);
 599LIST *mutt_find_list (LIST *, const char *);
 600int mutt_remove_from_rx_list (RX_LIST **l, const char *str);
 601
 602void mutt_init (int, LIST *);
 603
 604typedef struct alias
 605{
 606  struct alias *self;		/* XXX - ugly hack */
 607  char *name;
 608  ADDRESS *addr;
 609  struct alias *next;
 610  short tagged;
 611  short del;
 612  short num;
 613} ALIAS;
 614
 615typedef struct envelope
 616{
 617  ADDRESS *return_path;
 618  ADDRESS *from;
 619  ADDRESS *to;
 620  ADDRESS *cc;
 621  ADDRESS *bcc;
 622  ADDRESS *sender;
 623  ADDRESS *reply_to;
 624  ADDRESS *mail_followup_to;
 625  char *list_post;		/* this stores a mailto URL, or nothing */
 626  char *subject;
 627  char *real_subj;		/* offset of the real subject */
 628  char *disp_subj;		/* display subject (modified copy of subject) */
 629  char *message_id;
 630  char *supersedes;
 631  char *date;
 632  char *x_label;
 633  BUFFER *spam;
 634  LIST *references;		/* message references (in reverse order) */
 635  LIST *in_reply_to;		/* in-reply-to header content */
 636  LIST *userhdrs;		/* user defined headers */
 637
 638  unsigned int irt_changed : 1; /* In-Reply-To changed to link/break threads */
 639  unsigned int refs_changed : 1; /* References changed to break thread */
 640} ENVELOPE;
 641
 642typedef struct parameter
 643{
 644  char *attribute;
 645  char *value;
 646  struct parameter *next;
 647} PARAMETER;
 648
 649/* Information that helps in determing the Content-* of an attachment */
 650typedef struct content
 651{
 652  long hibin;              /* 8-bit characters */
 653  long lobin;              /* unprintable 7-bit chars (eg., control chars) */
 654  long crlf;		   /* '\r' and '\n' characters */
 655  long ascii;              /* number of ascii chars */
 656  long linemax;            /* length of the longest line in the file */
 657  unsigned int space : 1;  /* whitespace at the end of lines? */
 658  unsigned int binary : 1; /* long lines, or CR not in CRLF pair */
 659  unsigned int from : 1;   /* has a line beginning with "From "? */
 660  unsigned int dot : 1;    /* has a line consisting of a single dot? */
 661  unsigned int cr : 1;     /* has CR, even when in a CRLF pair */
 662} CONTENT;
 663
 664typedef struct body
 665{
 666  char *xtype;			/* content-type if x-unknown */
 667  char *subtype;                /* content-type subtype */
 668  PARAMETER *parameter;         /* parameters of the content-type */
 669  char *description;            /* content-description */
 670  char *form_name;		/* Content-Disposition form-data name param */
 671  long hdr_offset;              /* offset in stream where the headers begin.
 672				 * this info is used when invoking metamail,
 673				 * where we need to send the headers of the
 674				 * attachment
 675				 */
 676  LOFF_T offset;                /* offset where the actual data begins */
 677  LOFF_T length;                /* length (in bytes) of attachment */
 678  char *filename;               /* when sending a message, this is the file
 679				 * to which this structure refers
 680				 */
 681  char *d_filename;		/* filename to be used for the 
 682				 * content-disposition header.
 683				 * If NULL, filename is used 
 684				 * instead.
 685				 */
 686  char *charset;                /* charset of attached file */
 687  CONTENT *content;             /* structure used to store detailed info about
 688				 * the content of the attachment.  this is used
 689				 * to determine what content-transfer-encoding
 690				 * is required when sending mail.
 691				 */
 692  struct body *next;            /* next attachment in the list */
 693  struct body *parts;           /* parts of a multipart or message/rfc822 */
 694  struct header *hdr;		/* header information for message/rfc822 */
 695
 696  struct attachptr *aptr;	/* Menu information, used in recvattach.c */
 697
 698  signed short attach_count;
 699
 700  time_t stamp;			/* time stamp of last
 701				 * encoding update.
 702				 */
 703  
 704  unsigned int type : 4;        /* content-type primary type */
 705  unsigned int encoding : 3;    /* content-transfer-encoding */
 706  unsigned int disposition : 2; /* content-disposition */
 707  unsigned int use_disp : 1;    /* Content-Disposition uses filename= ? */
 708  unsigned int unlink : 1;      /* flag to indicate the the file named by
 709				 * "filename" should be unlink()ed before
 710				 * free()ing this structure
 711				 */
 712  unsigned int tagged : 1;
 713  unsigned int deleted : 1;	/* attachment marked for deletion */
 714
 715  unsigned int noconv : 1;	/* don't do character set conversion */
 716  unsigned int force_charset : 1; 
 717  				/* send mode: don't adjust the character
 718				 * set when in send-mode.
 719				 */
 720  unsigned int is_signed_data : 1; /* A lot of MUAs don't indicate
 721                                      S/MIME signed-data correctly,
 722                                      e.g. they use foo.p7m even for
 723                                      the name of signed data.  This
 724                                      flag is used to keep track of
 725                                      the actual message type.  It
 726                                      gets set during the verification
 727                                      (which is done if the encryption
 728                                      try failed) and check by the
 729                                      function to figure the type of
 730                                      the message. */
 731
 732  unsigned int goodsig : 1;	/* good cryptographic signature */
 733  unsigned int warnsig : 1;     /* maybe good signature */
 734  unsigned int badsig : 1;	/* bad cryptographic signature (needed to check encrypted s/mime-signatures) */
 735
 736  unsigned int collapsed : 1;	/* used by recvattach */
 737  unsigned int attach_qualifies : 1;
 738
 739} BODY;
 740
 741/* #3279: AIX defines conflicting struct thread */
 742typedef struct mutt_thread THREAD;
 743
 744typedef struct header
 745{
 746  unsigned int security : 12;  /* bit 0-8: flags, bit 9,10: application.
 747				 see: mutt_crypt.h pgplib.h, smime.h */
 748
 749  unsigned int mime : 1;    		/* has a MIME-Version header? */
 750  unsigned int flagged : 1; 		/* marked important? */
 751  unsigned int tagged : 1;
 752  unsigned int deleted : 1;
 753  unsigned int purge : 1;               /* skip trash folder when deleting */
 754  unsigned int changed : 1;
 755  unsigned int attach_del : 1; 		/* has an attachment marked for deletion */
 756  unsigned int old : 1;
 757  unsigned int read : 1;
 758  unsigned int expired : 1; 		/* already expired? */
 759  unsigned int superseded : 1; 		/* got superseded? */
 760  unsigned int replied : 1;
 761  unsigned int subject_changed : 1; 	/* used for threading */
 762  unsigned int threaded : 1;	    	/* used for threading */
 763  unsigned int display_subject : 1; 	/* used for threading */
 764  unsigned int recip_valid : 1;  	/* is_recipient is valid */
 765  unsigned int active : 1;	    	/* message is not to be removed */
 766  unsigned int trash : 1;		/* message is marked as trashed on disk.
 767					 * This flag is used by the maildir_trash
 768					 * option.
 769					 */
 770  unsigned int xlabel_changed : 1;	/* editable - used for syncing */
 771  
 772  /* timezone of the sender of this message */
 773  unsigned int zhours : 5;
 774  unsigned int zminutes : 6;
 775  unsigned int zoccident : 1;
 776
 777  /* bits used for caching when searching */
 778  unsigned int searched : 1;
 779  unsigned int matched : 1;
 780
 781  /* tells whether the attachment count is valid */
 782  unsigned int attach_valid : 1;
 783
 784  /* the following are used to support collapsing threads  */
 785  unsigned int collapsed : 1; 	/* is this message part of a collapsed thread? */
 786  unsigned int limited : 1;   	/* is this message in a limited view?  */
 787  size_t num_hidden;          	/* number of hidden messages in this view */
 788
 789  short recipient;		/* user_is_recipient()'s return value, cached */
 790  
 791  int pair; 			/* color-pair to use when displaying in the index */
 792
 793  time_t date_sent;     	/* time when the message was sent (UTC) */
 794  time_t received;      	/* time when the message was placed in the mailbox */
 795  LOFF_T offset;          	/* where in the stream does this message begin? */
 796  int lines;			/* how many lines in the body of this message? */
 797  int index;			/* the absolute (unsorted) message number */
 798  int msgno;			/* number displayed to the user */
 799  int virtual;			/* virtual message number */
 800  int score;
 801  ENVELOPE *env;		/* envelope information */
 802  BODY *content;		/* list of MIME parts */
 803  char *path;
 804  
 805  char *tree;           	/* character string to print thread tree */
 806  THREAD *thread;
 807
 808  /* Number of qualifying attachments in message, if attach_valid */
 809  short attach_total;
 810
 811#ifdef MIXMASTER
 812  LIST *chain;
 813#endif
 814
 815#ifdef USE_POP
 816  int refno;			/* message number on server */
 817#endif
 818
 819#if defined USE_POP || defined USE_IMAP
 820  void *data;            	/* driver-specific data */
 821#endif
 822  
 823  char *maildir_flags;		/* unknown maildir flags */
 824} HEADER;
 825
 826struct mutt_thread
 827{
 828  unsigned int fake_thread : 1;
 829  unsigned int duplicate_thread : 1;
 830  unsigned int sort_children : 1;
 831  unsigned int check_subject : 1;
 832  unsigned int visible : 1;
 833  unsigned int deep : 1;
 834  unsigned int subtree_visible : 2;
 835  unsigned int next_subtree_visible : 1;
 836  THREAD *parent;
 837  THREAD *child;
 838  THREAD *next;
 839  THREAD *prev;
 840  HEADER *message;
 841  HEADER *sort_key;
 842};
 843
 844
 845/* flag to mutt_pattern_comp() */
 846#define MUTT_FULL_MSG	(1<<0)	/* enable body and header matching */
 847
 848typedef enum {
 849  MUTT_MATCH_FULL_ADDRESS = 1
 850} pattern_exec_flag;
 851
 852typedef struct group_t
 853{
 854  ADDRESS *as;
 855  RX_LIST *rs;
 856  char *name;
 857} group_t;
 858
 859typedef struct group_context_t
 860{
 861  group_t *g;
 862  struct group_context_t *next;
 863} group_context_t;
 864
 865typedef struct pattern_t
 866{
 867  short op;
 868  unsigned int not : 1;
 869  unsigned int alladdr : 1;
 870  unsigned int stringmatch : 1;
 871  unsigned int groupmatch : 1;
 872  unsigned int ign_case : 1;		/* ignore case for local stringmatch searches */
 873  unsigned int isalias : 1;
 874  int min;
 875  int max;
 876  struct pattern_t *next;
 877  struct pattern_t *child;		/* arguments to logical op */
 878  union 
 879  {
 880    regex_t *rx;
 881    group_t *g;
 882    char *str;
 883  } p;
 884} pattern_t;
 885
 886/* This is used when a message is repeatedly pattern matched against.
 887 * e.g. for color, scoring, hooks.  It caches a few of the potentially slow
 888 * operations.
 889 * Each entry has a value of 0 = unset, 1 = false, 2 = true
 890 */
 891typedef struct
 892{
 893  int list_all;          /* ^~l */
 894  int list_one;          /*  ~l */
 895  int sub_all;           /* ^~u */
 896  int sub_one;           /*  ~u */
 897  int pers_recip_all;    /* ^~p */
 898  int pers_recip_one;    /*  ~p */
 899  int pers_from_all;     /* ^~P */
 900  int pers_from_one;     /*  ~P */
 901} pattern_cache_t;
 902
 903/* ACL Rights */
 904enum
 905{
 906  MUTT_ACL_LOOKUP = 0,
 907  MUTT_ACL_READ,
 908  MUTT_ACL_SEEN,
 909  MUTT_ACL_WRITE,
 910  MUTT_ACL_INSERT,
 911  MUTT_ACL_POST,
 912  MUTT_ACL_CREATE,
 913  MUTT_ACL_DELMX,
 914  MUTT_ACL_DELETE,
 915  MUTT_ACL_EXPUNGE,
 916  MUTT_ACL_ADMIN,
 917
 918  RIGHTSMAX
 919};
 920
 921struct _context;
 922struct _message;
 923
 924/*
 925 * struct mx_ops - a structure to store operations on a mailbox
 926 * The following operations are mandatory:
 927 *  - open
 928 *  - close
 929 *  - check
 930 *
 931 * Optional operations
 932 *  - open_new_msg
 933 */
 934struct mx_ops
 935{
 936  int (*open) (struct _context *);
 937  int (*open_append) (struct _context *, int flags);
 938  int (*close) (struct _context *);
 939  int (*check) (struct _context *ctx, int *index_hint);
 940  int (*sync) (struct _context *ctx, int *index_hint);
 941  int (*open_msg) (struct _context *, struct _message *, int msgno);
 942  int (*close_msg) (struct _context *, struct _message *);
 943  int (*commit_msg) (struct _context *, struct _message *);
 944  int (*open_new_msg) (struct _message *, struct _context *, HEADER *);
 945};
 946
 947typedef struct _context
 948{
 949  char *path;
 950  char *realpath;               /* used for buffy comparison and the sidebar */
 951  FILE *fp;
 952  time_t atime;
 953  time_t mtime;
 954  off_t size;
 955  off_t vsize;
 956  char *pattern;                /* limit pattern string */
 957  pattern_t *limit_pattern;     /* compiled limit pattern */
 958  HEADER **hdrs;
 959  HEADER *last_tag;		/* last tagged msg. used to link threads */
 960  THREAD *tree;			/* top of thread tree */
 961  HASH *id_hash;		/* hash table by msg id */
 962  HASH *subj_hash;		/* hash table by subject */
 963  HASH *thread_hash;		/* hash table for threading */
 964  HASH *label_hash;             /* hash table for x-labels */
 965  int *v2r;			/* mapping from virtual to real msgno */
 966  int hdrmax;			/* number of pointers in hdrs */
 967  int msgcount;			/* number of messages in the mailbox */
 968  int vcount;			/* the number of virtual messages */
 969  int tagged;			/* how many messages are tagged? */
 970  int new;			/* how many new messages? */
 971  int unread;			/* how many unread messages? */
 972  int deleted;			/* how many deleted messages */
 973  int flagged;			/* how many flagged messages */
 974  int msgnotreadyet;		/* which msg "new" in pager, -1 if none */
 975
 976  short magic;			/* mailbox type */
 977
 978  unsigned char rights[(RIGHTSMAX + 7)/8];	/* ACL bits */
 979
 980  unsigned int locked : 1;	/* is the mailbox locked? */
 981  unsigned int changed : 1;	/* mailbox has been modified */
 982  unsigned int readonly : 1;    /* don't allow changes to the mailbox */
 983  unsigned int dontwrite : 1;   /* don't write the mailbox on close */
 984  unsigned int append : 1;	/* mailbox is opened in append mode */
 985  unsigned int quiet : 1;	/* inhibit status messages? */
 986  unsigned int collapsed : 1;   /* are all threads collapsed? */
 987  unsigned int closing : 1;	/* mailbox is being closed */
 988  unsigned int peekonly : 1;	/* just taking a glance, revert atime */
 989
 990#ifdef USE_COMPRESSED
 991  void *compress_info;		/* compressed mbox module private data */
 992#endif /* USE_COMPRESSED */
 993
 994  /* driver hooks */
 995  void *data;			/* driver specific data */
 996  struct mx_ops *mx_ops;
 997} CONTEXT;
 998
 999typedef struct
1000{
1001  FILE *fpin;
1002  FILE *fpout;
1003  char *prefix;
1004  int flags;
1005} STATE;
1006
1007/* used by enter.c */
1008
1009typedef struct
1010{
1011  wchar_t *wbuf;
1012  size_t wbuflen;
1013  size_t lastchar;
1014  size_t curpos;
1015  size_t begin;
1016  int	 tabs;
1017} ENTER_STATE;
1018
1019/* flags for the STATE struct */
1020#define MUTT_DISPLAY       (1<<0) /* output is displayed to the user */
1021#define MUTT_VERIFY        (1<<1) /* perform signature verification */
1022#define MUTT_PENDINGPREFIX (1<<2) /* prefix to write, but character must follow */
1023#define MUTT_WEED          (1<<3) /* weed headers even when not in display mode */
1024#define MUTT_CHARCONV      (1<<4) /* Do character set conversions */
1025#define MUTT_PRINTING      (1<<5) /* are we printing? - MUTT_DISPLAY "light" */
1026#define MUTT_REPLYING      (1<<6) /* are we replying? */
1027#define MUTT_FIRSTDONE     (1<<7) /* the first attachment has been done */
1028
1029#define state_set_prefix(s) ((s)->flags |= MUTT_PENDINGPREFIX)
1030#define state_reset_prefix(s) ((s)->flags &= ~MUTT_PENDINGPREFIX)
1031#define state_puts(x,y) fputs(x,(y)->fpout)
1032#define state_putc(x,y) fputc(x,(y)->fpout)
1033
1034void state_mark_attach (STATE *);
1035void state_attach_puts (const char *, STATE *);
1036void state_prefix_putc (char, STATE *);
1037int  state_printf(STATE *, const char *, ...);
1038int state_putwc (wchar_t, STATE *);
1039int state_putws (const wchar_t *, STATE *);
1040
1041/* for attachment counter */
1042typedef struct
1043{
1044  char   *major;
1045  int     major_int;
1046  char   *minor;
1047  regex_t minor_rx;
1048} ATTACH_MATCH;
1049
1050/* multibyte character table.
1051 * Allows for direct access to the individual multibyte characters in a
1052 * string.  This is used for the Tochars and StChars option types. */
1053typedef struct
1054{
1055  int len;               /* number of characters */
1056  char **chars;          /* the array of multibyte character strings */
1057  char *segmented_str;   /* each chars entry points inside this string */
1058  char *orig_str;
1059} mbchar_table;
1060
1061#define MUTT_PARTS_TOPLEVEL	(1<<0)	/* is the top-level part */
1062
1063#include "ascii.h"
1064#include "protos.h"
1065#include "lib.h"
1066#include "globals.h"
1067
1068#endif /*MUTT_H*/