mutt stable branch with some hacks
at jcs 1172 lines 33 kB view raw
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 ci_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 361/* flags for mutt_compose_menu() */ 362#define MUTT_COMPOSE_NOFREEHEADER (1<<0) 363 364/* flags to _mutt_select_file() */ 365#define MUTT_SEL_BUFFY (1<<0) 366#define MUTT_SEL_MULTI (1<<1) 367#define MUTT_SEL_FOLDER (1<<2) 368 369/* flags for parse_spam_list */ 370#define MUTT_SPAM 1 371#define MUTT_NOSPAM 2 372 373/* boolean vars */ 374enum 375{ 376 OPTALLOW8BIT, 377 OPTALLOWANSI, 378 OPTARROWCURSOR, 379 OPTASCIICHARS, 380 OPTASKBCC, 381 OPTASKCC, 382 OPTATTACHSPLIT, 383#ifdef USE_AUTOCRYPT 384 OPTAUTOCRYPT, 385 OPTAUTOCRYPTREPLY, 386#endif 387 OPTAUTOEDIT, 388 OPTAUTOSUBSCRIBE, 389 OPTAUTOTAG, 390 OPTBEEP, 391 OPTBEEPNEW, 392 OPTBOUNCEDELIVERED, 393 OPTCHANGEFOLDERNEXT, 394 OPTBRAILLEFRIENDLY, 395 OPTBROWSERABBRMAILBOXES, 396 OPTBROWSERSTICKYCURSOR, 397 OPTCHECKMBOXSIZE, 398 OPTCHECKNEW, 399 OPTCOLLAPSEUNREAD, 400 OPTCONFIRMAPPEND, 401 OPTCONFIRMCREATE, 402 OPTCOUNTALTERNATIVES, 403 OPTDELETEUNTAG, 404 OPTDIGESTCOLLAPSE, 405 OPTDUPTHREADS, 406 OPTEDITHDRS, 407 OPTENCODEFROM, 408 OPTENVFROM, 409 OPTFASTREPLY, 410 OPTFCCBEFORESEND, 411 OPTFCCCLEAR, 412 OPTFLAGSAFE, 413 OPTFOLLOWUPTO, 414 OPTFORCENAME, 415 OPTFORWDECODE, 416 OPTFORWQUOTE, 417#ifdef USE_HCACHE 418 OPTHCACHEVERIFY, 419#if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC) 420 OPTHCACHECOMPRESS, 421#endif /* HAVE_QDBM */ 422#endif 423 OPTHDRS, 424 OPTHEADER, 425 OPTHEADERCOLORPARTIAL, 426 OPTHELP, 427 OPTHIDDENHOST, 428 OPTHIDELIMITED, 429 OPTHIDEMISSING, 430 OPTHIDETHREADSUBJECT, 431 OPTHIDETOPLIMITED, 432 OPTHIDETOPMISSING, 433 OPTHISTREMOVEDUPS, 434 OPTHONORDISP, 435 OPTIGNORELWS, 436 OPTIGNORELISTREPLYTO, 437#ifdef USE_IMAP 438 OPTIMAPCHECKSUBSCRIBED, 439 OPTIMAPCONDSTORE, 440 OPTIMAPIDLE, 441 OPTIMAPLSUB, 442 OPTIMAPPASSIVE, 443 OPTIMAPPEEK, 444 OPTIMAPQRESYNC, 445 OPTIMAPSERVERNOISE, 446#endif 447#if defined(USE_SSL) 448# ifndef USE_SSL_GNUTLS 449 OPTSSLSYSTEMCERTS, 450 OPTSSLV2, 451# endif /* USE_SSL_GNUTLS */ 452 OPTSSLV3, 453 OPTTLSV1, 454 OPTTLSV1_1, 455 OPTTLSV1_2, 456 OPTTLSV1_3, 457 OPTSSLFORCETLS, 458 OPTSSLVERIFYDATES, 459 OPTSSLVERIFYHOST, 460# if defined(USE_SSL_OPENSSL) && defined(HAVE_SSL_PARTIAL_CHAIN) 461 OPTSSLVERIFYPARTIAL, 462# endif /* USE_SSL_OPENSSL */ 463#endif /* defined(USE_SSL) */ 464 OPTIMPLICITAUTOVIEW, 465 OPTINCLUDEENCRYPTED, 466 OPTINCLUDEONLYFIRST, 467 OPTKEEPFLAGGED, 468 OPTMAILCAPSANITIZE, 469 OPTMAILCHECKRECENT, 470 OPTMAILCHECKSTATS, 471 OPTMAILDIRTRASH, 472 OPTMAILDIRCHECKCUR, 473 OPTMARKERS, 474 OPTMARKOLD, 475 OPTMENUSCROLL, /* scroll menu instead of implicit next-page */ 476 OPTMENUMOVEOFF, /* allow menu to scroll past last entry */ 477#if defined(USE_IMAP) || defined(USE_POP) 478 OPTMESSAGECACHECLEAN, 479#endif 480 OPTMETAKEY, /* interpret ALT-x as ESC-x */ 481 OPTMETOO, 482 OPTMHPURGE, 483 OPTMIMEFORWDECODE, 484 OPTMIMETYPEQUERYFIRST, 485 OPTNARROWTREE, 486 OPTPAGERSTOP, 487 OPTPIPEDECODE, 488 OPTPIPESPLIT, 489#ifdef USE_POP 490 OPTPOPAUTHTRYALL, 491 OPTPOPLAST, 492#endif 493 OPTPOSTPONEENCRYPT, 494 OPTPRINTDECODE, 495 OPTPRINTSPLIT, 496 OPTPROMPTAFTER, 497 OPTREADONLY, 498 OPTREFLOWSPACEQUOTES, 499 OPTREFLOWTEXT, 500 OPTREPLYSELF, 501 OPTRESOLVE, 502 OPTRESUMEDRAFTFILES, 503 OPTRESUMEEDITEDDRAFTFILES, 504 OPTREVALIAS, 505 OPTREVNAME, 506 OPTREVREAL, 507 OPTRFC2047PARAMS, 508 OPTSAVEADDRESS, 509 OPTSAVEEMPTY, 510 OPTSAVENAME, 511 OPTSCORE, 512#ifdef USE_SIDEBAR 513 OPTSIDEBAR, 514 OPTSIDEBARFOLDERINDENT, 515 OPTSIDEBARNEWMAILONLY, 516 OPTSIDEBARNEXTNEWWRAP, 517 OPTSIDEBARRELSPINDENT, 518 OPTSIDEBARUSEMBSHORTCUTS, 519 OPTSIDEBARSHORTPATH, 520#endif 521 OPTSIGDASHES, 522 OPTSIGONTOP, 523 OPTSIZESHOWBYTES, 524 OPTSIZESHOWMB, 525 OPTSIZESHOWFRACTIONS, 526 OPTSIZEUNITSONLEFT, 527 OPTSORTRE, 528 OPTSPAMSEP, 529 OPTSTATUSONTOP, 530 OPTSTRICTTHREADS, 531 OPTSUSPEND, 532 OPTTEXTFLOWED, 533 OPTTHOROUGHSRC, 534 OPTTHREADRECEIVED, 535 OPTTILDE, 536 OPTTSENABLED, 537 OPTUNCOLLAPSEJUMP, 538 OPTUNCOLLAPSENEW, 539 OPTUSE8BITMIME, 540 OPTUSEDOMAIN, 541 OPTUSEFROM, 542 OPTUSEGPGAGENT, 543#if defined(HAVE_LIBIDN) || defined(HAVE_LIBIDN2) 544 OPTIDNDECODE, 545 OPTIDNENCODE, 546#endif 547#ifdef HAVE_GETADDRINFO 548 OPTUSEIPV6, 549#endif 550 OPTWAITKEY, 551 OPTWEED, 552 OPTWRAP, 553 OPTWRAPSEARCH, 554 OPTWRITEBCC, /* write out a bcc header? */ 555 OPTXMAILER, 556 557 OPTCRYPTUSEGPGME, 558 OPTCRYPTUSEPKA, 559 560 /* PGP options */ 561 562 OPTCRYPTAUTOSIGN, 563 OPTCRYPTAUTOENCRYPT, 564 OPTCRYPTAUTOPGP, 565 OPTCRYPTAUTOSMIME, 566 OPTCRYPTCONFIRMHOOK, 567 OPTCRYPTOPPORTUNISTICENCRYPT, 568 OPTCRYPTPROTHDRSREAD, 569 OPTCRYPTPROTHDRSSAVE, 570 OPTCRYPTPROTHDRSWRITE, 571 OPTCRYPTREPLYENCRYPT, 572 OPTCRYPTREPLYSIGN, 573 OPTCRYPTREPLYSIGNENCRYPTED, 574 OPTCRYPTTIMESTAMP, 575 OPTSMIMEISDEFAULT, 576 OPTSMIMESELFENCRYPT, 577 OPTASKCERTLABEL, 578 OPTSDEFAULTDECRYPTKEY, 579 OPTPGPIGNORESUB, 580 OPTPGPCHECKEXIT, 581 OPTPGPCHECKGPGDECRYPTSTATUSFD, 582 OPTPGPLONGIDS, 583 OPTPGPAUTODEC, 584 OPTPGPRETAINABLESIG, 585 OPTPGPSELFENCRYPT, 586 OPTPGPSTRICTENC, 587 OPTFORWDECRYPT, 588 OPTPGPSHOWUNUSABLE, 589 OPTPGPAUTOINLINE, 590 OPTPGPREPLYINLINE, 591 592 /* pseudo options */ 593 594 OPTAUXSORT, /* (pseudo) using auxiliary sort function */ 595 OPTFORCEREFRESH, /* (pseudo) refresh even during macros */ 596 OPTLOCALES, /* (pseudo) set if user has valid locale definition */ 597 OPTNOCURSES, /* (pseudo) when sending in batch mode */ 598 OPTSEARCHREVERSE, /* (pseudo) used by ci_search_command */ 599 OPTMSGERR, /* (pseudo) used by mutt_error/mutt_message */ 600 OPTSEARCHINVALID, /* (pseudo) used to invalidate the search pat */ 601 OPTSIGNALSBLOCKED, /* (pseudo) using by mutt_block_signals () */ 602 OPTSYSSIGNALSBLOCKED, /* (pseudo) using by mutt_block_signals_system () */ 603 OPTNEEDRESORT, /* (pseudo) used to force a re-sort */ 604 OPTRESORTINIT, /* (pseudo) used to force the next resort to be from scratch */ 605 OPTVIEWATTACH, /* (pseudo) signals that we are viewing attachments */ 606 OPTSORTSUBTHREADS, /* (pseudo) used when $sort_aux changes */ 607 OPTNEEDRESCORE, /* (pseudo) set when the `score' command is used */ 608 OPTATTACHMSG, /* (pseudo) used by attach-message */ 609 OPTKEEPQUIET, /* (pseudo) shut up the message and refresh 610 * functions while we are executing an 611 * external program. 612 */ 613 OPTMENUCALLER, /* (pseudo) tell menu to give caller a take */ 614 OPTREDRAWTREE, /* (pseudo) redraw the thread tree */ 615 OPTPGPCHECKTRUST, /* (pseudo) used by pgp_select_key () */ 616 OPTDONTHANDLEPGPKEYS, /* (pseudo) used to extract PGP keys */ 617 OPTIGNOREMACROEVENTS, /* (pseudo) don't process macro/push/exec events while set */ 618 OPTAUTOCRYPTGPGME, /* (pseudo) use Autocrypt context inside crypt-gpgme.c */ 619 OPTMENUPOPCLEARSCREEN, /* (pseudo) clear the screen when popping the last menu. */ 620 621 OPTMAX 622}; 623 624#define mutt_bit_alloc(n) calloc ((n + 7) / 8, sizeof (char)) 625#define mutt_bit_set(v,n) v[n/8] |= (1 << (n % 8)) 626#define mutt_bit_unset(v,n) v[n/8] &= ~(1 << (n % 8)) 627#define mutt_bit_toggle(v,n) v[n/8] ^= (1 << (n % 8)) 628#define mutt_bit_isset(v,n) (v[n/8] & (1 << (n % 8))) 629 630#define set_option(x) mutt_bit_set(Options,x) 631#define unset_option(x) mutt_bit_unset(Options,x) 632#define toggle_option(x) mutt_bit_toggle(Options,x) 633#define option(x) mutt_bit_isset(Options,x) 634 635typedef struct list_t 636{ 637 char *data; 638 struct list_t *next; 639} LIST; 640 641typedef struct rx_list_t 642{ 643 REGEXP *rx; 644 struct rx_list_t *next; 645} RX_LIST; 646 647typedef struct replace_list_t 648{ 649 REGEXP *rx; 650 int nmatch; 651 char *template; 652 struct replace_list_t *next; 653} REPLACE_LIST; 654 655#define mutt_new_list() safe_calloc (1, sizeof (LIST)) 656#define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST)) 657#define mutt_new_replace_list() safe_calloc (1, sizeof (REPLACE_LIST)) 658void mutt_free_list (LIST **); 659void mutt_free_list_generic (LIST **list, void (*data_free)(char **)); 660void mutt_free_rx_list (RX_LIST **); 661void mutt_free_replace_list (REPLACE_LIST **); 662LIST *mutt_copy_list (LIST *); 663int mutt_matches_ignore (const char *, LIST *); 664 665/* add an element to a list */ 666LIST *mutt_add_list (LIST *, const char *); 667LIST *mutt_add_list_n (LIST*, const void *, size_t); 668LIST *mutt_find_list (LIST *, const char *); 669int mutt_remove_from_rx_list (RX_LIST **l, const char *str); 670 671void mutt_init (int, LIST *); 672 673typedef struct alias 674{ 675 struct alias *self; /* XXX - ugly hack */ 676 char *name; 677 ADDRESS *addr; 678 struct alias *next; 679 short tagged; 680 short del; 681 short num; 682} ALIAS; 683 684#define MUTT_ENV_CHANGED_IRT (1<<0) /* In-Reply-To changed to link/break threads */ 685#define MUTT_ENV_CHANGED_REFS (1<<1) /* References changed to break thread */ 686#define MUTT_ENV_CHANGED_XLABEL (1<<2) /* X-Label edited */ 687#define MUTT_ENV_CHANGED_SUBJECT (1<<3) /* Protected header update */ 688 689#ifdef USE_AUTOCRYPT 690typedef struct autocrypt 691{ 692 char *addr; 693 char *keydata; 694 unsigned int prefer_encrypt : 1; 695 unsigned int invalid : 1; 696 struct autocrypt *next; 697} AUTOCRYPTHDR; 698#endif 699 700typedef struct envelope 701{ 702 ADDRESS *return_path; 703 ADDRESS *from; 704 ADDRESS *to; 705 ADDRESS *cc; 706 ADDRESS *bcc; 707 ADDRESS *sender; 708 ADDRESS *reply_to; 709 ADDRESS *mail_followup_to; 710 char *list_post; /* this stores a mailto URL, or nothing */ 711 char *subject; 712 char *real_subj; /* offset of the real subject */ 713 char *disp_subj; /* display subject (modified copy of subject) */ 714 char *message_id; 715 char *supersedes; 716 char *date; 717 char *x_label; 718 BUFFER *spam; 719 LIST *references; /* message references (in reverse order) */ 720 LIST *in_reply_to; /* in-reply-to header content */ 721 LIST *userhdrs; /* user defined headers */ 722#ifdef USE_AUTOCRYPT 723 AUTOCRYPTHDR *autocrypt; 724 AUTOCRYPTHDR *autocrypt_gossip; 725#endif 726 unsigned char changed; /* The MUTT_ENV_CHANGED_* flags specify which 727 * fields are modified */ 728} ENVELOPE; 729 730typedef struct parameter 731{ 732 char *attribute; 733 char *value; 734 struct parameter *next; 735} PARAMETER; 736 737/* Information that helps in determining the Content-* of an attachment */ 738typedef struct content 739{ 740 long hibin; /* 8-bit characters */ 741 long lobin; /* unprintable 7-bit chars (eg., control chars) */ 742 long nulbin; /* null characters (0x0) */ 743 long crlf; /* '\r' and '\n' characters */ 744 long ascii; /* number of ascii chars */ 745 long linemax; /* length of the longest line in the file */ 746 unsigned int space : 1; /* whitespace at the end of lines? */ 747 unsigned int binary : 1; /* long lines, or CR not in CRLF pair */ 748 unsigned int from : 1; /* has a line beginning with "From "? */ 749 unsigned int dot : 1; /* has a line consisting of a single dot? */ 750 unsigned int cr : 1; /* has CR, even when in a CRLF pair */ 751} CONTENT; 752 753typedef struct body 754{ 755 char *xtype; /* content-type if x-unknown */ 756 char *subtype; /* content-type subtype */ 757 PARAMETER *parameter; /* parameters of the content-type */ 758 char *description; /* content-description */ 759 char *form_name; /* Content-Disposition form-data name param */ 760 long hdr_offset; /* offset in stream where the headers begin. 761 * this info is used when invoking metamail, 762 * where we need to send the headers of the 763 * attachment 764 */ 765 LOFF_T offset; /* offset where the actual data begins */ 766 LOFF_T length; /* length (in bytes) of attachment */ 767 char *filename; /* when sending a message, this is the file 768 * to which this structure refers 769 */ 770 char *d_filename; /* filename to be used for the 771 * content-disposition header. 772 * If NULL, filename is used 773 * instead. 774 */ 775 char *charset; /* send mode: charset of attached file as stored 776 * on disk. the charset used in the generated 777 * message is stored in parameter. */ 778 CONTENT *content; /* structure used to store detailed info about 779 * the content of the attachment. this is used 780 * to determine what content-transfer-encoding 781 * is required when sending mail. 782 */ 783 struct body *next; /* next attachment in the list */ 784 struct body *parts; /* parts of a multipart or message/rfc822 */ 785 struct header *hdr; /* header information for message/rfc822 */ 786 787 struct attachptr *aptr; /* Menu information, used in recvattach.c */ 788 789 signed short attach_count; 790 791 time_t stamp; /* time stamp of last 792 * encoding update. 793 */ 794 795 struct envelope *mime_headers; /* memory hole protected headers */ 796 797 unsigned int type : 4; /* content-type primary type */ 798 unsigned int encoding : 3; /* content-transfer-encoding */ 799 unsigned int disposition : 2; /* content-disposition */ 800 unsigned int use_disp : 1; /* Content-Disposition uses filename= ? */ 801 unsigned int unlink : 1; /* flag to indicate the the file named by 802 * "filename" should be unlink()ed before 803 * free()ing this structure 804 */ 805 unsigned int tagged : 1; 806 unsigned int deleted : 1; /* attachment marked for deletion */ 807 808 unsigned int noconv : 1; /* don't do character set conversion */ 809 unsigned int force_charset : 1; /* send mode: don't adjust the character 810 * set when in send-mode. 811 */ 812 unsigned int is_signed_data : 1; /* A lot of MUAs don't indicate 813 S/MIME signed-data correctly, 814 e.g. they use foo.p7m even for 815 the name of signed data. This 816 flag is used to keep track of 817 the actual message type. It 818 gets set during the verification 819 (which is done if the encryption 820 try failed) and check by the 821 function to figure the type of 822 the message. */ 823 824 unsigned int goodsig : 1; /* good cryptographic signature */ 825 unsigned int warnsig : 1; /* maybe good signature */ 826 unsigned int badsig : 1; /* bad cryptographic signature (needed to check encrypted s/mime-signatures) */ 827#ifdef USE_AUTOCRYPT 828 unsigned int is_autocrypt : 1; /* used to flag autocrypt-decrypted messages 829 * for replying */ 830#endif 831 832 unsigned int collapsed : 1; /* used by recvattach */ 833 unsigned int attach_qualifies : 1; 834 835} BODY; 836 837/* #3279: AIX defines conflicting struct thread */ 838typedef struct mutt_thread THREAD; 839 840typedef struct header 841{ 842 unsigned int security : 14; /* bit 0-10: flags 843 bit 11-12: application. 844 bit 13: traditional pgp. 845 see: mutt_crypt.h pgplib.h, smime.h */ 846 847 unsigned int mime : 1; /* has a MIME-Version header? */ 848 unsigned int flagged : 1; /* marked important? */ 849 unsigned int tagged : 1; 850 unsigned int deleted : 1; 851 unsigned int purge : 1; /* skip trash folder when deleting */ 852 unsigned int changed : 1; 853 unsigned int attach_del : 1; /* has an attachment marked for deletion */ 854 unsigned int old : 1; 855 unsigned int read : 1; 856 unsigned int expired : 1; /* already expired? */ 857 unsigned int superseded : 1; /* got superseded? */ 858 unsigned int replied : 1; 859 unsigned int subject_changed : 1; /* used for threading */ 860 unsigned int threaded : 1; /* used for threading */ 861 unsigned int display_subject : 1; /* used for threading */ 862 unsigned int recip_valid : 1; /* is_recipient is valid */ 863 unsigned int active : 1; /* message is not to be removed */ 864 unsigned int trash : 1; /* message is marked as trashed on disk. 865 * This flag is used by the maildir_trash 866 * option. 867 */ 868 869 /* timezone of the sender of this message */ 870 unsigned int zhours : 5; 871 unsigned int zminutes : 6; 872 unsigned int zoccident : 1; 873 874 /* bits used for caching when searching */ 875 unsigned int searched : 1; 876 unsigned int matched : 1; 877 878 /* tells whether the attachment count is valid */ 879 unsigned int attach_valid : 1; 880 881 /* the following are used to support collapsing threads */ 882 unsigned int collapsed : 1; /* is this message part of a collapsed thread? */ 883 unsigned int limited : 1; /* is this message in a limited view? */ 884 size_t num_hidden; /* number of hidden messages in this view. 885 * only valid for the root header, when 886 * collapsed is set. */ 887 888 short recipient; /* user_is_recipient()'s return value, cached */ 889 890 int pair; /* color-pair to use when displaying in the index */ 891 892 time_t date_sent; /* time when the message was sent (UTC) */ 893 time_t received; /* time when the message was placed in the mailbox */ 894 LOFF_T offset; /* where in the stream does this message begin? */ 895 int lines; /* how many lines in the body of this message? */ 896 int index; /* the absolute (unsorted) message number */ 897 int msgno; /* number displayed to the user */ 898 int virtual; /* virtual message number */ 899 int score; 900 ENVELOPE *env; /* envelope information */ 901 BODY *content; /* list of MIME parts */ 902 char *path; 903 904 char *tree; /* character string to print thread tree */ 905 THREAD *thread; 906 907 /* Number of qualifying attachments in message, if attach_valid */ 908 short attach_total; 909 910#ifdef MIXMASTER 911 LIST *chain; 912#endif 913 914#ifdef USE_POP 915 int refno; /* message number on server */ 916#endif 917 918#if defined USE_POP || defined USE_IMAP 919 void *data; /* driver-specific data */ 920#endif 921 922 char *maildir_flags; /* unknown maildir flags */ 923} HEADER; 924 925struct mutt_thread 926{ 927 unsigned int fake_thread : 1; 928 unsigned int duplicate_thread : 1; 929 unsigned int sort_children : 1; 930 unsigned int check_subject : 1; 931 unsigned int visible : 1; 932 unsigned int deep : 1; 933 unsigned int subtree_visible : 2; 934 unsigned int next_subtree_visible : 1; 935 THREAD *parent; 936 THREAD *child; 937 THREAD *next; 938 THREAD *prev; 939 HEADER *message; 940 HEADER *sort_key; 941}; 942 943 944/* flag to mutt_pattern_comp() */ 945#define MUTT_FULL_MSG (1<<0) /* enable body and header matching */ 946#define MUTT_PATTERN_DYNAMIC (1<<1) /* enable runtime date range evaluation */ 947 948typedef enum { 949 MUTT_MATCH_FULL_ADDRESS = 1 950} pattern_exec_flag; 951 952typedef struct group_t 953{ 954 ADDRESS *as; 955 RX_LIST *rs; 956 char *name; 957} group_t; 958 959typedef struct group_context_t 960{ 961 group_t *g; 962 struct group_context_t *next; 963} group_context_t; 964 965typedef struct pattern_t 966{ 967 short op; 968 unsigned int not : 1; 969 unsigned int alladdr : 1; 970 unsigned int stringmatch : 1; 971 unsigned int groupmatch : 1; 972 unsigned int ign_case : 1; /* ignore case for local stringmatch searches */ 973 unsigned int isalias : 1; 974 unsigned int dynamic : 1; /* evaluate date ranges at run time */ 975 int min; 976 int max; 977 struct pattern_t *next; 978 struct pattern_t *child; /* arguments to logical op */ 979 union 980 { 981 regex_t *rx; 982 group_t *g; 983 char *str; 984 } p; 985} pattern_t; 986 987/* This is used when a message is repeatedly pattern matched against. 988 * e.g. for color, scoring, hooks. It caches a few of the potentially slow 989 * operations. 990 * Each entry has a value of 0 = unset, 1 = false, 2 = true 991 */ 992typedef struct 993{ 994 int list_all; /* ^~l */ 995 int list_one; /* ~l */ 996 int sub_all; /* ^~u */ 997 int sub_one; /* ~u */ 998 int pers_recip_all; /* ^~p */ 999 int pers_recip_one; /* ~p */ 1000 int pers_from_all; /* ^~P */ 1001 int pers_from_one; /* ~P */ 1002} pattern_cache_t; 1003 1004/* ACL Rights */ 1005enum 1006{ 1007 MUTT_ACL_LOOKUP = 0, 1008 MUTT_ACL_READ, 1009 MUTT_ACL_SEEN, 1010 MUTT_ACL_WRITE, 1011 MUTT_ACL_INSERT, 1012 MUTT_ACL_POST, 1013 MUTT_ACL_CREATE, 1014 MUTT_ACL_DELMX, 1015 MUTT_ACL_DELETE, 1016 MUTT_ACL_EXPUNGE, 1017 MUTT_ACL_ADMIN, 1018 1019 RIGHTSMAX 1020}; 1021 1022struct _context; 1023struct _message; 1024 1025/* 1026 * struct mx_ops - a structure to store operations on a mailbox 1027 * The following operations are mandatory: 1028 * - open 1029 * - close 1030 * - check 1031 * 1032 * Optional operations 1033 * - open_new_msg 1034 */ 1035struct mx_ops 1036{ 1037 int (*open) (struct _context *); 1038 int (*open_append) (struct _context *, int flags); 1039 int (*close) (struct _context *); 1040 int (*check) (struct _context *ctx, int *index_hint); 1041 int (*sync) (struct _context *ctx, int *index_hint); 1042 int (*open_msg) (struct _context *, struct _message *, int msgno); 1043 int (*close_msg) (struct _context *, struct _message *); 1044 int (*commit_msg) (struct _context *, struct _message *); 1045 int (*open_new_msg) (struct _message *, struct _context *, HEADER *); 1046 int (*msg_padding_size) (struct _context *); 1047 int (*save_to_header_cache) (struct _context *, struct header *); 1048}; 1049 1050typedef struct _context 1051{ 1052 char *path; 1053 char *realpath; /* used for buffy comparison and the sidebar */ 1054 FILE *fp; 1055 struct timespec atime; 1056 struct timespec mtime; 1057 off_t size; 1058 off_t vsize; 1059 char *pattern; /* limit pattern string */ 1060 pattern_t *limit_pattern; /* compiled limit pattern */ 1061 HEADER **hdrs; 1062 HEADER *last_tag; /* last tagged msg. used to link threads */ 1063 THREAD *tree; /* top of thread tree */ 1064 HASH *id_hash; /* hash table by msg id */ 1065 HASH *subj_hash; /* hash table by subject */ 1066 HASH *thread_hash; /* hash table for threading */ 1067 HASH *label_hash; /* hash table for x-labels */ 1068 int *v2r; /* mapping from virtual to real msgno */ 1069 int hdrmax; /* number of pointers in hdrs */ 1070 int msgcount; /* number of messages in the mailbox */ 1071 int vcount; /* the number of virtual messages */ 1072 int tagged; /* how many messages are tagged? */ 1073 int new; /* how many new messages? */ 1074 int unread; /* how many unread messages? */ 1075 int deleted; /* how many deleted messages */ 1076 int flagged; /* how many flagged messages */ 1077 int msgnotreadyet; /* which msg "new" in pager, -1 if none */ 1078 1079 short magic; /* mailbox type */ 1080 1081 unsigned char rights[(RIGHTSMAX + 7)/8]; /* ACL bits */ 1082 1083 unsigned int locked : 1; /* is the mailbox locked? */ 1084 unsigned int changed : 1; /* mailbox has been modified */ 1085 unsigned int readonly : 1; /* don't allow changes to the mailbox */ 1086 unsigned int dontwrite : 1; /* don't write the mailbox on close */ 1087 unsigned int append : 1; /* mailbox is opened in append mode */ 1088 unsigned int quiet : 1; /* inhibit status messages? */ 1089 unsigned int collapsed : 1; /* are all threads collapsed? */ 1090 unsigned int closing : 1; /* mailbox is being closed */ 1091 unsigned int peekonly : 1; /* just taking a glance, revert atime */ 1092 1093#ifdef USE_COMPRESSED 1094 void *compress_info; /* compressed mbox module private data */ 1095#endif /* USE_COMPRESSED */ 1096 1097 /* driver hooks */ 1098 void *data; /* driver specific data */ 1099 struct mx_ops *mx_ops; 1100} CONTEXT; 1101 1102typedef struct 1103{ 1104 FILE *fpin; 1105 FILE *fpout; 1106 char *prefix; 1107 int flags; 1108} STATE; 1109 1110/* used by enter.c */ 1111 1112typedef struct 1113{ 1114 wchar_t *wbuf; 1115 size_t wbuflen; 1116 size_t lastchar; 1117 size_t curpos; 1118 size_t begin; 1119 int tabs; 1120} ENTER_STATE; 1121 1122/* flags for the STATE struct */ 1123#define MUTT_DISPLAY (1<<0) /* output is displayed to the user */ 1124#define MUTT_VERIFY (1<<1) /* perform signature verification */ 1125#define MUTT_PENDINGPREFIX (1<<2) /* prefix to write, but character must follow */ 1126#define MUTT_WEED (1<<3) /* weed headers even when not in display mode */ 1127#define MUTT_CHARCONV (1<<4) /* Do character set conversions */ 1128#define MUTT_PRINTING (1<<5) /* are we printing? - MUTT_DISPLAY "light" */ 1129#define MUTT_REPLYING (1<<6) /* are we replying? */ 1130#define MUTT_FIRSTDONE (1<<7) /* the first attachment has been done */ 1131 1132#define state_set_prefix(s) ((s)->flags |= MUTT_PENDINGPREFIX) 1133#define state_reset_prefix(s) ((s)->flags &= ~MUTT_PENDINGPREFIX) 1134#define state_puts(x,y) fputs(x,(y)->fpout) 1135#define state_putc(x,y) fputc(x,(y)->fpout) 1136 1137void state_mark_attach (STATE *); 1138void state_mark_protected_header (STATE *); 1139void state_attach_puts (const char *, STATE *); 1140void state_prefix_putc (char, STATE *); 1141int state_printf(STATE *, const char *, ...); 1142int state_putwc (wchar_t, STATE *); 1143int state_putws (const wchar_t *, STATE *); 1144 1145/* for attachment counter */ 1146typedef struct 1147{ 1148 char *major; 1149 int major_int; 1150 char *minor; 1151 regex_t minor_rx; 1152} ATTACH_MATCH; 1153 1154/* multibyte character table. 1155 * Allows for direct access to the individual multibyte characters in a 1156 * string. This is used for the Tochars and StChars option types. */ 1157typedef struct 1158{ 1159 int len; /* number of characters */ 1160 char **chars; /* the array of multibyte character strings */ 1161 char *segmented_str; /* each chars entry points inside this string */ 1162 char *orig_str; 1163} mbchar_table; 1164 1165#define MUTT_PARTS_TOPLEVEL (1<<0) /* is the top-level part */ 1166 1167#include "ascii.h" 1168#include "protos.h" 1169#include "lib.h" 1170#include "globals.h" 1171 1172#endif /*MUTT_H*/