From: ak1 Date: Fri, 18 Mar 2005 08:34:27 +0000 (+0000) Subject: Andreas Krennmair: X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=df70e07e24add1869bcc9b7af2277d9d0c09a281 Andreas Krennmair: reformatted source code using muttng_indent.sh script git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@194 e385b8ad-14ed-0310-8656-cc95a2468c6d --- diff --git a/Makefile.in b/Makefile.in index 19f47b4..d0746d7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,8 +1,6 @@ -# Makefile.in generated by automake 1.7.6 from Makefile.am. -# @configure_input@ +# Makefile.in generated automatically by automake 1.4-p4 from Makefile.am -# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 -# Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -12,87 +10,73 @@ # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. -@SET_MAKE@ + +SHELL = @SHELL@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ + top_builddir = . -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : +host_alias = @host_alias@ host_triplet = @host@ -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BUILD_IMAP_FALSE = @BUILD_IMAP_FALSE@ -BUILD_IMAP_TRUE = @BUILD_IMAP_TRUE@ BUILD_INCLUDED_LIBINTL = @BUILD_INCLUDED_LIBINTL@ CATALOGS = @CATALOGS@ CATOBJEXT = @CATOBJEXT@ CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ - - -# $(makedoc_OBJECTS): $(makedoc_SOURCES) -# $(HOST_CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -c $< - -# makedoc: $(makedoc_OBJECTS) $(makedoc_DEPENDENCIES) -# @rm -rf makedoc -# $(HOST_CC) $(AM_CFLAGS) $(LDFLAGS) $(makedoc_LDFLAGS) $(makedoc_OBJECTS) $(makedoc_LDADD) -o makedoc -CPP = @CPP@ - -CPPFLAGS = @CPPFLAGS@ -I$(includedir) -CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DBX = @DBX@ DEBUGGER = @DEBUGGER@ - -DEFS = -DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \ - -DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \ - -DHAVE_CONFIG_H=1 - -DEPDIR = @DEPDIR@ DOTLOCK_GROUP = @DOTLOCK_GROUP@ DOTLOCK_PERMISSION = @DOTLOCK_PERMISSION@ DOTLOCK_TARGET = @DOTLOCK_TARGET@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ GDB = @GDB@ GENCAT = @GENCAT@ GLIBC21 = @GLIBC21@ GMOFILES = @GMOFILES@ GMSGFMT = @GMSGFMT@ GPGME_CONFIG = @GPGME_CONFIG@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +HAVE_LIB = @HAVE_LIB@ INSTOBJEXT = @INSTOBJEXT@ INTLBISON = @INTLBISON@ INTLLIBS = @INTLLIBS@ @@ -100,7 +84,7 @@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ ISPELL = @ISPELL@ KRB5CFGPATH = @KRB5CFGPATH@ -LDFLAGS = @LDFLAGS@ +LIB = @LIB@ LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@ LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@ LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@ @@ -109,84 +93,30 @@ LIBGPGME_LIBS = @LIBGPGME_LIBS@ LIBICONV = @LIBICONV@ LIBIMAP = @LIBIMAP@ LIBIMAPDEPS = @LIBIMAPDEPS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ +LTLIB = @LTLIB@ MAKEINFO = @MAKEINFO@ MKINSTALLDIRS = @MKINSTALLDIRS@ MSGFMT = @MSGFMT@ MUTTLIBS = @MUTTLIBS@ MUTT_LIB_OBJECTS = @MUTT_LIB_OBJECTS@ -OBJEXT = @OBJEXT@ - -OPS = @OPS@ PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ PGPAUX_TARGET = @PGPAUX_TARGET@ POFILES = @POFILES@ POSUB = @POSUB@ RANLIB = @RANLIB@ SDB = @SDB@ SENDMAIL = @SENDMAIL@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ +SGML2HTML_CMD = @SGML2HTML_CMD@ +SGML2PS_CMD = @SGML2PS_CMD@ +SGML2TXT_CMD = @SGML2TXT_CMD@ SMIMEAUX_TARGET = @SMIMEAUX_TARGET@ -STRIP = @STRIP@ SUBVERSION = @SUBVERSION@ U = @U@ -USE_GSS_FALSE = @USE_GSS_FALSE@ -USE_GSS_TRUE = @USE_GSS_TRUE@ USE_INCLUDED_LIBINTL = @USE_INCLUDED_LIBINTL@ USE_NLS = @USE_NLS@ -USE_SASL_FALSE = @USE_SASL_FALSE@ -USE_SASL_TRUE = @USE_SASL_TRUE@ -USE_SSL_FALSE = @USE_SSL_FALSE@ -USE_SSL_TRUE = @USE_SSL_TRUE@ VERSION = @VERSION@ -XGETTEXT = @XGETTEXT@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -datadir = @datadir@ docdir = @docdir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ mutt_libesmtp_config_path = @mutt_libesmtp_config_path@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ AUTOMAKE_OPTIONS = foreign EXTRA_PROGRAMS = muttng_dotlock pgpringng pgpewrapng makedoc @@ -201,59 +131,39 @@ bin_SCRIPTS = muttngbug fleang BUILT_SOURCES = keymap_defs.h patchlist.c bin_PROGRAMS = muttng @DOTLOCK_TARGET@ @PGPAUX_TARGET@ @SMIMEAUX_TARGET@ -muttng_SOURCES = $(BUILT_SOURCES) \ - addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c \ - compress.c crypt.c cryptglue.c \ - commands.c complete.c compose.c copy.c curs_lib.c curs_main.c date.c \ - edit.c enter.c flags.c init.c filter.c from.c getdomain.c \ - handler.c hash.c hdrline.c headers.c help.c hook.c keymap.c \ - main.c mbox.c menu.c mh.c mx.c pager.c parse.c pattern.c \ - postpone.c query.c recvattach.c recvcmd.c \ - rfc822.c rfc1524.c rfc2047.c rfc2231.c \ - score.c send.c sendlib.c signal.c sort.c \ - status.c system.c thread.c charset.c history.c lib.c \ - muttlib.c editmsg.c utf8.c mbyte.c wcwidth.c md5c.c \ - url.c ascii.c mutt_idna.c sidebar.c hcache.c crypt-mod.c crypt-mod.h +muttng_SOURCES = $(BUILT_SOURCES) addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c compress.c crypt.c cryptglue.c commands.c complete.c compose.c copy.c curs_lib.c curs_main.c date.c edit.c enter.c flags.c init.c filter.c from.c getdomain.c handler.c hash.c hdrline.c headers.c help.c hook.c keymap.c main.c mbox.c menu.c mh.c mx.c pager.c parse.c pattern.c postpone.c query.c recvattach.c recvcmd.c rfc822.c rfc1524.c rfc2047.c rfc2231.c score.c send.c sendlib.c signal.c sort.c status.c system.c thread.c charset.c history.c lib.c muttlib.c editmsg.c utf8.c mbyte.c wcwidth.c md5c.c url.c ascii.c mutt_idna.c sidebar.c hcache.c crypt-mod.c crypt-mod.h -muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(MUTTLIBS) \ - $(INTLLIBS) $(LIBICONV) +muttng_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) -muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAPDEPS) \ - $(INTLDEPS) +muttng_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAPDEPS) $(INTLDEPS) makedoc_SOURCES = makedoc.c makedoc_LDADD = makedoc_DEPENDENCIES = +# $(makedoc_OBJECTS): $(makedoc_SOURCES) +# $(HOST_CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -c $< + +# makedoc: $(makedoc_OBJECTS) $(makedoc_DEPENDENCIES) +# @rm -rf makedoc +# $(HOST_CC) $(AM_CFLAGS) $(LDFLAGS) $(makedoc_LDFLAGS) $(makedoc_OBJECTS) $(makedoc_LDADD) -o makedoc + +CPP = @CPP@ + +DEFS = -DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" -DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" -DHAVE_CONFIG_H=1 + + INCLUDES = -I. -I$(top_srcdir) $(IMAP_INCLUDES) $(LIBGPGME_CFLAGS) -Iintl -EXTRA_muttng_SOURCES = account.c md5c.c mutt_sasl.c mutt_socket.c mutt_ssl.c \ - mutt_tunnel.c pop.c pop_auth.c pop_lib.c smime.c pgp.c pgpinvoke.c pgpkey.c \ - pgplib.c sha1.c pgpmicalg.c gnupgparse.c resize.c dotlock.c remailer.c \ - browser.h mbyte.h remailer.h url.h mutt_ssl_nss.c \ - pgppacket.c mutt_idna.h nntp.c newsrc.c mutt_libesmtp.c \ - sidebar.h crypt-mod-pgp-classic.c crypt-mod-smime-classic.c - - -EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO \ - configure acconfig.h account.h \ - compress.h \ - attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \ - globals.h hash.h history.h init.h keymap.h mutt_crypt.h \ - mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \ - mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \ - mx.h pager.h pgp.h pop.h protos.h reldate.h rfc1524.h rfc2047.h \ - rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \ - nntp.h ChangeLog.nntp \ - _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \ - mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h Muttngrc.head Muttngrc \ - makedoc.c stamp-doc-rc README.SSL smime.h\ - muttngbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh \ - ChangeLog.old mkchangelog.sh cvslog2changelog.pl mutt_idna.h \ - snprintf.c regex.c mutt_libesmtp.h crypt-gpgme.h +CPPFLAGS = @CPPFLAGS@ -I$(includedir) + +EXTRA_muttng_SOURCES = account.c md5c.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_tunnel.c pop.c pop_auth.c pop_lib.c smime.c pgp.c pgpinvoke.c pgpkey.c pgplib.c sha1.c pgpmicalg.c gnupgparse.c resize.c dotlock.c remailer.c browser.h mbyte.h remailer.h url.h mutt_ssl_nss.c pgppacket.c mutt_idna.h nntp.c newsrc.c mutt_libesmtp.c sidebar.h crypt-mod-pgp-classic.c crypt-mod-smime-classic.c + + +EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO configure acconfig.h account.h compress.h attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs globals.h hash.h history.h init.h keymap.h mutt_crypt.h mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h mx.h pager.h pgp.h pop.h protos.h reldate.h rfc1524.h rfc2047.h rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare nntp.h ChangeLog.nntp _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h Muttngrc.head Muttngrc makedoc.c stamp-doc-rc README.SSL smime.h muttngbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh ChangeLog.old mkchangelog.sh cvslog2changelog.pl mutt_idna.h snprintf.c regex.c mutt_libesmtp.h crypt-gpgme.h muttng_dotlock_SOURCES = mutt_dotlock.c @@ -268,221 +178,211 @@ pgpewrapng_SOURCES = pgpewrap.c pgpewrapng_LDADD = pgpewrapng_DEPENDENCIES = -CLEANFILES = mutt_dotlock.c stamp-doc-rc makedoc \ - keymap_alldefs.h keymap_defs.h patchlist.c +CLEANFILES = mutt_dotlock.c stamp-doc-rc makedoc keymap_alldefs.h keymap_defs.h patchlist.c ACLOCAL_AMFLAGS = -I m4 LDADD = @LIBOBJS@ @INTLLIBS@ -subdir = . + +OPS = @OPS@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = intl/Makefile doc/Makefile contrib/Makefile \ - muttbug.sh Muttngrc.head doc/instdoc.sh -EXTRA_PROGRAMS = muttng_dotlock$(EXEEXT) pgpringng$(EXEEXT) \ - pgpewrapng$(EXEEXT) makedoc$(EXEEXT) -bin_PROGRAMS = muttng$(EXEEXT) @DOTLOCK_TARGET@ @PGPAUX_TARGET@ \ - @SMIMEAUX_TARGET@ -PROGRAMS = $(bin_PROGRAMS) - -am_makedoc_OBJECTS = makedoc.$(OBJEXT) -makedoc_OBJECTS = $(am_makedoc_OBJECTS) -makedoc_LDFLAGS = -am__objects_1 = patchlist.$(OBJEXT) -am_muttng_OBJECTS = $(am__objects_1) addrbook.$(OBJEXT) alias.$(OBJEXT) \ - attach.$(OBJEXT) base64.$(OBJEXT) browser.$(OBJEXT) \ - buffy.$(OBJEXT) color.$(OBJEXT) compress.$(OBJEXT) \ - crypt.$(OBJEXT) cryptglue.$(OBJEXT) commands.$(OBJEXT) \ - complete.$(OBJEXT) compose.$(OBJEXT) copy.$(OBJEXT) \ - curs_lib.$(OBJEXT) curs_main.$(OBJEXT) date.$(OBJEXT) \ - edit.$(OBJEXT) enter.$(OBJEXT) flags.$(OBJEXT) init.$(OBJEXT) \ - filter.$(OBJEXT) from.$(OBJEXT) getdomain.$(OBJEXT) \ - handler.$(OBJEXT) hash.$(OBJEXT) hdrline.$(OBJEXT) \ - headers.$(OBJEXT) help.$(OBJEXT) hook.$(OBJEXT) \ - keymap.$(OBJEXT) main.$(OBJEXT) mbox.$(OBJEXT) menu.$(OBJEXT) \ - mh.$(OBJEXT) mx.$(OBJEXT) pager.$(OBJEXT) parse.$(OBJEXT) \ - pattern.$(OBJEXT) postpone.$(OBJEXT) query.$(OBJEXT) \ - recvattach.$(OBJEXT) recvcmd.$(OBJEXT) rfc822.$(OBJEXT) \ - rfc1524.$(OBJEXT) rfc2047.$(OBJEXT) rfc2231.$(OBJEXT) \ - score.$(OBJEXT) send.$(OBJEXT) sendlib.$(OBJEXT) \ - signal.$(OBJEXT) sort.$(OBJEXT) status.$(OBJEXT) \ - system.$(OBJEXT) thread.$(OBJEXT) charset.$(OBJEXT) \ - history.$(OBJEXT) lib.$(OBJEXT) muttlib.$(OBJEXT) \ - editmsg.$(OBJEXT) utf8.$(OBJEXT) mbyte.$(OBJEXT) \ - wcwidth.$(OBJEXT) md5c.$(OBJEXT) url.$(OBJEXT) ascii.$(OBJEXT) \ - mutt_idna.$(OBJEXT) sidebar.$(OBJEXT) hcache.$(OBJEXT) \ - crypt-mod.$(OBJEXT) -muttng_OBJECTS = $(am_muttng_OBJECTS) -muttng_LDFLAGS = -am_muttng_dotlock_OBJECTS = mutt_dotlock.$(OBJEXT) -muttng_dotlock_OBJECTS = $(am_muttng_dotlock_OBJECTS) -muttng_dotlock_LDFLAGS = -am_pgpewrapng_OBJECTS = pgpewrap.$(OBJEXT) -pgpewrapng_OBJECTS = $(am_pgpewrapng_OBJECTS) -pgpewrapng_LDFLAGS = -am_pgpringng_OBJECTS = pgppubring.$(OBJEXT) pgplib.$(OBJEXT) \ - lib.$(OBJEXT) extlib.$(OBJEXT) sha1.$(OBJEXT) md5c.$(OBJEXT) \ - pgppacket.$(OBJEXT) ascii.$(OBJEXT) -pgpringng_OBJECTS = $(am_pgpringng_OBJECTS) -pgpringng_LDFLAGS = -SCRIPTS = $(bin_SCRIPTS) - - -DEFAULT_INCLUDES = -I. -I$(srcdir) -I. -depcomp = -am__depfiles_maybe = -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CONFIG_CLEAN_FILES = muttbug.sh Muttngrc.head +PROGRAMS = $(bin_PROGRAMS) + +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +muttng_dotlock_OBJECTS = mutt_dotlock.o +muttng_dotlock_LDFLAGS = +pgpringng_OBJECTS = pgppubring.o pgplib.o lib.o extlib.o sha1.o md5c.o \ +pgppacket.o ascii.o +pgpringng_LDFLAGS = +pgpewrapng_OBJECTS = pgpewrap.o +pgpewrapng_LDFLAGS = +makedoc_OBJECTS = makedoc.o +makedoc_LDFLAGS = +muttng_OBJECTS = patchlist.o addrbook.o alias.o attach.o base64.o \ +browser.o buffy.o color.o compress.o crypt.o cryptglue.o commands.o \ +complete.o compose.o copy.o curs_lib.o curs_main.o date.o edit.o \ +enter.o flags.o init.o filter.o from.o getdomain.o handler.o hash.o \ +hdrline.o headers.o help.o hook.o keymap.o main.o mbox.o menu.o mh.o \ +mx.o pager.o parse.o pattern.o postpone.o query.o recvattach.o \ +recvcmd.o rfc822.o rfc1524.o rfc2047.o rfc2231.o score.o send.o \ +sendlib.o signal.o sort.o status.o system.o thread.o charset.o \ +history.o lib.o muttlib.o editmsg.o utf8.o mbyte.o wcwidth.o md5c.o \ +url.o ascii.o mutt_idna.o sidebar.o hcache.o crypt-mod.o +muttng_LDFLAGS = +SCRIPTS = $(bin_SCRIPTS) + +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -DIST_SOURCES = $(makedoc_SOURCES) $(muttng_SOURCES) \ - $(EXTRA_muttng_SOURCES) $(muttng_dotlock_SOURCES) \ - $(pgpewrapng_SOURCES) $(pgpringng_SOURCES) - -RECURSIVE_TARGETS = info-recursive dvi-recursive pdf-recursive \ - ps-recursive install-info-recursive uninstall-info-recursive \ - all-recursive install-data-recursive install-exec-recursive \ - installdirs-recursive install-recursive uninstall-recursive \ - check-recursive installcheck-recursive -DIST_COMMON = README ABOUT-NLS ChangeLog INSTALL Makefile.am \ - Makefile.in Muttngrc.head.in NEWS TODO acconfig.h aclocal.m4 \ - config.guess config.h.in config.sub configure configure.in \ - depcomp install-sh missing mkinstalldirs muttbug.sh.in regex.c \ - snprintf.c strcasecmp.c strdup.c -DIST_SUBDIRS = m4 po intl doc contrib imap -SOURCES = $(makedoc_SOURCES) $(muttng_SOURCES) $(EXTRA_muttng_SOURCES) $(muttng_dotlock_SOURCES) $(pgpewrapng_SOURCES) $(pgpringng_SOURCES) - -all: $(BUILT_SOURCES) config.h - $(MAKE) $(AM_MAKEFLAGS) all-recursive +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = README ./stamp-h.in ABOUT-NLS ChangeLog INSTALL \ +Makefile.am Makefile.in Muttngrc.head.in NEWS TODO acconfig.h \ +aclocal.m4 config.guess config.h.in config.sub configure configure.in \ +install-sh missing mkinstalldirs muttbug.sh.in strcasecmp.c strdup.c -.SUFFIXES: -.SUFFIXES: .c .o .obj -am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ - configure.lineno -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign --ignore-deps Makefile +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -$(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - $(SHELL) ./config.status --recheck -$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) - cd $(srcdir) && $(AUTOCONF) +TAR = tar +GZIP_ENV = --best +DIST_SUBDIRS = m4 po intl doc contrib imap +SOURCES = $(muttng_dotlock_SOURCES) $(pgpringng_SOURCES) $(pgpewrapng_SOURCES) $(makedoc_SOURCES) $(muttng_SOURCES) $(EXTRA_muttng_SOURCES) +OBJECTS = $(muttng_dotlock_OBJECTS) $(pgpringng_OBJECTS) $(pgpewrapng_OBJECTS) $(makedoc_OBJECTS) $(muttng_OBJECTS) -$(ACLOCAL_M4): configure.in m4/codeset.m4 m4/curslib.m4 m4/funcdecl.m4 m4/gettext.m4 m4/glibc21.m4 m4/gssapi.m4 m4/iconv.m4 m4/lcmessage.m4 m4/libesmtp.m4 m4/libgnutls.m4 m4/progtest.m4 m4/types.m4 +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .o .s +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status + +$(ACLOCAL_M4): configure.in m4/codeset.m4 m4/curslib.m4 m4/funcdecl.m4 \ + m4/gettext.m4 m4/glibc21.m4 m4/gssapi.m4 m4/iconv.m4 \ + m4/lcmessage.m4 m4/libesmtp.m4 m4/libgnutls.m4 \ + m4/progtest.m4 m4/types.m4 cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) -config.h: stamp-h1 +config.status: $(srcdir)/configure.in $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck +$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES) + cd $(srcdir) && $(AUTOCONF) + +config.h: stamp-h + @if test ! -f $@; then \ + rm -f stamp-h; \ + $(MAKE) stamp-h; \ + else :; fi +stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES= CONFIG_HEADERS=config.h \ + $(SHELL) ./config.status + @echo timestamp > stamp-h 2> /dev/null +$(srcdir)/config.h.in: $(srcdir)/stamp-h.in @if test ! -f $@; then \ - rm -f stamp-h1; \ - $(MAKE) stamp-h1; \ + rm -f $(srcdir)/stamp-h.in; \ + $(MAKE) $(srcdir)/stamp-h.in; \ else :; fi +$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h + cd $(top_srcdir) && $(AUTOHEADER) + @echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null -stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status - @rm -f stamp-h1 - cd $(top_builddir) && $(SHELL) ./config.status config.h +mostlyclean-hdr: -$(srcdir)/config.h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) $(top_srcdir)/acconfig.h - cd $(top_srcdir) && $(AUTOHEADER) - touch $(srcdir)/config.h.in +clean-hdr: distclean-hdr: - -rm -f config.h stamp-h1 -intl/Makefile: $(top_builddir)/config.status $(top_srcdir)/intl/Makefile.in - cd $(top_builddir) && $(SHELL) ./config.status $@ -doc/Makefile: $(top_builddir)/config.status $(top_srcdir)/doc/Makefile.in - cd $(top_builddir) && $(SHELL) ./config.status $@ -contrib/Makefile: $(top_builddir)/config.status $(top_srcdir)/contrib/Makefile.in - cd $(top_builddir) && $(SHELL) ./config.status $@ + -rm -f config.h + +maintainer-clean-hdr: muttbug.sh: $(top_builddir)/config.status muttbug.sh.in - cd $(top_builddir) && $(SHELL) ./config.status $@ + cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status Muttngrc.head: $(top_builddir)/config.status Muttngrc.head.in - cd $(top_builddir) && $(SHELL) ./config.status $@ -doc/instdoc.sh: $(top_builddir)/config.status $(top_srcdir)/doc/instdoc.sh.in - cd $(top_builddir) && $(SHELL) ./config.status $@ -binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) + cd $(top_builddir) && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status + +mostlyclean-binPROGRAMS: + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +distclean-binPROGRAMS: + +maintainer-clean-binPROGRAMS: + install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(bindir) @list='$(bin_PROGRAMS)'; for p in $$list; do \ - p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - if test -f $$p \ - ; then \ - f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \ - $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \ + if test -f $$p; then \ + echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \ + $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ else :; fi; \ done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ - rm -f $(DESTDIR)$(bindir)/$$f; \ + list='$(bin_PROGRAMS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \ done -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -makedoc$(EXEEXT): $(makedoc_OBJECTS) $(makedoc_DEPENDENCIES) - @rm -f makedoc$(EXEEXT) - $(LINK) $(makedoc_LDFLAGS) $(makedoc_OBJECTS) $(makedoc_LDADD) $(LIBS) -muttng$(EXEEXT): $(muttng_OBJECTS) $(muttng_DEPENDENCIES) - @rm -f muttng$(EXEEXT) - $(LINK) $(muttng_LDFLAGS) $(muttng_OBJECTS) $(muttng_LDADD) $(LIBS) -muttng_dotlock$(EXEEXT): $(muttng_dotlock_OBJECTS) $(muttng_dotlock_DEPENDENCIES) - @rm -f muttng_dotlock$(EXEEXT) +.c.o: + $(COMPILE) -c $< + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +muttng_dotlock: $(muttng_dotlock_OBJECTS) $(muttng_dotlock_DEPENDENCIES) + @rm -f muttng_dotlock $(LINK) $(muttng_dotlock_LDFLAGS) $(muttng_dotlock_OBJECTS) $(muttng_dotlock_LDADD) $(LIBS) -pgpewrapng$(EXEEXT): $(pgpewrapng_OBJECTS) $(pgpewrapng_DEPENDENCIES) - @rm -f pgpewrapng$(EXEEXT) - $(LINK) $(pgpewrapng_LDFLAGS) $(pgpewrapng_OBJECTS) $(pgpewrapng_LDADD) $(LIBS) -pgpringng$(EXEEXT): $(pgpringng_OBJECTS) $(pgpringng_DEPENDENCIES) - @rm -f pgpringng$(EXEEXT) + +pgpringng: $(pgpringng_OBJECTS) $(pgpringng_DEPENDENCIES) + @rm -f pgpringng $(LINK) $(pgpringng_LDFLAGS) $(pgpringng_OBJECTS) $(pgpringng_LDADD) $(LIBS) -binSCRIPT_INSTALL = $(INSTALL_SCRIPT) + +pgpewrapng: $(pgpewrapng_OBJECTS) $(pgpewrapng_DEPENDENCIES) + @rm -f pgpewrapng + $(LINK) $(pgpewrapng_LDFLAGS) $(pgpewrapng_OBJECTS) $(pgpewrapng_LDADD) $(LIBS) + +makedoc: $(makedoc_OBJECTS) $(makedoc_DEPENDENCIES) + @rm -f makedoc + $(LINK) $(makedoc_LDFLAGS) $(makedoc_OBJECTS) $(makedoc_LDADD) $(LIBS) + +muttng: $(muttng_OBJECTS) $(muttng_DEPENDENCIES) + @rm -f muttng + $(LINK) $(muttng_LDFLAGS) $(muttng_OBJECTS) $(muttng_LDADD) $(LIBS) + install-binSCRIPTS: $(bin_SCRIPTS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(bindir) @list='$(bin_SCRIPTS)'; for p in $$list; do \ - if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ - if test -f $$d$$p; then \ - f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ - echo " $(binSCRIPT_INSTALL) $$d$$p $(DESTDIR)$(bindir)/$$f"; \ - $(binSCRIPT_INSTALL) $$d$$p $(DESTDIR)$(bindir)/$$f; \ - else :; fi; \ + if test -f $$p; then \ + echo " $(INSTALL_SCRIPT) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ + $(INSTALL_SCRIPT) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + else if test -f $(srcdir)/$$p; then \ + echo " $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ + $(INSTALL_SCRIPT) $(srcdir)/$$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + else :; fi; fi; \ done uninstall-binSCRIPTS: @$(NORMAL_UNINSTALL) - @list='$(bin_SCRIPTS)'; for p in $$list; do \ - f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \ - echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ - rm -f $(DESTDIR)$(bindir)/$$f; \ + list='$(bin_SCRIPTS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ done -mostlyclean-compile: - -rm -f *.$(OBJEXT) core *.core - -distclean-compile: - -rm -f *.tab.c - -.c.o: - $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< - -.c.obj: - $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi` -uninstall-info-am: - # This directory's subdirectories are mostly independent; you can cd # into them and run `make' without going through this Makefile. # To change the values of `make' variables: instead of editing Makefiles, # (1) if the variable is set in `config.status', edit `config.status' # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. -$(RECURSIVE_TARGETS): - @set fnord $$MAKEFLAGS; amf=$$2; \ + +@SET_MAKE@ + +all-recursive install-data-recursive install-exec-recursive \ +installdirs-recursive install-recursive uninstall-recursive \ +check-recursive installcheck-recursive info-recursive dvi-recursive: + @set fnord $(MAKEFLAGS); amf=$$2; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ list='$(SUBDIRS)'; for subdir in $$list; do \ @@ -502,18 +402,13 @@ $(RECURSIVE_TARGETS): mostlyclean-recursive clean-recursive distclean-recursive \ maintainer-clean-recursive: - @set fnord $$MAKEFLAGS; amf=$$2; \ + @set fnord $(MAKEFLAGS); amf=$$2; \ dot_seen=no; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - rev=''; for subdir in $$list; do \ - if test "$$subdir" = "."; then :; else \ - rev="$$subdir $$rev"; \ - fi; \ + rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \ + rev="$$subdir $$rev"; \ + test "$$subdir" = "." && dot_seen=yes; \ done; \ - rev="$$rev ."; \ + test "$$dot_seen" = "no" && rev=". $$rev"; \ target=`echo $@ | sed s/-recursive//`; \ for subdir in $$rev; do \ echo "Making $$target in $$subdir"; \ @@ -529,227 +424,132 @@ tags-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ done -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ - done - -ETAGS = etags -ETAGSFLAGS = - -CTAGS = ctags -CTAGSFLAGS = tags: TAGS -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ - mkid -fID $$unique + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) -TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) +TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP) tags=; \ here=`pwd`; \ - if (etags --etags-include --version) >/dev/null 2>&1; then \ - include_option=--etags-include; \ - else \ - include_option=--include; \ - fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -f $$subdir/TAGS && \ - tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ - fi; \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \ + fi; \ done; \ - list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$tags$$unique" \ - || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique + test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS) -ctags: CTAGS -CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique +mostlyclean-tags: -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here +clean-tags: distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) - -top_distdir = . -distdir = $(PACKAGE)-$(VERSION) + -rm -f TAGS ID -am__remove_distdir = \ - { test ! -d $(distdir) \ - || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \ - && rm -fr $(distdir); }; } +maintainer-clean-tags: -GZIP_ENV = --best -distuninstallcheck_listfiles = find . -type f -print -distcleancheck_listfiles = find . -type f -print +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + -rm -rf $(distdir) + GZIP=$(GZIP_ENV) $(TAR) zxf $(distdir).tar.gz + mkdir $(distdir)/=build + mkdir $(distdir)/=inst + dc_install_base=`cd $(distdir)/=inst && pwd`; \ + cd $(distdir)/=build \ + && ../configure --with-included-gettext --srcdir=.. --prefix=$$dc_install_base \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) dist + -rm -rf $(distdir) + @banner="$(distdir).tar.gz is ready for distribution"; \ + dashes=`echo "$$banner" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + echo "$$dashes" +dist: distdir + -chmod -R a+r $(distdir) + GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) + -rm -rf $(distdir) +dist-all: distdir + -chmod -R a+r $(distdir) + GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir) + -rm -rf $(distdir) distdir: $(DISTFILES) - $(am__remove_distdir) + -rm -rf $(distdir) mkdir $(distdir) - $(mkinstalldirs) $(distdir)/. $(distdir)/contrib $(distdir)/doc $(distdir)/intl $(distdir)/po - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkinstalldirs) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ + -chmod 777 $(distdir) + @for file in $(DISTFILES); do \ + d=$(srcdir); \ if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + cp -pr $$d/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ fi; \ done - list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + for subdir in $(DIST_SUBDIRS); do \ if test "$$subdir" = .; then :; else \ test -d $(distdir)/$$subdir \ || mkdir $(distdir)/$$subdir \ || exit 1; \ - (cd $$subdir && \ - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$(top_distdir)" \ - distdir=../$(distdir)/$$subdir \ - distdir) \ + chmod 777 $(distdir)/$$subdir; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \ || exit 1; \ fi; \ done - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$(top_distdir)" distdir="$(distdir)" \ - dist-hook - -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \ - ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ - ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ - ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \ - || chmod -R a+r $(distdir) -dist-gzip: distdir - $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) - -dist dist-all: distdir - $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz - $(am__remove_distdir) - -# This target untars the dist file and tries a VPATH configuration. Then -# it guarantees that the distribution is self-contained by making another -# tarfile. -distcheck: dist - $(am__remove_distdir) - GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf - - chmod -R a-w $(distdir); chmod a+w $(distdir) - mkdir $(distdir)/_build - mkdir $(distdir)/_inst - chmod a-w $(distdir) - dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ - && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ - && cd $(distdir)/_build \ - && ../configure --srcdir=.. --prefix="$$dc_install_base" \ - $(DISTCHECK_CONFIGURE_FLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ - && $(MAKE) $(AM_MAKEFLAGS) check \ - && $(MAKE) $(AM_MAKEFLAGS) install \ - && $(MAKE) $(AM_MAKEFLAGS) installcheck \ - && $(MAKE) $(AM_MAKEFLAGS) uninstall \ - && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ - distuninstallcheck \ - && chmod -R a-w "$$dc_install_base" \ - && ({ \ - (cd ../.. && $(mkinstalldirs) "$$dc_destdir") \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ - && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ - distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ - } || { rm -rf "$$dc_destdir"; exit 1; }) \ - && rm -rf "$$dc_destdir" \ - && $(MAKE) $(AM_MAKEFLAGS) dist-gzip \ - && rm -f $(distdir).tar.gz \ - && $(MAKE) $(AM_MAKEFLAGS) distcleancheck - $(am__remove_distdir) - @echo "$(distdir).tar.gz is ready for distribution" | \ - sed 'h;s/./=/g;p;x;p;x' -distuninstallcheck: - @cd $(distuninstallcheck_dir) \ - && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \ - || { echo "ERROR: files left after uninstall:" ; \ - if test -n "$(DESTDIR)"; then \ - echo " (check DESTDIR support)"; \ - fi ; \ - $(distuninstallcheck_listfiles) ; \ - exit 1; } >&2 -distcleancheck: distclean - @if test '$(srcdir)' = . ; then \ - echo "ERROR: distcleancheck can only run from a VPATH build" ; \ - exit 1 ; \ - fi - @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ - || { echo "ERROR: files left in build directory after distclean:" ; \ - $(distcleancheck_listfiles) ; \ - exit 1; } >&2 + $(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-hook +info-am: +info: info-recursive +dvi-am: +dvi: dvi-recursive check-am: all-am -check: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) check-recursive -all-am: Makefile $(PROGRAMS) $(SCRIPTS) config.h -installdirs: installdirs-recursive -installdirs-am: - $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(bindir) +check: check-recursive +installcheck-am: +installcheck: installcheck-recursive +all-recursive-am: config.h + $(MAKE) $(AM_MAKEFLAGS) all-recursive -install: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) install-recursive +install-exec-am: install-binPROGRAMS install-binSCRIPTS \ + install-exec-local install-exec: install-exec-recursive + +install-data-am: install-data-local install-data: install-data-recursive -uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-recursive +install: install-recursive +uninstall-am: uninstall-binPROGRAMS uninstall-binSCRIPTS +uninstall: uninstall-recursive +all-am: Makefile $(PROGRAMS) $(SCRIPTS) config.h +all-redirect: all-recursive-am install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: installdirs-recursive +installdirs-am: + $(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(bindir) + + mostlyclean-generic: clean-generic: @@ -757,81 +557,53 @@ clean-generic: distclean-generic: -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -clean: clean-recursive - -clean-am: clean-binPROGRAMS clean-generic mostlyclean-am - -distclean: distclean-recursive - -rm -f $(am__CONFIG_DISTCLEAN_FILES) -distclean-am: clean-am distclean-compile distclean-generic distclean-hdr \ - distclean-tags - -dvi: dvi-recursive - -dvi-am: - -info: info-recursive - -info-am: - -install-data-am: install-data-local - -install-exec-am: install-binPROGRAMS install-binSCRIPTS \ - install-exec-local - -install-info: install-info-recursive - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-recursive - -rm -f $(am__CONFIG_DISTCLEAN_FILES) - -rm -rf $(top_srcdir)/autom4te.cache -maintainer-clean-am: distclean-am maintainer-clean-generic +mostlyclean-am: mostlyclean-hdr mostlyclean-binPROGRAMS \ + mostlyclean-compile mostlyclean-tags \ + mostlyclean-generic mostlyclean: mostlyclean-recursive -mostlyclean-am: mostlyclean-compile mostlyclean-generic +clean-am: clean-hdr clean-binPROGRAMS clean-compile clean-tags \ + clean-generic mostlyclean-am -pdf: pdf-recursive - -pdf-am: - -ps: ps-recursive +clean: clean-recursive -ps-am: +distclean-am: distclean-hdr distclean-binPROGRAMS distclean-compile \ + distclean-tags distclean-generic clean-am -uninstall-am: uninstall-binPROGRAMS uninstall-binSCRIPTS \ - uninstall-info-am +distclean: distclean-recursive + -rm -f config.status -uninstall-info: uninstall-info-recursive +maintainer-clean-am: maintainer-clean-hdr maintainer-clean-binPROGRAMS \ + maintainer-clean-compile maintainer-clean-tags \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." -.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am clean \ - clean-binPROGRAMS clean-generic clean-recursive ctags \ - ctags-recursive dist dist-all dist-gzip distcheck distclean \ - distclean-compile distclean-generic distclean-hdr \ - distclean-recursive distclean-tags distcleancheck distdir \ - distuninstallcheck dvi dvi-am dvi-recursive info info-am \ - info-recursive install install-am install-binPROGRAMS \ - install-binSCRIPTS install-data install-data-am \ - install-data-local install-data-recursive install-exec \ - install-exec-am install-exec-local install-exec-recursive \ - install-info install-info-am install-info-recursive install-man \ - install-recursive install-strip installcheck installcheck-am \ - installdirs installdirs-am installdirs-recursive \ - maintainer-clean maintainer-clean-generic \ - maintainer-clean-recursive mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-recursive pdf pdf-am \ - pdf-recursive ps ps-am ps-recursive tags tags-recursive \ - uninstall uninstall-am uninstall-binPROGRAMS \ - uninstall-binSCRIPTS uninstall-info-am uninstall-info-recursive \ - uninstall-recursive +maintainer-clean: maintainer-clean-recursive + -rm -f config.status + +.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \ +mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ +maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile uninstall-binSCRIPTS install-binSCRIPTS \ +install-data-recursive uninstall-data-recursive install-exec-recursive \ +uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \ +all-recursive check-recursive installcheck-recursive info-recursive \ +dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \ +maintainer-clean-recursive tags tags-recursive mostlyclean-tags \ +distclean-tags clean-tags maintainer-clean-tags distdir info-am info \ +dvi-am dvi check check-am installcheck-am installcheck all-recursive-am \ +install-exec-local install-exec-am install-exec install-data-local \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs-am installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean mutt_dotlock.c: dotlock.c @@ -881,7 +653,7 @@ install-data-local: Muttngrc elif [ ! -f $(DESTDIR)$(sysconfdir)/Muttngrc ] ; then \ $(INSTALL) -m 644 $(srcdir)/Muttngrc $(DESTDIR)$(sysconfdir) ; \ fi - -if [ ! -f $(DESTDIR)$(sysconfdir)/mime.types ]; then \ + -if [ ! -f $(DESTDIR)$(sysconfdir)/muttng-mime.types ]; then \ $(INSTALL) -m 644 $(srcdir)/mime.types $(DESTDIR)$(sysconfdir)/muttng-mime.types; \ fi @@ -931,6 +703,7 @@ stamp-doc-rc: $(srcdir)/init.h makedoc Muttngrc.head .PHONY: commit pclean check-security commit-real commit-changelog .PHONY: changelog ChangeLog + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/_regex.h b/_regex.h index 8e2bd8f..f112d73 100644 --- a/_regex.h +++ b/_regex.h @@ -41,15 +41,15 @@ extern "C" { wide enough to hold a value of a pointer. For most ANSI compilers ptrdiff_t and size_t should be likely OK. Still size of these two types is 2 for Microsoft C. Ugh... */ -typedef long int s_reg_t; -typedef unsigned long int active_reg_t; + typedef long int s_reg_t; + typedef unsigned long int active_reg_t; /* The following bits are used to determine the regexp syntax we recognize. The set/not-set meanings are chosen so that Emacs syntax remains the value 0. The bits are given in alphabetical order, and the definitions shifted by one from the previous bit; thus, when we add or remove a bit, only one other definition need change. */ -typedef unsigned long int reg_syntax_t; + typedef unsigned long int reg_syntax_t; /* If this bit is not set, then \ inside a bracket expression is literal. If set, then such a \ quotes the following character. */ @@ -164,7 +164,7 @@ typedef unsigned long int reg_syntax_t; some interfaces). When a regexp is compiled, the syntax used is stored in the pattern buffer, so changing this does not affect already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; + extern reg_syntax_t re_syntax_options; /* Define combinations of the above bits for the standard possibilities. (The [[[ comments delimit what gets put into the Texinfo file, so @@ -280,31 +280,30 @@ extern reg_syntax_t re_syntax_options; /* If any error codes are removed, changed, or added, update the `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; + typedef enum { + REG_NOERROR = 0, /* Success. */ + REG_NOMATCH, /* Didn't find a match (for regexec). */ + + /* POSIX regcomp return error codes. (In the order listed in the + standard.) */ + REG_BADPAT, /* Invalid pattern. */ + REG_ECOLLATE, /* Not implemented. */ + REG_ECTYPE, /* Invalid character class name. */ + REG_EESCAPE, /* Trailing backslash. */ + REG_ESUBREG, /* Invalid back reference. */ + REG_EBRACK, /* Unmatched left bracket. */ + REG_EPAREN, /* Parenthesis imbalance. */ + REG_EBRACE, /* Unmatched \{. */ + REG_BADBR, /* Invalid contents of \{\}. */ + REG_ERANGE, /* Invalid range end. */ + REG_ESPACE, /* Ran out of memory. */ + REG_BADRPT, /* No preceding re for repetition op. */ + + /* Error codes we've added. */ + REG_EEND, /* Premature end. */ + REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ + REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ + } reg_errcode_t; /* This data structure represents a compiled pattern. Before calling the pattern compiler, the fields `buffer', `allocated', `fastmap', @@ -316,88 +315,86 @@ typedef enum #define RE_TRANSLATE_TYPE char * #endif -struct re_pattern_buffer -{ + struct re_pattern_buffer { /* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long int allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long int used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - RE_TRANSLATE_TYPE translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ + /* Space that holds the compiled pattern. It is declared as + `unsigned char *' because its elements are + sometimes used as array indexes. */ + unsigned char *buffer; + + /* Number of bytes to which `buffer' points. */ + unsigned long int allocated; + + /* Number of bytes actually used in `buffer'. */ + unsigned long int used; + + /* Syntax setting with which the pattern was compiled. */ + reg_syntax_t syntax; + + /* Pointer to a fastmap, if any, otherwise zero. re_search uses + the fastmap, if there is one, to skip over impossible + starting points for matches. */ + char *fastmap; + + /* Either a translate table to apply to all characters before + comparing them, or zero for no translation. The translation + is applied to a pattern when it is compiled and to a string + when it is matched. */ + RE_TRANSLATE_TYPE translate; + + /* Number of subexpressions found by the compiler. */ + size_t re_nsub; + + /* Zero if this pattern cannot match the empty string, one else. + Well, in truth it's used only in `re_search_2', to see + whether or not we should use the fastmap, so we don't set + this absolutely perfectly; see `re_compile_fastmap' (the + `duplicate' case). */ + unsigned can_be_null:1; + + /* If REGS_UNALLOCATED, allocate space in the `regs' structure + for `max (RE_NREGS, re_nsub + 1)' groups. + If REGS_REALLOCATE, reallocate space if necessary. + If REGS_FIXED, use what's there. */ #define REGS_UNALLOCATED 0 #define REGS_REALLOCATE 1 #define REGS_FIXED 2 - unsigned regs_allocated : 2; + unsigned regs_allocated:2; - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; + /* Set to zero when `regex_compile' compiles a pattern; set to one + by `re_compile_fastmap' if it updates the fastmap. */ + unsigned fastmap_accurate:1; - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; + /* If set, `re_match_2' does not return information about + subexpressions. */ + unsigned no_sub:1; - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; + /* If set, a beginning-of-line anchor doesn't match at the + beginning of the string. */ + unsigned not_bol:1; - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; + /* Similarly for an end-of-line anchor. */ + unsigned not_eol:1; - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; + /* If true, an anchor at a newline matches. */ + unsigned newline_anchor:1; /* [[[end pattern_buffer]]] */ -}; + }; -typedef struct re_pattern_buffer regex_t; + typedef struct re_pattern_buffer regex_t; /* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; + typedef int regoff_t; /* This is the structure we store register match data in. See regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; + struct re_registers { + unsigned num_regs; + regoff_t *start; + regoff_t *end; + }; /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, @@ -411,11 +408,10 @@ struct re_registers /* POSIX specification for registers. Aside from the different names than `re_registers', POSIX uses an array of structures, instead of a structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; + typedef struct { + regoff_t rm_so; /* Byte offset from string's start to substring's start. */ + regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ + } regmatch_t; /* Declarations for routines. */ @@ -429,28 +425,29 @@ typedef struct #define _RE_ARGS(args) args -#else /* not __STDC__ */ +#else /* not __STDC__ */ #define _RE_ARGS(args) () -#endif /* not __STDC__ */ +#endif /* not __STDC__ */ /* Sets the current default syntax to SYNTAX, and return the old syntax. You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); + extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); /* Compile the regular expression PATTERN, with length LENGTH and syntax given by the global `re_syntax_options', into the buffer BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, size_t length, - struct re_pattern_buffer *buffer)); + extern const char *re_compile_pattern + _RE_ARGS ((const char *pattern, size_t length, + struct re_pattern_buffer * buffer)); /* Compile a fastmap for the compiled pattern in BUFFER; used to accelerate searches. Return 0 if successful and -2 if was an internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); + extern int re_compile_fastmap + _RE_ARGS ((struct re_pattern_buffer * buffer)); /* Search in the string STRING (with length LENGTH) for the pattern @@ -458,31 +455,31 @@ extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); characters. Return the starting position of the match, -1 for no match, or -2 for an internal error. Also return register information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); + extern int re_search + _RE_ARGS ((struct re_pattern_buffer * buffer, const char *string, + int length, int start, int range, struct re_registers * regs)); /* Like `re_search', but search in the concatenation of STRING1 and STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); + extern int re_search_2 + _RE_ARGS ((struct re_pattern_buffer * buffer, const char *string1, + int length1, const char *string2, int length2, + int start, int range, struct re_registers * regs, int stop)); /* Like `re_search', but return how many characters in STRING the regexp in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); + extern int re_match + _RE_ARGS ((struct re_pattern_buffer * buffer, const char *string, + int length, int start, struct re_registers * regs)); /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); + extern int re_match_2 + _RE_ARGS ((struct re_pattern_buffer * buffer, const char *string1, + int length1, const char *string2, int length2, + int start, struct re_registers * regs, int stop)); /* Set REGS to hold NUM_REGS registers, storing them in STARTS and @@ -497,36 +494,35 @@ extern int re_match_2 Unless this function is called, the first search or match using PATTERN_BUFFER will allocate its own register data, without freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); + extern void re_set_registers + _RE_ARGS ((struct re_pattern_buffer * buffer, struct re_registers * regs, + unsigned num_regs, regoff_t * starts, regoff_t * ends)); #ifdef _REGEX_RE_COMP #ifndef _CRAY /* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); + extern char *re_comp _RE_ARGS ((const char *)); + extern int re_exec _RE_ARGS ((const char *)); #endif #endif /* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); -extern int regexec - _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags)); -extern size_t regerror - _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size)); -extern void regfree _RE_ARGS ((regex_t *preg)); + extern int regcomp + _RE_ARGS ((regex_t * preg, const char *pattern, int cflags)); + extern int regexec + _RE_ARGS ((const regex_t * preg, const char *string, size_t nmatch, + regmatch_t pmatch[], int eflags)); + extern size_t regerror + _RE_ARGS ((int errcode, const regex_t * preg, char *errbuf, + size_t errbuf_size)); + extern void regfree _RE_ARGS ((regex_t * preg)); #ifdef __cplusplus } -#endif /* C++ */ - -#endif /* not __REGEXP_LIBRARY_H__ */ - -/* +#endif /* C++ */ +#endif /* not __REGEXP_LIBRARY_H__ */ + /* Local variables: make-backup-files: t version-control: t diff --git a/acconfig.h b/acconfig.h index 1e85d56..1107312 100644 --- a/acconfig.h +++ b/acconfig.h @@ -3,4 +3,3 @@ #undef USE_NNTP /* The compressed mailboxes support */ #undef USE_COMPRESSED - diff --git a/account.c b/account.c index 5b77531..a857829 100644 --- a/account.c +++ b/account.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* remote host account manipulation (POP/IMAP) */ @@ -27,9 +27,9 @@ #include "url.h" /* mutt_account_match: compare account info (host/port/user) */ -int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2) +int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * a2) { - const char* user = NONULL (Username); + const char *user = NONULL (Username); if (a1->type != a2->type) return 0; @@ -47,7 +47,7 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2) if (a1->type == M_ACCT_TYPE_POP && PopUser) user = PopUser; #endif - + #ifdef USE_NNTP if (a1->type == M_ACCT_TYPE_NNTP && NntpUser) user = NntpUser; @@ -64,7 +64,7 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2) } /* mutt_account_fromurl: fill account with information from url. */ -int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url) +int mutt_account_fromurl (ACCOUNT * account, ciss_url_t * url) { /* must be present */ if (url->host) @@ -72,18 +72,15 @@ int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url) else return -1; - if (url->user) - { + if (url->user) { strfcpy (account->user, url->user, sizeof (account->user)); account->flags |= M_ACCT_USER; } - if (url->pass) - { + if (url->pass) { strfcpy (account->pass, url->pass, sizeof (account->pass)); account->flags |= M_ACCT_PASS; } - if (url->port) - { + if (url->port) { account->port = url->port; account->flags |= M_ACCT_PORT; } @@ -95,7 +92,7 @@ int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url) * is a set of pointers into account - don't free or edit account until * you've finished with url (make a copy of account if you need it for * a while). */ -void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) +void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url) { url->scheme = U_UNKNOWN; url->user = NULL; @@ -103,8 +100,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) url->port = 0; #ifdef USE_IMAP - if (account->type == M_ACCT_TYPE_IMAP) - { + if (account->type == M_ACCT_TYPE_IMAP) { if (account->flags & M_ACCT_SSL) url->scheme = U_IMAPS; else @@ -113,8 +109,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) #endif #ifdef USE_POP - if (account->type == M_ACCT_TYPE_POP) - { + if (account->type == M_ACCT_TYPE_POP) { if (account->flags & M_ACCT_SSL) url->scheme = U_POPS; else @@ -123,8 +118,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) #endif #ifdef USE_NNTP - if (account->type == M_ACCT_TYPE_NNTP) - { + if (account->type == M_ACCT_TYPE_NNTP) { if (account->flags & M_ACCT_SSL) url->scheme = U_NNTPS; else @@ -142,7 +136,7 @@ void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) } /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */ -int mutt_account_getuser (ACCOUNT* account) +int mutt_account_getuser (ACCOUNT * account) { char prompt[SHORT_STRING]; @@ -162,8 +156,7 @@ int mutt_account_getuser (ACCOUNT* account) strfcpy (account->user, NntpUser, sizeof (account->user)); #endif /* prompt (defaults to unix username), copy into account->user */ - else - { + else { snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host); strfcpy (account->user, NONULL (Username), sizeof (account->user)); if (mutt_get_field (prompt, account->user, sizeof (account->user), 0)) @@ -176,7 +169,7 @@ int mutt_account_getuser (ACCOUNT* account) } /* mutt_account_getpass: fetch password into ACCOUNT, if neccessary */ -int mutt_account_getpass (ACCOUNT* account) +int mutt_account_getpass (ACCOUNT * account) { char prompt[SHORT_STRING]; @@ -194,10 +187,9 @@ int mutt_account_getpass (ACCOUNT* account) else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass) strfcpy (account->pass, NntpPass, sizeof (account->pass)); #endif - else - { + else { snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "), - account->user, account->host); + account->user, account->host); account->pass[0] = '\0'; if (mutt_get_password (prompt, account->pass, sizeof (account->pass))) return -1; @@ -208,7 +200,7 @@ int mutt_account_getpass (ACCOUNT* account) return 0; } -void mutt_account_unsetpass (ACCOUNT* account) +void mutt_account_unsetpass (ACCOUNT * account) { account->flags &= !M_ACCT_PASS; } diff --git a/account.h b/account.h index a2aa59e..d3c7a76 100644 --- a/account.h +++ b/account.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* remote host account manipulation (POP/IMAP) */ @@ -24,8 +24,7 @@ #include "url.h" /* account types */ -enum -{ +enum { M_ACCT_TYPE_NONE = 0, M_ACCT_TYPE_IMAP, M_ACCT_TYPE_NNTP, @@ -38,8 +37,7 @@ enum #define M_ACCT_PASS (1<<2) #define M_ACCT_SSL (1<<3) -typedef struct -{ +typedef struct { char user[64]; char pass[64]; char host[128]; @@ -48,11 +46,11 @@ typedef struct unsigned char flags; } ACCOUNT; -int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2); -int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url); -void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url); -int mutt_account_getuser (ACCOUNT* account); -int mutt_account_getpass (ACCOUNT* account); -void mutt_account_unsetpass (ACCOUNT* account); +int mutt_account_match (const ACCOUNT * a1, const ACCOUNT * m2); +int mutt_account_fromurl (ACCOUNT * account, ciss_url_t * url); +void mutt_account_tourl (ACCOUNT * account, ciss_url_t * url); +int mutt_account_getuser (ACCOUNT * account); +int mutt_account_getpass (ACCOUNT * account); +void mutt_account_unsetpass (ACCOUNT * account); #endif /* _MUTT_ACCOUNT_H_ */ diff --git a/aclocal.m4 b/aclocal.m4 index 3b6c48f..c54cad8 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,284 +1,914 @@ -# generated automatically by aclocal 1.7.6 -*- Autoconf -*- +dnl aclocal.m4 generated automatically by aclocal 1.4-p4 + +dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +# lib-prefix.m4 serial 3 (gettext-0.13) +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 -# Free Software Foundation, Inc. -# This file is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -# Like AC_CONFIG_HEADER, but automatically create stamp file. -*- Autoconf -*- - -# Copyright 1996, 1997, 2000, 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. +dnl From Bruno Haible. -AC_PREREQ([2.52]) +dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and +dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't +dnl require excessive bracketing. +ifdef([AC_HELP_STRING], +[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], +[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) + +dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed +dnl to access previously installed libraries. The basic assumption is that +dnl a user will want packages to use other packages he previously installed +dnl with the same --prefix option. +dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate +dnl libraries, but is otherwise very convenient. +AC_DEFUN([AC_LIB_PREFIX], +[ + AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_LIB_ARG_WITH([lib-prefix], +[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib + --without-lib-prefix don't search for libraries in includedir and libdir], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/lib" + fi + fi +]) + if test $use_additional = yes; then + dnl Potentially add $additional_includedir to $CPPFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's already present in $CPPFLAGS, + dnl 3. if it's /usr/local/include and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + for x in $CPPFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $CPPFLAGS. + CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" + fi + fi + fi + fi + dnl Potentially add $additional_libdir to $LDFLAGS. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's already present in $LDFLAGS, + dnl 3. if it's /usr/local/lib and we are using GCC on Linux, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/lib"; then + haveit= + for x in $LDFLAGS; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test "X$additional_libdir" = "X/usr/local/lib"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LDFLAGS. + LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" + fi + fi + fi + fi + fi +]) -# serial 6 +dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, +dnl acl_final_exec_prefix, containing the values to which $prefix and +dnl $exec_prefix will expand at the end of the configure script. +AC_DEFUN([AC_LIB_PREPARE_PREFIX], +[ + dnl Unfortunately, prefix and exec_prefix get only finally determined + dnl at the end of configure. + if test "X$prefix" = "XNONE"; then + acl_final_prefix="$ac_default_prefix" + else + acl_final_prefix="$prefix" + fi + if test "X$exec_prefix" = "XNONE"; then + acl_final_exec_prefix='${prefix}' + else + acl_final_exec_prefix="$exec_prefix" + fi + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" + prefix="$acl_save_prefix" +]) -# AM_CONFIG_HEADER is obsolete. It has been replaced by AC_CONFIG_HEADERS. -AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)]) +dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the +dnl variables prefix and exec_prefix bound to the values they will have +dnl at the end of the configure script. +AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], +[ + acl_save_prefix="$prefix" + prefix="$acl_final_prefix" + acl_save_exec_prefix="$exec_prefix" + exec_prefix="$acl_final_exec_prefix" + $1 + exec_prefix="$acl_save_exec_prefix" + prefix="$acl_save_prefix" +]) -# Do all the work for Automake. -*- Autoconf -*- +# lib-link.m4 serial 4 (gettext-0.12) +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. -# This macro actually does too much some checks are only needed if -# your package does certain things. But this isn't really a big deal. +dnl From Bruno Haible. -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 -# Free Software Foundation, Inc. +dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and +dnl the libraries corresponding to explicit and implicit dependencies. +dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and +dnl augments the CPPFLAGS variable. +AC_DEFUN([AC_LIB_LINKFLAGS], +[ + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + define([Name],[translit([$1],[./-], [___])]) + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ + AC_LIB_LINKFLAGS_BODY([$1], [$2]) + ac_cv_lib[]Name[]_libs="$LIB[]NAME" + ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME" + ac_cv_lib[]Name[]_cppflags="$INC[]NAME" + ]) + LIB[]NAME="$ac_cv_lib[]Name[]_libs" + LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs" + INC[]NAME="$ac_cv_lib[]Name[]_cppflags" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) + AC_SUBST([LIB]NAME) + AC_SUBST([LTLIB]NAME) + dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the + dnl results of this search when this library appears as a dependency. + HAVE_LIB[]NAME=yes + undefine([Name]) + undefine([NAME]) +]) -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. +dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode) +dnl searches for libname and the libraries corresponding to explicit and +dnl implicit dependencies, together with the specified include files and +dnl the ability to compile and link the specified testcode. If found, it +dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and +dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and +dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs +dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty. +AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], +[ + AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) + AC_REQUIRE([AC_LIB_RPATH]) + define([Name],[translit([$1],[./-], [___])]) + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + + dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME + dnl accordingly. + AC_LIB_LINKFLAGS_BODY([$1], [$2]) + + dnl Add $INC[]NAME to CPPFLAGS before performing the following checks, + dnl because if the user has installed lib[]Name and not disabled its use + dnl via --without-lib[]Name-prefix, he wants to use it. + ac_save_CPPFLAGS="$CPPFLAGS" + AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME) + + AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ + ac_save_LIBS="$LIBS" + LIBS="$LIBS $LIB[]NAME" + AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no]) + LIBS="$ac_save_LIBS" + ]) + if test "$ac_cv_lib[]Name" = yes; then + HAVE_LIB[]NAME=yes + AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.]) + AC_MSG_CHECKING([how to link with lib[]$1]) + AC_MSG_RESULT([$LIB[]NAME]) + else + HAVE_LIB[]NAME=no + dnl If $LIB[]NAME didn't lead to a usable library, we don't need + dnl $INC[]NAME either. + CPPFLAGS="$ac_save_CPPFLAGS" + LIB[]NAME= + LTLIB[]NAME= + fi + AC_SUBST([HAVE_LIB]NAME) + AC_SUBST([LIB]NAME) + AC_SUBST([LTLIB]NAME) + undefine([Name]) + undefine([NAME]) +]) -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +dnl Determine the platform dependent parameters needed to use rpath: +dnl libext, shlibext, hardcode_libdir_flag_spec, hardcode_libdir_separator, +dnl hardcode_direct, hardcode_minus_L. +AC_DEFUN([AC_LIB_RPATH], +[ + AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS + AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld + AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host + AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir + AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [ + CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \ + ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh + . ./conftest.sh + rm -f ./conftest.sh + acl_cv_rpath=done + ]) + wl="$acl_cv_wl" + libext="$acl_cv_libext" + shlibext="$acl_cv_shlibext" + hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec" + hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator" + hardcode_direct="$acl_cv_hardcode_direct" + hardcode_minus_L="$acl_cv_hardcode_minus_L" + dnl Determine whether the user wants rpath handling at all. + AC_ARG_ENABLE(rpath, + [ --disable-rpath do not hardcode runtime library paths], + :, enable_rpath=yes) +]) -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. +dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and +dnl the libraries corresponding to explicit and implicit dependencies. +dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables. +AC_DEFUN([AC_LIB_LINKFLAGS_BODY], +[ + define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], + [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) + dnl By default, look in $includedir and $libdir. + use_additional=yes + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + AC_LIB_ARG_WITH([lib$1-prefix], +[ --with-lib$1-prefix[=DIR] search for lib$1 in DIR/include and DIR/lib + --without-lib$1-prefix don't search for lib$1 in includedir and libdir], +[ + if test "X$withval" = "Xno"; then + use_additional=no + else + if test "X$withval" = "X"; then + AC_LIB_WITH_FINAL_PREFIX([ + eval additional_includedir=\"$includedir\" + eval additional_libdir=\"$libdir\" + ]) + else + additional_includedir="$withval/include" + additional_libdir="$withval/lib" + fi + fi +]) + dnl Search the library and its dependencies in $additional_libdir and + dnl $LDFLAGS. Using breadth-first-seach. + LIB[]NAME= + LTLIB[]NAME= + INC[]NAME= + rpathdirs= + ltrpathdirs= + names_already_handled= + names_next_round='$1 $2' + while test -n "$names_next_round"; do + names_this_round="$names_next_round" + names_next_round= + for name in $names_this_round; do + already_handled= + for n in $names_already_handled; do + if test "$n" = "$name"; then + already_handled=yes + break + fi + done + if test -z "$already_handled"; then + names_already_handled="$names_already_handled $name" + dnl See if it was already located by an earlier AC_LIB_LINKFLAGS + dnl or AC_LIB_HAVE_LINKFLAGS call. + uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` + eval value=\"\$HAVE_LIB$uppername\" + if test -n "$value"; then + if test "$value" = yes; then + eval value=\"\$LIB$uppername\" + test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value" + eval value=\"\$LTLIB$uppername\" + test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value" + else + dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined + dnl that this library doesn't exist. So just drop it. + : + fi + else + dnl Search the library lib$name in $additional_libdir and $LDFLAGS + dnl and the already constructed $LIBNAME/$LTLIBNAME. + found_dir= + found_la= + found_so= + found_a= + if test $use_additional = yes; then + if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then + found_dir="$additional_libdir" + found_so="$additional_libdir/lib$name.$shlibext" + if test -f "$additional_libdir/lib$name.la"; then + found_la="$additional_libdir/lib$name.la" + fi + else + if test -f "$additional_libdir/lib$name.$libext"; then + found_dir="$additional_libdir" + found_a="$additional_libdir/lib$name.$libext" + if test -f "$additional_libdir/lib$name.la"; then + found_la="$additional_libdir/lib$name.la" + fi + fi + fi + fi + if test "X$found_dir" = "X"; then + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + case "$x" in + -L*) + dir=`echo "X$x" | sed -e 's/^X-L//'` + if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then + found_dir="$dir" + found_so="$dir/lib$name.$shlibext" + if test -f "$dir/lib$name.la"; then + found_la="$dir/lib$name.la" + fi + else + if test -f "$dir/lib$name.$libext"; then + found_dir="$dir" + found_a="$dir/lib$name.$libext" + if test -f "$dir/lib$name.la"; then + found_la="$dir/lib$name.la" + fi + fi + fi + ;; + esac + if test "X$found_dir" != "X"; then + break + fi + done + fi + if test "X$found_dir" != "X"; then + dnl Found the library. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name" + if test "X$found_so" != "X"; then + dnl Linking with a shared library. We attempt to hardcode its + dnl directory into the executable's runpath, unless it's the + dnl standard /usr/lib. + if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/lib"; then + dnl No hardcoding is needed. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $found_dir" + fi + dnl The hardcoding into $LIBNAME is system dependent. + if test "$hardcode_direct" = yes; then + dnl Using DIR/libNAME.so during linking hardcodes DIR into the + dnl resulting binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + if test -n "$hardcode_libdir_flag_spec" && test "$hardcode_minus_L" = no; then + dnl Use an explicit option to hardcode DIR into the resulting + dnl binary. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $found_dir" + fi + else + dnl Rely on "-L$found_dir". + dnl But don't add it if it's already contained in the LDFLAGS + dnl or the already constructed $LIBNAME + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$found_dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir" + fi + if test "$hardcode_minus_L" != no; then + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" + else + dnl We cannot use $hardcode_runpath_var and LD_RUN_PATH + dnl here, because this doesn't fit in flags passed to the + dnl compiler. So give up. No hardcoding. This affects only + dnl very old systems. + dnl FIXME: Not sure whether we should use + dnl "-L$found_dir -l$name" or "-L$found_dir $found_so" + dnl here. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + fi + fi + fi + fi + else + if test "X$found_a" != "X"; then + dnl Linking with a static library. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a" + else + dnl We shouldn't come here, but anyway it's good to have a + dnl fallback. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name" + fi + fi + dnl Assume the include files are nearby. + additional_includedir= + case "$found_dir" in + */lib | */lib/) + basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e 's,/lib/*$,,'` + additional_includedir="$basedir/include" + ;; + esac + if test "X$additional_includedir" != "X"; then + dnl Potentially add $additional_includedir to $INCNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/include, + dnl 2. if it's /usr/local/include and we are using GCC on Linux, + dnl 3. if it's already present in $CPPFLAGS or the already + dnl constructed $INCNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_includedir" != "X/usr/include"; then + haveit= + if test "X$additional_includedir" = "X/usr/local/include"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + for x in $CPPFLAGS $INC[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-I$additional_includedir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_includedir"; then + dnl Really add $additional_includedir to $INCNAME. + INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir" + fi + fi + fi + fi + fi + dnl Look for dependencies. + if test -n "$found_la"; then + dnl Read the .la file. It defines the variables + dnl dlname, library_names, old_library, dependency_libs, current, + dnl age, revision, installed, dlopen, dlpreopen, libdir. + save_libdir="$libdir" + case "$found_la" in + */* | *\\*) . "$found_la" ;; + *) . "./$found_la" ;; + esac + libdir="$save_libdir" + dnl We use only dependency_libs. + for dep in $dependency_libs; do + case "$dep" in + -L*) + additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` + dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. + dnl But don't add it + dnl 1. if it's the standard /usr/lib, + dnl 2. if it's /usr/local/lib and we are using GCC on Linux, + dnl 3. if it's already present in $LDFLAGS or the already + dnl constructed $LIBNAME, + dnl 4. if it doesn't exist as a directory. + if test "X$additional_libdir" != "X/usr/lib"; then + haveit= + if test "X$additional_libdir" = "X/usr/local/lib"; then + if test -n "$GCC"; then + case $host_os in + linux*) haveit=yes;; + esac + fi + fi + if test -z "$haveit"; then + haveit= + for x in $LDFLAGS $LIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LIBNAME. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" + fi + fi + haveit= + for x in $LDFLAGS $LTLIB[]NAME; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X-L$additional_libdir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + if test -d "$additional_libdir"; then + dnl Really add $additional_libdir to $LTLIBNAME. + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" + fi + fi + fi + fi + ;; + -R*) + dir=`echo "X$dep" | sed -e 's/^X-R//'` + if test "$enable_rpath" != no; then + dnl Potentially add DIR to rpathdirs. + dnl The rpathdirs will be appended to $LIBNAME at the end. + haveit= + for x in $rpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + rpathdirs="$rpathdirs $dir" + fi + dnl Potentially add DIR to ltrpathdirs. + dnl The ltrpathdirs will be appended to $LTLIBNAME at the end. + haveit= + for x in $ltrpathdirs; do + if test "X$x" = "X$dir"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + ltrpathdirs="$ltrpathdirs $dir" + fi + fi + ;; + -l*) + dnl Handle this in the next round. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` + ;; + *.la) + dnl Handle this in the next round. Throw away the .la's + dnl directory; it is already contained in a preceding -L + dnl option. + names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'` + ;; + *) + dnl Most likely an immediate library name. + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep" + ;; + esac + done + fi + else + dnl Didn't find the library; assume it is in the system directories + dnl known to the linker and runtime loader. (All the system + dnl directories known to the linker should also be known to the + dnl runtime loader, otherwise the system is severely misconfigured.) + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name" + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name" + fi + fi + fi + done + done + if test "X$rpathdirs" != "X"; then + if test -n "$hardcode_libdir_separator"; then + dnl Weird platform: only the last -rpath option counts, the user must + dnl pass all path elements in one option. We can arrange that for a + dnl single library, but not when more than one $LIBNAMEs are used. + alldirs= + for found_dir in $rpathdirs; do + alldirs="${alldirs}${alldirs:+$hardcode_libdir_separator}$found_dir" + done + dnl Note: hardcode_libdir_flag_spec uses $libdir and $wl. + acl_save_libdir="$libdir" + libdir="$alldirs" + eval flag=\"$hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + else + dnl The -rpath options are cumulative. + for found_dir in $rpathdirs; do + acl_save_libdir="$libdir" + libdir="$found_dir" + eval flag=\"$hardcode_libdir_flag_spec\" + libdir="$acl_save_libdir" + LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag" + done + fi + fi + if test "X$ltrpathdirs" != "X"; then + dnl When using libtool, the option that works for both libraries and + dnl executables is -R. The -R options are cumulative. + for found_dir in $ltrpathdirs; do + LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" + done + fi +]) -# serial 10 +dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR, +dnl unless already present in VAR. +dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes +dnl contains two or three consecutive elements that belong together. +AC_DEFUN([AC_LIB_APPENDTOVAR], +[ + for element in [$2]; do + haveit= + for x in $[$1]; do + AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) + if test "X$x" = "X$element"; then + haveit=yes + break + fi + done + if test -z "$haveit"; then + [$1]="${[$1]}${[$1]:+ }$element" + fi + done +]) -AC_PREREQ([2.54]) - -# Autoconf 2.50 wants to disallow AM_ names. We explicitly allow -# the ones we care about. -m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl - -# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) -# AM_INIT_AUTOMAKE([OPTIONS]) -# ----------------------------------------------- -# The call with PACKAGE and VERSION arguments is the old style -# call (pre autoconf-2.50), which is being phased out. PACKAGE -# and VERSION should now be passed to AC_INIT and removed from -# the call to AM_INIT_AUTOMAKE. -# We support both call styles for the transition. After -# the next Automake release, Autoconf can make the AC_INIT -# arguments mandatory, and then we can depend on a new Autoconf -# release and drop the old call support. -AC_DEFUN([AM_INIT_AUTOMAKE], -[AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl - AC_REQUIRE([AC_PROG_INSTALL])dnl -# test to see if srcdir already configured -if test "`cd $srcdir && pwd`" != "`pwd`" && - test -f $srcdir/config.status; then - AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) -fi +# lib-ld.m4 serial 3 (gettext-0.13) +dnl Copyright (C) 1996-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl Subroutines of libtool.m4, +dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision +dnl with libtool.m4. + +dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no. +AC_DEFUN([AC_LIB_PROG_LD_GNU], +[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld, +[# I'd rather use --version here, but apparently some GNU ld's only accept -v. +case `$LD -v 2>&1 /dev/null 2>/dev/null; then - CYGPATH_W='cygpath -w' +dnl From libtool-1.4. Sets the variable LD. +AC_DEFUN([AC_LIB_PROG_LD], +[AC_ARG_WITH(gnu-ld, +[ --with-gnu-ld assume the C compiler uses GNU ld [default=no]], +test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no) +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +# Prepare PATH_SEPARATOR. +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' else - CYGPATH_W=echo + PATH_SEPARATOR=: fi + rm -f conf$$.sh fi -AC_SUBST([CYGPATH_W]) - -# Define the identity of the package. -dnl Distinguish between old-style and new-style calls. -m4_ifval([$2], -[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl - AC_SUBST([PACKAGE], [$1])dnl - AC_SUBST([VERSION], [$2])], -[_AM_SET_OPTIONS([$1])dnl - AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl - AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl - -_AM_IF_OPTION([no-define],, -[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) - AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl - -# Some tools Automake needs. -AC_REQUIRE([AM_SANITY_CHECK])dnl -AC_REQUIRE([AC_ARG_PROGRAM])dnl -AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) -AM_MISSING_PROG(AUTOCONF, autoconf) -AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) -AM_MISSING_PROG(AUTOHEADER, autoheader) -AM_MISSING_PROG(MAKEINFO, makeinfo) -AM_MISSING_PROG(AMTAR, tar) -AM_PROG_INSTALL_SH -AM_PROG_INSTALL_STRIP -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. -AC_REQUIRE([AC_PROG_AWK])dnl -AC_REQUIRE([AC_PROG_MAKE_SET])dnl -AC_REQUIRE([AM_SET_LEADING_DOT])dnl - -_AM_IF_OPTION([no-dependencies],, -[AC_PROVIDE_IFELSE([AC_PROG_CC], - [_AM_DEPENDENCIES(CC)], - [define([AC_PROG_CC], - defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl -AC_PROVIDE_IFELSE([AC_PROG_CXX], - [_AM_DEPENDENCIES(CXX)], - [define([AC_PROG_CXX], - defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl -]) +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by GCC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]* | [A-Za-z]:[\\/]*)] + [re_direlt='/[^/][^/]*/\.\./'] + # Canonicalize the path of ld + ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(acl_cv_path_LD, +[if test -z "$LD"; then + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" + for ac_dir in $PATH; do + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + acl_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some GNU ld's only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in + *GNU* | *'with BFD'*) + test "$with_gnu_ld" != no && break ;; + *) + test "$with_gnu_ld" != yes && break ;; + esac + fi + done + IFS="$ac_save_ifs" +else + acl_cv_path_LD="$LD" # Let the user override the test with a path. +fi]) +LD="$acl_cv_path_LD" +if test -n "$LD"; then + AC_MSG_RESULT($LD) +else + AC_MSG_RESULT(no) +fi +test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) +AC_LIB_PROG_LD_GNU ]) - -# When config.status generates a header, we must update the stamp-h file. -# This file resides in the same directory as the config header -# that is generated. The stamp files are numbered to have different names. - -# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the -# loop where config.status creates the headers, so we can generate -# our stamp files there. -AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], -[# Compute $1's index in $config_headers. -_am_stamp_count=1 -for _am_header in $config_headers :; do - case $_am_header in - $1 | $1:* ) - break ;; - * ) - _am_stamp_count=`expr $_am_stamp_count + 1` ;; +# Like AC_CONFIG_HEADER, but automatically create stamp file. + +AC_DEFUN(AM_CONFIG_HEADER, +[AC_PREREQ([2.12]) +AC_CONFIG_HEADER([$1]) +dnl When config.status generates a header, we must update the stamp-h file. +dnl This file resides in the same directory as the config header +dnl that is generated. We must strip everything past the first ":", +dnl and everything past the last "/". +AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl +ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>, +<>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>, +<>; do + case " <<$>>CONFIG_HEADERS " in + *" <<$>>am_file "*<<)>> + echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx + ;; esac -done -echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count]) - -# Copyright 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + am_indx=`expr "<<$>>am_indx" + 1` +done<<>>dnl>>) +changequote([,]))]) -# AM_AUTOMAKE_VERSION(VERSION) -# ---------------------------- -# Automake X.Y traces this macro to ensure aclocal.m4 has been -# generated from the m4 files accompanying Automake X.Y. -AC_DEFUN([AM_AUTOMAKE_VERSION],[am__api_version="1.7"]) +# Do all the work for Automake. This macro actually does too much -- +# some checks are only needed if your package does certain things. +# But this isn't really a big deal. -# AM_SET_CURRENT_AUTOMAKE_VERSION -# ------------------------------- -# Call AM_AUTOMAKE_VERSION so it can be traced. -# This function is AC_REQUIREd by AC_INIT_AUTOMAKE. -AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], - [AM_AUTOMAKE_VERSION([1.7.6])]) - -# Helper functions for option handling. -*- Autoconf -*- - -# Copyright 2001, 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 2 +# serial 1 -# _AM_MANGLE_OPTION(NAME) -# ----------------------- -AC_DEFUN([_AM_MANGLE_OPTION], -[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) - -# _AM_SET_OPTION(NAME) -# ------------------------------ -# Set option NAME. Presently that only means defining a flag for this option. -AC_DEFUN([_AM_SET_OPTION], -[m4_define(_AM_MANGLE_OPTION([$1]), 1)]) - -# _AM_SET_OPTIONS(OPTIONS) -# ---------------------------------- -# OPTIONS is a space-separated list of Automake options. -AC_DEFUN([_AM_SET_OPTIONS], -[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) - -# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) -# ------------------------------------------- -# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. -AC_DEFUN([_AM_IF_OPTION], -[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) +dnl Usage: +dnl AM_INIT_AUTOMAKE(package,version, [no-define]) + +AC_DEFUN(AM_INIT_AUTOMAKE, +[AC_REQUIRE([AC_PROG_INSTALL]) +PACKAGE=[$1] +AC_SUBST(PACKAGE) +VERSION=[$2] +AC_SUBST(VERSION) +dnl test to see if srcdir already configured +if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) +fi +ifelse([$3],, +AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) +AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])) +AC_REQUIRE([AM_SANITY_CHECK]) +AC_REQUIRE([AC_ARG_PROGRAM]) +dnl FIXME This is truly gross. +missing_dir=`cd $ac_aux_dir && pwd` +AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir) +AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir) +AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir) +AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir) +AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir) +AC_REQUIRE([AC_PROG_MAKE_SET])]) # # Check to make sure that the build environment is sane. # -# Copyright 1996, 1997, 2000, 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 3 - -# AM_SANITY_CHECK -# --------------- -AC_DEFUN([AM_SANITY_CHECK], +AC_DEFUN(AM_SANITY_CHECK, [AC_MSG_CHECKING([whether build environment is sane]) # Just in case sleep 1 -echo timestamp > conftest.file +echo timestamp > conftestfile # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( - set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null` - if test "$[*]" = "X"; then + set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null` + if test "[$]*" = "X"; then # -L didn't work. - set X `ls -t $srcdir/configure conftest.file` + set X `ls -t $srcdir/configure conftestfile` fi - rm -f conftest.file - if test "$[*]" != "X $srcdir/configure conftest.file" \ - && test "$[*]" != "X conftest.file $srcdir/configure"; then + if test "[$]*" != "X $srcdir/configure conftestfile" \ + && test "[$]*" != "X conftestfile $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a @@ -288,7 +918,7 @@ if ( alias in your environment]) fi - test "$[2]" = conftest.file + test "[$]2" = conftestfile ) then # Ok. @@ -297,569 +927,35 @@ else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi +rm -f conftest* AC_MSG_RESULT(yes)]) -# -*- Autoconf -*- - - -# Copyright 1997, 1999, 2000, 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 3 - -# AM_MISSING_PROG(NAME, PROGRAM) -# ------------------------------ -AC_DEFUN([AM_MISSING_PROG], -[AC_REQUIRE([AM_MISSING_HAS_RUN]) -$1=${$1-"${am_missing_run}$2"} -AC_SUBST($1)]) - - -# AM_MISSING_HAS_RUN -# ------------------ -# Define MISSING if not defined so far and test if it supports --run. -# If it does, set am_missing_run to use it, otherwise, to nothing. -AC_DEFUN([AM_MISSING_HAS_RUN], -[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing" -# Use eval to expand $SHELL -if eval "$MISSING --run true"; then - am_missing_run="$MISSING --run " -else - am_missing_run= - AC_MSG_WARN([`missing' script is too old or missing]) -fi -]) - -# AM_AUX_DIR_EXPAND - -# Copyright 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets -# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to -# `$srcdir', `$srcdir/..', or `$srcdir/../..'. -# -# Of course, Automake must honor this variable whenever it calls a -# tool from the auxiliary directory. The problem is that $srcdir (and -# therefore $ac_aux_dir as well) can be either absolute or relative, -# depending on how configure is run. This is pretty annoying, since -# it makes $ac_aux_dir quite unusable in subdirectories: in the top -# source directory, any form will work fine, but in subdirectories a -# relative path needs to be adjusted first. -# -# $ac_aux_dir/missing -# fails when called from a subdirectory if $ac_aux_dir is relative -# $top_srcdir/$ac_aux_dir/missing -# fails if $ac_aux_dir is absolute, -# fails when called from a subdirectory in a VPATH build with -# a relative $ac_aux_dir -# -# The reason of the latter failure is that $top_srcdir and $ac_aux_dir -# are both prefixed by $srcdir. In an in-source build this is usually -# harmless because $srcdir is `.', but things will broke when you -# start a VPATH build or use an absolute $srcdir. -# -# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, -# iff we strip the leading $srcdir from $ac_aux_dir. That would be: -# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` -# and then we would define $MISSING as -# MISSING="\${SHELL} $am_aux_dir/missing" -# This will work as long as MISSING is not called from configure, because -# unfortunately $(top_srcdir) has no meaning in configure. -# However there are other variables, like CC, which are often used in -# configure, and could therefore not use this "fixed" $ac_aux_dir. -# -# Another solution, used here, is to always expand $ac_aux_dir to an -# absolute PATH. The drawback is that using absolute paths prevent a -# configured tree to be moved without reconfiguration. - -# Rely on autoconf to set up CDPATH properly. -AC_PREREQ([2.50]) - -AC_DEFUN([AM_AUX_DIR_EXPAND], [ -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` -]) - -# AM_PROG_INSTALL_SH -# ------------------ -# Define $install_sh. - -# Copyright 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -AC_DEFUN([AM_PROG_INSTALL_SH], -[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -install_sh=${install_sh-"$am_aux_dir/install-sh"} -AC_SUBST(install_sh)]) - -# AM_PROG_INSTALL_STRIP - -# Copyright 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# One issue with vendor `install' (even GNU) is that you can't -# specify the program used to strip binaries. This is especially -# annoying in cross-compiling environments, where the build's strip -# is unlikely to handle the host's binaries. -# Fortunately install-sh will honor a STRIPPROG variable, so we -# always use install-sh in `make install-strip', and initialize -# STRIPPROG with the value of the STRIP variable (set by the user). -AC_DEFUN([AM_PROG_INSTALL_STRIP], -[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl -# Installed binaries are usually stripped using `strip' when the user -# run `make install-strip'. However `strip' might not be the right -# tool to use in cross-compilation environments, therefore Automake -# will honor the `STRIP' environment variable to overrule this program. -dnl Don't test for $cross_compiling = yes, because it might be `maybe'. -if test "$cross_compiling" != no; then - AC_CHECK_TOOL([STRIP], [strip], :) -fi -INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s" -AC_SUBST([INSTALL_STRIP_PROGRAM])]) - -# -*- Autoconf -*- -# Copyright (C) 2003 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 1 - -# Check whether the underlying file-system supports filenames -# with a leading dot. For instance MS-DOS doesn't. -AC_DEFUN([AM_SET_LEADING_DOT], -[rm -rf .tst 2>/dev/null -mkdir .tst 2>/dev/null -if test -d .tst; then - am__leading_dot=. -else - am__leading_dot=_ -fi -rmdir .tst 2>/dev/null -AC_SUBST([am__leading_dot])]) - -# serial 5 -*- Autoconf -*- - -# Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - - -# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be -# written in clear, in which case automake, when reading aclocal.m4, -# will think it sees a *use*, and therefore will trigger all it's -# C support machinery. Also note that it means that autoscan, seeing -# CC etc. in the Makefile, will ask for an AC_PROG_CC use... - - - -# _AM_DEPENDENCIES(NAME) -# ---------------------- -# See how the compiler implements dependency checking. -# NAME is "CC", "CXX", "GCJ", or "OBJC". -# We try a few techniques and use that to set a single cache variable. -# -# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was -# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular -# dependency, and given that the user is not expected to run this macro, -# just rely on AC_PROG_CC. -AC_DEFUN([_AM_DEPENDENCIES], -[AC_REQUIRE([AM_SET_DEPDIR])dnl -AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl -AC_REQUIRE([AM_MAKE_INCLUDE])dnl -AC_REQUIRE([AM_DEP_TRACK])dnl - -ifelse([$1], CC, [depcc="$CC" am_compiler_list=], - [$1], CXX, [depcc="$CXX" am_compiler_list=], - [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], - [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], - [depcc="$$1" am_compiler_list=]) - -AC_CACHE_CHECK([dependency style of $depcc], - [am_cv_$1_dependencies_compiler_type], -[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then - # We make a subdir and do the tests there. Otherwise we can end up - # making bogus files that we don't know about and never remove. For - # instance it was reported that on HP-UX the gcc test will end up - # making a dummy file named `D' -- because `-MD' means `put the output - # in D'. - mkdir conftest.dir - # Copy depcomp to subdir because otherwise we won't find it if we're - # using a relative directory. - cp "$am_depcomp" conftest.dir - cd conftest.dir - # We will build objects and dependencies in a subdirectory because - # it helps to detect inapplicable dependency modes. For instance - # both Tru64's cc and ICC support -MD to output dependencies as a - # side effect of compilation, but ICC will put the dependencies in - # the current directory while Tru64 will put them in the object - # directory. - mkdir sub - - am_cv_$1_dependencies_compiler_type=none - if test "$am_compiler_list" = ""; then - am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` - fi - for depmode in $am_compiler_list; do - # Setup a source with many dependencies, because some compilers - # like to wrap large dependency lists on column 80 (with \), and - # we should not choose a depcomp mode which is confused by this. - # - # We need to recreate these files for each test, as the compiler may - # overwrite some of them when testing with obscure command lines. - # This happens at least with the AIX C compiler. - : > sub/conftest.c - for i in 1 2 3 4 5 6; do - echo '#include "conftst'$i'.h"' >> sub/conftest.c - : > sub/conftst$i.h - done - echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf - - case $depmode in - nosideeffect) - # after this tag, mechanisms are not by side-effect, so they'll - # only be used when explicitly requested - if test "x$enable_dependency_tracking" = xyes; then - continue - else - break - fi - ;; - none) break ;; - esac - # We check with `-c' and `-o' for the sake of the "dashmstdout" - # mode. It turns out that the SunPro C++ compiler does not properly - # handle `-M -o', and we need to detect this. - if depmode=$depmode \ - source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \ - depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ - $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \ - >/dev/null 2>conftest.err && - grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && - grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 && - ${MAKE-make} -s -f confmf > /dev/null 2>&1; then - # icc doesn't choke on unknown options, it will just issue warnings - # (even with -Werror). So we grep stderr for any message - # that says an option was ignored. - if grep 'ignoring option' conftest.err >/dev/null 2>&1; then :; else - am_cv_$1_dependencies_compiler_type=$depmode - break - fi - fi - done - - cd .. - rm -rf conftest.dir +dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY) +dnl The program must properly implement --version. +AC_DEFUN(AM_MISSING_PROG, +[AC_MSG_CHECKING(for working $2) +# Run test in a subshell; some versions of sh will print an error if +# an executable is not found, even if stderr is redirected. +# Redirect stdin to placate older versions of autoconf. Sigh. +if ($2 --version) < /dev/null > /dev/null 2>&1; then + $1=$2 + AC_MSG_RESULT(found) else - am_cv_$1_dependencies_compiler_type=none -fi -]) -AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) -AM_CONDITIONAL([am__fastdep$1], [ - test "x$enable_dependency_tracking" != xno \ - && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) -]) - - -# AM_SET_DEPDIR -# ------------- -# Choose a directory name for dependency files. -# This macro is AC_REQUIREd in _AM_DEPENDENCIES -AC_DEFUN([AM_SET_DEPDIR], -[AC_REQUIRE([AM_SET_LEADING_DOT])dnl -AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl -]) - - -# AM_DEP_TRACK -# ------------ -AC_DEFUN([AM_DEP_TRACK], -[AC_ARG_ENABLE(dependency-tracking, -[ --disable-dependency-tracking Speeds up one-time builds - --enable-dependency-tracking Do not reject slow dependency extractors]) -if test "x$enable_dependency_tracking" != xno; then - am_depcomp="$ac_aux_dir/depcomp" - AMDEPBACKSLASH='\' -fi -AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) -AC_SUBST([AMDEPBACKSLASH]) -]) - -# Generate code to set up dependency tracking. -*- Autoconf -*- - -# Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -#serial 2 - -# _AM_OUTPUT_DEPENDENCY_COMMANDS -# ------------------------------ -AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], -[for mf in $CONFIG_FILES; do - # Strip MF so we end up with the name of the file. - mf=`echo "$mf" | sed -e 's/:.*$//'` - # Check whether this is an Automake generated Makefile or not. - # We used to match only the files named `Makefile.in', but - # some people rename them; so instead we look at the file content. - # Grep'ing the first line is not enough: some people post-process - # each Makefile.in and add a new line on top of each file to say so. - # So let's grep whole file. - if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then - dirpart=`AS_DIRNAME("$mf")` - else - continue - fi - grep '^DEP_FILES *= *[[^ @%:@]]' < "$mf" > /dev/null || continue - # Extract the definition of DEP_FILES from the Makefile without - # running `make'. - DEPDIR=`sed -n -e '/^DEPDIR = / s///p' < "$mf"` - test -z "$DEPDIR" && continue - # When using ansi2knr, U may be empty or an underscore; expand it - U=`sed -n -e '/^U = / s///p' < "$mf"` - test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR" - # We invoke sed twice because it is the simplest approach to - # changing $(DEPDIR) to its actual value in the expansion. - for file in `sed -n -e ' - /^DEP_FILES = .*\\\\$/ { - s/^DEP_FILES = // - :loop - s/\\\\$// - p - n - /\\\\$/ b loop - p - } - /^DEP_FILES = / s/^DEP_FILES = //p' < "$mf" | \ - sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do - # Make sure the directory exists. - test -f "$dirpart/$file" && continue - fdir=`AS_DIRNAME(["$file"])` - AS_MKDIR_P([$dirpart/$fdir]) - # echo "creating $dirpart/$file" - echo '# dummy' > "$dirpart/$file" - done -done -])# _AM_OUTPUT_DEPENDENCY_COMMANDS - - -# AM_OUTPUT_DEPENDENCY_COMMANDS -# ----------------------------- -# This macro should only be invoked once -- use via AC_REQUIRE. -# -# This code is only required when automatic dependency tracking -# is enabled. FIXME. This creates each `.P' file that we will -# need in order to bootstrap the dependency handling code. -AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], -[AC_CONFIG_COMMANDS([depfiles], - [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], - [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) -]) - -# Check to see how 'make' treats includes. -*- Autoconf -*- - -# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 2 - -# AM_MAKE_INCLUDE() -# ----------------- -# Check to see how make treats includes. -AC_DEFUN([AM_MAKE_INCLUDE], -[am_make=${MAKE-make} -cat > confinc << 'END' -am__doit: - @echo done -.PHONY: am__doit -END -# If we don't find an include directive, just comment out the code. -AC_MSG_CHECKING([for style of include used by $am_make]) -am__include="#" -am__quote= -_am_result=none -# First try GNU make style include. -echo "include confinc" > confmf -# We grep out `Entering directory' and `Leaving directory' -# messages which can occur if `w' ends up in MAKEFLAGS. -# In particular we don't look at `^make:' because GNU make might -# be invoked under some other name (usually "gmake"), in which -# case it prints its new name instead of `make'. -if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then - am__include=include - am__quote= - _am_result=GNU + $1="$3/missing $2" + AC_MSG_RESULT(missing) fi -# Now try BSD make style include. -if test "$am__include" = "#"; then - echo '.include "confinc"' > confmf - if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then - am__include=.include - am__quote="\"" - _am_result=BSD - fi -fi -AC_SUBST([am__include]) -AC_SUBST([am__quote]) -AC_MSG_RESULT([$_am_result]) -rm -f confinc confmf -]) - -# AM_CONDITIONAL -*- Autoconf -*- - -# Copyright 1997, 2000, 2001 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 5 +AC_SUBST($1)]) -AC_PREREQ(2.52) +# isc-posix.m4 serial 2 (gettext-0.11.2) +dnl Copyright (C) 1995-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. -# AM_CONDITIONAL(NAME, SHELL-CONDITION) -# ------------------------------------- -# Define a conditional. -AC_DEFUN([AM_CONDITIONAL], -[ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], - [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl -AC_SUBST([$1_TRUE]) -AC_SUBST([$1_FALSE]) -if $2; then - $1_TRUE= - $1_FALSE='#' -else - $1_TRUE='#' - $1_FALSE= -fi -AC_CONFIG_COMMANDS_PRE( -[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then - AC_MSG_ERROR([conditional "$1" was never defined. -Usually this means the macro was only invoked conditionally.]) -fi])]) +# This file is not needed with autoconf-2.53 and newer. Remove it in 2005. -#serial 1 # This test replaces the one in autoconf. # Currently this macro should have the same name as the autoconf macro # because gettext's gettext.m4 (distributed in the automake package) @@ -878,26 +974,9 @@ AC_DEFUN([AC_ISC_POSIX], ) -# Copyright 1996, 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 2 +# serial 1 -AC_DEFUN([AM_C_PROTOTYPES], +AC_DEFUN(AM_C_PROTOTYPES, [AC_REQUIRE([AM_PROG_CC_STDC]) AC_REQUIRE([AC_PROG_CPP]) AC_MSG_CHECKING([for function prototypes]) @@ -908,35 +987,16 @@ if test "$am_cv_prog_cc_stdc" != no; then else AC_MSG_RESULT(no) U=_ ANSI2KNR=./ansi2knr + # Ensure some checks needed by ansi2knr itself. + AC_HEADER_STDC + AC_CHECK_HEADERS(string.h) fi -# Ensure some checks needed by ansi2knr itself. -AC_HEADER_STDC -AC_CHECK_HEADERS(string.h) AC_SUBST(U)dnl AC_SUBST(ANSI2KNR)dnl ]) -AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES]) - -# Copyright 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -# 02111-1307, USA. - -# serial 2 +# serial 1 # @defmac AC_PROG_CC_STDC # @maindex PROG_CC_STDC @@ -953,7 +1013,7 @@ AU_DEFUN([fp_C_PROTOTYPES], [AM_C_PROTOTYPES]) # program @code{ansi2knr}, which comes with Ghostscript. # @end defmac -AC_DEFUN([AM_PROG_CC_STDC], +AC_DEFUN(AM_PROG_CC_STDC, [AC_REQUIRE([AC_PROG_CC]) AC_BEFORE([$0], [AC_C_INLINE]) AC_BEFORE([$0], [AC_C_CONST]) @@ -963,7 +1023,7 @@ dnl like #elif. dnl FIXME: can't do this because then AC_AIX won't work due to a dnl circular dependency. dnl AC_BEFORE([$0], [AC_PROG_CPP]) -AC_MSG_CHECKING([for ${CC-cc} option to accept ANSI C]) +AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C) AC_CACHE_VAL(am_cv_prog_cc_stdc, [am_cv_prog_cc_stdc=no ac_save_CC="$CC" @@ -971,10 +1031,9 @@ ac_save_CC="$CC" # breaks some systems' header files. # AIX -qlanglvl=ansi # Ultrix and OSF/1 -std1 -# HP-UX 10.20 and later -Ae -# HP-UX older versions -Aa -D_HPUX_SOURCE +# HP-UX -Aa -D_HPUX_SOURCE # SVR4 -Xc -D__EXTENSIONS__ -for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" AC_TRY_COMPILE( @@ -1016,7 +1075,7 @@ CC="$ac_save_CC" if test -z "$am_cv_prog_cc_stdc"; then AC_MSG_RESULT([none needed]) else - AC_MSG_RESULT([$am_cv_prog_cc_stdc]) + AC_MSG_RESULT($am_cv_prog_cc_stdc) fi case "x$am_cv_prog_cc_stdc" in x|xno) ;; @@ -1024,8 +1083,6 @@ case "x$am_cv_prog_cc_stdc" in esac ]) -AU_DEFUN([fp_PROG_CC_STDC], [AM_PROG_CC_STDC]) - dnl types.m4 dnl macros for type checks not covered by autoconf @@ -1210,6 +1267,19 @@ changequote([,])dnl ])dnl dnl --------------------------------------------------------------------------- +# Define a conditional. + +AC_DEFUN(AM_CONDITIONAL, +[AC_SUBST($1_TRUE) +AC_SUBST($1_FALSE) +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi]) + # gssapi.m4: Find GSSAPI libraries in either Heimdal or MIT implementations # Brendan Cully 20010529 @@ -1880,12 +1950,18 @@ fi AC_SUBST($1)dnl ]) -#serial 2 +# glibc21.m4 serial 2 (fileutils-4.1.3, gettext-0.10.40) +dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. # Test for the GNU C Library, version 2.1 or newer. # From Bruno Haible. -AC_DEFUN([MUTT_jm_GLIBC21], +AC_DEFUN([jm_GLIBC21], [ AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, ac_cv_gnu_library_2_1, @@ -2020,6 +2096,33 @@ AC_DEFUN([MUTT_AM_LC_MESSAGES], fi fi]) +#serial 2 + +# Test for the GNU C Library, version 2.1 or newer. +# From Bruno Haible. + +AC_DEFUN([MUTT_jm_GLIBC21], + [ + AC_CACHE_CHECK(whether we are using the GNU C Library 2.1 or newer, + ac_cv_gnu_library_2_1, + [AC_EGREP_CPP([Lucky GNU user], + [ +#include +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2) + Lucky GNU user + #endif +#endif + ], + ac_cv_gnu_library_2_1=yes, + ac_cv_gnu_library_2_1=no) + ] + ) + AC_SUBST(GLIBC21) + GLIBC21="$ac_cv_gnu_library_2_1" + ] +) + dnl vim:ft=config: dnl Search for libesmtp, by Steven Engelhardt diff --git a/addrbook.c b/addrbook.c index 15f78a4..8be76f6 100644 --- a/addrbook.c +++ b/addrbook.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -34,62 +34,64 @@ #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x static struct mapping_t AliasHelp[] = { - { N_("Exit"), OP_EXIT }, - { N_("Del"), OP_DELETE }, - { N_("Undel"), OP_UNDELETE }, - { N_("Select"), OP_GENERIC_SELECT_ENTRY }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Exit"), OP_EXIT}, + {N_("Del"), OP_DELETE}, + {N_("Undel"), OP_UNDELETE}, + {N_("Select"), OP_GENERIC_SELECT_ENTRY}, + {N_("Help"), OP_HELP}, + {NULL} }; -static const char * -alias_format_str (char *dest, size_t destlen, char op, const char *src, - const char *fmt, const char *ifstring, const char *elsestring, - unsigned long data, format_flag flags) +static const char *alias_format_str (char *dest, size_t destlen, char op, + const char *src, const char *fmt, + const char *ifstring, + const char *elsestring, + unsigned long data, format_flag flags) { char tmp[SHORT_STRING], adr[SHORT_STRING]; ALIAS *alias = (ALIAS *) data; - switch (op) - { - case 'f': - snprintf (tmp, sizeof (tmp), "%%%ss", fmt); - snprintf (dest, destlen, tmp, alias->del ? "D" : " "); - break; - case 'a': - mutt_format_s (dest, destlen, fmt, alias->name); - break; - case 'r': - adr[0] = 0; - rfc822_write_address (adr, sizeof (adr), alias->addr, 1); - snprintf (tmp, sizeof (tmp), "%%%ss", fmt); - snprintf (dest, destlen, tmp, adr); - break; - case 'n': - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, alias->num + 1); - break; - case 't': - dest[0] = alias->tagged ? '*' : ' '; - dest[1] = 0; - break; + switch (op) { + case 'f': + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, alias->del ? "D" : " "); + break; + case 'a': + mutt_format_s (dest, destlen, fmt, alias->name); + break; + case 'r': + adr[0] = 0; + rfc822_write_address (adr, sizeof (adr), alias->addr, 1); + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, adr); + break; + case 'n': + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, alias->num + 1); + break; + case 't': + dest[0] = alias->tagged ? '*' : ' '; + dest[1] = 0; + break; } return (src); } -static void alias_entry (char *s, size_t slen, MUTTMENU *m, int num) +static void alias_entry (char *s, size_t slen, MUTTMENU * m, int num) { - mutt_FormatString (s, slen, NONULL (AliasFmt), alias_format_str, (unsigned long) ((ALIAS **) m->data)[num], M_FORMAT_ARROWCURSOR); + mutt_FormatString (s, slen, NONULL (AliasFmt), alias_format_str, + (unsigned long) ((ALIAS **) m->data)[num], + M_FORMAT_ARROWCURSOR); } -static int alias_tag (MUTTMENU *menu, int n, int m) +static int alias_tag (MUTTMENU * menu, int n, int m) { ALIAS *cur = ((ALIAS **) menu->data)[n]; int ot = cur->tagged; - + cur->tagged = (m >= 0 ? m : !cur->tagged); - + return cur->tagged - ot; } @@ -114,8 +116,7 @@ static int alias_SortAddress (const void *a, const void *b) r = -1; else if (pb == NULL) r = 1; - else if (pa->personal) - { + else if (pa->personal) { if (pb->personal) r = mutt_strcasecmp (pa->personal, pb->personal); else @@ -128,7 +129,7 @@ static int alias_SortAddress (const void *a, const void *b) return (RSORT (r)); } -void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases) +void mutt_alias_menu (char *buf, size_t buflen, ALIAS * aliases) { ALIAS *aliasp; MUTTMENU *menu; @@ -139,31 +140,31 @@ void mutt_alias_menu (char *buf, size_t buflen, ALIAS *aliases) char helpstr[SHORT_STRING]; int omax; - - if (!aliases) - { + + if (!aliases) { mutt_error _("You have no aliases!"); + return; } - + /* tell whoever called me to redraw the screen when I return */ set_option (OPTNEEDREDRAW); - + menu = mutt_new_menu (); menu->make_entry = alias_entry; menu->tag = alias_tag; menu->menu = MENU_ALIAS; menu->title = _("Aliases"); - menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, AliasHelp); + menu->help = + mutt_compile_help (helpstr, sizeof (helpstr), MENU_ALIAS, AliasHelp); new_aliases: omax = menu->max; - + /* count the number of aliases */ - for (aliasp = aliases; aliasp; aliasp = aliasp->next) - { - aliasp->self->del = 0; + for (aliasp = aliases; aliasp; aliasp = aliasp->next) { + aliasp->self->del = 0; aliasp->self->tagged = 0; menu->max++; } @@ -171,76 +172,67 @@ new_aliases: safe_realloc (&AliasTable, menu->max * sizeof (ALIAS *)); menu->data = AliasTable; - for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++) - { + for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++) { AliasTable[i] = aliasp->self; - aliases = aliasp; + aliases = aliasp; } - if ((SortAlias & SORT_MASK) != SORT_ORDER) - { + if ((SortAlias & SORT_MASK) != SORT_ORDER) { qsort (AliasTable, i, sizeof (ALIAS *), - (SortAlias & SORT_MASK) == SORT_ADDRESS ? alias_SortAddress : alias_SortAlias); + (SortAlias & SORT_MASK) == + SORT_ADDRESS ? alias_SortAddress : alias_SortAlias); } - for (i=0; imax; i++) AliasTable[i]->num = i; + for (i = 0; i < menu->max; i++) + AliasTable[i]->num = i; - while (!done) - { - if (aliases->next) - { + while (!done) { + if (aliases->next) { menu->redraw |= REDRAW_FULL; - aliases = aliases->next; + aliases = aliases->next; goto new_aliases; } - - switch ((op = mutt_menuLoop (menu))) - { - case OP_DELETE: - case OP_UNDELETE: - if (menu->tagprefix) - { - for (i = 0; i < menu->max; i++) - if (AliasTable[i]->tagged) - AliasTable[i]->del = (op == OP_DELETE) ? 1 : 0; - menu->redraw |= REDRAW_INDEX; - } - else - { - AliasTable[menu->current]->self->del = (op == OP_DELETE) ? 1 : 0; - menu->redraw |= REDRAW_CURRENT; - if (option (OPTRESOLVE) && menu->current < menu->max - 1) - { - menu->current++; - menu->redraw |= REDRAW_INDEX; - } - } - break; - case OP_GENERIC_SELECT_ENTRY: - t = menu->current; - case OP_EXIT: - done = 1; - break; + + switch ((op = mutt_menuLoop (menu))) { + case OP_DELETE: + case OP_UNDELETE: + if (menu->tagprefix) { + for (i = 0; i < menu->max; i++) + if (AliasTable[i]->tagged) + AliasTable[i]->del = (op == OP_DELETE) ? 1 : 0; + menu->redraw |= REDRAW_INDEX; + } + else { + AliasTable[menu->current]->self->del = (op == OP_DELETE) ? 1 : 0; + menu->redraw |= REDRAW_CURRENT; + if (option (OPTRESOLVE) && menu->current < menu->max - 1) { + menu->current++; + menu->redraw |= REDRAW_INDEX; + } + } + break; + case OP_GENERIC_SELECT_ENTRY: + t = menu->current; + case OP_EXIT: + done = 1; + break; } } - for (i = 0; i < menu->max; i++) - { - if (AliasTable[i]->tagged) - { + for (i = 0; i < menu->max; i++) { + if (AliasTable[i]->tagged) { mutt_addrlist_to_local (AliasTable[i]->addr); rfc822_write_address (buf, buflen, AliasTable[i]->addr, 0); t = -1; } } - if(t != -1) - { - mutt_addrlist_to_local (AliasTable[t]->addr); + if (t != -1) { + mutt_addrlist_to_local (AliasTable[t]->addr); rfc822_write_address (buf, buflen, AliasTable[t]->addr, 0); } mutt_menuDestroy (&menu); FREE (&AliasTable); - + } diff --git a/alias.c b/alias.c index 5d83357..e664784 100644 --- a/alias.c +++ b/alias.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -35,76 +35,71 @@ ADDRESS *mutt_lookup_alias (const char *s) for (; t; t = t->next) if (!mutt_strcasecmp (s, t->name)) return (t->addr); - return (NULL); /* no such alias */ + return (NULL); /* no such alias */ } -static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn) +static ADDRESS *mutt_expand_aliases_r (ADDRESS * a, LIST ** expn) { ADDRESS *head = NULL, *last = NULL, *t, *w; LIST *u; char i; const char *fqdn; - - while (a) - { - if (!a->group && !a->personal && a->mailbox && strchr (a->mailbox, '@') == NULL) - { + + while (a) { + if (!a->group && !a->personal && a->mailbox + && strchr (a->mailbox, '@') == NULL) { t = mutt_lookup_alias (a->mailbox); - if (t) - { + if (t) { i = 0; - for (u = *expn; u; u = u->next) - { - if (mutt_strcmp (a->mailbox, u->data) == 0) /* alias already found */ - { - dprint (1, (debugfile, "mutt_expand_aliases_r(): loop in alias found for '%s'\n", a->mailbox)); - i = 1; - break; - } - } - - if (!i) - { + for (u = *expn; u; u = u->next) { + if (mutt_strcmp (a->mailbox, u->data) == 0) { /* alias already found */ + dprint (1, + (debugfile, + "mutt_expand_aliases_r(): loop in alias found for '%s'\n", + a->mailbox)); + i = 1; + break; + } + } + + if (!i) { u = safe_malloc (sizeof (LIST)); u->data = safe_strdup (a->mailbox); u->next = *expn; *expn = u; - w = rfc822_cpy_adr (t); - w = mutt_expand_aliases_r (w, expn); - if (head) - last->next = w; - else - head = last = w; - while (last && last->next) - last = last->next; + w = rfc822_cpy_adr (t); + w = mutt_expand_aliases_r (w, expn); + if (head) + last->next = w; + else + head = last = w; + while (last && last->next) + last = last->next; } - t = a; - a = a->next; - t->next = NULL; - rfc822_free_address (&t); - continue; + t = a; + a = a->next; + t->next = NULL; + rfc822_free_address (&t); + continue; } - else - { - struct passwd *pw = getpwnam (a->mailbox); - - if (pw) - { - char namebuf[STRING]; - - mutt_gecos_name (namebuf, sizeof (namebuf), pw); - mutt_str_replace (&a->personal, namebuf); - + else { + struct passwd *pw = getpwnam (a->mailbox); + + if (pw) { + char namebuf[STRING]; + + mutt_gecos_name (namebuf, sizeof (namebuf), pw); + mutt_str_replace (&a->personal, namebuf); + #ifdef EXACT_ADDRESS - FREE (&a->val); + FREE (&a->val); #endif - } + } } } - if (head) - { + if (head) { last->next = a; last = last->next; } @@ -114,8 +109,7 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn) last->next = NULL; } - if (option (OPTUSEDOMAIN) && (fqdn = mutt_fqdn(1))) - { + if (option (OPTUSEDOMAIN) && (fqdn = mutt_fqdn (1))) { /* now qualify all local addresses */ rfc822_qualify (head, fqdn); } @@ -123,17 +117,17 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn) return (head); } -ADDRESS *mutt_expand_aliases (ADDRESS *a) +ADDRESS *mutt_expand_aliases (ADDRESS * a) { ADDRESS *t; - LIST *expn = NULL; /* previously expanded aliases to avoid loops */ + LIST *expn = NULL; /* previously expanded aliases to avoid loops */ t = mutt_expand_aliases_r (a, &expn); mutt_free_list (&expn); return (mutt_remove_duplicates (t)); } -void mutt_expand_aliases_env (ENVELOPE *env) +void mutt_expand_aliases_env (ENVELOPE * env) { env->from = mutt_expand_aliases (env->from); env->to = mutt_expand_aliases (env->to); @@ -165,53 +159,47 @@ void mutt_expand_aliases_env (ENVELOPE *env) * variable. */ -static void write_safe_address (FILE *fp, char *s) +static void write_safe_address (FILE * fp, char *s) { - while (*s) - { - if (*s == '\\' || *s == '`' || *s == '\'' || *s == '"' - || *s == '$') + while (*s) { + if (*s == '\\' || *s == '`' || *s == '\'' || *s == '"' || *s == '$') fputc ('\\', fp); fputc (*s, fp); s++; } } -ADDRESS *mutt_get_address (ENVELOPE *env, char **pfxp) +ADDRESS *mutt_get_address (ENVELOPE * env, char **pfxp) { ADDRESS *adr; char *pfx = NULL; - if (mutt_addr_is_user (env->from)) - { - if (env->to && !mutt_is_mail_list (env->to)) - { + if (mutt_addr_is_user (env->from)) { + if (env->to && !mutt_is_mail_list (env->to)) { pfx = "To"; adr = env->to; } - else - { + else { pfx = "Cc"; adr = env->cc; } } - else if (env->reply_to && !mutt_is_mail_list (env->reply_to)) - { + else if (env->reply_to && !mutt_is_mail_list (env->reply_to)) { pfx = "Reply-To"; adr = env->reply_to; } - else - { + else { adr = env->from; pfx = "From"; } - if (pfxp) *pfxp = pfx; + if (pfxp) + *pfxp = pfx; return adr; } -void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr) +void mutt_create_alias (ENVELOPE * cur, ADDRESS * iadr) { ALIAS *new, *t; char buf[LONG_STRING], prompt[SHORT_STRING], *pc; @@ -220,17 +208,14 @@ void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr) FILE *rc; ADDRESS *adr = NULL; - if (cur) - { + if (cur) { adr = mutt_get_address (cur, NULL); } - else if (iadr) - { + else if (iadr) { adr = iadr; } - if (adr && adr->mailbox) - { + if (adr && adr->mailbox) { strfcpy (buf, adr->mailbox, sizeof (buf)); if ((pc = strchr (buf, '@'))) *pc = 0; @@ -240,70 +225,65 @@ void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr) /* Don't suggest a bad alias name in the event of a strange local part. */ mutt_check_alias_name (buf, buf); - + retry_name: /* add a new alias */ if (mutt_get_field (_("Alias as: "), buf, sizeof (buf), 0) != 0 || !buf[0]) return; /* check to see if the user already has an alias defined */ - if (mutt_lookup_alias (buf)) - { + if (mutt_lookup_alias (buf)) { mutt_error _("You already have an alias defined with that name!"); + return; } - - if (mutt_check_alias_name (buf, fixed)) - { - switch (mutt_yesorno (_("Warning: This alias name may not work. Fix it?"), M_YES)) - { - case M_YES: - strfcpy (buf, fixed, sizeof (buf)); - goto retry_name; - case -1: - return; + + if (mutt_check_alias_name (buf, fixed)) { + switch (mutt_yesorno + (_("Warning: This alias name may not work. Fix it?"), M_YES)) { + case M_YES: + strfcpy (buf, fixed, sizeof (buf)); + goto retry_name; + case -1: + return; } } - - new = safe_calloc (1, sizeof (ALIAS)); + + new = safe_calloc (1, sizeof (ALIAS)); new->self = new; new->name = safe_strdup (buf); mutt_addrlist_to_local (adr); - + if (adr) strfcpy (buf, adr->mailbox, sizeof (buf)); else buf[0] = 0; mutt_addrlist_to_idna (adr, NULL); - - do - { - if (mutt_get_field (_("Address: "), buf, sizeof (buf), 0) != 0 || !buf[0]) - { + + do { + if (mutt_get_field (_("Address: "), buf, sizeof (buf), 0) != 0 || !buf[0]) { mutt_free_alias (&new); return; } - - if((new->addr = rfc822_parse_adrlist (new->addr, buf)) == NULL) + + if ((new->addr = rfc822_parse_adrlist (new->addr, buf)) == NULL) BEEP (); - if (mutt_addrlist_to_idna (new->addr, &err)) - { + if (mutt_addrlist_to_idna (new->addr, &err)) { mutt_error (_("Error: '%s' is a bad IDN."), err); mutt_sleep (2); continue; } } - while(new->addr == NULL); - + while (new->addr == NULL); + if (adr && adr->personal && !mutt_is_mail_list (adr)) strfcpy (buf, adr->personal, sizeof (buf)); else buf[0] = 0; - if (mutt_get_field (_("Personal name: "), buf, sizeof (buf), 0) != 0) - { + if (mutt_get_field (_("Personal name: "), buf, sizeof (buf), 0) != 0) { mutt_free_alias (&new); return; } @@ -312,14 +292,12 @@ retry_name: buf[0] = 0; rfc822_write_address (buf, sizeof (buf), new->addr, 1); snprintf (prompt, sizeof (prompt), _("[%s = %s] Accept?"), new->name, buf); - if (mutt_yesorno (prompt, M_YES) != M_YES) - { + if (mutt_yesorno (prompt, M_YES) != M_YES) { mutt_free_alias (&new); return; } - if ((t = Aliases)) - { + if ((t = Aliases)) { while (t->next) t = t->next; t->next = new; @@ -331,8 +309,7 @@ retry_name: if (mutt_get_field (_("Save to file: "), buf, sizeof (buf), M_FILE) != 0) return; mutt_expand_path (buf, sizeof (buf)); - if ((rc = safe_fopen (buf, "a"))) - { + if ((rc = safe_fopen (buf, "a"))) { if (mutt_check_alias_name (new->name, NULL)) mutt_quote_filename (buf, sizeof (buf), new->name); else @@ -357,22 +334,20 @@ retry_name: static int check_alias_name_char (char c) { return (c == '-' || c == '_' || c == '+' || c == '=' || c == '.' || - isalnum ((unsigned char) c)); + isalnum ((unsigned char) c)); } int mutt_check_alias_name (const char *s, char *d) { int rv = 0; - for (; *s; s++) - { - if (!check_alias_name_char (*s)) - { + + for (; *s; s++) { + if (!check_alias_name_char (*s)) { if (!d) - return -1; - else - { - *d++ = '_'; - rv = -1; + return -1; + else { + *d++ = '_'; + rv = -1; } } else if (d) @@ -387,7 +362,7 @@ int mutt_check_alias_name (const char *s, char *d) * This routine looks to see if the user has an alias defined for the given * address. */ -ADDRESS *alias_reverse_lookup (ADDRESS *a) +ADDRESS *alias_reverse_lookup (ADDRESS * a) { ALIAS *t = Aliases; ADDRESS *ap; @@ -395,14 +370,12 @@ ADDRESS *alias_reverse_lookup (ADDRESS *a) if (!a || !a->mailbox) return NULL; - for (; t; t = t->next) - { + for (; t; t = t->next) { /* cycle through all addresses if this is a group alias */ - for (ap = t->addr; ap; ap = ap->next) - { + for (ap = t->addr; ap; ap = ap->next) { if (!ap->group && ap->mailbox && - ascii_strcasecmp (ap->mailbox, a->mailbox) == 0) - return ap; + ascii_strcasecmp (ap->mailbox, a->mailbox) == 0) + return ap; } } return 0; @@ -423,66 +396,55 @@ int mutt_alias_complete (char *s, size_t buflen) #define min(a,b) ((aname && strstr (a->name, s) == a->name) - { - if (!bestname[0]) /* init */ - strfcpy (bestname, a->name, - min (mutt_strlen (a->name) + 1, sizeof (bestname))); - else - { - for (i = 0 ; a->name[i] && a->name[i] == bestname[i] ; i++) - ; - bestname[i] = 0; - } + while (a) { + if (a->name && strstr (a->name, s) == a->name) { + if (!bestname[0]) /* init */ + strfcpy (bestname, a->name, + min (mutt_strlen (a->name) + 1, sizeof (bestname))); + else { + for (i = 0; a->name[i] && a->name[i] == bestname[i]; i++); + bestname[i] = 0; + } } a = a->next; } - if (bestname[0] != 0) - { - if (mutt_strcmp (bestname, s) != 0) - { - /* we are adding something to the completion */ - strfcpy (s, bestname, mutt_strlen (bestname) + 1); - return 1; + if (bestname[0] != 0) { + if (mutt_strcmp (bestname, s) != 0) { + /* we are adding something to the completion */ + strfcpy (s, bestname, mutt_strlen (bestname) + 1); + return 1; } /* build alias list and show it */ a = Aliases; - while (a) - { - if (a->name && (strstr (a->name, s) == a->name)) - { - if (!a_list) /* init */ - a_cur = a_list = (ALIAS *) safe_malloc (sizeof (ALIAS)); - else - { - a_cur->next = (ALIAS *) safe_malloc (sizeof (ALIAS)); - a_cur = a_cur->next; - } - memcpy (a_cur, a, sizeof (ALIAS)); - a_cur->next = NULL; - } - a = a->next; + while (a) { + if (a->name && (strstr (a->name, s) == a->name)) { + if (!a_list) /* init */ + a_cur = a_list = (ALIAS *) safe_malloc (sizeof (ALIAS)); + else { + a_cur->next = (ALIAS *) safe_malloc (sizeof (ALIAS)); + a_cur = a_cur->next; + } + memcpy (a_cur, a, sizeof (ALIAS)); + a_cur->next = NULL; + } + a = a->next; } } } bestname[0] = 0; - mutt_alias_menu (bestname, sizeof(bestname), a_list ? a_list : Aliases); + mutt_alias_menu (bestname, sizeof (bestname), a_list ? a_list : Aliases); if (bestname[0] != 0) strfcpy (s, bestname, buflen); /* free the alias list */ - while (a_list) - { + while (a_list) { a_cur = a_list; a_list = a_list->next; FREE (&a_cur); @@ -490,95 +452,99 @@ int mutt_alias_complete (char *s, size_t buflen) /* remove any aliases marked for deletion */ a_list = NULL; - for (a_cur = Aliases; a_cur;) - { - if (a_cur->del) - { + for (a_cur = Aliases; a_cur;) { + if (a_cur->del) { if (a_list) - a_list->next = a_cur->next; + a_list->next = a_cur->next; else - Aliases = a_cur->next; - + Aliases = a_cur->next; + a_cur->next = NULL; mutt_free_alias (&a_cur); - + if (a_list) - a_cur = a_list; + a_cur = a_list; else - a_cur = Aliases; + a_cur = Aliases; } - else - { + else { a_list = a_cur; - a_cur = a_cur->next; + a_cur = a_cur->next; } } - + return 0; } -static int string_is_address(const char *str, const char *u, const char *d) +static int string_is_address (const char *str, const char *u, const char *d) { char buf[LONG_STRING]; - - snprintf(buf, sizeof(buf), "%s@%s", NONULL(u), NONULL(d)); - if (ascii_strcasecmp(str, buf) == 0) + + snprintf (buf, sizeof (buf), "%s@%s", NONULL (u), NONULL (d)); + if (ascii_strcasecmp (str, buf) == 0) return 1; - + return 0; } /* returns TRUE if the given address belongs to the user. */ -int mutt_addr_is_user (ADDRESS *addr) +int mutt_addr_is_user (ADDRESS * addr) { /* NULL address is assumed to be the user. */ - if (!addr) - { + if (!addr) { dprint (5, (debugfile, "mail_addr_is_user: yes, NULL address\n")); return 1; } - if (!addr->mailbox) - { + if (!addr->mailbox) { dprint (5, (debugfile, "mail_addr_is_user: no, no mailbox\n")); return 0; } - if (ascii_strcasecmp (addr->mailbox, Username) == 0) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, Username)); + if (ascii_strcasecmp (addr->mailbox, Username) == 0) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, + Username)); return 1; } - if (string_is_address(addr->mailbox, Username, Hostname)) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, Hostname)); + if (string_is_address (addr->mailbox, Username, Hostname)) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", + addr->mailbox, Username, Hostname)); return 1; } - if (string_is_address(addr->mailbox, Username, mutt_fqdn(0))) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (0))); + if (string_is_address (addr->mailbox, Username, mutt_fqdn (0))) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", + addr->mailbox, Username, mutt_fqdn (0))); return 1; } - if (string_is_address(addr->mailbox, Username, mutt_fqdn(1))) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (1))); + if (string_is_address (addr->mailbox, Username, mutt_fqdn (1))) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", + addr->mailbox, Username, mutt_fqdn (1))); return 1; } - if (From && !ascii_strcasecmp (From->mailbox, addr->mailbox)) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, From->mailbox)); + if (From && !ascii_strcasecmp (From->mailbox, addr->mailbox)) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, + From->mailbox)); return 1; } - if (mutt_match_rx_list (addr->mailbox, Alternates)) - { - dprint (5, (debugfile, "mail_addr_is_user: yes, %s matched by alternates.\n", addr->mailbox)); + if (mutt_match_rx_list (addr->mailbox, Alternates)) { + dprint (5, + (debugfile, "mail_addr_is_user: yes, %s matched by alternates.\n", + addr->mailbox)); if (mutt_match_rx_list (addr->mailbox, UnAlternates)) - dprint (5, (debugfile, "mail_addr_is_user: but, %s matched by unalternates.\n", addr->mailbox)); + dprint (5, + (debugfile, + "mail_addr_is_user: but, %s matched by unalternates.\n", + addr->mailbox)); else return 1; } - + dprint (5, (debugfile, "mail_addr_is_user: no, all failed.\n")); return 0; } diff --git a/ascii.c b/ascii.c index 27f3a86..e588f61 100644 --- a/ascii.c +++ b/ascii.c @@ -48,7 +48,7 @@ int ascii_toupper (int c) { if (ascii_islower (c)) return c & ~32; - + return c; } @@ -56,46 +56,44 @@ int ascii_tolower (int c) { if (ascii_isupper (c)) return c | 32; - + return c; } int ascii_strcasecmp (const char *a, const char *b) { int i; - + if (a == b) return 0; if (a == NULL && b) return -1; if (b == NULL && a) return 1; - - for (; *a || *b; a++, b++) - { + + for (; *a || *b; a++, b++) { if ((i = ascii_tolower (*a) - ascii_tolower (*b))) return i; } - + return 0; } int ascii_strncasecmp (const char *a, const char *b, int n) { int i, j; - + if (a == b) return 0; if (a == NULL && b) return -1; if (b == NULL && a) return 1; - - for (j = 0; (*a || *b) && j < n; a++, b++, j++) - { + + for (j = 0; (*a || *b) && j < n; a++, b++, j++) { if ((i = ascii_tolower (*a) - ascii_tolower (*b))) return i; } - + return 0; } diff --git a/attach.c b/attach.c index 102329d..ca06827 100644 --- a/attach.c +++ b/attach.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -42,48 +42,49 @@ #include #include -int mutt_get_tmp_attachment (BODY *a) +int mutt_get_tmp_attachment (BODY * a) { char type[STRING]; char tempfile[_POSIX_PATH_MAX]; - rfc1524_entry *entry = rfc1524_new_entry(); + rfc1524_entry *entry = rfc1524_new_entry (); FILE *fpin = NULL, *fpout = NULL; struct stat st; - - if(a->unlink) + + if (a->unlink) return 0; - snprintf(type, sizeof(type), "%s/%s", TYPE(a), a->subtype); - rfc1524_mailcap_lookup(a, type, entry, 0); - rfc1524_expand_filename(entry->nametemplate, a->filename, - tempfile, sizeof(tempfile)); - - rfc1524_free_entry(&entry); + snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); + rfc1524_mailcap_lookup (a, type, entry, 0); + rfc1524_expand_filename (entry->nametemplate, a->filename, + tempfile, sizeof (tempfile)); + + rfc1524_free_entry (&entry); - if(stat(a->filename, &st) == -1) + if (stat (a->filename, &st) == -1) return -1; - if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w"))) /* __FOPEN_CHECKED__ */ - { + if ((fpin = fopen (a->filename, "r")) && (fpout = safe_fopen (tempfile, "w"))) { /* __FOPEN_CHECKED__ */ mutt_copy_stream (fpin, fpout); mutt_str_replace (&a->filename, tempfile); a->unlink = 1; - if(a->stamp >= st.st_mtime) - mutt_stamp_attachment(a); + if (a->stamp >= st.st_mtime) + mutt_stamp_attachment (a); } else - mutt_perror(fpin ? tempfile : a->filename); - - if(fpin) fclose(fpin); - if(fpout) fclose(fpout); - + mutt_perror (fpin ? tempfile : a->filename); + + if (fpin) + fclose (fpin); + if (fpout) + fclose (fpout); + return a->unlink ? 0 : -1; } /* return 1 if require full screen redraw, 0 otherwise */ -int mutt_compose_attachment (BODY *a) +int mutt_compose_attachment (BODY * a) { char type[STRING]; char command[STRING]; @@ -91,119 +92,109 @@ int mutt_compose_attachment (BODY *a) rfc1524_entry *entry = rfc1524_new_entry (); short unlink_newfile = 0; int rc = 0; - + snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); - if (rfc1524_mailcap_lookup (a, type, entry, M_COMPOSE)) - { - if (entry->composecommand || entry->composetypecommand) - { + if (rfc1524_mailcap_lookup (a, type, entry, M_COMPOSE)) { + if (entry->composecommand || entry->composetypecommand) { if (entry->composetypecommand) - strfcpy (command, entry->composetypecommand, sizeof (command)); - else - strfcpy (command, entry->composecommand, sizeof (command)); + strfcpy (command, entry->composetypecommand, sizeof (command)); + else + strfcpy (command, entry->composecommand, sizeof (command)); if (rfc1524_expand_filename (entry->nametemplate, - a->filename, newfile, sizeof (newfile))) - { - dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", - a->filename, newfile)); - if (safe_symlink (a->filename, newfile) == -1) - { - if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES) - goto bailout; - } - else - unlink_newfile = 1; + a->filename, newfile, sizeof (newfile))) { + dprint (1, (debugfile, "oldfile: %s\t newfile: %s\n", + a->filename, newfile)); + if (safe_symlink (a->filename, newfile) == -1) { + if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) + != M_YES) + goto bailout; + } + else + unlink_newfile = 1; } else - strfcpy(newfile, a->filename, sizeof(newfile)); - + strfcpy (newfile, a->filename, sizeof (newfile)); + if (rfc1524_expand_command (a, newfile, type, - command, sizeof (command))) - { - /* For now, editing requires a file, no piping */ - mutt_error _("Mailcap compose entry requires %%s"); + command, sizeof (command))) { + /* For now, editing requires a file, no piping */ + mutt_error _("Mailcap compose entry requires %%s"); } - else - { - int r; - - mutt_endwin (NULL); - if ((r = mutt_system (command)) == -1) - mutt_error (_("Error running \"%s\"!"), command); - - if (r != -1 && entry->composetypecommand) - { - BODY *b; - FILE *fp, *tfp; - char tempfile[_POSIX_PATH_MAX]; - - if ((fp = safe_fopen (a->filename, "r")) == NULL) - { - mutt_perror _("Failure to open file to parse headers."); - goto bailout; - } - - b = mutt_read_mime_header (fp, 0); - if (b) - { - if (b->parameter) - { - mutt_free_parameter (&a->parameter); - a->parameter = b->parameter; - b->parameter = NULL; - } - if (b->description) { - FREE (&a->description); - a->description = b->description; - b->description = NULL; - } - if (b->form_name) - { - FREE (&a->form_name); - a->form_name = b->form_name; - b->form_name = NULL; - } - - /* Remove headers by copying out data to another file, then - * copying the file back */ - fseek (fp, b->offset, 0); - mutt_mktemp (tempfile); - if ((tfp = safe_fopen (tempfile, "w")) == NULL) - { - mutt_perror _("Failure to open file to strip headers."); - goto bailout; - } - mutt_copy_stream (fp, tfp); - fclose (fp); - fclose (tfp); - mutt_unlink (a->filename); - if (mutt_rename_file (tempfile, a->filename) != 0) - { - mutt_perror _("Failure to rename file."); - goto bailout; - } - - mutt_free_body (&b); - } - } + else { + int r; + + mutt_endwin (NULL); + if ((r = mutt_system (command)) == -1) + mutt_error (_("Error running \"%s\"!"), command); + + if (r != -1 && entry->composetypecommand) { + BODY *b; + FILE *fp, *tfp; + char tempfile[_POSIX_PATH_MAX]; + + if ((fp = safe_fopen (a->filename, "r")) == NULL) { + mutt_perror _("Failure to open file to parse headers."); + + goto bailout; + } + + b = mutt_read_mime_header (fp, 0); + if (b) { + if (b->parameter) { + mutt_free_parameter (&a->parameter); + a->parameter = b->parameter; + b->parameter = NULL; + } + if (b->description) { + FREE (&a->description); + a->description = b->description; + b->description = NULL; + } + if (b->form_name) { + FREE (&a->form_name); + a->form_name = b->form_name; + b->form_name = NULL; + } + + /* Remove headers by copying out data to another file, then + * copying the file back */ + fseek (fp, b->offset, 0); + mutt_mktemp (tempfile); + if ((tfp = safe_fopen (tempfile, "w")) == NULL) { + mutt_perror _("Failure to open file to strip headers."); + + goto bailout; + } + mutt_copy_stream (fp, tfp); + fclose (fp); + fclose (tfp); + mutt_unlink (a->filename); + if (mutt_rename_file (tempfile, a->filename) != 0) { + mutt_perror _("Failure to rename file."); + + goto bailout; + } + + mutt_free_body (&b); + } + } } } } - else - { + else { rfc1524_free_entry (&entry); mutt_message (_("No mailcap compose entry for %s, creating empty file."), - type); + type); return 1; } rc = 1; - - bailout: - - if(unlink_newfile) - unlink(newfile); + +bailout: + + if (unlink_newfile) + unlink (newfile); rfc1524_free_entry (&entry); return rc; @@ -218,7 +209,7 @@ int mutt_compose_attachment (BODY *a) * Returns 1 if editor found, 0 if not (useful to tell calling menu to * redraw) */ -int mutt_edit_attachment (BODY *a) +int mutt_edit_attachment (BODY * a) { char type[STRING]; char command[STRING]; @@ -226,63 +217,56 @@ int mutt_edit_attachment (BODY *a) rfc1524_entry *entry = rfc1524_new_entry (); short unlink_newfile = 0; int rc = 0; - + snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); - if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) - { - if (entry->editcommand) - { + if (rfc1524_mailcap_lookup (a, type, entry, M_EDIT)) { + if (entry->editcommand) { strfcpy (command, entry->editcommand, sizeof (command)); if (rfc1524_expand_filename (entry->nametemplate, - a->filename, newfile, sizeof (newfile))) - { - dprint(1, (debugfile, "oldfile: %s\t newfile: %s\n", - a->filename, newfile)); - if (safe_symlink (a->filename, newfile) == -1) - { - if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES) - goto bailout; - } - else - unlink_newfile = 1; + a->filename, newfile, sizeof (newfile))) { + dprint (1, (debugfile, "oldfile: %s\t newfile: %s\n", + a->filename, newfile)); + if (safe_symlink (a->filename, newfile) == -1) { + if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) + != M_YES) + goto bailout; + } + else + unlink_newfile = 1; } else - strfcpy(newfile, a->filename, sizeof(newfile)); + strfcpy (newfile, a->filename, sizeof (newfile)); if (rfc1524_expand_command (a, newfile, type, - command, sizeof (command))) - { - /* For now, editing requires a file, no piping */ - mutt_error _("Mailcap Edit entry requires %%s"); + command, sizeof (command))) { + /* For now, editing requires a file, no piping */ + mutt_error _("Mailcap Edit entry requires %%s"); } - else - { - mutt_endwin (NULL); - if (mutt_system (command) == -1) - mutt_error (_("Error running \"%s\"!"), command); + else { + mutt_endwin (NULL); + if (mutt_system (command) == -1) + mutt_error (_("Error running \"%s\"!"), command); } } } - else if (a->type == TYPETEXT) - { + else if (a->type == TYPETEXT) { /* On text, default to editor */ mutt_edit_file (NONULL (Editor), newfile); } - else - { + else { rfc1524_free_entry (&entry); - mutt_error (_("No mailcap edit entry for %s"),type); + mutt_error (_("No mailcap edit entry for %s"), type); return 0; } rc = 1; - - bailout: - - if(unlink_newfile) - unlink(newfile); - + +bailout: + + if (unlink_newfile) + unlink (newfile); + rfc1524_free_entry (&entry); return rc; } @@ -294,34 +278,28 @@ static int is_mmnoask (const char *buf) char tmp[LONG_STRING], *p, *q; int lng; - if ((p = getenv ("MM_NOASK")) != NULL && *p) - { + if ((p = getenv ("MM_NOASK")) != NULL && *p) { if (mutt_strcmp (p, "1") == 0) return (1); strfcpy (tmp, p, sizeof (tmp)); p = tmp; - while ((p = strtok (p, ",")) != NULL) - { - if ((q = strrchr (p, '/')) != NULL) - { - if (*(q+1) == '*') - { - if (ascii_strncasecmp (buf, p, q-p) == 0) - return (1); - } - else - { - if (ascii_strcasecmp (buf, p) == 0) - return (1); - } + while ((p = strtok (p, ",")) != NULL) { + if ((q = strrchr (p, '/')) != NULL) { + if (*(q + 1) == '*') { + if (ascii_strncasecmp (buf, p, q - p) == 0) + return (1); + } + else { + if (ascii_strcasecmp (buf, p) == 0) + return (1); + } } - else - { - lng = mutt_strlen (p); - if (buf[lng] == '/' && mutt_strncasecmp (buf, p, lng) == 0) - return (1); + else { + lng = mutt_strlen (p); + if (buf[lng] == '/' && mutt_strncasecmp (buf, p, lng) == 0) + return (1); } p = NULL; @@ -331,42 +309,42 @@ static int is_mmnoask (const char *buf) return (0); } -void mutt_check_lookup_list (BODY *b, char *type, int len) +void mutt_check_lookup_list (BODY * b, char *type, int len) { LIST *t = MimeLookupList; int i; for (; t; t = t->next) { i = mutt_strlen (t->data) - 1; - if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && - ascii_strncasecmp (type, t->data, i) == 0) || - ascii_strcasecmp (type, t->data) == 0) { - - BODY tmp = {0}; - int n; - if ((n = mutt_lookup_mime_type (&tmp, b->filename)) != TYPEOTHER) { - snprintf (type, len, "%s/%s", - n == TYPEAUDIO ? "audio" : - n == TYPEAPPLICATION ? "application" : - n == TYPEIMAGE ? "image" : - n == TYPEMESSAGE ? "message" : - n == TYPEMODEL ? "model" : - n == TYPEMULTIPART ? "multipart" : - n == TYPETEXT ? "text" : - n == TYPEVIDEO ? "video" : "other", - tmp.subtype); - dprint(1, (debugfile, "mutt_check_lookup_list: \"%s\" -> %s\n", - b->filename, type)); - } - if (tmp.subtype) - FREE (&tmp.subtype); - if (tmp.xtype) - FREE (&tmp.xtype); + if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' && + ascii_strncasecmp (type, t->data, i) == 0) || + ascii_strcasecmp (type, t->data) == 0) { + + BODY tmp = { 0 }; + int n; + + if ((n = mutt_lookup_mime_type (&tmp, b->filename)) != TYPEOTHER) { + snprintf (type, len, "%s/%s", + n == TYPEAUDIO ? "audio" : + n == TYPEAPPLICATION ? "application" : + n == TYPEIMAGE ? "image" : + n == TYPEMESSAGE ? "message" : + n == TYPEMODEL ? "model" : + n == TYPEMULTIPART ? "multipart" : + n == TYPETEXT ? "text" : + n == TYPEVIDEO ? "video" : "other", tmp.subtype); + dprint (1, (debugfile, "mutt_check_lookup_list: \"%s\" -> %s\n", + b->filename, type)); + } + if (tmp.subtype) + FREE (&tmp.subtype); + if (tmp.xtype) + FREE (&tmp.xtype); } } } -int mutt_is_autoview (BODY *b, const char *type) +int mutt_is_autoview (BODY * b, const char *type) { LIST *t = AutoViewList; char _type[SHORT_STRING]; @@ -375,25 +353,24 @@ int mutt_is_autoview (BODY *b, const char *type) if (!type) snprintf (_type, sizeof (_type), "%s/%s", TYPE (b), b->subtype); else - strncpy (_type, type, sizeof(_type)); + strncpy (_type, type, sizeof (_type)); - mutt_check_lookup_list (b, _type, sizeof(_type)); + mutt_check_lookup_list (b, _type, sizeof (_type)); type = _type; - if (mutt_needs_mailcap (b)) - { + if (mutt_needs_mailcap (b)) { if (option (OPTIMPLICITAUTOVIEW)) return 1; - + if (is_mmnoask (type)) return 1; } for (; t; t = t->next) { i = mutt_strlen (t->data) - 1; - if ((i > 0 && t->data[i-1] == '/' && t->data[i] == '*' && - ascii_strncasecmp (type, t->data, i) == 0) || - ascii_strcasecmp (type, t->data) == 0) + if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' && + ascii_strncasecmp (type, t->data, i) == 0) || + ascii_strcasecmp (type, t->data) == 0) return 1; } @@ -401,8 +378,8 @@ int mutt_is_autoview (BODY *b, const char *type) } /* returns -1 on error, 0 or the return code from mutt_do_pager() on success */ -int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, - ATTACHPTR **idx, short idxlen) +int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr, + ATTACHPTR ** idx, short idxlen) { char tempfile[_POSIX_PATH_MAX] = ""; char pagerfile[_POSIX_PATH_MAX] = ""; @@ -417,44 +394,40 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, rfc1524_entry *entry = NULL; int rc = -1; int unlink_tempfile = 0; - - is_message = mutt_is_message_type(a->type, a->subtype); + + is_message = mutt_is_message_type (a->type, a->subtype); if (WithCrypto && is_message && a->hdr && (a->hdr->security & ENCRYPT) && - !crypt_valid_passphrase(a->hdr->security)) + !crypt_valid_passphrase (a->hdr->security)) return (rc); use_mailcap = (flag == M_MAILCAP || - (flag == M_REGULAR && mutt_needs_mailcap (a))); + (flag == M_REGULAR && mutt_needs_mailcap (a))); snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); - - if (use_mailcap) - { - entry = rfc1524_new_entry (); - if (!rfc1524_mailcap_lookup (a, type, entry, 0)) - { - if (flag == M_REGULAR) - { - /* fallback to view as text */ - rfc1524_free_entry (&entry); - mutt_error _("No matching mailcap entry found. Viewing as text."); - flag = M_AS_TEXT; - use_mailcap = 0; + + if (use_mailcap) { + entry = rfc1524_new_entry (); + if (!rfc1524_mailcap_lookup (a, type, entry, 0)) { + if (flag == M_REGULAR) { + /* fallback to view as text */ + rfc1524_free_entry (&entry); + mutt_error _("No matching mailcap entry found. Viewing as text."); + + flag = M_AS_TEXT; + use_mailcap = 0; } else - goto return_error; + goto return_error; } } - - if (use_mailcap) - { - if (!entry->command) - { + + if (use_mailcap) { + if (!entry->command) { mutt_error _("MIME type not defined. Cannot view attachment."); + goto return_error; } strfcpy (command, entry->command, sizeof (command)); - - if (fp) - { + + if (fp) { fname = safe_strdup (a->filename); mutt_sanitize_filename (fname, 1); } @@ -462,151 +435,139 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, fname = a->filename; if (rfc1524_expand_filename (entry->nametemplate, fname, - tempfile, sizeof (tempfile))) - { - if (fp == NULL && mutt_strcmp(tempfile, a->filename)) - { - /* send case: the file is already there */ - if (safe_symlink (a->filename, tempfile) == -1) - { - if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) == M_YES) - strfcpy (tempfile, a->filename, sizeof (tempfile)); - else - goto return_error; - } - else - unlink_tempfile = 1; + tempfile, sizeof (tempfile))) { + if (fp == NULL && mutt_strcmp (tempfile, a->filename)) { + /* send case: the file is already there */ + if (safe_symlink (a->filename, tempfile) == -1) { + if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) + == M_YES) + strfcpy (tempfile, a->filename, sizeof (tempfile)); + else + goto return_error; + } + else + unlink_tempfile = 1; } } - else if (fp == NULL) /* send case */ + else if (fp == NULL) /* send case */ strfcpy (tempfile, a->filename, sizeof (tempfile)); - - if (fp) - { + + if (fp) { /* recv case: we need to save the attachment to a file */ FREE (&fname); if (mutt_save_attachment (fp, a, tempfile, 0, NULL) == -1) - goto return_error; + goto return_error; } use_pipe = rfc1524_expand_command (a, tempfile, type, - command, sizeof (command)); + command, sizeof (command)); use_pager = entry->copiousoutput; } - - if (use_pager) - { - if (fp && !use_mailcap && a->filename) - { + + if (use_pager) { + if (fp && !use_mailcap && a->filename) { /* recv case */ strfcpy (pagerfile, a->filename, sizeof (pagerfile)); - mutt_adv_mktemp (pagerfile, sizeof(pagerfile)); + mutt_adv_mktemp (pagerfile, sizeof (pagerfile)); } else mutt_mktemp (pagerfile); } - - if (use_mailcap) - { + + if (use_mailcap) { pid_t thepid = 0; int tempfd = -1, pagerfd = -1; - + if (!use_pager) mutt_endwin (NULL); - if (use_pager || use_pipe) - { - if (use_pager && ((pagerfd = safe_open (pagerfile, O_CREAT | O_EXCL | O_WRONLY)) == -1)) - { - mutt_perror ("open"); - goto return_error; + if (use_pager || use_pipe) { + if (use_pager + && ((pagerfd = safe_open (pagerfile, O_CREAT | O_EXCL | O_WRONLY)) + == -1)) { + mutt_perror ("open"); + goto return_error; } - if (use_pipe && ((tempfd = open (tempfile, 0)) == -1)) - { - if(pagerfd != -1) - close(pagerfd); - mutt_perror ("open"); - goto return_error; + if (use_pipe && ((tempfd = open (tempfile, 0)) == -1)) { + if (pagerfd != -1) + close (pagerfd); + mutt_perror ("open"); + goto return_error; } if ((thepid = mutt_create_filter_fd (command, NULL, NULL, NULL, - use_pipe ? tempfd : -1, use_pager ? pagerfd : -1, -1)) == -1) - { - if(pagerfd != -1) - close(pagerfd); - - if(tempfd != -1) - close(tempfd); - - mutt_error _("Cannot create filter"); - goto return_error; + use_pipe ? tempfd : -1, + use_pager ? pagerfd : -1, + -1)) == -1) { + if (pagerfd != -1) + close (pagerfd); + + if (tempfd != -1) + close (tempfd); + + mutt_error _("Cannot create filter"); + + goto return_error; } - if (use_pager) - { - if (a->description) - snprintf (descrip, sizeof (descrip), - "---Command: %-20.20s Description: %s", - command, a->description); - else - snprintf (descrip, sizeof (descrip), - "---Command: %-30.30s Attachment: %s", command, type); + if (use_pager) { + if (a->description) + snprintf (descrip, sizeof (descrip), + "---Command: %-20.20s Description: %s", + command, a->description); + else + snprintf (descrip, sizeof (descrip), + "---Command: %-30.30s Attachment: %s", command, type); } if ((mutt_wait_filter (thepid) || (entry->needsterminal && - option (OPTWAITKEY))) && !use_pager) - mutt_any_key_to_continue (NULL); - - close(tempfd); - close(pagerfd); - + option (OPTWAITKEY))) && !use_pager) + mutt_any_key_to_continue (NULL); + + close (tempfd); + close (pagerfd); + } - else - { + else { /* interactive command */ if (mutt_system (command) || - (entry->needsterminal && option (OPTWAITKEY))) - mutt_any_key_to_continue (NULL); + (entry->needsterminal && option (OPTWAITKEY))) + mutt_any_key_to_continue (NULL); } } - else - { + else { /* Don't use mailcap; the attachment is viewed in the pager */ - if (flag == M_AS_TEXT) - { + if (flag == M_AS_TEXT) { /* just let me see the raw data */ if (mutt_save_attachment (fp, a, pagerfile, 0, NULL)) - goto return_error; + goto return_error; } - else - { + else { /* Use built-in handler */ - set_option (OPTVIEWATTACH); /* disable the "use 'v' to view this part" - * message in case of error */ - if (mutt_decode_save_attachment (fp, a, pagerfile, M_DISPLAY, 0)) - { - unset_option (OPTVIEWATTACH); - goto return_error; + set_option (OPTVIEWATTACH); /* disable the "use 'v' to view this part" + * message in case of error */ + if (mutt_decode_save_attachment (fp, a, pagerfile, M_DISPLAY, 0)) { + unset_option (OPTVIEWATTACH); + goto return_error; } unset_option (OPTVIEWATTACH); } - + if (a->description) strfcpy (descrip, a->description, sizeof (descrip)); else if (a->filename) snprintf (descrip, sizeof (descrip), "---Attachment: %s : %s", - a->filename, type); + a->filename, type); else snprintf (descrip, sizeof (descrip), "---Attachment: %s", type); } - + /* We only reach this point if there have been no errors */ - if (use_pager) - { + if (use_pager) { pager_t info; - + memset (&info, 0, sizeof (info)); info.fp = fp; info.bdy = a; @@ -616,20 +577,21 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, info.hdr = hdr; rc = mutt_do_pager (descrip, pagerfile, - M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE : 0), &info); + M_PAGER_ATTACHMENT | (is_message ? M_PAGER_MESSAGE : + 0), &info); *pagerfile = '\0'; } else rc = 0; - return_error: - +return_error: + if (entry) rfc1524_free_entry (&entry); if (fp && tempfile[0]) mutt_unlink (tempfile); else if (unlink_tempfile) - unlink(tempfile); + unlink (tempfile); if (pagerfile[0]) mutt_unlink (pagerfile); @@ -638,23 +600,22 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, } /* returns 1 on success, 0 on error */ -int mutt_pipe_attachment (FILE *fp, BODY *b, const char *path, char *outfile) +int mutt_pipe_attachment (FILE * fp, BODY * b, const char *path, + char *outfile) { pid_t thepid; int out = -1; int rv = 0; - + if (outfile && *outfile) - if ((out = safe_open (outfile, O_CREAT | O_EXCL | O_WRONLY)) < 0) - { + if ((out = safe_open (outfile, O_CREAT | O_EXCL | O_WRONLY)) < 0) { mutt_perror ("open"); return 0; } mutt_endwin (NULL); - if (fp) - { + if (fp) { /* recv case */ STATE s; @@ -662,33 +623,31 @@ int mutt_pipe_attachment (FILE *fp, BODY *b, const char *path, char *outfile) memset (&s, 0, sizeof (STATE)); if (outfile && *outfile) - thepid = mutt_create_filter_fd (path, &s.fpout, NULL, NULL, -1, out, -1); + thepid = + mutt_create_filter_fd (path, &s.fpout, NULL, NULL, -1, out, -1); else thepid = mutt_create_filter (path, &s.fpout, NULL, NULL); - if (thepid < 0) - { + if (thepid < 0) { mutt_perror _("Can't create filter"); + goto bail; } - + s.fpin = fp; mutt_decode_attachment (b, &s); safe_fclose (&s.fpout); } - else - { + else { /* send case */ FILE *ifp, *ofp; - if ((ifp = fopen (b->filename, "r")) == NULL) - { + if ((ifp = fopen (b->filename, "r")) == NULL) { mutt_perror ("fopen"); - if (outfile && *outfile) - { - close (out); - unlink (outfile); + if (outfile && *outfile) { + close (out); + unlink (outfile); } return 0; } @@ -698,22 +657,22 @@ int mutt_pipe_attachment (FILE *fp, BODY *b, const char *path, char *outfile) else thepid = mutt_create_filter (path, &ofp, NULL, NULL); - if (thepid < 0) - { + if (thepid < 0) { mutt_perror _("Can't create filter"); + safe_fclose (&ifp); goto bail; } - + mutt_copy_stream (ifp, ofp); safe_fclose (&ofp); safe_fclose (&ifp); } rv = 1; - + bail: - + if (outfile && *outfile) close (out); @@ -728,34 +687,32 @@ bail: return rv; } -static FILE * -mutt_save_attachment_open (char *path, int flags) +static FILE *mutt_save_attachment_open (char *path, int flags) { if (flags == M_SAVE_APPEND) return fopen (path, "a"); - /* be sure not to change the following fopen to safe_fopen - * as safe_fopen returns w/ an error if path exists - */ + /* be sure not to change the following fopen to safe_fopen + * as safe_fopen returns w/ an error if path exists + */ if (flags == M_SAVE_OVERWRITE) - return fopen (path, "w"); /* __FOPEN_CHECKED__ */ - + return fopen (path, "w"); /* __FOPEN_CHECKED__ */ + return safe_fopen (path, "w"); } /* returns 0 on success, -1 on error */ -int mutt_save_attachment (FILE *fp, BODY *m, char *path, int flags, HEADER *hdr) +int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags, + HEADER * hdr) { - if (fp) - { - + if (fp) { + /* recv mode */ - if(hdr && - m->hdr && - m->encoding != ENCBASE64 && - m->encoding != ENCQUOTEDPRINTABLE && - mutt_is_message_type(m->type, m->subtype)) - { + if (hdr && + m->hdr && + m->encoding != ENCBASE64 && + m->encoding != ENCQUOTEDPRINTABLE && + mutt_is_message_type (m->type, m->subtype)) { /* message type attachments are written to mail folders. */ char buf[HUGE_STRING]; @@ -764,78 +721,74 @@ int mutt_save_attachment (FILE *fp, BODY *m, char *path, int flags, HEADER *hdr) MESSAGE *msg; int chflags = 0; int r = -1; - + hn = m->hdr; - hn->msgno = hdr->msgno; /* required for MH/maildir */ + hn->msgno = hdr->msgno; /* required for MH/maildir */ hn->read = 1; fseek (fp, m->offset, 0); if (fgets (buf, sizeof (buf), fp) == NULL) - return -1; - if (mx_open_mailbox(path, M_APPEND | M_QUIET, &ctx) == NULL) - return -1; - if ((msg = mx_open_new_message (&ctx, hn, is_from (buf, NULL, 0, NULL) ? 0 : M_ADD_FROM)) == NULL) - { - mx_close_mailbox(&ctx, NULL); - return -1; + return -1; + if (mx_open_mailbox (path, M_APPEND | M_QUIET, &ctx) == NULL) + return -1; + if ((msg = + mx_open_new_message (&ctx, hn, + is_from (buf, NULL, 0, + NULL) ? 0 : M_ADD_FROM)) == NULL) { + mx_close_mailbox (&ctx, NULL); + return -1; } if (ctx.magic == M_MBOX || ctx.magic == M_MMDF) - chflags = CH_FROM; + chflags = CH_FROM; chflags |= (ctx.magic == M_MAILDIR ? CH_NOSTATUS : CH_UPDATE); - if (_mutt_copy_message (msg->fp, fp, hn, hn->content, 0, chflags) == 0 - && mx_commit_message (msg, &ctx) == 0) - r = 0; + if (_mutt_copy_message (msg->fp, fp, hn, hn->content, 0, chflags) == 0 + && mx_commit_message (msg, &ctx) == 0) + r = 0; else - r = -1; + r = -1; mx_close_message (&msg); mx_close_mailbox (&ctx, NULL); return r; } - else - { + else { /* In recv mode, extract from folder and decode */ - + STATE s; - + memset (&s, 0, sizeof (s)); - if ((s.fpout = mutt_save_attachment_open (path, flags)) == NULL) - { - mutt_perror ("fopen"); - return (-1); + if ((s.fpout = mutt_save_attachment_open (path, flags)) == NULL) { + mutt_perror ("fopen"); + return (-1); } fseek ((s.fpin = fp), m->offset, 0); mutt_decode_attachment (m, &s); - - if (fclose (s.fpout) != 0) - { - mutt_perror ("fclose"); - return (-1); + + if (fclose (s.fpout) != 0) { + mutt_perror ("fclose"); + return (-1); } } } - else - { + else { /* In send mode, just copy file */ FILE *ofp, *nfp; - if ((ofp = fopen (m->filename, "r")) == NULL) - { + if ((ofp = fopen (m->filename, "r")) == NULL) { mutt_perror ("fopen"); return (-1); } - - if ((nfp = mutt_save_attachment_open (path, flags)) == NULL) - { + + if ((nfp = mutt_save_attachment_open (path, flags)) == NULL) { mutt_perror ("fopen"); safe_fclose (&ofp); return (-1); } - if (mutt_copy_stream (ofp, nfp) == -1) - { + if (mutt_copy_stream (ofp, nfp) == -1) { mutt_error _("Write fault!"); + safe_fclose (&ofp); safe_fclose (&nfp); return (-1); @@ -848,8 +801,8 @@ int mutt_save_attachment (FILE *fp, BODY *m, char *path, int flags, HEADER *hdr) } /* returns 0 on success, -1 on error */ -int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, - int displaying, int flags) +int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path, + int displaying, int flags) { STATE s; unsigned int saved_encoding = 0; @@ -862,31 +815,27 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, if (flags == M_SAVE_APPEND) s.fpout = fopen (path, "a"); else if (flags == M_SAVE_OVERWRITE) - s.fpout = safe_fopen (path, "w"); /* __FOPEN_CHECKED__ */ + s.fpout = safe_fopen (path, "w"); /* __FOPEN_CHECKED__ */ else s.fpout = safe_fopen (path, "w"); - if (s.fpout == NULL) - { + if (s.fpout == NULL) { mutt_perror ("fopen"); return (-1); } - if (fp == NULL) - { + if (fp == NULL) { /* When called from the compose menu, the attachment isn't parsed, * so we need to do it here. */ struct stat st; - if (stat (m->filename, &st) == -1) - { + if (stat (m->filename, &st) == -1) { mutt_perror ("stat"); fclose (s.fpout); return (-1); } - if ((s.fpin = fopen (m->filename, "r")) == NULL) - { + if ((s.fpin = fopen (m->filename, "r")) == NULL) { mutt_perror ("fopen"); return (-1); } @@ -894,7 +843,7 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, saved_encoding = m->encoding; if (!is_multipart (m)) m->encoding = ENC8BIT; - + m->length = st.st_size; m->offset = 0; saved_parts = m->parts; @@ -904,8 +853,7 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, if (m->noconv || is_multipart (m)) s.flags |= M_CHARCONV; } - else - { + else { s.fpin = fp; s.flags |= M_CHARCONV; } @@ -913,12 +861,10 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, mutt_body_handler (m, &s); fclose (s.fpout); - if (fp == NULL) - { + if (fp == NULL) { m->length = 0; m->encoding = saved_encoding; - if (saved_parts) - { + if (saved_parts) { mutt_free_header (&m->hdr); m->parts = saved_parts; m->hdr = saved_hdr; @@ -936,42 +882,38 @@ int mutt_decode_save_attachment (FILE *fp, BODY *m, char *path, * attachment */ -int mutt_print_attachment (FILE *fp, BODY *a) +int mutt_print_attachment (FILE * fp, BODY * a) { char newfile[_POSIX_PATH_MAX] = ""; char type[STRING]; pid_t thepid; FILE *ifp, *fpout; short unlink_newfile = 0; - + snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); - if (rfc1524_mailcap_lookup (a, type, NULL, M_PRINT)) - { - char command[_POSIX_PATH_MAX+STRING]; + if (rfc1524_mailcap_lookup (a, type, NULL, M_PRINT)) { + char command[_POSIX_PATH_MAX + STRING]; rfc1524_entry *entry; int piped = FALSE; dprint (2, (debugfile, "Using mailcap...\n")); - + entry = rfc1524_new_entry (); rfc1524_mailcap_lookup (a, type, entry, M_PRINT); if (rfc1524_expand_filename (entry->nametemplate, a->filename, - newfile, sizeof (newfile))) - { - if (!fp) - { - if (safe_symlink(a->filename, newfile) == -1) - { - if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES) - { - rfc1524_free_entry (&entry); - return 0; - } - strfcpy (newfile, a->filename, sizeof (newfile)); - } - else - unlink_newfile = 1; + newfile, sizeof (newfile))) { + if (!fp) { + if (safe_symlink (a->filename, newfile) == -1) { + if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) + != M_YES) { + rfc1524_free_entry (&entry); + return 0; + } + strfcpy (newfile, a->filename, sizeof (newfile)); + } + else + unlink_newfile = 1; } } @@ -980,93 +922,89 @@ int mutt_print_attachment (FILE *fp, BODY *a) mutt_save_attachment (fp, a, newfile, 0, NULL); strfcpy (command, entry->printcommand, sizeof (command)); - piped = rfc1524_expand_command (a, newfile, type, command, sizeof (command)); + piped = + rfc1524_expand_command (a, newfile, type, command, sizeof (command)); mutt_endwin (NULL); /* interactive program */ - if (piped) - { - if ((ifp = fopen (newfile, "r")) == NULL) - { - mutt_perror ("fopen"); - rfc1524_free_entry (&entry); - return (0); + if (piped) { + if ((ifp = fopen (newfile, "r")) == NULL) { + mutt_perror ("fopen"); + rfc1524_free_entry (&entry); + return (0); } - if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0) - { - mutt_perror _("Can't create filter"); - rfc1524_free_entry (&entry); - safe_fclose (&ifp); - return 0; + if ((thepid = mutt_create_filter (command, &fpout, NULL, NULL)) < 0) { + mutt_perror _("Can't create filter"); + + rfc1524_free_entry (&entry); + safe_fclose (&ifp); + return 0; } mutt_copy_stream (ifp, fpout); safe_fclose (&fpout); safe_fclose (&ifp); if (mutt_wait_filter (thepid) || option (OPTWAITKEY)) - mutt_any_key_to_continue (NULL); + mutt_any_key_to_continue (NULL); } - else - { + else { if (mutt_system (command) || option (OPTWAITKEY)) - mutt_any_key_to_continue (NULL); + mutt_any_key_to_continue (NULL); } if (fp) mutt_unlink (newfile); else if (unlink_newfile) - unlink(newfile); + unlink (newfile); rfc1524_free_entry (&entry); return (1); } if (!ascii_strcasecmp ("text/plain", type) || - !ascii_strcasecmp ("application/postscript", type)) - { - return (mutt_pipe_attachment (fp, a, NONULL(PrintCmd), NULL)); + !ascii_strcasecmp ("application/postscript", type)) { + return (mutt_pipe_attachment (fp, a, NONULL (PrintCmd), NULL)); } - else if (mutt_can_decode (a)) - { + else if (mutt_can_decode (a)) { /* decode and print */ int rc = 0; - + ifp = NULL; fpout = NULL; - + mutt_mktemp (newfile); - if (mutt_decode_save_attachment (fp, a, newfile, M_PRINTING, 0) == 0) - { - - dprint (2, (debugfile, "successfully decoded %s type attachment to %s\n", - type, newfile)); - - if ((ifp = fopen (newfile, "r")) == NULL) - { - mutt_perror ("fopen"); - goto bail0; + if (mutt_decode_save_attachment (fp, a, newfile, M_PRINTING, 0) == 0) { + + dprint (2, + (debugfile, "successfully decoded %s type attachment to %s\n", + type, newfile)); + + if ((ifp = fopen (newfile, "r")) == NULL) { + mutt_perror ("fopen"); + goto bail0; } dprint (2, (debugfile, "successfully opened %s read-only\n", newfile)); - + mutt_endwin (NULL); - if ((thepid = mutt_create_filter (NONULL(PrintCmd), &fpout, NULL, NULL)) < 0) - { - mutt_perror _("Can't create filter"); - goto bail0; + if ((thepid = + mutt_create_filter (NONULL (PrintCmd), &fpout, NULL, NULL)) < 0) { + mutt_perror _("Can't create filter"); + + goto bail0; } dprint (2, (debugfile, "Filter created.\n")); - + mutt_copy_stream (ifp, fpout); safe_fclose (&fpout); safe_fclose (&ifp); if (mutt_wait_filter (thepid) != 0 || option (OPTWAITKEY)) - mutt_any_key_to_continue (NULL); + mutt_any_key_to_continue (NULL); rc = 1; } bail0: @@ -1075,9 +1013,9 @@ int mutt_print_attachment (FILE *fp, BODY *a) mutt_unlink (newfile); return rc; } - else - { + else { mutt_error _("I don't know how to print that!"); + return 0; } } diff --git a/attach.h b/attach.h index b751a95..e7b5513 100644 --- a/attach.h +++ b/attach.h @@ -14,19 +14,20 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* common protos for compose / attach menus */ -int mutt_tag_attach (MUTTMENU *menu, int n, int m); -int mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, - BODY *cur, ATTACHPTR ***idxp, short *idxlen, short *idxmax, - int recv); +int mutt_tag_attach (MUTTMENU * menu, int n, int m); +int mutt_attach_display_loop (MUTTMENU * menu, int op, FILE * fp, + HEADER * hdr, BODY * cur, ATTACHPTR *** idxp, + short *idxlen, short *idxmax, int recv); -void mutt_save_attachment_list (FILE *fp, int tag, BODY *top, HEADER *hdr, MUTTMENU *menu); -void mutt_pipe_attachment_list (FILE *fp, int tag, BODY *top, int filter); -void mutt_print_attachment_list (FILE *fp, int tag, BODY *top); +void mutt_save_attachment_list (FILE * fp, int tag, BODY * top, HEADER * hdr, + MUTTMENU * menu); +void mutt_pipe_attachment_list (FILE * fp, int tag, BODY * top, int filter); +void mutt_print_attachment_list (FILE * fp, int tag, BODY * top); void mutt_attach_bounce (FILE *, HEADER *, ATTACHPTR **, short, BODY *); void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *); diff --git a/base64.c b/base64.c index 4e63292..ad6c6c4 100644 --- a/base64.c +++ b/base64.c @@ -50,22 +50,20 @@ /* raw bytes to null-terminated base 64 string */ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, - size_t olen) + size_t olen) { - while (len >= 3 && olen > 10) - { + while (len >= 3 && olen > 10) { *out++ = B64Chars[in[0] >> 2]; *out++ = B64Chars[((in[0] << 4) & 0x30) | (in[1] >> 4)]; *out++ = B64Chars[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; *out++ = B64Chars[in[2] & 0x3f]; - olen -= 4; - len -= 3; - in += 3; + olen -= 4; + len -= 3; + in += 3; } /* clean up remainder */ - if (len > 0 && olen > 4) - { + if (len > 0 && olen > 4) { unsigned char fragment; *out++ = B64Chars[in[0] >> 2]; @@ -86,8 +84,7 @@ int mutt_from_base64 (char *out, const char *in) int len = 0; register unsigned char digit1, digit2, digit3, digit4; - do - { + do { digit1 = in[0]; if (digit1 > 127 || base64val (digit1) == BAD) return -1; @@ -103,16 +100,14 @@ int mutt_from_base64 (char *out, const char *in) in += 4; /* digits are already sanity-checked */ - *out++ = (base64val(digit1) << 2) | (base64val(digit2) >> 4); + *out++ = (base64val (digit1) << 2) | (base64val (digit2) >> 4); len++; - if (digit3 != '=') - { - *out++ = ((base64val(digit2) << 4) & 0xf0) | (base64val(digit3) >> 2); + if (digit3 != '=') { + *out++ = ((base64val (digit2) << 4) & 0xf0) | (base64val (digit3) >> 2); len++; - if (digit4 != '=') - { - *out++ = ((base64val(digit3) << 6) & 0xc0) | base64val(digit4); - len++; + if (digit4 != '=') { + *out++ = ((base64val (digit3) << 6) & 0xc0) | base64val (digit4); + len++; } } } diff --git a/browser.c b/browser.c index 21bb588..f47b8fb 100644 --- a/browser.c +++ b/browser.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -45,28 +45,27 @@ #include static struct mapping_t FolderHelp[] = { - { N_("Exit"), OP_EXIT }, - { N_("Chdir"), OP_CHANGE_DIRECTORY }, - { N_("Mask"), OP_ENTER_MASK }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Exit"), OP_EXIT}, + {N_("Chdir"), OP_CHANGE_DIRECTORY}, + {N_("Mask"), OP_ENTER_MASK}, + {N_("Help"), OP_HELP}, + {NULL} }; #ifdef USE_NNTP static struct mapping_t FolderNewsHelp[] = { - { N_("Exit"), OP_EXIT }, - { N_("List"), OP_TOGGLE_MAILBOXES }, - { N_("Subscribe"), OP_BROWSER_SUBSCRIBE }, - { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE }, - { N_("Catchup"), OP_CATCHUP }, - { N_("Mask"), OP_ENTER_MASK }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Exit"), OP_EXIT}, + {N_("List"), OP_TOGGLE_MAILBOXES}, + {N_("Subscribe"), OP_BROWSER_SUBSCRIBE}, + {N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE}, + {N_("Catchup"), OP_CATCHUP}, + {N_("Mask"), OP_ENTER_MASK}, + {N_("Help"), OP_HELP}, + {NULL} }; #endif -typedef struct folder_t -{ +typedef struct folder_t { struct folder_file *ff; int num; } FOLDER; @@ -79,8 +78,7 @@ static void destroy_state (struct browser_state *state) { int c; - for (c = 0; c < state->entrylen; c++) - { + for (c = 0; c < state->entrylen; c++) { FREE (&((state->entry)[c].name)); FREE (&((state->entry)[c].desc)); FREE (&((state->entry)[c].st)); @@ -125,28 +123,27 @@ static void browser_sort (struct browser_state *state) { int (*f) (const void *, const void *); - switch (BrowserSort & SORT_MASK) - { - case SORT_ORDER: - return; - case SORT_DATE: + switch (BrowserSort & SORT_MASK) { + case SORT_ORDER: + return; + case SORT_DATE: #ifdef USE_NNTP - if (option (OPTNEWS)) - return; + if (option (OPTNEWS)) + return; #endif - f = browser_compare_date; - break; - case SORT_SIZE: + f = browser_compare_date; + break; + case SORT_SIZE: #ifdef USE_NNTP - if (option (OPTNEWS)) - return; + if (option (OPTNEWS)) + return; #endif - f = browser_compare_size; - break; - case SORT_SUBJECT: - default: - f = browser_compare_subject; - break; + f = browser_compare_size; + break; + case SORT_SUBJECT: + default: + f = browser_compare_subject; + break; } qsort (state->entry, state->entrylen, sizeof (struct folder_file), f); } @@ -155,19 +152,20 @@ static int link_is_dir (const char *folder, const char *path) { struct stat st; char fullpath[_POSIX_PATH_MAX]; - + mutt_concat_path (fullpath, folder, path, sizeof (fullpath)); - + if (stat (fullpath, &st) == 0) return (S_ISDIR (st.st_mode)); else return 0; } -static const char * -folder_format_str (char *dest, size_t destlen, char op, const char *src, - const char *fmt, const char *ifstring, const char *elsestring, - unsigned long data, format_flag flags) +static const char *folder_format_str (char *dest, size_t destlen, char op, + const char *src, const char *fmt, + const char *ifstring, + const char *elsestring, + unsigned long data, format_flag flags) { char fn[SHORT_STRING], tmp[SHORT_STRING], permission[11]; char date[16], *t_fmt; @@ -177,149 +175,151 @@ folder_format_str (char *dest, size_t destlen, char op, const char *src, struct group *gr; int optional = (flags & M_FORMAT_OPTIONAL); - switch (op) - { - case 'C': - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->num + 1); - break; - - case 'd': - if (folder->ff->st != NULL) - { - tnow = time (NULL); - t_fmt = tnow - folder->ff->st->st_mtime < 31536000 ? "%b %d %H:%M" : "%b %d %Y"; - strftime (date, sizeof (date), t_fmt, localtime (&folder->ff->st->st_mtime)); - mutt_format_s (dest, destlen, fmt, date); - } - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - case 'f': + switch (op) { + case 'C': + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->num + 1); + break; + + case 'd': + if (folder->ff->st != NULL) { + tnow = time (NULL); + t_fmt = + tnow - folder->ff->st->st_mtime < + 31536000 ? "%b %d %H:%M" : "%b %d %Y"; + strftime (date, sizeof (date), t_fmt, + localtime (&folder->ff->st->st_mtime)); + mutt_format_s (dest, destlen, fmt, date); + } + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + case 'f': { char *s; + #ifdef USE_IMAP if (folder->ff->imap) - s = NONULL (folder->ff->desc); + s = NONULL (folder->ff->desc); else #endif - s = NONULL (folder->ff->name); + s = NONULL (folder->ff->name); snprintf (fn, sizeof (fn), "%s%s", s, - folder->ff->st ? (S_ISLNK (folder->ff->st->st_mode) ? "@" : - (S_ISDIR (folder->ff->st->st_mode) ? "/" : - ((folder->ff->st->st_mode & S_IXUSR) != 0 ? "*" : ""))) : ""); - + folder->ff->st ? (S_ISLNK (folder->ff->st->st_mode) ? "@" : + (S_ISDIR (folder->ff->st->st_mode) ? "/" : + ((folder->ff->st->st_mode & S_IXUSR) != + 0 ? "*" : ""))) : ""); + mutt_format_s (dest, destlen, fmt, fn); break; } - case 'F': - if (folder->ff->st != NULL) - { - snprintf (permission, sizeof (permission), "%c%c%c%c%c%c%c%c%c%c", - S_ISDIR(folder->ff->st->st_mode) ? 'd' : (S_ISLNK(folder->ff->st->st_mode) ? 'l' : '-'), - (folder->ff->st->st_mode & S_IRUSR) != 0 ? 'r': '-', - (folder->ff->st->st_mode & S_IWUSR) != 0 ? 'w' : '-', - (folder->ff->st->st_mode & S_ISUID) != 0 ? 's' : (folder->ff->st->st_mode & S_IXUSR) != 0 ? 'x': '-', - (folder->ff->st->st_mode & S_IRGRP) != 0 ? 'r' : '-', - (folder->ff->st->st_mode & S_IWGRP) != 0 ? 'w' : '-', - (folder->ff->st->st_mode & S_ISGID) != 0 ? 's' : (folder->ff->st->st_mode & S_IXGRP) != 0 ? 'x': '-', - (folder->ff->st->st_mode & S_IROTH) != 0 ? 'r' : '-', - (folder->ff->st->st_mode & S_IWOTH) != 0 ? 'w' : '-', - (folder->ff->st->st_mode & S_ISVTX) != 0 ? 't' : (folder->ff->st->st_mode & S_IXOTH) != 0 ? 'x': '-'); - mutt_format_s (dest, destlen, fmt, permission); - } + case 'F': + if (folder->ff->st != NULL) { + snprintf (permission, sizeof (permission), "%c%c%c%c%c%c%c%c%c%c", + S_ISDIR (folder->ff->st-> + st_mode) ? 'd' : (S_ISLNK (folder->ff->st-> + st_mode) ? 'l' : '-'), + (folder->ff->st->st_mode & S_IRUSR) != 0 ? 'r' : '-', + (folder->ff->st->st_mode & S_IWUSR) != 0 ? 'w' : '-', + (folder->ff->st->st_mode & S_ISUID) != + 0 ? 's' : (folder->ff->st->st_mode & S_IXUSR) != + 0 ? 'x' : '-', + (folder->ff->st->st_mode & S_IRGRP) != 0 ? 'r' : '-', + (folder->ff->st->st_mode & S_IWGRP) != 0 ? 'w' : '-', + (folder->ff->st->st_mode & S_ISGID) != + 0 ? 's' : (folder->ff->st->st_mode & S_IXGRP) != + 0 ? 'x' : '-', + (folder->ff->st->st_mode & S_IROTH) != 0 ? 'r' : '-', + (folder->ff->st->st_mode & S_IWOTH) != 0 ? 'w' : '-', + (folder->ff->st->st_mode & S_ISVTX) != + 0 ? 't' : (folder->ff->st->st_mode & S_IXOTH) != + 0 ? 'x' : '-'); + mutt_format_s (dest, destlen, fmt, permission); + } #ifdef USE_IMAP - else if (folder->ff->imap) - { - /* mark folders with subfolders AND mail */ - snprintf (permission, sizeof (permission), "IMAP %c", - (folder->ff->inferiors && folder->ff->selectable) ? '+' : ' '); - mutt_format_s (dest, destlen, fmt, permission); - } + else if (folder->ff->imap) { + /* mark folders with subfolders AND mail */ + snprintf (permission, sizeof (permission), "IMAP %c", + (folder->ff->inferiors + && folder->ff->selectable) ? '+' : ' '); + mutt_format_s (dest, destlen, fmt, permission); + } #endif - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - case 'g': - if (folder->ff->st != NULL) - { - if ((gr = getgrgid (folder->ff->st->st_gid))) - mutt_format_s (dest, destlen, fmt, gr->gr_name); - else - { - snprintf (tmp, sizeof (tmp), "%%%sld", fmt); - snprintf (dest, destlen, tmp, folder->ff->st->st_gid); - } - } - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - case 'l': - if (folder->ff->st != NULL) - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->ff->st->st_nlink); + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + case 'g': + if (folder->ff->st != NULL) { + if ((gr = getgrgid (folder->ff->st->st_gid))) + mutt_format_s (dest, destlen, fmt, gr->gr_name); + else { + snprintf (tmp, sizeof (tmp), "%%%sld", fmt); + snprintf (dest, destlen, tmp, folder->ff->st->st_gid); } - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - case 'N': + } + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + case 'l': + if (folder->ff->st != NULL) { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->ff->st->st_nlink); + } + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + case 'N': #ifdef USE_IMAP - if (mx_is_imap (folder->ff->desc)) - { - if (!optional) - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->ff->new); - } - else if (!folder->ff->new) - optional = 0; - break; - } -#endif - snprintf (tmp, sizeof (tmp), "%%%sc", fmt); - snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : ' '); - break; - - case 's': - if (folder->ff->st != NULL) - { - snprintf (tmp, sizeof (tmp), "%%%sld", fmt); - snprintf (dest, destlen, tmp, (long) folder->ff->st->st_size); + if (mx_is_imap (folder->ff->desc)) { + if (!optional) { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->ff->new); } - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - case 't': - snprintf (tmp, sizeof (tmp), "%%%sc", fmt); - snprintf (dest, destlen, tmp, folder->ff->tagged ? '*' : ' '); + else if (!folder->ff->new) + optional = 0; break; - - case 'u': - if (folder->ff->st != NULL) - { - if ((pw = getpwuid (folder->ff->st->st_uid))) - mutt_format_s (dest, destlen, fmt, pw->pw_name); - else - { - snprintf (tmp, sizeof (tmp), "%%%sld", fmt); - snprintf (dest, destlen, tmp, folder->ff->st->st_uid); - } + } +#endif + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : ' '); + break; + + case 's': + if (folder->ff->st != NULL) { + snprintf (tmp, sizeof (tmp), "%%%sld", fmt); + snprintf (dest, destlen, tmp, (long) folder->ff->st->st_size); + } + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + case 't': + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + snprintf (dest, destlen, tmp, folder->ff->tagged ? '*' : ' '); + break; + + case 'u': + if (folder->ff->st != NULL) { + if ((pw = getpwuid (folder->ff->st->st_uid))) + mutt_format_s (dest, destlen, fmt, pw->pw_name); + else { + snprintf (tmp, sizeof (tmp), "%%%sld", fmt); + snprintf (dest, destlen, tmp, folder->ff->st->st_uid); } - else - mutt_format_s (dest, destlen, fmt, ""); - break; - - default: - snprintf (tmp, sizeof (tmp), "%%%sc", fmt); - snprintf (dest, destlen, tmp, op); - break; + } + else + mutt_format_s (dest, destlen, fmt, ""); + break; + + default: + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + snprintf (dest, destlen, tmp, op); + break; } if (optional) @@ -331,123 +331,115 @@ folder_format_str (char *dest, size_t destlen, char op, const char *src, } #ifdef USE_NNTP -static const char * -newsgroup_format_str (char *dest, size_t destlen, char op, const char *src, - const char *fmt, const char *ifstring, const char *elsestring, - unsigned long data, format_flag flags) +static const char *newsgroup_format_str (char *dest, size_t destlen, char op, + const char *src, const char *fmt, + const char *ifstring, + const char *elsestring, + unsigned long data, + format_flag flags) { char fn[SHORT_STRING], tmp[SHORT_STRING]; FOLDER *folder = (FOLDER *) data; - switch (op) - { - case 'C': - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->num + 1); - break; - - case 'f': - strncpy (fn, folder->ff->name, sizeof(fn) - 1); - snprintf (tmp, sizeof (tmp), "%%%ss", fmt); - snprintf (dest, destlen, tmp, fn); - break; - - case 'N': - snprintf (tmp, sizeof (tmp), "%%%sc", fmt); - if (folder->ff->nd->subscribed) - snprintf (dest, destlen, tmp, ' '); - else - snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : 'u'); - break; - - case 'M': - snprintf (tmp, sizeof (tmp), "%%%sc", fmt); - if (folder->ff->nd->deleted) - snprintf (dest, destlen, tmp, 'D'); - else - snprintf (dest, destlen, tmp, folder->ff->nd->allowed ? ' ' : '-'); - break; + switch (op) { + case 'C': + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->num + 1); + break; + + case 'f': + strncpy (fn, folder->ff->name, sizeof (fn) - 1); + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, fn); + break; + + case 'N': + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + if (folder->ff->nd->subscribed) + snprintf (dest, destlen, tmp, ' '); + else + snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : 'u'); + break; - case 's': - if (flags & M_FORMAT_OPTIONAL) - { - if (folder->ff->nd->unread != 0) - mutt_FormatString (dest, destlen, ifstring, newsgroup_format_str, - data, flags); - else - mutt_FormatString (dest, destlen, elsestring, newsgroup_format_str, - data, flags); - } - else if (Context && Context->data == folder->ff->nd) - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, Context->unread); - } + case 'M': + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + if (folder->ff->nd->deleted) + snprintf (dest, destlen, tmp, 'D'); + else + snprintf (dest, destlen, tmp, folder->ff->nd->allowed ? ' ' : '-'); + break; + + case 's': + if (flags & M_FORMAT_OPTIONAL) { + if (folder->ff->nd->unread != 0) + mutt_FormatString (dest, destlen, ifstring, newsgroup_format_str, + data, flags); else - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->ff->nd->unread); - } - break; + mutt_FormatString (dest, destlen, elsestring, newsgroup_format_str, + data, flags); + } + else if (Context && Context->data == folder->ff->nd) { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, Context->unread); + } + else { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->ff->nd->unread); + } + break; - case 'n': - if (Context && Context->data == folder->ff->nd) - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, Context->new); - } - else if (option (OPTMARKOLD) && - folder->ff->nd->lastCached >= folder->ff->nd->firstMessage && - folder->ff->nd->lastCached <= folder->ff->nd->lastMessage) - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->ff->nd->lastMessage - folder->ff->nd->lastCached); - } - else - { - snprintf (tmp, sizeof (tmp), "%%%sd", fmt); - snprintf (dest, destlen, tmp, folder->ff->nd->unread); - } - break; + case 'n': + if (Context && Context->data == folder->ff->nd) { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, Context->new); + } + else if (option (OPTMARKOLD) && + folder->ff->nd->lastCached >= folder->ff->nd->firstMessage && + folder->ff->nd->lastCached <= folder->ff->nd->lastMessage) { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, + folder->ff->nd->lastMessage - folder->ff->nd->lastCached); + } + else { + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, folder->ff->nd->unread); + } + break; - case 'd': - if (folder->ff->nd->desc != NULL) - { - snprintf (tmp, sizeof (tmp), "%%%ss", fmt); - snprintf (dest, destlen, tmp, folder->ff->nd->desc); - } - else - { - snprintf (tmp, sizeof (tmp), "%%%ss", fmt); - snprintf (dest, destlen, tmp, ""); - } - break; + case 'd': + if (folder->ff->nd->desc != NULL) { + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, folder->ff->nd->desc); + } + else { + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, ""); + } + break; } return (src); } #endif /* USE_NNTP */ -static void add_folder (MUTTMENU *m, struct browser_state *state, - const char *name, const struct stat *s, - void *data, int new) +static void add_folder (MUTTMENU * m, struct browser_state *state, + const char *name, const struct stat *s, + void *data, int new) { - if (state->entrylen == state->entrymax) - { + if (state->entrylen == state->entrymax) { /* need to allocate more space */ safe_realloc (&state->entry, - sizeof (struct folder_file) * (state->entrymax += 256)); + sizeof (struct folder_file) * (state->entrymax += 256)); memset (&state->entry[state->entrylen], 0, - sizeof (struct folder_file) * 256); + sizeof (struct folder_file) * 256); if (m) m->data = state->entry; } - if (s != NULL) - { + if (s != NULL) { (state->entry)[state->entrylen].mode = s->st_mode; (state->entry)[state->entrylen].mtime = s->st_mtime; (state->entry)[state->entrylen].size = s->st_size; - + (state->entry)[state->entrylen].st = safe_malloc (sizeof (struct stat)); memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat)); } @@ -465,11 +457,13 @@ static void add_folder (MUTTMENU *m, struct browser_state *state, (state->entrylen)++; } -static void init_state (struct browser_state *state, MUTTMENU *menu) +static void init_state (struct browser_state *state, MUTTMENU * menu) { state->entrylen = 0; state->entrymax = 256; - state->entry = (struct folder_file *) safe_calloc (state->entrymax, sizeof (struct folder_file)); + state->entry = + (struct folder_file *) safe_calloc (state->entrymax, + sizeof (struct folder_file)); #ifdef USE_IMAP state->imap_browse = 0; #endif @@ -478,12 +472,11 @@ static void init_state (struct browser_state *state, MUTTMENU *menu) } /* get list of all files/newsgroups with mask */ -static int examine_directory (MUTTMENU *menu, struct browser_state *state, - char *d, const char *prefix) +static int examine_directory (MUTTMENU * menu, struct browser_state *state, + char *d, const char *prefix) { #ifdef USE_NNTP - if (option (OPTNEWS)) - { + if (option (OPTNEWS)) { LIST *tmp; NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; @@ -491,84 +484,78 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state, /* mutt_buffy_check (0); */ init_state (state, menu); - for (tmp = news->list; tmp; tmp = tmp->next) - { - if (!(data = (NNTP_DATA *)tmp->data)) - continue; + for (tmp = news->list; tmp; tmp = tmp->next) { + if (!(data = (NNTP_DATA *) tmp->data)) + continue; if (prefix && *prefix && strncmp (prefix, data->group, - strlen (prefix)) != 0) - continue; + strlen (prefix)) != 0) + continue; if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not)) - continue; + continue; add_folder (menu, state, data->group, NULL, data, data->new); } } else #endif /* USE_NNTP */ { - struct stat s; - DIR *dp; - struct dirent *de; - char buffer[_POSIX_PATH_MAX + SHORT_STRING]; - BUFFY *tmp; + struct stat s; + DIR *dp; + struct dirent *de; + char buffer[_POSIX_PATH_MAX + SHORT_STRING]; + BUFFY *tmp; + + while (stat (d, &s) == -1) { + if (errno == ENOENT) { + /* The last used directory is deleted, try to use the parent dir. */ + char *c = strrchr (d, '/'); + + if (c && (c > d)) { + *c = 0; + continue; + } + } + mutt_perror (d); + return (-1); + } - while (stat (d, &s) == -1) - { - if (errno == ENOENT) - { - /* The last used directory is deleted, try to use the parent dir. */ - char *c = strrchr (d, '/'); + if (!S_ISDIR (s.st_mode)) { + mutt_error (_("%s is not a directory."), d); + return (-1); + } - if (c && (c > d)) - { - *c = 0; - continue; - } + mutt_buffy_check (0); + + if ((dp = opendir (d)) == NULL) { + mutt_perror (d); + return (-1); } - mutt_perror (d); - return (-1); - } - if (!S_ISDIR (s.st_mode)) - { - mutt_error (_("%s is not a directory."), d); - return (-1); - } + init_state (state, menu); - mutt_buffy_check (0); + while ((de = readdir (dp)) != NULL) { + if (mutt_strcmp (de->d_name, ".") == 0) + continue; /* we don't need . */ - if ((dp = opendir (d)) == NULL) - { - mutt_perror (d); - return (-1); - } + if (prefix && *prefix + && mutt_strncmp (prefix, de->d_name, mutt_strlen (prefix)) != 0) + continue; + if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) + continue; - init_state (state, menu); + mutt_concat_path (buffer, d, de->d_name, sizeof (buffer)); + if (lstat (buffer, &s) == -1) + continue; - while ((de = readdir (dp)) != NULL) - { - if (mutt_strcmp (de->d_name, ".") == 0) - continue; /* we don't need . */ - - if (prefix && *prefix && mutt_strncmp (prefix, de->d_name, mutt_strlen (prefix)) != 0) - continue; - if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) - continue; - - mutt_concat_path (buffer, d, de->d_name, sizeof (buffer)); - if (lstat (buffer, &s) == -1) - continue; - - if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) && - (! S_ISLNK (s.st_mode))) - continue; - - tmp = Incoming; - while (tmp && mutt_strcmp (buffer, tmp->path)) - tmp = tmp->next; - add_folder (menu, state, de->d_name, &s, NULL, (tmp) ? tmp->new : 0); - } - closedir (dp); + if ((!S_ISREG (s.st_mode)) && (!S_ISDIR (s.st_mode)) && + (!S_ISLNK (s.st_mode))) + continue; + + tmp = Incoming; + while (tmp && mutt_strcmp (buffer, tmp->path)) + tmp = tmp->next; + add_folder (menu, state, de->d_name, &s, NULL, (tmp) ? tmp->new : 0); + } + closedir (dp); } draw_sidebar (CurrentMenu); browser_sort (state); @@ -576,14 +563,13 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state, } /* get list of mailboxes/subscribed newsgroups */ -static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) +static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) { struct stat s; char buffer[LONG_STRING]; #ifdef USE_NNTP - if (option (OPTNEWS)) - { + if (option (OPTNEWS)) { LIST *tmp; NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; @@ -591,11 +577,14 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) /* mutt_buffy_check (0); */ init_state (state, menu); - for (tmp = news->list; tmp; tmp = tmp->next) - { + for (tmp = news->list; tmp; tmp = tmp->next) { if ((data = (NNTP_DATA *) tmp->data) != NULL && (data->new || - (data->subscribed && (!option (OPTSHOWONLYUNREAD) || data->unread)))) - add_folder (menu, state, data->group, NULL, data, data->new); + (data->subscribed + && + (!option + (OPTSHOWONLYUNREAD) + || data->unread)))) + add_folder (menu, state, data->group, NULL, data, data->new); } } else @@ -609,37 +598,33 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) init_state (state, menu); - do - { + do { #ifdef USE_IMAP - if (mx_is_imap (tmp->path)) - { - add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); - continue; + if (mx_is_imap (tmp->path)) { + add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); + continue; } #endif #ifdef USE_POP - if (mx_is_pop (tmp->path)) - { - add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); - continue; + if (mx_is_pop (tmp->path)) { + add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); + continue; } #endif #ifdef USE_NNTP - if (mx_is_nntp (tmp->path)) - { - add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); - continue; + if (mx_is_nntp (tmp->path)) { + add_folder (menu, state, tmp->path, NULL, NULL, tmp->new); + continue; } #endif if (lstat (tmp->path, &s) == -1) - continue; + continue; - if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) && - (! S_ISLNK (s.st_mode))) - continue; - - strfcpy (buffer, NONULL(tmp->path), sizeof (buffer)); + if ((!S_ISREG (s.st_mode)) && (!S_ISDIR (s.st_mode)) && + (!S_ISLNK (s.st_mode))) + continue; + + strfcpy (buffer, NONULL (tmp->path), sizeof (buffer)); mutt_pretty_mailbox (buffer); add_folder (menu, state, buffer, &s, NULL, tmp->new); @@ -650,40 +635,42 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) return 0; } -static int select_file_search (MUTTMENU *menu, regex_t *re, int n) +static int select_file_search (MUTTMENU * menu, regex_t * re, int n) { #ifdef USE_NNTP if (option (OPTNEWS)) - return (regexec (re, ((struct folder_file *) menu->data)[n].desc, 0, NULL, 0)); + return (regexec + (re, ((struct folder_file *) menu->data)[n].desc, 0, NULL, 0)); #endif - return (regexec (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0)); + return (regexec + (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0)); } -static void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num) +static void folder_entry (char *s, size_t slen, MUTTMENU * menu, int num) { FOLDER folder; folder.ff = &((struct folder_file *) menu->data)[num]; folder.num = num; - + #ifdef USE_NNTP if (option (OPTNEWS)) - mutt_FormatString (s, slen, NONULL(GroupFormat), newsgroup_format_str, - (unsigned long) &folder, M_FORMAT_ARROWCURSOR); + mutt_FormatString (s, slen, NONULL (GroupFormat), newsgroup_format_str, + (unsigned long) &folder, M_FORMAT_ARROWCURSOR); else #endif - mutt_FormatString (s, slen, NONULL(FolderFormat), folder_format_str, - (unsigned long) &folder, M_FORMAT_ARROWCURSOR); + mutt_FormatString (s, slen, NONULL (FolderFormat), folder_format_str, + (unsigned long) &folder, M_FORMAT_ARROWCURSOR); } -static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title, - size_t titlelen, int buffy) +static void init_menu (struct browser_state *state, MUTTMENU * menu, + char *title, size_t titlelen, int buffy) { char path[_POSIX_PATH_MAX]; menu->max = state->entrylen; - if(menu->current >= menu->max) + if (menu->current >= menu->max) menu->current = menu->max - 1; if (menu->current < 0) menu->current = 0; @@ -693,51 +680,52 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title, menu->tagged = 0; #ifdef USE_NNTP - if (option (OPTNEWS)) - { + if (option (OPTNEWS)) { if (buffy) snprintf (title, titlelen, "%s", _("Subscribed newsgroups")); else snprintf (title, titlelen, _("Newsgroups on server [%s]"), - CurrentNewsSrv->conn->account.host); + CurrentNewsSrv->conn->account.host); } else #endif if (buffy) snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0)); - else - { + else { strfcpy (path, LastDir, sizeof (path)); mutt_pretty_mailbox (path); #ifdef USE_IMAP - if (state->imap_browse && option (OPTIMAPLSUB)) - snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"), - path, NONULL (Mask.pattern)); - else + if (state->imap_browse && option (OPTIMAPLSUB)) + snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"), + path, NONULL (Mask.pattern)); + else #endif - snprintf (title, titlelen, _("Directory [%s], File mask: %s"), - path, NONULL(Mask.pattern)); + snprintf (title, titlelen, _("Directory [%s], File mask: %s"), + path, NONULL (Mask.pattern)); } menu->redraw = REDRAW_FULL; } -static int file_tag (MUTTMENU *menu, int n, int m) +static int file_tag (MUTTMENU * menu, int n, int m) { - struct folder_file *ff = &(((struct folder_file *)menu->data)[n]); + struct folder_file *ff = &(((struct folder_file *) menu->data)[n]); int ot; - if (S_ISDIR (ff->mode) || (S_ISLNK (ff->mode) && link_is_dir (LastDir, ff->name))) - { + + if (S_ISDIR (ff->mode) + || (S_ISLNK (ff->mode) && link_is_dir (LastDir, ff->name))) { mutt_error _("Can't attach a directory!"); + return 0; } - + ot = ff->tagged; ff->tagged = (m >= 0 ? m : !ff->tagged); - + return ff->tagged - ot; } -void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *numfiles) +void _mutt_select_file (char *f, size_t flen, int flags, char ***files, + int *numfiles) { char buf[_POSIX_PATH_MAX]; char prefix[_POSIX_PATH_MAX] = ""; @@ -747,99 +735,87 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num MUTTMENU *menu; struct stat st; int i, killPrefix = 0; - int multiple = (flags & M_SEL_MULTI) ? 1 : 0; - int folder = (flags & M_SEL_FOLDER) ? 1 : 0; - int buffy = (flags & M_SEL_BUFFY) ? 1 : 0; + int multiple = (flags & M_SEL_MULTI) ? 1 : 0; + int folder = (flags & M_SEL_FOLDER) ? 1 : 0; + int buffy = (flags & M_SEL_BUFFY) ? 1 : 0; buffy = buffy && folder; - + memset (&state, 0, sizeof (struct browser_state)); if (!folder) strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup)); #ifdef USE_NNTP - if (option (OPTNEWS)) - { + if (option (OPTNEWS)) { if (*f) strfcpy (prefix, f, sizeof (prefix)); - else - { + else { LIST *list; /* default state for news reader mode is browse subscribed newsgroups */ buffy = 0; - for (list = CurrentNewsSrv->list; list; list = list->next) - { - NNTP_DATA *data = (NNTP_DATA *) list->data; + for (list = CurrentNewsSrv->list; list; list = list->next) { + NNTP_DATA *data = (NNTP_DATA *) list->data; - if (data && data->subscribed) - { - buffy = 1; - break; - } + if (data && data->subscribed) { + buffy = 1; + break; + } } } } else #endif - if (*f) - { + if (*f) { mutt_expand_path (f, flen); #ifdef USE_IMAP - if (mx_is_imap (f)) - { + if (mx_is_imap (f)) { init_state (&state, NULL); state.imap_browse = 1; imap_browse (f, &state); strfcpy (LastDir, state.folder, sizeof (LastDir)); } - else - { + else { #endif - for (i = mutt_strlen (f) - 1; i > 0 && f[i] != '/' ; i--); - if (i > 0) - { - if (f[0] == '/') - { - if (i > sizeof (LastDir) - 1) i = sizeof (LastDir) - 1; - strncpy (LastDir, f, i); - LastDir[i] = 0; + for (i = mutt_strlen (f) - 1; i > 0 && f[i] != '/'; i--); + if (i > 0) { + if (f[0] == '/') { + if (i > sizeof (LastDir) - 1) + i = sizeof (LastDir) - 1; + strncpy (LastDir, f, i); + LastDir[i] = 0; + } + else { + getcwd (LastDir, sizeof (LastDir)); + safe_strcat (LastDir, sizeof (LastDir), "/"); + safe_strncat (LastDir, sizeof (LastDir), f, i); + } } - else - { - getcwd (LastDir, sizeof (LastDir)); - safe_strcat (LastDir, sizeof (LastDir), "/"); - safe_strncat (LastDir, sizeof (LastDir), f, i); + else { + if (f[0] == '/') + strcpy (LastDir, "/"); /* __STRCPY_CHECKED__ */ + else + getcwd (LastDir, sizeof (LastDir)); } - } - else - { - if (f[0] == '/') - strcpy (LastDir, "/"); /* __STRCPY_CHECKED__ */ - else - getcwd (LastDir, sizeof (LastDir)); - } - if (i <= 0 && f[0] != '/') - strfcpy (prefix, f, sizeof (prefix)); - else - strfcpy (prefix, f + i + 1, sizeof (prefix)); - killPrefix = 1; + if (i <= 0 && f[0] != '/') + strfcpy (prefix, f, sizeof (prefix)); + else + strfcpy (prefix, f + i + 1, sizeof (prefix)); + killPrefix = 1; #ifdef USE_IMAP } #endif } - else - { + else { if (!folder) getcwd (LastDir, sizeof (LastDir)); else if (!LastDir[0]) - strfcpy (LastDir, NONULL(Maildir), sizeof (LastDir)); - + strfcpy (LastDir, NONULL (Maildir), sizeof (LastDir)); + #ifdef USE_IMAP - if (!buffy && mx_is_imap (LastDir)) - { + if (!buffy && mx_is_imap (LastDir)) { init_state (&state, NULL); state.imap_browse = 1; imap_browse (LastDir, &state); @@ -849,8 +825,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num *f = 0; - if (buffy) - { + if (buffy) { if (examine_mailboxes (NULL, &state) == -1) goto bail; } @@ -858,8 +833,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num #ifdef USE_IMAP if (!state.imap_browse) #endif - if (examine_directory (NULL, &state, LastDir, prefix) == -1) - goto bail; + if (examine_directory (NULL, &state, LastDir, prefix) == -1) + goto bail; menu = mutt_new_menu (); menu->menu = MENU_FOLDER; @@ -872,573 +847,537 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER, #ifdef USE_NNTP - (option (OPTNEWS)) ? FolderNewsHelp : + (option (OPTNEWS)) ? FolderNewsHelp : #endif - FolderHelp); + FolderHelp); init_menu (&state, menu, title, sizeof (title), buffy); - FOREVER - { - switch (i = mutt_menuLoop (menu)) - { - case OP_GENERIC_SELECT_ENTRY: + FOREVER { + switch (i = mutt_menuLoop (menu)) { + case OP_GENERIC_SELECT_ENTRY: - if (!state.entrylen) - { - mutt_error _("No files match the file mask"); - break; - } + if (!state.entrylen) { + mutt_error _("No files match the file mask"); + + break; + } - if (S_ISDIR (state.entry[menu->current].mode) || - (S_ISLNK (state.entry[menu->current].mode) && - link_is_dir (LastDir, state.entry[menu->current].name)) + if (S_ISDIR (state.entry[menu->current].mode) || + (S_ISLNK (state.entry[menu->current].mode) && + link_is_dir (LastDir, state.entry[menu->current].name)) #ifdef USE_IMAP - || state.entry[menu->current].inferiors + || state.entry[menu->current].inferiors #endif - ) - { - /* make sure this isn't a MH or maildir mailbox */ - if (buffy) - { - strfcpy (buf, state.entry[menu->current].name, sizeof (buf)); - mutt_expand_path (buf, sizeof (buf)); - } + ) { + /* make sure this isn't a MH or maildir mailbox */ + if (buffy) { + strfcpy (buf, state.entry[menu->current].name, sizeof (buf)); + mutt_expand_path (buf, sizeof (buf)); + } #ifdef USE_IMAP - else if (state.imap_browse) - { - strfcpy (buf, state.entry[menu->current].name, sizeof (buf)); - } + else if (state.imap_browse) { + strfcpy (buf, state.entry[menu->current].name, sizeof (buf)); + } #endif - else - mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf)); + else + mutt_concat_path (buf, LastDir, state.entry[menu->current].name, + sizeof (buf)); - if ((mx_get_magic (buf) <= 0) + if ((mx_get_magic (buf) <= 0) #ifdef USE_IMAP - || state.entry[menu->current].inferiors + || state.entry[menu->current].inferiors #endif - ) - { - char OldLastDir[_POSIX_PATH_MAX]; - - /* save the old directory */ - strfcpy (OldLastDir, LastDir, sizeof (OldLastDir)); - - if (mutt_strcmp (state.entry[menu->current].name, "..") == 0) - { - if (mutt_strcmp ("..", LastDir + mutt_strlen (LastDir) - 2) == 0) - strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ - else - { - char *p = strrchr (LastDir + 1, '/'); - - if (p) - *p = 0; - else - { - if (LastDir[0] == '/') - LastDir[1] = 0; - else - strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ - } - } - } - else if (buffy) - { - strfcpy (LastDir, state.entry[menu->current].name, sizeof (LastDir)); - mutt_expand_path (LastDir, sizeof (LastDir)); - } + ) { + char OldLastDir[_POSIX_PATH_MAX]; + + /* save the old directory */ + strfcpy (OldLastDir, LastDir, sizeof (OldLastDir)); + + if (mutt_strcmp (state.entry[menu->current].name, "..") == 0) { + if (mutt_strcmp ("..", LastDir + mutt_strlen (LastDir) - 2) == 0) + strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ + else { + char *p = strrchr (LastDir + 1, '/'); + + if (p) + *p = 0; + else { + if (LastDir[0] == '/') + LastDir[1] = 0; + else + strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ + } + } + } + else if (buffy) { + strfcpy (LastDir, state.entry[menu->current].name, + sizeof (LastDir)); + mutt_expand_path (LastDir, sizeof (LastDir)); + } #ifdef USE_IMAP - else if (state.imap_browse) - { - int n; - ciss_url_t url; - - strfcpy (LastDir, state.entry[menu->current].name, - sizeof (LastDir)); - /* tack on delimiter here */ - n = strlen (LastDir)+1; - - /* special case "" needs no delimiter */ - url_parse_ciss (&url, state.entry[menu->current].name); - if (url.path && - (state.entry[menu->current].delim != '\0') && - (n < sizeof (LastDir))) - { - LastDir[n] = '\0'; - LastDir[n-1] = state.entry[menu->current].delim; - } - } + else if (state.imap_browse) { + int n; + ciss_url_t url; + + strfcpy (LastDir, state.entry[menu->current].name, + sizeof (LastDir)); + /* tack on delimiter here */ + n = strlen (LastDir) + 1; + + /* special case "" needs no delimiter */ + url_parse_ciss (&url, state.entry[menu->current].name); + if (url.path && + (state.entry[menu->current].delim != '\0') && + (n < sizeof (LastDir))) { + LastDir[n] = '\0'; + LastDir[n - 1] = state.entry[menu->current].delim; + } + } #endif - else - { - char tmp[_POSIX_PATH_MAX]; - mutt_concat_path (tmp, LastDir, state.entry[menu->current].name, sizeof (tmp)); - strfcpy (LastDir, tmp, sizeof (LastDir)); - } - - destroy_state (&state); - if (killPrefix) - { - prefix[0] = 0; - killPrefix = 0; - } - buffy = 0; + else { + char tmp[_POSIX_PATH_MAX]; + + mutt_concat_path (tmp, LastDir, state.entry[menu->current].name, + sizeof (tmp)); + strfcpy (LastDir, tmp, sizeof (LastDir)); + } + + destroy_state (&state); + if (killPrefix) { + prefix[0] = 0; + killPrefix = 0; + } + buffy = 0; #ifdef USE_IMAP - if (state.imap_browse) - { - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - } - else + if (state.imap_browse) { + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + } + else #endif - if (examine_directory (menu, &state, LastDir, prefix) == -1) - { - /* try to restore the old values */ - strfcpy (LastDir, OldLastDir, sizeof (LastDir)); - if (examine_directory (menu, &state, LastDir, prefix) == -1) - { - strfcpy (LastDir, NONULL(Homedir), sizeof (LastDir)); - goto bail; - } - } - menu->current = 0; - menu->top = 0; - init_menu (&state, menu, title, sizeof (title), buffy); - break; - } - } + if (examine_directory (menu, &state, LastDir, prefix) == -1) { + /* try to restore the old values */ + strfcpy (LastDir, OldLastDir, sizeof (LastDir)); + if (examine_directory (menu, &state, LastDir, prefix) == -1) { + strfcpy (LastDir, NONULL (Homedir), sizeof (LastDir)); + goto bail; + } + } + menu->current = 0; + menu->top = 0; + init_menu (&state, menu, title, sizeof (title), buffy); + break; + } + } #ifdef USE_NNTP - if (buffy || option (OPTNEWS)) /* news have not path */ + if (buffy || option (OPTNEWS)) /* news have not path */ #else - if (buffy) + if (buffy) #endif - { - strfcpy (f, state.entry[menu->current].name, flen); - mutt_expand_path (f, flen); - } + { + strfcpy (f, state.entry[menu->current].name, flen); + mutt_expand_path (f, flen); + } #ifdef USE_IMAP - else if (state.imap_browse) - strfcpy (f, state.entry[menu->current].name, flen); + else if (state.imap_browse) + strfcpy (f, state.entry[menu->current].name, flen); #endif - else - mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen); - - /* Fall through to OP_EXIT */ - - case OP_EXIT: - - if (multiple) - { - char **tfiles; - int i, j; - - if (menu->tagged) - { - *numfiles = menu->tagged; - tfiles = safe_calloc (*numfiles, sizeof (char *)); - for (i = 0, j = 0; i < state.entrylen; i++) - { - struct folder_file ff = state.entry[i]; - char full[_POSIX_PATH_MAX]; - if (ff.tagged) - { - mutt_concat_path (full, LastDir, ff.name, sizeof (full)); - mutt_expand_path (full, sizeof (full)); - tfiles[j++] = safe_strdup (full); - } - } - *files = tfiles; - } - else if (f[0]) /* no tagged entries. return selected entry */ - { - *numfiles = 1; - tfiles = safe_calloc (*numfiles, sizeof (char *)); - mutt_expand_path (f, flen); - tfiles[0] = safe_strdup (f); - *files = tfiles; - } - } - - destroy_state (&state); - mutt_menuDestroy (&menu); - goto bail; - - case OP_BROWSER_TELL: - if(state.entrylen) - mutt_message("%s", state.entry[menu->current].name); - break; + else + mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen); + + /* Fall through to OP_EXIT */ + + case OP_EXIT: + + if (multiple) { + char **tfiles; + int i, j; + + if (menu->tagged) { + *numfiles = menu->tagged; + tfiles = safe_calloc (*numfiles, sizeof (char *)); + for (i = 0, j = 0; i < state.entrylen; i++) { + struct folder_file ff = state.entry[i]; + char full[_POSIX_PATH_MAX]; + + if (ff.tagged) { + mutt_concat_path (full, LastDir, ff.name, sizeof (full)); + mutt_expand_path (full, sizeof (full)); + tfiles[j++] = safe_strdup (full); + } + } + *files = tfiles; + } + else if (f[0]) { /* no tagged entries. return selected entry */ + *numfiles = 1; + tfiles = safe_calloc (*numfiles, sizeof (char *)); + mutt_expand_path (f, flen); + tfiles[0] = safe_strdup (f); + *files = tfiles; + } + } + + destroy_state (&state); + mutt_menuDestroy (&menu); + goto bail; + + case OP_BROWSER_TELL: + if (state.entrylen) + mutt_message ("%s", state.entry[menu->current].name); + break; #ifdef USE_IMAP - case OP_BROWSER_TOGGLE_LSUB: - if (option (OPTIMAPLSUB)) - { - unset_option (OPTIMAPLSUB); - } - else - { - set_option (OPTIMAPLSUB); - } - mutt_ungetch (0, OP_CHECK_NEW); - break; - - case OP_CREATE_MAILBOX: - if (!state.imap_browse) - mutt_error (_("Create is only supported for IMAP mailboxes")); - else - { - imap_mailbox_create (LastDir); - /* TODO: find a way to detect if the new folder would appear in - * this window, and insert it without starting over. */ - destroy_state (&state); - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - menu->current = 0; - menu->top = 0; - init_menu (&state, menu, title, sizeof (title), buffy); - MAYBE_REDRAW (menu->redraw); - } - break; - - case OP_RENAME_MAILBOX: - if (!state.entry[menu->current].imap) - mutt_error (_("Rename is only supported for IMAP mailboxes")); - else - { - int nentry = menu->current; - - if (imap_mailbox_rename (state.entry[nentry].name) >= 0) { - destroy_state (&state); - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - menu->current = 0; - menu->top = 0; - init_menu (&state, menu, title, sizeof (title), buffy); - MAYBE_REDRAW (menu->redraw); - } - } - break; + case OP_BROWSER_TOGGLE_LSUB: + if (option (OPTIMAPLSUB)) { + unset_option (OPTIMAPLSUB); + } + else { + set_option (OPTIMAPLSUB); + } + mutt_ungetch (0, OP_CHECK_NEW); + break; + + case OP_CREATE_MAILBOX: + if (!state.imap_browse) + mutt_error (_("Create is only supported for IMAP mailboxes")); + else { + imap_mailbox_create (LastDir); + /* TODO: find a way to detect if the new folder would appear in + * this window, and insert it without starting over. */ + destroy_state (&state); + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + menu->current = 0; + menu->top = 0; + init_menu (&state, menu, title, sizeof (title), buffy); + MAYBE_REDRAW (menu->redraw); + } + break; + + case OP_RENAME_MAILBOX: + if (!state.entry[menu->current].imap) + mutt_error (_("Rename is only supported for IMAP mailboxes")); + else { + int nentry = menu->current; + + if (imap_mailbox_rename (state.entry[nentry].name) >= 0) { + destroy_state (&state); + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + menu->current = 0; + menu->top = 0; + init_menu (&state, menu, title, sizeof (title), buffy); + MAYBE_REDRAW (menu->redraw); + } + } + break; case OP_DELETE_MAILBOX: - if (!state.entry[menu->current].imap) - mutt_error (_("Delete is only supported for IMAP mailboxes")); - else - { - char msg[SHORT_STRING]; - IMAP_MBOX mx; - int nentry = menu->current; - - imap_parse_path (state.entry[nentry].name, &mx); - snprintf (msg, sizeof (msg), _("Really delete mailbox \"%s\"?"), - mx.mbox); - if (mutt_yesorno (msg, M_NO) == M_YES) - { - if (!imap_delete_mailbox (Context, mx)) - { - /* free the mailbox from the browser */ - FREE (&((state.entry)[nentry].name)); - FREE (&((state.entry)[nentry].desc)); - /* and move all other entries up */ - if (nentry+1 < state.entrylen) - memmove (state.entry + nentry, state.entry + nentry + 1, - sizeof (struct folder_file) * (state.entrylen - (nentry+1))); - state.entrylen--; - mutt_message _("Mailbox deleted."); - init_menu (&state, menu, title, sizeof (title), buffy); - MAYBE_REDRAW (menu->redraw); - } - } - else - mutt_message _("Mailbox not deleted."); - FREE (&mx.mbox); + if (!state.entry[menu->current].imap) + mutt_error (_("Delete is only supported for IMAP mailboxes")); + else { + char msg[SHORT_STRING]; + IMAP_MBOX mx; + int nentry = menu->current; + + imap_parse_path (state.entry[nentry].name, &mx); + snprintf (msg, sizeof (msg), _("Really delete mailbox \"%s\"?"), + mx.mbox); + if (mutt_yesorno (msg, M_NO) == M_YES) { + if (!imap_delete_mailbox (Context, mx)) { + /* free the mailbox from the browser */ + FREE (&((state.entry)[nentry].name)); + FREE (&((state.entry)[nentry].desc)); + /* and move all other entries up */ + if (nentry + 1 < state.entrylen) + memmove (state.entry + nentry, state.entry + nentry + 1, + sizeof (struct folder_file) * (state.entrylen - + (nentry + 1))); + state.entrylen--; + mutt_message _("Mailbox deleted."); + + init_menu (&state, menu, title, sizeof (title), buffy); + MAYBE_REDRAW (menu->redraw); + } } - break; + else + mutt_message _("Mailbox not deleted."); + FREE (&mx.mbox); + } + break; #endif - - case OP_CHANGE_DIRECTORY: + + case OP_CHANGE_DIRECTORY: #ifdef USE_NNTP - if (option (OPTNEWS)) - break; + if (option (OPTNEWS)) + break; #endif - strfcpy (buf, LastDir, sizeof (buf)); + strfcpy (buf, LastDir, sizeof (buf)); #ifdef USE_IMAP - if (!state.imap_browse) + if (!state.imap_browse) #endif - { - /* add '/' at the end of the directory name if not already there */ - int len=mutt_strlen(LastDir); - if (len && LastDir[len-1] != '/' && sizeof (buf) > len) - buf[len]='/'; - } - - if (mutt_get_field (_("Chdir to: "), buf, sizeof (buf), M_FILE) == 0 && - buf[0]) - { - buffy = 0; - mutt_expand_path (buf, sizeof (buf)); + { + /* add '/' at the end of the directory name if not already there */ + int len = mutt_strlen (LastDir); + + if (len && LastDir[len - 1] != '/' && sizeof (buf) > len) + buf[len] = '/'; + } + + if (mutt_get_field (_("Chdir to: "), buf, sizeof (buf), M_FILE) == 0 && + buf[0]) { + buffy = 0; + mutt_expand_path (buf, sizeof (buf)); #ifdef USE_IMAP - if (mx_is_imap (buf)) - { - strfcpy (LastDir, buf, sizeof (LastDir)); - destroy_state (&state); - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - menu->current = 0; - menu->top = 0; - init_menu (&state, menu, title, sizeof (title), buffy); - } - else + if (mx_is_imap (buf)) { + strfcpy (LastDir, buf, sizeof (LastDir)); + destroy_state (&state); + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + menu->current = 0; + menu->top = 0; + init_menu (&state, menu, title, sizeof (title), buffy); + } + else #endif - if (stat (buf, &st) == 0) - { - if (S_ISDIR (st.st_mode)) - { - destroy_state (&state); - if (examine_directory (menu, &state, buf, prefix) == 0) - strfcpy (LastDir, buf, sizeof (LastDir)); - else - { - mutt_error _("Error scanning directory."); - if (examine_directory (menu, &state, LastDir, prefix) == -1) - { - mutt_menuDestroy (&menu); - goto bail; - } - } - menu->current = 0; - menu->top = 0; - init_menu (&state, menu, title, sizeof (title), buffy); - } - else - mutt_error (_("%s is not a directory."), buf); - } - else - mutt_perror (buf); - } - MAYBE_REDRAW (menu->redraw); - break; - - case OP_ENTER_MASK: - - strfcpy (buf, NONULL(Mask.pattern), sizeof (buf)); - if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) - { - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); - char *s = buf; - int not = 0, err; - - buffy = 0; - /* assume that the user wants to see everything */ - if (!buf[0]) - strfcpy (buf, ".", sizeof (buf)); - SKIPWS (s); - if (*s == '!') - { - s++; - SKIPWS (s); - not = 1; - } - - if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) - { - regerror (err, rx, buf, sizeof (buf)); - regfree (rx); - FREE (&rx); - mutt_error ("%s", buf); - } - else - { - mutt_str_replace (&Mask.pattern, buf); - regfree (Mask.rx); - FREE (&Mask.rx); - Mask.rx = rx; - Mask.not = not; - - destroy_state (&state); + if (stat (buf, &st) == 0) { + if (S_ISDIR (st.st_mode)) { + destroy_state (&state); + if (examine_directory (menu, &state, buf, prefix) == 0) + strfcpy (LastDir, buf, sizeof (LastDir)); + else { + mutt_error _("Error scanning directory."); + + if (examine_directory (menu, &state, LastDir, prefix) == -1) { + mutt_menuDestroy (&menu); + goto bail; + } + } + menu->current = 0; + menu->top = 0; + init_menu (&state, menu, title, sizeof (title), buffy); + } + else + mutt_error (_("%s is not a directory."), buf); + } + else + mutt_perror (buf); + } + MAYBE_REDRAW (menu->redraw); + break; + + case OP_ENTER_MASK: + + strfcpy (buf, NONULL (Mask.pattern), sizeof (buf)); + if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) { + regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + char *s = buf; + int not = 0, err; + + buffy = 0; + /* assume that the user wants to see everything */ + if (!buf[0]) + strfcpy (buf, ".", sizeof (buf)); + SKIPWS (s); + if (*s == '!') { + s++; + SKIPWS (s); + not = 1; + } + + if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { + regerror (err, rx, buf, sizeof (buf)); + regfree (rx); + FREE (&rx); + mutt_error ("%s", buf); + } + else { + mutt_str_replace (&Mask.pattern, buf); + regfree (Mask.rx); + FREE (&Mask.rx); + Mask.rx = rx; + Mask.not = not; + + destroy_state (&state); #ifdef USE_IMAP - if (state.imap_browse) - { - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - init_menu (&state, menu, title, sizeof (title), buffy); - } - else + if (state.imap_browse) { + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + init_menu (&state, menu, title, sizeof (title), buffy); + } + else #endif - if (examine_directory (menu, &state, LastDir, NULL) == 0) - init_menu (&state, menu, title, sizeof (title), buffy); - else - { - mutt_error _("Error scanning directory."); - mutt_menuDestroy (&menu); - goto bail; - } - killPrefix = 0; - if (!state.entrylen) - { - mutt_error _("No files match the file mask"); - break; - } - } - } - MAYBE_REDRAW (menu->redraw); - break; - - case OP_SORT: - case OP_SORT_REVERSE: - - { - int resort = 1; - int reverse = (i == OP_SORT_REVERSE); - - switch (mutt_multi_choice ((reverse) ? - _("Reverse sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? ") : - _("Sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? "), - _("dazn"))) - { - case -1: /* abort */ - resort = 0; - break; - - case 1: /* (d)ate */ - BrowserSort = SORT_DATE; - break; - - case 2: /* (a)lpha */ - BrowserSort = SORT_SUBJECT; - break; - - case 3: /* si(z)e */ - BrowserSort = SORT_SIZE; - break; - - case 4: /* do(n)'t sort */ - BrowserSort = SORT_ORDER; - resort = 0; - break; - } - if (resort) - { - BrowserSort |= reverse ? SORT_REVERSE : 0; - browser_sort (&state); - menu->redraw = REDRAW_FULL; - } - break; - } - - case OP_TOGGLE_MAILBOXES: - buffy = 1 - buffy; - - case OP_CHECK_NEW: - destroy_state (&state); - prefix[0] = 0; - killPrefix = 0; - - if (buffy) - { - if (examine_mailboxes (menu, &state) == -1) - goto bail; - } + if (examine_directory (menu, &state, LastDir, NULL) == 0) + init_menu (&state, menu, title, sizeof (title), buffy); + else { + mutt_error _("Error scanning directory."); + + mutt_menuDestroy (&menu); + goto bail; + } + killPrefix = 0; + if (!state.entrylen) { + mutt_error _("No files match the file mask"); + + break; + } + } + } + MAYBE_REDRAW (menu->redraw); + break; + + case OP_SORT: + case OP_SORT_REVERSE: + + { + int resort = 1; + int reverse = (i == OP_SORT_REVERSE); + + switch (mutt_multi_choice ((reverse) ? + _ + ("Reverse sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? ") + : + _ + ("Sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? "), + _("dazn"))) { + case -1: /* abort */ + resort = 0; + break; + + case 1: /* (d)ate */ + BrowserSort = SORT_DATE; + break; + + case 2: /* (a)lpha */ + BrowserSort = SORT_SUBJECT; + break; + + case 3: /* si(z)e */ + BrowserSort = SORT_SIZE; + break; + + case 4: /* do(n)'t sort */ + BrowserSort = SORT_ORDER; + resort = 0; + break; + } + if (resort) { + BrowserSort |= reverse ? SORT_REVERSE : 0; + browser_sort (&state); + menu->redraw = REDRAW_FULL; + } + break; + } + + case OP_TOGGLE_MAILBOXES: + buffy = 1 - buffy; + + case OP_CHECK_NEW: + destroy_state (&state); + prefix[0] = 0; + killPrefix = 0; + + if (buffy) { + if (examine_mailboxes (menu, &state) == -1) + goto bail; + } #ifdef USE_IMAP - else if (mx_is_imap (LastDir)) - { - init_state (&state, NULL); - state.imap_browse = 1; - imap_browse (LastDir, &state); - menu->data = state.entry; - } + else if (mx_is_imap (LastDir)) { + init_state (&state, NULL); + state.imap_browse = 1; + imap_browse (LastDir, &state); + menu->data = state.entry; + } #endif - else if (examine_directory (menu, &state, LastDir, prefix) == -1) - goto bail; - init_menu (&state, menu, title, sizeof (title), buffy); - break; - - case OP_BUFFY_LIST: - mutt_buffy_list (); - break; - - case OP_BROWSER_NEW_FILE: - - snprintf (buf, sizeof (buf), "%s/", LastDir); - if (mutt_get_field (_("New file name: "), buf, sizeof (buf), M_FILE) == 0) - { - strfcpy (f, buf, flen); - destroy_state (&state); - mutt_menuDestroy (&menu); - goto bail; - } - MAYBE_REDRAW (menu->redraw); - break; - - case OP_BROWSER_VIEW_FILE: - if (!state.entrylen) - { - mutt_error _("No files match the file mask"); - break; - } + else if (examine_directory (menu, &state, LastDir, prefix) == -1) + goto bail; + init_menu (&state, menu, title, sizeof (title), buffy); + break; + + case OP_BUFFY_LIST: + mutt_buffy_list (); + break; + + case OP_BROWSER_NEW_FILE: + + snprintf (buf, sizeof (buf), "%s/", LastDir); + if (mutt_get_field (_("New file name: "), buf, sizeof (buf), M_FILE) == + 0) { + strfcpy (f, buf, flen); + destroy_state (&state); + mutt_menuDestroy (&menu); + goto bail; + } + MAYBE_REDRAW (menu->redraw); + break; + + case OP_BROWSER_VIEW_FILE: + if (!state.entrylen) { + mutt_error _("No files match the file mask"); + + break; + } #ifdef USE_IMAP - if (state.entry[menu->current].selectable) - { - strfcpy (f, state.entry[menu->current].name, flen); - destroy_state (&state); - mutt_menuDestroy (&menu); - goto bail; - } - else + if (state.entry[menu->current].selectable) { + strfcpy (f, state.entry[menu->current].name, flen); + destroy_state (&state); + mutt_menuDestroy (&menu); + goto bail; + } + else #endif - if (S_ISDIR (state.entry[menu->current].mode) || - (S_ISLNK (state.entry[menu->current].mode) && - link_is_dir (LastDir, state.entry[menu->current].name))) - { - mutt_error _("Can't view a directory"); - break; - } - else - { - BODY *b; - char buf[_POSIX_PATH_MAX]; - - mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf)); - b = mutt_make_file_attach (buf); - if (b != NULL) - { - mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0); - mutt_free_body (&b); - menu->redraw = REDRAW_FULL; - } - else - mutt_error _("Error trying to view file"); - } - break; + if (S_ISDIR (state.entry[menu->current].mode) || + (S_ISLNK (state.entry[menu->current].mode) && + link_is_dir (LastDir, state.entry[menu->current].name))) { + mutt_error _("Can't view a directory"); + + break; + } + else { + BODY *b; + char buf[_POSIX_PATH_MAX]; + + mutt_concat_path (buf, LastDir, state.entry[menu->current].name, + sizeof (buf)); + b = mutt_make_file_attach (buf); + if (b != NULL) { + mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0); + mutt_free_body (&b); + menu->redraw = REDRAW_FULL; + } + else + mutt_error _("Error trying to view file"); + } + break; #ifdef USE_NNTP - case OP_CATCHUP: - case OP_UNCATCHUP: - if (option (OPTNEWS)) - { - struct folder_file *f = &state.entry[menu->current]; - NNTP_DATA *nd; - - if (i == OP_CATCHUP) - nd = mutt_newsgroup_catchup (CurrentNewsSrv, f->name); - else - nd = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name); - - if (nd) - { + case OP_CATCHUP: + case OP_UNCATCHUP: + if (option (OPTNEWS)) { + struct folder_file *f = &state.entry[menu->current]; + NNTP_DATA *nd; + + if (i == OP_CATCHUP) + nd = mutt_newsgroup_catchup (CurrentNewsSrv, f->name); + else + nd = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name); + + if (nd) { /* FOLDER folder; struct folder_file ff; char buffer[_POSIX_PATH_MAX + SHORT_STRING]; @@ -1453,97 +1392,90 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num newsgroup_format_str, (unsigned long) &folder, M_FORMAT_ARROWCURSOR); f->desc = safe_strdup (buffer); */ - if (menu->current + 1 < menu->max) - menu->current++; - menu->redraw = REDRAW_MOTION_RESYNCH; - } - } - break; - - case OP_LOAD_ACTIVE: - if (!option (OPTNEWS)) - break; - - { - LIST *tmp; - NNTP_DATA *data; - - for (tmp = CurrentNewsSrv->list; tmp; tmp = tmp->next) - { - if ((data = (NNTP_DATA *)tmp->data)) - data->deleted = 1; - } - } - nntp_get_active (CurrentNewsSrv); - - destroy_state (&state); - if (buffy) - examine_mailboxes (menu, &state); - else - examine_directory (menu, &state, NULL, NULL); - init_menu (&state, menu, title, sizeof (title), buffy); - break; + if (menu->current + 1 < menu->max) + menu->current++; + menu->redraw = REDRAW_MOTION_RESYNCH; + } + } + break; + + case OP_LOAD_ACTIVE: + if (!option (OPTNEWS)) + break; + + { + LIST *tmp; + NNTP_DATA *data; + + for (tmp = CurrentNewsSrv->list; tmp; tmp = tmp->next) { + if ((data = (NNTP_DATA *) tmp->data)) + data->deleted = 1; + } + } + nntp_get_active (CurrentNewsSrv); + + destroy_state (&state); + if (buffy) + examine_mailboxes (menu, &state); + else + examine_directory (menu, &state, NULL, NULL); + init_menu (&state, menu, title, sizeof (title), buffy); + break; #endif /* USE_NNTP */ #if defined USE_IMAP || defined USE_NNTP - case OP_BROWSER_SUBSCRIBE: - case OP_BROWSER_UNSUBSCRIBE: + case OP_BROWSER_SUBSCRIBE: + case OP_BROWSER_UNSUBSCRIBE: #endif #ifdef USE_NNTP - case OP_SUBSCRIBE_PATTERN: - case OP_UNSUBSCRIBE_PATTERN: - if (option (OPTNEWS)) - { - regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); - char *s = buf; - int j = menu->current; - NNTP_DATA *nd; - NNTP_SERVER *news = CurrentNewsSrv; - - if (i == OP_SUBSCRIBE_PATTERN || i == OP_UNSUBSCRIBE_PATTERN) - { - char tmp[STRING]; - int err; - - buf[0] = 0; - if (i == OP_SUBSCRIBE_PATTERN) - snprintf (tmp, sizeof (tmp), _("Subscribe pattern: ")); - else - snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: ")); - if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) - { - FREE (&rx); - break; - } - - if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) - { - regerror (err, rx, buf, sizeof (buf)); - regfree (rx); - FREE (&rx); - mutt_error ("%s", buf); - break; - } - menu->redraw = REDRAW_FULL; - j = 0; - } - else if (!state.entrylen) - { - mutt_error _("No newsgroups match the mask"); - break; - } - - for ( ; j < state.entrylen; j++) - { - struct folder_file *f = &state.entry[j]; - - if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE || - regexec (rx, f->name, 0, NULL, 0) == 0) - { - if (i == OP_BROWSER_SUBSCRIBE || i == OP_SUBSCRIBE_PATTERN) - nd = mutt_newsgroup_subscribe (news, f->name); - else - nd = mutt_newsgroup_unsubscribe (news, f->name); + case OP_SUBSCRIBE_PATTERN: + case OP_UNSUBSCRIBE_PATTERN: + if (option (OPTNEWS)) { + regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t)); + char *s = buf; + int j = menu->current; + NNTP_DATA *nd; + NNTP_SERVER *news = CurrentNewsSrv; + + if (i == OP_SUBSCRIBE_PATTERN || i == OP_UNSUBSCRIBE_PATTERN) { + char tmp[STRING]; + int err; + + buf[0] = 0; + if (i == OP_SUBSCRIBE_PATTERN) + snprintf (tmp, sizeof (tmp), _("Subscribe pattern: ")); + else + snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: ")); + if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) { + FREE (&rx); + break; + } + + if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { + regerror (err, rx, buf, sizeof (buf)); + regfree (rx); + FREE (&rx); + mutt_error ("%s", buf); + break; + } + menu->redraw = REDRAW_FULL; + j = 0; + } + else if (!state.entrylen) { + mutt_error _("No newsgroups match the mask"); + + break; + } + + for (; j < state.entrylen; j++) { + struct folder_file *f = &state.entry[j]; + + if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE || + regexec (rx, f->name, 0, NULL, 0) == 0) { + if (i == OP_BROWSER_SUBSCRIBE || i == OP_SUBSCRIBE_PATTERN) + nd = mutt_newsgroup_subscribe (news, f->name); + else + nd = mutt_newsgroup_unsubscribe (news, f->name); /* if (nd) { FOLDER folder; @@ -1559,59 +1491,54 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num M_FORMAT_ARROWCURSOR); f->desc = safe_strdup (buffer); } */ - } - if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) - { - if (menu->current + 1 < menu->max) - menu->current++; - menu->redraw = REDRAW_MOTION_RESYNCH; - break; - } - } - if (i == OP_SUBSCRIBE_PATTERN) - { - LIST *grouplist = NULL; - - if (news) - grouplist = news->list; - for (; grouplist; grouplist = grouplist->next) - { - nd = (NNTP_DATA *) grouplist->data; - if (nd && nd->group && !nd->subscribed) - { - if (regexec (rx, nd->group, 0, NULL, 0) == 0) - { - mutt_newsgroup_subscribe (news, nd->group); - add_folder (menu, &state, nd->group, NULL, nd, nd->new); - } - } - } - init_menu (&state, menu, title, sizeof (title), buffy); - } - mutt_newsrc_update (news); - nntp_clear_cacheindex (news); - if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE) - regfree (rx); - FREE (&rx); - } + } + if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) { + if (menu->current + 1 < menu->max) + menu->current++; + menu->redraw = REDRAW_MOTION_RESYNCH; + break; + } + } + if (i == OP_SUBSCRIBE_PATTERN) { + LIST *grouplist = NULL; + + if (news) + grouplist = news->list; + for (; grouplist; grouplist = grouplist->next) { + nd = (NNTP_DATA *) grouplist->data; + if (nd && nd->group && !nd->subscribed) { + if (regexec (rx, nd->group, 0, NULL, 0) == 0) { + mutt_newsgroup_subscribe (news, nd->group); + add_folder (menu, &state, nd->group, NULL, nd, nd->new); + } + } + } + init_menu (&state, menu, title, sizeof (title), buffy); + } + mutt_newsrc_update (news); + nntp_clear_cacheindex (news); + if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE) + regfree (rx); + FREE (&rx); + } #ifdef USE_IMAP - else + else #endif /* USE_IMAP && USE_NNTP */ #endif /* USE_NNTP */ #ifdef USE_IMAP - { - if (i == OP_BROWSER_SUBSCRIBE) - imap_subscribe (state.entry[menu->current].name, 1); - else - imap_subscribe (state.entry[menu->current].name, 0); - } + { + if (i == OP_BROWSER_SUBSCRIBE) + imap_subscribe (state.entry[menu->current].name, 1); + else + imap_subscribe (state.entry[menu->current].name, 0); + } #endif /* USE_IMAP */ } } - - bail: - + +bail: + if (!folder) strfcpy (LastDir, LastDirBackup, sizeof (LastDir)); - + } diff --git a/browser.h b/browser.h index dbc5726..cbfe9a3 100644 --- a/browser.h +++ b/browser.h @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #ifndef _BROWSER_H #define _BROWSER_H 1 @@ -24,8 +24,7 @@ #include "nntp.h" #endif -struct folder_file -{ +struct folder_file { mode_t mode; off_t size; time_t mtime; @@ -37,28 +36,27 @@ struct folder_file unsigned short new; #ifdef USE_IMAP char delim; - - unsigned imap : 1; - unsigned selectable : 1; - unsigned inferiors : 1; + + unsigned imap:1; + unsigned selectable:1; + unsigned inferiors:1; #endif #ifdef USE_NNTP NNTP_DATA *nd; #endif - unsigned tagged : 1; + unsigned tagged:1; }; -struct browser_state -{ +struct browser_state { struct folder_file *entry; - unsigned int entrylen; /* number of real entries */ - unsigned int entrymax; /* max entry */ + unsigned int entrylen; /* number of real entries */ + unsigned int entrymax; /* max entry */ #ifdef USE_IMAP short imap_browse; char *folder; - unsigned noselect : 1; - unsigned marked : 1; - unsigned unmarked : 1; + unsigned noselect:1; + unsigned marked:1; + unsigned unmarked:1; #endif }; diff --git a/buffy.c b/buffy.c index c955ab9..48927d1 100644 --- a/buffy.c +++ b/buffy.c @@ -41,12 +41,13 @@ #include -static time_t BuffyTime = 0; /* last time we started checking for mail */ +static time_t BuffyTime = 0; /* last time we started checking for mail */ + #ifdef USE_IMAP static time_t ImapBuffyTime = 0; /* last time we started checking for mail */ #endif -static short BuffyCount = 0; /* how many boxes with new mail */ -static short BuffyNotify = 0; /* # of unnotified new boxes */ +static short BuffyCount = 0; /* how many boxes with new mail */ +static short BuffyNotify = 0; /* # of unnotified new boxes */ #ifdef BUFFY_SIZE @@ -56,11 +57,11 @@ static short BuffyNotify = 0; /* # of unnotified new boxes */ int fseek_last_message (FILE * f) { long int pos; - char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ + char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ int bytes_read; - int i; /* Index into `buffer' for scanning. */ + int i; /* Index into `buffer' for scanning. */ - memset (buffer, 0, sizeof(buffer)); + memset (buffer, 0, sizeof (buffer)); fseek (f, 0, SEEK_END); pos = ftell (f); @@ -71,26 +72,23 @@ int fseek_last_message (FILE * f) bytes_read = BUFSIZ; /* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all * reads will be on block boundaries, which might increase efficiency. */ - while ((pos -= bytes_read) >= 0) - { + while ((pos -= bytes_read) >= 0) { /* we save in the buffer at the end the first 7 chars from the last read */ - strncpy (buffer + BUFSIZ, buffer, 5+2); /* 2 == 2 * mutt_strlen(CRLF) */ + strncpy (buffer + BUFSIZ, buffer, 5 + 2); /* 2 == 2 * mutt_strlen(CRLF) */ fseek (f, pos, SEEK_SET); bytes_read = fread (buffer, sizeof (char), bytes_read, f); if (bytes_read == -1) return -1; for (i = bytes_read; --i >= 0;) - if (!mutt_strncmp (buffer + i, "\n\nFrom ", mutt_strlen ("\n\nFrom "))) - { /* found it - go to the beginning of the From */ - fseek (f, pos + i + 2, SEEK_SET); - return 0; + if (!mutt_strncmp (buffer + i, "\n\nFrom ", mutt_strlen ("\n\nFrom "))) { /* found it - go to the beginning of the From */ + fseek (f, pos + i + 2, SEEK_SET); + return 0; } bytes_read = BUFSIZ; } /* here we are at the beginning of the file */ - if (!mutt_strncmp ("From ", buffer, 5)) - { + if (!mutt_strncmp ("From ", buffer, 5)) { fseek (f, 0, 0); return (0); } @@ -102,7 +100,7 @@ int fseek_last_message (FILE * f) int test_last_status_new (FILE * f) { HEADER *hdr; - ENVELOPE* tmp_envelope; + ENVELOPE *tmp_envelope; int result = 0; if (fseek_last_message (f) == -1) @@ -113,7 +111,7 @@ int test_last_status_new (FILE * f) if (!(hdr->read || hdr->old)) result = 1; - mutt_free_envelope(&tmp_envelope); + mutt_free_envelope (&tmp_envelope); mutt_free_header (&hdr); return result; @@ -130,8 +128,7 @@ int test_new_folder (const char *path) if (typ != M_MBOX && typ != M_MMDF) return 0; - if ((f = fopen (path, "rb"))) - { + if ((f = fopen (path, "rb"))) { rc = test_last_status_new (f); fclose (f); } @@ -144,14 +141,13 @@ BUFFY *mutt_find_mailbox (const char *path) BUFFY *tmp = NULL; struct stat sb; struct stat tmp_sb; - - if (stat (path,&sb) != 0) + + if (stat (path, &sb) != 0) return NULL; - for (tmp = Incoming; tmp; tmp = tmp->next) - { - if (stat (tmp->path,&tmp_sb) ==0 && - sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino) + for (tmp = Incoming; tmp; tmp = tmp->next) { + if (stat (tmp->path, &tmp_sb) == 0 && + sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino) break; } return tmp; @@ -172,27 +168,26 @@ void mutt_update_mailbox (BUFFY * b) } #endif -int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *err) +int mutt_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, + BUFFER * err) { - BUFFY **tmp,*tmp1; + BUFFY **tmp, *tmp1; char buf[_POSIX_PATH_MAX]; + #ifdef BUFFY_SIZE struct stat sb; #endif /* BUFFY_SIZE */ - while (MoreArgs (s)) - { + while (MoreArgs (s)) { mutt_extract_token (path, s, 0); strfcpy (buf, path->data, sizeof (buf)); - if(data == M_UNMAILBOXES && mutt_strcmp(buf,"*") == 0) - { - for (tmp = &Incoming; *tmp;) - { + if (data == M_UNMAILBOXES && mutt_strcmp (buf, "*") == 0) { + for (tmp = &Incoming; *tmp;) { FREE (&((*tmp)->path)); - tmp1=(*tmp)->next; + tmp1 = (*tmp)->next; FREE (tmp); - *tmp=tmp1; + *tmp = tmp1; } return 0; } @@ -200,35 +195,32 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e mutt_expand_path (buf, sizeof (buf)); /* Skip empty tokens. */ - if(!*buf) continue; + if (!*buf) + continue; /* simple check to avoid duplicates */ - for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next)) - { + for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next)) { if (mutt_strcmp (buf, (*tmp)->path) == 0) - break; + break; } - if(data == M_UNMAILBOXES) - { - if(*tmp) - { + if (data == M_UNMAILBOXES) { + if (*tmp) { FREE (&((*tmp)->path)); - tmp1=(*tmp)->next; + tmp1 = (*tmp)->next; FREE (tmp); - *tmp=tmp1; + *tmp = tmp1; } continue; } - if (!*tmp) - { + if (!*tmp) { *tmp = (BUFFY *) safe_calloc (1, sizeof (BUFFY)); (*tmp)->path = safe_strdup (buf); (*tmp)->next = NULL; /* it is tempting to set magic right here */ (*tmp)->magic = 0; - + } (*tmp)->new = 0; @@ -240,8 +232,7 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e * reading it), the size is set to 0 so that later when we check we see * that it increased . without buffy_size we probably don't care. */ - if (stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path)) - { + if (stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path)) { /* some systems out there don't have an off_t type */ (*tmp)->size = (long) sb.st_size; } @@ -276,8 +267,10 @@ int mutt_buffy_check (int force) struct stat contex_sb; time_t now, last1; CONTEXT *ctx; + #ifdef USE_IMAP time_t last2; + /* update postponed count as well, on force */ if (force != 0) mutt_update_num_postponed (); @@ -291,7 +284,7 @@ int mutt_buffy_check (int force) #ifdef USE_IMAP && (now - ImapBuffyTime < ImapBuffyTimeout)) #else - ) + ) #endif return BuffyCount; @@ -310,20 +303,19 @@ int mutt_buffy_check (int force) if (!Context || Context->magic != M_IMAP) #endif #ifdef USE_POP - if (!Context || Context->magic != M_POP) + if (!Context || Context->magic != M_POP) #endif #ifdef USE_NNTP - if (!Context || Context->magic != M_NNTP) + if (!Context || Context->magic != M_NNTP) #endif - /* check device ID and serial number instead of comparing paths */ - if (!Context || !Context->path || stat (Context->path, &contex_sb) != 0) - { - contex_sb.st_dev=0; - contex_sb.st_ino=0; - } - - for (tmp = Incoming; tmp; tmp = tmp->next) - { + /* check device ID and serial number instead of comparing paths */ + if (!Context || !Context->path + || stat (Context->path, &contex_sb) != 0) { + contex_sb.st_dev = 0; + contex_sb.st_ino = 0; + } + + for (tmp = Incoming; tmp; tmp = tmp->next) { #ifdef USE_IMAP if (mx_is_imap (tmp->path)) tmp->magic = M_IMAP; @@ -340,8 +332,7 @@ int mutt_buffy_check (int force) else #endif if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 || - (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0)) - { + (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0)) { /* if the mailbox still doesn't exist, set the newly created flag to * be ready for when it does. */ tmp->newly_created = 1; @@ -354,25 +345,31 @@ int mutt_buffy_check (int force) /* check to see if the folder is the currently selected folder * before polling */ - if (!Context || !Context->path || - ( - (0 + if (!Context || !Context->path || ((0 #ifdef USE_IMAP - || tmp->magic == M_IMAP + || tmp->magic == M_IMAP #endif #ifdef USE_POP - || tmp->magic == M_POP + || tmp->magic == M_POP #endif #ifdef USE_NNTP - || tmp->magic == M_NNTP + || tmp->magic == M_NNTP #endif - ) ? mutt_strcmp (tmp->path, Context->path) : - (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino) - ) - ) - { - switch (tmp->magic) - { + )? mutt_strcmp (tmp->path, + Context->path) : (sb. + st_dev + != + contex_sb. + st_dev + || + sb. + st_ino + != + contex_sb. + st_ino) + ) + ) { + switch (tmp->magic) { case M_MBOX: case M_MMDF: /* only check on force or $mail_check reached */ @@ -383,17 +380,19 @@ int mutt_buffy_check (int force) tmp->new = 1; } #ifdef BUFFY_SIZE - else - { + else { /* some other program has deleted mail from the folder */ tmp->size = (long) sb.st_size; } #endif - } else if (SidebarWidth > 0 && option (OPTMBOXPANE) && - (STAT_CHECK || tmp->msgcount == 0)) { + } + else if (SidebarWidth > 0 && option (OPTMBOXPANE) && + (STAT_CHECK || tmp->msgcount == 0)) { /* sidebar visible */ BuffyCount++; - if ((ctx = mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT, NULL)) != NULL) { + if ((ctx = + mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT, + NULL)) != NULL) { tmp->msgcount = ctx->msgcount; tmp->new = ctx->new; tmp->msg_unread = ctx->new; /* for sidebar, wtf? */ @@ -404,7 +403,8 @@ int mutt_buffy_check (int force) if (tmp->newly_created && (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime)) tmp->newly_created = 0; - } else if (tmp->new > 0) + } + else if (tmp->new > 0) BuffyCount++; break; @@ -412,23 +412,20 @@ int mutt_buffy_check (int force) /* only check on force or $mail_check reached */ if (force != 0 || (now - last1 >= BuffyTimeout)) { snprintf (path, sizeof (path), "%s/new", tmp->path); - if ((dirp = opendir (path)) == NULL) - { + if ((dirp = opendir (path)) == NULL) { tmp->magic = 0; break; } tmp->new = 0; tmp->msg_unread = 0; tmp->msgcount = 0; - while ((de = readdir (dirp)) != NULL) - { + while ((de = readdir (dirp)) != NULL) { char *p; - if (*de->d_name != '.' && - (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T'))) - { + + if (*de->d_name != '.' && + (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T'))) { /* one new and undeleted message is enough */ - if (tmp->new == 0) - { + if (tmp->new == 0) { BuffyCount++; tmp->new = 1; if (SidebarWidth == 0 || !option (OPTMBOXPANE)) @@ -442,20 +439,19 @@ int mutt_buffy_check (int force) } closedir (dirp); - if (SidebarWidth > 0 && option (OPTMBOXPANE)) - { + if (SidebarWidth > 0 && option (OPTMBOXPANE)) { /* only count total mail if sidebar visible */ snprintf (path, sizeof (path), "%s/cur", tmp->path); - if ((dirp = opendir (path)) == NULL) - { + if ((dirp = opendir (path)) == NULL) { tmp->magic = 0; break; } tmp->msg_flagged = 0; - while ((de = readdir (dirp)) != NULL) - { + while ((de = readdir (dirp)) != NULL) { char *p; - if (*de->d_name != '.' && (p = strstr (de->d_name, ":2,")) != NULL) { + + if (*de->d_name != '.' + && (p = strstr (de->d_name, ":2,")) != NULL) { if (!strchr (p + 3, 'T')) tmp->msgcount++; if (strchr (p + 3, 'F')) @@ -464,7 +460,8 @@ int mutt_buffy_check (int force) } closedir (dirp); } - } else if (tmp->new > 0) + } + else if (tmp->new > 0) /* keep current stats if !force and !$mail_check reached */ BuffyCount++; break; @@ -474,19 +471,17 @@ int mutt_buffy_check (int force) if (force != 0 || (now - last1 >= BuffyTimeout)) { if ((tmp->new = mh_buffy (tmp->path)) > 0) BuffyCount++; - if (SidebarWidth > 0 && option (OPTMBOXPANE)) - { + if (SidebarWidth > 0 && option (OPTMBOXPANE)) { DIR *dp; struct dirent *de; + if ((dp = opendir (path)) == NULL) break; tmp->new = 0; tmp->msgcount = 0; tmp->msg_unread = 0; - while ((de = readdir (dp))) - { - if (mh_valid_message (de->d_name)) - { + while ((de = readdir (dp))) { + if (mh_valid_message (de->d_name)) { tmp->msgcount++; tmp->msg_unread++; tmp->new++; @@ -494,7 +489,8 @@ int mutt_buffy_check (int force) } closedir (dp); } - } else if (tmp->new > 0) + } + else if (tmp->new > 0) /* keep current stats if !force and !$mail_check reached */ BuffyCount++; break; @@ -512,7 +508,8 @@ int mutt_buffy_check (int force) tmp->new = 0; tmp->msg_unread = 0; } - } else if (tmp->new > 0) + } + else if (tmp->new > 0) /* keep current stats if !force and !$imap_mail_check reached */ BuffyCount++; break; @@ -531,7 +528,7 @@ int mutt_buffy_check (int force) } #ifdef BUFFY_SIZE else if (Context && Context->path) - tmp->size = (long) sb.st_size; /* update the size */ + tmp->size = (long) sb.st_size; /* update the size */ #endif if (tmp->new <= 0) @@ -561,37 +558,33 @@ int mutt_buffy_list (void) first = 1; buffylist[0] = 0; pos += strlen (strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ - for (tmp = Incoming; tmp; tmp = tmp->next) - { + for (tmp = Incoming; tmp; tmp = tmp->next) { /* Is there new mail in this mailbox? */ if (tmp->new <= 0 || (have_unnotified && tmp->notified)) continue; strfcpy (path, tmp->path, sizeof (path)); mutt_pretty_mailbox (path); - + if (!first && pos + strlen (path) >= COLS - 7) break; - + if (!first) - pos += strlen (strncat(buffylist + pos, ", ", sizeof(buffylist)-1-pos)); /* __STRNCAT_CHECKED__ */ + pos += strlen (strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ /* Prepend an asterisk to mailboxes not already notified */ - if (!tmp->notified) - { + if (!tmp->notified) { /* pos += strlen (strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos)); __STRNCAT_CHECKED__ */ tmp->notified = 1; BuffyNotify--; } - pos += strlen (strncat(buffylist + pos, path, sizeof(buffylist)-1-pos)); /* __STRNCAT_CHECKED__ */ + pos += strlen (strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ first = 0; } - if (!first && tmp) - { - strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos); /* __STRNCAT_CHECKED__ */ + if (!first && tmp) { + strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos); /* __STRNCAT_CHECKED__ */ } - if (!first) - { + if (!first) { /* on new mail: redraw sidebar */ draw_sidebar (CurrentMenu); mutt_message ("%s", buffylist); @@ -606,8 +599,7 @@ int mutt_buffy_list (void) int mutt_buffy_notify (void) { - if (mutt_buffy_check (0) && BuffyNotify) - { + if (mutt_buffy_check (0) && BuffyNotify) { return (mutt_buffy_list ()); } return (0); @@ -625,8 +617,7 @@ void mutt_buffy (char *s, size_t slen) BUFFY *tmp = Incoming; mutt_expand_path (s, _POSIX_PATH_MAX); - switch (mutt_buffy_check (0)) - { + switch (mutt_buffy_check (0)) { case 0: *s = '\0'; @@ -636,10 +627,9 @@ void mutt_buffy (char *s, size_t slen) while (tmp && tmp->new <= 0) tmp = tmp->next; - if (!tmp) - { + if (!tmp) { *s = '\0'; - mutt_buffy_check (1); /* buffy was wrong - resync things */ + mutt_buffy_check (1); /* buffy was wrong - resync things */ break; } strfcpy (s, tmp->path, slen); @@ -647,25 +637,22 @@ void mutt_buffy (char *s, size_t slen) break; default: - + count = 0; - while (count < 3) - { + while (count < 3) { if (mutt_strcmp (s, tmp->path) == 0) - count++; + count++; else if (count && tmp->new > 0) - break; + break; tmp = tmp->next; - if (!tmp) - { - tmp = Incoming; - count++; + if (!tmp) { + tmp = Incoming; + count++; } } - if (count >= 3) - { + if (count >= 3) { *s = '\0'; - mutt_buffy_check (1); /* buffy was wrong - resync things */ + mutt_buffy_check (1); /* buffy was wrong - resync things */ break; } strfcpy (s, tmp->path, slen); diff --git a/buffy.h b/buffy.h index 94a325c..a8dd0d9 100644 --- a/buffy.h +++ b/buffy.h @@ -18,31 +18,29 @@ /*parameter to mutt_parse_mailboxes*/ #define M_MAILBOXES 1 -#define M_UNMAILBOXES 2 +#define M_UNMAILBOXES 2 -typedef struct buffy_t -{ +typedef struct buffy_t { char *path; #ifdef BUFFY_SIZE long size; -#endif /* BUFFY_SIZE */ +#endif /* BUFFY_SIZE */ struct buffy_t *next; struct buffy_t *prev; - short new; /* mailbox has new mail */ - short has_new; /* set it new if new and not read */ - int msgcount; /* total number of messages */ - int msg_unread; /* number of unread messages */ - int msg_flagged; /* number of flagged messages */ - short notified; /* user has been notified */ - short magic; /* mailbox type */ - short newly_created; /* mbox or mmdf just popped into existence */ -} -BUFFY; + short new; /* mailbox has new mail */ + short has_new; /* set it new if new and not read */ + int msgcount; /* total number of messages */ + int msg_unread; /* number of unread messages */ + int msg_flagged; /* number of flagged messages */ + short notified; /* user has been notified */ + short magic; /* mailbox type */ + short newly_created; /* mbox or mmdf just popped into existence */ +} BUFFY; WHERE BUFFY *Incoming INITVAL (0); WHERE short BuffyTimeout INITVAL (3); -extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ +extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ #ifdef BUFFY_SIZE BUFFY *mutt_find_mailbox (const char *path); diff --git a/charset.c b/charset.c index c211563..3fd4628 100644 --- a/charset.c +++ b/charset.c @@ -50,167 +50,144 @@ * a preferred MIME name is given. */ -static struct -{ +static struct { char *key; char *pref; -} -PreferredMIMENames[] = -{ - { "ansi_x3.4-1968", "us-ascii" }, - { "iso-ir-6", "us-ascii" }, - { "iso_646.irv:1991", "us-ascii" }, - { "ascii", "us-ascii" }, - { "iso646-us", "us-ascii" }, - { "us", "us-ascii" }, - { "ibm367", "us-ascii" }, - { "cp367", "us-ascii" }, - { "csASCII", "us-ascii" }, - - { "csISO2022KR", "iso-2022-kr" }, - { "csEUCKR", "euc-kr" }, - { "csISO2022JP", "iso-2022-jp" }, - { "csISO2022JP2", "iso-2022-jp-2" }, - - { "ISO_8859-1:1987", "iso-8859-1" }, - { "iso-ir-100", "iso-8859-1" }, - { "iso_8859-1", "iso-8859-1" }, - { "latin1", "iso-8859-1" }, - { "l1", "iso-8859-1" }, - { "IBM819", "iso-8859-1" }, - { "CP819", "iso-8859-1" }, - { "csISOLatin1", "iso-8859-1" }, - - { "ISO_8859-2:1987", "iso-8859-2" }, - { "iso-ir-101", "iso-8859-2" }, - { "iso_8859-2", "iso-8859-2" }, - { "latin2", "iso-8859-2" }, - { "l2", "iso-8859-2" }, - { "csISOLatin2", "iso-8859-2" }, - - { "ISO_8859-3:1988", "iso-8859-3" }, - { "iso-ir-109", "iso-8859-3" }, - { "ISO_8859-3", "iso-8859-3" }, - { "latin3", "iso-8859-3" }, - { "l3", "iso-8859-3" }, - { "csISOLatin3", "iso-8859-3" }, - - { "ISO_8859-4:1988", "iso-8859-4" }, - { "iso-ir-110", "iso-8859-4" }, - { "ISO_8859-4", "iso-8859-4" }, - { "latin4", "iso-8859-4" }, - { "l4", "iso-8859-4" }, - { "csISOLatin4", "iso-8859-4" }, - - { "ISO_8859-6:1987", "iso-8859-6" }, - { "iso-ir-127", "iso-8859-6" }, - { "iso_8859-6", "iso-8859-6" }, - { "ECMA-114", "iso-8859-6" }, - { "ASMO-708", "iso-8859-6" }, - { "arabic", "iso-8859-6" }, - { "csISOLatinArabic", "iso-8859-6" }, - - { "ISO_8859-7:1987", "iso-8859-7" }, - { "iso-ir-126", "iso-8859-7" }, - { "ISO_8859-7", "iso-8859-7" }, - { "ELOT_928", "iso-8859-7" }, - { "ECMA-118", "iso-8859-7" }, - { "greek", "iso-8859-7" }, - { "greek8", "iso-8859-7" }, - { "csISOLatinGreek", "iso-8859-7" }, - - { "ISO_8859-8:1988", "iso-8859-8" }, - { "iso-ir-138", "iso-8859-8" }, - { "ISO_8859-8", "iso-8859-8" }, - { "hebrew", "iso-8859-8" }, - { "csISOLatinHebrew", "iso-8859-8" }, - - { "ISO_8859-5:1988", "iso-8859-5" }, - { "iso-ir-144", "iso-8859-5" }, - { "ISO_8859-5", "iso-8859-5" }, - { "cyrillic", "iso-8859-5" }, - { "csISOLatinCyrillic", "iso8859-5" }, - - { "ISO_8859-9:1989", "iso-8859-9" }, - { "iso-ir-148", "iso-8859-9" }, - { "ISO_8859-9", "iso-8859-9" }, - { "latin5", "iso-8859-9" }, /* this is not a bug */ - { "l5", "iso-8859-9" }, - { "csISOLatin5", "iso-8859-9" }, - - { "ISO_8859-10:1992", "iso-8859-10" }, - { "iso-ir-157", "iso-8859-10" }, - { "latin6", "iso-8859-10" }, /* this is not a bug */ - { "l6", "iso-8859-10" }, - { "csISOLatin6" "iso-8859-10" }, - - { "csKOI8r", "koi8-r" }, - - { "MS_Kanji", "Shift_JIS" }, /* Note the underscore! */ - { "csShiftJis", "Shift_JIS" }, - - { "Extended_UNIX_Code_Packed_Format_for_Japanese", - "EUC-JP" }, - { "csEUCPkdFmtJapanese", - "EUC-JP" }, - - { "csGB2312", "gb2312" }, - { "csbig5", "big5" }, - - /* - * End of official brain damage. What follows has been taken - * from glibc's localedata files. - */ - - { "iso_8859-13", "iso-8859-13" }, - { "iso-ir-179", "iso-8859-13" }, - { "latin7", "iso-8859-13" }, /* this is not a bug */ - { "l7", "iso-8859-13" }, - - { "iso_8859-14", "iso-8859-14" }, - { "latin8", "iso-8859-14" }, /* this is not a bug */ - { "l8", "iso-8859-14" }, - - { "iso_8859-15", "iso-8859-15" }, - { "latin9", "iso-8859-15" }, /* this is not a bug */ - - /* Suggested by Ionel Mugurel Ciobica */ - { "latin0", "iso-8859-15" }, /* this is not a bug */ - - { "iso_8859-16", "iso-8859-16" }, - { "latin10", "iso-8859-16" }, /* this is not a bug */ - - /* - * David Champion has observed this with - * nl_langinfo under SunOS 5.8. - */ - - { "646", "us-ascii" }, - - /* - * http://www.sun.com/software/white-papers/wp-unicode/ - */ - - { "eucJP", "euc-jp" }, - { "PCK", "Shift_JIS" }, - { "ko_KR-euc", "euc-kr" }, - { "zh_TW-big5", "big5" }, - - /* seems to be common on some systems */ - - { "sjis", "Shift_JIS" }, - { "euc-jp-ms", "eucJP-ms" }, - - - /* - * If you happen to encounter system-specific brain-damage with - * respect to character set naming, please add it above this - * comment, and submit a patch to . - */ - - /* End of aliases. Please keep this line last. */ - - { NULL, NULL } +} PreferredMIMENames[] = { + { + "ansi_x3.4-1968", "us-ascii"}, { + "iso-ir-6", "us-ascii"}, { + "iso_646.irv:1991", "us-ascii"}, { + "ascii", "us-ascii"}, { + "iso646-us", "us-ascii"}, { + "us", "us-ascii"}, { + "ibm367", "us-ascii"}, { + "cp367", "us-ascii"}, { + "csASCII", "us-ascii"}, { + "csISO2022KR", "iso-2022-kr"}, { + "csEUCKR", "euc-kr"}, { + "csISO2022JP", "iso-2022-jp"}, { + "csISO2022JP2", "iso-2022-jp-2"}, { + "ISO_8859-1:1987", "iso-8859-1"}, { + "iso-ir-100", "iso-8859-1"}, { + "iso_8859-1", "iso-8859-1"}, { + "latin1", "iso-8859-1"}, { + "l1", "iso-8859-1"}, { + "IBM819", "iso-8859-1"}, { + "CP819", "iso-8859-1"}, { + "csISOLatin1", "iso-8859-1"}, { + "ISO_8859-2:1987", "iso-8859-2"}, { + "iso-ir-101", "iso-8859-2"}, { + "iso_8859-2", "iso-8859-2"}, { + "latin2", "iso-8859-2"}, { + "l2", "iso-8859-2"}, { + "csISOLatin2", "iso-8859-2"}, { + "ISO_8859-3:1988", "iso-8859-3"}, { + "iso-ir-109", "iso-8859-3"}, { + "ISO_8859-3", "iso-8859-3"}, { + "latin3", "iso-8859-3"}, { + "l3", "iso-8859-3"}, { + "csISOLatin3", "iso-8859-3"}, { + "ISO_8859-4:1988", "iso-8859-4"}, { + "iso-ir-110", "iso-8859-4"}, { + "ISO_8859-4", "iso-8859-4"}, { + "latin4", "iso-8859-4"}, { + "l4", "iso-8859-4"}, { + "csISOLatin4", "iso-8859-4"}, { + "ISO_8859-6:1987", "iso-8859-6"}, { + "iso-ir-127", "iso-8859-6"}, { + "iso_8859-6", "iso-8859-6"}, { + "ECMA-114", "iso-8859-6"}, { + "ASMO-708", "iso-8859-6"}, { + "arabic", "iso-8859-6"}, { + "csISOLatinArabic", "iso-8859-6"}, { + "ISO_8859-7:1987", "iso-8859-7"}, { + "iso-ir-126", "iso-8859-7"}, { + "ISO_8859-7", "iso-8859-7"}, { + "ELOT_928", "iso-8859-7"}, { + "ECMA-118", "iso-8859-7"}, { + "greek", "iso-8859-7"}, { + "greek8", "iso-8859-7"}, { + "csISOLatinGreek", "iso-8859-7"}, { + "ISO_8859-8:1988", "iso-8859-8"}, { + "iso-ir-138", "iso-8859-8"}, { + "ISO_8859-8", "iso-8859-8"}, { + "hebrew", "iso-8859-8"}, { + "csISOLatinHebrew", "iso-8859-8"}, { + "ISO_8859-5:1988", "iso-8859-5"}, { + "iso-ir-144", "iso-8859-5"}, { + "ISO_8859-5", "iso-8859-5"}, { + "cyrillic", "iso-8859-5"}, { + "csISOLatinCyrillic", "iso8859-5"}, { + "ISO_8859-9:1989", "iso-8859-9"}, { + "iso-ir-148", "iso-8859-9"}, { + "ISO_8859-9", "iso-8859-9"}, { + "latin5", "iso-8859-9"}, /* this is not a bug */ + { + "l5", "iso-8859-9"}, { + "csISOLatin5", "iso-8859-9"}, { + "ISO_8859-10:1992", "iso-8859-10"}, { + "iso-ir-157", "iso-8859-10"}, { + "latin6", "iso-8859-10"}, /* this is not a bug */ + { + "l6", "iso-8859-10"}, { + "csISOLatin6" "iso-8859-10"}, { + "csKOI8r", "koi8-r"}, { + "MS_Kanji", "Shift_JIS"}, /* Note the underscore! */ + { + "csShiftJis", "Shift_JIS"}, { + "Extended_UNIX_Code_Packed_Format_for_Japanese", "EUC-JP"}, { + "csEUCPkdFmtJapanese", "EUC-JP"}, { + "csGB2312", "gb2312"}, { + "csbig5", "big5"}, + /* + * End of official brain damage. What follows has been taken + * from glibc's localedata files. + */ + { + "iso_8859-13", "iso-8859-13"}, { + "iso-ir-179", "iso-8859-13"}, { + "latin7", "iso-8859-13"}, /* this is not a bug */ + { + "l7", "iso-8859-13"}, { + "iso_8859-14", "iso-8859-14"}, { + "latin8", "iso-8859-14"}, /* this is not a bug */ + { + "l8", "iso-8859-14"}, { + "iso_8859-15", "iso-8859-15"}, { + "latin9", "iso-8859-15"}, /* this is not a bug */ + /* Suggested by Ionel Mugurel Ciobica */ + { + "latin0", "iso-8859-15"}, /* this is not a bug */ + { + "iso_8859-16", "iso-8859-16"}, { + "latin10", "iso-8859-16"}, /* this is not a bug */ + /* + * David Champion has observed this with + * nl_langinfo under SunOS 5.8. + */ + { + "646", "us-ascii"}, + /* + * http://www.sun.com/software/white-papers/wp-unicode/ + */ + { + "eucJP", "euc-jp"}, { + "PCK", "Shift_JIS"}, { + "ko_KR-euc", "euc-kr"}, { + "zh_TW-big5", "big5"}, + /* seems to be common on some systems */ + { + "sjis", "Shift_JIS"}, { + "euc-jp-ms", "eucJP-ms"}, + /* + * If you happen to encounter system-specific brain-damage with + * respect to character set naming, please add it above this + * comment, and submit a patch to . + */ + /* End of aliases. Please keep this line last. */ + { + NULL, NULL} }; #ifdef HAVE_LANGINFO_CODESET @@ -221,10 +198,10 @@ void mutt_set_langinfo_charset (void) { char buff[LONG_STRING]; char buff2[LONG_STRING]; - + strfcpy (buff, nl_langinfo (CODESET), sizeof (buff)); mutt_canonical_charset (buff2, sizeof (buff2), buff); - + /* finally, set $charset */ if (!(Charset = safe_strdup (buff2))) Charset = safe_strdup ("iso-8859-1"); @@ -247,7 +224,7 @@ void mutt_canonical_charset (char *dest, size_t dlen, const char *name) /* catch some common iso-8859-something misspellings */ if (!ascii_strncasecmp (name, "8859", 4) && name[4] != '-') - snprintf (scratch, sizeof (scratch), "iso-8859-%s", name +4); + snprintf (scratch, sizeof (scratch), "iso-8859-%s", name + 4); else if (!ascii_strncasecmp (name, "8859-", 5)) snprintf (scratch, sizeof (scratch), "iso-8859-%s", name + 5); else if (!ascii_strncasecmp (name, "iso8859", 7) && name[7] != '-') @@ -255,12 +232,11 @@ void mutt_canonical_charset (char *dest, size_t dlen, const char *name) else if (!ascii_strncasecmp (name, "iso8859-", 8)) snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 8); else - strfcpy (scratch, NONULL(name), sizeof (scratch)); + strfcpy (scratch, NONULL (name), sizeof (scratch)); for (i = 0; PreferredMIMENames[i].key; i++) if (!ascii_strcasecmp (scratch, PreferredMIMENames[i].key) || - !mutt_strcasecmp (scratch, PreferredMIMENames[i].key)) - { + !mutt_strcasecmp (scratch, PreferredMIMENames[i].key)) { strfcpy (dest, PreferredMIMENames[i].pref, dlen); return; } @@ -276,7 +252,8 @@ int mutt_chscmp (const char *s, const char *chs) { char buffer[STRING]; - if (!s) return 0; + if (!s) + return 0; mutt_canonical_charset (buffer, sizeof (buffer), s); return !ascii_strcasecmp (buffer, chs); @@ -287,11 +264,11 @@ int mutt_chscmp (const char *s, const char *chs) iconv_t iconv_open (const char *tocode, const char *fromcode) { - return (iconv_t)(-1); + return (iconv_t) (-1); } -size_t iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft) +size_t iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, + char **outbuf, size_t * outbytesleft) { return 0; } @@ -316,7 +293,7 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) char *tmp; iconv_t cd; - + mutt_canonical_charset (tocode1, sizeof (tocode1), tocode); #ifdef M_ICONV_HOOK_TO @@ -329,12 +306,13 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1))) mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp); - if ((cd = iconv_open (tocode1, fromcode1)) != (iconv_t) -1) + if ((cd = iconv_open (tocode1, fromcode1)) != (iconv_t) - 1) return cd; - if ((tocode2 = mutt_iconv_hook (tocode1)) && (fromcode2 = mutt_iconv_hook (fromcode1))) + if ((tocode2 = mutt_iconv_hook (tocode1)) + && (fromcode2 = mutt_iconv_hook (fromcode1))) return iconv_open (tocode2, fromcode2); - - return (iconv_t) -1; + + return (iconv_t) - 1; } @@ -344,9 +322,9 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) * if you're supplying an outrepl, the target charset should be. */ -size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - ICONV_CONST char **inrepls, const char *outrepl) +size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, + char **outbuf, size_t * outbytesleft, + ICONV_CONST char **inrepls, const char *outrepl) { size_t ret = 0, ret1; ICONV_CONST char *ib = *inbuf; @@ -354,53 +332,49 @@ size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, char *ob = *outbuf; size_t obl = *outbytesleft; - for (;;) - { + for (;;) { ret1 = iconv (cd, &ib, &ibl, &ob, &obl); - if (ret1 != (size_t)-1) + if (ret1 != (size_t) - 1) ret += ret1; - if (ibl && obl && errno == EILSEQ) - { - if (inrepls) - { - /* Try replacing the input */ - ICONV_CONST char **t; - for (t = inrepls; *t; t++) - { - ICONV_CONST char *ib1 = *t; - size_t ibl1 = strlen (*t); - char *ob1 = ob; - size_t obl1 = obl; - iconv (cd, &ib1, &ibl1, &ob1, &obl1); - if (!ibl1) - { - ++ib, --ibl; - ob = ob1, obl = obl1; - ++ret; - break; - } - } - if (*t) - continue; + if (ibl && obl && errno == EILSEQ) { + if (inrepls) { + /* Try replacing the input */ + ICONV_CONST char **t; + + for (t = inrepls; *t; t++) { + ICONV_CONST char *ib1 = *t; + size_t ibl1 = strlen (*t); + char *ob1 = ob; + size_t obl1 = obl; + + iconv (cd, &ib1, &ibl1, &ob1, &obl1); + if (!ibl1) { + ++ib, --ibl; + ob = ob1, obl = obl1; + ++ret; + break; + } + } + if (*t) + continue; } /* Replace the output */ if (!outrepl) - outrepl = "?"; + outrepl = "?"; iconv (cd, 0, 0, &ob, &obl); - if (obl) - { - int n = strlen (outrepl); - if (n > obl) - { - outrepl = "?"; - n = 1; - } - memcpy (ob, outrepl, n); - ++ib, --ibl; - ob += n, obl -= n; - ++ret; - iconv (cd, 0, 0, 0, 0); /* for good measure */ - continue; + if (obl) { + int n = strlen (outrepl); + + if (n > obl) { + outrepl = "?"; + n = 1; + } + memcpy (ob, outrepl, n); + ++ib, --ibl; + ob += n, obl -= n; + ++ret; + iconv (cd, 0, 0, 0, 0); /* for good measure */ + continue; } } *inbuf = ib, *inbytesleft = ibl; @@ -415,7 +389,8 @@ size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, * Used in rfc2047.c and rfc2231.c */ -int mutt_convert_string (char **ps, const char *from, const char *to, int flags) +int mutt_convert_string (char **ps, const char *from, const char *to, + int flags) { iconv_t cd; ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; @@ -424,8 +399,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to, int flags) if (!s || !*s) return 0; - if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t)-1) - { + if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t) - 1) { int len; ICONV_CONST char *ib; char *buf, *ob; @@ -439,12 +413,12 @@ int mutt_convert_string (char **ps, const char *from, const char *to, int flags) inrepls = repls; else outrepl = "?"; - + len = strlen (s); ib = s, ibl = len + 1; obl = MB_LEN_MAX * ibl; ob = buf = safe_malloc (obl + 1); - + mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); iconv_close (cd); @@ -452,7 +426,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to, int flags) FREE (ps); *ps = buf; - + mutt_str_adjust (ps); return 0; } @@ -466,8 +440,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to, int flags) * Used in sendlib.c for converting from mutt's Charset */ -struct fgetconv_s -{ +struct fgetconv_s { FILE *file; iconv_t cd; char bufi[512]; @@ -479,23 +452,22 @@ struct fgetconv_s ICONV_CONST char **inrepls; }; -struct fgetconv_not -{ +struct fgetconv_not { FILE *file; iconv_t cd; }; -FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to, int flags) +FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to, + int flags) { struct fgetconv_s *fc; - iconv_t cd = (iconv_t)-1; + iconv_t cd = (iconv_t) - 1; static ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; if (from && to) cd = mutt_iconv_open (to, from, flags); - if (cd != (iconv_t)-1) - { + if (cd != (iconv_t) - 1) { fc = safe_malloc (sizeof (struct fgetconv_s)); fc->p = fc->ob = fc->bufo; fc->ib = fc->bufi; @@ -506,51 +478,50 @@ FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to, int flags fc = safe_malloc (sizeof (struct fgetconv_not)); fc->file = file; fc->cd = cd; - return (FGETCONV *)fc; + return (FGETCONV *) fc; } -char *fgetconvs (char *buf, size_t l, FGETCONV *_fc) +char *fgetconvs (char *buf, size_t l, FGETCONV * _fc) { int c; size_t r; - - for (r = 0; r + 1 < l;) - { + + for (r = 0; r + 1 < l;) { if ((c = fgetconv (_fc)) == EOF) break; buf[r++] = (char) c; - if (c == '\n') + if (c == '\n') break; } buf[r] = '\0'; - - if (r) + + if (r) return buf; - else + else return NULL; } -int fgetconv (FGETCONV *_fc) +int fgetconv (FGETCONV * _fc) { - struct fgetconv_s *fc = (struct fgetconv_s *)_fc; + struct fgetconv_s *fc = (struct fgetconv_s *) _fc; if (!fc) return EOF; - if (fc->cd == (iconv_t)-1) + if (fc->cd == (iconv_t) - 1) return fgetc (fc->file); if (!fc->p) return EOF; if (fc->p < fc->ob) - return (unsigned char)*(fc->p)++; + return (unsigned char) *(fc->p)++; /* Try to convert some more */ fc->p = fc->ob = fc->bufo; - if (fc->ibl) - { + if (fc->ibl) { size_t obl = sizeof (fc->bufo); - iconv (fc->cd, (ICONV_CONST char **)&fc->ib, &fc->ibl, &fc->ob, &obl); + + iconv (fc->cd, (ICONV_CONST char **) &fc->ib, &fc->ibl, &fc->ob, &obl); if (fc->p < fc->ob) - return (unsigned char)*(fc->p)++; + return (unsigned char) *(fc->p)++; } /* If we trusted iconv a bit more, we would at this point @@ -558,24 +529,24 @@ int fgetconv (FGETCONV *_fc) /* Try to read some more */ if (fc->ibl == sizeof (fc->bufi) || - (fc->ibl && fc->ib + fc->ibl < fc->bufi + sizeof (fc->bufi))) - { + (fc->ibl && fc->ib + fc->ibl < fc->bufi + sizeof (fc->bufi))) { fc->p = 0; return EOF; } if (fc->ibl) memcpy (fc->bufi, fc->ib, fc->ibl); fc->ib = fc->bufi; - fc->ibl += fread (fc->ib + fc->ibl, 1, sizeof (fc->bufi) - fc->ibl, fc->file); + fc->ibl += + fread (fc->ib + fc->ibl, 1, sizeof (fc->bufi) - fc->ibl, fc->file); /* Try harder this time to convert some */ - if (fc->ibl) - { + if (fc->ibl) { size_t obl = sizeof (fc->bufo); - mutt_iconv (fc->cd, (ICONV_CONST char **)&fc->ib, &fc->ibl, &fc->ob, &obl, - fc->inrepls, 0); + + mutt_iconv (fc->cd, (ICONV_CONST char **) &fc->ib, &fc->ibl, &fc->ob, + &obl, fc->inrepls, 0); if (fc->p < fc->ob) - return (unsigned char)*(fc->p)++; + return (unsigned char) *(fc->p)++; } /* Either the file has finished or one of the buffers is too small */ @@ -583,11 +554,11 @@ int fgetconv (FGETCONV *_fc) return EOF; } -void fgetconv_close (FGETCONV **_fc) +void fgetconv_close (FGETCONV ** _fc) { struct fgetconv_s *fc = (struct fgetconv_s *) *_fc; - if (fc->cd != (iconv_t)-1) + if (fc->cd != (iconv_t) - 1) iconv_close (fc->cd); FREE (_fc); } @@ -598,7 +569,7 @@ char *mutt_get_first_charset (const char *charset) const char *c, *c1; c = charset; - if (!mutt_strlen(c)) + if (!mutt_strlen (c)) return "us-ascii"; if (!(c1 = strchr (c, ':'))) return charset; @@ -607,8 +578,8 @@ char *mutt_get_first_charset (const char *charset) } static size_t convert_string (ICONV_CONST char *f, size_t flen, - const char *from, const char *to, - char **t, size_t *tlen) + const char *from, const char *to, + char **t, size_t * tlen) { iconv_t cd; char *buf, *ob; @@ -616,18 +587,17 @@ static size_t convert_string (ICONV_CONST char *f, size_t flen, int e; cd = mutt_iconv_open (to, from, 0); - if (cd == (iconv_t)(-1)) - return (size_t)(-1); + if (cd == (iconv_t) (-1)) + return (size_t) (-1); obl = 4 * flen + 1; ob = buf = safe_malloc (obl); n = iconv (cd, &f, &flen, &ob, &obl); - if (n == (size_t)(-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t)(-1)) - { + if (n == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) { e = errno; FREE (&buf); iconv_close (cd); errno = e; - return (size_t)(-1); + return (size_t) (-1); } *ob = '\0'; @@ -644,8 +614,7 @@ int mutt_convert_nonmime_string (char **ps) { const char *c, *c1; - for (c = AssumedCharset; c; c = c1 ? c1 + 1 : 0) - { + for (c = AssumedCharset; c; c = c1 ? c1 + 1 : 0) { char *u = *ps; char *s; char *fromcode; @@ -664,8 +633,7 @@ int mutt_convert_nonmime_string (char **ps) strfcpy (fromcode, c, n + 1); m = convert_string (u, ulen, fromcode, Charset, &s, &slen); FREE (&fromcode); - if (m != (size_t)(-1)) - { + if (m != (size_t) (-1)) { FREE (ps); *ps = s; return 0; @@ -673,4 +641,3 @@ int mutt_convert_nonmime_string (char **ps) } return -1; } - diff --git a/charset.h b/charset.h index 6397493..2721b01 100644 --- a/charset.h +++ b/charset.h @@ -29,7 +29,7 @@ typedef void *iconv_t; #ifndef HAVE_ICONV #define ICONV_CONST /**/ -iconv_t iconv_open (const char *, const char *); + iconv_t iconv_open (const char *, const char *); size_t iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *); int iconv_close (iconv_t); #endif @@ -39,13 +39,14 @@ char *mutt_get_first_charset (const char *); int mutt_convert_nonmime_string (char **); iconv_t mutt_iconv_open (const char *, const char *, int); -size_t mutt_iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *, ICONV_CONST char **, const char *); +size_t mutt_iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *, + ICONV_CONST char **, const char *); -typedef void * FGETCONV; +typedef void *FGETCONV; FGETCONV *fgetconv_open (FILE *, const char *, const char *, int); int fgetconv (FGETCONV *); -char * fgetconvs (char *, size_t, FGETCONV *); +char *fgetconvs (char *, size_t, FGETCONV *); void fgetconv_close (FGETCONV **); void mutt_set_langinfo_charset (void); diff --git a/color.c b/color.c index 8dda6cf..34a3d70 100644 --- a/color.c +++ b/color.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -43,8 +43,7 @@ static int ColorQuoteSize; #define COLOR_DEFAULT (-2) -typedef struct color_list -{ +typedef struct color_list { short fg; short bg; short index; @@ -55,48 +54,46 @@ typedef struct color_list static COLOR_LIST *ColorList = NULL; static int UserColors = 0; -static struct mapping_t Colors[] = -{ - { "black", COLOR_BLACK }, - { "blue", COLOR_BLUE }, - { "cyan", COLOR_CYAN }, - { "green", COLOR_GREEN }, - { "magenta", COLOR_MAGENTA }, - { "red", COLOR_RED }, - { "white", COLOR_WHITE }, - { "yellow", COLOR_YELLOW }, +static struct mapping_t Colors[] = { + {"black", COLOR_BLACK}, + {"blue", COLOR_BLUE}, + {"cyan", COLOR_CYAN}, + {"green", COLOR_GREEN}, + {"magenta", COLOR_MAGENTA}, + {"red", COLOR_RED}, + {"white", COLOR_WHITE}, + {"yellow", COLOR_YELLOW}, #if defined (USE_SLANG_CURSES) || defined (HAVE_USE_DEFAULT_COLORS) - { "default", COLOR_DEFAULT }, + {"default", COLOR_DEFAULT}, #endif - { 0, 0 } + {0, 0} }; #endif /* HAVE_COLOR */ -static struct mapping_t Fields[] = -{ - { "hdrdefault", MT_COLOR_HDEFAULT }, - { "quoted", MT_COLOR_QUOTED }, - { "signature", MT_COLOR_SIGNATURE }, - { "indicator", MT_COLOR_INDICATOR }, - { "status", MT_COLOR_STATUS }, - { "tree", MT_COLOR_TREE }, - { "error", MT_COLOR_ERROR }, - { "normal", MT_COLOR_NORMAL }, - { "tilde", MT_COLOR_TILDE }, - { "markers", MT_COLOR_MARKERS }, - { "header", MT_COLOR_HEADER }, - { "body", MT_COLOR_BODY }, - { "message", MT_COLOR_MESSAGE }, - { "attachment", MT_COLOR_ATTACHMENT }, - { "search", MT_COLOR_SEARCH }, - { "bold", MT_COLOR_BOLD }, - { "underline", MT_COLOR_UNDERLINE }, - { "index", MT_COLOR_INDEX }, - { "sidebar_new", MT_COLOR_NEW }, - { "sidebar", MT_COLOR_SIDEBAR }, - { "sidebar_flagged", MT_COLOR_FLAGGED }, - { NULL, 0 } +static struct mapping_t Fields[] = { + {"hdrdefault", MT_COLOR_HDEFAULT}, + {"quoted", MT_COLOR_QUOTED}, + {"signature", MT_COLOR_SIGNATURE}, + {"indicator", MT_COLOR_INDICATOR}, + {"status", MT_COLOR_STATUS}, + {"tree", MT_COLOR_TREE}, + {"error", MT_COLOR_ERROR}, + {"normal", MT_COLOR_NORMAL}, + {"tilde", MT_COLOR_TILDE}, + {"markers", MT_COLOR_MARKERS}, + {"header", MT_COLOR_HEADER}, + {"body", MT_COLOR_BODY}, + {"message", MT_COLOR_MESSAGE}, + {"attachment", MT_COLOR_ATTACHMENT}, + {"search", MT_COLOR_SEARCH}, + {"bold", MT_COLOR_BOLD}, + {"underline", MT_COLOR_UNDERLINE}, + {"index", MT_COLOR_INDEX}, + {"sidebar_new", MT_COLOR_NEW}, + {"sidebar", MT_COLOR_SIDEBAR}, + {"sidebar_flagged", MT_COLOR_FLAGGED}, + {NULL, 0} }; #define COLOR_QUOTE_INIT 8 @@ -106,31 +103,30 @@ static COLOR_LINE *mutt_new_color_line (void) COLOR_LINE *p = safe_calloc (1, sizeof (COLOR_LINE)); p->fg = p->bg = -1; - + return (p); } -static void mutt_free_color_line(COLOR_LINE **l, - int free_colors) +static void mutt_free_color_line (COLOR_LINE ** l, int free_colors) { COLOR_LINE *tmp; - - if(!l || !*l) + + if (!l || !*l) return; tmp = *l; #ifdef HAVE_COLOR - if(free_colors && tmp->fg != -1 && tmp->bg != -1) - mutt_free_color(tmp->fg, tmp->bg); + if (free_colors && tmp->fg != -1 && tmp->bg != -1) + mutt_free_color (tmp->fg, tmp->bg); #endif /* we should really introduce a container * type for regular expressions. */ - - regfree(&tmp->rx); - mutt_pattern_free(&tmp->color_pattern); + + regfree (&tmp->rx); + mutt_pattern_free (&tmp->color_pattern); FREE (&tmp->pattern); FREE (l); } @@ -162,28 +158,25 @@ void ci_start_color (void) #ifdef USE_SLANG_CURSES static char *get_color_name (char *dest, size_t destlen, int val) { - static char * missing[3] = {"brown", "lightgray", "default"}; + static char *missing[3] = { "brown", "lightgray", "default" }; int i; - switch (val) - { - case COLOR_YELLOW: - strfcpy (dest, missing[0], destlen); - return dest; + switch (val) { + case COLOR_YELLOW: + strfcpy (dest, missing[0], destlen); + return dest; - case COLOR_WHITE: - strfcpy (dest, missing[1], destlen); - return dest; - - case COLOR_DEFAULT: - strfcpy (dest, missing[2], destlen); - return dest; + case COLOR_WHITE: + strfcpy (dest, missing[1], destlen); + return dest; + + case COLOR_DEFAULT: + strfcpy (dest, missing[2], destlen); + return dest; } - for (i = 0; Colors[i].name; i++) - { - if (Colors[i].value == val) - { + for (i = 0; Colors[i].name; i++) { + if (Colors[i].value == val) { strfcpy (dest, Colors[i].name, destlen); return dest; } @@ -202,16 +195,14 @@ int mutt_alloc_color (int fg, int bg) { COLOR_LIST *p = ColorList; int i; - + #if defined (USE_SLANG_CURSES) char fgc[SHORT_STRING], bgc[SHORT_STRING]; #endif /* check to see if this color is already allocated to save space */ - while (p) - { - if (p->fg == fg && p->bg == bg) - { + while (p) { + if (p->fg == fg && p->bg == bg) { (p->count)++; return (COLOR_PAIR (p->index)); } @@ -219,19 +210,20 @@ int mutt_alloc_color (int fg, int bg) } /* check to see if there are colors left */ - if (++UserColors > COLOR_PAIRS) return (A_NORMAL); + if (++UserColors > COLOR_PAIRS) + return (A_NORMAL); /* find the smallest available index (object) */ i = 1; - FOREVER - { + FOREVER { p = ColorList; - while (p) - { - if (p->index == i) break; + while (p) { + if (p->index == i) + break; p = p->next; } - if (p == NULL) break; + if (p == NULL) + break; i++; } @@ -246,7 +238,8 @@ int mutt_alloc_color (int fg, int bg) #if defined (USE_SLANG_CURSES) if (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) - SLtt_set_color (i, NULL, get_color_name (fgc, sizeof (fgc), fg), get_color_name (bgc, sizeof (bgc), bg)); + SLtt_set_color (i, NULL, get_color_name (fgc, sizeof (fgc), fg), + get_color_name (bgc, sizeof (bgc), bg)); else #elif defined (HAVE_USE_DEFAULT_COLORS) if (fg == COLOR_DEFAULT) @@ -255,10 +248,10 @@ int mutt_alloc_color (int fg, int bg) bg = -1; #endif - init_pair(i, fg, bg); + init_pair (i, fg, bg); - dprint(1,(debugfile,"mutt_alloc_color(): Color pairs used so far: %d\n", - UserColors)); + dprint (1, (debugfile, "mutt_alloc_color(): Color pairs used so far: %d\n", + UserColors)); return (COLOR_PAIR (p->index)); } @@ -268,33 +261,30 @@ void mutt_free_color (int fg, int bg) COLOR_LIST *p, *q; p = ColorList; - while (p) - { - if (p->fg == fg && p->bg == bg) - { + while (p) { + if (p->fg == fg && p->bg == bg) { (p->count)--; - if (p->count > 0) return; + if (p->count > 0) + return; UserColors--; - dprint(1,(debugfile,"mutt_free_color(): Color pairs used so far: %d\n", - UserColors)); - - if (p == ColorList) - { - ColorList = ColorList->next; - FREE (&p); - return; + dprint (1, + (debugfile, "mutt_free_color(): Color pairs used so far: %d\n", + UserColors)); + + if (p == ColorList) { + ColorList = ColorList->next; + FREE (&p); + return; } q = ColorList; - while (q) - { - if (q->next == p) - { - q->next = p->next; - FREE (&p); - return; - } - q = q->next; + while (q) { + if (q->next == p) { + q->next = p->next; + FREE (&p); + return; + } + q = q->next; } /* can't get here */ } @@ -308,30 +298,27 @@ void mutt_free_color (int fg, int bg) #ifdef HAVE_COLOR static int -parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER *err) +parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER * err) { char *eptr; - if (mutt_strncasecmp (s, "bright", 6) == 0) - { + if (mutt_strncasecmp (s, "bright", 6) == 0) { *attr |= brite; s += 6; } /* allow aliases for xterm color resources */ - if (mutt_strncasecmp (s, "color", 5) == 0) - { + if (mutt_strncasecmp (s, "color", 5) == 0) { s += 5; *col = strtol (s, &eptr, 10); if (!*s || *eptr || *col < 0 || - (*col >= COLORS && !option(OPTNOCURSES) && has_colors())) - { - snprintf (err->data, err->dsize, _("%s: color not supported by term"), s); + (*col >= COLORS && !option (OPTNOCURSES) && has_colors ())) { + snprintf (err->data, err->dsize, _("%s: color not supported by term"), + s); return (-1); } } - else if ((*col = mutt_getvaluebyname (s, Colors)) == -1) - { + else if ((*col = mutt_getvaluebyname (s, Colors)) == -1) { snprintf (err->data, err->dsize, _("%s: no such color"), s); return (-1); } @@ -346,71 +333,68 @@ parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER *err) * unmono index pattern [pattern...] */ -static int -_mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err, - short parse_uncolor); +static int +_mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, + BUFFER * err, short parse_uncolor); #ifdef HAVE_COLOR -int mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, - BUFFER *err) +int mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, + BUFFER * err) { - return _mutt_parse_uncolor(buf, s, data, err, 1); + return _mutt_parse_uncolor (buf, s, data, err, 1); } #endif -int mutt_parse_unmono (BUFFER *buf, BUFFER *s, unsigned long data, - BUFFER *err) +int mutt_parse_unmono (BUFFER * buf, BUFFER * s, unsigned long data, + BUFFER * err) { - return _mutt_parse_uncolor(buf, s, data, err, 0); + return _mutt_parse_uncolor (buf, s, data, err, 0); } -static int -_mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err, - short parse_uncolor) +static int +_mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, + BUFFER * err, short parse_uncolor) { int object = 0, do_cache = 0; COLOR_LINE *tmp, *last = NULL; mutt_extract_token (buf, s, 0); - if ((object = mutt_getvaluebyname (buf->data, Fields)) == -1) - { + if ((object = mutt_getvaluebyname (buf->data, Fields)) == -1) { snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); return (-1); } - if (mutt_strncmp (buf->data, "index", 5) != 0) - { + if (mutt_strncmp (buf->data, "index", 5) != 0) { snprintf (err->data, err->dsize, - _("%s: command valid only for index object"), - parse_uncolor ? "uncolor" : "unmono"); + _("%s: command valid only for index object"), + parse_uncolor ? "uncolor" : "unmono"); return (-1); } - - if (!MoreArgs (s)) - { + + if (!MoreArgs (s)) { snprintf (err->data, err->dsize, - _("%s: too few arguments"), parse_uncolor ? "uncolor" : "unmono"); + _("%s: too few arguments"), + parse_uncolor ? "uncolor" : "unmono"); return (-1); } - if( + if ( #ifdef HAVE_COLOR - /* we're running without curses */ - option (OPTNOCURSES) - || /* we're parsing an uncolor command, and have no colors */ - (parse_uncolor && !has_colors()) - /* we're parsing an unmono command, and have colors */ - || (!parse_uncolor && has_colors()) + /* we're running without curses */ + option (OPTNOCURSES) + || /* we're parsing an uncolor command, and have no colors */ + (parse_uncolor && !has_colors ()) + /* we're parsing an unmono command, and have colors */ + || (!parse_uncolor && has_colors ()) #else - /* We don't even have colors compiled in */ - parse_uncolor + /* We don't even have colors compiled in */ + parse_uncolor #endif - ) - { + ) { /* just eat the command, but don't do anything real about it */ do mutt_extract_token (buf, s, 0); @@ -418,49 +402,45 @@ _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err, return 0; } - - - do - { + + + do { mutt_extract_token (buf, s, 0); - if (!mutt_strcmp ("*", buf->data)) - { - for (tmp = ColorIndexList; tmp; ) - { + if (!mutt_strcmp ("*", buf->data)) { + for (tmp = ColorIndexList; tmp;) { if (!do_cache) - do_cache = 1; - last = tmp; - tmp = tmp->next; - mutt_free_color_line(&last, parse_uncolor); + do_cache = 1; + last = tmp; + tmp = tmp->next; + mutt_free_color_line (&last, parse_uncolor); } ColorIndexList = NULL; } - else - { - for (last = NULL, tmp = ColorIndexList; tmp; last = tmp, tmp = tmp->next) - { - if (!mutt_strcmp (buf->data, tmp->pattern)) - { + else { + for (last = NULL, tmp = ColorIndexList; tmp; + last = tmp, tmp = tmp->next) { + if (!mutt_strcmp (buf->data, tmp->pattern)) { if (!do_cache) - do_cache = 1; - dprint(1,(debugfile,"Freeing pattern \"%s\" from ColorIndexList\n", - tmp->pattern)); - if (last) - last->next = tmp->next; - else - ColorIndexList = tmp->next; - mutt_free_color_line(&tmp, parse_uncolor); - break; - } + do_cache = 1; + dprint (1, + (debugfile, "Freeing pattern \"%s\" from ColorIndexList\n", + tmp->pattern)); + if (last) + last->next = tmp->next; + else + ColorIndexList = tmp->next; + mutt_free_color_line (&tmp, parse_uncolor); + break; + } } } } while (MoreArgs (s)); - if (do_cache && !option (OPTNOCURSES)) - { + if (do_cache && !option (OPTNOCURSES)) { int i; + set_option (OPTFORCEREDRAWINDEX); /* force re-caching of index colors */ for (i = 0; Context && i < Context->msgcount; i++) @@ -470,10 +450,9 @@ _mutt_parse_uncolor (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err, } -static int -add_pattern (COLOR_LINE **top, const char *s, int sensitive, - int fg, int bg, int attr, BUFFER *err, - int is_index) +static int +add_pattern (COLOR_LINE ** top, const char *s, int sensitive, + int fg, int bg, int attr, BUFFER * err, int is_index) { /* is_index used to store compiled pattern @@ -482,71 +461,64 @@ add_pattern (COLOR_LINE **top, const char *s, int sensitive, COLOR_LINE *tmp = *top; - while (tmp) - { - if (sensitive) - { + while (tmp) { + if (sensitive) { if (mutt_strcmp (s, tmp->pattern) == 0) - break; + break; } - else - { + else { if (mutt_strcasecmp (s, tmp->pattern) == 0) - break; + break; } tmp = tmp->next; } - if (tmp) - { + if (tmp) { #ifdef HAVE_COLOR - if (fg != -1 && bg != -1) - { - if (tmp->fg != fg || tmp->bg != bg) - { - mutt_free_color (tmp->fg, tmp->bg); - tmp->fg = fg; - tmp->bg = bg; - attr |= mutt_alloc_color (fg, bg); + if (fg != -1 && bg != -1) { + if (tmp->fg != fg || tmp->bg != bg) { + mutt_free_color (tmp->fg, tmp->bg); + tmp->fg = fg; + tmp->bg = bg; + attr |= mutt_alloc_color (fg, bg); } else - attr |= (tmp->pair & ~A_BOLD); + attr |= (tmp->pair & ~A_BOLD); } #endif /* HAVE_COLOR */ tmp->pair = attr; } - else - { + else { int r; char buf[STRING]; tmp = mutt_new_color_line (); - if (is_index) - { + if (is_index) { int i; - strfcpy(buf, NONULL(s), sizeof(buf)); - mutt_check_simple (buf, sizeof (buf), NONULL(SimpleSearch)); - if((tmp->color_pattern = mutt_pattern_comp (buf, M_FULL_MSG, err)) == NULL) - { - mutt_free_color_line(&tmp, 1); - return -1; + strfcpy (buf, NONULL (s), sizeof (buf)); + mutt_check_simple (buf, sizeof (buf), NONULL (SimpleSearch)); + if ((tmp->color_pattern = + mutt_pattern_comp (buf, M_FULL_MSG, err)) == NULL) { + mutt_free_color_line (&tmp, 1); + return -1; } /* force re-caching of index colors */ for (i = 0; Context && i < Context->msgcount; i++) - Context->hdrs[i]->pair = 0; + Context->hdrs[i]->pair = 0; } - else if ((r = REGCOMP (&tmp->rx, s, (sensitive ? mutt_which_case (s) : REG_ICASE))) != 0) - { + else + if ((r = + REGCOMP (&tmp->rx, s, + (sensitive ? mutt_which_case (s) : REG_ICASE))) != 0) { regerror (r, &tmp->rx, err->data, err->dsize); - mutt_free_color_line(&tmp, 1); + mutt_free_color_line (&tmp, 1); return (-1); } tmp->next = *top; tmp->pattern = safe_strdup (s); #ifdef HAVE_COLOR - if(fg != -1 && bg != -1) - { + if (fg != -1 && bg != -1) { tmp->fg = fg; tmp->bg = bg; attr |= mutt_alloc_color (fg, bg); @@ -560,36 +532,31 @@ add_pattern (COLOR_LINE **top, const char *s, int sensitive, } static int -parse_object(BUFFER *buf, BUFFER *s, int *o, int *ql, BUFFER *err) +parse_object (BUFFER * buf, BUFFER * s, int *o, int *ql, BUFFER * err) { int q_level = 0; char *eptr; - - if(!MoreArgs(s)) - { - strfcpy(err->data, _("Missing arguments."), err->dsize); + + if (!MoreArgs (s)) { + strfcpy (err->data, _("Missing arguments."), err->dsize); return -1; } - - mutt_extract_token(buf, s, 0); - if(!mutt_strncmp(buf->data, "quoted", 6)) - { - if(buf->data[6]) - { - *ql = strtol(buf->data + 6, &eptr, 10); - if(*eptr || q_level < 0) - { - snprintf(err->data, err->dsize, _("%s: no such object"), buf->data); - return -1; + + mutt_extract_token (buf, s, 0); + if (!mutt_strncmp (buf->data, "quoted", 6)) { + if (buf->data[6]) { + *ql = strtol (buf->data + 6, &eptr, 10); + if (*eptr || q_level < 0) { + snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); + return -1; } } else *ql = 0; - + *o = MT_COLOR_QUOTED; } - else if ((*o = mutt_getvaluebyname (buf->data, Fields)) == -1) - { + else if ((*o = mutt_getvaluebyname (buf->data, Fields)) == -1) { snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); return (-1); } @@ -597,15 +564,16 @@ parse_object(BUFFER *buf, BUFFER *s, int *o, int *ql, BUFFER *err) return 0; } -typedef int (*parser_callback_t)(BUFFER *, BUFFER *, int *, int *, int *, BUFFER *); +typedef int (*parser_callback_t) (BUFFER *, BUFFER *, int *, int *, int *, + BUFFER *); #ifdef HAVE_COLOR static int -parse_color_pair(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err) +parse_color_pair (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, + BUFFER * err) { - if (! MoreArgs (s)) - { + if (!MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } @@ -615,31 +583,32 @@ parse_color_pair(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *er if (parse_color_name (buf->data, fg, attr, A_BOLD, err) != 0) return (-1); - if (! MoreArgs (s)) - { + if (!MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } - + mutt_extract_token (buf, s, 0); if (parse_color_name (buf->data, bg, attr, A_BLINK, err) != 0) return (-1); - + return 0; } #endif static int -parse_attr_spec(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err) +parse_attr_spec (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, + BUFFER * err) { - - if(fg) *fg = -1; - if(bg) *bg = -1; - if (! MoreArgs (s)) - { + if (fg) + *fg = -1; + if (bg) + *bg = -1; + + if (!MoreArgs (s)) { strfcpy (err->data, _("mono: too few arguments"), err->dsize); return (-1); } @@ -657,21 +626,20 @@ parse_attr_spec(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err else if (ascii_strcasecmp ("standout", buf->data) == 0) *attr |= A_STANDOUT; else if (ascii_strcasecmp ("normal", buf->data) == 0) - *attr = A_NORMAL; /* needs use = instead of |= to clear other bits */ - else - { + *attr = A_NORMAL; /* needs use = instead of |= to clear other bits */ + else { snprintf (err->data, err->dsize, _("%s: no such attribute"), buf->data); return (-1); } - + return 0; } -static int fgbgattr_to_color(int fg, int bg, int attr) +static int fgbgattr_to_color (int fg, int bg, int attr) { #ifdef HAVE_COLOR - if(fg != -1 && bg != -1) - return attr | mutt_alloc_color(fg, bg); + if (fg != -1 && bg != -1) + return attr | mutt_alloc_color (fg, bg); else #endif return attr; @@ -681,95 +649,88 @@ static int fgbgattr_to_color(int fg, int bg, int attr) * mono [ ] */ -static int -_mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, - parser_callback_t callback, short dry_run) +static int +_mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, + parser_callback_t callback, short dry_run) { int object = 0, attr = 0, fg = 0, bg = 0, q_level = 0; int r = 0; - if(parse_object(buf, s, &object, &q_level, err) == -1) + if (parse_object (buf, s, &object, &q_level, err) == -1) return -1; - if(callback(buf, s, &fg, &bg, &attr, err) == -1) + if (callback (buf, s, &fg, &bg, &attr, err) == -1) return -1; /* extract a regular expression if needed */ - - if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX) - { - if (!MoreArgs (s)) - { + + if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY + || object == MT_COLOR_INDEX) { + if (!MoreArgs (s)) { strfcpy (err->data, _("too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); } - - if (MoreArgs (s)) - { + + if (MoreArgs (s)) { strfcpy (err->data, _("too many arguments"), err->dsize); return (-1); } - + /* dry run? */ - - if(dry_run) return 0; - + if (dry_run) + return 0; + + #ifdef HAVE_COLOR # ifdef HAVE_USE_DEFAULT_COLORS - if (!option (OPTNOCURSES) && has_colors() - /* delay use_default_colors() until needed, since it initializes things */ - && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) - && use_default_colors () != OK) - { + if (!option (OPTNOCURSES) && has_colors () + /* delay use_default_colors() until needed, since it initializes things */ + && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) + && use_default_colors () != OK) { strfcpy (err->data, _("default colors not supported"), err->dsize); return (-1); } # endif /* HAVE_USE_DEFAULT_COLORS */ #endif - + if (object == MT_COLOR_HEADER) - r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0); + r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err, 0); else if (object == MT_COLOR_BODY) r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0); - else if (object == MT_COLOR_INDEX) - { + else if (object == MT_COLOR_INDEX) { r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); } - else if (object == MT_COLOR_QUOTED) - { - if (q_level >= ColorQuoteSize) - { + else if (object == MT_COLOR_QUOTED) { + if (q_level >= ColorQuoteSize) { safe_realloc (&ColorQuote, (ColorQuoteSize += 2) * sizeof (int)); - ColorQuote[ColorQuoteSize-2] = ColorDefs[MT_COLOR_QUOTED]; - ColorQuote[ColorQuoteSize-1] = ColorDefs[MT_COLOR_QUOTED]; + ColorQuote[ColorQuoteSize - 2] = ColorDefs[MT_COLOR_QUOTED]; + ColorQuote[ColorQuoteSize - 1] = ColorDefs[MT_COLOR_QUOTED]; } if (q_level >= ColorQuoteUsed) ColorQuoteUsed = q_level + 1; - if (q_level == 0) - { - ColorDefs[MT_COLOR_QUOTED] = fgbgattr_to_color(fg, bg, attr); - + if (q_level == 0) { + ColorDefs[MT_COLOR_QUOTED] = fgbgattr_to_color (fg, bg, attr); + ColorQuote[0] = ColorDefs[MT_COLOR_QUOTED]; - for (q_level = 1; q_level < ColorQuoteUsed; q_level++) - { - if (ColorQuote[q_level] == A_NORMAL) - ColorQuote[q_level] = ColorDefs[MT_COLOR_QUOTED]; + for (q_level = 1; q_level < ColorQuoteUsed; q_level++) { + if (ColorQuote[q_level] == A_NORMAL) + ColorQuote[q_level] = ColorDefs[MT_COLOR_QUOTED]; } } else - ColorQuote[q_level] = fgbgattr_to_color(fg, bg, attr); + ColorQuote[q_level] = fgbgattr_to_color (fg, bg, attr); } else - ColorDefs[object] = fgbgattr_to_color(fg, bg, attr); + ColorDefs[object] = fgbgattr_to_color (fg, bg, attr); #ifdef HAVE_COLOR # ifdef HAVE_BKGDSET - if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors()) + if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors ()) BKGDSET (MT_COLOR_NORMAL); # endif #endif @@ -779,30 +740,31 @@ _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, #ifdef HAVE_COLOR -int mutt_parse_color(BUFFER *buff, BUFFER *s, unsigned long data, BUFFER *err) +int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data, + BUFFER * err) { int dry_run = 0; - - if(option(OPTNOCURSES) || !has_colors()) + + if (option (OPTNOCURSES) || !has_colors ()) dry_run = 1; - - return _mutt_parse_color(buff, s, err, parse_color_pair, dry_run); + + return _mutt_parse_color (buff, s, err, parse_color_pair, dry_run); } #endif -int mutt_parse_mono(BUFFER *buff, BUFFER *s, unsigned long data, BUFFER *err) +int mutt_parse_mono (BUFFER * buff, BUFFER * s, unsigned long data, + BUFFER * err) { int dry_run = 0; - + #ifdef HAVE_COLOR - if(option(OPTNOCURSES) || has_colors()) + if (option (OPTNOCURSES) || has_colors ()) dry_run = 1; #else - if(option(OPTNOCURSES)) + if (option (OPTNOCURSES)) dry_run = 1; #endif - return _mutt_parse_color(buff, s, err, parse_attr_spec, dry_run); + return _mutt_parse_color (buff, s, err, parse_attr_spec, dry_run); } - diff --git a/commands.c b/commands.c index 86a83ba..33051bb 100644 --- a/commands.c +++ b/commands.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -59,7 +59,7 @@ extern char *ReleaseDate; /* The folder the user last saved to. Used by ci_save_message() */ static char LastSaveFolder[_POSIX_PATH_MAX] = ""; -int mutt_display_message (HEADER *cur) +int mutt_display_message (HEADER * cur) { char tempfile[_POSIX_PATH_MAX], buf[LONG_STRING]; int rc = 0, builtin = 0; @@ -70,40 +70,35 @@ int mutt_display_message (HEADER *cur) int res; snprintf (buf, sizeof (buf), "%s/%s", TYPE (cur->content), - cur->content->subtype); + cur->content->subtype); mutt_parse_mime_message (Context, cur); mutt_message_hook (Context, cur, M_MESSAGEHOOK); /* see if crytpo is needed for this message. if so, we should exit curses */ - if (WithCrypto && cur->security) - { - if (cur->security & ENCRYPT) - { + if (WithCrypto && cur->security) { + if (cur->security & ENCRYPT) { if (cur->security & APPLICATION_SMIME) - crypt_smime_getkeys (cur->env); - if(!crypt_valid_passphrase(cur->security)) - return 0; + crypt_smime_getkeys (cur->env); + if (!crypt_valid_passphrase (cur->security)) + return 0; cmflags |= M_CM_VERIFY; } - else if (cur->security & SIGN) - { + else if (cur->security & SIGN) { /* find out whether or not the verify signature */ - if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == M_YES) - { - cmflags |= M_CM_VERIFY; + if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == + M_YES) { + cmflags |= M_CM_VERIFY; } } } - - if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT) - { - if (cur->security & APPLICATION_PGP) - { + + if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT) { + if (cur->security & APPLICATION_PGP) { if (cur->env->from) crypt_pgp_invoke_getkeys (cur->env->from); - + crypt_invoke_message (APPLICATION_PGP); } @@ -113,21 +108,19 @@ int mutt_display_message (HEADER *cur) mutt_mktemp (tempfile); - if ((fpout = safe_fopen (tempfile, "w")) == NULL) - { + if ((fpout = safe_fopen (tempfile, "w")) == NULL) { mutt_error _("Could not create temporary file!"); + return (0); } - if (DisplayFilter && *DisplayFilter) - { + if (DisplayFilter && *DisplayFilter) { fpfilterout = fpout; fpout = NULL; /* mutt_endwin (NULL); */ filterpid = mutt_create_filter_fd (DisplayFilter, &fpout, NULL, NULL, - -1, fileno(fpfilterout), -1); - if (filterpid < 0) - { + -1, fileno (fpfilterout), -1); + if (filterpid < 0) { mutt_error (_("Cannot create display filter")); safe_fclose (&fpfilterout); unlink (tempfile); @@ -137,20 +130,18 @@ int mutt_display_message (HEADER *cur) if (!Pager || mutt_strcmp (Pager, "builtin") == 0) builtin = 1; - else - { - mutt_make_string (buf, sizeof (buf), NONULL(PagerFmt), Context, cur); + else { + mutt_make_string (buf, sizeof (buf), NONULL (PagerFmt), Context, cur); fputs (buf, fpout); fputs ("\n\n", fpout); } res = mutt_copy_message (fpout, Context, cur, cmflags, - (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE | CH_FROM); - if ((safe_fclose (&fpout) != 0 && errno != EPIPE) || res == -1) - { + (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | + CH_DECODE | CH_FROM); + if ((safe_fclose (&fpout) != 0 && errno != EPIPE) || res == -1) { mutt_error (_("Could not copy message")); - if (fpfilterout != NULL) - { + if (fpfilterout != NULL) { mutt_wait_filter (filterpid); safe_fclose (&fpfilterout); } @@ -161,48 +152,45 @@ int mutt_display_message (HEADER *cur) if (fpfilterout != NULL && mutt_wait_filter (filterpid) != 0) mutt_any_key_to_continue (NULL); - safe_fclose (&fpfilterout); /* XXX - check result? */ + safe_fclose (&fpfilterout); /* XXX - check result? */ + - - if (WithCrypto) - { + if (WithCrypto) { /* update crypto information for this message */ cur->security |= crypt_query (cur->content); - + /* Remove color cache for this message, in case there are color patterns for both ~g and ~V */ cur->pair = 0; } - if (builtin) - { + if (builtin) { pager_t info; - if (WithCrypto - && (cur->security & APPLICATION_SMIME) && (cmflags & M_CM_VERIFY)) - { - if (cur->security & GOODSIGN) - { - if (!crypt_smime_verify_sender(cur)) - mutt_message ( _("S/MIME signature successfully verified.")); - else - mutt_error ( _("S/MIME certificate owner does not match sender.")); + if (WithCrypto + && (cur->security & APPLICATION_SMIME) && (cmflags & M_CM_VERIFY)) { + if (cur->security & GOODSIGN) { + if (!crypt_smime_verify_sender (cur)) + mutt_message (_("S/MIME signature successfully verified.")); + else + mutt_error (_("S/MIME certificate owner does not match sender.")); } else if (cur->security & PARTSIGN) - mutt_message (_("Warning: Part of this message has not been signed.")); + mutt_message (_ + ("Warning: Part of this message has not been signed.")); else if (cur->security & SIGN || cur->security & BADSIGN) - mutt_error ( _("S/MIME signature could NOT be verified.")); + mutt_error (_("S/MIME signature could NOT be verified.")); } - if (WithCrypto - && (cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) - { + if (WithCrypto + && (cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) { if (cur->security & GOODSIGN) - mutt_message (_("PGP signature successfully verified.")); + mutt_message (_("PGP signature successfully verified.")); else if (cur->security & PARTSIGN) - mutt_message (_("Warning: Part of this message has not been signed.")); + mutt_message (_ + ("Warning: Part of this message has not been signed.")); else - mutt_message (_("PGP signature could NOT be verified.")); + mutt_message (_("PGP signature could NOT be verified.")); } /* Invoke the builtin pager */ @@ -211,20 +199,18 @@ int mutt_display_message (HEADER *cur) info.ctx = Context; rc = mutt_pager (NULL, tempfile, M_PAGER_MESSAGE, &info); } - else - { + else { int r; mutt_endwin (NULL); - snprintf (buf, sizeof (buf), "%s %s", NONULL(Pager), tempfile); + snprintf (buf, sizeof (buf), "%s %s", NONULL (Pager), tempfile); if ((r = mutt_system (buf)) == -1) mutt_error (_("Error running \"%s\"!"), buf); unlink (tempfile); keypad (stdscr, TRUE); if (r != -1) mutt_set_flag (Context, cur, M_READ, 1); - if (r != -1 && option (OPTPROMPTAFTER)) - { + if (r != -1 && option (OPTPROMPTAFTER)) { mutt_ungetch (mutt_any_key_to_continue _("Command: "), 0); rc = km_dokey (MENU_PAGER); } @@ -235,7 +221,7 @@ int mutt_display_message (HEADER *cur) return rc; } -void ci_bounce_message (HEADER *h, int *redraw) +void ci_bounce_message (HEADER * h, int *redraw) { char prompt[SHORT_STRING]; char buf[HUGE_STRING] = { 0 }; @@ -243,15 +229,14 @@ void ci_bounce_message (HEADER *h, int *redraw) char *err = NULL; int rc; - if(h) - strfcpy(prompt, _("Bounce message to: "), sizeof(prompt)); + if (h) + strfcpy (prompt, _("Bounce message to: "), sizeof (prompt)); else - strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt)); - + strfcpy (prompt, _("Bounce tagged messages to: "), sizeof (prompt)); + rc = mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS); - if (option (OPTNEEDREDRAW)) - { + if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); *redraw = REDRAW_FULL; } @@ -259,16 +244,15 @@ void ci_bounce_message (HEADER *h, int *redraw) if (rc || !buf[0]) return; - if (!(adr = rfc822_parse_adrlist (adr, buf))) - { + if (!(adr = rfc822_parse_adrlist (adr, buf))) { mutt_error _("Error parsing address!"); + return; } adr = mutt_expand_aliases (adr); - if (mutt_addrlist_to_idna (adr, &err) < 0) - { + if (mutt_addrlist_to_idna (adr, &err) < 0) { mutt_error (_("Bad IDN: '%s'"), err); FREE (&err); rfc822_free_address (&adr); @@ -280,20 +264,19 @@ void ci_bounce_message (HEADER *h, int *redraw) #define extra_space (15 + 7 + 2) snprintf (prompt, sizeof (prompt), - (h ? _("Bounce message to %s") : _("Bounce messages to %s")), buf); + (h ? _("Bounce message to %s") : _("Bounce messages to %s")), + buf); - if (mutt_strwidth (prompt) > COLS - extra_space) - { + if (mutt_strwidth (prompt) > COLS - extra_space) { mutt_format_string (prompt, sizeof (prompt), - 0, COLS-extra_space, 0, 0, - prompt, sizeof (prompt), 0); + 0, COLS - extra_space, 0, 0, + prompt, sizeof (prompt), 0); safe_strcat (prompt, sizeof (prompt), "...?"); } else safe_strcat (prompt, sizeof (prompt), "?"); - if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) - { + if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) { rfc822_free_address (&adr); CLEARLINE (LINES - 1); mutt_message (h ? _("Message not bounced.") : _("Messages not bounced.")); @@ -301,7 +284,7 @@ void ci_bounce_message (HEADER *h, int *redraw) } CLEARLINE (LINES - 1); - + rc = mutt_bounce_message (NULL, h, adr); rfc822_free_address (&adr); /* If no error, or background, display message. */ @@ -311,33 +294,30 @@ void ci_bounce_message (HEADER *h, int *redraw) static void pipe_set_flags (int decode, int print, int *cmflags, int *chflags) { - if (decode) - { + if (decode) { *cmflags |= M_CM_DECODE | M_CM_CHARCONV; *chflags |= CH_DECODE | CH_REORDER; - - if (option (OPTWEED)) - { + + if (option (OPTWEED)) { *chflags |= CH_WEED; *cmflags |= M_CM_WEED; } } - + if (print) *cmflags |= M_CM_PRINTING; - + } -static void pipe_msg (HEADER *h, FILE *fp, int decode, int print) +static void pipe_msg (HEADER * h, FILE * fp, int decode, int print) { int cmflags = 0; int chflags = CH_FROM; - + pipe_set_flags (decode, print, &cmflags, &chflags); - if (WithCrypto && decode && h->security & ENCRYPT) - { - if(!crypt_valid_passphrase(h->security)) + if (WithCrypto && decode && h->security & ENCRYPT) { + if (!crypt_valid_passphrase (h->security)) return; endwin (); } @@ -351,105 +331,97 @@ static void pipe_msg (HEADER *h, FILE *fp, int decode, int print) /* the following code is shared between printing and piping */ -static int _mutt_pipe_message (HEADER *h, char *cmd, - int decode, - int print, - int split, - char *sep) +static int _mutt_pipe_message (HEADER * h, char *cmd, + int decode, int print, int split, char *sep) { - + int i, rc = 0; pid_t thepid; FILE *fpout; - + /* mutt_endwin (NULL); is this really needed here ? it makes the screen flicker on pgp and s/mime messages, before asking for a passphrase... Oliver Ehli */ - if (h) - { + if (h) { mutt_message_hook (Context, h, M_MESSAGEHOOK); - if (WithCrypto && decode) - { + if (WithCrypto && decode) { mutt_parse_mime_message (Context, h); - if(h->security & ENCRYPT && !crypt_valid_passphrase(h->security)) - return 1; + if (h->security & ENCRYPT && !crypt_valid_passphrase (h->security)) + return 1; } mutt_endwin (NULL); - if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) - { + if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) { mutt_perror _("Can't create filter process"); + return 1; } - + pipe_msg (h, fpout, decode, print); fclose (fpout); rc = mutt_wait_filter (thepid); } - else - { /* handle tagged messages */ + else { /* handle tagged messages */ - if (WithCrypto && decode) - { + if (WithCrypto && decode) { for (i = 0; i < Context->vcount; i++) - if(Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); - mutt_parse_mime_message(Context, Context->hdrs[Context->v2r[i]]); - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && - !crypt_valid_passphrase(Context->hdrs[Context->v2r[i]]->security)) - return 1; - } + if (Context->hdrs[Context->v2r[i]]->tagged) { + mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], + M_MESSAGEHOOK); + mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]); + if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && + !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]-> + security)) + return 1; + } } - - if (split) - { - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); - mutt_endwin (NULL); - if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) - { - mutt_perror _("Can't create filter process"); - return 1; - } + + if (split) { + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]]->tagged) { + mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], + M_MESSAGEHOOK); + mutt_endwin (NULL); + if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) { + mutt_perror _("Can't create filter process"); + + return 1; + } pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode, print); /* add the message separator */ - if (sep) fputs (sep, fpout); - safe_fclose (&fpout); - if (mutt_wait_filter (thepid) != 0) - rc = 1; + if (sep) + fputs (sep, fpout); + safe_fclose (&fpout); + if (mutt_wait_filter (thepid) != 0) + rc = 1; } } } - else - { + else { mutt_endwin (NULL); - if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) - { - mutt_perror _("Can't create filter process"); - return 1; + if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) { + mutt_perror _("Can't create filter process"); + + return 1; } - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]]->tagged) { + mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], + M_MESSAGEHOOK); pipe_msg (Context->hdrs[Context->v2r[i]], fpout, decode, print); /* add the message separator */ - if (sep) fputs (sep, fpout); + if (sep) + fputs (sep, fpout); } } safe_fclose (&fpout); if (mutt_wait_filter (thepid) != 0) - rc = 1; + rc = 1; } } @@ -458,7 +430,7 @@ static int _mutt_pipe_message (HEADER *h, char *cmd, return rc; } -void mutt_pipe_message (HEADER *h) +void mutt_pipe_message (HEADER * h) { char buffer[LONG_STRING]; @@ -469,94 +441,91 @@ void mutt_pipe_message (HEADER *h) mutt_expand_path (buffer, sizeof (buffer)); _mutt_pipe_message (h, buffer, - option (OPTPIPEDECODE), - 0, - option (OPTPIPESPLIT), - PipeSep); + option (OPTPIPEDECODE), + 0, option (OPTPIPESPLIT), PipeSep); } -void mutt_print_message (HEADER *h) +void mutt_print_message (HEADER * h) { - if (quadoption (OPT_PRINT) && (!PrintCmd || !*PrintCmd)) - { + if (quadoption (OPT_PRINT) && (!PrintCmd || !*PrintCmd)) { mutt_message (_("No printing command has been defined.")); return; } - + if (query_quadoption (OPT_PRINT, - h ? _("Print message?") : _("Print tagged messages?")) - != M_YES) + h ? _("Print message?") : _("Print tagged messages?")) + != M_YES) return; if (_mutt_pipe_message (h, PrintCmd, - option (OPTPRINTDECODE), - 1, - option (OPTPRINTSPLIT), - "\f") == 0) + option (OPTPRINTDECODE), + 1, option (OPTPRINTSPLIT), "\f") == 0) mutt_message (h ? _("Message printed") : _("Messages printed")); else mutt_message (h ? _("Message could not be printed") : - _("Messages could not be printed")); + _("Messages could not be printed")); } int mutt_select_sort (int reverse) { - int method = Sort; /* save the current method in case of abort */ + int method = Sort; /* save the current method in case of abort */ switch (mutt_multi_choice (reverse ? - _("Rev-Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: ") : - _("Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: "), - _("dfrsotuzcp"))) - { - case -1: /* abort - don't resort */ + _ + ("Rev-Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: ") + : + _ + ("Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: "), + _("dfrsotuzcp"))) { + case -1: /* abort - don't resort */ return -1; - case 1: /* (d)ate */ + case 1: /* (d)ate */ Sort = SORT_DATE; break; - case 2: /* (f)rm */ + case 2: /* (f)rm */ Sort = SORT_FROM; break; - - case 3: /* (r)ecv */ + + case 3: /* (r)ecv */ Sort = SORT_RECEIVED; break; - - case 4: /* (s)ubj */ + + case 4: /* (s)ubj */ Sort = SORT_SUBJECT; break; - - case 5: /* t(o) */ + + case 5: /* t(o) */ Sort = SORT_TO; break; - - case 6: /* (t)hread */ + + case 6: /* (t)hread */ Sort = SORT_THREADS; break; - - case 7: /* (u)nsort */ + + case 7: /* (u)nsort */ Sort = SORT_ORDER; break; - - case 8: /* si(z)e */ + + case 8: /* si(z)e */ Sort = SORT_SIZE; break; - - case 9: /* s(c)ore */ + + case 9: /* s(c)ore */ Sort = SORT_SCORE; break; - case 10: /* s(p)am */ + case 10: /* s(p)am */ Sort = SORT_SPAM; break; } if (reverse) Sort |= SORT_REVERSE; - return (Sort != method ? 0 : -1); /* no need to resort if it's the same */ + return (Sort != method ? 0 : -1); /* no need to resort if it's the same */ } /* invoke a command in a subshell */ @@ -565,17 +534,15 @@ void mutt_shell_escape (void) char buf[LONG_STRING]; buf[0] = 0; - if (mutt_get_field (_("Shell command: "), buf, sizeof (buf), M_CMD) == 0) - { + if (mutt_get_field (_("Shell command: "), buf, sizeof (buf), M_CMD) == 0) { if (!buf[0] && Shell) strfcpy (buf, Shell, sizeof (buf)); - if(buf[0]) - { - CLEARLINE (LINES-1); + if (buf[0]) { + CLEARLINE (LINES - 1); mutt_endwin (NULL); fflush (stdout); if (mutt_system (buf) != 0 || option (OPTWAITKEY)) - mutt_any_key_to_continue (NULL); + mutt_any_key_to_continue (NULL); } } } @@ -588,15 +555,15 @@ void mutt_enter_command (void) int r; buffer[0] = 0; - if (mutt_get_field (":", buffer, sizeof (buffer), M_COMMAND) != 0 || !buffer[0]) + if (mutt_get_field (":", buffer, sizeof (buffer), M_COMMAND) != 0 + || !buffer[0]) return; err.data = errbuf; err.dsize = sizeof (errbuf); memset (&token, 0, sizeof (token)); r = mutt_parse_rc_line (buffer, &token, &err); FREE (&token.data); - if (errbuf[0]) - { + if (errbuf[0]) { /* since errbuf could potentially contain printf() sequences in it, we must call mutt_error() in this fashion so that vsprintf() doesn't expect more arguments that we passed */ @@ -607,7 +574,7 @@ void mutt_enter_command (void) } } -void mutt_display_address (ENVELOPE *env) +void mutt_display_address (ENVELOPE * env) { char *pfx = NULL; char buf[SHORT_STRING]; @@ -615,92 +582,88 @@ void mutt_display_address (ENVELOPE *env) adr = mutt_get_address (env, &pfx); - if (!adr) return; - + if (!adr) + return; + /* * Note: We don't convert IDNA to local representation this time. * That is intentional, so the user has an opportunity to copy & * paste the on-the-wire form of the address to other, IDN-unable * software. */ - + buf[0] = 0; rfc822_write_address (buf, sizeof (buf), adr, 0); mutt_message ("%s: %s", pfx, buf); } -static void set_copy_flags (HEADER *hdr, int decode, int decrypt, int *cmflags, int *chflags) +static void set_copy_flags (HEADER * hdr, int decode, int decrypt, + int *cmflags, int *chflags) { *cmflags = 0; *chflags = CH_UPDATE_LEN; - - if (WithCrypto && !decode && decrypt && (hdr->security & ENCRYPT)) - { + + if (WithCrypto && !decode && decrypt && (hdr->security & ENCRYPT)) { if ((WithCrypto & APPLICATION_PGP) - && mutt_is_multipart_encrypted(hdr->content)) - { + && mutt_is_multipart_encrypted (hdr->content)) { *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_PGP; } else if ((WithCrypto & APPLICATION_PGP) - && mutt_is_application_pgp (hdr->content) & ENCRYPT) + && mutt_is_application_pgp (hdr->content) & ENCRYPT) decode = 1; else if ((WithCrypto & APPLICATION_SMIME) - && mutt_is_application_smime(hdr->content) & ENCRYPT) - { + && mutt_is_application_smime (hdr->content) & ENCRYPT) { *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_SMIME; } } - if (decode) - { + if (decode) { *chflags = CH_XMIT | CH_MIME | CH_TXTPLAIN; *cmflags = M_CM_DECODE | M_CM_CHARCONV; - if (!decrypt) /* If decode doesn't kick in for decrypt, */ - { - *chflags |= CH_DECODE; /* then decode RFC 2047 headers, */ + if (!decrypt) { /* If decode doesn't kick in for decrypt, */ + *chflags |= CH_DECODE; /* then decode RFC 2047 headers, */ - if (option (OPTWEED)) - { - *chflags |= CH_WEED; /* and respect $weed. */ - *cmflags |= M_CM_WEED; + if (option (OPTWEED)) { + *chflags |= CH_WEED; /* and respect $weed. */ + *cmflags |= M_CM_WEED; } } } } -void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int decrypt) +void _mutt_save_message (HEADER * h, CONTEXT * ctx, int delete, int decode, + int decrypt) { int cmflags, chflags; - + set_copy_flags (h, decode, decrypt, &cmflags, &chflags); if (decode || decrypt) mutt_parse_mime_message (Context, h); - if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0) - { - if (delete) - { + if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0) { + if (delete) { mutt_set_flag (Context, h, M_DELETE, 1); if (option (OPTDELETEUNTAG)) - mutt_set_flag (Context, h, M_TAG, 0); + mutt_set_flag (Context, h, M_TAG, 0); } mutt_set_flag (Context, h, M_APPENDED, 1); } } /* returns 0 if the copy/save was successful, or -1 on error/abort */ -int mutt_save_message (HEADER *h, int delete, - int decode, int decrypt, int *redraw) +int mutt_save_message (HEADER * h, int delete, + int decode, int decrypt, int *redraw) { int i, need_buffy_cleanup; - int need_passphrase = 0, app=0; + int need_passphrase = 0, app = 0; char prompt[SHORT_STRING], buf[_POSIX_PATH_MAX]; CONTEXT ctx; struct stat st; + #ifdef BUFFY_SIZE BUFFY *tmp = NULL; #else @@ -709,46 +672,39 @@ int mutt_save_message (HEADER *h, int delete, *redraw = 0; - + snprintf (prompt, sizeof (prompt), - decode ? (delete ? _("Decode-save%s to mailbox") : - _("Decode-copy%s to mailbox")) : - (decrypt ? (delete ? _("Decrypt-save%s to mailbox") : - _("Decrypt-copy%s to mailbox")) : - (delete ? _("Save%s to mailbox") : _("Copy%s to mailbox"))), - h ? "" : _(" tagged")); - + decode ? (delete ? _("Decode-save%s to mailbox") : + _("Decode-copy%s to mailbox")) : + (decrypt ? (delete ? _("Decrypt-save%s to mailbox") : + _("Decrypt-copy%s to mailbox")) : + (delete ? _("Save%s to mailbox") : _("Copy%s to mailbox"))), + h ? "" : _(" tagged")); - if (h) - { - if (WithCrypto) - { + + if (h) { + if (WithCrypto) { need_passphrase = h->security & ENCRYPT; app = h->security; } mutt_message_hook (Context, h, M_MESSAGEHOOK); mutt_default_save (buf, sizeof (buf), h); } - else - { + else { /* look for the first tagged message */ - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - h = Context->hdrs[Context->v2r[i]]; - break; + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]]->tagged) { + h = Context->hdrs[Context->v2r[i]]; + break; } } - if (h) - { + if (h) { mutt_message_hook (Context, h, M_MESSAGEHOOK); mutt_default_save (buf, sizeof (buf), h); - if (WithCrypto) - { + if (WithCrypto) { need_passphrase = h->security & ENCRYPT; app = h->security; } @@ -760,8 +716,7 @@ int mutt_save_message (HEADER *h, int delete, if (mutt_enter_fname (prompt, buf, sizeof (buf), redraw, 0) == -1) return (-1); - if (*redraw != REDRAW_FULL) - { + if (*redraw != REDRAW_FULL) { if (!h) *redraw = REDRAW_INDEX | REDRAW_STATUS; else @@ -770,7 +725,7 @@ int mutt_save_message (HEADER *h, int delete, if (!buf[0]) return (-1); - + /* This is an undocumented feature of ELM pointed out to me by Felix von * Leitner */ @@ -786,41 +741,39 @@ int mutt_save_message (HEADER *h, int delete, return -1; if (WithCrypto && need_passphrase && (decode || decrypt) - && !crypt_valid_passphrase(app)) + && !crypt_valid_passphrase (app)) return -1; - + mutt_message (_("Copying to %s..."), buf); - + #ifdef USE_IMAP - if (Context->magic == M_IMAP && - !(decode || decrypt) && mx_is_imap (buf)) - { - switch (imap_copy_messages (Context, h, buf, delete)) - { + if (Context->magic == M_IMAP && !(decode || decrypt) && mx_is_imap (buf)) { + switch (imap_copy_messages (Context, h, buf, delete)) { /* success */ - case 0: mutt_clear_error (); return 0; + case 0: + mutt_clear_error (); + return 0; /* non-fatal error: fall through to fetch/append */ - case 1: break; + case 1: + break; /* fatal error, abort */ - case -1: return -1; + case -1: + return -1; } } #endif - if (mx_open_mailbox (buf, M_APPEND, &ctx) != NULL) - { + if (mx_open_mailbox (buf, M_APPEND, &ctx) != NULL) { if (h) - _mutt_save_message(h, &ctx, delete, decode, decrypt); - else - { - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK); - _mutt_save_message(Context->hdrs[Context->v2r[i]], - &ctx, delete, decode, decrypt); - } + _mutt_save_message (h, &ctx, delete, decode, decrypt); + else { + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]]->tagged) { + mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], + M_MESSAGEHOOK); + _mutt_save_message (Context->hdrs[Context->v2r[i]], &ctx, delete, + decode, decrypt); + } } } @@ -828,33 +781,32 @@ int mutt_save_message (HEADER *h, int delete, mx_close_mailbox (&ctx, NULL); - if (need_buffy_cleanup) - { + if (need_buffy_cleanup) { #ifdef BUFFY_SIZE tmp = mutt_find_mailbox (buf); if (tmp && tmp->new <= 0) - mutt_update_mailbox (tmp); + mutt_update_mailbox (tmp); #else /* fix up the times so buffy won't get confused */ - if (st.st_mtime > st.st_atime) - { - ut.actime = st.st_atime; - ut.modtime = time (NULL); - utime (buf, &ut); + if (st.st_mtime > st.st_atime) { + ut.actime = st.st_atime; + ut.modtime = time (NULL); + utime (buf, &ut); } else - utime (buf, NULL); + utime (buf, NULL); #endif } mutt_clear_error (); return (0); } - + return -1; } -int mutt_update_list_file (char *filename, char *section, char *key, char *line) +int mutt_update_list_file (char *filename, char *section, char *key, + char *line) { FILE *ifp; FILE *ofp; @@ -863,95 +815,90 @@ int mutt_update_list_file (char *filename, char *section, char *key, char *line) char *c; int ext = 0, done = 0, r = 0; - snprintf (oldfile, sizeof(oldfile), "%s.bak", filename); + snprintf (oldfile, sizeof (oldfile), "%s.bak", filename); dprint (1, (debugfile, "Renaming %s to %s\n", filename, oldfile)); /* if file not exist, create it */ if ((ifp = safe_fopen (filename, "a"))) fclose (ifp); - if (_mutt_rename_file (filename, oldfile, 1)) - { + if (_mutt_rename_file (filename, oldfile, 1)) { mutt_perror _("Unable to create backup file"); + return (-1); } dprint (1, (debugfile, "Opening %s\n", oldfile)); - if (!(ifp = safe_fopen (oldfile, "r"))) - { + if (!(ifp = safe_fopen (oldfile, "r"))) { mutt_perror _("Unable to open backup file for reading"); + return (-1); } dprint (1, (debugfile, "Opening %s\n", filename)); - if (!(ofp = safe_fopen (filename, "w"))) - { + if (!(ofp = safe_fopen (filename, "w"))) { fclose (ifp); mutt_perror _("Unable to open new file for writing"); + return (-1); } - if (mx_lock_file (filename, fileno (ofp), 1, 0, 1)) - { + if (mx_lock_file (filename, fileno (ofp), 1, 0, 1)) { fclose (ofp); fclose (ifp); - mutt_error (_("Unable to lock %s, old file saved as %s"), filename, oldfile); + mutt_error (_("Unable to lock %s, old file saved as %s"), filename, + oldfile); return (-1); } - if (section) - { - while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) - { + if (section) { + while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) { r = fputs (buf, ofp); c = buf; - while (*c && *c != '\n') c++; - c[0] = 0; /* strip EOL */ - if (!strncmp (buf, "#: ", 3) && !mutt_strcasecmp (buf+3, section)) - done++; + while (*c && *c != '\n') + c++; + c[0] = 0; /* strip EOL */ + if (!strncmp (buf, "#: ", 3) && !mutt_strcasecmp (buf + 3, section)) + done++; } - if (r != EOF && !done) - { - snprintf (buf, sizeof(buf), "#: %s\n", section); + if (r != EOF && !done) { + snprintf (buf, sizeof (buf), "#: %s\n", section); r = fputs (buf, ofp); } done = 0; } - while (r != EOF && fgets (buf, sizeof (buf), ifp)) - { - if (ext) - { + while (r != EOF && fgets (buf, sizeof (buf), ifp)) { + if (ext) { c = buf; - while (*c && (*c != '\r') && (*c != '\n')) c++; + while (*c && (*c != '\r') && (*c != '\n')) + c++; c--; - if (*c != '\\') ext = 0; + if (*c != '\\') + ext = 0; } - else if ((section && !strncmp (buf, "#: ", 3))) - { - if (!done && line) - { - fputs (line, ofp); - fputc ('\n', ofp); + else if ((section && !strncmp (buf, "#: ", 3))) { + if (!done && line) { + fputs (line, ofp); + fputc ('\n', ofp); } r = fputs (buf, ofp); done++; break; } - else if (key && !strncmp (buf, key, strlen(key)) && - (!*key || buf[strlen(key)] == ' ')) - { + else if (key && !strncmp (buf, key, strlen (key)) && + (!*key || buf[strlen (key)] == ' ')) { c = buf; ext = 0; - while (*c && (*c != '\r') && (*c != '\n')) c++; + while (*c && (*c != '\r') && (*c != '\n')) + c++; c--; - if (*c == '\\') ext = 1; - if (!done && line) - { - r = fputs (line, ofp); - if (*key) - r = fputc ('\n', ofp); - done++; + if (*c == '\\') + ext = 1; + if (!done && line) { + r = fputs (line, ofp); + if (*key) + r = fputc ('\n', ofp); + done++; } } - else - { + else { r = fputs (buf, ofp); } } @@ -960,22 +907,20 @@ int mutt_update_list_file (char *filename, char *section, char *key, char *line) r = fputs (buf, ofp); /* If there wasn't a line to replace, put it on the end of the file */ - if (r != EOF && !done && line) - { + if (r != EOF && !done && line) { fputs (line, ofp); r = fputc ('\n', ofp); } mx_unlock_file (filename, fileno (ofp), 0); fclose (ofp); fclose (ifp); - if (r != EOF) - { + if (r != EOF) { unlink (oldfile); return 0; } unlink (filename); mutt_error (_("Cannot write new %s, old file saved as %s"), filename, - oldfile); + oldfile); return (-1); } @@ -985,7 +930,7 @@ void mutt_version (void) mutt_message ("Mutt-ng %s (%s)", MUTT_VERSION, ReleaseDate); } -void mutt_edit_content_type (HEADER *h, BODY *b, FILE *fp) +void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp) { char buf[LONG_STRING]; char obuf[LONG_STRING]; @@ -997,125 +942,120 @@ void mutt_edit_content_type (HEADER *h, BODY *b, FILE *fp) short charset_changed = 0; short type_changed = 0; - + cp = mutt_get_parameter ("charset", b->parameter); strfcpy (charset, NONULL (cp), sizeof (charset)); snprintf (buf, sizeof (buf), "%s/%s", TYPE (b), b->subtype); strfcpy (obuf, buf, sizeof (obuf)); - if (b->parameter) - { + if (b->parameter) { size_t l; - - for (p = b->parameter; p; p = p->next) - { + + for (p = b->parameter; p; p = p->next) { l = strlen (buf); rfc822_cat (tmp, sizeof (tmp), p->value, MimeSpecials); snprintf (buf + l, sizeof (buf) - l, "; %s=%s", p->attribute, tmp); } } - + if (mutt_get_field ("Content-Type: ", buf, sizeof (buf), 0) != 0 || buf[0] == 0) return; - + /* clean up previous junk */ mutt_free_parameter (&b->parameter); FREE (&b->subtype); - + mutt_parse_content_type (buf, b); - + snprintf (tmp, sizeof (tmp), "%s/%s", TYPE (b), NONULL (b->subtype)); type_changed = ascii_strcasecmp (tmp, obuf); - charset_changed = ascii_strcasecmp (charset, mutt_get_parameter ("charset", b->parameter)); + charset_changed = + ascii_strcasecmp (charset, mutt_get_parameter ("charset", b->parameter)); /* if in send mode, check for conversion - current setting is default. */ - if (!h && b->type == TYPETEXT && charset_changed) - { + if (!h && b->type == TYPETEXT && charset_changed) { int r; + snprintf (tmp, sizeof (tmp), _("Convert to %s upon sending?"), - mutt_get_parameter ("charset", b->parameter)); + mutt_get_parameter ("charset", b->parameter)); if ((r = mutt_yesorno (tmp, !b->noconv)) != -1) b->noconv = (r == M_NO); } /* inform the user */ - + snprintf (tmp, sizeof (tmp), "%s/%s", TYPE (b), NONULL (b->subtype)); if (type_changed) mutt_message (_("Content-Type changed to %s."), tmp); - if (b->type == TYPETEXT && charset_changed) - { + if (b->type == TYPETEXT && charset_changed) { if (type_changed) mutt_sleep (1); mutt_message (_("Character set changed to %s; %s."), - mutt_get_parameter ("charset", b->parameter), - b->noconv ? _("not converting") : _("converting")); + mutt_get_parameter ("charset", b->parameter), + b->noconv ? _("not converting") : _("converting")); } b->force_charset |= charset_changed ? 1 : 0; if (!is_multipart (b) && b->parts) mutt_free_body (&b->parts); - if (!mutt_is_message_type (b->type, b->subtype) && b->hdr) - { + if (!mutt_is_message_type (b->type, b->subtype) && b->hdr) { b->hdr->content = NULL; mutt_free_header (&b->hdr); } if (fp && (is_multipart (b) || mutt_is_message_type (b->type, b->subtype))) mutt_parse_part (fp, b); - - if (WithCrypto && h) - { + + if (WithCrypto && h) { if (h->content == b) - h->security = 0; + h->security = 0; h->security |= crypt_query (b); } } -static int _mutt_check_traditional_pgp (HEADER *h, int *redraw) +static int _mutt_check_traditional_pgp (HEADER * h, int *redraw) { MESSAGE *msg; int rv = 0; - + h->security |= PGP_TRADITIONAL_CHECKED; - + mutt_parse_mime_message (Context, h); if ((msg = mx_open_message (Context, h->msgno)) == NULL) return 0; - if (crypt_pgp_check_traditional (msg->fp, h->content, 0)) - { + if (crypt_pgp_check_traditional (msg->fp, h->content, 0)) { h->security = crypt_query (h->content); *redraw |= REDRAW_FULL; rv = 1; } - + h->security |= PGP_TRADITIONAL_CHECKED; mx_close_message (&msg); return rv; } -int mutt_check_traditional_pgp (HEADER *h, int *redraw) +int mutt_check_traditional_pgp (HEADER * h, int *redraw) { int i; int rv = 0; + if (h && !(h->security & PGP_TRADITIONAL_CHECKED)) rv = _mutt_check_traditional_pgp (h, redraw); - else - { + else { for (i = 0; i < Context->vcount; i++) - if (Context->hdrs[Context->v2r[i]]->tagged && - !(Context->hdrs[Context->v2r[i]]->security & PGP_TRADITIONAL_CHECKED)) - rv = _mutt_check_traditional_pgp (Context->hdrs[Context->v2r[i]], redraw) - || rv; + if (Context->hdrs[Context->v2r[i]]->tagged && + !(Context->hdrs[Context->v2r[i]]-> + security & PGP_TRADITIONAL_CHECKED)) + rv = + _mutt_check_traditional_pgp (Context->hdrs[Context->v2r[i]], redraw) + || rv; } return rv; } - - diff --git a/complete.c b/complete.c index d8355a7..fcb9269 100644 --- a/complete.c +++ b/complete.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -45,10 +45,11 @@ int mutt_complete (char *s, size_t slen) char *p; DIR *dirp = NULL; struct dirent *de; - int i ,init=0; + int i, init = 0; size_t len; char dirpart[_POSIX_PATH_MAX], exp_dirpart[_POSIX_PATH_MAX]; char filepart[_POSIX_PATH_MAX]; + #ifdef USE_IMAP char imap_path[LONG_STRING]; #endif @@ -56,8 +57,7 @@ int mutt_complete (char *s, size_t slen) dprint (2, (debugfile, "mutt_complete: completing %s\n", s)); #ifdef USE_NNTP - if (option (OPTNEWS)) - { + if (option (OPTNEWS)) { LIST *l = CurrentNewsSrv->list; strfcpy (filepart, s, sizeof (filepart)); @@ -66,46 +66,37 @@ int mutt_complete (char *s, size_t slen) * special case to handle when there is no filepart yet. * find the first subscribed newsgroup */ - if ((len = mutt_strlen (filepart)) == 0) - { - for (; l; l = l->next) - { - NNTP_DATA *data = (NNTP_DATA *)l->data; - - if (data && data->subscribed) - { - strfcpy (filepart, data->group, sizeof (filepart)); - init++; - l = l->next; - break; - } + if ((len = mutt_strlen (filepart)) == 0) { + for (; l; l = l->next) { + NNTP_DATA *data = (NNTP_DATA *) l->data; + + if (data && data->subscribed) { + strfcpy (filepart, data->group, sizeof (filepart)); + init++; + l = l->next; + break; + } } } - for (; l; l = l->next) - { - NNTP_DATA *data = (NNTP_DATA *)l->data; + for (; l; l = l->next) { + NNTP_DATA *data = (NNTP_DATA *) l->data; if (data && data->subscribed && - mutt_strncmp (data->group, filepart, len) == 0) - { - if (init) - { - for (i = 0; filepart[i] && data->group[i]; i++) - { - if (filepart[i] != data->group[i]) - { - filepart[i] = 0; - break; - } - } - filepart[i] = 0; - } - else - { - strfcpy (filepart, data->group, sizeof (filepart)); - init = 1; - } + mutt_strncmp (data->group, filepart, len) == 0) { + if (init) { + for (i = 0; filepart[i] && data->group[i]; i++) { + if (filepart[i] != data->group[i]) { + filepart[i] = 0; + break; + } + } + filepart[i] = 0; + } + else { + strfcpy (filepart, data->group, sizeof (filepart)); + init = 1; + } } } @@ -117,37 +108,35 @@ int mutt_complete (char *s, size_t slen) #ifdef USE_IMAP /* we can use '/' as a delimiter, imap_complete rewrites it */ - if (*s == '=' || *s == '+' || *s == '!') - { + if (*s == '=' || *s == '+' || *s == '!') { if (*s == '!') p = NONULL (Spoolfile); else p = NONULL (Maildir); - mutt_concat_path (imap_path, p, s+1, sizeof (imap_path)); + mutt_concat_path (imap_path, p, s + 1, sizeof (imap_path)); } else - strfcpy (imap_path, s, sizeof(imap_path)); + strfcpy (imap_path, s, sizeof (imap_path)); if (mx_is_imap (imap_path)) return imap_complete (s, slen, imap_path); #endif - - if (*s == '=' || *s == '+' || *s == '!') - { + + if (*s == '=' || *s == '+' || *s == '!') { dirpart[0] = *s; dirpart[1] = 0; if (*s == '!') strfcpy (exp_dirpart, NONULL (Spoolfile), sizeof (exp_dirpart)); else strfcpy (exp_dirpart, NONULL (Maildir), sizeof (exp_dirpart)); - if ((p = strrchr (s, '/'))) - { + if ((p = strrchr (s, '/'))) { char buf[_POSIX_PATH_MAX]; + *p++ = 0; mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf)); strfcpy (exp_dirpart, buf, sizeof (exp_dirpart)); - snprintf (buf, sizeof (buf), "%s%s/", dirpart, s+1); + snprintf (buf, sizeof (buf), "%s%s/", dirpart, s + 1); strfcpy (dirpart, buf, sizeof (dirpart)); strfcpy (filepart, p, sizeof (filepart)); } @@ -155,33 +144,28 @@ int mutt_complete (char *s, size_t slen) strfcpy (filepart, s + 1, sizeof (filepart)); dirp = opendir (exp_dirpart); } - else - { - if ((p = strrchr (s, '/'))) - { - if (p == s) /* absolute path */ - { - p = s + 1; - strfcpy (dirpart, "/", sizeof (dirpart)); - exp_dirpart[0] = 0; - strfcpy (filepart, p, sizeof (filepart)); - dirp = opendir (dirpart); + else { + if ((p = strrchr (s, '/'))) { + if (p == s) { /* absolute path */ + p = s + 1; + strfcpy (dirpart, "/", sizeof (dirpart)); + exp_dirpart[0] = 0; + strfcpy (filepart, p, sizeof (filepart)); + dirp = opendir (dirpart); } - else - { - *p = 0; - len = (size_t)(p - s); - strncpy (dirpart, s, len); - dirpart[len]=0; - p++; - strfcpy (filepart, p, sizeof (filepart)); - strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart)); - mutt_expand_path (exp_dirpart, sizeof (exp_dirpart)); - dirp = opendir (exp_dirpart); + else { + *p = 0; + len = (size_t) (p - s); + strncpy (dirpart, s, len); + dirpart[len] = 0; + p++; + strfcpy (filepart, p, sizeof (filepart)); + strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart)); + mutt_expand_path (exp_dirpart, sizeof (exp_dirpart)); + dirp = opendir (exp_dirpart); } } - else - { + else { /* no directory name, so assume current directory. */ dirpart[0] = 0; strfcpy (filepart, s, sizeof (filepart)); @@ -189,9 +173,10 @@ int mutt_complete (char *s, size_t slen) } } - if (dirp == NULL) - { - dprint (1, (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart, strerror (errno), errno)); + if (dirp == NULL) { + dprint (1, + (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart, + strerror (errno), errno)); return (-1); } @@ -199,64 +184,55 @@ int mutt_complete (char *s, size_t slen) * special case to handle when there is no filepart yet. find the first * file/directory which is not ``.'' or ``..'' */ - if ((len = mutt_strlen (filepart)) == 0) - { - while ((de = readdir (dirp)) != NULL) - { - if (mutt_strcmp (".", de->d_name) != 0 && mutt_strcmp ("..", de->d_name) != 0) - { - strfcpy (filepart, de->d_name, sizeof (filepart)); - init++; - break; + if ((len = mutt_strlen (filepart)) == 0) { + while ((de = readdir (dirp)) != NULL) { + if (mutt_strcmp (".", de->d_name) != 0 + && mutt_strcmp ("..", de->d_name) != 0) { + strfcpy (filepart, de->d_name, sizeof (filepart)); + init++; + break; } } } - while ((de = readdir (dirp)) != NULL) - { - if (mutt_strncmp (de->d_name, filepart, len) == 0) - { - if (init) - { - for (i=0; filepart[i] && de->d_name[i]; i++) - { - if (filepart[i] != de->d_name[i]) - { - filepart[i] = 0; - break; - } - } - filepart[i] = 0; + while ((de = readdir (dirp)) != NULL) { + if (mutt_strncmp (de->d_name, filepart, len) == 0) { + if (init) { + for (i = 0; filepart[i] && de->d_name[i]; i++) { + if (filepart[i] != de->d_name[i]) { + filepart[i] = 0; + break; + } + } + filepart[i] = 0; } - else - { - char buf[_POSIX_PATH_MAX]; - struct stat st; - - strfcpy (filepart, de->d_name, sizeof(filepart)); - - /* check to see if it is a directory */ - if (dirpart[0]) - { - strfcpy (buf, exp_dirpart, sizeof (buf)); - strfcpy (buf + strlen (buf), "/", sizeof (buf) - strlen (buf)); - } - else - buf[0] = 0; - strfcpy (buf + strlen (buf), filepart, sizeof (buf) - strlen (buf)); - if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR)) - strfcpy (filepart + strlen (filepart), "/", - sizeof (filepart) - strlen (filepart)); - init = 1; + else { + char buf[_POSIX_PATH_MAX]; + struct stat st; + + strfcpy (filepart, de->d_name, sizeof (filepart)); + + /* check to see if it is a directory */ + if (dirpart[0]) { + strfcpy (buf, exp_dirpart, sizeof (buf)); + strfcpy (buf + strlen (buf), "/", sizeof (buf) - strlen (buf)); + } + else + buf[0] = 0; + strfcpy (buf + strlen (buf), filepart, sizeof (buf) - strlen (buf)); + if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR)) + strfcpy (filepart + strlen (filepart), "/", + sizeof (filepart) - strlen (filepart)); + init = 1; } } } closedir (dirp); - if (dirpart[0]) - { + if (dirpart[0]) { strfcpy (s, dirpart, slen); - if (mutt_strcmp ("/", dirpart) != 0 && dirpart[0] != '=' && dirpart[0] != '+') + if (mutt_strcmp ("/", dirpart) != 0 && dirpart[0] != '=' + && dirpart[0] != '+') strfcpy (s + strlen (s), "/", slen - strlen (s)); strfcpy (s + strlen (s), filepart, slen - strlen (s)); } diff --git a/compose.c b/compose.c index ddf10cc..7ea1952 100644 --- a/compose.c +++ b/compose.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -37,7 +37,7 @@ #ifdef MIXMASTER #include "remailer.h" #endif - + #ifdef USE_NNTP #include "nntp.h" #endif @@ -49,15 +49,14 @@ #include #include -static const char* There_are_no_attachments = N_("There are no attachments."); +static const char *There_are_no_attachments = N_("There are no attachments."); #define CHECK_COUNT if (idxlen == 0) { mutt_error _(There_are_no_attachments); break; } -enum -{ - HDR_FROM = 1, +enum { + HDR_FROM = 1, HDR_TO, HDR_CC, HDR_BCC, @@ -65,7 +64,7 @@ enum HDR_REPLYTO, HDR_FCC, -#ifdef MIXMASTER +#ifdef MIXMASTER HDR_MIX, #endif @@ -79,18 +78,17 @@ enum #endif #ifndef USE_NNTP - HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */ + HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */ #else - HDR_ATTACH = (HDR_FCC + 7) + HDR_ATTACH = (HDR_FCC + 7) #endif }; #define HDR_XOFFSET 14 -#define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */ +#define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */ #define W (COLS - HDR_XOFFSET - SidebarWidth) -static char *Prompts[] = -{ +static char *Prompts[] = { "From: ", "To: ", "Cc: ", @@ -100,69 +98,64 @@ static char *Prompts[] = "Fcc: " #ifdef USE_NNTP #ifdef MIXMASTER - ,"" + , "" #endif - ,"" - ,"" - ,"Newsgroups: " - ,"Followup-To: " - ,"X-Comment-To: " + , "", "", "Newsgroups: ", "Followup-To: ", "X-Comment-To: " #endif }; static struct mapping_t ComposeHelp[] = { - { N_("Send"), OP_COMPOSE_SEND_MESSAGE }, - { N_("Abort"), OP_EXIT }, - { "To", OP_COMPOSE_EDIT_TO }, - { "CC", OP_COMPOSE_EDIT_CC }, - { "Subj", OP_COMPOSE_EDIT_SUBJECT }, - { N_("Attach file"), OP_COMPOSE_ATTACH_FILE }, - { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Send"), OP_COMPOSE_SEND_MESSAGE}, + {N_("Abort"), OP_EXIT}, + {"To", OP_COMPOSE_EDIT_TO}, + {"CC", OP_COMPOSE_EDIT_CC}, + {"Subj", OP_COMPOSE_EDIT_SUBJECT}, + {N_("Attach file"), OP_COMPOSE_ATTACH_FILE}, + {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION}, + {N_("Help"), OP_HELP}, + {NULL} }; #ifdef USE_NNTP static struct mapping_t ComposeNewsHelp[] = { - { N_("Send"), OP_COMPOSE_SEND_MESSAGE }, - { N_("Abort"), OP_EXIT }, - { "Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS }, - { "Subj", OP_COMPOSE_EDIT_SUBJECT }, - { N_("Attach file"), OP_COMPOSE_ATTACH_FILE }, - { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Send"), OP_COMPOSE_SEND_MESSAGE}, + {N_("Abort"), OP_EXIT}, + {"Newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS}, + {"Subj", OP_COMPOSE_EDIT_SUBJECT}, + {N_("Attach file"), OP_COMPOSE_ATTACH_FILE}, + {N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION}, + {N_("Help"), OP_HELP}, + {NULL} }; #endif -static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num) +static void snd_entry (char *b, size_t blen, MUTTMENU * menu, int num) { - mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt, - (unsigned long)(((ATTACHPTR **) menu->data)[num]), - M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR); + mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt, + (unsigned long) (((ATTACHPTR **) menu->data)[num]), + M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR); } #include "mutt_crypt.h" -static void redraw_crypt_lines (HEADER *msg) +static void redraw_crypt_lines (HEADER * msg) { int off = 0; - if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) - { + if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) { if (!msg->security) - mvaddstr (HDR_CRYPT, SidebarWidth, " Security: "); + mvaddstr (HDR_CRYPT, SidebarWidth, " Security: "); else if (msg->security & APPLICATION_SMIME) - mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: "); + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: "); else if (msg->security & APPLICATION_PGP) - mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: "); + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: "); } else if ((WithCrypto & APPLICATION_SMIME)) - mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: "); + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: "); else if ((WithCrypto & APPLICATION_PGP)) - mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: "); + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: "); else return; @@ -176,65 +169,63 @@ static void redraw_crypt_lines (HEADER *msg) addstr (_("Clear")); if ((WithCrypto & APPLICATION_PGP)) - if ((msg->security & APPLICATION_PGP) - && (msg->security & (ENCRYPT | SIGN))) - { + if ((msg->security & APPLICATION_PGP) + && (msg->security & (ENCRYPT | SIGN))) { if ((msg->security & INLINE)) - addstr (_(" (inline)")); + addstr (_(" (inline)")); else - addstr (_(" (PGP/MIME)")); + addstr (_(" (PGP/MIME)")); } clrtoeol (); move (HDR_CRYPTINFO, SidebarWidth); clrtoeol (); if ((WithCrypto & APPLICATION_PGP) - && msg->security & APPLICATION_PGP && msg->security & SIGN) - printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("")); + && msg->security & APPLICATION_PGP && msg->security & SIGN) + printw ("%s%s", _(" sign as: "), + PgpSignAs ? PgpSignAs : _("")); if ((WithCrypto & APPLICATION_SMIME) - && msg->security & APPLICATION_SMIME && msg->security & SIGN) { - printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("")); + && msg->security & APPLICATION_SMIME && msg->security & SIGN) { + printw ("%s%s", _(" sign as: "), + SmimeDefaultKey ? SmimeDefaultKey : _("")); } if ((WithCrypto & APPLICATION_SMIME) - && (msg->security & APPLICATION_SMIME) - && (msg->security & ENCRYPT) - && SmimeCryptAlg - && *SmimeCryptAlg) { - mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "), - NONULL(SmimeCryptAlg)); - off = 20; + && (msg->security & APPLICATION_SMIME) + && (msg->security & ENCRYPT) + && SmimeCryptAlg && *SmimeCryptAlg) { + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "), + NONULL (SmimeCryptAlg)); + off = 20; } } #ifdef MIXMASTER -static void redraw_mix_line (LIST *chain) +static void redraw_mix_line (LIST * chain) { int c; char *t; - mvaddstr (HDR_MIX, SidebarWidth, " Mix: "); + mvaddstr (HDR_MIX, SidebarWidth, " Mix: "); - if (!chain) - { + if (!chain) { addstr (""); clrtoeol (); return; } - - for (c = 12; chain; chain = chain->next) - { + + for (c = 12; chain; chain = chain->next) { t = chain->data; if (t && t[0] == '0' && t[1] == '\0') t = ""; - + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth) break; - addstr (NONULL(t)); + addstr (NONULL (t)); if (chain->next) addstr (", "); @@ -243,41 +234,36 @@ static void redraw_mix_line (LIST *chain) } #endif /* MIXMASTER */ -static int -check_attachments(ATTACHPTR **idx, short idxlen) +static int check_attachments (ATTACHPTR ** idx, short idxlen) { int i, r; struct stat st; char pretty[_POSIX_PATH_MAX], msg[_POSIX_PATH_MAX + SHORT_STRING]; - for (i = 0; i < idxlen; i++) - { - strfcpy(pretty, idx[i]->content->filename, sizeof(pretty)); - if(stat(idx[i]->content->filename, &st) != 0) - { - mutt_pretty_mailbox(pretty); - mutt_error(_("%s [#%d] no longer exists!"), - pretty, i+1); + for (i = 0; i < idxlen; i++) { + strfcpy (pretty, idx[i]->content->filename, sizeof (pretty)); + if (stat (idx[i]->content->filename, &st) != 0) { + mutt_pretty_mailbox (pretty); + mutt_error (_("%s [#%d] no longer exists!"), pretty, i + 1); return -1; } - - if(idx[i]->content->stamp < st.st_mtime) - { - mutt_pretty_mailbox(pretty); - snprintf(msg, sizeof(msg), _("%s [#%d] modified. Update encoding?"), - pretty, i+1); - - if((r = mutt_yesorno(msg, M_YES)) == M_YES) - mutt_update_encoding(idx[i]->content); - else if(r == -1) - return -1; + + if (idx[i]->content->stamp < st.st_mtime) { + mutt_pretty_mailbox (pretty); + snprintf (msg, sizeof (msg), _("%s [#%d] modified. Update encoding?"), + pretty, i + 1); + + if ((r = mutt_yesorno (msg, M_YES)) == M_YES) + mutt_update_encoding (idx[i]->content); + else if (r == -1) + return -1; } } return 0; } -static void draw_envelope_addr (int line, ADDRESS *addr) +static void draw_envelope_addr (int line, ADDRESS * addr) { char buf[STRING]; @@ -287,27 +273,24 @@ static void draw_envelope_addr (int line, ADDRESS *addr) mutt_paddstr (W, buf); } -static void draw_envelope (HEADER *msg, char *fcc) +static void draw_envelope (HEADER * msg, char *fcc) { draw_envelope_addr (HDR_FROM, msg->env->from); #ifdef USE_NNTP - if (!option (OPTNEWSSEND)) - { + if (!option (OPTNEWSSEND)) { #endif - draw_envelope_addr (HDR_TO, msg->env->to); - draw_envelope_addr (HDR_CC, msg->env->cc); - draw_envelope_addr (HDR_BCC, msg->env->bcc); + draw_envelope_addr (HDR_TO, msg->env->to); + draw_envelope_addr (HDR_CC, msg->env->cc); + draw_envelope_addr (HDR_BCC, msg->env->bcc); #ifdef USE_NNTP } - else - { - mvprintw (HDR_TO, SidebarWidth, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]); + else { + mvprintw (HDR_TO, SidebarWidth, TITLE_FMT, Prompts[HDR_NEWSGROUPS - 1]); mutt_paddstr (W, NONULL (msg->env->newsgroups)); - mvprintw (HDR_CC, SidebarWidth, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]); + mvprintw (HDR_CC, SidebarWidth, TITLE_FMT, Prompts[HDR_FOLLOWUPTO - 1]); mutt_paddstr (W, NONULL (msg->env->followup_to)); - if (option (OPTXCOMMENTTO)) - { - mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]); + if (option (OPTXCOMMENTTO)) { + mvprintw (HDR_BCC, 0, TITLE_FMT, Prompts[HDR_XCOMMENTTO - 1]); mutt_paddstr (W, NONULL (msg->env->x_comment_to)); } } @@ -334,60 +317,55 @@ static void draw_envelope (HEADER *msg, char *fcc) SETCOLOR (MT_COLOR_NORMAL); } -static int edit_address_list (int line, ADDRESS **addr) +static int edit_address_list (int line, ADDRESS ** addr) { - char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */ + char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */ char *err = NULL; - + mutt_addrlist_to_local (*addr); rfc822_write_address (buf, sizeof (buf), *addr, 0); - if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) - { + if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0) { rfc822_free_address (addr); *addr = mutt_parse_adrlist (*addr, buf); *addr = mutt_expand_aliases (*addr); } - if (option (OPTNEEDREDRAW)) - { + if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); return (REDRAW_FULL); } - if (mutt_addrlist_to_idna (*addr, &err) != 0) - { + if (mutt_addrlist_to_idna (*addr, &err) != 0) { mutt_error (_("Warning: '%s' is a bad IDN."), err); - mutt_refresh(); + mutt_refresh (); FREE (&err); } /* redraw the expanded list so the user can see the result */ buf[0] = 0; rfc822_write_address (buf, sizeof (buf), *addr, 1); - move (line, HDR_XOFFSET+SidebarWidth); + move (line, HDR_XOFFSET + SidebarWidth); mutt_paddstr (W, buf); - + return 0; } -static int delete_attachment (MUTTMENU *menu, short *idxlen, int x) +static int delete_attachment (MUTTMENU * menu, short *idxlen, int x) { ATTACHPTR **idx = (ATTACHPTR **) menu->data; int y; menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - if (x == 0 && menu->max == 1) - { + if (x == 0 && menu->max == 1) { mutt_error _("You may not delete the only attachment."); + idx[x]->content->tagged = 0; return (-1); } - for (y = 0; y < *idxlen; y++) - { - if (idx[y]->content->next == idx[x]->content) - { + for (y = 0; y < *idxlen; y++) { + if (idx[y]->content->next == idx[x]->content) { idx[y]->content->next = idx[x]->content->next; break; } @@ -399,15 +377,15 @@ static int delete_attachment (MUTTMENU *menu, short *idxlen, int x) FREE (&idx[x]->tree); FREE (&idx[x]); for (; x < *idxlen - 1; x++) - idx[x] = idx[x+1]; + idx[x] = idx[x + 1]; menu->max = --(*idxlen); - + return (0); } -static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen) +static void update_idx (MUTTMENU * menu, ATTACHPTR ** idx, short idxlen) { - idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0; + idx[idxlen]->level = (idxlen > 0) ? idx[idxlen - 1]->level : 0; if (idxlen) idx[idxlen - 1]->content->next = idx[idxlen]->content; idx[idxlen]->content->aptr = idx[idxlen]; @@ -427,34 +405,31 @@ static void update_idx (MUTTMENU *menu, ATTACHPTR **idx, short idxlen) * */ -static unsigned long cum_attachs_size (MUTTMENU *menu) +static unsigned long cum_attachs_size (MUTTMENU * menu) { size_t s; unsigned short i; ATTACHPTR **idx = menu->data; CONTENT *info; BODY *b; - - for (i = 0, s = 0; i < menu->max; i++) - { + + for (i = 0, s = 0; i < menu->max; i++) { b = idx[i]->content; if (!b->content) b->content = mutt_get_content_info (b->filename, b); - if ((info = b->content)) - { - switch (b->encoding) - { - case ENCQUOTEDPRINTABLE: - s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf; - break; - case ENCBASE64: - s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3; - break; - default: - s += info->lobin + info->hibin + info->ascii + info->crlf; - break; + if ((info = b->content)) { + switch (b->encoding) { + case ENCQUOTEDPRINTABLE: + s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf; + break; + case ENCBASE64: + s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3; + break; + default: + s += info->lobin + info->hibin + info->ascii + info->crlf; + break; } } } @@ -463,8 +438,8 @@ static unsigned long cum_attachs_size (MUTTMENU *menu) } /* prototype for use below */ -static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, - const char *p); +static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu, + const char *p); /* * compose_format_str() @@ -478,47 +453,46 @@ static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, * help when modifying this function. */ -static const char * -compose_format_str (char *buf, size_t buflen, char op, const char *src, - const char *prefix, const char *ifstring, - const char *elsestring, - unsigned long data, format_flag flags) +static const char *compose_format_str (char *buf, size_t buflen, char op, + const char *src, const char *prefix, + const char *ifstring, + const char *elsestring, + unsigned long data, format_flag flags) { char fmt[SHORT_STRING], tmp[SHORT_STRING]; int optional = (flags & M_FORMAT_OPTIONAL); MUTTMENU *menu = (MUTTMENU *) data; *buf = 0; - switch (op) - { - case 'a': /* total number of attachments */ - snprintf (fmt, sizeof (fmt), "%%%sd", prefix); - snprintf (buf, buflen, fmt, menu->max); - break; - - case 'h': /* hostname */ - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (buf, buflen, fmt, NONULL(Hostname)); - break; - - case 'l': /* approx length of current message in bytes */ - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0); - snprintf (buf, buflen, fmt, tmp); - break; - - case 'v': - snprintf (fmt, sizeof (fmt), "Mutt-ng %%s"); - snprintf (buf, buflen, fmt, MUTT_VERSION); - break; - - case 0: - *buf = 0; - return (src); - - default: - snprintf (buf, buflen, "%%%s%c", prefix, op); - break; + switch (op) { + case 'a': /* total number of attachments */ + snprintf (fmt, sizeof (fmt), "%%%sd", prefix); + snprintf (buf, buflen, fmt, menu->max); + break; + + case 'h': /* hostname */ + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + snprintf (buf, buflen, fmt, NONULL (Hostname)); + break; + + case 'l': /* approx length of current message in bytes */ + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size (menu) : 0); + snprintf (buf, buflen, fmt, tmp); + break; + + case 'v': + snprintf (fmt, sizeof (fmt), "Mutt-ng %%s"); + snprintf (buf, buflen, fmt, MUTT_VERSION); + break; + + case 0: + *buf = 0; + return (src); + + default: + snprintf (buf, buflen, "%%%s%c", prefix, op); + break; } if (optional) @@ -529,11 +503,11 @@ compose_format_str (char *buf, size_t buflen, char op, const char *src, return (src); } -static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, - const char *p) +static void compose_status_line (char *buf, size_t buflen, MUTTMENU * menu, + const char *p) { - mutt_FormatString (buf, buflen, p, compose_format_str, - (unsigned long) menu, 0); + mutt_FormatString (buf, buflen, p, compose_format_str, + (unsigned long) menu, 0); } @@ -543,11 +517,10 @@ static void compose_status_line (char *buf, size_t buflen, MUTTMENU *menu, * 0 normal exit * -1 abort message */ -int mutt_compose_menu (HEADER *msg, /* structure for new message */ - char *fcc, /* where to save a copy of the message */ - size_t fcclen, - HEADER *cur) /* current message */ -{ +int mutt_compose_menu (HEADER * msg, /* structure for new message */ + char *fcc, /* where to save a copy of the message */ + size_t fcclen, HEADER * cur) +{ /* current message */ char helpstr[SHORT_STRING]; char buf[LONG_STRING]; char fname[_POSIX_PATH_MAX]; @@ -556,16 +529,18 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ short idxlen = 0; short idxmax = 0; int i, close = 0; - int r = -1; /* return value */ + int r = -1; /* return value */ int op = 0; int loop = 1; - int fccSet = 0; /* has the user edited the Fcc: field ? */ + int fccSet = 0; /* has the user edited the Fcc: field ? */ CONTEXT *ctx = NULL, *this = NULL; + /* Sort, SortAux could be changed in mutt_index_menu() */ int oldSort, oldSortAux; struct stat st; + #ifdef USE_NNTP - int news = 0; /* is it a news article ? */ + int news = 0; /* is it a news article ? */ if (option (OPTNEWSSEND)) news++; @@ -583,884 +558,865 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->data = idx; #ifdef USE_NNTP if (news) - menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp); + menu->help = + mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, + ComposeNewsHelp); else #endif - menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp); - - if (option(OPTMBOXPANE)) - mutt_buffy_check(1); - while (loop) - { + menu->help = + mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, + ComposeHelp); + + if (option (OPTMBOXPANE)) + mutt_buffy_check (1); + while (loop) { #ifdef USE_NNTP - unset_option (OPTNEWS); /* for any case */ + unset_option (OPTNEWS); /* for any case */ #endif - switch (op = mutt_menuLoop (menu)) - { - case OP_REDRAW: - draw_envelope (msg, fcc); - menu->offset = HDR_ATTACH; - menu->pagelen = LINES - HDR_ATTACH - 2; - break; - case OP_COMPOSE_EDIT_FROM: - menu->redraw = edit_address_list (HDR_FROM, &msg->env->from); - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - case OP_COMPOSE_EDIT_TO: + switch (op = mutt_menuLoop (menu)) { + case OP_REDRAW: + draw_envelope (msg, fcc); + menu->offset = HDR_ATTACH; + menu->pagelen = LINES - HDR_ATTACH - 2; + break; + case OP_COMPOSE_EDIT_FROM: + menu->redraw = edit_address_list (HDR_FROM, &msg->env->from); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + case OP_COMPOSE_EDIT_TO: #ifdef USE_NNTP - if (!news) { + if (!news) { #endif - menu->redraw = edit_address_list (HDR_TO, &msg->env->to); - mutt_message_hook (NULL, msg, M_SEND2HOOK); + menu->redraw = edit_address_list (HDR_TO, &msg->env->to); + mutt_message_hook (NULL, msg, M_SEND2HOOK); #ifdef USE_NNTP - } + } #endif - break; - case OP_COMPOSE_EDIT_BCC: + break; + case OP_COMPOSE_EDIT_BCC: #ifdef USE_NNTP - if (!news) { + if (!news) { #endif - menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc); - mutt_message_hook (NULL, msg, M_SEND2HOOK); + menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc); + mutt_message_hook (NULL, msg, M_SEND2HOOK); #ifdef USE_NNTP - } + } #endif - break; - case OP_COMPOSE_EDIT_CC: + break; + case OP_COMPOSE_EDIT_CC: #ifdef USE_NNTP - if (!news) { + if (!news) { #endif - menu->redraw = edit_address_list (HDR_CC, &msg->env->cc); - mutt_message_hook (NULL, msg, M_SEND2HOOK); + menu->redraw = edit_address_list (HDR_CC, &msg->env->cc); + mutt_message_hook (NULL, msg, M_SEND2HOOK); #ifdef USE_NNTP - } + } #endif - break; + break; #ifdef USE_NNTP - case OP_COMPOSE_EDIT_NEWSGROUPS: - if (news) - { - if (msg->env->newsgroups) - strfcpy (buf, msg->env->newsgroups, sizeof (buf)); - else - buf[0] = 0; - if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0]) - { - FREE (&msg->env->newsgroups); - mutt_remove_trailing_ws (buf); - msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf)); - move (HDR_TO, HDR_XOFFSET); - clrtoeol (); - if (msg->env->newsgroups) - printw ("%-*.*s", W, W, msg->env->newsgroups); - } - } - break; - - case OP_COMPOSE_EDIT_FOLLOWUP_TO: - if (news) - { - buf[0] = 0; - if (msg->env->followup_to) - strfcpy (buf, msg->env->followup_to, sizeof (buf)); - if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0]) - { - FREE (&msg->env->followup_to); - mutt_remove_trailing_ws (buf); - msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf)); - move (HDR_CC, HDR_XOFFSET); - clrtoeol(); - if (msg->env->followup_to) - printw ("%-*.*s", W, W, msg->env->followup_to); - } - } - break; - - case OP_COMPOSE_EDIT_X_COMMENT_TO: - if (news && option (OPTXCOMMENTTO)) - { - buf[0] = 0; - if (msg->env->x_comment_to) - strfcpy (buf, msg->env->x_comment_to, sizeof (buf)); - if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0]) - { - FREE (&msg->env->x_comment_to); - msg->env->x_comment_to = safe_strdup (buf); - move (HDR_BCC, HDR_XOFFSET); - clrtoeol(); - if (msg->env->x_comment_to) - printw ("%-*.*s", W, W, msg->env->x_comment_to); - } - } - break; + case OP_COMPOSE_EDIT_NEWSGROUPS: + if (news) { + if (msg->env->newsgroups) + strfcpy (buf, msg->env->newsgroups, sizeof (buf)); + else + buf[0] = 0; + if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 + && buf[0]) { + FREE (&msg->env->newsgroups); + mutt_remove_trailing_ws (buf); + msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf)); + move (HDR_TO, HDR_XOFFSET); + clrtoeol (); + if (msg->env->newsgroups) + printw ("%-*.*s", W, W, msg->env->newsgroups); + } + } + break; + + case OP_COMPOSE_EDIT_FOLLOWUP_TO: + if (news) { + buf[0] = 0; + if (msg->env->followup_to) + strfcpy (buf, msg->env->followup_to, sizeof (buf)); + if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 + && buf[0]) { + FREE (&msg->env->followup_to); + mutt_remove_trailing_ws (buf); + msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf)); + move (HDR_CC, HDR_XOFFSET); + clrtoeol (); + if (msg->env->followup_to) + printw ("%-*.*s", W, W, msg->env->followup_to); + } + } + break; + + case OP_COMPOSE_EDIT_X_COMMENT_TO: + if (news && option (OPTXCOMMENTTO)) { + buf[0] = 0; + if (msg->env->x_comment_to) + strfcpy (buf, msg->env->x_comment_to, sizeof (buf)); + if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 + && buf[0]) { + FREE (&msg->env->x_comment_to); + msg->env->x_comment_to = safe_strdup (buf); + move (HDR_BCC, HDR_XOFFSET); + clrtoeol (); + if (msg->env->x_comment_to) + printw ("%-*.*s", W, W, msg->env->x_comment_to); + } + } + break; #endif - case OP_COMPOSE_EDIT_SUBJECT: - if (msg->env->subject) - strfcpy (buf, msg->env->subject, sizeof (buf)); - else - buf[0] = 0; - if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) - { - mutt_str_replace (&msg->env->subject, buf); - move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth); - clrtoeol (); - if (msg->env->subject) - mutt_paddstr (W, msg->env->subject); - } + case OP_COMPOSE_EDIT_SUBJECT: + if (msg->env->subject) + strfcpy (buf, msg->env->subject, sizeof (buf)); + else + buf[0] = 0; + if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0) { + mutt_str_replace (&msg->env->subject, buf); + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth); + clrtoeol (); + if (msg->env->subject) + mutt_paddstr (W, msg->env->subject); + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + case OP_COMPOSE_EDIT_REPLY_TO: + menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + case OP_COMPOSE_EDIT_FCC: + strfcpy (buf, fcc, sizeof (buf)); + if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) { + strfcpy (fcc, buf, _POSIX_PATH_MAX); + mutt_pretty_mailbox (fcc); + move (HDR_FCC, HDR_XOFFSET + SidebarWidth); + mutt_paddstr (W, fcc); + fccSet = 1; + } + MAYBE_REDRAW (menu->redraw); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + case OP_COMPOSE_EDIT_MESSAGE: + if (Editor && (mutt_strcmp ("builtin", Editor) != 0) + && !option (OPTEDITHDRS)) { + mutt_edit_file (Editor, msg->content->filename); + mutt_update_encoding (msg->content); + menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; - case OP_COMPOSE_EDIT_REPLY_TO: - menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to); - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - case OP_COMPOSE_EDIT_FCC: - strfcpy (buf, fcc, sizeof (buf)); - if (mutt_get_field ("Fcc: ", buf, sizeof (buf), M_FILE | M_CLEAR) == 0) - { - strfcpy (fcc, buf, _POSIX_PATH_MAX); - mutt_pretty_mailbox (fcc); - move (HDR_FCC, HDR_XOFFSET + SidebarWidth); - mutt_paddstr (W, fcc); - fccSet = 1; - } - MAYBE_REDRAW (menu->redraw); - mutt_message_hook (NULL, msg, M_SEND2HOOK); + } + /* fall through */ + case OP_COMPOSE_EDIT_HEADERS: + if (mutt_strcmp ("builtin", Editor) != 0 && + (op == OP_COMPOSE_EDIT_HEADERS || + (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) { + char *tag = NULL, *err = NULL; + + mutt_env_to_local (msg->env); + mutt_edit_headers (NONULL (Editor), msg->content->filename, msg, + fcc, fcclen); + if (mutt_env_to_idna (msg->env, &tag, &err)) { + mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); + FREE (&err); + } + } + else { + /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the + attachment list could change if the user invokes ~v to edit + the message with headers, in which we need to execute the + code below to regenerate the index array */ + mutt_builtin_editor (msg->content->filename, msg, cur); + } + mutt_update_encoding (msg->content); + + /* attachments may have been added */ + if (idxlen && idx[idxlen - 1]->content->next) { + for (i = 0; i < idxlen; i++) + FREE (&idx[i]); + idxlen = 0; + idx = + mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, + 1); + menu->data = idx; + menu->max = idxlen; + } + + menu->redraw = REDRAW_FULL; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + + + case OP_COMPOSE_ATTACH_KEY: + if (!(WithCrypto & APPLICATION_PGP)) break; - case OP_COMPOSE_EDIT_MESSAGE: - if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS)) - { - mutt_edit_file (Editor, msg->content->filename); - mutt_update_encoding (msg->content); - menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - } - /* fall through */ - case OP_COMPOSE_EDIT_HEADERS: - if (mutt_strcmp ("builtin", Editor) != 0 && - (op == OP_COMPOSE_EDIT_HEADERS || - (op == OP_COMPOSE_EDIT_MESSAGE && option (OPTEDITHDRS)))) - { - char *tag = NULL, *err = NULL; - mutt_env_to_local (msg->env); - mutt_edit_headers (NONULL (Editor), msg->content->filename, msg, - fcc, fcclen); - if (mutt_env_to_idna (msg->env, &tag, &err)) - { - mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); - FREE (&err); - } - } - else - { - /* this is grouped with OP_COMPOSE_EDIT_HEADERS because the - attachment list could change if the user invokes ~v to edit - the message with headers, in which we need to execute the - code below to regenerate the index array */ - mutt_builtin_editor (msg->content->filename, msg, cur); - } - mutt_update_encoding (msg->content); - - /* attachments may have been added */ - if (idxlen && idx[idxlen - 1]->content->next) - { - for (i = 0; i < idxlen; i++) - FREE (&idx[i]); - idxlen = 0; - idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); - menu->data = idx; - menu->max = idxlen; - } + if (idxlen == idxmax) { + safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); + menu->data = idx; + } + idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + if ((idx[idxlen]->content = + crypt_pgp_make_key_attachment (NULL)) != NULL) { + update_idx (menu, idx, idxlen++); + menu->redraw |= REDRAW_INDEX; + } + else + FREE (&idx[idxlen]); + + menu->redraw |= REDRAW_STATUS; + + if (option (OPTNEEDREDRAW)) { menu->redraw = REDRAW_FULL; - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - - - - case OP_COMPOSE_ATTACH_KEY: - if (!(WithCrypto & APPLICATION_PGP)) - break; - if (idxlen == idxmax) - { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); - menu->data = idx; - } - - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) - { - update_idx (menu, idx, idxlen++); - menu->redraw |= REDRAW_INDEX; - } - else - FREE (&idx[idxlen]); - - menu->redraw |= REDRAW_STATUS; - - if (option(OPTNEEDREDRAW)) - { - menu->redraw = REDRAW_FULL; - unset_option(OPTNEEDREDRAW); - } - - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + unset_option (OPTNEEDREDRAW); + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; - case OP_COMPOSE_ATTACH_FILE: - { - char *prompt, **files; - int error, numfiles; - - fname[0] = 0; - prompt = _("Attach file"); - numfiles = 0; - files = NULL; - - if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1 || - *fname == '\0') - break; - - if (idxlen + numfiles >= idxmax) - { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); - menu->data = idx; - } - - error = 0; - if (numfiles > 1) - mutt_message _("Attaching selected files..."); - for (i = 0; i < numfiles; i++) - { - char *att = files[i]; - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - idx[idxlen]->content = mutt_make_file_attach (att); - if (idx[idxlen]->content != NULL) - update_idx (menu, idx, idxlen++); - else - { - error = 1; - mutt_error (_("Unable to attach %s!"), att); - FREE (&idx[idxlen]); - } - } - - FREE (&files); - if (!error) mutt_clear_error (); - - menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - case OP_COMPOSE_ATTACH_MESSAGE: + case OP_COMPOSE_ATTACH_FILE: + { + char *prompt, **files; + int error, numfiles; + + fname[0] = 0; + prompt = _("Attach file"); + numfiles = 0; + files = NULL; + + if (_mutt_enter_fname + (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, + &numfiles) == -1 || *fname == '\0') + break; + + if (idxlen + numfiles >= idxmax) { + safe_realloc (&idx, + sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); + menu->data = idx; + } + + error = 0; + if (numfiles > 1) + mutt_message _("Attaching selected files..."); + + for (i = 0; i < numfiles; i++) { + char *att = files[i]; + + idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + idx[idxlen]->content = mutt_make_file_attach (att); + if (idx[idxlen]->content != NULL) + update_idx (menu, idx, idxlen++); + else { + error = 1; + mutt_error (_("Unable to attach %s!"), att); + FREE (&idx[idxlen]); + } + } + + FREE (&files); + if (!error) + mutt_clear_error (); + + menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_ATTACH_MESSAGE: #ifdef USE_NNTP - case OP_COMPOSE_ATTACH_NEWS_MESSAGE: + case OP_COMPOSE_ATTACH_NEWS_MESSAGE: #endif - { - char *prompt; - HEADER *h; + { + char *prompt; + HEADER *h; - fname[0] = 0; - prompt = _("Open mailbox to attach message from"); + fname[0] = 0; + prompt = _("Open mailbox to attach message from"); #ifdef USE_NNTP - unset_option (OPTNEWS); - if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) - { - if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) - break; - - prompt = _("Open newsgroup to attach message from"); - set_option (OPTNEWS); - } + unset_option (OPTNEWS); + if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE) { + if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) + break; + + prompt = _("Open newsgroup to attach message from"); + set_option (OPTNEWS); + } #endif - if (Context) + if (Context) #ifdef USE_NNTP - if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP)) + if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP)) #endif - { - strfcpy (fname, NONULL (Context->path), sizeof (fname)); - mutt_pretty_mailbox (fname); - } + { + strfcpy (fname, NONULL (Context->path), sizeof (fname)); + mutt_pretty_mailbox (fname); + } - if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0]) - break; + if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) + == -1 || !fname[0]) + break; #ifdef USE_NNTP - if (option (OPTNEWS)) - nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account); - else + if (option (OPTNEWS)) + nntp_expand_path (fname, sizeof (fname), + &CurrentNewsSrv->conn->account); + else #endif - mutt_expand_path (fname, sizeof (fname)); + mutt_expand_path (fname, sizeof (fname)); #ifdef USE_IMAP - if (!mx_is_imap (fname)) + if (!mx_is_imap (fname)) #endif #ifdef USE_POP if (!mx_is_pop (fname)) #endif #ifdef USE_NNTP - if (!mx_is_nntp (fname) && !option (OPTNEWS)) + if (!mx_is_nntp (fname) && !option (OPTNEWS)) #endif - /* check to make sure the file exists and is readable */ - if (access (fname, R_OK) == -1) - { - mutt_perror (fname); - break; - } - - menu->redraw = REDRAW_FULL; - - ctx = mx_open_mailbox (fname, M_READONLY, NULL); - if (ctx == NULL) - { - mutt_perror (fname); - break; - } - - if (!ctx->msgcount) - { - mx_close_mailbox (ctx, NULL); - FREE (&ctx); - mutt_error _("No messages in that folder."); - break; - } - - this = Context; /* remember current folder and sort methods*/ - oldSort = Sort; oldSortAux = SortAux; - - Context = ctx; - set_option(OPTATTACHMSG); - mutt_message _("Tag the messages you want to attach!"); - close = mutt_index_menu (); - unset_option(OPTATTACHMSG); - - if (!Context) - { - /* go back to the folder we started from */ - Context = this; - /* Restore old $sort and $sort_aux */ - Sort = oldSort; - SortAux = oldSortAux; - menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; - break; - } - - if (idxlen + Context->tagged >= idxmax) - { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged)); - menu->data = idx; - } - - for (i = 0; i < Context->msgcount; i++) - { - h = Context->hdrs[i]; - if (h->tagged) - { - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - idx[idxlen]->content = mutt_make_message_attach (Context, h, 1); - if (idx[idxlen]->content != NULL) - update_idx (menu, idx, idxlen++); - else - { - mutt_error _("Unable to attach!"); - FREE (&idx[idxlen]); - } - } - } - menu->redraw |= REDRAW_FULL; - - if (close == OP_QUIT) - mx_close_mailbox (Context, NULL); - else - mx_fastclose_mailbox (Context); - FREE (&Context); - - /* go back to the folder we started from */ - Context = this; - /* Restore old $sort and $sort_aux */ - Sort = oldSort; - SortAux = oldSortAux; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + /* check to make sure the file exists and is readable */ + if (access (fname, R_OK) == -1) { + mutt_perror (fname); + break; + } - case OP_DELETE: - CHECK_COUNT; - if (delete_attachment (menu, &idxlen, menu->current) == -1) - break; - mutt_update_tree (idx, idxlen); - if (idxlen) - { - if (menu->current > idxlen - 1) - menu->current = idxlen - 1; - } - else - menu->current = 0; - - if (menu->current == 0) - msg->content = idx[0]->content; + menu->redraw = REDRAW_FULL; - menu->redraw |= REDRAW_STATUS; - mutt_message_hook (NULL, msg, M_SEND2HOOK); + ctx = mx_open_mailbox (fname, M_READONLY, NULL); + if (ctx == NULL) { + mutt_perror (fname); + break; + } + + if (!ctx->msgcount) { + mx_close_mailbox (ctx, NULL); + FREE (&ctx); + mutt_error _("No messages in that folder."); + + break; + } + + this = Context; /* remember current folder and sort methods */ + oldSort = Sort; + oldSortAux = SortAux; + + Context = ctx; + set_option (OPTATTACHMSG); + mutt_message _("Tag the messages you want to attach!"); + + close = mutt_index_menu (); + unset_option (OPTATTACHMSG); + + if (!Context) { + /* go back to the folder we started from */ + Context = this; + /* Restore old $sort and $sort_aux */ + Sort = oldSort; + SortAux = oldSortAux; + menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; + break; + } + + if (idxlen + Context->tagged >= idxmax) { + safe_realloc (&idx, + sizeof (ATTACHPTR *) * (idxmax += + 5 + Context->tagged)); + menu->data = idx; + } + + for (i = 0; i < Context->msgcount; i++) { + h = Context->hdrs[i]; + if (h->tagged) { + idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + idx[idxlen]->content = mutt_make_message_attach (Context, h, 1); + if (idx[idxlen]->content != NULL) + update_idx (menu, idx, idxlen++); + else { + mutt_error _("Unable to attach!"); + + FREE (&idx[idxlen]); + } + } + } + menu->redraw |= REDRAW_FULL; + + if (close == OP_QUIT) + mx_close_mailbox (Context, NULL); + else + mx_fastclose_mailbox (Context); + FREE (&Context); + + /* go back to the folder we started from */ + Context = this; + /* Restore old $sort and $sort_aux */ + Sort = oldSort; + SortAux = oldSortAux; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_DELETE: + CHECK_COUNT; + if (delete_attachment (menu, &idxlen, menu->current) == -1) break; + mutt_update_tree (idx, idxlen); + if (idxlen) { + if (menu->current > idxlen - 1) + menu->current = idxlen - 1; + } + else + menu->current = 0; + + if (menu->current == 0) + msg->content = idx[0]->content; + + menu->redraw |= REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; #define CURRENT idx[menu->current]->content - - case OP_COMPOSE_TOGGLE_RECODE: - { + + case OP_COMPOSE_TOGGLE_RECODE: + { CHECK_COUNT; - if (!mutt_is_text_part (CURRENT)) - { - mutt_error (_("Recoding only affects text attachments.")); - break; - } + if (!mutt_is_text_part (CURRENT)) { + mutt_error (_("Recoding only affects text attachments.")); + break; + } CURRENT->noconv = !CURRENT->noconv; if (CURRENT->noconv) - mutt_message (_("The current attachment won't be converted.")); + mutt_message (_("The current attachment won't be converted.")); else - mutt_message (_("The current attachment will be converted.")); - menu->redraw = REDRAW_CURRENT; + mutt_message (_("The current attachment will be converted.")); + menu->redraw = REDRAW_CURRENT; mutt_message_hook (NULL, msg, M_SEND2HOOK); break; } #undef CURRENT - case OP_COMPOSE_EDIT_DESCRIPTION: - CHECK_COUNT; - strfcpy (buf, - idx[menu->current]->content->description ? - idx[menu->current]->content->description : "", - sizeof (buf)); - /* header names should not be translated */ - if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) - { - mutt_str_replace (&idx[menu->current]->content->description, buf); - menu->redraw = REDRAW_CURRENT; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + case OP_COMPOSE_EDIT_DESCRIPTION: + CHECK_COUNT; + strfcpy (buf, + idx[menu->current]->content->description ? + idx[menu->current]->content->description : "", sizeof (buf)); + /* header names should not be translated */ + if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0) { + mutt_str_replace (&idx[menu->current]->content->description, buf); + menu->redraw = REDRAW_CURRENT; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; - case OP_COMPOSE_UPDATE_ENCODING: - CHECK_COUNT; - if (menu->tagprefix) - { - BODY *top; - for (top = msg->content; top; top = top->next) - { - if (top->tagged) - mutt_update_encoding (top); - } - menu->redraw = REDRAW_FULL; - } + case OP_COMPOSE_UPDATE_ENCODING: + CHECK_COUNT; + if (menu->tagprefix) { + BODY *top; + + for (top = msg->content; top; top = top->next) { + if (top->tagged) + mutt_update_encoding (top); + } + menu->redraw = REDRAW_FULL; + } + else { + mutt_update_encoding (idx[menu->current]->content); + menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_TOGGLE_DISPOSITION: + /* toggle the content-disposition between inline/attachment */ + idx[menu->current]->content->disposition = + (idx[menu->current]->content->disposition == + DISPINLINE) ? DISPATTACH : DISPINLINE; + menu->redraw = REDRAW_CURRENT; + break; + + case OP_EDIT_TYPE: + CHECK_COUNT; + { + mutt_edit_content_type (NULL, idx[menu->current]->content, NULL); + + /* this may have been a change to text/something */ + mutt_update_encoding (idx[menu->current]->content); + + menu->redraw = REDRAW_CURRENT; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_EDIT_ENCODING: + CHECK_COUNT; + strfcpy (buf, ENCODING (idx[menu->current]->content->encoding), + sizeof (buf)); + if (mutt_get_field ("Content-Transfer-Encoding: ", buf, + sizeof (buf), 0) == 0 && buf[0]) { + if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) { + idx[menu->current]->content->encoding = i; + menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; + mutt_clear_error (); + } else - { - mutt_update_encoding(idx[menu->current]->content); - menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - - case OP_COMPOSE_TOGGLE_DISPOSITION: - /* toggle the content-disposition between inline/attachment */ - idx[menu->current]->content->disposition = (idx[menu->current]->content->disposition == DISPINLINE) ? DISPATTACH : DISPINLINE; - menu->redraw = REDRAW_CURRENT; - break; - - case OP_EDIT_TYPE: - CHECK_COUNT; - { - mutt_edit_content_type (NULL, idx[menu->current]->content, NULL); - - /* this may have been a change to text/something */ - mutt_update_encoding (idx[menu->current]->content); - - menu->redraw = REDRAW_CURRENT; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + mutt_error _("Invalid encoding."); + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; - case OP_COMPOSE_EDIT_ENCODING: - CHECK_COUNT; - strfcpy (buf, ENCODING (idx[menu->current]->content->encoding), - sizeof (buf)); - if (mutt_get_field ("Content-Transfer-Encoding: ", buf, - sizeof (buf), 0) == 0 && buf[0]) - { - if ((i = mutt_check_encoding (buf)) != ENCOTHER && i != ENCUUENCODED) - { - idx[menu->current]->content->encoding = i; - menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; - mutt_clear_error(); - } - else - mutt_error _("Invalid encoding."); - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + case OP_COMPOSE_SEND_MESSAGE: - case OP_COMPOSE_SEND_MESSAGE: + /* Note: We don't invoke send2-hook here, since we want to leave + * users an opportunity to change settings from the ":" prompt. + */ + + if (check_attachments (idx, idxlen) != 0) { + menu->redraw = REDRAW_FULL; + break; + } - /* Note: We don't invoke send2-hook here, since we want to leave - * users an opportunity to change settings from the ":" prompt. - */ - - if(check_attachments(idx, idxlen) != 0) - { - menu->redraw = REDRAW_FULL; - break; - } - #ifdef MIXMASTER - if (msg->chain && mix_check_message (msg) != 0) - break; + if (msg->chain && mix_check_message (msg) != 0) + break; #endif - - if (!fccSet && *fcc) - { - if ((i = query_quadoption (OPT_COPY, - _("Save a copy of this message?"))) == -1) - break; - else if (i == M_NO) - *fcc = 0; - } - - loop = 0; - r = 0; - break; - - case OP_COMPOSE_EDIT_FILE: - CHECK_COUNT; - mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename); - mutt_update_encoding (idx[menu->current]->content); - menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - case OP_COMPOSE_TOGGLE_UNLINK: - CHECK_COUNT; - idx[menu->current]->content->unlink = !idx[menu->current]->content->unlink; + if (!fccSet && *fcc) { + if ((i = query_quadoption (OPT_COPY, + _("Save a copy of this message?"))) == -1) + break; + else if (i == M_NO) + *fcc = 0; + } + + loop = 0; + r = 0; + break; + + case OP_COMPOSE_EDIT_FILE: + CHECK_COUNT; + mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename); + mutt_update_encoding (idx[menu->current]->content); + menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_TOGGLE_UNLINK: + CHECK_COUNT; + idx[menu->current]->content->unlink = + !idx[menu->current]->content->unlink; #if 0 - /* OPTRESOLVE is otherwise ignored on this menu. - * Where's the bug? - */ + /* OPTRESOLVE is otherwise ignored on this menu. + * Where's the bug? + */ - if (option (OPTRESOLVE) && menu->current + 1 < menu->max) - menu->current++; + if (option (OPTRESOLVE) && menu->current + 1 < menu->max) + menu->current++; # endif - menu->redraw = REDRAW_INDEX; - /* No send2hook since this doesn't change the message. */ - break; + menu->redraw = REDRAW_INDEX; + /* No send2hook since this doesn't change the message. */ + break; - case OP_COMPOSE_GET_ATTACHMENT: - CHECK_COUNT; - if(menu->tagprefix) - { - BODY *top; - for(top = msg->content; top; top = top->next) - { - if(top->tagged) - mutt_get_tmp_attachment(top); - } - menu->redraw = REDRAW_FULL; - } - else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0) - menu->redraw = REDRAW_CURRENT; - - /* No send2hook since this doesn't change the message. */ - break; - - case OP_COMPOSE_RENAME_FILE: - CHECK_COUNT; - strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); - mutt_pretty_mailbox (fname); - if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE) - == 0 && fname[0]) - { - if (stat(idx[menu->current]->content->filename, &st) == -1) - { - mutt_error (_("Can't stat %s: %s"), fname, strerror (errno)); - break; - } - - mutt_expand_path (fname, sizeof (fname)); - if(mutt_rename_file (idx[menu->current]->content->filename, fname)) - break; - - mutt_str_replace (&idx[menu->current]->content->filename, fname); - menu->redraw = REDRAW_CURRENT; - - if(idx[menu->current]->content->stamp >= st.st_mtime) - mutt_stamp_attachment(idx[menu->current]->content); - - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + case OP_COMPOSE_GET_ATTACHMENT: + CHECK_COUNT; + if (menu->tagprefix) { + BODY *top; + + for (top = msg->content; top; top = top->next) { + if (top->tagged) + mutt_get_tmp_attachment (top); + } + menu->redraw = REDRAW_FULL; + } + else if (mutt_get_tmp_attachment (idx[menu->current]->content) == 0) + menu->redraw = REDRAW_CURRENT; + + /* No send2hook since this doesn't change the message. */ + break; + + case OP_COMPOSE_RENAME_FILE: + CHECK_COUNT; + strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); + mutt_pretty_mailbox (fname); + if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE) + == 0 && fname[0]) { + if (stat (idx[menu->current]->content->filename, &st) == -1) { + mutt_error (_("Can't stat %s: %s"), fname, strerror (errno)); + break; + } + + mutt_expand_path (fname, sizeof (fname)); + if (mutt_rename_file (idx[menu->current]->content->filename, fname)) + break; + + mutt_str_replace (&idx[menu->current]->content->filename, fname); + menu->redraw = REDRAW_CURRENT; + + if (idx[menu->current]->content->stamp >= st.st_mtime) + mutt_stamp_attachment (idx[menu->current]->content); - case OP_COMPOSE_NEW_MIME: - { - char type[STRING]; - char *p; - int itype; - FILE *fp; - - CLEARLINE (LINES-1); - fname[0] = 0; - if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE) - != 0 || !fname[0]) - continue; - mutt_expand_path (fname, sizeof (fname)); - - /* Call to lookup_mime_type () ? maybe later */ - type[0] = 0; - if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0 - || !type[0]) - continue; - - if (!(p = strchr (type, '/'))) - { - mutt_error _("Content-Type is of the form base/sub"); - continue; - } - *p++ = 0; - if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) - { - mutt_error (_("Unknown Content-Type %s"), type); - continue; - } - if (idxlen == idxmax) - { - safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); - menu->data = idx; - } - - idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - /* Touch the file */ - if (!(fp = safe_fopen (fname, "w"))) - { - mutt_error (_("Can't create file %s"), fname); - FREE (&idx[idxlen]); - continue; - } - fclose (fp); - - if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) - { - mutt_error _("What we have here is a failure to make an attachment"); - continue; - } - update_idx (menu, idx, idxlen++); - - idx[menu->current]->content->type = itype; - mutt_str_replace (&idx[menu->current]->content->subtype, p); - idx[menu->current]->content->unlink = 1; - menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; - - if (mutt_compose_attachment (idx[menu->current]->content)) - { - mutt_update_encoding (idx[menu->current]->content); - menu->redraw = REDRAW_FULL; - } - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_NEW_MIME: + { + char type[STRING]; + char *p; + int itype; + FILE *fp; + + CLEARLINE (LINES - 1); + fname[0] = 0; + if (mutt_get_field (_("New file: "), fname, sizeof (fname), M_FILE) + != 0 || !fname[0]) + continue; + mutt_expand_path (fname, sizeof (fname)); + + /* Call to lookup_mime_type () ? maybe later */ + type[0] = 0; + if (mutt_get_field ("Content-Type: ", type, sizeof (type), 0) != 0 + || !type[0]) + continue; + + if (!(p = strchr (type, '/'))) { + mutt_error _("Content-Type is of the form base/sub"); + + continue; + } + *p++ = 0; + if ((itype = mutt_check_mime_type (type)) == TYPEOTHER) { + mutt_error (_("Unknown Content-Type %s"), type); + continue; + } + if (idxlen == idxmax) { + safe_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); + menu->data = idx; + } + + idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); + /* Touch the file */ + if (!(fp = safe_fopen (fname, "w"))) { + mutt_error (_("Can't create file %s"), fname); + FREE (&idx[idxlen]); + continue; + } + fclose (fp); + + if ((idx[idxlen]->content = mutt_make_file_attach (fname)) == NULL) { + mutt_error + _("What we have here is a failure to make an attachment"); + continue; + } + update_idx (menu, idx, idxlen++); + + idx[menu->current]->content->type = itype; + mutt_str_replace (&idx[menu->current]->content->subtype, p); + idx[menu->current]->content->unlink = 1; + menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; + + if (mutt_compose_attachment (idx[menu->current]->content)) { + mutt_update_encoding (idx[menu->current]->content); + menu->redraw = REDRAW_FULL; + } + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_COMPOSE_EDIT_MIME: + CHECK_COUNT; + if (mutt_edit_attachment (idx[menu->current]->content)) { + mutt_update_encoding (idx[menu->current]->content); + menu->redraw = REDRAW_FULL; + } + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_VIEW_ATTACH: + case OP_DISPLAY_HEADERS: + CHECK_COUNT; + mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, + NULL, 0); + menu->redraw = REDRAW_FULL; + /* no send2hook, since this doesn't modify the message */ + break; + + case OP_SAVE: + CHECK_COUNT; + mutt_save_attachment_list (NULL, menu->tagprefix, + menu->tagprefix ? msg->content : idx[menu-> + current]-> + content, NULL, menu); + MAYBE_REDRAW (menu->redraw); + /* no send2hook, since this doesn't modify the message */ + break; + + case OP_PRINT: + CHECK_COUNT; + mutt_print_attachment_list (NULL, menu->tagprefix, + menu->tagprefix ? msg->content : idx[menu-> + current]-> + content); + /* no send2hook, since this doesn't modify the message */ + break; + + case OP_PIPE: + case OP_FILTER: + CHECK_COUNT; + mutt_pipe_attachment_list (NULL, menu->tagprefix, + menu->tagprefix ? msg->content : idx[menu-> + current]-> + content, op == OP_FILTER); + if (op == OP_FILTER) /* cte might have changed */ + menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; + menu->redraw |= REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + + case OP_EXIT: + if ((i = + query_quadoption (OPT_POSTPONE, + _("Postpone this message?"))) == M_NO) { + while (idxlen-- > 0) { + /* avoid freeing other attachments */ + idx[idxlen]->content->next = NULL; + idx[idxlen]->content->parts = NULL; + mutt_free_body (&idx[idxlen]->content); + FREE (&idx[idxlen]->tree); + FREE (&idx[idxlen]); + } + FREE (&idx); + idxlen = 0; + idxmax = 0; + r = -1; + loop = 0; break; + } + else if (i == -1) + break; /* abort */ - case OP_COMPOSE_EDIT_MIME: - CHECK_COUNT; - if (mutt_edit_attachment (idx[menu->current]->content)) - { - mutt_update_encoding (idx[menu->current]->content); - menu->redraw = REDRAW_FULL; - } - mutt_message_hook (NULL, msg, M_SEND2HOOK); + /* fall through to postpone! */ + + case OP_COMPOSE_POSTPONE_MESSAGE: + + if (check_attachments (idx, idxlen) != 0) { + menu->redraw = REDRAW_FULL; break; + } - case OP_VIEW_ATTACH: - case OP_DISPLAY_HEADERS: - CHECK_COUNT; - mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0); - menu->redraw = REDRAW_FULL; - /* no send2hook, since this doesn't modify the message */ - break; - - case OP_SAVE: - CHECK_COUNT; - mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu); - MAYBE_REDRAW (menu->redraw); - /* no send2hook, since this doesn't modify the message */ - break; - - case OP_PRINT: - CHECK_COUNT; - mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content); - /* no send2hook, since this doesn't modify the message */ - break; - - case OP_PIPE: - case OP_FILTER: - CHECK_COUNT; - mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER); - if (op == OP_FILTER) /* cte might have changed */ - menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; + loop = 0; + r = 1; + break; + + case OP_COMPOSE_ISPELL: + endwin (); + snprintf (buf, sizeof (buf), "%s -x %s", NONULL (Ispell), + msg->content->filename); + if (mutt_system (buf) == -1) + mutt_error (_("Error running \"%s\"!"), buf); + else { + mutt_update_encoding (msg->content); menu->redraw |= REDRAW_STATUS; - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; - - case OP_EXIT: - if ((i = query_quadoption (OPT_POSTPONE, _("Postpone this message?"))) == M_NO) - { - while (idxlen-- > 0) - { - /* avoid freeing other attachments */ - idx[idxlen]->content->next = NULL; - idx[idxlen]->content->parts = NULL; - mutt_free_body (&idx[idxlen]->content); - FREE (&idx[idxlen]->tree); - FREE (&idx[idxlen]); - } - FREE (&idx); - idxlen = 0; - idxmax = 0; - r = -1; - loop = 0; - break; - } - else if (i == -1) - break; /* abort */ - - /* fall through to postpone! */ - - case OP_COMPOSE_POSTPONE_MESSAGE: - - if(check_attachments(idx, idxlen) != 0) - { - menu->redraw = REDRAW_FULL; - break; - } - - loop = 0; - r = 1; - break; - - case OP_COMPOSE_ISPELL: - endwin (); - snprintf (buf, sizeof (buf), "%s -x %s", NONULL(Ispell), msg->content->filename); - if (mutt_system (buf) == -1) - mutt_error (_("Error running \"%s\"!"), buf); - else - { - mutt_update_encoding (msg->content); - menu->redraw |= REDRAW_STATUS; - } - break; - - case OP_COMPOSE_WRITE_MESSAGE: - - fname[0] = '\0'; - if (Context) - { - strfcpy (fname, NONULL (Context->path), sizeof (fname)); - mutt_pretty_mailbox (fname); - } - if (idxlen) - msg->content = idx[0]->content; - if (mutt_enter_fname (_("Write message to mailbox"), fname, sizeof (fname), - &menu->redraw, 1) != -1 && fname[0]) - { - mutt_message (_("Writing message to %s ..."), fname); - mutt_expand_path (fname, sizeof (fname)); - - if (msg->content->next) - msg->content = mutt_make_multipart (msg->content); - - if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0) - msg->content = mutt_remove_multipart (msg->content); - else - mutt_message _("Message written."); - } - break; - - - - case OP_COMPOSE_PGP_MENU: - if (!(WithCrypto & APPLICATION_PGP)) - break; - if ((WithCrypto & APPLICATION_SMIME) - && msg->security & APPLICATION_SMIME) - { - if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "), - M_YES) != M_YES) - { - mutt_clear_error (); - break; - } - msg->security = 0; - } - msg->security = crypt_pgp_send_menu (msg, &menu->redraw); - redraw_crypt_lines (msg); - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + } + break; + + case OP_COMPOSE_WRITE_MESSAGE: + fname[0] = '\0'; + if (Context) { + strfcpy (fname, NONULL (Context->path), sizeof (fname)); + mutt_pretty_mailbox (fname); + } + if (idxlen) + msg->content = idx[0]->content; + if (mutt_enter_fname + (_("Write message to mailbox"), fname, sizeof (fname), + &menu->redraw, 1) != -1 && fname[0]) { + mutt_message (_("Writing message to %s ..."), fname); + mutt_expand_path (fname, sizeof (fname)); + + if (msg->content->next) + msg->content = mutt_make_multipart (msg->content); + + if (mutt_write_fcc (NONULL (fname), msg, NULL, 1, NULL) < 0) + msg->content = mutt_remove_multipart (msg->content); + else + mutt_message _("Message written."); + } + break; - case OP_FORGET_PASSPHRASE: - crypt_forget_passphrase (); - break; - case OP_COMPOSE_SMIME_MENU: - if (!(WithCrypto & APPLICATION_SMIME)) + case OP_COMPOSE_PGP_MENU: + if (!(WithCrypto & APPLICATION_PGP)) + break; + if ((WithCrypto & APPLICATION_SMIME) + && msg->security & APPLICATION_SMIME) { + if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "), + M_YES) != M_YES) { + mutt_clear_error (); break; + } + msg->security = 0; + } + msg->security = crypt_pgp_send_menu (msg, &menu->redraw); + redraw_crypt_lines (msg); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; - if ((WithCrypto & APPLICATION_PGP) - && msg->security & APPLICATION_PGP) - { - if (mutt_yesorno (_("PGP already selected. Clear & continue ? "), - M_YES) != M_YES) - { - mutt_clear_error (); - break; - } - msg->security = 0; - } - msg->security = crypt_smime_send_menu(msg, &menu->redraw); - redraw_crypt_lines (msg); - mutt_message_hook (NULL, msg, M_SEND2HOOK); + + case OP_FORGET_PASSPHRASE: + crypt_forget_passphrase (); + break; + + + case OP_COMPOSE_SMIME_MENU: + if (!(WithCrypto & APPLICATION_SMIME)) break; + if ((WithCrypto & APPLICATION_PGP) + && msg->security & APPLICATION_PGP) { + if (mutt_yesorno (_("PGP already selected. Clear & continue ? "), + M_YES) != M_YES) { + mutt_clear_error (); + break; + } + msg->security = 0; + } + msg->security = crypt_smime_send_menu (msg, &menu->redraw); + redraw_crypt_lines (msg); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; + #ifdef MIXMASTER - case OP_COMPOSE_MIX: - - mix_make_chain (&msg->chain, &menu->redraw); - mutt_message_hook (NULL, msg, M_SEND2HOOK); - break; + case OP_COMPOSE_MIX: + + mix_make_chain (&msg->chain, &menu->redraw); + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; #endif } /* Draw formated compose status line */ - if (menu->redraw & REDRAW_STATUS) - { - compose_status_line (buf, sizeof (buf), menu, NONULL(ComposeFormat)); - CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); - SETCOLOR (MT_COLOR_STATUS); - printw ("%-*.*s", COLS, COLS, buf); - SETCOLOR (MT_COLOR_NORMAL); - menu->redraw &= ~REDRAW_STATUS; + if (menu->redraw & REDRAW_STATUS) { + compose_status_line (buf, sizeof (buf), menu, NONULL (ComposeFormat)); + CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2); + SETCOLOR (MT_COLOR_STATUS); + printw ("%-*.*s", COLS, COLS, buf); + SETCOLOR (MT_COLOR_NORMAL); + menu->redraw &= ~REDRAW_STATUS; } } mutt_menuDestroy (&menu); - if (idxlen) - { + if (idxlen) { msg->content = idx[0]->content; - for (i = 0; i < idxlen; i++) - { + for (i = 0; i < idxlen; i++) { idx[i]->content->aptr = NULL; FREE (&idx[i]); } @@ -1472,4 +1428,3 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ return (r); } - diff --git a/compress.c b/compress.c index 11d4fa4..1ac8355 100644 --- a/compress.c +++ b/compress.c @@ -29,12 +29,11 @@ #include #include -typedef struct -{ - const char *close; /* close-hook command */ - const char *open; /* open-hook command */ - const char *append; /* append-hook command */ - off_t size; /* size of real folder */ +typedef struct { + const char *close; /* close-hook command */ + const char *open; /* open-hook command */ + const char *append; /* append-hook command */ + off_t size; /* size of real folder */ } COMPRESS_INFO; char echo_cmd[HUGE_STRING]; @@ -44,14 +43,13 @@ char echo_cmd[HUGE_STRING]; * excl - exclusive lock? * retry - should retry if unable to lock? */ -int mbox_lock_compressed (CONTEXT *ctx, FILE *fp, int excl, int retry) +int mbox_lock_compressed (CONTEXT * ctx, FILE * fp, int excl, int retry) { int r; if ((r = mx_lock_file (ctx->realpath, fileno (fp), excl, 1, retry)) == 0) ctx->locked = 1; - else if (retry && !excl) - { + else if (retry && !excl) { ctx->readonly = 1; return 0; } @@ -59,10 +57,9 @@ int mbox_lock_compressed (CONTEXT *ctx, FILE *fp, int excl, int retry) return (r); } -void mbox_unlock_compressed (CONTEXT *ctx, FILE *fp) +void mbox_unlock_compressed (CONTEXT * ctx, FILE * fp) { - if (ctx->locked) - { + if (ctx->locked) { fflush (fp); mx_unlock_file (ctx->realpath, fileno (fp), 1); @@ -75,9 +72,10 @@ static int is_new (const char *path) return (access (path, W_OK) != 0 && errno == ENOENT) ? 1 : 0; } -static const char* find_compress_hook (int type, const char *path) +static const char *find_compress_hook (int type, const char *path) { - const char* c = mutt_find_hook (type, path); + const char *c = mutt_find_hook (type, path); + return (!c || !*c) ? NULL : c; } @@ -89,12 +87,13 @@ int mutt_can_read_compressed (const char *path) /* if the file is new, we really do not append, but create, and so use * close-hook, and not append-hook */ -static const char* get_append_command (const char *path, const CONTEXT* ctx) +static const char *get_append_command (const char *path, const CONTEXT * ctx) { COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; + return (is_new (path)) ? ci->close : ci->append; } - + int mutt_can_append_compressed (const char *path) { int magic; @@ -103,30 +102,30 @@ int mutt_can_append_compressed (const char *path) return (find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0); magic = mx_get_magic (path); - + if (magic != 0 && magic != M_COMPRESSED) return 0; return (find_compress_hook (M_APPENDHOOK, path) - || (find_compress_hook (M_OPENHOOK, path) - && find_compress_hook (M_CLOSEHOOK, path))) ? 1 : 0; + || (find_compress_hook (M_OPENHOOK, path) + && find_compress_hook (M_CLOSEHOOK, path))) ? 1 : 0; } /* open a compressed mailbox */ -static COMPRESS_INFO *set_compress_info (CONTEXT *ctx) +static COMPRESS_INFO *set_compress_info (CONTEXT * ctx) { COMPRESS_INFO *ci; /* Now lets uncompress this thing */ ci = safe_malloc (sizeof (COMPRESS_INFO)); - ctx->compressinfo = (void*) ci; + ctx->compressinfo = (void *) ci; ci->append = find_compress_hook (M_APPENDHOOK, ctx->path); ci->open = find_compress_hook (M_OPENHOOK, ctx->path); ci->close = find_compress_hook (M_CLOSEHOOK, ctx->path); return ci; } - -static void set_path (CONTEXT* ctx) + +static void set_path (CONTEXT * ctx) { char tmppath[_POSIX_PATH_MAX]; @@ -139,31 +138,35 @@ static void set_path (CONTEXT* ctx) strcpy (ctx->path, tmppath); } -static int get_size (const char* path) +static int get_size (const char *path) { struct stat sb; + if (stat (path, &sb) != 0) return 0; return (sb.st_size); } -static void store_size (CONTEXT* ctx) +static void store_size (CONTEXT * ctx) { COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; + ci->size = get_size (ctx->realpath); } -static const char * -compresshook_format_str (char *dest, size_t destlen, char op, const char *src, - const char *fmt, const char *ifstring, - const char *elsestring, unsigned long data, - format_flag flags) +static const char *compresshook_format_str (char *dest, size_t destlen, + char op, const char *src, + const char *fmt, + const char *ifstring, + const char *elsestring, + unsigned long data, + format_flag flags) { char tmp[SHORT_STRING]; - + CONTEXT *ctx = (CONTEXT *) data; - switch (op) - { + + switch (op) { case 'f': snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, ctx->realpath); @@ -179,39 +182,42 @@ compresshook_format_str (char *dest, size_t destlen, char op, const char *src, /* check that the command has both %f and %t * 0 means OK, -1 means error */ -int mutt_test_compress_command (const char* cmd) +int mutt_test_compress_command (const char *cmd) { return (strstr (cmd, "%f") && strstr (cmd, "%t")) ? 0 : -1; } -static char *get_compression_cmd (const char* cmd, const CONTEXT* ctx) +static char *get_compression_cmd (const char *cmd, const CONTEXT * ctx) { char expanded[_POSIX_PATH_MAX]; - mutt_FormatString (expanded, sizeof (expanded), cmd, compresshook_format_str, - (unsigned long) ctx, 0); + + mutt_FormatString (expanded, sizeof (expanded), cmd, + compresshook_format_str, (unsigned long) ctx, 0); return safe_strdup (expanded); } -int mutt_check_mailbox_compressed (CONTEXT* ctx) +int mutt_check_mailbox_compressed (CONTEXT * ctx) { COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; - if (ci->size != get_size (ctx->realpath)) - { + + if (ci->size != get_size (ctx->realpath)) { FREE (&ctx->compressinfo); FREE (&ctx->realpath); mutt_error _("Mailbox was corrupted!"); + return (-1); } return (0); } -int mutt_open_read_compressed (CONTEXT *ctx) +int mutt_open_read_compressed (CONTEXT * ctx) { char *cmd; FILE *fp; int rc; COMPRESS_INFO *ci = set_compress_info (ctx); + if (!ci->open) { ctx->magic = 0; FREE (ctx->compressinfo); @@ -227,44 +233,43 @@ int mutt_open_read_compressed (CONTEXT *ctx) mutt_message (_("Decompressing %s..."), ctx->realpath); cmd = get_compression_cmd (ci->open, ctx); - if (cmd == NULL) + if (cmd == NULL) return (-1); dprint (2, (debugfile, "DecompressCmd: '%s'\n", cmd)); - if ((fp = fopen (ctx->realpath, "r")) == NULL) - { + if ((fp = fopen (ctx->realpath, "r")) == NULL) { mutt_perror (ctx->realpath); FREE (&cmd); return (-1); } mutt_block_signals (); - if (mbox_lock_compressed (ctx, fp, 0, 1) == -1) - { + if (mbox_lock_compressed (ctx, fp, 0, 1) == -1) { fclose (fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); + FREE (&cmd); return (-1); } endwin (); fflush (stdout); - sprintf(echo_cmd,_("echo Decompressing %s..."),ctx->realpath); - mutt_system(echo_cmd); + sprintf (echo_cmd, _("echo Decompressing %s..."), ctx->realpath); + mutt_system (echo_cmd); rc = mutt_system (cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); fclose (fp); - if (rc) - { + if (rc) { mutt_any_key_to_continue (NULL); ctx->magic = 0; FREE (ctx->compressinfo); - mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), cmd); + mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), + cmd); } FREE (&cmd); - if (rc) + if (rc) return (-1); if (mutt_check_mailbox_compressed (ctx)) @@ -275,26 +280,25 @@ int mutt_open_read_compressed (CONTEXT *ctx) return (0); } -void restore_path (CONTEXT* ctx) +void restore_path (CONTEXT * ctx) { FREE (&ctx->path); ctx->path = ctx->realpath; } /* remove the temporary mailbox */ -void remove_file (CONTEXT* ctx) +void remove_file (CONTEXT * ctx) { if (ctx->magic == M_MBOX || ctx->magic == M_MMDF) remove (ctx->path); } -int mutt_open_append_compressed (CONTEXT *ctx) +int mutt_open_append_compressed (CONTEXT * ctx) { FILE *fh; COMPRESS_INFO *ci = set_compress_info (ctx); - if (!get_append_command (ctx->path, ctx)) - { + if (!get_append_command (ctx->path, ctx)) { if (ci->open && ci->close) return (mutt_open_read_compressed (ctx)); @@ -310,25 +314,24 @@ int mutt_open_append_compressed (CONTEXT *ctx) if (!is_new (ctx->realpath)) if (ctx->magic == M_MBOX || ctx->magic == M_MMDF) if ((fh = safe_fopen (ctx->path, "w"))) - fclose (fh); + fclose (fh); /* No error checking - the parent function will catch it */ return (0); } /* close a compressed mailbox */ -void mutt_fast_close_compressed (CONTEXT *ctx) +void mutt_fast_close_compressed (CONTEXT * ctx) { dprint (2, (debugfile, "mutt_fast_close_compressed called on '%s'\n", - ctx->path)); + ctx->path)); - if (ctx->compressinfo) - { + if (ctx->compressinfo) { if (ctx->fp) fclose (ctx->fp); ctx->fp = NULL; /* if the folder was removed, remove the gzipped folder too */ - if (access (ctx->path, F_OK) != 0 && ! option (OPTSAVEEMPTY)) + if (access (ctx->path, F_OK) != 0 && !option (OPTSAVEEMPTY)) remove (ctx->realpath); else remove_file (ctx); @@ -339,7 +342,7 @@ void mutt_fast_close_compressed (CONTEXT *ctx) } /* return 0 on success, -1 on failure */ -int mutt_sync_compressed (CONTEXT* ctx) +int mutt_sync_compressed (CONTEXT * ctx) { char *cmd; int rc = 0; @@ -350,23 +353,21 @@ int mutt_sync_compressed (CONTEXT* ctx) mutt_message (_("Compressing %s..."), ctx->realpath); cmd = get_compression_cmd (ci->close, ctx); - if (cmd == NULL) + if (cmd == NULL) return (-1); - if ((fp = fopen (ctx->realpath, "a")) == NULL) - { + if ((fp = fopen (ctx->realpath, "a")) == NULL) { mutt_perror (ctx->realpath); FREE (&cmd); return (-1); } mutt_block_signals (); - if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) - { + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) { fclose (fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); - store_size (ctx); + store_size (ctx); FREE (&cmd); return (-1); @@ -376,12 +377,13 @@ int mutt_sync_compressed (CONTEXT* ctx) endwin (); fflush (stdout); - sprintf(echo_cmd,_("echo Compressing %s..."), ctx->realpath); - mutt_system(echo_cmd); - if (mutt_system (cmd)) - { + sprintf (echo_cmd, _("echo Compressing %s..."), ctx->realpath); + mutt_system (echo_cmd); + if (mutt_system (cmd)) { mutt_any_key_to_continue (NULL); - mutt_error (_("%s: Error compressing mailbox! Original mailbox deleted, uncompressed one kept!\n"), ctx->path); + mutt_error (_ + ("%s: Error compressing mailbox! Original mailbox deleted, uncompressed one kept!\n"), + ctx->path); rc = -1; } @@ -390,29 +392,27 @@ int mutt_sync_compressed (CONTEXT* ctx) fclose (fp); FREE (&cmd); - + store_size (ctx); return (rc); } -int mutt_slow_close_compressed (CONTEXT *ctx) +int mutt_slow_close_compressed (CONTEXT * ctx) { FILE *fp; const char *append; char *cmd; COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; - dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n", - ctx->path)); + dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n", + ctx->path)); - if (! (ctx->append - && ((append = get_append_command (ctx->realpath, ctx)) - || (append = ci->close)))) - { /* if we can not or should not append, - * we only have to remove the compressed info, because sync was already - * called - */ + if (!(ctx->append && ((append = get_append_command (ctx->realpath, ctx)) + || (append = ci->close)))) { /* if we can not or should not append, + * we only have to remove the compressed info, because sync was already + * called + */ mutt_fast_close_compressed (ctx); return (0); } @@ -421,8 +421,7 @@ int mutt_slow_close_compressed (CONTEXT *ctx) fclose (ctx->fp); ctx->fp = NULL; - if (!ctx->quiet) - { + if (!ctx->quiet) { if (append == ci->close) mutt_message (_("Compressing %s..."), ctx->realpath); else @@ -430,21 +429,20 @@ int mutt_slow_close_compressed (CONTEXT *ctx) } cmd = get_compression_cmd (append, ctx); - if (cmd == NULL) + if (cmd == NULL) return (-1); - if ((fp = fopen (ctx->realpath, "a")) == NULL) - { + if ((fp = fopen (ctx->realpath, "a")) == NULL) { mutt_perror (ctx->realpath); FREE (&cmd); return (-1); } mutt_block_signals (); - if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) - { + if (mbox_lock_compressed (ctx, fp, 1, 1) == -1) { fclose (fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); + FREE (&cmd); return (-1); } @@ -455,16 +453,17 @@ int mutt_slow_close_compressed (CONTEXT *ctx) fflush (stdout); if (append == ci->close) - sprintf(echo_cmd,_("echo Compressing %s..."), ctx->realpath); + sprintf (echo_cmd, _("echo Compressing %s..."), ctx->realpath); else - sprintf(echo_cmd,_("echo Compressed-appending to %s..."), ctx->realpath); - mutt_system(echo_cmd); + sprintf (echo_cmd, _("echo Compressed-appending to %s..."), + ctx->realpath); + mutt_system (echo_cmd); - if (mutt_system (cmd)) - { + if (mutt_system (cmd)) { mutt_any_key_to_continue (NULL); - mutt_error (_(" %s: Error compressing mailbox! Uncompressed one kept!\n"), - ctx->path); + mutt_error (_ + (" %s: Error compressing mailbox! Uncompressed one kept!\n"), + ctx->path); FREE (&cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); diff --git a/config.h.in b/config.h.in index 126df1e..dc0b806 100644 --- a/config.h.in +++ b/config.h.in @@ -496,9 +496,9 @@ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at run-time. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION /* Define to 1 if you have the ANSI C header files. */ @@ -596,9 +596,11 @@ typedef unsigned long long uint64_t; /* Define to empty if `const' does not conform to ANSI C. */ #undef const -/* Define as `__inline' if that's what the C compiler calls it, or to nothing - if it is not supported. */ +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus #undef inline +#endif /* Define to 'int' if system headers don't define. */ #undef mbstate_t diff --git a/copy.c b/copy.c index 9afdc25..f68d45f 100644 --- a/copy.c +++ b/copy.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -32,22 +32,23 @@ #include #include #include -#include /* needed for SEEK_SET under SunOS 4.1.4 */ +#include /* needed for SEEK_SET under SunOS 4.1.4 */ static int address_header_decode (char **str); -static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date); +static int copy_delete_attach (BODY * b, FILE * fpin, FILE * fpout, + char *date); /* Ok, the only reason for not merging this with mutt_copy_header() * below is to avoid creating a HEADER structure in message_handler(). */ int -mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, - const char *prefix) +mutt_copy_hdr (FILE * in, FILE * out, long off_start, long off_end, int flags, + const char *prefix) { int from = 0; int this_is_from; int ignore = 0; - char buf[STRING]; /* should be long enough to get most fields in one pass */ + char buf[STRING]; /* should be long enough to get most fields in one pass */ char *nl; LIST *t; char **headers; @@ -62,54 +63,52 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, buf[0] = '\n'; buf[1] = 0; - if ((flags & (CH_REORDER | CH_WEED | CH_MIME | CH_DECODE | CH_PREFIX | CH_WEED_DELIVERED)) == 0) - { + if ((flags & + (CH_REORDER | CH_WEED | CH_MIME | CH_DECODE | CH_PREFIX | + CH_WEED_DELIVERED)) == 0) { /* Without these flags to complicate things * we can do a more efficient line to line copying */ - while (ftell (in) < off_end) - { + while (ftell (in) < off_end) { nl = strchr (buf, '\n'); if ((fgets (buf, sizeof (buf), in)) == NULL) - break; + break; /* Is it the begining of a header? */ - if (nl && buf[0] != ' ' && buf[0] != '\t') - { - ignore = 1; - if (!from && mutt_strncmp ("From ", buf, 5) == 0) - { - if ((flags & CH_FROM) == 0) - continue; - from = 1; - } - else if (flags & (CH_NOQFROM) && - ascii_strncasecmp (">From ", buf, 6) == 0) - continue; - - else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) - break; /* end of header */ - - if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) && - (ascii_strncasecmp ("Status:", buf, 7) == 0 || - ascii_strncasecmp ("X-Status:", buf, 9) == 0)) - continue; - if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) && - (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 || - ascii_strncasecmp ("Lines:", buf, 6) == 0)) - continue; - if ((flags & CH_UPDATE_REFS) && - ascii_strncasecmp ("References:", buf, 11) == 0) - continue; - if ((flags & CH_UPDATE_IRT) && - ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0) - continue; - ignore = 0; + if (nl && buf[0] != ' ' && buf[0] != '\t') { + ignore = 1; + if (!from && mutt_strncmp ("From ", buf, 5) == 0) { + if ((flags & CH_FROM) == 0) + continue; + from = 1; + } + else if (flags & (CH_NOQFROM) && + ascii_strncasecmp (">From ", buf, 6) == 0) + continue; + + else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) + break; /* end of header */ + + if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) && + (ascii_strncasecmp ("Status:", buf, 7) == 0 || + ascii_strncasecmp ("X-Status:", buf, 9) == 0)) + continue; + if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) && + (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 || + ascii_strncasecmp ("Lines:", buf, 6) == 0)) + continue; + if ((flags & CH_UPDATE_REFS) && + ascii_strncasecmp ("References:", buf, 11) == 0) + continue; + if ((flags & CH_UPDATE_IRT) && + ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0) + continue; + ignore = 0; } if (!ignore && fputs (buf, out) == EOF) - return (-1); + return (-1); } return 0; } @@ -122,11 +121,9 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, * so we are able to do re-ordering. * First count the number of entries in the array */ - if (flags & CH_REORDER) - { - for (t = HeaderOrderList; t; t = t->next) - { - dprint(1, (debugfile, "Reorder list: %s\n", t->data)); + if (flags & CH_REORDER) { + for (t = HeaderOrderList; t; t = t->next) { + dprint (1, (debugfile, "Reorder list: %s\n", t->data)); hdr_count++; } } @@ -136,8 +133,7 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, headers = safe_calloc (hdr_count, sizeof (char *)); /* Read all the headers into the array */ - while (ftell (in) < off_end) - { + while (ftell (in) < off_end) { nl = strchr (buf, '\n'); /* Read a line */ @@ -145,172 +141,152 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, break; /* Is it the begining of a header? */ - if (nl && buf[0] != ' ' && buf[0] != '\t') - { + if (nl && buf[0] != ' ' && buf[0] != '\t') { /* Do we have anything pending? */ - if (this_one) - { - if (flags & CH_DECODE) - { - if (!address_header_decode (&this_one)) - rfc2047_decode (&this_one); - } - - if (!headers[x]) - headers[x] = this_one; - else - { - safe_realloc (&headers[x], mutt_strlen (headers[x]) + - mutt_strlen (this_one) + sizeof (char)); - strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ - FREE (&this_one); - } - - this_one = NULL; + if (this_one) { + if (flags & CH_DECODE) { + if (!address_header_decode (&this_one)) + rfc2047_decode (&this_one); + } + + if (!headers[x]) + headers[x] = this_one; + else { + safe_realloc (&headers[x], mutt_strlen (headers[x]) + + mutt_strlen (this_one) + sizeof (char)); + strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ + FREE (&this_one); + } + + this_one = NULL; } - + ignore = 1; this_is_from = 0; - if (!from && mutt_strncmp ("From ", buf, 5) == 0) - { - if ((flags & CH_FROM) == 0) - continue; - this_is_from = from = 1; + if (!from && mutt_strncmp ("From ", buf, 5) == 0) { + if ((flags & CH_FROM) == 0) + continue; + this_is_from = from = 1; } else if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) - break; /* end of header */ + break; /* end of header */ /* note: CH_FROM takes precedence over header weeding. */ if (!((flags & CH_FROM) && (flags & CH_FORCE_FROM) && this_is_from) && - (flags & CH_WEED) && - mutt_matches_ignore (buf, Ignore) && - !mutt_matches_ignore (buf, UnIgnore)) - continue; + (flags & CH_WEED) && + mutt_matches_ignore (buf, Ignore) && + !mutt_matches_ignore (buf, UnIgnore)) + continue; if ((flags & CH_WEED_DELIVERED) && - ascii_strncasecmp ("Delivered-To:", buf, 13) == 0) - continue; + ascii_strncasecmp ("Delivered-To:", buf, 13) == 0) + continue; if ((flags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) && - (ascii_strncasecmp ("Status:", buf, 7) == 0 || - ascii_strncasecmp ("X-Status:", buf, 9) == 0)) - continue; + (ascii_strncasecmp ("Status:", buf, 7) == 0 || + ascii_strncasecmp ("X-Status:", buf, 9) == 0)) + continue; if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) && - (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 || - ascii_strncasecmp ("Lines:", buf, 6) == 0)) - continue; + (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 || + ascii_strncasecmp ("Lines:", buf, 6) == 0)) + continue; if ((flags & CH_MIME) && - ((ascii_strncasecmp ("content-", buf, 8) == 0 && - (ascii_strncasecmp ("transfer-encoding:", buf + 8, 18) == 0 || - ascii_strncasecmp ("type:", buf + 8, 5) == 0)) || - ascii_strncasecmp ("mime-version:", buf, 13) == 0)) - continue; + ((ascii_strncasecmp ("content-", buf, 8) == 0 && + (ascii_strncasecmp ("transfer-encoding:", buf + 8, 18) == 0 || + ascii_strncasecmp ("type:", buf + 8, 5) == 0)) || + ascii_strncasecmp ("mime-version:", buf, 13) == 0)) + continue; if ((flags & CH_UPDATE_REFS) && - ascii_strncasecmp ("References:", buf, 11) == 0) - continue; + ascii_strncasecmp ("References:", buf, 11) == 0) + continue; if ((flags & CH_UPDATE_IRT) && - ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0) - continue; + ascii_strncasecmp ("In-Reply-To:", buf, 12) == 0) + continue; /* Find x -- the array entry where this header is to be saved */ - if (flags & CH_REORDER) - { - for (t = HeaderOrderList, x = 0 ; (t) ; t = t->next, x++) - { - if (!ascii_strncasecmp (buf, t->data, mutt_strlen (t->data))) - { - dprint(2, (debugfile, "Reorder: %s matches %s\n", t->data, buf)); - break; - } - } + if (flags & CH_REORDER) { + for (t = HeaderOrderList, x = 0; (t); t = t->next, x++) { + if (!ascii_strncasecmp (buf, t->data, mutt_strlen (t->data))) { + dprint (2, (debugfile, "Reorder: %s matches %s\n", t->data, buf)); + break; + } + } } - + ignore = 0; - } /* If beginning of header */ + } /* If beginning of header */ - if (!ignore) - { - dprint (2, (debugfile, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count)); + if (!ignore) { + dprint (2, + (debugfile, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count)); if (!this_one) - this_one = safe_strdup (buf); - else - { - safe_realloc (&this_one, - mutt_strlen (this_one) + mutt_strlen (buf) + sizeof (char)); - strcat (this_one, buf); /* __STRCAT_CHECKED__ */ + this_one = safe_strdup (buf); + else { + safe_realloc (&this_one, + mutt_strlen (this_one) + mutt_strlen (buf) + + sizeof (char)); + strcat (this_one, buf); /* __STRCAT_CHECKED__ */ } } - } /* while (ftell (in) < off_end) */ + } /* while (ftell (in) < off_end) */ /* Do we have anything pending? -- XXX, same code as in above in the loop. */ - if (this_one) - { - if (flags & CH_DECODE) - { + if (this_one) { + if (flags & CH_DECODE) { if (!address_header_decode (&this_one)) - rfc2047_decode (&this_one); + rfc2047_decode (&this_one); } - + if (!headers[x]) headers[x] = this_one; - else - { - safe_realloc (&headers[x], mutt_strlen (headers[x]) + - mutt_strlen (this_one) + sizeof (char)); - strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ + else { + safe_realloc (&headers[x], mutt_strlen (headers[x]) + + mutt_strlen (this_one) + sizeof (char)); + strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ FREE (&this_one); } - + this_one = NULL; } /* Now output the headers in order */ - for (x = 0; x < hdr_count; x++) - { - if (headers[x]) - { + for (x = 0; x < hdr_count; x++) { + if (headers[x]) { #if 0 if (flags & CH_DECODE) - rfc2047_decode (&headers[x]); + rfc2047_decode (&headers[x]); #endif /* We couldn't do the prefixing when reading because RFC 2047 * decoding may have concatenated lines. */ - if (flags & CH_PREFIX) - { - char *ch = headers[x]; - int print_prefix = 1; - - while (*ch) - { - if (print_prefix) - { - if (fputs (prefix, out) == EOF) - { - error = TRUE; - break; - } - print_prefix = 0; - } - - if (*ch == '\n' && ch[1]) - print_prefix = 1; - - if (putc (*ch++, out) == EOF) - { - error = TRUE; - break; - } - } - if (error) - break; + if (flags & CH_PREFIX) { + char *ch = headers[x]; + int print_prefix = 1; + + while (*ch) { + if (print_prefix) { + if (fputs (prefix, out) == EOF) { + error = TRUE; + break; + } + print_prefix = 0; + } + + if (*ch == '\n' && ch[1]) + print_prefix = 1; + + if (putc (*ch++, out) == EOF) { + error = TRUE; + break; + } + } + if (error) + break; } - else - { - if (fputs (headers[x], out) == EOF) - { - error = TRUE; - break; - } + else { + if (fputs (headers[x], out) == EOF) { + error = TRUE; + break; + } } } } @@ -350,171 +326,158 @@ mutt_copy_hdr (FILE *in, FILE *out, long off_start, long off_end, int flags, */ int -mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) +mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags, + const char *prefix) { char buffer[SHORT_STRING]; flags |= (h->irt_changed ? CH_UPDATE_IRT : 0) - | (h->refs_changed ? CH_UPDATE_REFS : 0); - - if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == -1) + | (h->refs_changed ? CH_UPDATE_REFS : 0); + + if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == + -1) return (-1); - if (flags & CH_TXTPLAIN) - { + if (flags & CH_TXTPLAIN) { char chsbuf[SHORT_STRING]; + fputs ("Mime-Version: 1.0\n", out); fputs ("Content-Transfer-Encoding: 8bit\n", out); fputs ("Content-Type: text/plain; charset=", out); - mutt_canonical_charset (chsbuf, sizeof (chsbuf), Charset ? Charset : "us-ascii"); - rfc822_cat(buffer, sizeof(buffer), chsbuf, MimeSpecials); - fputs(buffer, out); - fputc('\n', out); - + mutt_canonical_charset (chsbuf, sizeof (chsbuf), + Charset ? Charset : "us-ascii"); + rfc822_cat (buffer, sizeof (buffer), chsbuf, MimeSpecials); + fputs (buffer, out); + fputc ('\n', out); + if (ferror (out) != 0 || feof (out) != 0) return -1; - + } - if (flags & CH_UPDATE) - { - if ((flags & CH_NOSTATUS) == 0) - { - if (h->irt_changed && h->new_env->in_reply_to) - { - LIST *listp = h->new_env->in_reply_to; + if (flags & CH_UPDATE) { + if ((flags & CH_NOSTATUS) == 0) { + if (h->irt_changed && h->new_env->in_reply_to) { + LIST *listp = h->new_env->in_reply_to; - if (fputs ("In-Reply-To: ", out) == EOF) - return (-1); + if (fputs ("In-Reply-To: ", out) == EOF) + return (-1); - for (; listp; listp = listp->next) - if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF)) - return (-1); + for (; listp; listp = listp->next) + if ((fputs (listp->data, out) == EOF) || (fputc (' ', out) == EOF)) + return (-1); - if (fputc ('\n', out) == EOF) - return (-1); + if (fputc ('\n', out) == EOF) + return (-1); } - if (h->refs_changed && h->new_env->references) - { - LIST *listp = h->new_env->references, *refs = NULL, *t; - - if (fputs ("References: ", out) == EOF) - return (-1); - - /* Mutt stores references in reverse order, thus we create - * a reordered refs list that we can put in the headers */ - for (; listp; listp = listp->next, refs = t) - { - t = (LIST *)safe_malloc (sizeof (LIST)); - t->data = listp->data; - t->next = refs; - } - - for (; refs; refs = refs->next) - if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF)) - return (-1); - - /* clearing refs from memory */ - for (t = refs; refs; refs = t->next, t = refs) - FREE(&refs); - - if (fputc ('\n', out) == EOF) - return (-1); + if (h->refs_changed && h->new_env->references) { + LIST *listp = h->new_env->references, *refs = NULL, *t; + + if (fputs ("References: ", out) == EOF) + return (-1); + + /* Mutt stores references in reverse order, thus we create + * a reordered refs list that we can put in the headers */ + for (; listp; listp = listp->next, refs = t) { + t = (LIST *) safe_malloc (sizeof (LIST)); + t->data = listp->data; + t->next = refs; + } + + for (; refs; refs = refs->next) + if ((fputs (refs->data, out) == EOF) || (fputc (' ', out) == EOF)) + return (-1); + + /* clearing refs from memory */ + for (t = refs; refs; refs = t->next, t = refs) + FREE (&refs); + + if (fputc ('\n', out) == EOF) + return (-1); } - if (h->old || h->read) - { - if (fputs ("Status: ", out) == EOF) - return (-1); - - if (h->read) - { - if (fputs ("RO", out) == EOF) - return (-1); - } - else if (h->old) - { - if (fputc ('O', out) == EOF) - return (-1); - } - - if (fputc ('\n', out) == EOF) - return (-1); + if (h->old || h->read) { + if (fputs ("Status: ", out) == EOF) + return (-1); + + if (h->read) { + if (fputs ("RO", out) == EOF) + return (-1); + } + else if (h->old) { + if (fputc ('O', out) == EOF) + return (-1); + } + + if (fputc ('\n', out) == EOF) + return (-1); } - if (h->flagged || h->replied) - { - if (fputs ("X-Status: ", out) == EOF) - return (-1); - - if (h->replied) - { - if (fputc ('A', out) == EOF) - return (-1); - } - - if (h->flagged) - { - if (fputc ('F', out) == EOF) - return (-1); - } - - if (fputc ('\n', out) == EOF) - return (-1); + if (h->flagged || h->replied) { + if (fputs ("X-Status: ", out) == EOF) + return (-1); + + if (h->replied) { + if (fputc ('A', out) == EOF) + return (-1); + } + + if (h->flagged) { + if (fputc ('F', out) == EOF) + return (-1); + } + + if (fputc ('\n', out) == EOF) + return (-1); } } } - if (flags & CH_UPDATE_LEN && - (flags & CH_NOLEN) == 0) - { + if (flags & CH_UPDATE_LEN && (flags & CH_NOLEN) == 0) { fprintf (out, "Content-Length: %ld\n", h->content->length); if (h->lines != 0 || h->content->length == 0) fprintf (out, "Lines: %d\n", h->lines); } - if ((flags & CH_NONEWLINE) == 0) - { + if ((flags & CH_NONEWLINE) == 0) { if (flags & CH_PREFIX) - fputs(prefix, out); - if (fputc ('\n', out) == EOF) /* add header terminator */ + fputs (prefix, out); + if (fputc ('\n', out) == EOF) /* add header terminator */ return (-1); } if (ferror (out) || feof (out)) return -1; - + return (0); } /* Count the number of lines and bytes to be deleted in this body*/ -static int count_delete_lines (FILE *fp, BODY *b, long *length, size_t datelen) +static int count_delete_lines (FILE * fp, BODY * b, long *length, + size_t datelen) { int dellines = 0; long l; int ch; - if (b->deleted) - { + if (b->deleted) { fseek (fp, b->offset, SEEK_SET); - for (l = b->length ; l ; l --) - { + for (l = b->length; l; l--) { ch = getc (fp); if (ch == EOF) - break; + break; if (ch == '\n') - dellines ++; + dellines++; } dellines -= 3; *length -= b->length - (84 + datelen); /* Count the number of digits exceeding the first one to write the size */ - for (l = 10 ; b->length >= l ; l *= 10) - (*length) ++; + for (l = 10; b->length >= l; l *= 10) + (*length)++; } - else - { - for (b = b->parts ; b ; b = b->next) + else { + for (b = b->parts; b; b = b->next) dellines += count_delete_lines (fp, b, length, datelen); } return dellines; @@ -539,28 +502,26 @@ static int count_delete_lines (FILE *fp, BODY *b, long *length, size_t datelen) */ int -_mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, - int flags, int chflags) +_mutt_copy_message (FILE * fpout, FILE * fpin, HEADER * hdr, BODY * body, + int flags, int chflags) { char prefix[SHORT_STRING]; STATE s; long new_offset = -1; - if (flags & M_CM_PREFIX) - { + if (flags & M_CM_PREFIX) { if (option (OPTTEXTFLOWED)) strfcpy (prefix, ">", sizeof (prefix)); else - _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, hdr, 0); + _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, + hdr, 0); } - if ((flags & M_CM_NOHEADER) == 0) - { + if ((flags & M_CM_NOHEADER) == 0) { if (flags & M_CM_PREFIX) chflags |= CH_PREFIX; - else if (hdr->attach_del && (chflags & CH_UPDATE_LEN)) - { + else if (hdr->attach_del && (chflags & CH_UPDATE_LEN)) { int new_lines; long new_length = body->length; char date[SHORT_STRING]; @@ -571,71 +532,68 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, /* Count the number of lines and bytes to be deleted */ fseek (fpin, body->offset, SEEK_SET); new_lines = hdr->lines - - count_delete_lines (fpin, body, &new_length, mutt_strlen (date)); + count_delete_lines (fpin, body, &new_length, mutt_strlen (date)); /* Copy the headers */ if (mutt_copy_header (fpin, hdr, fpout, - chflags | CH_NOLEN | CH_NONEWLINE, NULL)) - return -1; + chflags | CH_NOLEN | CH_NONEWLINE, NULL)) + return -1; fprintf (fpout, "Content-Length: %ld\n", new_length); if (new_lines <= 0) - new_lines = 0; + new_lines = 0; else - fprintf (fpout, "Lines: %d\n\n", new_lines); + fprintf (fpout, "Lines: %d\n\n", new_lines); if (ferror (fpout) || feof (fpout)) - return -1; + return -1; new_offset = ftell (fpout); /* Copy the body */ fseek (fpin, body->offset, SEEK_SET); if (copy_delete_attach (body, fpin, fpout, date)) - return -1; + return -1; #ifdef DEBUG { - long fail = ((ftell (fpout) - new_offset) - new_length); - - if (fail) - { - mutt_error ("The length calculation was wrong by %ld bytes", fail); - new_length += fail; - mutt_sleep (1); - } + long fail = ((ftell (fpout) - new_offset) - new_length); + + if (fail) { + mutt_error ("The length calculation was wrong by %ld bytes", fail); + new_length += fail; + mutt_sleep (1); + } } #endif - /* Update original message if we are sync'ing a mailfolder */ - if (flags & M_CM_UPDATE) - { - hdr->attach_del = 0; - hdr->lines = new_lines; - body->offset = new_offset; - - /* update the total size of the mailbox to reflect this deletion */ - Context->size -= body->length - new_length; - /* - * if the message is visible, update the visible size of the mailbox - * as well. - */ - if (Context->v2r[hdr->msgno] != -1) - Context->vsize -= body->length - new_length; - - body->length = new_length; - mutt_free_body (&body->parts); + /* Update original message if we are sync'ing a mailfolder */ + if (flags & M_CM_UPDATE) { + hdr->attach_del = 0; + hdr->lines = new_lines; + body->offset = new_offset; + + /* update the total size of the mailbox to reflect this deletion */ + Context->size -= body->length - new_length; + /* + * if the message is visible, update the visible size of the mailbox + * as well. + */ + if (Context->v2r[hdr->msgno] != -1) + Context->vsize -= body->length - new_length; + + body->length = new_length; + mutt_free_body (&body->parts); } return 0; } if (mutt_copy_header (fpin, hdr, fpout, chflags, - (chflags & CH_PREFIX) ? prefix : NULL) == -1) + (chflags & CH_PREFIX) ? prefix : NULL) == -1) return -1; new_offset = ftell (fpout); } - if (flags & M_CM_DECODE) - { + if (flags & M_CM_DECODE) { /* now make a text/plain version of the message */ memset (&s, 0, sizeof (STATE)); s.fpin = fpin; @@ -652,41 +610,37 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, s.flags |= M_CHARCONV; if (flags & M_CM_REPLYING) s.flags |= M_REPLYING; - + if (WithCrypto && flags & M_CM_VERIFY) s.flags |= M_VERIFY; mutt_body_handler (body, &s); } else if (WithCrypto - && (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT)) - { + && (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT)) { BODY *cur; FILE *fp; if ((WithCrypto & APPLICATION_PGP) && (flags & M_CM_DECODE_PGP) && (hdr->security & APPLICATION_PGP) && - hdr->content->type == TYPEMULTIPART) - { + hdr->content->type == TYPEMULTIPART) { if (crypt_pgp_decrypt_mime (fpin, &fp, hdr->content, &cur)) - return (-1); + return (-1); fputs ("Mime-Version: 1.0\n", fpout); } if ((WithCrypto & APPLICATION_SMIME) && (flags & M_CM_DECODE_SMIME) && (hdr->security & APPLICATION_SMIME) - && hdr->content->type == TYPEAPPLICATION) - { + && hdr->content->type == TYPEAPPLICATION) { if (crypt_smime_decrypt_mime (fpin, &fp, hdr->content, &cur)) - return (-1); + return (-1); } mutt_write_mime_header (cur, fpout); fputc ('\n', fpout); fseek (fp, cur->offset, 0); - if (mutt_copy_bytes (fp, fpout, cur->length) == -1) - { + if (mutt_copy_bytes (fp, fpout, cur->length) == -1) { fclose (fp); mutt_free_body (&cur); return (-1); @@ -694,32 +648,27 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, mutt_free_body (&cur); fclose (fp); } - else - { + else { fseek (fpin, body->offset, 0); - if (flags & M_CM_PREFIX) - { + if (flags & M_CM_PREFIX) { int c; size_t bytes = body->length; - - fputs(prefix, fpout); - - while((c = fgetc(fpin)) != EOF && bytes--) - { - fputc(c, fpout); - if(c == '\n') - { - fputs(prefix, fpout); - } - } + + fputs (prefix, fpout); + + while ((c = fgetc (fpin)) != EOF && bytes--) { + fputc (c, fpout); + if (c == '\n') { + fputs (prefix, fpout); + } + } } else if (mutt_copy_bytes (fpin, fpout, body->length) == -1) return -1; } - if ((flags & M_CM_UPDATE) && (flags & M_CM_NOHEADER) == 0 - && new_offset != -1) - { + if ((flags & M_CM_UPDATE) && (flags & M_CM_NOHEADER) == 0 + && new_offset != -1) { body->offset = new_offset; mutt_free_body (&body->parts); } @@ -728,17 +677,18 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, } int -mutt_copy_message (FILE *fpout, CONTEXT *src, HEADER *hdr, int flags, - int chflags) +mutt_copy_message (FILE * fpout, CONTEXT * src, HEADER * hdr, int flags, + int chflags) { MESSAGE *msg; int r; - + if ((msg = mx_open_message (src, hdr->msgno)) == NULL) return -1; - if ((r = _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0 - && (ferror (fpout) || feof (fpout))) - { + if ((r = + _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, + chflags)) == 0 && (ferror (fpout) + || feof (fpout))) { dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n")); r = -1; } @@ -758,13 +708,17 @@ mutt_copy_message (FILE *fpout, CONTEXT *src, HEADER *hdr, int flags, */ int -_mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr, - BODY *body, int flags, int chflags) +_mutt_append_message (CONTEXT * dest, FILE * fpin, CONTEXT * src, + HEADER * hdr, BODY * body, int flags, int chflags) { MESSAGE *msg; int r; - if ((msg = mx_open_new_message (dest, hdr, (src->magic == M_MBOX || src->magic == M_MMDF) ? 0 : M_ADD_FROM)) == NULL) + if ((msg = + mx_open_new_message (dest, hdr, + (src->magic == M_MBOX + || src->magic == M_MMDF) ? 0 : M_ADD_FROM)) == + NULL) return -1; if (dest->magic == M_MBOX || dest->magic == M_MMDF) chflags |= CH_FROM | CH_FORCE_FROM; @@ -778,15 +732,17 @@ _mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr, } int -mutt_append_message (CONTEXT *dest, CONTEXT *src, HEADER *hdr, int cmflags, - int chflags) +mutt_append_message (CONTEXT * dest, CONTEXT * src, HEADER * hdr, int cmflags, + int chflags) { MESSAGE *msg; int r; if ((msg = mx_open_message (src, hdr->msgno)) == NULL) return -1; - r = _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags, chflags); + r = + _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags, + chflags); mx_close_message (&msg); return r; } @@ -798,38 +754,35 @@ mutt_append_message (CONTEXT *dest, CONTEXT *src, HEADER *hdr, int cmflags, * * The function will return 0 on success and -1 on failure. */ -static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date) +static int copy_delete_attach (BODY * b, FILE * fpin, FILE * fpout, + char *date) { BODY *part; - for (part = b->parts ; part ; part = part->next) - { - if (part->deleted || part->parts) - { + for (part = b->parts; part; part = part->next) { + if (part->deleted || part->parts) { /* Copy till start of this part */ if (mutt_copy_bytes (fpin, fpout, part->hdr_offset - ftell (fpin))) - return -1; - - if (part->deleted) - { - fprintf (fpout, - "Content-Type: message/external-body; access-type=x-mutt-deleted;\n" - "\texpiration=%s; length=%ld\n" - "\n", date + 5, part->length); - if (ferror (fpout)) - return -1; - - /* Copy the original mime headers */ - if (mutt_copy_bytes (fpin, fpout, part->offset - ftell (fpin))) - return -1; - - /* Skip the deleted body */ - fseek (fpin, part->offset + part->length, SEEK_SET); + return -1; + + if (part->deleted) { + fprintf (fpout, + "Content-Type: message/external-body; access-type=x-mutt-deleted;\n" + "\texpiration=%s; length=%ld\n" + "\n", date + 5, part->length); + if (ferror (fpout)) + return -1; + + /* Copy the original mime headers */ + if (mutt_copy_bytes (fpin, fpout, part->offset - ftell (fpin))) + return -1; + + /* Skip the deleted body */ + fseek (fpin, part->offset + part->length, SEEK_SET); } - else - { - if (copy_delete_attach (part, fpin, fpout, date)) - return -1; + else { + if (copy_delete_attach (part, fpin, fpout, date)) + return -1; } } } @@ -850,57 +803,54 @@ static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date) * XXX - fix that. */ -static void format_address_header (char **h, ADDRESS *a) +static void format_address_header (char **h, ADDRESS * a) { char buf[HUGE_STRING]; char cbuf[STRING]; char c2buf[STRING]; - + int l, linelen, buflen, count; + linelen = mutt_strlen (*h); - buflen = linelen + 3; - - + buflen = linelen + 3; + + safe_realloc (h, buflen); - for (count = 0; a; a = a->next, count++) - { + for (count = 0; a; a = a->next, count++) { ADDRESS *tmp = a->next; + a->next = NULL; *buf = *cbuf = *c2buf = '\0'; rfc822_write_address (buf, sizeof (buf), a, 0); a->next = tmp; - + l = mutt_strlen (buf); - if (count && linelen + l > 74) - { - strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */ + if (count && linelen + l > 74) { + strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */ linelen = l + 8; } - else - { - if (a->mailbox) - { - strcpy (cbuf, " "); /* __STRCPY_CHECKED__ */ - linelen++; + else { + if (a->mailbox) { + strcpy (cbuf, " "); /* __STRCPY_CHECKED__ */ + linelen++; } linelen += l; } - if (!a->group && a->next && a->next->mailbox) - { + if (!a->group && a->next && a->next->mailbox) { linelen++; buflen++; - strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */ + strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */ } - + buflen += l + mutt_strlen (cbuf) + mutt_strlen (c2buf); safe_realloc (h, buflen); - strcat (*h, cbuf); /* __STRCAT_CHECKED__ */ - strcat (*h, buf); /* __STRCAT_CHECKED__ */ - strcat (*h, c2buf); /* __STRCAT_CHECKED__ */ + strcat (*h, cbuf); /* __STRCAT_CHECKED__ */ + strcat (*h, buf); /* __STRCAT_CHECKED__ */ + strcat (*h, c2buf); /* __STRCAT_CHECKED__ */ } - + /* Space for this was allocated in the beginning of this function. */ - strcat (*h, "\n"); /* __STRCAT_CHECKED__ */ + strcat (*h, "\n"); /* __STRCAT_CHECKED__ */ } static int address_header_decode (char **h) @@ -910,82 +860,80 @@ static int address_header_decode (char **h) ADDRESS *a = NULL; - switch (tolower ((unsigned char) *s)) - { - case 'r': + switch (tolower ((unsigned char) *s)) { + case 'r': { - if (ascii_strncasecmp (s, "return-path:", 12) == 0) - { - l = 12; - break; + if (ascii_strncasecmp (s, "return-path:", 12) == 0) { + l = 12; + break; } - else if (ascii_strncasecmp (s, "reply-to:", 9) == 0) - { - l = 9; - break; + else if (ascii_strncasecmp (s, "reply-to:", 9) == 0) { + l = 9; + break; } return 0; } - case 'f': + case 'f': { - if (ascii_strncasecmp (s, "from:", 5)) - return 0; + if (ascii_strncasecmp (s, "from:", 5)) + return 0; l = 5; break; } - case 'c': + case 'c': { if (ascii_strncasecmp (s, "cc:", 3)) - return 0; + return 0; l = 3; break; - + } - case 'b': + case 'b': { if (ascii_strncasecmp (s, "bcc:", 4)) - return 0; + return 0; l = 4; break; } - case 's': + case 's': { if (ascii_strncasecmp (s, "sender:", 7)) - return 0; + return 0; l = 7; break; } - case 't': + case 't': { if (ascii_strncasecmp (s, "to:", 3)) - return 0; + return 0; l = 3; break; } - case 'm': + case 'm': { if (ascii_strncasecmp (s, "mail-followup-to:", 17)) - return 0; + return 0; l = 17; break; } - default: return 0; + default: + return 0; } if ((a = rfc822_parse_adrlist (a, s + l)) == NULL) return 0; - + mutt_addrlist_to_local (a); rfc2047_decode_adrlist (a); - + *h = safe_calloc (1, l + 2); - + strfcpy (*h, s, l + 1); - + format_address_header (h, a); rfc822_free_address (&a); - + FREE (&s); return 1; } diff --git a/copy.h b/copy.h index f0a9b86..8963117 100644 --- a/copy.h +++ b/copy.h @@ -14,26 +14,26 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* flags to _mutt_copy_message */ -#define M_CM_NOHEADER 1 /* don't copy the message header */ -#define M_CM_PREFIX (1<<1) /* quote the message */ -#define M_CM_DECODE (1<<2) /* decode the message body into text/plain */ -#define M_CM_DISPLAY (1<<3) /* output is displayed to the user */ +#define M_CM_NOHEADER 1 /* don't copy the message header */ +#define M_CM_PREFIX (1<<1) /* quote the message */ +#define M_CM_DECODE (1<<2) /* decode the message body into text/plain */ +#define M_CM_DISPLAY (1<<3) /* output is displayed to the user */ #define M_CM_UPDATE (1<<4) /* update structs on sync */ #define M_CM_WEED (1<<5) /* weed message/rfc822 attachment headers */ #define M_CM_CHARCONV (1<<6) /* perform character set conversions */ -#define M_CM_PRINTING (1<<7) /* printing the message - display light */ -#define M_CM_REPLYING (1<<8) /* replying the message */ +#define M_CM_PRINTING (1<<7) /* printing the message - display light */ +#define M_CM_REPLYING (1<<8) /* replying the message */ -#define M_CM_DECODE_PGP (1<<9) /* used for decoding PGP messages */ -#define M_CM_DECODE_SMIME (1<<10) /* used for decoding S/MIME messages */ +#define M_CM_DECODE_PGP (1<<9) /* used for decoding PGP messages */ +#define M_CM_DECODE_SMIME (1<<10) /* used for decoding S/MIME messages */ #define M_CM_DECODE_CRYPT (M_CM_DECODE_PGP | M_CM_DECODE_SMIME) -#define M_CM_VERIFY (1<<11) /* do signature verification */ +#define M_CM_VERIFY (1<<11) /* do signature verification */ @@ -41,29 +41,18 @@ int mutt_copy_hdr (FILE *, FILE *, long, long, int, const char *); int mutt_copy_header (FILE *, HEADER *, FILE *, int, const char *); -int _mutt_copy_message (FILE *fpout, - FILE *fpin, - HEADER *hdr, - BODY *body, - int flags, - int chflags); +int _mutt_copy_message (FILE * fpout, + FILE * fpin, + HEADER * hdr, BODY * body, int flags, int chflags); -int mutt_copy_message (FILE *fpout, - CONTEXT *src, - HEADER *hdr, - int flags, - int chflags); +int mutt_copy_message (FILE * fpout, + CONTEXT * src, HEADER * hdr, int flags, int chflags); -int _mutt_append_message (CONTEXT *dest, - FILE *fpin, - CONTEXT *src, - HEADER *hdr, - BODY *body, - int flags, - int chflags); +int _mutt_append_message (CONTEXT * dest, + FILE * fpin, + CONTEXT * src, + HEADER * hdr, BODY * body, int flags, int chflags); -int mutt_append_message (CONTEXT *dest, - CONTEXT *src, - HEADER *hdr, - int cmflags, - int chflags); +int mutt_append_message (CONTEXT * dest, + CONTEXT * src, + HEADER * hdr, int cmflags, int chflags); diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 8843195..4b201e2 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -82,32 +82,28 @@ * Type definitions. */ -struct crypt_cache -{ +struct crypt_cache { char *what; char *dflt; struct crypt_cache *next; }; -struct dn_array_s -{ +struct dn_array_s { char *key; char *value; }; /* We work based on user IDs, getting from a user ID to the key is check and does not need any memory (gpgme uses reference counting). */ -typedef struct crypt_keyinfo -{ +typedef struct crypt_keyinfo { struct crypt_keyinfo *next; gpgme_key_t kobj; - int idx; /* and the user ID at this index */ - const char *uid; /* and for convenience point to this user ID */ - unsigned int flags; /* global and per uid flags (for convenience)*/ + int idx; /* and the user ID at this index */ + const char *uid; /* and for convenience point to this user ID */ + unsigned int flags; /* global and per uid flags (for convenience) */ } crypt_key_t; -typedef struct crypt_entry -{ +typedef struct crypt_entry { size_t num; crypt_key_t *key; } crypt_entry_t; @@ -121,23 +117,21 @@ static gpgme_key_t signature_key = NULL; */ /* return true when S pints to a didgit or letter. */ -static int -digit_or_letter (const unsigned char *s) +static int digit_or_letter (const unsigned char *s) { - return ( (*s >= '0' && *s < '9') - || (*s >= 'A' && *s <= 'Z') - || (*s >= 'a' && *s <= 'z')); + return ((*s >= '0' && *s < '9') + || (*s >= 'A' && *s <= 'Z') + || (*s >= 'a' && *s <= 'z')); } /* Print the utf-8 encoded string BUF of length LEN bytes to stream FP. Convert the character set. */ -static void -print_utf8 (FILE *fp, const char *buf, size_t len) +static void print_utf8 (FILE * fp, const char *buf, size_t len) { char *tstr; - tstr = safe_malloc (len+1); + tstr = safe_malloc (len + 1); memcpy (tstr, buf, len); tstr[len] = 0; mutt_convert_string (&tstr, "utf-8", Charset, M_ICONV_HOOK_FROM); @@ -152,23 +146,22 @@ print_utf8 (FILE *fp, const char *buf, size_t len) /* Return the keyID for the key K. Note that this string is valid as long as K is valid */ -static const char *crypt_keyid (crypt_key_t *k) +static const char *crypt_keyid (crypt_key_t * k) { const char *s = "????????"; - if (k->kobj && k->kobj->subkeys) - { - s = k->kobj->subkeys->keyid; - if ((! option (OPTPGPLONGIDS)) && (strlen (s) == 16)) - /* Return only the short keyID. */ - s += 8; - } + if (k->kobj && k->kobj->subkeys) { + s = k->kobj->subkeys->keyid; + if ((!option (OPTPGPLONGIDS)) && (strlen (s) == 16)) + /* Return only the short keyID. */ + s += 8; + } return s; } /* Return the hexstring fingerprint from the key K. */ -static const char *crypt_fpr (crypt_key_t *k) +static const char *crypt_fpr (crypt_key_t * k) { const char *s = ""; @@ -213,12 +206,12 @@ static char crypt_flags (int flags) return 'd'; else if (flags & KEYFLAG_CRITICAL) return 'c'; - else + else return ' '; } /* Return a copy of KEY. */ -static crypt_key_t *crypt_copy_key (crypt_key_t *key) +static crypt_key_t *crypt_copy_key (crypt_key_t * key) { crypt_key_t *k; @@ -234,18 +227,18 @@ static crypt_key_t *crypt_copy_key (crypt_key_t *key) /* Release all the keys at the address of KEYLIST and set the address to NULL. */ -static void crypt_free_key (crypt_key_t **keylist) +static void crypt_free_key (crypt_key_t ** keylist) { - while (*keylist) - { - crypt_key_t *k = (*keylist)->next; - FREE (&k); - *keylist = k; - } + while (*keylist) { + crypt_key_t *k = (*keylist)->next; + + FREE (&k); + *keylist = k; + } } /* Return trute when key K is valid. */ -static int crypt_key_is_valid (crypt_key_t *k) +static int crypt_key_is_valid (crypt_key_t * k) { if (k->flags & KEYFLAG_CANTUSE) return 0; @@ -253,7 +246,7 @@ static int crypt_key_is_valid (crypt_key_t *k) } /* Return true whe validity of KEY is sufficient. */ -static int crypt_id_is_strong (crypt_key_t *key) +static int crypt_id_is_strong (crypt_key_t * key) { gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN; gpgme_user_id_t uid = NULL; @@ -264,56 +257,54 @@ static int crypt_id_is_strong (crypt_key_t *key) return 1; for (i = 0, uid = key->kobj->uids; (i < key->idx) && uid; - i++, uid = uid->next) - ; + i++, uid = uid->next); if (uid) val = uid->validity; - switch (val) - { - case GPGME_VALIDITY_UNKNOWN: - case GPGME_VALIDITY_UNDEFINED: - case GPGME_VALIDITY_NEVER: - case GPGME_VALIDITY_MARGINAL: - is_strong = 0; - break; + switch (val) { + case GPGME_VALIDITY_UNKNOWN: + case GPGME_VALIDITY_UNDEFINED: + case GPGME_VALIDITY_NEVER: + case GPGME_VALIDITY_MARGINAL: + is_strong = 0; + break; - case GPGME_VALIDITY_FULL: - case GPGME_VALIDITY_ULTIMATE: - is_strong = 1; - break; - } + case GPGME_VALIDITY_FULL: + case GPGME_VALIDITY_ULTIMATE: + is_strong = 1; + break; + } return is_strong; } /* Return true when the KEY is valid, i.e. not marked as unusable. */ -static int crypt_id_is_valid (crypt_key_t *key) +static int crypt_id_is_valid (crypt_key_t * key) { - return ! (key->flags & KEYFLAG_CANTUSE); + return !(key->flags & KEYFLAG_CANTUSE); } /* Return a bit vector describing how well the addresses ADDR and U_ADDR match and whether KEY is valid. */ -static int crypt_id_matches_addr (ADDRESS *addr, ADDRESS *u_addr, - crypt_key_t *key) +static int crypt_id_matches_addr (ADDRESS * addr, ADDRESS * u_addr, + crypt_key_t * key) { int rv = 0; - + if (crypt_id_is_valid (key)) rv |= CRYPT_KV_VALID; if (crypt_id_is_strong (key)) rv |= CRYPT_KV_STRONGID; - + if (addr->mailbox && u_addr->mailbox && mutt_strcasecmp (addr->mailbox, u_addr->mailbox) == 0) rv |= CRYPT_KV_ADDR; - + if (addr->personal && u_addr->personal && mutt_strcasecmp (addr->personal, u_addr->personal) == 0) rv |= CRYPT_KV_STRING; - + return rv; } @@ -330,24 +321,20 @@ static gpgme_ctx_t create_gpgme_context (int for_smime) gpgme_ctx_t ctx; err = gpgme_new (&ctx); - if (err) - { - mutt_error ("error creating gpgme context: %s\n", gpgme_strerror (err)); + if (err) { + mutt_error ("error creating gpgme context: %s\n", gpgme_strerror (err)); + sleep (2); + mutt_exit (1); + } + + if (for_smime) { + err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + if (err) { + mutt_error ("error enabling CMS protocol: %s\n", gpgme_strerror (err)); sleep (2); mutt_exit (1); } - - if (for_smime) - { - err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); - if (err) - { - mutt_error ("error enabling CMS protocol: %s\n", - gpgme_strerror (err)); - sleep (2); - mutt_exit (1); - } - } + } return ctx; } @@ -360,77 +347,69 @@ static gpgme_data_t create_gpgme_data (void) gpgme_data_t data; err = gpgme_data_new (&data); - if (err) - { - mutt_error ("error creating gpgme data object: %s\n", - gpgme_strerror (err)); - sleep (2); - mutt_exit (1); - } + if (err) { + mutt_error ("error creating gpgme data object: %s\n", + gpgme_strerror (err)); + sleep (2); + mutt_exit (1); + } return data; } /* Create a new GPGME Data object from the mail body A. With CONVERT passed as true, the lines are converted to CR,LF if required. Return NULL on error or the gpgme_data_t object on success. */ -static gpgme_data_t body_to_data_object (BODY *a, int convert) +static gpgme_data_t body_to_data_object (BODY * a, int convert) { char tempfile[_POSIX_PATH_MAX]; FILE *fptmp; int err = 0; gpgme_data_t data; - + mutt_mktemp (tempfile); fptmp = safe_fopen (tempfile, "w+"); - if (!fptmp) - { - mutt_perror (tempfile); - return NULL; - } + if (!fptmp) { + mutt_perror (tempfile); + return NULL; + } mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - if (convert) - { - int c, hadcr = 0; - unsigned char buf[1]; - - data = create_gpgme_data (); - rewind (fptmp); - while ((c = fgetc (fptmp)) != EOF) - { - if (c == '\r') - hadcr = 1; - else - { - if (c == '\n' && !hadcr) - { - buf[0] = '\r'; - gpgme_data_write (data, buf, 1); - } - - hadcr = 0; - } - /* FIXME: This is quite suboptimal */ - buf[0] = c; + if (convert) { + int c, hadcr = 0; + unsigned char buf[1]; + + data = create_gpgme_data (); + rewind (fptmp); + while ((c = fgetc (fptmp)) != EOF) { + if (c == '\r') + hadcr = 1; + else { + if (c == '\n' && !hadcr) { + buf[0] = '\r'; gpgme_data_write (data, buf, 1); } - fclose(fptmp); - gpgme_data_seek (data, 0, SEEK_SET); - } - else - { - fclose(fptmp); - err = gpgme_data_new_from_file (&data, tempfile, 1); + + hadcr = 0; + } + /* FIXME: This is quite suboptimal */ + buf[0] = c; + gpgme_data_write (data, buf, 1); } + fclose (fptmp); + gpgme_data_seek (data, 0, SEEK_SET); + } + else { + fclose (fptmp); + err = gpgme_data_new_from_file (&data, tempfile, 1); + } unlink (tempfile); - if (err) - { - mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); - return NULL; - } + if (err) { + mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); + return NULL; + } return data; } @@ -438,23 +417,22 @@ static gpgme_data_t body_to_data_object (BODY *a, int convert) /* Create a GPGME data object from the stream FP but limit the object to LENGTH bytes starting at OFFSET bytes from the beginning of the file. */ -static gpgme_data_t file_to_data_object (FILE *fp, long offset, long length) +static gpgme_data_t file_to_data_object (FILE * fp, long offset, long length) { int err = 0; gpgme_data_t data; - + err = gpgme_data_new_from_filepart (&data, NULL, fp, offset, length); - if (err) - { - mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); - return NULL; - } + if (err) { + mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); + return NULL; + } return data; } /* Write a GPGME data object to the stream FP. */ -static int data_object_to_stream (gpgme_data_t data, FILE *fp) +static int data_object_to_stream (gpgme_data_t data, FILE * fp) { int err; char buf[4096], *p; @@ -462,40 +440,35 @@ static int data_object_to_stream (gpgme_data_t data, FILE *fp) err = ((gpgme_data_seek (data, 0, SEEK_SET) == -1) ? gpgme_error_from_errno (errno) : 0); - if (err) - { - mutt_error ("error rewinding data object: %s\n", gpgme_strerror (err)); - return -1; - } - - while ((nread = gpgme_data_read (data, buf, sizeof (buf)))) - { - /* fixme: we are not really converting CRLF to LF but just - skipping CR. Doing it correctly needs a more complex logic */ - for (p=buf; nread; p++, nread--) - { - if (*p != '\r') - putc (*p, fp); - } + if (err) { + mutt_error ("error rewinding data object: %s\n", gpgme_strerror (err)); + return -1; + } - if (ferror (fp)) - { - mutt_perror ("[tempfile]"); - return -1; - } + while ((nread = gpgme_data_read (data, buf, sizeof (buf)))) { + /* fixme: we are not really converting CRLF to LF but just + skipping CR. Doing it correctly needs a more complex logic */ + for (p = buf; nread; p++, nread--) { + if (*p != '\r') + putc (*p, fp); } - if (nread == -1) - { - mutt_error ("error reading data object: %s\n", strerror (errno)); + + if (ferror (fp)) { + mutt_perror ("[tempfile]"); return -1; } + } + if (nread == -1) { + mutt_error ("error reading data object: %s\n", strerror (errno)); + return -1; + } return 0; } /* Copy a data object to a newly created temporay file and return that filename. Caller must free. With RET_FP not NULL, don't close the stream but return it there. */ -static char *data_object_to_tempfile (gpgme_data_t data, FILE **ret_fp) +static char *data_object_to_tempfile (gpgme_data_t data, FILE ** ret_fp) { int err; char tempfile[_POSIX_PATH_MAX]; @@ -504,40 +477,35 @@ static char *data_object_to_tempfile (gpgme_data_t data, FILE **ret_fp) mutt_mktemp (tempfile); fp = safe_fopen (tempfile, "w+"); - if (!fp) - { - mutt_perror (tempfile); - return NULL; - } + if (!fp) { + mutt_perror (tempfile); + return NULL; + } err = ((gpgme_data_seek (data, 0, SEEK_SET) == -1) ? gpgme_error_from_errno (errno) : 0); - if (!err) - { - char buf[4096]; - - while ((nread = gpgme_data_read (data, buf, sizeof (buf)))) - { - if (fwrite (buf, nread, 1, fp) != 1) - { - mutt_perror (tempfile); - fclose (fp); - unlink (tempfile); - return NULL; - } - } + if (!err) { + char buf[4096]; + + while ((nread = gpgme_data_read (data, buf, sizeof (buf)))) { + if (fwrite (buf, nread, 1, fp) != 1) { + mutt_perror (tempfile); + fclose (fp); + unlink (tempfile); + return NULL; + } } + } if (ret_fp) rewind (fp); else fclose (fp); - if (nread == -1) - { - mutt_error ("error reading data object: %s\n", gpgme_strerror (err)); - unlink (tempfile); - fclose (fp); - return NULL; - } + if (nread == -1) { + mutt_error ("error reading data object: %s\n", gpgme_strerror (err)); + unlink (tempfile); + fclose (fp); + return NULL; + } if (ret_fp) *ret_fp = fp; return safe_strdup (tempfile); @@ -559,54 +527,49 @@ static gpgme_key_t *create_recipient_set (const char *keylist, gpgme_ctx_t context = NULL; err = gpgme_new (&context); - if (! err) + if (!err) err = gpgme_set_protocol (context, protocol); - if (! err) - { - s = keylist; - do { - while (*s == ' ') - s++; - for (i=0; *s && *s != ' ' && i < sizeof(buf)-1;) - buf[i++] = *s++; - buf[i] = 0; - if (*buf) - { - if (i>1 && buf[i-1] == '!') - { - /* The user selected to override the valididy of that - key. */ - buf[i-1] = 0; - - err = gpgme_get_key (context, buf, &key, 0); - if (! err) - key->uids->validity = GPGME_VALIDITY_FULL; - buf[i-1] = '!'; - } - else - err = gpgme_get_key (context, buf, &key, 0); - - if (! err) - { - safe_realloc (&rset, sizeof (*rset) * (rset_n + 1)); - rset[rset_n++] = key; - } - else - { - mutt_error ("error adding recipient `%s': %s\n", - buf, gpgme_strerror (err)); - FREE (&rset); - return NULL; - } - } - } while (*s); - } + if (!err) { + s = keylist; + do { + while (*s == ' ') + s++; + for (i = 0; *s && *s != ' ' && i < sizeof (buf) - 1;) + buf[i++] = *s++; + buf[i] = 0; + if (*buf) { + if (i > 1 && buf[i - 1] == '!') { + /* The user selected to override the valididy of that + key. */ + buf[i - 1] = 0; + + err = gpgme_get_key (context, buf, &key, 0); + if (!err) + key->uids->validity = GPGME_VALIDITY_FULL; + buf[i - 1] = '!'; + } + else + err = gpgme_get_key (context, buf, &key, 0); + + if (!err) { + safe_realloc (&rset, sizeof (*rset) * (rset_n + 1)); + rset[rset_n++] = key; + } + else { + mutt_error ("error adding recipient `%s': %s\n", + buf, gpgme_strerror (err)); + FREE (&rset); + return NULL; + } + } + } while (*s); + } /* NULL terminate. */ safe_realloc (&rset, sizeof (*rset) * (rset_n + 1)); rset[rset_n++] = NULL; - + if (context) gpgme_release (context); @@ -617,7 +580,7 @@ static gpgme_key_t *create_recipient_set (const char *keylist, /* Make sure that the correct signer is set. Returns 0 on success. */ static int set_signer (gpgme_ctx_t ctx, int for_smime) { - char *signid = for_smime ? SmimeDefaultKey: PgpSignAs; + char *signid = for_smime ? SmimeDefaultKey : PgpSignAs; gpgme_error_t err; gpgme_ctx_t listctx; gpgme_key_t key, key2; @@ -629,35 +592,31 @@ static int set_signer (gpgme_ctx_t ctx, int for_smime) err = gpgme_op_keylist_start (listctx, signid, 1); if (!err) err = gpgme_op_keylist_next (listctx, &key); - if (err) - { - gpgme_release (listctx); - mutt_error (_("secret key `%s' not found: %s\n"), - signid, gpgme_strerror (err)); - return -1; - } + if (err) { + gpgme_release (listctx); + mutt_error (_("secret key `%s' not found: %s\n"), + signid, gpgme_strerror (err)); + return -1; + } err = gpgme_op_keylist_next (listctx, &key2); - if (!err) - { - gpgme_key_release (key); - gpgme_key_release (key2); - gpgme_release (listctx); - mutt_error (_("ambiguous specfication of secret key `%s'\n"), - signid); - return -1; - } + if (!err) { + gpgme_key_release (key); + gpgme_key_release (key2); + gpgme_release (listctx); + mutt_error (_("ambiguous specfication of secret key `%s'\n"), signid); + return -1; + } gpgme_op_keylist_end (listctx); gpgme_release (listctx); gpgme_signers_clear (ctx); err = gpgme_signers_add (ctx, key); gpgme_key_release (key); - if (err) - { - mutt_error (_("error setting secret key `%s': %s\n"), - signid, gpgme_strerror (err)); - return -1; - } + if (err) { + mutt_error (_("error setting secret key `%s': %s\n"), + signid, gpgme_strerror (err)); + return -1; + } return 0; } @@ -667,7 +626,7 @@ static int set_signer (gpgme_ctx_t ctx, int for_smime) enciphered text. With USE_SMIME set to true, the smime backend is used. With COMBINED_SIGNED a PGP message is signed and encrypted. Returns NULL in case of error */ -static char *encrypt_gpgme_object (gpgme_data_t plaintext, gpgme_key_t *rset, +static char *encrypt_gpgme_object (gpgme_data_t plaintext, gpgme_key_t * rset, int use_smime, int combined_signed) { int err; @@ -676,33 +635,30 @@ static char *encrypt_gpgme_object (gpgme_data_t plaintext, gpgme_key_t *rset, char *outfile; ctx = create_gpgme_context (use_smime); - if (!use_smime) - gpgme_set_armor (ctx, 1); + if (!use_smime) + gpgme_set_armor (ctx, 1); ciphertext = create_gpgme_data (); - if (combined_signed) - { - if (set_signer (ctx, use_smime)) - { - gpgme_data_release (ciphertext); - gpgme_release (ctx); - return NULL; - } - err = gpgme_op_encrypt_sign (ctx, rset, GPGME_ENCRYPT_ALWAYS_TRUST, - plaintext, ciphertext); + if (combined_signed) { + if (set_signer (ctx, use_smime)) { + gpgme_data_release (ciphertext); + gpgme_release (ctx); + return NULL; } + err = gpgme_op_encrypt_sign (ctx, rset, GPGME_ENCRYPT_ALWAYS_TRUST, + plaintext, ciphertext); + } else err = gpgme_op_encrypt (ctx, rset, GPGME_ENCRYPT_ALWAYS_TRUST, plaintext, ciphertext); mutt_need_hard_redraw (); - if (err) - { - mutt_error ("error encrypting data: %s\n", gpgme_strerror (err)); - gpgme_data_release (ciphertext); - gpgme_release (ctx); - return NULL; - } + if (err) { + mutt_error ("error encrypting data: %s\n", gpgme_strerror (err)); + gpgme_data_release (ciphertext); + gpgme_release (ctx); + return NULL; + } gpgme_release (ctx); @@ -727,20 +683,18 @@ static int get_micalg (gpgme_ctx_t ctx, char *buf, size_t buflen) *buf = 0; result = gpgme_op_sign_result (ctx); - if (result) - { - algorithm_name = gpgme_hash_algo_name (result->signatures->hash_algo); - if (algorithm_name) - { - strncpy (buf, algorithm_name, buflen - 1); - buf[buflen - 1] = 0; - } + if (result) { + algorithm_name = gpgme_hash_algo_name (result->signatures->hash_algo); + if (algorithm_name) { + strncpy (buf, algorithm_name, buflen - 1); + buf[buflen - 1] = 0; } + } - return *buf? 0:-1; + return *buf ? 0 : -1; } -static void print_time(time_t t, STATE *s) +static void print_time (time_t t, STATE * s) { char p[STRING]; @@ -761,7 +715,7 @@ static void print_time(time_t t, STATE *s) /* Sign the MESSAGE in body A either using OpenPGP or S/MIME when USE_SMIME is passed as true. Returns the new body or NULL on error. */ -static BODY *sign_message (BODY *a, int use_smime) +static BODY *sign_message (BODY * a, int use_smime) { BODY *t; char *sigfile; @@ -770,42 +724,39 @@ static BODY *sign_message (BODY *a, int use_smime) gpgme_ctx_t ctx; gpgme_data_t message, signature; - convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */ + convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */ message = body_to_data_object (a, 1); if (!message) - return NULL; + return NULL; signature = create_gpgme_data (); ctx = create_gpgme_context (use_smime); if (!use_smime) gpgme_set_armor (ctx, 1); - if (set_signer (ctx, use_smime)) - { - gpgme_data_release (signature); - gpgme_release (ctx); - return NULL; - } + if (set_signer (ctx, use_smime)) { + gpgme_data_release (signature); + gpgme_release (ctx); + return NULL; + } - err = gpgme_op_sign (ctx, message, signature, GPGME_SIG_MODE_DETACH ); + err = gpgme_op_sign (ctx, message, signature, GPGME_SIG_MODE_DETACH); mutt_need_hard_redraw (); gpgme_data_release (message); - if (err) - { - gpgme_data_release (signature); - gpgme_release (ctx); - mutt_error ("error signing data: %s\n", gpgme_strerror (err)); - return NULL; - } + if (err) { + gpgme_data_release (signature); + gpgme_release (ctx); + mutt_error ("error signing data: %s\n", gpgme_strerror (err)); + return NULL; + } sigfile = data_object_to_tempfile (signature, NULL); gpgme_data_release (signature); - if (!sigfile) - { - gpgme_release (ctx); - return NULL; - } + if (!sigfile) { + gpgme_release (ctx); + return NULL; + } t = mutt_new_body (); t->type = TYPEMULTIPART; @@ -816,9 +767,8 @@ static BODY *sign_message (BODY *a, int use_smime) mutt_generate_boundary (&t->parameter); mutt_set_parameter ("protocol", - use_smime? "application/pkcs7-signature" - : "application/pgp-signature", - &t->parameter); + use_smime ? "application/pkcs7-signature" + : "application/pgp-signature", &t->parameter); /* Get the micalg from gpgme. Old gpgme versions don't support this for S/MIME so we assume sha-1 in this case. */ if (!get_micalg (ctx, buf, sizeof buf)) @@ -833,35 +783,33 @@ static BODY *sign_message (BODY *a, int use_smime) t->parts->next = mutt_new_body (); t = t->parts->next; t->type = TYPEAPPLICATION; - if (use_smime) - { - t->subtype = safe_strdup ("pkcs7-signature"); - mutt_set_parameter ("name", "smime.p7s", &t->parameter); - t->encoding = ENCBASE64; - t->use_disp = 1; - t->disposition = DISPATTACH; - t->d_filename = safe_strdup ("smime.p7s"); - } - else - { - t->subtype = safe_strdup ("pgp-signature"); - t->use_disp = 0; - t->disposition = DISPINLINE; - t->encoding = ENC7BIT; - } + if (use_smime) { + t->subtype = safe_strdup ("pkcs7-signature"); + mutt_set_parameter ("name", "smime.p7s", &t->parameter); + t->encoding = ENCBASE64; + t->use_disp = 1; + t->disposition = DISPATTACH; + t->d_filename = safe_strdup ("smime.p7s"); + } + else { + t->subtype = safe_strdup ("pgp-signature"); + t->use_disp = 0; + t->disposition = DISPINLINE; + t->encoding = ENC7BIT; + } t->filename = sigfile; - t->unlink = 1; /* ok to remove this file after sending. */ + t->unlink = 1; /* ok to remove this file after sending. */ return a; } -BODY *pgp_gpgme_sign_message (BODY *a) +BODY *pgp_gpgme_sign_message (BODY * a) { return sign_message (a, 0); } -BODY *smime_gpgme_sign_message (BODY *a) +BODY *smime_gpgme_sign_message (BODY * a) { return sign_message (a, 1); } @@ -872,31 +820,30 @@ BODY *smime_gpgme_sign_message (BODY *a) /* Encrypt the mail body A to all keys given as space separated keyids or fingerprints in KEYLIST and return the encrypted body. */ -BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign) +BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign) { char *outfile = NULL; BODY *t; gpgme_key_t *rset = NULL; gpgme_data_t plaintext; - + rset = create_recipient_set (keylist, GPGME_PROTOCOL_OpenPGP); if (!rset) return NULL; - + if (sign) convert_to_7bit (a); plaintext = body_to_data_object (a, 0); - if (!plaintext) - { - FREE (&rset); - return NULL; - } - + if (!plaintext) { + FREE (&rset); + return NULL; + } + outfile = encrypt_gpgme_object (plaintext, rset, 0, sign); gpgme_data_release (plaintext); FREE (&rset); if (!outfile) - return NULL; + return NULL; t = mutt_new_body (); t->type = TYPEMULTIPART; @@ -905,9 +852,9 @@ BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign) t->use_disp = 0; t->disposition = DISPINLINE; - mutt_generate_boundary(&t->parameter); - mutt_set_parameter("protocol", "application/pgp-encrypted", &t->parameter); - + mutt_generate_boundary (&t->parameter); + mutt_set_parameter ("protocol", "application/pgp-encrypted", &t->parameter); + t->parts = mutt_new_body (); t->parts->type = TYPEAPPLICATION; t->parts->subtype = safe_strdup ("pgp-encrypted"); @@ -920,7 +867,7 @@ BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign) t->parts->next->filename = outfile; t->parts->next->use_disp = 1; t->parts->next->disposition = DISPINLINE; - t->parts->next->unlink = 1; /* delete after sending the message */ + t->parts->next->unlink = 1; /* delete after sending the message */ t->parts->next->d_filename = safe_strdup ("msg.asc"); /* non pgp/mime can save */ @@ -933,7 +880,7 @@ BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign) /* Encrypt the mail body A to all keys given as space separated fingerprints in KEYLIST and return the S/MIME encrypted body. */ -BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist) +BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist) { char *outfile = NULL; BODY *t; @@ -945,32 +892,31 @@ BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist) return NULL; plaintext = body_to_data_object (a, 0); - if (!plaintext) - { - FREE (&rset); - return NULL; - } + if (!plaintext) { + FREE (&rset); + return NULL; + } outfile = encrypt_gpgme_object (plaintext, rset, 1, 0); gpgme_data_release (plaintext); FREE (&rset); - if (!outfile) - return NULL; + if (!outfile) + return NULL; t = mutt_new_body (); t->type = TYPEAPPLICATION; t->subtype = safe_strdup ("pkcs7-mime"); mutt_set_parameter ("name", "smime.p7m", &t->parameter); mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter); - t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */ + t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */ t->use_disp = 1; t->disposition = DISPATTACH; t->d_filename = safe_strdup ("smime.p7m"); t->filename = outfile; - t->unlink = 1; /*delete after sending the message */ - t->parts=0; - t->next=0; - + t->unlink = 1; /*delete after sending the message */ + t->parts = 0; + t->next = 0; + return t; } @@ -983,108 +929,97 @@ BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist) Return 1 if there is is a severe warning. */ static int show_sig_summary (unsigned long sum, - gpgme_ctx_t ctx, gpgme_key_t key, int idx, - STATE *s) + gpgme_ctx_t ctx, gpgme_key_t key, int idx, + STATE * s) { int severe = 0; - if ((sum & GPGME_SIGSUM_KEY_REVOKED)) - { - state_attach_puts (_("Warning: One of the keys has been revoked\n"),s); - severe = 1; - } + if ((sum & GPGME_SIGSUM_KEY_REVOKED)) { + state_attach_puts (_("Warning: One of the keys has been revoked\n"), s); + severe = 1; + } - if ((sum & GPGME_SIGSUM_KEY_EXPIRED)) - { - time_t at = key->subkeys->expires ? key->subkeys->expires : 0; - if (at) - { - state_attach_puts (_("Warning: The key used to create the " - "signature expired at: "), s); - print_time (at , s); - state_attach_puts ("\n", s); - } - else - state_attach_puts (_("Warning: At least one certification key " - "has expired\n"), s); - } + if ((sum & GPGME_SIGSUM_KEY_EXPIRED)) { + time_t at = key->subkeys->expires ? key->subkeys->expires : 0; - if ((sum & GPGME_SIGSUM_SIG_EXPIRED)) - { - gpgme_verify_result_t result; - gpgme_signature_t sig; - unsigned int i; - - result = gpgme_op_verify_result (ctx); - - for (sig = result->signatures, i = 0; sig && (i < idx); - sig = sig->next, i++) - ; - - state_attach_puts (_("Warning: The signature expired at: "), s); - print_time (sig ? sig->exp_timestamp : 0, s); + if (at) { + state_attach_puts (_("Warning: The key used to create the " + "signature expired at: "), s); + print_time (at, s); state_attach_puts ("\n", s); } + else + state_attach_puts (_("Warning: At least one certification key " + "has expired\n"), s); + } + + if ((sum & GPGME_SIGSUM_SIG_EXPIRED)) { + gpgme_verify_result_t result; + gpgme_signature_t sig; + unsigned int i; + + result = gpgme_op_verify_result (ctx); + + for (sig = result->signatures, i = 0; sig && (i < idx); + sig = sig->next, i++); + + state_attach_puts (_("Warning: The signature expired at: "), s); + print_time (sig ? sig->exp_timestamp : 0, s); + state_attach_puts ("\n", s); + } if ((sum & GPGME_SIGSUM_KEY_MISSING)) state_attach_puts (_("Can't verify due to a missing " "key or certificate\n"), s); - if ((sum & GPGME_SIGSUM_CRL_MISSING)) - { - state_attach_puts (_("The CRL is not available\n"), s); - severe = 1; - } + if ((sum & GPGME_SIGSUM_CRL_MISSING)) { + state_attach_puts (_("The CRL is not available\n"), s); + severe = 1; + } - if ((sum & GPGME_SIGSUM_CRL_TOO_OLD)) - { - state_attach_puts (_("Available CRL is too old\n"), s); - severe = 1; - } + if ((sum & GPGME_SIGSUM_CRL_TOO_OLD)) { + state_attach_puts (_("Available CRL is too old\n"), s); + severe = 1; + } if ((sum & GPGME_SIGSUM_BAD_POLICY)) state_attach_puts (_("A policy requirement was not met\n"), s); - if ((sum & GPGME_SIGSUM_SYS_ERROR)) - { - const char *t0 = NULL, *t1 = NULL; - gpgme_verify_result_t result; - gpgme_signature_t sig; - unsigned int i; - - state_attach_puts (_("A system error occured"), s ); - - /* Try to figure out some more detailed system error information. */ - result = gpgme_op_verify_result (ctx); - for (sig = result->signatures, i = 0; sig && (i < idx); - sig = sig->next, i++) - ; - if (sig) - { - t0 = ""; - t1 = sig->wrong_key_usage ? "Wrong_Key_Usage" : ""; - } - - if (t0 || t1) - { - state_attach_puts (": ", s); - if (t0) - state_attach_puts (t0, s); - if (t1 && !(t0 && !strcmp (t0, t1))) - { - if (t0) - state_attach_puts (",", s); - state_attach_puts (t1, s); - } - } - state_attach_puts ("\n", s); + if ((sum & GPGME_SIGSUM_SYS_ERROR)) { + const char *t0 = NULL, *t1 = NULL; + gpgme_verify_result_t result; + gpgme_signature_t sig; + unsigned int i; + + state_attach_puts (_("A system error occured"), s); + + /* Try to figure out some more detailed system error information. */ + result = gpgme_op_verify_result (ctx); + for (sig = result->signatures, i = 0; sig && (i < idx); + sig = sig->next, i++); + if (sig) { + t0 = ""; + t1 = sig->wrong_key_usage ? "Wrong_Key_Usage" : ""; + } + + if (t0 || t1) { + state_attach_puts (": ", s); + if (t0) + state_attach_puts (t0, s); + if (t1 && !(t0 && !strcmp (t0, t1))) { + if (t0) + state_attach_puts (",", s); + state_attach_puts (t1, s); + } } + state_attach_puts ("\n", s); + } return severe; } -static void show_fingerprint (gpgme_key_t key, STATE *state) +static void show_fingerprint (gpgme_key_t key, STATE * state) { const char *s; int i, is_pgp; @@ -1098,33 +1033,29 @@ static void show_fingerprint (gpgme_key_t key, STATE *state) return; is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP); - buf = safe_malloc ( strlen (prefix) + strlen(s) * 4 + 2 ); - strcpy (buf, prefix); /* __STRCPY_CHECKED__ */ + buf = safe_malloc (strlen (prefix) + strlen (s) * 4 + 2); + strcpy (buf, prefix); /* __STRCPY_CHECKED__ */ p = buf + strlen (buf); - if (is_pgp && strlen (s) == 40) - { /* PGP v4 style formatted. */ - for (i=0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) - { - *p++ = s[0]; - *p++ = s[1]; - *p++ = s[2]; - *p++ = s[3]; - *p++ = ' '; - if (i == 4) - *p++ = ' '; - } + if (is_pgp && strlen (s) == 40) { /* PGP v4 style formatted. */ + for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) { + *p++ = s[0]; + *p++ = s[1]; + *p++ = s[2]; + *p++ = s[3]; + *p++ = ' '; + if (i == 4) + *p++ = ' '; } - else - { - for (i=0; *s && s[1] && s[2]; s += 2, i++) - { - *p++ = s[0]; - *p++ = s[1]; - *p++ = is_pgp? ' ':':'; - if (is_pgp && i == 7) - *p++ = ' '; - } + } + else { + for (i = 0; *s && s[1] && s[2]; s += 2, i++) { + *p++ = s[0]; + *p++ = s[1]; + *p++ = is_pgp ? ' ' : ':'; + if (is_pgp && i == 7) + *p++ = ' '; } + } /* just in case print remaining odd digits */ for (; *s; s++) @@ -1136,7 +1067,7 @@ static void show_fingerprint (gpgme_key_t key, STATE *state) } /* Show the valididy of a key used for one signature. */ -static void show_one_sig_validity (gpgme_ctx_t ctx, int idx, STATE *s) +static void show_one_sig_validity (gpgme_ctx_t ctx, int idx, STATE * s) { gpgme_verify_result_t result = NULL; gpgme_signature_t sig = NULL; @@ -1146,28 +1077,26 @@ static void show_one_sig_validity (gpgme_ctx_t ctx, int idx, STATE *s) if (result) for (sig = result->signatures; sig && (idx > 0); sig = sig->next, idx--); - switch (sig ? sig->validity : 0) - { - case GPGME_VALIDITY_UNKNOWN: - txt = _("WARNING: We have NO indication whether " - "the key belongs to the person named " - "as shown above\n"); - break; - case GPGME_VALIDITY_UNDEFINED: - break; - case GPGME_VALIDITY_NEVER: - txt = _("WARNING: The key does NOT BELONG to " - "the person named as shown above\n"); - break; - case GPGME_VALIDITY_MARGINAL: - txt = _("WARNING: It is NOT certain that the key " - "belongs to the person named as shown above\n"); - break; - case GPGME_VALIDITY_FULL: - case GPGME_VALIDITY_ULTIMATE: - txt = NULL; - break; - } + switch (sig ? sig->validity : 0) { + case GPGME_VALIDITY_UNKNOWN: + txt = _("WARNING: We have NO indication whether " + "the key belongs to the person named " "as shown above\n"); + break; + case GPGME_VALIDITY_UNDEFINED: + break; + case GPGME_VALIDITY_NEVER: + txt = _("WARNING: The key does NOT BELONG to " + "the person named as shown above\n"); + break; + case GPGME_VALIDITY_MARGINAL: + txt = _("WARNING: It is NOT certain that the key " + "belongs to the person named as shown above\n"); + break; + case GPGME_VALIDITY_FULL: + case GPGME_VALIDITY_ULTIMATE: + txt = NULL; + break; + } if (txt) state_attach_puts (txt, s); } @@ -1179,7 +1108,7 @@ static void show_one_sig_validity (gpgme_ctx_t ctx, int idx, STATE *s) Return values are: 0 for normal procession, 1 for a bad signature, 2 for a signature with a warning or -1 for no more signature. */ -static int show_one_sig_status (gpgme_ctx_t ctx, int idx, STATE *s) +static int show_one_sig_status (gpgme_ctx_t ctx, int idx, STATE * s) { time_t created; const char *fpr, *uid; @@ -1192,117 +1121,106 @@ static int show_one_sig_status (gpgme_ctx_t ctx, int idx, STATE *s) gpgme_error_t err = GPG_ERR_NO_ERROR; result = gpgme_op_verify_result (ctx); - if (result) - { - /* FIXME: this code should use a static variable and remember - the current position in the list of signatures, IMHO. - -moritz. */ - - for (i = 0, sig = result->signatures; sig && (i < idx); - i++, sig = sig->next) - ; - if (! sig) - return -1; /* Signature not found. */ - - if (signature_key) - { - gpgme_key_release (signature_key); - signature_key = NULL; - } - - created = sig->timestamp; - fpr = sig->fpr; - sum = sig->summary; - - if (gpg_err_code (sig->status) != GPG_ERR_NO_ERROR) - anybad = 1; - - err = gpgme_get_key (ctx, fpr, &key, 0); /* secret key? */ - if (! err) - { - uid = (key->uids && key->uids->uid) ? key->uids->uid : "[?]"; - if (! signature_key) - signature_key = key; - } - else - { - key = NULL; /* Old gpgme versions did not set KEY to NULL on - error. Do it here to avoid a double free. */ - uid = "[?]"; - } - - if (!s || !s->fpout || !(s->flags & M_DISPLAY)) - ; /* No state information so no way to print anything. */ - else if (err) - { - state_attach_puts (_("Error getting key information: "), s); - state_attach_puts ( gpg_strerror (err), s ); - state_attach_puts ("\n", s); - anybad = 1; - } - else if ((sum & GPGME_SIGSUM_GREEN)) - { - state_attach_puts (_("Good signature from: "), s); - state_attach_puts (uid, s); - state_attach_puts ("\n", s); - for (i = 1, uids = key->uids; uids; i++, uids = uids->next) - { - if (i == 1) - /* Skip primary UID. */ - continue; - if (uids->revoked) - continue; - state_attach_puts (_(" aka: "), s); - state_attach_puts (uids->uid, s); - state_attach_puts ("\n", s); - } - state_attach_puts (_(" created: "), s); - print_time (created, s); - state_attach_puts ("\n", s); - if (show_sig_summary (sum, ctx, key, idx, s)) - anywarn = 1; - show_one_sig_validity (ctx, idx, s); - } - else if ((sum & GPGME_SIGSUM_RED)) - { - state_attach_puts (_("*BAD* signature claimed to be from: "), s); - state_attach_puts (uid, s); - state_attach_puts ("\n", s); - show_sig_summary (sum, ctx, key, idx, s); - } - else if (!anybad && key && (key->protocol == GPGME_PROTOCOL_OpenPGP)) - { /* We can't decide (yellow) but this is a PGP key with a good - signature, so we display what a PGP user expects: The name, - fingerprint and the key validity (which is neither fully or - ultimate). */ - state_attach_puts (_("Good signature from: "), s); - state_attach_puts (uid, s); - state_attach_puts ("\n", s); - state_attach_puts (_(" created: "), s); - print_time (created, s); - state_attach_puts ("\n", s); - show_one_sig_validity (ctx, idx, s); - show_fingerprint (key,s); - if (show_sig_summary (sum, ctx, key, idx, s)) - anywarn = 1; - } - else /* can't decide (yellow) */ - { - state_attach_puts (_("Error checking signature"), s); - state_attach_puts ("\n", s); - show_sig_summary (sum, ctx, key, idx, s); - } - - if (key != signature_key) - gpgme_key_release (key); - } + if (result) { + /* FIXME: this code should use a static variable and remember + the current position in the list of signatures, IMHO. + -moritz. */ - return anybad ? 1 : anywarn ? 2 : 0; -} + for (i = 0, sig = result->signatures; sig && (i < idx); + i++, sig = sig->next); + if (!sig) + return -1; /* Signature not found. */ -/* Do the actual verification step. With IS_SMIME set to true we - assume S/MIME (surprise!) */ -static int verify_one (BODY *sigbdy, STATE *s, + if (signature_key) { + gpgme_key_release (signature_key); + signature_key = NULL; + } + + created = sig->timestamp; + fpr = sig->fpr; + sum = sig->summary; + + if (gpg_err_code (sig->status) != GPG_ERR_NO_ERROR) + anybad = 1; + + err = gpgme_get_key (ctx, fpr, &key, 0); /* secret key? */ + if (!err) { + uid = (key->uids && key->uids->uid) ? key->uids->uid : "[?]"; + if (!signature_key) + signature_key = key; + } + else { + key = NULL; /* Old gpgme versions did not set KEY to NULL on + error. Do it here to avoid a double free. */ + uid = "[?]"; + } + + if (!s || !s->fpout || !(s->flags & M_DISPLAY)); /* No state information so no way to print anything. */ + else if (err) { + state_attach_puts (_("Error getting key information: "), s); + state_attach_puts (gpg_strerror (err), s); + state_attach_puts ("\n", s); + anybad = 1; + } + else if ((sum & GPGME_SIGSUM_GREEN)) { + state_attach_puts (_("Good signature from: "), s); + state_attach_puts (uid, s); + state_attach_puts ("\n", s); + for (i = 1, uids = key->uids; uids; i++, uids = uids->next) { + if (i == 1) + /* Skip primary UID. */ + continue; + if (uids->revoked) + continue; + state_attach_puts (_(" aka: "), s); + state_attach_puts (uids->uid, s); + state_attach_puts ("\n", s); + } + state_attach_puts (_(" created: "), s); + print_time (created, s); + state_attach_puts ("\n", s); + if (show_sig_summary (sum, ctx, key, idx, s)) + anywarn = 1; + show_one_sig_validity (ctx, idx, s); + } + else if ((sum & GPGME_SIGSUM_RED)) { + state_attach_puts (_("*BAD* signature claimed to be from: "), s); + state_attach_puts (uid, s); + state_attach_puts ("\n", s); + show_sig_summary (sum, ctx, key, idx, s); + } + else if (!anybad && key && (key->protocol == GPGME_PROTOCOL_OpenPGP)) { /* We can't decide (yellow) but this is a PGP key with a good + signature, so we display what a PGP user expects: The name, + fingerprint and the key validity (which is neither fully or + ultimate). */ + state_attach_puts (_("Good signature from: "), s); + state_attach_puts (uid, s); + state_attach_puts ("\n", s); + state_attach_puts (_(" created: "), s); + print_time (created, s); + state_attach_puts ("\n", s); + show_one_sig_validity (ctx, idx, s); + show_fingerprint (key, s); + if (show_sig_summary (sum, ctx, key, idx, s)) + anywarn = 1; + } + else { /* can't decide (yellow) */ + + state_attach_puts (_("Error checking signature"), s); + state_attach_puts ("\n", s); + show_sig_summary (sum, ctx, key, idx, s); + } + + if (key != signature_key) + gpgme_key_release (key); + } + + return anybad ? 1 : anywarn ? 2 : 0; +} + +/* Do the actual verification step. With IS_SMIME set to true we + assume S/MIME (surprise!) */ +static int verify_one (BODY * sigbdy, STATE * s, const char *tempfile, int is_smime) { int badsig = -1; @@ -1321,12 +1239,11 @@ static int verify_one (BODY *sigbdy, STATE *s, gpgme_data_set_encoding (signature, GPGME_DATA_ENCODING_BASE64); err = gpgme_data_new_from_file (&message, tempfile, 1); - if (err) - { - gpgme_data_release (signature); - mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); - return -1; - } + if (err) { + gpgme_data_release (signature); + mutt_error ("error allocating data object: %s\n", gpgme_strerror (err)); + return -1; + } ctx = create_gpgme_context (is_smime); /* Note: We don't need a current time output because GPGME avoids @@ -1336,90 +1253,79 @@ static int verify_one (BODY *sigbdy, STATE *s, err = gpgme_op_verify (ctx, signature, message, NULL); mutt_need_hard_redraw (); - if (err) - { - char buf[200]; - - snprintf (buf, sizeof(buf)-1, - _("Error: verification failed: %s\n"), - gpgme_strerror (err)); - state_attach_puts (buf, s); - } - else - { /* Verification succeeded, see what the result is. */ - int res, idx; - int anybad = 0; - - if (signature_key) - { - gpgme_key_release (signature_key); - signature_key = NULL; - } - - for(idx=0; (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) - { - if (res == 1) - anybad = 1; - else if (res == 2) - anywarn = 2; - } - if (!anybad) - badsig = 0; + if (err) { + char buf[200]; + + snprintf (buf, sizeof (buf) - 1, + _("Error: verification failed: %s\n"), gpgme_strerror (err)); + state_attach_puts (buf, s); + } + else { /* Verification succeeded, see what the result is. */ + int res, idx; + int anybad = 0; + + if (signature_key) { + gpgme_key_release (signature_key); + signature_key = NULL; } - if (!badsig) - { - gpgme_verify_result_t result; - gpgme_sig_notation_t notation; - gpgme_signature_t signature; + for (idx = 0; (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) { + if (res == 1) + anybad = 1; + else if (res == 2) + anywarn = 2; + } + if (!anybad) + badsig = 0; + } - result = gpgme_op_verify_result (ctx); - if (result) - { - for (signature = result->signatures; signature; - signature = signature->next) - { - if (signature->notations) - { - state_attach_puts ("*** Begin Notation (signature by: ", s); - state_attach_puts (signature->fpr, s); - state_attach_puts (") ***\n", s); - for (notation = signature->notations; notation; - notation = notation->next) - { - if (notation->name) - { - state_attach_puts (notation->name, s); - state_attach_puts ("=", s); - } - if (notation->value) - { - state_attach_puts (notation->value, s); - if (!(*notation->value - && (notation->value[strlen (notation->value)-1]=='\n'))) - state_attach_puts ("\n", s); - } - } - state_attach_puts ("*** End Notation ***\n", s); - } - } + if (!badsig) { + gpgme_verify_result_t result; + gpgme_sig_notation_t notation; + gpgme_signature_t signature; + + result = gpgme_op_verify_result (ctx); + if (result) { + for (signature = result->signatures; signature; + signature = signature->next) { + if (signature->notations) { + state_attach_puts ("*** Begin Notation (signature by: ", s); + state_attach_puts (signature->fpr, s); + state_attach_puts (") ***\n", s); + for (notation = signature->notations; notation; + notation = notation->next) { + if (notation->name) { + state_attach_puts (notation->name, s); + state_attach_puts ("=", s); + } + if (notation->value) { + state_attach_puts (notation->value, s); + if (!(*notation->value + && (notation->value[strlen (notation->value) - 1] == + '\n'))) + state_attach_puts ("\n", s); + } + } + state_attach_puts ("*** End Notation ***\n", s); + } } } + } gpgme_release (ctx); - + state_attach_puts (_("[-- End signature information --]\n\n"), s); dprint (1, (debugfile, "verify_one: returning %d.\n", badsig)); - - return badsig? 1: anywarn? 2 : 0; + + return badsig ? 1 : anywarn ? 2 : 0; } -int pgp_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) +int pgp_gpgme_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) { return verify_one (sigbdy, s, tempfile, 0); } -int smime_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) +int smime_gpgme_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) { return verify_one (sigbdy, s, tempfile, 1); } @@ -1434,7 +1340,7 @@ int smime_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile) a flag in R_IS_SIGNED to indicate whether this is a combined encrypted and signed message, for S/MIME it returns true when it is not a encrypted but a signed message. */ -static BODY *decrypt_part (BODY *a, STATE *s, FILE *fpout, int is_smime, +static BODY *decrypt_part (BODY * a, STATE * s, FILE * fpout, int is_smime, int *r_is_signed) { struct stat info; @@ -1451,7 +1357,7 @@ static BODY *decrypt_part (BODY *a, STATE *s, FILE *fpout, int is_smime, ctx = create_gpgme_context (is_smime); - restart: +restart: /* Make a data object from the body, create context etc. */ ciphertext = file_to_data_object (s->fpin, a->offset, a->length); if (!ciphertext) @@ -1459,144 +1365,133 @@ static BODY *decrypt_part (BODY *a, STATE *s, FILE *fpout, int is_smime, plaintext = create_gpgme_data (); /* Do the decryption or the verification in case of the S/MIME hack. */ - if ((! is_smime) || maybe_signed) + if ((!is_smime) || maybe_signed) { + if (!is_smime) + err = gpgme_op_decrypt_verify (ctx, ciphertext, plaintext); + else if (maybe_signed) + err = gpgme_op_verify (ctx, ciphertext, NULL, plaintext); + { - if (! is_smime) - err = gpgme_op_decrypt_verify (ctx, ciphertext, plaintext); - else if (maybe_signed) - err = gpgme_op_verify (ctx, ciphertext, NULL, plaintext); + /* Check wether signatures have been verified. */ + gpgme_verify_result_t verify_result = gpgme_op_verify_result (ctx); - { - /* Check wether signatures have been verified. */ - gpgme_verify_result_t verify_result = gpgme_op_verify_result (ctx); - if (verify_result->signatures) - sig_stat = 1; - } + if (verify_result->signatures) + sig_stat = 1; } + } else err = gpgme_op_decrypt (ctx, ciphertext, plaintext); gpgme_data_release (ciphertext); - if (err) - { - if (is_smime && !maybe_signed - && gpg_err_code (err) == GPG_ERR_NO_DATA) - { - /* Check whether this might be a signed message despite what - the mime header told us. Retry then. gpgsm returns the - error information "unsupported Algorithm '?'" but gpgme - will not store this unknown algorithm, thus we test that - it has not been set. */ - gpgme_decrypt_result_t result; - - result = gpgme_op_decrypt_result (ctx); - if (!result->unsupported_algorithm) - { - maybe_signed = 1; - gpgme_data_release (plaintext); - goto restart; - } - } - mutt_need_hard_redraw (); - if ((s->flags & M_DISPLAY)) - { - char buf[200]; - - snprintf (buf, sizeof(buf)-1, - _("[-- Error: decryption failed: %s --]\n\n"), - gpgme_strerror (err)); - state_attach_puts (buf, s); - } - gpgme_data_release (plaintext); - gpgme_release (ctx); - return NULL; + if (err) { + if (is_smime && !maybe_signed && gpg_err_code (err) == GPG_ERR_NO_DATA) { + /* Check whether this might be a signed message despite what + the mime header told us. Retry then. gpgsm returns the + error information "unsupported Algorithm '?'" but gpgme + will not store this unknown algorithm, thus we test that + it has not been set. */ + gpgme_decrypt_result_t result; + + result = gpgme_op_decrypt_result (ctx); + if (!result->unsupported_algorithm) { + maybe_signed = 1; + gpgme_data_release (plaintext); + goto restart; + } + } + mutt_need_hard_redraw (); + if ((s->flags & M_DISPLAY)) { + char buf[200]; + + snprintf (buf, sizeof (buf) - 1, + _("[-- Error: decryption failed: %s --]\n\n"), + gpgme_strerror (err)); + state_attach_puts (buf, s); + } + gpgme_data_release (plaintext); + gpgme_release (ctx); + return NULL; } mutt_need_hard_redraw (); /* Read the output from GPGME, and make sure to change CRLF to LF, otherwise read_mime_header has a hard time parsing the message. */ - if (data_object_to_stream (plaintext, fpout)) - { - gpgme_data_release (plaintext); - gpgme_release (ctx); - return NULL; - } + if (data_object_to_stream (plaintext, fpout)) { + gpgme_data_release (plaintext); + gpgme_release (ctx); + return NULL; + } gpgme_data_release (plaintext); a->is_signed_data = 0; - if (sig_stat) - { - int res, idx; - int anybad = 0; - - if (maybe_signed) - a->is_signed_data = 1; - if(r_is_signed) - *r_is_signed = -1; /* A signature exists. */ - - if ((s->flags & M_DISPLAY)) - state_attach_puts (_("[-- Begin signature " - "information --]\n"), s); - for(idx = 0; (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) - { - if (res == 1) - anybad = 1; - else if (res == 2) - anywarn = 1; - } - if (!anybad && idx && r_is_signed && *r_is_signed) - *r_is_signed = anywarn? 2:1; /* Good signature. */ - - if ((s->flags & M_DISPLAY)) - state_attach_puts (_("[-- End signature " - "information --]\n\n"), s); - } - gpgme_release (ctx); ctx = NULL; + if (sig_stat) { + int res, idx; + int anybad = 0; + + if (maybe_signed) + a->is_signed_data = 1; + if (r_is_signed) + *r_is_signed = -1; /* A signature exists. */ + + if ((s->flags & M_DISPLAY)) + state_attach_puts (_("[-- Begin signature " "information --]\n"), s); + for (idx = 0; (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) { + if (res == 1) + anybad = 1; + else if (res == 2) + anywarn = 1; + } + if (!anybad && idx && r_is_signed && *r_is_signed) + *r_is_signed = anywarn ? 2 : 1; /* Good signature. */ + + if ((s->flags & M_DISPLAY)) + state_attach_puts (_("[-- End signature " "information --]\n\n"), s); + } + gpgme_release (ctx); + ctx = NULL; fflush (fpout); rewind (fpout); tattach = mutt_read_mime_header (fpout, 0); - if (tattach) - { - /* - * Need to set the length of this body part. - */ - fstat (fileno (fpout), &info); - tattach->length = info.st_size - tattach->offset; - - tattach->warnsig = anywarn; + if (tattach) { + /* + * Need to set the length of this body part. + */ + fstat (fileno (fpout), &info); + tattach->length = info.st_size - tattach->offset; - /* See if we need to recurse on this MIME part. */ - mutt_parse_part (fpout, tattach); - } + tattach->warnsig = anywarn; + + /* See if we need to recurse on this MIME part. */ + mutt_parse_part (fpout, tattach); + } return tattach; } /* Decrypt a PGP/MIME message in FPIN and B and return a new body and the stream in CUR and FPOUT. Returns 0 on success. */ -int pgp_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) +int pgp_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) { char tempfile[_POSIX_PATH_MAX]; STATE s; BODY *first_part = b; int is_signed; - + first_part->goodsig = 0; first_part->warnsig = 0; - if(!mutt_is_multipart_encrypted(b)) + if (!mutt_is_multipart_encrypted (b)) return -1; - if(!b->parts || !b->parts->next) + if (!b->parts || !b->parts->next) return -1; - + b = b->parts->next; - + memset (&s, 0, sizeof (s)); s.fpin = fpin; mutt_mktemp (tempfile); - if (!(*fpout = safe_fopen (tempfile, "w+"))) - { + if (!(*fpout = safe_fopen (tempfile, "w+"))) { mutt_perror (tempfile); return -1; } @@ -1606,18 +1501,19 @@ int pgp_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) rewind (*fpout); if (is_signed > 0) first_part->goodsig = 1; - - return *cur? 0:-1; + + return *cur ? 0 : -1; } /* Decrypt a S/MIME message in FPIN and B and return a new body and the stream in CUR and FPOUT. Returns 0 on success. */ -int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) +int smime_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, + BODY ** cur) { char tempfile[_POSIX_PATH_MAX]; STATE s; - FILE *tmpfp=NULL; + FILE *tmpfp = NULL; int is_signed; long saved_b_offset; size_t saved_b_length; @@ -1628,7 +1524,7 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) if (b->parts) return -1; - + /* Decode the body - we need to pass binary CMS to the backend. The backend allows for Base64 encoded data but it does not allow for QP which I have seen in some messages. So better @@ -1638,13 +1534,12 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) saved_b_length = b->length; memset (&s, 0, sizeof (s)); s.fpin = fpin; - fseek (s.fpin, b->offset, 0); + fseek (s.fpin, b->offset, 0); mutt_mktemp (tempfile); - if (!(tmpfp = safe_fopen (tempfile, "w+"))) - { - mutt_perror (tempfile); - return -1; - } + if (!(tmpfp = safe_fopen (tempfile, "w+"))) { + mutt_perror (tempfile); + return -1; + } mutt_unlink (tempfile); s.fpout = tmpfp; @@ -1658,11 +1553,10 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) s.fpin = tmpfp; s.fpout = 0; mutt_mktemp (tempfile); - if (!(*fpout = safe_fopen (tempfile, "w+"))) - { - mutt_perror (tempfile); - return -1; - } + if (!(*fpout = safe_fopen (tempfile, "w+"))) { + mutt_perror (tempfile); + return -1; + } mutt_unlink (tempfile); *cur = decrypt_part (b, &s, *fpout, 1, &is_signed); @@ -1673,65 +1567,63 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) b->offset = saved_b_offset; fclose (tmpfp); rewind (*fpout); - if (*cur && !is_signed && !(*cur)->parts && mutt_is_application_smime (*cur)) - { - /* Assume that this is a opaque signed s/mime message. This is - an ugly way of doing it but we have anyway a problem with - arbitrary encoded S/MIME messages: Only the outer part may be - encrypted. The entire mime parsing should be revamped, - probably by keeping the temportary files so that we don't - need to decrypt them all the time. Inner parts of an - encrypted part can then pint into this file and tehre won't - never be a need to decrypt again. This needs a partial - rewrite of the MIME engine. */ - BODY *bb = *cur; - BODY *tmp_b; - - saved_b_type = bb->type; - saved_b_offset = bb->offset; - saved_b_length = bb->length; - memset (&s, 0, sizeof (s)); - s.fpin = *fpout; - fseek (s.fpin, bb->offset, 0); - mutt_mktemp (tempfile); - if (!(tmpfp = safe_fopen (tempfile, "w+"))) - { - mutt_perror (tempfile); - return -1; - } - mutt_unlink (tempfile); - - s.fpout = tmpfp; - mutt_decode_attachment (bb, &s); - fflush (tmpfp); - bb->length = ftell (s.fpout); - bb->offset = 0; - rewind (tmpfp); - fclose (*fpout); - - memset (&s, 0, sizeof (s)); - s.fpin = tmpfp; - s.fpout = 0; - mutt_mktemp (tempfile); - if (!(*fpout = safe_fopen (tempfile, "w+"))) - { - mutt_perror (tempfile); - return -1; - } - mutt_unlink (tempfile); - - tmp_b = decrypt_part (bb, &s, *fpout, 1, &is_signed); - if (tmp_b) - tmp_b->goodsig = is_signed > 0; - bb->type = saved_b_type; - bb->length = saved_b_length; - bb->offset = saved_b_offset; - fclose (tmpfp); - rewind (*fpout); - mutt_free_body (cur); - *cur = tmp_b; + if (*cur && !is_signed && !(*cur)->parts + && mutt_is_application_smime (*cur)) { + /* Assume that this is a opaque signed s/mime message. This is + an ugly way of doing it but we have anyway a problem with + arbitrary encoded S/MIME messages: Only the outer part may be + encrypted. The entire mime parsing should be revamped, + probably by keeping the temportary files so that we don't + need to decrypt them all the time. Inner parts of an + encrypted part can then pint into this file and tehre won't + never be a need to decrypt again. This needs a partial + rewrite of the MIME engine. */ + BODY *bb = *cur; + BODY *tmp_b; + + saved_b_type = bb->type; + saved_b_offset = bb->offset; + saved_b_length = bb->length; + memset (&s, 0, sizeof (s)); + s.fpin = *fpout; + fseek (s.fpin, bb->offset, 0); + mutt_mktemp (tempfile); + if (!(tmpfp = safe_fopen (tempfile, "w+"))) { + mutt_perror (tempfile); + return -1; + } + mutt_unlink (tempfile); + + s.fpout = tmpfp; + mutt_decode_attachment (bb, &s); + fflush (tmpfp); + bb->length = ftell (s.fpout); + bb->offset = 0; + rewind (tmpfp); + fclose (*fpout); + + memset (&s, 0, sizeof (s)); + s.fpin = tmpfp; + s.fpout = 0; + mutt_mktemp (tempfile); + if (!(*fpout = safe_fopen (tempfile, "w+"))) { + mutt_perror (tempfile); + return -1; } - return *cur? 0:-1; + mutt_unlink (tempfile); + + tmp_b = decrypt_part (bb, &s, *fpout, 1, &is_signed); + if (tmp_b) + tmp_b->goodsig = is_signed > 0; + bb->type = saved_b_type; + bb->length = saved_b_length; + bb->offset = saved_b_offset; + fclose (tmpfp); + rewind (*fpout); + mutt_free_body (cur); + *cur = tmp_b; + } + return *cur ? 0 : -1; } @@ -1739,15 +1631,16 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) * Implementation of `pgp_check_traditional'. */ -static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) +static int pgp_check_traditional_one_body (FILE * fp, BODY * b, + int tagged_only) { char tempfile[_POSIX_PATH_MAX]; char buf[HUGE_STRING]; FILE *tfp; - + short sgn = 0; short enc = 0; - + if (b->type != TYPETEXT) return 0; @@ -1755,26 +1648,22 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) return 0; mutt_mktemp (tempfile); - if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0) - { + if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0) { unlink (tempfile); return 0; } - - if ((tfp = fopen (tempfile, "r")) == NULL) - { + + if ((tfp = fopen (tempfile, "r")) == NULL) { unlink (tempfile); return 0; } - - while (fgets (buf, sizeof (buf), tfp)) - { - if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) - { + + while (fgets (buf, sizeof (buf), tfp)) { + if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) { if (!mutt_strcmp ("MESSAGE-----\n", buf + 15)) - enc = 1; + enc = 1; else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15)) - sgn = 1; + sgn = 1; } } safe_fclose (&tfp); @@ -1784,28 +1673,27 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) return 0; /* fix the content type */ - + mutt_set_parameter ("format", "fixed", &b->parameter); mutt_set_parameter ("x-action", enc ? "pgp-encrypted" : "pgp-signed", &b->parameter); - + return 1; } -int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only) +int pgp_gpgme_check_traditional (FILE * fp, BODY * b, int tagged_only) { int rv = 0; int r; - for (; b; b = b->next) - { + + for (; b; b = b->next) { if (is_multipart (b)) rv = (pgp_gpgme_check_traditional (fp, b->parts, tagged_only) || rv); - else if (b->type == TYPETEXT) - { + else if (b->type == TYPETEXT) { if ((r = mutt_is_application_pgp (b))) - rv = (rv || r); + rv = (rv || r); else - rv = (pgp_check_traditional_one_body (fp, b, tagged_only) || rv); + rv = (pgp_check_traditional_one_body (fp, b, tagged_only) || rv); } } return rv; @@ -1828,7 +1716,7 @@ int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only) note that we can successfully handle anything produced by any existing versions of mutt.) */ -static void copy_clearsigned (gpgme_data_t data, STATE *s, char *charset) +static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset) { char buf[HUGE_STRING]; short complete, armor_header; @@ -1841,46 +1729,43 @@ static void copy_clearsigned (gpgme_data_t data, STATE *s, char *charset) return; unlink (fname); FREE (&fname); - + fc = fgetconv_open (fp, charset, Charset, M_ICONV_HOOK_FROM); - + for (complete = 1, armor_header = 1; fgetconvs (buf, sizeof (buf), fc) != NULL; - complete = strchr (buf, '\n') != NULL) - { - if (!complete) - { + complete = strchr (buf, '\n') != NULL) { + if (!complete) { if (!armor_header) - state_puts (buf, s); + state_puts (buf, s); continue; } if (!mutt_strcmp (buf, "-----BEGIN PGP SIGNATURE-----\n")) break; - - if (armor_header) - { - if (buf[0] == '\n') - armor_header = 0; + + if (armor_header) { + if (buf[0] == '\n') + armor_header = 0; continue; } - - if (s->prefix) + + if (s->prefix) state_puts (s->prefix, s); - + if (buf[0] == '-' && buf[1] == ' ') state_puts (buf + 2, s); else state_puts (buf, s); } - + fgetconv_close (&fc); fclose (fp); } /* Support for classic_application/pgp */ -void pgp_gpgme_application_handler (BODY *m, STATE *s) +void pgp_gpgme_application_handler (BODY * m, STATE * s) { int needpass = -1, pgp_keyblock = 0; int clearsign = 0; @@ -1895,7 +1780,7 @@ void pgp_gpgme_application_handler (BODY *m, STATE *s) short maybe_goodsig = 1; short have_any_sigs = 0; - char body_charset[STRING]; /* Only used for clearsigned messages. */ + char body_charset[STRING]; /* Only used for clearsigned messages. */ dprint (2, (debugfile, "Entering pgp_application_pgp handler\n")); @@ -1907,229 +1792,201 @@ void pgp_gpgme_application_handler (BODY *m, STATE *s) fseek (s->fpin, m->offset, 0); last_pos = m->offset; - - for (bytes = m->length; bytes > 0;) - { - if (fgets (buf, sizeof (buf), s->fpin) == NULL) - break; - - offset = ftell (s->fpin); - bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf) */ - last_pos = offset; - - if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) - { - clearsign = 0; - start_pos = last_pos; - - if (!mutt_strcmp ("MESSAGE-----\n", buf + 15)) - needpass = 1; - else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15)) - { - clearsign = 1; - needpass = 0; - } - else if (!option (OPTDONTHANDLEPGPKEYS) && - !mutt_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15)) - { - needpass = 0; - pgp_keyblock =1; - } - else - { - /* XXX - we may wish to recode here */ - if (s->prefix) - state_puts (s->prefix, s); - state_puts (buf, s); - continue; - } - - have_any_sigs = (have_any_sigs - || (clearsign && (s->flags & M_VERIFY))); - - /* Copy PGP material to an data container */ - armored_data = create_gpgme_data (); - gpgme_data_write (armored_data, buf, strlen (buf)); - while (bytes > 0 && fgets (buf, sizeof (buf) - 1, s->fpin) != NULL) - { - offset = ftell (s->fpin); - bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf)*/ - last_pos = offset; - - gpgme_data_write (armored_data, buf, strlen (buf)); - - if ((needpass - && !mutt_strcmp ("-----END PGP MESSAGE-----\n", buf)) - || (!needpass - && (!mutt_strcmp ("-----END PGP SIGNATURE-----\n", buf) - || !mutt_strcmp ( - "-----END PGP PUBLIC KEY BLOCK-----\n",buf)))) - break; - } - - /* Invoke PGP if needed */ - if (!clearsign || (s->flags & M_VERIFY)) - { - unsigned int sig_stat = 0; - gpgme_data_t plaintext; - gpgme_ctx_t ctx; - - plaintext = create_gpgme_data (); - ctx = create_gpgme_context (0); - - if (clearsign) - err = gpgme_op_verify (ctx, armored_data, NULL, plaintext); - else - { - err = gpgme_op_decrypt_verify (ctx, armored_data, plaintext); - if (gpg_err_code (err) == GPG_ERR_NO_DATA) - { - /* Decrypt verify can't handle signed only messages. */ - err = (gpgme_data_seek (armored_data, 0, SEEK_SET) == -1) - ? gpgme_error_from_errno (errno) : 0; - /* Must release plaintext so that we supply an - uninitialized object. */ - gpgme_data_release (plaintext); - plaintext = create_gpgme_data (); - err = gpgme_op_verify (ctx, armored_data, - NULL, plaintext); - } - } - - if (err) - { - char errbuf[200]; - - snprintf (errbuf, sizeof(errbuf)-1, - _("Error: decryption/verification failed: %s\n"), - gpgme_strerror (err)); - state_attach_puts (errbuf, s); - } - else - { /* Decryption/Verification succeeded */ - char *tmpfname; - - { - /* Check wether signatures have been verified. */ - gpgme_verify_result_t verify_result; - - verify_result = gpgme_op_verify_result (ctx); - if (verify_result->signatures) - sig_stat = 1; - } - - have_any_sigs = 0; - maybe_goodsig = 0; - if ((s->flags & M_DISPLAY) && sig_stat) - { - int res, idx; - int anybad = 0; - int anywarn = 0; - - state_attach_puts (_("[-- Begin signature " - "information --]\n"), s); - have_any_sigs = 1; - for(idx=0; - (res = show_one_sig_status (ctx, idx, s)) != -1; - idx++) - { - if (res == 1) - anybad = 1; - else if (res == 2) - anywarn = 1; - } - if (!anybad && idx) - maybe_goodsig = 1; - - state_attach_puts (_("[-- End signature " - "information --]\n\n"), s); - } - - tmpfname = data_object_to_tempfile (plaintext, &pgpout); - if (!tmpfname) - { - pgpout = NULL; - state_attach_puts (_("Error: copy data failed\n"), s); - } - else - { - unlink (tmpfname); - FREE (&tmpfname); - } - } - gpgme_release (ctx); - } - - /* - * Now, copy cleartext to the screen. NOTE - we expect that PGP - * outputs utf-8 cleartext. This may not always be true, but it - * seems to be a reasonable guess. - */ - - if(s->flags & M_DISPLAY) - { - if (needpass) - state_attach_puts (_("[-- BEGIN PGP MESSAGE --]\n\n"), s); - else if (pgp_keyblock) - state_attach_puts (_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), - s); - else - state_attach_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), - s); - } - - if (clearsign) - { - copy_clearsigned (armored_data, s, body_charset); - } - else if (pgpout) - { - FGETCONV *fc; - int c; - rewind (pgpout); - fc = fgetconv_open (pgpout, "utf-8", Charset, 0); - while ((c = fgetconv (fc)) != EOF) - { - state_putc (c, s); - if (c == '\n' && s->prefix) - state_puts (s->prefix, s); - } - fgetconv_close (&fc); - } - - if (s->flags & M_DISPLAY) - { - state_putc ('\n', s); - if (needpass) - state_attach_puts (_("[-- END PGP MESSAGE --]\n"), s); - else if (pgp_keyblock) - state_attach_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s); - else - state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s); - } - - if (pgpout) - { - safe_fclose (&pgpout); + + for (bytes = m->length; bytes > 0;) { + if (fgets (buf, sizeof (buf), s->fpin) == NULL) + break; + + offset = ftell (s->fpin); + bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf) */ + last_pos = offset; + + if (!mutt_strncmp ("-----BEGIN PGP ", buf, 15)) { + clearsign = 0; + start_pos = last_pos; + + if (!mutt_strcmp ("MESSAGE-----\n", buf + 15)) + needpass = 1; + else if (!mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15)) { + clearsign = 1; + needpass = 0; + } + else if (!option (OPTDONTHANDLEPGPKEYS) && + !mutt_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15)) { + needpass = 0; + pgp_keyblock = 1; + } + else { + /* XXX - we may wish to recode here */ + if (s->prefix) + state_puts (s->prefix, s); + state_puts (buf, s); + continue; + } + + have_any_sigs = (have_any_sigs || (clearsign && (s->flags & M_VERIFY))); + + /* Copy PGP material to an data container */ + armored_data = create_gpgme_data (); + gpgme_data_write (armored_data, buf, strlen (buf)); + while (bytes > 0 && fgets (buf, sizeof (buf) - 1, s->fpin) != NULL) { + offset = ftell (s->fpin); + bytes -= (offset - last_pos); /* don't rely on mutt_strlen(buf) */ + last_pos = offset; + + gpgme_data_write (armored_data, buf, strlen (buf)); + + if ((needpass && !mutt_strcmp ("-----END PGP MESSAGE-----\n", buf)) + || (!needpass + && (!mutt_strcmp ("-----END PGP SIGNATURE-----\n", buf) + || !mutt_strcmp ("-----END PGP PUBLIC KEY BLOCK-----\n", + buf)))) + break; + } + + /* Invoke PGP if needed */ + if (!clearsign || (s->flags & M_VERIFY)) { + unsigned int sig_stat = 0; + gpgme_data_t plaintext; + gpgme_ctx_t ctx; + + plaintext = create_gpgme_data (); + ctx = create_gpgme_context (0); + + if (clearsign) + err = gpgme_op_verify (ctx, armored_data, NULL, plaintext); + else { + err = gpgme_op_decrypt_verify (ctx, armored_data, plaintext); + if (gpg_err_code (err) == GPG_ERR_NO_DATA) { + /* Decrypt verify can't handle signed only messages. */ + err = (gpgme_data_seek (armored_data, 0, SEEK_SET) == -1) + ? gpgme_error_from_errno (errno) : 0; + /* Must release plaintext so that we supply an + uninitialized object. */ + gpgme_data_release (plaintext); + plaintext = create_gpgme_data (); + err = gpgme_op_verify (ctx, armored_data, NULL, plaintext); + } + } + + if (err) { + char errbuf[200]; + + snprintf (errbuf, sizeof (errbuf) - 1, + _("Error: decryption/verification failed: %s\n"), + gpgme_strerror (err)); + state_attach_puts (errbuf, s); + } + else { /* Decryption/Verification succeeded */ + char *tmpfname; + + { + /* Check wether signatures have been verified. */ + gpgme_verify_result_t verify_result; + + verify_result = gpgme_op_verify_result (ctx); + if (verify_result->signatures) + sig_stat = 1; + } + + have_any_sigs = 0; + maybe_goodsig = 0; + if ((s->flags & M_DISPLAY) && sig_stat) { + int res, idx; + int anybad = 0; + int anywarn = 0; + + state_attach_puts (_("[-- Begin signature " + "information --]\n"), s); + have_any_sigs = 1; + for (idx = 0; + (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) { + if (res == 1) + anybad = 1; + else if (res == 2) + anywarn = 1; } + if (!anybad && idx) + maybe_goodsig = 1; + + state_attach_puts (_("[-- End signature " + "information --]\n\n"), s); + } + + tmpfname = data_object_to_tempfile (plaintext, &pgpout); + if (!tmpfname) { + pgpout = NULL; + state_attach_puts (_("Error: copy data failed\n"), s); + } + else { + unlink (tmpfname); + FREE (&tmpfname); + } } - else - { - /* XXX - we may wish to recode here */ - if (s->prefix) + gpgme_release (ctx); + } + + /* + * Now, copy cleartext to the screen. NOTE - we expect that PGP + * outputs utf-8 cleartext. This may not always be true, but it + * seems to be a reasonable guess. + */ + + if (s->flags & M_DISPLAY) { + if (needpass) + state_attach_puts (_("[-- BEGIN PGP MESSAGE --]\n\n"), s); + else if (pgp_keyblock) + state_attach_puts (_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s); + else + state_attach_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s); + } + + if (clearsign) { + copy_clearsigned (armored_data, s, body_charset); + } + else if (pgpout) { + FGETCONV *fc; + int c; + + rewind (pgpout); + fc = fgetconv_open (pgpout, "utf-8", Charset, 0); + while ((c = fgetconv (fc)) != EOF) { + state_putc (c, s); + if (c == '\n' && s->prefix) state_puts (s->prefix, s); - state_puts (buf, s); } + fgetconv_close (&fc); + } + + if (s->flags & M_DISPLAY) { + state_putc ('\n', s); + if (needpass) + state_attach_puts (_("[-- END PGP MESSAGE --]\n"), s); + else if (pgp_keyblock) + state_attach_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s); + else + state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s); + } + + if (pgpout) { + safe_fclose (&pgpout); + } + } + else { + /* XXX - we may wish to recode here */ + if (s->prefix) + state_puts (s->prefix, s); + state_puts (buf, s); } + } m->goodsig = (maybe_goodsig && have_any_sigs); - - if (needpass == -1) - { - state_attach_puts (_("[-- Error: could not find beginning" - " of PGP message! --]\n\n"), s); - return; - } + + if (needpass == -1) { + state_attach_puts (_("[-- Error: could not find beginning" + " of PGP message! --]\n\n"), s); + return; + } dprint (2, (debugfile, "Leaving pgp_application_pgp handler\n")); } @@ -2138,84 +1995,84 @@ void pgp_gpgme_application_handler (BODY *m, STATE *s) */ /* MIME handler for pgp/mime encrypted messages. */ -void pgp_gpgme_encrypted_handler (BODY *a, STATE *s) +void pgp_gpgme_encrypted_handler (BODY * a, STATE * s) { char tempfile[_POSIX_PATH_MAX]; FILE *fpout; BODY *tattach; BODY *orig_body = a; int is_signed; - + dprint (2, (debugfile, "Entering pgp_encrypted handler\n")); a = a->parts; if (!a || a->type != TYPEAPPLICATION || !a->subtype - || ascii_strcasecmp ("pgp-encrypted", a->subtype) + || ascii_strcasecmp ("pgp-encrypted", a->subtype) || !a->next || a->next->type != TYPEAPPLICATION || !a->next->subtype - || ascii_strcasecmp ("octet-stream", a->next->subtype) ) - { - if (s->flags & M_DISPLAY) - state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), - s); - return; - } + || ascii_strcasecmp ("octet-stream", a->next->subtype)) { + if (s->flags & M_DISPLAY) + state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), + s); + return; + } /* Move forward to the application/pgp-encrypted body. */ a = a->next; mutt_mktemp (tempfile); - if (!(fpout = safe_fopen (tempfile, "w+"))) - { - if (s->flags & M_DISPLAY) - state_attach_puts (_("[-- Error: could not create temporary file! " - "--]\n"), s); - return; - } + if (!(fpout = safe_fopen (tempfile, "w+"))) { + if (s->flags & M_DISPLAY) + state_attach_puts (_("[-- Error: could not create temporary file! " + "--]\n"), s); + return; + } tattach = decrypt_part (a, s, fpout, 0, &is_signed); - if (tattach) + if (tattach) { + tattach->goodsig = is_signed > 0; + + if (s->flags & M_DISPLAY) + state_attach_puts (is_signed ? + _ + ("[-- The following data is PGP/MIME signed and encrypted --]\n\n") + : + _ + ("[-- The following data is PGP/MIME encrypted --]\n\n"), + s); + { - tattach->goodsig = is_signed > 0; - - if (s->flags & M_DISPLAY) - state_attach_puts (is_signed? - _("[-- The following data is PGP/MIME signed and encrypted --]\n\n"): - _("[-- The following data is PGP/MIME encrypted --]\n\n"), - s); - - { - FILE *savefp = s->fpin; - s->fpin = fpout; - mutt_body_handler (tattach, s); - s->fpin = savefp; - } + FILE *savefp = s->fpin; - /* - * if a multipart/signed is the _only_ sub-part of a - * multipart/encrypted, cache signature verification - * status. - */ - if (mutt_is_multipart_signed (tattach) && !tattach->next) - orig_body->goodsig |= tattach->goodsig; - - if (s->flags & M_DISPLAY) - { - state_puts ("\n", s); - state_attach_puts (is_signed? - _("[-- End of PGP/MIME signed and encrypted data --]\n"): - _("[-- End of PGP/MIME encrypted data --]\n"), - s); - } + s->fpin = fpout; + mutt_body_handler (tattach, s); + s->fpin = savefp; + } - mutt_free_body (&tattach); + /* + * if a multipart/signed is the _only_ sub-part of a + * multipart/encrypted, cache signature verification + * status. + */ + if (mutt_is_multipart_signed (tattach) && !tattach->next) + orig_body->goodsig |= tattach->goodsig; + + if (s->flags & M_DISPLAY) { + state_puts ("\n", s); + state_attach_puts (is_signed ? + _ + ("[-- End of PGP/MIME signed and encrypted data --]\n") + : _("[-- End of PGP/MIME encrypted data --]\n"), s); } - + + mutt_free_body (&tattach); + } + fclose (fpout); - mutt_unlink(tempfile); + mutt_unlink (tempfile); dprint (2, (debugfile, "Leaving pgp_encrypted handler\n")); } /* Support for application/smime */ -void smime_gpgme_application_handler (BODY *a, STATE *s) +void smime_gpgme_application_handler (BODY * a, STATE * s) { char tempfile[_POSIX_PATH_MAX]; FILE *fpout; @@ -2224,65 +2081,62 @@ void smime_gpgme_application_handler (BODY *a, STATE *s) dprint (2, (debugfile, "Entering smime_encrypted handler\n")); - + a->warnsig = 0; mutt_mktemp (tempfile); - if (!(fpout = safe_fopen (tempfile, "w+"))) - { - if (s->flags & M_DISPLAY) - state_attach_puts (_("[-- Error: could not create temporary file! " - "--]\n"), s); - return; - } + if (!(fpout = safe_fopen (tempfile, "w+"))) { + if (s->flags & M_DISPLAY) + state_attach_puts (_("[-- Error: could not create temporary file! " + "--]\n"), s); + return; + } tattach = decrypt_part (a, s, fpout, 1, &is_signed); - if (tattach) + if (tattach) { + tattach->goodsig = is_signed > 0; + + if (s->flags & M_DISPLAY) + state_attach_puts (is_signed ? + _("[-- The following data is S/MIME signed --]\n\n") + : + _ + ("[-- The following data is S/MIME encrypted --]\n\n"), + s); + { - tattach->goodsig = is_signed > 0; - - if (s->flags & M_DISPLAY) - state_attach_puts (is_signed? - _("[-- The following data is S/MIME signed --]\n\n"): - _("[-- The following data is S/MIME encrypted --]\n\n"), - s); - - { - FILE *savefp = s->fpin; - s->fpin = fpout; - mutt_body_handler (tattach, s); - s->fpin = savefp; - } + FILE *savefp = s->fpin; - /* - * if a multipart/signed is the _only_ sub-part of a - * multipart/encrypted, cache signature verification - * status. - */ - if (mutt_is_multipart_signed (tattach) && !tattach->next) - { - if (!(a->goodsig = tattach->goodsig)) - a->warnsig = tattach->warnsig; - } - else if (tattach->goodsig) - { - a->goodsig = 1; - a->warnsig = tattach->warnsig; - } + s->fpin = fpout; + mutt_body_handler (tattach, s); + s->fpin = savefp; + } - if (s->flags & M_DISPLAY) - { - state_puts ("\n", s); - state_attach_puts (is_signed? - _("[-- End of S/MIME signed data --]\n"): - _("[-- End of S/MIME encrypted data --]\n"), - s); - } + /* + * if a multipart/signed is the _only_ sub-part of a + * multipart/encrypted, cache signature verification + * status. + */ + if (mutt_is_multipart_signed (tattach) && !tattach->next) { + if (!(a->goodsig = tattach->goodsig)) + a->warnsig = tattach->warnsig; + } + else if (tattach->goodsig) { + a->goodsig = 1; + a->warnsig = tattach->warnsig; + } - mutt_free_body (&tattach); + if (s->flags & M_DISPLAY) { + state_puts ("\n", s); + state_attach_puts (is_signed ? + _("[-- End of S/MIME signed data --]\n") : + _("[-- End of S/MIME encrypted data --]\n"), s); } - + + mutt_free_body (&tattach); + } + fclose (fpout); - mutt_unlink(tempfile); + mutt_unlink (tempfile); dprint (2, (debugfile, "Leaving smime_encrypted handler\n")); } @@ -2309,8 +2163,7 @@ static const char *crypt_entry_fmt (char *dest, const char *prefix, const char *ifstring, const char *elsestring, - unsigned long data, - format_flag flags) + unsigned long data, format_flag flags) { char fmt[16]; crypt_entry_t *entry; @@ -2321,190 +2174,174 @@ static const char *crypt_entry_fmt (char *dest, unsigned long val; entry = (crypt_entry_t *) data; - key = entry->key; + key = entry->key; /* if (isupper ((unsigned char) op)) */ /* key = pkey; */ - kflags = (key->flags /*| (pkey->flags & KEYFLAG_RESTRICTIONS) - | uid->flags*/); - - switch (ascii_tolower (op)) + kflags = (key->flags /*| (pkey->flags & KEYFLAG_RESTRICTIONS) + | uid->flags */ ); + + switch (ascii_tolower (op)) { + case '[': { - case '[': - { - const char *cp; - char buf2[SHORT_STRING], *p; - int do_locales; - struct tm *tm; - size_t len; - - p = dest; - - cp = src; - if (*cp == '!') - { - do_locales = 0; - cp++; - } - else - do_locales = 1; - - len = destlen - 1; - while (len > 0 && *cp != ']') - { - if (*cp == '%') - { - cp++; - if (len >= 2) - { - *p++ = '%'; - *p++ = *cp; - len -= 2; - } - else - break; /* not enough space */ - cp++; - } - else - { - *p++ = *cp++; - len--; - } - } - *p = 0; - - if (do_locales && Locale) - setlocale (LC_TIME, Locale); - - { - time_t tt = 0; - - if (key->kobj->subkeys && (key->kobj->subkeys->timestamp > 0)) - tt = key->kobj->subkeys->timestamp; - - tm = localtime (&tt); - } - strftime (buf2, sizeof (buf2), dest, tm); - - if (do_locales) - setlocale (LC_TIME, "C"); - - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (dest, destlen, fmt, buf2); - if (len > 0) - src = cp + 1; - } - break; - case 'n': - if (!optional) - { - snprintf (fmt, sizeof (fmt), "%%%sd", prefix); - snprintf (dest, destlen, fmt, entry->num); - } - break; - case 'k': - if (!optional) - { - /* fixme: we need a way to distinguish between main and subkeys. - Store the idx in entry? */ - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (dest, destlen, fmt, crypt_keyid (key)); - } - break; - case 'u': - if (!optional) - { - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (dest, destlen, fmt, key->uid); - } - break; - case 'a': - if (!optional) - { - snprintf (fmt, sizeof (fmt), "%%%s.3s", prefix); - if (key->kobj->subkeys) - s = gpgme_pubkey_algo_name (key->kobj->subkeys->pubkey_algo); - else - s = "?"; - snprintf (dest, destlen, fmt, s); - } - break; - case 'l': - if (!optional) - { - snprintf (fmt, sizeof (fmt), "%%%slu", prefix); - if (key->kobj->subkeys) - val = key->kobj->subkeys->length; - else - val = 0; - snprintf (dest, destlen, fmt, val); + const char *cp; + char buf2[SHORT_STRING], *p; + int do_locales; + struct tm *tm; + size_t len; + + p = dest; + + cp = src; + if (*cp == '!') { + do_locales = 0; + cp++; } - break; - case 'f': - if (!optional) - { - snprintf (fmt, sizeof (fmt), "%%%sc", prefix); - snprintf (dest, destlen, fmt, crypt_flags (kflags)); + else + do_locales = 1; + + len = destlen - 1; + while (len > 0 && *cp != ']') { + if (*cp == '%') { + cp++; + if (len >= 2) { + *p++ = '%'; + *p++ = *cp; + len -= 2; + } + else + break; /* not enough space */ + cp++; + } + else { + *p++ = *cp++; + len--; + } } - else if (!(kflags & (KEYFLAG_RESTRICTIONS))) - optional = 0; - break; - case 'c': - if (!optional) + *p = 0; + + if (do_locales && Locale) + setlocale (LC_TIME, Locale); + { - snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (dest, destlen, fmt, crypt_key_abilities (kflags)); + time_t tt = 0; + + if (key->kobj->subkeys && (key->kobj->subkeys->timestamp > 0)) + tt = key->kobj->subkeys->timestamp; + + tm = localtime (&tt); } - else if (!(kflags & (KEYFLAG_ABILITIES))) - optional = 0; - break; - case 't': - if ((kflags & KEYFLAG_ISX509)) - s = "x"; + strftime (buf2, sizeof (buf2), dest, tm); + + if (do_locales) + setlocale (LC_TIME, "C"); + + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + snprintf (dest, destlen, fmt, buf2); + if (len > 0) + src = cp + 1; + } + break; + case 'n': + if (!optional) { + snprintf (fmt, sizeof (fmt), "%%%sd", prefix); + snprintf (dest, destlen, fmt, entry->num); + } + break; + case 'k': + if (!optional) { + /* fixme: we need a way to distinguish between main and subkeys. + Store the idx in entry? */ + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + snprintf (dest, destlen, fmt, crypt_keyid (key)); + } + break; + case 'u': + if (!optional) { + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + snprintf (dest, destlen, fmt, key->uid); + } + break; + case 'a': + if (!optional) { + snprintf (fmt, sizeof (fmt), "%%%s.3s", prefix); + if (key->kobj->subkeys) + s = gpgme_pubkey_algo_name (key->kobj->subkeys->pubkey_algo); else - { - gpgme_user_id_t uid = NULL; - unsigned int i = 0; - - for (i = 0, uid = key->kobj->uids; uid && (i < key->idx); - i++, uid = uid->next) - ; - if (uid) - switch (uid->validity) - { - case GPGME_VALIDITY_UNDEFINED: - s = "q"; - break; - case GPGME_VALIDITY_NEVER: - s = "n"; - break; - case GPGME_VALIDITY_MARGINAL: - s = "m"; - break; - case GPGME_VALIDITY_FULL: - s = "f"; - break; - case GPGME_VALIDITY_ULTIMATE: - s = "u"; - break; - case GPGME_VALIDITY_UNKNOWN: - default: - s = "?"; - break; - } - } + s = "?"; + snprintf (dest, destlen, fmt, s); + } + break; + case 'l': + if (!optional) { + snprintf (fmt, sizeof (fmt), "%%%slu", prefix); + if (key->kobj->subkeys) + val = key->kobj->subkeys->length; + else + val = 0; + snprintf (dest, destlen, fmt, val); + } + break; + case 'f': + if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sc", prefix); - snprintf (dest, destlen, fmt, s? *s: 'B'); - break; - case 'p': + snprintf (dest, destlen, fmt, crypt_flags (kflags)); + } + else if (!(kflags & (KEYFLAG_RESTRICTIONS))) + optional = 0; + break; + case 'c': + if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (dest, destlen, fmt, - gpgme_get_protocol_name (key->kobj->protocol)); - break; + snprintf (dest, destlen, fmt, crypt_key_abilities (kflags)); + } + else if (!(kflags & (KEYFLAG_ABILITIES))) + optional = 0; + break; + case 't': + if ((kflags & KEYFLAG_ISX509)) + s = "x"; + else { + gpgme_user_id_t uid = NULL; + unsigned int i = 0; + + for (i = 0, uid = key->kobj->uids; uid && (i < key->idx); + i++, uid = uid->next); + if (uid) + switch (uid->validity) { + case GPGME_VALIDITY_UNDEFINED: + s = "q"; + break; + case GPGME_VALIDITY_NEVER: + s = "n"; + break; + case GPGME_VALIDITY_MARGINAL: + s = "m"; + break; + case GPGME_VALIDITY_FULL: + s = "f"; + break; + case GPGME_VALIDITY_ULTIMATE: + s = "u"; + break; + case GPGME_VALIDITY_UNKNOWN: + default: + s = "?"; + break; + } + } + snprintf (fmt, sizeof (fmt), "%%%sc", prefix); + snprintf (dest, destlen, fmt, s ? *s : 'B'); + break; + case 'p': + snprintf (fmt, sizeof (fmt), "%%%ss", prefix); + snprintf (dest, destlen, fmt, + gpgme_get_protocol_name (key->kobj->protocol)); + break; - default: - *dest = '\0'; + default: + *dest = '\0'; } if (optional) @@ -2513,18 +2350,18 @@ static const char *crypt_entry_fmt (char *dest, mutt_FormatString (dest, destlen, elsestring, mutt_attach_fmt, data, 0); return (src); } - + /* Used by the display fucntion to format a line. */ static void crypt_entry (char *s, size_t l, MUTTMENU * menu, int num) { crypt_key_t **key_table = (crypt_key_t **) menu->data; crypt_entry_t entry; - + entry.key = key_table[num]; entry.num = num + 1; - mutt_FormatString (s, l, NONULL (PgpEntryFormat), crypt_entry_fmt, - (unsigned long) &entry, M_FORMAT_ARROWCURSOR); + mutt_FormatString (s, l, NONULL (PgpEntryFormat), crypt_entry_fmt, + (unsigned long) &entry, M_FORMAT_ARROWCURSOR); } /* Compare two addresses and the keyid to be used for sorting. */ @@ -2543,7 +2380,7 @@ static int _crypt_compare_address (const void *a, const void *b) static int crypt_compare_address (const void *a, const void *b) { return ((PgpSortKeys & SORT_REVERSE) ? !_crypt_compare_address (a, b) - : _crypt_compare_address (a, b)); + : _crypt_compare_address (a, b)); } @@ -2563,7 +2400,7 @@ static int _crypt_compare_keyid (const void *a, const void *b) static int crypt_compare_keyid (const void *a, const void *b) { return ((PgpSortKeys & SORT_REVERSE) ? !_crypt_compare_keyid (a, b) - : _crypt_compare_keyid (a, b)); + : _crypt_compare_keyid (a, b)); } /* Compare 2 creation dates and the addresses. For sorting. */ @@ -2589,7 +2426,7 @@ static int _crypt_compare_date (const void *a, const void *b) static int crypt_compare_date (const void *a, const void *b) { return ((PgpSortKeys & SORT_REVERSE) ? !_crypt_compare_date (a, b) - : _crypt_compare_date (a, b)); + : _crypt_compare_date (a, b)); } /* Compare two trust values, the key length, the creation dates. the @@ -2602,7 +2439,7 @@ static int _crypt_compare_trust (const void *a, const void *b) int r; if ((r = (((*s)->flags & (KEYFLAG_RESTRICTIONS)) - - ((*t)->flags & (KEYFLAG_RESTRICTIONS))))) + - ((*t)->flags & (KEYFLAG_RESTRICTIONS))))) return r > 0; if ((*s)->kobj->uids) @@ -2636,152 +2473,135 @@ static int _crypt_compare_trust (const void *a, const void *b) static int crypt_compare_trust (const void *a, const void *b) { return ((PgpSortKeys & SORT_REVERSE) ? !_crypt_compare_trust (a, b) - : _crypt_compare_trust (a, b)); + : _crypt_compare_trust (a, b)); } /* Print the X.500 Distinguished Name part KEY from the array of parts DN to FP. */ -static int -print_dn_part (FILE *fp, struct dn_array_s *dn, const char *key) +static int print_dn_part (FILE * fp, struct dn_array_s *dn, const char *key) { int any = 0; - for (; dn->key; dn++) - { - if (!strcmp (dn->key, key)) - { - if (any) - fputs (" + ", fp); - print_utf8 (fp, dn->value, strlen (dn->value)); - any = 1; - } + for (; dn->key; dn++) { + if (!strcmp (dn->key, key)) { + if (any) + fputs (" + ", fp); + print_utf8 (fp, dn->value, strlen (dn->value)); + any = 1; } + } return any; } /* Print all parts of a DN in a standard sequence. */ -static void -print_dn_parts (FILE *fp, struct dn_array_s *dn) +static void print_dn_parts (FILE * fp, struct dn_array_s *dn) { const char *stdpart[] = { - "CN", "OU", "O", "STREET", "L", "ST", "C", NULL + "CN", "OU", "O", "STREET", "L", "ST", "C", NULL }; - int any=0, any2=0, i; - - for (i=0; stdpart[i]; i++) - { + int any = 0, any2 = 0, i; + + for (i = 0; stdpart[i]; i++) { + if (any) + fputs (", ", fp); + any = print_dn_part (fp, dn, stdpart[i]); + } + /* now print the rest without any specific ordering */ + for (; dn->key; dn++) { + for (i = 0; stdpart[i]; i++) { + if (!strcmp (dn->key, stdpart[i])) + break; + } + if (!stdpart[i]) { if (any) fputs (", ", fp); - any = print_dn_part (fp, dn, stdpart[i]); - } - /* now print the rest without any specific ordering */ - for (; dn->key; dn++) - { - for (i=0; stdpart[i]; i++) - { - if (!strcmp (dn->key, stdpart[i])) - break; - } - if (!stdpart[i]) - { - if (any) - fputs (", ", fp); - if (!any2) - fputs ("(", fp); - any = print_dn_part (fp, dn, dn->key); - any2 = 1; - } + if (!any2) + fputs ("(", fp); + any = print_dn_part (fp, dn, dn->key); + any2 = 1; } + } if (any2) fputs (")", fp); } /* Parse an RDN; this is a helper to parse_dn(). */ -static const unsigned char * -parse_dn_part (struct dn_array_s *array, const unsigned char *string) +static const unsigned char *parse_dn_part (struct dn_array_s *array, + const unsigned char *string) { const unsigned char *s, *s1; size_t n; unsigned char *p; /* parse attributeType */ - for (s = string+1; *s && *s != '='; s++) - ; + for (s = string + 1; *s && *s != '='; s++); if (!*s) - return NULL; /* error */ + return NULL; /* error */ n = s - string; if (!n) - return NULL; /* empty key */ - array->key = safe_malloc (n+1); - p = (unsigned char *)array->key; - memcpy (p, string, n); /* fixme: trim trailing spaces */ + return NULL; /* empty key */ + array->key = safe_malloc (n + 1); + p = (unsigned char *) array->key; + memcpy (p, string, n); /* fixme: trim trailing spaces */ p[n] = 0; string = s + 1; - if (*string == '#') - { /* hexstring */ - string++; - for (s=string; hexdigitp (s); s++) + if (*string == '#') { /* hexstring */ + string++; + for (s = string; hexdigitp (s); s++) + s++; + n = s - string; + if (!n || (n & 1)) + return NULL; /* empty or odd number of digits */ + n /= 2; + p = safe_malloc (n + 1); + array->value = (char *) p; + for (s1 = string; n; s1 += 2, n--) + *p++ = xtoi_2 (s1); + *p = 0; + } + else { /* regular v3 quoted string */ + for (n = 0, s = string; *s; s++) { + if (*s == '\\') { /* pair */ s++; - n = s - string; - if (!n || (n & 1)) - return NULL; /* empty or odd number of digits */ - n /= 2; - p = safe_malloc (n+1); - array->value = (char*)p; - for (s1=string; n; s1 += 2, n--) - *p++ = xtoi_2 (s1); - *p = 0; - } - else - { /* regular v3 quoted string */ - for (n=0, s=string; *s; s++) - { - if (*s == '\\') - { /* pair */ - s++; - if (*s == ',' || *s == '=' || *s == '+' - || *s == '<' || *s == '>' || *s == '#' || *s == ';' - || *s == '\\' || *s == '\"' || *s == ' ') - n++; - else if (hexdigitp (s) && hexdigitp (s+1)) - { - s++; - n++; - } - else - return NULL; /* invalid escape sequence */ - } - else if (*s == '\"') - return NULL; /* invalid encoding */ - else if (*s == ',' || *s == '=' || *s == '+' - || *s == '<' || *s == '>' || *s == '#' || *s == ';' ) - break; - else - n++; + if (*s == ',' || *s == '=' || *s == '+' + || *s == '<' || *s == '>' || *s == '#' || *s == ';' + || *s == '\\' || *s == '\"' || *s == ' ') + n++; + else if (hexdigitp (s) && hexdigitp (s + 1)) { + s++; + n++; } + else + return NULL; /* invalid escape sequence */ + } + else if (*s == '\"') + return NULL; /* invalid encoding */ + else if (*s == ',' || *s == '=' || *s == '+' + || *s == '<' || *s == '>' || *s == '#' || *s == ';') + break; + else + n++; + } - p = safe_malloc (n+1); - array->value = (char*)p; - for (s=string; n; s++, n--) - { - if (*s == '\\') - { - s++; - if (hexdigitp (s)) - { - *p++ = xtoi_2 (s); - s++; - } - else - *p++ = *s; - } - else - *p++ = *s; + p = safe_malloc (n + 1); + array->value = (char *) p; + for (s = string; n; s++, n--) { + if (*s == '\\') { + s++; + if (hexdigitp (s)) { + *p++ = xtoi_2 (s); + s++; } - *p = 0; + else + *p++ = *s; + } + else + *p++ = *s; } + *p = 0; + } return s; } @@ -2789,59 +2609,54 @@ parse_dn_part (struct dn_array_s *array, const unsigned char *string) /* Parse a DN and return an array-ized one. This is not a validating parser and it does not support any old-stylish syntax; gpgme is expected to return only rfc2253 compatible strings. */ -static struct dn_array_s * -parse_dn (const unsigned char *string) +static struct dn_array_s *parse_dn (const unsigned char *string) { struct dn_array_s *array; size_t arrayidx, arraysize; int i; - arraysize = 7; /* C,ST,L,O,OU,CN,email */ - array = safe_malloc ((arraysize+1) * sizeof *array); + arraysize = 7; /* C,ST,L,O,OU,CN,email */ + array = safe_malloc ((arraysize + 1) * sizeof *array); arrayidx = 0; - while (*string) - { - while (*string == ' ') - string++; - if (!*string) - break; /* ready */ - if (arrayidx >= arraysize) - { /* mutt lacks a real safe_realoc - so we need to copy */ - struct dn_array_s *a2; - - arraysize += 5; - a2 = safe_malloc ((arraysize+1) * sizeof *array); - for (i=0; i < arrayidx; i++) - { - a2[i].key = array[i].key; - a2[i].value = array[i].value; - } - FREE (&array); - array = a2; - } - array[arrayidx].key = NULL; - array[arrayidx].value = NULL; - string = parse_dn_part (array+arrayidx, string); - arrayidx++; - if (!string) - goto failure; - while (*string == ' ') - string++; - if (*string && *string != ',' && *string != ';' && *string != '+') - goto failure; /* invalid delimiter */ - if (*string) - string++; - } + while (*string) { + while (*string == ' ') + string++; + if (!*string) + break; /* ready */ + if (arrayidx >= arraysize) { /* mutt lacks a real safe_realoc - so we need to copy */ + struct dn_array_s *a2; + + arraysize += 5; + a2 = safe_malloc ((arraysize + 1) * sizeof *array); + for (i = 0; i < arrayidx; i++) { + a2[i].key = array[i].key; + a2[i].value = array[i].value; + } + FREE (&array); + array = a2; + } + array[arrayidx].key = NULL; + array[arrayidx].value = NULL; + string = parse_dn_part (array + arrayidx, string); + arrayidx++; + if (!string) + goto failure; + while (*string == ' ') + string++; + if (*string && *string != ',' && *string != ';' && *string != '+') + goto failure; /* invalid delimiter */ + if (*string) + string++; + } array[arrayidx].key = NULL; array[arrayidx].value = NULL; return array; - failure: - for (i=0; i < arrayidx; i++) - { - FREE (&array[i].key); - FREE (&array[i].value); - } +failure: + for (i = 0; i < arrayidx; i++) { + FREE (&array[i].key); + FREE (&array[i].value); + } FREE (&array); return NULL; } @@ -2851,82 +2666,74 @@ parse_dn (const unsigned char *string) displayed in a proper way, which does mean to reorder some parts for S/MIME's DNs. USERID is a string as returned by the gpgme key functions. It is utf-8 encoded. */ -static void -parse_and_print_user_id (FILE *fp, const char *userid) +static void parse_and_print_user_id (FILE * fp, const char *userid) { const char *s; int i; - if (*userid == '<') - { - s = strchr (userid+1, '>'); - if (s) - print_utf8 (fp, userid+1, s-userid-1); - } + if (*userid == '<') { + s = strchr (userid + 1, '>'); + if (s) + print_utf8 (fp, userid + 1, s - userid - 1); + } else if (*userid == '(') fputs (_("[Can't display this user ID (unknown encoding)]"), fp); - else if (!digit_or_letter ((const unsigned char *)userid)) + else if (!digit_or_letter ((const unsigned char *) userid)) fputs (_("[Can't display this user ID (invalid encoding)]"), fp); - else - { - struct dn_array_s *dn = parse_dn ((const unsigned char *)userid); - if (!dn) - fputs (_("[Can't display this user ID (invalid DN)]"), fp); - else - { - print_dn_parts (fp, dn); - for (i=0; dn[i].key; i++) - { - FREE (&dn[i].key); - FREE (&dn[i].value); - } - FREE (&dn); - } + else { + struct dn_array_s *dn = parse_dn ((const unsigned char *) userid); + + if (!dn) + fputs (_("[Can't display this user ID (invalid DN)]"), fp); + else { + print_dn_parts (fp, dn); + for (i = 0; dn[i].key; i++) { + FREE (&dn[i].key); + FREE (&dn[i].value); + } + FREE (&dn); } + } } -typedef enum - { - KEY_CAP_CAN_ENCRYPT, - KEY_CAP_CAN_SIGN, - KEY_CAP_CAN_CERTIFY - } -key_cap_t; +typedef enum { + KEY_CAP_CAN_ENCRYPT, + KEY_CAP_CAN_SIGN, + KEY_CAP_CAN_CERTIFY +} key_cap_t; -static unsigned int -key_check_cap (gpgme_key_t key, key_cap_t cap) +static unsigned int key_check_cap (gpgme_key_t key, key_cap_t cap) { gpgme_subkey_t subkey = NULL; unsigned int ret = 0; - switch (cap) - { - case KEY_CAP_CAN_ENCRYPT: - if (! (ret = key->can_encrypt)) - for (subkey = key->subkeys; subkey; subkey = subkey->next) - if ((ret = subkey->can_encrypt)) - break; - break; - case KEY_CAP_CAN_SIGN: - if (! (ret = key->can_sign)) - for (subkey = key->subkeys; subkey; subkey = subkey->next) - if ((ret = subkey->can_sign)) - break; - break; - case KEY_CAP_CAN_CERTIFY: - if (! (ret = key->can_certify)) - for (subkey = key->subkeys; subkey; subkey = subkey->next) - if ((ret = subkey->can_certify)) - break; - break; - } + switch (cap) { + case KEY_CAP_CAN_ENCRYPT: + if (!(ret = key->can_encrypt)) + for (subkey = key->subkeys; subkey; subkey = subkey->next) + if ((ret = subkey->can_encrypt)) + break; + break; + case KEY_CAP_CAN_SIGN: + if (!(ret = key->can_sign)) + for (subkey = key->subkeys; subkey; subkey = subkey->next) + if ((ret = subkey->can_sign)) + break; + break; + case KEY_CAP_CAN_CERTIFY: + if (!(ret = key->can_certify)) + for (subkey = key->subkeys; subkey; subkey = subkey->next) + if ((ret = subkey->can_certify)) + break; + break; + } return ret; } /* Print verbose information about a key or certificate to FP. */ -static void print_key_info (gpgme_key_t key, FILE *fp) +static void print_key_info (gpgme_key_t key, FILE * fp) { int idx; const char *s = NULL, *s2 = NULL; @@ -2944,50 +2751,46 @@ static void print_key_info (gpgme_key_t key, FILE *fp) is_pgp = key->protocol == GPGME_PROTOCOL_OpenPGP; - for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) - { - if (uid->revoked) - continue; + for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { + if (uid->revoked) + continue; - s = uid->uid; - fprintf (fp, "%s ......: ", idx ? _(" aka") :_("Name")); - if (uid->invalid) - { - fputs (_("[Invalid]"), fp); - putc (' ', fp); - } - if (is_pgp) - print_utf8 (fp, s, strlen(s)); - else - parse_and_print_user_id (fp, s); - putc ('\n', fp); + s = uid->uid; + fprintf (fp, "%s ......: ", idx ? _(" aka") : _("Name")); + if (uid->invalid) { + fputs (_("[Invalid]"), fp); + putc (' ', fp); } + if (is_pgp) + print_utf8 (fp, s, strlen (s)); + else + parse_and_print_user_id (fp, s); + putc ('\n', fp); + } - if (key->subkeys && (key->subkeys->timestamp > 0)) - { - tt = key->subkeys->timestamp; + if (key->subkeys && (key->subkeys->timestamp > 0)) { + tt = key->subkeys->timestamp; - tm = localtime (&tt); + tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - fprintf (fp, "Valid From : %s\n", shortbuf); - } - - if (key->subkeys && (key->subkeys->expires > 0)) - { - tt = key->subkeys->expires; - - tm = localtime (&tt); + fprintf (fp, "Valid From : %s\n", shortbuf); + } + + if (key->subkeys && (key->subkeys->expires > 0)) { + tt = key->subkeys->expires; + + tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - fprintf (fp, "Valid To ..: %s\n", shortbuf); - } + fprintf (fp, "Valid To ..: %s\n", shortbuf); + } if (key->subkeys) s = gpgme_pubkey_algo_name (key->subkeys->pubkey_algo); @@ -3004,167 +2807,144 @@ static void print_key_info (gpgme_key_t key, FILE *fp) fprintf (fp, "Key Usage .: "); delim = ""; - if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) - { - fprintf (fp, "%s%s", delim, _("encryption")); - delim = ", "; - } - if (key_check_cap (key, KEY_CAP_CAN_SIGN)) - { - fprintf (fp, "%s%s", delim, _("signing")); - delim = ", "; - } - if (key_check_cap (key, KEY_CAP_CAN_CERTIFY)) - { - fprintf (fp, "%s%s", delim, _("certification")); - delim = ", "; - } + if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) { + fprintf (fp, "%s%s", delim, _("encryption")); + delim = ", "; + } + if (key_check_cap (key, KEY_CAP_CAN_SIGN)) { + fprintf (fp, "%s%s", delim, _("signing")); + delim = ", "; + } + if (key_check_cap (key, KEY_CAP_CAN_CERTIFY)) { + fprintf (fp, "%s%s", delim, _("certification")); + delim = ", "; + } putc ('\n', fp); - if (key->subkeys) - { - s = key->subkeys->fpr; - fputs (_("Fingerprint: "), fp); - if (is_pgp && strlen (s) == 40) - { - for (i=0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) - { - putc (*s, fp); - putc (s[1], fp); - putc (s[2], fp); - putc (s[3], fp); - putc (is_pgp? ' ':':', fp); - if (is_pgp && i == 4) - putc (' ', fp); - } - } - else - { - for (i=0; *s && s[1] && s[2]; s += 2, i++) - { - putc (*s, fp); - putc (s[1], fp); - putc (is_pgp? ' ':':', fp); - if (is_pgp && i == 7) - putc (' ', fp); - } - } - fprintf (fp, "%s\n", s); + if (key->subkeys) { + s = key->subkeys->fpr; + fputs (_("Fingerprint: "), fp); + if (is_pgp && strlen (s) == 40) { + for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) { + putc (*s, fp); + putc (s[1], fp); + putc (s[2], fp); + putc (s[3], fp); + putc (is_pgp ? ' ' : ':', fp); + if (is_pgp && i == 4) + putc (' ', fp); + } } - - if (key->issuer_serial) - { - s = key->issuer_serial; - if (s) - fprintf (fp, "Serial-No .: 0x%s\n", s); + else { + for (i = 0; *s && s[1] && s[2]; s += 2, i++) { + putc (*s, fp); + putc (s[1], fp); + putc (is_pgp ? ' ' : ':', fp); + if (is_pgp && i == 7) + putc (' ', fp); + } } + fprintf (fp, "%s\n", s); + } - if (key->issuer_name) - { - s = key->issuer_name; - if (s) - { - fprintf (fp, "Issued By .: "); - parse_and_print_user_id (fp, s); - putc ('\n', fp); - } + if (key->issuer_serial) { + s = key->issuer_serial; + if (s) + fprintf (fp, "Serial-No .: 0x%s\n", s); + } + + if (key->issuer_name) { + s = key->issuer_name; + if (s) { + fprintf (fp, "Issued By .: "); + parse_and_print_user_id (fp, s); + putc ('\n', fp); } + } /* For PGP we list all subkeys. */ - if (is_pgp) - { - gpgme_subkey_t subkey = NULL; - - for (idx = 1, subkey = key->subkeys; subkey; - idx++, subkey = subkey->next) - { - s = subkey->keyid; - - putc ('\n', fp); - if ( strlen (s) == 16) - s += 8; /* display only the short keyID */ - fprintf (fp, "Subkey ....: 0x%s", s); - if (subkey->revoked) - { - putc (' ', fp); - fputs (_("[Revoked]"), fp); - } - if (subkey->invalid) - { - putc (' ', fp); - fputs (_("[Invalid]"), fp); - } - if (subkey->expired) - { - putc (' ', fp); - fputs (_("[Expired]"), fp); - } - if (subkey->disabled) - { - putc (' ', fp); - fputs (_("[Disabled]"), fp); - } - putc ('\n', fp); + if (is_pgp) { + gpgme_subkey_t subkey = NULL; + + for (idx = 1, subkey = key->subkeys; subkey; idx++, subkey = subkey->next) { + s = subkey->keyid; + + putc ('\n', fp); + if (strlen (s) == 16) + s += 8; /* display only the short keyID */ + fprintf (fp, "Subkey ....: 0x%s", s); + if (subkey->revoked) { + putc (' ', fp); + fputs (_("[Revoked]"), fp); + } + if (subkey->invalid) { + putc (' ', fp); + fputs (_("[Invalid]"), fp); + } + if (subkey->expired) { + putc (' ', fp); + fputs (_("[Expired]"), fp); + } + if (subkey->disabled) { + putc (' ', fp); + fputs (_("[Disabled]"), fp); + } + putc ('\n', fp); - if (subkey->timestamp > 0) - { - tt = subkey->timestamp; + if (subkey->timestamp > 0) { + tt = subkey->timestamp; - tm = localtime (&tt); + tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - fprintf (fp, "Valid From : %s\n", shortbuf); - } + fprintf (fp, "Valid From : %s\n", shortbuf); + } - if (subkey->expires > 0) - { - tt = subkey->expires; + if (subkey->expires > 0) { + tt = subkey->expires; - tm = localtime (&tt); + tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof shortbuf, "%c", tm); #endif - fprintf (fp, "Valid To ..: %s\n", shortbuf); - } + fprintf (fp, "Valid To ..: %s\n", shortbuf); + } - if (subkey) - s = gpgme_pubkey_algo_name (subkey->pubkey_algo); - else - s = "?"; + if (subkey) + s = gpgme_pubkey_algo_name (subkey->pubkey_algo); + else + s = "?"; - if (subkey) - aval = subkey->length; - else - aval = 0; + if (subkey) + aval = subkey->length; + else + aval = 0; - fprintf (fp, "Key Type ..: %s, %lu bit %s\n", "PGP", aval, s); + fprintf (fp, "Key Type ..: %s, %lu bit %s\n", "PGP", aval, s); - fprintf (fp, "Key Usage .: "); - delim = ""; + fprintf (fp, "Key Usage .: "); + delim = ""; - if (subkey->can_encrypt) - { - fprintf (fp, "%s%s", delim, _("encryption")); - delim = ", "; - } - if (subkey->can_sign) - { - fprintf (fp, "%s%s", delim, _("signing")); - delim = ", "; - } - if (subkey->can_certify) - { - fprintf (fp, "%s%s", delim, _("certification")); - delim = ", "; - } - putc ('\n', fp); - } + if (subkey->can_encrypt) { + fprintf (fp, "%s%s", delim, _("encryption")); + delim = ", "; + } + if (subkey->can_sign) { + fprintf (fp, "%s%s", delim, _("signing")); + delim = ", "; + } + if (subkey->can_certify) { + fprintf (fp, "%s%s", delim, _("certification")); + delim = ", "; + } + putc ('\n', fp); } + } if (Locale) setlocale (LC_TIME, "C"); @@ -3172,8 +2952,7 @@ static void print_key_info (gpgme_key_t key, FILE *fp) /* Show detailed information about the selected key */ -static void -verify_key (crypt_key_t *key) +static void verify_key (crypt_key_t * key) { FILE *fp; char cmd[LONG_STRING], tempfile[_POSIX_PATH_MAX]; @@ -3184,59 +2963,53 @@ verify_key (crypt_key_t *key) int maxdepth = 100; mutt_mktemp (tempfile); - if (!(fp = safe_fopen (tempfile, "w"))) - { - mutt_perror _("Can't create temporary file"); - return; - } + if (!(fp = safe_fopen (tempfile, "w"))) { + mutt_perror _("Can't create temporary file"); + + return; + } mutt_message _("Collecting data..."); print_key_info (key->kobj, fp); err = gpgme_new (&listctx); - if (err) - { - fprintf (fp, "Internal error: can't create gpgme context: %s\n", - gpgme_strerror (err)); - goto leave; - } + if (err) { + fprintf (fp, "Internal error: can't create gpgme context: %s\n", + gpgme_strerror (err)); + goto leave; + } if ((key->flags & KEYFLAG_ISX509)) - gpgme_set_protocol (listctx, GPGME_PROTOCOL_CMS); + gpgme_set_protocol (listctx, GPGME_PROTOCOL_CMS); k = key->kobj; gpgme_key_ref (k); - while ((s = k->chain_id) && k->subkeys && strcmp (s, k->subkeys->fpr) ) - { - putc ('\n', fp); - err = gpgme_op_keylist_start (listctx, s, 0); - gpgme_key_release (k); - k = NULL; - if (!err) - err = gpgme_op_keylist_next (listctx, &k); - if (err) - { - fprintf (fp, _("Error finding issuer key: %s\n"), - gpgme_strerror (err)); - goto leave; - } - gpgme_op_keylist_end (listctx); - - print_key_info (k, fp); - if (!--maxdepth) - { - putc ('\n', fp); - fputs (_("Error: certification chain to long - stopping here\n"), - fp); - break; - } + while ((s = k->chain_id) && k->subkeys && strcmp (s, k->subkeys->fpr)) { + putc ('\n', fp); + err = gpgme_op_keylist_start (listctx, s, 0); + gpgme_key_release (k); + k = NULL; + if (!err) + err = gpgme_op_keylist_next (listctx, &k); + if (err) { + fprintf (fp, _("Error finding issuer key: %s\n"), gpgme_strerror (err)); + goto leave; + } + gpgme_op_keylist_end (listctx); + + print_key_info (k, fp); + if (!--maxdepth) { + putc ('\n', fp); + fputs (_("Error: certification chain to long - stopping here\n"), fp); + break; } + } - leave: +leave: gpgme_key_release (k); gpgme_release (listctx); fclose (fp); mutt_clear_error (); - snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), crypt_keyid (key)); + snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), crypt_keyid (key)); mutt_do_pager (cmd, tempfile, 0, NULL); } @@ -3248,7 +3021,7 @@ verify_key (crypt_key_t *key) /* Convert LIST into a pattern string suitable to be passed to GPGME. We need to convert spaces in an item into a '+' and '%' into "%25". */ -static char *list_to_pattern (LIST *list) +static char *list_to_pattern (LIST * list) { LIST *l; char *pattern, *p; @@ -3256,53 +3029,47 @@ static char *list_to_pattern (LIST *list) size_t n; n = 0; - for(l=list; l; l = l->next) - { - for(s = l->data; *s; s++) - { - if (*s == '%') - n += 2; - n++; - } - n++; /* delimiter or end of string */ + for (l = list; l; l = l->next) { + for (s = l->data; *s; s++) { + if (*s == '%') + n += 2; + n++; } - n++; /* make sure to allocate at least one byte */ - pattern = p = safe_calloc (1,n); - for(l=list; l; l = l->next) - { - s = l->data; - if (*s) - { - if (l != list) - *p++ = ' '; - for(s = l->data; *s; s++) - { - if (*s == '%') - { - *p++ = '%'; - *p++ = '2'; - *p++ = '5'; - } - else if (*s == '+') - { - *p++ = '%'; - *p++ = '2'; - *p++ = 'B'; - } - else if (*s == ' ') - *p++ = '+'; - else - *p++ = *s; - } + n++; /* delimiter or end of string */ + } + n++; /* make sure to allocate at least one byte */ + pattern = p = safe_calloc (1, n); + for (l = list; l; l = l->next) { + s = l->data; + if (*s) { + if (l != list) + *p++ = ' '; + for (s = l->data; *s; s++) { + if (*s == '%') { + *p++ = '%'; + *p++ = '2'; + *p++ = '5'; + } + else if (*s == '+') { + *p++ = '%'; + *p++ = '2'; + *p++ = 'B'; } + else if (*s == ' ') + *p++ = '+'; + else + *p++ = *s; + } } + } *p = 0; return pattern; } /* Return a list of keys which are candidates for the selection. Select by looking at the HINTS list. */ -static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) +static crypt_key_t *get_candidates (LIST * hints, unsigned int app, + int secret) { crypt_key_t *db, *k, **kend; char *pattern; @@ -3315,143 +3082,128 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) pattern = list_to_pattern (hints); if (!pattern) return NULL; - + err = gpgme_new (&ctx); - if (err) - { - mutt_error ("gpgme_new failed: %s", gpgme_strerror (err)); + if (err) { + mutt_error ("gpgme_new failed: %s", gpgme_strerror (err)); + FREE (&pattern); + return NULL; + } + + db = NULL; + kend = &db; + + if ((app & APPLICATION_PGP)) { + /* Its all a mess. That old GPGME expects different things + depending on the protocol. For gpg we don' t need percent + escaped pappert but simple strings passed in an array to the + keylist_ext_start function. */ + LIST *l; + size_t n; + char **patarr; + + for (l = hints, n = 0; l; l = l->next) { + if (l->data && *l->data) + n++; + } + if (!n) + goto no_pgphints; + + patarr = safe_calloc (n + 1, sizeof *patarr); + for (l = hints, n = 0; l; l = l->next) { + if (l->data && *l->data) + patarr[n++] = safe_strdup (l->data); + } + patarr[n] = NULL; + err = gpgme_op_keylist_ext_start (ctx, (const char **) patarr, secret, 0); + for (n = 0; patarr[n]; n++) + FREE (&patarr[n]); + FREE (&patarr); + if (err) { + mutt_error ("gpgme_op_keylist_start failed: %s", gpgme_strerror (err)); + gpgme_release (ctx); FREE (&pattern); return NULL; } - db = NULL; - kend = &db; - - if ((app & APPLICATION_PGP)) - { - /* Its all a mess. That old GPGME expects different things - depending on the protocol. For gpg we don' t need percent - escaped pappert but simple strings passed in an array to the - keylist_ext_start function. */ - LIST *l; - size_t n; - char **patarr; - - for(l=hints, n=0; l; l = l->next) - { - if (l->data && *l->data) - n++; - } - if (!n) - goto no_pgphints; - - patarr = safe_calloc (n+1, sizeof *patarr); - for(l=hints, n=0; l; l = l->next) - { - if (l->data && *l->data) - patarr[n++] = safe_strdup (l->data); - } - patarr[n] = NULL; - err = gpgme_op_keylist_ext_start (ctx, (const char**)patarr, secret, 0); - for (n=0; patarr[n]; n++) - FREE (&patarr[n]); - FREE (&patarr); - if (err) - { - mutt_error ("gpgme_op_keylist_start failed: %s", - gpgme_strerror (err)); - gpgme_release (ctx); - FREE (&pattern); - return NULL; - } + while (!(err = gpgme_op_keylist_next (ctx, &key))) { + unsigned int flags = 0; - while (!(err = gpgme_op_keylist_next (ctx, &key)) ) - { - unsigned int flags = 0; - - if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) - flags |= KEYFLAG_CANENCRYPT; - if (key_check_cap (key, KEY_CAP_CAN_SIGN)) - flags |= KEYFLAG_CANSIGN; - -#if 0 /* DISABLED code */ - if (!flags) - { - /* Bug in gpg. Capabilities are not listed for secret - keys. Try to deduce them from the algorithm. */ - - switch (key->subkeys[0].pubkey_algo) - { - case GPGME_PK_RSA: - flags |= KEYFLAG_CANENCRYPT; - flags |= KEYFLAG_CANSIGN; - break; - case GPGME_PK_ELG_E: - flags |= KEYFLAG_CANENCRYPT; - break; - case GPGME_PK_DSA: - flags |= KEYFLAG_CANSIGN; - break; - } - } -#endif /* DISABLED code */ + if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) + flags |= KEYFLAG_CANENCRYPT; + if (key_check_cap (key, KEY_CAP_CAN_SIGN)) + flags |= KEYFLAG_CANSIGN; - for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) - { - k = safe_calloc (1, sizeof *k); - k->kobj = key; - k->idx = idx; - k->uid = uid->uid; - k->flags = flags; - *kend = k; - kend = &k->next; - } +#if 0 /* DISABLED code */ + if (!flags) { + /* Bug in gpg. Capabilities are not listed for secret + keys. Try to deduce them from the algorithm. */ + + switch (key->subkeys[0].pubkey_algo) { + case GPGME_PK_RSA: + flags |= KEYFLAG_CANENCRYPT; + flags |= KEYFLAG_CANSIGN; + break; + case GPGME_PK_ELG_E: + flags |= KEYFLAG_CANENCRYPT; + break; + case GPGME_PK_DSA: + flags |= KEYFLAG_CANSIGN; + break; } - if (gpg_err_code (err) != GPG_ERR_EOF) - mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err)); - gpgme_op_keylist_end (ctx); - no_pgphints: - ; + } +#endif /* DISABLED code */ + + for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { + k = safe_calloc (1, sizeof *k); + k->kobj = key; + k->idx = idx; + k->uid = uid->uid; + k->flags = flags; + *kend = k; + kend = &k->next; + } } + if (gpg_err_code (err) != GPG_ERR_EOF) + mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err)); + gpgme_op_keylist_end (ctx); + no_pgphints: + ; + } - if ((app & APPLICATION_SMIME)) - { - /* and now look for x509 certificates */ - gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); - err = gpgme_op_keylist_start (ctx, pattern, 0); - if (err) - { - mutt_error ("gpgme_op_keylist_start failed: %s", - gpgme_strerror (err)); - gpgme_release (ctx); - FREE (&pattern); - return NULL; - } + if ((app & APPLICATION_SMIME)) { + /* and now look for x509 certificates */ + gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); + err = gpgme_op_keylist_start (ctx, pattern, 0); + if (err) { + mutt_error ("gpgme_op_keylist_start failed: %s", gpgme_strerror (err)); + gpgme_release (ctx); + FREE (&pattern); + return NULL; + } - while (!(err = gpgme_op_keylist_next (ctx, &key)) ) - { - unsigned int flags = KEYFLAG_ISX509; - - if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) - flags |= KEYFLAG_CANENCRYPT; - if (key_check_cap (key, KEY_CAP_CAN_SIGN)) - flags |= KEYFLAG_CANSIGN; - - for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) - { - k = safe_calloc (1, sizeof *k); - k->kobj = key; - k->idx = idx; - k->uid = uid->uid; - k->flags = flags; - *kend = k; - kend = &k->next; - } - } - if (gpg_err_code (err) != GPG_ERR_EOF) - mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err)); - gpgme_op_keylist_end (ctx); + while (!(err = gpgme_op_keylist_next (ctx, &key))) { + unsigned int flags = KEYFLAG_ISX509; + + if (key_check_cap (key, KEY_CAP_CAN_ENCRYPT)) + flags |= KEYFLAG_CANENCRYPT; + if (key_check_cap (key, KEY_CAP_CAN_SIGN)) + flags |= KEYFLAG_CANSIGN; + + for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { + k = safe_calloc (1, sizeof *k); + k->kobj = key; + k->idx = idx; + k->uid = uid->uid; + k->flags = flags; + *kend = k; + kend = &k->next; + } } + if (gpg_err_code (err) != GPG_ERR_EOF) + mutt_error ("gpgme_op_keylist_next failed: %s", gpgme_strerror (err)); + gpgme_op_keylist_end (ctx); + } gpgme_release (ctx); FREE (&pattern); @@ -3460,7 +3212,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) /* Add the string STR to the list HINTS. This list is later used to match addresses. */ -static LIST *crypt_add_string_to_hints (LIST *hints, const char *str) +static LIST *crypt_add_string_to_hints (LIST * hints, const char *str) { char *scratch; char *t; @@ -3469,12 +3221,11 @@ static LIST *crypt_add_string_to_hints (LIST *hints, const char *str) return hints; for (t = strtok (scratch, " ,.:\"()<>\n"); t; - t = strtok (NULL, " ,.:\"()<>\n")) - { - if (strlen (t) > 3) - hints = mutt_add_list (hints, t); - } - + t = strtok (NULL, " ,.:\"()<>\n")) { + if (strlen (t) > 3) + hints = mutt_add_list (hints, t); + } + FREE (&scratch); return hints; } @@ -3482,8 +3233,8 @@ static LIST *crypt_add_string_to_hints (LIST *hints, const char *str) /* Display a menu to select a key from the array KEYS. FORCED_VALID will be set to true on return if the user did override the the key's validity. */ -static crypt_key_t *crypt_select_key (crypt_key_t *keys, - ADDRESS * p, const char *s, +static crypt_key_t *crypt_select_key (crypt_key_t * keys, + ADDRESS * p, const char *s, unsigned int app, int *forced_valid) { int keymax; @@ -3501,47 +3252,43 @@ static crypt_key_t *crypt_select_key (crypt_key_t *keys, /* build the key table */ keymax = i = 0; key_table = NULL; - for (k = keys; k; k = k->next) - { - if (!option (OPTPGPSHOWUNUSABLE) && (k->flags & KEYFLAG_CANTUSE)) - { - unusable = 1; - continue; - } - - if (i == keymax) - { - keymax += 20; - safe_realloc (&key_table, sizeof (crypt_key_t*)*keymax); - } - - key_table[i++] = k; + for (k = keys; k; k = k->next) { + if (!option (OPTPGPSHOWUNUSABLE) && (k->flags & KEYFLAG_CANTUSE)) { + unusable = 1; + continue; } - if (!i && unusable) - { - mutt_error _("All matching keys are marked expired/revoked."); - mutt_sleep (1); - return NULL; + if (i == keymax) { + keymax += 20; + safe_realloc (&key_table, sizeof (crypt_key_t *) * keymax); } - switch (PgpSortKeys & SORT_MASK) - { - case SORT_DATE: - f = crypt_compare_date; - break; - case SORT_KEYID: - f = crypt_compare_keyid; - break; - case SORT_ADDRESS: - f = crypt_compare_address; - break; - case SORT_TRUST: - default: - f = crypt_compare_trust; - break; + key_table[i++] = k; } - qsort (key_table, i, sizeof (crypt_key_t*), f); + + if (!i && unusable) { + mutt_error _("All matching keys are marked expired/revoked."); + + mutt_sleep (1); + return NULL; + } + + switch (PgpSortKeys & SORT_MASK) { + case SORT_DATE: + f = crypt_compare_date; + break; + case SORT_KEYID: + f = crypt_compare_keyid; + break; + case SORT_ADDRESS: + f = crypt_compare_address; + break; + case SORT_TRUST: + default: + f = crypt_compare_trust; + break; + } + qsort (key_table, i, sizeof (crypt_key_t *), f); if (app & APPLICATION_PGP) menu_to_use = MENU_KEY_SELECT_PGP; @@ -3550,15 +3297,15 @@ static crypt_key_t *crypt_select_key (crypt_key_t *keys, helpstr[0] = 0; mutt_make_help (buf, sizeof (buf), _("Exit "), menu_to_use, OP_EXIT); - strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ + strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ mutt_make_help (buf, sizeof (buf), _("Select "), menu_to_use, - OP_GENERIC_SELECT_ENTRY); - strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ + OP_GENERIC_SELECT_ENTRY); + strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ mutt_make_help (buf, sizeof (buf), _("Check key "), menu_to_use, OP_VERIFY_KEY); - strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ + strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ mutt_make_help (buf, sizeof (buf), _("Help"), menu_to_use, OP_HELP); - strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ + strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ menu = mutt_new_menu (); menu->max = i; @@ -3570,7 +3317,7 @@ static crypt_key_t *crypt_select_key (crypt_key_t *keys, { const char *ts; - if ((app & APPLICATION_PGP) && (app & APPLICATION_SMIME)) + if ((app & APPLICATION_PGP) && (app & APPLICATION_SMIME)) ts = _("PGP and S/MIME keys matching"); else if ((app & APPLICATION_PGP)) ts = _("PGP keys matching"); @@ -3583,120 +3330,110 @@ static crypt_key_t *crypt_select_key (crypt_key_t *keys, snprintf (buf, sizeof (buf), _("%s <%s>."), ts, p->mailbox); else snprintf (buf, sizeof (buf), _("%s \"%s\"."), ts, s); - menu->title = buf; + menu->title = buf; } mutt_clear_error (); k = NULL; - while (!done) - { - *forced_valid = 0; - switch (mutt_menuLoop (menu)) - { - case OP_VERIFY_KEY: - verify_key (key_table[menu->current]); - menu->redraw = REDRAW_FULL; - break; - - case OP_VIEW_ID: - mutt_message ("%s", key_table[menu->current]->uid); - break; - - case OP_GENERIC_SELECT_ENTRY: - /* FIXME make error reporting more verbose - this should be - easy because gpgme provides more information */ - if (option (OPTPGPCHECKTRUST)) - { - if (!crypt_key_is_valid (key_table[menu->current])) - { - mutt_error _("This key can't be used: " - "expired/disabled/revoked."); - break; - } - } - - if (option (OPTPGPCHECKTRUST) && - (!crypt_id_is_valid (key_table[menu->current]) - || !crypt_id_is_strong (key_table[menu->current]))) - { - const char *warn_s; - char buff[LONG_STRING]; - - if (key_table[menu->current]->flags & KEYFLAG_CANTUSE) - s = N_("ID is expired/disabled/revoked."); - else - { - gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN; - gpgme_user_id_t uid = NULL; - unsigned int j = 0; - - warn_s = "??"; - - uid = key_table[menu->current]->kobj->uids; - for (j = 0; (j < key_table[menu->current]->idx) && uid; - j++, uid = uid->next) - ; - if (uid) - val = uid->validity; - - switch (val) - { - case GPGME_VALIDITY_UNKNOWN: - case GPGME_VALIDITY_UNDEFINED: - warn_s = N_("ID has undefined validity."); - break; - case GPGME_VALIDITY_NEVER: - warn_s = N_("ID is not valid."); - break; - case GPGME_VALIDITY_MARGINAL: - warn_s = N_("ID is only marginally valid."); - break; - case GPGME_VALIDITY_FULL: - case GPGME_VALIDITY_ULTIMATE: - break; - } - - snprintf (buff, sizeof (buff), - _("%s Do you really want to use the key?"), - _(warn_s)); - - if (mutt_yesorno (buff, 0) != 1) - { - mutt_clear_error (); - break; - } - *forced_valid = 1; - } - } - - k = crypt_copy_key (key_table[menu->current]); - done = 1; - break; - - case OP_EXIT: - k = NULL; - done = 1; + while (!done) { + *forced_valid = 0; + switch (mutt_menuLoop (menu)) { + case OP_VERIFY_KEY: + verify_key (key_table[menu->current]); + menu->redraw = REDRAW_FULL; + break; + + case OP_VIEW_ID: + mutt_message ("%s", key_table[menu->current]->uid); + break; + + case OP_GENERIC_SELECT_ENTRY: + /* FIXME make error reporting more verbose - this should be + easy because gpgme provides more information */ + if (option (OPTPGPCHECKTRUST)) { + if (!crypt_key_is_valid (key_table[menu->current])) { + mutt_error _("This key can't be used: " + "expired/disabled/revoked."); break; } + } + + if (option (OPTPGPCHECKTRUST) && + (!crypt_id_is_valid (key_table[menu->current]) + || !crypt_id_is_strong (key_table[menu->current]))) { + const char *warn_s; + char buff[LONG_STRING]; + + if (key_table[menu->current]->flags & KEYFLAG_CANTUSE) + s = N_("ID is expired/disabled/revoked."); + else { + gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN; + gpgme_user_id_t uid = NULL; + unsigned int j = 0; + + warn_s = "??"; + + uid = key_table[menu->current]->kobj->uids; + for (j = 0; (j < key_table[menu->current]->idx) && uid; + j++, uid = uid->next); + if (uid) + val = uid->validity; + + switch (val) { + case GPGME_VALIDITY_UNKNOWN: + case GPGME_VALIDITY_UNDEFINED: + warn_s = N_("ID has undefined validity."); + break; + case GPGME_VALIDITY_NEVER: + warn_s = N_("ID is not valid."); + break; + case GPGME_VALIDITY_MARGINAL: + warn_s = N_("ID is only marginally valid."); + break; + case GPGME_VALIDITY_FULL: + case GPGME_VALIDITY_ULTIMATE: + break; + } + + snprintf (buff, sizeof (buff), + _("%s Do you really want to use the key?"), _(warn_s)); + + if (mutt_yesorno (buff, 0) != 1) { + mutt_clear_error (); + break; + } + *forced_valid = 1; + } + } + + k = crypt_copy_key (key_table[menu->current]); + done = 1; + break; + + case OP_EXIT: + k = NULL; + done = 1; + break; } - + } + mutt_menuDestroy (&menu); FREE (&key_table); set_option (OPTNEEDREDRAW); - + return k; } static crypt_key_t *crypt_getkeybyaddr (ADDRESS * a, short abilities, - unsigned int app, int *forced_valid) + unsigned int app, int *forced_valid) { ADDRESS *r, *p; LIST *hints = NULL; - int weak = 0; + int weak = 0; int invalid = 0; - int multi = 0; + int multi = 0; int this_key_has_strong; int this_key_has_weak; int this_key_has_invalid; @@ -3706,7 +3443,7 @@ static crypt_key_t *crypt_getkeybyaddr (ADDRESS * a, short abilities, crypt_key_t *the_valid_key = NULL; crypt_key_t *matches = NULL; crypt_key_t **matches_endp = &matches; - + *forced_valid = 0; if (a && a->mailbox) @@ -3715,110 +3452,102 @@ static crypt_key_t *crypt_getkeybyaddr (ADDRESS * a, short abilities, hints = crypt_add_string_to_hints (hints, a->personal); mutt_message (_("Looking for keys matching \"%s\"..."), a->mailbox); - keys = get_candidates (hints, app, (abilities & KEYFLAG_CANSIGN) ); + keys = get_candidates (hints, app, (abilities & KEYFLAG_CANSIGN)); mutt_free_list (&hints); - + if (!keys) return NULL; - + dprint (5, (debugfile, "crypt_getkeybyaddr: looking for %s <%s>.", - a->personal, a->mailbox)); + a->personal, a->mailbox)); - for (k = keys; k; k = k->next) - { - dprint (5, (debugfile, " looking at key: %s `%.15s'\n", - crypt_keyid (k), k->uid)); - - if (abilities && !(k->flags & abilities)) - { - dprint (5, (debugfile, " insufficient abilities: Has %x, want %x\n", - k->flags, abilities)); - continue; - } + for (k = keys; k; k = k->next) { + dprint (5, (debugfile, " looking at key: %s `%.15s'\n", + crypt_keyid (k), k->uid)); - this_key_has_weak = 0; /* weak but valid match */ - this_key_has_invalid = 0; /* invalid match */ - this_key_has_strong = 0; /* strong and valid match */ - match = 0; /* any match */ - - r = rfc822_parse_adrlist (NULL, k->uid); - for (p = r; p; p = p->next) - { - int validity = crypt_id_matches_addr (a, p, k); - - if (validity & CRYPT_KV_MATCH) /* something matches */ - match = 1; - - /* is this key a strong candidate? */ - if ((validity & CRYPT_KV_VALID) - && (validity & CRYPT_KV_STRONGID) - && (validity & CRYPT_KV_ADDR)) - { - if (the_valid_key && the_valid_key != k) - multi = 1; - the_valid_key = k; - this_key_has_strong = 1; - } - else if ((validity & CRYPT_KV_MATCH) - && !(validity & CRYPT_KV_VALID)) - this_key_has_invalid = 1; - else if ((validity & CRYPT_KV_MATCH) - && (!(validity & CRYPT_KV_STRONGID) - || !(validity & CRYPT_KV_ADDR))) - this_key_has_weak = 1; - } - rfc822_free_address (&r); - - if (match) - { - crypt_key_t *tmp; - - if (!this_key_has_strong && this_key_has_invalid) - invalid = 1; - if (!this_key_has_strong && this_key_has_weak) - weak = 1; - - *matches_endp = tmp = crypt_copy_key (k); - matches_endp = &tmp->next; - the_valid_key = tmp; - } + if (abilities && !(k->flags & abilities)) { + dprint (5, (debugfile, " insufficient abilities: Has %x, want %x\n", + k->flags, abilities)); + continue; } - + + this_key_has_weak = 0; /* weak but valid match */ + this_key_has_invalid = 0; /* invalid match */ + this_key_has_strong = 0; /* strong and valid match */ + match = 0; /* any match */ + + r = rfc822_parse_adrlist (NULL, k->uid); + for (p = r; p; p = p->next) { + int validity = crypt_id_matches_addr (a, p, k); + + if (validity & CRYPT_KV_MATCH) /* something matches */ + match = 1; + + /* is this key a strong candidate? */ + if ((validity & CRYPT_KV_VALID) + && (validity & CRYPT_KV_STRONGID) + && (validity & CRYPT_KV_ADDR)) { + if (the_valid_key && the_valid_key != k) + multi = 1; + the_valid_key = k; + this_key_has_strong = 1; + } + else if ((validity & CRYPT_KV_MATCH) + && !(validity & CRYPT_KV_VALID)) + this_key_has_invalid = 1; + else if ((validity & CRYPT_KV_MATCH) + && (!(validity & CRYPT_KV_STRONGID) + || !(validity & CRYPT_KV_ADDR))) + this_key_has_weak = 1; + } + rfc822_free_address (&r); + + if (match) { + crypt_key_t *tmp; + + if (!this_key_has_strong && this_key_has_invalid) + invalid = 1; + if (!this_key_has_strong && this_key_has_weak) + weak = 1; + + *matches_endp = tmp = crypt_copy_key (k); + matches_endp = &tmp->next; + the_valid_key = tmp; + } + } + crypt_free_key (&keys); - - if (matches) - { - if (the_valid_key && !multi && !weak - && !(invalid && option (OPTPGPSHOWUNUSABLE))) - { - /* - * There was precisely one strong match on a valid ID, there - * were no valid keys with weak matches, and we aren't - * interested in seeing invalid keys. - * - * Proceed without asking the user. - */ - k = crypt_copy_key (the_valid_key); - } - else - { - /* - * Else: Ask the user. - */ - k = crypt_select_key (matches, a, NULL, app, forced_valid); - } - crypt_free_key (&matches); + + if (matches) { + if (the_valid_key && !multi && !weak + && !(invalid && option (OPTPGPSHOWUNUSABLE))) { + /* + * There was precisely one strong match on a valid ID, there + * were no valid keys with weak matches, and we aren't + * interested in seeing invalid keys. + * + * Proceed without asking the user. + */ + k = crypt_copy_key (the_valid_key); } - else + else { + /* + * Else: Ask the user. + */ + k = crypt_select_key (matches, a, NULL, app, forced_valid); + } + crypt_free_key (&matches); + } + else k = NULL; - + return k; } static crypt_key_t *crypt_getkeybystr (char *p, short abilities, - unsigned int app, int *forced_valid) + unsigned int app, int *forced_valid) { LIST *hints = NULL; crypt_key_t *keys; @@ -3837,43 +3566,39 @@ static crypt_key_t *crypt_getkeybystr (char *p, short abilities, if (!keys) return NULL; - - for (k = keys; k; k = k->next) - { - if (abilities && !(k->flags & abilities)) - continue; - match = 0; - dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against " - "key %s, \"%s\": ", p, crypt_keyid (k), k->uid)); - - if (!*p - || !mutt_strcasecmp (p, crypt_keyid (k)) - || (!mutt_strncasecmp (p, "0x", 2) - && !mutt_strcasecmp (p + 2, crypt_keyid (k))) - || (option (OPTPGPLONGIDS) - && !mutt_strncasecmp (p, "0x", 2) - && !mutt_strcasecmp (p + 2, crypt_keyid (k) + 8)) - || mutt_stristr (k->uid, p)) - { - crypt_key_t *tmp; - - dprint (5, (debugfile, "match.\n")); - - *matches_endp = tmp = crypt_copy_key (k); - matches_endp = &tmp->next; - } + for (k = keys; k; k = k->next) { + if (abilities && !(k->flags & abilities)) + continue; + + match = 0; + dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against " + "key %s, \"%s\": ", p, crypt_keyid (k), k->uid)); + + if (!*p || !mutt_strcasecmp (p, crypt_keyid (k)) + || (!mutt_strncasecmp (p, "0x", 2) + && !mutt_strcasecmp (p + 2, crypt_keyid (k))) + || (option (OPTPGPLONGIDS) + && !mutt_strncasecmp (p, "0x", 2) + && !mutt_strcasecmp (p + 2, crypt_keyid (k) + 8)) + || mutt_stristr (k->uid, p)) { + crypt_key_t *tmp; + + dprint (5, (debugfile, "match.\n")); + + *matches_endp = tmp = crypt_copy_key (k); + matches_endp = &tmp->next; } - + } + crypt_free_key (&keys); - - if (matches) - { - k = crypt_select_key (matches, NULL, p, app, forced_valid); - crypt_free_key (&matches); - return k; - } - + + if (matches) { + k = crypt_select_key (matches, NULL, p, app, forced_valid); + crypt_free_key (&matches); + return k; + } + return NULL; } @@ -3882,11 +3607,10 @@ static crypt_key_t *crypt_getkeybystr (char *p, short abilities, default. ABILITIES describe the required key abilities (sign, encrypt) and APP the type of the requested key; ether S/MIME or PGP. Return a copy of the key or NULL if not found. */ -static crypt_key_t *crypt_ask_for_key (char *tag, - char *whatfor, +static crypt_key_t *crypt_ask_for_key (char *tag, + char *whatfor, short abilities, - unsigned int app, - int *forced_valid) + unsigned int app, int *forced_valid) { crypt_key_t *key; char resp[SHORT_STRING]; @@ -3900,49 +3624,44 @@ static crypt_key_t *crypt_ask_for_key (char *tag, *forced_valid = 0; resp[0] = 0; - if (whatfor) - { - - for (l = id_defaults; l; l = l->next) - if (!mutt_strcasecmp (whatfor, l->what)) - { - strfcpy (resp, NONULL (l->dflt), sizeof (resp)); - break; - } - } + if (whatfor) { + for (l = id_defaults; l; l = l->next) + if (!mutt_strcasecmp (whatfor, l->what)) { + strfcpy (resp, NONULL (l->dflt), sizeof (resp)); + break; + } + } - for (;;) - { - resp[0] = 0; - if (mutt_get_field (tag, resp, sizeof (resp), M_CLEAR) != 0) - return NULL; - - if (whatfor) - { - if (l) - mutt_str_replace (&l->dflt, resp); - else - { - l = safe_malloc (sizeof (struct crypt_cache)); - l->next = id_defaults; - id_defaults = l; - l->what = safe_strdup (whatfor); - l->dflt = safe_strdup (resp); - } - } - - if ((key = crypt_getkeybystr (resp, abilities, app, forced_valid))) - return key; - - BEEP (); + + for (;;) { + resp[0] = 0; + if (mutt_get_field (tag, resp, sizeof (resp), M_CLEAR) != 0) + return NULL; + + if (whatfor) { + if (l) + mutt_str_replace (&l->dflt, resp); + else { + l = safe_malloc (sizeof (struct crypt_cache)); + l->next = id_defaults; + id_defaults = l; + l->what = safe_strdup (whatfor); + l->dflt = safe_strdup (resp); + } } + + if ((key = crypt_getkeybystr (resp, abilities, app, forced_valid))) + return key; + + BEEP (); + } /* not reached */ } /* This routine attempts to find the keyids of the recipients of a message. It returns NULL if any of the keys can not be found. */ -static char *find_keys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc, +static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc, unsigned int app) { char *keyID, *keylist = NULL, *t; @@ -3956,127 +3675,123 @@ static char *find_keys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc, const char *fqdn = mutt_fqdn (1); #if 0 - *r_application = APPLICATION_PGP|APPLICATION_SMIME; + *r_application = APPLICATION_PGP | APPLICATION_SMIME; #endif - - for (i = 0; i < 3; i++) - { - switch (i) - { - case 0: p = to; break; - case 1: p = cc; break; - case 2: p = bcc; break; - default: abort (); - } - - *last = rfc822_cpy_adr (p); - while (*last) - last = &((*last)->next); + + for (i = 0; i < 3; i++) { + switch (i) { + case 0: + p = to; + break; + case 1: + p = cc; + break; + case 2: + p = bcc; + break; + default: + abort (); } - + + *last = rfc822_cpy_adr (p); + while (*last) + last = &((*last)->next); + } + if (fqdn) rfc822_qualify (tmp, fqdn); - + tmp = mutt_remove_duplicates (tmp); - - for (p = tmp; p ; p = p->next) - { - char buf[LONG_STRING]; - int forced_valid = 0; - - q = p; - k_info = NULL; - - if ((keyID = mutt_crypt_hook (p)) != NULL) - { - int r; - snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), - keyID, p->mailbox); - if ((r = mutt_yesorno (buf, M_YES)) == M_YES) - { - /* check for e-mail address */ - if ((t = strchr (keyID, '@')) && - (addr = rfc822_parse_adrlist (NULL, keyID))) - { - if (fqdn) - rfc822_qualify (addr, fqdn); - q = addr; - } - else - { -#if 0 - k_info = crypt_getkeybystr (keyID, KEYFLAG_CANENCRYPT, - *r_application, &forced_valid); + + for (p = tmp; p; p = p->next) { + char buf[LONG_STRING]; + int forced_valid = 0; + + q = p; + k_info = NULL; + + if ((keyID = mutt_crypt_hook (p)) != NULL) { + int r; + + snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), + keyID, p->mailbox); + if ((r = mutt_yesorno (buf, M_YES)) == M_YES) { + /* check for e-mail address */ + if ((t = strchr (keyID, '@')) && + (addr = rfc822_parse_adrlist (NULL, keyID))) { + if (fqdn) + rfc822_qualify (addr, fqdn); + q = addr; + } + else { +#if 0 + k_info = crypt_getkeybystr (keyID, KEYFLAG_CANENCRYPT, + *r_application, &forced_valid); #else - k_info = crypt_getkeybystr (keyID, KEYFLAG_CANENCRYPT, - app, &forced_valid); + k_info = crypt_getkeybystr (keyID, KEYFLAG_CANENCRYPT, + app, &forced_valid); #endif - } - } - else if (r == -1) - { - FREE (&keylist); - rfc822_free_address (&tmp); - rfc822_free_address (&addr); - return NULL; - } } + } + else if (r == -1) { + FREE (&keylist); + rfc822_free_address (&tmp); + rfc822_free_address (&addr); + return NULL; + } + } + + if (k_info == NULL + && (k_info = crypt_getkeybyaddr (q, KEYFLAG_CANENCRYPT, + app, &forced_valid)) == NULL) { + snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); - if (k_info == NULL - && (k_info = crypt_getkeybyaddr (q, KEYFLAG_CANENCRYPT, - app, &forced_valid)) == NULL) - { - snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); - - if ((key = crypt_ask_for_key (buf, q->mailbox, - KEYFLAG_CANENCRYPT, + if ((key = crypt_ask_for_key (buf, q->mailbox, KEYFLAG_CANENCRYPT, #if 0 - *r_application, + *r_application, #else - app, + app, #endif - &forced_valid)) == NULL) - { - FREE (&keylist); - rfc822_free_address (&tmp); - rfc822_free_address (&addr); - return NULL; - } - } - else - key = k_info; + &forced_valid)) == NULL) { + FREE (&keylist); + rfc822_free_address (&tmp); + rfc822_free_address (&addr); + return NULL; + } + } + else + key = k_info; - { - const char *s = crypt_fpr (key); + { + const char *s = crypt_fpr (key); #if 0 - if (key->flags & KEYFLAG_ISX509) - *r_application &= ~APPLICATION_PGP; - if (!(key->flags & KEYFLAG_ISX509)) - *r_application &= ~APPLICATION_SMIME; + if (key->flags & KEYFLAG_ISX509) + *r_application &= ~APPLICATION_PGP; + if (!(key->flags & KEYFLAG_ISX509)) + *r_application &= ~APPLICATION_SMIME; #endif - - keylist_size += mutt_strlen (s) + 4 + 1; - safe_realloc (&keylist, keylist_size); - sprintf (keylist + keylist_used, "%s0x%s%s", /* __SPRINTF_CHECKED__ */ - keylist_used ? " " : "", s, - forced_valid? "!":""); - } - keylist_used = mutt_strlen (keylist); - - crypt_free_key (&key); - rfc822_free_address (&addr); + + keylist_size += mutt_strlen (s) + 4 + 1; + safe_realloc (&keylist, keylist_size); + sprintf (keylist + keylist_used, "%s0x%s%s", /* __SPRINTF_CHECKED__ */ + keylist_used ? " " : "", s, forced_valid ? "!" : ""); } + keylist_used = mutt_strlen (keylist); + + crypt_free_key (&key); + rfc822_free_address (&addr); + } rfc822_free_address (&tmp); return (keylist); } -char *pgp_gpgme_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +char *pgp_gpgme_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) { return find_keys (to, cc, bcc, APPLICATION_PGP); } -char *smime_gpgme_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +char *smime_gpgme_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) { return find_keys (to, cc, bcc, APPLICATION_SMIME); } @@ -4089,12 +3804,11 @@ char *smime_gpgme_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) static void init_gpgme (void) { /* Make sure that gpg-agent is running. */ - if (! getenv ("GPG_AGENT_INFO")) - { - mutt_error ("\nUsing GPGME backend, although no gpg-agent is running"); - if (mutt_any_key_to_continue (NULL) == -1) - mutt_exit(1); - } + if (!getenv ("GPG_AGENT_INFO")) { + mutt_error ("\nUsing GPGME backend, although no gpg-agent is running"); + if (mutt_any_key_to_continue (NULL) == -1) + mutt_exit (1); + } } void pgp_gpgme_init (void) @@ -4106,7 +3820,7 @@ void smime_gpgme_init (void) { } -static int gpgme_send_menu (HEADER *msg, int *redraw, int is_smime) +static int gpgme_send_menu (HEADER * msg, int *redraw, int is_smime) { crypt_key_t *p; char input_signas[SHORT_STRING]; @@ -4118,135 +3832,126 @@ static int gpgme_send_menu (HEADER *msg, int *redraw, int is_smime) is_smime = 1; if (is_smime) - choice = mutt_multi_choice ( - _("S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"), - _("esabtf")); - else - choice = mutt_multi_choice ( - _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"), - _("esabtf")); - - switch (choice) - { - case 1: /* (e)ncrypt */ + choice = + mutt_multi_choice (_ + ("S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"), + _("esabtf")); + else + choice = + mutt_multi_choice (_ + ("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (t)oggle or (f)orget it?"), + _("esabtf")); + + switch (choice) { + case 1: /* (e)ncrypt */ msg->security |= (is_smime ? SMIMEENCRYPT : PGPENCRYPT); break; - case 2: /* (s)ign */ - msg->security |= (is_smime? SMIMESIGN :PGPSIGN); + case 2: /* (s)ign */ + msg->security |= (is_smime ? SMIMESIGN : PGPSIGN); break; - case 3: /* sign (a)s */ + case 3: /* sign (a)s */ /* unset_option(OPTCRYPTCHECKTRUST); */ if ((p = crypt_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, - is_smime? APPLICATION_SMIME:APPLICATION_PGP, - NULL))) - { + is_smime ? APPLICATION_SMIME : + APPLICATION_PGP, NULL))) { snprintf (input_signas, sizeof (input_signas), "0x%s", crypt_keyid (p)); - mutt_str_replace (is_smime? &SmimeDefaultKey : &PgpSignAs, input_signas); - crypt_free_key (&p); - - msg->security |= (is_smime? SMIMESIGN:PGPSIGN); + mutt_str_replace (is_smime ? &SmimeDefaultKey : &PgpSignAs, + input_signas); + crypt_free_key (&p); + + msg->security |= (is_smime ? SMIMESIGN : PGPSIGN); } - else - { - msg->security &= (is_smime? ~SMIMESIGN : ~PGPSIGN); + else { + msg->security &= (is_smime ? ~SMIMESIGN : ~PGPSIGN); } *redraw = REDRAW_FULL; break; - case 4: /* (b)oth */ - msg->security = (is_smime? (SMIMEENCRYPT|SMIMESIGN):(PGPENCRYPT|PGPSIGN)); + case 4: /* (b)oth */ + msg->security = + (is_smime ? (SMIMEENCRYPT | SMIMESIGN) : (PGPENCRYPT | PGPSIGN)); break; - case 5: /* (t)oggle */ + case 5: /* (t)oggle */ is_smime = !is_smime; break; - case 6: /* (f)orget it */ + case 6: /* (f)orget it */ msg->security = 0; break; } - if (choice == 6) - ; - else if (is_smime) - { - msg->security &= ~APPLICATION_PGP; - msg->security |= APPLICATION_SMIME; - } - else - { - msg->security &= ~APPLICATION_SMIME; - msg->security |= APPLICATION_PGP; - } - + if (choice == 6); + else if (is_smime) { + msg->security &= ~APPLICATION_PGP; + msg->security |= APPLICATION_SMIME; + } + else { + msg->security &= ~APPLICATION_SMIME; + msg->security |= APPLICATION_PGP; + } + return (msg->security); } -int pgp_gpgme_send_menu (HEADER *msg, int *redraw) +int pgp_gpgme_send_menu (HEADER * msg, int *redraw) { return gpgme_send_menu (msg, redraw, 0); } -int smime_gpgme_send_menu (HEADER *msg, int *redraw) +int smime_gpgme_send_menu (HEADER * msg, int *redraw) { return gpgme_send_menu (msg, redraw, 1); } -static int verify_sender (HEADER *h, gpgme_protocol_t protocol) +static int verify_sender (HEADER * h, gpgme_protocol_t protocol) { ADDRESS *sender = NULL; unsigned int ret = 1; - if (h->env->from) - { - h->env->from = mutt_expand_aliases (h->env->from); - sender = h->env->from; - } - else if (h->env->sender) - { - h->env->sender = mutt_expand_aliases (h->env->sender); - sender = h->env->sender; - } + if (h->env->from) { + h->env->from = mutt_expand_aliases (h->env->from); + sender = h->env->from; + } + else if (h->env->sender) { + h->env->sender = mutt_expand_aliases (h->env->sender); + sender = h->env->sender; + } - if (sender) - { - if (signature_key) - { - gpgme_key_t key = signature_key; - gpgme_user_id_t uid = NULL; - int sender_length = 0; - int uid_length = 0; - - sender_length = strlen (sender->mailbox); - for (uid = key->uids; uid && ret; uid = uid->next) - { - uid_length = strlen (uid->email); - if (1 - && (uid->email[0] == '<') - && (uid->email[uid_length - 1] == '>') - && (uid_length == sender_length + 2) - && (! strncmp (uid->email + 1, sender->mailbox, sender_length))) - ret = 0; - } - } - else - mutt_any_key_to_continue ("Failed to verify sender"); + if (sender) { + if (signature_key) { + gpgme_key_t key = signature_key; + gpgme_user_id_t uid = NULL; + int sender_length = 0; + int uid_length = 0; + + sender_length = strlen (sender->mailbox); + for (uid = key->uids; uid && ret; uid = uid->next) { + uid_length = strlen (uid->email); + if (1 && (uid->email[0] == '<') + && (uid->email[uid_length - 1] == '>') + && (uid_length == sender_length + 2) + && (!strncmp (uid->email + 1, sender->mailbox, sender_length))) + ret = 0; + } } + else + mutt_any_key_to_continue ("Failed to verify sender"); + } else mutt_any_key_to_continue ("Failed to figure out sender"); - if (signature_key) - { - gpgme_key_release (signature_key); - signature_key = NULL; - } + if (signature_key) { + gpgme_key_release (signature_key); + signature_key = NULL; + } return ret; } -int smime_gpgme_verify_sender (HEADER *h) +int smime_gpgme_verify_sender (HEADER * h) { return verify_sender (h, GPGME_PROTOCOL_CMS); } diff --git a/crypt-gpgme.h b/crypt-gpgme.h index 4901351..224367a 100644 --- a/crypt-gpgme.h +++ b/crypt-gpgme.h @@ -24,30 +24,32 @@ void pgp_gpgme_init (void); void smime_gpgme_init (void); -char *pgp_gpgme_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); -char *smime_gpgme_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); +char *pgp_gpgme_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc); +char *smime_gpgme_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc); -BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign); -BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist); +BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign); +BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist); -int pgp_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur); -int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur); +int pgp_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, + BODY ** cur); +int smime_gpgme_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, + BODY ** cur); -int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only); +int pgp_gpgme_check_traditional (FILE * fp, BODY * b, int tagged_only); -void pgp_gpgme_application_handler (BODY *m, STATE *s); -void smime_gpgme_application_handler (BODY *a, STATE *s); -void pgp_gpgme_encrypted_handler (BODY *a, STATE *s); +void pgp_gpgme_application_handler (BODY * m, STATE * s); +void smime_gpgme_application_handler (BODY * a, STATE * s); +void pgp_gpgme_encrypted_handler (BODY * a, STATE * s); BODY *pgp_gpgme_make_key_attachment (char *tempf); -BODY *pgp_gpgme_sign_message (BODY *a); -BODY *smime_gpgme_sign_message (BODY *a); +BODY *pgp_gpgme_sign_message (BODY * a); +BODY *smime_gpgme_sign_message (BODY * a); -int pgp_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile); -int smime_gpgme_verify_one (BODY *sigbdy, STATE *s, const char *tempfile); +int pgp_gpgme_verify_one (BODY * sigbdy, STATE * s, const char *tempfile); +int smime_gpgme_verify_one (BODY * sigbdy, STATE * s, const char *tempfile); -int pgp_gpgme_send_menu (HEADER *msg, int *redraw); -int smime_gpgme_send_menu (HEADER *msg, int *redraw); +int pgp_gpgme_send_menu (HEADER * msg, int *redraw); +int smime_gpgme_send_menu (HEADER * msg, int *redraw); #endif diff --git a/crypt-mod-pgp-classic.c b/crypt-mod-pgp-classic.c index e6e3bc8..f5613ee 100644 --- a/crypt-mod-pgp-classic.c +++ b/crypt-mod-pgp-classic.c @@ -37,36 +37,39 @@ static int crypt_mod_pgp_valid_passphrase (void) return pgp_valid_passphrase (); } -static int crypt_mod_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +static int crypt_mod_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, + BODY ** d) { return pgp_decrypt_mime (a, b, c, d); } -static void crypt_mod_pgp_application_handler (BODY *m, STATE *s) +static void crypt_mod_pgp_application_handler (BODY * m, STATE * s) { pgp_application_pgp_handler (m, s); } -static char *crypt_mod_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +static char *crypt_mod_pgp_findkeys (ADDRESS * to, ADDRESS * cc, + ADDRESS * bcc) { return pgp_findKeys (to, cc, bcc); } -static BODY *crypt_mod_pgp_sign_message (BODY *a) +static BODY *crypt_mod_pgp_sign_message (BODY * a) { return pgp_sign_message (a); } -static int crypt_mod_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +static int crypt_mod_pgp_verify_one (BODY * sigbdy, STATE * s, + const char *tempf) { return pgp_verify_one (sigbdy, s, tempf); } -static int crypt_mod_pgp_send_menu (HEADER *msg, int *redraw) +static int crypt_mod_pgp_send_menu (HEADER * msg, int *redraw) { return pgp_send_menu (msg, redraw); } -static BODY *crypt_mod_pgp_encrypt_message (BODY *a, char *keylist, int sign) +static BODY *crypt_mod_pgp_encrypt_message (BODY * a, char *keylist, int sign) { return pgp_encrypt_message (a, keylist, sign); } @@ -76,22 +79,24 @@ static BODY *crypt_mod_pgp_make_key_attachment (char *tempf) return pgp_make_key_attachment (tempf); } -static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) +static int crypt_mod_pgp_check_traditional (FILE * fp, BODY * b, + int tagged_only) { return pgp_check_traditional (fp, b, tagged_only); } -static BODY *crypt_mod_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) +static BODY *crypt_mod_pgp_traditional_encryptsign (BODY * a, int flags, + char *keylist) { return pgp_traditional_encryptsign (a, flags, keylist); } -static void crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s) +static void crypt_mod_pgp_encrypted_handler (BODY * m, STATE * s) { pgp_encrypted_handler (m, s); } -static void crypt_mod_pgp_invoke_getkeys (ADDRESS *addr) +static void crypt_mod_pgp_invoke_getkeys (ADDRESS * addr) { pgp_invoke_getkeys (addr); } @@ -101,36 +106,37 @@ static void crypt_mod_pgp_invoke_import (const char *fname) pgp_invoke_import (fname); } -static void crypt_mod_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top) +static void crypt_mod_pgp_extract_keys_from_attachment_list (FILE * fp, + int tag, + BODY * top) { pgp_extract_keys_from_attachment_list (fp, tag, top); } -struct crypt_module_specs crypt_mod_pgp_classic = - { APPLICATION_PGP, - { - NULL, /* init */ - crypt_mod_pgp_void_passphrase, - crypt_mod_pgp_valid_passphrase, - crypt_mod_pgp_decrypt_mime, - crypt_mod_pgp_application_handler, - crypt_mod_pgp_encrypted_handler, - crypt_mod_pgp_findkeys, - crypt_mod_pgp_sign_message, - crypt_mod_pgp_verify_one, - crypt_mod_pgp_send_menu, - - crypt_mod_pgp_encrypt_message, - crypt_mod_pgp_make_key_attachment, - crypt_mod_pgp_check_traditional, - crypt_mod_pgp_traditional_encryptsign, - crypt_mod_pgp_invoke_getkeys, - crypt_mod_pgp_invoke_import, - crypt_mod_pgp_extract_keys_from_attachment_list, - - NULL, /* smime_getkeys */ - NULL, /* smime_verify_sender */ - NULL, /* smime_build_smime_entity */ - NULL, /* smime_invoke_import */ - } - }; +struct crypt_module_specs crypt_mod_pgp_classic = { APPLICATION_PGP, + { + NULL, /* init */ + crypt_mod_pgp_void_passphrase, + crypt_mod_pgp_valid_passphrase, + crypt_mod_pgp_decrypt_mime, + crypt_mod_pgp_application_handler, + crypt_mod_pgp_encrypted_handler, + crypt_mod_pgp_findkeys, + crypt_mod_pgp_sign_message, + crypt_mod_pgp_verify_one, + crypt_mod_pgp_send_menu, + + crypt_mod_pgp_encrypt_message, + crypt_mod_pgp_make_key_attachment, + crypt_mod_pgp_check_traditional, + crypt_mod_pgp_traditional_encryptsign, + crypt_mod_pgp_invoke_getkeys, + crypt_mod_pgp_invoke_import, + crypt_mod_pgp_extract_keys_from_attachment_list, + + NULL, /* smime_getkeys */ + NULL, /* smime_verify_sender */ + NULL, /* smime_build_smime_entity */ + NULL, /* smime_invoke_import */ + } +}; diff --git a/crypt-mod-pgp-gpgme.c b/crypt-mod-pgp-gpgme.c index bab9663..54b2af0 100644 --- a/crypt-mod-pgp-gpgme.c +++ b/crypt-mod-pgp-gpgme.c @@ -45,80 +45,83 @@ static int crypt_mod_pgp_valid_passphrase (void) return 1; } -static int crypt_mod_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +static int crypt_mod_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, + BODY ** d) { return pgp_gpgme_decrypt_mime (a, b, c, d); } -static void crypt_mod_pgp_application_handler (BODY *m, STATE *s) +static void crypt_mod_pgp_application_handler (BODY * m, STATE * s) { pgp_gpgme_application_handler (m, s); } -static void crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s) +static void crypt_mod_pgp_encrypted_handler (BODY * m, STATE * s) { pgp_gpgme_encrypted_handler (m, s); } -static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) +static int crypt_mod_pgp_check_traditional (FILE * fp, BODY * b, + int tagged_only) { return pgp_gpgme_check_traditional (fp, b, tagged_only); } -static char *crypt_mod_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +static char *crypt_mod_pgp_findkeys (ADDRESS * to, ADDRESS * cc, + ADDRESS * bcc) { return pgp_gpgme_findkeys (to, cc, bcc); } -static BODY *crypt_mod_pgp_sign_message (BODY *a) +static BODY *crypt_mod_pgp_sign_message (BODY * a) { return pgp_gpgme_sign_message (a); } -static int crypt_mod_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +static int crypt_mod_pgp_verify_one (BODY * sigbdy, STATE * s, + const char *tempf) { return pgp_gpgme_verify_one (sigbdy, s, tempf); } -static int crypt_mod_pgp_send_menu (HEADER *msg, int *redraw) +static int crypt_mod_pgp_send_menu (HEADER * msg, int *redraw) { return pgp_gpgme_send_menu (msg, redraw); } -static BODY *crypt_mod_pgp_encrypt_message (BODY *a, char *keylist, int sign) +static BODY *crypt_mod_pgp_encrypt_message (BODY * a, char *keylist, int sign) { return pgp_gpgme_encrypt_message (a, keylist, sign); } -struct crypt_module_specs crypt_mod_pgp_gpgme = - { APPLICATION_PGP, - { - /* Common. */ - crypt_mod_pgp_init, - crypt_mod_pgp_void_passphrase, - crypt_mod_pgp_valid_passphrase, - crypt_mod_pgp_decrypt_mime, - crypt_mod_pgp_application_handler, - crypt_mod_pgp_encrypted_handler, - crypt_mod_pgp_findkeys, - crypt_mod_pgp_sign_message, - crypt_mod_pgp_verify_one, - crypt_mod_pgp_send_menu, - - /* PGP specific. */ - crypt_mod_pgp_encrypt_message, - NULL, /* pgp_make_key_attachment, */ - crypt_mod_pgp_check_traditional, - NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - NULL, /* pgp_invoke_import */ - NULL, /* pgp_extract_keys_from_attachment_list */ - - NULL, /* smime_getkeys */ - NULL, /* smime_verify_sender */ - NULL, /* smime_build_smime_entity */ - NULL, /* smime_invoke_import */ - } - }; +struct crypt_module_specs crypt_mod_pgp_gpgme = { APPLICATION_PGP, + { + /* Common. */ + crypt_mod_pgp_init, + crypt_mod_pgp_void_passphrase, + crypt_mod_pgp_valid_passphrase, + crypt_mod_pgp_decrypt_mime, + crypt_mod_pgp_application_handler, + crypt_mod_pgp_encrypted_handler, + crypt_mod_pgp_findkeys, + crypt_mod_pgp_sign_message, + crypt_mod_pgp_verify_one, + crypt_mod_pgp_send_menu, + + /* PGP specific. */ + crypt_mod_pgp_encrypt_message, + NULL, /* pgp_make_key_attachment, */ + crypt_mod_pgp_check_traditional, + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + NULL, /* pgp_invoke_import */ + NULL, /* pgp_extract_keys_from_attachment_list */ + + NULL, /* smime_getkeys */ + NULL, /* smime_verify_sender */ + NULL, /* smime_build_smime_entity */ + NULL, /* smime_invoke_import */ + } +}; #endif diff --git a/crypt-mod-smime-classic.c b/crypt-mod-smime-classic.c index cff63b2..a790036 100644 --- a/crypt-mod-smime-classic.c +++ b/crypt-mod-smime-classic.c @@ -37,46 +37,49 @@ static int crypt_mod_smime_valid_passphrase (void) return smime_valid_passphrase (); } -static int crypt_mod_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +static int crypt_mod_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, + BODY ** d) { return smime_decrypt_mime (a, b, c, d); } -static void crypt_mod_smime_application_handler (BODY *m, STATE *s) +static void crypt_mod_smime_application_handler (BODY * m, STATE * s) { smime_application_smime_handler (m, s); } -static char *crypt_mod_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +static char *crypt_mod_smime_findkeys (ADDRESS * to, ADDRESS * cc, + ADDRESS * bcc) { return smime_findKeys (to, cc, bcc); } -static BODY *crypt_mod_smime_sign_message (BODY *a) +static BODY *crypt_mod_smime_sign_message (BODY * a) { return smime_sign_message (a); } -static int crypt_mod_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +static int crypt_mod_smime_verify_one (BODY * sigbdy, STATE * s, + const char *tempf) { return smime_verify_one (sigbdy, s, tempf); } -static int crypt_mod_smime_send_menu (HEADER *msg, int *redraw) +static int crypt_mod_smime_send_menu (HEADER * msg, int *redraw) { return smime_send_menu (msg, redraw); } -static void crypt_mod_smime_getkeys (ENVELOPE *env) +static void crypt_mod_smime_getkeys (ENVELOPE * env) { smime_getkeys (env); } -static int crypt_mod_smime_verify_sender (HEADER *h) +static int crypt_mod_smime_verify_sender (HEADER * h) { return smime_verify_sender (h); } -static BODY *crypt_mod_smime_build_smime_entity (BODY *a, char *certlist) +static BODY *crypt_mod_smime_build_smime_entity (BODY * a, char *certlist) { return smime_build_smime_entity (a, certlist); } @@ -87,31 +90,30 @@ static void crypt_mod_smime_invoke_import (char *infile, char *mailbox) } -struct crypt_module_specs crypt_mod_smime_classic = - { APPLICATION_SMIME, - { - NULL, /* init */ - crypt_mod_smime_void_passphrase, - crypt_mod_smime_valid_passphrase, - crypt_mod_smime_decrypt_mime, - crypt_mod_smime_application_handler, - NULL, /* encrypted_handler */ - crypt_mod_smime_findkeys, - crypt_mod_smime_sign_message, - crypt_mod_smime_verify_one, - crypt_mod_smime_send_menu, - - NULL, /* pgp_encrypt_message */ - NULL, /* pgp_make_key_attachment */ - NULL, /* pgp_check_traditional */ - NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - NULL, /* pgp_invoke_import */ - NULL, /* pgp_extract_keys_from_attachment_list */ - - crypt_mod_smime_getkeys, - crypt_mod_smime_verify_sender, - crypt_mod_smime_build_smime_entity, - crypt_mod_smime_invoke_import, - } - }; +struct crypt_module_specs crypt_mod_smime_classic = { APPLICATION_SMIME, + { + NULL, /* init */ + crypt_mod_smime_void_passphrase, + crypt_mod_smime_valid_passphrase, + crypt_mod_smime_decrypt_mime, + crypt_mod_smime_application_handler, + NULL, /* encrypted_handler */ + crypt_mod_smime_findkeys, + crypt_mod_smime_sign_message, + crypt_mod_smime_verify_one, + crypt_mod_smime_send_menu, + + NULL, /* pgp_encrypt_message */ + NULL, /* pgp_make_key_attachment */ + NULL, /* pgp_check_traditional */ + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + NULL, /* pgp_invoke_import */ + NULL, /* pgp_extract_keys_from_attachment_list */ + + crypt_mod_smime_getkeys, + crypt_mod_smime_verify_sender, + crypt_mod_smime_build_smime_entity, + crypt_mod_smime_invoke_import, + } +}; diff --git a/crypt-mod-smime-gpgme.c b/crypt-mod-smime-gpgme.c index 761dec9..ca17ce9 100644 --- a/crypt-mod-smime-gpgme.c +++ b/crypt-mod-smime-gpgme.c @@ -45,73 +45,75 @@ static int crypt_mod_smime_valid_passphrase (void) return 1; } -static int crypt_mod_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +static int crypt_mod_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, + BODY ** d) { return smime_gpgme_decrypt_mime (a, b, c, d); } -static void crypt_mod_smime_application_handler (BODY *m, STATE *s) +static void crypt_mod_smime_application_handler (BODY * m, STATE * s) { smime_gpgme_application_handler (m, s); } -static char *crypt_mod_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +static char *crypt_mod_smime_findkeys (ADDRESS * to, ADDRESS * cc, + ADDRESS * bcc) { return smime_gpgme_findkeys (to, cc, bcc); } -static BODY *crypt_mod_smime_sign_message (BODY *a) +static BODY *crypt_mod_smime_sign_message (BODY * a) { return smime_gpgme_sign_message (a); } -static int crypt_mod_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +static int crypt_mod_smime_verify_one (BODY * sigbdy, STATE * s, + const char *tempf) { return smime_gpgme_verify_one (sigbdy, s, tempf); } -static int crypt_mod_smime_send_menu (HEADER *msg, int *redraw) +static int crypt_mod_smime_send_menu (HEADER * msg, int *redraw) { return smime_gpgme_send_menu (msg, redraw); } -static BODY *crypt_mod_smime_build_smime_entity (BODY *a, char *certlist) +static BODY *crypt_mod_smime_build_smime_entity (BODY * a, char *certlist) { return smime_gpgme_build_smime_entity (a, certlist); } -static int crypt_mod_smime_verify_sender (HEADER *h) +static int crypt_mod_smime_verify_sender (HEADER * h) { return smime_gpgme_verify_sender (h); } -struct crypt_module_specs crypt_mod_smime_gpgme = - { APPLICATION_SMIME, - { - crypt_mod_smime_init, - crypt_mod_smime_void_passphrase, - crypt_mod_smime_valid_passphrase, - crypt_mod_smime_decrypt_mime, - crypt_mod_smime_application_handler, - NULL, /* encrypted_handler */ - crypt_mod_smime_findkeys, - crypt_mod_smime_sign_message, - crypt_mod_smime_verify_one, - crypt_mod_smime_send_menu, - - NULL, /* pgp_encrypt_message */ - NULL, /* pgp_make_key_attachment */ - NULL, /* pgp_check_traditional */ - NULL, /* pgp_traditional_encryptsign */ - NULL, /* pgp_invoke_getkeys */ - NULL, /* pgp_invoke_import */ - NULL, /* pgp_extract_keys_from_attachment_list */ - - NULL, /* smime_getkeys */ - crypt_mod_smime_verify_sender, - crypt_mod_smime_build_smime_entity, - NULL, /* smime_invoke_import */ - } - }; +struct crypt_module_specs crypt_mod_smime_gpgme = { APPLICATION_SMIME, + { + crypt_mod_smime_init, + crypt_mod_smime_void_passphrase, + crypt_mod_smime_valid_passphrase, + crypt_mod_smime_decrypt_mime, + crypt_mod_smime_application_handler, + NULL, /* encrypted_handler */ + crypt_mod_smime_findkeys, + crypt_mod_smime_sign_message, + crypt_mod_smime_verify_one, + crypt_mod_smime_send_menu, + + NULL, /* pgp_encrypt_message */ + NULL, /* pgp_make_key_attachment */ + NULL, /* pgp_check_traditional */ + NULL, /* pgp_traditional_encryptsign */ + NULL, /* pgp_invoke_getkeys */ + NULL, /* pgp_invoke_import */ + NULL, /* pgp_extract_keys_from_attachment_list */ + + NULL, /* smime_getkeys */ + crypt_mod_smime_verify_sender, + crypt_mod_smime_build_smime_entity, + NULL, /* smime_invoke_import */ + } +}; #endif diff --git a/crypt-mod.c b/crypt-mod.c index 4be1e43..3c52671 100644 --- a/crypt-mod.c +++ b/crypt-mod.c @@ -25,8 +25,7 @@ /* A type an a variable to keep track of registered crypto modules. */ typedef struct crypt_module *crypt_module_t; -struct crypt_module -{ +struct crypt_module { crypt_module_specs_t specs; crypt_module_t next, *prevp; }; diff --git a/crypt-mod.h b/crypt-mod.h index 4f69c3e..dabf9a2 100644 --- a/crypt-mod.h +++ b/crypt-mod.h @@ -29,41 +29,43 @@ Type defintions for crypto module functions. */ typedef void (*crypt_func_void_passphrase_t) (void); -typedef int (*crypt_func_valid_passphrase_t) (void); +typedef int (*crypt_func_valid_passphrase_t) (void); -typedef int (*crypt_func_decrypt_mime_t) (FILE *a, FILE **b, - BODY *c, BODY **d); +typedef int (*crypt_func_decrypt_mime_t) (FILE * a, FILE ** b, + BODY * c, BODY ** d); -typedef void (*crypt_func_application_handler_t) (BODY *m, STATE *s); -typedef void (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s); +typedef void (*crypt_func_application_handler_t) (BODY * m, STATE * s); +typedef void (*crypt_func_encrypted_handler_t) (BODY * m, STATE * s); -typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS *addr); -typedef int (*crypt_func_pgp_check_traditional_t) (FILE *fp, BODY *b, +typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS * addr); +typedef int (*crypt_func_pgp_check_traditional_t) (FILE * fp, BODY * b, int tagged_only); -typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY *a, int flags, +typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY * a, + int flags, char *keylist); typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf); -typedef char *(*crypt_func_findkeys_t) (ADDRESS *to, - ADDRESS *cc, ADDRESS *bcc); -typedef BODY *(*crypt_func_sign_message_t) (BODY *a); -typedef BODY *(*crypt_func_pgp_encrypt_message_t) (BODY *a, char *keylist, +typedef char *(*crypt_func_findkeys_t) (ADDRESS * to, + ADDRESS * cc, ADDRESS * bcc); +typedef BODY *(*crypt_func_sign_message_t) (BODY * a); +typedef BODY *(*crypt_func_pgp_encrypt_message_t) (BODY * a, char *keylist, int sign); typedef void (*crypt_func_pgp_invoke_import_t) (const char *fname); -typedef int (*crypt_func_verify_one_t) (BODY *sigbdy, STATE *s, +typedef int (*crypt_func_verify_one_t) (BODY * sigbdy, STATE * s, const char *tempf); -typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t) - (FILE *fp, int tag, BODY *top); +typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t) + (FILE * fp, int tag, BODY * top); -typedef int (*crypt_func_send_menu_t) (HEADER *msg, int *redraw); +typedef int (*crypt_func_send_menu_t) (HEADER * msg, int *redraw); /* (SMIME) */ -typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE *env); -typedef int (*crypt_func_smime_verify_sender_t) (HEADER *h); +typedef void (*crypt_func_smime_getkeys_t) (ENVELOPE * env); +typedef int (*crypt_func_smime_verify_sender_t) (HEADER * h); -typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY *a, +typedef BODY *(*crypt_func_smime_build_smime_entity_t) (BODY * a, char *certlist); -typedef void (*crypt_func_smime_invoke_import_t) (char *infile, char *mailbox); +typedef void (*crypt_func_smime_invoke_import_t) (char *infile, + char *mailbox); typedef void (*crypt_func_init_t) (void); @@ -71,8 +73,7 @@ typedef void (*crypt_func_init_t) (void); /* A structure to keep all crypto module fucntions together. */ -typedef struct crypt_module_functions -{ +typedef struct crypt_module_functions { /* Common/General functions. */ crypt_func_init_t init; crypt_func_void_passphrase_t void_passphrase; @@ -92,8 +93,22 @@ typedef struct crypt_module_functions crypt_func_pgp_traditional_encryptsign_t pgp_traditional_encryptsign; crypt_func_pgp_invoke_getkeys_t pgp_invoke_getkeys; crypt_func_pgp_invoke_import_t pgp_invoke_import; - crypt_func_pgp_extract_keys_from_attachment_list_t - pgp_extract_keys_from_attachment_list; + + + + + + + + + + + + + + + crypt_func_pgp_extract_keys_from_attachment_list_t + pgp_extract_keys_from_attachment_list; /* S/MIME specific functions. */ @@ -107,11 +122,10 @@ typedef struct crypt_module_functions /* A structure to decribe a crypto module. */ -typedef struct crypt_module_specs -{ - int identifier; /* Identifying bit. */ +typedef struct crypt_module_specs { + int identifier; /* Identifying bit. */ crypt_module_functions_t functions; -} *crypt_module_specs_t; +} *crypt_module_specs_t; diff --git a/crypt.c b/crypt.c index 9c0fc4c..39fead1 100644 --- a/crypt.c +++ b/crypt.c @@ -54,7 +54,7 @@ /* print the current time to avoid spoofing of the signature output */ -void crypt_current_time(STATE *s, char *app_name) +void crypt_current_time (STATE * s, char *app_name) { time_t t; char p[STRING], tmp[STRING]; @@ -62,9 +62,8 @@ void crypt_current_time(STATE *s, char *app_name) if (!WithCrypto) return; - if (option (OPTCRYPTTIMESTAMP)) - { - t = time(NULL); + if (option (OPTCRYPTTIMESTAMP)) { + t = time (NULL); setlocale (LC_TIME, ""); strftime (p, sizeof (p), _(" (current time: %c)"), localtime (&t)); setlocale (LC_TIME, "C"); @@ -72,7 +71,8 @@ void crypt_current_time(STATE *s, char *app_name) else *p = '\0'; - snprintf (tmp, sizeof (tmp), _("[-- %s output follows%s --]\n"), NONULL(app_name), p); + snprintf (tmp, sizeof (tmp), _("[-- %s output follows%s --]\n"), + NONULL (app_name), p); state_attach_puts (tmp, s); } @@ -95,11 +95,10 @@ void crypt_forget_passphrase (void) static void disable_coredumps (void) { - struct rlimit rl = {0, 0}; + struct rlimit rl = { 0, 0 }; static short done = 0; - if (!done) - { + if (!done) { setrlimit (RLIMIT_CORE, &rl); done = 1; } @@ -108,7 +107,7 @@ static void disable_coredumps (void) #endif /* HAVE_SETRLIMIT */ -int crypt_valid_passphrase(int flags) +int crypt_valid_passphrase (int flags) { int ret = 0; @@ -127,12 +126,12 @@ int crypt_valid_passphrase(int flags) -int mutt_protect (HEADER *msg, char *keylist) +int mutt_protect (HEADER * msg, char *keylist) { BODY *pbody = NULL, *tmp_pbody = NULL; BODY *tmp_smime_pbody = NULL; BODY *tmp_pgp_pbody = NULL; - int flags = (WithCrypto & APPLICATION_PGP)? msg->security: 0; + int flags = (WithCrypto & APPLICATION_PGP) ? msg->security : 0; int i; if (!WithCrypto) @@ -141,48 +140,51 @@ int mutt_protect (HEADER *msg, char *keylist) if ((msg->security & SIGN) && !crypt_valid_passphrase (msg->security)) return (-1); - if ((WithCrypto & APPLICATION_PGP) && ((msg->security & PGPINLINE) == PGPINLINE)) - { + if ((WithCrypto & APPLICATION_PGP) + && ((msg->security & PGPINLINE) == PGPINLINE)) { /* they really want to send it inline... go for it */ - if (!isendwin ()) mutt_endwin _("Invoking PGP..."); + if (!isendwin ()) + mutt_endwin _("Invoking PGP..."); + pbody = crypt_pgp_traditional_encryptsign (msg->content, flags, keylist); - if (pbody) - { + if (pbody) { msg->content = pbody; return 0; } /* otherwise inline won't work...ask for revert */ - if ((i = query_quadoption (OPT_PGPMIMEAUTO, _("Message can't be sent inline. Revert to using PGP/MIME?"))) != M_YES) - { - mutt_error _("Mail not sent."); - return -1; - } + if ((i = + query_quadoption (OPT_PGPMIMEAUTO, + _ + ("Message can't be sent inline. Revert to using PGP/MIME?"))) + != M_YES) { + mutt_error _("Mail not sent."); + + return -1; + } /* go ahead with PGP/MIME */ } - if (!isendwin ()) mutt_endwin (NULL); + if (!isendwin ()) + mutt_endwin (NULL); if ((WithCrypto & APPLICATION_SMIME)) tmp_smime_pbody = msg->content; if ((WithCrypto & APPLICATION_PGP)) - tmp_pgp_pbody = msg->content; + tmp_pgp_pbody = msg->content; - if (msg->security & SIGN) - { + if (msg->security & SIGN) { if ((WithCrypto & APPLICATION_SMIME) - && (msg->security & APPLICATION_SMIME)) - { + && (msg->security & APPLICATION_SMIME)) { if (!(tmp_pbody = crypt_smime_sign_message (msg->content))) - return -1; + return -1; pbody = tmp_smime_pbody = tmp_pbody; } if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP) - && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) - { + && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) { if (!(tmp_pbody = crypt_pgp_sign_message (msg->content))) return -1; @@ -190,87 +192,77 @@ int mutt_protect (HEADER *msg, char *keylist) pbody = tmp_pgp_pbody = tmp_pbody; } - if (WithCrypto - && (msg->security & APPLICATION_SMIME) - && (msg->security & APPLICATION_PGP)) - { - /* here comes the draft ;-) */ + if (WithCrypto && (msg->security & APPLICATION_SMIME) + && (msg->security & APPLICATION_PGP)) { + /* here comes the draft ;-) */ } } - if (msg->security & ENCRYPT) - { + if (msg->security & ENCRYPT) { if ((WithCrypto & APPLICATION_SMIME) - && (msg->security & APPLICATION_SMIME)) - { + && (msg->security & APPLICATION_SMIME)) { if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody, - keylist))) - { - /* signed ? free it! */ - return (-1); + keylist))) { + /* signed ? free it! */ + return (-1); } /* free tmp_body if messages was signed AND encrypted ... */ - if (tmp_smime_pbody != msg->content && tmp_smime_pbody != tmp_pbody) - { - /* detatch and dont't delete msg->content, - which tmp_smime_pbody->parts after signing. */ - tmp_smime_pbody->parts = tmp_smime_pbody->parts->next; - msg->content->next = NULL; - mutt_free_body (&tmp_smime_pbody); + if (tmp_smime_pbody != msg->content && tmp_smime_pbody != tmp_pbody) { + /* detatch and dont't delete msg->content, + which tmp_smime_pbody->parts after signing. */ + tmp_smime_pbody->parts = tmp_smime_pbody->parts->next; + msg->content->next = NULL; + mutt_free_body (&tmp_smime_pbody); } pbody = tmp_pbody; } if ((WithCrypto & APPLICATION_PGP) - && (msg->security & APPLICATION_PGP)) - { + && (msg->security & APPLICATION_PGP)) { if (!(pbody = crypt_pgp_encrypt_message (tmp_pgp_pbody, keylist, - flags & SIGN))) - { - - /* did we perform a retainable signature? */ - if (flags != msg->security) - { - /* remove the outer multipart layer */ - tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody); - /* get rid of the signature */ - mutt_free_body (&tmp_pgp_pbody->next); - } - - return (-1); + flags & SIGN))) { + + /* did we perform a retainable signature? */ + if (flags != msg->security) { + /* remove the outer multipart layer */ + tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody); + /* get rid of the signature */ + mutt_free_body (&tmp_pgp_pbody->next); + } + + return (-1); } /* destroy temporary signature envelope when doing retainable * signatures. */ - if (flags != msg->security) - { - tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody); - mutt_free_body (&tmp_pgp_pbody->next); + if (flags != msg->security) { + tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody); + mutt_free_body (&tmp_pgp_pbody->next); } } } - if(pbody) - msg->content = pbody; + if (pbody) + msg->content = pbody; return 0; } - - -int mutt_is_multipart_signed (BODY *b) + + +int mutt_is_multipart_signed (BODY * b) { char *p; if (!b || !(b->type == TYPEMULTIPART) || - !b->subtype || ascii_strcasecmp(b->subtype, "signed")) + !b->subtype || ascii_strcasecmp (b->subtype, "signed")) return 0; - if (!(p = mutt_get_parameter("protocol", b->parameter))) + if (!(p = mutt_get_parameter ("protocol", b->parameter))) return 0; if (!(ascii_strcasecmp (p, "multipart/mixed"))) @@ -279,7 +271,7 @@ int mutt_is_multipart_signed (BODY *b) if ((WithCrypto & APPLICATION_PGP) && !(ascii_strcasecmp (p, "application/pgp-signature"))) return PGPSIGN; - + if ((WithCrypto & APPLICATION_SMIME) && !(ascii_strcasecmp (p, "application/x-pkcs7-signature"))) return SMIMESIGN; @@ -289,45 +281,45 @@ int mutt_is_multipart_signed (BODY *b) return 0; } - - -int mutt_is_multipart_encrypted (BODY *b) + + +int mutt_is_multipart_encrypted (BODY * b) { - if ((WithCrypto & APPLICATION_PGP)) - { + if ((WithCrypto & APPLICATION_PGP)) { char *p; - + if (!b || b->type != TYPEMULTIPART || !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") || !(p = mutt_get_parameter ("protocol", b->parameter)) || ascii_strcasecmp (p, "application/pgp-encrypted")) return 0; - - return PGPENCRYPT; + + return PGPENCRYPT; } return 0; } -int mutt_is_application_pgp (BODY *m) +int mutt_is_application_pgp (BODY * m) { int t = 0; char *p; - - if (m->type == TYPEAPPLICATION) - { - if (!ascii_strcasecmp (m->subtype, "pgp") || !ascii_strcasecmp (m->subtype, "x-pgp-message")) - { + + if (m->type == TYPEAPPLICATION) { + if (!ascii_strcasecmp (m->subtype, "pgp") + || !ascii_strcasecmp (m->subtype, "x-pgp-message")) { if ((p = mutt_get_parameter ("x-action", m->parameter)) - && (!ascii_strcasecmp (p, "sign") || !ascii_strcasecmp (p, "signclear"))) - t |= PGPSIGN; + && (!ascii_strcasecmp (p, "sign") + || !ascii_strcasecmp (p, "signclear"))) + t |= PGPSIGN; - if ((p = mutt_get_parameter ("format", m->parameter)) && - !ascii_strcasecmp (p, "keys-only")) - t |= PGPKEY; + if ((p = mutt_get_parameter ("format", m->parameter)) && + !ascii_strcasecmp (p, "keys-only")) + t |= PGPKEY; - if(!t) t |= PGPENCRYPT; /* not necessarily correct, but... */ + if (!t) + t |= PGPENCRYPT; /* not necessarily correct, but... */ } if (!ascii_strcasecmp (m->subtype, "pgp-signed")) @@ -336,12 +328,11 @@ int mutt_is_application_pgp (BODY *m) if (!ascii_strcasecmp (m->subtype, "pgp-keys")) t |= PGPKEY; } - else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0) - { + else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0) { if (((p = mutt_get_parameter ("x-mutt-action", m->parameter)) - || (p = mutt_get_parameter ("x-action", m->parameter)) - || (p = mutt_get_parameter ("action", m->parameter))) - && !ascii_strncasecmp ("pgp-sign", p, 8)) + || (p = mutt_get_parameter ("x-action", m->parameter)) + || (p = mutt_get_parameter ("action", m->parameter))) + && !ascii_strncasecmp ("pgp-sign", p, 8)) t |= PGPSIGN; else if (p && !ascii_strncasecmp ("pgp-encrypt", p, 11)) t |= PGPENCRYPT; @@ -354,34 +345,32 @@ int mutt_is_application_pgp (BODY *m) return t; } -int mutt_is_application_smime (BODY *m) +int mutt_is_application_smime (BODY * m) { - char *t=NULL; - int len, complain=0; + char *t = NULL; + int len, complain = 0; if (!m) return 0; - if ((m->type & TYPEAPPLICATION) && m->subtype) - { + if ((m->type & TYPEAPPLICATION) && m->subtype) { /* S/MIME MIME types don't need x- anymore, see RFC2311 */ if (!ascii_strcasecmp (m->subtype, "x-pkcs7-mime") || - !ascii_strcasecmp (m->subtype, "pkcs7-mime")) - { - if ((t = mutt_get_parameter ("smime-type", m->parameter))) - { - if (!ascii_strcasecmp (t, "enveloped-data")) - return SMIMEENCRYPT; - else if (!ascii_strcasecmp (t, "signed-data")) - return (SMIMESIGN|SMIMEOPAQUE); - else return 0; + !ascii_strcasecmp (m->subtype, "pkcs7-mime")) { + if ((t = mutt_get_parameter ("smime-type", m->parameter))) { + if (!ascii_strcasecmp (t, "enveloped-data")) + return SMIMEENCRYPT; + else if (!ascii_strcasecmp (t, "signed-data")) + return (SMIMESIGN | SMIMEOPAQUE); + else + return 0; } /* Netscape 4.7 uses * Content-Description: S/MIME Encrypted Message * instead of Content-Type parameter */ if (!ascii_strcasecmp (m->description, "S/MIME Encrypted Message")) - return SMIMEENCRYPT; + return SMIMEENCRYPT; complain = 1; } else if (ascii_strcasecmp (m->subtype, "octet-stream")) @@ -389,31 +378,32 @@ int mutt_is_application_smime (BODY *m) t = mutt_get_parameter ("name", m->parameter); - if (!t) t = m->d_filename; - if (!t) t = m->filename; - if (!t) - { + if (!t) + t = m->d_filename; + if (!t) + t = m->filename; + if (!t) { if (complain) - mutt_message (_("S/MIME messages with no hints on content are unsupported.")); + mutt_message (_ + ("S/MIME messages with no hints on content are unsupported.")); return 0; } /* no .p7c, .p10 support yet. */ len = mutt_strlen (t) - 4; - if (len > 0 && *(t+len) == '.') - { + if (len > 0 && *(t + len) == '.') { len++; - if (!ascii_strcasecmp ((t+len), "p7m")) + if (!ascii_strcasecmp ((t + len), "p7m")) #if 0 - return SMIMEENCRYPT; + return SMIMEENCRYPT; #else - /* Not sure if this is the correct thing to do, but - it's required for compatibility with Outlook */ - return (SMIMESIGN|SMIMEOPAQUE); + /* Not sure if this is the correct thing to do, but + it's required for compatibility with Outlook */ + return (SMIMESIGN | SMIMEOPAQUE); #endif - else if (!ascii_strcasecmp ((t+len), "p7s")) - return (SMIMESIGN|SMIMEOPAQUE); + else if (!ascii_strcasecmp ((t + len), "p7s")) + return (SMIMESIGN | SMIMEOPAQUE); } } @@ -425,59 +415,56 @@ int mutt_is_application_smime (BODY *m) -int crypt_query (BODY *m) +int crypt_query (BODY * m) { int t = 0; if (!WithCrypto) return 0; - + if (!m) return 0; - if (m->type == TYPEAPPLICATION) - { + if (m->type == TYPEAPPLICATION) { if ((WithCrypto & APPLICATION_PGP)) - t |= mutt_is_application_pgp(m); - - if ((WithCrypto & APPLICATION_SMIME)) - { - t |= mutt_is_application_smime(m); - if (t && m->goodsig) t |= GOODSIGN; - if (t && m->badsig) t |= BADSIGN; + t |= mutt_is_application_pgp (m); + + if ((WithCrypto & APPLICATION_SMIME)) { + t |= mutt_is_application_smime (m); + if (t && m->goodsig) + t |= GOODSIGN; + if (t && m->badsig) + t |= BADSIGN; } } - else if ((WithCrypto & APPLICATION_PGP) && m->type == TYPETEXT) - { + else if ((WithCrypto & APPLICATION_PGP) && m->type == TYPETEXT) { t |= mutt_is_application_pgp (m); if (t && m->goodsig) t |= GOODSIGN; } - - if (m->type == TYPEMULTIPART) - { - t |= mutt_is_multipart_encrypted(m); + + if (m->type == TYPEMULTIPART) { + t |= mutt_is_multipart_encrypted (m); t |= mutt_is_multipart_signed (m); - if (t && m->goodsig) + if (t && m->goodsig) t |= GOODSIGN; } - if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) - { + if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) { BODY *p; int u, v, w; - - u = m->parts ? 0xffffffff : 0; /* Bits set in all parts */ - w = 0; /* Bits set in any part */ - - for (p = m->parts; p; p = p->next) - { - v = crypt_query (p); - u &= v; w |= v; + + u = m->parts ? 0xffffffff : 0; /* Bits set in all parts */ + w = 0; /* Bits set in any part */ + + for (p = m->parts; p; p = p->next) { + v = crypt_query (p); + u &= v; + w |= v; } t |= u | (w & ~GOODSIGN); - + if ((w & GOODSIGN) && !(u & GOODSIGN)) t |= PARTSIGN; } @@ -488,7 +475,7 @@ int crypt_query (BODY *m) -int crypt_write_signed(BODY *a, STATE *s, const char *tempfile) +int crypt_write_signed (BODY * a, STATE * s, const char *tempfile) { FILE *fp; int c; @@ -498,34 +485,31 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempfile) if (!WithCrypto) return -1; - if (!(fp = safe_fopen (tempfile, "w"))) - { + if (!(fp = safe_fopen (tempfile, "w"))) { mutt_perror (tempfile); return -1; } - + fseek (s->fpin, a->hdr_offset, 0); bytes = a->length + a->offset - a->hdr_offset; hadcr = 0; - while (bytes > 0) - { + while (bytes > 0) { if ((c = fgetc (s->fpin)) == EOF) break; - + bytes--; - - if (c == '\r') + + if (c == '\r') hadcr = 1; - else - { + else { if (c == '\n' && !hadcr) - fputc ('\r', fp); - + fputc ('\r', fp); + hadcr = 0; } - + fputc (c, fp); - + } fclose (fp); @@ -534,36 +518,32 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempfile) -void convert_to_7bit (BODY *a) +void convert_to_7bit (BODY * a) { if (!WithCrypto) return; - while (a) - { - if (a->type == TYPEMULTIPART) - { - if (a->encoding != ENC7BIT) - { + while (a) { + if (a->type == TYPEMULTIPART) { + if (a->encoding != ENC7BIT) { a->encoding = ENC7BIT; - convert_to_7bit(a->parts); + convert_to_7bit (a->parts); } else if ((WithCrypto & APPLICATION_PGP) && option (OPTPGPSTRICTENC)) - convert_to_7bit (a->parts); - } + convert_to_7bit (a->parts); + } else if (a->type == TYPEMESSAGE && - mutt_strcasecmp(a->subtype, "delivery-status")) - { - if(a->encoding != ENC7BIT) - mutt_message_to_7bit (a, NULL); + mutt_strcasecmp (a->subtype, "delivery-status")) { + if (a->encoding != ENC7BIT) + mutt_message_to_7bit (a, NULL); } else if (a->encoding == ENC8BIT) a->encoding = ENCQUOTEDPRINTABLE; else if (a->encoding == ENCBINARY) a->encoding = ENCBASE64; else if (a->content && a->encoding != ENCBASE64 && - (a->content->from || (a->content->space && - option (OPTPGPSTRICTENC)))) + (a->content->from || (a->content->space && + option (OPTPGPSTRICTENC)))) a->encoding = ENCQUOTEDPRINTABLE; a = a->next; } @@ -583,8 +563,7 @@ void crypt_extract_keys_from_messages (HEADER * h) return; mutt_mktemp (tempfname); - if (!(fpout = safe_fopen (tempfname, "w"))) - { + if (!(fpout = safe_fopen (tempfname, "w"))) { mutt_perror (tempfname); return; } @@ -592,100 +571,90 @@ void crypt_extract_keys_from_messages (HEADER * h) if ((WithCrypto & APPLICATION_PGP)) set_option (OPTDONTHANDLEPGPKEYS); - if (!h) - { - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]); - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && - !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]->security)) - { - fclose (fpout); - break; - } - - if ((WithCrypto & APPLICATION_PGP) - && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP)) - { - mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], - M_CM_DECODE|M_CM_CHARCONV, 0); - fflush(fpout); - - mutt_endwin (_("Trying to extract PGP keys...\n")); - crypt_pgp_invoke_import (tempfname); - } - - if ((WithCrypto & APPLICATION_SMIME) - && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME)) - { - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT) - mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], - M_CM_NOHEADER|M_CM_DECODE_CRYPT - |M_CM_DECODE_SMIME, 0); - else - mutt_copy_message (fpout, Context, - Context->hdrs[Context->v2r[i]], 0, 0); - fflush(fpout); + if (!h) { + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]]->tagged) { + mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]); + if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && + !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]-> + security)) { + fclose (fpout); + break; + } + + if ((WithCrypto & APPLICATION_PGP) + && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP)) { + mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], + M_CM_DECODE | M_CM_CHARCONV, 0); + fflush (fpout); + + mutt_endwin (_("Trying to extract PGP keys...\n")); + crypt_pgp_invoke_import (tempfname); + } + + if ((WithCrypto & APPLICATION_SMIME) + && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME)) { + if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT) + mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], + M_CM_NOHEADER | M_CM_DECODE_CRYPT + | M_CM_DECODE_SMIME, 0); + else + mutt_copy_message (fpout, Context, + Context->hdrs[Context->v2r[i]], 0, 0); + fflush (fpout); if (Context->hdrs[Context->v2r[i]]->env->from) - tmp = mutt_expand_aliases (h->env->from); - else if (Context->hdrs[Context->v2r[i]]->env->sender) - tmp = mutt_expand_aliases (Context->hdrs[Context->v2r[i]] - ->env->sender); + tmp = mutt_expand_aliases (h->env->from); + else if (Context->hdrs[Context->v2r[i]]->env->sender) + tmp = mutt_expand_aliases (Context->hdrs[Context->v2r[i]] + ->env->sender); mbox = tmp ? tmp->mailbox : NULL; - if (mbox) - { - mutt_endwin (_("Trying to extract S/MIME certificates...\n")); - crypt_smime_invoke_import (tempfname, mbox); - tmp = NULL; - } - } - - rewind (fpout); + if (mbox) { + mutt_endwin (_("Trying to extract S/MIME certificates...\n")); + crypt_smime_invoke_import (tempfname, mbox); + tmp = NULL; + } + } + + rewind (fpout); } } } - else - { + else { mutt_parse_mime_message (Context, h); - if (!(h->security & ENCRYPT && !crypt_valid_passphrase (h->security))) - { + if (!(h->security & ENCRYPT && !crypt_valid_passphrase (h->security))) { if ((WithCrypto & APPLICATION_PGP) - && (h->security & APPLICATION_PGP)) - { - mutt_copy_message (fpout, Context, h, M_CM_DECODE|M_CM_CHARCONV, 0); - fflush(fpout); - mutt_endwin (_("Trying to extract PGP keys...\n")); - crypt_pgp_invoke_import (tempfname); + && (h->security & APPLICATION_PGP)) { + mutt_copy_message (fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0); + fflush (fpout); + mutt_endwin (_("Trying to extract PGP keys...\n")); + crypt_pgp_invoke_import (tempfname); } if ((WithCrypto & APPLICATION_SMIME) - && (h->security & APPLICATION_SMIME)) - { - if (h->security & ENCRYPT) - mutt_copy_message (fpout, Context, h, M_CM_NOHEADER - |M_CM_DECODE_CRYPT - |M_CM_DECODE_SMIME, 0); - else - mutt_copy_message (fpout, Context, h, 0, 0); - - fflush(fpout); - if (h->env->from) tmp = mutt_expand_aliases (h->env->from); - else if (h->env->sender) tmp = mutt_expand_aliases (h->env->sender); - mbox = tmp ? tmp->mailbox : NULL; - if (mbox) /* else ? */ - { - mutt_message (_("Trying to extract S/MIME certificates...\n")); - crypt_smime_invoke_import (tempfname, mbox); - } + && (h->security & APPLICATION_SMIME)) { + if (h->security & ENCRYPT) + mutt_copy_message (fpout, Context, h, M_CM_NOHEADER + | M_CM_DECODE_CRYPT | M_CM_DECODE_SMIME, 0); + else + mutt_copy_message (fpout, Context, h, 0, 0); + + fflush (fpout); + if (h->env->from) + tmp = mutt_expand_aliases (h->env->from); + else if (h->env->sender) + tmp = mutt_expand_aliases (h->env->sender); + mbox = tmp ? tmp->mailbox : NULL; + if (mbox) { /* else ? */ + mutt_message (_("Trying to extract S/MIME certificates...\n")); + crypt_smime_invoke_import (tempfname, mbox); + } } } } - + fclose (fpout); - if (isendwin()) + if (isendwin ()) mutt_any_key_to_continue (NULL); mutt_unlink (tempfname); @@ -696,7 +665,7 @@ void crypt_extract_keys_from_messages (HEADER * h) -int crypt_get_keys (HEADER *msg, char **keylist) +int crypt_get_keys (HEADER * msg, char **keylist) { /* Do a quick check to make sure that we can find all of the encryption * keys if the user has requested this service. @@ -710,43 +679,38 @@ int crypt_get_keys (HEADER *msg, char **keylist) *keylist = NULL; - if (msg->security & ENCRYPT) - { - if ((WithCrypto & APPLICATION_PGP) - && (msg->security & APPLICATION_PGP)) - { - if ((*keylist = crypt_pgp_findkeys (msg->env->to, msg->env->cc, - msg->env->bcc)) == NULL) - return (-1); - unset_option (OPTPGPCHECKTRUST); - } - if ((WithCrypto & APPLICATION_SMIME) - && (msg->security & APPLICATION_SMIME)) - { - if ((*keylist = crypt_smime_findkeys (msg->env->to, msg->env->cc, - msg->env->bcc)) == NULL) - return (-1); - } + if (msg->security & ENCRYPT) { + if ((WithCrypto & APPLICATION_PGP) + && (msg->security & APPLICATION_PGP)) { + if ((*keylist = crypt_pgp_findkeys (msg->env->to, msg->env->cc, + msg->env->bcc)) == NULL) + return (-1); + unset_option (OPTPGPCHECKTRUST); + } + if ((WithCrypto & APPLICATION_SMIME) + && (msg->security & APPLICATION_SMIME)) { + if ((*keylist = crypt_smime_findkeys (msg->env->to, msg->env->cc, + msg->env->bcc)) == NULL) + return (-1); + } } - + return (0); } -static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n) +static void crypt_fetch_signatures (BODY *** signatures, BODY * a, int *n) { if (!WithCrypto) return; - for (; a; a = a->next) - { + for (; a; a = a->next) { if (a->type == TYPEMULTIPART) crypt_fetch_signatures (signatures, a->parts, n); - else - { - if((*n % 5) == 0) - safe_realloc (signatures, (*n + 6) * sizeof (BODY **)); + else { + if ((*n % 5) == 0) + safe_realloc (signatures, (*n + 6) * sizeof (BODY **)); (*signatures)[(*n)++] = a; } @@ -758,13 +722,13 @@ static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n) * This routine verifies a "multipart/signed" body. */ -void mutt_signed_handler (BODY *a, STATE *s) +void mutt_signed_handler (BODY * a, STATE * s) { char tempfile[_POSIX_PATH_MAX]; char *protocol; int protocol_major = TYPEOTHER; char *protocol_minor = NULL; - + BODY *b = a; BODY **signatures = NULL; int sigcnt = 0; @@ -778,26 +742,25 @@ void mutt_signed_handler (BODY *a, STATE *s) a = a->parts; /* extract the protocol information */ - - if (protocol) - { + + if (protocol) { char major[STRING]; char *t; - if ((protocol_minor = strchr (protocol, '/'))) protocol_minor++; - - strfcpy (major, protocol, sizeof(major)); - if((t = strchr(major, '/'))) + if ((protocol_minor = strchr (protocol, '/'))) + protocol_minor++; + + strfcpy (major, protocol, sizeof (major)); + if ((t = strchr (major, '/'))) *t = '\0'; - + protocol_major = mutt_check_mime_type (major); } /* consistency check */ - if (!(a && a->next && a->next->type == protocol_major && - !mutt_strcasecmp (a->next->subtype, protocol_minor))) - { + if (!(a && a->next && a->next->type == protocol_major && + !mutt_strcasecmp (a->next->subtype, protocol_minor))) { state_attach_puts (_("[-- Error: " "Inconsistent multipart/signed structure! --]\n\n"), s); @@ -805,72 +768,64 @@ void mutt_signed_handler (BODY *a, STATE *s) return; } - + if ((WithCrypto & APPLICATION_PGP) && protocol_major == TYPEAPPLICATION - && !mutt_strcasecmp (protocol_minor, "pgp-signature")) - ; + && !mutt_strcasecmp (protocol_minor, "pgp-signature")); else if ((WithCrypto & APPLICATION_SMIME) && protocol_major == TYPEAPPLICATION - && !(mutt_strcasecmp (protocol_minor, "x-pkcs7-signature") - && mutt_strcasecmp (protocol_minor, "pkcs7-signature"))) - ; + && !(mutt_strcasecmp (protocol_minor, "x-pkcs7-signature") + && mutt_strcasecmp (protocol_minor, "pkcs7-signature"))); else if (protocol_major == TYPEMULTIPART - && !mutt_strcasecmp (protocol_minor, "mixed")) - ; - else - { + && !mutt_strcasecmp (protocol_minor, "mixed")); + else { state_printf (s, _("[-- Error: " "Unknown multipart/signed protocol %s! --]\n\n"), protocol); mutt_body_handler (a, s); return; } - - if (s->flags & M_DISPLAY) - { - + + if (s->flags & M_DISPLAY) { + crypt_fetch_signatures (&signatures, a->next, &sigcnt); - - if (sigcnt) - { + + if (sigcnt) { mutt_mktemp (tempfile); - if (crypt_write_signed (a, s, tempfile) == 0) - { - for (i = 0; i < sigcnt; i++) - { - if ((WithCrypto & APPLICATION_PGP) - && signatures[i]->type == TYPEAPPLICATION - && !mutt_strcasecmp (signatures[i]->subtype, "pgp-signature")) - { - if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0) - goodsig = 0; - - continue; - } - - if ((WithCrypto & APPLICATION_SMIME) - && signatures[i]->type == TYPEAPPLICATION - && (!mutt_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature") - || !mutt_strcasecmp(signatures[i]->subtype, "pkcs7-signature"))) - { - if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0) - goodsig = 0; - - continue; - } - - state_printf (s, _("[-- Warning: " + if (crypt_write_signed (a, s, tempfile) == 0) { + for (i = 0; i < sigcnt; i++) { + if ((WithCrypto & APPLICATION_PGP) + && signatures[i]->type == TYPEAPPLICATION + && !mutt_strcasecmp (signatures[i]->subtype, "pgp-signature")) { + if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0) + goodsig = 0; + + continue; + } + + if ((WithCrypto & APPLICATION_SMIME) + && signatures[i]->type == TYPEAPPLICATION + && + (!mutt_strcasecmp (signatures[i]->subtype, "x-pkcs7-signature") + || !mutt_strcasecmp (signatures[i]->subtype, + "pkcs7-signature"))) { + if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0) + goodsig = 0; + + continue; + } + + state_printf (s, _("[-- Warning: " "We can't verify %s/%s signatures. --]\n\n"), - TYPE(signatures[i]), signatures[i]->subtype); - } + TYPE (signatures[i]), signatures[i]->subtype); + } } - + mutt_unlink (tempfile); b->goodsig = goodsig; - b->badsig = !goodsig; - + b->badsig = !goodsig; + /* Now display the signed body */ state_attach_puts (_("[-- The following data is signed --]\n\n"), s); @@ -878,13 +833,12 @@ void mutt_signed_handler (BODY *a, STATE *s) FREE (&signatures); } else - state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"), s); + state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"), + s); } - + mutt_body_handler (a, s); - + if (s->flags & M_DISPLAY && sigcnt) state_attach_puts (_("\n[-- End of signed data --]\n"), s); } - - diff --git a/cryptglue.c b/cryptglue.c index f6a1bab..28e8492 100644 --- a/cryptglue.c +++ b/cryptglue.c @@ -61,37 +61,36 @@ void crypt_init (void) #ifdef CRYPT_BACKEND_CLASSIC_PGP if ( #ifdef CRYPT_BACKEND_GPGME - (! option (OPTCRYPTUSEGPGME)) + (!option (OPTCRYPTUSEGPGME)) #else 1 #endif - ) + ) crypto_module_register (&crypt_mod_pgp_classic); #endif #ifdef CRYPT_BACKEND_CLASSIC_SMIME if ( #ifdef CRYPT_BACKEND_GPGME - (! option (OPTCRYPTUSEGPGME)) + (!option (OPTCRYPTUSEGPGME)) #else 1 #endif - ) + ) crypto_module_register (&crypt_mod_smime_classic); #endif - if (option (OPTCRYPTUSEGPGME)) - { + if (option (OPTCRYPTUSEGPGME)) { #ifdef CRYPT_BACKEND_GPGME - crypto_module_register (&crypt_mod_pgp_gpgme); - crypto_module_register (&crypt_mod_smime_gpgme); + crypto_module_register (&crypt_mod_pgp_gpgme); + crypto_module_register (&crypt_mod_smime_gpgme); #else - mutt_message (_("\"crypt_use_gpgme\" set" - " but not build with GPGME support.")); - if (mutt_any_key_to_continue (NULL) == -1) - mutt_exit(1); + mutt_message (_("\"crypt_use_gpgme\" set" + " but not build with GPGME support.")); + if (mutt_any_key_to_continue (NULL) == -1) + mutt_exit (1); #endif - } + } #if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME if (CRYPT_MOD_CALL_CHECK (PGP, init)) @@ -106,14 +105,16 @@ void crypt_init (void) /* Show a message that a backend will be invoked. */ void crypt_invoke_message (int type) { - if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP)) + if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP)) { mutt_message _("Invoking PGP..."); - else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME)) + } + else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME)) { mutt_message _("Invoking SMIME..."); + } } + - /* PGP @@ -138,7 +139,7 @@ int crypt_pgp_valid_passphrase (void) /* Decrypt a PGP/MIME message. */ -int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d) { if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime)) return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d); @@ -147,28 +148,28 @@ int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) } /* MIME handler for the application/pgp content-type. */ -void crypt_pgp_application_pgp_handler (BODY *m, STATE *s) +void crypt_pgp_application_pgp_handler (BODY * m, STATE * s) { if (CRYPT_MOD_CALL_CHECK (PGP, application_handler)) (CRYPT_MOD_CALL (PGP, application_handler)) (m, s); } /* MIME handler for an PGP/MIME encrypted message. */ -void crypt_pgp_encrypted_handler (BODY *a, STATE *s) +void crypt_pgp_encrypted_handler (BODY * a, STATE * s) { if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler)) (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s); } /* fixme: needs documentation. */ -void crypt_pgp_invoke_getkeys (ADDRESS *addr) +void crypt_pgp_invoke_getkeys (ADDRESS * addr) { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys)) (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr); } /* Check for a traditional PGP message in body B. */ -int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) +int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only) { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional)) return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only); @@ -177,10 +178,11 @@ int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) } /* fixme: needs documentation. */ -BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) +BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign)) - return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags, keylist); + return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags, + keylist); return NULL; } @@ -196,7 +198,7 @@ BODY *crypt_pgp_make_key_attachment (char *tempf) /* This routine attempts to find the keyids of the recipients of a message. It returns NULL if any of the keys can not be found. */ -char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +char *crypt_pgp_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) { if (CRYPT_MOD_CALL_CHECK (PGP, findkeys)) return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc); @@ -205,7 +207,7 @@ char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) } /* Create a new body with a PGP signed message from A. */ -BODY *crypt_pgp_sign_message (BODY *a) +BODY *crypt_pgp_sign_message (BODY * a) { if (CRYPT_MOD_CALL_CHECK (PGP, sign_message)) return (CRYPT_MOD_CALL (PGP, sign_message)) (a); @@ -215,7 +217,7 @@ BODY *crypt_pgp_sign_message (BODY *a) /* Warning: A is no longer freed in this routine, you need to free it later. This is necessary for $fcc_attach. */ -BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign) +BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign) { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message)) return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign); @@ -231,7 +233,7 @@ void crypt_pgp_invoke_import (const char *fname) } /* fixme: needs documentation */ -int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf) { if (CRYPT_MOD_CALL_CHECK (PGP, verify_one)) return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf); @@ -240,7 +242,7 @@ int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) } -int crypt_pgp_send_menu (HEADER *msg, int *redraw) +int crypt_pgp_send_menu (HEADER * msg, int *redraw) { if (CRYPT_MOD_CALL_CHECK (PGP, send_menu)) return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw); @@ -250,14 +252,16 @@ int crypt_pgp_send_menu (HEADER *msg, int *redraw) /* fixme: needs documentation */ -void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top) +void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag, + BODY * top) { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list)) - (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag, top); + (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag, + top); } + - /* S/MIME @@ -281,7 +285,7 @@ int crypt_smime_valid_passphrase (void) } /* Decrypt am S/MIME message. */ -int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d) { if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime)) return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d); @@ -290,28 +294,28 @@ int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) } /* MIME handler for the application/smime content-type. */ -void crypt_smime_application_smime_handler (BODY *m, STATE *s) +void crypt_smime_application_smime_handler (BODY * m, STATE * s) { if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler)) (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s); } /* MIME handler for an PGP/MIME encrypted message. */ -void crypt_smime_encrypted_handler (BODY *a, STATE *s) +void crypt_smime_encrypted_handler (BODY * a, STATE * s) { if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler)) (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s); } /* fixme: Needs documentation. */ -void crypt_smime_getkeys (ENVELOPE *env) +void crypt_smime_getkeys (ENVELOPE * env) { if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys)) (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env); } /* Check that the sender matches. */ -int crypt_smime_verify_sender(HEADER *h) +int crypt_smime_verify_sender (HEADER * h) { if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender)) return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h); @@ -321,7 +325,7 @@ int crypt_smime_verify_sender(HEADER *h) /* This routine attempts to find the keyids of the recipients of a message. It returns NULL if any of the keys can not be found. */ -char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +char *crypt_smime_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) { if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys)) return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc); @@ -330,7 +334,7 @@ char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) } /* fixme: Needs documentation. */ -BODY *crypt_smime_sign_message (BODY *a) +BODY *crypt_smime_sign_message (BODY * a) { if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message)) return (CRYPT_MOD_CALL (SMIME, sign_message)) (a); @@ -339,7 +343,7 @@ BODY *crypt_smime_sign_message (BODY *a) } /* fixme: needs documentation. */ -BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist) +BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist) { if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity)) return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist); @@ -355,7 +359,7 @@ void crypt_smime_invoke_import (char *infile, char *mailbox) } /* fixme: needs documentation */ -int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf) { if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one)) return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf); @@ -363,7 +367,7 @@ int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) return -1; } -int crypt_smime_send_menu (HEADER *msg, int *redraw) +int crypt_smime_send_menu (HEADER * msg, int *redraw) { if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu)) return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw); diff --git a/curs_lib.c b/curs_lib.c index 6601ce8..0678d28 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -68,8 +68,7 @@ void mutt_refresh (void) customize this is of course the Mutt way. */ void mutt_need_hard_redraw (void) { - if (!getenv ("DISPLAY")) - { + if (!getenv ("DISPLAY")) { keypad (stdscr, TRUE); clearok (stdscr, TRUE); set_option (OPTNEEDREDRAW); @@ -79,9 +78,9 @@ void mutt_need_hard_redraw (void) event_t mutt_getch (void) { int ch; - event_t err = {-1, OP_NULL }, ret; + event_t err = { -1, OP_NULL }, ret; - if (!option(OPTUNBUFFEREDINPUT) && UngetCount) + if (!option (OPTUNBUFFEREDINPUT) && UngetCount) return (KeyEvent[--UngetCount]); SigInt = 0; @@ -98,11 +97,10 @@ event_t mutt_getch (void) if (SigInt) mutt_query_exit (); - if(ch == ERR) + if (ch == ERR) return err; - - if ((ch & 0x80) && option (OPTMETAKEY)) - { + + if ((ch & 0x80) && option (OPTMETAKEY)) { /* send ALT-x as ESC-x */ ch &= ~0x80; mutt_ungetch (ch, 0); @@ -116,57 +114,59 @@ event_t mutt_getch (void) return (ch == ctrl ('G') ? err : ret); } -int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles) +int _mutt_get_field ( /* const */ char *field, char *buf, size_t buflen, + int complete, int multiple, char ***files, int *numfiles) { int ret; int x, y; - ENTER_STATE *es = mutt_new_enter_state(); - - do - { - CLEARLINE (LINES-1); + ENTER_STATE *es = mutt_new_enter_state (); + + do { + CLEARLINE (LINES - 1); addstr (field); mutt_refresh (); getyx (stdscr, y, x); - ret = _mutt_enter_string (buf, buflen, y, x, complete, multiple, files, numfiles, es); + ret = + _mutt_enter_string (buf, buflen, y, x, complete, multiple, files, + numfiles, es); } while (ret == 1); - CLEARLINE (LINES-1); + CLEARLINE (LINES - 1); mutt_free_enter_state (&es); - + return (ret); } int mutt_get_password (char *msg, char *buf, size_t buflen) { int rc; - - CLEARLINE (LINES-1); + + CLEARLINE (LINES - 1); addstr (msg); set_option (OPTUNBUFFEREDINPUT); rc = mutt_enter_string (buf, buflen, LINES - 1, mutt_strlen (msg), M_PASS); unset_option (OPTUNBUFFEREDINPUT); - CLEARLINE (LINES-1); + CLEARLINE (LINES - 1); return (rc); } void mutt_clear_error (void) { Errorbuf[0] = 0; - if (!option(OPTNOCURSES)) - CLEARLINE (LINES-1); + if (!option (OPTNOCURSES)) + CLEARLINE (LINES - 1); } static void fix_end_of_file (const char *data) { FILE *fp; int c; - + if ((fp = safe_fopen (data, "a+")) == NULL) return; - fseek (fp,-1,SEEK_END); - if ((c = fgetc(fp)) != '\n') + fseek (fp, -1, SEEK_END); + if ((c = fgetc (fp)) != '\n') fputc ('\n', fp); safe_fclose (&fp); } @@ -174,7 +174,7 @@ static void fix_end_of_file (const char *data) void mutt_edit_file (const char *editor, const char *data) { char cmd[LONG_STRING]; - + mutt_endwin (NULL); mutt_expand_file_fmt (cmd, sizeof (cmd), editor, data); if (mutt_system (cmd) == -1) @@ -201,14 +201,14 @@ int mutt_yesorno (const char *msg, int def) char answer[2]; answer[1] = 0; - + reyes_ok = (expr = nl_langinfo (YESEXPR)) && expr[0] == '^' && - !regcomp (&reyes, expr, REG_NOSUB|REG_EXTENDED); + !regcomp (&reyes, expr, REG_NOSUB | REG_EXTENDED); reno_ok = (expr = nl_langinfo (NOEXPR)) && expr[0] == '^' && - !regcomp (&reno, expr, REG_NOSUB|REG_EXTENDED); + !regcomp (&reno, expr, REG_NOSUB | REG_EXTENDED); #endif - CLEARLINE(LINES-1); + CLEARLINE (LINES - 1); /* * In order to prevent the default answer to the question to wrapped @@ -217,60 +217,53 @@ int mutt_yesorno (const char *msg, int def) * to fit. */ answer_string = safe_malloc (COLS + 1); - snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_YES ? no : yes); + snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, + def == M_YES ? no : yes); answer_string_len = strlen (answer_string); printw ("%.*s%s", COLS - answer_string_len, msg, answer_string); FREE (&answer_string); - FOREVER - { + FOREVER { mutt_refresh (); ch = mutt_getch (); if (CI_is_return (ch.ch)) break; - if (ch.ch == -1) - { + if (ch.ch == -1) { def = -1; break; } #ifdef HAVE_LANGINFO_YESEXPR answer[0] = ch.ch; - if (reyes_ok ? - (regexec (& reyes, answer, 0, 0, 0) == 0) : + if (reyes_ok ? (regexec (&reyes, answer, 0, 0, 0) == 0) : #else if ( #endif - (tolower (ch.ch) == 'y')) - { + (tolower (ch.ch) == 'y')) { def = M_YES; break; } else if ( #ifdef HAVE_LANGINFO_YESEXPR - reno_ok ? - (regexec (& reno, answer, 0, 0, 0) == 0) : + reno_ok ? (regexec (&reno, answer, 0, 0, 0) == 0) : #endif - (tolower (ch.ch) == 'n')) - { + (tolower (ch.ch) == 'n')) { def = M_NO; break; } - else - { - BEEP(); + else { + BEEP (); } } -#ifdef HAVE_LANGINFO_YESEXPR +#ifdef HAVE_LANGINFO_YESEXPR if (reyes_ok) - regfree (& reyes); + regfree (&reyes); if (reno_ok) - regfree (& reno); + regfree (&reno); #endif - if (def != -1) - { + if (def != -1) { addstr ((char *) (def == M_YES ? yes : no)); mutt_refresh (); } @@ -283,13 +276,12 @@ void mutt_query_exit (void) mutt_flushinp (); curs_set (1); if (Timeout) - timeout (-1); /* restore blocking operation */ - if (mutt_yesorno (_("Exit Mutt-ng?"), M_YES) == M_YES) - { + timeout (-1); /* restore blocking operation */ + if (mutt_yesorno (_("Exit Mutt-ng?"), M_YES) == M_YES) { endwin (); exit (1); } - mutt_clear_error(); + mutt_clear_error (); mutt_curs_set (-1); SigInt = 0; } @@ -302,17 +294,16 @@ void mutt_curses_error (const char *fmt, ...) va_start (ap, fmt); vsnprintf (Errorbuf, sizeof (Errorbuf), fmt, ap); va_end (ap); - + dprint (1, (debugfile, "%s\n", Errorbuf)); mutt_format_string (TmpErrorbuf, sizeof (TmpErrorbuf), - 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); - snprintf(Errorbuf,sizeof(Errorbuf),"%s",TmpErrorbuf); /* overkill */ + 0, COLS - 2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); + snprintf (Errorbuf, sizeof (Errorbuf), "%s", TmpErrorbuf); /* overkill */ - if (!option (OPTKEEPQUIET)) - { + if (!option (OPTKEEPQUIET)) { BEEP (); SETCOLOR (MT_COLOR_ERROR); - mvaddstr (LINES-1, 0, Errorbuf); + mvaddstr (LINES - 1, 0, Errorbuf); clrtoeol (); SETCOLOR (MT_COLOR_NORMAL); mutt_refresh (); @@ -331,11 +322,10 @@ void mutt_curses_message (const char *fmt, ...) va_end (ap); mutt_format_string (TmpErrorbuf, sizeof (TmpErrorbuf), - 0, COLS-2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); - snprintf(Errorbuf,sizeof(Errorbuf),"%s",TmpErrorbuf); /* overkill */ + 0, COLS - 2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); + snprintf (Errorbuf, sizeof (Errorbuf), "%s", TmpErrorbuf); /* overkill */ - if (!option (OPTKEEPQUIET)) - { + if (!option (OPTKEEPQUIET)) { SETCOLOR (MT_COLOR_MESSAGE); mvaddstr (LINES - 1, 0, Errorbuf); clrtoeol (); @@ -350,26 +340,24 @@ void mutt_show_error (void) { if (option (OPTKEEPQUIET)) return; - + SETCOLOR (option (OPTMSGERR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); - CLEARLINE (LINES-1); + CLEARLINE (LINES - 1); addstr (Errorbuf); SETCOLOR (MT_COLOR_NORMAL); } void mutt_endwin (const char *msg) { - if (!option (OPTNOCURSES)) - { + if (!option (OPTNOCURSES)) { CLEARLINE (LINES - 1); - + attrset (A_NORMAL); mutt_refresh (); endwin (); } - - if (msg && *msg) - { + + if (msg && *msg) { puts (msg); fflush (stdout); } @@ -379,8 +367,8 @@ void mutt_perror (const char *s) { char *p = strerror (errno); - dprint (1, (debugfile, "%s: %s (errno = %d)\n", s, - p ? p : "unknown error", errno)); + dprint (1, (debugfile, "%s: %s (errno = %d)\n", s, + p ? p : "unknown error", errno)); mutt_error ("%s: %s (errno = %d)", s, p ? p : _("unknown error"), errno); } @@ -392,7 +380,7 @@ int mutt_any_key_to_continue (const char *s) f = open ("/dev/tty", O_RDONLY); tcgetattr (f, &t); - memcpy ((void *)&old, (void *)&t, sizeof(struct termios)); /* save original state */ + memcpy ((void *) &old, (void *) &t, sizeof (struct termios)); /* save original state */ t.c_lflag &= ~(ICANON | ECHO); t.c_cc[VMIN] = 1; t.c_cc[VTIME] = 0; @@ -413,22 +401,18 @@ int mutt_any_key_to_continue (const char *s) } int mutt_do_pager (const char *banner, - const char *tempfile, - int do_color, - pager_t *info) + const char *tempfile, int do_color, pager_t * info) { int rc; - + if (!Pager || mutt_strcmp (Pager, "builtin") == 0) rc = mutt_pager (banner, tempfile, do_color, info); - else - { + else { char cmd[STRING]; - + mutt_endwin (NULL); - mutt_expand_file_fmt (cmd, sizeof(cmd), Pager, tempfile); - if (mutt_system (cmd) == -1) - { + mutt_expand_file_fmt (cmd, sizeof (cmd), Pager, tempfile); + if (mutt_system (cmd) == -1) { mutt_error (_("Error running \"%s\"!"), cmd); rc = -1; } @@ -440,38 +424,39 @@ int mutt_do_pager (const char *banner, return rc; } -int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy, int multiple, char ***files, int *numfiles) +int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, + int *redraw, int buffy, int multiple, char ***files, + int *numfiles) { event_t ch; - mvaddstr (LINES-1, 0, (char *) prompt); + mvaddstr (LINES - 1, 0, (char *) prompt); addstr (_(" ('?' for list): ")); if (buf[0]) addstr (buf); clrtoeol (); mutt_refresh (); - ch = mutt_getch(); - if (ch.ch == -1) - { - CLEARLINE (LINES-1); + ch = mutt_getch (); + if (ch.ch == -1) { + CLEARLINE (LINES - 1); return (-1); } - else if (ch.ch == '?') - { + else if (ch.ch == '?') { mutt_refresh (); buf[0] = 0; - _mutt_select_file (buf, blen, M_SEL_FOLDER | (multiple ? M_SEL_MULTI : 0), + _mutt_select_file (buf, blen, M_SEL_FOLDER | (multiple ? M_SEL_MULTI : 0), files, numfiles); *redraw = REDRAW_FULL; } - else - { + else { char *pc = safe_malloc (mutt_strlen (prompt) + 3); - sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ + sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */ mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0); - if (_mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, numfiles) + if (_mutt_get_field + (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, + numfiles) != 0) buf[0] = 0; MAYBE_REDRAW (*redraw); @@ -489,7 +474,7 @@ void mutt_ungetch (int ch, int op) tmp.op = op; if (UngetCount >= UngetBufLen) - safe_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof(event_t)); + safe_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof (event_t)); KeyEvent[UngetCount++] = tmp; } @@ -509,15 +494,15 @@ void mutt_flushinp (void) void mutt_curs_set (int cursor) { static int SavedCursor = 1; - + if (cursor < 0) cursor = SavedCursor; else SavedCursor = cursor; - + if (curs_set (cursor) == ERR) { - if (cursor == 1) /* cnorm */ - curs_set (2); /* cvvis */ + if (cursor == 1) /* cnorm */ + curs_set (2); /* cvvis */ } } #endif @@ -530,25 +515,20 @@ int mutt_multi_choice (char *prompt, char *letters) mvaddstr (LINES - 1, 0, prompt); clrtoeol (); - FOREVER - { + FOREVER { mutt_refresh (); - ch = mutt_getch (); - if (ch.ch == -1 || CI_is_return (ch.ch)) - { + ch = mutt_getch (); + if (ch.ch == -1 || CI_is_return (ch.ch)) { choice = -1; break; } - else - { + else { p = strchr (letters, ch.ch); - if (p) - { + if (p) { choice = p - letters + 1; break; } - else if (ch.ch <= '9' && ch.ch > '0') - { + else if (ch.ch <= '9' && ch.ch > '0') { choice = ch.ch - '0'; if (choice <= mutt_strlen (letters)) break; @@ -567,14 +547,14 @@ int mutt_multi_choice (char *prompt, char *letters) int mutt_addwch (wchar_t wc) { - char buf[MB_LEN_MAX*2]; + char buf[MB_LEN_MAX * 2]; mbstate_t mbstate; size_t n1, n2; memset (&mbstate, 0, sizeof (mbstate)); - if ((n1 = wcrtomb (buf, wc, &mbstate)) == (size_t)(-1) || - (n2 = wcrtomb (buf + n1, 0, &mbstate)) == (size_t)(-1)) - return -1; /* ERR */ + if ((n1 = wcrtomb (buf, wc, &mbstate)) == (size_t) (-1) || + (n2 = wcrtomb (buf + n1, 0, &mbstate)) == (size_t) (-1)) + return -1; /* ERR */ else return addstr (buf); } @@ -590,8 +570,7 @@ int mutt_addwch (wchar_t wc) void mutt_format_string (char *dest, size_t destlen, int min_width, int max_width, int right_justify, char m_pad_char, - const char *s, size_t n, - int arboreal) + const char *s, size_t n, int arboreal) { char *p; wchar_t wc; @@ -600,49 +579,43 @@ void mutt_format_string (char *dest, size_t destlen, char scratch[MB_LEN_MAX]; mbstate_t mbstate1, mbstate2; - memset(&mbstate1, 0, sizeof (mbstate1)); - memset(&mbstate2, 0, sizeof (mbstate2)); + memset (&mbstate1, 0, sizeof (mbstate1)); + memset (&mbstate2, 0, sizeof (mbstate2)); --destlen; p = dest; - for (; n && (k = mbrtowc (&wc, s, n, &mbstate1)); s += k, n -= k) - { - if (k == (size_t)(-1) || k == (size_t)(-2)) - { - k = (k == (size_t)(-1)) ? 1 : n; + for (; n && (k = mbrtowc (&wc, s, n, &mbstate1)); s += k, n -= k) { + if (k == (size_t) (-1) || k == (size_t) (-2)) { + k = (k == (size_t) (-1)) ? 1 : n; wc = replacement_char (); } if (arboreal && wc < M_TREE_MAX) - w = 1; /* hack */ - else - { + w = 1; /* hack */ + else { if (!IsWPrint (wc)) - wc = '?'; + wc = '?'; w = wcwidth (wc); } - if (w >= 0) - { + if (w >= 0) { if (w > max_width || (k2 = wcrtomb (scratch, wc, &mbstate2)) > destlen) break; min_width -= w; max_width -= w; strncpy (p, scratch, k2); - p += k2; + p += k2; destlen -= k2; } } - w = (int)destlen < min_width ? destlen : min_width; + w = (int) destlen < min_width ? destlen : min_width; if (w <= 0) *p = '\0'; - else if (right_justify) - { + else if (right_justify) { p[w] = '\0'; while (--p >= dest) p[w] = *p; while (--w >= 0) dest[w] = m_pad_char; } - else - { + else { while (--w >= 0) *p++ = m_pad_char; *p = '\0'; @@ -659,9 +632,7 @@ void mutt_format_string (char *dest, size_t destlen, static void mutt_format_s_x (char *dest, size_t destlen, - const char *prefix, - const char *s, - int arboreal) + const char *prefix, const char *s, int arboreal) { int right_justify = 1; char *p; @@ -671,8 +642,7 @@ static void mutt_format_s_x (char *dest, if (*prefix == '-') ++prefix, right_justify = 0; min_width = strtol (prefix, &p, 10); - if (*p == '.') - { + if (*p == '.') { prefix = p + 1; max_width = strtol (prefix, &p, 10); if (p <= prefix) @@ -684,17 +654,13 @@ static void mutt_format_s_x (char *dest, } void mutt_format_s (char *dest, - size_t destlen, - const char *prefix, - const char *s) + size_t destlen, const char *prefix, const char *s) { mutt_format_s_x (dest, destlen, prefix, s, 0); } void mutt_format_s_tree (char *dest, - size_t destlen, - const char *prefix, - const char *s) + size_t destlen, const char *prefix, const char *s) { mutt_format_s_x (dest, destlen, prefix, s, 1); } @@ -713,21 +679,18 @@ void mutt_paddstr (int n, const char *s) mbstate_t mbstate; memset (&mbstate, 0, sizeof (mbstate)); - for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k) - { - if (k == (size_t)(-1) || k == (size_t)(-2)) - { - k = (k == (size_t)(-1)) ? 1 : len; + for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k) { + if (k == (size_t) (-1) || k == (size_t) (-2)) { + k = (k == (size_t) (-1)) ? 1 : len; wc = replacement_char (); } if (!IsWPrint (wc)) wc = '?'; w = wcwidth (wc); - if (w >= 0) - { + if (w >= 0) { if (w > n) break; - addnstr ((char *)s, k); + addnstr ((char *) s, k); n -= w; } } @@ -747,16 +710,15 @@ int mutt_strwidth (const char *s) size_t k, n; mbstate_t mbstate; - if (!s) return 0; + if (!s) + return 0; n = mutt_strlen (s); memset (&mbstate, 0, sizeof (mbstate)); - for (w=0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) - { - if (k == (size_t)(-1) || k == (size_t)(-2)) - { - k = (k == (size_t)(-1)) ? 1 : n; + for (w = 0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) { + if (k == (size_t) (-1) || k == (size_t) (-2)) { + k = (k == (size_t) (-1)) ? 1 : n; wc = replacement_char (); } if (!IsWPrint (wc)) diff --git a/curs_main.c b/curs_main.c index 1e50716..7720241 100644 --- a/curs_main.c +++ b/curs_main.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -57,38 +57,39 @@ static const char *No_mailbox_is_open = N_("No mailbox is open."); static const char *There_are_no_messages = N_("There are no messages."); static const char *Mailbox_is_read_only = N_("Mailbox is read-only."); -static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode."); +static const char *Function_not_permitted_in_attach_message_mode = +N_("Function not permitted in attach-message mode."); static const char *No_visible = N_("No visible messages."); #define CHECK_MSGCOUNT if (!Context) \ { \ mutt_flushinp (); \ - mutt_error _(No_mailbox_is_open); \ + mutt_error(_(No_mailbox_is_open)); \ break; \ } \ else if (!Context->msgcount) \ { \ mutt_flushinp (); \ - mutt_error _(There_are_no_messages); \ + mutt_error(_(There_are_no_messages)); \ break; \ } #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \ {\ mutt_flushinp (); \ - mutt_error _(No_visible); \ + mutt_error(_(No_visible)); \ break; \ } - + #define CHECK_READONLY if (Context->readonly) \ { \ mutt_flushinp (); \ - mutt_error _(Mailbox_is_read_only); \ + mutt_error(_(Mailbox_is_read_only)); \ break; \ } -#ifdef USE_IMAP +#ifdef USE_IMAP /* the error message returned here could be better. */ #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \ if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \ @@ -102,7 +103,7 @@ static const char *No_visible = N_("No visible messages."); #define CHECK_ATTACH if(option(OPTATTACHMSG)) \ {\ mutt_flushinp (); \ - mutt_error _(Function_not_permitted_in_attach_message_mode); \ + mutt_error(_(Function_not_permitted_in_attach_message_mode)); \ break; \ } @@ -113,38 +114,36 @@ static const char *No_visible = N_("No visible messages."); extern const char *ReleaseDate; extern size_t UngetCount; -static void set_xterm_title_bar(char *title) +static void set_xterm_title_bar (char *title) { - fputs("\033]2;", stdout); - fputs(title, stdout); - fputs("\007", stdout); - fflush(stdout); + fputs ("\033]2;", stdout); + fputs (title, stdout); + fputs ("\007", stdout); + fflush (stdout); } -static void set_xterm_icon_name(char *name) +static void set_xterm_icon_name (char *name) { - fputs("\033]1;", stdout); - fputs(name, stdout); - fputs("\007", stdout); - fflush(stdout); + fputs ("\033]1;", stdout); + fputs (name, stdout); + fputs ("\007", stdout); + fflush (stdout); } -void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num) +void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num) { - format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX; + format_flag flag = + M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX; int edgemsgno, reverse = Sort & SORT_REVERSE; HEADER *h = Context->hdrs[Context->v2r[num]]; THREAD *tmp; - if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) - { - flag |= M_FORMAT_TREE; /* display the thread tree */ + if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) { + flag |= M_FORMAT_TREE; /* display the thread tree */ if (h->display_subject) flag |= M_FORMAT_FORCESUBJ; - else - { - if (reverse) - { + else { + if (reverse) { if (menu->top + menu->pagelen > menu->max) edgemsgno = Context->v2r[menu->max - 1]; else @@ -153,33 +152,30 @@ void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num) else edgemsgno = Context->v2r[menu->top]; - for (tmp = h->thread->parent; tmp; tmp = tmp->parent) - { + for (tmp = h->thread->parent; tmp; tmp = tmp->parent) { if (!tmp->message) continue; /* if no ancestor is visible on current screen, provisionally force * subject... */ - if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno) - { + if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < + edgemsgno) { flag |= M_FORMAT_FORCESUBJ; break; } else if (tmp->message->virtual >= 0) break; } - if (flag & M_FORMAT_FORCESUBJ) - { - for (tmp = h->thread->prev; tmp; tmp = tmp->prev) - { + if (flag & M_FORMAT_FORCESUBJ) { + for (tmp = h->thread->prev; tmp; tmp = tmp->prev) { if (!tmp->message) continue; /* ...but if a previous sibling is available, don't force it */ - if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno) + if (reverse ? tmp->message->msgno > + edgemsgno : tmp->message->msgno < edgemsgno) break; - else if (tmp->message->virtual >= 0) - { + else if (tmp->message->virtual >= 0) { flag &= ~M_FORMAT_FORCESUBJ; break; } @@ -206,8 +202,8 @@ static int ci_next_undeleted (int msgno) { int i; - for (i=msgno+1; i < Context->vcount; i++) - if (! Context->hdrs[Context->v2r[i]]->deleted) + for (i = msgno + 1; i < Context->vcount; i++) + if (!Context->hdrs[Context->v2r[i]]->deleted) return (i); return (-1); } @@ -216,8 +212,8 @@ static int ci_previous_undeleted (int msgno) { int i; - for (i=msgno-1; i>=0; i--) - if (! Context->hdrs[Context->v2r[i]]->deleted) + for (i = msgno - 1; i >= 0; i--) + if (!Context->hdrs[Context->v2r[i]]->deleted) return (i); return (-1); } @@ -229,14 +225,11 @@ static int ci_first_message (void) { int old = -1, i; - if (Context && Context->msgcount) - { - for (i=0; i < Context->vcount; i++) - { - if (! Context->hdrs[Context->v2r[i]]->read && - ! Context->hdrs[Context->v2r[i]]->deleted) - { - if (! Context->hdrs[Context->v2r[i]]->old) + if (Context && Context->msgcount) { + for (i = 0; i < Context->vcount; i++) { + if (!Context->hdrs[Context->v2r[i]]->read && + !Context->hdrs[Context->v2r[i]]->deleted) { + if (!Context->hdrs[Context->v2r[i]]->old) return (i); else if (old == -1) old = i; @@ -260,110 +253,99 @@ static int ci_first_message (void) } /* This should be in mx.c, but it only gets used here. */ -static int mx_toggle_write (CONTEXT *ctx) +static int mx_toggle_write (CONTEXT * ctx) { if (!ctx) return -1; - if (ctx->readonly) - { - mutt_error _("Cannot toggle write on a readonly mailbox!"); + if (ctx->readonly) { + mutt_error (_("Cannot toggle write on a readonly mailbox!")); + return -1; } - if (ctx->dontwrite) - { + if (ctx->dontwrite) { ctx->dontwrite = 0; - mutt_message _("Changes to folder will be written on folder exit."); + mutt_message (_("Changes to folder will be written on folder exit.")); } - else - { + else { ctx->dontwrite = 1; - mutt_message _("Changes to folder will not be written."); + mutt_message (_("Changes to folder will not be written.")); } return 0; } -static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check, +static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check, int oldcount, int index_hint) { /* store pointers to the newly added messages */ - HEADER **save_new = NULL; + HEADER **save_new = NULL; int j; - + /* take note of the current message */ - if (oldcount) - { + if (oldcount) { if (menu->current < Context->vcount) menu->oldcurrent = index_hint; else - oldcount = 0; /* invalid message number! */ + oldcount = 0; /* invalid message number! */ } - + /* We are in a limited view. Check if the new message(s) satisfy * the limit criteria. If they do, set their virtual msgno so that * they will be visible in the limited view */ - if (Context->pattern) - { + if (Context->pattern) { #define THIS_BODY Context->hdrs[j]->content - if (oldcount || check == M_REOPENED) - { - for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) - { - if (mutt_pattern_exec (Context->limit_pattern, - M_MATCH_FULL_ADDRESS, - Context, Context->hdrs[j])) - { + if (oldcount || check == M_REOPENED) { + for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; + j++) { + if (mutt_pattern_exec + (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context, + Context->hdrs[j])) { Context->hdrs[j]->virtual = Context->vcount; Context->v2r[Context->vcount] = j; Context->hdrs[j]->limited = 1; Context->vcount++; - Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset; + Context->vsize += + THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset; } } } #undef THIS_BODY } - + /* save the list of new messages */ - if (oldcount && check != M_REOPENED - && ((Sort & SORT_MASK) == SORT_THREADS)) - { - save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (Context->msgcount - oldcount)); + if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) { + save_new = + (HEADER **) safe_malloc (sizeof (HEADER *) * + (Context->msgcount - oldcount)); for (j = oldcount; j < Context->msgcount; j++) - save_new[j-oldcount] = Context->hdrs[j]; + save_new[j - oldcount] = Context->hdrs[j]; } - + /* if the mailbox was reopened, need to rethread from scratch */ mutt_sort_headers (Context, (check == M_REOPENED)); /* uncollapse threads with new mail */ - if ((Sort & SORT_MASK) == SORT_THREADS) - { - if (check == M_REOPENED) - { + if ((Sort & SORT_MASK) == SORT_THREADS) { + if (check == M_REOPENED) { THREAD *h, *j; - + Context->collapsed = 0; - - for (h = Context->tree; h; h = h->next) - { - for (j = h; !j->message; j = j->child) - ; + + for (h = Context->tree; h; h = h->next) { + for (j = h; !j->message; j = j->child); mutt_uncollapse_thread (Context, j->message); } mutt_set_virtual (Context); } - else if (oldcount) - { - for (j = 0; j < Context->msgcount - oldcount; j++) - { + else if (oldcount) { + for (j = 0; j < Context->msgcount - oldcount; j++) { int k; - - for (k = 0; k < Context->msgcount; k++) - { + + for (k = 0; k < Context->msgcount; k++) { HEADER *h = Context->hdrs[k]; + if (h == save_new[j] && (!Context->pattern || h->limited)) mutt_uncollapse_thread (Context, h); } @@ -372,27 +354,24 @@ static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check, mutt_set_virtual (Context); } } - + menu->current = -1; - if (oldcount) - { + if (oldcount) { /* restore the current message to the message it was pointing to */ - for (j = 0; j < Context->vcount; j++) - { - if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) - { + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) { menu->current = j; break; } } } - + if (menu->current < 0) menu->current = ci_first_message (); - + } -static void resort_index (MUTTMENU *menu) +static void resort_index (MUTTMENU * menu) { int i; HEADER *current = CURHDR; @@ -401,47 +380,45 @@ static void resort_index (MUTTMENU *menu) mutt_sort_headers (Context, 0); /* Restore the current message */ - for (i = 0; i < Context->vcount; i++) - { - if (Context->hdrs[Context->v2r[i]] == current) - { + for (i = 0; i < Context->vcount; i++) { + if (Context->hdrs[Context->v2r[i]] == current) { menu->current = i; break; } } - + if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0) menu->current = mutt_parent_message (Context, current); - + if (menu->current < 0) menu->current = ci_first_message (); - + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } struct mapping_t IndexHelp[] = { - { N_("Quit"), OP_QUIT }, - { N_("Del"), OP_DELETE }, - { N_("Undel"), OP_UNDELETE }, - { N_("Save"), OP_SAVE }, - { N_("Mail"), OP_MAIL }, - { N_("Reply"), OP_REPLY }, - { N_("Group"), OP_GROUP_REPLY }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Quit"), OP_QUIT}, + {N_("Del"), OP_DELETE}, + {N_("Undel"), OP_UNDELETE}, + {N_("Save"), OP_SAVE}, + {N_("Mail"), OP_MAIL}, + {N_("Reply"), OP_REPLY}, + {N_("Group"), OP_GROUP_REPLY}, + {N_("Help"), OP_HELP}, + {NULL} }; #ifdef USE_NNTP struct mapping_t IndexNewsHelp[] = { - { N_("Quit"), OP_QUIT }, - { N_("Del"), OP_DELETE }, - { N_("Undel"), OP_UNDELETE }, - { N_("Save"), OP_SAVE }, - { N_("Post"), OP_POST }, - { N_("Followup"), OP_FOLLOWUP }, - { N_("Catchup"), OP_CATCHUP }, - { N_("Help"), OP_HELP }, - { NULL } + {N_("Quit"), OP_QUIT}, + {N_("Del"), OP_DELETE}, + {N_("Undel"), OP_UNDELETE}, + {N_("Save"), OP_SAVE}, + {N_("Post"), OP_POST}, + {N_("Followup"), OP_FOLLOWUP}, + {N_("Catchup"), OP_CATCHUP}, + {N_("Help"), OP_HELP}, + {NULL} }; #endif @@ -453,19 +430,19 @@ int mutt_index_menu (void) char buf[LONG_STRING], helpstr[SHORT_STRING]; int flags; int op = OP_NULL; - int done = 0; /* controls when to exit the "event" loop */ + int done = 0; /* controls when to exit the "event" loop */ int i = 0, j; - int tag = 0; /* has the tag-prefix command been pressed? */ + int tag = 0; /* has the tag-prefix command been pressed? */ int newcount = -1; int oldcount = -1; int rc = -1; MUTTMENU *menu; - char *cp; /* temporary variable. */ - int index_hint; /* used to restore cursor position */ + char *cp; /* temporary variable. */ + int index_hint; /* used to restore cursor position */ int do_buffy_notify = 1; - int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */ - int attach_msg = option(OPTATTACHMSG); - + int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */ + int attach_msg = option (OPTATTACHMSG); + menu = mutt_new_menu (); menu->menu = MENU_MAIN; menu->offset = 1; @@ -475,20 +452,21 @@ int mutt_index_menu (void) menu->current = ci_first_message (); menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, #ifdef USE_NNTP - (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : + (Context + && (Context->magic == + M_NNTP)) ? IndexNewsHelp : #endif - IndexHelp); - + IndexHelp); + if (!attach_msg) { - mutt_buffy_check(1); /* force the buffy check after we enter the folder */ + mutt_buffy_check (1); /* force the buffy check after we enter the folder */ /* record folder we open to place sidebar indicator properly */ if (Context && Context->path) - set_curbuffy(Context->path); + set_curbuffy (Context->path); } - FOREVER - { - tag = 0; /* clear the tag-prefix */ + FOREVER { + tag = 0; /* clear the tag-prefix */ menu->max = Context ? Context->vcount : 0; oldcount = Context ? Context->msgcount : 0; @@ -499,17 +477,17 @@ int mutt_index_menu (void) */ if (option (OPTNEEDRESORT) && Context && Context->msgcount) resort_index (menu); - - if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS) - { + + if (option (OPTREDRAWTREE) && Context && Context->msgcount + && (Sort & SORT_MASK) == SORT_THREADS) { mutt_draw_tree (Context); menu->redraw |= REDRAW_STATUS; unset_option (OPTREDRAWTREE); } - if (Context && !attach_msg) - { + if (Context && !attach_msg) { int check; + /* check for new mail in the mailbox. If nonzero, then something has * changed about the file (either we got new mail or the file was * modified underneath us.) @@ -518,43 +496,42 @@ int mutt_index_menu (void) #ifdef USE_IMAP imap_allow_reopen (Context); #endif - - index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0; - if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) - { - if (!Context->path) - { + index_hint = (Context->vcount && menu->current >= 0 + && menu->current < Context->vcount) ? CURHDR->index : 0; + + if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) { + if (!Context->path) { /* fatal error occurred */ FREE (&Context); menu->redraw = REDRAW_FULL; } - set_option (OPTSEARCHINVALID); } - else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) - { + else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) { update_index (menu, Context, check, oldcount, index_hint); - + /* notify the user of new mail */ if (check == M_REOPENED) - mutt_error _("Mailbox was externally modified. Flags may be wrong."); - else if (check == M_NEW_MAIL) - { + mutt_error (_ + ("Mailbox was externally modified. Flags may be wrong.")); + else if (check == M_NEW_MAIL) { /* on new mail: redraw sidebar */ draw_sidebar (CurrentMenu); - mutt_message _("New mail in this mailbox."); + mutt_message (_("New mail in this mailbox.")); + if (option (OPTBEEPNEW)) beep (); - } else if (check == M_FLAGS) - mutt_message _("Mailbox was externally modified."); + } + else if (check == M_FLAGS) + mutt_message (_("Mailbox was externally modified.")); /* avoid the message being overwritten by buffy */ do_buffy_notify = 0; - + menu->redraw = REDRAW_FULL; menu->max = Context->vcount; - + set_option (OPTSEARCHINVALID); } } @@ -564,41 +541,36 @@ int mutt_index_menu (void) imap_disallow_reopen (Context); #endif - if (!attach_msg) - { - /* check for new mail in the incoming folders */ - oldcount = newcount; - if ((newcount = mutt_buffy_check (0)) != oldcount){ - menu->redraw |= REDRAW_STATUS; - menu->redraw |= REDRAW_SIDEBAR; - } - if (do_buffy_notify) - { - if (mutt_buffy_notify () && option (OPTBEEPNEW)) - beep (); - } - else - do_buffy_notify = 1; + if (!attach_msg) { + /* check for new mail in the incoming folders */ + oldcount = newcount; + if ((newcount = mutt_buffy_check (0)) != oldcount) { + menu->redraw |= REDRAW_STATUS; + menu->redraw |= REDRAW_SIDEBAR; + } + if (do_buffy_notify) { + if (mutt_buffy_notify () && option (OPTBEEPNEW)) + beep (); + } + else + do_buffy_notify = 1; } if (op != -1) mutt_curs_set (0); - if (menu->redraw & REDRAW_SIDEBAR) draw_sidebar(menu->menu); - if (menu->redraw & REDRAW_FULL) - { + if (menu->redraw & REDRAW_SIDEBAR) + draw_sidebar (menu->menu); + if (menu->redraw & REDRAW_FULL) { menu_redraw_full (menu); - draw_sidebar(menu->menu); + draw_sidebar (menu->menu); mutt_show_error (); } - if (menu->menu == MENU_MAIN) - { - if (Context && Context->hdrs && !(menu->current >= Context->vcount)) - { + if (menu->menu == MENU_MAIN) { + if (Context && Context->hdrs && !(menu->current >= Context->vcount)) { menu_check_recenter (menu); - if (menu->redraw & REDRAW_INDEX) - { + if (menu->redraw & REDRAW_INDEX) { menu_redraw_index (menu); menu->redraw |= REDRAW_STATUS; } @@ -608,23 +580,21 @@ int mutt_index_menu (void) menu_redraw_current (menu); } - if (menu->redraw & REDRAW_STATUS) - { + if (menu->redraw & REDRAW_STATUS) { DrawFullLine = 1; menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); DrawFullLine = 0; - CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); + CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2); SETCOLOR (MT_COLOR_STATUS); mutt_paddstr (COLS, buf); SETCOLOR (MT_COLOR_NORMAL); set_buffystats (Context); menu->redraw &= ~REDRAW_STATUS; - if (option(OPTXTERMSETTITLES)) - { + if (option (OPTXTERMSETTITLES)) { menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle)); - set_xterm_title_bar(buf); + set_xterm_title_bar (buf); menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon)); - set_xterm_icon_name(buf); + set_xterm_icon_name (buf); } } @@ -642,43 +612,42 @@ int mutt_index_menu (void) op = km_dokey (MENU_MAIN); - dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op)); + dprint (4, + (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op)); #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) - if (SigWinch) - { + if (SigWinch) { mutt_flushinp (); mutt_resize_screen (); menu->redraw = REDRAW_FULL; menu->menu = MENU_MAIN; SigWinch = 0; - menu->top = 0; /* so we scroll the right amount */ + menu->top = 0; /* so we scroll the right amount */ /* * force a real complete redraw. clrtobot() doesn't seem to be able * to handle every case without this. */ - clearok(stdscr,TRUE); + clearok (stdscr, TRUE); continue; } #endif if (op == -1) - continue; /* either user abort or timeout */ - + continue; /* either user abort or timeout */ + mutt_curs_set (1); - + /* special handling for the tag-prefix function */ - if (op == OP_TAG_PREFIX) - { - if (!Context) - { - mutt_error _("No mailbox is open."); + if (op == OP_TAG_PREFIX) { + if (!Context) { + mutt_error (_("No mailbox is open.")); + continue; } - if (!Context->tagged) - { - mutt_error _("No tagged messages."); + if (!Context->tagged) { + mutt_error (_("No tagged messages.")); + continue; } tag = 1; @@ -688,33 +657,32 @@ int mutt_index_menu (void) clrtoeol (); /* get the real command */ - if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) - { + if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) { /* abort tag sequence */ - CLEARLINE (LINES-1); + CLEARLINE (LINES - 1); continue; } } else if (option (OPTAUTOTAG) && Context && Context->tagged) tag = 1; - if (op == OP_TAG_PREFIX_COND) - { - if (!Context) - { - mutt_error _("No mailbox is open."); + if (op == OP_TAG_PREFIX_COND) { + if (!Context) { + mutt_error (_("No mailbox is open.")); + continue; } - if (!Context->tagged) - { + if (!Context->tagged) { event_t tmp; - while(UngetCount>0) - { - tmp=mutt_getch(); - if(tmp.op==OP_END_COND)break; + + while (UngetCount > 0) { + tmp = mutt_getch (); + if (tmp.op == OP_END_COND) + break; } - mutt_message _("Nothing to do."); + mutt_message (_("Nothing to do.")); + continue; } tag = 1; @@ -724,996 +692,955 @@ int mutt_index_menu (void) clrtoeol (); /* get the real command */ - if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) - { + if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) { /* abort tag sequence */ - CLEARLINE (LINES-1); + CLEARLINE (LINES - 1); continue; } } mutt_clear_error (); } - else - { + else { if (menu->current < menu->max) menu->oldcurrent = menu->current; else menu->oldcurrent = -1; - + mutt_curs_set (1); /* fallback from the pager */ } #ifdef USE_NNTP - unset_option (OPTNEWS); /* for any case */ + unset_option (OPTNEWS); /* for any case */ #endif - switch (op) - { + switch (op) { /* ---------------------------------------------------------------------- * movement commands */ - case OP_BOTTOM_PAGE: - menu_bottom_page (menu); - break; - case OP_FIRST_ENTRY: - menu_first_entry (menu); - break; - case OP_MIDDLE_PAGE: - menu_middle_page (menu); - break; - case OP_HALF_UP: - menu_half_up (menu); - break; - case OP_HALF_DOWN: - menu_half_down (menu); - break; - case OP_NEXT_LINE: - menu_next_line (menu); - break; - case OP_PREV_LINE: - menu_prev_line (menu); - break; - case OP_NEXT_PAGE: - menu_next_page (menu); - break; - case OP_PREV_PAGE: - menu_prev_page (menu); - break; - case OP_LAST_ENTRY: - menu_last_entry (menu); - break; - case OP_TOP_PAGE: - menu_top_page (menu); - break; - case OP_CURRENT_TOP: - menu_current_top (menu); - break; - case OP_CURRENT_MIDDLE: - menu_current_middle (menu); - break; - case OP_CURRENT_BOTTOM: - menu_current_bottom (menu); - break; + case OP_BOTTOM_PAGE: + menu_bottom_page (menu); + break; + case OP_FIRST_ENTRY: + menu_first_entry (menu); + break; + case OP_MIDDLE_PAGE: + menu_middle_page (menu); + break; + case OP_HALF_UP: + menu_half_up (menu); + break; + case OP_HALF_DOWN: + menu_half_down (menu); + break; + case OP_NEXT_LINE: + menu_next_line (menu); + break; + case OP_PREV_LINE: + menu_prev_line (menu); + break; + case OP_NEXT_PAGE: + menu_next_page (menu); + break; + case OP_PREV_PAGE: + menu_prev_page (menu); + break; + case OP_LAST_ENTRY: + menu_last_entry (menu); + break; + case OP_TOP_PAGE: + menu_top_page (menu); + break; + case OP_CURRENT_TOP: + menu_current_top (menu); + break; + case OP_CURRENT_MIDDLE: + menu_current_middle (menu); + break; + case OP_CURRENT_BOTTOM: + menu_current_bottom (menu); + break; #ifdef USE_NNTP - case OP_GET_MESSAGE: - case OP_GET_PARENT: - CHECK_MSGCOUNT; - if (Context->magic == M_NNTP) - { - HEADER *h; + case OP_GET_MESSAGE: + case OP_GET_PARENT: + CHECK_MSGCOUNT; + if (Context->magic == M_NNTP) { + HEADER *h; + + if (op == OP_GET_MESSAGE) { + buf[0] = 0; + if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) + != 0 || !buf[0]) + break; + } + else { + LIST *ref = CURHDR->env->references; - if (op == OP_GET_MESSAGE) - { - buf[0] = 0; - if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0 - || !buf[0]) - break; + if (!ref) { + mutt_error (_("Article has no parent reference!")); + + break; } - else - { - LIST *ref = CURHDR->env->references; - if (!ref) - { - mutt_error _("Article has no parent reference!"); - break; - } - strfcpy (buf, ref->data, sizeof (buf)); + strfcpy (buf, ref->data, sizeof (buf)); + } + if (!Context->id_hash) + Context->id_hash = mutt_make_id_hash (Context); + if ((h = hash_find (Context->id_hash, buf))) { + if (h->virtual != -1) { + menu->current = h->virtual; + menu->redraw = REDRAW_MOTION_RESYNCH; } - if (!Context->id_hash) - Context->id_hash = mutt_make_id_hash (Context); - if ((h = hash_find (Context->id_hash, buf))) - { - if (h->virtual != -1) - { - menu->current = h->virtual; - menu->redraw = REDRAW_MOTION_RESYNCH; - } - else if (h->collapsed) - { - mutt_uncollapse_thread (Context, h); - mutt_set_virtual (Context); - menu->current = h->virtual; - menu->redraw = REDRAW_MOTION_RESYNCH; - } - else - mutt_error _("Message not visible in limited view."); + else if (h->collapsed) { + mutt_uncollapse_thread (Context, h); + mutt_set_virtual (Context); + menu->current = h->virtual; + menu->redraw = REDRAW_MOTION_RESYNCH; } else - { - if (nntp_check_msgid (Context, buf) == 0) - { - h = Context->hdrs[Context->msgcount-1]; - mutt_sort_headers (Context, 0); - menu->current = h->virtual; - menu->redraw = REDRAW_FULL; - } - else - mutt_error (_("Article %s not found on server"), buf); + mutt_error (_("Message not visible in limited view.")); + } + else { + if (nntp_check_msgid (Context, buf) == 0) { + h = Context->hdrs[Context->msgcount - 1]; + mutt_sort_headers (Context, 0); + menu->current = h->virtual; + menu->redraw = REDRAW_FULL; } + else + mutt_error (_("Article %s not found on server"), buf); } - break; + } + break; - case OP_GET_CHILDREN: - case OP_RECONSTRUCT_THREAD: - CHECK_MSGCOUNT; - if (Context->magic == M_NNTP) - { - HEADER *h; - int old = CURHDR->index, i; + case OP_GET_CHILDREN: + case OP_RECONSTRUCT_THREAD: + CHECK_MSGCOUNT; + if (Context->magic == M_NNTP) { + HEADER *h; + int old = CURHDR->index, i; - if (!CURHDR->env->message_id) - { - mutt_error _("No Message-Id. Unable to perform operation"); - break; - } + if (!CURHDR->env->message_id) { + mutt_error (_("No Message-Id. Unable to perform operation")); - if (!Context->id_hash) - Context->id_hash = mutt_make_id_hash (Context); - strfcpy (buf, CURHDR->env->message_id, sizeof (buf)); - - if (op == OP_RECONSTRUCT_THREAD) - { - LIST *ref = CURHDR->env->references; - while (ref) - { - nntp_check_msgid (Context, ref->data); - /* the last msgid in References is the root message */ - if (!ref->next) - strfcpy (buf, ref->data, sizeof (buf)); - ref = ref->next; - } - } - mutt_message _("Check for children of message..."); - if (nntp_check_children (Context, buf) == 0) - { - mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD)); - h = hash_find (Context->id_hash, buf); - /* if the root message was retrieved, move to it */ - if (h) - menu->current = h->virtual; - else /* try to restore old position */ - for (i = 0; i < Context->msgcount; i++) - if (Context->hdrs[i]->index == old) - { - menu->current = Context->hdrs[i]->virtual; - /* As an added courtesy, recenter the menu - * with the current entry at the middle of the screen */ - menu_check_recenter (menu); - menu_current_middle (menu); - } + break; + } + + if (!Context->id_hash) + Context->id_hash = mutt_make_id_hash (Context); + strfcpy (buf, CURHDR->env->message_id, sizeof (buf)); + + if (op == OP_RECONSTRUCT_THREAD) { + LIST *ref = CURHDR->env->references; + + while (ref) { + nntp_check_msgid (Context, ref->data); + /* the last msgid in References is the root message */ + if (!ref->next) + strfcpy (buf, ref->data, sizeof (buf)); + ref = ref->next; } - menu->redraw = REDRAW_FULL; - mutt_clear_error (); } - break; + mutt_message (_("Check for children of message...")); + + if (nntp_check_children (Context, buf) == 0) { + mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD)); + h = hash_find (Context->id_hash, buf); + /* if the root message was retrieved, move to it */ + if (h) + menu->current = h->virtual; + else /* try to restore old position */ + for (i = 0; i < Context->msgcount; i++) + if (Context->hdrs[i]->index == old) { + menu->current = Context->hdrs[i]->virtual; + /* As an added courtesy, recenter the menu + * with the current entry at the middle of the screen */ + menu_check_recenter (menu); + menu_current_middle (menu); + } + } + menu->redraw = REDRAW_FULL; + mutt_clear_error (); + } + break; #endif - case OP_JUMP: + case OP_JUMP: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (isdigit (LastKey)) mutt_ungetch (LastKey, 0); - buf[0] = 0; - if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0 - || !buf[0]) - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (isdigit (LastKey)) + mutt_ungetch (LastKey, 0); + buf[0] = 0; + if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0 + || !buf[0]) + break; - if (! isdigit ((unsigned char) buf[0])) - { - mutt_error _("Argument must be a message number."); - break; - } + if (!isdigit ((unsigned char) buf[0])) { + mutt_error (_("Argument must be a message number.")); - i = atoi (buf); - if (i > 0 && i <= Context->msgcount) - { - for (j = i-1; j < Context->msgcount; j++) - { + break; + } + + i = atoi (buf); + if (i > 0 && i <= Context->msgcount) { + for (j = i - 1; j < Context->msgcount; j++) { + if (Context->hdrs[j]->virtual != -1) + break; + } + if (j >= Context->msgcount) { + for (j = i - 2; j >= 0; j--) { if (Context->hdrs[j]->virtual != -1) break; } - if (j >= Context->msgcount) - { - for (j = i-2; j >= 0; j--) - { - if (Context->hdrs[j]->virtual != -1) - break; - } - } + } - if (j >= 0) - { - menu->current = Context->hdrs[j]->virtual; - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; + if (j >= 0) { + menu->current = Context->hdrs[j]->virtual; + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; } else - mutt_error _("That message is not visible."); + menu->redraw = REDRAW_MOTION; } else - mutt_error _("Invalid message number."); + mutt_error (_("That message is not visible.")); + } + else + mutt_error (_("Invalid message number.")); - break; + break; - /* -------------------------------------------------------------------- - * `index' specific commands - */ + /* -------------------------------------------------------------------- + * `index' specific commands + */ - case OP_MAIN_DELETE_PATTERN: + case OP_MAIN_DELETE_PATTERN: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - CHECK_ATTACH; - mutt_pattern_func (M_DELETE, _("Delete messages matching: ")); - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - break; + CHECK_ATTACH; + mutt_pattern_func (M_DELETE, _("Delete messages matching: ")); + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + break; #ifdef USE_POP - case OP_MAIN_FETCH_MAIL: + case OP_MAIN_FETCH_MAIL: - CHECK_ATTACH; - pop_fetch_mail (); - menu->redraw = REDRAW_FULL; - break; + CHECK_ATTACH; + pop_fetch_mail (); + menu->redraw = REDRAW_FULL; + break; #endif /* USE_POP */ - case OP_HELP: + case OP_HELP: - mutt_help (MENU_MAIN); - menu->redraw = REDRAW_FULL; - break; + mutt_help (MENU_MAIN); + menu->redraw = REDRAW_FULL; + break; - case OP_MAIN_SHOW_LIMIT: - CHECK_MSGCOUNT; - if (!Context->pattern) - mutt_message _("No limit pattern is in effect."); - else - { - char buf[STRING]; - /* i18n: ask for a limit to apply */ - snprintf (buf, sizeof(buf), _("Limit: %s"),Context->pattern); - mutt_message ("%s", buf); - } - break; + case OP_MAIN_SHOW_LIMIT: + CHECK_MSGCOUNT; + if (!Context->pattern) + mutt_message (_("No limit pattern is in effect.")); - case OP_MAIN_LIMIT: - case OP_TOGGLE_READ: + else { + char buf[STRING]; - CHECK_MSGCOUNT; - menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? - CURHDR->index : -1; - if (op == OP_TOGGLE_READ) - { - char buf[LONG_STRING]; + /* i18n: ask for a limit to apply */ + snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern); + mutt_message ("%s", buf); + } + break; - if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) - { - snprintf (buf, sizeof (buf), "!~R!~D~s%s", - Context->pattern ? Context->pattern : ".*"); - set_option (OPTHIDEREAD); - } - else - { - strfcpy (buf, Context->pattern + 8, sizeof(buf)); - if (!*buf || strncmp (buf, ".*", 2) == 0) - snprintf (buf, sizeof(buf), "~A"); - unset_option (OPTHIDEREAD); - } - FREE (&Context->pattern); - Context->pattern = safe_strdup (buf); - } - if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) || - mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0) - { - if (menu->oldcurrent >= 0) - { - /* try to find what used to be the current message */ - menu->current = -1; - for (i = 0; i < Context->vcount; i++) - if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) - { - menu->current = i; - break; - } - if (menu->current < 0) menu->current = 0; - } - else + case OP_MAIN_LIMIT: + case OP_TOGGLE_READ: + + CHECK_MSGCOUNT; + menu->oldcurrent = (Context->vcount && menu->current >= 0 + && menu->current < + Context->vcount) ? CURHDR->index : -1; + if (op == OP_TOGGLE_READ) { + char buf[LONG_STRING]; + + if (!Context->pattern + || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) { + snprintf (buf, sizeof (buf), "!~R!~D~s%s", + Context->pattern ? Context->pattern : ".*"); + set_option (OPTHIDEREAD); + } + else { + strfcpy (buf, Context->pattern + 8, sizeof (buf)); + if (!*buf || strncmp (buf, ".*", 2) == 0) + snprintf (buf, sizeof (buf), "~A"); + unset_option (OPTHIDEREAD); + } + FREE (&Context->pattern); + Context->pattern = safe_strdup (buf); + } + if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) || + mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0) + { + if (menu->oldcurrent >= 0) { + /* try to find what used to be the current message */ + menu->current = -1; + for (i = 0; i < Context->vcount; i++) + if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) { + menu->current = i; + break; + } + if (menu->current < 0) menu->current = 0; - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - if ((Sort & SORT_MASK) == SORT_THREADS) - mutt_draw_tree (Context); - menu->redraw = REDRAW_FULL; } - break; + else + menu->current = 0; + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + if ((Sort & SORT_MASK) == SORT_THREADS) + mutt_draw_tree (Context); + menu->redraw = REDRAW_FULL; + } + break; - case OP_QUIT: + case OP_QUIT: - close = op; - if (attach_msg) - { - done = 1; - break; - } + close = op; + if (attach_msg) { + done = 1; + break; + } - if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) - { - int check; - - oldcount = Context ? Context->msgcount : 0; + if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) { + int check; - if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0) - done = 1; - else - { - if (check == M_NEW_MAIL || check == M_REOPENED) - update_index (menu, Context, check, oldcount, index_hint); + oldcount = Context ? Context->msgcount : 0; - menu->redraw = REDRAW_FULL; /* new mail arrived? */ - set_option (OPTSEARCHINVALID); - } + if (!Context + || (check = mx_close_mailbox (Context, &index_hint)) == 0) + done = 1; + else { + if (check == M_NEW_MAIL || check == M_REOPENED) + update_index (menu, Context, check, oldcount, index_hint); + + menu->redraw = REDRAW_FULL; /* new mail arrived? */ + set_option (OPTSEARCHINVALID); } - break; + } + break; - case OP_REDRAW: + case OP_REDRAW: - clearok (stdscr, TRUE); - menu->redraw = REDRAW_FULL; - break; + clearok (stdscr, TRUE); + menu->redraw = REDRAW_FULL; + break; - case OP_SEARCH: - case OP_SEARCH_REVERSE: - case OP_SEARCH_NEXT: - case OP_SEARCH_OPPOSITE: + case OP_SEARCH: + case OP_SEARCH_REVERSE: + case OP_SEARCH_NEXT: + case OP_SEARCH_OPPOSITE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if ((menu->current = mutt_search_command (menu->current, op)) == -1) - menu->current = menu->oldcurrent; - else - menu->redraw = REDRAW_MOTION; - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if ((menu->current = mutt_search_command (menu->current, op)) == -1) + menu->current = menu->oldcurrent; + else + menu->redraw = REDRAW_MOTION; + break; - case OP_SORT: - case OP_SORT_REVERSE: + case OP_SORT: + case OP_SORT_REVERSE: - if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) - { - if (Context && Context->msgcount) - { - resort_index (menu); - set_option (OPTSEARCHINVALID); - } + if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) { + if (Context && Context->msgcount) { + resort_index (menu); + set_option (OPTSEARCHINVALID); } - break; + } + break; - case OP_TAG: + case OP_TAG: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (tag && !option (OPTAUTOTAG)) - { - for (j = 0; j < Context->vcount; j++) - mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0); - menu->redraw = REDRAW_STATUS | REDRAW_INDEX; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (tag && !option (OPTAUTOTAG)) { + for (j = 0; j < Context->vcount; j++) + mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0); + menu->redraw = REDRAW_STATUS | REDRAW_INDEX; + } + else { + mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged); + Context->last_tag = CURHDR->tagged ? CURHDR : + ((Context->last_tag == CURHDR && !CURHDR->tagged) + ? NULL : Context->last_tag); + menu->redraw = REDRAW_STATUS; + if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) { + menu->current++; + menu->redraw |= REDRAW_MOTION_RESYNCH; } else - { - mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged); - Context->last_tag = CURHDR->tagged ? CURHDR : - ((Context->last_tag == CURHDR && !CURHDR->tagged) - ? NULL : Context->last_tag); - menu->redraw = REDRAW_STATUS; - if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) - { - menu->current++; - menu->redraw |= REDRAW_MOTION_RESYNCH; - } - else - menu->redraw |= REDRAW_CURRENT; - } - break; + menu->redraw |= REDRAW_CURRENT; + } + break; - case OP_MAIN_TAG_PATTERN: + case OP_MAIN_TAG_PATTERN: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - mutt_pattern_func (M_TAG, _("Tag messages matching: ")); - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + mutt_pattern_func (M_TAG, _("Tag messages matching: ")); + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + break; - case OP_MAIN_UNDELETE_PATTERN: + case OP_MAIN_UNDELETE_PATTERN: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == 0) - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - break; + if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == + 0) + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + break; - case OP_MAIN_UNTAG_PATTERN: + case OP_MAIN_UNTAG_PATTERN: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0) - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0) + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + break; - /* -------------------------------------------------------------------- - * The following operations can be performed inside of the pager. - */ + /* -------------------------------------------------------------------- + * The following operations can be performed inside of the pager. + */ #ifdef USE_IMAP - case OP_MAIN_IMAP_FETCH: - if (Context->magic == M_IMAP) - imap_check_mailbox (Context, &index_hint, 1); - break; + case OP_MAIN_IMAP_FETCH: + if (Context->magic == M_IMAP) + imap_check_mailbox (Context, &index_hint, 1); + break; #endif - - case OP_MAIN_SYNC_FOLDER: - if (Context && !Context->msgcount) - break; + case OP_MAIN_SYNC_FOLDER: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; - { - int oldvcount = Context->vcount; - int oldcount = Context->msgcount; - int dcount = 0; - int check; - - /* calculate the number of messages _above_ the cursor, - * so we can keep the cursor on the current message - */ - for (j = 0; j <= menu->current; j++) - { - if (Context->hdrs[Context->v2r[j]]->deleted) - dcount++; - } + if (Context && !Context->msgcount) + break; - if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) - { - if (Context->vcount != oldvcount) - menu->current -= dcount; - set_option (OPTSEARCHINVALID); - } - else if (check == M_NEW_MAIL || check == M_REOPENED) - update_index (menu, Context, check, oldcount, index_hint); + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; + { + int oldvcount = Context->vcount; + int oldcount = Context->msgcount; + int dcount = 0; + int check; - /* - * do a sanity check even if mx_sync_mailbox failed. - */ + /* calculate the number of messages _above_ the cursor, + * so we can keep the cursor on the current message + */ + for (j = 0; j <= menu->current; j++) { + if (Context->hdrs[Context->v2r[j]]->deleted) + dcount++; + } - if (menu->current < 0 || menu->current >= Context->vcount) - menu->current = ci_first_message (); + if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) { + if (Context->vcount != oldvcount) + menu->current -= dcount; + set_option (OPTSEARCHINVALID); } + else if (check == M_NEW_MAIL || check == M_REOPENED) + update_index (menu, Context, check, oldcount, index_hint); - /* check for a fatal error, or all messages deleted */ - if (!Context->path) - FREE (&Context); + /* + * do a sanity check even if mx_sync_mailbox failed. + */ - /* if we were in the pager, redisplay the message */ - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_FULL; - break; + if (menu->current < 0 || menu->current >= Context->vcount) + menu->current = ci_first_message (); + } + + /* check for a fatal error, or all messages deleted */ + if (!Context->path) + FREE (&Context); - case OP_SIDEBAR_OPEN: - case OP_MAIN_CHANGE_FOLDER: - case OP_MAIN_CHANGE_FOLDER_READONLY: + /* if we were in the pager, redisplay the message */ + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_FULL; + break; + + case OP_SIDEBAR_OPEN: + case OP_MAIN_CHANGE_FOLDER: + case OP_MAIN_CHANGE_FOLDER_READONLY: #ifdef USE_NNTP - case OP_MAIN_CHANGE_GROUP: - case OP_MAIN_CHANGE_GROUP_READONLY: + case OP_MAIN_CHANGE_GROUP: + case OP_MAIN_CHANGE_GROUP_READONLY: #endif - if (attach_msg || option (OPTREADONLY) || + if (attach_msg || option (OPTREADONLY) || #ifdef USE_NNTP - op == OP_MAIN_CHANGE_GROUP_READONLY || + op == OP_MAIN_CHANGE_GROUP_READONLY || #endif - op == OP_MAIN_CHANGE_FOLDER_READONLY) - flags = M_READONLY; - else - flags = 0; + op == OP_MAIN_CHANGE_FOLDER_READONLY) + flags = M_READONLY; + else + flags = 0; - if (flags) - cp = _("Open mailbox in read-only mode"); - else - cp = _("Open mailbox"); + if (flags) + cp = _("Open mailbox in read-only mode"); + else + cp = _("Open mailbox"); - buf[0] = '\0'; + buf[0] = '\0'; #ifdef USE_NNTP - unset_option (OPTNEWS); - if (op == OP_MAIN_CHANGE_GROUP || - op == OP_MAIN_CHANGE_GROUP_READONLY) - { - set_option (OPTNEWS); - if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) - break; - if (flags) - cp = _("Open newsgroup in read-only mode"); - else - cp = _("Open newsgroup"); - nntp_buffy (buf); - } + unset_option (OPTNEWS); + if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) { + set_option (OPTNEWS); + if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) + break; + if (flags) + cp = _("Open newsgroup in read-only mode"); else + cp = _("Open newsgroup"); + nntp_buffy (buf); + } + else #endif - { - if (Context && Context->path) - strncpy (buf, Context->path, sizeof (buf)); - mutt_buffy (buf, sizeof (buf)); - } + { + if (Context && Context->path) + strncpy (buf, Context->path, sizeof (buf)); + mutt_buffy (buf, sizeof (buf)); + } - if ( op == OP_SIDEBAR_OPEN ) { - if(!CurBuffy) - break; - strncpy( buf, CurBuffy->path, sizeof(buf) ); - } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) - break; - if (!buf[0]) - { - CLEARLINE (LINES-1); + if (op == OP_SIDEBAR_OPEN) { + if (!CurBuffy) break; - } + strncpy (buf, CurBuffy->path, sizeof (buf)); + } + else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == + -1) + break; + if (!buf[0]) { + CLEARLINE (LINES - 1); + break; + } #ifdef USE_NNTP - if (option (OPTNEWS)) - { - unset_option (OPTNEWS); - nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account); - } - else + if (option (OPTNEWS)) { + unset_option (OPTNEWS); + nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account); + } + else #endif mutt_expand_path (buf, sizeof (buf)); - set_curbuffy(buf); - if (mx_get_magic (buf) <= 0) - { - mutt_error (_("%s is not a mailbox."), buf); - break; - } - mutt_str_replace (&CurrentFolder, buf); + set_curbuffy (buf); + if (mx_get_magic (buf) <= 0) { + mutt_error (_("%s is not a mailbox."), buf); + break; + } + mutt_str_replace (&CurrentFolder, buf); - if (Context) - { - int check; + if (Context) { + int check; #ifdef USE_COMPRESSED - if (Context->compressinfo && Context->realpath) - mutt_str_replace (&LastFolder, Context->realpath); - else + if (Context->compressinfo && Context->realpath) + mutt_str_replace (&LastFolder, Context->realpath); + else #endif mutt_str_replace (&LastFolder, Context->path); - oldcount = Context ? Context->msgcount : 0; - - if ((check = mx_close_mailbox (Context, &index_hint)) != 0) - { - if (check == M_NEW_MAIL || check == M_REOPENED) - update_index (menu, Context, check, oldcount, index_hint); - - set_option (OPTSEARCHINVALID); - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - break; - } - FREE (&Context); + oldcount = Context ? Context->msgcount : 0; + + if ((check = mx_close_mailbox (Context, &index_hint)) != 0) { + if (check == M_NEW_MAIL || check == M_REOPENED) + update_index (menu, Context, check, oldcount, index_hint); + + set_option (OPTSEARCHINVALID); + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + break; } + FREE (&Context); + } - mutt_sleep (0); - - /* Set CurrentMenu to MENU_MAIN before executing any folder - * hooks so that all the index menu functions are available to - * the exec command. - */ + mutt_sleep (0); - CurrentMenu = MENU_MAIN; - mutt_folder_hook (buf); + /* Set CurrentMenu to MENU_MAIN before executing any folder + * hooks so that all the index menu functions are available to + * the exec command. + */ - if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) - { - menu->current = ci_first_message (); - } - else - menu->current = 0; + CurrentMenu = MENU_MAIN; + mutt_folder_hook (buf); + + if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) { + menu->current = ci_first_message (); + } + else + menu->current = 0; #ifdef USE_NNTP - /* mutt_buffy_check() must be done with mail-reader mode! */ - menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, - (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp); + /* mutt_buffy_check() must be done with mail-reader mode! */ + menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, + (Context + && (Context->magic == + M_NNTP)) ? IndexNewsHelp : + IndexHelp); #endif - mutt_clear_error (); - mutt_buffy_check(1); /* force the buffy check after we have changed - the folder */ - menu->redraw = REDRAW_FULL; - set_option (OPTSEARCHINVALID); - break; + mutt_clear_error (); + mutt_buffy_check (1); /* force the buffy check after we have changed + the folder */ + menu->redraw = REDRAW_FULL; + set_option (OPTSEARCHINVALID); + break; - case OP_DISPLAY_MESSAGE: - case OP_DISPLAY_HEADERS: /* don't weed the headers */ + case OP_DISPLAY_MESSAGE: + case OP_DISPLAY_HEADERS: /* don't weed the headers */ - CHECK_MSGCOUNT; - CHECK_VISIBLE; - /* - * toggle the weeding of headers so that a user can press the key - * again while reading the message. - */ - if (op == OP_DISPLAY_HEADERS) - toggle_option (OPTWEED); + CHECK_MSGCOUNT; + CHECK_VISIBLE; + /* + * toggle the weeding of headers so that a user can press the key + * again while reading the message. + */ + if (op == OP_DISPLAY_HEADERS) + toggle_option (OPTWEED); + + unset_option (OPTNEEDRESORT); + if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) { + mutt_uncollapse_thread (Context, CURHDR); + mutt_set_virtual (Context); + if (option (OPTUNCOLLAPSEJUMP)) + menu->current = mutt_thread_next_unread (Context, CURHDR); + } + + if ((op = mutt_display_message (CURHDR)) == -1) { unset_option (OPTNEEDRESORT); + break; + } - if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) - { - mutt_uncollapse_thread (Context, CURHDR); - mutt_set_virtual (Context); - if (option (OPTUNCOLLAPSEJUMP)) - menu->current = mutt_thread_next_unread (Context, CURHDR); - } - - if ((op = mutt_display_message (CURHDR)) == -1) - { - unset_option (OPTNEEDRESORT); - break; + menu->menu = MENU_PAGER; + menu->oldcurrent = menu->current; + continue; + + case OP_EXIT: + + close = op; + if (menu->menu == MENU_MAIN && attach_msg) { + done = 1; + break; + } + + if ((menu->menu == MENU_MAIN) + && (query_quadoption (OPT_QUIT, + _("Exit Mutt-ng without saving?")) == M_YES)) + { + if (Context) { + mx_fastclose_mailbox (Context); + FREE (&Context); } + done = 1; + } + break; - menu->menu = MENU_PAGER; - menu->oldcurrent = menu->current; + case OP_EDIT_TYPE: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_ATTACH; + mutt_edit_content_type (CURHDR, CURHDR->content, NULL); + /* if we were in the pager, redisplay the message */ + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; continue; + } + else + menu->redraw = REDRAW_CURRENT; + break; - case OP_EXIT: + case OP_MAIN_BREAK_THREAD: - close = op; - if (menu->menu == MENU_MAIN && attach_msg) - { - done = 1; - break; - } + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; + + if ((Sort & SORT_MASK) != SORT_THREADS) + mutt_error (_("Threading is not enabled.")); - if ((menu->menu == MENU_MAIN) - && (query_quadoption (OPT_QUIT, - _("Exit Mutt-ng without saving?")) == M_YES)) + else { { - if (Context) - { - mx_fastclose_mailbox (Context); - FREE (&Context); - } - done = 1; + HEADER *oldcur = CURHDR; + + mutt_break_thread (CURHDR); + mutt_sort_headers (Context, 1); + menu->current = oldcur->virtual; } - break; - case OP_EDIT_TYPE: + Context->changed = 1; + mutt_message _("Thread broken"); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_ATTACH; - mutt_edit_content_type (CURHDR, CURHDR->content, NULL); - /* if we were in the pager, redisplay the message */ - if (menu->menu == MENU_PAGER) - { + if (menu->menu == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; } else - menu->redraw = REDRAW_CURRENT; - break; - - case OP_MAIN_BREAK_THREAD: - - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + menu->redraw |= REDRAW_INDEX; + } + break; - if ((Sort & SORT_MASK) != SORT_THREADS) - mutt_error _("Threading is not enabled."); - else - { - { - HEADER *oldcur = CURHDR; + case OP_MAIN_LINK_THREADS: - mutt_break_thread (CURHDR); - mutt_sort_headers (Context, 1); - menu->current = oldcur->virtual; - } + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; - Context->changed = 1; - mutt_message _("Thread broken"); + if ((Sort & SORT_MASK) != SORT_THREADS) + mutt_error (_("Threading is not enabled.")); - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw |= REDRAW_INDEX; - } - break; + else if (!CURHDR->env->message_id) + mutt_error (_("No Message-ID: header available to link thread")); - case OP_MAIN_LINK_THREADS: + else if (!tag && (!Context->last_tag || !Context->last_tag->tagged)) + mutt_error (_("First, please tag a message to be linked here")); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; - - if ((Sort & SORT_MASK) != SORT_THREADS) - mutt_error _("Threading is not enabled."); - else if (!CURHDR->env->message_id) - mutt_error _("No Message-ID: header available to link thread"); - else if (!tag && (!Context->last_tag || !Context->last_tag->tagged)) - mutt_error _("First, please tag a message to be linked here"); - else - { - HEADER *oldcur = CURHDR; + else { + HEADER *oldcur = CURHDR; - if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag, - Context)) - { - mutt_sort_headers (Context, 1); - menu->current = oldcur->virtual; - - Context->changed = 1; - mutt_message _("Threads linked"); - } - else - mutt_error _("No thread linked"); - } + if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag, + Context)) { + mutt_sort_headers (Context, 1); + menu->current = oldcur->virtual; - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; + Context->changed = 1; + mutt_message _("Threads linked"); } else - menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; - break; + mutt_error (_("No thread linked")); + } - case OP_MAIN_NEXT_UNDELETED: + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; + break; + + case OP_MAIN_NEXT_UNDELETED: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (menu->current >= Context->vcount - 1) { + if (menu->menu == MENU_MAIN) + mutt_error (_("You are on the last message.")); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (menu->current >= Context->vcount - 1) - { - if (menu->menu == MENU_MAIN) - mutt_error _("You are on the last message."); - break; - } - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - if (menu->menu == MENU_MAIN) - mutt_error _("No undeleted messages."); - } - else if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; break; + } + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + if (menu->menu == MENU_MAIN) + mutt_error (_("No undeleted messages.")); + } + else if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_NEXT_ENTRY: + case OP_NEXT_ENTRY: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (menu->current >= Context->vcount - 1) { + if (menu->menu == MENU_MAIN) + mutt_error (_("You are on the last message.")); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (menu->current >= Context->vcount - 1) - { - if (menu->menu == MENU_MAIN) - mutt_error _("You are on the last message."); - break; - } - menu->current++; - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; break; + } + menu->current++; + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_MAIN_PREV_UNDELETED: + case OP_MAIN_PREV_UNDELETED: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (menu->current < 1) { + mutt_error (_("You are on the first message.")); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (menu->current < 1) - { - mutt_error _("You are on the first message."); - break; - } - if ((menu->current = ci_previous_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - if (menu->menu == MENU_MAIN) - mutt_error _("No undeleted messages."); - } - else if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; break; + } + if ((menu->current = ci_previous_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + if (menu->menu == MENU_MAIN) + mutt_error (_("No undeleted messages.")); + } + else if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_PREV_ENTRY: + case OP_PREV_ENTRY: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (menu->current < 1) { + if (menu->menu == MENU_MAIN) + mutt_error (_("You are on the first message.")); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (menu->current < 1) - { - if (menu->menu == MENU_MAIN) mutt_error _("You are on the first message."); - break; - } - menu->current--; - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; break; + } + menu->current--; + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_DECRYPT_COPY: - case OP_DECRYPT_SAVE: - if (!WithCrypto) - break; - /* fall thru */ - case OP_COPY_MESSAGE: - case OP_SAVE: - case OP_DECODE_COPY: - case OP_DECODE_SAVE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (mutt_save_message (tag ? NULL : CURHDR, - (op == OP_DECRYPT_SAVE) || - (op == OP_SAVE) || (op == OP_DECODE_SAVE), - (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY), - (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) || - 0, - &menu->redraw) == 0 && - (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE) - ) - { - if (tag) - menu->redraw |= REDRAW_INDEX; - else if (option (OPTRESOLVE)) - { - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - menu->redraw |= REDRAW_CURRENT; - } - else - menu->redraw |= REDRAW_MOTION_RESYNCH; + case OP_DECRYPT_COPY: + case OP_DECRYPT_SAVE: + if (!WithCrypto) + break; + /* fall thru */ + case OP_COPY_MESSAGE: + case OP_SAVE: + case OP_DECODE_COPY: + case OP_DECODE_SAVE: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (mutt_save_message (tag ? NULL : CURHDR, + (op == OP_DECRYPT_SAVE) || + (op == OP_SAVE) || (op == OP_DECODE_SAVE), + (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY), + (op == OP_DECRYPT_SAVE) + || (op == OP_DECRYPT_COPY) + || 0, &menu->redraw) == 0 && (op == OP_SAVE + || op == + OP_DECODE_SAVE + || op == + OP_DECRYPT_SAVE) + ) { + if (tag) + menu->redraw |= REDRAW_INDEX; + else if (option (OPTRESOLVE)) { + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + menu->redraw |= REDRAW_CURRENT; } else - menu->redraw |= REDRAW_CURRENT; + menu->redraw |= REDRAW_MOTION_RESYNCH; } - break; + else + menu->redraw |= REDRAW_CURRENT; + } + break; - case OP_MAIN_NEXT_NEW: - case OP_MAIN_NEXT_UNREAD: - case OP_MAIN_PREV_NEW: - case OP_MAIN_PREV_UNREAD: - case OP_MAIN_NEXT_NEW_THEN_UNREAD: - case OP_MAIN_PREV_NEW_THEN_UNREAD: + case OP_MAIN_NEXT_NEW: + case OP_MAIN_NEXT_UNREAD: + case OP_MAIN_PREV_NEW: + case OP_MAIN_PREV_UNREAD: + case OP_MAIN_NEXT_NEW_THEN_UNREAD: + case OP_MAIN_PREV_NEW_THEN_UNREAD: { int first_unread = -1; - int first_new = -1; - + int first_new = -1; + CHECK_MSGCOUNT; CHECK_VISIBLE; i = menu->current; menu->current = -1; - for (j = 0; j != Context->vcount; j++) - { -#define CURHDRi Context->hdrs[Context->v2r[i]] - if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) - { + for (j = 0; j != Context->vcount; j++) { +#define CURHDRi Context->hdrs[Context->v2r[i]] + if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD + || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) { i++; - if (i > Context->vcount - 1) - { + if (i > Context->vcount - 1) { mutt_message _("Search wrapped to top."); + i = 0; } } - else - { + else { i--; - if (i < 0) - { + if (i < 0) { mutt_message _("Search wrapped to bottom."); + i = Context->vcount - 1; } } - if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) - { + if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) { if (UNREAD (CURHDRi) && first_unread == -1) first_unread = i; if (UNREAD (CURHDRi) == 1 && first_new == -1) first_new = i; } - else if ((!CURHDRi->deleted && !CURHDRi->read)) - { + else if ((!CURHDRi->deleted && !CURHDRi->read)) { if (first_unread == -1) first_unread = i; if ((!CURHDRi->old) && first_new == -1) first_new = i; } - + if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) && first_unread != -1) break; if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW || - op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD) + op == OP_MAIN_NEXT_NEW_THEN_UNREAD + || op == OP_MAIN_PREV_NEW_THEN_UNREAD) && first_new != -1) break; } #undef CURHDRi if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW || - op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD) + op == OP_MAIN_NEXT_NEW_THEN_UNREAD + || op == OP_MAIN_PREV_NEW_THEN_UNREAD) && first_new != -1) menu->current = first_new; else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD || - op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD) + op == OP_MAIN_NEXT_NEW_THEN_UNREAD + || op == OP_MAIN_PREV_NEW_THEN_UNREAD) && first_unread != -1) menu->current = first_unread; - if (menu->current == -1) - { + if (menu->current == -1) { menu->current = menu->oldcurrent; - mutt_error ("%s%s.", (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW) ? _("No new messages") : _("No unread messages"), + mutt_error ("%s%s.", + (op == OP_MAIN_NEXT_NEW + || op == + OP_MAIN_PREV_NEW) ? _("No new messages") : + _("No unread messages"), Context->pattern ? _(" in this limited view") : ""); } - else if (menu->menu == MENU_PAGER) - { + else if (menu->menu == MENU_PAGER) { op = OP_DISPLAY_MESSAGE; continue; } @@ -1721,785 +1648,755 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE); menu->redraw = REDRAW_MOTION; break; } - case OP_FLAG_MESSAGE: + case OP_FLAG_MESSAGE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_POP - if (Context->magic == M_POP) - { - mutt_flushinp (); - mutt_error _("Can't change 'important' flag on POP server."); - break; - } + if (Context->magic == M_POP) { + mutt_flushinp (); + mutt_error (_("Can't change 'important' flag on POP server.")); + + break; + } #endif #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_WRITE); + CHECK_IMAP_ACL (IMAP_ACL_WRITE); #endif #ifdef USE_NNTP - if (Context->magic == M_NNTP) - { - mutt_flushinp (); - mutt_error _("Can't change 'important' flag on NNTP server."); - break; - } -#endif + if (Context->magic == M_NNTP) { + mutt_flushinp (); + mutt_error (_("Can't change 'important' flag on NNTP server.")); - if (tag) - { - for (j = 0; j < Context->vcount; j++) - { - if (Context->hdrs[Context->v2r[j]]->tagged) - mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], - M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged); - } + break; + } +#endif - menu->redraw |= REDRAW_INDEX; + if (tag) { + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->tagged) + mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], + M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged); } - else - { - mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged); - if (option (OPTRESOLVE)) - { - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - menu->redraw = REDRAW_CURRENT; - } - else - menu->redraw = REDRAW_MOTION_RESYNCH; + + menu->redraw |= REDRAW_INDEX; + } + else { + mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged); + if (option (OPTRESOLVE)) { + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + menu->redraw = REDRAW_CURRENT; } else - menu->redraw = REDRAW_CURRENT; + menu->redraw = REDRAW_MOTION_RESYNCH; } - menu->redraw |= REDRAW_STATUS; - break; + else + menu->redraw = REDRAW_CURRENT; + } + menu->redraw |= REDRAW_STATUS; + break; - case OP_TOGGLE_NEW: + case OP_TOGGLE_NEW: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_SEEN); + CHECK_IMAP_ACL (IMAP_ACL_SEEN); #endif - if (tag) - { - for (j = 0; j < Context->vcount; j++) - { - if (Context->hdrs[Context->v2r[j]]->tagged) - { - if (Context->hdrs[Context->v2r[j]]->read || - Context->hdrs[Context->v2r[j]]->old) - mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, 1); - else - mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, 1); - } + if (tag) { + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->tagged) { + if (Context->hdrs[Context->v2r[j]]->read || + Context->hdrs[Context->v2r[j]]->old) + mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, + 1); + else + mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, + 1); } - menu->redraw = REDRAW_STATUS | REDRAW_INDEX; } + menu->redraw = REDRAW_STATUS | REDRAW_INDEX; + } + else { + if (CURHDR->read || CURHDR->old) + mutt_set_flag (Context, CURHDR, M_NEW, 1); else - { - if (CURHDR->read || CURHDR->old) - mutt_set_flag (Context, CURHDR, M_NEW, 1); - else - mutt_set_flag (Context, CURHDR, M_READ, 1); - - if (option (OPTRESOLVE)) - { - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - menu->redraw = REDRAW_CURRENT; - } - else - menu->redraw = REDRAW_MOTION_RESYNCH; + mutt_set_flag (Context, CURHDR, M_READ, 1); + + if (option (OPTRESOLVE)) { + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + menu->redraw = REDRAW_CURRENT; } else - menu->redraw = REDRAW_CURRENT; - menu->redraw |= REDRAW_STATUS; + menu->redraw = REDRAW_MOTION_RESYNCH; } - break; + else + menu->redraw = REDRAW_CURRENT; + menu->redraw |= REDRAW_STATUS; + } + break; - case OP_TOGGLE_WRITE: + case OP_TOGGLE_WRITE: - CHECK_MSGCOUNT; - if (mx_toggle_write (Context) == 0) - menu->redraw |= REDRAW_STATUS; - break; + CHECK_MSGCOUNT; + if (mx_toggle_write (Context) == 0) + menu->redraw |= REDRAW_STATUS; + break; + + case OP_MAIN_NEXT_THREAD: + case OP_MAIN_NEXT_SUBTHREAD: + case OP_MAIN_PREV_THREAD: + case OP_MAIN_PREV_SUBTHREAD: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + switch (op) { case OP_MAIN_NEXT_THREAD: + menu->current = mutt_next_thread (CURHDR); + break; + case OP_MAIN_NEXT_SUBTHREAD: - case OP_MAIN_PREV_THREAD: - case OP_MAIN_PREV_SUBTHREAD: + menu->current = mutt_next_subthread (CURHDR); + break; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - switch (op) - { - case OP_MAIN_NEXT_THREAD: - menu->current = mutt_next_thread (CURHDR); - break; + case OP_MAIN_PREV_THREAD: + menu->current = mutt_previous_thread (CURHDR); + break; - case OP_MAIN_NEXT_SUBTHREAD: - menu->current = mutt_next_subthread (CURHDR); - break; - - case OP_MAIN_PREV_THREAD: - menu->current = mutt_previous_thread (CURHDR); - break; + case OP_MAIN_PREV_SUBTHREAD: + menu->current = mutt_previous_subthread (CURHDR); + break; + } - case OP_MAIN_PREV_SUBTHREAD: - menu->current = mutt_previous_subthread (CURHDR); - break; - } + if (menu->current < 0) { + menu->current = menu->oldcurrent; + if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD) + mutt_error (_("No more threads.")); - if (menu->current < 0) - { - menu->current = menu->oldcurrent; - if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD) - mutt_error _("No more threads."); - else - mutt_error _("You are on the first thread."); - } - else if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } else - menu->redraw = REDRAW_MOTION; - break; + mutt_error (_("You are on the first thread.")); + } + else if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_MAIN_PARENT_MESSAGE: + case OP_MAIN_PARENT_MESSAGE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; + CHECK_MSGCOUNT; + CHECK_VISIBLE; - if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) - { - menu->current = menu->oldcurrent; - } - else if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw = REDRAW_MOTION; - break; + if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) { + menu->current = menu->oldcurrent; + } + else if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + menu->redraw = REDRAW_MOTION; + break; - case OP_MAIN_SET_FLAG: - case OP_MAIN_CLEAR_FLAG: + case OP_MAIN_SET_FLAG: + case OP_MAIN_CLEAR_FLAG: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; - /* #ifdef USE_IMAP CHECK_IMAP_ACL(IMAP_ACL_WRITE); #endif */ - if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) - { - menu->redraw = REDRAW_STATUS; - if (tag) - menu->redraw |= REDRAW_INDEX; - else if (option (OPTRESOLVE)) - { - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - menu->redraw |= REDRAW_CURRENT; - } - else - menu->redraw |= REDRAW_MOTION_RESYNCH; + if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == + 0) { + menu->redraw = REDRAW_STATUS; + if (tag) + menu->redraw |= REDRAW_INDEX; + else if (option (OPTRESOLVE)) { + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + menu->redraw |= REDRAW_CURRENT; } else - menu->redraw |= REDRAW_CURRENT; + menu->redraw |= REDRAW_MOTION_RESYNCH; } + else + menu->redraw |= REDRAW_CURRENT; + } + break; + + case OP_MAIN_COLLAPSE_THREAD: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + + if ((Sort & SORT_MASK) != SORT_THREADS) { + mutt_error (_("Threading is not enabled.")); + break; + } - case OP_MAIN_COLLAPSE_THREAD: - CHECK_MSGCOUNT; - CHECK_VISIBLE; + if (CURHDR->collapsed) { + menu->current = mutt_uncollapse_thread (Context, CURHDR); + mutt_set_virtual (Context); + if (option (OPTUNCOLLAPSEJUMP)) + menu->current = mutt_thread_next_unread (Context, CURHDR); + } + else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) { + menu->current = mutt_collapse_thread (Context, CURHDR); + mutt_set_virtual (Context); + } + else { + mutt_error (_("Thread contains unread messages.")); + + break; + } + + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + + break; + + case OP_MAIN_COLLAPSE_ALL: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + + if ((Sort & SORT_MASK) != SORT_THREADS) { + mutt_error (_("Threading is not enabled.")); + + break; + } + + { + HEADER *h, *base; + THREAD *thread, *top; + int final; - if ((Sort & SORT_MASK) != SORT_THREADS) - { - mutt_error _("Threading is not enabled."); - break; - } - if (CURHDR->collapsed) - { - menu->current = mutt_uncollapse_thread (Context, CURHDR); - mutt_set_virtual (Context); - if (option (OPTUNCOLLAPSEJUMP)) - menu->current = mutt_thread_next_unread (Context, CURHDR); - } + final = mutt_uncollapse_thread (Context, CURHDR); else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) - { - menu->current = mutt_collapse_thread (Context, CURHDR); - mutt_set_virtual (Context); - } + final = mutt_collapse_thread (Context, CURHDR); else - { - mutt_error _("Thread contains unread messages."); - break; - } + final = CURHDR->virtual; - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - - break; - - case OP_MAIN_COLLAPSE_ALL: - CHECK_MSGCOUNT; - CHECK_VISIBLE; + base = Context->hdrs[Context->v2r[final]]; - if ((Sort & SORT_MASK) != SORT_THREADS) - { - mutt_error _("Threading is not enabled."); - break; - } + top = Context->tree; + Context->collapsed = !Context->collapsed; + while ((thread = top) != NULL) { + while (!thread->message) + thread = thread->child; + h = thread->message; - { - HEADER *h, *base; - THREAD *thread, *top; - int final; - - if (CURHDR->collapsed) - final = mutt_uncollapse_thread (Context, CURHDR); - else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) - final = mutt_collapse_thread (Context, CURHDR); - else - final = CURHDR->virtual; - - base = Context->hdrs[Context->v2r[final]]; - - top = Context->tree; - Context->collapsed = !Context->collapsed; - while ((thread = top) != NULL) - { - while (!thread->message) - thread = thread->child; - h = thread->message; - - if (h->collapsed != Context->collapsed) - { - if (h->collapsed) - mutt_uncollapse_thread (Context, h); - else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h)) - mutt_collapse_thread (Context, h); - } - top = top->next; + if (h->collapsed != Context->collapsed) { + if (h->collapsed) + mutt_uncollapse_thread (Context, h); + else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h)) + mutt_collapse_thread (Context, h); } - - mutt_set_virtual (Context); - for (j = 0; j < Context->vcount; j++) - { - if (Context->hdrs[Context->v2r[j]]->index == base->index) - { - menu->current = j; - break; - } + top = top->next; + } + + mutt_set_virtual (Context); + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->index == base->index) { + menu->current = j; + break; } - - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } - break; - + + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; + /* -------------------------------------------------------------------- * These functions are invoked directly from the internal-pager */ - case OP_BOUNCE_MESSAGE: + case OP_BOUNCE_MESSAGE: - CHECK_ATTACH; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw); - break; + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw); + break; - case OP_CREATE_ALIAS: + case OP_CREATE_ALIAS: - mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL); - MAYBE_REDRAW (menu->redraw); - menu->redraw |= REDRAW_CURRENT; - break; + mutt_create_alias (Context + && Context->vcount ? CURHDR->env : NULL, NULL); + MAYBE_REDRAW (menu->redraw); + menu->redraw |= REDRAW_CURRENT; + break; - case OP_QUERY: - CHECK_ATTACH; - mutt_query_menu (NULL, 0); - MAYBE_REDRAW (menu->redraw); - break; + case OP_QUERY: + CHECK_ATTACH; + mutt_query_menu (NULL, 0); + MAYBE_REDRAW (menu->redraw); + break; - case OP_PURGE_MESSAGE: - case OP_DELETE: + case OP_PURGE_MESSAGE: + case OP_DELETE: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; - #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - if (tag) - { - mutt_tag_set_flag (M_DELETE, 1); - mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1); - if (option (OPTDELETEUNTAG)) - mutt_tag_set_flag (M_TAG, 0); - menu->redraw = REDRAW_INDEX; - } - else - { - mutt_set_flag (Context, CURHDR, M_DELETE, 1); - mutt_set_flag (Context, CURHDR, M_PURGED, - (op != OP_PURGE_MESSAGE) ? 0 : 1); - if (option (OPTDELETEUNTAG)) - mutt_set_flag (Context, CURHDR, M_TAG, 0); - if (option (OPTRESOLVE)) - { - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - { - menu->current = menu->oldcurrent; - menu->redraw = REDRAW_CURRENT; - } - else if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - menu->redraw |= REDRAW_MOTION_RESYNCH; + if (tag) { + mutt_tag_set_flag (M_DELETE, 1); + mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1); + if (option (OPTDELETEUNTAG)) + mutt_tag_set_flag (M_TAG, 0); + menu->redraw = REDRAW_INDEX; + } + else { + mutt_set_flag (Context, CURHDR, M_DELETE, 1); + mutt_set_flag (Context, CURHDR, M_PURGED, + (op != OP_PURGE_MESSAGE) ? 0 : 1); + if (option (OPTDELETEUNTAG)) + mutt_set_flag (Context, CURHDR, M_TAG, 0); + if (option (OPTRESOLVE)) { + if ((menu->current = ci_next_undeleted (menu->current)) == -1) { + menu->current = menu->oldcurrent; + menu->redraw = REDRAW_CURRENT; + } + else if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; } else - menu->redraw = REDRAW_CURRENT; + menu->redraw |= REDRAW_MOTION_RESYNCH; } - menu->redraw |= REDRAW_STATUS; - break; + else + menu->redraw = REDRAW_CURRENT; + } + menu->redraw |= REDRAW_STATUS; + break; - case OP_DELETE_THREAD: - case OP_DELETE_SUBTHREAD: + case OP_DELETE_THREAD: + case OP_DELETE_SUBTHREAD: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1, - op == OP_DELETE_THREAD ? 0 : 1); + rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1, + op == OP_DELETE_THREAD ? 0 : 1); - if (rc != -1) - { - if (option (OPTDELETEUNTAG)) - mutt_thread_set_flag (CURHDR, M_TAG, 0, - op == OP_DELETE_THREAD ? 0 : 1); - if (option (OPTRESOLVE)) - if ((menu->current = ci_next_undeleted (menu->current)) == -1) - menu->current = menu->oldcurrent; - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - } - break; + if (rc != -1) { + if (option (OPTDELETEUNTAG)) + mutt_thread_set_flag (CURHDR, M_TAG, 0, + op == OP_DELETE_THREAD ? 0 : 1); + if (option (OPTRESOLVE)) + if ((menu->current = ci_next_undeleted (menu->current)) == -1) + menu->current = menu->oldcurrent; + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; #ifdef USE_NNTP - case OP_CATCHUP: - if (Context && Context->magic == M_NNTP) - { - if (mutt_newsgroup_catchup (CurrentNewsSrv, - ((NNTP_DATA *)Context->data)->group)) - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - } - break; + case OP_CATCHUP: + if (Context && Context->magic == M_NNTP) { + if (mutt_newsgroup_catchup (CurrentNewsSrv, + ((NNTP_DATA *) Context->data)->group)) + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; #endif - case OP_DISPLAY_ADDRESS: + case OP_DISPLAY_ADDRESS: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - mutt_display_address (CURHDR->env); - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + mutt_display_address (CURHDR->env); + break; - case OP_ENTER_COMMAND: + case OP_ENTER_COMMAND: - CurrentMenu = MENU_MAIN; - mutt_enter_command (); - mutt_check_rescore (Context); - if (option (OPTFORCEREDRAWINDEX)) - menu->redraw = REDRAW_FULL; - unset_option (OPTFORCEREDRAWINDEX); - unset_option (OPTFORCEREDRAWPAGER); - break; + CurrentMenu = MENU_MAIN; + mutt_enter_command (); + mutt_check_rescore (Context); + if (option (OPTFORCEREDRAWINDEX)) + menu->redraw = REDRAW_FULL; + unset_option (OPTFORCEREDRAWINDEX); + unset_option (OPTFORCEREDRAWPAGER); + break; - case OP_EDIT_MESSAGE: + case OP_EDIT_MESSAGE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; - CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; + CHECK_ATTACH; #ifdef USE_POP - if (Context->magic == M_POP) - { - mutt_flushinp (); - mutt_error _("Can't edit message on POP server."); - break; - } + if (Context->magic == M_POP) { + mutt_flushinp (); + mutt_error (_("Can't edit message on POP server.")); + + break; + } #endif #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_INSERT); + CHECK_IMAP_ACL (IMAP_ACL_INSERT); #endif #ifdef USE_NNTP - if (Context->magic == M_NNTP) - { - mutt_flushinp (); - mutt_error _("Can't edit message on newsserver."); - break; - } + if (Context->magic == M_NNTP) { + mutt_flushinp (); + mutt_error (_("Can't edit message on newsserver.")); + + break; + } #endif - if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))) - mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); - mutt_edit_message (Context, tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; + if (option (OPTPGPAUTODEC) + && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))) + mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); + mutt_edit_message (Context, tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; - break; + break; - case OP_FORWARD_MESSAGE: + case OP_FORWARD_MESSAGE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_ATTACH; - ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_ATTACH; + ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; - case OP_FORGET_PASSPHRASE: - crypt_forget_passphrase (); - break; + case OP_FORGET_PASSPHRASE: + crypt_forget_passphrase (); + break; - case OP_GROUP_REPLY: + case OP_GROUP_REPLY: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_ATTACH; - ci_send_message (SENDREPLY|SENDGROUPREPLY, NULL, NULL, Context, tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_ATTACH; + ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context, + tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; - case OP_LIST_REPLY: + case OP_LIST_REPLY: - CHECK_ATTACH; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - ci_send_message (SENDREPLY|SENDLISTREPLY, NULL, NULL, Context, tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; - break; + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context, + tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; - case OP_MAIL: + case OP_MAIL: - CHECK_ATTACH; - ci_send_message (0, NULL, NULL, Context, NULL); - menu->redraw = REDRAW_FULL; - break; + CHECK_ATTACH; + ci_send_message (0, NULL, NULL, Context, NULL); + menu->redraw = REDRAW_FULL; + break; - case OP_MAIL_KEY: - if (!(WithCrypto & APPLICATION_PGP)) - break; - CHECK_ATTACH; - ci_send_message (SENDKEY, NULL, NULL, NULL, NULL); - menu->redraw = REDRAW_FULL; + case OP_MAIL_KEY: + if (!(WithCrypto & APPLICATION_PGP)) break; + CHECK_ATTACH; + ci_send_message (SENDKEY, NULL, NULL, NULL, NULL); + menu->redraw = REDRAW_FULL; + break; - - case OP_EXTRACT_KEYS: - if (!WithCrypto) - break; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - crypt_extract_keys_from_messages(tag ? NULL : CURHDR); - menu->redraw = REDRAW_FULL; + + case OP_EXTRACT_KEYS: + if (!WithCrypto) break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + crypt_extract_keys_from_messages (tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; - case OP_CHECK_TRADITIONAL: - if (!(WithCrypto & APPLICATION_PGP)) - break; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)) - mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); - - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } + case OP_CHECK_TRADITIONAL: + if (!(WithCrypto & APPLICATION_PGP)) break; - - case OP_PIPE: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)) + mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); - CHECK_MSGCOUNT; - CHECK_VISIBLE; - mutt_pipe_message (tag ? NULL : CURHDR); - MAYBE_REDRAW (menu->redraw); - break; + if (menu->menu == MENU_PAGER) { + op = OP_DISPLAY_MESSAGE; + continue; + } + break; - case OP_PRINT: + case OP_PIPE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - mutt_print_message (tag ? NULL : CURHDR); - break; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + mutt_pipe_message (tag ? NULL : CURHDR); + MAYBE_REDRAW (menu->redraw); + break; - case OP_MAIN_READ_THREAD: - case OP_MAIN_READ_SUBTHREAD: + case OP_PRINT: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + mutt_print_message (tag ? NULL : CURHDR); + break; + + case OP_MAIN_READ_THREAD: + case OP_MAIN_READ_SUBTHREAD: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_SEEN); + CHECK_IMAP_ACL (IMAP_ACL_SEEN); #endif - rc = mutt_thread_set_flag (CURHDR, M_READ, 1, - op == OP_MAIN_READ_THREAD ? 0 : 1); + rc = mutt_thread_set_flag (CURHDR, M_READ, 1, + op == OP_MAIN_READ_THREAD ? 0 : 1); - if (rc != -1) - { - if (option (OPTRESOLVE)) - { - if ((menu->current = (op == OP_MAIN_READ_THREAD ? - mutt_next_thread (CURHDR) : mutt_next_subthread (CURHDR))) == -1) - menu->current = menu->oldcurrent; - } - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + if (rc != -1) { + if (option (OPTRESOLVE)) { + if ((menu->current = (op == OP_MAIN_READ_THREAD ? + mutt_next_thread (CURHDR) : + mutt_next_subthread (CURHDR))) == -1) + menu->current = menu->oldcurrent; } - break; + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; - case OP_RECALL_MESSAGE: + case OP_RECALL_MESSAGE: - CHECK_ATTACH; - ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL); - menu->redraw = REDRAW_FULL; - break; + CHECK_ATTACH; + ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL); + menu->redraw = REDRAW_FULL; + break; - case OP_RESEND: - - CHECK_ATTACH; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - - if (tag) - { - for (j = 0; j < Context->vcount; j++) - { - if (Context->hdrs[Context->v2r[j]]->tagged) - mutt_resend_message (NULL, Context, Context->hdrs[Context->v2r[j]]); - } + case OP_RESEND: + + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + + if (tag) { + for (j = 0; j < Context->vcount; j++) { + if (Context->hdrs[Context->v2r[j]]->tagged) + mutt_resend_message (NULL, Context, + Context->hdrs[Context->v2r[j]]); } - else - mutt_resend_message (NULL, Context, CURHDR); - - menu->redraw = REDRAW_FULL; - break; + } + else + mutt_resend_message (NULL, Context, CURHDR); + + menu->redraw = REDRAW_FULL; + break; #ifdef USE_NNTP - case OP_POST: - case OP_FOLLOWUP: - case OP_FORWARD_TO_GROUP: - - CHECK_ATTACH; - if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) && - Context && Context->msgcount == 0) { - mutt_error (_("There are no messages.")); - sleep (2); - } else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to || - mutt_strcasecmp (CURHDR->env->followup_to, "poster") || - query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES) - { - if (Context && Context->magic == M_NNTP && - !((NNTP_DATA *)Context->data)->allowed && - query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES) - break; - if (op == OP_POST) - ci_send_message (SENDNEWS, NULL, NULL, Context, NULL); - else - { - CHECK_MSGCOUNT; - if (op == OP_FOLLOWUP) - ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context, - tag ? NULL : CURHDR); - else - ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context, - tag ? NULL : CURHDR); - } - menu->redraw = REDRAW_FULL; + case OP_POST: + case OP_FOLLOWUP: + case OP_FORWARD_TO_GROUP: + + CHECK_ATTACH; + if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) && + Context && Context->msgcount == 0) { + mutt_error (_("There are no messages.")); + sleep (2); + } + else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to || + mutt_strcasecmp (CURHDR->env->followup_to, "poster") || + query_quadoption (OPT_FOLLOWUPTOPOSTER, + _("Reply by mail as poster prefers?")) != + M_YES) { + if (Context && Context->magic == M_NNTP + && !((NNTP_DATA *) Context->data)->allowed + && query_quadoption (OPT_TOMODERATED, + _ + ("Posting to this group not allowed, may be moderated. Continue?")) + != M_YES) break; + if (op == OP_POST) + ci_send_message (SENDNEWS, NULL, NULL, Context, NULL); + else { + CHECK_MSGCOUNT; + if (op == OP_FOLLOWUP) + ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context, + tag ? NULL : CURHDR); + else + ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context, + tag ? NULL : CURHDR); } -#endif - - case OP_REPLY: - - CHECK_ATTACH; - CHECK_MSGCOUNT; - CHECK_VISIBLE; - ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR); menu->redraw = REDRAW_FULL; break; + } +#endif - case OP_SHELL_ESCAPE: + case OP_REPLY: - mutt_shell_escape (); - MAYBE_REDRAW (menu->redraw); - break; + CHECK_ATTACH; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR); + menu->redraw = REDRAW_FULL; + break; - case OP_TAG_THREAD: - case OP_TAG_SUBTHREAD: + case OP_SHELL_ESCAPE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged, - op == OP_TAG_THREAD ? 0 : 1); - - if (rc != -1) - { - if (option (OPTRESOLVE)) - { - menu->current = mutt_next_thread (CURHDR); + mutt_shell_escape (); + MAYBE_REDRAW (menu->redraw); + break; - if (menu->current == -1) - menu->current = menu->oldcurrent; - } - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + case OP_TAG_THREAD: + case OP_TAG_SUBTHREAD: + + CHECK_MSGCOUNT; + CHECK_VISIBLE; + rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged, + op == OP_TAG_THREAD ? 0 : 1); + + if (rc != -1) { + if (option (OPTRESOLVE)) { + menu->current = mutt_next_thread (CURHDR); + + if (menu->current == -1) + menu->current = menu->oldcurrent; } - break; + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; - case OP_UNDELETE: + case OP_UNDELETE: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - - if (tag) - { - mutt_tag_set_flag (M_DELETE, 0); - mutt_tag_set_flag (M_PURGED, 0); - menu->redraw = REDRAW_INDEX; + + if (tag) { + mutt_tag_set_flag (M_DELETE, 0); + mutt_tag_set_flag (M_PURGED, 0); + menu->redraw = REDRAW_INDEX; + } + else { + mutt_set_flag (Context, CURHDR, M_DELETE, 0); + mutt_set_flag (Context, CURHDR, M_PURGED, 0); + if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) { + menu->current++; + menu->redraw = REDRAW_MOTION_RESYNCH; } else - { - mutt_set_flag (Context, CURHDR, M_DELETE, 0); - mutt_set_flag (Context, CURHDR, M_PURGED, 0); - if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) - { - menu->current++; - menu->redraw = REDRAW_MOTION_RESYNCH; - } - else - menu->redraw = REDRAW_CURRENT; - } - menu->redraw |= REDRAW_STATUS; - break; + menu->redraw = REDRAW_CURRENT; + } + menu->redraw |= REDRAW_STATUS; + break; - case OP_UNDELETE_THREAD: - case OP_UNDELETE_SUBTHREAD: + case OP_UNDELETE_THREAD: + case OP_UNDELETE_SUBTHREAD: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - CHECK_READONLY; + CHECK_MSGCOUNT; + CHECK_VISIBLE; + CHECK_READONLY; #ifdef USE_IMAP -CHECK_IMAP_ACL(IMAP_ACL_DELETE); + CHECK_IMAP_ACL (IMAP_ACL_DELETE); #endif - rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0, - op == OP_UNDELETE_THREAD ? 0 : 1) - + mutt_thread_set_flag (CURHDR, M_PURGED, 0, - op == OP_UNDELETE_THREAD ? 0 : 1); + rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0, + op == OP_UNDELETE_THREAD ? 0 : 1) + + mutt_thread_set_flag (CURHDR, M_PURGED, 0, + op == OP_UNDELETE_THREAD ? 0 : 1); - if (rc > -1) - { - if (option (OPTRESOLVE)) - { - if (op == OP_UNDELETE_THREAD) - menu->current = mutt_next_thread (CURHDR); - else - menu->current = mutt_next_subthread (CURHDR); + if (rc > -1) { + if (option (OPTRESOLVE)) { + if (op == OP_UNDELETE_THREAD) + menu->current = mutt_next_thread (CURHDR); + else + menu->current = mutt_next_subthread (CURHDR); - if (menu->current == -1) - menu->current = menu->oldcurrent; - } - menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + if (menu->current == -1) + menu->current = menu->oldcurrent; } - break; + menu->redraw = REDRAW_INDEX | REDRAW_STATUS; + } + break; - case OP_VERSION: - mutt_version (); - break; + case OP_VERSION: + mutt_version (); + break; - case OP_BUFFY_LIST: - mutt_buffy_list (); - menu->redraw = REDRAW_FULL; - break; + case OP_BUFFY_LIST: + mutt_buffy_list (); + menu->redraw = REDRAW_FULL; + break; - case OP_VIEW_ATTACHMENTS: - CHECK_MSGCOUNT; - CHECK_VISIBLE; - mutt_view_attachments (CURHDR); - if (CURHDR->attach_del) - Context->changed = 1; - menu->redraw = REDRAW_FULL; - break; + case OP_VIEW_ATTACHMENTS: + CHECK_MSGCOUNT; + CHECK_VISIBLE; + mutt_view_attachments (CURHDR); + if (CURHDR->attach_del) + Context->changed = 1; + menu->redraw = REDRAW_FULL; + break; - case OP_END_COND: - break; + case OP_END_COND: + break; - case OP_WHAT_KEY: - mutt_what_key(); - break; + case OP_WHAT_KEY: + mutt_what_key (); + break; - case OP_SIDEBAR_SCROLL_UP: - case OP_SIDEBAR_SCROLL_DOWN: - case OP_SIDEBAR_NEXT: - case OP_SIDEBAR_PREV: - case OP_SIDEBAR_NEXT_NEW: - case OP_SIDEBAR_PREV_NEW: - scroll_sidebar(op, menu->menu); - break; - default: - if (menu->menu == MENU_MAIN) - km_error_key (MENU_MAIN); + case OP_SIDEBAR_SCROLL_UP: + case OP_SIDEBAR_SCROLL_DOWN: + case OP_SIDEBAR_NEXT: + case OP_SIDEBAR_PREV: + case OP_SIDEBAR_NEXT_NEW: + case OP_SIDEBAR_PREV_NEW: + scroll_sidebar (op, menu->menu); + break; + default: + if (menu->menu == MENU_MAIN) + km_error_key (MENU_MAIN); } - if (menu->menu == MENU_PAGER) - { + if (menu->menu == MENU_PAGER) { menu->menu = MENU_MAIN; menu->redraw = REDRAW_FULL; #if 0 - set_option (OPTWEED); /* turn header weeding back on. */ + set_option (OPTWEED); /* turn header weeding back on. */ #endif } - if (done) break; + if (done) + break; } #ifdef USE_IMAP @@ -2517,18 +2414,18 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE); return (close); } -void mutt_set_header_color (CONTEXT *ctx, HEADER *curhdr) +void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr) { COLOR_LINE *color; if (!curhdr) return; - + for (color = ColorIndexList; color; color = color->next) - if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) - { + if (mutt_pattern_exec + (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) { curhdr->pair = color->pair; return; - } + } curhdr->pair = ColorDefs[MT_COLOR_NORMAL]; } diff --git a/date.c b/date.c index b97b113..f9a2075 100644 --- a/date.c +++ b/date.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -33,11 +33,10 @@ static time_t compute_tz (time_t g, struct tm *utc) t = (((lt->tm_hour - utc->tm_hour) * 60) + (lt->tm_min - utc->tm_min)) * 60; - if ((yday = (lt->tm_yday - utc->tm_yday))) - { + if ((yday = (lt->tm_yday - utc->tm_yday))) { /* This code is optimized to negative timezones (West of Greenwich) */ - if (yday == -1 || /* UTC passed midnight before localtime */ - yday > 1) /* UTC passed new year before localtime */ + if (yday == -1 || /* UTC passed midnight before localtime */ + yday > 1) /* UTC passed new year before localtime */ t -= 24 * 60 * 60; else t += 24 * 60 * 60; @@ -65,7 +64,7 @@ time_t mutt_local_tz (time_t t) /* converts struct tm to time_t, but does not take the local timezone into account unless ``local'' is nonzero */ -time_t mutt_mktime (struct tm *t, int local) +time_t mutt_mktime (struct tm * t, int local) { time_t g; @@ -74,7 +73,7 @@ time_t mutt_mktime (struct tm *t, int local) }; /* Compute the number of days since January 1 in the same year */ - g = AccumDaysPerMonth [t->tm_mon % 12]; + g = AccumDaysPerMonth[t->tm_mon % 12]; /* The leap years are 1972 and every 4. year until 2096, * but this algoritm will fail after year 2099 */ @@ -108,9 +107,9 @@ time_t mutt_mktime (struct tm *t, int local) /* Return 1 if month is February of leap year, else 0 */ static int isLeapYearFeb (struct tm *tm) { - if (tm->tm_mon == 1) - { + if (tm->tm_mon == 1) { int y = tm->tm_year + 1900; + return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0))); } return (0); @@ -123,66 +122,54 @@ void mutt_normalize_time (struct tm *tm) }; int nLeap; - while (tm->tm_sec < 0) - { + while (tm->tm_sec < 0) { tm->tm_sec += 60; tm->tm_min--; } - while (tm->tm_sec >= 60) - { + while (tm->tm_sec >= 60) { tm->tm_sec -= 60; tm->tm_min++; } - while (tm->tm_min < 0) - { + while (tm->tm_min < 0) { tm->tm_min += 60; tm->tm_hour--; } - while (tm->tm_min >= 60) - { + while (tm->tm_min >= 60) { tm->tm_min -= 60; tm->tm_hour++; } - while (tm->tm_hour < 0) - { + while (tm->tm_hour < 0) { tm->tm_hour += 24; tm->tm_mday--; } - while (tm->tm_hour >= 24) - { + while (tm->tm_hour >= 24) { tm->tm_hour -= 24; tm->tm_mday++; } /* use loops on NNNdwmy user input values? */ - while (tm->tm_mon < 0) - { + while (tm->tm_mon < 0) { tm->tm_mon += 12; tm->tm_year--; } - while (tm->tm_mon >= 12) - { + while (tm->tm_mon >= 12) { tm->tm_mon -= 12; tm->tm_year++; } - while (tm->tm_mday <= 0) - { + while (tm->tm_mday <= 0) { if (tm->tm_mon) tm->tm_mon--; - else - { + else { tm->tm_mon = 11; tm->tm_year--; } tm->tm_mday += DaysPerMonth[tm->tm_mon] + isLeapYearFeb (tm); } - while (tm->tm_mday > (DaysPerMonth[tm->tm_mon] + - (nLeap = isLeapYearFeb (tm)))) - { + while (tm->tm_mday > (DaysPerMonth[tm->tm_mon] + + (nLeap = isLeapYearFeb (tm)))) { tm->tm_mday -= DaysPerMonth[tm->tm_mon] + nLeap; if (tm->tm_mon < 11) tm->tm_mon++; - else - { + else { tm->tm_mon = 0; tm->tm_year++; } diff --git a/dotlock.c b/dotlock.c index 008c1c6..eb4ba30 100644 --- a/dotlock.c +++ b/dotlock.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* * This module either be compiled into Mutt, or it can be @@ -57,7 +57,7 @@ # include "reldate.h" #endif -#define MAXLINKS 1024 /* maximum link depth */ +#define MAXLINKS 1024 /* maximum link depth */ #ifdef DL_STANDALONE @@ -83,7 +83,7 @@ extern int snprintf (char *, size_t, const char *, ...); # endif -#else /* DL_STANDALONE */ +#else /* DL_STANDALONE */ # ifdef USE_SETGID # error Do not try to compile dotlock as a mutt module when requiring egid switching! @@ -142,15 +142,15 @@ int main (int argc, char **argv) struct utsname utsname; /* first, drop privileges */ - + if (dotlock_init_privs () == -1) return DL_EX_ERROR; /* determine the system's host name */ - + uname (&utsname); - if (!(Hostname = strdup (utsname.nodename))) /* __MEM_CHECKED__ */ + if (!(Hostname = strdup (utsname.nodename))) /* __MEM_CHECKED__ */ return DL_EX_ERROR; if ((p = strchr (Hostname, '.'))) *p = '\0'; @@ -158,22 +158,37 @@ int main (int argc, char **argv) /* parse the command line options. */ DotlockFlags = 0; - - while ((i = getopt (argc, argv, "dtfupr:")) != EOF) - { - switch (i) - { + + while ((i = getopt (argc, argv, "dtfupr:")) != EOF) { + switch (i) { /* actions, mutually exclusive */ - case 't': check_flags (DotlockFlags); DotlockFlags |= DL_FL_TRY; break; - case 'd': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLINK; break; - case 'u': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLOCK; break; + case 't': + check_flags (DotlockFlags); + DotlockFlags |= DL_FL_TRY; + break; + case 'd': + check_flags (DotlockFlags); + DotlockFlags |= DL_FL_UNLINK; + break; + case 'u': + check_flags (DotlockFlags); + DotlockFlags |= DL_FL_UNLOCK; + break; /* other flags */ - case 'f': DotlockFlags |= DL_FL_FORCE; break; - case 'p': DotlockFlags |= DL_FL_USEPRIV; break; - case 'r': DotlockFlags |= DL_FL_RETRY; Retry = atoi (optarg); break; - - default: usage (argv[0]); + case 'f': + DotlockFlags |= DL_FL_FORCE; + break; + case 'p': + DotlockFlags |= DL_FL_USEPRIV; + break; + case 'r': + DotlockFlags |= DL_FL_RETRY; + Retry = atoi (optarg); + break; + + default: + usage (argv[0]); } } @@ -196,12 +211,11 @@ int main (int argc, char **argv) */ -static int -dotlock_init_privs (void) +static int dotlock_init_privs (void) { # ifdef USE_SETGID - + UserGid = getgid (); MailGid = getegid (); @@ -212,9 +226,9 @@ dotlock_init_privs (void) return 0; } - -#else /* DL_STANDALONE */ + +#else /* DL_STANDALONE */ /* * This function is intended to be invoked from within @@ -227,7 +241,7 @@ int dotlock_invoke (const char *path, int fd, int flags, int retry) int r; DotlockFlags = flags; - + if ((currdir = open (".", O_RDONLY)) == -1) return DL_EX_ERROR; @@ -235,16 +249,16 @@ int dotlock_invoke (const char *path, int fd, int flags, int retry) Retry = MAXLOCKATTEMPT; else Retry = 0; - + r = dotlock_dispatch (path, fd); - + fchdir (currdir); close (currdir); - + return r; } -#endif /* DL_STANDALONE */ +#endif /* DL_STANDALONE */ static int dotlock_dispatch (const char *f, int fd) @@ -273,11 +287,11 @@ static int dotlock_dispatch (const char *f, int fd) return dotlock_unlock (realpath); else if (DotlockFlags & DL_FL_UNLINK) return dotlock_unlink (realpath); - else /* lock */ + else /* lock */ return dotlock_lock (realpath); } - + /* * Get privileges * @@ -289,14 +303,11 @@ static int dotlock_dispatch (const char *f, int fd) * */ -static void -BEGIN_PRIVILEGED (void) +static void BEGIN_PRIVILEGED (void) { #ifdef USE_SETGID - if (DotlockFlags & DL_FL_USEPRIV) - { - if (SETEGID (MailGid) != 0) - { + if (DotlockFlags & DL_FL_USEPRIV) { + if (SETEGID (MailGid) != 0) { /* perror ("setegid"); */ exit (DL_EX_ERROR); } @@ -313,14 +324,11 @@ BEGIN_PRIVILEGED (void) * */ -static void -END_PRIVILEGED (void) +static void END_PRIVILEGED (void) { #ifdef USE_SETGID - if (DotlockFlags & DL_FL_USEPRIV) - { - if (SETEGID (UserGid) != 0) - { + if (DotlockFlags & DL_FL_USEPRIV) { + if (SETEGID (UserGid) != 0) { /* perror ("setegid"); */ exit (DL_EX_ERROR); } @@ -337,25 +345,20 @@ END_PRIVILEGED (void) * */ -static void -usage (const char *av0) +static void usage (const char *av0) { fprintf (stderr, "dotlock [Mutt-ng %s (%s)]\n", VERSION, ReleaseDate); - fprintf (stderr, "usage: %s [-t|-f|-u|-d] [-p] [-r ] file\n", - av0); + fprintf (stderr, "usage: %s [-t|-f|-u|-d] [-p] [-r ] file\n", av0); fputs ("\noptions:" - "\n -t\t\ttry" - "\n -f\t\tforce" - "\n -u\t\tunlock" - "\n -d\t\tunlink" - "\n -p\t\tprivileged" + "\n -t\t\ttry" + "\n -f\t\tforce" + "\n -u\t\tunlock" "\n -d\t\tunlink" "\n -p\t\tprivileged" #ifndef USE_SETGID - " (ignored)" + " (ignored)" #endif - "\n -r \tRetry locking" - "\n", stderr); - + "\n -r \tRetry locking" "\n", stderr); + exit (DL_EX_ERROR); } @@ -409,8 +412,7 @@ usage (const char *av0) * tlr, Jul 15 1998 */ -static int -dotlock_check_stats (struct stat *fsb, struct stat *lsb) +static int dotlock_check_stats (struct stat *fsb, struct stat *lsb) { /* S_ISLNK (fsb->st_mode) should actually be impossible, * but we may have mixed up the parameters somewhere. @@ -419,25 +421,22 @@ dotlock_check_stats (struct stat *fsb, struct stat *lsb) if (S_ISLNK (lsb->st_mode) || S_ISLNK (fsb->st_mode)) return -1; - + if ((lsb->st_dev != fsb->st_dev) || - (lsb->st_ino != fsb->st_ino) || - (lsb->st_mode != fsb->st_mode) || - (lsb->st_nlink != fsb->st_nlink) || - (lsb->st_uid != fsb->st_uid) || - (lsb->st_gid != fsb->st_gid) || - (lsb->st_rdev != fsb->st_rdev) || - (lsb->st_size != fsb->st_size)) - { + (lsb->st_ino != fsb->st_ino) || + (lsb->st_mode != fsb->st_mode) || + (lsb->st_nlink != fsb->st_nlink) || + (lsb->st_uid != fsb->st_uid) || + (lsb->st_gid != fsb->st_gid) || + (lsb->st_rdev != fsb->st_rdev) || (lsb->st_size != fsb->st_size)) { /* something's fishy */ return -1; } - + return 0; } -static int -dotlock_prepare (char *bn, size_t l, const char *f, int _fd) +static int dotlock_prepare (char *bn, size_t l, const char *f, int _fd) { struct stat fsb, lsb; char realpath[_POSIX_PATH_MAX]; @@ -445,27 +444,25 @@ dotlock_prepare (char *bn, size_t l, const char *f, int _fd) char *p; int fd; int r; - + if (dotlock_deference_symlink (realpath, sizeof (realpath), f) == -1) return -1; - - if ((p = strrchr (realpath, '/'))) - { + + if ((p = strrchr (realpath, '/'))) { *p = '\0'; basename = p + 1; dirname = realpath; } - else - { + else { basename = realpath; dirname = "."; } if (strlen (basename) + 1 > l) return -1; - + strfcpy (bn, basename, l); - + if (chdir (dirname) == -1) return -1; @@ -473,15 +470,15 @@ dotlock_prepare (char *bn, size_t l, const char *f, int _fd) fd = _fd; else if ((fd = open (basename, O_RDONLY)) == -1) return -1; - + r = fstat (fd, &fsb); - + if (_fd == -1) close (fd); - + if (r == -1) return -1; - + if (lstat (basename, &lsb) == -1) return -1; @@ -499,21 +496,19 @@ dotlock_prepare (char *bn, size_t l, const char *f, int _fd) * */ -static void +static void dotlock_expand_link (char *newpath, const char *path, const char *link) { const char *lb = NULL; size_t len; /* link is full path */ - if (*link == '/') - { + if (*link == '/') { strfcpy (newpath, link, _POSIX_PATH_MAX); return; } - if ((lb = strrchr (path, '/')) == NULL) - { + if ((lb = strrchr (path, '/')) == NULL) { /* no path in link */ strfcpy (newpath, link, _POSIX_PATH_MAX); return; @@ -532,34 +527,29 @@ dotlock_expand_link (char *newpath, const char *path, const char *link) * */ -static int -dotlock_deference_symlink (char *d, size_t l, const char *path) +static int dotlock_deference_symlink (char *d, size_t l, const char *path) { struct stat sb; char realpath[_POSIX_PATH_MAX]; const char *pathptr = path; int count = 0; - - while (count++ < MAXLINKS) - { - if (lstat (pathptr, &sb) == -1) - { + + while (count++ < MAXLINKS) { + if (lstat (pathptr, &sb) == -1) { /* perror (pathptr); */ return -1; } - - if (S_ISLNK (sb.st_mode)) - { + + if (S_ISLNK (sb.st_mode)) { char linkfile[_POSIX_PATH_MAX]; char linkpath[_POSIX_PATH_MAX]; int len; - if ((len = readlink (pathptr, linkfile, sizeof (linkfile))) == -1) - { - /* perror (pathptr); */ - return -1; + if ((len = readlink (pathptr, linkfile, sizeof (linkfile))) == -1) { + /* perror (pathptr); */ + return -1; } - + linkfile[len] = '\0'; dotlock_expand_link (linkpath, pathptr, linkfile); strfcpy (realpath, linkpath, sizeof (realpath)); @@ -584,8 +574,7 @@ dotlock_deference_symlink (char *d, size_t l, const char *path) #define HARDMAXATTEMPTS 10 -static int -dotlock_lock (const char *realpath) +static int dotlock_lock (const char *realpath) { char lockfile[_POSIX_PATH_MAX + LONG_STRING]; char nfslockfile[_POSIX_PATH_MAX + LONG_STRING]; @@ -595,45 +584,41 @@ dotlock_lock (const char *realpath) int hard_count = 0; struct stat sb; time_t t; - + snprintf (nfslockfile, sizeof (nfslockfile), "%s.%s.%d", - realpath, Hostname, (int) getpid ()); + realpath, Hostname, (int) getpid ()); snprintf (lockfile, sizeof (lockfile), "%s.lock", realpath); - + BEGIN_PRIVILEGED (); unlink (nfslockfile); - while ((fd = open (nfslockfile, O_WRONLY | O_EXCL | O_CREAT, 0)) < 0) - { + while ((fd = open (nfslockfile, O_WRONLY | O_EXCL | O_CREAT, 0)) < 0) { END_PRIVILEGED (); - - if (errno != EAGAIN) - { + + if (errno != EAGAIN) { /* perror ("cannot open NFS lock file"); */ return DL_EX_ERROR; } - + BEGIN_PRIVILEGED (); } END_PRIVILEGED (); - + close (fd); - - while (hard_count++ < HARDMAXATTEMPTS) - { + + while (hard_count++ < HARDMAXATTEMPTS) { BEGIN_PRIVILEGED (); link (nfslockfile, lockfile); END_PRIVILEGED (); - if (stat (nfslockfile, &sb) != 0) - { + if (stat (nfslockfile, &sb) != 0) { /* perror ("stat"); */ return DL_EX_ERROR; } @@ -644,32 +629,29 @@ dotlock_lock (const char *realpath) if (count == 0) prev_size = sb.st_size; - if (prev_size == sb.st_size && ++count > Retry) - { - if (DotlockFlags & DL_FL_FORCE) - { - BEGIN_PRIVILEGED (); - unlink (lockfile); - END_PRIVILEGED (); + if (prev_size == sb.st_size && ++count > Retry) { + if (DotlockFlags & DL_FL_FORCE) { + BEGIN_PRIVILEGED (); + unlink (lockfile); + END_PRIVILEGED (); - count = 0; - continue; + count = 0; + continue; } - else - { - BEGIN_PRIVILEGED (); - unlink (nfslockfile); - END_PRIVILEGED (); - return DL_EX_EXIST; + else { + BEGIN_PRIVILEGED (); + unlink (nfslockfile); + END_PRIVILEGED (); + return DL_EX_EXIST; } } - + prev_size = sb.st_size; - + /* don't trust sleep (3) as it may be interrupted * by users sending signals. */ - + t = time (NULL); do { sleep (1); @@ -691,29 +673,26 @@ dotlock_lock (const char *realpath) * */ -static int -dotlock_unlock (const char *realpath) +static int dotlock_unlock (const char *realpath) { char lockfile[_POSIX_PATH_MAX + LONG_STRING]; int i; - snprintf (lockfile, sizeof (lockfile), "%s.lock", - realpath); - + snprintf (lockfile, sizeof (lockfile), "%s.lock", realpath); + BEGIN_PRIVILEGED (); i = unlink (lockfile); END_PRIVILEGED (); - + if (i == -1) return DL_EX_ERROR; - + return DL_EX_OK; } /* remove an empty file */ -static int -dotlock_unlink (const char *realpath) +static int dotlock_unlink (const char *realpath) { struct stat lsb; int i = -1; @@ -726,7 +705,7 @@ dotlock_unlink (const char *realpath) dotlock_unlock (realpath); - return (i == 0) ? DL_EX_OK : DL_EX_ERROR; + return (i == 0) ? DL_EX_OK : DL_EX_ERROR; } @@ -737,8 +716,7 @@ dotlock_unlink (const char *realpath) * */ -static int -dotlock_try (void) +static int dotlock_try (void) { #ifdef USE_SETGID struct stat sb; @@ -748,8 +726,7 @@ dotlock_try (void) return DL_EX_OK; #ifdef USE_SETGID - if (stat (".", &sb) == 0) - { + if (stat (".", &sb) == 0) { if ((sb.st_mode & S_IWGRP) == S_IWGRP && sb.st_gid == MailGid) return DL_EX_NEED_PRIVS; } diff --git a/dotlock.h b/dotlock.h index dff6f61..4ce4dd7 100644 --- a/dotlock.h +++ b/dotlock.h @@ -15,16 +15,16 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #ifndef _DOTLOCK_H #define _DOTLOCK_H /* exit values */ -#define DL_EX_OK 0 -#define DL_EX_ERROR 1 -#define DL_EX_EXIST 3 +#define DL_EX_OK 0 +#define DL_EX_ERROR 1 +#define DL_EX_EXIST 3 #define DL_EX_NEED_PRIVS 4 #define DL_EX_IMPOSSIBLE 5 diff --git a/edit.c b/edit.c index 1674248..fd1eeb2 100644 --- a/edit.c +++ b/edit.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ /* Close approximation of the mailx(1) builtin editor for sending mail. */ @@ -38,7 +38,7 @@ * SLcurses_waddnstr() can't take a "const char *", so this is only * declared "static" (sigh) */ -static char* EditorHelp = N_("\ +static char *EditorHelp = N_("\ ~~ insert a line begining with a single ~\n\ ~b users add users to the Bcc: field\n\ ~c users add users to the Cc: field\n\ @@ -58,61 +58,58 @@ static char* EditorHelp = N_("\ ~? this message\n\ . on a line by itself ends input\n"); -static char ** -be_snarf_data (FILE *f, char **buf, int *bufmax, int *buflen, int offset, - int bytes, int prefix) +static char **be_snarf_data (FILE * f, char **buf, int *bufmax, int *buflen, + int offset, int bytes, int prefix) { char tmp[HUGE_STRING]; char *p = tmp; int tmplen = sizeof (tmp); tmp[sizeof (tmp) - 1] = 0; - if (prefix) - { - strfcpy (tmp, NONULL(Prefix), sizeof (tmp)); + if (prefix) { + strfcpy (tmp, NONULL (Prefix), sizeof (tmp)); tmplen = mutt_strlen (tmp); p = tmp + tmplen; tmplen = sizeof (tmp) - tmplen; } fseek (f, offset, 0); - while (bytes > 0) - { - if (fgets (p, tmplen - 1, f) == NULL) break; + while (bytes > 0) { + if (fgets (p, tmplen - 1, f) == NULL) + break; bytes -= mutt_strlen (p); if (*bufmax == *buflen) safe_realloc (&buf, sizeof (char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup (tmp); } - if (buf && *bufmax == *buflen) { /* Do not smash memory past buf */ + if (buf && *bufmax == *buflen) { /* Do not smash memory past buf */ safe_realloc (&buf, sizeof (char *) * (++*bufmax)); } - if (buf) buf[*buflen] = NULL; + if (buf) + buf[*buflen] = NULL; return (buf); } -static char ** -be_snarf_file (const char *path, char **buf, int *max, int *len, int verbose) +static char **be_snarf_file (const char *path, char **buf, int *max, int *len, + int verbose) { FILE *f; char tmp[LONG_STRING]; struct stat sb; - - if ((f = fopen (path, "r"))) - { + + if ((f = fopen (path, "r"))) { fstat (fileno (f), &sb); buf = be_snarf_data (f, buf, max, len, 0, sb.st_size, 0); - if (verbose) - { - snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) sb.st_size); - addstr(tmp); + if (verbose) { + snprintf (tmp, sizeof (tmp), "\"%s\" %lu bytes\n", path, + (unsigned long) sb.st_size); + addstr (tmp); } fclose (f); } - else - { - snprintf(tmp, sizeof(tmp), "%s: %s\n", path, strerror(errno)); - addstr(tmp); + else { + snprintf (tmp, sizeof (tmp), "%s: %s\n", path, strerror (errno)); + addstr (tmp); } return (buf); } @@ -121,15 +118,16 @@ static int be_barf_file (const char *path, char **buf, int buflen) { FILE *f; int i; - - if ((f = safe_fopen (path, "w")) == NULL) /* __FOPEN_CHECKED__ */ - { + + if ((f = safe_fopen (path, "w")) == NULL) { /* __FOPEN_CHECKED__ */ addstr (strerror (errno)); addch ('\n'); return (-1); } - for (i = 0; i < buflen; i++) fputs (buf[i], f); - if (fclose (f) == 0) return 0; + for (i = 0; i < buflen; i++) + fputs (buf[i], f); + if (fclose (f) == 0) + return 0; printw ("fclose: %s\n", strerror (errno)); return (-1); } @@ -142,44 +140,40 @@ static void be_free_memory (char **buf, int buflen) FREE (&buf); } -static char ** -be_include_messages (char *msg, char **buf, int *bufmax, int *buflen, - int pfx, int inc_hdrs) +static char **be_include_messages (char *msg, char **buf, int *bufmax, + int *buflen, int pfx, int inc_hdrs) { int offset, bytes, n; char tmp[LONG_STRING]; - while ((msg = strtok (msg, " ,")) != NULL) - { + while ((msg = strtok (msg, " ,")) != NULL) { n = atoi (msg); - if (n > 0 && n <= Context->msgcount) - { + if (n > 0 && n <= Context->msgcount) { n--; /* add the attribution */ - if (Attribution) - { - mutt_make_string (tmp, sizeof (tmp) - 1, Attribution, Context, Context->hdrs[n]); - strcat (tmp, "\n"); /* __STRCAT_CHECKED__ */ + if (Attribution) { + mutt_make_string (tmp, sizeof (tmp) - 1, Attribution, Context, + Context->hdrs[n]); + strcat (tmp, "\n"); /* __STRCAT_CHECKED__ */ } if (*bufmax == *buflen) - safe_realloc ( &buf, sizeof (char *) * (*bufmax += 25)); + safe_realloc (&buf, sizeof (char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup (tmp); bytes = Context->hdrs[n]->content->length; - if (inc_hdrs) - { - offset = Context->hdrs[n]->offset; - bytes += Context->hdrs[n]->content->offset - offset; + if (inc_hdrs) { + offset = Context->hdrs[n]->offset; + bytes += Context->hdrs[n]->content->offset - offset; } else - offset = Context->hdrs[n]->content->offset; + offset = Context->hdrs[n]->content->offset; buf = be_snarf_data (Context->fp, buf, bufmax, buflen, offset, bytes, - pfx); + pfx); if (*bufmax == *buflen) - safe_realloc (&buf, sizeof (char *) * (*bufmax += 25)); + safe_realloc (&buf, sizeof (char *) * (*bufmax += 25)); buf[(*buflen)++] = safe_strdup ("\n"); } else @@ -189,36 +183,32 @@ be_include_messages (char *msg, char **buf, int *bufmax, int *buflen, return (buf); } -static void be_print_header (ENVELOPE *env) +static void be_print_header (ENVELOPE * env) { char tmp[HUGE_STRING]; - if (env->to) - { + if (env->to) { addstr ("To: "); tmp[0] = 0; rfc822_write_address (tmp, sizeof (tmp), env->to, 1); addstr (tmp); addch ('\n'); } - if (env->cc) - { + if (env->cc) { addstr ("Cc: "); tmp[0] = 0; rfc822_write_address (tmp, sizeof (tmp), env->cc, 1); addstr (tmp); addch ('\n'); } - if (env->bcc) - { + if (env->bcc) { addstr ("Bcc: "); tmp[0] = 0; rfc822_write_address (tmp, sizeof (tmp), env->bcc, 1); addstr (tmp); addch ('\n'); } - if (env->subject) - { + if (env->subject) { addstr ("Subject: "); addstr (env->subject); addch ('\n'); @@ -229,53 +219,47 @@ static void be_print_header (ENVELOPE *env) /* args: * force override the $ask* vars (used for the ~h command) */ -static void be_edit_header (ENVELOPE *e, int force) +static void be_edit_header (ENVELOPE * e, int force) { char tmp[HUGE_STRING]; - move (LINES-1, 0); + move (LINES - 1, 0); addstr ("To: "); tmp[0] = 0; mutt_addrlist_to_local (e->to); rfc822_write_address (tmp, sizeof (tmp), e->to, 0); - if (!e->to || force) - { - if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 4, 0) == 0) - { + if (!e->to || force) { + if (mutt_enter_string (tmp, sizeof (tmp), LINES - 1, 4, 0) == 0) { rfc822_free_address (&e->to); e->to = mutt_parse_adrlist (e->to, tmp); e->to = mutt_expand_aliases (e->to); - mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */ + mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */ tmp[0] = 0; rfc822_write_address (tmp, sizeof (tmp), e->to, 1); mvaddstr (LINES - 1, 4, tmp); } } - else - { - mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */ + else { + mutt_addrlist_to_idna (e->to, NULL); /* XXX - IDNA error reporting? */ addstr (tmp); } addch ('\n'); - if (!e->subject || force) - { + if (!e->subject || force) { addstr ("Subject: "); - strfcpy (tmp, e->subject ? e->subject: "", sizeof (tmp)); - if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 9, 0) == 0) + strfcpy (tmp, e->subject ? e->subject : "", sizeof (tmp)); + if (mutt_enter_string (tmp, sizeof (tmp), LINES - 1, 9, 0) == 0) mutt_str_replace (&e->subject, tmp); addch ('\n'); } - if ((!e->cc && option (OPTASKCC)) || force) - { + if ((!e->cc && option (OPTASKCC)) || force) { addstr ("Cc: "); tmp[0] = 0; mutt_addrlist_to_local (e->cc); rfc822_write_address (tmp, sizeof (tmp), e->cc, 0); - if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 4, 0) == 0) - { + if (mutt_enter_string (tmp, sizeof (tmp), LINES - 1, 4, 0) == 0) { rfc822_free_address (&e->cc); e->cc = mutt_parse_adrlist (e->cc, tmp); e->cc = mutt_expand_aliases (e->cc); @@ -289,14 +273,12 @@ static void be_edit_header (ENVELOPE *e, int force) addch ('\n'); } - if (option (OPTASKBCC) || force) - { + if (option (OPTASKBCC) || force) { addstr ("Bcc: "); tmp[0] = 0; mutt_addrlist_to_local (e->bcc); rfc822_write_address (tmp, sizeof (tmp), e->bcc, 0); - if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 5, 0) == 0) - { + if (mutt_enter_string (tmp, sizeof (tmp), LINES - 1, 5, 0) == 0) { rfc822_free_address (&e->bcc); e->bcc = mutt_parse_adrlist (e->bcc, tmp); e->bcc = mutt_expand_aliases (e->bcc); @@ -311,7 +293,7 @@ static void be_edit_header (ENVELOPE *e, int force) } } -int mutt_builtin_editor (const char *path, HEADER *msg, HEADER *cur) +int mutt_builtin_editor (const char *path, HEADER * msg, HEADER * cur) { char **buf = NULL; int bufmax = 0, buflen = 0; @@ -320,7 +302,7 @@ int mutt_builtin_editor (const char *path, HEADER *msg, HEADER *cur) int done = 0; int i; char *p; - + scrollok (stdscr, TRUE); be_edit_header (msg->env, 0); @@ -330,153 +312,146 @@ int mutt_builtin_editor (const char *path, HEADER *msg, HEADER *cur) buf = be_snarf_file (path, buf, &bufmax, &buflen, 0); tmp[0] = 0; - while (!done) - { - if (mutt_enter_string (tmp, sizeof (tmp), LINES-1, 0, 0) == -1) - { + while (!done) { + if (mutt_enter_string (tmp, sizeof (tmp), LINES - 1, 0, 0) == -1) { tmp[0] = 0; continue; } addch ('\n'); - if (EscChar && tmp[0] == EscChar[0] && tmp[1] != EscChar[0]) - { + if (EscChar && tmp[0] == EscChar[0] && tmp[1] != EscChar[0]) { /* remove trailing whitespace from the line */ p = tmp + mutt_strlen (tmp) - 1; while (p >= tmp && ISSPACE (*p)) - *p-- = 0; + *p-- = 0; p = tmp + 2; SKIPWS (p); - switch (tmp[1]) - { - case '?': - addstr (_(EditorHelp)); - break; - case 'b': - msg->env->bcc = mutt_parse_adrlist (msg->env->bcc, p); - msg->env->bcc = mutt_expand_aliases (msg->env->bcc); - break; - case 'c': - msg->env->cc = mutt_parse_adrlist (msg->env->cc, p); - msg->env->cc = mutt_expand_aliases (msg->env->cc); - break; - case 'h': - be_edit_header (msg->env, 1); - break; - case 'F': - case 'f': - case 'm': - case 'M': - if (Context) - { - if (!*p && cur) - { - /* include the current message */ - p = tmp + mutt_strlen (tmp) + 1; - snprintf (tmp + mutt_strlen (tmp), sizeof (tmp) - mutt_strlen (tmp), " %d", - cur->msgno + 1); - } - buf = be_include_messages (p, buf, &bufmax, &buflen, - (ascii_tolower (tmp[1]) == 'm'), - (ascii_isupper ((unsigned char) tmp[1]))); - } - else - addstr (_("No mailbox.\n")); - break; - case 'p': - addstr ("-----\n"); - addstr (_("Message contains:\n")); - be_print_header (msg->env); - for (i = 0; i < buflen; i++) - addstr (buf[i]); - addstr (_("(continue)\n")); - break; - case 'q': - done = 1; - break; - case 'r': - if (*p) - { - strncpy(tmp, p, sizeof(tmp)); - mutt_expand_path(tmp, sizeof(tmp)); - buf = be_snarf_file (tmp, buf, &bufmax, &buflen, 1); + switch (tmp[1]) { + case '?': + addstr (_(EditorHelp)); + break; + case 'b': + msg->env->bcc = mutt_parse_adrlist (msg->env->bcc, p); + msg->env->bcc = mutt_expand_aliases (msg->env->bcc); + break; + case 'c': + msg->env->cc = mutt_parse_adrlist (msg->env->cc, p); + msg->env->cc = mutt_expand_aliases (msg->env->cc); + break; + case 'h': + be_edit_header (msg->env, 1); + break; + case 'F': + case 'f': + case 'm': + case 'M': + if (Context) { + if (!*p && cur) { + /* include the current message */ + p = tmp + mutt_strlen (tmp) + 1; + snprintf (tmp + mutt_strlen (tmp), + sizeof (tmp) - mutt_strlen (tmp), " %d", + cur->msgno + 1); + } + buf = be_include_messages (p, buf, &bufmax, &buflen, + (ascii_tolower (tmp[1]) == 'm'), + (ascii_isupper + ((unsigned char) tmp[1]))); + } + else + addstr (_("No mailbox.\n")); + break; + case 'p': + addstr ("-----\n"); + addstr (_("Message contains:\n")); + be_print_header (msg->env); + for (i = 0; i < buflen; i++) + addstr (buf[i]); + addstr (_("(continue)\n")); + break; + case 'q': + done = 1; + break; + case 'r': + if (*p) { + strncpy (tmp, p, sizeof (tmp)); + mutt_expand_path (tmp, sizeof (tmp)); + buf = be_snarf_file (tmp, buf, &bufmax, &buflen, 1); + } + else + addstr (_("missing filename.\n")); + break; + case 's': + mutt_str_replace (&msg->env->subject, p); + break; + case 't': + msg->env->to = rfc822_parse_adrlist (msg->env->to, p); + msg->env->to = mutt_expand_aliases (msg->env->to); + break; + case 'u': + if (buflen) { + buflen--; + strfcpy (tmp, buf[buflen], sizeof (tmp)); + tmp[mutt_strlen (tmp) - 1] = 0; + FREE (&buf[buflen]); + buf[buflen] = NULL; + continue; + } + else + addstr (_("No lines in message.\n")); + break; + + case 'e': + case 'v': + if (be_barf_file (path, buf, buflen) == 0) { + char *tag, *err; + + be_free_memory (buf, buflen); + buf = NULL; + bufmax = buflen = 0; + + if (option (OPTEDITHDRS)) { + mutt_env_to_local (msg->env); + mutt_edit_headers (NONULL (Visual), path, msg, NULL, 0); + if (mutt_env_to_idna (msg->env, &tag, &err)) + printw (_("Bad IDN in %s: '%s'\n"), tag, err); } - else - addstr (_("missing filename.\n")); - break; - case 's': - mutt_str_replace (&msg->env->subject, p); - break; - case 't': - msg->env->to = rfc822_parse_adrlist (msg->env->to, p); - msg->env->to = mutt_expand_aliases (msg->env->to); - break; - case 'u': - if (buflen) - { - buflen--; - strfcpy (tmp, buf[buflen], sizeof (tmp)); - tmp[mutt_strlen (tmp)-1] = 0; - FREE (&buf[buflen]); - buf[buflen] = NULL; - continue; - } - else - addstr (_("No lines in message.\n")); - break; - - case 'e': - case 'v': - if (be_barf_file (path, buf, buflen) == 0) - { - char *tag, *err; - be_free_memory (buf, buflen); - buf = NULL; - bufmax = buflen = 0; - - if (option (OPTEDITHDRS)) - { - mutt_env_to_local (msg->env); - mutt_edit_headers (NONULL(Visual), path, msg, NULL, 0); - if (mutt_env_to_idna (msg->env, &tag, &err)) - printw (_("Bad IDN in %s: '%s'\n"), tag, err); - } - else - mutt_edit_file (NONULL(Visual), path); - - buf = be_snarf_file (path, buf, &bufmax, &buflen, 0); - - addstr (_("(continue)\n")); - } - break; - case 'w': - be_barf_file (*p ? p : path, buf, buflen); - break; - case 'x': - abort = 1; - done = 1; - break; - default: - printw (_("%s: unknown editor command (~? for help)\n"), tmp); - break; + else + mutt_edit_file (NONULL (Visual), path); + + buf = be_snarf_file (path, buf, &bufmax, &buflen, 0); + + addstr (_("(continue)\n")); + } + break; + case 'w': + be_barf_file (*p ? p : path, buf, buflen); + break; + case 'x': + abort = 1; + done = 1; + break; + default: + printw (_("%s: unknown editor command (~? for help)\n"), tmp); + break; } } else if (mutt_strcmp (".", tmp) == 0) done = 1; - else - { + else { safe_strcat (tmp, sizeof (tmp), "\n"); if (buflen == bufmax) - safe_realloc (&buf, sizeof (char *) * (bufmax += 25)); + safe_realloc (&buf, sizeof (char *) * (bufmax += 25)); buf[buflen++] = safe_strdup (tmp[1] == '~' ? tmp + 1 : tmp); } - + tmp[0] = 0; } - if (!abort) be_barf_file (path, buf, buflen); + if (!abort) + be_barf_file (path, buf, buflen); be_free_memory (buf, buflen); return (abort ? -1 : 0); diff --git a/editmsg.c b/editmsg.c index 0d037d4..d0b080f 100644 --- a/editmsg.c +++ b/editmsg.c @@ -17,7 +17,7 @@ * License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111, USA. - */ + */ /* simple, editor-based message editing */ @@ -43,7 +43,7 @@ * -1 error */ -static int edit_one_message (CONTEXT *ctx, HEADER *cur) +static int edit_one_message (CONTEXT * ctx, HEADER * cur) { char tmp[_POSIX_PATH_MAX]; char buff[STRING]; @@ -55,7 +55,7 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) unsigned short o_old; int of, cf; - + CONTEXT tmpctx; MESSAGE *msg; @@ -63,7 +63,7 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) struct stat sb; time_t mtime = 0; - + mutt_mktemp (tmp); omagic = DefaultMagic; @@ -73,21 +73,21 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) DefaultMagic = omagic; - if (rc == -1) - { + if (rc == -1) { mutt_error (_("could not create temporary folder: %s"), strerror (errno)); return -1; } rc = mutt_append_message (&tmpctx, ctx, cur, 0, CH_NOLEN | - ((ctx->magic == M_MBOX || ctx->magic == M_MMDF) ? 0 : CH_NOSTATUS)); + ((ctx->magic == M_MBOX + || ctx->magic == M_MMDF) ? 0 : CH_NOSTATUS)); oerrno = errno; mx_close_mailbox (&tmpctx, NULL); - if (rc == -1) - { - mutt_error (_("could not write temporary mail folder: %s"), strerror (oerrno)); + if (rc == -1) { + mutt_error (_("could not write temporary mail folder: %s"), + strerror (oerrno)); goto bail; } @@ -102,44 +102,38 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) * remove it, the message will grow by one line each time the user edits * the message. */ - if (sb.st_size != 0 && truncate (tmp, sb.st_size - 1) == -1) - { + if (sb.st_size != 0 && truncate (tmp, sb.st_size - 1) == -1) { mutt_error (_("could not truncate temporary mail folder: %s"), - strerror (errno)); + strerror (errno)); goto bail; } - mutt_edit_file (NONULL(Editor), tmp); + mutt_edit_file (NONULL (Editor), tmp); - if ((rc = stat (tmp, &sb)) == -1) - { + if ((rc = stat (tmp, &sb)) == -1) { mutt_error (_("Can't stat %s: %s"), tmp, strerror (errno)); goto bail; } - - if (sb.st_size == 0) - { + + if (sb.st_size == 0) { mutt_message (_("Message file is empty!")); rc = 1; goto bail; } - if (sb.st_mtime == mtime) - { + if (sb.st_mtime == mtime) { mutt_message (_("Message not modified!")); rc = 1; goto bail; } - if ((fp = fopen (tmp, "r")) == NULL) - { + if ((fp = fopen (tmp, "r")) == NULL) { rc = -1; mutt_error (_("Can't open message file: %s"), strerror (errno)); goto bail; } - if (mx_open_mailbox (ctx->path, M_APPEND, &tmpctx) == NULL) - { + if (mx_open_mailbox (ctx->path, M_APPEND, &tmpctx) == NULL) { rc = -1; mutt_error (_("Can't append to folder: %s"), strerror (errno)); goto bail; @@ -147,9 +141,8 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) of = 0; cf = ((tmpctx.magic == M_MBOX || tmpctx.magic == M_MMDF) ? 0 : CH_NOSTATUS); - - if (fgets (buff, sizeof (buff), fp) && is_from (buff, NULL, 0, NULL)) - { + + if (fgets (buff, sizeof (buff), fp) && is_from (buff, NULL, 0, NULL)) { if (tmpctx.magic == M_MBOX || tmpctx.magic == M_MMDF) cf = CH_FROM | CH_FORCE_FROM; } @@ -162,37 +155,39 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) * */ - o_read = cur->read; o_old = cur->old; + o_read = cur->read; + o_old = cur->old; cur->read = cur->old = 0; msg = mx_open_new_message (&tmpctx, cur, of); - cur->read = o_read; cur->old = o_old; + cur->read = o_read; + cur->old = o_old; - if (msg == NULL) - { + if (msg == NULL) { mutt_error (_("Can't append to folder: %s"), strerror (errno)); mx_close_mailbox (&tmpctx, NULL); goto bail; } - if ((rc = mutt_copy_hdr (fp, msg->fp, 0, sb.st_size, CH_NOLEN | cf, NULL)) == 0) - { + if ((rc = + mutt_copy_hdr (fp, msg->fp, 0, sb.st_size, CH_NOLEN | cf, + NULL)) == 0) { fputc ('\n', msg->fp); rc = mutt_copy_stream (fp, msg->fp); } rc = mx_commit_message (msg, &tmpctx); mx_close_message (&msg); - + mx_close_mailbox (&tmpctx, NULL); - - bail: - if (fp) fclose (fp); + +bail: + if (fp) + fclose (fp); if (rc >= 0) unlink (tmp); - if (rc == 0) - { + if (rc == 0) { mutt_set_flag (Context, cur, M_DELETE, 1); mutt_set_flag (Context, cur, M_READ, 1); @@ -202,25 +197,23 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) else if (rc == -1) mutt_message (_("Error. Preserving temporary file: %s"), tmp); - + return rc; } -int mutt_edit_message (CONTEXT *ctx, HEADER *hdr) +int mutt_edit_message (CONTEXT * ctx, HEADER * hdr) { int i, j; if (hdr) return edit_one_message (ctx, hdr); - - for (i = 0; i < ctx->vcount; i++) - { + + for (i = 0; i < ctx->vcount; i++) { j = ctx->v2r[i]; - if (ctx->hdrs[j]->tagged) - { + if (ctx->hdrs[j]->tagged) { if (edit_one_message (ctx, ctx->hdrs[j]) == -1) - return -1; + return -1; } } diff --git a/enter.c b/enter.c index 6cf9d8d..f327001 100644 --- a/enter.c +++ b/enter.c @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -30,15 +30,15 @@ #include /* redraw flags for mutt_enter_string() */ -enum -{ - M_REDRAW_INIT = 1, /* go to end of line and redraw */ - M_REDRAW_LINE /* redraw entire line */ +enum { + M_REDRAW_INIT = 1, /* go to end of line and redraw */ + M_REDRAW_LINE /* redraw entire line */ }; static int my_wcwidth (wchar_t wc) { int n = wcwidth (wc); + if (IsWPrint (wc) && n > 0) return n; if (!(wc & ~0x7f)) @@ -51,9 +51,10 @@ static int my_wcwidth (wchar_t wc) /* combining mark / non-spacing character */ #define COMB_CHAR(wc) (IsWPrint (wc) && !wcwidth (wc)) -static int my_wcswidth (const wchar_t *s, size_t n) +static int my_wcswidth (const wchar_t * s, size_t n) { int w = 0; + while (n--) w += my_wcwidth (*s++); return w; @@ -62,26 +63,29 @@ static int my_wcswidth (const wchar_t *s, size_t n) static int my_addwch (wchar_t wc) { int n = wcwidth (wc); + if (IsWPrint (wc) && n > 0) return mutt_addwch (wc); if (!(wc & ~0x7f)) - return printw ("^%c", ((int)wc + 0x40) & 0x7f); + return printw ("^%c", ((int) wc + 0x40) & 0x7f); if (!(wc & ~0xffff)) - return printw ("\\u%04x", (int)wc); - return printw ("\\u%08x", (int)wc); + return printw ("\\u%04x", (int) wc); + return printw ("\\u%08x", (int) wc); } -static size_t width_ceiling (const wchar_t *s, size_t n, int w1) +static size_t width_ceiling (const wchar_t * s, size_t n, int w1) { const wchar_t *s0 = s; int w = 0; + for (; n; s++, n--) if ((w += my_wcwidth (*s)) > w1) break; - return s - s0; + return s - s0; } -static void my_wcstombs (char *dest, size_t dlen, const wchar_t *src, size_t slen) +static void my_wcstombs (char *dest, size_t dlen, const wchar_t * src, + size_t slen) { mbstate_t st; size_t k; @@ -89,7 +93,7 @@ static void my_wcstombs (char *dest, size_t dlen, const wchar_t *src, size_t sle /* First convert directly into the destination buffer */ memset (&st, 0, sizeof (st)); for (; slen && dlen >= MB_LEN_MAX; dest += k, dlen -= k, src++, slen--) - if ((k = wcrtomb (dest, *src, &st)) == (size_t)(-1)) + if ((k = wcrtomb (dest, *src, &st)) == (size_t) (-1)) break; /* If this works, we can stop now */ @@ -104,7 +108,7 @@ static void my_wcstombs (char *dest, size_t dlen, const wchar_t *src, size_t sle char *p = buf; for (; slen && p - buf < dlen; p += k, src++, slen--) - if ((k = wcrtomb (p, *src, &st)) == (size_t)(-1)) + if ((k = wcrtomb (p, *src, &st)) == (size_t) (-1)) break; p += wcrtomb (p, 0, &st); @@ -116,11 +120,11 @@ static void my_wcstombs (char *dest, size_t dlen, const wchar_t *src, size_t sle /* Otherwise we truncate the string in an ugly fashion */ memcpy (dest, buf, dlen); - dest[dlen - 1] = '\0'; /* assume original dlen > 0 */ + dest[dlen - 1] = '\0'; /* assume original dlen > 0 */ } } -size_t my_mbstowcs (wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) +size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, char *buf) { wchar_t wc; mbstate_t st; @@ -131,10 +135,8 @@ size_t my_mbstowcs (wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) wbuf = *pwbuf, wbuflen = *pwbuflen; memset (&st, 0, sizeof (st)); for (; (k = mbrtowc (&wc, buf, MB_LEN_MAX, &st)) && - k != (size_t)(-1) && k != (size_t)(-2); buf += k) - { - if (i >= wbuflen) - { + k != (size_t) (-1) && k != (size_t) (-2); buf += k) { + if (i >= wbuflen) { wbuflen = i + 20; safe_realloc (&wbuf, wbuflen * sizeof (*wbuf)); } @@ -148,19 +150,19 @@ size_t my_mbstowcs (wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) * Replace part of the wchar_t buffer, from FROM to CURPOS, by BUF. */ -static void replace_part (ENTER_STATE *state, size_t from, char *buf) +static void replace_part (ENTER_STATE * state, size_t from, char *buf) { /* Save the suffix */ size_t savelen = state->lastchar - state->curpos; wchar_t *savebuf = safe_calloc (savelen, sizeof (wchar_t)); + memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t)); /* Convert to wide characters */ state->curpos = my_mbstowcs (&state->wbuf, &state->wbuflen, from, buf); /* Make space for suffix */ - if (state->curpos + savelen > state->wbuflen) - { + if (state->curpos + savelen > state->wbuflen) { state->wbuflen = state->curpos + savelen; safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); } @@ -179,10 +181,11 @@ static void replace_part (ENTER_STATE *state, size_t from, char *buf) * -1 if abort. */ -int mutt_enter_string(char *buf, size_t buflen, int y, int x, int flags) +int mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags) { int rv; ENTER_STATE *es = mutt_new_enter_state (); + rv = _mutt_enter_string (buf, buflen, y, x, flags, 0, NULL, NULL, es); mutt_free_enter_state (&es); return rv; @@ -190,7 +193,7 @@ int mutt_enter_string(char *buf, size_t buflen, int y, int x, int flags) int _mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags, int multiple, char ***files, int *numfiles, - ENTER_STATE *state) + ENTER_STATE * state) { int width = COLS - x - 1; int redraw; @@ -205,15 +208,14 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, mbstate_t mbstate; int rv = 0; + memset (&mbstate, 0, sizeof (mbstate)); - - if (state->wbuf) - { + + if (state->wbuf) { /* Coming back after return 1 */ redraw = M_REDRAW_LINE; } - else - { + else { /* Initialise wbuf from buf */ state->wbuflen = 0; state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf); @@ -230,401 +232,381 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, hclass = HC_COMMAND; else if (flags & M_PATTERN) hclass = HC_PATTERN; - else + else hclass = HC_OTHER; - - for (;;) - { - if (redraw && !pass) - { - if (redraw == M_REDRAW_INIT) - { + + for (;;) { + if (redraw && !pass) { + if (redraw == M_REDRAW_INIT) { /* Go to end of line */ state->curpos = state->lastchar; - state->begin = width_ceiling (state->wbuf, state->lastchar, my_wcswidth (state->wbuf, state->lastchar) - width + 1); - } + state->begin = + width_ceiling (state->wbuf, state->lastchar, + my_wcswidth (state->wbuf, + state->lastchar) - width + 1); + } if (state->curpos < state->begin || - my_wcswidth (state->wbuf + state->begin, state->curpos - state->begin) >= width) - state->begin = width_ceiling (state->wbuf, state->lastchar, my_wcswidth (state->wbuf, state->curpos) - width / 2); + my_wcswidth (state->wbuf + state->begin, + state->curpos - state->begin) >= width) + state->begin = + width_ceiling (state->wbuf, state->lastchar, + my_wcswidth (state->wbuf, + state->curpos) - width / 2); move (y, x); w = 0; - for (i = state->begin; i < state->lastchar; i++) - { + for (i = state->begin; i < state->lastchar; i++) { w += my_wcwidth (state->wbuf[i]); if (w > width) break; my_addwch (state->wbuf[i]); } clrtoeol (); - move (y, x + my_wcswidth (state->wbuf + state->begin, state->curpos - state->begin)); + move (y, + x + my_wcswidth (state->wbuf + state->begin, + state->curpos - state->begin)); } mutt_refresh (); - if ((ch = km_dokey (MENU_EDITOR)) == -1) - { - rv = -1; + if ((ch = km_dokey (MENU_EDITOR)) == -1) { + rv = -1; goto bye; } - if (ch != OP_NULL) - { + if (ch != OP_NULL) { first = 0; if (ch != OP_EDITOR_COMPLETE) state->tabs = 0; redraw = M_REDRAW_LINE; - switch (ch) - { - case OP_EDITOR_HISTORY_UP: - state->curpos = state->lastchar; - replace_part (state, 0, mutt_history_prev (hclass)); - redraw = M_REDRAW_INIT; - break; + switch (ch) { + case OP_EDITOR_HISTORY_UP: + state->curpos = state->lastchar; + replace_part (state, 0, mutt_history_prev (hclass)); + redraw = M_REDRAW_INIT; + break; - case OP_EDITOR_HISTORY_DOWN: - state->curpos = state->lastchar; - replace_part (state, 0, mutt_history_next (hclass)); - redraw = M_REDRAW_INIT; - break; + case OP_EDITOR_HISTORY_DOWN: + state->curpos = state->lastchar; + replace_part (state, 0, mutt_history_next (hclass)); + redraw = M_REDRAW_INIT; + break; - case OP_EDITOR_BACKSPACE: - if (state->curpos == 0) - BEEP (); - else - { - i = state->curpos; - while (i && COMB_CHAR (state->wbuf[i - 1])) - --i; - if (i) - --i; - memmove (state->wbuf + i, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t)); - state->lastchar -= state->curpos - i; - state->curpos = i; - } - break; + case OP_EDITOR_BACKSPACE: + if (state->curpos == 0) + BEEP (); + else { + i = state->curpos; + while (i && COMB_CHAR (state->wbuf[i - 1])) + --i; + if (i) + --i; + memmove (state->wbuf + i, state->wbuf + state->curpos, + (state->lastchar - state->curpos) * sizeof (wchar_t)); + state->lastchar -= state->curpos - i; + state->curpos = i; + } + break; - case OP_EDITOR_BOL: - state->curpos = 0; - break; + case OP_EDITOR_BOL: + state->curpos = 0; + break; - case OP_EDITOR_EOL: - redraw= M_REDRAW_INIT; - break; + case OP_EDITOR_EOL: + redraw = M_REDRAW_INIT; + break; - case OP_EDITOR_KILL_LINE: - state->curpos = state->lastchar = 0; - break; + case OP_EDITOR_KILL_LINE: + state->curpos = state->lastchar = 0; + break; - case OP_EDITOR_KILL_EOL: - state->lastchar = state->curpos; - break; + case OP_EDITOR_KILL_EOL: + state->lastchar = state->curpos; + break; - case OP_EDITOR_BACKWARD_CHAR: - if (state->curpos == 0) - BEEP (); - else - { - while (state->curpos && COMB_CHAR (state->wbuf[state->curpos - 1])) - state->curpos--; - if (state->curpos) - state->curpos--; - } - break; + case OP_EDITOR_BACKWARD_CHAR: + if (state->curpos == 0) + BEEP (); + else { + while (state->curpos && COMB_CHAR (state->wbuf[state->curpos - 1])) + state->curpos--; + if (state->curpos) + state->curpos--; + } + break; - case OP_EDITOR_FORWARD_CHAR: - if (state->curpos == state->lastchar) - BEEP (); - else - { + case OP_EDITOR_FORWARD_CHAR: + if (state->curpos == state->lastchar) + BEEP (); + else { + ++state->curpos; + while (state->curpos < state->lastchar + && COMB_CHAR (state->wbuf[state->curpos])) ++state->curpos; - while (state->curpos < state->lastchar && COMB_CHAR (state->wbuf[state->curpos])) - ++state->curpos; - } - break; - - case OP_EDITOR_BACKWARD_WORD: - if (state->curpos == 0) - BEEP (); - else - { - while (state->curpos && iswspace (state->wbuf[state->curpos - 1])) - --state->curpos; - while (state->curpos && !iswspace (state->wbuf[state->curpos - 1])) - --state->curpos; - } - break; - - case OP_EDITOR_FORWARD_WORD: - if (state->curpos == state->lastchar) - BEEP (); - else - { - while (state->curpos < state->lastchar && iswspace (state->wbuf[state->curpos])) - ++state->curpos; - while (state->curpos < state->lastchar && !iswspace (state->wbuf[state->curpos])) - ++state->curpos; - } - break; + } + break; - case OP_EDITOR_CAPITALIZE_WORD: - case OP_EDITOR_UPCASE_WORD: - case OP_EDITOR_DOWNCASE_WORD: - if (state->curpos == state->lastchar) - { - BEEP (); - break; - } - while (state->curpos && !iswspace (state->wbuf[state->curpos])) + case OP_EDITOR_BACKWARD_WORD: + if (state->curpos == 0) + BEEP (); + else { + while (state->curpos && iswspace (state->wbuf[state->curpos - 1])) + --state->curpos; + while (state->curpos && !iswspace (state->wbuf[state->curpos - 1])) --state->curpos; - while (state->curpos < state->lastchar && iswspace (state->wbuf[state->curpos])) + } + break; + + case OP_EDITOR_FORWARD_WORD: + if (state->curpos == state->lastchar) + BEEP (); + else { + while (state->curpos < state->lastchar + && iswspace (state->wbuf[state->curpos])) ++state->curpos; - while (state->curpos < state->lastchar && !iswspace (state->wbuf[state->curpos])) - { - if (ch == OP_EDITOR_DOWNCASE_WORD) - state->wbuf[state->curpos] = towlower (state->wbuf[state->curpos]); - else - { - state->wbuf[state->curpos] = towupper (state->wbuf[state->curpos]); - if (ch == OP_EDITOR_CAPITALIZE_WORD) - ch = OP_EDITOR_DOWNCASE_WORD; - } - state->curpos++; - } - break; + while (state->curpos < state->lastchar + && !iswspace (state->wbuf[state->curpos])) + ++state->curpos; + } + break; - case OP_EDITOR_DELETE_CHAR: - if (state->curpos == state->lastchar) - BEEP (); - else - { - i = state->curpos; - while (i < state->lastchar && COMB_CHAR (state->wbuf[i])) - ++i; - if (i < state->lastchar) - ++i; - while (i < state->lastchar && COMB_CHAR (state->wbuf[i])) - ++i; - memmove (state->wbuf + state->curpos, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t)); - state->lastchar -= i - state->curpos; - } + case OP_EDITOR_CAPITALIZE_WORD: + case OP_EDITOR_UPCASE_WORD: + case OP_EDITOR_DOWNCASE_WORD: + if (state->curpos == state->lastchar) { + BEEP (); break; - - case OP_EDITOR_KILL_WORD: - /* delete to begining of word */ - if (state->curpos != 0) - { - i = state->curpos; - while (i && iswspace (state->wbuf[i - 1])) - --i; - if (i) - { - if (iswalnum (state->wbuf[i - 1])) - { - for (--i; i && iswalnum (state->wbuf[i - 1]); i--) - ; - } - else - --i; - } - memmove (state->wbuf + i, state->wbuf + state->curpos, - (state->lastchar - state->curpos) * sizeof (wchar_t)); - state->lastchar += i - state->curpos; - state->curpos = i; + } + while (state->curpos && !iswspace (state->wbuf[state->curpos])) + --state->curpos; + while (state->curpos < state->lastchar + && iswspace (state->wbuf[state->curpos])) + ++state->curpos; + while (state->curpos < state->lastchar + && !iswspace (state->wbuf[state->curpos])) { + if (ch == OP_EDITOR_DOWNCASE_WORD) + state->wbuf[state->curpos] = + towlower (state->wbuf[state->curpos]); + else { + state->wbuf[state->curpos] = + towupper (state->wbuf[state->curpos]); + if (ch == OP_EDITOR_CAPITALIZE_WORD) + ch = OP_EDITOR_DOWNCASE_WORD; } - break; + state->curpos++; + } + break; - case OP_EDITOR_KILL_EOW: - /* delete to end of word */ - for (i = state->curpos; - i < state->lastchar && iswspace (state->wbuf[i]); i++) - ; - for (; i < state->lastchar && !iswspace (state->wbuf[i]); i++) - ; + case OP_EDITOR_DELETE_CHAR: + if (state->curpos == state->lastchar) + BEEP (); + else { + i = state->curpos; + while (i < state->lastchar && COMB_CHAR (state->wbuf[i])) + ++i; + if (i < state->lastchar) + ++i; + while (i < state->lastchar && COMB_CHAR (state->wbuf[i])) + ++i; memmove (state->wbuf + state->curpos, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t)); - state->lastchar += state->curpos - i; - break; + state->lastchar -= i - state->curpos; + } + break; - case OP_EDITOR_BUFFY_CYCLE: - if (flags & M_EFILE) - { - first = 1; /* clear input if user types a real key later */ - my_wcstombs (buf, buflen, state->wbuf, state->curpos); - mutt_buffy (buf, buflen); - state->curpos = state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf); - break; - } - else if (!(flags & M_FILE)) - goto self_insert; - /* fall through to completion routine (M_FILE) */ - - case OP_EDITOR_COMPLETE: - state->tabs++; - if (flags & M_CMD) - { - for (i = state->curpos; i && state->wbuf[i-1] != ' '; i--) - ; - my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); - if (tempbuf && templen == state->lastchar - i && - !memcmp (tempbuf, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t))) - { - mutt_select_file (buf, buflen, (flags & M_EFILE) ? M_SEL_FOLDER : 0); - set_option (OPTNEEDREDRAW); - if (*buf) - replace_part (state, i, buf); - rv = 1; - goto bye; - } - if (!mutt_complete (buf, buflen)) - { - templen = state->lastchar - i; - safe_realloc (&tempbuf, templen * sizeof (wchar_t)); + case OP_EDITOR_KILL_WORD: + /* delete to begining of word */ + if (state->curpos != 0) { + i = state->curpos; + while (i && iswspace (state->wbuf[i - 1])) + --i; + if (i) { + if (iswalnum (state->wbuf[i - 1])) { + for (--i; i && iswalnum (state->wbuf[i - 1]); i--); } else - BEEP (); - - replace_part (state, i, buf); + --i; } - else if (flags & M_ALIAS) - { - /* invoke the alias-menu to get more addresses */ - for (i = state->curpos; i && state->wbuf[i-1] != ',' && - state->wbuf[i-1] != ':'; i--) - ; - for (; i < state->lastchar && state->wbuf[i] == ' '; i++) - ; - my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); - r = mutt_alias_complete (buf, buflen); - replace_part (state, i, buf); - if (!r) - { - rv = 1; - goto bye; - } - break; + memmove (state->wbuf + i, state->wbuf + state->curpos, + (state->lastchar - state->curpos) * sizeof (wchar_t)); + state->lastchar += i - state->curpos; + state->curpos = i; + } + break; + + case OP_EDITOR_KILL_EOW: + /* delete to end of word */ + for (i = state->curpos; + i < state->lastchar && iswspace (state->wbuf[i]); i++); + for (; i < state->lastchar && !iswspace (state->wbuf[i]); i++); + memmove (state->wbuf + state->curpos, state->wbuf + i, + (state->lastchar - i) * sizeof (wchar_t)); + state->lastchar += state->curpos - i; + break; + + case OP_EDITOR_BUFFY_CYCLE: + if (flags & M_EFILE) { + first = 1; /* clear input if user types a real key later */ + my_wcstombs (buf, buflen, state->wbuf, state->curpos); + mutt_buffy (buf, buflen); + state->curpos = state->lastchar = + my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf); + break; + } + else if (!(flags & M_FILE)) + goto self_insert; + /* fall through to completion routine (M_FILE) */ + + case OP_EDITOR_COMPLETE: + state->tabs++; + if (flags & M_CMD) { + for (i = state->curpos; i && state->wbuf[i - 1] != ' '; i--); + my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); + if (tempbuf && templen == state->lastchar - i && + !memcmp (tempbuf, state->wbuf + i, + (state->lastchar - i) * sizeof (wchar_t))) { + mutt_select_file (buf, buflen, + (flags & M_EFILE) ? M_SEL_FOLDER : 0); + set_option (OPTNEEDREDRAW); + if (*buf) + replace_part (state, i, buf); + rv = 1; + goto bye; } - else if (flags & M_COMMAND) - { - my_wcstombs (buf, buflen, state->wbuf, state->curpos); - i = strlen (buf); - if (i && buf[i - 1] == '=' && - mutt_var_value_complete (buf, buflen, i)) - state->tabs = 0; - else if (!mutt_command_complete (buf, buflen, i, state->tabs)) - BEEP (); - replace_part (state, 0, buf); + if (!mutt_complete (buf, buflen)) { + templen = state->lastchar - i; + safe_realloc (&tempbuf, templen * sizeof (wchar_t)); } - else if (flags & (M_FILE | M_EFILE)) - { - my_wcstombs (buf, buflen, state->wbuf, state->curpos); - - /* see if the path has changed from the last time */ - if ((!tempbuf && !state->lastchar) || (tempbuf && templen == state->lastchar && - !memcmp (tempbuf, state->wbuf, state->lastchar * sizeof (wchar_t)))) - { - _mutt_select_file (buf, buflen, - ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | (multiple ? M_SEL_MULTI : 0), - files, numfiles); - set_option (OPTNEEDREDRAW); - if (*buf) - { - mutt_pretty_mailbox (buf); - if (!pass) - mutt_history_add (hclass, buf); - rv = 0; - goto bye; - } - - /* file selection cancelled */ - rv = 1; - goto bye; - } + else + BEEP (); - if (!mutt_complete (buf, buflen)) - { - templen = state->lastchar; - safe_realloc (&tempbuf, templen * sizeof (wchar_t)); - memcpy (tempbuf, state->wbuf, templen * sizeof (wchar_t)); - } - else - BEEP (); /* let the user know that nothing matched */ - replace_part (state, 0, buf); + replace_part (state, i, buf); + } + else if (flags & M_ALIAS) { + /* invoke the alias-menu to get more addresses */ + for (i = state->curpos; i && state->wbuf[i - 1] != ',' && + state->wbuf[i - 1] != ':'; i--); + for (; i < state->lastchar && state->wbuf[i] == ' '; i++); + my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); + r = mutt_alias_complete (buf, buflen); + replace_part (state, i, buf); + if (!r) { + rv = 1; + goto bye; } - else - goto self_insert; break; - - case OP_EDITOR_COMPLETE_QUERY: - if (flags & M_ALIAS) - { - /* invoke the query-menu to get more addresses */ - if ((i = state->curpos)) - { - for (; i && state->wbuf[i - 1] != ','; i--) - ; - for (; i < state->curpos && state->wbuf[i] == ' '; i++) - ; + } + else if (flags & M_COMMAND) { + my_wcstombs (buf, buflen, state->wbuf, state->curpos); + i = strlen (buf); + if (i && buf[i - 1] == '=' && + mutt_var_value_complete (buf, buflen, i)) + state->tabs = 0; + else if (!mutt_command_complete (buf, buflen, i, state->tabs)) + BEEP (); + replace_part (state, 0, buf); + } + else if (flags & (M_FILE | M_EFILE)) { + my_wcstombs (buf, buflen, state->wbuf, state->curpos); + + /* see if the path has changed from the last time */ + if ((!tempbuf && !state->lastchar) + || (tempbuf && templen == state->lastchar + && !memcmp (tempbuf, state->wbuf, + state->lastchar * sizeof (wchar_t)))) { + _mutt_select_file (buf, buflen, + ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | + (multiple ? M_SEL_MULTI : 0), files, numfiles); + set_option (OPTNEEDREDRAW); + if (*buf) { + mutt_pretty_mailbox (buf); + if (!pass) + mutt_history_add (hclass, buf); + rv = 0; + goto bye; } - my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); - mutt_query_complete (buf, buflen); - replace_part (state, i, buf); - - rv = 1; + /* file selection cancelled */ + rv = 1; goto bye; } + + if (!mutt_complete (buf, buflen)) { + templen = state->lastchar; + safe_realloc (&tempbuf, templen * sizeof (wchar_t)); + memcpy (tempbuf, state->wbuf, templen * sizeof (wchar_t)); + } else - goto self_insert; + BEEP (); /* let the user know that nothing matched */ + replace_part (state, 0, buf); + } + else + goto self_insert; + break; - case OP_EDITOR_QUOTE_CHAR: - { - event_t event; - /*ADDCH (LastKey);*/ - event = mutt_getch (); - if (event.ch != -1) - { - LastKey = event.ch; - goto self_insert; - } + case OP_EDITOR_COMPLETE_QUERY: + if (flags & M_ALIAS) { + /* invoke the query-menu to get more addresses */ + if ((i = state->curpos)) { + for (; i && state->wbuf[i - 1] != ','; i--); + for (; i < state->curpos && state->wbuf[i] == ' '; i++); } - case OP_EDITOR_TRANSPOSE_CHARS: - if (state->lastchar < 2) - BEEP (); - else - { - wchar_t t; + my_wcstombs (buf, buflen, state->wbuf + i, state->curpos - i); + mutt_query_complete (buf, buflen); + replace_part (state, i, buf); - if (state->curpos == 0) - state->curpos = 2; - else if (state->curpos < state->lastchar) - ++state->curpos; + rv = 1; + goto bye; + } + else + goto self_insert; + + case OP_EDITOR_QUOTE_CHAR: + { + event_t event; - t = state->wbuf[state->curpos - 2]; - state->wbuf[state->curpos - 2] = state->wbuf[state->curpos - 1]; - state->wbuf[state->curpos - 1] = t; + /*ADDCH (LastKey); */ + event = mutt_getch (); + if (event.ch != -1) { + LastKey = event.ch; + goto self_insert; } - break; + } - default: + case OP_EDITOR_TRANSPOSE_CHARS: + if (state->lastchar < 2) BEEP (); + else { + wchar_t t; + + if (state->curpos == 0) + state->curpos = 2; + else if (state->curpos < state->lastchar) + ++state->curpos; + + t = state->wbuf[state->curpos - 2]; + state->wbuf[state->curpos - 2] = state->wbuf[state->curpos - 1]; + state->wbuf[state->curpos - 1] = t; + } + break; + + default: + BEEP (); } } - else - { - -self_insert: + else { + + self_insert: state->tabs = 0; /* use the raw keypress */ ch = LastKey; - if ((ch == '#') && (flags & M_LASTFOLDER)) - { + if ((ch == '#') && (flags & M_LASTFOLDER)) { rv = 2; my_wcstombs (buf, buflen, state->wbuf, state->lastchar); goto bye; } - + #ifdef KEY_ENTER /* treat ENTER the same as RETURN */ if (ch == KEY_ENTER) @@ -642,70 +624,66 @@ self_insert: c = ch; k = mbrtowc (&wc, &c, 1, &mbstate); - if (k == (size_t)(-2)) + if (k == (size_t) (-2)) continue; - else if (k && k != 1) - { + else if (k && k != 1) { memset (&mbstate, 0, sizeof (mbstate)); continue; } } - if (first && (flags & M_CLEAR)) - { + if (first && (flags & M_CLEAR)) { first = 0; - if (IsWPrint (wc)) /* why? */ + if (IsWPrint (wc)) /* why? */ state->curpos = state->lastchar = 0; } - if (wc == '\r' || wc == '\n') - { + if (wc == '\r' || wc == '\n') { /* Convert from wide characters */ my_wcstombs (buf, buflen, state->wbuf, state->lastchar); if (!pass) mutt_history_add (hclass, buf); - if (multiple) - { + if (multiple) { char **tfiles; + *numfiles = 1; tfiles = safe_calloc (*numfiles, sizeof (char *)); mutt_expand_path (buf, buflen); tfiles[0] = safe_strdup (buf); *files = tfiles; } - rv = 0; + rv = 0; goto bye; } - else if (wc && (wc < ' ' || IsWPrint (wc))) /* why? */ - { - if (state->lastchar >= state->wbuflen) - { + else if (wc && (wc < ' ' || IsWPrint (wc))) { /* why? */ + if (state->lastchar >= state->wbuflen) { state->wbuflen = state->lastchar + 20; safe_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); } - memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t)); + memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, + (state->lastchar - state->curpos) * sizeof (wchar_t)); state->wbuf[state->curpos++] = wc; state->lastchar++; } - else - { + else { mutt_flushinp (); BEEP (); } } } - - bye: - + +bye: + FREE (&tempbuf); return rv; } -void mutt_free_enter_state (ENTER_STATE **esp) +void mutt_free_enter_state (ENTER_STATE ** esp) { - if (!esp) return; - + if (!esp) + return; + FREE (&(*esp)->wbuf); FREE (esp); } diff --git a/extlib.c b/extlib.c index 2dda7fd..5933042 100644 --- a/extlib.c +++ b/extlib.c @@ -17,7 +17,7 @@ * License along with this program; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111, USA. - */ + */ /* * Some simple dummies, so we can reuse the routines from @@ -40,4 +40,3 @@ void mutt_exit (int code) { exit (code); } - diff --git a/filter.c b/filter.c index 862ebbd..7391a99 100644 --- a/filter.c +++ b/filter.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -30,46 +30,38 @@ * to the specified handles. */ pid_t -mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, - int fdin, int fdout, int fderr) +mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, + int fdin, int fdout, int fderr) { int pin[2], pout[2], perr[2], thepid; - if (in) - { + if (in) { *in = 0; if (pipe (pin) == -1) return (-1); } - if (out) - { + if (out) { *out = 0; - if (pipe (pout) == -1) - { - if (in) - { - close (pin[0]); - close (pin[1]); + if (pipe (pout) == -1) { + if (in) { + close (pin[0]); + close (pin[1]); } return (-1); } } - if (err) - { + if (err) { *err = 0; - if (pipe (perr) == -1) - { - if (in) - { - close (pin[0]); - close (pin[1]); + if (pipe (perr) == -1) { + if (in) { + close (pin[0]); + close (pin[1]); } - if (out) - { - close (pout[0]); - close (pout[1]); + if (out) { + close (pout[0]); + close (pout[1]); } return (-1); } @@ -77,42 +69,35 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, mutt_block_signals_system (); - if ((thepid = fork ()) == 0) - { + if ((thepid = fork ()) == 0) { mutt_unblock_signals_system (0); - if (in) - { + if (in) { close (pin[1]); dup2 (pin[0], 0); close (pin[0]); } - else if (fdin != -1) - { + else if (fdin != -1) { dup2 (fdin, 0); close (fdin); } - if (out) - { + if (out) { close (pout[0]); dup2 (pout[1], 1); close (pout[1]); } - else if (fdout != -1) - { + else if (fdout != -1) { dup2 (fdout, 1); close (fdout); } - if (err) - { + if (err) { close (perr[0]); dup2 (perr[1], 2); close (perr[1]); } - else if (fderr != -1) - { + else if (fderr != -1) { dup2 (fderr, 2); close (fderr); } @@ -120,24 +105,20 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, execl (EXECSHELL, "sh", "-c", cmd, NULL); _exit (127); } - else if (thepid == -1) - { + else if (thepid == -1) { mutt_unblock_signals_system (1); - if (in) - { + if (in) { close (pin[0]); close (pin[1]); } - - if (out) - { + + if (out) { close (pout[0]); close (pout[1]); } - if (err) - { + if (err) { close (perr[0]); close (perr[1]); } @@ -145,20 +126,17 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, return (-1); } - if (out) - { + if (out) { close (pout[1]); *out = fdopen (pout[0], "r"); } - if (in) - { + if (in) { close (pin[0]); *in = fdopen (pin[1], "w"); } - if (err) - { + if (err) { close (perr[1]); *err = fdopen (perr[0], "r"); } @@ -166,7 +144,7 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, return (thepid); } -pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err) +pid_t mutt_create_filter (const char *s, FILE ** in, FILE ** out, FILE ** err) { return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1)); } @@ -174,10 +152,10 @@ pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err) int mutt_wait_filter (pid_t pid) { int rc; - + waitpid (pid, &rc, 0); mutt_unblock_signals_system (1); rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1; - + return rc; } diff --git a/flags.c b/flags.c index 8cc3c42..8e1bbdb 100644 --- a/flags.c +++ b/flags.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -31,279 +31,287 @@ #include "imap_private.h" #endif -void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) +void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx) { int changed = h->changed; int deleted = ctx->deleted; int tagged = ctx->tagged; if (ctx->readonly && flag != M_TAG) - return; /* don't modify anything if we are read-only */ + return; /* don't modify anything if we are read-only */ - switch (flag) - { - case M_DELETE: + switch (flag) { + case M_DELETE: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_DELETE)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_DELETE)) + return; #endif - if (bf) - { - if (!h->deleted && !ctx->readonly) - { - h->deleted = 1; - if (upd_ctx) ctx->deleted++; + if (bf) { + if (!h->deleted && !ctx->readonly) { + h->deleted = 1; + if (upd_ctx) + ctx->deleted++; #ifdef USE_IMAP - /* deleted messages aren't treated as changed elsewhere so that the - * purge-on-sync option works correctly. This isn't applicable here */ - if (ctx && ctx->magic == M_IMAP) - { - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } + /* deleted messages aren't treated as changed elsewhere so that the + * purge-on-sync option works correctly. This isn't applicable here */ + if (ctx && ctx->magic == M_IMAP) { + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } #endif - } } - else if (h->deleted) - { - h->deleted = 0; - if (upd_ctx) - { - ctx->deleted--; - if (h->appended) - ctx->appended--; - } - h->appended = 0; /* when undeleting, also reset the appended flag */ + } + else if (h->deleted) { + h->deleted = 0; + if (upd_ctx) { + ctx->deleted--; + if (h->appended) + ctx->appended--; + } + h->appended = 0; /* when undeleting, also reset the appended flag */ #ifdef USE_IMAP - /* see my comment above */ - if (ctx->magic == M_IMAP) - { - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } -#endif - /* - * If the user undeletes a message which is marked as - * "trash" in the maildir folder on disk, the folder has - * been changed, and is marked accordingly. However, we do - * _not_ mark the message itself changed, because trashing - * is checked in specific code in the maildir folder - * driver. - */ - if (ctx->magic == M_MAILDIR && upd_ctx && h->trash) - ctx->changed = 1; + /* see my comment above */ + if (ctx->magic == M_IMAP) { + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - break; - - case M_APPENDED: - if (bf) - { - if (!h->appended) - { - h->appended = 1; - if (upd_ctx) ctx->appended++; - } +#endif + /* + * If the user undeletes a message which is marked as + * "trash" in the maildir folder on disk, the folder has + * been changed, and is marked accordingly. However, we do + * _not_ mark the message itself changed, because trashing + * is checked in specific code in the maildir folder + * driver. + */ + if (ctx->magic == M_MAILDIR && upd_ctx && h->trash) + ctx->changed = 1; + } + break; + + case M_APPENDED: + if (bf) { + if (!h->appended) { + h->appended = 1; + if (upd_ctx) + ctx->appended++; } - break; + } + break; - case M_PURGED: - if (bf) - { - if (!h->purged) - h->purged = 1; - } - else if (h->purged) - h->purged = 0; - break; + case M_PURGED: + if (bf) { + if (!h->purged) + h->purged = 1; + } + else if (h->purged) + h->purged = 0; + break; - case M_NEW: + case M_NEW: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_SEEN)) + return; #endif - if (bf) - { - if (h->read || h->old) - { - h->old = 0; - if (upd_ctx) ctx->new++; - if (h->read) - { - h->read = 0; - if (upd_ctx) ctx->unread++; - } - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } + if (bf) { + if (h->read || h->old) { + h->old = 0; + if (upd_ctx) + ctx->new++; + if (h->read) { + h->read = 0; + if (upd_ctx) + ctx->unread++; + } + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - else if (!h->read) - { - if (!h->old) - if (upd_ctx) ctx->new--; - h->read = 1; - if (upd_ctx) ctx->unread--; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } - break; + } + else if (!h->read) { + if (!h->old) + if (upd_ctx) + ctx->new--; + h->read = 1; + if (upd_ctx) + ctx->unread--; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } + break; - case M_OLD: + case M_OLD: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_SEEN)) + return; #endif - if (bf) - { - if (!h->old) - { - h->old = 1; - if (!h->read) - if (upd_ctx) ctx->new--; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } - } - else if (h->old) - { - h->old = 0; - if (!h->read) - if (upd_ctx) ctx->new++; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; + if (bf) { + if (!h->old) { + h->old = 1; + if (!h->read) + if (upd_ctx) + ctx->new--; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - break; + } + else if (h->old) { + h->old = 0; + if (!h->read) + if (upd_ctx) + ctx->new++; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } + break; - case M_READ: + case M_READ: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_SEEN)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_SEEN)) + return; #endif - if (bf) - { - if (!h->read) - { - h->read = 1; - if (upd_ctx) ctx->unread--; - if (!h->old) - if (upd_ctx) ctx->new--; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } - } - else if (h->read) - { - h->read = 0; - if (upd_ctx) ctx->unread++; - if (!h->old) - if (upd_ctx) ctx->new++; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; + if (bf) { + if (!h->read) { + h->read = 1; + if (upd_ctx) + ctx->unread--; + if (!h->old) + if (upd_ctx) + ctx->new--; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - break; + } + else if (h->read) { + h->read = 0; + if (upd_ctx) + ctx->unread++; + if (!h->old) + if (upd_ctx) + ctx->new++; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } + break; - case M_REPLIED: + case M_REPLIED: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_WRITE)) + return; #endif - if (bf) - { - if (!h->replied) - { - h->replied = 1; - if (!h->read) - { - h->read = 1; - if (upd_ctx) ctx->unread--; - if (!h->old) - if (upd_ctx) ctx->new--; - } - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } + if (bf) { + if (!h->replied) { + h->replied = 1; + if (!h->read) { + h->read = 1; + if (upd_ctx) + ctx->unread--; + if (!h->old) + if (upd_ctx) + ctx->new--; + } + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - else if (h->replied) - { - h->replied = 0; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } - break; + } + else if (h->replied) { + h->replied = 0; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } + break; - case M_FLAG: + case M_FLAG: #ifdef USE_IMAP - if (ctx && ctx->magic == M_IMAP) - if (mutt_bit_isset (((IMAP_DATA *)ctx->data)->capabilities, ACL) \ - && !mutt_bit_isset(((IMAP_DATA *)ctx->data)->rights,IMAP_ACL_WRITE)) - return; + if (ctx && ctx->magic == M_IMAP) + if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL) + && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights, + IMAP_ACL_WRITE)) + return; #endif - if (bf) - { - if (!h->flagged) - { - h->flagged = bf; - if (upd_ctx) ctx->flagged++; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; - } - } - else if (h->flagged) - { - h->flagged = 0; - if (upd_ctx) ctx->flagged--; - h->changed = 1; - if (upd_ctx) ctx->changed = 1; + if (bf) { + if (!h->flagged) { + h->flagged = bf; + if (upd_ctx) + ctx->flagged++; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; } - break; - - case M_TAG: - if (bf) - { - if (!h->tagged) - { - h->tagged = 1; - if (upd_ctx) ctx->tagged++; - } - } - else if (h->tagged) - { - h->tagged = 0; - if (upd_ctx) ctx->tagged--; + } + else if (h->flagged) { + h->flagged = 0; + if (upd_ctx) + ctx->flagged--; + h->changed = 1; + if (upd_ctx) + ctx->changed = 1; + } + break; + + case M_TAG: + if (bf) { + if (!h->tagged) { + h->tagged = 1; + if (upd_ctx) + ctx->tagged++; } - break; + } + else if (h->tagged) { + h->tagged = 0; + if (upd_ctx) + ctx->tagged--; + } + break; } - mutt_set_header_color(ctx, h); + mutt_set_header_color (ctx, h); /* if the message status has changed, we need to invalidate the cached * search results so that any future search will match the current status * of this message and not what it was at the time it was last searched. */ - if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged)) + if (h->searched + && (changed != h->changed || deleted != ctx->deleted + || tagged != ctx->tagged)) h->searched = 0; - draw_sidebar(0); + draw_sidebar (0); } void mutt_tag_set_flag (int flag, int bf) @@ -314,13 +322,13 @@ void mutt_tag_set_flag (int flag, int bf) if (Context->hdrs[Context->v2r[j]]->tagged) mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], flag, bf); } -int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread) +int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread) { THREAD *start, *cur = hdr->thread; - - if ((Sort & SORT_MASK) != SORT_THREADS) - { + + if ((Sort & SORT_MASK) != SORT_THREADS) { mutt_error _("Threading is not enabled."); + return (-1); } @@ -328,15 +336,14 @@ int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread) while (cur->parent) cur = cur->parent; start = cur; - + if (cur->message) mutt_set_flag (Context, cur->message, flag, bf); if ((cur = cur->child) == NULL) return (0); - FOREVER - { + FOREVER { if (cur->message) mutt_set_flag (Context, cur->message, flag, bf); @@ -344,13 +351,11 @@ int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread) cur = cur->child; else if (cur->next) cur = cur->next; - else - { - while (!cur->next) - { - cur = cur->parent; - if (cur == start) - return (0); + else { + while (!cur->next) { + cur = cur->parent; + if (cur == start) + return (0); } cur = cur->next; } @@ -358,61 +363,60 @@ int mutt_thread_set_flag (HEADER *hdr, int flag, int bf, int subthread) /* not reached */ } -int mutt_change_flag (HEADER *h, int bf) +int mutt_change_flag (HEADER * h, int bf) { int i, flag; event_t event; - mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear flag")); + mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", + bf ? _("Set flag") : _("Clear flag")); clrtoeol (); - event = mutt_getch(); + event = mutt_getch (); i = event.ch; - if (i == -1) - { - CLEARLINE (LINES-1); + if (i == -1) { + CLEARLINE (LINES - 1); return (-1); } - CLEARLINE (LINES-1); - - switch (i) - { - case 'd': - case 'D': - flag = M_DELETE; - break; - - case 'N': - case 'n': - flag = M_NEW; - break; - - case 'o': - case 'O': - if (h) - mutt_set_flag (Context, h, M_READ, !bf); - else - mutt_tag_set_flag (M_READ, !bf); - flag = M_OLD; - break; - - case 'r': - case 'R': - flag = M_REPLIED; - break; - - case '*': - flag = M_TAG; - break; - - case '!': - flag = M_FLAG; - break; - - default: - BEEP (); - return (-1); + CLEARLINE (LINES - 1); + + switch (i) { + case 'd': + case 'D': + flag = M_DELETE; + break; + + case 'N': + case 'n': + flag = M_NEW; + break; + + case 'o': + case 'O': + if (h) + mutt_set_flag (Context, h, M_READ, !bf); + else + mutt_tag_set_flag (M_READ, !bf); + flag = M_OLD; + break; + + case 'r': + case 'R': + flag = M_REPLIED; + break; + + case '*': + flag = M_TAG; + break; + + case '!': + flag = M_FLAG; + break; + + default: + BEEP (); + return (-1); } if (h) diff --git a/from.c b/from.c index c26d5b1..e8b190b 100644 --- a/from.c +++ b/from.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ #if HAVE_CONFIG_H # include "config.h" @@ -40,16 +40,16 @@ int mutt_check_month (const char *s) for (i = 0; i < 12; i++) if (mutt_strncasecmp (s, Months[i], 3) == 0) return (i); - return (-1); /* error */ + return (-1); /* error */ } static int is_day_name (const char *s) { int i; - if ((strlen (s) < 3) || !*(s + 3) || !ISSPACE (*(s+3))) + if ((strlen (s) < 3) || !*(s + 3) || !ISSPACE (*(s + 3))) return 0; - for (i=0; i<7; i++) + for (i = 0; i < 7; i++) if (mutt_strncasecmp (s, Weekdays[i], 3) == 0) return 1; return 0; @@ -61,7 +61,7 @@ static int is_day_name (const char *s) * From [ ]