PageRenderTime 52ms CodeModel.GetById 18ms app.highlight 24ms RepoModel.GetById 0ms app.codeStats 0ms

/mutt.h

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