From a485ed478abbd599d8c9aab48934e7a26733ecb1 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Fri, 7 Oct 2011 08:35:27 +0200 Subject: [PATCH] Rearranged whitespace (and comments) in all the code! The primary goal was to only indent with tabs and not mix them with spaces. Also, no more tabs should appear past the first printable char on each line. Now editing the sources will be much easier, no matter which editor one uses, and rearranging won't break aligned code. (Beware, the changeset is huge, but the `diff -w' changes are moderate.) --- Makefile.in | 6 +- config/Makefile.in | 2 +- config/config.c | 171 +- config/version.sh | 36 +- configure.ac | 104 +- docs/COMPLETION-BASH | 16 +- docs/ChangeLog_MH-3_to_MH-6.6 | 16 +- docs/FAQ | 254 +-- docs/MAILING-LISTS | 6 +- docs/Makefile.in | 4 +- docs/README-HOOKS | 2 +- docs/README.about | 6 +- docs/README.developers | 6 +- docs/README.manpages | 2 +- etc/MailAliases | 6 +- etc/Makefile.in | 15 +- etc/digestcomps | 8 +- etc/mhn.defaults.sh | 86 +- etc/mhn.find.sh | 18 +- etc/mts.conf.in | 2 +- etc/sendfiles.in | 41 +- h/Makefile.in | 11 +- h/addrsbr.h | 41 +- h/aliasbr.h | 48 +- h/crawl_folders.h | 1 - h/dropsbr.h | 22 +- h/fmt_compile.h | 184 +- h/fmt_scan.h | 59 +- h/md5.h | 17 +- h/mf.h | 69 +- h/mh.h | 279 +-- h/mhcachesbr.h | 11 +- h/mhparse.h | 277 ++- h/mime.h | 50 +- h/mts.h | 13 +- h/nmh.h | 24 +- h/picksbr.h | 1 - h/prototypes.h | 2 - h/rcvmail.h | 5 +- h/scansbr.h | 22 +- h/signals.h | 1 - h/tws.h | 67 +- h/utils.h | 1 - man/Makefile.in | 29 +- man/ali.man | 2 +- man/ap.man | 2 +- man/comp.man | 2 +- man/conflict.man | 2 +- man/dist.man | 4 +- man/dp.man | 2 +- man/fmtdump.man | 2 +- man/folder.man | 4 +- man/forw.man | 10 +- man/mark.man | 2 +- man/mh-chart.man | 40 +- man/mh-format.man | 34 +- man/mh-profile.man | 4 +- man/mhl.man | 2 +- man/mhmail.man | 2 +- man/next.man | 2 +- man/nmh.man | 2 +- man/packf.man | 2 +- man/pick.man | 2 +- man/post.man | 4 +- man/prev.man | 2 +- man/rcvpack.man | 2 +- man/refile.man | 2 +- man/repl.man | 10 +- man/rmf.man | 2 +- man/send.man | 4 +- man/sendfiles.man | 2 +- sbr/Makefile.in | 56 +- sbr/addrsbr.c | 848 ++++---- sbr/ambigsw.c | 5 +- sbr/atooi.c | 17 +- sbr/brkstring.c | 59 +- sbr/check_charset.c | 69 +- sbr/client.c | 201 +- sbr/closefds.c | 7 +- sbr/concat.c | 31 +- sbr/context_del.c | 35 +- sbr/context_find.c | 11 +- sbr/context_foil.c | 86 +- sbr/context_read.c | 206 +- sbr/context_replace.c | 83 +- sbr/context_save.c | 107 +- sbr/copy.c | 11 +- sbr/copyip.c | 10 +- sbr/cpydata.c | 17 +- sbr/cpydgst.c | 69 +- sbr/crawl_folders.c | 190 +- sbr/discard.c | 27 +- sbr/done.c | 1 - sbr/dtime.c | 514 +++-- sbr/dtimep.lex | 427 ++-- sbr/error.c | 137 +- sbr/ext_hook.c | 97 +- sbr/fdcompare.c | 43 +- sbr/fmt_addr.c | 123 +- sbr/fmt_compile.c | 982 +++++---- sbr/fmt_def.c | 1 - sbr/fmt_new.c | 115 +- sbr/fmt_rfc2047.c | 551 ++--- sbr/fmt_scan.c | 1582 +++++++-------- sbr/folder_addmsg.c | 331 ++- sbr/folder_delmsgs.c | 187 +- sbr/folder_free.c | 21 +- sbr/folder_pack.c | 143 +- sbr/folder_read.c | 243 ++- sbr/folder_realloc.c | 109 +- sbr/gans.c | 61 +- sbr/getans.c | 83 +- sbr/getanswer.c | 9 +- sbr/getarguments.c | 69 +- sbr/getcpy.c | 23 +- sbr/getfolder.c | 31 +- sbr/getpass.c | 73 +- sbr/lock_file.c | 546 +++-- sbr/m_atoi.c | 21 +- sbr/m_backup.c | 20 +- sbr/m_convert.c | 678 ++++--- sbr/m_draft.c | 101 +- sbr/m_getfld.c | 914 ++++----- sbr/m_gmprot.c | 5 +- sbr/m_maildir.c | 113 +- sbr/m_mktemp.c | 144 +- sbr/m_msgdef.c | 1 - sbr/m_name.c | 9 +- sbr/m_scratch.c | 37 +- sbr/m_tmpfil.c | 22 +- sbr/makedir.c | 182 +- sbr/memmove.c | 15 +- sbr/mf.c | 1380 +++++++------ sbr/mts.c | 491 +++-- sbr/norm_charmap.c | 144 +- sbr/path.c | 237 ++- sbr/peekc.c | 9 +- sbr/pidstatus.c | 59 +- sbr/pidwait.c | 41 +- sbr/print_help.c | 23 +- sbr/print_sw.c | 73 +- sbr/print_version.c | 3 +- sbr/push.c | 60 +- sbr/putenv.c | 67 +- sbr/r1bindex.c | 23 +- sbr/readconfig.c | 157 +- sbr/refile.c | 69 +- sbr/remdir.c | 15 +- sbr/ruserpass.c | 284 +-- sbr/seq_add.c | 275 ++- sbr/seq_bits.c | 21 +- sbr/seq_del.c | 155 +- sbr/seq_getnum.c | 11 +- sbr/seq_list.c | 147 +- sbr/seq_nameok.c | 77 +- sbr/seq_print.c | 34 +- sbr/seq_read.c | 315 ++- sbr/seq_save.c | 145 +- sbr/seq_setcur.c | 11 +- sbr/seq_setprev.c | 35 +- sbr/seq_setunseen.c | 63 +- sbr/showfile.c | 89 +- sbr/sigmsg.awk | 144 +- sbr/signals.c | 102 +- sbr/smatch.c | 59 +- sbr/snprintb.c | 42 +- sbr/snprintf.c | 1508 +++++++------- sbr/ssequal.c | 17 +- sbr/strcasecmp.c | 61 +- sbr/strdup.c | 17 +- sbr/strerror.c | 9 +- sbr/strindex.c | 15 +- sbr/trimcpy.c | 45 +- sbr/uprf.c | 34 +- sbr/utils.c | 202 +- sbr/vfgets.c | 93 +- uip/Makefile.in | 25 +- uip/ali.c | 381 ++-- uip/aliasbr.c | 722 ++++--- uip/anno.c | 551 +++-- uip/annosbr.c | 724 +++---- uip/ap.c | 309 ++- uip/burst.c | 716 +++---- uip/comp.c | 507 +++-- uip/conflict.c | 739 ++++--- uip/dist.c | 501 +++-- uip/distsbr.c | 321 ++- uip/dp.c | 213 +- uip/dropsbr.c | 1021 +++++----- uip/flist.c | 980 ++++----- uip/fmtdump.c | 854 ++++---- uip/folder.c | 1051 +++++----- uip/forw.c | 1153 ++++++----- uip/ftpsbr.c | 655 +++--- uip/inc.c | 798 ++++---- uip/install-mh.c | 384 ++-- uip/mark.c | 441 ++-- uip/md5.c | 92 +- uip/mhbuild.c | 589 +++--- uip/mhbuildsbr.c | 2701 +++++++++++++------------ uip/mhcachesbr.c | 576 +++--- uip/mhfree.c | 365 ++-- uip/mhl.c | 7 +- uip/mhlist.c | 561 +++--- uip/mhlistsbr.c | 497 +++-- uip/mhlsbr.c | 2769 +++++++++++++------------ uip/mhmail.c | 333 ++-- uip/mhmisc.c | 247 ++- uip/mhoutsbr.c | 639 +++--- uip/mhparam.c | 277 ++- uip/mhparse.c | 4436 ++++++++++++++++++++--------------------- uip/mhpath.c | 203 +- uip/mhshow.c | 697 ++++--- uip/mhshowsbr.c | 1561 ++++++++------- uip/mhstore.c | 589 +++--- uip/mhstoresbr.c | 1499 +++++++------- uip/mhtest.c | 553 +++-- uip/msgchk.c | 353 ++-- uip/new.c | 755 ++++--- uip/packf.c | 293 ++- uip/pick.c | 535 +++-- uip/picksbr.c | 1375 +++++++------ uip/prompter.c | 663 +++--- uip/rcvdist.c | 414 ++-- uip/rcvpack.c | 137 +- uip/rcvstore.c | 380 ++-- uip/rcvtty.c | 445 +++-- uip/refile.c | 549 +++-- uip/repl.c | 801 ++++---- uip/replsbr.c | 685 +++---- uip/rmf.c | 391 ++-- uip/rmm.c | 213 +- uip/scan.c | 525 +++-- uip/scansbr.c | 556 +++--- uip/send.c | 797 ++++---- uip/sendsbr.c | 1713 ++++++++-------- uip/show.c | 919 +++++---- uip/slocal.c | 2276 ++++++++++----------- uip/sortm.c | 923 +++++---- uip/spost.c | 1393 ++++++------- uip/termsbr.c | 156 +- uip/viamail.c | 370 ++-- uip/whatnow.c | 5 +- uip/whatnowproc.c | 169 +- uip/whatnowsbr.c | 2267 ++++++++++----------- uip/whom.c | 337 ++-- 246 files changed, 36165 insertions(+), 36428 deletions(-) diff --git a/Makefile.in b/Makefile.in index 85dbf10..efab885 100644 --- a/Makefile.in +++ b/Makefile.in @@ -61,9 +61,9 @@ INSTALL_DATA = @INSTALL_DATA@ .SUFFIXES: # all files in this directory included in the distribution -DIST = ChangeLog COPYRIGHT DATE INSTALL MACHINES README VERSION \ - ChangeLog install-sh mkinstalldirs Makefile.in aclocal.m4 \ - acconfig.h config.h.in configure.ac configure stamp-h.in \ +DIST = ChangeLog COPYRIGHT DATE INSTALL MACHINES README VERSION \ + ChangeLog install-sh mkinstalldirs Makefile.in aclocal.m4 \ + acconfig.h config.h.in configure.ac configure stamp-h.in \ config.sub config.guess # subdirectories in distribution diff --git a/config/Makefile.in b/config/Makefile.in index 1f1d5aa..c1b16bd 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -84,7 +84,7 @@ subdir = config Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) nmhdist: $(DIST) @echo "Copying distribution files in $(subdir)" diff --git a/config/config.c b/config/config.c index f03cd19..f5471a9 100644 --- a/config/config.c +++ b/config/config.c @@ -1,4 +1,3 @@ - /* * config.c -- master nmh configuration file * @@ -26,77 +25,76 @@ * 2) Next, if it begins with ~user, then expand it. * 3) Next, check in nmh Mail directory. * 4) Next, check in nmh `etc' directory. - * */ char * etcpath (char *file) { - static char epath[PATH_MAX]; - char *cp; + static char epath[PATH_MAX]; + char *cp; #ifdef MHRC - char *pp; - struct passwd *pw; + char *pp; + struct passwd *pw; #endif #ifdef MHRC - context_read(); + context_read(); #endif - switch (*file) { - case '/': - /* If already absolute pathname, return it */ - return file; + switch (*file) { + case '/': + /* If already absolute pathname, return it */ + return file; #ifdef MHRC - case '~': - /* Expand ~username */ - if ((cp = strchr(pp = file + 1, '/'))) - *cp++ = '\0'; - if (*pp == '\0') { - pp = mypath; - } else { - if ((pw = getpwnam (pp))) - pp = pw->pw_dir; - else { - if (cp) - *--cp = '/'; - goto try_it; + case '~': + /* Expand ~username */ + if ((cp = strchr(pp = file + 1, '/'))) + *cp++ = '\0'; + if (*pp == '\0') { + pp = mypath; + } else { + if ((pw = getpwnam (pp))) + pp = pw->pw_dir; + else { + if (cp) + *--cp = '/'; + goto try_it; + } } - } - snprintf (epath, sizeof(epath), "%s/%s", pp, cp ? cp : ""); - if (cp) - *--cp = '/'; + snprintf (epath, sizeof(epath), "%s/%s", pp, cp ? cp : ""); + if (cp) + *--cp = '/'; - if (access (epath, R_OK) != NOTOK) - return epath; /* else fall */ + if (access (epath, R_OK) != NOTOK) + return epath; /* else fall */ try_it: #endif /* MHRC */ - default: - /* Check nmh Mail directory */ - if (access ((cp = m_mailpath (file)), R_OK) != NOTOK) - return cp; - } + default: + /* Check nmh Mail directory */ + if (access ((cp = m_mailpath (file)), R_OK) != NOTOK) + return cp; + } - /* Check nmh `etc' directory */ - snprintf (epath, sizeof(epath), nmhetcdir(/%s), file); - return (access (epath, R_OK) != NOTOK ? epath : file); + /* Check nmh `etc' directory */ + snprintf (epath, sizeof(epath), nmhetcdir(/%s), file); + return (access (epath, R_OK) != NOTOK ? epath : file); } -/* +/* * Standard yes/no switches structure */ struct swit anoyes[] = { - { "no", 0 }, - { "yes", 0 }, - { NULL, 0 } + { "no", 0 }, + { "yes", 0 }, + { NULL, 0 } }; -/* +/* * nmh constants */ @@ -110,18 +108,18 @@ char *mh_profile = ".mh_profile"; char *current = "cur"; /* standard component files */ -char *components = "components"; /* comp */ -char *replcomps = "replcomps"; /* repl */ -char *replgroupcomps = "replgroupcomps"; /* repl -group */ -char *forwcomps = "forwcomps"; /* forw */ -char *distcomps = "distcomps"; /* dist */ -char *rcvdistcomps = "rcvdistcomps"; /* rcvdist */ -char *digestcomps = "digestcomps"; /* forw -digest */ +char *components = "components"; /* comp */ +char *replcomps = "replcomps"; /* repl */ +char *replgroupcomps = "replgroupcomps"; /* repl -group */ +char *forwcomps = "forwcomps"; /* forw */ +char *distcomps = "distcomps"; /* dist */ +char *rcvdistcomps = "rcvdistcomps"; /* rcvdist */ +char *digestcomps = "digestcomps"; /* forw -digest */ /* standard format (filter) files */ -char *mhlformat = "mhl.format"; /* show */ -char *mhlreply = "mhl.reply"; /* repl -filter */ -char *mhlforward = "mhl.forward"; /* forw -filter */ +char *mhlformat = "mhl.format"; /* show */ +char *mhlreply = "mhl.reply"; /* repl -filter */ +char *mhlforward = "mhl.forward"; /* forw -filter */ char *draft = "draft"; @@ -144,7 +142,7 @@ char *nmhaccessftp = "nmh-access-ftp"; char *mhlibdir = NMHLIBDIR; char *mhetcdir = NMHETCDIR; -/* +/* * nmh not-so constants */ @@ -164,18 +162,18 @@ char *mh_seq = NULL; char *mh_seq = ".mh_sequences"; #endif -/* +/* * nmh globals */ -char ctxflags; /* status of user's context */ -char *invo_name; /* command invocation name */ -char *mypath; /* user's $HOME */ -char *defpath; /* pathname of user's profile */ -char *ctxpath; /* pathname of user's context */ -struct node *m_defs; /* profile/context structure */ +char ctxflags; /* status of user's context */ +char *invo_name; /* command invocation name */ +char *mypath; /* user's $HOME */ +char *defpath; /* pathname of user's profile */ +char *ctxpath; /* pathname of user's context */ +struct node *m_defs; /* profile/context structure */ -/* +/* * nmh processes */ @@ -191,7 +189,6 @@ char *catproc = "/bin/cat"; /* * mhl runs this program as a visual-end. */ - char *faceproc = NULL; /* @@ -199,20 +196,17 @@ char *faceproc = NULL; * also invoked by the spost program to process an "Fcc", or by * comp/repl/forw/dist to refile a draft message. */ - char *fileproc = nmhbindir (/refile); -/* +/* * This program is called to incorporate messages into a folder. */ - char *incproc = nmhbindir (/inc); /* * When a user runs an nmh program for the first time, this program * is called to create his nmh profile, and mail directory. */ - char *installproc = nmhlibdir (/install-mh); /* @@ -221,13 +215,11 @@ char *installproc = nmhlibdir (/install-mh); * folder facility in comp/dist/forw/repl to display the * draft message. */ - char *lproc = "more"; /* * This is the path for the Bell equivalent mail program. */ - char *mailproc = nmhbindir (/mhmail); /* @@ -235,10 +227,9 @@ char *mailproc = nmhbindir (/mhmail); * by mhshow as the default method of displaying message bodies * or message parts of type text/plain. */ - char *moreproc = "more"; -/* +/* * This is the program (mhl) used to filter messages. It is * used by mhshow to filter and display the message headers of * MIME messages. It is used by repl/forw (with -filter) @@ -246,54 +237,46 @@ char *moreproc = "more"; * It is used by send/spost (with -filter) to filter the message * for "Bcc:" recipients. */ - char *mhlproc = nmhlibdir (/mhl); -/* - * This program is called to pack a folder. +/* + * This program is called to pack a folder. */ - char *packproc = nmhbindir (/packf); /* * This is the delivery program called by send to actually * deliver mail to users. This is the interface to the MTS. */ - char *postproc = nmhlibdir (/spost); /* * This is program is called by slocal to handle * the action `folder' or `+'. */ - char *rcvstoreproc = nmhlibdir (/rcvstore); -/* - * This program is called to remove a folder. +/* + * This program is called to remove a folder. */ - char *rmfproc = nmhbindir (/rmf); -/* +/* * This program is called to remove a message by rmm or refile -nolink. * It's usually empty, which means to rename the file to a backup name. */ - char *rmmproc = NULL; /* * This program is usually called by the user's whatnowproc, but it * may also be called directly to send a message previously composed. */ - char *sendproc = nmhbindir (/send); /* * This is the path to the program used by "show" * to display non-text (MIME) messages. */ - char *showmimeproc = nmhbindir (/mhshow); /* @@ -302,32 +285,27 @@ char *showmimeproc = nmhbindir (/mhshow); * changed to a pager (such as "more" or "less") if you prefer * that such message not be filtered in any way. */ - char *showproc = nmhlibdir (/mhl); -/* +/* * This program is called after comp, et. al., have built a draft */ - char *whatnowproc = nmhbindir (/whatnow); -/* +/* * This program is called to list/validate the addresses in a message. */ - char *whomproc = nmhbindir (/whom); -/* +/* * This is the sendmail interface to use for sending mail. */ - char *sendmail = SENDMAILPATH; /* * The prefix that is prepended to the name of message files when they * are "removed" by rmm. This should typically be `,' or `#'. */ - char *backup_prefix = ","; /* @@ -335,7 +313,6 @@ char *backup_prefix = ","; * composition programs. It SHOULD be a full screen * editor, such as vi or emacs, but any editor will work. */ - char *defaulteditor = "vi"; /* @@ -344,21 +321,19 @@ char *defaulteditor = "vi"; */ char *altmsglink = "@"; -/* +/* * This is the global nmh alias file. It is somewhat obsolete, since * global aliases should be handled by the Mail Transport Agent (MTA). */ - char *AliasFile = nmhetcdir (/MailAliases); -/* +/* * File protections */ /* * Folders (directories) are created with this protection (mode) */ - char *foldprot = "700"; /* @@ -366,6 +341,4 @@ char *foldprot = "700"; * message is filed it retains its protection, so this only applies * to messages coming in through inc. */ - char *msgprot = "600"; - diff --git a/config/version.sh b/config/version.sh index 1ff7eed..61d9637 100755 --- a/config/version.sh +++ b/config/version.sh @@ -6,8 +6,8 @@ # if [ -z "$1" ]; then - echo "usage: version.sh VERSION" 1>&2 - exit 1 + echo "usage: version.sh VERSION" 1>&2 + exit 1 fi VERSION=$1 @@ -18,22 +18,24 @@ HOSTNAME=unknown # Find out the name of the host we are compiling on for prog in uname hostname do - for dir in $PATH - do - if [ ! -f $dir/$prog ]; then - continue + for dir in $PATH + do + if [ ! -f $dir/$prog ]; then + continue + fi + case $prog in + uname) + HOSTNAME=`$prog -n` + ;; + hostname) + HOSTNAME=`$prog` + ;; + esac + break + done + if [ X"$HOSTNAME" != X -a X"$HOSTNAME" != Xunknown ]; then + break fi - case $prog in - uname) HOSTNAME=`$prog -n` - ;; - hostname) HOSTNAME=`$prog` - ;; - esac - break - done - if [ X"$HOSTNAME" != X -a X"$HOSTNAME" != Xunknown ]; then - break - fi done IFS=" " diff --git a/configure.ac b/configure.ac index f4d1dd6..e9d2354 100644 --- a/configure.ac +++ b/configure.ac @@ -24,7 +24,7 @@ if test -n "$LIBTOOL" ; then fi fi ] ) - + echo "configuring for AC_PACKAGE_NAME-AC_PACKAGE_VERSION" AC_SUBST(VERSION,AC_PACKAGE_VERSION)dnl @@ -140,9 +140,9 @@ dnl We use -Wall; if the compiler supports it we also use -Wno-pointer-sign, dnl because gcc 4 now produces a lot of new warnings which are probably mostly dnl spurious and which in any case we don't want to deal with now. if test "$nmh_cv_has_noptrsign" = "yes"; then - nmh_gcc_warnflags="-Wall -Wno-pointer-sign" + nmh_gcc_warnflags="-Wall -Wno-pointer-sign" else - nmh_gcc_warnflags="-Wall" + nmh_gcc_warnflags="-Wall" fi if test -n "$auto_cflags"; then @@ -155,12 +155,12 @@ if test -n "$auto_cflags"; then else if test -z "$LDFLAGS"; then case "$build_os" in - darwin*) - LDFLAGS= + darwin*) + LDFLAGS= + ;; + *) + LDFLAGS=-s ;; - *) - LDFLAGS=-s - ;; esac fi if test -n "$GCC"; then @@ -171,16 +171,16 @@ if test -n "$auto_cflags"; then fi fi -AC_C_CONST dnl Does compiler support `const'. +AC_C_CONST dnl Does compiler support `const'. dnl ------------------ dnl CHECK FOR PROGRAMS dnl ------------------ -AC_PROG_MAKE_SET dnl Does make define $MAKE -AC_PROG_INSTALL dnl Check for BSD compatible `install' -AC_PROG_RANLIB dnl Check for `ranlib' -AC_PROG_AWK dnl Check for mawk,gawk,nawk, then awk -AC_PROG_LEX dnl Check for lex/flex +AC_PROG_MAKE_SET dnl Does make define $MAKE +AC_PROG_INSTALL dnl Check for BSD compatible `install' +AC_PROG_RANLIB dnl Check for `ranlib' +AC_PROG_AWK dnl Check for mawk,gawk,nawk, then awk +AC_PROG_LEX dnl Check for lex/flex dnl Look for `cut' pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb @@ -248,8 +248,8 @@ AC_PATH_PROG(lspath, ls, no, [$pathtmp]) dnl See how we get ls to display the owner and the group if test "$lspath" != "no"; then - AC_CACHE_CHECK(how to get ls to show us the group ownership of a file, - nmh_cv_ls_grpopt, + AC_CACHE_CHECK(how to get ls to show us the group ownership of a file, + nmh_cv_ls_grpopt, [if test x"`$lspath -dl / | $AWK '{print $9}'`" = x"/"; then dnl There were 9 parameters, so unless this is a really bizarre, nonstandard dnl ls, it would seem -l gave us both the user and group. On this type of @@ -287,8 +287,8 @@ AC_SUBST(mailspool)dnl dnl See whether the mail spool directory is world-writable. if test "$lspath" != "no" -a "$cutpath" != "no"; then - AC_CACHE_CHECK(whether the mail spool is world-writable, - nmh_cv_mailspool_world_writable, + AC_CACHE_CHECK(whether the mail spool is world-writable, + nmh_cv_mailspool_world_writable, [if test "`$lspath -dlL $mailspool | $cutpath -c9`" = "-"; then nmh_cv_mailspool_world_writable=no else @@ -362,7 +362,7 @@ AC_CHECK_HEADERS(string.h memory.h stdlib.h unistd.h errno.h fcntl.h \ langinfo.h wchar.h wctype.h iconv.h netdb.h \ sys/param.h sys/time.h sys/utsname.h sys/stream.h \ arpa/inet.h arpa/ftp.h) - + dnl dnl Checks for _IO_write_ptr. A Linuxism used by nmh on linux. We dnl really use a whole set of them, but this check should be @@ -370,7 +370,7 @@ dnl sufficient. dnl AC_CHECK_HEADER(libio.h, [ AC_EGREP_HEADER(_IO_write_ptr, libio.h, [ - AC_DEFINE(LINUX_STDIO,1,[Use the Linux _IO_*_ptr defines from .]) ]) ]) + AC_DEFINE(LINUX_STDIO,1,[Use the Linux _IO_*_ptr defines from .]) ]) ]) AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1, [Define to 1 if `struct winsize' requires .]),, @@ -399,14 +399,14 @@ AC_REPLACE_FUNCS(memmove snprintf strerror strdup) dnl Look for the initgroups() declaration. On AIX 4.[13], Solaris 4.1.3, and dnl ULTRIX 4.2A the function is defined in libc but there's no declaration in -dnl any system header. +dnl any system header. dnl dnl On Solaris 2.[456], the declaration is in . On HP-UX 9-11 and dnl (reportedly) FreeBSD 3.[23], it's in . Any other locations we dnl need to check? AH_TEMPLATE(INITGROUPS_HEADER, [Define to the header containing the declaration of `initgroups'.]) AC_EGREP_HEADER(initgroups, grp.h, AC_DEFINE(INITGROUPS_HEADER, ), - AC_EGREP_HEADER(initgroups, unistd.h, + AC_EGREP_HEADER(initgroups, unistd.h, AC_DEFINE(INITGROUPS_HEADER, ))) dnl On AIX 4.1, snprintf() is defined in libc.a but there's no prototype in @@ -414,8 +414,8 @@ dnl or elsewhere. Apparently it's not officially supported (though it dnl seems to work perfectly and IBM apparently uses it in internal code). dnl Anyhow, if we omit our own snprintf() and vsnprintf() prototypes when we dnl HAVE_SNPRINTF, we get a billion warnings at compile time. Use the C -dnl preprocessor to preprocess stdio.h and make sure that there's actually a -dnl prototype. +dnl preprocessor to preprocess stdio.h and make sure that there's actually a +dnl prototype. AC_EGREP_HEADER(snprintf, stdio.h, AC_DEFINE(HAVE_SNPRINTF_PROTOTYPE,1, [Define to 1 if has a prototype for snprintf().])) @@ -564,13 +564,13 @@ AC_CACHE_CHECK(if an include file defines ospeed, nmh_cv_decl_ospeed_include_defines, [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include #if HAVE_TERMIOS_H -#include +# include #endif #if HAVE_TERMCAP_H -#include +# include #endif]], [[ospeed = 0;]])], nmh_cv_decl_ospeed_include_defines=yes,nmh_cv_decl_ospeed_include_defines=no)]) - + if test $nmh_cv_decl_ospeed_include_defines = no; then AC_CACHE_CHECK(if you must define ospeed, nmh_cv_decl_ospeed_must_define, @@ -578,7 +578,7 @@ if test $nmh_cv_decl_ospeed_include_defines = no; then [[extern short ospeed; ospeed = 0;]])], nmh_cv_decl_ospeed_must_define=yes,nmh_cv_decl_ospeed_must_define=no)]) fi - + AH_TEMPLATE(HAVE_OSPEED, [Define to 1 if your termcap library has the ospeed variable.]) if test $nmh_cv_decl_ospeed_include_defines = yes; then AC_DEFINE(HAVE_OSPEED)dnl @@ -600,16 +600,16 @@ nmh_cv_func_tgetent_accepts_null, [AC_TRY_RUN([ main() { - char buf[4096]; - int r1 = tgetent(buf, "vt100"); - int r2 = tgetent((char*)0,"vt100"); - if (r1 >= 0 && r1 == r2) { - char tbuf[1024], *u; - u = tbuf; - tgetstr("cl", &u); - creat("conftest.tgetent", 0640); - } - exit((r1 != r2) || r2 == -1); + char buf[4096]; + int r1 = tgetent(buf, "vt100"); + int r2 = tgetent((char*)0,"vt100"); + if (r1 >= 0 && r1 == r2) { + char tbuf[1024], *u; + u = tbuf; + tgetstr("cl", &u); + creat("conftest.tgetent", 0640); + } + exit((r1 != r2) || r2 == -1); } ], if test -f conftest.tgetent; then @@ -627,16 +627,16 @@ nmh_cv_func_tgetent_zero_success, [AC_TRY_RUN([ main() { - char buf[4096]; - int r1 = tgetent(buf, "!@#$%^&*"); - int r2 = tgetent(buf, "vt100"); - if (r1 < 0 && r2 == 0) { - char tbuf[1024], *u; - u = tbuf; - tgetstr("cl", &u); - creat("conftest.tgetent0", 0640); - } - exit(r1 == r2); + char buf[4096]; + int r1 = tgetent(buf, "!@#$%^&*"); + int r2 = tgetent(buf, "vt100"); + if (r1 < 0 && r2 == 0) { + char tbuf[1024], *u; + u = tbuf; + tgetstr("cl", &u); + creat("conftest.tgetent0", 0640); + } + exit(r1 == r2); } ], if test -f conftest.tgetent0; then @@ -767,7 +767,7 @@ AC_CACHE_CHECK(where signal.h is located, nmh_cv_path_signal_h, /dev/null; dnl Just in case we fall through do test -f $SIGNAL_H && \ - grep '#[ ]*define[ ][ ]*SIG[0-9A-Z]*[ ]*[0-9][0-9]*' $SIGNAL_H > /dev/null && \ + grep '#[ ]*define[ ][ ]*SIG[0-9A-Z]*[ ]*[0-9][0-9]*' $SIGNAL_H > /dev/null && \ break done nmh_cv_path_signal_h=$SIGNAL_H @@ -786,7 +786,7 @@ case "$target_os" in sunos4*) AC_DEFINE(BSD42) ;; - freebsd*) + freebsd*) AC_DEFINE(BSD42) ;; netbsd*) @@ -808,7 +808,7 @@ dnl ---------------- dnl OUTPUT MAKEFILES dnl ---------------- AC_CONFIG_FILES(Makefile config/Makefile h/Makefile sbr/Makefile uip/Makefile \ - etc/Makefile docs/Makefile man/Makefile) + etc/Makefile docs/Makefile man/Makefile) AC_CONFIG_COMMANDS([stamp],[test -z "$CONFIG_HEADERS" || echo > stamp-h]) AC_OUTPUT @@ -843,5 +843,5 @@ man page install path : ${nmhman} sendmail path : ${sendmailpath} file locking type : ${LOCKTYPE} -email address masq. : ${masquerade} +address masquerading : ${masquerade} " diff --git a/docs/COMPLETION-BASH b/docs/COMPLETION-BASH index d6496f7..bdc584f 100644 --- a/docs/COMPLETION-BASH +++ b/docs/COMPLETION-BASH @@ -13,7 +13,7 @@ _nmh() prev=${COMP_WORDS[COMP_CWORD-1]} command=$1 - orig_opts=$(shopt -p extglob) + orig_opts=$(shopt -p extglob) shopt -s extglob # Get the folder, if specified @@ -21,22 +21,22 @@ _nmh() do case "${COMP_WORDS[i]}" in \++([a-zA-Z_]) ) - folder=${COMP_WORDS[i]} + folder=${COMP_WORDS[i]} origfolder=$( folder -f ) ;; esac done - case $current in - -* ) + case $current in + -* ) # Command-line switches for the most common commands. case $command in - ali ) + ali ) # no sequences or messages options=(-alias -list -nolist -normalize -nonormalize -user -nouser -version -help) ;; - burst ) + burst ) options=(-inplace -noinplace -quiet -noquiet -verbose -noverbose -version -help) ;; @@ -44,7 +44,7 @@ _nmh() options=(-form -use -nouse -file -draftfolder -draftmessage -nodraftfolder -editor -noedit -whatnowproc -nowhatnowproc -version -help ) - ;; + ;; flist* ) options=(-sequence -all -noall -showzero -noshowzero -recurse -norecurse -fast -nofast -alpha -noalpha -version @@ -161,4 +161,4 @@ _nmh() COMPREPLY=( $( compgen -W "${options[*]}" -- $current ) ) return 0 } -[ "$have" ] && complete -F _nmh ali anno burst comp dist flist flists folder folders forw inc mark mhbuild mhl mhlist mhmail mhparam mhpath mhshow mhstore msgchk next packf pick prev prompter rcvdist rcvpack rcvstore rcvtty refile repl rmf rmm scan send sendfiles show slocal sortm whatnow whom +[ "$have" ] && complete -F _nmh ali anno burst comp dist flist flists folder folders forw inc mark mhbuild mhl mhlist mhmail mhparam mhpath mhshow mhstore msgchk next packf pick prev prompter rcvdist rcvpack rcvstore rcvtty refile repl rmf rmm scan send sendfiles show slocal sortm whatnow whom diff --git a/docs/ChangeLog_MH-3_to_MH-6.6 b/docs/ChangeLog_MH-3_to_MH-6.6 index ea7cd58..4b7ecf8 100644 --- a/docs/ChangeLog_MH-3_to_MH-6.6 +++ b/docs/ChangeLog_MH-3_to_MH-6.6 @@ -936,7 +936,7 @@ Sun Feb 23 13:59:46 1986 /mtr Thu Feb 20 22:57:33 1986 /mtr - + MH 6.4 #1[UCI] (nrtc-gremlin) made available to Van Jacobson for inclusion in 4.3BSD UNIX @@ -1092,7 +1092,7 @@ Wed Feb 5 14:42:55 1986 /mtr Wed Feb 5 11:25:05 1986 /mtr - + MH 6.3 #1[UCI] (nrtc-gremlin) is official, still awaiting Berkeley enhancements @@ -1845,7 +1845,7 @@ Sun Oct 13 14:17:10 1985 /mtr Wed Oct 9 19:49:04 1985 /mtr - uip/send.c: fix bogus annotation handling, e.g., + uip/send.c: fix bogus annotation handling, e.g., send -push; rmm; folder -pack uip/{forw,mhlsbr}.c: add extra blank line after final EB so user can add suffix text with an editor (e.g., prompter) @@ -3030,7 +3030,7 @@ Wed Apr 3 23:52:13 1985 /mtr (agent: Marshall Rose) Tue Mar 26 18:32:49 1985 /mtr (agent: Marshall Rose) - conf/{config/mts.c,tailor/READ-ME}, config/aliasbr.h, mts/mts.h, + conf/{config/mts.c,tailor/READ-ME}, config/aliasbr.h, mts/mts.h, uip/aliasbr.c: make "*" logic mts-tailorable (ugh), you get to choose highest non-user uid and non-user shell @@ -3430,7 +3430,7 @@ Wed Apr 3 23:52:13 1985 /mtr (agent: Marshall Rose) Tue Mar 26 18:32:49 1985 /mtr (agent: Marshall Rose) - conf/{config/mts.c,tailor/READ-ME}, config/aliasbr.h, mts/mts.h, + conf/{config/mts.c,tailor/READ-ME}, config/aliasbr.h, mts/mts.h, uip/aliasbr.c: make "*" logic mts-tailorable (ugh), you get to choose highest non-user uid and non-user shell @@ -3944,7 +3944,7 @@ Wed Nov 28 22:59:34 1984 /mtr (agent: Marshall Rose) sbr/m_draft.c: call path() on value of Draft-Folder: so relative folders work (!!) uip/repl.c: expand fcc: @folder arguments - + Wed Nov 28 20:42:21 1984 /mtr (agent: Marshall Rose) @@ -4171,7 +4171,7 @@ Fri Nov 16 19:01:32 1984 /mtr (agent: Marshall Rose) uip/msh.c: remove -[no]burst switches. Add "rmm" command, but don't document it yet. Still have to resolve a few problems. - + Fri Nov 16 08:21:08 1984 /mtr (agent: Marshall Rose) @@ -4958,7 +4958,7 @@ Sun Jul 15 17:10:38 1984 Rand MH mail system (agent: Marshall Rose) diff --git a/docs/FAQ b/docs/FAQ index f086862..4786c02 100644 --- a/docs/FAQ +++ b/docs/FAQ @@ -48,7 +48,7 @@ Posting-Frequency: monthly MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ---------------------------------------------------------------------- - + Subject: Table of Contents From: Bill Wohler Date: Sat, 3 Mar 2001 11:29:16 -0800 @@ -215,7 +215,7 @@ Appendix Removing duplicate messages (Perl) ------------------------------ - + Subject: Viewing This Article From: Bill Wohler Date: Mon, 27 Nov 1995 14:44:19 -0800 @@ -265,7 +265,7 @@ Date: Mon, 27 Nov 1995 14:44:19 -0800 Note that due to bottom feeding email address harvesting spam scum, mailto links have been removed and @s in addresses have been replaced by "at." - + ------------------------------ Subject: 01.00 ***** Introduction ***** @@ -310,7 +310,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 MH is free, powerful, flexible--and the basics are easy to learn. ------------------------------ - + Subject: !01.02 What is the current version/status of MH. From: Bill Wohler Date: Sun, 23 Sep 2007 23:51:52 -0700 @@ -349,13 +349,13 @@ Date: Sun, 23 Sep 2007 23:51:52 -0700 http://www.gnu.org/software/mailutils/. ------------------------------ - + Subject: !01.03 Where can I get MH? From: Bill Wohler Date: Sun, 23 Sep 2007 23:51:46 -0700 MH comes standard with: - + Berkeley Software Design BSD/386 . . . . MH 6.8.3 Control Data Corp. CDC4680-MP . . . . . . EMH 1.4.2 (modified MH) Debian GNU/Linux 4.0 . . . . . . . . . . nmh 1.1-RC4 @@ -378,11 +378,11 @@ Date: Sun, 23 Sep 2007 23:51:46 -0700 http://download.savannah.nongnu.org/releases/nmh/nmh-1.2.tar.gz 831kB Download GNU mailutils: - + http://ftp.gnu.org/gnu/mailutils/mailutils-1.2.tar.gz 3.4MB ------------------------------ - + Subject: !01.04 What references exist for MH? From: Bill Wohler Date: Sun, 23 Sep 2007 23:51:41 -0700 @@ -426,15 +426,15 @@ Date: Sun, 23 Sep 2007 23:51:41 -0700 gmane.mail.mh-e.devel gmane.mail.mh-e.user gmane.mail.nmh.devel - + Mailing lists: There are three mailing lists for nmh: nmh-announce, nmh-workers, and nmh-commits. See: http://savannah.nongnu.org/mail/?group=nmh - + The page for each list contains a link to the archives. - + MH-users archives: Current archives can be found at: @@ -473,7 +473,7 @@ Date: Sun, 23 Sep 2007 23:51:41 -0700 http://www.faqs.org/faqs/usenet/signature-faq/ ------------------------------ - + Subject: 01.05 What other MH software is available? From: Stephen Gildea , Bill Wohler Date: Thu, 19 May 2005 21:20:57 -0700 @@ -560,7 +560,7 @@ Date: Fri, 26 Jan 1996 13:51:08 +0100 [MH-E has had these capabilities since version 7.0 so mew is obsolete if you use MH-E. --Ed] -From: James Perkins +From: James Perkins Date: Fri, 1 Jan 1993 00:00:00 -0800 Vmh is designed for people using the bulletin-board features of MH, @@ -800,14 +800,14 @@ Date: Sun, 11 Mar 2001 00:23:21 -0800 compile nmh with the Cygwin tools (http://www.cygwin.com/). ------------------------------ - + Subject: !01.06 How can I print a MH manual? From: Bill Wohler , Jos Vos Date: Sun, 23 Sep 2007 23:51:33 -0700 Documentation in text and PostScript format is found in the MH-doc.tgz tarball on: - + http://sourceforge.net/project/showfiles.php?group_id=143658&package_id=188464 To generate your own copy for printing, first obtain the MH sources @@ -824,7 +824,7 @@ Date: Sun, 23 Sep 2007 23:51:33 -0700 tmac.h file in the MH lib directory is made in the manual pages. ------------------------------ - + Subject: 01.07 How should I report bugs? From: Bill Wohler Date: Wed, 29 Sep 2004 00:12:42 -0700 @@ -838,7 +838,7 @@ Date: Wed, 29 Sep 2004 00:12:42 -0700 http://sourceforge.net/tracker/?atid=113357&group_id=13357 ------------------------------ - + Subject: 01.08 How can I convert from my mailer to MH? From: Mike Sutton Date: 7 Jul 1995 10:03:50 GMT @@ -912,7 +912,7 @@ Date: Sun, 1 May 1994 00:00:00 -0800 See also MH book second edition (Appendix D). ------------------------------ - + Subject: 01.09 What is the copyright status of nmh? From: Richard Coleman Date: Mon, 10 Oct 2005 18:16:58 -0700 @@ -947,7 +947,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 If you have a computer running Unix, you can probably run MH. ------------------------------ - + Subject: 02.02 How do I build MH? From: Bill Wohler Date: Sun, 8 Sep 1996 15:13:12 -0700 @@ -968,7 +968,7 @@ Date: Sun, 8 Sep 1996 15:13:12 -0700 info. ------------------------------ - + Subject: 02.03 What options should I use? From: Bill Wohler Date: Tue, 1 Dec 1992 00:00:00 -0800 @@ -1013,7 +1013,7 @@ Date: Tue, 1 Dec 1992 00:00:00 -0800 tools like from work. ------------------------------ - + Subject: 02.04 What do I need to do to use POP? From: Bill Wohler Date: Sun, 8 Sep 1996 23:31:01 -0700 @@ -1041,7 +1041,7 @@ Date: 06 Feb 1997 03:43:17 -0500 configuration and recompile: ------------------------------ - + Subject: 02.05 Does MH support IMAP? From: Lyndon Nerenberg Date: 27 Jul 1999 11:33:39 -0600 @@ -1148,7 +1148,7 @@ Date: Sun, 8 Sep 1996 15:45:32 -0700 campus email server. There are current IETF working groups revising IMAP and readying it to become an Internet standard. A copy of the latest IMAP draft may be obtained from: - + ftp://ftp.cac.washington.edu/mail/latest-imap-draft For a list of IMAP clients, see the file imap.software, in the same @@ -1173,7 +1173,7 @@ Date: Mon, 1 Aug 1994 00:00:00 -0800 future develop a version of MH that can use IMAP. ------------------------------ - + Subject: 02.06 Why does "mailgroup mail" only affect inc but not slocal? From: John Romine Date: Fri, 1 Jan 1993 00:00:00 -0800 @@ -1194,11 +1194,11 @@ Date: Fri, 1 Jan 1993 00:00:00 -0800 (See "What mail filters are available?") ------------------------------ - + Subject: 02.07 How can I build MH on Solaris 2? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 - + nmh builds out of the box on Solaris. From: Bill Wohler @@ -1279,7 +1279,7 @@ Date: Fri, 04 Apr 1997 15:30:36 GMT MH configuration. ------------------------------ - + Subject: 02.08 How can I build MH on Linux? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -1342,7 +1342,7 @@ Date: Sun, 26 Nov 1995 16:18:50 -0800 please let me know if they are missing. ------------------------------ - + Subject: 02.09 How can I build MH on IRIX? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -1383,7 +1383,7 @@ Date: 25 Jul 1995 02:35:41 GMT (See "IRIX config file") below. ------------------------------ - + Subject: 02.10 How can I get MH to interpret the Content-Length field? From: Casper H.S. Dik Date: Sun, 8 Sep 1996 15:38:30 -0700 @@ -1395,7 +1395,7 @@ Date: Sun, 8 Sep 1996 15:38:30 -0700 http://www.gw.com/mail/mh/patches/solaris/si_value_2.3 ------------------------------ - + Subject: 02.11 How can I build MH on HP-UX? From: Bill Wohler Date: Sun, 8 Sep 1996 15:50:54 -0700 @@ -1407,7 +1407,7 @@ Date: Sun, 8 Sep 1996 15:50:54 -0700 See http://www.gw.com/mail/mh/patches/hp/ for for patches you may need. ------------------------------ - + Subject: 02.12 Can I prevent adding the local hostname to addresses behind firewalls? From: Ted Remillard @@ -1446,7 +1446,7 @@ Date: 18 Aug 1995 23:51:48 -0400 around line 613. ------------------------------ - + Subject: 02.13 Is there a patch to fix this or that? From: Kimmo Suominen Date: Sat, 3 Mar 2001 13:40:35 -0800 @@ -1476,7 +1476,7 @@ Date: Sat, 3 Mar 2001 13:40:35 -0800 gw.com>. ------------------------------ - + Subject: 02.14 How can I build MH on OS/2? From: Sanjay Aiyagari Date: 21 Nov 1996 19:37:10 GMT @@ -1484,7 +1484,7 @@ Date: 21 Nov 1996 19:37:10 GMT ftp://ftp.jaist.ac.jp/pub/os/os2/network/MH/ ------------------------------ - + Subject: 02.15 Do any POP/IMAP servers handle MH format? From: "Carl S. Gutekunst" Date: 27 May 1997 07:24:34 GMT @@ -1525,7 +1525,7 @@ Date: 11 Feb 2003 04:23:38 -0800 .mailboxlist file in your home directory. ------------------------------ - + Subject: 02.16 How can I build MH on Windows? From: Satyaki Das Date: Wed, 19 Jun 2002 20:57:19 -0700 @@ -1570,7 +1570,7 @@ Date: 25 May 1999 18:13:55 GMT If you have Windows, consider looking at VMware http://www.vmware.com/ - + which provides a virtual machine where you can run Unix and therefore MH under Windows. @@ -1580,11 +1580,11 @@ Date: 24 May 99 17:20:27 GMT The latest Cygnus Cygwin, GNU tools that run under Windows, http://www.cygwin.com/ - + seems to work pretty well and may well be able to build nmh. ------------------------------ - + Subject: !02.17 How can I build MH on a Mac? From: Dr Eberhard W Lisse Date: Sun, 05 Jun 2005 13:43:19 +0100 @@ -1633,7 +1633,7 @@ Date: 19 Jan 2000 23:01:10 -0800 I have submitted patches to nmh-workers. ------------------------------ - + Subject: 03.02 How would one go about reading Usenet with MH? From: Bill Wohler Date: Sun, 26 Nov 1995 12:32:09 -0800 @@ -1724,7 +1724,7 @@ Date: Tue, 1 Nov 1994 00:00:00 -0800 See mhunify in (see also "What other MH software is available?"). ------------------------------ - + Subject: 03.03 How can I search through multiple folders? From: Jerry Peek Date: Mon, 1 Mar 1993 00:00:00 -0800 @@ -1756,7 +1756,7 @@ Date: Mon, 1 Mar 1993 00:00:00 -0800 http://rand-mh.sourceforge.net/book/mh/usilin.html#AFoFuoLi ------------------------------ - + Subject: 03.04 Why don't MH format commands such as %(friendly) work? From: Anthony Baxter Date: Sun, 1 May 1994 00:00:00 -0800 @@ -1765,7 +1765,7 @@ Date: Sun, 1 May 1994 00:00:00 -0800 such as %(friendly). Recompile MH without the BERK option. ------------------------------ - + Subject: 03.05 Why doesn't "show" display all of a MIME message? From: Jerry Peek Date: Mon, 1 Aug 1994 00:00:00 -0800 @@ -1836,7 +1836,7 @@ Date: Tue, 1 Nov 1994 00:00:00 -0800 mhn-charset-iso-8859-1: /bin/sh -c '%s' # MH ------------------------------ - + Subject: 03.06 Can I get show not to run "less" so much on MIME messages? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -1862,7 +1862,7 @@ Date: Tue, 1 Nov 1994 00:00:00 -0800 http://rand-mh.sourceforge.net/book/mh/remime.html#Alttomhn ------------------------------ - + Subject: 03.07 Why do I get "mhn: don't know how to display content"? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -1876,13 +1876,13 @@ Date: Sun, 8 Sep 1996 15:49:50 -0700 if it doesn't know about foo. The patch: http://www.gw.com/mail/mh/patches/all/mhn_multipart - + tells it to treat such things as if they were multipart/mixed. (See also "Why doesn't "show" display all of a MIME message?"). ------------------------------ - + Subject: 03.08 How can I automatically delete MH backup files? From: mccammaa at expt05.stp.xfi.bp.com (Andy McCammont) Date: 22 May 1995 06:27:36 -0400 @@ -1898,7 +1898,7 @@ Date: 22 May 1995 06:27:36 -0400 5 5 * * * find /PATH/TO/HOME/Mail -name ",*" -mtime +5 -exec rm {} \; ------------------------------ - + Subject: 03.09 Fixing "cannot fopen and lock /var/spool/mail/(user)" From: Patrick.Wambacq at esat.kuleuven.ac.be Date: Mon, 30 Sep 96 15:00:16 +0200 @@ -1933,7 +1933,7 @@ Date: Mon, 9 Sep 1996 01:01:16 -0700 (See also "Why does inc hang (on Sun)?") ------------------------------ - + Subject: 03.10 Can I read my mail with a Web browser? From: Jerry Heyman Date: Sat, 09 Oct 2004 12:41:03 -0400 @@ -1984,7 +1984,7 @@ Date: 8 Sep 1995 16:36:03 GMT http://www.mhonarc.org/ ------------------------------ - + Subject: 03.11 How can I run inc automatically with POP? From: Bill Wohler Date: Mon, 27 Nov 1995 12:23:51 -0800 @@ -2016,7 +2016,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 other means (e.g., with SMTP). ------------------------------ - + Subject: 03.12 Why does inc hang (on Sun)? From: ericding at mit.edu (Eric J. Ding) Date: 30 Apr 1996 00:22:01 -0400 @@ -2026,7 +2026,7 @@ Date: 30 Apr 1996 00:22:01 -0400 so that MH uses dotfile locking rather than FLOCK or LOCKF. ------------------------------ - + Subject: 03.13 How can I get POP to work? From: Jonathan George Date: Tue, 23 Apr 1996 10:23:16 GMT @@ -2047,7 +2047,7 @@ Date: Tue, 23 Apr 1996 10:23:16 GMT Try running inc with -noapop -norpop flags. ------------------------------ - + Subject: 03.14 How do I persuade mhshow (mhn) not to bring up a new window? From: Joel Reicher Date: Tue, 13 Nov 2001 16:49:04 +1100 @@ -2068,13 +2068,13 @@ Date: 27 Mar 1996 16:53:39 -0600 mhn-charset-iso-8859-1: %s # MH ------------------------------ - + Subject: 03.15 How do I turn off of all the mhshow (mhn) prompts? From: Bill Wohler Date: Sun, 11 Mar 2001 11:33:10 -0800 In nmh, use mhshow -nopause. - + From: Larry Daffner Date: 27 Mar 1996 16:53:39 -0600 @@ -2086,7 +2086,7 @@ Date: 27 Mar 1996 16:53:39 -0600 worth reading. ------------------------------ - + Subject: 03.16 Why is inc splitting messages improperly? From: Mayank Choudhary Date: Mon, 29 Apr 1996 09:39:29 -0700 @@ -2095,15 +2095,15 @@ Date: Mon, 29 Apr 1996 09:39:29 -0700 is found within the body, inc splits the message. Add the following line to your .forward - + "|/usr/bin/mailcompat " - + where user-name is your login-id. See mailcompat(1) for more information. ------------------------------ - + Subject: 03.17 Can MH thread messages? From: "John W. Coomes" Date: 30 Apr 1997 13:02:10 -0500 @@ -2113,7 +2113,7 @@ Date: 30 Apr 1997 13:02:10 -0500 sortm -textfield subject ------------------------------ - + Subject: 03.18 How can I avoid reading the HTML version of the message? From: Bill Wohler Date: 23 Jun 2000 10:19:34 -0700 @@ -2131,7 +2131,7 @@ Date: 23 Jun 2000 10:19:34 -0700 able to view text/html at all, but you probably wouldn't care. ------------------------------ - + Subject: 03.19 How do I view or save attachments? From: Bill Wohler Date: Mon, 5 Mar 2001 09:12:15 -0800 @@ -2140,7 +2140,7 @@ Date: Mon, 5 Mar 2001 09:12:15 -0800 the man pages for more details. ------------------------------ - + Subject: 03.20 How do I view HTML attachments with Netscape? From: Bill Wohler Date: Mon, 5 Mar 2001 09:58:05 -0800 @@ -2156,7 +2156,7 @@ Date: Mon, 5 Mar 2001 09:58:05 -0800 M-w and go back to reading mail. ------------------------------ - + Subject: 03.21 Fixing folders: unable to allocate storage for msgstats From: Pete Phillips Date: 30 Jan 2003 03:33:57 -0800 @@ -2172,7 +2172,7 @@ Date: 30 Jan 2003 03:33:57 -0800 fixed the problem. ------------------------------ - + Subject: 03.22 How do I recursively list message attachments? From: Joel Reicher Date: 31 Oct 2001 00:36:14 +1100 @@ -2197,7 +2197,7 @@ Date: 31 Oct 2001 00:36:14 +1100 env MHSTORE=mhn.rec mhstore ------------------------------ - + Subject: 03.23 Why do folder and flist overlook some of my sub-folders? From: Richard Coleman Date: Mon, 10 Oct 2005 18:14:24 -0700 @@ -2228,7 +2228,7 @@ Date: Fri, 1 Jan 1993 00:00:00 -0800 Yes, see $MHLIB/packmbox. ------------------------------ - + Subject: 04.02 Can I append MH messages to a GNU Emacs rmail BABYL-format file? From: Bill Wohler Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -2258,7 +2258,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 MMDF to BABYL, since there may be really strange results. ------------------------------ - + Subject: 04.03 Why do I get ".../.mh_sequences is poorly formatted?" From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -2308,7 +2308,7 @@ Date: Mon, 1 Aug 1994 00:00:00 -0800 a quick-&-dirty way to write xargs(1) if you don't have it. ------------------------------ - + Subject: 04.04 How can you save News articles into an MH folder? From: Jerry Peek Date: Mon, 1 May 1995 00:00:00 -0800 @@ -2330,7 +2330,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 Of course, you can also put that in a little shell script. ------------------------------ - + Subject: !04.05 Are there any good tools to archive MH messages? From: Bill Wohler Date: Sun, 23 Sep 2007 18:35:53 -0700 @@ -2359,7 +2359,7 @@ Date: Sun, 4 Mar 2001 10:26:24 -0800 http://www.webglimpse.org/ ------------------------------ - + Subject: 04.06 How can I remove duplicate messages? From: Bill Wohler Date: Sun, 17 Oct 2004 13:04:57 -0700 @@ -2389,7 +2389,7 @@ Date: 20 Nov 1995 18:51:24 GMT not require that you first sort the folder. ------------------------------ - + Subject: 04.07 How can I remove holes in numbering? From: Bill Wohler @@ -2411,7 +2411,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 went away. ------------------------------ - + Subject: 05.02 How do I include messages in repl with or without ">"? From: Richard Coleman Date: Tue, 20 Jan 1998 02:19:58 -0500 @@ -2469,7 +2469,7 @@ Date: Fri, 1 Jan 1993 00:00:00 -0800 http://rand-mh.sourceforge.net/book/mh/verrep.html#IncRep ------------------------------ - + Subject: 05.03 How can I eliminate duplicate copies of letters to myself? From: Bill Wohler Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -2518,7 +2518,7 @@ Date: Fri, 24 Jan 1997 09:33:19 -0800 Alternate-Mailboxes: asriniva ------------------------------ - + Subject: 05.04 How can I include my signature? From: Eric W. Ziegast , Hardy Mayer @@ -2631,7 +2631,7 @@ Date: Tue, 1 Nov 1994 00:00:00 -0800 See also the Signature FAQ (see "What references exist for MH?"). ------------------------------ - + Subject: 05.05 How do I call my editor with arguments? From: John Romine Date: Mon, 1 May 1995 00:00:00 -0800 @@ -2649,7 +2649,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 different arguments depending on your EDITOR environment variable. ------------------------------ - + Subject: 05.06 How can I digestify messages in a folder for mail to another user? From: Jerry Peek , Bill Wohler Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -2684,7 +2684,7 @@ Date: Tue, 1 Nov 1994 00:00:00 -0800 works beautifully with MIME-capable mail readers, especially exmh. ------------------------------ - + Subject: 05.07 How can I change my return address? From: Bill Wohler Date: Tue, 1 Dec 1992 00:00:00 -0800 @@ -2700,7 +2700,7 @@ Date: Tue, 1 Dec 1992 00:00:00 -0800 Reply-To: jack@newt.com ------------------------------ - + Subject: 05.08 How can I change my From header? From: Bill Wohler Date: Mon, 27 Nov 1995 11:40:50 -0800 @@ -2733,7 +2733,7 @@ Date: Tue, 1 Dec 1992 00:00:00 -0800 thinks is your real address. ------------------------------ - + Subject: 05.09 How can I save a copy of all messages I send? From: Ping Huang Date: Mon, 18 Dec 1995 17:51:33 -0800 @@ -2782,7 +2782,7 @@ Date: 30 Oct 1995 10:23:55 -0500 as sendmail's--it doesn't include the date. ------------------------------ - + Subject: 05.10 Can the folder in Fcc: be dynamically specified? From: Andy Rabagliati Date: Mon, 1 Aug 1994 00:00:00 -0800 @@ -2796,7 +2796,7 @@ Date: Mon, 1 Aug 1994 00:00:00 -0800 for incoming and outgoing mail. ------------------------------ - + Subject: 05.11 Can I post secure/encryped mail? From: Bill Wohler Date: Thu, 19 May 2005 18:06:39 -0700 @@ -2868,7 +2868,7 @@ Date: Wed, 16 Apr 1997 00:06:59 -0700 for details. ------------------------------ - + Subject: 05.12 How can I send multi-media (MIME) attachments? From: Brian Exelbierd Date: Mon, 09 Oct 1995 08:05:55 -0400 @@ -2902,7 +2902,7 @@ Date: Mon, 09 Oct 1995 08:05:55 -0400 http://rand-mh.sourceforge.net/book/overall/tocs/intmime.html ------------------------------ - + Subject: 05.13 What's the best way to send mail to a long list of people? From: Bill Wohler Date: Thu, 12 Oct 1995 07:53:53 -0700 @@ -2935,7 +2935,7 @@ Date: Thu, 12 Oct 1995 07:53:53 -0700 (See "What is the Dcc header?") ------------------------------ - + Subject: 05.14 What is the Dcc header? From: jpeek at jpeek.com (Jerry Peek) Date: 14 Sep 96 05:51:13 GMT @@ -2950,7 +2950,7 @@ Date: 14 Sep 96 05:51:13 GMT field with some address (like yours) in it. I use a comment that tells people what's really happening--like this, more or less: - To: "Faculty members, c/o" + To: "Faculty members, c/o" dcc: faculty There are some other choices, like using an un-replyable group list @@ -2974,7 +2974,7 @@ From: John Romine (or worse). ------------------------------ - + Subject: 05.15 How can I make sense of the replcomps file? From: Bill Wohler Date: Thu, 9 Mar 2006 19:27:14 -0800 @@ -3050,7 +3050,7 @@ Date: Thu, 9 Mar 2006 19:27:14 -0800 Comments fields above. ------------------------------ - + Subject: 05.16 How can I convert quoted-printable to 8bit in quoted text in replies? From: Jarle F. Greipsland Date: 22 Aug 1995 10:42:07 +0200 @@ -3134,7 +3134,7 @@ Date: 22 Aug 1995 10:42:07 +0200 in the .mh_profile, isoextract exec's this editor. ------------------------------ - + Subject: 05.17 Can I have aliases include aliases? From: Bruce Cox Date: Fri, 16 Aug 1996 14:26:12 +1000 @@ -3163,7 +3163,7 @@ Date: Fri, 16 Aug 1996 14:26:12 +1000 presidents, authors ------------------------------ - + Subject: 05.18 Why doesn't mhmail understand aliases? From: "John L. Romine" Date: 25 Apr 1996 16:34:10 GMT @@ -3174,7 +3174,7 @@ Date: 25 Apr 1996 16:34:10 GMT them before passing them as arguments (e.g., "mhmail `ali joe`"). ------------------------------ - + Subject: 05.19 How do I send blind carbon copies? From: Bill Wohler Date: Mon, 9 Sep 1996 00:32:14 -0700 @@ -3198,7 +3198,7 @@ Date: Mon, 9 Sep 1996 00:32:14 -0700 inadvertently. Read the warning in (see "What is the Dcc header?"). ------------------------------ - + Subject: 05.20 When I forward a message, can I use its Subject? From: Jerry Peek Date: Sun, 17 Nov 1996 20:16:31 -0800 @@ -3208,7 +3208,7 @@ Date: Sun, 17 Nov 1996 20:16:31 -0800 http://rand-mh.sourceforge.net/book/examples/mh/bin/forwedit ------------------------------ - + Subject: 05.21 Why is the timezone field in my 'Date:' field wrong? From: Alex Tomlinson Date: Wed, 11 Jun 1997 09:16:41 -0500 @@ -3221,7 +3221,7 @@ Date: Wed, 11 Jun 1997 09:16:41 -0500 rebuild. ------------------------------ - + Subject: 05.22 Can I automate the comp -editor mhn process? From: Soren Dayton Date: Tue, 21 Jan 1997 17:23:32 GMT @@ -3233,7 +3233,7 @@ Date: Tue, 21 Jan 1997 17:23:32 GMT to your MH profile. ------------------------------ - + Subject: 05.23 How can I remove those "=20" characters when forwarding? From: Dave Marquardt Date: 12 Oct 2000 10:27:38 -0500 @@ -3241,7 +3241,7 @@ Date: 12 Oct 2000 10:27:38 -0500 Use `forw -mime'. ------------------------------ - + Subject: 05.24 Can I use mh-format substitution with forw? From: Dave Marquardt Date: Tue, 3 Aug 1999 13:28:30 -0500 (EST) @@ -3249,7 +3249,7 @@ Date: Tue, 3 Aug 1999 13:28:30 -0500 (EST) The answer is no, and the real question is why not? ------------------------------ - + Subject: 05.25 How can I keep repl from breaking long lines? From: Jerry Peek Date: Fri, 14 May 1999 11:15:07 -0400 @@ -3302,7 +3302,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 Then complain to your vendor that "vi" is broken, and they shouldfix it. ------------------------------ - + Subject: 06.02 Can I run my message through a program (e.g., ispell) before sending? From: Jerry Peek Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -3338,7 +3338,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 http://rand-mh.sourceforge.net/book/mh/chaedi.html#Edi ------------------------------ - + Subject: 06.03 What to do with "bad address 'xxx' - no at-sign after local-part". From: Owen Rees Date: Fri, 1 Jan 1993 00:00:00 -0800 @@ -3357,7 +3357,7 @@ Date: Fri, 1 Jan 1993 00:00:00 -0800 (Mr. Foo Bar) fb@somewhere.edu ------------------------------ - + Subject: 06.04 Fixing "post: problem initializing server; [BHST] no servers available" From: Peter Marvit , Eric Bracken @@ -3408,9 +3408,9 @@ Date: Sun, 02 Sep 2001 02:13:42 -0400 Solution: Try specifying the path explicitly by adding a line to mts.conf thus: - + sendmail: /usr/sbin/sendmail - + or wherever your sendmail daemon executable lives. From: Neil W Rickert @@ -3426,7 +3426,7 @@ Date: 13 Apr 2001 18:47:43 -0500 command line sendmail. ------------------------------ - + Subject: 06.05 Fixing "post: problem initializing server; [RPLY] 503 Sender already specified" From: Paul Pomes Date: Mon, 1 Mar 1993 00:00:00 -0800 @@ -3440,7 +3440,7 @@ Date: Mon, 1 Mar 1993 00:00:00 -0800 MH sources to not use the ONEX verb. ------------------------------ - + Subject: 06.06 Fixing "post: unexpected response; [BHST] no socket opened" From: Steve Lembark , Bill Wohler Date: Mon, 1 Aug 1994 00:00:00 -0800 @@ -3505,7 +3505,7 @@ Date: Mon, 1 Aug 1994 00:00:00 -0800 solutions seem to be the most prevalent. ------------------------------ - + Subject: 06.07 How do I fix the "X-Authentication-Warning" header? From: Bill Wohler Date: Mon, 9 Sep 1996 01:32:15 -0700 @@ -3513,7 +3513,7 @@ Date: Mon, 9 Sep 1996 01:32:15 -0700 (See "Fixing "Sender didn't use the HELO protocol"".) ------------------------------ - + Subject: 06.08 Fixing "post: unexpected response; [RPLY] 503 Need MAIL before RCPT" From: Bjoern Stabell Date: Mon, 1 May 1995 00:00:00 -0800 @@ -3525,7 +3525,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 in the $MHLIB/mts.conf (mtstailor) file, and that fixed the problem. ------------------------------ - + Subject: 06.09 Fixing "post: problem initializing server; [BHST] premature end-of-file on socket" From: Ginko Date: Thu, 8 Mar 2001 09:18:14 +0000 (UTC) @@ -3551,7 +3551,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 ". ------------------------------ - + Subject: 06.10 Fixing "Sender didn't use the HELO protocol" From: rickert at cs.niu.edu (Neil Rickert) Date: Tue, 20 Mar 2001 22:01:16 -0800 @@ -3605,7 +3605,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 in your sendmail.cf. ------------------------------ - + Subject: 06.11 Fixing "post: problem initializing server; [RPLY] 553 Local configuration error, hostname not recognized as local" From: "Matthew V. J. Whalen" Date: Mon, 1 May 1995 00:00:00 -0800 @@ -3726,7 +3726,7 @@ Date: Tue, 28 Jul 1998 13:22:07 +0200 http://www.cpan.org/authors/Raphael_Manfredi/ ------------------------------ - + Subject: 07.02 Why slocal writes messages to system mailbox that from(1) can't read. From: Bill Wohler Date: Mon, 1 May 1995 00:00:00 -0800 @@ -3735,7 +3735,7 @@ Date: Mon, 1 May 1995 00:00:00 -0800 MH-like command instead of from: "scan -file $MAIL". ------------------------------ - + Subject: 07.03 Where can I read about slocal and the format of .maildelivery? From: Bill Wohler Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -3768,7 +3768,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 (See "What mail filters are available?") ------------------------------ - + Subject: 07.04 How do I debug my .maildelivery file? From: Bill Wohler Date: Mon, 1 Mar 1993 00:00:00 -0800 @@ -3796,7 +3796,7 @@ Date: Mon, 1 Mar 1993 00:00:00 -0800 http://rand-mh.sourceforge.net/book/mh/debugti.html ------------------------------ - + Subject: 07.05 Why isn't slocal working? From: Bill Wohler Date: Mon, 1 Mar 1993 00:00:00 -0800 @@ -3816,7 +3816,7 @@ Date: Mon, 1 Mar 1993 00:00:00 -0800 See also "How do I debug my .maildelivery file?" ------------------------------ - + Subject: 07.06 Are there any good biff applications for MH? From: Rob Austein Date: Tue, 01 Dec 1998 03:02:34 -0500 @@ -3846,7 +3846,7 @@ Date: 7 Jul 97 09:36:32 GMT character for readability. ------------------------------ - + Subject: 07.07 How do I read new messages filed by procmail? From: Bill Wohler Date: Sun, 17 Oct 2004 15:17:14 -0700 @@ -3948,7 +3948,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 in the Appendix "Switching xmh's editor". ------------------------------ - + Subject: 09.02 Does xmh support subfolders? From: Steve Malowany Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -3973,7 +3973,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 http://rand-mh.sourceforge.net/book/xmh/orgfol.html#FolaSub ------------------------------ - + Subject: 09.03 How do I precede included messages with ">" when replying in xmh? From: Len Makin Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -4018,7 +4018,7 @@ Date: Wed, 29 Sep 2004 00:04:34 -0700 SMTP Simple Mail Transport Protocol (STD 10; RFC 821) ------------------------------ - + Subject: Acknowledgments From: Bill Wohler Date: Mon, 9 Sep 1996 01:37:27 -0700 @@ -4046,7 +4046,7 @@ Suominen for maintaining the MH patch page, and Richard Coleman for taking MH to nmh. ------------------------------ - + Subject: Switching xmh's editor From: Andrew Wason Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -4238,7 +4238,7 @@ echo shar: End of shell archive. exit 0 ------------------------------ - + Subject: babyl2mh.pl From: Vivek Khera Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -4287,7 +4287,7 @@ while () { } ------------------------------ - + Subject: inco - babyl to MH converter From: Juergen Nickelsen Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -4329,7 +4329,7 @@ inc -file $tmpmbox $folder rm -f $lispfile $tmpmbox ------------------------------ - + Subject: t2h - add hyperlinks to message viewed From: TANAKA Tomoyuki Date: Mon, 13 Sep 1999 11:35:43 -0600 @@ -4355,7 +4355,7 @@ $a\ ------------------------------ - + Subject: srvrsmtp.c patch From: Paul Pomes Date: Fri, 1 Mar 1991 13:03:15 -0800 @@ -4381,7 +4381,7 @@ Date: Fri, 1 Mar 1991 13:03:15 -0800 case CMDVRFY: /* vrfy -- verify address */ ------------------------------ - + Subject: IRIX config file From: Jack Repenning Date: 25 Jul 1995 02:35:41 GMT @@ -4449,7 +4449,7 @@ options MSGPROT='"0600"' RPATHS SENDMTS SGI SMTP SOCKETS SYS5 options TYPESIG="void" ncr MIME VSPRINTF UNISTD SYSVR4 SYS5DIR ------------------------------ - + Subject: HP-UX 10.20 config file From: Marko Heikkinen Date: 06 Jan 1997 17:19:07 +0000 @@ -4470,7 +4470,7 @@ mts sendmail/smtp pop off slibdir: /opt/mail/lib options SYS5 -options MHE +options MHE options MIME options ATZ options BIND @@ -4525,7 +4525,7 @@ Date: 20 Nov 1995 18:51:24 GMT gets too big, your system may complain. And I'm sure there are some more-efficient ways to find the list of duplicate message-ids. But that's the idea. - + Subject: Removing duplicate messages (Perl) From: rtor at ansa.co.uk (Owen Rees) Date: 20 Nov 1995 12:39:47 GMT @@ -4567,7 +4567,7 @@ Date: Sun, 17 Oct 2004 13:00:20 -0700 #!/usr/bin/perl -w # -# Id: mhfinddup 6593 2004-09-02 16:34:24Z wohler +# Id: mhfinddup 6593 2004-09-02 16:34:24Z wohler =head1 NAME @@ -4666,7 +4666,7 @@ B(1), B(1), B(1) =head1 VERSION -Revision: 6593 +Revision: 6593 =head1 AUTHOR diff --git a/docs/MAILING-LISTS b/docs/MAILING-LISTS index 66d49a9..767291c 100644 --- a/docs/MAILING-LISTS +++ b/docs/MAILING-LISTS @@ -3,7 +3,7 @@ There are currently three mailing lists related to nmh: nmh-announce@mhost.com ---------------------- This is a very low-traffic mailing list for announcing new releases, -patches, and important events related to nmh. +patches, and important events related to nmh. nmh-bugs@mhost.com ------------------ @@ -13,7 +13,7 @@ prevent being spammed. Any nmh-related mail is approved. nmh-workers@mhost.com --------------------- This is the main list for discussing work on nmh. Both of the above -mailing lists are forwarded to this one. There is currently no +mailing lists are forwarded to this one. There is currently no nmh-users mailing list, so user questions are acceptable here (the comp.mail.mh newsgroup is another good option). @@ -26,7 +26,7 @@ email addresses by spammers. To access the archives, you need to send mail to nmh-workers-request with an archive access command. You can get a current list of commands the archive server understands by sending a message to nmh-workers-request@mhost.com with the subject -"archive help". +"archive help". Of interest in the archive are the directories "latest" which contains everything since the nmh-workers mailing list has been hosted on diff --git a/docs/Makefile.in b/docs/Makefile.in index 695bdf0..38db87e 100644 --- a/docs/Makefile.in +++ b/docs/Makefile.in @@ -50,9 +50,9 @@ subdir = docs Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) -nmhdist: +nmhdist: @echo "Copying distribution files in $(subdir)" @for file in $(DIST); do \ cp -p $(srcdir)/$$file $(distdir); \ diff --git a/docs/README-HOOKS b/docs/README-HOOKS index 83b6bf7..714ba00 100644 --- a/docs/README-HOOKS +++ b/docs/README-HOOKS @@ -43,7 +43,7 @@ ref-hook: This is the full pathname of a program that is invoked message file, the second is the full pathname of the final message file. The program is executed after the message is written. - + msg-hook: This is a text message that is output if the execution of one of the external hook programs fails. There is a built-in default message if none is specified. diff --git a/docs/README.about b/docs/README.about index eba3004..41f4482 100644 --- a/docs/README.about +++ b/docs/README.about @@ -11,9 +11,9 @@ a (mostly) compatible drop-in replacement for MH. If you have previously used MH, check the file DIFFERENCES for a list of the differences between nmh and MH (not up-to-date as of this writing). -Although development of nmh is ongoing, it is generally stable and -is in current use. But it is possible that we may break things as -changes are made. +Although development of nmh is ongoing, it is generally stable and +is in current use. But it is possible that we may break things as +changes are made. -------------------------------- ftp and web sites, mailing lists diff --git a/docs/README.developers b/docs/README.developers index 8b3da50..de32185 100644 --- a/docs/README.developers +++ b/docs/README.developers @@ -38,7 +38,7 @@ directory structure Following is a list of nmh's directories along with a brief description of the purpose of each one. Meanings are given for the abbreviations, but note that these meanings are just informed guesses as to what the MH developers were -thinking. +thinking. ./ The top-level directory. Contains files like README and INSTALL. @@ -67,7 +67,7 @@ sbr/ "sbr" stands for "subroutine(s)". For the most part, each source file in this directory contains a single function with the same name as the source file. These functions are of general use and are called from throughout - nmh. + nmh. uip/ "uip" stands for "User Interface Programs". Most nmh commands have a file @@ -97,7 +97,7 @@ For some system functions whose availability or behavior varies from OS to OS, nmh conditionally uses a local definition with the same name as the OS function (e.g. snprintf()). For other functions, developers need to avoid the OS versions and always use the nmh-supplied function. Here is a list of such -functions: +functions: OS function nmh-local version to use instead =========== ================================ diff --git a/docs/README.manpages b/docs/README.manpages index c4dc67b..90451b9 100644 --- a/docs/README.manpages +++ b/docs/README.manpages @@ -10,7 +10,7 @@ nmh manpages should be in this general form: comp \- compose a message .SH SYNOPSIS .HP 5 -.B comp +.B comp .RI [ +folder ] .RI [ msgs ] .RB [ \-form diff --git a/etc/MailAliases b/etc/MailAliases index 5037a54..e8455db 100644 --- a/etc/MailAliases +++ b/etc/MailAliases @@ -11,15 +11,15 @@ ; everyone: * ; Blank lines and lines beginning with a ; are ignored. -; < file -> read more aliases from "file" +; < file -> read more aliases from "file" ; foo: fum -> simple replacement ; foo: fum, fie -> list replacement ; foo: < file -> list replacement from "file" ; foo: = group -> list replacement from UNIX group ; foo: + group -> list replacement by ALL users in /etc/passwd -; with gid == group +; with gid == group ; foo: * -> list replacement by ALL users in /etc/passwd -; with uid >= 200 +; with uid >= 200 ; foo*: fum -> matches foo (including the empty string) ; ; using a ';' instead of a ':' indicates that the alias should be displayed diff --git a/etc/Makefile.in b/etc/Makefile.in index faefd09..c326577 100644 --- a/etc/Makefile.in +++ b/etc/Makefile.in @@ -35,12 +35,12 @@ SED = sed .SUFFIXES: # static configuration, format, and components files -STATIC_FILES = MailAliases components digestcomps distcomps forwcomps \ - mhl.body mhl.digest mhl.format mhl.forward mhl.headers \ - mhl.reply rcvdistcomps rcvdistcomps.outbox \ - replcomps replgroupcomps scan.MMDDYY scan.YYYYMMDD \ - scan.default scan.mailx scan.nomime scan.size scan.time \ - scan.timely scan.unseen +STATIC_FILES = MailAliases components digestcomps distcomps forwcomps \ + mhl.body mhl.digest mhl.format mhl.forward mhl.headers \ + mhl.reply rcvdistcomps rcvdistcomps.outbox \ + replcomps replgroupcomps scan.MMDDYY scan.YYYYMMDD \ + scan.default scan.mailx scan.nomime scan.size scan.time \ + scan.timely scan.unseen # templates and scripts from which non-static files are generated GENERATED_FILE_SRCS = mhn.defaults.sh mhn.find.sh mts.conf.in sendfiles.in @@ -139,11 +139,10 @@ subdir = etc Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) nmhdist: $(DIST) @echo "Copying distribution files in $(subdir)" @for file in $(DIST); do \ cp -p $(srcdir)/$$file $(distdir); \ done - diff --git a/etc/digestcomps b/etc/digestcomps index 7f5036d..29d732d 100644 --- a/etc/digestcomps +++ b/etc/digestcomps @@ -1,9 +1,9 @@ -From: %{digest}-Request -To: %{digest} Distribution: dist-%{digest}; +From: %{digest}-Request +To: %{digest} Distribution: dist-%{digest}; Subject: %{digest} Digest V%(cur) #%(msg) Reply-To: %{digest} -------- -%{digest} Digest %(weekday{date}), %2(mday{date}) %(month{date}) %(year{date}) - Volume %(cur) : Issue %(msg) +%{digest} Digest %(weekday{date}), %2(mday{date}) %(month{date}) %(year{date}) + Volume %(cur) : Issue %(msg) Today's Topics: diff --git a/etc/mhn.defaults.sh b/etc/mhn.defaults.sh index 0db5d3a..1c798fc 100755 --- a/etc/mhn.defaults.sh +++ b/etc/mhn.defaults.sh @@ -56,72 +56,72 @@ elif [ ! -z $"PBM" -a ! -z "$XWUD" ]; then PGM="`$SEARCHPROG $SEARCHPATH djpeg`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-image/jpeg: %p$PGM -Pg | ${PBMDIR}ppmtopgm | ${PBMDIR}pgmtopbm | ${PBMDIR}pbmtoxwd | $XWUD -geometry =-0+0" >> $TMP + echo "mhshow-show-image/jpeg: %p$PGM -Pg | ${PBMDIR}ppmtopgm | ${PBMDIR}pgmtopbm | ${PBMDIR}pbmtoxwd | $XWUD -geometry =-0+0" >> $TMP fi fi if [ -f "/dev/audioIU" ]; then PGM="`$SEARCHPROG $SEARCHPATH recorder`" if [ ! -z "$PGM" ]; then - echo "mhstore-store-audio/basic: %m%P.au" >> $TMP + echo "mhstore-store-audio/basic: %m%P.au" >> $TMP echo "mhbuild-compose-audio/basic: ${AUDIODIR}recorder '%f' -au -pause > /dev/tty" >> $TMP echo "mhshow-show-audio/basic: %p${AUDIODIR}splayer -au" >> $TMP fi elif [ -f "/dev/audio" ]; then PGM="`$SEARCHPROG $SEARCHPATH raw2audio`" if [ ! -z "$PGM" ]; then - AUDIODIR="`echo $PGM | awk -F/ '{ for(i=2;i %m%P.au" >> $TMP + AUDIODIR="`echo $PGM | awk -F/ '{ for(i=2;i %m%P.au" >> $TMP echo "mhstore-store-audio/x-next: %m%P.au" >> $TMP - AUDIOTOOL="`$SEARCHPROG $SEARCHPATH audiotool`" - if [ ! -z "$AUDIOTOOL" ]; then - echo "mhbuild-compose-audio/basic: $AUDIOTOOL '%f' && ${AUDIODIR}raw2audio -F < '%f'" >> $TMP - else - echo "mhbuild-compose-audio/basic: trap \"exit 0\" 2 && ${AUDIODIR}record | ${AUDIODIR}raw2audio -F" >> $TMP - fi - echo "mhshow-show-audio/basic: %p${AUDIODIR}raw2audio 2>/dev/null | ${AUDIODIR}play" >> $TMP - - PGM="`$SEARCHPROG $SEARCHPATH adpcm_enc`" - if [ ! -z "$PGM" ]; then - DIR="`echo $PGM | awk -F/ '{ for(i=2;i> $TMP - else - echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record | ${DIR}adpcm_enc" >> $TMP - fi - echo "mhshow-show-audio/x-next: %p${DIR}adpcm_dec | ${AUDIODIR}play" >> $TMP - else - if [ ! -z "$AUDIOTOOL" ]; then - echo "mhbuild-compose-audio/x-next: $AUDIOTOOL '%f'" >> $TMP - else - echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record" >> $TMP - fi - echo "mhshow-show-audio/x-next: %p${AUDIODIR}play" >> $TMP - fi + AUDIOTOOL="`$SEARCHPROG $SEARCHPATH audiotool`" + if [ ! -z "$AUDIOTOOL" ]; then + echo "mhbuild-compose-audio/basic: $AUDIOTOOL '%f' && ${AUDIODIR}raw2audio -F < '%f'" >> $TMP + else + echo "mhbuild-compose-audio/basic: trap \"exit 0\" 2 && ${AUDIODIR}record | ${AUDIODIR}raw2audio -F" >> $TMP + fi + echo "mhshow-show-audio/basic: %p${AUDIODIR}raw2audio 2>/dev/null | ${AUDIODIR}play" >> $TMP + + PGM="`$SEARCHPROG $SEARCHPATH adpcm_enc`" + if [ ! -z "$PGM" ]; then + DIR="`echo $PGM | awk -F/ '{ for(i=2;i> $TMP + else + echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record | ${DIR}adpcm_enc" >> $TMP + fi + echo "mhshow-show-audio/x-next: %p${DIR}adpcm_dec | ${AUDIODIR}play" >> $TMP + else + if [ ! -z "$AUDIOTOOL" ]; then + echo "mhbuild-compose-audio/x-next: $AUDIOTOOL '%f'" >> $TMP + else + echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record" >> $TMP + fi + echo "mhshow-show-audio/x-next: %p${AUDIODIR}play" >> $TMP + fi else - echo "mhbuild-compose-audio/basic: cat < /dev/audio" >> $TMP + echo "mhbuild-compose-audio/basic: cat < /dev/audio" >> $TMP echo "mhshow-show-audio/basic: %pcat > /dev/audio" >> $TMP fi fi PGM="`$SEARCHPROG $SEARCHPATH mpeg_play`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-video/mpeg: %p$PGM '%f'" >> $TMP + echo "mhshow-show-video/mpeg: %p$PGM '%f'" >> $TMP fi PGM="`$SEARCHPROG $SEARCHPATH lpr`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-application/PostScript: %plpr -Pps" >> $TMP + echo "mhshow-show-application/PostScript: %plpr -Pps" >> $TMP else PGM="`$SEARCHPROG $SEARCHPATH lp`" - if [ ! -z "$PGM" ]; then - echo "mhshow-show-application/PostScript: %plp -dps" >> $TMP + if [ ! -z "$PGM" ]; then + echo "mhshow-show-application/PostScript: %plp -dps" >> $TMP fi fi PGM="`$SEARCHPROG $SEARCHPATH ivs_replay`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-application/x-ivs: %p$PGM -o '%F'" >> $TMP + echo "mhshow-show-application/x-ivs: %p$PGM -o '%F'" >> $TMP fi echo "mhshow-suffix-text/html: .html" >> $TMP @@ -132,24 +132,24 @@ echo "mhshow-suffix-text/html: .html" >> $TMP # that another netscape is already running and certain things can't be done). PGM="`$SEARCHPROG $SEARCHPATH lynx`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-text/html: %p$PGM '%F'" >> $TMP + echo "mhshow-show-text/html: %p$PGM '%F'" >> $TMP fi PGM="`$SEARCHPROG $SEARCHPATH richtext`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-text/richtext: %p$PGM -p '%F'" >> $TMP + echo "mhshow-show-text/richtext: %p$PGM -p '%F'" >> $TMP else PGM="`$SEARCHPROG $SEARCHPATH rt2raw`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-text/richtext: %p$PGM < '%f' | fmt -78 | more" >> $TMP + echo "mhshow-show-text/richtext: %p$PGM < '%f' | fmt -78 | more" >> $TMP fi fi # staroffice to read .doc files PGM="`$SEARCHPROG $SEARCHPATH soffice`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-application/msword: %psoffice '%F'" >> $TMP - echo "mhshow-suffix-application/msword: .doc" >> $TMP + echo "mhshow-show-application/msword: %psoffice '%F'" >> $TMP + echo "mhshow-suffix-application/msword: .doc" >> $TMP fi # output a sorted version of the file @@ -165,8 +165,8 @@ if [ "$DISPLAY" = "unix:0.0" -a ! -z "$PGM" ]; then else PGM="`$SEARCHPROG $SEARCHPATH gs`" if [ ! -z "$PGM" ]; then - echo "mhshow-show-application/PostScript: %p$PGM -- '%F'" >> $TMP - echo "mhshow-suffix-application/PostScript: .ps" >> $TMP + echo "mhshow-show-application/PostScript: %p$PGM -- '%F'" >> $TMP + echo "mhshow-suffix-application/PostScript: .ps" >> $TMP fi fi @@ -174,5 +174,5 @@ fi PGM="`$SEARCHPROG $SEARCHPATH ivs_record`" if [ ! -z "$PGM" ]; then - echo "mhbuild-compose-application/x-ivs: $PGM -u localhost '%F'" >> $TMP + echo "mhbuild-compose-application/x-ivs: $PGM -u localhost '%F'" >> $TMP fi diff --git a/etc/mhn.find.sh b/etc/mhn.find.sh index 3e5e98a..4b4230d 100755 --- a/etc/mhn.find.sh +++ b/etc/mhn.find.sh @@ -19,20 +19,20 @@ for A in $SEARCHPATH; do # skip the directories `.' and `..' if test "$A" = "." -o "$A" = ".."; then - continue + continue fi # if program was found in /usr/local/bin, then # just echo program name, else echo full pathname if test -f "$A/$PROGRAM"; then - if test "$A" = "/usr/local/bin"; then - PGM="$PROGRAM" - else - PGM="$A/$PROGRAM" - fi - - echo "$PGM" - exit 0 + if test "$A" = "/usr/local/bin"; then + PGM="$PROGRAM" + else + PGM="$A/$PROGRAM" + fi + + echo "$PGM" + exit 0 fi done IFS="$oIFS" diff --git a/etc/mts.conf.in b/etc/mts.conf.in index b86878b..c5fd01c 100644 --- a/etc/mts.conf.in +++ b/etc/mts.conf.in @@ -1,6 +1,6 @@ # # nmh mail transport interface customization file. -# +# # Check the mh-tailor(5) man page for a list of # all the available options for this file. # diff --git a/etc/sendfiles.in b/etc/sendfiles.in index 85ec6f0..a3545d1 100755 --- a/etc/sendfiles.in +++ b/etc/sendfiles.in @@ -27,20 +27,25 @@ fi # handle command-line options to override compression method and delay while [ $# -gt 3 ]; do case "$1" in - -gzip) METHOD=gzip - shift - ;; - -compress) METHOD=compress - shift - ;; - -none) METHOD=none - shift - ;; - -*) DELAY="`echo $1 | sed -e 's%-%%'`" - shift - ;; - *) break - ;; + -gzip) + METHOD=gzip + shift + ;; + -compress) + METHOD=compress + shift + ;; + -none) + METHOD=none + shift + ;; + -*) + DELAY="`echo $1 | sed -e 's%-%%'`" + shift + ;; + *) + break + ;; esac done @@ -76,7 +81,7 @@ echo "files = $*" 1>&2 tar cvf - "$@" | $COMPRESS | \ %libdir%/viamail -to "$mailpath" -subject "$subject" \ - -parameters "type=tar$CONVERSION" \ - -comment "extract with $UNCOMPRESS | tar xvpf -" \ - -delay "$DELAY" \ - -verbose $FROM + -parameters "type=tar$CONVERSION" \ + -comment "extract with $UNCOMPRESS | tar xvpf -" \ + -delay "$DELAY" \ + -verbose $FROM diff --git a/h/Makefile.in b/h/Makefile.in index d40a92b..dbf540e 100644 --- a/h/Makefile.in +++ b/h/Makefile.in @@ -8,10 +8,10 @@ srcdir = @srcdir@ VPATH = @srcdir@ # header files included in distribution -HDRS = addrsbr.h aliasbr.h crawl_folders.h dropsbr.h fmt_compile.h fmt_scan.h \ - md5.h mf.h mh.h mhcachesbr.h mhparse.h mime.h mts.h \ - netdb.h nmh.h picksbr.h popsbr.h prototypes.h rcvmail.h \ - scansbr.h signals.h tws.h utils.h +HDRS = addrsbr.h aliasbr.h crawl_folders.h dropsbr.h fmt_compile.h \ + fmt_scan.h md5.h mf.h mh.h mhcachesbr.h mhparse.h mime.h mts.h \ + netdb.h nmh.h picksbr.h popsbr.h prototypes.h rcvmail.h \ + scansbr.h signals.h tws.h utils.h # auxiliary files AUX = Makefile.in @@ -49,11 +49,10 @@ subdir = h Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) nmhdist: $(DIST) @echo "Copying distribution files in $(subdir)" @for file in $(DIST); do \ cp -p $(srcdir)/$$file $(distdir); \ done - diff --git a/h/addrsbr.h b/h/addrsbr.h index a6c7a41..9aaabd5 100644 --- a/h/addrsbr.h +++ b/h/addrsbr.h @@ -1,33 +1,32 @@ - /* * addrsbr.h -- definitions for the address parsing system */ -#define AD_HOST 1 /* getm(): lookup official hostname */ -#define AD_NHST 0 /* getm(): do not lookup official name */ -#define AD_NAME AD_NHST /* AD_HOST is TOO slow */ +#define AD_HOST 1 /* getm(): lookup official hostname */ +#define AD_NHST 0 /* getm(): do not lookup official name */ +#define AD_NAME AD_NHST /* AD_HOST is TOO slow */ -#define UUCPHOST (-1) -#define LOCALHOST 0 -#define NETHOST 1 -#define BADHOST 2 +#define UUCPHOST (-1) +#define LOCALHOST 0 +#define NETHOST 1 +#define BADHOST 2 struct mailname { - struct mailname *m_next; - char *m_text; - char *m_pers; - char *m_mbox; - char *m_host; - char *m_path; - int m_type; - char m_nohost; - char m_bcc; - int m_ingrp; - char *m_gname; - char *m_note; + struct mailname *m_next; + char *m_text; + char *m_pers; + char *m_mbox; + char *m_host; + char *m_path; + int m_type; + char m_nohost; + char m_bcc; + int m_ingrp; + char *m_gname; + char *m_note; }; -#define adrformat(m) auxformat ((m), 1) +#define adrformat(m) auxformat ((m), 1) /* * prototypes diff --git a/h/aliasbr.h b/h/aliasbr.h index cc4da7f..aa38c42 100644 --- a/h/aliasbr.h +++ b/h/aliasbr.h @@ -1,38 +1,36 @@ - /* * aliasbr.h -- definitions for the aliasing system - * */ -extern char *AliasFile; /* mh-alias(5) */ -#define PASSWD "/etc/passwd" /* passwd(5) */ -#define GROUP "/etc/group" /* group(5) */ -#define EVERYONE 200 /* lowest uid for everyone */ +extern char *AliasFile; /* mh-alias(5) */ +#define PASSWD "/etc/passwd" /* passwd(5) */ +#define GROUP "/etc/group" /* group(5) */ +#define EVERYONE 200 /* lowest uid for everyone */ struct aka { - char *ak_name; /* name to match against */ - struct adr *ak_addr; /* list of addresses that it maps to */ - struct aka *ak_next; /* next aka in list */ - char ak_visible; /* should be visible in headers */ + char *ak_name; /* name to match against */ + struct adr *ak_addr; /* list of addresses that it maps to */ + struct aka *ak_next; /* next aka in list */ + char ak_visible; /* should be visible in headers */ }; struct adr { - char *ad_text; /* text of this address in list */ - struct adr *ad_next; /* next adr in list */ - char ad_local; /* text is local (check for expansion) */ + char *ad_text; /* text of this address in list */ + struct adr *ad_next; /* next adr in list */ + char ad_local; /* text is local (check for expansion) */ }; /* * incore version of /etc/passwd */ struct home { - char *h_name; /* user name */ - uid_t h_uid; /* user id */ - gid_t h_gid; /* user's group */ - char *h_home; /* user's home directory */ - char *h_shell; /* user's shell */ - int h_ngrps; /* number of groups this user belongs to */ - struct home *h_next; /* next home in list */ + char *h_name; /* user name */ + uid_t h_uid; /* user id */ + gid_t h_gid; /* user's group */ + char *h_home; /* user's home directory */ + char *h_shell; /* user's shell */ + int h_ngrps; /* number of groups this user belongs to */ + struct home *h_next; /* next home in list */ }; struct home *seek_home (char *); @@ -49,11 +47,11 @@ char *akerror (int); /* codes returned by alias() */ -#define AK_OK 0 /* file parsed ok */ -#define AK_NOFILE 1 /* couldn't read file */ -#define AK_ERROR 2 /* error parsing file */ -#define AK_LIMIT 3 /* memory limit exceeded */ -#define AK_NOGROUP 4 /* no such group */ +#define AK_OK 0 /* file parsed ok */ +#define AK_NOFILE 1 /* couldn't read file */ +#define AK_ERROR 2 /* error parsing file */ +#define AK_LIMIT 3 /* memory limit exceeded */ +#define AK_NOGROUP 4 /* no such group */ /* should live here, not in mts.c */ diff --git a/h/crawl_folders.h b/h/crawl_folders.h index 51fc882..a5ac7b4 100644 --- a/h/crawl_folders.h +++ b/h/crawl_folders.h @@ -1,4 +1,3 @@ - /* * crawl_folders.h -- crawl folder hierarchy */ diff --git a/h/dropsbr.h b/h/dropsbr.h index 5a84ae1..c261541 100644 --- a/h/dropsbr.h +++ b/h/dropsbr.h @@ -1,4 +1,3 @@ - /* * dropsbr.h -- definitions for maildrop-style files */ @@ -9,16 +8,16 @@ * of such an map is special, it contains: * * d_id = number of messages in file - * d_size = version number of map + * d_size = version number of map * d_start = last message read * d_stop = size of file * * Each record after that contains: * - * d_id = BBoard-ID: of message, or similar info - * d_size = size of message in ARPA Internet octets (\n == 2 octets) - * d_start = starting position of message in file - * d_stop = stopping position of message in file + * d_id = BBoard-ID: of message, or similar info + * d_size = size of message in ARPA Internet octets (\n == 2 octets) + * d_start = starting position of message in file + * d_stop = stopping position of message in file * * Note that d_start/d_stop do NOT include the message delimiters, so * programs using the map can simply fseek to d_start and keep reading @@ -32,13 +31,13 @@ #define MBOX_FORMAT 1 #define MMDF_FORMAT 2 -#define DRVRSN 3 +#define DRVRSN 3 struct drop { - int d_id; - int d_size; - off_t d_start; - off_t d_stop; + int d_id; + int d_size; + off_t d_start; + off_t d_stop; }; /* @@ -54,4 +53,3 @@ char *map_name (char *); int map_read (char *, long, struct drop **, int); int map_write (char *, int, int, long, off_t, off_t, long, int, int); int map_chk (char *, int, struct drop *, long, int); - diff --git a/h/fmt_compile.h b/h/fmt_compile.h index 22be450..f3b2b9b 100644 --- a/h/fmt_compile.h +++ b/h/fmt_compile.h @@ -1,108 +1,108 @@ - /* * fmt_compile.h -- format types */ /* types that output text */ -#define FT_COMP 1 /* the text of a component */ -#define FT_COMPF 2 /* comp text, filled */ -#define FT_LIT 3 /* literal text */ -#define FT_LITF 4 /* literal text, filled */ -#define FT_CHAR 5 /* a single ascii character */ -#define FT_NUM 6 /* "value" as decimal number */ -#define FT_NUMF 7 /* "value" as filled dec number */ -#define FT_STR 8 /* "str" as text */ -#define FT_STRF 9 /* "str" as text, filled */ -#define FT_STRFW 10 /* "str" as text, filled, width in "value" */ -#define FT_PUTADDR 11 /* split and print address line */ +#define FT_COMP 1 /* the text of a component */ +#define FT_COMPF 2 /* comp text, filled */ +#define FT_LIT 3 /* literal text */ +#define FT_LITF 4 /* literal text, filled */ +#define FT_CHAR 5 /* a single ascii character */ +#define FT_NUM 6 /* "value" as decimal number */ +#define FT_NUMF 7 /* "value" as filled dec number */ +#define FT_STR 8 /* "str" as text */ +#define FT_STRF 9 /* "str" as text, filled */ +#define FT_STRFW 10 /* "str" as text, filled, width in "value" */ +#define FT_PUTADDR 11 /* split and print address line */ -/* types that modify the "str" or "value" registers */ -#define FT_LS_COMP 12 /* set "str" to component text */ -#define FT_LS_LIT 13 /* set "str" to literal text */ -#define FT_LS_GETENV 14 /* set "str" to getenv(text) */ -#define FT_LS_CFIND 15 /* set "str" to context_find(text) */ -#define FT_LS_DECODECOMP 16 /* set "str" to decoded component text */ -#define FT_LS_DECODE 17 /* decode "str" as RFC-2047 header */ -#define FT_LS_TRIM 18 /* trim trailing white space from "str" */ -#define FT_LV_COMP 19 /* set "value" to comp (as dec. num) */ -#define FT_LV_COMPFLAG 20 /* set "value" to comp flag word */ -#define FT_LV_LIT 21 /* set "value" to literal num */ -#define FT_LV_DAT 22 /* set "value" to dat[n] */ -#define FT_LV_STRLEN 23 /* set "value" to length of "str" */ -#define FT_LV_PLUS_L 24 /* set "value" += literal */ -#define FT_LV_MINUS_L 25 /* set "value" -= literal */ -#define FT_LV_DIVIDE_L 26 /* set "value" to value / literal */ -#define FT_LV_MODULO_L 27 /* set "value" to value % literal */ -#define FT_LV_CHAR_LEFT 28 /* set "value" to char left in output */ +/* types that modify the "str" or "value" registers */ +#define FT_LS_COMP 12 /* set "str" to component text */ +#define FT_LS_LIT 13 /* set "str" to literal text */ +#define FT_LS_GETENV 14 /* set "str" to getenv(text) */ +#define FT_LS_CFIND 15 /* set "str" to context_find(text) */ +#define FT_LS_DECODECOMP 16 /* set "str" to decoded component text */ +#define FT_LS_DECODE 17 /* decode "str" as RFC-2047 header */ +#define FT_LS_TRIM 18 /* trim trailing white space from "str" */ +#define FT_LV_COMP 19 /* set "value" to comp (as dec. num) */ +#define FT_LV_COMPFLAG 20 /* set "value" to comp flag word */ +#define FT_LV_LIT 21 /* set "value" to literal num */ +#define FT_LV_DAT 22 /* set "value" to dat[n] */ +#define FT_LV_STRLEN 23 /* set "value" to length of "str" */ +#define FT_LV_PLUS_L 24 /* set "value" += literal */ +#define FT_LV_MINUS_L 25 /* set "value" -= literal */ +#define FT_LV_DIVIDE_L 26 /* set "value" to value / literal */ +#define FT_LV_MODULO_L 27 /* set "value" to value % literal */ +#define FT_LV_CHAR_LEFT 28 /* set "value" to char left in output */ -#define FT_LS_MONTH 29 /* set "str" to tws month */ -#define FT_LS_LMONTH 30 /* set "str" to long tws month */ -#define FT_LS_ZONE 31 /* set "str" to tws timezone */ -#define FT_LS_DAY 32 /* set "str" to tws weekday */ -#define FT_LS_WEEKDAY 33 /* set "str" to long tws weekday */ -#define FT_LS_822DATE 34 /* set "str" to 822 date str */ -#define FT_LS_PRETTY 35 /* set "str" to pretty (?) date str */ -#define FT_LV_SEC 36 /* set "value" to tws second */ -#define FT_LV_MIN 37 /* set "value" to tws minute */ -#define FT_LV_HOUR 38 /* set "value" to tws hour */ -#define FT_LV_MDAY 39 /* set "value" to tws day of month */ -#define FT_LV_MON 40 /* set "value" to tws month */ -#define FT_LV_YEAR 41 /* set "value" to tws year */ -#define FT_LV_YDAY 42 /* set "value" to tws day of year */ -#define FT_LV_WDAY 43 /* set "value" to tws weekday */ -#define FT_LV_ZONE 44 /* set "value" to tws timezone */ -#define FT_LV_CLOCK 45 /* set "value" to tws clock */ -#define FT_LV_RCLOCK 46 /* set "value" to now - tws clock */ -#define FT_LV_DAYF 47 /* set "value" to tws day flag */ -#define FT_LV_DST 48 /* set "value" to tws daylight savings flag */ -#define FT_LV_ZONEF 49 /* set "value" to tws timezone flag */ +#define FT_LS_MONTH 29 /* set "str" to tws month */ +#define FT_LS_LMONTH 30 /* set "str" to long tws month */ +#define FT_LS_ZONE 31 /* set "str" to tws timezone */ +#define FT_LS_DAY 32 /* set "str" to tws weekday */ +#define FT_LS_WEEKDAY 33 /* set "str" to long tws weekday */ +#define FT_LS_822DATE 34 /* set "str" to 822 date str */ +#define FT_LS_PRETTY 35 /* set "str" to pretty (?) date str */ +#define FT_LV_SEC 36 /* set "value" to tws second */ +#define FT_LV_MIN 37 /* set "value" to tws minute */ +#define FT_LV_HOUR 38 /* set "value" to tws hour */ +#define FT_LV_MDAY 39 /* set "value" to tws day of month */ +#define FT_LV_MON 40 /* set "value" to tws month */ +#define FT_LV_YEAR 41 /* set "value" to tws year */ +#define FT_LV_YDAY 42 /* set "value" to tws day of year */ +#define FT_LV_WDAY 43 /* set "value" to tws weekday */ +#define FT_LV_ZONE 44 /* set "value" to tws timezone */ +#define FT_LV_CLOCK 45 /* set "value" to tws clock */ +#define FT_LV_RCLOCK 46 /* set "value" to now - tws clock */ +#define FT_LV_DAYF 47 /* set "value" to tws day flag */ +#define FT_LV_DST 48 /* set "value" to tws daylight savings flag */ +#define FT_LV_ZONEF 49 /* set "value" to tws timezone flag */ -#define FT_LS_PERS 50 /* set "str" to person part of addr */ -#define FT_LS_MBOX 51 /* set "str" to mbox part of addr */ -#define FT_LS_HOST 52 /* set "str" to host part of addr */ -#define FT_LS_PATH 53 /* set "str" to route part of addr */ -#define FT_LS_GNAME 54 /* set "str" to group part of addr */ -#define FT_LS_NOTE 55 /* set "str" to comment part of addr */ -#define FT_LS_ADDR 56 /* set "str" to mbox@host */ -#define FT_LS_822ADDR 57 /* set "str" to 822 format addr */ -#define FT_LS_FRIENDLY 58 /* set "str" to "friendly" format addr */ -#define FT_LV_HOSTTYPE 59 /* set "value" to addr host type */ -#define FT_LV_INGRPF 60 /* set "value" to addr in-group flag */ -#define FT_LS_UNQUOTE 61 /* remove RFC 2822 quotes from "str" */ -#define FT_LV_NOHOSTF 62 /* set "value" to addr no-host flag */ +#define FT_LS_PERS 50 /* set "str" to person part of addr */ +#define FT_LS_MBOX 51 /* set "str" to mbox part of addr */ +#define FT_LS_HOST 52 /* set "str" to host part of addr */ +#define FT_LS_PATH 53 /* set "str" to route part of addr */ +#define FT_LS_GNAME 54 /* set "str" to group part of addr */ +#define FT_LS_NOTE 55 /* set "str" to comment part of addr */ +#define FT_LS_ADDR 56 /* set "str" to mbox@host */ +#define FT_LS_822ADDR 57 /* set "str" to 822 format addr */ +#define FT_LS_FRIENDLY 58 /* set "str" to "friendly" format addr */ +#define FT_LV_HOSTTYPE 59 /* set "value" to addr host type */ +#define FT_LV_INGRPF 60 /* set "value" to addr in-group flag */ +#define FT_LS_UNQUOTE 61 /* remove RFC 2822 quotes from "str" */ +#define FT_LV_NOHOSTF 62 /* set "value" to addr no-host flag */ /* Date Coercion */ -#define FT_LOCALDATE 63 /* Coerce date to local timezone */ -#define FT_GMTDATE 64 /* Coerce date to gmt */ +#define FT_LOCALDATE 63 /* Coerce date to local timezone */ +#define FT_GMTDATE 64 /* Coerce date to gmt */ /* pre-format processing */ -#define FT_PARSEDATE 65 /* parse comp into a date (tws) struct */ -#define FT_PARSEADDR 66 /* parse comp into a mailaddr struct */ -#define FT_FORMATADDR 67 /* let external routine format addr */ -#define FT_MYMBOX 68 /* do "mymbox" test on comp */ +#define FT_PARSEDATE 65 /* parse comp into a date (tws) struct */ +#define FT_PARSEADDR 66 /* parse comp into a mailaddr struct */ +#define FT_FORMATADDR 67 /* let external routine format addr */ +#define FT_MYMBOX 68 /* do "mymbox" test on comp */ -/* misc. */ /* ADDTOSEQ only works if you include "options LBL" */ -#define FT_ADDTOSEQ 69 /* add current msg to a sequence */ +/* misc. */ +/* ADDTOSEQ only works if you include "options LBL" */ +#define FT_ADDTOSEQ 69 /* add current msg to a sequence */ /* conditionals & control flow (must be last) */ -#define FT_SAVESTR 70 /* save current str reg */ -#define FT_DONE 71 /* stop formatting */ -#define FT_PAUSE 72 /* pause */ -#define FT_NOP 73 /* nop */ -#define FT_GOTO 74 /* (relative) goto */ -#define FT_IF_S_NULL 75 /* test if "str" null */ -#define FT_IF_S 76 /* test if "str" non-null */ -#define FT_IF_V_EQ 77 /* test if "value" = literal */ -#define FT_IF_V_NE 78 /* test if "value" != literal */ -#define FT_IF_V_GT 79 /* test if "value" > literal */ -#define FT_IF_MATCH 80 /* test if "str" contains literal */ -#define FT_IF_AMATCH 81 /* test if "str" starts with literal */ -#define FT_S_NULL 82 /* V = 1 if "str" null */ -#define FT_S_NONNULL 83 /* V = 1 if "str" non-null */ -#define FT_V_EQ 84 /* V = 1 if "value" = literal */ -#define FT_V_NE 85 /* V = 1 if "value" != literal */ -#define FT_V_GT 86 /* V = 1 if "value" > literal */ -#define FT_V_MATCH 87 /* V = 1 if "str" contains literal */ -#define FT_V_AMATCH 88 /* V = 1 if "str" starts with literal */ +#define FT_SAVESTR 70 /* save current str reg */ +#define FT_DONE 71 /* stop formatting */ +#define FT_PAUSE 72 /* pause */ +#define FT_NOP 73 /* nop */ +#define FT_GOTO 74 /* (relative) goto */ +#define FT_IF_S_NULL 75 /* test if "str" null */ +#define FT_IF_S 76 /* test if "str" non-null */ +#define FT_IF_V_EQ 77 /* test if "value" = literal */ +#define FT_IF_V_NE 78 /* test if "value" != literal */ +#define FT_IF_V_GT 79 /* test if "value" > literal */ +#define FT_IF_MATCH 80 /* test if "str" contains literal */ +#define FT_IF_AMATCH 81 /* test if "str" starts with literal */ +#define FT_S_NULL 82 /* V = 1 if "str" null */ +#define FT_S_NONNULL 83 /* V = 1 if "str" non-null */ +#define FT_V_EQ 84 /* V = 1 if "value" = literal */ +#define FT_V_NE 85 /* V = 1 if "value" != literal */ +#define FT_V_GT 86 /* V = 1 if "value" > literal */ +#define FT_V_MATCH 87 /* V = 1 if "str" contains literal */ +#define FT_V_AMATCH 88 /* V = 1 if "str" starts with literal */ -#define IF_FUNCS FT_S_NULL /* start of "if" functions */ +#define IF_FUNCS FT_S_NULL /* start of "if" functions */ diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 9872e09..ea34898 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -1,4 +1,3 @@ - /* * fmt_scan.h -- definitions for fmt_scan() */ @@ -13,15 +12,15 @@ * processing once. e.g., parse an address.). */ struct comp { - char *c_name; /* component name (in lower case) */ - char *c_text; /* component text (if found) */ - struct comp *c_next; /* hash chain linkage */ - short c_flags; /* misc. flags (from fmt_scan) */ - short c_type; /* type info (from fmt_compile) */ - union { - struct tws *c_u_tws; - struct mailname *c_u_mn; - } c_un; + char *c_name; /* component name (in lower case) */ + char *c_text; /* component text (if found) */ + struct comp *c_next; /* hash chain linkage */ + short c_flags; /* misc. flags (from fmt_scan) */ + short c_type; /* type info (from fmt_compile) */ + union { + struct tws *c_u_tws; + struct mailname *c_u_mn; + } c_un; }; #define c_tws c_un.c_u_tws @@ -30,15 +29,15 @@ struct comp { /* * c_type bits */ -#define CT_ADDR (1<<0) /* referenced as address */ -#define CT_DATE (1<<1) /* referenced as date */ +#define CT_ADDR (1<<0) /* referenced as address */ +#define CT_DATE (1<<1) /* referenced as date */ /* * c_flags bits */ -#define CF_TRUE (1<<0) /* usually means component is present */ -#define CF_PARSED (1<<1) /* address/date has been parsed */ -#define CF_DATEFAB (1<<2) /* datefield fabricated */ +#define CF_TRUE (1<<0) /* usually means component is present */ +#define CF_PARSED (1<<1) /* address/date has been parsed */ +#define CF_DATEFAB (1<<2) /* datefield fabricated */ extern int fmt_norm; @@ -47,38 +46,38 @@ extern int fmt_norm; */ extern struct comp *wantcomp[128]; -/* +/* * Hash function for component name. The function should be * case independent and probably shouldn't involve a routine * call. This function is pretty good but will not work on - * single character component names. + * single character component names. */ -#define CHASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f)) +#define CHASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f)) /* * Find a component in the hash table. */ #define FINDCOMP(comp,name) \ for (comp = wantcomp[CHASH(name)]; \ - comp && strcmp(comp->c_name,name); \ - comp = comp->c_next) ; + comp && strcmp(comp->c_name,name); \ + comp = comp->c_next) ; /* * This structure defines one formatting instruction. */ struct format { - unsigned char f_type; - char f_fill; - short f_width; /* output field width */ - union { - struct comp *f_u_comp; /* associated component */ - char *f_u_text; /* literal text */ - char f_u_char; /* literal character */ - int f_u_value; /* literal value */ - } f_un; + unsigned char f_type; + char f_fill; + short f_width; /* output field width */ + union { + struct comp *f_u_comp; /* associated component */ + char *f_u_text; /* literal text */ + char f_u_char; /* literal character */ + int f_u_value; /* literal value */ + } f_un; }; -#define f_skip f_width /* instr to skip (false "if") */ +#define f_skip f_width /* instr to skip (false "if") */ #define f_comp f_un.f_u_comp #define f_text f_un.f_u_text diff --git a/h/md5.h b/h/md5.h index e49ef4e..0a750be 100644 --- a/h/md5.h +++ b/h/md5.h @@ -25,7 +25,7 @@ * with C compiler flags. */ #ifndef PROTOTYPES -#define PROTOTYPES 0 +# define PROTOTYPES 0 #endif /* POINTER defines a generic pointer type */ @@ -38,13 +38,13 @@ typedef unsigned short int UINT2; typedef unsigned long int UINT4; /* PROTO_LIST is defined depending on how PROTOTYPES is defined above. -If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it - returns an empty list. + * If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it + * returns an empty list. */ #if PROTOTYPES -#define PROTO_LIST(list) list +# define PROTO_LIST(list) list #else -#define PROTO_LIST(list) () +# define PROTO_LIST(list) () #endif /* MD5.H - header file for MD5C.C @@ -74,12 +74,11 @@ documentation and/or software. /* MD5 context. */ typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ } MD5_CTX; void MD5Init PROTO_LIST ((MD5_CTX *)); void MD5Update PROTO_LIST ((MD5_CTX *, unsigned char *, unsigned int)); void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); - diff --git a/h/mf.h b/h/mf.h index 6063e60..b84a626 100644 --- a/h/mf.h +++ b/h/mf.h @@ -1,70 +1,68 @@ - /* * mf.h -- include file for mailbox filters */ #include -#ifndef TRUE +#ifndef TRUE # define TRUE 1 #endif -#ifndef FALSE +#ifndef FALSE # define FALSE 0 #endif -#ifndef NOTOK +#ifndef NOTOK # define NOTOK (-1) #endif -#ifndef OK +#ifndef OK # define OK 0 #endif -#ifndef DONE +#ifndef DONE # define DONE 1 #endif -#define LINESIZ 512 +#define LINESIZ 512 -#define MBXMODE 0600 -#define TMPMODE 0600 +#define MBXMODE 0600 +#define TMPMODE 0600 -#define OWIDTH 75 /* length of a header line */ +#define OWIDTH 75 /* length of a header line */ -#define HFROM 1 /* header has From: component */ -#define HSNDR 2 /* header has Sender: component */ -#define HADDR 3 /* header has address component */ -#define HDATE 4 /* header has Date: component */ -#define HOTHR 5 /* header is unimportant */ +#define HFROM 1 /* header has From: component */ +#define HSNDR 2 /* header has Sender: component */ +#define HADDR 3 /* header has address component */ +#define HDATE 4 /* header has Date: component */ +#define HOTHR 5 /* header is unimportant */ struct adrx { - char *text; - char *pers; - char *mbox; - char *host; - char *path; - char *grp; - int ingrp; - char *note; - char *err; + char *text; + char *pers; + char *mbox; + char *host; + char *path; + char *grp; + int ingrp; + char *note; + char *err; }; -/* +/* * Codes returned by uucp2mmdf(), mmdf2uucp() */ - -#define MFOK 0 /* all went well */ - /* remaining codes must > DONE */ -#define MFPRM 2 /* bad parameter */ -#define MFSIO 3 /* stdio package went screwy */ -#define MFROM 4 /* from line was bad */ -#define MFHDR 5 /* headers were bad */ -#define MFTXT 6 /* text was bad */ -#define MFERR 7 /* I/O or system error */ -#define MFDLM 8 /* Bad delimiter in MMDF file */ +#define MFOK 0 /* all went well */ +/* remaining codes must > DONE */ +#define MFPRM 2 /* bad parameter */ +#define MFSIO 3 /* stdio package went screwy */ +#define MFROM 4 /* from line was bad */ +#define MFHDR 5 /* headers were bad */ +#define MFTXT 6 /* text was bad */ +#define MFERR 7 /* I/O or system error */ +#define MFDLM 8 /* Bad delimiter in MMDF file */ /* @@ -77,4 +75,3 @@ char *legal_person (char *); struct adrx *seekadrx (char *); struct adrx *getadrx (char *); struct adrx *uucpadrx (char *); - diff --git a/h/mh.h b/h/mh.h index 5898831..d41ab95 100644 --- a/h/mh.h +++ b/h/mh.h @@ -1,4 +1,3 @@ - /* * mh.h -- main header file for all of nmh */ @@ -8,22 +7,22 @@ /* * Well-used constants */ -#define NOTOK (-1) /* syscall()s return this on error */ -#define OK 0 /* ditto on success */ -#define DONE 1 /* trinary logic */ +#define NOTOK (-1) /* syscall()s return this on error */ +#define OK 0 /* ditto on success */ +#define DONE 1 /* trinary logic */ #define ALL "" -#define Nbby 8 /* number of bits/byte */ +#define Nbby 8 /* number of bits/byte */ -#define MAXARGS 1000 /* max arguments to exec */ -#define NFOLDERS 1000 /* max folder arguments on command line */ -#define DMAXFOLDER 4 /* typical number of digits */ -#define MAXFOLDER 1000 /* message increment */ +#define MAXARGS 1000 /* max arguments to exec */ +#define NFOLDERS 1000 /* max folder arguments on command line */ +#define DMAXFOLDER 4 /* typical number of digits */ +#define MAXFOLDER 1000 /* message increment */ #ifndef FALSE -#define FALSE 0 +# define FALSE 0 #endif #ifndef TRUE -#define TRUE 1 +# define TRUE 1 #endif typedef unsigned char boolean; /* not int so we can pack in a structure */ @@ -31,51 +30,52 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ * functions that abort. */ #if __GNUC__ > 2 -#define NORETURN __attribute__((__noreturn__)) +# define NORETURN __attribute__((__noreturn__)) #else -#define NORETURN +# define NORETURN #endif /* * user context/profile structure */ struct node { - char *n_name; /* key */ - char *n_field; /* value */ - char n_context; /* context, not profile */ - struct node *n_next; /* next entry */ + char *n_name; /* key */ + char *n_field; /* value */ + char n_context; /* context, not profile */ + struct node *n_next; /* next entry */ }; /* * switches structure */ -#define AMBIGSW (-2) /* from smatch() on ambiguous switch */ -#define UNKWNSW (-1) /* from smatch() on unknown switch */ +#define AMBIGSW (-2) /* from smatch() on ambiguous switch */ +#define UNKWNSW (-1) /* from smatch() on unknown switch */ struct swit { - char *sw; - - /* The minchars field is apparently used like this: - - -# : Switch can be abbreviated to # characters; switch hidden in -help. - 0 : Switch can't be abbreviated; switch shown in -help. - # : Switch can be abbreviated to # characters; switch shown in -help. */ - int minchars; + char *sw; + /* + * The minchars field is apparently used like this: + * + * -# : Switch can be abbreviated to # chars; switch hidden in -help. + * 0 : Switch can't be abbreviated; switch shown in -help. + * # : Switch can be abbreviated to # chars; switch shown in -help. + */ + int minchars; }; -extern struct swit anoyes[]; /* standard yes/no switches */ +extern struct swit anoyes[]; /* standard yes/no switches */ -#define ATTACHFORMATS 3 /* Number of send attach formats. */ +#define ATTACHFORMATS 3 /* Number of send attach formats. */ /* * general folder attributes */ -#define READONLY (1<<0) /* No write access to folder */ -#define SEQMOD (1<<1) /* folder's sequences modifed */ -#define ALLOW_NEW (1<<2) /* allow the "new" sequence */ -#define OTHERS (1<<3) /* folder has other files */ +#define READONLY (1<<0) /* No write access to folder */ +#define SEQMOD (1<<1) /* folder's sequences modifed */ +#define ALLOW_NEW (1<<2) /* allow the "new" sequence */ +#define OTHERS (1<<3) /* folder has other files */ -#define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS" +#define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS" /* * type for holding the sequence set of a message @@ -87,70 +87,70 @@ typedef unsigned int seqset_t; * can have. The first 5 sequence flags are for * internal nmh message flags. */ -#define NUMATTRS ((sizeof(seqset_t) * Nbby) - 5) +#define NUMATTRS ((sizeof(seqset_t) * Nbby) - 5) /* * first free slot for user defined sequences * and attributes */ -#define FFATTRSLOT 5 +#define FFATTRSLOT 5 /* * internal messages attributes (sequences) */ -#define EXISTS (1<<0) /* exists */ -#define DELETED (1<<1) /* deleted */ -#define SELECTED (1<<2) /* selected for use */ -#define SELECT_EMPTY (1<<3) /* "new" message */ -#define SELECT_UNSEEN (1<<4) /* inc/show "unseen" */ +#define EXISTS (1<<0) /* exists */ +#define DELETED (1<<1) /* deleted */ +#define SELECTED (1<<2) /* selected for use */ +#define SELECT_EMPTY (1<<3) /* "new" message */ +#define SELECT_UNSEEN (1<<4) /* inc/show "unseen" */ -#define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN" +#define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN" /* * Primary structure of folder/message information */ struct msgs { - int lowmsg; /* Lowest msg number */ - int hghmsg; /* Highest msg number */ - int nummsg; /* Actual Number of msgs */ - - int lowsel; /* Lowest selected msg number */ - int hghsel; /* Highest selected msg number */ - int numsel; /* Number of msgs selected */ - - int curmsg; /* Number of current msg if any */ - - int msgflags; /* Folder attributes (READONLY, etc) */ - char *foldpath; /* Pathname of folder */ - - /* - * Name of sequences in this folder. We add an - * extra slot, so we can NULL terminate the list. - */ - char *msgattrs[NUMATTRS + 1]; - - /* - * bit flags for whether sequence - * is public (0), or private (1) - */ - seqset_t attrstats; - - /* - * These represent the lowest and highest possible - * message numbers we can put in the message status - * area, without calling folder_realloc(). - */ - int lowoff; - int hghoff; - - /* - * This is an array of seqset_t which we allocate dynamically. - * Each seqset_t is a set of bits flags for a particular message. - * These bit flags represent general attributes such as - * EXISTS, SELECTED, etc. as well as track if message is - * in a particular sequence. - */ - seqset_t *msgstats; /* msg status */ + int lowmsg; /* Lowest msg number */ + int hghmsg; /* Highest msg number */ + int nummsg; /* Actual Number of msgs */ + + int lowsel; /* Lowest selected msg number */ + int hghsel; /* Highest selected msg number */ + int numsel; /* Number of msgs selected */ + + int curmsg; /* Number of current msg if any */ + + int msgflags; /* Folder attributes (READONLY, etc) */ + char *foldpath; /* Pathname of folder */ + + /* + * Name of sequences in this folder. We add an + * extra slot, so we can NULL terminate the list. + */ + char *msgattrs[NUMATTRS + 1]; + + /* + * bit flags for whether sequence + * is public (0), or private (1) + */ + seqset_t attrstats; + + /* + * These represent the lowest and highest possible + * message numbers we can put in the message status + * area, without calling folder_realloc(). + */ + int lowoff; + int hghoff; + + /* + * This is an array of seqset_t which we allocate dynamically. + * Each seqset_t is a set of bits flags for a particular message. + * These bit flags represent general attributes such as + * EXISTS, SELECTED, etc. as well as track if message is + * in a particular sequence. + */ + seqset_t *msgstats; /* msg status */ }; /* @@ -164,25 +164,25 @@ struct msgs { */ #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0) #define copy_msg_flags(mp,i,j) \ - ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff]) + ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff]) #define get_msg_flags(mp,ptr,msgnum) (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff]) #define set_msg_flags(mp,ptr,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr)) -#define does_exist(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS) -#define unset_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS) -#define set_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS) +#define does_exist(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS) +#define unset_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS) +#define set_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS) -#define is_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED) -#define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED) -#define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED) +#define is_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED) +#define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED) +#define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED) -#define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY) +#define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY) #define set_select_empty(mp,msgnum) \ - ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY) + ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY) -#define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN) -#define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN) -#define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN) +#define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN) +#define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN) +#define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN) #define in_sequence(mp,seqnum,msgnum) \ @@ -206,61 +206,63 @@ struct msgs { */ #define clear_folder_flags(mp) ((mp)->msgflags = 0) -#define is_readonly(mp) ((mp)->msgflags & READONLY) -#define set_readonly(mp) ((mp)->msgflags |= READONLY) +#define is_readonly(mp) ((mp)->msgflags & READONLY) +#define set_readonly(mp) ((mp)->msgflags |= READONLY) -#define other_files(mp) ((mp)->msgflags & OTHERS) -#define set_other_files(mp) ((mp)->msgflags |= OTHERS) +#define other_files(mp) ((mp)->msgflags & OTHERS) +#define set_other_files(mp) ((mp)->msgflags |= OTHERS) -#define NULLMP ((struct msgs *) 0) +#define NULLMP ((struct msgs *) 0) /* * m_getfld() message parsing */ -#define NAMESZ 999 /* Limit on component name size. - RFC 2822 limits line lengths to - 998 characters, so a header name - can be at most that long. - m_getfld limits header names to 2 - less than NAMESZ, which is fine, - because header names must be - followed by a colon. Add one for - terminating NULL. */ - -#define LENERR (-2) /* Name too long error from getfld */ -#define FMTERR (-3) /* Message Format error */ -#define FLD 0 /* Field returned */ -#define FLDPLUS 1 /* Field returned with more to come */ -#define FLDEOF 2 /* Field returned ending at eom */ -#define BODY 3 /* Body returned with more to come */ -#define BODYEOF 4 /* Body returned ending at eom */ -#define FILEEOF 5 /* Reached end of input file */ +#define NAMESZ 999 /* Limit on component name size. + * RFC 2822 limits line lengths to + * 998 characters, so a header name + * can be at most that long. + * m_getfld limits header names to 2 + * less than NAMESZ, which is fine, + * because header names must be + * followed by a colon. Add one for + * terminating NULL. + */ + +#define LENERR (-2) /* Name too long error from getfld */ +#define FMTERR (-3) /* Message Format error */ +#define FLD 0 /* Field returned */ +#define FLDPLUS 1 /* Field returned with more to come */ +#define FLDEOF 2 /* Field returned ending at eom */ +#define BODY 3 /* Body returned with more to come */ +#define BODYEOF 4 /* Body returned ending at eom */ +#define FILEEOF 5 /* Reached end of input file */ /* * Maildrop styles */ -#define MS_DEFAULT 0 /* default (one msg per file) */ -#define MS_UNKNOWN 1 /* type not known yet */ -#define MS_MBOX 2 /* Unix-style "from" lines */ -#define MS_MMDF 3 /* string mmdlm2 */ +#define MS_DEFAULT 0 /* default (one msg per file) */ +#define MS_UNKNOWN 1 /* type not known yet */ +#define MS_MBOX 2 /* Unix-style "from" lines */ +#define MS_MMDF 3 /* string mmdlm2 */ -extern int msg_count; /* m_getfld() indicators */ -extern int msg_style; /* .. */ -extern char *msg_delim; /* .. */ +extern int msg_count; /* m_getfld() indicators */ +extern int msg_style; /* .. */ +extern char *msg_delim; /* .. */ -#define NOUSE 0 /* draft being re-used */ +#define NOUSE 0 /* draft being re-used */ -#define TFOLDER 0 /* path() given a +folder */ -#define TFILE 1 /* path() given a file */ -#define TSUBCWF 2 /* path() given a @folder */ +#define TFOLDER 0 /* path() given a +folder */ +#define TFILE 1 /* path() given a file */ +#define TSUBCWF 2 /* path() given a @folder */ -#define OUTPUTLINELEN 72 /* default line length for headers */ +#define OUTPUTLINELEN 72 /* default line length for headers */ /* * miscellaneous macros */ -#define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp) + +#define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp) #ifndef max # define max(a,b) ((a) > (b) ? (a) : (b)) @@ -277,15 +279,15 @@ extern char *msg_delim; /* .. */ /* * GLOBAL VARIABLES */ -#define CTXMOD 0x01 /* context information modified */ -#define DBITS "\020\01CTXMOD" +#define CTXMOD 0x01 /* context information modified */ +#define DBITS "\020\01CTXMOD" extern char ctxflags; -extern char *invo_name; /* command invocation name */ -extern char *mypath; /* user's $HOME */ -extern char *defpath; /* pathname of user's profile */ -extern char *ctxpath; /* pathname of user's context */ -extern struct node *m_defs; /* list of profile/context entries */ +extern char *invo_name; /* command invocation name */ +extern char *mypath; /* user's $HOME */ +extern char *defpath; /* pathname of user's profile */ +extern char *ctxpath; /* pathname of user's context */ +extern struct node *m_defs; /* list of profile/context entries */ /* * These standard strings are defined in config.c. They are the @@ -351,4 +353,3 @@ extern char *whomproc; extern void (*done) (int) NORETURN; #include - diff --git a/h/mhcachesbr.h b/h/mhcachesbr.h index 9c1db6a..68bd2be 100644 --- a/h/mhcachesbr.h +++ b/h/mhcachesbr.h @@ -1,4 +1,3 @@ - /* * mhcachesbr.h -- definitions for manipulating MIME content cache */ @@ -8,12 +7,12 @@ */ static struct swit caches[] = { #define CACHE_NEVER 0 - { "never", 0 }, + { "never", 0 }, #define CACHE_PRIVATE 1 - { "private", 0 }, + { "private", 0 }, #define CACHE_PUBLIC 2 - { "public", 0 }, + { "public", 0 }, #define CACHE_ASK 3 - { "ask", 0 }, - { NULL, 0 } + { "ask", 0 }, + { NULL, 0 } }; diff --git a/h/mhparse.h b/h/mhparse.h index 48f221f..e3abf31 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -1,12 +1,11 @@ - /* * mhparse.h -- definitions for parsing/building of MIME content * -- (mhparse.c/mhbuildsbr.c) */ -#define NPARTS 50 -#define NTYPES 20 -#define NPARMS 10 +#define NPARTS 50 +#define NTYPES 20 +#define NPARMS 10 /* * Abstract type for header fields @@ -37,10 +36,10 @@ typedef unsigned long (*SizeCEFunc) (CT); * a header field and its value. */ struct hfield { - char *name; /* field name */ - char *value; /* field body */ - int hf_encoding; /* internal flag for transfer encoding to use */ - HF next; /* link to next header field */ + char *name; /* field name */ + char *value; /* field body */ + int hf_encoding; /* internal flag for transfer encoding to use */ + HF next; /* link to next header field */ }; /* @@ -48,12 +47,12 @@ struct hfield { * of the Content-Type component. */ struct CTinfo { - char *ci_type; /* content type */ - char *ci_subtype; /* content subtype */ - char *ci_attrs[NPARMS + 2]; /* attribute names */ - char *ci_values[NPARMS]; /* attribute values */ - char *ci_comment; /* RFC-822 comments */ - char *ci_magic; + char *ci_type; /* content type */ + char *ci_subtype; /* content subtype */ + char *ci_attrs[NPARMS + 2]; /* attribute names */ + char *ci_values[NPARMS]; /* attribute values */ + char *ci_comment; /* RFC-822 comments */ + char *ci_magic; }; /* @@ -61,115 +60,115 @@ struct CTinfo { * removing Content-Transfer-Encoding. */ struct cefile { - char *ce_file; /* decoded content (file) */ - FILE *ce_fp; /* decoded content (stream) */ - int ce_unlink; /* remove file when done? */ + char *ce_file; /* decoded content (file) */ + FILE *ce_fp; /* decoded content (stream) */ + int ce_unlink; /* remove file when done? */ }; /* * Primary structure for handling Content (Entity) */ struct Content { - /* source (read) file */ - char *c_file; /* read contents (file) */ - FILE *c_fp; /* read contents (stream) */ - int c_unlink; /* remove file when done? */ - - long c_begin; /* where content body starts in file */ - long c_end; /* where content body ends in file */ - - /* linked list of header fields */ - HF c_first_hf; /* pointer to first header field */ - HF c_last_hf; /* pointer to last header field */ - - /* copies of MIME related header fields */ - char *c_vrsn; /* MIME-Version: */ - char *c_ctline; /* Content-Type: */ - char *c_celine; /* Content-Transfer-Encoding: */ - char *c_id; /* Content-ID: */ - char *c_descr; /* Content-Description: */ - char *c_dispo; /* Content-Disposition: */ - char *c_partno; /* within multipart content */ - - /* Content-Type info */ - struct CTinfo c_ctinfo; /* parsed elements of Content-Type */ - int c_type; /* internal flag for content type */ - int c_subtype; /* internal flag for content subtype */ - - /* Content-Transfer-Encoding info (decoded contents) */ - CE c_cefile; /* structure holding decoded content */ - int c_encoding; /* internal flag for encoding type */ - - /* Content-MD5 info */ - int c_digested; /* have we seen this header before? */ - unsigned char c_digest[16]; /* decoded MD5 checksum */ - - /* pointers to content-specific structures */ - void *c_ctparams; /* content type specific data */ - struct exbody *c_ctexbody; /* data for type message/external */ - - /* function pointers */ - InitFunc c_ctinitfnx; /* parse content body */ - OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */ - CloseCEFunc c_ceclosefnx; /* release stream */ - SizeCEFunc c_cesizefnx; /* size of decoded contents */ - - int c_umask; /* associated umask */ - pid_t c_pid; /* process doing display */ - int c_rfc934; /* rfc934 compatibility flag */ - - char *c_showproc; /* default, if not in profile */ - char *c_termproc; /* for charset madness... */ - char *c_storeproc; /* overrides profile entry, if any */ - - char *c_storage; /* write contents (file) */ - char *c_folder; /* write contents (folder) */ + /* source (read) file */ + char *c_file; /* read contents (file) */ + FILE *c_fp; /* read contents (stream) */ + int c_unlink; /* remove file when done? */ + + long c_begin; /* where content body starts in file */ + long c_end; /* where content body ends in file */ + + /* linked list of header fields */ + HF c_first_hf; /* pointer to first header field */ + HF c_last_hf; /* pointer to last header field */ + + /* copies of MIME related header fields */ + char *c_vrsn; /* MIME-Version: */ + char *c_ctline; /* Content-Type: */ + char *c_celine; /* Content-Transfer-Encoding: */ + char *c_id; /* Content-ID: */ + char *c_descr; /* Content-Description: */ + char *c_dispo; /* Content-Disposition: */ + char *c_partno; /* within multipart content */ + + /* Content-Type info */ + struct CTinfo c_ctinfo; /* parsed elements of Content-Type */ + int c_type; /* internal flag for content type */ + int c_subtype; /* internal flag for content subtype */ + + /* Content-Transfer-Encoding info (decoded contents) */ + CE c_cefile; /* structure holding decoded content */ + int c_encoding; /* internal flag for encoding type */ + + /* Content-MD5 info */ + int c_digested; /* have we seen this header before? */ + unsigned char c_digest[16]; /* decoded MD5 checksum */ + + /* pointers to content-specific structures */ + void *c_ctparams; /* content type specific data */ + struct exbody *c_ctexbody; /* data for type message/external */ + + /* function pointers */ + InitFunc c_ctinitfnx; /* parse content body */ + OpenCEFunc c_ceopenfnx; /* get a stream to decoded contents */ + CloseCEFunc c_ceclosefnx; /* release stream */ + SizeCEFunc c_cesizefnx; /* size of decoded contents */ + + int c_umask; /* associated umask */ + pid_t c_pid; /* process doing display */ + int c_rfc934; /* rfc934 compatibility flag */ + + char *c_showproc; /* default, if not in profile */ + char *c_termproc; /* for charset madness... */ + char *c_storeproc; /* overrides profile entry, if any */ + + char *c_storage; /* write contents (file) */ + char *c_folder; /* write contents (folder) */ }; /* * Flags for Content-Type (Content->c_type) */ -#define CT_UNKNOWN 0x00 -#define CT_APPLICATION 0x01 -#define CT_AUDIO 0x02 -#define CT_IMAGE 0x03 -#define CT_MESSAGE 0x04 -#define CT_MULTIPART 0x05 -#define CT_TEXT 0x06 -#define CT_VIDEO 0x07 -#define CT_EXTENSION 0x08 +#define CT_UNKNOWN 0x00 +#define CT_APPLICATION 0x01 +#define CT_AUDIO 0x02 +#define CT_IMAGE 0x03 +#define CT_MESSAGE 0x04 +#define CT_MULTIPART 0x05 +#define CT_TEXT 0x06 +#define CT_VIDEO 0x07 +#define CT_EXTENSION 0x08 /* * Flags for Content-Transfer-Encoding (Content->c_encoding) */ -#define CE_UNKNOWN 0x00 -#define CE_BASE64 0x01 -#define CE_QUOTED 0x02 -#define CE_8BIT 0x03 -#define CE_7BIT 0x04 -#define CE_BINARY 0x05 -#define CE_EXTENSION 0x06 -#define CE_EXTERNAL 0x07 /* for external-body */ +#define CE_UNKNOWN 0x00 +#define CE_BASE64 0x01 +#define CE_QUOTED 0x02 +#define CE_8BIT 0x03 +#define CE_7BIT 0x04 +#define CE_BINARY 0x05 +#define CE_EXTENSION 0x06 +#define CE_EXTERNAL 0x07 /* for external-body */ /* * TEXT content */ /* Flags for subtypes of TEXT */ -#define TEXT_UNKNOWN 0x00 -#define TEXT_PLAIN 0x01 -#define TEXT_RICHTEXT 0x02 -#define TEXT_ENRICHED 0x03 +#define TEXT_UNKNOWN 0x00 +#define TEXT_PLAIN 0x01 +#define TEXT_RICHTEXT 0x02 +#define TEXT_ENRICHED 0x03 /* Flags for character sets */ -#define CHARSET_UNKNOWN 0x00 -#define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */ -#define CHARSET_USASCII 0x01 -#define CHARSET_LATIN 0x02 +#define CHARSET_UNKNOWN 0x00 +#define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */ +#define CHARSET_USASCII 0x01 +#define CHARSET_LATIN 0x02 /* Structure for text content */ struct text { - int tx_charset; /* flag for character set */ + int tx_charset; /* flag for character set */ }; /* @@ -177,23 +176,23 @@ struct text { */ /* Flags for subtypes of MULTIPART */ -#define MULTI_UNKNOWN 0x00 -#define MULTI_MIXED 0x01 -#define MULTI_ALTERNATE 0x02 -#define MULTI_DIGEST 0x03 -#define MULTI_PARALLEL 0x04 +#define MULTI_UNKNOWN 0x00 +#define MULTI_MIXED 0x01 +#define MULTI_ALTERNATE 0x02 +#define MULTI_DIGEST 0x03 +#define MULTI_PARALLEL 0x04 /* Structure for subparts of a multipart content */ struct part { - CT mp_part; /* Content structure for subpart */ - struct part *mp_next; /* pointer to next subpart structure */ + CT mp_part; /* Content structure for subpart */ + struct part *mp_next; /* pointer to next subpart structure */ }; /* Main structure for multipart content */ struct multipart { - char *mp_start; /* boundary string separating parts */ - char *mp_stop; /* terminating boundary string */ - struct part *mp_parts; /* pointer to first subpart structure */ + char *mp_start; /* boundary string separating parts */ + char *mp_stop; /* terminating boundary string */ + struct part *mp_parts; /* pointer to first subpart structure */ }; /* @@ -201,36 +200,36 @@ struct multipart { */ /* Flags for subtypes of MESSAGE */ -#define MESSAGE_UNKNOWN 0x00 -#define MESSAGE_RFC822 0x01 -#define MESSAGE_PARTIAL 0x02 -#define MESSAGE_EXTERNAL 0x03 +#define MESSAGE_UNKNOWN 0x00 +#define MESSAGE_RFC822 0x01 +#define MESSAGE_PARTIAL 0x02 +#define MESSAGE_EXTERNAL 0x03 /* Structure for message/partial */ struct partial { - char *pm_partid; - int pm_partno; - int pm_maxno; - int pm_marked; - int pm_stored; + char *pm_partid; + int pm_partno; + int pm_maxno; + int pm_marked; + int pm_stored; }; /* Structure for message/external */ struct exbody { - CT eb_parent; /* pointer to controlling content structure */ - CT eb_content; /* pointer to internal content structure */ - char *eb_partno; - char *eb_access; - int eb_flags; - char *eb_name; - char *eb_permission; - char *eb_site; - char *eb_dir; - char *eb_mode; - unsigned long eb_size; - char *eb_server; - char *eb_subject; - char *eb_body; + CT eb_parent; /* pointer to controlling content structure */ + CT eb_content; /* pointer to internal content structure */ + char *eb_partno; + char *eb_access; + int eb_flags; + char *eb_name; + char *eb_permission; + char *eb_site; + char *eb_dir; + char *eb_mode; + unsigned long eb_size; + char *eb_server; + char *eb_subject; + char *eb_body; }; /* @@ -238,17 +237,17 @@ struct exbody { */ /* Flags for subtype of APPLICATION */ -#define APPLICATION_UNKNOWN 0x00 -#define APPLICATION_OCTETS 0x01 -#define APPLICATION_POSTSCRIPT 0x02 +#define APPLICATION_UNKNOWN 0x00 +#define APPLICATION_OCTETS 0x01 +#define APPLICATION_POSTSCRIPT 0x02 /* * Structures for mapping types to their internal flags */ struct k2v { - char *kv_key; - int kv_value; + char *kv_key; + int kv_value; }; extern struct k2v SubText[]; extern struct k2v Charset[]; @@ -261,9 +260,9 @@ extern struct k2v SubApplication[]; * the functions to handle them. */ struct str2init { - char *si_key; - int si_val; - InitFunc si_init; + char *si_key; + int si_val; + InitFunc si_init; }; extern struct str2init str2cts[]; extern struct str2init str2ces[]; @@ -280,4 +279,4 @@ int params_external (CT, int); int open7Bit (CT, char **); void close_encoding (CT); -extern int checksw; /* Add Content-MD5 field */ +extern int checksw; /* Add Content-MD5 field */ diff --git a/h/mime.h b/h/mime.h index 3e50ce2..d51e3af 100644 --- a/h/mime.h +++ b/h/mime.h @@ -1,37 +1,35 @@ - /* * mime.h -- definitions for MIME */ -#define VRSN_FIELD "MIME-Version" -#define VRSN_VALUE "1.0" -#define XXX_FIELD_PRF "Content-" -#define TYPE_FIELD "Content-Type" -#define ENCODING_FIELD "Content-Transfer-Encoding" -#define ID_FIELD "Content-ID" -#define DESCR_FIELD "Content-Description" -#define DISPO_FIELD "Content-Disposition" -#define MD5_FIELD "Content-MD5" +#define VRSN_FIELD "MIME-Version" +#define VRSN_VALUE "1.0" +#define XXX_FIELD_PRF "Content-" +#define TYPE_FIELD "Content-Type" +#define ENCODING_FIELD "Content-Transfer-Encoding" +#define ID_FIELD "Content-ID" +#define DESCR_FIELD "Content-Description" +#define DISPO_FIELD "Content-Disposition" +#define MD5_FIELD "Content-MD5" -#define isatom(c) (!isspace (c) && !iscntrl (c) && (c) != '(' \ - && (c) != ')' && (c) != '<' && (c) != '>' \ - && (c) != '@' && (c) != ',' && (c) != ';' \ - && (c) != ':' && (c) != '\\' && (c) != '"' \ - && (c) != '.' && (c) != '[' && (c) != ']') +#define isatom(c) (!isspace (c) && !iscntrl (c) && (c) != '(' \ + && (c) != ')' && (c) != '<' && (c) != '>' \ + && (c) != '@' && (c) != ',' && (c) != ';' \ + && (c) != ':' && (c) != '\\' && (c) != '"' \ + && (c) != '.' && (c) != '[' && (c) != ']') /* * Test for valid characters used in "token" * as defined in RFC2045 */ -#define istoken(c) (!isspace (c) && !iscntrl (c) && (c) != '(' \ - && (c) != ')' && (c) != '<' && (c) != '>' \ - && (c) != '@' && (c) != ',' && (c) != ';' \ - && (c) != ':' && (c) != '\\' && (c) != '"' \ - && (c) != '/' && (c) != '[' && (c) != ']' \ - && (c) != '?' && (c) != '=') - -#define CPERLIN 76 -#define BPERLIN (CPERLIN / 4) -#define LPERMSG 632 -#define CPERMSG (LPERMSG * CPERLIN) +#define istoken(c) (!isspace (c) && !iscntrl (c) && (c) != '(' \ + && (c) != ')' && (c) != '<' && (c) != '>' \ + && (c) != '@' && (c) != ',' && (c) != ';' \ + && (c) != ':' && (c) != '\\' && (c) != '"' \ + && (c) != '/' && (c) != '[' && (c) != ']' \ + && (c) != '?' && (c) != '=') +#define CPERLIN 76 +#define BPERLIN (CPERLIN / 4) +#define LPERMSG 632 +#define CPERMSG (LPERMSG * CPERLIN) diff --git a/h/mts.h b/h/mts.h index 07fa8a2..20b42a0 100644 --- a/h/mts.h +++ b/h/mts.h @@ -1,4 +1,3 @@ - /* * mts.h -- definitions for the mail system */ @@ -17,10 +16,10 @@ extern char *mmdflfil; extern char *uucpldir; extern char *uucplfil; -#define MAILDIR (mmdfldir && *mmdfldir ? mmdfldir : getenv ("HOME")) -#define MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername ()) -#define UUCPDIR (uucpldir && *uucpldir ? uucpldir : getenv ("HOME")) -#define UUCPFIL (uucplfil && *uucplfil ? uucplfil : getusername ()) +#define MAILDIR (mmdfldir && *mmdfldir ? mmdfldir : getenv ("HOME")) +#define MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername ()) +#define UUCPDIR (uucpldir && *uucpldir ? uucpldir : getenv ("HOME")) +#define UUCPFIL (uucplfil && *uucplfil ? uucplfil : getusername ()) char *getusername(void); char *getfullname(void); @@ -31,8 +30,8 @@ char *getfullname(void); extern char *mmdlm1; extern char *mmdlm2; -#define isdlm1(s) (strcmp (s, mmdlm1) == 0) -#define isdlm2(s) (strcmp (s, mmdlm2) == 0) +#define isdlm1(s) (strcmp (s, mmdlm1) == 0) +#define isdlm2(s) (strcmp (s, mmdlm2) == 0) /* * Read mts.conf file diff --git a/h/nmh.h b/h/nmh.h index f1711d5..f10ec1e 100644 --- a/h/nmh.h +++ b/h/nmh.h @@ -1,4 +1,3 @@ - /* * nmh.h -- system configuration header file */ @@ -109,7 +108,7 @@ #endif #include - + #define bcmp(b1,b2,length) memcmp(b1, b2, length) #define bcopy(b1,b2,length) memcpy (b2, b1, length) #define bcpy(b1,b2,length) memcmp (b1, b2, length) @@ -128,33 +127,32 @@ #ifdef STAT_MACROS_BROKEN # ifdef S_ISBLK # undef S_ISBLK -# endif +# endif # ifdef S_ISCHR # undef S_ISCHR -# endif +# endif # ifdef S_ISDIR # undef S_ISDIR -# endif +# endif # ifdef S_ISFIFO # undef S_ISFIFO -# endif +# endif # ifdef S_ISLNK # undef S_ISLNK -# endif +# endif # ifdef S_ISMPB # undef S_ISMPB -# endif +# endif # ifdef S_ISMPC # undef S_ISMPC -# endif +# endif # ifdef S_ISNWK # undef S_ISNWK -# endif +# endif # ifdef S_ISREG # undef S_ISREG -# endif +# endif # ifdef S_ISSOCK # undef S_ISSOCK -# endif +# endif #endif /* STAT_MACROS_BROKEN. */ - diff --git a/h/picksbr.h b/h/picksbr.h index 27c2e66..9c4b475 100644 --- a/h/picksbr.h +++ b/h/picksbr.h @@ -1,4 +1,3 @@ - /* * picksbr.h -- definitions for picksbr.c */ diff --git a/h/prototypes.h b/h/prototypes.h index c679ace..5ddd467 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -1,4 +1,3 @@ - /* * prototypes.h -- various prototypes */ @@ -162,4 +161,3 @@ void replout (FILE *, char *, char *, struct msgs *, int, int sendsbr (char **, int, char *, struct stat *, int, char *, int); int what_now (char *, int, int, char *, char *, int, struct msgs *, char *, int, char *); - diff --git a/h/rcvmail.h b/h/rcvmail.h index b2a355e..98a7f18 100644 --- a/h/rcvmail.h +++ b/h/rcvmail.h @@ -1,4 +1,3 @@ - /* * rcvmail.h -- rcvmail hook definitions */ @@ -9,5 +8,5 @@ # include # include -# define RCV_MOK 0 -# define RCV_MBX 1 +# define RCV_MOK 0 +# define RCV_MBX 1 diff --git a/h/scansbr.h b/h/scansbr.h index f6cd35c..d3b1c9f 100644 --- a/h/scansbr.h +++ b/h/scansbr.h @@ -1,30 +1,28 @@ - /* * scansbr.h -- definitions for scan() */ extern char *scanl; -#define SCNENC 2 /* message just fine, but encrypted(!!) */ -#define SCNMSG 1 /* message just fine */ -#define SCNEOF 0 /* empty message */ -#define SCNERR (-1) /* error message */ -#define SCNNUM (-2) /* number out of range */ -#define SCNFAT (-3) /* fatal error */ +#define SCNENC 2 /* message just fine, but encrypted(!!) */ +#define SCNMSG 1 /* message just fine */ +#define SCNEOF 0 /* empty message */ +#define SCNERR (-1) /* error message */ +#define SCNNUM (-2) /* number out of range */ +#define SCNFAT (-3) /* fatal error */ /* * default format for `scan' and `inc' */ - -#ifndef UK -#define FORMAT \ +#ifndef UK +# define FORMAT \ "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>\ %02(mon{date})/%02(mday{date})%<{date} %|*%>\ %<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\ %<(zero)%17(decode(friendly{from}))%> \ %(decode{subject})%<{body}<<%{body}>>%>\n" #else -#define FORMAT \ +# define FORMAT \ "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>\ %02(mday{date})/%02(mon{date})%<{date} %|*%>\ %<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\ @@ -32,7 +30,7 @@ extern char *scanl; %(decode{subject})%<{body}<<%{body}>>%>\n" #endif -#define WIDTH 78 +#define WIDTH 78 /* * prototypes diff --git a/h/signals.h b/h/signals.h index 4ad2b57..d65da58 100644 --- a/h/signals.h +++ b/h/signals.h @@ -1,4 +1,3 @@ - /* * signals.h -- header file for nmh signal interface */ diff --git a/h/tws.h b/h/tws.h index 5d99cf5..1db78c7 100644 --- a/h/tws.h +++ b/h/tws.h @@ -1,48 +1,50 @@ - /* * tws.h */ -/* If the following is #defined, a timezone given as a numeric-only offset will - be treated specially if it's in a zone that observes Daylight Saving Time. - For instance, during DST, a Date: like "Mon, 24 Jul 2000 12:31:44 -0700" will - be printed as "Mon, 24 Jul 2000 12:31:44 PDT". Without the code activated by - the following #define, that'd be incorrectly printed as "...MST". */ -#define ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST 1 +/* + * If the following is #defined, a timezone given as a numeric-only + * offset will be treated specially if it's in a zone that observes + * Daylight Saving Time. For instance, during DST, a Date: like "Mon, + * 24 Jul 2000 12:31:44 -0700" will be printed as "Mon, 24 Jul 2000 + * 12:31:44 PDT". Without the code activated by the following #define, + * that'd be incorrectly printed as "...MST". + */ +#define ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST 1 struct tws { - int tw_sec; /* seconds after the minute - [0, 61] */ - int tw_min; /* minutes after the hour - [0, 59] */ - int tw_hour; /* hour since midnight - [0, 23] */ - int tw_mday; /* day of the month - [1, 31] */ - int tw_mon; /* months since January - [0, 11] */ - int tw_year; /* 4 digit year (ie, 1997) */ - int tw_wday; /* days since Sunday - [0, 6] */ - int tw_yday; /* days since January 1 - [0, 365] */ - int tw_zone; - time_t tw_clock; /* if != 0, corresponding calendar value */ - int tw_flags; + int tw_sec; /* seconds after the minute - [0, 61] */ + int tw_min; /* minutes after the hour - [0, 59] */ + int tw_hour; /* hour since midnight - [0, 23] */ + int tw_mday; /* day of the month - [1, 31] */ + int tw_mon; /* months since January - [0, 11] */ + int tw_year; /* 4 digit year (ie, 1997) */ + int tw_wday; /* days since Sunday - [0, 6] */ + int tw_yday; /* days since January 1 - [0, 365] */ + int tw_zone; + time_t tw_clock; /* if != 0, corresponding calendar value */ + int tw_flags; }; -#define TW_NULL 0x0000 +#define TW_NULL 0x0000 -#define TW_SDAY 0x0003 /* how day-of-week was determined */ -#define TW_SNIL 0x0000 /* not given */ -#define TW_SEXP 0x0001 /* explicitly given */ -#define TW_SIMP 0x0002 /* implicitly given */ +#define TW_SDAY 0x0003 /* how day-of-week was determined */ +#define TW_SNIL 0x0000 /* not given */ +#define TW_SEXP 0x0001 /* explicitly given */ +#define TW_SIMP 0x0002 /* implicitly given */ -#define TW_SZONE 0x0004 /* how timezone was determined */ -#define TW_SZNIL 0x0000 /* not given */ -#define TW_SZEXP 0x0004 /* explicitly given */ +#define TW_SZONE 0x0004 /* how timezone was determined */ +#define TW_SZNIL 0x0000 /* not given */ +#define TW_SZEXP 0x0004 /* explicitly given */ -#define TW_DST 0x0010 /* daylight savings time */ -#define TW_ZONE 0x0020 /* use numeric timezones only */ +#define TW_DST 0x0010 /* daylight savings time */ +#define TW_ZONE 0x0020 /* use numeric timezones only */ -#define TW_SUCC 0x0040 /* whether parsing was successful */ -#define TW_YES 0x0040 /* yes, found */ -#define TW_NO 0x0000 /* no, not found */ +#define TW_SUCC 0x0040 /* whether parsing was successful */ +#define TW_YES 0x0040 /* yes, found */ +#define TW_NO 0x0000 /* no, not found */ -#define dtwszone(tw) dtimezone (tw->tw_zone, tw->tw_flags) +#define dtwszone(tw) dtimezone (tw->tw_zone, tw->tw_flags) extern char *tw_dotw[]; extern char *tw_ldotw[]; @@ -65,4 +67,3 @@ time_t dmktime (struct tws *); void set_dotw (struct tws *); struct tws *dparsetime (char *); - diff --git a/h/utils.h b/h/utils.h index b9660a5..bc5c2ec 100644 --- a/h/utils.h +++ b/h/utils.h @@ -1,4 +1,3 @@ - /* * utils.h -- utility prototypes */ diff --git a/man/Makefile.in b/man/Makefile.in index cee0747..2a5a77a 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -43,26 +43,17 @@ SEDMAN = $(SED) -f man.sed $< > $@ $(SEDMAN) # man pages to install in $(mandir)/$(manext1) -MAN1SRC = ali. anno. burst. comp. \ - dist. flist. flists. folder. folders. \ - forw. inc. install-mh. mark. mh-chart. \ - nmh. mhbuild. mhl. mhlist. mhmail. \ - mhparam. mhpath. mhshow. \ - mhstore. msgchk. \ - new. fnext. fprev. unseen. \ - next. packf. pick. prev. \ - prompter. rcvdist. rcvpack. \ - rcvstore. rcvtty. refile. \ - repl. rmf. rmm. scan. \ - send. sendfiles. show. slocal. \ - sortm. whatnow. whom. - -MAN5SRC = mh-alias. mh-draft. mh-format. \ - mh-mail. mh-profile. mh-sequence. \ +MAN1SRC = ali. anno. burst. comp. dist. flist. flists. folder. folders. \ + forw. inc. install-mh. mark. mh-chart. nmh. mhbuild. mhl. mhlist. \ + mhmail. mhparam. mhpath. mhshow. mhstore. msgchk. new. fnext. \ + fprev. unseen. next. packf. pick. prev. prompter. rcvdist. rcvpack. \ + rcvstore. rcvtty. refile. repl. rmf. rmm. scan. send. sendfiles. \ + show. slocal. sortm. whatnow. whom. + +MAN5SRC = mh-alias. mh-draft. mh-format. mh-mail. mh-profile. mh-sequence. \ mh-tailor. mts.conf. -MAN8SRC = ap. conflict. dp. fmtdump. \ - post. +MAN8SRC = ap. conflict. dp. fmtdump. post. MAN1 = $(MAN1SRC:.=.$(manext1)) MAN5 = $(MAN5SRC:.=.$(manext5)) @@ -185,7 +176,7 @@ subdir = man Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) nmhdist: $(DIST) @echo "Copying distribution files in $(subdir)" diff --git a/man/ali.man b/man/ali.man index f2fb580..772e967 100644 --- a/man/ali.man +++ b/man/ali.man @@ -14,7 +14,7 @@ ali \- list mail aliases .RB [ \-normalize " | " \-nonormalize ] .RB [ \-user " | " \-nouser ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .RI [ aliases " ...]" .ad .SH DESCRIPTION diff --git a/man/ap.man b/man/ap.man index c77b39e..30e5fb8 100644 --- a/man/ap.man +++ b/man/ap.man @@ -16,7 +16,7 @@ ap \- parse addresses 822-style .RB [ \-width .IR columns ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .I addrs \&... .ad diff --git a/man/comp.man b/man/comp.man index bfb78b3..b9c4bc6 100644 --- a/man/comp.man +++ b/man/comp.man @@ -7,7 +7,7 @@ comp \- compose a message .SH SYNOPSIS .HP 5 .na -.B comp +.B comp .RI [ +folder ] .RI [ msgs ] .RB [ \-form diff --git a/man/conflict.man b/man/conflict.man index f690596..fc9cc99 100644 --- a/man/conflict.man +++ b/man/conflict.man @@ -13,7 +13,7 @@ conflict \- search for alias/password conflicts .RB [ \-mail .IR name ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .RI [ aliasfiles \&...] .ad diff --git a/man/dist.man b/man/dist.man index ae7be11..7598e46 100644 --- a/man/dist.man +++ b/man/dist.man @@ -12,8 +12,8 @@ dist \- redistribute a message to additional addresses .RI [ msgs ] .RB [ \-form .IR formfile ] -.RB [ \-annotate " | " \-noannotate ] -.RB [ \-inplace " | " \-noinplace ] +.RB [ \-annotate " | " \-noannotate ] +.RB [ \-inplace " | " \-noinplace ] .RB [ \-draftfolder .IR +folder ] .RB [ \-draftmessage diff --git a/man/dp.man b/man/dp.man index 363f44a..e31e626 100644 --- a/man/dp.man +++ b/man/dp.man @@ -15,7 +15,7 @@ dp \- parse dates 822-style .RB [ \-width .IR columns ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .I dates \&... .ad diff --git a/man/fmtdump.man b/man/fmtdump.man index 0524f01..00127e6 100644 --- a/man/fmtdump.man +++ b/man/fmtdump.man @@ -13,7 +13,7 @@ fmtdump \- decode nmh format files .RB [ \-format .IR string ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .ad .SH DESCRIPTION .B Fmtdump diff --git a/man/folder.man b/man/folder.man index 34d3fa0..9fffec6 100644 --- a/man/folder.man +++ b/man/folder.man @@ -84,7 +84,7 @@ to exit without creating a non-existant folder. .\" .\" note - this doesn't work at present -.\" If `\-noprint' is specified, +.\" If `\-noprint' is specified, .\" a `+folder' and/or `msg' may still be specified .\" to set the current folder and/or message, .\" but the folder summary will not be printed. @@ -308,7 +308,7 @@ and/or are given, they will become the current folder and/or message. .SH BUGS -There is no way to restore the default behavior +There is no way to restore the default behavior (to ask the user whether to create a non-existant folder) after .B \-create diff --git a/man/forw.man b/man/forw.man index 877b49b..3ff187f 100644 --- a/man/forw.man +++ b/man/forw.man @@ -10,7 +10,7 @@ forw \- forward messages .B forw .RI [ +folder ] .RI [ msgs ] -.RB [ \-annotate " | " \-noannotate ] +.RB [ \-annotate " | " \-noannotate ] .RB [ \-form .IR formfile ] .RB [ \-format " | " \-noformat ] @@ -46,7 +46,7 @@ forw \- forward messages .IR number ] .RB [ \-volume .IR number ] -[other\ switches\ for\ +[other\ switches\ for\ .BR forw ] .RB [ \-version ] .RB [ \-help ] @@ -281,14 +281,14 @@ it is documented here only for completeness. The .B \-file .I msgfile -switch specifies the message to be forwarded as an +switch specifies the message to be forwarded as an exact filename rather than as an .B nmh -folder and message number. It is +folder and message number. It is intended to be used by the .B msh interface to -.BR nmh . +.BR nmh . This switch implies .BR \-noannotate . The forwarded message is simply diff --git a/man/mark.man b/man/mark.man index eff4bf0..9b9766d 100644 --- a/man/mark.man +++ b/man/mark.man @@ -14,7 +14,7 @@ mark \- manipulate message sequences .I name \&...] .RB [ \-add " | " \-delete ] -.RB [ \-list ] +.RB [ \-list ] .RB [ \-public " | " \-nopublic ] .RB [ \-zero " | " \-nozero ] .RB [ \-version ] diff --git a/man/mh-chart.man b/man/mh-chart.man index 0ea33b0..adf2a56 100644 --- a/man/mh-chart.man +++ b/man/mh-chart.man @@ -14,7 +14,7 @@ mh-chart \- Chart of nmh Commands .RB [ \-normalize " | " \-nonormalize ] .RB [ \-user " | " \-nouser ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .RI [ aliases " ...]" .HP 5 @@ -40,7 +40,7 @@ mh-chart \- Chart of nmh Commands .RB [ \-width .IR columns ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .I addrs \&... @@ -55,7 +55,7 @@ mh-chart \- Chart of nmh Commands .RB [ \-help ] .HP 5 -.B comp +.B comp .RI [ +folder ] .RI [ msgs ] .RB [ \-form @@ -84,7 +84,7 @@ mh-chart \- Chart of nmh Commands .RB [ \-mail .IR name ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .RI [ aliasfiles \&...] @@ -94,8 +94,8 @@ mh-chart \- Chart of nmh Commands .RI [ msgs ] .RB [ \-form .IR formfile ] -.RB [ \-annotate " | " \-noannotate ] -.RB [ \-inplace " | " \-noinplace ] +.RB [ \-annotate " | " \-noannotate ] +.RB [ \-inplace " | " \-noinplace ] .RB [ \-draftfolder .IR +folder ] .RB [ \-draftmessage @@ -119,7 +119,7 @@ mh-chart \- Chart of nmh Commands .RB [ \-width .IR columns ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .I dates \&... @@ -154,7 +154,7 @@ is equivalent to .RB [ \-format .IR string ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .HP 5 .B folder @@ -184,7 +184,7 @@ is equivalent to .B forw .RI [ +folder ] .RI [ msgs ] -.RB [ \-annotate " | " \-noannotate ] +.RB [ \-annotate " | " \-noannotate ] .RB [ \-form .IR formfile ] .RB [ \-format " | " \-noformat ] @@ -220,7 +220,7 @@ is equivalent to .IR number ] .RB [ \-volume .IR number ] -[other\ switches\ for\ +[other\ switches\ for\ .BR forw ] .RB [ \-version ] .RB [ \-help ] @@ -259,7 +259,7 @@ is equivalent to .I name \&...] .RB [ \-add " | " \-delete ] -.RB [ \-list ] +.RB [ \-list ] .RB [ \-public " | " \-nopublic ] .RB [ \-zero " | " \-nozero ] .RB [ \-version ] @@ -321,7 +321,7 @@ is equivalent to .RB [ \-subject .IR subject ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .HP 5 .B mhpath @@ -389,7 +389,7 @@ all/mail/nomail ] .RB [ \-help ] .HP 5 -.B next +.B next .RI [ +folder ] .RB [\-showproc .IR program ] @@ -453,12 +453,12 @@ or \&...] .RB [ \-public " | " \-nopublic ] .RB [ \-zero " | " \-nozero ] -.RB [ \-list " | " \-nolist ] +.RB [ \-list " | " \-nolist ] .RB [ \-version ] .RB [ \-help ] .HP 5 -.B %libdir%/post +.B %libdir%/post .RB [ \-alias .IR aliasfile ] .RB [ \-filter @@ -476,7 +476,7 @@ or .RB [ \-help ] .HP 5 -.B prev +.B prev .RI [ +folder ] .RB [\-showproc .IR program ] @@ -539,7 +539,7 @@ or .RB [ \-help ] .HP 5 -.B refile +.B refile .RI [ msgs ] .RB [ \-draft ] .RB [ \-link " | " \-nolink ] @@ -561,7 +561,7 @@ or .B repl .RI [ +folder ] .RI [ msgs ] -.RB [ \-annotate " | " \-noannotate ] +.RB [ \-annotate " | " \-noannotate ] .RB [ \-group " | " \-nogroup ] .RB [ \-cc all/to/cc/me] @@ -597,7 +597,7 @@ all/to/cc/me] .RB [ \-help ] .HP 5 -.B rmf +.B rmf .RI [ +folder ] .RB [ \-interactive " | " \-nointeractive ] .RB [ \-version ] @@ -654,7 +654,7 @@ all/to/cc/me] .RB [ \-width .IR columns ] .RB [ file -\&...] +\&...] .RB [ \-version ] .RB [ \-help ] diff --git a/man/mh-format.man b/man/mh-format.man index 8925b8c..80021df 100644 --- a/man/mh-format.man +++ b/man/mh-format.man @@ -86,7 +86,7 @@ The argument follows the function escape: separating whitespace is discarded: .RI `%( function " " argument )'. .PP -In addition to literal numbers or strings, +In addition to literal numbers or strings, the argument to a function escape can be another function, a component, or a control escape. When the argument is a function or a component, they are listed without a leading `%'. When control escapes @@ -97,7 +97,7 @@ a leading `%'; .PP A .I control -escape is one of: `%<', `%?', `%|', or `%>'. +escape is one of: `%<', `%?', `%|', or `%>'. These are combined into the conditional execution construct: .PP .RS 5 @@ -115,11 +115,11 @@ constructs may be nested without ambiguity. They form a general .B if\-elseif\-else\-endif block where only one of the format-texts -is interpreted. In other -words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like +is interpreted. In other +words, `%<' is like the "if", `%?' is like the "elseif", `%|' is like "else", and `%>' is like "endif". .PP -A `%<' or `%?' control escape causes its condition to be evaluated. +A `%<' or `%?' control escape causes its condition to be evaluated. This condition is a .I component or @@ -127,7 +127,7 @@ or For integer valued functions or components, the condition is true if the function return or component value is non-zero, and false if zero. For string valued functions or components, the condition is true -if the function return or component value is +if the function return or component value is a non-empty string, and false for an empty string. .PP @@ -172,7 +172,7 @@ are required. When escapes are nested (via expr arguments), evaluation is done from inner-most to outer-most. As noted above, for the expr -argument type, +argument type, functions and components are written without a leading `%'. Control escape arguments must use a leading `%', preceded by a space. @@ -187,10 +187,10 @@ For example, .PP writes the value of the header component \*(lqFrom:\*(rq to the internal register named str; then (\fImymbox\fR\^) reads str and -writes its result to the internal register named -.IR num ; -then the control escape evaluates -.IR num . +writes its result to the internal register named +.IR num ; +then the control escape evaluates +.IR num . If .IR num is non-zero, the @@ -267,7 +267,7 @@ num integer Set \fInum\fR to zero. lit literal string Set \fIstr\fR to \fIarg\fR. lit string Clear \fIstr\fR. getenv literal string Set \fIstr\fR to environment value of \fIarg\fR -profile literal string Set \fIstr\fR to profile component \fIarg\fR +profile literal string Set \fIstr\fR to profile component \fIarg\fR value .\" dat literal int return value of dat[arg] nonzero expr boolean \fInum\fR is non-zero @@ -279,7 +279,7 @@ comp comp string Set \fIstr\fR to component text compval comp integer Set \fInum\fR to \*(lq\fBatoi\fR(\fIcomp\fR\^)\*(rq .\" compflag comp integer Set \fInum\fR to component flags bits (internal) .\" decodecomp comp string Set \fIstr\fR to RFC-2047 decoded component text -decode expr string decode \fIstr\fR as RFC-2047 (MIME-encoded) +decode expr string decode \fIstr\fR as RFC-2047 (MIME-encoded) component unquote expr string remove RFC-2822 quotes from \fIstr\fR trim expr trim trailing white-space from \fIstr\fR @@ -331,7 +331,7 @@ pretty date string user-friendly rendering .fi .RE .PP -These functions require an address component as an argument. +These functions require an address component as an argument. The return value of functions noted with `*' is computed from the first address present in the header component. .PP @@ -473,7 +473,7 @@ format file. .PP This clears .I str -and formats the \*(lqReply-To:\*(rq header +and formats the \*(lqReply-To:\*(rq header if present. If not present, the else-if clause is executed. .PP .RS 5 @@ -482,7 +482,7 @@ if present. If not present, the else-if clause is executed. .fi .RE .PP -This formats the +This formats the \*(lqFrom:\*(rq, \*(lqSender:\*(rq and \*(lqReturn-Path:\*(rq headers, stopping as soon as one of them is present. Next: .PP @@ -595,7 +595,7 @@ Nontheless (as noted above) the various scan format strings are inherited from older MH versions, and are generally hard-coded to 4 digits of message number before formatting problems -start to occur. +start to occur. The nmh format strings can be modified to behave more sensibly with larger message numbers: .PP diff --git a/man/mh-profile.man b/man/mh-profile.man index 19399fb..afe5444 100644 --- a/man/mh-profile.man +++ b/man/mh-profile.man @@ -256,9 +256,9 @@ If present, tells .B inc to compose an .I MHE -auditfile in addition to its other tasks. +auditfile in addition to its other tasks. .I MHE -is Brian Reid's +is Brian Reid's .B emacs front-end for .BR nmh . diff --git a/man/mhl.man b/man/mhl.man index f8546c3..d824b47 100644 --- a/man/mhl.man +++ b/man/mhl.man @@ -346,7 +346,7 @@ show(1), ap(8), dp(8) None .SH BUGS -There should be some way to pass `bell' and `clear' information to the +There should be some way to pass `bell' and `clear' information to the front\-end. .PP The \*(lqnonewline\*(rq option interacts badly with \*(lqcompress\*(rq diff --git a/man/mhmail.man b/man/mhmail.man index 6e3cf13..ba2edcb 100644 --- a/man/mhmail.man +++ b/man/mhmail.man @@ -20,7 +20,7 @@ mhmail \- send or read mail .RB [ \-subject .IR subject ] .RB [ \-version ] -.RB [ \-help ] +.RB [ \-help ] .ad .SH DESCRIPTION .B mhmail diff --git a/man/next.man b/man/next.man index eecc044..613b500 100644 --- a/man/next.man +++ b/man/next.man @@ -7,7 +7,7 @@ next \- show the next message .SH SYNOPSIS .HP 5 .na -.B next +.B next .RI [ +folder ] .RB [\-showproc .IR program ] diff --git a/man/nmh.man b/man/nmh.man index 9b1f955..6152ccb 100644 --- a/man/nmh.man +++ b/man/nmh.man @@ -194,7 +194,7 @@ commands: ^ali(1)~^\- list mail aliases ^anno(1)~^\- annotate messages ^burst(1)~^\- explode digests into messages -^comp(1)~^\- compose a message +^comp(1)~^\- compose a message ^dist(1)~^\- redistribute a message to additional addresses ^flist(1)~^\- list folders with messages in given sequence(s) ^flists(1)~^\- list all folders with messages in given sequence(s) diff --git a/man/packf.man b/man/packf.man index fd32b3a..cdc4ee6 100644 --- a/man/packf.man +++ b/man/packf.man @@ -50,7 +50,7 @@ makes an mbox-style delimiter by examining the first line of the message. If the first line is a \*(lqReturn-Path\*(rq field, its address and the current date and time are used. Otherwise, if the first line has an \*(lqX-Envelope-From\*(rq field, its -contents (which should already be in the correct format) are used. +contents (which should already be in the correct format) are used. Otherwise, a dummy address and the current date and time are used. .PP Messages that are packed by diff --git a/man/pick.man b/man/pick.man index 1a1b0ff..c5ef463 100644 --- a/man/pick.man +++ b/man/pick.man @@ -44,7 +44,7 @@ pick \- search for messages by content \&...] .RB [ \-public " | " \-nopublic ] .RB [ \-zero " | " \-nozero ] -.RB [ \-list " | " \-nolist ] +.RB [ \-list " | " \-nolist ] .RB [ \-version ] .RB [ \-help ] .PP diff --git a/man/post.man b/man/post.man index 2f771da..c90b4ee 100644 --- a/man/post.man +++ b/man/post.man @@ -7,7 +7,7 @@ post \- deliver a message .SH SYNOPSIS .HP 5 .na -.B %libdir%/post +.B %libdir%/post .RB [ \-alias .IR aliasfile ] .RB [ \-filter @@ -170,7 +170,7 @@ header. This is useful in pretending to send mail \*(lqdirectly\*(rq from a rem account, or when remote email robots give improper precedence to the envelope \*(lqFrom:\*(rq. Note that your MTA may still reveal your real identity (e.g. .BR sendmail 's -\*(lqX\-Authentication\-Warning:\*(rq header). +\*(lqX\-Authentication\-Warning:\*(rq header). .PP If nmh is using the SMTP MTA, the .B \-server diff --git a/man/prev.man b/man/prev.man index 6ef0b8e..4703cae 100644 --- a/man/prev.man +++ b/man/prev.man @@ -7,7 +7,7 @@ prev \- show the previous message .SH SYNOPSIS .HP 5 .na -.B prev +.B prev .RI [ +folder ] .RB [\-showproc .IR program ] diff --git a/man/rcvpack.man b/man/rcvpack.man index 26ba263..ca00d6b 100644 --- a/man/rcvpack.man +++ b/man/rcvpack.man @@ -25,7 +25,7 @@ If the switch is given (the default), then the messages are separated using mbox (uucp) style delimiters. This is the format used by most mail clients (elm, mailx, etc.). -.PP +.PP If the .B \-mmdf switch is given, then the messages are separated by diff --git a/man/refile.man b/man/refile.man index 4b55fe1..f9b805a 100644 --- a/man/refile.man +++ b/man/refile.man @@ -7,7 +7,7 @@ refile \- file message in other folders .SH SYNOPSIS .HP 5 .na -.B refile +.B refile .RI [ msgs ] .RB [ \-draft ] .RB [ \-link " | " \-nolink ] diff --git a/man/repl.man b/man/repl.man index 9f2f489..bb4a7e5 100644 --- a/man/repl.man +++ b/man/repl.man @@ -10,7 +10,7 @@ repl \- reply to a message .B repl .RI [ +folder ] .RI [ msgs ] -.RB [ \-annotate " | " \-noannotate ] +.RB [ \-annotate " | " \-noannotate ] .RB [ \-group " | " \-nogroup ] .RB [ \-cc all/to/cc/me] @@ -89,7 +89,7 @@ Subject: Re: In\-Reply\-To: References: Comments: In\-Reply\-To or or -.ti +3 +.ti +3 message dated -------- .fi @@ -443,14 +443,14 @@ it is documented here only for completeness. The .B \-file .I msgfile -switch specifies the message to be replied to as an +switch specifies the message to be replied to as an exact filename rather than as an .B nmh -folder and message number. It is +folder and message number. It is intended to be used by the .B msh interface to -.BR nmh . +.BR nmh . The same caveats apply to this option as to the .B \-build switch. diff --git a/man/rmf.man b/man/rmf.man index 047db5a..22c0046 100644 --- a/man/rmf.man +++ b/man/rmf.man @@ -7,7 +7,7 @@ rmf \- remove an nmh folder .SH SYNOPSIS .HP 5 .na -.B rmf +.B rmf .RI [ +folder ] .RB [ \-interactive " | " \-nointeractive ] .RB [ \-version ] diff --git a/man/send.man b/man/send.man index 6fa3547..a45eb8f 100644 --- a/man/send.man +++ b/man/send.man @@ -35,7 +35,7 @@ send \- send a message .RB [ \-width .IR columns ] .RB [ file -\&...] +\&...] .RB [ \-version ] .RB [ \-help ] .RB [ \-attach @@ -129,7 +129,7 @@ values: -attachformat 0: Content-Type: text/plain; name="VERSION"; x-unix-mode="0644"; charset="us-ascii" -Content-Description: ASCII text +Content-Description: ASCII text -attachformat 1: Content-Type: text/plain; name="VERSION"; charset="us-ascii" diff --git a/man/sendfiles.man b/man/sendfiles.man index 76b793a..ed67329 100644 --- a/man/sendfiles.man +++ b/man/sendfiles.man @@ -149,7 +149,7 @@ to perform the extraction. .fi .SH "SEE ALSO" -mhbuild(1), mhlist(1), mhshow(1), mhstore(1). +mhbuild(1), mhlist(1), mhshow(1), mhstore(1). .I "Proposed Standard for Message Encapsulation" (RFC\-934) diff --git a/sbr/Makefile.in b/sbr/Makefile.in index 581cc6d..9e69965 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -27,8 +27,8 @@ TSORT = @TSORT@ RANLIB = @RANLIB@ LIBTOOL = @LIBTOOL@ GNU_LIBTOOL = @GNU_LIBTOOL@ -LINT = @LINT@ -LINTFLAGS = @LINTFLAGS@ +LINT = @LINT@ +LINTFLAGS = @LINTFLAGS@ LIBOBJS = @LIBOBJS@ @@ -50,36 +50,36 @@ COMPILE2 = $(CC) -c $(DEFS) $(CONFIGDEFS) $(INCLUDES) $(CFLAGS) SIGNAL_H = @SIGNAL_H@ # source for library functions -SRCS = addrsbr.c ambigsw.c atooi.c brkstring.c \ - check_charset.c client.c closefds.c concat.c context_del.c \ - context_find.c context_foil.c context_read.c \ - context_replace.c context_save.c copy.c \ - copyip.c cpydata.c cpydgst.c crawl_folders.c \ - discard.c done.c dtime.c dtimep.c \ - error.c ext_hook.c fdcompare.c folder_addmsg.c folder_delmsgs.c \ - folder_free.c folder_pack.c folder_read.c \ - folder_realloc.c gans.c getans.c getanswer.c \ - getarguments.c getcpy.c getfolder.c getpass.c \ - fmt_addr.c fmt_compile.c fmt_new.c fmt_rfc2047.c \ - fmt_scan.c lock_file.c m_atoi.c m_backup.c \ - m_convert.c m_draft.c m_getfld.c m_gmprot.c \ - m_maildir.c m_name.c m_scratch.c m_tmpfil.c \ - makedir.c mts.c norm_charmap.c \ - path.c peekc.c pidwait.c pidstatus.c \ - print_help.c print_sw.c print_version.c push.c \ - putenv.c refile.c remdir.c r1bindex.c \ - readconfig.c ruserpass.c seq_add.c seq_bits.c \ - seq_del.c seq_getnum.c seq_list.c seq_nameok.c \ - seq_print.c seq_read.c seq_save.c seq_setcur.c \ - seq_setprev.c seq_setunseen.c showfile.c signals.c \ - smatch.c snprintb.c ssequal.c strcasecmp.c \ - strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c \ +SRCS = addrsbr.c ambigsw.c atooi.c brkstring.c \ + check_charset.c client.c closefds.c concat.c context_del.c \ + context_find.c context_foil.c context_read.c \ + context_replace.c context_save.c copy.c \ + copyip.c cpydata.c cpydgst.c crawl_folders.c \ + discard.c done.c dtime.c dtimep.c \ + error.c ext_hook.c fdcompare.c folder_addmsg.c folder_delmsgs.c \ + folder_free.c folder_pack.c folder_read.c \ + folder_realloc.c gans.c getans.c getanswer.c \ + getarguments.c getcpy.c getfolder.c getpass.c \ + fmt_addr.c fmt_compile.c fmt_new.c fmt_rfc2047.c \ + fmt_scan.c lock_file.c m_atoi.c m_backup.c \ + m_convert.c m_draft.c m_getfld.c m_gmprot.c \ + m_maildir.c m_name.c m_scratch.c m_tmpfil.c \ + makedir.c mts.c norm_charmap.c \ + path.c peekc.c pidwait.c pidstatus.c \ + print_help.c print_sw.c print_version.c push.c \ + putenv.c refile.c remdir.c r1bindex.c \ + readconfig.c ruserpass.c seq_add.c seq_bits.c \ + seq_del.c seq_getnum.c seq_list.c seq_nameok.c \ + seq_print.c seq_read.c seq_save.c seq_setcur.c \ + seq_setprev.c seq_setunseen.c showfile.c signals.c \ + smatch.c snprintb.c ssequal.c strcasecmp.c \ + strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c \ m_msgdef.c mf.c utils.c m_mktemp.c # source for compatibility functions COMPAT = memmove.c snprintf.c strdup.c strerror.c -OBJS = $(SRCS:.c=.o) $(LIBOBJS) +OBJS = $(SRCS:.c=.o) $(LIBOBJS) # auxiliary files AUX = Makefile.in sigmsg.awk dtimep.lex @@ -147,7 +147,7 @@ subdir = sbr Makefile: Makefile.in ../config.status cd .. && ./config.status $(subdir)/$@ - + distdir = ../`cat ../distname`/$(subdir) nmhdist: $(DIST) @echo "Copying distribution files in $(subdir)" diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index 79d7afe..4ab3fec 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -1,4 +1,3 @@ - /* * addrsbr.c -- parse addresses 822-style * @@ -11,54 +10,55 @@ #include #include -/* High level parsing of addresses: - - The routines in sbr/mf.c parse the syntactic representations of - addresses. The routines in sbr/addrsbr.c associate semantics with those - addresses. - - If #ifdef DUMB is in effect, a full 822-style parser is called - for syntax recongition. This breaks each address into its components. - Note however that no semantics are assumed about the parts or their - totality. This means that implicit hostnames aren't made explicit, - and explicit hostnames aren't expanded to their "official" represenations. - - If DUMB is not in effect, then this module does some - high-level thinking about what the addresses are. - - 1. for MMDF systems: - - string%@ -> string - - 2. for non-MMDF systems: - - string@host. -> host!string - - 3. for any system, an address interpreted relative to the local host: - - string@ -> string - - For cases (1) and (3) above, the leftmost host is extracted. If it's not - present, the local host is used. If the tests above fail, the address is - considered to be a real 822-style address. - - If an explicit host is not present, then MH checks for a bang to indicate - an explicit UUCP-style address. If so, this is noted. If not, the host is - defaulted, typically to the local host. The lack of an explict host is - also noted. - - If an explicit 822-style host is present, then MH checks to see if it - can expand this to the official name for the host. If the hostname is - unknown, the address is so typed. - - To summarize, when we're all done, here's what MH knows about the address: - - DUMB - type: local, uucp, or network - host: not locally defaulted, not explicitly expanded - everything else - - other - type: local, uucp, network, unknown - everything else +/* + * High level parsing of addresses: + * + * The routines in sbr/mf.c parse the syntactic representations of + * addresses. The routines in sbr/addrsbr.c associate semantics with those + * addresses. + * + * If #ifdef DUMB is in effect, a full 822-style parser is called + * for syntax recongition. This breaks each address into its components. + * Note however that no semantics are assumed about the parts or their + * totality. This means that implicit hostnames aren't made explicit, + * and explicit hostnames aren't expanded to their "official" represenations. + * + * If DUMB is not in effect, then this module does some + * high-level thinking about what the addresses are. + * + * 1. for MMDF systems: + * + * string%@ -> string + * + * 2. for non-MMDF systems: + * + * string@host. -> host!string + * + * 3. for any system, an address interpreted relative to the local host: + * + * string@ -> string + * + * For cases (1) and (3) above, the leftmost host is extracted. If it's not + * present, the local host is used. If the tests above fail, the address is + * considered to be a real 822-style address. + * + * If an explicit host is not present, then MH checks for a bang to indicate + * an explicit UUCP-style address. If so, this is noted. If not, the host is + * defaulted, typically to the local host. The lack of an explict host is + * also noted. + * + * If an explicit 822-style host is present, then MH checks to see if it + * can expand this to the official name for the host. If the hostname is + * unknown, the address is so typed. + * + * To summarize, when we're all done, here's what MH knows about the address: + * + * DUMB - type: local, uucp, or network + * host: not locally defaulted, not explicitly expanded + * everything else + * + * other - type: local, uucp, network, unknown + * everything else */ @@ -85,184 +85,177 @@ char *getusername (void); char * getname (char *addrs) { - struct adrx *ap; - - pers = mbox = host = route = grp = note = NULL; - err[0] = '\0'; - - if ((ap = getadrx (addrs ? addrs : "")) == NULL) - return NULL; - - strncpy (adr, ap->text, sizeof(adr)); - pers = ap->pers; - mbox = ap->mbox; - host = ap->host; - route = ap->path; - grp = ap->grp; - ingrp = ap->ingrp; - note = ap->note; - if (ap->err && *ap->err) - strncpy (err, ap->err, sizeof(err)); - - return adr; + struct adrx *ap; + + pers = mbox = host = route = grp = note = NULL; + err[0] = '\0'; + + if ((ap = getadrx (addrs ? addrs : "")) == NULL) + return NULL; + + strncpy (adr, ap->text, sizeof(adr)); + pers = ap->pers; + mbox = ap->mbox; + host = ap->host; + route = ap->path; + grp = ap->grp; + ingrp = ap->ingrp; + note = ap->note; + if (ap->err && *ap->err) + strncpy (err, ap->err, sizeof(err)); + + return adr; } struct mailname * getm (char *str, char *dfhost, int dftype, int wanthost, char *eresult) { - char *pp; - struct mailname *mp; -#ifndef DUMB - char *dp; + char *pp; + struct mailname *mp; +#ifndef DUMB + char *dp; #endif /* not DUMB */ - if (err[0]) { - if (eresult) - strcpy (eresult, err); - else - if (wanthost == AD_HOST) - admonish (NULL, "bad address '%s' - %s", str, err); - return NULL; - } - if (pers == NULL - && mbox == NULL && host == NULL && route == NULL - && grp == NULL) { - if (eresult) - strcpy (eresult, "null address"); - else - if (wanthost == AD_HOST) - admonish (NULL, "null address '%s'", str); - return NULL; - } - if (mbox == NULL && grp == NULL) { - if (eresult) - strcpy (eresult, "no mailbox in address"); - else - if (wanthost == AD_HOST) - admonish (NULL, "no mailbox in address '%s'", str); - return NULL; - } - - if (dfhost == NULL) { - dfhost = LocalName (); - dftype = LOCALHOST; - } - - mp = (struct mailname *) calloc ((size_t) 1, sizeof(*mp)); - if (mp == NULL) { - if (eresult) - strcpy (eresult, "insufficient memory to represent address"); - else - if (wanthost == AD_HOST) - adios (NULL, "insufficient memory to represent address"); - return NULL; - } - - mp->m_next = NULL; - mp->m_text = getcpy (str); - if (pers) - mp->m_pers = getcpy (pers); - - if (mbox == NULL) { - mp->m_type = BADHOST; - mp->m_nohost = 1; - mp->m_ingrp = ingrp; - mp->m_gname = getcpy (grp); - if (note) - mp->m_note = getcpy (note); - return mp; - } - - if (host) { - mp->m_mbox = getcpy (mbox); - mp->m_host = getcpy (host); - } - else { - if ((pp = strchr(mbox, '!'))) { - *pp++ = '\0'; - mp->m_mbox = getcpy (pp); - mp->m_host = getcpy (mbox); - mp->m_type = UUCPHOST; + if (err[0]) { + if (eresult) + strcpy (eresult, err); + else + if (wanthost == AD_HOST) + admonish (NULL, "bad address '%s' - %s", str, err); + return NULL; + } + if (pers == NULL && mbox == NULL && host == NULL && route == NULL + && grp == NULL) { + if (eresult) + strcpy (eresult, "null address"); + else + if (wanthost == AD_HOST) + admonish (NULL, "null address '%s'", str); + return NULL; + } + if (mbox == NULL && grp == NULL) { + if (eresult) + strcpy (eresult, "no mailbox in address"); + else if (wanthost == AD_HOST) + admonish (NULL, "no mailbox in address '%s'", str); + return NULL; + } + + if (dfhost == NULL) { + dfhost = LocalName (); + dftype = LOCALHOST; + } + + mp = (struct mailname *) calloc ((size_t) 1, sizeof(*mp)); + if (mp == NULL) { + if (eresult) + strcpy (eresult, "insufficient memory to represent address"); + else if (wanthost == AD_HOST) + adios (NULL, "insufficient memory to represent address"); + return NULL; } - else { - mp->m_nohost = 1; - mp->m_mbox = getcpy (mbox); + + mp->m_next = NULL; + mp->m_text = getcpy (str); + if (pers) + mp->m_pers = getcpy (pers); + + if (mbox == NULL) { + mp->m_type = BADHOST; + mp->m_nohost = 1; + mp->m_ingrp = ingrp; + mp->m_gname = getcpy (grp); + if (note) + mp->m_note = getcpy (note); + return mp; + } + + if (host) { + mp->m_mbox = getcpy (mbox); + mp->m_host = getcpy (host); + } else { + if ((pp = strchr(mbox, '!'))) { + *pp++ = '\0'; + mp->m_mbox = getcpy (pp); + mp->m_host = getcpy (mbox); + mp->m_type = UUCPHOST; + } else { + mp->m_nohost = 1; + mp->m_mbox = getcpy (mbox); #ifdef DUMB - if (route == NULL && dftype == LOCALHOST) { - mp->m_host = NULL; - mp->m_type = dftype; - } - else + if (route == NULL && dftype == LOCALHOST) { + mp->m_host = NULL; + mp->m_type = dftype; + } else #endif /* DUMB */ - { - mp->m_host = route ? NULL : getcpy (dfhost); - mp->m_type = route ? NETHOST : dftype; - } + { + mp->m_host = route ? NULL : getcpy (dfhost); + mp->m_type = route ? NETHOST : dftype; + } + } + goto got_host; } - goto got_host; - } - if (wanthost == AD_NHST) - mp->m_type = !mh_strcasecmp (LocalName (), mp->m_host) - ? LOCALHOST : NETHOST; + if (wanthost == AD_NHST) + mp->m_type = !mh_strcasecmp (LocalName (), mp->m_host) + ? LOCALHOST : NETHOST; #ifdef DUMB - else - mp->m_type = mh_strcasecmp (LocalName(), mp->m_host) ? NETHOST : LOCALHOST; + else + mp->m_type = mh_strcasecmp (LocalName(), mp->m_host) ? NETHOST : LOCALHOST; #else /* not DUMB */ - else - if (pp = OfficialName (mp->m_host)) { - got_real_host: ; - free (mp->m_host); - mp->m_host = getcpy (pp); - mp->m_type = mh_strcasecmp (LocalName(), mp->m_host) ? NETHOST : LOCALHOST; - } - else { - if (dp = strchr(mp->m_host, '.')) { - *dp = NULL; - if (pp = OfficialName (mp->m_host)) - goto got_real_host; - *dp = '.'; - } - mp->m_type = BADHOST; - } + else + if (pp = OfficialName (mp->m_host)) { + got_real_host: ; + free (mp->m_host); + mp->m_host = getcpy (pp); + mp->m_type = mh_strcasecmp (LocalName(), mp->m_host) ? NETHOST : LOCALHOST; + } else { + if (dp = strchr(mp->m_host, '.')) { + *dp = NULL; + if (pp = OfficialName (mp->m_host)) + goto got_real_host; + *dp = '.'; + } + mp->m_type = BADHOST; + } #endif /* not DUMB */ got_host: ; - if (route) - mp->m_path = getcpy (route); - mp->m_ingrp = ingrp; - if (grp) - mp->m_gname = getcpy (grp); - if (note) - mp->m_note = getcpy (note); - - return mp; + if (route) + mp->m_path = getcpy (route); + mp->m_ingrp = ingrp; + if (grp) + mp->m_gname = getcpy (grp); + if (note) + mp->m_note = getcpy (note); + + return mp; } void mnfree (struct mailname *mp) { - if (!mp) - return; - - if (mp->m_text) - free (mp->m_text); - if (mp->m_pers) - free (mp->m_pers); - if (mp->m_mbox) - free (mp->m_mbox); - if (mp->m_host) - free (mp->m_host); - if (mp->m_path) - free (mp->m_path); - if (mp->m_gname) - free (mp->m_gname); - if (mp->m_note) - free (mp->m_note); - - free ((char *) mp); + if (!mp) + return; + + if (mp->m_text) + free (mp->m_text); + if (mp->m_pers) + free (mp->m_pers); + if (mp->m_mbox) + free (mp->m_mbox); + if (mp->m_host) + free (mp->m_host); + if (mp->m_path) + free (mp->m_path); + if (mp->m_gname) + free (mp->m_gname); + if (mp->m_note) + free (mp->m_note); + + free ((char *) mp); } @@ -271,43 +264,41 @@ mnfree (struct mailname *mp) char * auxformat (struct mailname *mp, int extras) { - static char addr[BUFSIZ]; - static char buffer[BUFSIZ]; + static char addr[BUFSIZ]; + static char buffer[BUFSIZ]; #ifdef DUMB if (mp->m_nohost) - strncpy (addr, mp->m_mbox ? mp->m_mbox : "", sizeof(addr)); + strncpy (addr, mp->m_mbox ? mp->m_mbox : "", sizeof(addr)); else #endif /* DUMB */ -#ifndef BANG +#ifndef BANG if (mp->m_type != UUCPHOST) - snprintf (addr, sizeof(addr), mp->m_host ? "%s%s@%s" : "%s%s", - empty(mp->m_path), empty(mp->m_mbox), mp->m_host); + snprintf (addr, sizeof(addr), mp->m_host ? "%s%s@%s" : "%s%s", + empty(mp->m_path), empty(mp->m_mbox), mp->m_host); else #endif /* not BANG */ - snprintf (addr, sizeof(addr), "%s!%s", mp->m_host, mp->m_mbox); - - if (!extras) - return addr; - - if (mp->m_pers || mp->m_path) { - if (mp->m_note) - snprintf (buffer, sizeof(buffer), "%s %s <%s>", - legal_person (mp->m_pers ? mp->m_pers : mp->m_mbox), - mp->m_note, addr); + snprintf (addr, sizeof(addr), "%s!%s", mp->m_host, mp->m_mbox); + + if (!extras) + return addr; + + if (mp->m_pers || mp->m_path) { + if (mp->m_note) + snprintf (buffer, sizeof(buffer), "%s %s <%s>", + legal_person (mp->m_pers ? mp->m_pers : mp->m_mbox), + mp->m_note, addr); + else + snprintf (buffer, sizeof(buffer), "%s <%s>", + legal_person (mp->m_pers ? mp->m_pers : mp->m_mbox), + addr); + } else if (mp->m_note) + snprintf (buffer, sizeof(buffer), "%s %s", addr, mp->m_note); else - snprintf (buffer, sizeof(buffer), "%s <%s>", - legal_person (mp->m_pers ? mp->m_pers : mp->m_mbox), - addr); - } - else - if (mp->m_note) - snprintf (buffer, sizeof(buffer), "%s %s", addr, mp->m_note); - else - strncpy (buffer, addr, sizeof(buffer)); + strncpy (buffer, addr, sizeof(buffer)); - return buffer; + return buffer; } @@ -318,65 +309,66 @@ auxformat (struct mailname *mp, int extras) char * adrsprintf (char *username, char *domain) { - int snprintf_return; - static char addr[BUFSIZ]; - - if (username == NULL) - username = getusername(); - - if (username_extension_masquerading) { - /* mts.conf contains "masquerade:[...]username_extension[...]", so tack - on the value of the $USERNAME_EXTENSION environment variable, if set, - to username. */ - char* extension = getenv("USERNAME_EXTENSION"); - static char username_with_extension[BUFSIZ]; - - if (extension != NULL && *extension != '\0') { - snprintf_return = snprintf(username_with_extension, - sizeof(username_with_extension), - "%s%s", username, extension); - - if (snprintf_return < 0 || - snprintf_return >= sizeof(username_with_extension)) - adios(NULL, "snprintf() error writing username (%d chars) and" - " $USERNAME_EXTENSION (%d chars) to array of BUFSIZ (%d)" - " chars", - strlen(username), strlen(extension), BUFSIZ); - - username = username_with_extension; + int snprintf_return; + static char addr[BUFSIZ]; + + if (username == NULL) + username = getusername(); + + if (username_extension_masquerading) { + /* mts.conf contains "masquerade:[...]username_extension[...]", + * so tack on the value of the $USERNAME_EXTENSION environment + * variable, if set, to username. + */ + char* extension = getenv("USERNAME_EXTENSION"); + static char username_with_extension[BUFSIZ]; + + if (extension != NULL && *extension != '\0') { + snprintf_return = snprintf(username_with_extension, + sizeof(username_with_extension), + "%s%s", username, extension); + + if (snprintf_return < 0 || + snprintf_return >= sizeof(username_with_extension)) + adios(NULL, "snprintf() error writing username (%d chars) and" + " $USERNAME_EXTENSION (%d chars) to array of BUFSIZ (%d)" + " chars", + strlen(username), strlen(extension), BUFSIZ); + + username = username_with_extension; + } } - } #ifdef REALLYDUMB - return username; + return username; #endif - if (domain == NULL) - domain = LocalName(); + if (domain == NULL) + domain = LocalName(); -#ifndef BANG - snprintf_return = snprintf (addr, sizeof(addr), "%s@%s", username, domain); +#ifndef BANG + snprintf_return = snprintf (addr, sizeof(addr), "%s@%s", username, domain); #else /* BANG */ - snprintf_return = snprintf (addr, sizeof(addr), "%s!%s", domain, username); + snprintf_return = snprintf (addr, sizeof(addr), "%s!%s", domain, username); #endif /* BANG */ - if (snprintf_return < 0 || snprintf_return >= sizeof(addr)) - adios(NULL, "snprintf() error writing username (%d chars), domain (%d" - " chars), and 1 separator char to array of BUFSIZ (%d) chars", - strlen(username), strlen(domain), BUFSIZ); - - return addr; + if (snprintf_return < 0 || snprintf_return >= sizeof(addr)) + adios(NULL, "snprintf() error writing username (%d chars), domain (%d" + " chars), and 1 separator char to array of BUFSIZ (%d) chars", + strlen(username), strlen(domain), BUFSIZ); + + return addr; } -#define W_NIL 0x0000 -#define W_MBEG 0x0001 -#define W_MEND 0x0002 -#define W_MBOX (W_MBEG | W_MEND) -#define W_HBEG 0x0004 -#define W_HEND 0x0008 -#define W_HOST (W_HBEG | W_HEND) -#define WBITS "\020\01MBEG\02MEND\03HBEG\04HEND" +#define W_NIL 0x0000 +#define W_MBEG 0x0001 +#define W_MEND 0x0002 +#define W_MBOX (W_MBEG | W_MEND) +#define W_HBEG 0x0004 +#define W_HEND 0x0008 +#define W_HOST (W_HBEG | W_HEND) +#define WBITS "\020\01MBEG\02MEND\03HBEG\04HEND" /* * Check if this is my address @@ -385,146 +377,146 @@ adrsprintf (char *username, char *domain) int ismymbox (struct mailname *np) { - int oops; - register int len, i; - register char *cp; - register char *pp; - char buffer[BUFSIZ]; - struct mailname *mp; - static char *am = NULL; - static struct mailname mq={NULL}; - - /* - * If this is the first call, initialize - * list of alternate mailboxes. - */ - if (am == NULL) { - mq.m_next = NULL; - mq.m_mbox = getusername (); - if ((am = context_find ("alternate-mailboxes")) == NULL) - am = getusername(); - else { - mp = &mq; - oops = 0; - while ((cp = getname (am))) { - if ((mp->m_next = getm (cp, NULL, 0, AD_NAME, NULL)) == NULL) { - admonish (NULL, "illegal address: %s", cp); - oops++; - } else { - mp = mp->m_next; - mp->m_type = W_NIL; - if (*mp->m_mbox == '*') { - mp->m_type |= W_MBEG; - mp->m_mbox++; - } - if (*(cp = mp->m_mbox + strlen (mp->m_mbox) - 1) == '*') { - mp->m_type |= W_MEND; - *cp = '\0'; - } - if (mp->m_host) { - if (*mp->m_host == '*') { - mp->m_type |= W_HBEG; - mp->m_host++; - } - if (*(cp = mp->m_host + strlen (mp->m_host) - 1) == '*') { - mp->m_type |= W_HEND; - *cp = '\0'; + int oops; + register int len, i; + register char *cp; + register char *pp; + char buffer[BUFSIZ]; + struct mailname *mp; + static char *am = NULL; + static struct mailname mq={NULL}; + + /* + * If this is the first call, initialize + * list of alternate mailboxes. + */ + if (am == NULL) { + mq.m_next = NULL; + mq.m_mbox = getusername (); + if ((am = context_find ("alternate-mailboxes")) == NULL) + am = getusername(); + else { + mp = &mq; + oops = 0; + while ((cp = getname (am))) { + if ((mp->m_next = getm (cp, NULL, 0, AD_NAME, NULL)) == NULL) { + admonish (NULL, "illegal address: %s", cp); + oops++; + } else { + mp = mp->m_next; + mp->m_type = W_NIL; + if (*mp->m_mbox == '*') { + mp->m_type |= W_MBEG; + mp->m_mbox++; + } + if (*(cp = mp->m_mbox + strlen (mp->m_mbox) - 1) == '*') { + mp->m_type |= W_MEND; + *cp = '\0'; + } + if (mp->m_host) { + if (*mp->m_host == '*') { + mp->m_type |= W_HBEG; + mp->m_host++; + } + if (*(cp = mp->m_host + strlen (mp->m_host) - 1) == '*') { + mp->m_type |= W_HEND; + *cp = '\0'; + } + } + if ((cp = getenv ("MHWDEBUG")) && *cp) + fprintf (stderr, "mbox=\"%s\" host=\"%s\" %s\n", + mp->m_mbox, mp->m_host, + snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type, WBITS)); + } } - } - if ((cp = getenv ("MHWDEBUG")) && *cp) - fprintf (stderr, "mbox=\"%s\" host=\"%s\" %s\n", - mp->m_mbox, mp->m_host, - snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type, WBITS)); + if (oops) + advise (NULL, "please fix the %s: entry in your %s file", + "alternate-mailboxes", mh_profile); } - } - if (oops) - advise (NULL, "please fix the %s: entry in your %s file", - "alternate-mailboxes", mh_profile); } - } - if (np == NULL) /* XXX */ - return 0; - - switch (np->m_type) { - case NETHOST: - len = strlen (cp = LocalName ()); - if (!uprf (np->m_host, cp) || np->m_host[len] != '.') - break; - goto local_test; - - case UUCPHOST: - if (mh_strcasecmp (np->m_host, SystemName())) - break; /* fall */ - case LOCALHOST: + if (np == NULL) /* XXX */ + return 0; + + switch (np->m_type) { + case NETHOST: + len = strlen (cp = LocalName ()); + if (!uprf (np->m_host, cp) || np->m_host[len] != '.') + break; + goto local_test; + + case UUCPHOST: + if (mh_strcasecmp (np->m_host, SystemName())) + break; /* fall */ + case LOCALHOST: local_test: ; - if (!mh_strcasecmp (np->m_mbox, mq.m_mbox)) - return 1; - break; - - default: - break; - } - - /* - * Now scan through list of alternate - * mailboxes, and check for a match. - */ - for (mp = &mq; mp->m_next;) { - mp = mp->m_next; - if (!np->m_mbox) - continue; - if ((len = strlen (cp = np->m_mbox)) - < (i = strlen (pp = mp->m_mbox))) - continue; - switch (mp->m_type & W_MBOX) { - case W_NIL: - if (mh_strcasecmp (cp, pp)) - continue; - break; - case W_MBEG: - if (mh_strcasecmp (cp + len - i, pp)) - continue; - break; - case W_MEND: - if (!uprf (cp, pp)) - continue; - break; - case W_MBEG | W_MEND: - if (stringdex (pp, cp) < 0) - continue; - break; + if (!mh_strcasecmp (np->m_mbox, mq.m_mbox)) + return 1; + break; + + default: + break; } - if (mp->m_nohost) - return 1; - if (np->m_host == NULL) - continue; - if ((len = strlen (cp = np->m_host)) - < (i = strlen (pp = mp->m_host))) - continue; - switch (mp->m_type & W_HOST) { - case W_NIL: - if (mh_strcasecmp (cp, pp)) - continue; - break; - case W_HBEG: - if (mh_strcasecmp (cp + len - i, pp)) - continue; - break; - case W_HEND: - if (!uprf (cp, pp)) - continue; - break; - case W_HBEG | W_HEND: - if (stringdex (pp, cp) < 0) - continue; - break; + /* + * Now scan through list of alternate + * mailboxes, and check for a match. + */ + for (mp = &mq; mp->m_next;) { + mp = mp->m_next; + if (!np->m_mbox) + continue; + if ((len = strlen (cp = np->m_mbox)) + < (i = strlen (pp = mp->m_mbox))) + continue; + switch (mp->m_type & W_MBOX) { + case W_NIL: + if (mh_strcasecmp (cp, pp)) + continue; + break; + case W_MBEG: + if (mh_strcasecmp (cp + len - i, pp)) + continue; + break; + case W_MEND: + if (!uprf (cp, pp)) + continue; + break; + case W_MBEG | W_MEND: + if (stringdex (pp, cp) < 0) + continue; + break; + } + + if (mp->m_nohost) + return 1; + if (np->m_host == NULL) + continue; + if ((len = strlen (cp = np->m_host)) + < (i = strlen (pp = mp->m_host))) + continue; + switch (mp->m_type & W_HOST) { + case W_NIL: + if (mh_strcasecmp (cp, pp)) + continue; + break; + case W_HBEG: + if (mh_strcasecmp (cp + len - i, pp)) + continue; + break; + case W_HEND: + if (!uprf (cp, pp)) + continue; + break; + case W_HBEG | W_HEND: + if (stringdex (pp, cp) < 0) + continue; + break; + } + return 1; } - return 1; - } - return 0; + return 0; } @@ -546,31 +538,31 @@ local_test: ; char * OfficialName (char *name) { - unsigned char *p; - char *q, site[BUFSIZ]; - struct addrinfo hints, *res; + unsigned char *p; + char *q, site[BUFSIZ]; + struct addrinfo hints, *res; - static char buffer[BUFSIZ]; + static char buffer[BUFSIZ]; - for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++) - *q = isupper (*p) ? tolower (*p) : *p; - *q = '\0'; - q = site; + for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++) + *q = isupper (*p) ? tolower (*p) : *p; + *q = '\0'; + q = site; - if (!mh_strcasecmp (LocalName(), site)) - return LocalName(); + if (!mh_strcasecmp (LocalName(), site)) + return LocalName(); - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = PF_UNSPEC; + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + hints.ai_family = PF_UNSPEC; - if (getaddrinfo(q, NULL, &hints, &res) == 0) { - strncpy (buffer, res->ai_canonname, sizeof(buffer)); - buffer[sizeof(buffer) - 1] = '\0'; - freeaddrinfo(res); - return buffer; - } + if (getaddrinfo(q, NULL, &hints, &res) == 0) { + strncpy (buffer, res->ai_canonname, sizeof(buffer)); + buffer[sizeof(buffer) - 1] = '\0'; + freeaddrinfo(res); + return buffer; + } - strncpy (buffer, site, sizeof(buffer)); - return buffer; + strncpy (buffer, site, sizeof(buffer)); + return buffer; } diff --git a/sbr/ambigsw.c b/sbr/ambigsw.c index c11b9e7..cd84ad6 100644 --- a/sbr/ambigsw.c +++ b/sbr/ambigsw.c @@ -1,4 +1,3 @@ - /* * ambigsw.c -- report an ambiguous switch * @@ -13,6 +12,6 @@ void ambigsw (char *arg, struct swit *swp) { - advise (NULL, "-%s ambiguous. It matches", arg); - print_sw (arg, swp, "-", stderr); + advise (NULL, "-%s ambiguous. It matches", arg); + print_sw (arg, swp, "-", stderr); } diff --git a/sbr/atooi.c b/sbr/atooi.c index d62de17..a0e4f74 100644 --- a/sbr/atooi.c +++ b/sbr/atooi.c @@ -1,4 +1,3 @@ - /* * atooi.c -- octal version of atoi() * @@ -13,14 +12,14 @@ int atooi(char *cp) { - register int i, base; + register int i, base; - i = 0; - base = 8; - while (*cp >= '0' && *cp <= '7') { - i *= base; - i += *cp++ - '0'; - } + i = 0; + base = 8; + while (*cp >= '0' && *cp <= '7') { + i *= base; + i += *cp++ - '0'; + } - return i; + return i; } diff --git a/sbr/brkstring.c b/sbr/brkstring.c index 5375596..1e78b17 100644 --- a/sbr/brkstring.c +++ b/sbr/brkstring.c @@ -1,4 +1,3 @@ - /* * brkstring.c -- (destructively) split a string into * -- an array of substrings @@ -14,8 +13,8 @@ /* allocate this number of pointers at a time */ #define NUMBROKEN 256 -static char **broken = NULL; /* array of substring start addresses */ -static int len = 0; /* current size of "broken" */ +static char **broken = NULL; /* array of substring start addresses */ +static int len = 0; /* current size of "broken" */ /* * static prototypes @@ -26,50 +25,50 @@ static int brkany (char, char *); char ** brkstring (char *str, char *brksep, char *brkterm) { - int i; - char c, *s; + int i; + char c, *s; - /* allocate initial space for pointers on first call */ - if (!broken) { - len = NUMBROKEN; - broken = (char **) mh_xmalloc ((size_t) (len * sizeof(*broken))); - } + /* allocate initial space for pointers on first call */ + if (!broken) { + len = NUMBROKEN; + broken = (char **) mh_xmalloc ((size_t) (len * sizeof(*broken))); + } - /* - * scan string, replacing separators with zeroes - * and enter start addresses in "broken". - */ - s = str; + /* + * scan string, replacing separators with zeroes + * and enter start addresses in "broken". + */ + s = str; - for (i = 0;; i++) { + for (i = 0;; i++) { /* enlarge pointer array, if necessary */ if (i >= len) { - len += NUMBROKEN; - broken = mh_xrealloc (broken, (size_t) (len * sizeof(*broken))); + len += NUMBROKEN; + broken = mh_xrealloc (broken, (size_t) (len * sizeof(*broken))); } while (brkany (c = *s, brksep)) - *s++ = '\0'; + *s++ = '\0'; /* * we are either at the end of the string, or the * terminator found has been found, so finish up. */ if (!c || brkany (c, brkterm)) { - *s = '\0'; - broken[i] = NULL; - return broken; + *s = '\0'; + broken[i] = NULL; + return broken; } /* set next start addr */ broken[i] = s; while ((c = *++s) && !brkany (c, brksep) && !brkany (c, brkterm)) - ; /* empty body */ - } + ; /* empty body */ + } - return broken; /* NOT REACHED */ + return broken; /* NOT REACHED */ } @@ -81,12 +80,12 @@ brkstring (char *str, char *brksep, char *brkterm) static int brkany (char c, char *str) { - char *s; + char *s; - if (str) { + if (str) { for (s = str; *s; s++) - if (c == *s) + if (c == *s) return 1; - } - return 0; + } + return 0; } diff --git a/sbr/check_charset.c b/sbr/check_charset.c index 8ee93b1..e6debc2 100644 --- a/sbr/check_charset.c +++ b/sbr/check_charset.c @@ -1,4 +1,3 @@ - /* * check_charset.c -- routines for character sets * @@ -19,12 +18,12 @@ char * get_charset () { - char *charset = getenv ("MM_CHARSET"); + char *charset = getenv ("MM_CHARSET"); #if defined(HAVE_NL_LANGINFO) && defined(CODESET) - if (!charset) - charset = norm_charmap(nl_langinfo (CODESET)); + if (!charset) + charset = norm_charmap(nl_langinfo (CODESET)); #endif - return charset; + return charset; } @@ -36,34 +35,34 @@ get_charset () */ int -check_charset (char *str, int len) +check_charset (char *str, int len) { - static char *mm_charset = NULL; - static char *alt_charset = NULL; - static int mm_len; - static int alt_len; + static char *mm_charset = NULL; + static char *alt_charset = NULL; + static int mm_len; + static int alt_len; - /* Cache the name of our default character set */ - if (!mm_charset) { - if (!(mm_charset = get_charset ())) - mm_charset = "US-ASCII"; - mm_len = strlen (mm_charset); + /* Cache the name of our default character set */ + if (!mm_charset) { + if (!(mm_charset = get_charset ())) + mm_charset = "US-ASCII"; + mm_len = strlen (mm_charset); - /* US-ASCII is a subset of the ISO-8859-X and UTF-8 character sets */ - if (!strncasecmp("ISO-8859-", mm_charset, 9) || - !mh_strcasecmp("UTF-8", mm_charset)) { - alt_charset = "US-ASCII"; - alt_len = strlen (alt_charset); + /* US-ASCII is a subset of the ISO-8859-X and UTF-8 character sets */ + if (!strncasecmp("ISO-8859-", mm_charset, 9) || + !mh_strcasecmp("UTF-8", mm_charset)) { + alt_charset = "US-ASCII"; + alt_len = strlen (alt_charset); + } } - } - /* Check if character set is OK */ - if ((len == mm_len) && !strncasecmp(str, mm_charset, mm_len)) - return 1; - if (alt_charset && (len == alt_len) && !strncasecmp(str, alt_charset, alt_len)) - return 1; + /* Check if character set is OK */ + if ((len == mm_len) && !strncasecmp(str, mm_charset, mm_len)) + return 1; + if (alt_charset && (len == alt_len) && !strncasecmp(str, alt_charset, alt_len)) + return 1; - return 0; + return 0; } @@ -74,14 +73,14 @@ check_charset (char *str, int len) char * write_charset_8bit (void) { - static char *mm_charset = NULL; + static char *mm_charset = NULL; - /* - * Cache the name of the character set to - * use for 8bit text. - */ - if (!mm_charset && !(mm_charset = get_charset ())) - mm_charset = "x-unknown"; + /* + * Cache the name of the character set to + * use for 8bit text. + */ + if (!mm_charset && !(mm_charset = get_charset ())) + mm_charset = "x-unknown"; - return mm_charset; + return mm_charset; } diff --git a/sbr/client.c b/sbr/client.c index 92e0711..0dd4a67 100644 --- a/sbr/client.c +++ b/sbr/client.c @@ -1,4 +1,3 @@ - /* * client.c -- connect to a server * @@ -19,10 +18,10 @@ # include #endif -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 -#define MAXARGS 1000 +#define MAXARGS 1000 /* * static prototypes @@ -39,81 +38,81 @@ static void client_freelist(char **); int client (char *args, char *service, char *response, int len_response, int debug) { - int sd, rc; - char **ap, *arguments[MAXARGS]; - struct addrinfo hints, *res, *ai; - - ap = arguments; - if (args != NULL && *args != 0) { - ap = client_copyip (client_brkstring (client_getcpy (args), " ", "\n"), - ap, MAXARGS); - } - if (ap == arguments) { - *ap++ = client_getcpy ("localhost"); - *ap = NULL; - } - - memset(&hints, 0, sizeof(hints)); + int sd, rc; + char **ap, *arguments[MAXARGS]; + struct addrinfo hints, *res, *ai; + + ap = arguments; + if (args != NULL && *args != 0) { + ap = client_copyip (client_brkstring (client_getcpy (args), " ", "\n"), + ap, MAXARGS); + } + if (ap == arguments) { + *ap++ = client_getcpy ("localhost"); + *ap = NULL; + } + + memset(&hints, 0, sizeof(hints)); #ifdef AI_ADDRCONFIG - hints.ai_flags = AI_ADDRCONFIG; + hints.ai_flags = AI_ADDRCONFIG; #endif - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; - for (ap = arguments; *ap; ap++) { + for (ap = arguments; *ap; ap++) { - if (debug) { - fprintf(stderr, "Trying to connect to \"%s\" ...\n", *ap); - } + if (debug) { + fprintf(stderr, "Trying to connect to \"%s\" ...\n", *ap); + } - rc = getaddrinfo(*ap, service, &hints, &res); + rc = getaddrinfo(*ap, service, &hints, &res); - if (rc) { - if (debug) { - fprintf(stderr, "Lookup of \"%s\" failed: %s\n", *ap, - gai_strerror(rc)); - } - continue; - } + if (rc) { + if (debug) { + fprintf(stderr, "Lookup of \"%s\" failed: %s\n", *ap, + gai_strerror(rc)); + } + continue; + } - for (ai = res; ai != NULL; ai = ai->ai_next) { - if (debug) { - char address[NI_MAXHOST]; + for (ai = res; ai != NULL; ai = ai->ai_next) { + if (debug) { + char address[NI_MAXHOST]; - rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, address, - sizeof(address), NULL, 0, NI_NUMERICHOST); + rc = getnameinfo(ai->ai_addr, ai->ai_addrlen, address, + sizeof(address), NULL, 0, NI_NUMERICHOST); - fprintf(stderr, "Connecting to %s...\n", - rc ? "unknown" : address); - } + fprintf(stderr, "Connecting to %s...\n", + rc ? "unknown" : address); + } - sd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + sd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sd < 0) { - if (debug) - fprintf(stderr, "socket() failed: %s\n", strerror(errno)); - continue; - } + if (sd < 0) { + if (debug) + fprintf(stderr, "socket() failed: %s\n", strerror(errno)); + continue; + } - if (connect(sd, ai->ai_addr, ai->ai_addrlen) == 0) { - freeaddrinfo(res); - client_freelist(ap); - return sd; - } + if (connect(sd, ai->ai_addr, ai->ai_addrlen) == 0) { + freeaddrinfo(res); + client_freelist(ap); + return sd; + } - if (debug) { - fprintf(stderr, "Connection failed: %s\n", strerror(errno)); - } + if (debug) { + fprintf(stderr, "Connection failed: %s\n", strerror(errno)); + } - close(sd); - } + close(sd); + } - freeaddrinfo(res); - } + freeaddrinfo(res); + } - client_freelist(ap); - strncpy (response, "no servers available", len_response); - return NOTOK; + client_freelist(ap); + strncpy (response, "no servers available", len_response); + return NOTOK; } @@ -124,8 +123,8 @@ client (char *args, char *service, char *response, int len_response, int debug) static void client_freelist(char **list) { - while (*list++ != NULL) - free(*list); + while (*list++ != NULL) + free(*list); } @@ -138,27 +137,27 @@ static char *broken[MAXARGS + 1]; static char ** client_brkstring (char *strg, char *brksep, char *brkterm) { - register int bi; - register char c, *sp; - - sp = strg; - - for (bi = 0; bi < MAXARGS; bi++) { - while (client_brkany (c = *sp, brksep)) - *sp++ = 0; - if (!c || client_brkany (c, brkterm)) { - *sp = 0; - broken[bi] = 0; - return broken; + register int bi; + register char c, *sp; + + sp = strg; + + for (bi = 0; bi < MAXARGS; bi++) { + while (client_brkany (c = *sp, brksep)) + *sp++ = 0; + if (!c || client_brkany (c, brkterm)) { + *sp = 0; + broken[bi] = 0; + return broken; + } + + broken[bi] = sp; + while ((c = *++sp) && !client_brkany (c, brksep) && !client_brkany (c, brkterm)) + continue; } + broken[MAXARGS] = 0; - broken[bi] = sp; - while ((c = *++sp) && !client_brkany (c, brksep) && !client_brkany (c, brkterm)) - continue; - } - broken[MAXARGS] = 0; - - return broken; + return broken; } @@ -168,13 +167,13 @@ client_brkstring (char *strg, char *brksep, char *brkterm) static int client_brkany (char chr, char *strg) { - register char *sp; - - if (strg) - for (sp = strg; *sp; sp++) - if (chr == *sp) - return 1; - return 0; + register char *sp; + + if (strg) + for (sp = strg; *sp; sp++) + if (chr == *sp) + return 1; + return 0; } @@ -184,25 +183,25 @@ client_brkany (char chr, char *strg) static char ** client_copyip (char **p, char **q, int len_q) { - while (*p && --len_q > 0) - *q++ = *p++; + while (*p && --len_q > 0) + *q++ = *p++; - *q = NULL; + *q = NULL; - return q; + return q; } static char * client_getcpy (char *str) { - char *cp; - size_t len; + char *cp; + size_t len; - len = strlen(str) + 1; - cp = mh_xmalloc(len); + len = strlen(str) + 1; + cp = mh_xmalloc(len); - memcpy (cp, str, len); - return cp; + memcpy (cp, str, len); + return cp; } diff --git a/sbr/closefds.c b/sbr/closefds.c index d292112..99543f5 100644 --- a/sbr/closefds.c +++ b/sbr/closefds.c @@ -1,4 +1,3 @@ - /* * closefds.c -- close-up fd's * @@ -13,8 +12,8 @@ void closefds(int i) { - int nbits = OPEN_MAX; + int nbits = OPEN_MAX; - for (; i < nbits; i++) - close (i); + for (; i < nbits; i++) + close (i); } diff --git a/sbr/concat.c b/sbr/concat.c index 82979f5..2d0bc60 100644 --- a/sbr/concat.c +++ b/sbr/concat.c @@ -1,4 +1,3 @@ - /* * concat.c -- concatenate a variable number (minimum of 1) * of strings in managed memory @@ -15,24 +14,24 @@ char * concat (char *s1, ...) { - char *cp, *dp, *sp; - size_t len; - va_list list; + char *cp, *dp, *sp; + size_t len; + va_list list; - len = strlen (s1) + 1; - va_start(list, s1); - while ((cp = va_arg(list, char *))) - len += strlen (cp); - va_end(list); + len = strlen (s1) + 1; + va_start(list, s1); + while ((cp = va_arg(list, char *))) + len += strlen (cp); + va_end(list); - dp = sp = mh_xmalloc(len); + dp = sp = mh_xmalloc(len); - sp = copy(s1, sp); + sp = copy(s1, sp); - va_start(list, s1); - while ((cp = va_arg (list, char *))) - sp = copy(cp, sp); - va_end(list); + va_start(list, s1); + while ((cp = va_arg (list, char *))) + sp = copy(cp, sp); + va_end(list); - return dp; + return dp; } diff --git a/sbr/context_del.c b/sbr/context_del.c index 474e51c..f2ff0a4 100644 --- a/sbr/context_del.c +++ b/sbr/context_del.c @@ -1,4 +1,3 @@ - /* * context_del.c -- delete an entry from the context/profile list * @@ -17,24 +16,24 @@ int context_del (char *key) { - register struct node *np, *pp; + register struct node *np, *pp; - for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) { - if (!mh_strcasecmp (np->n_name, key)) { - if (!np->n_context) - admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name); - if (pp) - pp->n_next = np->n_next; - else - m_defs = np->n_next; - free (np->n_name); - if (np->n_field) - free (np->n_field); - free ((char *) np); - ctxflags |= CTXMOD; - return 0; + for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) { + if (!mh_strcasecmp (np->n_name, key)) { + if (!np->n_context) + admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name); + if (pp) + pp->n_next = np->n_next; + else + m_defs = np->n_next; + free (np->n_name); + if (np->n_field) + free (np->n_field); + free ((char *) np); + ctxflags |= CTXMOD; + return 0; + } } - } - return 1; + return 1; } diff --git a/sbr/context_find.c b/sbr/context_find.c index 8c0675f..da1ee10 100644 --- a/sbr/context_find.c +++ b/sbr/context_find.c @@ -1,4 +1,3 @@ - /* * context_find.c -- find an entry in the context/profile list * @@ -13,11 +12,11 @@ char * context_find (char *str) { - struct node *np; + struct node *np; - for (np = m_defs; np; np = np->n_next) - if (!mh_strcasecmp (np->n_name, str)) - return (np->n_field); + for (np = m_defs; np; np = np->n_next) + if (!mh_strcasecmp (np->n_name, str)) + return (np->n_field); - return NULL; + return NULL; } diff --git a/sbr/context_foil.c b/sbr/context_foil.c index 4a6e89b..94f687a 100644 --- a/sbr/context_foil.c +++ b/sbr/context_foil.c @@ -1,4 +1,3 @@ - /* * context_foil.c -- foil search of profile and context * @@ -18,53 +17,52 @@ int context_foil (char *path) { - register struct node *np; + register struct node *np; - /* In fact, nobody examines defpath in code paths where - * it's been set by us -- the uses in the source tree are: - * 1 sbr/context_read.c uses it only after setting it itself - * 2 uip/install_mh.c uses it only after setting it itself - * 3 uip/mark.c print it if given the -debug switch - * A worthwhile piece of code cleanup would be to make 1 and - * 2 use a local variable and just delete 3. - * - * Similarly, context and ctxpath are not really used - * outside the context_* routines. It might be worth combining - * them into one file so the variables can be made static. - */ + /* In fact, nobody examines defpath in code paths where + * it's been set by us -- the uses in the source tree are: + * 1 sbr/context_read.c uses it only after setting it itself + * 2 uip/install_mh.c uses it only after setting it itself + * 3 uip/mark.c print it if given the -debug switch + * A worthwhile piece of code cleanup would be to make 1 and + * 2 use a local variable and just delete 3. + * + * Similarly, context and ctxpath are not really used + * outside the context_* routines. It might be worth combining + * them into one file so the variables can be made static. + */ - /* We set context to NULL to indicate that no context file - * is to be read. (Using /dev/null doesn't work because we - * would try to lock it, which causes timeouts with some - * locking methods.) - */ - defpath = context = NULL; + /* We set context to NULL to indicate that no context file + * is to be read. (Using /dev/null doesn't work because we + * would try to lock it, which causes timeouts with some + * locking methods.) + */ + defpath = context = NULL; - /* - * If path is given, create a minimal profile/context list - */ - if (path) { - m_defs = (struct node *) mh_xmalloc (sizeof(*np)); + /* + * If path is given, create a minimal profile/context list + */ + if (path) { + m_defs = (struct node *) mh_xmalloc (sizeof(*np)); - np = m_defs; - if (!(np->n_name = strdup ("Path"))) { - advise (NULL, "strdup failed"); - return -1; - } - if (!(np->n_field = strdup (path))) { - advise (NULL, "strdup failed"); - return -1; - } - np->n_context = 0; - np->n_next = NULL; + np = m_defs; + if (!(np->n_name = strdup ("Path"))) { + advise (NULL, "strdup failed"); + return -1; + } + if (!(np->n_field = strdup (path))) { + advise (NULL, "strdup failed"); + return -1; + } + np->n_context = 0; + np->n_next = NULL; - if (mypath == NULL && (mypath = getenv ("HOME")) != NULL) - if (!(mypath = strdup (mypath))) { - advise (NULL, "strdup failed"); - return -1; - } - } + if (mypath == NULL && (mypath = getenv ("HOME")) != NULL) + if (!(mypath = strdup (mypath))) { + advise (NULL, "strdup failed"); + return -1; + } + } - return 0; + return 0; } - diff --git a/sbr/context_read.c b/sbr/context_read.c index a655eff..24e6350 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -5,141 +5,133 @@ * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. * - * This function must be called early on in any nmh utility, and - * may only be called once. It does the following: + * This function must be called early on in any nmh utility, and + * may only be called once. It does the following: * - * o Sets the global variable "mypath" to the home directory path. + * o Sets the global variable "mypath" to the home directory path. * - * o Sets the global variable "defpath" to the absolute path of - * the profile file. + * o Sets the global variable "defpath" to the absolute path of + * the profile file. * - * o Reads in the profile file. Bails out if it can't. + * o Reads in the profile file. Bails out if it can't. * - * o Makes sure that the mail directory exists, prompting for - * creation if it doesn't. + * o Makes sure that the mail directory exists, prompting for + * creation if it doesn't. * - * o Reads the context file either as set by the MHCONTEXT - * environment variable or by the profile. + * o Reads the context file either as set by the MHCONTEXT + * environment variable or by the profile. */ -#include /* mh internals */ -#include /* system call errors */ -#include /* structure for getpwuid() results */ +#include /* mh internals */ +#include /* system call errors */ +#include /* structure for getpwuid() results */ void context_read (void) { - char buf[BUFSIZ]; /* path name buffer */ - char *cp; /* miscellaneous pointer */ - char *nd; /* nmh directory pointer */ - struct stat st; /* stat() results */ - register struct passwd *pw; /* getpwuid() results */ - register FILE *ib; /* profile and context file pointer */ - - /* - * If this routine _is_ called again (despite the wanings in the - * comments above), return immediately. - */ - if ( m_defs != 0 ) - return; - - /* - * Find user's home directory. Try the HOME environment variable first, - * the home directory field in the password file if that's not found. - */ - - if ((mypath = getenv("HOME")) == (char *)0) { + char buf[BUFSIZ]; /* path name buffer */ + char *cp; /* miscellaneous pointer */ + char *nd; /* nmh directory pointer */ + struct stat st; /* stat() results */ + register struct passwd *pw; /* getpwuid() results */ + register FILE *ib; /* profile and context file pointer */ + + /* + * If this routine _is_ called again (despite the wanings in the + * comments above), return immediately. + */ + if ( m_defs != 0 ) + return; + + /* + * Find user's home directory. Try the HOME environment variable first, + * the home directory field in the password file if that's not found. + */ + if ((mypath = getenv("HOME")) == (char *)0) { if ((pw = getpwuid(getuid())) == (struct passwd *)0 || *pw->pw_dir == '\0') - adios(NULL, "cannot determine your home directory"); + adios(NULL, "cannot determine your home directory"); else - mypath = pw->pw_dir; - } + mypath = pw->pw_dir; + } - /* - * Find and read user's profile. Check for the existence of an MH environment - * variable first with non-empty contents. Convert any relative path name - * found there to an absolute one. Look for the profile in the user's home - * directory if the MH environment variable isn't set. - */ + /* + * Find and read user's profile. Check for the existence of an MH environment + * variable first with non-empty contents. Convert any relative path name + * found there to an absolute one. Look for the profile in the user's home + * directory if the MH environment variable isn't set. + */ - if ((cp = getenv("MH")) && *cp != '\0') { + if ((cp = getenv("MH")) && *cp != '\0') { defpath = path(cp, TFILE); if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0) adios((char *)0, "`%s' specified by your MH environment variable is not a normal file", cp); if ((ib = fopen(defpath, "r")) == (FILE *)0) - adios((char *)0, "unable to read the `%s' profile specified by your MH environment variable", defpath); - } - else { - defpath = concat(mypath, "/", mh_profile, NULL); + adios((char *)0, "unable to read the `%s' profile specified by your MH environment variable", defpath); + } else { + defpath = concat(mypath, "/", mh_profile, NULL); - if ((ib = fopen(defpath, "r")) == (FILE *)0) - adios((char *)0, "Doesn't look like nmh is installed. Run install-mh to do so."); - - cp = mh_profile; - } - - readconfig (&m_defs, ib, cp, 0); - fclose (ib); - - /* - * Find the user's nmh directory, which is specified by the "path" profile component. - * Convert a relative path name to an absolute one rooted in the home directory. - */ - - if ((cp = context_find ("path")) == (char *)0) - adios(NULL, "Your %s file does not contain a path entry.", defpath); - - if (*cp == '\0') - adios(NULL, "Your `%s' profile file does not contain a valid path entry.", defpath); + if ((ib = fopen(defpath, "r")) == (FILE *)0) + adios((char *)0, "Doesn't look like nmh is installed. Run install-mh to do so."); - if (*cp != '/') - (void)snprintf (nd = buf, sizeof(buf), "%s/%s", mypath, cp); - else - nd = cp; + cp = mh_profile; + } - if (stat(nd, &st) == -1) { - if (errno != ENOENT) - adios (nd, "error opening"); + readconfig (&m_defs, ib, cp, 0); + fclose (ib); - cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL); + /* + * Find the user's nmh directory, which is specified by the "path" profile component. + * Convert a relative path name to an absolute one rooted in the home directory. + */ - if (!getanswer(cp)) - adios (NULL, "unable to access MH-directory \"%s\"", nd); + if ((cp = context_find ("path")) == (char *)0) + adios(NULL, "Your %s file does not contain a path entry.", defpath); - free (cp); + if (*cp == '\0') + adios(NULL, "Your `%s' profile file does not contain a valid path entry.", defpath); - if (!makedir (nd)) - adios (NULL, "unable to create %s", nd); - } - - else if ((st.st_mode & S_IFDIR) == 0) - adios ((char *)0, "`%s' is not a directory", nd); - - /* - * Open and read user's context file. The name of the context file comes from the - * profile unless overridden by the MHCONTEXT environment variable. - */ - - if ((cp = getenv ("MHCONTEXT")) == (char *)0 || *cp == '\0') - cp = context; + if (*cp != '/') + (void)snprintf (nd = buf, sizeof(buf), "%s/%s", mypath, cp); + else + nd = cp; + + if (stat(nd, &st) == -1) { + if (errno != ENOENT) + adios (nd, "error opening"); + cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL); + if (!getanswer(cp)) + adios (NULL, "unable to access MH-directory \"%s\"", nd); + free (cp); + if (!makedir (nd)) + adios (NULL, "unable to create %s", nd); + } else if ((st.st_mode & S_IFDIR) == 0) + adios ((char *)0, "`%s' is not a directory", nd); + + /* + * Open and read user's context file. The name of the context file comes from the + * profile unless overridden by the MHCONTEXT environment variable. + */ + + if ((cp = getenv ("MHCONTEXT")) == (char *)0 || *cp == '\0') + cp = context; + + /* context is NULL if context_foil() was called to disable use of context + * We also support users setting explicitly setting MHCONTEXT to /dev/null. + * (if this wasn't specialcased then the locking would be liable to fail) + */ + if (!cp || (strcmp(cp,"/dev/null") == 0)) { + ctxpath = NULL; + return; + } + + ctxpath = getcpy (m_maildir (cp)); + + if ((ib = lkfopen (ctxpath, "r"))) { + readconfig ((struct node **) 0, ib, cp, 1); + lkfclose (ib, ctxpath); + } - /* context is NULL if context_foil() was called to disable use of context - * We also support users setting explicitly setting MHCONTEXT to /dev/null. - * (if this wasn't specialcased then the locking would be liable to fail) - */ - if (!cp || (strcmp(cp,"/dev/null") == 0)) { - ctxpath = NULL; return; - } - - ctxpath = getcpy (m_maildir (cp)); - - if ((ib = lkfopen (ctxpath, "r"))) { - readconfig ((struct node **) 0, ib, cp, 1); - lkfclose (ib, ctxpath); - } - - return; } diff --git a/sbr/context_replace.c b/sbr/context_replace.c index a0c5032..dbe1014 100644 --- a/sbr/context_replace.c +++ b/sbr/context_replace.c @@ -1,4 +1,3 @@ - /* * context_replace.c -- add/replace an entry in the context/profile list * @@ -14,52 +13,52 @@ void context_replace (char *key, char *value) { - register struct node *np; - - /* - * If list is emtpy, allocate head of profile/context list. - */ - if (!m_defs) { - m_defs = (struct node *) mh_xmalloc (sizeof(*np)); + register struct node *np; - np = m_defs; - np->n_name = getcpy (key); - np->n_field = getcpy (value); - np->n_context = 1; - np->n_next = NULL; - ctxflags |= CTXMOD; - return; - } + /* + * If list is emtpy, allocate head of profile/context list. + */ + if (!m_defs) { + m_defs = (struct node *) mh_xmalloc (sizeof(*np)); - /* - * Search list of context/profile entries for - * this key, and replace its value if found. - */ - for (np = m_defs;; np = np->n_next) { - if (!mh_strcasecmp (np->n_name, key)) { - if (strcmp (value, np->n_field)) { - if (!np->n_context) - admonish (NULL, "bug: context_replace(key=\"%s\",value=\"%s\")", key, value); - if (np->n_field) - free (np->n_field); + np = m_defs; + np->n_name = getcpy (key); np->n_field = getcpy (value); + np->n_context = 1; + np->n_next = NULL; ctxflags |= CTXMOD; - } - return; + return; } - if (!np->n_next) - break; - } - /* - * Else add this new entry at the end - */ - np->n_next = (struct node *) mh_xmalloc (sizeof(*np)); + /* + * Search list of context/profile entries for + * this key, and replace its value if found. + */ + for (np = m_defs;; np = np->n_next) { + if (!mh_strcasecmp (np->n_name, key)) { + if (strcmp (value, np->n_field)) { + if (!np->n_context) + admonish (NULL, "bug: context_replace(key=\"%s\",value=\"%s\")", key, value); + if (np->n_field) + free (np->n_field); + np->n_field = getcpy (value); + ctxflags |= CTXMOD; + } + return; + } + if (!np->n_next) + break; + } + + /* + * Else add this new entry at the end + */ + np->n_next = (struct node *) mh_xmalloc (sizeof(*np)); - np = np->n_next; - np->n_name = getcpy (key); - np->n_field = getcpy (value); - np->n_context = 1; - np->n_next = NULL; - ctxflags |= CTXMOD; + np = np->n_next; + np->n_name = getcpy (key); + np->n_field = getcpy (value); + np->n_context = 1; + np->n_next = NULL; + ctxflags |= CTXMOD; } diff --git a/sbr/context_save.c b/sbr/context_save.c index 4ee40ca..d4a56ed 100644 --- a/sbr/context_save.c +++ b/sbr/context_save.c @@ -1,4 +1,3 @@ - /* * context_save.c -- write out the updated context file * @@ -19,41 +18,41 @@ static int m_chkids(void); void context_save (void) { - int action; - register struct node *np; - FILE *out; - sigset_t set, oset; - - /* No context in use -- silently ignore any changes! */ - if (!ctxpath) - return; - - if (!(ctxflags & CTXMOD)) - return; - ctxflags &= ~CTXMOD; - - if ((action = m_chkids ()) > 0) - return; /* child did it for us */ - - /* block a few signals */ - sigemptyset (&set); - sigaddset (&set, SIGHUP); - sigaddset (&set, SIGINT); - sigaddset (&set, SIGQUIT); - sigaddset (&set, SIGTERM); - SIGPROCMASK (SIG_BLOCK, &set, &oset); - - if (!(out = lkfopen (ctxpath, "w"))) - adios (ctxpath, "unable to write"); - for (np = m_defs; np; np = np->n_next) - if (np->n_context) - fprintf (out, "%s: %s\n", np->n_name, np->n_field); - lkfclose (out, ctxpath); - - SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset the signal mask */ - - if (action == 0) - _exit (0); /* we are child, time to die */ + int action; + register struct node *np; + FILE *out; + sigset_t set, oset; + + /* No context in use -- silently ignore any changes! */ + if (!ctxpath) + return; + + if (!(ctxflags & CTXMOD)) + return; + ctxflags &= ~CTXMOD; + + if ((action = m_chkids ()) > 0) + return; /* child did it for us */ + + /* block a few signals */ + sigemptyset (&set); + sigaddset (&set, SIGHUP); + sigaddset (&set, SIGINT); + sigaddset (&set, SIGQUIT); + sigaddset (&set, SIGTERM); + SIGPROCMASK (SIG_BLOCK, &set, &oset); + + if (!(out = lkfopen (ctxpath, "w"))) + adios (ctxpath, "unable to write"); + for (np = m_defs; np; np = np->n_next) + if (np->n_context) + fprintf (out, "%s: %s\n", np->n_name, np->n_field); + lkfclose (out, ctxpath); + + SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset the signal mask */ + + if (action == 0) + _exit (0); /* we are child, time to die */ } /* @@ -69,28 +68,28 @@ context_save (void) static int m_chkids (void) { - int i; - pid_t pid; + int i; + pid_t pid; - if (getuid () == geteuid ()) - return (-1); + if (getuid () == geteuid ()) + return (-1); - for (i = 0; (pid = fork ()) == -1 && i < 5; i++) - sleep (5); + for (i = 0; (pid = fork ()) == -1 && i < 5; i++) + sleep (5); - switch (pid) { - case -1: - break; + switch (pid) { + case -1: + break; - case 0: - setgid (getgid ()); - setuid (getuid ()); - break; + case 0: + setgid (getgid ()); + setuid (getuid ()); + break; - default: - pidwait (pid, -1); - break; - } + default: + pidwait (pid, -1); + break; + } - return pid; + return pid; } diff --git a/sbr/copy.c b/sbr/copy.c index cc35e95..4a0ef51 100644 --- a/sbr/copy.c +++ b/sbr/copy.c @@ -1,4 +1,3 @@ - /* * copy.c -- copy a string and return pointer to NULL terminator * @@ -12,9 +11,9 @@ char * copy(char *from, char *to) { - while ((*to = *from)) { - to++; - from++; - } - return (to); + while ((*to = *from)) { + to++; + from++; + } + return (to); } diff --git a/sbr/copyip.c b/sbr/copyip.c index 84f724c..5ae52bd 100644 --- a/sbr/copyip.c +++ b/sbr/copyip.c @@ -1,4 +1,3 @@ - /* * copyip.c -- copy a string array and return pointer to end * @@ -13,10 +12,9 @@ char ** copyip (char **p, char **q, int len_q) { - while (*p && --len_q > 0) - *q++ = *p++; - - *q = NULL; + while (*p && --len_q > 0) + *q++ = *p++; + *q = NULL; - return q; + return q; } diff --git a/sbr/cpydata.c b/sbr/cpydata.c index d322ba9..c74b2ae 100644 --- a/sbr/cpydata.c +++ b/sbr/cpydata.c @@ -1,4 +1,3 @@ - /* * cpydata.c -- copy all data from one fd to another * @@ -12,14 +11,14 @@ void cpydata (int in, int out, char *ifile, char *ofile) { - int i; - char buffer[BUFSIZ]; + int i; + char buffer[BUFSIZ]; - while ((i = read(in, buffer, sizeof(buffer))) > 0) { - if (write(out, buffer, i) != i) - adios(ofile, "error writing"); - } + while ((i = read(in, buffer, sizeof(buffer))) > 0) { + if (write(out, buffer, i) != i) + adios(ofile, "error writing"); + } - if (i == -1) - adios(ifile, "error reading"); + if (i == -1) + adios(ifile, "error reading"); } diff --git a/sbr/cpydgst.c b/sbr/cpydgst.c index 12829f1..7195cd1 100644 --- a/sbr/cpydgst.c +++ b/sbr/cpydgst.c @@ -1,4 +1,3 @@ - /* * cpydgst.c -- copy from one fd to another in encapsulating mode * -- (do dashstuffing of input data). @@ -13,7 +12,7 @@ /* * We want to perform the substitution * - * \n(-.*)\n --> \n- \1\n + * \n(-.*)\n --> \n- \1\n * * This is equivalent to the sed substitution * @@ -22,46 +21,46 @@ * but the routine below is faster than the pipe, fork, and exec. */ -#define S1 0 -#define S2 1 +#define S1 0 +#define S2 1 -#define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c -#define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \ - adios (ofile, "error writing"); \ - else \ - bp = outbuf +#define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c +#define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \ + adios (ofile, "error writing"); \ + else \ + bp = outbuf void cpydgst (int in, int out, char *ifile, char *ofile) { - register int i, j, state; - register char *cp, *ep; - register char *bp, *dp; - char buffer[BUFSIZ], outbuf[BUFSIZ]; + register int i, j, state; + register char *cp, *ep; + register char *bp, *dp; + char buffer[BUFSIZ], outbuf[BUFSIZ]; - dp = (bp = outbuf) + sizeof outbuf; - for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;) - for (ep = (cp = buffer) + i; cp < ep; cp++) { - if (*cp == '\0') - continue; - switch (state) { - case S1: - if (*cp == '-') { - output ('-'); - output (' '); - } - state = S2; /* fall */ + dp = (bp = outbuf) + sizeof outbuf; + for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;) + for (ep = (cp = buffer) + i; cp < ep; cp++) { + if (*cp == '\0') + continue; + switch (state) { + case S1: + if (*cp == '-') { + output ('-'); + output (' '); + } + state = S2; /* fall */ - case S2: - output (*cp); - if (*cp == '\n') - state = S1; - break; - } - } + case S2: + output (*cp); + if (*cp == '\n') + state = S1; + break; + } + } - if (i == -1) - adios (ifile, "error reading"); - flush(); + if (i == -1) + adios (ifile, "error reading"); + flush(); } diff --git a/sbr/crawl_folders.c b/sbr/crawl_folders.c index d8bcdba..28116b7 100644 --- a/sbr/crawl_folders.c +++ b/sbr/crawl_folders.c @@ -1,4 +1,3 @@ - /* * crawl_folders.c -- crawl folder hierarchy * @@ -12,13 +11,12 @@ #include struct crawl_context { - int max; /* how many folders we currently can hold in - * the array `folders', increased by - * CRAWL_NUMFOLDERS at a time */ - int total; /* how many `folders' actually has */ - char **folders; /* the array of folders */ - int start; - int foldp; + int max; /* how many folders we currently can hold in the array + * `folders', increased by CRAWL_NUMFOLDERS at a time */ + int total; /* how many `folders' actually has */ + char **folders; /* the array of folders */ + int start; + int foldp; }; /* @@ -29,121 +27,121 @@ struct crawl_context { static void add_folder (char *fold, struct crawl_context *crawl) { - register int i, j; - - /* if necessary, reallocate the space for folder names */ - if (crawl->foldp >= crawl->max) { - crawl->max += CRAWL_NUMFOLDERS; - crawl->folders = mh_xrealloc (crawl->folders, - crawl->max * sizeof(char *)); - } - - for (i = crawl->start; i < crawl->foldp; i++) - if (strcmp (fold, crawl->folders[i]) < 0) { - for (j = crawl->foldp - 1; j >= i; j--) - crawl->folders[j + 1] = crawl->folders[j]; - crawl->foldp++; - crawl->folders[i] = fold; - return; + register int i, j; + + /* if necessary, reallocate the space for folder names */ + if (crawl->foldp >= crawl->max) { + crawl->max += CRAWL_NUMFOLDERS; + crawl->folders = mh_xrealloc (crawl->folders, + crawl->max * sizeof(char *)); } - crawl->total++; - crawl->folders[crawl->foldp++] = fold; + for (i = crawl->start; i < crawl->foldp; i++) + if (strcmp (fold, crawl->folders[i]) < 0) { + for (j = crawl->foldp - 1; j >= i; j--) + crawl->folders[j + 1] = crawl->folders[j]; + crawl->foldp++; + crawl->folders[i] = fold; + return; + } + + crawl->total++; + crawl->folders[crawl->foldp++] = fold; } static void add_children (char *name, struct crawl_context *crawl) { - char *prefix, *child; - struct stat st; - struct dirent *dp; - DIR * dd; - int child_is_folder; - - if (!(dd = opendir (name))) { - admonish (name, "unable to read directory "); - return; - } - - if (strcmp (name, ".") == 0) { - prefix = getcpy (""); - } else { - prefix = concat (name, "/", (void *)NULL); - } - - while ((dp = readdir (dd))) { - /* If the system supports it, try to skip processing of children we - * know are not directories or symlinks. */ - child_is_folder = -1; -#if defined(HAVE_STRUCT_DIRENT_D_TYPE) - if (dp->d_type == DT_DIR) { - child_is_folder = 1; - } else if (dp->d_type != DT_LNK && dp->d_type != DT_UNKNOWN) { - continue; - } -#endif - if (!strcmp (dp->d_name, ".") || !strcmp (dp->d_name, "..")) { - continue; - } - child = concat (prefix, dp->d_name, (void *)NULL); - /* If we have no d_type or d_type is DT_LNK or DT_UNKNOWN, stat the - * child to see what it is. */ - if (child_is_folder == -1) { - child_is_folder = (stat (child, &st) != -1 && S_ISDIR(st.st_mode)); + char *prefix, *child; + struct stat st; + struct dirent *dp; + DIR * dd; + int child_is_folder; + + if (!(dd = opendir (name))) { + admonish (name, "unable to read directory "); + return; } - if (child_is_folder) { - /* add_folder saves child in the list, don't free it */ - add_folder (child, crawl); + + if (strcmp (name, ".") == 0) { + prefix = getcpy (""); } else { - free (child); + prefix = concat (name, "/", (void *)NULL); + } + + while ((dp = readdir (dd))) { + /* If the system supports it, try to skip processing of + * children we know are not directories or symlinks. */ + child_is_folder = -1; +#if defined(HAVE_STRUCT_DIRENT_D_TYPE) + if (dp->d_type == DT_DIR) { + child_is_folder = 1; + } else if (dp->d_type != DT_LNK && dp->d_type != DT_UNKNOWN) { + continue; + } +#endif + if (!strcmp (dp->d_name, ".") || !strcmp (dp->d_name, "..")) { + continue; + } + child = concat (prefix, dp->d_name, (void *)NULL); + /* If we have no d_type or d_type is DT_LNK or DT_UNKNOWN, stat the + * child to see what it is. */ + if (child_is_folder == -1) { + child_is_folder = (stat (child, &st) != -1 && S_ISDIR(st.st_mode)); + } + if (child_is_folder) { + /* add_folder saves child in the list, don't free it */ + add_folder (child, crawl); + } else { + free (child); + } } - } - closedir (dd); - free(prefix); + closedir (dd); + free(prefix); } static void -crawl_folders_body (struct crawl_context *crawl, - char *dir, crawl_callback_t *callback, void *baton) +crawl_folders_body (struct crawl_context *crawl, char *dir, + crawl_callback_t *callback, void *baton) { - int i; - int os = crawl->start; - int of = crawl->foldp; + int i; + int os = crawl->start; + int of = crawl->foldp; - crawl->start = crawl->foldp; + crawl->start = crawl->foldp; - add_children (dir, crawl); + add_children (dir, crawl); - for (i = crawl->start; i < crawl->foldp; i++) { - char *fold = crawl->folders[i]; - int crawl_children = 1; + for (i = crawl->start; i < crawl->foldp; i++) { + char *fold = crawl->folders[i]; + int crawl_children = 1; - if (callback != NULL) { - crawl_children = callback (fold, baton); - } + if (callback != NULL) { + crawl_children = callback (fold, baton); + } - if (crawl_children) { - crawl_folders_body (crawl, fold, callback, baton); + if (crawl_children) { + crawl_folders_body (crawl, fold, callback, baton); + } } - } - crawl->start = os; - crawl->foldp = of; + crawl->start = os; + crawl->foldp = of; } void crawl_folders (char *dir, crawl_callback_t *callback, void *baton) { - struct crawl_context *crawl = mh_xmalloc (sizeof(*crawl)); - crawl->max = CRAWL_NUMFOLDERS; - crawl->total = crawl->start = crawl->foldp = 0; - crawl->folders = mh_xmalloc (crawl->max * sizeof(*crawl->folders)); + struct crawl_context *crawl = mh_xmalloc (sizeof(*crawl)); + crawl->max = CRAWL_NUMFOLDERS; + crawl->total = crawl->start = crawl->foldp = 0; + crawl->folders = mh_xmalloc (crawl->max * sizeof(*crawl->folders)); - crawl_folders_body (crawl, dir, callback, baton); + crawl_folders_body (crawl, dir, callback, baton); - /* Note that we "leak" the folder names, on the assumption that the caller - * is using them. */ - free (crawl->folders); - free (crawl); + /* Note that we "leak" the folder names, on the assumption that the caller + * is using them. */ + free (crawl->folders); + free (crawl); } diff --git a/sbr/discard.c b/sbr/discard.c index dbc865c..21fc88f 100644 --- a/sbr/discard.c +++ b/sbr/discard.c @@ -1,4 +1,3 @@ - /* * discard.c -- discard output on a file pointer * @@ -32,35 +31,35 @@ discard (FILE *io) { #ifndef HAVE_TERMIOS_H # ifdef HAVE_TERMIO_H - struct termio tio; + struct termio tio; # else - struct sgttyb tio; + struct sgttyb tio; # endif #endif - if (io == NULL) - return; + if (io == NULL) + return; #ifdef HAVE_TERMIOS_H - tcflush (fileno(io), TCOFLUSH); + tcflush (fileno(io), TCOFLUSH); #else # ifdef HAVE_TERMIO_H - if (ioctl (fileno(io), TCGETA, &tio) != -1) - ioctl (fileno(io), TCSETA, &tio); + if (ioctl (fileno(io), TCGETA, &tio) != -1) + ioctl (fileno(io), TCSETA, &tio); # else - if (ioctl (fileno(io), TIOCGETP, (char *) &tio) != -1) - ioctl (fileno(io), TIOCSETP, (char *) &tio); + if (ioctl (fileno(io), TIOCGETP, (char *) &tio) != -1) + ioctl (fileno(io), TIOCSETP, (char *) &tio); # endif #endif #if defined(_FSTDIO) || defined(__DragonFly__) - fpurge (io); + fpurge (io); #else # ifdef LINUX_STDIO - io->_IO_write_ptr = io->_IO_write_base; + io->_IO_write_ptr = io->_IO_write_base; # else - if ((io->_ptr = io->_base)) - io->_cnt = 0; + if ((io->_ptr = io->_base)) + io->_cnt = 0; # endif #endif } diff --git a/sbr/done.c b/sbr/done.c index 05bcf52..e4efff3 100644 --- a/sbr/done.c +++ b/sbr/done.c @@ -1,4 +1,3 @@ - /* * done.c -- terminate the program * diff --git a/sbr/dtime.c b/sbr/dtime.c index 2e978d7..0c229ee 100644 --- a/sbr/dtime.c +++ b/sbr/dtime.c @@ -1,4 +1,3 @@ - /* * dtime.c -- time/date routines * @@ -32,83 +31,83 @@ extern long timezone; extern char *tzname[]; #endif -#ifndef abs +#ifndef abs # define abs(a) (a >= 0 ? a : -a) #endif /* * The number of days in the year, accounting for leap years */ -#define dysize(y) \ +#define dysize(y) \ (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366))) char *tw_moty[] = { - "Jan", "Feb", "Mar", "Apr", - "May", "Jun", "Jul", "Aug", - "Sep", "Oct", "Nov", "Dec", - NULL + "Jan", "Feb", "Mar", "Apr", + "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec", + NULL }; char *tw_dotw[] = { - "Sun", "Mon", "Tue", - "Wed", "Thu", "Fri", - "Sat", NULL + "Sun", "Mon", "Tue", + "Wed", "Thu", "Fri", + "Sat", NULL }; char *tw_ldotw[] = { - "Sunday", "Monday", "Tuesday", - "Wednesday", "Thursday", "Friday", - "Saturday", NULL + "Sunday", "Monday", "Tuesday", + "Wednesday", "Thursday", "Friday", + "Saturday", NULL }; struct zone { - char *std; - char *dst; - int shift; + char *std; + char *dst; + int shift; }; static struct zone zones[] = { - { "GMT", "BST", 0 }, - { "EST", "EDT", -5 }, - { "CST", "CDT", -6 }, - { "MST", "MDT", -7 }, - { "PST", "PDT", -8 }, + { "GMT", "BST", 0 }, + { "EST", "EDT", -5 }, + { "CST", "CDT", -6 }, + { "MST", "MDT", -7 }, + { "PST", "PDT", -8 }, #if 0 /* RFC1123 specifies do not use military TZs */ - { "A", NULL, -1 }, - { "B", NULL, -2 }, - { "C", NULL, -3 }, - { "D", NULL, -4 }, - { "E", NULL, -5 }, - { "F", NULL, -6 }, - { "G", NULL, -7 }, - { "H", NULL, -8 }, - { "I", NULL, -9 }, - { "K", NULL, -10 }, - { "L", NULL, -11 }, - { "M", NULL, -12 }, - { "N", NULL, 1 }, -#ifndef HUJI - { "O", NULL, 2 }, + { "A", NULL, -1 }, + { "B", NULL, -2 }, + { "C", NULL, -3 }, + { "D", NULL, -4 }, + { "E", NULL, -5 }, + { "F", NULL, -6 }, + { "G", NULL, -7 }, + { "H", NULL, -8 }, + { "I", NULL, -9 }, + { "K", NULL, -10 }, + { "L", NULL, -11 }, + { "M", NULL, -12 }, + { "N", NULL, 1 }, +#ifndef HUJI + { "O", NULL, 2 }, #else - { "JST", "JDT", 2 }, + { "JST", "JDT", 2 }, #endif - { "P", NULL, 3 }, - { "Q", NULL, 4 }, - { "R", NULL, 5 }, - { "S", NULL, 6 }, - { "T", NULL, 7 }, - { "U", NULL, 8 }, - { "V", NULL, 9 }, - { "W", NULL, 10 }, - { "X", NULL, 11 }, - { "Y", NULL, 12 }, + { "P", NULL, 3 }, + { "Q", NULL, 4 }, + { "R", NULL, 5 }, + { "S", NULL, 6 }, + { "T", NULL, 7 }, + { "U", NULL, 8 }, + { "V", NULL, 9 }, + { "W", NULL, 10 }, + { "X", NULL, 11 }, + { "Y", NULL, 12 }, #endif - { NULL, NULL, 0 } + { NULL, NULL, 0 } }; static int dmsize[] = { - 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; @@ -121,10 +120,10 @@ static int dmsize[] = { struct tws * dlocaltimenow (void) { - time_t clock; + time_t clock; - time (&clock); - return dlocaltime (&clock); + time (&clock); + return dlocaltime (&clock); } @@ -137,58 +136,58 @@ dlocaltimenow (void) struct tws * dlocaltime (time_t *clock) { - static struct tws tw; - struct tm *tm; + static struct tws tw; + struct tm *tm; #if !defined(HAVE_STRUCT_TM_TM_GMTOFF) && !defined(HAVE_TZSET) - struct timeb tb; + struct timeb tb; #endif - if (!clock) - return NULL; + if (!clock) + return NULL; - tm = localtime (clock); + tm = localtime (clock); - tw.tw_sec = tm->tm_sec; - tw.tw_min = tm->tm_min; - tw.tw_hour = tm->tm_hour; - tw.tw_mday = tm->tm_mday; - tw.tw_mon = tm->tm_mon; + tw.tw_sec = tm->tm_sec; + tw.tw_min = tm->tm_min; + tw.tw_hour = tm->tm_hour; + tw.tw_mday = tm->tm_mday; + tw.tw_mon = tm->tm_mon; - /* - * tm_year is always "year - 1900". - * So we correct for this. - */ - tw.tw_year = tm->tm_year + 1900; - tw.tw_wday = tm->tm_wday; - tw.tw_yday = tm->tm_yday; + /* + * tm_year is always "year - 1900". + * So we correct for this. + */ + tw.tw_year = tm->tm_year + 1900; + tw.tw_wday = tm->tm_wday; + tw.tw_yday = tm->tm_yday; - tw.tw_flags = TW_NULL; - if (tm->tm_isdst) - tw.tw_flags |= TW_DST; + tw.tw_flags = TW_NULL; + if (tm->tm_isdst) + tw.tw_flags |= TW_DST; #ifdef HAVE_STRUCT_TM_TM_GMTOFF - tw.tw_zone = tm->tm_gmtoff / 60; - if (tm->tm_isdst) /* if DST is in effect */ - tw.tw_zone -= 60; /* reset to normal offset */ + tw.tw_zone = tm->tm_gmtoff / 60; + if (tm->tm_isdst) /* if DST is in effect */ + tw.tw_zone -= 60; /* reset to normal offset */ #else # ifdef HAVE_TZSET - tzset(); - tw.tw_zone = -(timezone / 60); + tzset(); + tw.tw_zone = -(timezone / 60); # else - ftime (&tb); - tw.tw_zone = -tb.timezone; + ftime (&tb); + tw.tw_zone = -tb.timezone; # endif #endif - tw.tw_flags &= ~TW_SDAY; - tw.tw_flags |= TW_SEXP; - tw.tw_flags &= ~TW_SZONE; - tw.tw_flags |= TW_SZEXP; + tw.tw_flags &= ~TW_SDAY; + tw.tw_flags |= TW_SEXP; + tw.tw_flags &= ~TW_SZONE; + tw.tw_flags |= TW_SZEXP; - tw.tw_clock = *clock; + tw.tw_clock = *clock; - return (&tw); + return (&tw); } @@ -201,42 +200,42 @@ dlocaltime (time_t *clock) struct tws * dgmtime (time_t *clock) { - static struct tws tw; - struct tm *tm; + static struct tws tw; + struct tm *tm; - if (!clock) - return NULL; + if (!clock) + return NULL; - tm = gmtime (clock); + tm = gmtime (clock); - tw.tw_sec = tm->tm_sec; - tw.tw_min = tm->tm_min; - tw.tw_hour = tm->tm_hour; - tw.tw_mday = tm->tm_mday; - tw.tw_mon = tm->tm_mon; + tw.tw_sec = tm->tm_sec; + tw.tw_min = tm->tm_min; + tw.tw_hour = tm->tm_hour; + tw.tw_mday = tm->tm_mday; + tw.tw_mon = tm->tm_mon; - /* - * tm_year is always "year - 1900" - * So we correct for this. - */ - tw.tw_year = tm->tm_year + 1900; - tw.tw_wday = tm->tm_wday; - tw.tw_yday = tm->tm_yday; + /* + * tm_year is always "year - 1900" + * So we correct for this. + */ + tw.tw_year = tm->tm_year + 1900; + tw.tw_wday = tm->tm_wday; + tw.tw_yday = tm->tm_yday; - tw.tw_flags = TW_NULL; - if (tm->tm_isdst) - tw.tw_flags |= TW_DST; + tw.tw_flags = TW_NULL; + if (tm->tm_isdst) + tw.tw_flags |= TW_DST; - tw.tw_zone = 0; + tw.tw_zone = 0; - tw.tw_flags &= ~TW_SDAY; - tw.tw_flags |= TW_SEXP; - tw.tw_flags &= ~TW_SZONE; - tw.tw_flags |= TW_SZEXP; + tw.tw_flags &= ~TW_SDAY; + tw.tw_flags |= TW_SEXP; + tw.tw_flags &= ~TW_SZONE; + tw.tw_flags |= TW_SZEXP; - tw.tw_clock = *clock; + tw.tw_clock = *clock; - return (&tw); + return (&tw); } @@ -244,31 +243,31 @@ dgmtime (time_t *clock) * Using a nmh "broken-down" time structure, * produce a 26-byte date/time string, such as * - * Tue Jan 14 17:49:03 1992\n\0 + * Tue Jan 14 17:49:03 1992\n\0 */ char * dctime (struct tws *tw) { - static char buffer[26]; + static char buffer[26]; - if (!tw) - return NULL; + if (!tw) + return NULL; - snprintf (buffer, sizeof(buffer), "%.3s %.3s %02d %02d:%02d:%02d %.4d\n", - tw_dotw[tw->tw_wday], tw_moty[tw->tw_mon], tw->tw_mday, - tw->tw_hour, tw->tw_min, tw->tw_sec, - tw->tw_year < 100 ? tw->tw_year + 1900 : tw->tw_year); + snprintf (buffer, sizeof(buffer), "%.3s %.3s %02d %02d:%02d:%02d %.4d\n", + tw_dotw[tw->tw_wday], tw_moty[tw->tw_mon], tw->tw_mday, + tw->tw_hour, tw->tw_min, tw->tw_sec, + tw->tw_year < 100 ? tw->tw_year + 1900 : tw->tw_year); - return buffer; + return buffer; } /* * Produce a date/time string of the form * - * Mon, 16 Jun 1992 15:30:48 -700 (or) - * Mon, 16 Jun 1992 15:30:48 EDT + * Mon, 16 Jun 1992 15:30:48 -700 (or) + * Mon, 16 Jun 1992 15:30:48 EDT * * for the current time, as specified by rfc822. * The first form is required by rfc1123. @@ -277,10 +276,10 @@ dctime (struct tws *tw) char * dtimenow (int alpha_timezone) { - time_t clock; + time_t clock; - time (&clock); - return dtime (&clock, alpha_timezone); + time (&clock); + return dtime (&clock, alpha_timezone); } @@ -288,8 +287,8 @@ dtimenow (int alpha_timezone) * Using a local calendar time value, produce * a date/time string of the form * - * Mon, 16 Jun 1992 15:30:48 -700 (or) - * Mon, 16 Jun 1992 15:30:48 EDT + * Mon, 16 Jun 1992 15:30:48 -700 (or) + * Mon, 16 Jun 1992 15:30:48 EDT * * as specified by rfc822. The first form is required * by rfc1123 for outgoing messages. @@ -298,12 +297,12 @@ dtimenow (int alpha_timezone) char * dtime (time_t *clock, int alpha_timezone) { - if (alpha_timezone) - /* use alpha-numeric timezones */ - return dasctime (dlocaltime (clock), TW_NULL); - else - /* use numeric timezones */ - return dasctime (dlocaltime (clock), TW_ZONE); + if (alpha_timezone) + /* use alpha-numeric timezones */ + return dasctime (dlocaltime (clock), TW_NULL); + else + /* use numeric timezones */ + return dasctime (dlocaltime (clock), TW_ZONE); } @@ -311,7 +310,7 @@ dtime (time_t *clock, int alpha_timezone) * Using a nmh "broken-down" time structure, produce * a date/time string of the form * - * Mon, 16 Jun 1992 15:30:48 -0700 + * Mon, 16 Jun 1992 15:30:48 -0700 * * as specified by rfc822 and rfc1123. */ @@ -319,32 +318,32 @@ dtime (time_t *clock, int alpha_timezone) char * dasctime (struct tws *tw, int flags) { - char buffer[80]; - static char result[80]; - - if (!tw) - return NULL; - - /* Display timezone if known */ - if ((tw->tw_flags & TW_SZONE) == TW_SZNIL) - result[0] = '\0'; - else - snprintf(result, sizeof(result), " %s", dtimezone(tw->tw_zone, tw->tw_flags | flags)); - - snprintf(buffer, sizeof(buffer), "%02d %s %0*d %02d:%02d:%02d%s", - tw->tw_mday, tw_moty[tw->tw_mon], - tw->tw_year < 100 ? 2 : 4, tw->tw_year, - tw->tw_hour, tw->tw_min, tw->tw_sec, result); - - if ((tw->tw_flags & TW_SDAY) == TW_SEXP) - snprintf (result, sizeof(result), "%s, %s", tw_dotw[tw->tw_wday], buffer); - else - if ((tw->tw_flags & TW_SDAY) == TW_SNIL) - strncpy (result, buffer, sizeof(result)); + char buffer[80]; + static char result[80]; + + if (!tw) + return NULL; + + /* Display timezone if known */ + if ((tw->tw_flags & TW_SZONE) == TW_SZNIL) + result[0] = '\0'; + else + snprintf(result, sizeof(result), " %s", dtimezone(tw->tw_zone, tw->tw_flags | flags)); + + snprintf(buffer, sizeof(buffer), "%02d %s %0*d %02d:%02d:%02d%s", + tw->tw_mday, tw_moty[tw->tw_mon], + tw->tw_year < 100 ? 2 : 4, tw->tw_year, + tw->tw_hour, tw->tw_min, tw->tw_sec, result); + + if ((tw->tw_flags & TW_SDAY) == TW_SEXP) + snprintf (result, sizeof(result), "%s, %s", tw_dotw[tw->tw_wday], buffer); else - snprintf (result, sizeof(result), "%s (%s)", buffer, tw_dotw[tw->tw_wday]); + if ((tw->tw_flags & TW_SDAY) == TW_SNIL) + strncpy (result, buffer, sizeof(result)); + else + snprintf (result, sizeof(result), "%s (%s)", buffer, tw_dotw[tw->tw_wday]); - return result; + return result; } @@ -355,36 +354,36 @@ dasctime (struct tws *tw, int flags) char * dtimezone (int offset, int flags) { - int hours, mins; - struct zone *z; - static char buffer[10]; - - if (offset < 0) { - mins = -((-offset) % 60); - hours = -((-offset) / 60); - } else { - mins = offset % 60; - hours = offset / 60; - } - - if (!(flags & TW_ZONE) && mins == 0) { + int hours, mins; + struct zone *z; + static char buffer[10]; + + if (offset < 0) { + mins = -((-offset) % 60); + hours = -((-offset) / 60); + } else { + mins = offset % 60; + hours = offset / 60; + } + + if (!(flags & TW_ZONE) && mins == 0) { #if defined(HAVE_TZSET) && defined(HAVE_TZNAME) - tzset(); - return ((flags & TW_DST) ? tzname[1] : tzname[0]); + tzset(); + return ((flags & TW_DST) ? tzname[1] : tzname[0]); #else - for (z = zones; z->std; z++) - if (z->shift == hours) - return (z->dst && (flags & TW_DST) ? z->dst : z->std); + for (z = zones; z->std; z++) + if (z->shift == hours) + return (z->dst && (flags & TW_DST) ? z->dst : z->std); #endif - } + } #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST - if (flags & TW_DST) - hours += 1; + if (flags & TW_DST) + hours += 1; #endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ - snprintf (buffer, sizeof(buffer), "%s%02d%02d", + snprintf (buffer, sizeof(buffer), "%s%02d%02d", offset < 0 ? "-" : "+", abs (hours), abs (mins)); - return buffer; + return buffer; } @@ -398,43 +397,43 @@ dtimezone (int offset, int flags) time_t dmktime (struct tws *tw) { - int i, sec, min, hour, mday, mon, year; - time_t result; - - if (tw->tw_clock != 0) - return tw->tw_clock; - - if ((sec = tw->tw_sec) < 0 || sec > 61 - || (min = tw->tw_min) < 0 || min > 59 - || (hour = tw->tw_hour) < 0 || hour > 23 - || (mday = tw->tw_mday) < 1 || mday > 31 - || (mon = tw->tw_mon + 1) < 1 || mon > 12) - return (tw->tw_clock = (time_t) -1); - - year = tw->tw_year; - - result = 0; - if (year < 1970) - year += 1900; - - if (year < 1970) - year += 100; - - for (i = 1970; i < year; i++) - result += dysize (i); - if (dysize (year) == 366 && mon >= 3) - result++; - while (--mon) - result += dmsize[mon - 1]; - result += mday - 1; - result = 24 * result + hour; - result = 60 * result + min; - result = 60 * result + sec; - result -= 60 * tw->tw_zone; - if (tw->tw_flags & TW_DST) - result -= 60 * 60; - - return (tw->tw_clock = result); + int i, sec, min, hour, mday, mon, year; + time_t result; + + if (tw->tw_clock != 0) + return tw->tw_clock; + + if ((sec = tw->tw_sec) < 0 || sec > 61 + || (min = tw->tw_min) < 0 || min > 59 + || (hour = tw->tw_hour) < 0 || hour > 23 + || (mday = tw->tw_mday) < 1 || mday > 31 + || (mon = tw->tw_mon + 1) < 1 || mon > 12) + return (tw->tw_clock = (time_t) -1); + + year = tw->tw_year; + + result = 0; + if (year < 1970) + year += 1900; + + if (year < 1970) + year += 100; + + for (i = 1970; i < year; i++) + result += dysize (i); + if (dysize (year) == 366 && mon >= 3) + result++; + while (--mon) + result += dmsize[mon - 1]; + result += mday - 1; + result = 24 * result + hour; + result = 60 * result + min; + result = 60 * result + sec; + result -= 60 * tw->tw_zone; + if (tw->tw_flags & TW_DST) + result -= 60 * 60; + + return (tw->tw_clock = result); } @@ -447,28 +446,27 @@ dmktime (struct tws *tw) void set_dotw (struct tws *tw) { - int month, day, year, century; - - month = tw->tw_mon - 1; - day = tw->tw_mday; - year = tw->tw_year % 100; - century = tw->tw_year < 100 ? 19 : tw->tw_year / 100; - - if (month <= 0) { - month += 12; - if (--year < 0) { - year += 100; - century--; + int month, day, year, century; + + month = tw->tw_mon - 1; + day = tw->tw_mday; + year = tw->tw_year % 100; + century = tw->tw_year < 100 ? 19 : tw->tw_year / 100; + + if (month <= 0) { + month += 12; + if (--year < 0) { + year += 100; + century--; + } } - } - tw->tw_wday = - ((26 * month - 2) / 10 + day + year + year / 4 - - 3 * century / 4 + 1) % 7; - if (tw->tw_wday < 0) - tw->tw_wday += 7; + tw->tw_wday = ((26 * month - 2) / 10 + day + year + year / 4 + - 3 * century / 4 + 1) % 7; + if (tw->tw_wday < 0) + tw->tw_wday += 7; - tw->tw_flags &= ~TW_SDAY, tw->tw_flags |= TW_SIMP; + tw->tw_flags &= ~TW_SDAY, tw->tw_flags |= TW_SIMP; } @@ -479,20 +477,20 @@ set_dotw (struct tws *tw) void twscopy (struct tws *tb, struct tws *tw) { - *tb = *tw; /* struct copy */ + *tb = *tw; /* struct copy */ #if 0 - tb->tw_sec = tw->tw_sec; - tb->tw_min = tw->tw_min; - tb->tw_hour = tw->tw_hour; - tb->tw_mday = tw->tw_mday; - tb->tw_mon = tw->tw_mon; - tb->tw_year = tw->tw_year; - tb->tw_wday = tw->tw_wday; - tb->tw_yday = tw->tw_yday; - tb->tw_zone = tw->tw_zone; - tb->tw_clock = tw->tw_clock; - tb->tw_flags = tw->tw_flags; + tb->tw_sec = tw->tw_sec; + tb->tw_min = tw->tw_min; + tb->tw_hour = tw->tw_hour; + tb->tw_mday = tw->tw_mday; + tb->tw_mon = tw->tw_mon; + tb->tw_year = tw->tw_year; + tb->tw_wday = tw->tw_wday; + tb->tw_yday = tw->tw_yday; + tb->tw_zone = tw->tw_zone; + tb->tw_clock = tw->tw_clock; + tb->tw_flags = tw->tw_flags; #endif } @@ -504,13 +502,13 @@ twscopy (struct tws *tb, struct tws *tw) int twsort (struct tws *tw1, struct tws *tw2) { - time_t c1, c2; + time_t c1, c2; - if (tw1->tw_clock == 0) - dmktime (tw1); - if (tw2->tw_clock == 0) - dmktime (tw2); + if (tw1->tw_clock == 0) + dmktime (tw1); + if (tw2->tw_clock == 0) + dmktime (tw2); - return ((c1 = tw1->tw_clock) > (c2 = tw2->tw_clock) ? 1 - : c1 == c2 ? 0 : -1); + return ((c1 = tw1->tw_clock) > (c2 = tw2->tw_clock) ? 1 + : c1 == c2 ? 0 : -1); } diff --git a/sbr/dtimep.lex b/sbr/dtimep.lex index 0191086..a353393 100644 --- a/sbr/dtimep.lex +++ b/sbr/dtimep.lex @@ -34,14 +34,14 @@ */ #define yyterminate() (void)yy_delete_buffer(lexhandle); \ - if(!(tw.tw_flags & TW_SUCC)) { \ - return (struct tws *)NULL; \ - } \ - if(tw.tw_year < 1970) \ - tw.tw_year += 1900; \ - if(tw.tw_year < 1970) \ - tw.tw_year += 100; \ - return(&tw) + if(!(tw.tw_flags & TW_SUCC)) { \ + return (struct tws *)NULL; \ + } \ + if(tw.tw_year < 1970) \ + tw.tw_year += 1900; \ + if(tw.tw_year < 1970) \ + tw.tw_year += 100; \ + return(&tw) /* * Patchable flag that says how to interpret NN/NN/NN dates. When @@ -121,43 +121,26 @@ static int day_map[] = { * character of a particular class. */ -#define INIT() { cp = yytext;} -#define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \ - tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \ - SKIPA(); } -#define SETMON() { cp++; \ - tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \ - SKIPA(); } -#define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; \ - SKIPD(); } -#define SETYEAR() { tw.tw_year = atoi(cp); \ - SKIPD(); } -#define SETDAY() { tw.tw_mday = atoi(cp); \ - tw.tw_flags |= TW_YES; \ - SKIPD(); } -#define SETTIME() { tw.tw_hour = atoi(cp); \ - cp += 2; \ - SKIPTOD(); \ - tw.tw_min = atoi(cp); \ - cp += 2; \ - if(*cp == ':') { \ - tw.tw_sec = atoi(++cp); SKIPD(); } } -#define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \ - tw.tw_flags |= TW_SZEXP; \ - SKIPD(); } -#define SETDST() { tw.tw_flags |= TW_DST; } -#define SKIPD() { while ( isdigit(*cp++) ) ; \ - --cp; } -#define SKIPTOD() { while ( !isdigit(*cp++) ) ; \ - --cp; } -#define SKIPA() { while ( isalpha(*cp++) ) ; \ - --cp; } -#define SKIPTOA() { while ( !isalpha(*cp++) ) ; \ - --cp; } -#define SKIPSP() { while ( isspace(*cp++) ) ; \ - --cp; } -#define SKIPTOSP() { while ( !isspace(*cp++) ) ; \ - --cp; } +#define INIT() { cp = yytext;} +#define SETWDAY() { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \ + tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; SKIPA(); } +#define SETMON() { cp++; tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; \ + SKIPA(); } +#define SETMON_NUM() { tw.tw_mon = atoi(cp)-1; SKIPD(); } +#define SETYEAR() { tw.tw_year = atoi(cp); SKIPD(); } +#define SETDAY() { tw.tw_mday = atoi(cp); tw.tw_flags |= TW_YES; SKIPD(); } +#define SETTIME() { tw.tw_hour = atoi(cp); cp += 2; SKIPTOD(); \ + tw.tw_min = atoi(cp); cp += 2; if(*cp == ':') { \ + tw.tw_sec = atoi(++cp); SKIPD(); } } +#define SETZONE(x) { tw.tw_zone = ((x)/100)*60+(x)%100; \ + tw.tw_flags |= TW_SZEXP; SKIPD(); } +#define SETDST() { tw.tw_flags |= TW_DST; } +#define SKIPD() { while ( isdigit(*cp++) ) ; --cp; } +#define SKIPTOD() { while ( !isdigit(*cp++) ) ; --cp; } +#define SKIPA() { while ( isalpha(*cp++) ) ; --cp; } +#define SKIPTOA() { while ( !isalpha(*cp++) ) ; --cp; } +#define SKIPSP() { while ( isspace(*cp++) ) ; --cp; } +#define SKIPTOSP() { while ( !isspace(*cp++) ) ; --cp; } #ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST # ifdef TIME_WITH_SYS_TIME @@ -174,18 +157,18 @@ static int day_map[] = { static void zonehack (struct tws *tw) { - register struct tm *tm; + register struct tm *tm; - if (dmktime (tw) == (time_t) -1) - return; + if (dmktime (tw) == (time_t) -1) + return; - tm = localtime (&tw->tw_clock); - if (tm->tm_isdst) { - tw->tw_flags |= TW_DST; - tw->tw_zone -= 60; - } + tm = localtime (&tw->tw_clock); + if (tm->tm_isdst) { + tw->tw_flags |= TW_DST; + tw->tw_zone -= 60; + } } -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ +#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ %} sun ([Ss]un(day)?) @@ -213,201 +196,195 @@ dec ([Dd]ec(ember)?) MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec}) -TIME ({D}:{d}{d}(:{d}{d})?) +TIME ({D}:{d}{d}(:{d}{d})?) - /* The year can either be 2 digits, or 4. However, after - Y2K, we found that some MUA were reporting the year 100, hence - the middle term here. yyterminate() resolves the actual - issues with 2-digit years. - */ +/* + * The year can either be 2 digits, or 4. However, after + * Y2K, we found that some MUA were reporting the year 100, hence + * the middle term here. yyterminate() resolves the actual + * issues with 2-digit years. + */ -YEAR (({d}{d})|(1{d}{d})|({d}{4})) +YEAR (({d}{d})|(1{d}{d})|({d}{4})) w ([ \t]*) W ([ \t]+) D ([0-9]?[0-9]) d [0-9] -nl [ \t\n()] +nl [ \t\n()] %% %{ - /* This section begins the definition of dparsetime(). - Put here any local variable definitions and initializations */ - - YY_BUFFER_STATE lexhandle; + /* This section begins the definition of dparsetime(). + * Put here any local variable definitions and initializations */ + + YY_BUFFER_STATE lexhandle; - register unsigned char *cp; - static struct tws tw; + register unsigned char *cp; + static struct tws tw; - memset(&tw,0,sizeof(struct tws)); + memset(&tw,0,sizeof(struct tws)); - lexhandle = yy_scan_string(lexstr); + lexhandle = yy_scan_string(lexstr); %} -{DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETTIME(); - SKIPTOD(); - SETYEAR(); - } - -{DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { - INIT(); - SETWDAY(); - SKIPTOD(); - SETDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { - INIT(); - SETDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} { - INIT(); - SETWDAY(); - SKIPTOA(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - } -{MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} { - INIT(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - SKIPTOA(); - SETWDAY(); - } -{MONTH}{W}{D}","?{W}{YEAR} { - INIT(); - SETMON(); - SKIPTOD(); - SETDAY(); - SKIPTOD(); - SETYEAR(); - } -{D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} { - INIT(); - if(europeandate) { - /* DD/MM/YY */ - SETDAY(); - SKIPTOD(); - SETMON_NUM(); - } else { - /* MM/DD/YY */ - SETMON_NUM(); - SKIPTOD(); - SETDAY(); - } - SKIPTOD(); - SETYEAR(); - SKIPTOD(); - SETTIME(); - } -{D}("-"|"/"){D}("-"|"/"){YEAR} { - INIT(); - if(europeandate) { - /* DD/MM/YY */ - SETDAY(); - SKIPTOD(); - SETMON_NUM(); - } else { - /* MM/DD/YY */ - SETMON_NUM(); - SKIPTOD(); - SETDAY(); - } - SKIPTOD(); - SETYEAR(); - } +{DAY}","?{W}{MONTH}{W}{D}{W}{TIME}{W}{YEAR} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETTIME(); + SKIPTOD(); + SETYEAR(); +} + +{DAY}","?{W}{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { + INIT(); + SETWDAY(); + SKIPTOD(); + SETDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{D}{W}{MONTH}{W}{YEAR}{W}{TIME} { + INIT(); + SETDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR}","?{W}{TIME} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{DAY}","?{W}{MONTH}{W}{D}","?{W}{YEAR} { + INIT(); + SETWDAY(); + SKIPTOA(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); +} +{MONTH}{W}{D}","?{W}{YEAR}","?{W}{DAY} { + INIT(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); + SKIPTOA(); + SETWDAY(); +} +{MONTH}{W}{D}","?{W}{YEAR} { + INIT(); + SETMON(); + SKIPTOD(); + SETDAY(); + SKIPTOD(); + SETYEAR(); +} +{D}("-"|"/"){D}("-"|"/"){YEAR}{W}{TIME} { + INIT(); + if(europeandate) { + /* DD/MM/YY */ + SETDAY(); + SKIPTOD(); + SETMON_NUM(); + } else { + /* MM/DD/YY */ + SETMON_NUM(); + SKIPTOD(); + SETDAY(); + } + SKIPTOD(); + SETYEAR(); + SKIPTOD(); + SETTIME(); +} +{D}("-"|"/"){D}("-"|"/"){YEAR} { + INIT(); + if(europeandate) { + /* DD/MM/YY */ + SETDAY(); + SKIPTOD(); + SETMON_NUM(); + } else { + /* MM/DD/YY */ + SETMON_NUM(); + SKIPTOD(); + SETDAY(); + } + SKIPTOD(); + SETYEAR(); +} "[Aa][Mm]" -"[Pp][Mm]" tw.tw_hour += 12; - -"+"{D}{d}{d} { - INIT(); - SKIPTOD(); - SETZONE(atoi(cp)); -#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST - zonehack (&tw); -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ - yyterminate(); - } -"-"{D}{d}{d} { - INIT(); - SKIPTOD(); - SETZONE(-atoi(cp)); -#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST - zonehack (&tw); -#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ - yyterminate(); - - } -{nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate(); -{nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate(); -{nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate(); -{nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); - yyterminate(); } -{nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate(); -{nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); - yyterminate(); } -{nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate(); -{nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); - yyterminate(); } -{nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate(); -{nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); - yyterminate(); } -{nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate(); -{nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate(); -{nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); - yyterminate(); } -{nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate(); -{nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); - yyterminate(); } +"[Pp][Mm]" tw.tw_hour += 12; + +"+"{D}{d}{d} { + INIT(); + SKIPTOD(); + SETZONE(atoi(cp)); +#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST + zonehack (&tw); +#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ + yyterminate(); +} +"-"{D}{d}{d} { + INIT(); + SKIPTOD(); + SETZONE(-atoi(cp)); +#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST + zonehack (&tw); +#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */ + yyterminate(); + +} +{nl}("ut"|"UT") INIT(); SETZONE(0); yyterminate(); +{nl}("gmt"|"GMT") INIT(); SETZONE(0); yyterminate(); +{nl}("est"|"EST") INIT(); SETZONE(-500); yyterminate(); +{nl}("edt"|"EDT") { INIT(); SETDST(); SETZONE(-500); yyterminate(); } +{nl}("cst"|"CST") INIT(); SETZONE(-600); yyterminate(); +{nl}("cdt"|"CDT") { INIT(); SETDST(); SETZONE(-600); yyterminate(); } +{nl}("mst"|"MST") INIT(); SETZONE(-700); yyterminate(); +{nl}("mdt"|"MDT") { INIT(); SETDST(); SETZONE(-700); yyterminate(); } +{nl}("pst"|"PST") INIT(); SETZONE(-800); yyterminate(); +{nl}("pdt"|"PDT") { INIT(); SETDST(); SETZONE(-800); yyterminate(); } +{nl}("nst"|"NST") INIT(); SETZONE(-330); yyterminate(); +{nl}("ast"|"AST") INIT(); SETZONE(-400); yyterminate(); +{nl}("adt"|"ADT") { INIT(); SETDST(); SETZONE(-400); yyterminate(); } +{nl}("hst"|"HST") INIT(); SETZONE(-1000); yyterminate(); +{nl}("hdt"|"HDT") { INIT(); SETDST(); SETZONE(-1000); yyterminate(); } .|\n %% /* This is a portable way to squash a warning about the yyunput() * function being static but never used. It costs us a tiny amount * of extra code in the binary but the other options are: - * "%option nounput" which is flex-specific - * makefile hackery just to compile dtimep.c with different flags + * "%option nounput" which is flex-specific + * makefile hackery just to compile dtimep.c with different flags */ void dtimep_yyunput(int c) { - unput(c); + unput(c); } - diff --git a/sbr/error.c b/sbr/error.c index 6dc6995..1c15006 100644 --- a/sbr/error.c +++ b/sbr/error.c @@ -1,4 +1,3 @@ - /* * error.c -- main error handling routines * @@ -23,11 +22,11 @@ void advise (char *what, char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); + va_start(ap, fmt); + advertise (what, NULL, fmt, ap); + va_end(ap); } @@ -37,12 +36,12 @@ advise (char *what, char *fmt, ...) void adios (char *what, char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); - done (1); + va_start(ap, fmt); + advertise (what, NULL, fmt, ap); + va_end(ap); + done (1); } @@ -52,11 +51,11 @@ adios (char *what, char *fmt, ...) void admonish (char *what, char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - advertise (what, "continuing...", fmt, ap); - va_end(ap); + va_start(ap, fmt); + advertise (what, "continuing...", fmt, ap); + va_end(ap); } @@ -71,72 +70,72 @@ admonish (char *what, char *fmt, ...) void advertise (char *what, char *tail, char *fmt, va_list ap) { - int eindex = errno; + int eindex = errno; #ifdef HAVE_WRITEV - char buffer[BUFSIZ], err[BUFSIZ]; - struct iovec iob[20], *iov; + char buffer[BUFSIZ], err[BUFSIZ]; + struct iovec iob[20], *iov; #endif - fflush (stdout); + fflush (stdout); #ifdef HAVE_WRITEV - fflush (stderr); - iov = iob; + fflush (stderr); + iov = iob; + + if (invo_name && *invo_name) { + iov->iov_len = strlen (iov->iov_base = invo_name); + iov++; + iov->iov_len = strlen (iov->iov_base = ": "); + iov++; + } - if (invo_name && *invo_name) { - iov->iov_len = strlen (iov->iov_base = invo_name); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); + vsnprintf (buffer, sizeof(buffer), fmt, ap); + iov->iov_len = strlen (iov->iov_base = buffer); iov++; - } - - vsnprintf (buffer, sizeof(buffer), fmt, ap); - iov->iov_len = strlen (iov->iov_base = buffer); - iov++; - if (what) { - if (*what) { - iov->iov_len = strlen (iov->iov_base = " "); - iov++; - iov->iov_len = strlen (iov->iov_base = what); - iov++; - iov->iov_len = strlen (iov->iov_base = ": "); - iov++; + if (what) { + if (*what) { + iov->iov_len = strlen (iov->iov_base = " "); + iov++; + iov->iov_len = strlen (iov->iov_base = what); + iov++; + iov->iov_len = strlen (iov->iov_base = ": "); + iov++; + } + if (!(iov->iov_base = strerror (eindex))) { + /* this shouldn't happen, but we'll test for it just in case */ + snprintf (err, sizeof(err), "Error %d", eindex); + iov->iov_base = err; + } + iov->iov_len = strlen (iov->iov_base); + iov++; } - if (!(iov->iov_base = strerror (eindex))) { - /* this shouldn't happen, but we'll test for it just in case */ - snprintf (err, sizeof(err), "Error %d", eindex); - iov->iov_base = err; + if (tail && *tail) { + iov->iov_len = strlen (iov->iov_base = ", "); + iov++; + iov->iov_len = strlen (iov->iov_base = tail); + iov++; } - iov->iov_len = strlen (iov->iov_base); + iov->iov_len = strlen (iov->iov_base = "\n"); iov++; - } - if (tail && *tail) { - iov->iov_len = strlen (iov->iov_base = ", "); - iov++; - iov->iov_len = strlen (iov->iov_base = tail); - iov++; - } - iov->iov_len = strlen (iov->iov_base = "\n"); - iov++; - writev (fileno (stderr), iob, iov - iob); + writev (fileno (stderr), iob, iov - iob); #else - if (invo_name && *invo_name) - fprintf (stderr, "%s: ", invo_name); - vfprintf (stderr, fmt, ap); - - if (what) { - char *s; - - if (*what) - fprintf (stderr, " %s: ", what); - if ((s = strerror(eindex))) - fprintf (stderr, "%s", s); - else - fprintf (stderr, "Error %d", eindex); - } - if (tail) - fprintf (stderr, ", %s", tail); - fputc ('\n', stderr); + if (invo_name && *invo_name) + fprintf (stderr, "%s: ", invo_name); + vfprintf (stderr, fmt, ap); + + if (what) { + char *s; + + if (*what) + fprintf (stderr, " %s: ", what); + if ((s = strerror(eindex))) + fprintf (stderr, "%s", s); + else + fprintf (stderr, "Error %d", eindex); + } + if (tail) + fprintf (stderr, ", %s", tail); + fputc ('\n', stderr); #endif } diff --git a/sbr/ext_hook.c b/sbr/ext_hook.c index e94083b..5ff9394 100644 --- a/sbr/ext_hook.c +++ b/sbr/ext_hook.c @@ -1,11 +1,10 @@ /* - * - * Run a program that hooks into some other system. The first argument is - * name of the hook to use, the second is the full path name of a mail message. - * The third argument is also the full path name of a mail message, or a NULL - * pointer if it isn't needed. Look in the context for an error message if - * something goes wrong; there is a built-in message in case one isn't specified. - * Only produce the error message once. + * Run a program that hooks into some other system. The first argument is + * name of the hook to use, the second is the full path name of a mail message. + * The third argument is also the full path name of a mail message, or a NULL + * pointer if it isn't needed. Look in the context for an error message if + * something goes wrong; there is a built-in message in case one isn't specified. + * Only produce the error message once. */ #include @@ -13,49 +12,49 @@ int ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2) { - char *hook; /* hook program from context */ - pid_t pid; /* ID of child process */ - int status; /* exit or other child process status */ - char *vec[4]; /* argument vector for child process */ - - static int did_message = 0; /* set if we've already output a message */ - - if ((hook = context_find(hook_name)) == (char *)0) - return (OK); - - switch (pid = vfork()) { - case -1: - status = NOTOK; - advise(NULL, "external database may be out-of-date."); - break; - - case 0: - vec[0] = r1bindex(hook, '/'); - vec[1] = message_file_name_1; - vec[2] = message_file_name_2; - vec[3] = (char *)0; - execvp(hook, vec); - _exit(-1); - /* NOTREACHED */ - - default: - status = pidwait(pid, -1); - break; - } - - if (status != OK) { - if (did_message == 0) { - if ((hook = context_find("msg-hook")) != (char *)0) - advise(NULL, hook); - else - advise(NULL, "external hook (%s) did not work properly.", hook); - - did_message = 1; + char *hook; /* hook program from context */ + pid_t pid; /* ID of child process */ + int status; /* exit or other child process status */ + char *vec[4]; /* argument vector for child process */ + + static int did_message = 0; /* set if we've already output a message */ + + if ((hook = context_find(hook_name)) == (char *)0) + return (OK); + + switch (pid = vfork()) { + case -1: + status = NOTOK; + advise(NULL, "external database may be out-of-date."); + break; + + case 0: + vec[0] = r1bindex(hook, '/'); + vec[1] = message_file_name_1; + vec[2] = message_file_name_2; + vec[3] = (char *)0; + execvp(hook, vec); + _exit(-1); + /* NOTREACHED */ + + default: + status = pidwait(pid, -1); + break; } - return (NOTOK); - } + if (status != OK) { + if (did_message == 0) { + if ((hook = context_find("msg-hook")) != (char *)0) + advise(NULL, hook); + else + advise(NULL, "external hook (%s) did not work properly.", hook); - else - return (OK); + did_message = 1; + } + + return (NOTOK); + } + + else + return (OK); } diff --git a/sbr/fdcompare.c b/sbr/fdcompare.c index 38174e0..72dff99 100644 --- a/sbr/fdcompare.c +++ b/sbr/fdcompare.c @@ -1,4 +1,3 @@ - /* * fdcompare.c -- are two files identical? * @@ -13,28 +12,28 @@ int fdcompare (int fd1, int fd2) { - register int i, n1, n2, resp; - register char *c1, *c2; - char b1[BUFSIZ], b2[BUFSIZ]; + register int i, n1, n2, resp; + register char *c1, *c2; + char b1[BUFSIZ], b2[BUFSIZ]; - resp = 1; - while ((n1 = read (fd1, b1, sizeof(b1))) >= 0 - && (n2 = read (fd2, b2, sizeof(b2))) >= 0 - && n1 == n2) { - c1 = b1; - c2 = b2; - for (i = n1 < sizeof(b1) ? n1 : sizeof(b1); i--;) - if (*c1++ != *c2++) { - resp = 0; - goto leave; - } - if (n1 < sizeof(b1)) - goto leave; - } - resp = 0; + resp = 1; + while ((n1 = read (fd1, b1, sizeof(b1))) >= 0 + && (n2 = read (fd2, b2, sizeof(b2))) >= 0 + && n1 == n2) { + c1 = b1; + c2 = b2; + for (i = n1 < sizeof(b1) ? n1 : sizeof(b1); i--;) + if (*c1++ != *c2++) { + resp = 0; + goto leave; + } + if (n1 < sizeof(b1)) + goto leave; + } + resp = 0; leave: ; - lseek (fd1, (off_t) 0, SEEK_SET); - lseek (fd2, (off_t) 0, SEEK_SET); - return resp; + lseek (fd1, (off_t) 0, SEEK_SET); + lseek (fd2, (off_t) 0, SEEK_SET); + return resp; } diff --git a/sbr/fmt_addr.c b/sbr/fmt_addr.c index be9b483..bfb42d8 100644 --- a/sbr/fmt_addr.c +++ b/sbr/fmt_addr.c @@ -1,4 +1,3 @@ - /* * fmt_addr.c -- format an address field (from fmt_scan) * @@ -12,18 +11,18 @@ #include #include -static char *buf; /* our current working buffer */ -static char *bufend; /* end of working buffer */ -static char *last_dst; /* buf ptr at end of last call */ -static unsigned int bufsiz; /* current size of buf */ +static char *buf; /* our current working buffer */ +static char *bufend; /* end of working buffer */ +static char *last_dst; /* buf ptr at end of last call */ +static unsigned int bufsiz; /* current size of buf */ -#define BUFINCR 512 /* how much to expand buf when if fills */ +#define BUFINCR 512 /* how much to expand buf when if fills */ #define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; } /* check if there's enough room in buf for str. add more mem if needed */ #define CHECKMEM(str) \ - if ((len = strlen (str)) >= bufend - dst) {\ + if ((len = strlen (str)) >= bufend - dst) {\ int i = dst - buf;\ int n = last_dst - buf;\ bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\ @@ -31,7 +30,7 @@ static unsigned int bufsiz; /* current size of buf */ dst = buf + i;\ last_dst = buf + n;\ bufend = buf + bufsiz;\ - } + } /* fmt_scan will call this routine if the user includes the function @@ -51,64 +50,64 @@ static unsigned int bufsiz; /* current size of buf */ char * formataddr (char *orig, char *str) { - register int len; - register int isgroup; - register char *dst; - register char *cp; - register char *sp; - register struct mailname *mp = NULL; - - /* if we don't have a buffer yet, get one */ - if (bufsiz == 0) { - buf = mh_xmalloc (BUFINCR); - last_dst = buf; /* XXX */ - bufsiz = BUFINCR - 6; /* leave some slop */ - bufend = buf + bufsiz; - } - /* - * If "orig" points to our buffer we can just pick up where we - * left off. Otherwise we have to copy orig into our buffer. - */ - if (orig == buf) - dst = last_dst; - else if (!orig || !*orig) { - dst = buf; - *dst = '\0'; - } else { - dst = last_dst; /* XXX */ - CHECKMEM (orig); - CPY (orig); - } + register int len; + register int isgroup; + register char *dst; + register char *cp; + register char *sp; + register struct mailname *mp = NULL; - /* concatenate all the new addresses onto 'buf' */ - for (isgroup = 0; (cp = getname (str)); ) { - if ((mp = getm (cp, NULL, 0, fmt_norm, NULL)) == NULL) - continue; - - if (isgroup && (mp->m_gname || !mp->m_ingrp)) { - *dst++ = ';'; - isgroup = 0; + /* if we don't have a buffer yet, get one */ + if (bufsiz == 0) { + buf = mh_xmalloc (BUFINCR); + last_dst = buf; /* XXX */ + bufsiz = BUFINCR - 6; /* leave some slop */ + bufend = buf + bufsiz; } - /* if we get here we're going to add an address */ - if (dst != buf) { - *dst++ = ','; - *dst++ = ' '; + /* + * If "orig" points to our buffer we can just pick up where we + * left off. Otherwise we have to copy orig into our buffer. + */ + if (orig == buf) + dst = last_dst; + else if (!orig || !*orig) { + dst = buf; + *dst = '\0'; + } else { + dst = last_dst; /* XXX */ + CHECKMEM (orig); + CPY (orig); } - if (mp->m_gname) { - CHECKMEM (mp->m_gname); - CPY (mp->m_gname); - isgroup++; + + /* concatenate all the new addresses onto 'buf' */ + for (isgroup = 0; (cp = getname (str)); ) { + if ((mp = getm (cp, NULL, 0, fmt_norm, NULL)) == NULL) + continue; + + if (isgroup && (mp->m_gname || !mp->m_ingrp)) { + *dst++ = ';'; + isgroup = 0; + } + /* if we get here we're going to add an address */ + if (dst != buf) { + *dst++ = ','; + *dst++ = ' '; + } + if (mp->m_gname) { + CHECKMEM (mp->m_gname); + CPY (mp->m_gname); + isgroup++; + } + sp = adrformat (mp); + CHECKMEM (sp); + CPY (sp); + mnfree (mp); } - sp = adrformat (mp); - CHECKMEM (sp); - CPY (sp); - mnfree (mp); - } - if (isgroup) - *dst++ = ';'; + if (isgroup) + *dst++ = ';'; - *dst = '\0'; - last_dst = dst; - return (buf); + *dst = '\0'; + last_dst = dst; + return (buf); } diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index a180c56..87e0769 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -1,4 +1,3 @@ - /* * fmt_compile.c -- "compile" format strings for fmt_scan * @@ -29,165 +28,165 @@ */ struct comp *wantcomp[128]; -static struct format *formatvec; /* array to hold formats */ -static struct format *next_fp; /* next free format slot */ -static struct format *fp; /* current format slot */ -static struct comp *cm; /* most recent comp ref */ -static struct ftable *ftbl; /* most recent func ref */ +static struct format *formatvec; /* array to hold formats */ +static struct format *next_fp; /* next free format slot */ +static struct format *fp; /* current format slot */ +static struct comp *cm; /* most recent comp ref */ +static struct ftable *ftbl; /* most recent func ref */ static int ncomp; -static int infunction; /* function nesting cnt */ +static int infunction; /* function nesting cnt */ extern struct mailname fmt_mnull; /* ftable->type (argument type) */ -#define TF_COMP 0 /* component expected */ -#define TF_NUM 1 /* number expected */ -#define TF_STR 2 /* string expected */ -#define TF_EXPR 3 /* component or func. expected */ -#define TF_NONE 4 /* no argument */ -#define TF_MYBOX 5 /* special - get current user's mbox */ -#define TF_NOW 6 /* special - get current unix time */ -#define TF_EXPR_SV 7 /* like expr but save current str reg */ -#define TF_NOP 8 /* like expr but no result */ +#define TF_COMP 0 /* component expected */ +#define TF_NUM 1 /* number expected */ +#define TF_STR 2 /* string expected */ +#define TF_EXPR 3 /* component or func. expected */ +#define TF_NONE 4 /* no argument */ +#define TF_MYBOX 5 /* special - get current user's mbox */ +#define TF_NOW 6 /* special - get current unix time */ +#define TF_EXPR_SV 7 /* like expr but save current str reg */ +#define TF_NOP 8 /* like expr but no result */ /* ftable->flags */ /* NB that TFL_PUTS is also used to decide whether the test * in a "%<(function)..." should be a string or numeric one. */ -#define TFL_PUTS 1 /* implicit putstr if top level */ -#define TFL_PUTN 2 /* implicit putnum if top level */ +#define TFL_PUTS 1 /* implicit putstr if top level */ +#define TFL_PUTN 2 /* implicit putnum if top level */ struct ftable { - char *name; /* function name */ - char type; /* argument type */ - char f_type; /* fmt type */ - char extra; /* arg. type dependent extra info */ - char flags; + char *name; /* function name */ + char type; /* argument type */ + char f_type; /* fmt type */ + char extra; /* arg. type dependent extra info */ + char flags; }; static struct ftable functable[] = { - { "nonzero", TF_EXPR, FT_V_NE, FT_IF_V_NE, 0 }, - { "zero", TF_EXPR, FT_V_EQ, FT_IF_V_EQ, 0 }, - { "eq", TF_NUM, FT_V_EQ, FT_IF_V_EQ, 0 }, - { "ne", TF_NUM, FT_V_NE, FT_IF_V_NE, 0 }, - { "gt", TF_NUM, FT_V_GT, FT_IF_V_GT, 0 }, - { "null", TF_EXPR, FT_S_NULL, FT_IF_S_NULL, 0 }, - { "nonnull", TF_EXPR, FT_S_NONNULL, FT_IF_S, 0 }, - { "match", TF_STR, FT_V_MATCH, FT_IF_MATCH, 0 }, - { "amatch", TF_STR, FT_V_AMATCH, FT_IF_AMATCH, 0 }, - - { "putstr", TF_EXPR, FT_STR, 0, 0 }, - { "putstrf", TF_EXPR, FT_STRF, 0, 0 }, - { "putnum", TF_EXPR, FT_NUM, 0, 0 }, - { "putnumf", TF_EXPR, FT_NUMF, 0, 0 }, - { "putaddr", TF_STR, FT_PUTADDR, 0, 0 }, - { "void", TF_NOP, 0, 0, 0 }, - - { "comp", TF_COMP, FT_LS_COMP, 0, TFL_PUTS }, - { "lit", TF_STR, FT_LS_LIT, 0, TFL_PUTS }, - { "getenv", TF_STR, FT_LS_GETENV, 0, TFL_PUTS }, - { "profile", TF_STR, FT_LS_CFIND, 0, TFL_PUTS }, - { "decodecomp", TF_COMP, FT_LS_DECODECOMP, 0, TFL_PUTS }, - { "decode", TF_EXPR, FT_LS_DECODE, 0, TFL_PUTS }, - { "trim", TF_EXPR, FT_LS_TRIM, 0, 0 }, - { "compval", TF_COMP, FT_LV_COMP, 0, TFL_PUTN }, - { "compflag", TF_COMP, FT_LV_COMPFLAG, 0, TFL_PUTN }, - { "num", TF_NUM, FT_LV_LIT, 0, TFL_PUTN }, - { "msg", TF_NONE, FT_LV_DAT, 0, TFL_PUTN }, - { "cur", TF_NONE, FT_LV_DAT, 1, TFL_PUTN }, - { "size", TF_NONE, FT_LV_DAT, 2, TFL_PUTN }, - { "width", TF_NONE, FT_LV_DAT, 3, TFL_PUTN }, - { "unseen", TF_NONE, FT_LV_DAT, 4, TFL_PUTN }, - { "dat", TF_NUM, FT_LV_DAT, 0, TFL_PUTN }, - { "strlen", TF_NONE, FT_LV_STRLEN, 0, TFL_PUTN }, - { "me", TF_MYBOX, FT_LS_LIT, 0, TFL_PUTS }, - { "plus", TF_NUM, FT_LV_PLUS_L, 0, TFL_PUTN }, - { "minus", TF_NUM, FT_LV_MINUS_L, 0, TFL_PUTN }, - { "divide", TF_NUM, FT_LV_DIVIDE_L, 0, TFL_PUTN }, - { "modulo", TF_NUM, FT_LV_MODULO_L, 0, TFL_PUTN }, - { "charleft", TF_NONE, FT_LV_CHAR_LEFT, 0, TFL_PUTN }, - { "timenow", TF_NOW, FT_LV_LIT, 0, TFL_PUTN }, - - { "month", TF_COMP, FT_LS_MONTH, FT_PARSEDATE, TFL_PUTS }, - { "lmonth", TF_COMP, FT_LS_LMONTH, FT_PARSEDATE, TFL_PUTS }, - { "tzone", TF_COMP, FT_LS_ZONE, FT_PARSEDATE, TFL_PUTS }, - { "day", TF_COMP, FT_LS_DAY, FT_PARSEDATE, TFL_PUTS }, - { "weekday", TF_COMP, FT_LS_WEEKDAY, FT_PARSEDATE, TFL_PUTS }, - { "tws", TF_COMP, FT_LS_822DATE, FT_PARSEDATE, TFL_PUTS }, - { "sec", TF_COMP, FT_LV_SEC, FT_PARSEDATE, TFL_PUTN }, - { "min", TF_COMP, FT_LV_MIN, FT_PARSEDATE, TFL_PUTN }, - { "hour", TF_COMP, FT_LV_HOUR, FT_PARSEDATE, TFL_PUTN }, - { "mday", TF_COMP, FT_LV_MDAY, FT_PARSEDATE, TFL_PUTN }, - { "mon", TF_COMP, FT_LV_MON, FT_PARSEDATE, TFL_PUTN }, - { "year", TF_COMP, FT_LV_YEAR, FT_PARSEDATE, TFL_PUTN }, - { "yday", TF_COMP, FT_LV_YDAY, FT_PARSEDATE, TFL_PUTN }, - { "wday", TF_COMP, FT_LV_WDAY, FT_PARSEDATE, TFL_PUTN }, - { "zone", TF_COMP, FT_LV_ZONE, FT_PARSEDATE, TFL_PUTN }, - { "clock", TF_COMP, FT_LV_CLOCK, FT_PARSEDATE, TFL_PUTN }, - { "rclock", TF_COMP, FT_LV_RCLOCK, FT_PARSEDATE, TFL_PUTN }, - { "sday", TF_COMP, FT_LV_DAYF, FT_PARSEDATE, TFL_PUTN }, - { "szone", TF_COMP, FT_LV_ZONEF, FT_PARSEDATE, TFL_PUTN }, - { "dst", TF_COMP, FT_LV_DST, FT_PARSEDATE, TFL_PUTN }, - { "pretty", TF_COMP, FT_LS_PRETTY, FT_PARSEDATE, TFL_PUTS }, - { "nodate", TF_COMP, FT_LV_COMPFLAG, FT_PARSEDATE, TFL_PUTN }, - { "date2local", TF_COMP, FT_LOCALDATE, FT_PARSEDATE, 0 }, - { "date2gmt", TF_COMP, FT_GMTDATE, FT_PARSEDATE, 0 }, - - { "pers", TF_COMP, FT_LS_PERS, FT_PARSEADDR, TFL_PUTS }, - { "mbox", TF_COMP, FT_LS_MBOX, FT_PARSEADDR, TFL_PUTS }, - { "host", TF_COMP, FT_LS_HOST, FT_PARSEADDR, TFL_PUTS }, - { "path", TF_COMP, FT_LS_PATH, FT_PARSEADDR, TFL_PUTS }, - { "gname", TF_COMP, FT_LS_GNAME, FT_PARSEADDR, TFL_PUTS }, - { "note", TF_COMP, FT_LS_NOTE, FT_PARSEADDR, TFL_PUTS }, - { "addr", TF_COMP, FT_LS_ADDR, FT_PARSEADDR, TFL_PUTS }, - { "proper", TF_COMP, FT_LS_822ADDR, FT_PARSEADDR, TFL_PUTS }, - { "type", TF_COMP, FT_LV_HOSTTYPE, FT_PARSEADDR, TFL_PUTN }, - { "ingrp", TF_COMP, FT_LV_INGRPF, FT_PARSEADDR, TFL_PUTN }, - { "nohost", TF_COMP, FT_LV_NOHOSTF, FT_PARSEADDR, TFL_PUTN }, - { "formataddr", TF_EXPR_SV,FT_FORMATADDR, FT_FORMATADDR, 0 }, - { "friendly", TF_COMP, FT_LS_FRIENDLY, FT_PARSEADDR, TFL_PUTS }, - - { "mymbox", TF_COMP, FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN }, - { "addtoseq", TF_STR, FT_ADDTOSEQ, 0, 0 }, - - { "unquote", TF_EXPR, FT_LS_UNQUOTE, 0, TFL_PUTS}, - - { NULL, 0, 0, 0, 0 } + { "nonzero", TF_EXPR, FT_V_NE, FT_IF_V_NE, 0 }, + { "zero", TF_EXPR, FT_V_EQ, FT_IF_V_EQ, 0 }, + { "eq", TF_NUM, FT_V_EQ, FT_IF_V_EQ, 0 }, + { "ne", TF_NUM, FT_V_NE, FT_IF_V_NE, 0 }, + { "gt", TF_NUM, FT_V_GT, FT_IF_V_GT, 0 }, + { "null", TF_EXPR, FT_S_NULL, FT_IF_S_NULL, 0 }, + { "nonnull", TF_EXPR, FT_S_NONNULL, FT_IF_S, 0 }, + { "match", TF_STR, FT_V_MATCH, FT_IF_MATCH, 0 }, + { "amatch", TF_STR, FT_V_AMATCH, FT_IF_AMATCH, 0 }, + + { "putstr", TF_EXPR, FT_STR, 0, 0 }, + { "putstrf", TF_EXPR, FT_STRF, 0, 0 }, + { "putnum", TF_EXPR, FT_NUM, 0, 0 }, + { "putnumf", TF_EXPR, FT_NUMF, 0, 0 }, + { "putaddr", TF_STR, FT_PUTADDR, 0, 0 }, + { "void", TF_NOP, 0, 0, 0 }, + + { "comp", TF_COMP, FT_LS_COMP, 0, TFL_PUTS }, + { "lit", TF_STR, FT_LS_LIT, 0, TFL_PUTS }, + { "getenv", TF_STR, FT_LS_GETENV, 0, TFL_PUTS }, + { "profile", TF_STR, FT_LS_CFIND, 0, TFL_PUTS }, + { "decodecomp", TF_COMP, FT_LS_DECODECOMP, 0, TFL_PUTS }, + { "decode", TF_EXPR, FT_LS_DECODE, 0, TFL_PUTS }, + { "trim", TF_EXPR, FT_LS_TRIM, 0, 0 }, + { "compval", TF_COMP, FT_LV_COMP, 0, TFL_PUTN }, + { "compflag", TF_COMP, FT_LV_COMPFLAG, 0, TFL_PUTN }, + { "num", TF_NUM, FT_LV_LIT, 0, TFL_PUTN }, + { "msg", TF_NONE, FT_LV_DAT, 0, TFL_PUTN }, + { "cur", TF_NONE, FT_LV_DAT, 1, TFL_PUTN }, + { "size", TF_NONE, FT_LV_DAT, 2, TFL_PUTN }, + { "width", TF_NONE, FT_LV_DAT, 3, TFL_PUTN }, + { "unseen", TF_NONE, FT_LV_DAT, 4, TFL_PUTN }, + { "dat", TF_NUM, FT_LV_DAT, 0, TFL_PUTN }, + { "strlen", TF_NONE, FT_LV_STRLEN, 0, TFL_PUTN }, + { "me", TF_MYBOX, FT_LS_LIT, 0, TFL_PUTS }, + { "plus", TF_NUM, FT_LV_PLUS_L, 0, TFL_PUTN }, + { "minus", TF_NUM, FT_LV_MINUS_L, 0, TFL_PUTN }, + { "divide", TF_NUM, FT_LV_DIVIDE_L, 0, TFL_PUTN }, + { "modulo", TF_NUM, FT_LV_MODULO_L, 0, TFL_PUTN }, + { "charleft", TF_NONE, FT_LV_CHAR_LEFT, 0, TFL_PUTN }, + { "timenow", TF_NOW, FT_LV_LIT, 0, TFL_PUTN }, + + { "month", TF_COMP, FT_LS_MONTH, FT_PARSEDATE, TFL_PUTS }, + { "lmonth", TF_COMP, FT_LS_LMONTH, FT_PARSEDATE, TFL_PUTS }, + { "tzone", TF_COMP, FT_LS_ZONE, FT_PARSEDATE, TFL_PUTS }, + { "day", TF_COMP, FT_LS_DAY, FT_PARSEDATE, TFL_PUTS }, + { "weekday", TF_COMP, FT_LS_WEEKDAY, FT_PARSEDATE, TFL_PUTS }, + { "tws", TF_COMP, FT_LS_822DATE, FT_PARSEDATE, TFL_PUTS }, + { "sec", TF_COMP, FT_LV_SEC, FT_PARSEDATE, TFL_PUTN }, + { "min", TF_COMP, FT_LV_MIN, FT_PARSEDATE, TFL_PUTN }, + { "hour", TF_COMP, FT_LV_HOUR, FT_PARSEDATE, TFL_PUTN }, + { "mday", TF_COMP, FT_LV_MDAY, FT_PARSEDATE, TFL_PUTN }, + { "mon", TF_COMP, FT_LV_MON, FT_PARSEDATE, TFL_PUTN }, + { "year", TF_COMP, FT_LV_YEAR, FT_PARSEDATE, TFL_PUTN }, + { "yday", TF_COMP, FT_LV_YDAY, FT_PARSEDATE, TFL_PUTN }, + { "wday", TF_COMP, FT_LV_WDAY, FT_PARSEDATE, TFL_PUTN }, + { "zone", TF_COMP, FT_LV_ZONE, FT_PARSEDATE, TFL_PUTN }, + { "clock", TF_COMP, FT_LV_CLOCK, FT_PARSEDATE, TFL_PUTN }, + { "rclock", TF_COMP, FT_LV_RCLOCK, FT_PARSEDATE, TFL_PUTN }, + { "sday", TF_COMP, FT_LV_DAYF, FT_PARSEDATE, TFL_PUTN }, + { "szone", TF_COMP, FT_LV_ZONEF, FT_PARSEDATE, TFL_PUTN }, + { "dst", TF_COMP, FT_LV_DST, FT_PARSEDATE, TFL_PUTN }, + { "pretty", TF_COMP, FT_LS_PRETTY, FT_PARSEDATE, TFL_PUTS }, + { "nodate", TF_COMP, FT_LV_COMPFLAG, FT_PARSEDATE, TFL_PUTN }, + { "date2local", TF_COMP, FT_LOCALDATE, FT_PARSEDATE, 0 }, + { "date2gmt", TF_COMP, FT_GMTDATE, FT_PARSEDATE, 0 }, + + { "pers", TF_COMP, FT_LS_PERS, FT_PARSEADDR, TFL_PUTS }, + { "mbox", TF_COMP, FT_LS_MBOX, FT_PARSEADDR, TFL_PUTS }, + { "host", TF_COMP, FT_LS_HOST, FT_PARSEADDR, TFL_PUTS }, + { "path", TF_COMP, FT_LS_PATH, FT_PARSEADDR, TFL_PUTS }, + { "gname", TF_COMP, FT_LS_GNAME, FT_PARSEADDR, TFL_PUTS }, + { "note", TF_COMP, FT_LS_NOTE, FT_PARSEADDR, TFL_PUTS }, + { "addr", TF_COMP, FT_LS_ADDR, FT_PARSEADDR, TFL_PUTS }, + { "proper", TF_COMP, FT_LS_822ADDR, FT_PARSEADDR, TFL_PUTS }, + { "type", TF_COMP, FT_LV_HOSTTYPE, FT_PARSEADDR, TFL_PUTN }, + { "ingrp", TF_COMP, FT_LV_INGRPF, FT_PARSEADDR, TFL_PUTN }, + { "nohost", TF_COMP, FT_LV_NOHOSTF, FT_PARSEADDR, TFL_PUTN }, + { "formataddr", TF_EXPR_SV, FT_FORMATADDR, FT_FORMATADDR, 0 }, + { "friendly", TF_COMP, FT_LS_FRIENDLY, FT_PARSEADDR, TFL_PUTS }, + + { "mymbox", TF_COMP, FT_LV_COMPFLAG, FT_MYMBOX, TFL_PUTN }, + { "addtoseq", TF_STR, FT_ADDTOSEQ, 0, 0 }, + + { "unquote", TF_EXPR, FT_LS_UNQUOTE, 0, TFL_PUTS}, + + { NULL, 0, 0, 0, 0 } }; /* Add new component to the hash table */ #define NEWCOMP(cm,name) do { \ - cm = ((struct comp *) calloc(1, sizeof (struct comp)));\ - cm->c_name = name;\ - ncomp++;\ - i = CHASH(name);\ - cm->c_next = wantcomp[i];\ - wantcomp[i] = cm; \ + cm = ((struct comp *) calloc(1, sizeof (struct comp)));\ + cm->c_name = name;\ + ncomp++;\ + i = CHASH(name);\ + cm->c_next = wantcomp[i];\ + wantcomp[i] = cm; \ } while (0) #define NEWFMT (next_fp++) #define NEW(type,fill,wid) do {\ - fp=NEWFMT; fp->f_type=(type); fp->f_fill=(fill); fp->f_width=(wid); \ + fp=NEWFMT; fp->f_type=(type); fp->f_fill=(fill); fp->f_width=(wid); \ } while (0) /* Add (possibly new) component to the hash table */ #define ADDC(name) do { \ - FINDCOMP(cm, name);\ - if (!cm) {\ - NEWCOMP(cm,name);\ - }\ - fp->f_comp = cm; \ + FINDCOMP(cm, name);\ + if (!cm) {\ + NEWCOMP(cm,name);\ + }\ + fp->f_comp = cm; \ } while (0) -#define LV(type, value) do { NEW(type,0,0); fp->f_value = (value); } while (0) -#define LS(type, str) do { NEW(type,0,0); fp->f_text = (str); } while (0) +#define LV(type, value) do { NEW(type,0,0); fp->f_value = (value); } while (0) +#define LS(type, str) do { NEW(type,0,0); fp->f_text = (str); } while (0) -#define PUTCOMP(comp) do { NEW(FT_COMP,0,0); ADDC(comp); } while (0) -#define PUTLIT(str) do { NEW(FT_LIT,0,0); fp->f_text = (str); } while (0) -#define PUTC(c) do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0) +#define PUTCOMP(comp) do { NEW(FT_COMP,0,0); ADDC(comp); } while (0) +#define PUTLIT(str) do { NEW(FT_LIT,0,0); fp->f_text = (str); } while (0) +#define PUTC(c) do { NEW(FT_CHAR,0,0); fp->f_char = (c); } while (0) static char *format_string; -static unsigned char *usr_fstring; /* for CERROR */ +static unsigned char *usr_fstring; /* for CERROR */ #define CERROR(str) compile_error (str, cp) @@ -213,41 +212,41 @@ static char *do_if(char *); static struct ftable * lookup(char *name) { - register struct ftable *t = functable; - register char *nm; - register char c = *name; + register struct ftable *t = functable; + register char *nm; + register char c = *name; - while ((nm = t->name)) { - if (*nm == c && strcmp (nm, name) == 0) - return (ftbl = t); + while ((nm = t->name)) { + if (*nm == c && strcmp (nm, name) == 0) + return (ftbl = t); - t++; - } - return (struct ftable *) 0; + t++; + } + return (struct ftable *) 0; } static void compile_error(char *str, char *cp) { - int i, errpos, errctx; + int i, errpos, errctx; - errpos = cp - format_string; - errctx = errpos > 20 ? 20 : errpos; - usr_fstring[errpos] = '\0'; + errpos = cp - format_string; + errctx = errpos > 20 ? 20 : errpos; + usr_fstring[errpos] = '\0'; - for (i = errpos-errctx; i < errpos; i++) { + for (i = errpos-errctx; i < errpos; i++) { #ifdef LOCALE - if (iscntrl(usr_fstring[i])) + if (iscntrl(usr_fstring[i])) #else - if (usr_fstring[i] < 32) + if (usr_fstring[i] < 32) #endif - usr_fstring[i] = '_'; - } + usr_fstring[i] = '_'; + } - advise(NULL, "\"%s\": format compile error - %s", - &usr_fstring[errpos-errctx], str); - adios (NULL, "%*s", errctx+1, "^"); + advise(NULL, "\"%s\": format compile error - %s", + &usr_fstring[errpos-errctx], str); + adios (NULL, "%*s", errctx+1, "^"); } /* @@ -259,409 +258,404 @@ compile_error(char *str, char *cp) int fmt_compile(char *fstring, struct format **fmt) { - register char *cp; - int i; - - if (format_string) - free (format_string); - format_string = getcpy (fstring); - usr_fstring = fstring; - - /* init the component hash table. */ - for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++) - wantcomp[i] = 0; - - memset((char *) &fmt_mnull, 0, sizeof(fmt_mnull)); - - /* it takes at least 4 char to generate one format so we - * allocate a worst-case format array using 1/4 the length - * of the format string. We actually need twice this much - * to handle both pre-processing (e.g., address parsing) and - * normal processing. - */ - i = strlen(fstring)/2 + 1; - if (i==1) i++; - next_fp = formatvec = (struct format *)calloc ((size_t) i, - sizeof(struct format)); - if (next_fp == NULL) - adios (NULL, "unable to allocate format storage"); - - ncomp = 0; - infunction = 0; - - cp = compile(format_string); - if (*cp) { - CERROR("extra '%>', '%|' or '%?'"); - } - LV(FT_DONE, 0); /* really done */ - *fmt = formatvec; - - return (ncomp); + register char *cp; + int i; + + if (format_string) + free (format_string); + format_string = getcpy (fstring); + usr_fstring = fstring; + + /* init the component hash table. */ + for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++) + wantcomp[i] = 0; + + memset((char *) &fmt_mnull, 0, sizeof(fmt_mnull)); + + /* it takes at least 4 char to generate one format so we + * allocate a worst-case format array using 1/4 the length + * of the format string. We actually need twice this much + * to handle both pre-processing (e.g., address parsing) and + * normal processing. + */ + i = strlen(fstring)/2 + 1; + if (i == 1) + i++; + next_fp = formatvec = (struct format *)calloc ((size_t) i, + sizeof(struct format)); + if (next_fp == NULL) + adios (NULL, "unable to allocate format storage"); + + ncomp = 0; + infunction = 0; + + cp = compile(format_string); + if (*cp) { + CERROR("extra '%>', '%|' or '%?'"); + } + LV(FT_DONE, 0); /* really done */ + *fmt = formatvec; + + return (ncomp); } static char * compile (char *sp) { - register char *cp = sp; - register int c; - - for (;;) { - sp = cp; - while ((c = *cp) && c != '%') - cp++; - *cp = 0; - switch (cp-sp) { - case 0: - break; - case 1: - PUTC(*sp); - break; - default: - PUTLIT(sp); - break; - } - if (c == 0) - return (cp); - - switch (c = *++cp) { - case '%': - PUTC (*cp); - cp++; - break; - - case '|': - case '>': - case '?': - case ']': - return (cp); - - case '<': - cp = do_if(++cp); - break; - - case '[': /* ] */ - cp = do_loop(++cp); - break; - - case ';': /* comment line */ - cp++; - while ((c = *cp++) && c != '\n') - continue; - break; - - default: - cp = do_spec(cp); - break; + register char *cp = sp; + register int c; + + for (;;) { + sp = cp; + while ((c = *cp) && c != '%') + cp++; + *cp = 0; + switch (cp-sp) { + case 0: + break; + case 1: + PUTC(*sp); + break; + default: + PUTLIT(sp); + break; + } + if (c == 0) + return (cp); + + switch (c = *++cp) { + case '%': + PUTC (*cp); + cp++; + break; + + case '|': + case '>': + case '?': + case ']': + return (cp); + + case '<': + cp = do_if(++cp); + break; + + case '[': /* ] */ + cp = do_loop(++cp); + break; + + case ';': /* comment line */ + cp++; + while ((c = *cp++) && c != '\n') + continue; + break; + + default: + cp = do_spec(cp); + break; + } } - } } static char * do_spec(char *sp) { - register char *cp = sp; - register int c; -#ifndef lint - register int ljust = 0; -#endif /* not lint */ - register int wid = 0; - register char fill = ' '; - - c = *cp++; - if (c == '-') { - ljust++; - c = *cp++; - } - if (c == '0') { - fill = c; - c = *cp++; - } - while (isdigit(c)) { - wid = wid*10 + (c - '0'); + register char *cp = sp; + register int c; +#ifndef lint + register int ljust = 0; +#endif /* not lint */ + register int wid = 0; + register char fill = ' '; + c = *cp++; - } - if (c == '{') { - cp = do_name(cp, 0); - if (! infunction) - fp->f_type = wid? FT_COMPF : FT_COMP; - } - else if (c == '(') { - cp = do_func(cp); - if (! infunction) { - if (ftbl->flags & TFL_PUTS) { - LV( wid? FT_STRF : FT_STR, ftbl->extra); - } - else if (ftbl->flags & TFL_PUTN) { - LV( wid? FT_NUMF : FT_NUM, ftbl->extra); - } + if (c == '-') { + ljust++; + c = *cp++; + } + if (c == '0') { + fill = c; + c = *cp++; + } + while (isdigit(c)) { + wid = wid*10 + (c - '0'); + c = *cp++; } - } - else { - CERROR("component or function name expected"); - } - if (ljust) - wid = -wid; - fp->f_width = wid; - fp->f_fill = fill; - - return (cp); + if (c == '{') { + cp = do_name(cp, 0); + if (! infunction) + fp->f_type = wid? FT_COMPF : FT_COMP; + } else if (c == '(') { + cp = do_func(cp); + if (! infunction) { + if (ftbl->flags & TFL_PUTS) { + LV( wid? FT_STRF : FT_STR, ftbl->extra); + } else if (ftbl->flags & TFL_PUTN) { + LV( wid? FT_NUMF : FT_NUM, ftbl->extra); + } + } + } else { + CERROR("component or function name expected"); + } + if (ljust) + wid = -wid; + fp->f_width = wid; + fp->f_fill = fill; + + return (cp); } static char * do_name(char *sp, int preprocess) { - register char *cp = sp; - register int c; - register int i; - static int primed = 0; - - while (isalnum(c = *cp++) || c == '-' || c == '_') - ; - if (c != '}') { - CERROR("'}' expected"); - } - cp[-1] = '\0'; - PUTCOMP(sp); - switch (preprocess) { - - case FT_PARSEDATE: - if (cm->c_type & CT_ADDR) { - CERROR("component used as both date and address"); + register char *cp = sp; + register int c; + register int i; + static int primed = 0; + + while (isalnum(c = *cp++) || c == '-' || c == '_') + ; + if (c != '}') { + CERROR("'}' expected"); } - cm->c_tws = (struct tws *) - calloc((size_t) 1, sizeof(*cm->c_tws)); - fp->f_type = preprocess; - PUTCOMP(sp); - cm->c_type |= CT_DATE; - break; - - case FT_MYMBOX: - if (!primed) { - ismymbox ((struct mailname *) 0); - primed++; - } - /* fall through */ - case FT_PARSEADDR: - if (cm->c_type & CT_DATE) { - CERROR("component used as both date and address"); - } - cm->c_mn = &fmt_mnull; - fp->f_type = preprocess; + cp[-1] = '\0'; PUTCOMP(sp); - cm->c_type |= CT_ADDR; - break; + switch (preprocess) { - case FT_FORMATADDR: - if (cm->c_type & CT_DATE) { - CERROR("component used as both date and address"); + case FT_PARSEDATE: + if (cm->c_type & CT_ADDR) { + CERROR("component used as both date and address"); + } + cm->c_tws = (struct tws *) + calloc((size_t) 1, sizeof(*cm->c_tws)); + fp->f_type = preprocess; + PUTCOMP(sp); + cm->c_type |= CT_DATE; + break; + + case FT_MYMBOX: + if (!primed) { + ismymbox ((struct mailname *) 0); + primed++; + } + /* fall through */ + case FT_PARSEADDR: + if (cm->c_type & CT_DATE) { + CERROR("component used as both date and address"); + } + cm->c_mn = &fmt_mnull; + fp->f_type = preprocess; + PUTCOMP(sp); + cm->c_type |= CT_ADDR; + break; + + case FT_FORMATADDR: + if (cm->c_type & CT_DATE) { + CERROR("component used as both date and address"); + } + cm->c_type |= CT_ADDR; + break; } - cm->c_type |= CT_ADDR; - break; - } - return (cp); + return (cp); } static char * do_func(char *sp) { - register char *cp = sp; - register int c; - register struct ftable *t; - register int n; - int mflag; /* minus sign in NUM */ - - infunction++; - - while (isalnum(c = *cp++)) - ; - if (c != '(' && c != '{' && c != ' ' && c != ')') { - CERROR("'(', '{', ' ' or ')' expected"); - } - cp[-1] = '\0'; - if ((t = lookup (sp)) == 0) { - CERROR("unknown function"); - } - if (isspace(c)) - c = *cp++; + register char *cp = sp; + register int c; + register struct ftable *t; + register int n; + int mflag; /* minus sign in NUM */ + + infunction++; + + while (isalnum(c = *cp++)) + ; + if (c != '(' && c != '{' && c != ' ' && c != ')') { + CERROR("'(', '{', ' ' or ')' expected"); + } + cp[-1] = '\0'; + if ((t = lookup (sp)) == 0) { + CERROR("unknown function"); + } + if (isspace(c)) + c = *cp++; - switch (t->type) { + switch (t->type) { - case TF_COMP: - if (c != '{') { - CERROR("component name expected"); + case TF_COMP: + if (c != '{') { + CERROR("component name expected"); + } + cp = do_name(cp, t->extra); + fp->f_type = t->f_type; + c = *cp++; + break; + + case TF_NUM: + if ((mflag = (c == '-'))) + c = *cp++; + n = 0; + while (isdigit(c)) { + n = n*10 + (c - '0'); + c = *cp++; + } + if (mflag) + n = (-n); + LV(t->f_type,n); + break; + + case TF_STR: + sp = cp - 1; + while (c && c != ')') + c = *cp++; + cp[-1] = '\0'; + LS(t->f_type,sp); + break; + + case TF_NONE: + LV(t->f_type,t->extra); + break; + + case TF_MYBOX: + LS(t->f_type, getusername()); + break; + + case TF_NOW: + LV(t->f_type, time((time_t *) 0)); + break; + + case TF_EXPR_SV: + LV(FT_SAVESTR, 0); + /* fall through */ + case TF_EXPR: + *--cp = c; + cp = do_expr(cp, t->extra); + LV(t->f_type, 0); + c = *cp++; + ftbl = t; + break; + + case TF_NOP: + *--cp = c; + cp = do_expr(cp, t->extra); + c = *cp++; + ftbl = t; + break; } - cp = do_name(cp, t->extra); - fp->f_type = t->f_type; - c = *cp++; - break; - - case TF_NUM: - if ((mflag = (c == '-'))) - c = *cp++; - n = 0; - while (isdigit(c)) { - n = n*10 + (c - '0'); - c = *cp++; + if (c != ')') { + CERROR("')' expected"); } - if (mflag) - n = (-n); - LV(t->f_type,n); - break; - - case TF_STR: - sp = cp - 1; - while (c && c != ')') - c = *cp++; - cp[-1] = '\0'; - LS(t->f_type,sp); - break; - - case TF_NONE: - LV(t->f_type,t->extra); - break; - - case TF_MYBOX: - LS(t->f_type, getusername()); - break; - - case TF_NOW: - LV(t->f_type, time((time_t *) 0)); - break; - - case TF_EXPR_SV: - LV(FT_SAVESTR, 0); - /* fall through */ - case TF_EXPR: - *--cp = c; - cp = do_expr(cp, t->extra); - LV(t->f_type, 0); - c = *cp++; - ftbl = t; - break; - - case TF_NOP: - *--cp = c; - cp = do_expr(cp, t->extra); - c = *cp++; - ftbl = t; - break; - } - if (c != ')') { - CERROR("')' expected"); - } - --infunction; - return (cp); + --infunction; + return (cp); } static char * do_expr (char *sp, int preprocess) { - register char *cp = sp; - register int c; - - if ((c = *cp++) == '{') { - cp = do_name (cp, preprocess); - fp->f_type = FT_LS_COMP; - } else if (c == '(') { - cp = do_func (cp); - } else if (c == ')') { - return (--cp); - } else if (c == '%' && *cp == '<') { - cp = do_if (cp+1); - } else { - CERROR ("'(', '{', '%<' or ')' expected"); - } - return (cp); + register char *cp = sp; + register int c; + + if ((c = *cp++) == '{') { + cp = do_name (cp, preprocess); + fp->f_type = FT_LS_COMP; + } else if (c == '(') { + cp = do_func (cp); + } else if (c == ')') { + return (--cp); + } else if (c == '%' && *cp == '<') { + cp = do_if (cp+1); + } else { + CERROR ("'(', '{', '%<' or ')' expected"); + } + return (cp); } static char * do_loop(char *sp) { - register char *cp = sp; - struct format *floop; + register char *cp = sp; + struct format *floop; - floop = next_fp; - cp = compile (cp); - if (*cp++ != ']') - CERROR ("']' expected"); + floop = next_fp; + cp = compile (cp); + if (*cp++ != ']') + CERROR ("']' expected"); - LV(FT_DONE, 1); /* not yet done */ - LV(FT_GOTO, 0); - fp->f_skip = floop - fp; /* skip backwards */ + LV(FT_DONE, 1); /* not yet done */ + LV(FT_GOTO, 0); + fp->f_skip = floop - fp; /* skip backwards */ - return cp; + return cp; } static char * do_if(char *sp) { - register char *cp = sp; - register struct format *fexpr, - *fif = (struct format *)NULL; - register int c = '<'; - - for (;;) { - if (c == '<') { /* doing an IF */ - if ((c = *cp++) == '{') /*}*/{ - cp = do_name(cp, 0); - fp->f_type = FT_LS_COMP; - LV (FT_IF_S, 0); - } - else if (c == '(') { - cp = do_func(cp); - /* see if we can merge the load and the "if" */ - if (ftbl->f_type >= IF_FUNCS) - fp->f_type = ftbl->extra; - else { - /* Put out a string test or a value test depending - * on what this function's return type is. - */ - if (ftbl->flags & TFL_PUTS) { - LV (FT_IF_S, 0); - } else { - LV (FT_IF_V_NE, 0); - } + register char *cp = sp; + register struct format *fexpr, *fif = (struct format *)NULL; + register int c = '<'; + + for (;;) { + if (c == '<') { /* doing an IF */ + if ((c = *cp++) == '{') /*}*/{ + cp = do_name(cp, 0); + fp->f_type = FT_LS_COMP; + LV (FT_IF_S, 0); + } else if (c == '(') { + cp = do_func(cp); + /* see if we can merge the load and the "if" */ + if (ftbl->f_type >= IF_FUNCS) + fp->f_type = ftbl->extra; + else { + /* Put out a string test or a value + * test depending on what this + * function 's return type is. + */ + if (ftbl->flags & TFL_PUTS) { + LV (FT_IF_S, 0); + } else { + LV (FT_IF_V_NE, 0); + } + } + } else { + CERROR("'(' or '{' expected"); /*}*/ + } } - } - else { - CERROR("'(' or '{' expected"); /*}*/ - } - } - fexpr = fp; /* loc of [ELS]IF */ - cp = compile (cp); /* compile IF TRUE stmts */ - if (fif) - fif->f_skip = next_fp - fif; + fexpr = fp; /* loc of [ELS]IF */ + cp = compile (cp); /* compile IF TRUE stmts */ + if (fif) + fif->f_skip = next_fp - fif; - if ((c = *cp++) == '|') { /* the last ELSE */ - LV(FT_GOTO, 0); - fif = fp; /* loc of GOTO */ - fexpr->f_skip = next_fp - fexpr; + if ((c = *cp++) == '|') { /* the last ELSE */ + LV(FT_GOTO, 0); + fif = fp; /* loc of GOTO */ + fexpr->f_skip = next_fp - fexpr; - fexpr = (struct format *)NULL;/* no extra ENDIF */ + fexpr = (struct format *)NULL;/* no extra ENDIF */ - cp = compile (cp); /* compile ELSE stmts */ - fif->f_skip = next_fp - fif; - c = *cp++; - } - else if (c == '?') { /* another ELSIF */ - LV(FT_GOTO, 0); - fif = fp; /* loc of GOTO */ - fexpr->f_skip = next_fp - fexpr; + cp = compile (cp); /* compile ELSE stmts */ + fif->f_skip = next_fp - fif; + c = *cp++; + } else if (c == '?') { /* another ELSIF */ + LV(FT_GOTO, 0); + fif = fp; /* loc of GOTO */ + fexpr->f_skip = next_fp - fexpr; - c = '<'; /* impersonate an IF */ - continue; + c = '<'; /* impersonate an IF */ + continue; + } + break; } - break; - } - if (c != '>') { - CERROR("'>' expected."); - } + if (c != '>') { + CERROR("'>' expected."); + } - if (fexpr) /* IF ... [ELSIF ...] ENDIF */ - fexpr->f_skip = next_fp - fexpr; + if (fexpr) /* IF ... [ELSIF ...] ENDIF */ + fexpr->f_skip = next_fp - fexpr; - return (cp); + return (cp); } diff --git a/sbr/fmt_def.c b/sbr/fmt_def.c index 1edb787..d6e2e9f 100644 --- a/sbr/fmt_def.c +++ b/sbr/fmt_def.c @@ -1,4 +1,3 @@ - /* * fmt_def.c -- some defines for sbr/fmt_scan.c * diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index 44a18b3..4acabe7 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -1,4 +1,3 @@ - /* * fmt_new.c -- read format file/string and normalize * @@ -27,34 +26,34 @@ static void normalize (char *); char * new_fs (char *form, char *format, char *default_fs) { - struct stat st; - register FILE *fp; + struct stat st; + register FILE *fp; - if (formats) - free (formats); + if (formats) + free (formats); - if (form) { - if ((fp = fopen (etcpath (form), "r")) == NULL) - adios (form, "unable to open format file"); + if (form) { + if ((fp = fopen (etcpath (form), "r")) == NULL) + adios (form, "unable to open format file"); - if (fstat (fileno (fp), &st) == -1) - adios (form, "unable to stat format file"); + if (fstat (fileno (fp), &st) == -1) + adios (form, "unable to stat format file"); - formats = mh_xmalloc ((size_t) st.st_size + 1); + formats = mh_xmalloc ((size_t) st.st_size + 1); - if (read (fileno(fp), formats, (int) st.st_size) != st.st_size) - adios (form, "error reading format file"); + if (read (fileno(fp), formats, (int) st.st_size) != st.st_size) + adios (form, "error reading format file"); - formats[st.st_size] = '\0'; + formats[st.st_size] = '\0'; - fclose (fp); - } else { - formats = getcpy (format ? format : default_fs); - } + fclose (fp); + } else { + formats = getcpy (format ? format : default_fs); + } - normalize (formats); /* expand escapes */ + normalize (formats); /* expand escapes */ - return formats; + return formats; } @@ -65,43 +64,43 @@ new_fs (char *form, char *format, char *default_fs) static void normalize (char *cp) { - char *dp; - - for (dp = cp; *cp; cp++) { - if (*cp != QUOTE) { - *dp++ = *cp; - } else { - switch (*++cp) { - case 'b': - *dp++ = '\b'; - break; - - case 'f': - *dp++ = '\f'; - break; - - case 'n': - *dp++ = '\n'; - break; - - case 'r': - *dp++ = '\r'; - break; - - case 't': - *dp++ = '\t'; - break; - - case '\n': - break; - - case 0: - cp--; /* fall */ - default: - *dp++ = *cp; - break; - } + char *dp; + + for (dp = cp; *cp; cp++) { + if (*cp != QUOTE) { + *dp++ = *cp; + } else { + switch (*++cp) { + case 'b': + *dp++ = '\b'; + break; + + case 'f': + *dp++ = '\f'; + break; + + case 'n': + *dp++ = '\n'; + break; + + case 'r': + *dp++ = '\r'; + break; + + case 't': + *dp++ = '\t'; + break; + + case '\n': + break; + + case 0: + cp--; /* fall */ + default: + *dp++ = *cp; + break; + } + } } - } - *dp = '\0'; + *dp = '\0'; } diff --git a/sbr/fmt_rfc2047.c b/sbr/fmt_rfc2047.c index 4d3fc29..92e168b 100644 --- a/sbr/fmt_rfc2047.c +++ b/sbr/fmt_rfc2047.c @@ -1,6 +1,5 @@ - /* - * fmt_rfc2047.c -- decode RFC-2047 header format + * fmt_rfc2047.c -- decode RFC-2047 header format * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -15,25 +14,25 @@ #endif static signed char hexindex[] = { - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, + -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; static signed char index_64[128] = { - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, - 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14, - 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1, - -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, - 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, + 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14, + 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1, + -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, + 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 }; #define char64(c) (((unsigned char) (c) > 127) ? -1 : index_64[(unsigned char) (c)]) @@ -41,9 +40,9 @@ static signed char index_64[128] = { static int unqp (unsigned char byte1, unsigned char byte2) { - if (hexindex[byte1] == -1 || hexindex[byte2] == -1) - return -1; - return (hexindex[byte1] << 4 | hexindex[byte2]); + if (hexindex[byte1] == -1 || hexindex[byte2] == -1) + return -1; + return (hexindex[byte1] << 4 | hexindex[byte2]); } /* Check if character is linear whitespace */ @@ -60,294 +59,296 @@ unqp (unsigned char byte1, unsigned char byte2) int decode_rfc2047 (char *str, char *dst, size_t dstlen) { - char *p, *q, *pp; - char *startofmime, *endofmime; - int c, quoted_printable; - int encoding_found = 0; /* did we decode anything? */ - int between_encodings = 0; /* are we between two encodings? */ - int equals_pending = 0; /* is there a '=' pending? */ - int whitespace = 0; /* how much whitespace between encodings? */ + char *p, *q, *pp; + char *startofmime, *endofmime; + int c, quoted_printable; + int encoding_found = 0; /* did we decode anything? */ + int between_encodings = 0; /* are we between two encodings? */ + int equals_pending = 0; /* is there a '=' pending? */ + int whitespace = 0; /* how much whitespace between encodings? */ #ifdef HAVE_ICONV - int use_iconv = 0; /* are we converting encoding with iconv? */ - iconv_t cd = NULL; - int fromutf8 = 0; - char *saveq, *convbuf = NULL; - size_t savedstlen; + int use_iconv = 0; /* are we converting encoding with iconv? */ + iconv_t cd = NULL; + int fromutf8 = 0; + char *saveq, *convbuf = NULL; + size_t savedstlen; #endif - if (!str) - return 0; + if (!str) + return 0; - /* - * Do a quick and dirty check for the '=' character. - * This should quickly eliminate many cases. - */ - if (!strchr (str, '=')) - return 0; + /* + * Do a quick and dirty check for the '=' character. + * This should quickly eliminate many cases. + */ + if (!strchr (str, '=')) + return 0; - for (p = str, q = dst; *p; p++) { + for (p = str, q = dst; *p; p++) { - /* reset iconv */ + /* reset iconv */ #ifdef HAVE_ICONV - if (use_iconv) { - iconv_close(cd); - use_iconv = 0; - } + if (use_iconv) { + iconv_close(cd); + use_iconv = 0; + } #endif - /* - * If we had an '=' character pending from - * last iteration, then add it first. - */ - if (equals_pending) { - ADDCHR('='); - equals_pending = 0; - between_encodings = 0; /* we have added non-whitespace text */ - } + /* + * If we had an '=' character pending from + * last iteration, then add it first. + */ + if (equals_pending) { + ADDCHR('='); + equals_pending = 0; + between_encodings = 0; /* we have added non-whitespace text */ + } - if (*p != '=') { - /* count linear whitespace while between encodings */ - if (between_encodings && is_lws(*p)) - whitespace++; - else - between_encodings = 0; /* we have added non-whitespace text */ - ADDCHR(*p); - continue; - } + if (*p != '=') { + /* count linear whitespace while between encodings */ + if (between_encodings && is_lws(*p)) + whitespace++; + else + between_encodings = 0; /* we have added non-whitespace text */ + ADDCHR(*p); + continue; + } - equals_pending = 1; /* we have a '=' pending */ + equals_pending = 1; /* we have a '=' pending */ - /* Check for initial =? */ - if (*p == '=' && p[1] && p[1] == '?' && p[2]) { - startofmime = p + 2; + /* Check for initial =? */ + if (*p == '=' && p[1] && p[1] == '?' && p[2]) { + startofmime = p + 2; - /* Scan ahead for the next '?' character */ - for (pp = startofmime; *pp && *pp != '?'; pp++) - ; + /* Scan ahead for the next '?' character */ + for (pp = startofmime; *pp && *pp != '?'; pp++) + ; - if (!*pp) - continue; + if (!*pp) + continue; - /* Check if character set can be handled natively */ - if (!check_charset(startofmime, pp - startofmime)) { + /* Check if character set can be handled natively */ + if (!check_charset(startofmime, pp - startofmime)) { #ifdef HAVE_ICONV - /* .. it can't. We'll use iconv then. */ - *pp = '\0'; - cd = iconv_open(get_charset(), startofmime); - fromutf8 = !mh_strcasecmp(startofmime, "UTF-8"); - *pp = '?'; - if (cd == (iconv_t)-1) continue; - use_iconv = 1; + /* .. it can't. We'll use iconv then. */ + *pp = '\0'; + cd = iconv_open(get_charset(), startofmime); + fromutf8 = !mh_strcasecmp(startofmime, "UTF-8"); + *pp = '?'; + if (cd == (iconv_t)-1) continue; + use_iconv = 1; #else - continue; + continue; #endif - } - - startofmime = pp + 1; - - /* Check for valid encoding type */ - if (*startofmime != 'B' && *startofmime != 'b' && - *startofmime != 'Q' && *startofmime != 'q') - continue; - - /* Is encoding quoted printable or base64? */ - quoted_printable = (*startofmime == 'Q' || *startofmime == 'q'); - startofmime++; - - /* Check for next '?' character */ - if (*startofmime != '?') - continue; - startofmime++; - - /* - * Scan ahead for the ending ?= - * - * While doing this, we will also check if encoded - * word has any embedded linear whitespace. - */ - endofmime = NULL; - for (pp = startofmime; *pp && *(pp+1); pp++) { - if (is_lws(*pp)) { - break; - } else if (*pp == '?' && pp[1] == '=') { - endofmime = pp; - break; - } - } - if (is_lws(*pp) || endofmime == NULL) - continue; - - /* - * We've found an encoded word, so we can drop - * the '=' that was pending - */ - equals_pending = 0; - - /* - * If we are between two encoded words separated only by - * linear whitespace, then we ignore the whitespace. - * We will roll back the buffer the number of whitespace - * characters we've seen since last encoded word. - */ - if (between_encodings) { - q -= whitespace; - dstlen += whitespace; - } + } + + startofmime = pp + 1; + + /* Check for valid encoding type */ + if (*startofmime != 'B' && *startofmime != 'b' && + *startofmime != 'Q' && *startofmime != 'q') + continue; + + /* Is encoding quoted printable or base64? */ + quoted_printable = (*startofmime == 'Q' || *startofmime == 'q'); + startofmime++; + + /* Check for next '?' character */ + if (*startofmime != '?') + continue; + startofmime++; + + /* + * Scan ahead for the ending ?= + * + * While doing this, we will also check if encoded + * word has any embedded linear whitespace. + */ + endofmime = NULL; + for (pp = startofmime; *pp && *(pp+1); pp++) { + if (is_lws(*pp)) { + break; + } else if (*pp == '?' && pp[1] == '=') { + endofmime = pp; + break; + } + } + if (is_lws(*pp) || endofmime == NULL) + continue; + + /* + * We've found an encoded word, so we can drop + * the '=' that was pending + */ + equals_pending = 0; + + /* + * If we are between two encoded words separated only by + * linear whitespace, then we ignore the whitespace. + * We will roll back the buffer the number of whitespace + * characters we've seen since last encoded word. + */ + if (between_encodings) { + q -= whitespace; + dstlen += whitespace; + } #ifdef HAVE_ICONV - /* - * empty encoded text. This ensures that we don't - * malloc 0 bytes but skip on to the end - */ - if (endofmime == startofmime && use_iconv) { - use_iconv = 0; - iconv_close(cd); - } - - if (use_iconv) { - saveq = q; - savedstlen = dstlen; - q = convbuf = (char *) mh_xmalloc(endofmime - startofmime); - } + /* + * empty encoded text. This ensures that we don't + * malloc 0 bytes but skip on to the end + */ + if (endofmime == startofmime && use_iconv) { + use_iconv = 0; + iconv_close(cd); + } + + if (use_iconv) { + saveq = q; + savedstlen = dstlen; + q = convbuf = (char *) mh_xmalloc(endofmime - startofmime); + } /* ADDCHR2 is for adding characters when q is or might be convbuf: * in this case on buffer-full we want to run iconv before returning. * I apologise for the dreadful name. */ -#define ADDCHR2(C) do { *q++ = (C); dstlen--; if (!dstlen) goto iconvbuffull; } while (0) +# define ADDCHR2(C) do { *q++ = (C); dstlen--; if (!dstlen) goto iconvbuffull; } while (0) #else -#define ADDCHR2(C) ADDCHR(C) +# define ADDCHR2(C) ADDCHR(C) #endif - /* Now decode the text */ - if (quoted_printable) { - for (pp = startofmime; pp < endofmime; pp++) { - if (*pp == '=') { - c = unqp (pp[1], pp[2]); - if (c == -1) - continue; - if (c != 0) - *q++ = c; - pp += 2; - } else if (*pp == '_') { - ADDCHR2(' '); - } else { - ADDCHR2(*pp); - } - } - } else { - /* base64 */ - int c1, c2, c3, c4; - c1 = c2 = c3 = c4 = -1; - - pp = startofmime; - while (pp < endofmime) { - /* 6 + 2 bits */ - while ((pp < endofmime) && - ((c1 = char64(*pp)) == -1)) { - pp++; - } - if (pp < endofmime) { - pp++; - } - while ((pp < endofmime) && - ((c2 = char64(*pp)) == -1)) { - pp++; - } - if (pp < endofmime && c1 != -1 && c2 != -1) { - ADDCHR2((c1 << 2) | (c2 >> 4)); - pp++; - } - /* 4 + 4 bits */ - while ((pp < endofmime) && - ((c3 = char64(*pp)) == -1)) { - pp++; - } - if (pp < endofmime && c2 != -1 && c3 != -1) { - ADDCHR2(((c2 & 0xF) << 4) | (c3 >> 2)); - pp++; - } - /* 2 + 6 bits */ - while ((pp < endofmime) && - ((c4 = char64(*pp)) == -1)) { - pp++; - } - if (pp < endofmime && c3 != -1 && c4 != -1) { - ADDCHR2(((c3 & 0x3) << 6) | (c4)); - pp++; - } - } - } + /* Now decode the text */ + if (quoted_printable) { + for (pp = startofmime; pp < endofmime; pp++) { + if (*pp == '=') { + c = unqp (pp[1], pp[2]); + if (c == -1) + continue; + if (c != 0) + *q++ = c; + pp += 2; + } else if (*pp == '_') { + ADDCHR2(' '); + } else { + ADDCHR2(*pp); + } + } + } else { + /* base64 */ + int c1, c2, c3, c4; + c1 = c2 = c3 = c4 = -1; + + pp = startofmime; + while (pp < endofmime) { + /* 6 + 2 bits */ + while ((pp < endofmime) && + ((c1 = char64(*pp)) == -1)) { + pp++; + } + if (pp < endofmime) { + pp++; + } + while ((pp < endofmime) && + ((c2 = char64(*pp)) == -1)) { + pp++; + } + if (pp < endofmime && c1 != -1 && c2 != -1) { + ADDCHR2((c1 << 2) | (c2 >> 4)); + pp++; + } + /* 4 + 4 bits */ + while ((pp < endofmime) && + ((c3 = char64(*pp)) == -1)) { + pp++; + } + if (pp < endofmime && c2 != -1 && c3 != -1) { + ADDCHR2(((c2 & 0xF) << 4) | (c3 >> 2)); + pp++; + } + /* 2 + 6 bits */ + while ((pp < endofmime) && + ((c4 = char64(*pp)) == -1)) { + pp++; + } + if (pp < endofmime && c3 != -1 && c4 != -1) { + ADDCHR2(((c3 & 0x3) << 6) | (c4)); + pp++; + } + } + } #ifdef HAVE_ICONV - iconvbuffull: - /* NB that the string at convbuf is not necessarily NUL terminated here: - * q points to the first byte after the valid part. - */ - /* Convert to native character set */ - if (use_iconv) { - size_t inbytes = q - convbuf; - ICONV_CONST char *start = convbuf; - - while (inbytes) { - if (iconv(cd, &start, &inbytes, &saveq, &savedstlen) == - (size_t)-1) { - if (errno != EILSEQ) break; - /* character couldn't be converted. we output a `?' - * and try to carry on which won't work if - * either encoding was stateful */ - iconv (cd, 0, 0, &saveq, &savedstlen); - if (!savedstlen) - break; - *saveq++ = '?'; - savedstlen--; - if (!savedstlen) - break; - /* skip to next input character */ - if (fromutf8) { - for (start++;(start < q) && ((*start & 192) == 128);start++) - inbytes--; - } else - start++, inbytes--; - if (start >= q) - break; - } - } - q = saveq; - /* Stop now if (1) we hit the end of the buffer trying to do - * MIME decoding and have just iconv-converted a partial string - * or (2) our iconv-conversion hit the end of the buffer. - */ - if (!dstlen || !savedstlen) - goto buffull; - dstlen = savedstlen; - free(convbuf); - } + iconvbuffull: + /* NB that the string at convbuf is not necessarily + * NUL terminated here: + * q points to the first byte after the valid part. + */ + /* Convert to native character set */ + if (use_iconv) { + size_t inbytes = q - convbuf; + ICONV_CONST char *start = convbuf; + + while (inbytes) { + if (iconv(cd, &start, &inbytes, &saveq, &savedstlen) == + (size_t)-1) { + if (errno != EILSEQ) + break; + /* character couldn't be converted. we output a `?' + * and try to carry on which won't work if + * either encoding was stateful */ + iconv (cd, 0, 0, &saveq, &savedstlen); + if (!savedstlen) + break; + *saveq++ = '?'; + savedstlen--; + if (!savedstlen) + break; + /* skip to next input character */ + if (fromutf8) { + for (start++;(start < q) && ((*start & 192) == 128);start++) + inbytes--; + } else + start++, inbytes--; + if (start >= q) + break; + } + } + q = saveq; + /* Stop now if (1) we hit the end of the buffer trying to do + * MIME decoding and have just iconv-converted a partial string + * or (2) our iconv-conversion hit the end of the buffer. + */ + if (!dstlen || !savedstlen) + goto buffull; + dstlen = savedstlen; + free(convbuf); + } #endif - - /* - * Now that we are done decoding this particular - * encoded word, advance string to trailing '='. - */ - p = endofmime + 1; - - encoding_found = 1; /* we found (at least 1) encoded word */ - between_encodings = 1; /* we have just decoded something */ - whitespace = 0; /* re-initialize amount of whitespace */ + + /* + * Now that we are done decoding this particular + * encoded word, advance string to trailing '='. + */ + p = endofmime + 1; + + encoding_found = 1; /* we found (at least 1) encoded word */ + between_encodings = 1; /* we have just decoded something */ + whitespace = 0; /* re-initialize amount of whitespace */ + } } - } #ifdef HAVE_ICONV - if (use_iconv) iconv_close(cd); + if (use_iconv) iconv_close(cd); #endif - /* If an equals was pending at end of string, add it now. */ - if (equals_pending) - ADDCHR('='); - *q = '\0'; + /* If an equals was pending at end of string, add it now. */ + if (equals_pending) + ADDCHR('='); + *q = '\0'; - return encoding_found; + return encoding_found; buffull: - /* q is currently just off the end of the buffer, so rewind to NUL terminate */ - q--; - *q = '\0'; - return encoding_found; + /* q is currently just off the end of the buffer, so rewind to NUL terminate */ + q--; + *q = '\0'; + return encoding_found; } diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 97a0b4a..14ec48b 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -1,4 +1,3 @@ - /* * fmt_scan.c -- format string interpretation * @@ -28,15 +27,15 @@ # include #endif -#define NFMTS MAXARGS +#define NFMTS MAXARGS -extern char *formataddr (); /* hook for custom address formatting */ +extern char *formataddr (); /* hook for custom address formatting */ #ifdef LBL struct msgs *fmt_current_folder; /* current folder (set by main program) */ #endif -extern int fmt_norm; /* defined in sbr/fmt_def.c = AD_NAME */ +extern int fmt_norm; /* defined in sbr/fmt_def.c = AD_NAME */ struct mailname fmt_mnull; /* @@ -55,36 +54,36 @@ static int get_x400_comp (char *, char *, char *, int); static int match (char *str, char *sub) { - int c1, c2; - char *s1, *s2; + int c1, c2; + char *s1, *s2; #ifdef LOCALE - while ((c1 = *sub)) { - c1 = (isalpha(c1) && isupper(c1)) ? tolower(c1) : c1; - while ((c2 = *str++) && c1 != ((isalpha(c2) && isupper(c2)) ? tolower(c2) : c2)) - ; - if (! c2) - return 0; - s1 = sub + 1; s2 = str; - while ((c1 = *s1++) && ((isalpha(c1) && isupper(c1)) ? tolower(c1) : c1) == ((isalpha(c2 =*s2++) && isupper(c2)) ? tolower(c2) : c2)) - ; - if (! c1) - return 1; - } + while ((c1 = *sub)) { + c1 = (isalpha(c1) && isupper(c1)) ? tolower(c1) : c1; + while ((c2 = *str++) && c1 != ((isalpha(c2) && isupper(c2)) ? tolower(c2) : c2)) + ; + if (! c2) + return 0; + s1 = sub + 1; s2 = str; + while ((c1 = *s1++) && ((isalpha(c1) && isupper(c1)) ? tolower(c1) : c1) == ((isalpha(c2 =*s2++) && isupper(c2)) ? tolower(c2) : c2)) + ; + if (! c1) + return 1; + } #else - while ((c1 = *sub)) { - while ((c2 = *str++) && (c1 | 040) != (c2 | 040)) - ; - if (! c2) - return 0; - s1 = sub + 1; s2 = str; - while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040)) - ; - if (! c1) - return 1; - } + while ((c1 = *sub)) { + while ((c2 = *str++) && (c1 | 040) != (c2 | 040)) + ; + if (! c2) + return 0; + s1 = sub + 1; s2 = str; + while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040)) + ; + if (! c1) + return 1; + } #endif - return 1; + return 1; } /* @@ -92,30 +91,30 @@ match (char *str, char *sub) */ static void cpnumber(char **dest, int num, unsigned int wid, char fill, size_t n) { - int i, c; - char *sp; - char *cp = *dest; - char *ep = cp + n; - - if (cp + wid < ep) { - if ((i = (num)) < 0) - i = -(num); - if ((c = (wid)) < 0) - c = -c; - sp = cp + c; - do { - *--sp = (i % 10) + '0'; - i /= 10; - } while (i > 0 && sp > cp); - if (i > 0) - *sp = '?'; - else if ((num) < 0 && sp > cp) - *--sp = '-'; - while (sp > cp) - *--sp = fill; - cp += c; - } - *dest = cp; + int i, c; + char *sp; + char *cp = *dest; + char *ep = cp + n; + + if (cp + wid < ep) { + if ((i = (num)) < 0) + i = -(num); + if ((c = (wid)) < 0) + c = -c; + sp = cp + c; + do { + *--sp = (i % 10) + '0'; + i /= 10; + } while (i > 0 && sp > cp); + if (i > 0) + *sp = '?'; + else if ((num) < 0 && sp > cp) + *--sp = '-'; + while (sp > cp) + *--sp = fill; + cp += c; + } + *dest = cp; } /* @@ -125,807 +124,808 @@ cpnumber(char **dest, int num, unsigned int wid, char fill, size_t n) { */ static void cptrimmed(char **dest, char *str, unsigned int wid, char fill, size_t n) { - int remaining; /* remaining output width available */ - int c, ljust, w; - int end; /* number of input bytes remaining in str */ + int remaining; /* remaining output width available */ + int c, ljust, w; + int end; /* number of input bytes remaining in str */ #ifdef MULTIBYTE_SUPPORT - int char_len; /* bytes in current character */ - wchar_t wide_char; + int char_len; /* bytes in current character */ + wchar_t wide_char; #endif - char *sp; /* current position in source string */ - char *cp = *dest; /* current position in destination string */ - char *ep = cp + n; /* end of destination buffer */ - int prevCtrl = 1; - - /* get alignment */ - ljust = 0; - if ((remaining = (wid)) < 0) { - remaining = -remaining; - ljust++; - } - if ((sp = (str))) { - mbtowc(NULL, NULL, 0); /* reset shift state */ - end = strlen(str); - while (*sp && remaining > 0 && end > 0) { + char *sp; /* current position in source string */ + char *cp = *dest; /* current position in destination string */ + char *ep = cp + n; /* end of destination buffer */ + int prevCtrl = 1; + + /* get alignment */ + ljust = 0; + if ((remaining = (wid)) < 0) { + remaining = -remaining; + ljust++; + } + if ((sp = (str))) { + mbtowc(NULL, NULL, 0); /* reset shift state */ + end = strlen(str); + while (*sp && remaining > 0 && end > 0) { #ifdef MULTIBYTE_SUPPORT - char_len = mbtowc(&wide_char, sp, end); - if (char_len <= 0 || (cp + char_len > ep)) - break; + char_len = mbtowc(&wide_char, sp, end); + if (char_len <= 0 || (cp + char_len > ep)) + break; - end -= char_len; + end -= char_len; - if (iswcntrl(wide_char) || iswspace(wide_char)) { - sp += char_len; + if (iswcntrl(wide_char) || iswspace(wide_char)) { + sp += char_len; #else - end--; - if (iscntrl(*sp) || isspace(*sp)) { - sp++; + end--; + if (iscntrl(*sp) || isspace(*sp)) { + sp++; #endif - if (!prevCtrl) { - *cp++ = ' '; - remaining--; - } + if (!prevCtrl) { + *cp++ = ' '; + remaining--; + } - prevCtrl = 1; - continue; - } - prevCtrl = 0; + prevCtrl = 1; + continue; + } + prevCtrl = 0; #ifdef MULTIBYTE_SUPPORT - w = wcwidth(wide_char); - if (w >= 0 && remaining >= w) { - strncpy(cp, sp, char_len); - cp += char_len; - remaining -= w; - } - sp += char_len; + w = wcwidth(wide_char); + if (w >= 0 && remaining >= w) { + strncpy(cp, sp, char_len); + cp += char_len; + remaining -= w; + } + sp += char_len; #else - *cp++ = *sp++; - remaining--; + *cp++ = *sp++; + remaining--; #endif + } } - } - - if (ljust) { - if (cp + remaining > ep) - remaining = ep - cp; - ep = cp + remaining; - if (remaining > 0) { - /* copy string to the right */ - while (--cp >= *dest) - *(cp + remaining) = *cp; - /* add padding at the beginning */ - cp += remaining; - for (c=remaining; c>0; c--) - *cp-- = fill; + + if (ljust) { + if (cp + remaining > ep) + remaining = ep - cp; + ep = cp + remaining; + if (remaining > 0) { + /* copy string to the right */ + while (--cp >= *dest) + *(cp + remaining) = *cp; + /* add padding at the beginning */ + cp += remaining; + for (c=remaining; c>0; c--) + *cp-- = fill; + } + *dest = ep; + } else { + /* pad remaining space */ + while (remaining-- > 0 && cp < ep) + *cp++ = fill; + *dest = cp; } - *dest = ep; - } else { - /* pad remaining space */ - while (remaining-- > 0 && cp < ep) - *cp++ = fill; - *dest = cp; - } } static void cpstripped (char **start, char *end, char *str) { - int c; - char *s = str; + int c; + char *s = str; - if (!s) - return; + if (!s) + return; - /* skip any initial control characters or spaces */ - while ((c = (unsigned char) *s) && + /* skip any initial control characters or spaces */ + while ((c = (unsigned char) *s) && #ifdef LOCALE - (iscntrl(c) || isspace(c))) + (iscntrl(c) || isspace(c))) #else - (c <= 32)) + (c <= 32)) #endif - s++; - - /* compact repeated control characters and spaces into a single space */ - while((c = (unsigned char) *s++) && *start < end) - if (!iscntrl(c) && !isspace(c)) - *(*start)++ = c; - else { - while ((c = (unsigned char) *s) && + s++; + + /* compact repeated control characters and spaces into a single space */ + while((c = (unsigned char) *s++) && *start < end) + if (!iscntrl(c) && !isspace(c)) + *(*start)++ = c; + else { + while ((c = (unsigned char) *s) && #ifdef LOCALE - (iscntrl(c) || isspace(c))) + (iscntrl(c) || isspace(c))) #else - (c <= 32)) + (c <= 32)) #endif - s++; - *(*start)++ = ' '; - } + s++; + *(*start)++ = ' '; + } } -static char *lmonth[] = { "January", "February","March", "April", - "May", "June", "July", "August", - "September","October", "November","December" }; +static char *lmonth[] = { + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" +}; static char * get_x400_friendly (char *mbox, char *buffer, int buffer_len) { - char given[BUFSIZ], surname[BUFSIZ]; + char given[BUFSIZ], surname[BUFSIZ]; - if (mbox == NULL) - return NULL; - if (*mbox == '"') - mbox++; - if (*mbox != '/') - return NULL; + if (mbox == NULL) + return NULL; + if (*mbox == '"') + mbox++; + if (*mbox != '/') + return NULL; - if (get_x400_comp (mbox, "/PN=", buffer, buffer_len)) { - for (mbox = buffer; (mbox = strchr(mbox, '.')); ) - *mbox++ = ' '; + if (get_x400_comp (mbox, "/PN=", buffer, buffer_len)) { + for (mbox = buffer; (mbox = strchr(mbox, '.')); ) + *mbox++ = ' '; - return buffer; - } + return buffer; + } - if (!get_x400_comp (mbox, "/S=", surname, sizeof(surname))) - return NULL; + if (!get_x400_comp (mbox, "/S=", surname, sizeof(surname))) + return NULL; - if (get_x400_comp (mbox, "/G=", given, sizeof(given))) - snprintf (buffer, buffer_len, "%s %s", given, surname); - else - snprintf (buffer, buffer_len, "%s", surname); + if (get_x400_comp (mbox, "/G=", given, sizeof(given))) + snprintf (buffer, buffer_len, "%s %s", given, surname); + else + snprintf (buffer, buffer_len, "%s", surname); - return buffer; + return buffer; } static int get_x400_comp (char *mbox, char *key, char *buffer, int buffer_len) { - int idx; - char *cp; + int idx; + char *cp; - if ((idx = stringdex (key, mbox)) < 0 - || !(cp = strchr(mbox += idx + strlen (key), '/'))) - return 0; + if ((idx = stringdex (key, mbox)) < 0 + || !(cp = strchr(mbox += idx + strlen (key), '/'))) + return 0; - snprintf (buffer, buffer_len, "%*.*s", (int)(cp - mbox), (int)(cp - mbox), mbox); - return 1; + snprintf (buffer, buffer_len, "%*.*s", (int)(cp - mbox), (int)(cp - mbox), mbox); + return 1; } struct format * fmt_scan (struct format *format, char *scanl, int width, int *dat) { - char *cp, *ep; - unsigned char *sp; - char *savestr = NULL; - unsigned char *str = NULL; - char buffer[BUFSIZ], buffer2[BUFSIZ]; - int i, c, ljust, n; - int value = 0; - time_t t; - struct format *fmt; - struct comp *comp; - struct tws *tws; - struct mailname *mn; - - cp = scanl; - ep = scanl + width - 1; - - for (fmt = format; fmt->f_type != FT_DONE; fmt++) - switch (fmt->f_type) { - case FT_PARSEADDR: - case FT_PARSEDATE: - fmt->f_comp->c_flags &= ~CF_PARSED; - break; - } + char *cp, *ep; + unsigned char *sp; + char *savestr = NULL; + unsigned char *str = NULL; + char buffer[BUFSIZ], buffer2[BUFSIZ]; + int i, c, ljust, n; + int value = 0; + time_t t; + struct format *fmt; + struct comp *comp; + struct tws *tws; + struct mailname *mn; + + cp = scanl; + ep = scanl + width - 1; + + for (fmt = format; fmt->f_type != FT_DONE; fmt++) + switch (fmt->f_type) { + case FT_PARSEADDR: + case FT_PARSEDATE: + fmt->f_comp->c_flags &= ~CF_PARSED; + break; + } + + fmt = format; - fmt = format; - - while (cp < ep) { - switch (fmt->f_type) { - - case FT_COMP: - cpstripped (&cp, ep, fmt->f_comp->c_text); - break; - case FT_COMPF: - cptrimmed (&cp, fmt->f_comp->c_text, fmt->f_width, fmt->f_fill, ep - cp); - break; - - case FT_LIT: - sp = fmt->f_text; - while( (c = *sp++) && cp < ep) - *cp++ = c; - break; - case FT_LITF: - sp = fmt->f_text; - ljust = 0; - i = fmt->f_width; - if (i < 0) { - i = -i; - ljust++; /* XXX should do something with this */ - } - while( (c = *sp++) && --i >= 0 && cp < ep) - *cp++ = c; - while( --i >= 0 && cp < ep) - *cp++ = fmt->f_fill; - break; - - case FT_STR: - cpstripped (&cp, ep, str); - break; - case FT_STRF: - cptrimmed (&cp, str, fmt->f_width, fmt->f_fill, ep - cp); - break; - case FT_STRFW: - adios (NULL, "internal error (FT_STRFW)"); - - case FT_NUM: - n = snprintf(cp, ep - cp + 1, "%d", value); - if (n >= 0) { - if (n >= ep - cp) { - cp = ep; - } else - cp += n; - } - break; - case FT_NUMF: - cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp); - break; - - case FT_CHAR: - *cp++ = fmt->f_char; - break; - - case FT_DONE: - goto finished; - - case FT_IF_S: - if (!(value = (str && *str))) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_IF_S_NULL: - if (!(value = (str == NULL || *str == 0))) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_IF_V_EQ: - if (value != fmt->f_value) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_IF_V_NE: - if (value == fmt->f_value) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_IF_V_GT: - if (value <= fmt->f_value) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_IF_MATCH: - if (!(value = (str && match (str, fmt->f_text)))) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_V_MATCH: - if (str) - value = match (str, fmt->f_text); - else - value = 0; - break; - - case FT_IF_AMATCH: - if (!(value = (str && uprf (str, fmt->f_text)))) { - fmt += fmt->f_skip; - continue; - } - break; - - case FT_V_AMATCH: - value = uprf (str, fmt->f_text); - break; - - case FT_S_NONNULL: - value = (str != NULL && *str != 0); - break; - - case FT_S_NULL: - value = (str == NULL || *str == 0); - break; - - case FT_V_EQ: - value = (fmt->f_value == value); - break; - - case FT_V_NE: - value = (fmt->f_value != value); - break; - - case FT_V_GT: - value = (fmt->f_value > value); - break; - - case FT_GOTO: - fmt += fmt->f_skip; - continue; - - case FT_NOP: - break; - - case FT_LS_COMP: - str = fmt->f_comp->c_text; - break; - case FT_LS_LIT: - str = fmt->f_text; - break; - case FT_LS_GETENV: - if (!(str = getenv (fmt->f_text))) - str = ""; - break; - case FT_LS_CFIND: - if (!(str = context_find (fmt->f_text))) - str = ""; - break; - - case FT_LS_DECODECOMP: - if (decode_rfc2047(fmt->f_comp->c_text, buffer2, sizeof(buffer2))) - str = buffer2; - else - str = fmt->f_comp->c_text; - break; - - case FT_LS_DECODE: - if (str && decode_rfc2047(str, buffer2, sizeof(buffer2))) - str = buffer2; - break; - - case FT_LS_TRIM: - if (str) { - unsigned char *xp; - - strncpy(buffer, str, sizeof(buffer)); - buffer[sizeof(buffer)-1] = '\0'; - str = buffer; - while (isspace(*str)) - str++; - ljust = 0; - if ((i = fmt->f_width) < 0) { - i = -i; - ljust++; - } - - if (!ljust && i > 0 && strlen(str) > i) - str[i] = '\0'; - xp = str; - xp += strlen(str) - 1; - while (xp > str && isspace(*xp)) - *xp-- = '\0'; - if (ljust && i > 0 && strlen(str) > i) - str += strlen(str) - i; - } - break; - - case FT_LV_COMPFLAG: - value = (fmt->f_comp->c_flags & CF_TRUE) != 0; - break; - case FT_LV_COMP: - value = (comp = fmt->f_comp)->c_text ? atoi(comp->c_text) : 0; - break; - case FT_LV_LIT: - value = fmt->f_value; - break; - case FT_LV_DAT: - value = dat[fmt->f_value]; - break; - case FT_LV_STRLEN: - if (str != NULL) - value = strlen(str); - else - value = 0; - break; - case FT_LV_CHAR_LEFT: - value = width - (cp - scanl); - break; - case FT_LV_PLUS_L: - value += fmt->f_value; - break; - case FT_LV_MINUS_L: - value = fmt->f_value - value; - break; - case FT_LV_DIVIDE_L: - if (fmt->f_value) - value = value / fmt->f_value; - else - value = 0; - break; - case FT_LV_MODULO_L: - if (fmt->f_value) - value = value % fmt->f_value; - else - value = 0; - break; - case FT_SAVESTR: - savestr = str; - break; - - case FT_LV_SEC: - value = fmt->f_comp->c_tws->tw_sec; - break; - case FT_LV_MIN: - value = fmt->f_comp->c_tws->tw_min; - break; - case FT_LV_HOUR: - value = fmt->f_comp->c_tws->tw_hour; - break; - case FT_LV_MDAY: - value = fmt->f_comp->c_tws->tw_mday; - break; - case FT_LV_MON: - value = fmt->f_comp->c_tws->tw_mon + 1; - break; - case FT_LS_MONTH: - str = tw_moty[fmt->f_comp->c_tws->tw_mon]; - break; - case FT_LS_LMONTH: - str = lmonth[fmt->f_comp->c_tws->tw_mon]; - break; - case FT_LS_ZONE: - str = dtwszone (fmt->f_comp->c_tws); - break; - case FT_LV_YEAR: - value = fmt->f_comp->c_tws->tw_year; - break; - case FT_LV_WDAY: - if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) - set_dotw (tws); - value = tws->tw_wday; - break; - case FT_LS_DAY: - if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) - set_dotw (tws); - str = tw_dotw[tws->tw_wday]; - break; - case FT_LS_WEEKDAY: - if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) - set_dotw (tws); - str = tw_ldotw[tws->tw_wday]; - break; - case FT_LV_YDAY: - value = fmt->f_comp->c_tws->tw_yday; - break; - case FT_LV_ZONE: - value = fmt->f_comp->c_tws->tw_zone; - break; - case FT_LV_CLOCK: - if ((value = fmt->f_comp->c_tws->tw_clock) == 0) - value = dmktime(fmt->f_comp->c_tws); - break; - case FT_LV_RCLOCK: - if ((value = fmt->f_comp->c_tws->tw_clock) == 0) - value = dmktime(fmt->f_comp->c_tws); - value = time((time_t *) 0) - value; - break; - case FT_LV_DAYF: - if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) - set_dotw (tws); - switch (fmt->f_comp->c_tws->tw_flags & TW_SDAY) { - case TW_SEXP: - value = 1; break; - case TW_SIMP: - value = 0; break; - default: - value = -1; break; - } - case FT_LV_ZONEF: - if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP) - value = 1; - else - value = -1; - break; - case FT_LV_DST: - value = fmt->f_comp->c_tws->tw_flags & TW_DST; - break; - case FT_LS_822DATE: - str = dasctime (fmt->f_comp->c_tws , TW_ZONE); - break; - case FT_LS_PRETTY: - str = dasctime (fmt->f_comp->c_tws, TW_NULL); - break; - - case FT_LS_PERS: - str = fmt->f_comp->c_mn->m_pers; - break; - case FT_LS_MBOX: - str = fmt->f_comp->c_mn->m_mbox; - break; - case FT_LS_HOST: - str = fmt->f_comp->c_mn->m_host; - break; - case FT_LS_PATH: - str = fmt->f_comp->c_mn->m_path; - break; - case FT_LS_GNAME: - str = fmt->f_comp->c_mn->m_gname; - break; - case FT_LS_NOTE: - str = fmt->f_comp->c_mn->m_note; - break; - case FT_LS_822ADDR: - str = adrformat( fmt->f_comp->c_mn ); - break; - case FT_LV_HOSTTYPE: - value = fmt->f_comp->c_mn->m_type; - break; - case FT_LV_INGRPF: - value = fmt->f_comp->c_mn->m_ingrp; - break; - case FT_LV_NOHOSTF: - value = fmt->f_comp->c_mn->m_nohost; - break; - case FT_LS_ADDR: - case FT_LS_FRIENDLY: - if ((mn = fmt->f_comp->c_mn) == &fmt_mnull) { - str = fmt->f_comp->c_text; - break; - } - if (fmt->f_type == FT_LS_ADDR) - goto unfriendly; - if ((str = mn->m_pers) == NULL) { - if ((str = mn->m_note)) { - strncpy (buffer, str, sizeof(buffer)); - buffer[sizeof(buffer)-1] = '\0'; - str = buffer; - if (*str == '(') - str++; - sp = str + strlen(str) - 1; - if (*sp == ')') { - *sp-- = '\0'; - while (sp >= str) - if (*sp == ' ') - *sp-- = '\0'; - else - break; - } - } else if (!(str = get_x400_friendly (mn->m_mbox, - buffer, sizeof(buffer)))) { - unfriendly: ; - switch (mn->m_type) { - case LOCALHOST: - str = mn->m_mbox; - break; - case UUCPHOST: - snprintf (buffer, sizeof(buffer), "%s!%s", - mn->m_host, mn->m_mbox); - str = buffer; - break; - default: - if (mn->m_mbox) { - snprintf (buffer, sizeof(buffer), "%s@%s", - mn->m_mbox, mn->m_host); - str= buffer; + while (cp < ep) { + switch (fmt->f_type) { + + case FT_COMP: + cpstripped (&cp, ep, fmt->f_comp->c_text); + break; + case FT_COMPF: + cptrimmed (&cp, fmt->f_comp->c_text, fmt->f_width, fmt->f_fill, ep - cp); + break; + + case FT_LIT: + sp = fmt->f_text; + while( (c = *sp++) && cp < ep) + *cp++ = c; + break; + case FT_LITF: + sp = fmt->f_text; + ljust = 0; + i = fmt->f_width; + if (i < 0) { + i = -i; + ljust++; /* XXX should do something with this */ } + while( (c = *sp++) && --i >= 0 && cp < ep) + *cp++ = c; + while( --i >= 0 && cp < ep) + *cp++ = fmt->f_fill; + break; + + case FT_STR: + cpstripped (&cp, ep, str); + break; + case FT_STRF: + cptrimmed (&cp, str, fmt->f_width, fmt->f_fill, ep - cp); + break; + case FT_STRFW: + adios (NULL, "internal error (FT_STRFW)"); + + case FT_NUM: + n = snprintf(cp, ep - cp + 1, "%d", value); + if (n >= 0) { + if (n >= ep - cp) { + cp = ep; + } else + cp += n; + } + break; + case FT_NUMF: + cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp); + break; + + case FT_CHAR: + *cp++ = fmt->f_char; + break; + + case FT_DONE: + goto finished; + + case FT_IF_S: + if (!(value = (str && *str))) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_IF_S_NULL: + if (!(value = (str == NULL || *str == 0))) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_IF_V_EQ: + if (value != fmt->f_value) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_IF_V_NE: + if (value == fmt->f_value) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_IF_V_GT: + if (value <= fmt->f_value) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_IF_MATCH: + if (!(value = (str && match (str, fmt->f_text)))) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_V_MATCH: + if (str) + value = match (str, fmt->f_text); else - str = mn->m_text; + value = 0; + break; + + case FT_IF_AMATCH: + if (!(value = (str && uprf (str, fmt->f_text)))) { + fmt += fmt->f_skip; + continue; + } + break; + + case FT_V_AMATCH: + value = uprf (str, fmt->f_text); + break; + + case FT_S_NONNULL: + value = (str != NULL && *str != 0); + break; + + case FT_S_NULL: + value = (str == NULL || *str == 0); + break; + + case FT_V_EQ: + value = (fmt->f_value == value); + break; + + case FT_V_NE: + value = (fmt->f_value != value); + break; + + case FT_V_GT: + value = (fmt->f_value > value); + break; + + case FT_GOTO: + fmt += fmt->f_skip; + continue; + + case FT_NOP: + break; + + case FT_LS_COMP: + str = fmt->f_comp->c_text; + break; + case FT_LS_LIT: + str = fmt->f_text; + break; + case FT_LS_GETENV: + if (!(str = getenv (fmt->f_text))) + str = ""; + break; + case FT_LS_CFIND: + if (!(str = context_find (fmt->f_text))) + str = ""; + break; + + case FT_LS_DECODECOMP: + if (decode_rfc2047(fmt->f_comp->c_text, buffer2, sizeof(buffer2))) + str = buffer2; + else + str = fmt->f_comp->c_text; + break; + + case FT_LS_DECODE: + if (str && decode_rfc2047(str, buffer2, sizeof(buffer2))) + str = buffer2; + break; + + case FT_LS_TRIM: + if (str) { + unsigned char *xp; + + strncpy(buffer, str, sizeof(buffer)); + buffer[sizeof(buffer)-1] = '\0'; + str = buffer; + while (isspace(*str)) + str++; + ljust = 0; + if ((i = fmt->f_width) < 0) { + i = -i; + ljust++; + } + + if (!ljust && i > 0 && strlen(str) > i) + str[i] = '\0'; + xp = str; + xp += strlen(str) - 1; + while (xp > str && isspace(*xp)) + *xp-- = '\0'; + if (ljust && i > 0 && strlen(str) > i) + str += strlen(str) - i; + } + break; + + case FT_LV_COMPFLAG: + value = (fmt->f_comp->c_flags & CF_TRUE) != 0; + break; + case FT_LV_COMP: + value = (comp = fmt->f_comp)->c_text ? atoi(comp->c_text) : 0; + break; + case FT_LV_LIT: + value = fmt->f_value; + break; + case FT_LV_DAT: + value = dat[fmt->f_value]; + break; + case FT_LV_STRLEN: + if (str != NULL) + value = strlen(str); + else + value = 0; + break; + case FT_LV_CHAR_LEFT: + value = width - (cp - scanl); + break; + case FT_LV_PLUS_L: + value += fmt->f_value; + break; + case FT_LV_MINUS_L: + value = fmt->f_value - value; + break; + case FT_LV_DIVIDE_L: + if (fmt->f_value) + value = value / fmt->f_value; + else + value = 0; + break; + case FT_LV_MODULO_L: + if (fmt->f_value) + value = value % fmt->f_value; + else + value = 0; + break; + case FT_SAVESTR: + savestr = str; + break; + + case FT_LV_SEC: + value = fmt->f_comp->c_tws->tw_sec; + break; + case FT_LV_MIN: + value = fmt->f_comp->c_tws->tw_min; + break; + case FT_LV_HOUR: + value = fmt->f_comp->c_tws->tw_hour; + break; + case FT_LV_MDAY: + value = fmt->f_comp->c_tws->tw_mday; + break; + case FT_LV_MON: + value = fmt->f_comp->c_tws->tw_mon + 1; + break; + case FT_LS_MONTH: + str = tw_moty[fmt->f_comp->c_tws->tw_mon]; + break; + case FT_LS_LMONTH: + str = lmonth[fmt->f_comp->c_tws->tw_mon]; + break; + case FT_LS_ZONE: + str = dtwszone (fmt->f_comp->c_tws); + break; + case FT_LV_YEAR: + value = fmt->f_comp->c_tws->tw_year; + break; + case FT_LV_WDAY: + if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) + set_dotw (tws); + value = tws->tw_wday; + break; + case FT_LS_DAY: + if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) + set_dotw (tws); + str = tw_dotw[tws->tw_wday]; + break; + case FT_LS_WEEKDAY: + if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) + set_dotw (tws); + str = tw_ldotw[tws->tw_wday]; + break; + case FT_LV_YDAY: + value = fmt->f_comp->c_tws->tw_yday; + break; + case FT_LV_ZONE: + value = fmt->f_comp->c_tws->tw_zone; + break; + case FT_LV_CLOCK: + if ((value = fmt->f_comp->c_tws->tw_clock) == 0) + value = dmktime(fmt->f_comp->c_tws); + break; + case FT_LV_RCLOCK: + if ((value = fmt->f_comp->c_tws->tw_clock) == 0) + value = dmktime(fmt->f_comp->c_tws); + value = time((time_t *) 0) - value; + break; + case FT_LV_DAYF: + if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP))) + set_dotw (tws); + switch (fmt->f_comp->c_tws->tw_flags & TW_SDAY) { + case TW_SEXP: + value = 1; break; + case TW_SIMP: + value = 0; break; + default: + value = -1; break; + } + case FT_LV_ZONEF: + if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP) + value = 1; + else + value = -1; + break; + case FT_LV_DST: + value = fmt->f_comp->c_tws->tw_flags & TW_DST; + break; + case FT_LS_822DATE: + str = dasctime (fmt->f_comp->c_tws , TW_ZONE); + break; + case FT_LS_PRETTY: + str = dasctime (fmt->f_comp->c_tws, TW_NULL); + break; + + case FT_LS_PERS: + str = fmt->f_comp->c_mn->m_pers; + break; + case FT_LS_MBOX: + str = fmt->f_comp->c_mn->m_mbox; + break; + case FT_LS_HOST: + str = fmt->f_comp->c_mn->m_host; + break; + case FT_LS_PATH: + str = fmt->f_comp->c_mn->m_path; + break; + case FT_LS_GNAME: + str = fmt->f_comp->c_mn->m_gname; + break; + case FT_LS_NOTE: + str = fmt->f_comp->c_mn->m_note; + break; + case FT_LS_822ADDR: + str = adrformat( fmt->f_comp->c_mn ); + break; + case FT_LV_HOSTTYPE: + value = fmt->f_comp->c_mn->m_type; + break; + case FT_LV_INGRPF: + value = fmt->f_comp->c_mn->m_ingrp; + break; + case FT_LV_NOHOSTF: + value = fmt->f_comp->c_mn->m_nohost; + break; + case FT_LS_ADDR: + case FT_LS_FRIENDLY: + if ((mn = fmt->f_comp->c_mn) == &fmt_mnull) { + str = fmt->f_comp->c_text; + break; + } + if (fmt->f_type == FT_LS_ADDR) + goto unfriendly; + if ((str = mn->m_pers) == NULL) { + if ((str = mn->m_note)) { + strncpy (buffer, str, sizeof(buffer)); + buffer[sizeof(buffer)-1] = '\0'; + str = buffer; + if (*str == '(') + str++; + sp = str + strlen(str) - 1; + if (*sp == ')') { + *sp-- = '\0'; + while (sp >= str) + if (*sp == ' ') + *sp-- = '\0'; + else + break; + } + } else if (!(str = get_x400_friendly (mn->m_mbox, + buffer, sizeof(buffer)))) { + unfriendly: ; + switch (mn->m_type) { + case LOCALHOST: + str = mn->m_mbox; + break; + case UUCPHOST: + snprintf (buffer, sizeof(buffer), "%s!%s", + mn->m_host, mn->m_mbox); + str = buffer; + break; + default: + if (mn->m_mbox) { + snprintf (buffer, sizeof(buffer), "%s@%s", + mn->m_mbox, mn->m_host); + str= buffer; + } else + str = mn->m_text; + break; + } + } + } break; - } - } - } - break; /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */ - case FT_LS_UNQUOTE: - if (str) { - int m; - strncpy(buffer, str, sizeof(buffer)); - /* strncpy doesn't NUL-terminate if it fills the buffer */ - buffer[sizeof(buffer)-1] = '\0'; - str = buffer; - - /* we will parse from buffer to buffer2 */ - n = 0; /* n is the input position in str */ - m = 0; /* m is the ouput position in buffer2 */ - - while ( str[n] != '\0') { - switch ( str[n] ) { - case '\\': - n++; - if ( str[n] != '\0') - buffer2[m++] = str[n++]; - break; - case '"': - n++; - break; - default: - buffer2[m++] = str[n++]; - break; + case FT_LS_UNQUOTE: + if (str) { + int m; + strncpy(buffer, str, sizeof(buffer)); + /* strncpy doesn't NUL-terminate if it fills the buffer */ + buffer[sizeof(buffer)-1] = '\0'; + str = buffer; + + /* we will parse from buffer to buffer2 */ + n = 0; /* n is the input position in str */ + m = 0; /* m is the ouput position in buffer2 */ + + while ( str[n] != '\0') { + switch ( str[n] ) { + case '\\': + n++; + if ( str[n] != '\0') + buffer2[m++] = str[n++]; + break; + case '"': + n++; + break; + default: + buffer2[m++] = str[n++]; + break; + } + } + buffer2[m] = '\0'; + str = buffer2; } - } - buffer2[m] = '\0'; - str = buffer2; - } - break; - - case FT_LOCALDATE: - comp = fmt->f_comp; - if ((t = comp->c_tws->tw_clock) == 0) - t = dmktime(comp->c_tws); - tws = dlocaltime(&t); - *comp->c_tws = *tws; - break; - - case FT_GMTDATE: - comp = fmt->f_comp; - if ((t = comp->c_tws->tw_clock) == 0) - t = dmktime(comp->c_tws); - tws = dgmtime(&t); - *comp->c_tws = *tws; - break; - - case FT_PARSEDATE: - comp = fmt->f_comp; - if (comp->c_flags & CF_PARSED) - break; - if ((sp = comp->c_text) && (tws = dparsetime(sp))) { - *comp->c_tws = *tws; - comp->c_flags &= ~CF_TRUE; - } else if ((comp->c_flags & CF_DATEFAB) == 0) { - memset ((char *) comp->c_tws, 0, sizeof *comp->c_tws); - comp->c_flags = CF_TRUE; - } - comp->c_flags |= CF_PARSED; - break; - - case FT_FORMATADDR: - /* hook for custom address list formatting (see replsbr.c) */ - str = formataddr (savestr, str); - break; - - case FT_PUTADDR: - /* output the str register as an address component, - * splitting it into multiple lines if necessary. The - * value reg. contains the max line length. The lit. - * field may contain a string to prepend to the result - * (e.g., "To: ") - */ - { - unsigned char *lp; - char *lastb; - int indent, wid, len; - - lp = str; - wid = value; - len = strlen (str); - sp = fmt->f_text; - indent = strlen (sp); - wid -= indent; - while( (c = *sp++) && cp < ep) - *cp++ = c; - while (len > wid) { - /* try to break at a comma; failing that, break at a - * space. - */ - lastb = 0; sp = lp + wid; - while (sp > lp && (c = *--sp) != ',') { - if (! lastb && isspace(c)) - lastb = sp - 1; - } - if (sp == lp) { - if (! (sp = lastb)) { - sp = lp + wid - 1; - while (*sp && *sp != ',' && !isspace(*sp)) - sp++; - if (*sp != ',') - sp--; - } - } - len -= sp - lp + 1; - while (cp < ep && lp <= sp) - *cp++ = *lp++; - while (isspace(*lp)) - lp++, len--; - if (*lp) { - if (cp < ep) - *cp++ = '\n'; - for (i=indent; cp < ep && i > 0; i--) - *cp++ = ' '; - } - } - cpstripped (&cp, ep, lp); - } - break; - - case FT_PARSEADDR: - comp = fmt->f_comp; - if (comp->c_flags & CF_PARSED) - break; - if (comp->c_mn != &fmt_mnull) - mnfree (comp->c_mn); - if ((sp = comp->c_text) && (sp = getname(sp)) && - (mn = getm (sp, NULL, 0, fmt_norm, NULL))) { - comp->c_mn = mn; - while (getname("")) - ; - comp->c_flags |= CF_PARSED; - } else { - while (getname("")) /* XXX */ - ; - comp->c_mn = &fmt_mnull; - } - break; - - case FT_MYMBOX: - /* - * if there's no component, we say true. Otherwise we - * say "true" only if we can parse the address and it - * matches one of our addresses. - */ - comp = fmt->f_comp; - if (comp->c_mn != &fmt_mnull) - mnfree (comp->c_mn); - if ((sp = comp->c_text) && (sp = getname(sp)) && - (mn = getm (sp, NULL, 0, AD_NAME, NULL))) { - comp->c_mn = mn; - if (ismymbox(mn)) - comp->c_flags |= CF_TRUE; - else - comp->c_flags &= ~CF_TRUE; - while ((sp = getname(sp))) - if ((comp->c_flags & CF_TRUE) == 0 && - (mn = getm (sp, NULL, 0, AD_NAME, NULL))) - if (ismymbox(mn)) - comp->c_flags |= CF_TRUE; - } else { - while (getname("")) /* XXX */ - ; - if (comp->c_text == 0) - comp->c_flags |= CF_TRUE; - else - comp->c_flags &= ~CF_TRUE; - comp->c_mn = &fmt_mnull; - } - break; - - case FT_ADDTOSEQ: + break; + + case FT_LOCALDATE: + comp = fmt->f_comp; + if ((t = comp->c_tws->tw_clock) == 0) + t = dmktime(comp->c_tws); + tws = dlocaltime(&t); + *comp->c_tws = *tws; + break; + + case FT_GMTDATE: + comp = fmt->f_comp; + if ((t = comp->c_tws->tw_clock) == 0) + t = dmktime(comp->c_tws); + tws = dgmtime(&t); + *comp->c_tws = *tws; + break; + + case FT_PARSEDATE: + comp = fmt->f_comp; + if (comp->c_flags & CF_PARSED) + break; + if ((sp = comp->c_text) && (tws = dparsetime(sp))) { + *comp->c_tws = *tws; + comp->c_flags &= ~CF_TRUE; + } else if ((comp->c_flags & CF_DATEFAB) == 0) { + memset ((char *) comp->c_tws, 0, sizeof *comp->c_tws); + comp->c_flags = CF_TRUE; + } + comp->c_flags |= CF_PARSED; + break; + + case FT_FORMATADDR: + /* hook for custom address list formatting (see replsbr.c) */ + str = formataddr (savestr, str); + break; + + case FT_PUTADDR: + /* output the str register as an address component, + * splitting it into multiple lines if necessary. The + * value reg. contains the max line length. The lit. + * field may contain a string to prepend to the result + * (e.g., "To: ") + */ + { + unsigned char *lp; + char *lastb; + int indent, wid, len; + + lp = str; + wid = value; + len = strlen (str); + sp = fmt->f_text; + indent = strlen (sp); + wid -= indent; + while( (c = *sp++) && cp < ep) + *cp++ = c; + while (len > wid) { + /* try to break at a comma; failing that, + * break at a space. + */ + lastb = 0; sp = lp + wid; + while (sp > lp && (c = *--sp) != ',') { + if (! lastb && isspace(c)) + lastb = sp - 1; + } + if (sp == lp) { + if (! (sp = lastb)) { + sp = lp + wid - 1; + while (*sp && *sp != ',' && !isspace(*sp)) + sp++; + if (*sp != ',') + sp--; + } + } + len -= sp - lp + 1; + while (cp < ep && lp <= sp) + *cp++ = *lp++; + while (isspace(*lp)) + lp++, len--; + if (*lp) { + if (cp < ep) + *cp++ = '\n'; + for (i=indent; cp < ep && i > 0; i--) + *cp++ = ' '; + } + } + cpstripped (&cp, ep, lp); + } + break; + + case FT_PARSEADDR: + comp = fmt->f_comp; + if (comp->c_flags & CF_PARSED) + break; + if (comp->c_mn != &fmt_mnull) + mnfree (comp->c_mn); + if ((sp = comp->c_text) && (sp = getname(sp)) && + (mn = getm (sp, NULL, 0, fmt_norm, NULL))) { + comp->c_mn = mn; + while (getname("")) + ; + comp->c_flags |= CF_PARSED; + } else { + while (getname("")) /* XXX */ + ; + comp->c_mn = &fmt_mnull; + } + break; + + case FT_MYMBOX: + /* + * if there's no component, we say true. Otherwise we + * say "true" only if we can parse the address and it + * matches one of our addresses. + */ + comp = fmt->f_comp; + if (comp->c_mn != &fmt_mnull) + mnfree (comp->c_mn); + if ((sp = comp->c_text) && (sp = getname(sp)) && + (mn = getm (sp, NULL, 0, AD_NAME, NULL))) { + comp->c_mn = mn; + if (ismymbox(mn)) + comp->c_flags |= CF_TRUE; + else + comp->c_flags &= ~CF_TRUE; + while ((sp = getname(sp))) + if ((comp->c_flags & CF_TRUE) == 0 && + (mn = getm (sp, NULL, 0, AD_NAME, NULL))) + if (ismymbox(mn)) + comp->c_flags |= CF_TRUE; + } else { + while (getname("")) /* XXX */ + ; + if (comp->c_text == 0) + comp->c_flags |= CF_TRUE; + else + comp->c_flags &= ~CF_TRUE; + comp->c_mn = &fmt_mnull; + } + break; + + case FT_ADDTOSEQ: #ifdef LBL - /* If we're working on a folder (as opposed to a file), add the - * current msg to sequence given in literal field. Don't - * disturb string or value registers. - */ - if (fmt_current_folder) - seq_addmsg(fmt_current_folder, fmt->f_text, dat[0], -1); + /* If we're working on a folder (as opposed to a file), add the + * current msg to sequence given in literal field. Don't + * disturb string or value registers. + */ + if (fmt_current_folder) + seq_addmsg(fmt_current_folder, fmt->f_text, dat[0], -1); #endif - break; + break; + } + fmt++; } - fmt++; - } #ifndef JLR - finished:; - if (cp[-1] != '\n') - *cp++ = '\n'; - *cp = 0; - return ((struct format *)0); + finished:; + if (cp[-1] != '\n') + *cp++ = '\n'; + *cp = 0; + return ((struct format *)0); #else /* JLR */ - if (cp[-1] != '\n') - *cp++ = '\n'; - while (fmt->f_type != FT_DONE) - fmt++; - - finished:; - *cp = '\0'; - return (fmt->f_value ? ++fmt : (struct format *) 0); + if (cp[-1] != '\n') + *cp++ = '\n'; + while (fmt->f_type != FT_DONE) + fmt++; + + finished:; + *cp = '\0'; + return (fmt->f_value ? ++fmt : (struct format *) 0); #endif /* JLR */ } diff --git a/sbr/folder_addmsg.c b/sbr/folder_addmsg.c index a0595e6..e26e3bf 100644 --- a/sbr/folder_addmsg.c +++ b/sbr/folder_addmsg.c @@ -1,4 +1,3 @@ - /* * folder_addmsg.c -- Link message into folder * @@ -18,191 +17,189 @@ int folder_addmsg (struct msgs **mpp, char *msgfile, int selected, - int unseen, int preserve, int deleting, char *from_dir) + int unseen, int preserve, int deleting, char *from_dir) { - int infd, outfd, linkerr, msgnum; - char *nmsg, newmsg[BUFSIZ]; - char oldmsg[BUFSIZ]; - struct msgs *mp; - struct stat st1, st2; - - mp = *mpp; - - /* should we preserve the numbering of the message? */ - if (preserve && (msgnum = m_atoi (msgfile)) > 0) { - ; - } else if (mp->nummsg == 0) { - /* check if we are adding to empty folder */ - msgnum = 1; - } else { - /* else use highest message number + 1 */ - msgnum = mp->hghmsg + 1; - } - - /* - * We might need to make several attempts - * in order to add the message to the folder. - */ - for (;; msgnum++) { - - /* - * See if we need more space. If we need space at the - * end, then we allocate space for an addition 100 messages. - * If we need space at the beginning of the range, then just - * extend message status range to cover this message number. - */ - if (msgnum > mp->hghoff) { - if ((mp = folder_realloc (mp, mp->lowoff, msgnum + 100))) - *mpp = mp; - else { - advise (NULL, "unable to allocate folder storage"); - return -1; - } - } else if (msgnum < mp->lowoff) { - if ((mp = folder_realloc (mp, msgnum, mp->hghoff))) - *mpp = mp; - else { - advise (NULL, "unable to allocate folder storage"); - return -1; - } + int infd, outfd, linkerr, msgnum; + char *nmsg, newmsg[BUFSIZ]; + char oldmsg[BUFSIZ]; + struct msgs *mp; + struct stat st1, st2; + + mp = *mpp; + + /* should we preserve the numbering of the message? */ + if (preserve && (msgnum = m_atoi (msgfile)) > 0) { + ; + } else if (mp->nummsg == 0) { + /* check if we are adding to empty folder */ + msgnum = 1; + } else { + /* else use highest message number + 1 */ + msgnum = mp->hghmsg + 1; } /* - * If a message is already in that slot, - * then loop to next available slot. + * We might need to make several attempts + * in order to add the message to the folder. */ - if (does_exist (mp, msgnum)) - continue; + for (;; msgnum++) { + + /* + * See if we need more space. If we need space at the + * end, then we allocate space for an addition 100 messages. + * If we need space at the beginning of the range, then just + * extend message status range to cover this message number. + */ + if (msgnum > mp->hghoff) { + if ((mp = folder_realloc (mp, mp->lowoff, msgnum + 100))) + *mpp = mp; + else { + advise (NULL, "unable to allocate folder storage"); + return -1; + } + } else if (msgnum < mp->lowoff) { + if ((mp = folder_realloc (mp, msgnum, mp->hghoff))) + *mpp = mp; + else { + advise (NULL, "unable to allocate folder storage"); + return -1; + } + } - /* setup the bit flags for this message */ - clear_msg_flags (mp, msgnum); - set_exists (mp, msgnum); + /* + * If a message is already in that slot, + * then loop to next available slot. + */ + if (does_exist (mp, msgnum)) + continue; - /* should we set the SELECT_UNSEEN bit? */ - if (unseen) { - set_unseen (mp, msgnum); - } + /* setup the bit flags for this message */ + clear_msg_flags (mp, msgnum); + set_exists (mp, msgnum); - /* should we set the SELECTED bit? */ - if (selected) { - set_selected (mp, msgnum); - - /* check if highest or lowest selected */ - if (mp->numsel == 0) { - mp->lowsel = msgnum; - mp->hghsel = msgnum; - } else { - if (msgnum < mp->lowsel) - mp->lowsel = msgnum; - if (msgnum > mp->hghsel) - mp->hghsel = msgnum; - } - - /* increment number selected */ - mp->numsel++; - } + /* should we set the SELECT_UNSEEN bit? */ + if (unseen) { + set_unseen (mp, msgnum); + } - /* - * check if this is highest or lowest message - */ - if (mp->nummsg == 0) { - mp->lowmsg = msgnum; - mp->hghmsg = msgnum; - } else { - if (msgnum < mp->lowmsg) - mp->lowmsg = msgnum; - if (msgnum > mp->hghmsg) - mp->hghmsg = msgnum; - } + /* should we set the SELECTED bit? */ + if (selected) { + set_selected (mp, msgnum); + + /* check if highest or lowest selected */ + if (mp->numsel == 0) { + mp->lowsel = msgnum; + mp->hghsel = msgnum; + } else { + if (msgnum < mp->lowsel) + mp->lowsel = msgnum; + if (msgnum > mp->hghsel) + mp->hghsel = msgnum; + } + + /* increment number selected */ + mp->numsel++; + } - /* increment message count */ - mp->nummsg++; + /* + * check if this is highest or lowest message + */ + if (mp->nummsg == 0) { + mp->lowmsg = msgnum; + mp->hghmsg = msgnum; + } else { + if (msgnum < mp->lowmsg) + mp->lowmsg = msgnum; + if (msgnum > mp->hghmsg) + mp->hghmsg = msgnum; + } - nmsg = m_name (msgnum); - snprintf (newmsg, sizeof(newmsg), "%s/%s", mp->foldpath, nmsg); + /* increment message count */ + mp->nummsg++; - /* - * Now try to link message into folder. - * Then run the external hook on the message if one was specified in the context. - * Run the refile hook if we're moving the message from one place to another. - * We have to construct the from path name for this because it's not there. - * Run the add hook if the message is getting copied or linked somewhere else. - */ - if (link (msgfile, newmsg) != -1) { + nmsg = m_name (msgnum); + snprintf (newmsg, sizeof(newmsg), "%s/%s", mp->foldpath, nmsg); - if (deleting) { - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); - (void)ext_hook("ref-hook", oldmsg, newmsg); - } - else - (void)ext_hook("add-hook", newmsg, (char *)0); + /* + * Now try to link message into folder. + * Then run the external hook on the message if one was specified in the context. + * Run the refile hook if we're moving the message from one place to another. + * We have to construct the from path name for this because it's not there. + * Run the add hook if the message is getting copied or linked somewhere else. + */ + if (link (msgfile, newmsg) != -1) { - return msgnum; - } else { - linkerr = errno; + if (deleting) { + (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); + (void)ext_hook("ref-hook", oldmsg, newmsg); + } else + (void)ext_hook("add-hook", newmsg, (char *)0); + + return msgnum; + } else { + linkerr = errno; #ifdef EISREMOTE - if (linkerr == EISREMOTE) - linkerr = EXDEV; + if (linkerr == EISREMOTE) + linkerr = EXDEV; #endif /* EISREMOTE */ - /* - * Check if the file in our desired location is the same - * as the source file. If so, then just leave it alone - * and return. Otherwise, we will continue the main loop - * and try again at another slot (hghmsg+1). - */ - if (linkerr == EEXIST) { - if (stat (msgfile, &st2) == 0 && stat (newmsg, &st1) == 0 - && st2.st_ino == st1.st_ino) { - return msgnum; - } else { - continue; - } - } - - /* - * If link failed because we are trying to link - * across devices, then check if there is a message - * already in the desired location. If so, then return - * error, else just copy the message. - */ - if (linkerr == EXDEV) { - if (stat (newmsg, &st1) == 0) { - advise (NULL, "message %s:%s already exists", mp->foldpath, newmsg); - return -1; - } else { - if ((infd = open (msgfile, O_RDONLY)) == -1) { - advise (msgfile, "unable to open message %s", msgfile); - return -1; - } - fstat (infd, &st1); - if ((outfd = creat (newmsg, (int) st1.st_mode & 0777)) == -1) { - advise (newmsg, "unable to create"); - close (infd); + /* + * Check if the file in our desired location is the same + * as the source file. If so, then just leave it alone + * and return. Otherwise, we will continue the main loop + * and try again at another slot (hghmsg+1). + */ + if (linkerr == EEXIST) { + if (stat (msgfile, &st2) == 0 && stat (newmsg, &st1) == 0 + && st2.st_ino == st1.st_ino) { + return msgnum; + } else { + continue; + } + } + + /* + * If link failed because we are trying to link + * across devices, then check if there is a message + * already in the desired location. If so, then return + * error, else just copy the message. + */ + if (linkerr == EXDEV) { + if (stat (newmsg, &st1) == 0) { + advise (NULL, "message %s:%s already exists", mp->foldpath, newmsg); + return -1; + } else { + if ((infd = open (msgfile, O_RDONLY)) == -1) { + advise (msgfile, "unable to open message %s", msgfile); + return -1; + } + fstat (infd, &st1); + if ((outfd = creat (newmsg, (int) st1.st_mode & 0777)) == -1) { + advise (newmsg, "unable to create"); + close (infd); + return -1; + } + cpydata (infd, outfd, msgfile, newmsg); + close (infd); + close (outfd); + + if (deleting) { + (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); + (void)ext_hook("ref-hook", oldmsg, newmsg); + } else + (void)ext_hook("add-hook", newmsg, (char *)0); + + return msgnum; + } + } + + /* + * Else, some other type of link error, + * so just return error. + */ + advise (newmsg, "error linking %s to", msgfile); return -1; - } - cpydata (infd, outfd, msgfile, newmsg); - close (infd); - close (outfd); - - if (deleting) { - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); - (void)ext_hook("ref-hook", oldmsg, newmsg); - } - else - (void)ext_hook("add-hook", newmsg, (char *)0); - - return msgnum; } - } - - /* - * Else, some other type of link error, - * so just return error. - */ - advise (newmsg, "error linking %s to", msgfile); - return -1; } - } } diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c index e6fac04..0636d11 100644 --- a/sbr/folder_delmsgs.c +++ b/sbr/folder_delmsgs.c @@ -1,4 +1,3 @@ - /* * folder_delmsgs.c -- "remove" SELECTED messages from a folder * @@ -22,110 +21,110 @@ int folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) { - pid_t pid; - int msgnum, vecp, retval = 0; - char buf[100], *dp, **vec; - char msgpath[BUFSIZ]; - - /* - * If "rmmproc" is defined, exec it to remove messages. - */ - if (rmmproc) { - /* Unset the EXISTS flag for each message to be removed */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) - unset_exists (mp, msgnum); - } - - /* Mark that the sequence information has changed */ - mp->msgflags |= SEQMOD; + pid_t pid; + int msgnum, vecp, retval = 0; + char buf[100], *dp, **vec; + char msgpath[BUFSIZ]; + + /* + * If "rmmproc" is defined, exec it to remove messages. + */ + if (rmmproc) { + /* Unset the EXISTS flag for each message to be removed */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) + unset_exists (mp, msgnum); + } - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for %s exec", MAXARGS - 2, - rmmproc); - vec = (char **) calloc ((size_t) (mp->numsel + 2), sizeof(*vec)); - if (vec == NULL) - adios (NULL, "unable to allocate exec vector"); - vecp = 1; - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum) && - !(vec[vecp++] = strdup (m_name (msgnum)))) - adios (NULL, "strdup failed"); - } - vec[vecp] = NULL; + /* Mark that the sequence information has changed */ + mp->msgflags |= SEQMOD; + + if (mp->numsel > MAXARGS - 2) + adios (NULL, "more than %d messages for %s exec", MAXARGS - 2, + rmmproc); + vec = (char **) calloc ((size_t) (mp->numsel + 2), sizeof(*vec)); + if (vec == NULL) + adios (NULL, "unable to allocate exec vector"); + vecp = 1; + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum) && + !(vec[vecp++] = strdup (m_name (msgnum)))) + adios (NULL, "strdup failed"); + } + vec[vecp] = NULL; - fflush (stdout); - vec[0] = r1bindex (rmmproc, '/'); + fflush (stdout); + vec[0] = r1bindex (rmmproc, '/'); - switch (pid = vfork()) { - case -1: - advise ("fork", "unable to"); - return -1; + switch (pid = vfork()) { + case -1: + advise ("fork", "unable to"); + return -1; - case 0: - execvp (rmmproc, vec); - fprintf (stderr, "unable to exec "); - perror (rmmproc); - _exit (-1); + case 0: + execvp (rmmproc, vec); + fprintf (stderr, "unable to exec "); + perror (rmmproc); + _exit (-1); - default: - return (pidwait (pid, -1)); - } - } - - /* - * Either unlink or rename the SELECTED messages - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - /* unselect message */ - unset_selected (mp, msgnum); - mp->numsel--; - - /* - * Run the external hook on the message if one was specified in the context. - * All we have is the message number; we have changed to the directory - * containing the message. So, we need to extract that directory to form - * the complete path. Note that the caller knows the directory, but has - * no way of passing that to us. - */ - - if (!nohook) { - (void)snprintf(msgpath, sizeof (msgpath), "%s/%d", mp->foldpath, msgnum); - (void)ext_hook("del-hook", msgpath, (char *)0); + default: + return (pidwait (pid, -1)); } + } - dp = m_name (msgnum); - - if (unlink_msgs) { - /* just unlink the messages */ - if (unlink (dp) == -1) { - admonish (dp, "unable to unlink"); - retval = -1; - continue; - } - } else { - /* or rename messages with standard prefix */ - strncpy (buf, m_backup (dp), sizeof(buf)); - if (rename (dp, buf) == -1) { - admonish (buf, "unable to rename %s to", dp); - retval = -1; - continue; + /* + * Either unlink or rename the SELECTED messages + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + /* unselect message */ + unset_selected (mp, msgnum); + mp->numsel--; + + /* + * Run the external hook on the message if one was specified in the context. + * All we have is the message number; we have changed to the directory + * containing the message. So, we need to extract that directory to form + * the complete path. Note that the caller knows the directory, but has + * no way of passing that to us. + */ + + if (!nohook) { + (void)snprintf(msgpath, sizeof (msgpath), "%s/%d", mp->foldpath, msgnum); + (void)ext_hook("del-hook", msgpath, (char *)0); + } + + dp = m_name (msgnum); + + if (unlink_msgs) { + /* just unlink the messages */ + if (unlink (dp) == -1) { + admonish (dp, "unable to unlink"); + retval = -1; + continue; + } + } else { + /* or rename messages with standard prefix */ + strncpy (buf, m_backup (dp), sizeof(buf)); + if (rename (dp, buf) == -1) { + admonish (buf, "unable to rename %s to", dp); + retval = -1; + continue; + } + } + + /* If removal was successful, decrement message count */ + unset_exists (mp, msgnum); + mp->nummsg--; } - } - - /* If removal was successful, decrement message count */ - unset_exists (mp, msgnum); - mp->nummsg--; } - } - /* Sanity check */ - if (mp->numsel != 0) + /* Sanity check */ + if (mp->numsel != 0) adios (NULL, "oops, mp->numsel should be 0"); - /* Mark that the sequence information has changed */ - mp->msgflags |= SEQMOD; + /* Mark that the sequence information has changed */ + mp->msgflags |= SEQMOD; - return retval; + return retval; } diff --git a/sbr/folder_free.c b/sbr/folder_free.c index ebb58ab..985c7a4 100644 --- a/sbr/folder_free.c +++ b/sbr/folder_free.c @@ -1,4 +1,3 @@ - /* * folder_free.c -- free a folder/message structure * @@ -13,18 +12,18 @@ void folder_free (struct msgs *mp) { - int i; + int i; - if (!mp) - return; + if (!mp) + return; - if (mp->foldpath) - free (mp->foldpath); + if (mp->foldpath) + free (mp->foldpath); - /* free the sequence names */ - for (i = 0; mp->msgattrs[i]; i++) - free (mp->msgattrs[i]); + /* free the sequence names */ + for (i = 0; mp->msgattrs[i]; i++) + free (mp->msgattrs[i]); - free (mp->msgstats); /* free message status area */ - free (mp); /* free main folder structure */ + free (mp->msgstats); /* free message status area */ + free (mp); /* free main folder structure */ } diff --git a/sbr/folder_pack.c b/sbr/folder_pack.c index b0bc67b..2e321b0 100644 --- a/sbr/folder_pack.c +++ b/sbr/folder_pack.c @@ -1,4 +1,3 @@ - /* * folder_pack.c -- pack (renumber) the messages in a folder * -- into a contiguous range from 1 to n. @@ -18,81 +17,81 @@ int folder_pack (struct msgs **mpp, int verbose) { - int hole, msgnum, newcurrent = 0; - char newmsg[BUFSIZ], oldmsg[BUFSIZ]; - struct msgs *mp; - - mp = *mpp; - - /* - * Just return if folder is empty. - */ - if (mp->nummsg == 0) - return 0; - - /* - * Make sure we have message status space allocated - * for all numbers from 1 to current high message. - */ - if (mp->lowoff > 1) { - if ((mp = folder_realloc (mp, 1, mp->hghmsg))) - *mpp = mp; - else { - advise (NULL, "unable to allocate folder storage"); - return -1; - } - } - - for (msgnum = mp->lowmsg, hole = 1; msgnum <= mp->hghmsg; msgnum++) { - if (does_exist (mp, msgnum)) { - if (msgnum != hole) { - strncpy (newmsg, m_name (hole), sizeof(newmsg)); - strncpy (oldmsg, m_name (msgnum), sizeof(oldmsg)); - if (verbose) - printf ("message %s becomes %s\n", oldmsg, newmsg); - - /* - * Invoke the external refile hook for each message being renamed. - * This is done before the file is renamed so that the old message - * file is around for the hook. - */ - - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%d", mp->foldpath, msgnum); - (void)snprintf(newmsg, sizeof (newmsg), "%s/%d", mp->foldpath, hole); - ext_hook("ref-hook", oldmsg, newmsg); - - /* move the message file */ - if (rename (oldmsg, newmsg) == -1) { - advise (newmsg, "unable to rename %s to", oldmsg); - return -1; + int hole, msgnum, newcurrent = 0; + char newmsg[BUFSIZ], oldmsg[BUFSIZ]; + struct msgs *mp; + + mp = *mpp; + + /* + * Just return if folder is empty. + */ + if (mp->nummsg == 0) + return 0; + + /* + * Make sure we have message status space allocated + * for all numbers from 1 to current high message. + */ + if (mp->lowoff > 1) { + if ((mp = folder_realloc (mp, 1, mp->hghmsg))) + *mpp = mp; + else { + advise (NULL, "unable to allocate folder storage"); + return -1; } + } - /* check if this is the current message */ - if (msgnum == mp->curmsg) - newcurrent = hole; - - /* copy the attribute flags for this message */ - copy_msg_flags (mp, hole, msgnum); - - if (msgnum == mp->lowsel) - mp->lowsel = hole; - if (msgnum == mp->hghsel) - mp->hghsel = hole; - - /* mark that sequence information has been modified */ - mp->msgflags |= SEQMOD; - } - hole++; + for (msgnum = mp->lowmsg, hole = 1; msgnum <= mp->hghmsg; msgnum++) { + if (does_exist (mp, msgnum)) { + if (msgnum != hole) { + strncpy (newmsg, m_name (hole), sizeof(newmsg)); + strncpy (oldmsg, m_name (msgnum), sizeof(oldmsg)); + if (verbose) + printf ("message %s becomes %s\n", oldmsg, newmsg); + + /* + * Invoke the external refile hook for each message being renamed. + * This is done before the file is renamed so that the old message + * file is around for the hook. + */ + + (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%d", mp->foldpath, msgnum); + (void)snprintf(newmsg, sizeof (newmsg), "%s/%d", mp->foldpath, hole); + ext_hook("ref-hook", oldmsg, newmsg); + + /* move the message file */ + if (rename (oldmsg, newmsg) == -1) { + advise (newmsg, "unable to rename %s to", oldmsg); + return -1; + } + + /* check if this is the current message */ + if (msgnum == mp->curmsg) + newcurrent = hole; + + /* copy the attribute flags for this message */ + copy_msg_flags (mp, hole, msgnum); + + if (msgnum == mp->lowsel) + mp->lowsel = hole; + if (msgnum == mp->hghsel) + mp->hghsel = hole; + + /* mark that sequence information has been modified */ + mp->msgflags |= SEQMOD; + } + hole++; + } } - } - /* record the new number for the high/low message */ - mp->lowmsg = 1; - mp->hghmsg = hole - 1; + /* record the new number for the high/low message */ + mp->lowmsg = 1; + mp->hghmsg = hole - 1; - /* update the "cur" sequence */ - if (newcurrent != 0) - seq_setcur (mp, newcurrent); + /* update the "cur" sequence */ + if (newcurrent != 0) + seq_setcur (mp, newcurrent); - return 0; + return 0; } diff --git a/sbr/folder_read.c b/sbr/folder_read.c index f642ed3..c77ea1e 100644 --- a/sbr/folder_read.c +++ b/sbr/folder_read.c @@ -1,4 +1,3 @@ - /* * folder_read.c -- initialize folder structure and read folder * @@ -11,7 +10,7 @@ #include /* We allocate the `mi' array 1024 elements at a time */ -#define NUMMSGS 1024 +#define NUMMSGS 1024 /* * 1) Create the folder/message structure @@ -25,136 +24,136 @@ struct msgs * folder_read (char *name) { - int msgnum, prefix_len, len, *mi; - struct msgs *mp; - struct stat st; - struct dirent *dp; - DIR *dd; - - name = m_mailpath (name); - if (!(dd = opendir (name))) { - free (name); - return NULL; - } - - if (stat (name, &st) == -1) { - free (name); - return NULL; - } - - /* Allocate the main structure for folder information */ - mp = (struct msgs *) mh_xmalloc ((size_t) sizeof(*mp)); - - clear_folder_flags (mp); - mp->foldpath = name; - mp->lowmsg = 0; - mp->hghmsg = 0; - mp->curmsg = 0; - mp->lowsel = 0; - mp->hghsel = 0; - mp->numsel = 0; - mp->nummsg = 0; - - if (access (name, W_OK) == -1) - set_readonly (mp); - prefix_len = strlen(backup_prefix); - - /* - * Allocate a temporary place to record the - * name of the messages in this folder. - */ - len = NUMMSGS; - mi = (int *) mh_xmalloc ((size_t) (len * sizeof(*mi))); - - while ((dp = readdir (dd))) { - if ((msgnum = m_atoi (dp->d_name)) && msgnum > 0) { - /* - * Check if we need to allocate more - * temporary elements for message names. - */ - if (mp->nummsg >= len) { - len += NUMMSGS; - mi = (int *) mh_xrealloc (mi, (size_t) (len * sizeof(*mi))); - } - - /* Check if this is the first message we've seen */ - if (mp->nummsg == 0) { - mp->lowmsg = msgnum; - mp->hghmsg = msgnum; - } else { - /* Check if this is it the highest or lowest we've seen? */ - if (msgnum < mp->lowmsg) - mp->lowmsg = msgnum; - if (msgnum > mp->hghmsg) - mp->hghmsg = msgnum; - } - - /* - * Now increment count, and record message - * number in a temporary place for now. - */ - mi[mp->nummsg++] = msgnum; - - } else { - switch (dp->d_name[0]) { - case '.': - case ',': -#ifdef MHE - case '+': -#endif /* MHE */ - continue; - - default: - /* skip any files beginning with backup prefix */ - if (!strncmp (dp->d_name, backup_prefix, prefix_len)) - continue; + int msgnum, prefix_len, len, *mi; + struct msgs *mp; + struct stat st; + struct dirent *dp; + DIR *dd; + + name = m_mailpath (name); + if (!(dd = opendir (name))) { + free (name); + return NULL; + } - /* skip the altmsg link file */ - if (!strcmp (dp->d_name, altmsglink)) - continue; + if (stat (name, &st) == -1) { + free (name); + return NULL; + } - /* indicate that there are other files in folder */ - set_other_files (mp); - continue; - } + /* Allocate the main structure for folder information */ + mp = (struct msgs *) mh_xmalloc ((size_t) sizeof(*mp)); + + clear_folder_flags (mp); + mp->foldpath = name; + mp->lowmsg = 0; + mp->hghmsg = 0; + mp->curmsg = 0; + mp->lowsel = 0; + mp->hghsel = 0; + mp->numsel = 0; + mp->nummsg = 0; + + if (access (name, W_OK) == -1) + set_readonly (mp); + prefix_len = strlen(backup_prefix); + + /* + * Allocate a temporary place to record the + * name of the messages in this folder. + */ + len = NUMMSGS; + mi = (int *) mh_xmalloc ((size_t) (len * sizeof(*mi))); + + while ((dp = readdir (dd))) { + if ((msgnum = m_atoi (dp->d_name)) && msgnum > 0) { + /* + * Check if we need to allocate more + * temporary elements for message names. + */ + if (mp->nummsg >= len) { + len += NUMMSGS; + mi = (int *) mh_xrealloc (mi, (size_t) (len * sizeof(*mi))); + } + + /* Check if this is the first message we've seen */ + if (mp->nummsg == 0) { + mp->lowmsg = msgnum; + mp->hghmsg = msgnum; + } else { + /* Check if this is it the highest or lowest we've seen? */ + if (msgnum < mp->lowmsg) + mp->lowmsg = msgnum; + if (msgnum > mp->hghmsg) + mp->hghmsg = msgnum; + } + + /* + * Now increment count, and record message + * number in a temporary place for now. + */ + mi[mp->nummsg++] = msgnum; + + } else { + switch (dp->d_name[0]) { + case '.': + case ',': +#ifdef MHE + case '+': +#endif /* MHE */ + continue; + + default: + /* skip any files beginning with backup prefix */ + if (!strncmp (dp->d_name, backup_prefix, prefix_len)) + continue; + + /* skip the altmsg link file */ + if (!strcmp (dp->d_name, altmsglink)) + continue; + + /* indicate that there are other files in folder */ + set_other_files (mp); + continue; + } + } } - } - closedir (dd); - mp->lowoff = max (mp->lowmsg, 1); + closedir (dd); + mp->lowoff = max (mp->lowmsg, 1); - /* Go ahead and allocate space for 100 additional messages. */ - mp->hghoff = mp->hghmsg + 100; + /* Go ahead and allocate space for 100 additional messages. */ + mp->hghoff = mp->hghmsg + 100; - /* for testing, allocate minimal necessary space */ - /* mp->hghoff = max (mp->hghmsg, 1); */ + /* for testing, allocate minimal necessary space */ + /* mp->hghoff = max (mp->hghmsg, 1); */ - /* - * Allocate space for status of each message. - */ - mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)); + /* + * Allocate space for status of each message. + */ + mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)); - /* - * Clear all the flag bits for all the message - * status entries we just allocated. - */ - for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++) - clear_msg_flags (mp, msgnum); + /* + * Clear all the flag bits for all the message + * status entries we just allocated. + */ + for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++) + clear_msg_flags (mp, msgnum); - /* - * Scan through the array of messages we've seen and - * setup the initial flags for those messages in the - * newly allocated mp->msgstats area. - */ - for (msgnum = 0; msgnum < mp->nummsg; msgnum++) - set_exists (mp, mi[msgnum]); + /* + * Scan through the array of messages we've seen and + * setup the initial flags for those messages in the + * newly allocated mp->msgstats area. + */ + for (msgnum = 0; msgnum < mp->nummsg; msgnum++) + set_exists (mp, mi[msgnum]); - free (mi); /* We don't need this anymore */ + free (mi); /* We don't need this anymore */ - /* - * Read and initialize the sequence information. - */ - seq_read (mp); + /* + * Read and initialize the sequence information. + */ + seq_read (mp); - return mp; + return mp; } diff --git a/sbr/folder_realloc.c b/sbr/folder_realloc.c index 6a94a00..1d2b140 100644 --- a/sbr/folder_realloc.c +++ b/sbr/folder_realloc.c @@ -1,4 +1,3 @@ - /* * folder_realloc.c -- realloc a folder/msgs structure * @@ -21,67 +20,67 @@ struct msgs * folder_realloc (struct msgs *mp, int lo, int hi) { - int msgnum; + int msgnum; - /* sanity checks */ - if (lo < 1) - adios (NULL, "BUG: called folder_realloc with lo (%d) < 1", lo); - if (hi < 1) - adios (NULL, "BUG: called folder_realloc with hi (%d) < 1", hi); - if (mp->nummsg > 0 && lo > mp->lowmsg) - adios (NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)", - lo, mp->lowmsg); - if (mp->nummsg > 0 && hi < mp->hghmsg) - adios (NULL, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)", - hi, mp->hghmsg); + /* sanity checks */ + if (lo < 1) + adios (NULL, "BUG: called folder_realloc with lo (%d) < 1", lo); + if (hi < 1) + adios (NULL, "BUG: called folder_realloc with hi (%d) < 1", hi); + if (mp->nummsg > 0 && lo > mp->lowmsg) + adios (NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)", + lo, mp->lowmsg); + if (mp->nummsg > 0 && hi < mp->hghmsg) + adios (NULL, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)", + hi, mp->hghmsg); - /* Check if we really need to reallocate anything */ - if (lo == mp->lowoff && hi == mp->hghoff) - return mp; + /* Check if we really need to reallocate anything */ + if (lo == mp->lowoff && hi == mp->hghoff) + return mp; - if (lo == mp->lowoff) { - /* - * We are just extending (or shrinking) the end of message - * status array. So we don't have to move anything and can - * just realloc the message status array. - */ - mp->msgstats = mh_xrealloc (mp->msgstats, MSGSTATSIZE(mp, lo, hi)); - } else { - /* - * We are changing the offset of the message status - * array. So we will need to shift everything. - */ - seqset_t *tmpstats; + if (lo == mp->lowoff) { + /* + * We are just extending (or shrinking) the end of message + * status array. So we don't have to move anything and can + * just realloc the message status array. + */ + mp->msgstats = mh_xrealloc (mp->msgstats, MSGSTATSIZE(mp, lo, hi)); + } else { + /* + * We are changing the offset of the message status + * array. So we will need to shift everything. + */ + seqset_t *tmpstats; - /* first allocate the new message status space */ - tmpstats = mh_xmalloc (MSGSTATSIZE(mp, lo, hi)); + /* first allocate the new message status space */ + tmpstats = mh_xmalloc (MSGSTATSIZE(mp, lo, hi)); - /* then copy messages status array with shift */ - if (mp->nummsg > 0) { - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) - tmpstats[msgnum - lo] = mp->msgstats[msgnum - mp->lowoff]; + /* then copy messages status array with shift */ + if (mp->nummsg > 0) { + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) + tmpstats[msgnum - lo] = mp->msgstats[msgnum - mp->lowoff]; + } + free(mp->msgstats); + mp->msgstats = tmpstats; } - free(mp->msgstats); - mp->msgstats = tmpstats; - } - mp->lowoff = lo; - mp->hghoff = hi; + mp->lowoff = lo; + mp->hghoff = hi; - /* - * Clear all the flags for entries outside - * the current message range for this folder. - */ - if (mp->nummsg > 0) { - for (msgnum = mp->lowoff; msgnum < mp->lowmsg; msgnum++) - clear_msg_flags (mp, msgnum); - for (msgnum = mp->hghmsg + 1; msgnum <= mp->hghoff; msgnum++) - clear_msg_flags (mp, msgnum); - } else { - /* no messages, so clear entire range */ - for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++) - clear_msg_flags (mp, msgnum); - } + /* + * Clear all the flags for entries outside + * the current message range for this folder. + */ + if (mp->nummsg > 0) { + for (msgnum = mp->lowoff; msgnum < mp->lowmsg; msgnum++) + clear_msg_flags (mp, msgnum); + for (msgnum = mp->hghmsg + 1; msgnum <= mp->hghoff; msgnum++) + clear_msg_flags (mp, msgnum); + } else { + /* no messages, so clear entire range */ + for (msgnum = mp->lowoff; msgnum <= mp->hghoff; msgnum++) + clear_msg_flags (mp, msgnum); + } - return mp; + return mp; } diff --git a/sbr/gans.c b/sbr/gans.c index 6b76b7b..270b729 100644 --- a/sbr/gans.c +++ b/sbr/gans.c @@ -1,4 +1,3 @@ - /* * gans.c -- get an answer from the user * @@ -13,39 +12,39 @@ int gans (char *prompt, struct swit *ansp) { - register int i; - register char *cp; - register struct swit *ap; - char ansbuf[BUFSIZ]; + register int i; + register char *cp; + register struct swit *ap; + char ansbuf[BUFSIZ]; - for (;;) { - printf ("%s", prompt); - fflush (stdout); - cp = ansbuf; - while ((i = getchar ()) != '\n') { - if (i == EOF) - return 0; - if (cp < &ansbuf[sizeof ansbuf - 1]) { + for (;;) { + printf ("%s", prompt); + fflush (stdout); + cp = ansbuf; + while ((i = getchar ()) != '\n') { + if (i == EOF) + return 0; + if (cp < &ansbuf[sizeof ansbuf - 1]) { #ifdef LOCALE - i = (isalpha(i) && isupper(i)) ? tolower(i) : i; + i = (isalpha(i) && isupper(i)) ? tolower(i) : i; #else - if (i >= 'A' && i <= 'Z') - i += 'a' - 'A'; + if (i >= 'A' && i <= 'Z') + i += 'a' - 'A'; #endif - *cp++ = i; - } - } - *cp = '\0'; - if (ansbuf[0] == '?' || cp == ansbuf) { - printf ("Options are:\n"); - for (ap = ansp; ap->sw; ap++) - printf (" %s\n", ap->sw); - continue; - } - if ((i = smatch (ansbuf, ansp)) < 0) { - printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous"); - continue; + *cp++ = i; + } + } + *cp = '\0'; + if (ansbuf[0] == '?' || cp == ansbuf) { + printf ("Options are:\n"); + for (ap = ansp; ap->sw; ap++) + printf (" %s\n", ap->sw); + continue; + } + if ((i = smatch (ansbuf, ansp)) < 0) { + printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous"); + continue; + } + return i; } - return i; - } } diff --git a/sbr/getans.c b/sbr/getans.c index 3229eb5..befbd9a 100644 --- a/sbr/getans.c +++ b/sbr/getans.c @@ -1,4 +1,3 @@ - /* * getans.c -- get an answer from the user and return a string array * @@ -24,54 +23,54 @@ static RETSIGTYPE intrser (int); char ** getans (char *prompt, struct swit *ansp) { - int i; - SIGNAL_HANDLER istat = NULL; - char *cp, **cpp; - - if (!(setjmp (sigenv))) { - istat = SIGNAL (SIGINT, intrser); - } else { - SIGNAL (SIGINT, istat); - return NULL; - } + int i; + SIGNAL_HANDLER istat = NULL; + char *cp, **cpp; - for (;;) { - printf ("%s", prompt); - fflush (stdout); - cp = ansbuf; - while ((i = getchar ()) != '\n') { - if (i == EOF) - longjmp (sigenv, 1); - if (cp < &ansbuf[sizeof ansbuf - 1]) - *cp++ = i; - } - *cp = '\0'; - if (ansbuf[0] == '?' || cp == ansbuf) { - printf ("Options are:\n"); - print_sw (ALL, ansp, "", stdout); - continue; - } - cpp = brkstring (ansbuf, " ", NULL); - switch (smatch (*cpp, ansp)) { - case AMBIGSW: - ambigsw (*cpp, ansp); - continue; - case UNKWNSW: - printf (" -%s unknown. Hit for help.\n", *cpp); - continue; - default: + if (!(setjmp (sigenv))) { + istat = SIGNAL (SIGINT, intrser); + } else { SIGNAL (SIGINT, istat); - return cpp; + return NULL; + } + + for (;;) { + printf ("%s", prompt); + fflush (stdout); + cp = ansbuf; + while ((i = getchar ()) != '\n') { + if (i == EOF) + longjmp (sigenv, 1); + if (cp < &ansbuf[sizeof ansbuf - 1]) + *cp++ = i; + } + *cp = '\0'; + if (ansbuf[0] == '?' || cp == ansbuf) { + printf ("Options are:\n"); + print_sw (ALL, ansp, "", stdout); + continue; + } + cpp = brkstring (ansbuf, " ", NULL); + switch (smatch (*cpp, ansp)) { + case AMBIGSW: + ambigsw (*cpp, ansp); + continue; + case UNKWNSW: + printf (" -%s unknown. Hit for help.\n", *cpp); + continue; + default: + SIGNAL (SIGINT, istat); + return cpp; + } } - } } static RETSIGTYPE intrser (int i) { - /* - * should this be siglongjmp? - */ - longjmp (sigenv, 1); + /* + * should this be siglongjmp? + */ + longjmp (sigenv, 1); } diff --git a/sbr/getanswer.c b/sbr/getanswer.c index d0ec6f8..ed5fac0 100644 --- a/sbr/getanswer.c +++ b/sbr/getanswer.c @@ -1,4 +1,3 @@ - /* * getanswer.c -- get a yes/no answer from the user * @@ -14,10 +13,10 @@ int getanswer (char *prompt) { - static int interactive = -1; + static int interactive = -1; - if (interactive < 0) - interactive = isatty (fileno (stdin)) ? 1 : 0; + if (interactive < 0) + interactive = isatty (fileno (stdin)) ? 1 : 0; - return (interactive ? gans (prompt, anoyes) : 1); + return (interactive ? gans (prompt, anoyes) : 1); } diff --git a/sbr/getarguments.c b/sbr/getarguments.c index 0f8834b..d133e06 100644 --- a/sbr/getarguments.c +++ b/sbr/getarguments.c @@ -1,4 +1,3 @@ - /* * getarguments.c -- Get the argument vector ready to go. * @@ -13,38 +12,38 @@ char ** getarguments (char *invo_name, int argc, char **argv, int check_context) { - char *cp = NULL, **ap = NULL, **bp = NULL, **arguments = NULL; - int n = 0; - - /* - * Check if profile/context specifies any arguments - */ - if (check_context && (cp = context_find (invo_name))) { - cp = getcpy (cp); /* make copy */ - ap = brkstring (cp, " ", "\n"); /* split string */ - - /* Count number of arguments split */ - bp = ap; - while (*bp++) - n++; - } - - arguments = (char **) mh_xmalloc ((argc + n) * sizeof(*arguments)); - bp = arguments; - - /* Copy any arguments from profile/context */ - if (ap != NULL && n > 0) { - while (*ap) - *bp++ = *ap++; - } - - /* Copy arguments from command line */ - argv++; - while (*argv) - *bp++ = *argv++; - - /* Now NULL terminate the array */ - *bp = NULL; - - return arguments; + char *cp = NULL, **ap = NULL, **bp = NULL, **arguments = NULL; + int n = 0; + + /* + * Check if profile/context specifies any arguments + */ + if (check_context && (cp = context_find (invo_name))) { + cp = getcpy (cp); /* make copy */ + ap = brkstring (cp, " ", "\n"); /* split string */ + + /* Count number of arguments split */ + bp = ap; + while (*bp++) + n++; + } + + arguments = (char **) mh_xmalloc ((argc + n) * sizeof(*arguments)); + bp = arguments; + + /* Copy any arguments from profile/context */ + if (ap != NULL && n > 0) { + while (*ap) + *bp++ = *ap++; + } + + /* Copy arguments from command line */ + argv++; + while (*argv) + *bp++ = *argv++; + + /* Now NULL terminate the array */ + *bp = NULL; + + return arguments; } diff --git a/sbr/getcpy.c b/sbr/getcpy.c index 6633248..2e94f08 100644 --- a/sbr/getcpy.c +++ b/sbr/getcpy.c @@ -1,4 +1,3 @@ - /* * getcpy.c -- copy a string in managed memory * @@ -18,16 +17,16 @@ char * getcpy (char *str) { - char *cp; - size_t len; + char *cp; + size_t len; - if (str) { - len = strlen(str) + 1; - cp = mh_xmalloc (len); - memcpy (cp, str, len); - } else { - cp = mh_xmalloc ((size_t) 1); - *cp = '\0'; - } - return cp; + if (str) { + len = strlen(str) + 1; + cp = mh_xmalloc (len); + memcpy (cp, str, len); + } else { + cp = mh_xmalloc ((size_t) 1); + *cp = '\0'; + } + return cp; } diff --git a/sbr/getfolder.c b/sbr/getfolder.c index 6c6d267..11e2b21 100644 --- a/sbr/getfolder.c +++ b/sbr/getfolder.c @@ -1,4 +1,3 @@ - /* * getfolder.c -- get the current or default folder * @@ -13,22 +12,22 @@ char * getfolder(int wantcurrent) { - register char *folder; + register char *folder; - /* - * If wantcurrent == 1, then try the current folder first - */ - if (wantcurrent && (folder = context_find (pfolder)) && *folder != '\0') - return folder; + /* + * If wantcurrent == 1, then try the current folder first + */ + if (wantcurrent && (folder = context_find (pfolder)) && *folder != '\0') + return folder; - /* - * Else try the Inbox profile entry - */ - if ((folder = context_find (inbox)) && *folder != '\0') - return folder; + /* + * Else try the Inbox profile entry + */ + if ((folder = context_find (inbox)) && *folder != '\0') + return folder; - /* - * Else return compile time default. - */ - return defaultfolder; + /* + * Else return compile time default. + */ + return defaultfolder; } diff --git a/sbr/getpass.c b/sbr/getpass.c index f3ae829..865a6c9 100644 --- a/sbr/getpass.c +++ b/sbr/getpass.c @@ -1,6 +1,6 @@ /* * Portions of this code are Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,8 +12,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -42,48 +42,45 @@ #define MAX_PASSWORD_LEN 256 #ifndef TCSANOW -#define TCSANOW 0 +# define TCSANOW 0 #endif char * nmh_getpass(const char *prompt) { - struct termios oterm, term; - int ch; - char *p; - FILE *fout, *fin; - static char buf[MAX_PASSWORD_LEN + 1]; - int istty = isatty(fileno(stdin)); + struct termios oterm, term; + int ch; + char *p; + FILE *fout, *fin; + static char buf[MAX_PASSWORD_LEN + 1]; + int istty = isatty(fileno(stdin)); - /* Find if stdin is connect to a terminal. If so, read directly from - * the terminal, and turn off echo. Otherwise read from stdin. - */ + /* Find if stdin is connect to a terminal. If so, read directly from + * the terminal, and turn off echo. Otherwise read from stdin. + */ - if (!istty || !(fout = fin = fopen("/dev/tty", "w+"))) { - fout = stderr; - fin = stdin; - } - else /* Reading directly from terminal here */ - { - (void)tcgetattr(fileno(fin), &oterm); - term = oterm; /* Save original info */ - term.c_lflag &= ~ECHO; - (void)fputs(prompt, fout); - rewind(fout); /* implied flush */ - (void)tcsetattr(fileno(fin), TCSANOW, &term); - } + if (!istty || !(fout = fin = fopen("/dev/tty", "w+"))) { + fout = stderr; + fin = stdin; + } else { /* Reading directly from terminal here */ + (void)tcgetattr(fileno(fin), &oterm); + term = oterm; /* Save original info */ + term.c_lflag &= ~ECHO; + (void)fputs(prompt, fout); + rewind(fout); /* implied flush */ + (void)tcsetattr(fileno(fin), TCSANOW, &term); + } - for (p = buf; (ch = getc(fin)) != EOF && - ch != '\n' && - p < buf + MAX_PASSWORD_LEN;) - *p++ = ch; - *p = '\0'; + for (p = buf; (ch = getc(fin)) != EOF && ch != '\n' && + p < buf + MAX_PASSWORD_LEN;) + *p++ = ch; + *p = '\0'; - if (istty) { - (void)tcsetattr(fileno(fin), TCSANOW, &oterm); - rewind(fout); - (void)fputc('\n', fout); - (void)fclose(fin); - } - return buf; + if (istty) { + (void)tcsetattr(fileno(fin), TCSANOW, &oterm); + rewind(fout); + (void)fputc('\n', fout); + (void)fclose(fin); + } + return buf; } diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 7eaa0de..5bc83cc 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -1,4 +1,3 @@ - /* * lock.c -- routines to lock/unlock files * @@ -14,7 +13,7 @@ * * Ruud de Rooij Sun, 28 Mar 1999 15:34:03 +0200 */ - + #include #include #include @@ -63,9 +62,9 @@ char *lockdir = LOCKDIR; /* struct for getting name of lock file to create */ struct lockinfo { - char curlock[BUFSIZ]; + char curlock[BUFSIZ]; #if !defined(HAVE_LIBLOCKFILE) - char tmplock[BUFSIZ]; + char tmplock[BUFSIZ]; #endif }; @@ -73,7 +72,7 @@ struct lockinfo { * Amount of time to wait before * updating ctime of lock file. */ -#define NSECS 20 +#define NSECS 20 #if !defined(HAVE_LIBLOCKFILE) /* @@ -85,9 +84,9 @@ struct lockinfo { /* struct for recording and updating locks */ struct lock { - int l_fd; - char *l_lock; - struct lock *l_next; + int l_fd; + char *l_lock; + struct lock *l_next; }; /* top of list containing all open locks */ @@ -122,11 +121,11 @@ int lkopen (char *file, int access, mode_t mode) { #ifdef KERNEL_LOCKING - return lkopen_kernel(file, access, mode); + return lkopen_kernel(file, access, mode); #endif #ifdef DOT_LOCKING - return lkopen_dot(file, access, mode); + return lkopen_dot(file, access, mode); #endif } @@ -140,45 +139,45 @@ int lkclose (int fd, char *file) { #ifdef FCNTL_LOCKING - struct flock buf; + struct flock buf; #endif #ifdef DOT_LOCKING - struct lockinfo lkinfo; + struct lockinfo lkinfo; #endif - if (fd == -1) - return 0; + if (fd == -1) + return 0; #ifdef FCNTL_LOCKING - buf.l_type = F_UNLCK; - buf.l_whence = SEEK_SET; - buf.l_start = 0; - buf.l_len = 0; - fcntl(fd, F_SETLK, &buf); + buf.l_type = F_UNLCK; + buf.l_whence = SEEK_SET; + buf.l_start = 0; + buf.l_len = 0; + fcntl(fd, F_SETLK, &buf); #endif #ifdef FLOCK_LOCKING - flock (fd, LOCK_UN); + flock (fd, LOCK_UN); #endif #ifdef LOCKF_LOCKING - /* make sure we unlock the whole thing */ - lseek (fd, (off_t) 0, SEEK_SET); - lockf (fd, F_ULOCK, 0L); -#endif + /* make sure we unlock the whole thing */ + lseek (fd, (off_t) 0, SEEK_SET); + lockf (fd, F_ULOCK, 0L); +#endif #ifdef DOT_LOCKING - lockname (file, &lkinfo, 0); /* get name of lock file */ + lockname (file, &lkinfo, 0); /* get name of lock file */ #if !defined(HAVE_LIBLOCKFILE) - unlink (lkinfo.curlock); /* remove lock file */ + unlink (lkinfo.curlock); /* remove lock file */ #else - lockfile_remove(lkinfo.curlock); + lockfile_remove(lkinfo.curlock); #endif /* HAVE_LIBLOCKFILE */ - timerOFF (fd); /* turn off lock timer */ + timerOFF (fd); /* turn off lock timer */ #endif /* DOT_LOCKING */ - return (close (fd)); + return (close (fd)); } @@ -190,35 +189,35 @@ lkclose (int fd, char *file) FILE * lkfopen (char *file, char *mode) { - int fd, access; - FILE *fp; - - if (strcmp (mode, "r") == 0) - access = O_RDONLY; - else if (strcmp (mode, "r+") == 0) - access = O_RDWR; - else if (strcmp (mode, "w") == 0) - access = O_WRONLY | O_CREAT | O_TRUNC; - else if (strcmp (mode, "w+") == 0) - access = O_RDWR | O_CREAT | O_TRUNC; - else if (strcmp (mode, "a") == 0) - access = O_WRONLY | O_CREAT | O_APPEND; - else if (strcmp (mode, "a+") == 0) - access = O_RDWR | O_CREAT | O_APPEND; - else { - errno = EINVAL; - return NULL; - } - - if ((fd = lkopen (file, access, 0666)) == -1) - return NULL; - - if ((fp = fdopen (fd, mode)) == NULL) { - close (fd); - return NULL; - } + int fd, access; + FILE *fp; + + if (strcmp (mode, "r") == 0) + access = O_RDONLY; + else if (strcmp (mode, "r+") == 0) + access = O_RDWR; + else if (strcmp (mode, "w") == 0) + access = O_WRONLY | O_CREAT | O_TRUNC; + else if (strcmp (mode, "w+") == 0) + access = O_RDWR | O_CREAT | O_TRUNC; + else if (strcmp (mode, "a") == 0) + access = O_WRONLY | O_CREAT | O_APPEND; + else if (strcmp (mode, "a+") == 0) + access = O_RDWR | O_CREAT | O_APPEND; + else { + errno = EINVAL; + return NULL; + } - return fp; + if ((fd = lkopen (file, access, 0666)) == -1) + return NULL; + + if ((fp = fdopen (fd, mode)) == NULL) { + close (fd); + return NULL; + } + + return fp; } @@ -231,45 +230,45 @@ int lkfclose (FILE *fp, char *file) { #ifdef FCNTL_LOCKING - struct flock buf; + struct flock buf; #endif #ifdef DOT_LOCKING - struct lockinfo lkinfo; + struct lockinfo lkinfo; #endif - if (fp == NULL) - return 0; + if (fp == NULL) + return 0; #ifdef FCNTL_LOCKING - buf.l_type = F_UNLCK; - buf.l_whence = SEEK_SET; - buf.l_start = 0; - buf.l_len = 0; - fcntl(fileno(fp), F_SETLK, &buf); + buf.l_type = F_UNLCK; + buf.l_whence = SEEK_SET; + buf.l_start = 0; + buf.l_len = 0; + fcntl(fileno(fp), F_SETLK, &buf); #endif #ifdef FLOCK_LOCKING - flock (fileno(fp), LOCK_UN); + flock (fileno(fp), LOCK_UN); #endif #ifdef LOCKF_LOCKING - /* make sure we unlock the whole thing */ - fseek (fp, 0L, SEEK_SET); - lockf (fileno(fp), F_ULOCK, 0L); + /* make sure we unlock the whole thing */ + fseek (fp, 0L, SEEK_SET); + lockf (fileno(fp), F_ULOCK, 0L); #endif #ifdef DOT_LOCKING - lockname (file, &lkinfo, 0); /* get name of lock file */ + lockname (file, &lkinfo, 0); /* get name of lock file */ #if !defined(HAVE_LIBLOCKFILE) - unlink (lkinfo.curlock); /* remove lock file */ + unlink (lkinfo.curlock); /* remove lock file */ #else - lockfile_remove(lkinfo.curlock); + lockfile_remove(lkinfo.curlock); #endif /* HAVE_LIBLOCKFILE */ - timerOFF (fileno(fp)); /* turn off lock timer */ + timerOFF (fileno(fp)); /* turn off lock timer */ #endif /* DOT_LOCKING */ - return (fclose (fp)); + return (fclose (fp)); } @@ -282,66 +281,66 @@ lkfclose (FILE *fp, char *file) static int lkopen_kernel (char *file, int access, mode_t mode) { - int fd, i, j; + int fd, i, j; # ifdef FCNTL_LOCKING - struct flock buf; + struct flock buf; # endif /* FCNTL_LOCKING */ - for (i = 0; i < 5; i++) { + for (i = 0; i < 5; i++) { # if defined(LOCKF_LOCKING) || defined(FCNTL_LOCKING) - /* remember the original mode */ - j = access; + /* remember the original mode */ + j = access; - /* make sure we open at the beginning */ - access &= ~O_APPEND; + /* make sure we open at the beginning */ + access &= ~O_APPEND; - /* - * We MUST have write permission or - * lockf/fcntl() won't work - */ - if ((access & 03) == O_RDONLY) { - access &= ~O_RDONLY; - access |= O_RDWR; - } + /* + * We MUST have write permission or + * lockf/fcntl() won't work + */ + if ((access & 03) == O_RDONLY) { + access &= ~O_RDONLY; + access |= O_RDWR; + } # endif /* LOCKF_LOCKING || FCNTL_LOCKING */ - if ((fd = open (file, access | O_NDELAY, mode)) == -1) - return -1; + if ((fd = open (file, access | O_NDELAY, mode)) == -1) + return -1; # ifdef FCNTL_LOCKING - buf.l_type = F_WRLCK; - buf.l_whence = SEEK_SET; - buf.l_start = 0; - buf.l_len = 0; - if (fcntl (fd, F_SETLK, &buf) != -1) - return fd; + buf.l_type = F_WRLCK; + buf.l_whence = SEEK_SET; + buf.l_start = 0; + buf.l_len = 0; + if (fcntl (fd, F_SETLK, &buf) != -1) + return fd; # endif # ifdef FLOCK_LOCKING - if (flock (fd, (((access & 03) == O_RDONLY) ? LOCK_SH : LOCK_EX) - | LOCK_NB) != -1) - return fd; + if (flock (fd, (((access & 03) == O_RDONLY) ? LOCK_SH : + LOCK_EX) | LOCK_NB) != -1) + return fd; # endif # ifdef LOCKF_LOCKING - if (lockf (fd, F_TLOCK, 0L) != -1) { - /* see if we should be at the end */ - if (j & O_APPEND) - lseek (fd, (off_t) 0, SEEK_END); - return fd; - } + if (lockf (fd, F_TLOCK, 0L) != -1) { + /* see if we should be at the end */ + if (j & O_APPEND) + lseek (fd, (off_t) 0, SEEK_END); + return fd; + } # endif - j = errno; - close (fd); - sleep (5); - } + j = errno; + close (fd); + sleep (5); + } - close (fd); - errno = j; - return -1; + close (fd); + errno = j; + return -1; } #endif /* KERNEL_LOCKING */ @@ -356,62 +355,61 @@ lkopen_kernel (char *file, int access, mode_t mode) static int lkopen_dot (char *file, int access, mode_t mode) { - int fd; - struct lockinfo lkinfo; + int fd; + struct lockinfo lkinfo; - /* open the file */ - if ((fd = open (file, access, mode)) == -1) - return -1; + /* open the file */ + if ((fd = open (file, access, mode)) == -1) + return -1; - /* - * Get the name of the eventual lock file, as well - * as a name for a temporary lock file. - */ - lockname (file, &lkinfo, 1); + /* + * Get the name of the eventual lock file, as well + * as a name for a temporary lock file. + */ + lockname (file, &lkinfo, 1); #if !defined(HAVE_LIBLOCKFILE) - { - int i; - for (i = 0;;) { - /* attempt to create lock file */ - if (lockit (&lkinfo) == 0) { - /* if successful, turn on timer and return */ - timerON (lkinfo.curlock, fd); - return fd; - } else { - /* - * Abort locking, if we fail to lock after 5 attempts - * and are never able to stat the lock file. - */ - struct stat st; - if (stat (lkinfo.curlock, &st) == -1) { - if (i++ > 5) - return -1; - sleep (5); - } else { - time_t curtime; - i = 0; - time (&curtime); - - /* check for stale lockfile, else sleep */ - if (curtime > st.st_ctime + RSECS) - unlink (lkinfo.curlock); - else - sleep (5); + { + int i; + for (i = 0;;) { + /* attempt to create lock file */ + if (lockit (&lkinfo) == 0) { + /* if successful, turn on timer and return */ + timerON (lkinfo.curlock, fd); + return fd; + } else { + /* + * Abort locking, if we fail to lock after 5 attempts + * and are never able to stat the lock file. + */ + struct stat st; + if (stat (lkinfo.curlock, &st) == -1) { + if (i++ > 5) + return -1; + sleep (5); + } else { + time_t curtime; + i = 0; + time (&curtime); + + /* check for stale lockfile, else sleep */ + if (curtime > st.st_ctime + RSECS) + unlink (lkinfo.curlock); + else + sleep (5); + } + lockname (file, &lkinfo, 1); + } } - lockname (file, &lkinfo, 1); - } } - } #else - if (lockfile_create(lkinfo.curlock, 5, 0) == L_SUCCESS) { - timerON(lkinfo.curlock, fd); - return fd; - } - else { - close(fd); - return -1; - } + if (lockfile_create(lkinfo.curlock, 5, 0) == L_SUCCESS) { + timerON(lkinfo.curlock, fd); + return fd; + } else { + close(fd); + return -1; + } #endif /* HAVE_LIBLOCKFILE */ } @@ -424,45 +422,45 @@ lkopen_dot (char *file, int access, mode_t mode) static int lockit (struct lockinfo *li) { - int fd; - char *curlock, *tmplock; + int fd; + char *curlock, *tmplock; #if 0 - char buffer[128]; + char buffer[128]; #endif - curlock = li->curlock; - tmplock = li->tmplock; + curlock = li->curlock; + tmplock = li->tmplock; #ifdef HAVE_MKSTEMP - if ((fd = mkstemp(tmplock)) == -1) - return -1; + if ((fd = mkstemp(tmplock)) == -1) + return -1; #else - if (mktemp(tmplock) == NULL) - return -1; - if (unlink(tmplock) == -1 && errno != ENOENT) - return -1; - /* create the temporary lock file */ - if ((fd = creat(tmplock, 0600)) == -1) - return -1; + if (mktemp(tmplock) == NULL) + return -1; + if (unlink(tmplock) == -1 && errno != ENOENT) + return -1; + /* create the temporary lock file */ + if ((fd = creat(tmplock, 0600)) == -1) + return -1; #endif #if 0 - /* write our process id into lock file */ - snprintf (buffer, sizeof(buffer), "nmh lock: pid %d\n", (int) getpid()); - write(fd, buffer, strlen(buffer) + 1); + /* write our process id into lock file */ + snprintf (buffer, sizeof(buffer), "nmh lock: pid %d\n", (int) getpid()); + write(fd, buffer, strlen(buffer) + 1); #endif - close (fd); + close (fd); - /* - * Now try to create the real lock file - * by linking to the temporary file. - */ - fd = link(tmplock, curlock); - unlink(tmplock); + /* + * Now try to create the real lock file + * by linking to the temporary file. + */ + fd = link(tmplock, curlock); + unlink(tmplock); - return (fd == -1 ? -1 : 0); + return (fd == -1 ? -1 : 0); } #endif /* HAVE_LIBLOCKFILE */ @@ -473,59 +471,59 @@ lockit (struct lockinfo *li) static void lockname (char *file, struct lockinfo *li, int isnewlock) { - int bplen, tmplen; - char *bp, *cp; + int bplen, tmplen; + char *bp, *cp; #if 0 - struct stat st; + struct stat st; #endif - if ((cp = strrchr (file, '/')) == NULL || *++cp == 0) - cp = file; + if ((cp = strrchr (file, '/')) == NULL || *++cp == 0) + cp = file; - bp = li->curlock; - bplen = 0; + bp = li->curlock; + bplen = 0; #ifdef LOCKDIR - snprintf (bp, sizeof(li->curlock), "%s/", lockdir); - tmplen = strlen (bp); - bp += tmplen; - bplen += tmplen; -#else - if (cp != file) { - snprintf (bp, sizeof(li->curlock), "%.*s", (int)(cp - file), file); + snprintf (bp, sizeof(li->curlock), "%s/", lockdir); tmplen = strlen (bp); - bp += tmplen; + bp += tmplen; bplen += tmplen; - } +#else + if (cp != file) { + snprintf (bp, sizeof(li->curlock), "%.*s", (int)(cp - file), file); + tmplen = strlen (bp); + bp += tmplen; + bplen += tmplen; + } #endif #if 0 - /* - * mmdf style dot locking. Currently not supported. - * If we start supporting mmdf style dot locking, - * we will need to change the return value of lockname - */ - if (stat (file, &st) == -1) - return -1; + /* + * mmdf style dot locking. Currently not supported. + * If we start supporting mmdf style dot locking, + * we will need to change the return value of lockname + */ + if (stat (file, &st) == -1) + return -1; - snprintf (bp, sizeof(li->curlock) - bplen, "LCK%05d.%05d", - st.st_dev, st.st_ino); + snprintf (bp, sizeof(li->curlock) - bplen, "LCK%05d.%05d", + st.st_dev, st.st_ino); #endif - snprintf (bp, sizeof(li->curlock) - bplen, "%s.lock", cp); + snprintf (bp, sizeof(li->curlock) - bplen, "%s.lock", cp); #if !defined(HAVE_LIBLOCKFILE) - /* - * If this is for a new lock, create a name for - * the temporary lock file for lockit() - */ - if (isnewlock) { - if ((cp = strrchr (li->curlock, '/')) == NULL || *++cp == 0) - strncpy (li->tmplock, ",LCK.XXXXXX", sizeof(li->tmplock)); - else - snprintf (li->tmplock, sizeof(li->tmplock), "%.*s,LCK.XXXXXX", - (int)(cp - li->curlock), li->curlock); - } + /* + * If this is for a new lock, create a name for + * the temporary lock file for lockit() + */ + if (isnewlock) { + if ((cp = strrchr (li->curlock, '/')) == NULL || *++cp == 0) + strncpy (li->tmplock, ",LCK.XXXXXX", sizeof(li->tmplock)); + else + snprintf (li->tmplock, sizeof(li->tmplock), "%.*s,LCK.XXXXXX", + (int)(cp - li->curlock), li->curlock); + } #endif } @@ -538,24 +536,24 @@ lockname (char *file, struct lockinfo *li, int isnewlock) static void timerON (char *curlock, int fd) { - struct lock *lp; - size_t len; + struct lock *lp; + size_t len; - lp = (struct lock *) mh_xmalloc (sizeof(*lp)); + lp = (struct lock *) mh_xmalloc (sizeof(*lp)); - len = strlen(curlock) + 1; - lp->l_fd = fd; - lp->l_lock = mh_xmalloc (len); - memcpy (lp->l_lock, curlock, len); - lp->l_next = l_top; + len = strlen(curlock) + 1; + lp->l_fd = fd; + lp->l_lock = mh_xmalloc (len); + memcpy (lp->l_lock, curlock, len); + lp->l_next = l_top; - if (!l_top) { - /* perhaps SIGT{STP,TIN,TOU} ? */ - SIGNAL (SIGALRM, alrmser); - alarm (NSECS); - } + if (!l_top) { + /* perhaps SIGT{STP,TIN,TOU} ? */ + SIGNAL (SIGALRM, alrmser); + alarm (NSECS); + } - l_top = lp; + l_top = lp; } @@ -567,29 +565,29 @@ timerON (char *curlock, int fd) static void timerOFF (int fd) { - struct lock *pp, *lp; + struct lock *pp, *lp; - alarm(0); + alarm(0); - if (l_top) { - for (pp = lp = l_top; lp; pp = lp, lp = lp->l_next) { - if (lp->l_fd == fd) - break; - } - if (lp) { - if (lp == l_top) - l_top = lp->l_next; - else - pp->l_next = lp->l_next; - - free (lp->l_lock); - free (lp); + if (l_top) { + for (pp = lp = l_top; lp; pp = lp, lp = lp->l_next) { + if (lp->l_fd == fd) + break; + } + if (lp) { + if (lp == l_top) + l_top = lp->l_next; + else + pp->l_next = lp->l_next; + + free (lp->l_lock); + free (lp); + } } - } - /* if there are locks left, restart timer */ - if (l_top) - alarm (NSECS); + /* if there are locks left, restart timer */ + if (l_top) + alarm (NSECS); } @@ -601,29 +599,29 @@ timerOFF (int fd) static RETSIGTYPE alrmser (int sig) { - char *lockfile; - struct lock *lp; + char *lockfile; + struct lock *lp; -#ifndef RELIABLE_SIGNALS - SIGNAL (SIGALRM, alrmser); +#ifndef RELIABLE_SIGNALS + SIGNAL (SIGALRM, alrmser); #endif - /* update the ctime of all the lock files */ - for (lp = l_top; lp; lp = lp->l_next) { - lockfile = lp->l_lock; + /* update the ctime of all the lock files */ + for (lp = l_top; lp; lp = lp->l_next) { + lockfile = lp->l_lock; #if !defined(HAVE_LIBLOCKFILE) - { - int j; - if (*lockfile && (j = creat (lockfile, 0600)) != -1) - close (j); - } + { + int j; + if (*lockfile && (j = creat (lockfile, 0600)) != -1) + close (j); + } #else - lockfile_touch(lockfile); + lockfile_touch(lockfile); #endif - } + } - /* restart the alarm */ - alarm (NSECS); + /* restart the alarm */ + alarm (NSECS); } #endif /* DOT_LOCKING */ diff --git a/sbr/m_atoi.c b/sbr/m_atoi.c index 174c407..21606c4 100644 --- a/sbr/m_atoi.c +++ b/sbr/m_atoi.c @@ -1,4 +1,3 @@ - /* * m_atoi.c -- Parse a string representation of a message number, and * -- return the numeric value of the message. If the string @@ -15,20 +14,20 @@ int m_atoi (char *str) { - int i; - unsigned char *cp; + int i; + unsigned char *cp; - for (i = 0, cp = str; *cp; cp++) { + for (i = 0, cp = str; *cp; cp++) { #ifdef LOCALE - if (!isdigit(*cp)) + if (!isdigit(*cp)) #else - if (*cp < '0' || *cp > '9') + if (*cp < '0' || *cp > '9') #endif - return 0; + return 0; - i *= 10; - i += (*cp - '0'); - } + i *= 10; + i += (*cp - '0'); + } - return i; + return i; } diff --git a/sbr/m_backup.c b/sbr/m_backup.c index 4159850..1b219a2 100644 --- a/sbr/m_backup.c +++ b/sbr/m_backup.c @@ -1,4 +1,3 @@ - /* * m_backup.c -- construct a backup file * @@ -13,16 +12,15 @@ char * m_backup (char *file) { - char *cp; - static char buffer[BUFSIZ]; + char *cp; + static char buffer[BUFSIZ]; - if ((cp = r1bindex(file, '/')) == file) - snprintf(buffer, sizeof(buffer), "%s%s", - backup_prefix, cp); - else - snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file, - backup_prefix, cp); + if ((cp = r1bindex(file, '/')) == file) + snprintf(buffer, sizeof(buffer), "%s%s", backup_prefix, cp); + else + snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), + file, backup_prefix, cp); - unlink(buffer); - return buffer; + unlink(buffer); + return buffer; } diff --git a/sbr/m_convert.c b/sbr/m_convert.c index 1696190..ee9ba5b 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -1,4 +1,3 @@ - /* * m_convert.c -- parse a message range or sequence and set SELECTED * @@ -13,18 +12,18 @@ * error codes for sequence * and message range processing */ -#define BADMSG (-2) -#define BADRNG (-3) -#define BADNEW (-4) -#define BADNUM (-5) -#define BADLST (-6) +#define BADMSG (-2) +#define BADRNG (-3) +#define BADNEW (-4) +#define BADNUM (-5) +#define BADLST (-6) -#define FIRST 1 -#define LAST 2 +#define FIRST 1 +#define LAST 2 -#define getnew(mp) (mp->hghmsg + 1) +#define getnew(mp) (mp->hghmsg + 1) -static int convdir; /* convert direction */ +static int convdir; /* convert direction */ static char *delimp; /* @@ -37,275 +36,272 @@ static int attr (struct msgs *, char *); int m_convert (struct msgs *mp, char *name) { - int first, last, found, range, err; - unsigned char *bp; - char *cp; - - /* check if user defined sequence */ - err = attr (mp, cp = name); - - if (err == -1) - return 0; - else if (err < 0) - goto badmsg; - else if (err > 0) - return 1; - /* - * else err == 0, so continue - */ - - found = 0; - - /* - * Check for special "new" sequence, which - * is valid only if ALLOW_NEW is set. - */ - if ((mp->msgflags & ALLOW_NEW) && !strcmp (cp, "new")) { - if ((err = first = getnew (mp)) <= 0) - goto badmsg; - else - goto single; - } - - if (!strcmp (cp, "all")) - cp = "first-last"; - - if ((err = first = m_conv (mp, cp, FIRST)) <= 0) - goto badmsg; - - cp = delimp; - if (*cp != '\0' && *cp != '-' && *cp != ':') { -badelim: - advise (NULL, "illegal argument delimiter: `%c'(0%o)", *delimp, *delimp); - return 0; - } + int first, last, found, range, err; + unsigned char *bp; + char *cp; - if (*cp == '-') { - cp++; - if ((err = last = m_conv (mp, cp, LAST)) <= 0) { -badmsg: - switch (err) { - case BADMSG: - advise (NULL, "no %s message", cp); - break; + /* check if user defined sequence */ + err = attr (mp, cp = name); + + if (err == -1) + return 0; + else if (err < 0) + goto badmsg; + else if (err > 0) + return 1; + /* + * else err == 0, so continue + */ - case BADNUM: - advise (NULL, "message %s doesn't exist", cp); - break; + found = 0; - case BADRNG: - advise (NULL, "message %s out of range 1-%d", cp, mp->hghmsg); - break; + /* + * Check for special "new" sequence, which + * is valid only if ALLOW_NEW is set. + */ + if ((mp->msgflags & ALLOW_NEW) && !strcmp (cp, "new")) { + if ((err = first = getnew (mp)) <= 0) + goto badmsg; + else + goto single; + } - case BADLST: -badlist: - advise (NULL, "bad message list %s", name); - break; + if (!strcmp (cp, "all")) + cp = "first-last"; - case BADNEW: - advise (NULL, "folder full, no %s message", name); - break; + if ((err = first = m_conv (mp, cp, FIRST)) <= 0) + goto badmsg; - default: - advise (NULL, "no messages match specification"); - } - return 0; + cp = delimp; + if (*cp != '\0' && *cp != '-' && *cp != ':') { +badelim: + advise (NULL, "illegal argument delimiter: `%c'(0%o)", *delimp, *delimp); + return 0; } - if (last < first) - goto badlist; - if (*delimp) - goto badelim; - if (first > mp->hghmsg || last < mp->lowmsg) { + if (*cp == '-') { + cp++; + if ((err = last = m_conv (mp, cp, LAST)) <= 0) { +badmsg: + switch (err) { + case BADMSG: + advise (NULL, "no %s message", cp); + break; + + case BADNUM: + advise (NULL, "message %s doesn't exist", cp); + break; + + case BADRNG: + advise (NULL, "message %s out of range 1-%d", cp, mp->hghmsg); + break; + + case BADLST: +badlist: + advise (NULL, "bad message list %s", name); + break; + + case BADNEW: + advise (NULL, "folder full, no %s message", name); + break; + + default: + advise (NULL, "no messages match specification"); + } + return 0; + } + + if (last < first) + goto badlist; + if (*delimp) + goto badelim; + if (first > mp->hghmsg || last < mp->lowmsg) { rangerr: - advise (NULL, "no messages in range %s", name); - return 0; - } + advise (NULL, "no messages in range %s", name); + return 0; + } - /* tighten the range to search */ - if (last > mp->hghmsg) - last = mp->hghmsg; - if (first < mp->lowmsg) - first = mp->lowmsg; + /* tighten the range to search */ + if (last > mp->hghmsg) + last = mp->hghmsg; + if (first < mp->lowmsg) + first = mp->lowmsg; - } else if (*cp == ':') { - cp++; - if (*cp == '-') { - convdir = -1; - cp++; - } else { - if (*cp == '+') { - convdir = 1; + } else if (*cp == ':') { cp++; - } - } - if ((range = atoi (bp = cp)) == 0) - goto badlist; - while (isdigit (*bp)) - bp++; - if (*bp) - goto badelim; - if ((convdir > 0 && first > mp->hghmsg) - || (convdir < 0 && first < mp->lowmsg)) - goto rangerr; - - /* tighten the range to search */ - if (first < mp->lowmsg) - first = mp->lowmsg; - if (first > mp->hghmsg) - first = mp->hghmsg; - - for (last = first; - last >= mp->lowmsg && last <= mp->hghmsg; - last += convdir) - if (does_exist (mp, last)) - if (--range <= 0) - break; - if (last < mp->lowmsg) - last = mp->lowmsg; - if (last > mp->hghmsg) - last = mp->hghmsg; - if (last < first) { - range = last; - last = first; - first = range; - } - } else { + if (*cp == '-') { + convdir = -1; + cp++; + } else if (*cp == '+') { + convdir = 1; + cp++; + } + if ((range = atoi (bp = cp)) == 0) + goto badlist; + while (isdigit (*bp)) + bp++; + if (*bp) + goto badelim; + if ((convdir > 0 && first > mp->hghmsg) + || (convdir < 0 && first < mp->lowmsg)) + goto rangerr; + + /* tighten the range to search */ + if (first < mp->lowmsg) + first = mp->lowmsg; + if (first > mp->hghmsg) + first = mp->hghmsg; + + for (last = first; last >= mp->lowmsg && last <= mp->hghmsg; + last += convdir) + if (does_exist (mp, last)) + if (--range <= 0) + break; + if (last < mp->lowmsg) + last = mp->lowmsg; + if (last > mp->hghmsg) + last = mp->hghmsg; + if (last < first) { + range = last; + last = first; + first = range; + } + } else { single: + /* + * Single Message + * + * If ALLOW_NEW is set, then allow selecting of an + * empty slot. If ALLOW_NEW is not set, then we + * check if message is in-range and exists. + */ + if (mp->msgflags & ALLOW_NEW) { + set_select_empty (mp, first); + } else { + if (first > mp->hghmsg + || first < mp->lowmsg + || !(does_exist (mp, first))) { + if (!strcmp (name, "cur") || !strcmp (name, ".")) + advise (NULL, "no %s message", name); + else + advise (NULL, "message %d doesn't exist", first); + return 0; + } + } + last = first; /* range of 1 */ + } + /* - * Single Message - * - * If ALLOW_NEW is set, then allow selecting of an - * empty slot. If ALLOW_NEW is not set, then we - * check if message is in-range and exists. + * Cycle through the range and select the messages + * that exist. If ALLOW_NEW is set, then we also check + * if we are selecting an empty slot. */ - if (mp->msgflags & ALLOW_NEW) { - set_select_empty (mp, first); - } else { - if (first > mp->hghmsg - || first < mp->lowmsg - || !(does_exist (mp, first))) { - if (!strcmp (name, "cur") || !strcmp (name, ".")) - advise (NULL, "no %s message", name); - else - advise (NULL, "message %d doesn't exist", first); - return 0; - } - } - last = first; /* range of 1 */ - } - - /* - * Cycle through the range and select the messages - * that exist. If ALLOW_NEW is set, then we also check - * if we are selecting an empty slot. - */ - for (; first <= last; first++) { - if (does_exist (mp, first) || - ((mp->msgflags & ALLOW_NEW) && is_select_empty (mp, first))) { - if (!is_selected (mp, first)) { - set_selected (mp, first); - mp->numsel++; - if (mp->lowsel == 0 || first < mp->lowsel) - mp->lowsel = first; - if (first > mp->hghsel) - mp->hghsel = first; - } - found++; + for (; first <= last; first++) { + if (does_exist (mp, first) || + ((mp->msgflags & ALLOW_NEW) && is_select_empty (mp, first))) { + if (!is_selected (mp, first)) { + set_selected (mp, first); + mp->numsel++; + if (mp->lowsel == 0 || first < mp->lowsel) + mp->lowsel = first; + if (first > mp->hghsel) + mp->hghsel = first; + } + found++; + } } - } - if (!found) - goto rangerr; + if (!found) + goto rangerr; - return 1; + return 1; } /* * Convert the various message names to * their numeric values. * - * n (integer) + * n (integer) * prev * next * first * last * cur - * . (same as cur) + * . (same as cur) */ static int m_conv (struct msgs *mp, char *str, int call) { - register int i; - register unsigned char *cp, *bp; - unsigned char buf[16]; - - convdir = 1; - cp = bp = str; - if (isdigit (*cp)) { - while (isdigit (*bp)) - bp++; - delimp = bp; - i = atoi (cp); - - if (i <= mp->hghmsg) - return i; - else if (*delimp || call == LAST) - return mp->hghmsg + 1; - else if (mp->msgflags & ALLOW_NEW) - return BADRNG; - else - return BADNUM; - } + register int i; + register unsigned char *cp, *bp; + unsigned char buf[16]; + + convdir = 1; + cp = bp = str; + if (isdigit (*cp)) { + while (isdigit (*bp)) + bp++; + delimp = bp; + i = atoi (cp); + + if (i <= mp->hghmsg) + return i; + else if (*delimp || call == LAST) + return mp->hghmsg + 1; + else if (mp->msgflags & ALLOW_NEW) + return BADRNG; + else + return BADNUM; + } #ifdef LOCALE - /* doesn't enforce lower case */ - for (bp = buf; (isalpha(*cp) || *cp == '.') - && (bp - buf < sizeof(buf) - 1); ) + /* doesn't enforce lower case */ + for (bp = buf; (isalpha(*cp) || *cp == '.') + && (bp - buf < sizeof(buf) - 1); ) #else - for (bp = buf; ((*cp >= 'a' && *cp <= 'z') || *cp == '.') - && (bp - buf < sizeof(buf) - 1); ) + for (bp = buf; ((*cp >= 'a' && *cp <= 'z') || *cp == '.') + && (bp - buf < sizeof(buf) - 1); ) #endif /* LOCALE */ - { - *bp++ = *cp++; - } - *bp++ = '\0'; - delimp = cp; - - if (!strcmp (buf, "first")) - return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) - ? mp->lowmsg : BADMSG); - - if (!strcmp (buf, "last")) { - convdir = -1; - return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG); - } - - if (!strcmp (buf, "cur") || !strcmp (buf, ".")) - return (mp->curmsg > 0 ? mp->curmsg : BADMSG); - - if (!strcmp (buf, "prev")) { - convdir = -1; - for (i = (mp->curmsg <= mp->hghmsg) ? mp->curmsg - 1 : mp->hghmsg; - i >= mp->lowmsg; i--) { - if (does_exist (mp, i)) - return i; + { + *bp++ = *cp++; + } + *bp++ = '\0'; + delimp = cp; + + if (!strcmp (buf, "first")) + return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) + ? mp->lowmsg : BADMSG); + + if (!strcmp (buf, "last")) { + convdir = -1; + return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG); + } + + if (!strcmp (buf, "cur") || !strcmp (buf, ".")) + return (mp->curmsg > 0 ? mp->curmsg : BADMSG); + + if (!strcmp (buf, "prev")) { + convdir = -1; + for (i = (mp->curmsg <= mp->hghmsg) ? mp->curmsg - 1 : mp->hghmsg; + i >= mp->lowmsg; i--) { + if (does_exist (mp, i)) + return i; + } + return BADMSG; } - return BADMSG; - } - - if (!strcmp (buf, "next")) { - for (i = (mp->curmsg >= mp->lowmsg) ? mp->curmsg + 1 : mp->lowmsg; - i <= mp->hghmsg; i++) { - if (does_exist (mp, i)) - return i; + + if (!strcmp (buf, "next")) { + for (i = (mp->curmsg >= mp->lowmsg) ? mp->curmsg + 1 : mp->lowmsg; + i <= mp->hghmsg; i++) { + if (does_exist (mp, i)) + return i; + } + return BADMSG; } - return BADMSG; - } - return BADLST; + return BADLST; } /* @@ -325,122 +321,116 @@ m_conv (struct msgs *mp, char *str, int call) static int attr (struct msgs *mp, char *cp) { - register unsigned char *dp; - char *bp = NULL; - register int i, j; - int found, - inverted = 0, - range = 0, /* no range */ - first = 0; - - /* hack for "cur-name", "cur-n", etc. */ - if (!strcmp (cp, "cur")) - return 0; - if (ssequal ("cur:", cp)) /* this code need to be rewritten... */ - return 0; - - /* Check for sequence negation */ - if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) { - inverted = 1; - cp += strlen (dp); - } - - convdir = 1; /* convert direction */ - - for (dp = cp; *dp && isalnum(*dp); dp++) - continue; - - if (*dp == ':') { - bp = dp++; - range = 1; + register unsigned char *dp; + char *bp = NULL; + register int i, j; + int found; + int inverted = 0; + int range = 0; /* no range */ + int first = 0; + + /* hack for "cur-name", "cur-n", etc. */ + if (!strcmp (cp, "cur")) + return 0; + if (ssequal ("cur:", cp)) /* this code need to be rewritten... */ + return 0; - /* - * seq:prev (or) - * seq:next (or) - * seq:first (or) - * seq:last - */ - if (isalpha (*dp)) { - if (!strcmp (dp, "prev")) { - convdir = -1; - first = (mp->curmsg > 0) && (mp->curmsg <= mp->hghmsg) - ? mp->curmsg - 1 - : mp->hghmsg; - } - else if (!strcmp (dp, "next")) { - convdir = 1; - first = (mp->curmsg >= mp->lowmsg) - ? mp->curmsg + 1 - : mp->lowmsg; - } - else if (!strcmp (dp, "first")) { - convdir = 1; - } - else if (!strcmp (dp, "last")) { - convdir = -1; - } - else - return BADLST; - } else { - /* - * seq:n (or) - * seq:+n (or) - * seq:-n - */ - if (*dp == '+') - dp++; - else if (*dp == '-') { - dp++; - convdir = -1; - } - if ((range = atoi(dp)) == 0) - return BADLST; - while (isdigit (*dp)) - dp++; - if (*dp) - return BADLST; + /* Check for sequence negation */ + if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) { + inverted = 1; + cp += strlen (dp); } - *bp = '\0'; /* temporarily terminate sequence name */ - } + convdir = 1; /* convert direction */ + + for (dp = cp; *dp && isalnum(*dp); dp++) + continue; + + if (*dp == ':') { + bp = dp++; + range = 1; + + /* + * seq:prev (or) + * seq:next (or) + * seq:first (or) + * seq:last + */ + if (isalpha (*dp)) { + if (!strcmp (dp, "prev")) { + convdir = -1; + first = (mp->curmsg > 0) && (mp->curmsg <= mp->hghmsg) + ? mp->curmsg - 1 : mp->hghmsg; + } else if (!strcmp (dp, "next")) { + convdir = 1; + first = (mp->curmsg >= mp->lowmsg) + ? mp->curmsg + 1 : mp->lowmsg; + } else if (!strcmp (dp, "first")) { + convdir = 1; + } else if (!strcmp (dp, "last")) { + convdir = -1; + } else + return BADLST; + } else { + /* + * seq:n (or) + * seq:+n (or) + * seq:-n + */ + if (*dp == '+') + dp++; + else if (*dp == '-') { + dp++; + convdir = -1; + } + if ((range = atoi(dp)) == 0) + return BADLST; + while (isdigit (*dp)) + dp++; + if (*dp) + return BADLST; + } + + *bp = '\0'; /* temporarily terminate sequence name */ + } - i = seq_getnum (mp, cp); /* get index of sequence */ + i = seq_getnum (mp, cp); /* get index of sequence */ - if (bp) - *bp = ':'; /* restore sequence name */ - if (i == -1) - return 0; + if (bp) + *bp = ':'; /* restore sequence name */ + if (i == -1) + return 0; - found = 0; /* count the number we select for this argument */ + found = 0; /* count the number we select for this argument */ - for (j = first ? first : (convdir > 0) ? mp->lowmsg : mp->hghmsg; + for (j = first ? first : (convdir > 0) ? mp->lowmsg : mp->hghmsg; j >= mp->lowmsg && j <= mp->hghmsg; j += convdir) { - if (does_exist (mp, j) - && inverted ? !in_sequence (mp, i, j) : in_sequence (mp, i, j)) { - if (!is_selected (mp, j)) { - set_selected (mp, j); - mp->numsel++; - if (mp->lowsel == 0 || j < mp->lowsel) - mp->lowsel = j; - if (j > mp->hghsel) - mp->hghsel = j; - } - found++; - - /* - * If we have a range, then break out - * once we've found enough. - */ - if (range && found >= range) - break; + if (does_exist (mp, j) + && inverted ? !in_sequence (mp, i, j) : in_sequence (mp, i, j)) { + if (!is_selected (mp, j)) { + set_selected (mp, j); + mp->numsel++; + if (mp->lowsel == 0 || j < mp->lowsel) + mp->lowsel = j; + if (j > mp->hghsel) + mp->hghsel = j; + } + found++; + + /* + * If we have a range, then break out + * once we've found enough. + */ + if (range && found >= range) + break; + } } - } - if (found > 0) - return found; + if (found > 0) + return found; - if (first) - return BADMSG; - advise (NULL, "sequence %s %s", cp, inverted ? "full" : "empty"); - return -1; + if (first) + return BADMSG; + advise (NULL, "sequence %s %s", cp, inverted ? "full" : "empty"); + return -1; } diff --git a/sbr/m_draft.c b/sbr/m_draft.c index e479186..ceee73a 100644 --- a/sbr/m_draft.c +++ b/sbr/m_draft.c @@ -1,4 +1,3 @@ - /* * m_draft.c -- construct the name of a draft message * @@ -15,66 +14,66 @@ char * m_draft (char *folder, char *msg, int use, int *isdf) { - register char *cp; - register struct msgs *mp; - static char buffer[BUFSIZ]; + register char *cp; + register struct msgs *mp; + static char buffer[BUFSIZ]; - if (*isdf == -1 || folder == NULL || *folder == '\0') { - if (*isdf == -1 || (cp = context_find ("Draft-Folder")) == NULL) { - *isdf = 0; - return m_maildir (msg && *msg ? msg : draft); - } else { - folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); + if (*isdf == -1 || folder == NULL || *folder == '\0') { + if (*isdf == -1 || (cp = context_find ("Draft-Folder")) == NULL) { + *isdf = 0; + return m_maildir (msg && *msg ? msg : draft); + } else { + folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + } } - } - *isdf = 1; - - chdir (m_maildir ("")); - strncpy (buffer, m_maildir (folder), sizeof(buffer)); + *isdf = 1; + + chdir (m_maildir ("")); + strncpy (buffer, m_maildir (folder), sizeof(buffer)); - create_folder (buffer, 0, done); + create_folder (buffer, 0, done); - if (chdir (buffer) == -1) - adios (buffer, "unable to change directory to"); + if (chdir (buffer) == -1) + adios (buffer, "unable to change directory to"); - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); - /* - * Make sure we have enough message status space for all - * the message numbers from 1 to "new", since we might - * select an empty slot. If we add more space at the - * end, go ahead and add 10 additional slots. - */ - if (mp->hghmsg >= mp->hghoff) { - if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10))) - adios (NULL, "unable to allocate folder storage"); - } else if (mp->lowoff > 1) { - if (!(mp = folder_realloc (mp, 1, mp->hghoff))) - adios (NULL, "unable to allocate folder storage"); - } + /* + * Make sure we have enough message status space for all + * the message numbers from 1 to "new", since we might + * select an empty slot. If we add more space at the + * end, go ahead and add 10 additional slots. + */ + if (mp->hghmsg >= mp->hghoff) { + if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10))) + adios (NULL, "unable to allocate folder storage"); + } else if (mp->lowoff > 1) { + if (!(mp = folder_realloc (mp, 1, mp->hghoff))) + adios (NULL, "unable to allocate folder storage"); + } - mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */ + mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */ - /* - * If we have been give a valid message name, then use that. - * Else, if we are given the "use" option, then use the - * current message. Else, use special sequence "new". - */ - if (!m_convert (mp, msg && *msg ? msg : use ? "cur" : "new")) - done (1); - seq_setprev (mp); + /* + * If we have been give a valid message name, then use that. + * Else, if we are given the "use" option, then use the + * current message. Else, use special sequence "new". + */ + if (!m_convert (mp, msg && *msg ? msg : use ? "cur" : "new")) + done (1); + seq_setprev (mp); - if (mp->numsel > 1) - adios (NULL, "only one message draft at a time!"); + if (mp->numsel > 1) + adios (NULL, "only one message draft at a time!"); - snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, m_name (mp->lowsel)); - cp = buffer; + snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, m_name (mp->lowsel)); + cp = buffer; - seq_setcur (mp, mp->lowsel);/* set current message for folder */ - seq_save (mp); /* synchronize message sequences */ - folder_free (mp); /* free folder/message structure */ + seq_setcur (mp, mp->lowsel);/* set current message for folder */ + seq_save (mp); /* synchronize message sequences */ + folder_free (mp); /* free folder/message structure */ - return cp; + return cp; } diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 42bb72f..97b2466 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -1,4 +1,3 @@ - /* * m_getfld.c -- read/parse a message * @@ -19,7 +18,7 @@ caused the old version of m_getfld() to declare eom prematurely. The fix was a lot slower than - c == '\001' && peekc (iob) == '\001' + c == '\001' && peekc (iob) == '\001' but it worked, and to increase generality, MBOX style maildrops could be parsed as well. Unfortunately the speed issue finally caught up with @@ -42,8 +41,8 @@ This worked fine, until one day: a message with no body portion arrived. Then the - while (eom (c = Getc (iob), iob)) - continue; + while (eom (c = Getc (iob), iob)) + continue; loop caused m_getfld() to return FMTERR. So, that logic was changed to check for (*eom_action) and act accordingly. @@ -128,7 +127,7 @@ it knows that _filbuf ignores the _ptr & _cnt and simply fills the buffer. If stdio on your system doesn't work this way, you may have to make small changes in this routine. - + This routine also "knows" that an EOF indication on a stream is "sticky" (i.e., you will keep getting EOF until you reposition the stream). If your system doesn't work this way it is broken and you @@ -145,10 +144,10 @@ static int m_Eom (int, FILE *); static unsigned char *matchc(int, char *, int, char *); static unsigned char *locc(int, unsigned char *, unsigned char); -#define Getc(iob) getc(iob) -#define eom(c,iob) (msg_style != MS_DEFAULT && \ - (((c) == *msg_delim && m_Eom(c,iob)) ||\ - (eom_action && (*eom_action)(c)))) +#define Getc(iob) getc(iob) +#define eom(c,iob) (msg_style != MS_DEFAULT && \ + (((c) == *msg_delim && m_Eom(c,iob)) ||\ + (eom_action && (*eom_action)(c)))) static unsigned char **pat_map; @@ -177,7 +176,7 @@ extern int msg_style; * is used in m_Eom because the first character of the string * has been read and matched before m_Eom is called. */ -extern char *msg_delim; /* defined in sbr/m_msgdef.c = "" */ +extern char *msg_delim; /* defined in sbr/m_msgdef.c = "" */ static unsigned char *fdelim; static unsigned char *delimend; static int fdelimlen; @@ -187,9 +186,9 @@ static int edelimlen; static int (*eom_action)(int) = NULL; #ifdef _FSTDIO -# define _ptr _p /* Gag */ -# define _cnt _r /* Retch */ -# define _filbuf __srget /* Puke */ +# define _ptr _p /* Gag */ +# define _cnt _r /* Retch */ +# define _filbuf __srget /* Puke */ # define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC #endif @@ -208,380 +207,380 @@ extern int _filbuf(FILE*); int m_getfld (int state, unsigned char *name, unsigned char *buf, - int bufsz, FILE *iob) + int bufsz, FILE *iob) { - register unsigned char *bp, *cp, *ep, *sp; - register int cnt, c, i, j; - - if ((c = Getc(iob)) < 0) { - msg_count = 0; - *buf = 0; - return FILEEOF; - } - if (eom (c, iob)) { - if (! eom_action) { - /* flush null messages */ - while ((c = Getc(iob)) >= 0 && eom (c, iob)) - ; - if (c >= 0) - ungetc(c, iob); + register unsigned char *bp, *cp, *ep, *sp; + register int cnt, c, i, j; + + if ((c = Getc(iob)) < 0) { + msg_count = 0; + *buf = 0; + return FILEEOF; } - msg_count = 0; - *buf = 0; - return FILEEOF; - } - - switch (state) { - case FLDEOF: - case BODYEOF: - case FLD: - if (c == '\n' || c == '-') { - /* we hit the header/body separator */ - while (c != '\n' && (c = Getc(iob)) >= 0) - ; - - if (c < 0 || (c = Getc(iob)) < 0 || eom (c, iob)) { - if (! eom_action) { + if (eom (c, iob)) { + if (! eom_action) { /* flush null messages */ while ((c = Getc(iob)) >= 0 && eom (c, iob)) - ; + ; if (c >= 0) - ungetc(c, iob); - } - msg_count = 0; - *buf = 0; - return FILEEOF; + ungetc(c, iob); } - state = BODY; - goto body; - } - /* - * get the name of this component. take characters up - * to a ':', a newline or NAMESZ-1 characters, whichever - * comes first. - */ - cp = name; - i = NAMESZ - 1; - for (;;) { + msg_count = 0; + *buf = 0; + return FILEEOF; + } + + switch (state) { + case FLDEOF: + case BODYEOF: + case FLD: + if (c == '\n' || c == '-') { + /* we hit the header/body separator */ + while (c != '\n' && (c = Getc(iob)) >= 0) + ; + + if (c < 0 || (c = Getc(iob)) < 0 || eom (c, iob)) { + if (! eom_action) { + /* flush null messages */ + while ((c = Getc(iob)) >= 0 && eom (c, iob)) + ; + if (c >= 0) + ungetc(c, iob); + } + msg_count = 0; + *buf = 0; + return FILEEOF; + } + state = BODY; + goto body; + } + /* + * get the name of this component. take characters up + * to a ':', a newline or NAMESZ-1 characters, + * whichever comes first. + */ + cp = name; + i = NAMESZ - 1; + for (;;) { #ifdef LINUX_STDIO - bp = sp = (unsigned char *) iob->_IO_read_ptr - 1; - j = (cnt = ((long) iob->_IO_read_end - - (long) iob->_IO_read_ptr) + 1) < i ? cnt : i; + bp = sp = (unsigned char *) iob->_IO_read_ptr - 1; + j = (cnt = ((long) iob->_IO_read_end - + (long) iob->_IO_read_ptr) + 1) < i ? cnt : i; #elif defined(__DragonFly__) - bp = sp = (unsigned char *) ((struct __FILE_public *)iob)->_p - 1; - j = (cnt = ((struct __FILE_public *)iob)->_r+1) < i ? cnt : i; + bp = sp = (unsigned char *) ((struct __FILE_public *)iob)->_p - 1; + j = (cnt = ((struct __FILE_public *)iob)->_r+1) < i ? cnt : i; #else - bp = sp = (unsigned char *) iob->_ptr - 1; - j = (cnt = iob->_cnt+1) < i ? cnt : i; + bp = sp = (unsigned char *) iob->_ptr - 1; + j = (cnt = iob->_cnt+1) < i ? cnt : i; #endif - while (--j >= 0 && (c = *bp++) != ':' && c != '\n') - *cp++ = c; + while (--j >= 0 && (c = *bp++) != ':' && c != '\n') + *cp++ = c; - j = bp - sp; - if ((cnt -= j) <= 0) { + j = bp - sp; + if ((cnt -= j) <= 0) { #ifdef LINUX_STDIO - iob->_IO_read_ptr = iob->_IO_read_end; - if (__underflow(iob) == EOF) { + iob->_IO_read_ptr = iob->_IO_read_end; + if (__underflow(iob) == EOF) { #elif defined(__DragonFly__) - if (__srget(iob) == EOF) { + if (__srget(iob) == EOF) { #else - if (_filbuf(iob) == EOF) { + if (_filbuf(iob) == EOF) { #endif - *cp = *buf = 0; - advise (NULL, "eof encountered in field \"%s\"", name); - return FMTERR; - } + *cp = *buf = 0; + advise (NULL, "eof encountered in field \"%s\"", name); + return FMTERR; + } #ifdef LINUX_STDIO - iob->_IO_read_ptr++; /* NOT automatic in __underflow()! */ + iob->_IO_read_ptr++; /* NOT automatic in __underflow()! */ #endif - } else { + } else { #ifdef LINUX_STDIO - iob->_IO_read_ptr = bp + 1; + iob->_IO_read_ptr = bp + 1; #elif defined(__DragonFly__) - ((struct __FILE_public *)iob)->_p = bp + 1; - ((struct __FILE_public *)iob)->_r = cnt - 1; + ((struct __FILE_public *)iob)->_p = bp + 1; + ((struct __FILE_public *)iob)->_r = cnt - 1; #else - iob->_ptr = bp + 1; - iob->_cnt = cnt - 1; + iob->_ptr = bp + 1; + iob->_cnt = cnt - 1; #endif - } - if (c == ':') - break; - - /* - * something went wrong. possibilities are: - * . hit a newline (error) - * . got more than namesz chars. (error) - * . hit the end of the buffer. (loop) - */ - if (c == '\n') { - /* We hit the end of the line without seeing ':' to - * terminate the field name. This is usually (always?) - * spam. But, blowing up is lame, especially when - * scan(1)ing a folder with such messages. Pretend such - * lines are the first of the body (at least mutt also - * handles it this way). */ - - /* See if buf can hold this line, since we were assuming - * we had a buffer of NAMESZ, not bufsz. */ - /* + 1 for the newline */ - if (bufsz < j + 1) { - /* No, it can't. Oh well, guess we'll blow up. */ - *cp = *buf = 0; - advise (NULL, "eol encountered in field \"%s\"", name); - state = FMTERR; - goto finish; - } - memcpy (buf, name, j - 1); - buf[j - 1] = '\n'; - buf[j] = '\0'; - /* mhparse.c:get_content wants to find the position of the - * body start, but it thinks there's a blank line between - * the header and the body (naturally!), so seek back so - * that things line up even though we don't have that - * blank line in this case. Simpler parsers (e.g. mhl) - * get extra newlines, but that should be harmless enough, - * right? This is a corrupt message anyway. */ - fseek (iob, ftell (iob) - 2, SEEK_SET); - return BODY; - } - if ((i -= j) <= 0) { - *cp = *buf = 0; - advise (NULL, "field name \"%s\" exceeds %d bytes", name, NAMESZ - 2); - state = LENERR; - goto finish; - } - } + } + if (c == ':') + break; - while (isspace (*--cp) && cp >= name) - ; - *++cp = 0; - /* fall through */ - - case FLDPLUS: - /* - * get (more of) the text of a field. take - * characters up to the end of this field (newline - * followed by non-blank) or bufsz-1 characters. - */ - cp = buf; i = bufsz-1; - for (;;) { + /* + * something went wrong. possibilities are: + * . hit a newline (error) + * . got more than namesz chars. (error) + * . hit the end of the buffer. (loop) + */ + if (c == '\n') { + /* We hit the end of the line without seeing ':' to + * terminate the field name. This is usually (always?) + * spam. But, blowing up is lame, especially when + * scan(1)ing a folder with such messages. Pretend such + * lines are the first of the body (at least mutt also + * handles it this way). */ + + /* See if buf can hold this line, since we were assuming + * we had a buffer of NAMESZ, not bufsz. */ + /* + 1 for the newline */ + if (bufsz < j + 1) { + /* No, it can't. Oh well, guess we'll blow up. */ + *cp = *buf = 0; + advise (NULL, "eol encountered in field \"%s\"", name); + state = FMTERR; + goto finish; + } + memcpy (buf, name, j - 1); + buf[j - 1] = '\n'; + buf[j] = '\0'; + /* mhparse.c:get_content wants to find the position of the + * body start, but it thinks there's a blank line between + * the header and the body (naturally!), so seek back so + * that things line up even though we don't have that + * blank line in this case. Simpler parsers (e.g. mhl) + * get extra newlines, but that should be harmless enough, + * right? This is a corrupt message anyway. */ + fseek (iob, ftell (iob) - 2, SEEK_SET); + return BODY; + } + if ((i -= j) <= 0) { + *cp = *buf = 0; + advise (NULL, "field name \"%s\" exceeds %d bytes", name, NAMESZ - 2); + state = LENERR; + goto finish; + } + } + + while (isspace (*--cp) && cp >= name) + ; + *++cp = 0; + /* fall through */ + + case FLDPLUS: + /* + * get (more of) the text of a field. take + * characters up to the end of this field (newline + * followed by non-blank) or bufsz-1 characters. + */ + cp = buf; i = bufsz-1; + for (;;) { #ifdef LINUX_STDIO - cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; - bp = (unsigned char *) --iob->_IO_read_ptr; + cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; + bp = (unsigned char *) --iob->_IO_read_ptr; #elif defined(__DragonFly__) - cnt = ((struct __FILE_public *)iob)->_r++; - bp = (unsigned char *) --((struct __FILE_public *)iob)->_p; + cnt = ((struct __FILE_public *)iob)->_r++; + bp = (unsigned char *) --((struct __FILE_public *)iob)->_p; #else - cnt = iob->_cnt++; - bp = (unsigned char *) --iob->_ptr; + cnt = iob->_cnt++; + bp = (unsigned char *) --iob->_ptr; #endif - c = cnt < i ? cnt : i; - while ((ep = locc( c, bp, '\n' ))) { - /* - * if we hit the end of this field, return. - */ - if ((j = *++ep) != ' ' && j != '\t') { + c = cnt < i ? cnt : i; + while ((ep = locc( c, bp, '\n' ))) { + /* + * if we hit the end of this field, return. + */ + if ((j = *++ep) != ' ' && j != '\t') { #ifdef LINUX_STDIO - j = ep - (unsigned char *) iob->_IO_read_ptr; - memcpy (cp, iob->_IO_read_ptr, j); - iob->_IO_read_ptr = ep; + j = ep - (unsigned char *) iob->_IO_read_ptr; + memcpy (cp, iob->_IO_read_ptr, j); + iob->_IO_read_ptr = ep; #elif defined(__DragonFly__) - j = ep - (unsigned char *) ((struct __FILE_public *)iob)->_p; - memcpy (cp, ((struct __FILE_public *)iob)->_p, j); - ((struct __FILE_public *)iob)->_p = ep; - ((struct __FILE_public *)iob)->_r -= j; + j = ep - (unsigned char *) ((struct __FILE_public *)iob)->_p; + memcpy (cp, ((struct __FILE_public *)iob)->_p, j); + ((struct __FILE_public *)iob)->_p = ep; + ((struct __FILE_public *)iob)->_r -= j; #else - j = ep - (unsigned char *) iob->_ptr; - memcpy (cp, iob->_ptr, j); - iob->_ptr = ep; - iob->_cnt -= j; + j = ep - (unsigned char *) iob->_ptr; + memcpy (cp, iob->_ptr, j); + iob->_ptr = ep; + iob->_cnt -= j; #endif - cp += j; - state = FLD; - goto finish; - } - c -= ep - bp; - bp = ep; - } - /* - * end of input or dest buffer - copy what we've found. - */ + cp += j; + state = FLD; + goto finish; + } + c -= ep - bp; + bp = ep; + } + /* + * end of input or dest buffer - copy what we've found. + */ #ifdef LINUX_STDIO - c += bp - (unsigned char *) iob->_IO_read_ptr; - memcpy( cp, iob->_IO_read_ptr, c); + c += bp - (unsigned char *) iob->_IO_read_ptr; + memcpy( cp, iob->_IO_read_ptr, c); #elif defined(__DragonFly__) - c += bp - (unsigned char *) ((struct __FILE_public *)iob)->_p; - memcpy( cp, ((struct __FILE_public *)iob)->_p, c); + c += bp - (unsigned char *) ((struct __FILE_public *)iob)->_p; + memcpy( cp, ((struct __FILE_public *)iob)->_p, c); #else - c += bp - (unsigned char *) iob->_ptr; - memcpy( cp, iob->_ptr, c); + c += bp - (unsigned char *) iob->_ptr; + memcpy( cp, iob->_ptr, c); #endif - i -= c; - cp += c; - if (i <= 0) { - /* the dest buffer is full */ + i -= c; + cp += c; + if (i <= 0) { + /* the dest buffer is full */ #ifdef LINUX_STDIO - iob->_IO_read_ptr += c; + iob->_IO_read_ptr += c; #elif defined(__DragonFly__) - ((struct __FILE_public *)iob)->_r -= c; - ((struct __FILE_public *)iob)->_p += c; + ((struct __FILE_public *)iob)->_r -= c; + ((struct __FILE_public *)iob)->_p += c; #else - iob->_cnt -= c; - iob->_ptr += c; + iob->_cnt -= c; + iob->_ptr += c; #endif - state = FLDPLUS; - break; - } - /* - * There's one character left in the input buffer. - * Copy it & fill the buffer. If the last char - * was a newline and the next char is not whitespace, - * this is the end of the field. Otherwise loop. - */ - --i; + state = FLDPLUS; + break; + } + /* + * There's one character left in the input buffer. + * Copy it & fill the buffer. If the last char + * was a newline and the next char is not whitespace, + * this is the end of the field. Otherwise loop. + */ + --i; #ifdef LINUX_STDIO - *cp++ = j = *(iob->_IO_read_ptr + c); - iob->_IO_read_ptr = iob->_IO_read_end; - c = __underflow(iob); - iob->_IO_read_ptr++; /* NOT automatic! */ + *cp++ = j = *(iob->_IO_read_ptr + c); + iob->_IO_read_ptr = iob->_IO_read_end; + c = __underflow(iob); + iob->_IO_read_ptr++; /* NOT automatic! */ #elif defined(__DragonFly__) - *cp++ =j = *(((struct __FILE_public *)iob)->_p + c); - c = __srget(iob); + *cp++ =j = *(((struct __FILE_public *)iob)->_p + c); + c = __srget(iob); #else - *cp++ = j = *(iob->_ptr + c); - c = _filbuf(iob); + *cp++ = j = *(iob->_ptr + c); + c = _filbuf(iob); #endif - if (c == EOF || - ((j == '\0' || j == '\n') && c != ' ' && c != '\t')) { - if (c != EOF) { + if (c == EOF || + ((j == '\0' || j == '\n') && c != ' ' && c != '\t')) { + if (c != EOF) { #ifdef LINUX_STDIO - --iob->_IO_read_ptr; + --iob->_IO_read_ptr; #elif defined(__DragonFly__) - --((struct __FILE_public *)iob)->_p; - ++((struct __FILE_public *)iob)->_r; + --((struct __FILE_public *)iob)->_p; + ++((struct __FILE_public *)iob)->_r; #else - --iob->_ptr; - ++iob->_cnt; + --iob->_ptr; + ++iob->_cnt; #endif - } - state = FLD; - break; - } - } - break; - - case BODY: - body: - /* - * get the message body up to bufsz characters or the - * end of the message. Sleazy hack: if bufsz is negative - * we assume that we were called to copy directly into - * the output buffer and we don't add an eos. - */ - i = (bufsz < 0) ? -bufsz : bufsz-1; + } + state = FLD; + break; + } + } + break; + + case BODY: + body: + /* + * get the message body up to bufsz characters or the + * end of the message. Sleazy hack: if bufsz is negative + * we assume that we were called to copy directly into + * the output buffer and we don't add an eos. + */ + i = (bufsz < 0) ? -bufsz : bufsz-1; #ifdef LINUX_STDIO - bp = (unsigned char *) --iob->_IO_read_ptr; - cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; + bp = (unsigned char *) --iob->_IO_read_ptr; + cnt = (long) iob->_IO_read_end - (long) iob->_IO_read_ptr; #elif defined(__DragonFly__) - bp = (unsigned char *) --((struct __FILE_public *)iob)->_p; - cnt = ++((struct __FILE_public *)iob)->_r; + bp = (unsigned char *) --((struct __FILE_public *)iob)->_p; + cnt = ++((struct __FILE_public *)iob)->_r; #else - bp = (unsigned char *) --iob->_ptr; - cnt = ++iob->_cnt; + bp = (unsigned char *) --iob->_ptr; + cnt = ++iob->_cnt; #endif - c = (cnt < i ? cnt : i); - if (msg_style != MS_DEFAULT && c > 1) { - /* - * packed maildrop - only take up to the (possible) - * start of the next message. This "matchc" should - * probably be a Boyer-Moore matcher for non-vaxen, - * particularly since we have the alignment table - * all built for the end-of-buffer test (next). - * But our vax timings indicate that the "matchc" - * instruction is 50% faster than a carefully coded - * B.M. matcher for most strings. (So much for elegant - * algorithms vs. brute force.) Since I (currently) - * run MH on a vax, we use the matchc instruction. --vj - */ - if ((ep = matchc( fdelimlen, fdelim, c, bp ))) - c = ep - bp + 1; - else { - /* - * There's no delim in the buffer but there may be - * a partial one at the end. If so, we want to leave - * it so the "eom" check on the next call picks it up. - * Use a modified Boyer-Moore matcher to make this - * check relatively cheap. The first "if" figures - * out what position in the pattern matches the last - * character in the buffer. The inner "while" matches - * the pattern against the buffer, backwards starting - * at that position. Note that unless the buffer - * ends with one of the characters in the pattern - * (excluding the first and last), we do only one test. - */ - ep = bp + c - 1; - if ((sp = pat_map[*ep])) { - do { - /* This if() is true unless (a) the buffer is too - * small to contain this delimiter prefix, or - * (b) it contains exactly enough chars for the - * delimiter prefix. - * For case (a) obviously we aren't going to match. - * For case (b), if the buffer really contained exactly - * a delim prefix, then the m_eom call at entry - * should have found it. Thus it's not a delim - * and we know we won't get a match. - */ - if (((sp - fdelim) + 2) <= c) { - cp = sp; - /* Unfortunately although fdelim has a preceding NUL - * we can't use this as a sentinel in case the buffer - * contains a NUL in exactly the wrong place (this - * would cause us to run off the front of fdelim). + c = (cnt < i ? cnt : i); + if (msg_style != MS_DEFAULT && c > 1) { + /* + * packed maildrop - only take up to the (possible) + * start of the next message. This "matchc" should + * probably be a Boyer-Moore matcher for non-vaxen, + * particularly since we have the alignment table + * all built for the end-of-buffer test (next). + * But our vax timings indicate that the "matchc" + * instruction is 50% faster than a carefully coded + * B.M. matcher for most strings. (So much for elegant + * algorithms vs. brute force.) Since I (currently) + * run MH on a vax, we use the matchc instruction. --vj */ - while (*--ep == *--cp) - if (cp < fdelim) - break; - if (cp < fdelim) { - /* we matched the entire delim prefix, - * so only take the buffer up to there. - * we know ep >= bp -- check above prevents underrun - */ - c = (ep - bp) + 2; - break; + if ((ep = matchc( fdelimlen, fdelim, c, bp ))) + c = ep - bp + 1; + else { + /* + * There's no delim in the buffer but there may be + * a partial one at the end. If so, we want to leave + * it so the "eom" check on the next call picks it up. + * Use a modified Boyer-Moore matcher to make this + * check relatively cheap. The first "if" figures + * out what position in the pattern matches the last + * character in the buffer. The inner "while" matches + * the pattern against the buffer, backwards starting + * at that position. Note that unless the buffer + * ends with one of the characters in the pattern + * (excluding the first and last), we do only one test. + */ + ep = bp + c - 1; + if ((sp = pat_map[*ep])) { + do { + /* This if() is true unless (a) the buffer is too + * small to contain this delimiter prefix, or + * (b) it contains exactly enough chars for the + * delimiter prefix. + * For case (a) obviously we aren't going to match. + * For case (b), if the buffer really contained exactly + * a delim prefix, then the m_eom call at entry + * should have found it. Thus it's not a delim + * and we know we won't get a match. + */ + if (((sp - fdelim) + 2) <= c) { + cp = sp; + /* Unfortunately although fdelim has a preceding NUL + * we can't use this as a sentinel in case the buffer + * contains a NUL in exactly the wrong place (this + * would cause us to run off the front of fdelim). + */ + while (*--ep == *--cp) + if (cp < fdelim) + break; + if (cp < fdelim) { + /* we matched the entire delim prefix, + * so only take the buffer up to there. + * we know ep >= bp -- check above prevents underrun + */ + c = (ep - bp) + 2; + break; + } + } + /* try matching one less char of delim string */ + ep = bp + c - 1; + } while (--sp > fdelim); + } } - } - /* try matching one less char of delim string */ - ep = bp + c - 1; - } while (--sp > fdelim); - } - } - } - memcpy( buf, bp, c ); + } + memcpy( buf, bp, c ); #ifdef LINUX_STDIO - iob->_IO_read_ptr += c; + iob->_IO_read_ptr += c; #elif defined(__DragonFly__) - ((struct __FILE_public *)iob)->_r -= c; - ((struct __FILE_public *)iob)->_p += c; + ((struct __FILE_public *)iob)->_r -= c; + ((struct __FILE_public *)iob)->_p += c; #else - iob->_cnt -= c; - iob->_ptr += c; + iob->_cnt -= c; + iob->_ptr += c; #endif - if (bufsz < 0) { - msg_count = c; - return (state); - } - cp = buf + c; - break; - - default: - adios (NULL, "m_getfld() called with bogus state of %d", state); - } + if (bufsz < 0) { + msg_count = c; + return (state); + } + cp = buf + c; + break; + + default: + adios (NULL, "m_getfld() called with bogus state of %d", state); + } finish: - *cp = 0; - msg_count = cp - buf; - return (state); + *cp = 0; + msg_count = cp - buf; + return (state); } @@ -592,11 +591,11 @@ static char unixbuf[BUFSIZ] = ""; void m_unknown(FILE *iob) { - register int c; - register long pos; - char text[10]; - register char *cp; - register char *delimstr; + register int c; + register long pos; + char text[10]; + register char *cp; + register char *delimstr; /* * Figure out what the message delimitter string is for this @@ -611,60 +610,60 @@ m_unknown(FILE *iob) * specified when nmh was built (or from the mts.conf file). */ - msg_style = MS_UNKNOWN; + msg_style = MS_UNKNOWN; - pos = ftell (iob); - if (fread (text, sizeof(*text), 5, iob) == 5 - && strncmp (text, "From ", 5) == 0) { - msg_style = MS_MBOX; - delimstr = "\nFrom "; -#ifndef RPATHS - while ((c = getc (iob)) != '\n' && c >= 0) - ; + pos = ftell (iob); + if (fread (text, sizeof(*text), 5, iob) == 5 + && strncmp (text, "From ", 5) == 0) { + msg_style = MS_MBOX; + delimstr = "\nFrom "; +#ifndef RPATHS + while ((c = getc (iob)) != '\n' && c >= 0) + ; #else /* RPATHS */ - cp = unixbuf; - while ((c = getc (iob)) != '\n' && cp - unixbuf < BUFSIZ - 1) - *cp++ = c; - *cp = 0; + cp = unixbuf; + while ((c = getc (iob)) != '\n' && cp - unixbuf < BUFSIZ - 1) + *cp++ = c; + *cp = 0; #endif /* RPATHS */ - } else { - /* not a Unix style maildrop */ - fseek (iob, pos, SEEK_SET); - if (mmdlm2 == NULL || *mmdlm2 == 0) - mmdlm2 = "\001\001\001\001\n"; - delimstr = mmdlm2; - msg_style = MS_MMDF; - } - c = strlen (delimstr); - fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); - *fdelim++ = '\0'; - *fdelim = '\n'; - msg_delim = (char *)fdelim+1; - edelim = (unsigned char *)msg_delim+1; - fdelimlen = c + 1; - edelimlen = c - 1; - strcpy (msg_delim, delimstr); - delimend = (unsigned char *)msg_delim + edelimlen; - if (edelimlen <= 1) - adios (NULL, "maildrop delimiter must be at least 2 bytes"); - /* - * build a Boyer-Moore end-position map for the matcher in m_getfld. - * N.B. - we don't match just the first char (since it's the newline - * separator) or the last char (since the matchc would have found it - * if it was a real delim). - */ - pat_map = (unsigned char **) calloc (256, sizeof(unsigned char *)); - - for (cp = (char *) fdelim + 1; cp < (char *) delimend; cp++ ) - pat_map[(unsigned char)*cp] = (unsigned char *) cp; - - if (msg_style == MS_MMDF) { - /* flush extra msg hdrs */ - while ((c = Getc(iob)) >= 0 && eom (c, iob)) - ; - if (c >= 0) - ungetc(c, iob); - } + } else { + /* not a Unix style maildrop */ + fseek (iob, pos, SEEK_SET); + if (mmdlm2 == NULL || *mmdlm2 == 0) + mmdlm2 = "\001\001\001\001\n"; + delimstr = mmdlm2; + msg_style = MS_MMDF; + } + c = strlen (delimstr); + fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); + *fdelim++ = '\0'; + *fdelim = '\n'; + msg_delim = (char *)fdelim+1; + edelim = (unsigned char *)msg_delim+1; + fdelimlen = c + 1; + edelimlen = c - 1; + strcpy (msg_delim, delimstr); + delimend = (unsigned char *)msg_delim + edelimlen; + if (edelimlen <= 1) + adios (NULL, "maildrop delimiter must be at least 2 bytes"); + /* + * build a Boyer-Moore end-position map for the matcher in m_getfld. + * N.B. - we don't match just the first char (since it's the newline + * separator) or the last char (since the matchc would have found it + * if it was a real delim). + */ + pat_map = (unsigned char **) calloc (256, sizeof(unsigned char *)); + + for (cp = (char *) fdelim + 1; cp < (char *) delimend; cp++ ) + pat_map[(unsigned char)*cp] = (unsigned char *) cp; + + if (msg_style == MS_MMDF) { + /* flush extra msg hdrs */ + while ((c = Getc(iob)) >= 0 && eom (c, iob)) + ; + if (c >= 0) + ungetc(c, iob); + } } @@ -675,45 +674,45 @@ m_unknown(FILE *iob) static int m_Eom (int c, FILE *iob) { - register long pos = 0L; - register int i; - char text[10]; + register long pos = 0L; + register int i; + char text[10]; #ifdef RPATHS - register char *cp; + register char *cp; #endif /* RPATHS */ - pos = ftell (iob); - if ((i = fread (text, sizeof *text, edelimlen, iob)) != edelimlen - || strncmp (text, (char *)edelim, edelimlen)) { - if (i == 0 && msg_style == MS_MBOX) - /* the final newline in the (brain damaged) unix-format - * maildrop is part of the delimitter - delete it. - */ - return 1; + pos = ftell (iob); + if ((i = fread (text, sizeof *text, edelimlen, iob)) != edelimlen + || strncmp (text, (char *)edelim, edelimlen)) { + if (i == 0 && msg_style == MS_MBOX) + /* the final newline in the (brain damaged) unix-format + * maildrop is part of the delimitter - delete it. + */ + return 1; #if 0 - fseek (iob, pos, SEEK_SET); + fseek (iob, pos, SEEK_SET); #endif - fseek (iob, (long)(pos-1), SEEK_SET); - getc (iob); /* should be OK */ - return 0; - } + fseek (iob, (long)(pos-1), SEEK_SET); + getc (iob); /* should be OK */ + return 0; + } - if (msg_style == MS_MBOX) { + if (msg_style == MS_MBOX) { #ifndef RPATHS - while ((c = getc (iob)) != '\n') - if (c < 0) - break; + while ((c = getc (iob)) != '\n') + if (c < 0) + break; #else /* RPATHS */ - cp = unixbuf; - while ((c = getc (iob)) != '\n' && c >= 0 && cp - unixbuf < BUFSIZ - 1) - *cp++ = c; - *cp = 0; + cp = unixbuf; + while ((c = getc (iob)) != '\n' && c >= 0 && cp - unixbuf < BUFSIZ - 1) + *cp++ = c; + *cp = 0; #endif /* RPATHS */ - } + } - return 1; + return 1; } @@ -732,48 +731,48 @@ m_Eom (int c, FILE *iob) int get_returnpath (char *rp, int rplen, char *dd, int ddlen) { - char *ap, *bp, *cp, *dp; - - ap = unixbuf; - if (!(bp = cp = strchr(ap, ' '))) - return 0; - - /* - * Check for "remote from" in envelope to see - * if this message uses UUCP style addressing - */ - while ((cp = strchr(++cp, 'r'))) { - if (strncmp (cp, "remote from", 11) == 0) { - cp = strrchr (cp, ' '); - break; + char *ap, *bp, *cp, *dp; + + ap = unixbuf; + if (!(bp = cp = strchr(ap, ' '))) + return 0; + + /* + * Check for "remote from" in envelope to see + * if this message uses UUCP style addressing + */ + while ((cp = strchr(++cp, 'r'))) { + if (strncmp (cp, "remote from", 11) == 0) { + cp = strrchr (cp, ' '); + break; + } } - } - - /* - * Get the Return-Path information from - * the "From " envelope. - */ - if (cp) { - /* return path for UUCP style addressing */ - dp = strchr (++cp, '\n'); - snprintf (rp, rplen, "%.*s!%.*s\n", (int)(dp - cp), cp, (int)(bp - ap), ap); - } else { - /* return path for standard domain addressing */ - snprintf (rp, rplen, "%.*s\n", (int)(bp - ap), ap); - } - - /* - * advance over the spaces to get to - * delivery date on envelope - */ - while (*bp == ' ') - bp++; - - /* Now get delivery date from envelope */ - snprintf (dd, ddlen, "%.*s\n", 24, bp); - - unixbuf[0] = 0; - return 1; + + /* + * Get the Return-Path information from + * the "From " envelope. + */ + if (cp) { + /* return path for UUCP style addressing */ + dp = strchr (++cp, '\n'); + snprintf (rp, rplen, "%.*s!%.*s\n", (int)(dp - cp), cp, (int)(bp - ap), ap); + } else { + /* return path for standard domain addressing */ + snprintf (rp, rplen, "%.*s\n", (int)(bp - ap), ap); + } + + /* + * advance over the spaces to get to + * delivery date on envelope + */ + while (*bp == ' ') + bp++; + + /* Now get delivery date from envelope */ + snprintf (dd, ddlen, "%.*s\n", 24, bp); + + unixbuf[0] = 0; + return 1; } #endif /* RPATHS */ @@ -796,7 +795,7 @@ matchc(int patln, char *pat, int strln, char *str) sp = str; pp = pat; while (pp < ep && *sp++ == *pp) pp++; - if (pp >= ep) + if (pp >= ep) return ((unsigned char *)--str); } } @@ -810,8 +809,9 @@ matchc(int patln, char *pat, int strln, char *str) static unsigned char * locc(int cnt, unsigned char *src, unsigned char term) { - while (*src++ != term && --cnt > 0); + while (*src++ != term && --cnt > 0) + ; - return (cnt > 0 ? --src : (unsigned char *)0); + return (cnt > 0 ? --src : (unsigned char *)0); } diff --git a/sbr/m_gmprot.c b/sbr/m_gmprot.c index 92ead2d..9bf7088 100644 --- a/sbr/m_gmprot.c +++ b/sbr/m_gmprot.c @@ -1,4 +1,3 @@ - /* * m_gmprot.c -- return the msg-protect value * @@ -13,7 +12,7 @@ int m_gmprot (void) { - register char *cp; + register char *cp; - return atooi ((cp = context_find ("msg-protect")) && *cp ? cp : msgprot); + return atooi ((cp = context_find ("msg-protect")) && *cp ? cp : msgprot); } diff --git a/sbr/m_maildir.c b/sbr/m_maildir.c index 6c8c584..15e4a66 100644 --- a/sbr/m_maildir.c +++ b/sbr/m_maildir.c @@ -1,4 +1,3 @@ - /* * m_maildir.c -- get the path for the mail directory * @@ -9,12 +8,12 @@ #include -#define CWD "./" -#define NCWD (sizeof(CWD) - 1) -#define DOT "." -#define DOTDOT ".." -#define PWD "../" -#define NPWD (sizeof(PWD) - 1) +#define CWD "./" +#define NCWD (sizeof(CWD) - 1) +#define DOT "." +#define DOTDOT ".." +#define PWD "../" +#define NPWD (sizeof(PWD) - 1) static char mailfold[BUFSIZ]; @@ -27,70 +26,70 @@ static char *exmaildir (char *); char * m_maildir (char *folder) { - register char *cp, *ep; + register char *cp, *ep; - if ((cp = exmaildir (folder)) - && (ep = cp + strlen (cp) - 1) > cp - && *ep == '/') - *ep = '\0'; + if ((cp = exmaildir (folder)) + && (ep = cp + strlen (cp) - 1) > cp + && *ep == '/') + *ep = '\0'; - return cp; + return cp; } char * m_mailpath (char *folder) { - register char *cp; - char maildir[BUFSIZ]; - - if (*folder != '/' - && strncmp (folder, CWD, NCWD) - && strcmp (folder, DOT) - && strcmp (folder, DOTDOT) - && strncmp (folder, PWD, NPWD)) { - strncpy (maildir, mailfold, sizeof(maildir)); /* preserve... */ - cp = getcpy (m_maildir (folder)); - strncpy (mailfold, maildir, sizeof(mailfold)); - } else { - cp = path (folder, TFOLDER); - } - - return cp; + register char *cp; + char maildir[BUFSIZ]; + + if (*folder != '/' + && strncmp (folder, CWD, NCWD) + && strcmp (folder, DOT) + && strcmp (folder, DOTDOT) + && strncmp (folder, PWD, NPWD)) { + strncpy (maildir, mailfold, sizeof(maildir)); /* preserve... */ + cp = getcpy (m_maildir (folder)); + strncpy (mailfold, maildir, sizeof(mailfold)); + } else { + cp = path (folder, TFOLDER); + } + + return cp; } static char * exmaildir (char *folder) { - register char *cp, *pp; - - /* use current folder if none is specified */ - if (folder == NULL) - folder = getfolder(1); - - if (!(*folder != '/' - && strncmp (folder, CWD, NCWD) - && strcmp (folder, DOT) - && strcmp (folder, DOTDOT) - && strncmp (folder, PWD, NPWD))) { - strncpy (mailfold, folder, sizeof(mailfold)); - return mailfold; - } + register char *cp, *pp; + + /* use current folder if none is specified */ + if (folder == NULL) + folder = getfolder(1); + + if (!(*folder != '/' + && strncmp (folder, CWD, NCWD) + && strcmp (folder, DOT) + && strcmp (folder, DOTDOT) + && strncmp (folder, PWD, NPWD))) { + strncpy (mailfold, folder, sizeof(mailfold)); + return mailfold; + } - cp = mailfold; - if ((pp = context_find ("path")) && *pp) { - if (*pp != '/') { - sprintf (cp, "%s/", mypath); - cp += strlen (cp); + cp = mailfold; + if ((pp = context_find ("path")) && *pp) { + if (*pp != '/') { + sprintf (cp, "%s/", mypath); + cp += strlen (cp); + } + cp = copy (pp, cp); + } else { + cp = copy (path ("./", TFOLDER), cp); } - cp = copy (pp, cp); - } else { - cp = copy (path ("./", TFOLDER), cp); - } - if (cp[-1] != '/') - *cp++ = '/'; - strcpy (cp, folder); - - return mailfold; + if (cp[-1] != '/') + *cp++ = '/'; + strcpy (cp, folder); + + return mailfold; } diff --git a/sbr/m_mktemp.c b/sbr/m_mktemp.c index aa25636..6f2089b 100644 --- a/sbr/m_mktemp.c +++ b/sbr/m_mktemp.c @@ -27,7 +27,7 @@ static char *get_temp_dir(); * * When pfx_in is null, the temporary directory is determined as * follows, in order: - * + * * MHTMPDIR envvar * TMPDIR envvar * TMP envvar @@ -42,49 +42,49 @@ static char *get_temp_dir(); */ char * m_mktemp ( - const char *pfx_in, /* Pathname prefix for temporary file. */ - int *fd_ret, /* (return,optional) File descriptor to temp file. */ - FILE **fp_ret /* (return,optional) FILE pointer to temp file. */ + const char *pfx_in, /* Pathname prefix for temporary file. */ + int *fd_ret, /* (return,optional) File descriptor to temp file. */ + FILE **fp_ret /* (return,optional) FILE pointer to temp file. */ ) { - static char tmpfil[BUFSIZ]; - int fd = -1; - int keep_open = 0; - mode_t oldmode = umask(077); + static char tmpfil[BUFSIZ]; + int fd = -1; + int keep_open = 0; + mode_t oldmode = umask(077); - if (pfx_in == NULL) { - snprintf(tmpfil, sizeof(tmpfil), "%s/nmhXXXXXX", get_temp_dir()); - } else { - snprintf(tmpfil, sizeof(tmpfil), "%sXXXXXX", pfx_in); - } + if (pfx_in == NULL) { + snprintf(tmpfil, sizeof(tmpfil), "%s/nmhXXXXXX", get_temp_dir()); + } else { + snprintf(tmpfil, sizeof(tmpfil), "%sXXXXXX", pfx_in); + } - fd = mkstemp(tmpfil); - if (fd < 0) { - umask(oldmode); - return NULL; - } - if (fd_ret != NULL) { - *fd_ret = fd; - keep_open = 1; - } - if (fp_ret != NULL) { - FILE *fp = fdopen(fd, "w+"); - if (fp == NULL) { - int olderr = errno; - unlink(tmpfil); - close(fd); - errno = olderr; - umask(oldmode); - return NULL; - } - *fp_ret = fp; - keep_open = 1; - } - if (!keep_open) { - close(fd); - } - umask(oldmode); - return tmpfil; + fd = mkstemp(tmpfil); + if (fd < 0) { + umask(oldmode); + return NULL; + } + if (fd_ret != NULL) { + *fd_ret = fd; + keep_open = 1; + } + if (fp_ret != NULL) { + FILE *fp = fdopen(fd, "w+"); + if (fp == NULL) { + int olderr = errno; + unlink(tmpfil); + close(fd); + errno = olderr; + umask(oldmode); + return NULL; + } + *fp_ret = fp; + keep_open = 1; + } + if (!keep_open) { + close(fd); + } + umask(oldmode); + return tmpfil; } /* This version allows one to specify the directory the temp file should @@ -99,48 +99,48 @@ m_mktemp ( */ char * m_mktemp2 ( - const char *dir_in, /* Directory to place temp file. */ - const char *pfx_in, /* Basename prefix for temp file. */ - int *fd_ret, /* (return,optional) File descriptor to temp file. */ - FILE **fp_ret /* (return,optional) FILE pointer to temp file. */ + const char *dir_in, /* Directory to place temp file. */ + const char *pfx_in, /* Basename prefix for temp file. */ + int *fd_ret, /* (return,optional) File descriptor to temp file. */ + FILE **fp_ret /* (return,optional) FILE pointer to temp file. */ ) { - static char buffer[BUFSIZ]; - char *cp; - int n; + static char buffer[BUFSIZ]; + char *cp; + int n; - if (dir_in == NULL) { - if (pfx_in == NULL) { - return m_mktemp(NULL, fd_ret, fp_ret); - } - snprintf(buffer, sizeof(buffer), "%s/%s", get_temp_dir(), pfx_in); - return m_mktemp(buffer, fd_ret, fp_ret); - } + if (dir_in == NULL) { + if (pfx_in == NULL) { + return m_mktemp(NULL, fd_ret, fp_ret); + } + snprintf(buffer, sizeof(buffer), "%s/%s", get_temp_dir(), pfx_in); + return m_mktemp(buffer, fd_ret, fp_ret); + } - if ((cp = r1bindex ((char *)dir_in, '/')) == dir_in) { - /* No directory component */ - return m_mktemp(pfx_in, fd_ret, fp_ret); - } - n = (int)(cp-dir_in-1); /* Length of dir component */ - snprintf(buffer, sizeof(buffer), "%.*s%s", n, dir_in, pfx_in); - return m_mktemp(buffer, fd_ret, fp_ret); + if ((cp = r1bindex ((char *)dir_in, '/')) == dir_in) { + /* No directory component */ + return m_mktemp(pfx_in, fd_ret, fp_ret); + } + n = (int)(cp-dir_in-1); /* Length of dir component */ + snprintf(buffer, sizeof(buffer), "%.*s%s", n, dir_in, pfx_in); + return m_mktemp(buffer, fd_ret, fp_ret); } static char * get_temp_dir() { - // Ignore envvars if we are setuid - if ((getuid()==geteuid()) && (getgid()==getegid())) { - char *tmpdir = NULL; - tmpdir = getenv("MHTMPDIR"); - if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; + // Ignore envvars if we are setuid + if ((getuid()==geteuid()) && (getgid()==getegid())) { + char *tmpdir = NULL; + tmpdir = getenv("MHTMPDIR"); + if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; - tmpdir = getenv("TMPDIR"); - if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; + tmpdir = getenv("TMPDIR"); + if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; - tmpdir = getenv("TMP"); - if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; - } - return m_maildir(""); + tmpdir = getenv("TMP"); + if (tmpdir != NULL && *tmpdir != '\0') return tmpdir; + } + return m_maildir(""); } diff --git a/sbr/m_msgdef.c b/sbr/m_msgdef.c index d602973..cddb4e9 100644 --- a/sbr/m_msgdef.c +++ b/sbr/m_msgdef.c @@ -1,4 +1,3 @@ - /* * m_msgdef.c -- some defines for sbr/m_getfld.c * diff --git a/sbr/m_name.c b/sbr/m_name.c index 18ee081..bc3a681 100644 --- a/sbr/m_name.c +++ b/sbr/m_name.c @@ -1,4 +1,3 @@ - /* * m_name.c -- return a message number as a string * @@ -15,9 +14,9 @@ static char name[BUFSIZ]; char * m_name (int num) { - if (num <= 0) - return "?"; + if (num <= 0) + return "?"; - snprintf (name, sizeof(name), "%d", num); - return name; + snprintf (name, sizeof(name), "%d", num); + return name; } diff --git a/sbr/m_scratch.c b/sbr/m_scratch.c index 3c63d09..a929419 100644 --- a/sbr/m_scratch.c +++ b/sbr/m_scratch.c @@ -1,4 +1,3 @@ - /* * m_scratch.c -- construct a scratch file * @@ -16,26 +15,26 @@ char * m_scratch (char *file, char *template) { - char *cp; - static char buffer[BUFSIZ], tmpfil[BUFSIZ]; + char *cp; + static char buffer[BUFSIZ], tmpfil[BUFSIZ]; - snprintf (tmpfil, sizeof(tmpfil), "%sXXXXXX", template); + snprintf (tmpfil, sizeof(tmpfil), "%sXXXXXX", template); /* - Mkstemp work postponed until later -Doug -#ifdef HAVE_MKSTEMP - mkstemp (tmpfil); -#else -*/ - mktemp (tmpfil); + * Mkstemp work postponed until later -Doug + * #ifdef HAVE_MKSTEMP + * mkstemp (tmpfil); + * #else + */ + mktemp (tmpfil); /* -#endif -*/ - /* nasty - this really means: if there is no '/' in the path */ - if ((cp = r1bindex (file, '/')) == file) - strncpy (buffer, tmpfil, sizeof(buffer)); - else - snprintf (buffer, sizeof(buffer), "%.*s%s", (int)(cp - file), file, tmpfil); - unlink (buffer); + * #endif + */ + /* nasty - this really means: if there is no '/' in the path */ + if ((cp = r1bindex (file, '/')) == file) + strncpy (buffer, tmpfil, sizeof(buffer)); + else + snprintf (buffer, sizeof(buffer), "%.*s%s", (int)(cp - file), file, tmpfil); + unlink (buffer); - return buffer; + return buffer; } diff --git a/sbr/m_tmpfil.c b/sbr/m_tmpfil.c index 291d996..c0a60bc 100644 --- a/sbr/m_tmpfil.c +++ b/sbr/m_tmpfil.c @@ -15,18 +15,18 @@ char * m_tmpfil (char *template) { - static char tmpfil[BUFSIZ]; + static char tmpfil[BUFSIZ]; - snprintf (tmpfil, sizeof(tmpfil), "/tmp/%sXXXXXX", template); + snprintf (tmpfil, sizeof(tmpfil), "/tmp/%sXXXXXX", template); /* - Mkstemp work postponed until later -Doug -#ifdef HAVE_MKSTEMP - unlink(mkstemp(tmpfil)); -#else -*/ - unlink(mktemp(tmpfil)); + * Mkstemp work postponed until later -Doug + * #ifdef HAVE_MKSTEMP + * unlink(mkstemp(tmpfil)); + * #else + */ + unlink(mktemp(tmpfil)); /* -#endif -*/ - return tmpfil; + * #endif + */ + return tmpfil; } diff --git a/sbr/makedir.c b/sbr/makedir.c index 4337b7c..1e03caa 100644 --- a/sbr/makedir.c +++ b/sbr/makedir.c @@ -1,4 +1,3 @@ - /* * makedir.c -- make a directory * @@ -15,104 +14,103 @@ #include #include #include - + int makedir (char *dir) { - char path[PATH_MAX]; - char* folder_perms_ASCII; - int had_an_error = 0; - mode_t folder_perms, saved_umask; - pid_t pid; - register char* c; - - context_save(); /* save the context file */ - fflush(stdout); - - if (!(folder_perms_ASCII = context_find ("folder-protect"))) - folder_perms_ASCII = foldprot; /* defaults to "700" */ - - /* Because mh-profile.man documents "Folder-Protect:" as an octal constant, - and we don't want to force the user to remember to include a leading - zero, we call atooi(folder_perms_ASCII) here rather than - strtoul(folder_perms_ASCII, NULL, 0). Therefore, if anyone ever tries to - specify a mode in say, hex, they'll get garbage. (I guess nmh uses its - atooi() function rather than calling strtoul() with a radix of 8 because - some ancient platforms are missing that functionality. */ - folder_perms = atooi(folder_perms_ASCII); - - /* Folders have definite desired permissions that are set -- we don't want - to interact with the umask. Clear it temporarily. */ - saved_umask = umask(0); - - if (getuid () == geteuid ()) { - c = strncpy(path, dir, sizeof(path)); - - while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) { - *c = (char)0; - if (access(path, X_OK)) { - if (errno != ENOENT){ - advise (dir, "unable to create directory"); - had_an_error = 1; + char path[PATH_MAX]; + char* folder_perms_ASCII; + int had_an_error = 0; + mode_t folder_perms, saved_umask; + pid_t pid; + register char* c; + + context_save(); /* save the context file */ + fflush(stdout); + + if (!(folder_perms_ASCII = context_find ("folder-protect"))) + folder_perms_ASCII = foldprot; /* defaults to "700" */ + + /* Because mh-profile.man documents "Folder-Protect:" as an octal constant, + and we don't want to force the user to remember to include a leading + zero, we call atooi(folder_perms_ASCII) here rather than + strtoul(folder_perms_ASCII, NULL, 0). Therefore, if anyone ever tries to + specify a mode in say, hex, they'll get garbage. (I guess nmh uses its + atooi() function rather than calling strtoul() with a radix of 8 because + some ancient platforms are missing that functionality. */ + folder_perms = atooi(folder_perms_ASCII); + + /* Folders have definite desired permissions that are set -- we don't want + to interact with the umask. Clear it temporarily. */ + saved_umask = umask(0); + + if (getuid () == geteuid ()) { + c = strncpy(path, dir, sizeof(path)); + + while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) { + *c = (char)0; + if (access(path, X_OK)) { + if (errno != ENOENT){ + advise (dir, "unable to create directory"); + had_an_error = 1; + } + /* Create an outer directory. */ + if (mkdir(path, folder_perms)) { + advise (dir, "unable to create directory"); + had_an_error = 1; + } + } + *c = '/'; } - /* Create an outer directory. */ - if (mkdir(path, folder_perms)) { - advise (dir, "unable to create directory"); - had_an_error = 1; + + if (!had_an_error) { + /* Create the innermost nested subdirectory of the + * path we're being asked to create. */ + if (mkdir (dir, folder_perms) == -1) { + advise (dir, "unable to create directory"); + had_an_error = 1; + } } - } - *c = '/'; - } + } else { + /* Ummm, why do we want to avoid creating directories with the effective + user ID? None of the nmh tools are installed such that the effective + should be different from the real, and if some parent process made + the two be different, I don't see why it should be our job to enforce + the real UID. Also, why the heck do we call the mkdir executable + rather than the library function in this case?? If we do want to + call the mkdir executable, we should at least be giving it -p (and + change the single chmod() call below) so it can successfully create + nested directories like the above code can. - if (!had_an_error) { - /* Create the innermost nested subdirectory of the path we're being - asked to create. */ - if (mkdir (dir, folder_perms) == -1) { - advise (dir, "unable to create directory"); - had_an_error = 1; - } - } - } - else { - /* Ummm, why do we want to avoid creating directories with the effective - user ID? None of the nmh tools are installed such that the effective - should be different from the real, and if some parent process made - the two be different, I don't see why it should be our job to enforce - the real UID. Also, why the heck do we call the mkdir executable - rather than the library function in this case?? If we do want to - call the mkdir executable, we should at least be giving it -p (and - change the single chmod() call below) so it can successfully create - nested directories like the above code can. - - -- Dan Harkless */ - switch (pid = vfork()) { - case -1: - advise ("fork", "unable to"); - return 0; - - case 0: - setgid (getgid ()); - setuid (getuid ()); - - execl ("/bin/mkdir", "mkdir", dir, NULL); - execl ("/usr/bin/mkdir", "mkdir", dir, NULL); - fprintf (stderr, "unable to exec "); - perror ("mkdir"); - _exit (-1); - - default: - if (pidXwait(pid, "mkdir")) - return 0; - break; - } + -- Dan Harkless */ + switch (pid = vfork()) { + case -1: + advise ("fork", "unable to"); + return 0; + + case 0: + setgid (getgid ()); + setuid (getuid ()); - chmod (dir, folder_perms); - } + execl ("/bin/mkdir", "mkdir", dir, NULL); + execl ("/usr/bin/mkdir", "mkdir", dir, NULL); + fprintf (stderr, "unable to exec "); + perror ("mkdir"); + _exit (-1); + + default: + if (pidXwait(pid, "mkdir")) + return 0; + break; + } + + chmod (dir, folder_perms); + } - umask(saved_umask); /* put the user's umask back */ + umask(saved_umask); /* put the user's umask back */ - if (had_an_error) - return 0; /* opposite of UNIX error return convention */ - else - return 1; + if (had_an_error) + return 0; /* opposite of UNIX error return convention */ + else + return 1; } diff --git a/sbr/memmove.c b/sbr/memmove.c index 62a303f..fabe133 100644 --- a/sbr/memmove.c +++ b/sbr/memmove.c @@ -1,11 +1,12 @@ /* public domain function from Jan Wolter Unix Incompatibility Notes */ /* http://unixpapa.com/incnote/ */ -char *memmove(char *dst, char *src, int n) +char * +memmove(char *dst, char *src, int n) { - if (src > dst) - for ( ; n > 0; n--) - *(dst++)= *(src++); - else - for (dst+= n-1, src+= n-1; n > 0; n--) - *(dst--)= *(src--); + if (src > dst) + for ( ; n > 0; n--) + *(dst++)= *(src++); + else + for (dst+= n-1, src+= n-1; n > 0; n--) + *(dst--)= *(src--); } diff --git a/sbr/mf.c b/sbr/mf.c index fd92e36..063541b 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -1,4 +1,3 @@ - /* * mf.c -- mail filter subroutines * @@ -30,57 +29,57 @@ static int my_lex (char *); static char * getcpy (char *s) { - register char *p; - - if (!s) { -/* causes compiles to blow up because the symbol _cleanup is undefined - where did this ever come from? */ - /* _cleanup(); */ - abort(); - for(;;) - pause(); - } - p = mh_xmalloc ((size_t) (strlen (s) + 2)); - strcpy (p, s); - return p; + register char *p; + + if (!s) { +/* causes compiles to blow up because the symbol _cleanup is undefined + * where did this ever come from? */ + /* _cleanup(); */ + abort(); + for(;;) + pause(); + } + p = mh_xmalloc ((size_t) (strlen (s) + 2)); + strcpy (p, s); + return p; } int isfrom(char *string) { - return (strncmp (string, "From ", 5) == 0 - || strncmp (string, ">From ", 6) == 0); + return (strncmp (string, "From ", 5) == 0 + || strncmp (string, ">From ", 6) == 0); } int lequal (unsigned char *a, unsigned char *b) { - for (; *a; a++, b++) - if (*b == 0) - return FALSE; - else { - char c1 = islower (*a) ? toupper (*a) : *a; - char c2 = islower (*b) ? toupper (*b) : *b; - if (c1 != c2) - return FALSE; - } + for (; *a; a++, b++) + if (*b == 0) + return FALSE; + else { + char c1 = islower (*a) ? toupper (*a) : *a; + char c2 = islower (*b) ? toupper (*b) : *b; + if (c1 != c2) + return FALSE; + } - return (*b == 0); + return (*b == 0); } -/* +/* * seekadrx() is tricky. We want to cover both UUCP-style and ARPA-style * addresses, so for each list of addresses we see if we can find some * character to give us a hint. */ -#define CHKADR 0 /* undertermined address style */ -#define UNIXDR 1 /* UNIX-style address */ -#define ARPADR 2 /* ARPAnet-style address */ +#define CHKADR 0 /* undertermined address style */ +#define UNIXDR 1 /* UNIX-style address */ +#define ARPADR 2 /* ARPAnet-style address */ static char *punctuators = ";<>.()[]"; @@ -93,32 +92,32 @@ static struct adrx adrxs1; struct adrx * seekadrx (char *addrs) { - static int state = CHKADR; - register char *cp; - register struct adrx *adrxp; - - if (state == CHKADR) - for (state = UNIXDR, cp = addrs; *cp; cp++) - if (strchr(punctuators, *cp)) { - state = ARPADR; - break; - } - - switch (state) { - case UNIXDR: - adrxp = uucpadrx (addrs); - break; - - case ARPADR: - default: - adrxp = getadrx (addrs); - break; - } - - if (adrxp == NULL) - state = CHKADR; - - return adrxp; + static int state = CHKADR; + register char *cp; + register struct adrx *adrxp; + + if (state == CHKADR) + for (state = UNIXDR, cp = addrs; *cp; cp++) + if (strchr(punctuators, *cp)) { + state = ARPADR; + break; + } + + switch (state) { + case UNIXDR: + adrxp = uucpadrx (addrs); + break; + + case ARPADR: + default: + adrxp = getadrx (addrs); + break; + } + + if (adrxp == NULL) + state = CHKADR; + + return adrxp; } @@ -131,105 +130,97 @@ seekadrx (char *addrs) struct adrx * uucpadrx (char *addrs) { - register unsigned char *cp, *wp, *xp, *yp; - register char *zp; - register struct adrx *adrxp = &adrxs1; - - if (vp == NULL) { - vp = tp = getcpy (addrs); - compress (addrs, vp); - } - else - if (tp == NULL) { - free (vp); - vp = NULL; - return NULL; + register unsigned char *cp, *wp, *xp, *yp; + register char *zp; + register struct adrx *adrxp = &adrxs1; + + if (vp == NULL) { + vp = tp = getcpy (addrs); + compress (addrs, vp); + } else if (tp == NULL) { + free (vp); + vp = NULL; + return NULL; } - for (cp = tp; isspace (*cp); cp++) - continue; - if (*cp == 0) { - free (vp); - vp = tp = NULL; - return NULL; - } - - if ((wp = strchr(cp, ',')) == NULL) { - if ((wp = strchr(cp, ' ')) != NULL) { - xp = wp; - while (isspace (*xp)) - xp++; - if (*xp != 0 && isat (--xp)) { - yp = xp + 4; - while (isspace (*yp)) - yp++; - if (*yp != 0) { - if ((zp = strchr(yp, ' ')) != NULL) - *zp = 0, tp = ++zp; - else - tp = NULL; - } - else - *wp = 0, tp = ++wp; - } - else - *wp = 0, tp = ++wp; + for (cp = tp; isspace (*cp); cp++) + continue; + if (*cp == 0) { + free (vp); + vp = tp = NULL; + return NULL; } - else - tp = NULL; - } - else - *wp = 0, tp = ++wp; - - if (adrxp->text) - free (adrxp->text); - adrxp->text = getcpy (cp); - adrxp->mbox = cp; - adrxp->host = adrxp->path = NULL; - if ((wp = strrchr(cp, '@')) != NULL) { - *wp++ = 0; - adrxp->host = *wp ? wp : NULL; - } - else - for (wp = cp + strlen (cp) - 4; wp >= cp; wp--) - if (isat (wp)) { - *wp++ = 0; - adrxp->host = wp + 3; - } - adrxp->pers = adrxp->grp = adrxp->note = adrxp->err = NULL; - adrxp->ingrp = 0; + if ((wp = strchr(cp, ',')) == NULL) { + if ((wp = strchr(cp, ' ')) != NULL) { + xp = wp; + while (isspace (*xp)) + xp++; + if (*xp != 0 && isat (--xp)) { + yp = xp + 4; + while (isspace (*yp)) + yp++; + if (*yp != 0) { + if ((zp = strchr(yp, ' ')) != NULL) + *zp = 0, tp = ++zp; + else + tp = NULL; + } else + *wp = 0, tp = ++wp; + } else + *wp = 0, tp = ++wp; + } else + tp = NULL; + } else + *wp = 0, tp = ++wp; - return adrxp; + if (adrxp->text) + free (adrxp->text); + adrxp->text = getcpy (cp); + adrxp->mbox = cp; + adrxp->host = adrxp->path = NULL; + if ((wp = strrchr(cp, '@')) != NULL) { + *wp++ = 0; + adrxp->host = *wp ? wp : NULL; + } else + for (wp = cp + strlen (cp) - 4; wp >= cp; wp--) + if (isat (wp)) { + *wp++ = 0; + adrxp->host = wp + 3; + } + + adrxp->pers = adrxp->grp = adrxp->note = adrxp->err = NULL; + adrxp->ingrp = 0; + + return adrxp; } static void compress (char *fp, unsigned char *tp) { - register char c; - register unsigned char *cp; - - for (c = ' ', cp = tp; (*tp = *fp++) != 0;) - if (isspace (*tp)) { - if (c != ' ') - *tp++ = c = ' '; - } - else - c = *tp++; - - if (c == ' ' && cp < tp) - *--tp = 0; + register char c; + register unsigned char *cp; + + for (c = ' ', cp = tp; (*tp = *fp++) != 0;) + if (isspace (*tp)) { + if (c != ' ') + *tp++ = c = ' '; + } else + c = *tp++; + + if (c == ' ' && cp < tp) + *--tp = 0; } static int isat (char *p) { - return (strncmp (p, " AT ", 4) - && strncmp (p, " At ", 4) - && strncmp (p, " aT ", 4) - && strncmp (p, " at ", 4) ? FALSE : TRUE); + return (strncmp (p, " AT ", 4) + && strncmp (p, " At ", 4) + && strncmp (p, " aT ", 4) + && strncmp (p, " at ", 4) ? FALSE : TRUE); } @@ -240,12 +231,12 @@ isat (char *p) * of the 822 address syntax. In addition it handles the majority of the * 733 syntax as well. Most problems arise from trying to accomodate both. * - * In terms of 822, the route-specification in + * In terms of 822, the route-specification in * - * "<" [route] local-part "@" domain ">" + * "<" [route] local-part "@" domain ">" * * is parsed and returned unchanged. Multiple at-signs are compressed - * via source-routing. Recursive groups are not allowed as per the + * via source-routing. Recursive groups are not allowed as per the * standard. * * In terms of 733, " at " is recognized as equivalent to "@". @@ -254,13 +245,13 @@ isat (char *p) * * ----- * - * We should not allow addresses like + * We should not allow addresses like * - * Marshall T. Rose + * Marshall T. Rose * * but should insist on * - * "Marshall T. Rose" + * "Marshall T. Rose" * * Unfortunately, a lot of mailers stupidly let people get away with this. * @@ -268,11 +259,11 @@ isat (char *p) * * We should not allow addresses like * - * + * * * but should insist on * - * MRose@UCI + * MRose@UCI * * Unfortunately, a lot of mailers stupidly let people's UAs get away with * this. @@ -281,51 +272,51 @@ isat (char *p) * * We should not allow addresses like * - * @UCI:MRose@UCI-750a + * @UCI:MRose@UCI-750a * * but should insist on * - * Marshall Rose <@UCI:MRose@UCI-750a> + * Marshall Rose <@UCI:MRose@UCI-750a> * * Unfortunately, a lot of mailers stupidly do this. * */ -#define QUOTE '\\' - -#define LX_END 0 -#define LX_ERR 1 -#define LX_ATOM 2 -#define LX_QSTR 3 -#define LX_DLIT 4 -#define LX_SEMI 5 -#define LX_COMA 6 -#define LX_LBRK 7 -#define LX_RBRK 8 -#define LX_COLN 9 -#define LX_DOT 10 -#define LX_AT 11 +#define QUOTE '\\' + +#define LX_END 0 +#define LX_ERR 1 +#define LX_ATOM 2 +#define LX_QSTR 3 +#define LX_DLIT 4 +#define LX_SEMI 5 +#define LX_COMA 6 +#define LX_LBRK 7 +#define LX_RBRK 8 +#define LX_COLN 9 +#define LX_DOT 10 +#define LX_AT 11 struct specials { - char lx_chr; - int lx_val; + char lx_chr; + int lx_val; }; static struct specials special[] = { - { ';', LX_SEMI }, - { ',', LX_COMA }, - { '<', LX_LBRK }, - { '>', LX_RBRK }, - { ':', LX_COLN }, - { '.', LX_DOT }, - { '@', LX_AT }, - { '(', LX_ERR }, - { ')', LX_ERR }, - { QUOTE, LX_ERR }, - { '"', LX_ERR }, - { '[', LX_ERR }, - { ']', LX_ERR }, - { 0, 0 } + { ';', LX_SEMI }, + { ',', LX_COMA }, + { '<', LX_LBRK }, + { '>', LX_RBRK }, + { ':', LX_COLN }, + { '.', LX_DOT }, + { '@', LX_AT }, + { '(', LX_ERR }, + { ')', LX_ERR }, + { QUOTE, LX_ERR }, + { '"', LX_ERR }, + { '[', LX_ERR }, + { ']', LX_ERR }, + { 0, 0 } }; static int glevel = 0; @@ -350,619 +341,616 @@ static struct adrx adrxs2; struct adrx * getadrx (char *addrs) { - register char *bp; - register struct adrx *adrxp = &adrxs2; - - if (pers) - free (pers); - if (mbox) - free (mbox); - if (host) - free (host); - if (path) - free (path); - if (grp) - free (grp); - if (note) - free (note); - pers = mbox = host = path = grp = note = NULL; - err[0] = 0; - - if (dp == NULL) { - dp = cp = getcpy (addrs ? addrs : ""); - glevel = 0; - } - else - if (cp == NULL) { - free (dp); - dp = NULL; - return NULL; + register char *bp; + register struct adrx *adrxp = &adrxs2; + + if (pers) + free (pers); + if (mbox) + free (mbox); + if (host) + free (host); + if (path) + free (path); + if (grp) + free (grp); + if (note) + free (note); + pers = mbox = host = path = grp = note = NULL; + err[0] = 0; + + if (dp == NULL) { + dp = cp = getcpy (addrs ? addrs : ""); + glevel = 0; + } else if (cp == NULL) { + free (dp); + dp = NULL; + return NULL; } - switch (parse_address ()) { - case DONE: - free (dp); - dp = cp = NULL; - return NULL; - - case OK: - switch (last_lex) { - case LX_COMA: - case LX_END: - break; - - default: /* catch trailing comments */ - bp = cp; - my_lex (adr); - cp = bp; - break; - } - break; - - default: - break; - } + switch (parse_address ()) { + case DONE: + free (dp); + dp = cp = NULL; + return NULL; + + case OK: + switch (last_lex) { + case LX_COMA: + case LX_END: + break; + + default: /* catch trailing comments */ + bp = cp; + my_lex (adr); + cp = bp; + break; + } + break; - if (err[0]) - for (;;) { - switch (last_lex) { - case LX_COMA: - case LX_END: - break; - - default: - my_lex (adr); - continue; - } - break; - } - while (isspace (*ap)) - ap++; - if (cp) - sprintf (adr, "%.*s", (int)(cp - ap), ap); - else - strcpy (adr, ap); - bp = adr + strlen (adr) - 1; - if (*bp == ',' || *bp == ';' || *bp == '\n') - *bp = 0; + default: + break; + } - adrxp->text = adr; - adrxp->pers = pers; - adrxp->mbox = mbox; - adrxp->host = host; - adrxp->path = path; - adrxp->grp = grp; - adrxp->ingrp = ingrp; - adrxp->note = note; - adrxp->err = err[0] ? err : NULL; - - return adrxp; + if (err[0]) + for (;;) { + switch (last_lex) { + case LX_COMA: + case LX_END: + break; + + default: + my_lex (adr); + continue; + } + break; + } + while (isspace (*ap)) + ap++; + if (cp) + sprintf (adr, "%.*s", (int)(cp - ap), ap); + else + strcpy (adr, ap); + bp = adr + strlen (adr) - 1; + if (*bp == ',' || *bp == ';' || *bp == '\n') + *bp = 0; + + adrxp->text = adr; + adrxp->pers = pers; + adrxp->mbox = mbox; + adrxp->host = host; + adrxp->path = path; + adrxp->grp = grp; + adrxp->ingrp = ingrp; + adrxp->note = note; + adrxp->err = err[0] ? err : NULL; + + return adrxp; } static int parse_address (void) { - char buffer[BUFSIZ]; + char buffer[BUFSIZ]; again: ; - ap = cp; - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_QSTR: - pers = getcpy (buffer); - break; - - case LX_SEMI: - if (glevel-- <= 0) { - strcpy (err, "extraneous semi-colon"); - return NOTOK; - } - case LX_COMA: - if (note) { - free (note); - note = NULL; - } - goto again; + ap = cp; + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_QSTR: + pers = getcpy (buffer); + break; - case LX_END: - return DONE; + case LX_SEMI: + if (glevel-- <= 0) { + strcpy (err, "extraneous semi-colon"); + return NOTOK; + } + case LX_COMA: + if (note) { + free (note); + note = NULL; + } + goto again; - case LX_LBRK: /* sigh (2) */ - goto get_addr; + case LX_END: + return DONE; - case LX_AT: /* sigh (3) */ - cp = ap; - if (route_addr (buffer) == NOTOK) - return NOTOK; - return OK; /* why be choosy? */ - - default: - sprintf (err, "illegal address construct (%s)", buffer); - return NOTOK; - } - - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_QSTR: - pers = add (buffer, add (" ", pers)); - more_phrase: ; /* sigh (1) */ - if (phrase (buffer) == NOTOK) - return NOTOK; + case LX_LBRK: /* sigh (2) */ + goto get_addr; - switch (last_lex) { - case LX_LBRK: - get_addr: ; - if (route_addr (buffer) == NOTOK) - return NOTOK; - if (last_lex == LX_RBRK) - return OK; - sprintf (err, "missing right-bracket (%s)", buffer); - return NOTOK; + case LX_AT: /* sigh (3) */ + cp = ap; + if (route_addr (buffer) == NOTOK) + return NOTOK; + return OK; /* why be choosy? */ - case LX_COLN: - get_group: ; - if (glevel++ > 0) { - sprintf (err, "nested groups not allowed (%s)", pers); + default: + sprintf (err, "illegal address construct (%s)", buffer); return NOTOK; - } - grp = add (": ", pers); - pers = NULL; - { - char *pp = cp; - - for (;;) - switch (my_lex (buffer)) { - case LX_SEMI: - case LX_END: /* tsk, tsk */ - glevel--; - return OK; - - case LX_COMA: - continue; - - default: - cp = pp; - return parse_address (); - } - } - - case LX_DOT: /* sigh (1) */ - pers = add (".", pers); - goto more_phrase; - - default: - sprintf (err, "no mailbox in address, only a phrase (%s%s)", - pers, buffer); - return NOTOK; - } - - case LX_LBRK: - goto get_addr; - - case LX_COLN: - goto get_group; - - case LX_DOT: - mbox = add (buffer, pers); - pers = NULL; - if (route_addr (buffer) == NOTOK) - return NOTOK; - goto check_end; + } - case LX_AT: - ingrp = glevel; - mbox = pers; - pers = NULL; - if (domain (buffer) == NOTOK) - return NOTOK; - check_end: ; - switch (last_lex) { - case LX_SEMI: - if (glevel-- <= 0) { - strcpy (err, "extraneous semi-colon"); + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_QSTR: + pers = add (buffer, add (" ", pers)); + more_phrase: ; /* sigh (1) */ + if (phrase (buffer) == NOTOK) + return NOTOK; + + switch (last_lex) { + case LX_LBRK: + get_addr: ; + if (route_addr (buffer) == NOTOK) + return NOTOK; + if (last_lex == LX_RBRK) + return OK; + sprintf (err, "missing right-bracket (%s)", buffer); + return NOTOK; + + case LX_COLN: + get_group: ; + if (glevel++ > 0) { + sprintf (err, "nested groups not allowed (%s)", pers); + return NOTOK; + } + grp = add (": ", pers); + pers = NULL; + { + char *pp = cp; + + for (;;) + switch (my_lex (buffer)) { + case LX_SEMI: + case LX_END: /* tsk, tsk */ + glevel--; + return OK; + + case LX_COMA: + continue; + + default: + cp = pp; + return parse_address (); + } + } + + case LX_DOT: /* sigh (1) */ + pers = add (".", pers); + goto more_phrase; + + default: + sprintf (err, "no mailbox in address, only a phrase (%s%s)", pers, buffer); + return NOTOK; + } + + case LX_LBRK: + goto get_addr; + + case LX_COLN: + goto get_group; + + case LX_DOT: + mbox = add (buffer, pers); + pers = NULL; + if (route_addr (buffer) == NOTOK) + return NOTOK; + goto check_end; + + case LX_AT: + ingrp = glevel; + mbox = pers; + pers = NULL; + if (domain (buffer) == NOTOK) + return NOTOK; + check_end: ; + switch (last_lex) { + case LX_SEMI: + if (glevel-- <= 0) { + strcpy (err, "extraneous semi-colon"); + return NOTOK; + } + case LX_COMA: + case LX_END: + return OK; + + default: + sprintf (err, "junk after local@domain (%s)", buffer); + return NOTOK; + } + + case LX_SEMI: /* no host */ + case LX_COMA: + case LX_END: + ingrp = glevel; + if (last_lex == LX_SEMI && glevel-- <= 0) { + strcpy (err, "extraneous semi-colon"); + return NOTOK; + } + mbox = pers; + pers = NULL; + return OK; + + default: + sprintf (err, "missing mailbox (%s)", buffer); return NOTOK; - } - case LX_COMA: - case LX_END: - return OK; - - default: - sprintf (err, "junk after local@domain (%s)", buffer); - return NOTOK; - } - - case LX_SEMI: /* no host */ - case LX_COMA: - case LX_END: - ingrp = glevel; - if (last_lex == LX_SEMI && glevel-- <= 0) { - strcpy (err, "extraneous semi-colon"); - return NOTOK; - } - mbox = pers; - pers = NULL; - return OK; - - default: - sprintf (err, "missing mailbox (%s)", buffer); - return NOTOK; - } + } } static int phrase (char *buffer) { - for (;;) - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_QSTR: - pers = add (buffer, add (" ", pers)); - continue; - - default: - return OK; - } + for (;;) + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_QSTR: + pers = add (buffer, add (" ", pers)); + continue; + + default: + return OK; + } } static int route_addr (char *buffer) { - register char *pp = cp; - - if (my_lex (buffer) == LX_AT) { - if (route (buffer) == NOTOK) - return NOTOK; - } - else - cp = pp; - - if (local_part (buffer) == NOTOK) - return NOTOK; - - switch (last_lex) { - case LX_AT: - return domain (buffer); - - case LX_SEMI: /* if in group */ - case LX_RBRK: /* no host */ - case LX_COMA: - case LX_END: - return OK; - - default: - sprintf (err, "no at-sign after local-part (%s)", buffer); - return NOTOK; - } + register char *pp = cp; + + if (my_lex (buffer) == LX_AT) { + if (route (buffer) == NOTOK) + return NOTOK; + } + else + cp = pp; + + if (local_part (buffer) == NOTOK) + return NOTOK; + + switch (last_lex) { + case LX_AT: + return domain (buffer); + + case LX_SEMI: /* if in group */ + case LX_RBRK: /* no host */ + case LX_COMA: + case LX_END: + return OK; + + default: + sprintf (err, "no at-sign after local-part (%s)", buffer); + return NOTOK; + } } static int local_part (char *buffer) { - ingrp = glevel; + ingrp = glevel; - for (;;) { - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_QSTR: - mbox = add (buffer, mbox); - break; - - default: - sprintf (err, "no mailbox in local-part (%s)", buffer); - return NOTOK; - } + for (;;) { + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_QSTR: + mbox = add (buffer, mbox); + break; + + default: + sprintf (err, "no mailbox in local-part (%s)", buffer); + return NOTOK; + } - switch (my_lex (buffer)) { - case LX_DOT: - mbox = add (buffer, mbox); - continue; + switch (my_lex (buffer)) { + case LX_DOT: + mbox = add (buffer, mbox); + continue; - default: - return OK; + default: + return OK; + } } - } } static int domain (char *buffer) { - for (;;) { - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_DLIT: - host = add (buffer, host); - break; - - default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); - return NOTOK; - } + for (;;) { + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_DLIT: + host = add (buffer, host); + break; + + default: + sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + return NOTOK; + } - switch (my_lex (buffer)) { - case LX_DOT: - host = add (buffer, host); - continue; + switch (my_lex (buffer)) { + case LX_DOT: + host = add (buffer, host); + continue; - case LX_AT: /* sigh (0) */ - mbox = add (host, add ("%", mbox)); - free (host); - host = NULL; - continue; + case LX_AT: /* sigh (0) */ + mbox = add (host, add ("%", mbox)); + free (host); + host = NULL; + continue; - default: - return OK; + default: + return OK; + } } - } } static int route (char *buffer) { - path = getcpy ("@"); - - for (;;) { - switch (my_lex (buffer)) { - case LX_ATOM: - case LX_DLIT: - path = add (buffer, path); - break; + path = getcpy ("@"); - default: - sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); - return NOTOK; - } - switch (my_lex (buffer)) { - case LX_COMA: - path = add (buffer, path); - for (;;) { - switch (my_lex (buffer)) { - case LX_COMA: - continue; - - case LX_AT: - path = add (buffer, path); - break; - - default: - sprintf (err, "no at-sign found for next domain in route (%s)", - buffer); - } - break; + for (;;) { + switch (my_lex (buffer)) { + case LX_ATOM: + case LX_DLIT: + path = add (buffer, path); + break; + + default: + sprintf (err, "no sub-domain in domain-part of address (%s)", buffer); + return NOTOK; + } + switch (my_lex (buffer)) { + case LX_COMA: + path = add (buffer, path); + for (;;) { + switch (my_lex (buffer)) { + case LX_COMA: + continue; + + case LX_AT: + path = add (buffer, path); + break; + + default: + sprintf (err, "no at-sign found for next domain in route (%s)", + buffer); + } + break; + } + continue; + + case LX_AT: /* XXX */ + case LX_DOT: + path = add (buffer, path); + continue; + + case LX_COLN: + path = add (buffer, path); + return OK; + + default: + sprintf (err, "no colon found to terminate route (%s)", buffer); + return NOTOK; } - continue; - - case LX_AT: /* XXX */ - case LX_DOT: - path = add (buffer, path); - continue; - - case LX_COLN: - path = add (buffer, path); - return OK; - - default: - sprintf (err, "no colon found to terminate route (%s)", buffer); - return NOTOK; } - } } static int my_lex (char *buffer) { - /* buffer should be at least BUFSIZ bytes long */ - int i, gotat = 0; - register unsigned char c; - register char *bp; + /* buffer should be at least BUFSIZ bytes long */ + int i, gotat = 0; + register unsigned char c; + register char *bp; /* Add C to the buffer bp. After use of this macro *bp is guaranteed to be within the buffer. */ #define ADDCHR(C) do { *bp++ = (C); if ((bp - buffer) == (BUFSIZ-1)) goto my_lex_buffull; } while (0) - bp = buffer; - *bp = 0; - if (!cp) - return (last_lex = LX_END); + bp = buffer; + *bp = 0; + if (!cp) + return (last_lex = LX_END); - gotat = isat (cp); - c = *cp++; - while (isspace (c)) + gotat = isat (cp); c = *cp++; - if (c == 0) { - cp = NULL; - return (last_lex = LX_END); - } + while (isspace (c)) + c = *cp++; + if (c == 0) { + cp = NULL; + return (last_lex = LX_END); + } - if (c == '(') { - ADDCHR(c); - for (i = 0;;) - switch (c = *cp++) { - case 0: - cp = NULL; - return (last_lex = LX_ERR); - case QUOTE: - ADDCHR(c); - if ((c = *cp++) == 0) { - cp = NULL; - return (last_lex = LX_ERR); - } - ADDCHR(c); - continue; - case '(': - i++; - default: - ADDCHR(c); - continue; - case ')': - ADDCHR(c); - if (--i < 0) { - *bp = 0; - note = note ? add (buffer, add (" ", note)) - : getcpy (buffer); - return my_lex (buffer); - } - } - } - - if (c == '"') { - ADDCHR(c); - for (;;) - switch (c = *cp++) { - case 0: - cp = NULL; - return (last_lex = LX_ERR); - case QUOTE: - ADDCHR(c); - if ((c = *cp++) == 0) { - cp = NULL; - return (last_lex = LX_ERR); - } - default: - ADDCHR(c); - continue; - case '"': - ADDCHR(c); - *bp = 0; - return (last_lex = LX_QSTR); - } - } - - if (c == '[') { - ADDCHR(c); - for (;;) - switch (c = *cp++) { - case 0: - cp = NULL; - return (last_lex = LX_ERR); - case QUOTE: - ADDCHR(c); - if ((c = *cp++) == 0) { - cp = NULL; - return (last_lex = LX_ERR); - } - default: - ADDCHR(c); - continue; - case ']': - ADDCHR(c); - *bp = 0; - return (last_lex = LX_DLIT); - } - } - - ADDCHR(c); - *bp = 0; - for (i = 0; special[i].lx_chr != 0; i++) - if (c == special[i].lx_chr) - return (last_lex = special[i].lx_val); - - if (iscntrl (c)) - return (last_lex = LX_ERR); + if (c == '(') { + ADDCHR(c); + for (i = 0;;) + switch (c = *cp++) { + case 0: + cp = NULL; + return (last_lex = LX_ERR); + case QUOTE: + ADDCHR(c); + if ((c = *cp++) == 0) { + cp = NULL; + return (last_lex = LX_ERR); + } + ADDCHR(c); + continue; + case '(': + i++; + default: + ADDCHR(c); + continue; + case ')': + ADDCHR(c); + if (--i < 0) { + *bp = 0; + note = note ? add (buffer, add (" ", note)) + : getcpy (buffer); + return my_lex (buffer); + } + } + } + + if (c == '"') { + ADDCHR(c); + for (;;) + switch (c = *cp++) { + case 0: + cp = NULL; + return (last_lex = LX_ERR); + case QUOTE: + ADDCHR(c); + if ((c = *cp++) == 0) { + cp = NULL; + return (last_lex = LX_ERR); + } + default: + ADDCHR(c); + continue; + case '"': + ADDCHR(c); + *bp = 0; + return (last_lex = LX_QSTR); + } + } + + if (c == '[') { + ADDCHR(c); + for (;;) + switch (c = *cp++) { + case 0: + cp = NULL; + return (last_lex = LX_ERR); + case QUOTE: + ADDCHR(c); + if ((c = *cp++) == 0) { + cp = NULL; + return (last_lex = LX_ERR); + } + default: + ADDCHR(c); + continue; + case ']': + ADDCHR(c); + *bp = 0; + return (last_lex = LX_DLIT); + } + } - for (;;) { - if ((c = *cp++) == 0) - break; - for (i = 0; special[i].lx_chr != 0; i++) - if (c == special[i].lx_chr) - goto got_atom; - if (iscntrl (c) || isspace (c)) - break; ADDCHR(c); - } + *bp = 0; + for (i = 0; special[i].lx_chr != 0; i++) + if (c == special[i].lx_chr) + return (last_lex = special[i].lx_val); + + if (iscntrl (c)) + return (last_lex = LX_ERR); + + for (;;) { + if ((c = *cp++) == 0) + break; + for (i = 0; special[i].lx_chr != 0; i++) + if (c == special[i].lx_chr) + goto got_atom; + if (iscntrl (c) || isspace (c)) + break; + ADDCHR(c); + } got_atom: ; - if (c == 0) - cp = NULL; - else - cp--; - *bp = 0; - last_lex = !gotat || cp == NULL || strchr(cp, '<') != NULL - ? LX_ATOM : LX_AT; - return last_lex; + if (c == 0) + cp = NULL; + else + cp--; + *bp = 0; + last_lex = !gotat || cp == NULL || strchr(cp, '<') != NULL + ? LX_ATOM : LX_AT; + return last_lex; my_lex_buffull: - /* Out of buffer space. *bp is the last byte in the buffer */ - *bp = 0; - return (last_lex = LX_ERR); + /* Out of buffer space. *bp is the last byte in the buffer */ + *bp = 0; + return (last_lex = LX_ERR); } char * legal_person (char *p) { - int i; - register char *cp; - static char buffer[BUFSIZ]; + int i; + register char *cp; + static char buffer[BUFSIZ]; + + if (*p == '"') + return p; + for (cp = p; *cp; cp++) + for (i = 0; special[i].lx_chr; i++) + if (*cp == special[i].lx_chr) { + sprintf (buffer, "\"%s\"", p); + return buffer; + } - if (*p == '"') return p; - for (cp = p; *cp; cp++) - for (i = 0; special[i].lx_chr; i++) - if (*cp == special[i].lx_chr) { - sprintf (buffer, "\"%s\"", p); - return buffer; - } - - return p; } int mfgets (FILE *in, char **bp) { - int i; - register char *cp, *dp, *ep; - static int len = 0; - static char *pp = NULL; - - if (pp == NULL) - pp = mh_xmalloc ((size_t) (len = BUFSIZ)); - - for (ep = (cp = pp) + len - 2;;) { - switch (i = getc (in)) { - case EOF: - eol: ; - if (cp != pp) { - *cp = 0; - *bp = pp; - return OK; - } - eoh: ; - *bp = NULL; - free (pp); - pp = NULL; - return DONE; + int i; + register char *cp, *dp, *ep; + static int len = 0; + static char *pp = NULL; - case 0: - continue; + if (pp == NULL) + pp = mh_xmalloc ((size_t) (len = BUFSIZ)); - case '\n': - if (cp == pp) /* end of headers, gobble it */ - goto eoh; + for (ep = (cp = pp) + len - 2;;) { switch (i = getc (in)) { - default: /* end of line */ - case '\n': /* end of headers, save for next call */ - ungetc (i, in); - goto eol; - - case ' ': /* continue headers */ - case '\t': - *cp++ = '\n'; - break; - } /* fall into default case */ - - default: - *cp++ = i; - break; - } - if (cp >= ep) { - dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ)); - cp += dp - pp, ep = (pp = cp) + len - 2; + case EOF: + eol: ; + if (cp != pp) { + *cp = 0; + *bp = pp; + return OK; + } + eoh: ; + *bp = NULL; + free (pp); + pp = NULL; + return DONE; + + case 0: + continue; + + case '\n': + if (cp == pp) /* end of headers, gobble it */ + goto eoh; + switch (i = getc (in)) { + default: /* end of line */ + case '\n': /* end of headers, save for next call */ + ungetc (i, in); + goto eol; + + case ' ': /* continue headers */ + case '\t': + *cp++ = '\n'; + break; + } /* fall into default case */ + + default: + *cp++ = i; + break; + } + if (cp >= ep) { + dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ)); + cp += dp - pp, ep = (pp = cp) + len - 2; + } } - } } diff --git a/sbr/mts.c b/sbr/mts.c index 6418ef5..4e02831 100644 --- a/sbr/mts.c +++ b/sbr/mts.c @@ -1,4 +1,3 @@ - /* * mts.c -- definitions for the mail transport system * @@ -23,8 +22,8 @@ # include #endif -#define NOTOK (-1) -#define OK 0 +#define NOTOK (-1) +#define OK 0 /* * static prototypes @@ -61,10 +60,10 @@ static char username[BUFSIZ]; static char fullname[BUFSIZ]; /* Variables for username masquerading: */ - boolean draft_from_masquerading = FALSE; +boolean draft_from_masquerading = FALSE; static boolean mmailid_masquerading = FALSE; - boolean username_extension_masquerading = FALSE; /* " from addrsbr.c */ -static char* masquerade = ""; +boolean username_extension_masquerading = FALSE; /* " from addrsbr.c */ +static char* masquerade = ""; /* * Global MailDelivery file @@ -85,22 +84,22 @@ char *NoShell = ""; */ struct bind { - char *keyword; - char **value; + char *keyword; + char **value; }; static struct bind binds[] = { - { "mmdfldir", &mmdfldir }, - { "mmdflfil", &mmdflfil }, - { "uucpldir", &uucpldir }, - { "uucplfil", &uucplfil }, - { "mmdelim1", &mmdlm1 }, - { "mmdelim2", &mmdlm2 }, - { "masquerade", &masquerade }, - { "maildelivery", &maildelivery }, - { "everyone", &everyone }, - { "noshell", &NoShell }, - { NULL, NULL } + { "mmdfldir", &mmdfldir }, + { "mmdflfil", &mmdflfil }, + { "uucpldir", &uucpldir }, + { "uucplfil", &uucplfil }, + { "mmdelim1", &mmdlm1 }, + { "mmdelim2", &mmdlm2 }, + { "masquerade", &masquerade }, + { "maildelivery", &maildelivery }, + { "everyone", &everyone }, + { "noshell", &NoShell }, + { NULL, NULL } }; @@ -112,36 +111,36 @@ static struct bind binds[] = { void mts_init (char *name) { - const char *cp; - FILE *fp; - static int inited = 0; - - if (inited++ || (fp = fopen (get_mtsconf_pathname(), "r")) == NULL) - return; - mts_read_conf_file(fp); - fclose (fp); - - cp = get_mtsuserconf_pathname(); - if (cp != NULL && - ((fp = fopen (get_mtsuserconf_pathname(), "r")) != NULL)) { - mts_read_conf_file(fp); - fclose (fp); - } + const char *cp; + FILE *fp; + static int inited = 0; + + if (inited++ || (fp = fopen (get_mtsconf_pathname(), "r")) == NULL) + return; + mts_read_conf_file(fp); + fclose (fp); + + cp = get_mtsuserconf_pathname(); + if (cp != NULL && + ((fp = fopen (get_mtsuserconf_pathname(), "r")) != NULL)) { + mts_read_conf_file(fp); + fclose (fp); + } - Everyone = atoi (everyone); + Everyone = atoi (everyone); - if (strstr(masquerade, "draft_from") != NULL) - draft_from_masquerading = TRUE; + if (strstr(masquerade, "draft_from") != NULL) + draft_from_masquerading = TRUE; - if (strstr(masquerade, "mmailid") != NULL) - mmailid_masquerading = TRUE; + if (strstr(masquerade, "mmailid") != NULL) + mmailid_masquerading = TRUE; - if (strstr(masquerade, "username_extension") != NULL) - username_extension_masquerading = TRUE; + if (strstr(masquerade, "username_extension") != NULL) + username_extension_masquerading = TRUE; } -#define QUOTE '\\' +#define QUOTE '\\' /* * Convert escaped values, malloc some new space, @@ -151,47 +150,47 @@ mts_init (char *name) static char * tailor_value (unsigned char *s) { - int i, r; - char *bp; - char buffer[BUFSIZ]; - size_t len; - - for (bp = buffer; *s; bp++, s++) { - if (*s != QUOTE) { - *bp = *s; - } else { - switch (*++s) { - case 'b': *bp = '\b'; break; - case 'f': *bp = '\f'; break; - case 'n': *bp = '\n'; break; - case 't': *bp = '\t'; break; - - case 0: s--; - case QUOTE: - *bp = QUOTE; - break; - - default: - if (!isdigit (*s)) { - *bp++ = QUOTE; + int i, r; + char *bp; + char buffer[BUFSIZ]; + size_t len; + + for (bp = buffer; *s; bp++, s++) { + if (*s != QUOTE) { *bp = *s; - } - r = *s != '0' ? 10 : 8; - for (i = 0; isdigit (*s); s++) - i = i * r + *s - '0'; - s--; - *bp = toascii (i); - break; - } + } else { + switch (*++s) { + case 'b': *bp = '\b'; break; + case 'f': *bp = '\f'; break; + case 'n': *bp = '\n'; break; + case 't': *bp = '\t'; break; + + case 0: s--; + case QUOTE: + *bp = QUOTE; + break; + + default: + if (!isdigit (*s)) { + *bp++ = QUOTE; + *bp = *s; + } + r = *s != '0' ? 10 : 8; + for (i = 0; isdigit (*s); s++) + i = i * r + *s - '0'; + s--; + *bp = toascii (i); + break; + } + } } - } - *bp = 0; + *bp = 0; - len = strlen (buffer) + 1; - bp = mh_xmalloc (len); - memcpy (bp, buffer, len); + len = strlen (buffer) + 1; + bp = mh_xmalloc (len); + memcpy (bp, buffer, len); - return bp; + return bp; } /* @@ -201,38 +200,38 @@ tailor_value (unsigned char *s) char * LocalName (void) { - static char buffer[BUFSIZ] = ""; - struct addrinfo hints, *res; + static char buffer[BUFSIZ] = ""; + struct addrinfo hints, *res; #ifdef HAVE_UNAME - struct utsname name; + struct utsname name; #endif - /* check if we have cached the local name */ - if (buffer[0]) - return buffer; + /* check if we have cached the local name */ + if (buffer[0]) + return buffer; - mts_init ("mts"); + mts_init ("mts"); - memset(buffer, 0, sizeof(buffer)); + memset(buffer, 0, sizeof(buffer)); #ifdef HAVE_UNAME - /* first get our local name */ - uname (&name); - strncpy (buffer, name.nodename, sizeof(buffer) - 1); + /* first get our local name */ + uname (&name); + strncpy (buffer, name.nodename, sizeof(buffer) - 1); #else - /* first get our local name */ - gethostname (buffer, sizeof(buffer) - 1); + /* first get our local name */ + gethostname (buffer, sizeof(buffer) - 1); #endif - /* now fully qualify our name */ - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = PF_UNSPEC; - if (getaddrinfo(buffer, NULL, &hints, &res) == 0) { - strncpy(buffer, res->ai_canonname, sizeof(buffer) - 1); - freeaddrinfo(res); - } + /* now fully qualify our name */ + + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + hints.ai_family = PF_UNSPEC; + if (getaddrinfo(buffer, NULL, &hints, &res) == 0) { + strncpy(buffer, res->ai_canonname, sizeof(buffer) - 1); + freeaddrinfo(res); + } - return buffer; + return buffer; } @@ -244,26 +243,26 @@ LocalName (void) char * SystemName (void) { - static char buffer[BUFSIZ] = ""; + static char buffer[BUFSIZ] = ""; #ifdef HAVE_UNAME - struct utsname name; + struct utsname name; #endif - /* check if we have cached the system name */ - if (buffer[0]) - return buffer; + /* check if we have cached the system name */ + if (buffer[0]) + return buffer; - mts_init ("mts"); + mts_init ("mts"); #ifdef HAVE_UNAME - uname (&name); - strncpy (buffer, name.nodename, sizeof(buffer)); + uname (&name); + strncpy (buffer, name.nodename, sizeof(buffer)); #else - gethostname (buffer, sizeof(buffer)); + gethostname (buffer, sizeof(buffer)); #endif - return buffer; + return buffer; } @@ -274,10 +273,10 @@ SystemName (void) char * getusername (void) { - if (username[0] == '\0') - getuserinfo(); + if (username[0] == '\0') + getuserinfo(); - return username; + return username; } @@ -289,173 +288,171 @@ getusername (void) char * getfullname (void) { - if (username[0] == '\0') - getuserinfo(); + if (username[0] == '\0') + getuserinfo(); - return fullname; + return fullname; } /* * Find the user's username and full name, and cache them. * Also, handle "mmailid" username masquerading controlled from the GECOS field - * of the passwd file. + * of the passwd file. */ static void getuserinfo (void) { - register unsigned char *cp; - register char *np; - register struct passwd *pw; - - if ((pw = getpwuid (getuid ())) == NULL - || pw->pw_name == NULL - || *pw->pw_name == '\0') { - strncpy (username, "unknown", sizeof(username)); - snprintf (fullname, sizeof(fullname), "The Unknown User-ID (%d)", - (int) getuid ()); - return; - } + register unsigned char *cp; + register char *np; + register struct passwd *pw; + + if ((pw = getpwuid (getuid ())) == NULL + || pw->pw_name == NULL + || *pw->pw_name == '\0') { + strncpy (username, "unknown", sizeof(username)); + snprintf (fullname, sizeof(fullname), "The Unknown User-ID (%d)", + (int) getuid ()); + return; + } - np = pw->pw_gecos; + np = pw->pw_gecos; - /* Get the user's real name from the GECOS field. Stop once we hit a ',', - which some OSes use to separate other 'finger' information in the GECOS - field, like phone number. Also, if mmailid masquerading is turned on due - to "mmailid" appearing on the "masquerade:" line of mts.conf, stop if we - hit a '<' (which should precede any ','s). */ + /* Get the user's real name from the GECOS field. Stop once we hit a ',', + * which some OSes use to separate other 'finger' information in the GECOS + * field, like phone number. Also, if mmailid masquerading is turned on due + * to "mmailid" appearing on the "masquerade:" line of mts.conf, stop if we + * hit a '<' (which should precede any ','s). */ #ifndef BSD42 - if (mmailid_masquerading) - /* Stop at ',' or '<'. */ - for (cp = fullname; *np != '\0' && *np != ',' && *np != '<'; - *cp++ = *np++) - continue; - else - /* Allow '<' as a legal character of the user's name. This code is - basically a duplicate of the code above the "else" -- we don't - collapse it down to one copy and put the mmailid_masquerading check - inside the loop with "(x ? y : z)" because that's inefficient and the - value'll never change while it's in there. */ - for (cp = fullname; *np != '\0' && *np != ','; - *cp++ = *np++) - continue; + if (mmailid_masquerading) + /* Stop at ',' or '<'. */ + for (cp = fullname; *np != '\0' && *np != ',' && *np != '<'; + *cp++ = *np++) + continue; + else + /* Allow '<' as a legal character of the user's name. This code is + * basically a duplicate of the code above the "else" -- we don't + * collapse it down to one copy and put the mmailid_masquerading check + * inside the loop with "(x ? y : z)" because that's inefficient and the + * value'll never change while it's in there. */ + for (cp = fullname; *np != '\0' && *np != ','; *cp++ = *np++) + continue; #else /* BSD42 */ - /* On BSD(-derived) systems, the system utilities that deal with the GECOS - field (finger, mail, sendmail, etc.) translate any '&' character in it to - the login name, with the first letter capitalized. So, for instance, - fingering a user "bob" with the GECOS field "& Jones" would reveal him to - be "In real life: Bob Jones". Surprisingly, though, the OS doesn't do - the translation for you, so we have to do it manually here. */ - if (mmailid_masquerading) - /* Stop at ',' or '<'. */ - for (cp = fullname; - *np != '\0' && *np != ',' && *np != '<';) { - if (*np == '&') { /* blech! */ - strcpy (cp, pw->pw_name); - *cp = toupper(*cp); - while (*cp) - cp++; - np++; - } else { - *cp++ = *np++; - } - } - else - /* Allow '<' as a legal character of the user's name. This code is - basically a duplicate of the code above the "else" -- we don't - collapse it down to one copy and put the mmailid_masquerading check - inside the loop with "(x ? y : z)" because that's inefficient and the - value'll never change while it's in there. */ - for (cp = fullname; - *np != '\0' && *np != ',';) { - if (*np == '&') { /* blech! */ - strcpy (cp, pw->pw_name); - *cp = toupper(*cp); - while (*cp) - cp++; - np++; - } else { - *cp++ = *np++; - } - } + /* On BSD(-derived) systems, the system utilities that deal with the GECOS + * field (finger, mail, sendmail, etc.) translate any '&' character in it to + * the login name, with the first letter capitalized. So, for instance, + * fingering a user "bob" with the GECOS field "& Jones" would reveal him to + * be "In real life: Bob Jones". Surprisingly, though, the OS doesn't do + * the translation for you, so we have to do it manually here. */ + if (mmailid_masquerading) + /* Stop at ',' or '<'. */ + for (cp = fullname; + *np != '\0' && *np != ',' && *np != '<';) { + if (*np == '&') { /* blech! */ + strcpy (cp, pw->pw_name); + *cp = toupper(*cp); + while (*cp) + cp++; + np++; + } else { + *cp++ = *np++; + } + } + else + /* Allow '<' as a legal character of the user's name. This code is + * basically a duplicate of the code above the "else" -- we don't + * collapse it down to one copy and put the mmailid_masquerading check + * inside the loop with "(x ? y : z)" because that's inefficient and the + * value'll never change while it's in there. */ + for (cp = fullname; *np != '\0' && *np != ',';) { + if (*np == '&') { /* blech! */ + strcpy (cp, pw->pw_name); + *cp = toupper(*cp); + while (*cp) + cp++; + np++; + } else { + *cp++ = *np++; + } + } #endif /* BSD42 */ - *cp = '\0'; - - if (mmailid_masquerading) { - /* Do mmailid processing. The GECOS field should have the form - "Full Name ". For instance, - "Dan Harkless ". Naturally, you'll want your MTA to - have an alias (e.g. in /etc/aliases) from "fakeusername" to your - account name. */ - if (*np) - np++; - for (cp = username; *np && *np != '>'; *cp++ = *np++) - continue; *cp = '\0'; - } - if (!mmailid_masquerading || *np == '\0') - strncpy (username, pw->pw_name, sizeof(username)); - /* The $SIGNATURE environment variable overrides the GECOS field's idea of - your real name. */ - if ((cp = getenv ("SIGNATURE")) && *cp) - strncpy (fullname, cp, sizeof(fullname)); + if (mmailid_masquerading) { + /* Do mmailid processing. The GECOS field should have the form + * "Full Name ". For instance, + * "Dan Harkless ". Naturally, you'll want your MTA to + * have an alias (e.g. in /etc/aliases) from "fakeusername" to your + * account name. */ + if (*np) + np++; + for (cp = username; *np && *np != '>'; *cp++ = *np++) + continue; + *cp = '\0'; + } + if (!mmailid_masquerading || *np == '\0') + strncpy (username, pw->pw_name, sizeof(username)); - if (strchr(fullname, '.')) { /* quote any .'s */ - char tmp[BUFSIZ]; + /* The $SIGNATURE environment variable overrides the GECOS field's + * idea of your real name. */ + if ((cp = getenv ("SIGNATURE")) && *cp) + strncpy (fullname, cp, sizeof(fullname)); - /* should quote "'s too */ - snprintf (tmp, sizeof(tmp), "\"%s\"", fullname); - strncpy (fullname, tmp, sizeof(fullname)); - } + if (strchr(fullname, '.')) { /* quote any .'s */ + char tmp[BUFSIZ]; - return; + /* should quote "'s too */ + snprintf (tmp, sizeof(tmp), "\"%s\"", fullname); + strncpy (fullname, tmp, sizeof(fullname)); + } + + return; } static const char* get_mtsconf_pathname (void) { - const char *cp = getenv ( "MHMTSCONF "); - if (cp != NULL && *cp != '\0') { - return cp; - } - return mtsconf; + const char *cp = getenv ( "MHMTSCONF "); + if (cp != NULL && *cp != '\0') { + return cp; + } + return mtsconf; } static const char* get_mtsuserconf_pathname (void) { - const char *cp = getenv ( "MHMTSUSERCONF" ); - if (cp != NULL && *cp != '\0') { - return cp; - } - return NULL; + const char *cp = getenv ( "MHMTSUSERCONF" ); + if (cp != NULL && *cp != '\0') { + return cp; + } + return NULL; } static void mts_read_conf_file (FILE *fp) { - unsigned char *bp; - char *cp, buffer[BUFSIZ]; - struct bind *b; - - while (fgets (buffer, sizeof(buffer), fp)) { - if (!(cp = strchr(buffer, '\n'))) - break; - *cp = 0; - if (*buffer == '#' || *buffer == '\0') - continue; - if (!(bp = strchr(buffer, ':'))) - break; - *bp++ = 0; - while (isspace (*bp)) - *bp++ = 0; - - for (b = binds; b->keyword; b++) - if (!strcmp (buffer, b->keyword)) - break; - if (b->keyword && (cp = tailor_value (bp))) - *b->value = cp; - } + unsigned char *bp; + char *cp, buffer[BUFSIZ]; + struct bind *b; + + while (fgets (buffer, sizeof(buffer), fp)) { + if (!(cp = strchr(buffer, '\n'))) + break; + *cp = 0; + if (*buffer == '#' || *buffer == '\0') + continue; + if (!(bp = strchr(buffer, ':'))) + break; + *bp++ = 0; + while (isspace (*bp)) + *bp++ = 0; + + for (b = binds; b->keyword; b++) + if (!strcmp (buffer, b->keyword)) + break; + if (b->keyword && (cp = tailor_value (bp))) + *b->value = cp; + } } diff --git a/sbr/norm_charmap.c b/sbr/norm_charmap.c index ae81046..8ec544f 100644 --- a/sbr/norm_charmap.c +++ b/sbr/norm_charmap.c @@ -33,80 +33,82 @@ static char buf[16]; char * norm_charmap(char *name) { - char *p; - - if (!name) - return name; - - /* Many need no remapping, but they are listed here so you - * can see what output to expect, and modify for your needs - * as necessary. */ - if (!strcmp(name, "UTF-8")) - return "UTF-8"; - if (!strcmp(name, "EUC-JP")) - return "EUC-JP"; - if (!strcmp(name, "EUC-KR")) - return "EUC-KR"; - if (!strcmp(name, "EUC-TW")) - return "EUC-TW"; - if (!strcmp(name, "KOI8-R")) - return "KOI8-R"; - if (!strcmp(name, "KOI8-U")) - return "KOI8-U"; - if (!strcmp(name, "GBK")) - return "GBK"; - if (!strcmp(name, "GB2312")) - return "GB2312"; - if (!strcmp(name, "GB18030")) - return "GB18030"; - if (!strcmp(name, "VSCII")) - return "VSCII"; - - /* ASCII comes in many names */ - if (!strcmp(name, "ASCII") || - !strcmp(name, "US-ASCII") || - !strcmp(name, "ANSI_X3.4-1968") || - !strcmp(name, "646") || - !strcmp(name, "ISO646") || - !strcmp(name, "ISO_646.IRV")) - return "US-ASCII"; + char *p; - /* ISO 8859 will be converted to "ISO-8859-x" */ - if ((p = strstr(name, "8859-"))) { - memcpy(buf, "ISO-8859-\0\0", 12); - p += 5; - if (digit(*p)) { - buf[9] = *p++; - if (digit(*p)) buf[10] = *p++; - return buf; - } - } + if (!name) + return name; - /* Windows code pages will be converted to "WINDOWS-12xx" */ - if ((p = strstr(name, "CP12"))) { - memcpy(buf, "WINDOWS-12\0\0", 13); - p += 4; - if (digit(*p)) { - buf[10] = *p++; - if (digit(*p)) buf[11] = *p++; - return buf; - } - } + /* Many need no remapping, but they are listed here so you + * can see what output to expect, and modify for your needs + * as necessary. */ + if (!strcmp(name, "UTF-8")) + return "UTF-8"; + if (!strcmp(name, "EUC-JP")) + return "EUC-JP"; + if (!strcmp(name, "EUC-KR")) + return "EUC-KR"; + if (!strcmp(name, "EUC-TW")) + return "EUC-TW"; + if (!strcmp(name, "KOI8-R")) + return "KOI8-R"; + if (!strcmp(name, "KOI8-U")) + return "KOI8-U"; + if (!strcmp(name, "GBK")) + return "GBK"; + if (!strcmp(name, "GB2312")) + return "GB2312"; + if (!strcmp(name, "GB18030")) + return "GB18030"; + if (!strcmp(name, "VSCII")) + return "VSCII"; - /* TIS-620 comes in at least the following two forms */ - if (!strcmp(name, "TIS-620") || - !strcmp(name, "TIS620.2533")) - return "ISO-8859-11"; + /* ASCII comes in many names */ + if (!strcmp(name, "ASCII") || + !strcmp(name, "US-ASCII") || + !strcmp(name, "ANSI_X3.4-1968") || + !strcmp(name, "646") || + !strcmp(name, "ISO646") || + !strcmp(name, "ISO_646.IRV")) + return "US-ASCII"; - /* For some, uppercase/lowercase might differ */ - if (!strcmp(name, "Big5") || !strcmp(name, "BIG5")) - return "Big5"; - if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS")) - return "Big5HKSCS"; + /* ISO 8859 will be converted to "ISO-8859-x" */ + if ((p = strstr(name, "8859-"))) { + memcpy(buf, "ISO-8859-\0\0", 12); + p += 5; + if (digit(*p)) { + buf[9] = *p++; + if (digit(*p)) + buf[10] = *p++; + return buf; + } + } - /* I don't know of any implementation of nl_langinfo(CODESET) out - * there that returns anything else (and I'm not even certain all of - * the above occur in the wild), but just in case, as a fallback, - * return the unmodified name. */ - return name; + /* Windows code pages will be converted to "WINDOWS-12xx" */ + if ((p = strstr(name, "CP12"))) { + memcpy(buf, "WINDOWS-12\0\0", 13); + p += 4; + if (digit(*p)) { + buf[10] = *p++; + if (digit(*p)) + buf[11] = *p++; + return buf; + } + } + + /* TIS-620 comes in at least the following two forms */ + if (!strcmp(name, "TIS-620") || + !strcmp(name, "TIS620.2533")) + return "ISO-8859-11"; + + /* For some, uppercase/lowercase might differ */ + if (!strcmp(name, "Big5") || !strcmp(name, "BIG5")) + return "Big5"; + if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS")) + return "Big5HKSCS"; + + /* I don't know of any implementation of nl_langinfo(CODESET) out + * there that returns anything else (and I'm not even certain all of + * the above occur in the wild), but just in case, as a fallback, + * return the unmodified name. */ + return name; } diff --git a/sbr/path.c b/sbr/path.c index 5a9529d..a01385f 100644 --- a/sbr/path.c +++ b/sbr/path.c @@ -1,4 +1,3 @@ - /* * path.c -- return a pathname * @@ -9,12 +8,12 @@ #include -#define CWD "./" -#define NCWD (sizeof(CWD) - 1) -#define DOT "." -#define DOTDOT ".." -#define PWD "../" -#define NPWD (sizeof(PWD) - 1) +#define CWD "./" +#define NCWD (sizeof(CWD) - 1) +#define DOT "." +#define DOTDOT ".." +#define PWD "../" +#define NPWD (sizeof(PWD) - 1) static char *pwds; @@ -33,136 +32,132 @@ pluspath(char *name) char * path(char *name, int flag) { - register char *cp, *ep; + register char *cp, *ep; - if ((cp = expath (name, flag)) - && (ep = cp + strlen (cp) - 1) > cp - && *ep == '/') - *ep = '\0'; + if ((cp = expath (name, flag)) + && (ep = cp + strlen (cp) - 1) > cp + && *ep == '/') + *ep = '\0'; - return cp; + return cp; } static char * expath (char *name, int flag) { - register char *cp, *ep; - char buffer[BUFSIZ]; - - if (flag == TSUBCWF) { - snprintf (buffer, sizeof(buffer), "%s/%s", getfolder (1), name); - name = m_mailpath (buffer); - compath (name); - snprintf (buffer, sizeof(buffer), "%s/", m_maildir ("")); - if (ssequal (buffer, name)) { - cp = name; - name = getcpy (name + strlen (buffer)); - free (cp); + register char *cp, *ep; + char buffer[BUFSIZ]; + + if (flag == TSUBCWF) { + snprintf (buffer, sizeof(buffer), "%s/%s", getfolder (1), name); + name = m_mailpath (buffer); + compath (name); + snprintf (buffer, sizeof(buffer), "%s/", m_maildir ("")); + if (ssequal (buffer, name)) { + cp = name; + name = getcpy (name + strlen (buffer)); + free (cp); + } + flag = TFOLDER; } - flag = TFOLDER; - } - - if (*name == '/' - || (flag == TFOLDER - && (strncmp (name, CWD, NCWD) - && strcmp (name, DOT) - && strcmp (name, DOTDOT) - && strncmp (name, PWD, NPWD)))) - return getcpy (name); - - if (pwds == NULL) - pwds = pwd (); - - if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0) - return getcpy (pwds); - - ep = pwds + strlen (pwds); - if ((cp = strrchr(pwds, '/')) == NULL) - cp = ep; - else - if (cp == pwds) - cp++; - - if (strncmp (name, CWD, NCWD) == 0) - name += NCWD; - - if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) { - snprintf (buffer, sizeof(buffer), "%.*s", (int)(cp - pwds), pwds); - return getcpy (buffer); - } - if (strncmp (name, PWD, NPWD) == 0) - name += NPWD; - else - cp = ep; + if (*name == '/' || (flag == TFOLDER + && (strncmp (name, CWD, NCWD) && strcmp (name, DOT) + && strcmp (name, DOTDOT) && strncmp (name, PWD, NPWD)))) + return getcpy (name); + + if (pwds == NULL) + pwds = pwd (); + + if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0) + return getcpy (pwds); - snprintf (buffer, sizeof(buffer), "%.*s/%s", (int)(cp - pwds), pwds, name); - return getcpy (buffer); + ep = pwds + strlen (pwds); + if ((cp = strrchr(pwds, '/')) == NULL) + cp = ep; + else + if (cp == pwds) + cp++; + + if (strncmp (name, CWD, NCWD) == 0) + name += NCWD; + + if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) { + snprintf (buffer, sizeof(buffer), "%.*s", (int)(cp - pwds), pwds); + return getcpy (buffer); + } + + if (strncmp (name, PWD, NPWD) == 0) + name += NPWD; + else + cp = ep; + + snprintf (buffer, sizeof(buffer), "%.*s/%s", (int)(cp - pwds), pwds, name); + return getcpy (buffer); } static void compath (char *f) { - register char *cp, *dp; - - if (*f != '/') - return; - - for (cp = f; *cp;) - if (*cp == '/') { - switch (*++cp) { - case 0: - if (--cp > f) - *cp = '\0'; - break; - - case '/': - for (dp = cp; *dp == '/'; dp++) - continue; - strcpy (cp--, dp); - continue; - - case '.': - if (strcmp (cp, DOT) == 0) { - if (cp > f + 1) - cp--; - *cp = '\0'; + register char *cp, *dp; + + if (*f != '/') + return; + + for (cp = f; *cp;) + if (*cp == '/') { + switch (*++cp) { + case 0: + if (--cp > f) + *cp = '\0'; + break; + + case '/': + for (dp = cp; *dp == '/'; dp++) + continue; + strcpy (cp--, dp); + continue; + + case '.': + if (strcmp (cp, DOT) == 0) { + if (cp > f + 1) + cp--; + *cp = '\0'; + break; + } + if (strcmp (cp, DOTDOT) == 0) { + for (cp -= 2; cp > f; cp--) + if (*cp == '/') + break; + if (cp <= f) + cp = f + 1; + *cp = '\0'; + break; + } + if (strncmp (cp, PWD, NPWD) == 0) { + for (dp = cp - 2; dp > f; dp--) + if (*dp == '/') + break; + if (dp <= f) + dp = f; + strcpy (dp, cp + NPWD - 1); + cp = dp; + continue; + } + if (strncmp (cp, CWD, NCWD) == 0) { + strcpy (cp - 1, cp + NCWD - 1); + cp--; + continue; + } + continue; + + default: + cp++; + continue; + } break; - } - if (strcmp (cp, DOTDOT) == 0) { - for (cp -= 2; cp > f; cp--) - if (*cp == '/') - break; - if (cp <= f) - cp = f + 1; - *cp = '\0'; - break; - } - if (strncmp (cp, PWD, NPWD) == 0) { - for (dp = cp - 2; dp > f; dp--) - if (*dp == '/') - break; - if (dp <= f) - dp = f; - strcpy (dp, cp + NPWD - 1); - cp = dp; - continue; - } - if (strncmp (cp, CWD, NCWD) == 0) { - strcpy (cp - 1, cp + NCWD - 1); - cp--; - continue; - } - continue; - - default: - cp++; - continue; - } - break; - } - else - cp++; + } else + cp++; } diff --git a/sbr/peekc.c b/sbr/peekc.c index 5ed8c3f..cee7504 100644 --- a/sbr/peekc.c +++ b/sbr/peekc.c @@ -1,4 +1,3 @@ - /* * peekc.c -- peek at the next character in a stream * @@ -13,9 +12,9 @@ int peekc(FILE *fp) { - register int c; + register int c; - c = getc(fp); - ungetc(c, fp); - return c; + c = getc(fp); + ungetc(c, fp); + return c; } diff --git a/sbr/pidstatus.c b/sbr/pidstatus.c index f16f7e0..6f5f578 100644 --- a/sbr/pidstatus.c +++ b/sbr/pidstatus.c @@ -1,4 +1,3 @@ - /* * pidstatus.c -- report child's status * @@ -29,37 +28,37 @@ int pidstatus (int status, FILE *fp, char *cp) { - int signum; + int signum; -/* - * I have no idea what this is for (rc) - * so I'm commenting it out for right now. - * - * if ((status & 0xff00) == 0xff00) - * return status; - */ + /* + * I have no idea what this is for (rc) + * so I'm commenting it out for right now. + * + * if ((status & 0xff00) == 0xff00) + * return status; + */ - /* If child process returned normally */ - if (WIFEXITED(status)) { - if ((signum = WEXITSTATUS(status))) { - if (cp) - fprintf (fp, "%s: ", cp); - fprintf (fp, "exit %d\n", signum); - } - } else if (WIFSIGNALED(status)) { - /* If child process terminated due to receipt of a signal */ - signum = WTERMSIG(status); - if (signum != SIGINT) { - if (cp) - fprintf (fp, "%s: ", cp); - fprintf (fp, "signal %d", signum); - if (signum >= 0 && signum < sizeof(sigmsg) && sigmsg[signum] != NULL) - fprintf (fp, " (%s%s)\n", sigmsg[signum], - WCOREDUMP(status) ? ", core dumped" : ""); - else - fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : ""); + /* If child process returned normally */ + if (WIFEXITED(status)) { + if ((signum = WEXITSTATUS(status))) { + if (cp) + fprintf (fp, "%s: ", cp); + fprintf (fp, "exit %d\n", signum); + } + } else if (WIFSIGNALED(status)) { + /* If child process terminated due to receipt of a signal */ + signum = WTERMSIG(status); + if (signum != SIGINT) { + if (cp) + fprintf (fp, "%s: ", cp); + fprintf (fp, "signal %d", signum); + if (signum >= 0 && signum < sizeof(sigmsg) && sigmsg[signum] != NULL) + fprintf (fp, " (%s%s)\n", sigmsg[signum], + WCOREDUMP(status) ? ", core dumped" : ""); + else + fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : ""); + } } - } - return status; + return status; } diff --git a/sbr/pidwait.c b/sbr/pidwait.c index ef42e1a..d7dd1d7 100644 --- a/sbr/pidwait.c +++ b/sbr/pidwait.c @@ -1,4 +1,3 @@ - /* * pidwait.c -- wait for child to exit * @@ -19,38 +18,38 @@ int pidwait (pid_t id, int sigsok) { - pid_t pid; - SIGNAL_HANDLER istat = NULL, qstat = NULL; + pid_t pid; + SIGNAL_HANDLER istat = NULL, qstat = NULL; #ifdef HAVE_UNION_WAIT - union wait status; + union wait status; #else - int status; + int status; #endif - if (sigsok == -1) { - /* ignore a couple of signals */ - istat = SIGNAL (SIGINT, SIG_IGN); - qstat = SIGNAL (SIGQUIT, SIG_IGN); - } + if (sigsok == -1) { + /* ignore a couple of signals */ + istat = SIGNAL (SIGINT, SIG_IGN); + qstat = SIGNAL (SIGQUIT, SIG_IGN); + } #ifdef HAVE_WAITPID - while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR) - ; + while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR) + ; #else - while ((pid = wait(&status)) != -1 && pid != id) - continue; + while ((pid = wait(&status)) != -1 && pid != id) + continue; #endif - if (sigsok == -1) { - /* reset the signal handlers */ - SIGNAL (SIGINT, istat); - SIGNAL (SIGQUIT, qstat); - } + if (sigsok == -1) { + /* reset the signal handlers */ + SIGNAL (SIGINT, istat); + SIGNAL (SIGQUIT, qstat); + } #ifdef HAVE_UNION_WAIT - return (pid == -1 ? -1 : status.w_status); + return (pid == -1 ? -1 : status.w_status); #else - return (pid == -1 ? -1 : status); + return (pid == -1 ? -1 : status); #endif } diff --git a/sbr/print_help.c b/sbr/print_help.c index e045788..ff3f0f1 100644 --- a/sbr/print_help.c +++ b/sbr/print_help.c @@ -1,4 +1,3 @@ - /* * print_help.c -- print a help message, and possibly the * -- profile/context entries for this command @@ -14,18 +13,18 @@ void print_help (char *str, struct swit *swp, int print_context) { - char *s; + char *s; - /* print Usage string */ - printf ("Usage: %s\n", str); + /* print Usage string */ + printf ("Usage: %s\n", str); - /* print all the switches */ - printf (" switches are:\n"); - print_sw (ALL, swp, "-", stdout); + /* print all the switches */ + printf (" switches are:\n"); + print_sw (ALL, swp, "-", stdout); - /* - * check if we should print any profile entries - */ - if (print_context && (s = context_find (invo_name))) - printf ("\nProfile: %s\n", s); + /* + * check if we should print any profile entries + */ + if (print_context && (s = context_find (invo_name))) + printf ("\nProfile: %s\n", s); } diff --git a/sbr/print_sw.c b/sbr/print_sw.c index 6d475ab..dad30d2 100644 --- a/sbr/print_sw.c +++ b/sbr/print_sw.c @@ -1,4 +1,3 @@ - /* * print_sw.c -- print switches * @@ -13,44 +12,44 @@ void print_sw (char *substr, struct swit *swp, char *prefix, FILE *fp) { - int len, optno; - register int i; - register char *cp, *cp1, *sp; - char buf[128]; + int len, optno; + register int i; + register char *cp, *cp1, *sp; + char buf[128]; - len = strlen(substr); - for (; swp->sw; swp++) { - /* null matches all strings */ - if (!*substr || (ssequal (substr, swp->sw) && len >= swp->minchars)) { - optno = 0; - /* next switch */ - if ((sp = (&swp[1])->sw)) { - if (!*substr && sp[0] == 'n' && sp[1] == 'o' && - strcmp (&sp[2], swp->sw) == 0 && ( - ((&swp[1])->minchars == 0 && swp->minchars == 0) || - ((&swp[1])->minchars == (swp->minchars) + 2))) - optno++; - } + len = strlen(substr); + for (; swp->sw; swp++) { + /* null matches all strings */ + if (!*substr || (ssequal (substr, swp->sw) && len >= swp->minchars)) { + optno = 0; + /* next switch */ + if ((sp = (&swp[1])->sw)) { + if (!*substr && sp[0] == 'n' && sp[1] == 'o' && + strcmp (&sp[2], swp->sw) == 0 && ( + ((&swp[1])->minchars == 0 && swp->minchars == 0) || + ((&swp[1])->minchars == (swp->minchars) + 2))) + optno++; + } - if (swp->minchars > 0) { - cp = buf; - *cp++ = '('; - if (optno) { - strcpy (cp, "[no]"); - cp += strlen (cp); + if (swp->minchars > 0) { + cp = buf; + *cp++ = '('; + if (optno) { + strcpy (cp, "[no]"); + cp += strlen (cp); + } + for (cp1 = swp->sw, i = 0; i < swp->minchars; i++) + *cp++ = *cp1++; + *cp++ = ')'; + while ((*cp++ = *cp1++)); + fprintf (fp, " %s%s\n", prefix, buf); + } else { + if (!swp->minchars) + fprintf(fp, optno ? " %s[no]%s\n" : " %s%s\n", + prefix, swp->sw); + } + if (optno) + swp++; /* skip -noswitch */ } - for (cp1 = swp->sw, i = 0; i < swp->minchars; i++) - *cp++ = *cp1++; - *cp++ = ')'; - while ((*cp++ = *cp1++)); - fprintf (fp, " %s%s\n", prefix, buf); - } else { - if (!swp->minchars) - fprintf(fp, optno ? " %s[no]%s\n" : " %s%s\n", - prefix, swp->sw); - } - if (optno) - swp++; /* skip -noswitch */ } - } } diff --git a/sbr/print_version.c b/sbr/print_version.c index b828b3c..28ce0c9 100644 --- a/sbr/print_version.c +++ b/sbr/print_version.c @@ -1,4 +1,3 @@ - /* * print_version.c -- print a version string * @@ -13,5 +12,5 @@ void print_version (char *invo_name) { - printf("%s -- %s\n", invo_name, version_str); + printf("%s -- %s\n", invo_name, version_str); } diff --git a/sbr/push.c b/sbr/push.c index ce00f68..b2517b3 100644 --- a/sbr/push.c +++ b/sbr/push.c @@ -1,4 +1,3 @@ - /* * push.c -- push a fork into the background * @@ -15,36 +14,35 @@ void push(void) { - pid_t pid; - int i; - - for (i = 0; (pid = fork()) == -1 && i < 5; i++) - sleep (5); - - switch (pid) { - case -1: - /* fork error */ - advise (NULL, "unable to fork, so can't push..."); - break; - - case 0: - /* child, block a few signals and continue */ - SIGNAL (SIGHUP, SIG_IGN); - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - SIGNAL (SIGTERM, SIG_IGN); + pid_t pid; + int i; + + for (i = 0; (pid = fork()) == -1 && i < 5; i++) + sleep (5); + + switch (pid) { + case -1: + /* fork error */ + advise (NULL, "unable to fork, so can't push..."); + break; + + case 0: + /* child, block a few signals and continue */ + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); #ifdef SIGTSTP - SIGNAL (SIGTSTP, SIG_IGN); - SIGNAL (SIGTTIN, SIG_IGN); - SIGNAL (SIGTTOU, SIG_IGN); + SIGNAL (SIGTSTP, SIG_IGN); + SIGNAL (SIGTTIN, SIG_IGN); + SIGNAL (SIGTTOU, SIG_IGN); #endif - freopen ("/dev/null", "r", stdin); - freopen ("/dev/null", "w", stdout); - break; - - default: - /* parent, just exit */ - done (0); - } + freopen ("/dev/null", "r", stdin); + freopen ("/dev/null", "w", stdout); + break; + + default: + /* parent, just exit */ + done (0); + } } - diff --git a/sbr/putenv.c b/sbr/putenv.c index dd66514..bade935 100644 --- a/sbr/putenv.c +++ b/sbr/putenv.c @@ -1,4 +1,3 @@ - /* * putenv.c -- (un)set an envariable * @@ -23,55 +22,55 @@ static int nvmatch (char *, char *); int m_putenv (char *name, char *value) { - register int i; - register char **ep, **nep, *cp; + register int i; + register char **ep, **nep, *cp; - cp = mh_xmalloc ((size_t) (strlen (name) + strlen (value) + 2)); + cp = mh_xmalloc ((size_t) (strlen (name) + strlen (value) + 2)); - sprintf (cp, "%s=%s", name, value); + sprintf (cp, "%s=%s", name, value); - for (ep = environ, i = 0; *ep; ep++, i++) - if (nvmatch (name, *ep)) { - *ep = cp; - return 0; - } + for (ep = environ, i = 0; *ep; ep++, i++) + if (nvmatch (name, *ep)) { + *ep = cp; + return 0; + } - nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep))); + nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep))); - for (ep = environ, i = 0; *ep; nep[i++] = *ep++) - continue; - nep[i++] = cp; - nep[i] = NULL; - environ = nep; - return 0; + for (ep = environ, i = 0; *ep; nep[i++] = *ep++) + continue; + nep[i++] = cp; + nep[i] = NULL; + environ = nep; + return 0; } int unputenv (char *name) { - char **ep, **nep; - - for (ep = environ; *ep; ep++) - if (nvmatch (name, *ep)) - break; - if (*ep == NULL) - return 1; - - for (nep = ep + 1; *nep; nep++) - continue; - *ep = *--nep; - *nep = NULL; - return 0; + char **ep, **nep; + + for (ep = environ; *ep; ep++) + if (nvmatch (name, *ep)) + break; + if (*ep == NULL) + return 1; + + for (nep = ep + 1; *nep; nep++) + continue; + *ep = *--nep; + *nep = NULL; + return 0; } static int nvmatch (char *s1, char *s2) { - while (*s1 == *s2++) - if (*s1++ == '=') - return 1; + while (*s1 == *s2++) + if (*s1++ == '=') + return 1; - return (*s1 == '\0' && *--s2 == '='); + return (*s1 == '\0' && *--s2 == '='); } diff --git a/sbr/r1bindex.c b/sbr/r1bindex.c index 92818f9..93ec950 100644 --- a/sbr/r1bindex.c +++ b/sbr/r1bindex.c @@ -1,4 +1,3 @@ - /* * r1bindex.c -- Given a string and a character, return a pointer * -- to the right of the rightmost occurrence of the @@ -16,19 +15,19 @@ char * r1bindex(char *str, int chr) { - char *cp; - - /* find null at the end of the string */ - for (cp = str; *cp; cp++) - continue; + char *cp; - /* backup to the rightmost character */ - --cp; + /* find null at the end of the string */ + for (cp = str; *cp; cp++) + continue; - /* now search for the rightmost occurrence of the character */ - while (cp >= str && *cp != chr) + /* backup to the rightmost character */ --cp; - /* now move one to the right */ - return (++cp); + /* now search for the rightmost occurrence of the character */ + while (cp >= str && *cp != chr) + --cp; + + /* now move one to the right */ + return (++cp); } diff --git a/sbr/readconfig.c b/sbr/readconfig.c index 671ada3..46644eb 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -1,4 +1,3 @@ - /* * readconfig.c -- base routine to read nmh configuration files * -- such as nmh profile, context file, or mhn.defaults. @@ -12,35 +11,35 @@ #include struct procstr { - char *procname; - char **procnaddr; + char *procname; + char **procnaddr; }; static struct procstr procs[] = { - { "context", &context }, - { "mh-sequences", &mh_seq }, - { "backup-prefix", &backup_prefix }, - { "altmsg-link", &altmsglink }, - { "buildmimeproc", &buildmimeproc }, - { "faceproc", &faceproc }, - { "fileproc", &fileproc }, - { "incproc", &incproc }, - { "installproc", &installproc }, - { "lproc", &lproc }, - { "mailproc", &mailproc }, - { "mhlproc", &mhlproc }, - { "moreproc", &moreproc }, - { "packproc", &packproc }, - { "postproc", &postproc }, - { "rmfproc", &rmfproc }, - { "rmmproc", &rmmproc }, - { "sendmail", &sendmail }, - { "sendproc", &sendproc }, - { "showmimeproc", &showmimeproc }, - { "showproc", &showproc }, - { "whatnowproc", &whatnowproc }, - { "whomproc", &whomproc }, - { NULL, NULL } + { "context", &context }, + { "mh-sequences", &mh_seq }, + { "backup-prefix", &backup_prefix }, + { "altmsg-link", &altmsglink }, + { "buildmimeproc", &buildmimeproc }, + { "faceproc", &faceproc }, + { "fileproc", &fileproc }, + { "incproc", &incproc }, + { "installproc", &installproc }, + { "lproc", &lproc }, + { "mailproc", &mailproc }, + { "mhlproc", &mhlproc }, + { "moreproc", &moreproc }, + { "packproc", &packproc }, + { "postproc", &postproc }, + { "rmfproc", &rmfproc }, + { "rmmproc", &rmmproc }, + { "sendmail", &sendmail }, + { "sendproc", &sendproc }, + { "showmimeproc", &showmimeproc }, + { "showproc", &showproc }, + { "whatnowproc", &whatnowproc }, + { "whomproc", &whomproc }, + { NULL, NULL } }; static struct node **opp = NULL; @@ -49,64 +48,64 @@ static struct node **opp = NULL; void readconfig (struct node **npp, FILE *ib, char *file, int ctx) { - register int state; - register char *cp; - char name[NAMESZ], field[BUFSIZ]; - register struct node *np; - register struct procstr *ps; + register int state; + register char *cp; + char name[NAMESZ], field[BUFSIZ]; + register struct node *np; + register struct procstr *ps; - if (npp == NULL && (npp = opp) == NULL) { - admonish (NULL, "bug: readconfig called but pump not primed"); - return; - } + if (npp == NULL && (npp = opp) == NULL) { + admonish (NULL, "bug: readconfig called but pump not primed"); + return; + } - for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), ib)) { - case FLD: - case FLDPLUS: - case FLDEOF: - np = (struct node *) mh_xmalloc (sizeof(*np)); - *npp = np; - *(npp = &np->n_next) = NULL; - np->n_name = getcpy (name); - if (state == FLDPLUS) { - cp = getcpy (field); - while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), ib); - cp = add (field, cp); - } - np->n_field = trimcpy (cp); - free (cp); - } else { - np->n_field = trimcpy (field); - } - np->n_context = ctx; + for (state = FLD;;) { + switch (state = m_getfld (state, name, field, sizeof(field), ib)) { + case FLD: + case FLDPLUS: + case FLDEOF: + np = (struct node *) mh_xmalloc (sizeof(*np)); + *npp = np; + *(npp = &np->n_next) = NULL; + np->n_name = getcpy (name); + if (state == FLDPLUS) { + cp = getcpy (field); + while (state == FLDPLUS) { + state = m_getfld (state, name, field, sizeof(field), ib); + cp = add (field, cp); + } + np->n_field = trimcpy (cp); + free (cp); + } else { + np->n_field = trimcpy (field); + } + np->n_context = ctx; - /* - * Now scan the list of `procs' and link in the - * field value to the global variable. - */ - for (ps = procs; ps->procname; ps++) - if (strcmp (np->n_name, ps->procname) == 0) { - *ps->procnaddr = np->n_field; - break; - } - if (state == FLDEOF) - break; - continue; + /* + * Now scan the list of `procs' and link in the + * field value to the global variable. + */ + for (ps = procs; ps->procname; ps++) + if (strcmp (np->n_name, ps->procname) == 0) { + *ps->procnaddr = np->n_field; + break; + } + if (state == FLDEOF) + break; + continue; - case BODY: - case BODYEOF: - adios (NULL, "no blank lines are permitted in %s", file); + case BODY: + case BODYEOF: + adios (NULL, "no blank lines are permitted in %s", file); - case FILEEOF: - break; + case FILEEOF: + break; - default: - adios (NULL, "%s is poorly formatted", file); + default: + adios (NULL, "%s is poorly formatted", file); + } + break; } - break; - } - opp = npp; + opp = npp; } diff --git a/sbr/refile.c b/sbr/refile.c index fc2793c..5637d6f 100644 --- a/sbr/refile.c +++ b/sbr/refile.c @@ -1,4 +1,3 @@ - /* * refile.c -- call the "fileproc" to refile the * -- msg or draft into another folder @@ -14,38 +13,38 @@ int refile (char **arg, char *file) { - pid_t pid; - register int vecp; - char *vec[MAXARGS]; - - vecp = 0; - vec[vecp++] = r1bindex (fileproc, '/'); - vec[vecp++] = "-nolink"; /* override bad .mh_profile defaults */ - vec[vecp++] = "-nopreserve"; - vec[vecp++] = "-file"; - vec[vecp++] = file; - - if (arg) { - while (*arg) - vec[vecp++] = *arg++; - } - vec[vecp] = NULL; - - context_save(); /* save the context file */ - fflush(stdout); - - switch (pid = vfork()) { - case -1: - advise ("fork", "unable to"); - return -1; - - case 0: - execvp (fileproc, vec); - fprintf (stderr, "unable to exec "); - perror (fileproc); - _exit (-1); - - default: - return (pidwait (pid, -1)); - } + pid_t pid; + register int vecp; + char *vec[MAXARGS]; + + vecp = 0; + vec[vecp++] = r1bindex (fileproc, '/'); + vec[vecp++] = "-nolink"; /* override bad .mh_profile defaults */ + vec[vecp++] = "-nopreserve"; + vec[vecp++] = "-file"; + vec[vecp++] = file; + + if (arg) { + while (*arg) + vec[vecp++] = *arg++; + } + vec[vecp] = NULL; + + context_save(); /* save the context file */ + fflush(stdout); + + switch (pid = vfork()) { + case -1: + advise ("fork", "unable to"); + return -1; + + case 0: + execvp (fileproc, vec); + fprintf (stderr, "unable to exec "); + perror (fileproc); + _exit (-1); + + default: + return (pidwait (pid, -1)); + } } diff --git a/sbr/remdir.c b/sbr/remdir.c index 4ce0b14..397a689 100644 --- a/sbr/remdir.c +++ b/sbr/remdir.c @@ -1,4 +1,3 @@ - /* * remdir.c -- remove a directory * @@ -13,12 +12,12 @@ int remdir (char *dir) { - context_save(); /* save the context file */ - fflush(stdout); + context_save(); /* save the context file */ + fflush(stdout); - if (rmdir(dir) == -1) { - admonish (dir, "unable to remove directory"); - return 0; - } - return 1; + if (rmdir(dir) == -1) { + admonish (dir, "unable to remove directory"); + return 0; + } + return 1; } diff --git a/sbr/ruserpass.c b/sbr/ruserpass.c index 882889c..5437674 100644 --- a/sbr/ruserpass.c +++ b/sbr/ruserpass.c @@ -27,30 +27,30 @@ static FILE *cfile; # define MAXHOSTNAMELEN 64 #endif -#define DEFAULT 1 -#define LOGIN 2 -#define PASSWD 3 -#define ACCOUNT 4 +#define DEFAULT 1 +#define LOGIN 2 +#define PASSWD 3 +#define ACCOUNT 4 #define MACDEF 5 -#define ID 10 -#define MACH 11 +#define ID 10 +#define MACH 11 static char tokval[100]; struct toktab { - char *tokstr; - int tval; + char *tokstr; + int tval; }; static struct toktab toktabs[] = { - { "default", DEFAULT }, - { "login", LOGIN }, - { "password", PASSWD }, - { "passwd", PASSWD }, - { "account", ACCOUNT }, - { "machine", MACH }, - { "macdef", MACDEF }, - { 0, 0 } + { "default", DEFAULT }, + { "login", LOGIN }, + { "password", PASSWD }, + { "passwd", PASSWD }, + { "account", ACCOUNT }, + { "machine", MACH }, + { "macdef", MACDEF }, + { 0, 0 } }; /* @@ -62,152 +62,152 @@ static int token(void); void ruserpass(char *host, char **aname, char **apass) { - char *hdir, buf[BUFSIZ]; - int t, usedefault = 0; - struct stat stb; - - hdir = getenv("HOME"); - if (hdir == NULL) - hdir = "."; - snprintf(buf, sizeof(buf), "%s/.netrc", hdir); - cfile = fopen(buf, "r"); - if (cfile == NULL) { - if (errno != ENOENT) - perror(buf); - goto done; - } - - while ((t = token())) { - switch(t) { - case DEFAULT: - usedefault = 1; - /* FALL THROUGH */ - - case MACH: - if (!usedefault) { - if (token() != ID) - continue; - /* - * Allow match either for user's host name. - */ - if (mh_strcasecmp(host, tokval) == 0) - goto match; - continue; - } -match: - while ((t = token()) && t != MACH && t != DEFAULT) { + char *hdir, buf[BUFSIZ]; + int t, usedefault = 0; + struct stat stb; + + hdir = getenv("HOME"); + if (hdir == NULL) + hdir = "."; + snprintf(buf, sizeof(buf), "%s/.netrc", hdir); + cfile = fopen(buf, "r"); + if (cfile == NULL) { + if (errno != ENOENT) + perror(buf); + goto done; + } + + while ((t = token())) { switch(t) { - case LOGIN: - if (token() && *aname == 0) { - *aname = mh_xmalloc((size_t) strlen(tokval) + 1); - strcpy(*aname, tokval); - } - break; - case PASSWD: - if (fstat(fileno(cfile), &stb) >= 0 && - (stb.st_mode & 077) != 0) { - /* We make this a fatal error to force the user to correct it */ - advise(NULL, "Error - ~/.netrc file must not be world or group readable."); - adios(NULL, "Remove password or correct file permissions."); - } - if (token() && *apass == 0) { - *apass = mh_xmalloc((size_t) strlen(tokval) + 1); - strcpy(*apass, tokval); - } - break; - case ACCOUNT: - break; - - case MACDEF: - goto done_close; - break; - default: - fprintf(stderr, "Unknown .netrc keyword %s\n", tokval); - break; + case DEFAULT: + usedefault = 1; + /* FALL THROUGH */ + + case MACH: + if (!usedefault) { + if (token() != ID) + continue; + /* + * Allow match either for user's host name. + */ + if (mh_strcasecmp(host, tokval) == 0) + goto match; + continue; + } +match: + while ((t = token()) && t != MACH && t != DEFAULT) { + switch(t) { + case LOGIN: + if (token() && *aname == 0) { + *aname = mh_xmalloc((size_t) strlen(tokval) + 1); + strcpy(*aname, tokval); + } + break; + case PASSWD: + if (fstat(fileno(cfile), &stb) >= 0 && + (stb.st_mode & 077) != 0) { + /* We make this a fatal error to force the user to correct it */ + advise(NULL, "Error - ~/.netrc file must not be world or group readable."); + adios(NULL, "Remove password or correct file permissions."); + } + if (token() && *apass == 0) { + *apass = mh_xmalloc((size_t) strlen(tokval) + 1); + strcpy(*apass, tokval); + } + break; + case ACCOUNT: + break; + + case MACDEF: + goto done_close; + break; + default: + fprintf(stderr, "Unknown .netrc keyword %s\n", tokval); + break; + } + } + goto done; } - } - goto done; } - } done_close: - fclose(cfile); + fclose(cfile); done: - if (!*aname) { - char tmp[80]; - char *myname; + if (!*aname) { + char tmp[80]; + char *myname; - if ((myname = getlogin()) == NULL) { - struct passwd *pp; + if ((myname = getlogin()) == NULL) { + struct passwd *pp; - if ((pp = getpwuid (getuid())) != NULL) - myname = pp->pw_name; - } - printf("Name (%s:%s): ", host, myname); + if ((pp = getpwuid (getuid())) != NULL) + myname = pp->pw_name; + } + printf("Name (%s:%s): ", host, myname); + + fgets(tmp, sizeof(tmp) - 1, stdin); + tmp[strlen(tmp) - 1] = '\0'; + if (*tmp != '\0') { + myname = tmp; + } - fgets(tmp, sizeof(tmp) - 1, stdin); - tmp[strlen(tmp) - 1] = '\0'; - if (*tmp != '\0') { - myname = tmp; + *aname = mh_xmalloc((size_t) strlen(myname) + 1); + strcpy (*aname, myname); } - *aname = mh_xmalloc((size_t) strlen(myname) + 1); - strcpy (*aname, myname); - } + if (!*apass) { + char prompt[256]; + char *mypass; - if (!*apass) { - char prompt[256]; - char *mypass; + snprintf(prompt, sizeof(prompt), "Password (%s:%s): ", host, *aname); + mypass = nmh_getpass(prompt); - snprintf(prompt, sizeof(prompt), "Password (%s:%s): ", host, *aname); - mypass = nmh_getpass(prompt); - - if (*mypass == '\0') { - mypass = *aname; - } + if (*mypass == '\0') { + mypass = *aname; + } - *apass = mh_xmalloc((size_t) strlen(mypass) + 1); - strcpy (*apass, mypass); - } + *apass = mh_xmalloc((size_t) strlen(mypass) + 1); + strcpy (*apass, mypass); + } } static int token(void) { - char *cp; - int c; - struct toktab *t; - - if (feof(cfile)) - return (0); - while ((c = getc(cfile)) != EOF && - (c == '\n' || c == '\t' || c == ' ' || c == ',')) - continue; - if (c == EOF) - return (0); - cp = tokval; - if (c == '"') { - while ((c = getc(cfile)) != EOF && c != '"') { - if (c == '\\') - c = getc(cfile); - *cp++ = c; - } - } else { - *cp++ = c; - while ((c = getc(cfile)) != EOF - && c != '\n' && c != '\t' && c != ' ' && c != ',') { - if (c == '\\') - c = getc(cfile); - *cp++ = c; + char *cp; + int c; + struct toktab *t; + + if (feof(cfile)) + return (0); + while ((c = getc(cfile)) != EOF && + (c == '\n' || c == '\t' || c == ' ' || c == ',')) + continue; + if (c == EOF) + return (0); + cp = tokval; + if (c == '"') { + while ((c = getc(cfile)) != EOF && c != '"') { + if (c == '\\') + c = getc(cfile); + *cp++ = c; + } + } else { + *cp++ = c; + while ((c = getc(cfile)) != EOF + && c != '\n' && c != '\t' && c != ' ' && c != ',') { + if (c == '\\') + c = getc(cfile); + *cp++ = c; + } } - } - *cp = 0; - if (tokval[0] == 0) - return (0); - for (t = toktabs; t->tokstr; t++) - if (!strcmp(t->tokstr, tokval)) - return (t->tval); - return (ID); + *cp = 0; + if (tokval[0] == 0) + return (0); + for (t = toktabs; t->tokstr; t++) + if (!strcmp(t->tokstr, tokval)) + return (t->tval); + return (ID); } diff --git a/sbr/seq_add.c b/sbr/seq_add.c index 68fa724..fb56bb9 100644 --- a/sbr/seq_add.c +++ b/sbr/seq_add.c @@ -1,4 +1,3 @@ - /* * seq_add.c -- add message(s) to a sequence * @@ -25,80 +24,80 @@ int seq_addsel (struct msgs *mp, char *cp, int public, int zero) { - int i, msgnum, new_seq = 1; - - if (!seq_nameok (cp)) - return 0; - - /* - * We keep mp->curmsg and "cur" sequence in sync. - * See seq_list() and seq_init(). - */ - if (!strcmp (current,cp)) - mp->curmsg = mp->hghsel; - - /* - * Get the number for this sequence - */ - for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp (mp->msgattrs[i], cp)) { - new_seq = 0; - break; + int i, msgnum, new_seq = 1; + + if (!seq_nameok (cp)) + return 0; + + /* + * We keep mp->curmsg and "cur" sequence in sync. + * See seq_list() and seq_init(). + */ + if (!strcmp (current,cp)) + mp->curmsg = mp->hghsel; + + /* + * Get the number for this sequence + */ + for (i = 0; mp->msgattrs[i]; i++) { + if (!strcmp (mp->msgattrs[i], cp)) { + new_seq = 0; + break; + } } - } - - /* - * If this is a new sequence, add a slot for it - */ - if (new_seq) { - if (i >= NUMATTRS) { - advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); - return 0; + + /* + * If this is a new sequence, add a slot for it + */ + if (new_seq) { + if (i >= NUMATTRS) { + advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); + return 0; + } + if (!(mp->msgattrs[i] = strdup (cp))) { + advise (NULL, "strdup failed"); + return 0; + } + mp->msgattrs[i + 1] = NULL; } - if (!(mp->msgattrs[i] = strdup (cp))) { - advise (NULL, "strdup failed"); - return 0; + + /* + * If sequence is new, or zero flag is set, then first + * clear the bit for this sequence from all messages. + */ + if (new_seq || zero) { + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) + clear_sequence (mp, i, msgnum); } - mp->msgattrs[i + 1] = NULL; - } - - /* - * If sequence is new, or zero flag is set, then first - * clear the bit for this sequence from all messages. - */ - if (new_seq || zero) { - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) - clear_sequence (mp, i, msgnum); - } - - /* - * Now flip on the bit for this sequence - * for all selected messages. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) - add_sequence (mp, i, msgnum); - - /* - * Set the public/private bit for this sequence. - */ - if (public == 1) - make_seq_public (mp, i); - else if (public == 0) - make_seq_private (mp, i); - else if (new_seq) { + /* - * If public == -1, then only set the - * public/private bit for new sequences. - */ - if (is_readonly (mp)) - make_seq_private (mp, i); - else - make_seq_public (mp, i); - } - - mp->msgflags |= SEQMOD; - return 1; + * Now flip on the bit for this sequence + * for all selected messages. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected (mp, msgnum)) + add_sequence (mp, i, msgnum); + + /* + * Set the public/private bit for this sequence. + */ + if (public == 1) + make_seq_public (mp, i); + else if (public == 0) + make_seq_private (mp, i); + else if (new_seq) { + /* + * If public == -1, then only set the + * public/private bit for new sequences. + */ + if (is_readonly (mp)) + make_seq_private (mp, i); + else + make_seq_public (mp, i); + } + + mp->msgflags |= SEQMOD; + return 1; } @@ -117,75 +116,75 @@ seq_addsel (struct msgs *mp, char *cp, int public, int zero) int seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero) { - int i, j, new_seq = 1; - - if (!seq_nameok (cp)) - return 0; - - /* - * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list() - */ - if (!strcmp (current,cp)) - mp->curmsg = msgnum; - - /* - * Get the number for this sequence - */ - for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp (mp->msgattrs[i], cp)) { - new_seq = 0; - break; + int i, j, new_seq = 1; + + if (!seq_nameok (cp)) + return 0; + + /* + * keep mp->curmsg and msgattrs["cur"] in sync - see seq_list() + */ + if (!strcmp (current,cp)) + mp->curmsg = msgnum; + + /* + * Get the number for this sequence + */ + for (i = 0; mp->msgattrs[i]; i++) { + if (!strcmp (mp->msgattrs[i], cp)) { + new_seq = 0; + break; + } } - } - - /* - * If this is a new sequence, add a slot for it - */ - if (new_seq) { - if (i >= NUMATTRS) { - advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); - return 0; + + /* + * If this is a new sequence, add a slot for it + */ + if (new_seq) { + if (i >= NUMATTRS) { + advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); + return 0; + } + if (!(mp->msgattrs[i] = strdup (cp))) { + advise (NULL, "strdup failed"); + return 0; + } + mp->msgattrs[i + 1] = NULL; } - if (!(mp->msgattrs[i] = strdup (cp))) { - advise (NULL, "strdup failed"); - return 0; + + /* + * If sequence is new, or zero flag is set, then first + * clear the bit for this sequence from all messages. + */ + if (new_seq || zero) { + for (j = mp->lowmsg; j <= mp->hghmsg; j++) + clear_sequence (mp, i, j); } - mp->msgattrs[i + 1] = NULL; - } - - /* - * If sequence is new, or zero flag is set, then first - * clear the bit for this sequence from all messages. - */ - if (new_seq || zero) { - for (j = mp->lowmsg; j <= mp->hghmsg; j++) - clear_sequence (mp, i, j); - } - - /* - * Now flip on the bit for this sequence - * for this particular message. - */ - add_sequence (mp, i, msgnum); - - /* - * Set the public/private bit for this sequence. - */ - if (public == 1) - make_seq_public (mp, i); - else if (public == 0) - make_seq_private (mp, i); - else if (new_seq) { + /* - * If public == -1, then only set the - * public/private bit for new sequences. - */ - if (is_readonly (mp)) - make_seq_private (mp, i); - else - make_seq_public (mp, i); - } - - mp->msgflags |= SEQMOD; - return 1; + * Now flip on the bit for this sequence + * for this particular message. + */ + add_sequence (mp, i, msgnum); + + /* + * Set the public/private bit for this sequence. + */ + if (public == 1) + make_seq_public (mp, i); + else if (public == 0) + make_seq_private (mp, i); + else if (new_seq) { + /* + * If public == -1, then only set the + * public/private bit for new sequences. + */ + if (is_readonly (mp)) + make_seq_private (mp, i); + else + make_seq_public (mp, i); + } + + mp->msgflags |= SEQMOD; + return 1; } diff --git a/sbr/seq_bits.c b/sbr/seq_bits.c index 30dd3f5..e93846a 100644 --- a/sbr/seq_bits.c +++ b/sbr/seq_bits.c @@ -1,4 +1,3 @@ - /* * seq_bits.c -- return the snprintb() string for a sequence * @@ -13,17 +12,17 @@ char * seq_bits (struct msgs *mp) { - int i; - size_t len; - static char buffer[BUFSIZ]; + int i; + size_t len; + static char buffer[BUFSIZ]; - strncpy (buffer, MBITS, sizeof(buffer)); + strncpy (buffer, MBITS, sizeof(buffer)); - for (i = 0; mp->msgattrs[i]; i++) { - len = strlen (buffer); - snprintf (buffer + len, sizeof(buffer) - len, - "%c%s", FFATTRSLOT + 1 + i, mp->msgattrs[i]); - } + for (i = 0; mp->msgattrs[i]; i++) { + len = strlen (buffer); + snprintf (buffer + len, sizeof(buffer) - len, + "%c%s", FFATTRSLOT + 1 + i, mp->msgattrs[i]); + } - return buffer; + return buffer; } diff --git a/sbr/seq_del.c b/sbr/seq_del.c index eb41ec4..44ae6ce 100644 --- a/sbr/seq_del.c +++ b/sbr/seq_del.c @@ -1,4 +1,3 @@ - /* * seq_del.c -- delete message(s) from a sequence * @@ -25,83 +24,83 @@ int seq_delsel (struct msgs *mp, char *cp, int public, int zero) { - int i, msgnum, new_seq = 1; + int i, msgnum, new_seq = 1; - if (!seq_nameok (cp)) - return 0; + if (!seq_nameok (cp)) + return 0; - /* - * Get the number for this sequence - */ - for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp (mp->msgattrs[i], cp)) { - new_seq = 0; - break; + /* + * Get the number for this sequence + */ + for (i = 0; mp->msgattrs[i]; i++) { + if (!strcmp (mp->msgattrs[i], cp)) { + new_seq = 0; + break; + } } - } - /* - * If the zero flag is set, first add all existing - * messages in this folder to the sequence. - */ - if (zero) { /* - * create the sequence, if necessary + * If the zero flag is set, first add all existing + * messages in this folder to the sequence. */ - if (new_seq) { - if (i >= NUMATTRS) { - advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); - return 0; - } - if (!(mp->msgattrs[i] = strdup (cp))) { - advise (NULL, "strdup failed"); - return 0; - } - mp->msgattrs[i + 1] = NULL; + if (zero) { + /* + * create the sequence, if necessary + */ + if (new_seq) { + if (i >= NUMATTRS) { + advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp); + return 0; + } + if (!(mp->msgattrs[i] = strdup (cp))) { + advise (NULL, "strdup failed"); + return 0; + } + mp->msgattrs[i + 1] = NULL; + } + /* + * now add sequence bit to all existing messages + */ + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { + if (does_exist (mp, msgnum)) + add_sequence (mp, i, msgnum); + else + clear_sequence (mp, i, msgnum); + } + } else { + if (new_seq) { + advise (NULL, "no such sequence as %s", cp); + return 0; + } } + /* - * now add sequence bit to all existing messages + * Now clear the bit on all selected messages */ - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { - if (does_exist (mp, msgnum)) - add_sequence (mp, i, msgnum); - else - clear_sequence (mp, i, msgnum); - } - } else { - if (new_seq) { - advise (NULL, "no such sequence as %s", cp); - return 0; - } - } - - /* - * Now clear the bit on all selected messages - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) - clear_sequence (mp, i, msgnum); - - /* - * Set the public/private bit for this sequence. - */ - if (public == 1) - make_seq_public (mp, i); - else if (public == 0) - make_seq_private (mp, i); - else if (new_seq) { + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected (mp, msgnum)) + clear_sequence (mp, i, msgnum); + /* - * If public == -1, then only set the - * public/private bit for new sequences. + * Set the public/private bit for this sequence. */ - if (is_readonly (mp)) - make_seq_private (mp, i); - else - make_seq_public (mp, i); - } - - mp->msgflags |= SEQMOD; - return 1; + if (public == 1) + make_seq_public (mp, i); + else if (public == 0) + make_seq_private (mp, i); + else if (new_seq) { + /* + * If public == -1, then only set the + * public/private bit for new sequences. + */ + if (is_readonly (mp)) + make_seq_private (mp, i); + else + make_seq_public (mp, i); + } + + mp->msgflags |= SEQMOD; + return 1; } @@ -114,19 +113,19 @@ seq_delsel (struct msgs *mp, char *cp, int public, int zero) int seq_delmsg (struct msgs *mp, char *cp, int msgnum) { - int i; + int i; - if (!seq_nameok (cp)) - return 0; + if (!seq_nameok (cp)) + return 0; - for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp (mp->msgattrs[i], cp)) { - clear_sequence (mp, i, msgnum); - mp->msgflags |= SEQMOD; - return 1; + for (i = 0; mp->msgattrs[i]; i++) { + if (!strcmp (mp->msgattrs[i], cp)) { + clear_sequence (mp, i, msgnum); + mp->msgflags |= SEQMOD; + return 1; + } } - } - advise (NULL, "no such sequence as %s", cp); - return 0; + advise (NULL, "no such sequence as %s", cp); + return 0; } diff --git a/sbr/seq_getnum.c b/sbr/seq_getnum.c index 251b609..c5ff8b4 100644 --- a/sbr/seq_getnum.c +++ b/sbr/seq_getnum.c @@ -1,4 +1,3 @@ - /* * seq_getnum.c -- find the index for a sequence * -- return -1 if sequence doesn't exist @@ -14,11 +13,11 @@ int seq_getnum (struct msgs *mp, char *seqname) { - int i; + int i; - for (i = 0; mp->msgattrs[i]; i++) - if (!strcmp (mp->msgattrs[i], seqname)) - return i; + for (i = 0; mp->msgattrs[i]; i++) + if (!strcmp (mp->msgattrs[i], seqname)) + return i; - return -1; + return -1; } diff --git a/sbr/seq_list.c b/sbr/seq_list.c index b64e8cd..23bd544 100644 --- a/sbr/seq_list.c +++ b/sbr/seq_list.c @@ -1,4 +1,3 @@ - /* * seq_list.c -- Get all messages in a sequence and return them * -- as a space separated list of message ranges. @@ -22,84 +21,84 @@ static int len = 0; char * seq_list(struct msgs *mp, char *seqname) { - int i, j, seqnum; - char *bp; - - /* On first invocation, allocate initial buffer space */ - if (!buffer) { - len = MAXBUFFER; - buffer = mh_xmalloc ((size_t) len); - } - - /* - * Special processing for "cur" sequence. We assume that the - * "cur" sequence and mp->curmsg are in sync (see seq_add.c). - * This is returned, even if message doesn't exist or the - * folder is empty. - */ - if (!strcmp (current, seqname)) { - if (mp->curmsg) { - sprintf(buffer, "%s", m_name(mp->curmsg)); - return (buffer); - } else - return (NULL); - } - - /* If the folder is empty, just return NULL */ - if (mp->nummsg == 0) - return NULL; - - /* Get the index of the sequence */ - if ((seqnum = seq_getnum (mp, seqname)) == -1) - return NULL; - - bp = buffer; - - for (i = mp->lowmsg; i <= mp->hghmsg; ++i) { - /* - * If message doesn't exist, or isn't in - * the sequence, then continue. - */ - if (!does_exist(mp, i) || !in_sequence(mp, seqnum, i)) - continue; - - /* - * See if we need to enlarge buffer. Since we don't know - * exactly how many character this particular message range - * will need, we enlarge the buffer if we are within - * 50 characters of the end. - */ - if (bp - buffer > len - 50) { - char *newbuf; + int i, j, seqnum; + char *bp; - len += MAXBUFFER; - newbuf = mh_xrealloc (buffer, (size_t) len); - bp = newbuf + (bp - buffer); - buffer = newbuf; + /* On first invocation, allocate initial buffer space */ + if (!buffer) { + len = MAXBUFFER; + buffer = mh_xmalloc ((size_t) len); } /* - * If this is not the first message range in - * the list, first add a space. + * Special processing for "cur" sequence. We assume that the + * "cur" sequence and mp->curmsg are in sync (see seq_add.c). + * This is returned, even if message doesn't exist or the + * folder is empty. */ - if (bp > buffer) - *bp++ = ' '; - - sprintf(bp, "%s", m_name(i)); - bp += strlen(bp); - j = i; /* Remember beginning of message range */ - - /* - * Scan to the end of this message range - */ - for (++i; i <= mp->hghmsg && does_exist(mp, i) && in_sequence(mp, seqnum, i); - ++i) - ; + if (!strcmp (current, seqname)) { + if (mp->curmsg) { + sprintf(buffer, "%s", m_name(mp->curmsg)); + return (buffer); + } else + return (NULL); + } - if (i - j > 1) { - sprintf(bp, "-%s", m_name(i - 1)); - bp += strlen(bp); + /* If the folder is empty, just return NULL */ + if (mp->nummsg == 0) + return NULL; + + /* Get the index of the sequence */ + if ((seqnum = seq_getnum (mp, seqname)) == -1) + return NULL; + + bp = buffer; + + for (i = mp->lowmsg; i <= mp->hghmsg; ++i) { + /* + * If message doesn't exist, or isn't in + * the sequence, then continue. + */ + if (!does_exist(mp, i) || !in_sequence(mp, seqnum, i)) + continue; + + /* + * See if we need to enlarge buffer. Since we don't know + * exactly how many character this particular message range + * will need, we enlarge the buffer if we are within + * 50 characters of the end. + */ + if (bp - buffer > len - 50) { + char *newbuf; + + len += MAXBUFFER; + newbuf = mh_xrealloc (buffer, (size_t) len); + bp = newbuf + (bp - buffer); + buffer = newbuf; + } + + /* + * If this is not the first message range in + * the list, first add a space. + */ + if (bp > buffer) + *bp++ = ' '; + + sprintf(bp, "%s", m_name(i)); + bp += strlen(bp); + j = i; /* Remember beginning of message range */ + + /* + * Scan to the end of this message range + */ + for (++i; i <= mp->hghmsg && does_exist(mp, i) && in_sequence(mp, seqnum, i); + ++i) + ; + + if (i - j > 1) { + sprintf(bp, "-%s", m_name(i - 1)); + bp += strlen(bp); + } } - } - return (bp > buffer? buffer : NULL); + return (bp > buffer? buffer : NULL); } diff --git a/sbr/seq_nameok.c b/sbr/seq_nameok.c index 6887ac6..e10ef92 100644 --- a/sbr/seq_nameok.c +++ b/sbr/seq_nameok.c @@ -1,4 +1,3 @@ - /* * seq_nameok.c -- check if a sequence name is ok * @@ -13,44 +12,44 @@ int seq_nameok (unsigned char *s) { - unsigned char *pp; - - if (s == NULL || *s == '\0') { - advise (NULL, "empty sequence name"); - return 0; - } - - /* - * Make sure sequence name doesn't clash with one - * of the `reserved' sequence names. - */ - if (!(strcmp (s, "new") && - strcmp (s, "all") && - strcmp (s, "first") && - strcmp (s, "last") && - strcmp (s, "prev") && - strcmp (s, "next"))) { - advise (NULL, "illegal sequence name: %s", s); - return 0; - } - - /* - * First character in a sequence name must be - * an alphabetic character ... - */ - if (!isalpha (*s)) { - advise (NULL, "illegal sequence name: %s", s); - return 0; - } - - /* - * and can be followed by zero or more alphanumeric characters - */ - for (pp = s + 1; *pp; pp++) - if (!isalnum (*pp)) { - advise (NULL, "illegal sequence name: %s", s); - return 0; + unsigned char *pp; + + if (s == NULL || *s == '\0') { + advise (NULL, "empty sequence name"); + return 0; + } + + /* + * Make sure sequence name doesn't clash with one + * of the `reserved' sequence names. + */ + if (!(strcmp (s, "new") && + strcmp (s, "all") && + strcmp (s, "first") && + strcmp (s, "last") && + strcmp (s, "prev") && + strcmp (s, "next"))) { + advise (NULL, "illegal sequence name: %s", s); + return 0; } - return 1; + /* + * First character in a sequence name must be + * an alphabetic character ... + */ + if (!isalpha (*s)) { + advise (NULL, "illegal sequence name: %s", s); + return 0; + } + + /* + * and can be followed by zero or more alphanumeric characters + */ + for (pp = s + 1; *pp; pp++) + if (!isalnum (*pp)) { + advise (NULL, "illegal sequence name: %s", s); + return 0; + } + + return 1; } diff --git a/sbr/seq_print.c b/sbr/seq_print.c index 3d97038..2db6656 100644 --- a/sbr/seq_print.c +++ b/sbr/seq_print.c @@ -1,4 +1,3 @@ - /* * seq_print.c -- Routines to print sequence information. * @@ -17,14 +16,15 @@ void seq_printall (struct msgs *mp) { - int i; - char *list; - - for (i = 0; mp->msgattrs[i]; i++) { - list = seq_list (mp, mp->msgattrs[i]); - printf ("%s%s: %s\n", mp->msgattrs[i], - is_seq_private (mp, i) ? " (private)" : "", empty(list)); - } + int i; + char *list; + + for (i = 0; mp->msgattrs[i]; i++) { + list = seq_list (mp, mp->msgattrs[i]); + printf ("%s%s: %s\n", mp->msgattrs[i], + is_seq_private (mp, i) ? " (private)" : "", + empty(list)); + } } @@ -34,15 +34,15 @@ seq_printall (struct msgs *mp) void seq_print (struct msgs *mp, char *seqname) { - int i; - char *list; + int i; + char *list; - /* get the index of sequence */ - i = seq_getnum (mp, seqname); + /* get the index of sequence */ + i = seq_getnum (mp, seqname); - /* get sequence information */ - list = seq_list (mp, seqname); + /* get sequence information */ + list = seq_list (mp, seqname); - printf ("%s%s: %s\n", seqname, - (i == -1) ? "" : is_seq_private(mp, i) ? " (private)" : "", empty(list)); + printf ("%s%s: %s\n", seqname, (i == -1) ? "" : + is_seq_private(mp, i) ? " (private)" : "", empty(list)); } diff --git a/sbr/seq_read.c b/sbr/seq_read.c index e349121..6945f00 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -1,4 +1,3 @@ - /* * seq_read.c -- read the .mh_sequence file and * -- initialize sequence information @@ -28,23 +27,23 @@ static void seq_private (struct msgs *); void seq_read (struct msgs *mp) { - /* - * Initialize the list of sequence names. Go ahead and - * add the "cur" sequence to the list of sequences. - */ - mp->msgattrs[0] = getcpy (current); - mp->msgattrs[1] = NULL; - make_all_public (mp); /* initially, make all public */ - - /* If folder is empty, don't scan for sequence information */ - if (mp->nummsg == 0) - return; - - /* Initialize the public sequences */ - seq_public (mp); - - /* Initialize the private sequences */ - seq_private (mp); + /* + * Initialize the list of sequence names. Go ahead and + * add the "cur" sequence to the list of sequences. + */ + mp->msgattrs[0] = getcpy (current); + mp->msgattrs[1] = NULL; + make_all_public (mp); /* initially, make all public */ + + /* If folder is empty, don't scan for sequence information */ + if (mp->nummsg == 0) + return; + + /* Initialize the public sequences */ + seq_public (mp); + + /* Initialize the private sequences */ + seq_private (mp); } @@ -55,62 +54,62 @@ seq_read (struct msgs *mp) static void seq_public (struct msgs *mp) { - int state; - char *cp, seqfile[PATH_MAX]; - char name[NAMESZ], field[BUFSIZ]; - FILE *fp; - - /* - * If mh_seq == NULL (such as if nmh been compiled with - * NOPUBLICSEQ), or if *mh_seq == '\0' (the user has defined - * the "mh-sequences" profile entry, but left it empty), - * then just return, and do not initialize any public sequences. - */ - if (mh_seq == NULL || *mh_seq == '\0') - return; - - /* get filename of sequence file */ - snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); - - if ((fp = lkfopen (seqfile, "r")) == NULL) - return; - - /* Use m_getfld to scan sequence file */ - for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - if (state == FLDPLUS) { - cp = getcpy (field); - while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), fp); - cp = add (field, cp); - } - seq_init (mp, getcpy (name), trimcpy (cp)); - free (cp); - } else { - seq_init (mp, getcpy (name), trimcpy (field)); + int state; + char *cp, seqfile[PATH_MAX]; + char name[NAMESZ], field[BUFSIZ]; + FILE *fp; + + /* + * If mh_seq == NULL (such as if nmh been compiled with + * NOPUBLICSEQ), or if *mh_seq == '\0' (the user has defined + * the "mh-sequences" profile entry, but left it empty), + * then just return, and do not initialize any public sequences. + */ + if (mh_seq == NULL || *mh_seq == '\0') + return; + + /* get filename of sequence file */ + snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); + + if ((fp = lkfopen (seqfile, "r")) == NULL) + return; + + /* Use m_getfld to scan sequence file */ + for (state = FLD;;) { + switch (state = m_getfld (state, name, field, sizeof(field), fp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + if (state == FLDPLUS) { + cp = getcpy (field); + while (state == FLDPLUS) { + state = m_getfld (state, name, field, sizeof(field), fp); + cp = add (field, cp); + } + seq_init (mp, getcpy (name), trimcpy (cp)); + free (cp); + } else { + seq_init (mp, getcpy (name), trimcpy (field)); + } + if (state == FLDEOF) + break; + continue; + + case BODY: + case BODYEOF: + adios (NULL, "no blank lines are permitted in %s", seqfile); + /* fall */ + + case FILEEOF: + break; + + default: + adios (NULL, "%s is poorly formatted", seqfile); } - if (state == FLDEOF) - break; - continue; - - case BODY: - case BODYEOF: - adios (NULL, "no blank lines are permitted in %s", seqfile); - /* fall */ - - case FILEEOF: - break; - - default: - adios (NULL, "%s is poorly formatted", seqfile); + break; /* break from for loop */ } - break; /* break from for loop */ - } - lkfclose (fp, seqfile); + lkfclose (fp, seqfile); } @@ -124,24 +123,24 @@ seq_public (struct msgs *mp) static void seq_private (struct msgs *mp) { - int i, j, alen, plen; - char *cp; - struct node *np; - - alen = strlen ("atr-"); - plen = strlen (mp->foldpath) + 1; - - for (np = m_defs; np; np = np->n_next) { - if (ssequal ("atr-", np->n_name) - && (j = strlen (np->n_name) - plen) > alen - && *(np->n_name + j) == '-' - && strcmp (mp->foldpath, np->n_name + j + 1) == 0) { - cp = getcpy (np->n_name + alen); - *(cp + j - alen) = '\0'; - if ((i = seq_init (mp, cp, getcpy (np->n_field))) != -1) - make_seq_private (mp, i); + int i, j, alen, plen; + char *cp; + struct node *np; + + alen = strlen ("atr-"); + plen = strlen (mp->foldpath) + 1; + + for (np = m_defs; np; np = np->n_next) { + if (ssequal ("atr-", np->n_name) + && (j = strlen (np->n_name) - plen) > alen + && *(np->n_name + j) == '-' + && strcmp (mp->foldpath, np->n_name + j + 1) == 0) { + cp = getcpy (np->n_name + alen); + *(cp + j - alen) = '\0'; + if ((i = seq_init (mp, cp, getcpy (np->n_field))) != -1) + make_seq_private (mp, i); + } } - } } @@ -158,77 +157,77 @@ seq_private (struct msgs *mp) static int seq_init (struct msgs *mp, char *name, char *field) { - int i, j, k, is_current; - char *cp, **ap; - - /* - * Check if this is "cur" sequence, - * so we can do some special things. - */ - is_current = !strcmp (current, name); - - /* - * Search for this sequence name to see if we've seen - * it already. If we've seen this sequence before, - * then clear the bit for this sequence from all the - * mesages in this folder. - */ - for (i = 0; mp->msgattrs[i]; i++) { - if (!strcmp (mp->msgattrs[i], name)) { - for (j = mp->lowmsg; j <= mp->hghmsg; j++) - clear_sequence (mp, i, j); - break; + int i, j, k, is_current; + char *cp, **ap; + + /* + * Check if this is "cur" sequence, + * so we can do some special things. + */ + is_current = !strcmp (current, name); + + /* + * Search for this sequence name to see if we've seen + * it already. If we've seen this sequence before, + * then clear the bit for this sequence from all the + * mesages in this folder. + */ + for (i = 0; mp->msgattrs[i]; i++) { + if (!strcmp (mp->msgattrs[i], name)) { + for (j = mp->lowmsg; j <= mp->hghmsg; j++) + clear_sequence (mp, i, j); + break; + } } - } - - /* Return error, if too many sequences */ - if (i >= NUMATTRS) { - free (name); - free (field); - return -1; - } - - /* - * If we've already seen this sequence name, just free the - * name string. Else add it to the list of sequence names. - */ - if (mp->msgattrs[i]) { - free (name); - } else { - mp->msgattrs[i] = name; - mp->msgattrs[i + 1] = NULL; - } - - /* - * Split up the different message ranges at whitespace - */ - for (ap = brkstring (field, " ", "\n"); *ap; ap++) { - if ((cp = strchr(*ap, '-'))) - *cp++ = '\0'; - if ((j = m_atoi (*ap)) > 0) { - k = cp ? m_atoi (cp) : j; - - /* - * Keep mp->curmsg and "cur" sequence in synch. Unlike - * other sequences, this message doesn't need to exist. - * Think about the series of command (rmm; next) to - * understand why this can be the case. But if it does - * exist, we will still set the bit flag for it like - * other sequences. - */ - if (is_current) - mp->curmsg = j; - /* - * We iterate through messages in this range - * and flip on bit for this sequence. - */ - for (; j <= k; j++) { - if (j >= mp->lowmsg && j <= mp->hghmsg && does_exist(mp, j)) - add_sequence (mp, i, j); - } + + /* Return error, if too many sequences */ + if (i >= NUMATTRS) { + free (name); + free (field); + return -1; + } + + /* + * If we've already seen this sequence name, just free the + * name string. Else add it to the list of sequence names. + */ + if (mp->msgattrs[i]) { + free (name); + } else { + mp->msgattrs[i] = name; + mp->msgattrs[i + 1] = NULL; + } + + /* + * Split up the different message ranges at whitespace + */ + for (ap = brkstring (field, " ", "\n"); *ap; ap++) { + if ((cp = strchr(*ap, '-'))) + *cp++ = '\0'; + if ((j = m_atoi (*ap)) > 0) { + k = cp ? m_atoi (cp) : j; + + /* + * Keep mp->curmsg and "cur" sequence in synch. Unlike + * other sequences, this message doesn't need to exist. + * Think about the series of command (rmm; next) to + * understand why this can be the case. But if it does + * exist, we will still set the bit flag for it like + * other sequences. + */ + if (is_current) + mp->curmsg = j; + /* + * We iterate through messages in this range + * and flip on bit for this sequence. + */ + for (; j <= k; j++) { + if (j >= mp->lowmsg && j <= mp->hghmsg && does_exist(mp, j)) + add_sequence (mp, i, j); + } + } } - } - free (field); /* free string containing message ranges */ - return i; + free (field); /* free string containing message ranges */ + return i; } diff --git a/sbr/seq_save.c b/sbr/seq_save.c index 94b7543..0c14f47 100644 --- a/sbr/seq_save.c +++ b/sbr/seq_save.c @@ -1,4 +1,3 @@ - /* * seq_save.c -- 1) synchronize sequences * -- 2) save public sequences @@ -24,90 +23,90 @@ void seq_save (struct msgs *mp) { - int i; - char flags, *cp, attr[BUFSIZ], seqfile[PATH_MAX]; - FILE *fp; - sigset_t set, oset; + int i; + char flags, *cp, attr[BUFSIZ], seqfile[PATH_MAX]; + FILE *fp; + sigset_t set, oset; - /* check if sequence information has changed */ - if (!(mp->msgflags & SEQMOD)) - return; - mp->msgflags &= ~SEQMOD; + /* check if sequence information has changed */ + if (!(mp->msgflags & SEQMOD)) + return; + mp->msgflags &= ~SEQMOD; - fp = NULL; - flags = mp->msgflags; /* record folder flags */ + fp = NULL; + flags = mp->msgflags; /* record folder flags */ - /* - * If no mh-sequences file is defined, or if a mh-sequences file - * is defined but empty (*mh_seq == '\0'), then pretend folder - * is readonly. This will force all sequences to be private. - */ - if (mh_seq == NULL || *mh_seq == '\0') - set_readonly (mp); - else - snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); + /* + * If no mh-sequences file is defined, or if a mh-sequences file + * is defined but empty (*mh_seq == '\0'), then pretend folder + * is readonly. This will force all sequences to be private. + */ + if (mh_seq == NULL || *mh_seq == '\0') + set_readonly (mp); + else + snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq); - for (i = 0; mp->msgattrs[i]; i++) { - snprintf (attr, sizeof(attr), "atr-%s-%s", mp->msgattrs[i], mp->foldpath); + for (i = 0; mp->msgattrs[i]; i++) { + snprintf (attr, sizeof(attr), "atr-%s-%s", mp->msgattrs[i], mp->foldpath); - /* get space separated list of sequence ranges */ - if (!(cp = seq_list(mp, mp->msgattrs[i]))) { - context_del (attr); /* delete sequence from context */ - continue; - } + /* get space separated list of sequence ranges */ + if (!(cp = seq_list(mp, mp->msgattrs[i]))) { + context_del (attr); /* delete sequence from context */ + continue; + } - if (is_readonly(mp) || is_seq_private(mp, i)) { + if (is_readonly(mp) || is_seq_private(mp, i)) { priv: - /* - * sequence is private - */ - context_replace (attr, cp); /* update sequence in context */ - } else { - /* - * sequence is public - */ - context_del (attr); /* delete sequence from context */ + /* + * sequence is private + */ + context_replace (attr, cp); /* update sequence in context */ + } else { + /* + * sequence is public + */ + context_del (attr); /* delete sequence from context */ - if (!fp) { - /* - * Attempt to open file for public sequences. - * If that fails (probably because folder is - * readonly), then make sequence private. - */ - if ((fp = lkfopen (seqfile, "w")) == NULL - && (unlink (seqfile) == -1 || - (fp = lkfopen (seqfile, "w")) == NULL)) { - admonish (attr, "unable to write"); - goto priv; + if (!fp) { + /* + * Attempt to open file for public sequences. + * If that fails (probably because folder is + * readonly), then make sequence private. + */ + if ((fp = lkfopen (seqfile, "w")) == NULL + && (unlink (seqfile) == -1 || + (fp = lkfopen (seqfile, "w")) == NULL)) { + admonish (attr, "unable to write"); + goto priv; + } + + /* block a few signals */ + sigemptyset (&set); + sigaddset(&set, SIGHUP); + sigaddset(&set, SIGINT); + sigaddset(&set, SIGQUIT); + sigaddset(&set, SIGTERM); + SIGPROCMASK (SIG_BLOCK, &set, &oset); + } + fprintf (fp, "%s: %s\n", mp->msgattrs[i], cp); } + } - /* block a few signals */ - sigemptyset (&set); - sigaddset(&set, SIGHUP); - sigaddset(&set, SIGINT); - sigaddset(&set, SIGQUIT); - sigaddset(&set, SIGTERM); - SIGPROCMASK (SIG_BLOCK, &set, &oset); - } - fprintf (fp, "%s: %s\n", mp->msgattrs[i], cp); + if (fp) { + lkfclose (fp, seqfile); + SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset signal mask */ + } else { + /* + * If folder is not readonly, and we didn't save any + * public sequences, then remove that file. + */ + if (!is_readonly(mp)) + unlink (seqfile); } - } - if (fp) { - lkfclose (fp, seqfile); - SIGPROCMASK (SIG_SETMASK, &oset, &set); /* reset signal mask */ - } else { /* - * If folder is not readonly, and we didn't save any - * public sequences, then remove that file. + * Reset folder flag, since we may be + * pretending that folder is readonly. */ - if (!is_readonly(mp)) - unlink (seqfile); - } - - /* - * Reset folder flag, since we may be - * pretending that folder is readonly. - */ - mp->msgflags = flags; + mp->msgflags = flags; } diff --git a/sbr/seq_setcur.c b/sbr/seq_setcur.c index f18a388..fdf2028 100644 --- a/sbr/seq_setcur.c +++ b/sbr/seq_setcur.c @@ -1,4 +1,3 @@ - /* * seq_setcur.c -- set the current message ("cur" sequence) for a folder * @@ -13,9 +12,9 @@ void seq_setcur (struct msgs *mp, int msgnum) { - /* - * Just call seq_addmsg() to update the - * "cur" sequence. - */ - seq_addmsg (mp, current, msgnum, -1, 1); + /* + * Just call seq_addmsg() to update the + * "cur" sequence. + */ + seq_addmsg (mp, current, msgnum, -1, 1); } diff --git a/sbr/seq_setprev.c b/sbr/seq_setprev.c index 11de143..7e62b64 100644 --- a/sbr/seq_setprev.c +++ b/sbr/seq_setprev.c @@ -1,4 +1,3 @@ - /* * seq_setprev.c -- set the Previous-Sequence * @@ -20,25 +19,25 @@ void seq_setprev (struct msgs *mp) { - char **ap, *cp, *dp; + char **ap, *cp, *dp; - /* - * Get the list of sequences for Previous-Sequence - * and split them. - */ - if ((cp = context_find (psequence))) { - dp = getcpy (cp); - if (!(ap = brkstring (dp, " ", "\n")) || !*ap) { - free (dp); - return; + /* + * Get the list of sequences for Previous-Sequence + * and split them. + */ + if ((cp = context_find (psequence))) { + dp = getcpy (cp); + if (!(ap = brkstring (dp, " ", "\n")) || !*ap) { + free (dp); + return; + } + } else { + return; } - } else { - return; - } - /* Now add all SELECTED messages to each sequence */ - for (; *ap; ap++) - seq_addsel (mp, *ap, -1, 1); + /* Now add all SELECTED messages to each sequence */ + for (; *ap; ap++) + seq_addsel (mp, *ap, -1, 1); - free (dp); + free (dp); } diff --git a/sbr/seq_setunseen.c b/sbr/seq_setunseen.c index ea18d17..a115564 100644 --- a/sbr/seq_setunseen.c +++ b/sbr/seq_setunseen.c @@ -1,4 +1,3 @@ - /* * seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN * -- bit set to/from the Unseen-Sequence @@ -21,40 +20,40 @@ void seq_setunseen (struct msgs *mp, int seen) { - int msgnum; - char **ap, *cp, *dp; + int msgnum; + char **ap, *cp, *dp; - /* - * Get the list of sequences for Unseen-Sequence - * and split them. - */ - if ((cp = context_find (usequence))) { - dp = getcpy (cp); - if (!(ap = brkstring (dp, " ", "\n")) || !*ap) { - free (dp); - return; + /* + * Get the list of sequences for Unseen-Sequence + * and split them. + */ + if ((cp = context_find (usequence))) { + dp = getcpy (cp); + if (!(ap = brkstring (dp, " ", "\n")) || !*ap) { + free (dp); + return; + } + } else { + return; } - } else { - return; - } - /* - * Now add/delete each message which has the SELECT_UNSEEN - * bit set to/from each of these sequences. - */ - for (; *ap; ap++) { - if (seen) { - /* make sure sequence exists first */ - if (seq_getnum(mp, *ap) != -1) - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_unseen (mp, msgnum)) - seq_delmsg (mp, *ap, msgnum); - } else { - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) - if (is_unseen (mp, msgnum)) - seq_addmsg (mp, *ap, msgnum, -1, 0); + /* + * Now add/delete each message which has the SELECT_UNSEEN + * bit set to/from each of these sequences. + */ + for (; *ap; ap++) { + if (seen) { + /* make sure sequence exists first */ + if (seq_getnum(mp, *ap) != -1) + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_unseen (mp, msgnum)) + seq_delmsg (mp, *ap, msgnum); + } else { + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) + if (is_unseen (mp, msgnum)) + seq_addmsg (mp, *ap, msgnum, -1, 0); + } } - } - free (dp); + free (dp); } diff --git a/sbr/showfile.c b/sbr/showfile.c index 59ae795..b8e984b 100644 --- a/sbr/showfile.c +++ b/sbr/showfile.c @@ -1,4 +1,3 @@ - /* * showfile.c -- invoke the `lproc' command * @@ -13,55 +12,55 @@ int showfile (char **arg, char *file) { - pid_t pid; - int isdraft, vecp; - char *vec[MAXARGS]; + pid_t pid; + int isdraft, vecp; + char *vec[MAXARGS]; - context_save(); /* save the context file */ - fflush(stdout); + context_save(); /* save the context file */ + fflush(stdout); - /* - * If you have your lproc listed as "mhl", - * then really invoked the mhlproc instead - * (which is usually mhl anyway). - */ - if (!strcmp (r1bindex (lproc, '/'), "mhl")) - lproc = mhlproc; + /* + * If you have your lproc listed as "mhl", + * then really invoked the mhlproc instead + * (which is usually mhl anyway). + */ + if (!strcmp (r1bindex (lproc, '/'), "mhl")) + lproc = mhlproc; - switch (pid = vfork()) { - case -1: - /* fork error */ - advise ("fork", "unable to"); - return 1; + switch (pid = vfork()) { + case -1: + /* fork error */ + advise ("fork", "unable to"); + return 1; - case 0: - /* child */ - vecp = 0; - vec[vecp++] = r1bindex (lproc, '/'); - isdraft = 1; - if (arg) { - while (*arg) { - if (**arg != '-') - isdraft = 0; - vec[vecp++] = *arg++; - } - } - if (isdraft) { - if (!strcmp (vec[0], "show")) - vec[vecp++] = "-file"; - vec[vecp++] = file; - } - vec[vecp] = NULL; + case 0: + /* child */ + vecp = 0; + vec[vecp++] = r1bindex (lproc, '/'); + isdraft = 1; + if (arg) { + while (*arg) { + if (**arg != '-') + isdraft = 0; + vec[vecp++] = *arg++; + } + } + if (isdraft) { + if (!strcmp (vec[0], "show")) + vec[vecp++] = "-file"; + vec[vecp++] = file; + } + vec[vecp] = NULL; - execvp (lproc, vec); - fprintf (stderr, "unable to exec "); - perror (lproc); - _exit (-1); + execvp (lproc, vec); + fprintf (stderr, "unable to exec "); + perror (lproc); + _exit (-1); - default: - /* parent */ - return (pidwait (pid, -1) & 0377 ? 1 : 0); - } + default: + /* parent */ + return (pidwait (pid, -1) & 0377 ? 1 : 0); + } - return 1; /* NOT REACHED */ + return 1; /* NOT REACHED */ } diff --git a/sbr/sigmsg.awk b/sbr/sigmsg.awk index 88beac1..699302c 100755 --- a/sbr/sigmsg.awk +++ b/sbr/sigmsg.awk @@ -1,4 +1,4 @@ -# +# # sigmsg.awk -- awk/nawk/gawk script to generate sigmsg.h # # provided by Geoff Wing @@ -6,80 +6,80 @@ # On SunOS 4.1.3 - user-functions don't work properly, also \" problems # Without 0 + hacks some nawks compare numbers as strings # -/^[\t ]*#[\t ]*define[\t _]*SIG[A-Z][A-Z0-9]*[\t ]*[1-9][0-9]*/ { - sigindex = index($0, "SIG") - sigtail = substr($0, sigindex, 80) - split(sigtail, tmp) - signam = substr(tmp[1], 4, 20) - signum = tmp[2] - if (sig[signum] == "") { - sig[signum] = signam - if (0 + max < 0 + signum && signum < 60) - max = signum - if (signam == "ABRT") { msg[signum] = "abort" } - if (signam == "ALRM") { msg[signum] = "alarm" } - if (signam == "BUS") { msg[signum] = "bus error" } - if (signam == "CHLD") { msg[signum] = "death of child" } - if (signam == "CLD") { msg[signum] = "death of child" } - if (signam == "CONT") { msg[signum] = "continued" } - if (signam == "EMT") { msg[signum] = "EMT instruction" } - if (signam == "FPE") { msg[signum] = "floating point exception" } - if (signam == "HUP") { msg[signum] = "hangup" } - if (signam == "ILL") { msg[signum] = "illegal hardware instruction" } - if (signam == "INFO") { msg[signum] = "status request from keyboard" } - if (signam == "INT") { msg[signum] = "interrupt" } - if (signam == "IO") { msg[signum] = "i/o ready" } - if (signam == "IOT") { msg[signum] = "IOT instruction" } - if (signam == "KILL") { msg[signum] = "killed" } - if (signam == "LOST") { msg[signum] = "resource lost" } - if (signam == "PIPE") { msg[signum] = "broken pipe" } - if (signam == "POLL") { msg[signum] = "pollable event occurred" } - if (signam == "PROF") { msg[signum] = "profile signal" } - if (signam == "PWR") { msg[signum] = "power fail" } - if (signam == "QUIT") { msg[signum] = "quit" } - if (signam == "SEGV") { msg[signum] = "segmentation fault" } - if (signam == "SYS") { msg[signum] = "invalid system call" } - if (signam == "TERM") { msg[signum] = "terminated" } - if (signam == "TRAP") { msg[signum] = "trace trap" } - if (signam == "URG") { msg[signum] = "urgent condition" } - if (signam == "USR1") { msg[signum] = "user-defined signal 1" } - if (signam == "USR2") { msg[signum] = "user-defined signal 2" } - if (signam == "VTALRM") { msg[signum] = "virtual time alarm" } - if (signam == "WINCH") { msg[signum] = "window size changed" } - if (signam == "XCPU") { msg[signum] = "cpu limit exceeded" } - if (signam == "XFSZ") { msg[signum] = "file size limit exceeded" } - } +/^[\t ]*#[\t ]*define[\t _]*SIG[A-Z][A-Z0-9]*[\t ]*[1-9][0-9]*/ { + sigindex = index($0, "SIG") + sigtail = substr($0, sigindex, 80) + split(sigtail, tmp) + signam = substr(tmp[1], 4, 20) + signum = tmp[2] + if (sig[signum] == "") { + sig[signum] = signam + if (0 + max < 0 + signum && signum < 60) + max = signum + if (signam == "ABRT") { msg[signum] = "abort" } + if (signam == "ALRM") { msg[signum] = "alarm" } + if (signam == "BUS") { msg[signum] = "bus error" } + if (signam == "CHLD") { msg[signum] = "death of child" } + if (signam == "CLD") { msg[signum] = "death of child" } + if (signam == "CONT") { msg[signum] = "continued" } + if (signam == "EMT") { msg[signum] = "EMT instruction" } + if (signam == "FPE") { msg[signum] = "floating point exception" } + if (signam == "HUP") { msg[signum] = "hangup" } + if (signam == "ILL") { msg[signum] = "illegal hardware instruction" } + if (signam == "INFO") { msg[signum] = "status request from keyboard" } + if (signam == "INT") { msg[signum] = "interrupt" } + if (signam == "IO") { msg[signum] = "i/o ready" } + if (signam == "IOT") { msg[signum] = "IOT instruction" } + if (signam == "KILL") { msg[signum] = "killed" } + if (signam == "LOST") { msg[signum] = "resource lost" } + if (signam == "PIPE") { msg[signum] = "broken pipe" } + if (signam == "POLL") { msg[signum] = "pollable event occurred" } + if (signam == "PROF") { msg[signum] = "profile signal" } + if (signam == "PWR") { msg[signum] = "power fail" } + if (signam == "QUIT") { msg[signum] = "quit" } + if (signam == "SEGV") { msg[signum] = "segmentation fault" } + if (signam == "SYS") { msg[signum] = "invalid system call" } + if (signam == "TERM") { msg[signum] = "terminated" } + if (signam == "TRAP") { msg[signum] = "trace trap" } + if (signam == "URG") { msg[signum] = "urgent condition" } + if (signam == "USR1") { msg[signum] = "user-defined signal 1" } + if (signam == "USR2") { msg[signum] = "user-defined signal 2" } + if (signam == "VTALRM") { msg[signum] = "virtual time alarm" } + if (signam == "WINCH") { msg[signum] = "window size changed" } + if (signam == "XCPU") { msg[signum] = "cpu limit exceeded" } + if (signam == "XFSZ") { msg[signum] = "file size limit exceeded" } + } } END { - ps = "%s" - ifdstr = sprintf("\t%cstopped%s%c,\n", 34, ps, 34) + ps = "%s" + ifdstr = sprintf("\t%cstopped%s%c,\n", 34, ps, 34) - print "\n/*" - print " * sigmsg.h -- architecture-customized signal messages for nmh" - print " *" - print " * automatically generated by sigmsg.awk" - print " */\n" - printf("%s %d\n\n", "#define SIGCOUNT", max) - print "char *sigmsg[SIGCOUNT+2] = {" - print "\tNULL," + print "\n/*" + print " * sigmsg.h -- architecture-customized signal messages for nmh" + print " *" + print " * automatically generated by sigmsg.awk" + print " */\n" + printf("%s %d\n\n", "#define SIGCOUNT", max) + print "char *sigmsg[SIGCOUNT+2] = {" + print "\tNULL," - for (i = 1; i <= 0 + max; i++) - if (msg[i] == "") { - if (sig[i] == "") - printf("\tNULL,\n") - else if (sig[i] == "STOP") - printf ifdstr, " (signal)", " (signal)" - else if (sig[i] == "TSTP") - printf ifdstr, "", "" - else if (sig[i] == "TTIN") - printf ifdstr, " (tty input)", " (tty input)" - else if (sig[i] == "TTOU") - printf ifdstr, " (tty output)", " (tty output)" - else - printf("\t%cSIG%s%c,\n", 34, sig[i], 34) - } else - printf("\t%c%s%c,\n", 34, msg[i], 34) - print "\tNULL" - print "};" + for (i = 1; i <= 0 + max; i++) + if (msg[i] == "") { + if (sig[i] == "") + printf("\tNULL,\n") + else if (sig[i] == "STOP") + printf ifdstr, " (signal)", " (signal)" + else if (sig[i] == "TSTP") + printf ifdstr, "", "" + else if (sig[i] == "TTIN") + printf ifdstr, " (tty input)", " (tty input)" + else if (sig[i] == "TTOU") + printf ifdstr, " (tty output)", " (tty output)" + else + printf("\t%cSIG%s%c,\n", 34, sig[i], 34) + } else + printf("\t%c%s%c,\n", 34, msg[i], 34) + print "\tNULL" + print "};" } diff --git a/sbr/signals.c b/sbr/signals.c index 919b8e0..00f516c 100644 --- a/sbr/signals.c +++ b/sbr/signals.c @@ -1,4 +1,3 @@ - /* * signals.c -- general signals interface for nmh * @@ -15,26 +14,26 @@ int SIGPROCMASK (int how, const sigset_t *set, sigset_t *oset) { #ifdef POSIX_SIGNALS - return sigprocmask(how, set, oset); + return sigprocmask(how, set, oset); #else # ifdef BSD_SIGNALS - switch(how) { - case SIG_BLOCK: - *oset = sigblock(*set); - break; - case SIG_UNBLOCK: - sigfillset(*oset); - *oset = sigsetmask(*oset); - sigsetmask(*oset & ~(*set)); - break; - case SIG_SETMASK: - *oset = sigsetmask(*set); - break; - default: - adios(NULL, "unknown flag in SIGPROCMASK"); - break; - } - return 0; + switch(how) { + case SIG_BLOCK: + *oset = sigblock(*set); + break; + case SIG_UNBLOCK: + sigfillset(*oset); + *oset = sigsetmask(*oset); + sigsetmask(*oset & ~(*set)); + break; + case SIG_SETMASK: + *oset = sigsetmask(*set); + break; + default: + adios(NULL, "unknown flag in SIGPROCMASK"); + break; + } + return 0; # endif #endif } @@ -51,26 +50,26 @@ SIGNAL_HANDLER SIGNAL (int sig, SIGNAL_HANDLER func) { #ifdef POSIX_SIGNALS - struct sigaction act, oact; + struct sigaction act, oact; - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; - if (sig == SIGALRM) { + if (sig == SIGALRM) { # ifdef SA_INTERRUPT - act.sa_flags |= SA_INTERRUPT; /* SunOS */ + act.sa_flags |= SA_INTERRUPT; /* SunOS */ # endif - } else { + } else { # ifdef SA_RESTART - act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ + act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ # endif - } - if (sigaction(sig, &act, &oact) < 0) - return (SIG_ERR); - return (oact.sa_handler); + } + if (sigaction(sig, &act, &oact) < 0) + return (SIG_ERR); + return (oact.sa_handler); #else - return signal (sig, func); + return signal (sig, func); #endif } @@ -85,34 +84,33 @@ SIGNAL_HANDLER SIGNAL2 (int sig, SIGNAL_HANDLER func) { #ifdef POSIX_SIGNALS - struct sigaction act, oact; + struct sigaction act, oact; - if (sigaction(sig, NULL, &oact) < 0) - return (SIG_ERR); - if (oact.sa_handler != SIG_IGN) { - act.sa_handler = func; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; + if (sigaction(sig, NULL, &oact) < 0) + return (SIG_ERR); + if (oact.sa_handler != SIG_IGN) { + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; - if (sig == SIGALRM) { + if (sig == SIGALRM) { # ifdef SA_INTERRUPT - act.sa_flags |= SA_INTERRUPT; /* SunOS */ + act.sa_flags |= SA_INTERRUPT; /* SunOS */ # endif - } else { + } else { # ifdef SA_RESTART - act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ + act.sa_flags |= SA_RESTART; /* SVR4, BSD4.4 */ # endif + } + if (sigaction(sig, &act, &oact) < 0) + return (SIG_ERR); } - if (sigaction(sig, &act, &oact) < 0) - return (SIG_ERR); - } - return (oact.sa_handler); + return (oact.sa_handler); #else - SIGNAL_HANDLER ofunc; + SIGNAL_HANDLER ofunc; - if ((ofunc = signal (sig, SIG_IGN)) != SIG_IGN) - signal (sig, func); - return ofunc; + if ((ofunc = signal (sig, SIG_IGN)) != SIG_IGN) + signal (sig, func); + return ofunc; #endif } - diff --git a/sbr/smatch.c b/sbr/smatch.c index 88a098b..b22df66 100644 --- a/sbr/smatch.c +++ b/sbr/smatch.c @@ -1,4 +1,3 @@ - /* * smatch.c -- match a switch (option) * @@ -13,35 +12,35 @@ int smatch(char *string, struct swit *swp) { - char *sp, *tcp; - int firstone, len; - struct swit *tp; - - firstone = UNKWNSW; - - if (!string) - return firstone; - len = strlen(string); - - for (tp = swp; tp->sw; tp++) { - tcp = tp->sw; - if (len < abs(tp->minchars)) - continue; /* no match */ - for (sp = string; *sp == *tcp++;) { - if (*sp++ == '\0') - return (tp - swp); /* exact match */ - } - if (*sp) { - if (*sp != ' ') - continue; /* no match */ - if (*--tcp == '\0') - return (tp - swp); /* exact match */ + char *sp, *tcp; + int firstone, len; + struct swit *tp; + + firstone = UNKWNSW; + + if (!string) + return firstone; + len = strlen(string); + + for (tp = swp; tp->sw; tp++) { + tcp = tp->sw; + if (len < abs(tp->minchars)) + continue; /* no match */ + for (sp = string; *sp == *tcp++;) { + if (*sp++ == '\0') + return (tp - swp); /* exact match */ + } + if (*sp) { + if (*sp != ' ') + continue; /* no match */ + if (*--tcp == '\0') + return (tp - swp); /* exact match */ + } + if (firstone == UNKWNSW) + firstone = tp - swp; + else + firstone = AMBIGSW; } - if (firstone == UNKWNSW) - firstone = tp - swp; - else - firstone = AMBIGSW; - } - return (firstone); + return (firstone); } diff --git a/sbr/snprintb.c b/sbr/snprintb.c index 5f3f124..baab61f 100644 --- a/sbr/snprintb.c +++ b/sbr/snprintb.c @@ -1,4 +1,3 @@ - /* * snprintb.c -- snprintf a %b string * @@ -13,28 +12,27 @@ char * snprintb (char *buffer, size_t n, unsigned v, char *bits) { - register int i, j; - register char c, *bp; + register int i, j; + register char c, *bp; - snprintf (buffer, n, bits && *bits == 010 ? "0%o" : "0x%x", v); - bp = buffer + strlen(buffer); + snprintf (buffer, n, bits && *bits == 010 ? "0%o" : "0x%x", v); + bp = buffer + strlen(buffer); - if (bits && *++bits) { - j = 0; - *bp++ = '<'; - while ((i = *bits++)) - if (v & (1 << (i - 1))) { - if (j++) - *bp++ = ','; - for (; (c = *bits) > 32; bits++) - *bp++ = c; - } - else - for (; *bits > 32; bits++) - continue; - *bp++ = '>'; - *bp = 0; - } + if (bits && *++bits) { + j = 0; + *bp++ = '<'; + while ((i = *bits++)) + if (v & (1 << (i - 1))) { + if (j++) + *bp++ = ','; + for (; (c = *bits) > 32; bits++) + *bp++ = c; + } else + for (; *bits > 32; bits++) + continue; + *bp++ = '>'; + *bp = 0; + } - return buffer; + return buffer; } diff --git a/sbr/snprintf.c b/sbr/snprintf.c index efb6df0..9bc163a 100644 --- a/sbr/snprintf.c +++ b/sbr/snprintf.c @@ -14,7 +14,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -76,33 +76,33 @@ #include typedef enum { - NO = 0, YES = 1 + NO = 0, YES = 1 } boolean_e; #ifndef FALSE -#define FALSE 0 +# define FALSE 0 #endif #ifndef TRUE -#define TRUE 1 +# define TRUE 1 #endif -#define NUL '\0' -#define INT_NULL ((int *)0) -#define WIDE_INT long +#define NUL '\0' +#define INT_NULL ((int *)0) +#define WIDE_INT long typedef struct { - char *curpos; - char *endpos; + char *curpos; + char *endpos; } ap_vformatter_buff; typedef WIDE_INT wide_int; typedef unsigned WIDE_INT u_wide_int; typedef int bool_int; -#define S_NULL "(null)" -#define S_NULL_LEN 6 +#define S_NULL "(null)" +#define S_NULL_LEN 6 -#define FLOAT_DIGITS 6 -#define EXPONENT_LENGTH 10 +#define FLOAT_DIGITS 6 +#define EXPONENT_LENGTH 10 /* These macros allow correct support of 8-bit characters on systems which * support 8-bit characters. Pretty dumb how the cast is required, but @@ -118,7 +118,7 @@ typedef int bool_int; * * XXX: this is a magic number; do not decrease it */ -#define NUM_BUF_SIZE 512 +#define NUM_BUF_SIZE 512 /* * cvt.c - IEEE floating point formatting routines for FreeBSD @@ -132,90 +132,89 @@ typedef int bool_int; * sign is set to 0 for positive, 1 for negative */ -#define NDIG 80 +#define NDIG 80 /* buf must have at least NDIG bytes */ static char *ap_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag, char *buf) { - register int r2; - double fi, fj; - register char *p, *p1; - - if (ndigits >= NDIG - 1) - ndigits = NDIG - 2; - r2 = 0; - *sign = 0; - p = &buf[0]; - if (arg < 0) { - *sign = 1; - arg = -arg; - } - arg = modf(arg, &fi); - p1 = &buf[NDIG]; - /* - * Do integer part - */ - if (fi != 0) { + register int r2; + double fi, fj; + register char *p, *p1; + + if (ndigits >= NDIG - 1) + ndigits = NDIG - 2; + r2 = 0; + *sign = 0; + p = &buf[0]; + if (arg < 0) { + *sign = 1; + arg = -arg; + } + arg = modf(arg, &fi); p1 = &buf[NDIG]; - while (fi != 0) { - fj = modf(fi / 10, &fi); - *--p1 = (int) ((fj + .03) * 10) + '0'; - r2++; + /* + * Do integer part + */ + if (fi != 0) { + p1 = &buf[NDIG]; + while (fi != 0) { + fj = modf(fi / 10, &fi); + *--p1 = (int) ((fj + .03) * 10) + '0'; + r2++; + } + while (p1 < &buf[NDIG]) + *p++ = *p1++; + } else if (arg > 0) { + while ((fj = arg * 10) < 1) { + arg = fj; + r2--; + } } - while (p1 < &buf[NDIG]) - *p++ = *p1++; - } - else if (arg > 0) { - while ((fj = arg * 10) < 1) { - arg = fj; - r2--; + p1 = &buf[ndigits]; + if (eflag == 0) + p1 += r2; + *decpt = r2; + if (p1 < &buf[0]) { + buf[0] = '\0'; + return (buf); } - } - p1 = &buf[ndigits]; - if (eflag == 0) - p1 += r2; - *decpt = r2; - if (p1 < &buf[0]) { - buf[0] = '\0'; - return (buf); - } - while (p <= p1 && p < &buf[NDIG]) { - arg *= 10; - arg = modf(arg, &fj); - *p++ = (int) fj + '0'; - } - if (p1 >= &buf[NDIG]) { - buf[NDIG - 1] = '\0'; - return (buf); - } - p = p1; - *p1 += 5; - while (*p1 > '9') { - *p1 = '0'; - if (p1 > buf) - ++ * --p1; - else { - *p1 = '1'; - (*decpt)++; - if (eflag == 0) { - if (p > buf) - *p = '0'; - p++; - } + while (p <= p1 && p < &buf[NDIG]) { + arg *= 10; + arg = modf(arg, &fj); + *p++ = (int) fj + '0'; } - } - *p = '\0'; - return (buf); + if (p1 >= &buf[NDIG]) { + buf[NDIG - 1] = '\0'; + return (buf); + } + p = p1; + *p1 += 5; + while (*p1 > '9') { + *p1 = '0'; + if (p1 > buf) + ++ * --p1; + else { + *p1 = '1'; + (*decpt)++; + if (eflag == 0) { + if (p > buf) + *p = '0'; + p++; + } + } + } + *p = '\0'; + return (buf); } static char *ap_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf) { - return (ap_cvt(arg, ndigits, decpt, sign, 1, buf)); + return (ap_cvt(arg, ndigits, decpt, sign, 1, buf)); } static char *ap_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) { - return (ap_cvt(arg, ndigits, decpt, sign, 0, buf)); + return (ap_cvt(arg, ndigits, decpt, sign, 0, buf)); } /* @@ -225,61 +224,59 @@ static char *ap_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf) static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) { - int sign, decpt; - register char *p1, *p2; - register int i; - char buf1[NDIG]; - - p1 = ap_ecvt(number, ndigit, &decpt, &sign, buf1); - p2 = buf; - if (sign) - *p2++ = '-'; - for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--) - ndigit--; - if ((decpt >= 0 && decpt - ndigit > 4) - || (decpt < 0 && decpt < -3)) { /* use E-style */ - decpt--; - *p2++ = *p1++; - *p2++ = '.'; - for (i = 1; i < ndigit; i++) - *p2++ = *p1++; - *p2++ = 'e'; - if (decpt < 0) { - decpt = -decpt; - *p2++ = '-'; - } - else - *p2++ = '+'; - if (decpt / 100 > 0) - *p2++ = decpt / 100 + '0'; - if (decpt / 10 > 0) - *p2++ = (decpt % 100) / 10 + '0'; - *p2++ = decpt % 10 + '0'; - } - else { - if (decpt <= 0) { - if (*p1 != '0') - *p2++ = '.'; - while (decpt < 0) { - decpt++; - *p2++ = '0'; - } - } - for (i = 1; i <= ndigit; i++) { - *p2++ = *p1++; - if (i == decpt) + int sign, decpt; + register char *p1, *p2; + register int i; + char buf1[NDIG]; + + p1 = ap_ecvt(number, ndigit, &decpt, &sign, buf1); + p2 = buf; + if (sign) + *p2++ = '-'; + for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--) + ndigit--; + if ((decpt >= 0 && decpt - ndigit > 4) + || (decpt < 0 && decpt < -3)) { /* use E-style */ + decpt--; + *p2++ = *p1++; *p2++ = '.'; + for (i = 1; i < ndigit; i++) + *p2++ = *p1++; + *p2++ = 'e'; + if (decpt < 0) { + decpt = -decpt; + *p2++ = '-'; + } else + *p2++ = '+'; + if (decpt / 100 > 0) + *p2++ = decpt / 100 + '0'; + if (decpt / 10 > 0) + *p2++ = (decpt % 100) / 10 + '0'; + *p2++ = decpt % 10 + '0'; + } else { + if (decpt <= 0) { + if (*p1 != '0') + *p2++ = '.'; + while (decpt < 0) { + decpt++; + *p2++ = '0'; + } + } + for (i = 1; i <= ndigit; i++) { + *p2++ = *p1++; + if (i == decpt) + *p2++ = '.'; + } + if (ndigit < decpt) { + while (ndigit++ < decpt) + *p2++ = '0'; + *p2++ = '.'; + } } - if (ndigit < decpt) { - while (ndigit++ < decpt) - *p2++ = '0'; - *p2++ = '.'; - } - } - if (p2[-1] == '.' && !altform) - p2--; - *p2 = '\0'; - return (buf); + if (p2[-1] == '.' && !altform) + p2--; + *p2 = '\0'; + return (buf); } /* @@ -292,28 +289,28 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * * NOTE: Evaluation of the c argument should not have any side-effects */ -#define INS_CHAR(c, sp, bep, cc) \ - { \ - if (sp >= bep) { \ - vbuff->curpos = sp; \ - if (flush_func(vbuff)) \ - return -1; \ - sp = vbuff->curpos; \ - bep = vbuff->endpos; \ - } \ - *sp++ = (c); \ - cc++; \ - } - -#define NUM( c ) ( c - '0' ) - -#define STR_TO_DEC( str, num ) \ - num = NUM( *str++ ) ; \ - while ( ap_isdigit( *str ) ) \ - { \ - num *= 10 ; \ - num += NUM( *str++ ) ; \ - } +#define INS_CHAR(c, sp, bep, cc) \ + { \ + if (sp >= bep) { \ + vbuff->curpos = sp; \ + if (flush_func(vbuff)) \ + return -1; \ + sp = vbuff->curpos; \ + bep = vbuff->endpos; \ + } \ + *sp++ = (c); \ + cc++; \ + } + +#define NUM( c ) ( c - '0' ) + +#define STR_TO_DEC( str, num ) \ + num = NUM( *str++ ) ; \ + while ( ap_isdigit( *str ) ) \ + { \ + num *= 10 ; \ + num += NUM( *str++ ) ; \ + } /* * This macro does zero padding so that the precision @@ -321,23 +318,23 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * adding '0's to the left of the string that is going * to be printed. */ -#define FIX_PRECISION( adjust, precision, s, s_len ) \ - if ( adjust ) \ - while ( s_len < precision ) \ - { \ - *--s = '0' ; \ - s_len++ ; \ - } +#define FIX_PRECISION( adjust, precision, s, s_len ) \ + if ( adjust ) \ + while ( s_len < precision ) \ + { \ + *--s = '0' ; \ + s_len++ ; \ + } /* * Macro that does padding. The padding is done by printing * the character ch. */ -#define PAD( width, len, ch ) do \ - { \ - INS_CHAR( ch, sp, bep, cc ) ; \ - width-- ; \ - } \ +#define PAD( width, len, ch ) do \ + { \ + INS_CHAR( ch, sp, bep, cc ) ; \ + width-- ; \ + } \ while ( width > len ) /* @@ -345,7 +342,7 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * Increase length * Set the has_prefix flag */ -#define PREFIX( str, length, ch ) *--str = ch ; length++ ; has_prefix = YES +#define PREFIX( str, length, ch ) *--str = ch ; length++ ; has_prefix = YES /* @@ -361,87 +358,85 @@ static char *ap_gcvt(double number, int ndigit, char *buf, boolean_e altform) * is declared as buf[ 100 ], buf_end should be &buf[ 100 ]) */ static char *conv_10(register wide_int num, register bool_int is_unsigned, - register bool_int *is_negative, char *buf_end, - register int *len) + register bool_int *is_negative, char *buf_end, + register int *len) { - register char *p = buf_end; - register u_wide_int magnitude; + register char *p = buf_end; + register u_wide_int magnitude; - if (is_unsigned) { - magnitude = (u_wide_int) num; - *is_negative = FALSE; - } - else { - *is_negative = (num < 0); + if (is_unsigned) { + magnitude = (u_wide_int) num; + *is_negative = FALSE; + } else { + *is_negative = (num < 0); + + /* + * On a 2's complement machine, negating the most negative integer + * results in a number that cannot be represented as a signed integer. + * Here is what we do to obtain the number's magnitude: + * a. add 1 to the number + * b. negate it (becomes positive) + * c. convert it to unsigned + * d. add 1 + */ + if (*is_negative) { + wide_int t = num + 1; + + magnitude = ((u_wide_int) -t) + 1; + } else + magnitude = (u_wide_int) num; + } /* - * On a 2's complement machine, negating the most negative integer - * results in a number that cannot be represented as a signed integer. - * Here is what we do to obtain the number's magnitude: - * a. add 1 to the number - * b. negate it (becomes positive) - * c. convert it to unsigned - * d. add 1 + * We use a do-while loop so that we write at least 1 digit */ - if (*is_negative) { - wide_int t = num + 1; + do { + register u_wide_int new_magnitude = magnitude / 10; - magnitude = ((u_wide_int) -t) + 1; + *--p = (char) (magnitude - new_magnitude * 10 + '0'); + magnitude = new_magnitude; } - else - magnitude = (u_wide_int) num; - } - - /* - * We use a do-while loop so that we write at least 1 digit - */ - do { - register u_wide_int new_magnitude = magnitude / 10; - - *--p = (char) (magnitude - new_magnitude * 10 + '0'); - magnitude = new_magnitude; - } - while (magnitude); - - *len = buf_end - p; - return (p); + while (magnitude); + + *len = buf_end - p; + return (p); } static char *conv_in_addr(struct in_addr *ia, char *buf_end, int *len) { - unsigned addr = ntohl(ia->s_addr); - char *p = buf_end; - bool_int is_negative; - int sub_len; - - p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len); - *--p = '.'; - p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len); - - *len = buf_end - p; - return (p); + unsigned addr = ntohl(ia->s_addr); + char *p = buf_end; + bool_int is_negative; + int sub_len; + + p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len); + + *len = buf_end - p; + return (p); } static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) { - char *p = buf_end; - bool_int is_negative; - int sub_len; + char *p = buf_end; + bool_int is_negative; + int sub_len; - p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len); - *--p = ':'; - p = conv_in_addr(&si->sin_addr, p, &sub_len); + p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len); + *--p = ':'; + p = conv_in_addr(&si->sin_addr, p, &sub_len); - *len = buf_end - p; - return (p); + *len = buf_end - p; + return (p); } @@ -453,87 +448,84 @@ static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) * in buf). */ static char *conv_fp(register char format, register double num, - boolean_e add_dp, int precision, bool_int *is_negative, - char *buf, int *len) + boolean_e add_dp, int precision, bool_int *is_negative, + char *buf, int *len) { - register char *s = buf; - register char *p; - int decimal_point; - char buf1[NDIG]; - - if (format == 'f') - p = ap_fcvt(num, precision, &decimal_point, is_negative, buf1); - else /* either e or E format */ - p = ap_ecvt(num, precision + 1, &decimal_point, is_negative, buf1); - - /* - * Check for Infinity and NaN - */ - if (ap_isalpha(*p)) { - *len = strlen(strcpy(buf, p)); - *is_negative = FALSE; - return (buf); - } - - if (format == 'f') { - if (decimal_point <= 0) { - *s++ = '0'; - if (precision > 0) { - *s++ = '.'; - while (decimal_point++ < 0) - *s++ = '0'; - } - else if (add_dp) - *s++ = '.'; + register char *s = buf; + register char *p; + int decimal_point; + char buf1[NDIG]; + + if (format == 'f') + p = ap_fcvt(num, precision, &decimal_point, is_negative, buf1); + else /* either e or E format */ + p = ap_ecvt(num, precision + 1, &decimal_point, is_negative, buf1); + + /* + * Check for Infinity and NaN + */ + if (ap_isalpha(*p)) { + *len = strlen(strcpy(buf, p)); + *is_negative = FALSE; + return (buf); } - else { - while (decimal_point-- > 0) + + if (format == 'f') { + if (decimal_point <= 0) { + *s++ = '0'; + if (precision > 0) { + *s++ = '.'; + while (decimal_point++ < 0) + *s++ = '0'; + } else if (add_dp) + *s++ = '.'; + } else { + while (decimal_point-- > 0) + *s++ = *p++; + if (precision > 0 || add_dp) + *s++ = '.'; + } + } else { *s++ = *p++; - if (precision > 0 || add_dp) - *s++ = '.'; + if (precision > 0 || add_dp) + *s++ = '.'; } - } - else { - *s++ = *p++; - if (precision > 0 || add_dp) - *s++ = '.'; - } - - /* - * copy the rest of p, the NUL is NOT copied - */ - while (*p) - *s++ = *p++; - - if (format != 'f') { - char temp[EXPONENT_LENGTH]; /* for exponent conversion */ - int t_len; - bool_int exponent_is_negative; - - *s++ = format; /* either e or E */ - decimal_point--; - if (decimal_point != 0) { - p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative, - &temp[EXPONENT_LENGTH], &t_len); - *s++ = exponent_is_negative ? '-' : '+'; - - /* - * Make sure the exponent has at least 2 digits - */ - if (t_len == 1) - *s++ = '0'; - while (t_len--) + + /* + * copy the rest of p, the NUL is NOT copied + */ + while (*p) *s++ = *p++; + + if (format != 'f') { + char temp[EXPONENT_LENGTH]; /* for exponent conversion */ + int t_len; + bool_int exponent_is_negative; + + *s++ = format; /* either e or E */ + decimal_point--; + if (decimal_point != 0) { + p = conv_10((wide_int) decimal_point, FALSE, + &exponent_is_negative, &temp[EXPONENT_LENGTH], + &t_len); + *s++ = exponent_is_negative ? '-' : '+'; + + /* + * Make sure the exponent has at least 2 digits + */ + if (t_len == 1) + *s++ = '0'; + while (t_len--) + *s++ = *p++; + } else { + *s++ = '+'; + *s++ = '0'; + *s++ = '0'; + } } - else { - *s++ = '+'; - *s++ = '0'; - *s++ = '0'; - } - } - *len = s - buf; - return (buf); + *len = s - buf; + return (buf); } @@ -548,22 +540,22 @@ static char *conv_fp(register char format, register double num, * is declared as buf[ 100 ], buf_end should be &buf[ 100 ]) */ static char *conv_p2(register u_wide_int num, register int nbits, - char format, char *buf_end, register int *len) + char format, char *buf_end, register int *len) { - register int mask = (1 << nbits) - 1; - register char *p = buf_end; - static const char low_digits[] = "0123456789abcdef"; - static const char upper_digits[] = "0123456789ABCDEF"; - register const char *digits = (format == 'X') ? upper_digits : low_digits; - - do { - *--p = digits[num & mask]; - num >>= nbits; - } - while (num); - - *len = buf_end - p; - return (p); + register int mask = (1 << nbits) - 1; + register char *p = buf_end; + static const char low_digits[] = "0123456789abcdef"; + static const char upper_digits[] = "0123456789ABCDEF"; + register const char *digits = (format == 'X') ? upper_digits : low_digits; + + do { + *--p = digits[num & mask]; + num >>= nbits; + } + while (num); + + *len = buf_end - p; + return (p); } @@ -571,475 +563,467 @@ static char *conv_p2(register u_wide_int num, register int nbits, * Do format conversion placing the output in buffer */ int ap_vformatter(int (*flush_func)(ap_vformatter_buff *), - ap_vformatter_buff *vbuff, const char *fmt, va_list ap) + ap_vformatter_buff *vbuff, const char *fmt, va_list ap) { - register char *sp; - register char *bep; - register int cc = 0; - register int i; - - register char *s = NULL; - char *q; - int s_len; - - register int min_width = 0; - int precision = 0; - enum { - LEFT, RIGHT - } adjust; - char pad_char; - char prefix_char; - - double fp_num; - wide_int i_num = (wide_int) 0; - u_wide_int ui_num; - - char num_buf[NUM_BUF_SIZE]; - char char_buf[2]; /* for printing %% and % */ - - /* - * Flag variables - */ - boolean_e is_long; - boolean_e alternate_form; - boolean_e print_sign; - boolean_e print_blank; - boolean_e adjust_precision; - boolean_e adjust_width; - bool_int is_negative; - - sp = vbuff->curpos; - bep = vbuff->endpos; - - while (*fmt) { - if (*fmt != '%') { - INS_CHAR(*fmt, sp, bep, cc); - } - else { - /* - * Default variable settings - */ - adjust = RIGHT; - alternate_form = print_sign = print_blank = NO; - pad_char = ' '; - prefix_char = NUL; - - fmt++; - - /* - * Try to avoid checking for flags, width or precision - */ - if (!ap_islower(*fmt)) { - /* - * Recognize flags: -, #, BLANK, + - */ - for (;; fmt++) { - if (*fmt == '-') - adjust = LEFT; - else if (*fmt == '+') - print_sign = YES; - else if (*fmt == '#') - alternate_form = YES; - else if (*fmt == ' ') - print_blank = YES; - else if (*fmt == '0') - pad_char = '0'; - else - break; - } + register char *sp; + register char *bep; + register int cc = 0; + register int i; + + register char *s = NULL; + char *q; + int s_len; + + register int min_width = 0; + int precision = 0; + enum { + LEFT, RIGHT + } adjust; + char pad_char; + char prefix_char; + + double fp_num; + wide_int i_num = (wide_int) 0; + u_wide_int ui_num; + + char num_buf[NUM_BUF_SIZE]; + char char_buf[2]; /* for printing %% and % */ - /* - * Check if a width was specified - */ - if (ap_isdigit(*fmt)) { - STR_TO_DEC(fmt, min_width); - adjust_width = YES; - } - else if (*fmt == '*') { - min_width = va_arg(ap, int); - fmt++; - adjust_width = YES; - if (min_width < 0) { - adjust = LEFT; - min_width = -min_width; - } - } - else - adjust_width = NO; + /* + * Flag variables + */ + boolean_e is_long; + boolean_e alternate_form; + boolean_e print_sign; + boolean_e print_blank; + boolean_e adjust_precision; + boolean_e adjust_width; + bool_int is_negative; + + sp = vbuff->curpos; + bep = vbuff->endpos; + + while (*fmt) { + if (*fmt != '%') { + INS_CHAR(*fmt, sp, bep, cc); + } else { + /* + * Default variable settings + */ + adjust = RIGHT; + alternate_form = print_sign = print_blank = NO; + pad_char = ' '; + prefix_char = NUL; - /* - * Check if a precision was specified - * - * XXX: an unreasonable amount of precision may be specified - * resulting in overflow of num_buf. Currently we - * ignore this possibility. - */ - if (*fmt == '.') { - adjust_precision = YES; - fmt++; - if (ap_isdigit(*fmt)) { - STR_TO_DEC(fmt, precision); - } - else if (*fmt == '*') { - precision = va_arg(ap, int); fmt++; - if (precision < 0) - precision = 0; - } - else - precision = 0; - } - else - adjust_precision = NO; - } - else - adjust_precision = adjust_width = NO; - - /* - * Modifier check - */ - if (*fmt == 'l') { - is_long = YES; - fmt++; - } - else { - if (*fmt == 'h') /* "short" backward compatibility */ - ++fmt; - is_long = NO; - } - - /* - * Argument extraction and printing. - * First we determine the argument type. - * Then, we convert the argument to a string. - * On exit from the switch, s points to the string that - * must be printed, s_len has the length of the string - * The precision requirements, if any, are reflected in s_len. - * - * NOTE: pad_char may be set to '0' because of the 0 flag. - * It is reset to ' ' by non-numeric formats - */ - switch (*fmt) { - case 'u': - if (is_long) - i_num = va_arg(ap, u_wide_int); - else - i_num = (wide_int) va_arg(ap, unsigned int); - s = conv_10(i_num, 1, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - break; - - case 'd': - case 'i': - if (is_long) - i_num = va_arg(ap, wide_int); - else - i_num = (wide_int) va_arg(ap, int); - s = conv_10(i_num, 0, &is_negative, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - break; - - - case 'o': - if (is_long) - ui_num = va_arg(ap, u_wide_int); - else - ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 3, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && *s != '0') { - *--s = '0'; - s_len++; - } - break; - - - case 'x': - case 'X': - if (is_long) - ui_num = (u_wide_int) va_arg(ap, u_wide_int); - else - ui_num = (u_wide_int) va_arg(ap, unsigned int); - s = conv_p2(ui_num, 4, *fmt, - &num_buf[NUM_BUF_SIZE], &s_len); - FIX_PRECISION(adjust_precision, precision, s, s_len); - if (alternate_form && i_num != 0) { - *--s = *fmt; /* 'x' or 'X' */ - *--s = '0'; - s_len += 2; - } - break; - - case 's': - s = va_arg(ap, char *); - if (s != NULL) { - s_len = strlen(s); - if (adjust_precision && precision < s_len) - s_len = precision; - } - else { - s = S_NULL; - s_len = S_NULL_LEN; - } - pad_char = ' '; - break; - - - case 'f': - case 'e': - case 'E': - fp_num = va_arg(ap, double); - /* - * * We use &num_buf[ 1 ], so that we have room for the sign - */ - s = conv_fp(*fmt, fp_num, alternate_form, - (adjust_precision == NO) ? FLOAT_DIGITS : precision, - &is_negative, &num_buf[1], &s_len); - if (is_negative) - prefix_char = '-'; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - break; - - - case 'g': - case 'G': - if (adjust_precision == NO) - precision = FLOAT_DIGITS; - else if (precision == 0) - precision = 1; - /* - * * We use &num_buf[ 1 ], so that we have room for the sign - */ - s = ap_gcvt(va_arg(ap, double), precision, &num_buf[1], - alternate_form); - if (*s == '-') - prefix_char = *s++; - else if (print_sign) - prefix_char = '+'; - else if (print_blank) - prefix_char = ' '; - - s_len = strlen(s); - - if (alternate_form && (q = strchr(s, '.')) == NULL) { - s[s_len++] = '.'; - s[s_len] = '\0'; /* delimit for following strchr() */ - } - if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) - *q = 'E'; - break; - - - case 'c': - char_buf[0] = (char) (va_arg(ap, int)); - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case '%': - char_buf[0] = '%'; - s = &char_buf[0]; - s_len = 1; - pad_char = ' '; - break; - - - case 'n': - *(va_arg(ap, int *)) = cc; - break; - - /* - * This is where we extend the printf format, with a second - * type specifier - */ - case 'p': - switch(*++fmt) { - /* - * If the pointer size is equal to the size of an unsigned - * integer we convert the pointer to a hex number, otherwise - * we print "%p" to indicate that we don't handle "%p". - */ - case 'p': - ui_num = (u_wide_int) va_arg(ap, void *); - - if (sizeof(char *) <= sizeof(u_wide_int)) - s = conv_p2(ui_num, 4, 'x', - &num_buf[NUM_BUF_SIZE], &s_len); - else { - s = "%p"; - s_len = 2; - prefix_char = NUL; - } - pad_char = ' '; - break; - - /* print a struct sockaddr_in as a.b.c.d:port */ - case 'I': - { - struct sockaddr_in *si; - - si = va_arg(ap, struct sockaddr_in *); - if (si != NULL) { - s = conv_sockaddr_in(si, &num_buf[NUM_BUF_SIZE], &s_len); - if (adjust_precision && precision < s_len) - s_len = precision; - } - else { - s = S_NULL; - s_len = S_NULL_LEN; + /* + * Try to avoid checking for flags, width or precision + */ + if (!ap_islower(*fmt)) { + /* + * Recognize flags: -, #, BLANK, + + */ + for (;; fmt++) { + if (*fmt == '-') + adjust = LEFT; + else if (*fmt == '+') + print_sign = YES; + else if (*fmt == '#') + alternate_form = YES; + else if (*fmt == ' ') + print_blank = YES; + else if (*fmt == '0') + pad_char = '0'; + else + break; + } + + /* + * Check if a width was specified + */ + if (ap_isdigit(*fmt)) { + STR_TO_DEC(fmt, min_width); + adjust_width = YES; + } else if (*fmt == '*') { + min_width = va_arg(ap, int); + fmt++; + adjust_width = YES; + if (min_width < 0) { + adjust = LEFT; + min_width = -min_width; + } + } else + adjust_width = NO; + + /* + * Check if a precision was specified + * + * XXX: an unreasonable amount of precision may be specified + * resulting in overflow of num_buf. Currently we + * ignore this possibility. + */ + if (*fmt == '.') { + adjust_precision = YES; + fmt++; + if (ap_isdigit(*fmt)) { + STR_TO_DEC(fmt, precision); + } else if (*fmt == '*') { + precision = va_arg(ap, int); + fmt++; + if (precision < 0) + precision = 0; + } else + precision = 0; + } else + adjust_precision = NO; + } else + adjust_precision = adjust_width = NO; + + /* + * Modifier check + */ + if (*fmt == 'l') { + is_long = YES; + fmt++; + } else { + if (*fmt == 'h') /* "short" backward compatibility */ + ++fmt; + is_long = NO; } - pad_char = ' '; - } - break; - - /* print a struct in_addr as a.b.c.d */ - case 'A': - { - struct in_addr *ia; - - ia = va_arg(ap, struct in_addr *); - if (ia != NULL) { - s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len); - if (adjust_precision && precision < s_len) - s_len = precision; + + /* + * Argument extraction and printing. + * First we determine the argument type. + * Then, we convert the argument to a string. + * On exit from the switch, s points to the string that + * must be printed, s_len has the length of the string + * The precision requirements, if any, are reflected in s_len. + * + * NOTE: pad_char may be set to '0' because of the 0 flag. + * It is reset to ' ' by non-numeric formats + */ + switch (*fmt) { + case 'u': + if (is_long) + i_num = va_arg(ap, u_wide_int); + else + i_num = (wide_int) va_arg(ap, unsigned int); + s = conv_10(i_num, 1, &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + break; + + case 'd': + case 'i': + if (is_long) + i_num = va_arg(ap, wide_int); + else + i_num = (wide_int) va_arg(ap, int); + s = conv_10(i_num, 0, &is_negative, + &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + break; + + + case 'o': + if (is_long) + ui_num = va_arg(ap, u_wide_int); + else + ui_num = (u_wide_int) va_arg(ap, unsigned int); + s = conv_p2(ui_num, 3, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + if (alternate_form && *s != '0') { + *--s = '0'; + s_len++; + } + break; + + + case 'x': + case 'X': + if (is_long) + ui_num = (u_wide_int) va_arg(ap, u_wide_int); + else + ui_num = (u_wide_int) va_arg(ap, unsigned int); + s = conv_p2(ui_num, 4, *fmt, + &num_buf[NUM_BUF_SIZE], &s_len); + FIX_PRECISION(adjust_precision, precision, s, s_len); + if (alternate_form && i_num != 0) { + *--s = *fmt; /* 'x' or 'X' */ + *--s = '0'; + s_len += 2; + } + break; + + + case 's': + s = va_arg(ap, char *); + if (s != NULL) { + s_len = strlen(s); + if (adjust_precision && precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + break; + + + case 'f': + case 'e': + case 'E': + fp_num = va_arg(ap, double); + /* + * * We use &num_buf[ 1 ], so that we have room for the sign + */ + s = conv_fp(*fmt, fp_num, alternate_form, + (adjust_precision == NO) ? FLOAT_DIGITS : precision, + &is_negative, &num_buf[1], &s_len); + if (is_negative) + prefix_char = '-'; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + break; + + + case 'g': + case 'G': + if (adjust_precision == NO) + precision = FLOAT_DIGITS; + else if (precision == 0) + precision = 1; + /* + * * We use &num_buf[ 1 ], so that we have room for the sign + */ + s = ap_gcvt(va_arg(ap, double), precision, &num_buf[1], + alternate_form); + if (*s == '-') + prefix_char = *s++; + else if (print_sign) + prefix_char = '+'; + else if (print_blank) + prefix_char = ' '; + + s_len = strlen(s); + + if (alternate_form && (q = strchr(s, '.')) == NULL) { + s[s_len++] = '.'; + s[s_len] = '\0'; /* delimit for following strchr() */ + } + if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL) + *q = 'E'; + break; + + + case 'c': + char_buf[0] = (char) (va_arg(ap, int)); + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case '%': + char_buf[0] = '%'; + s = &char_buf[0]; + s_len = 1; + pad_char = ' '; + break; + + + case 'n': + *(va_arg(ap, int *)) = cc; + break; + + /* + * This is where we extend the printf format, with a second + * type specifier + */ + case 'p': + switch(*++fmt) { + /* + * If the pointer size is equal to the size of an unsigned + * integer we convert the pointer to a hex number, otherwise + * we print "%p" to indicate that we don't handle "%p". + */ + case 'p': + ui_num = (u_wide_int) va_arg(ap, void *); + + if (sizeof(char *) <= sizeof(u_wide_int)) + s = conv_p2(ui_num, 4, 'x', + &num_buf[NUM_BUF_SIZE], &s_len); + else { + s = "%p"; + s_len = 2; + prefix_char = NUL; + } + pad_char = ' '; + break; + + /* print a struct sockaddr_in as a.b.c.d:port */ + case 'I': + { + struct sockaddr_in *si; + + si = va_arg(ap, struct sockaddr_in *); + if (si != NULL) { + s = conv_sockaddr_in(si, &num_buf[NUM_BUF_SIZE], &s_len); + if (adjust_precision && precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + } + break; + + /* print a struct in_addr as a.b.c.d */ + case 'A': + { + struct in_addr *ia; + + ia = va_arg(ap, struct in_addr *); + if (ia != NULL) { + s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len); + if (adjust_precision && precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + } + break; + + case NUL: + /* if %p ends the string, oh well ignore it */ + continue; + + default: + s = "bogus %p"; + s_len = 8; + prefix_char = NUL; + break; + } + break; + + case NUL: + /* + * The last character of the format string was %. + * We ignore it. + */ + continue; + + + /* + * The default case is for unrecognized %'s. + * We print % to help the user identify what + * option is not understood. + * This is also useful in case the user wants to pass + * the output of format_converter to another function + * that understands some other % (like syslog). + * Note that we can't point s inside fmt because the + * unknown could be preceded by width etc. + */ + default: + char_buf[0] = '%'; + char_buf[1] = *fmt; + s = char_buf; + s_len = 2; + pad_char = ' '; + break; } - else { - s = S_NULL; - s_len = S_NULL_LEN; + + if (prefix_char != NUL && s != S_NULL && s != char_buf) { + *--s = prefix_char; + s_len++; } - pad_char = ' '; - } - break; - - case NUL: - /* if %p ends the string, oh well ignore it */ - continue; - - default: - s = "bogus %p"; - s_len = 8; - prefix_char = NUL; - break; - } - break; - case NUL: - /* - * The last character of the format string was %. - * We ignore it. - */ - continue; + if (adjust_width && adjust == RIGHT && min_width > s_len) { + if (pad_char == '0' && prefix_char != NUL) { + INS_CHAR(*s, sp, bep, cc); + s++; + s_len--; + min_width--; + } + PAD(min_width, s_len, pad_char); + } + /* + * Print the string s. + */ + for (i = s_len; i != 0; i--) { + INS_CHAR(*s, sp, bep, cc); + s++; + } - /* - * The default case is for unrecognized %'s. - * We print % to help the user identify what - * option is not understood. - * This is also useful in case the user wants to pass - * the output of format_converter to another function - * that understands some other % (like syslog). - * Note that we can't point s inside fmt because the - * unknown could be preceded by width etc. - */ - default: - char_buf[0] = '%'; - char_buf[1] = *fmt; - s = char_buf; - s_len = 2; - pad_char = ' '; - break; - } - - if (prefix_char != NUL && s != S_NULL && s != char_buf) { - *--s = prefix_char; - s_len++; - } - - if (adjust_width && adjust == RIGHT && min_width > s_len) { - if (pad_char == '0' && prefix_char != NUL) { - INS_CHAR(*s, sp, bep, cc); - s++; - s_len--; - min_width--; + if (adjust_width && adjust == LEFT && min_width > s_len) + PAD(min_width, s_len, pad_char); } - PAD(min_width, s_len, pad_char); - } - - /* - * Print the string s. - */ - for (i = s_len; i != 0; i--) { - INS_CHAR(*s, sp, bep, cc); - s++; - } - - if (adjust_width && adjust == LEFT && min_width > s_len) - PAD(min_width, s_len, pad_char); + fmt++; } - fmt++; - } - vbuff->curpos = sp; - return cc; + vbuff->curpos = sp; + return cc; } static int snprintf_flush(ap_vformatter_buff *vbuff) { - /* if the buffer fills we have to abort immediately, there is no way - * to "flush" a snprintf... there's nowhere to flush it to. - */ - return -1; + /* if the buffer fills we have to abort immediately, there is no way + * to "flush" a snprintf... there's nowhere to flush it to. + */ + return -1; } int snprintf(char *buf, size_t len, const char *format,...) { - int cc; - va_list ap; - ap_vformatter_buff vbuff; - - if (len == 0) - return 0; - - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; - va_start(ap, format); - cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); - va_end(ap); - *vbuff.curpos = '\0'; - return (cc == -1) ? len : cc; + int cc; + va_list ap; + ap_vformatter_buff vbuff; + + if (len == 0) + return 0; + + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + va_start(ap, format); + cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); + va_end(ap); + *vbuff.curpos = '\0'; + return (cc == -1) ? len : cc; } int vsnprintf(char *buf, size_t len, const char *format, va_list ap) { - int cc; - ap_vformatter_buff vbuff; - - if (len == 0) - return 0; - - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; - cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); - *vbuff.curpos = '\0'; - return (cc == -1) ? len : cc; + int cc; + ap_vformatter_buff vbuff; + + if (len == 0) + return 0; + + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + cc = ap_vformatter(snprintf_flush, &vbuff, format, ap); + *vbuff.curpos = '\0'; + return (cc == -1) ? len : cc; } diff --git a/sbr/ssequal.c b/sbr/ssequal.c index 5ccf28f..e7a12ad 100644 --- a/sbr/ssequal.c +++ b/sbr/ssequal.c @@ -1,4 +1,3 @@ - /* * ssequal.c -- check if a string is a substring of another * @@ -25,13 +24,13 @@ int ssequal (char *s1, char *s2) { - if (!s1) - s1 = ""; - if (!s2) - s2 = ""; + if (!s1) + s1 = ""; + if (!s2) + s2 = ""; - while (*s1) - if (*s1++ != *s2++) - return 0; - return 1; + while (*s1) + if (*s1++ != *s2++) + return 0; + return 1; } diff --git a/sbr/strcasecmp.c b/sbr/strcasecmp.c index 04aad7d..c128f9b 100644 --- a/sbr/strcasecmp.c +++ b/sbr/strcasecmp.c @@ -1,4 +1,3 @@ - /* * strcasecmp.c -- compare strings, ignoring case * @@ -16,40 +15,40 @@ */ int -mh_strcasecmp (const char *s1, const char *s2) +mh_strcasecmp (const char *s1, const char *s2) { - const unsigned char *us1, *us2; - - us1 = (const unsigned char *) s1, - us2 = (const unsigned char *) s2; - - if (!us1) - us1 = ""; - if (!us2) - us2 = ""; - - while (tolower(*us1) == tolower(*us2++)) - if (*us1++ == '\0') - return (0); - return (tolower(*us1) - tolower(*--us2)); + const unsigned char *us1, *us2; + + us1 = (const unsigned char *) s1, + us2 = (const unsigned char *) s2; + + if (!us1) + us1 = ""; + if (!us2) + us2 = ""; + + while (tolower(*us1) == tolower(*us2++)) + if (*us1++ == '\0') + return (0); + return (tolower(*us1) - tolower(*--us2)); } - + int mh_strncasecmp (const char *s1, const char *s2, size_t n) { - const unsigned char *us1, *us2; - - if (n != 0) { - us1 = (const unsigned char *) s1, - us2 = (const unsigned char *) s2; - - do { - if (tolower(*us1) != tolower(*us2++)) - return (tolower(*us1) - tolower(*--us2)); - if (*us1++ == '\0') - break; - } while (--n != 0); - } - return (0); + const unsigned char *us1, *us2; + + if (n != 0) { + us1 = (const unsigned char *) s1, + us2 = (const unsigned char *) s2; + + do { + if (tolower(*us1) != tolower(*us2++)) + return (tolower(*us1) - tolower(*--us2)); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); } diff --git a/sbr/strdup.c b/sbr/strdup.c index 251145a..3e206c7 100644 --- a/sbr/strdup.c +++ b/sbr/strdup.c @@ -1,4 +1,3 @@ - /* * strdup.c -- duplicate a string * @@ -14,14 +13,14 @@ char * strdup (const char *str) { - char *cp; - size_t len; + char *cp; + size_t len; - if (!str) - return NULL; + if (!str) + return NULL; - len = strlen(str) + 1; - cp = mh_xmalloc (len); - memcpy (cp, str, len); - return cp; + len = strlen(str) + 1; + cp = mh_xmalloc (len); + memcpy (cp, str, len); + return cp; } diff --git a/sbr/strerror.c b/sbr/strerror.c index 476a574..af8d58f 100644 --- a/sbr/strerror.c +++ b/sbr/strerror.c @@ -1,4 +1,3 @@ - /* * strerror.c -- get error message string */ @@ -12,8 +11,8 @@ extern char *sys_errlist[]; char * strerror (int errnum) { - if (errnum > 0 && errnum < sys_nerr) - return sys_errlist[errnum]; - else - return NULL; + if (errnum > 0 && errnum < sys_nerr) + return sys_errlist[errnum]; + else + return NULL; } diff --git a/sbr/strindex.c b/sbr/strindex.c index 9a1e4fe..92245b2 100644 --- a/sbr/strindex.c +++ b/sbr/strindex.c @@ -1,4 +1,3 @@ - /* * strindex.c -- "unsigned" lexical index * @@ -12,14 +11,14 @@ int stringdex (char *p1, char *p2) { - char *p; + char *p; - if (p1 == NULL || p2 == NULL) - return -1; + if (p1 == NULL || p2 == NULL) + return -1; - for (p = p2; *p; p++) - if (uprf (p, p1)) - return (p - p2); + for (p = p2; *p; p++) + if (uprf (p, p1)) + return (p - p2); - return -1; + return -1; } diff --git a/sbr/trimcpy.c b/sbr/trimcpy.c index b640ea6..f24563c 100644 --- a/sbr/trimcpy.c +++ b/sbr/trimcpy.c @@ -1,4 +1,3 @@ - /* * trimcpy.c -- strip leading and trailing whitespace, * -- replace internal whitespace with spaces, @@ -15,26 +14,26 @@ char * trimcpy (unsigned char *cp) { - unsigned char *sp; - - /* skip over leading whitespace */ - while (isspace(*cp)) - cp++; - - /* start at the end and zap trailing whitespace */ - for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) { - if (isspace(*sp)) - *sp = '\0'; - else - break; - } - - /* replace remaining whitespace with spaces */ - for (sp = cp; *sp; sp++) { - if (isspace(*sp)) - *sp = ' '; - } - - /* now return a copy */ - return getcpy(cp); + unsigned char *sp; + + /* skip over leading whitespace */ + while (isspace(*cp)) + cp++; + + /* start at the end and zap trailing whitespace */ + for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) { + if (isspace(*sp)) + *sp = '\0'; + else + break; + } + + /* replace remaining whitespace with spaces */ + for (sp = cp; *sp; sp++) { + if (isspace(*sp)) + *sp = ' '; + } + + /* now return a copy */ + return getcpy(cp); } diff --git a/sbr/uprf.c b/sbr/uprf.c index b3c81ff..7964a82 100644 --- a/sbr/uprf.c +++ b/sbr/uprf.c @@ -1,4 +1,3 @@ - /* * uprf.c -- "unsigned" lexical prefix * @@ -16,26 +15,25 @@ int uprf (char *c1, char *c2) { - int c, mask; + int c, mask; - if (!(c1 && c2)) - return 0; + if (!(c1 && c2)) + return 0; - while ((c = *c2++)) - { + while ((c = *c2++)) { #ifdef LOCALE - c &= 0xff; - mask = *c1 & 0xff; - c = (isalpha(c) && isupper(c)) ? tolower(c) : c; - mask = (isalpha(mask) && isupper(mask)) ? tolower(mask) : mask; - if (c != mask) + c &= 0xff; + mask = *c1 & 0xff; + c = (isalpha(c) && isupper(c)) ? tolower(c) : c; + mask = (isalpha(mask) && isupper(mask)) ? tolower(mask) : mask; + if (c != mask) #else - mask = (isalpha(c) && isalpha(*c1)) ? TO_LOWER : NO_MASK; - if ((c | mask) != (*c1 | mask)) + mask = (isalpha(c) && isalpha(*c1)) ? TO_LOWER : NO_MASK; + if ((c | mask) != (*c1 | mask)) #endif - return 0; - else - c1++; - } - return 1; + return 0; + else + c1++; + } + return 1; } diff --git a/sbr/utils.c b/sbr/utils.c index 48969ab..7d0158a 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -1,4 +1,3 @@ - /* * utils.c -- various utility routines * @@ -25,16 +24,16 @@ void * mh_xmalloc(size_t size) { - void *memory; + void *memory; - if (size == 0) - adios(NULL, "Tried to malloc 0 bytes"); + if (size == 0) + adios(NULL, "Tried to malloc 0 bytes"); - memory = malloc(size); - if (!memory) - adios(NULL, "Malloc failed"); + memory = malloc(size); + if (!memory) + adios(NULL, "Malloc failed"); - return memory; + return memory; } /* @@ -43,20 +42,20 @@ mh_xmalloc(size_t size) void * mh_xrealloc(void *ptr, size_t size) { - void *memory; + void *memory; - /* Some non-POSIX realloc()s don't cope with realloc(NULL,sz) */ - if (!ptr) - return mh_xmalloc(size); + /* Some non-POSIX realloc()s don't cope with realloc(NULL,sz) */ + if (!ptr) + return mh_xmalloc(size); - if (size == 0) - adios(NULL, "Tried to realloc 0bytes"); + if (size == 0) + adios(NULL, "Tried to realloc 0bytes"); - memory = realloc(ptr, size); - if (!memory) - adios(NULL, "Realloc failed"); + memory = realloc(ptr, size); + if (!memory) + adios(NULL, "Realloc failed"); - return memory; + return memory; } /* @@ -66,23 +65,23 @@ mh_xrealloc(void *ptr, size_t size) char * pwd(void) { - register char *cp; - static char curwd[PATH_MAX]; - - if (!getcwd (curwd, PATH_MAX)) { - admonish (NULL, "unable to determine working directory"); - if (!mypath || !*mypath - || (strcpy (curwd, mypath), chdir (curwd)) == -1) { - strcpy (curwd, "/"); - chdir (curwd); - } - return curwd; - } - - if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/') - *cp = '\0'; - - return curwd; + register char *cp; + static char curwd[PATH_MAX]; + + if (!getcwd (curwd, PATH_MAX)) { + admonish (NULL, "unable to determine working directory"); + if (!mypath || !*mypath + || (strcpy (curwd, mypath), chdir (curwd)) == -1) { + strcpy (curwd, "/"); + chdir (curwd); + } + return curwd; + } + + if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/') + *cp = '\0'; + + return curwd; } /* @@ -96,106 +95,105 @@ pwd(void) char * add (char *s2, char *s1) { - char *cp; - size_t len1 = 0, len2 = 0; + char *cp; + size_t len1 = 0, len2 = 0; - if (s1) - len1 = strlen (s1); - if (s2) - len2 = strlen (s2); + if (s1) + len1 = strlen (s1); + if (s2) + len2 = strlen (s2); - cp = mh_xmalloc (len1 + len2 + 1); + cp = mh_xmalloc (len1 + len2 + 1); - /* Copy s1 and free it */ - if (s1) { - memcpy (cp, s1, len1); - free (s1); - } + /* Copy s1 and free it */ + if (s1) { + memcpy (cp, s1, len1); + free (s1); + } - /* Copy s2 */ - if (s2) - memcpy (cp + len1, s2, len2); + /* Copy s2 */ + if (s2) + memcpy (cp + len1, s2, len2); - /* Now NULL terminate the string */ - cp[len1 + len2] = '\0'; + /* Now NULL terminate the string */ + cp[len1 + len2] = '\0'; - return cp; + return cp; } /* * folder_exists - * Check to see if a folder exists. + * Check to see if a folder exists. */ int folder_exists(char *folder) { - struct stat st; - int exists = 0; - - if (stat (folder, &st) == -1) { - /* The folder either doesn't exist, or we hit an error. Either way - * return a failure. - */ - exists = 0; - } else { - /* We can see a folder with the right name */ - exists = 1; - } - - return exists; + struct stat st; + int exists = 0; + + if (stat (folder, &st) == -1) { + /* The folder either doesn't exist, or we hit an error. + * Either way return a failure. + */ + exists = 0; + } else { + /* We can see a folder with the right name */ + exists = 1; + } + + return exists; } /* * create_folder - * Check to see if a folder exists, if not, prompt the user to create - * it. + * Check to see if a folder exists, if not, prompt the user to create it. */ void create_folder(char *folder, int autocreate, void (*done_callback)(int)) { - struct stat st; - extern int errno; - char *cp; - - if (stat (folder, &st) == -1) { - if (errno != ENOENT) - adios (folder, "error on folder"); - if (autocreate == 0) { - /* ask before creating folder */ - cp = concat ("Create folder \"", folder, "\"? ", NULL); - if (!getanswer (cp)) - done_callback (1); - free (cp); - } else if (autocreate == -1) { - /* do not create, so exit */ - done_callback (1); - } - if (!makedir (folder)) - adios (NULL, "unable to create folder %s", folder); - } + struct stat st; + extern int errno; + char *cp; + + if (stat (folder, &st) == -1) { + if (errno != ENOENT) + adios (folder, "error on folder"); + if (autocreate == 0) { + /* ask before creating folder */ + cp = concat ("Create folder \"", folder, "\"? ", NULL); + if (!getanswer (cp)) + done_callback (1); + free (cp); + } else if (autocreate == -1) { + /* do not create, so exit */ + done_callback (1); + } + if (!makedir (folder)) + adios (NULL, "unable to create folder %s", folder); + } } /* * num_digits - * Return the number of digits in a nonnegative integer. + * Return the number of digits in a nonnegative integer. */ int num_digits (int n) { - int ndigits = 0; + int ndigits = 0; - /* Sanity check */ - if (n < 0) - adios (NULL, "oops, num_digits called with negative value"); + /* Sanity check */ + if (n < 0) + adios (NULL, "oops, num_digits called with negative value"); - if (n == 0) - return 1; + if (n == 0) + return 1; - while (n) { - n /= 10; - ndigits++; - } + while (n) { + n /= 10; + ndigits++; + } - return ndigits; + return ndigits; } /* diff --git a/sbr/vfgets.c b/sbr/vfgets.c index 3a376e1..1a99b76 100644 --- a/sbr/vfgets.c +++ b/sbr/vfgets.c @@ -1,4 +1,3 @@ - /* * vfgets.c -- virtual fgets * @@ -10,63 +9,63 @@ #include #include -#define QUOTE '\\' +#define QUOTE '\\' int vfgets (FILE *in, char **bp) { - int toggle; - char *cp, *dp, *ep, *fp; - static int len = 0; - static char *pp = NULL; + int toggle; + char *cp, *dp, *ep, *fp; + static int len = 0; + static char *pp = NULL; - if (pp == NULL) - pp = mh_xmalloc ((size_t) (len = BUFSIZ)); + if (pp == NULL) + pp = mh_xmalloc ((size_t) (len = BUFSIZ)); - for (ep = (cp = pp) + len - 1;;) { - if (fgets (cp, ep - cp + 1, in) == NULL) { - if (cp != pp) { - *bp = pp; - return 0; - } - return (ferror (in) && !feof (in) ? -1 : 1); - } + for (ep = (cp = pp) + len - 1;;) { + if (fgets (cp, ep - cp + 1, in) == NULL) { + if (cp != pp) { + *bp = pp; + return 0; + } + return (ferror (in) && !feof (in) ? -1 : 1); + } - if ((dp = cp + strlen (cp) - 2) < cp || *dp != QUOTE) { + if ((dp = cp + strlen (cp) - 2) < cp || *dp != QUOTE) { wrong_guess: - if (cp > ++dp) - adios (NULL, "vfgets() botch -- you lose big"); - if (*dp == '\n') { - *bp = pp; - return 0; - } else { - cp = ++dp; - } - } else { - for (fp = dp - 1, toggle = 0; fp >= cp; fp--) { - if (*fp != QUOTE) - break; - else - toggle = !toggle; - } - if (toggle) - goto wrong_guess; + if (cp > ++dp) + adios (NULL, "vfgets() botch -- you lose big"); + if (*dp == '\n') { + *bp = pp; + return 0; + } else { + cp = ++dp; + } + } else { + for (fp = dp - 1, toggle = 0; fp >= cp; fp--) { + if (*fp != QUOTE) + break; + else + toggle = !toggle; + } + if (toggle) + goto wrong_guess; - if (*++dp == '\n') { - *--dp = 0; - cp = dp; - } else { - cp = ++dp; - } - } + if (*++dp == '\n') { + *--dp = 0; + cp = dp; + } else { + cp = ++dp; + } + } - if (cp >= ep) { - int curlen = cp - pp; + if (cp >= ep) { + int curlen = cp - pp; - dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ)); - cp = dp + curlen; - ep = (pp = dp) + len - 1; + dp = mh_xrealloc (pp, (size_t) (len += BUFSIZ)); + cp = dp + curlen; + ep = (pp = dp) + len - 1; + } } - } } diff --git a/uip/Makefile.in b/uip/Makefile.in index 9118045..d600813 100644 --- a/uip/Makefile.in +++ b/uip/Makefile.in @@ -21,13 +21,13 @@ INCLUDES = -I.. -I$(srcdir) -I$(top_srcdir) @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ -MTSLIB = +MTSLIB = # ../mts/libmts.a NDBM_LIBS = @NDBM_LIBS@ LOCALLIBS = ../config/version.o ../config/config.o $(MTSLIB) ../sbr/libmh.a LINKLIBS = $(LOCALLIBS) $(LIBS) -LINT = @LINT@ +LINT = @LINT@ LINTFLAGS = @LINTFLAGS@ TERMLIB = @TERMLIB@ @@ -66,18 +66,17 @@ MISC = ap conflict dp fmtdump mhl rcvdist rcvpack \ SCMDS = inc # source files -SRCS = ali.c aliasbr.c anno.c annosbr.c ap.c burst.c comp.c \ - conflict.c dist.c distsbr.c dp.c dropsbr.c flist.c fmtdump.c \ +SRCS = ali.c aliasbr.c anno.c annosbr.c ap.c burst.c comp.c \ + conflict.c dist.c distsbr.c dp.c dropsbr.c flist.c fmtdump.c \ folder.c forw.c ftpsbr.c inc.c install-mh.c mark.c md5.c mhbuild.c \ - mhbuildsbr.c mhcachesbr.c mhfree.c mhl.c mhlist.c mhlistsbr.c \ - mhlsbr.c mhmail.c mhmisc.c mhoutsbr.c mhparam.c mhparse.c \ - mhpath.c mhshow.c mhshowsbr.c mhstore.c mhstoresbr.c mhtest.c \ + mhbuildsbr.c mhcachesbr.c mhfree.c mhl.c mhlist.c mhlistsbr.c \ + mhlsbr.c mhmail.c mhmisc.c mhoutsbr.c mhparam.c mhparse.c \ + mhpath.c mhshow.c mhshowsbr.c mhstore.c mhstoresbr.c mhtest.c \ msgchk.c new.c packf.c pick.c picksbr.c \ - prompter.c rcvdist.c rcvpack.c rcvstore.c rcvtty.c \ - refile.c repl.c replsbr.c rmf.c rmm.c scan.c scansbr.c send.c \ - sendsbr.c show.c slocal.c sortm.c spost.c termsbr.c viamail.c \ - whatnow.c whatnowproc.c whatnowsbr.c \ - whom.c + prompter.c rcvdist.c rcvpack.c rcvstore.c rcvtty.c \ + refile.c repl.c replsbr.c rmf.c rmm.c scan.c scansbr.c send.c \ + sendsbr.c show.c slocal.c sortm.c spost.c termsbr.c viamail.c \ + whatnow.c whatnowproc.c whatnowsbr.c whom.c # auxiliary files AUX = Makefile.in @@ -305,7 +304,7 @@ superclean: realclean # ========== DEPENDENCIES FOR LINT ================ -lint: +lint: $(LINT) $(LINTFLAGS) $(INCLUDES) $(DEFS) $(SRCS) # ========== DEPENDENCIES FOR MAINTENANCE ========== diff --git a/uip/ali.c b/uip/ali.c index 41f92a6..00af8ce 100644 --- a/uip/ali.c +++ b/uip/ali.c @@ -1,4 +1,3 @@ - /* * ali.c -- list nmh mail aliases * @@ -16,30 +15,30 @@ /* * maximum number of names */ -#define NVEC 50 +#define NVEC 50 static struct swit switches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define NALIASW 1 - { "noalias", -7 }, -#define LISTSW 2 - { "list", 0 }, -#define NLISTSW 3 - { "nolist", 0 }, -#define NORMSW 4 - { "normalize", 0 }, -#define NNORMSW 5 - { "nonormalize", 0 }, -#define USERSW 6 - { "user", 0 }, -#define NUSERSW 7 - { "nouser", 0 }, -#define VERSIONSW 8 - { "version", 0 }, -#define HELPSW 9 - { "help", 0 }, - { NULL, 0 } +#define ALIASW 0 + { "alias aliasfile", 0 }, +#define NALIASW 1 + { "noalias", -7 }, +#define LISTSW 2 + { "list", 0 }, +#define NLISTSW 3 + { "nolist", 0 }, +#define NORMSW 4 + { "normalize", 0 }, +#define NNORMSW 5 + { "nonormalize", 0 }, +#define USERSW 6 + { "user", 0 }, +#define NUSERSW 7 + { "nouser", 0 }, +#define VERSIONSW 8 + { "version", 0 }, +#define HELPSW 9 + { "help", 0 }, + { NULL, 0 } }; static int pos = 1; @@ -56,203 +55,203 @@ static void print_usr (char *, int, int); int main (int argc, char **argv) { - int i, vecp = 0, inverted = 0, list = 0; - int noalias = 0, normalize = AD_NHST; - char *cp, **ap, **argp, buf[BUFSIZ]; - char *vec[NVEC], **arguments; - struct aka *ak; + int i, vecp = 0, inverted = 0, list = 0; + int noalias = 0, normalize = AD_NHST; + char *cp, **ap, **argp, buf[BUFSIZ]; + char *vec[NVEC], **arguments; + struct aka *ak; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] aliases ...", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version (invo_name); - done (1); - - case ALIASW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((i = alias (cp)) != AK_OK) - adios (NULL, "aliasing error in %s - %s", cp, akerror (i)); - continue; - case NALIASW: - noalias++; - continue; - - case LISTSW: - list++; - continue; - case NLISTSW: - list = 0; - continue; - - case NORMSW: - normalize = AD_HOST; - continue; - case NNORMSW: - normalize = AD_NHST; - continue; - - case USERSW: - inverted++; - continue; - case NUSERSW: - inverted = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] aliases ...", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version (invo_name); + done (1); + + case ALIASW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((i = alias (cp)) != AK_OK) + adios (NULL, "aliasing error in %s - %s", cp, akerror (i)); + continue; + case NALIASW: + noalias++; + continue; + + case LISTSW: + list++; + continue; + case NLISTSW: + list = 0; + continue; + + case NORMSW: + normalize = AD_HOST; + continue; + case NNORMSW: + normalize = AD_NHST; + continue; + + case USERSW: + inverted++; + continue; + case NUSERSW: + inverted = 0; + continue; + } + } + vec[vecp++] = cp; } - vec[vecp++] = cp; - } - - if (!noalias) { - /* allow Aliasfile: profile entry */ - if ((cp = context_find ("Aliasfile"))) { - char *dp = NULL; - - for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) - if ((i = alias (*ap)) != AK_OK) - adios (NULL, "aliasing error in %s - %s", *ap, akerror (i)); - if (dp) - free(dp); + + if (!noalias) { + /* allow Aliasfile: profile entry */ + if ((cp = context_find ("Aliasfile"))) { + char *dp = NULL; + + for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) + if ((i = alias (*ap)) != AK_OK) + adios (NULL, "aliasing error in %s - %s", *ap, akerror (i)); + if (dp) + free(dp); + } + alias (AliasFile); } - alias (AliasFile); - } - /* - * If -user is specified - */ - if (inverted) { - if (vecp == 0) - adios (NULL, "usage: %s -user addresses ... (you forgot the addresses)", - invo_name); + /* + * If -user is specified + */ + if (inverted) { + if (vecp == 0) + adios (NULL, "usage: %s -user addresses ... (you forgot the addresses)", + invo_name); - for (i = 0; i < vecp; i++) - print_usr (vec[i], list, normalize); + for (i = 0; i < vecp; i++) + print_usr (vec[i], list, normalize); - done (0); - } - - if (vecp) { - /* print specified aliases */ - for (i = 0; i < vecp; i++) - print_aka (akvalue (vec[i]), list, 0); - } else { - /* print them all */ - for (ak = akahead; ak; ak = ak->ak_next) { - printf ("%s: ", ak->ak_name); - pos += strlen (ak->ak_name) + 1; - print_aka (akresult (ak), list, pos); + done (0); + } + + if (vecp) { + /* print specified aliases */ + for (i = 0; i < vecp; i++) + print_aka (akvalue (vec[i]), list, 0); + } else { + /* print them all */ + for (ak = akahead; ak; ak = ak->ak_next) { + printf ("%s: ", ak->ak_name); + pos += strlen (ak->ak_name) + 1; + print_aka (akresult (ak), list, pos); + } } - } - done (0); - return 1; + done (0); + return 1; } static void print_aka (char *p, int list, int margin) { - char c; - - if (p == NULL) { - printf ("\n"); - return; - } - - while ((c = *p++)) { - switch (c) { - case ',': - if (*p) { - if (list) - printf ("\n%*s", margin, ""); - else { - if (pos >= 68) { - printf (",\n "); - pos = 2; - } else { - printf (", "); - pos += 2; - } - } - } + char c; - case 0: - break; + if (p == NULL) { + printf ("\n"); + return; + } - default: - pos++; - putchar (c); + while ((c = *p++)) { + switch (c) { + case ',': + if (*p) { + if (list) + printf ("\n%*s", margin, ""); + else { + if (pos >= 68) { + printf (",\n "); + pos = 2; + } else { + printf (", "); + pos += 2; + } + } + } + + case 0: + break; + + default: + pos++; + putchar (c); + } } - } - putchar ('\n'); - pos = 1; + putchar ('\n'); + pos = 1; } static void print_usr (char *s, int list, int norm) { - register char *cp, *pp, *vp; - register struct aka *ak; - register struct mailname *mp, *np; - - if ((pp = getname (s)) == NULL) - adios (NULL, "no address in \"%s\"", s); - if ((mp = getm (pp, NULL, 0, norm, NULL)) == NULL) - adios (NULL, "bad address \"%s\"", s); - while (getname ("")) - continue; - - vp = NULL; - for (ak = akahead; ak; ak = ak->ak_next) { - pp = akresult (ak); - while ((cp = getname (pp))) { - if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL) + register char *cp, *pp, *vp; + register struct aka *ak; + register struct mailname *mp, *np; + + if ((pp = getname (s)) == NULL) + adios (NULL, "no address in \"%s\"", s); + if ((mp = getm (pp, NULL, 0, norm, NULL)) == NULL) + adios (NULL, "bad address \"%s\"", s); + while (getname ("")) continue; - if (!mh_strcasecmp (mp->m_host, np->m_host) - && !mh_strcasecmp (mp->m_mbox, np->m_mbox)) { - vp = vp ? add (ak->ak_name, add (",", vp)) - : getcpy (ak->ak_name); - mnfree (np); - while (getname ("")) - continue; - break; - } - mnfree (np); + + vp = NULL; + for (ak = akahead; ak; ak = ak->ak_next) { + pp = akresult (ak); + while ((cp = getname (pp))) { + if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL) + continue; + if (!mh_strcasecmp (mp->m_host, np->m_host) + && !mh_strcasecmp (mp->m_mbox, np->m_mbox)) { + vp = vp ? add (ak->ak_name, add (",", vp)) + : getcpy (ak->ak_name); + mnfree (np); + while (getname ("")) + continue; + break; + } + mnfree (np); + } } - } - mnfree (mp); + mnfree (mp); #if 0 - printf ("%s: ", s); - print_aka (vp ? vp : s, list, pos += strlen (s) + 1); + printf ("%s: ", s); + print_aka (vp ? vp : s, list, pos += strlen (s) + 1); #else - print_aka (vp ? vp : s, list, 0); + print_aka (vp ? vp : s, list, 0); #endif - if (vp) - free (vp); + if (vp) + free (vp); } diff --git a/uip/aliasbr.c b/uip/aliasbr.c index b1a7e61..752cda7 100644 --- a/uip/aliasbr.c +++ b/uip/aliasbr.c @@ -1,4 +1,3 @@ - /* * aliasbr.c -- new aliasing mechanism * @@ -25,7 +24,7 @@ struct home *hometail = NULL; /* * prototypes */ -int alias (char *); +int alias (char *); int akvisible (void); void init_pw (void); char *akresult (struct aka *); @@ -52,462 +51,461 @@ struct home *seek_home (char *); char * akvalue (char *s) { - register char *v; + register char *v; - if (akahead == NULL) - alias (AliasFile); + if (akahead == NULL) + alias (AliasFile); - akvis = -1; - v = akval (akahead, s); - if (akvis == -1) - akvis = 0; - return v; + akvis = -1; + v = akval (akahead, s); + if (akvis == -1) + akvis = 0; + return v; } int akvisible (void) { - return akvis; + return akvis; } char * akresult (struct aka *ak) { - register char *cp = NULL, *dp, *pp; - register struct adr *ad; - - for (ad = ak->ak_addr; ad; ad = ad->ad_next) { - pp = ad->ad_local ? akval (ak->ak_next, ad->ad_text) - : getcpy (ad->ad_text); - - if (cp) { - dp = cp; - cp = concat (cp, ",", pp, NULL); - free (dp); - free (pp); + register char *cp = NULL, *dp, *pp; + register struct adr *ad; + + for (ad = ak->ak_addr; ad; ad = ad->ad_next) { + pp = ad->ad_local ? akval (ak->ak_next, ad->ad_text) + : getcpy (ad->ad_text); + + if (cp) { + dp = cp; + cp = concat (cp, ",", pp, NULL); + free (dp); + free (pp); + } else + cp = pp; } - else - cp = pp; - } - if (akvis == -1) - akvis = ak->ak_visible; - return cp; + if (akvis == -1) + akvis = ak->ak_visible; + return cp; } -static char * +static char * akval (struct aka *ak, char *s) { - if (!s) - return s; /* XXX */ + if (!s) + return s; /* XXX */ - for (; ak; ak = ak->ak_next) - if (aleq (s, ak->ak_name)) - return akresult (ak); + for (; ak; ak = ak->ak_next) + if (aleq (s, ak->ak_name)) + return akresult (ak); - return getcpy (s); + return getcpy (s); } static int aleq (char *string, char *aliasent) { - register char c; - - while ((c = *string++)) - if (*aliasent == '*') - return 1; - else - if ((c | 040) != (*aliasent | 040)) - return 0; - else - aliasent++; - - return (*aliasent == 0 || *aliasent == '*'); + register char c; + + while ((c = *string++)) + if (*aliasent == '*') + return 1; + else + if ((c | 040) != (*aliasent | 040)) + return 0; + else + aliasent++; + + return (*aliasent == 0 || *aliasent == '*'); } int alias (char *file) { - int i; - register char *bp, *cp, *pp; - char lc, *ap; - register struct aka *ak = NULL; - register FILE *fp; - - if (*file != '/' - && (strncmp (file, "./", 2) && strncmp (file, "../", 3))) - file = etcpath (file); - if ((fp = fopen (file, "r")) == NULL) { - akerrst = file; - return AK_NOFILE; - } - - while (vfgets (fp, &ap) == OK) { - bp = ap; - switch (*(pp = scanp (bp))) { - case '<': /* recurse a level */ - if (!*(cp = getp (pp + 1))) { - akerrst = "'<' without alias-file"; - fclose (fp); - return AK_ERROR; - } - if ((i = alias (cp)) != AK_OK) { - fclose (fp); - return i; - } - - case ':': /* comment */ - case ';': - case '#': - case 0: - continue; - } - - akerrst = bp; - if (!*(cp = seekp (pp, &lc, &ap))) { - fclose (fp); - return AK_ERROR; - } - if (!(ak = akalloc (cp))) { - fclose (fp); - return AK_LIMIT; - } - switch (lc) { - case ':': - ak->ak_visible = 0; - break; - - case ';': - ak->ak_visible = 1; - break; - - default: - fclose (fp); - return AK_ERROR; + int i; + register char *bp, *cp, *pp; + char lc, *ap; + register struct aka *ak = NULL; + register FILE *fp; + + if (*file != '/' + && (strncmp (file, "./", 2) && strncmp (file, "../", 3))) + file = etcpath (file); + if ((fp = fopen (file, "r")) == NULL) { + akerrst = file; + return AK_NOFILE; } - switch (*(pp = scanp (ap))) { - case 0: /* EOL */ - fclose (fp); - return AK_ERROR; - - case '<': /* read values from file */ - if (!*(cp = getp (pp + 1))) { - fclose (fp); - return AK_ERROR; - } - if (!addfile (ak, cp)) { - fclose (fp); - return AK_NOFILE; + while (vfgets (fp, &ap) == OK) { + bp = ap; + switch (*(pp = scanp (bp))) { + case '<': /* recurse a level */ + if (!*(cp = getp (pp + 1))) { + akerrst = "'<' without alias-file"; + fclose (fp); + return AK_ERROR; + } + if ((i = alias (cp)) != AK_OK) { + fclose (fp); + return i; + } + + case ':': /* comment */ + case ';': + case '#': + case 0: + continue; } - break; - case '=': /* UNIX group */ - if (!*(cp = getp (pp + 1))) { - fclose (fp); - return AK_ERROR; + akerrst = bp; + if (!*(cp = seekp (pp, &lc, &ap))) { + fclose (fp); + return AK_ERROR; } - if (!addgroup (ak, cp)) { - fclose (fp); - return AK_NOGROUP; + if (!(ak = akalloc (cp))) { + fclose (fp); + return AK_LIMIT; } - break; - - case '+': /* UNIX group members */ - if (!*(cp = getp (pp + 1))) { - fclose (fp); - return AK_ERROR; - } - if (!addmember (ak, cp)) { - fclose (fp); - return AK_NOGROUP; + switch (lc) { + case ':': + ak->ak_visible = 0; + break; + + case ';': + ak->ak_visible = 1; + break; + + default: + fclose (fp); + return AK_ERROR; } - break; - - case '*': /* Everyone */ - addall (ak); - break; - default: /* list */ - while ((cp = getalias (pp))) - add_aka (ak, cp); - break; + switch (*(pp = scanp (ap))) { + case 0: /* EOL */ + fclose (fp); + return AK_ERROR; + + case '<': /* read values from file */ + if (!*(cp = getp (pp + 1))) { + fclose (fp); + return AK_ERROR; + } + if (!addfile (ak, cp)) { + fclose (fp); + return AK_NOFILE; + } + break; + + case '=': /* UNIX group */ + if (!*(cp = getp (pp + 1))) { + fclose (fp); + return AK_ERROR; + } + if (!addgroup (ak, cp)) { + fclose (fp); + return AK_NOGROUP; + } + break; + + case '+': /* UNIX group members */ + if (!*(cp = getp (pp + 1))) { + fclose (fp); + return AK_ERROR; + } + if (!addmember (ak, cp)) { + fclose (fp); + return AK_NOGROUP; + } + break; + + case '*': /* Everyone */ + addall (ak); + break; + + default: /* list */ + while ((cp = getalias (pp))) + add_aka (ak, cp); + break; + } } - } - fclose (fp); - return AK_OK; + fclose (fp); + return AK_OK; } char * akerror (int i) { - static char buffer[BUFSIZ]; + static char buffer[BUFSIZ]; - switch (i) { - case AK_NOFILE: - snprintf (buffer, sizeof(buffer), "unable to read '%s'", akerrst); - break; + switch (i) { + case AK_NOFILE: + snprintf (buffer, sizeof(buffer), "unable to read '%s'", akerrst); + break; - case AK_ERROR: - snprintf (buffer, sizeof(buffer), "error in line '%s'", akerrst); - break; + case AK_ERROR: + snprintf (buffer, sizeof(buffer), "error in line '%s'", akerrst); + break; - case AK_LIMIT: - snprintf (buffer, sizeof(buffer), "out of memory while on '%s'", akerrst); - break; + case AK_LIMIT: + snprintf (buffer, sizeof(buffer), "out of memory while on '%s'", akerrst); + break; - case AK_NOGROUP: - snprintf (buffer, sizeof(buffer), "no such group as '%s'", akerrst); - break; + case AK_NOGROUP: + snprintf (buffer, sizeof(buffer), "no such group as '%s'", akerrst); + break; - default: - snprintf (buffer, sizeof(buffer), "unknown error (%d)", i); - break; - } + default: + snprintf (buffer, sizeof(buffer), "unknown error (%d)", i); + break; + } - return buffer; + return buffer; } static char * scanp (unsigned char *p) { - while (isspace (*p)) - p++; - return p; + while (isspace (*p)) + p++; + return p; } static char * getp (char *p) { - register unsigned char *cp = scanp (p); + register unsigned char *cp = scanp (p); - p = cp; - while (!isspace (*cp) && *cp) - cp++; - *cp = 0; + p = cp; + while (!isspace (*cp) && *cp) + cp++; + *cp = 0; - return p; + return p; } static char * seekp (char *p, char *c, char **a) { - register unsigned char *cp; + register unsigned char *cp; - p = cp = scanp (p); - while (!isspace (*cp) && *cp && *cp != ':' && *cp != ';') - cp++; - *c = *cp; - *cp++ = 0; - *a = cp; + p = cp = scanp (p); + while (!isspace (*cp) && *cp && *cp != ':' && *cp != ';') + cp++; + *c = *cp; + *cp++ = 0; + *a = cp; - return p; + return p; } static int addfile (struct aka *ak, char *file) { - register char *cp; - char buffer[BUFSIZ]; - register FILE *fp; + register char *cp; + char buffer[BUFSIZ]; + register FILE *fp; - if (!(fp = fopen (etcpath (file), "r"))) { - akerrst = file; - return 0; - } + if (!(fp = fopen (etcpath (file), "r"))) { + akerrst = file; + return 0; + } - while (fgets (buffer, sizeof buffer, fp)) - while ((cp = getalias (buffer))) - add_aka (ak, cp); + while (fgets (buffer, sizeof buffer, fp)) + while ((cp = getalias (buffer))) + add_aka (ak, cp); - fclose (fp); - return 1; + fclose (fp); + return 1; } static int addgroup (struct aka *ak, char *grp) { - register char *gp; - register struct group *gr = getgrnam (grp); - register struct home *hm = NULL; - - if (!gr) - gr = getgrgid (atoi (grp)); - if (!gr) { - akerrst = grp; - return 0; - } + register char *gp; + register struct group *gr = getgrnam (grp); + register struct home *hm = NULL; + + if (!gr) + gr = getgrgid (atoi (grp)); + if (!gr) { + akerrst = grp; + return 0; + } #ifndef DBMPWD - if (homehead == NULL) - init_pw (); + if (homehead == NULL) + init_pw (); #endif /* DBMPWD */ - while ((gp = *gr->gr_mem++)) + while ((gp = *gr->gr_mem++)) #ifdef DBMPWD - { - struct passwd *pw; + { + struct passwd *pw; #endif /* DBMPWD */ - for (hm = homehead; hm; hm = hm->h_next) - if (!strcmp (hm->h_name, gp)) { - add_aka (ak, hm->h_name); - break; - } + for (hm = homehead; hm; hm = hm->h_next) + if (!strcmp (hm->h_name, gp)) { + add_aka (ak, hm->h_name); + break; + } #ifdef DBMPWD - if ((pw = getpwnam(gp))) - { - hmalloc(pw); - add_aka (ak, gp); + if ((pw = getpwnam(gp))) + { + hmalloc(pw); + add_aka (ak, gp); + } } - } #endif /* DBMPWD */ - return 1; + return 1; } static int addmember (struct aka *ak, char *grp) { - gid_t gid; - register struct group *gr = getgrnam (grp); - register struct home *hm = NULL; - - if (gr) - gid = gr->gr_gid; - else { - gid = atoi (grp); - gr = getgrgid (gid); - } - if (!gr) { - akerrst = grp; - return 0; - } + gid_t gid; + register struct group *gr = getgrnam (grp); + register struct home *hm = NULL; + + if (gr) + gid = gr->gr_gid; + else { + gid = atoi (grp); + gr = getgrgid (gid); + } + if (!gr) { + akerrst = grp; + return 0; + } #ifndef DBMPWD - if (homehead == NULL) + if (homehead == NULL) #endif /* DBMPWD */ - init_pw (); + init_pw (); - for (hm = homehead; hm; hm = hm->h_next) - if (hm->h_gid == gid) - add_aka (ak, hm->h_name); + for (hm = homehead; hm; hm = hm->h_next) + if (hm->h_gid == gid) + add_aka (ak, hm->h_name); - return 1; + return 1; } static int addall (struct aka *ak) { - int noshell = NoShell == NULL || *NoShell == 0; - register struct home *hm; + int noshell = NoShell == NULL || *NoShell == 0; + register struct home *hm; #ifndef DBMPWD - if (homehead == NULL) + if (homehead == NULL) #endif /* DBMPWD */ - init_pw (); - if (Everyone < 0) - Everyone = EVERYONE; + init_pw (); + if (Everyone < 0) + Everyone = EVERYONE; - for (hm = homehead; hm; hm = hm->h_next) - if (hm->h_uid > Everyone - && (noshell || strcmp (hm->h_shell, NoShell))) - add_aka (ak, hm->h_name); + for (hm = homehead; hm; hm = hm->h_next) + if (hm->h_uid > Everyone + && (noshell || strcmp (hm->h_shell, NoShell))) + add_aka (ak, hm->h_name); - return homehead != NULL; + return homehead != NULL; } static char * getalias (char *addrs) { - register unsigned char *pp, *qp; - static char *cp = NULL; - - if (cp == NULL) - cp = addrs; - else - if (*cp == 0) - return (cp = NULL); - - for (pp = cp; isspace (*pp); pp++) - continue; - if (*pp == 0) - return (cp = NULL); - for (qp = pp; *qp != 0 && *qp != ','; qp++) - continue; - if (*qp == ',') - *qp++ = 0; - for (cp = qp, qp--; qp > pp; qp--) - if (*qp != 0) { - if (isspace (*qp)) - *qp = 0; - else - break; - } + register unsigned char *pp, *qp; + static char *cp = NULL; + + if (cp == NULL) + cp = addrs; + else + if (*cp == 0) + return (cp = NULL); - return pp; + for (pp = cp; isspace (*pp); pp++) + continue; + if (*pp == 0) + return (cp = NULL); + for (qp = pp; *qp != 0 && *qp != ','; qp++) + continue; + if (*qp == ',') + *qp++ = 0; + for (cp = qp, qp--; qp > pp; qp--) + if (*qp != 0) { + if (isspace (*qp)) + *qp = 0; + else + break; + } + + return pp; } static void add_aka (struct aka *ak, char *pp) { - register struct adr *ad, *ld; - - for (ad = ak->ak_addr, ld = NULL; ad; ld = ad, ad = ad->ad_next) - if (!strcmp (pp, ad->ad_text)) - return; - - ad = (struct adr *) mh_xmalloc (sizeof(*ad)); - ad->ad_text = getcpy (pp); - ad->ad_local = strchr(pp, '@') == NULL && strchr(pp, '!') == NULL; - ad->ad_next = NULL; - if (ak->ak_addr) - ld->ad_next = ad; - else - ak->ak_addr = ad; + register struct adr *ad, *ld; + + for (ad = ak->ak_addr, ld = NULL; ad; ld = ad, ad = ad->ad_next) + if (!strcmp (pp, ad->ad_text)) + return; + + ad = (struct adr *) mh_xmalloc (sizeof(*ad)); + ad->ad_text = getcpy (pp); + ad->ad_local = strchr(pp, '@') == NULL && strchr(pp, '!') == NULL; + ad->ad_next = NULL; + if (ak->ak_addr) + ld->ad_next = ad; + else + ak->ak_addr = ad; } void init_pw (void) { - register struct passwd *pw; + register struct passwd *pw; #ifdef DBMPWD - static int init; - - if (!init) - { - /* if the list has yet to be initialized */ - /* zap the list, and rebuild from scratch */ - homehead=NULL; - hometail=NULL; - init++; + static int init; + + if (!init) + { + /* if the list has yet to be initialized */ + /* zap the list, and rebuild from scratch */ + homehead=NULL; + hometail=NULL; + init++; #endif /* DBMPWD */ - setpwent (); + setpwent (); - while ((pw = getpwent ())) - if (!hmalloc (pw)) - break; + while ((pw = getpwent ())) + if (!hmalloc (pw)) + break; - endpwent (); + endpwent (); #ifdef DBMPWD - } + } #endif /* DBMPWD */ } @@ -515,82 +513,82 @@ init_pw (void) static struct aka * akalloc (char *id) { - register struct aka *p; + register struct aka *p; - p = (struct aka *) mh_xmalloc (sizeof(*p)); + p = (struct aka *) mh_xmalloc (sizeof(*p)); - p->ak_name = getcpy (id); - p->ak_visible = 0; - p->ak_addr = NULL; - p->ak_next = NULL; - if (akatail != NULL) - akatail->ak_next = p; - if (akahead == NULL) - akahead = p; - akatail = p; + p->ak_name = getcpy (id); + p->ak_visible = 0; + p->ak_addr = NULL; + p->ak_next = NULL; + if (akatail != NULL) + akatail->ak_next = p; + if (akahead == NULL) + akahead = p; + akatail = p; - return p; + return p; } static struct home * hmalloc (struct passwd *pw) { - register struct home *p; - - p = (struct home *) mh_xmalloc (sizeof(*p)); - - p->h_name = getcpy (pw->pw_name); - p->h_uid = pw->pw_uid; - p->h_gid = pw->pw_gid; - p->h_home = getcpy (pw->pw_dir); - p->h_shell = getcpy (pw->pw_shell); - p->h_ngrps = 0; - p->h_next = NULL; - if (hometail != NULL) - hometail->h_next = p; - if (homehead == NULL) - homehead = p; - hometail = p; - - return p; + register struct home *p; + + p = (struct home *) mh_xmalloc (sizeof(*p)); + + p->h_name = getcpy (pw->pw_name); + p->h_uid = pw->pw_uid; + p->h_gid = pw->pw_gid; + p->h_home = getcpy (pw->pw_dir); + p->h_shell = getcpy (pw->pw_shell); + p->h_ngrps = 0; + p->h_next = NULL; + if (hometail != NULL) + hometail->h_next = p; + if (homehead == NULL) + homehead = p; + hometail = p; + + return p; } struct home * seek_home (char *name) { - register struct home *hp; + register struct home *hp; #ifdef DBMPWD - struct passwd *pw; - char lname[32]; - unsigned char *c; - char *c1; + struct passwd *pw; + char lname[32]; + unsigned char *c; + char *c1; #else /* DBMPWD */ - if (homehead == NULL) - init_pw (); + if (homehead == NULL) + init_pw (); #endif /* DBMPWD */ - for (hp = homehead; hp; hp = hp->h_next) - if (!mh_strcasecmp (name, hp->h_name)) - return hp; + for (hp = homehead; hp; hp = hp->h_next) + if (!mh_strcasecmp (name, hp->h_name)) + return hp; #ifdef DBMPWD - /* - * The only place where there might be problems. - * This assumes that ALL usernames are kept in lowercase. - */ - for (c = name, c1 = lname; *c && (c1 - lname < sizeof(lname) - 1); c++, c1++) { - if (isalpha(*c) && isupper(*c)) - *c1 = tolower (*c); - else - *c1 = *c; - } - *c1 = '\0'; - if ((pw = getpwnam(lname))) - return(hmalloc(pw)); + /* + * The only place where there might be problems. + * This assumes that ALL usernames are kept in lowercase. + */ + for (c = name, c1 = lname; *c && (c1 - lname < sizeof(lname) - 1); c++, c1++) { + if (isalpha(*c) && isupper(*c)) + *c1 = tolower (*c); + else + *c1 = *c; + } + *c1 = '\0'; + if ((pw = getpwnam(lname))) + return(hmalloc(pw)); #endif /* DBMPWD */ - - return NULL; + + return NULL; } diff --git a/uip/anno.c b/uip/anno.c index 41716f7..db1b96c 100644 --- a/uip/anno.c +++ b/uip/anno.c @@ -1,4 +1,3 @@ - /* * anno.c -- annotate messages * @@ -6,78 +5,78 @@ * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. * - * Four new options have been added: delete, list, number, and draft. - * Message header fields are used by the new MIME attachment code in - * the send command. Adding features to generalize the anno command - * seemed to be a better approach than the creation of a new command - * whose features would overlap with those of the anno command. + * Four new options have been added: delete, list, number, and draft. + * Message header fields are used by the new MIME attachment code in + * the send command. Adding features to generalize the anno command + * seemed to be a better approach than the creation of a new command + * whose features would overlap with those of the anno command. * - * The -draft option causes anno to operate on the current draft file - * instead of on a message sequence. + * The -draft option causes anno to operate on the current draft file + * instead of on a message sequence. * - * The -delete option deletes header elements that match the -component - * field name. If -delete is used without the -text option, the first - * header field whose field name matches the component name is deleted. - * If the -delete is used with the -text option, and the -text argument - * begins with a /, the first header field whose field name matches the - * component name and whose field body matches the text is deleted. If - * the -text argument does not begin with a /, then the text is assumed - * to be the last component of a path name, and the first header field - * whose field name matches the component name and a field body whose - * last path name component matches the text is deleted. If the -delete - * option is used with the new -number option described below, the nth - * header field whose field name matches the component name is deleted. - * No header fields are deleted if none of the above conditions are met. + * The -delete option deletes header elements that match the -component + * field name. If -delete is used without the -text option, the first + * header field whose field name matches the component name is deleted. + * If the -delete is used with the -text option, and the -text argument + * begins with a /, the first header field whose field name matches the + * component name and whose field body matches the text is deleted. If + * the -text argument does not begin with a /, then the text is assumed + * to be the last component of a path name, and the first header field + * whose field name matches the component name and a field body whose + * last path name component matches the text is deleted. If the -delete + * option is used with the new -number option described below, the nth + * header field whose field name matches the component name is deleted. + * No header fields are deleted if none of the above conditions are met. * - * The -list option outputs the field bodies from each header field whose - * field name matches the component name, one per line. If no -text - * option is specified, only the last path name component of each field - * body is output. The entire field body is output if the -text option - * is used; the contents of the -text argument are ignored. If the -list - * option is used in conjuction with the new -number option described - * below, each line is numbered starting with 1. A tab separates the - * number from the field body. + * The -list option outputs the field bodies from each header field whose + * field name matches the component name, one per line. If no -text + * option is specified, only the last path name component of each field + * body is output. The entire field body is output if the -text option + * is used; the contents of the -text argument are ignored. If the -list + * option is used in conjuction with the new -number option described + * below, each line is numbered starting with 1. A tab separates the + * number from the field body. * - * The -number option works with both the -delete and -list options as - * described above. The -number option takes an optional argument. A - * value of 1 is assumed if this argument is absent. + * The -number option works with both the -delete and -list options as + * described above. The -number option takes an optional argument. A + * value of 1 is assumed if this argument is absent. */ #include #include static struct swit switches[] = { -#define COMPSW 0 - { "component field", 0 }, -#define INPLSW 1 - { "inplace", 0 }, -#define NINPLSW 2 - { "noinplace", 0 }, -#define DATESW 3 - { "date", 0 }, -#define NDATESW 4 - { "nodate", 0 }, -#define TEXTSW 5 - { "text body", 0 }, +#define COMPSW 0 + { "component field", 0 }, +#define INPLSW 1 + { "inplace", 0 }, +#define NINPLSW 2 + { "noinplace", 0 }, +#define DATESW 3 + { "date", 0 }, +#define NDATESW 4 + { "nodate", 0 }, +#define TEXTSW 5 + { "text body", 0 }, #define VERSIONSW 6 - { "version", 0 }, -#define HELPSW 7 - { "help", 0 }, -#define DRFTSW 8 - { "draft", 2 }, -#define LISTSW 9 - { "list", 1 }, -#define DELETESW 10 - { "delete", 2 }, -#define NUMBERSW 11 - { "number", 2 }, -#define APPENDSW 12 - { "append", 1 }, -#define PRESERVESW 13 - { "preserve", 1 }, -#define NOPRESERVESW 14 - { "nopreserve", 3 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 7 + { "help", 0 }, +#define DRFTSW 8 + { "draft", 2 }, +#define LISTSW 9 + { "list", 1 }, +#define DELETESW 10 + { "delete", 2 }, +#define NUMBERSW 11 + { "number", 2 }, +#define APPENDSW 12 + { "append", 1 }, +#define PRESERVESW 13 + { "preserve", 1 }, +#define NOPRESERVESW 14 + { "nopreserve", 3 }, + { NULL, 0 } }; /* @@ -89,230 +88,230 @@ static void make_comp (unsigned char **); int main (int argc, char **argv) { - int inplace = 1, datesw = 1; - int msgnum; - char *cp, *maildir; - unsigned char *comp = NULL; - char *text = NULL, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; - int append = 0; /* append annotations instead of default prepend */ - int delete = -2; /* delete header element if set */ - char *draft = (char *)0; /* draft file name */ - int isdf = 0; /* return needed for m_draft() */ - int list = 0; /* list header elements if set */ - int number = 0; /* delete specific number of like elements if set */ + int inplace = 1, datesw = 1; + int msgnum; + char *cp, *maildir; + unsigned char *comp = NULL; + char *text = NULL, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; + int append = 0; /* append annotations instead of default prepend */ + int delete = -2; /* delete header element if set */ + char *draft = (char *)0; /* draft file name */ + int isdf = 0; /* return needed for m_draft() */ + int list = 0; /* list header elements if set */ + int number = 0; /* delete specific number of like elements if set */ #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case COMPSW: - if (comp) - adios (NULL, "only one component at a time!"); - if (!(comp = *argp++) || *comp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case DATESW: - datesw++; - continue; - case NDATESW: - datesw = 0; - continue; - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case TEXTSW: - if (text) - adios (NULL, "only one body at a time!"); - if (!(text = *argp++) || *text == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case DELETESW: /* delete annotations */ - delete = 0; - continue; - - case DRFTSW: /* draft message specified */ - draft = ""; - continue; - - case LISTSW: /* produce a listing */ - list = 1; - continue; - - case NUMBERSW: /* number listing or delete by number */ - if (number != 0) - adios (NULL, "only one number at a time!"); - - if (argp - arguments == argc - 1 || **argp == '-') - number = 1; - - else { - if (strcmp(*argp, "all") == 0) - number = -1; - - else if (!(number = atoi(*argp))) - adios (NULL, "missing argument to %s", argp[-2]); - - argp++; - } - - delete = number; - continue; - - case APPENDSW: /* append annotations instead of default prepend */ - append = 1; - continue; - - case PRESERVESW: /* preserve access and modification times on annotated message */ - annopreserve(1); - continue; - - case NOPRESERVESW: /* don't preserve access and modification times on annotated message (default) */ - annopreserve(0); - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case COMPSW: + if (comp) + adios (NULL, "only one component at a time!"); + if (!(comp = *argp++) || *comp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case DATESW: + datesw++; + continue; + case NDATESW: + datesw = 0; + continue; + + case INPLSW: + inplace++; + continue; + case NINPLSW: + inplace = 0; + continue; + + case TEXTSW: + if (text) + adios (NULL, "only one body at a time!"); + if (!(text = *argp++) || *text == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case DELETESW: /* delete annotations */ + delete = 0; + continue; + + case DRFTSW: /* draft message specified */ + draft = ""; + continue; + + case LISTSW: /* produce a listing */ + list = 1; + continue; + + case NUMBERSW: /* number listing or delete by number */ + if (number != 0) + adios (NULL, "only one number at a time!"); + + if (argp - arguments == argc - 1 || **argp == '-') + number = 1; + + else { + if (strcmp(*argp, "all") == 0) + number = -1; + + else if (!(number = atoi(*argp))) + adios (NULL, "missing argument to %s", argp[-2]); + + argp++; + } + + delete = number; + continue; + + case APPENDSW: /* append annotations instead of default prepend */ + append = 1; + continue; + + case PRESERVESW: /* preserve access and modification times on annotated message */ + annopreserve(1); + continue; + + case NOPRESERVESW: /* don't preserve access and modification times on annotated message (default) */ + annopreserve(0); + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); + } + + /* + * We're dealing with the draft message instead of message numbers. + * Get the name of the draft and deal with it just as we do with + * message numbers below. + */ + + if (draft != (char *)0) { + if (msgs.size != 0) + adios(NULL, "can only have message numbers or -draft."); + + draft = getcpy(m_draft(folder, (char *)0, 1, &isdf)); + + make_comp(&comp); + + if (list) + annolist(draft, comp, text, number); + else + annotate (draft, comp, text, inplace, datesw, delete, append); + + done(0); + return 1; } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* - * We're dealing with the draft message instead of message numbers. - * Get the name of the draft and deal with it just as we do with - * message numbers below. - */ - - if (draft != (char *)0) { - if (msgs.size != 0) - adios(NULL, "can only have message numbers or -draft."); - - draft = getcpy(m_draft(folder, (char *)0, 1, &isdf)); - - make_comp(&comp); - - if (list) - annolist(draft, comp, text, number); - else - annotate (draft, comp, text, inplace, datesw, delete, append); - - done(0); - return 1; - } #ifdef UCI - if (strcmp(invo_name, "fanno") == 0) /* ugh! */ - datesw = 0; -#endif /* UCI */ - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - - make_comp (&comp); - - /* annotate all the SELECTED messages */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - if (list) - annolist(m_name(msgnum), comp, text, number); - else - annotate (m_name (msgnum), comp, text, inplace, datesw, delete, append); + if (strcmp(invo_name, "fanno") == 0) /* ugh! */ + datesw = 0; +#endif /* UCI */ + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + + make_comp (&comp); + + /* annotate all the SELECTED messages */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + if (list) + annolist(m_name(msgnum), comp, text, number); + else + annotate (m_name (msgnum), comp, text, inplace, datesw, delete, append); + } } - } - - context_replace (pfolder, folder); /* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize message sequences */ - folder_free (mp); /* free folder/message structure */ - context_save (); /* save the context file */ - done (0); - return 1; + + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->lowsel); /* update current message */ + seq_save (mp); /* synchronize message sequences */ + folder_free (mp); /* free folder/message structure */ + context_save (); /* save the context file */ + done (0); + return 1; } static void make_comp (unsigned char **ap) { - register unsigned char *cp; - char buffer[BUFSIZ]; - - if (*ap == NULL) { - printf ("Enter component name: "); - fflush (stdout); - - if (fgets (buffer, sizeof buffer, stdin) == NULL) - done (1); - *ap = trimcpy (buffer); - } - - if ((cp = *ap + strlen (*ap) - 1) > *ap && *cp == ':') - *cp = 0; - if (strlen (*ap) == 0) - adios (NULL, "null component name"); - if (**ap == '-') - adios (NULL, "invalid component name %s", *ap); - if (strlen (*ap) >= NAMESZ) - adios (NULL, "too large component name %s", *ap); - - for (cp = *ap; *cp; cp++) - if (!isalnum (*cp) && *cp != '-') - adios (NULL, "invalid component name %s", *ap); + register unsigned char *cp; + char buffer[BUFSIZ]; + + if (*ap == NULL) { + printf ("Enter component name: "); + fflush (stdout); + + if (fgets (buffer, sizeof buffer, stdin) == NULL) + done (1); + *ap = trimcpy (buffer); + } + + if ((cp = *ap + strlen (*ap) - 1) > *ap && *cp == ':') + *cp = 0; + if (strlen (*ap) == 0) + adios (NULL, "null component name"); + if (**ap == '-') + adios (NULL, "invalid component name %s", *ap); + if (strlen (*ap) >= NAMESZ) + adios (NULL, "too large component name %s", *ap); + + for (cp = *ap; *cp; cp++) + if (!isalnum (*cp) && *cp != '-') + adios (NULL, "invalid component name %s", *ap); } diff --git a/uip/annosbr.c b/uip/annosbr.c index 87e9580..427daba 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -1,4 +1,3 @@ - /* * annosbr.c -- prepend annotation to messages * @@ -21,143 +20,146 @@ static int annosbr (int, char *, char *, char *, int, int, int, int); /* - * This "local" global and the annopreserve() function are a hack that allows additional - * functionality to be added to anno without piling on yet another annotate() argument. + * This "local" global and the annopreserve() function are a hack that + * allows additional functionality to be added to anno without piling + * on yet another annotate() argument. */ -static int preserve_actime_and_modtime = 0; /* set to preserve access and modification times on annotated message */ +/* set to preserve access and modification times on annotated message */ +static int preserve_actime_and_modtime = 0; int -annotate (char *file, char *comp, char *text, int inplace, int datesw, int delete, int append) +annotate (char *file, char *comp, char *text, int inplace, int datesw, + int delete, int append) { - int i, fd; - struct utimbuf b; - struct stat s; - - /* open and lock the file to be annotated */ - if ((fd = lkopen (file, O_RDWR, 0)) == NOTOK) { - switch (errno) { - case ENOENT: - break; - - default: - admonish (file, "unable to lock and open"); - break; + int i, fd; + struct utimbuf b; + struct stat s; + + /* open and lock the file to be annotated */ + if ((fd = lkopen (file, O_RDWR, 0)) == NOTOK) { + switch (errno) { + case ENOENT: + break; + + default: + admonish (file, "unable to lock and open"); + break; + } + return 1; } - return 1; - } - if (stat(file, &s) == -1) { - advise("can't get access and modification times for %s", file); - preserve_actime_and_modtime = 0; - } + if (stat(file, &s) == -1) { + advise("can't get access and modification times for %s", file); + preserve_actime_and_modtime = 0; + } - b.actime = s.st_atime; - b.modtime = s.st_mtime; + b.actime = s.st_atime; + b.modtime = s.st_mtime; - i = annosbr (fd, file, comp, text, inplace, datesw, delete, append); + i = annosbr (fd, file, comp, text, inplace, datesw, delete, append); - if (preserve_actime_and_modtime && utime(file, &b) == -1) - advise("can't set access and modification times for %s", file); + if (preserve_actime_and_modtime && utime(file, &b) == -1) + advise("can't set access and modification times for %s", file); - lkclose (fd, file); - return i; + lkclose (fd, file); + return i; } /* - * Produce a listing of all header fields (annotations) whose field name matches - * comp. Number the listing if number is set. Treate the field bodies as path - * names and just output the last component unless text is non-NULL. We don't - * care what text is set to. + * Produce a listing of all header fields (annotations) whose field + * name matches comp. Number the listing if number is set. Treate the + * field bodies as path names and just output the last component unless + * text is non-NULL. We don't care what text is set to. */ void annolist(char *file, char *comp, char *text, int number) { - int c; /* current character */ - int count; /* header field (annotation) counter */ - char *cp; /* miscellaneous character pointer */ - char *field; /* buffer for header field */ - int field_size; /* size of field buffer */ - FILE *fp; /* file pointer made from locked file descriptor */ - int length; /* length of field name */ - int n; /* number of bytes written */ - char *sp; /* another miscellaneous character pointer */ - - if ((fp = fopen(file, "r")) == (FILE *)0) - adios(file, "unable to open"); + int c; /* current character */ + int count; /* header field (annotation) counter */ + char *cp; /* miscellaneous character pointer */ + char *field; /* buffer for header field */ + int field_size; /* size of field buffer */ + FILE *fp; /* file pointer made from locked file descriptor */ + int length; /* length of field name */ + int n; /* number of bytes written */ + char *sp; /* another miscellaneous character pointer */ + + if ((fp = fopen(file, "r")) == (FILE *)0) + adios(file, "unable to open"); - /* - * Allocate a buffer to hold the header components as they're read in. - * This buffer might need to be quite large, so we grow it as needed. - */ + /* + * Allocate a buffer to hold the header components as they're read in. + * This buffer might need to be quite large, so we grow it as needed. + */ + field = (char *)mh_xmalloc(field_size = 256); - field = (char *)mh_xmalloc(field_size = 256); + /* + * Get the length of the field name since we use it often. + */ + length = strlen(comp); - /* - * Get the length of the field name since we use it often. - */ + count = 0; - length = strlen(comp); + do { + /* + * Get a line from the input file, growing the field buffer + * as needed. We do this so that we can fit an entire line + * in the buffer making it easy to do a string comparison + * on both the field name and the field body which might be + * a long path name. + */ + + for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) { + if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') { + (void)ungetc(c, fp); + c = '\n'; + break; + } - count = 0; + if (++n >= field_size - 1) { + field = (char *) mh_xrealloc((void *)field, field_size += 256); - do { - /* - * Get a line from the input file, growing the field buffer as needed. We do this - * so that we can fit an entire line in the buffer making it easy to do a string - * comparison on both the field name and the field body which might be a long path - * name. - */ - - for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) { - if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') { - (void)ungetc(c, fp); - c = '\n'; - break; - } - - if (++n >= field_size - 1) { - field = (char *) mh_xrealloc((void *)field, field_size += 256); - - cp = field + n - 1; - } - } + cp = field + n - 1; + } + } - /* - * NUL-terminate the field.. - */ + /* + * NUL-terminate the field.. + */ - *cp = '\0'; + *cp = '\0'; - if (strncasecmp(field, comp, length) == 0 && field[length] == ':') { - for (cp = field + length + 1; *cp == ' ' || *cp == '\t'; cp++) - ; + if (strncasecmp(field, comp, length) == 0 && field[length] == ':') { + for (cp = field + length + 1; *cp == ' ' || *cp == '\t'; cp++) + ; - if (number) - (void)printf("%d\t", ++count); + if (number) + (void)printf("%d\t", ++count); - if (text == (char *)0 && (sp = strrchr(cp, '/')) != (char *)0) - cp = sp + 1; + if (text == (char *)0 && (sp = strrchr(cp, '/')) != (char *)0) + cp = sp + 1; - (void)printf("%s\n", cp); - } + (void)printf("%s\n", cp); + } - } while (*field != '\0' && *field != '-'); + } while (*field != '\0' && *field != '-'); - /* - * Clean up. - */ + /* + * Clean up. + */ - free(field); + free(field); - (void)fclose(fp); + (void)fclose(fp); - return; + return; } /* - * Set the preserve-times flag. This hack eliminates the need for an additional argument to annotate(). + * Set the preserve-times flag. This hack eliminates the need for an + * additional argument to annotate(). */ void @@ -168,280 +170,304 @@ annopreserve(int preserve) } static int -annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, int delete, int append) +annosbr (int fd, char *file, char *comp, char *text, int inplace, + int datesw, int delete, int append) { - int mode, tmpfd; - char *cp, *sp; - char buffer[BUFSIZ], tmpfil[BUFSIZ]; - struct stat st; - FILE *tmp; - int c; /* current character */ - int count; /* header field (annotation) counter */ - char *field = NULL; /* buffer for header field */ - int field_size = 0; /* size of field buffer */ - FILE *fp = NULL; /* file pointer made from locked file descriptor */ - int length; /* length of field name */ - int n; /* number of bytes written */ - - mode = fstat (fd, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot (); - - strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil)); - chmod (tmpfil, mode); - - /* - * We're going to need to copy some of the message file to the temporary - * file while examining the contents. Convert the message file descriptor - * to a file pointer since it's a lot easier and more efficient to use - * stdio for this. Also allocate a buffer to hold the header components - * as they're read in. This buffer is grown as needed later. - */ - - if (delete >= -1 || append != 0) { - if ((fp = fdopen(fd, "r")) == (FILE *)0) - adios(NULL, "unable to fdopen file."); + int mode, tmpfd; + char *cp, *sp; + char buffer[BUFSIZ], tmpfil[BUFSIZ]; + struct stat st; + FILE *tmp; + int c; /* current character */ + int count; /* header field (annotation) counter */ + char *field = NULL; /* buffer for header field */ + int field_size = 0; /* size of field buffer */ + FILE *fp = NULL; /* file pointer made from locked file descriptor */ + int length; /* length of field name */ + int n; /* number of bytes written */ + + mode = fstat (fd, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot (); + + strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil)); + chmod (tmpfil, mode); - field = (char *)mh_xmalloc(field_size = 256); - } - - /* - * We're trying to delete a header field (annotation )if the delete flag is - * not -2 or less. A value greater than zero means that we're deleting the - * nth header field that matches the field (component) name. A value of - * zero means that we're deleting the first field in which both the field - * name matches the component name and the field body matches the text. - * The text is matched in its entirety if it begins with a slash; otherwise - * the text is matched against whatever portion of the field body follows - * the last slash. This allows matching of both absolute and relative path - * names. This is because this functionality was added to support attachments. - * It might be worth having a separate flag to indicate path name matching to - * make it more general. A value of -1 means to delete all matching fields. - */ - - if (delete >= -1) { /* - * Get the length of the field name since we use it often. + * We're going to need to copy some of the message file to the + * temporary file while examining the contents. Convert the + * message file descriptor to a file pointer since it's a lot + * easier and more efficient to use stdio for this. Also allocate + * a buffer to hold the header components as they're read in. + * This buffer is grown as needed later. */ - length = strlen(comp); - - /* - * Initialize the field counter. This is only used if we're deleting by - * number. - */ + if (delete >= -1 || append != 0) { + if ((fp = fdopen(fd, "r")) == (FILE *)0) + adios(NULL, "unable to fdopen file."); - count = 0; + field = (char *)mh_xmalloc(field_size = 256); + } /* - * Copy lines from the input file to the temporary file until we either find the one - * that we're looking for (which we don't copy) or we reach the end of the headers. - * Both a blank line and a line beginning with a - terminate the headers so that we - * can handle both drafts and RFC-2822 format messages. + * We're trying to delete a header field (annotation )if the + * delete flag is not -2 or less. A value greater than zero + * means that we're deleting the nth header field that matches + * the field (component) name. A value of zero means that + * we're deleting the first field in which both the field name + * matches the component name and the field body matches the text. + * The text is matched in its entirety if it begins with a slash; + * otherwise the text is matched against whatever portion of the + * field body follows the last slash. This allows matching of + * both absolute and relative path names. This is because this + * functionality was added to support attachments. It might be + * worth having a separate flag to indicate path name matching + * to make it more general. A value of -1 means to delete all + * matching fields. */ - do { - /* - * Get a line from the input file, growing the field buffer as needed. We do this - * so that we can fit an entire line in the buffer making it easy to do a string - * comparison on both the field name and the field body which might be a long path - * name. - */ - - for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) { - if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') { - (void)ungetc(c, fp); - c = '\n'; - break; - } + if (delete >= -1) { + /* + * Get the length of the field name since we use it often. + */ + + length = strlen(comp); + + /* + * Initialize the field counter. This is only used if + * we're deleting by number. + */ + + count = 0; + + /* + * Copy lines from the input file to the temporary file + * until we either find the one that we're looking + * for (which we don't copy) or we reach the end of + * the headers. Both a blank line and a line beginning + * with a - terminate the headers so that we can handle + * both drafts and RFC-2822 format messages. + */ + + do { + /* + * Get a line from the input file, growing the + * field buffer as needed. We do this so that + * we can fit an entire line in the buffer making + * it easy to do a string comparison on both the + * field name and the field body which might be + * a long path name. + */ + + for (n = 0, cp = field; (c = getc(fp)) != EOF; *cp++ = c) { + if (c == '\n' && (c = getc(fp)) != ' ' && c != '\t') { + (void)ungetc(c, fp); + c = '\n'; + break; + } + + if (++n >= field_size - 1) { + field = (char *) mh_xrealloc((void *)field, field_size *= 2); + + cp = field + n - 1; + } + } + + /* + * NUL-terminate the field.. + */ + + *cp = '\0'; + + /* + * Check for a match on the field name. We delete + * the line by not copying it to the temporary + * file if + * + * o The delete flag is 0, meaning that we're + * going to delete the first matching + * field, and the text is NULL meaning that + * we don't care about the field body. + * + * o The delete flag is 0, meaning that we're + * going to delete the first matching + * field, and the text begins with a / meaning + * that we're looking for a full path name, + * and the text matches the field body. + * + * o The delete flag is 0, meaning that we're + * going to delete the first matching + * field, the text does not begin with a / + * meaning that we're looking for the last + * path name component, and the last path + * name component matches the text. + * + * o The delete flag is positive meaning that + * we're going to delete the nth field + * with a matching field name, and this is + * the nth matching field name. + * + * o The delete flag is -1 meaning that we're + * going to delete all fields with a + * matching field name. + */ + + if (strncasecmp(field, comp, length) == 0 && field[length] == ':') { + if (delete == 0) { + if (text == (char *)0) + break; + + for (cp = field + length + 1; *cp == ' ' || *cp == '\t'; cp++) + ; + + if (*text == '/') { + if (strcmp(cp, text) == 0) + break; + } + else { + if ((sp = strrchr(cp, '/')) != (char *)0) + cp = sp + 1; + + if (strcmp(cp, text) == 0) + break; + } + } + + else if (delete == -1) + continue; + + else if (++count == delete) + break; + } + + /* + * This line wasn't a match so copy it to the + * temporary file. + */ + + if ((n = fputs(field, tmp)) == EOF || (c == '\n' && fputc('\n', tmp) == EOF)) + adios(NULL, "unable to write temporary file."); + + } while (*field != '\0' && *field != '-'); + + /* + * Get rid of the field buffer because we're done with it. + */ + + free((void *)field); + } - if (++n >= field_size - 1) { - field = (char *) mh_xrealloc((void *)field, field_size *= 2); - - cp = field + n - 1; + else { + /* + * Find the end of the headers before adding the + * annotations if we're appending instead of the default + * prepending. A special check for no headers is needed + * if appending. + */ + + if (append) { + /* + * Copy lines from the input file to the temporary + * file until we reach the end of the headers. + */ + + if ((c = getc(fp)) == '\n') + rewind(fp); + + else { + (void)putc(c, tmp); + + while ((c = getc(fp)) != EOF) { + (void)putc(c, tmp); + + if (c == '\n') { + (void)ungetc(c = getc(fp), fp); + + if (c == '\n' || c == '-') + break; + } + } + } } - } - - /* - * NUL-terminate the field.. - */ - - *cp = '\0'; - - /* - * Check for a match on the field name. We delete the line by not copying it to the - * temporary file if - * - * o The delete flag is 0, meaning that we're going to delete the first matching - * field, and the text is NULL meaning that we don't care about the field body. - * - * o The delete flag is 0, meaning that we're going to delete the first matching - * field, and the text begins with a / meaning that we're looking for a full - * path name, and the text matches the field body. - * - * o The delete flag is 0, meaning that we're going to delete the first matching - * field, the text does not begin with a / meaning that we're looking for the - * last path name component, and the last path name component matches the text. - * - * o The delete flag is positive meaning that we're going to delete the nth field - * with a matching field name, and this is the nth matching field name. - * - * o The delete flag is -1 meaning that we're going to delete all fields with a - * matching field name. - */ - - if (strncasecmp(field, comp, length) == 0 && field[length] == ':') { - if (delete == 0) { - if (text == (char *)0) - break; - - for (cp = field + length + 1; *cp == ' ' || *cp == '\t'; cp++) - ; - - if (*text == '/') { - if (strcmp(cp, text) == 0) - break; - } - else { - if ((sp = strrchr(cp, '/')) != (char *)0) - cp = sp + 1; - - if (strcmp(cp, text) == 0) - break; - } - } - - else if (delete == -1) - continue; - - else if (++count == delete) - break; - } - /* - * This line wasn't a match so copy it to the temporary file. - */ - - if ((n = fputs(field, tmp)) == EOF || (c == '\n' && fputc('\n', tmp) == EOF)) - adios(NULL, "unable to write temporary file."); - - } while (*field != '\0' && *field != '-'); - - /* - * Get rid of the field buffer because we're done with it. - */ + if (datesw) + fprintf (tmp, "%s: %s\n", comp, dtimenow (0)); + if ((cp = text)) { + do { + while (*cp == ' ' || *cp == '\t') + cp++; + sp = cp; + while (*cp && *cp++ != '\n') + continue; + if (cp - sp) + fprintf (tmp, "%s: %*.*s", comp, (int)(cp - sp), (int)(cp - sp), sp); + } while (*cp); + if (cp[-1] != '\n' && cp != text) + putc ('\n', tmp); + } + } - free((void *)field); - } + fflush (tmp); - else { /* - * Find the end of the headers before adding the annotations if we're - * appending instead of the default prepending. A special check for - * no headers is needed if appending. + * We've been messing with the input file position. Move the + * input file descriptor to the current place in the file + * because the stock data copying routine uses the descriptor, + * not the pointer. */ - if (append) { - /* - * Copy lines from the input file to the temporary file until we - * reach the end of the headers. - */ - - if ((c = getc(fp)) == '\n') - rewind(fp); - - else { - (void)putc(c, tmp); - - while ((c = getc(fp)) != EOF) { - (void)putc(c, tmp); - - if (c == '\n') { - (void)ungetc(c = getc(fp), fp); - - if (c == '\n' || c == '-') - break; - } - } - } + if (append || delete >= -1) { + if (lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1) + adios(NULL, "can't seek."); } - if (datesw) - fprintf (tmp, "%s: %s\n", comp, dtimenow (0)); - if ((cp = text)) { - do { - while (*cp == ' ' || *cp == '\t') - cp++; - sp = cp; - while (*cp && *cp++ != '\n') - continue; - if (cp - sp) - fprintf (tmp, "%s: %*.*s", comp, (int)(cp - sp), (int)(cp - sp), sp); - } while (*cp); - if (cp[-1] != '\n' && cp != text) - putc ('\n', tmp); + cpydata (fd, fileno (tmp), file, tmpfil); + fclose (tmp); + + if (inplace) { + if ((tmpfd = open (tmpfil, O_RDONLY)) == NOTOK) + adios (tmpfil, "unable to open for re-reading"); + + lseek (fd, (off_t) 0, SEEK_SET); + + /* + * We're making the file shorter if we're deleting a + * header field so the file has to be truncated or it + * will contain garbage. + */ + + if (delete >= -1 && ftruncate(fd, 0) == -1) + adios(tmpfil, "unable to truncate."); + + cpydata (tmpfd, fd, tmpfil, file); + close (tmpfd); + unlink (tmpfil); + } else { + strncpy (buffer, m_backup (file), sizeof(buffer)); + if (rename (file, buffer) == NOTOK) { + switch (errno) { + case ENOENT: /* unlinked early - no annotations */ + unlink (tmpfil); + break; + + default: + admonish (buffer, "unable to rename %s to", file); + break; + } + return 1; + } + if (rename (tmpfil, file) == NOTOK) { + admonish (file, "unable to rename %s to", tmpfil); + return 1; + } } - } - - fflush (tmp); - - /* - * We've been messing with the input file position. Move the input file - * descriptor to the current place in the file because the stock data - * copying routine uses the descriptor, not the pointer. - */ - - if (append || delete >= -1) { - if (lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1) - adios(NULL, "can't seek."); - } - - cpydata (fd, fileno (tmp), file, tmpfil); - fclose (tmp); - - if (inplace) { - if ((tmpfd = open (tmpfil, O_RDONLY)) == NOTOK) - adios (tmpfil, "unable to open for re-reading"); - - lseek (fd, (off_t) 0, SEEK_SET); /* - * We're making the file shorter if we're deleting a header field - * so the file has to be truncated or it will contain garbage. + * Close the delete file so that we don't run out of file pointers if + * we're doing piles of files. Note that this will make the close() in + * lkclose() fail, but that failure is ignored so it's not a problem. */ - if (delete >= -1 && ftruncate(fd, 0) == -1) - adios(tmpfil, "unable to truncate."); - - cpydata (tmpfd, fd, tmpfil, file); - close (tmpfd); - unlink (tmpfil); - } else { - strncpy (buffer, m_backup (file), sizeof(buffer)); - if (rename (file, buffer) == NOTOK) { - switch (errno) { - case ENOENT: /* unlinked early - no annotations */ - unlink (tmpfil); - break; - - default: - admonish (buffer, "unable to rename %s to", file); - break; - } - return 1; - } - if (rename (tmpfil, file) == NOTOK) { - admonish (file, "unable to rename %s to", tmpfil); - return 1; - } - } - - /* - * Close the delete file so that we don't run out of file pointers if - * we're doing piles of files. Note that this will make the close() in - * lkclose() fail, but that failure is ignored so it's not a problem. - */ - - if (delete >= -1) - (void)fclose(fp); + if (delete >= -1) + (void)fclose(fp); - return 0; + return 0; } diff --git a/uip/ap.c b/uip/ap.c index a0f7f77..1e2151b 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -1,4 +1,3 @@ - /* * ap.c -- parse addresses 822-style * @@ -12,29 +11,29 @@ #include #include -#define NADDRS 100 +#define NADDRS 100 -#define WIDTH 78 -#define WBUFSIZ BUFSIZ +#define WIDTH 78 +#define WBUFSIZ BUFSIZ -#define FORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>" +#define FORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>" static struct swit switches[] = { -#define FORMSW 0 - { "form formatfile", 0 }, -#define FMTSW 1 - { "format string", 5 }, -#define NORMSW 2 - { "normalize", 0 }, -#define NNORMSW 3 - { "nonormalize", 0 }, -#define WIDTHSW 4 - { "width columns", 0 }, +#define FORMSW 0 + { "form formatfile", 0 }, +#define FMTSW 1 + { "format string", 5 }, +#define NORMSW 2 + { "normalize", 0 }, +#define NNORMSW 3 + { "nonormalize", 0 }, +#define WIDTHSW 4 + { "width columns", 0 }, #define VERSIONSW 5 - { "version", 0 }, -#define HELPSW 6 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 6 + { "help", 0 }, + { NULL, 0 } }; static struct format *fmt; @@ -55,155 +54,155 @@ static int process (char *, int, int); int main (int argc, char **argv) { - int addrp = 0, normalize = AD_HOST; - int width = 0, status = 0; - char *cp, *form = NULL, *format = NULL, *nfs; - char buf[BUFSIZ], **argp; - char **arguments, *addrs[NADDRS]; + int addrp = 0, normalize = AD_HOST; + int width = 0, status = 0; + char *cp, *form = NULL, *format = NULL, *nfs; + char buf[BUFSIZ], **argp; + char **arguments, *addrs[NADDRS]; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] addrs ...", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version (invo_name); - done (1); - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - width = atoi (cp); - continue; - - case NORMSW: - normalize = AD_HOST; - continue; - case NNORMSW: - normalize = AD_NHST; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] addrs ...", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version (invo_name); + done (1); + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + width = atoi (cp); + continue; + + case NORMSW: + normalize = AD_HOST; + continue; + case NNORMSW: + normalize = AD_NHST; + continue; + } + } + if (addrp > NADDRS) + adios (NULL, "more than %d addresses", NADDRS); + else + addrs[addrp++] = cp; } - if (addrp > NADDRS) - adios (NULL, "more than %d addresses", NADDRS); - else - addrs[addrp++] = cp; - } - addrs[addrp] = NULL; - - if (addrp == 0) - adios (NULL, "usage: %s [switches] addrs ...", invo_name); - - /* get new format string */ - nfs = new_fs (form, format, FORMAT); - - if (width == 0) { - if ((width = sc_width ()) < WIDTH / 2) - width = WIDTH / 2; - width -= 2; - } - if (width > WBUFSIZ) - width = WBUFSIZ; - fmt_norm = normalize; - fmt_compile (nfs, &fmt); - - dat[0] = 0; - dat[1] = 0; - dat[2] = 0; - dat[3] = width; - dat[4] = 0; - - for (addrp = 0; addrs[addrp]; addrp++) - status += process (addrs[addrp], width, normalize); - - done (status); - return 1; + addrs[addrp] = NULL; + + if (addrp == 0) + adios (NULL, "usage: %s [switches] addrs ...", invo_name); + + /* get new format string */ + nfs = new_fs (form, format, FORMAT); + + if (width == 0) { + if ((width = sc_width ()) < WIDTH / 2) + width = WIDTH / 2; + width -= 2; + } + if (width > WBUFSIZ) + width = WBUFSIZ; + fmt_norm = normalize; + fmt_compile (nfs, &fmt); + + dat[0] = 0; + dat[1] = 0; + dat[2] = 0; + dat[3] = width; + dat[4] = 0; + + for (addrp = 0; addrs[addrp]; addrp++) + status += process (addrs[addrp], width, normalize); + + done (status); + return 1; } struct pqpair { - char *pq_text; - char *pq_error; - struct pqpair *pq_next; + char *pq_text; + char *pq_error; + struct pqpair *pq_next; }; static int process (char *arg, int length, int norm) { - int status = 0; - register char *cp; - char buffer[WBUFSIZ + 1], error[BUFSIZ]; - register struct comp *cptr; - register struct pqpair *p, *q; - struct pqpair pq; - register struct mailname *mp; - - (q = &pq)->pq_next = NULL; - while ((cp = getname (arg))) { - if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL) - adios (NULL, "unable to allocate pqpair memory"); - if ((mp = getm (cp, NULL, 0, norm, error)) == NULL) { - p->pq_text = getcpy (cp); - p->pq_error = getcpy (error); - status++; + int status = 0; + register char *cp; + char buffer[WBUFSIZ + 1], error[BUFSIZ]; + register struct comp *cptr; + register struct pqpair *p, *q; + struct pqpair pq; + register struct mailname *mp; + + (q = &pq)->pq_next = NULL; + while ((cp = getname (arg))) { + if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL) + adios (NULL, "unable to allocate pqpair memory"); + if ((mp = getm (cp, NULL, 0, norm, error)) == NULL) { + p->pq_text = getcpy (cp); + p->pq_error = getcpy (error); + status++; + } + else { + p->pq_text = getcpy (mp->m_text); + mnfree (mp); + } + q = (q->pq_next = p); } - else { - p->pq_text = getcpy (mp->m_text); - mnfree (mp); + + for (p = pq.pq_next; p; p = q) { + FINDCOMP (cptr, "text"); + if (cptr) + cptr->c_text = p->pq_text; + FINDCOMP (cptr, "error"); + if (cptr) + cptr->c_text = p->pq_error; + + fmt_scan (fmt, buffer, length, dat); + fputs (buffer, stdout); + + free (p->pq_text); + if (p->pq_error) + free (p->pq_error); + q = p->pq_next; + free ((char *) p); } - q = (q->pq_next = p); - } - - for (p = pq.pq_next; p; p = q) { - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = p->pq_text; - FINDCOMP (cptr, "error"); - if (cptr) - cptr->c_text = p->pq_error; - - fmt_scan (fmt, buffer, length, dat); - fputs (buffer, stdout); - - free (p->pq_text); - if (p->pq_error) - free (p->pq_error); - q = p->pq_next; - free ((char *) p); - } - - return status; + + return status; } diff --git a/uip/burst.c b/uip/burst.c index fa3ac73..8f0a238 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -1,4 +1,3 @@ - /* * burst.c -- explode digests into individual messages * @@ -10,30 +9,30 @@ #include static struct swit switches[] = { -#define INPLSW 0 - { "inplace", 0 }, -#define NINPLSW 1 - { "noinplace", 0 }, -#define QIETSW 2 - { "quiet", 0 }, -#define NQIETSW 3 - { "noquiet", 0 }, -#define VERBSW 4 - { "verbose", 0 }, -#define NVERBSW 5 - { "noverbose", 0 }, +#define INPLSW 0 + { "inplace", 0 }, +#define NINPLSW 1 + { "noinplace", 0 }, +#define QIETSW 2 + { "quiet", 0 }, +#define NQIETSW 3 + { "noquiet", 0 }, +#define VERBSW 4 + { "verbose", 0 }, +#define NVERBSW 5 + { "noverbose", 0 }, #define VERSIONSW 6 - { "version", 0 }, -#define HELPSW 7 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 7 + { "help", 0 }, + { NULL, 0 } }; static char delim3[] = "-------"; struct smsg { - long s_start; - long s_stop; + long s_start; + long s_stop; }; /* @@ -47,148 +46,148 @@ static void cpybrst (FILE *, FILE *, char *, char *, int); int main (int argc, char **argv) { - int inplace = 0, quietsw = 0, verbosw = 0; - int msgp = 0, hi, msgnum, numburst; - char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments, *msgs[MAXARGS]; - struct smsg *smsgs; - struct msgs *mp; + int inplace = 0, quietsw = 0, verbosw = 0; + int msgp = 0, hi, msgnum, numburst; + char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments, *msgs[MAXARGS]; + struct smsg *smsgs; + struct msgs *mp; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case QIETSW: - quietsw++; - continue; - case NQIETSW: - quietsw = 0; - continue; - - case VERBSW: - verbosw++; - continue; - case NVERBSW: - verbosw = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case INPLSW: + inplace++; + continue; + case NINPLSW: + inplace = 0; + continue; + + case QIETSW: + quietsw++; + continue; + case NQIETSW: + quietsw = 0; + continue; + + case VERBSW: + verbosw++; + continue; + case NVERBSW: + verbosw = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + msgs[msgp++] = cp; + } } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - msgs[msgp++] = cp; + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!msgp) + msgs[msgp++] = "cur"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgp; msgnum++) + if (!m_convert (mp, msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + smsgs = (struct smsg *) + calloc ((size_t) (MAXFOLDER + 2), sizeof(*smsgs)); + if (smsgs == NULL) + adios (NULL, "unable to allocate burst storage"); + + hi = mp->hghmsg + 1; + + /* burst all the SELECTED messages */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + if ((numburst = find_delim (msgnum, smsgs)) >= 1) { + if (verbosw) + printf ("%d message%s exploded from digest %d\n", + numburst, numburst > 1 ? "s" : "", msgnum); + burst (&mp, msgnum, smsgs, numburst, inplace, verbosw, maildir); + } else { + if (numburst == 0) { + if (!quietsw) + admonish (NULL, "message %d not in digest format", + msgnum); + } /* this pair of braces was missing before 1999-07-15 */ + else + adios (NULL, "burst() botch -- you lose big"); + } + } } - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!msgp) - msgs[msgp++] = "cur"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - smsgs = (struct smsg *) - calloc ((size_t) (MAXFOLDER + 2), sizeof(*smsgs)); - if (smsgs == NULL) - adios (NULL, "unable to allocate burst storage"); - - hi = mp->hghmsg + 1; - - /* burst all the SELECTED messages */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - if ((numburst = find_delim (msgnum, smsgs)) >= 1) { - if (verbosw) - printf ("%d message%s exploded from digest %d\n", - numburst, numburst > 1 ? "s" : "", msgnum); - burst (&mp, msgnum, smsgs, numburst, inplace, verbosw, maildir); - } else { - if (numburst == 0) { - if (!quietsw) - admonish (NULL, "message %d not in digest format", - msgnum); - } /* this pair of braces was missing before 1999-07-15 */ - else - adios (NULL, "burst() botch -- you lose big"); - } + + free ((char *) smsgs); + context_replace (pfolder, folder); /* update current folder */ + + /* + * If -inplace is given, then the first message burst becomes + * the current message (which will now show a table of contents). + * Otherwise, the first message extracted from the first digest + * becomes the current message. + */ + if (inplace) { + if (mp->lowsel != mp->curmsg) + seq_setcur (mp, mp->lowsel); + } else { + if (hi <= mp->hghmsg) + seq_setcur (mp, hi); } - } - - free ((char *) smsgs); - context_replace (pfolder, folder); /* update current folder */ - - /* - * If -inplace is given, then the first message burst becomes - * the current message (which will now show a table of contents). - * Otherwise, the first message extracted from the first digest - * becomes the current message. - */ - if (inplace) { - if (mp->lowsel != mp->curmsg) - seq_setcur (mp, mp->lowsel); - } else { - if (hi <= mp->hghmsg) - seq_setcur (mp, hi); - } - - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ + done (0); + return 1; } @@ -200,52 +199,52 @@ main (int argc, char **argv) static int find_delim (int msgnum, struct smsg *smsgs) { - int ld3, wasdlm, msgp; - long pos; - char c, *msgnam; - int cc; - char buffer[BUFSIZ]; - FILE *in; - - ld3 = strlen (delim3); - - if ((in = fopen (msgnam = m_name (msgnum), "r")) == NULL) - adios (msgnam, "unable to read message"); - - for (msgp = 0, pos = 0L; msgp <= MAXFOLDER;) { - while (fgets (buffer, sizeof(buffer), in) && buffer[0] == '\n') - pos += (long) strlen (buffer); - if (feof (in)) - break; - fseek (in, pos, SEEK_SET); - smsgs[msgp].s_start = pos; - - for (c = 0; fgets (buffer, sizeof(buffer), in); c = buffer[0]) { - if (strncmp (buffer, delim3, ld3) == 0 - && (msgp == 1 || c == '\n') - && ((cc = peekc (in)) == '\n' || cc == EOF)) - break; - else - pos += (long) strlen (buffer); - } + int ld3, wasdlm, msgp; + long pos; + char c, *msgnam; + int cc; + char buffer[BUFSIZ]; + FILE *in; + + ld3 = strlen (delim3); + + if ((in = fopen (msgnam = m_name (msgnum), "r")) == NULL) + adios (msgnam, "unable to read message"); + + for (msgp = 0, pos = 0L; msgp <= MAXFOLDER;) { + while (fgets (buffer, sizeof(buffer), in) && buffer[0] == '\n') + pos += (long) strlen (buffer); + if (feof (in)) + break; + fseek (in, pos, SEEK_SET); + smsgs[msgp].s_start = pos; + + for (c = 0; fgets (buffer, sizeof(buffer), in); c = buffer[0]) { + if (strncmp (buffer, delim3, ld3) == 0 + && (msgp == 1 || c == '\n') + && ((cc = peekc (in)) == '\n' || cc == EOF)) + break; + else + pos += (long) strlen (buffer); + } - wasdlm = strncmp (buffer, delim3, ld3) == 0; - if (smsgs[msgp].s_start != pos) - smsgs[msgp++].s_stop = (c == '\n' && wasdlm) ? pos - 1 : pos; - if (feof (in)) { + wasdlm = strncmp (buffer, delim3, ld3) == 0; + if (smsgs[msgp].s_start != pos) + smsgs[msgp++].s_stop = (c == '\n' && wasdlm) ? pos - 1 : pos; + if (feof (in)) { #if 0 - if (wasdlm) { - smsgs[msgp - 1].s_stop -= ((long) strlen (buffer) + 1); - msgp++; /* fake "End of XXX Digest" */ - } + if (wasdlm) { + smsgs[msgp - 1].s_stop -= ((long) strlen (buffer) + 1); + msgp++; /* fake "End of XXX Digest" */ + } #endif - break; + break; + } + pos += (long) strlen (buffer); } - pos += (long) strlen (buffer); - } - fclose (in); - return (msgp - 1); /* toss "End of XXX Digest" */ + fclose (in); + return (msgp - 1); /* toss "End of XXX Digest" */ } @@ -257,130 +256,133 @@ static void burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, int inplace, int verbosw, char *maildir) { - int i, j, mode; - char *msgnam; - char f1[BUFSIZ], f2[BUFSIZ], f3[BUFSIZ]; - FILE *in, *out; - struct stat st; - struct msgs *mp; - - if ((in = fopen (msgnam = m_name (msgnum), "r")) == NULL) - adios (msgnam, "unable to read message"); - - mode = fstat (fileno(in), &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot(); - mp = *mpp; - - /* - * See if we have enough space in the folder - * structure for all the new messages. - */ - if ((mp->hghmsg + numburst > mp->hghoff) && - !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + numburst))) - adios (NULL, "unable to allocate folder storage"); - *mpp = mp; - - j = mp->hghmsg; /* old value */ - mp->hghmsg += numburst; - mp->nummsg += numburst; - - /* - * If this is not the highest SELECTED message, then - * increment mp->hghsel by numburst, since the highest - * SELECTED is about to be slid down by that amount. - */ - if (msgnum < mp->hghsel) - mp->hghsel += numburst; - - /* - * If -inplace is given, renumber the messages after the - * source message, to make room for each of the messages - * contained within the digest. - * - * This is equivalent to refiling a message from the point - * of view of the external hooks. - */ - if (inplace) { - for (i = mp->hghmsg; j > msgnum; i--, j--) { - strncpy (f1, m_name (i), sizeof(f1)); - strncpy (f2, m_name (j), sizeof(f2)); - if (does_exist (mp, j)) { - if (verbosw) - printf ("message %d becomes message %d\n", j, i); + int i, j, mode; + char *msgnam; + char f1[BUFSIZ], f2[BUFSIZ], f3[BUFSIZ]; + FILE *in, *out; + struct stat st; + struct msgs *mp; + + if ((in = fopen (msgnam = m_name (msgnum), "r")) == NULL) + adios (msgnam, "unable to read message"); + + mode = fstat (fileno(in), &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot(); + mp = *mpp; + + /* + * See if we have enough space in the folder + * structure for all the new messages. + */ + if ((mp->hghmsg + numburst > mp->hghoff) && + !(mp = folder_realloc (mp, mp->lowoff, mp->hghmsg + numburst))) + adios (NULL, "unable to allocate folder storage"); + *mpp = mp; + + j = mp->hghmsg; /* old value */ + mp->hghmsg += numburst; + mp->nummsg += numburst; + + /* + * If this is not the highest SELECTED message, then + * increment mp->hghsel by numburst, since the highest + * SELECTED is about to be slid down by that amount. + */ + if (msgnum < mp->hghsel) + mp->hghsel += numburst; + + /* + * If -inplace is given, renumber the messages after the + * source message, to make room for each of the messages + * contained within the digest. + * + * This is equivalent to refiling a message from the point + * of view of the external hooks. + */ + if (inplace) { + for (i = mp->hghmsg; j > msgnum; i--, j--) { + strncpy (f1, m_name (i), sizeof(f1)); + strncpy (f2, m_name (j), sizeof(f2)); + if (does_exist (mp, j)) { + if (verbosw) + printf ("message %d becomes message %d\n", j, i); + + if (rename (f2, f1) == NOTOK) + admonish (f1, "unable to rename %s to", f2); + + (void)snprintf(f1, sizeof (f1), "%s/%d", maildir, i); + (void)snprintf(f2, sizeof (f2), "%s/%d", maildir, j); + ext_hook("ref-hook", f1, f2); + + copy_msg_flags (mp, i, j); + clear_msg_flags (mp, j); + mp->msgflags |= SEQMOD; + } + } + } + unset_selected (mp, msgnum); + + /* new hghmsg is hghmsg + numburst + * + * At this point, there is an array of numburst smsgs, each + * element of which contains the starting and stopping offsets + * (seeks) of the message in the digest. The inplace flag is set + * if the original digest is replaced by a message containing + * the table of contents. smsgs[0] is that table of contents. + * Go through the message numbers in reverse order (high to low). + * + * Set f1 to the name of the destination message, f2 to the name + * of a scratch file. Extract a message from the digest to the + * scratch file. Move the original message to a backup file if + * the destination message number is the same as the number of + * the original message, which only happens if the inplace flag + * is set. Then move the scratch file to the destination message. + * + * Moving the original message to the backup file is equivalent + * to deleting the message from the point of view of the external + * hooks. And bursting each message is equivalent to adding a + * new message. + */ + + i = inplace ? msgnum + numburst : mp->hghmsg; + for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) { + strncpy (f1, m_name (i), sizeof(f1)); + strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2)); + + if (verbosw && i != msgnum) + printf ("message %d of digest %d becomes message %d\n", j, msgnum, i); + + chmod (f2, mode); + fseek (in, smsgs[j].s_start, SEEK_SET); + cpybrst (in, out, msgnam, f2, + (int) (smsgs[j].s_stop - smsgs[j].s_start)); + fclose (out); + + if (i == msgnum) { + strncpy (f3, m_backup (f1), sizeof(f3)); + if (rename (f1, f3) == NOTOK) + admonish (f3, "unable to rename %s to", f1); + + (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i); + ext_hook("del-hook", f3, (char *)0); + } if (rename (f2, f1) == NOTOK) - admonish (f1, "unable to rename %s to", f2); + admonish (f1, "unable to rename %s to", f2); - (void)snprintf(f1, sizeof (f1), "%s/%d", maildir, i); - (void)snprintf(f2, sizeof (f2), "%s/%d", maildir, j); - ext_hook("ref-hook", f1, f2); + (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i); + ext_hook("add-hook", f3, (char *)0); - copy_msg_flags (mp, i, j); - clear_msg_flags (mp, j); + copy_msg_flags (mp, i, msgnum); mp->msgflags |= SEQMOD; - } - } - } - - unset_selected (mp, msgnum); - - /* new hghmsg is hghmsg + numburst - * - * At this point, there is an array of numburst smsgs, each element of - * which contains the starting and stopping offsets (seeks) of the message - * in the digest. The inplace flag is set if the original digest is replaced - * by a message containing the table of contents. smsgs[0] is that table of - * contents. Go through the message numbers in reverse order (high to low). - * - * Set f1 to the name of the destination message, f2 to the name of a scratch - * file. Extract a message from the digest to the scratch file. Move the - * original message to a backup file if the destination message number is the - * same as the number of the original message, which only happens if the - * inplace flag is set. Then move the scratch file to the destination message. - * - * Moving the original message to the backup file is equivalent to deleting the - * message from the point of view of the external hooks. And bursting each - * message is equivalent to adding a new message. - */ - - i = inplace ? msgnum + numburst : mp->hghmsg; - for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) { - strncpy (f1, m_name (i), sizeof(f1)); - strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2)); - - if (verbosw && i != msgnum) - printf ("message %d of digest %d becomes message %d\n", j, msgnum, i); - - chmod (f2, mode); - fseek (in, smsgs[j].s_start, SEEK_SET); - cpybrst (in, out, msgnam, f2, - (int) (smsgs[j].s_stop - smsgs[j].s_start)); - fclose (out); - - if (i == msgnum) { - strncpy (f3, m_backup (f1), sizeof(f3)); - if (rename (f1, f3) == NOTOK) - admonish (f3, "unable to rename %s to", f1); - - (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i); - ext_hook("del-hook", f3, (char *)0); } - if (rename (f2, f1) == NOTOK) - admonish (f1, "unable to rename %s to", f2); - (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i); - ext_hook("add-hook", f3, (char *)0); - - copy_msg_flags (mp, i, msgnum); - mp->msgflags |= SEQMOD; - } - - fclose (in); + fclose (in); } -#define S1 0 -#define S2 1 -#define S3 2 +#define S1 0 +#define S2 1 +#define S3 2 /* * Copy a mesage which is being burst out of a digest. @@ -390,54 +392,54 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, static void cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len) { - register int c, state; - - for (state = S1; (c = fgetc (in)) != EOF && len > 0; len--) { - if (c == 0) - continue; - switch (state) { - case S1: - switch (c) { - case '-': - state = S3; - break; - - default: - state = S2; - case '\n': - fputc (c, out); - break; - } - break; - - case S2: - switch (c) { - case '\n': - state = S1; - default: - fputc (c, out); - break; - } - break; - - case S3: - switch (c) { - case ' ': - state = S2; - break; - - default: - state = (c == '\n') ? S1 : S2; - fputc ('-', out); - fputc (c, out); - break; + register int c, state; + + for (state = S1; (c = fgetc (in)) != EOF && len > 0; len--) { + if (c == 0) + continue; + switch (state) { + case S1: + switch (c) { + case '-': + state = S3; + break; + + default: + state = S2; + case '\n': + fputc (c, out); + break; + } + break; + + case S2: + switch (c) { + case '\n': + state = S1; + default: + fputc (c, out); + break; + } + break; + + case S3: + switch (c) { + case ' ': + state = S2; + break; + + default: + state = (c == '\n') ? S1 : S2; + fputc ('-', out); + fputc (c, out); + break; + } + break; } - break; } - } - if (ferror (in) && !feof (in)) - adios (ifile, "error reading"); - if (ferror (out)) - adios (ofile, "error writing"); + if (ferror (in) && !feof (in)) + adios (ifile, "error reading"); + if (ferror (out)) + adios (ofile, "error writing"); } diff --git a/uip/comp.c b/uip/comp.c index 5ebce6e..f713b6f 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -1,4 +1,3 @@ - /* * comp.c -- compose a message * @@ -12,288 +11,288 @@ #include static struct swit switches[] = { -#define DFOLDSW 0 - { "draftfolder +folder", 0 }, -#define DMSGSW 1 - { "draftmessage msg", 0 }, -#define NDFLDSW 2 - { "nodraftfolder", 0 }, -#define EDITRSW 3 - { "editor editor", 0 }, -#define NEDITSW 4 - { "noedit", 0 }, -#define FILESW 5 - { "file file", 0 }, -#define FORMSW 6 - { "form formfile", 0 }, -#define USESW 7 - { "use", 0 }, -#define NUSESW 8 - { "nouse", 0 }, -#define WHATSW 9 - { "whatnowproc program", 0 }, -#define NWHATSW 10 - { "nowhatnowproc", 0 }, -#define VERSIONSW 11 - { "version", 0 }, -#define HELPSW 12 - { "help", 0 }, - { NULL, 0 } +#define DFOLDSW 0 + { "draftfolder +folder", 0 }, +#define DMSGSW 1 + { "draftmessage msg", 0 }, +#define NDFLDSW 2 + { "nodraftfolder", 0 }, +#define EDITRSW 3 + { "editor editor", 0 }, +#define NEDITSW 4 + { "noedit", 0 }, +#define FILESW 5 + { "file file", 0 }, +#define FORMSW 6 + { "form formfile", 0 }, +#define USESW 7 + { "use", 0 }, +#define NUSESW 8 + { "nouse", 0 }, +#define WHATSW 9 + { "whatnowproc program", 0 }, +#define NWHATSW 10 + { "nowhatnowproc", 0 }, +#define VERSIONSW 11 + { "version", 0 }, +#define HELPSW 12 + { "help", 0 }, + { NULL, 0 } }; static struct swit aqrunl[] = { -#define NOSW 0 - { "quit", 0 }, -#define YESW 1 - { "replace", 0 }, -#define USELSW 2 - { "use", 0 }, -#define LISTDSW 3 - { "list", 0 }, -#define REFILSW 4 - { "refile +folder", 0 }, -#define NEWSW 5 - { "new", 0 }, - { NULL, 0 } +#define NOSW 0 + { "quit", 0 }, +#define YESW 1 + { "replace", 0 }, +#define USELSW 2 + { "use", 0 }, +#define LISTDSW 3 + { "list", 0 }, +#define REFILSW 4 + { "refile +folder", 0 }, +#define NEWSW 5 + { "new", 0 }, + { NULL, 0 } }; static struct swit aqrul[] = { - { "quit", 0 }, - { "replace", 0 }, - { "use", 0 }, - { "list", 0 }, - { "refile", 0 }, - { NULL, 0 } + { "quit", 0 }, + { "replace", 0 }, + { "use", 0 }, + { "list", 0 }, + { "refile", 0 }, + { NULL, 0 } }; int main (int argc, char **argv) { - int use = NOUSE, nedit = 0, nwhat = 0; - int i, in, isdf = 0, out; - char *cp, *cwd, *maildir, *dfolder = NULL; - char *ed = NULL, *file = NULL, *form = NULL; - char *folder = NULL, *msg = NULL, buf[BUFSIZ]; - char drft[BUFSIZ], **argp, **arguments; - struct msgs *mp = NULL; - struct stat st; + int use = NOUSE, nedit = 0, nwhat = 0; + int i, in, isdf = 0, out; + char *cp, *cwd, *maildir, *dfolder = NULL; + char *ed = NULL, *file = NULL, *form = NULL; + char *folder = NULL, *msg = NULL, buf[BUFSIZ]; + char drft[BUFSIZ], **argp, **arguments; + struct msgs *mp = NULL; + struct stat st; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; - continue; - - case WHATSW: - if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; - continue; - case NWHATSW: - nwhat++; - continue; - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case USESW: - use++; - continue; - case NUSESW: - use = NOUSE; - continue; - - case FILESW: /* compatibility */ - if (file) - adios (NULL, "only one file at a time!"); - if (!(file = *argp++) || *file == '-') - adios (NULL, "missing argument to %s", argp[-2]); - isdf = NOTOK; - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (file) - adios (NULL, "only one draft message at a time!"); - if (!(file = *argp++) || *file == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - if (msg) - adios (NULL, "only one message at a time!"); - else - msg = cp; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nedit = 0; + continue; + case NEDITSW: + nedit++; + continue; + + case WHATSW: + if (!(whatnowproc = *argp++) || *whatnowproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nwhat = 0; + continue; + case NWHATSW: + nwhat++; + continue; + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case USESW: + use++; + continue; + case NUSESW: + use = NOUSE; + continue; + + case FILESW: /* compatibility */ + if (file) + adios (NULL, "only one file at a time!"); + if (!(file = *argp++) || *file == '-') + adios (NULL, "missing argument to %s", argp[-2]); + isdf = NOTOK; + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (file) + adios (NULL, "only one draft message at a time!"); + if (!(file = *argp++) || *file == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + if (msg) + adios (NULL, "only one message at a time!"); + else + msg = cp; + } } - } - - cwd = getcpy (pwd ()); - if (!context_find ("path")) - free (path ("./", TFOLDER)); + cwd = getcpy (pwd ()); - /* - * Check if we are using a draft folder - * and have specified a message in it. - */ - if ((dfolder || context_find ("Draft-Folder")) && !folder && msg && !file) { - file = msg; - msg = NULL; - } - if (form && (folder || msg)) - adios (NULL, "can't mix forms and folders/msgs"); + if (!context_find ("path")) + free (path ("./", TFOLDER)); - if (folder || msg) { /* - * Use a message as the "form" for the new message. + * Check if we are using a draft folder + * and have specified a message in it. */ - if (!msg) - msg = "cur"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse the message range/sequence/name and set SELECTED */ - if (!m_convert (mp, msg)) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - if (mp->numsel > 1) - adios (NULL, "only one message at a time!"); - - if ((in = open (form = getcpy (m_name (mp->lowsel)), O_RDONLY)) == NOTOK) - adios (form, "unable to open message"); - } else - in = open_form(&form, components); + if ((dfolder || context_find ("Draft-Folder")) && !folder && msg && !file) { + file = msg; + msg = NULL; + } + if (form && (folder || msg)) + adios (NULL, "can't mix forms and folders/msgs"); + + if (folder || msg) { + /* + * Use a message as the "form" for the new message. + */ + if (!msg) + msg = "cur"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse the message range/sequence/name and set SELECTED */ + if (!m_convert (mp, msg)) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (mp->numsel > 1) + adios (NULL, "only one message at a time!"); + + if ((in = open (form = getcpy (m_name (mp->lowsel)), O_RDONLY)) == NOTOK) + adios (form, "unable to open message"); + } else + in = open_form(&form, components); try_it_again: - strncpy (drft, m_draft (dfolder, file, use, &isdf), sizeof(drft)); - - /* - * Check if we have an existing draft - */ - if ((out = open (drft, O_RDONLY)) != NOTOK) { - i = fdcompare (in, out); - close (out); + strncpy (drft, m_draft (dfolder, file, use, &isdf), sizeof(drft)); /* - * If we have given -use flag, or if the - * draft is just the same as the components - * file, then no need to ask any questions. + * Check if we have an existing draft */ - if (use || i) - goto edit_it; - - if (stat (drft, &st) == NOTOK) - adios (drft, "unable to stat"); - printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); - for (i = LISTDSW; i != YESW;) { - if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul))) - done (1); - switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) { - case NOSW: - done (0); - case NEWSW: - file = NULL; - use = NOUSE; - goto try_it_again; - case YESW: - break; - case USELSW: - use++; - goto edit_it; - case LISTDSW: - showfile (++argp, drft); - break; - case REFILSW: - if (refile (++argp, drft) == 0) - i = YESW; - break; - default: - advise (NULL, "say what?"); - break; - } + if ((out = open (drft, O_RDONLY)) != NOTOK) { + i = fdcompare (in, out); + close (out); + + /* + * If we have given -use flag, or if the + * draft is just the same as the components + * file, then no need to ask any questions. + */ + if (use || i) + goto edit_it; + + if (stat (drft, &st) == NOTOK) + adios (drft, "unable to stat"); + printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); + for (i = LISTDSW; i != YESW;) { + if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul))) + done (1); + switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) { + case NOSW: + done (0); + case NEWSW: + file = NULL; + use = NOUSE; + goto try_it_again; + case YESW: + break; + case USELSW: + use++; + goto edit_it; + case LISTDSW: + showfile (++argp, drft); + break; + case REFILSW: + if (refile (++argp, drft) == 0) + i = YESW; + break; + default: + advise (NULL, "say what?"); + break; + } + } + } else { + if (use) + adios (drft, "unable to open"); } - } else { - if (use) - adios (drft, "unable to open"); - } - if ((out = creat (drft, m_gmprot ())) == NOTOK) - adios (drft, "unable to create"); - cpydata (in, out, form, drft); - close (in); - close (out); + if ((out = creat (drft, m_gmprot ())) == NOTOK) + adios (drft, "unable to create"); + cpydata (in, out, form, drft); + close (in); + close (out); edit_it: - context_save (); /* save the context file */ + context_save (); /* save the context file */ - if (nwhat) - done (0); - what_now (ed, nedit, use, drft, NULL, 0, NULLMP, NULL, 0, cwd); - done (1); - return 1; + if (nwhat) + done (0); + what_now (ed, nedit, use, drft, NULL, 0, NULLMP, NULL, 0, cwd); + done (1); + return 1; } diff --git a/uip/conflict.c b/uip/conflict.c index 07e77fc..b49c1cc 100644 --- a/uip/conflict.c +++ b/uip/conflict.c @@ -1,4 +1,3 @@ - /* * conflict.c -- check for conflicts in mail system * @@ -19,23 +18,23 @@ * maximum number of directories that can * be specified using -search switch. */ -#define NDIRS 100 +#define NDIRS 100 /* * Add space for group names, 100 at a time */ -#define NGRPS 100 +#define NGRPS 100 static struct swit switches[] = { -#define MAILSW 0 - { "mail name", 0 }, -#define SERCHSW 1 - { "search directory", 0 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } +#define MAILSW 0 + { "mail name", 0 }, +#define SERCHSW 1 + { "search directory", 0 }, +#define VERSIONSW 2 + { "version", 0 }, +#define HELPSW 3 + { "help", 0 }, + { NULL, 0 } }; static char *mail = NULL; @@ -62,322 +61,322 @@ void setup (void); int main (int argc, char **argv) { - int akp = 0, dp = 0; - char *cp, **argp, **arguments; - char buf[BUFSIZ], *akv[50]; + int akp = 0, dp = 0; + char *cp, **argp, **arguments; + char buf[BUFSIZ], *akv[50]; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] [aliasfiles ...]", - invo_name); - print_help (buf, switches, 0); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case MAILSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (mail) - adios (NULL, "mail to one address only"); - else - mail = cp; - continue; - - case SERCHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (dp >= NDIRS) - adios (NULL, "more than %d directories", NDIRS); - dirs[dp++] = cp; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* foil search of user profile/context */ + if (context_foil (NULL) == -1) + done (1); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] [aliasfiles ...]", + invo_name); + print_help (buf, switches, 0); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case MAILSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (mail) + adios (NULL, "mail to one address only"); + else + mail = cp; + continue; + + case SERCHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (dp >= NDIRS) + adios (NULL, "more than %d directories", NDIRS); + dirs[dp++] = cp; + continue; + } + } + akv[akp++] = cp; } - akv[akp++] = cp; - } - - if (akp == 0) - akv[akp++] = AliasFile; - if (!homehead) - init_pw (); - if (!mail) - out = stdout; - dirs[dp] = NULL; - - alias_files (akp, akv); - pwd_names (); - grp_names (); - grp_members (); - grp_ids (); -#ifdef UCI - ldr_names (); - ldr_ship (); -#endif /* UCI */ - maildrops (); - - done (0); - return 1; + + if (akp == 0) + akv[akp++] = AliasFile; + if (!homehead) + init_pw (); + if (!mail) + out = stdout; + dirs[dp] = NULL; + + alias_files (akp, akv); + pwd_names (); + grp_names (); + grp_members (); + grp_ids (); +#ifdef UCI + ldr_names (); + ldr_ship (); +#endif /* UCI */ + maildrops (); + + done (0); + return 1; } void alias_files (int akp, char **akv) { - register int i, err; + register int i, err; - for (i = 0; i < akp; i++) - if ((err = alias (akv[i])) != AK_OK) { - setup (); - fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (err)); - } - else - if (out && !mail) - fprintf (out, "alias file %s is ok\n", akv[i]); + for (i = 0; i < akp; i++) + if ((err = alias (akv[i])) != AK_OK) { + setup (); + fprintf (out, "aliasing error in %s - %s\n", akv[i], akerror (err)); + } + else + if (out && !mail) + fprintf (out, "alias file %s is ok\n", akv[i]); } void pwd_names (void) { - int hit = 0; - register struct home *hm, *lm; - - for (hm = homehead; hm; hm = hm->h_next) - for (lm = hm->h_next; lm; lm = lm->h_next) - if (strcmp (hm->h_name, lm->h_name) == 0) { - setup (); - fprintf (out, "duplicate user %s(uid=%d)\n", - lm->h_name, (int) lm->h_uid); - hit++; - } - - if (!hit && out && !mail) - fprintf (out, "no duplicate users\n"); + int hit = 0; + register struct home *hm, *lm; + + for (hm = homehead; hm; hm = hm->h_next) + for (lm = hm->h_next; lm; lm = lm->h_next) + if (strcmp (hm->h_name, lm->h_name) == 0) { + setup (); + fprintf (out, "duplicate user %s(uid=%d)\n", + lm->h_name, (int) lm->h_uid); + hit++; + } + + if (!hit && out && !mail) + fprintf (out, "no duplicate users\n"); } void grp_names (void) { - int numgroups, maxgroups; - int i, hit = 0; - char **grps; - struct group *gr; - - /* allocate space NGRPS at a time */ - numgroups = 0; - maxgroups = NGRPS; - grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps))); - - setgrent (); - while ((gr = getgrent ())) { - for (i = 0; i < numgroups; i++) - if (!strcmp (grps[i], gr->gr_name)) { - setup (); - fprintf (out, "duplicate group %s(gid=%d)\n", - gr->gr_name, (int) gr->gr_gid); - hit++; - break; - } - if (i >= numgroups) { - if (numgroups >= maxgroups) { - maxgroups += NGRPS; - grps = (char **) mh_xrealloc(grps, - (size_t) (maxgroups * sizeof(*grps))); - } - grps[numgroups++] = getcpy (gr->gr_name); + int numgroups, maxgroups; + int i, hit = 0; + char **grps; + struct group *gr; + + /* allocate space NGRPS at a time */ + numgroups = 0; + maxgroups = NGRPS; + grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps))); + + setgrent (); + while ((gr = getgrent ())) { + for (i = 0; i < numgroups; i++) + if (!strcmp (grps[i], gr->gr_name)) { + setup (); + fprintf (out, "duplicate group %s(gid=%d)\n", + gr->gr_name, (int) gr->gr_gid); + hit++; + break; + } + if (i >= numgroups) { + if (numgroups >= maxgroups) { + maxgroups += NGRPS; + grps = (char **) mh_xrealloc(grps, + (size_t) (maxgroups * sizeof(*grps))); + } + grps[numgroups++] = getcpy (gr->gr_name); + } } - } - endgrent (); + endgrent (); - for (i = 0; i < numgroups; i++) - free (grps[i]); - free (grps); + for (i = 0; i < numgroups; i++) + free (grps[i]); + free (grps); - if (!hit && out && !mail) - fprintf (out, "no duplicate groups\n"); + if (!hit && out && !mail) + fprintf (out, "no duplicate groups\n"); } void grp_members (void) { - register int hit = 0; - register char **cp, **dp; - register struct group *gr; - register struct home *hm; - - setgrent (); - while ((gr = getgrent ())) { - for (cp = gr->gr_mem; *cp; cp++) { - for (hm = homehead; hm; hm = hm->h_next) - if (!strcmp (*cp, hm->h_name)) - break; - if (hm == NULL) { - setup (); - fprintf (out, "group %s(gid=%d) has unknown member %s\n", - gr->gr_name, (int) gr->gr_gid, *cp); - hit++; - } else { - hm->h_ngrps++; - } - - for (dp = cp + 1; *dp; dp++) - if (strcmp (*cp, *dp) == 0) { - setup (); - fprintf (out, "group %s(gid=%d) has duplicate member %s\n", - gr->gr_name, (int) gr->gr_gid, *cp); - hit++; + register int hit = 0; + register char **cp, **dp; + register struct group *gr; + register struct home *hm; + + setgrent (); + while ((gr = getgrent ())) { + for (cp = gr->gr_mem; *cp; cp++) { + for (hm = homehead; hm; hm = hm->h_next) + if (!strcmp (*cp, hm->h_name)) + break; + if (hm == NULL) { + setup (); + fprintf (out, "group %s(gid=%d) has unknown member %s\n", + gr->gr_name, (int) gr->gr_gid, *cp); + hit++; + } else { + hm->h_ngrps++; + } + + for (dp = cp + 1; *dp; dp++) + if (strcmp (*cp, *dp) == 0) { + setup (); + fprintf (out, "group %s(gid=%d) has duplicate member %s\n", + gr->gr_name, (int) gr->gr_gid, *cp); + hit++; + } } } - } - endgrent (); - - for (hm = homehead; hm; hm = hm->h_next) - if (hm->h_ngrps > NGROUPS_MAX) { - setup (); - fprintf (out, "user %s is a member of %d groups (max %d)\n", - hm->h_name, hm->h_ngrps, NGROUPS_MAX); - hit++; - } + endgrent (); + + for (hm = homehead; hm; hm = hm->h_next) + if (hm->h_ngrps > NGROUPS_MAX) { + setup (); + fprintf (out, "user %s is a member of %d groups (max %d)\n", + hm->h_name, hm->h_ngrps, NGROUPS_MAX); + hit++; + } - if (!hit && out && !mail) - fprintf (out, "all group members accounted for\n"); + if (!hit && out && !mail) + fprintf (out, "all group members accounted for\n"); } void grp_ids (void) -{ /* -DRAND not implemented at most places */ - register int hit = 0; - register struct home *hm; - - for (hm = homehead; hm; hm = hm->h_next) - if (getgrgid (hm->h_gid) == NULL) { - setup (); - fprintf (out, "user %s(uid=%d) has unknown group-id %d\n", - hm->h_name, (int) hm->h_uid, (int) hm->h_gid); - hit++; - } +{ /* -DRAND not implemented at most places */ + register int hit = 0; + register struct home *hm; + + for (hm = homehead; hm; hm = hm->h_next) + if (getgrgid (hm->h_gid) == NULL) { + setup (); + fprintf (out, "user %s(uid=%d) has unknown group-id %d\n", + hm->h_name, (int) hm->h_uid, (int) hm->h_gid); + hit++; + } - if (!hit && out && !mail) - fprintf (out, "all group-id users accounted for\n"); + if (!hit && out && !mail) + fprintf (out, "all group-id users accounted for\n"); } void -maildrops (void) +maildrops (void) { - register int i; - - if (mmdfldir && *mmdfldir) - mdrop (mmdfldir); - if (uucpldir && *uucpldir) - mdrop (uucpldir); - for (i = 0; dirs[i]; i++) - mdrop (dirs[i]); + register int i; + + if (mmdfldir && *mmdfldir) + mdrop (mmdfldir); + if (uucpldir && *uucpldir) + mdrop (uucpldir); + for (i = 0; dirs[i]; i++) + mdrop (dirs[i]); } void mdrop(char *drop) { - register int hit = 0; - register struct dirent *dp; - register DIR *dd = opendir (drop); - - if (!dd) { - setup (); - fprintf (out, "unable to open maildrop area %s\n", drop); - return; - } - - while ((dp = readdir (dd))) - if (dp->d_name[0] != '.' && !check (dp->d_name)) { - setup (); - fprintf (out, - "there is a maildrop for the unknown user %s in %s\n", - dp->d_name, drop); - hit++; + register int hit = 0; + register struct dirent *dp; + register DIR *dd = opendir (drop); + + if (!dd) { + setup (); + fprintf (out, "unable to open maildrop area %s\n", drop); + return; } - closedir (dd); - if (!hit && out && !mail) - fprintf (out, "all maildrops accounted for in %s\n", drop); + while ((dp = readdir (dd))) + if (dp->d_name[0] != '.' && !check (dp->d_name)) { + setup (); + fprintf (out, + "there is a maildrop for the unknown user %s in %s\n", + dp->d_name, drop); + hit++; + } + + closedir (dd); + if (!hit && out && !mail) + fprintf (out, "all maildrops accounted for in %s\n", drop); } int check (char *s) { - register struct home *hm; + register struct home *hm; - for (hm = homehead; hm; hm = hm->h_next) - if (!strcmp (s, hm->h_name)) - return 1; - return 0; + for (hm = homehead; hm; hm = hm->h_next) + if (!strcmp (s, hm->h_name)) + return 1; + return 0; } void setup (void) { - int fd, pd[2]; - - if (out) - return; - - if (mail) { - if (pipe (pd) == NOTOK) - adios ("pipe", "unable to"); - - switch (fork ()) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - close (pd[1]); - if (pd[0] != 0) { - dup2 (pd[0], 0); - close (pd[0]); + int fd, pd[2]; + + if (out) + return; + + if (mail) { + if (pipe (pd) == NOTOK) + adios ("pipe", "unable to"); + + switch (fork ()) { + case NOTOK: + adios ("fork", "unable to"); + + case OK: + close (pd[1]); + if (pd[0] != 0) { + dup2 (pd[0], 0); + close (pd[0]); + } + if ((fd = open ("/dev/null", O_WRONLY)) != NOTOK) + if (fd != 1) { + dup2 (fd, 1); + close (fd); + } + execlp (mailproc, r1bindex (mailproc, '/'), + mail, "-subject", invo_name, NULL); + adios (mailproc, "unable to exec "); + + default: + close (pd[0]); + out = fdopen (pd[1], "w"); + fprintf (out, "%s: the following is suspicious\n\n", + invo_name); } - if ((fd = open ("/dev/null", O_WRONLY)) != NOTOK) - if (fd != 1) { - dup2 (fd, 1); - close (fd); - } - execlp (mailproc, r1bindex (mailproc, '/'), - mail, "-subject", invo_name, NULL); - adios (mailproc, "unable to exec "); - - default: - close (pd[0]); - out = fdopen (pd[1], "w"); - fprintf (out, "%s: the following is suspicious\n\n", - invo_name); } - } } #ifdef UCI @@ -387,11 +386,11 @@ setup (void) /* taken from */ -#define GLDRS "/admin/etc/GroupLeaders" +#define GLDRS "/admin/etc/GroupLeaders" struct grpldr { - char *gl_name; - char **gl_ldr; + char *gl_name; + char **gl_ldr; }; int setglent (), endglent (); @@ -400,7 +399,7 @@ struct grpldr *getglent (), *getglnam (); /* taken from the getglent() routines */ -#define MAXGLS 100 +#define MAXGLS 100 static FILE *glp = NULL; static char line[BUFSIZ+1]; @@ -409,139 +408,137 @@ static char *gl_ldr[MAXGLS + 1]; setglent() { - if (glp == NULL) - glp = fopen (GLDRS, "r"); - else - rewind (glp); + if (glp == NULL) + glp = fopen (GLDRS, "r"); + else + rewind (glp); - return (glp != NULL); + return (glp != NULL); } endglent() { - if (glp != NULL) { - fclose (glp); - glp = NULL; - } + if (glp != NULL) { + fclose (glp); + glp = NULL; + } - return 1; + return 1; } struct grpldr *getglent () { - register char *cp, - **q; - - if (glp == NULL && !setglent ()) - return NULL; - if ((cp = fgets (line, BUFSIZ, glp)) == NULL) - return NULL; - - grpldr.gl_name = cp; - grpldr.gl_ldr = q = gl_ldr; - - while (*cp) { - while (*cp && !isspace (*cp)) - cp++; - while (*cp && isspace (*cp)) - *cp++ = '\0'; - if (*cp == '\0') - break; - if (q < gl_ldr + MAXGLS) - *q++ = cp; - else - break; - } - *q = NULL; + register char *cp, + **q; + + if (glp == NULL && !setglent ()) + return NULL; + if ((cp = fgets (line, BUFSIZ, glp)) == NULL) + return NULL; + + grpldr.gl_name = cp; + grpldr.gl_ldr = q = gl_ldr; + + while (*cp) { + while (*cp && !isspace (*cp)) + cp++; + while (*cp && isspace (*cp)) + *cp++ = '\0'; + if (*cp == '\0') + break; + if (q < gl_ldr + MAXGLS) + *q++ = cp; + else + break; + } + *q = NULL; - return (&grpldr); + return (&grpldr); } struct grpldr *getglnam (name) char *name; { - register struct grpldr *gl = NULL; + register struct grpldr *gl = NULL; - setglent (); - while (gl = getglent ()) - if (strcmp (name, gl->gl_name) == 0) - break; - endglent (); + setglent (); + while (gl = getglent ()) + if (strcmp (name, gl->gl_name) == 0) + break; + endglent (); - return gl; + return gl; } ldr_names () { - register int gp, - hit = 0; - char *gldrs[NGRPS]; - register struct grpldr *gl; - - gldrs[0] = NULL; - setglent (); - while (gl = getglent ()) { - if (getgrnam (gl->gl_name) == NULL) { - setup (); - fprintf (out, "unknown group %s in group leaders file\n", - gl->gl_name); - hit++; + register int gp, hit = 0; + char *gldrs[NGRPS]; + register struct grpldr *gl; + + gldrs[0] = NULL; + setglent (); + while (gl = getglent ()) { + if (getgrnam (gl->gl_name) == NULL) { + setup (); + fprintf (out, "unknown group %s in group leaders file\n", + gl->gl_name); + hit++; + } + for (gp = 0; gldrs[gp]; gp++) + if (strcmp (gldrs[gp], gl->gl_name) == 0) { + setup (); + fprintf (out, "duplicate group %s in group leaders file\n", + gl->gl_name); + hit++; + break; + } + if (gldrs[gp] == NULL) + if (gp < NGRPS) { + gldrs[gp++] = getcpy (gl->gl_name); + gldrs[gp] = NULL; + } + else { + setup (); + fprintf (out, "more than %d groups in group leaders file%s\n", + " (time to recompile)", NGRPS - 1); + hit++; + } } + endglent (); + for (gp = 0; gldrs[gp]; gp++) - if (strcmp (gldrs[gp], gl->gl_name) == 0) { - setup (); - fprintf (out, "duplicate group %s in group leaders file\n", - gl->gl_name); - hit++; - break; - } - if (gldrs[gp] == NULL) - if (gp < NGRPS) { - gldrs[gp++] = getcpy (gl->gl_name); - gldrs[gp] = NULL; - } - else { - setup (); - fprintf (out, "more than %d groups in group leaders file%s\n", - " (time to recompile)", NGRPS - 1); - hit++; - } - } - endglent (); - - for (gp = 0; gldrs[gp]; gp++) - free (gldrs[gp]); - - if (!hit && out && !mail) - fprintf (out, "all groups in group leaders file accounted for\n"); + free (gldrs[gp]); + + if (!hit && out && !mail) + fprintf (out, "all groups in group leaders file accounted for\n"); } ldr_ship () { - register int hit = 0; - register char **cp, - **dp; - register struct grpldr *gl; - - setglent (); - while (gl = getglent ()) - for (cp = gl->gl_ldr; *cp; cp++) { - if (!check (*cp)) { - setup (); - fprintf (out, "group %s has unknown leader %s\n", - gl->gl_name, *cp); - hit++; - } - - for (dp = cp + 1; *dp; dp++) - if (strcmp (*cp, *dp) == 0) { - setup (); - fprintf (out, "group %s had duplicate leader %s\n", - gl->gl_name, *cp); - hit++; + register int hit = 0; + register char **cp, **dp; + register struct grpldr *gl; + + setglent (); + while (gl = getglent ()) + for (cp = gl->gl_ldr; *cp; cp++) { + if (!check (*cp)) { + setup (); + fprintf (out, "group %s has unknown leader %s\n", + gl->gl_name, *cp); + hit++; + } + + for (dp = cp + 1; *dp; dp++) + if (strcmp (*cp, *dp) == 0) { + setup (); + fprintf (out, "group %s had duplicate leader %s\n", + gl->gl_name, *cp); + hit++; + } } - } - endglent (); + endglent (); - if (!hit && out && !mail) - fprintf (out, "all group leaders accounted for\n"); + if (!hit && out && !mail) + fprintf (out, "all group leaders accounted for\n"); } -#endif /* UCI */ +#endif /* UCI */ diff --git a/uip/dist.c b/uip/dist.c index 4bad51a..10ef995 100644 --- a/uip/dist.c +++ b/uip/dist.c @@ -1,4 +1,3 @@ - /* * dist.c -- re-distribute a message * @@ -12,277 +11,277 @@ #include static struct swit switches[] = { -#define ANNOSW 0 - { "annotate", 0 }, -#define NANNOSW 1 - { "noannotate", 0 }, -#define DFOLDSW 2 - { "draftfolder +folder", 0 }, -#define DMSGSW 3 - { "draftmessage msg", 0 }, -#define NDFLDSW 4 - { "nodraftfolder", 0 }, -#define EDITRSW 5 - { "editor editor", 0 }, -#define NEDITSW 6 - { "noedit", 0 }, -#define FORMSW 7 - { "form formfile", 0 }, -#define INPLSW 8 - { "inplace", 0 }, -#define NINPLSW 9 - { "noinplace", 0 }, -#define WHATSW 10 - { "whatnowproc program", 0 }, -#define NWHATSW 11 - { "nowhatnowproc", 0 }, -#define VERSIONSW 12 - { "version", 0 }, -#define HELPSW 13 - { "help", 0 }, -#define FILESW 14 - { "file file", -4 }, /* interface from msh */ - { NULL, 0 } +#define ANNOSW 0 + { "annotate", 0 }, +#define NANNOSW 1 + { "noannotate", 0 }, +#define DFOLDSW 2 + { "draftfolder +folder", 0 }, +#define DMSGSW 3 + { "draftmessage msg", 0 }, +#define NDFLDSW 4 + { "nodraftfolder", 0 }, +#define EDITRSW 5 + { "editor editor", 0 }, +#define NEDITSW 6 + { "noedit", 0 }, +#define FORMSW 7 + { "form formfile", 0 }, +#define INPLSW 8 + { "inplace", 0 }, +#define NINPLSW 9 + { "noinplace", 0 }, +#define WHATSW 10 + { "whatnowproc program", 0 }, +#define NWHATSW 11 + { "nowhatnowproc", 0 }, +#define VERSIONSW 12 + { "version", 0 }, +#define HELPSW 13 + { "help", 0 }, +#define FILESW 14 + { "file file", -4 }, /* interface from msh */ + { NULL, 0 } }; static struct swit aqrnl[] = { -#define NOSW 0 - { "quit", 0 }, -#define YESW 1 - { "replace", 0 }, -#define LISTDSW 2 - { "list", 0 }, -#define REFILSW 3 - { "refile +folder", 0 }, -#define NEWSW 4 - { "new", 0 }, - { NULL, 0 } +#define NOSW 0 + { "quit", 0 }, +#define YESW 1 + { "replace", 0 }, +#define LISTDSW 2 + { "list", 0 }, +#define REFILSW 3 + { "refile +folder", 0 }, +#define NEWSW 4 + { "new", 0 }, + { NULL, 0 } }; static struct swit aqrl[] = { - { "quit", 0 }, - { "replace", 0 }, - { "list", 0 }, - { "refile +folder", 0 }, - { NULL, 0 } + { "quit", 0 }, + { "replace", 0 }, + { "list", 0 }, + { "refile +folder", 0 }, + { NULL, 0 } }; int main (int argc, char **argv) { - int anot = 0, inplace = 1, nedit = 0; - int nwhat = 0, i, in, isdf = 0, out; - char *cp, *cwd, *maildir, *msgnam, *dfolder = NULL; - char *dmsg = NULL, *ed = NULL, *file = NULL, *folder = NULL; - char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ]; - char **argp, **arguments; - struct msgs *mp = NULL; - struct stat st; + int anot = 0, inplace = 1, nedit = 0; + int nwhat = 0, i, in, isdf = 0, out; + char *cp, *cwd, *maildir, *msgnam, *dfolder = NULL; + char *dmsg = NULL, *ed = NULL, *file = NULL, *folder = NULL; + char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ]; + char **argp, **arguments; + struct msgs *mp = NULL; + struct stat st; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ANNOSW: - anot++; - continue; - case NANNOSW: - anot = 0; - continue; - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; - continue; - - case WHATSW: - if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; - continue; - case NWHATSW: - nwhat++; - continue; - - case FILESW: - if (file) - adios (NULL, "only one file at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - if (msg) - adios (NULL, "only one message at a time!"); - else - msg = cp; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ANNOSW: + anot++; + continue; + case NANNOSW: + anot = 0; + continue; + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nedit = 0; + continue; + case NEDITSW: + nedit++; + continue; + + case WHATSW: + if (!(whatnowproc = *argp++) || *whatnowproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nwhat = 0; + continue; + case NWHATSW: + nwhat++; + continue; + + case FILESW: + if (file) + adios (NULL, "only one file at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + file = path (cp, TFILE); + continue; + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case INPLSW: + inplace++; + continue; + case NINPLSW: + inplace = 0; + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (dmsg) + adios (NULL, "only one draft message at a time!"); + if (!(dmsg = *argp++) || *dmsg == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + if (msg) + adios (NULL, "only one message at a time!"); + else + msg = cp; + } } - } - cwd = getcpy (pwd ()); + cwd = getcpy (pwd ()); - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (file && (msg || folder)) - adios (NULL, "can't mix files and folders/msgs"); + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (file && (msg || folder)) + adios (NULL, "can't mix files and folders/msgs"); - in = open_form(&form, distcomps); + in = open_form(&form, distcomps); try_it_again: - strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); - - /* Check if draft already exists */ - if (stat (drft, &st) != NOTOK) { - printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); - for (i = LISTDSW; i != YESW;) { - if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) - done (1); - switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { - case NOSW: - done (0); - case NEWSW: - dmsg = NULL; - goto try_it_again; - case YESW: - break; - case LISTDSW: - showfile (++argp, drft); - break; - case REFILSW: - if (refile (++argp, drft) == 0) - i = YESW; - break; - default: - advise (NULL, "say what?"); - break; - } + strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); + + /* Check if draft already exists */ + if (stat (drft, &st) != NOTOK) { + printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); + for (i = LISTDSW; i != YESW;) { + if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) + done (1); + switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { + case NOSW: + done (0); + case NEWSW: + dmsg = NULL; + goto try_it_again; + case YESW: + break; + case LISTDSW: + showfile (++argp, drft); + break; + case REFILSW: + if (refile (++argp, drft) == 0) + i = YESW; + break; + default: + advise (NULL, "say what?"); + break; + } + } + } + if ((out = creat (drft, m_gmprot ())) == NOTOK) + adios (drft, "unable to create"); + + cpydata (in, out, form, drft); + close (in); + close (out); + + if (file) { + /* + * Dist a file + */ + anot = 0; /* don't want to annotate a file */ + } else { + /* + * Dist a message + */ + if (!msg) + msg = "cur"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse the message range/sequence/name and set SELECTED */ + if (!m_convert (mp, msg)) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (mp->numsel > 1) + adios (NULL, "only one message at a time!"); } - } - if ((out = creat (drft, m_gmprot ())) == NOTOK) - adios (drft, "unable to create"); - - cpydata (in, out, form, drft); - close (in); - close (out); - - if (file) { - /* - * Dist a file - */ - anot = 0; /* don't want to annotate a file */ - } else { - /* - * Dist a message - */ - if (!msg) - msg = "cur"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse the message range/sequence/name and set SELECTED */ - if (!m_convert (mp, msg)) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - if (mp->numsel > 1) - adios (NULL, "only one message at a time!"); - } - - msgnam = file ? file : getcpy (m_name (mp->lowsel)); - if ((in = open (msgnam, O_RDONLY)) == NOTOK) - adios (msgnam, "unable to open message"); - - if (!file) { - context_replace (pfolder, folder);/* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - if (nwhat) - done (0); - what_now (ed, nedit, NOUSE, drft, msgnam, 1, mp, - anot ? "Resent" : NULL, inplace, cwd); - done (1); - return 1; + + msgnam = file ? file : getcpy (m_name (mp->lowsel)); + if ((in = open (msgnam, O_RDONLY)) == NOTOK) + adios (msgnam, "unable to open message"); + + if (!file) { + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->lowsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ + } + + if (nwhat) + done (0); + what_now (ed, nedit, NOUSE, drft, msgnam, 1, mp, + anot ? "Resent" : NULL, inplace, cwd); + done (1); + return 1; } diff --git a/uip/distsbr.c b/uip/distsbr.c index afd4e41..a40d3e4 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -1,4 +1,3 @@ - /* * distsbr.c -- routines to do additional "dist-style" processing * @@ -14,10 +13,10 @@ static int hdrfd = NOTOK; static int txtfd = NOTOK; -#define BADHDR "please re-edit %s to remove the ``%s'' header!" -#define BADTXT "please re-edit %s to consist of headers only!" -#define BADMSG "please re-edit %s to include a ``Resent-To:''!" -#define BADRFT "please re-edit %s and fix that header!" +#define BADHDR "please re-edit %s to remove the ``%s'' header!" +#define BADTXT "please re-edit %s to consist of headers only!" +#define BADMSG "please re-edit %s to include a ``Resent-To:''!" +#define BADRFT "please re-edit %s and fix that header!" /* * static prototypes @@ -27,179 +26,179 @@ static void ready_msg(char *); int distout (char *drft, char *msgnam, char *backup) { - int state; - register unsigned char *dp; - register char *resent; - char name[NAMESZ], buffer[BUFSIZ]; - register FILE *ifp, *ofp; - - if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK) - adios (backup, "unable to rename %s to",drft); - if ((ifp = fopen (backup, "r")) == NULL) - adios (backup, "unable to read"); - - if ((ofp = fopen (drft, "w")) == NULL) - adios (drft, "unable to create temporary file"); - chmod (drft, m_gmprot ()); - - ready_msg (msgnam); - lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ - cpydata (hdrfd, fileno (ofp), msgnam, drft); - - for (state = FLD, resent = NULL;;) - switch (state = - m_getfld (state, name, buffer, sizeof buffer, ifp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - if (uprf (name, "distribute-")) - snprintf (name, sizeof(name), "%s%s", "Resent", &name[10]); - if (uprf (name, "distribution-")) - snprintf (name, sizeof(name), "%s%s", "Resent", &name[12]); - if (!uprf (name, "resent")) { - advise (NULL, BADHDR, "draft", name); - goto leave_bad; - } - if (state == FLD) - resent = add (":", add (name, resent)); - resent = add (buffer, resent); - fprintf (ofp, "%s: %s", name, buffer); - while (state == FLDPLUS) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); - resent = add (buffer, resent); - fputs (buffer, ofp); + int state; + register unsigned char *dp; + register char *resent; + char name[NAMESZ], buffer[BUFSIZ]; + register FILE *ifp, *ofp; + + if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK) + adios (backup, "unable to rename %s to",drft); + if ((ifp = fopen (backup, "r")) == NULL) + adios (backup, "unable to read"); + + if ((ofp = fopen (drft, "w")) == NULL) + adios (drft, "unable to create temporary file"); + chmod (drft, m_gmprot ()); + + ready_msg (msgnam); + lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ + cpydata (hdrfd, fileno (ofp), msgnam, drft); + + for (state = FLD, resent = NULL;;) + switch (state = + m_getfld (state, name, buffer, sizeof buffer, ifp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + if (uprf (name, "distribute-")) + snprintf (name, sizeof(name), "%s%s", "Resent", &name[10]); + if (uprf (name, "distribution-")) + snprintf (name, sizeof(name), "%s%s", "Resent", &name[12]); + if (!uprf (name, "resent")) { + advise (NULL, BADHDR, "draft", name); + goto leave_bad; + } + if (state == FLD) + resent = add (":", add (name, resent)); + resent = add (buffer, resent); + fprintf (ofp, "%s: %s", name, buffer); + while (state == FLDPLUS) { + state = m_getfld (state, name, + buffer, sizeof buffer, ifp); + resent = add (buffer, resent); + fputs (buffer, ofp); + } + if (state == FLDEOF) + goto process; + break; + + case BODY: + case BODYEOF: + for (dp = buffer; *dp; dp++) + if (!isspace (*dp)) { + advise (NULL, BADTXT, "draft"); + goto leave_bad; + } + + case FILEEOF: + goto process; + + case LENERR: + case FMTERR: + advise (NULL, BADRFT, "draft"); + leave_bad: ; + fclose (ifp); + fclose (ofp); + unlink (drft); + if (rename (backup, drft) == NOTOK) + adios (drft, "unable to rename %s to", backup); + return NOTOK; + + default: + adios (NULL, "getfld() returned %d", state); } - if (state == FLDEOF) - goto process; - break; - - case BODY: - case BODYEOF: - for (dp = buffer; *dp; dp++) - if (!isspace (*dp)) { - advise (NULL, BADTXT, "draft"); - goto leave_bad; - } - - case FILEEOF: - goto process; - - case LENERR: - case FMTERR: - advise (NULL, BADRFT, "draft"); - leave_bad: ; - fclose (ifp); +process: ; + fclose (ifp); + fflush (ofp); + + if (!resent) { + advise (NULL, BADMSG, "draft"); fclose (ofp); unlink (drft); if (rename (backup, drft) == NOTOK) - adios (drft, "unable to rename %s to", backup); + adios (drft, "unable to rename %s to", backup); return NOTOK; + } + free (resent); - default: - adios (NULL, "getfld() returned %d", state); + if (txtfd != NOTOK) { + lseek (txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ + cpydata (txtfd, fileno (ofp), msgnam, drft); } -process: ; - fclose (ifp); - fflush (ofp); - if (!resent) { - advise (NULL, BADMSG, "draft"); fclose (ofp); - unlink (drft); - if (rename (backup, drft) == NOTOK) - adios (drft, "unable to rename %s to", backup); - return NOTOK; - } - free (resent); - - if (txtfd != NOTOK) { - lseek (txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ - cpydata (txtfd, fileno (ofp), msgnam, drft); - } - fclose (ofp); - - return OK; + return OK; } static void ready_msg (char *msgnam) { - int state, out; - char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ]; - register FILE *ifp, *ofp; - char *cp = NULL; - - if (hdrfd != NOTOK) - close (hdrfd), hdrfd = NOTOK; - if (txtfd != NOTOK) - close (txtfd), txtfd = NOTOK; - - if ((ifp = fopen (msgnam, "r")) == NULL) - adios (msgnam, "unable to open message"); - - cp = m_mktemp2(NULL, "dist", &hdrfd, NULL); - if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); - } - fchmod(hdrfd, 0600); - strncpy(tmpfil, cp, sizeof(tmpfil)); - if ((out = dup (hdrfd)) == NOTOK - || (ofp = fdopen (out, "w")) == NULL) - adios (NULL, "no file descriptors -- you lose big"); - unlink (tmpfil); - - for (state = FLD;;) - switch (state = - m_getfld (state, name, buffer, sizeof buffer, ifp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - if (uprf (name, "resent")) - fprintf (ofp, "Prev-"); - fprintf (ofp, "%s: %s", name, buffer); - while (state == FLDPLUS) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); - fputs (buffer, ofp); - } - if (state == FLDEOF) - goto process; - break; - - case BODY: - case BODYEOF: - fclose (ofp); - - cp = m_mktemp2(NULL, "dist", &txtfd, NULL); - if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); - } - fchmod(txtfd, 0600); - strncpy (tmpfil, cp, sizeof(tmpfil)); - if ((out = dup (txtfd)) == NOTOK + int state, out; + char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ]; + register FILE *ifp, *ofp; + char *cp = NULL; + + if (hdrfd != NOTOK) + close (hdrfd), hdrfd = NOTOK; + if (txtfd != NOTOK) + close (txtfd), txtfd = NOTOK; + + if ((ifp = fopen (msgnam, "r")) == NULL) + adios (msgnam, "unable to open message"); + + cp = m_mktemp2(NULL, "dist", &hdrfd, NULL); + if (cp == NULL) { + adios("distsbr", "unable to create temporary file"); + } + fchmod(hdrfd, 0600); + strncpy(tmpfil, cp, sizeof(tmpfil)); + if ((out = dup (hdrfd)) == NOTOK || (ofp = fdopen (out, "w")) == NULL) - adios (NULL, "no file descriptors -- you lose big"); - unlink (tmpfil); - fprintf (ofp, "\n%s", buffer); - while (state == BODY) { - state = m_getfld (state, name, - buffer, sizeof buffer, ifp); - fputs (buffer, ofp); + adios (NULL, "no file descriptors -- you lose big"); + unlink (tmpfil); + + for (state = FLD;;) + switch (state = + m_getfld (state, name, buffer, sizeof buffer, ifp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + if (uprf (name, "resent")) + fprintf (ofp, "Prev-"); + fprintf (ofp, "%s: %s", name, buffer); + while (state == FLDPLUS) { + state = m_getfld (state, name, + buffer, sizeof buffer, ifp); + fputs (buffer, ofp); + } + if (state == FLDEOF) + goto process; + break; + + case BODY: + case BODYEOF: + fclose (ofp); + + cp = m_mktemp2(NULL, "dist", &txtfd, NULL); + if (cp == NULL) { + adios("distsbr", "unable to create temporary file"); + } + fchmod(txtfd, 0600); + strncpy (tmpfil, cp, sizeof(tmpfil)); + if ((out = dup (txtfd)) == NOTOK + || (ofp = fdopen (out, "w")) == NULL) + adios (NULL, "no file descriptors -- you lose big"); + unlink (tmpfil); + fprintf (ofp, "\n%s", buffer); + while (state == BODY) { + state = m_getfld (state, name, + buffer, sizeof buffer, ifp); + fputs (buffer, ofp); + } + case FILEEOF: + goto process; + + case LENERR: + case FMTERR: + adios (NULL, "format error in message %s", msgnam); + + default: + adios (NULL, "getfld() returned %d", state); } - case FILEEOF: - goto process; - - case LENERR: - case FMTERR: - adios (NULL, "format error in message %s", msgnam); - - default: - adios (NULL, "getfld() returned %d", state); - } process: ; - fclose (ifp); - fclose (ofp); + fclose (ifp); + fclose (ofp); } diff --git a/uip/dp.c b/uip/dp.c index c94c8ea..0db0ba5 100644 --- a/uip/dp.c +++ b/uip/dp.c @@ -1,4 +1,3 @@ - /* * dp.c -- parse dates 822-style * @@ -11,25 +10,25 @@ #include #include -#define NDATES 100 +#define NDATES 100 -#define WIDTH 78 -#define WBUFSIZ BUFSIZ +#define WIDTH 78 +#define WBUFSIZ BUFSIZ -#define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>" +#define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>" static struct swit switches[] = { -#define FORMSW 0 - { "form formatfile", 0 }, -#define FMTSW 1 - { "format string", 5 }, -#define WIDTHSW 2 - { "width columns", 0 }, -#define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, - { NULL, 0 } +#define FORMSW 0 + { "form formatfile", 0 }, +#define FMTSW 1 + { "format string", 5 }, +#define WIDTHSW 2 + { "width columns", 0 }, +#define VERSIONSW 3 + { "version", 0 }, +#define HELPSW 4 + { "help", 0 }, + { NULL, 0 } }; static struct format *fmt; @@ -50,107 +49,107 @@ static int process (char *, int); int main (int argc, char **argv) { - int datep = 0, width = 0, status = 0; - char *cp, *form = NULL, *format = NULL, *nfs; - char buf[BUFSIZ], **argp, **arguments; - char *dates[NDATES]; + int datep = 0, width = 0, status = 0; + char *cp, *form = NULL, *format = NULL, *nfs; + char buf[BUFSIZ], **argp, **arguments; + char *dates[NDATES]; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] dates ...", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - width = atoi (cp); - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] dates ...", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + width = atoi (cp); + continue; + } + } + if (datep > NDATES) + adios (NULL, "more than %d dates", NDATES); + else + dates[datep++] = cp; + } + dates[datep] = NULL; + + if (datep == 0) + adios (NULL, "usage: %s [switches] dates ...", invo_name); + + /* get new format string */ + nfs = new_fs (form, format, FORMAT); + + if (width == 0) { + if ((width = sc_width ()) < WIDTH / 2) + width = WIDTH / 2; + width -= 2; } - if (datep > NDATES) - adios (NULL, "more than %d dates", NDATES); - else - dates[datep++] = cp; - } - dates[datep] = NULL; - - if (datep == 0) - adios (NULL, "usage: %s [switches] dates ...", invo_name); - - /* get new format string */ - nfs = new_fs (form, format, FORMAT); - - if (width == 0) { - if ((width = sc_width ()) < WIDTH / 2) - width = WIDTH / 2; - width -= 2; - } - if (width > WBUFSIZ) - width = WBUFSIZ; - fmt_compile (nfs, &fmt); - - dat[0] = 0; - dat[1] = 0; - dat[2] = 0; - dat[3] = width; - dat[4] = 0; - - for (datep = 0; dates[datep]; datep++) - status += process (dates[datep], width); - - context_save (); /* save the context file */ - done (status); - return 1; + if (width > WBUFSIZ) + width = WBUFSIZ; + fmt_compile (nfs, &fmt); + + dat[0] = 0; + dat[1] = 0; + dat[2] = 0; + dat[3] = width; + dat[4] = 0; + + for (datep = 0; dates[datep]; datep++) + status += process (dates[datep], width); + + context_save (); /* save the context file */ + done (status); + return 1; } static int process (char *date, int length) { - int status = 0; - char buffer[WBUFSIZ + 1]; - register struct comp *cptr; + int status = 0; + char buffer[WBUFSIZ + 1]; + register struct comp *cptr; - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = date; - fmt_scan (fmt, buffer, length, dat); - fputs (buffer, stdout); + FINDCOMP (cptr, "text"); + if (cptr) + cptr->c_text = date; + fmt_scan (fmt, buffer, length, dat); + fputs (buffer, stdout); - return status; + return status; } diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 76bc00d..0e3ce19 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -1,4 +1,3 @@ - /* * dropsbr.c -- create/read/manipulate mail drops * @@ -44,80 +43,80 @@ static int map_open (char *, int); int mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) { - int j, count, fd; - struct stat st; + int j, count, fd; + struct stat st; - j = 0; + j = 0; - /* attempt to open and lock file */ - for (count = 4; count > 0; count--) { - if ((fd = lkopen (file, O_RDWR | O_CREAT | O_NONBLOCK, mode)) == NOTOK) { - switch (errno) { + /* attempt to open and lock file */ + for (count = 4; count > 0; count--) { + if ((fd = lkopen (file, O_RDWR | O_CREAT | O_NONBLOCK, mode)) == NOTOK) { + switch (errno) { #if defined(FCNTL_LOCKING) || defined(LOCKF_LOCKING) - case EACCES: - case EAGAIN: + case EACCES: + case EAGAIN: #endif #ifdef FLOCK_LOCKING - case EWOULDBLOCK: + case EWOULDBLOCK: #endif - case ETXTBSY: - j = errno; - sleep (5); - break; - - default: - /* just return error */ - return NOTOK; - } - } - - /* good file descriptor */ - break; - } + case ETXTBSY: + j = errno; + sleep (5); + break; + + default: + /* just return error */ + return NOTOK; + } + } - errno = j; + /* good file descriptor */ + break; + } - /* - * Return if we still failed after 4 attempts, - * or we just want to skip the sanity checks. - */ - if (fd == NOTOK || mbx_style == OTHER_FORMAT) - return fd; + errno = j; - /* - * Do sanity checks on maildrop. - */ - if (fstat (fd, &st) == NOTOK) { /* - * The stat failed. So we make sure file - * has right ownership/modes + * Return if we still failed after 4 attempts, + * or we just want to skip the sanity checks. */ - chown (file, uid, gid); - chmod (file, mode); - } else if (st.st_size > (off_t) 0) { - int status; - - /* check the maildrop */ - switch (mbx_style) { - case MMDF_FORMAT: - default: - status = mbx_chk_mmdf (fd); - break; + if (fd == NOTOK || mbx_style == OTHER_FORMAT) + return fd; - case MBOX_FORMAT: - status = mbx_chk_mbox (fd); - break; - } + /* + * Do sanity checks on maildrop. + */ + if (fstat (fd, &st) == NOTOK) { + /* + * The stat failed. So we make sure file + * has right ownership/modes + */ + chown (file, uid, gid); + chmod (file, mode); + } else if (st.st_size > (off_t) 0) { + int status; + + /* check the maildrop */ + switch (mbx_style) { + case MMDF_FORMAT: + default: + status = mbx_chk_mmdf (fd); + break; + + case MBOX_FORMAT: + status = mbx_chk_mbox (fd); + break; + } - /* if error, attempt to close it */ - if (status == NOTOK) { - close (fd); - return NOTOK; + /* if error, attempt to close it */ + if (status == NOTOK) { + close (fd); + return NOTOK; + } } - } - return fd; + return fd; } @@ -128,11 +127,11 @@ mbx_open (char *file, int mbx_style, uid_t uid, gid_t gid, mode_t mode) static int mbx_chk_mbox (int fd) { - /* just seek to the end */ - if (lseek (fd, (off_t) 0, SEEK_END) == (off_t) NOTOK) - return NOTOK; + /* just seek to the end */ + if (lseek (fd, (off_t) 0, SEEK_END) == (off_t) NOTOK) + return NOTOK; - return OK; + return OK; } @@ -143,135 +142,135 @@ mbx_chk_mbox (int fd) static int mbx_chk_mmdf (int fd) { - size_t count; - char ldelim[BUFSIZ]; + size_t count; + char ldelim[BUFSIZ]; - count = strlen (mmdlm2); + count = strlen (mmdlm2); - /* casting -count to off_t, seem to break FreeBSD 2.2.6 */ - if (lseek (fd, (long) (-count), SEEK_END) == (off_t) NOTOK) - return NOTOK; - if (read (fd, ldelim, count) != count) - return NOTOK; + /* casting -count to off_t, seem to break FreeBSD 2.2.6 */ + if (lseek (fd, (long) (-count), SEEK_END) == (off_t) NOTOK) + return NOTOK; + if (read (fd, ldelim, count) != count) + return NOTOK; - ldelim[count] = 0; + ldelim[count] = 0; - if (strcmp (ldelim, mmdlm2) - && write (fd, "\n", 1) != 1 - && write (fd, mmdlm2, count) != count) - return NOTOK; + if (strcmp (ldelim, mmdlm2) + && write (fd, "\n", 1) != 1 + && write (fd, mmdlm2, count) != count) + return NOTOK; - return OK; + return OK; } int mbx_read (FILE *fp, long pos, struct drop **drops, int noisy) { - register int len, size; - register long ld1, ld2; - register char *bp; - char buffer[BUFSIZ]; - register struct drop *cp, *dp, *ep, *pp; - - pp = (struct drop *) calloc ((size_t) (len = MAXFOLDER), sizeof(*dp)); - if (pp == NULL) { - if (noisy) - admonish (NULL, "unable to allocate drop storage"); - return NOTOK; - } - - ld1 = (long) strlen (mmdlm1); - ld2 = (long) strlen (mmdlm2); - - fseek (fp, pos, SEEK_SET); - for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof(buffer), fp);) { - size = 0; - if (strcmp (buffer, mmdlm1) == 0) - pos += ld1, dp->d_start = (long) pos; - else { - dp->d_start = (long)pos , pos += (long) strlen (buffer); - for (bp = buffer; *bp; bp++, size++) - if (*bp == '\n') - size++; + register int len, size; + register long ld1, ld2; + register char *bp; + char buffer[BUFSIZ]; + register struct drop *cp, *dp, *ep, *pp; + + pp = (struct drop *) calloc ((size_t) (len = MAXFOLDER), sizeof(*dp)); + if (pp == NULL) { + if (noisy) + admonish (NULL, "unable to allocate drop storage"); + return NOTOK; } - while (fgets (buffer, sizeof(buffer), fp) != NULL) - if (strcmp (buffer, mmdlm2) == 0) - break; - else { - pos += (long) strlen (buffer); - for (bp = buffer; *bp; bp++, size++) - if (*bp == '\n') - size++; - } - - if (dp->d_start != (long) pos) { - dp->d_id = 0; - dp->d_size = (long) size; - dp->d_stop = pos; - dp++; - } - pos += ld2; + ld1 = (long) strlen (mmdlm1); + ld2 = (long) strlen (mmdlm2); + + fseek (fp, pos, SEEK_SET); + for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof(buffer), fp);) { + size = 0; + if (strcmp (buffer, mmdlm1) == 0) + pos += ld1, dp->d_start = (long) pos; + else { + dp->d_start = (long)pos , pos += (long) strlen (buffer); + for (bp = buffer; *bp; bp++, size++) + if (*bp == '\n') + size++; + } + + while (fgets (buffer, sizeof(buffer), fp) != NULL) + if (strcmp (buffer, mmdlm2) == 0) + break; + else { + pos += (long) strlen (buffer); + for (bp = buffer; *bp; bp++, size++) + if (*bp == '\n') + size++; + } + + if (dp->d_start != (long) pos) { + dp->d_id = 0; + dp->d_size = (long) size; + dp->d_stop = pos; + dp++; + } + pos += ld2; - if (dp >= ep) { - register int curlen = dp - pp; + if (dp >= ep) { + register int curlen = dp - pp; - cp = (struct drop *) mh_xrealloc ((char *) pp, - (size_t) (len += MAXFOLDER) * sizeof(*pp)); - dp = cp + curlen, ep = (pp = cp) + len - 1; + cp = (struct drop *) mh_xrealloc ((char *) pp, + (size_t) (len += MAXFOLDER) * sizeof(*pp)); + dp = cp + curlen, ep = (pp = cp) + len - 1; + } } - } - if (dp == pp) - free ((char *) pp); - else - *drops = pp; - return (dp - pp); + if (dp == pp) + free ((char *) pp); + else + *drops = pp; + return (dp - pp); } int mbx_write(char *mailbox, int md, FILE *fp, int id, long last, - long pos, off_t stop, int mapping, int noisy) + long pos, off_t stop, int mapping, int noisy) { - register int i, j, size; - off_t start; - long off; - register char *cp; - char buffer[BUFSIZ]; - - off = (long) lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm1); - if (write (md, mmdlm1, j) != j) - return NOTOK; - start = lseek (md, (off_t) 0, SEEK_CUR); - size = 0; - - fseek (fp, pos, SEEK_SET); - while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) { - i = strlen (buffer); - for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++) - continue; - for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++) - continue; - if (write (md, buffer, i) != i) - return NOTOK; - pos += (long) i; + register int i, j, size; + off_t start; + long off; + register char *cp; + char buffer[BUFSIZ]; + + off = (long) lseek (md, (off_t) 0, SEEK_CUR); + j = strlen (mmdlm1); + if (write (md, mmdlm1, j) != j) + return NOTOK; + start = lseek (md, (off_t) 0, SEEK_CUR); + size = 0; + + fseek (fp, pos, SEEK_SET); + while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) { + i = strlen (buffer); + for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++) + continue; + for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++) + continue; + if (write (md, buffer, i) != i) + return NOTOK; + pos += (long) i; + if (mapping) + for (cp = buffer; i-- > 0; size++) + if (*cp++ == '\n') + size++; + } + + stop = lseek (md, (off_t) 0, SEEK_CUR); + j = strlen (mmdlm2); + if (write (md, mmdlm2, j) != j) + return NOTOK; if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; - } - - stop = lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm2); - if (write (md, mmdlm2, j) != j) - return NOTOK; - if (mapping) - map_write (mailbox, md, id, last, start, stop, off, size, noisy); + map_write (mailbox, md, id, last, start, stop, off, size, noisy); - return OK; + return OK; } @@ -281,182 +280,182 @@ mbx_write(char *mailbox, int md, FILE *fp, int id, long last, int mbx_copy (char *mailbox, int mbx_style, int md, int fd, - int mapping, char *text, int noisy) + int mapping, char *text, int noisy) { - int i, j, size; - off_t start, stop; - long pos; - char *cp, buffer[BUFSIZ]; - FILE *fp; - - pos = (long) lseek (md, (off_t) 0, SEEK_CUR); - size = 0; - - switch (mbx_style) { - case MMDF_FORMAT: - default: - j = strlen (mmdlm1); - if (write (md, mmdlm1, j) != j) - return NOTOK; - start = lseek (md, (off_t) 0, SEEK_CUR); - - if (text) { - i = strlen (text); - if (write (md, text, i) != i) - return NOTOK; - for (cp = text; *cp++; size++) - if (*cp == '\n') - size++; - } - - while ((i = read (fd, buffer, sizeof(buffer))) > 0) { - for (j = 0; - (j = stringdex (mmdlm1, buffer)) >= 0; - buffer[j]++) - continue; - for (j = 0; - (j = stringdex (mmdlm2, buffer)) >= 0; - buffer[j]++) - continue; - if (write (md, buffer, i) != i) - return NOTOK; - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; - } - - stop = lseek (md, (off_t) 0, SEEK_CUR); - j = strlen (mmdlm2); - if (write (md, mmdlm2, j) != j) - return NOTOK; - if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); + int i, j, size; + off_t start, stop; + long pos; + char *cp, buffer[BUFSIZ]; + FILE *fp; - return (i != NOTOK ? OK : NOTOK); + pos = (long) lseek (md, (off_t) 0, SEEK_CUR); + size = 0; - case MBOX_FORMAT: - if ((j = dup (fd)) == NOTOK) - return NOTOK; - if ((fp = fdopen (j, "r")) == NULL) { - close (j); - return NOTOK; - } - start = lseek (md, (off_t) 0, SEEK_CUR); - - /* If text is given, we add it to top of message */ - if (text) { - i = strlen (text); - if (write (md, text, i) != i) - return NOTOK; - for (cp = text; *cp++; size++) - if (*cp == '\n') - size++; - } - - for (j = 0; fgets (buffer, sizeof(buffer), fp) != NULL; j++) { + switch (mbx_style) { + case MMDF_FORMAT: + default: + j = strlen (mmdlm1); + if (write (md, mmdlm1, j) != j) + return NOTOK; + start = lseek (md, (off_t) 0, SEEK_CUR); + + if (text) { + i = strlen (text); + if (write (md, text, i) != i) + return NOTOK; + for (cp = text; *cp++; size++) + if (*cp == '\n') + size++; + } + + while ((i = read (fd, buffer, sizeof(buffer))) > 0) { + for (j = 0; + (j = stringdex (mmdlm1, buffer)) >= 0; + buffer[j]++) + continue; + for (j = 0; + (j = stringdex (mmdlm2, buffer)) >= 0; + buffer[j]++) + continue; + if (write (md, buffer, i) != i) + return NOTOK; + if (mapping) + for (cp = buffer; i-- > 0; size++) + if (*cp++ == '\n') + size++; + } + + stop = lseek (md, (off_t) 0, SEEK_CUR); + j = strlen (mmdlm2); + if (write (md, mmdlm2, j) != j) + return NOTOK; + if (mapping) + map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); + + return (i != NOTOK ? OK : NOTOK); + + case MBOX_FORMAT: + if ((j = dup (fd)) == NOTOK) + return NOTOK; + if ((fp = fdopen (j, "r")) == NULL) { + close (j); + return NOTOK; + } + start = lseek (md, (off_t) 0, SEEK_CUR); + + /* If text is given, we add it to top of message */ + if (text) { + i = strlen (text); + if (write (md, text, i) != i) + return NOTOK; + for (cp = text; *cp++; size++) + if (*cp == '\n') + size++; + } + + for (j = 0; fgets (buffer, sizeof(buffer), fp) != NULL; j++) { + + /* + * Check the first line, and make some changes. + */ + if (j == 0 && !text) { + /* + * Change the "Return-Path:" field (if in first line) + * back to "From ". + */ + if (!strncmp (buffer, "Return-Path:", 12)) { + char tmpbuffer[BUFSIZ]; + char *tp, *ep, *fp; + + strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); + ep = tmpbuffer + 13; + if (!(fp = strchr(ep + 1, ' '))) + fp = strchr(ep + 1, '\n'); + tp = dctime(dlocaltimenow()); + snprintf (buffer, sizeof(buffer), "From %.*s %s", + (int)(fp - ep), ep, tp); + } else if (!strncmp (buffer, "X-Envelope-From:", 16)) { + /* + * Change the "X-Envelope-From:" field + * (if first line) back to "From ". + */ + char tmpbuffer[BUFSIZ]; + char *ep; + + strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); + ep = tmpbuffer + 17; + snprintf (buffer, sizeof(buffer), "From %s", ep); + } else if (strncmp (buffer, "From ", 5)) { + /* + * If there is already a "From " line, + * then leave it alone. Else we add one. + */ + char tmpbuffer[BUFSIZ]; + char *tp, *ep; + + strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); + ep = "nobody@nowhere"; + tp = dctime(dlocaltimenow()); + snprintf (buffer, sizeof(buffer), "From %s %s%s", ep, tp, tmpbuffer); + } + } + + /* + * If this is not first line, and begins with + * "From ", then prepend line with ">". + */ + if (j != 0 && strncmp (buffer, "From ", 5) == 0) { + write (md, ">", 1); + size++; + } + i = strlen (buffer); + if (write (md, buffer, i) != i) { + fclose (fp); + return NOTOK; + } + if (mapping) + for (cp = buffer; i-- > 0; size++) + if (*cp++ == '\n') + size++; + } + if (write (md, "\n", 1) != 1) { + fclose (fp); + return NOTOK; + } + if (mapping) + size += 2; - /* - * Check the first line, and make some changes. - */ - if (j == 0 && !text) { - /* - * Change the "Return-Path:" field (if in first line) - * back to "From ". - */ - if (!strncmp (buffer, "Return-Path:", 12)) { - char tmpbuffer[BUFSIZ]; - char *tp, *ep, *fp; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = tmpbuffer + 13; - if (!(fp = strchr(ep + 1, ' '))) - fp = strchr(ep + 1, '\n'); - tp = dctime(dlocaltimenow()); - snprintf (buffer, sizeof(buffer), "From %.*s %s", - (int)(fp - ep), ep, tp); - } else if (!strncmp (buffer, "X-Envelope-From:", 16)) { - /* - * Change the "X-Envelope-From:" field - * (if first line) back to "From ". - */ - char tmpbuffer[BUFSIZ]; - char *ep; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = tmpbuffer + 17; - snprintf (buffer, sizeof(buffer), "From %s", ep); - } else if (strncmp (buffer, "From ", 5)) { - /* - * If there is already a "From " line, - * then leave it alone. Else we add one. - */ - char tmpbuffer[BUFSIZ]; - char *tp, *ep; - - strncpy(tmpbuffer, buffer, sizeof(tmpbuffer)); - ep = "nobody@nowhere"; - tp = dctime(dlocaltimenow()); - snprintf (buffer, sizeof(buffer), "From %s %s%s", ep, tp, tmpbuffer); - } - } + fclose (fp); + lseek (fd, (off_t) 0, SEEK_END); + stop = lseek (md, (off_t) 0, SEEK_CUR); + if (mapping) + map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); - /* - * If this is not first line, and begins with - * "From ", then prepend line with ">". - */ - if (j != 0 && strncmp (buffer, "From ", 5) == 0) { - write (md, ">", 1); - size++; - } - i = strlen (buffer); - if (write (md, buffer, i) != i) { - fclose (fp); - return NOTOK; - } - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; - } - if (write (md, "\n", 1) != 1) { - fclose (fp); - return NOTOK; - } - if (mapping) - size += 2; - - fclose (fp); - lseek (fd, (off_t) 0, SEEK_END); - stop = lseek (md, (off_t) 0, SEEK_CUR); - if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); - - return OK; - } + return OK; + } } int mbx_size (int md, off_t start, off_t stop) { - register int i, fd; - register long pos; - register FILE *fp; + register int i, fd; + register long pos; + register FILE *fp; - if ((fd = dup (md)) == NOTOK || (fp = fdopen (fd, "r")) == NULL) { - if (fd != NOTOK) - close (fd); - return NOTOK; - } + if ((fd = dup (md)) == NOTOK || (fp = fdopen (fd, "r")) == NULL) { + if (fd != NOTOK) + close (fd); + return NOTOK; + } - fseek (fp, start, SEEK_SET); - for (i = 0, pos = stop - start; pos-- > 0; i++) - if (fgetc (fp) == '\n') - i++; + fseek (fp, start, SEEK_SET); + for (i = 0, pos = stop - start; pos-- > 0; i++) + if (fgetc (fp) == '\n') + i++; - fclose (fp); - return i; + fclose (fp); + return i; } @@ -467,9 +466,9 @@ mbx_size (int md, off_t start, off_t stop) int mbx_close (char *mailbox, int md) { - if (lkclose (md, mailbox) == 0) - return OK; - return NOTOK; + if (lkclose (md, mailbox) == 0) + return OK; + return NOTOK; } @@ -481,237 +480,237 @@ mbx_close (char *mailbox, int md) char * map_name (char *file) { - register char *cp, *dp; - static char buffer[BUFSIZ]; - - if ((dp = strchr(cp = r1bindex (file, '/'), '.')) == NULL) - dp = cp + strlen (cp); - if (cp == file) - snprintf (buffer, sizeof(buffer), ".%.*s%s", (int)(dp - cp), cp, ".map"); - else - snprintf (buffer, sizeof(buffer), "%.*s.%.*s%s", - (int)(cp - file), file, (int)(dp - cp), cp, ".map"); - - return buffer; + register char *cp, *dp; + static char buffer[BUFSIZ]; + + if ((dp = strchr(cp = r1bindex (file, '/'), '.')) == NULL) + dp = cp + strlen (cp); + if (cp == file) + snprintf (buffer, sizeof(buffer), ".%.*s%s", (int)(dp - cp), cp, ".map"); + else + snprintf (buffer, sizeof(buffer), "%.*s.%.*s%s", + (int)(cp - file), file, (int)(dp - cp), cp, ".map"); + + return buffer; } int map_read (char *file, long pos, struct drop **drops, int noisy) { - register int i, md, msgp; - register char *cp; - struct drop d; - register struct drop *mp, *dp; - - if ((md = open (cp = map_name (file), O_RDONLY)) == NOTOK - || map_chk (cp, md, mp = &d, pos, noisy)) { - if (md != NOTOK) - close (md); - return 0; - } - - msgp = mp->d_id; - dp = (struct drop *) calloc ((size_t) (msgp + 1), sizeof(*dp)); - if (dp == NULL) { - close (md); - return 0; - } + register int i, md, msgp; + register char *cp; + struct drop d; + register struct drop *mp, *dp; + + if ((md = open (cp = map_name (file), O_RDONLY)) == NOTOK + || map_chk (cp, md, mp = &d, pos, noisy)) { + if (md != NOTOK) + close (md); + return 0; + } + + msgp = mp->d_id; + dp = (struct drop *) calloc ((size_t) (msgp + 1), sizeof(*dp)); + if (dp == NULL) { + close (md); + return 0; + } - memcpy((char *) dp, (char *) mp, sizeof(*dp)); + memcpy((char *) dp, (char *) mp, sizeof(*dp)); - lseek (md, (off_t) sizeof(*mp), SEEK_SET); - if ((i = read (md, (char *) (dp + 1), msgp * sizeof(*dp))) < sizeof(*dp)) { - i = 0; - free ((char *) dp); - } else { + lseek (md, (off_t) sizeof(*mp), SEEK_SET); + if ((i = read (md, (char *) (dp + 1), msgp * sizeof(*dp))) < sizeof(*dp)) { + i = 0; + free ((char *) dp); + } else { #ifdef NTOHLSWAP - register struct drop *tdp; - int j; - - for (j = 0, tdp = dp; j < i / sizeof(*dp); j++, tdp++) { - tdp->d_id = ntohl(tdp->d_id); - tdp->d_size = ntohl(tdp->d_size); - tdp->d_start = ntohl(tdp->d_start); - tdp->d_stop = ntohl(tdp->d_stop); - } + register struct drop *tdp; + int j; + + for (j = 0, tdp = dp; j < i / sizeof(*dp); j++, tdp++) { + tdp->d_id = ntohl(tdp->d_id); + tdp->d_size = ntohl(tdp->d_size); + tdp->d_start = ntohl(tdp->d_start); + tdp->d_stop = ntohl(tdp->d_stop); + } #endif - *drops = dp; - } + *drops = dp; + } - close (md); + close (md); - return (i / sizeof(*dp)); + return (i / sizeof(*dp)); } int map_write (char *mailbox, int md, int id, long last, off_t start, - off_t stop, long pos, int size, int noisy) + off_t stop, long pos, int size, int noisy) { - register int i; - int clear, fd, td; - char *file; - register struct drop *dp; - struct drop d1, d2, *rp; - register FILE *fp; - struct stat st; - - if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) - return NOTOK; - - if ((fstat (fd, &st) == OK) && (st.st_size > 0)) - clear = 0; - else - clear = 1; + register int i; + int clear, fd, td; + char *file; + register struct drop *dp; + struct drop d1, d2, *rp; + register FILE *fp; + struct stat st; + + if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) + return NOTOK; - if (!clear && map_chk (file, fd, &d1, pos, noisy)) { - unlink (file); - mbx_close (file, fd); - if ((fd = map_open (file, md)) == NOTOK) - return NOTOK; - clear++; - } - - if (clear) { - if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) { - if (noisy) - admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup"); - if (td != NOTOK) - close (td); - mbx_close (file, fd); - return NOTOK; - } + if ((fstat (fd, &st) == OK) && (st.st_size > 0)) + clear = 0; + else + clear = 1; - switch (i = mbx_read (fp, 0, &rp, noisy)) { - case NOTOK: - fclose (fp); + if (!clear && map_chk (file, fd, &d1, pos, noisy)) { + unlink (file); mbx_close (file, fd); - return NOTOK; + if ((fd = map_open (file, md)) == NOTOK) + return NOTOK; + clear++; + } - case OK: - fclose (fp); - break; + if (clear) { + if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) { + if (noisy) + admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup"); + if (td != NOTOK) + close (td); + mbx_close (file, fd); + return NOTOK; + } - default: - d1.d_id = 0; - for (dp = rp; i-- >0; dp++) { - if (dp->d_start == start) - dp->d_id = id; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { + switch (i = mbx_read (fp, 0, &rp, noisy)) { + case NOTOK: + fclose (fp); + mbx_close (file, fd); + return NOTOK; + + case OK: + fclose (fp); + break; + + default: + d1.d_id = 0; + for (dp = rp; i-- >0; dp++) { + if (dp->d_start == start) + dp->d_id = id; + lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); + if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { + if (noisy) + admonish (file, "write error"); + mbx_close (file, fd); + fclose (fp); + return NOTOK; + } + } + free ((char *) rp); + fclose (fp); + break; + } + } + else { + if (last == 0) + last = d1.d_start; + dp = &d2; + dp->d_id = id; + dp->d_size = (long) (size ? size : mbx_size (fd, start, stop)); + dp->d_start = start; + dp->d_stop = stop; + lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); + if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { if (noisy) - admonish (file, "write error"); + admonish (file, "write error"); mbx_close (file, fd); - fclose (fp); return NOTOK; - } } - free ((char *) rp); - fclose (fp); - break; } - } - else { - if (last == 0) - last = d1.d_start; - dp = &d2; - dp->d_id = id; - dp->d_size = (long) (size ? size : mbx_size (fd, start, stop)); - dp->d_start = start; - dp->d_stop = stop; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); + + dp = &d1; + dp->d_size = DRVRSN; + dp->d_start = (long) last; + dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR); + + lseek (fd, (off_t) 0, SEEK_SET); if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); - return NOTOK; + if (noisy) + admonish (file, "write error"); + mbx_close (file, fd); + return NOTOK; } - } - - dp = &d1; - dp->d_size = DRVRSN; - dp->d_start = (long) last; - dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR); - lseek (fd, (off_t) 0, SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); mbx_close (file, fd); - return NOTOK; - } - - mbx_close (file, fd); - return OK; + return OK; } static int map_open (char *file, int md) { - mode_t mode; - struct stat st; + mode_t mode; + struct stat st; - mode = fstat (md, &st) != NOTOK ? (mode_t) (st.st_mode & 0777) : m_gmprot (); - return mbx_open (file, OTHER_FORMAT, st.st_uid, st.st_gid, mode); + mode = fstat (md, &st) != NOTOK ? (mode_t) (st.st_mode & 0777) : m_gmprot (); + return mbx_open (file, OTHER_FORMAT, st.st_uid, st.st_gid, mode); } int map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) { - long count; - struct drop d, tmpd; - register struct drop *dl; + long count; + struct drop d, tmpd; + register struct drop *dl; - if (read (fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { + if (read (fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { #ifdef notdef - admonish (NULL, "%s: missing or partial index", file); + admonish (NULL, "%s: missing or partial index", file); #endif /* notdef */ - return NOTOK; - } -#ifndef NTOHLSWAP - *dp = tmpd; /* if ntohl(n)=(n), can use struct assign */ + return NOTOK; + } +#ifndef NTOHLSWAP + *dp = tmpd; /* if ntohl(n)=(n), can use struct assign */ #else - dp->d_id = ntohl(tmpd.d_id); - dp->d_size = ntohl(tmpd.d_size); - dp->d_start = ntohl(tmpd.d_start); - dp->d_stop = ntohl(tmpd.d_stop); + dp->d_id = ntohl(tmpd.d_id); + dp->d_size = ntohl(tmpd.d_size); + dp->d_start = ntohl(tmpd.d_start); + dp->d_stop = ntohl(tmpd.d_stop); #endif - - if (dp->d_size != DRVRSN) { - if (noisy) - admonish (NULL, "%s: version mismatch (%d != %d)", file, - dp->d_size, DRVRSN); - return NOTOK; - } - if (dp->d_stop != pos) { - if (noisy && pos != (long) 0) - admonish (NULL, - "%s: pointer mismatch or incomplete index (%ld!=%ld)", - file, dp->d_stop, (long) pos); - return NOTOK; - } + if (dp->d_size != DRVRSN) { + if (noisy) + admonish (NULL, "%s: version mismatch (%d != %d)", + file, dp->d_size, DRVRSN); + return NOTOK; + } - if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek (fd, (off_t) 0, SEEK_END)) { - if (noisy) - admonish (NULL, "%s: corrupt index(1)", file); - return NOTOK; - } - - dl = &d; - count = (long) strlen (mmdlm2); - lseek (fd, (off_t) (dp->d_id * sizeof(*dp)), SEEK_SET); - if (read (fd, (char *) dl, sizeof(*dl)) != sizeof(*dl) - || (ntohl(dl->d_stop) != dp->d_stop - && ntohl(dl->d_stop) + count != dp->d_stop)) { - if (noisy) - admonish (NULL, "%s: corrupt index(2)", file); - return NOTOK; - } + if (dp->d_stop != pos) { + if (noisy && pos != (long) 0) + admonish (NULL, + "%s: pointer mismatch or incomplete index (%ld!=%ld)", + file, dp->d_stop, (long) pos); + return NOTOK; + } + + if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek (fd, (off_t) 0, SEEK_END)) { + if (noisy) + admonish (NULL, "%s: corrupt index(1)", file); + return NOTOK; + } + + dl = &d; + count = (long) strlen (mmdlm2); + lseek (fd, (off_t) (dp->d_id * sizeof(*dp)), SEEK_SET); + if (read (fd, (char *) dl, sizeof(*dl)) != sizeof(*dl) + || (ntohl(dl->d_stop) != dp->d_stop + && ntohl(dl->d_stop) + count != dp->d_stop)) { + if (noisy) + admonish (NULL, "%s: corrupt index(2)", file); + return NOTOK; + } - return OK; + return OK; } diff --git a/uip/flist.c b/uip/flist.c index e3da709..51eff1e 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -28,46 +28,46 @@ static struct swit switches[] = { -#define SEQSW 0 - { "sequence name", 0 }, -#define ALLSW 1 - { "all", 0 }, -#define NOALLSW 2 - { "noall", 0 }, -#define RECURSE 3 - { "recurse", 0 }, -#define NORECURSE 4 - { "norecurse", 0 }, -#define SHOWZERO 5 - { "showzero", 0 }, -#define NOSHOWZERO 6 - { "noshowzero", 0 }, -#define ALPHASW 7 - { "alpha", 0 }, -#define NOALPHASW 8 - { "noalpha", 0 }, -#define FASTSW 9 - { "fast", 0 }, -#define NOFASTSW 10 - { "nofast", 0 }, -#define TOTALSW 11 - { "total", -5 }, -#define NOTOTALSW 12 - { "nototal", -7 }, -#define VERSIONSW 13 - { "version", 0 }, -#define HELPSW 14 - { "help", 0 }, - { NULL, 0 } +#define SEQSW 0 + { "sequence name", 0 }, +#define ALLSW 1 + { "all", 0 }, +#define NOALLSW 2 + { "noall", 0 }, +#define RECURSE 3 + { "recurse", 0 }, +#define NORECURSE 4 + { "norecurse", 0 }, +#define SHOWZERO 5 + { "showzero", 0 }, +#define NOSHOWZERO 6 + { "noshowzero", 0 }, +#define ALPHASW 7 + { "alpha", 0 }, +#define NOALPHASW 8 + { "noalpha", 0 }, +#define FASTSW 9 + { "fast", 0 }, +#define NOFASTSW 10 + { "nofast", 0 }, +#define TOTALSW 11 + { "total", -5 }, +#define NOTOTALSW 12 + { "nototal", -7 }, +#define VERSIONSW 13 + { "version", 0 }, +#define HELPSW 14 + { "help", 0 }, + { NULL, 0 } }; struct Folder { - char *name; /* name of folder */ - int priority; - int error; /* error == 1 for unreadable folder */ - int nMsgs; /* number of messages in folder */ - int nSeq[NUMATTRS]; /* number of messages in each sequence */ - int private[NUMATTRS]; /* is given sequence, public or private */ + char *name; /* name of folder */ + int priority; + int error; /* error == 1 for unreadable folder */ + int nMsgs; /* number of messages in folder */ + int nSeq[NUMATTRS]; /* number of messages in each sequence */ + int private[NUMATTRS]; /* is given sequence, public or private */ }; static struct Folder *orders = NULL; @@ -86,15 +86,15 @@ static int maxfolders; static char *sequencesToDo[NUMATTRS]; static int numsequences; -static int all = FALSE; /* scan all folders in top level? */ -static int alphaOrder = FALSE; /* want alphabetical order only */ -static int recurse = FALSE; /* show nested folders? */ -static int showzero = TRUE; /* show folders even if no messages in seq? */ -static int Total = TRUE; /* display info on number of messages in * - * sequence found, and total num messages */ +static int all = FALSE; /* scan all folders in top level? */ +static int alphaOrder = FALSE; /* want alphabetical order only */ +static int recurse = FALSE; /* show nested folders? */ +static int showzero = TRUE; /* show folders even if no messages in seq? */ +static int Total = TRUE; /* display info on number of messages in + * sequence found, and total num messages */ -static char curfolder[BUFSIZ]; /* name of the current folder */ -static char *nmhdir; /* base nmh mail directory */ +static char curfolder[BUFSIZ]; /* name of the current folder */ +static char *nmhdir; /* base nmh mail directory */ /* * Type for a compare function for qsort. This keeps @@ -121,161 +121,161 @@ static void do_readonly_folders(void); int main(int argc, char **argv) { - char *cp, **argp; - char **arguments; - char buf[BUFSIZ]; + char *cp, **argp; + char **arguments; + char buf[BUFSIZ]; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex(argv[0], '/'); - - /* read user profile/context */ - context_read(); - - /* - * If program was invoked with name ending - * in `s', then add switch `-all'. - */ - if (argv[0][strlen (argv[0]) - 1] == 's') - all = TRUE; - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* allocate the initial space to record the folder names */ - numfolders = 0; - maxfolders = MAXFOLDERS; - foldersToDo = (char **) mh_xmalloc ((size_t) (maxfolders * sizeof(*foldersToDo))); - - /* no sequences yet */ - numsequences = 0; - - /* parse arguments */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch(++cp, switches)) { - case AMBIGSW: - ambigsw(cp, switches); - done(1); - case UNKWNSW: - adios(NULL, "-%s unknown", cp); - - case HELPSW: - snprintf(buf, sizeof(buf), "%s [+folder1 [+folder2 ...]][switches]", - invo_name); - print_help(buf, switches, 1); - done(1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case SEQSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - - /* check if too many sequences specified */ - if (numsequences >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); - sequencesToDo[numsequences++] = cp; - break; - - case ALLSW: + invo_name = r1bindex(argv[0], '/'); + + /* read user profile/context */ + context_read(); + + /* + * If program was invoked with name ending + * in `s', then add switch `-all'. + */ + if (argv[0][strlen (argv[0]) - 1] == 's') all = TRUE; - break; - case NOALLSW: - all = FALSE; - break; - - case SHOWZERO: - showzero = TRUE; - break; - case NOSHOWZERO: - showzero = FALSE; - break; - - case ALPHASW: - alphaOrder = TRUE; - break; - case NOALPHASW: - alphaOrder = FALSE; - break; - - case NOFASTSW: - case TOTALSW: - Total = TRUE; - break; - - case FASTSW: - case NOTOTALSW: - Total = FALSE; - break; - - case RECURSE: - recurse = TRUE; - break; - case NORECURSE: - recurse = FALSE; - break; - } - } else { - /* - * Check if we need to allocate more space - * for folder names. - */ - if (numfolders >= maxfolders) { - maxfolders += MAXFOLDERS; - foldersToDo = (char **) mh_xrealloc (foldersToDo, - (size_t) (maxfolders * sizeof(*foldersToDo))); - } - if (*cp == '+' || *cp == '@') { - foldersToDo[numfolders++] = - pluspath (cp); - } else - foldersToDo[numfolders++] = cp; + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* allocate the initial space to record the folder names */ + numfolders = 0; + maxfolders = MAXFOLDERS; + foldersToDo = (char **) mh_xmalloc ((size_t) (maxfolders * sizeof(*foldersToDo))); + + /* no sequences yet */ + numsequences = 0; + + /* parse arguments */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch(++cp, switches)) { + case AMBIGSW: + ambigsw(cp, switches); + done(1); + case UNKWNSW: + adios(NULL, "-%s unknown", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [+folder1 [+folder2 ...]][switches]", + invo_name); + print_help(buf, switches, 1); + done(1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case SEQSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + + /* check if too many sequences specified */ + if (numsequences >= NUMATTRS) + adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + sequencesToDo[numsequences++] = cp; + break; + + case ALLSW: + all = TRUE; + break; + case NOALLSW: + all = FALSE; + break; + + case SHOWZERO: + showzero = TRUE; + break; + case NOSHOWZERO: + showzero = FALSE; + break; + + case ALPHASW: + alphaOrder = TRUE; + break; + case NOALPHASW: + alphaOrder = FALSE; + break; + + case NOFASTSW: + case TOTALSW: + Total = TRUE; + break; + + case FASTSW: + case NOTOTALSW: + Total = FALSE; + break; + + case RECURSE: + recurse = TRUE; + break; + case NORECURSE: + recurse = FALSE; + break; + } + } else { + /* + * Check if we need to allocate more space + * for folder names. + */ + if (numfolders >= maxfolders) { + maxfolders += MAXFOLDERS; + foldersToDo = (char **) mh_xrealloc (foldersToDo, + (size_t) (maxfolders * sizeof(*foldersToDo))); + } + if (*cp == '+' || *cp == '@') { + foldersToDo[numfolders++] = + pluspath (cp); + } else + foldersToDo[numfolders++] = cp; + } } - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* get current folder */ - strncpy (curfolder, getfolder(1), sizeof(curfolder)); - - /* get nmh base directory */ - nmhdir = m_maildir (""); - - /* - * If we didn't specify any sequences, we search - * for the "Unseen-Sequence" profile entry and use - * all the sequences defined there. We check to - * make sure that the Unseen-Sequence entry doesn't - * contain more than NUMATTRS sequences. - */ - if (numsequences == 0) { - if ((cp = context_find(usequence)) && *cp) { - char **ap, *dp; - - dp = getcpy(cp); - ap = brkstring (dp, " ", "\n"); - for (; ap && *ap; ap++) { - if (numsequences >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) in %s profile entry", - NUMATTRS, usequence); - else - sequencesToDo[numsequences++] = *ap; - } - } else { - adios (NULL, "no sequence specified or %s profile entry found", usequence); + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + /* get current folder */ + strncpy (curfolder, getfolder(1), sizeof(curfolder)); + + /* get nmh base directory */ + nmhdir = m_maildir (""); + + /* + * If we didn't specify any sequences, we search + * for the "Unseen-Sequence" profile entry and use + * all the sequences defined there. We check to + * make sure that the Unseen-Sequence entry doesn't + * contain more than NUMATTRS sequences. + */ + if (numsequences == 0) { + if ((cp = context_find(usequence)) && *cp) { + char **ap, *dp; + + dp = getcpy(cp); + ap = brkstring (dp, " ", "\n"); + for (; ap && *ap; ap++) { + if (numsequences >= NUMATTRS) + adios (NULL, "too many sequences (more than %d) in %s profile entry", + NUMATTRS, usequence); + else + sequencesToDo[numsequences++] = *ap; + } + } else { + adios (NULL, "no sequence specified or %s profile entry found", usequence); + } } - } - - GetFolderOrder(); - ScanFolders(); - qsort(folders, nFolders, sizeof(struct Folder), (qsort_comp) CompareFolders); - PrintFolders(); - done (0); - return 1; + + GetFolderOrder(); + ScanFolders(); + qsort(folders, nFolders, sizeof(struct Folder), (qsort_comp) CompareFolders); + PrintFolders(); + done (0); + return 1; } /* @@ -286,29 +286,29 @@ main(int argc, char **argv) void GetFolderOrder(void) { - unsigned char *p, *s; - int priority = 1; - struct Folder *o; - - if (!(p = context_find("Flist-Order"))) - return; - for (;;) { - while (isspace(*p)) - ++p; - s = p; - while (*p && !isspace(*p)) - ++p; - if (p != s) { - /* Found one. */ - AllocFolders(&orders, &nOrdersAlloced, nOrders + 1); - o = &orders[nOrders++]; - o->priority = priority++; - o->name = (char *) mh_xmalloc(p - s + 1); - strncpy(o->name, s, p - s); - o->name[p - s] = 0; - } else - break; - } + unsigned char *p, *s; + int priority = 1; + struct Folder *o; + + if (!(p = context_find("Flist-Order"))) + return; + for (;;) { + while (isspace(*p)) + ++p; + s = p; + while (*p && !isspace(*p)) + ++p; + if (p != s) { + /* Found one. */ + AllocFolders(&orders, &nOrdersAlloced, nOrders + 1); + o = &orders[nOrders++]; + o->priority = priority++; + o->name = (char *) mh_xmalloc(p - s + 1); + strncpy(o->name, s, p - s); + o->name[p - s] = 0; + } else + break; + } } /* @@ -318,45 +318,45 @@ GetFolderOrder(void) void ScanFolders(void) { - int i; - - /* - * change directory to base of nmh directory - */ - if (chdir (nmhdir) == NOTOK) - adios (nmhdir, "unable to change directory to"); - - if (numfolders > 0) { - /* Update context */ - strncpy (curfolder, foldersToDo[numfolders - 1], sizeof(curfolder)); - context_replace (pfolder, curfolder);/* update current folder */ - context_save (); /* save the context file */ + int i; /* - * Scan each given folder. If -all is given, - * then also scan the 1st level subfolders under - * each given folder. + * change directory to base of nmh directory */ - for (i = 0; i < numfolders; ++i) - BuildFolderList(foldersToDo[i], all ? 1 : 0); - } else { - if (all) { - /* - * Do the readonly folders - */ - do_readonly_folders(); - - /* - * Now scan the entire nmh directory for folders - */ - BuildFolderList(".", 0); + if (chdir (nmhdir) == NOTOK) + adios (nmhdir, "unable to change directory to"); + + if (numfolders > 0) { + /* Update context */ + strncpy (curfolder, foldersToDo[numfolders - 1], sizeof(curfolder)); + context_replace (pfolder, curfolder);/* update current folder */ + context_save (); /* save the context file */ + + /* + * Scan each given folder. If -all is given, + * then also scan the 1st level subfolders under + * each given folder. + */ + for (i = 0; i < numfolders; ++i) + BuildFolderList(foldersToDo[i], all ? 1 : 0); } else { - /* - * Else scan current folder - */ - BuildFolderList(curfolder, 0); + if (all) { + /* + * Do the readonly folders + */ + do_readonly_folders(); + + /* + * Now scan the entire nmh directory for folders + */ + BuildFolderList(".", 0); + } else { + /* + * Else scan current folder + */ + BuildFolderList(curfolder, 0); + } } - } } /* @@ -367,28 +367,28 @@ ScanFolders(void) void BuildFolderList(char *dirName, int searchdepth) { - struct stat st; - - /* Make sure we have a directory */ - if ((stat(dirName, &st) == -1) || !S_ISDIR(st.st_mode)) - return; - - /* - * If base directory, don't add it to the - * folder list. We just recurse into it. - */ - if (!strcmp (dirName, ".")) { - BuildFolderListRecurse (".", &st, 0); - return; - } - - /* - * Add this folder to the list. - * If recursing and directory has subfolders, - * then build folder list for subfolders. - */ - if (AddFolder(dirName, showzero) && (recurse || searchdepth) && st.st_nlink > 2) - BuildFolderListRecurse(dirName, &st, searchdepth - 1); + struct stat st; + + /* Make sure we have a directory */ + if ((stat(dirName, &st) == -1) || !S_ISDIR(st.st_mode)) + return; + + /* + * If base directory, don't add it to the + * folder list. We just recurse into it. + */ + if (!strcmp (dirName, ".")) { + BuildFolderListRecurse (".", &st, 0); + return; + } + + /* + * Add this folder to the list. + * If recursing and directory has subfolders, + * then build folder list for subfolders. + */ + if (AddFolder(dirName, showzero) && (recurse || searchdepth) && st.st_nlink > 2) + BuildFolderListRecurse(dirName, &st, searchdepth - 1); } /* @@ -398,62 +398,62 @@ BuildFolderList(char *dirName, int searchdepth) void BuildFolderListRecurse(char *dirName, struct stat *s, int searchdepth) { - char *base, name[PATH_MAX]; - unsigned char *n; - int nlinks; - DIR *dir; - struct dirent *dp; - struct stat st; - - /* - * Keep track of number of directories we've seen so we can - * stop stat'ing entries in this directory once we've seen - * them all. This optimization will fail if you have extra - * directories beginning with ".", since we don't bother to - * stat them. But that shouldn't generally be a problem. - */ - nlinks = s->st_nlink; - - if (!(dir = opendir(dirName))) - adios(dirName, "can't open directory"); - - /* - * A hack so that we don't see a - * leading "./" in folder names. - */ - base = strcmp (dirName, ".") ? dirName : dirName + 1; - - while (nlinks && (dp = readdir(dir))) { - if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { - nlinks--; - continue; - } - if (dp->d_name[0] == '.') - continue; - /* Check to see if the name of the file is a number - * if it is, we assume it's a mail file and skip it + char *base, name[PATH_MAX]; + unsigned char *n; + int nlinks; + DIR *dir; + struct dirent *dp; + struct stat st; + + /* + * Keep track of number of directories we've seen so we can + * stop stat'ing entries in this directory once we've seen + * them all. This optimization will fail if you have extra + * directories beginning with ".", since we don't bother to + * stat them. But that shouldn't generally be a problem. + */ + nlinks = s->st_nlink; + + if (!(dir = opendir(dirName))) + adios(dirName, "can't open directory"); + + /* + * A hack so that we don't see a + * leading "./" in folder names. */ - for (n = dp->d_name; *n && isdigit(*n); n++); - if (!*n) - continue; - strncpy (name, base, sizeof(name) - 2); - if (*base) - strcat(name, "/"); - strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1); - if ((stat(name, &st) != -1) && S_ISDIR(st.st_mode)) { - /* - * Check if this was really a symbolic link pointing - * to a directory. If not, then decrement link count. - */ - if (lstat (name, &st) == -1) - nlinks--; - /* Add this folder to the list */ - if (AddFolder(name, showzero) && - (recurse || searchdepth) && st.st_nlink > 2) - BuildFolderListRecurse(name, &st, searchdepth - 1); + base = strcmp (dirName, ".") ? dirName : dirName + 1; + + while (nlinks && (dp = readdir(dir))) { + if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { + nlinks--; + continue; + } + if (dp->d_name[0] == '.') + continue; + /* Check to see if the name of the file is a number + * if it is, we assume it's a mail file and skip it + */ + for (n = dp->d_name; *n && isdigit(*n); n++); + if (!*n) + continue; + strncpy (name, base, sizeof(name) - 2); + if (*base) + strcat(name, "/"); + strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1); + if ((stat(name, &st) != -1) && S_ISDIR(st.st_mode)) { + /* + * Check if this was really a symbolic link pointing + * to a directory. If not, then decrement link count. + */ + if (lstat (name, &st) == -1) + nlinks--; + /* Add this folder to the list */ + if (AddFolder(name, showzero) && + (recurse || searchdepth) && st.st_nlink > 2) + BuildFolderListRecurse(name, &st, searchdepth - 1); + } } - } - closedir(dir); + closedir(dir); } /* @@ -464,66 +464,66 @@ BuildFolderListRecurse(char *dirName, struct stat *s, int searchdepth) int AddFolder(char *name, int force) { - int i, msgnum, nonzero; - int seqnum[NUMATTRS], nSeq[NUMATTRS]; - struct Folder *f; - struct msgs *mp; - - /* Read folder and create message structure */ - if (!(mp = folder_read (name))) { - /* Oops, error occurred. Record it and continue. */ - AllocFolders(&folders, &nFoldersAlloced, nFolders + 1); - f = &folders[nFolders++]; - f->name = getcpy(name); - f->error = 1; - f->priority = AssignPriority(f->name); - return 0; - } - - for (i = 0; i < numsequences; i++) { - /* Convert sequences to their sequence numbers */ - if (sequencesToDo[i]) - seqnum[i] = seq_getnum(mp, sequencesToDo[i]); - else - seqnum[i] = -1; - - /* Now count messages in this sequence */ - nSeq[i] = 0; - if (mp->nummsg > 0 && seqnum[i] != -1) { - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { - if (in_sequence(mp, seqnum[i], msgnum)) - nSeq[i]++; - } + int i, msgnum, nonzero; + int seqnum[NUMATTRS], nSeq[NUMATTRS]; + struct Folder *f; + struct msgs *mp; + + /* Read folder and create message structure */ + if (!(mp = folder_read (name))) { + /* Oops, error occurred. Record it and continue. */ + AllocFolders(&folders, &nFoldersAlloced, nFolders + 1); + f = &folders[nFolders++]; + f->name = getcpy(name); + f->error = 1; + f->priority = AssignPriority(f->name); + return 0; } - } - - /* Check if any of the sequence checks were nonzero */ - nonzero = 0; - for (i = 0; i < numsequences; i++) { - if (nSeq[i] > 0) { - nonzero = 1; - break; + + for (i = 0; i < numsequences; i++) { + /* Convert sequences to their sequence numbers */ + if (sequencesToDo[i]) + seqnum[i] = seq_getnum(mp, sequencesToDo[i]); + else + seqnum[i] = -1; + + /* Now count messages in this sequence */ + nSeq[i] = 0; + if (mp->nummsg > 0 && seqnum[i] != -1) { + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { + if (in_sequence(mp, seqnum[i], msgnum)) + nSeq[i]++; + } + } } - } - - if (nonzero || force) { - /* save general folder information */ - AllocFolders(&folders, &nFoldersAlloced, nFolders + 1); - f = &folders[nFolders++]; - f->name = getcpy(name); - f->nMsgs = mp->nummsg; - f->error = 0; - f->priority = AssignPriority(f->name); - - /* record the sequence information */ + + /* Check if any of the sequence checks were nonzero */ + nonzero = 0; for (i = 0; i < numsequences; i++) { - f->nSeq[i] = nSeq[i]; - f->private[i] = (seqnum[i] != -1) ? is_seq_private(mp, seqnum[i]) : 0; + if (nSeq[i] > 0) { + nonzero = 1; + break; + } } - } - folder_free (mp); /* free folder/message structure */ - return 1; + if (nonzero || force) { + /* save general folder information */ + AllocFolders(&folders, &nFoldersAlloced, nFolders + 1); + f = &folders[nFolders++]; + f->name = getcpy(name); + f->nMsgs = mp->nummsg; + f->error = 0; + f->priority = AssignPriority(f->name); + + /* record the sequence information */ + for (i = 0; i < numsequences; i++) { + f->nSeq[i] = nSeq[i]; + f->private[i] = (seqnum[i] != -1) ? is_seq_private(mp, seqnum[i]) : 0; + } + } + + folder_free (mp); /* free folder/message structure */ + return 1; } /* @@ -533,74 +533,74 @@ AddFolder(char *name, int force) void PrintFolders(void) { - char tmpname[BUFSIZ]; - int i, j, len, has_private = 0; - int maxfolderlen = 0, maxseqlen = 0; - int maxnum = 0, maxseq = 0; - - if (!Total) { - for (i = 0; i < nFolders; i++) - printf("%s\n", folders[i].name); - return; - } - - /* - * Find the width we need for various fields - */ - for (i = 0; i < nFolders; ++i) { - /* find the length of longest folder name */ - len = strlen(folders[i].name); - if (len > maxfolderlen) - maxfolderlen = len; - - /* If folder had error, skip the rest */ - if (folders[i].error) - continue; - - /* find the maximum total messages */ - if (folders[i].nMsgs > maxnum) - maxnum = folders[i].nMsgs; - - for (j = 0; j < numsequences; j++) { - /* find maximum width of sequence name */ - len = strlen (sequencesToDo[j]); - if ((folders[i].nSeq[j] > 0 || showzero) && (len > maxseqlen)) - maxseqlen = len; - - /* find the maximum number of messages in sequence */ - if (folders[i].nSeq[j] > maxseq) - maxseq = folders[i].nSeq[j]; - - /* check if this sequence is private in any of the folders */ - if (folders[i].private[j]) - has_private = 1; + char tmpname[BUFSIZ]; + int i, j, len, has_private = 0; + int maxfolderlen = 0, maxseqlen = 0; + int maxnum = 0, maxseq = 0; + + if (!Total) { + for (i = 0; i < nFolders; i++) + printf("%s\n", folders[i].name); + return; } - } - - /* Now print all the folder/sequence information */ - for (i = 0; i < nFolders; i++) { - for (j = 0; j < numsequences; j++) { - if (folders[i].nSeq[j] > 0 || showzero) { - /* Add `+' to end of name of current folder */ - if (strcmp(curfolder, folders[i].name)) - snprintf(tmpname, sizeof(tmpname), "%s", folders[i].name); - else - snprintf(tmpname, sizeof(tmpname), "%s+", folders[i].name); - if (folders[i].error) { - printf("%-*s is unreadable\n", maxfolderlen+1, tmpname); - continue; + /* + * Find the width we need for various fields + */ + for (i = 0; i < nFolders; ++i) { + /* find the length of longest folder name */ + len = strlen(folders[i].name); + if (len > maxfolderlen) + maxfolderlen = len; + + /* If folder had error, skip the rest */ + if (folders[i].error) + continue; + + /* find the maximum total messages */ + if (folders[i].nMsgs > maxnum) + maxnum = folders[i].nMsgs; + + for (j = 0; j < numsequences; j++) { + /* find maximum width of sequence name */ + len = strlen (sequencesToDo[j]); + if ((folders[i].nSeq[j] > 0 || showzero) && (len > maxseqlen)) + maxseqlen = len; + + /* find the maximum number of messages in sequence */ + if (folders[i].nSeq[j] > maxseq) + maxseq = folders[i].nSeq[j]; + + /* check if this sequence is private in any of the folders */ + if (folders[i].private[j]) + has_private = 1; } + } - printf("%-*s has %*d in sequence %-*s%s; out of %*d\n", - maxfolderlen+1, tmpname, - num_digits(maxseq), folders[i].nSeq[j], - maxseqlen, sequencesToDo[j], - !has_private ? "" : folders[i].private[j] ? " (private)" : " ", - num_digits(maxnum), folders[i].nMsgs); - } + /* Now print all the folder/sequence information */ + for (i = 0; i < nFolders; i++) { + for (j = 0; j < numsequences; j++) { + if (folders[i].nSeq[j] > 0 || showzero) { + /* Add `+' to end of name of current folder */ + if (strcmp(curfolder, folders[i].name)) + snprintf(tmpname, sizeof(tmpname), "%s", folders[i].name); + else + snprintf(tmpname, sizeof(tmpname), "%s+", folders[i].name); + + if (folders[i].error) { + printf("%-*s is unreadable\n", maxfolderlen+1, tmpname); + continue; + } + + printf("%-*s has %*d in sequence %-*s%s; out of %*d\n", + maxfolderlen+1, tmpname, + num_digits(maxseq), folders[i].nSeq[j], + maxseqlen, sequencesToDo[j], + !has_private ? "" : folders[i].private[j] ? " (private)" : " ", + num_digits(maxnum), folders[i].nMsgs); + } + } } - } } /* @@ -610,10 +610,10 @@ PrintFolders(void) int CompareFolders(struct Folder *f1, struct Folder *f2) { - if (!alphaOrder && f1->priority != f2->priority) - return f1->priority - f2->priority; - else - return strcmp(f1->name, f2->name); + if (!alphaOrder && f1->priority != f2->priority) + return f1->priority - f2->priority; + else + return strcmp(f1->name, f2->name); } /* @@ -623,15 +623,15 @@ CompareFolders(struct Folder *f1, struct Folder *f2) void AllocFolders(struct Folder **f, int *nfa, int n) { - if (n <= *nfa) - return; - if (*f == NULL) { - *nfa = 10; - *f = (struct Folder *) mh_xmalloc (*nfa * (sizeof(struct Folder))); - } else { - *nfa *= 2; - *f = (struct Folder *) mh_xrealloc (*f, *nfa * (sizeof(struct Folder))); - } + if (n <= *nfa) + return; + if (*f == NULL) { + *nfa = 10; + *f = (struct Folder *) mh_xmalloc (*nfa * (sizeof(struct Folder))); + } else { + *nfa *= 2; + *f = (struct Folder *) mh_xrealloc (*f, *nfa * (sizeof(struct Folder))); + } } /* @@ -641,30 +641,30 @@ AllocFolders(struct Folder **f, int *nfa, int n) int AssignPriority(char *name) { - int i, ol, nl; - int best = nOrders; - int bestLen = 0; - struct Folder *o; - - nl = strlen(name); - for (i = 0; i < nOrders; ++i) { - o = &orders[i]; - if (!strcmp(name, o->name)) - return o->priority; - ol = strlen(o->name); - if (nl < ol - 1) - continue; - if (ol < bestLen) - continue; - if (o->name[0] == '*' && !strcmp(o->name + 1, name + (nl - ol + 1))) { - best = o->priority; - bestLen = ol; - } else if (o->name[ol - 1] == '*' && strncmp(o->name, name, ol - 1) == 0) { - best = o->priority; - bestLen = ol; + int i, ol, nl; + int best = nOrders; + int bestLen = 0; + struct Folder *o; + + nl = strlen(name); + for (i = 0; i < nOrders; ++i) { + o = &orders[i]; + if (!strcmp(name, o->name)) + return o->priority; + ol = strlen(o->name); + if (nl < ol - 1) + continue; + if (ol < bestLen) + continue; + if (o->name[0] == '*' && !strcmp(o->name + 1, name + (nl - ol + 1))) { + best = o->priority; + bestLen = ol; + } else if (o->name[ol - 1] == '*' && strncmp(o->name, name, ol - 1) == 0) { + best = o->priority; + bestLen = ol; + } } - } - return best; + return best; } /* @@ -674,15 +674,15 @@ AssignPriority(char *name) static void do_readonly_folders (void) { - int atrlen; - char atrcur[BUFSIZ]; - register struct node *np; + int atrlen; + char atrcur[BUFSIZ]; + register struct node *np; - snprintf (atrcur, sizeof(atrcur), "atr-%s-", current); - atrlen = strlen (atrcur); + snprintf (atrcur, sizeof(atrcur), "atr-%s-", current); + atrlen = strlen (atrcur); - for (np = m_defs; np; np = np->n_next) - if (ssequal (atrcur, np->n_name) - && !ssequal (nmhdir, np->n_name + atrlen)) - BuildFolderList (np->n_name + atrlen, 0); + for (np = m_defs; np; np = np->n_next) + if (ssequal (atrcur, np->n_name) + && !ssequal (nmhdir, np->n_name + atrlen)) + BuildFolderList (np->n_name + atrlen, 0); } diff --git a/uip/fmtdump.c b/uip/fmtdump.c index fff4502..e6561ad 100644 --- a/uip/fmtdump.c +++ b/uip/fmtdump.c @@ -1,4 +1,3 @@ - /* * fmtdump.c -- compile format file and dump out instructions * @@ -13,15 +12,15 @@ #include static struct swit switches[] = { -#define FORMSW 0 - { "form formatfile", 0 }, -#define FMTSW 1 - { "format string", 5 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } +#define FORMSW 0 + { "form formatfile", 0 }, +#define FMTSW 1 + { "format string", 5 }, +#define VERSIONSW 2 + { "version", 0 }, +#define HELPSW 3 + { "help", 0 }, + { NULL, 0 } }; /* for assignlabel */ @@ -45,482 +44,483 @@ static void litputc(char); int main (int argc, char **argv) { - int ncomps; - char *cp, *form = NULL, *format = NULL; - char buf[BUFSIZ], *nfs, **argp, **arguments; - struct format *fmt; + int ncomps; + char *cp, *form = NULL, *format = NULL; + char buf[BUFSIZ], *nfs, **argp, **arguments; + struct format *fmt; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + } + } + if (form) + adios (NULL, "only one form at a time!"); + else + form = cp; } - if (form) - adios (NULL, "only one form at a time!"); - else - form = cp; - } - - /* - * Get new format string. Must be before chdir(). - */ - nfs = new_fs (form, format, FORMAT); - ncomps = fmt_compile(nfs, &fmt); - - fmt_dump(fmt); - done(0); - return 1; + + /* + * Get new format string. Must be before chdir(). + */ + nfs = new_fs (form, format, FORMAT); + ncomps = fmt_compile(nfs, &fmt); + + fmt_dump(fmt); + done(0); + return 1; } static void fmt_dump (struct format *fmth) { - int i; - register struct format *fmt, *addr; - - /* Assign labels */ - for (fmt = fmth; fmt; ++fmt) { - i = fmt->f_type; - if (i == FT_IF_S || - i == FT_IF_S_NULL || - i == FT_IF_V_EQ || - i == FT_IF_V_NE || - i == FT_IF_V_GT || - i == FT_IF_MATCH || - i == FT_IF_AMATCH || - i == FT_GOTO) { - addr = fmt + fmt->f_skip; - if (findlabel(addr) < 0) - assignlabel(addr); + int i; + register struct format *fmt, *addr; + + /* Assign labels */ + for (fmt = fmth; fmt; ++fmt) { + i = fmt->f_type; + if (i == FT_IF_S || + i == FT_IF_S_NULL || + i == FT_IF_V_EQ || + i == FT_IF_V_NE || + i == FT_IF_V_GT || + i == FT_IF_MATCH || + i == FT_IF_AMATCH || + i == FT_GOTO) { + addr = fmt + fmt->f_skip; + if (findlabel(addr) < 0) + assignlabel(addr); + } + if (fmt->f_type == FT_DONE && fmt->f_value == 0) + break; } - if (fmt->f_type == FT_DONE && fmt->f_value == 0) - break; - } - /* Dump them out! */ - for (fmt = fmth; fmt; ++fmt) { - dumpone(fmt); - if (fmt->f_type == FT_DONE && fmt->f_value == 0) - break; - } + /* Dump them out! */ + for (fmt = fmth; fmt; ++fmt) { + dumpone(fmt); + if (fmt->f_type == FT_DONE && fmt->f_value == 0) + break; + } } static void dumpone(struct format *fmt) { - register int i; - - if ((i = findlabel(fmt)) >= 0) - printf("L%d:", i); - putchar('\t'); - - fputs(f_typestr((int)fmt->f_type), stdout); - - switch (fmt->f_type) { - - case FT_COMP: - case FT_LS_COMP: - case FT_LV_COMPFLAG: - case FT_LV_COMP: - printf(", comp "); - litputs(fmt->f_comp->c_name); - if (fmt->f_comp->c_type) - printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); - if (fmt->f_comp->c_flags) - printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); - break; - - case FT_LV_SEC: - case FT_LV_MIN: - case FT_LV_HOUR: - case FT_LV_MDAY: - case FT_LV_MON: - case FT_LS_MONTH: - case FT_LS_LMONTH: - case FT_LS_ZONE: - case FT_LV_YEAR: - case FT_LV_WDAY: - case FT_LS_DAY: - case FT_LS_WEEKDAY: - case FT_LV_YDAY: - case FT_LV_ZONE: - case FT_LV_CLOCK: - case FT_LV_RCLOCK: - case FT_LV_DAYF: - case FT_LV_ZONEF: - case FT_LV_DST: - case FT_LS_822DATE: - case FT_LS_PRETTY: - case FT_LOCALDATE: - case FT_GMTDATE: - case FT_PARSEDATE: - printf(", c_name "); - litputs(fmt->f_comp->c_name); - if (fmt->f_comp->c_type) - printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); - if (fmt->f_comp->c_flags) - printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); - break; - - case FT_LS_ADDR: - case FT_LS_PERS: - case FT_LS_MBOX: - case FT_LS_HOST: - case FT_LS_PATH: - case FT_LS_GNAME: - case FT_LS_NOTE: - case FT_LS_822ADDR: - case FT_LV_HOSTTYPE: - case FT_LV_INGRPF: - case FT_LV_NOHOSTF: - case FT_LS_FRIENDLY: - case FT_PARSEADDR: - case FT_MYMBOX: - printf(", c_name "); - litputs(fmt->f_comp->c_name); - if (fmt->f_comp->c_type) - printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); - if (fmt->f_comp->c_flags) - printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); - break; - - case FT_COMPF: - printf(", width %d, fill '", fmt->f_width); - litputc(fmt->f_fill); - printf("' name "); - litputs(fmt->f_comp->c_name); - if (fmt->f_comp->c_type) - printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); - if (fmt->f_comp->c_flags) - printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); - break; - - case FT_STRF: - case FT_NUMF: - printf(", width %d, fill '", fmt->f_width); - litputc(fmt->f_fill); - putchar('\''); - break; - - case FT_LIT: + register int i; + + if ((i = findlabel(fmt)) >= 0) + printf("L%d:", i); + putchar('\t'); + + fputs(f_typestr((int)fmt->f_type), stdout); + + switch (fmt->f_type) { + + case FT_COMP: + case FT_LS_COMP: + case FT_LV_COMPFLAG: + case FT_LV_COMP: + printf(", comp "); + litputs(fmt->f_comp->c_name); + if (fmt->f_comp->c_type) + printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); + if (fmt->f_comp->c_flags) + printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); + break; + + case FT_LV_SEC: + case FT_LV_MIN: + case FT_LV_HOUR: + case FT_LV_MDAY: + case FT_LV_MON: + case FT_LS_MONTH: + case FT_LS_LMONTH: + case FT_LS_ZONE: + case FT_LV_YEAR: + case FT_LV_WDAY: + case FT_LS_DAY: + case FT_LS_WEEKDAY: + case FT_LV_YDAY: + case FT_LV_ZONE: + case FT_LV_CLOCK: + case FT_LV_RCLOCK: + case FT_LV_DAYF: + case FT_LV_ZONEF: + case FT_LV_DST: + case FT_LS_822DATE: + case FT_LS_PRETTY: + case FT_LOCALDATE: + case FT_GMTDATE: + case FT_PARSEDATE: + printf(", c_name "); + litputs(fmt->f_comp->c_name); + if (fmt->f_comp->c_type) + printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); + if (fmt->f_comp->c_flags) + printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); + break; + + case FT_LS_ADDR: + case FT_LS_PERS: + case FT_LS_MBOX: + case FT_LS_HOST: + case FT_LS_PATH: + case FT_LS_GNAME: + case FT_LS_NOTE: + case FT_LS_822ADDR: + case FT_LV_HOSTTYPE: + case FT_LV_INGRPF: + case FT_LV_NOHOSTF: + case FT_LS_FRIENDLY: + case FT_PARSEADDR: + case FT_MYMBOX: + printf(", c_name "); + litputs(fmt->f_comp->c_name); + if (fmt->f_comp->c_type) + printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); + if (fmt->f_comp->c_flags) + printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); + break; + + case FT_COMPF: + printf(", width %d, fill '", fmt->f_width); + litputc(fmt->f_fill); + printf("' name "); + litputs(fmt->f_comp->c_name); + if (fmt->f_comp->c_type) + printf(", c_type %s", c_typestr(fmt->f_comp->c_type)); + if (fmt->f_comp->c_flags) + printf(", c_flags %s", c_flagsstr(fmt->f_comp->c_flags)); + break; + + case FT_STRF: + case FT_NUMF: + printf(", width %d, fill '", fmt->f_width); + litputc(fmt->f_fill); + putchar('\''); + break; + + case FT_LIT: #ifdef FT_LIT_FORCE - case FT_LIT_FORCE: + case FT_LIT_FORCE: #endif - putchar(' '); - litputs(fmt->f_text); - break; - - case FT_LITF: - printf(", width %d, fill '", fmt->f_width); - litputc(fmt->f_fill); - printf("' "); - litputs(fmt->f_text); - break; - - case FT_CHAR: - putchar(' '); - putchar('\''); - litputc(fmt->f_char); - putchar('\''); - break; - - - case FT_IF_S: - case FT_IF_S_NULL: - case FT_IF_MATCH: - case FT_IF_AMATCH: - printf(" continue else goto"); - case FT_GOTO: - i = findlabel(fmt + fmt->f_skip); - printf(" L%d", i); - break; - - case FT_IF_V_EQ: - case FT_IF_V_NE: - case FT_IF_V_GT: - i = findlabel(fmt + fmt->f_skip); - printf(" %d continue else goto L%d", fmt->f_value, i); - break; - - case FT_V_EQ: - case FT_V_NE: - case FT_V_GT: - case FT_LV_LIT: - case FT_LV_PLUS_L: - case FT_LV_MINUS_L: - case FT_LV_DIVIDE_L: - case FT_LV_MODULO_L: - printf(" value %d", fmt->f_value); - break; - - case FT_LS_LIT: - printf(" str "); - litputs(fmt->f_text); - break; - - case FT_LS_GETENV: - printf(" getenv "); - litputs(fmt->f_text); - break; - - case FT_LS_DECODECOMP: - printf(", comp "); - litputs(fmt->f_comp->c_name); - break; - - case FT_LS_DECODE: - break; - - case FT_LS_TRIM: - printf(", width %d", fmt->f_width); - break; - - case FT_LV_DAT: - printf(", value dat[%d]", fmt->f_value); - break; - } - putchar('\n'); + putchar(' '); + litputs(fmt->f_text); + break; + + case FT_LITF: + printf(", width %d, fill '", fmt->f_width); + litputc(fmt->f_fill); + printf("' "); + litputs(fmt->f_text); + break; + + case FT_CHAR: + putchar(' '); + putchar('\''); + litputc(fmt->f_char); + putchar('\''); + break; + + + case FT_IF_S: + case FT_IF_S_NULL: + case FT_IF_MATCH: + case FT_IF_AMATCH: + printf(" continue else goto"); + case FT_GOTO: + i = findlabel(fmt + fmt->f_skip); + printf(" L%d", i); + break; + + case FT_IF_V_EQ: + case FT_IF_V_NE: + case FT_IF_V_GT: + i = findlabel(fmt + fmt->f_skip); + printf(" %d continue else goto L%d", fmt->f_value, i); + break; + + case FT_V_EQ: + case FT_V_NE: + case FT_V_GT: + case FT_LV_LIT: + case FT_LV_PLUS_L: + case FT_LV_MINUS_L: + case FT_LV_DIVIDE_L: + case FT_LV_MODULO_L: + printf(" value %d", fmt->f_value); + break; + + case FT_LS_LIT: + printf(" str "); + litputs(fmt->f_text); + break; + + case FT_LS_GETENV: + printf(" getenv "); + litputs(fmt->f_text); + break; + + case FT_LS_DECODECOMP: + printf(", comp "); + litputs(fmt->f_comp->c_name); + break; + + case FT_LS_DECODE: + break; + + case FT_LS_TRIM: + printf(", width %d", fmt->f_width); + break; + + case FT_LV_DAT: + printf(", value dat[%d]", fmt->f_value); + break; + } + putchar('\n'); } static int findlabel(struct format *addr) { - register int i; + register int i; - for (i = 0; i < lused; ++i) - if (addr == lvec[i]) - return(i); - return(-1); + for (i = 0; i < lused; ++i) + if (addr == lvec[i]) + return(i); + return(-1); } static void assignlabel(struct format *addr) { - lvec[lused++] = addr; + lvec[lused++] = addr; } static char * f_typestr(int t) { - static char buf[32]; - - switch (t) { - case FT_COMP: return("COMP"); - case FT_COMPF: return("COMPF"); - case FT_LIT: return("LIT"); - case FT_LITF: return("LITF"); -#ifdef FT_LIT_FORCE - case FT_LIT_FORCE: return("LIT_FORCE"); + static char buf[32]; + + switch (t) { + case FT_COMP: return("COMP"); + case FT_COMPF: return("COMPF"); + case FT_LIT: return("LIT"); + case FT_LITF: return("LITF"); +#ifdef FT_LIT_FORCE + case FT_LIT_FORCE: return("LIT_FORCE"); #endif - case FT_CHAR: return("CHAR"); - case FT_NUM: return("NUM"); - case FT_NUMF: return("NUMF"); - case FT_STR: return("STR"); - case FT_STRF: return("STRF"); - case FT_STRFW: return("STRFW"); - case FT_PUTADDR: return("PUTADDR"); - case FT_LS_COMP: return("LS_COMP"); - case FT_LS_LIT: return("LS_LIT"); - case FT_LS_GETENV: return("LS_GETENV"); - case FT_LS_DECODECOMP: return("FT_LS_DECODECOMP"); - case FT_LS_DECODE: return("FT_LS_DECODE"); - case FT_LS_TRIM: return("LS_TRIM"); - case FT_LV_COMP: return("LV_COMP"); - case FT_LV_COMPFLAG: return("LV_COMPFLAG"); - case FT_LV_LIT: return("LV_LIT"); - case FT_LV_DAT: return("LV_DAT"); - case FT_LV_STRLEN: return("LV_STRLEN"); - case FT_LV_PLUS_L: return("LV_PLUS_L"); - case FT_LV_MINUS_L: return("LV_MINUS_L"); - case FT_LV_DIVIDE_L: return("LV_DIVIDE_L"); - case FT_LV_MODULO_L: return("LV_MODULO_L"); - case FT_LV_CHAR_LEFT: return("LV_CHAR_LEFT"); - case FT_LS_MONTH: return("LS_MONTH"); - case FT_LS_LMONTH: return("LS_LMONTH"); - case FT_LS_ZONE: return("LS_ZONE"); - case FT_LS_DAY: return("LS_DAY"); - case FT_LS_WEEKDAY: return("LS_WEEKDAY"); - case FT_LS_822DATE: return("LS_822DATE"); - case FT_LS_PRETTY: return("LS_PRETTY"); - case FT_LV_SEC: return("LV_SEC"); - case FT_LV_MIN: return("LV_MIN"); - case FT_LV_HOUR: return("LV_HOUR"); - case FT_LV_MDAY: return("LV_MDAY"); - case FT_LV_MON: return("LV_MON"); - case FT_LV_YEAR: return("LV_YEAR"); - case FT_LV_YDAY: return("LV_YDAY"); - case FT_LV_WDAY: return("LV_WDAY"); - case FT_LV_ZONE: return("LV_ZONE"); - case FT_LV_CLOCK: return("LV_CLOCK"); - case FT_LV_RCLOCK: return("LV_RCLOCK"); - case FT_LV_DAYF: return("LV_DAYF"); - case FT_LV_DST: return("LV_DST"); - case FT_LV_ZONEF: return("LV_ZONEF"); - case FT_LS_ADDR: return("LS_ADDR"); - case FT_LS_PERS: return("LS_PERS"); - case FT_LS_MBOX: return("LS_MBOX"); - case FT_LS_HOST: return("LS_HOST"); - case FT_LS_PATH: return("LS_PATH"); - case FT_LS_GNAME: return("LS_GNAME"); - case FT_LS_NOTE: return("LS_NOTE"); - case FT_LS_822ADDR: return("LS_822ADDR"); - case FT_LS_FRIENDLY: return("LS_FRIENDLY"); - case FT_LV_HOSTTYPE: return("LV_HOSTTYPE"); - case FT_LV_INGRPF: return("LV_INGRPF"); - case FT_LV_NOHOSTF: return("LV_NOHOSTF"); - case FT_LOCALDATE: return("LOCALDATE"); - case FT_GMTDATE: return("GMTDATE"); - case FT_PARSEDATE: return("PARSEDATE"); - case FT_PARSEADDR: return("PARSEADDR"); - case FT_FORMATADDR: return("FORMATADDR"); - case FT_MYMBOX: return("MYMBOX"); -#ifdef FT_ADDTOSEQ - case FT_ADDTOSEQ: return("ADDTOSEQ"); + case FT_CHAR: return("CHAR"); + case FT_NUM: return("NUM"); + case FT_NUMF: return("NUMF"); + case FT_STR: return("STR"); + case FT_STRF: return("STRF"); + case FT_STRFW: return("STRFW"); + case FT_PUTADDR: return("PUTADDR"); + case FT_LS_COMP: return("LS_COMP"); + case FT_LS_LIT: return("LS_LIT"); + case FT_LS_GETENV: return("LS_GETENV"); + case FT_LS_DECODECOMP: return("FT_LS_DECODECOMP"); + case FT_LS_DECODE: return("FT_LS_DECODE"); + case FT_LS_TRIM: return("LS_TRIM"); + case FT_LV_COMP: return("LV_COMP"); + case FT_LV_COMPFLAG: return("LV_COMPFLAG"); + case FT_LV_LIT: return("LV_LIT"); + case FT_LV_DAT: return("LV_DAT"); + case FT_LV_STRLEN: return("LV_STRLEN"); + case FT_LV_PLUS_L: return("LV_PLUS_L"); + case FT_LV_MINUS_L: return("LV_MINUS_L"); + case FT_LV_DIVIDE_L: return("LV_DIVIDE_L"); + case FT_LV_MODULO_L: return("LV_MODULO_L"); + case FT_LV_CHAR_LEFT: return("LV_CHAR_LEFT"); + case FT_LS_MONTH: return("LS_MONTH"); + case FT_LS_LMONTH: return("LS_LMONTH"); + case FT_LS_ZONE: return("LS_ZONE"); + case FT_LS_DAY: return("LS_DAY"); + case FT_LS_WEEKDAY: return("LS_WEEKDAY"); + case FT_LS_822DATE: return("LS_822DATE"); + case FT_LS_PRETTY: return("LS_PRETTY"); + case FT_LV_SEC: return("LV_SEC"); + case FT_LV_MIN: return("LV_MIN"); + case FT_LV_HOUR: return("LV_HOUR"); + case FT_LV_MDAY: return("LV_MDAY"); + case FT_LV_MON: return("LV_MON"); + case FT_LV_YEAR: return("LV_YEAR"); + case FT_LV_YDAY: return("LV_YDAY"); + case FT_LV_WDAY: return("LV_WDAY"); + case FT_LV_ZONE: return("LV_ZONE"); + case FT_LV_CLOCK: return("LV_CLOCK"); + case FT_LV_RCLOCK: return("LV_RCLOCK"); + case FT_LV_DAYF: return("LV_DAYF"); + case FT_LV_DST: return("LV_DST"); + case FT_LV_ZONEF: return("LV_ZONEF"); + case FT_LS_ADDR: return("LS_ADDR"); + case FT_LS_PERS: return("LS_PERS"); + case FT_LS_MBOX: return("LS_MBOX"); + case FT_LS_HOST: return("LS_HOST"); + case FT_LS_PATH: return("LS_PATH"); + case FT_LS_GNAME: return("LS_GNAME"); + case FT_LS_NOTE: return("LS_NOTE"); + case FT_LS_822ADDR: return("LS_822ADDR"); + case FT_LS_FRIENDLY: return("LS_FRIENDLY"); + case FT_LV_HOSTTYPE: return("LV_HOSTTYPE"); + case FT_LV_INGRPF: return("LV_INGRPF"); + case FT_LV_NOHOSTF: return("LV_NOHOSTF"); + case FT_LOCALDATE: return("LOCALDATE"); + case FT_GMTDATE: return("GMTDATE"); + case FT_PARSEDATE: return("PARSEDATE"); + case FT_PARSEADDR: return("PARSEADDR"); + case FT_FORMATADDR: return("FORMATADDR"); + case FT_MYMBOX: return("MYMBOX"); +#ifdef FT_ADDTOSEQ + case FT_ADDTOSEQ: return("ADDTOSEQ"); #endif - case FT_SAVESTR: return("SAVESTR"); -#ifdef FT_PAUSE - case FT_PAUSE: return ("PAUSE"); + case FT_SAVESTR: return("SAVESTR"); +#ifdef FT_PAUSE + case FT_PAUSE: return ("PAUSE"); #endif - case FT_DONE: return("DONE"); - case FT_NOP: return("NOP"); - case FT_GOTO: return("GOTO"); - case FT_IF_S_NULL: return("IF_S_NULL"); - case FT_IF_S: return("IF_S"); - case FT_IF_V_EQ: return("IF_V_EQ"); - case FT_IF_V_NE: return("IF_V_NE"); - case FT_IF_V_GT: return("IF_V_GT"); - case FT_IF_MATCH: return("IF_MATCH"); - case FT_IF_AMATCH: return("IF_AMATCH"); - case FT_S_NULL: return("S_NULL"); - case FT_S_NONNULL: return("S_NONNULL"); - case FT_V_EQ: return("V_EQ"); - case FT_V_NE: return("V_NE"); - case FT_V_GT: return("V_GT"); - case FT_V_MATCH: return("V_MATCH"); - case FT_V_AMATCH: return("V_AMATCH"); - default: - printf(buf, "/* ??? #%d */", t); - return(buf); - } + case FT_DONE: return("DONE"); + case FT_NOP: return("NOP"); + case FT_GOTO: return("GOTO"); + case FT_IF_S_NULL: return("IF_S_NULL"); + case FT_IF_S: return("IF_S"); + case FT_IF_V_EQ: return("IF_V_EQ"); + case FT_IF_V_NE: return("IF_V_NE"); + case FT_IF_V_GT: return("IF_V_GT"); + case FT_IF_MATCH: return("IF_MATCH"); + case FT_IF_AMATCH: return("IF_AMATCH"); + case FT_S_NULL: return("S_NULL"); + case FT_S_NONNULL: return("S_NONNULL"); + case FT_V_EQ: return("V_EQ"); + case FT_V_NE: return("V_NE"); + case FT_V_GT: return("V_GT"); + case FT_V_MATCH: return("V_MATCH"); + case FT_V_AMATCH: return("V_AMATCH"); + default: + printf(buf, "/* ??? #%d */", t); + return(buf); + } } #define FNORD(v, s) if (t & (v)) { \ - if (i++ > 0) \ - strcat(buf, "|"); \ - strcat(buf, s); } + if (i++ > 0) \ + strcat(buf, "|"); \ + strcat(buf, s); } static char * c_typestr(int t) { - register int i; - static char buf[64]; - - buf[0] = '\0'; - if (t & ~(CT_ADDR|CT_DATE)) - printf(buf, "0x%x ", t); - strcat(buf, "<"); - i = 0; - FNORD(CT_ADDR, "ADDR"); - FNORD(CT_DATE, "DATE"); - strcat(buf, ">"); - return(buf); + register int i; + static char buf[64]; + + buf[0] = '\0'; + if (t & ~(CT_ADDR|CT_DATE)) + printf(buf, "0x%x ", t); + strcat(buf, "<"); + i = 0; + FNORD(CT_ADDR, "ADDR"); + FNORD(CT_DATE, "DATE"); + strcat(buf, ">"); + return(buf); } static char * c_flagsstr(int t) { - register int i; - static char buf[64]; - - buf[0] = '\0'; - if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB)) - printf(buf, "0x%x ", t); - strcat(buf, "<"); - i = 0; - FNORD(CF_TRUE, "TRUE"); - FNORD(CF_PARSED, "PARSED"); - FNORD(CF_DATEFAB, "DATEFAB"); - strcat(buf, ">"); - return(buf); + register int i; + static char buf[64]; + + buf[0] = '\0'; + if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB)) + printf(buf, "0x%x ", t); + strcat(buf, "<"); + i = 0; + FNORD(CF_TRUE, "TRUE"); + FNORD(CF_PARSED, "PARSED"); + FNORD(CF_DATEFAB, "DATEFAB"); + strcat(buf, ">"); + return(buf); } #undef FNORD static void litputs(char *s) { - if (s) { - putc('"', stdout); - while (*s) - litputc(*s++); - putc('"', stdout); - } else - fputs("", stdout); + if (s) { + putc('"', stdout); + while (*s) + litputc(*s++); + putc('"', stdout); + } else + fputs("", stdout); } static void litputc(char c) { - if (c & ~ 0177) { - putc('M', stdout); - putc('-', stdout); - c &= 0177; - } - if (c < 0x20 || c == 0177) { - if (c == '\b') { - putc('\\', stdout); - putc('b', stdout); - } else if (c == '\f') { - putc('\\', stdout); - putc('f', stdout); - } else if (c == '\n') { - putc('\\', stdout); - putc('n', stdout); - } else if (c == '\r') { - putc('\\', stdout); - putc('r', stdout); - } else if (c == '\t') { - putc('\\', stdout); - putc('t', stdout); - } else { - putc('^', stdout); - putc(c ^ 0x40, stdout); /* DEL to ?, others to alpha */ + if (c & ~ 0177) { + putc('M', stdout); + putc('-', stdout); + c &= 0177; } - } else - putc(c, stdout); + if (c < 0x20 || c == 0177) { + if (c == '\b') { + putc('\\', stdout); + putc('b', stdout); + } else if (c == '\f') { + putc('\\', stdout); + putc('f', stdout); + } else if (c == '\n') { + putc('\\', stdout); + putc('n', stdout); + } else if (c == '\r') { + putc('\\', stdout); + putc('r', stdout); + } else if (c == '\t') { + putc('\\', stdout); + putc('t', stdout); + } else { + putc('^', stdout); + putc(c ^ 0x40, stdout); + /* DEL to ?, others to alpha */ + } + } else + putc(c, stdout); } diff --git a/uip/folder.c b/uip/folder.c index 3e7c85d..6f0f8b8 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -1,4 +1,3 @@ - /* * folder(s).c -- set/list the current message and/or folder * -- push/pop a folder onto/from the folder stack @@ -15,67 +14,67 @@ #include static struct swit switches[] = { -#define ALLSW 0 - { "all", 0 }, -#define NALLSW 1 - { "noall", 0 }, -#define CREATSW 2 - { "create", 0 }, -#define NCREATSW 3 - { "nocreate", 0 }, -#define FASTSW 4 - { "fast", 0 }, -#define NFASTSW 5 - { "nofast", 0 }, -#define HDRSW 6 - { "header", 0 }, -#define NHDRSW 7 - { "noheader", 0 }, -#define PACKSW 8 - { "pack", 0 }, -#define NPACKSW 9 - { "nopack", 0 }, -#define VERBSW 10 - { "verbose", 0 }, -#define NVERBSW 11 - { "noverbose", 0 }, -#define RECURSW 12 - { "recurse", 0 }, -#define NRECRSW 13 - { "norecurse", 0 }, -#define TOTALSW 14 - { "total", 0 }, -#define NTOTLSW 15 - { "nototal", 0 }, -#define LISTSW 16 - { "list", 0 }, -#define NLISTSW 17 - { "nolist", 0 }, -#define PRNTSW 18 - { "print", 0 }, -#define NPRNTSW 19 - { "noprint", -4 }, -#define PUSHSW 20 - { "push", 0 }, -#define POPSW 21 - { "pop", 0 }, -#define VERSIONSW 22 - { "version", 0 }, -#define HELPSW 23 - { "help", 0 }, - { NULL, 0 } +#define ALLSW 0 + { "all", 0 }, +#define NALLSW 1 + { "noall", 0 }, +#define CREATSW 2 + { "create", 0 }, +#define NCREATSW 3 + { "nocreate", 0 }, +#define FASTSW 4 + { "fast", 0 }, +#define NFASTSW 5 + { "nofast", 0 }, +#define HDRSW 6 + { "header", 0 }, +#define NHDRSW 7 + { "noheader", 0 }, +#define PACKSW 8 + { "pack", 0 }, +#define NPACKSW 9 + { "nopack", 0 }, +#define VERBSW 10 + { "verbose", 0 }, +#define NVERBSW 11 + { "noverbose", 0 }, +#define RECURSW 12 + { "recurse", 0 }, +#define NRECRSW 13 + { "norecurse", 0 }, +#define TOTALSW 14 + { "total", 0 }, +#define NTOTLSW 15 + { "nototal", 0 }, +#define LISTSW 16 + { "list", 0 }, +#define NLISTSW 17 + { "nolist", 0 }, +#define PRNTSW 18 + { "print", 0 }, +#define NPRNTSW 19 + { "noprint", -4 }, +#define PUSHSW 20 + { "push", 0 }, +#define POPSW 21 + { "pop", 0 }, +#define VERSIONSW 22 + { "version", 0 }, +#define HELPSW 23 + { "help", 0 }, + { NULL, 0 } }; -static int fshort = 0; /* output only folder names */ -static int fcreat = 0; /* should we ask to create new folders? */ -static int fpack = 0; /* are we packing the folder? */ -static int fverb = 0; /* print actions taken while packing folder */ -static int fheader = 0; /* should we output a header? */ -static int frecurse = 0; /* recurse through subfolders */ -static int ftotal = 0; /* should we output the totals? */ -static int all = 0; /* should we output all folders */ +static int fshort = 0; /* output only folder names */ +static int fcreat = 0; /* should we ask to create new folders? */ +static int fpack = 0; /* are we packing the folder? */ +static int fverb = 0; /* print actions taken while packing folder */ +static int fheader = 0; /* should we output a header? */ +static int frecurse = 0; /* recurse through subfolders */ +static int ftotal = 0; /* should we output the totals? */ +static int all = 0; /* should we output all folders */ -static int total_folders = 0; /* total number of folders */ +static int total_folders = 0; /* total number of folders */ static char *nmhdir; static char *stack = "Folder-Stack"; @@ -86,13 +85,13 @@ static char folder[BUFSIZ]; * folders as we scan them. */ struct FolderInfo { - char *name; - int nummsg; - int curmsg; - int lowmsg; - int hghmsg; - int others; /* others == 1 if other files in folder */ - int error; /* error == 1 for unreadable folder */ + char *name; + int nummsg; + int curmsg; + int lowmsg; + int hghmsg; + int others; /* others == 1 if other files in folder */ + int error; /* error == 1 for unreadable folder */ }; /* @@ -115,367 +114,367 @@ static void readonly_folders (void); int main (int argc, char **argv) { - int printsw = 0, listsw = 0; - int pushsw = 0, popsw = 0; - char *cp, *dp, *msg = NULL, *argfolder = NULL; - char **ap, **argp, buf[BUFSIZ], **arguments; + int printsw = 0, listsw = 0; + int pushsw = 0, popsw = 0; + char *cp, *dp, *msg = NULL, *argfolder = NULL; + char **ap, **argp, buf[BUFSIZ], **arguments; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - /* - * If program was invoked with name ending - * in `s', then add switch `-all'. - */ - if (argv[0][strlen (argv[0]) - 1] == 's') - all = 1; - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ALLSW: - all = 1; - continue; - - case NALLSW: - all = 0; - continue; - - case CREATSW: - fcreat = 1; - continue; - case NCREATSW: - fcreat = -1; - continue; - - case FASTSW: - fshort++; - continue; - case NFASTSW: - fshort = 0; - continue; - - case HDRSW: - fheader = 1; - continue; - case NHDRSW: - fheader = -1; - continue; - - case PACKSW: - fpack++; - continue; - case NPACKSW: - fpack = 0; - continue; - - case VERBSW: - fverb++; - continue; - case NVERBSW: - fverb = 0; - continue; - - case RECURSW: - frecurse++; - continue; - case NRECRSW: - frecurse = 0; - continue; - - case TOTALSW: - ftotal = 1; - continue; - case NTOTLSW: - ftotal = -1; - continue; - - case PRNTSW: - printsw = 1; - continue; - case NPRNTSW: - printsw = 0; - continue; - - case LISTSW: - listsw = 1; - continue; - case NLISTSW: - listsw = 0; - continue; - - case PUSHSW: - pushsw = 1; - listsw = 1; - popsw = 0; - continue; - case POPSW: - popsw = 1; - listsw = 1; - pushsw = 0; - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (argfolder) - adios (NULL, "only one folder at a time!"); - else - argfolder = pluspath (cp); - } else { - if (msg) - adios (NULL, "only one (current) message at a time!"); - else - msg = cp; - } - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - nmhdir = concat (m_maildir (""), "/", NULL); - - /* - * If we aren't working with the folder stack - * (-push, -pop, -list) then the default is to print. - */ - if (pushsw == 0 && popsw == 0 && listsw == 0) - printsw++; - - /* Pushing a folder onto the folder stack */ - if (pushsw) { - if (!argfolder) { - /* If no folder is given, the current folder and */ - /* the top of the folder stack are swapped. */ - if ((cp = context_find (stack))) { - dp = getcpy (cp); - ap = brkstring (dp, " ", "\n"); - argfolder = getcpy(*ap++); - } else { - adios (NULL, "no other folder"); - } - for (cp = getcpy (getfolder (1)); *ap; ap++) - cp = add (*ap, add (" ", cp)); - free (dp); - context_replace (stack, cp); /* update folder stack */ - } else { - /* update folder stack */ - context_replace (stack, - (cp = context_find (stack)) - ? concat (getfolder (1), " ", cp, NULL) - : getcpy (getfolder (1))); + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + /* + * If program was invoked with name ending + * in `s', then add switch `-all'. + */ + if (argv[0][strlen (argv[0]) - 1] == 's') + all = 1; + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ALLSW: + all = 1; + continue; + + case NALLSW: + all = 0; + continue; + + case CREATSW: + fcreat = 1; + continue; + case NCREATSW: + fcreat = -1; + continue; + + case FASTSW: + fshort++; + continue; + case NFASTSW: + fshort = 0; + continue; + + case HDRSW: + fheader = 1; + continue; + case NHDRSW: + fheader = -1; + continue; + + case PACKSW: + fpack++; + continue; + case NPACKSW: + fpack = 0; + continue; + + case VERBSW: + fverb++; + continue; + case NVERBSW: + fverb = 0; + continue; + + case RECURSW: + frecurse++; + continue; + case NRECRSW: + frecurse = 0; + continue; + + case TOTALSW: + ftotal = 1; + continue; + case NTOTLSW: + ftotal = -1; + continue; + + case PRNTSW: + printsw = 1; + continue; + case NPRNTSW: + printsw = 0; + continue; + + case LISTSW: + listsw = 1; + continue; + case NLISTSW: + listsw = 0; + continue; + + case PUSHSW: + pushsw = 1; + listsw = 1; + popsw = 0; + continue; + case POPSW: + popsw = 1; + listsw = 1; + pushsw = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (argfolder) + adios (NULL, "only one folder at a time!"); + else + argfolder = pluspath (cp); + } else { + if (msg) + adios (NULL, "only one (current) message at a time!"); + else + msg = cp; + } } - } - - /* Popping a folder off of the folder stack */ - if (popsw) { - if (argfolder) - adios (NULL, "sorry, no folders allowed with -pop"); - if ((cp = context_find (stack))) { - dp = getcpy (cp); - ap = brkstring (dp, " ", "\n"); - argfolder = getcpy(*ap++); - } else { - adios (NULL, "folder stack empty"); + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + nmhdir = concat (m_maildir (""), "/", NULL); + + /* + * If we aren't working with the folder stack + * (-push, -pop, -list) then the default is to print. + */ + if (pushsw == 0 && popsw == 0 && listsw == 0) + printsw++; + + /* Pushing a folder onto the folder stack */ + if (pushsw) { + if (!argfolder) { + /* If no folder is given, the current folder and */ + /* the top of the folder stack are swapped. */ + if ((cp = context_find (stack))) { + dp = getcpy (cp); + ap = brkstring (dp, " ", "\n"); + argfolder = getcpy(*ap++); + } else { + adios (NULL, "no other folder"); + } + for (cp = getcpy (getfolder (1)); *ap; ap++) + cp = add (*ap, add (" ", cp)); + free (dp); + context_replace (stack, cp); /* update folder stack */ + } else { + /* update folder stack */ + context_replace (stack, + (cp = context_find (stack)) + ? concat (getfolder (1), " ", cp, NULL) + : getcpy (getfolder (1))); + } } - if (*ap) { - /* if there's anything left in the stack */ - cp = getcpy (*ap++); - for (; *ap; ap++) - cp = add (*ap, add (" ", cp)); - context_replace (stack, cp); /* update folder stack */ - } else { - context_del (stack); /* delete folder stack entry from context */ + + /* Popping a folder off of the folder stack */ + if (popsw) { + if (argfolder) + adios (NULL, "sorry, no folders allowed with -pop"); + if ((cp = context_find (stack))) { + dp = getcpy (cp); + ap = brkstring (dp, " ", "\n"); + argfolder = getcpy(*ap++); + } else { + adios (NULL, "folder stack empty"); + } + if (*ap) { + /* if there's anything left in the stack */ + cp = getcpy (*ap++); + for (; *ap; ap++) + cp = add (*ap, add (" ", cp)); + context_replace (stack, cp); /* update folder stack */ + } else { + context_del (stack); /* delete folder stack entry from context */ + } + free (dp); } - free (dp); - } - if (pushsw || popsw) { - cp = m_maildir(argfolder); - if (access (cp, F_OK) == NOTOK) - adios (cp, "unable to find folder"); - context_replace (pfolder, argfolder); /* update current folder */ - context_save (); /* save the context file */ - argfolder = NULL; - } - - /* Listing the folder stack */ - if (listsw) { - printf ("%s", argfolder ? argfolder : getfolder (1)); - if ((cp = context_find (stack))) { - dp = getcpy (cp); - for (ap = brkstring (dp, " ", "\n"); *ap; ap++) - printf (" %s", *ap); - free (dp); + if (pushsw || popsw) { + cp = m_maildir(argfolder); + if (access (cp, F_OK) == NOTOK) + adios (cp, "unable to find folder"); + context_replace (pfolder, argfolder); /* update current folder */ + context_save (); /* save the context file */ + argfolder = NULL; } - printf ("\n"); - if (!printsw) - done (0); - } + /* Listing the folder stack */ + if (listsw) { + printf ("%s", argfolder ? argfolder : getfolder (1)); + if ((cp = context_find (stack))) { + dp = getcpy (cp); + for (ap = brkstring (dp, " ", "\n"); *ap; ap++) + printf (" %s", *ap); + free (dp); + } + printf ("\n"); + + if (!printsw) + done (0); + } - /* Allocate initial space to record folder information */ - maxFolderInfo = CRAWL_NUMFOLDERS; - fi = mh_xmalloc (maxFolderInfo * sizeof(*fi)); + /* Allocate initial space to record folder information */ + maxFolderInfo = CRAWL_NUMFOLDERS; + fi = mh_xmalloc (maxFolderInfo * sizeof(*fi)); - /* - * Scan the folders - */ - if (all || ftotal > 0) { /* - * If no folder is given, do them all + * Scan the folders */ - /* change directory to base of nmh directory for crawl_folders */ - if (chdir (nmhdir) == NOTOK) - adios (nmhdir, "unable to change directory to"); - if (!argfolder) { - if (msg) - admonish (NULL, "no folder given for message %s", msg); - readonly_folders (); /* do any readonly folders */ - strncpy (folder, (cp = context_find (pfolder)) ? cp : "", sizeof(folder)); - crawl_folders (".", get_folder_info_callback, NULL); + if (all || ftotal > 0) { + /* + * If no folder is given, do them all + */ + /* change directory to base of nmh directory for crawl_folders */ + if (chdir (nmhdir) == NOTOK) + adios (nmhdir, "unable to change directory to"); + if (!argfolder) { + if (msg) + admonish (NULL, "no folder given for message %s", msg); + readonly_folders (); /* do any readonly folders */ + strncpy (folder, (cp = context_find (pfolder)) ? cp : "", sizeof(folder)); + crawl_folders (".", get_folder_info_callback, NULL); + } else { + strncpy (folder, argfolder, sizeof(folder)); + if (get_folder_info (argfolder, msg)) { + context_replace (pfolder, argfolder);/* update current folder */ + context_save (); /* save the context file */ + } + /* + * Since recurse wasn't done in get_folder_info(), + * we still need to list all level-1 sub-folders. + */ + if (!frecurse) + crawl_folders (folder, get_folder_info_callback, NULL); + } } else { - strncpy (folder, argfolder, sizeof(folder)); - if (get_folder_info (argfolder, msg)) { - context_replace (pfolder, argfolder);/* update current folder */ - context_save (); /* save the context file */ - } - /* - * Since recurse wasn't done in get_folder_info(), - * we still need to list all level-1 sub-folders. - */ - if (!frecurse) - crawl_folders (folder, get_folder_info_callback, NULL); + strncpy (folder, argfolder ? argfolder : getfolder (1), sizeof(folder)); + + /* + * Check if folder exists. If not, then see if + * we should create it, or just exit. + */ + create_folder (m_maildir (folder), fcreat, done); + + if (get_folder_info (folder, msg) && argfolder) { + /* update current folder */ + context_replace (pfolder, argfolder); + } } - } else { - strncpy (folder, argfolder ? argfolder : getfolder (1), sizeof(folder)); /* - * Check if folder exists. If not, then see if - * we should create it, or just exit. + * Print out folder information */ - create_folder (m_maildir (folder), fcreat, done); - - if (get_folder_info (folder, msg) && argfolder) { - /* update current folder */ - context_replace (pfolder, argfolder); - } - } - - /* - * Print out folder information - */ - print_folders(); - - context_save (); /* save the context file */ - done (0); - return 1; + print_folders(); + + context_save (); /* save the context file */ + done (0); + return 1; } static int get_folder_info_body (char *fold, char *msg, boolean *crawl_children) { - int i, retval = 1; - struct msgs *mp = NULL; - - i = total_folders++; - - /* - * if necessary, reallocate the space - * for folder information - */ - if (total_folders >= maxFolderInfo) { - maxFolderInfo += CRAWL_NUMFOLDERS; - fi = mh_xrealloc (fi, maxFolderInfo * sizeof(*fi)); - } - - fi[i].name = fold; - fi[i].nummsg = 0; - fi[i].curmsg = 0; - fi[i].lowmsg = 0; - fi[i].hghmsg = 0; - fi[i].others = 0; - fi[i].error = 0; - - if ((ftotal > 0) || !fshort || msg || fpack) { + int i, retval = 1; + struct msgs *mp = NULL; + + i = total_folders++; + /* - * create message structure and get folder info + * if necessary, reallocate the space + * for folder information */ - if (!(mp = folder_read (fold))) { - admonish (NULL, "unable to read folder %s", fold); - return 0; + if (total_folders >= maxFolderInfo) { + maxFolderInfo += CRAWL_NUMFOLDERS; + fi = mh_xrealloc (fi, maxFolderInfo * sizeof(*fi)); } - /* set the current message */ - if (msg && !sfold (mp, msg)) - retval = 0; + fi[i].name = fold; + fi[i].nummsg = 0; + fi[i].curmsg = 0; + fi[i].lowmsg = 0; + fi[i].hghmsg = 0; + fi[i].others = 0; + fi[i].error = 0; + + if ((ftotal > 0) || !fshort || msg || fpack) { + /* + * create message structure and get folder info + */ + if (!(mp = folder_read (fold))) { + admonish (NULL, "unable to read folder %s", fold); + return 0; + } - if (fpack) { - if (folder_pack (&mp, fverb) == -1) - done (1); - seq_save (mp); /* synchronize the sequences */ - context_save (); /* save the context file */ - } + /* set the current message */ + if (msg && !sfold (mp, msg)) + retval = 0; - /* record info for this folder */ - if ((ftotal > 0) || !fshort) { - fi[i].nummsg = mp->nummsg; - fi[i].curmsg = mp->curmsg; - fi[i].lowmsg = mp->lowmsg; - fi[i].hghmsg = mp->hghmsg; - fi[i].others = other_files (mp); - } + if (fpack) { + if (folder_pack (&mp, fverb) == -1) + done (1); + seq_save (mp); /* synchronize the sequences */ + context_save (); /* save the context file */ + } + + /* record info for this folder */ + if ((ftotal > 0) || !fshort) { + fi[i].nummsg = mp->nummsg; + fi[i].curmsg = mp->curmsg; + fi[i].lowmsg = mp->lowmsg; + fi[i].hghmsg = mp->hghmsg; + fi[i].others = other_files (mp); + } - folder_free (mp); /* free folder/message structure */ - } + folder_free (mp); /* free folder/message structure */ + } - *crawl_children = (frecurse && (fshort || fi[i].others) - && (fi[i].error == 0)); - return retval; + *crawl_children = (frecurse && (fshort || fi[i].others) + && (fi[i].error == 0)); + return retval; } static boolean get_folder_info_callback (char *fold, void *baton) { - boolean crawl_children; - get_folder_info_body (fold, NULL, &crawl_children); - fflush (stdout); - return crawl_children; + boolean crawl_children; + get_folder_info_body (fold, NULL, &crawl_children); + fflush (stdout); + return crawl_children; } static int get_folder_info (char *fold, char *msg) { - boolean crawl_children; - int retval; + boolean crawl_children; + int retval; - retval = get_folder_info_body (fold, msg, &crawl_children); + retval = get_folder_info_body (fold, msg, &crawl_children); - if (crawl_children) { - crawl_folders (fold, get_folder_info_callback, NULL); - } + if (crawl_children) { + crawl_folders (fold, get_folder_info_callback, NULL); + } - return retval; + return retval; } /* @@ -485,129 +484,129 @@ get_folder_info (char *fold, char *msg) static void print_folders (void) { - int i, len, hasempty = 0, curprinted; - int maxlen = 0, maxnummsg = 0, maxlowmsg = 0; - int maxhghmsg = 0, maxcurmsg = 0, total_msgs = 0; - int nummsgdigits, lowmsgdigits; - int hghmsgdigits, curmsgdigits; - char tmpname[BUFSIZ]; - - /* - * compute a few values needed to for - * printing various fields - */ - for (i = 0; i < total_folders; i++) { - /* length of folder name */ - len = strlen (fi[i].name); - if (len > maxlen) - maxlen = len; - - /* If folder has error, skip the rest */ - if (fi[i].error) - continue; - - /* calculate total number of messages */ - total_msgs += fi[i].nummsg; - - /* maximum number of messages */ - if (fi[i].nummsg > maxnummsg) - maxnummsg = fi[i].nummsg; - - /* maximum low message */ - if (fi[i].lowmsg > maxlowmsg) - maxlowmsg = fi[i].lowmsg; - - /* maximum high message */ - if (fi[i].hghmsg > maxhghmsg) - maxhghmsg = fi[i].hghmsg; - - /* maximum current message */ - if (fi[i].curmsg >= fi[i].lowmsg && - fi[i].curmsg <= fi[i].hghmsg && - fi[i].curmsg > maxcurmsg) - maxcurmsg = fi[i].curmsg; - - /* check for empty folders */ - if (fi[i].nummsg == 0) - hasempty = 1; - } - nummsgdigits = num_digits (maxnummsg); - lowmsgdigits = num_digits (maxlowmsg); - hghmsgdigits = num_digits (maxhghmsg); - curmsgdigits = num_digits (maxcurmsg); - - if (hasempty && nummsgdigits < 2) - nummsgdigits = 2; - - /* - * Print the header - */ - if (fheader > 0 || (all && !fshort && fheader >= 0)) - printf ("%-*s %*s %-*s; %-*s %*s\n", - maxlen+1, "FOLDER", - nummsgdigits + 13, "# MESSAGES", - lowmsgdigits + hghmsgdigits + 4, " RANGE", - curmsgdigits + 4, "CUR", - 9, "(OTHERS)"); - - /* - * Print folder information - */ - if (all || fshort || ftotal < 1) { + int i, len, hasempty = 0, curprinted; + int maxlen = 0, maxnummsg = 0, maxlowmsg = 0; + int maxhghmsg = 0, maxcurmsg = 0, total_msgs = 0; + int nummsgdigits, lowmsgdigits; + int hghmsgdigits, curmsgdigits; + char tmpname[BUFSIZ]; + + /* + * compute a few values needed to for + * printing various fields + */ for (i = 0; i < total_folders; i++) { - if (fshort) { - printf ("%s\n", fi[i].name); - continue; - } - - /* Add `+' to end of name, if folder is current */ - if (strcmp (folder, fi[i].name)) - snprintf (tmpname, sizeof(tmpname), "%s", fi[i].name); - else - snprintf (tmpname, sizeof(tmpname), "%s+", fi[i].name); - - if (fi[i].error) { - printf ("%-*s is unreadable\n", maxlen+1, tmpname); - continue; - } - - printf ("%-*s ", maxlen+1, tmpname); - - curprinted = 0; /* remember if we print cur */ - if (fi[i].nummsg == 0) { - printf ("has %*s messages%*s", - nummsgdigits, "no", - fi[i].others ? lowmsgdigits + hghmsgdigits + 5 : 0, ""); - } else { - printf ("has %*d message%s (%*d-%*d)", - nummsgdigits, fi[i].nummsg, - (fi[i].nummsg == 1) ? " " : "s", - lowmsgdigits, fi[i].lowmsg, - hghmsgdigits, fi[i].hghmsg); - if (fi[i].curmsg >= fi[i].lowmsg && fi[i].curmsg <= fi[i].hghmsg) { - curprinted = 1; - printf ("; cur=%*d", curmsgdigits, fi[i].curmsg); + /* length of folder name */ + len = strlen (fi[i].name); + if (len > maxlen) + maxlen = len; + + /* If folder has error, skip the rest */ + if (fi[i].error) + continue; + + /* calculate total number of messages */ + total_msgs += fi[i].nummsg; + + /* maximum number of messages */ + if (fi[i].nummsg > maxnummsg) + maxnummsg = fi[i].nummsg; + + /* maximum low message */ + if (fi[i].lowmsg > maxlowmsg) + maxlowmsg = fi[i].lowmsg; + + /* maximum high message */ + if (fi[i].hghmsg > maxhghmsg) + maxhghmsg = fi[i].hghmsg; + + /* maximum current message */ + if (fi[i].curmsg >= fi[i].lowmsg && + fi[i].curmsg <= fi[i].hghmsg && + fi[i].curmsg > maxcurmsg) + maxcurmsg = fi[i].curmsg; + + /* check for empty folders */ + if (fi[i].nummsg == 0) + hasempty = 1; + } + nummsgdigits = num_digits (maxnummsg); + lowmsgdigits = num_digits (maxlowmsg); + hghmsgdigits = num_digits (maxhghmsg); + curmsgdigits = num_digits (maxcurmsg); + + if (hasempty && nummsgdigits < 2) + nummsgdigits = 2; + + /* + * Print the header + */ + if (fheader > 0 || (all && !fshort && fheader >= 0)) + printf ("%-*s %*s %-*s; %-*s %*s\n", + maxlen+1, "FOLDER", + nummsgdigits + 13, "# MESSAGES", + lowmsgdigits + hghmsgdigits + 4, " RANGE", + curmsgdigits + 4, "CUR", + 9, "(OTHERS)"); + + /* + * Print folder information + */ + if (all || fshort || ftotal < 1) { + for (i = 0; i < total_folders; i++) { + if (fshort) { + printf ("%s\n", fi[i].name); + continue; + } + + /* Add `+' to end of name, if folder is current */ + if (strcmp (folder, fi[i].name)) + snprintf (tmpname, sizeof(tmpname), "%s", fi[i].name); + else + snprintf (tmpname, sizeof(tmpname), "%s+", fi[i].name); + + if (fi[i].error) { + printf ("%-*s is unreadable\n", maxlen+1, tmpname); + continue; + } + + printf ("%-*s ", maxlen+1, tmpname); + + curprinted = 0; /* remember if we print cur */ + if (fi[i].nummsg == 0) { + printf ("has %*s messages%*s", + nummsgdigits, "no", + fi[i].others ? lowmsgdigits + hghmsgdigits + 5 : 0, ""); + } else { + printf ("has %*d message%s (%*d-%*d)", + nummsgdigits, fi[i].nummsg, + (fi[i].nummsg == 1) ? " " : "s", + lowmsgdigits, fi[i].lowmsg, + hghmsgdigits, fi[i].hghmsg); + if (fi[i].curmsg >= fi[i].lowmsg && fi[i].curmsg <= fi[i].hghmsg) { + curprinted = 1; + printf ("; cur=%*d", curmsgdigits, fi[i].curmsg); + } + } + + if (fi[i].others) + printf (";%*s (others)", curprinted ? 0 : curmsgdigits + 6, ""); + printf (".\n"); } - } + } - if (fi[i].others) - printf (";%*s (others)", curprinted ? 0 : curmsgdigits + 6, ""); - printf (".\n"); + /* + * Print folder/message totals + */ + if (ftotal > 0 || (all && !fshort && ftotal >= 0)) { + if (all) + printf ("\n"); + printf ("TOTAL = %d message%c in %d folder%s.\n", + total_msgs, total_msgs != 1 ? 's' : ' ', + total_folders, total_folders != 1 ? "s" : ""); } - } - - /* - * Print folder/message totals - */ - if (ftotal > 0 || (all && !fshort && ftotal >= 0)) { - if (all) - printf ("\n"); - printf ("TOTAL = %d message%c in %d folder%s.\n", - total_msgs, total_msgs != 1 ? 's' : ' ', - total_folders, total_folders != 1 ? "s" : ""); - } - - fflush (stdout); + + fflush (stdout); } /* @@ -617,20 +616,20 @@ print_folders (void) static int sfold (struct msgs *mp, char *msg) { - /* parse the message range/sequence/name and set SELECTED */ - if (!m_convert (mp, msg)) - return 0; - - if (mp->numsel > 1) { - admonish (NULL, "only one message at a time!"); - return 0; - } - seq_setprev (mp); /* set the previous-sequence */ - seq_setcur (mp, mp->lowsel);/* set current message */ - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - - return 1; + /* parse the message range/sequence/name and set SELECTED */ + if (!m_convert (mp, msg)) + return 0; + + if (mp->numsel > 1) { + admonish (NULL, "only one message at a time!"); + return 0; + } + seq_setprev (mp); /* set the previous-sequence */ + seq_setcur (mp, mp->lowsel); /* set current message */ + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + + return 1; } @@ -641,15 +640,15 @@ sfold (struct msgs *mp, char *msg) static void readonly_folders (void) { - int atrlen; - char atrcur[BUFSIZ]; - register struct node *np; + int atrlen; + char atrcur[BUFSIZ]; + register struct node *np; - snprintf (atrcur, sizeof(atrcur), "atr-%s-", current); - atrlen = strlen (atrcur); + snprintf (atrcur, sizeof(atrcur), "atr-%s-", current); + atrlen = strlen (atrcur); - for (np = m_defs; np; np = np->n_next) - if (ssequal (atrcur, np->n_name) - && !ssequal (nmhdir, np->n_name + atrlen)) - get_folder_info (np->n_name + atrlen, NULL); + for (np = m_defs; np; np = np->n_next) + if (ssequal (atrcur, np->n_name) + && !ssequal (nmhdir, np->n_name + atrlen)) + get_folder_info (np->n_name + atrlen, NULL); } diff --git a/uip/forw.c b/uip/forw.c index 7668b4d..8a7ed34 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -1,4 +1,3 @@ - /* * forw.c -- forward a message, or group of messages. * @@ -14,99 +13,99 @@ #include -#define IFORMAT "digest-issue-%s" -#define VFORMAT "digest-volume-%s" +#define IFORMAT "digest-issue-%s" +#define VFORMAT "digest-volume-%s" static struct swit switches[] = { -#define ANNOSW 0 - { "annotate", 0 }, -#define NANNOSW 1 - { "noannotate", 0 }, -#define DFOLDSW 2 - { "draftfolder +folder", 0 }, -#define DMSGSW 3 - { "draftmessage msg", 0 }, -#define NDFLDSW 4 - { "nodraftfolder", 0 }, -#define EDITRSW 5 - { "editor editor", 0 }, -#define NEDITSW 6 - { "noedit", 0 }, -#define FILTSW 7 - { "filter filterfile", 0 }, -#define FORMSW 8 - { "form formfile", 0 }, -#define FRMTSW 9 - { "format", 5 }, -#define NFRMTSW 10 - { "noformat", 7 }, -#define INPLSW 11 - { "inplace", 0 }, -#define NINPLSW 12 - { "noinplace", 0 }, -#define MIMESW 13 - { "mime", 0 }, -#define NMIMESW 14 - { "nomime", 0 }, -#define DGSTSW 15 - { "digest list", 0 }, -#define ISSUESW 16 - { "issue number", 0 }, -#define VOLUMSW 17 - { "volume number", 0 }, -#define WHATSW 18 - { "whatnowproc program", 0 }, -#define NWHATSW 19 - { "nowhatnowproc", 0 }, -#define BITSTUFFSW 20 - { "dashstuffing", 0 }, /* interface to mhl */ -#define NBITSTUFFSW 21 - { "nodashstuffing", 0 }, -#define VERSIONSW 22 - { "version", 0 }, -#define HELPSW 23 - { "help", 0 }, -#define FILESW 24 - { "file file", 4 }, /* interface from msh */ +#define ANNOSW 0 + { "annotate", 0 }, +#define NANNOSW 1 + { "noannotate", 0 }, +#define DFOLDSW 2 + { "draftfolder +folder", 0 }, +#define DMSGSW 3 + { "draftmessage msg", 0 }, +#define NDFLDSW 4 + { "nodraftfolder", 0 }, +#define EDITRSW 5 + { "editor editor", 0 }, +#define NEDITSW 6 + { "noedit", 0 }, +#define FILTSW 7 + { "filter filterfile", 0 }, +#define FORMSW 8 + { "form formfile", 0 }, +#define FRMTSW 9 + { "format", 5 }, +#define NFRMTSW 10 + { "noformat", 7 }, +#define INPLSW 11 + { "inplace", 0 }, +#define NINPLSW 12 + { "noinplace", 0 }, +#define MIMESW 13 + { "mime", 0 }, +#define NMIMESW 14 + { "nomime", 0 }, +#define DGSTSW 15 + { "digest list", 0 }, +#define ISSUESW 16 + { "issue number", 0 }, +#define VOLUMSW 17 + { "volume number", 0 }, +#define WHATSW 18 + { "whatnowproc program", 0 }, +#define NWHATSW 19 + { "nowhatnowproc", 0 }, +#define BITSTUFFSW 20 + { "dashstuffing", 0 }, /* interface to mhl */ +#define NBITSTUFFSW 21 + { "nodashstuffing", 0 }, +#define VERSIONSW 22 + { "version", 0 }, +#define HELPSW 23 + { "help", 0 }, +#define FILESW 24 + { "file file", 4 }, /* interface from msh */ #ifdef MHE -#define BILDSW 25 - { "build", 5 }, /* interface from mhe */ +#define BILDSW 25 + { "build", 5 }, /* interface from mhe */ #endif /* MHE */ - { NULL, 0 } + { NULL, 0 } }; static struct swit aqrnl[] = { -#define NOSW 0 - { "quit", 0 }, -#define YESW 1 - { "replace", 0 }, -#define LISTDSW 2 - { "list", 0 }, -#define REFILSW 3 - { "refile +folder", 0 }, -#define NEWSW 4 - { "new", 0 }, - { NULL, 0 } +#define NOSW 0 + { "quit", 0 }, +#define YESW 1 + { "replace", 0 }, +#define LISTDSW 2 + { "list", 0 }, +#define REFILSW 3 + { "refile +folder", 0 }, +#define NEWSW 4 + { "new", 0 }, + { NULL, 0 } }; static struct swit aqrl[] = { - { "quit", 0 }, - { "replace", 0 }, - { "list", 0 }, - { "refile +folder", 0 }, - { NULL, 0 } + { "quit", 0 }, + { "replace", 0 }, + { "list", 0 }, + { "refile +folder", 0 }, + { NULL, 0 } }; static char drft[BUFSIZ]; static char delim3[] = - "\n------------------------------------------------------------\n\n"; + "\n------------------------------------------------------------\n\n"; static char delim4[] = "\n------------------------------\n\n"; -static struct msgs *mp = NULL; /* used a lot */ +static struct msgs *mp = NULL; /* used a lot */ /* @@ -121,329 +120,329 @@ static int build_form (char *, char *, int, int); int main (int argc, char **argv) { - int msgp = 0, anot = 0, inplace = 1, mime = 0; - int issue = 0, volume = 0, dashstuff = 0; - int nedit = 0, nwhat = 0, i, in; - int out, isdf = 0, msgnum; - char *cp, *cwd, *maildir, *dfolder = NULL; - char *dmsg = NULL, *digest = NULL, *ed = NULL; - char *file = NULL, *filter = NULL, *folder = NULL; - char *form = NULL, buf[BUFSIZ], value[10]; - char **argp, **arguments, *msgs[MAXARGS]; - struct stat st; - -#ifdef MHE - int buildsw = 0; -#endif /* MHE */ + int msgp = 0, anot = 0, inplace = 1, mime = 0; + int issue = 0, volume = 0, dashstuff = 0; + int nedit = 0, nwhat = 0, i, in; + int out, isdf = 0, msgnum; + char *cp, *cwd, *maildir, *dfolder = NULL; + char *dmsg = NULL, *digest = NULL, *ed = NULL; + char *file = NULL, *filter = NULL, *folder = NULL; + char *form = NULL, buf[BUFSIZ], value[10]; + char **argp, **arguments, *msgs[MAXARGS]; + struct stat st; + +#ifdef MHE + int buildsw = 0; +#endif /* MHE */ #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ANNOSW: - anot++; - continue; - case NANNOSW: - anot = 0; - continue; - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; - continue; - - case WHATSW: - if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; - continue; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ANNOSW: + anot++; + continue; + case NANNOSW: + anot = 0; + continue; + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nedit = 0; + continue; + case NEDITSW: + nedit++; + continue; + + case WHATSW: + if (!(whatnowproc = *argp++) || *whatnowproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nwhat = 0; + continue; #ifdef MHE - case BILDSW: - buildsw++; /* fall... */ + case BILDSW: + buildsw++; /* fall... */ #endif /* MHE */ - case NWHATSW: - nwhat++; - continue; - - case FILESW: - if (file) - adios (NULL, "only one file at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); - continue; - case FILTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); - mime = 0; - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case FRMTSW: - filter = getcpy (etcpath (mhlforward)); - continue; - case NFRMTSW: - filter = NULL; - continue; - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case MIMESW: - mime++; - filter = NULL; - continue; - case NMIMESW: - mime = 0; - continue; - - case DGSTSW: - if (!(digest = *argp++) || *digest == '-') - adios (NULL, "missing argument to %s", argp[-2]); - mime = 0; - continue; - case ISSUESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((issue = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - case VOLUMSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((volume = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - - case BITSTUFFSW: - dashstuff = 1; /* trinary logic */ - continue; - case NBITSTUFFSW: - dashstuff = -1; /* trinary logic */ - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - msgs[msgp++] = cp; + case NWHATSW: + nwhat++; + continue; + + case FILESW: + if (file) + adios (NULL, "only one file at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + file = path (cp, TFILE); + continue; + case FILTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + filter = getcpy (etcpath (cp)); + mime = 0; + continue; + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case FRMTSW: + filter = getcpy (etcpath (mhlforward)); + continue; + case NFRMTSW: + filter = NULL; + continue; + + case INPLSW: + inplace++; + continue; + case NINPLSW: + inplace = 0; + continue; + + case MIMESW: + mime++; + filter = NULL; + continue; + case NMIMESW: + mime = 0; + continue; + + case DGSTSW: + if (!(digest = *argp++) || *digest == '-') + adios (NULL, "missing argument to %s", argp[-2]); + mime = 0; + continue; + case ISSUESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((issue = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + case VOLUMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((volume = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (dmsg) + adios (NULL, "only one draft message at a time!"); + if (!(dmsg = *argp++) || *dmsg == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + + case BITSTUFFSW: + dashstuff = 1; /* trinary logic */ + continue; + case NBITSTUFFSW: + dashstuff = -1; /* trinary logic */ + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + msgs[msgp++] = cp; + } } - } - cwd = getcpy (pwd ()); + cwd = getcpy (pwd ()); - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (file && (msgp || folder)) - adios (NULL, "can't mix files and folders/msgs"); + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (file && (msgp || folder)) + adios (NULL, "can't mix files and folders/msgs"); try_it_again: #ifdef MHE - strncpy (drft, buildsw ? m_maildir ("draft") - : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft)); + strncpy (drft, buildsw ? m_maildir ("draft") + : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft)); - /* Check if a draft already exists */ - if (!buildsw && stat (drft, &st) != NOTOK) { + /* Check if a draft already exists */ + if (!buildsw && stat (drft, &st) != NOTOK) { #else - strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); - - /* Check if a draft already exists */ - if (stat (drft, &st) != NOTOK) { -#endif /* MHE */ - printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); - for (i = LISTDSW; i != YESW;) { - if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) - done (1); - switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { - case NOSW: - done (0); - case NEWSW: - dmsg = NULL; - goto try_it_again; - case YESW: - break; - case LISTDSW: - showfile (++argp, drft); - break; - case REFILSW: - if (refile (++argp, drft) == 0) - i = YESW; - break; - default: - advise (NULL, "say what?"); - break; - } + strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); + + /* Check if a draft already exists */ + if (stat (drft, &st) != NOTOK) { +#endif /* MHE */ + printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); + for (i = LISTDSW; i != YESW;) { + if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) + done (1); + switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { + case NOSW: + done (0); + case NEWSW: + dmsg = NULL; + goto try_it_again; + case YESW: + break; + case LISTDSW: + showfile (++argp, drft); + break; + case REFILSW: + if (refile (++argp, drft) == 0) + i = YESW; + break; + default: + advise (NULL, "say what?"); + break; + } + } } - } - if (file) { - /* - * Forwarding a file. - */ - anot = 0; /* don't want to annotate a file */ - } else { + if (file) { + /* + * Forwarding a file. + */ + anot = 0; /* don't want to annotate a file */ + } else { + /* + * Forwarding a message. + */ + if (!msgp) + msgs[msgp++] = "cur"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgp; msgnum++) + if (!m_convert (mp, msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous sequence */ + } + + if (filter && access (filter, R_OK) == NOTOK) + adios (filter, "unable to read"); + /* - * Forwarding a message. + * Open form (component) file. */ - if (!msgp) - msgs[msgp++] = "cur"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous sequence */ - } - - if (filter && access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); - - /* - * Open form (component) file. - */ - if (digest) { - if (issue == 0) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - if (volume == 0 - && (cp = context_find (buf)) - && ((issue = atoi (cp)) < 0)) - issue = 0; - issue++; - } - if (volume == 0) - snprintf (buf, sizeof(buf), VFORMAT, digest); - if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) - volume = 1; - if (!form) - form = digestcomps; - in = build_form (form, digest, volume, issue); - } else - in = open_form(&form, forwcomps); - - if ((out = creat (drft, m_gmprot ())) == NOTOK) - adios (drft, "unable to create"); - - /* - * copy the components into the draft - */ - cpydata (in, out, form, drft); - close (in); - - if (file) { - /* just copy the file into the draft */ - if ((in = open (file, O_RDONLY)) == NOTOK) - adios (file, "unable to open"); - cpydata (in, out, file, drft); - close (in); - close (out); - } else { + if (digest) { + if (issue == 0) { + snprintf (buf, sizeof(buf), IFORMAT, digest); + if (volume == 0 + && (cp = context_find (buf)) + && ((issue = atoi (cp)) < 0)) + issue = 0; + issue++; + } + if (volume == 0) + snprintf (buf, sizeof(buf), VFORMAT, digest); + if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) + volume = 1; + if (!form) + form = digestcomps; + in = build_form (form, digest, volume, issue); + } else + in = open_form(&form, forwcomps); + + if ((out = creat (drft, m_gmprot ())) == NOTOK) + adios (drft, "unable to create"); + /* - * If filter file is defined, then format the - * messages into the draft using mhlproc. + * copy the components into the draft */ - if (filter) - mhl_draft (out, digest, volume, issue, drft, filter, dashstuff); - else if (mime) - copy_mime_draft (out); - else - copy_draft (out, digest, drft, volume, issue, dashstuff); - close (out); + cpydata (in, out, form, drft); + close (in); - if (digest) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - snprintf (value, sizeof(value), "%d", issue); - context_replace (buf, getcpy (value)); - snprintf (buf, sizeof(buf), VFORMAT, digest); - snprintf (value, sizeof(value), "%d", volume); - context_replace (buf, getcpy (value)); + if (file) { + /* just copy the file into the draft */ + if ((in = open (file, O_RDONLY)) == NOTOK) + adios (file, "unable to open"); + cpydata (in, out, file, drft); + close (in); + close (out); + } else { + /* + * If filter file is defined, then format the + * messages into the draft using mhlproc. + */ + if (filter) + mhl_draft (out, digest, volume, issue, drft, filter, dashstuff); + else if (mime) + copy_mime_draft (out); + else + copy_draft (out, digest, drft, volume, issue, dashstuff); + close (out); + + if (digest) { + snprintf (buf, sizeof(buf), IFORMAT, digest); + snprintf (value, sizeof(value), "%d", issue); + context_replace (buf, getcpy (value)); + snprintf (buf, sizeof(buf), VFORMAT, digest); + snprintf (value, sizeof(value), "%d", volume); + context_replace (buf, getcpy (value)); + } + + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->lowsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ } - context_replace (pfolder, folder); /* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - if (nwhat) - done (0); - what_now (ed, nedit, NOUSE, drft, NULL, 0, mp, - anot ? "Forwarded" : NULL, inplace, cwd); - done (1); - return 1; + if (nwhat) + done (0); + what_now (ed, nedit, NOUSE, drft, NULL, 0, mp, + anot ? "Forwarded" : NULL, inplace, cwd); + done (1); + return 1; } @@ -455,83 +454,83 @@ try_it_again: static void mhl_draft (int out, char *digest, int volume, int issue, - char *file, char *filter, int dashstuff) + char *file, char *filter, int dashstuff) { - pid_t child_id; - int i, msgnum, pd[2]; - char *vec[MAXARGS]; - char buf1[BUFSIZ]; - char buf2[BUFSIZ]; - - if (pipe (pd) == NOTOK) - adios ("pipe", "unable to create"); - - vec[0] = r1bindex (mhlproc, '/'); - - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - close (pd[0]); - dup2 (pd[1], 1); - close (pd[1]); - - i = 1; - vec[i++] = "-forwall"; - vec[i++] = "-form"; - vec[i++] = filter; - - if (digest) { - vec[i++] = "-digest"; - vec[i++] = digest; - vec[i++] = "-issue"; - snprintf (buf1, sizeof(buf1), "%d", issue); - vec[i++] = buf1; - vec[i++] = "-volume"; - snprintf (buf2, sizeof(buf2), "%d", volume); - vec[i++] = buf2; - } - - /* - * Are we dashstuffing (quoting) the lines that begin - * with `-'. We use the mhl default (don't add any flag) - * unless the user has specified a specific flag. - */ - if (dashstuff > 0) - vec[i++] = "-dashstuffing"; - else if (dashstuff < 0) - vec[i++] = "-nodashstuffing"; - - if (mp->numsel >= MAXARGS - i) - adios (NULL, "more than %d messages for %s exec", - MAXARGS - i, vec[0]); - - /* - * Now add the message names to filter. We can only - * handle about 995 messages (because vec is fixed size), - * but that should be plenty. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel && i < sizeof(vec) - 1; - msgnum++) - if (is_selected (mp, msgnum)) - vec[i++] = getcpy (m_name (msgnum)); - vec[i] = NULL; - - execvp (mhlproc, vec); - fprintf (stderr, "unable to exec "); - perror (mhlproc); - _exit (-1); - - default: - close (pd[1]); - cpydata (pd[0], out, vec[0], file); - close (pd[0]); - pidXwait(child_id, mhlproc); - break; - } + pid_t child_id; + int i, msgnum, pd[2]; + char *vec[MAXARGS]; + char buf1[BUFSIZ]; + char buf2[BUFSIZ]; + + if (pipe (pd) == NOTOK) + adios ("pipe", "unable to create"); + + vec[0] = r1bindex (mhlproc, '/'); + + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + adios ("fork", "unable to"); + + case OK: + close (pd[0]); + dup2 (pd[1], 1); + close (pd[1]); + + i = 1; + vec[i++] = "-forwall"; + vec[i++] = "-form"; + vec[i++] = filter; + + if (digest) { + vec[i++] = "-digest"; + vec[i++] = digest; + vec[i++] = "-issue"; + snprintf (buf1, sizeof(buf1), "%d", issue); + vec[i++] = buf1; + vec[i++] = "-volume"; + snprintf (buf2, sizeof(buf2), "%d", volume); + vec[i++] = buf2; + } + + /* + * Are we dashstuffing (quoting) the lines that begin + * with `-'. We use the mhl default (don't add any flag) + * unless the user has specified a specific flag. + */ + if (dashstuff > 0) + vec[i++] = "-dashstuffing"; + else if (dashstuff < 0) + vec[i++] = "-nodashstuffing"; + + if (mp->numsel >= MAXARGS - i) + adios (NULL, "more than %d messages for %s exec", + MAXARGS - i, vec[0]); + + /* + * Now add the message names to filter. We can only + * handle about 995 messages (because vec is fixed size), + * but that should be plenty. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel && i < sizeof(vec) - 1; + msgnum++) + if (is_selected (mp, msgnum)) + vec[i++] = getcpy (m_name (msgnum)); + vec[i] = NULL; + + execvp (mhlproc, vec); + fprintf (stderr, "unable to exec "); + perror (mhlproc); + _exit (-1); + + default: + close (pd[1]); + cpydata (pd[0], out, vec[0], file); + close (pd[0]); + pidXwait(child_id, mhlproc); + break; + } } @@ -544,78 +543,78 @@ mhl_draft (int out, char *digest, int volume, int issue, static void copy_draft (int out, char *digest, char *file, int volume, int issue, int dashstuff) { - int fd,i, msgcnt, msgnum; - int len, buflen; - register char *bp, *msgnam; - char buffer[BUFSIZ]; - - msgcnt = 1; - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - if (digest) { - strncpy (buffer, msgnum == mp->lowsel ? delim3 : delim4, - sizeof(buffer)); - } else { - /* Get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - strncpy (bp, "\n-------", buflen); - len = strlen (bp); - bp += len; - buflen -= len; - - if (msgnum == mp->lowsel) { - snprintf (bp, buflen, " Forwarded Message%s", - mp->numsel > 1 ? "s" : ""); - } else { - snprintf (bp, buflen, " Message %d", msgcnt); + int fd,i, msgcnt, msgnum; + int len, buflen; + register char *bp, *msgnam; + char buffer[BUFSIZ]; + + msgcnt = 1; + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + if (digest) { + strncpy (buffer, msgnum == mp->lowsel ? + delim3 : delim4, sizeof(buffer)); + } else { + /* Get buffer ready to go */ + bp = buffer; + buflen = sizeof(buffer); + + strncpy (bp, "\n-------", buflen); + len = strlen (bp); + bp += len; + buflen -= len; + + if (msgnum == mp->lowsel) { + snprintf (bp, buflen, " Forwarded Message%s", + mp->numsel > 1 ? "s" : ""); + } else { + snprintf (bp, buflen, " Message %d", msgcnt); + } + len = strlen (bp); + bp += len; + buflen -= len; + + strncpy (bp, "\n\n", buflen); + } + write (out, buffer, strlen (buffer)); + + if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { + admonish (msgnam, "unable to read message"); + continue; + } + + /* + * Copy the message. Add RFC934 quoting (dashstuffing) + * unless given the -nodashstuffing flag. + */ + if (dashstuff >= 0) + cpydgst (fd, out, msgnam, file); + else + cpydata (fd, out, msgnam, file); + + close (fd); + msgcnt++; } - len = strlen (bp); - bp += len; - buflen -= len; - - strncpy (bp, "\n\n", buflen); - } - write (out, buffer, strlen (buffer)); - - if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { - admonish (msgnam, "unable to read message"); - continue; - } - - /* - * Copy the message. Add RFC934 quoting (dashstuffing) - * unless given the -nodashstuffing flag. - */ - if (dashstuff >= 0) - cpydgst (fd, out, msgnam, file); - else - cpydata (fd, out, msgnam, file); - - close (fd); - msgcnt++; } - } - - if (digest) { - strncpy (buffer, delim4, sizeof(buffer)); - } else { - snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n\n", - mp->numsel > 1 ? "s" : ""); - } - write (out, buffer, strlen (buffer)); - - if (digest) { - snprintf (buffer, sizeof(buffer), "End of %s Digest [Volume %d Issue %d]\n", - digest, volume, issue); - i = strlen (buffer); - for (bp = buffer + i; i > 1; i--) - *bp++ = '*'; - *bp++ = '\n'; - *bp = 0; + + if (digest) { + strncpy (buffer, delim4, sizeof(buffer)); + } else { + snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n\n", + mp->numsel > 1 ? "s" : ""); + } write (out, buffer, strlen (buffer)); - } + + if (digest) { + snprintf (buffer, sizeof(buffer), "End of %s Digest [Volume %d Issue %d]\n", + digest, volume, issue); + i = strlen (buffer); + for (bp = buffer + i; i > 1; i--) + *bp++ = '*'; + *bp++ = '\n'; + *bp = 0; + write (out, buffer, strlen (buffer)); + } } @@ -626,68 +625,68 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, int dashst static void copy_mime_draft (int out) { - int msgnum; - char buffer[BUFSIZ]; - - snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s", - mp->numsel == 1 ? "" : "s", mp->foldpath); - write (out, buffer, strlen (buffer)); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) { - snprintf (buffer, sizeof(buffer), " %s", m_name (msgnum)); - write (out, buffer, strlen (buffer)); - } - write (out, "\n", 1); + int msgnum; + char buffer[BUFSIZ]; + + snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s", + mp->numsel == 1 ? "" : "s", mp->foldpath); + write (out, buffer, strlen (buffer)); + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected (mp, msgnum)) { + snprintf (buffer, sizeof(buffer), " %s", m_name (msgnum)); + write (out, buffer, strlen (buffer)); + } + write (out, "\n", 1); } static int build_form (char *form, char *digest, int volume, int issue) { - int in; - int fmtsize; - register char *nfs; - char *line, tmpfil[BUFSIZ]; - FILE *tmp; - register struct comp *cptr; - struct format *fmt; - int dat[5]; - char *cp = NULL; - - /* Get new format string */ - nfs = new_fs (form, NULL, NULL); - fmtsize = strlen (nfs) + 256; - - /* Compile format string */ - fmt_compile (nfs, &fmt); - - FINDCOMP (cptr, "digest"); - if (cptr) - cptr->c_text = digest; - FINDCOMP (cptr, "date"); - if (cptr) - cptr->c_text = getcpy(dtimenow (0)); - - dat[0] = issue; - dat[1] = volume; - dat[2] = 0; - dat[3] = fmtsize; - dat[4] = 0; - - cp = m_mktemp2(NULL, invo_name, NULL, &tmp); - if (cp == NULL) adios("forw", "unable to create temporary file"); - strncpy (tmpfil, cp, sizeof(tmpfil)); - unlink (tmpfil); - if ((in = dup (fileno (tmp))) == NOTOK) - adios ("dup", "unable to"); - - line = mh_xmalloc ((unsigned) fmtsize); - fmt_scan (fmt, line, fmtsize, dat); - fputs (line, tmp); - free (line); - if (fclose (tmp)) - adios (tmpfil, "error writing"); - - lseek (in, (off_t) 0, SEEK_SET); - return in; + int in; + int fmtsize; + register char *nfs; + char *line, tmpfil[BUFSIZ]; + FILE *tmp; + register struct comp *cptr; + struct format *fmt; + int dat[5]; + char *cp = NULL; + + /* Get new format string */ + nfs = new_fs (form, NULL, NULL); + fmtsize = strlen (nfs) + 256; + + /* Compile format string */ + fmt_compile (nfs, &fmt); + + FINDCOMP (cptr, "digest"); + if (cptr) + cptr->c_text = digest; + FINDCOMP (cptr, "date"); + if (cptr) + cptr->c_text = getcpy(dtimenow (0)); + + dat[0] = issue; + dat[1] = volume; + dat[2] = 0; + dat[3] = fmtsize; + dat[4] = 0; + + cp = m_mktemp2(NULL, invo_name, NULL, &tmp); + if (cp == NULL) adios("forw", "unable to create temporary file"); + strncpy (tmpfil, cp, sizeof(tmpfil)); + unlink (tmpfil); + if ((in = dup (fileno (tmp))) == NOTOK) + adios ("dup", "unable to"); + + line = mh_xmalloc ((unsigned) fmtsize); + fmt_scan (fmt, line, fmtsize, dat); + fputs (line, tmp); + free (line); + if (fclose (tmp)) + adios (tmpfil, "error writing"); + + lseek (in, (off_t) 0, SEEK_SET); + return in; } diff --git a/uip/ftpsbr.c b/uip/ftpsbr.c index 57f25ba..8295546 100644 --- a/uip/ftpsbr.c +++ b/uip/ftpsbr.c @@ -13,8 +13,8 @@ # include #endif -#define v_debug debugsw -#define v_verbose verbosw +#define v_debug debugsw +#define v_verbose verbosw static int ftp_fd = NOTOK; static int data_fd = NOTOK; @@ -30,11 +30,11 @@ extern int v_verbose; #include #include -#define start_tcp_client(res) \ - socket (res->ai_family, res->ai_socktype, res->ai_protocol) +#define start_tcp_client(res) \ + socket (res->ai_family, res->ai_socktype, res->ai_protocol) -#define join_tcp_server(fd, sock, len) \ - connect ((fd), (struct sockaddr *) (sock), len) +#define join_tcp_server(fd, sock, len) \ + connect ((fd), (struct sockaddr *) (sock), len) /* * prototypes @@ -59,459 +59,454 @@ static int getreply (int, int); static int start_tcp_server (struct sockaddr_in *sock, int backlog, int opt1, int opt2) { - int eindex, sd; + int eindex, sd; - if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK) - return NOTOK; + if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == NOTOK) + return NOTOK; - if (bind (sd, (struct sockaddr *) sock, sizeof *sock) == NOTOK) { - eindex = errno; - close (sd); - errno = eindex; - } else { - listen (sd, backlog); - } + if (bind (sd, (struct sockaddr *) sock, sizeof *sock) == NOTOK) { + eindex = errno; + close (sd); + errno = eindex; + } else { + listen (sd, backlog); + } - return sd; + return sd; } static int __len__; -#define join_tcp_client(fd,sock) \ - accept ((fd), (struct sockaddr *) (sock), \ +#define join_tcp_client(fd,sock) \ + accept ((fd), (struct sockaddr *) (sock), \ (__len__ = sizeof *(sock), &__len__)) -#define read_tcp_socket read -#define write_tcp_socket write -#define close_tcp_socket close +#define read_tcp_socket read +#define write_tcp_socket write +#define close_tcp_socket close static void _asnprintf (char *bp, int len_bp, char *what, va_list ap) { - int eindex, len; - char *fmt; + int eindex, len; + char *fmt; - eindex = errno; + eindex = errno; - *bp = '\0'; - fmt = va_arg (ap, char *); + *bp = '\0'; + fmt = va_arg (ap, char *); - if (fmt) { - vsnprintf(bp, len_bp, fmt, ap); - len = strlen(bp); - bp += len; - len_bp -= len; - } + if (fmt) { + vsnprintf(bp, len_bp, fmt, ap); + len = strlen(bp); + bp += len; + len_bp -= len; + } - if (what) { - char *s; + if (what) { + char *s; - if (*what) { - snprintf (bp, len_bp, " %s: ", what); - len = strlen (bp); - bp += len; - len_bp -= len; + if (*what) { + snprintf (bp, len_bp, " %s: ", what); + len = strlen (bp); + bp += len; + len_bp -= len; + } + if ((s = strerror(eindex))) + strncpy (bp, s, len_bp); + else + snprintf (bp, len_bp, "Error %d", eindex); + bp += strlen (bp); } - if ((s = strerror(eindex))) - strncpy (bp, s, len_bp); - else - snprintf (bp, len_bp, "Error %d", eindex); - bp += strlen (bp); - } - errno = eindex; + errno = eindex; } int ftp_get (char *host, char *user, char *password, char *cwd, - char *remote, char *local, int ascii, int stayopen) + char *remote, char *local, int ascii, int stayopen) { - return ftp_trans (host, user, password, cwd, remote, local, - "RETR", ascii, stayopen); + return ftp_trans (host, user, password, cwd, remote, local, + "RETR", ascii, stayopen); } int ftp_trans (char *host, char *user, char *password, char *cwd, char *remote, - char *local, char *cmd, int ascii, int stayopen) + char *local, char *cmd, int ascii, int stayopen) { - int result; + int result; - if (stayopen <= 0) { - result = ftp_quit (); - if (host == NULL) - return result; - } + if (stayopen <= 0) { + result = ftp_quit (); + if (host == NULL) + return result; + } - if (ftp_fd == NOTOK) { - struct addrinfo hints, *res; + if (ftp_fd == NOTOK) { + struct addrinfo hints, *res; - memset(&hints, 0, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); #ifdef AI_ADDRCONFIG - hints.ai_flags = AI_ADDRCONFIG; + hints.ai_flags = AI_ADDRCONFIG; #endif - hints.ai_family = PF_INET; - hints.ai_socktype = SOCK_STREAM; + hints.ai_family = PF_INET; + hints.ai_socktype = SOCK_STREAM; - result = getaddrinfo(host, "ftp", &hints, &res); + result = getaddrinfo(host, "ftp", &hints, &res); - if (result) { - fprintf(stderr, "%s/ftp: %s\n", host, gai_strerror(result)); - return NOTOK; - } + if (result) { + fprintf(stderr, "%s/ftp: %s\n", host, gai_strerror(result)); + return NOTOK; + } - if ((ftp_fd = start_tcp_client (res)) == NOTOK) { - perror (host); - freeaddrinfo(res); - return NOTOK; - } - if (join_tcp_server (ftp_fd, res->ai_addr, res->ai_addrlen) == NOTOK) { - perror (host); - freeaddrinfo(res); - close_tcp_socket (ftp_fd), ftp_fd = NOTOK; - return NOTOK; - } - freeaddrinfo(res); - getreply (1, 0); + if ((ftp_fd = start_tcp_client (res)) == NOTOK) { + perror (host); + freeaddrinfo(res); + return NOTOK; + } + if (join_tcp_server (ftp_fd, res->ai_addr, res->ai_addrlen) == NOTOK) { + perror (host); + freeaddrinfo(res); + close_tcp_socket (ftp_fd), ftp_fd = NOTOK; + return NOTOK; + } + freeaddrinfo(res); + getreply (1, 0); + + if (v_verbose) { + fprintf (stdout, "Connected to %s\n", host); + fflush (stdout); + } + + if (user) { + if ((result = command (0, "USER %s", user)) == CONTINUE) + result = command (1, "PASS %s", password); + if (result != COMPLETE) { + result = NOTOK; + goto out; + } + } - if (v_verbose) { - fprintf (stdout, "Connected to %s\n", host); - fflush (stdout); + if (remote == NULL) + return OK; } - if (user) { - if ((result = command (0, "USER %s", user)) == CONTINUE) - result = command (1, "PASS %s", password); - if (result != COMPLETE) { + if (cwd && ((result = command (0, "CWD %s", cwd)) != COMPLETE + && result != CONTINUE)) { result = NOTOK; goto out; - } } - if (remote == NULL) - return OK; - } - - if (cwd && ((result = command (0, "CWD %s", cwd)) != COMPLETE - && result != CONTINUE)) { - result = NOTOK; - goto out; - } - - if (command (1, ascii ? "TYPE A" : "TYPE I") != COMPLETE) { - result = NOTOK; - goto out; - } + if (command (1, ascii ? "TYPE A" : "TYPE I") != COMPLETE) { + result = NOTOK; + goto out; + } - result = ftp_read (remote, local, cmd, ascii); + result = ftp_read (remote, local, cmd, ascii); out: ; - if (result != OK || !stayopen) - ftp_quit (); + if (result != OK || !stayopen) + ftp_quit (); - return result; + return result; } static int ftp_quit (void) { - int n; + int n; - if (ftp_fd == NOTOK) - return OK; + if (ftp_fd == NOTOK) + return OK; - n = command (1, "QUIT"); - close_tcp_socket (ftp_fd), ftp_fd = NOTOK; - return (n == 0 || n == COMPLETE ? OK : NOTOK); + n = command (1, "QUIT"); + close_tcp_socket (ftp_fd), ftp_fd = NOTOK; + return (n == 0 || n == COMPLETE ? OK : NOTOK); } static int ftp_read (char *remote, char *local, char *cmd, int ascii) { - int istdio = 0, istore; - register int cc; - int expectingreply = 0; - char buffer[BUFSIZ]; - FILE *fp = NULL; + int istdio = 0, istore; + register int cc; + int expectingreply = 0; + char buffer[BUFSIZ]; + FILE *fp = NULL; - if (initconn () == NOTOK) - goto bad; + if (initconn () == NOTOK) + goto bad; - v_noise = v_verbose; - if (command (-1, *remote ? "%s %s" : "%s", cmd, remote) != PRELIM) - goto bad; + v_noise = v_verbose; + if (command (-1, *remote ? "%s %s" : "%s", cmd, remote) != PRELIM) + goto bad; - expectingreply++; - if (dataconn () == NOTOK) { + expectingreply++; + if (dataconn () == NOTOK) { bad: ; - if (fp && !istdio) - fclose (fp); - if (data_fd != NOTOK) - close_tcp_socket (data_fd), data_fd = NOTOK; - if (expectingreply) - getreply (-2, 0); + if (fp && !istdio) + fclose (fp); + if (data_fd != NOTOK) + close_tcp_socket (data_fd), data_fd = NOTOK; + if (expectingreply) + getreply (-2, 0); + + return NOTOK; + } - return NOTOK; - } + istore = !strcmp (cmd, "STOR"); - istore = !strcmp (cmd, "STOR"); + if ((istdio = !strcmp (local, "-"))) + fp = istore ? stdin : stdout; + else + if ((fp = fopen (local, istore ? "r" : "w")) == NULL) { + perror (local); + goto bad; + } - if ((istdio = !strcmp (local, "-"))) - fp = istore ? stdin : stdout; - else - if ((fp = fopen (local, istore ? "r" : "w")) == NULL) { - perror (local); - goto bad; - } + if (istore) { + if (ascii) { + int c; + FILE *out; - if (istore) { - if (ascii) { - int c; - FILE *out; + if (!(out = fdopen (data_fd, "w"))) { + perror ("fdopen"); + goto bad; + } - if (!(out = fdopen (data_fd, "w"))) { - perror ("fdopen"); - goto bad; - } - - while ((c = getc (fp)) != EOF) { - if (c == '\n') - putc ('\r', out); - if (putc (c, out) == EOF) { - perror ("putc"); - fclose (out); - data_fd = NOTOK; - goto bad; - } - } + while ((c = getc (fp)) != EOF) { + if (c == '\n') + putc ('\r', out); + if (putc (c, out) == EOF) { + perror ("putc"); + fclose (out); + data_fd = NOTOK; + goto bad; + } + } - fclose (out); - data_fd = NOTOK; - } - else { - while ((cc = fread (buffer, sizeof *buffer, sizeof buffer, fp)) > 0) - if (write_tcp_socket (data_fd, buffer, cc) != cc) { - perror ("write_tcp_socket"); - goto bad; + fclose (out); + data_fd = NOTOK; + } else { + while ((cc = fread (buffer, sizeof *buffer, sizeof buffer, fp)) > 0) + if (write_tcp_socket (data_fd, buffer, cc) != cc) { + perror ("write_tcp_socket"); + goto bad; + } + + close_tcp_socket (data_fd), data_fd = NOTOK; } + } else { + if (ascii) { + int c; + FILE *in; + + if (!(in = fdopen (data_fd, "r"))) { + perror ("fdopen"); + goto bad; + } - close_tcp_socket (data_fd), data_fd = NOTOK; - } - } - else { - if (ascii) { - int c; - FILE *in; - - if (!(in = fdopen (data_fd, "r"))) { - perror ("fdopen"); - goto bad; - } - - while ((c = getc (in)) != EOF) { - if (c == '\r') - switch (c = getc (in)) { - case EOF: - case '\0': - c = '\r'; - break; - - case '\n': - break; - - default: - putc ('\r', fp); - break; + while ((c = getc (in)) != EOF) { + if (c == '\r') + switch (c = getc (in)) { + case EOF: + case '\0': + c = '\r'; + break; + + case '\n': + break; + + default: + putc ('\r', fp); + break; + } + + if (putc (c, fp) == EOF) { + perror ("putc"); + fclose (in); + data_fd = NOTOK; + goto bad; + } } - if (putc (c, fp) == EOF) { - perror ("putc"); - fclose (in); - data_fd = NOTOK; - goto bad; - } - } + fclose (in); + data_fd = NOTOK; + } else { + while ((cc = read_tcp_socket (data_fd, buffer, sizeof buffer)) > 0) + if (fwrite (buffer, sizeof *buffer, cc, fp) == 0) { + perror ("fwrite"); + goto bad; + } + if (cc < 0) { + perror ("read_tcp_socket"); + goto bad; + } - fclose (in); - data_fd = NOTOK; - } - else { - while ((cc = read_tcp_socket (data_fd, buffer, sizeof buffer)) > 0) - if (fwrite (buffer, sizeof *buffer, cc, fp) == 0) { - perror ("fwrite"); - goto bad; + close_tcp_socket (data_fd), data_fd = NOTOK; } - if (cc < 0) { - perror ("read_tcp_socket"); - goto bad; - } - - close_tcp_socket (data_fd), data_fd = NOTOK; } - } - if (!istdio) - fclose (fp); + if (!istdio) + fclose (fp); - v_noise = v_verbose; - return (getreply (1, 0) == COMPLETE ? OK : NOTOK); + v_noise = v_verbose; + return (getreply (1, 0) == COMPLETE ? OK : NOTOK); } -#define UC(b) (((int) b) & 0xff) +#define UC(b) (((int) b) & 0xff) static int initconn (void) { - int len; - register char *a, *p; - struct sockaddr_in in_socket; - - if (getsockname (ftp_fd, (struct sockaddr *) &in_socket, - (len = sizeof(in_socket), &len)) == NOTOK) { - perror ("getsockname"); - return NOTOK; - } - in_socket.sin_port = 0; - if ((data_fd = start_tcp_server (&in_socket, 1, 0, 0)) == NOTOK) { - perror ("start_tcp_server"); - return NOTOK; - } + int len; + register char *a, *p; + struct sockaddr_in in_socket; + + if (getsockname (ftp_fd, (struct sockaddr *) &in_socket, + (len = sizeof(in_socket), &len)) == NOTOK) { + perror ("getsockname"); + return NOTOK; + } + in_socket.sin_port = 0; + if ((data_fd = start_tcp_server (&in_socket, 1, 0, 0)) == NOTOK) { + perror ("start_tcp_server"); + return NOTOK; + } - if (getsockname (data_fd, (struct sockaddr *) &in_socket, - (len = sizeof in_socket, &len)) == NOTOK) { - perror ("getsockname"); - return NOTOK; - } + if (getsockname (data_fd, (struct sockaddr *) &in_socket, + (len = sizeof in_socket, &len)) == NOTOK) { + perror ("getsockname"); + return NOTOK; + } - a = (char *) &in_socket.sin_addr; - p = (char *) &in_socket.sin_port; + a = (char *) &in_socket.sin_addr; + p = (char *) &in_socket.sin_port; - if (command (1, "PORT %d,%d,%d,%d,%d,%d", - UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), - UC(p[0]), UC(p[1])) == COMPLETE) - return OK; + if (command (1, "PORT %d,%d,%d,%d,%d,%d", + UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), + UC(p[0]), UC(p[1])) == COMPLETE) + return OK; - return NOTOK; + return NOTOK; } static int dataconn (void) { - int fd; - struct sockaddr_in in_socket; - - if ((fd = join_tcp_client (data_fd, &in_socket)) == NOTOK) { - perror ("join_tcp_client"); - return NOTOK; - } - close_tcp_socket (data_fd); - data_fd = fd; + int fd; + struct sockaddr_in in_socket; - return OK; + if ((fd = join_tcp_client (data_fd, &in_socket)) == NOTOK) { + perror ("join_tcp_client"); + return NOTOK; + } + close_tcp_socket (data_fd); + data_fd = fd; + + return OK; } static int command (int arg1, ...) { - int val; - va_list ap; + int val; + va_list ap; - va_start (ap, arg1); - val = vcommand (arg1, ap); - va_end (ap); + va_start (ap, arg1); + val = vcommand (arg1, ap); + va_end (ap); - return val; + return val; } static int vcommand (int complete, va_list ap) { - int len; - char buffer[BUFSIZ]; + int len; + char buffer[BUFSIZ]; - if (ftp_fd == NOTOK) - return NOTOK; + if (ftp_fd == NOTOK) + return NOTOK; - _asnprintf (buffer, sizeof(buffer), NULL, ap); - if (v_debug) - fprintf (stderr, "<--- %s\n", buffer); + _asnprintf (buffer, sizeof(buffer), NULL, ap); + if (v_debug) + fprintf (stderr, "<--- %s\n", buffer); - strcat (buffer, "\r\n"); - len = strlen (buffer); + strcat (buffer, "\r\n"); + len = strlen (buffer); - if (write_tcp_socket (ftp_fd, buffer, len) != len) { - perror ("write_tcp_socket"); - return NOTOK; - } + if (write_tcp_socket (ftp_fd, buffer, len) != len) { + perror ("write_tcp_socket"); + return NOTOK; + } - return (getreply (complete, !strcmp (buffer, "QUIT"))); + return (getreply (complete, !strcmp (buffer, "QUIT"))); } static int getreply (int complete, int expecteof) { - for (;;) { - register int code, dig, n; - int continuation; - register char *bp; - char buffer[BUFSIZ]; + for (;;) { + register int code, dig, n; + int continuation; + register char *bp; + char buffer[BUFSIZ]; - code = dig = n = continuation = 0; - bp = buffer; + code = dig = n = continuation = 0; + bp = buffer; - for (;;) { - unsigned char c; - - if (read_tcp_socket (ftp_fd, &c, 1) < 1) { - if (expecteof) - return OK; - - perror ("read_tcp_socket"); - return DONE; - } - if (c == '\n') - break; - *bp++ = c != '\r' ? c : '\0'; - - dig++; - if (dig < 4) { - if (isdigit(c)) - code = code * 10 + (c - '0'); - else /* XXX: naughty FTP... */ - if (isspace (c)) - continuation++; - } - else - if (dig == 4 && c == '-') - continuation++; - if (n == 0) - n = c; - } + for (;;) { + unsigned char c; - if (v_debug) - fprintf (stderr, "---> %s\n", buffer); - if (continuation) - continue; + if (read_tcp_socket (ftp_fd, &c, 1) < 1) { + if (expecteof) + return OK; - n -= '0'; + perror ("read_tcp_socket"); + return DONE; + } + if (c == '\n') + break; + *bp++ = c != '\r' ? c : '\0'; + + dig++; + if (dig < 4) { + if (isdigit(c)) + code = code * 10 + (c - '0'); + else if (isspace (c)) + /* XXX: naughty FTP... */ + continuation++; + } else + if (dig == 4 && c == '-') + continuation++; + if (n == 0) + n = c; + } - if (v_noise) { - fprintf (stdout, "%s\n", buffer); - fflush (stdout); - v_noise = 0; - } - else - if ((complete == -1 && n != PRELIM) - || (complete == 0 && n != CONTINUE && n != COMPLETE) - || (complete == 1 && n != COMPLETE)) - fprintf (stderr, "%s\n", buffer); + if (v_debug) + fprintf (stderr, "---> %s\n", buffer); + if (continuation) + continue; + + n -= '0'; - return n; - } + if (v_noise) { + fprintf (stdout, "%s\n", buffer); + fflush (stdout); + v_noise = 0; + } else + if ((complete == -1 && n != PRELIM) + || (complete == 0 && n != CONTINUE && n != COMPLETE) + || (complete == 1 && n != COMPLETE)) + fprintf (stderr, "%s\n", buffer); + + return n; + } } diff --git a/uip/inc.c b/uip/inc.c index 7c91c25..ca1cc72 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -1,4 +1,3 @@ - /* * inc.c -- incorporate messages from a maildrop into a folder * @@ -9,12 +8,12 @@ #ifdef MAILGROUP /* Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@hplabs) - * Added hpux hacks to set and reset gid to be "mail" as needed. The reset - * is necessary so inc'ed mail is the group of the inc'er, rather than - * "mail". We setgid to egid only when [un]locking the mail file. This - * is also a major security precaution which will not be explained here. + * Added hpux hacks to set and reset gid to be "mail" as needed. The reset + * is necessary so inc'ed mail is the group of the inc'er, rather than + * "mail". We setgid to egid only when [un]locking the mail file. This + * is also a major security precaution which will not be explained here. * - * Fri Feb 7 16:04:57 PST 1992 John Romine + * Fri Feb 7 16:04:57 PST 1992 John Romine * NB: I'm not 100% sure that this setgid stuff is secure even now. * * See the *GROUPPRIVS() macros later. I'm reasonably happy with the setgid @@ -39,34 +38,34 @@ #include static struct swit switches[] = { -#define AUDSW 0 - { "audit audit-file", 0 }, -#define NAUDSW 1 - { "noaudit", 0 }, -#define CHGSW 2 - { "changecur", 0 }, -#define NCHGSW 3 - { "nochangecur", 0 }, -#define FILESW 4 - { "file name", 0 }, -#define FORMSW 5 - { "form formatfile", 0 }, -#define FMTSW 6 - { "format string", 5 }, -#define SILSW 12 - { "silent", 0 }, -#define NSILSW 13 - { "nosilent", 0 }, -#define TRNCSW 14 - { "truncate", 0 }, -#define NTRNCSW 15 - { "notruncate", 0 }, -#define WIDTHSW 16 - { "width columns", 0 }, -#define VERSIONSW 17 - { "version", 0 }, -#define HELPSW 18 - { "help", 0 }, +#define AUDSW 0 + { "audit audit-file", 0 }, +#define NAUDSW 1 + { "noaudit", 0 }, +#define CHGSW 2 + { "changecur", 0 }, +#define NCHGSW 3 + { "nochangecur", 0 }, +#define FILESW 4 + { "file name", 0 }, +#define FORMSW 5 + { "form formatfile", 0 }, +#define FMTSW 6 + { "format string", 5 }, +#define SILSW 12 + { "silent", 0 }, +#define NSILSW 13 + { "nosilent", 0 }, +#define TRNCSW 14 + { "truncate", 0 }, +#define NTRNCSW 15 + { "notruncate", 0 }, +#define WIDTHSW 16 + { "width columns", 0 }, +#define VERSIONSW 17 + { "version", 0 }, +#define HELPSW 18 + { "help", 0 }, }; /* This is an attempt to simplify things by putting all the @@ -125,403 +124,404 @@ static void inc_done(int) NORETURN; int main (int argc, char **argv) { - int chgflag = 1, trnflag = 1; - int noisy = 1, width = 0; - int hghnum = 0, msgnum = 0; - int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */ - char *cp, *maildir = NULL, *folder = NULL; - char *format = NULL, *form = NULL; - char *audfile = NULL, *from = NULL; - char buf[BUFSIZ], **argp, *nfs, **arguments; - struct msgs *mp = NULL; - struct stat st, s1; - FILE *aud = NULL; - char b[MAXPATHLEN + 1]; - char *maildir_copy = NULL; /* copy of mail directory because the static gets overwritten */ + int chgflag = 1, trnflag = 1; + int noisy = 1, width = 0; + int hghnum = 0, msgnum = 0; + int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */ + char *cp, *maildir = NULL, *folder = NULL; + char *format = NULL, *form = NULL; + char *audfile = NULL, *from = NULL; + char buf[BUFSIZ], **argp, *nfs, **arguments; + struct msgs *mp = NULL; + struct stat st, s1; + FILE *aud = NULL; + char b[MAXPATHLEN + 1]; + /* copy of mail directory because the static gets overwritten */ + char *maildir_copy = NULL; #ifdef MHE - FILE *mhe = NULL; + FILE *mhe = NULL; #endif - done=inc_done; + done=inc_done; /* absolutely the first thing we do is save our privileges, * and drop them if we can. */ - SAVEGROUPPRIVS(); - TRYDROPGROUPPRIVS(); + SAVEGROUPPRIVS(); + TRYDROPGROUPPRIVS(); #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [switches]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case AUDSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - audfile = getcpy (m_maildir (cp)); - continue; - case NAUDSW: - audfile = NULL; - continue; - - case CHGSW: - chgflag++; - continue; - case NCHGSW: - chgflag = 0; - continue; - - /* - * The flag `trnflag' has the value: - * - * 2 if -truncate is given - * 1 by default (truncating is default) - * 0 if -notruncate is given - */ - case TRNCSW: - trnflag = 2; - continue; - case NTRNCSW: - trnflag = 0; - continue; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [switches]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case AUDSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + audfile = getcpy (m_maildir (cp)); + continue; + case NAUDSW: + audfile = NULL; + continue; + + case CHGSW: + chgflag++; + continue; + case NCHGSW: + chgflag = 0; + continue; + + /* + * The flag `trnflag' has the value: + * + * 2 if -truncate is given + * 1 by default (truncating is default) + * 0 if -notruncate is given + */ + case TRNCSW: + trnflag = 2; + continue; + case NTRNCSW: + trnflag = 0; + continue; + + case FILESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + from = path (cp, TFILE); + + /* + * If the truncate file is in default state, + * change to not truncate. + */ + if (trnflag == 1) + trnflag = 0; + continue; + + case SILSW: + noisy = 0; + continue; + case NSILSW: + noisy++; + continue; + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + width = atoi (cp); + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + adios (NULL, "usage: %s [+folder] [switches]", invo_name); + } + } - case FILESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - from = path (cp, TFILE); + /* NOTE: above this point you should use TRYDROPGROUPPRIVS(), + * not DROPGROUPPRIVS(). + */ + /* guarantee dropping group priveleges; we might not have done so earlier */ + DROPGROUPPRIVS(); + + /* + * We will get the mail from a file + * (typically the standard maildrop) + */ + if (from) + newmail = from; + else if ((newmail = getenv ("MAILDROP")) && *newmail) + newmail = m_mailpath (newmail); + else if ((newmail = context_find ("maildrop")) && *newmail) + newmail = m_mailpath (newmail); + else { + newmail = concat (MAILDIR, "/", MAILFIL, NULL); + } + if (stat (newmail, &s1) == NOTOK || s1.st_size == 0) + adios (NULL, "no mail to incorporate"); - /* - * If the truncate file is in default state, - * change to not truncate. + if ((cp = strdup(newmail)) == (char *)0) + adios (NULL, "error allocating memory to copy newmail"); + + newmail = cp; + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!folder) + folder = getfolder (0); + maildir = m_maildir (folder); + + if ((maildir_copy = strdup(maildir)) == (char *)0) + adios (maildir, "error allocating memory to copy maildir"); + + if (!folder_exists(maildir)) { + /* If the folder doesn't exist, and we're given the -silent flag, + * just fail. */ - if (trnflag == 1) - trnflag = 0; - continue; - - case SILSW: - noisy = 0; - continue; - case NSILSW: - noisy++; - continue; - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - width = atoi (cp); - continue; - } + if (noisy) + create_folder(maildir, 0, done); + else + done (1); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + if (access (newmail, W_OK) != NOTOK) { + locked++; + if (trnflag) { + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); + } + + GETGROUPPRIVS(); /* Reset gid to lock mail file */ + in = lkfopen (newmail, "r"); + DROPGROUPPRIVS(); + if (in == NULL) + adios (NULL, "unable to lock and fopen %s", newmail); + fstat (fileno(in), &s1); } else { - adios (NULL, "usage: %s [+folder] [switches]", invo_name); + trnflag = 0; + if ((in = fopen (newmail, "r")) == NULL) + adios (newmail, "unable to read"); + } + + /* This shouldn't be necessary but it can't hurt. */ + DROPGROUPPRIVS(); + + if (audfile) { + int i; + if ((i = stat (audfile, &st)) == NOTOK) + advise (NULL, "Creating Receive-Audit: %s", audfile); + if ((aud = fopen (audfile, "a")) == NULL) + adios (audfile, "unable to append to"); + else if (i == NOTOK) + chmod (audfile, m_gmprot ()); + + fprintf (aud, from ? "<> %s -ms %s\n" : "<> %s\n", + dtimenow (0), from); } - } - - /* NOTE: above this point you should use TRYDROPGROUPPRIVS(), - * not DROPGROUPPRIVS(). - */ - /* guarantee dropping group priveleges; we might not have done so earlier */ - DROPGROUPPRIVS(); - - /* - * We will get the mail from a file - * (typically the standard maildrop) - */ - if (from) - newmail = from; - else if ((newmail = getenv ("MAILDROP")) && *newmail) - newmail = m_mailpath (newmail); - else if ((newmail = context_find ("maildrop")) && *newmail) - newmail = m_mailpath (newmail); - else { - newmail = concat (MAILDIR, "/", MAILFIL, NULL); - } - if (stat (newmail, &s1) == NOTOK || s1.st_size == 0) - adios (NULL, "no mail to incorporate"); - - if ((cp = strdup(newmail)) == (char *)0) - adios (NULL, "error allocating memory to copy newmail"); - - newmail = cp; - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!folder) - folder = getfolder (0); - maildir = m_maildir (folder); - - if ((maildir_copy = strdup(maildir)) == (char *)0) - adios (maildir, "error allocating memory to copy maildir"); - - if (!folder_exists(maildir)) { - /* If the folder doesn't exist, and we're given the -silent flag, - * just fail. - */ - if (noisy) - create_folder(maildir, 0, done); - else - done (1); - } - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - if (access (newmail, W_OK) != NOTOK) { - locked++; - if (trnflag) { - SIGNAL (SIGHUP, SIG_IGN); - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - SIGNAL (SIGTERM, SIG_IGN); - } - - GETGROUPPRIVS(); /* Reset gid to lock mail file */ - in = lkfopen (newmail, "r"); - DROPGROUPPRIVS(); - if (in == NULL) - adios (NULL, "unable to lock and fopen %s", newmail); - fstat (fileno(in), &s1); - } else { - trnflag = 0; - if ((in = fopen (newmail, "r")) == NULL) - adios (newmail, "unable to read"); - } - - /* This shouldn't be necessary but it can't hurt. */ - DROPGROUPPRIVS(); - - if (audfile) { - int i; - if ((i = stat (audfile, &st)) == NOTOK) - advise (NULL, "Creating Receive-Audit: %s", audfile); - if ((aud = fopen (audfile, "a")) == NULL) - adios (audfile, "unable to append to"); - else if (i == NOTOK) - chmod (audfile, m_gmprot ()); - - fprintf (aud, from ? "<> %s -ms %s\n" : "<> %s\n", - dtimenow (0), from); - } #ifdef MHE - if (context_find ("mhe")) { - int i; - cp = concat (maildir, "/++", NULL); - i = stat (cp, &st); - if ((mhe = fopen (cp, "a")) == NULL) - admonish (cp, "unable to append to"); - else - if (i == NOTOK) - chmod (cp, m_gmprot ()); - free (cp); - } + if (context_find ("mhe")) { + int i; + cp = concat (maildir, "/++", NULL); + i = stat (cp, &st); + if ((mhe = fopen (cp, "a")) == NULL) + admonish (cp, "unable to append to"); + else + if (i == NOTOK) + chmod (cp, m_gmprot ()); + free (cp); + } #endif /* MHE */ - /* Get new format string */ - nfs = new_fs (form, format, FORMAT); - - if (noisy) { - printf ("Incorporating new mail into %s...\n\n", folder); - fflush (stdout); - } - - /* - * Get the mail from file (usually mail spool) - */ - m_unknown (in); /* the MAGIC invocation... */ - hghnum = msgnum = mp->hghmsg; - for (;;) { - /* - * Check if we need to allocate more space for message status. - * If so, then add space for an additional 100 messages. - */ - if (msgnum >= mp->hghoff - && !(mp = folder_realloc (mp, mp->lowoff, mp->hghoff + 100))) { - advise (NULL, "unable to allocate folder storage"); - incerr = NOTOK; - break; - } - - /* create scanline for new message */ - switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width, - msgnum == hghnum && chgflag, 1, NULL, 0L, noisy)) { - case SCNFAT: - case SCNEOF: - break; - - case SCNERR: - if (aud) - fputs ("inc aborted!\n", aud); - advise (NULL, "aborted!"); /* doesn't clean up locks! */ - break; - - case SCNNUM: - advise (NULL, "BUG in %s, number out of range", invo_name); - break; - - default: - advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, incerr); - break; - - case SCNMSG: - case SCNENC: - /* - * Run the external program hook on the message. - */ - - (void)snprintf(b, sizeof (b), "%s/%d", maildir_copy, msgnum + 1); - (void)ext_hook("add-hook", b, (char *)0); - - if (aud) - fputs (scanl, aud); + /* Get new format string */ + nfs = new_fs (form, format, FORMAT); + + if (noisy) { + printf ("Incorporating new mail into %s...\n\n", folder); + fflush (stdout); + } + + /* + * Get the mail from file (usually mail spool) + */ + m_unknown (in); /* the MAGIC invocation... */ + hghnum = msgnum = mp->hghmsg; + for (;;) { + /* + * Check if we need to allocate more space for message status. + * If so, then add space for an additional 100 messages. + */ + if (msgnum >= mp->hghoff + && !(mp = folder_realloc (mp, mp->lowoff, mp->hghoff + 100))) { + advise (NULL, "unable to allocate folder storage"); + incerr = NOTOK; + break; + } + + /* create scanline for new message */ + switch (incerr = scan (in, msgnum + 1, msgnum + 1, nfs, width, + msgnum == hghnum && chgflag, 1, NULL, 0L, noisy)) { + case SCNFAT: + case SCNEOF: + break; + + case SCNERR: + if (aud) + fputs ("inc aborted!\n", aud); + /* doesn't clean up locks! */ + advise (NULL, "aborted!"); + break; + + case SCNNUM: + advise (NULL, "BUG in %s, number out of range", invo_name); + break; + + default: + advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, incerr); + break; + + case SCNMSG: + case SCNENC: + /* + * Run the external program hook on the message. + */ + + (void)snprintf(b, sizeof (b), "%s/%d", maildir_copy, msgnum + 1); + (void)ext_hook("add-hook", b, (char *)0); + + if (aud) + fputs (scanl, aud); #ifdef MHE - if (mhe) - fputs (scanl, mhe); + if (mhe) + fputs (scanl, mhe); #endif /* MHE */ - if (noisy) - fflush (stdout); - msgnum++; - mp->hghmsg++; - mp->nummsg++; - if (mp->lowmsg == 0) - mp->lowmsg = 1; - clear_msg_flags (mp, msgnum); - set_exists (mp, msgnum); - set_unseen (mp, msgnum); - mp->msgflags |= SEQMOD; - continue; - } - /* If we get here there was some sort of error from scan(), - * so stop processing anything more from the spool. - */ - break; - } - - if (incerr < 0) { /* error */ - if (locked) { - GETGROUPPRIVS(); /* Be sure we can unlock mail file */ - (void) lkfclose (in, newmail); in = NULL; - DROPGROUPPRIVS(); /* And then return us to normal privileges */ - } else { - fclose (in); in = NULL; + if (noisy) + fflush (stdout); + msgnum++; + mp->hghmsg++; + mp->nummsg++; + if (mp->lowmsg == 0) + mp->lowmsg = 1; + clear_msg_flags (mp, msgnum); + set_exists (mp, msgnum); + set_unseen (mp, msgnum); + mp->msgflags |= SEQMOD; + continue; + } + /* If we get here there was some sort of error from scan(), + * so stop processing anything more from the spool. + */ + break; } - adios (NULL, "failed"); - } - if (aud) - fclose (aud); + if (incerr < 0) { /* error */ + if (locked) { + GETGROUPPRIVS(); /* Be sure we can unlock mail file */ + (void) lkfclose (in, newmail); in = NULL; + DROPGROUPPRIVS(); /* And then return us to normal privileges */ + } else { + fclose (in); in = NULL; + } + adios (NULL, "failed"); + } + + if (aud) + fclose (aud); #ifdef MHE - if (mhe) - fclose (mhe); + if (mhe) + fclose (mhe); #endif /* MHE */ - if (noisy) - fflush (stdout); - - /* - * truncate file we are incorporating from - */ - if (trnflag) { - if (stat (newmail, &st) != NOTOK && s1.st_mtime != st.st_mtime) - advise (NULL, "new messages have arrived!\007"); - else { - int newfd; - if ((newfd = creat (newmail, 0600)) != NOTOK) - close (newfd); - else - admonish (newmail, "error zero'ing"); - unlink(map_name(newmail)); - } - } else { - if (noisy) - printf ("%s not zero'd\n", newmail); - } - - if (msgnum == hghnum) { - admonish (NULL, "no messages incorporated"); - } else { - context_replace (pfolder, folder); /* update current folder */ - if (chgflag) - mp->curmsg = hghnum + 1; - mp->hghmsg = msgnum; - if (mp->lowmsg == 0) - mp->lowmsg = 1; - if (chgflag) /* sigh... */ - seq_setcur (mp, mp->curmsg); - } - - /* - * unlock the mail spool - */ - if (locked) { - GETGROUPPRIVS(); /* Be sure we can unlock mail file */ - (void) lkfclose (in, newmail); in = NULL; - DROPGROUPPRIVS(); /* And then return us to normal privileges */ - } else { - fclose (in); in = NULL; - } - - seq_setunseen (mp, 0); /* set the Unseen-Sequence */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - done (0); - return 1; + if (noisy) + fflush (stdout); + + /* + * truncate file we are incorporating from + */ + if (trnflag) { + if (stat (newmail, &st) != NOTOK && s1.st_mtime != st.st_mtime) + advise (NULL, "new messages have arrived!\007"); + else { + int newfd; + if ((newfd = creat (newmail, 0600)) != NOTOK) + close (newfd); + else + admonish (newmail, "error zero'ing"); + unlink(map_name(newmail)); + } + } else { + if (noisy) + printf ("%s not zero'd\n", newmail); + } + + if (msgnum == hghnum) { + admonish (NULL, "no messages incorporated"); + } else { + context_replace (pfolder, folder); /* update current folder */ + if (chgflag) + mp->curmsg = hghnum + 1; + mp->hghmsg = msgnum; + if (mp->lowmsg == 0) + mp->lowmsg = 1; + if (chgflag) /* sigh... */ + seq_setcur (mp, mp->curmsg); + } + + /* + * unlock the mail spool + */ + if (locked) { + GETGROUPPRIVS(); /* Be sure we can unlock mail file */ + (void) lkfclose (in, newmail); in = NULL; + DROPGROUPPRIVS(); /* And then return us to normal privileges */ + } else { + fclose (in); in = NULL; + } + + seq_setunseen (mp, 0); /* set the Unseen-Sequence */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ + done (0); + return 1; } static void inc_done (int status) { - if (locked) - { - GETGROUPPRIVS(); - lkfclose(in, newmail); - DROPGROUPPRIVS(); - } - exit (status); + if (locked) { + GETGROUPPRIVS(); + lkfclose(in, newmail); + DROPGROUPPRIVS(); + } + exit (status); } diff --git a/uip/install-mh.c b/uip/install-mh.c index c484771..364cfb2 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -6,20 +6,20 @@ * complete copyright information. */ -#include /* mh internals */ +#include /* mh internals */ #include -#include /* structure for getpwuid() results */ +#include /* structure for getpwuid() results */ static struct swit switches[] = { -#define AUTOSW 0 - { "auto", 0 }, +#define AUTOSW 0 + { "auto", 0 }, #define VERSIONSW 1 - { "version", 0 }, -#define HELPSW 2 - { "help", 0 }, -#define CHECKSW 3 - { "check", 1 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 2 + { "help", 0 }, +#define CHECKSW 3 + { "check", 1 }, + { NULL, 0 } }; /* @@ -31,201 +31,203 @@ static char *geta(void); int main (int argc, char **argv) { - int autof = 0; - char *cp, *pathname, buf[BUFSIZ]; - char *dp, **arguments, **argp; - struct node *np; - struct passwd *pw; - struct stat st; - FILE *in, *out; - int check; + int autof = 0; + char *cp, *pathname, buf[BUFSIZ]; + char *dp, **arguments, **argp; + struct node *np; + struct passwd *pw; + struct stat st; + FILE *in, *out; + int check; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - check = 0; - - while ((dp = *argp++)) { - if (*dp == '-') { - switch (smatch (++dp, switches)) { - case AMBIGSW: - ambigsw (dp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", dp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches]", invo_name); - print_help (buf, switches, 0); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case AUTOSW: - autof++; - continue; - - case CHECKSW: - check = 1; - continue; - } - } else { - adios (NULL, "%s is invalid argument", dp); + invo_name = r1bindex (argv[0], '/'); + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + check = 0; + + while ((dp = *argp++)) { + if (*dp == '-') { + switch (smatch (++dp, switches)) { + case AMBIGSW: + ambigsw (dp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", dp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches]", invo_name); + print_help (buf, switches, 0); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case AUTOSW: + autof++; + continue; + + case CHECKSW: + check = 1; + continue; + } + } else { + adios (NULL, "%s is invalid argument", dp); + } } - } - /* - * Find user's home directory. Try the HOME environment variable first, - * the home directory field in the password file if that's not found. - */ + /* + * Find user's home directory. Try the HOME environment + * variable first, the home directory field in the password file + * if that's not found. + */ + + if ((mypath = getenv("HOME")) == (char *)0) { + if ((pw = getpwuid(getuid())) == (struct passwd *)0 || *pw->pw_dir == '\0') + adios(NULL, "cannot determine your home directory"); + else + mypath = pw->pw_dir; + } - if ((mypath = getenv("HOME")) == (char *)0) { - if ((pw = getpwuid(getuid())) == (struct passwd *)0 || *pw->pw_dir == '\0') - adios(NULL, "cannot determine your home directory"); - else - mypath = pw->pw_dir; - } - - /* - * Find the user's profile. Check for the existence of an MH environment - * variable first with non-empty contents. Convert any relative path name - * found there to an absolute one. Look for the profile in the user's home - * directory if the MH environment variable isn't set. - */ - - if ((cp = getenv("MH")) && *cp != '\0') - defpath = path(cp, TFILE); - else - defpath = concat(mypath, "/", mh_profile, NULL); - - /* - * Check for the existence of the profile file. It's an error if it exists and - * this isn't an installation check. An installation check fails if it does not - * exist, succeeds if it does. - */ - - if (stat (defpath, &st) != NOTOK) { - if (check) - done(0); - - else if (autof) - adios (NULL, "invocation error"); + /* + * Find the user's profile. Check for the existence of an + * MH environment variable first with non-empty contents. + * Convert any relative path name found there to an absolute one. + * Look for the profile in the user's home directory if the MH + * environment variable isn't set. + */ + + if ((cp = getenv("MH")) && *cp != '\0') + defpath = path(cp, TFILE); else - adios (NULL, "You already have an nmh profile, use an editor to modify it"); - } - else if (check) { - done(1); - } - - if (!autof && gans ("Do you want help? ", anoyes)) { - (void)printf( - "\n" - "Prior to using nmh, it is necessary to have a file in your login\n" - "directory (%s) named %s which contains information\n" - "to direct certain nmh operations. The only item which is required\n" - "is the path to use for all nmh folder operations. The suggested nmh\n" - "path for you is %s/Mail...\n" - "\n", mypath, mh_profile, mypath); - } - - cp = concat (mypath, "/", "Mail", NULL); - if (stat (cp, &st) != NOTOK) { - if (S_ISDIR(st.st_mode)) { - cp = concat ("You already have the standard nmh directory \"", - cp, "\".\nDo you want to use it for nmh? ", NULL); - if (gans (cp, anoyes)) - pathname = "Mail"; - else - goto query; - } else { - goto query; + defpath = concat(mypath, "/", mh_profile, NULL); + + /* + * Check for the existence of the profile file. It's an + * error if it exists and this isn't an installation check. + * An installation check fails if it does not exist, succeeds + * if it does. + */ + + if (stat (defpath, &st) != NOTOK) { + if (check) + done(0); + + else if (autof) + adios (NULL, "invocation error"); + else + adios (NULL, "You already have an nmh profile, use an editor to modify it"); + } else if (check) { + done(1); } - } else { - if (autof) - printf ("I'm going to create the standard nmh path for you.\n"); - else - cp = concat ("Do you want the standard nmh path \"", - mypath, "/", "Mail\"? ", NULL); - if (autof || gans (cp, anoyes)) - pathname = "Mail"; - else { + + if (!autof && gans ("Do you want help? ", anoyes)) { + (void)printf( + "\n" + "Prior to using nmh, it is necessary to have a file in your login\n" + "directory (%s) named %s which contains information\n" + "to direct certain nmh operations. The only item which is required\n" + "is the path to use for all nmh folder operations. The suggested nmh\n" + "path for you is %s/Mail...\n" + "\n", mypath, mh_profile, mypath); + } + + cp = concat (mypath, "/", "Mail", NULL); + if (stat (cp, &st) != NOTOK) { + if (S_ISDIR(st.st_mode)) { + cp = concat ("You already have the standard nmh directory \"", + cp, "\".\nDo you want to use it for nmh? ", NULL); + if (gans (cp, anoyes)) + pathname = "Mail"; + else + goto query; + } else { + goto query; + } + } else { + if (autof) + printf ("I'm going to create the standard nmh path for you.\n"); + else + cp = concat ("Do you want the standard nmh path \"", + mypath, "/", "Mail\"? ", NULL); + if (autof || gans (cp, anoyes)) + pathname = "Mail"; + else { query: - if (gans ("Do you want a path below your login directory? ", - anoyes)) { - printf ("What is the path? %s/", mypath); - pathname = geta (); - } else { - printf ("What is the whole path? /"); - pathname = concat ("/", geta (), NULL); - } + if (gans ("Do you want a path below your login directory? ", + anoyes)) { + printf ("What is the path? %s/", mypath); + pathname = geta (); + } else { + printf ("What is the whole path? /"); + pathname = concat ("/", geta (), NULL); + } + } + } + + chdir (mypath); + if (chdir (pathname) == NOTOK) { + cp = concat ("\"", pathname, "\" doesn't exist; Create it? ", NULL); + if (autof || gans (cp, anoyes)) + if (makedir (pathname) == 0) + adios (NULL, "unable to create %s", pathname); + } else { + printf ("[Using existing directory]\n"); + } + + /* + * Add some initial elements to the profile/context list + */ + m_defs = (struct node *) mh_xmalloc (sizeof *np); + np = m_defs; + np->n_name = getcpy ("Path"); + np->n_field = getcpy (pathname); + np->n_context = 0; + np->n_next = NULL; + + /* + * If there is a default profile file in the + * nmh `etc' directory, then read it also. + */ + if ((in = fopen (mh_defaults, "r"))) { + readconfig (&np->n_next, in, mh_defaults, 0); + fclose (in); + } + + ctxpath = getcpy (m_maildir (context = "context")); + + /* Initialize current folder to default */ + context_replace (pfolder, defaultfolder); + context_save (); + + /* + * Now write out the initial .mh_profile + */ + if ((out = fopen (defpath, "w")) == NULL) + adios (defpath, "unable to write"); + for (np = m_defs; np; np = np->n_next) { + if (!np->n_context) + fprintf (out, "%s: %s\n", np->n_name, np->n_field); } - } - - chdir (mypath); - if (chdir (pathname) == NOTOK) { - cp = concat ("\"", pathname, "\" doesn't exist; Create it? ", NULL); - if (autof || gans (cp, anoyes)) - if (makedir (pathname) == 0) - adios (NULL, "unable to create %s", pathname); - } else { - printf ("[Using existing directory]\n"); - } - - /* - * Add some initial elements to the profile/context list - */ - m_defs = (struct node *) mh_xmalloc (sizeof *np); - np = m_defs; - np->n_name = getcpy ("Path"); - np->n_field = getcpy (pathname); - np->n_context = 0; - np->n_next = NULL; - - /* - * If there is a default profile file in the - * nmh `etc' directory, then read it also. - */ - if ((in = fopen (mh_defaults, "r"))) { - readconfig (&np->n_next, in, mh_defaults, 0); - fclose (in); - } - - ctxpath = getcpy (m_maildir (context = "context")); - - /* Initialize current folder to default */ - context_replace (pfolder, defaultfolder); - context_save (); - - /* - * Now write out the initial .mh_profile - */ - if ((out = fopen (defpath, "w")) == NULL) - adios (defpath, "unable to write"); - for (np = m_defs; np; np = np->n_next) { - if (!np->n_context) - fprintf (out, "%s: %s\n", np->n_name, np->n_field); - } - fclose (out); - done (0); - return 1; + fclose (out); + done (0); + return 1; } static char * geta (void) { - char *cp; - static char line[BUFSIZ]; - - fflush(stdout); - if (fgets(line, sizeof(line), stdin) == NULL) - done (1); - if ((cp = strchr(line, '\n'))) - *cp = 0; - return line; + char *cp; + static char line[BUFSIZ]; + + fflush(stdout); + if (fgets(line, sizeof(line), stdin) == NULL) + done (1); + if ((cp = strchr(line, '\n'))) + *cp = 0; + return line; } diff --git a/uip/mark.c b/uip/mark.c index dd09b48..e4d078e 100644 --- a/uip/mark.c +++ b/uip/mark.c @@ -1,4 +1,3 @@ - /* * mark.c -- add message(s) to sequences in given folder * -- delete messages (s) from sequences in given folder @@ -13,29 +12,29 @@ #include static struct swit switches[] = { -#define ADDSW 0 - { "add", 0 }, -#define DELSW 1 - { "delete", 0 }, -#define LSTSW 2 - { "list", 0 }, -#define SEQSW 3 - { "sequence name", 0 }, -#define PUBLSW 4 - { "public", 0 }, -#define NPUBLSW 5 - { "nopublic", 0 }, -#define ZEROSW 6 - { "zero", 0 }, -#define NZEROSW 7 - { "nozero", 0 }, -#define VERSIONSW 8 - { "version", 0 }, -#define HELPSW 9 - { "help", 0 }, -#define DEBUGSW 10 - { "debug", -5 }, - { NULL, 0 } +#define ADDSW 0 + { "add", 0 }, +#define DELSW 1 + { "delete", 0 }, +#define LSTSW 2 + { "list", 0 }, +#define SEQSW 3 + { "sequence name", 0 }, +#define PUBLSW 4 + { "public", 0 }, +#define NPUBLSW 5 + { "nopublic", 0 }, +#define ZEROSW 6 + { "zero", 0 }, +#define NZEROSW 7 + { "nozero", 0 }, +#define VERSIONSW 8 + { "version", 0 }, +#define HELPSW 9 + { "help", 0 }, +#define DEBUGSW 10 + { "debug", -5 }, + { NULL, 0 } }; /* @@ -48,186 +47,187 @@ static void seq_printdebug (struct msgs *); int main (int argc, char **argv) { - int addsw = 0, deletesw = 0, debugsw = 0; - int listsw = 0, publicsw = -1, zerosw = 0; - int seqp = 0, msgnum; - char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments; - char *seqs[NUMATTRS + 1]; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; + int addsw = 0, deletesw = 0, debugsw = 0; + int listsw = 0, publicsw = -1, zerosw = 0; + int seqp = 0, msgnum; + char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments; + char *seqs[NUMATTRS + 1]; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ADDSW: - addsw++; - deletesw = listsw = 0; - continue; - case DELSW: - deletesw++; - addsw = listsw = 0; - continue; - case LSTSW: - listsw++; - addsw = deletesw = 0; - continue; - - case SEQSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - - /* check if too many sequences specified */ - if (seqp >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); - seqs[seqp++] = cp; - continue; - - case PUBLSW: - publicsw = 1; - continue; - case NPUBLSW: - publicsw = 0; - continue; - - case DEBUGSW: - debugsw++; - continue; - - case ZEROSW: - zerosw++; - continue; - case NZEROSW: - zerosw = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), + "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ADDSW: + addsw++; + deletesw = listsw = 0; + continue; + case DELSW: + deletesw++; + addsw = listsw = 0; + continue; + case LSTSW: + listsw++; + addsw = deletesw = 0; + continue; + + case SEQSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + + /* check if too many sequences specified */ + if (seqp >= NUMATTRS) + adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + seqs[seqp++] = cp; + continue; + + case PUBLSW: + publicsw = 1; + continue; + case NPUBLSW: + publicsw = 0; + continue; + + case DEBUGSW: + debugsw++; + continue; + + case ZEROSW: + zerosw++; + continue; + case NZEROSW: + zerosw = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* - * If we haven't specified -add, -delete, or -list, - * then use -add if a sequence was specified, else - * use -list. - */ - if (!addsw && !deletesw && !listsw) { - if (seqp) - addsw++; - else - listsw++; - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!msgs.size) - app_msgarg(&msgs, listsw ? "all" :"cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* print some general debugging info */ - if (debugsw) - print_debug(mp); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - - if (publicsw == 1 && is_readonly(mp)) - adios (NULL, "folder %s is read-only, so -public not allowed", folder); - - /* - * Make sure at least one sequence has been - * specified if we are adding or deleting. - */ - if (seqp == 0 && (addsw || deletesw)) - adios (NULL, "-%s requires at least one -sequence argument", - addsw ? "add" : "delete"); - seqs[seqp] = NULL; - - /* Adding messages to sequences */ - if (addsw) { - for (seqp = 0; seqs[seqp]; seqp++) - if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw)) - done (1); - } - - /* Deleting messages from sequences */ - if (deletesw) { - for (seqp = 0; seqs[seqp]; seqp++) - if (!seq_delsel (mp, seqs[seqp], publicsw, zerosw)) - done (1); - } - - /* Listing messages in sequences */ - if (listsw) { - if (seqp) { - /* print the sequences given */ - for (seqp = 0; seqs[seqp]; seqp++) - seq_print (mp, seqs[seqp]); - } else { - /* else print them all */ - seq_printall (mp); + + /* + * If we haven't specified -add, -delete, or -list, + * then use -add if a sequence was specified, else + * use -list. + */ + if (!addsw && !deletesw && !listsw) { + if (seqp) + addsw++; + else + listsw++; } - /* print debugging info about SELECTED messages */ + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!msgs.size) + app_msgarg(&msgs, listsw ? "all" :"cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* print some general debugging info */ if (debugsw) - seq_printdebug (mp); - } - - seq_save (mp); /* synchronize message sequences */ - context_replace (pfolder, folder); /* update current folder */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + print_debug(mp); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + + if (publicsw == 1 && is_readonly(mp)) + adios (NULL, "folder %s is read-only, so -public not allowed", folder); + + /* + * Make sure at least one sequence has been + * specified if we are adding or deleting. + */ + if (seqp == 0 && (addsw || deletesw)) + adios (NULL, "-%s requires at least one -sequence argument", + addsw ? "add" : "delete"); + seqs[seqp] = NULL; + + /* Adding messages to sequences */ + if (addsw) { + for (seqp = 0; seqs[seqp]; seqp++) + if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw)) + done (1); + } + + /* Deleting messages from sequences */ + if (deletesw) { + for (seqp = 0; seqs[seqp]; seqp++) + if (!seq_delsel (mp, seqs[seqp], publicsw, zerosw)) + done (1); + } + + /* Listing messages in sequences */ + if (listsw) { + if (seqp) { + /* print the sequences given */ + for (seqp = 0; seqs[seqp]; seqp++) + seq_print (mp, seqs[seqp]); + } else { + /* else print them all */ + seq_printall (mp); + } + + /* print debugging info about SELECTED messages */ + if (debugsw) + seq_printdebug (mp); + } + + seq_save (mp); /* synchronize message sequences */ + context_replace (pfolder, folder); /* update current folder */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ + done (0); + return 1; } @@ -237,22 +237,22 @@ main (int argc, char **argv) static void print_debug (struct msgs *mp) { - char buf[100]; + char buf[100]; - printf ("invo_name = %s\n", invo_name); - printf ("mypath = %s\n", mypath); - printf ("defpath = %s\n", defpath); - printf ("ctxpath = %s\n", ctxpath); - printf ("context flags = %s\n", snprintb (buf, sizeof(buf), + printf ("invo_name = %s\n", invo_name); + printf ("mypath = %s\n", mypath); + printf ("defpath = %s\n", defpath); + printf ("ctxpath = %s\n", ctxpath); + printf ("context flags = %s\n", snprintb (buf, sizeof(buf), (unsigned) ctxflags, DBITS)); - printf ("foldpath = %s\n", mp->foldpath); - printf ("folder flags = %s\n\n", snprintb(buf, sizeof(buf), + printf ("foldpath = %s\n", mp->foldpath); + printf ("folder flags = %s\n\n", snprintb(buf, sizeof(buf), (unsigned) mp->msgflags, FBITS)); - printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n", - mp->lowmsg, mp->hghmsg, mp->nummsg, mp->curmsg); - printf ("lowsel=%d hghsel=%d numsel=%d\n", - mp->lowsel, mp->hghsel, mp->numsel); - printf ("lowoff=%d hghoff=%d\n\n", mp->lowoff, mp->hghoff); + printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n", + mp->lowmsg, mp->hghmsg, mp->nummsg, mp->curmsg); + printf ("lowsel=%d hghsel=%d numsel=%d\n", + mp->lowsel, mp->hghsel, mp->numsel); + printf ("lowoff=%d hghoff=%d\n\n", mp->lowoff, mp->hghoff); } @@ -263,14 +263,15 @@ print_debug (struct msgs *mp) static void seq_printdebug (struct msgs *mp) { - int msgnum; - char buf[100]; - - printf ("\n"); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) - printf ("%*d: %s\n", DMAXFOLDER, msgnum, - snprintb (buf, sizeof(buf), - (unsigned) mp->msgstats[msgnum - mp->lowoff], seq_bits (mp))); - } + int msgnum; + char buf[100]; + + printf ("\n"); + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) + printf ("%*d: %s\n", DMAXFOLDER, msgnum, + snprintb (buf, sizeof(buf), + (unsigned) mp->msgstats[msgnum - mp->lowoff], + seq_bits (mp))); + } } diff --git a/uip/md5.c b/uip/md5.c index 5e0ab3b..a40d289 100644 --- a/uip/md5.c +++ b/uip/md5.c @@ -1,4 +1,3 @@ - /* * md5.c -- md5 message digest algorithm * taken from RFC-1321/Appendix A.3 @@ -75,37 +74,37 @@ static unsigned char PADDING[64] = { #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. -Rotation is separate from addition to prevent recomputation. + * Rotation is separate from addition to prevent recomputation. */ #define FF(a, b, c, d, x, s, ac) { \ - (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} #define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} #define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} #define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } + (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ + (a) = ROTATE_LEFT ((a), (s)); \ + (a) += (b); \ +} /* MD5 initialization. Begins an MD5 operation, writing a new context. */ void MD5Init (context) -MD5_CTX *context; /* context */ +MD5_CTX *context; /* context */ { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. -*/ + */ context->state[0] = 0x67452301; context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; @@ -113,13 +112,13 @@ MD5_CTX *context; /* context */ } /* MD5 block update operation. Continues an MD5 message-digest - operation, processing another message block, and updating the - context. + * operation, processing another message block, and updating the + * context. */ void MD5Update (context, input, inputLen) -MD5_CTX *context; /* context */ -unsigned char *input; /* input block */ -unsigned int inputLen; /* length of input block */ +MD5_CTX *context; /* context */ +unsigned char *input; /* input block */ +unsigned int inputLen; /* length of input block */ { unsigned int i, index, partLen; @@ -127,25 +126,23 @@ unsigned int inputLen; /* length of input block */ index = (unsigned int)((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += ((UINT4)inputLen << 3)) - < ((UINT4)inputLen << 3)) - context->count[1]++; + if ((context->count[0] += ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3)) + context->count[1]++; context->count[1] += ((UINT4)inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { - memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); - MD5Transform (context->state, context->buffer); + memcpy ((POINTER)&context->buffer[index], (POINTER)input, partLen); + MD5Transform (context->state, context->buffer); - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform (context->state, &input[i]); + for (i = partLen; i + 63 < inputLen; i += 64) + MD5Transform (context->state, &input[i]); - index = 0; - } - else - i = 0; + index = 0; + } else + i = 0; /* Buffer remaining input */ memcpy ((POINTER)&context->buffer[index], (POINTER)&input[i], inputLen-i); @@ -156,8 +153,8 @@ unsigned int inputLen; /* length of input block */ * the message digest and zeroizing the context. */ void MD5Final (digest, context) -unsigned char digest[16]; /* message digest */ -MD5_CTX *context; /* context */ +unsigned char digest[16]; /* message digest */ +MD5_CTX *context; /* context */ { unsigned char bits[8]; unsigned int index, padLen; @@ -166,7 +163,7 @@ MD5_CTX *context; /* context */ Encode (bits, context->count, 8); /* Pad out to 56 mod 64. -*/ + */ index = (unsigned int)((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update (context, PADDING, padLen); @@ -272,7 +269,7 @@ unsigned char block[64]; } /* Encodes input (UINT4) into output (unsigned char). Assumes len is - a multiple of 4. + * a multiple of 4. */ static void Encode (output, input, len) unsigned char *output; @@ -282,15 +279,15 @@ unsigned int len; unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char)(input[i] & 0xff); - output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); - output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); - output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); + output[j] = (unsigned char)(input[i] & 0xff); + output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); + output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); + output[j+3] = (unsigned char)((input[i] >> 24) & 0xff); } } /* Decodes input (unsigned char) into output (UINT4). Assumes len is - a multiple of 4. + * a multiple of 4. */ static void Decode (output, input, len) UINT4 *output; @@ -300,7 +297,6 @@ unsigned int len; unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | - (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); + output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | + (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } - diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 1e86290..dc71d83 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -1,4 +1,3 @@ - /* * mhbuild.c -- expand/translate MIME composition files * @@ -25,54 +24,54 @@ #endif static struct swit switches[] = { -#define CHECKSW 0 - { "check", 0 }, -#define NCHECKSW 1 - { "nocheck", 0 }, -#define EBCDICSW 2 - { "ebcdicsafe", 0 }, -#define NEBCDICSW 3 - { "noebcdicsafe", 0 }, -#define HEADSW 4 - { "headers", 0 }, -#define NHEADSW 5 - { "noheaders", 0 }, -#define LISTSW 6 - { "list", 0 }, -#define NLISTSW 7 - { "nolist", 0 }, -#define SIZESW 8 - { "realsize", 0 }, -#define NSIZESW 9 - { "norealsize", 0 }, -#define RFC934SW 10 - { "rfc934mode", 0 }, -#define NRFC934SW 11 - { "norfc934mode", 0 }, -#define VERBSW 12 - { "verbose", 0 }, -#define NVERBSW 13 - { "noverbose", 0 }, -#define RCACHESW 14 - { "rcache policy", 0 }, -#define WCACHESW 15 - { "wcache policy", 0 }, -#define CONTENTIDSW 16 - { "contentid", 0 }, -#define NCONTENTIDSW 17 - { "nocontentid", 0 }, -#define VERSIONSW 18 - { "version", 0 }, -#define HELPSW 19 - { "help", 0 }, -#define DEBUGSW 20 - { "debug", -5 }, - { NULL, 0 } +#define CHECKSW 0 + { "check", 0 }, +#define NCHECKSW 1 + { "nocheck", 0 }, +#define EBCDICSW 2 + { "ebcdicsafe", 0 }, +#define NEBCDICSW 3 + { "noebcdicsafe", 0 }, +#define HEADSW 4 + { "headers", 0 }, +#define NHEADSW 5 + { "noheaders", 0 }, +#define LISTSW 6 + { "list", 0 }, +#define NLISTSW 7 + { "nolist", 0 }, +#define SIZESW 8 + { "realsize", 0 }, +#define NSIZESW 9 + { "norealsize", 0 }, +#define RFC934SW 10 + { "rfc934mode", 0 }, +#define NRFC934SW 11 + { "norfc934mode", 0 }, +#define VERBSW 12 + { "verbose", 0 }, +#define NVERBSW 13 + { "noverbose", 0 }, +#define RCACHESW 14 + { "rcache policy", 0 }, +#define WCACHESW 15 + { "wcache policy", 0 }, +#define CONTENTIDSW 16 + { "contentid", 0 }, +#define NCONTENTIDSW 17 + { "nocontentid", 0 }, +#define VERSIONSW 18 + { "version", 0 }, +#define HELPSW 19 + { "help", 0 }, +#define DEBUGSW 20 + { "debug", -5 }, + { NULL, 0 } }; /* mhbuildsbr.c */ -extern char *tmp; /* directory to place temp files */ +extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ extern int rcachesw; @@ -117,286 +116,286 @@ void free_content (CT); int main (int argc, char **argv) { - int sizesw = 1, headsw = 1; - int *icachesw; - char *cp, buf[BUFSIZ]; - char buffer[BUFSIZ], *compfile = NULL; - char **argp, **arguments; - CT ct, cts[2]; - FILE *fp = NULL; - FILE *fp_out = NULL; + int sizesw = 1, headsw = 1; + int *icachesw; + char *cp, buf[BUFSIZ]; + char buffer[BUFSIZ], *compfile = NULL; + char **argp, **arguments; + CT ct, cts[2]; + FILE *fp = NULL; + FILE *fp_out = NULL; - done=unlink_done; + done = unlink_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (cp[0] == '-' && cp[1] == '\0') { - if (compfile) - adios (NULL, "cannot specify both standard input and a file"); - else - compfile = cp; - listsw = 0; /* turn off -list if using standard in/out */ - verbosw = 0; /* turn off -verbose listings */ - break; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (cp[0] == '-' && cp[1] == '\0') { + if (compfile) + adios (NULL, "cannot specify both standard input and a file"); + else + compfile = cp; + listsw = 0; /* turn off -list if using standard in/out */ + verbosw = 0; /* turn off -verbose listings */ + break; + } + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case RCACHESW: + icachesw = &rcachesw; + goto do_cache; + case WCACHESW: + icachesw = &wcachesw; + do_cache: ; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + switch (*icachesw = smatch (cp, caches)) { + case AMBIGSW: + ambigsw (cp, caches); + done (1); + case UNKWNSW: + adios (NULL, "%s unknown", cp); + default: + break; + } + continue; + + case CHECKSW: + checksw++; + continue; + case NCHECKSW: + checksw = 0; + continue; + + case EBCDICSW: + ebcdicsw++; + continue; + case NEBCDICSW: + ebcdicsw = 0; + continue; + + case HEADSW: + headsw++; + continue; + case NHEADSW: + headsw = 0; + continue; + + case LISTSW: + listsw++; + continue; + case NLISTSW: + listsw = 0; + continue; + + case RFC934SW: + rfc934sw++; + continue; + case NRFC934SW: + rfc934sw = 0; + continue; + + case SIZESW: + sizesw++; + continue; + case NSIZESW: + sizesw = 0; + continue; + + case CONTENTIDSW: + contentidsw = 1; + continue; + case NCONTENTIDSW: + contentidsw = 0; + continue; + + case VERBSW: + verbosw++; + continue; + case NVERBSW: + verbosw = 0; + continue; + case DEBUGSW: + debugsw = 1; + continue; + } + } + if (compfile) + adios (NULL, "only one composition file allowed"); + else + compfile = cp; } - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + set_endian (); - case RCACHESW: - icachesw = &rcachesw; - goto do_cache; - case WCACHESW: - icachesw = &wcachesw; - do_cache: ; - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - switch (*icachesw = smatch (cp, caches)) { - case AMBIGSW: - ambigsw (cp, caches); - done (1); - case UNKWNSW: - adios (NULL, "%s unknown", cp); - default: - break; + if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1")) + listsw = 0; + + /* + * Check if we've specified an additional profile + */ + if ((cp = getenv ("MHBUILD"))) { + if ((fp = fopen (cp, "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } else { + admonish ("", "unable to read $MHBUILD profile (%s)", cp); } - continue; - - case CHECKSW: - checksw++; - continue; - case NCHECKSW: - checksw = 0; - continue; - - case EBCDICSW: - ebcdicsw++; - continue; - case NEBCDICSW: - ebcdicsw = 0; - continue; - - case HEADSW: - headsw++; - continue; - case NHEADSW: - headsw = 0; - continue; - - case LISTSW: - listsw++; - continue; - case NLISTSW: - listsw = 0; - continue; - - case RFC934SW: - rfc934sw++; - continue; - case NRFC934SW: - rfc934sw = 0; - continue; - - case SIZESW: - sizesw++; - continue; - case NSIZESW: - sizesw = 0; - continue; - - case CONTENTIDSW: - contentidsw = 1; - continue; - case NCONTENTIDSW: - contentidsw = 0; - continue; - - case VERBSW: - verbosw++; - continue; - case NVERBSW: - verbosw = 0; - continue; - case DEBUGSW: - debugsw = 1; - continue; - } } - if (compfile) - adios (NULL, "only one composition file allowed"); + + /* + * Read the standard profile setup + */ + if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } + + /* Check for public cache location */ + if ((cache_public = context_find (nmhcache)) && *cache_public != '/') + cache_public = NULL; + + /* Check for private cache location */ + if (!(cache_private = context_find (nmhprivcache))) + cache_private = ".cache"; + cache_private = getcpy (m_maildir (cache_private)); + + /* + * Check for storage directory. If defined, we + * will store temporary files there. Else we + * store them in standard nmh directory. + */ + if ((cp = context_find (nmhstorage)) && *cp) + tmp = concat (cp, "/", invo_name, NULL); else - compfile = cp; - } - - set_endian (); - - if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1")) - listsw = 0; - - /* - * Check if we've specified an additional profile - */ - if ((cp = getenv ("MHBUILD"))) { - if ((fp = fopen (cp, "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } else { - admonish ("", "unable to read $MHBUILD profile (%s)", cp); + tmp = add (m_maildir (invo_name), NULL); + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + /* Check if we have a file to process */ + if (!compfile) + adios (NULL, "need to specify a %s composition file", invo_name); + + /* + * Process the composition file from standard input. + */ + if (compfile[0] == '-' && compfile[1] == '\0') { + /* copy standard input to temporary file */ + strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile)); + while (fgets (buffer, BUFSIZ, stdin)) + fputs (buffer, fp); + fclose (fp); + unlink_infile = 1; + + /* build the content structures for MIME message */ + ct = build_mime (infile); + cts[0] = ct; + cts[1] = NULL; + + /* output MIME message to this temporary file */ + strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile)); + unlink_outfile = 1; + + /* output the message */ + output_message_fp (ct, fp_out, outfile); + fclose(fp_out); + + /* output the temp file to standard output */ + if ((fp = fopen (outfile, "r")) == NULL) + adios (outfile, "unable to open"); + while (fgets (buffer, BUFSIZ, fp)) + fputs (buffer, stdout); + fclose (fp); + + unlink (infile); + unlink_infile = 0; + + unlink (outfile); + unlink_outfile = 0; + + free_content (ct); + done (0); } - } - - /* - * Read the standard profile setup - */ - if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } - - /* Check for public cache location */ - if ((cache_public = context_find (nmhcache)) && *cache_public != '/') - cache_public = NULL; - - /* Check for private cache location */ - if (!(cache_private = context_find (nmhprivcache))) - cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); - - /* - * Check for storage directory. If defined, we - * will store temporary files there. Else we - * store them in standard nmh directory. - */ - if ((cp = context_find (nmhstorage)) && *cp) - tmp = concat (cp, "/", invo_name, NULL); - else - tmp = add (m_maildir (invo_name), NULL); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* Check if we have a file to process */ - if (!compfile) - adios (NULL, "need to specify a %s composition file", invo_name); - - /* - * Process the composition file from standard input. - */ - if (compfile[0] == '-' && compfile[1] == '\0') { - /* copy standard input to temporary file */ - strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile)); - while (fgets (buffer, BUFSIZ, stdin)) - fputs (buffer, fp); - fclose (fp); - unlink_infile = 1; + + /* + * Process the composition file from a file. + */ /* build the content structures for MIME message */ - ct = build_mime (infile); + ct = build_mime (compfile); cts[0] = ct; cts[1] = NULL; /* output MIME message to this temporary file */ - strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile)); + strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out), + sizeof(outfile)); unlink_outfile = 1; /* output the message */ output_message_fp (ct, fp_out, outfile); - fclose(fp_out); - - /* output the temp file to standard output */ - if ((fp = fopen (outfile, "r")) == NULL) - adios (outfile, "unable to open"); - while (fgets (buffer, BUFSIZ, fp)) - fputs (buffer, stdout); - fclose (fp); - - unlink (infile); - unlink_infile = 0; + fclose(fp_out); + + /* + * List the message info + */ + if (listsw) + list_all_messages (cts, headsw, sizesw, verbosw, debugsw); + + /* Rename composition draft */ + snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile)); + if (rename (compfile, buffer) == NOTOK) { + adios (compfile, "unable to rename comp draft %s to", buffer); + } - unlink (outfile); + /* Rename output file to take its place */ + if (rename (outfile, compfile) == NOTOK) { + advise (outfile, "unable to rename output %s to", compfile); + rename (buffer, compfile); + done (1); + } unlink_outfile = 0; free_content (ct); done (0); - } - - /* - * Process the composition file from a file. - */ - - /* build the content structures for MIME message */ - ct = build_mime (compfile); - cts[0] = ct; - cts[1] = NULL; - - /* output MIME message to this temporary file */ - strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out), - sizeof(outfile)); - unlink_outfile = 1; - - /* output the message */ - output_message_fp (ct, fp_out, outfile); - fclose(fp_out); - - /* - * List the message info - */ - if (listsw) - list_all_messages (cts, headsw, sizesw, verbosw, debugsw); - - /* Rename composition draft */ - snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile)); - if (rename (compfile, buffer) == NOTOK) { - adios (compfile, "unable to rename comp draft %s to", buffer); - } - - /* Rename output file to take its place */ - if (rename (outfile, compfile) == NOTOK) { - advise (outfile, "unable to rename output %s to", compfile); - rename (buffer, compfile); - done (1); - } - unlink_outfile = 0; - - free_content (ct); - done (0); - return 1; + return 1; } static void unlink_done (int status) { - /* - * Check if we need to remove stray - * temporary files. - */ - if (unlink_infile) - unlink (infile); - if (unlink_outfile) - unlink (outfile); - - exit (status); + /* + * Check if we need to remove stray + * temporary files. + */ + if (unlink_infile) + unlink (infile); + if (unlink_outfile) + unlink (outfile); + + exit (status); } diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index f01abd5..1ca8091 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -1,4 +1,3 @@ - /* * mhbuildsbr.c -- routines to expand/translate MIME composition files * @@ -51,11 +50,11 @@ extern int listsw; extern int rfc934sw; extern int contentidsw; -extern int endian; /* mhmisc.c */ +extern int endian; /* mhmisc.c */ /* cache policies */ -extern int rcachesw; /* mhcachesbr.c */ -extern int wcachesw; /* mhcachesbr.c */ +extern int rcachesw; /* mhcachesbr.c */ +extern int wcachesw; /* mhcachesbr.c */ /* * Directory to place tmp files. This must @@ -113,205 +112,205 @@ static char *calculate_digest (CT, int); CT build_mime (char *infile) { - int compnum, state; - char buf[BUFSIZ], name[NAMESZ]; - char *cp, *np, *vp; - struct multipart *m; - struct part **pp; - CT ct; - FILE *in; - - umask (~m_gmprot ()); - - /* open the composition draft */ - if ((in = fopen (infile, "r")) == NULL) - adios (infile, "unable to open for reading"); - - /* - * Allocate space for primary (outside) content - */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) - adios (NULL, "out of memory"); - - /* - * Allocate structure for handling decoded content - * for this part. We don't really need this, but - * allocate it to remain consistent. - */ - init_decoded_content (ct); - - /* - * Parse some of the header fields in the composition - * draft into the linked list of header fields for - * the new MIME message. - */ - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { - case FLD: - case FLDPLUS: - case FLDEOF: - compnum++; - - /* abort if draft has Mime-Version header field */ - if (!mh_strcasecmp (name, VRSN_FIELD)) - adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD); - - /* abort if draft has Content-Transfer-Encoding header field */ - if (!mh_strcasecmp (name, ENCODING_FIELD)) - adios (NULL, "draft shouldn't contain %s: field", ENCODING_FIELD); - - /* ignore any Content-Type fields in the header */ - if (!mh_strcasecmp (name, TYPE_FIELD)) { - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), in); - goto finish_field; - } - - /* get copies of the buffers */ - np = add (name, NULL); - vp = add (buf, NULL); - - /* if necessary, get rest of field */ - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); - vp = add (buf, vp); /* add to previous value */ - } - - /* Now add the header data to the list */ - add_header (ct, np, vp); + int compnum, state; + char buf[BUFSIZ], name[NAMESZ]; + char *cp, *np, *vp; + struct multipart *m; + struct part **pp; + CT ct; + FILE *in; + + umask (~m_gmprot ()); + + /* open the composition draft */ + if ((in = fopen (infile, "r")) == NULL) + adios (infile, "unable to open for reading"); + + /* + * Allocate space for primary (outside) content + */ + if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + adios (NULL, "out of memory"); + + /* + * Allocate structure for handling decoded content + * for this part. We don't really need this, but + * allocate it to remain consistent. + */ + init_decoded_content (ct); + + /* + * Parse some of the header fields in the composition + * draft into the linked list of header fields for + * the new MIME message. + */ + for (compnum = 1, state = FLD;;) { + switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + case FLD: + case FLDPLUS: + case FLDEOF: + compnum++; + + /* abort if draft has Mime-Version header field */ + if (!mh_strcasecmp (name, VRSN_FIELD)) + adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD); + + /* abort if draft has Content-Transfer-Encoding header field */ + if (!mh_strcasecmp (name, ENCODING_FIELD)) + adios (NULL, "draft shouldn't contain %s: field", ENCODING_FIELD); + + /* ignore any Content-Type fields in the header */ + if (!mh_strcasecmp (name, TYPE_FIELD)) { + while (state == FLDPLUS) + state = m_getfld (state, name, buf, sizeof(buf), in); + goto finish_field; + } + + /* get copies of the buffers */ + np = add (name, NULL); + vp = add (buf, NULL); + + /* if necessary, get rest of field */ + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), in); + vp = add (buf, vp); /* add to previous value */ + } + + /* Now add the header data to the list */ + add_header (ct, np, vp); finish_field: - /* if this wasn't the last header field, then continue */ - if (state != FLDEOF) - continue; - /* else fall... */ + /* if this wasn't the last header field, then continue */ + if (state != FLDEOF) + continue; + /* else fall... */ + + case FILEEOF: + adios (NULL, "draft has empty body -- no directives!"); + /* NOTREACHED */ + + case BODY: + case BODYEOF: + fseek (in, (long) (-strlen (buf)), SEEK_CUR); + break; - case FILEEOF: - adios (NULL, "draft has empty body -- no directives!"); - /* NOTREACHED */ + case LENERR: + case FMTERR: + adios (NULL, "message format error in component #%d", compnum); - case BODY: - case BODYEOF: - fseek (in, (long) (-strlen (buf)), SEEK_CUR); - break; + default: + adios (NULL, "getfld() returned %d", state); + } + break; + } - case LENERR: - case FMTERR: - adios (NULL, "message format error in component #%d", compnum); + /* + * Now add the MIME-Version header field + * to the list of header fields. + */ + np = add (VRSN_FIELD, NULL); + vp = concat (" ", VRSN_VALUE, "\n", NULL); + add_header (ct, np, vp); - default: - adios (NULL, "getfld() returned %d", state); + /* + * We initally assume we will find multiple contents in the + * draft. So create a multipart/mixed content to hold everything. + * We can remove this later, if it is not needed. + */ + if (get_ctinfo ("multipart/mixed", ct, 0) == NOTOK) + done (1); + ct->c_type = CT_MULTIPART; + ct->c_subtype = MULTI_MIXED; + ct->c_file = add (infile, NULL); + + if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) m; + pp = &m->mp_parts; + + /* + * read and parse the composition file + * and the directives it contains. + */ + while (fgetstr (buf, sizeof(buf) - 1, in)) { + struct part *part; + CT p; + + if (user_content (in, infile, buf, &p) == DONE) { + admonish (NULL, "ignoring spurious #end"); + continue; + } + if (!p) + continue; + + if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + adios (NULL, "out of memory"); + *pp = part; + pp = &part->mp_next; + part->mp_part = p; } - break; - } - - /* - * Now add the MIME-Version header field - * to the list of header fields. - */ - np = add (VRSN_FIELD, NULL); - vp = concat (" ", VRSN_VALUE, "\n", NULL); - add_header (ct, np, vp); - - /* - * We initally assume we will find multiple contents in the - * draft. So create a multipart/mixed content to hold everything. - * We can remove this later, if it is not needed. - */ - if (get_ctinfo ("multipart/mixed", ct, 0) == NOTOK) - done (1); - ct->c_type = CT_MULTIPART; - ct->c_subtype = MULTI_MIXED; - ct->c_file = add (infile, NULL); - - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) m; - pp = &m->mp_parts; - - /* - * read and parse the composition file - * and the directives it contains. - */ - while (fgetstr (buf, sizeof(buf) - 1, in)) { - struct part *part; - CT p; - - if (user_content (in, infile, buf, &p) == DONE) { - admonish (NULL, "ignoring spurious #end"); - continue; + + /* + * close the composition draft since + * it's not needed any longer. + */ + fclose (in); + + /* check if any contents were found */ + if (!m->mp_parts) + adios (NULL, "no content directives found"); + + /* + * If only one content was found, then remove and + * free the outer multipart content. + */ + if (!m->mp_parts->mp_next) { + CT p; + + p = m->mp_parts->mp_part; + m->mp_parts->mp_part = NULL; + + /* move header fields */ + p->c_first_hf = ct->c_first_hf; + p->c_last_hf = ct->c_last_hf; + ct->c_first_hf = NULL; + ct->c_last_hf = NULL; + + free_content (ct); + ct = p; + } else { + set_id (ct, 1); } - if (!p) - continue; - - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) - adios (NULL, "out of memory"); - *pp = part; - pp = &part->mp_next; - part->mp_part = p; - } - - /* - * close the composition draft since - * it's not needed any longer. - */ - fclose (in); - - /* check if any contents were found */ - if (!m->mp_parts) - adios (NULL, "no content directives found"); - - /* - * If only one content was found, then remove and - * free the outer multipart content. - */ - if (!m->mp_parts->mp_next) { - CT p; - - p = m->mp_parts->mp_part; - m->mp_parts->mp_part = NULL; - - /* move header fields */ - p->c_first_hf = ct->c_first_hf; - p->c_last_hf = ct->c_last_hf; - ct->c_first_hf = NULL; - ct->c_last_hf = NULL; - - free_content (ct); - ct = p; - } else { - set_id (ct, 1); - } - - /* - * Fill out, or expand directives. Parse and execute - * commands specified by profile composition strings. - */ - compose_content (ct); - - if ((cp = strchr(prefix, 'a')) == NULL) - adios (NULL, "internal error(4)"); - - /* - * Scan the contents. Choose a transfer encoding, and - * check if prefix for multipart boundary clashes with - * any of the contents. - */ - while (scan_content (ct) == NOTOK) { - if (*cp < 'z') { - (*cp)++; - } else { - if (*++cp == 0) - adios (NULL, "giving up trying to find a unique delimiter string"); - else - (*cp)++; + + /* + * Fill out, or expand directives. Parse and execute + * commands specified by profile composition strings. + */ + compose_content (ct); + + if ((cp = strchr(prefix, 'a')) == NULL) + adios (NULL, "internal error(4)"); + + /* + * Scan the contents. Choose a transfer encoding, and + * check if prefix for multipart boundary clashes with + * any of the contents. + */ + while (scan_content (ct) == NOTOK) { + if (*cp < 'z') { + (*cp)++; + } else { + if (*++cp == 0) + adios (NULL, "giving up trying to find a unique delimiter string"); + else + (*cp)++; + } } - } - /* Build the rest of the header field structures */ - build_headers (ct); + /* Build the rest of the header field structures */ + build_headers (ct); - return ct; + return ct; } @@ -323,41 +322,41 @@ finish_field: static int init_decoded_content (CT ct) { - CE ce; + CE ce; - if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL) - adios (NULL, "out of memory"); + if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL) + adios (NULL, "out of memory"); - ct->c_cefile = ce; - ct->c_ceopenfnx = open7Bit; /* since unencoded */ - ct->c_ceclosefnx = close_encoding; - ct->c_cesizefnx = NULL; /* since unencoded */ + ct->c_cefile = ce; + ct->c_ceopenfnx = open7Bit; /* since unencoded */ + ct->c_ceclosefnx = close_encoding; + ct->c_cesizefnx = NULL; /* since unencoded */ - return OK; + return OK; } static char * fgetstr (char *s, int n, FILE *stream) { - char *cp, *ep; + char *cp, *ep; - for (ep = (cp = s) + n; cp < ep; ) { - int i; + for (ep = (cp = s) + n; cp < ep; ) { + int i; - if (!fgets (cp, n, stream)) - return (cp != s ? s : NULL); - if (cp == s && *cp != '#') - return s; + if (!fgets (cp, n, stream)) + return (cp != s ? s : NULL); + if (cp == s && *cp != '#') + return s; - cp += (i = strlen (cp)) - 1; - if (i <= 1 || *cp-- != '\n' || *cp != '\\') - break; - *cp = '\0'; - n -= (i - 2); - } + cp += (i = strlen (cp)) - 1; + if (i <= 1 || *cp-- != '\n' || *cp != '\\') + break; + *cp = '\0'; + n -= (i - 2); + } - return s; + return s; } @@ -369,551 +368,551 @@ fgetstr (char *s, int n, FILE *stream) static int user_content (FILE *in, char *file, char *buf, CT *ctp) { - int extrnal, vrsn; - unsigned char *cp; - char **ap; - char buffer[BUFSIZ]; - struct multipart *m; - struct part **pp; - struct stat st; - struct str2init *s2i; - CI ci; - CT ct; - CE ce; - - if (buf[0] == '\n' || strcmp (buf, "#\n") == 0) { - *ctp = NULL; - return OK; - } - - /* allocate basic Content structure */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) - adios (NULL, "out of memory"); - *ctp = ct; - - /* allocate basic structure for handling decoded content */ - init_decoded_content (ct); - ce = ct->c_cefile; - - ci = &ct->c_ctinfo; - set_id (ct, 0); - - /* - * Handle inline text. Check if line - * is one of the following forms: - * - * 1) doesn't begin with '#' (implicit directive) - * 2) begins with "##" (implicit directive) - * 3) begins with "#<" - */ - if (buf[0] != '#' || buf[1] == '#' || buf[1] == '<') { - int headers; - int inlineD; - long pos; - char content[BUFSIZ]; - FILE *out; - char *cp; - - cp = m_mktemp2(NULL, invo_name, NULL, &out); - if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file"); - - /* use a temp file to collect the plain text lines */ - ce->ce_file = add (cp, NULL); - ce->ce_unlink = 1; - - if (buf[0] == '#' && buf[1] == '<') { - strncpy (content, buf + 2, sizeof(content)); - inlineD = 1; - goto rock_and_roll; - } else { - inlineD = 0; + int extrnal, vrsn; + unsigned char *cp; + char **ap; + char buffer[BUFSIZ]; + struct multipart *m; + struct part **pp; + struct stat st; + struct str2init *s2i; + CI ci; + CT ct; + CE ce; + + if (buf[0] == '\n' || strcmp (buf, "#\n") == 0) { + *ctp = NULL; + return OK; } - /* the directive is implicit */ - strncpy (content, "text/plain", sizeof(content)); - headers = 0; - strncpy (buffer, buf[0] != '#' ? buf : buf + 1, sizeof(buffer)); - for (;;) { - int i; + /* allocate basic Content structure */ + if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + adios (NULL, "out of memory"); + *ctp = ct; - if (headers >= 0 && uprf (buffer, DESCR_FIELD) - && buffer[i = strlen (DESCR_FIELD)] == ':') { - headers = 1; + /* allocate basic structure for handling decoded content */ + init_decoded_content (ct); + ce = ct->c_cefile; -again_descr: - ct->c_descr = add (buffer + i + 1, ct->c_descr); - if (!fgetstr (buffer, sizeof(buffer) - 1, in)) - adios (NULL, "end-of-file after %s: field in plaintext", DESCR_FIELD); - switch (buffer[0]) { - case ' ': - case '\t': - i = -1; - goto again_descr; - - case '#': - adios (NULL, "#-directive after %s: field in plaintext", DESCR_FIELD); - /* NOTREACHED */ + ci = &ct->c_ctinfo; + set_id (ct, 0); - default: - break; + /* + * Handle inline text. Check if line + * is one of the following forms: + * + * 1) doesn't begin with '#' (implicit directive) + * 2) begins with "##" (implicit directive) + * 3) begins with "#<" + */ + if (buf[0] != '#' || buf[1] == '#' || buf[1] == '<') { + int headers; + int inlineD; + long pos; + char content[BUFSIZ]; + FILE *out; + char *cp; + + cp = m_mktemp2(NULL, invo_name, NULL, &out); + if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file"); + + /* use a temp file to collect the plain text lines */ + ce->ce_file = add (cp, NULL); + ce->ce_unlink = 1; + + if (buf[0] == '#' && buf[1] == '<') { + strncpy (content, buf + 2, sizeof(content)); + inlineD = 1; + goto rock_and_roll; + } else { + inlineD = 0; } - } - if (headers >= 0 && uprf (buffer, DISPO_FIELD) - && buffer[i = strlen (DISPO_FIELD)] == ':') { - headers = 1; + /* the directive is implicit */ + strncpy (content, "text/plain", sizeof(content)); + headers = 0; + strncpy (buffer, buf[0] != '#' ? buf : buf + 1, sizeof(buffer)); + for (;;) { + int i; -again_dispo: - ct->c_dispo = add (buffer + i + 1, ct->c_dispo); - if (!fgetstr (buffer, sizeof(buffer) - 1, in)) - adios (NULL, "end-of-file after %s: field in plaintext", DISPO_FIELD); - switch (buffer[0]) { - case ' ': - case '\t': - i = -1; - goto again_dispo; - - case '#': - adios (NULL, "#-directive after %s: field in plaintext", DISPO_FIELD); - /* NOTREACHED */ + if (headers >= 0 && uprf (buffer, DESCR_FIELD) + && buffer[i = strlen (DESCR_FIELD)] == ':') { + headers = 1; - default: - break; - } - } +again_descr: + ct->c_descr = add (buffer + i + 1, ct->c_descr); + if (!fgetstr (buffer, sizeof(buffer) - 1, in)) + adios (NULL, "end-of-file after %s: field in plaintext", DESCR_FIELD); + switch (buffer[0]) { + case ' ': + case '\t': + i = -1; + goto again_descr; + + case '#': + adios (NULL, "#-directive after %s: field in plaintext", DESCR_FIELD); + /* NOTREACHED */ + + default: + break; + } + } - if (headers != 1 || buffer[0] != '\n') - fputs (buffer, out); + if (headers >= 0 && uprf (buffer, DISPO_FIELD) + && buffer[i = strlen (DISPO_FIELD)] == ':') { + headers = 1; -rock_and_roll: - headers = -1; - pos = ftell (in); - if ((cp = fgetstr (buffer, sizeof(buffer) - 1, in)) == NULL) - break; - if (buffer[0] == '#') { - char *bp; +again_dispo: + ct->c_dispo = add (buffer + i + 1, ct->c_dispo); + if (!fgetstr (buffer, sizeof(buffer) - 1, in)) + adios (NULL, "end-of-file after %s: field in plaintext", DISPO_FIELD); + switch (buffer[0]) { + case ' ': + case '\t': + i = -1; + goto again_dispo; + + case '#': + adios (NULL, "#-directive after %s: field in plaintext", DISPO_FIELD); + /* NOTREACHED */ + + default: + break; + } + } - if (buffer[1] != '#') - break; - for (cp = (bp = buffer) + 1; *cp; cp++) - *bp++ = *cp; - *bp = '\0'; - } - } + if (headers != 1 || buffer[0] != '\n') + fputs (buffer, out); - if (listsw) - ct->c_end = ftell (out); - fclose (out); +rock_and_roll: + headers = -1; + pos = ftell (in); + if ((cp = fgetstr (buffer, sizeof(buffer) - 1, in)) == NULL) + break; + if (buffer[0] == '#') { + char *bp; + + if (buffer[1] != '#') + break; + for (cp = (bp = buffer) + 1; *cp; cp++) + *bp++ = *cp; + *bp = '\0'; + } + } - /* parse content type */ - if (get_ctinfo (content, ct, inlineD) == NOTOK) - done (1); + if (listsw) + ct->c_end = ftell (out); + fclose (out); - for (s2i = str2cts; s2i->si_key; s2i++) - if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) - break; - if (!s2i->si_key && !uprf (ci->ci_type, "X-")) - s2i++; + /* parse content type */ + if (get_ctinfo (content, ct, inlineD) == NOTOK) + done (1); - /* - * check type specified (possibly implicitly) - */ - switch (ct->c_type = s2i->si_val) { - case CT_MESSAGE: - if (!mh_strcasecmp (ci->ci_subtype, "rfc822")) { - ct->c_encoding = CE_7BIT; - goto call_init; - } - /* else fall... */ - case CT_MULTIPART: - adios (NULL, "it doesn't make sense to define an in-line %s content", - ct->c_type == CT_MESSAGE ? "message" : "multipart"); - /* NOTREACHED */ + for (s2i = str2cts; s2i->si_key; s2i++) + if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) + break; + if (!s2i->si_key && !uprf (ci->ci_type, "X-")) + s2i++; + + /* + * check type specified (possibly implicitly) + */ + switch (ct->c_type = s2i->si_val) { + case CT_MESSAGE: + if (!mh_strcasecmp (ci->ci_subtype, "rfc822")) { + ct->c_encoding = CE_7BIT; + goto call_init; + } + /* else fall... */ + case CT_MULTIPART: + adios (NULL, "it doesn't make sense to define an in-line %s content", + ct->c_type == CT_MESSAGE ? "message" : "multipart"); + /* NOTREACHED */ - default: + default: call_init: - if ((ct->c_ctinitfnx = s2i->si_init)) - (*ct->c_ctinitfnx) (ct); - break; + if ((ct->c_ctinitfnx = s2i->si_init)) + (*ct->c_ctinitfnx) (ct); + break; + } + + if (cp) + fseek (in, pos, SEEK_SET); + return OK; } - if (cp) - fseek (in, pos, SEEK_SET); - return OK; - } - - /* - * If we've reached this point, the next line - * must be some type of explicit directive. - */ - - /* check if directive is external-type */ - extrnal = (buf[1] == '@'); - - /* parse directive */ - if (get_ctinfo (buf + (extrnal ? 2 : 1), ct, 1) == NOTOK) - done (1); - - /* check directive against the list of MIME types */ - for (s2i = str2cts; s2i->si_key; s2i++) - if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) - break; - - /* - * Check if the directive specified a valid type. - * This will happen if it was one of the following forms: - * - * #type/subtype (or) - * #@type/subtype - */ - if (s2i->si_key) { - if (!ci->ci_subtype) - adios (NULL, "missing subtype in \"#%s\"", ci->ci_type); - - switch (ct->c_type = s2i->si_val) { - case CT_MULTIPART: - adios (NULL, "use \"#begin ... #end\" instead of \"#%s/%s\"", - ci->ci_type, ci->ci_subtype); - /* NOTREACHED */ + /* + * If we've reached this point, the next line + * must be some type of explicit directive. + */ - case CT_MESSAGE: - if (!mh_strcasecmp (ci->ci_subtype, "partial")) - adios (NULL, "sorry, \"#%s/%s\" isn't supported", - ci->ci_type, ci->ci_subtype); - if (!mh_strcasecmp (ci->ci_subtype, "external-body")) - adios (NULL, "use \"#@type/subtype ... [] ...\" instead of \"#%s/%s\"", - ci->ci_type, ci->ci_subtype); -use_forw: - adios (NULL, - "use \"#forw [+folder] [msgs]\" instead of \"#%s/%s\"", - ci->ci_type, ci->ci_subtype); - /* NOTREACHED */ + /* check if directive is external-type */ + extrnal = (buf[1] == '@'); - default: - if ((ct->c_ctinitfnx = s2i->si_init)) - (*ct->c_ctinitfnx) (ct); - break; - } + /* parse directive */ + if (get_ctinfo (buf + (extrnal ? 2 : 1), ct, 1) == NOTOK) + done (1); + + /* check directive against the list of MIME types */ + for (s2i = str2cts; s2i->si_key; s2i++) + if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) + break; /* - * #@type/subtype (external types directive) + * Check if the directive specified a valid type. + * This will happen if it was one of the following forms: + * + * #type/subtype (or) + * #@type/subtype */ - if (extrnal) { - struct exbody *e; - CT p; - - if (!ci->ci_magic) - adios (NULL, "need external information for \"#@%s/%s\"", - ci->ci_type, ci->ci_subtype); - p = ct; - - snprintf (buffer, sizeof(buffer), "message/external-body; %s", ci->ci_magic); - free (ci->ci_magic); - ci->ci_magic = NULL; - - /* - * Since we are using the current Content structure to - * hold information about the type of the external - * reference, we need to create another Content structure - * for the message/external-body to wrap it in. - */ - if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) - adios (NULL, "out of memory"); - *ctp = ct; - ci = &ct->c_ctinfo; - if (get_ctinfo (buffer, ct, 0) == NOTOK) - done (1); - ct->c_type = CT_MESSAGE; - ct->c_subtype = MESSAGE_EXTERNAL; + if (s2i->si_key) { + if (!ci->ci_subtype) + adios (NULL, "missing subtype in \"#%s\"", ci->ci_type); + + switch (ct->c_type = s2i->si_val) { + case CT_MULTIPART: + adios (NULL, "use \"#begin ... #end\" instead of \"#%s/%s\"", + ci->ci_type, ci->ci_subtype); + /* NOTREACHED */ + + case CT_MESSAGE: + if (!mh_strcasecmp (ci->ci_subtype, "partial")) + adios (NULL, "sorry, \"#%s/%s\" isn't supported", + ci->ci_type, ci->ci_subtype); + if (!mh_strcasecmp (ci->ci_subtype, "external-body")) + adios (NULL, "use \"#@type/subtype ... [] ...\" instead of \"#%s/%s\"", + ci->ci_type, ci->ci_subtype); +use_forw: + adios (NULL, + "use \"#forw [+folder] [msgs]\" instead of \"#%s/%s\"", + ci->ci_type, ci->ci_subtype); + /* NOTREACHED */ - if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) e; + default: + if ((ct->c_ctinitfnx = s2i->si_init)) + (*ct->c_ctinitfnx) (ct); + break; + } - e->eb_parent = ct; - e->eb_content = p; - p->c_ctexbody = e; + /* + * #@type/subtype (external types directive) + */ + if (extrnal) { + struct exbody *e; + CT p; - if (params_external (ct, 1) == NOTOK) - done (1); + if (!ci->ci_magic) + adios (NULL, "need external information for \"#@%s/%s\"", + ci->ci_type, ci->ci_subtype); + p = ct; - return OK; - } + snprintf (buffer, sizeof(buffer), "message/external-body; %s", ci->ci_magic); + free (ci->ci_magic); + ci->ci_magic = NULL; - /* Handle [file] argument */ - if (ci->ci_magic) { - /* check if specifies command to execute */ - if (*ci->ci_magic == '|' || *ci->ci_magic == '!') { - for (cp = ci->ci_magic + 1; isspace (*cp); cp++) - continue; - if (!*cp) - adios (NULL, "empty pipe command for #%s directive", ci->ci_type); - cp = add (cp, NULL); - free (ci->ci_magic); - ci->ci_magic = cp; - } else { - /* record filename of decoded contents */ - ce->ce_file = ci->ci_magic; - if (access (ce->ce_file, R_OK) == NOTOK) - adios ("reading", "unable to access %s for", ce->ce_file); - if (listsw && stat (ce->ce_file, &st) != NOTOK) - ct->c_end = (long) st.st_size; - ci->ci_magic = NULL; - } - return OK; + /* + * Since we are using the current Content structure to + * hold information about the type of the external + * reference, we need to create another Content structure + * for the message/external-body to wrap it in. + */ + if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL) + adios (NULL, "out of memory"); + *ctp = ct; + ci = &ct->c_ctinfo; + if (get_ctinfo (buffer, ct, 0) == NOTOK) + done (1); + ct->c_type = CT_MESSAGE; + ct->c_subtype = MESSAGE_EXTERNAL; + + if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) e; + + e->eb_parent = ct; + e->eb_content = p; + p->c_ctexbody = e; + + if (params_external (ct, 1) == NOTOK) + done (1); + + return OK; + } + + /* Handle [file] argument */ + if (ci->ci_magic) { + /* check if specifies command to execute */ + if (*ci->ci_magic == '|' || *ci->ci_magic == '!') { + for (cp = ci->ci_magic + 1; isspace (*cp); cp++) + continue; + if (!*cp) + adios (NULL, "empty pipe command for #%s directive", ci->ci_type); + cp = add (cp, NULL); + free (ci->ci_magic); + ci->ci_magic = cp; + } else { + /* record filename of decoded contents */ + ce->ce_file = ci->ci_magic; + if (access (ce->ce_file, R_OK) == NOTOK) + adios ("reading", "unable to access %s for", ce->ce_file); + if (listsw && stat (ce->ce_file, &st) != NOTOK) + ct->c_end = (long) st.st_size; + ci->ci_magic = NULL; + } + return OK; + } + + /* + * No [file] argument, so check profile for + * method to compose content. + */ + snprintf (buffer, sizeof(buffer), "%s-compose-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + if ((cp = context_find (buffer)) == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-compose-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) == NULL || *cp == '\0') { + content_error (NULL, ct, "don't know how to compose content"); + done (1); + } + } + ci->ci_magic = add (cp, NULL); + return OK; } + if (extrnal) + adios (NULL, "external definition not allowed for \"#%s\"", ci->ci_type); + /* - * No [file] argument, so check profile for - * method to compose content. + * Message directive + * #forw [+folder] [msgs] */ - snprintf (buffer, sizeof(buffer), "%s-compose-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-compose-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - content_error (NULL, ct, "don't know how to compose content"); - done (1); - } - } - ci->ci_magic = add (cp, NULL); - return OK; - } - - if (extrnal) - adios (NULL, "external definition not allowed for \"#%s\"", ci->ci_type); - - /* - * Message directive - * #forw [+folder] [msgs] - */ - if (!mh_strcasecmp (ci->ci_type, "forw")) { - int msgnum; - char *folder, *arguments[MAXARGS]; - struct msgs *mp; - - if (ci->ci_magic) { - ap = brkstring (ci->ci_magic, " ", "\n"); - copyip (ap, arguments, MAXARGS); - } else { - arguments[0] = "cur"; - arguments[1] = NULL; - } - folder = NULL; - - /* search the arguments for a folder name */ - for (ap = arguments; *ap; ap++) { - cp = *ap; - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder per #forw directive"); - else - folder = pluspath (cp); - } - } + if (!mh_strcasecmp (ci->ci_type, "forw")) { + int msgnum; + char *folder, *arguments[MAXARGS]; + struct msgs *mp; + + if (ci->ci_magic) { + ap = brkstring (ci->ci_magic, " ", "\n"); + copyip (ap, arguments, MAXARGS); + } else { + arguments[0] = "cur"; + arguments[1] = NULL; + } + folder = NULL; + + /* search the arguments for a folder name */ + for (ap = arguments; *ap; ap++) { + cp = *ap; + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder per #forw directive"); + else + folder = pluspath (cp); + } + } - /* else, use the current folder */ - if (!folder) - folder = add (getfolder (1), NULL); - - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - for (ap = arguments; *ap; ap++) { - cp = *ap; - if (*cp != '+' && *cp != '@') - if (!m_convert (mp, cp)) - done (1); + /* else, use the current folder */ + if (!folder) + folder = add (getfolder (1), NULL); + + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + for (ap = arguments; *ap; ap++) { + cp = *ap; + if (*cp != '+' && *cp != '@') + if (!m_convert (mp, cp)) + done (1); + } + free (folder); + free_ctinfo (ct); + + /* + * If there is more than one message to include, make this + * a content of type "multipart/digest" and insert each message + * as a subpart. If there is only one message, then make this + * a content of type "message/rfc822". + */ + if (mp->numsel > 1) { + /* we are forwarding multiple messages */ + if (get_ctinfo ("multipart/digest", ct, 0) == NOTOK) + done (1); + ct->c_type = CT_MULTIPART; + ct->c_subtype = MULTI_DIGEST; + + if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) m; + pp = &m->mp_parts; + + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + struct part *part; + CT p; + CE pe; + + if ((p = (CT) calloc (1, sizeof(*p))) == NULL) + adios (NULL, "out of memory"); + init_decoded_content (p); + pe = p->c_cefile; + if (get_ctinfo ("message/rfc822", p, 0) == NOTOK) + done (1); + p->c_type = CT_MESSAGE; + p->c_subtype = MESSAGE_RFC822; + + snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum); + pe->ce_file = add (buffer, NULL); + if (listsw && stat (pe->ce_file, &st) != NOTOK) + p->c_end = (long) st.st_size; + + if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + adios (NULL, "out of memory"); + *pp = part; + pp = &part->mp_next; + part->mp_part = p; + } + } + } else { + /* we are forwarding one message */ + if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK) + done (1); + ct->c_type = CT_MESSAGE; + ct->c_subtype = MESSAGE_RFC822; + + msgnum = mp->lowsel; + snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum); + ce->ce_file = add (buffer, NULL); + if (listsw && stat (ce->ce_file, &st) != NOTOK) + ct->c_end = (long) st.st_size; + } + + folder_free (mp); /* free folder/message structure */ + return OK; } - free (folder); - free_ctinfo (ct); /* - * If there is more than one message to include, make this - * a content of type "multipart/digest" and insert each message - * as a subpart. If there is only one message, then make this - * a content of type "message/rfc822". + * #end */ - if (mp->numsel > 1) { - /* we are forwarding multiple messages */ - if (get_ctinfo ("multipart/digest", ct, 0) == NOTOK) - done (1); - ct->c_type = CT_MULTIPART; - ct->c_subtype = MULTI_DIGEST; - - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) m; - pp = &m->mp_parts; + if (!mh_strcasecmp (ci->ci_type, "end")) { + free_content (ct); + *ctp = NULL; + return DONE; + } - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - struct part *part; - CT p; - CE pe; + /* + * #begin [ alternative | parallel ] + */ + if (!mh_strcasecmp (ci->ci_type, "begin")) { + if (!ci->ci_magic) { + vrsn = MULTI_MIXED; + cp = SubMultiPart[vrsn - 1].kv_key; + } else if (!mh_strcasecmp (ci->ci_magic, "alternative")) { + vrsn = MULTI_ALTERNATE; + cp = SubMultiPart[vrsn - 1].kv_key; + } else if (!mh_strcasecmp (ci->ci_magic, "parallel")) { + vrsn = MULTI_PARALLEL; + cp = SubMultiPart[vrsn - 1].kv_key; + } else if (uprf (ci->ci_magic, "digest")) { + goto use_forw; + } else { + vrsn = MULTI_UNKNOWN; + cp = ci->ci_magic; + } - if ((p = (CT) calloc (1, sizeof(*p))) == NULL) - adios (NULL, "out of memory"); - init_decoded_content (p); - pe = p->c_cefile; - if (get_ctinfo ("message/rfc822", p, 0) == NOTOK) + free_ctinfo (ct); + snprintf (buffer, sizeof(buffer), "multipart/%s", cp); + if (get_ctinfo (buffer, ct, 0) == NOTOK) done (1); - p->c_type = CT_MESSAGE; - p->c_subtype = MESSAGE_RFC822; + ct->c_type = CT_MULTIPART; + ct->c_subtype = vrsn; - snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum); - pe->ce_file = add (buffer, NULL); - if (listsw && stat (pe->ce_file, &st) != NOTOK) - p->c_end = (long) st.st_size; - - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) adios (NULL, "out of memory"); - *pp = part; - pp = &part->mp_next; - part->mp_part = p; - } - } - } else { - /* we are forwarding one message */ - if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK) - done (1); - ct->c_type = CT_MESSAGE; - ct->c_subtype = MESSAGE_RFC822; - - msgnum = mp->lowsel; - snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum); - ce->ce_file = add (buffer, NULL); - if (listsw && stat (ce->ce_file, &st) != NOTOK) - ct->c_end = (long) st.st_size; - } - - folder_free (mp); /* free folder/message structure */ - return OK; - } - - /* - * #end - */ - if (!mh_strcasecmp (ci->ci_type, "end")) { - free_content (ct); - *ctp = NULL; - return DONE; - } - - /* - * #begin [ alternative | parallel ] - */ - if (!mh_strcasecmp (ci->ci_type, "begin")) { - if (!ci->ci_magic) { - vrsn = MULTI_MIXED; - cp = SubMultiPart[vrsn - 1].kv_key; - } else if (!mh_strcasecmp (ci->ci_magic, "alternative")) { - vrsn = MULTI_ALTERNATE; - cp = SubMultiPart[vrsn - 1].kv_key; - } else if (!mh_strcasecmp (ci->ci_magic, "parallel")) { - vrsn = MULTI_PARALLEL; - cp = SubMultiPart[vrsn - 1].kv_key; - } else if (uprf (ci->ci_magic, "digest")) { - goto use_forw; - } else { - vrsn = MULTI_UNKNOWN; - cp = ci->ci_magic; - } + ct->c_ctparams = (void *) m; - free_ctinfo (ct); - snprintf (buffer, sizeof(buffer), "multipart/%s", cp); - if (get_ctinfo (buffer, ct, 0) == NOTOK) - done (1); - ct->c_type = CT_MULTIPART; - ct->c_subtype = vrsn; - - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) m; + pp = &m->mp_parts; + while (fgetstr (buffer, sizeof(buffer) - 1, in)) { + struct part *part; + CT p; - pp = &m->mp_parts; - while (fgetstr (buffer, sizeof(buffer) - 1, in)) { - struct part *part; - CT p; - - if (user_content (in, file, buffer, &p) == DONE) { - if (!m->mp_parts) - adios (NULL, "empty \"#begin ... #end\" sequence"); + if (user_content (in, file, buffer, &p) == DONE) { + if (!m->mp_parts) + adios (NULL, "empty \"#begin ... #end\" sequence"); + return OK; + } + if (!p) + continue; + + if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + adios (NULL, "out of memory"); + *pp = part; + pp = &part->mp_next; + part->mp_part = p; + } + admonish (NULL, "premature end-of-file, missing #end"); return OK; - } - if (!p) - continue; - - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) - adios (NULL, "out of memory"); - *pp = part; - pp = &part->mp_next; - part->mp_part = p; } - admonish (NULL, "premature end-of-file, missing #end"); - return OK; - } - /* - * Unknown directive - */ - adios (NULL, "unknown directive \"#%s\"", ci->ci_type); - return NOTOK; /* NOT REACHED */ + /* + * Unknown directive + */ + adios (NULL, "unknown directive \"#%s\"", ci->ci_type); + return NOTOK; /* NOT REACHED */ } static void set_id (CT ct, int top) { - char msgid[BUFSIZ]; - static int partno; - static time_t clock = 0; - static char *msgfmt; - - if (clock == 0) { - time (&clock); - snprintf (msgid, sizeof(msgid), "<%d.%ld.%%d@%s>\n", - (int) getpid(), (long) clock, LocalName()); - partno = 0; - msgfmt = getcpy(msgid); - } - snprintf (msgid, sizeof(msgid), msgfmt, top ? 0 : ++partno); - ct->c_id = getcpy (msgid); + char msgid[BUFSIZ]; + static int partno; + static time_t clock = 0; + static char *msgfmt; + + if (clock == 0) { + time (&clock); + snprintf (msgid, sizeof(msgid), "<%d.%ld.%%d@%s>\n", + (int) getpid(), (long) clock, LocalName()); + partno = 0; + msgfmt = getcpy(msgid); + } + snprintf (msgid, sizeof(msgid), msgfmt, top ? 0 : ++partno); + ct->c_id = getcpy (msgid); } static char ebcdicsafe[0x100] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -926,216 +925,216 @@ static char ebcdicsafe[0x100] = { static int compose_content (CT ct) { - CE ce = ct->c_cefile; - - switch (ct->c_type) { - case CT_MULTIPART: - { - int partnum; - char *pp; - char partnam[BUFSIZ]; - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - - if (ct->c_partno) { - snprintf (partnam, sizeof(partnam), "%s.", ct->c_partno); - pp = partnam + strlen (partnam); - } else { - pp = partnam; - } + CE ce = ct->c_cefile; - /* first, we call compose_content on all the subparts */ - for (part = m->mp_parts, partnum = 1; part; part = part->mp_next, partnum++) { - CT p = part->mp_part; + switch (ct->c_type) { + case CT_MULTIPART: + { + int partnum; + char *pp; + char partnam[BUFSIZ]; + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; + + if (ct->c_partno) { + snprintf (partnam, sizeof(partnam), "%s.", ct->c_partno); + pp = partnam + strlen (partnam); + } else { + pp = partnam; + } - sprintf (pp, "%d", partnum); - p->c_partno = add (partnam, NULL); - if (compose_content (p) == NOTOK) - return NOTOK; - } + /* first, we call compose_content on all the subparts */ + for (part = m->mp_parts, partnum = 1; part; part = part->mp_next, partnum++) { + CT p = part->mp_part; - /* - * If the -rfc934mode switch is given, then check all - * the subparts of a multipart/digest. If they are all - * message/rfc822, then mark this content and all - * subparts with the rfc934 compatibility mode flag. - */ - if (rfc934sw && ct->c_subtype == MULTI_DIGEST) { - int is934 = 1; + sprintf (pp, "%d", partnum); + p->c_partno = add (partnam, NULL); + if (compose_content (p) == NOTOK) + return NOTOK; + } - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; + /* + * If the -rfc934mode switch is given, then check all + * the subparts of a multipart/digest. If they are all + * message/rfc822, then mark this content and all + * subparts with the rfc934 compatibility mode flag. + */ + if (rfc934sw && ct->c_subtype == MULTI_DIGEST) { + int is934 = 1; + + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; + + if (p->c_subtype != MESSAGE_RFC822) { + is934 = 0; + break; + } + } + ct->c_rfc934 = is934; + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; - if (p->c_subtype != MESSAGE_RFC822) { - is934 = 0; - break; + if ((p->c_rfc934 = is934)) + p->c_end++; + } } - } - ct->c_rfc934 = is934; - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; - - if ((p->c_rfc934 = is934)) - p->c_end++; - } - } - if (listsw) { - ct->c_end = (partnum = strlen (prefix) + 2) + 2; - if (ct->c_rfc934) - ct->c_end += 1; + if (listsw) { + ct->c_end = (partnum = strlen (prefix) + 2) + 2; + if (ct->c_rfc934) + ct->c_end += 1; - for (part = m->mp_parts; part; part = part->mp_next) - ct->c_end += part->mp_part->c_end + partnum; + for (part = m->mp_parts; part; part = part->mp_next) + ct->c_end += part->mp_part->c_end + partnum; + } } - } - break; - - case CT_MESSAGE: - /* Nothing to do for type message */ break; - /* - * Discrete types (text/application/audio/image/video) - */ - default: - if (!ce->ce_file) { - pid_t child_id; - int i, xstdout, len, buflen; - char *bp, **ap, *cp; - char *vec[4], buffer[BUFSIZ]; - FILE *out; - CI ci = &ct->c_ctinfo; - char *tfile = NULL; - - if (!(cp = ci->ci_magic)) - adios (NULL, "internal error(5)"); - - tfile = m_mktemp2(NULL, invo_name, NULL, NULL); - if (tfile == NULL) { - adios("mhbuildsbr", "unable to create temporary file"); - } - ce->ce_file = add (tfile, NULL); - ce->ce_unlink = 1; - - xstdout = 0; - - /* Get buffer ready to go */ - bp = buffer; - bp[0] = '\0'; - buflen = sizeof(buffer); - - /* - * Parse composition string into buffer - */ - for ( ; *cp; cp++) { - if (*cp == '%') { - switch (*++cp) { - case 'a': - { - /* insert parameters from directive */ - char **ep; - char *s = ""; - - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); - len = strlen (bp); - bp += len; - buflen -= len; - s = " "; + case CT_MESSAGE: + /* Nothing to do for type message */ + break; + + /* + * Discrete types (text/application/audio/image/video) + */ + default: + if (!ce->ce_file) { + pid_t child_id; + int i, xstdout, len, buflen; + char *bp, **ap, *cp; + char *vec[4], buffer[BUFSIZ]; + FILE *out; + CI ci = &ct->c_ctinfo; + char *tfile = NULL; + + if (!(cp = ci->ci_magic)) + adios (NULL, "internal error(5)"); + + tfile = m_mktemp2(NULL, invo_name, NULL, NULL); + if (tfile == NULL) { + adios("mhbuildsbr", "unable to create temporary file"); } - } - break; + ce->ce_file = add (tfile, NULL); + ce->ce_unlink = 1; + + xstdout = 0; - case 'F': - /* %f, and stdout is not-redirected */ - xstdout = 1; - /* and fall... */ + /* Get buffer ready to go */ + bp = buffer; + bp[0] = '\0'; + buflen = sizeof(buffer); - case 'f': /* - * insert temporary filename where - * content should be written + * Parse composition string into buffer */ - snprintf (bp, buflen, "%s", ce->ce_file); - break; + for ( ; *cp; cp++) { + if (*cp == '%') { + switch (*++cp) { + case 'a': + { + /* insert parameters from directive */ + char **ep; + char *s = ""; + + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); + len = strlen (bp); + bp += len; + buflen -= len; + s = " "; + } + } + break; + + case 'F': + /* %f, and stdout is not-redirected */ + xstdout = 1; + /* and fall... */ + + case 'f': + /* + * insert temporary filename where + * content should be written + */ + snprintf (bp, buflen, "%s", ce->ce_file); + break; + + case 's': + /* insert content subtype */ + strncpy (bp, ci->ci_subtype, buflen); + break; + + case '%': + /* insert character % */ + goto raw; + + default: + *bp++ = *--cp; + *bp = '\0'; + buflen--; + continue; + } + len = strlen (bp); + bp += len; + buflen -= len; + } else { +raw: + *bp++ = *cp; + *bp = '\0'; + buflen--; + } + } - case 's': - /* insert content subtype */ - strncpy (bp, ci->ci_subtype, buflen); - break; + if (verbosw) + printf ("composing content %s/%s from command\n\t%s\n", + ci->ci_type, ci->ci_subtype, buffer); + + fflush (stdout); /* not sure if need for -noverbose */ + + vec[0] = "/bin/sh"; + vec[1] = "-c"; + vec[2] = buffer; + vec[3] = NULL; + + if ((out = fopen (ce->ce_file, "w")) == NULL) + adios (ce->ce_file, "unable to open for writing"); + + for (i = 0; (child_id = vfork()) == NOTOK && i > 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + adios ("fork", "unable to fork"); + /* NOTREACHED */ + + case OK: + if (!xstdout) + dup2 (fileno (out), 1); + close (fileno (out)); + execvp ("/bin/sh", vec); + fprintf (stderr, "unable to exec "); + perror ("/bin/sh"); + _exit (-1); + /* NOTREACHED */ + + default: + fclose (out); + if (pidXwait(child_id, NULL)) + done (1); + break; + } + } - case '%': - /* insert character % */ - goto raw; + /* Check size of file */ + if (listsw && ct->c_end == 0L) { + struct stat st; - default: - *bp++ = *--cp; - *bp = '\0'; - buflen--; - continue; - } - len = strlen (bp); - bp += len; - buflen -= len; - } else { -raw: - *bp++ = *cp; - *bp = '\0'; - buflen--; + if (stat (ce->ce_file, &st) != NOTOK) + ct->c_end = (long) st.st_size; } - } - - if (verbosw) - printf ("composing content %s/%s from command\n\t%s\n", - ci->ci_type, ci->ci_subtype, buffer); - - fflush (stdout); /* not sure if need for -noverbose */ - - vec[0] = "/bin/sh"; - vec[1] = "-c"; - vec[2] = buffer; - vec[3] = NULL; - - if ((out = fopen (ce->ce_file, "w")) == NULL) - adios (ce->ce_file, "unable to open for writing"); - - for (i = 0; (child_id = vfork()) == NOTOK && i > 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - adios ("fork", "unable to fork"); - /* NOTREACHED */ - - case OK: - if (!xstdout) - dup2 (fileno (out), 1); - close (fileno (out)); - execvp ("/bin/sh", vec); - fprintf (stderr, "unable to exec "); - perror ("/bin/sh"); - _exit (-1); - /* NOTREACHED */ - - default: - fclose (out); - if (pidXwait(child_id, NULL)) - done (1); break; - } } - /* Check size of file */ - if (listsw && ct->c_end == 0L) { - struct stat st; - - if (stat (ce->ce_file, &st) != NOTOK) - ct->c_end = (long) st.st_size; - } - break; - } - - return OK; + return OK; } @@ -1155,220 +1154,220 @@ raw: static int scan_content (CT ct) { - int len; - int check8bit = 0, contains8bit = 0; /* check if contains 8bit data */ - int checklinelen = 0, linelen = 0; /* check for long lines */ - int checkboundary = 0, boundaryclash = 0; /* check if clashes with multipart boundary */ - int checklinespace = 0, linespace = 0; /* check if any line ends with space */ - int checkebcdic = 0, ebcdicunsafe = 0; /* check if contains ebcdic unsafe characters */ - unsigned char *cp = NULL, buffer[BUFSIZ]; - struct text *t = NULL; - FILE *in = NULL; - CE ce = ct->c_cefile; - - /* - * handle multipart by scanning all subparts - * and then checking their encoding. - */ - if (ct->c_type == CT_MULTIPART) { - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - - /* initially mark the domain of enclosing multipart as 7bit */ - ct->c_encoding = CE_7BIT; - - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; - - if (scan_content (p) == NOTOK) /* choose encoding for subpart */ - return NOTOK; - - /* if necessary, enlarge encoding for enclosing multipart */ - if (p->c_encoding == CE_BINARY) - ct->c_encoding = CE_BINARY; - if (p->c_encoding == CE_8BIT && ct->c_encoding != CE_BINARY) - ct->c_encoding = CE_8BIT; - } + int len; + int check8bit = 0, contains8bit = 0; /* check if contains 8bit data */ + int checklinelen = 0, linelen = 0; /* check for long lines */ + int checkboundary = 0, boundaryclash = 0; /* check if clashes with multipart boundary */ + int checklinespace = 0, linespace = 0; /* check if any line ends with space */ + int checkebcdic = 0, ebcdicunsafe = 0; /* check if contains ebcdic unsafe characters */ + unsigned char *cp = NULL, buffer[BUFSIZ]; + struct text *t = NULL; + FILE *in = NULL; + CE ce = ct->c_cefile; - return OK; - } - - /* - * Decide what to check while scanning this content. - */ - switch (ct->c_type) { - case CT_TEXT: - check8bit = 1; - checkboundary = 1; - if (ct->c_subtype == TEXT_PLAIN) { - checkebcdic = 0; - checklinelen = 0; - checklinespace = 0; - } else { - checkebcdic = ebcdicsw; - checklinelen = 1; - checklinespace = 1; + /* + * handle multipart by scanning all subparts + * and then checking their encoding. + */ + if (ct->c_type == CT_MULTIPART) { + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; + + /* initially mark the domain of enclosing multipart as 7bit */ + ct->c_encoding = CE_7BIT; + + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; + + if (scan_content (p) == NOTOK) /* choose encoding for subpart */ + return NOTOK; + + /* if necessary, enlarge encoding for enclosing multipart */ + if (p->c_encoding == CE_BINARY) + ct->c_encoding = CE_BINARY; + if (p->c_encoding == CE_8BIT && ct->c_encoding != CE_BINARY) + ct->c_encoding = CE_8BIT; + } + + return OK; } - break; - case CT_APPLICATION: - check8bit = 1; - checkebcdic = ebcdicsw; - checklinelen = 1; - checklinespace = 1; - checkboundary = 1; - break; + /* + * Decide what to check while scanning this content. + */ + switch (ct->c_type) { + case CT_TEXT: + check8bit = 1; + checkboundary = 1; + if (ct->c_subtype == TEXT_PLAIN) { + checkebcdic = 0; + checklinelen = 0; + checklinespace = 0; + } else { + checkebcdic = ebcdicsw; + checklinelen = 1; + checklinespace = 1; + } + break; - case CT_MESSAGE: - check8bit = 0; - checkebcdic = 0; - checklinelen = 0; - checklinespace = 0; - - /* don't check anything for message/external */ - if (ct->c_subtype == MESSAGE_EXTERNAL) - checkboundary = 0; - else - checkboundary = 1; - break; + case CT_APPLICATION: + check8bit = 1; + checkebcdic = ebcdicsw; + checklinelen = 1; + checklinespace = 1; + checkboundary = 1; + break; + + case CT_MESSAGE: + check8bit = 0; + checkebcdic = 0; + checklinelen = 0; + checklinespace = 0; + + /* don't check anything for message/external */ + if (ct->c_subtype == MESSAGE_EXTERNAL) + checkboundary = 0; + else + checkboundary = 1; + break; + + case CT_AUDIO: + case CT_IMAGE: + case CT_VIDEO: + /* + * Don't check anything for these types, + * since we are forcing use of base64. + */ + check8bit = 0; + checkebcdic = 0; + checklinelen = 0; + checklinespace = 0; + checkboundary = 0; + break; + } - case CT_AUDIO: - case CT_IMAGE: - case CT_VIDEO: /* - * Don't check anything for these types, - * since we are forcing use of base64. + * Scan the unencoded content */ - check8bit = 0; - checkebcdic = 0; - checklinelen = 0; - checklinespace = 0; - checkboundary = 0; - break; - } + if (check8bit || checklinelen || checklinespace || checkboundary) { + if ((in = fopen (ce->ce_file, "r")) == NULL) + adios (ce->ce_file, "unable to open for reading"); + len = strlen (prefix); - /* - * Scan the unencoded content - */ - if (check8bit || checklinelen || checklinespace || checkboundary) { - if ((in = fopen (ce->ce_file, "r")) == NULL) - adios (ce->ce_file, "unable to open for reading"); - len = strlen (prefix); - - while (fgets (buffer, sizeof(buffer) - 1, in)) { - /* - * Check for 8bit data. - */ - if (check8bit) { - for (cp = buffer; *cp; cp++) { - if (!isascii (*cp)) { - contains8bit = 1; - check8bit = 0; /* no need to keep checking */ - } - /* - * Check if character is ebcdic-safe. We only check - * this if also checking for 8bit data. - */ - if (checkebcdic && !ebcdicsafe[*cp & 0xff]) { - ebcdicunsafe = 1; - checkebcdic = 0; /* no need to keep checking */ - } - } - } - - /* - * Check line length. - */ - if (checklinelen && (strlen (buffer) > CPERLIN + 1)) { - linelen = 1; - checklinelen = 0; /* no need to keep checking */ - } - - /* - * Check if line ends with a space. - */ - if (checklinespace && (cp = buffer + strlen (buffer) - 2) > buffer && isspace (*cp)) { - linespace = 1; - checklinespace = 0; /* no need to keep checking */ - } - - /* - * Check if content contains a line that clashes - * with our standard boundary for multipart messages. - */ - if (checkboundary && buffer[0] == '-' && buffer[1] == '-') { - for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--) - if (!isspace (*cp)) - break; - *++cp = '\0'; - if (!strncmp(buffer + 2, prefix, len) && isdigit(buffer[2 + len])) { - boundaryclash = 1; - checkboundary = 0; /* no need to keep checking */ + while (fgets (buffer, sizeof(buffer) - 1, in)) { + /* + * Check for 8bit data. + */ + if (check8bit) { + for (cp = buffer; *cp; cp++) { + if (!isascii (*cp)) { + contains8bit = 1; + check8bit = 0; /* no need to keep checking */ + } + /* + * Check if character is ebcdic-safe. We only check + * this if also checking for 8bit data. + */ + if (checkebcdic && !ebcdicsafe[*cp & 0xff]) { + ebcdicunsafe = 1; + checkebcdic = 0; /* no need to keep checking */ + } + } + } + + /* + * Check line length. + */ + if (checklinelen && (strlen (buffer) > CPERLIN + 1)) { + linelen = 1; + checklinelen = 0; /* no need to keep checking */ + } + + /* + * Check if line ends with a space. + */ + if (checklinespace && (cp = buffer + strlen (buffer) - 2) > buffer && isspace (*cp)) { + linespace = 1; + checklinespace = 0; /* no need to keep checking */ + } + + /* + * Check if content contains a line that clashes + * with our standard boundary for multipart messages. + */ + if (checkboundary && buffer[0] == '-' && buffer[1] == '-') { + for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--) + if (!isspace (*cp)) + break; + *++cp = '\0'; + if (!strncmp(buffer + 2, prefix, len) && isdigit(buffer[2 + len])) { + boundaryclash = 1; + checkboundary = 0; /* no need to keep checking */ + } + } } - } + fclose (in); } - fclose (in); - } - /* - * Decide which transfer encoding to use. - */ - switch (ct->c_type) { - case CT_TEXT: /* - * If the text content didn't specify a character - * set, we need to figure out which one was used. + * Decide which transfer encoding to use. */ - t = (struct text *) ct->c_ctparams; - if (t->tx_charset == CHARSET_UNSPECIFIED) { - CI ci = &ct->c_ctinfo; - char **ap, **ep; - - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) - continue; - - if (contains8bit) { - t->tx_charset = CHARSET_UNKNOWN; - *ap = concat ("charset=", write_charset_8bit(), NULL); - } else { - t->tx_charset = CHARSET_USASCII; - *ap = add ("charset=us-ascii", NULL); - } - - cp = strchr(*ap++, '='); - *ap = NULL; - *cp++ = '\0'; - *ep = cp; - } + switch (ct->c_type) { + case CT_TEXT: + /* + * If the text content didn't specify a character + * set, we need to figure out which one was used. + */ + t = (struct text *) ct->c_ctparams; + if (t->tx_charset == CHARSET_UNSPECIFIED) { + CI ci = &ct->c_ctinfo; + char **ap, **ep; + + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) + continue; + + if (contains8bit) { + t->tx_charset = CHARSET_UNKNOWN; + *ap = concat ("charset=", write_charset_8bit(), NULL); + } else { + t->tx_charset = CHARSET_USASCII; + *ap = add ("charset=us-ascii", NULL); + } - if (contains8bit || ebcdicunsafe || linelen || linespace || checksw) - ct->c_encoding = CE_QUOTED; - else - ct->c_encoding = CE_7BIT; - break; + cp = strchr(*ap++, '='); + *ap = NULL; + *cp++ = '\0'; + *ep = cp; + } - case CT_APPLICATION: - /* For application type, use base64, except when postscript */ - if (contains8bit || ebcdicunsafe || linelen || linespace || checksw) - ct->c_encoding = (ct->c_subtype == APPLICATION_POSTSCRIPT) - ? CE_QUOTED : CE_BASE64; - else - ct->c_encoding = CE_7BIT; - break; + if (contains8bit || ebcdicunsafe || linelen || linespace || checksw) + ct->c_encoding = CE_QUOTED; + else + ct->c_encoding = CE_7BIT; + break; - case CT_MESSAGE: - ct->c_encoding = CE_7BIT; - break; + case CT_APPLICATION: + /* For application type, use base64, except when postscript */ + if (contains8bit || ebcdicunsafe || linelen || linespace || checksw) + ct->c_encoding = (ct->c_subtype == APPLICATION_POSTSCRIPT) + ? CE_QUOTED : CE_BASE64; + else + ct->c_encoding = CE_7BIT; + break; - case CT_AUDIO: - case CT_IMAGE: - case CT_VIDEO: - /* For audio, image, and video contents, just use base64 */ - ct->c_encoding = CE_BASE64; - break; - } + case CT_MESSAGE: + ct->c_encoding = CE_7BIT; + break; + + case CT_AUDIO: + case CT_IMAGE: + case CT_VIDEO: + /* For audio, image, and video contents, just use base64 */ + ct->c_encoding = CE_BASE64; + break; + } - return (boundaryclash ? NOTOK : OK); + return (boundaryclash ? NOTOK : OK); } @@ -1381,227 +1380,227 @@ scan_content (CT ct) static int build_headers (CT ct) { - int cc, mailbody, len; - char **ap, **ep; - char *np, *vp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; - - /* - * If message is type multipart, then add the multipart - * boundary to the list of attribute/value pairs. - */ - if (ct->c_type == CT_MULTIPART) { - char *cp; - static int level = 0; /* store nesting level */ - - ap = ci->ci_attrs; - ep = ci->ci_values; - snprintf (buffer, sizeof(buffer), "boundary=%s%d", prefix, level++); - cp = strchr(*ap++ = add (buffer, NULL), '='); - *ap = NULL; - *cp++ = '\0'; - *ep = cp; - } - - /* - * Skip the output of Content-Type, parameters, content - * description and disposition, and Content-ID if the - * content is of type "message" and the rfc934 compatibility - * flag is set (which means we are inside multipart/digest - * and the switch -rfc934mode was given). - */ - if (ct->c_type == CT_MESSAGE && ct->c_rfc934) - goto skip_headers; - - /* - * output the content type and subtype - */ - np = add (TYPE_FIELD, NULL); - vp = concat (" ", ci->ci_type, "/", ci->ci_subtype, NULL); - - /* keep track of length of line */ - len = strlen (TYPE_FIELD) + strlen (ci->ci_type) + int cc, mailbody, len; + char **ap, **ep; + char *np, *vp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; + + /* + * If message is type multipart, then add the multipart + * boundary to the list of attribute/value pairs. + */ + if (ct->c_type == CT_MULTIPART) { + char *cp; + static int level = 0; /* store nesting level */ + + ap = ci->ci_attrs; + ep = ci->ci_values; + snprintf (buffer, sizeof(buffer), "boundary=%s%d", prefix, level++); + cp = strchr(*ap++ = add (buffer, NULL), '='); + *ap = NULL; + *cp++ = '\0'; + *ep = cp; + } + + /* + * Skip the output of Content-Type, parameters, content + * description and disposition, and Content-ID if the + * content is of type "message" and the rfc934 compatibility + * flag is set (which means we are inside multipart/digest + * and the switch -rfc934mode was given). + */ + if (ct->c_type == CT_MESSAGE && ct->c_rfc934) + goto skip_headers; + + /* + * output the content type and subtype + */ + np = add (TYPE_FIELD, NULL); + vp = concat (" ", ci->ci_type, "/", ci->ci_subtype, NULL); + + /* keep track of length of line */ + len = strlen (TYPE_FIELD) + strlen (ci->ci_type) + strlen (ci->ci_subtype) + 3; - mailbody = ct->c_type == CT_MESSAGE - && ct->c_subtype == MESSAGE_EXTERNAL - && ((struct exbody *) ct->c_ctparams)->eb_body; - - /* - * Append the attribute/value pairs to - * the end of the Content-Type line. - */ - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - if (mailbody && !mh_strcasecmp (*ap, "body")) - continue; - - vp = add (";", vp); - len++; - - snprintf (buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep); - if (len + 1 + (cc = strlen (buffer)) >= CPERLIN) { - vp = add ("\n\t", vp); - len = 8; - } else { - vp = add (" ", vp); - len++; + mailbody = ct->c_type == CT_MESSAGE + && ct->c_subtype == MESSAGE_EXTERNAL + && ((struct exbody *) ct->c_ctparams)->eb_body; + + /* + * Append the attribute/value pairs to + * the end of the Content-Type line. + */ + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + if (mailbody && !mh_strcasecmp (*ap, "body")) + continue; + + vp = add (";", vp); + len++; + + snprintf (buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep); + if (len + 1 + (cc = strlen (buffer)) >= CPERLIN) { + vp = add ("\n\t", vp); + len = 8; + } else { + vp = add (" ", vp); + len++; + } + vp = add (buffer, vp); + len += cc; } - vp = add (buffer, vp); - len += cc; - } - - /* - * Append any RFC-822 comment to the end of - * the Content-Type line. - */ - if (ci->ci_comment) { - snprintf (buffer, sizeof(buffer), "(%s)", ci->ci_comment); - if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) { - vp = add ("\n\t", vp); - len = 8; - } else { - vp = add (" ", vp); - len++; + + /* + * Append any RFC-822 comment to the end of + * the Content-Type line. + */ + if (ci->ci_comment) { + snprintf (buffer, sizeof(buffer), "(%s)", ci->ci_comment); + if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) { + vp = add ("\n\t", vp); + len = 8; + } else { + vp = add (" ", vp); + len++; + } + vp = add (buffer, vp); + len += cc; } - vp = add (buffer, vp); - len += cc; - } - vp = add ("\n", vp); - add_header (ct, np, vp); - - /* - * output the Content-ID, unless disabled by -nocontentid - */ - if (contentidsw && ct->c_id) { - np = add (ID_FIELD, NULL); - vp = concat (" ", ct->c_id, NULL); + vp = add ("\n", vp); add_header (ct, np, vp); - } - - /* - * output the Content-Description - */ - if (ct->c_descr) { - np = add (DESCR_FIELD, NULL); - vp = concat (" ", ct->c_descr, NULL); - add_header (ct, np, vp); - } - - /* - * output the Content-Disposition - */ - if (ct->c_dispo) { - np = add (DISPO_FIELD, NULL); - vp = concat (" ", ct->c_dispo, NULL); - add_header (ct, np, vp); - } + + /* + * output the Content-ID, unless disabled by -nocontentid + */ + if (contentidsw && ct->c_id) { + np = add (ID_FIELD, NULL); + vp = concat (" ", ct->c_id, NULL); + add_header (ct, np, vp); + } + + /* + * output the Content-Description + */ + if (ct->c_descr) { + np = add (DESCR_FIELD, NULL); + vp = concat (" ", ct->c_descr, NULL); + add_header (ct, np, vp); + } + + /* + * output the Content-Disposition + */ + if (ct->c_dispo) { + np = add (DISPO_FIELD, NULL); + vp = concat (" ", ct->c_dispo, NULL); + add_header (ct, np, vp); + } skip_headers: - /* - * If this is the internal content structure for a - * "message/external", then we are done with the - * headers (since it has no body). - */ - if (ct->c_ctexbody) - return OK; + /* + * If this is the internal content structure for a + * "message/external", then we are done with the + * headers (since it has no body). + */ + if (ct->c_ctexbody) + return OK; - /* - * output the Content-MD5 - */ - if (checksw) { - np = add (MD5_FIELD, NULL); - vp = calculate_digest (ct, (ct->c_encoding == CE_QUOTED) ? 1 : 0); - add_header (ct, np, vp); - } - - /* - * output the Content-Transfer-Encoding - */ - switch (ct->c_encoding) { - case CE_7BIT: - /* Nothing to output */ + /* + * output the Content-MD5 + */ + if (checksw) { + np = add (MD5_FIELD, NULL); + vp = calculate_digest (ct, (ct->c_encoding == CE_QUOTED) ? 1 : 0); + add_header (ct, np, vp); + } + + /* + * output the Content-Transfer-Encoding + */ + switch (ct->c_encoding) { + case CE_7BIT: + /* Nothing to output */ #if 0 - np = add (ENCODING_FIELD, NULL); - vp = concat (" ", "7bit", "\n", NULL); - add_header (ct, np, vp); + np = add (ENCODING_FIELD, NULL); + vp = concat (" ", "7bit", "\n", NULL); + add_header (ct, np, vp); #endif - break; + break; - case CE_8BIT: - if (ct->c_type == CT_MESSAGE) - adios (NULL, "internal error, invalid encoding"); + case CE_8BIT: + if (ct->c_type == CT_MESSAGE) + adios (NULL, "internal error, invalid encoding"); - np = add (ENCODING_FIELD, NULL); - vp = concat (" ", "8bit", "\n", NULL); - add_header (ct, np, vp); - break; + np = add (ENCODING_FIELD, NULL); + vp = concat (" ", "8bit", "\n", NULL); + add_header (ct, np, vp); + break; - case CE_QUOTED: - if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART) - adios (NULL, "internal error, invalid encoding"); + case CE_QUOTED: + if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART) + adios (NULL, "internal error, invalid encoding"); - np = add (ENCODING_FIELD, NULL); - vp = concat (" ", "quoted-printable", "\n", NULL); - add_header (ct, np, vp); - break; + np = add (ENCODING_FIELD, NULL); + vp = concat (" ", "quoted-printable", "\n", NULL); + add_header (ct, np, vp); + break; - case CE_BASE64: - if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART) - adios (NULL, "internal error, invalid encoding"); + case CE_BASE64: + if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART) + adios (NULL, "internal error, invalid encoding"); - np = add (ENCODING_FIELD, NULL); - vp = concat (" ", "base64", "\n", NULL); - add_header (ct, np, vp); - break; + np = add (ENCODING_FIELD, NULL); + vp = concat (" ", "base64", "\n", NULL); + add_header (ct, np, vp); + break; - case CE_BINARY: - if (ct->c_type == CT_MESSAGE) - adios (NULL, "internal error, invalid encoding"); + case CE_BINARY: + if (ct->c_type == CT_MESSAGE) + adios (NULL, "internal error, invalid encoding"); - np = add (ENCODING_FIELD, NULL); - vp = concat (" ", "binary", "\n", NULL); - add_header (ct, np, vp); - break; + np = add (ENCODING_FIELD, NULL); + vp = concat (" ", "binary", "\n", NULL); + add_header (ct, np, vp); + break; - default: - adios (NULL, "unknown transfer encoding in content"); - break; - } - - /* - * Additional content specific header processing - */ - switch (ct->c_type) { - case CT_MULTIPART: - { - struct multipart *m; - struct part *part; + default: + adios (NULL, "unknown transfer encoding in content"); + break; + } + + /* + * Additional content specific header processing + */ + switch (ct->c_type) { + case CT_MULTIPART: + { + struct multipart *m; + struct part *part; - m = (struct multipart *) ct->c_ctparams; - for (part = m->mp_parts; part; part = part->mp_next) { - CT p; + m = (struct multipart *) ct->c_ctparams; + for (part = m->mp_parts; part; part = part->mp_next) { + CT p; - p = part->mp_part; - build_headers (p); + p = part->mp_part; + build_headers (p); + } } - } - break; + break; - case CT_MESSAGE: - if (ct->c_subtype == MESSAGE_EXTERNAL) { - struct exbody *e; + case CT_MESSAGE: + if (ct->c_subtype == MESSAGE_EXTERNAL) { + struct exbody *e; - e = (struct exbody *) ct->c_ctparams; - build_headers (e->eb_content); - } - break; + e = (struct exbody *) ct->c_ctparams; + build_headers (e->eb_content); + } + break; - default: - /* Nothing to do */ - break; - } + default: + /* Nothing to do */ + break; + } - return OK; + return OK; } @@ -1611,85 +1610,85 @@ static char nib2b64[0x40+1] = static char * calculate_digest (CT ct, int asciiP) { - int cc; - char buffer[BUFSIZ], *vp, *op; - unsigned char *dp; - unsigned char digest[16]; - unsigned char outbuf[25]; - FILE *in; - MD5_CTX mdContext; - CE ce = ct->c_cefile; - - /* open content */ - if ((in = fopen (ce->ce_file, "r")) == NULL) - adios (ce->ce_file, "unable to open for reading"); - - /* Initialize md5 context */ - MD5Init (&mdContext); - - /* calculate md5 message digest */ - if (asciiP) { - while (fgets (buffer, sizeof(buffer) - 1, in)) { - char c, *cp; - - cp = buffer + strlen (buffer) - 1; - if ((c = *cp) == '\n') - *cp = '\0'; + int cc; + char buffer[BUFSIZ], *vp, *op; + unsigned char *dp; + unsigned char digest[16]; + unsigned char outbuf[25]; + FILE *in; + MD5_CTX mdContext; + CE ce = ct->c_cefile; + + /* open content */ + if ((in = fopen (ce->ce_file, "r")) == NULL) + adios (ce->ce_file, "unable to open for reading"); + + /* Initialize md5 context */ + MD5Init (&mdContext); + + /* calculate md5 message digest */ + if (asciiP) { + while (fgets (buffer, sizeof(buffer) - 1, in)) { + char c, *cp; - MD5Update (&mdContext, (unsigned char *) buffer, - (unsigned int) strlen (buffer)); + cp = buffer + strlen (buffer) - 1; + if ((c = *cp) == '\n') + *cp = '\0'; - if (c == '\n') - MD5Update (&mdContext, (unsigned char *) "\r\n", 2); + MD5Update (&mdContext, (unsigned char *) buffer, + (unsigned int) strlen (buffer)); + + if (c == '\n') + MD5Update (&mdContext, (unsigned char *) "\r\n", 2); + } + } else { + while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), in)) > 0) + MD5Update (&mdContext, (unsigned char *) buffer, (unsigned int) cc); } - } else { - while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), in)) > 0) - MD5Update (&mdContext, (unsigned char *) buffer, (unsigned int) cc); - } - - /* md5 finalization. Write digest and zero md5 context */ - MD5Final (digest, &mdContext); - - /* close content */ - fclose (in); - - /* print debugging info */ - if (debugsw) { - unsigned char *ep; - - fprintf (stderr, "MD5 digest="); - for (ep = (dp = digest) + sizeof(digest) / sizeof(digest[0]); - dp < ep; dp++) - fprintf (stderr, "%02x", *dp & 0xff); - fprintf (stderr, "\n"); - } - - /* encode the digest using base64 */ - for (dp = digest, op = outbuf, cc = sizeof(digest) / sizeof(digest[0]); - cc > 0; cc -= 3, op += 4) { - unsigned long bits; - char *bp; - - bits = (*dp++ & 0xff) << 16; - if (cc > 1) { - bits |= (*dp++ & 0xff) << 8; - if (cc > 2) - bits |= *dp++ & 0xff; + + /* md5 finalization. Write digest and zero md5 context */ + MD5Final (digest, &mdContext); + + /* close content */ + fclose (in); + + /* print debugging info */ + if (debugsw) { + unsigned char *ep; + + fprintf (stderr, "MD5 digest="); + for (ep = (dp = digest) + sizeof(digest) / sizeof(digest[0]); + dp < ep; dp++) + fprintf (stderr, "%02x", *dp & 0xff); + fprintf (stderr, "\n"); } - for (bp = op + 4; bp > op; bits >>= 6) - *--bp = nib2b64[bits & 0x3f]; - if (cc < 3) { - *(op + 3) = '='; - if (cc < 2) - *(op + 2) = '='; + /* encode the digest using base64 */ + for (dp = digest, op = outbuf, cc = sizeof(digest) / sizeof(digest[0]); + cc > 0; cc -= 3, op += 4) { + unsigned long bits; + char *bp; + + bits = (*dp++ & 0xff) << 16; + if (cc > 1) { + bits |= (*dp++ & 0xff) << 8; + if (cc > 2) + bits |= *dp++ & 0xff; + } + + for (bp = op + 4; bp > op; bits >>= 6) + *--bp = nib2b64[bits & 0x3f]; + if (cc < 3) { + *(op + 3) = '='; + if (cc < 2) + *(op + 2) = '='; + } } - } - /* null terminate string */ - outbuf[24] = '\0'; + /* null terminate string */ + outbuf[24] = '\0'; - /* now make copy and return string */ - vp = concat (" ", outbuf, "\n", NULL); - return vp; + /* now make copy and return string */ + vp = concat (" ", outbuf, "\n", NULL); + return vp; } diff --git a/uip/mhcachesbr.c b/uip/mhcachesbr.c index 2223e80..0cefa87 100644 --- a/uip/mhcachesbr.c +++ b/uip/mhcachesbr.c @@ -1,4 +1,3 @@ - /* * mhcachesbr.c -- routines to manipulate the MIME content cache * @@ -38,7 +37,7 @@ extern int debugsw; -extern pid_t xpid; /* mhshowsbr.c or mhbuildsbr.c */ +extern pid_t xpid; /* mhshowsbr.c or mhbuildsbr.c */ /* cache policies */ int rcachesw = CACHE_ASK; @@ -84,21 +83,21 @@ static int find_cache_aux2 (char *, char *, char *, int); void cache_all_messages (CT *cts) { - CT ct, *ctp; - - for (ctp = cts; *ctp; ctp++) { - ct = *ctp; - if (type_ok (ct, 1)) { - cache_content (ct); - if (ct->c_fp) { - fclose (ct->c_fp); - ct->c_fp = NULL; - } - if (ct->c_ceclosefnx) - (*ct->c_ceclosefnx) (ct); + CT ct, *ctp; + + for (ctp = cts; *ctp; ctp++) { + ct = *ctp; + if (type_ok (ct, 1)) { + cache_content (ct); + if (ct->c_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } + if (ct->c_ceclosefnx) + (*ct->c_ceclosefnx) (ct); + } } - } - flush_errors (); + flush_errors (); } @@ -109,85 +108,85 @@ cache_all_messages (CT *cts) static void cache_content (CT ct) { - int cachetype; - char *file, cachefile[BUFSIZ]; - CE ce = ct->c_cefile; + int cachetype; + char *file, cachefile[BUFSIZ]; + CE ce = ct->c_cefile; - if (!ct->c_id) { - advise (NULL, "no %s: field in %s", ID_FIELD, ct->c_file); - return; - } + if (!ct->c_id) { + advise (NULL, "no %s: field in %s", ID_FIELD, ct->c_file); + return; + } - if (!ce) { - advise (NULL, "unable to decode %s", ct->c_file); - return; - } + if (!ce) { + advise (NULL, "unable to decode %s", ct->c_file); + return; + } /* THIS NEEDS TO BE FIXED */ #if 0 - if (ct->c_ceopenfnx == openMail) { - advise (NULL, "a radish may no know Greek, but I do..."); - return; - } + if (ct->c_ceopenfnx == openMail) { + advise (NULL, "a radish may no know Greek, but I do..."); + return; + } #endif - if (find_cache (NULL, wcachesw != CACHE_NEVER ? wcachesw : CACHE_ASK, - &cachetype, ct->c_id, cachefile, sizeof(cachefile)) - == NOTOK) { - advise (NULL, "unable to cache %s's contents", ct->c_file); - return; - } - if (wcachesw != CACHE_NEVER && wcachesw != CACHE_ASK) { - fflush (stdout); - fprintf (stderr, "caching message %s as file %s\n", ct->c_file, - cachefile); - } - - if (ce->ce_file) { - int mask = umask (cachetype ? ~m_gmprot () : 0222); - FILE *fp; + if (find_cache (NULL, wcachesw != CACHE_NEVER ? wcachesw : CACHE_ASK, + &cachetype, ct->c_id, cachefile, sizeof(cachefile)) + == NOTOK) { + advise (NULL, "unable to cache %s's contents", ct->c_file); + return; + } + if (wcachesw != CACHE_NEVER && wcachesw != CACHE_ASK) { + fflush (stdout); + fprintf (stderr, "caching message %s as file %s\n", ct->c_file, + cachefile); + } - if (debugsw) - fprintf (stderr, "caching by copying %s...\n", ce->ce_file); - - file = NULL; - if ((*ct->c_ceopenfnx) (ct, &file) == NOTOK) - goto reset_umask; - - if ((fp = fopen (cachefile, "w"))) { - int cc; - char buffer[BUFSIZ]; - FILE *gp = ce->ce_fp; - - fseek (gp, 0L, SEEK_SET); - - while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) - > 0) - fwrite (buffer, sizeof(*buffer), cc, fp); - fflush (fp); - - if (ferror (gp)) { - admonish (ce->ce_file, "error reading"); - unlink (cachefile); - } else { - if (ferror (fp)) { - admonish (cachefile, "error writing"); - unlink (cachefile); - } - } - fclose (fp); - } else - content_error (cachefile, ct, "unable to fopen for writing"); + if (ce->ce_file) { + int mask = umask (cachetype ? ~m_gmprot () : 0222); + FILE *fp; + + if (debugsw) + fprintf (stderr, "caching by copying %s...\n", ce->ce_file); + + file = NULL; + if ((*ct->c_ceopenfnx) (ct, &file) == NOTOK) + goto reset_umask; + + if ((fp = fopen (cachefile, "w"))) { + int cc; + char buffer[BUFSIZ]; + FILE *gp = ce->ce_fp; + + fseek (gp, 0L, SEEK_SET); + + while ((cc = fread (buffer, sizeof(*buffer), + sizeof(buffer), gp)) > 0) + fwrite (buffer, sizeof(*buffer), cc, fp); + fflush (fp); + + if (ferror (gp)) { + admonish (ce->ce_file, "error reading"); + unlink (cachefile); + } else { + if (ferror (fp)) { + admonish (cachefile, "error writing"); + unlink (cachefile); + } + } + fclose (fp); + } else + content_error (cachefile, ct, "unable to fopen for writing"); reset_umask: - umask (mask); - } else { - if (debugsw) - fprintf (stderr, "in place caching...\n"); + umask (mask); + } else { + if (debugsw) + fprintf (stderr, "in place caching...\n"); - file = cachefile; - if ((*ct->c_ceopenfnx) (ct, &file) != NOTOK) - chmod (cachefile, cachetype ? m_gmprot () : 0444); - } + file = cachefile; + if ((*ct->c_ceopenfnx) (ct, &file) != NOTOK) + chmod (cachefile, cachetype ? m_gmprot () : 0444); + } } @@ -195,114 +194,111 @@ int find_cache (CT ct, int policy, int *writing, char *id, char *buffer, int buflen) { - int status = NOTOK; + int status = NOTOK; - if (id == NULL) - return NOTOK; - id = trimcpy (id); - - if (debugsw) - fprintf (stderr, "find_cache %s(%d) %s %s\n", caches[policy].sw, - policy, writing ? "writing" : "reading", id); - - switch (policy) { - case CACHE_NEVER: - default: - break; - - case CACHE_ASK: - case CACHE_PUBLIC: - if (cache_private - && !writing - && find_cache_aux (writing ? 2 : 0, cache_private, id, - buffer, buflen) == OK) { - if (access (buffer, R_OK) != NOTOK) { + if (id == NULL) + return NOTOK; + id = trimcpy (id); + + if (debugsw) + fprintf (stderr, "find_cache %s(%d) %s %s\n", caches[policy].sw, + policy, writing ? "writing" : "reading", id); + + switch (policy) { + case CACHE_NEVER: + default: + break; + + case CACHE_ASK: + case CACHE_PUBLIC: + if (cache_private && !writing + && find_cache_aux (writing ? 2 : 0, + cache_private, id, buffer, buflen) == OK) { + if (access (buffer, R_OK) != NOTOK) { got_private: - if (writing) - *writing = 1; + if (writing) + *writing = 1; got_it: - status = OK; - break; - } - } - if (cache_public - && find_cache_aux (writing ? 1 : 0, cache_public, id, - buffer, buflen) == OK) { - if (writing || access (buffer, R_OK) != NOTOK) { - if (writing) - *writing = 0; - goto got_it; - } - } - break; - - case CACHE_PRIVATE: - if (cache_private - && find_cache_aux (writing ? 2 : 0, cache_private, id, - buffer, buflen) == OK) { - if (writing || access (buffer, R_OK) != NOTOK) - goto got_private; - } - break; - - } - - if (status == OK && policy == CACHE_ASK) { - int len, buflen; - char *bp, query[BUFSIZ]; - - if (xpid) { - if (xpid < 0) - xpid = -xpid; - pidcheck (pidwait (xpid, NOTOK)); - xpid = 0; - } + status = OK; + break; + } + } + if (cache_public && find_cache_aux (writing ? 1 : 0, + cache_public, id, buffer, buflen) == OK) { + if (writing || access (buffer, R_OK) != NOTOK) { + if (writing) + *writing = 0; + goto got_it; + } + } + break; + + case CACHE_PRIVATE: + if (cache_private && find_cache_aux (writing ? 2 : 0, + cache_private, id, buffer, buflen) == OK) { + if (writing || access (buffer, R_OK) != NOTOK) + goto got_private; + } + break; - /* Get buffer ready to go */ - bp = query; - buflen = sizeof(query); + } - /* Now, construct query */ - if (writing) { - snprintf (bp, buflen, "Make cached, publically-accessible copy"); - } else { - struct stat st; + if (status == OK && policy == CACHE_ASK) { + int len, buflen; + char *bp, query[BUFSIZ]; - snprintf (bp, buflen, "Use cached copy"); - len = strlen (bp); - bp += len; - buflen -= len; + if (xpid) { + if (xpid < 0) + xpid = -xpid; + pidcheck (pidwait (xpid, NOTOK)); + xpid = 0; + } - if (ct->c_partno) { - snprintf (bp, buflen, " of content %s", ct->c_partno); + /* Get buffer ready to go */ + bp = query; + buflen = sizeof(query); + + /* Now, construct query */ + if (writing) { + snprintf (bp, buflen, "Make cached, publically-accessible copy"); + } else { + struct stat st; + + snprintf (bp, buflen, "Use cached copy"); + len = strlen (bp); + bp += len; + buflen -= len; + + if (ct->c_partno) { + snprintf (bp, buflen, " of content %s", ct->c_partno); + len = strlen (bp); + bp += len; + buflen -= len; + } + + stat (buffer, &st); + snprintf (bp, buflen, " (size %lu octets)", + (unsigned long) st.st_size); + } len = strlen (bp); bp += len; buflen -= len; - } - - stat (buffer, &st); - snprintf (bp, buflen, " (size %lu octets)", - (unsigned long) st.st_size); - } - len = strlen (bp); - bp += len; - buflen -= len; - snprintf (bp, buflen, "\n in file %s? ", buffer); + snprintf (bp, buflen, "\n in file %s? ", buffer); - /* Now, check answer */ - if (!getanswer (query)) - status = NOTOK; - } + /* Now, check answer */ + if (!getanswer (query)) + status = NOTOK; + } - if (status == OK && writing) { - if (*writing && strchr(buffer, '/')) - make_intermediates (buffer); - unlink (buffer); - } + if (status == OK && writing) { + if (*writing && strchr(buffer, '/')) + make_intermediates (buffer); + unlink (buffer); + } - free (id); - return status; + free (id); + return status; } @@ -310,146 +306,146 @@ static int find_cache_aux (int writing, char *directory, char *id, char *buffer, int buflen) { - int mask, usemap; - char mapfile[BUFSIZ], mapname[BUFSIZ]; - FILE *fp; - static int partno, pid; - static time_t clock = 0; + int mask, usemap; + char mapfile[BUFSIZ], mapname[BUFSIZ]; + FILE *fp; + static int partno, pid; + static time_t clock = 0; #ifdef BSD42 - usemap = strchr (id, '/') ? 1 : 0; + usemap = strchr (id, '/') ? 1 : 0; #else - usemap = 1; + usemap = 1; #endif - if (debugsw) - fprintf (stderr, "find_cache_aux %s usemap=%d\n", directory, usemap); + if (debugsw) + fprintf (stderr, "find_cache_aux %s usemap=%d\n", directory, usemap); - snprintf (mapfile, sizeof(mapfile), "%s/cache.map", directory); - if (find_cache_aux2 (mapfile, id, mapname, sizeof(mapname)) == OK) - goto done_map; + snprintf (mapfile, sizeof(mapfile), "%s/cache.map", directory); + if (find_cache_aux2 (mapfile, id, mapname, sizeof(mapname)) == OK) + goto done_map; - if (!writing) { - if (usemap) - return NOTOK; + if (!writing) { + if (usemap) + return NOTOK; use_raw: - snprintf (buffer, buflen, "%s/%s", directory, id); - return OK; - } - - if (!usemap && access (mapfile, W_OK) == NOTOK) - goto use_raw; - - if (clock != 0) { - time_t now; - - time (&now); - if (now > clock) - clock = 0; - } else { - pid = getpid (); - } - - if (clock == 0) { - time (&clock); - partno = 0; - } else { - if (partno > 0xff) { - clock++; - partno = 0; + snprintf (buffer, buflen, "%s/%s", directory, id); + return OK; + } + + if (!usemap && access (mapfile, W_OK) == NOTOK) + goto use_raw; + + if (clock != 0) { + time_t now; + + time (&now); + if (now > clock) + clock = 0; + } else { + pid = getpid (); + } + + if (clock == 0) { + time (&clock); + partno = 0; + } else { + if (partno > 0xff) { + clock++; + partno = 0; + } } - } - snprintf (mapname, sizeof(mapname), "%08x%04x%02x", + snprintf (mapname, sizeof(mapname), "%08x%04x%02x", (unsigned int) (clock & 0xffffffff), (unsigned int) (pid & 0xffff), (unsigned int) (partno++ & 0xff)); - if (debugsw) - fprintf (stderr, "creating mapping %s->%s\n", mapname, id); + if (debugsw) + fprintf (stderr, "creating mapping %s->%s\n", mapname, id); - make_intermediates (mapfile); - mask = umask (writing == 2 ? 0077 : 0); - if (!(fp = lkfopen (mapfile, "a")) && errno == ENOENT) { - int fd; + make_intermediates (mapfile); + mask = umask (writing == 2 ? 0077 : 0); + if (!(fp = lkfopen (mapfile, "a")) && errno == ENOENT) { + int fd; - if ((fd = creat (mapfile, 0666)) != NOTOK) { - close (fd); - fp = lkfopen (mapfile, "a"); + if ((fd = creat (mapfile, 0666)) != NOTOK) { + close (fd); + fp = lkfopen (mapfile, "a"); + } } - } - umask (mask); - if (!fp) - return NOTOK; - fprintf (fp, "%s: %s\n", mapname, id); - lkfclose (fp, mapfile); + umask (mask); + if (!fp) + return NOTOK; + fprintf (fp, "%s: %s\n", mapname, id); + lkfclose (fp, mapfile); done_map: - if (*mapname == '/') - strncpy (buffer, mapname, buflen); - else - snprintf (buffer, buflen, "%s/%s", directory, mapname); - if (debugsw) - fprintf (stderr, "use %s\n", buffer); - - return OK; + if (*mapname == '/') + strncpy (buffer, mapname, buflen); + else + snprintf (buffer, buflen, "%s/%s", directory, mapname); + if (debugsw) + fprintf (stderr, "use %s\n", buffer); + + return OK; } static int find_cache_aux2 (char *mapfile, char *id, char *mapname, int namelen) { - int state; - char buf[BUFSIZ], name[NAMESZ]; - FILE *fp; - - if (!(fp = lkfopen (mapfile, "r"))) - return NOTOK; + int state; + char buf[BUFSIZ], name[NAMESZ]; + FILE *fp; - for (state = FLD;;) { - int result; - char *cp, *dp; - - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - strncpy (mapname, name, namelen); - if (state != FLDPLUS) - cp = buf; - else { - cp = add (buf, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); - cp = add (buf, cp); - } + if (!(fp = lkfopen (mapfile, "r"))) + return NOTOK; + + for (state = FLD;;) { + int result; + char *cp, *dp; + + switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + strncpy (mapname, name, namelen); + if (state != FLDPLUS) + cp = buf; + else { + cp = add (buf, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), fp); + cp = add (buf, cp); + } + } + dp = trimcpy (cp); + if (cp != buf) + free (cp); + if (debugsw) + fprintf (stderr, "compare %s to %s <- %s\n", id, dp, + mapname); + result = strcmp (id, dp); + free (dp); + if (result == 0) { + lkfclose (fp, mapfile); + return OK; + } + if (state != FLDEOF) + continue; + /* else fall... */ + + case BODY: + case BODYEOF: + case FILEEOF: + default: + break; } - dp = trimcpy (cp); - if (cp != buf) - free (cp); - if (debugsw) - fprintf (stderr, "compare %s to %s <- %s\n", id, dp, - mapname); - result = strcmp (id, dp); - free (dp); - if (result == 0) { - lkfclose (fp, mapfile); - return OK; - } - if (state != FLDEOF) - continue; - /* else fall... */ - - case BODY: - case BODYEOF: - case FILEEOF: - default: break; } - break; - } - lkfclose (fp, mapfile); - return NOTOK; + lkfclose (fp, mapfile); + return NOTOK; } diff --git a/uip/mhfree.c b/uip/mhfree.c index 38b830e..b9f15aa 100644 --- a/uip/mhfree.c +++ b/uip/mhfree.c @@ -1,4 +1,3 @@ - /* * mhfree.c -- routines to free the data structures used to * -- represent MIME messages @@ -41,85 +40,85 @@ static void free_external (CT); void free_content (CT ct) { - if (!ct) - return; - - /* - * free all the header fields - */ - free_header (ct); - - if (ct->c_partno) - free (ct->c_partno); - - if (ct->c_vrsn) - free (ct->c_vrsn); - - if (ct->c_ctline) - free (ct->c_ctline); - - free_ctinfo (ct); - - /* - * some of the content types have extra - * parts which need to be freed. - */ - switch (ct->c_type) { - case CT_MULTIPART: - free_multi (ct); - break; - - case CT_MESSAGE: - switch (ct->c_subtype) { - case MESSAGE_PARTIAL: - free_partial (ct); - break; - - case MESSAGE_EXTERNAL: - free_external (ct); - break; - } - break; - - case CT_TEXT: - free_text (ct); - break; - } - - if (ct->c_showproc) - free (ct->c_showproc); - if (ct->c_termproc) - free (ct->c_termproc); - if (ct->c_storeproc) - free (ct->c_storeproc); - - if (ct->c_celine) - free (ct->c_celine); - - /* free structures for content encodings */ - free_encoding (ct, 1); - - if (ct->c_id) - free (ct->c_id); - if (ct->c_descr) - free (ct->c_descr); - if (ct->c_dispo) - free (ct->c_dispo); - - if (ct->c_file) { - if (ct->c_unlink) - unlink (ct->c_file); - free (ct->c_file); - } - if (ct->c_fp) - fclose (ct->c_fp); - - if (ct->c_storage) - free (ct->c_storage); - if (ct->c_folder) - free (ct->c_folder); - - free (ct); + if (!ct) + return; + + /* + * free all the header fields + */ + free_header (ct); + + if (ct->c_partno) + free (ct->c_partno); + + if (ct->c_vrsn) + free (ct->c_vrsn); + + if (ct->c_ctline) + free (ct->c_ctline); + + free_ctinfo (ct); + + /* + * some of the content types have extra + * parts which need to be freed. + */ + switch (ct->c_type) { + case CT_MULTIPART: + free_multi (ct); + break; + + case CT_MESSAGE: + switch (ct->c_subtype) { + case MESSAGE_PARTIAL: + free_partial (ct); + break; + + case MESSAGE_EXTERNAL: + free_external (ct); + break; + } + break; + + case CT_TEXT: + free_text (ct); + break; + } + + if (ct->c_showproc) + free (ct->c_showproc); + if (ct->c_termproc) + free (ct->c_termproc); + if (ct->c_storeproc) + free (ct->c_storeproc); + + if (ct->c_celine) + free (ct->c_celine); + + /* free structures for content encodings */ + free_encoding (ct, 1); + + if (ct->c_id) + free (ct->c_id); + if (ct->c_descr) + free (ct->c_descr); + if (ct->c_dispo) + free (ct->c_dispo); + + if (ct->c_file) { + if (ct->c_unlink) + unlink (ct->c_file); + free (ct->c_file); + } + if (ct->c_fp) + fclose (ct->c_fp); + + if (ct->c_storage) + free (ct->c_storage); + if (ct->c_folder) + free (ct->c_folder); + + free (ct); } @@ -131,123 +130,123 @@ free_content (CT ct) void free_header (CT ct) { - HF hp1, hp2; + HF hp1, hp2; - hp1 = ct->c_first_hf; - while (hp1) { - hp2 = hp1->next; + hp1 = ct->c_first_hf; + while (hp1) { + hp2 = hp1->next; - free (hp1->name); - free (hp1->value); - free (hp1); + free (hp1->name); + free (hp1->value); + free (hp1); - hp1 = hp2; - } + hp1 = hp2; + } - ct->c_first_hf = NULL; - ct->c_last_hf = NULL; + ct->c_first_hf = NULL; + ct->c_last_hf = NULL; } void free_ctinfo (CT ct) { - char **ap; - CI ci; - - ci = &ct->c_ctinfo; - if (ci->ci_type) { - free (ci->ci_type); - ci->ci_type = NULL; - } - if (ci->ci_subtype) { - free (ci->ci_subtype); - ci->ci_subtype = NULL; - } - for (ap = ci->ci_attrs; *ap; ap++) { - free (*ap); - *ap = NULL; - } - if (ci->ci_comment) { - free (ci->ci_comment); - ci->ci_comment = NULL; - } - if (ci->ci_magic) { - free (ci->ci_magic); - ci->ci_magic = NULL; - } + char **ap; + CI ci; + + ci = &ct->c_ctinfo; + if (ci->ci_type) { + free (ci->ci_type); + ci->ci_type = NULL; + } + if (ci->ci_subtype) { + free (ci->ci_subtype); + ci->ci_subtype = NULL; + } + for (ap = ci->ci_attrs; *ap; ap++) { + free (*ap); + *ap = NULL; + } + if (ci->ci_comment) { + free (ci->ci_comment); + ci->ci_comment = NULL; + } + if (ci->ci_magic) { + free (ci->ci_magic); + ci->ci_magic = NULL; + } } static void free_text (CT ct) { - struct text *t; + struct text *t; - if (!(t = (struct text *) ct->c_ctparams)) - return; + if (!(t = (struct text *) ct->c_ctparams)) + return; - free ((char *) t); - ct->c_ctparams = NULL; + free ((char *) t); + ct->c_ctparams = NULL; } static void free_multi (CT ct) { - struct multipart *m; - struct part *part, *next; - - if (!(m = (struct multipart *) ct->c_ctparams)) - return; - - if (m->mp_start) - free (m->mp_start); - if (m->mp_stop) - free (m->mp_stop); - - for (part = m->mp_parts; part; part = next) { - next = part->mp_next; - free_content (part->mp_part); - free ((char *) part); - } - m->mp_parts = NULL; - - free ((char *) m); - ct->c_ctparams = NULL; + struct multipart *m; + struct part *part, *next; + + if (!(m = (struct multipart *) ct->c_ctparams)) + return; + + if (m->mp_start) + free (m->mp_start); + if (m->mp_stop) + free (m->mp_stop); + + for (part = m->mp_parts; part; part = next) { + next = part->mp_next; + free_content (part->mp_part); + free ((char *) part); + } + m->mp_parts = NULL; + + free ((char *) m); + ct->c_ctparams = NULL; } static void free_partial (CT ct) { - struct partial *p; + struct partial *p; - if (!(p = (struct partial *) ct->c_ctparams)) - return; + if (!(p = (struct partial *) ct->c_ctparams)) + return; - if (p->pm_partid) - free (p->pm_partid); + if (p->pm_partid) + free (p->pm_partid); - free ((char *) p); - ct->c_ctparams = NULL; + free ((char *) p); + ct->c_ctparams = NULL; } static void free_external (CT ct) { - struct exbody *e; + struct exbody *e; - if (!(e = (struct exbody *) ct->c_ctparams)) - return; + if (!(e = (struct exbody *) ct->c_ctparams)) + return; - free_content (e->eb_content); - if (e->eb_body) - free (e->eb_body); + free_content (e->eb_content); + if (e->eb_body) + free (e->eb_body); - free ((char *) e); - ct->c_ctparams = NULL; + free ((char *) e); + ct->c_ctparams = NULL; } @@ -259,40 +258,40 @@ free_external (CT ct) void free_encoding (CT ct, int toplevel) { - CE ce; - - if (!(ce = ct->c_cefile)) - return; - - if (ce->ce_fp) { - fclose (ce->ce_fp); - ce->ce_fp = NULL; - } - - if (ce->ce_file) { - if (ce->ce_unlink) - unlink (ce->ce_file); - free (ce->ce_file); - ce->ce_file = NULL; - } - - if (toplevel) { - free ((char *) ce); - ct->c_cefile = NULL; - } else { - ct->c_ceopenfnx = NULL; - } + CE ce; + + if (!(ce = ct->c_cefile)) + return; + + if (ce->ce_fp) { + fclose (ce->ce_fp); + ce->ce_fp = NULL; + } + + if (ce->ce_file) { + if (ce->ce_unlink) + unlink (ce->ce_file); + free (ce->ce_file); + ce->ce_file = NULL; + } + + if (toplevel) { + free ((char *) ce); + ct->c_cefile = NULL; + } else { + ct->c_ceopenfnx = NULL; + } } void freects_done (int status) { - CT *ctp; + CT *ctp; - if ((ctp = cts)) - for (; *ctp; ctp++) - free_content (*ctp); + if ((ctp = cts)) + for (; *ctp; ctp++) + free_content (*ctp); - exit (status); + exit (status); } diff --git a/uip/mhl.c b/uip/mhl.c index fdbd679..7914b5f 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -1,4 +1,3 @@ - /* * mhl.c -- the nmh message listing program * @@ -17,8 +16,8 @@ int main (int argc, char **argv) { #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - done (mhl (argc, argv)); - return 1; + done (mhl (argc, argv)); + return 1; } diff --git a/uip/mhlist.c b/uip/mhlist.c index cb6a3cf..1cd8357 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -1,4 +1,3 @@ - /* * mhlist.c -- list the contents of MIME messages * @@ -25,48 +24,48 @@ #endif static struct swit switches[] = { -#define CHECKSW 0 - { "check", 0 }, -#define NCHECKSW 1 - { "nocheck", 0 }, -#define HEADSW 2 - { "headers", 0 }, -#define NHEADSW 3 - { "noheaders", 0 }, -#define SIZESW 4 - { "realsize", 0 }, -#define NSIZESW 5 - { "norealsize", 0 }, -#define VERBSW 6 - { "verbose", 0 }, -#define NVERBSW 7 - { "noverbose", 0 }, -#define FILESW 8 /* interface from show */ - { "file file", 0 }, -#define PARTSW 9 - { "part number", 0 }, -#define TYPESW 10 - { "type content", 0 }, -#define RCACHESW 11 - { "rcache policy", 0 }, -#define WCACHESW 12 - { "wcache policy", 0 }, -#define VERSIONSW 13 - { "version", 0 }, -#define HELPSW 14 - { "help", 0 }, +#define CHECKSW 0 + { "check", 0 }, +#define NCHECKSW 1 + { "nocheck", 0 }, +#define HEADSW 2 + { "headers", 0 }, +#define NHEADSW 3 + { "noheaders", 0 }, +#define SIZESW 4 + { "realsize", 0 }, +#define NSIZESW 5 + { "norealsize", 0 }, +#define VERBSW 6 + { "verbose", 0 }, +#define NVERBSW 7 + { "noverbose", 0 }, +#define FILESW 8 /* interface from show */ + { "file file", 0 }, +#define PARTSW 9 + { "part number", 0 }, +#define TYPESW 10 + { "type content", 0 }, +#define RCACHESW 11 + { "rcache policy", 0 }, +#define WCACHESW 12 + { "wcache policy", 0 }, +#define VERSIONSW 13 + { "version", 0 }, +#define HELPSW 14 + { "help", 0 }, /* * switches for debugging */ -#define DEBUGSW 15 - { "debug", -5 }, - { NULL, 0 } +#define DEBUGSW 15 + { "debug", -5 }, + { NULL, 0 } }; /* mhparse.c */ -extern char *tmp; /* directory to place temp files */ +extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ extern int rcachesw; @@ -90,7 +89,7 @@ pid_t xpid = 0; int debugsw = 0; int verbosw = 0; -#define quitser pipeser +#define quitser pipeser /* mhparse.c */ CT parse_mime (char *); @@ -118,273 +117,273 @@ static RETSIGTYPE pipeser (int); int main (int argc, char **argv) { - int sizesw = 1, headsw = 1; - int msgnum, *icachesw; - char *cp, *file = NULL, *folder = NULL; - char *maildir, buf[100], **argp; - char **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp = NULL; - CT ct, *ctp; + int sizesw = 1, headsw = 1; + int msgnum, *icachesw; + char *cp, *file = NULL, *folder = NULL; + char *maildir, buf[100], **argp; + char **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp = NULL; + CT ct, *ctp; - done=freects_done; + done=freects_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + invo_name = r1bindex (argv[0], '/'); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; - case RCACHESW: - icachesw = &rcachesw; - goto do_cache; - case WCACHESW: - icachesw = &wcachesw; + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case RCACHESW: + icachesw = &rcachesw; + goto do_cache; + case WCACHESW: + icachesw = &wcachesw; do_cache: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - switch (*icachesw = smatch (cp, caches)) { - case AMBIGSW: - ambigsw (cp, caches); - done (1); - case UNKWNSW: - adios (NULL, "%s unknown", cp); - default: - break; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + switch (*icachesw = smatch (cp, caches)) { + case AMBIGSW: + ambigsw (cp, caches); + done (1); + case UNKWNSW: + adios (NULL, "%s unknown", cp); + default: + break; + } + continue; + + case CHECKSW: + checksw++; + continue; + case NCHECKSW: + checksw = 0; + continue; + + case HEADSW: + headsw = 1; + continue; + case NHEADSW: + headsw = 0; + continue; + + case SIZESW: + sizesw = 1; + continue; + case NSIZESW: + sizesw = 0; + continue; + + case PARTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (npart >= NPARTS) + adios (NULL, "too many parts (starting with %s), %d max", + cp, NPARTS); + parts[npart++] = cp; + continue; + + case TYPESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (ntype >= NTYPES) + adios (NULL, "too many types (starting with %s), %d max", + cp, NTYPES); + types[ntype++] = cp; + continue; + + case FILESW: + if (!(cp = *argp++) || (*cp == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + file = *cp == '-' ? cp : path (cp, TFILE); + continue; + + case VERBSW: + verbosw = 1; + continue; + case NVERBSW: + verbosw = 0; + continue; + case DEBUGSW: + debugsw = 1; + continue; + } } - continue; - - case CHECKSW: - checksw++; - continue; - case NCHECKSW: - checksw = 0; - continue; - - case HEADSW: - headsw = 1; - continue; - case NHEADSW: - headsw = 0; - continue; - - case SIZESW: - sizesw = 1; - continue; - case NSIZESW: - sizesw = 0; - continue; - - case PARTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (npart >= NPARTS) - adios (NULL, "too many parts (starting with %s), %d max", - cp, NPARTS); - parts[npart++] = cp; - continue; - - case TYPESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (ntype >= NTYPES) - adios (NULL, "too many types (starting with %s), %d max", - cp, NTYPES); - types[ntype++] = cp; - continue; - - case FILESW: - if (!(cp = *argp++) || (*cp == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - file = *cp == '-' ? cp : path (cp, TFILE); - continue; - - case VERBSW: - verbosw = 1; - continue; - case NVERBSW: - verbosw = 0; - continue; - case DEBUGSW: - debugsw = 1; - continue; - } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* null terminate the list of acceptable parts/types */ - parts[npart] = NULL; - types[ntype] = NULL; - - set_endian (); - - /* Check for public cache location */ - if ((cache_public = context_find (nmhcache)) && *cache_public != '/') - cache_public = NULL; - - /* Check for private cache location */ - if (!(cache_private = context_find (nmhprivcache))) - cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); - - /* - * Check for storage directory. If specified, - * then store temporary files there. Else we - * store them in standard nmh directory. - */ - if ((cp = context_find (nmhstorage)) && *cp) - tmp = concat (cp, "/", invo_name, NULL); - else - tmp = add (m_maildir (invo_name), NULL); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (file && msgs.size) - adios (NULL, "cannot specify msg and file at same time!"); - - /* - * check if message is coming from file - */ - if (file) { - if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; - - if ((ct = parse_mime (file))); - *ctp++ = ct; - } else { + + /* null terminate the list of acceptable parts/types */ + parts[npart] = NULL; + types[ntype] = NULL; + + set_endian (); + + /* Check for public cache location */ + if ((cache_public = context_find (nmhcache)) && *cache_public != '/') + cache_public = NULL; + + /* Check for private cache location */ + if (!(cache_private = context_find (nmhprivcache))) + cache_private = ".cache"; + cache_private = getcpy (m_maildir (cache_private)); + /* - * message(s) are coming from a folder + * Check for storage directory. If specified, + * then store temporary files there. Else we + * store them in standard nmh directory. */ - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ + if ((cp = context_find (nmhstorage)) && *cp) + tmp = concat (cp, "/", invo_name, NULL); + else + tmp = add (m_maildir (invo_name), NULL); - if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; + if (!context_find ("path")) + free (path ("./", TFOLDER)); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - char *msgnam; + if (file && msgs.size) + adios (NULL, "cannot specify msg and file at same time!"); - msgnam = m_name (msgnum); - if ((ct = parse_mime (msgnam))) - *ctp++ = ct; - } + /* + * check if message is coming from file + */ + if (file) { + if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + if ((ct = parse_mime (file))); + *ctp++ = ct; + } else { + /* + * message(s) are coming from a folder + */ + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + char *msgnam; + + msgnam = m_name (msgnum); + if ((ct = parse_mime (msgnam))) + *ctp++ = ct; + } + } } - } - if (!*cts) - done (1); + if (!*cts) + done (1); + + userrs = 1; + SIGNAL (SIGQUIT, quitser); + SIGNAL (SIGPIPE, pipeser); + + /* + * Get the associated umask for the relevant contents. + */ + for (ctp = cts; *ctp; ctp++) { + struct stat st; + + ct = *ctp; + if (type_ok (ct, 1) && !ct->c_umask) { + if (stat (ct->c_file, &st) != NOTOK) + ct->c_umask = ~(st.st_mode & 0777); + else + ct->c_umask = ~m_gmprot(); + } + } + + /* + * List the message content + */ + list_all_messages (cts, headsw, sizesw, verbosw, debugsw); + + /* Now free all the structures for the content */ + for (ctp = cts; *ctp; ctp++) + free_content (*ctp); + + free ((char *) cts); + cts = NULL; - userrs = 1; - SIGNAL (SIGQUIT, quitser); - SIGNAL (SIGPIPE, pipeser); - - /* - * Get the associated umask for the relevant contents. - */ - for (ctp = cts; *ctp; ctp++) { - struct stat st; - - ct = *ctp; - if (type_ok (ct, 1) && !ct->c_umask) { - if (stat (ct->c_file, &st) != NOTOK) - ct->c_umask = ~(st.st_mode & 0777); - else - ct->c_umask = ~m_gmprot(); + /* If reading from a folder, do some updating */ + if (mp) { + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->hghsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ } - } - - /* - * List the message content - */ - list_all_messages (cts, headsw, sizesw, verbosw, debugsw); - - /* Now free all the structures for the content */ - for (ctp = cts; *ctp; ctp++) - free_content (*ctp); - - free ((char *) cts); - cts = NULL; - - /* If reading from a folder, do some updating */ - if (mp) { - context_replace (pfolder, folder);/* update current folder */ - seq_setcur (mp, mp->hghsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - done (0); - return 1; + + done (0); + return 1; } static RETSIGTYPE pipeser (int i) { - if (i == SIGQUIT) { - unlink ("core"); - fflush (stdout); - fprintf (stderr, "\n"); - fflush (stderr); - } - - done (1); - /* NOTREACHED */ + if (i == SIGQUIT) { + unlink ("core"); + fflush (stdout); + fprintf (stderr, "\n"); + fflush (stderr); + } + + done (1); + /* NOTREACHED */ } diff --git a/uip/mhlistsbr.c b/uip/mhlistsbr.c index 1aac74a..e5fecd6 100644 --- a/uip/mhlistsbr.c +++ b/uip/mhlistsbr.c @@ -1,4 +1,3 @@ - /* * mhlistsbr.c -- routines to list information about the * -- contents of MIME messages @@ -46,15 +45,15 @@ static int list_encoding (CT); /* * various formats for -list option */ -#define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n" -#define LSTFMT2a "%4d " -#define LSTFMT2b "%-5s %-24.24s " -#define LSTFMT2c1 "%5lu" -#define LSTFMT2c2 "%4lu%c" -#define LSTFMT2c3 "huge " -#define LSTFMT2c4 " " -#define LSTFMT2d1 " %-36.36s" -#define LSTFMT2d2 "\t %-65.65s\n" +#define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n" +#define LSTFMT2a "%4d " +#define LSTFMT2b "%-5s %-24.24s " +#define LSTFMT2c1 "%5lu" +#define LSTFMT2c2 "%4lu%c" +#define LSTFMT2c3 "huge " +#define LSTFMT2c4 " " +#define LSTFMT2d1 " %-36.36s" +#define LSTFMT2d2 "\t %-65.65s\n" /* @@ -64,17 +63,17 @@ static int list_encoding (CT); void list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug) { - CT ct, *ctp; + CT ct, *ctp; - if (headers) - printf (LSTFMT1, "msg", "part", "type/subtype", "size", "description"); + if (headers) + printf (LSTFMT1, "msg", "part", "type/subtype", "size", "description"); - for (ctp = cts; *ctp; ctp++) { - ct = *ctp; - list_single_message (ct, realsize, verbose, debug); - } + for (ctp = cts; *ctp; ctp++) { + ct = *ctp; + list_single_message (ct, realsize, verbose, debug); + } - flush_errors (); + flush_errors (); } @@ -85,16 +84,16 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug) static void list_single_message (CT ct, int realsize, int verbose, int debug) { - if (type_ok (ct, 1)) { - umask (ct->c_umask); - list_switch (ct, 1, realsize, verbose, debug); - if (ct->c_fp) { - fclose (ct->c_fp); - ct->c_fp = NULL; + if (type_ok (ct, 1)) { + umask (ct->c_umask); + list_switch (ct, 1, realsize, verbose, debug); + if (ct->c_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } + if (ct->c_ceclosefnx) + (*ct->c_ceclosefnx) (ct); } - if (ct->c_ceclosefnx) - (*ct->c_ceclosefnx) (ct); - } } @@ -105,46 +104,46 @@ list_single_message (CT ct, int realsize, int verbose, int debug) int list_switch (CT ct, int toplevel, int realsize, int verbose, int debug) { - switch (ct->c_type) { - case CT_MULTIPART: - return list_multi (ct, toplevel, realsize, verbose, debug); - break; - - case CT_MESSAGE: - switch (ct->c_subtype) { - case MESSAGE_PARTIAL: - return list_partial (ct, toplevel, realsize, verbose, debug); - break; - - case MESSAGE_EXTERNAL: - return list_external (ct, toplevel, realsize, verbose, debug); - break; - - case MESSAGE_RFC822: + switch (ct->c_type) { + case CT_MULTIPART: + return list_multi (ct, toplevel, realsize, verbose, debug); + break; + + case CT_MESSAGE: + switch (ct->c_subtype) { + case MESSAGE_PARTIAL: + return list_partial (ct, toplevel, realsize, verbose, debug); + break; + + case MESSAGE_EXTERNAL: + return list_external (ct, toplevel, realsize, verbose, debug); + break; + + case MESSAGE_RFC822: + default: + return list_content (ct, toplevel, realsize, verbose, debug); + break; + } + break; + + case CT_TEXT: + case CT_AUDIO: + case CT_IMAGE: + case CT_VIDEO: + return list_content (ct, toplevel, realsize, verbose, debug); + break; + + case CT_APPLICATION: + return list_application (ct, toplevel, realsize, verbose, debug); + break; + default: - return list_content (ct, toplevel, realsize, verbose, debug); - break; - } - break; - - case CT_TEXT: - case CT_AUDIO: - case CT_IMAGE: - case CT_VIDEO: - return list_content (ct, toplevel, realsize, verbose, debug); - break; - - case CT_APPLICATION: - return list_application (ct, toplevel, realsize, verbose, debug); - break; - - default: - /* list_debug (ct); */ - adios (NULL, "unknown content type %d", ct->c_type); - break; - } - - return 0; /* NOT REACHED */ + /* list_debug (ct); */ + adios (NULL, "unknown content type %d", ct->c_type); + break; + } + + return 0; /* NOT REACHED */ } @@ -157,73 +156,73 @@ list_switch (CT ct, int toplevel, int realsize, int verbose, int debug) int list_content (CT ct, int toplevel, int realsize, int verbose, int debug) { - unsigned long size; - char *cp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + unsigned long size; + char *cp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - printf (toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ", - atoi (r1bindex (empty (ct->c_file), '/'))); - snprintf (buffer, sizeof(buffer), "%s/%s", empty (ci->ci_type), + printf (toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ", + atoi (r1bindex (empty (ct->c_file), '/'))); + snprintf (buffer, sizeof(buffer), "%s/%s", empty (ci->ci_type), empty (ci->ci_subtype)); - printf (LSTFMT2b, empty (ct->c_partno), buffer); - - if (ct->c_cesizefnx && realsize) - size = (*ct->c_cesizefnx) (ct); - else - size = ct->c_end - ct->c_begin; - - /* find correct scale for size (Kilo/Mega/Giga/Tera) */ - for (cp = " KMGT"; size > 9999; size >>= 10) - if (!*++cp) - break; - - /* print size of this body part */ - switch (*cp) { - case ' ': - if (size > 0 || ct->c_encoding != CE_EXTERNAL) - printf (LSTFMT2c1, size); - else - printf (LSTFMT2c4); - break; - - default: - printf (LSTFMT2c2, size, *cp); - break; - - case '\0': - printf (LSTFMT2c3); - } - - /* print Content-Description */ - if (ct->c_descr) { - char *dp; - - dp = trimcpy (cp = add (ct->c_descr, NULL)); - free (cp); - printf (LSTFMT2d1, dp); - free (dp); - } - - printf ("\n"); - - /* - * If verbose, print any RFC-822 comments in the - * Content-Type line. - */ - if (verbose && ci->ci_comment) { - char *dp; - - dp = trimcpy (cp = add (ci->ci_comment, NULL)); - free (cp); - snprintf (buffer, sizeof(buffer), "(%s)", dp); - free (dp); - printf (LSTFMT2d2, buffer); - } - - if (debug) - list_debug (ct); - - return OK; + printf (LSTFMT2b, empty (ct->c_partno), buffer); + + if (ct->c_cesizefnx && realsize) + size = (*ct->c_cesizefnx) (ct); + else + size = ct->c_end - ct->c_begin; + + /* find correct scale for size (Kilo/Mega/Giga/Tera) */ + for (cp = " KMGT"; size > 9999; size >>= 10) + if (!*++cp) + break; + + /* print size of this body part */ + switch (*cp) { + case ' ': + if (size > 0 || ct->c_encoding != CE_EXTERNAL) + printf (LSTFMT2c1, size); + else + printf (LSTFMT2c4); + break; + + default: + printf (LSTFMT2c2, size, *cp); + break; + + case '\0': + printf (LSTFMT2c3); + } + + /* print Content-Description */ + if (ct->c_descr) { + char *dp; + + dp = trimcpy (cp = add (ct->c_descr, NULL)); + free (cp); + printf (LSTFMT2d1, dp); + free (dp); + } + + printf ("\n"); + + /* + * If verbose, print any RFC-822 comments in the + * Content-Type line. + */ + if (verbose && ci->ci_comment) { + char *dp; + + dp = trimcpy (cp = add (ci->ci_comment, NULL)); + free (cp); + snprintf (buffer, sizeof(buffer), "(%s)", dp); + free (dp); + printf (LSTFMT2d2, buffer); + } + + if (debug) + list_debug (ct); + + return OK; } @@ -234,64 +233,64 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug) static int list_debug (CT ct) { - char **ap, **ep; - CI ci = &ct->c_ctinfo; + char **ap, **ep; + CI ci = &ct->c_ctinfo; - fflush (stdout); - fprintf (stderr, " partno \"%s\"\n", empty (ct->c_partno)); + fflush (stdout); + fprintf (stderr, " partno \"%s\"\n", empty (ct->c_partno)); - /* print MIME-Version line */ - if (ct->c_vrsn) - fprintf (stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn); + /* print MIME-Version line */ + if (ct->c_vrsn) + fprintf (stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn); - /* print Content-Type line */ - if (ct->c_ctline) - fprintf (stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline); + /* print Content-Type line */ + if (ct->c_ctline) + fprintf (stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline); - /* print parsed elements of content type */ - fprintf (stderr, " type \"%s\"\n", empty (ci->ci_type)); - fprintf (stderr, " subtype \"%s\"\n", empty (ci->ci_subtype)); - fprintf (stderr, " comment \"%s\"\n", empty (ci->ci_comment)); - fprintf (stderr, " magic \"%s\"\n", empty (ci->ci_magic)); + /* print parsed elements of content type */ + fprintf (stderr, " type \"%s\"\n", empty (ci->ci_type)); + fprintf (stderr, " subtype \"%s\"\n", empty (ci->ci_subtype)); + fprintf (stderr, " comment \"%s\"\n", empty (ci->ci_comment)); + fprintf (stderr, " magic \"%s\"\n", empty (ci->ci_magic)); - /* print parsed parameters attached to content type */ - fprintf (stderr, " parameters\n"); - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) - fprintf (stderr, " %s=\"%s\"\n", *ap, *ep); + /* print parsed parameters attached to content type */ + fprintf (stderr, " parameters\n"); + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) + fprintf (stderr, " %s=\"%s\"\n", *ap, *ep); - /* print internal flags for type/subtype */ - fprintf (stderr, " type 0x%x subtype 0x%x params 0x%x\n", - ct->c_type, ct->c_subtype, - (unsigned int)(unsigned long) ct->c_ctparams); + /* print internal flags for type/subtype */ + fprintf (stderr, " type 0x%x subtype 0x%x params 0x%x\n", + ct->c_type, ct->c_subtype, + (unsigned int)(unsigned long) ct->c_ctparams); - fprintf (stderr, " showproc \"%s\"\n", empty (ct->c_showproc)); - fprintf (stderr, " termproc \"%s\"\n", empty (ct->c_termproc)); - fprintf (stderr, " storeproc \"%s\"\n", empty (ct->c_storeproc)); + fprintf (stderr, " showproc \"%s\"\n", empty (ct->c_showproc)); + fprintf (stderr, " termproc \"%s\"\n", empty (ct->c_termproc)); + fprintf (stderr, " storeproc \"%s\"\n", empty (ct->c_storeproc)); - /* print transfer encoding information */ - if (ct->c_celine) - fprintf (stderr, " %s:%s", ENCODING_FIELD, ct->c_celine); + /* print transfer encoding information */ + if (ct->c_celine) + fprintf (stderr, " %s:%s", ENCODING_FIELD, ct->c_celine); - /* print internal flags for transfer encoding */ - fprintf (stderr, " transfer encoding 0x%x params 0x%x\n", - ct->c_encoding, (unsigned int)(unsigned long) ct->c_cefile); + /* print internal flags for transfer encoding */ + fprintf (stderr, " transfer encoding 0x%x params 0x%x\n", + ct->c_encoding, (unsigned int)(unsigned long) ct->c_cefile); - /* print Content-ID */ - if (ct->c_id) - fprintf (stderr, " %s:%s", ID_FIELD, ct->c_id); + /* print Content-ID */ + if (ct->c_id) + fprintf (stderr, " %s:%s", ID_FIELD, ct->c_id); - /* print Content-Description */ - if (ct->c_descr) - fprintf (stderr, " %s:%s", DESCR_FIELD, ct->c_descr); + /* print Content-Description */ + if (ct->c_descr) + fprintf (stderr, " %s:%s", DESCR_FIELD, ct->c_descr); - fprintf (stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n", - (unsigned int)(unsigned long) ct->c_fp, empty (ct->c_file), - ct->c_begin, ct->c_end); + fprintf (stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n", + (unsigned int)(unsigned long) ct->c_fp, empty (ct->c_file), + ct->c_begin, ct->c_end); - /* print more information about transfer encoding */ - list_encoding (ct); + /* print more information about transfer encoding */ + list_encoding (ct); - return OK; + return OK; } #undef empty @@ -304,21 +303,21 @@ list_debug (CT ct) static int list_multi (CT ct, int toplevel, int realsize, int verbose, int debug) { - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; - /* list the content for toplevel of this multipart */ - list_content (ct, toplevel, realsize, verbose, debug); + /* list the content for toplevel of this multipart */ + list_content (ct, toplevel, realsize, verbose, debug); - /* now list for all the subparts */ - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; + /* now list for all the subparts */ + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; - if (part_ok (p, 1) && type_ok (p, 1)) - list_switch (p, 0, realsize, verbose, debug); - } + if (part_ok (p, 1) && type_ok (p, 1)) + list_switch (p, 0, realsize, verbose, debug); + } - return OK; + return OK; } @@ -329,17 +328,17 @@ list_multi (CT ct, int toplevel, int realsize, int verbose, int debug) static int list_partial (CT ct, int toplevel, int realsize, int verbose, int debug) { - struct partial *p = (struct partial *) ct->c_ctparams; - - list_content (ct, toplevel, realsize, verbose, debug); - if (verbose) { - printf ("\t [message %s, part %d", p->pm_partid, p->pm_partno); - if (p->pm_maxno) - printf (" of %d", p->pm_maxno); - printf ("]\n"); - } + struct partial *p = (struct partial *) ct->c_ctparams; + + list_content (ct, toplevel, realsize, verbose, debug); + if (verbose) { + printf ("\t [message %s, part %d", p->pm_partid, p->pm_partno); + if (p->pm_maxno) + printf (" of %d", p->pm_maxno); + printf ("]\n"); + } - return OK; + return OK; } @@ -350,45 +349,45 @@ list_partial (CT ct, int toplevel, int realsize, int verbose, int debug) static int list_external (CT ct, int toplevel, int realsize, int verbose, int debug) { - struct exbody *e = (struct exbody *) ct->c_ctparams; - - /* - * First list the information for the - * message/external content itself. - */ - list_content (ct, toplevel, realsize, verbose, debug); - - if (verbose) { - if (e->eb_name) - printf ("\t name=\"%s\"\n", e->eb_name); - if (e->eb_dir) - printf ("\t directory=\"%s\"\n", e->eb_dir); - if (e->eb_site) - printf ("\t site=\"%s\"\n", e->eb_site); - if (e->eb_server) - printf ("\t server=\"%s\"\n", e->eb_server); - if (e->eb_subject) - printf ("\t subject=\"%s\"\n", e->eb_subject); - - /* This must be defined */ - printf ("\t access-type=\"%s\"\n", e->eb_access); - - if (e->eb_mode) - printf ("\t mode=\"%s\"\n", e->eb_mode); - if (e->eb_permission) - printf ("\t permission=\"%s\"\n", e->eb_permission); - - if (e->eb_flags == NOTOK) - printf ("\t [service unavailable]\n"); - } - - /* - * Now list the information for the external content - * to which this content points. - */ - list_content (e->eb_content, 0, realsize, verbose, debug); - - return OK; + struct exbody *e = (struct exbody *) ct->c_ctparams; + + /* + * First list the information for the + * message/external content itself. + */ + list_content (ct, toplevel, realsize, verbose, debug); + + if (verbose) { + if (e->eb_name) + printf ("\t name=\"%s\"\n", e->eb_name); + if (e->eb_dir) + printf ("\t directory=\"%s\"\n", e->eb_dir); + if (e->eb_site) + printf ("\t site=\"%s\"\n", e->eb_site); + if (e->eb_server) + printf ("\t server=\"%s\"\n", e->eb_server); + if (e->eb_subject) + printf ("\t subject=\"%s\"\n", e->eb_subject); + + /* This must be defined */ + printf("\t access-type=\"%s\"\n", e->eb_access); + + if (e->eb_mode) + printf ("\t mode=\"%s\"\n", e->eb_mode); + if (e->eb_permission) + printf ("\t permission=\"%s\"\n", e->eb_permission); + + if (e->eb_flags == NOTOK) + printf ("\t [service unavailable]\n"); + } + + /* + * Now list the information for the external content + * to which this content points. + */ + list_content (e->eb_content, 0, realsize, verbose, debug); + + return OK; } @@ -399,16 +398,16 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug) static int list_application (CT ct, int toplevel, int realsize, int verbose, int debug) { - list_content (ct, toplevel, realsize, verbose, debug); - if (verbose) { - char **ap, **ep; - CI ci = &ct->c_ctinfo; + list_content (ct, toplevel, realsize, verbose, debug); + if (verbose) { + char **ap, **ep; + CI ci = &ct->c_ctinfo; - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) - printf ("\t %s=\"%s\"\n", *ap, *ep); - } + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) + printf ("\t %s=\"%s\"\n", *ap, *ep); + } - return OK; + return OK; } @@ -420,12 +419,12 @@ list_application (CT ct, int toplevel, int realsize, int verbose, int debug) static int list_encoding (CT ct) { - CE ce; + CE ce; - if ((ce = ct->c_cefile)) - fprintf (stderr, " decoded fp 0x%x file \"%s\"\n", - (unsigned int)(unsigned long) ce->ce_fp, - ce->ce_file ? ce->ce_file : ""); + if ((ce = ct->c_cefile)) + fprintf (stderr, " decoded fp 0x%x file \"%s\"\n", + (unsigned int)(unsigned long) ce->ce_fp, + ce->ce_file ? ce->ce_file : ""); - return OK; + return OK; } diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 58b2978..e7f34c2 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1,4 +1,3 @@ - /* * mhlsbr.c -- main routines for nmh message lister * @@ -37,95 +36,95 @@ #define ONECOMP 0 #define TWOCOMP 1 -#define BODYCOMP 2 +#define BODYCOMP 2 -#define QUOTE '\\' +#define QUOTE '\\' static struct swit mhlswitches[] = { -#define BELLSW 0 - { "bell", 0 }, -#define NBELLSW 1 - { "nobell", 0 }, -#define CLRSW 2 - { "clear", 0 }, -#define NCLRSW 3 - { "noclear", 0 }, -#define FACESW 4 - { "faceproc program", 0 }, -#define NFACESW 5 - { "nofaceproc", 0 }, -#define FOLDSW 6 - { "folder +folder", 0 }, -#define FORMSW 7 - { "form formfile", 0 }, -#define PROGSW 8 - { "moreproc program", 0 }, -#define NPROGSW 9 - { "nomoreproc", 0 }, -#define LENSW 10 - { "length lines", 0 }, -#define WIDTHSW 11 - { "width columns", 0 }, -#define SLEEPSW 12 - { "sleep seconds", 0 }, -#define BITSTUFFSW 13 - { "dashstuffing", -12 }, /* interface from forw */ -#define NBITSTUFFSW 14 - { "nodashstuffing", -14 }, /* interface from forw */ -#define VERSIONSW 15 - { "version", 0 }, -#define HELPSW 16 - { "help", 0 }, -#define FORW1SW 17 - { "forward", -7 }, /* interface from forw */ -#define FORW2SW 18 - { "forwall", -7 }, /* interface from forw */ -#define DGSTSW 19 - { "digest list", -6 }, -#define VOLUMSW 20 - { "volume number", -6 }, -#define ISSUESW 21 - { "issue number", -5 }, -#define NBODYSW 22 - { "nobody", -6 }, - { NULL, 0 } +#define BELLSW 0 + { "bell", 0 }, +#define NBELLSW 1 + { "nobell", 0 }, +#define CLRSW 2 + { "clear", 0 }, +#define NCLRSW 3 + { "noclear", 0 }, +#define FACESW 4 + { "faceproc program", 0 }, +#define NFACESW 5 + { "nofaceproc", 0 }, +#define FOLDSW 6 + { "folder +folder", 0 }, +#define FORMSW 7 + { "form formfile", 0 }, +#define PROGSW 8 + { "moreproc program", 0 }, +#define NPROGSW 9 + { "nomoreproc", 0 }, +#define LENSW 10 + { "length lines", 0 }, +#define WIDTHSW 11 + { "width columns", 0 }, +#define SLEEPSW 12 + { "sleep seconds", 0 }, +#define BITSTUFFSW 13 + { "dashstuffing", -12 }, /* interface from forw */ +#define NBITSTUFFSW 14 + { "nodashstuffing", -14 }, /* interface from forw */ +#define VERSIONSW 15 + { "version", 0 }, +#define HELPSW 16 + { "help", 0 }, +#define FORW1SW 17 + { "forward", -7 }, /* interface from forw */ +#define FORW2SW 18 + { "forwall", -7 }, /* interface from forw */ +#define DGSTSW 19 + { "digest list", -6 }, +#define VOLUMSW 20 + { "volume number", -6 }, +#define ISSUESW 21 + { "issue number", -5 }, +#define NBODYSW 22 + { "nobody", -6 }, + { NULL, 0 } }; -#define NOCOMPONENT 0x000001 /* don't show component name */ -#define UPPERCASE 0x000002 /* display in all upper case */ -#define CENTER 0x000004 /* center line */ -#define CLEARTEXT 0x000008 /* cleartext */ -#define EXTRA 0x000010 /* an "extra" component */ -#define HDROUTPUT 0x000020 /* already output */ -#define CLEARSCR 0x000040 /* clear screen */ -#define LEFTADJUST 0x000080 /* left justify multiple lines */ -#define COMPRESS 0x000100 /* compress text */ -#define ADDRFMT 0x000200 /* contains addresses */ -#define BELL 0x000400 /* sound bell at EOP */ -#define DATEFMT 0x000800 /* contains dates */ -#define FORMAT 0x001000 /* parse address/date/RFC-2047 field */ -#define INIT 0x002000 /* initialize component */ -#define FACEFMT 0x004000 /* contains face */ -#define FACEDFLT 0x008000 /* default for face */ -#define SPLIT 0x010000 /* split headers (don't concatenate) */ -#define NONEWLINE 0x020000 /* don't write trailing newline */ -#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017FACEFMT\020FACEDFLT\021SPLIT\022NONEWLINE" -#define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT) +#define NOCOMPONENT 0x000001 /* don't show component name */ +#define UPPERCASE 0x000002 /* display in all upper case */ +#define CENTER 0x000004 /* center line */ +#define CLEARTEXT 0x000008 /* cleartext */ +#define EXTRA 0x000010 /* an "extra" component */ +#define HDROUTPUT 0x000020 /* already output */ +#define CLEARSCR 0x000040 /* clear screen */ +#define LEFTADJUST 0x000080 /* left justify multiple lines */ +#define COMPRESS 0x000100 /* compress text */ +#define ADDRFMT 0x000200 /* contains addresses */ +#define BELL 0x000400 /* sound bell at EOP */ +#define DATEFMT 0x000800 /* contains dates */ +#define FORMAT 0x001000 /* parse address/date/RFC-2047 field */ +#define INIT 0x002000 /* initialize component */ +#define FACEFMT 0x004000 /* contains face */ +#define FACEDFLT 0x008000 /* default for face */ +#define SPLIT 0x010000 /* split headers (don't concatenate) */ +#define NONEWLINE 0x020000 /* don't write trailing newline */ +#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017FACEFMT\020FACEDFLT\021SPLIT\022NONEWLINE" +#define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT) struct mcomp { - char *c_name; /* component name */ - char *c_text; /* component text */ - char *c_ovtxt; /* text overflow indicator */ - char *c_nfs; /* iff FORMAT */ - struct format *c_fmt; /* .. */ - char *c_face; /* face designator */ - int c_offset; /* left margin indentation */ - int c_ovoff; /* overflow indentation */ - int c_width; /* width of field */ - int c_cwidth; /* width of component */ - int c_length; /* length in lines */ - long c_flags; - struct mcomp *c_next; + char *c_name; /* component name */ + char *c_text; /* component text */ + char *c_ovtxt; /* text overflow indicator */ + char *c_nfs; /* iff FORMAT */ + struct format *c_fmt; /* .. */ + char *c_face; /* face designator */ + int c_offset; /* left margin indentation */ + int c_ovoff; /* overflow indentation */ + int c_width; /* width of field */ + int c_cwidth; /* width of component */ + int c_length; /* length in lines */ + long c_flags; + struct mcomp *c_next; }; static struct mcomp *msghd = NULL; @@ -134,65 +133,65 @@ static struct mcomp *fmthd = NULL; static struct mcomp *fmttl = NULL; static struct mcomp global = { - NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 40, BELL, 0 + NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 40, BELL, 0 }; static struct mcomp holder = { - NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NOCOMPONENT, 0 + NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NOCOMPONENT, 0 }; struct pair { - char *p_name; - long p_flags; + char *p_name; + long p_flags; }; static struct pair pairs[] = { - { "Date", DATEFMT }, - { "From", ADDRFMT|FACEDFLT }, - { "Sender", ADDRFMT }, - { "Reply-To", ADDRFMT }, - { "To", ADDRFMT }, - { "cc", ADDRFMT }, - { "Bcc", ADDRFMT }, - { "Resent-Date", DATEFMT }, - { "Resent-From", ADDRFMT }, - { "Resent-Sender", ADDRFMT }, - { "Resent-Reply-To", ADDRFMT }, - { "Resent-To", ADDRFMT }, - { "Resent-cc", ADDRFMT }, - { "Resent-Bcc", ADDRFMT }, - { "Face", FACEFMT }, - { NULL, 0 } + { "Date", DATEFMT }, + { "From", ADDRFMT|FACEDFLT }, + { "Sender", ADDRFMT }, + { "Reply-To", ADDRFMT }, + { "To", ADDRFMT }, + { "cc", ADDRFMT }, + { "Bcc", ADDRFMT }, + { "Resent-Date", DATEFMT }, + { "Resent-From", ADDRFMT }, + { "Resent-Sender", ADDRFMT }, + { "Resent-Reply-To", ADDRFMT }, + { "Resent-To", ADDRFMT }, + { "Resent-cc", ADDRFMT }, + { "Resent-Bcc", ADDRFMT }, + { "Face", FACEFMT }, + { NULL, 0 } }; struct triple { - char *t_name; - long t_on; - long t_off; + char *t_name; + long t_on; + long t_off; }; static struct triple triples[] = { - { "nocomponent", NOCOMPONENT, 0 }, - { "uppercase", UPPERCASE, 0 }, - { "nouppercase", 0, UPPERCASE }, - { "center", CENTER, 0 }, - { "nocenter", 0, CENTER }, - { "clearscreen", CLEARSCR, 0 }, - { "noclearscreen", 0, CLEARSCR }, - { "noclear", 0, CLEARSCR }, - { "leftadjust", LEFTADJUST, 0 }, - { "noleftadjust", 0, LEFTADJUST }, - { "compress", COMPRESS, 0 }, - { "nocompress", 0, COMPRESS }, - { "split", SPLIT, 0 }, - { "nosplit", 0, SPLIT }, - { "addrfield", ADDRFMT, DATEFMT }, - { "bell", BELL, 0 }, - { "nobell", 0, BELL }, - { "datefield", DATEFMT, ADDRFMT }, - { "newline", 0, NONEWLINE }, - { "nonewline", NONEWLINE, 0 }, - { NULL, 0, 0 } + { "nocomponent", NOCOMPONENT, 0 }, + { "uppercase", UPPERCASE, 0 }, + { "nouppercase", 0, UPPERCASE }, + { "center", CENTER, 0 }, + { "nocenter", 0, CENTER }, + { "clearscreen", CLEARSCR, 0 }, + { "noclearscreen", 0, CLEARSCR }, + { "noclear", 0, CLEARSCR }, + { "leftadjust", LEFTADJUST, 0 }, + { "noleftadjust", 0, LEFTADJUST }, + { "compress", COMPRESS, 0 }, + { "nocompress", 0, COMPRESS }, + { "split", SPLIT, 0 }, + { "nosplit", 0, SPLIT }, + { "addrfield", ADDRFMT, DATEFMT }, + { "bell", BELL, 0 }, + { "nobell", 0, BELL }, + { "datefield", DATEFMT, ADDRFMT }, + { "newline", 0, NONEWLINE }, + { "nonewline", NONEWLINE, 0 }, + { NULL, 0, 0 } }; @@ -212,9 +211,9 @@ static int issue = 0; static int exitstat = 0; static int mhldebug = 0; -#define PITTY (-1) -#define NOTTY 0 -#define ISTTY 1 +#define PITTY (-1) +#define NOTTY 0 +#define ISTTY 1 static int ontty = NOTTY; static int row; @@ -238,8 +237,8 @@ static char *ignores[MAXARGS]; static jmp_buf env; static jmp_buf mhlenv; -static char delim3[] = /* from forw.c */ - "\n----------------------------------------------------------------------\n\n"; +static char delim3[] = /* from forw.c */ + "\n----------------------------------------------------------------------\n\n"; static char delim4[] = "\n------------------------------\n\n"; static FILE *(*mhl_action) () = (FILE *(*) ()) 0; @@ -249,8 +248,8 @@ static FILE *(*mhl_action) () = (FILE *(*) ()) 0; * Redefine a couple of functions. * These are undefined later in the code. */ -#define adios mhladios -#define done mhldone +#define adios mhladios +#define done mhldone /* * prototypes @@ -284,1163 +283,1158 @@ int mhl (int, char **); int mhlsbr (int, char **, FILE *(*)()); void m_pclose (void); -void clear_screen (void); /* from termsbr.c */ -int SOprintf (char *, ...); /* from termsbr.c */ -int sc_width (void); /* from termsbr.c */ -int sc_length (void); /* from termsbr.c */ -int sc_hardcopy (void); /* from termsbr.c */ +void clear_screen (void); /* from termsbr.c */ +int SOprintf (char *, ...); /* from termsbr.c */ +int sc_width (void); /* from termsbr.c */ +int sc_length (void); /* from termsbr.c */ +int sc_hardcopy (void); /* from termsbr.c */ int mhl (int argc, char **argv) { - int length = 0, nomore = 0; - int i, width = 0, vecp = 0; - char *cp, *folder = NULL, *form = NULL; - char buf[BUFSIZ], *files[MAXARGS]; - char **argp, **arguments; - - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - if ((cp = getenv ("MHLDEBUG")) && *cp) - mhldebug++; - - if ((cp = getenv ("FACEPROC"))) - faceproc = cp; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, mhlswitches)) { - case AMBIGSW: - ambigsw (cp, mhlswitches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] [files ...]", invo_name); - print_help (buf, mhlswitches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case BELLSW: - bellflg = 1; - continue; - case NBELLSW: - bellflg = -1; - continue; - - case CLRSW: - clearflg = 1; - continue; - case NCLRSW: - clearflg = -1; - continue; - - case FOLDSW: - if (!(folder = *argp++) || *folder == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case FACESW: - if (!(faceproc = *argp++) || *faceproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NFACESW: - faceproc = NULL; - continue; - case SLEEPSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - sleepsw = atoi (cp);/* ZERO ok! */ - continue; - - case PROGSW: - if (!(moreproc = *argp++) || *moreproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NPROGSW: - nomore++; - continue; - - case LENSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((length = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((width = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - - case DGSTSW: - if (!(digest = *argp++) || *digest == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case ISSUESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((issue = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - case VOLUMSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((volume = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - - case FORW2SW: - forwall++; /* fall */ - case FORW1SW: - forwflg++; - clearflg = -1;/* XXX */ - continue; - - case BITSTUFFSW: - dashstuff = 1; /* trinary logic */ - continue; - case NBITSTUFFSW: - dashstuff = -1; /* trinary logic */ - continue; - - case NBODYSW: - dobody = 0; - continue; - } + int length = 0, nomore = 0; + int i, width = 0, vecp = 0; + char *cp, *folder = NULL, *form = NULL; + char buf[BUFSIZ], *files[MAXARGS]; + char **argp, **arguments; + + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + if ((cp = getenv ("MHLDEBUG")) && *cp) + mhldebug++; + + if ((cp = getenv ("FACEPROC"))) + faceproc = cp; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, mhlswitches)) { + case AMBIGSW: + ambigsw (cp, mhlswitches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] [files ...]", invo_name); + print_help (buf, mhlswitches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case BELLSW: + bellflg = 1; + continue; + case NBELLSW: + bellflg = -1; + continue; + + case CLRSW: + clearflg = 1; + continue; + case NCLRSW: + clearflg = -1; + continue; + + case FOLDSW: + if (!(folder = *argp++) || *folder == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case FACESW: + if (!(faceproc = *argp++) || *faceproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NFACESW: + faceproc = NULL; + continue; + case SLEEPSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + sleepsw = atoi (cp);/* ZERO ok! */ + continue; + + case PROGSW: + if (!(moreproc = *argp++) || *moreproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NPROGSW: + nomore++; + continue; + + case LENSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((length = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((width = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + + case DGSTSW: + if (!(digest = *argp++) || *digest == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case ISSUESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((issue = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + case VOLUMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((volume = atoi (cp)) < 1) + adios (NULL, "bad argument %s %s", argp[-2], cp); + continue; + + case FORW2SW: + forwall++; /* fall */ + case FORW1SW: + forwflg++; + clearflg = -1;/* XXX */ + continue; + + case BITSTUFFSW: + dashstuff = 1; /* trinary logic */ + continue; + case NBITSTUFFSW: + dashstuff = -1; /* trinary logic */ + continue; + + case NBODYSW: + dobody = 0; + continue; + } + } + files[vecp++] = cp; } - files[vecp++] = cp; - } - - if (!folder) - folder = getenv ("mhfolder"); - - if (isatty (fileno (stdout))) { - if (!nomore && !sc_hardcopy() && moreproc && *moreproc != '\0') { - if (mhl_action) { - SIGNAL (SIGINT, SIG_IGN); - SIGNAL2 (SIGQUIT, quitser); - } - SIGNAL2 (SIGPIPE, pipeser); - m_popen (moreproc); - ontty = PITTY; + + if (!folder) + folder = getenv ("mhfolder"); + + if (isatty (fileno (stdout))) { + if (!nomore && !sc_hardcopy() && moreproc && *moreproc != '\0') { + if (mhl_action) { + SIGNAL (SIGINT, SIG_IGN); + SIGNAL2 (SIGQUIT, quitser); + } + SIGNAL2 (SIGPIPE, pipeser); + m_popen (moreproc); + ontty = PITTY; + } else { + SIGNAL (SIGINT, SIG_IGN); + SIGNAL2 (SIGQUIT, quitser); + ontty = ISTTY; + } } else { - SIGNAL (SIGINT, SIG_IGN); - SIGNAL2 (SIGQUIT, quitser); - ontty = ISTTY; + ontty = NOTTY; } - } else { - ontty = NOTTY; - } - - mhl_format (form ? form : mhlformat, length, width); - - if (vecp == 0) { - process (folder, NULL, 1, vecp = 1); - } else { - for (i = 0; i < vecp; i++) - process (folder, files[i], i + 1, vecp); - } - - if (forwall) { - if (digest) { - printf ("%s", delim4); - if (volume == 0) { - snprintf (buf, sizeof(buf), "End of %s Digest\n", digest); - } else { - snprintf (buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", - digest, volume, issue); - } - i = strlen (buf); - for (cp = buf + i; i > 1; i--) - *cp++ = '*'; - *cp++ = '\n'; - *cp = 0; - printf ("%s", buf); + + mhl_format (form ? form : mhlformat, length, width); + + if (vecp == 0) { + process (folder, NULL, 1, vecp = 1); + } else { + for (i = 0; i < vecp; i++) + process (folder, files[i], i + 1, vecp); } - else - printf ("\n------- End of Forwarded Message%s\n\n", - vecp > 1 ? "s" : ""); - } - - fflush(stdout); - if(ferror(stdout)){ - adios("output", "error writing"); - } - - if (clearflg > 0 && ontty == NOTTY) - clear_screen (); - - if (ontty == PITTY) - m_pclose (); - - return exitstat; + + if (forwall) { + if (digest) { + printf ("%s", delim4); + if (volume == 0) { + snprintf (buf, sizeof(buf), + "End of %s Digest\n", digest); + } else { + snprintf (buf, sizeof(buf), + "End of %s Digest [Volume %d Issue %d]\n", + digest, volume, issue); + } + i = strlen (buf); + for (cp = buf + i; i > 1; i--) + *cp++ = '*'; + *cp++ = '\n'; + *cp = 0; + printf ("%s", buf); + } else + printf ("\n------- End of Forwarded Message%s\n\n", + vecp > 1 ? "s" : ""); + } + + fflush(stdout); + if (ferror(stdout)) { + adios("output", "error writing"); + } + + if (clearflg > 0 && ontty == NOTTY) + clear_screen (); + + if (ontty == PITTY) + m_pclose (); + + return exitstat; } static void mhl_format (char *file, int length, int width) { - int i; - char *bp, *cp, **ip; - char *ap, buffer[BUFSIZ], name[NAMESZ]; - struct mcomp *c1; - struct stat st; - FILE *fp; - static dev_t dev = 0; - static ino_t ino = 0; - static time_t mtime = 0; - - if (fmthd != NULL) { - if (stat (etcpath (file), &st) != NOTOK - && mtime == st.st_mtime - && dev == st.st_dev - && ino == st.st_ino) - goto out; - else - free_queue (&fmthd, &fmttl); - } - - if ((fp = fopen (etcpath (file), "r")) == NULL) - adios (file, "unable to open format file"); - - if (fstat (fileno (fp), &st) != NOTOK) { - mtime = st.st_mtime; - dev = st.st_dev; - ino = st.st_ino; - } - - global.c_ovtxt = global.c_nfs = NULL; - global.c_fmt = NULL; - global.c_offset = 0; - global.c_ovoff = -1; - if ((i = sc_width ()) > 5) - global.c_width = i; - global.c_cwidth = -1; - if ((i = sc_length ()) > 5) - global.c_length = i - 1; - global.c_flags = BELL; /* BELL is default */ - *(ip = ignores) = NULL; - - while (vfgets (fp, &ap) == OK) { - bp = ap; - if (*bp == ';') - continue; - - if ((cp = strchr(bp, '\n'))) - *cp = 0; - - if (*bp == ':') { - c1 = add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT); - continue; + int i; + char *bp, *cp, **ip; + char *ap, buffer[BUFSIZ], name[NAMESZ]; + struct mcomp *c1; + struct stat st; + FILE *fp; + static dev_t dev = 0; + static ino_t ino = 0; + static time_t mtime = 0; + + if (fmthd != NULL) { + if (stat (etcpath (file), &st) != NOTOK + && mtime == st.st_mtime + && dev == st.st_dev + && ino == st.st_ino) + goto out; + else + free_queue (&fmthd, &fmttl); } - parptr = bp; - strncpy (name, parse(), sizeof(name)); - switch (*parptr) { - case '\0': - case ',': - case '=': - /* - * Split this list of fields to ignore, and copy - * it to the end of the current "ignores" list. - */ - if (!mh_strcasecmp (name, "ignores")) { - char **tmparray, **p; - int n = 0; - - /* split the fields */ - tmparray = brkstring (getcpy (++parptr), ",", NULL); - - /* count number of fields split */ - p = tmparray; - while (*p++) - n++; - - /* copy pointers to split fields to ignores array */ - ip = copyip (tmparray, ip, MAXARGS - num_ignores); - num_ignores += n; - continue; + if ((fp = fopen (etcpath (file), "r")) == NULL) + adios (file, "unable to open format file"); + + if (fstat (fileno (fp), &st) != NOTOK) { + mtime = st.st_mtime; + dev = st.st_dev; + ino = st.st_ino; + } + + global.c_ovtxt = global.c_nfs = NULL; + global.c_fmt = NULL; + global.c_offset = 0; + global.c_ovoff = -1; + if ((i = sc_width ()) > 5) + global.c_width = i; + global.c_cwidth = -1; + if ((i = sc_length ()) > 5) + global.c_length = i - 1; + global.c_flags = BELL; /* BELL is default */ + *(ip = ignores) = NULL; + + while (vfgets (fp, &ap) == OK) { + bp = ap; + if (*bp == ';') + continue; + + if ((cp = strchr(bp, '\n'))) + *cp = 0; + + if (*bp == ':') { + c1 = add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT); + continue; } + parptr = bp; - while (*parptr) { - if (evalvar (&global)) - adios (NULL, "format file syntax error: %s", bp); - if (*parptr) - parptr++; - } - continue; - - case ':': - c1 = add_queue (&fmthd, &fmttl, name, NULL, INIT); - while (*parptr == ':' || *parptr == ',') { - parptr++; - if (evalvar (c1)) - adios (NULL, "format file syntax error: %s", bp); + strncpy (name, parse(), sizeof(name)); + switch (*parptr) { + case '\0': + case ',': + case '=': + /* + * Split this list of fields to ignore, + * and copy it to the end of the current + * "ignores" list. + */ + if (!mh_strcasecmp (name, "ignores")) { + char **tmparray, **p; + int n = 0; + + /* split the fields */ + tmparray = brkstring (getcpy (++parptr), ",", NULL); + + /* count number of fields split */ + p = tmparray; + while (*p++) + n++; + + /* copy pointers to split fields to ignores array */ + ip = copyip (tmparray, ip, MAXARGS - num_ignores); + num_ignores += n; + continue; + } + parptr = bp; + while (*parptr) { + if (evalvar (&global)) + adios (NULL, "format file syntax error: %s", bp); + if (*parptr) + parptr++; + } + continue; + + case ':': + c1 = add_queue (&fmthd, &fmttl, name, NULL, INIT); + while (*parptr == ':' || *parptr == ',') { + parptr++; + if (evalvar (c1)) + adios (NULL, "format file syntax error: %s", bp); + } + if (!c1->c_nfs && global.c_nfs) { + if (c1->c_flags & DATEFMT) { + if (global.c_flags & DATEFMT) + c1->c_nfs = getcpy (global.c_nfs); + } + else + if (c1->c_flags & ADDRFMT) { + if (global.c_flags & ADDRFMT) + c1->c_nfs = getcpy (global.c_nfs); + } + } + continue; + + default: + adios (NULL, "format file syntax error: %s", bp); } - if (!c1->c_nfs && global.c_nfs) { - if (c1->c_flags & DATEFMT) { - if (global.c_flags & DATEFMT) - c1->c_nfs = getcpy (global.c_nfs); - } - else - if (c1->c_flags & ADDRFMT) { - if (global.c_flags & ADDRFMT) - c1->c_nfs = getcpy (global.c_nfs); - } + } + fclose (fp); + + if (mhldebug) { + for (c1 = fmthd; c1; c1 = c1->c_next) { + fprintf (stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", + c1->c_name, c1->c_text, c1->c_ovtxt); + fprintf (stderr, "\tnfs=0x%x fmt=0x%x\n", + (unsigned int)(unsigned long) c1->c_nfs, + (unsigned int)(unsigned long) c1->c_fmt); + fprintf (stderr, "\toffset=%d ovoff=%d width=%d cwidth=%d length=%d\n", + c1->c_offset, c1->c_ovoff, c1->c_width, + c1->c_cwidth, c1->c_length); + fprintf (stderr, "\tflags=%s\n", + snprintb (buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS)); } - continue; + } - default: - adios (NULL, "format file syntax error: %s", bp); +out: + if (clearflg == 1) { + global.c_flags |= CLEARSCR; + } else { + if (clearflg == -1) + global.c_flags &= ~CLEARSCR; } - } - fclose (fp); - - if (mhldebug) { - for (c1 = fmthd; c1; c1 = c1->c_next) { - fprintf (stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", - c1->c_name, c1->c_text, c1->c_ovtxt); - fprintf (stderr, "\tnfs=0x%x fmt=0x%x\n", - (unsigned int)(unsigned long) c1->c_nfs, - (unsigned int)(unsigned long) c1->c_fmt); - fprintf (stderr, "\toffset=%d ovoff=%d width=%d cwidth=%d length=%d\n", - c1->c_offset, c1->c_ovoff, c1->c_width, - c1->c_cwidth, c1->c_length); - fprintf (stderr, "\tflags=%s\n", - snprintb (buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS)); + + switch (bellflg) { /* command line may override format file */ + case 1: + global.c_flags |= BELL; + break; + case -1: + global.c_flags &= ~BELL; + break; } - } -out: - if (clearflg == 1) { - global.c_flags |= CLEARSCR; - } else { - if (clearflg == -1) - global.c_flags &= ~CLEARSCR; - } - - switch (bellflg) { /* command line may override format file */ - case 1: - global.c_flags |= BELL; - break; - case -1: - global.c_flags &= ~BELL; - break; - } - - if (length) - global.c_length = length; - if (width) - global.c_width = width; - if (global.c_length < 5) - global.c_length = 10000; - if (global.c_width < 5) - global.c_width = 10000; + if (length) + global.c_length = length; + if (width) + global.c_width = width; + if (global.c_length < 5) + global.c_length = 10000; + if (global.c_width < 5) + global.c_width = 10000; } static int evalvar (struct mcomp *c1) { - char *cp, name[NAMESZ]; - struct triple *ap; + char *cp, name[NAMESZ]; + struct triple *ap; - if (!*parptr) - return 0; - strncpy (name, parse(), sizeof(name)); + if (!*parptr) + return 0; + strncpy (name, parse(), sizeof(name)); - if (!mh_strcasecmp (name, "component")) { - if (ptos (name, &c1->c_text)) - return 1; - c1->c_flags &= ~NOCOMPONENT; - return 0; - } + if (!mh_strcasecmp (name, "component")) { + if (ptos (name, &c1->c_text)) + return 1; + c1->c_flags &= ~NOCOMPONENT; + return 0; + } - if (!mh_strcasecmp (name, "overflowtext")) - return ptos (name, &c1->c_ovtxt); + if (!mh_strcasecmp (name, "overflowtext")) + return ptos (name, &c1->c_ovtxt); - if (!mh_strcasecmp (name, "formatfield")) { - char *nfs; + if (!mh_strcasecmp (name, "formatfield")) { + char *nfs; - if (ptos (name, &cp)) - return 1; - nfs = new_fs (NULL, NULL, cp); - c1->c_nfs = getcpy (nfs); - c1->c_flags |= FORMAT; - return 0; - } + if (ptos (name, &cp)) + return 1; + nfs = new_fs (NULL, NULL, cp); + c1->c_nfs = getcpy (nfs); + c1->c_flags |= FORMAT; + return 0; + } - if (!mh_strcasecmp (name, "decode")) { - char *nfs; + if (!mh_strcasecmp (name, "decode")) { + char *nfs; - nfs = new_fs (NULL, NULL, "%(decode{text})"); - c1->c_nfs = getcpy (nfs); - c1->c_flags |= FORMAT; - return 0; - } - - if (!mh_strcasecmp (name, "offset")) - return ptoi (name, &c1->c_offset); - if (!mh_strcasecmp (name, "overflowoffset")) - return ptoi (name, &c1->c_ovoff); - if (!mh_strcasecmp (name, "width")) - return ptoi (name, &c1->c_width); - if (!mh_strcasecmp (name, "compwidth")) - return ptoi (name, &c1->c_cwidth); - if (!mh_strcasecmp (name, "length")) - return ptoi (name, &c1->c_length); - if (!mh_strcasecmp (name, "nodashstuffing")) - return (dashstuff = -1); - - for (ap = triples; ap->t_name; ap++) - if (!mh_strcasecmp (ap->t_name, name)) { - c1->c_flags |= ap->t_on; - c1->c_flags &= ~ap->t_off; - return 0; + nfs = new_fs (NULL, NULL, "%(decode{text})"); + c1->c_nfs = getcpy (nfs); + c1->c_flags |= FORMAT; + return 0; } - return 1; + if (!mh_strcasecmp (name, "offset")) + return ptoi (name, &c1->c_offset); + if (!mh_strcasecmp (name, "overflowoffset")) + return ptoi (name, &c1->c_ovoff); + if (!mh_strcasecmp (name, "width")) + return ptoi (name, &c1->c_width); + if (!mh_strcasecmp (name, "compwidth")) + return ptoi (name, &c1->c_cwidth); + if (!mh_strcasecmp (name, "length")) + return ptoi (name, &c1->c_length); + if (!mh_strcasecmp (name, "nodashstuffing")) + return (dashstuff = -1); + + for (ap = triples; ap->t_name; ap++) + if (!mh_strcasecmp (ap->t_name, name)) { + c1->c_flags |= ap->t_on; + c1->c_flags &= ~ap->t_off; + return 0; + } + + return 1; } static int ptoi (char *name, int *i) { - char *cp; + char *cp; - if (*parptr++ != '=' || !*(cp = parse ())) { - advise (NULL, "missing argument to variable %s", name); - return 1; - } + if (*parptr++ != '=' || !*(cp = parse ())) { + advise (NULL, "missing argument to variable %s", name); + return 1; + } - *i = atoi (cp); - return 0; + *i = atoi (cp); + return 0; } static int ptos (char *name, char **s) { - char c, *cp; + char c, *cp; - if (*parptr++ != '=') { - advise (NULL, "missing argument to variable %s", name); - return 1; - } - - if (*parptr != '"') { - for (cp = parptr; - *parptr && *parptr != ':' && *parptr != ','; - parptr++) - continue; - } else { - for (cp = ++parptr; *parptr && *parptr != '"'; parptr++) - if (*parptr == QUOTE) - if (!*++parptr) - parptr--; - } - c = *parptr; - *parptr = 0; - *s = getcpy (cp); - if ((*parptr = c) == '"') - parptr++; - return 0; + if (*parptr++ != '=') { + advise (NULL, "missing argument to variable %s", name); + return 1; + } + + if (*parptr != '"') { + for (cp = parptr; + *parptr && *parptr != ':' && *parptr != ','; + parptr++) + continue; + } else { + for (cp = ++parptr; *parptr && *parptr != '"'; parptr++) + if (*parptr == QUOTE) + if (!*++parptr) + parptr--; + } + c = *parptr; + *parptr = 0; + *s = getcpy (cp); + if ((*parptr = c) == '"') + parptr++; + return 0; } static char * parse (void) { - int c; - char *cp; - static char result[NAMESZ]; - - for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) { - c = *parptr; - if (isalnum (c) - || c == '.' - || c == '-' - || c == '_' - || c =='[' - || c == ']') - *cp++ = c; - else - break; - } - *cp = '\0'; + int c; + char *cp; + static char result[NAMESZ]; + + for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) { + c = *parptr; + if (isalnum (c) + || c == '.' + || c == '-' + || c == '_' + || c =='[' + || c == ']') + *cp++ = c; + else + break; + } + *cp = '\0'; - return result; + return result; } static void process (char *folder, char *fname, int ofilen, int ofilec) { - char *cp = NULL; - FILE *fp = NULL; - struct mcomp *c1; - - switch (setjmp (env)) { - case OK: - if (fname) { - fp = mhl_action ? (*mhl_action) (fname) : fopen (fname, "r"); - if (fp == NULL) { - advise (fname, "unable to open"); - exitstat++; - return; - } - } else { - fname = "(stdin)"; - fp = stdin; - } - cp = folder ? concat (folder, ":", fname, NULL) : getcpy (fname); - if (ontty != PITTY) - SIGNAL (SIGINT, intrser); - mhlfile (fp, cp, ofilen, ofilec); /* FALL THROUGH! */ - - default: - if (ontty != PITTY) - SIGNAL (SIGINT, SIG_IGN); - if (mhl_action == NULL && fp != stdin) - fclose (fp); - free (cp); - if (holder.c_text) { - free (holder.c_text); - holder.c_text = NULL; - } - free_queue (&msghd, &msgtl); - for (c1 = fmthd; c1; c1 = c1->c_next) - c1->c_flags &= ~HDROUTPUT; - break; - } + char *cp = NULL; + FILE *fp = NULL; + struct mcomp *c1; + + switch (setjmp (env)) { + case OK: + if (fname) { + fp = mhl_action ? (*mhl_action) (fname) : fopen (fname, "r"); + if (fp == NULL) { + advise (fname, "unable to open"); + exitstat++; + return; + } + } else { + fname = "(stdin)"; + fp = stdin; + } + cp = folder ? concat (folder, ":", fname, NULL) : getcpy (fname); + if (ontty != PITTY) + SIGNAL (SIGINT, intrser); + mhlfile (fp, cp, ofilen, ofilec); /* FALL THROUGH! */ + + default: + if (ontty != PITTY) + SIGNAL (SIGINT, SIG_IGN); + if (mhl_action == NULL && fp != stdin) + fclose (fp); + free (cp); + if (holder.c_text) { + free (holder.c_text); + holder.c_text = NULL; + } + free_queue (&msghd, &msgtl); + for (c1 = fmthd; c1; c1 = c1->c_next) + c1->c_flags &= ~HDROUTPUT; + break; + } } static void mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) { - int state; - struct mcomp *c1, *c2, *c3; - char **ip, name[NAMESZ], buf[BUFSIZ]; - - if (forwall) { - if (digest) - printf ("%s", ofilen == 1 ? delim3 : delim4); - else { - printf ("\n-------"); - if (ofilen == 1) - printf (" Forwarded Message%s", ofilec > 1 ? "s" : ""); - else - printf (" Message %d", ofilen); - printf ("\n\n"); - } - } else { - switch (ontty) { - case PITTY: - if (ofilec > 1) { - if (ofilen > 1) { - if ((global.c_flags & CLEARSCR)) - clear_screen (); - else - printf ("\n\n\n"); - } - printf (">>> %s\n\n", mname); - } - break; - - case ISTTY: - strncpy (buf, "\n", sizeof(buf)); - if (ofilec > 1) { - if (SOprintf ("Press to list \"%s\"...", mname)) { - if (ofilen > 1) - printf ("\n\n\n"); - printf ("Press to list \"%s\"...", mname); - } - fflush (stdout); - buf[0] = 0; - read (fileno (stdout), buf, sizeof(buf)); - } - if (strchr(buf, '\n')) { - if ((global.c_flags & CLEARSCR)) - clear_screen (); - } - else - printf ("\n"); - break; - - default: - if (ofilec > 1) { - if (ofilen > 1) { - printf ("\n\n\n"); - if (clearflg > 0) - clear_screen (); - } - printf (">>> %s\n\n", mname); - } - break; - } - } - - for (state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { - case FLD: - case FLDPLUS: - for (ip = ignores; *ip; ip++) - if (!mh_strcasecmp (name, *ip)) { - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); - break; - } - if (*ip) - continue; + int state; + struct mcomp *c1, *c2, *c3; + char **ip, name[NAMESZ], buf[BUFSIZ]; - for (c2 = fmthd; c2; c2 = c2->c_next) - if (!mh_strcasecmp (c2->c_name, name)) - break; - c1 = NULL; - if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT)) - for (c1 = msghd; c1; c1 = c1->c_next) - if (!mh_strcasecmp (c1->c_name, c3->c_name)) { - c1->c_text = - mcomp_add (c1->c_flags, buf, c1->c_text); - break; - } - if (c1 == NULL) - c1 = add_queue (&msghd, &msgtl, name, buf, 0); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); - c1->c_text = add (buf, c1->c_text); + if (forwall) { + if (digest) + printf ("%s", ofilen == 1 ? delim3 : delim4); + else { + printf ("\n-------"); + if (ofilen == 1) + printf (" Forwarded Message%s", ofilec > 1 ? "s" : ""); + else + printf (" Message %d", ofilen); + printf ("\n\n"); } - if (c2 == NULL) - c1->c_flags |= EXTRA; - continue; + } else { + switch (ontty) { + case PITTY: + if (ofilec > 1) { + if (ofilen > 1) { + if ((global.c_flags & CLEARSCR)) + clear_screen (); + else + printf ("\n\n\n"); + } + printf (">>> %s\n\n", mname); + } + break; - case BODY: - case FILEEOF: - row = column = 0; - for (c1 = fmthd; c1; c1 = c1->c_next) { - if (c1->c_flags & CLEARTEXT) { - putcomp (c1, c1, ONECOMP); - continue; - } - if (!mh_strcasecmp (c1->c_name, "messagename")) { - holder.c_text = concat ("(Message ", mname, ")\n", - NULL); - putcomp (c1, &holder, ONECOMP); - free (holder.c_text); - holder.c_text = NULL; - continue; - } - if (!mh_strcasecmp (c1->c_name, "extras")) { - for (c2 = msghd; c2; c2 = c2->c_next) - if (c2->c_flags & EXTRA) - putcomp (c1, c2, TWOCOMP); - continue; - } - if (dobody && !mh_strcasecmp (c1->c_name, "body")) { - holder.c_text = mh_xmalloc (sizeof(buf)); - strncpy (holder.c_text, buf, sizeof(buf)); - while (state == BODY) { - putcomp (c1, &holder, BODYCOMP); - state = m_getfld (state, name, holder.c_text, - sizeof(buf), fp); - } - free (holder.c_text); - holder.c_text = NULL; - continue; - } - for (c2 = msghd; c2; c2 = c2->c_next) - if (!mh_strcasecmp (c2->c_name, c1->c_name)) { - putcomp (c1, c2, ONECOMP); - if (!(c1->c_flags & SPLIT)) + case ISTTY: + strncpy (buf, "\n", sizeof(buf)); + if (ofilec > 1) { + if (SOprintf ("Press to list \"%s\"...", mname)) { + if (ofilen > 1) + printf ("\n\n\n"); + printf ("Press to list \"%s\"...", mname); + } + fflush (stdout); + buf[0] = 0; + read (fileno (stdout), buf, sizeof(buf)); + } + if (strchr(buf, '\n')) { + if ((global.c_flags & CLEARSCR)) + clear_screen (); + } + else + printf ("\n"); break; - } - if (faceproc && c2 == NULL && (c1->c_flags & FACEFMT)) - for (c2 = msghd; c2; c2 = c2->c_next) - if (c2->c_flags & FACEDFLT) { - if (c2->c_face == NULL) - face_format (c2); - if ((holder.c_text = c2->c_face)) { - putcomp (c1, &holder, ONECOMP); - holder.c_text = NULL; + + default: + if (ofilec > 1) { + if (ofilen > 1) { + printf ("\n\n\n"); + if (clearflg > 0) + clear_screen (); + } + printf (">>> %s\n\n", mname); } break; - } } - return; + } - case LENERR: - case FMTERR: - advise (NULL, "format error in message %s", mname); - exitstat++; - return; + for (state = FLD;;) { + switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + case FLD: + case FLDPLUS: + for (ip = ignores; *ip; ip++) + if (!mh_strcasecmp (name, *ip)) { + while (state == FLDPLUS) + state = m_getfld (state, name, buf, sizeof(buf), fp); + break; + } + if (*ip) + continue; + + for (c2 = fmthd; c2; c2 = c2->c_next) + if (!mh_strcasecmp (c2->c_name, name)) + break; + c1 = NULL; + if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT)) + for (c1 = msghd; c1; c1 = c1->c_next) + if (!mh_strcasecmp (c1->c_name, c3->c_name)) { + c1->c_text = + mcomp_add (c1->c_flags, buf, c1->c_text); + break; + } + if (c1 == NULL) + c1 = add_queue (&msghd, &msgtl, name, buf, 0); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), fp); + c1->c_text = add (buf, c1->c_text); + } + if (c2 == NULL) + c1->c_flags |= EXTRA; + continue; + + case BODY: + case FILEEOF: + row = column = 0; + for (c1 = fmthd; c1; c1 = c1->c_next) { + if (c1->c_flags & CLEARTEXT) { + putcomp (c1, c1, ONECOMP); + continue; + } + if (!mh_strcasecmp (c1->c_name, "messagename")) { + holder.c_text = concat ("(Message ", mname, ")\n", + NULL); + putcomp (c1, &holder, ONECOMP); + free (holder.c_text); + holder.c_text = NULL; + continue; + } + if (!mh_strcasecmp (c1->c_name, "extras")) { + for (c2 = msghd; c2; c2 = c2->c_next) + if (c2->c_flags & EXTRA) + putcomp (c1, c2, TWOCOMP); + continue; + } + if (dobody && !mh_strcasecmp (c1->c_name, "body")) { + holder.c_text = mh_xmalloc (sizeof(buf)); + strncpy (holder.c_text, buf, sizeof(buf)); + while (state == BODY) { + putcomp (c1, &holder, BODYCOMP); + state = m_getfld (state, name, holder.c_text, + sizeof(buf), fp); + } + free (holder.c_text); + holder.c_text = NULL; + continue; + } + for (c2 = msghd; c2; c2 = c2->c_next) + if (!mh_strcasecmp (c2->c_name, c1->c_name)) { + putcomp (c1, c2, ONECOMP); + if (!(c1->c_flags & SPLIT)) + break; + } + if (faceproc && c2 == NULL && (c1->c_flags & FACEFMT)) + for (c2 = msghd; c2; c2 = c2->c_next) + if (c2->c_flags & FACEDFLT) { + if (c2->c_face == NULL) + face_format (c2); + if ((holder.c_text = c2->c_face)) { + putcomp (c1, &holder, ONECOMP); + holder.c_text = NULL; + } + break; + } + } + return; + + case LENERR: + case FMTERR: + advise (NULL, "format error in message %s", mname); + exitstat++; + return; - default: - adios (NULL, "getfld() returned %d", state); + default: + adios (NULL, "getfld() returned %d", state); + } } - } } static int mcomp_flags (char *name) { - struct pair *ap; + struct pair *ap; - for (ap = pairs; ap->p_name; ap++) - if (!mh_strcasecmp (ap->p_name, name)) - return (ap->p_flags); + for (ap = pairs; ap->p_name; ap++) + if (!mh_strcasecmp (ap->p_name, name)) + return (ap->p_flags); - return 0; + return 0; } static char * mcomp_add (long flags, char *s1, char *s2) { - char *dp; + char *dp; - if (!(flags & ADDRFMT)) - return add (s1, s2); + if (!(flags & ADDRFMT)) + return add (s1, s2); - if (s2 && *(dp = s2 + strlen (s2) - 1) == '\n') - *dp = 0; + if (s2 && *(dp = s2 + strlen (s2) - 1) == '\n') + *dp = 0; - return add (s1, add (",\n", s2)); + return add (s1, add (",\n", s2)); } struct pqpair { - char *pq_text; - char *pq_error; - struct pqpair *pq_next; + char *pq_text; + char *pq_error; + struct pqpair *pq_next; }; static void mcomp_format (struct mcomp *c1, struct mcomp *c2) { - int dat[5]; - char *ap, *cp; - char buffer[BUFSIZ], error[BUFSIZ]; - struct comp *cptr; - struct pqpair *p, *q; - struct pqpair pq; - struct mailname *mp; - - ap = c2->c_text; - c2->c_text = NULL; - dat[0] = 0; - dat[1] = 0; - dat[2] = 0; - dat[3] = sizeof(buffer) - 1; - dat[4] = 0; - fmt_compile (c1->c_nfs, &c1->c_fmt); - - if (!(c1->c_flags & ADDRFMT)) { - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = ap; - if ((cp = strrchr(ap, '\n'))) /* drop ending newline */ - if (!cp[1]) - *cp = 0; - - fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat); - /* Don't need to append a newline, dctime() already did */ - c2->c_text = getcpy (buffer); + int dat[5]; + char *ap, *cp; + char buffer[BUFSIZ], error[BUFSIZ]; + struct comp *cptr; + struct pqpair *p, *q; + struct pqpair pq; + struct mailname *mp; + + ap = c2->c_text; + c2->c_text = NULL; + dat[0] = 0; + dat[1] = 0; + dat[2] = 0; + dat[3] = sizeof(buffer) - 1; + dat[4] = 0; + fmt_compile (c1->c_nfs, &c1->c_fmt); + + if (!(c1->c_flags & ADDRFMT)) { + FINDCOMP (cptr, "text"); + if (cptr) + cptr->c_text = ap; + if ((cp = strrchr(ap, '\n'))) /* drop ending newline */ + if (!cp[1]) + *cp = 0; + + fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat); + /* Don't need to append a newline, dctime() already did */ + c2->c_text = getcpy (buffer); + + free (ap); + return; + } - free (ap); - return; - } + (q = &pq)->pq_next = NULL; + while ((cp = getname (ap))) { + if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL) + adios (NULL, "unable to allocate pqpair memory"); + + if ((mp = getm (cp, NULL, 0, AD_NAME, error)) == NULL) { + p->pq_text = getcpy (cp); + p->pq_error = getcpy (error); + } else { + if ((c1->c_flags & FACEDFLT) && c2->c_face == NULL) { + char *h, *o; + if ((h = mp->m_host) == NULL) + h = LocalName (); + if ((o = OfficialName (h))) + h = o; + c2->c_face = concat ("address ", h, " ", + mp->m_mbox, NULL); + } + p->pq_text = getcpy (mp->m_text); + mnfree (mp); + } + q = (q->pq_next = p); + } - (q = &pq)->pq_next = NULL; - while ((cp = getname (ap))) { - if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL) - adios (NULL, "unable to allocate pqpair memory"); + for (p = pq.pq_next; p; p = q) { + FINDCOMP (cptr, "text"); + if (cptr) + cptr->c_text = p->pq_text; + FINDCOMP (cptr, "error"); + if (cptr) + cptr->c_text = p->pq_error; + + fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat); + if (*buffer) { + if (c2->c_text) + c2->c_text = add (",\n", c2->c_text); + if (*(cp = buffer + strlen (buffer) - 1) == '\n') + *cp = 0; + c2->c_text = add (buffer, c2->c_text); + } - if ((mp = getm (cp, NULL, 0, AD_NAME, error)) == NULL) { - p->pq_text = getcpy (cp); - p->pq_error = getcpy (error); - } else { - if ((c1->c_flags & FACEDFLT) && c2->c_face == NULL) { - char *h, *o; - if ((h = mp->m_host) == NULL) - h = LocalName (); - if ((o = OfficialName (h))) - h = o; - c2->c_face = concat ("address ", h, " ", mp->m_mbox, - NULL); - } - p->pq_text = getcpy (mp->m_text); - mnfree (mp); + free (p->pq_text); + if (p->pq_error) + free (p->pq_error); + q = p->pq_next; + free ((char *) p); } - q = (q->pq_next = p); - } - - for (p = pq.pq_next; p; p = q) { - FINDCOMP (cptr, "text"); - if (cptr) - cptr->c_text = p->pq_text; - FINDCOMP (cptr, "error"); - if (cptr) - cptr->c_text = p->pq_error; - - fmt_scan (c1->c_fmt, buffer, sizeof(buffer) - 1, dat); - if (*buffer) { - if (c2->c_text) - c2->c_text = add (",\n", c2->c_text); - if (*(cp = buffer + strlen (buffer) - 1) == '\n') - *cp = 0; - c2->c_text = add (buffer, c2->c_text); - } - - free (p->pq_text); - if (p->pq_error) - free (p->pq_error); - q = p->pq_next; - free ((char *) p); - } - c2->c_text = add ("\n", c2->c_text); - free (ap); + c2->c_text = add ("\n", c2->c_text); + free (ap); } static struct mcomp * -add_queue (struct mcomp **head, struct mcomp **tail, char *name, char *text, int flags) +add_queue (struct mcomp **head, struct mcomp **tail, char *name, + char *text, int flags) { - struct mcomp *c1; - - if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL) - adios (NULL, "unable to allocate comp memory"); - - c1->c_flags = flags & ~INIT; - if ((c1->c_name = name ? getcpy (name) : NULL)) - c1->c_flags |= mcomp_flags (c1->c_name); - c1->c_text = text ? getcpy (text) : NULL; - if (flags & INIT) { - if (global.c_ovtxt) - c1->c_ovtxt = getcpy (global.c_ovtxt); - c1->c_offset = global.c_offset; - c1->c_ovoff = global. c_ovoff; - c1->c_width = c1->c_length = 0; - c1->c_cwidth = global.c_cwidth; - c1->c_flags |= global.c_flags & GFLAGS; - } - if (*head == NULL) - *head = c1; - if (*tail != NULL) - (*tail)->c_next = c1; - *tail = c1; - - return c1; + struct mcomp *c1; + + if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL) + adios (NULL, "unable to allocate comp memory"); + + c1->c_flags = flags & ~INIT; + if ((c1->c_name = name ? getcpy (name) : NULL)) + c1->c_flags |= mcomp_flags (c1->c_name); + c1->c_text = text ? getcpy (text) : NULL; + if (flags & INIT) { + if (global.c_ovtxt) + c1->c_ovtxt = getcpy (global.c_ovtxt); + c1->c_offset = global.c_offset; + c1->c_ovoff = global. c_ovoff; + c1->c_width = c1->c_length = 0; + c1->c_cwidth = global.c_cwidth; + c1->c_flags |= global.c_flags & GFLAGS; + } + if (*head == NULL) + *head = c1; + if (*tail != NULL) + (*tail)->c_next = c1; + *tail = c1; + + return c1; } static void free_queue (struct mcomp **head, struct mcomp **tail) { - struct mcomp *c1, *c2; - - for (c1 = *head; c1; c1 = c2) { - c2 = c1->c_next; - if (c1->c_name) - free (c1->c_name); - if (c1->c_text) - free (c1->c_text); - if (c1->c_ovtxt) - free (c1->c_ovtxt); - if (c1->c_nfs) - free (c1->c_nfs); - if (c1->c_fmt) - free ((char *) c1->c_fmt); - if (c1->c_face) - free (c1->c_face); - free ((char *) c1); - } - - *head = *tail = NULL; + struct mcomp *c1, *c2; + + for (c1 = *head; c1; c1 = c2) { + c2 = c1->c_next; + if (c1->c_name) + free (c1->c_name); + if (c1->c_text) + free (c1->c_text); + if (c1->c_ovtxt) + free (c1->c_ovtxt); + if (c1->c_nfs) + free (c1->c_nfs); + if (c1->c_fmt) + free ((char *) c1->c_fmt); + if (c1->c_face) + free (c1->c_face); + free ((char *) c1); + } + + *head = *tail = NULL; } static void putcomp (struct mcomp *c1, struct mcomp *c2, int flag) { - int count, cchdr; - unsigned char *cp; - - cchdr = 0; - lm = 0; - llim = c1->c_length ? c1->c_length : -1; - wid = c1->c_width ? c1->c_width : global.c_width; - ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff) - + c1->c_offset; - if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL) - ovtxt = ""; - if (wid < ovoff + strlen (ovtxt) + 5) - adios (NULL, "component: %s width(%d) too small for overflow(%d)", - c1->c_name, wid, ovoff + strlen (ovtxt) + 5); - onelp = NULL; - - if (c1->c_flags & CLEARTEXT) { - putstr (c1->c_text); - putstr ("\n"); - return; - } - - if (c1->c_flags & FACEFMT) - switch (doface (c2)) { - case NOTOK: /* error */ - case OK: /* async faceproc */ + int count, cchdr; + unsigned char *cp; + + cchdr = 0; + lm = 0; + llim = c1->c_length ? c1->c_length : -1; + wid = c1->c_width ? c1->c_width : global.c_width; + ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff) + + c1->c_offset; + if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL) + ovtxt = ""; + if (wid < ovoff + strlen (ovtxt) + 5) + adios (NULL, "component: %s width(%d) too small for overflow(%d)", + c1->c_name, wid, ovoff + strlen (ovtxt) + 5); + onelp = NULL; + + if (c1->c_flags & CLEARTEXT) { + putstr (c1->c_text); + putstr ("\n"); return; + } + + if (c1->c_flags & FACEFMT) + switch (doface (c2)) { + case NOTOK: /* error */ + case OK: /* async faceproc */ + return; - default: /* sync faceproc */ - break; + default: /* sync faceproc */ + break; + } + + if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT))) + mcomp_format (c1, c2); + + if (c1->c_flags & CENTER) { + count = (c1->c_width ? c1->c_width : global.c_width) + - c1->c_offset - strlen (c2->c_text); + if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) + count -= strlen (c1->c_text ? c1->c_text : c1->c_name) + 2; + lm = c1->c_offset + (count / 2); + } else { + if (c1->c_offset) + lm = c1->c_offset; } - if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT))) - mcomp_format (c1, c2); - - if (c1->c_flags & CENTER) { - count = (c1->c_width ? c1->c_width : global.c_width) - - c1->c_offset - strlen (c2->c_text); - if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) - count -= strlen (c1->c_text ? c1->c_text : c1->c_name) + 2; - lm = c1->c_offset + (count / 2); - } else { - if (c1->c_offset) - lm = c1->c_offset; - } - - if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) { - if (c1->c_flags & UPPERCASE) /* uppercase component also */ - for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++) - if (islower (*cp)) - *cp = toupper (*cp); - putstr (c1->c_text ? c1->c_text : c1->c_name); - if (flag != BODYCOMP) { - putstr (": "); - if (!(c1->c_flags & SPLIT)) - c1->c_flags |= HDROUTPUT; - - cchdr++; - if ((count = c1->c_cwidth - - strlen (c1->c_text ? c1->c_text : c1->c_name) - 2) > 0) - while (count--) - putstr (" "); + if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) { + if (c1->c_flags & UPPERCASE) /* uppercase component also */ + for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++) + if (islower (*cp)) + *cp = toupper (*cp); + putstr (c1->c_text ? c1->c_text : c1->c_name); + if (flag != BODYCOMP) { + putstr (": "); + if (!(c1->c_flags & SPLIT)) + c1->c_flags |= HDROUTPUT; + + cchdr++; + if ((count = c1->c_cwidth - + strlen (c1->c_text ? c1->c_text : c1->c_name) - 2) > 0) + while (count--) + putstr (" "); + } else + c1->c_flags |= HDROUTPUT; /* for BODYCOMP */ } - else - c1->c_flags |= HDROUTPUT; /* for BODYCOMP */ - } - - if (flag == TWOCOMP - && !(c2->c_flags & HDROUTPUT) - && !(c2->c_flags & NOCOMPONENT)) { - if (c1->c_flags & UPPERCASE) - for (cp = c2->c_name; *cp; cp++) - if (islower (*cp)) - *cp = toupper (*cp); - putstr (c2->c_name); - putstr (": "); - if (!(c1->c_flags & SPLIT)) - c2->c_flags |= HDROUTPUT; - - cchdr++; - if ((count = c1->c_cwidth - strlen (c2->c_name) - 2) > 0) - while (count--) - putstr (" "); - } - if (c1->c_flags & UPPERCASE) - for (cp = c2->c_text; *cp; cp++) - if (islower (*cp)) - *cp = toupper (*cp); - - count = 0; - if (cchdr) { - if (flag == TWOCOMP) - count = (c1->c_cwidth >= 0) ? c1->c_cwidth - : strlen (c2->c_name) + 2; - else - count = (c1->c_cwidth >= 0) ? c1->c_cwidth - : strlen (c1->c_text ? c1->c_text : c1->c_name) + 2; - } - count += c1->c_offset; - - if ((cp = oneline (c2->c_text, c1->c_flags))) - putstr(cp); - if (term == '\n') - putstr ("\n"); - while ((cp = oneline (c2->c_text, c1->c_flags))) { - lm = count; - if (flag == BODYCOMP - && !(c1->c_flags & NOCOMPONENT)) - putstr (c1->c_text ? c1->c_text : c1->c_name); - if (*cp) - putstr (cp); + + if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT) + && !(c2->c_flags & NOCOMPONENT)) { + if (c1->c_flags & UPPERCASE) + for (cp = c2->c_name; *cp; cp++) + if (islower (*cp)) + *cp = toupper (*cp); + putstr (c2->c_name); + putstr (": "); + if (!(c1->c_flags & SPLIT)) + c2->c_flags |= HDROUTPUT; + + cchdr++; + if ((count = c1->c_cwidth - strlen (c2->c_name) - 2) > 0) + while (count--) + putstr (" "); + } + if (c1->c_flags & UPPERCASE) + for (cp = c2->c_text; *cp; cp++) + if (islower (*cp)) + *cp = toupper (*cp); + + count = 0; + if (cchdr) { + if (flag == TWOCOMP) + count = (c1->c_cwidth >= 0) ? c1->c_cwidth + : strlen (c2->c_name) + 2; + else + count = (c1->c_cwidth >= 0) ? c1->c_cwidth + : strlen (c1->c_text ? c1->c_text : c1->c_name) + 2; + } + count += c1->c_offset; + + if ((cp = oneline (c2->c_text, c1->c_flags))) + putstr(cp); if (term == '\n') - putstr ("\n"); - } - if (flag == BODYCOMP && term == '\n') - c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */ + putstr ("\n"); + while ((cp = oneline (c2->c_text, c1->c_flags))) { + lm = count; + if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT)) + putstr (c1->c_text ? c1->c_text : c1->c_name); + if (*cp) + putstr (cp); + if (term == '\n') + putstr ("\n"); + } + if (flag == BODYCOMP && term == '\n') + c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */ } static char * oneline (char *stuff, long flags) { - int spc; - char *cp, *ret; - - if (onelp == NULL) - onelp = stuff; - if (*onelp == 0) - return (onelp = NULL); - - ret = onelp; - term = 0; - if (flags & COMPRESS) { - for (spc = 1, cp = ret; *onelp; onelp++) - if (isspace (*onelp)) { - if (*onelp == '\n' && (!onelp[1] || (flags & ADDRFMT))) { - term = '\n'; - *onelp++ = 0; - break; + int spc; + char *cp, *ret; + + if (onelp == NULL) + onelp = stuff; + if (*onelp == 0) + return (onelp = NULL); + + ret = onelp; + term = 0; + if (flags & COMPRESS) { + for (spc = 1, cp = ret; *onelp; onelp++) + if (isspace (*onelp)) { + if (*onelp == '\n' && (!onelp[1] || (flags & ADDRFMT))) { + term = '\n'; + *onelp++ = 0; + break; + } else if (!spc) { + *cp++ = ' '; + spc++; + } + } else { + *cp++ = *onelp; + spc = 0; + } + + *cp = 0; + } else { + while (*onelp && *onelp != '\n') + onelp++; + if (*onelp == '\n') { + term = '\n'; + *onelp++ = 0; } - else - if (!spc) { - *cp++ = ' '; - spc++; - } - } - else { - *cp++ = *onelp; - spc = 0; - } - - *cp = 0; - } - else { - while (*onelp && *onelp != '\n') - onelp++; - if (*onelp == '\n') { - term = '\n'; - *onelp++ = 0; + if (flags & LEFTADJUST) + while (*ret == ' ' || *ret == '\t') + ret++; } - if (flags & LEFTADJUST) - while (*ret == ' ' || *ret == '\t') - ret++; - } - if (*onelp == 0 && term == '\n' && (flags & NONEWLINE)) - term = 0; + if (*onelp == 0 && term == '\n' && (flags & NONEWLINE)) + term = 0; - return ret; + return ret; } static void putstr (char *string) { - if (!column && lm > 0) { - while (lm > 0) - if (lm >= 8) { - putch ('\t'); - lm -= 8; - } - else { - putch (' '); - lm--; - } - } - lm = 0; - while (*string) - putch (*string++); + if (!column && lm > 0) { + while (lm > 0) + if (lm >= 8) { + putch ('\t'); + lm -= 8; + } else { + putch (' '); + lm--; + } + } + lm = 0; + while (*string) + putch (*string++); } static void putch (char ch) { - char buf[BUFSIZ]; - - if (llim == 0) - return; - - switch (ch) { - case '\n': - if (llim > 0) - llim--; - column = 0; - row++; - if (ontty != ISTTY || row != global.c_length) - break; - if (global.c_flags & BELL) - putchar ('\007'); - fflush (stdout); - buf[0] = 0; - read (fileno (stdout), buf, sizeof(buf)); - if (strchr(buf, '\n')) { - if (global.c_flags & CLEARSCR) - clear_screen (); - row = 0; - } else { - putchar ('\n'); - row = global.c_length / 3; - } - return; - - case '\t': - column |= 07; - column++; - break; - - case '\b': - column--; - break; - - case '\r': - column = 0; - break; - - default: - /* - * If we are forwarding this message, and the first - * column contains a dash, then add a dash and a space. - */ - if (column == 0 && forwflg && (dashstuff >= 0) && ch == '-') { - putchar ('-'); - putchar (' '); - } - if (ch >= ' ') - column++; - break; - } - - if (column >= wid) { - putch ('\n'); - if (ovoff > 0) - lm = ovoff; - putstr (ovtxt ? ovtxt : ""); - putch (ch); - return; - } - - putchar (ch); + char buf[BUFSIZ]; + + if (llim == 0) + return; + + switch (ch) { + case '\n': + if (llim > 0) + llim--; + column = 0; + row++; + if (ontty != ISTTY || row != global.c_length) + break; + if (global.c_flags & BELL) + putchar ('\007'); + fflush (stdout); + buf[0] = 0; + read (fileno (stdout), buf, sizeof(buf)); + if (strchr(buf, '\n')) { + if (global.c_flags & CLEARSCR) + clear_screen (); + row = 0; + } else { + putchar ('\n'); + row = global.c_length / 3; + } + return; + + case '\t': + column |= 07; + column++; + break; + + case '\b': + column--; + break; + + case '\r': + column = 0; + break; + + default: + /* + * If we are forwarding this message, and the first + * column contains a dash, then add a dash and a space. + */ + if (column == 0 && forwflg && (dashstuff >= 0) && ch == '-') { + putchar ('-'); + putchar (' '); + } + if (ch >= ' ') + column++; + break; + } + + if (column >= wid) { + putch ('\n'); + if (ovoff > 0) + lm = ovoff; + putstr (ovtxt ? ovtxt : ""); + putch (ch); + return; + } + + putchar (ch); } @@ -1448,12 +1442,12 @@ static RETSIGTYPE intrser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGINT, intrser); + SIGNAL (SIGINT, intrser); #endif - discard (stdout); - putchar ('\n'); - longjmp (env, DONE); + discard (stdout); + putchar ('\n'); + longjmp (env, DONE); } @@ -1461,10 +1455,10 @@ static RETSIGTYPE pipeser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGPIPE, pipeser); + SIGNAL (SIGPIPE, pipeser); #endif - done (NOTOK); + done (NOTOK); } @@ -1472,37 +1466,37 @@ static RETSIGTYPE quitser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGQUIT, quitser); + SIGNAL (SIGQUIT, quitser); #endif - putchar ('\n'); - fflush (stdout); - done (NOTOK); + putchar ('\n'); + fflush (stdout); + done (NOTOK); } static void face_format (struct mcomp *c1) { - char *cp; - struct mailname *mp; - - if ((cp = c1->c_text) == NULL) - return; - - if ((cp = getname (cp))) { - if ((mp = getm (cp, NULL, 0, AD_NAME, NULL))) { - char *h, *o; - if ((h = mp->m_host) == NULL) - h = LocalName (); - if ((o = OfficialName (h))) - h = o; - c1->c_face = concat ("address ", h, " ", mp->m_mbox, NULL); - } + char *cp; + struct mailname *mp; - while ((cp = getname (cp))) - continue; - } + if ((cp = c1->c_text) == NULL) + return; + + if ((cp = getname (cp))) { + if ((mp = getm (cp, NULL, 0, AD_NAME, NULL))) { + char *h, *o; + if ((h = mp->m_host) == NULL) + h = LocalName (); + if ((o = OfficialName (h))) + h = o; + c1->c_face = concat ("address ", h, " ", mp->m_mbox, NULL); + } + + while ((cp = getname (cp))) + continue; + } } @@ -1523,54 +1517,54 @@ face_format (struct mcomp *c1) static int doface (struct mcomp *c1) { - int result, sd; - static int inited = OK; - static struct sockaddr_storage ss; - static socklen_t socklen; - static int socktype; - static int protocol; - - if (inited == OK) { - char *cp; - char **ap = brkstring (cp = getcpy (faceproc), " ", "\n"); - struct addrinfo hints, *res; - - if (ap[0] == NULL || ap[1] == NULL) { + int result, sd; + static int inited = OK; + static struct sockaddr_storage ss; + static socklen_t socklen; + static int socktype; + static int protocol; + + if (inited == OK) { + char *cp; + char **ap = brkstring (cp = getcpy (faceproc), " ", "\n"); + struct addrinfo hints, *res; + + if (ap[0] == NULL || ap[1] == NULL) { bad_faceproc: ; - free (cp); - return (inited = NOTOK); - } + free (cp); + return (inited = NOTOK); + } - memset(&hints, 0, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); #ifdef AI_ADDRCONFIG - hints.ai_flags = AI_ADDRCONFIG; + hints.ai_flags = AI_ADDRCONFIG; #endif - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; - if (getaddrinfo(ap[0], ap[1], &hints, &res) != 0) - goto bad_faceproc; + if (getaddrinfo(ap[0], ap[1], &hints, &res) != 0) + goto bad_faceproc; - memcpy(&ss, res->ai_addr, res->ai_addrlen); - socklen = res->ai_addrlen; - socktype = res->ai_socktype; - protocol = res->ai_protocol; - freeaddrinfo(res); + memcpy(&ss, res->ai_addr, res->ai_addrlen); + socklen = res->ai_addrlen; + socktype = res->ai_socktype; + protocol = res->ai_protocol; + freeaddrinfo(res); - inited = DONE; - } - if (inited == NOTOK) - return NOTOK; + inited = DONE; + } + if (inited == NOTOK) + return NOTOK; - if ((sd = socket (ss.ss_family, socktype, protocol)) == NOTOK) - return NOTOK; + if ((sd = socket (ss.ss_family, socktype, protocol)) == NOTOK) + return NOTOK; - result = sendto (sd, c1->c_text, strlen (c1->c_text), 0, + result = sendto (sd, c1->c_text, strlen (c1->c_text), 0, (struct sockaddr *) &ss, socklen); - close (sd); + close (sd); - return (result != NOTOK ? OK : NOTOK); + return (result != NOTOK ? OK : NOTOK); } /* @@ -1582,104 +1576,103 @@ bad_faceproc: ; static int doface (struct mcomp *c1) { - int i, len, vecp; - pid_t child_id; - int result, pdi[2], pdo[2]; - char *bp, *cp; - char buffer[BUFSIZ], *vec[10]; - - if (pipe (pdi) == NOTOK) - return NOTOK; - if (pipe (pdo) == NOTOK) { - close (pdi[0]); - close (pdi[1]); - return NOTOK; - } - - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); - - switch (child_id) { - case NOTOK: - /* oops... fork error */ - return NOTOK; - - case OK: - /* child process */ - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - if (pdi[0] != fileno (stdin)) { - dup2 (pdi[0], fileno (stdin)); + int i, len, vecp; + pid_t child_id; + int result, pdi[2], pdo[2]; + char *bp, *cp; + char buffer[BUFSIZ], *vec[10]; + + if (pipe (pdi) == NOTOK) + return NOTOK; + if (pipe (pdo) == NOTOK) { close (pdi[0]); - } - close (pdi[1]); - close (pdo[0]); - if (pdo[1] != fileno (stdout)) { - dup2 (pdo[1], fileno (stdout)); - close (pdo[1]); - } - vecp = 0; - vec[vecp++] = r1bindex (faceproc, '/'); - vec[vecp++] = "-e"; - if (sleepsw != NOTOK) { - vec[vecp++] = "-s"; - snprintf (buffer, sizeof(buffer), "%d", sleepsw); - vec[vecp++] = buffer; - } - vec[vecp] = NULL; - execvp (faceproc, vec); - fprintf (stderr, "unable to exec "); - perror (faceproc); - _exit (-1); /* NOTREACHED */ - - default: - /* parent process */ - close (pdi[0]); - i = strlen (c1->c_text); - if (write (pdi[1], c1->c_text, i) != i) - adios ("pipe", "error writing to"); - free (c1->c_text), c1->c_text = NULL; - close (pdi[1]); - - close (pdo[1]); - cp = NULL, len = 0; - result = DONE; - while ((i = read (pdo[0], buffer, strlen (buffer))) > 0) { - if (cp) { - int j; - char *dp; - dp = mh_xrealloc (cp, (unsigned) (j = len + i)); - memcpy(dp + len, buffer, i); - cp = dp, len = j; - } - else { - cp = mh_xmalloc ((unsigned) i); - memcpy(cp, buffer, i); - len = i; - } - if (result == DONE) - for (bp = buffer + i - 1; bp >= buffer; bp--) - if (!isascii (*bp) || iscntrl (*bp)) { - result = OK; - break; + close (pdi[1]); + return NOTOK; + } + + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); + + switch (child_id) { + case NOTOK: + /* oops... fork error */ + return NOTOK; + + case OK: + /* child process */ + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + if (pdi[0] != fileno (stdin)) { + dup2 (pdi[0], fileno (stdin)); + close (pdi[0]); + } + close (pdi[1]); + close (pdo[0]); + if (pdo[1] != fileno (stdout)) { + dup2 (pdo[1], fileno (stdout)); + close (pdo[1]); + } + vecp = 0; + vec[vecp++] = r1bindex (faceproc, '/'); + vec[vecp++] = "-e"; + if (sleepsw != NOTOK) { + vec[vecp++] = "-s"; + snprintf (buffer, sizeof(buffer), "%d", sleepsw); + vec[vecp++] = buffer; + } + vec[vecp] = NULL; + execvp (faceproc, vec); + fprintf (stderr, "unable to exec "); + perror (faceproc); + _exit (-1); /* NOTREACHED */ + + default: + /* parent process */ + close (pdi[0]); + i = strlen (c1->c_text); + if (write (pdi[1], c1->c_text, i) != i) + adios ("pipe", "error writing to"); + free (c1->c_text), c1->c_text = NULL; + close (pdi[1]); + + close (pdo[1]); + cp = NULL, len = 0; + result = DONE; + while ((i = read (pdo[0], buffer, strlen (buffer))) > 0) { + if (cp) { + int j; + char *dp; + dp = mh_xrealloc (cp, (unsigned) (j = len + i)); + memcpy(dp + len, buffer, i); + cp = dp, len = j; + } else { + cp = mh_xmalloc ((unsigned) i); + memcpy(cp, buffer, i); + len = i; + } + if (result == DONE) + for (bp = buffer + i - 1; bp >= buffer; bp--) + if (!isascii (*bp) || iscntrl (*bp)) { + result = OK; + break; + } } - } - close (pdo[0]); + close (pdo[0]); /* no waiting for child... */ - if (result == OK) { /* binary */ - if (write (1, cp, len) != len) - adios ("writing", "error"); - free (cp); - } - else /* empty */ - if ((c1->c_text = cp) == NULL) - result = OK; - break; - } - - return result; + if (result == OK) { /* binary */ + if (write (1, cp, len) != len) + adios ("writing", "error"); + free (cp); + } + else /* empty */ + if ((c1->c_text = cp) == NULL) + result = OK; + break; + } + + return result; } #endif /* COMMENTED OUT */ @@ -1687,47 +1680,47 @@ doface (struct mcomp *c1) int mhlsbr (int argc, char **argv, FILE *(*action)()) { - SIGNAL_HANDLER istat = NULL, pstat = NULL, qstat = NULL; - char *cp = NULL; - struct mcomp *c1; - - switch (setjmp (mhlenv)) { - case OK: - cp = invo_name; - sleepsw = 0; /* XXX */ - bellflg = clearflg = forwflg = forwall = exitstat = 0; - digest = NULL; - ontty = NOTTY; - mhl_action = action; - - /* - * If signal is at default action, then start ignoring - * it, else let it set to its current action. - */ - if ((istat = SIGNAL (SIGINT, SIG_IGN)) != SIG_DFL) - SIGNAL (SIGINT, istat); - if ((qstat = SIGNAL (SIGQUIT, SIG_IGN)) != SIG_DFL) - SIGNAL (SIGQUIT, qstat); - pstat = SIGNAL (SIGPIPE, pipeser); - mhl (argc, argv); /* FALL THROUGH! */ - - default: - SIGNAL (SIGINT, istat); - SIGNAL (SIGQUIT, qstat); - SIGNAL (SIGPIPE, SIG_IGN);/* should probably change to block instead */ - if (ontty == PITTY) - m_pclose (); - SIGNAL (SIGPIPE, pstat); - invo_name = cp; - if (holder.c_text) { - free (holder.c_text); - holder.c_text = NULL; - } - free_queue (&msghd, &msgtl); - for (c1 = fmthd; c1; c1 = c1->c_next) - c1->c_flags &= ~HDROUTPUT; - return exitstat; - } + SIGNAL_HANDLER istat = NULL, pstat = NULL, qstat = NULL; + char *cp = NULL; + struct mcomp *c1; + + switch (setjmp (mhlenv)) { + case OK: + cp = invo_name; + sleepsw = 0; /* XXX */ + bellflg = clearflg = forwflg = forwall = exitstat = 0; + digest = NULL; + ontty = NOTTY; + mhl_action = action; + + /* + * If signal is at default action, then start ignoring + * it, else let it set to its current action. + */ + if ((istat = SIGNAL (SIGINT, SIG_IGN)) != SIG_DFL) + SIGNAL (SIGINT, istat); + if ((qstat = SIGNAL (SIGQUIT, SIG_IGN)) != SIG_DFL) + SIGNAL (SIGQUIT, qstat); + pstat = SIGNAL (SIGPIPE, pipeser); + mhl (argc, argv); /* FALL THROUGH! */ + + default: + SIGNAL (SIGINT, istat); + SIGNAL (SIGQUIT, qstat); + SIGNAL (SIGPIPE, SIG_IGN); /* should probably change to block instead */ + if (ontty == PITTY) + m_pclose (); + SIGNAL (SIGPIPE, pstat); + invo_name = cp; + if (holder.c_text) { + free (holder.c_text); + holder.c_text = NULL; + } + free_queue (&msghd, &msgtl); + for (c1 = fmthd; c1; c1 = c1->c_next) + c1->c_flags &= ~HDROUTPUT; + return exitstat; + } } #undef adios @@ -1736,86 +1729,86 @@ mhlsbr (int argc, char **argv, FILE *(*action)()) static void mhladios (char *what, char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); - mhldone (1); + va_start(ap, fmt); + advertise (what, NULL, fmt, ap); + va_end(ap); + mhldone (1); } static void mhldone (int status) { - exitstat = status; - if (mhl_action) - longjmp (mhlenv, DONE); - else - done (exitstat); + exitstat = status; + if (mhl_action) + longjmp (mhlenv, DONE); + else + done (exitstat); } -static int m_pid = NOTOK; -static int sd = NOTOK; +static int m_pid = NOTOK; +static int sd = NOTOK; static void m_popen (char *name) { - int pd[2]; - - if (mhl_action && (sd = dup (fileno (stdout))) == NOTOK) - adios ("standard output", "unable to dup()"); - - if (pipe (pd) == NOTOK) - adios ("pipe", "unable to"); - - switch (m_pid = vfork ()) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - SIGNAL (SIGINT, SIG_DFL); - SIGNAL (SIGQUIT, SIG_DFL); - - close (pd[1]); - if (pd[0] != fileno (stdin)) { - dup2 (pd[0], fileno (stdin)); - close (pd[0]); - } - execlp (name, r1bindex (name, '/'), NULL); - fprintf (stderr, "unable to exec "); - perror (name); - _exit (-1); - - default: - close (pd[0]); - if (pd[1] != fileno (stdout)) { - dup2 (pd[1], fileno (stdout)); - close (pd[1]); - } - } + int pd[2]; + + if (mhl_action && (sd = dup (fileno (stdout))) == NOTOK) + adios ("standard output", "unable to dup()"); + + if (pipe (pd) == NOTOK) + adios ("pipe", "unable to"); + + switch (m_pid = vfork ()) { + case NOTOK: + adios ("fork", "unable to"); + + case OK: + SIGNAL (SIGINT, SIG_DFL); + SIGNAL (SIGQUIT, SIG_DFL); + + close (pd[1]); + if (pd[0] != fileno (stdin)) { + dup2 (pd[0], fileno (stdin)); + close (pd[0]); + } + execlp (name, r1bindex (name, '/'), NULL); + fprintf (stderr, "unable to exec "); + perror (name); + _exit (-1); + + default: + close (pd[0]); + if (pd[1] != fileno (stdout)) { + dup2 (pd[1], fileno (stdout)); + close (pd[1]); + } + } } void m_pclose (void) { - if (m_pid == NOTOK) - return; + if (m_pid == NOTOK) + return; - if (sd != NOTOK) { - fflush (stdout); - if (dup2 (sd, fileno (stdout)) == NOTOK) - adios ("standard output", "unable to dup2()"); + if (sd != NOTOK) { + fflush (stdout); + if (dup2 (sd, fileno (stdout)) == NOTOK) + adios ("standard output", "unable to dup2()"); - clearerr (stdout); - close (sd); - sd = NOTOK; - } - else - fclose (stdout); + clearerr (stdout); + close (sd); + sd = NOTOK; + } + else + fclose (stdout); - pidwait (m_pid, OK); - m_pid = NOTOK; + pidwait (m_pid, OK); + m_pid = NOTOK; } diff --git a/uip/mhmail.c b/uip/mhmail.c index e586860..4939b02 100644 --- a/uip/mhmail.c +++ b/uip/mhmail.c @@ -1,4 +1,3 @@ - /* * mhmail.c -- simple mail program * @@ -13,23 +12,23 @@ #include static struct swit switches[] = { -#define BODYSW 0 - { "body text", 0 }, -#define CCSW 1 - { "cc addrs ...", 0 }, -#define FROMSW 2 - { "from addr", 0 }, -#define SUBJSW 3 - { "subject text", 0 }, -#define VERSIONSW 4 - { "version", 0 }, -#define HELPSW 5 - { "help", 0 }, -#define RESNDSW 6 - { "resent", -6 }, -#define QUEUESW 7 - { "queued", -6 }, - { NULL, 0 } +#define BODYSW 0 + { "body text", 0 }, +#define CCSW 1 + { "cc addrs ...", 0 }, +#define FROMSW 2 + { "from addr", 0 }, +#define SUBJSW 3 + { "subject text", 0 }, +#define VERSIONSW 4 + { "version", 0 }, +#define HELPSW 5 + { "help", 0 }, +#define RESNDSW 6 + { "resent", -6 }, +#define QUEUESW 7 + { "queued", -6 }, + { NULL, 0 } }; static char tmpfil[BUFSIZ]; @@ -43,157 +42,157 @@ static RETSIGTYPE intrser (int); int main (int argc, char **argv) { - pid_t child_id; - int status, i, iscc = 0, nvec; - int queued = 0, resent = 0, somebody; - char *cp, *tolist = NULL, *cclist = NULL, *subject = NULL; - char *from = NULL, *body = NULL, **argp, **arguments; - char *vec[5], buf[BUFSIZ]; - FILE *out; - char *tfile = NULL; + pid_t child_id; + int status, i, iscc = 0, nvec; + int queued = 0, resent = 0, somebody; + char *cp, *tolist = NULL, *cclist = NULL, *subject = NULL; + char *from = NULL, *body = NULL, **argp, **arguments; + char *vec[5], buf[BUFSIZ]; + FILE *out; + char *tfile = NULL; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - /* If no arguments, just incorporate new mail */ - if (argc == 1) { - execlp (incproc, r1bindex (incproc, '/'), NULL); - adios (incproc, "unable to exec"); - } - - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [addrs ... [switches]]", - invo_name); - print_help (buf, switches, 0); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FROMSW: - if (!(from = *argp++) || *from == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case BODYSW: - if (!(body = *argp++) || *body == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case CCSW: - iscc++; - continue; - - case SUBJSW: - if (!(subject = *argp++) || *subject == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case RESNDSW: - resent++; - continue; - - case QUEUESW: - queued++; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* foil search of user profile/context */ + if (context_foil (NULL) == -1) + done (1); + + /* If no arguments, just incorporate new mail */ + if (argc == 1) { + execlp (incproc, r1bindex (incproc, '/'), NULL); + adios (incproc, "unable to exec"); } - if (iscc) - cclist = cclist ? add (cp, add (", ", cclist)) : getcpy (cp); - else - tolist = tolist ? add (cp, add (", ", tolist)) : getcpy (cp); - } - - if (tolist == NULL) - adios (NULL, "usage: %s addrs ... [switches]", invo_name); - - tfile = m_mktemp2(NULL, invo_name, NULL, &out); - if (tfile == NULL) adios("mhmail", "unable to create temporary file"); - chmod(tfile, 0600); - strncpy (tmpfil, tfile, sizeof(tmpfil)); - - SIGNAL2 (SIGINT, intrser); - - fprintf (out, "%sTo: %s\n", resent ? "Resent-" : "", tolist); - if (cclist) - fprintf (out, "%scc: %s\n", resent ? "Resent-" : "", cclist); - if (subject) - fprintf (out, "%sSubject: %s\n", resent ? "Resent-" : "", subject); - if (from) - fprintf (out, "%sFrom: %s\n", resent ? "Resent-" : "", from); - if (!resent) - fputs ("\n", out); - - if (body) { - fprintf (out, "%s", body); - if (*body && *(body + strlen (body) - 1) != '\n') - fputs ("\n", out); - } else { - for (somebody = 0; - (i = fread (buf, sizeof(*buf), sizeof(buf), stdin)) > 0; - somebody++) - if (fwrite (buf, sizeof(*buf), i, out) != i) - adios (tmpfil, "error writing"); - if (!somebody) { - unlink (tmpfil); - done (1); + + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [addrs ... [switches]]", + invo_name); + print_help (buf, switches, 0); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FROMSW: + if (!(from = *argp++) || *from == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case BODYSW: + if (!(body = *argp++) || *body == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case CCSW: + iscc++; + continue; + + case SUBJSW: + if (!(subject = *argp++) || *subject == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case RESNDSW: + resent++; + continue; + + case QUEUESW: + queued++; + continue; + } + } + if (iscc) + cclist = cclist ? add (cp, add (", ", cclist)) : getcpy (cp); + else + tolist = tolist ? add (cp, add (", ", tolist)) : getcpy (cp); } - } - fclose (out); - - nvec = 0; - vec[nvec++] = r1bindex (postproc, '/'); - vec[nvec++] = tmpfil; - if (resent) - vec[nvec++] = "-dist"; - if (queued) - vec[nvec++] = "-queued"; - vec[nvec] = NULL; - - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - - if (child_id == NOTOK) { - /* report failure and then send it */ - adios (NULL, "unable to fork"); - } else if (child_id) { - /* parent process */ - if ((status = pidXwait(child_id, postproc))) { - fprintf (stderr, "Letter saved in dead.letter\n"); - execl ("/bin/mv", "mv", tmpfil, "dead.letter", NULL); - execl ("/usr/bin/mv", "mv", tmpfil, "dead.letter", NULL); - perror ("mv"); - _exit (-1); + + if (tolist == NULL) + adios (NULL, "usage: %s addrs ... [switches]", invo_name); + + tfile = m_mktemp2(NULL, invo_name, NULL, &out); + if (tfile == NULL) adios("mhmail", "unable to create temporary file"); + chmod(tfile, 0600); + strncpy (tmpfil, tfile, sizeof(tmpfil)); + + SIGNAL2 (SIGINT, intrser); + + fprintf (out, "%sTo: %s\n", resent ? "Resent-" : "", tolist); + if (cclist) + fprintf (out, "%scc: %s\n", resent ? "Resent-" : "", cclist); + if (subject) + fprintf (out, "%sSubject: %s\n", resent ? "Resent-" : "", subject); + if (from) + fprintf (out, "%sFrom: %s\n", resent ? "Resent-" : "", from); + if (!resent) + fputs ("\n", out); + + if (body) { + fprintf (out, "%s", body); + if (*body && *(body + strlen (body) - 1) != '\n') + fputs ("\n", out); + } else { + for (somebody = 0; + (i = fread (buf, sizeof(*buf), sizeof(buf), stdin)) > 0; + somebody++) + if (fwrite (buf, sizeof(*buf), i, out) != i) + adios (tmpfil, "error writing"); + if (!somebody) { + unlink (tmpfil); + done (1); + } } - unlink (tmpfil); - done (status ? 1 : 0); - } else { - /* child process */ - execvp (postproc, vec); - fprintf (stderr, "unable to exec "); - perror (postproc); - _exit (-1); - } - - return 0; /* dead code to satisfy the compiler */ + fclose (out); + + nvec = 0; + vec[nvec++] = r1bindex (postproc, '/'); + vec[nvec++] = tmpfil; + if (resent) + vec[nvec++] = "-dist"; + if (queued) + vec[nvec++] = "-queued"; + vec[nvec] = NULL; + + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + + if (child_id == NOTOK) { + /* report failure and then send it */ + adios (NULL, "unable to fork"); + } else if (child_id) { + /* parent process */ + if ((status = pidXwait(child_id, postproc))) { + fprintf (stderr, "Letter saved in dead.letter\n"); + execl ("/bin/mv", "mv", tmpfil, "dead.letter", NULL); + execl ("/usr/bin/mv", "mv", tmpfil, "dead.letter", NULL); + perror ("mv"); + _exit (-1); + } + unlink (tmpfil); + done (status ? 1 : 0); + } else { + /* child process */ + execvp (postproc, vec); + fprintf (stderr, "unable to exec "); + perror (postproc); + _exit (-1); + } + + return 0; /* dead code to satisfy the compiler */ } @@ -201,11 +200,11 @@ static RETSIGTYPE intrser (int i) { #ifndef RELIABLE_SIGNALS - if (i) - SIGNAL (i, SIG_IGN); + if (i) + SIGNAL (i, SIG_IGN); #endif - unlink (tmpfil); - done (i != 0 ? 1 : 0); + unlink (tmpfil); + done (i != 0 ? 1 : 0); } diff --git a/uip/mhmisc.c b/uip/mhmisc.c index 7a23139..c32157f 100644 --- a/uip/mhmisc.c +++ b/uip/mhmisc.c @@ -1,4 +1,3 @@ - /* * mhparse.c -- misc routines to process MIME messages * @@ -23,7 +22,7 @@ int ntype = 0; char *parts[NPARTS + 1]; char *types[NTYPES + 1]; -int endian = 0; /* little or big endian */ +int endian = 0; /* little or big endian */ int userrs = 0; static char *errs = NULL; @@ -43,93 +42,93 @@ void flush_errors (void); int part_ok (CT ct, int sP) { - char **ap; - int len; + char **ap; + int len; - if (npart == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype))) - return 1; + if (npart == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype))) + return 1; - for (ap = parts; *ap; ap++) { - len = strlen(*ap); - if (!strncmp (*ap, ct->c_partno, len) && - (!ct->c_partno[len] || ct->c_partno[len] == '.' )) - return 1; - } + for (ap = parts; *ap; ap++) { + len = strlen(*ap); + if (!strncmp (*ap, ct->c_partno, len) && + (!ct->c_partno[len] || ct->c_partno[len] == '.' )) + return 1; + } - return 0; + return 0; } int type_ok (CT ct, int sP) { - char **ap; - char buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + char **ap; + char buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - if (ntype == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype))) - return 1; + if (ntype == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype))) + return 1; - snprintf (buffer, sizeof(buffer), "%s/%s", ci->ci_type, ci->ci_subtype); - for (ap = types; *ap; ap++) - if (!mh_strcasecmp (*ap, ci->ci_type) || !mh_strcasecmp (*ap, buffer)) - return 1; + snprintf (buffer, sizeof(buffer), "%s/%s", ci->ci_type, ci->ci_subtype); + for (ap = types; *ap; ap++) + if (!mh_strcasecmp (*ap, ci->ci_type) || !mh_strcasecmp (*ap, buffer)) + return 1; - return 0; + return 0; } void set_endian (void) { - union { - long l; - char c[sizeof(long)]; - } un; - - un.l = 1; - endian = un.c[0] ? -1 : 1; - if (debugsw) - fprintf (stderr, "%s endian architecture\n", - endian > 0 ? "big" : "little"); + union { + long l; + char c[sizeof(long)]; + } un; + + un.l = 1; + endian = un.c[0] ? -1 : 1; + if (debugsw) + fprintf (stderr, "%s endian architecture\n", + endian > 0 ? "big" : "little"); } int make_intermediates (char *file) { - char *cp; + char *cp; - for (cp = file + 1; (cp = strchr(cp, '/')); cp++) { - struct stat st; + for (cp = file + 1; (cp = strchr(cp, '/')); cp++) { + struct stat st; - *cp = '\0'; - if (stat (file, &st) == NOTOK) { - int answer; - char *ep; - if (errno != ENOENT) { - advise (file, "error on directory"); + *cp = '\0'; + if (stat (file, &st) == NOTOK) { + int answer; + char *ep; + if (errno != ENOENT) { + advise (file, "error on directory"); losing_directory: + *cp = '/'; + return NOTOK; + } + + ep = concat ("Create directory \"", file, "\"? ", NULL); + answer = getanswer (ep); + free (ep); + + if (!answer) + goto losing_directory; + if (!makedir (file)) { + advise (NULL, "unable to create directory %s", file); + goto losing_directory; + } + } + *cp = '/'; - return NOTOK; - } - - ep = concat ("Create directory \"", file, "\"? ", NULL); - answer = getanswer (ep); - free (ep); - - if (!answer) - goto losing_directory; - if (!makedir (file)) { - advise (NULL, "unable to create directory %s", file); - goto losing_directory; - } } - *cp = '/'; - } - - return OK; + return OK; } @@ -140,98 +139,98 @@ losing_directory: void content_error (char *what, CT ct, char *fmt, ...) { - va_list arglist; - int i, len, buflen; - char *bp, buffer[BUFSIZ]; - CI ci; + va_list arglist; + int i, len, buflen; + char *bp, buffer[BUFSIZ]; + CI ci; + + bp = buffer; + buflen = sizeof(buffer); + + if (userrs && invo_name && *invo_name) { + snprintf (bp, buflen, "%s: ", invo_name); + len = strlen (bp); + bp += len; + buflen -= len; + } - bp = buffer; - buflen = sizeof(buffer); + va_start (arglist, fmt); - if (userrs && invo_name && *invo_name) { - snprintf (bp, buflen, "%s: ", invo_name); + vsnprintf (bp, buflen, fmt, arglist); len = strlen (bp); bp += len; buflen -= len; - } - va_start (arglist, fmt); + ci = &ct->c_ctinfo; - vsnprintf (bp, buflen, fmt, arglist); - len = strlen (bp); - bp += len; - buflen -= len; + if (what) { + char *s; - ci = &ct->c_ctinfo; + if (*what) { + snprintf (bp, buflen, " %s: ", what); + len = strlen (bp); + bp += len; + buflen -= len; + } - if (what) { - char *s; + if ((s = strerror (errno))) + snprintf (bp, buflen, "%s", s); + else + snprintf (bp, buflen, "Error %d", errno); - if (*what) { - snprintf (bp, buflen, " %s: ", what); - len = strlen (bp); - bp += len; - buflen -= len; + len = strlen (bp); + bp += len; + buflen -= len; } - if ((s = strerror (errno))) - snprintf (bp, buflen, "%s", s); - else - snprintf (bp, buflen, "Error %d", errno); + i = strlen (invo_name) + 2; + /* Now add content type and subtype */ + snprintf (bp, buflen, "\n%*.*s(content %s/%s", i, i, "", + ci->ci_type, ci->ci_subtype); len = strlen (bp); bp += len; buflen -= len; - } - i = strlen (invo_name) + 2; - - /* Now add content type and subtype */ - snprintf (bp, buflen, "\n%*.*s(content %s/%s", i, i, "", - ci->ci_type, ci->ci_subtype); - len = strlen (bp); - bp += len; - buflen -= len; + /* Now add the message/part number */ + if (ct->c_file) { + snprintf (bp, buflen, " in message %s", ct->c_file); + len = strlen (bp); + bp += len; + buflen -= len; + + if (ct->c_partno) { + snprintf (bp, buflen, ", part %s", ct->c_partno); + len = strlen (bp); + bp += len; + buflen -= len; + } + } - /* Now add the message/part number */ - if (ct->c_file) { - snprintf (bp, buflen, " in message %s", ct->c_file); + snprintf (bp, buflen, ")"); len = strlen (bp); bp += len; buflen -= len; - if (ct->c_partno) { - snprintf (bp, buflen, ", part %s", ct->c_partno); - len = strlen (bp); - bp += len; - buflen -= len; + if (userrs) { + *bp++ = '\n'; + *bp = '\0'; + buflen--; + + errs = add (buffer, errs); + } else { + advise (NULL, "%s", buffer); } - } - - snprintf (bp, buflen, ")"); - len = strlen (bp); - bp += len; - buflen -= len; - - if (userrs) { - *bp++ = '\n'; - *bp = '\0'; - buflen--; - - errs = add (buffer, errs); - } else { - advise (NULL, "%s", buffer); - } } void flush_errors (void) { - if (errs) { - fflush (stdout); - fprintf (stderr, "%s", errs); - free (errs); - errs = NULL; - } + if (errs) { + fflush (stdout); + fprintf (stderr, "%s", errs); + free (errs); + errs = NULL; + } } diff --git a/uip/mhoutsbr.c b/uip/mhoutsbr.c index 7e12c46..e354958 100644 --- a/uip/mhoutsbr.c +++ b/uip/mhoutsbr.c @@ -1,4 +1,3 @@ - /* * mhoutsbr.c -- routines to output MIME messages * -- given a Content structure @@ -27,38 +26,38 @@ extern int ebcdicsw; static char ebcdicsafe[0x100] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static char nib2b64[0x40+1] = @@ -91,29 +90,29 @@ static int writeBase64 (CT, FILE *); int output_message_fp (CT ct, FILE *fp, char *file) { - if (output_content (ct, fp) == NOTOK) - return NOTOK; - - if (fflush (fp)) { - advise ((file?file:""), "error writing to"); - return NOTOK; - } - return OK; + if (output_content (ct, fp) == NOTOK) + return NOTOK; + + if (fflush (fp)) { + advise ((file?file:""), "error writing to"); + return NOTOK; + } + return OK; } int output_message (CT ct, char *file) { - FILE *fp; - int status; - - if ((fp = fopen (file, "w")) == NULL) { - advise (file, "unable to open for writing"); - return NOTOK; - } - status = output_message_fp(ct, fp, file); - fclose(fp); - return status; + FILE *fp; + int status; + + if ((fp = fopen (file, "w")) == NULL) { + advise (file, "unable to open for writing"); + return NOTOK; + } + status = output_message_fp(ct, fp, file); + fclose(fp); + return status; } @@ -124,102 +123,102 @@ output_message (CT ct, char *file) static int output_content (CT ct, FILE *out) { - int result = 0; - CI ci = &ct->c_ctinfo; - - /* - * Output all header fields for this content - */ - output_headers (ct, out); - - /* - * If this is the internal content structure for a - * "message/external", then we are done with the - * headers (since it has no body). - */ - if (ct->c_ctexbody) - return OK; - - /* - * Now output the content bodies. - */ - switch (ct->c_type) { - case CT_MULTIPART: - { - struct multipart *m; - struct part *part; - - if (ct->c_rfc934) - putc ('\n', out); + int result = 0; + CI ci = &ct->c_ctinfo; + + /* + * Output all header fields for this content + */ + output_headers (ct, out); + + /* + * If this is the internal content structure for a + * "message/external", then we are done with the + * headers (since it has no body). + */ + if (ct->c_ctexbody) + return OK; + + /* + * Now output the content bodies. + */ + switch (ct->c_type) { + case CT_MULTIPART: + { + struct multipart *m; + struct part *part; + + if (ct->c_rfc934) + putc ('\n', out); + + m = (struct multipart *) ct->c_ctparams; + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; + + fprintf (out, "\n--%s\n", ci->ci_values[0]); + if (output_content (p, out) == NOTOK) + return NOTOK; + } + fprintf (out, "\n--%s--\n", ci->ci_values[0]); + } + break; - m = (struct multipart *) ct->c_ctparams; - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; + case CT_MESSAGE: + putc ('\n', out); + if (ct->c_subtype == MESSAGE_EXTERNAL) { + struct exbody *e; + + e = (struct exbody *) ct->c_ctparams; + if (output_content (e->eb_content, out) == NOTOK) + return NOTOK; + + /* output phantom body for access-type "mail-server" */ + if (e->eb_body) + writeExternalBody (ct, out); + } else { + result = write8Bit (ct, out); + } + break; - fprintf (out, "\n--%s\n", ci->ci_values[0]); - if (output_content (p, out) == NOTOK) - return NOTOK; - } - fprintf (out, "\n--%s--\n", ci->ci_values[0]); - } - break; + /* + * Handle discrete types (text/application/audio/image/video) + */ + default: + switch (ct->c_encoding) { + case CE_7BIT: + putc ('\n', out); + result = write8Bit (ct, out); + break; - case CT_MESSAGE: - putc ('\n', out); - if (ct->c_subtype == MESSAGE_EXTERNAL) { - struct exbody *e; + case CE_8BIT: + putc ('\n', out); + result = write8Bit (ct, out); + break; - e = (struct exbody *) ct->c_ctparams; - if (output_content (e->eb_content, out) == NOTOK) - return NOTOK; + case CE_QUOTED: + putc ('\n', out); + result = writeQuoted (ct, out); + break; - /* output phantom body for access-type "mail-server" */ - if (e->eb_body) - writeExternalBody (ct, out); - } else { - result = write8Bit (ct, out); - } - break; + case CE_BASE64: + putc ('\n', out); + result = writeBase64 (ct, out); + break; - /* - * Handle discrete types (text/application/audio/image/video) - */ - default: - switch (ct->c_encoding) { - case CE_7BIT: - putc ('\n', out); - result = write8Bit (ct, out); - break; - - case CE_8BIT: - putc ('\n', out); - result = write8Bit (ct, out); - break; - - case CE_QUOTED: - putc ('\n', out); - result = writeQuoted (ct, out); - break; - - case CE_BASE64: - putc ('\n', out); - result = writeBase64 (ct, out); - break; - - case CE_BINARY: - advise (NULL, "can't handle binary transfer encoding in content"); - result = NOTOK; - break; + case CE_BINARY: + advise (NULL, "can't handle binary transfer encoding in content"); + result = NOTOK; + break; - default: - advise (NULL, "unknown transfer encoding in content"); - result = NOTOK; - break; + default: + advise (NULL, "unknown transfer encoding in content"); + result = NOTOK; + break; + } + break; } - break; - } - return result; + return result; } @@ -230,13 +229,13 @@ output_content (CT ct, FILE *out) static void output_headers (CT ct, FILE *out) { - HF hp; + HF hp; - hp = ct->c_first_hf; - while (hp) { - fprintf (out, "%s:%s", hp->name, hp->value); - hp = hp->next; - } + hp = ct->c_first_hf; + while (hp) { + fprintf (out, "%s:%s", hp->name, hp->value); + hp = hp->next; + } } @@ -247,65 +246,65 @@ output_headers (CT ct, FILE *out) static int writeExternalBody (CT ct, FILE *out) { - char **ap, **ep, *cp; - struct exbody *e = (struct exbody *) ct->c_ctparams; - - putc ('\n', out); - for (cp = e->eb_body; *cp; cp++) { - CT ct2 = e->eb_content; - CI ci2 = &ct2->c_ctinfo; - - if (*cp == '\\') { - switch (*++cp) { - case 'I': - if (ct2->c_id) { - char *dp = trimcpy (ct2->c_id); - - fputs (dp, out); - free (dp); - } - continue; - - case 'N': - for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++) - if (!mh_strcasecmp (*ap, "name")) { - fprintf (out, "%s", *ep); - break; - } - continue; - - case 'T': - fprintf (out, "%s/%s", ci2->ci_type, ci2->ci_subtype); - for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++) - fprintf (out, "; %s=\"%s\"", *ap, *ep); - continue; + char **ap, **ep, *cp; + struct exbody *e = (struct exbody *) ct->c_ctparams; - case 'n': - putc ('\n', out); - continue; - - case 't': - putc ('\t', out); - continue; - - case '\0': - cp--; - break; - - case '\\': - case '"': - break; - - default: - putc ('\\', out); - break; - } + putc ('\n', out); + for (cp = e->eb_body; *cp; cp++) { + CT ct2 = e->eb_content; + CI ci2 = &ct2->c_ctinfo; + + if (*cp == '\\') { + switch (*++cp) { + case 'I': + if (ct2->c_id) { + char *dp = trimcpy (ct2->c_id); + + fputs (dp, out); + free (dp); + } + continue; + + case 'N': + for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++) + if (!mh_strcasecmp (*ap, "name")) { + fprintf (out, "%s", *ep); + break; + } + continue; + + case 'T': + fprintf (out, "%s/%s", ci2->ci_type, ci2->ci_subtype); + for (ap = ci2->ci_attrs, ep = ci2->ci_values; *ap; ap++, ep++) + fprintf (out, "; %s=\"%s\"", *ap, *ep); + continue; + + case 'n': + putc ('\n', out); + continue; + + case 't': + putc ('\t', out); + continue; + + case '\0': + cp--; + break; + + case '\\': + case '"': + break; + + default: + putc ('\\', out); + break; + } + } + putc (*cp, out); } - putc (*cp, out); - } - putc ('\n', out); + putc ('\n', out); - return OK; + return OK; } @@ -316,24 +315,24 @@ writeExternalBody (CT ct, FILE *out) static int write8Bit (CT ct, FILE *out) { - int fd; - char c, *file, buffer[BUFSIZ]; - CE ce = ct->c_cefile; - - file = NULL; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return NOTOK; - - c = '\n'; - while (fgets (buffer, sizeof(buffer) - 1, ce->ce_fp)) { - c = buffer[strlen (buffer) - 1]; - fputs (buffer, out); - } - if (c != '\n') - putc ('\n', out); + int fd; + char c, *file, buffer[BUFSIZ]; + CE ce = ct->c_cefile; + + file = NULL; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return NOTOK; + + c = '\n'; + while (fgets (buffer, sizeof(buffer) - 1, ce->ce_fp)) { + c = buffer[strlen (buffer) - 1]; + fputs (buffer, out); + } + if (c != '\n') + putc ('\n', out); - (*ct->c_ceclosefnx) (ct); - return OK; + (*ct->c_ceclosefnx) (ct); + return OK; } @@ -344,69 +343,69 @@ write8Bit (CT ct, FILE *out) static int writeQuoted (CT ct, FILE *out) { - int fd; - char *cp, *file; - char c, buffer[BUFSIZ]; - CE ce = ct->c_cefile; - - file = NULL; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return NOTOK; - - while (fgets (buffer, sizeof(buffer) - 1, ce->ce_fp)) { - int n; - - cp = buffer + strlen (buffer) - 1; - if ((c = *cp) == '\n') - *cp = '\0'; - - if (strncmp (cp = buffer, "From ", sizeof("From ") - 1) == 0) { - fprintf (out, "=%02X", *cp++ & 0xff); - n = 3; - } else { - n = 0; - } - for (; *cp; cp++) { - if (n > CPERLIN - 3) { - fputs ("=\n", out); - n = 0; - } - - switch (*cp) { - case ' ': - case '\t': - putc (*cp, out); - n++; - break; + int fd; + char *cp, *file; + char c, buffer[BUFSIZ]; + CE ce = ct->c_cefile; - default: - if (*cp < '!' || *cp > '~' - || (ebcdicsw && !ebcdicsafe[*cp & 0xff])) - goto three_print; - putc (*cp, out); - n++; - break; - - case '=': + file = NULL; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return NOTOK; + + while (fgets (buffer, sizeof(buffer) - 1, ce->ce_fp)) { + int n; + + cp = buffer + strlen (buffer) - 1; + if ((c = *cp) == '\n') + *cp = '\0'; + + if (strncmp (cp = buffer, "From ", sizeof("From ") - 1) == 0) { + fprintf (out, "=%02X", *cp++ & 0xff); + n = 3; + } else { + n = 0; + } + for (; *cp; cp++) { + if (n > CPERLIN - 3) { + fputs ("=\n", out); + n = 0; + } + + switch (*cp) { + case ' ': + case '\t': + putc (*cp, out); + n++; + break; + + default: + if (*cp < '!' || *cp > '~' + || (ebcdicsw && !ebcdicsafe[*cp & 0xff])) + goto three_print; + putc (*cp, out); + n++; + break; + + case '=': three_print: - fprintf (out, "=%02X", *cp & 0xff); - n += 3; - break; - } - } + fprintf (out, "=%02X", *cp & 0xff); + n += 3; + break; + } + } - if (c == '\n') { - if (cp > buffer && (*--cp == ' ' || *cp == '\t')) - fputs ("=\n", out); + if (c == '\n') { + if (cp > buffer && (*--cp == ' ' || *cp == '\t')) + fputs ("=\n", out); - putc ('\n', out); - } else { - fputs ("=\n", out); + putc ('\n', out); + } else { + fputs ("=\n", out); + } } - } - (*ct->c_ceclosefnx) (ct); - return OK; + (*ct->c_ceclosefnx) (ct); + return OK; } @@ -417,63 +416,63 @@ three_print: static int writeBase64 (CT ct, FILE *out) { - int fd, result; - char *file; - CE ce = ct->c_cefile; + int fd, result; + char *file; + CE ce = ct->c_cefile; - file = NULL; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return NOTOK; + file = NULL; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return NOTOK; - result = writeBase64aux (ce->ce_fp, out); - (*ct->c_ceclosefnx) (ct); - return result; + result = writeBase64aux (ce->ce_fp, out); + (*ct->c_ceclosefnx) (ct); + return result; } int writeBase64aux (FILE *in, FILE *out) { - int cc, n; - char inbuf[3]; - - n = BPERLIN; - while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) { - unsigned long bits; - char *bp; - char outbuf[4]; - - if (cc < sizeof(inbuf)) { - inbuf[2] = 0; - if (cc < sizeof(inbuf) - 1) - inbuf[1] = 0; - } - bits = (inbuf[0] & 0xff) << 16; - bits |= (inbuf[1] & 0xff) << 8; - bits |= inbuf[2] & 0xff; - - for (bp = outbuf + sizeof(outbuf); bp > outbuf; bits >>= 6) - *--bp = nib2b64[bits & 0x3f]; - if (cc < sizeof(inbuf)) { - outbuf[3] = '='; - if (cc < sizeof inbuf - 1) - outbuf[2] = '='; - } + int cc, n; + char inbuf[3]; + + n = BPERLIN; + while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) { + unsigned long bits; + char *bp; + char outbuf[4]; + + if (cc < sizeof(inbuf)) { + inbuf[2] = 0; + if (cc < sizeof(inbuf) - 1) + inbuf[1] = 0; + } + bits = (inbuf[0] & 0xff) << 16; + bits |= (inbuf[1] & 0xff) << 8; + bits |= inbuf[2] & 0xff; + + for (bp = outbuf + sizeof(outbuf); bp > outbuf; bits >>= 6) + *--bp = nib2b64[bits & 0x3f]; + if (cc < sizeof(inbuf)) { + outbuf[3] = '='; + if (cc < sizeof inbuf - 1) + outbuf[2] = '='; + } - fwrite (outbuf, sizeof(*outbuf), sizeof(outbuf), out); + fwrite (outbuf, sizeof(*outbuf), sizeof(outbuf), out); - if (cc < sizeof(inbuf)) { - putc ('\n', out); - return OK; - } + if (cc < sizeof(inbuf)) { + putc ('\n', out); + return OK; + } - if (--n <= 0) { - n = BPERLIN; - putc ('\n', out); + if (--n <= 0) { + n = BPERLIN; + putc ('\n', out); + } } - } - if (n != BPERLIN) - putc ('\n', out); + if (n != BPERLIN) + putc ('\n', out); - return OK; + return OK; } diff --git a/uip/mhparam.c b/uip/mhparam.c index eae587d..328ea6b 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -1,4 +1,3 @@ - /* * mhparam.c -- print mh_profile values * @@ -16,57 +15,57 @@ extern char *mhlibdir; extern char *mhetcdir; static struct swit switches[] = { -#define COMPSW 0 - { "components", 0 }, -#define NCOMPSW 1 - { "nocomponents", 0 }, -#define ALLSW 2 - { "all", 0 }, +#define COMPSW 0 + { "components", 0 }, +#define NCOMPSW 1 + { "nocomponents", 0 }, +#define ALLSW 2 + { "all", 0 }, #define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, + { "version", 0 }, +#define HELPSW 4 + { "help", 0 }, #define DEBUGSW 5 - { "debug", -5 }, - { NULL, 0 } + { "debug", -5 }, + { NULL, 0 } }; struct proc { - char *p_name; - char **p_field; + char *p_name; + char **p_field; }; static struct proc procs [] = { - { "context", &context }, - { "mh-sequences", &mh_seq }, - { "buildmimeproc", &buildmimeproc }, - { "editor", &defaulteditor }, - { "faceproc", &faceproc }, - { "fileproc", &fileproc }, - { "foldprot", &foldprot }, - { "incproc", &incproc }, - { "installproc", &installproc }, - { "lproc", &lproc }, - { "mailproc", &mailproc }, - { "mhlproc", &mhlproc }, - { "moreproc", &moreproc }, - { "msgprot", &msgprot }, - { "packproc", &packproc }, - { "postproc", &postproc }, - { "rmfproc", &rmfproc }, - { "rmmproc", &rmmproc }, - { "sendmail", &sendmail }, - { "sendproc", &sendproc }, - { "showmimeproc", &showmimeproc }, - { "showproc", &showproc }, - { "version", &version_num }, - { "whatnowproc", &whatnowproc }, - { "whomproc", &whomproc }, - { "etcdir", &mhetcdir }, - { "libdir", &mhlibdir }, - { "backup-prefix", &backup_prefix }, - { "altmsg-link", &altmsglink }, - { NULL, NULL }, + { "context", &context }, + { "mh-sequences", &mh_seq }, + { "buildmimeproc", &buildmimeproc }, + { "editor", &defaulteditor }, + { "faceproc", &faceproc }, + { "fileproc", &fileproc }, + { "foldprot", &foldprot }, + { "incproc", &incproc }, + { "installproc", &installproc }, + { "lproc", &lproc }, + { "mailproc", &mailproc }, + { "mhlproc", &mhlproc }, + { "moreproc", &moreproc }, + { "msgprot", &msgprot }, + { "packproc", &packproc }, + { "postproc", &postproc }, + { "rmfproc", &rmfproc }, + { "rmmproc", &rmmproc }, + { "sendmail", &sendmail }, + { "sendproc", &sendproc }, + { "showmimeproc", &showmimeproc }, + { "showproc", &showproc }, + { "version", &version_num }, + { "whatnowproc", &whatnowproc }, + { "whomproc", &whomproc }, + { "etcdir", &mhetcdir }, + { "libdir", &mhlibdir }, + { "backup-prefix", &backup_prefix }, + { "altmsg-link", &altmsglink }, + { NULL, NULL }, }; @@ -79,116 +78,116 @@ static char *p_find(char *); int main(int argc, char **argv) { - int i, compp = 0, missed = 0; - int all = 0, debug = 0; - int components = -1; - char *cp, buf[BUFSIZ], **argp; - char **arguments, *comps[MAXARGS]; - - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [profile-components] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case COMPSW: - components = 1; - break; - case NCOMPSW: - components = 0; - break; - - case ALLSW: - all = 1; - break; - - case DEBUGSW: - debug = 1; - break; - } - } else { - comps[compp++] = cp; + int i, compp = 0, missed = 0; + int all = 0, debug = 0; + int components = -1; + char *cp, buf[BUFSIZ], **argp; + char **arguments, *comps[MAXARGS]; + + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [profile-components] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case COMPSW: + components = 1; + break; + case NCOMPSW: + components = 0; + break; + + case ALLSW: + all = 1; + break; + + case DEBUGSW: + debug = 1; + break; + } + } else { + comps[compp++] = cp; + } } - } - - if (all) { - struct node *np; - if (compp) - advise(NULL, "profile-components ignored with -all"); + if (all) { + struct node *np; - if (components >= 0) - advise(NULL, "-%scomponents ignored with -all", - components ? "" : "no"); + if (compp) + advise(NULL, "profile-components ignored with -all"); - /* print all entries in context/profile list */ - for (np = m_defs; np; np = np->n_next) - printf("%s: %s\n", np->n_name, np->n_field); + if (components >= 0) + advise(NULL, "-%scomponents ignored with -all", + components ? "" : "no"); - } else if (debug) { - struct proc *ps; - - /* - * Print the current value of everything in - * procs array. This will show their current - * value (as determined after context is read). - */ - for (ps = procs; ps->p_name; ps++) - printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : ""); + /* print all entries in context/profile list */ + for (np = m_defs; np; np = np->n_next) + printf("%s: %s\n", np->n_name, np->n_field); - } else { - if (components < 0) - components = compp > 1; + } else if (debug) { + struct proc *ps; - for (i = 0; i < compp; i++) { - register char *value; + /* + * Print the current value of everything in + * procs array. This will show their current + * value (as determined after context is read). + */ + for (ps = procs; ps->p_name; ps++) + printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : ""); - value = context_find (comps[i]); - if (!value) - value = p_find (comps[i]); - if (value) { - if (components) - printf("%s: ", comps[i]); - - printf("%s\n", value); - } else - missed++; + } else { + if (components < 0) + components = compp > 1; + + for (i = 0; i < compp; i++) { + register char *value; + + value = context_find (comps[i]); + if (!value) + value = p_find (comps[i]); + if (value) { + if (components) + printf("%s: ", comps[i]); + + printf("%s\n", value); + } else + missed++; + } } - } - - done (missed); - return 1; + + done (missed); + return 1; } static char * p_find(char *str) { - struct proc *ps; + struct proc *ps; - for (ps = procs; ps->p_name; ps++) - if (!mh_strcasecmp (ps->p_name, str)) - return (*ps->p_field); + for (ps = procs; ps->p_name; ps++) + if (!mh_strcasecmp (ps->p_name, str)) + return (*ps->p_field); - return NULL; + return NULL; } diff --git a/uip/mhparse.c b/uip/mhparse.c index d40d78c..c72c415 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -1,4 +1,3 @@ - /* * mhparse.c -- routines to parse the contents of MIME messages * @@ -27,15 +26,15 @@ extern int debugsw; -extern int endian; /* mhmisc.c */ +extern int endian; /* mhmisc.c */ -extern pid_t xpid; /* mhshowsbr.c */ +extern pid_t xpid; /* mhshowsbr.c */ /* cache policies */ -extern int rcachesw; /* mhcachesbr.c */ -extern int wcachesw; /* mhcachesbr.c */ +extern int rcachesw; /* mhcachesbr.c */ +extern int wcachesw; /* mhcachesbr.c */ -int checksw = 0; /* check Content-MD5 field */ +int checksw = 0; /* check Content-MD5 field */ /* * Directory to place temp files. This must @@ -47,46 +46,46 @@ char *tmp; * Structures for TEXT messages */ struct k2v SubText[] = { - { "plain", TEXT_PLAIN }, - { "richtext", TEXT_RICHTEXT }, /* defined in RFC-1341 */ - { "enriched", TEXT_ENRICHED }, /* defined in RFC-1896 */ - { NULL, TEXT_UNKNOWN } /* this one must be last! */ + { "plain", TEXT_PLAIN }, + { "richtext", TEXT_RICHTEXT }, /* defined in RFC-1341 */ + { "enriched", TEXT_ENRICHED }, /* defined in RFC-1896 */ + { NULL, TEXT_UNKNOWN } /* this one must be last! */ }; struct k2v Charset[] = { - { "us-ascii", CHARSET_USASCII }, - { "iso-8859-1", CHARSET_LATIN }, - { NULL, CHARSET_UNKNOWN } /* this one must be last! */ + { "us-ascii", CHARSET_USASCII }, + { "iso-8859-1", CHARSET_LATIN }, + { NULL, CHARSET_UNKNOWN } /* this one must be last! */ }; /* * Structures for MULTIPART messages */ struct k2v SubMultiPart[] = { - { "mixed", MULTI_MIXED }, - { "alternative", MULTI_ALTERNATE }, - { "digest", MULTI_DIGEST }, - { "parallel", MULTI_PARALLEL }, - { NULL, MULTI_UNKNOWN } /* this one must be last! */ + { "mixed", MULTI_MIXED }, + { "alternative", MULTI_ALTERNATE }, + { "digest", MULTI_DIGEST }, + { "parallel", MULTI_PARALLEL }, + { NULL, MULTI_UNKNOWN } /* this one must be last! */ }; /* * Structures for MESSAGE messages */ struct k2v SubMessage[] = { - { "rfc822", MESSAGE_RFC822 }, - { "partial", MESSAGE_PARTIAL }, - { "external-body", MESSAGE_EXTERNAL }, - { NULL, MESSAGE_UNKNOWN } /* this one must be last! */ + { "rfc822", MESSAGE_RFC822 }, + { "partial", MESSAGE_PARTIAL }, + { "external-body", MESSAGE_EXTERNAL }, + { NULL, MESSAGE_UNKNOWN } /* this one must be last! */ }; /* * Structure for APPLICATION messages */ struct k2v SubApplication[] = { - { "octet-stream", APPLICATION_OCTETS }, - { "postscript", APPLICATION_POSTSCRIPT }, - { NULL, APPLICATION_UNKNOWN } /* this one must be last! */ + { "octet-stream", APPLICATION_OCTETS }, + { "postscript", APPLICATION_POSTSCRIPT }, + { NULL, APPLICATION_UNKNOWN } /* this one must be last! */ }; @@ -135,25 +134,25 @@ static int openMail (CT, char **); static int readDigest (CT, char *); struct str2init str2cts[] = { - { "application", CT_APPLICATION, InitApplication }, - { "audio", CT_AUDIO, InitGeneric }, - { "image", CT_IMAGE, InitGeneric }, - { "message", CT_MESSAGE, InitMessage }, - { "multipart", CT_MULTIPART, InitMultiPart }, - { "text", CT_TEXT, InitText }, - { "video", CT_VIDEO, InitGeneric }, - { NULL, CT_EXTENSION, NULL }, /* these two must be last! */ - { NULL, CT_UNKNOWN, NULL }, + { "application", CT_APPLICATION, InitApplication }, + { "audio", CT_AUDIO, InitGeneric }, + { "image", CT_IMAGE, InitGeneric }, + { "message", CT_MESSAGE, InitMessage }, + { "multipart", CT_MULTIPART, InitMultiPart }, + { "text", CT_TEXT, InitText }, + { "video", CT_VIDEO, InitGeneric }, + { NULL, CT_EXTENSION, NULL }, /* these two must be last! */ + { NULL, CT_UNKNOWN, NULL }, }; struct str2init str2ces[] = { - { "base64", CE_BASE64, InitBase64 }, - { "quoted-printable", CE_QUOTED, InitQuoted }, - { "8bit", CE_8BIT, Init7Bit }, - { "7bit", CE_7BIT, Init7Bit }, - { "binary", CE_BINARY, Init7Bit }, - { NULL, CE_EXTENSION, NULL }, /* these two must be last! */ - { NULL, CE_UNKNOWN, NULL }, + { "base64", CE_BASE64, InitBase64 }, + { "quoted-printable", CE_QUOTED, InitQuoted }, + { "8bit", CE_8BIT, Init7Bit }, + { "7bit", CE_7BIT, Init7Bit }, + { "binary", CE_BINARY, Init7Bit }, + { NULL, CE_EXTENSION, NULL }, /* these two must be last! */ + { NULL, CE_UNKNOWN, NULL }, }; /* @@ -162,25 +161,25 @@ struct str2init str2ces[] = { * si_key is 1 if access method is anonymous. */ struct str2init str2methods[] = { - { "afs", 1, InitFile }, - { "anon-ftp", 1, InitFTP }, - { "ftp", 0, InitFTP }, - { "local-file", 0, InitFile }, - { "mail-server", 0, InitMail }, - { NULL, 0, NULL } + { "afs", 1, InitFile }, + { "anon-ftp", 1, InitFTP }, + { "ftp", 0, InitFTP }, + { "local-file", 0, InitFile }, + { "mail-server", 0, InitMail }, + { NULL, 0, NULL } }; int pidcheck (int status) { - if ((status & 0xff00) == 0xff00 || (status & 0x007f) != SIGQUIT) - return status; + if ((status & 0xff00) == 0xff00 || (status & 0x007f) != SIGQUIT) + return status; - fflush (stdout); - fflush (stderr); - done (1); - return 1; + fflush (stdout); + fflush (stderr); + done (1); + return 1; } @@ -189,72 +188,71 @@ pidcheck (int status) * It returns the Content structure for the top level * entity in the file. */ - CT parse_mime (char *file) { - int is_stdin; - char buffer[BUFSIZ]; - FILE *fp; - CT ct; - - /* - * Check if file is actually standard input - */ - if ((is_stdin = !(strcmp (file, "-")))) { - char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) { - advise("mhparse", "unable to create temporary file"); - return NULL; - } - file = add (tfile, NULL); - chmod (file, 0600); - - while (fgets (buffer, sizeof(buffer), stdin)) - fputs (buffer, fp); - fflush (fp); - - if (ferror (stdin)) { - unlink (file); - advise ("stdin", "error reading"); - return NULL; - } - if (ferror (fp)) { - unlink (file); - advise (file, "error writing"); - return NULL; - } - fseek (fp, 0L, SEEK_SET); - } else if ((fp = fopen (file, "r")) == NULL) { - advise (file, "unable to read"); - return NULL; - } + int is_stdin; + char buffer[BUFSIZ]; + FILE *fp; + CT ct; + + /* + * Check if file is actually standard input + */ + if ((is_stdin = !(strcmp (file, "-")))) { + char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp); + if (tfile == NULL) { + advise("mhparse", "unable to create temporary file"); + return NULL; + } + file = add (tfile, NULL); + chmod (file, 0600); + + while (fgets (buffer, sizeof(buffer), stdin)) + fputs (buffer, fp); + fflush (fp); + + if (ferror (stdin)) { + unlink (file); + advise ("stdin", "error reading"); + return NULL; + } + if (ferror (fp)) { + unlink (file); + advise (file, "error writing"); + return NULL; + } + fseek (fp, 0L, SEEK_SET); + } else if ((fp = fopen (file, "r")) == NULL) { + advise (file, "unable to read"); + return NULL; + } + + if (!(ct = get_content (fp, file, 1))) { + if (is_stdin) + unlink (file); + advise (NULL, "unable to decode %s", file); + return NULL; + } - if (!(ct = get_content (fp, file, 1))) { if (is_stdin) - unlink (file); - advise (NULL, "unable to decode %s", file); - return NULL; - } + ct->c_unlink = 1; /* temp file to remove */ - if (is_stdin) - ct->c_unlink = 1; /* temp file to remove */ + ct->c_fp = NULL; - ct->c_fp = NULL; + if (ct->c_end == 0L) { + fseek (fp, 0L, SEEK_END); + ct->c_end = ftell (fp); + } - if (ct->c_end == 0L) { - fseek (fp, 0L, SEEK_END); - ct->c_end = ftell (fp); - } + if (ct->c_ctinitfnx && (*ct->c_ctinitfnx) (ct) == NOTOK) { + fclose (fp); + free_content (ct); + return NULL; + } - if (ct->c_ctinitfnx && (*ct->c_ctinitfnx) (ct) == NOTOK) { fclose (fp); - free_content (ct); - return NULL; - } - - fclose (fp); - return ct; + return ct; } @@ -272,286 +270,286 @@ parse_mime (char *file) static CT get_content (FILE *in, char *file, int toplevel) { - int compnum, state; - char buf[BUFSIZ], name[NAMESZ]; - char *np, *vp; - CT ct; - HF hp; - - /* allocate the content structure */ - if (!(ct = (CT) calloc (1, sizeof(*ct)))) - adios (NULL, "out of memory"); - - ct->c_fp = in; - ct->c_file = add (file, NULL); - ct->c_begin = ftell (ct->c_fp) + 1; - - /* - * Parse the header fields for this - * content into a linked list. - */ - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { - case FLD: - case FLDPLUS: - case FLDEOF: - compnum++; - - /* get copies of the buffers */ - np = add (name, NULL); - vp = add (buf, NULL); - - /* if necessary, get rest of field */ - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); - vp = add (buf, vp); /* add to previous value */ - } - - /* Now add the header data to the list */ - add_header (ct, np, vp); - - /* continue, if this isn't the last header field */ - if (state != FLDEOF) { - ct->c_begin = ftell (in) + 1; - continue; - } - /* else fall... */ - - case BODY: - case BODYEOF: - ct->c_begin = ftell (in) - strlen (buf); - break; - - case FILEEOF: - ct->c_begin = ftell (in); - break; - - case LENERR: - case FMTERR: - adios (NULL, "message format error in component #%d", compnum); - - default: - adios (NULL, "getfld() returned %d", state); - } - - /* break out of the loop */ - break; - } - - /* - * Read the content headers. We will parse the - * MIME related header fields into their various - * structures and set internal flags related to - * content type/subtype, etc. - */ - - hp = ct->c_first_hf; /* start at first header field */ - while (hp) { - /* Get MIME-Version field */ - if (!mh_strcasecmp (hp->name, VRSN_FIELD)) { - int ucmp; - char c; - unsigned char *cp, *dp; - - if (ct->c_vrsn) { - advise (NULL, "message %s has multiple %s: fields", - ct->c_file, VRSN_FIELD); - goto next_header; - } - ct->c_vrsn = add (hp->value, NULL); - - /* Now, cleanup this field */ - cp = ct->c_vrsn; - - while (isspace (*cp)) - cp++; - for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) - *dp++ = ' '; - for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) - if (!isspace (*dp)) - break; - *++dp = '\0'; - if (debugsw) - fprintf (stderr, "%s: %s\n", VRSN_FIELD, cp); + int compnum, state; + char buf[BUFSIZ], name[NAMESZ]; + char *np, *vp; + CT ct; + HF hp; + + /* allocate the content structure */ + if (!(ct = (CT) calloc (1, sizeof(*ct)))) + adios (NULL, "out of memory"); - if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) - goto out; + ct->c_fp = in; + ct->c_file = add (file, NULL); + ct->c_begin = ftell (ct->c_fp) + 1; - for (dp = cp; istoken (*dp); dp++) - continue; - c = *dp; - *dp = '\0'; - ucmp = !mh_strcasecmp (cp, VRSN_VALUE); - *dp = c; - if (!ucmp) { - admonish (NULL, "message %s has unknown value for %s: field (%s)", - ct->c_file, VRSN_FIELD, cp); - } - } - else if (!mh_strcasecmp (hp->name, TYPE_FIELD)) { - /* Get Content-Type field */ - struct str2init *s2i; - CI ci = &ct->c_ctinfo; - - /* Check if we've already seen a Content-Type header */ - if (ct->c_ctline) { - advise (NULL, "message %s has multiple %s: fields", - ct->c_file, TYPE_FIELD); - goto next_header; - } - - /* Parse the Content-Type field */ - if (get_ctinfo (hp->value, ct, 0) == NOTOK) - goto out; - - /* - * Set the Init function and the internal - * flag for this content type. - */ - for (s2i = str2cts; s2i->si_key; s2i++) - if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) - break; - if (!s2i->si_key && !uprf (ci->ci_type, "X-")) - s2i++; - ct->c_type = s2i->si_val; - ct->c_ctinitfnx = s2i->si_init; - } - else if (!mh_strcasecmp (hp->name, ENCODING_FIELD)) { - /* Get Content-Transfer-Encoding field */ - char c; - unsigned char *cp, *dp; - struct str2init *s2i; - - /* - * Check if we've already seen the - * Content-Transfer-Encoding field - */ - if (ct->c_celine) { - advise (NULL, "message %s has multiple %s: fields", - ct->c_file, ENCODING_FIELD); - goto next_header; - } - - /* get copy of this field */ - ct->c_celine = cp = add (hp->value, NULL); - - while (isspace (*cp)) - cp++; - for (dp = cp; istoken (*dp); dp++) - continue; - c = *dp; - *dp = '\0'; - - /* - * Find the internal flag and Init function - * for this transfer encoding. - */ - for (s2i = str2ces; s2i->si_key; s2i++) - if (!mh_strcasecmp (cp, s2i->si_key)) - break; - if (!s2i->si_key && !uprf (cp, "X-")) - s2i++; - *dp = c; - ct->c_encoding = s2i->si_val; - - /* Call the Init function for this encoding */ - if (s2i->si_init && (*s2i->si_init) (ct) == NOTOK) - goto out; - } - else if (!mh_strcasecmp (hp->name, MD5_FIELD)) { - /* Get Content-MD5 field */ - unsigned char *cp, *dp; - char *ep; - - if (!checksw) - goto next_header; - - if (ct->c_digested) { - advise (NULL, "message %s has multiple %s: fields", - ct->c_file, MD5_FIELD); - goto next_header; - } - - ep = cp = add (hp->value, NULL); /* get a copy */ - - while (isspace (*cp)) - cp++; - for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) - *dp++ = ' '; - for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) - if (!isspace (*dp)) - break; - *++dp = '\0'; - if (debugsw) - fprintf (stderr, "%s: %s\n", MD5_FIELD, cp); + /* + * Parse the header fields for this + * content into a linked list. + */ + for (compnum = 1, state = FLD;;) { + switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + case FLD: + case FLDPLUS: + case FLDEOF: + compnum++; + + /* get copies of the buffers */ + np = add (name, NULL); + vp = add (buf, NULL); + + /* if necessary, get rest of field */ + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), in); + vp = add (buf, vp); /* add to previous value */ + } - if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) { - free (ep); - goto out; - } + /* Now add the header data to the list */ + add_header (ct, np, vp); - for (dp = cp; *dp && !isspace (*dp); dp++) - continue; - *dp = '\0'; + /* continue, if this isn't the last header field */ + if (state != FLDEOF) { + ct->c_begin = ftell (in) + 1; + continue; + } + /* else fall... */ - readDigest (ct, cp); - free (ep); - ct->c_digested++; - } - else if (!mh_strcasecmp (hp->name, ID_FIELD)) { - /* Get Content-ID field */ - ct->c_id = add (hp->value, ct->c_id); - } - else if (!mh_strcasecmp (hp->name, DESCR_FIELD)) { - /* Get Content-Description field */ - ct->c_descr = add (hp->value, ct->c_descr); - } - else if (!mh_strcasecmp (hp->name, DISPO_FIELD)) { - /* Get Content-Disposition field */ - ct->c_dispo = add (hp->value, ct->c_dispo); + case BODY: + case BODYEOF: + ct->c_begin = ftell (in) - strlen (buf); + break; + + case FILEEOF: + ct->c_begin = ftell (in); + break; + + case LENERR: + case FMTERR: + adios (NULL, "message format error in component #%d", compnum); + + default: + adios (NULL, "getfld() returned %d", state); + } + + /* break out of the loop */ + break; } + /* + * Read the content headers. We will parse the + * MIME related header fields into their various + * structures and set internal flags related to + * content type/subtype, etc. + */ + + hp = ct->c_first_hf; /* start at first header field */ + while (hp) { + /* Get MIME-Version field */ + if (!mh_strcasecmp (hp->name, VRSN_FIELD)) { + int ucmp; + char c; + unsigned char *cp, *dp; + + if (ct->c_vrsn) { + advise (NULL, "message %s has multiple %s: fields", + ct->c_file, VRSN_FIELD); + goto next_header; + } + ct->c_vrsn = add (hp->value, NULL); + + /* Now, cleanup this field */ + cp = ct->c_vrsn; + + while (isspace (*cp)) + cp++; + for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) + *dp++ = ' '; + for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) + if (!isspace (*dp)) + break; + *++dp = '\0'; + if (debugsw) + fprintf (stderr, "%s: %s\n", VRSN_FIELD, cp); + + if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) + goto out; + + for (dp = cp; istoken (*dp); dp++) + continue; + c = *dp; + *dp = '\0'; + ucmp = !mh_strcasecmp (cp, VRSN_VALUE); + *dp = c; + if (!ucmp) { + admonish (NULL, "message %s has unknown value for %s: field (%s)", + ct->c_file, VRSN_FIELD, cp); + } + } + else if (!mh_strcasecmp (hp->name, TYPE_FIELD)) { + /* Get Content-Type field */ + struct str2init *s2i; + CI ci = &ct->c_ctinfo; + + /* Check if we've already seen a Content-Type header */ + if (ct->c_ctline) { + advise (NULL, "message %s has multiple %s: fields", + ct->c_file, TYPE_FIELD); + goto next_header; + } + + /* Parse the Content-Type field */ + if (get_ctinfo (hp->value, ct, 0) == NOTOK) + goto out; + + /* + * Set the Init function and the internal + * flag for this content type. + */ + for (s2i = str2cts; s2i->si_key; s2i++) + if (!mh_strcasecmp (ci->ci_type, s2i->si_key)) + break; + if (!s2i->si_key && !uprf (ci->ci_type, "X-")) + s2i++; + ct->c_type = s2i->si_val; + ct->c_ctinitfnx = s2i->si_init; + } + else if (!mh_strcasecmp (hp->name, ENCODING_FIELD)) { + /* Get Content-Transfer-Encoding field */ + char c; + unsigned char *cp, *dp; + struct str2init *s2i; + + /* + * Check if we've already seen the + * Content-Transfer-Encoding field + */ + if (ct->c_celine) { + advise (NULL, "message %s has multiple %s: fields", + ct->c_file, ENCODING_FIELD); + goto next_header; + } + + /* get copy of this field */ + ct->c_celine = cp = add (hp->value, NULL); + + while (isspace (*cp)) + cp++; + for (dp = cp; istoken (*dp); dp++) + continue; + c = *dp; + *dp = '\0'; + + /* + * Find the internal flag and Init function + * for this transfer encoding. + */ + for (s2i = str2ces; s2i->si_key; s2i++) + if (!mh_strcasecmp (cp, s2i->si_key)) + break; + if (!s2i->si_key && !uprf (cp, "X-")) + s2i++; + *dp = c; + ct->c_encoding = s2i->si_val; + + /* Call the Init function for this encoding */ + if (s2i->si_init && (*s2i->si_init) (ct) == NOTOK) + goto out; + } + else if (!mh_strcasecmp (hp->name, MD5_FIELD)) { + /* Get Content-MD5 field */ + unsigned char *cp, *dp; + char *ep; + + if (!checksw) + goto next_header; + + if (ct->c_digested) { + advise (NULL, "message %s has multiple %s: fields", + ct->c_file, MD5_FIELD); + goto next_header; + } + + ep = cp = add (hp->value, NULL); /* get a copy */ + + while (isspace (*cp)) + cp++; + for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) + *dp++ = ' '; + for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) + if (!isspace (*dp)) + break; + *++dp = '\0'; + if (debugsw) + fprintf (stderr, "%s: %s\n", MD5_FIELD, cp); + + if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) { + free (ep); + goto out; + } + + for (dp = cp; *dp && !isspace (*dp); dp++) + continue; + *dp = '\0'; + + readDigest (ct, cp); + free (ep); + ct->c_digested++; + } + else if (!mh_strcasecmp (hp->name, ID_FIELD)) { + /* Get Content-ID field */ + ct->c_id = add (hp->value, ct->c_id); + } + else if (!mh_strcasecmp (hp->name, DESCR_FIELD)) { + /* Get Content-Description field */ + ct->c_descr = add (hp->value, ct->c_descr); + } + else if (!mh_strcasecmp (hp->name, DISPO_FIELD)) { + /* Get Content-Disposition field */ + ct->c_dispo = add (hp->value, ct->c_dispo); + } + next_header: - hp = hp->next; /* next header field */ - } - - /* - * Check if we saw a Content-Type field. - * If not, then assign a default value for - * it, and the Init function. - */ - if (!ct->c_ctline) { + hp = hp->next; /* next header field */ + } + /* - * If we are inside a multipart/digest message, - * so default type is message/rfc822 + * Check if we saw a Content-Type field. + * If not, then assign a default value for + * it, and the Init function. */ - if (toplevel < 0) { - if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK) - goto out; - ct->c_type = CT_MESSAGE; - ct->c_ctinitfnx = InitMessage; - } else { - /* - * Else default type is text/plain - */ - if (get_ctinfo ("text/plain", ct, 0) == NOTOK) - goto out; - ct->c_type = CT_TEXT; - ct->c_ctinitfnx = InitText; + if (!ct->c_ctline) { + /* + * If we are inside a multipart/digest message, + * so default type is message/rfc822 + */ + if (toplevel < 0) { + if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK) + goto out; + ct->c_type = CT_MESSAGE; + ct->c_ctinitfnx = InitMessage; + } else { + /* + * Else default type is text/plain + */ + if (get_ctinfo ("text/plain", ct, 0) == NOTOK) + goto out; + ct->c_type = CT_TEXT; + ct->c_ctinitfnx = InitText; + } } - } - /* Use default Transfer-Encoding, if necessary */ - if (!ct->c_celine) { - ct->c_encoding = CE_7BIT; - Init7Bit (ct); - } + /* Use default Transfer-Encoding, if necessary */ + if (!ct->c_celine) { + ct->c_encoding = CE_7BIT; + Init7Bit (ct); + } - return ct; + return ct; out: - free_content (ct); - return NULL; + free_content (ct); + return NULL; } @@ -562,110 +560,109 @@ out: int add_header (CT ct, char *name, char *value) { - HF hp; - - /* allocate header field structure */ - hp = mh_xmalloc (sizeof(*hp)); - - /* link data into header structure */ - hp->name = name; - hp->value = value; - hp->next = NULL; - - /* link header structure into the list */ - if (ct->c_first_hf == NULL) { - ct->c_first_hf = hp; /* this is the first */ - ct->c_last_hf = hp; - } else { - ct->c_last_hf->next = hp; /* add it to the end */ - ct->c_last_hf = hp; - } - - return 0; + HF hp; + + /* allocate header field structure */ + hp = mh_xmalloc (sizeof(*hp)); + + /* link data into header structure */ + hp->name = name; + hp->value = value; + hp->next = NULL; + + /* link header structure into the list */ + if (ct->c_first_hf == NULL) { + ct->c_first_hf = hp; /* this is the first */ + ct->c_last_hf = hp; + } else { + ct->c_last_hf->next = hp; /* add it to the end */ + ct->c_last_hf = hp; + } + + return 0; } /* Make sure that buf contains at least one appearance of name, followed by =. If not, insert both name and value, just after first semicolon, if any. Note that name should not contain a - trailing =. And quotes will be added around the value. Typical + trailing =. And quotes will be added around the value. Typical usage: make sure that a Content-Disposition header contains filename="foo". If it doesn't and value does, use value from that. */ static char * incl_name_value (unsigned char *buf, char *name, char *value) { - char *newbuf = buf; - - /* Assume that name is non-null. */ - if (buf && value) { - char *name_plus_equal = concat (name, "=", NULL); - - if (! strstr (buf, name_plus_equal)) { - char *insertion; - unsigned char *cp; - char *prefix, *suffix; - - /* Trim trailing space, esp. newline. */ - for (cp = &buf[strlen (buf) - 1]; - cp >= buf && isspace (*cp); - --cp) { - *cp = '\0'; - } - - insertion = concat ("; ", name, "=", "\"", value, "\"", NULL); - - /* Insert at first semicolon, if any. If none, append to - end. */ - prefix = add (buf, NULL); - if ((cp = strchr (prefix, ';'))) { - suffix = concat (cp, NULL); - *cp = '\0'; - newbuf = concat (prefix, insertion, suffix, "\n", NULL); - free (suffix); - } else { - /* Append to end. */ - newbuf = concat (buf, insertion, "\n", NULL); - } - - free (prefix); - free (insertion); - free (buf); - } - - free (name_plus_equal); - } - - return newbuf; + char *newbuf = buf; + + /* Assume that name is non-null. */ + if (buf && value) { + char *name_plus_equal = concat (name, "=", NULL); + + if (! strstr (buf, name_plus_equal)) { + char *insertion; + unsigned char *cp; + char *prefix, *suffix; + + /* Trim trailing space, esp. newline. */ + for (cp = &buf[strlen (buf) - 1]; + cp >= buf && isspace (*cp); + --cp) { + *cp = '\0'; + } + + insertion = concat ("; ", name, "=", "\"", value, "\"", NULL); + + /* Insert at first semicolon, if any. If none, append to + end. */ + prefix = add (buf, NULL); + if ((cp = strchr (prefix, ';'))) { + suffix = concat (cp, NULL); + *cp = '\0'; + newbuf = concat (prefix, insertion, suffix, "\n", NULL); + free (suffix); + } else { + /* Append to end. */ + newbuf = concat (buf, insertion, "\n", NULL); + } + + free (prefix); + free (insertion); + free (buf); + } + + free (name_plus_equal); + } + + return newbuf; } -/* Extract just name_suffix="foo", if any, from value. If there isn't +/* Extract just name_suffix="foo", if any, from value. If there isn't one, return the entire value. Note that, for example, a name_suffix of name will match filename="foo", and return foo. */ static char * extract_name_value (char *name_suffix, char *value) { - char *extracted_name_value = value; - char *name_suffix_plus_quote = concat (name_suffix, "=\"", NULL); - char *name_suffix_equals = strstr (value, name_suffix_plus_quote); - char *cp; - - free (name_suffix_plus_quote); - if (name_suffix_equals) { - char *name_suffix_begin; - - /* Find first \". */ - for (cp = name_suffix_equals; *cp != '"'; ++cp) /* empty */; - name_suffix_begin = ++cp; - /* Find second \". */ - for (; *cp != '"'; ++cp) /* empty */; - - extracted_name_value = mh_xmalloc (cp - name_suffix_begin + 1); - memcpy (extracted_name_value, - name_suffix_begin, - cp - name_suffix_begin); - extracted_name_value[cp - name_suffix_begin] = '\0'; - } - - return extracted_name_value; + char *extracted_name_value = value; + char *name_suffix_plus_quote = concat (name_suffix, "=\"", NULL); + char *name_suffix_equals = strstr (value, name_suffix_plus_quote); + char *cp; + + free (name_suffix_plus_quote); + if (name_suffix_equals) { + char *name_suffix_begin; + + /* Find first \". */ + for (cp = name_suffix_equals; *cp != '"'; ++cp) /* empty */; + name_suffix_begin = ++cp; + /* Find second \". */ + for (; *cp != '"'; ++cp) /* empty */; + + extracted_name_value = mh_xmalloc (cp - name_suffix_begin + 1); + memcpy (extracted_name_value, name_suffix_begin, + cp - name_suffix_begin); + extracted_name_value[cp - name_suffix_begin] = '\0'; + } + + return extracted_name_value; } /* @@ -675,364 +672,359 @@ extract_name_value (char *name_suffix, char *value) { int get_ctinfo (unsigned char *cp, CT ct, int magic) { - int i; - unsigned char *dp; - char **ap, **ep; - char c; - CI ci; + int i; + unsigned char *dp; + char **ap, **ep; + char c; + CI ci; - ci = &ct->c_ctinfo; - i = strlen (invo_name) + 2; + ci = &ct->c_ctinfo; + i = strlen (invo_name) + 2; - /* store copy of Content-Type line */ - cp = ct->c_ctline = add (cp, NULL); + /* store copy of Content-Type line */ + cp = ct->c_ctline = add (cp, NULL); - while (isspace (*cp)) /* trim leading spaces */ - cp++; + while (isspace (*cp)) /* trim leading spaces */ + cp++; - /* change newlines to spaces */ - for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) - *dp++ = ' '; + /* change newlines to spaces */ + for (dp = strchr(cp, '\n'); dp; dp = strchr(dp, '\n')) + *dp++ = ' '; - /* trim trailing spaces */ - for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) - if (!isspace (*dp)) - break; - *++dp = '\0'; + /* trim trailing spaces */ + for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) + if (!isspace (*dp)) + break; + *++dp = '\0'; - if (debugsw) - fprintf (stderr, "%s: %s\n", TYPE_FIELD, cp); + if (debugsw) + fprintf (stderr, "%s: %s\n", TYPE_FIELD, cp); - if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; + if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) + return NOTOK; - for (dp = cp; istoken (*dp); dp++) - continue; - c = *dp, *dp = '\0'; - ci->ci_type = add (cp, NULL); /* store content type */ - *dp = c, cp = dp; + for (dp = cp; istoken (*dp); dp++) + continue; + c = *dp, *dp = '\0'; + ci->ci_type = add (cp, NULL); /* store content type */ + *dp = c, cp = dp; - if (!*ci->ci_type) { - advise (NULL, "invalid %s: field in message %s (empty type)", - TYPE_FIELD, ct->c_file); - return NOTOK; - } + if (!*ci->ci_type) { + advise (NULL, "invalid %s: field in message %s (empty type)", + TYPE_FIELD, ct->c_file); + return NOTOK; + } - /* down case the content type string */ - for (dp = ci->ci_type; *dp; dp++) - if (isalpha(*dp) && isupper (*dp)) - *dp = tolower (*dp); + /* down case the content type string */ + for (dp = ci->ci_type; *dp; dp++) + if (isalpha(*dp) && isupper (*dp)) + *dp = tolower (*dp); - while (isspace (*cp)) - cp++; + while (isspace (*cp)) + cp++; - if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; + if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) + return NOTOK; - if (*cp != '/') { - if (!magic) - ci->ci_subtype = add ("", NULL); - goto magic_skip; - } + if (*cp != '/') { + if (!magic) + ci->ci_subtype = add ("", NULL); + goto magic_skip; + } - cp++; - while (isspace (*cp)) cp++; + while (isspace (*cp)) + cp++; - if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; - - for (dp = cp; istoken (*dp); dp++) - continue; - c = *dp, *dp = '\0'; - ci->ci_subtype = add (cp, NULL); /* store the content subtype */ - *dp = c, cp = dp; + if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) + return NOTOK; - if (!*ci->ci_subtype) { - advise (NULL, - "invalid %s: field in message %s (empty subtype for \"%s\")", - TYPE_FIELD, ct->c_file, ci->ci_type); - return NOTOK; - } + for (dp = cp; istoken (*dp); dp++) + continue; + c = *dp, *dp = '\0'; + ci->ci_subtype = add (cp, NULL); /* store the content subtype */ + *dp = c, cp = dp; + + if (!*ci->ci_subtype) { + advise (NULL, + "invalid %s: field in message %s (empty subtype for \"%s\")", + TYPE_FIELD, ct->c_file, ci->ci_type); + return NOTOK; + } - /* down case the content subtype string */ - for (dp = ci->ci_subtype; *dp; dp++) - if (isalpha(*dp) && isupper (*dp)) - *dp = tolower (*dp); + /* down case the content subtype string */ + for (dp = ci->ci_subtype; *dp; dp++) + if (isalpha(*dp) && isupper (*dp)) + *dp = tolower (*dp); magic_skip: - while (isspace (*cp)) - cp++; - - if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; - - /* - * Parse attribute/value pairs given with Content-Type - */ - ep = (ap = ci->ci_attrs) + NPARMS; - while (*cp == ';') { - char *vp; - unsigned char *up; - - if (ap >= ep) { - advise (NULL, - "too many parameters in message %s's %s: field (%d max)", - ct->c_file, TYPE_FIELD, NPARMS); - return NOTOK; - } - - cp++; while (isspace (*cp)) - cp++; + cp++; if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; + return NOTOK; - if (*cp == 0) { - advise (NULL, - "extraneous trailing ';' in message %s's %s: parameter list", - ct->c_file, TYPE_FIELD); - return OK; - } + /* + * Parse attribute/value pairs given with Content-Type + */ + ep = (ap = ci->ci_attrs) + NPARMS; + while (*cp == ';') { + char *vp; + unsigned char *up; + + if (ap >= ep) { + advise (NULL, + "too many parameters in message %s's %s: field (%d max)", + ct->c_file, TYPE_FIELD, NPARMS); + return NOTOK; + } - /* down case the attribute name */ - for (dp = cp; istoken (*dp); dp++) - if (isalpha(*dp) && isupper (*dp)) - *dp = tolower (*dp); + cp++; + while (isspace (*cp)) + cp++; - for (up = dp; isspace (*dp);) - dp++; - if (dp == cp || *dp != '=') { - advise (NULL, - "invalid parameter in message %s's %s: field\n%*.*sparameter %s (error detected at offset %d)", - ct->c_file, TYPE_FIELD, i, i, "", cp, dp - cp); - return NOTOK; - } + if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) + return NOTOK; + + if (*cp == 0) { + advise (NULL, + "extraneous trailing ';' in message %s's %s: parameter list", + ct->c_file, TYPE_FIELD); + return OK; + } - vp = (*ap = add (cp, NULL)) + (up - cp); - *vp = '\0'; - for (dp++; isspace (*dp);) - dp++; + /* down case the attribute name */ + for (dp = cp; istoken (*dp); dp++) + if (isalpha(*dp) && isupper (*dp)) + *dp = tolower (*dp); + + for (up = dp; isspace (*dp);) + dp++; + if (dp == cp || *dp != '=') { + advise (NULL, + "invalid parameter in message %s's %s: field\n%*.*sparameter %s (error detected at offset %d)", + ct->c_file, TYPE_FIELD, i, i, "", cp, dp - cp); + return NOTOK; + } - /* now add the attribute value */ - ci->ci_values[ap - ci->ci_attrs] = vp = *ap + (dp - cp); + vp = (*ap = add (cp, NULL)) + (up - cp); + *vp = '\0'; + for (dp++; isspace (*dp);) + dp++; - if (*dp == '"') { - for (cp = ++dp, dp = vp;;) { - switch (c = *cp++) { - case '\0': + /* now add the attribute value */ + ci->ci_values[ap - ci->ci_attrs] = vp = *ap + (dp - cp); + + if (*dp == '"') { + for (cp = ++dp, dp = vp;;) { + switch (c = *cp++) { + case '\0': bad_quote: - advise (NULL, - "invalid quoted-string in message %s's %s: field\n%*.*s(parameter %s)", + advise (NULL, + "invalid quoted-string in message %s's %s: field\n%*.*s(parameter %s)", + ct->c_file, TYPE_FIELD, i, i, "", *ap); + return NOTOK; + + case '\\': + *dp++ = c; + if ((c = *cp++) == '\0') + goto bad_quote; + /* else fall... */ + + default: + *dp++ = c; + continue; + + case '"': + *dp = '\0'; + break; + } + break; + } + } else { + for (cp = dp, dp = vp; istoken (*cp); cp++, dp++) + continue; + *dp = '\0'; + } + if (!*vp) { + advise (NULL, + "invalid parameter in message %s's %s: field\n%*.*s(parameter %s)", ct->c_file, TYPE_FIELD, i, i, "", *ap); return NOTOK; + } + ap++; - case '\\': - *dp++ = c; - if ((c = *cp++) == '\0') - goto bad_quote; - /* else fall... */ + while (isspace (*cp)) + cp++; - default: - *dp++ = c; - continue; + if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) + return NOTOK; + } - case '"': - *dp = '\0'; - break; + /* + * Get any given in buffer + */ + if (magic && *cp == '<') { + if (ct->c_id) { + free (ct->c_id); + ct->c_id = NULL; } - break; - } - } else { - for (cp = dp, dp = vp; istoken (*cp); cp++, dp++) - continue; - *dp = '\0'; - } - if (!*vp) { - advise (NULL, - "invalid parameter in message %s's %s: field\n%*.*s(parameter %s)", - ct->c_file, TYPE_FIELD, i, i, "", *ap); - return NOTOK; + if (!(dp = strchr(ct->c_id = ++cp, '>'))) { + advise (NULL, "invalid ID in message %s", ct->c_file); + return NOTOK; + } + c = *dp; + *dp = '\0'; + if (*ct->c_id) + ct->c_id = concat ("<", ct->c_id, ">\n", NULL); + else + ct->c_id = NULL; + *dp++ = c; + cp = dp; + + while (isspace (*cp)) + cp++; } - ap++; - while (isspace (*cp)) - cp++; + /* + * Get any [Content-Description] given in buffer. + */ + if (magic && *cp == '[') { + ct->c_descr = ++cp; + for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) + if (*dp == ']') + break; + if (dp < cp) { + advise (NULL, "invalid description in message %s", ct->c_file); + ct->c_descr = NULL; + return NOTOK; + } - if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK) - return NOTOK; - } - - /* - * Get any given in buffer - */ - if (magic && *cp == '<') { - if (ct->c_id) { - free (ct->c_id); - ct->c_id = NULL; - } - if (!(dp = strchr(ct->c_id = ++cp, '>'))) { - advise (NULL, "invalid ID in message %s", ct->c_file); - return NOTOK; - } - c = *dp; - *dp = '\0'; - if (*ct->c_id) - ct->c_id = concat ("<", ct->c_id, ">\n", NULL); - else - ct->c_id = NULL; - *dp++ = c; - cp = dp; + c = *dp; + *dp = '\0'; + if (*ct->c_descr) + ct->c_descr = concat (ct->c_descr, "\n", NULL); + else + ct->c_descr = NULL; + *dp++ = c; + cp = dp; - while (isspace (*cp)) - cp++; - } - - /* - * Get any [Content-Description] given in buffer. - */ - if (magic && *cp == '[') { - ct->c_descr = ++cp; - for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) - if (*dp == ']') - break; - if (dp < cp) { - advise (NULL, "invalid description in message %s", ct->c_file); - ct->c_descr = NULL; - return NOTOK; - } - - c = *dp; - *dp = '\0'; - if (*ct->c_descr) - ct->c_descr = concat (ct->c_descr, "\n", NULL); - else - ct->c_descr = NULL; - *dp++ = c; - cp = dp; + while (isspace (*cp)) + cp++; + } - while (isspace (*cp)) - cp++; - } - - /* - * Get any {Content-Disposition} given in buffer. - */ - if (magic && *cp == '{') { - ct->c_dispo = ++cp; - for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) - if (*dp == '}') - break; - if (dp < cp) { - advise (NULL, "invalid disposition in message %s", ct->c_file); - ct->c_dispo = NULL; - return NOTOK; - } - - c = *dp; - *dp = '\0'; - if (*ct->c_dispo) - ct->c_dispo = concat (ct->c_dispo, "\n", NULL); - else - ct->c_dispo = NULL; - *dp++ = c; - cp = dp; + /* + * Get any {Content-Disposition} given in buffer. + */ + if (magic && *cp == '{') { + ct->c_dispo = ++cp; + for (dp = cp + strlen (cp) - 1; dp >= cp; dp--) + if (*dp == '}') + break; + if (dp < cp) { + advise (NULL, "invalid disposition in message %s", ct->c_file); + ct->c_dispo = NULL; + return NOTOK; + } - while (isspace (*cp)) - cp++; - } - - /* - * Check if anything is left over - */ - if (*cp) { - if (magic) { - ci->ci_magic = add (cp, NULL); - - /* If there is a Content-Disposition header and it doesn't - have a *filename=, extract it from the magic contents. - The r1bindex call skips any leading directory - components. */ - if (ct->c_dispo) - ct->c_dispo = - incl_name_value (ct->c_dispo, - "filename", - r1bindex (extract_name_value ("name", - ci-> - ci_magic), - '/')); - } - else - advise (NULL, - "extraneous information in message %s's %s: field\n%*.*s(%s)", - ct->c_file, TYPE_FIELD, i, i, "", cp); - } + c = *dp; + *dp = '\0'; + if (*ct->c_dispo) + ct->c_dispo = concat (ct->c_dispo, "\n", NULL); + else + ct->c_dispo = NULL; + *dp++ = c; + cp = dp; + + while (isspace (*cp)) + cp++; + } + + /* + * Check if anything is left over + */ + if (*cp) { + if (magic) { + ci->ci_magic = add (cp, NULL); + + /* + * If there is a Content-Disposition header and + * it doesn't have a *filename=, extract it from + * the magic contents. The r1bindex call skips + * any leading directory components. + */ + if (ct->c_dispo) + ct->c_dispo = incl_name_value (ct->c_dispo, "filename", r1bindex (extract_name_value ("name", ci->ci_magic), '/')); + } else + advise (NULL, + "extraneous information in message %s's %s: field\n%*.*s(%s)", + ct->c_file, TYPE_FIELD, i, i, "", cp); + } - return OK; + return OK; } static int get_comment (CT ct, unsigned char **ap, int istype) { - int i; - char *bp; - unsigned char *cp; - char c, buffer[BUFSIZ], *dp; - CI ci; - - ci = &ct->c_ctinfo; - cp = *ap; - bp = buffer; - cp++; - - for (i = 0;;) { - switch (c = *cp++) { - case '\0': + int i; + char *bp; + unsigned char *cp; + char c, buffer[BUFSIZ], *dp; + CI ci; + + ci = &ct->c_ctinfo; + cp = *ap; + bp = buffer; + cp++; + + for (i = 0;;) { + switch (c = *cp++) { + case '\0': invalid: - advise (NULL, "invalid comment in message %s's %s: field", - ct->c_file, istype ? TYPE_FIELD : VRSN_FIELD); - return NOTOK; + advise (NULL, "invalid comment in message %s's %s: field", + ct->c_file, istype ? TYPE_FIELD : VRSN_FIELD); + return NOTOK; + + case '\\': + *bp++ = c; + if ((c = *cp++) == '\0') + goto invalid; + *bp++ = c; + continue; + + case '(': + i++; + /* and fall... */ + default: + *bp++ = c; + continue; - case '\\': - *bp++ = c; - if ((c = *cp++) == '\0') - goto invalid; - *bp++ = c; - continue; - - case '(': - i++; - /* and fall... */ - default: - *bp++ = c; - continue; - - case ')': - if (--i < 0) + case ')': + if (--i < 0) + break; + *bp++ = c; + continue; + } break; - *bp++ = c; - continue; } - break; - } - *bp = '\0'; + *bp = '\0'; - if (istype) { - if ((dp = ci->ci_comment)) { - ci->ci_comment = concat (dp, " ", buffer, NULL); - free (dp); - } else { - ci->ci_comment = add (buffer, NULL); + if (istype) { + if ((dp = ci->ci_comment)) { + ci->ci_comment = concat (dp, " ", buffer, NULL); + free (dp); + } else { + ci->ci_comment = add (buffer, NULL); + } } - } - while (isspace (*cp)) - cp++; + while (isspace (*cp)) + cp++; - *ap = cp; - return OK; + *ap = cp; + return OK; } @@ -1046,7 +1038,7 @@ invalid: static int InitGeneric (CT ct) { - return OK; /* not much to do here */ + return OK; /* not much to do here */ } @@ -1057,255 +1049,255 @@ InitGeneric (CT ct) static int InitText (CT ct) { - char buffer[BUFSIZ]; - char *chset = NULL; - char **ap, **ep, *cp; - struct k2v *kv; - struct text *t; - CI ci = &ct->c_ctinfo; - - /* check for missing subtype */ - if (!*ci->ci_subtype) - ci->ci_subtype = add ("plain", ci->ci_subtype); - - /* match subtype */ - for (kv = SubText; kv->kv_key; kv++) - if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) - break; - ct->c_subtype = kv->kv_value; - - /* allocate text character set structure */ - if ((t = (struct text *) calloc (1, sizeof(*t))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) t; - - /* scan for charset parameter */ - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) - if (!mh_strcasecmp (*ap, "charset")) - break; - - /* check if content specified a character set */ - if (*ap) { - /* match character set or set to CHARSET_UNKNOWN */ - for (kv = Charset; kv->kv_key; kv++) { - if (!mh_strcasecmp (*ep, kv->kv_key)) { - chset = *ep; - break; - } - } - t->tx_charset = kv->kv_value; - } else { - t->tx_charset = CHARSET_UNSPECIFIED; - } - - /* - * If we can not handle character set natively, - * then check profile for string to modify the - * terminal or display method. - * - * termproc is for mhshow, though mhlist -debug prints it, too. - */ - if (chset != NULL && !check_charset (chset, strlen (chset))) { - snprintf (buffer, sizeof(buffer), "%s-charset-%s", invo_name, chset); - if ((cp = context_find (buffer))) - ct->c_termproc = getcpy (cp); - } - - return OK; -} - + char buffer[BUFSIZ]; + char *chset = NULL; + char **ap, **ep, *cp; + struct k2v *kv; + struct text *t; + CI ci = &ct->c_ctinfo; -/* - * MULTIPART - */ + /* check for missing subtype */ + if (!*ci->ci_subtype) + ci->ci_subtype = add ("plain", ci->ci_subtype); -static int -InitMultiPart (CT ct) -{ - int inout; - long last, pos; - unsigned char *cp, *dp; - char **ap, **ep; - char *bp, buffer[BUFSIZ]; - struct multipart *m; - struct k2v *kv; - struct part *part, **next; - CI ci = &ct->c_ctinfo; - CT p; - FILE *fp; - - /* - * The encoding for multipart messages must be either - * 7bit, 8bit, or binary (per RFC2045). - */ - if (ct->c_encoding != CE_7BIT && ct->c_encoding != CE_8BIT - && ct->c_encoding != CE_BINARY) { - admonish (NULL, - "\"%s/%s\" type in message %s must be encoded in 7bit, 8bit, or binary", - ci->ci_type, ci->ci_subtype, ct->c_file); - return NOTOK; - } - - /* match subtype */ - for (kv = SubMultiPart; kv->kv_key; kv++) - if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) - break; - ct->c_subtype = kv->kv_value; - - /* - * Check for "boundary" parameter, which is - * required for multipart messages. - */ - bp = 0; - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - if (!mh_strcasecmp (*ap, "boundary")) { - bp = *ep; - break; - } - } - - /* complain if boundary parameter is missing */ - if (!*ap) { - advise (NULL, - "a \"boundary\" parameter is mandatory for \"%s/%s\" type in message %s's %s: field", - ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); - return NOTOK; - } - - /* allocate primary structure for multipart info */ - if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) m; - - /* check if boundary parameter contains only whitespace characters */ - for (cp = bp; isspace (*cp); cp++) - continue; - if (!*cp) { - advise (NULL, "invalid \"boundary\" parameter for \"%s/%s\" type in message %s's %s: field", - ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); - return NOTOK; - } + /* match subtype */ + for (kv = SubText; kv->kv_key; kv++) + if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) + break; + ct->c_subtype = kv->kv_value; - /* remove trailing whitespace from boundary parameter */ - for (cp = bp, dp = cp + strlen (cp) - 1; dp > cp; dp--) - if (!isspace (*dp)) - break; - *++dp = '\0'; + /* allocate text character set structure */ + if ((t = (struct text *) calloc (1, sizeof(*t))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) t; - /* record boundary separators */ - m->mp_start = concat (bp, "\n", NULL); - m->mp_stop = concat (bp, "--\n", NULL); + /* scan for charset parameter */ + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) + if (!mh_strcasecmp (*ap, "charset")) + break; - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - advise (ct->c_file, "unable to open for reading"); - return NOTOK; - } - - fseek (fp = ct->c_fp, pos = ct->c_begin, SEEK_SET); - last = ct->c_end; - next = &m->mp_parts; - part = NULL; - inout = 1; - - while (fgets (buffer, sizeof(buffer) - 1, fp)) { - if (pos > last) - break; - - pos += strlen (buffer); - if (buffer[0] != '-' || buffer[1] != '-') - continue; - if (inout) { - if (strcmp (buffer + 2, m->mp_start)) - continue; -next_part: - if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + /* check if content specified a character set */ + if (*ap) { + /* match character set or set to CHARSET_UNKNOWN */ + for (kv = Charset; kv->kv_key; kv++) { + if (!mh_strcasecmp (*ep, kv->kv_key)) { + chset = *ep; + break; + } + } + t->tx_charset = kv->kv_value; + } else { + t->tx_charset = CHARSET_UNSPECIFIED; + } + + /* + * If we can not handle character set natively, + * then check profile for string to modify the + * terminal or display method. + * + * termproc is for mhshow, though mhlist -debug prints it, too. + */ + if (chset != NULL && !check_charset (chset, strlen (chset))) { + snprintf (buffer, sizeof(buffer), "%s-charset-%s", invo_name, chset); + if ((cp = context_find (buffer))) + ct->c_termproc = getcpy (cp); + } + + return OK; +} + + +/* + * MULTIPART + */ + +static int +InitMultiPart (CT ct) +{ + int inout; + long last, pos; + unsigned char *cp, *dp; + char **ap, **ep; + char *bp, buffer[BUFSIZ]; + struct multipart *m; + struct k2v *kv; + struct part *part, **next; + CI ci = &ct->c_ctinfo; + CT p; + FILE *fp; + + /* + * The encoding for multipart messages must be either + * 7bit, 8bit, or binary (per RFC2045). + */ + if (ct->c_encoding != CE_7BIT && ct->c_encoding != CE_8BIT + && ct->c_encoding != CE_BINARY) { + admonish (NULL, + "\"%s/%s\" type in message %s must be encoded in 7bit, 8bit, or binary", + ci->ci_type, ci->ci_subtype, ct->c_file); + return NOTOK; + } + + /* match subtype */ + for (kv = SubMultiPart; kv->kv_key; kv++) + if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) + break; + ct->c_subtype = kv->kv_value; + + /* + * Check for "boundary" parameter, which is + * required for multipart messages. + */ + bp = 0; + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + if (!mh_strcasecmp (*ap, "boundary")) { + bp = *ep; + break; + } + } + + /* complain if boundary parameter is missing */ + if (!*ap) { + advise (NULL, + "a \"boundary\" parameter is mandatory for \"%s/%s\" type in message %s's %s: field", + ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); + return NOTOK; + } + + /* allocate primary structure for multipart info */ + if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL) adios (NULL, "out of memory"); - *next = part; - next = &part->mp_next; + ct->c_ctparams = (void *) m; - if (!(p = get_content (fp, ct->c_file, - ct->c_subtype == MULTI_DIGEST ? -1 : 0))) { - ct->c_fp = NULL; + /* check if boundary parameter contains only whitespace characters */ + for (cp = bp; isspace (*cp); cp++) + continue; + if (!*cp) { + advise (NULL, "invalid \"boundary\" parameter for \"%s/%s\" type in message %s's %s: field", + ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); return NOTOK; - } - p->c_fp = NULL; - part->mp_part = p; - pos = p->c_begin; - fseek (fp, pos, SEEK_SET); - inout = 0; - } else { - if (strcmp (buffer + 2, m->mp_start) == 0) { - inout = 1; + } + + /* remove trailing whitespace from boundary parameter */ + for (cp = bp, dp = cp + strlen (cp) - 1; dp > cp; dp--) + if (!isspace (*dp)) + break; + *++dp = '\0'; + + /* record boundary separators */ + m->mp_start = concat (bp, "\n", NULL); + m->mp_stop = concat (bp, "--\n", NULL); + + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + advise (ct->c_file, "unable to open for reading"); + return NOTOK; + } + + fseek (fp = ct->c_fp, pos = ct->c_begin, SEEK_SET); + last = ct->c_end; + next = &m->mp_parts; + part = NULL; + inout = 1; + + while (fgets (buffer, sizeof(buffer) - 1, fp)) { + if (pos > last) + break; + + pos += strlen (buffer); + if (buffer[0] != '-' || buffer[1] != '-') + continue; + if (inout) { + if (strcmp (buffer + 2, m->mp_start)) + continue; +next_part: + if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL) + adios (NULL, "out of memory"); + *next = part; + next = &part->mp_next; + + if (!(p = get_content (fp, ct->c_file, + ct->c_subtype == MULTI_DIGEST ? -1 : 0))) { + ct->c_fp = NULL; + return NOTOK; + } + p->c_fp = NULL; + part->mp_part = p; + pos = p->c_begin; + fseek (fp, pos, SEEK_SET); + inout = 0; + } else { + if (strcmp (buffer + 2, m->mp_start) == 0) { + inout = 1; end_part: + p = part->mp_part; + p->c_end = ftell(fp) - (strlen(buffer) + 1); + if (p->c_end < p->c_begin) + p->c_begin = p->c_end; + if (inout) + goto next_part; + goto last_part; + } else { + if (strcmp (buffer + 2, m->mp_stop) == 0) + goto end_part; + } + } + } + + advise (NULL, "bogus multipart content in message %s", ct->c_file); + if (!inout && part) { p = part->mp_part; - p->c_end = ftell(fp) - (strlen(buffer) + 1); - if (p->c_end < p->c_begin) - p->c_begin = p->c_end; - if (inout) - goto next_part; - goto last_part; - } else { - if (strcmp (buffer + 2, m->mp_stop) == 0) - goto end_part; - } - } - } - - advise (NULL, "bogus multipart content in message %s", ct->c_file); - if (!inout && part) { - p = part->mp_part; - p->c_end = ct->c_end; - - if (p->c_begin >= p->c_end) { - for (next = &m->mp_parts; *next != part; - next = &((*next)->mp_next)) - continue; - *next = NULL; - free_content (p); - free ((char *) part); + p->c_end = ct->c_end; + + if (p->c_begin >= p->c_end) { + for (next = &m->mp_parts; *next != part; + next = &((*next)->mp_next)) + continue; + *next = NULL; + free_content (p); + free ((char *) part); + } } - } last_part: - /* reverse the order of the parts for multipart/alternative */ - if (ct->c_subtype == MULTI_ALTERNATE) - reverse_parts (ct); - - /* - * label all subparts with part number, and - * then initialize the content of the subpart. - */ - { - int partnum; - char *pp; - char partnam[BUFSIZ]; - - if (ct->c_partno) { - snprintf (partnam, sizeof(partnam), "%s.", ct->c_partno); - pp = partnam + strlen (partnam); - } else { - pp = partnam; - } + /* reverse the order of the parts for multipart/alternative */ + if (ct->c_subtype == MULTI_ALTERNATE) + reverse_parts (ct); - for (part = m->mp_parts, partnum = 1; part; - part = part->mp_next, partnum++) { - p = part->mp_part; + /* + * label all subparts with part number, and + * then initialize the content of the subpart. + */ + { + int partnum; + char *pp; + char partnam[BUFSIZ]; + + if (ct->c_partno) { + snprintf (partnam, sizeof(partnam), "%s.", ct->c_partno); + pp = partnam + strlen (partnam); + } else { + pp = partnam; + } - sprintf (pp, "%d", partnum); - p->c_partno = add (partnam, NULL); + for (part = m->mp_parts, partnum = 1; part; + part = part->mp_next, partnum++) { + p = part->mp_part; - /* initialize the content of the subparts */ - if (p->c_ctinitfnx && (*p->c_ctinitfnx) (p) == NOTOK) { - fclose (ct->c_fp); - ct->c_fp = NULL; - return NOTOK; - } + sprintf (pp, "%d", partnum); + p->c_partno = add (partnam, NULL); + + /* initialize the content of the subparts */ + if (p->c_ctinitfnx && (*p->c_ctinitfnx) (p) == NOTOK) { + fclose (ct->c_fp); + ct->c_fp = NULL; + return NOTOK; + } + } } - } - fclose (ct->c_fp); - ct->c_fp = NULL; - return OK; + fclose (ct->c_fp); + ct->c_fp = NULL; + return OK; } @@ -1316,42 +1308,42 @@ last_part: static void reverse_parts (CT ct) { - int i; - struct multipart *m; - struct part **base, **bmp, **next, *part; - - m = (struct multipart *) ct->c_ctparams; - - /* if only one part, just return */ - if (!m->mp_parts || !m->mp_parts->mp_next) - return; - - /* count number of parts */ - i = 0; - for (part = m->mp_parts; part; part = part->mp_next) - i++; - - /* allocate array of pointers to the parts */ - if (!(base = (struct part **) calloc ((size_t) (i + 1), sizeof(*base)))) - adios (NULL, "out of memory"); - bmp = base; - - /* point at all the parts */ - for (part = m->mp_parts; part; part = part->mp_next) - *bmp++ = part; - *bmp = NULL; - - /* reverse the order of the parts */ - next = &m->mp_parts; - for (bmp--; bmp >= base; bmp--) { - part = *bmp; - *next = part; - next = &part->mp_next; - } - *next = NULL; - - /* free array of pointers */ - free ((char *) base); + int i; + struct multipart *m; + struct part **base, **bmp, **next, *part; + + m = (struct multipart *) ct->c_ctparams; + + /* if only one part, just return */ + if (!m->mp_parts || !m->mp_parts->mp_next) + return; + + /* count number of parts */ + i = 0; + for (part = m->mp_parts; part; part = part->mp_next) + i++; + + /* allocate array of pointers to the parts */ + if (!(base = (struct part **) calloc ((size_t) (i + 1), sizeof(*base)))) + adios (NULL, "out of memory"); + bmp = base; + + /* point at all the parts */ + for (part = m->mp_parts; part; part = part->mp_next) + *bmp++ = part; + *bmp = NULL; + + /* reverse the order of the parts */ + next = &m->mp_parts; + for (bmp--; bmp >= base; bmp--) { + part = *bmp; + *next = part; + next = &part->mp_next; + } + *next = NULL; + + /* free array of pointers */ + free ((char *) base); } @@ -1362,245 +1354,242 @@ reverse_parts (CT ct) static int InitMessage (CT ct) { - struct k2v *kv; - CI ci = &ct->c_ctinfo; - - if ((ct->c_encoding != CE_7BIT) && (ct->c_encoding != CE_8BIT)) { - admonish (NULL, - "\"%s/%s\" type in message %s should be encoded in 7bit or 8bit", - ci->ci_type, ci->ci_subtype, ct->c_file); - return NOTOK; - } - - /* check for missing subtype */ - if (!*ci->ci_subtype) - ci->ci_subtype = add ("rfc822", ci->ci_subtype); + struct k2v *kv; + CI ci = &ct->c_ctinfo; - /* match subtype */ - for (kv = SubMessage; kv->kv_key; kv++) - if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) - break; - ct->c_subtype = kv->kv_value; + if ((ct->c_encoding != CE_7BIT) && (ct->c_encoding != CE_8BIT)) { + admonish (NULL, + "\"%s/%s\" type in message %s should be encoded in 7bit or 8bit", + ci->ci_type, ci->ci_subtype, ct->c_file); + return NOTOK; + } - switch (ct->c_subtype) { - case MESSAGE_RFC822: - break; + /* check for missing subtype */ + if (!*ci->ci_subtype) + ci->ci_subtype = add ("rfc822", ci->ci_subtype); - case MESSAGE_PARTIAL: - { - char **ap, **ep; - struct partial *p; + /* match subtype */ + for (kv = SubMessage; kv->kv_key; kv++) + if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) + break; + ct->c_subtype = kv->kv_value; - if ((p = (struct partial *) calloc (1, sizeof(*p))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) p; + switch (ct->c_subtype) { + case MESSAGE_RFC822: + break; - /* scan for parameters "id", "number", and "total" */ - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - if (!mh_strcasecmp (*ap, "id")) { - p->pm_partid = add (*ep, NULL); - continue; - } - if (!mh_strcasecmp (*ap, "number")) { - if (sscanf (*ep, "%d", &p->pm_partno) != 1 - || p->pm_partno < 1) { + case MESSAGE_PARTIAL: + { + char **ap, **ep; + struct partial *p; + + if ((p = (struct partial *) calloc (1, sizeof(*p))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) p; + + /* scan for parameters "id", "number", and "total" */ + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + if (!mh_strcasecmp (*ap, "id")) { + p->pm_partid = add (*ep, NULL); + continue; + } + if (!mh_strcasecmp (*ap, "number")) { + if (sscanf (*ep, "%d", &p->pm_partno) != 1 + || p->pm_partno < 1) { invalid_param: - advise (NULL, - "invalid %s parameter for \"%s/%s\" type in message %s's %s field", - *ap, ci->ci_type, ci->ci_subtype, - ct->c_file, TYPE_FIELD); - return NOTOK; + advise (NULL, + "invalid %s parameter for \"%s/%s\" type in message %s's %s field", + *ap, ci->ci_type, ci->ci_subtype, + ct->c_file, TYPE_FIELD); + return NOTOK; + } + continue; + } + if (!mh_strcasecmp (*ap, "total")) { + if (sscanf (*ep, "%d", &p->pm_maxno) != 1 + || p->pm_maxno < 1) + goto invalid_param; + continue; + } + } + + if (!p->pm_partid || !p->pm_partno + || (p->pm_maxno && p->pm_partno > p->pm_maxno)) { + advise (NULL, + "invalid parameters for \"%s/%s\" type in message %s's %s field", + ci->ci_type, ci->ci_subtype, + ct->c_file, TYPE_FIELD); + return NOTOK; + } } - continue; - } - if (!mh_strcasecmp (*ap, "total")) { - if (sscanf (*ep, "%d", &p->pm_maxno) != 1 - || p->pm_maxno < 1) - goto invalid_param; - continue; - } - } - - if (!p->pm_partid - || !p->pm_partno - || (p->pm_maxno && p->pm_partno > p->pm_maxno)) { - advise (NULL, - "invalid parameters for \"%s/%s\" type in message %s's %s field", - ci->ci_type, ci->ci_subtype, - ct->c_file, TYPE_FIELD); - return NOTOK; - } - } - break; - - case MESSAGE_EXTERNAL: - { - int exresult; - struct exbody *e; - CT p; - FILE *fp; - - if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL) - adios (NULL, "out of memory"); - ct->c_ctparams = (void *) e; - - if (!ct->c_fp - && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - advise (ct->c_file, "unable to open for reading"); - return NOTOK; - } - - fseek (fp = ct->c_fp, ct->c_begin, SEEK_SET); - - if (!(p = get_content (fp, ct->c_file, 0))) { - ct->c_fp = NULL; - return NOTOK; - } + break; - e->eb_parent = ct; - e->eb_content = p; - p->c_ctexbody = e; - if ((exresult = params_external (ct, 0)) != NOTOK - && p->c_ceopenfnx == openMail) { - int cc, size; - char *bp; - - if ((size = ct->c_end - p->c_begin) <= 0) { - if (!e->eb_subject) - content_error (NULL, ct, - "empty body for access-type=mail-server"); - goto no_body; - } - - e->eb_body = bp = mh_xmalloc ((unsigned) size); - fseek (p->c_fp, p->c_begin, SEEK_SET); - while (size > 0) - switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) { - case NOTOK: - adios ("failed", "fread"); - - case OK: - adios (NULL, "unexpected EOF from fread"); - - default: - bp += cc, size -= cc; - break; - } - *bp = 0; - } + case MESSAGE_EXTERNAL: + { + int exresult; + struct exbody *e; + CT p; + FILE *fp; + + if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL) + adios (NULL, "out of memory"); + ct->c_ctparams = (void *) e; + + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + advise (ct->c_file, "unable to open for reading"); + return NOTOK; + } + + fseek (fp = ct->c_fp, ct->c_begin, SEEK_SET); + + if (!(p = get_content (fp, ct->c_file, 0))) { + ct->c_fp = NULL; + return NOTOK; + } + + e->eb_parent = ct; + e->eb_content = p; + p->c_ctexbody = e; + if ((exresult = params_external (ct, 0)) != NOTOK + && p->c_ceopenfnx == openMail) { + int cc, size; + char *bp; + + if ((size = ct->c_end - p->c_begin) <= 0) { + if (!e->eb_subject) + content_error (NULL, ct, "empty body for access-type=mail-server"); + goto no_body; + } + + e->eb_body = bp = mh_xmalloc ((unsigned) size); + fseek (p->c_fp, p->c_begin, SEEK_SET); + while (size > 0) + switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) { + case NOTOK: + adios ("failed", "fread"); + + case OK: + adios (NULL, "unexpected EOF from fread"); + + default: + bp += cc, size -= cc; + break; + } + *bp = 0; + } no_body: - p->c_fp = NULL; - p->c_end = p->c_begin; - - fclose (ct->c_fp); - ct->c_fp = NULL; - - if (exresult == NOTOK) - return NOTOK; - if (e->eb_flags == NOTOK) - return OK; - - switch (p->c_type) { - case CT_MULTIPART: - break; - - case CT_MESSAGE: - if (p->c_subtype != MESSAGE_RFC822) - break; - /* else fall... */ - default: - e->eb_partno = ct->c_partno; - if (p->c_ctinitfnx) - (*p->c_ctinitfnx) (p); + p->c_fp = NULL; + p->c_end = p->c_begin; + + fclose (ct->c_fp); + ct->c_fp = NULL; + + if (exresult == NOTOK) + return NOTOK; + if (e->eb_flags == NOTOK) + return OK; + + switch (p->c_type) { + case CT_MULTIPART: + break; + + case CT_MESSAGE: + if (p->c_subtype != MESSAGE_RFC822) + break; + /* else fall... */ + default: + e->eb_partno = ct->c_partno; + if (p->c_ctinitfnx) + (*p->c_ctinitfnx) (p); + break; + } + } break; - } - } - break; - default: - break; - } + default: + break; + } - return OK; + return OK; } int params_external (CT ct, int composing) { - char **ap, **ep; - struct exbody *e = (struct exbody *) ct->c_ctparams; - CI ci = &ct->c_ctinfo; - - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - if (!mh_strcasecmp (*ap, "access-type")) { - struct str2init *s2i; - CT p = e->eb_content; - - for (s2i = str2methods; s2i->si_key; s2i++) - if (!mh_strcasecmp (*ep, s2i->si_key)) - break; - if (!s2i->si_key) { - e->eb_access = *ep; - e->eb_flags = NOTOK; - p->c_encoding = CE_EXTERNAL; - continue; - } - e->eb_access = s2i->si_key; - e->eb_flags = s2i->si_val; - p->c_encoding = CE_EXTERNAL; + char **ap, **ep; + struct exbody *e = (struct exbody *) ct->c_ctparams; + CI ci = &ct->c_ctinfo; - /* Call the Init function for this external type */ - if ((*s2i->si_init)(p) == NOTOK) - return NOTOK; - continue; - } - if (!mh_strcasecmp (*ap, "name")) { - e->eb_name = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "permission")) { - e->eb_permission = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "site")) { - e->eb_site = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "directory")) { - e->eb_dir = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "mode")) { - e->eb_mode = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "size")) { - sscanf (*ep, "%lu", &e->eb_size); - continue; - } - if (!mh_strcasecmp (*ap, "server")) { - e->eb_server = *ep; - continue; - } - if (!mh_strcasecmp (*ap, "subject")) { - e->eb_subject = *ep; - continue; - } - if (composing && !mh_strcasecmp (*ap, "body")) { - e->eb_body = getcpy (*ep); - continue; + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + if (!mh_strcasecmp (*ap, "access-type")) { + struct str2init *s2i; + CT p = e->eb_content; + + for (s2i = str2methods; s2i->si_key; s2i++) + if (!mh_strcasecmp (*ep, s2i->si_key)) + break; + if (!s2i->si_key) { + e->eb_access = *ep; + e->eb_flags = NOTOK; + p->c_encoding = CE_EXTERNAL; + continue; + } + e->eb_access = s2i->si_key; + e->eb_flags = s2i->si_val; + p->c_encoding = CE_EXTERNAL; + + /* Call the Init function for this external type */ + if ((*s2i->si_init)(p) == NOTOK) + return NOTOK; + continue; + } + if (!mh_strcasecmp (*ap, "name")) { + e->eb_name = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "permission")) { + e->eb_permission = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "site")) { + e->eb_site = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "directory")) { + e->eb_dir = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "mode")) { + e->eb_mode = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "size")) { + sscanf (*ep, "%lu", &e->eb_size); + continue; + } + if (!mh_strcasecmp (*ap, "server")) { + e->eb_server = *ep; + continue; + } + if (!mh_strcasecmp (*ap, "subject")) { + e->eb_subject = *ep; + continue; + } + if (composing && !mh_strcasecmp (*ap, "body")) { + e->eb_body = getcpy (*ep); + continue; + } } - } - if (!e->eb_access) { - advise (NULL, - "invalid parameters for \"%s/%s\" type in message %s's %s field", - ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); - return NOTOK; - } + if (!e->eb_access) { + advise (NULL, + "invalid parameters for \"%s/%s\" type in message %s's %s field", + ci->ci_type, ci->ci_subtype, ct->c_file, TYPE_FIELD); + return NOTOK; + } - return OK; + return OK; } @@ -1611,16 +1600,16 @@ params_external (CT ct, int composing) static int InitApplication (CT ct) { - struct k2v *kv; - CI ci = &ct->c_ctinfo; + struct k2v *kv; + CI ci = &ct->c_ctinfo; - /* match subtype */ - for (kv = SubApplication; kv->kv_key; kv++) - if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) - break; - ct->c_subtype = kv->kv_value; + /* match subtype */ + for (kv = SubApplication; kv->kv_key; kv++) + if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key)) + break; + ct->c_subtype = kv->kv_value; - return OK; + return OK; } @@ -1631,71 +1620,71 @@ InitApplication (CT ct) static int init_encoding (CT ct, OpenCEFunc openfnx) { - CE ce; + CE ce; - if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL) - adios (NULL, "out of memory"); + if ((ce = (CE) calloc (1, sizeof(*ce))) == NULL) + adios (NULL, "out of memory"); - ct->c_cefile = ce; - ct->c_ceopenfnx = openfnx; - ct->c_ceclosefnx = close_encoding; - ct->c_cesizefnx = size_encoding; + ct->c_cefile = ce; + ct->c_ceopenfnx = openfnx; + ct->c_ceclosefnx = close_encoding; + ct->c_cesizefnx = size_encoding; - return OK; + return OK; } void close_encoding (CT ct) { - CE ce; + CE ce; - if (!(ce = ct->c_cefile)) - return; + if (!(ce = ct->c_cefile)) + return; - if (ce->ce_fp) { - fclose (ce->ce_fp); - ce->ce_fp = NULL; - } + if (ce->ce_fp) { + fclose (ce->ce_fp); + ce->ce_fp = NULL; + } } static unsigned long size_encoding (CT ct) { - int fd; - unsigned long size; - char *file; - CE ce; - struct stat st; + int fd; + unsigned long size; + char *file; + CE ce; + struct stat st; - if (!(ce = ct->c_cefile)) - return (ct->c_end - ct->c_begin); + if (!(ce = ct->c_cefile)) + return (ct->c_end - ct->c_begin); - if (ce->ce_fp && fstat (fileno (ce->ce_fp), &st) != NOTOK) - return (long) st.st_size; + if (ce->ce_fp && fstat (fileno (ce->ce_fp), &st) != NOTOK) + return (long) st.st_size; - if (ce->ce_file) { - if (stat (ce->ce_file, &st) != NOTOK) - return (long) st.st_size; - else - return 0L; - } + if (ce->ce_file) { + if (stat (ce->ce_file, &st) != NOTOK) + return (long) st.st_size; + else + return 0L; + } - if (ct->c_encoding == CE_EXTERNAL) - return (ct->c_end - ct->c_begin); + if (ct->c_encoding == CE_EXTERNAL) + return (ct->c_end - ct->c_begin); - file = NULL; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return (ct->c_end - ct->c_begin); + file = NULL; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return (ct->c_end - ct->c_begin); - if (fstat (fd, &st) != NOTOK) - size = (long) st.st_size; - else - size = 0L; + if (fstat (fd, &st) != NOTOK) + size = (long) st.st_size; + else + size = 0L; - (*ct->c_ceclosefnx) (ct); - return size; + (*ct->c_ceclosefnx) (ct); + return size; } @@ -1704,226 +1693,221 @@ size_encoding (CT ct) */ static unsigned char b642nib[0x80] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, - 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff }; static int InitBase64 (CT ct) { - return init_encoding (ct, openBase64); + return init_encoding (ct, openBase64); } static int openBase64 (CT ct, char **file) { - int bitno, cc, digested; - int fd, len, skip; - unsigned long bits; - unsigned char value, *b, *b1, *b2, *b3; - unsigned char *cp, *ep; - char buffer[BUFSIZ]; - /* sbeck -- handle suffixes */ - CI ci; - CE ce; - MD5_CTX mdContext; - - b = (unsigned char *) &bits; - b1 = &b[endian > 0 ? 1 : 2]; - b2 = &b[endian > 0 ? 2 : 1]; - b3 = &b[endian > 0 ? 3 : 0]; - - ce = ct->c_cefile; - if (ce->ce_fp) { - fseek (ce->ce_fp, 0L, SEEK_SET); - goto ready_to_go; - } - - if (ce->ce_file) { - if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading"); - return NOTOK; + int bitno, cc, digested; + int fd, len, skip; + unsigned long bits; + unsigned char value, *b, *b1, *b2, *b3; + unsigned char *cp, *ep; + char buffer[BUFSIZ]; + /* sbeck -- handle suffixes */ + CI ci; + CE ce; + MD5_CTX mdContext; + + b = (unsigned char *) &bits; + b1 = &b[endian > 0 ? 1 : 2]; + b2 = &b[endian > 0 ? 2 : 1]; + b3 = &b[endian > 0 ? 3 : 0]; + + ce = ct->c_cefile; + if (ce->ce_fp) { + fseek (ce->ce_fp, 0L, SEEK_SET); + goto ready_to_go; } - goto ready_to_go; - } - if (*file == NULL) { - ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); - ce->ce_unlink = 1; - } else { - ce->ce_file = add (*file, NULL); - ce->ce_unlink = 0; - } - - /* sbeck@cise.ufl.edu -- handle suffixes */ - ci = &ct->c_ctinfo; - snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - cp = context_find (buffer); - if (cp == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, - ci->ci_type); - cp = context_find (buffer); - } - if (cp != NULL && *cp != '\0') { - if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. - char *file_org = strdup(ce->ce_file); - ce->ce_file = add (cp, ce->ce_file); - if (rename(file_org, ce->ce_file)) { - adios (ce->ce_file, "unable to rename %s to ", file_org); - } - free(file_org); - - } else { - ce->ce_file = add (cp, ce->ce_file); - } - } - - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + if (ce->ce_file) { + if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading"); + return NOTOK; + } + goto ready_to_go; + } - if ((len = ct->c_end - ct->c_begin) < 0) - adios (NULL, "internal error(1)"); + if (*file == NULL) { + ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); + ce->ce_unlink = 1; + } else { + ce->ce_file = add (*file, NULL); + ce->ce_unlink = 0; + } - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; - } - - if ((digested = ct->c_digested)) - MD5Init (&mdContext); - - bitno = 18; - bits = 0L; - skip = 0; - - lseek (fd = fileno (ct->c_fp), (off_t) ct->c_begin, SEEK_SET); - while (len > 0) { - switch (cc = read (fd, buffer, sizeof(buffer) - 1)) { - case NOTOK: - content_error (ct->c_file, ct, "error reading from"); - goto clean_up; - - case OK: - content_error (NULL, ct, "premature eof"); - goto clean_up; - - default: - if (cc > len) - cc = len; - len -= cc; - - for (ep = (cp = buffer) + cc; cp < ep; cp++) { - switch (*cp) { - default: - if (isspace (*cp)) - break; - if (skip || (*cp & 0x80) - || (value = b642nib[*cp & 0x7f]) > 0x3f) { - if (debugsw) { - fprintf (stderr, "*cp=0x%x pos=%ld skip=%d\n", - *cp, - (long) (lseek (fd, (off_t) 0, SEEK_CUR) - (ep - cp)), - skip); + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') { + if (ce->ce_unlink) { + // Temporary file already exists, so we rename to + // version with extension. + char *file_org = strdup(ce->ce_file); + ce->ce_file = add (cp, ce->ce_file); + if (rename(file_org, ce->ce_file)) { + adios (ce->ce_file, "unable to rename %s to ", file_org); } - content_error (NULL, ct, - "invalid BASE64 encoding -- continuing"); - continue; - } + free(file_org); - bits |= value << bitno; -test_end: - if ((bitno -= 6) < 0) { - putc ((char) *b1, ce->ce_fp); - if (digested) - MD5Update (&mdContext, b1, 1); - if (skip < 2) { - putc ((char) *b2, ce->ce_fp); - if (digested) - MD5Update (&mdContext, b2, 1); - if (skip < 1) { - putc ((char) *b3, ce->ce_fp); - if (digested) - MD5Update (&mdContext, b3, 1); - } - } + } else { + ce->ce_file = add (cp, ce->ce_file); + } + } - if (ferror (ce->ce_fp)) { - content_error (ce->ce_file, ct, - "error writing to"); - goto clean_up; + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } + + if ((len = ct->c_end - ct->c_begin) < 0) + adios (NULL, "internal error(1)"); + + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; + } + + if ((digested = ct->c_digested)) + MD5Init (&mdContext); + + bitno = 18; + bits = 0L; + skip = 0; + + lseek (fd = fileno (ct->c_fp), (off_t) ct->c_begin, SEEK_SET); + while (len > 0) { + switch (cc = read (fd, buffer, sizeof(buffer) - 1)) { + case NOTOK: + content_error (ct->c_file, ct, "error reading from"); + goto clean_up; + + case OK: + content_error (NULL, ct, "premature eof"); + goto clean_up; + + default: + if (cc > len) + cc = len; + len -= cc; + + for (ep = (cp = buffer) + cc; cp < ep; cp++) { + switch (*cp) { + default: + if (isspace (*cp)) + break; + if (skip || (*cp & 0x80) + || (value = b642nib[*cp & 0x7f]) > 0x3f) { + if (debugsw) { + fprintf (stderr, "*cp=0x%x pos=%ld skip=%d\n", *cp, (long) (lseek (fd, (off_t) 0, SEEK_CUR) - (ep - cp)), skip); + } + content_error (NULL, ct, + "invalid BASE64 encoding -- continuing"); + continue; + } + + bits |= value << bitno; +test_end: + if ((bitno -= 6) < 0) { + putc ((char) *b1, ce->ce_fp); + if (digested) + MD5Update (&mdContext, b1, 1); + if (skip < 2) { + putc ((char) *b2, ce->ce_fp); + if (digested) + MD5Update (&mdContext, b2, 1); + if (skip < 1) { + putc ((char) *b3, ce->ce_fp); + if (digested) + MD5Update (&mdContext, b3, 1); + } + } + + if (ferror (ce->ce_fp)) { + content_error (ce->ce_file, ct, + "error writing to"); + goto clean_up; + } + bitno = 18, bits = 0L, skip = 0; + } + break; + + case '=': + if (++skip > 3) + goto self_delimiting; + goto test_end; + } } - bitno = 18, bits = 0L, skip = 0; - } - break; - - case '=': - if (++skip > 3) - goto self_delimiting; - goto test_end; } - } } - } - if (bitno != 18) { - if (debugsw) - fprintf (stderr, "premature ending (bitno %d)\n", bitno); + if (bitno != 18) { + if (debugsw) + fprintf (stderr, "premature ending (bitno %d)\n", bitno); - content_error (NULL, ct, "invalid BASE64 encoding"); - goto clean_up; - } + content_error (NULL, ct, "invalid BASE64 encoding"); + goto clean_up; + } self_delimiting: - fseek (ct->c_fp, 0L, SEEK_SET); + fseek (ct->c_fp, 0L, SEEK_SET); - if (fflush (ce->ce_fp)) { - content_error (ce->ce_file, ct, "error writing to"); - goto clean_up; - } + if (fflush (ce->ce_fp)) { + content_error (ce->ce_file, ct, "error writing to"); + goto clean_up; + } - if (digested) { - unsigned char digest[16]; + if (digested) { + unsigned char digest[16]; - MD5Final (digest, &mdContext); - if (memcmp((char *) digest, (char *) ct->c_digest, - sizeof(digest) / sizeof(digest[0]))) - content_error (NULL, ct, - "content integrity suspect (digest mismatch) -- continuing"); - else - if (debugsw) - fprintf (stderr, "content integrity confirmed\n"); - } + MD5Final (digest, &mdContext); + if (memcmp((char *) digest, (char *) ct->c_digest, + sizeof(digest) / sizeof(digest[0]))) + content_error (NULL, ct, "content integrity suspect (digest mismatch) -- continuing"); + else if (debugsw) + fprintf (stderr, "content integrity confirmed\n"); + } - fseek (ce->ce_fp, 0L, SEEK_SET); + fseek (ce->ce_fp, 0L, SEEK_SET); ready_to_go: - *file = ce->ce_file; - return fileno (ce->ce_fp); + *file = ce->ce_file; + return fileno (ce->ce_fp); clean_up: - free_encoding (ct, 0); - return NOTOK; + free_encoding (ct, 0); + return NOTOK; } @@ -1932,234 +1916,234 @@ clean_up: */ static char hex2nib[0x80] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static int +static int InitQuoted (CT ct) { - return init_encoding (ct, openQuoted); + return init_encoding (ct, openQuoted); } static int openQuoted (CT ct, char **file) { - int cc, digested, len, quoted; - unsigned char *cp, *ep; - char buffer[BUFSIZ]; - unsigned char mask; - CE ce; - /* sbeck -- handle suffixes */ - CI ci; - MD5_CTX mdContext; - - ce = ct->c_cefile; - if (ce->ce_fp) { - fseek (ce->ce_fp, 0L, SEEK_SET); - goto ready_to_go; - } + int cc, digested, len, quoted; + unsigned char *cp, *ep; + char buffer[BUFSIZ]; + unsigned char mask; + CE ce; + /* sbeck -- handle suffixes */ + CI ci; + MD5_CTX mdContext; + + ce = ct->c_cefile; + if (ce->ce_fp) { + fseek (ce->ce_fp, 0L, SEEK_SET); + goto ready_to_go; + } - if (ce->ce_file) { - if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading"); - return NOTOK; + if (ce->ce_file) { + if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading"); + return NOTOK; + } + goto ready_to_go; } - goto ready_to_go; - } - if (*file == NULL) { - ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); - ce->ce_unlink = 1; - } else { - ce->ce_file = add (*file, NULL); - ce->ce_unlink = 0; - } - - /* sbeck@cise.ufl.edu -- handle suffixes */ - ci = &ct->c_ctinfo; - snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - cp = context_find (buffer); - if (cp == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, - ci->ci_type); - cp = context_find (buffer); - } - if (cp != NULL && *cp != '\0') { - if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. - char *file_org = strdup(ce->ce_file); - ce->ce_file = add (cp, ce->ce_file); - if (rename(file_org, ce->ce_file)) { - adios (ce->ce_file, "unable to rename %s to ", file_org); - } - free(file_org); - - } else { - ce->ce_file = add (cp, ce->ce_file); - } - } - - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + if (*file == NULL) { + ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); + ce->ce_unlink = 1; + } else { + ce->ce_file = add (*file, NULL); + ce->ce_unlink = 0; + } - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') { + if (ce->ce_unlink) { + // Temporary file already exists, so we rename to + // version with extension. + char *file_org = strdup(ce->ce_file); + ce->ce_file = add (cp, ce->ce_file); + if (rename(file_org, ce->ce_file)) { + adios (ce->ce_file, "unable to rename %s to ", file_org); + } + free(file_org); - if ((len = ct->c_end - ct->c_begin) < 0) - adios (NULL, "internal error(2)"); + } else { + ce->ce_file = add (cp, ce->ce_file); + } + } - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; - } + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } - if ((digested = ct->c_digested)) - MD5Init (&mdContext); + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } - quoted = 0; -#ifdef lint - mask = 0; -#endif + if ((len = ct->c_end - ct->c_begin) < 0) + adios (NULL, "internal error(2)"); - fseek (ct->c_fp, ct->c_begin, SEEK_SET); - while (len > 0) { - if (fgets (buffer, sizeof(buffer) - 1, ct->c_fp) == NULL) { - content_error (NULL, ct, "premature eof"); - goto clean_up; + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; } - if ((cc = strlen (buffer)) > len) - cc = len; - len -= cc; + if ((digested = ct->c_digested)) + MD5Init (&mdContext); - for (ep = (cp = buffer) + cc - 1; cp <= ep; ep--) - if (!isspace (*ep)) - break; - *++ep = '\n', ep++; - - for (; cp < ep; cp++) { - if (quoted > 0) { - /* in an escape sequence */ - if (quoted == 1) { - /* at byte 1 of an escape sequence */ - mask = hex2nib[*cp & 0x7f]; - /* next is byte 2 */ - quoted = 2; - } else { - /* at byte 2 of an escape sequence */ - mask <<= 4; - mask |= hex2nib[*cp & 0x7f]; - putc (mask, ce->ce_fp); - if (digested) - MD5Update (&mdContext, &mask, 1); - if (ferror (ce->ce_fp)) { - content_error (ce->ce_file, ct, "error writing to"); + quoted = 0; +#ifdef lint + mask = 0; +#endif + + fseek (ct->c_fp, ct->c_begin, SEEK_SET); + while (len > 0) { + if (fgets (buffer, sizeof(buffer) - 1, ct->c_fp) == NULL) { + content_error (NULL, ct, "premature eof"); goto clean_up; - } - /* finished escape sequence; next may be literal or a new - * escape sequence */ - quoted = 0; - } - /* on to next byte */ - continue; - } - - /* not in an escape sequence */ - if (*cp == '=') { - /* starting an escape sequence, or invalid '='? */ - if (cp + 1 < ep && cp[1] == '\n') { - /* "=\n" soft line break, eat the \n */ - cp++; - continue; } - if (cp + 1 >= ep || cp + 2 >= ep) { - /* We don't have 2 bytes left, so this is an invalid - * escape sequence; just show the raw bytes (below). */ - } else if (isxdigit (cp[1]) && isxdigit (cp[2])) { - /* Next 2 bytes are hex digits, making this a valid escape - * sequence; let's decode it (above). */ - quoted = 1; - continue; - } else { - /* One or both of the next 2 is out of range, making this - * an invalid escape sequence; just show the raw bytes - * (below). */ - } - } - /* Just show the raw byte. */ - putc (*cp, ce->ce_fp); - if (digested) { - if (*cp == '\n') { - MD5Update (&mdContext, (unsigned char *) "\r\n",2); - } else { - MD5Update (&mdContext, (unsigned char *) cp, 1); + if ((cc = strlen (buffer)) > len) + cc = len; + len -= cc; + + for (ep = (cp = buffer) + cc - 1; cp <= ep; ep--) + if (!isspace (*ep)) + break; + *++ep = '\n', ep++; + + for (; cp < ep; cp++) { + if (quoted > 0) { + /* in an escape sequence */ + if (quoted == 1) { + /* at byte 1 of an escape sequence */ + mask = hex2nib[*cp & 0x7f]; + /* next is byte 2 */ + quoted = 2; + } else { + /* at byte 2 of an escape sequence */ + mask <<= 4; + mask |= hex2nib[*cp & 0x7f]; + putc (mask, ce->ce_fp); + if (digested) + MD5Update (&mdContext, &mask, 1); + if (ferror (ce->ce_fp)) { + content_error (ce->ce_file, ct, "error writing to"); + goto clean_up; + } + /* finished escape sequence; next may + * be literal or a new escape + * sequence */ + quoted = 0; + } + /* on to next byte */ + continue; + } + + /* not in an escape sequence */ + if (*cp == '=') { + /* starting an escape sequence, or invalid '='? */ + if (cp + 1 < ep && cp[1] == '\n') { + /* "=\n" soft line break, eat the \n */ + cp++; + continue; + } + if (cp + 1 >= ep || cp + 2 >= ep) { + /* We don't have 2 bytes left, so this is an invalid + * escape sequence; just show the raw bytes (below). */ + } else if (isxdigit (cp[1]) && isxdigit (cp[2])) { + /* Next 2 bytes are hex digits, making this a valid escape + * sequence; let's decode it (above). */ + quoted = 1; + continue; + } else { + /* One or both of the next 2 is out of range, making this + * an invalid escape sequence; just show the raw bytes + * (below). */ + } + } + + /* Just show the raw byte. */ + putc (*cp, ce->ce_fp); + if (digested) { + if (*cp == '\n') { + MD5Update (&mdContext, (unsigned char *) "\r\n",2); + } else { + MD5Update (&mdContext, (unsigned char *) cp, 1); + } + } + if (ferror (ce->ce_fp)) { + content_error (ce->ce_file, ct, "error writing to"); + goto clean_up; + } } - } - if (ferror (ce->ce_fp)) { + } + if (quoted) { + content_error (NULL, ct, + "invalid QUOTED-PRINTABLE encoding -- end-of-content while still quoting"); + goto clean_up; + } + + fseek (ct->c_fp, 0L, SEEK_SET); + + if (fflush (ce->ce_fp)) { content_error (ce->ce_file, ct, "error writing to"); goto clean_up; - } - } - } - if (quoted) { - content_error (NULL, ct, - "invalid QUOTED-PRINTABLE encoding -- end-of-content while still quoting"); - goto clean_up; - } - - fseek (ct->c_fp, 0L, SEEK_SET); - - if (fflush (ce->ce_fp)) { - content_error (ce->ce_file, ct, "error writing to"); - goto clean_up; - } - - if (digested) { - unsigned char digest[16]; - - MD5Final (digest, &mdContext); - if (memcmp((char *) digest, (char *) ct->c_digest, - sizeof(digest) / sizeof(digest[0]))) - content_error (NULL, ct, - "content integrity suspect (digest mismatch) -- continuing"); - else - if (debugsw) - fprintf (stderr, "content integrity confirmed\n"); - } + } - fseek (ce->ce_fp, 0L, SEEK_SET); + if (digested) { + unsigned char digest[16]; + + MD5Final (digest, &mdContext); + if (memcmp((char *) digest, (char *) ct->c_digest, + sizeof(digest) / sizeof(digest[0]))) + content_error (NULL, ct, + "content integrity suspect (digest mismatch) -- continuing"); + else if (debugsw) + fprintf (stderr, "content integrity confirmed\n"); + } + + fseek (ce->ce_fp, 0L, SEEK_SET); ready_to_go: - *file = ce->ce_file; - return fileno (ce->ce_fp); + *file = ce->ce_file; + return fileno (ce->ce_fp); clean_up: - free_encoding (ct, 0); - return NOTOK; + free_encoding (ct, 0); + return NOTOK; } @@ -2170,171 +2154,171 @@ clean_up: static int Init7Bit (CT ct) { - if (init_encoding (ct, open7Bit) == NOTOK) - return NOTOK; + if (init_encoding (ct, open7Bit) == NOTOK) + return NOTOK; - ct->c_cesizefnx = NULL; /* no need to decode for real size */ - return OK; + ct->c_cesizefnx = NULL; /* no need to decode for real size */ + return OK; } int open7Bit (CT ct, char **file) { - int cc, fd, len; - char buffer[BUFSIZ]; - /* sbeck -- handle suffixes */ - char *cp; - CI ci; - CE ce; - - ce = ct->c_cefile; - if (ce->ce_fp) { - fseek (ce->ce_fp, 0L, SEEK_SET); - goto ready_to_go; - } + int cc, fd, len; + char buffer[BUFSIZ]; + /* sbeck -- handle suffixes */ + char *cp; + CI ci; + CE ce; + + ce = ct->c_cefile; + if (ce->ce_fp) { + fseek (ce->ce_fp, 0L, SEEK_SET); + goto ready_to_go; + } - if (ce->ce_file) { - if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading"); - return NOTOK; + if (ce->ce_file) { + if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading"); + return NOTOK; + } + goto ready_to_go; } - goto ready_to_go; - } - if (*file == NULL) { - ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); - ce->ce_unlink = 1; - } else { - ce->ce_file = add (*file, NULL); - ce->ce_unlink = 0; - } - - /* sbeck@cise.ufl.edu -- handle suffixes */ - ci = &ct->c_ctinfo; - snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - cp = context_find (buffer); - if (cp == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, - ci->ci_type); - cp = context_find (buffer); - } - if (cp != NULL && *cp != '\0') { - if (ce->ce_unlink) { - // Temporary file already exists, so we rename to - // version with extension. - char *file_org = strdup(ce->ce_file); - ce->ce_file = add (cp, ce->ce_file); - if (rename(file_org, ce->ce_file)) { - adios (ce->ce_file, "unable to rename %s to ", file_org); - } - free(file_org); - - } else { - ce->ce_file = add (cp, ce->ce_file); - } - } - - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + if (*file == NULL) { + ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); + ce->ce_unlink = 1; + } else { + ce->ce_file = add (*file, NULL); + ce->ce_unlink = 0; + } - if (ct->c_type == CT_MULTIPART) { - char **ap, **ep; - CI ci = &ct->c_ctinfo; + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') { + if (ce->ce_unlink) { + // Temporary file already exists, so we rename to + // version with extension. + char *file_org = strdup(ce->ce_file); + ce->ce_file = add (cp, ce->ce_file); + if (rename(file_org, ce->ce_file)) { + adios (ce->ce_file, "unable to rename %s to ", file_org); + } + free(file_org); - len = 0; - fprintf (ce->ce_fp, "%s: %s/%s", TYPE_FIELD, ci->ci_type, ci->ci_subtype); - len += strlen (TYPE_FIELD) + 2 + strlen (ci->ci_type) - + 1 + strlen (ci->ci_subtype); - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - putc (';', ce->ce_fp); - len++; - - snprintf (buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep); - - if (len + 1 + (cc = strlen (buffer)) >= CPERLIN) { - fputs ("\n\t", ce->ce_fp); - len = 8; - } else { - putc (' ', ce->ce_fp); - len++; - } - fprintf (ce->ce_fp, "%s", buffer); - len += cc; - } - - if (ci->ci_comment) { - if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) { - fputs ("\n\t", ce->ce_fp); - len = 8; - } - else { - putc (' ', ce->ce_fp); - len++; - } - fprintf (ce->ce_fp, "(%s)", ci->ci_comment); - len += cc; - } - fprintf (ce->ce_fp, "\n"); - if (ct->c_id) - fprintf (ce->ce_fp, "%s:%s", ID_FIELD, ct->c_id); - if (ct->c_descr) - fprintf (ce->ce_fp, "%s:%s", DESCR_FIELD, ct->c_descr); - if (ct->c_dispo) - fprintf (ce->ce_fp, "%s:%s", DISPO_FIELD, ct->c_dispo); - fprintf (ce->ce_fp, "\n"); - } - - if ((len = ct->c_end - ct->c_begin) < 0) - adios (NULL, "internal error(3)"); - - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - content_error (ct->c_file, ct, "unable to open for reading"); - return NOTOK; - } - - lseek (fd = fileno (ct->c_fp), (off_t) ct->c_begin, SEEK_SET); - while (len > 0) - switch (cc = read (fd, buffer, sizeof(buffer) - 1)) { - case NOTOK: - content_error (ct->c_file, ct, "error reading from"); - goto clean_up; - - case OK: - content_error (NULL, ct, "premature eof"); - goto clean_up; - - default: - if (cc > len) - cc = len; - len -= cc; - - fwrite (buffer, sizeof(*buffer), cc, ce->ce_fp); - if (ferror (ce->ce_fp)) { - content_error (ce->ce_file, ct, "error writing to"); - goto clean_up; - } + } else { + ce->ce_file = add (cp, ce->ce_file); + } } - fseek (ct->c_fp, 0L, SEEK_SET); + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } - if (fflush (ce->ce_fp)) { - content_error (ce->ce_file, ct, "error writing to"); - goto clean_up; - } + if (ct->c_type == CT_MULTIPART) { + char **ap, **ep; + CI ci = &ct->c_ctinfo; - fseek (ce->ce_fp, 0L, SEEK_SET); + len = 0; + fprintf (ce->ce_fp, "%s: %s/%s", TYPE_FIELD, ci->ci_type, ci->ci_subtype); + len += strlen (TYPE_FIELD) + 2 + strlen (ci->ci_type) + + 1 + strlen (ci->ci_subtype); + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + putc (';', ce->ce_fp); + len++; + + snprintf (buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep); + + if (len + 1 + (cc = strlen (buffer)) >= CPERLIN) { + fputs ("\n\t", ce->ce_fp); + len = 8; + } else { + putc (' ', ce->ce_fp); + len++; + } + fprintf (ce->ce_fp, "%s", buffer); + len += cc; + } + + if (ci->ci_comment) { + if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) { + fputs ("\n\t", ce->ce_fp); + len = 8; + } + else { + putc (' ', ce->ce_fp); + len++; + } + fprintf (ce->ce_fp, "(%s)", ci->ci_comment); + len += cc; + } + fprintf (ce->ce_fp, "\n"); + if (ct->c_id) + fprintf (ce->ce_fp, "%s:%s", ID_FIELD, ct->c_id); + if (ct->c_descr) + fprintf (ce->ce_fp, "%s:%s", DESCR_FIELD, ct->c_descr); + if (ct->c_dispo) + fprintf (ce->ce_fp, "%s:%s", DISPO_FIELD, ct->c_dispo); + fprintf (ce->ce_fp, "\n"); + } + + if ((len = ct->c_end - ct->c_begin) < 0) + adios (NULL, "internal error(3)"); + + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + content_error (ct->c_file, ct, "unable to open for reading"); + return NOTOK; + } + + lseek (fd = fileno (ct->c_fp), (off_t) ct->c_begin, SEEK_SET); + while (len > 0) + switch (cc = read (fd, buffer, sizeof(buffer) - 1)) { + case NOTOK: + content_error (ct->c_file, ct, "error reading from"); + goto clean_up; + + case OK: + content_error (NULL, ct, "premature eof"); + goto clean_up; + + default: + if (cc > len) + cc = len; + len -= cc; + + fwrite (buffer, sizeof(*buffer), cc, ce->ce_fp); + if (ferror (ce->ce_fp)) { + content_error (ce->ce_file, ct, "error writing to"); + goto clean_up; + } + } + + fseek (ct->c_fp, 0L, SEEK_SET); + + if (fflush (ce->ce_fp)) { + content_error (ce->ce_file, ct, "error writing to"); + goto clean_up; + } + + fseek (ce->ce_fp, 0L, SEEK_SET); ready_to_go: - *file = ce->ce_file; - return fileno (ce->ce_fp); + *file = ce->ce_file; + return fileno (ce->ce_fp); clean_up: - free_encoding (ct, 0); - return NOTOK; + free_encoding (ct, 0); + return NOTOK; } @@ -2345,38 +2329,38 @@ clean_up: static int openExternal (CT ct, CT cb, CE ce, char **file, int *fd) { - char cachefile[BUFSIZ]; + char cachefile[BUFSIZ]; - if (ce->ce_fp) { - fseek (ce->ce_fp, 0L, SEEK_SET); - goto ready_already; - } + if (ce->ce_fp) { + fseek (ce->ce_fp, 0L, SEEK_SET); + goto ready_already; + } - if (ce->ce_file) { - if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading"); - return NOTOK; + if (ce->ce_file) { + if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading"); + return NOTOK; + } + goto ready_already; } - goto ready_already; - } - if (find_cache (ct, rcachesw, (int *) 0, cb->c_id, - cachefile, sizeof(cachefile)) != NOTOK) { - if ((ce->ce_fp = fopen (cachefile, "r"))) { - ce->ce_file = getcpy (cachefile); - ce->ce_unlink = 0; - goto ready_already; - } else { - admonish (cachefile, "unable to fopen for reading"); + if (find_cache (ct, rcachesw, (int *) 0, cb->c_id, + cachefile, sizeof(cachefile)) != NOTOK) { + if ((ce->ce_fp = fopen (cachefile, "r"))) { + ce->ce_file = getcpy (cachefile); + ce->ce_unlink = 0; + goto ready_already; + } else { + admonish (cachefile, "unable to fopen for reading"); + } } - } - return OK; + return OK; ready_already: - *file = ce->ce_file; - *fd = fileno (ce->ce_fp); - return DONE; + *file = ce->ce_file; + *fd = fileno (ce->ce_fp); + return DONE; } /* @@ -2386,78 +2370,75 @@ ready_already: static int InitFile (CT ct) { - return init_encoding (ct, openFile); + return init_encoding (ct, openFile); } static int openFile (CT ct, char **file) { - int fd, cachetype; - char cachefile[BUFSIZ]; - struct exbody *e = ct->c_ctexbody; - CE ce = ct->c_cefile; + int fd, cachetype; + char cachefile[BUFSIZ]; + struct exbody *e = ct->c_ctexbody; + CE ce = ct->c_cefile; - switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { - case NOTOK: - return NOTOK; + switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { + case NOTOK: + return NOTOK; - case OK: - break; + case OK: + break; - case DONE: - return fd; - } + case DONE: + return fd; + } - if (!e->eb_name) { - content_error (NULL, ct, "missing name parameter"); - return NOTOK; - } + if (!e->eb_name) { + content_error (NULL, ct, "missing name parameter"); + return NOTOK; + } - ce->ce_file = getcpy (e->eb_name); - ce->ce_unlink = 0; + ce->ce_file = getcpy (e->eb_name); + ce->ce_unlink = 0; - if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading"); - return NOTOK; - } + if ((ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading"); + return NOTOK; + } - if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write")) - && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id, - cachefile, sizeof(cachefile)) != NOTOK) { - int mask; - FILE *fp; + if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write")) + && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id, + cachefile, sizeof(cachefile)) != NOTOK) { + int mask; + FILE *fp; - mask = umask (cachetype ? ~m_gmprot () : 0222); - if ((fp = fopen (cachefile, "w"))) { - int cc; - char buffer[BUFSIZ]; - FILE *gp = ce->ce_fp; + mask = umask (cachetype ? ~m_gmprot () : 0222); + if ((fp = fopen (cachefile, "w"))) { + int cc; + char buffer[BUFSIZ]; + FILE *gp = ce->ce_fp; - fseek (gp, 0L, SEEK_SET); + fseek (gp, 0L, SEEK_SET); - while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) - > 0) - fwrite (buffer, sizeof(*buffer), cc, fp); - fflush (fp); + while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) > 0) + fwrite (buffer, sizeof(*buffer), cc, fp); + fflush (fp); - if (ferror (gp)) { - admonish (ce->ce_file, "error reading"); - unlink (cachefile); - } - else - if (ferror (fp)) { - admonish (cachefile, "error writing"); - unlink (cachefile); + if (ferror (gp)) { + admonish (ce->ce_file, "error reading"); + unlink (cachefile); + } else if (ferror (fp)) { + admonish (cachefile, "error writing"); + unlink (cachefile); + } + fclose (fp); } - fclose (fp); + umask (mask); } - umask (mask); - } - fseek (ce->ce_fp, 0L, SEEK_SET); - *file = ce->ce_file; - return fileno (ce->ce_fp); + fseek (ce->ce_fp, 0L, SEEK_SET); + *file = ce->ce_file; + return fileno (ce->ce_fp); } /* @@ -2467,224 +2448,219 @@ openFile (CT ct, char **file) static int InitFTP (CT ct) { - return init_encoding (ct, openFTP); + return init_encoding (ct, openFTP); } static int openFTP (CT ct, char **file) { - int cachetype, caching, fd; - int len, buflen; - char *bp, *ftp, *user, *pass; - char buffer[BUFSIZ], cachefile[BUFSIZ]; - struct exbody *e; - CE ce; - static char *username = NULL; - static char *password = NULL; + int cachetype, caching, fd; + int len, buflen; + char *bp, *ftp, *user, *pass; + char buffer[BUFSIZ], cachefile[BUFSIZ]; + struct exbody *e; + CE ce; + static char *username = NULL; + static char *password = NULL; - e = ct->c_ctexbody; - ce = ct->c_cefile; + e = ct->c_ctexbody; + ce = ct->c_cefile; - if ((ftp = context_find (nmhaccessftp)) && !*ftp) - ftp = NULL; + if ((ftp = context_find (nmhaccessftp)) && !*ftp) + ftp = NULL; #ifndef BUILTIN_FTP - if (!ftp) - return NOTOK; + if (!ftp) + return NOTOK; #endif - switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { - case NOTOK: - return NOTOK; + switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { + case NOTOK: + return NOTOK; - case OK: - break; + case OK: + break; - case DONE: - return fd; - } + case DONE: + return fd; + } - if (!e->eb_name || !e->eb_site) { - content_error (NULL, ct, "missing %s parameter", - e->eb_name ? "site": "name"); - return NOTOK; - } - - if (xpid) { - if (xpid < 0) - xpid = -xpid; - pidcheck (pidwait (xpid, NOTOK)); - xpid = 0; - } - - /* Get the buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - /* - * Construct the query message for user - */ - snprintf (bp, buflen, "Retrieve %s", e->eb_name); - len = strlen (bp); - bp += len; - buflen -= len; - - if (e->eb_partno) { - snprintf (bp, buflen, " (content %s)", e->eb_partno); + if (!e->eb_name || !e->eb_site) { + content_error (NULL, ct, "missing %s parameter", + e->eb_name ? "site": "name"); + return NOTOK; + } + + if (xpid) { + if (xpid < 0) + xpid = -xpid; + pidcheck (pidwait (xpid, NOTOK)); + xpid = 0; + } + + /* Get the buffer ready to go */ + bp = buffer; + buflen = sizeof(buffer); + + /* + * Construct the query message for user + */ + snprintf (bp, buflen, "Retrieve %s", e->eb_name); len = strlen (bp); bp += len; buflen -= len; - } - snprintf (bp, buflen, "\n using %sFTP from site %s", - e->eb_flags ? "anonymous " : "", e->eb_site); - len = strlen (bp); - bp += len; - buflen -= len; + if (e->eb_partno) { + snprintf (bp, buflen, " (content %s)", e->eb_partno); + len = strlen (bp); + bp += len; + buflen -= len; + } - if (e->eb_size > 0) { - snprintf (bp, buflen, " (%lu octets)", e->eb_size); + snprintf (bp, buflen, "\n using %sFTP from site %s", + e->eb_flags ? "anonymous " : "", e->eb_site); len = strlen (bp); bp += len; buflen -= len; - } - snprintf (bp, buflen, "? "); - /* - * Now, check the answer - */ - if (!getanswer (buffer)) - return NOTOK; + if (e->eb_size > 0) { + snprintf (bp, buflen, " (%lu octets)", e->eb_size); + len = strlen (bp); + bp += len; + buflen -= len; + } + snprintf (bp, buflen, "? "); + + /* + * Now, check the answer + */ + if (!getanswer (buffer)) + return NOTOK; + + if (e->eb_flags) { + user = "anonymous"; + snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), LocalName ()); + pass = buffer; + } else { + ruserpass (e->eb_site, &username, &password); + user = username; + pass = password; + } - if (e->eb_flags) { - user = "anonymous"; - snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), LocalName ()); - pass = buffer; - } else { - ruserpass (e->eb_site, &username, &password); - user = username; - pass = password; - } - - ce->ce_unlink = (*file == NULL); - caching = 0; - cachefile[0] = '\0'; - if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write")) - && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id, + ce->ce_unlink = (*file == NULL); + caching = 0; + cachefile[0] = '\0'; + if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write")) + && find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id, cachefile, sizeof(cachefile)) != NOTOK) { - if (*file == NULL) { - ce->ce_unlink = 0; - caching = 1; + if (*file == NULL) { + ce->ce_unlink = 0; + caching = 1; + } } - } - if (*file) - ce->ce_file = add (*file, NULL); - else if (caching) - ce->ce_file = add (cachefile, NULL); - else - ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); + if (*file) + ce->ce_file = add (*file, NULL); + else if (caching) + ce->ce_file = add (cachefile, NULL); + else + ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } #ifdef BUILTIN_FTP - if (ftp) + if (ftp) #endif - { - int child_id, i, vecp; - char *vec[9]; - - vecp = 0; - vec[vecp++] = r1bindex (ftp, '/'); - vec[vecp++] = e->eb_site; - vec[vecp++] = user; - vec[vecp++] = pass; - vec[vecp++] = e->eb_dir; - vec[vecp++] = e->eb_name; - vec[vecp++] = ce->ce_file, - vec[vecp++] = e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii") - ? "ascii" : "binary"; - vec[vecp] = NULL; - - fflush (stdout); - - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - adios ("fork", "unable to"); - /* NOTREACHED */ - - case OK: - close (fileno (ce->ce_fp)); - execvp (ftp, vec); - fprintf (stderr, "unable to exec "); - perror (ftp); - _exit (-1); - /* NOTREACHED */ - - default: - if (pidXwait (child_id, NULL)) { + { + int child_id, i, vecp; + char *vec[9]; + + vecp = 0; + vec[vecp++] = r1bindex (ftp, '/'); + vec[vecp++] = e->eb_site; + vec[vecp++] = user; + vec[vecp++] = pass; + vec[vecp++] = e->eb_dir; + vec[vecp++] = e->eb_name; + vec[vecp++] = ce->ce_file, + vec[vecp++] = e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii") + ? "ascii" : "binary"; + vec[vecp] = NULL; + + fflush (stdout); + + for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + adios ("fork", "unable to"); + /* NOTREACHED */ + + case OK: + close (fileno (ce->ce_fp)); + execvp (ftp, vec); + fprintf (stderr, "unable to exec "); + perror (ftp); + _exit (-1); + /* NOTREACHED */ + + default: + if (pidXwait (child_id, NULL)) { #ifdef BUILTIN_FTP losing_ftp: #endif - username = password = NULL; - ce->ce_unlink = 1; - return NOTOK; + username = password = NULL; + ce->ce_unlink = 1; + return NOTOK; + } + break; } - break; } - } #ifdef BUILTIN_FTP - else - if (ftp_get (e->eb_site, user, pass, e->eb_dir, e->eb_name, - ce->ce_file, - e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii"), 0) - == NOTOK) - goto losing_ftp; + else if (ftp_get (e->eb_site, user, pass, e->eb_dir, e->eb_name, + ce->ce_file, e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii"), 0) + == NOTOK) + goto losing_ftp; #endif - if (cachefile[0]) { - if (caching) - chmod (cachefile, cachetype ? m_gmprot () : 0444); - else { - int mask; - FILE *fp; - - mask = umask (cachetype ? ~m_gmprot () : 0222); - if ((fp = fopen (cachefile, "w"))) { - int cc; - FILE *gp = ce->ce_fp; - - fseek (gp, 0L, SEEK_SET); - - while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) - > 0) - fwrite (buffer, sizeof(*buffer), cc, fp); - fflush (fp); - - if (ferror (gp)) { - admonish (ce->ce_file, "error reading"); - unlink (cachefile); + if (cachefile[0]) { + if (caching) + chmod (cachefile, cachetype ? m_gmprot () : 0444); + else { + int mask; + FILE *fp; + + mask = umask (cachetype ? ~m_gmprot () : 0222); + if ((fp = fopen (cachefile, "w"))) { + int cc; + FILE *gp = ce->ce_fp; + + fseek (gp, 0L, SEEK_SET); + + while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) > 0) + fwrite (buffer, sizeof(*buffer), cc, fp); + fflush (fp); + + if (ferror (gp)) { + admonish (ce->ce_file, "error reading"); + unlink (cachefile); + } else if (ferror (fp)) { + admonish (cachefile, "error writing"); + unlink (cachefile); + } + fclose (fp); + } + umask (mask); } - else - if (ferror (fp)) { - admonish (cachefile, "error writing"); - unlink (cachefile); - } - fclose (fp); - } - umask (mask); } - } - fseek (ce->ce_fp, 0L, SEEK_SET); - *file = ce->ce_file; - return fileno (ce->ce_fp); + fseek (ce->ce_fp, 0L, SEEK_SET); + *file = ce->ce_file; + return fileno (ce->ce_fp); } @@ -2695,197 +2671,195 @@ losing_ftp: static int InitMail (CT ct) { - return init_encoding (ct, openMail); + return init_encoding (ct, openMail); } static int openMail (CT ct, char **file) { - int child_id, fd, i, vecp; - int len, buflen; - char *bp, buffer[BUFSIZ], *vec[7]; - struct exbody *e = ct->c_ctexbody; - CE ce = ct->c_cefile; + int child_id, fd, i, vecp; + int len, buflen; + char *bp, buffer[BUFSIZ], *vec[7]; + struct exbody *e = ct->c_ctexbody; + CE ce = ct->c_cefile; + + switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { + case NOTOK: + return NOTOK; - switch (openExternal (e->eb_parent, e->eb_content, ce, file, &fd)) { - case NOTOK: - return NOTOK; + case OK: + break; - case OK: - break; + case DONE: + return fd; + } - case DONE: - return fd; - } + if (!e->eb_server) { + content_error (NULL, ct, "missing server parameter"); + return NOTOK; + } - if (!e->eb_server) { - content_error (NULL, ct, "missing server parameter"); - return NOTOK; - } - - if (xpid) { - if (xpid < 0) - xpid = -xpid; - pidcheck (pidwait (xpid, NOTOK)); - xpid = 0; - } - - /* Get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - /* Now, construct query message */ - snprintf (bp, buflen, "Retrieve content"); - len = strlen (bp); - bp += len; - buflen -= len; - - if (e->eb_partno) { - snprintf (bp, buflen, " %s", e->eb_partno); + if (xpid) { + if (xpid < 0) + xpid = -xpid; + pidcheck (pidwait (xpid, NOTOK)); + xpid = 0; + } + + /* Get buffer ready to go */ + bp = buffer; + buflen = sizeof(buffer); + + /* Now, construct query message */ + snprintf (bp, buflen, "Retrieve content"); len = strlen (bp); bp += len; buflen -= len; - } - snprintf (bp, buflen, " by asking %s\n\n%s\n? ", - e->eb_server, - e->eb_subject ? e->eb_subject : e->eb_body); + if (e->eb_partno) { + snprintf (bp, buflen, " %s", e->eb_partno); + len = strlen (bp); + bp += len; + buflen -= len; + } - /* Now, check answer */ - if (!getanswer (buffer)) - return NOTOK; + snprintf (bp, buflen, " by asking %s\n\n%s\n? ", e->eb_server, + e->eb_subject ? e->eb_subject : e->eb_body); - vecp = 0; - vec[vecp++] = r1bindex (mailproc, '/'); - vec[vecp++] = e->eb_server; - vec[vecp++] = "-subject"; - vec[vecp++] = e->eb_subject ? e->eb_subject : "mail-server request"; - vec[vecp++] = "-body"; - vec[vecp++] = e->eb_body; - vec[vecp] = NULL; - - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - advise ("fork", "unable to"); - return NOTOK; - - case OK: - execvp (mailproc, vec); - fprintf (stderr, "unable to exec "); - perror (mailproc); - _exit (-1); - /* NOTREACHED */ - - default: - if (pidXwait (child_id, NULL) == OK) - advise (NULL, "request sent"); - break; - } - - if (*file == NULL) { - ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); - ce->ce_unlink = 1; - } else { - ce->ce_file = add (*file, NULL); - ce->ce_unlink = 0; - } + /* Now, check answer */ + if (!getanswer (buffer)) + return NOTOK; - if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { - content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); - return NOTOK; - } + vecp = 0; + vec[vecp++] = r1bindex (mailproc, '/'); + vec[vecp++] = e->eb_server; + vec[vecp++] = "-subject"; + vec[vecp++] = e->eb_subject ? e->eb_subject : "mail-server request"; + vec[vecp++] = "-body"; + vec[vecp++] = e->eb_body; + vec[vecp] = NULL; + + for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + advise ("fork", "unable to"); + return NOTOK; + + case OK: + execvp (mailproc, vec); + fprintf (stderr, "unable to exec "); + perror (mailproc); + _exit (-1); + /* NOTREACHED */ - /* showproc is for mhshow and mhstore, though mhlist -debug - * prints it, too. */ - if (ct->c_showproc) - free (ct->c_showproc); - ct->c_showproc = add ("true", NULL); + default: + if (pidXwait (child_id, NULL) == OK) + advise (NULL, "request sent"); + break; + } - fseek (ce->ce_fp, 0L, SEEK_SET); - *file = ce->ce_file; - return fileno (ce->ce_fp); + if (*file == NULL) { + ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL); + ce->ce_unlink = 1; + } else { + ce->ce_file = add (*file, NULL); + ce->ce_unlink = 0; + } + + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } + + /* showproc is for mhshow and mhstore, though mhlist -debug + * prints it, too. */ + if (ct->c_showproc) + free (ct->c_showproc); + ct->c_showproc = add ("true", NULL); + + fseek (ce->ce_fp, 0L, SEEK_SET); + *file = ce->ce_file; + return fileno (ce->ce_fp); } static int readDigest (CT ct, char *cp) { - int bitno, skip; - unsigned long bits; - char *bp = cp; - unsigned char *dp, value, *ep; - unsigned char *b, *b1, *b2, *b3; - - b = (unsigned char *) &bits, - b1 = &b[endian > 0 ? 1 : 2], - b2 = &b[endian > 0 ? 2 : 1], - b3 = &b[endian > 0 ? 3 : 0]; - bitno = 18; - bits = 0L; - skip = 0; - - for (ep = (dp = ct->c_digest) - + sizeof(ct->c_digest) / sizeof(ct->c_digest[0]); *cp; cp++) - switch (*cp) { - default: - if (skip - || (*cp & 0x80) - || (value = b642nib[*cp & 0x7f]) > 0x3f) { - if (debugsw) - fprintf (stderr, "invalid BASE64 encoding\n"); - return NOTOK; - } - - bits |= value << bitno; + int bitno, skip; + unsigned long bits; + char *bp = cp; + unsigned char *dp, value, *ep; + unsigned char *b, *b1, *b2, *b3; + + b = (unsigned char *) &bits, + b1 = &b[endian > 0 ? 1 : 2], + b2 = &b[endian > 0 ? 2 : 1], + b3 = &b[endian > 0 ? 3 : 0]; + bitno = 18; + bits = 0L; + skip = 0; + + for (ep = (dp = ct->c_digest) + + sizeof(ct->c_digest) / sizeof(ct->c_digest[0]); *cp; cp++) + switch (*cp) { + default: + if (skip || (*cp & 0x80) + || (value = b642nib[*cp & 0x7f]) > 0x3f) { + if (debugsw) + fprintf (stderr, "invalid BASE64 encoding\n"); + return NOTOK; + } + + bits |= value << bitno; test_end: - if ((bitno -= 6) < 0) { - if (dp + (3 - skip) > ep) - goto invalid_digest; - *dp++ = *b1; - if (skip < 2) { - *dp++ = *b2; - if (skip < 1) - *dp++ = *b3; - } - bitno = 18; - bits = 0L; - skip = 0; + if ((bitno -= 6) < 0) { + if (dp + (3 - skip) > ep) + goto invalid_digest; + *dp++ = *b1; + if (skip < 2) { + *dp++ = *b2; + if (skip < 1) + *dp++ = *b3; + } + bitno = 18; + bits = 0L; + skip = 0; + } + break; + + case '=': + if (++skip > 3) + goto self_delimiting; + goto test_end; } - break; + if (bitno != 18) { + if (debugsw) + fprintf (stderr, "premature ending (bitno %d)\n", bitno); - case '=': - if (++skip > 3) - goto self_delimiting; - goto test_end; + return NOTOK; } - if (bitno != 18) { - if (debugsw) - fprintf (stderr, "premature ending (bitno %d)\n", bitno); - - return NOTOK; - } self_delimiting: - if (dp != ep) { + if (dp != ep) { invalid_digest: - if (debugsw) { - while (*cp) - cp++; - fprintf (stderr, "invalid MD5 digest (got %d octets)\n", - (int)(cp - bp)); - } + if (debugsw) { + while (*cp) + cp++; + fprintf (stderr, "invalid MD5 digest (got %d octets)\n", + (int)(cp - bp)); + } - return NOTOK; - } + return NOTOK; + } - if (debugsw) { - fprintf (stderr, "MD5 digest="); - for (dp = ct->c_digest; dp < ep; dp++) - fprintf (stderr, "%02x", *dp & 0xff); - fprintf (stderr, "\n"); - } + if (debugsw) { + fprintf (stderr, "MD5 digest="); + for (dp = ct->c_digest; dp < ep; dp++) + fprintf (stderr, "%02x", *dp & 0xff); + fprintf (stderr, "\n"); + } - return OK; + return OK; } diff --git a/uip/mhpath.c b/uip/mhpath.c index 23ca542..aa38bbe 100644 --- a/uip/mhpath.c +++ b/uip/mhpath.c @@ -1,4 +1,3 @@ - /* * mhpath.c -- print full pathnames of nmh messages and folders * @@ -12,115 +11,115 @@ static struct swit switches[] = { #define VERSIONSW 0 - { "version", 0 }, -#define HELPSW 1 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 1 + { "help", 0 }, + { NULL, 0 } }; int main(int argc, char **argv) { - int i; - char *cp, *maildir, *folder = NULL; - char **argp; - char **arguments, buf[BUFSIZ]; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; + int i; + char *cp, *maildir, *folder = NULL; + char **argp; + char **arguments, buf[BUFSIZ]; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); + } + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + /* If no messages are given, print folder pathname */ + if (!msgs.size) { + printf ("%s\n", maildir); + done (0); + } + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* + * We need to make sure there is message status space + * for all the message numbers from 1 to "new" since + * mhpath can select empty slots. If we are adding + * space at the end, we go ahead and add 10 slots. + */ + if (mp->hghmsg >= mp->hghoff) { + if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10))) + adios (NULL, "unable to allocate folder storage"); + } else if (mp->lowoff > 1) { + if (!(mp = folder_realloc (mp, 1, mp->hghoff))) + adios (NULL, "unable to allocate folder storage"); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - /* If no messages are given, print folder pathname */ - if (!msgs.size) { - printf ("%s\n", maildir); + + mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */ + + /* parse all the message ranges/sequences and set SELECTED */ + for (i = 0; i < msgs.size; i++) + if (!m_convert (mp, msgs.msgs[i])) + done (1); + + seq_setprev (mp); /* set the previous-sequence */ + + /* print the path of all selected messages */ + for (i = mp->lowsel; i <= mp->hghsel; i++) + if (is_selected (mp, i)) + printf ("%s/%s\n", mp->foldpath, m_name (i)); + + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ done (0); - } - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* - * We need to make sure there is message status space - * for all the message numbers from 1 to "new" since - * mhpath can select empty slots. If we are adding - * space at the end, we go ahead and add 10 slots. - */ - if (mp->hghmsg >= mp->hghoff) { - if (!(mp = folder_realloc (mp, 1, mp->hghmsg + 10))) - adios (NULL, "unable to allocate folder storage"); - } else if (mp->lowoff > 1) { - if (!(mp = folder_realloc (mp, 1, mp->hghoff))) - adios (NULL, "unable to allocate folder storage"); - } - - mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */ - - /* parse all the message ranges/sequences and set SELECTED */ - for (i = 0; i < msgs.size; i++) - if (!m_convert (mp, msgs.msgs[i])) - done (1); - - seq_setprev (mp); /* set the previous-sequence */ - - /* print the path of all selected messages */ - for (i = mp->lowsel; i <= mp->hghsel; i++) - if (is_selected (mp, i)) - printf ("%s/%s\n", mp->foldpath, m_name (i)); - - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + return 1; } diff --git a/uip/mhshow.c b/uip/mhshow.c index 191eeff..bbb7fb8 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -1,4 +1,3 @@ - /* * mhshow.c -- display the contents of MIME messages * @@ -25,62 +24,62 @@ #endif static struct swit switches[] = { -#define CHECKSW 0 - { "check", 0 }, -#define NCHECKSW 1 - { "nocheck", 0 }, -#define PAUSESW 2 - { "pause", 0 }, -#define NPAUSESW 3 - { "nopause", 0 }, -#define SERIALSW 4 - { "serialonly", 0 }, -#define NSERIALSW 5 - { "noserialonly", 0 }, -#define VERBSW 6 - { "verbose", 0 }, -#define NVERBSW 7 - { "noverbose", 0 }, -#define FILESW 8 /* interface from show */ - { "file file", 0 }, -#define FORMSW 9 - { "form formfile", 0 }, -#define PARTSW 10 - { "part number", 0 }, -#define TYPESW 11 - { "type content", 0 }, -#define RCACHESW 12 - { "rcache policy", 0 }, -#define WCACHESW 13 - { "wcache policy", 0 }, -#define VERSIONSW 14 - { "version", 0 }, -#define HELPSW 15 - { "help", 0 }, +#define CHECKSW 0 + { "check", 0 }, +#define NCHECKSW 1 + { "nocheck", 0 }, +#define PAUSESW 2 + { "pause", 0 }, +#define NPAUSESW 3 + { "nopause", 0 }, +#define SERIALSW 4 + { "serialonly", 0 }, +#define NSERIALSW 5 + { "noserialonly", 0 }, +#define VERBSW 6 + { "verbose", 0 }, +#define NVERBSW 7 + { "noverbose", 0 }, +#define FILESW 8 /* interface from show */ + { "file file", 0 }, +#define FORMSW 9 + { "form formfile", 0 }, +#define PARTSW 10 + { "part number", 0 }, +#define TYPESW 11 + { "type content", 0 }, +#define RCACHESW 12 + { "rcache policy", 0 }, +#define WCACHESW 13 + { "wcache policy", 0 }, +#define VERSIONSW 14 + { "version", 0 }, +#define HELPSW 15 + { "help", 0 }, /* * switches for moreproc/mhlproc */ -#define PROGSW 16 - { "moreproc program", -4 }, -#define NPROGSW 17 - { "nomoreproc", -3 }, -#define LENSW 18 - { "length lines", -4 }, -#define WIDTHSW 19 - { "width columns", -4 }, +#define PROGSW 16 + { "moreproc program", -4 }, +#define NPROGSW 17 + { "nomoreproc", -3 }, +#define LENSW 18 + { "length lines", -4 }, +#define WIDTHSW 19 + { "width columns", -4 }, /* * switches for debugging */ -#define DEBUGSW 20 - { "debug", -5 }, - { NULL, 0 } +#define DEBUGSW 20 + { "debug", -5 }, + { NULL, 0 } }; /* mhparse.c */ -extern char *tmp; /* directory to place temp files */ +extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ extern int rcachesw; @@ -93,7 +92,7 @@ extern int pausesw; extern int serialsw; extern char *progsw; extern int nolist; -extern int nomore; /* flags for moreproc/header display */ +extern int nomore; /* flags for moreproc/header display */ extern char *formsw; /* mhmisc.c */ @@ -106,7 +105,7 @@ extern int userrs; int debugsw = 0; int verbosw = 0; -#define quitser pipeser +#define quitser pipeser /* mhparse.c */ CT parse_mime (char *); @@ -134,337 +133,337 @@ static RETSIGTYPE pipeser (int); int main (int argc, char **argv) { - int msgnum, *icachesw; - char *cp, *file = NULL, *folder = NULL; - char *maildir, buf[100], **argp; - char **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp = NULL; - CT ct, *ctp; - FILE *fp; + int msgnum, *icachesw; + char *cp, *file = NULL, *folder = NULL; + char *maildir, buf[100], **argp; + char **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp = NULL; + CT ct, *ctp; + FILE *fp; - done=freects_done; + done=freects_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + invo_name = r1bindex (argv[0], '/'); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; - case RCACHESW: - icachesw = &rcachesw; - goto do_cache; - case WCACHESW: - icachesw = &wcachesw; + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case RCACHESW: + icachesw = &rcachesw; + goto do_cache; + case WCACHESW: + icachesw = &wcachesw; do_cache: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - switch (*icachesw = smatch (cp, caches)) { - case AMBIGSW: - ambigsw (cp, caches); - done (1); - case UNKWNSW: - adios (NULL, "%s unknown", cp); - default: - break; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + switch (*icachesw = smatch (cp, caches)) { + case AMBIGSW: + ambigsw (cp, caches); + done (1); + case UNKWNSW: + adios (NULL, "%s unknown", cp); + default: + break; + } + continue; + + case CHECKSW: + checksw++; + continue; + case NCHECKSW: + checksw = 0; + continue; + + case PAUSESW: + pausesw = 1; + continue; + case NPAUSESW: + pausesw = 0; + continue; + + case SERIALSW: + serialsw = 1; + continue; + case NSERIALSW: + serialsw = 0; + continue; + + case PARTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (npart >= NPARTS) + adios (NULL, "too many parts (starting with %s), %d max", + cp, NPARTS); + parts[npart++] = cp; + continue; + + case TYPESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (ntype >= NTYPES) + adios (NULL, "too many types (starting with %s), %d max", + cp, NTYPES); + types[ntype++] = cp; + continue; + + case FILESW: + if (!(cp = *argp++) || (*cp == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + file = *cp == '-' ? cp : path (cp, TFILE); + continue; + + case FORMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (formsw) + free (formsw); + formsw = getcpy (etcpath (cp)); + continue; + + /* + * Switches for moreproc/mhlproc + */ + case PROGSW: + if (!(progsw = *argp++) || *progsw == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NPROGSW: + nomore++; + continue; + + case LENSW: + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case VERBSW: + verbosw = 1; + continue; + case NVERBSW: + verbosw = 0; + continue; + case DEBUGSW: + debugsw = 1; + continue; + } } - continue; - - case CHECKSW: - checksw++; - continue; - case NCHECKSW: - checksw = 0; - continue; - - case PAUSESW: - pausesw = 1; - continue; - case NPAUSESW: + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); + } + + /* null terminate the list of acceptable parts/types */ + parts[npart] = NULL; + types[ntype] = NULL; + + set_endian (); + + if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1")) { + nolist = 1; pausesw = 0; - continue; - - case SERIALSW: - serialsw = 1; - continue; - case NSERIALSW: - serialsw = 0; - continue; - - case PARTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (npart >= NPARTS) - adios (NULL, "too many parts (starting with %s), %d max", - cp, NPARTS); - parts[npart++] = cp; - continue; - - case TYPESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (ntype >= NTYPES) - adios (NULL, "too many types (starting with %s), %d max", - cp, NTYPES); - types[ntype++] = cp; - continue; - - case FILESW: - if (!(cp = *argp++) || (*cp == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - file = *cp == '-' ? cp : path (cp, TFILE); - continue; - - case FORMSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (formsw) - free (formsw); - formsw = getcpy (etcpath (cp)); - continue; - - /* - * Switches for moreproc/mhlproc - */ - case PROGSW: - if (!(progsw = *argp++) || *progsw == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NPROGSW: - nomore++; - continue; - - case LENSW: - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case VERBSW: - verbosw = 1; - continue; - case NVERBSW: - verbosw = 0; - continue; - case DEBUGSW: - debugsw = 1; - continue; - } } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* null terminate the list of acceptable parts/types */ - parts[npart] = NULL; - types[ntype] = NULL; - - set_endian (); - - if ((cp = getenv ("MM_NOASK")) && !strcmp (cp, "1")) { - nolist = 1; - pausesw = 0; - } - - /* - * Check if we've specified an additional profile - */ - if ((cp = getenv ("MHSHOW"))) { - if ((fp = fopen (cp, "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } else { - admonish ("", "unable to read $MHSHOW profile (%s)", cp); + + /* + * Check if we've specified an additional profile + */ + if ((cp = getenv ("MHSHOW"))) { + if ((fp = fopen (cp, "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } else { + admonish ("", "unable to read $MHSHOW profile (%s)", cp); + } } - } - - /* - * Read the standard profile setup - */ - if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } - - /* Check for public cache location */ - if ((cache_public = context_find (nmhcache)) && *cache_public != '/') - cache_public = NULL; - - /* Check for private cache location */ - if (!(cache_private = context_find (nmhprivcache))) - cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); - - /* - * Check for storage directory. If specified, - * then store temporary files there. Else we - * store them in standard nmh directory. - */ - if ((cp = context_find (nmhstorage)) && *cp) - tmp = concat (cp, "/", invo_name, NULL); - else - tmp = add (m_maildir (invo_name), NULL); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (file && msgs.size) - adios (NULL, "cannot specify msg and file at same time!"); - - /* - * check if message is coming from file - */ - if (file) { - if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; - - if ((ct = parse_mime (file))); - *ctp++ = ct; - } else { + /* - * message(s) are coming from a folder + * Read the standard profile setup */ - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); + if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } + + /* Check for public cache location */ + if ((cache_public = context_find (nmhcache)) && *cache_public != '/') + cache_public = NULL; + + /* Check for private cache location */ + if (!(cache_private = context_find (nmhprivcache))) + cache_private = ".cache"; + cache_private = getcpy (m_maildir (cache_private)); /* - * Set the SELECT_UNSEEN bit for all the SELECTED messages, - * since we will use that as a tag to know which messages - * to remove from the "unseen" sequence. + * Check for storage directory. If specified, + * then store temporary files there. Else we + * store them in standard nmh directory. */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected(mp, msgnum)) - set_unseen (mp, msgnum); + if ((cp = context_find (nmhstorage)) && *cp) + tmp = concat (cp, "/", invo_name, NULL); + else + tmp = add (m_maildir (invo_name), NULL); - seq_setprev (mp); /* set the Previous-Sequence */ - seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ + if (!context_find ("path")) + free (path ("./", TFOLDER)); - if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; + if (file && msgs.size) + adios (NULL, "cannot specify msg and file at same time!"); /* - * Parse all the SELECTED messages. + * check if message is coming from file */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - char *msgnam; - - msgnam = m_name (msgnum); - if ((ct = parse_mime (msgnam))) - *ctp++ = ct; - } + if (file) { + if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + if ((ct = parse_mime (file))); + *ctp++ = ct; + } else { + /* + * message(s) are coming from a folder + */ + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + + /* + * Set the SELECT_UNSEEN bit for all the SELECTED messages, + * since we will use that as a tag to know which messages + * to remove from the "unseen" sequence. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected(mp, msgnum)) + set_unseen (mp, msgnum); + + seq_setprev (mp); /* set the Previous-Sequence */ + seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ + + if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + /* + * Parse all the SELECTED messages. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + char *msgnam; + + msgnam = m_name (msgnum); + if ((ct = parse_mime (msgnam))) + *ctp++ = ct; + } + } } - } - if (!*cts) - done (1); + if (!*cts) + done (1); + + userrs = 1; + SIGNAL (SIGQUIT, quitser); + SIGNAL (SIGPIPE, pipeser); + + /* + * Get the associated umask for the relevant contents. + */ + for (ctp = cts; *ctp; ctp++) { + struct stat st; + + ct = *ctp; + if (type_ok (ct, 1) && !ct->c_umask) { + if (stat (ct->c_file, &st) != NOTOK) + ct->c_umask = ~(st.st_mode & 0777); + else + ct->c_umask = ~m_gmprot(); + } + } + + /* + * Show the message content + */ + show_all_messages (cts); + + /* Now free all the structures for the content */ + for (ctp = cts; *ctp; ctp++) + free_content (*ctp); - userrs = 1; - SIGNAL (SIGQUIT, quitser); - SIGNAL (SIGPIPE, pipeser); - - /* - * Get the associated umask for the relevant contents. - */ - for (ctp = cts; *ctp; ctp++) { - struct stat st; - - ct = *ctp; - if (type_ok (ct, 1) && !ct->c_umask) { - if (stat (ct->c_file, &st) != NOTOK) - ct->c_umask = ~(st.st_mode & 0777); - else - ct->c_umask = ~m_gmprot(); + free ((char *) cts); + cts = NULL; + + /* If reading from a folder, do some updating */ + if (mp) { + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->hghsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ } - } - - /* - * Show the message content - */ - show_all_messages (cts); - - /* Now free all the structures for the content */ - for (ctp = cts; *ctp; ctp++) - free_content (*ctp); - - free ((char *) cts); - cts = NULL; - - /* If reading from a folder, do some updating */ - if (mp) { - context_replace (pfolder, folder);/* update current folder */ - seq_setcur (mp, mp->hghsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - done (0); - return 1; + + done (0); + return 1; } static RETSIGTYPE pipeser (int i) { - if (i == SIGQUIT) { - unlink ("core"); - fflush (stdout); - fprintf (stderr, "\n"); - fflush (stderr); - } - - done (1); - /* NOTREACHED */ + if (i == SIGQUIT) { + unlink ("core"); + fflush (stdout); + fprintf (stderr, "\n"); + fflush (stderr); + } + + done (1); + /* NOTREACHED */ } diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 4a3589f..be03d96 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -1,4 +1,3 @@ - /* * mhshowsbr.c -- routines to display the contents of MIME messages * @@ -98,28 +97,28 @@ static RETSIGTYPE intrser (int); void show_all_messages (CT *cts) { - CT ct, *ctp; - - /* - * If form is not specified, then get default form - * for showing headers of MIME messages. - */ - if (!formsw) - formsw = getcpy (etcpath ("mhl.headers")); - - /* - * If form is "mhl.null", suppress display of header. - */ - if (!strcmp (formsw, "mhl.null")) - formsw = NULL; - - for (ctp = cts; *ctp; ctp++) { - ct = *ctp; - - /* if top-level type is ok, then display message */ - if (type_ok (ct, 1)) - show_single_message (ct, formsw); - } + CT ct, *ctp; + + /* + * If form is not specified, then get default form + * for showing headers of MIME messages. + */ + if (!formsw) + formsw = getcpy (etcpath ("mhl.headers")); + + /* + * If form is "mhl.null", suppress display of header. + */ + if (!strcmp (formsw, "mhl.null")) + formsw = NULL; + + for (ctp = cts; *ctp; ctp++) { + ct = *ctp; + + /* if top-level type is ok, then display message */ + if (type_ok (ct, 1)) + show_single_message (ct, formsw); + } } @@ -130,59 +129,59 @@ show_all_messages (CT *cts) static void show_single_message (CT ct, char *form) { - sigset_t set, oset; + sigset_t set, oset; #ifdef HAVE_UNION_WAIT - union wait status; + union wait status; #else - int status; + int status; #endif - /* Allow user executable bit so that temporary directories created by - * the viewer (e.g., lynx) are going to be accessible */ - umask (ct->c_umask & ~(0100)); - - /* - * If you have a format file, then display - * the message headers. - */ - if (form) - DisplayMsgHeader(ct, form); - else - xpid = 0; + /* Allow user executable bit so that temporary directories created by + * the viewer (e.g., lynx) are going to be accessible */ + umask (ct->c_umask & ~(0100)); - /* Show the body of the message */ - show_switch (ct, 1, 0); - - if (ct->c_fp) { - fclose (ct->c_fp); - ct->c_fp = NULL; - } - if (ct->c_ceclosefnx) - (*ct->c_ceclosefnx) (ct); - - /* block a few signals */ - sigemptyset (&set); - sigaddset (&set, SIGHUP); - sigaddset (&set, SIGINT); - sigaddset (&set, SIGQUIT); - sigaddset (&set, SIGTERM); - SIGPROCMASK (SIG_BLOCK, &set, &oset); - - while (wait (&status) != NOTOK) { + /* + * If you have a format file, then display + * the message headers. + */ + if (form) + DisplayMsgHeader(ct, form); + else + xpid = 0; + + /* Show the body of the message */ + show_switch (ct, 1, 0); + + if (ct->c_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } + if (ct->c_ceclosefnx) + (*ct->c_ceclosefnx) (ct); + + /* block a few signals */ + sigemptyset (&set); + sigaddset (&set, SIGHUP); + sigaddset (&set, SIGINT); + sigaddset (&set, SIGQUIT); + sigaddset (&set, SIGTERM); + SIGPROCMASK (SIG_BLOCK, &set, &oset); + + while (wait (&status) != NOTOK) { #ifdef HAVE_UNION_WAIT - pidcheck (status.w_status); + pidcheck (status.w_status); #else - pidcheck (status); + pidcheck (status); #endif - continue; - } + continue; + } - /* reset the signal mask */ - SIGPROCMASK (SIG_SETMASK, &oset, &set); + /* reset the signal mask */ + SIGPROCMASK (SIG_SETMASK, &oset, &set); - xpid = 0; - flush_errors (); + xpid = 0; + flush_errors (); } @@ -193,50 +192,50 @@ show_single_message (CT ct, char *form) static void DisplayMsgHeader (CT ct, char *form) { - pid_t child_id; - int i, vecp; - char *vec[8]; - - vecp = 0; - vec[vecp++] = r1bindex (mhlproc, '/'); - vec[vecp++] = "-form"; - vec[vecp++] = form; - vec[vecp++] = "-nobody"; - vec[vecp++] = ct->c_file; - - /* - * If we've specified -(no)moreproc, - * then just pass that along. - */ - if (nomore) { - vec[vecp++] = "-nomoreproc"; - } else if (progsw) { - vec[vecp++] = "-moreproc"; - vec[vecp++] = progsw; - } - vec[vecp] = NULL; - - fflush (stdout); - - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); - - switch (child_id) { - case NOTOK: - adios ("fork", "unable to"); - /* NOTREACHED */ - - case OK: - execvp (mhlproc, vec); - fprintf (stderr, "unable to exec "); - perror (mhlproc); - _exit (-1); - /* NOTREACHED */ - - default: - xpid = -child_id; - break; - } + pid_t child_id; + int i, vecp; + char *vec[8]; + + vecp = 0; + vec[vecp++] = r1bindex (mhlproc, '/'); + vec[vecp++] = "-form"; + vec[vecp++] = form; + vec[vecp++] = "-nobody"; + vec[vecp++] = ct->c_file; + + /* + * If we've specified -(no)moreproc, + * then just pass that along. + */ + if (nomore) { + vec[vecp++] = "-nomoreproc"; + } else if (progsw) { + vec[vecp++] = "-moreproc"; + vec[vecp++] = progsw; + } + vec[vecp] = NULL; + + fflush (stdout); + + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); + + switch (child_id) { + case NOTOK: + adios ("fork", "unable to"); + /* NOTREACHED */ + + case OK: + execvp (mhlproc, vec); + fprintf (stderr, "unable to exec "); + perror (mhlproc); + _exit (-1); + /* NOTREACHED */ + + default: + xpid = -child_id; + break; + } } @@ -248,45 +247,45 @@ DisplayMsgHeader (CT ct, char *form) static int show_switch (CT ct, int serial, int alternate) { - switch (ct->c_type) { - case CT_MULTIPART: - return show_multi (ct, serial, alternate); - break; - - case CT_MESSAGE: - switch (ct->c_subtype) { - case MESSAGE_PARTIAL: - return show_partial (ct, serial, alternate); - break; - - case MESSAGE_EXTERNAL: - return show_external (ct, serial, alternate); - break; - - case MESSAGE_RFC822: - default: - return show_message_rfc822 (ct, serial, alternate); - break; - } - break; - - case CT_TEXT: - return show_text (ct, serial, alternate); - break; - - case CT_AUDIO: - case CT_IMAGE: - case CT_VIDEO: - case CT_APPLICATION: - return show_content (ct, serial, alternate); - break; + switch (ct->c_type) { + case CT_MULTIPART: + return show_multi (ct, serial, alternate); + break; - default: - adios (NULL, "unknown content type %d", ct->c_type); - break; - } + case CT_MESSAGE: + switch (ct->c_subtype) { + case MESSAGE_PARTIAL: + return show_partial (ct, serial, alternate); + break; + + case MESSAGE_EXTERNAL: + return show_external (ct, serial, alternate); + break; + + case MESSAGE_RFC822: + default: + return show_message_rfc822 (ct, serial, alternate); + break; + } + break; - return 0; /* NOT REACHED */ + case CT_TEXT: + return show_text (ct, serial, alternate); + break; + + case CT_AUDIO: + case CT_IMAGE: + case CT_VIDEO: + case CT_APPLICATION: + return show_content (ct, serial, alternate); + break; + + default: + adios (NULL, "unknown content type %d", ct->c_type); + break; + } + + return 0; /* NOT REACHED */ } @@ -297,28 +296,28 @@ show_switch (CT ct, int serial, int alternate) static int show_content (CT ct, int serial, int alternate) { - char *cp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + char *cp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - /* Check for mhshow-show-type/subtype */ - snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); + /* Check for mhshow-show-type/subtype */ + snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); - /* Check for mhshow-show-type */ - snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); + /* Check for mhshow-show-type */ + snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); - if ((cp = ct->c_showproc)) - return show_content_aux (ct, serial, alternate, cp, NULL); + if ((cp = ct->c_showproc)) + return show_content_aux (ct, serial, alternate, cp, NULL); - /* complain if we are not a part of a multipart/alternative */ - if (!alternate) - content_error (NULL, ct, "don't know how to display content"); + /* complain if we are not a part of a multipart/alternative */ + if (!alternate) + content_error (NULL, ct, "don't know how to display content"); - return NOTOK; + return NOTOK; } @@ -329,187 +328,187 @@ show_content (CT ct, int serial, int alternate) int show_content_aux (CT ct, int serial, int alternate, char *cp, char *cracked) { - int fd, len, buflen, quoted; - int xstdin, xlist, xpause, xtty; - char *bp, *pp, *file, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + int fd, len, buflen, quoted; + int xstdin, xlist, xpause, xtty; + char *bp, *pp, *file, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - if (!ct->c_ceopenfnx) { - if (!alternate) - content_error (NULL, ct, "don't know how to decode content"); - - return NOTOK; - } + if (!ct->c_ceopenfnx) { + if (!alternate) + content_error (NULL, ct, "don't know how to decode content"); - file = NULL; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return NOTOK; - if (ct->c_showproc && !strcmp (ct->c_showproc, "true")) - return (alternate ? DONE : OK); - - xlist = 0; - xpause = 0; - xstdin = 0; - xtty = 0; - - if (cracked) { - strncpy (buffer, cp, sizeof(buffer)); - goto got_command; - } - - /* get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer) - 1; - bp[0] = bp[buflen] = '\0'; - quoted = 0; - - /* Now parse display string */ - for ( ; *cp && buflen > 0; cp++) { - if (*cp == '%') { - pp = bp; - - switch (*++cp) { - case 'a': - /* insert parameters from Content-Type field */ - { - char **ap, **ep; - char *s = ""; - - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); - len = strlen (bp); - bp += len; - buflen -= len; - s = " "; - } - } - break; - - case 'd': - /* insert content description */ - if (ct->c_descr) { - char *s; - - s = trimcpy (ct->c_descr); - strncpy (bp, s, buflen); - free (s); - } - break; - - case 'e': - /* exclusive execution */ - xtty = 1; - break; - - case 'F': - /* %e, %f, and stdin is terminal not content */ - xstdin = 1; - xtty = 1; - /* and fall... */ - - case 'f': - /* insert filename containing content */ - snprintf (bp, buflen, "'%s'", file); - /* since we've quoted the file argument, set things up - * to look past it, to avoid problems with the quoting - * logic below. (I know, I should figure out what's - * broken with the quoting logic, but..) - */ - len = strlen(bp); - buflen -= len; - bp += len; - pp = bp; - break; + return NOTOK; + } - case 'p': - /* %l, and pause prior to displaying content */ - xpause = pausesw; - /* and fall... */ + file = NULL; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return NOTOK; + if (ct->c_showproc && !strcmp (ct->c_showproc, "true")) + return (alternate ? DONE : OK); - case 'l': - /* display listing prior to displaying content */ - xlist = !nolist; - break; + xlist = 0; + xpause = 0; + xstdin = 0; + xtty = 0; - case 's': - /* insert subtype of content */ - strncpy (bp, ci->ci_subtype, buflen); - break; + if (cracked) { + strncpy (buffer, cp, sizeof(buffer)); + goto got_command; + } - case '%': - /* insert character % */ - goto raw; + /* get buffer ready to go */ + bp = buffer; + buflen = sizeof(buffer) - 1; + bp[0] = bp[buflen] = '\0'; + quoted = 0; + + /* Now parse display string */ + for ( ; *cp && buflen > 0; cp++) { + if (*cp == '%') { + pp = bp; + + switch (*++cp) { + case 'a': + /* insert parameters from Content-Type field */ + { + char **ap, **ep; + char *s = ""; + + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); + len = strlen (bp); + bp += len; + buflen -= len; + s = " "; + } + } + break; - default: - *bp++ = *--cp; - *bp = '\0'; - buflen--; - continue; - } - len = strlen (bp); - bp += len; - buflen -= len; - - /* Did we actually insert something? */ - if (bp != pp) { - /* Insert single quote if not inside quotes already */ - if (!quoted && buflen) { - len = strlen (pp); - memmove (pp + 1, pp, len); - *pp++ = '\''; - buflen--; - bp++; - } - /* Escape existing quotes */ - while ((pp = strchr (pp, '\'')) && buflen > 3) { - len = strlen (pp++); - memmove (pp + 3, pp, len); - *pp++ = '\\'; - *pp++ = '\''; - *pp++ = '\''; - buflen -= 3; - bp += 3; - } - /* If pp is still set, that means we ran out of space. */ - if (pp) - buflen = 0; - if (!quoted && buflen) { - *bp++ = '\''; - *bp = '\0'; - buflen--; - } - } - } else { + case 'd': + /* insert content description */ + if (ct->c_descr) { + char *s; + + s = trimcpy (ct->c_descr); + strncpy (bp, s, buflen); + free (s); + } + break; + + case 'e': + /* exclusive execution */ + xtty = 1; + break; + + case 'F': + /* %e, %f, and stdin is terminal not content */ + xstdin = 1; + xtty = 1; + /* and fall... */ + + case 'f': + /* insert filename containing content */ + snprintf (bp, buflen, "'%s'", file); + /* since we've quoted the file argument, set things up + * to look past it, to avoid problems with the quoting + * logic below. (I know, I should figure out what's + * broken with the quoting logic, but..) + */ + len = strlen(bp); + buflen -= len; + bp += len; + pp = bp; + break; + + case 'p': + /* %l, and pause prior to displaying content */ + xpause = pausesw; + /* and fall... */ + + case 'l': + /* display listing prior to displaying content */ + xlist = !nolist; + break; + + case 's': + /* insert subtype of content */ + strncpy (bp, ci->ci_subtype, buflen); + break; + + case '%': + /* insert character % */ + goto raw; + + default: + *bp++ = *--cp; + *bp = '\0'; + buflen--; + continue; + } + len = strlen (bp); + bp += len; + buflen -= len; + + /* Did we actually insert something? */ + if (bp != pp) { + /* Insert single quote if not inside quotes already */ + if (!quoted && buflen) { + len = strlen (pp); + memmove (pp + 1, pp, len); + *pp++ = '\''; + buflen--; + bp++; + } + /* Escape existing quotes */ + while ((pp = strchr (pp, '\'')) && buflen > 3) { + len = strlen (pp++); + memmove (pp + 3, pp, len); + *pp++ = '\\'; + *pp++ = '\''; + *pp++ = '\''; + buflen -= 3; + bp += 3; + } + /* If pp is still set, that means we ran out of space. */ + if (pp) + buflen = 0; + if (!quoted && buflen) { + *bp++ = '\''; + *bp = '\0'; + buflen--; + } + } + } else { raw: - *bp++ = *cp; - *bp = '\0'; - buflen--; + *bp++ = *cp; + *bp = '\0'; + buflen--; - if (*cp == '\'') - quoted = !quoted; + if (*cp == '\'') + quoted = !quoted; + } } - } - if (buflen <= 0 || (ct->c_termproc && buflen <= strlen(ct->c_termproc))) { - /* content_error would provide a more useful error message - * here, except that if we got overrun, it probably would - * too. - */ - fprintf(stderr, "Buffer overflow constructing show command!\n"); - return NOTOK; - } + if (buflen <= 0 || (ct->c_termproc && buflen <= strlen(ct->c_termproc))) { + /* content_error would provide a more useful error message + * here, except that if we got overrun, it probably would + * too. + */ + fprintf(stderr, "Buffer overflow constructing show command!\n"); + return NOTOK; + } - /* use charset string to modify display method */ - if (ct->c_termproc) { - char term[BUFSIZ]; + /* use charset string to modify display method */ + if (ct->c_termproc) { + char term[BUFSIZ]; - strncpy (term, buffer, sizeof(term)); - snprintf (buffer, sizeof(buffer), ct->c_termproc, term); - } + strncpy (term, buffer, sizeof(term)); + snprintf (buffer, sizeof(buffer), ct->c_termproc, term); + } got_command: - return show_content_aux2 (ct, serial, alternate, cracked, buffer, - fd, xlist, xpause, xstdin, xtty); + return show_content_aux2 (ct, serial, alternate, cracked, buffer, + fd, xlist, xpause, xstdin, xtty); } @@ -518,105 +517,105 @@ got_command: */ static int -show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer, - int fd, int xlist, int xpause, int xstdin, int xtty) +show_content_aux2 (CT ct, int serial, int alternate, char *cracked, + char *buffer, int fd, int xlist, int xpause, int xstdin, int xtty) { - pid_t child_id; - int i; - char *vec[4], exec[BUFSIZ + sizeof "exec "]; - - if (debugsw || cracked) { - fflush (stdout); + pid_t child_id; + int i; + char *vec[4], exec[BUFSIZ + sizeof "exec "]; - fprintf (stderr, "%s msg %s", cracked ? "storing" : "show", - ct->c_file); - if (ct->c_partno) - fprintf (stderr, " part %s", ct->c_partno); - if (cracked) - fprintf (stderr, " using command (cd %s; %s)\n", cracked, buffer); - else - fprintf (stderr, " using command %s\n", buffer); - } - - if (xpid < 0 || (xtty && xpid)) { - if (xpid < 0) - xpid = -xpid; - pidcheck(pidwait (xpid, NOTOK)); - xpid = 0; - } - - if (xlist) { - char prompt[BUFSIZ]; + if (debugsw || cracked) { + fflush (stdout); - if (ct->c_type == CT_MULTIPART) - list_content (ct, -1, 1, 0, 0); - else - list_switch (ct, -1, 1, 0, 0); + fprintf (stderr, "%s msg %s", cracked ? "storing" : "show", + ct->c_file); + if (ct->c_partno) + fprintf (stderr, " part %s", ct->c_partno); + if (cracked) + fprintf (stderr, " using command (cd %s; %s)\n", cracked, buffer); + else + fprintf (stderr, " using command %s\n", buffer); + } - if (xpause && SOprintf ("Press to show content...")) - printf ("Press to show content..."); + if (xpid < 0 || (xtty && xpid)) { + if (xpid < 0) + xpid = -xpid; + pidcheck(pidwait (xpid, NOTOK)); + xpid = 0; + } - if (xpause) { - int intr; - SIGNAL_HANDLER istat; + if (xlist) { + char prompt[BUFSIZ]; - istat = SIGNAL (SIGINT, intrser); - if ((intr = sigsetjmp (intrenv, 1)) == OK) { - fflush (stdout); - prompt[0] = 0; - read (fileno (stdout), prompt, sizeof(prompt)); - } - SIGNAL (SIGINT, istat); - if (intr != OK || prompt[0] == 'n') { - (*ct->c_ceclosefnx) (ct); - return (alternate ? DONE : NOTOK); - } - if (prompt[0] == 'q') done(OK); + if (ct->c_type == CT_MULTIPART) + list_content (ct, -1, 1, 0, 0); + else + list_switch (ct, -1, 1, 0, 0); + + if (xpause && SOprintf ("Press to show content...")) + printf ("Press to show content..."); + + if (xpause) { + int intr; + SIGNAL_HANDLER istat; + + istat = SIGNAL (SIGINT, intrser); + if ((intr = sigsetjmp (intrenv, 1)) == OK) { + fflush (stdout); + prompt[0] = 0; + read (fileno (stdout), prompt, sizeof(prompt)); + } + SIGNAL (SIGINT, istat); + if (intr != OK || prompt[0] == 'n') { + (*ct->c_ceclosefnx) (ct); + return (alternate ? DONE : NOTOK); + } + if (prompt[0] == 'q') done(OK); + } } - } - snprintf (exec, sizeof(exec), "exec %s", buffer); + snprintf (exec, sizeof(exec), "exec %s", buffer); - vec[0] = "/bin/sh"; - vec[1] = "-c"; - vec[2] = exec; - vec[3] = NULL; + vec[0] = "/bin/sh"; + vec[1] = "-c"; + vec[2] = exec; + vec[3] = NULL; - fflush (stdout); + fflush (stdout); - for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - advise ("fork", "unable to"); - (*ct->c_ceclosefnx) (ct); - return NOTOK; + for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + advise ("fork", "unable to"); + (*ct->c_ceclosefnx) (ct); + return NOTOK; - case OK: - if (cracked) - chdir (cracked); - if (!xstdin) - dup2 (fd, 0); - close (fd); - execvp ("/bin/sh", vec); - fprintf (stderr, "unable to exec "); - perror ("/bin/sh"); - _exit (-1); - /* NOTREACHED */ + case OK: + if (cracked) + chdir (cracked); + if (!xstdin) + dup2 (fd, 0); + close (fd); + execvp ("/bin/sh", vec); + fprintf (stderr, "unable to exec "); + perror ("/bin/sh"); + _exit (-1); + /* NOTREACHED */ - default: - if (!serial) { - ct->c_pid = child_id; - if (xtty) - xpid = child_id; - } else { - pidcheck (pidXwait (child_id, NULL)); - } - - if (fd != NOTOK) - (*ct->c_ceclosefnx) (ct); - return (alternate ? DONE : OK); - } + default: + if (!serial) { + ct->c_pid = child_id; + if (xtty) + xpid = child_id; + } else { + pidcheck (pidXwait (child_id, NULL)); + } + + if (fd != NOTOK) + (*ct->c_ceclosefnx) (ct); + return (alternate ? DONE : OK); + } } @@ -627,32 +626,32 @@ show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer static int show_text (CT ct, int serial, int alternate) { - char *cp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + char *cp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - /* Check for mhshow-show-type/subtype */ - snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", + /* Check for mhshow-show-type/subtype */ + snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); - - /* Check for mhshow-show-type */ - snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); - - /* - * Use default method if content is text/plain, or if - * if it is not a text part of a multipart/alternative - */ - if (!alternate || ct->c_subtype == TEXT_PLAIN) { - snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw : - moreproc && *moreproc ? moreproc : "more"); - cp = (ct->c_showproc = add (buffer, NULL)); - return show_content_aux (ct, serial, alternate, cp, NULL); - } - - return NOTOK; + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); + + /* Check for mhshow-show-type */ + snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); + + /* + * Use default method if content is text/plain, or if + * if it is not a text part of a multipart/alternative + */ + if (!alternate || ct->c_subtype == TEXT_PLAIN) { + snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw : + moreproc && *moreproc ? moreproc : "more"); + cp = (ct->c_showproc = add (buffer, NULL)); + return show_content_aux (ct, serial, alternate, cp, NULL); + } + + return NOTOK; } @@ -663,32 +662,32 @@ show_text (CT ct, int serial, int alternate) static int show_multi (CT ct, int serial, int alternate) { - char *cp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; + char *cp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; - /* Check for mhshow-show-type/subtype */ - snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", + /* Check for mhshow-show-type/subtype */ + snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_multi_aux (ct, serial, alternate, cp); - - /* Check for mhshow-show-type */ - snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_multi_aux (ct, serial, alternate, cp); - - if ((cp = ct->c_showproc)) - return show_multi_aux (ct, serial, alternate, cp); - - /* - * Use default method to display this multipart content - * if it is not a (nested) part of a multipart/alternative, - * or if it is one of the known subtypes of multipart. - */ - if (!alternate || ct->c_subtype != MULTI_UNKNOWN) - return show_multi_internal (ct, serial, alternate); - - return NOTOK; + if ((cp = context_find (buffer)) && *cp != '\0') + return show_multi_aux (ct, serial, alternate, cp); + + /* Check for mhshow-show-type */ + snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_multi_aux (ct, serial, alternate, cp); + + if ((cp = ct->c_showproc)) + return show_multi_aux (ct, serial, alternate, cp); + + /* + * Use default method to display this multipart content + * if it is not a (nested) part of a multipart/alternative, + * or if it is one of the known subtypes of multipart. + */ + if (!alternate || ct->c_subtype != MULTI_UNKNOWN) + return show_multi_internal (ct, serial, alternate); + + return NOTOK; } @@ -700,135 +699,135 @@ show_multi (CT ct, int serial, int alternate) static int show_multi_internal (CT ct, int serial, int alternate) { - int alternating, nowalternate, nowserial, result; - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - CT p; - sigset_t set, oset; - - alternating = 0; - nowalternate = alternate; - - if (ct->c_subtype == MULTI_PARALLEL) { - nowserial = serialsw; - } else if (ct->c_subtype == MULTI_ALTERNATE) { - nowalternate = 1; - alternating = 1; - nowserial = serial; - } else { - /* - * multipart/mixed - * mutlipart/digest - * unknown subtypes of multipart (treat as mixed per rfc2046) - */ - nowserial = serial; - } + int alternating, nowalternate, nowserial, result; + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; + CT p; + sigset_t set, oset; + + alternating = 0; + nowalternate = alternate; + + if (ct->c_subtype == MULTI_PARALLEL) { + nowserial = serialsw; + } else if (ct->c_subtype == MULTI_ALTERNATE) { + nowalternate = 1; + alternating = 1; + nowserial = serial; + } else { + /* + * multipart/mixed + * mutlipart/digest + * unknown subtypes of multipart (treat as mixed per rfc2046) + */ + nowserial = serial; + } - /* block a few signals */ - if (!nowserial) { - sigemptyset (&set); - sigaddset (&set, SIGHUP); - sigaddset (&set, SIGINT); - sigaddset (&set, SIGQUIT); - sigaddset (&set, SIGTERM); - SIGPROCMASK (SIG_BLOCK, &set, &oset); - } + /* block a few signals */ + if (!nowserial) { + sigemptyset (&set); + sigaddset (&set, SIGHUP); + sigaddset (&set, SIGINT); + sigaddset (&set, SIGQUIT); + sigaddset (&set, SIGTERM); + SIGPROCMASK (SIG_BLOCK, &set, &oset); + } /* * alternate -> we are a part inside an multipart/alternative - * alternating -> we are a multipart/alternative + * alternating -> we are a multipart/alternative */ - result = alternate ? NOTOK : OK; - - for (part = m->mp_parts; part; part = part->mp_next) { - p = part->mp_part; + result = alternate ? NOTOK : OK; - if (part_ok (p, 0) && type_ok (p, 0)) { - int inneresult; - - inneresult = show_switch (p, nowserial, nowalternate); - switch (inneresult) { - case NOTOK: - if (alternate && !alternating) { - result = NOTOK; - goto out; - } - continue; + for (part = m->mp_parts; part; part = part->mp_next) { + p = part->mp_part; - case OK: - case DONE: - if (alternating) { - result = DONE; + if (part_ok (p, 0) && type_ok (p, 0)) { + int inneresult; + + inneresult = show_switch (p, nowserial, nowalternate); + switch (inneresult) { + case NOTOK: + if (alternate && !alternating) { + result = NOTOK; + goto out; + } + continue; + + case OK: + case DONE: + if (alternating) { + result = DONE; + break; + } + if (alternate) { + alternate = nowalternate = 0; + if (result == NOTOK) + result = inneresult; + } + continue; + } break; - } - if (alternate) { - alternate = nowalternate = 0; - if (result == NOTOK) - result = inneresult; - } - continue; - } - break; + } } - } - if (alternating && !part) { - if (!alternate) - content_error (NULL, ct, "don't know how to display any of the contents"); - result = NOTOK; - goto out; - } - - if (serial && !nowserial) { - pid_t pid; - int kids; + if (alternating && !part) { + if (!alternate) + content_error (NULL, ct, "don't know how to display any of the contents"); + result = NOTOK; + goto out; + } + + if (serial && !nowserial) { + pid_t pid; + int kids; #ifdef HAVE_UNION_WAIT - union wait status; + union wait status; #else - int status; + int status; #endif - kids = 0; - for (part = m->mp_parts; part; part = part->mp_next) { - p = part->mp_part; - - if (p->c_pid > OK) { - if (kill (p->c_pid, 0) == NOTOK) - p->c_pid = 0; - else - kids++; - } - } + kids = 0; + for (part = m->mp_parts; part; part = part->mp_next) { + p = part->mp_part; + + if (p->c_pid > OK) { + if (kill (p->c_pid, 0) == NOTOK) + p->c_pid = 0; + else + kids++; + } + } - while (kids > 0 && (pid = wait (&status)) != NOTOK) { + while (kids > 0 && (pid = wait (&status)) != NOTOK) { #ifdef HAVE_UNION_WAIT - pidcheck (status.w_status); + pidcheck (status.w_status); #else - pidcheck (status); + pidcheck (status); #endif - for (part = m->mp_parts; part; part = part->mp_next) { - p = part->mp_part; - - if (xpid == pid) - xpid = 0; - if (p->c_pid == pid) { - p->c_pid = 0; - kids--; - break; + for (part = m->mp_parts; part; part = part->mp_next) { + p = part->mp_part; + + if (xpid == pid) + xpid = 0; + if (p->c_pid == pid) { + p->c_pid = 0; + kids--; + break; + } + } } - } } - } out: - if (!nowserial) { - /* reset the signal mask */ - SIGPROCMASK (SIG_SETMASK, &oset, &set); - } + if (!nowserial) { + /* reset the signal mask */ + SIGPROCMASK (SIG_SETMASK, &oset, &set); + } - return result; + return result; } @@ -840,198 +839,198 @@ out: static int show_multi_aux (CT ct, int serial, int alternate, char *cp) { - int len, buflen, quoted; - int xlist, xpause, xtty; - char *bp, *pp, *file, buffer[BUFSIZ]; - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - CI ci = &ct->c_ctinfo; - CT p; - - for (part = m->mp_parts; part; part = part->mp_next) { - p = part->mp_part; - - if (!p->c_ceopenfnx) { - if (!alternate) - content_error (NULL, p, "don't know how to decode content"); - return NOTOK; - } - - if (p->c_storage == NULL) { - file = NULL; - if ((*p->c_ceopenfnx) (p, &file) == NOTOK) - return NOTOK; + int len, buflen, quoted; + int xlist, xpause, xtty; + char *bp, *pp, *file, buffer[BUFSIZ]; + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; + CI ci = &ct->c_ctinfo; + CT p; - /* I'm not sure if this is necessary? */ - p->c_storage = add (file, NULL); + for (part = m->mp_parts; part; part = part->mp_next) { + p = part->mp_part; - if (p->c_showproc && !strcmp (p->c_showproc, "true")) - return (alternate ? DONE : OK); - (*p->c_ceclosefnx) (p); - } - } - - xlist = 0; - xpause = 0; - xtty = 0; - - /* get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer) - 1; - bp[0] = bp[buflen] = '\0'; - quoted = 0; - - /* Now parse display string */ - for ( ; *cp && buflen > 0; cp++) { - if (*cp == '%') { - pp = bp; - switch (*++cp) { - case 'a': - /* insert parameters from Content-Type field */ - { - char **ap, **ep; - char *s = ""; - - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); - len = strlen (bp); - bp += len; - buflen -= len; - s = " "; + if (!p->c_ceopenfnx) { + if (!alternate) + content_error (NULL, p, "don't know how to decode content"); + return NOTOK; } - } - break; - case 'd': - /* insert content description */ - if (ct->c_descr) { - char *s; + if (p->c_storage == NULL) { + file = NULL; + if ((*p->c_ceopenfnx) (p, &file) == NOTOK) + return NOTOK; - s = trimcpy (ct->c_descr); - strncpy (bp, s, buflen); - free (s); - } - break; + /* I'm not sure if this is necessary? */ + p->c_storage = add (file, NULL); - case 'e': - /* exclusive execution */ - xtty = 1; - break; - - case 'F': - /* %e and %f */ - xtty = 1; - /* and fall... */ - - case 'f': - /* insert filename(s) containing content */ - { - char *s = ""; - - for (part = m->mp_parts; part; part = part->mp_next) { - p = part->mp_part; - - snprintf (bp, buflen, "%s'%s'", s, p->c_storage); - len = strlen (bp); - bp += len; - buflen -= len; - s = " "; + if (p->c_showproc && !strcmp (p->c_showproc, "true")) + return (alternate ? DONE : OK); + (*p->c_ceclosefnx) (p); } - /* set our starting pointer back to bp, to avoid - * requoting the filenames we just added - */ - pp = bp; - } - break; - - case 'p': - /* %l, and pause prior to displaying content */ - xpause = pausesw; - /* and fall... */ - - case 'l': - /* display listing prior to displaying content */ - xlist = !nolist; - break; + } - case 's': - /* insert subtype of content */ - strncpy (bp, ci->ci_subtype, buflen); - break; + xlist = 0; + xpause = 0; + xtty = 0; + + /* get buffer ready to go */ + bp = buffer; + buflen = sizeof(buffer) - 1; + bp[0] = bp[buflen] = '\0'; + quoted = 0; + + /* Now parse display string */ + for ( ; *cp && buflen > 0; cp++) { + if (*cp == '%') { + pp = bp; + switch (*++cp) { + case 'a': + /* insert parameters from Content-Type field */ + { + char **ap, **ep; + char *s = ""; + + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); + len = strlen (bp); + bp += len; + buflen -= len; + s = " "; + } + } + break; - case '%': - /* insert character % */ - goto raw; + case 'd': + /* insert content description */ + if (ct->c_descr) { + char *s; + + s = trimcpy (ct->c_descr); + strncpy (bp, s, buflen); + free (s); + } + break; + + case 'e': + /* exclusive execution */ + xtty = 1; + break; + + case 'F': + /* %e and %f */ + xtty = 1; + /* and fall... */ + + case 'f': + /* insert filename(s) containing content */ + { + char *s = ""; + + for (part = m->mp_parts; part; part = part->mp_next) { + p = part->mp_part; + + snprintf (bp, buflen, "%s'%s'", s, p->c_storage); + len = strlen (bp); + bp += len; + buflen -= len; + s = " "; + } + /* set our starting pointer back to bp, to avoid + * requoting the filenames we just added + */ + pp = bp; + } + break; - default: - *bp++ = *--cp; - *bp = '\0'; - buflen--; - continue; - } - len = strlen (bp); - bp += len; - buflen -= len; - - /* Did we actually insert something? */ - if (bp != pp) { - /* Insert single quote if not inside quotes already */ - if (!quoted && buflen) { - len = strlen (pp); - memmove (pp + 1, pp, len); - *pp++ = '\''; - buflen--; - bp++; - } - /* Escape existing quotes */ - while ((pp = strchr (pp, '\'')) && buflen > 3) { - len = strlen (pp++); - memmove (pp + 3, pp, len); - *pp++ = '\\'; - *pp++ = '\''; - *pp++ = '\''; - buflen -= 3; - bp += 3; - } - /* If pp is still set, that means we ran out of space. */ - if (pp) - buflen = 0; - if (!quoted && buflen) { - *bp++ = '\''; - *bp = '\0'; - buflen--; - } - } - } else { + case 'p': + /* %l, and pause prior to displaying content */ + xpause = pausesw; + /* and fall... */ + + case 'l': + /* display listing prior to displaying content */ + xlist = !nolist; + break; + + case 's': + /* insert subtype of content */ + strncpy (bp, ci->ci_subtype, buflen); + break; + + case '%': + /* insert character % */ + goto raw; + + default: + *bp++ = *--cp; + *bp = '\0'; + buflen--; + continue; + } + len = strlen (bp); + bp += len; + buflen -= len; + + /* Did we actually insert something? */ + if (bp != pp) { + /* Insert single quote if not inside quotes already */ + if (!quoted && buflen) { + len = strlen (pp); + memmove (pp + 1, pp, len); + *pp++ = '\''; + buflen--; + bp++; + } + /* Escape existing quotes */ + while ((pp = strchr (pp, '\'')) && buflen > 3) { + len = strlen (pp++); + memmove (pp + 3, pp, len); + *pp++ = '\\'; + *pp++ = '\''; + *pp++ = '\''; + buflen -= 3; + bp += 3; + } + /* If pp is still set, that means we ran out of space. */ + if (pp) + buflen = 0; + if (!quoted && buflen) { + *bp++ = '\''; + *bp = '\0'; + buflen--; + } + } + } else { raw: - *bp++ = *cp; - *bp = '\0'; - buflen--; + *bp++ = *cp; + *bp = '\0'; + buflen--; - if (*cp == '\'') - quoted = !quoted; + if (*cp == '\'') + quoted = !quoted; + } } - } - if (buflen <= 0 || (ct->c_termproc && buflen <= strlen(ct->c_termproc))) { - /* content_error would provide a more useful error message - * here, except that if we got overrun, it probably would - * too. - */ - fprintf(stderr, "Buffer overflow constructing show command!\n"); - return NOTOK; - } + if (buflen <= 0 || (ct->c_termproc && buflen <= strlen(ct->c_termproc))) { + /* content_error would provide a more useful error message + * here, except that if we got overrun, it probably would + * too. + */ + fprintf(stderr, "Buffer overflow constructing show command!\n"); + return NOTOK; + } - /* use charset string to modify display method */ - if (ct->c_termproc) { - char term[BUFSIZ]; + /* use charset string to modify display method */ + if (ct->c_termproc) { + char term[BUFSIZ]; - strncpy (term, buffer, sizeof(term)); - snprintf (buffer, sizeof(buffer), ct->c_termproc, term); - } + strncpy (term, buffer, sizeof(term)); + snprintf (buffer, sizeof(buffer), ct->c_termproc, term); + } - return show_content_aux2 (ct, serial, alternate, NULL, buffer, - NOTOK, xlist, xpause, 0, xtty); + return show_content_aux2 (ct, serial, alternate, NULL, buffer, + NOTOK, xlist, xpause, 0, xtty); } @@ -1042,34 +1041,34 @@ raw: static int show_message_rfc822 (CT ct, int serial, int alternate) { - char *cp, buffer[BUFSIZ]; - CI ci = &ct->c_ctinfo; - - /* Check for mhshow-show-type/subtype */ - snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); - - /* Check for mhshow-show-type */ - snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, serial, alternate, cp, NULL); - - if ((cp = ct->c_showproc)) - return show_content_aux (ct, serial, alternate, cp, NULL); - - /* default method for message/rfc822 */ - if (ct->c_subtype == MESSAGE_RFC822) { - cp = (ct->c_showproc = add ("%pshow -file '%F'", NULL)); - return show_content_aux (ct, serial, alternate, cp, NULL); - } + char *cp, buffer[BUFSIZ]; + CI ci = &ct->c_ctinfo; + + /* Check for mhshow-show-type/subtype */ + snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); + + /* Check for mhshow-show-type */ + snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) && *cp != '\0') + return show_content_aux (ct, serial, alternate, cp, NULL); + + if ((cp = ct->c_showproc)) + return show_content_aux (ct, serial, alternate, cp, NULL); + + /* default method for message/rfc822 */ + if (ct->c_subtype == MESSAGE_RFC822) { + cp = (ct->c_showproc = add ("%pshow -file '%F'", NULL)); + return show_content_aux (ct, serial, alternate, cp, NULL); + } - /* complain if we are not a part of a multipart/alternative */ - if (!alternate) - content_error (NULL, ct, "don't know how to display content"); + /* complain if we are not a part of a multipart/alternative */ + if (!alternate) + content_error (NULL, ct, "don't know how to display content"); - return NOTOK; + return NOTOK; } @@ -1080,9 +1079,9 @@ show_message_rfc822 (CT ct, int serial, int alternate) static int show_partial (CT ct, int serial, int alternate) { - content_error (NULL, ct, - "in order to display this message, you must reassemble it"); - return NOTOK; + content_error (NULL, ct, + "in order to display this message, you must reassemble it"); + return NOTOK; } @@ -1095,17 +1094,17 @@ show_partial (CT ct, int serial, int alternate) static int show_external (CT ct, int serial, int alternate) { - struct exbody *e = (struct exbody *) ct->c_ctparams; - CT p = e->eb_content; + struct exbody *e = (struct exbody *) ct->c_ctparams; + CT p = e->eb_content; - if (!type_ok (p, 0)) - return OK; + if (!type_ok (p, 0)) + return OK; - return show_switch (p, serial, alternate); + return show_switch (p, serial, alternate); #if 0 - content_error (NULL, p, "don't know how to display content"); - return NOTOK; + content_error (NULL, p, "don't know how to display content"); + return NOTOK; #endif } @@ -1114,9 +1113,9 @@ static RETSIGTYPE intrser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGINT, intrser); + SIGNAL (SIGINT, intrser); #endif - putchar ('\n'); - siglongjmp (intrenv, DONE); + putchar ('\n'); + siglongjmp (intrenv, DONE); } diff --git a/uip/mhstore.c b/uip/mhstore.c index 7b44a96..2b413d4 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -1,4 +1,3 @@ - /* * mhstore.c -- store the contents of MIME messages * @@ -25,44 +24,44 @@ #endif static struct swit switches[] = { -#define AUTOSW 0 - { "auto", 0 }, -#define NAUTOSW 1 - { "noauto", 0 }, -#define CHECKSW 2 - { "check", 0 }, -#define NCHECKSW 3 - { "nocheck", 0 }, -#define VERBSW 4 - { "verbose", 0 }, -#define NVERBSW 5 - { "noverbose", 0 }, -#define FILESW 6 /* interface from show */ - { "file file", 0 }, -#define PARTSW 7 - { "part number", 0 }, -#define TYPESW 8 - { "type content", 0 }, -#define RCACHESW 9 - { "rcache policy", 0 }, -#define WCACHESW 10 - { "wcache policy", 0 }, -#define VERSIONSW 11 - { "version", 0 }, -#define HELPSW 12 - { "help", 0 }, +#define AUTOSW 0 + { "auto", 0 }, +#define NAUTOSW 1 + { "noauto", 0 }, +#define CHECKSW 2 + { "check", 0 }, +#define NCHECKSW 3 + { "nocheck", 0 }, +#define VERBSW 4 + { "verbose", 0 }, +#define NVERBSW 5 + { "noverbose", 0 }, +#define FILESW 6 /* interface from show */ + { "file file", 0 }, +#define PARTSW 7 + { "part number", 0 }, +#define TYPESW 8 + { "type content", 0 }, +#define RCACHESW 9 + { "rcache policy", 0 }, +#define WCACHESW 10 + { "wcache policy", 0 }, +#define VERSIONSW 11 + { "version", 0 }, +#define HELPSW 12 + { "help", 0 }, /* * switches for debugging */ -#define DEBUGSW 13 - { "debug", -5 }, - { NULL, 0 } +#define DEBUGSW 13 + { "debug", -5 }, + { NULL, 0 } }; /* mhparse.c */ -extern char *tmp; /* directory to place temp files */ +extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ extern int rcachesw; @@ -72,7 +71,7 @@ extern char *cache_private; /* mhstoresbr.c */ extern int autosw; -extern char *cwd; /* cache current working directory */ +extern char *cwd; /* cache current working directory */ /* mhmisc.c */ extern int npart; @@ -84,7 +83,7 @@ extern int userrs; int debugsw = 0; int verbosw = 0; -#define quitser pipeser +#define quitser pipeser /* mhparse.c */ CT parse_mime (char *); @@ -112,291 +111,291 @@ static RETSIGTYPE pipeser (int); int main (int argc, char **argv) { - int msgnum, *icachesw; - char *cp, *file = NULL, *folder = NULL; - char *maildir, buf[100], **argp; - char **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp = NULL; - CT ct, *ctp; - FILE *fp; + int msgnum, *icachesw; + char *cp, *file = NULL, *folder = NULL; + char *maildir, buf[100], **argp; + char **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp = NULL; + CT ct, *ctp; + FILE *fp; - done=freects_done; + done=freects_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + invo_name = r1bindex (argv[0], '/'); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; - case AUTOSW: - autosw++; - continue; - case NAUTOSW: - autosw = 0; - continue; - - case RCACHESW: - icachesw = &rcachesw; - goto do_cache; - case WCACHESW: - icachesw = &wcachesw; + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case AUTOSW: + autosw++; + continue; + case NAUTOSW: + autosw = 0; + continue; + + case RCACHESW: + icachesw = &rcachesw; + goto do_cache; + case WCACHESW: + icachesw = &wcachesw; do_cache: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - switch (*icachesw = smatch (cp, caches)) { - case AMBIGSW: - ambigsw (cp, caches); - done (1); - case UNKWNSW: - adios (NULL, "%s unknown", cp); - default: - break; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + switch (*icachesw = smatch (cp, caches)) { + case AMBIGSW: + ambigsw (cp, caches); + done (1); + case UNKWNSW: + adios (NULL, "%s unknown", cp); + default: + break; + } + continue; + + case CHECKSW: + checksw++; + continue; + case NCHECKSW: + checksw = 0; + continue; + + case PARTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (npart >= NPARTS) + adios (NULL, "too many parts (starting with %s), %d max", + cp, NPARTS); + parts[npart++] = cp; + continue; + + case TYPESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (ntype >= NTYPES) + adios (NULL, "too many types (starting with %s), %d max", + cp, NTYPES); + types[ntype++] = cp; + continue; + + case FILESW: + if (!(cp = *argp++) || (*cp == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + file = *cp == '-' ? cp : path (cp, TFILE); + continue; + + case VERBSW: + verbosw = 1; + continue; + case NVERBSW: + verbosw = 0; + continue; + case DEBUGSW: + debugsw = 1; + continue; + } } - continue; - - case CHECKSW: - checksw++; - continue; - case NCHECKSW: - checksw = 0; - continue; - - case PARTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (npart >= NPARTS) - adios (NULL, "too many parts (starting with %s), %d max", - cp, NPARTS); - parts[npart++] = cp; - continue; - - case TYPESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (ntype >= NTYPES) - adios (NULL, "too many types (starting with %s), %d max", - cp, NTYPES); - types[ntype++] = cp; - continue; - - case FILESW: - if (!(cp = *argp++) || (*cp == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - file = *cp == '-' ? cp : path (cp, TFILE); - continue; - - case VERBSW: - verbosw = 1; - continue; - case NVERBSW: - verbosw = 0; - continue; - case DEBUGSW: - debugsw = 1; - continue; - } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* null terminate the list of acceptable parts/types */ - parts[npart] = NULL; - types[ntype] = NULL; - - set_endian (); - - /* - * Check if we've specified an additional profile - */ - if ((cp = getenv ("MHSTORE"))) { - if ((fp = fopen (cp, "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } else { - admonish ("", "unable to read $MHSTORE profile (%s)", cp); + + /* null terminate the list of acceptable parts/types */ + parts[npart] = NULL; + types[ntype] = NULL; + + set_endian (); + + /* + * Check if we've specified an additional profile + */ + if ((cp = getenv ("MHSTORE"))) { + if ((fp = fopen (cp, "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } else { + admonish ("", "unable to read $MHSTORE profile (%s)", cp); + } } - } - - /* - * Read the standard profile setup - */ - if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { - readconfig ((struct node **) 0, fp, cp, 0); - fclose (fp); - } - - /* Check for public cache location */ - if ((cache_public = context_find (nmhcache)) && *cache_public != '/') - cache_public = NULL; - - /* Check for private cache location */ - if (!(cache_private = context_find (nmhprivcache))) - cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); - - /* - * Cache the current directory before we do any chdirs()'s. - */ - cwd = getcpy (pwd()); - - /* - * Check for storage directory. If specified, - * then store temporary files there. Else we - * store them in standard nmh directory. - */ - if ((cp = context_find (nmhstorage)) && *cp) - tmp = concat (cp, "/", invo_name, NULL); - else - tmp = add (m_maildir (invo_name), NULL); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (file && msgs.size) - adios (NULL, "cannot specify msg and file at same time!"); - - /* - * check if message is coming from file - */ - if (file) { - if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; - - if ((ct = parse_mime (file))); - *ctp++ = ct; - } else { + /* - * message(s) are coming from a folder + * Read the standard profile setup */ - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ + if ((fp = fopen (cp = etcpath ("mhn.defaults"), "r"))) { + readconfig ((struct node **) 0, fp, cp, 0); + fclose (fp); + } + + /* Check for public cache location */ + if ((cache_public = context_find (nmhcache)) && *cache_public != '/') + cache_public = NULL; - if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; + /* Check for private cache location */ + if (!(cache_private = context_find (nmhprivcache))) + cache_private = ".cache"; + cache_private = getcpy (m_maildir (cache_private)); + + /* + * Cache the current directory before we do any chdirs()'s. + */ + cwd = getcpy (pwd()); + + /* + * Check for storage directory. If specified, + * then store temporary files there. Else we + * store them in standard nmh directory. + */ + if ((cp = context_find (nmhstorage)) && *cp) + tmp = concat (cp, "/", invo_name, NULL); + else + tmp = add (m_maildir (invo_name), NULL); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - char *msgnam; + if (!context_find ("path")) + free (path ("./", TFOLDER)); - msgnam = m_name (msgnum); - if ((ct = parse_mime (msgnam))) - *ctp++ = ct; - } + if (file && msgs.size) + adios (NULL, "cannot specify msg and file at same time!"); + + /* + * check if message is coming from file + */ + if (file) { + if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + if ((ct = parse_mime (file))); + *ctp++ = ct; + } else { + /* + * message(s) are coming from a folder + */ + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + char *msgnam; + + msgnam = m_name (msgnum); + if ((ct = parse_mime (msgnam))) + *ctp++ = ct; + } + } } - } - if (!*cts) - done (1); + if (!*cts) + done (1); + + userrs = 1; + SIGNAL (SIGQUIT, quitser); + SIGNAL (SIGPIPE, pipeser); - userrs = 1; - SIGNAL (SIGQUIT, quitser); - SIGNAL (SIGPIPE, pipeser); - - /* - * Get the associated umask for the relevant contents. - */ - for (ctp = cts; *ctp; ctp++) { - struct stat st; - - ct = *ctp; - if (type_ok (ct, 1) && !ct->c_umask) { - if (stat (ct->c_file, &st) != NOTOK) - ct->c_umask = ~(st.st_mode & 0777); - else - ct->c_umask = ~m_gmprot(); + /* + * Get the associated umask for the relevant contents. + */ + for (ctp = cts; *ctp; ctp++) { + struct stat st; + + ct = *ctp; + if (type_ok (ct, 1) && !ct->c_umask) { + if (stat (ct->c_file, &st) != NOTOK) + ct->c_umask = ~(st.st_mode & 0777); + else + ct->c_umask = ~m_gmprot(); + } } - } - - /* - * Store the message content - */ - store_all_messages (cts); - - /* Now free all the structures for the content */ - for (ctp = cts; *ctp; ctp++) - free_content (*ctp); - - free ((char *) cts); - cts = NULL; - - /* If reading from a folder, do some updating */ - if (mp) { - context_replace (pfolder, folder);/* update current folder */ - seq_setcur (mp, mp->hghsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - done (0); - return 1; + + /* + * Store the message content + */ + store_all_messages (cts); + + /* Now free all the structures for the content */ + for (ctp = cts; *ctp; ctp++) + free_content (*ctp); + + free ((char *) cts); + cts = NULL; + + /* If reading from a folder, do some updating */ + if (mp) { + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->hghsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ + } + + done (0); + return 1; } static RETSIGTYPE pipeser (int i) { - if (i == SIGQUIT) { - unlink ("core"); - fflush (stdout); - fprintf (stderr, "\n"); - fflush (stderr); - } - - done (1); - /* NOTREACHED */ + if (i == SIGQUIT) { + unlink ("core"); + fflush (stdout); + fprintf (stderr, "\n"); + fflush (stderr); + } + + done (1); + /* NOTREACHED */ } diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 7c91184..2683fae 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -1,4 +1,3 @@ - /* * mhstoresbr.c -- routines to save/store the contents of MIME messages * @@ -87,26 +86,26 @@ static int copy_some_headers (FILE *, CT); void store_all_messages (CT *cts) { - CT ct, *ctp; - char *cp; - - /* - * Check for the directory in which to - * store any contents. - */ - if (autosw) - dir = getcpy (cwd); - else if ((cp = context_find (nmhstorage)) && *cp) - dir = getcpy (cp); - else - dir = getcpy (cwd); - - for (ctp = cts; *ctp; ctp++) { - ct = *ctp; - store_single_message (ct); - } - - flush_errors (); + CT ct, *ctp; + char *cp; + + /* + * Check for the directory in which to + * store any contents. + */ + if (autosw) + dir = getcpy (cwd); + else if ((cp = context_find (nmhstorage)) && *cp) + dir = getcpy (cp); + else + dir = getcpy (cwd); + + for (ctp = cts; *ctp; ctp++) { + ct = *ctp; + store_single_message (ct); + } + + flush_errors (); } @@ -118,16 +117,16 @@ store_all_messages (CT *cts) static void store_single_message (CT ct) { - if (type_ok (ct, 1)) { - umask (ct->c_umask); - store_switch (ct); - if (ct->c_fp) { - fclose (ct->c_fp); - ct->c_fp = NULL; + if (type_ok (ct, 1)) { + umask (ct->c_umask); + store_switch (ct); + if (ct->c_fp) { + fclose (ct->c_fp); + ct->c_fp = NULL; + } + if (ct->c_ceclosefnx) + (*ct->c_ceclosefnx) (ct); } - if (ct->c_ceclosefnx) - (*ct->c_ceclosefnx) (ct); - } } @@ -138,44 +137,44 @@ store_single_message (CT ct) static int store_switch (CT ct) { - switch (ct->c_type) { - case CT_MULTIPART: - return store_multi (ct); - break; + switch (ct->c_type) { + case CT_MULTIPART: + return store_multi (ct); + break; - case CT_MESSAGE: - switch (ct->c_subtype) { - case MESSAGE_PARTIAL: - return store_partial (ct); - break; + case CT_MESSAGE: + switch (ct->c_subtype) { + case MESSAGE_PARTIAL: + return store_partial (ct); + break; - case MESSAGE_EXTERNAL: - return store_external (ct); + case MESSAGE_EXTERNAL: + return store_external (ct); + + case MESSAGE_RFC822: + default: + return store_generic (ct); + break; + } + break; + + case CT_APPLICATION: + return store_application (ct); + break; + + case CT_TEXT: + case CT_AUDIO: + case CT_IMAGE: + case CT_VIDEO: + return store_generic (ct); + break; - case MESSAGE_RFC822: default: - return store_generic (ct); - break; - } - break; - - case CT_APPLICATION: - return store_application (ct); - break; - - case CT_TEXT: - case CT_AUDIO: - case CT_IMAGE: - case CT_VIDEO: - return store_generic (ct); - break; - - default: - adios (NULL, "unknown content type %d", ct->c_type); - break; - } - - return OK; /* NOT REACHED */ + adios (NULL, "unknown content type %d", ct->c_type); + break; + } + + return OK; /* NOT REACHED */ } @@ -187,15 +186,15 @@ store_switch (CT ct) static int store_generic (CT ct) { - /* - * Check if the content specifies a filename. - * Don't bother with this for type "message" - * (only "message/rfc822" will use store_generic). - */ - if (autosw && ct->c_type != CT_MESSAGE) - get_storeproc (ct); - - return store_content (ct, NULL); + /* + * Check if the content specifies a filename. + * Don't bother with this for type "message" + * (only "message/rfc822" will use store_generic). + */ + if (autosw && ct->c_type != CT_MESSAGE) + get_storeproc (ct); + + return store_content (ct, NULL); } @@ -206,65 +205,65 @@ store_generic (CT ct) static int store_application (CT ct) { - char **ap, **ep; - CI ci = &ct->c_ctinfo; + char **ap, **ep; + CI ci = &ct->c_ctinfo; - /* Check if the content specifies a filename */ - if (autosw) - get_storeproc (ct); + /* Check if the content specifies a filename */ + if (autosw) + get_storeproc (ct); - /* - * If storeproc is not defined, and the content is type - * "application/octet-stream", we also check for various - * attribute/value pairs which specify if this a tar file. - */ - if (!ct->c_storeproc && ct->c_subtype == APPLICATION_OCTETS) { - int tarP = 0, zP = 0, gzP = 0; + /* + * If storeproc is not defined, and the content is type + * "application/octet-stream", we also check for various + * attribute/value pairs which specify if this a tar file. + */ + if (!ct->c_storeproc && ct->c_subtype == APPLICATION_OCTETS) { + int tarP = 0, zP = 0, gzP = 0; - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - /* check for "type=tar" attribute */ - if (!mh_strcasecmp (*ap, "type")) { - if (mh_strcasecmp (*ep, "tar")) - break; - - tarP = 1; - continue; - } - - /* check for "conversions=compress" attribute */ - if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions")) - && (!mh_strcasecmp (*ep, "compress") || !mh_strcasecmp (*ep, "x-compress"))) { - zP = 1; - continue; - } - /* check for "conversions=gzip" attribute */ - if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions")) - && (!mh_strcasecmp (*ep, "gzip") || !mh_strcasecmp (*ep, "x-gzip"))) { - gzP = 1; - continue; - } - } + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + /* check for "type=tar" attribute */ + if (!mh_strcasecmp (*ap, "type")) { + if (mh_strcasecmp (*ep, "tar")) + break; - if (tarP) { - ct->c_showproc = add (zP ? "%euncompress | tar tvf -" - : (gzP ? "%egzip -dc | tar tvf -" - : "%etar tvf -"), NULL); - if (!ct->c_storeproc) { - if (autosw) { - ct->c_storeproc = add (zP ? "| uncompress | tar xvpf -" - : (gzP ? "| gzip -dc | tar xvpf -" - : "| tar xvpf -"), NULL); - ct->c_umask = 0022; - } else { - ct->c_storeproc= add (zP ? "%m%P.tar.Z" - : (gzP ? "%m%P.tar.gz" - : "%m%P.tar"), NULL); + tarP = 1; + continue; + } + + /* check for "conversions=compress" attribute */ + if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions")) + && (!mh_strcasecmp (*ep, "compress") || !mh_strcasecmp (*ep, "x-compress"))) { + zP = 1; + continue; + } + /* check for "conversions=gzip" attribute */ + if ((!mh_strcasecmp (*ap, "conversions") || !mh_strcasecmp (*ap, "x-conversions")) + && (!mh_strcasecmp (*ep, "gzip") || !mh_strcasecmp (*ep, "x-gzip"))) { + gzP = 1; + continue; + } + } + + if (tarP) { + ct->c_showproc = add (zP ? "%euncompress | tar tvf -" + : (gzP ? "%egzip -dc | tar tvf -" + : "%etar tvf -"), NULL); + if (!ct->c_storeproc) { + if (autosw) { + ct->c_storeproc = add (zP ? "| uncompress | tar xvpf -" + : (gzP ? "| gzip -dc | tar xvpf -" + : "| tar xvpf -"), NULL); + ct->c_umask = 0022; + } else { + ct->c_storeproc= add (zP ? "%m%P.tar.Z" + : (gzP ? "%m%P.tar.gz" + : "%m%P.tar"), NULL); + } + } } - } } - } - return store_content (ct, NULL); + return store_content (ct, NULL); } @@ -275,22 +274,22 @@ store_application (CT ct) static int store_multi (CT ct) { - int result; - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - - result = NOTOK; - for (part = m->mp_parts; part; part = part->mp_next) { - CT p = part->mp_part; - - if (part_ok (p, 1) && type_ok (p, 1)) { - result = store_switch (p); - if (result == OK && ct->c_subtype == MULTI_ALTERNATE) - break; + int result; + struct multipart *m = (struct multipart *) ct->c_ctparams; + struct part *part; + + result = NOTOK; + for (part = m->mp_parts; part; part = part->mp_next) { + CT p = part->mp_part; + + if (part_ok (p, 1) && type_ok (p, 1)) { + result = store_switch (p); + if (result == OK && ct->c_subtype == MULTI_ALTERNATE) + break; + } } - } - return result; + return result; } @@ -302,102 +301,100 @@ store_multi (CT ct) static int store_partial (CT ct) { - int cur, hi, i; - CT p, *ctp, *ctq; - CT *base; - struct partial *pm, *qm; - - qm = (struct partial *) ct->c_ctparams; - if (qm->pm_stored) - return OK; + int cur, hi, i; + CT p, *ctp, *ctq; + CT *base; + struct partial *pm, *qm; + + qm = (struct partial *) ct->c_ctparams; + if (qm->pm_stored) + return OK; + + hi = i = 0; + for (ctp = cts; *ctp; ctp++) { + p = *ctp; + if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) { + pm = (struct partial *) p->c_ctparams; + if (!pm->pm_stored + && strcmp (qm->pm_partid, pm->pm_partid) == 0) { + pm->pm_marked = pm->pm_partno; + if (pm->pm_maxno) + hi = pm->pm_maxno; + pm->pm_stored = 1; + i++; + } else + pm->pm_marked = 0; + } + } - hi = i = 0; - for (ctp = cts; *ctp; ctp++) { - p = *ctp; - if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) { - pm = (struct partial *) p->c_ctparams; - if (!pm->pm_stored - && strcmp (qm->pm_partid, pm->pm_partid) == 0) { - pm->pm_marked = pm->pm_partno; - if (pm->pm_maxno) - hi = pm->pm_maxno; - pm->pm_stored = 1; - i++; - } - else - pm->pm_marked = 0; + if (hi == 0) { + advise (NULL, "missing (at least) last part of multipart message"); + return NOTOK; } - } - - if (hi == 0) { - advise (NULL, "missing (at least) last part of multipart message"); - return NOTOK; - } - - if ((base = (CT *) calloc ((size_t) (i + 1), sizeof(*base))) == NULL) - adios (NULL, "out of memory"); - - ctq = base; - for (ctp = cts; *ctp; ctp++) { - p = *ctp; - if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) { - pm = (struct partial *) p->c_ctparams; - if (pm->pm_marked) - *ctq++ = p; + + if ((base = (CT *) calloc ((size_t) (i + 1), sizeof(*base))) == NULL) + adios (NULL, "out of memory"); + + ctq = base; + for (ctp = cts; *ctp; ctp++) { + p = *ctp; + if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) { + pm = (struct partial *) p->c_ctparams; + if (pm->pm_marked) + *ctq++ = p; + } } - } - *ctq = NULL; - - if (i > 1) - qsort ((char *) base, i, sizeof(*base), (qsort_comp) ct_compar); - - cur = 1; - for (ctq = base; *ctq; ctq++) { - p = *ctq; - pm = (struct partial *) p->c_ctparams; - if (pm->pm_marked != cur) { - if (pm->pm_marked == cur - 1) { - admonish (NULL, - "duplicate part %d of %d part multipart message", - pm->pm_marked, hi); - continue; - } + *ctq = NULL; + + if (i > 1) + qsort ((char *) base, i, sizeof(*base), (qsort_comp) ct_compar); + + cur = 1; + for (ctq = base; *ctq; ctq++) { + p = *ctq; + pm = (struct partial *) p->c_ctparams; + if (pm->pm_marked != cur) { + if (pm->pm_marked == cur - 1) { + admonish (NULL, + "duplicate part %d of %d part multipart message", + pm->pm_marked, hi); + continue; + } missing_part: - advise (NULL, - "missing %spart %d of %d part multipart message", - cur != hi ? "(at least) " : "", cur, hi); - goto losing; + advise (NULL, + "missing %spart %d of %d part multipart message", + cur != hi ? "(at least) " : "", cur, hi); + goto losing; + } else + cur++; } - else - cur++; - } - if (hi != --cur) { - cur = hi; - goto missing_part; - } - - /* - * Now cycle through the sorted list of messages of type - * "message/partial" and save/append them to a file. - */ - - ctq = base; - ct = *ctq++; - if (store_content (ct, NULL) == NOTOK) { + if (hi != --cur) { + cur = hi; + goto missing_part; + } + + /* + * Now cycle through the sorted list of messages of type + * "message/partial" and save/append them to a file. + */ + + ctq = base; + ct = *ctq++; + if (store_content (ct, NULL) == NOTOK) { losing: - free ((char *) base); - return NOTOK; - } + free ((char *) base); + return NOTOK; + } - for (; *ctq; ctq++) { - p = *ctq; - if (store_content (p, ct) == NOTOK) - goto losing; - } + for (; *ctq; ctq++) { + p = *ctq; + if (store_content (p, ct) == NOTOK) + goto losing; + } - free ((char *) base); - return OK; + free ((char *) base); + return OK; } @@ -408,46 +405,46 @@ losing: static int store_external (CT ct) { - int result = NOTOK; - struct exbody *e = (struct exbody *) ct->c_ctparams; - CT p = e->eb_content; - - if (!type_ok (p, 1)) - return OK; + int result = NOTOK; + struct exbody *e = (struct exbody *) ct->c_ctparams; + CT p = e->eb_content; - /* - * Check if the parameters for the external body - * specified a filename. - */ - if (autosw) { - char *cp; + if (!type_ok (p, 1)) + return OK; - if ((cp = e->eb_name) - && *cp != '/' - && *cp != '.' - && *cp != '|' - && *cp != '!' - && !strchr (cp, '%')) { - if (!ct->c_storeproc) - ct->c_storeproc = add (cp, NULL); - if (!p->c_storeproc) - p->c_storeproc = add (cp, NULL); + /* + * Check if the parameters for the external body + * specified a filename. + */ + if (autosw) { + char *cp; + + if ((cp = e->eb_name) + && *cp != '/' + && *cp != '.' + && *cp != '|' + && *cp != '!' + && !strchr (cp, '%')) { + if (!ct->c_storeproc) + ct->c_storeproc = add (cp, NULL); + if (!p->c_storeproc) + p->c_storeproc = add (cp, NULL); + } } - } - /* - * Since we will let the Content structure for the - * external body substitute for the current content, - * we temporarily change its partno (number inside - * multipart), so everything looks right. - */ - p->c_partno = ct->c_partno; + /* + * Since we will let the Content structure for the + * external body substitute for the current content, + * we temporarily change its partno (number inside + * multipart), so everything looks right. + */ + p->c_partno = ct->c_partno; - /* we probably need to check if content is really there */ - result = store_switch (p); + /* we probably need to check if content is really there */ + result = store_switch (p); - p->c_partno = NULL; - return result; + p->c_partno = NULL; + return result; } @@ -459,10 +456,10 @@ store_external (CT ct) static int ct_compar (CT *a, CT *b) { - struct partial *am = (struct partial *) ((*a)->c_ctparams); - struct partial *bm = (struct partial *) ((*b)->c_ctparams); + struct partial *am = (struct partial *) ((*a)->c_ctparams); + struct partial *bm = (struct partial *) ((*b)->c_ctparams); - return (am->pm_marked - bm->pm_marked); + return (am->pm_marked - bm->pm_marked); } @@ -480,180 +477,180 @@ ct_compar (CT *a, CT *b) static int store_content (CT ct, CT p) { - int appending = 0, msgnum = 0; - int is_partial = 0, first_partial = 0; - int last_partial = 0; - char *cp, buffer[BUFSIZ]; - - /* - * Do special processing for messages of - * type "message/partial". - * - * We first check if this content is of type - * "message/partial". If it is, then we need to check - * whether it is the first and/or last in the group. - * - * Then if "p" is a valid pointer, it points to the Content - * structure of the first partial in the group. So we copy - * the file name and/or folder name from that message. In - * this case, we also note that we will be appending. - */ - if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { - struct partial *pm = (struct partial *) ct->c_ctparams; - - /* Yep, it's a message/partial */ - is_partial = 1; - - /* But is it the first and/or last in the collection? */ - if (pm->pm_partno == 1) - first_partial = 1; - if (pm->pm_maxno && pm->pm_partno == pm->pm_maxno) - last_partial = 1; + int appending = 0, msgnum = 0; + int is_partial = 0, first_partial = 0; + int last_partial = 0; + char *cp, buffer[BUFSIZ]; /* - * If "p" is a valid pointer, then it points to the - * Content structure for the first message in the group. - * So we just copy the filename or foldername information - * from the previous iteration of this function. + * Do special processing for messages of + * type "message/partial". + * + * We first check if this content is of type + * "message/partial". If it is, then we need to check + * whether it is the first and/or last in the group. + * + * Then if "p" is a valid pointer, it points to the Content + * structure of the first partial in the group. So we copy + * the file name and/or folder name from that message. In + * this case, we also note that we will be appending. */ - if (p) { - appending = 1; - ct->c_storage = add (p->c_storage, NULL); - - /* record the folder name */ - if (p->c_folder) { - ct->c_folder = add (p->c_folder, NULL); - } - goto got_filename; + if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { + struct partial *pm = (struct partial *) ct->c_ctparams; + + /* Yep, it's a message/partial */ + is_partial = 1; + + /* But is it the first and/or last in the collection? */ + if (pm->pm_partno == 1) + first_partial = 1; + if (pm->pm_maxno && pm->pm_partno == pm->pm_maxno) + last_partial = 1; + + /* + * If "p" is a valid pointer, then it points to the + * Content structure for the first message in the group. + * So we just copy the filename or foldername information + * from the previous iteration of this function. + */ + if (p) { + appending = 1; + ct->c_storage = add (p->c_storage, NULL); + + /* record the folder name */ + if (p->c_folder) { + ct->c_folder = add (p->c_folder, NULL); + } + goto got_filename; + } } - } - - /* - * Get storage formatting string. - * - * 1) If we have storeproc defined, then use that - * 2) Else check for a mhstore-store-/ entry - * 3) Else check for a mhstore-store- entry - * 4) Else if content is "message", use "+" (current folder) - * 5) Else use string "%m%P.%s". - */ - if ((cp = ct->c_storeproc) == NULL || *cp == '\0') { - CI ci = &ct->c_ctinfo; - snprintf (buffer, sizeof(buffer), "%s-store-%s/%s", - invo_name, ci->ci_type, ci->ci_subtype); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - snprintf (buffer, sizeof(buffer), "%s-store-%s", invo_name, ci->ci_type); - if ((cp = context_find (buffer)) == NULL || *cp == '\0') { - cp = ct->c_type == CT_MESSAGE ? "+" : "%m%P.%s"; - } + /* + * Get storage formatting string. + * + * 1) If we have storeproc defined, then use that + * 2) Else check for a mhstore-store-/ entry + * 3) Else check for a mhstore-store- entry + * 4) Else if content is "message", use "+" (current folder) + * 5) Else use string "%m%P.%s". + */ + if ((cp = ct->c_storeproc) == NULL || *cp == '\0') { + CI ci = &ct->c_ctinfo; + + snprintf (buffer, sizeof(buffer), "%s-store-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + if ((cp = context_find (buffer)) == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-store-%s", invo_name, ci->ci_type); + if ((cp = context_find (buffer)) == NULL || *cp == '\0') { + cp = ct->c_type == CT_MESSAGE ? "+" : "%m%P.%s"; + } + } } - } - - /* - * Check the beginning of storage formatting string - * to see if we are saving content to a folder. - */ - if (*cp == '+' || *cp == '@') { - char *tmpfilenam, *folder; - - /* Store content in temporary file for now */ - tmpfilenam = m_mktemp(invo_name, NULL, NULL); - ct->c_storage = add (tmpfilenam, NULL); - - /* Get the folder name */ - if (cp[1]) - folder = pluspath (cp); - else - folder = getfolder (1); - /* Check if folder exists */ - create_folder(m_mailpath(folder), 0, exit); + /* + * Check the beginning of storage formatting string + * to see if we are saving content to a folder. + */ + if (*cp == '+' || *cp == '@') { + char *tmpfilenam, *folder; - /* Record the folder name */ - ct->c_folder = add (folder, NULL); + /* Store content in temporary file for now */ + tmpfilenam = m_mktemp(invo_name, NULL, NULL); + ct->c_storage = add (tmpfilenam, NULL); - if (cp[1]) - free (folder); + /* Get the folder name */ + if (cp[1]) + folder = pluspath (cp); + else + folder = getfolder (1); - goto got_filename; - } + /* Check if folder exists */ + create_folder(m_mailpath(folder), 0, exit); - /* - * Parse and expand the storage formatting string - * in `cp' into `buffer'. - */ - parse_format_string (ct, cp, buffer, sizeof(buffer), dir); + /* Record the folder name */ + ct->c_folder = add (folder, NULL); - /* - * If formatting begins with '|' or '!', then pass - * content to standard input of a command and return. - */ - if (buffer[0] == '|' || buffer[0] == '!') - return show_content_aux (ct, 1, 0, buffer + 1, dir); + if (cp[1]) + free (folder); - /* record the filename */ - ct->c_storage = add (buffer, NULL); + goto got_filename; + } + + /* + * Parse and expand the storage formatting string + * in `cp' into `buffer'. + */ + parse_format_string (ct, cp, buffer, sizeof(buffer), dir); + + /* + * If formatting begins with '|' or '!', then pass + * content to standard input of a command and return. + */ + if (buffer[0] == '|' || buffer[0] == '!') + return show_content_aux (ct, 1, 0, buffer + 1, dir); + + /* record the filename */ + ct->c_storage = add (buffer, NULL); got_filename: - /* flush the output stream */ - fflush (stdout); - - /* Now save or append the content to a file */ - if (output_content_file (ct, appending) == NOTOK) - return NOTOK; - - /* - * If necessary, link the file into a folder and remove - * the temporary file. If this message is a partial, - * then only do this if it is the last one in the group. - */ - if (ct->c_folder && (!is_partial || last_partial)) { - msgnum = output_content_folder (ct->c_folder, ct->c_storage); - unlink (ct->c_storage); - if (msgnum == NOTOK) - return NOTOK; - } - - /* - * Now print out the name/number of the message - * that we are storing. - */ - if (is_partial) { - if (first_partial) - fprintf (stderr, "reassembling partials "); - if (last_partial) - fprintf (stderr, "%s", ct->c_file); - else - fprintf (stderr, "%s,", ct->c_file); - } else { - fprintf (stderr, "storing message %s", ct->c_file); - if (ct->c_partno) - fprintf (stderr, " part %s", ct->c_partno); - } - - /* - * Unless we are in the "middle" of group of message/partials, - * we now print the name of the file, folder, and/or message - * to which we are storing the content. - */ - if (!is_partial || last_partial) { - if (ct->c_folder) { - fprintf (stderr, " to folder %s as message %d\n", ct->c_folder, msgnum); - } else if (!strcmp(ct->c_storage, "-")) { - fprintf (stderr, " to stdout\n"); + /* flush the output stream */ + fflush (stdout); + + /* Now save or append the content to a file */ + if (output_content_file (ct, appending) == NOTOK) + return NOTOK; + + /* + * If necessary, link the file into a folder and remove + * the temporary file. If this message is a partial, + * then only do this if it is the last one in the group. + */ + if (ct->c_folder && (!is_partial || last_partial)) { + msgnum = output_content_folder (ct->c_folder, ct->c_storage); + unlink (ct->c_storage); + if (msgnum == NOTOK) + return NOTOK; + } + + /* + * Now print out the name/number of the message + * that we are storing. + */ + if (is_partial) { + if (first_partial) + fprintf (stderr, "reassembling partials "); + if (last_partial) + fprintf (stderr, "%s", ct->c_file); + else + fprintf (stderr, "%s,", ct->c_file); } else { - int cwdlen; + fprintf (stderr, "storing message %s", ct->c_file); + if (ct->c_partno) + fprintf (stderr, " part %s", ct->c_partno); + } + + /* + * Unless we are in the "middle" of group of message/partials, + * we now print the name of the file, folder, and/or message + * to which we are storing the content. + */ + if (!is_partial || last_partial) { + if (ct->c_folder) { + fprintf (stderr, " to folder %s as message %d\n", ct->c_folder, msgnum); + } else if (!strcmp(ct->c_storage, "-")) { + fprintf (stderr, " to stdout\n"); + } else { + int cwdlen; - cwdlen = strlen (cwd); - fprintf (stderr, " as file %s\n", - strncmp (ct->c_storage, cwd, cwdlen) - || ct->c_storage[cwdlen] != '/' - ? ct->c_storage : ct->c_storage + cwdlen + 1); + cwdlen = strlen (cwd); + fprintf (stderr, " as file %s\n", + strncmp (ct->c_storage, cwd, cwdlen) + || ct->c_storage[cwdlen] != '/' + ? ct->c_storage : ct->c_storage + cwdlen + 1); + } } - } - return OK; + return OK; } @@ -664,198 +661,198 @@ got_filename: static int output_content_file (CT ct, int appending) { - int filterstate; - char *file, buffer[BUFSIZ]; - long pos, last; - FILE *fp; - - /* - * If the pathname is absolute, make sure - * all the relevant directories exist. - */ - if (strchr(ct->c_storage, '/') - && make_intermediates (ct->c_storage) == NOTOK) - return NOTOK; - - if (ct->c_encoding != CE_7BIT) { - int cc, fd; - - if (!ct->c_ceopenfnx) { - advise (NULL, "don't know how to decode part %s of message %s", - ct->c_partno, ct->c_file); - return NOTOK; - } - - file = appending || !strcmp (ct->c_storage, "-") ? NULL - : ct->c_storage; - if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) - return NOTOK; - if (!strcmp (file, ct->c_storage)) { - (*ct->c_ceclosefnx) (ct); - return OK; - } + int filterstate; + char *file, buffer[BUFSIZ]; + long pos, last; + FILE *fp; /* - * Send to standard output + * If the pathname is absolute, make sure + * all the relevant directories exist. */ - if (!strcmp (ct->c_storage, "-")) { - int gd; - - if ((gd = dup (fileno (stdout))) == NOTOK) { - advise ("stdout", "unable to dup"); -losing: - (*ct->c_ceclosefnx) (ct); + if (strchr(ct->c_storage, '/') + && make_intermediates (ct->c_storage) == NOTOK) return NOTOK; - } - if ((fp = fdopen (gd, appending ? "a" : "w")) == NULL) { - advise ("stdout", "unable to fdopen (%d, \"%s\") from", gd, - appending ? "a" : "w"); - close (gd); - goto losing; - } - } else { - /* - * Open output file - */ - if ((fp = fopen (ct->c_storage, appending ? "a" : "w")) == NULL) { - advise (ct->c_storage, "unable to fopen for %s", - appending ? "appending" : "writing"); - goto losing; - } - } - /* - * Filter the header fields of the initial enclosing - * message/partial into the file. - */ - if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { - struct partial *pm = (struct partial *) ct->c_ctparams; + if (ct->c_encoding != CE_7BIT) { + int cc, fd; - if (pm->pm_partno == 1) - copy_some_headers (fp, ct); - } + if (!ct->c_ceopenfnx) { + advise (NULL, "don't know how to decode part %s of message %s", + ct->c_partno, ct->c_file); + return NOTOK; + } - for (;;) { - switch (cc = read (fd, buffer, sizeof(buffer))) { - case NOTOK: - advise (file, "error reading content from"); - break; + file = appending || !strcmp (ct->c_storage, "-") ? NULL + : ct->c_storage; + if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK) + return NOTOK; + if (!strcmp (file, ct->c_storage)) { + (*ct->c_ceclosefnx) (ct); + return OK; + } - case OK: - break; + /* + * Send to standard output + */ + if (!strcmp (ct->c_storage, "-")) { + int gd; - default: - fwrite (buffer, sizeof(*buffer), cc, fp); - continue; - } - break; - } + if ((gd = dup (fileno (stdout))) == NOTOK) { + advise ("stdout", "unable to dup"); +losing: + (*ct->c_ceclosefnx) (ct); + return NOTOK; + } + if ((fp = fdopen (gd, appending ? "a" : "w")) == NULL) { + advise ("stdout", "unable to fdopen (%d, \"%s\") from", gd, + appending ? "a" : "w"); + close (gd); + goto losing; + } + } else { + /* + * Open output file + */ + if ((fp = fopen (ct->c_storage, appending ? "a" : "w")) == NULL) { + advise (ct->c_storage, "unable to fopen for %s", + appending ? "appending" : "writing"); + goto losing; + } + } - (*ct->c_ceclosefnx) (ct); + /* + * Filter the header fields of the initial enclosing + * message/partial into the file. + */ + if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { + struct partial *pm = (struct partial *) ct->c_ctparams; - if (cc != NOTOK && fflush (fp)) - advise (ct->c_storage, "error writing to"); + if (pm->pm_partno == 1) + copy_some_headers (fp, ct); + } - fclose (fp); + for (;;) { + switch (cc = read (fd, buffer, sizeof(buffer))) { + case NOTOK: + advise (file, "error reading content from"); + break; - return (cc != NOTOK ? OK : NOTOK); - } + case OK: + break; - if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { - advise (ct->c_file, "unable to open for reading"); - return NOTOK; - } + default: + fwrite (buffer, sizeof(*buffer), cc, fp); + continue; + } + break; + } - pos = ct->c_begin; - last = ct->c_end; - fseek (ct->c_fp, pos, SEEK_SET); + (*ct->c_ceclosefnx) (ct); - if (!strcmp (ct->c_storage, "-")) { - int gd; + if (cc != NOTOK && fflush (fp)) + advise (ct->c_storage, "error writing to"); - if ((gd = dup (fileno (stdout))) == NOTOK) { - advise ("stdout", "unable to dup"); - return NOTOK; - } - if ((fp = fdopen (gd, appending ? "a" : "w")) == NULL) { - advise ("stdout", "unable to fdopen (%d, \"%s\") from", gd, - appending ? "a" : "w"); - close (gd); - return NOTOK; - } - } else { - if ((fp = fopen (ct->c_storage, appending ? "a" : "w")) == NULL) { - advise (ct->c_storage, "unable to fopen for %s", - appending ? "appending" : "writing"); - return NOTOK; + fclose (fp); + + return (cc != NOTOK ? OK : NOTOK); } - } - - /* - * Copy a few of the header fields of the initial - * enclosing message/partial into the file. - */ - filterstate = 0; - if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { - struct partial *pm = (struct partial *) ct->c_ctparams; - - if (pm->pm_partno == 1) { - copy_some_headers (fp, ct); - filterstate = 1; + + if (!ct->c_fp && (ct->c_fp = fopen (ct->c_file, "r")) == NULL) { + advise (ct->c_file, "unable to open for reading"); + return NOTOK; } - } - while (fgets (buffer, sizeof(buffer) - 1, ct->c_fp)) { - if ((pos += strlen (buffer)) > last) { - int diff; + pos = ct->c_begin; + last = ct->c_end; + fseek (ct->c_fp, pos, SEEK_SET); + + if (!strcmp (ct->c_storage, "-")) { + int gd; - diff = strlen (buffer) - (pos - last); - if (diff >= 0) - buffer[diff] = '\0'; + if ((gd = dup (fileno (stdout))) == NOTOK) { + advise ("stdout", "unable to dup"); + return NOTOK; + } + if ((fp = fdopen (gd, appending ? "a" : "w")) == NULL) { + advise ("stdout", "unable to fdopen (%d, \"%s\") from", gd, + appending ? "a" : "w"); + close (gd); + return NOTOK; + } + } else { + if ((fp = fopen (ct->c_storage, appending ? "a" : "w")) == NULL) { + advise (ct->c_storage, "unable to fopen for %s", + appending ? "appending" : "writing"); + return NOTOK; + } } + /* - * If this is the first content of a group of - * message/partial contents, then we only copy a few - * of the header fields of the enclosed message. + * Copy a few of the header fields of the initial + * enclosing message/partial into the file. */ - if (filterstate) { - switch (buffer[0]) { - case ' ': - case '\t': - if (filterstate < 0) - buffer[0] = 0; - break; - - case '\n': - filterstate = 0; - break; + filterstate = 0; + if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) { + struct partial *pm = (struct partial *) ct->c_ctparams; - default: - if (!uprf (buffer, XXX_FIELD_PRF) - && !uprf (buffer, VRSN_FIELD) - && !uprf (buffer, "Subject:") - && !uprf (buffer, "Encrypted:") - && !uprf (buffer, "Message-ID:")) { - filterstate = -1; - buffer[0] = 0; + if (pm->pm_partno == 1) { + copy_some_headers (fp, ct); + filterstate = 1; + } + } + + while (fgets (buffer, sizeof(buffer) - 1, ct->c_fp)) { + if ((pos += strlen (buffer)) > last) { + int diff; + + diff = strlen (buffer) - (pos - last); + if (diff >= 0) + buffer[diff] = '\0'; + } + /* + * If this is the first content of a group of + * message/partial contents, then we only copy a few + * of the header fields of the enclosed message. + */ + if (filterstate) { + switch (buffer[0]) { + case ' ': + case '\t': + if (filterstate < 0) + buffer[0] = 0; + break; + + case '\n': + filterstate = 0; + break; + + default: + if (!uprf (buffer, XXX_FIELD_PRF) + && !uprf (buffer, VRSN_FIELD) + && !uprf (buffer, "Subject:") + && !uprf (buffer, "Encrypted:") + && !uprf (buffer, "Message-ID:")) { + filterstate = -1; + buffer[0] = 0; + break; + } + filterstate = 1; + break; + } + } + fputs (buffer, fp); + if (pos >= last) break; - } - filterstate = 1; - break; - } } - fputs (buffer, fp); - if (pos >= last) - break; - } - - if (fflush (fp)) - advise (ct->c_storage, "error writing to"); - - fclose (fp); - fclose (ct->c_fp); - ct->c_fp = NULL; - return OK; + + if (fflush (fp)) + advise (ct->c_storage, "error writing to"); + + fclose (fp); + fclose (ct->c_fp); + ct->c_fp = NULL; + return OK; } @@ -870,26 +867,26 @@ losing: static int output_content_folder (char *folder, char *filename) { - int msgnum; - struct msgs *mp; - - /* Read the folder. */ - if ((mp = folder_read (folder))) { - /* Link file into folder */ - msgnum = folder_addmsg (&mp, filename, 0, 0, 0, 0, (char *)0); - } else { - advise (NULL, "unable to read folder %s", folder); - return NOTOK; - } - - /* free folder structure */ - folder_free (mp); - - /* - * Return msgnum. We are relying on the fact that - * msgnum will be -1, if folder_addmsg() had an error. - */ - return msgnum; + int msgnum; + struct msgs *mp; + + /* Read the folder. */ + if ((mp = folder_read (folder))) { + /* Link file into folder */ + msgnum = folder_addmsg (&mp, filename, 0, 0, 0, 0, (char *)0); + } else { + advise (NULL, "unable to read folder %s", folder); + return NOTOK; + } + + /* free folder structure */ + folder_free (mp); + + /* + * Return msgnum. We are relying on the fact that + * msgnum will be -1, if folder_addmsg() had an error. + */ + return msgnum; } @@ -901,116 +898,116 @@ output_content_folder (char *folder, char *filename) static int parse_format_string (CT ct, char *cp, char *buffer, int buflen, char *dir) { - int len; - char *bp; - CI ci = &ct->c_ctinfo; - - /* - * If storage string is "-", just copy it, and - * return (send content to standard output). - */ - if (cp[0] == '-' && cp[1] == '\0') { - strncpy (buffer, cp, buflen); - return 0; - } - - bp = buffer; - bp[0] = '\0'; - - /* - * If formatting string is a pathname that doesn't - * begin with '/', then preface the path with the - * appropriate directory. - */ - if (*cp != '/' && *cp != '|' && *cp != '!') { - snprintf (bp, buflen, "%s/", dir[1] ? dir : ""); - len = strlen (bp); - bp += len; - buflen -= len; - } - - for (; *cp; cp++) { - - /* We are processing a storage escape */ - if (*cp == '%') { - switch (*++cp) { - case 'a': - /* - * Insert parameters from Content-Type. - * This is only valid for '|' commands. - */ - if (buffer[0] != '|' && buffer[0] != '!') { - *bp++ = *--cp; - *bp = '\0'; - buflen--; - continue; - } else { - char **ap, **ep; - char *s = ""; - - for (ap = ci->ci_attrs, ep = ci->ci_values; - *ap; ap++, ep++) { - snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); - len = strlen (bp); - bp += len; - buflen -= len; - s = " "; - } - } - break; - - case 'm': - /* insert message number */ - snprintf (bp, buflen, "%s", r1bindex (ct->c_file, '/')); - break; - - case 'P': - /* insert part number with leading dot */ - if (ct->c_partno) - snprintf (bp, buflen, ".%s", ct->c_partno); - break; - - case 'p': - /* insert part number withouth leading dot */ - if (ct->c_partno) - strncpy (bp, ct->c_partno, buflen); - break; - - case 't': - /* insert content type */ - strncpy (bp, ci->ci_type, buflen); - break; - - case 's': - /* insert content subtype */ - strncpy (bp, ci->ci_subtype, buflen); - break; - - case '%': - /* insert the character % */ - goto raw; + int len; + char *bp; + CI ci = &ct->c_ctinfo; - default: - *bp++ = *--cp; - *bp = '\0'; - buflen--; - continue; - } + /* + * If storage string is "-", just copy it, and + * return (send content to standard output). + */ + if (cp[0] == '-' && cp[1] == '\0') { + strncpy (buffer, cp, buflen); + return 0; + } - /* Advance bp and decrement buflen */ - len = strlen (bp); - bp += len; - buflen -= len; + bp = buffer; + bp[0] = '\0'; - } else { + /* + * If formatting string is a pathname that doesn't + * begin with '/', then preface the path with the + * appropriate directory. + */ + if (*cp != '/' && *cp != '|' && *cp != '!') { + snprintf (bp, buflen, "%s/", dir[1] ? dir : ""); + len = strlen (bp); + bp += len; + buflen -= len; + } + + for (; *cp; cp++) { + + /* We are processing a storage escape */ + if (*cp == '%') { + switch (*++cp) { + case 'a': + /* + * Insert parameters from Content-Type. + * This is only valid for '|' commands. + */ + if (buffer[0] != '|' && buffer[0] != '!') { + *bp++ = *--cp; + *bp = '\0'; + buflen--; + continue; + } else { + char **ap, **ep; + char *s = ""; + + for (ap = ci->ci_attrs, ep = ci->ci_values; + *ap; ap++, ep++) { + snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep); + len = strlen (bp); + bp += len; + buflen -= len; + s = " "; + } + } + break; + + case 'm': + /* insert message number */ + snprintf (bp, buflen, "%s", r1bindex (ct->c_file, '/')); + break; + + case 'P': + /* insert part number with leading dot */ + if (ct->c_partno) + snprintf (bp, buflen, ".%s", ct->c_partno); + break; + + case 'p': + /* insert part number withouth leading dot */ + if (ct->c_partno) + strncpy (bp, ct->c_partno, buflen); + break; + + case 't': + /* insert content type */ + strncpy (bp, ci->ci_type, buflen); + break; + + case 's': + /* insert content subtype */ + strncpy (bp, ci->ci_subtype, buflen); + break; + + case '%': + /* insert the character % */ + goto raw; + + default: + *bp++ = *--cp; + *bp = '\0'; + buflen--; + continue; + } + + /* Advance bp and decrement buflen */ + len = strlen (bp); + bp += len; + buflen -= len; + + } else { raw: - *bp++ = *cp; - *bp = '\0'; - buflen--; + *bp++ = *cp; + *bp = '\0'; + buflen--; + } } - } - return 0; + return 0; } @@ -1022,33 +1019,33 @@ raw: static void get_storeproc (CT ct) { - char **ap, **ep, *cp; - CI ci = &ct->c_ctinfo; - - /* - * If the storeproc has already been defined, - * we just return (for instance, if this content - * is part of a "message/external". - */ - if (ct->c_storeproc) - return; - - /* - * Check the attribute/value pairs, for the attribute "name". - * If found, do a few sanity checks and copy the value into - * the storeproc. - */ - for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { - if (!mh_strcasecmp (*ap, "name") - && *(cp = *ep) != '/' - && *cp != '.' - && *cp != '|' - && *cp != '!' - && !strchr (cp, '%')) { - ct->c_storeproc = add (cp, NULL); - return; + char **ap, **ep, *cp; + CI ci = &ct->c_ctinfo; + + /* + * If the storeproc has already been defined, + * we just return (for instance, if this content + * is part of a "message/external". + */ + if (ct->c_storeproc) + return; + + /* + * Check the attribute/value pairs, for the attribute "name". + * If found, do a few sanity checks and copy the value into + * the storeproc. + */ + for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { + if (!mh_strcasecmp (*ap, "name") + && *(cp = *ep) != '/' + && *cp != '.' + && *cp != '|' + && *cp != '!' + && !strchr (cp, '%')) { + ct->c_storeproc = add (cp, NULL); + return; + } } - } } @@ -1060,23 +1057,23 @@ get_storeproc (CT ct) static int copy_some_headers (FILE *out, CT ct) { - HF hp; - - hp = ct->c_first_hf; /* start at first header field */ + HF hp; + + hp = ct->c_first_hf; /* start at first header field */ + + while (hp) { + /* + * A few of the header fields of the enclosing + * messages are not copied. + */ + if (!uprf (hp->name, XXX_FIELD_PRF) + && mh_strcasecmp (hp->name, VRSN_FIELD) + && mh_strcasecmp (hp->name, "Subject") + && mh_strcasecmp (hp->name, "Encrypted") + && mh_strcasecmp (hp->name, "Message-ID")) + fprintf (out, "%s:%s", hp->name, hp->value); + hp = hp->next; /* next header field */ + } - while (hp) { - /* - * A few of the header fields of the enclosing - * messages are not copied. - */ - if (!uprf (hp->name, XXX_FIELD_PRF) - && mh_strcasecmp (hp->name, VRSN_FIELD) - && mh_strcasecmp (hp->name, "Subject") - && mh_strcasecmp (hp->name, "Encrypted") - && mh_strcasecmp (hp->name, "Message-ID")) - fprintf (out, "%s:%s", hp->name, hp->value); - hp = hp->next; /* next header field */ - } - - return OK; + return OK; } diff --git a/uip/mhtest.c b/uip/mhtest.c index 5c10b8b..9f21c01 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -1,4 +1,3 @@ - /* * mhtest.c -- test harness for MIME routines * @@ -25,44 +24,44 @@ #endif static struct swit switches[] = { -#define CHECKSW 0 - { "check", 0 }, -#define NCHECKSW 1 - { "nocheck", 0 }, -#define VERBSW 2 - { "verbose", 0 }, -#define NVERBSW 3 - { "noverbose", 0 }, -#define FILESW 4 - { "file file", 0 }, -#define OUTFILESW 5 - { "outfile file", 0 }, -#define PARTSW 6 - { "part number", 0 }, -#define TYPESW 7 - { "type content", 0 }, -#define RCACHESW 8 - { "rcache policy", 0 }, -#define WCACHESW 9 - { "wcache policy", 0 }, -#define VERSIONSW 10 - { "version", 0 }, -#define HELPSW 11 - { "help", 0 }, +#define CHECKSW 0 + { "check", 0 }, +#define NCHECKSW 1 + { "nocheck", 0 }, +#define VERBSW 2 + { "verbose", 0 }, +#define NVERBSW 3 + { "noverbose", 0 }, +#define FILESW 4 + { "file file", 0 }, +#define OUTFILESW 5 + { "outfile file", 0 }, +#define PARTSW 6 + { "part number", 0 }, +#define TYPESW 7 + { "type content", 0 }, +#define RCACHESW 8 + { "rcache policy", 0 }, +#define WCACHESW 9 + { "wcache policy", 0 }, +#define VERSIONSW 10 + { "version", 0 }, +#define HELPSW 11 + { "help", 0 }, /* * switches for debugging */ -#define DEBUGSW 12 - { "debug", -5 }, - { NULL, 0 } +#define DEBUGSW 12 + { "debug", -5 }, + { NULL, 0 } }; -int ebcdicsw = 0; /* hack for linking purposes */ +int ebcdicsw = 0; /* hack for linking purposes */ /* mhparse.c */ -extern char *tmp; /* directory to place temp files */ +extern char *tmp; /* directory to place temp files */ /* mhcachesbr.c */ extern int rcachesw; @@ -86,7 +85,7 @@ pid_t xpid = 0; int debugsw = 0; int verbosw = 0; -#define quitser pipeser +#define quitser pipeser /* mhparse.c */ CT parse_mime (char *); @@ -115,282 +114,282 @@ static RETSIGTYPE pipeser (int); int main (int argc, char **argv) { - int msgnum, *icachesw; - char *cp, *file = NULL, *folder = NULL; - char *maildir, buf[100], *outfile = NULL; - char **argp, **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp = NULL; - CT ct, *ctp; + int msgnum, *icachesw; + char *cp, *file = NULL, *folder = NULL; + char *maildir, buf[100], *outfile = NULL; + char **argp, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp = NULL; + CT ct, *ctp; - done=freects_done; + done=freects_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + invo_name = r1bindex (argv[0], '/'); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; - case RCACHESW: - icachesw = &rcachesw; - goto do_cache; - case WCACHESW: - icachesw = &wcachesw; + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case RCACHESW: + icachesw = &rcachesw; + goto do_cache; + case WCACHESW: + icachesw = &wcachesw; do_cache: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - switch (*icachesw = smatch (cp, caches)) { - case AMBIGSW: - ambigsw (cp, caches); - done (1); - case UNKWNSW: - adios (NULL, "%s unknown", cp); - default: - break; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + switch (*icachesw = smatch (cp, caches)) { + case AMBIGSW: + ambigsw (cp, caches); + done (1); + case UNKWNSW: + adios (NULL, "%s unknown", cp); + default: + break; + } + continue; + + case CHECKSW: + checksw++; + continue; + case NCHECKSW: + checksw = 0; + continue; + + case PARTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (npart >= NPARTS) + adios (NULL, "too many parts (starting with %s), %d max", + cp, NPARTS); + parts[npart++] = cp; + continue; + + case TYPESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (ntype >= NTYPES) + adios (NULL, "too many types (starting with %s), %d max", + cp, NTYPES); + types[ntype++] = cp; + continue; + + case FILESW: + if (!(cp = *argp++) || (*cp == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + file = *cp == '-' ? cp : path (cp, TFILE); + continue; + + case OUTFILESW: + if (!(cp = *argp++) || (*cp == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + outfile = *cp == '-' ? cp : path (cp, TFILE); + continue; + + case VERBSW: + verbosw = 1; + continue; + case NVERBSW: + verbosw = 0; + continue; + case DEBUGSW: + debugsw = 1; + continue; + } } - continue; - - case CHECKSW: - checksw++; - continue; - case NCHECKSW: - checksw = 0; - continue; - - case PARTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (npart >= NPARTS) - adios (NULL, "too many parts (starting with %s), %d max", - cp, NPARTS); - parts[npart++] = cp; - continue; - - case TYPESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (ntype >= NTYPES) - adios (NULL, "too many types (starting with %s), %d max", - cp, NTYPES); - types[ntype++] = cp; - continue; - - case FILESW: - if (!(cp = *argp++) || (*cp == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - file = *cp == '-' ? cp : path (cp, TFILE); - continue; - - case OUTFILESW: - if (!(cp = *argp++) || (*cp == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - outfile = *cp == '-' ? cp : path (cp, TFILE); - continue; - - case VERBSW: - verbosw = 1; - continue; - case NVERBSW: - verbosw = 0; - continue; - case DEBUGSW: - debugsw = 1; - continue; - } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - /* null terminate the list of acceptable parts/types */ - parts[npart] = NULL; - types[ntype] = NULL; - - set_endian (); - - if (outfile == NULL) - adios (NULL, "must specify output file"); - - /* Check for public cache location */ - if ((cache_public = context_find (nmhcache)) && *cache_public != '/') - cache_public = NULL; - - /* Check for private cache location */ - if (!(cache_private = context_find (nmhprivcache))) - cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); - - /* - * Check for storage directory. If specified, - * then store temporary files there. Else we - * store them in standard nmh directory. - */ - if ((cp = context_find (nmhstorage)) && *cp) - tmp = concat (cp, "/", invo_name, NULL); - else - tmp = add (m_maildir (invo_name), NULL); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (file && msgs.size) - adios (NULL, "cannot specify msg and file at same time!"); - - /* - * check if message is coming from file - */ - if (file) { - if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; - - if ((ct = parse_mime (file))); - *ctp++ = ct; - } else { + + /* null terminate the list of acceptable parts/types */ + parts[npart] = NULL; + types[ntype] = NULL; + + set_endian (); + + if (outfile == NULL) + adios (NULL, "must specify output file"); + + /* Check for public cache location */ + if ((cache_public = context_find (nmhcache)) && *cache_public != '/') + cache_public = NULL; + + /* Check for private cache location */ + if (!(cache_private = context_find (nmhprivcache))) + cache_private = ".cache"; + cache_private = getcpy (m_maildir (cache_private)); + /* - * message(s) are coming from a folder + * Check for storage directory. If specified, + * then store temporary files there. Else we + * store them in standard nmh directory. */ - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ + if ((cp = context_find (nmhstorage)) && *cp) + tmp = concat (cp, "/", invo_name, NULL); + else + tmp = add (m_maildir (invo_name), NULL); - if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) - adios (NULL, "out of memory"); - ctp = cts; + if (!context_find ("path")) + free (path ("./", TFOLDER)); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - char *msgnam; + if (file && msgs.size) + adios (NULL, "cannot specify msg and file at same time!"); - msgnam = m_name (msgnum); - if ((ct = parse_mime (msgnam))) - *ctp++ = ct; - } + /* + * check if message is coming from file + */ + if (file) { + if (!(cts = (CT *) calloc ((size_t) 2, sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + if ((ct = parse_mime (file))); + *ctp++ = ct; + } else { + /* + * message(s) are coming from a folder + */ + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (!(cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof(*cts)))) + adios (NULL, "out of memory"); + ctp = cts; + + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + char *msgnam; + + msgnam = m_name (msgnum); + if ((ct = parse_mime (msgnam))) + *ctp++ = ct; + } + } } - } - if (!*cts) - done (1); + if (!*cts) + done (1); + + userrs = 1; + SIGNAL (SIGQUIT, quitser); + SIGNAL (SIGPIPE, pipeser); - userrs = 1; - SIGNAL (SIGQUIT, quitser); - SIGNAL (SIGPIPE, pipeser); - - /* - * Get the associated umask for the relevant contents. - */ - for (ctp = cts; *ctp; ctp++) { - struct stat st; - - ct = *ctp; - if (type_ok (ct, 1) && !ct->c_umask) { - if (stat (ct->c_file, &st) != NOTOK) - ct->c_umask = ~(st.st_mode & 0777); - else - ct->c_umask = ~m_gmprot(); + /* + * Get the associated umask for the relevant contents. + */ + for (ctp = cts; *ctp; ctp++) { + struct stat st; + + ct = *ctp; + if (type_ok (ct, 1) && !ct->c_umask) { + if (stat (ct->c_file, &st) != NOTOK) + ct->c_umask = ~(st.st_mode & 0777); + else + ct->c_umask = ~m_gmprot(); + } } - } - - /* - * Write the content to a file - */ - write_content (cts, outfile); - - /* Now free all the structures for the content */ - for (ctp = cts; *ctp; ctp++) - free_content (*ctp); - - free ((char *) cts); - cts = NULL; - - /* If reading from a folder, do some updating */ - if (mp) { - context_replace (pfolder, folder);/* update current folder */ - seq_setcur (mp, mp->hghsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - done (0); - return 1; + + /* + * Write the content to a file + */ + write_content (cts, outfile); + + /* Now free all the structures for the content */ + for (ctp = cts; *ctp; ctp++) + free_content (*ctp); + + free ((char *) cts); + cts = NULL; + + /* If reading from a folder, do some updating */ + if (mp) { + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->hghsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ + } + + done (0); + return 1; } static int write_content (CT *cts, char *outfile) { - CT ct, *ctp; + CT ct, *ctp; - for (ctp = cts; *ctp; ctp++) { - ct = *ctp; - output_message (ct, outfile); - } + for (ctp = cts; *ctp; ctp++) { + ct = *ctp; + output_message (ct, outfile); + } - flush_errors (); - return OK; + flush_errors (); + return OK; } static RETSIGTYPE pipeser (int i) { - if (i == SIGQUIT) { - unlink ("core"); - fflush (stdout); - fprintf (stderr, "\n"); - fflush (stderr); - } - - done (1); - /* NOTREACHED */ + if (i == SIGQUIT) { + unlink ("core"); + fflush (stdout); + fprintf (stderr, "\n"); + fflush (stderr); + } + + done (1); + /* NOTREACHED */ } diff --git a/uip/msgchk.c b/uip/msgchk.c index 7ee5df5..0bec675 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -1,4 +1,3 @@ - /* * msgchk.c -- check for mail * @@ -13,18 +12,18 @@ #include static struct swit switches[] = { -#define DATESW 0 - { "date", 0 }, -#define NDATESW 1 - { "nodate", 0 }, -#define NOTESW 2 - { "notify type", 0 }, -#define NNOTESW 3 - { "nonotify type", 0 }, -#define VERSIONSW 7 - { "version", 0 }, -#define HELPSW 8 - { "help", 0 }, +#define DATESW 0 + { "date", 0 }, +#define NDATESW 1 + { "nodate", 0 }, +#define NOTESW 2 + { "notify type", 0 }, +#define NNOTESW 3 + { "nonotify type", 0 }, +#define VERSIONSW 7 + { "version", 0 }, +#define HELPSW 8 + { "help", 0 }, }; /* @@ -33,18 +32,18 @@ static struct swit switches[] = { */ #define MAXVEC 51 -#define NT_NONE 0x0 -#define NT_MAIL 0x1 -#define NT_NMAI 0x2 -#define NT_ALL (NT_MAIL | NT_NMAI) +#define NT_NONE 0x0 +#define NT_MAIL 0x1 +#define NT_NMAI 0x2 +#define NT_ALL (NT_MAIL | NT_NMAI) -#define NONEOK 0x0 -#define UUCPOLD 0x1 -#define UUCPNEW 0x2 -#define UUCPOK (UUCPOLD | UUCPNEW) -#define MMDFOLD 0x4 -#define MMDFNEW 0x8 -#define MMDFOK (MMDFOLD | MMDFNEW) +#define NONEOK 0x0 +#define UUCPOLD 0x1 +#define UUCPNEW 0x2 +#define UUCPOK (UUCPOLD | UUCPNEW) +#define MMDFOLD 0x4 +#define MMDFNEW 0x8 +#define MMDFOK (MMDFOLD | MMDFNEW) /* @@ -57,180 +56,180 @@ static int checkmail (char *, char *, int, int, int); int main (int argc, char **argv) { - int datesw = 1, notifysw = NT_ALL; - int status = 0; - int vecp = 0; - uid_t uid; - char buf[BUFSIZ]; - char *user, *cp; - char **argp, **arguments, *vec[MAXVEC]; - struct passwd *pw; + int datesw = 1, notifysw = NT_ALL; + int status = 0; + int vecp = 0; + uid_t uid; + char buf[BUFSIZ]; + char *user, *cp; + char **argp, **arguments, *vec[MAXVEC]; + struct passwd *pw; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - uid = getuid (); - user = getusername(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] [users ...]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case DATESW: - datesw++; - continue; - case NDATESW: - datesw = 0; - continue; - - case NOTESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - notifysw |= donote (cp, 1); - continue; - case NNOTESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - notifysw &= ~donote (cp, 0); - continue; - } - } - if (vecp >= MAXVEC-1) - adios (NULL, "you can only check %d users at a time", MAXVEC-1); - else - vec[vecp++] = cp; - } - - if (vecp != 0) - vec[vecp] = NULL; - - if (vecp == 0) { - char *home; - - /* Not sure this check makes sense... */ - if (!geteuid() || NULL == (home = getenv("HOME"))) { - pw = getpwnam (user); - if (pw == NULL) - adios (NULL, "unable to get information about user"); - home = pw->pw_dir; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + uid = getuid (); + user = getusername(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] [users ...]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DATESW: + datesw++; + continue; + case NDATESW: + datesw = 0; + continue; + + case NOTESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + notifysw |= donote (cp, 1); + continue; + case NNOTESW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + notifysw &= ~donote (cp, 0); + continue; + } + } + if (vecp >= MAXVEC-1) + adios (NULL, "you can only check %d users at a time", MAXVEC-1); + else + vec[vecp++] = cp; } - status = checkmail (user, home, datesw, notifysw, 1); - } else { - for (vecp = 0; vec[vecp]; vecp++) { - if ((pw = getpwnam (vec[vecp]))) - status += checkmail (pw->pw_name, pw->pw_dir, datesw, notifysw, 0); - else - advise (NULL, "no such user as %s", vec[vecp]); + + if (vecp != 0) + vec[vecp] = NULL; + + if (vecp == 0) { + char *home; + + /* Not sure this check makes sense... */ + if (!geteuid() || NULL == (home = getenv("HOME"))) { + pw = getpwnam (user); + if (pw == NULL) + adios (NULL, "unable to get information about user"); + home = pw->pw_dir; + } + status = checkmail (user, home, datesw, notifysw, 1); + } else { + for (vecp = 0; vec[vecp]; vecp++) { + if ((pw = getpwnam (vec[vecp]))) + status += checkmail (pw->pw_name, pw->pw_dir, datesw, notifysw, 0); + else + advise (NULL, "no such user as %s", vec[vecp]); + } } - } - done (status); - return 1; + done (status); + return 1; } static struct swit ntswitches[] = { -#define NALLSW 0 - { "all", 0 }, -#define NMAISW 1 - { "mail", 0 }, -#define NNMAISW 2 - { "nomail", 0 }, - { NULL, 0 } +#define NALLSW 0 + { "all", 0 }, +#define NMAISW 1 + { "mail", 0 }, +#define NNMAISW 2 + { "nomail", 0 }, + { NULL, 0 } }; static int donote (char *cp, int ntflag) { - switch (smatch (cp, ntswitches)) { - case AMBIGSW: - ambigsw (cp, ntswitches); - done (1); - case UNKWNSW: - adios (NULL, "-%snotify %s unknown", ntflag ? "" : "no", cp); - - case NALLSW: - return NT_ALL; - case NMAISW: - return NT_MAIL; - case NNMAISW: - return NT_NMAI; - } - - return 0; /* Before 1999-07-15, garbage was returned if control got here. */ + switch (smatch (cp, ntswitches)) { + case AMBIGSW: + ambigsw (cp, ntswitches); + done (1); + case UNKWNSW: + adios (NULL, "-%snotify %s unknown", ntflag ? "" : "no", cp); + + case NALLSW: + return NT_ALL; + case NMAISW: + return NT_MAIL; + case NNMAISW: + return NT_NMAI; + } + + return 0; /* Before 1999-07-15, garbage was returned if control got here. */ } static int checkmail (char *user, char *home, int datesw, int notifysw, int personal) { - int mf, status; - char buffer[BUFSIZ]; - struct stat st; - - snprintf (buffer, sizeof(buffer), "%s/%s", mmdfldir[0] ? mmdfldir : home, mmdflfil[0] ? mmdflfil : user); - if (datesw) { - st.st_size = 0; - st.st_atime = st.st_mtime = 0; - } - mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK - : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD; - - if ((mf & UUCPOK) || (mf & MMDFOK)) { - if (notifysw & NT_MAIL) { - printf (personal ? "You have " : "%s has ", user); - if (mf & UUCPOK) - printf ("%s old-style bell", mf & UUCPOLD ? "old" : "new"); - if ((mf & UUCPOK) && (mf & MMDFOK)) - printf (" and "); - if (mf & MMDFOK) - printf ("%s%s", mf & MMDFOLD ? "old" : "new", - mf & UUCPOK ? " Internet" : ""); - printf (" mail waiting"); - } else { - notifysw = 0; + int mf, status; + char buffer[BUFSIZ]; + struct stat st; + + snprintf (buffer, sizeof(buffer), "%s/%s", mmdfldir[0] ? mmdfldir : home, mmdflfil[0] ? mmdflfil : user); + if (datesw) { + st.st_size = 0; + st.st_atime = st.st_mtime = 0; + } + mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK + : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD; + + if ((mf & UUCPOK) || (mf & MMDFOK)) { + if (notifysw & NT_MAIL) { + printf (personal ? "You have " : "%s has ", user); + if (mf & UUCPOK) + printf ("%s old-style bell", mf & UUCPOLD ? "old" : "new"); + if ((mf & UUCPOK) && (mf & MMDFOK)) + printf (" and "); + if (mf & MMDFOK) + printf ("%s%s", mf & MMDFOLD ? "old" : "new", + mf & UUCPOK ? " Internet" : ""); + printf (" mail waiting"); + } else { + notifysw = 0; + } + status = 0; } - status = 0; - } - else { - if (notifysw & NT_NMAI) - printf (personal ? "You don't %s%s" : "%s doesn't %s", - personal ? "" : user, "have any mail waiting"); - else - notifysw = 0; - - status = 1; - } - - if (notifysw) - if (datesw && st.st_atime) - printf ("; last read on %s", dtime (&st.st_atime, 1)); - if (notifysw) - printf ("\n"); - - return status; + else { + if (notifysw & NT_NMAI) + printf (personal ? "You don't %s%s" : "%s doesn't %s", + personal ? "" : user, "have any mail waiting"); + else + notifysw = 0; + + status = 1; + } + + if (notifysw) + if (datesw && st.st_atime) + printf ("; last read on %s", dtime (&st.st_atime, 1)); + if (notifysw) + printf ("\n"); + + return status; } diff --git a/uip/new.c b/uip/new.c index 99d8528..49840a1 100644 --- a/uip/new.c +++ b/uip/new.c @@ -1,4 +1,3 @@ - /* * new.c -- as new, list all folders with unseen messages * -- as fnext, move to next folder with unseen messages @@ -23,14 +22,14 @@ static struct swit switches[] = { #define MODESW 0 - { "mode", 1 }, + { "mode", 1 }, #define FOLDERSSW 1 - { "folders", 1 }, + { "folders", 1 }, #define VERSIONSW 2 - { "version", 1 }, + { "version", 1 }, #define HELPSW 3 - { "help", 1 }, - { NULL, 0 } + { "help", 1 }, + { NULL, 0 } }; static enum { NEW, FNEXT, FPREV, UNSEEN } run_mode = NEW; @@ -38,52 +37,52 @@ static enum { NEW, FNEXT, FPREV, UNSEEN } run_mode = NEW; /* check_folders uses this to maintain state with both .folders list of * folders and with crawl_folders. */ struct list_state { - struct node **first, **cur_node; - size_t *maxlen; - char *cur; - char **sequences; - struct node *node; + struct node **first, **cur_node; + size_t *maxlen; + char *cur; + char **sequences; + struct node *node; }; /* Return the number of messages in a string list of message numbers. */ static int count_messages(char *field) { - int total = 0; - int j, k; - char *cp, **ap; + int total = 0; + int j, k; + char *cp, **ap; - field = getcpy(field); + field = getcpy(field); - /* copied from seq_read.c:seq_init */ - for (ap = brkstring (field, " ", "\n"); *ap; ap++) { - if ((cp = strchr(*ap, '-'))) - *cp++ = '\0'; - if ((j = m_atoi (*ap)) > 0) { - k = cp ? m_atoi (cp) : j; + /* copied from seq_read.c:seq_init */ + for (ap = brkstring (field, " ", "\n"); *ap; ap++) { + if ((cp = strchr(*ap, '-'))) + *cp++ = '\0'; + if ((j = m_atoi (*ap)) > 0) { + k = cp ? m_atoi (cp) : j; - total += k - j + 1; - } - } + total += k - j + 1; + } + } - free(field); + free(field); - return total; + return total; } /* Return TRUE if the sequence 'name' is in 'sequences'. */ static boolean seq_in_list(char *name, char *sequences[]) { - int i; + int i; - for (i = 0; sequences[i] != NULL; i++) { - if (strcmp(name, sequences[i]) == 0) { - return TRUE; + for (i = 0; sequences[i] != NULL; i++) { + if (strcmp(name, sequences[i]) == 0) { + return TRUE; + } } - } - return FALSE; + return FALSE; } /* Return the string list of message numbers from the sequences file, or NULL @@ -91,84 +90,84 @@ seq_in_list(char *name, char *sequences[]) static char * get_msgnums(char *folder, char *sequences[]) { - char *seqfile = concat(m_maildir(folder), "/", mh_seq, (void *)NULL); - FILE *fp = fopen(seqfile, "r"); - int state; - char name[NAMESZ], field[BUFSIZ]; - char *cp; - char *msgnums = NULL, *this_msgnums, *old_msgnums; - - /* no sequences file -> no messages */ - if (fp == NULL) { - return NULL; - } - - /* copied from seq_read.c:seq_public */ - for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - if (state == FLDPLUS) { - cp = getcpy (field); - while (state == FLDPLUS) { - state = m_getfld (state, name, field, - sizeof(field), fp); - cp = add (field, cp); - } - - /* Here's where we differ from seq_public: if it's in a - * sequence we want, save the list of messages. */ - if (seq_in_list(name, sequences)) { - this_msgnums = trimcpy(cp); - if (msgnums == NULL) { - msgnums = this_msgnums; - } else { - old_msgnums = msgnums; - msgnums = concat(old_msgnums, " ", - this_msgnums, (void *)NULL); - free(old_msgnums); - free(this_msgnums); - } - } - free (cp); - } else { - /* and here */ - if (seq_in_list(name, sequences)) { - this_msgnums = trimcpy(field); - if (msgnums == NULL) { - msgnums = this_msgnums; - } else { - old_msgnums = msgnums; - msgnums = concat(old_msgnums, " ", - this_msgnums, (void *)NULL); - free(old_msgnums); - free(this_msgnums); - } - } - } - - if (state == FLDEOF) - break; - continue; - - case BODY: - case BODYEOF: - adios (NULL, "no blank lines are permitted in %s", seqfile); - /* fall */ - - case FILEEOF: - break; + char *seqfile = concat(m_maildir(folder), "/", mh_seq, (void *)NULL); + FILE *fp = fopen(seqfile, "r"); + int state; + char name[NAMESZ], field[BUFSIZ]; + char *cp; + char *msgnums = NULL, *this_msgnums, *old_msgnums; + + /* no sequences file -> no messages */ + if (fp == NULL) { + return NULL; + } - default: - adios (NULL, "%s is poorly formatted", seqfile); - } - break; /* break from for loop */ - } + /* copied from seq_read.c:seq_public */ + for (state = FLD;;) { + switch (state = m_getfld (state, name, field, sizeof(field), fp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + if (state == FLDPLUS) { + cp = getcpy (field); + while (state == FLDPLUS) { + state = m_getfld (state, name, field, + sizeof(field), fp); + cp = add (field, cp); + } + + /* Here's where we differ from seq_public: if it's in a + * sequence we want, save the list of messages. */ + if (seq_in_list(name, sequences)) { + this_msgnums = trimcpy(cp); + if (msgnums == NULL) { + msgnums = this_msgnums; + } else { + old_msgnums = msgnums; + msgnums = concat(old_msgnums, " ", + this_msgnums, (void *)NULL); + free(old_msgnums); + free(this_msgnums); + } + } + free (cp); + } else { + /* and here */ + if (seq_in_list(name, sequences)) { + this_msgnums = trimcpy(field); + if (msgnums == NULL) { + msgnums = this_msgnums; + } else { + old_msgnums = msgnums; + msgnums = concat(old_msgnums, " ", + this_msgnums, (void *)NULL); + free(old_msgnums); + free(this_msgnums); + } + } + } + + if (state == FLDEOF) + break; + continue; + + case BODY: + case BODYEOF: + adios (NULL, "no blank lines are permitted in %s", seqfile); + /* fall */ + + case FILEEOF: + break; + + default: + adios (NULL, "%s is poorly formatted", seqfile); + } + break; /* break from for loop */ + } - fclose(fp); + fclose(fp); - return msgnums; + return msgnums; } /* Check `folder' (of length `len') for interesting messages, filling in the @@ -176,35 +175,35 @@ get_msgnums(char *folder, char *sequences[]) static void check_folder(char *folder, size_t len, struct list_state *b) { - char *msgnums = get_msgnums(folder, b->sequences); - int is_cur = strcmp(folder, b->cur) == 0; - - if (is_cur || msgnums != NULL) { - if (*b->first == NULL) { - *b->first = b->node = mh_xmalloc(sizeof(*b->node)); - } else { - b->node->n_next = mh_xmalloc(sizeof(*b->node)); - b->node = b->node->n_next; + char *msgnums = get_msgnums(folder, b->sequences); + int is_cur = strcmp(folder, b->cur) == 0; + + if (is_cur || msgnums != NULL) { + if (*b->first == NULL) { + *b->first = b->node = mh_xmalloc(sizeof(*b->node)); + } else { + b->node->n_next = mh_xmalloc(sizeof(*b->node)); + b->node = b->node->n_next; + } + b->node->n_name = folder; + b->node->n_field = msgnums; + + if (*b->maxlen < len) { + *b->maxlen = len; + } } - b->node->n_name = folder; - b->node->n_field = msgnums; - if (*b->maxlen < len) { - *b->maxlen = len; + /* Save the node for the current folder, so we can fall back to it. */ + if (is_cur) { + *b->cur_node = b->node; } - } - - /* Save the node for the current folder, so we can fall back to it. */ - if (is_cur) { - *b->cur_node = b->node; - } } static boolean crawl_callback(char *folder, void *baton) { - check_folder(folder, strlen(folder), baton); - return TRUE; + check_folder(folder, strlen(folder), baton); + return TRUE; } /* Scan folders, returning: @@ -223,67 +222,67 @@ crawl_callback(char *folder, void *baton) */ static void check_folders(struct node **first, struct node **last, - struct node **cur_node, size_t *maxlen, - char *cur, char *folders, char *sequences[]) + struct node **cur_node, size_t *maxlen, + char *cur, char *folders, char *sequences[]) { - struct list_state b; - FILE *fp; - char *line; - size_t len; - - *first = *last = *cur_node = NULL; - *maxlen = 0; - - b.first = first; - b.cur_node = cur_node; - b.maxlen = maxlen; - b.cur = cur; - b.sequences = sequences; - - if (folders == NULL) { - chdir(m_maildir("")); - crawl_folders(".", crawl_callback, &b); - } else { - fp = fopen(folders, "r"); - if (fp == NULL) { - adios(NULL, "failed to read %s", folders); - } - while (vfgets(fp, &line) == OK) { - len = strlen(line) - 1; - line[len] = '\0'; - check_folder(getcpy(line), len, &b); + struct list_state b; + FILE *fp; + char *line; + size_t len; + + *first = *last = *cur_node = NULL; + *maxlen = 0; + + b.first = first; + b.cur_node = cur_node; + b.maxlen = maxlen; + b.cur = cur; + b.sequences = sequences; + + if (folders == NULL) { + chdir(m_maildir("")); + crawl_folders(".", crawl_callback, &b); + } else { + fp = fopen(folders, "r"); + if (fp == NULL) { + adios(NULL, "failed to read %s", folders); + } + while (vfgets(fp, &line) == OK) { + len = strlen(line) - 1; + line[len] = '\0'; + check_folder(getcpy(line), len, &b); + } + fclose(fp); } - fclose(fp); - } - if (*first != NULL) { - b.node->n_next = NULL; - *last = b.node; - } + if (*first != NULL) { + b.node->n_next = NULL; + *last = b.node; + } } /* Return a single string of the `sequences' joined by a space (' '). */ static char * join_sequences(char *sequences[]) { - int i; - size_t len = 0; - char *result, *cp; - - for (i = 0; sequences[i] != NULL; i++) { - len += strlen(sequences[i]) + 1; - } - result = mh_xmalloc(len + 1); - - for (i = 0, cp = result; sequences[i] != NULL; i++, cp += len + 1) { - len = strlen(sequences[i]); - memcpy(cp, sequences[i], len); - cp[len] = ' '; - } - /* -1 to overwrite the last delimiter */ - *--cp = '\0'; - - return result; + int i; + size_t len = 0; + char *result, *cp; + + for (i = 0; sequences[i] != NULL; i++) { + len += strlen(sequences[i]) + 1; + } + result = mh_xmalloc(len + 1); + + for (i = 0, cp = result; sequences[i] != NULL; i++, cp += len + 1) { + len = strlen(sequences[i]); + memcpy(cp, sequences[i], len); + cp[len] = ' '; + } + /* -1 to overwrite the last delimiter */ + *--cp = '\0'; + + return result; } /* Return a struct node for the folder to change to. This is the next @@ -297,218 +296,218 @@ join_sequences(char *sequences[]) static struct node * doit(char *cur, char *folders, char *sequences[]) { - struct node *first, *cur_node, *node, *last, *prev; - size_t folder_len; - int count, total = 0; - char *command = NULL, *sequences_s = NULL; - - if (cur == NULL || cur[0] == '\0') { - cur = "inbox"; - } - - check_folders(&first, &last, &cur_node, &folder_len, cur, - folders, sequences); - - if (run_mode == FNEXT || run_mode == FPREV) { - if (first == NULL) { - /* No folders at all... */ - return NULL; - } else if (first->n_next == NULL) { - /* We have only one node; any desired messages in it? */ - if (first->n_field == NULL) { - return NULL; - } else { + struct node *first, *cur_node, *node, *last, *prev; + size_t folder_len; + int count, total = 0; + char *command = NULL, *sequences_s = NULL; + + if (cur == NULL || cur[0] == '\0') { + cur = "inbox"; + } + + check_folders(&first, &last, &cur_node, &folder_len, cur, + folders, sequences); + + if (run_mode == FNEXT || run_mode == FPREV) { + if (first == NULL) { + /* No folders at all... */ + return NULL; + } else if (first->n_next == NULL) { + /* We have only one node; any desired messages in it? */ + if (first->n_field == NULL) { + return NULL; + } else { + return first; + } + } else if (cur_node == NULL) { + /* Current folder is not listed in .folders, return first. */ + return first; + } + } else if (run_mode == UNSEEN) { + sequences_s = join_sequences(sequences); + } + + for (node = first, prev = NULL; + node != NULL; + prev = node, node = node->n_next) { + if (run_mode == FNEXT) { + /* If we have a previous node and it is the current + * folder, return this node. */ + if (prev != NULL && strcmp(prev->n_name, cur) == 0) { + return node; + } + } else if (run_mode == FPREV) { + if (strcmp(node->n_name, cur) == 0) { + /* Found current folder in fprev mode; if we have a + * previous node in the list, return it; else return + * the last node. */ + if (prev == NULL) { + return last; + } + return prev; + } + } else if (run_mode == UNSEEN) { + if (node->n_field == NULL) { + continue; + } + + printf("\n%d %s messages in %s", + count_messages(node->n_field), + sequences_s, + node->n_name); + if (strcmp(node->n_name, cur) == 0) { + puts(" (*: current folder)"); + } else { + puts(""); + } + fflush(stdout); + + /* TODO: Split enough of scan.c out so that we can call it here. */ + command = concat("scan +", node->n_name, " ", sequences_s, + (void *)NULL); + system(command); + free(command); + } else { + if (node->n_field == NULL) { + continue; + } + + count = count_messages(node->n_field); + total += count; + + printf("%-*s %6d.%c %s\n", + (int) folder_len, node->n_name, + count, + (strcmp(node->n_name, cur) == 0 ? '*' : ' '), + node->n_field); + } + } + + /* If we're fnext, we haven't checked the last node yet. If it's the + * current folder, return the first node. */ + if (run_mode == FNEXT && strcmp(last->n_name, cur) == 0) { return first; - } - } else if (cur_node == NULL) { - /* Current folder is not listed in .folders, return first. */ - return first; } - } else if (run_mode == UNSEEN) { - sequences_s = join_sequences(sequences); - } - - for (node = first, prev = NULL; - node != NULL; - prev = node, node = node->n_next) { - if (run_mode == FNEXT) { - /* If we have a previous node and it is the current - * folder, return this node. */ - if (prev != NULL && strcmp(prev->n_name, cur) == 0) { - return node; - } - } else if (run_mode == FPREV) { - if (strcmp(node->n_name, cur) == 0) { - /* Found current folder in fprev mode; if we have a - * previous node in the list, return it; else return - * the last node. */ - if (prev == NULL) { - return last; - } - return prev; - } - } else if (run_mode == UNSEEN) { - if (node->n_field == NULL) { - continue; - } - - printf("\n%d %s messages in %s", - count_messages(node->n_field), - sequences_s, - node->n_name); - if (strcmp(node->n_name, cur) == 0) { - puts(" (*: current folder)"); - } else { - puts(""); - } - fflush(stdout); - - /* TODO: Split enough of scan.c out so that we can call it here. */ - command = concat("scan +", node->n_name, " ", sequences_s, - (void *)NULL); - system(command); - free(command); - } else { - if (node->n_field == NULL) { - continue; - } - - count = count_messages(node->n_field); - total += count; - - printf("%-*s %6d.%c %s\n", - (int) folder_len, node->n_name, - count, - (strcmp(node->n_name, cur) == 0 ? '*' : ' '), - node->n_field); - } - } - - /* If we're fnext, we haven't checked the last node yet. If it's the - * current folder, return the first node. */ - if (run_mode == FNEXT && strcmp(last->n_name, cur) == 0) { - return first; - } - - if (run_mode == NEW) { - printf("%-*s %6d.\n", (int) folder_len, " total", total); - } - - return cur_node; + + if (run_mode == NEW) { + printf("%-*s %6d.\n", (int) folder_len, " total", total); + } + + return cur_node; } int main(int argc, char **argv) { - char **ap, *cp, **argp, **arguments; - char help[BUFSIZ]; - char *folders = NULL; - char *sequences[NUMATTRS + 1]; - int i = 0; - char *unseen; - struct node *folder; + char **ap, *cp, **argp, **arguments; + char help[BUFSIZ]; + char *folders = NULL; + char *sequences[NUMATTRS + 1]; + int i = 0; + char *unseen; + struct node *folder; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex(argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (help, sizeof(help), "%s [switches] [sequences]", - invo_name); - print_help (help, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FOLDERSSW: - if (!(folders = *argp++) || *folders == '-') - adios(NULL, "missing argument to %s", argp[-2]); - continue; - case MODESW: - if (!(invo_name = *argp++) || *invo_name == '-') - adios(NULL, "missing argument to %s", argp[-2]); - invo_name = r1bindex(invo_name, '/'); - continue; - } + invo_name = r1bindex(argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (help, sizeof(help), "%s [switches] [sequences]", + invo_name); + print_help (help, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FOLDERSSW: + if (!(folders = *argp++) || *folders == '-') + adios(NULL, "missing argument to %s", argp[-2]); + continue; + case MODESW: + if (!(invo_name = *argp++) || *invo_name == '-') + adios(NULL, "missing argument to %s", argp[-2]); + invo_name = r1bindex(invo_name, '/'); + continue; + } + } + /* have a sequence argument */ + if (!seq_in_list(cp, sequences)) { + sequences[i++] = cp; + } + } + + if (strcmp(invo_name, "fnext") == 0) { + run_mode = FNEXT; + } else if (strcmp(invo_name, "fprev") == 0) { + run_mode = FPREV; + } else if (strcmp(invo_name, "unseen") == 0) { + run_mode = UNSEEN; + } + + if (folders == NULL) { + /* will flists */ + } else { + if (folders[0] != '/') { + folders = m_maildir(folders); + } } - /* have a sequence argument */ - if (!seq_in_list(cp, sequences)) { - sequences[i++] = cp; + + if (i == 0) { + /* no sequence arguments; use unseen */ + unseen = context_find(usequence); + if (unseen == NULL || unseen[0] == '\0') { + adios(NULL, "must specify sequences or set %s", usequence); + } + for (ap = brkstring(unseen, " ", "\n"); *ap; ap++) { + sequences[i++] = *ap; + } } - } - - if (strcmp(invo_name, "fnext") == 0) { - run_mode = FNEXT; - } else if (strcmp(invo_name, "fprev") == 0) { - run_mode = FPREV; - } else if (strcmp(invo_name, "unseen") == 0) { - run_mode = UNSEEN; - } - - if (folders == NULL) { - /* will flists */ - } else { - if (folders[0] != '/') { - folders = m_maildir(folders); + sequences[i] = NULL; + + folder = doit(context_find(pfolder), folders, sequences); + if (folder == NULL) { + done(0); + return 1; } - } - if (i == 0) { - /* no sequence arguments; use unseen */ - unseen = context_find(usequence); - if (unseen == NULL || unseen[0] == '\0') { - adios(NULL, "must specify sequences or set %s", usequence); + if (run_mode == UNSEEN) { + /* All the scan(1)s it runs change the current folder, so we + * need to put it back. Unfortunately, context_replace lamely + * ignores the new value you give it if it is the same one it + * has in memory. So, we'll be lame, too. I'm not sure if i + * should just change context_replace... */ + context_replace(pfolder, "defeat_context_replace_optimization"); } - for (ap = brkstring(unseen, " ", "\n"); *ap; ap++) { - sequences[i++] = *ap; + + /* update current folder */ + context_replace(pfolder, folder->n_name); + + if (run_mode == FNEXT || run_mode == FPREV) { + printf("%s %s\n", folder->n_name, folder->n_field); } - } - sequences[i] = NULL; - - folder = doit(context_find(pfolder), folders, sequences); - if (folder == NULL) { - done(0); - return 1; - } - - if (run_mode == UNSEEN) { - /* All the scan(1)s it runs change the current folder, so we - * need to put it back. Unfortunately, context_replace lamely - * ignores the new value you give it if it is the same one it - * has in memory. So, we'll be lame, too. I'm not sure if i - * should just change context_replace... */ - context_replace(pfolder, "defeat_context_replace_optimization"); - } - - /* update current folder */ - context_replace(pfolder, folder->n_name); - - if (run_mode == FNEXT || run_mode == FPREV) { - printf("%s %s\n", folder->n_name, folder->n_field); - } - - context_save(); - - done (0); - return 1; + + context_save(); + + done (0); + return 1; } diff --git a/uip/packf.c b/uip/packf.c index c365440..cb7caf2 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -1,4 +1,3 @@ - /* * packf.c -- pack a nmh folder into a file * @@ -14,17 +13,17 @@ #include static struct swit switches[] = { -#define FILESW 0 - { "file name", 0 }, -#define MBOXSW 1 - { "mbox", 0 }, -#define MMDFSW 2 - { "mmdf", 0 }, -#define VERSIONSW 3 - { "version", 0 }, -#define HELPSW 4 - { "help", 0 }, - { NULL, 0 } +#define FILESW 0 + { "file name", 0 }, +#define MBOXSW 1 + { "mbox", 0 }, +#define MMDFSW 2 + { "mmdf", 0 }, +#define VERSIONSW 3 + { "version", 0 }, +#define HELPSW 4 + { "help", 0 }, + { NULL, 0 } }; static int md = NOTOK; @@ -39,151 +38,151 @@ char *file = NULL; int main (int argc, char **argv) { - int fd, msgnum; - char *cp, *maildir, *msgnam, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; - struct stat st; + int fd, msgnum; + char *cp, *maildir, *msgnam, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; + struct stat st; - done=mbxclose_done; + done=mbxclose_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FILESW: - if (file) - adios (NULL, "only one file at a time!"); - if (!(file = *argp++) || *file == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case MBOXSW: - mbx_style = MBOX_FORMAT; - mapping = 0; - continue; - case MMDFSW: - mbx_style = MMDF_FORMAT; - mapping = 1; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FILESW: + if (file) + adios (NULL, "only one file at a time!"); + if (!(file = *argp++) || *file == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case MBOXSW: + mbx_style = MBOX_FORMAT; + mapping = 0; + continue; + case MMDFSW: + mbx_style = MMDF_FORMAT; + mapping = 1; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!file) - file = "./msgbox"; - file = path (file, TFILE); - - /* - * Check if file to be created (or appended to) - * exists. If not, ask for confirmation. - */ - if (stat (file, &st) == NOTOK) { - if (errno != ENOENT) - adios (file, "error on file"); - cp = concat ("Create file \"", file, "\"? ", NULL); - if (!getanswer (cp)) - done (1); - free (cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* default is to pack whole folder */ - if (!msgs.size) - app_msgarg(&msgs, "all"); - - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to "); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - /* open and lock new maildrop file */ - if ((md = mbx_open(file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK) - adios (file, "unable to open"); - - /* copy all the SELECTED messages to the file */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected(mp, msgnum)) { - if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { - admonish (msgnam, "unable to read message"); - break; - } - - if (mbx_copy (file, mbx_style, md, fd, mapping, NULL, 1) == NOTOK) - adios (file, "error writing to file"); - - close (fd); + + if (!file) + file = "./msgbox"; + file = path (file, TFILE); + + /* + * Check if file to be created (or appended to) + * exists. If not, ask for confirmation. + */ + if (stat (file, &st) == NOTOK) { + if (errno != ENOENT) + adios (file, "error on file"); + cp = concat ("Create file \"", file, "\"? ", NULL); + if (!getanswer (cp)) + done (1); + free (cp); } - /* close and unlock maildrop file */ - mbx_close (file, md); - - context_replace (pfolder, folder); /* update current folder */ - if (mp->hghsel != mp->curmsg) - seq_setcur (mp, mp->lowsel); - seq_save (mp); - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + /* default is to pack whole folder */ + if (!msgs.size) + app_msgarg(&msgs, "all"); + + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to "); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + /* open and lock new maildrop file */ + if ((md = mbx_open(file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK) + adios (file, "unable to open"); + + /* copy all the SELECTED messages to the file */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected(mp, msgnum)) { + if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { + admonish (msgnam, "unable to read message"); + break; + } + + if (mbx_copy (file, mbx_style, md, fd, mapping, NULL, 1) == NOTOK) + adios (file, "error writing to file"); + + close (fd); + } + + /* close and unlock maildrop file */ + mbx_close (file, md); + + context_replace (pfolder, folder); /* update current folder */ + if (mp->hghsel != mp->curmsg) + seq_setcur (mp, mp->lowsel); + seq_save (mp); + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ + done (0); + return 1; } static void mbxclose_done (int status) { - mbx_close (file, md); - exit (status); + mbx_close (file, md); + exit (status); } diff --git a/uip/pick.c b/uip/pick.c index 24e6862..a4f61bd 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -1,4 +1,3 @@ - /* * pick.c -- search for messages by content * @@ -13,55 +12,55 @@ #include static struct swit switches[] = { -#define ANDSW 0 - { "and", 0 }, -#define ORSW 1 - { "or", 0 }, -#define NOTSW 2 - { "not", 0 }, -#define LBRSW 3 - { "lbrace", 0 }, -#define RBRSW 4 - { "rbrace", 0 }, -#define CCSW 5 - { "cc pattern", 0 }, -#define DATESW 6 - { "date pattern", 0 }, -#define FROMSW 7 - { "from pattern", 0 }, -#define SRCHSW 8 - { "search pattern", 0 }, -#define SUBJSW 9 - { "subject pattern", 0 }, -#define TOSW 10 - { "to pattern", 0 }, -#define OTHRSW 11 - { "-othercomponent pattern", 0 }, -#define AFTRSW 12 - { "after date", 0 }, -#define BEFRSW 13 - { "before date", 0 }, -#define DATFDSW 14 - { "datefield field", 5 }, -#define SEQSW 15 - { "sequence name", 0 }, -#define PUBLSW 16 - { "public", 0 }, -#define NPUBLSW 17 - { "nopublic", 0 }, -#define ZEROSW 18 - { "zero", 0 }, -#define NZEROSW 19 - { "nozero", 0 }, -#define LISTSW 20 - { "list", 0 }, -#define NLISTSW 21 - { "nolist", 0 }, -#define VERSIONSW 22 - { "version", 0 }, -#define HELPSW 23 - { "help", 0 }, - { NULL, 0 } +#define ANDSW 0 + { "and", 0 }, +#define ORSW 1 + { "or", 0 }, +#define NOTSW 2 + { "not", 0 }, +#define LBRSW 3 + { "lbrace", 0 }, +#define RBRSW 4 + { "rbrace", 0 }, +#define CCSW 5 + { "cc pattern", 0 }, +#define DATESW 6 + { "date pattern", 0 }, +#define FROMSW 7 + { "from pattern", 0 }, +#define SRCHSW 8 + { "search pattern", 0 }, +#define SUBJSW 9 + { "subject pattern", 0 }, +#define TOSW 10 + { "to pattern", 0 }, +#define OTHRSW 11 + { "-othercomponent pattern", 0 }, +#define AFTRSW 12 + { "after date", 0 }, +#define BEFRSW 13 + { "before date", 0 }, +#define DATFDSW 14 + { "datefield field", 5 }, +#define SEQSW 15 + { "sequence name", 0 }, +#define PUBLSW 16 + { "public", 0 }, +#define NPUBLSW 17 + { "nopublic", 0 }, +#define ZEROSW 18 + { "zero", 0 }, +#define NZEROSW 19 + { "nozero", 0 }, +#define LISTSW 20 + { "list", 0 }, +#define NLISTSW 21 + { "nolist", 0 }, +#define VERSIONSW 22 + { "version", 0 }, +#define HELPSW 23 + { "help", 0 }, + { NULL, 0 } }; static int listsw = -1; @@ -71,236 +70,236 @@ static void putzero_done (int) NORETURN; int main (int argc, char **argv) { - int publicsw = -1, zerosw = 1, seqp = 0, vecp = 0; - int lo, hi, msgnum; - char *maildir, *folder = NULL, buf[100]; - char *cp, **argp, **arguments; - char *seqs[NUMATTRS + 1], *vec[MAXARGS]; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; - register FILE *fp; + int publicsw = -1, zerosw = 1, seqp = 0, vecp = 0; + int lo, hi, msgnum; + char *maildir, *folder = NULL, buf[100]; + char *cp, **argp, **arguments; + char *seqs[NUMATTRS + 1], *vec[MAXARGS]; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; + register FILE *fp; - done=putzero_done; + done=putzero_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - if (*++cp == '-') { - vec[vecp++] = --cp; - goto pattern; - } - switch (smatch (cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - listsw = 0; /* HACK */ - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - listsw = 0; /* HACK */ - done (1); - case VERSIONSW: - print_version(invo_name); - listsw = 0; /* HACK */ + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + if (*++cp == '-') { + vec[vecp++] = --cp; + goto pattern; + } + switch (smatch (cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + listsw = 0; /* HACK */ + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + listsw = 0; /* HACK */ + done (1); + case VERSIONSW: + print_version(invo_name); + listsw = 0; /* HACK */ + done (1); + + case CCSW: + case DATESW: + case FROMSW: + case SUBJSW: + case TOSW: + case DATFDSW: + case AFTRSW: + case BEFRSW: + case SRCHSW: + vec[vecp++] = --cp; + pattern: + if (!(cp = *argp++))/* allow -xyz arguments */ + adios (NULL, "missing argument to %s", argp[-2]); + vec[vecp++] = cp; + continue; + case OTHRSW: + adios (NULL, "internal error!"); + + case ANDSW: + case ORSW: + case NOTSW: + case LBRSW: + case RBRSW: + vec[vecp++] = --cp; + continue; + + case SEQSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + + /* check if too many sequences specified */ + if (seqp >= NUMATTRS) + adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + + if (!seq_nameok (cp)) + done (1); + + seqs[seqp++] = cp; + continue; + case PUBLSW: + publicsw = 1; + continue; + case NPUBLSW: + publicsw = 0; + continue; + case ZEROSW: + zerosw++; + continue; + case NZEROSW: + zerosw = 0; + continue; + + case LISTSW: + listsw = 1; + continue; + case NLISTSW: + listsw = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); + } + vec[vecp] = NULL; + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + /* + * If we didn't specify which messages to search, + * then search the whole folder. + */ + if (!msgs.size) + app_msgarg(&msgs, "all"); + + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + /* + * If we aren't saving the results to a sequence, + * we default to list the results. + */ + if (listsw == -1) + listsw = !seqp; + + if (publicsw == 1 && is_readonly(mp)) + adios (NULL, "folder %s is read-only, so -public not allowed", folder); + + if (!pcompile (vec, NULL)) done (1); - case CCSW: - case DATESW: - case FROMSW: - case SUBJSW: - case TOSW: - case DATFDSW: - case AFTRSW: - case BEFRSW: - case SRCHSW: - vec[vecp++] = --cp; - pattern: - if (!(cp = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; - continue; - case OTHRSW: - adios (NULL, "internal error!"); - - case ANDSW: - case ORSW: - case NOTSW: - case LBRSW: - case RBRSW: - vec[vecp++] = --cp; - continue; - - case SEQSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - - /* check if too many sequences specified */ - if (seqp >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); - - if (!seq_nameok (cp)) - done (1); - - seqs[seqp++] = cp; - continue; - case PUBLSW: - publicsw = 1; - continue; - case NPUBLSW: - publicsw = 0; - continue; - case ZEROSW: - zerosw++; - continue; - case NZEROSW: - zerosw = 0; - continue; - - case LISTSW: - listsw = 1; - continue; - case NLISTSW: - listsw = 0; - continue; - } + lo = mp->lowsel; + hi = mp->hghsel; + + /* If printing message numbers to standard out, force line buffering on. + */ + if (listsw) + setvbuf (stdout, NULL, _IOLBF, 0); + + /* + * Scan through all the SELECTED messages and check for a + * match. If the message does not match, then unselect it. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL) + admonish (cp, "unable to read message"); + if (fp && pmatches (fp, msgnum, 0L, 0L)) { + if (msgnum < lo) + lo = msgnum; + if (msgnum > hi) + hi = msgnum; + + if (listsw) + printf ("%s\n", m_name (msgnum)); + } else { + /* if it doesn't match, then unselect it */ + unset_selected (mp, msgnum); + mp->numsel--; + } + if (fp) + fclose (fp); + } } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - vec[vecp] = NULL; - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* - * If we didn't specify which messages to search, - * then search the whole folder. - */ - if (!msgs.size) - app_msgarg(&msgs, "all"); - - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - /* - * If we aren't saving the results to a sequence, - * we default to list the results. - */ - if (listsw == -1) - listsw = !seqp; - - if (publicsw == 1 && is_readonly(mp)) - adios (NULL, "folder %s is read-only, so -public not allowed", folder); - - if (!pcompile (vec, NULL)) - done (1); - - lo = mp->lowsel; - hi = mp->hghsel; - - /* If printing message numbers to standard out, force line buffering on. - */ - if (listsw) - setvbuf (stdout, NULL, _IOLBF, 0); - - /* - * Scan through all the SELECTED messages and check for a - * match. If the message does not match, then unselect it. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL) - admonish (cp, "unable to read message"); - if (fp && pmatches (fp, msgnum, 0L, 0L)) { - if (msgnum < lo) - lo = msgnum; - if (msgnum > hi) - hi = msgnum; - - if (listsw) - printf ("%s\n", m_name (msgnum)); - } else { - /* if it doesn't match, then unselect it */ - unset_selected (mp, msgnum); - mp->numsel--; - } - if (fp) - fclose (fp); + + mp->lowsel = lo; + mp->hghsel = hi; + + if (mp->numsel <= 0) + adios (NULL, "no messages match specification"); + + seqs[seqp] = NULL; + + /* + * Add the matching messages to sequences + */ + for (seqp = 0; seqs[seqp]; seqp++) + if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw)) + done (1); + + /* + * Print total matched if not printing each matched message number. + */ + if (!listsw) { + printf ("%d hit%s\n", mp->numsel, mp->numsel == 1 ? "" : "s"); } - } - - mp->lowsel = lo; - mp->hghsel = hi; - - if (mp->numsel <= 0) - adios (NULL, "no messages match specification"); - - seqs[seqp] = NULL; - - /* - * Add the matching messages to sequences - */ - for (seqp = 0; seqs[seqp]; seqp++) - if (!seq_addsel (mp, seqs[seqp], publicsw, zerosw)) - done (1); - - /* - * Print total matched if not printing each matched message number. - */ - if (!listsw) { - printf ("%d hit%s\n", mp->numsel, mp->numsel == 1 ? "" : "s"); - } - - context_replace (pfolder, folder); /* update current folder */ - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + + context_replace (pfolder, folder); /* update current folder */ + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ + done (0); + return 1; } static void putzero_done (int status) { - if (listsw && status && !isatty (fileno (stdout))) - printf ("0\n"); - exit (status); + if (listsw && status && !isatty (fileno (stdout))) + printf ("0\n"); + exit (status); } diff --git a/uip/picksbr.c b/uip/picksbr.c index bd4c263..fd29c4c 100644 --- a/uip/picksbr.c +++ b/uip/picksbr.c @@ -1,4 +1,3 @@ - /* * picksbr.c -- routines to help pick along... * @@ -24,37 +23,37 @@ #endif static struct swit parswit[] = { -#define PRAND 0 - { "and", 0 }, -#define PROR 1 - { "or", 0 }, -#define PRNOT 2 - { "not", 0 }, -#define PRLBR 3 - { "lbrace", 0 }, -#define PRRBR 4 - { "rbrace", 0 }, -#define PRCC 5 - { "cc pattern", 0 }, -#define PRDATE 6 - { "date pattern", 0 }, -#define PRFROM 7 - { "from pattern", 0 }, -#define PRSRCH 8 - { "search pattern", 0 }, -#define PRSUBJ 9 - { "subject pattern", 0 }, -#define PRTO 10 - { "to pattern", 0 }, -#define PROTHR 11 - { "-othercomponent pattern", 15 }, -#define PRAFTR 12 - { "after date", 0 }, -#define PRBEFR 13 - { "before date", 0 }, -#define PRDATF 14 - { "datefield field", 5 }, - { NULL, 0 } +#define PRAND 0 + { "and", 0 }, +#define PROR 1 + { "or", 0 }, +#define PRNOT 2 + { "not", 0 }, +#define PRLBR 3 + { "lbrace", 0 }, +#define PRRBR 4 + { "rbrace", 0 }, +#define PRCC 5 + { "cc pattern", 0 }, +#define PRDATE 6 + { "date pattern", 0 }, +#define PRFROM 7 + { "from pattern", 0 }, +#define PRSRCH 8 + { "search pattern", 0 }, +#define PRSUBJ 9 + { "subject pattern", 0 }, +#define PRTO 10 + { "to pattern", 0 }, +#define PROTHR 11 + { "-othercomponent pattern", 15 }, +#define PRAFTR 12 + { "after date", 0 }, +#define PRBEFR 13 + { "before date", 0 }, +#define PRDATF 14 + { "datefield field", 5 }, + { NULL, 0 } }; /* DEFINITIONS FOR PATTERN MATCHING */ @@ -70,17 +69,17 @@ static struct swit parswit[] = { * routines (no \(xxx\) and \n constructs). Such is life. */ -#define CCHR 2 -#define CDOT 4 -#define CCL 6 -#define NCCL 8 -#define CDOL 10 -#define CEOF 11 +#define CCHR 2 +#define CDOT 4 +#define CCL 6 +#define NCCL 8 +#define CDOL 10 +#define CEOF 11 -#define STAR 01 +#define STAR 01 #define LBSIZE 1024 -#define ESIZE 1024 +#define ESIZE 1024 static char linebuf[LBSIZE + 1]; @@ -126,49 +125,49 @@ static char cc[] = { * DEFINITIONS FOR NEXUS */ -#define nxtarg() (*argp ? *argp++ : NULL) -#define prvarg() argp-- +#define nxtarg() (*argp ? *argp++ : NULL) +#define prvarg() argp-- -#define padvise if (!talked++) advise +#define padvise if (!talked++) advise struct nexus { - int (*n_action)(); - - union { - /* for {OR,AND,NOT}action */ - struct { - struct nexus *un_L_child; - struct nexus *un_R_child; - } st1; - - /* for GREPaction */ - struct { - int un_header; - int un_circf; - char un_expbuf[ESIZE]; - char *un_patbuf; - } st2; - - /* for TWSaction */ - struct { - char *un_datef; - int un_after; - struct tws un_tws; - } st3; - } un; + int (*n_action)(); + + union { + /* for {OR,AND,NOT}action */ + struct { + struct nexus *un_L_child; + struct nexus *un_R_child; + } st1; + + /* for GREPaction */ + struct { + int un_header; + int un_circf; + char un_expbuf[ESIZE]; + char *un_patbuf; + } st2; + + /* for TWSaction */ + struct { + char *un_datef; + int un_after; + struct tws un_tws; + } st3; + } un; }; -#define n_L_child un.st1.un_L_child -#define n_R_child un.st1.un_R_child +#define n_L_child un.st1.un_L_child +#define n_R_child un.st1.un_R_child -#define n_header un.st2.un_header -#define n_circf un.st2.un_circf -#define n_expbuf un.st2.un_expbuf -#define n_patbuf un.st2.un_patbuf +#define n_header un.st2.un_header +#define n_circf un.st2.un_circf +#define n_expbuf un.st2.un_expbuf +#define n_patbuf un.st2.un_patbuf -#define n_datef un.st3.un_datef -#define n_after un.st3.un_after -#define n_tws un.st3.un_tws +#define n_datef un.st3.un_datef +#define n_after un.st3.un_after +#define n_tws un.st3.un_tws static int talked; static int pdebug = 0; @@ -209,335 +208,335 @@ static int TWSaction(); int pcompile (char **vec, char *date) { - register char *cp; + register char *cp; - if ((cp = getenv ("MHPDEBUG")) && *cp) - pdebug++; + if ((cp = getenv ("MHPDEBUG")) && *cp) + pdebug++; - argp = vec; - if ((datesw = date) == NULL) - datesw = "date"; - talked = 0; + argp = vec; + if ((datesw = date) == NULL) + datesw = "date"; + talked = 0; - if ((head = parse ()) == NULL) - return (talked ? 0 : 1); + if ((head = parse ()) == NULL) + return (talked ? 0 : 1); - if (*argp) { - padvise (NULL, "%s unexpected", *argp); - return 0; - } + if (*argp) { + padvise (NULL, "%s unexpected", *argp); + return 0; + } - return 1; + return 1; } static struct nexus * parse (void) { - register char *cp; - register struct nexus *n, *o; + register char *cp; + register struct nexus *n, *o; - if ((n = nexp1 ()) == NULL || (cp = nxtarg ()) == NULL) - return n; + if ((n = nexp1 ()) == NULL || (cp = nxtarg ()) == NULL) + return n; - if (*cp != '-') { - padvise (NULL, "%s unexpected", cp); - return NULL; - } - - if (*++cp == '-') - goto header; - switch (smatch (cp, parswit)) { - case AMBIGSW: - ambigsw (cp, parswit); - talked++; - return NULL; - case UNKWNSW: - fprintf (stderr, "-%s unknown\n", cp); - talked++; - return NULL; - - case PROR: - o = newnexus (ORaction); - o->n_L_child = n; - if ((o->n_R_child = parse ())) - return o; - padvise (NULL, "missing disjunctive"); - return NULL; + if (*cp != '-') { + padvise (NULL, "%s unexpected", cp); + return NULL; + } + + if (*++cp == '-') + goto header; + switch (smatch (cp, parswit)) { + case AMBIGSW: + ambigsw (cp, parswit); + talked++; + return NULL; + case UNKWNSW: + fprintf (stderr, "-%s unknown\n", cp); + talked++; + return NULL; + + case PROR: + o = newnexus (ORaction); + o->n_L_child = n; + if ((o->n_R_child = parse ())) + return o; + padvise (NULL, "missing disjunctive"); + return NULL; header: ; - default: - prvarg (); - return n; - } + default: + prvarg (); + return n; + } } static struct nexus * nexp1 (void) { - register char *cp; - register struct nexus *n, *o; + register char *cp; + register struct nexus *n, *o; + + if ((n = nexp2 ()) == NULL || (cp = nxtarg ()) == NULL) + return n; - if ((n = nexp2 ()) == NULL || (cp = nxtarg ()) == NULL) - return n; + if (*cp != '-') { + padvise (NULL, "%s unexpected", cp); + return NULL; + } - if (*cp != '-') { - padvise (NULL, "%s unexpected", cp); - return NULL; - } - - if (*++cp == '-') - goto header; - switch (smatch (cp, parswit)) { - case AMBIGSW: - ambigsw (cp, parswit); - talked++; - return NULL; - case UNKWNSW: - fprintf (stderr, "-%s unknown\n", cp); - talked++; - return NULL; - - case PRAND: - o = newnexus (ANDaction); - o->n_L_child = n; - if ((o->n_R_child = nexp1 ())) - return o; - padvise (NULL, "missing conjunctive"); - return NULL; + if (*++cp == '-') + goto header; + switch (smatch (cp, parswit)) { + case AMBIGSW: + ambigsw (cp, parswit); + talked++; + return NULL; + case UNKWNSW: + fprintf (stderr, "-%s unknown\n", cp); + talked++; + return NULL; + + case PRAND: + o = newnexus (ANDaction); + o->n_L_child = n; + if ((o->n_R_child = nexp1 ())) + return o; + padvise (NULL, "missing conjunctive"); + return NULL; header: ; - default: - prvarg (); - return n; - } + default: + prvarg (); + return n; + } } static struct nexus * nexp2 (void) { - register char *cp; - register struct nexus *n; + register char *cp; + register struct nexus *n; - if ((cp = nxtarg ()) == NULL) - return NULL; + if ((cp = nxtarg ()) == NULL) + return NULL; - if (*cp != '-') { - prvarg (); - return nexp3 (); - } - - if (*++cp == '-') - goto header; - switch (smatch (cp, parswit)) { - case AMBIGSW: - ambigsw (cp, parswit); - talked++; - return NULL; - case UNKWNSW: - fprintf (stderr, "-%s unknown\n", cp); - talked++; - return NULL; - - case PRNOT: - n = newnexus (NOTaction); - if ((n->n_L_child = nexp3 ())) - return n; - padvise (NULL, "missing negation"); - return NULL; + if (*cp != '-') { + prvarg (); + return nexp3 (); + } + + if (*++cp == '-') + goto header; + switch (smatch (cp, parswit)) { + case AMBIGSW: + ambigsw (cp, parswit); + talked++; + return NULL; + case UNKWNSW: + fprintf (stderr, "-%s unknown\n", cp); + talked++; + return NULL; + + case PRNOT: + n = newnexus (NOTaction); + if ((n->n_L_child = nexp3 ())) + return n; + padvise (NULL, "missing negation"); + return NULL; header: ; - default: - prvarg (); - return nexp3 (); - } + default: + prvarg (); + return nexp3 (); + } } static struct nexus * nexp3 (void) { - int i; - register char *cp, *dp; - char buffer[BUFSIZ], temp[64]; - register struct nexus *n; + int i; + register char *cp, *dp; + char buffer[BUFSIZ], temp[64]; + register struct nexus *n; - if ((cp = nxtarg ()) == NULL) - return NULL; - - if (*cp != '-') { - padvise (NULL, "%s unexpected", cp); - return NULL; - } - - if (*++cp == '-') { - dp = ++cp; - goto header; - } - switch (i = smatch (cp, parswit)) { - case AMBIGSW: - ambigsw (cp, parswit); - talked++; - return NULL; - case UNKWNSW: - fprintf (stderr, "-%s unknown\n", cp); - talked++; - return NULL; - - case PRLBR: - if ((n = parse ()) == NULL) { - padvise (NULL, "missing group"); + if ((cp = nxtarg ()) == NULL) return NULL; - } - if ((cp = nxtarg ()) == NULL) { - padvise (NULL, "missing -rbrace"); - return NULL; - } - if (*cp++ == '-' && smatch (cp, parswit) == PRRBR) - return n; - padvise (NULL, "%s unexpected", --cp); - return NULL; - - default: - prvarg (); - return NULL; - - case PRCC: - case PRDATE: - case PRFROM: - case PRTO: - case PRSUBJ: - strncpy(temp, parswit[i].sw, sizeof(temp)); - temp[sizeof(temp) - 1] = '\0'; - dp = *brkstring (temp, " ", NULL); - header: ; - if (!(cp = nxtarg ())) {/* allow -xyz arguments */ - padvise (NULL, "missing argument to %s", argp[-2]); - return NULL; - } - n = newnexus (GREPaction); - n->n_header = 1; - snprintf (buffer, sizeof(buffer), "^%s[ \t]*:.*%s", dp, cp); - dp = buffer; - goto pattern; - - case PRSRCH: - n = newnexus (GREPaction); - n->n_header = 0; - if (!(cp = nxtarg ())) {/* allow -xyz arguments */ - padvise (NULL, "missing argument to %s", argp[-2]); - return NULL; - } - dp = cp; - pattern: ; - if (!gcompile (n, dp)) { - padvise (NULL, "pattern error in %s %s", argp[-2], cp); + + if (*cp != '-') { + padvise (NULL, "%s unexpected", cp); return NULL; - } - n->n_patbuf = getcpy (dp); - return n; + } - case PROTHR: - padvise (NULL, "internal error!"); - return NULL; + if (*++cp == '-') { + dp = ++cp; + goto header; + } + switch (i = smatch (cp, parswit)) { + case AMBIGSW: + ambigsw (cp, parswit); + talked++; + return NULL; + case UNKWNSW: + fprintf (stderr, "-%s unknown\n", cp); + talked++; + return NULL; + + case PRLBR: + if ((n = parse ()) == NULL) { + padvise (NULL, "missing group"); + return NULL; + } + if ((cp = nxtarg ()) == NULL) { + padvise (NULL, "missing -rbrace"); + return NULL; + } + if (*cp++ == '-' && smatch (cp, parswit) == PRRBR) + return n; + padvise (NULL, "%s unexpected", --cp); + return NULL; + + default: + prvarg (); + return NULL; + + case PRCC: + case PRDATE: + case PRFROM: + case PRTO: + case PRSUBJ: + strncpy(temp, parswit[i].sw, sizeof(temp)); + temp[sizeof(temp) - 1] = '\0'; + dp = *brkstring (temp, " ", NULL); + header: ; + if (!(cp = nxtarg ())) {/* allow -xyz arguments */ + padvise (NULL, "missing argument to %s", argp[-2]); + return NULL; + } + n = newnexus (GREPaction); + n->n_header = 1; + snprintf (buffer, sizeof(buffer), "^%s[ \t]*:.*%s", dp, cp); + dp = buffer; + goto pattern; + + case PRSRCH: + n = newnexus (GREPaction); + n->n_header = 0; + if (!(cp = nxtarg ())) {/* allow -xyz arguments */ + padvise (NULL, "missing argument to %s", argp[-2]); + return NULL; + } + dp = cp; + pattern: ; + if (!gcompile (n, dp)) { + padvise (NULL, "pattern error in %s %s", argp[-2], cp); + return NULL; + } + n->n_patbuf = getcpy (dp); + return n; - case PRDATF: - if (!(datesw = nxtarg ()) || *datesw == '-') { - padvise (NULL, "missing argument to %s", argp[-2]); - return NULL; - } - return nexp3 (); + case PROTHR: + padvise (NULL, "internal error!"); + return NULL; - case PRAFTR: - case PRBEFR: - if (!(cp = nxtarg ())) {/* allow -xyz arguments */ - padvise (NULL, "missing argument to %s", argp[-2]); - return NULL; - } - n = newnexus (TWSaction); - n->n_datef = datesw; - if (!tcompile (cp, &n->n_tws, n->n_after = i == PRAFTR)) { - padvise (NULL, "unable to parse %s %s", argp[-2], cp); - return NULL; - } - return n; - } + case PRDATF: + if (!(datesw = nxtarg ()) || *datesw == '-') { + padvise (NULL, "missing argument to %s", argp[-2]); + return NULL; + } + return nexp3 (); + + case PRAFTR: + case PRBEFR: + if (!(cp = nxtarg ())) {/* allow -xyz arguments */ + padvise (NULL, "missing argument to %s", argp[-2]); + return NULL; + } + n = newnexus (TWSaction); + n->n_datef = datesw; + if (!tcompile (cp, &n->n_tws, n->n_after = i == PRAFTR)) { + padvise (NULL, "unable to parse %s %s", argp[-2], cp); + return NULL; + } + return n; + } } static struct nexus * newnexus (int (*action)()) { - register struct nexus *p; + register struct nexus *p; - if ((p = (struct nexus *) calloc ((size_t) 1, sizeof *p)) == NULL) - adios (NULL, "unable to allocate component storage"); + if ((p = (struct nexus *) calloc ((size_t) 1, sizeof *p)) == NULL) + adios (NULL, "unable to allocate component storage"); - p->n_action = action; - return p; + p->n_action = action; + return p; } -#define args(a) a, fp, msgnum, start, stop -#define params args (n) -#define plist \ - register struct nexus *n; \ - register FILE *fp; \ - int msgnum; \ - long start, \ - stop; +#define args(a) a, fp, msgnum, start, stop +#define params args (n) +#define plist \ + register struct nexus *n; \ + register FILE *fp; \ + int msgnum; \ + long start, \ + stop; int pmatches (FILE *fp, int msgnum, long start, long stop) { - if (!head) - return 1; + if (!head) + return 1; - if (!talked++ && pdebug) - PRaction (head, 0); + if (!talked++ && pdebug) + PRaction (head, 0); - return (*head->n_action) (args (head)); + return (*head->n_action) (args (head)); } static void PRaction (struct nexus *n, int level) { - register int i; - - for (i = 0; i < level; i++) - fprintf (stderr, "| "); - - if (n->n_action == ORaction) { - fprintf (stderr, "OR\n"); - PRaction (n->n_L_child, level + 1); - PRaction (n->n_R_child, level + 1); - return; - } - if (n->n_action == ANDaction) { - fprintf (stderr, "AND\n"); - PRaction (n->n_L_child, level + 1); - PRaction (n->n_R_child, level + 1); - return; - } - if (n->n_action == NOTaction) { - fprintf (stderr, "NOT\n"); - PRaction (n->n_L_child, level + 1); - return; - } - if (n->n_action == GREPaction) { - fprintf (stderr, "PATTERN(%s) %s\n", - n->n_header ? "header" : "body", n->n_patbuf); - return; - } - if (n->n_action == TWSaction) { - fprintf (stderr, "TEMPORAL(%s) %s: %s\n", - n->n_after ? "after" : "before", n->n_datef, - dasctime (&n->n_tws, TW_NULL)); - return; - } - fprintf (stderr, "UNKNOWN(0x%x)\n", - (unsigned int)(unsigned long) (*n->n_action)); + register int i; + + for (i = 0; i < level; i++) + fprintf (stderr, "| "); + + if (n->n_action == ORaction) { + fprintf (stderr, "OR\n"); + PRaction (n->n_L_child, level + 1); + PRaction (n->n_R_child, level + 1); + return; + } + if (n->n_action == ANDaction) { + fprintf (stderr, "AND\n"); + PRaction (n->n_L_child, level + 1); + PRaction (n->n_R_child, level + 1); + return; + } + if (n->n_action == NOTaction) { + fprintf (stderr, "NOT\n"); + PRaction (n->n_L_child, level + 1); + return; + } + if (n->n_action == GREPaction) { + fprintf (stderr, "PATTERN(%s) %s\n", + n->n_header ? "header" : "body", n->n_patbuf); + return; + } + if (n->n_action == TWSaction) { + fprintf (stderr, "TEMPORAL(%s) %s: %s\n", + n->n_after ? "after" : "before", n->n_datef, + dasctime (&n->n_tws, TW_NULL)); + return; + } + fprintf (stderr, "UNKNOWN(0x%x)\n", + (unsigned int)(unsigned long) (*n->n_action)); } @@ -545,9 +544,9 @@ static int ORaction (params) plist { - if ((*n->n_L_child->n_action) (args (n->n_L_child))) - return 1; - return (*n->n_R_child->n_action) (args (n->n_R_child)); + if ((*n->n_L_child->n_action) (args (n->n_L_child))) + return 1; + return (*n->n_R_child->n_action) (args (n->n_R_child)); } @@ -555,9 +554,9 @@ static int ANDaction (params) plist { - if (!(*n->n_L_child->n_action) (args (n->n_L_child))) - return 0; - return (*n->n_R_child->n_action) (args (n->n_R_child)); + if (!(*n->n_L_child->n_action) (args (n->n_L_child))) + return 0; + return (*n->n_R_child->n_action) (args (n->n_R_child)); } @@ -565,96 +564,96 @@ static int NOTaction (params) plist { - return (!(*n->n_L_child->n_action) (args (n->n_L_child))); + return (!(*n->n_L_child->n_action) (args (n->n_L_child))); } static int gcompile (struct nexus *n, char *astr) { - register int c; - int cclcnt; - register unsigned char *ep, *dp, *sp, *lastep = 0; - - dp = (ep = n->n_expbuf) + sizeof n->n_expbuf; - sp = astr; - if (*sp == '^') { - n->n_circf = 1; - sp++; - } - else - n->n_circf = 0; - for (;;) { - if (ep >= dp) - goto cerror; - if ((c = *sp++) != '*') - lastep = ep; - switch (c) { - case '\0': - *ep++ = CEOF; - return 1; - - case '.': - *ep++ = CDOT; - continue; - - case '*': - if (lastep == 0) - goto defchar; - *lastep |= STAR; - continue; - - case '$': - if (*sp != '\0') - goto defchar; - *ep++ = CDOL; - continue; - - case '[': - *ep++ = CCL; - *ep++ = 0; - cclcnt = 0; - if ((c = *sp++) == '^') { - c = *sp++; - ep[-2] = NCCL; - } - if (c == '-') { - *ep++ = c; - cclcnt++; - c = *sp++; + register int c; + int cclcnt; + register unsigned char *ep, *dp, *sp, *lastep = 0; + + dp = (ep = n->n_expbuf) + sizeof n->n_expbuf; + sp = astr; + if (*sp == '^') { + n->n_circf = 1; + sp++; + } + else + n->n_circf = 0; + for (;;) { + if (ep >= dp) + goto cerror; + if ((c = *sp++) != '*') + lastep = ep; + switch (c) { + case '\0': + *ep++ = CEOF; + return 1; + + case '.': + *ep++ = CDOT; + continue; + + case '*': + if (lastep == 0) + goto defchar; + *lastep |= STAR; + continue; + + case '$': + if (*sp != '\0') + goto defchar; + *ep++ = CDOL; + continue; + + case '[': + *ep++ = CCL; + *ep++ = 0; + cclcnt = 0; + if ((c = *sp++) == '^') { + c = *sp++; + ep[-2] = NCCL; + } + if (c == '-') { + *ep++ = c; + cclcnt++; + c = *sp++; + } + do { + if (c == '-' && *sp != '\0' && *sp != ']') { + for (c = ep[-1]+1; c < *sp; c++) { + *ep++ = c; + cclcnt++; + if (c == '\0' || ep >= dp) + goto cerror; + } + } else { + *ep++ = c; + cclcnt++; + if (c == '\0' || ep >= dp) + goto cerror; + } + } while ((c = *sp++) != ']'); + if (cclcnt > 255) + goto cerror; + lastep[1] = cclcnt; + continue; + + case '\\': + if ((c = *sp++) == '\0') + goto cerror; + defchar: + default: + *ep++ = CCHR; + *ep++ = c; } - do { - if (c == '-' && *sp != '\0' && *sp != ']') { - for (c = ep[-1]+1; c < *sp; c++) { - *ep++ = c; - cclcnt++; - if (c == '\0' || ep >= dp) - goto cerror; - } - } else { - *ep++ = c; - cclcnt++; - if (c == '\0' || ep >= dp) - goto cerror; - } - } while ((c = *sp++) != ']'); - if (cclcnt > 255) - goto cerror; - lastep[1] = cclcnt; - continue; - - case '\\': - if ((c = *sp++) == '\0') - goto cerror; - defchar: - default: - *ep++ = CCHR; - *ep++ = c; } - } cerror: ; - return 0; + return 0; } @@ -662,272 +661,272 @@ static int GREPaction (params) plist { - int c, body, lf; - long pos = start; - register char *p1, *p2, *ebp, *cbp; - char ibuf[BUFSIZ]; - - fseek (fp, start, SEEK_SET); - body = 0; - ebp = cbp = ibuf; - for (;;) { - if (body && n->n_header) - return 0; - p1 = linebuf; - p2 = cbp; - lf = 0; + int c, body, lf; + long pos = start; + register char *p1, *p2, *ebp, *cbp; + char ibuf[BUFSIZ]; + + fseek (fp, start, SEEK_SET); + body = 0; + ebp = cbp = ibuf; for (;;) { - if (p2 >= ebp) { - if (fgets (ibuf, sizeof ibuf, fp) == NULL - || (stop && pos >= stop)) { - if (lf) - break; - return 0; - } - pos += (long) strlen (ibuf); - p2 = ibuf; - ebp = ibuf + strlen (ibuf); - } - c = *p2++; - if (lf && c != '\n') { - if (c != ' ' && c != '\t') { - --p2; - break; - } - else - lf = 0; - } - if (c == '\n') { - if (body) - break; - else { - if (lf) { - body++; - break; - } - lf++; - c = ' '; + if (body && n->n_header) + return 0; + p1 = linebuf; + p2 = cbp; + lf = 0; + for (;;) { + if (p2 >= ebp) { + if (fgets (ibuf, sizeof ibuf, fp) == NULL + || (stop && pos >= stop)) { + if (lf) + break; + return 0; + } + pos += (long) strlen (ibuf); + p2 = ibuf; + ebp = ibuf + strlen (ibuf); + } + c = *p2++; + if (lf && c != '\n') { + if (c != ' ' && c != '\t') { + --p2; + break; + } + else + lf = 0; + } + if (c == '\n') { + if (body) + break; + else { + if (lf) { + body++; + break; + } + lf++; + c = ' '; + } + } + if (c && p1 < &linebuf[LBSIZE - 1]) + *p1++ = c; } - } - if (c && p1 < &linebuf[LBSIZE - 1]) - *p1++ = c; - } - *p1++ = 0; - cbp = p2; - p1 = linebuf; - p2 = n->n_expbuf; + *p1++ = 0; + cbp = p2; + p1 = linebuf; + p2 = n->n_expbuf; - if (n->n_circf) { - if (advance (p1, p2)) - return 1; - continue; - } + if (n->n_circf) { + if (advance (p1, p2)) + return 1; + continue; + } - if (*p2 == CCHR) { - c = p2[1]; - do { - if (*p1 == c || cc[(unsigned char)*p1] == c) - if (advance (p1, p2)) - return 1; - } while (*p1++); - continue; - } + if (*p2 == CCHR) { + c = p2[1]; + do { + if (*p1 == c || cc[(unsigned char)*p1] == c) + if (advance (p1, p2)) + return 1; + } while (*p1++); + continue; + } - do { - if (advance (p1, p2)) - return 1; - } while (*p1++); - } + do { + if (advance (p1, p2)) + return 1; + } while (*p1++); + } } static int advance (char *alp, char *aep) { - register unsigned char *lp, *ep, *curlp; - - lp = (unsigned char *)alp; - ep = (unsigned char *)aep; - for (;;) - switch (*ep++) { - case CCHR: - if (*ep++ == *lp++ || ep[-1] == cc[lp[-1]]) - continue; - return 0; - - case CDOT: - if (*lp++) - continue; - return 0; - - case CDOL: - if (*lp == 0) - continue; - return 0; - - case CEOF: - return 1; - - case CCL: - if (cclass (ep, *lp++, 1)) { - ep += *ep + 1; - continue; + register unsigned char *lp, *ep, *curlp; + + lp = (unsigned char *)alp; + ep = (unsigned char *)aep; + for (;;) + switch (*ep++) { + case CCHR: + if (*ep++ == *lp++ || ep[-1] == cc[lp[-1]]) + continue; + return 0; + + case CDOT: + if (*lp++) + continue; + return 0; + + case CDOL: + if (*lp == 0) + continue; + return 0; + + case CEOF: + return 1; + + case CCL: + if (cclass (ep, *lp++, 1)) { + ep += *ep + 1; + continue; + } + return 0; + + case NCCL: + if (cclass (ep, *lp++, 0)) { + ep += *ep + 1; + continue; + } + return 0; + + case CDOT | STAR: + curlp = lp; + while (*lp++) + continue; + goto star; + + case CCHR | STAR: + curlp = lp; + while (*lp++ == *ep || cc[lp[-1]] == *ep) + continue; + ep++; + goto star; + + case CCL | STAR: + case NCCL | STAR: + curlp = lp; + while (cclass (ep, *lp++, ep[-1] == (CCL | STAR))) + continue; + ep += *ep + 1; + goto star; + + star: + do { + lp--; + if (advance (lp, ep)) + return (1); + } while (lp > curlp); + return 0; + + default: + admonish (NULL, "advance() botch -- you lose big"); + return 0; } - return 0; - - case NCCL: - if (cclass (ep, *lp++, 0)) { - ep += *ep + 1; - continue; - } - return 0; - - case CDOT | STAR: - curlp = lp; - while (*lp++) - continue; - goto star; - - case CCHR | STAR: - curlp = lp; - while (*lp++ == *ep || cc[lp[-1]] == *ep) - continue; - ep++; - goto star; - - case CCL | STAR: - case NCCL | STAR: - curlp = lp; - while (cclass (ep, *lp++, ep[-1] == (CCL | STAR))) - continue; - ep += *ep + 1; - goto star; - - star: - do { - lp--; - if (advance (lp, ep)) - return (1); - } while (lp > curlp); - return 0; - - default: - admonish (NULL, "advance() botch -- you lose big"); - return 0; - } } static int cclass (unsigned char *aset, int ac, int af) { - register unsigned int n; - register unsigned char c, *set; + register unsigned int n; + register unsigned char c, *set; - set = aset; - if ((c = ac) == 0) - return (0); + set = aset; + if ((c = ac) == 0) + return (0); - n = *set++; - while (n--) - if (*set++ == c || set[-1] == cc[c]) - return (af); + n = *set++; + while (n--) + if (*set++ == c || set[-1] == cc[c]) + return (af); - return (!af); + return (!af); } static int tcompile (char *ap, struct tws *tb, int isafter) { - register struct tws *tw; + register struct tws *tw; - if ((tw = tws_parse (ap, isafter)) == NULL) - return 0; + if ((tw = tws_parse (ap, isafter)) == NULL) + return 0; - twscopy (tb, tw); - return 1; + twscopy (tb, tw); + return 1; } static struct tws * tws_parse (char *ap, int isafter) { - char buffer[BUFSIZ]; - register struct tws *tw, *ts; - - if ((tw = tws_special (ap)) != NULL) { - tw->tw_sec = tw->tw_min = isafter ? 59 : 0; - tw->tw_hour = isafter ? 23 : 0; - return tw; - } - if ((tw = dparsetime (ap)) != NULL) - return tw; - - if ((ts = dlocaltimenow ()) == NULL) - return NULL; + char buffer[BUFSIZ]; + register struct tws *tw, *ts; + + if ((tw = tws_special (ap)) != NULL) { + tw->tw_sec = tw->tw_min = isafter ? 59 : 0; + tw->tw_hour = isafter ? 23 : 0; + return tw; + } + if ((tw = dparsetime (ap)) != NULL) + return tw; + + if ((ts = dlocaltimenow ()) == NULL) + return NULL; - snprintf (buffer, sizeof(buffer), "%s %s", ap, dtwszone (ts)); - if ((tw = dparsetime (buffer)) != NULL) - return tw; + snprintf (buffer, sizeof(buffer), "%s %s", ap, dtwszone (ts)); + if ((tw = dparsetime (buffer)) != NULL) + return tw; - snprintf (buffer, sizeof(buffer), "%s %02d:%02d:%02d %s", ap, - ts->tw_hour, ts->tw_min, ts->tw_sec, dtwszone (ts)); - if ((tw = dparsetime (buffer)) != NULL) - return tw; + snprintf (buffer, sizeof(buffer), "%s %02d:%02d:%02d %s", ap, + ts->tw_hour, ts->tw_min, ts->tw_sec, dtwszone (ts)); + if ((tw = dparsetime (buffer)) != NULL) + return tw; - snprintf (buffer, sizeof(buffer), "%02d %s %04d %s", - ts->tw_mday, tw_moty[ts->tw_mon], ts->tw_year, ap); - if ((tw = dparsetime (buffer)) != NULL) - return tw; + snprintf (buffer, sizeof(buffer), "%02d %s %04d %s", + ts->tw_mday, tw_moty[ts->tw_mon], ts->tw_year, ap); + if ((tw = dparsetime (buffer)) != NULL) + return tw; - snprintf (buffer, sizeof(buffer), "%02d %s %04d %s %s", - ts->tw_mday, tw_moty[ts->tw_mon], ts->tw_year, - ap, dtwszone (ts)); - if ((tw = dparsetime (buffer)) != NULL) - return tw; + snprintf (buffer, sizeof(buffer), "%02d %s %04d %s %s", + ts->tw_mday, tw_moty[ts->tw_mon], ts->tw_year, + ap, dtwszone (ts)); + if ((tw = dparsetime (buffer)) != NULL) + return tw; - return NULL; + return NULL; } static struct tws * tws_special (char *ap) { - int i; - time_t clock; - register struct tws *tw; + int i; + time_t clock; + register struct tws *tw; + + time (&clock); + if (!mh_strcasecmp (ap, "today")) + return dlocaltime (&clock); + if (!mh_strcasecmp (ap, "yesterday")) { + clock -= (long) (60 * 60 * 24); + return dlocaltime (&clock); + } + if (!mh_strcasecmp (ap, "tomorrow")) { + clock += (long) (60 * 60 * 24); + return dlocaltime (&clock); + } - time (&clock); - if (!mh_strcasecmp (ap, "today")) - return dlocaltime (&clock); - if (!mh_strcasecmp (ap, "yesterday")) { - clock -= (long) (60 * 60 * 24); - return dlocaltime (&clock); - } - if (!mh_strcasecmp (ap, "tomorrow")) { - clock += (long) (60 * 60 * 24); + for (i = 0; tw_ldotw[i]; i++) + if (!mh_strcasecmp (ap, tw_ldotw[i])) + break; + if (tw_ldotw[i]) { + if ((tw = dlocaltime (&clock)) == NULL) + return NULL; + if ((i -= tw->tw_wday) > 0) + i -= 7; + } + else + if (*ap != '-') + return NULL; + else /* -ddd days ago */ + i = atoi (ap); /* we should error check this */ + + clock += (long) ((60 * 60 * 24) * i); return dlocaltime (&clock); - } - - for (i = 0; tw_ldotw[i]; i++) - if (!mh_strcasecmp (ap, tw_ldotw[i])) - break; - if (tw_ldotw[i]) { - if ((tw = dlocaltime (&clock)) == NULL) - return NULL; - if ((i -= tw->tw_wday) > 0) - i -= 7; - } - else - if (*ap != '-') - return NULL; - else /* -ddd days ago */ - i = atoi (ap); /* we should error check this */ - - clock += (long) ((60 * 60 * 24) * i); - return dlocaltime (&clock); } @@ -935,54 +934,54 @@ static int TWSaction (params) plist { - int state; - register char *bp; - char buf[BUFSIZ], name[NAMESZ]; - register struct tws *tw; - - fseek (fp, start, SEEK_SET); - for (state = FLD, bp = NULL;;) { - switch (state = m_getfld (state, name, buf, sizeof buf, fp)) { - case FLD: - case FLDEOF: - case FLDPLUS: - if (bp != NULL) - free (bp), bp = NULL; - bp = add (buf, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof buf, fp); - bp = add (buf, bp); + int state; + register char *bp; + char buf[BUFSIZ], name[NAMESZ]; + register struct tws *tw; + + fseek (fp, start, SEEK_SET); + for (state = FLD, bp = NULL;;) { + switch (state = m_getfld (state, name, buf, sizeof buf, fp)) { + case FLD: + case FLDEOF: + case FLDPLUS: + if (bp != NULL) + free (bp), bp = NULL; + bp = add (buf, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof buf, fp); + bp = add (buf, bp); + } + if (!mh_strcasecmp (name, n->n_datef)) + break; + if (state != FLDEOF) + continue; + + case BODY: + case BODYEOF: + case FILEEOF: + case LENERR: + case FMTERR: + if (state == LENERR || state == FMTERR) + advise (NULL, "format error in message %d", msgnum); + if (bp != NULL) + free (bp); + return 0; + + default: + adios (NULL, "internal error -- you lose"); } - if (!mh_strcasecmp (name, n->n_datef)) - break; - if (state != FLDEOF) - continue; - - case BODY: - case BODYEOF: - case FILEEOF: - case LENERR: - case FMTERR: - if (state == LENERR || state == FMTERR) - advise (NULL, "format error in message %d", msgnum); - if (bp != NULL) - free (bp); - return 0; - - default: - adios (NULL, "internal error -- you lose"); + break; } - break; - } - - if ((tw = dparsetime (bp)) == NULL) - advise (NULL, "unable to parse %s field in message %d, matching...", - n->n_datef, msgnum), state = 1; - else - state = n->n_after ? (twsort (tw, &n->n_tws) > 0) - : (twsort (tw, &n->n_tws) < 0); - - if (bp != NULL) - free (bp); - return state; + + if ((tw = dparsetime (bp)) == NULL) + advise (NULL, "unable to parse %s field in message %d, matching...", + n->n_datef, msgnum), state = 1; + else + state = n->n_after ? (twsort (tw, &n->n_tws) > 0) + : (twsort (tw, &n->n_tws) < 0); + + if (bp != NULL) + free (bp); + return state; } diff --git a/uip/prompter.c b/uip/prompter.c index 7c28aec..f92eda1 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -1,4 +1,3 @@ - /* * prompter.c -- simple prompting editor front-end * @@ -24,42 +23,42 @@ # endif #endif -#define QUOTE '\\' +#define QUOTE '\\' -#ifndef CKILL +#ifndef CKILL # define CKILL '@' #endif -#ifndef CERASE +#ifndef CERASE # define CERASE '#' #endif static struct swit switches[] = { -#define ERASESW 0 - { "erase chr", 0 }, -#define KILLSW 1 - { "kill chr", 0 }, -#define PREPSW 2 - { "prepend", 0 }, -#define NPREPSW 3 - { "noprepend", 0 }, -#define RAPDSW 4 - { "rapid", 0 }, -#define NRAPDSW 5 - { "norapid", 0 }, -#define BODYSW 6 - { "body", -4 }, -#define NBODYSW 7 - { "nobody", -6 }, -#define DOTSW 8 - { "doteof", 0 }, -#define NDOTSW 9 - { "nodoteof", 0 }, +#define ERASESW 0 + { "erase chr", 0 }, +#define KILLSW 1 + { "kill chr", 0 }, +#define PREPSW 2 + { "prepend", 0 }, +#define NPREPSW 3 + { "noprepend", 0 }, +#define RAPDSW 4 + { "rapid", 0 }, +#define NRAPDSW 5 + { "norapid", 0 }, +#define BODYSW 6 + { "body", -4 }, +#define NBODYSW 7 + { "nobody", -6 }, +#define DOTSW 8 + { "doteof", 0 }, +#define NDOTSW 9 + { "nodoteof", 0 }, #define VERSIONSW 10 - { "version", 0 }, -#define HELPSW 11 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 11 + { "help", 0 }, + { NULL, 0 } }; @@ -99,386 +98,386 @@ static RETSIGTYPE intrser (int); int main (int argc, char **argv) { - int body = 1, prepend = 1, rapid = 0; - int doteof = 0, fdi, fdo, i, state; - char *cp, *drft = NULL, *erasep = NULL; - char *killp = NULL, name[NAMESZ], field[BUFSIZ]; - char buffer[BUFSIZ], tmpfil[BUFSIZ]; - char **arguments, **argp; - FILE *in, *out; - char *tfile = NULL; + int body = 1, prepend = 1, rapid = 0; + int doteof = 0, fdi, fdo, i, state; + char *cp, *drft = NULL, *erasep = NULL; + char *killp = NULL, name[NAMESZ], field[BUFSIZ]; + char buffer[BUFSIZ], tmpfil[BUFSIZ]; + char **arguments, **argp; + FILE *in, *out; + char *tfile = NULL; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buffer, sizeof(buffer), "%s [switches] file", - invo_name); - print_help (buffer, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ERASESW: - if (!(erasep = *argp++) || *erasep == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case KILLSW: - if (!(killp = *argp++) || *killp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case PREPSW: - prepend++; - continue; - case NPREPSW: - prepend = 0; - continue; - - case RAPDSW: - rapid++; - continue; - case NRAPDSW: - rapid = 0; - continue; - - case BODYSW: - body++; - continue; - case NBODYSW: - body = 0; - continue; - - case DOTSW: - doteof++; - continue; - case NDOTSW: - doteof = 0; - continue; - } - } else { - if (!drft) - drft = cp; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buffer, sizeof(buffer), "%s [switches] file", + invo_name); + print_help (buffer, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ERASESW: + if (!(erasep = *argp++) || *erasep == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case KILLSW: + if (!(killp = *argp++) || *killp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case PREPSW: + prepend++; + continue; + case NPREPSW: + prepend = 0; + continue; + + case RAPDSW: + rapid++; + continue; + case NRAPDSW: + rapid = 0; + continue; + + case BODYSW: + body++; + continue; + case NBODYSW: + body = 0; + continue; + + case DOTSW: + doteof++; + continue; + case NDOTSW: + doteof = 0; + continue; + } + } else { + if (!drft) + drft = cp; + } - if (!drft) - adios (NULL, "usage: %s [switches] file", invo_name); - if ((in = fopen (drft, "r")) == NULL) - adios (drft, "unable to open"); + if (!drft) + adios (NULL, "usage: %s [switches] file", invo_name); + if ((in = fopen (drft, "r")) == NULL) + adios (drft, "unable to open"); - tfile = m_mktemp2(NULL, invo_name, NULL, &out); - if (tfile == NULL) adios("prompter", "unable to create temporary file"); - chmod (tmpfil, 0600); - strncpy (tmpfil, tfile, sizeof(tmpfil)); + tfile = m_mktemp2(NULL, invo_name, NULL, &out); + if (tfile == NULL) adios("prompter", "unable to create temporary file"); + chmod (tmpfil, 0600); + strncpy (tmpfil, tfile, sizeof(tmpfil)); - /* - * Are we changing the kill or erase character? - */ - if (killp || erasep) { + /* + * Are we changing the kill or erase character? + */ + if (killp || erasep) { #ifdef HAVE_TERMIOS_H - cc_t save_erase, save_kill; + cc_t save_erase, save_kill; #else - int save_erase, save_kill; + int save_erase, save_kill; #endif - /* get the current terminal attributes */ + /* get the current terminal attributes */ #ifdef HAVE_TERMIOS_H - tcgetattr(0, &tio); + tcgetattr(0, &tio); #else # ifdef HAVE_TERMIO_H - ioctl(0, TCGETA, &tio); + ioctl(0, TCGETA, &tio); # else - ioctl (0, TIOCGETP, (char *) &tio); - ioctl (0, TIOCGETC, (char *) &tc); + ioctl (0, TIOCGETP, (char *) &tio); + ioctl (0, TIOCGETC, (char *) &tc); # endif #endif - /* save original kill, erase character for later */ - save_kill = KILL; - save_erase = ERASE; + /* save original kill, erase character for later */ + save_kill = KILL; + save_erase = ERASE; - /* set new kill, erase character in terminal structure */ - KILL = killp ? chrcnv (killp) : save_kill; - ERASE = erasep ? chrcnv (erasep) : save_erase; + /* set new kill, erase character in terminal structure */ + KILL = killp ? chrcnv (killp) : save_kill; + ERASE = erasep ? chrcnv (erasep) : save_erase; - /* set the new terminal attributes */ + /* set the new terminal attributes */ #ifdef HAVE_TERMIOS_H - tcsetattr(0, TCSADRAIN, &tio); + tcsetattr(0, TCSADRAIN, &tio); #else # ifdef HAVE_TERMIO_H - ioctl(0, TCSETAW, &tio); + ioctl(0, TCSETAW, &tio); # else - ioctl (0, TIOCSETN, (char *) &tio); + ioctl (0, TIOCSETN, (char *) &tio); # endif #endif - /* print out new kill erase characters */ - chrdsp ("erase", ERASE); - chrdsp (", kill", KILL); - chrdsp (", intr", INTR); - putchar ('\n'); - fflush (stdout); + /* print out new kill erase characters */ + chrdsp ("erase", ERASE); + chrdsp (", kill", KILL); + chrdsp (", intr", INTR); + putchar ('\n'); + fflush (stdout); - /* - * We set the kill and erase character back to original - * setup in terminal structure so we can easily - * restore it upon exit. - */ - KILL = save_kill; - ERASE = save_erase; - } - - sigint = 0; - SIGNAL2 (SIGINT, intrser); - - /* - * Loop through the lines of the draft skeleton. - */ - for (state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), in)) { - case FLD: - case FLDEOF: - case FLDPLUS: /* - * Check if the value of field contains anything - * other than space or tab. + * We set the kill and erase character back to original + * setup in terminal structure so we can easily + * restore it upon exit. */ - for (cp = field; *cp; cp++) - if (*cp != ' ' && *cp != '\t') - break; + KILL = save_kill; + ERASE = save_erase; + } - /* If so, just add header line to draft */ - if (*cp++ != '\n' || *cp != 0) { - printf ("%s:%s", name, field); - fprintf (out, "%s:%s", name, field); - while (state == FLDPLUS) { - state = - m_getfld (state, name, field, sizeof(field), in); - printf ("%s", field); - fprintf (out, "%s", field); - } - } else { - /* Else, get value of header field */ - printf ("%s: ", name); - fflush (stdout); - i = getln (field, sizeof(field)); - if (i == -1) { + sigint = 0; + SIGNAL2 (SIGINT, intrser); + + /* + * Loop through the lines of the draft skeleton. + */ + for (state = FLD;;) { + switch (state = m_getfld (state, name, field, sizeof(field), in)) { + case FLD: + case FLDEOF: + case FLDPLUS: + /* + * Check if the value of field contains anything + * other than space or tab. + */ + for (cp = field; *cp; cp++) + if (*cp != ' ' && *cp != '\t') + break; + + /* If so, just add header line to draft */ + if (*cp++ != '\n' || *cp != 0) { + printf ("%s:%s", name, field); + fprintf (out, "%s:%s", name, field); + while (state == FLDPLUS) { + state = + m_getfld (state, name, field, sizeof(field), in); + printf ("%s", field); + fprintf (out, "%s", field); + } + } else { + /* Else, get value of header field */ + printf ("%s: ", name); + fflush (stdout); + i = getln (field, sizeof(field)); + if (i == -1) { abort: - if (killp || erasep) { + if (killp || erasep) { #ifdef HAVE_TERMIOS_H - tcsetattr(0, TCSADRAIN, &tio); + tcsetattr(0, TCSADRAIN, &tio); #else # ifdef HAVE_TERMIO - ioctl (0, TCSETA, &tio); + ioctl (0, TCSETA, &tio); # else - ioctl (0, TIOCSETN, (char *) &tio); + ioctl (0, TIOCSETN, (char *) &tio); # endif #endif - } - unlink (tmpfil); - done (1); - } - if (i != 0 || (field[0] != '\n' && field[0] != 0)) { - fprintf (out, "%s:", name); - do { - if (field[0] != ' ' && field[0] != '\t') - putc (' ', out); - fprintf (out, "%s", field); - } while (i == 1 - && (i = getln (field, sizeof(field))) >= 0); - if (i == -1) - goto abort; - } - } - - if (state == FLDEOF) { /* moby hack */ - fprintf (out, "--------\n"); - printf ("--------\n"); - if (!body) - break; - goto no_body; - } - continue; - - case BODY: - case BODYEOF: - case FILEEOF: - if (!body) - break; - fprintf (out, "--------\n"); - if (field[0] == 0 || !prepend) - printf ("--------\n"); - if (field[0]) { - if (prepend && body) { - printf ("\n--------Enter initial text\n\n"); - fflush (stdout); - for (;;) { - getln (buffer, sizeof(buffer)); - if (doteof && buffer[0] == '.' && buffer[1] == '\n') - break; - if (buffer[0] == 0) - break; - fprintf (out, "%s", buffer); - } - } - - do { - fprintf (out, "%s", field); - if (!rapid && !sigint) - printf ("%s", field); - } while (state == BODY && - (state = m_getfld (state, name, field, sizeof(field), in))); - if (prepend || !body) - break; - else - printf ("\n--------Enter additional text\n\n"); - } + } + unlink (tmpfil); + done (1); + } + if (i != 0 || (field[0] != '\n' && field[0] != 0)) { + fprintf (out, "%s:", name); + do { + if (field[0] != ' ' && field[0] != '\t') + putc (' ', out); + fprintf (out, "%s", field); + } while (i == 1 + && (i = getln (field, sizeof(field))) >= 0); + if (i == -1) + goto abort; + } + } + + if (state == FLDEOF) { /* moby hack */ + fprintf (out, "--------\n"); + printf ("--------\n"); + if (!body) + break; + goto no_body; + } + continue; + + case BODY: + case BODYEOF: + case FILEEOF: + if (!body) + break; + fprintf (out, "--------\n"); + if (field[0] == 0 || !prepend) + printf ("--------\n"); + if (field[0]) { + if (prepend && body) { + printf ("\n--------Enter initial text\n\n"); + fflush (stdout); + for (;;) { + getln (buffer, sizeof(buffer)); + if (doteof && buffer[0] == '.' && buffer[1] == '\n') + break; + if (buffer[0] == 0) + break; + fprintf (out, "%s", buffer); + } + } + + do { + fprintf (out, "%s", field); + if (!rapid && !sigint) + printf ("%s", field); + } while (state == BODY && + (state = m_getfld (state, name, field, sizeof(field), in))); + if (prepend || !body) + break; + else + printf ("\n--------Enter additional text\n\n"); + } no_body: - fflush (stdout); - for (;;) { - getln (field, sizeof(field)); - if (doteof && field[0] == '.' && field[1] == '\n') - break; - if (field[0] == 0) - break; - fprintf (out, "%s", field); + fflush (stdout); + for (;;) { + getln (field, sizeof(field)); + if (doteof && field[0] == '.' && field[1] == '\n') + break; + if (field[0] == 0) + break; + fprintf (out, "%s", field); + } + break; + + default: + adios (NULL, "skeleton is poorly formatted"); } break; - - default: - adios (NULL, "skeleton is poorly formatted"); } - break; - } - if (body) - printf ("--------\n"); + if (body) + printf ("--------\n"); - fflush (stdout); - fclose (in); - fclose (out); - SIGNAL (SIGINT, SIG_IGN); + fflush (stdout); + fclose (in); + fclose (out); + SIGNAL (SIGINT, SIG_IGN); - if (killp || erasep) { + if (killp || erasep) { #ifdef HAVE_TERMIOS_H - tcsetattr(0, TCSADRAIN, &tio); + tcsetattr(0, TCSADRAIN, &tio); #else # ifdef HAVE_TERMIO_H - ioctl (0, TCSETAW, &tio); + ioctl (0, TCSETAW, &tio); # else - ioctl (0, TIOCSETN, (char *) &tio); + ioctl (0, TIOCSETN, (char *) &tio); # endif #endif - } - - if ((fdi = open (tmpfil, O_RDONLY)) == NOTOK) - adios (tmpfil, "unable to re-open"); - if ((fdo = creat (drft, m_gmprot ())) == NOTOK) - adios (drft, "unable to write"); - cpydata (fdi, fdo, tmpfil, drft); - close (fdi); - close (fdo); - unlink (tmpfil); - - context_save (); /* save the context file */ - done (0); - return 1; + } + + if ((fdi = open (tmpfil, O_RDONLY)) == NOTOK) + adios (tmpfil, "unable to re-open"); + if ((fdo = creat (drft, m_gmprot ())) == NOTOK) + adios (drft, "unable to write"); + cpydata (fdi, fdo, tmpfil, drft); + close (fdi); + close (fdo); + unlink (tmpfil); + + context_save (); /* save the context file */ + done (0); + return 1; } int getln (char *buffer, int n) { - int c; - char *cp; - - cp = buffer; - *cp = 0; - - switch (setjmp (sigenv)) { - case OK: - wtuser = 1; - break; - - case DONE: - wtuser = 0; - return 0; - - default: - wtuser = 0; - return NOTOK; - } - - for (;;) { - switch (c = getchar ()) { - case EOF: - clearerr (stdin); - longjmp (sigenv, DONE); - - case '\n': - if (cp[-1] == QUOTE) { - cp[-1] = c; - wtuser = 0; - return 1; + int c; + char *cp; + + cp = buffer; + *cp = 0; + + switch (setjmp (sigenv)) { + case OK: + wtuser = 1; + break; + + case DONE: + wtuser = 0; + return 0; + + default: + wtuser = 0; + return NOTOK; + } + + for (;;) { + switch (c = getchar ()) { + case EOF: + clearerr (stdin); + longjmp (sigenv, DONE); + + case '\n': + if (cp[-1] == QUOTE) { + cp[-1] = c; + wtuser = 0; + return 1; + } + *cp++ = c; + *cp = 0; + wtuser = 0; + return 0; + + default: + if (cp < buffer + n) + *cp++ = c; + *cp = 0; } - *cp++ = c; - *cp = 0; - wtuser = 0; - return 0; - - default: - if (cp < buffer + n) - *cp++ = c; - *cp = 0; } - } } static RETSIGTYPE intrser (int i) { -#ifndef RELIABLE_SIGNALS - SIGNAL (SIGINT, intrser); +#ifndef RELIABLE_SIGNALS + SIGNAL (SIGINT, intrser); #endif - if (wtuser) - longjmp (sigenv, NOTOK); - sigint++; + if (wtuser) + longjmp (sigenv, NOTOK); + sigint++; } static int chrcnv (char *cp) { - return (*cp != QUOTE ? *cp : m_atoi (++cp)); + return (*cp != QUOTE ? *cp : m_atoi (++cp)); } static void chrdsp (char *s, char c) { - printf ("%s ", s); - if (c < ' ' || c == 0177) - printf ("^%c", c ^ 0100); - else - printf ("%c", c); + printf ("%s ", s); + if (c < ' ' || c == 0177) + printf ("^%c", c ^ 0100); + else + printf ("%c", c); } diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 9038d5f..89ed029 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -1,4 +1,3 @@ - /* * rcvdist.c -- asynchronously redistribute messages * @@ -15,13 +14,13 @@ #include static struct swit switches[] = { -#define FORMSW 0 - { "form formfile", 4 }, -#define VERSIONSW 1 - { "version", 0 }, -#define HELPSW 2 - { "help", 0 }, - { NULL, 0 } +#define FORMSW 0 + { "form formfile", 4 }, +#define VERSIONSW 1 + { "version", 0 }, +#define HELPSW 2 + { "help", 0 }, + { NULL, 0 } }; static char backup[BUFSIZ] = ""; @@ -38,105 +37,105 @@ static void unlink_done (int) NORETURN; int main (int argc, char **argv) { - pid_t child_id; - int i, vecp = 1; - char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ]; - char **argp, **arguments, *vec[MAXARGS]; - FILE *fp; - char *tfile = NULL; + pid_t child_id; + int i, vecp = 1; + char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ]; + char **argp, **arguments, *vec[MAXARGS]; + FILE *fp; + char *tfile = NULL; - done=unlink_done; + done=unlink_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - vec[vecp++] = --cp; - continue; - - case HELPSW: - snprintf (buf, sizeof(buf), - "%s [switches] [switches for postproc] address ...", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + vec[vecp++] = --cp; + continue; + + case HELPSW: + snprintf (buf, sizeof(buf), + "%s [switches] [switches for postproc] address ...", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + } + } + addrs = addrs ? add (cp, add (", ", addrs)) : getcpy (cp); } - addrs = addrs ? add (cp, add (", ", addrs)) : getcpy (cp); - } - if (addrs == NULL) - adios (NULL, "usage: %s [switches] [switches for postproc] address ...", - invo_name); + if (addrs == NULL) + adios (NULL, "usage: %s [switches] [switches for postproc] address ...", + invo_name); - umask (~m_gmprot ()); + umask (~m_gmprot ()); - tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) adios("rcvdist", "unable to create temporary file"); - strncpy (tmpfil, tfile, sizeof(tmpfil)); + tfile = m_mktemp2(NULL, invo_name, NULL, &fp); + if (tfile == NULL) adios("rcvdist", "unable to create temporary file"); + strncpy (tmpfil, tfile, sizeof(tmpfil)); - cpydata (fileno (stdin), fileno (fp), "message", tmpfil); - fseek (fp, 0L, SEEK_SET); + cpydata (fileno (stdin), fileno (fp), "message", tmpfil); + fseek (fp, 0L, SEEK_SET); - tfile = m_mktemp2(NULL, invo_name, NULL, NULL); - if (tfile == NULL) adios("forw", "unable to create temporary file"); - strncpy (drft, tfile, sizeof(tmpfil)); + tfile = m_mktemp2(NULL, invo_name, NULL, NULL); + if (tfile == NULL) adios("forw", "unable to create temporary file"); + strncpy (drft, tfile, sizeof(tmpfil)); - rcvdistout (fp, form, addrs); - fclose (fp); + rcvdistout (fp, form, addrs); + fclose (fp); - if (distout (drft, tmpfil, backup) == NOTOK) - done (1); + if (distout (drft, tmpfil, backup) == NOTOK) + done (1); - vec[0] = r1bindex (postproc, '/'); - vec[vecp++] = "-dist"; - vec[vecp++] = drft; - vec[vecp] = NULL; + vec[0] = r1bindex (postproc, '/'); + vec[vecp++] = "-dist"; + vec[vecp++] = drft; + vec[vecp] = NULL; - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - admonish (NULL, "unable to fork");/* fall */ - case OK: - execvp (postproc, vec); - fprintf (stderr, "unable to exec "); - perror (postproc); - _exit (1); + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + admonish (NULL, "unable to fork");/* fall */ + case OK: + execvp (postproc, vec); + fprintf (stderr, "unable to exec "); + perror (postproc); + _exit (1); - default: - done (pidXwait(child_id, postproc)); - } + default: + done (pidXwait(child_id, postproc)); + } - return 0; /* dead code to satisfy the compiler */ + return 0; /* dead code to satisfy the compiler */ } /* very similar to routine in replsbr.c */ -#define SBUFSIZ 256 +#define SBUFSIZ 256 static int outputlinelen = OUTPUTLINELEN; @@ -149,141 +148,140 @@ static struct comp **used_buf = 0; static int dat[5]; static char *addrcomps[] = { - "from", - "sender", - "reply-to", - "to", - "cc", - "bcc", - "resent-from", - "resent-sender", - "resent-reply-to", - "resent-to", - "resent-cc", - "resent-bcc", - NULL + "from", + "sender", + "reply-to", + "to", + "cc", + "bcc", + "resent-from", + "resent-sender", + "resent-reply-to", + "resent-to", + "resent-cc", + "resent-bcc", + NULL }; static void rcvdistout (FILE *inb, char *form, char *addrs) { - register int char_read = 0, format_len, i, state; - register char *tmpbuf, **nxtbuf, **ap; - char *cp, *scanl, name[NAMESZ]; - register struct comp *cptr, **savecomp; - FILE *out; - - if (!(out = fopen (drft, "w"))) - adios (drft, "unable to create"); - - /* get new format string */ - cp = new_fs (form ? form : rcvdistcomps, NULL, NULL); - format_len = strlen (cp); - ncomps = fmt_compile (cp, &fmt) + 1; - if (!(nxtbuf = compbuffers = (char **) calloc ((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); - if (!(savecomp = used_buf = (struct comp **) calloc ((size_t) (ncomps + 1), sizeof(struct comp *)))) - adios (NULL, "unable to allocate component buffer stack"); - savecomp += ncomps + 1; - *--savecomp = 0; - - for (i = ncomps; i--;) - *nxtbuf++ = mh_xmalloc (SBUFSIZ); - nxtbuf = compbuffers; - tmpbuf = *nxtbuf++; - - for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); - if (cptr) - cptr->c_type |= CT_ADDR; - } - - FINDCOMP (cptr, "addresses"); - if (cptr) - cptr->c_text = addrs; - - for (state = FLD;;) { - switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { - case FLD: - case FLDPLUS: - if ((cptr = wantcomp[CHASH (name)])) - do { - if (!mh_strcasecmp (name, cptr->c_name)) { - char_read += msg_count; - if (!cptr->c_text) { - cptr->c_text = tmpbuf; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } - else { - i = strlen (cp = cptr->c_text) - 1; - if (cp[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cp[i] = 0; - cp = add (",\n\t", cp); - } - else - cp = add ("\t", cp); - } - cptr->c_text = add (tmpbuf, cp); - } - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, - SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); - char_read += msg_count; - } - break; - } - } while ((cptr = cptr->c_next)); - - while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); - break; - - case LENERR: - case FMTERR: - case BODY: - case FILEEOF: - goto finished; + register int char_read = 0, format_len, i, state; + register char *tmpbuf, **nxtbuf, **ap; + char *cp, *scanl, name[NAMESZ]; + register struct comp *cptr, **savecomp; + FILE *out; + + if (!(out = fopen (drft, "w"))) + adios (drft, "unable to create"); + + /* get new format string */ + cp = new_fs (form ? form : rcvdistcomps, NULL, NULL); + format_len = strlen (cp); + ncomps = fmt_compile (cp, &fmt) + 1; + if (!(nxtbuf = compbuffers = (char **) calloc ((size_t) ncomps, sizeof(char *)))) + adios (NULL, "unable to allocate component buffers"); + if (!(savecomp = used_buf = (struct comp **) calloc ((size_t) (ncomps + 1), sizeof(struct comp *)))) + adios (NULL, "unable to allocate component buffer stack"); + savecomp += ncomps + 1; + *--savecomp = 0; + + for (i = ncomps; i--;) + *nxtbuf++ = mh_xmalloc (SBUFSIZ); + nxtbuf = compbuffers; + tmpbuf = *nxtbuf++; + + for (ap = addrcomps; *ap; ap++) { + FINDCOMP (cptr, *ap); + if (cptr) + cptr->c_type |= CT_ADDR; + } - default: - adios (NULL, "m_getfld() returned %d", state); + FINDCOMP (cptr, "addresses"); + if (cptr) + cptr->c_text = addrs; + + for (state = FLD;;) { + switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { + case FLD: + case FLDPLUS: + if ((cptr = wantcomp[CHASH (name)])) + do { + if (!mh_strcasecmp (name, cptr->c_name)) { + char_read += msg_count; + if (!cptr->c_text) { + cptr->c_text = tmpbuf; + *--savecomp = cptr; + tmpbuf = *nxtbuf++; + } else { + i = strlen (cp = cptr->c_text) - 1; + if (cp[i] == '\n') { + if (cptr->c_type & CT_ADDR) { + cp[i] = 0; + cp = add (",\n\t", cp); + } + else + cp = add ("\t", cp); + } + cptr->c_text = add (tmpbuf, cp); + } + while (state == FLDPLUS) { + state = m_getfld (state, name, tmpbuf, + SBUFSIZ, inb); + cptr->c_text = add (tmpbuf, cptr->c_text); + char_read += msg_count; + } + break; + } + } while ((cptr = cptr->c_next)); + + while (state == FLDPLUS) + state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + break; + + case LENERR: + case FMTERR: + case BODY: + case FILEEOF: + goto finished; + + default: + adios (NULL, "m_getfld() returned %d", state); + } } - } finished: ; - i = format_len + char_read + 256; - scanl = mh_xmalloc ((size_t) i + 2); - dat[0] = dat[1] = dat[2] = dat[4] = 0; - dat[3] = outputlinelen; - fmt_scan (fmt, scanl, i, dat); - fputs (scanl, out); - - if (ferror (out)) - adios (drft, "error writing"); - fclose (out); - - free (scanl); - for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); - while (i-- > 0) - free (*nxtbuf++); - free ((char *) compbuffers); - free ((char *) used_buf); + i = format_len + char_read + 256; + scanl = mh_xmalloc ((size_t) i + 2); + dat[0] = dat[1] = dat[2] = dat[4] = 0; + dat[3] = outputlinelen; + fmt_scan (fmt, scanl, i, dat); + fputs (scanl, out); + + if (ferror (out)) + adios (drft, "error writing"); + fclose (out); + + free (scanl); + for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) + free (cptr->c_text); + while (i-- > 0) + free (*nxtbuf++); + free ((char *) compbuffers); + free ((char *) used_buf); } static void unlink_done (int status) { - if (backup[0]) - unlink (backup); - if (drft[0]) - unlink (drft); - if (tmpfil[0]) - unlink (tmpfil); - - exit (status ? RCV_MBX : RCV_MOK); + if (backup[0]) + unlink (backup); + if (drft[0]) + unlink (drft); + if (tmpfil[0]) + unlink (tmpfil); + + exit (status ? RCV_MBX : RCV_MOK); } diff --git a/uip/rcvpack.c b/uip/rcvpack.c index 0b4dc9f..b1bc518 100644 --- a/uip/rcvpack.c +++ b/uip/rcvpack.c @@ -1,4 +1,3 @@ - /* * rcvpack.c -- append message to a file * @@ -14,15 +13,15 @@ #include static struct swit switches[] = { -#define MBOXSW 0 - { "mbox", 0 }, -#define MMDFSW 1 - { "mmdf", 0 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } +#define MBOXSW 0 + { "mbox", 0 }, +#define MMDFSW 1 + { "mmdf", 0 }, +#define VERSIONSW 2 + { "version", 0 }, +#define HELPSW 3 + { "help", 0 }, + { NULL, 0 } }; /* @@ -34,73 +33,73 @@ static int mbx_style = MBOX_FORMAT; int main (int argc, char **argv) { - int md; - char *cp, *file = NULL, buf[BUFSIZ]; - char **argp, **arguments; + int md; + char *cp, *file = NULL, buf[BUFSIZ]; + char **argp, **arguments; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* parse arguments */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case MBOXSW: - mbx_style = MBOX_FORMAT; - continue; - case MMDFSW: - mbx_style = MMDF_FORMAT; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* parse arguments */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case MBOXSW: + mbx_style = MBOX_FORMAT; + continue; + case MMDFSW: + mbx_style = MMDF_FORMAT; + continue; + } + } + if (file) + adios (NULL, "only one file at a time!"); + else + file = cp; } - if (file) - adios (NULL, "only one file at a time!"); - else - file = cp; - } - if (!file) - adios (NULL, "%s [switches] file", invo_name); + if (!file) + adios (NULL, "%s [switches] file", invo_name); - rewind (stdin); + rewind (stdin); - /* open and lock the file */ - if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK) - done (RCV_MBX); + /* open and lock the file */ + if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK) + done (RCV_MBX); - /* append the message */ - if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) { - mbx_close (file, md); - done (RCV_MBX); - } + /* append the message */ + if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) { + mbx_close (file, md); + done (RCV_MBX); + } - /* close and unlock the file */ - if (mbx_close (file, md) == NOTOK) - done (RCV_MBX); + /* close and unlock the file */ + if (mbx_close (file, md) == NOTOK) + done (RCV_MBX); - done (RCV_MOK); - return 1; + done (RCV_MOK); + return 1; } diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 3131076..2458852 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -1,4 +1,3 @@ - /* * rcvstore.c -- asynchronously add mail to a folder * @@ -15,29 +14,29 @@ #include static struct swit switches[] = { -#define CRETSW 0 - { "create", 0 }, -#define NCRETSW 1 - { "nocreate", 0 }, -#define UNSEENSW 2 - { "unseen", 0 }, -#define NUNSEENSW 3 - { "nounseen", 0 }, -#define PUBSW 4 - { "public", 0 }, -#define NPUBSW 5 - { "nopublic", 0 }, -#define ZEROSW 6 - { "zero", 0 }, -#define NZEROSW 7 - { "nozero", 0 }, -#define SEQSW 8 - { "sequence name", 0 }, -#define VERSIONSW 9 - { "version", 0 }, -#define HELPSW 10 - { "help", 0 }, - { NULL, 0 } +#define CRETSW 0 + { "create", 0 }, +#define NCRETSW 1 + { "nocreate", 0 }, +#define UNSEENSW 2 + { "unseen", 0 }, +#define NUNSEENSW 3 + { "nounseen", 0 }, +#define PUBSW 4 + { "public", 0 }, +#define NPUBSW 5 + { "nopublic", 0 }, +#define ZEROSW 6 + { "zero", 0 }, +#define NZEROSW 7 + { "nozero", 0 }, +#define SEQSW 8 + { "sequence name", 0 }, +#define VERSIONSW 9 + { "version", 0 }, +#define HELPSW 10 + { "help", 0 }, + { NULL, 0 } }; @@ -51,181 +50,182 @@ static void unlink_done(int) NORETURN; int main (int argc, char **argv) { - int publicsw = -1, zerosw = 0; - int create = 1, unseensw = 1; - int fd, msgnum, seqp = 0; - char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments, *seqs[NUMATTRS+1]; - struct msgs *mp; - struct stat st; + int publicsw = -1, zerosw = 0; + int create = 1, unseensw = 1; + int fd, msgnum, seqp = 0; + char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments, *seqs[NUMATTRS+1]; + struct msgs *mp; + struct stat st; - done=unlink_done; + done=unlink_done; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* parse arguments */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), + "%s [+folder] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case SEQSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument name to %s", argp[-2]); + + /* check if too many sequences specified */ + if (seqp >= NUMATTRS) + adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); + seqs[seqp++] = cp; + continue; + + case UNSEENSW: + unseensw = 1; + continue; + case NUNSEENSW: + unseensw = 0; + continue; + + case PUBSW: + publicsw = 1; + continue; + case NPUBSW: + publicsw = 0; + continue; + + case ZEROSW: + zerosw++; + continue; + case NZEROSW: + zerosw = 0; + continue; + + case CRETSW: + create++; + continue; + case NCRETSW: + create = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + adios (NULL, "usage: %s [+folder] [switches]", invo_name); + } + } - /* read user profile/context */ - context_read(); + seqs[seqp] = NULL; /* NULL terminate list of sequences */ - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; + if (!context_find ("path")) + free (path ("./", TFOLDER)); - /* parse arguments */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + /* if no folder is given, use default folder */ + if (!folder) + folder = getfolder (0); + maildir = m_maildir (folder); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + /* check if folder exists */ + if (stat (maildir, &st) == NOTOK) { + if (errno != ENOENT) + adios (maildir, "error on folder"); + if (!create) + adios (NULL, "folder %s doesn't exist", maildir); + if (!makedir (maildir)) + adios (NULL, "unable to create folder %s", maildir); + } + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* ignore a few signals */ + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); + + /* create a temporary file */ + tmpfilenam = m_mktemp (invo_name, &fd, NULL); + if (tmpfilenam == NULL) { + adios ("rcvstore", "unable to create temporary file"); + } + chmod (tmpfilenam, m_gmprot()); + + /* copy the message from stdin into temp file */ + cpydata (fileno (stdin), fd, "standard input", tmpfilenam); - case SEQSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument name to %s", argp[-2]); - - /* check if too many sequences specified */ - if (seqp >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); - seqs[seqp++] = cp; - continue; - - case UNSEENSW: - unseensw = 1; - continue; - case NUNSEENSW: - unseensw = 0; - continue; - - case PUBSW: - publicsw = 1; - continue; - case NPUBSW: - publicsw = 0; - continue; - - case ZEROSW: - zerosw++; - continue; - case NZEROSW: - zerosw = 0; - continue; - - case CRETSW: - create++; - continue; - case NCRETSW: - create = 0; - continue; - } + if (fstat (fd, &st) == NOTOK) { + unlink (tmpfilenam); + adios (tmpfilenam, "unable to fstat"); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - adios (NULL, "usage: %s [+folder] [switches]", invo_name); + if (close (fd) == NOTOK) + adios (tmpfilenam, "error closing"); + + /* don't add file if it is empty */ + if (st.st_size == 0) { + unlink (tmpfilenam); + advise (NULL, "empty file"); + done (0); } - } - - seqs[seqp] = NULL; /* NULL terminate list of sequences */ - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* if no folder is given, use default folder */ - if (!folder) - folder = getfolder (0); - maildir = m_maildir (folder); - - /* check if folder exists */ - if (stat (maildir, &st) == NOTOK) { - if (errno != ENOENT) - adios (maildir, "error on folder"); - if (!create) - adios (NULL, "folder %s doesn't exist", maildir); - if (!makedir (maildir)) - adios (NULL, "unable to create folder %s", maildir); - } - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* ignore a few signals */ - SIGNAL (SIGHUP, SIG_IGN); - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - SIGNAL (SIGTERM, SIG_IGN); - - /* create a temporary file */ - tmpfilenam = m_mktemp (invo_name, &fd, NULL); - if (tmpfilenam == NULL) { - adios ("rcvstore", "unable to create temporary file"); - } - chmod (tmpfilenam, m_gmprot()); - - /* copy the message from stdin into temp file */ - cpydata (fileno (stdin), fd, "standard input", tmpfilenam); - - if (fstat (fd, &st) == NOTOK) { - unlink (tmpfilenam); - adios (tmpfilenam, "unable to fstat"); - } - if (close (fd) == NOTOK) - adios (tmpfilenam, "error closing"); - - /* don't add file if it is empty */ - if (st.st_size == 0) { - unlink (tmpfilenam); - advise (NULL, "empty file"); + + /* + * read folder and create message structure + */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* + * Link message into folder, and possibly add + * to the Unseen-Sequence's. + */ + if ((msgnum = folder_addmsg (&mp, tmpfilenam, 0, unseensw, 0, 0, (char *)0)) == -1) + done (1); + + /* + * Add the message to any extra sequences + * that have been specified. + */ + for (seqp = 0; seqs[seqp]; seqp++) { + if (!seq_addmsg (mp, seqs[seqp], msgnum, publicsw, zerosw)) + done (1); + } + + seq_setunseen (mp, 0); /* synchronize any Unseen-Sequence's */ + seq_save (mp); /* synchronize and save message sequences */ + folder_free (mp); /* free folder/message structure */ + + context_save (); /* save the global context file */ + unlink (tmpfilenam); /* remove temporary file */ + tmpfilenam = NULL; + done (0); - } - - /* - * read folder and create message structure - */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* - * Link message into folder, and possibly add - * to the Unseen-Sequence's. - */ - if ((msgnum = folder_addmsg (&mp, tmpfilenam, 0, unseensw, 0, 0, (char *)0)) == -1) - done (1); - - /* - * Add the message to any extra sequences - * that have been specified. - */ - for (seqp = 0; seqs[seqp]; seqp++) { - if (!seq_addmsg (mp, seqs[seqp], msgnum, publicsw, zerosw)) - done (1); - } - - seq_setunseen (mp, 0); /* synchronize any Unseen-Sequence's */ - seq_save (mp); /* synchronize and save message sequences */ - folder_free (mp); /* free folder/message structure */ - - context_save (); /* save the global context file */ - unlink (tmpfilenam); /* remove temporary file */ - tmpfilenam = NULL; - - done (0); - return 1; + return 1; } /* @@ -234,7 +234,7 @@ main (int argc, char **argv) static void unlink_done(int status) { - if (tmpfilenam && *tmpfilenam) - unlink (tmpfilenam); - exit (status); + if (tmpfilenam && *tmpfilenam) + unlink (tmpfilenam); + exit (status); } diff --git a/uip/rcvtty.c b/uip/rcvtty.c index 8b04d61..577873f 100644 --- a/uip/rcvtty.c +++ b/uip/rcvtty.c @@ -1,4 +1,3 @@ - /* * rcvtty.c -- a rcvmail program (a lot like rcvalert) handling IPC ttys * @@ -33,33 +32,33 @@ # endif #endif -#define SCANFMT \ +#define SCANFMT \ "%2(hour{dtimenow}):%02(min{dtimenow}): %<(size)%5(size) %>%<{encrypted}E%>\ %<(mymbox{from})%<{to}To:%14(friendly{to})%>%>%<(zero)%17(friendly{from})%> \ %{subject}%<{body}<<%{body}>>%>" static struct swit switches[] = { -#define BIFFSW 0 - { "biff", 0 }, -#define FORMSW 1 - { "form formatfile", 0 }, -#define FMTSW 2 - { "format string", 5 }, +#define BIFFSW 0 + { "biff", 0 }, +#define FORMSW 1 + { "form formatfile", 0 }, +#define FMTSW 2 + { "format string", 5 }, #define WIDTHSW 3 - { "width columns", 0 }, -#define NLSW 4 - { "newline", 0 }, + { "width columns", 0 }, +#define NLSW 4 + { "newline", 0 }, #define NNLSW 5 - { "nonewline", 0 }, -#define BELSW 6 - { "bell", 0 }, -#define NBELSW 7 - { "nobell", 0 }, + { "nonewline", 0 }, +#define BELSW 6 + { "bell", 0 }, +#define NBELSW 7 + { "nobell", 0 }, #define VERSIONSW 8 - { "version", 0 }, -#define HELPSW 9 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 9 + { "help", 0 }, + { NULL, 0 } }; static jmp_buf myctx; @@ -87,120 +86,120 @@ static void alert (char *, int); int main (int argc, char **argv) { - int md, vecp = 0; - char *cp, *user, buf[BUFSIZ], tty[BUFSIZ]; - char **argp, **arguments, *vec[MAXARGS]; + int md, vecp = 0; + char *cp, *user, buf[BUFSIZ], tty[BUFSIZ]; + char **argp, **arguments, *vec[MAXARGS]; #ifdef HAVE_GETUTENT - struct utmp * utp; + struct utmp * utp; #else - struct utmp ut; - register FILE *uf; + struct utmp ut; + register FILE *uf; #endif #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - vec[vecp++] = --cp; - continue; - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [command ...]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case BIFFSW: - biff = 1; - continue; - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", argp[-2]); - width = atoi(cp); - continue; - case NLSW: - newline = 1; - continue; - case NNLSW: - newline = 0; - continue; - case BELSW: - bell = 1; - continue; - case NBELSW: - bell = 0; - continue; - - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + vec[vecp++] = --cp; + continue; + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [command ...]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case BIFFSW: + biff = 1; + continue; + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios(NULL, "missing argument to %s", argp[-2]); + width = atoi(cp); + continue; + case NLSW: + newline = 1; + continue; + case NNLSW: + newline = 0; + continue; + case BELSW: + bell = 1; + continue; + case NBELSW: + bell = 0; + continue; + + } + } + vec[vecp++] = cp; } - vec[vecp++] = cp; - } - vec[vecp] = 0; + vec[vecp] = 0; - if ((md = vecp ? message_fd (vec) : header_fd ()) == NOTOK) - exit (RCV_MBX); + if ((md = vecp ? message_fd (vec) : header_fd ()) == NOTOK) + exit (RCV_MBX); - user = getusername(); + user = getusername(); #ifdef HAVE_GETUTENT - setutent(); - while ((utp = getutent()) != NULL) { - if ( + setutent(); + while ((utp = getutent()) != NULL) { + if ( #ifdef HAVE_STRUCT_UTMP_UT_TYPE - utp->ut_type == USER_PROCESS - && + utp->ut_type == USER_PROCESS + && #endif - utp->ut_name[0] != 0 - && utp->ut_line[0] != 0 - && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { - strncpy (tty, utp->ut_line, sizeof(utp->ut_line)); - alert (tty, md); - } - } - endutent(); -#else - if ((uf = fopen (UTMP_FILE, "r")) == NULL) - exit (RCV_MBX); - while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) - if (ut.ut_name[0] != 0 - && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { - strncpy (tty, ut.ut_line, sizeof(ut.ut_line)); - alert (tty, md); + utp->ut_name[0] != 0 + && utp->ut_line[0] != 0 + && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { + strncpy (tty, utp->ut_line, sizeof(utp->ut_line)); + alert (tty, md); + } } - fclose (uf); + endutent(); +#else + if ((uf = fopen (UTMP_FILE, "r")) == NULL) + exit (RCV_MBX); + while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) + if (ut.ut_name[0] != 0 + && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { + strncpy (tty, ut.ut_line, sizeof(ut.ut_line)); + alert (tty, md); + } + fclose (uf); #endif - exit (RCV_MOK); - return 0; /* dead code to satisfy the compiler */ + exit (RCV_MOK); + return 0; /* dead code to satisfy the compiler */ } @@ -208,140 +207,140 @@ static RETSIGTYPE alrmser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGALRM, alrmser); + SIGNAL (SIGALRM, alrmser); #endif - longjmp (myctx, 1); + longjmp (myctx, 1); } static int message_fd (char **vec) { - pid_t child_id; - int bytes, fd, seconds; - char tmpfil[BUFSIZ]; - struct stat st; + pid_t child_id; + int bytes, fd, seconds; + char tmpfil[BUFSIZ]; + struct stat st; #ifdef HAVE_MKSTEMP - fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil))); + fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil))); #else - unlink (mktemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)))); - if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK) - return header_fd (); + unlink (mktemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)))); + if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK) + return header_fd (); #endif - unlink (tmpfil); - - if ((child_id = vfork()) == NOTOK) { - /* fork error */ - close (fd); - return header_fd (); - } else if (child_id) { - /* parent process */ - if (!setjmp (myctx)) { - SIGNAL (SIGALRM, alrmser); - bytes = fstat(fileno (stdin), &st) != NOTOK ? (int) st.st_size : 100; - - /* amount of time to wait depends on message size */ - if (bytes <= 100) { - /* give at least 5 minutes */ - seconds = 300; - } else if (bytes >= 90000) { - /* but 30 minutes should be long enough */ - seconds = 1800; - } else { - seconds = (bytes / 60) + 300; - } - alarm ((unsigned int) seconds); - pidwait(child_id, OK); - alarm (0); - - if (fstat (fd, &st) != NOTOK && st.st_size > (off_t) 0) - return fd; - } else { - /* - * Ruthlessly kill the child and anything - * else in its process group. - */ - KILLPG(child_id, SIGKILL); + unlink (tmpfil); + + if ((child_id = vfork()) == NOTOK) { + /* fork error */ + close (fd); + return header_fd (); + } else if (child_id) { + /* parent process */ + if (!setjmp (myctx)) { + SIGNAL (SIGALRM, alrmser); + bytes = fstat(fileno (stdin), &st) != NOTOK ? (int) st.st_size : 100; + + /* amount of time to wait depends on message size */ + if (bytes <= 100) { + /* give at least 5 minutes */ + seconds = 300; + } else if (bytes >= 90000) { + /* but 30 minutes should be long enough */ + seconds = 1800; + } else { + seconds = (bytes / 60) + 300; + } + alarm ((unsigned int) seconds); + pidwait(child_id, OK); + alarm (0); + + if (fstat (fd, &st) != NOTOK && st.st_size > (off_t) 0) + return fd; + } else { + /* + * Ruthlessly kill the child and anything + * else in its process group. + */ + KILLPG(child_id, SIGKILL); + } + close (fd); + return header_fd (); } - close (fd); - return header_fd (); - } - /* child process */ - rewind (stdin); - if (dup2 (fd, 1) == NOTOK || dup2 (fd, 2) == NOTOK) + /* child process */ + rewind (stdin); + if (dup2 (fd, 1) == NOTOK || dup2 (fd, 2) == NOTOK) + _exit (-1); + closefds (3); + setpgid ((pid_t) 0, getpid ()); /* put in own process group */ + execvp (vec[0], vec); _exit (-1); - closefds (3); - setpgid ((pid_t) 0, getpid ()); /* put in own process group */ - execvp (vec[0], vec); - _exit (-1); - return 1; /* dead code to satisfy compiler */ + return 1; /* dead code to satisfy compiler */ } static int header_fd (void) { - int fd; - char *nfs; - char *tfile = NULL; - - tfile = m_mktemp2(NULL, invo_name, &fd, NULL); - if (tfile == NULL) return NOTOK; - unlink (tfile); - - rewind (stdin); - - /* get new format string */ - nfs = new_fs (form, format, SCANFMT); - scan (stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0); - if (newline) - write (fd, "\n\r", 2); - write (fd, scanl, strlen (scanl)); - if (bell) - write (fd, "\007", 1); - - return fd; + int fd; + char *nfs; + char *tfile = NULL; + + tfile = m_mktemp2(NULL, invo_name, &fd, NULL); + if (tfile == NULL) return NOTOK; + unlink (tfile); + + rewind (stdin); + + /* get new format string */ + nfs = new_fs (form, format, SCANFMT); + scan (stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0); + if (newline) + write (fd, "\n\r", 2); + write (fd, scanl, strlen (scanl)); + if (bell) + write (fd, "\007", 1); + + return fd; } static void alert (char *tty, int md) { - int i, td, mask; - char buffer[BUFSIZ], ttyspec[BUFSIZ]; - struct stat st; + int i, td, mask; + char buffer[BUFSIZ], ttyspec[BUFSIZ]; + struct stat st; - snprintf (ttyspec, sizeof(ttyspec), "/dev/%s", tty); + snprintf (ttyspec, sizeof(ttyspec), "/dev/%s", tty); - /* - * The mask depends on whether we are checking for - * write permission based on `biff' or `mesg'. - */ - mask = biff ? S_IEXEC : (S_IWRITE >> 3); - if (stat (ttyspec, &st) == NOTOK || (st.st_mode & mask) == 0) - return; + /* + * The mask depends on whether we are checking for + * write permission based on `biff' or `mesg'. + */ + mask = biff ? S_IEXEC : (S_IWRITE >> 3); + if (stat (ttyspec, &st) == NOTOK || (st.st_mode & mask) == 0) + return; - if (!setjmp (myctx)) { - SIGNAL (SIGALRM, alrmser); - alarm (2); - td = open (ttyspec, O_WRONLY); - alarm (0); - if (td == NOTOK) - return; - } else { - alarm (0); - return; - } - - lseek (md, (off_t) 0, SEEK_SET); - - while ((i = read (md, buffer, sizeof(buffer))) > 0) - if (write (td, buffer, i) != i) - break; - - close (td); + if (!setjmp (myctx)) { + SIGNAL (SIGALRM, alrmser); + alarm (2); + td = open (ttyspec, O_WRONLY); + alarm (0); + if (td == NOTOK) + return; + } else { + alarm (0); + return; + } + + lseek (md, (off_t) 0, SEEK_SET); + + while ((i = read (md, buffer, sizeof(buffer))) > 0) + if (write (td, buffer, i) != i) + break; + + close (td); } diff --git a/uip/refile.c b/uip/refile.c index 25f7629..b8b64d0 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -1,4 +1,3 @@ - /* * refile.c -- move or link message(s) from a source folder * -- into one or more destination folders @@ -14,40 +13,40 @@ #include static struct swit switches[] = { -#define DRAFTSW 0 - { "draft", 0 }, -#define LINKSW 1 - { "link", 0 }, -#define NLINKSW 2 - { "nolink", 0 }, -#define PRESSW 3 - { "preserve", 0 }, -#define NPRESSW 4 - { "nopreserve", 0 }, -#define UNLINKSW 5 - { "unlink", 0 }, -#define NUNLINKSW 6 - { "nounlink", 0 }, -#define SRCSW 7 - { "src +folder", 0 }, -#define FILESW 8 - { "file file", 0 }, -#define RPROCSW 9 - { "rmmproc program", 0 }, -#define NRPRCSW 10 - { "normmproc", 0 }, -#define VERSIONSW 11 - { "version", 0 }, -#define HELPSW 12 - { "help", 0 }, - { NULL, 0 } +#define DRAFTSW 0 + { "draft", 0 }, +#define LINKSW 1 + { "link", 0 }, +#define NLINKSW 2 + { "nolink", 0 }, +#define PRESSW 3 + { "preserve", 0 }, +#define NPRESSW 4 + { "nopreserve", 0 }, +#define UNLINKSW 5 + { "unlink", 0 }, +#define NUNLINKSW 6 + { "nounlink", 0 }, +#define SRCSW 7 + { "src +folder", 0 }, +#define FILESW 8 + { "file file", 0 }, +#define RPROCSW 9 + { "rmmproc program", 0 }, +#define NRPRCSW 10 + { "normmproc", 0 }, +#define VERSIONSW 11 + { "version", 0 }, +#define HELPSW 12 + { "help", 0 }, + { NULL, 0 } }; static char maildir[BUFSIZ]; struct st_fold { - char *f_name; - struct msgs *f_mp; + char *f_name; + struct msgs *f_mp; }; /* @@ -62,210 +61,210 @@ static int m_file (char *, struct st_fold *, int, int, int); int main (int argc, char **argv) { - int linkf = 0, preserve = 0, filep = 0; - int foldp = 0, isdf = 0, unlink_msgs = 0; - int i, msgnum; - char *cp, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments; - char *filevec[NFOLDERS + 2]; - char **files = &filevec[1]; /* leave room for remove_files:vec[0] */ - struct st_fold folders[NFOLDERS + 1]; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; + int linkf = 0, preserve = 0, filep = 0; + int foldp = 0, isdf = 0, unlink_msgs = 0; + int i, msgnum; + char *cp, *folder = NULL, buf[BUFSIZ]; + char **argp, **arguments; + char *filevec[NFOLDERS + 2]; + char **files = &filevec[1]; /* leave room for remove_files:vec[0] */ + struct st_fold folders[NFOLDERS + 1]; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [msgs] [switches] +folder ...", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case LINKSW: - linkf++; - continue; - case NLINKSW: - linkf = 0; - continue; - - case PRESSW: - preserve++; - continue; - case NPRESSW: - preserve = 0; - continue; - - case UNLINKSW: - unlink_msgs++; - continue; - case NUNLINKSW: - unlink_msgs = 0; - continue; - - case SRCSW: - if (folder) - adios (NULL, "only one source folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DRAFTSW: - if (filep > NFOLDERS) - adios (NULL, "only %d files allowed!", NFOLDERS); - isdf = 0; - files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); - continue; - case FILESW: - if (filep > NFOLDERS) - adios (NULL, "only %d files allowed!", NFOLDERS); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - files[filep++] = path (cp, TFILE); - continue; - - case RPROCSW: - if (!(rmmproc = *argp++) || *rmmproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NRPRCSW: - rmmproc = NULL; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [msgs] [switches] +folder ...", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case LINKSW: + linkf++; + continue; + case NLINKSW: + linkf = 0; + continue; + + case PRESSW: + preserve++; + continue; + case NPRESSW: + preserve = 0; + continue; + + case UNLINKSW: + unlink_msgs++; + continue; + case NUNLINKSW: + unlink_msgs = 0; + continue; + + case SRCSW: + if (folder) + adios (NULL, "only one source folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DRAFTSW: + if (filep > NFOLDERS) + adios (NULL, "only %d files allowed!", NFOLDERS); + isdf = 0; + files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); + continue; + case FILESW: + if (filep > NFOLDERS) + adios (NULL, "only %d files allowed!", NFOLDERS); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + files[filep++] = path (cp, TFILE); + continue; + + case RPROCSW: + if (!(rmmproc = *argp++) || *rmmproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NRPRCSW: + rmmproc = NULL; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (foldp > NFOLDERS) + adios (NULL, "only %d folders allowed!", NFOLDERS); + folders[foldp++].f_name = + pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (foldp > NFOLDERS) - adios (NULL, "only %d folders allowed!", NFOLDERS); - folders[foldp++].f_name = - pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (foldp == 0) - adios (NULL, "no folder specified"); + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (foldp == 0) + adios (NULL, "no folder specified"); #ifdef WHATNOW - if (!msgs.size && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp) - files[filep++] = cp; + if (!msgs.size && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp) + files[filep++] = cp; #endif /* WHATNOW */ - /* - * We are refiling a file to the folders - */ - if (filep > 0) { - if (folder || msgs.size) - adios (NULL, "use -file or some messages, not both"); + /* + * We are refiling a file to the folders + */ + if (filep > 0) { + if (folder || msgs.size) + adios (NULL, "use -file or some messages, not both"); + opnfolds (folders, foldp); + for (i = 0; i < filep; i++) + if (m_file (files[i], folders, foldp, preserve, 0)) + done (1); + /* If -nolink, then "remove" files */ + if (!linkf) + remove_files (filep, filevec); + done (0); + } + + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + strncpy (maildir, m_maildir (folder), sizeof(maildir)); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read source folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse the message range/sequence/name and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + /* create folder structures for each destination folder */ opnfolds (folders, foldp); - for (i = 0; i < filep; i++) - if (m_file (files[i], folders, foldp, preserve, 0)) - done (1); - /* If -nolink, then "remove" files */ - if (!linkf) - remove_files (filep, filevec); - done (0); - } - - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - strncpy (maildir, m_maildir (folder), sizeof(maildir)); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read source folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse the message range/sequence/name and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - /* create folder structures for each destination folder */ - opnfolds (folders, foldp); - - /* Link all the selected messages into destination folders. - * - * This causes the add hook to be run for messages that are - * linked into another folder. The refile hook is run for - * messages that are moved to another folder. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - cp = getcpy (m_name (msgnum)); - if (m_file (cp, folders, foldp, preserve, !linkf)) - done (1); - free (cp); + + /* Link all the selected messages into destination folders. + * + * This causes the add hook to be run for messages that are + * linked into another folder. The refile hook is run for + * messages that are moved to another folder. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + cp = getcpy (m_name (msgnum)); + if (m_file (cp, folders, foldp, preserve, !linkf)) + done (1); + free (cp); + } } - } - - /* - * This is a hack. If we are using an external rmmproc, - * then save the current folder to the context file, - * so the external rmmproc will remove files from the correct - * directory. This should be moved to folder_delmsgs(). - */ - if (rmmproc) { - context_replace (pfolder, folder); - context_save (); - fflush (stdout); - } - - /* If -nolink, then "remove" messages from source folder. - * - * Note that folder_delmsgs does not call the delete hook - * because the message has already been handled above. - */ - if (!linkf) { - folder_delmsgs (mp, unlink_msgs, 1); - } - - clsfolds (folders, foldp); - - if (mp->hghsel != mp->curmsg - && (mp->numsel != mp->nummsg || linkf)) - seq_setcur (mp, mp->hghsel); - seq_save (mp); /* synchronize message sequences */ - - context_replace (pfolder, folder); /* update current folder */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder structure */ - done (0); - return 1; + + /* + * This is a hack. If we are using an external rmmproc, + * then save the current folder to the context file, + * so the external rmmproc will remove files from the correct + * directory. This should be moved to folder_delmsgs(). + */ + if (rmmproc) { + context_replace (pfolder, folder); + context_save (); + fflush (stdout); + } + + /* If -nolink, then "remove" messages from source folder. + * + * Note that folder_delmsgs does not call the delete hook + * because the message has already been handled above. + */ + if (!linkf) { + folder_delmsgs (mp, unlink_msgs, 1); + } + + clsfolds (folders, foldp); + + if (mp->hghsel != mp->curmsg + && (mp->numsel != mp->nummsg || linkf)) + seq_setcur (mp, mp->hghsel); + seq_save (mp); /* synchronize message sequences */ + + context_replace (pfolder, folder); /* update current folder */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder structure */ + done (0); + return 1; } @@ -277,26 +276,26 @@ main (int argc, char **argv) static void opnfolds (struct st_fold *folders, int nfolders) { - char nmaildir[BUFSIZ]; - register struct st_fold *fp, *ep; - register struct msgs *mp; + char nmaildir[BUFSIZ]; + register struct st_fold *fp, *ep; + register struct msgs *mp; - for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { - chdir (m_maildir ("")); - strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir)); + for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { + chdir (m_maildir ("")); + strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir)); - create_folder (nmaildir, 0, done); + create_folder (nmaildir, 0, done); - if (chdir (nmaildir) == NOTOK) - adios (nmaildir, "unable to change directory to"); - if (!(mp = folder_read (fp->f_name))) - adios (NULL, "unable to read folder %s", fp->f_name); - mp->curmsg = 0; + if (chdir (nmaildir) == NOTOK) + adios (nmaildir, "unable to change directory to"); + if (!(mp = folder_read (fp->f_name))) + adios (NULL, "unable to read folder %s", fp->f_name); + mp->curmsg = 0; - fp->f_mp = mp; + fp->f_mp = mp; - chdir (maildir); - } + chdir (maildir); + } } @@ -308,14 +307,14 @@ opnfolds (struct st_fold *folders, int nfolders) static void clsfolds (struct st_fold *folders, int nfolders) { - register struct st_fold *fp, *ep; - register struct msgs *mp; - - for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { - mp = fp->f_mp; - seq_setprev (mp); - seq_save (mp); - } + register struct st_fold *fp, *ep; + register struct msgs *mp; + + for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { + mp = fp->f_mp; + seq_setprev (mp); + seq_save (mp); + } } @@ -328,26 +327,26 @@ clsfolds (struct st_fold *folders, int nfolders) static void remove_files (int filep, char **files) { - int i; - char **vec; - - /* If rmmproc is defined, we use that */ - if (rmmproc) { - vec = files++; /* vec[0] = filevec[0] */ - files[filep] = NULL; /* NULL terminate list */ - - fflush (stdout); - vec[0] = r1bindex (rmmproc, '/'); - execvp (rmmproc, vec); - adios (rmmproc, "unable to exec"); - } - - /* Else just unlink the files */ - files++; /* advance past filevec[0] */ - for (i = 0; i < filep; i++) { - if (unlink (files[i]) == NOTOK) - admonish (files[i], "unable to unlink"); - } + int i; + char **vec; + + /* If rmmproc is defined, we use that */ + if (rmmproc) { + vec = files++; /* vec[0] = filevec[0] */ + files[filep] = NULL; /* NULL terminate list */ + + fflush (stdout); + vec[0] = r1bindex (rmmproc, '/'); + execvp (rmmproc, vec); + adios (rmmproc, "unable to exec"); + } + + /* Else just unlink the files */ + files++; /* advance past filevec[0] */ + for (i = 0; i < filep; i++) { + if (unlink (files[i]) == NOTOK) + admonish (files[i], "unable to unlink"); + } } @@ -359,12 +358,12 @@ remove_files (int filep, char **files) static int m_file (char *msgfile, struct st_fold *folders, int nfolders, int preserve, int refile) { - int msgnum; - struct st_fold *fp, *ep; - - for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { - if ((msgnum = folder_addmsg (&fp->f_mp, msgfile, 1, 0, preserve, nfolders == 1 && refile, maildir)) == -1) - return 1; - } - return 0; + int msgnum; + struct st_fold *fp, *ep; + + for (fp = folders, ep = folders + nfolders; fp < ep; fp++) { + if ((msgnum = folder_addmsg (&fp->f_mp, msgfile, 1, 0, preserve, nfolders == 1 && refile, maildir)) == -1) + return 1; + } + return 0; } diff --git a/uip/repl.c b/uip/repl.c index d2b75df..7a9384b 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -1,4 +1,3 @@ - /* * repl.c -- reply to a message * @@ -12,117 +11,117 @@ static struct swit switches[] = { -#define GROUPSW 0 - { "group", 0 }, -#define NGROUPSW 1 - { "nogroup", 0 }, -#define ANNOSW 2 - { "annotate", 0 }, -#define NANNOSW 3 - { "noannotate", 0 }, -#define CCSW 4 - { "cc all|to|cc|me", 0 }, -#define NCCSW 5 - { "nocc type", 0 }, -#define DFOLDSW 6 - { "draftfolder +folder", 0 }, -#define DMSGSW 7 - { "draftmessage msg", 0 }, -#define NDFLDSW 8 - { "nodraftfolder", 0 }, -#define EDITRSW 9 - { "editor editor", 0 }, -#define NEDITSW 10 - { "noedit", 0 }, -#define FCCSW 11 - { "fcc folder", 0 }, -#define FILTSW 12 - { "filter filterfile", 0 }, -#define FORMSW 13 - { "form formfile", 0 }, -#define FRMTSW 14 - { "format", 5 }, -#define NFRMTSW 15 - { "noformat", 7 }, -#define INPLSW 16 - { "inplace", 0 }, -#define NINPLSW 17 - { "noinplace", 0 }, -#define MIMESW 18 - { "mime", 0 }, -#define NMIMESW 19 - { "nomime", 0 }, -#define QURYSW 20 - { "query", 0 }, -#define NQURYSW 21 - { "noquery", 0 }, -#define WHATSW 22 - { "whatnowproc program", 0 }, -#define NWHATSW 23 - { "nowhatnowproc", 0 }, -#define WIDTHSW 24 - { "width columns", 0 }, -#define VERSIONSW 25 - { "version", 0 }, -#define HELPSW 26 - { "help", 0 }, -#define FILESW 27 - { "file file", 4 }, /* interface from msh */ +#define GROUPSW 0 + { "group", 0 }, +#define NGROUPSW 1 + { "nogroup", 0 }, +#define ANNOSW 2 + { "annotate", 0 }, +#define NANNOSW 3 + { "noannotate", 0 }, +#define CCSW 4 + { "cc all|to|cc|me", 0 }, +#define NCCSW 5 + { "nocc type", 0 }, +#define DFOLDSW 6 + { "draftfolder +folder", 0 }, +#define DMSGSW 7 + { "draftmessage msg", 0 }, +#define NDFLDSW 8 + { "nodraftfolder", 0 }, +#define EDITRSW 9 + { "editor editor", 0 }, +#define NEDITSW 10 + { "noedit", 0 }, +#define FCCSW 11 + { "fcc folder", 0 }, +#define FILTSW 12 + { "filter filterfile", 0 }, +#define FORMSW 13 + { "form formfile", 0 }, +#define FRMTSW 14 + { "format", 5 }, +#define NFRMTSW 15 + { "noformat", 7 }, +#define INPLSW 16 + { "inplace", 0 }, +#define NINPLSW 17 + { "noinplace", 0 }, +#define MIMESW 18 + { "mime", 0 }, +#define NMIMESW 19 + { "nomime", 0 }, +#define QURYSW 20 + { "query", 0 }, +#define NQURYSW 21 + { "noquery", 0 }, +#define WHATSW 22 + { "whatnowproc program", 0 }, +#define NWHATSW 23 + { "nowhatnowproc", 0 }, +#define WIDTHSW 24 + { "width columns", 0 }, +#define VERSIONSW 25 + { "version", 0 }, +#define HELPSW 26 + { "help", 0 }, +#define FILESW 27 + { "file file", 4 }, /* interface from msh */ #ifdef MHE -#define BILDSW 28 - { "build", 5 }, /* interface from mhe */ +#define BILDSW 28 + { "build", 5 }, /* interface from mhe */ #endif - { NULL, 0 } + { NULL, 0 } }; static struct swit ccswitches[] = { -#define CTOSW 0 - { "to", 0 }, -#define CCCSW 1 - { "cc", 0 }, -#define CMESW 2 - { "me", 0 }, -#define CALSW 3 - { "all", 0 }, - { NULL, 0 } +#define CTOSW 0 + { "to", 0 }, +#define CCCSW 1 + { "cc", 0 }, +#define CMESW 2 + { "me", 0 }, +#define CALSW 3 + { "all", 0 }, + { NULL, 0 } }; static struct swit aqrnl[] = { -#define NOSW 0 - { "quit", 0 }, -#define YESW 1 - { "replace", 0 }, -#define LISTDSW 2 - { "list", 0 }, -#define REFILSW 3 - { "refile +folder", 0 }, -#define NEWSW 4 - { "new", 0 }, - { NULL, 0 } +#define NOSW 0 + { "quit", 0 }, +#define YESW 1 + { "replace", 0 }, +#define LISTDSW 2 + { "list", 0 }, +#define REFILSW 3 + { "refile +folder", 0 }, +#define NEWSW 4 + { "new", 0 }, + { NULL, 0 } }; static struct swit aqrl[] = { - { "quit", 0 }, - { "replace", 0 }, - { "list", 0 }, - { "refile +folder", 0 }, - { NULL, 0 } + { "quit", 0 }, + { "replace", 0 }, + { "list", 0 }, + { "refile +folder", 0 }, + { NULL, 0 } }; -short ccto = -1; /* global for replsbr */ +short ccto = -1; /* global for replsbr */ short cccc = -1; short ccme = -1; short querysw = 0; short outputlinelen = OUTPUTLINELEN; -short groupreply = 0; /* Is this a group reply? */ +short groupreply = 0; /* Is this a group reply? */ -int mime = 0; /* include original as MIME part */ -char *form = NULL; /* form (components) file */ -char *filter = NULL; /* message filter file */ -char *fcc = NULL; /* folders to add to Fcc: header */ +int mime = 0; /* include original as MIME part */ +char *form = NULL; /* form (components) file */ +char *filter = NULL; /* message filter file */ +char *fcc = NULL; /* folders to add to Fcc: header */ /* @@ -134,340 +133,340 @@ void docc (char *, int); int main (int argc, char **argv) { - int i, isdf = 0; - int anot = 0, inplace = 1; - int nedit = 0, nwhat = 0; - char *cp, *cwd, *dp, *maildir, *file = NULL; - char *folder = NULL, *msg = NULL, *dfolder = NULL; - char *dmsg = NULL, *ed = NULL, drft[BUFSIZ], buf[BUFSIZ]; - char **argp, **arguments; - struct msgs *mp = NULL; - struct stat st; - FILE *in; + int i, isdf = 0; + int anot = 0, inplace = 1; + int nedit = 0, nwhat = 0; + char *cp, *cwd, *dp, *maildir, *file = NULL; + char *folder = NULL, *msg = NULL, *dfolder = NULL; + char *dmsg = NULL, *ed = NULL, drft[BUFSIZ], buf[BUFSIZ]; + char **argp, **arguments; + struct msgs *mp = NULL; + struct stat st; + FILE *in; #ifdef MHE - int buildsw = 0; + int buildsw = 0; #endif /* MHE */ #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s: [+folder] [msg] [switches]", - invo_name); - print_help (buf, switches, 1); - done (0); - case VERSIONSW: - print_version(invo_name); - done (1); - - case GROUPSW: - groupreply++; - continue; - case NGROUPSW: - groupreply = 0; - continue; - - case ANNOSW: - anot++; - continue; - case NANNOSW: - anot = 0; - continue; - - case CCSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - docc (cp, 1); - continue; - case NCCSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - docc (cp, 0); - continue; - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; - continue; - - case WHATSW: - if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; - continue; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s: [+folder] [msg] [switches]", + invo_name); + print_help (buf, switches, 1); + done (0); + case VERSIONSW: + print_version(invo_name); + done (1); + + case GROUPSW: + groupreply++; + continue; + case NGROUPSW: + groupreply = 0; + continue; + + case ANNOSW: + anot++; + continue; + case NANNOSW: + anot = 0; + continue; + + case CCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + docc (cp, 1); + continue; + case NCCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + docc (cp, 0); + continue; + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nedit = 0; + continue; + case NEDITSW: + nedit++; + continue; + + case WHATSW: + if (!(whatnowproc = *argp++) || *whatnowproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nwhat = 0; + continue; #ifdef MHE - case BILDSW: - buildsw++; /* fall... */ + case BILDSW: + buildsw++; /* fall... */ #endif /* MHE */ - case NWHATSW: - nwhat++; - continue; - - case FCCSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dp = NULL; - if (*cp == '@') - cp = dp = path (cp + 1, TSUBCWF); - if (fcc) - fcc = add (", ", fcc); - fcc = add (cp, fcc); - if (dp) - free (dp); - continue; - - case FILESW: - if (file) - adios (NULL, "only one file at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); - continue; - case FILTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); - mime = 0; - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case FRMTSW: - filter = getcpy (etcpath (mhlreply)); - mime = 0; - continue; - case NFRMTSW: - filter = NULL; - continue; - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case MIMESW: - mime++; - filter = NULL; - continue; - case NMIMESW: - mime = 0; - continue; - - case QURYSW: - querysw++; - continue; - case NQURYSW: - querysw = 0; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((outputlinelen = atoi (cp)) < 10) - adios (NULL, "impossible width %d", outputlinelen); - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - if (msg) - adios (NULL, "only one message at a time!"); - else - msg = cp; + case NWHATSW: + nwhat++; + continue; + + case FCCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dp = NULL; + if (*cp == '@') + cp = dp = path (cp + 1, TSUBCWF); + if (fcc) + fcc = add (", ", fcc); + fcc = add (cp, fcc); + if (dp) + free (dp); + continue; + + case FILESW: + if (file) + adios (NULL, "only one file at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + file = path (cp, TFILE); + continue; + case FILTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + filter = getcpy (etcpath (cp)); + mime = 0; + continue; + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case FRMTSW: + filter = getcpy (etcpath (mhlreply)); + mime = 0; + continue; + case NFRMTSW: + filter = NULL; + continue; + + case INPLSW: + inplace++; + continue; + case NINPLSW: + inplace = 0; + continue; + + case MIMESW: + mime++; + filter = NULL; + continue; + case NMIMESW: + mime = 0; + continue; + + case QURYSW: + querysw++; + continue; + case NQURYSW: + querysw = 0; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((outputlinelen = atoi (cp)) < 10) + adios (NULL, "impossible width %d", outputlinelen); + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (dmsg) + adios (NULL, "only one draft message at a time!"); + if (!(dmsg = *argp++) || *dmsg == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + if (msg) + adios (NULL, "only one message at a time!"); + else + msg = cp; + } } - } - if (ccto == -1) - ccto = groupreply; - if (cccc == -1) - cccc = groupreply; - if (ccme == -1) - ccme = groupreply; + if (ccto == -1) + ccto = groupreply; + if (cccc == -1) + cccc = groupreply; + if (ccme == -1) + ccme = groupreply; - cwd = getcpy (pwd ()); + cwd = getcpy (pwd ()); - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (file && (msg || folder)) - adios (NULL, "can't mix files and folders/msgs"); + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (file && (msg || folder)) + adios (NULL, "can't mix files and folders/msgs"); try_it_again: #ifdef MHE - strncpy (drft, buildsw ? m_maildir ("reply") - : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft)); + strncpy (drft, buildsw ? m_maildir ("reply") + : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft)); - /* Check if a draft exists */ - if (!buildsw && stat (drft, &st) != NOTOK) { + /* Check if a draft exists */ + if (!buildsw && stat (drft, &st) != NOTOK) { #else - strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); + strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); - /* Check if a draft exists */ - if (stat (drft, &st) != NOTOK) { + /* Check if a draft exists */ + if (stat (drft, &st) != NOTOK) { #endif /* MHE */ - printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); - for (i = LISTDSW; i != YESW;) { - if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) - done (1); - switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { - case NOSW: - done (0); - case NEWSW: - dmsg = NULL; - goto try_it_again; - case YESW: - break; - case LISTDSW: - showfile (++argp, drft); - break; - case REFILSW: - if (refile (++argp, drft) == 0) - i = YESW; - break; - default: - advise (NULL, "say what?"); - break; - } + printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); + for (i = LISTDSW; i != YESW;) { + if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) + done (1); + switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { + case NOSW: + done (0); + case NEWSW: + dmsg = NULL; + goto try_it_again; + case YESW: + break; + case LISTDSW: + showfile (++argp, drft); + break; + case REFILSW: + if (refile (++argp, drft) == 0) + i = YESW; + break; + default: + advise (NULL, "say what?"); + break; + } + } } - } - - if (file) { - /* - * We are replying to a file. - */ - anot = 0; /* we don't want to annotate a file */ - } else { - /* - * We are replying to a message. - */ - if (!msg) - msg = "cur"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse the message range/sequence/name and set SELECTED */ - if (!m_convert (mp, msg)) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - if (mp->numsel > 1) - adios (NULL, "only one message at a time!"); - - context_replace (pfolder, folder); /* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - msg = file ? file : getcpy (m_name (mp->lowsel)); - - if ((in = fopen (msg, "r")) == NULL) - adios (msg, "unable to open"); - - /* find form (components) file */ - if (!form) { - if (groupreply) - form = etcpath (replgroupcomps); - else - form = etcpath (replcomps); - } - - replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc); - fclose (in); - - if (nwhat) - done (0); - what_now (ed, nedit, NOUSE, drft, msg, 0, mp, - anot ? "Replied" : NULL, inplace, cwd); - done (1); - return 1; + + if (file) { + /* + * We are replying to a file. + */ + anot = 0; /* we don't want to annotate a file */ + } else { + /* + * We are replying to a message. + */ + if (!msg) + msg = "cur"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse the message range/sequence/name and set SELECTED */ + if (!m_convert (mp, msg)) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + if (mp->numsel > 1) + adios (NULL, "only one message at a time!"); + + context_replace (pfolder, folder); /* update current folder */ + seq_setcur (mp, mp->lowsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_save (); /* save the context file */ + } + + msg = file ? file : getcpy (m_name (mp->lowsel)); + + if ((in = fopen (msg, "r")) == NULL) + adios (msg, "unable to open"); + + /* find form (components) file */ + if (!form) { + if (groupreply) + form = etcpath (replgroupcomps); + else + form = etcpath (replcomps); + } + + replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc); + fclose (in); + + if (nwhat) + done (0); + what_now (ed, nedit, NOUSE, drft, msg, 0, mp, + anot ? "Replied" : NULL, inplace, cwd); + done (1); + return 1; } void docc (char *cp, int ccflag) { - switch (smatch (cp, ccswitches)) { - case AMBIGSW: - ambigsw (cp, ccswitches); - done (1); - case UNKWNSW: - adios (NULL, "-%scc %s unknown", ccflag ? "" : "no", cp); - - case CTOSW: - ccto = ccflag; - break; - - case CCCSW: - cccc = ccflag; - break; - - case CMESW: - ccme = ccflag; - break; - - case CALSW: - ccto = cccc = ccme = ccflag; - break; - } + switch (smatch (cp, ccswitches)) { + case AMBIGSW: + ambigsw (cp, ccswitches); + done (1); + case UNKWNSW: + adios (NULL, "-%scc %s unknown", ccflag ? "" : "no", cp); + + case CTOSW: + ccto = ccflag; + break; + + case CCCSW: + cccc = ccflag; + break; + + case CMESW: + ccme = ccflag; + break; + + case CALSW: + ccto = cccc = ccme = ccflag; + break; + } } diff --git a/uip/replsbr.c b/uip/replsbr.c index ec140d6..add1371 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -1,4 +1,3 @@ - /* * replsbr.c -- routines to help repl along... * @@ -11,10 +10,10 @@ #include #include #include -#include /* L_SET */ +#include /* L_SET */ #include -extern short ccto; /* from repl.c */ +extern short ccto; /* from repl.c */ extern short cccc; extern short ccme; extern short querysw; @@ -33,30 +32,30 @@ static struct mailname mq = { NULL }; * small enough so that we don't snarf the entire * message body when we're not going to use any of it. */ -#define SBUFSIZ 256 +#define SBUFSIZ 256 static struct format *fmt; -static int ncomps = 0; /* # of interesting components */ -static char **compbuffers = NULL; /* buffers for component text */ -static struct comp **used_buf = NULL; /* stack for comp that use buffers */ +static int ncomps = 0; /* # of interesting components */ +static char **compbuffers = NULL; /* buffers for component text */ +static struct comp **used_buf = NULL; /* stack for comp that use buffers */ -static int dat[5]; /* aux. data for format routine */ +static int dat[5]; /* aux. data for format routine */ static char *addrcomps[] = { - "from", - "sender", - "reply-to", - "to", - "cc", - "bcc", - "resent-from", - "resent-sender", - "resent-reply-to", - "resent-to", - "resent-cc", - "resent-bcc", - NULL + "from", + "sender", + "reply-to", + "to", + "cc", + "bcc", + "resent-from", + "resent-sender", + "resent-reply-to", + "resent-to", + "resent-cc", + "resent-bcc", + NULL }; /* @@ -70,216 +69,218 @@ void replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, int mime, char *form, char *filter, char *fcc) { - register int state, i; - register struct comp *cptr; - register char *tmpbuf; - register char **nxtbuf; - register char **ap; - register struct comp **savecomp; - int char_read = 0, format_len, mask; - char name[NAMESZ], *scanl; - unsigned char *cp; - FILE *out; - - mask = umask(~m_gmprot()); - if ((out = fopen (drft, "w")) == NULL) - adios (drft, "unable to create"); - - umask(mask); - - /* get new format string */ - cp = new_fs (form, NULL, NULL); - format_len = strlen (cp); - - /* compile format string */ - ncomps = fmt_compile (cp, &fmt) + 1; - - if (!(nxtbuf = compbuffers = (char **) - calloc((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); - if (!(savecomp = used_buf = (struct comp **) - calloc((size_t) (ncomps+1), sizeof(struct comp *)))) - adios (NULL, "unable to allocate component buffer stack"); - savecomp += ncomps + 1; - *--savecomp = NULL; /* point at zero'd end minus 1 */ - - for (i = ncomps; i--; ) - *nxtbuf++ = mh_xmalloc(SBUFSIZ); - - nxtbuf = compbuffers; /* point at start */ - tmpbuf = *nxtbuf++; - - for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); - if (cptr) - cptr->c_type |= CT_ADDR; - } - - /* - * ignore any components killed by command line switches - */ - if (!ccto) { - FINDCOMP (cptr, "to"); - if (cptr) - cptr->c_name = ""; - } - if (!cccc) { - FINDCOMP (cptr, "cc"); - if (cptr) - cptr->c_name = ""; - } - /* set up the "fcc" pseudo-component */ - if (fcc) { - FINDCOMP (cptr, "fcc"); - if (cptr) - cptr->c_text = getcpy (fcc); - } - if ((cp = getenv("USER"))) { - FINDCOMP (cptr, "user"); - if (cptr) - cptr->c_text = getcpy(cp); - } - if (!ccme) - ismymbox (NULL); - - /* - * pick any interesting stuff out of msg "inb" - */ - for (state = FLD;;) { - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); - switch (state) { - case FLD: - case FLDPLUS: - /* - * if we're interested in this component, save a pointer - * to the component text, then start using our next free - * buffer as the component temp buffer (buffer switching - * saves an extra copy of the component text). - */ - if ((cptr = wantcomp[CHASH(name)])) - do { - if (!mh_strcasecmp(name, cptr->c_name)) { - char_read += msg_count; - if (! cptr->c_text) { - i = strlen(cptr->c_text = tmpbuf) - 1; - if (tmpbuf[i] == '\n') - tmpbuf[i] = '\0'; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } else { - i = strlen (cp = cptr->c_text) - 1; - if (cp[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cp[i] = '\0'; - cp = add (",\n\t", cp); - } else { - cp = add ("\t", cp); - } - } - cptr->c_text = add (tmpbuf, cp); - } - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, - SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); - char_read += msg_count; - } - break; - } - } while ((cptr = cptr->c_next)); - - while (state == FLDPLUS) - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); - break; - - case LENERR: - case FMTERR: - case BODY: - case FILEEOF: - goto finished; + register int state, i; + register struct comp *cptr; + register char *tmpbuf; + register char **nxtbuf; + register char **ap; + register struct comp **savecomp; + int char_read = 0, format_len, mask; + char name[NAMESZ], *scanl; + unsigned char *cp; + FILE *out; + + mask = umask(~m_gmprot()); + if ((out = fopen (drft, "w")) == NULL) + adios (drft, "unable to create"); + + umask(mask); + + /* get new format string */ + cp = new_fs (form, NULL, NULL); + format_len = strlen (cp); + + /* compile format string */ + ncomps = fmt_compile (cp, &fmt) + 1; + + if (!(nxtbuf = compbuffers = (char **) + calloc((size_t) ncomps, sizeof(char *)))) + adios (NULL, "unable to allocate component buffers"); + if (!(savecomp = used_buf = (struct comp **) + calloc((size_t) (ncomps+1), sizeof(struct comp *)))) + adios (NULL, "unable to allocate component buffer stack"); + savecomp += ncomps + 1; + *--savecomp = NULL; /* point at zero'd end minus 1 */ + + for (i = ncomps; i--; ) + *nxtbuf++ = mh_xmalloc(SBUFSIZ); + + nxtbuf = compbuffers; /* point at start */ + tmpbuf = *nxtbuf++; + + for (ap = addrcomps; *ap; ap++) { + FINDCOMP (cptr, *ap); + if (cptr) + cptr->c_type |= CT_ADDR; + } - default: - adios (NULL, "m_getfld() returned %d", state); + /* + * ignore any components killed by command line switches + */ + if (!ccto) { + FINDCOMP (cptr, "to"); + if (cptr) + cptr->c_name = ""; + } + if (!cccc) { + FINDCOMP (cptr, "cc"); + if (cptr) + cptr->c_name = ""; + } + /* set up the "fcc" pseudo-component */ + if (fcc) { + FINDCOMP (cptr, "fcc"); + if (cptr) + cptr->c_text = getcpy (fcc); + } + if ((cp = getenv("USER"))) { + FINDCOMP (cptr, "user"); + if (cptr) + cptr->c_text = getcpy(cp); + } + if (!ccme) + ismymbox (NULL); + + /* + * pick any interesting stuff out of msg "inb" + */ + for (state = FLD;;) { + state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + switch (state) { + case FLD: + case FLDPLUS: + /* + * if we're interested in this component, + * save a pointer to the component text, + * then start using our next free buffer + * as the component temp buffer (buffer + * switching saves an extra copy of the + * component text). + */ + if ((cptr = wantcomp[CHASH(name)])) + do { + if (!mh_strcasecmp(name, cptr->c_name)) { + char_read += msg_count; + if (! cptr->c_text) { + i = strlen(cptr->c_text = tmpbuf) - 1; + if (tmpbuf[i] == '\n') + tmpbuf[i] = '\0'; + *--savecomp = cptr; + tmpbuf = *nxtbuf++; + } else { + i = strlen (cp = cptr->c_text) - 1; + if (cp[i] == '\n') { + if (cptr->c_type & CT_ADDR) { + cp[i] = '\0'; + cp = add (",\n\t", cp); + } else { + cp = add ("\t", cp); + } + } + cptr->c_text = add (tmpbuf, cp); + } + while (state == FLDPLUS) { + state = m_getfld (state, name, tmpbuf, + SBUFSIZ, inb); + cptr->c_text = add (tmpbuf, cptr->c_text); + char_read += msg_count; + } + break; + } + } while ((cptr = cptr->c_next)); + + while (state == FLDPLUS) + state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + break; + + case LENERR: + case FMTERR: + case BODY: + case FILEEOF: + goto finished; + + default: + adios (NULL, "m_getfld() returned %d", state); + } } - } - /* - * format and output the header lines. - */ + /* + * format and output the header lines. + */ finished: - /* - * if there's a "Subject" component, strip any "Re:"s off it - */ - FINDCOMP (cptr, "subject") - if (cptr && (cp = cptr->c_text)) { - register char *sp = cp; - - for (;;) { - while (isspace(*cp)) - cp++; - if(uprf(cp, "re:")) - cp += 3; - else - break; - sp = cp; + /* + * if there's a "Subject" component, strip any "Re:"s off it + */ + FINDCOMP (cptr, "subject") + if (cptr && (cp = cptr->c_text)) { + register char *sp = cp; + + for (;;) { + while (isspace(*cp)) + cp++; + if(uprf(cp, "re:")) + cp += 3; + else + break; + sp = cp; + } + if (sp != cptr->c_text) { + cp = cptr->c_text; + cptr->c_text = getcpy (sp); + free (cp); + } } - if (sp != cptr->c_text) { - cp = cptr->c_text; - cptr->c_text = getcpy (sp); - free (cp); + i = format_len + char_read + 256; + scanl = mh_xmalloc ((size_t) i + 2); + dat[0] = 0; + dat[1] = 0; + dat[2] = 0; + dat[3] = outputlinelen; + dat[4] = 0; + fmt_scan (fmt, scanl, i, dat); + fputs (scanl, out); + if (badaddrs) { + fputs ("\nrepl: bad addresses:\n", out); + fputs ( badaddrs, out); } - } - i = format_len + char_read + 256; - scanl = mh_xmalloc ((size_t) i + 2); - dat[0] = 0; - dat[1] = 0; - dat[2] = 0; - dat[3] = outputlinelen; - dat[4] = 0; - fmt_scan (fmt, scanl, i, dat); - fputs (scanl, out); - if (badaddrs) { - fputs ("\nrepl: bad addresses:\n", out); - fputs ( badaddrs, out); - } - - /* - * Check if we should filter the message - * or add mhbuild directives - */ - if (filter) { + + /* + * Check if we should filter the message + * or add mhbuild directives + */ + if (filter) { + fflush(out); + if (ferror (out)) + adios (drft, "error writing"); + + replfilter (inb, out, filter); + } else if (mime && mp) { + fprintf (out, "#forw [original message] +%s %s\n", + mp->foldpath, m_name (mp->lowsel)); + } + fflush(out); if (ferror (out)) - adios (drft, "error writing"); - - replfilter (inb, out, filter); - } else if (mime && mp) { - fprintf (out, "#forw [original message] +%s %s\n", - mp->foldpath, m_name (mp->lowsel)); - } - - fflush(out); - if (ferror (out)) - adios (drft, "error writing"); - fclose (out); - - /* return dynamically allocated buffers */ - free (scanl); - for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ - while ( i-- > 0) - free (*nxtbuf++); /* free unused nxtbufs */ - free ((char *) compbuffers); - free ((char *) used_buf); + adios (drft, "error writing"); + fclose (out); + + /* return dynamically allocated buffers */ + free (scanl); + for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) + free (cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ + while ( i-- > 0) + free (*nxtbuf++); /* free unused nxtbufs */ + free ((char *) compbuffers); + free ((char *) used_buf); } -static char *buf; /* our current working buffer */ -static char *bufend; /* end of working buffer */ -static char *last_dst; /* buf ptr at end of last call */ -static unsigned int bufsiz=0; /* current size of buf */ +static char *buf; /* our current working buffer */ +static char *bufend; /* end of working buffer */ +static char *last_dst; /* buf ptr at end of last call */ +static unsigned int bufsiz=0; /* current size of buf */ -#define BUFINCR 512 /* how much to expand buf when if fills */ +#define BUFINCR 512 /* how much to expand buf when if fills */ #define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; } @@ -288,7 +289,7 @@ static unsigned int bufsiz=0; /* current size of buf */ * add more mem if needed */ #define CHECKMEM(str) \ - if ((len = strlen (str)) >= bufend - dst) {\ + if ((len = strlen (str)) >= bufend - dst) {\ int i = dst - buf;\ int n = last_dst - buf;\ bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\ @@ -296,7 +297,7 @@ static unsigned int bufsiz=0; /* current size of buf */ dst = buf + i;\ last_dst = buf + n;\ bufend = buf + bufsiz;\ - } + } /* @@ -313,103 +314,103 @@ static unsigned int bufsiz=0; /* current size of buf */ char * formataddr (char *orig, char *str) { - register int len; - char baddr[BUFSIZ], error[BUFSIZ]; - register int isgroup; - register char *dst; - register char *cp; - register char *sp; - register struct mailname *mp = NULL; - - /* if we don't have a buffer yet, get one */ - if (bufsiz == 0) { - buf = mh_xmalloc (BUFINCR); - last_dst = buf; /* XXX */ - bufsiz = BUFINCR - 6; /* leave some slop */ - bufend = buf + bufsiz; - } - /* - * If "orig" points to our buffer we can just pick up where we - * left off. Otherwise we have to copy orig into our buffer. - */ - if (orig == buf) - dst = last_dst; - else if (!orig || !*orig) { - dst = buf; - *dst = '\0'; - } else { - dst = last_dst; /* XXX */ - CHECKMEM (orig); - CPY (orig); - } - - /* concatenate all the new addresses onto 'buf' */ - for (isgroup = 0; (cp = getname (str)); ) { - if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) { - snprintf (baddr, sizeof(baddr), "\t%s -- %s\n", cp, error); - badaddrs = add (baddr, badaddrs); - continue; + register int len; + char baddr[BUFSIZ], error[BUFSIZ]; + register int isgroup; + register char *dst; + register char *cp; + register char *sp; + register struct mailname *mp = NULL; + + /* if we don't have a buffer yet, get one */ + if (bufsiz == 0) { + buf = mh_xmalloc (BUFINCR); + last_dst = buf; /* XXX */ + bufsiz = BUFINCR - 6; /* leave some slop */ + bufend = buf + bufsiz; } - if (isgroup && (mp->m_gname || !mp->m_ingrp)) { - *dst++ = ';'; - isgroup = 0; + /* + * If "orig" points to our buffer we can just pick up where we + * left off. Otherwise we have to copy orig into our buffer. + */ + if (orig == buf) + dst = last_dst; + else if (!orig || !*orig) { + dst = buf; + *dst = '\0'; + } else { + dst = last_dst; /* XXX */ + CHECKMEM (orig); + CPY (orig); } - if (insert (mp)) { - /* if we get here we're going to add an address */ - if (dst != buf) { - *dst++ = ','; - *dst++ = ' '; - } - if (mp->m_gname) { - CHECKMEM (mp->m_gname); - CPY (mp->m_gname); - isgroup++; - } - sp = adrformat (mp); - CHECKMEM (sp); - CPY (sp); + + /* concatenate all the new addresses onto 'buf' */ + for (isgroup = 0; (cp = getname (str)); ) { + if ((mp = getm (cp, dfhost, dftype, AD_NAME, error)) == NULL) { + snprintf (baddr, sizeof(baddr), "\t%s -- %s\n", cp, error); + badaddrs = add (baddr, badaddrs); + continue; + } + if (isgroup && (mp->m_gname || !mp->m_ingrp)) { + *dst++ = ';'; + isgroup = 0; + } + if (insert (mp)) { + /* if we get here we're going to add an address */ + if (dst != buf) { + *dst++ = ','; + *dst++ = ' '; + } + if (mp->m_gname) { + CHECKMEM (mp->m_gname); + CPY (mp->m_gname); + isgroup++; + } + sp = adrformat (mp); + CHECKMEM (sp); + CPY (sp); + } } - } - if (isgroup) - *dst++ = ';'; + if (isgroup) + *dst++ = ';'; - *dst = '\0'; - last_dst = dst; - return (buf); + *dst = '\0'; + last_dst = dst; + return (buf); } static int insert (struct mailname *np) { - char buffer[BUFSIZ]; - register struct mailname *mp; - - if (np->m_mbox == NULL) - return 0; - - for (mp = &mq; mp->m_next; mp = mp->m_next) { - if (!mh_strcasecmp (np->m_host, mp->m_next->m_host) - && !mh_strcasecmp (np->m_mbox, mp->m_next->m_mbox)) - return 0; - } - if (!ccme && ismymbox (np)) - return 0; - - if (querysw) { - snprintf (buffer, sizeof(buffer), "Reply to %s? ", adrformat (np)); - if (!gans (buffer, anoyes)) - return 0; - } - mp->m_next = np; + char buffer[BUFSIZ]; + register struct mailname *mp; + + if (np->m_mbox == NULL) + return 0; + + for (mp = &mq; mp->m_next; mp = mp->m_next) { + if (!mh_strcasecmp (np->m_host, mp->m_next->m_host) + && !mh_strcasecmp (np->m_mbox, mp->m_next->m_mbox)) + return 0; + } + if (!ccme && ismymbox (np)) + return 0; + + if (querysw) { + snprintf (buffer, sizeof(buffer), "Reply to %s? ", adrformat (np)); + if (!gans (buffer, anoyes)) + return 0; + } + mp->m_next = np; #ifdef ISI - if (ismymbox (np)) - ccme = 0; + if (ismymbox (np)) + ccme = 0; #endif - return 1; + return 1; } @@ -422,43 +423,43 @@ insert (struct mailname *np) static void replfilter (FILE *in, FILE *out, char *filter) { - int pid; - char *mhl; - char *errstr; - - if (filter == NULL) - return; - - if (access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); - - mhl = r1bindex (mhlproc, '/'); - - rewind (in); - lseek (fileno(in), (off_t) 0, SEEK_SET); - - switch (pid = vfork ()) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - dup2 (fileno (in), fileno (stdin)); - dup2 (fileno (out), fileno (stdout)); - closefds (3); - - execlp (mhlproc, mhl, "-form", filter, "-noclear", NULL); - errstr = strerror(errno); - write(2, "unable to exec ", 15); - write(2, mhlproc, strlen(mhlproc)); - write(2, ": ", 2); - write(2, errstr, strlen(errstr)); - write(2, "\n", 1); - _exit (-1); - - default: - if (pidXwait (pid, mhl)) - done (1); - fseek (out, 0L, SEEK_END); - break; - } + int pid; + char *mhl; + char *errstr; + + if (filter == NULL) + return; + + if (access (filter, R_OK) == NOTOK) + adios (filter, "unable to read"); + + mhl = r1bindex (mhlproc, '/'); + + rewind (in); + lseek (fileno(in), (off_t) 0, SEEK_SET); + + switch (pid = vfork ()) { + case NOTOK: + adios ("fork", "unable to"); + + case OK: + dup2 (fileno (in), fileno (stdin)); + dup2 (fileno (out), fileno (stdout)); + closefds (3); + + execlp (mhlproc, mhl, "-form", filter, "-noclear", NULL); + errstr = strerror(errno); + write(2, "unable to exec ", 15); + write(2, mhlproc, strlen(mhlproc)); + write(2, ": ", 2); + write(2, errstr, strlen(errstr)); + write(2, "\n", 1); + _exit (-1); + + default: + if (pidXwait (pid, mhl)) + done (1); + fseek (out, 0L, SEEK_END); + break; + } } diff --git a/uip/rmf.c b/uip/rmf.c index 12473f8..a53fe4c 100644 --- a/uip/rmf.c +++ b/uip/rmf.c @@ -1,4 +1,3 @@ - /* * rmf.c -- remove a folder * @@ -10,15 +9,15 @@ #include static struct swit switches[] = { -#define INTRSW 0 - { "interactive", 0 }, -#define NINTRSW 1 - { "nointeractive", 0 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } +#define INTRSW 0 + { "interactive", 0 }, +#define NINTRSW 1 + { "nointeractive", 0 }, +#define VERSIONSW 2 + { "version", 0 }, +#define HELPSW 3 + { "help", 0 }, + { NULL, 0 } }; /* @@ -31,185 +30,185 @@ static void rma (char *); int main (int argc, char **argv) { - int defolder = 0, interactive = -1; - char *cp, *folder = NULL, newfolder[BUFSIZ]; - char buf[BUFSIZ], **argp, **arguments; + int defolder = 0, interactive = -1; + char *cp, *folder = NULL, newfolder[BUFSIZ]; + char buf[BUFSIZ], **argp, **arguments; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case INTRSW: - interactive = 1; - continue; - case NINTRSW: - interactive = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case INTRSW: + interactive = 1; + continue; + case NINTRSW: + interactive = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + adios (NULL, "usage: %s [+folder] [switches]", invo_name); + } + } + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!folder) { + folder = getfolder (1); + defolder++; } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + if (strcmp (m_mailpath (folder), pwd ()) == 0) + adios (NULL, "sorry, you can't remove the current working directory"); + + if (interactive == -1) + interactive = defolder; + + if (strchr (folder, '/') && (*folder != '/') && (*folder != '.')) { + for (cp = copy (folder, newfolder); cp > newfolder && *cp != '/'; cp--) + continue; + if (cp > newfolder) + *cp = '\0'; + else + strncpy (newfolder, getfolder(0), sizeof(newfolder)); } else { - adios (NULL, "usage: %s [+folder] [switches]", invo_name); + strncpy (newfolder, getfolder(0), sizeof(newfolder)); + } + + if (interactive) { + cp = concat ("Remove folder \"", folder, "\"? ", NULL); + if (!getanswer (cp)) + done (0); + free (cp); } - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!folder) { - folder = getfolder (1); - defolder++; - } - if (strcmp (m_mailpath (folder), pwd ()) == 0) - adios (NULL, "sorry, you can't remove the current working directory"); - - if (interactive == -1) - interactive = defolder; - - if (strchr (folder, '/') && (*folder != '/') && (*folder != '.')) { - for (cp = copy (folder, newfolder); cp > newfolder && *cp != '/'; cp--) - continue; - if (cp > newfolder) - *cp = '\0'; - else - strncpy (newfolder, getfolder(0), sizeof(newfolder)); - } else { - strncpy (newfolder, getfolder(0), sizeof(newfolder)); - } - - if (interactive) { - cp = concat ("Remove folder \"", folder, "\"? ", NULL); - if (!getanswer (cp)) - done (0); - free (cp); - } - - if (rmf (folder) == OK) { - char *cfolder = context_find(pfolder); - if (cfolder && strcmp (cfolder, newfolder)) { - printf ("[+%s now current]\n", newfolder); - context_replace (pfolder, newfolder); /* update current folder */ + + if (rmf (folder) == OK) { + char *cfolder = context_find(pfolder); + if (cfolder && strcmp (cfolder, newfolder)) { + printf ("[+%s now current]\n", newfolder); + context_replace (pfolder, newfolder); /* update current folder */ + } } - } - context_save (); /* save the context file */ - done (0); - return 1; + context_save (); /* save the context file */ + done (0); + return 1; } static int rmf (char *folder) { - int i, j, others; - register char *maildir; - char cur[BUFSIZ]; - register struct dirent *dp; - register DIR *dd; - - switch (i = chdir (maildir = m_maildir (folder))) { - case OK: - if (access (".", W_OK) != NOTOK && access ("..", W_OK) != NOTOK) - break; /* fall otherwise */ - - case NOTOK: - snprintf (cur, sizeof(cur), "atr-%s-%s", - current, m_mailpath (folder)); - if (!context_del (cur)) { - printf ("[+%s de-referenced]\n", folder); - return OK; - } - advise (NULL, "you have no profile entry for the %s folder +%s", - i == NOTOK ? "unreadable" : "read-only", folder); - return NOTOK; - } - - if ((dd = opendir (".")) == NULL) - adios (NULL, "unable to read folder +%s", folder); - others = 0; - - /* - * Run the external delete hook program. - */ - - (void)ext_hook("del-hook", maildir, (char *)0); - - j = strlen(backup_prefix); - while ((dp = readdir (dd))) { - switch (dp->d_name[0]) { - case '.': - if (strcmp (dp->d_name, ".") == 0 - || strcmp (dp->d_name, "..") == 0) - continue; /* else fall */ - - case ',': + int i, j, others; + register char *maildir; + char cur[BUFSIZ]; + register struct dirent *dp; + register DIR *dd; + + switch (i = chdir (maildir = m_maildir (folder))) { + case OK: + if (access (".", W_OK) != NOTOK && access ("..", W_OK) != NOTOK) + break; /* fall otherwise */ + + case NOTOK: + snprintf (cur, sizeof(cur), "atr-%s-%s", + current, m_mailpath (folder)); + if (!context_del (cur)) { + printf ("[+%s de-referenced]\n", folder); + return OK; + } + advise (NULL, "you have no profile entry for the %s folder +%s", + i == NOTOK ? "unreadable" : "read-only", folder); + return NOTOK; + } + + if ((dd = opendir (".")) == NULL) + adios (NULL, "unable to read folder +%s", folder); + others = 0; + + /* + * Run the external delete hook program. + */ + + (void)ext_hook("del-hook", maildir, (char *)0); + + j = strlen(backup_prefix); + while ((dp = readdir (dd))) { + switch (dp->d_name[0]) { + case '.': + if (strcmp (dp->d_name, ".") == 0 + || strcmp (dp->d_name, "..") == 0) + continue; /* else fall */ + + case ',': #ifdef MHE - case '+': + case '+': #endif /* MHE */ #ifdef UCI - case '_': - case '#': + case '_': + case '#': #endif /* UCI */ - break; - - default: - if (m_atoi (dp->d_name)) - break; - if (strcmp (dp->d_name, altmsglink) == 0 - || strncmp (dp->d_name, backup_prefix, j) == 0) - break; - - admonish (NULL, "file \"%s/%s\" not deleted", - folder, dp->d_name); - others++; - continue; - } - if (unlink (dp->d_name) == NOTOK) { - admonish (dp->d_name, "unable to unlink %s:", folder); - others++; + break; + + default: + if (m_atoi (dp->d_name)) + break; + if (strcmp (dp->d_name, altmsglink) == 0 + || strncmp (dp->d_name, backup_prefix, j) == 0) + break; + + admonish (NULL, "file \"%s/%s\" not deleted", + folder, dp->d_name); + others++; + continue; + } + if (unlink (dp->d_name) == NOTOK) { + admonish (dp->d_name, "unable to unlink %s:", folder); + others++; + } } - } - closedir (dd); + closedir (dd); - /* - * Remove any relevant private sequences - * or attributes from context file. - */ - rma (folder); + /* + * Remove any relevant private sequences + * or attributes from context file. + */ + rma (folder); - chdir (".."); - if (others == 0 && remdir (maildir)) - return OK; + chdir (".."); + if (others == 0 && remdir (maildir)) + return OK; - advise (NULL, "folder +%s not removed", folder); - return NOTOK; + advise (NULL, "folder +%s not removed", folder); + return NOTOK; } @@ -221,33 +220,33 @@ rmf (char *folder) static void rma (char *folder) { - register int alen, j, plen; - register char *cp; - register struct node *np, *pp; - - alen = strlen ("atr-"); - plen = strlen (cp = m_mailpath (folder)) + 1; - - /* - * Search context list for keys that look like - * "atr-something-folderpath", and remove them. - */ - for (np = m_defs, pp = NULL; np; np = np->n_next) { - if (ssequal ("atr-", np->n_name) - && (j = strlen (np->n_name) - plen) > alen - && *(np->n_name + j) == '-' - && strcmp (cp, np->n_name + j + 1) == 0) { - if (!np->n_context) - admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name); - if (pp) { - pp->n_next = np->n_next; - np = pp; - } else { - m_defs = np->n_next; - } - ctxflags |= CTXMOD; - } else { - pp = np; + register int alen, j, plen; + register char *cp; + register struct node *np, *pp; + + alen = strlen ("atr-"); + plen = strlen (cp = m_mailpath (folder)) + 1; + + /* + * Search context list for keys that look like + * "atr-something-folderpath", and remove them. + */ + for (np = m_defs, pp = NULL; np; np = np->n_next) { + if (ssequal ("atr-", np->n_name) + && (j = strlen (np->n_name) - plen) > alen + && *(np->n_name + j) == '-' + && strcmp (cp, np->n_name + j + 1) == 0) { + if (!np->n_context) + admonish (NULL, "bug: context_del(key=\"%s\")", np->n_name); + if (pp) { + pp->n_next = np->n_next; + np = pp; + } else { + m_defs = np->n_next; + } + ctxflags |= CTXMOD; + } else { + pp = np; + } } - } } diff --git a/uip/rmm.c b/uip/rmm.c index 7680008..53103fd 100644 --- a/uip/rmm.c +++ b/uip/rmm.c @@ -1,4 +1,3 @@ - /* * rmm.c -- remove a message(s) * @@ -11,120 +10,120 @@ #include static struct swit switches[] = { -#define UNLINKSW 0 - { "unlink", 0 }, -#define NUNLINKSW 1 - { "nounlink", 0 }, -#define VERSIONSW 2 - { "version", 0 }, -#define HELPSW 3 - { "help", 0 }, - { NULL, 0 } +#define UNLINKSW 0 + { "unlink", 0 }, +#define NUNLINKSW 1 + { "nounlink", 0 }, +#define VERSIONSW 2 + { "version", 0 }, +#define HELPSW 3 + { "help", 0 }, + { NULL, 0 } }; int main (int argc, char **argv) { - int msgnum, unlink_msgs = 0; - char *cp, *maildir, *folder = NULL; - char buf[BUFSIZ], **argp; - char **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; + int msgnum, unlink_msgs = 0; + char *cp, *maildir, *folder = NULL; + char buf[BUFSIZ], **argp; + char **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* parse arguments */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case UNLINKSW: - unlink_msgs++; - continue; - case NUNLINKSW: - unlink_msgs = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* parse arguments */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case UNLINKSW: + unlink_msgs++; + continue; + case NUNLINKSW: + unlink_msgs = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); + } + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!msgs.size) + app_msgarg(&msgs, "cur"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + /* + * This is hackish. If we are using a external rmmproc, + * then we need to update the current folder in the + * context so the external rmmproc will remove files + * from the correct directory. This should be moved to + * folder_delmsgs(). + */ + if (rmmproc) { + context_replace (pfolder, folder); + context_save (); + fflush (stdout); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!msgs.size) - app_msgarg(&msgs, "cur"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - /* - * This is hackish. If we are using a external rmmproc, - * then we need to update the current folder in the - * context so the external rmmproc will remove files - * from the correct directory. This should be moved to - * folder_delmsgs(). - */ - if (rmmproc) { - context_replace (pfolder, folder); - context_save (); - fflush (stdout); - } - - /* "remove" the SELECTED messages */ - folder_delmsgs (mp, unlink_msgs, 0); - - seq_save (mp); /* synchronize message sequences */ - context_replace (pfolder, folder); /* update current folder */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder structure */ - done (0); - return 1; + + /* "remove" the SELECTED messages */ + folder_delmsgs (mp, unlink_msgs, 0); + + seq_save (mp); /* synchronize message sequences */ + context_replace (pfolder, folder); /* update current folder */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder structure */ + done (0); + return 1; } diff --git a/uip/scan.c b/uip/scan.c index 077f824..52a40af 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -1,4 +1,3 @@ - /* * scan.c -- display a one-line "scan" listing of folder or messages * @@ -16,31 +15,31 @@ #include static struct swit switches[] = { -#define CLRSW 0 - { "clear", 0 }, -#define NCLRSW 1 - { "noclear", 0 }, -#define FORMSW 2 - { "form formatfile", 0 }, -#define FMTSW 3 - { "format string", 5 }, -#define HEADSW 4 - { "header", 0 }, -#define NHEADSW 5 - { "noheader", 0 }, -#define WIDTHSW 6 - { "width columns", 0 }, -#define REVSW 7 - { "reverse", 0 }, -#define NREVSW 8 - { "noreverse", 0 }, -#define FILESW 9 - { "file file", 4 }, +#define CLRSW 0 + { "clear", 0 }, +#define NCLRSW 1 + { "noclear", 0 }, +#define FORMSW 2 + { "form formatfile", 0 }, +#define FMTSW 3 + { "format string", 5 }, +#define HEADSW 4 + { "header", 0 }, +#define NHEADSW 5 + { "noheader", 0 }, +#define WIDTHSW 6 + { "width columns", 0 }, +#define REVSW 7 + { "reverse", 0 }, +#define NREVSW 8 + { "noreverse", 0 }, +#define FILESW 9 + { "file file", 4 }, #define VERSIONSW 10 - { "version", 0 }, -#define HELPSW 11 - { "help", 0 }, - { NULL, 0 } + { "version", 0 }, +#define HELPSW 11 + { "help", 0 }, + { NULL, 0 } }; @@ -48,7 +47,7 @@ static struct swit switches[] = { * global for sbr/formatsbr.c - yech! */ #ifdef LBL -extern struct msgs *fmt_current_folder; +extern struct msgs *fmt_current_folder; #endif /* @@ -60,270 +59,270 @@ void clear_screen(void); /* from termsbr.c */ int main (int argc, char **argv) { - int clearflag = 0, hdrflag = 0, ontty; - int width = 0, revflag = 0; - int i, state, msgnum; - int seqnum[NUMATTRS], unseen, num_unseen_seq = 0; - char *cp, *maildir, *file = NULL, *folder = NULL; - char *form = NULL, *format = NULL, buf[BUFSIZ]; - char **argp, *nfs, **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; - FILE *in; + int clearflag = 0, hdrflag = 0, ontty; + int width = 0, revflag = 0; + int i, state, msgnum; + int seqnum[NUMATTRS], unseen, num_unseen_seq = 0; + char *cp, *maildir, *file = NULL, *folder = NULL; + char *form = NULL, *format = NULL, buf[BUFSIZ]; + char **argp, *nfs, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; + FILE *in; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case CLRSW: - clearflag++; - continue; - case NCLRSW: - clearflag = 0; - continue; - - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - format = NULL; - continue; - case FMTSW: - if (!(format = *argp++) || *format == '-') - adios (NULL, "missing argument to %s", argp[-2]); - form = NULL; - continue; - - case HEADSW: - hdrflag++; - continue; - case NHEADSW: - hdrflag = 0; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - width = atoi (cp); - continue; - case REVSW: - revflag++; - continue; - case NREVSW: - revflag = 0; - continue; - - case FILESW: - if (!(cp = *argp++) || (cp[0] == '-' && cp[1])) - adios (NULL, "missing argument to %s", argp[-2]); - if (strcmp (file = cp, "-")) - file = path (cp, TFILE); - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - /* - * Get new format string. Must be before chdir(). - */ - nfs = new_fs (form, format, FORMAT); - - /* - * We are scanning a maildrop file - */ - if (file) { - if (msgs.size) - adios (NULL, "\"msgs\" not allowed with -file"); - if (folder) - adios (NULL, "\"+folder\" not allowed with -file"); - - /* check if "file" is really stdin */ - if (strcmp (file, "-") == 0) { - in = stdin; - file = "stdin"; - } else { - if ((in = fopen (file, "r")) == NULL) - adios (file, "unable to open"); + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case CLRSW: + clearflag++; + continue; + case NCLRSW: + clearflag = 0; + continue; + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios (NULL, "missing argument to %s", argp[-2]); + format = NULL; + continue; + case FMTSW: + if (!(format = *argp++) || *format == '-') + adios (NULL, "missing argument to %s", argp[-2]); + form = NULL; + continue; + + case HEADSW: + hdrflag++; + continue; + case NHEADSW: + hdrflag = 0; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + width = atoi (cp); + continue; + case REVSW: + revflag++; + continue; + case NREVSW: + revflag = 0; + continue; + + case FILESW: + if (!(cp = *argp++) || (cp[0] == '-' && cp[1])) + adios (NULL, "missing argument to %s", argp[-2]); + if (strcmp (file = cp, "-")) + file = path (cp, TFILE); + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } -#ifndef JLR - if (hdrflag) { - printf ("FOLDER %s\t%s\n", file, dtimenow (1)); - } + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + /* + * Get new format string. Must be before chdir(). + */ + nfs = new_fs (form, format, FORMAT); + + /* + * We are scanning a maildrop file + */ + if (file) { + if (msgs.size) + adios (NULL, "\"msgs\" not allowed with -file"); + if (folder) + adios (NULL, "\"+folder\" not allowed with -file"); + + /* check if "file" is really stdin */ + if (strcmp (file, "-") == 0) { + in = stdin; + file = "stdin"; + } else { + if ((in = fopen (file, "r")) == NULL) + adios (file, "unable to open"); + } + +#ifndef JLR + if (hdrflag) { + printf ("FOLDER %s\t%s\n", file, dtimenow (1)); + } #endif /* JLR */ - m_unknown (in); - for (msgnum = 1; ; ++msgnum) { - state = scan (in, msgnum, -1, nfs, width, 0, 0, - hdrflag ? file : NULL, 0L, 1); - if (state != SCNMSG && state != SCNENC) - break; + m_unknown (in); + for (msgnum = 1; ; ++msgnum) { + state = scan (in, msgnum, -1, nfs, width, 0, 0, + hdrflag ? file : NULL, 0L, 1); + if (state != SCNMSG && state != SCNENC) + break; + } + fclose (in); + done (0); } - fclose (in); - done (0); - } - - /* - * We are scanning a folder - */ - - if (!msgs.size) - app_msgarg(&msgs, "all"); - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done(1); - seq_setprev (mp); /* set the Previous-Sequence */ - - context_replace (pfolder, folder); /* update current folder */ - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - - /* - * Get the sequence number for each sequence - * specified by Unseen-Sequence - */ - if ((cp = context_find (usequence)) && *cp) { - char **ap, *dp; - - dp = getcpy(cp); - ap = brkstring (dp, " ", "\n"); - for (i = 0; ap && *ap; i++, ap++) - seqnum[i] = seq_getnum (mp, *ap); - - num_unseen_seq = i; - if (dp) - free(dp); - } - - ontty = isatty (fileno (stdout)); + + /* + * We are scanning a folder + */ + + if (!msgs.size) + app_msgarg(&msgs, "all"); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done(1); + seq_setprev (mp); /* set the Previous-Sequence */ + + context_replace (pfolder, folder); /* update current folder */ + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + + /* + * Get the sequence number for each sequence + * specified by Unseen-Sequence + */ + if ((cp = context_find (usequence)) && *cp) { + char **ap, *dp; + + dp = getcpy(cp); + ap = brkstring (dp, " ", "\n"); + for (i = 0; ap && *ap; i++, ap++) + seqnum[i] = seq_getnum (mp, *ap); + + num_unseen_seq = i; + if (dp) + free(dp); + } + + ontty = isatty (fileno (stdout)); #ifdef LBL - else - fmt_current_folder = mp; + else + fmt_current_folder = mp; #endif - for (msgnum = revflag ? mp->hghsel : mp->lowsel; - (revflag ? msgnum >= mp->lowsel : msgnum <= mp->hghsel); - msgnum += (revflag ? -1 : 1)) { - if (is_selected(mp, msgnum)) { - if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) { + for (msgnum = revflag ? mp->hghsel : mp->lowsel; + (revflag ? msgnum >= mp->lowsel : msgnum <= mp->hghsel); + msgnum += (revflag ? -1 : 1)) { + if (is_selected(mp, msgnum)) { + if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) { #if 0 - if (errno != EACCES) + if (errno != EACCES) #endif - admonish (cp, "unable to open message"); + admonish (cp, "unable to open message"); #if 0 - else - printf ("%*d unreadable\n", DMAXFOLDER, msgnum); + else + printf ("%*d unreadable\n", DMAXFOLDER, msgnum); #endif - continue; - } + continue; + } #ifndef JLR - if (hdrflag) { - printf ("FOLDER %s\t%s\n", folder, dtimenow(1)); - } + if (hdrflag) { + printf ("FOLDER %s\t%s\n", folder, dtimenow(1)); + } #endif /* JLR */ - /* - * Check if message is in any sequence given - * by Unseen-Sequence profile entry. - */ - unseen = 0; - for (i = 0; i < num_unseen_seq; i++) { - if (in_sequence(mp, seqnum[i], msgnum)) { - unseen = 1; - break; - } - } - - switch (state = scan (in, msgnum, 0, nfs, width, - msgnum == mp->curmsg, unseen, - folder, 0L, 1)) { - case SCNMSG: - case SCNENC: - case SCNERR: - break; - - default: - adios (NULL, "scan() botch (%d)", state); - - case SCNEOF: + /* + * Check if message is in any sequence given + * by Unseen-Sequence profile entry. + */ + unseen = 0; + for (i = 0; i < num_unseen_seq; i++) { + if (in_sequence(mp, seqnum[i], msgnum)) { + unseen = 1; + break; + } + } + + switch (state = scan (in, msgnum, 0, nfs, width, + msgnum == mp->curmsg, unseen, + folder, 0L, 1)) { + case SCNMSG: + case SCNENC: + case SCNERR: + break; + + default: + adios (NULL, "scan() botch (%d)", state); + + case SCNEOF: #if 0 - printf ("%*d empty\n", DMAXFOLDER, msgnum); + printf ("%*d empty\n", DMAXFOLDER, msgnum); #else - advise (NULL, "message %d: empty", msgnum); + advise (NULL, "message %d: empty", msgnum); #endif - break; - } - hdrflag = 0; - fclose (in); - if (ontty) - fflush (stdout); + break; + } + hdrflag = 0; + fclose (in); + if (ontty) + fflush (stdout); + } } - } #ifdef LBL - seq_save (mp); /* because formatsbr might have made changes */ + seq_save (mp); /* because formatsbr might have made changes */ #endif - folder_free (mp); /* free folder/message structure */ - if (clearflag) - clear_screen (); + folder_free (mp); /* free folder/message structure */ + if (clearflag) + clear_screen (); - done (0); - return 1; + done (0); + return 1; } diff --git a/uip/scansbr.c b/uip/scansbr.c index dd0e498..7c0d198 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -1,4 +1,3 @@ - /* * scansbr.c -- routines to help scan along... * @@ -15,8 +14,8 @@ #include #ifdef _FSTDIO -# define _ptr _p /* Gag */ -# define _cnt _w /* Wretch */ +# define _ptr _p /* Gag */ +# define _cnt _w /* Wretch */ #endif #ifdef SCO_5_STDIO @@ -26,7 +25,7 @@ # define _filbuf(fp) ((fp)->__cnt = 0, __filbuf(fp)) #endif -#define MAXSCANL 256 /* longest possible scan line */ +#define MAXSCANL 256 /* longest possible scan line */ /* * Buffer size for content part of header fields. We want this @@ -42,28 +41,27 @@ static struct format *fmt; static struct format *fmt_top; #endif /* JLR */ -static struct comp *datecomp; /* pntr to "date" comp */ -static struct comp *bodycomp; /* pntr to "body" pseudo-comp * - * (if referenced) */ -static int ncomps = 0; /* # of interesting components */ -static char **compbuffers = 0; /* buffers for component text */ -static struct comp **used_buf = 0; /* stack for comp that use buffers */ +static struct comp *datecomp; /* pntr to "date" comp */ +static struct comp *bodycomp; /* pntr to "body" pseudo-comp (if referenced) */ +static int ncomps = 0; /* # of interesting components */ +static char **compbuffers = 0; /* buffers for component text */ +static struct comp **used_buf = 0; /* stack for comp that use buffers */ -static int dat[5]; /* aux. data for format routine */ +static int dat[5]; /* aux. data for format routine */ -char *scanl = 0; /* text of most recent scanline */ +char *scanl = 0; /* text of most recent scanline */ #define DIEWRERR() adios (scnmsg, "write error on") #define FPUTS(buf) {\ if (mh_fputs(buf,scnout) == EOF)\ - DIEWRERR();\ - } + DIEWRERR();\ + } /* * prototypes */ -int sc_width (void); /* from termsbr.c */ +int sc_width (void); /* from termsbr.c */ static int mh_fputs(char *, FILE *); #ifdef MULTIBYTE_SUPPORT @@ -74,317 +72,317 @@ static int mh_fputs(char *, FILE *); int scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, - int unseen, char *folder, long size, int noisy) + int unseen, char *folder, long size, int noisy) { - int i, compnum, encrypted, state; - unsigned char *cp, *tmpbuf; - char **nxtbuf; - char *saved_c_text = NULL; - struct comp *cptr; - struct comp **savecomp; - char *scnmsg = NULL; - FILE *scnout = NULL; - char name[NAMESZ]; - static int rlwidth, slwidth; + int i, compnum, encrypted, state; + unsigned char *cp, *tmpbuf; + char **nxtbuf; + char *saved_c_text = NULL; + struct comp *cptr; + struct comp **savecomp; + char *scnmsg = NULL; + FILE *scnout = NULL; + char name[NAMESZ]; + static int rlwidth, slwidth; #ifdef RPATHS - char returnpath[BUFSIZ]; - char deliverydate[BUFSIZ]; + char returnpath[BUFSIZ]; + char deliverydate[BUFSIZ]; #endif - /* first-time only initialization */ - if (!scanl) { - if (width == 0) { - if ((width = sc_width ()) < WIDTH/2) - width = WIDTH/2; - else if (width > MAXSCANL) - width = MAXSCANL; - } - dat[3] = slwidth = width; - scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * (slwidth + 2) ); - if (outnum) - umask(~m_gmprot()); + /* first-time only initialization */ + if (!scanl) { + if (width == 0) { + if ((width = sc_width ()) < WIDTH/2) + width = WIDTH/2; + else if (width > MAXSCANL) + width = MAXSCANL; + } + dat[3] = slwidth = width; + scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * (slwidth + 2) ); + if (outnum) + umask(~m_gmprot()); - /* Compile format string */ - ncomps = fmt_compile (nfs, &fmt) + 1; + /* Compile format string */ + ncomps = fmt_compile (nfs, &fmt) + 1; #ifdef JLR - fmt_top = fmt; -#endif /* JLR */ - FINDCOMP(bodycomp, "body"); - FINDCOMP(datecomp, "date"); - FINDCOMP(cptr, "folder"); - if (cptr && folder) - cptr->c_text = folder; - FINDCOMP(cptr, "encrypted"); - if (!cptr) - if ((cptr = (struct comp *) calloc (1, sizeof(*cptr)))) { - cptr->c_name = "encrypted"; - cptr->c_next = wantcomp[i = CHASH (cptr->c_name)]; - wantcomp[i] = cptr; - ncomps++; - } - FINDCOMP (cptr, "dtimenow"); - if (cptr) - cptr->c_text = getcpy(dtimenow (0)); - nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)); - if (nxtbuf == NULL) - adios (NULL, "unable to allocate component buffers"); - used_buf = (struct comp **) calloc((size_t) (ncomps+1), - sizeof(struct comp *)); - if (used_buf == NULL) - adios (NULL, "unable to allocate component buffer stack"); - used_buf += ncomps+1; *--used_buf = 0; - rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ; - for (i = ncomps; i--; ) - *nxtbuf++ = mh_xmalloc(rlwidth); - } - - /* - * each-message initialization - */ - nxtbuf = compbuffers; - savecomp = used_buf; - tmpbuf = *nxtbuf++; - dat[0] = innum ? innum : outnum; - dat[1] = curflg; - dat[4] = unseen; - - /* - * Get the first field. If the message is non-empty - * and we're doing an "inc", open the output file. - */ - if ((state = m_getfld (FLD, name, tmpbuf, rlwidth, inb)) == FILEEOF) { - if (ferror(inb)) { - advise("read", "unable to"); /* "read error" */ - return SCNFAT; - } else { - return SCNEOF; - } - } - - if (outnum) { - if (outnum > 0) { - scnmsg = m_name (outnum); - if (*scnmsg == '?') /* msg num out of range */ - return SCNNUM; - } else { - scnmsg = "/dev/null"; + fmt_top = fmt; +#endif /* JLR */ + FINDCOMP(bodycomp, "body"); + FINDCOMP(datecomp, "date"); + FINDCOMP(cptr, "folder"); + if (cptr && folder) + cptr->c_text = folder; + FINDCOMP(cptr, "encrypted"); + if (!cptr) + if ((cptr = (struct comp *) calloc (1, sizeof(*cptr)))) { + cptr->c_name = "encrypted"; + cptr->c_next = wantcomp[i = CHASH (cptr->c_name)]; + wantcomp[i] = cptr; + ncomps++; + } + FINDCOMP (cptr, "dtimenow"); + if (cptr) + cptr->c_text = getcpy(dtimenow (0)); + nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)); + if (nxtbuf == NULL) + adios (NULL, "unable to allocate component buffers"); + used_buf = (struct comp **) calloc((size_t) (ncomps+1), + sizeof(struct comp *)); + if (used_buf == NULL) + adios (NULL, "unable to allocate component buffer stack"); + used_buf += ncomps+1; *--used_buf = 0; + rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ; + for (i = ncomps; i--; ) + *nxtbuf++ = mh_xmalloc(rlwidth); } - if ((scnout = fopen (scnmsg, "w")) == NULL) - adios (scnmsg, "unable to write"); -#ifdef RPATHS + /* - * Add the Return-Path and Delivery-Date - * header fields to message. + * each-message initialization */ - if (get_returnpath (returnpath, sizeof(returnpath), - deliverydate, sizeof(deliverydate))) { - FPUTS ("Return-Path: "); - FPUTS (returnpath); - FPUTS ("Delivery-Date: "); - FPUTS (deliverydate); - } -#endif /* RPATHS */ - } - - /* scan - main loop */ - for (compnum = 1; ; state = m_getfld (state, name, tmpbuf, rlwidth, inb)) { - switch (state) { - case FLD: - case FLDPLUS: - compnum++; - if (outnum) { - FPUTS (name); - if ( putc (':', scnout) == EOF) DIEWRERR(); - FPUTS (tmpbuf); - } - /* - * if we're interested in this component, save a pointer - * to the component text, then start using our next free - * buffer as the component temp buffer (buffer switching - * saves an extra copy of the component text). - */ - if ((cptr = wantcomp[CHASH(name)])) { - do { - if (!mh_strcasecmp(name, cptr->c_name)) { - if (! cptr->c_text) { - cptr->c_text = tmpbuf; - for (cp = tmpbuf + strlen (tmpbuf) - 1; - cp >= tmpbuf; cp--) - if (isspace (*cp)) - *cp = 0; - else - break; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } - break; - } - } while ((cptr = cptr->c_next)); - } + nxtbuf = compbuffers; + savecomp = used_buf; + tmpbuf = *nxtbuf++; + dat[0] = innum ? innum : outnum; + dat[1] = curflg; + dat[4] = unseen; - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, rlwidth, inb); - if (outnum) - FPUTS (tmpbuf); + /* + * Get the first field. If the message is non-empty + * and we're doing an "inc", open the output file. + */ + if ((state = m_getfld (FLD, name, tmpbuf, rlwidth, inb)) == FILEEOF) { + if (ferror(inb)) { + advise("read", "unable to"); /* "read error" */ + return SCNFAT; + } else { + return SCNEOF; } - break; + } - case BODY: - compnum = -1; - if (! outnum) { - state = FILEEOF; /* stop now if scan cmd */ - goto finished; + if (outnum) { + if (outnum > 0) { + scnmsg = m_name (outnum); + if (*scnmsg == '?') /* msg num out of range */ + return SCNNUM; + } else { + scnmsg = "/dev/null"; } - if (putc ('\n', scnout) == EOF) DIEWRERR(); - FPUTS (tmpbuf); + if ((scnout = fopen (scnmsg, "w")) == NULL) + adios (scnmsg, "unable to write"); +#ifdef RPATHS /* - * performance hack: some people like to run "inc" on - * things like net.sources or large digests. We do a - * copy directly into the output buffer rather than - * going through an intermediate buffer. - * - * We need the amount of data m_getfld found & don't - * want to do a strlen on the long buffer so there's - * a hack in m_getfld to save the amount of data it - * returned in the global "msg_count". + * Add the Return-Path and Delivery-Date + * header fields to message. */ + if (get_returnpath (returnpath, sizeof(returnpath), + deliverydate, sizeof(deliverydate))) { + FPUTS ("Return-Path: "); + FPUTS (returnpath); + FPUTS ("Delivery-Date: "); + FPUTS (deliverydate); + } +#endif /* RPATHS */ + } + + /* scan - main loop */ + for (compnum = 1; ; state = m_getfld (state, name, tmpbuf, rlwidth, inb)) { + switch (state) { + case FLD: + case FLDPLUS: + compnum++; + if (outnum) { + FPUTS (name); + if ( putc (':', scnout) == EOF) DIEWRERR(); + FPUTS (tmpbuf); + } + /* + * if we're interested in this component, save a pointer + * to the component text, then start using our next free + * buffer as the component temp buffer (buffer switching + * saves an extra copy of the component text). + */ + if ((cptr = wantcomp[CHASH(name)])) { + do { + if (!mh_strcasecmp(name, cptr->c_name)) { + if (! cptr->c_text) { + cptr->c_text = tmpbuf; + for (cp = tmpbuf + strlen (tmpbuf) - 1; + cp >= tmpbuf; cp--) + if (isspace (*cp)) + *cp = 0; + else + break; + *--savecomp = cptr; + tmpbuf = *nxtbuf++; + } + break; + } + } while ((cptr = cptr->c_next)); + } + + while (state == FLDPLUS) { + state = m_getfld (state, name, tmpbuf, rlwidth, inb); + if (outnum) + FPUTS (tmpbuf); + } + break; + + case BODY: + compnum = -1; + if (! outnum) { + state = FILEEOF; /* stop now if scan cmd */ + goto finished; + } + if (putc ('\n', scnout) == EOF) DIEWRERR(); + FPUTS (tmpbuf); + /* + * performance hack: some people like to run "inc" on + * things like net.sources or large digests. We do a + * copy directly into the output buffer rather than + * going through an intermediate buffer. + * + * We need the amount of data m_getfld found & don't + * want to do a strlen on the long buffer so there's + * a hack in m_getfld to save the amount of data it + * returned in the global "msg_count". + */ body:; - while (state == BODY) { + while (state == BODY) { #ifdef LINUX_STDIO - if (scnout->_IO_write_ptr == scnout->_IO_write_end) { + if (scnout->_IO_write_ptr == scnout->_IO_write_end) { #elif defined(__DragonFly__) - if (((struct __FILE_public *)scnout)->_w <= 0) { + if (((struct __FILE_public *)scnout)->_w <= 0) { #else - if (scnout->_cnt <= 0) { + if (scnout->_cnt <= 0) { #endif - if (fflush(scnout) == EOF) - DIEWRERR (); - } + if (fflush(scnout) == EOF) + DIEWRERR (); + } #ifdef LINUX_STDIO - state = m_getfld(state, name, scnout->_IO_write_ptr, - (long)scnout->_IO_write_ptr-(long)scnout->_IO_write_end , inb); - scnout->_IO_write_ptr += msg_count; + state = m_getfld(state, name, scnout->_IO_write_ptr, + (long)scnout->_IO_write_ptr-(long)scnout->_IO_write_end , inb); + scnout->_IO_write_ptr += msg_count; #elif defined(__DragonFly__) - state = m_getfld( state, name, ((struct __FILE_public *)scnout)->_p, -(((struct __FILE_public *)scnout)->_w), inb ); - ((struct __FILE_public *)scnout)->_w -= msg_count; - ((struct __FILE_public *)scnout)->_p += msg_count; + state = m_getfld( state, name, ((struct __FILE_public *)scnout)->_p, -(((struct __FILE_public *)scnout)->_w), inb ); + ((struct __FILE_public *)scnout)->_w -= msg_count; + ((struct __FILE_public *)scnout)->_p += msg_count; #else - state = m_getfld( state, name, scnout->_ptr, -(scnout->_cnt), inb ); - scnout->_cnt -= msg_count; - scnout->_ptr += msg_count; + state = m_getfld( state, name, scnout->_ptr, -(scnout->_cnt), inb ); + scnout->_cnt -= msg_count; + scnout->_ptr += msg_count; #endif + } + goto finished; + + case LENERR: + case FMTERR: + fprintf (stderr, + innum ? "??Format error (message %d) in " + : "??Format error in ", + outnum ? outnum : innum); + fprintf (stderr, "component %d\n", compnum); + + if (outnum) { + FPUTS ("\n\nBAD MSG:\n"); + FPUTS (name); + if (putc ('\n', scnout) == EOF) DIEWRERR(); + state = BODY; + goto body; + } + /* fall through */ + + case FILEEOF: + goto finished; + + default: + adios (NULL, "getfld() returned %d", state); } - goto finished; - - case LENERR: - case FMTERR: - fprintf (stderr, - innum ? "??Format error (message %d) in " - : "??Format error in ", - outnum ? outnum : innum); - fprintf (stderr, "component %d\n", compnum); - - if (outnum) { - FPUTS ("\n\nBAD MSG:\n"); - FPUTS (name); - if (putc ('\n', scnout) == EOF) DIEWRERR(); - state = BODY; - goto body; - } - /* fall through */ + } + + /* + * format and output the scan line. + */ +finished: + if (ferror(inb)) { + advise("read", "unable to"); /* "read error" */ + return SCNFAT; + } - case FILEEOF: - goto finished; + /* Save and restore buffer so we don't trash our dynamic pool! */ + if (bodycomp) { + saved_c_text = bodycomp->c_text; + bodycomp->c_text = tmpbuf; + } - default: - adios (NULL, "getfld() returned %d", state); + if (size) + dat[2] = size; + else if (outnum > 0) + { + dat[2] = ftell(scnout); + if (dat[2] == EOF) DIEWRERR(); } - } - /* - * format and output the scan line. - */ -finished: - if (ferror(inb)) { - advise("read", "unable to"); /* "read error" */ - return SCNFAT; - } - - /* Save and restore buffer so we don't trash our dynamic pool! */ - if (bodycomp) { - saved_c_text = bodycomp->c_text; - bodycomp->c_text = tmpbuf; - } - - if (size) - dat[2] = size; - else if (outnum > 0) - { - dat[2] = ftell(scnout); - if (dat[2] == EOF) DIEWRERR(); - } - - if ((datecomp && !datecomp->c_text) || (!size && !outnum)) { - struct stat st; - - fstat (fileno(inb), &st); - if (!size && !outnum) - dat[2] = st.st_size; - if (datecomp) { - if (! datecomp->c_text) { - if (datecomp->c_tws == NULL) - datecomp->c_tws = (struct tws *) - calloc((size_t) 1, sizeof(*datecomp->c_tws)); - if (datecomp->c_tws == NULL) - adios (NULL, "unable to allocate tws buffer"); - *datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime); - datecomp->c_flags |= CF_DATEFAB|CF_TRUE; - } else { - datecomp->c_flags &= ~CF_DATEFAB; - } + if ((datecomp && !datecomp->c_text) || (!size && !outnum)) { + struct stat st; + + fstat (fileno(inb), &st); + if (!size && !outnum) + dat[2] = st.st_size; + if (datecomp) { + if (! datecomp->c_text) { + if (datecomp->c_tws == NULL) + datecomp->c_tws = (struct tws *) + calloc((size_t) 1, sizeof(*datecomp->c_tws)); + if (datecomp->c_tws == NULL) + adios (NULL, "unable to allocate tws buffer"); + *datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime); + datecomp->c_flags |= CF_DATEFAB|CF_TRUE; + } else { + datecomp->c_flags &= ~CF_DATEFAB; + } + } } - } - fmt_scan (fmt, scanl, slwidth, dat); + fmt_scan (fmt, scanl, slwidth, dat); #if 0 - fmt = fmt_scan (fmt, scanl, slwidth, dat); - if (!fmt) - fmt = fmt_top; /* reset for old format files */ + fmt = fmt_scan (fmt, scanl, slwidth, dat); + if (!fmt) + fmt = fmt_top; /* reset for old format files */ #endif - if (bodycomp) - bodycomp->c_text = saved_c_text; + if (bodycomp) + bodycomp->c_text = saved_c_text; - if (noisy) - fputs (scanl, stdout); + if (noisy) + fputs (scanl, stdout); - FINDCOMP (cptr, "encrypted"); - encrypted = cptr && cptr->c_text; + FINDCOMP (cptr, "encrypted"); + encrypted = cptr && cptr->c_text; - /* return dynamically allocated buffers to pool */ - while ((cptr = *savecomp++)) { - *--nxtbuf = cptr->c_text; - cptr->c_text = NULL; - } - *--nxtbuf = tmpbuf; + /* return dynamically allocated buffers to pool */ + while ((cptr = *savecomp++)) { + *--nxtbuf = cptr->c_text; + cptr->c_text = NULL; + } + *--nxtbuf = tmpbuf; - if (outnum && (ferror(scnout) || fclose (scnout) == EOF)) - DIEWRERR(); + if (outnum && (ferror(scnout) || fclose (scnout) == EOF)) + DIEWRERR(); - return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG); + return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG); } static int mh_fputs(char *s, FILE *stream) { - char c; + char c; - while ((c = *s++)) - if (putc (c,stream) == EOF ) - return(EOF); - return (0); + while ((c = *s++)) + if (putc (c,stream) == EOF ) + return(EOF); + return (0); } diff --git a/uip/send.c b/uip/send.c index c8b77f7..91f1c16 100644 --- a/uip/send.c +++ b/uip/send.c @@ -1,4 +1,3 @@ - /* * send.c -- send a composed message * @@ -14,100 +13,100 @@ static struct swit switches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define DEBUGSW 1 - { "debug", -5 }, -#define DRAFTSW 2 - { "draft", 0 }, -#define DFOLDSW 3 - { "draftfolder +folder", 6 }, -#define DMSGSW 4 - { "draftmessage msg", 6 }, -#define NDFLDSW 5 - { "nodraftfolder", 0 }, -#define FILTSW 6 - { "filter filterfile", 0 }, -#define NFILTSW 7 - { "nofilter", 0 }, -#define FRMTSW 8 - { "format", 0 }, -#define NFRMTSW 9 - { "noformat", 0 }, -#define FORWSW 10 - { "forward", 0 }, -#define NFORWSW 11 - { "noforward", 0 }, -#define MIMESW 12 - { "mime", 0 }, -#define NMIMESW 13 - { "nomime", 0 }, -#define MSGDSW 14 - { "msgid", 0 }, -#define NMSGDSW 15 - { "nomsgid", 0 }, -#define PUSHSW 16 - { "push", 0 }, -#define NPUSHSW 17 - { "nopush", 0 }, -#define SPLITSW 18 - { "split seconds", 0 }, -#define UNIQSW 19 - { "unique", -6 }, -#define NUNIQSW 20 - { "nounique", -8 }, -#define VERBSW 21 - { "verbose", 0 }, -#define NVERBSW 22 - { "noverbose", 0 }, -#define WATCSW 23 - { "watch", 0 }, -#define NWATCSW 24 - { "nowatch", 0 }, -#define WIDTHSW 25 - { "width columns", 0 }, -#define VERSIONSW 26 - { "version", 0 }, -#define HELPSW 27 - { "help", 0 }, -#define BITSTUFFSW 28 - { "dashstuffing", -12 }, -#define NBITSTUFFSW 29 - { "nodashstuffing", -14 }, -#define MAILSW 30 - { "mail", -4 }, -#define SAMLSW 31 - { "saml", -4 }, -#define SENDSW 32 - { "send", -4 }, -#define SOMLSW 33 - { "soml", -4 }, -#define CLIESW 34 - { "client host", -6 }, -#define SERVSW 35 - { "server host", 6 }, -#define SNOOPSW 36 - { "snoop", 5 }, -#define ATTACHSW 40 - { "attach", 6 }, -#define ATTACHFORMATSW 41 - { "attachformat", 7 }, -#define PORTSW 42 - { "port server-port-name/number" , 4 }, - { NULL, 0 } +#define ALIASW 0 + { "alias aliasfile", 0 }, +#define DEBUGSW 1 + { "debug", -5 }, +#define DRAFTSW 2 + { "draft", 0 }, +#define DFOLDSW 3 + { "draftfolder +folder", 6 }, +#define DMSGSW 4 + { "draftmessage msg", 6 }, +#define NDFLDSW 5 + { "nodraftfolder", 0 }, +#define FILTSW 6 + { "filter filterfile", 0 }, +#define NFILTSW 7 + { "nofilter", 0 }, +#define FRMTSW 8 + { "format", 0 }, +#define NFRMTSW 9 + { "noformat", 0 }, +#define FORWSW 10 + { "forward", 0 }, +#define NFORWSW 11 + { "noforward", 0 }, +#define MIMESW 12 + { "mime", 0 }, +#define NMIMESW 13 + { "nomime", 0 }, +#define MSGDSW 14 + { "msgid", 0 }, +#define NMSGDSW 15 + { "nomsgid", 0 }, +#define PUSHSW 16 + { "push", 0 }, +#define NPUSHSW 17 + { "nopush", 0 }, +#define SPLITSW 18 + { "split seconds", 0 }, +#define UNIQSW 19 + { "unique", -6 }, +#define NUNIQSW 20 + { "nounique", -8 }, +#define VERBSW 21 + { "verbose", 0 }, +#define NVERBSW 22 + { "noverbose", 0 }, +#define WATCSW 23 + { "watch", 0 }, +#define NWATCSW 24 + { "nowatch", 0 }, +#define WIDTHSW 25 + { "width columns", 0 }, +#define VERSIONSW 26 + { "version", 0 }, +#define HELPSW 27 + { "help", 0 }, +#define BITSTUFFSW 28 + { "dashstuffing", -12 }, +#define NBITSTUFFSW 29 + { "nodashstuffing", -14 }, +#define MAILSW 30 + { "mail", -4 }, +#define SAMLSW 31 + { "saml", -4 }, +#define SENDSW 32 + { "send", -4 }, +#define SOMLSW 33 + { "soml", -4 }, +#define CLIESW 34 + { "client host", -6 }, +#define SERVSW 35 + { "server host", 6 }, +#define SNOOPSW 36 + { "snoop", 5 }, +#define ATTACHSW 40 + { "attach", 6 }, +#define ATTACHFORMATSW 41 + { "attachformat", 7 }, +#define PORTSW 42 + { "port server-port-name/number" , 4 }, + { NULL, 0 } }; static struct swit anyl[] = { -#define NOSW 0 - { "no", 0 }, -#define YESW 1 - { "yes", 0 }, -#define LISTDSW 2 - { "list", 0 }, - { NULL, 0 } +#define NOSW 0 + { "no", 0 }, +#define YESW 1 + { "yes", 0 }, +#define LISTDSW 2 + { "list", 0 }, + { NULL, 0 } }; -extern int debugsw; /* from sendsbr.c */ +extern int debugsw; /* from sendsbr.c */ extern int forwsw; extern int inplace; extern int pushsw; @@ -115,7 +114,7 @@ extern int splitsw; extern int unique; extern int verbsw; -extern char *altmsg; /* .. */ +extern char *altmsg; /* .. */ extern char *annotext; extern char *distfile; @@ -123,342 +122,342 @@ extern char *distfile; int main (int argc, char **argv) { - int msgp = 0, distsw = 0, vecp = 1; - int isdf = 0, mime = 0; - int msgnum, status; - char *cp, *dfolder = NULL, *maildir = NULL; - char buf[BUFSIZ], **ap, **argp, **arguments; - char *msgs[MAXARGS], *vec[MAXARGS]; - struct msgs *mp; - struct stat st; - char *attach = (char *)0; /* header field name for attachments */ - int attachformat = 0; /* mhbuild format specifier for attachments */ + int msgp = 0, distsw = 0, vecp = 1; + int isdf = 0, mime = 0; + int msgnum, status; + char *cp, *dfolder = NULL, *maildir = NULL; + char buf[BUFSIZ], **ap, **argp, **arguments; + char *msgs[MAXARGS], *vec[MAXARGS]; + struct msgs *mp; + struct stat st; + char *attach = (char *)0; /* header field name for attachments */ + int attachformat = 0; /* mhbuild format specifier for attachments */ #ifdef UCI - FILE *fp; + FILE *fp; #endif /* UCI */ #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [file] [switches]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case DRAFTSW: - msgs[msgp++] = draft; - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - msgs[msgp++] = cp; - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - - case PUSHSW: - pushsw++; - continue; - case NPUSHSW: - pushsw = 0; - continue; - - case SPLITSW: - if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case UNIQSW: - unique++; - continue; - case NUNIQSW: - unique = 0; - continue; - - case FORWSW: - forwsw++; - continue; - case NFORWSW: - forwsw = 0; - continue; - - case VERBSW: - verbsw++; - vec[vecp++] = --cp; - continue; - case NVERBSW: - verbsw = 0; - vec[vecp++] = --cp; - continue; - - case MIMESW: - mime++; - vec[vecp++] = --cp; - continue; - case NMIMESW: - mime = 0; - vec[vecp++] = --cp; - continue; - - case DEBUGSW: - debugsw++; /* fall */ - case NFILTSW: - case FRMTSW: - case NFRMTSW: - case BITSTUFFSW: - case NBITSTUFFSW: - case MSGDSW: - case NMSGDSW: - case WATCSW: - case NWATCSW: - case MAILSW: - case SAMLSW: - case SENDSW: - case SOMLSW: - case SNOOPSW: - vec[vecp++] = --cp; - continue; - - case ALIASW: - case FILTSW: - case WIDTHSW: - case CLIESW: - case SERVSW: - case PORTSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; - continue; - - case ATTACHSW: - if (!(attach = *argp++) || *attach == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case ATTACHFORMATSW: - if (! *argp || **argp == '-') - adios (NULL, "missing argument to %s", argp[-1]); - else { - attachformat = atoi (*argp); - if (attachformat < 0 || - attachformat > ATTACHFORMATS - 1) { - advise (NULL, "unsupported attachformat %d", - attachformat); - continue; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + vec[vecp++] = "-library"; + vec[vecp++] = getcpy (m_maildir ("")); + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [file] [switches]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DRAFTSW: + msgs[msgp++] = draft; + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + msgs[msgp++] = cp; + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + + case PUSHSW: + pushsw++; + continue; + case NPUSHSW: + pushsw = 0; + continue; + + case SPLITSW: + if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case UNIQSW: + unique++; + continue; + case NUNIQSW: + unique = 0; + continue; + + case FORWSW: + forwsw++; + continue; + case NFORWSW: + forwsw = 0; + continue; + + case VERBSW: + verbsw++; + vec[vecp++] = --cp; + continue; + case NVERBSW: + verbsw = 0; + vec[vecp++] = --cp; + continue; + + case MIMESW: + mime++; + vec[vecp++] = --cp; + continue; + case NMIMESW: + mime = 0; + vec[vecp++] = --cp; + continue; + + case DEBUGSW: + debugsw++; /* fall */ + case NFILTSW: + case FRMTSW: + case NFRMTSW: + case BITSTUFFSW: + case NBITSTUFFSW: + case MSGDSW: + case NMSGDSW: + case WATCSW: + case NWATCSW: + case MAILSW: + case SAMLSW: + case SENDSW: + case SOMLSW: + case SNOOPSW: + vec[vecp++] = --cp; + continue; + + case ALIASW: + case FILTSW: + case WIDTHSW: + case CLIESW: + case SERVSW: + case PORTSW: + vec[vecp++] = --cp; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + vec[vecp++] = cp; + continue; + + case ATTACHSW: + if (!(attach = *argp++) || *attach == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case ATTACHFORMATSW: + if (! *argp || **argp == '-') + adios (NULL, "missing argument to %s", argp[-1]); + else { + attachformat = atoi (*argp); + if (attachformat < 0 || + attachformat > ATTACHFORMATS - 1) { + advise (NULL, "unsupported attachformat %d", + attachformat); + continue; + } + } + ++argp; + continue; } - } - ++argp; - continue; - } - } else { - msgs[msgp++] = cp; + } else { + msgs[msgp++] = cp; + } } - } - /* - * check for "Aliasfile:" profile entry - */ - if ((cp = context_find ("Aliasfile"))) { - char *dp = NULL; + /* + * check for "Aliasfile:" profile entry + */ + if ((cp = context_find ("Aliasfile"))) { + char *dp = NULL; - for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) { - vec[vecp++] = "-alias"; - vec[vecp++] = *ap; + for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) { + vec[vecp++] = "-alias"; + vec[vecp++] = *ap; + } } - } - if (dfolder == NULL) { - if (msgp == 0) { + if (dfolder == NULL) { + if (msgp == 0) { #ifdef WHATNOW - if ((cp = getenv ("mhdraft")) && *cp) { - msgs[msgp++] = cp; - goto go_to_it; - } + if ((cp = getenv ("mhdraft")) && *cp) { + msgs[msgp++] = cp; + goto go_to_it; + } #endif /* WHATNOW */ - msgs[msgp++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); - if (stat (msgs[0], &st) == NOTOK) - adios (msgs[0], "unable to stat draft file"); - cp = concat ("Use \"", msgs[0], "\"? ", NULL); - for (status = LISTDSW; status != YESW;) { - if (!(argp = getans (cp, anyl))) - done (1); - switch (status = smatch (*argp, anyl)) { - case NOSW: - done (0); - case YESW: - break; - case LISTDSW: - showfile (++argp, msgs[0]); - break; - default: - advise (NULL, "say what?"); - break; + msgs[msgp++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); + if (stat (msgs[0], &st) == NOTOK) + adios (msgs[0], "unable to stat draft file"); + cp = concat ("Use \"", msgs[0], "\"? ", NULL); + for (status = LISTDSW; status != YESW;) { + if (!(argp = getans (cp, anyl))) + done (1); + switch (status = smatch (*argp, anyl)) { + case NOSW: + done (0); + case YESW: + break; + case LISTDSW: + showfile (++argp, msgs[0]); + break; + default: + advise (NULL, "say what?"); + break; + } + } + } else { + for (msgnum = 0; msgnum < msgp; msgnum++) + msgs[msgnum] = getcpy (m_maildir (msgs[msgnum])); } - } } else { - for (msgnum = 0; msgnum < msgp; msgnum++) - msgs[msgnum] = getcpy (m_maildir (msgs[msgnum])); - } - } else { - if (!context_find ("path")) - free (path ("./", TFOLDER)); - - if (!msgp) - msgs[msgp++] = "cur"; - maildir = m_maildir (dfolder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (dfolder))) - adios (NULL, "unable to read folder %s", dfolder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", dfolder); + if (!context_find ("path")) + free (path ("./", TFOLDER)); + + if (!msgp) + msgs[msgp++] = "cur"; + maildir = m_maildir (dfolder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (dfolder))) + adios (NULL, "unable to read folder %s", dfolder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", dfolder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgp; msgnum++) + if (!m_convert (mp, msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous-sequence */ + + for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected (mp, msgnum)) { + msgs[msgp++] = getcpy (m_name (msgnum)); + unset_exists (mp, msgnum); + } + } - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous-sequence */ - - for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - msgs[msgp++] = getcpy (m_name (msgnum)); - unset_exists (mp, msgnum); - } + mp->msgflags |= SEQMOD; + seq_save (mp); } - mp->msgflags |= SEQMOD; - seq_save (mp); - } - #ifdef WHATNOW go_to_it: #endif /* WHATNOW */ - if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) - if ((cp = context_find ("signature")) && *cp) - m_putenv ("SIGNATURE", cp); + if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) + if ((cp = context_find ("signature")) && *cp) + m_putenv ("SIGNATURE", cp); #ifdef UCI - else { - snprintf (buf, sizeof(buf), "%s/.signature", mypath); - if ((fp = fopen (buf, "r")) != NULL - && fgets (buf, sizeof buf, fp) != NULL) { - fclose (fp); - if (cp = strchr (buf, '\n')) - *cp = 0; - m_putenv ("SIGNATURE", buf); - } - } + else { + snprintf (buf, sizeof(buf), "%s/.signature", mypath); + if ((fp = fopen (buf, "r")) != NULL + && fgets (buf, sizeof buf, fp) != NULL) { + fclose (fp); + if (cp = strchr (buf, '\n')) + *cp = 0; + m_putenv ("SIGNATURE", buf); + } + } #endif /* UCI */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (stat (msgs[msgnum], &st) == NOTOK) - adios (msgs[msgnum], "unable to stat draft file"); - - if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) - annotext = NULL; - if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0)) - inplace = atoi (cp); - if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0) - altmsg = NULL; /* used by dist interface - see below */ - - if ((cp = getenv ("mhdist")) - && *cp - && (distsw = atoi (cp)) - && altmsg) { - vec[vecp++] = "-dist"; - distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL)); - if (link (altmsg, distfile) == NOTOK) { - if (errno != EXDEV + for (msgnum = 0; msgnum < msgp; msgnum++) + if (stat (msgs[msgnum], &st) == NOTOK) + adios (msgs[msgnum], "unable to stat draft file"); + + if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) + annotext = NULL; + if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0)) + inplace = atoi (cp); + if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0) + altmsg = NULL; /* used by dist interface - see below */ + + if ((cp = getenv ("mhdist")) + && *cp + && (distsw = atoi (cp)) + && altmsg) { + vec[vecp++] = "-dist"; + distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL)); + if (link (altmsg, distfile) == NOTOK) { + if (errno != EXDEV #ifdef EISREMOTE - && errno != EISREMOTE + && errno != EISREMOTE #endif /* EISREMOTE */ - ) - adios (distfile, "unable to link %s to", altmsg); - free (distfile); - distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL)); - { - int in, out; - struct stat st; - - if ((in = open (altmsg, O_RDONLY)) == NOTOK) - adios (altmsg, "unable to open"); - fstat(in, &st); - if ((out = creat (distfile, (int) st.st_mode & 0777)) == NOTOK) - adios (distfile, "unable to write"); - cpydata (in, out, altmsg, distfile); - close (in); - close (out); - } + ) + adios (distfile, "unable to link %s to", altmsg); + free (distfile); + distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL)); + { + int in, out; + struct stat st; + + if ((in = open (altmsg, O_RDONLY)) == NOTOK) + adios (altmsg, "unable to open"); + fstat(in, &st); + if ((out = creat (distfile, (int) st.st_mode & 0777)) == NOTOK) + adios (distfile, "unable to write"); + cpydata (in, out, altmsg, distfile); + close (in); + close (out); + } + } + } else { + distfile = NULL; } - } else { - distfile = NULL; - } - - if (altmsg == NULL || stat (altmsg, &st) == NOTOK) { - st.st_mtime = 0; - st.st_dev = 0; - st.st_ino = 0; - } - if (pushsw) - push (); - - status = 0; - vec[0] = r1bindex (postproc, '/'); - closefds (3); - - for (msgnum = 0; msgnum < msgp; msgnum++) { - switch (sendsbr (vec, vecp, msgs[msgnum], &st, 1, attach, - attachformat)) { - case DONE: - done (++status); - case NOTOK: - status++; /* fall */ - case OK: - break; + + if (altmsg == NULL || stat (altmsg, &st) == NOTOK) { + st.st_mtime = 0; + st.st_dev = 0; + st.st_ino = 0; + } + if (pushsw) + push (); + + status = 0; + vec[0] = r1bindex (postproc, '/'); + closefds (3); + + for (msgnum = 0; msgnum < msgp; msgnum++) { + switch (sendsbr (vec, vecp, msgs[msgnum], &st, 1, attach, + attachformat)) { + case DONE: + done (++status); + case NOTOK: + status++; /* fall */ + case OK: + break; + } } - } - context_save (); /* save the context file */ - done (status); - return 1; + context_save (); /* save the context file */ + done (status); + return 1; } diff --git a/uip/sendsbr.c b/uip/sendsbr.c index b610ad8..772c006 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -1,4 +1,3 @@ - /* * sendsbr.c -- routines to help WhatNow/Send along * @@ -27,7 +26,7 @@ # endif #endif -int debugsw = 0; /* global */ +int debugsw = 0; /* global */ int forwsw = 1; int inplace = 1; int pushsw = 0; @@ -35,19 +34,19 @@ int splitsw = -1; int unique = 0; int verbsw = 0; -char *altmsg = NULL; /* .. */ +char *altmsg = NULL; /* .. */ char *annotext = NULL; char *distfile = NULL; static jmp_buf env; -static char body_file_name[MAXPATHLEN + 1]; /* name of temporary file for body content */ -static char composition_file_name[MAXPATHLEN + 1]; /* name of mhbuild composition temporary file */ -static int field_size; /* size of header field buffer */ -static char *field; /* header field buffer */ -static FILE *draft_file; /* draft file pointer */ -static FILE *body_file; /* body file pointer */ -static FILE *composition_file; /* composition file pointer */ +static char body_file_name[MAXPATHLEN + 1]; /* name of temporary file for body content */ +static char composition_file_name[MAXPATHLEN + 1]; /* name of mhbuild composition temporary file */ +static int field_size; /* size of header field buffer */ +static char *field; /* header field buffer */ +static FILE *draft_file; /* draft file pointer */ +static FILE *body_file; /* body file pointer */ +static FILE *composition_file; /* composition file pointer */ /* * external prototypes @@ -66,10 +65,10 @@ static void annoaux (int); static int splitmsg (char **, int, char *, struct stat *, int); static int sendaux (char **, int, char *, struct stat *); -static int attach(char *, char *, int); -static void clean_up_temporary_files(void); -static int get_line(void); -static void make_mime_composition_file_entry(char *, int); +static int attach(char *, char *, int); +static void clean_up_temporary_files(void); +static int get_line(void); +static void make_mime_composition_file_entry(char *, int); /* @@ -77,466 +76,486 @@ static void make_mime_composition_file_entry(char *, int); */ int -sendsbr (char **vec, int vecp, char *drft, struct stat *st, int rename_drft, char *attachment_header_field_name, int attachformat) +sendsbr (char **vec, int vecp, char *drft, struct stat *st, + int rename_drft, char *attachment_header_field_name, int attachformat) { - int status; - char buffer[BUFSIZ], file[BUFSIZ]; - struct stat sts; - char *original_draft; /* name of original draft file */ - char *p; /* string pointer for building file name */ - - /* - * Save the original name of the draft file. The name of the draft file is changed - * to a temporary file containing the built MIME message if there are attachments. - * We need the original name so that it can be renamed after the message is sent. - */ - - original_draft = drft; - - /* - * There might be attachments if a header field name for attachments is supplied. - * Convert the draft to a MIME message. Use the mhbuild composition file for the - * draft if there was a successful conversion because that now contains the MIME - * message. A nice side effect of this is that it leaves the original draft file - * untouched so that it can be retrieved and modified if desired. - */ - - if (attachment_header_field_name != (char *)0) { - switch (attach(attachment_header_field_name, drft, attachformat)) { - case OK: - drft = composition_file_name; - break; + int status; + char buffer[BUFSIZ], file[BUFSIZ]; + struct stat sts; + char *original_draft; /* name of original draft file */ + char *p; /* string pointer for building file name */ - case NOTOK: - return (NOTOK); + /* + * Save the original name of the draft file. The name of the + * draft file is changed to a temporary file containing the built + * MIME message if there are attachments. We need the original + * name so that it can be renamed after the message is sent. + */ - case DONE: - break; - } - } + original_draft = drft; - done=armed_done; - switch (setjmp (env)) { - case OK: /* - * If given -push and -unique (which is undocumented), then - * rename the draft file. I'm not quite sure why. + * There might be attachments if a header field name for + * attachments is supplied. Convert the draft to a MIME message. + * Use the mhbuild composition file for the draft if there was + * a successful conversion because that now contains the MIME + * message. A nice side effect of this is that it leaves the + * original draft file untouched so that it can be retrieved + * and modified if desired. */ - if (pushsw && unique) { - char *cp = m_mktemp2(drft, invo_name, NULL, NULL); - if (cp == NULL) { - adios ("sendsbr", "unable to create temporary file"); - } - if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK) - adios (file, "unable to rename %s to", drft); - drft = file; + + if (attachment_header_field_name != (char *)0) { + switch (attach(attachment_header_field_name, drft, attachformat)) { + case OK: + drft = composition_file_name; + break; + + case NOTOK: + return (NOTOK); + + case DONE: + break; + } } + done=armed_done; + switch (setjmp (env)) { + case OK: + /* + * If given -push and -unique (which is undocumented), then + * rename the draft file. I'm not quite sure why. + */ + if (pushsw && unique) { + char *cp = m_mktemp2(drft, invo_name, NULL, NULL); + if (cp == NULL) { + adios ("sendsbr", "unable to create temporary file"); + } + if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK) + adios (file, "unable to rename %s to", drft); + drft = file; + } + + /* + * Check if we need to split the message into + * multiple messages of type "message/partial". + */ + if (splitsw >= 0 && !distfile && stat (drft, &sts) != NOTOK + && sts.st_size >= CPERMSG) { + status = splitmsg (vec, vecp, drft, st, splitsw) ? NOTOK : OK; + } else { + status = sendaux (vec, vecp, drft, st) ? NOTOK : OK; + } + + /* rename the original draft */ + if (rename_drft && status == OK && + rename (original_draft, strncpy (buffer, m_backup (original_draft), sizeof(buffer))) == NOTOK) + advise (buffer, "unable to rename %s to", drft); + break; + + default: + status = DONE; + break; + } + + done=exit; + if (distfile) + unlink (distfile); + /* - * Check if we need to split the message into - * multiple messages of type "message/partial". + * Get rid of any temporary files that we created for attachments. + * Also get rid of the renamed composition file that mhbuild + * leaves as a turd. It looks confusing, but we use the body + * file name to help build the renamed composition file name. */ - if (splitsw >= 0 && !distfile && stat (drft, &sts) != NOTOK - && sts.st_size >= CPERMSG) { - status = splitmsg (vec, vecp, drft, st, splitsw) ? NOTOK : OK; - } else { - status = sendaux (vec, vecp, drft, st) ? NOTOK : OK; - } - /* rename the original draft */ - if (rename_drft && status == OK && - rename (original_draft, strncpy (buffer, m_backup (original_draft), sizeof(buffer))) == NOTOK) - advise (buffer, "unable to rename %s to", drft); - break; - - default: - status = DONE; - break; - } - - done=exit; - if (distfile) - unlink (distfile); - - /* - * Get rid of any temporary files that we created for attachments. Also get rid of - * the renamed composition file that mhbuild leaves as a turd. It looks confusing, - * but we use the body file name to help build the renamed composition file name. - */ - - if (drft == composition_file_name) { - clean_up_temporary_files(); - - if (strlen(composition_file_name) >= sizeof (composition_file_name) - 6) - advise((char *)0, "unable to remove original composition file."); - - else { - if ((p = strrchr(composition_file_name, '/')) == (char *)0) - p = composition_file_name; - else - p++; - - (void)strcpy(body_file_name, p); - *p++ = ','; - (void)strcpy(p, body_file_name); - (void)strcat(p, ".orig"); - - (void)unlink(composition_file_name); + if (drft == composition_file_name) { + clean_up_temporary_files(); + + if (strlen(composition_file_name) >= sizeof (composition_file_name) - 6) + advise((char *)0, "unable to remove original composition file."); + + else { + if ((p = strrchr(composition_file_name, '/')) == (char *)0) + p = composition_file_name; + else + p++; + + (void)strcpy(body_file_name, p); + *p++ = ','; + (void)strcpy(p, body_file_name); + (void)strcat(p, ".orig"); + + (void)unlink(composition_file_name); + } } - } - return status; + return status; } -static int +static int attach(char *attachment_header_field_name, char *draft_file_name, - int attachformat) + int attachformat) { - char buf[MAXPATHLEN + 6]; /* miscellaneous buffer */ - int c; /* current character for body copy */ - int has_attachment; /* draft has at least one attachment */ - int has_body; /* draft has a message body */ - int length; /* length of attachment header field name */ - char *p; /* miscellaneous string pointer */ + char buf[MAXPATHLEN + 6]; /* miscellaneous buffer */ + int c; /* current character for body copy */ + int has_attachment; /* draft has at least one attachment */ + int has_body; /* draft has a message body */ + int length; /* length of attachment header field name */ + char *p; /* miscellaneous string pointer */ - /* - * Open up the draft file. - */ + /* + * Open up the draft file. + */ - if ((draft_file = fopen(draft_file_name, "r")) == (FILE *)0) - adios((char *)0, "can't open draft file `%s'.", draft_file_name); + if ((draft_file = fopen(draft_file_name, "r")) == (FILE *)0) + adios((char *)0, "can't open draft file `%s'.", draft_file_name); - /* - * Allocate a buffer to hold the header components as they're read in. - * This buffer might need to be quite large, so we grow it as needed. - */ + /* + * Allocate a buffer to hold the header components as they're read in. + * This buffer might need to be quite large, so we grow it as needed. + */ + + field = (char *)mh_xmalloc(field_size = 256); - field = (char *)mh_xmalloc(field_size = 256); + /* + * Scan the draft file for a header field name that matches the + * -attach argument. The existence of one indicates that the + * draft has attachments. Bail out if there are no attachments + * because we're done. Read to the end of the headers even if + * we have no attachments. + */ - /* - * Scan the draft file for a header field name that matches the -attach - * argument. The existence of one indicates that the draft has attachments. - * Bail out if there are no attachments because we're done. Read to the - * end of the headers even if we have no attachments. - */ + length = strlen(attachment_header_field_name); - length = strlen(attachment_header_field_name); + has_attachment = 0; - has_attachment = 0; + while (get_line() != EOF && *field != '\0' && *field != '-') + if (strncasecmp(field, attachment_header_field_name, length) == 0 && field[length] == ':') + has_attachment = 1; - while (get_line() != EOF && *field != '\0' && *field != '-') - if (strncasecmp(field, attachment_header_field_name, length) == 0 && field[length] == ':') - has_attachment = 1; + if (has_attachment == 0) + return (DONE); - if (has_attachment == 0) - return (DONE); + /* + * We have at least one attachment. Look for at least one + * non-blank line in the body of the message which indicates + * content in the body. + */ - /* - * We have at least one attachment. Look for at least one non-blank line - * in the body of the message which indicates content in the body. - */ + has_body = 0; - has_body = 0; + while (get_line() != EOF) { + for (p = field; *p != '\0'; p++) { + if (*p != ' ' && *p != '\t') { + has_body = 1; + break; + } + } - while (get_line() != EOF) { - for (p = field; *p != '\0'; p++) { - if (*p != ' ' && *p != '\t') { - has_body = 1; - break; - } + if (has_body) + break; } - if (has_body) - break; - } - - /* - * Make names for the temporary files. - */ + /* + * Make names for the temporary files. + */ - (void)strncpy(body_file_name, - m_mktemp(m_maildir(invo_name), NULL, NULL), - sizeof (body_file_name)); - (void)strncpy(composition_file_name, - m_mktemp(m_maildir(invo_name), NULL, NULL), - sizeof (composition_file_name)); + (void)strncpy(body_file_name, + m_mktemp(m_maildir(invo_name), NULL, NULL), + sizeof (body_file_name)); + (void)strncpy(composition_file_name, + m_mktemp(m_maildir(invo_name), NULL, NULL), + sizeof (composition_file_name)); - if (has_body) - body_file = fopen(body_file_name, "w"); + if (has_body) + body_file = fopen(body_file_name, "w"); - composition_file = fopen(composition_file_name, "w"); + composition_file = fopen(composition_file_name, "w"); - if ((has_body && body_file == (FILE *)0) || composition_file == (FILE *)0) { - clean_up_temporary_files(); - adios((char *)0, "unable to open all of the temporary files."); - } + if ((has_body && body_file == (FILE *)0) || composition_file == (FILE *)0) { + clean_up_temporary_files(); + adios((char *)0, "unable to open all of the temporary files."); + } - /* - * Start at the beginning of the draft file. Copy all non-attachment header fields - * to the temporary composition file. Then add the dashed line separator. - */ + /* + * Start at the beginning of the draft file. Copy all + * non-attachment header fields to the temporary composition file. + * Then add the dashed line separator. + */ - rewind(draft_file); + rewind(draft_file); - while (get_line() != EOF && *field != '\0' && *field != '-') - if (strncasecmp(field, attachment_header_field_name, length) != 0 || field[length] != ':') - (void)fprintf(composition_file, "%s\n", field); + while (get_line() != EOF && *field != '\0' && *field != '-') + if (strncasecmp(field, attachment_header_field_name, length) != 0 || field[length] != ':') + (void)fprintf(composition_file, "%s\n", field); - (void)fputs("--------\n", composition_file); + (void)fputs("--------\n", composition_file); - /* - * Copy the message body to a temporary file. - */ + /* + * Copy the message body to a temporary file. + */ - if (has_body) { - while ((c = getc(draft_file)) != EOF) - putc(c, body_file); + if (has_body) { + while ((c = getc(draft_file)) != EOF) + putc(c, body_file); - (void)fclose(body_file); - } + (void)fclose(body_file); + } - /* - * Add a mhbuild MIME composition file line for the body if there was one. - */ + /* + * Add a mhbuild MIME composition file line for the body if + * there was one. + */ - if (has_body) - make_mime_composition_file_entry(body_file_name, attachformat); + if (has_body) + make_mime_composition_file_entry(body_file_name, attachformat); - /* - * Now, go back to the beginning of the draft file and look for header fields - * that specify attachments. Add a mhbuild MIME composition file for each. - */ + /* + * Now, go back to the beginning of the draft file and look for + * header fields that specify attachments. Add a mhbuild MIME + * composition file for each. + */ - rewind(draft_file); + rewind(draft_file); - while (get_line() != EOF && *field != '\0' && *field != '-') { - if (strncasecmp(field, attachment_header_field_name, length) == 0 && field[length] == ':') { - for (p = field + length + 1; *p == ' ' || *p == '\t'; p++) - ; + while (get_line() != EOF && *field != '\0' && *field != '-') { + if (strncasecmp(field, attachment_header_field_name, length) == 0 && field[length] == ':') { + for (p = field + length + 1; *p == ' ' || *p == '\t'; p++) + ; - make_mime_composition_file_entry(p, attachformat); + make_mime_composition_file_entry(p, attachformat); + } } - } - (void)fclose(composition_file); + (void)fclose(composition_file); - /* - * We're ready to roll! Run mhbuild on the composition file. Note that mhbuild - * is in the context as buildmimeproc. - */ + /* + * We're ready to roll! Run mhbuild on the composition file. + * Note that mhbuild is in the context as buildmimeproc. + */ - (void)sprintf(buf, "%s %s", buildmimeproc, composition_file_name); + (void)sprintf(buf, "%s %s", buildmimeproc, composition_file_name); - if (system(buf) != 0) { - clean_up_temporary_files(); - return (NOTOK); - } + if (system(buf) != 0) { + clean_up_temporary_files(); + return (NOTOK); + } - return (OK); + return (OK); } -static void +static void clean_up_temporary_files(void) { - (void)unlink(body_file_name); - (void)unlink(composition_file_name); + (void)unlink(body_file_name); + (void)unlink(composition_file_name); - return; + return; } -static int +static int get_line(void) { - int c; /* current character */ - int n; /* number of bytes in buffer */ - char *p; /* buffer pointer */ - - /* - * Get a line from the input file, growing the field buffer as needed. We do this - * so that we can fit an entire line in the buffer making it easy to do a string - * comparison on both the field name and the field body which might be a long path - * name. - */ - - for (n = 0, p = field; (c = getc(draft_file)) != EOF; *p++ = c) { - if (c == '\n' && (c = getc(draft_file)) != ' ' && c != '\t') { - (void)ungetc(c, draft_file); - c = '\n'; - break; - } + int c; /* current character */ + int n; /* number of bytes in buffer */ + char *p; /* buffer pointer */ - if (++n >= field_size - 1) { - field = (char *)mh_xrealloc((void *)field, field_size += 256); + /* + * Get a line from the input file, growing the field buffer as + * needed. We do this so that we can fit an entire line in the + * buffer making it easy to do a string comparison on both the + * field name and the field body which might be a long path name. + */ + + for (n = 0, p = field; (c = getc(draft_file)) != EOF; *p++ = c) { + if (c == '\n' && (c = getc(draft_file)) != ' ' && c != '\t') { + (void)ungetc(c, draft_file); + c = '\n'; + break; + } - p = field + n - 1; + if (++n >= field_size - 1) { + field = (char *)mh_xrealloc((void *)field, field_size += 256); + + p = field + n - 1; + } } - } - /* - * NUL-terminate the field.. - */ + /* + * NUL-terminate the field.. + */ - *p = '\0'; + *p = '\0'; - return (c); + return (c); } -static void +static void make_mime_composition_file_entry(char *file_name, int attachformat) { - int binary; /* binary character found flag */ - int c; /* current character */ - char cmd[MAXPATHLEN + 6]; /* file command buffer */ - char *content_type; /* mime content type */ - FILE *fp; /* content and pipe file pointer */ - struct node *np; /* context scan node pointer */ - char *p; /* miscellaneous string pointer */ - struct stat st; /* file status buffer */ - - content_type = (char *)0; - - /* - * Check the file name for a suffix. Scan the context for that suffix on a - * mhshow-suffix- entry. We use these entries to be compatible with mhshow, - * and there's no reason to make the user specify each suffix twice. Context - * entries of the form "mhshow-suffix-contenttype" in the name have the suffix - * in the field, including the dot. - */ - - if ((p = strrchr(file_name, '.')) != (char *)0) { - for (np = m_defs; np; np = np->n_next) { - if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 && mh_strcasecmp(p, np->n_field) == 0) { - content_type = np->n_name + 14; - break; - } + int binary; /* binary character found flag */ + int c; /* current character */ + char cmd[MAXPATHLEN + 6]; /* file command buffer */ + char *content_type; /* mime content type */ + FILE *fp; /* content and pipe file pointer */ + struct node *np; /* context scan node pointer */ + char *p; /* miscellaneous string pointer */ + struct stat st; /* file status buffer */ + + content_type = (char *)0; + + /* + * Check the file name for a suffix. Scan the context for that + * suffix on a mhshow-suffix- entry. We use these entries to + * be compatible with mhshow, and there's no reason to make the + * user specify each suffix twice. Context entries of the form + * "mhshow-suffix-contenttype" in the name have the suffix in + * the field, including the dot. + */ + + if ((p = strrchr(file_name, '.')) != (char *)0) { + for (np = m_defs; np; np = np->n_next) { + if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 && mh_strcasecmp(p, np->n_field) == 0) { + content_type = np->n_name + 14; + break; + } + } + } + + /* + * No content type was found, either because there was no matching + * entry in the context or because the file name has no suffix. + * Open the file and check for non-ASCII characters. Choose the + * content type based on this check. + */ + + if (content_type == (char *)0) { + if ((fp = fopen(file_name, "r")) == (FILE *)0) { + clean_up_temporary_files(); + adios((char *)0, "unable to access file \"%s\"", file_name); + } + + binary = 0; + + while ((c = getc(fp)) != EOF) { + if (c > 127 || c < 0) { + binary = 1; + break; + } + } + + (void)fclose(fp); + + content_type = binary ? "application/octet-stream" : "text/plain"; } - } - - /* - * No content type was found, either because there was no matching entry in the - * context or because the file name has no suffix. Open the file and check for - * non-ASCII characters. Choose the content type based on this check. - */ - - if (content_type == (char *)0) { - if ((fp = fopen(file_name, "r")) == (FILE *)0) { - clean_up_temporary_files(); - adios((char *)0, "unable to access file \"%s\"", file_name); + + /* + * Make sure that the attachment file exists and is readable. + * Append a mhbuild directive to the draft file. This starts with + * the content type. Append a file name attribute and a private + * x-unix-mode attribute. Also append a description obtained + * (if possible) by running the "file" command on the file. + */ + + if (stat(file_name, &st) == -1 || access(file_name, R_OK) != 0) { + clean_up_temporary_files(); + adios((char *)0, "unable to access file \"%s\"", file_name); } - binary = 0; + switch (attachformat) { + case 0: + /* Insert name, file mode, and Content-Id. */ + (void)fprintf(composition_file, "#%s; name=\"%s\"; x-unix-mode=0%.3ho", + content_type, ((p = strrchr(file_name, '/')) == (char *)0) ? file_name : p + 1, (unsigned short)(st.st_mode & 0777)); + + if (strlen(file_name) > MAXPATHLEN) { + clean_up_temporary_files(); + adios((char *)0, "attachment file name `%s' too long.", file_name); + } + + (void)sprintf(cmd, "file '%s'", file_name); + + if ((fp = popen(cmd, "r")) != (FILE *)0 && fgets(cmd, sizeof (cmd), fp) != (char *)0) { + *strchr(cmd, '\n') = '\0'; + + /* + * The output of the "file" command is of the form + * + * file: description + * + * Strip off the "file:" and subsequent white space. + */ + + for (p = cmd; *p != '\0'; p++) { + if (*p == ':') { + for (p++; *p != '\0'; p++) { + if (*p != '\t') + break; + } + break; + } + } + + if (*p != '\0') + /* Insert Content-Description. */ + (void)fprintf(composition_file, " [ %s ]", p); + + (void)pclose(fp); + } + + break; + case 1: + if (stringdex (m_maildir(invo_name), file_name) == 0) { + /* + * Content had been placed by send into a temp file. + * Don't generate Content-Disposition header, because + * it confuses Microsoft Outlook, Build 10.0.6626, at + * least. + */ + (void) fprintf (composition_file, "#%s <>", content_type); + } else { + /* Suppress Content-Id, insert simple Content-Disposition. */ + (void) fprintf (composition_file, + "#%s; name=\"%s\" <>{attachment}", + content_type, + ((p = strrchr(file_name, '/')) == (char *)0) ? + file_name : p + 1); + } - while ((c = getc(fp)) != EOF) { - if (c > 127 || c < 0) { - binary = 1; break; - } + case 2: + if (stringdex (m_maildir(invo_name), file_name) == 0) { + /* + * Content had been placed by send into a temp file. + * Don't generate Content-Disposition header, because + * it confuses Microsoft Outlook, Build 10.0.6626, at + * least. + */ + (void) fprintf (composition_file, "#%s <>", content_type); + } else { + /* + * Suppress Content-Id, insert Content-Disposition + * with modification date. + */ + (void) fprintf (composition_file, + "#%s; name=\"%s\" <>{attachment; modification-date=\"%s\"}", + content_type, + ((p = strrchr(file_name, '/')) == (char *)0) ? + file_name : p + 1, dtime (&st.st_mtime, 0)); + } + + break; + default: + adios ((char *)0, "unsupported attachformat %d", attachformat); } - (void)fclose(fp); - - content_type = binary ? "application/octet-stream" : "text/plain"; - } - - /* - * Make sure that the attachment file exists and is readable. Append a mhbuild - * directive to the draft file. This starts with the content type. Append a - * file name attribute and a private x-unix-mode attribute. Also append a - * description obtained (if possible) by running the "file" command on the file. - */ - - if (stat(file_name, &st) == -1 || access(file_name, R_OK) != 0) { - clean_up_temporary_files(); - adios((char *)0, "unable to access file \"%s\"", file_name); - } - - switch (attachformat) { - case 0: - /* Insert name, file mode, and Content-Id. */ - (void)fprintf(composition_file, "#%s; name=\"%s\"; x-unix-mode=0%.3ho", - content_type, ((p = strrchr(file_name, '/')) == (char *)0) ? file_name : p + 1, (unsigned short)(st.st_mode & 0777)); - - if (strlen(file_name) > MAXPATHLEN) { - clean_up_temporary_files(); - adios((char *)0, "attachment file name `%s' too long.", file_name); - } - - (void)sprintf(cmd, "file '%s'", file_name); - - if ((fp = popen(cmd, "r")) != (FILE *)0 && fgets(cmd, sizeof (cmd), fp) != (char *)0) { - *strchr(cmd, '\n') = '\0'; - - /* - * The output of the "file" command is of the form - * - * file: description - * - * Strip off the "file:" and subsequent white space. - */ - - for (p = cmd; *p != '\0'; p++) { - if (*p == ':') { - for (p++; *p != '\0'; p++) { - if (*p != '\t') - break; - } - break; - } - } - - if (*p != '\0') - /* Insert Content-Description. */ - (void)fprintf(composition_file, " [ %s ]", p); - - (void)pclose(fp); - } - - break; - case 1: - if (stringdex (m_maildir(invo_name), file_name) == 0) { - /* Content had been placed by send into a temp file. - Don't generate Content-Disposition header, because - it confuses Microsoft Outlook, Build 10.0.6626, at - least. */ - (void) fprintf (composition_file, "#%s <>", content_type); - } else { - /* Suppress Content-Id, insert simple Content-Disposition. */ - (void) fprintf (composition_file, - "#%s; name=\"%s\" <>{attachment}", - content_type, - ((p = strrchr(file_name, '/')) == (char *)0) ? file_name : p + 1); - } - - break; - case 2: - if (stringdex (m_maildir(invo_name), file_name) == 0) { - /* Content had been placed by send into a temp file. - Don't generate Content-Disposition header, because - it confuses Microsoft Outlook, Build 10.0.6626, at - least. */ - (void) fprintf (composition_file, "#%s <>", content_type); - } else { - /* Suppress Content-Id, insert Content-Disposition with - modification date. */ - (void) fprintf (composition_file, - "#%s; name=\"%s\" <>{attachment; modification-date=\"%s\"}", - content_type, - ((p = strrchr(file_name, '/')) == (char *)0) ? file_name : p + 1, - dtime (&st.st_mtime, 0)); - } - - break; - default: - adios ((char *)0, "unsupported attachformat %d", attachformat); - } - - /* - * Finish up with the file name. - */ - - (void)fprintf(composition_file, " %s\n", file_name); - - return; + /* + * Finish up with the file name. + */ + + (void)fprintf(composition_file, " %s\n", file_name); + + return; } /* @@ -547,226 +566,232 @@ make_mime_composition_file_entry(char *file_name, int attachformat) static int splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) { - int compnum, nparts, partno, state, status; - long pos, start; - time_t clock; - char *cp, *dp, buffer[BUFSIZ], msgid[BUFSIZ]; - char subject[BUFSIZ]; - char name[NAMESZ], partnum[BUFSIZ]; - FILE *in; - - if ((in = fopen (drft, "r")) == NULL) - adios (drft, "unable to open for reading"); - - cp = dp = NULL; - start = 0L; - - /* - * Scan through the message and examine the various header fields, - * as well as locate the beginning of the message body. - */ - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buffer, sizeof(buffer), in)) { - case FLD: - case FLDPLUS: - case FLDEOF: - compnum++; + int compnum, nparts, partno, state, status; + long pos, start; + time_t clock; + char *cp, *dp, buffer[BUFSIZ], msgid[BUFSIZ]; + char subject[BUFSIZ]; + char name[NAMESZ], partnum[BUFSIZ]; + FILE *in; - /* - * This header field is discarded. - */ - if (!mh_strcasecmp (name, "Message-ID")) { - while (state == FLDPLUS) - state = m_getfld (state, name, buffer, sizeof(buffer), in); - } else if (uprf (name, XXX_FIELD_PRF) - || !mh_strcasecmp (name, VRSN_FIELD) - || !mh_strcasecmp (name, "Subject") - || !mh_strcasecmp (name, "Encrypted")) { - /* - * These header fields are copied to the enclosed - * header of the first message in the collection - * of message/partials. For the "Subject" header - * field, we also record it, so that a modified - * version of it, can be copied to the header - * of each messsage/partial in the collection. - */ - if (!mh_strcasecmp (name, "Subject")) { - size_t sublen; - - strncpy (subject, buffer, BUFSIZ); - sublen = strlen (subject); - if (sublen > 0 && subject[sublen - 1] == '\n') - subject[sublen - 1] = '\0'; - } - - dp = add (concat (name, ":", buffer, NULL), dp); - while (state == FLDPLUS) { - state = m_getfld (state, name, buffer, sizeof(buffer), in); - dp = add (buffer, dp); - } - } else { - /* - * These header fields are copied to the header of - * each message/partial in the collection. - */ - cp = add (concat (name, ":", buffer, NULL), cp); - while (state == FLDPLUS) { - state = m_getfld (state, name, buffer, sizeof(buffer), in); - cp = add (buffer, cp); - } - } + if ((in = fopen (drft, "r")) == NULL) + adios (drft, "unable to open for reading"); + + cp = dp = NULL; + start = 0L; - if (state != FLDEOF) { - start = ftell (in) + 1; - continue; + /* + * Scan through the message and examine the various header fields, + * as well as locate the beginning of the message body. + */ + for (compnum = 1, state = FLD;;) { + switch (state = m_getfld (state, name, buffer, sizeof(buffer), in)) { + case FLD: + case FLDPLUS: + case FLDEOF: + compnum++; + + /* + * This header field is discarded. + */ + if (!mh_strcasecmp (name, "Message-ID")) { + while (state == FLDPLUS) + state = m_getfld (state, name, buffer, sizeof(buffer), in); + } else if (uprf (name, XXX_FIELD_PRF) + || !mh_strcasecmp (name, VRSN_FIELD) + || !mh_strcasecmp (name, "Subject") + || !mh_strcasecmp (name, "Encrypted")) { + /* + * These header fields are copied + * to the enclosed header of the + * first message in the collection + * of message/partials. For the + * "Subject" header field, + * we also record it, so that + * a modified version of it, + * can be copied to the header + * of each messsage/partial in + * the collection. + */ + if (!mh_strcasecmp (name, "Subject")) { + size_t sublen; + + strncpy (subject, buffer, BUFSIZ); + sublen = strlen (subject); + if (sublen > 0 && subject[sublen - 1] == '\n') + subject[sublen - 1] = '\0'; + } + + dp = add (concat (name, ":", buffer, NULL), dp); + while (state == FLDPLUS) { + state = m_getfld (state, name, buffer, sizeof(buffer), in); + dp = add (buffer, dp); + } + } else { + /* + * These header fields are + * copied to the header of + * each message/partial in + * the collection. + */ + cp = add (concat (name, ":", buffer, NULL), cp); + while (state == FLDPLUS) { + state = m_getfld (state, name, buffer, sizeof(buffer), in); + cp = add (buffer, cp); + } + } + + if (state != FLDEOF) { + start = ftell (in) + 1; + continue; + } + /* else fall... */ + + case BODY: + case BODYEOF: + case FILEEOF: + break; + + case LENERR: + case FMTERR: + adios (NULL, "message format error in component #%d", compnum); + + default: + adios (NULL, "getfld () returned %d", state); } - /* else fall... */ - case BODY: - case BODYEOF: - case FILEEOF: break; + } + if (cp == NULL) + adios (NULL, "headers missing from draft"); - case LENERR: - case FMTERR: - adios (NULL, "message format error in component #%d", compnum); + nparts = 1; + pos = start; + while (fgets (buffer, sizeof(buffer) - 1, in)) { + long len; - default: - adios (NULL, "getfld () returned %d", state); + if ((pos += (len = strlen (buffer))) > CPERMSG) { + nparts++; + pos = len; + } } - break; - } - if (cp == NULL) - adios (NULL, "headers missing from draft"); + /* Only one part, nothing to split */ + if (nparts == 1) { + free (cp); + if (dp) + free (dp); - nparts = 1; - pos = start; - while (fgets (buffer, sizeof(buffer) - 1, in)) { - long len; + fclose (in); + return sendaux (vec, vecp, drft, st); + } - if ((pos += (len = strlen (buffer))) > CPERMSG) { - nparts++; - pos = len; + if (!pushsw) { + printf ("Sending as %d Partial Messages\n", nparts); + fflush (stdout); } - } + status = OK; - /* Only one part, nothing to split */ - if (nparts == 1) { - free (cp); - if (dp) - free (dp); - - fclose (in); - return sendaux (vec, vecp, drft, st); - } - - if (!pushsw) { - printf ("Sending as %d Partial Messages\n", nparts); - fflush (stdout); - } - status = OK; - - vec[vecp++] = "-partno"; - vec[vecp++] = partnum; - if (delay == 0) - vec[vecp++] = "-queued"; - - time (&clock); - snprintf (msgid, sizeof(msgid), "<%d.%ld@%s>", - (int) getpid(), (long) clock, LocalName()); - - fseek (in, start, SEEK_SET); - for (partno = 1; partno <= nparts; partno++) { - char tmpdrf[BUFSIZ]; - FILE *out; - - char *cp = m_mktemp2(drft, invo_name, NULL, &out); - if (cp == NULL) { - adios (drft, "unable to create temporary file for"); - } - strncpy(tmpdrf, cp, sizeof(tmpdrf)); - chmod (tmpdrf, 0600); + vec[vecp++] = "-partno"; + vec[vecp++] = partnum; + if (delay == 0) + vec[vecp++] = "-queued"; - /* - * Output the header fields - */ - fputs (cp, out); - fprintf (out, "Subject: %s (part %d of %d)\n", subject, partno, nparts); - fprintf (out, "%s: %s\n", VRSN_FIELD, VRSN_VALUE); - fprintf (out, "%s: message/partial; id=\"%s\";\n", TYPE_FIELD, msgid); - fprintf (out, "\tnumber=%d; total=%d\n", partno, nparts); - fprintf (out, "%s: part %d of %d\n\n", DESCR_FIELD, partno, nparts); + time (&clock); + snprintf (msgid, sizeof(msgid), "<%d.%ld@%s>", + (int) getpid(), (long) clock, LocalName()); - /* - * If this is the first in the collection, output the - * header fields we are encapsulating at the beginning - * of the body of the first message. - */ - if (partno == 1) { - if (dp) - fputs (dp, out); - fprintf (out, "Message-ID: %s\n", msgid); - fprintf (out, "\n"); - } + fseek (in, start, SEEK_SET); + for (partno = 1; partno <= nparts; partno++) { + char tmpdrf[BUFSIZ]; + FILE *out; - pos = 0; - for (;;) { - long len; - - if (!fgets (buffer, sizeof(buffer) - 1, in)) { - if (partno == nparts) - break; - adios (NULL, "premature eof"); - } - - if ((pos += (len = strlen (buffer))) > CPERMSG) { - fseek (in, -len, SEEK_CUR); - break; - } + char *cp = m_mktemp2(drft, invo_name, NULL, &out); + if (cp == NULL) { + adios (drft, "unable to create temporary file for"); + } + strncpy(tmpdrf, cp, sizeof(tmpdrf)); + chmod (tmpdrf, 0600); - fputs (buffer, out); - } + /* + * Output the header fields + */ + fputs (cp, out); + fprintf (out, "Subject: %s (part %d of %d)\n", subject, partno, nparts); + fprintf (out, "%s: %s\n", VRSN_FIELD, VRSN_VALUE); + fprintf (out, "%s: message/partial; id=\"%s\";\n", TYPE_FIELD, msgid); + fprintf (out, "\tnumber=%d; total=%d\n", partno, nparts); + fprintf (out, "%s: part %d of %d\n\n", DESCR_FIELD, partno, nparts); - if (fflush (out)) - adios (tmpdrf, "error writing to"); + /* + * If this is the first in the collection, output the + * header fields we are encapsulating at the beginning + * of the body of the first message. + */ + if (partno == 1) { + if (dp) + fputs (dp, out); + fprintf (out, "Message-ID: %s\n", msgid); + fprintf (out, "\n"); + } - fclose (out); + pos = 0; + for (;;) { + long len; - if (!pushsw && verbsw) { - printf ("\n"); - fflush (stdout); - } + if (!fgets (buffer, sizeof(buffer) - 1, in)) { + if (partno == nparts) + break; + adios (NULL, "premature eof"); + } - /* Pause here, if a delay is specified */ - if (delay > 0 && 1 < partno && partno <= nparts) { - if (!pushsw) { - printf ("pausing %d seconds before sending part %d...\n", - delay, partno); - fflush (stdout); - } - sleep ((unsigned int) delay); - } + if ((pos += (len = strlen (buffer))) > CPERMSG) { + fseek (in, -len, SEEK_CUR); + break; + } - snprintf (partnum, sizeof(partnum), "%d", partno); - status = sendaux (vec, vecp, tmpdrf, st); - unlink (tmpdrf); - if (status != OK) - break; + fputs (buffer, out); + } - /* - * This is so sendaux will only annotate - * the altmsg the first time it is called. - */ - annotext = NULL; - } + if (fflush (out)) + adios (tmpdrf, "error writing to"); + + fclose (out); + + if (!pushsw && verbsw) { + printf ("\n"); + fflush (stdout); + } + + /* Pause here, if a delay is specified */ + if (delay > 0 && 1 < partno && partno <= nparts) { + if (!pushsw) { + printf ("pausing %d seconds before sending part %d...\n", + delay, partno); + fflush (stdout); + } + sleep ((unsigned int) delay); + } + + snprintf (partnum, sizeof(partnum), "%d", partno); + status = sendaux (vec, vecp, tmpdrf, st); + unlink (tmpdrf); + if (status != OK) + break; - free (cp); - if (dp) - free (dp); + /* + * This is so sendaux will only annotate + * the altmsg the first time it is called. + */ + annotext = NULL; + } + + free (cp); + if (dp) + free (dp); - fclose (in); /* close the draft */ - return status; + fclose (in); /* close the draft */ + return status; } @@ -778,85 +803,85 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) static int sendaux (char **vec, int vecp, char *drft, struct stat *st) { - pid_t child_id; - int i, status, fd, fd2; - char backup[BUFSIZ], buf[BUFSIZ]; - - fd = pushsw ? tmp_fd () : NOTOK; - fd2 = NOTOK; - - vec[vecp++] = drft; - if (annotext) { - if ((fd2 = tmp_fd ()) != NOTOK) { - vec[vecp++] = "-idanno"; - snprintf (buf, sizeof(buf), "%d", fd2); - vec[vecp++] = buf; - } else { - admonish (NULL, "unable to create file for annotation list"); + pid_t child_id; + int i, status, fd, fd2; + char backup[BUFSIZ], buf[BUFSIZ]; + + fd = pushsw ? tmp_fd () : NOTOK; + fd2 = NOTOK; + + vec[vecp++] = drft; + if (annotext) { + if ((fd2 = tmp_fd ()) != NOTOK) { + vec[vecp++] = "-idanno"; + snprintf (buf, sizeof(buf), "%d", fd2); + vec[vecp++] = buf; + } else { + admonish (NULL, "unable to create file for annotation list"); + } } - } - if (distfile && distout (drft, distfile, backup) == NOTOK) - done (1); - vec[vecp] = NULL; + if (distfile && distout (drft, distfile, backup) == NOTOK) + done (1); + vec[vecp] = NULL; - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); - switch (child_id) { - case -1: - /* oops -- fork error */ - adios ("fork", "unable to"); - break; /* NOT REACHED */ + switch (child_id) { + case -1: + /* oops -- fork error */ + adios ("fork", "unable to"); + break; /* NOT REACHED */ - case 0: - /* - * child process -- send it - * - * If fd is ok, then we are pushing and fd points to temp - * file, so capture anything on stdout and stderr there. - */ - if (fd != NOTOK) { - dup2 (fd, fileno (stdout)); - dup2 (fd, fileno (stderr)); - close (fd); - } - execvp (postproc, vec); - fprintf (stderr, "unable to exec "); - perror (postproc); - _exit (-1); - break; /* NOT REACHED */ + case 0: + /* + * child process -- send it + * + * If fd is ok, then we are pushing and fd points to temp + * file, so capture anything on stdout and stderr there. + */ + if (fd != NOTOK) { + dup2 (fd, fileno (stdout)); + dup2 (fd, fileno (stderr)); + close (fd); + } + execvp (postproc, vec); + fprintf (stderr, "unable to exec "); + perror (postproc); + _exit (-1); + break; /* NOT REACHED */ - default: - /* - * parent process -- wait for it - */ - if ((status = pidwait(child_id, NOTOK)) == OK) { - if (annotext && fd2 != NOTOK) - anno (fd2, st); - } else { - /* - * If postproc failed, and we have good fd (which means - * we pushed), then mail error message (and possibly the - * draft) back to the user. - */ - if (fd != NOTOK) { - alert (drft, fd); - close (fd); - } else { - advise (NULL, "message not delivered to anyone"); - } - if (annotext && fd2 != NOTOK) - close (fd2); - if (distfile) { - unlink (drft); - if (rename (backup, drft) == NOTOK) - advise (drft, "unable to rename %s to", backup); - } + default: + /* + * parent process -- wait for it + */ + if ((status = pidwait(child_id, NOTOK)) == OK) { + if (annotext && fd2 != NOTOK) + anno (fd2, st); + } else { + /* + * If postproc failed, and we have good fd (which means + * we pushed), then mail error message (and possibly the + * draft) back to the user. + */ + if (fd != NOTOK) { + alert (drft, fd); + close (fd); + } else { + advise (NULL, "message not delivered to anyone"); + } + if (annotext && fd2 != NOTOK) + close (fd2); + if (distfile) { + unlink (drft); + if (rename (backup, drft) == NOTOK) + advise (drft, "unable to rename %s to", backup); + } + } + break; } - break; - } - return status; + return status; } @@ -868,224 +893,224 @@ sendaux (char **vec, int vecp, char *drft, struct stat *st) static void alert (char *file, int out) { - pid_t child_id; - int i, in; - char buf[BUFSIZ]; - - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - - switch (child_id) { - case NOTOK: - /* oops -- fork error */ - advise ("fork", "unable to"); - - case OK: - /* child process -- send it */ - SIGNAL (SIGHUP, SIG_IGN); - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - SIGNAL (SIGTERM, SIG_IGN); - if (forwsw) { - if ((in = open (file, O_RDONLY)) == NOTOK) { - admonish (file, "unable to re-open"); - } else { - lseek (out, (off_t) 0, SEEK_END); - strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf)); - write (out, buf, strlen (buf)); - strncpy (buf, "\n------- Unsent Draft\n\n", sizeof(buf)); - write (out, buf, strlen (buf)); - cpydgst (in, out, file, "temporary file"); - close (in); - strncpy (buf, "\n------- End of Unsent Draft\n", sizeof(buf)); - write (out, buf, strlen (buf)); - if (rename (file, strncpy (buf, m_backup (file), sizeof(buf))) == NOTOK) - admonish (buf, "unable to rename %s to", file); - } - } - lseek (out, (off_t) 0, SEEK_SET); - dup2 (out, fileno (stdin)); - close (out); - /* create subject for error notification */ - snprintf (buf, sizeof(buf), "send failed on %s", - forwsw ? "enclosed draft" : file); - - execlp (mailproc, r1bindex (mailproc, '/'), getusername (), - "-subject", buf, NULL); - fprintf (stderr, "unable to exec "); - perror (mailproc); - _exit (-1); - - default: /* no waiting... */ - break; - } + pid_t child_id; + int i, in; + char buf[BUFSIZ]; + + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + + switch (child_id) { + case NOTOK: + /* oops -- fork error */ + advise ("fork", "unable to"); + + case OK: + /* child process -- send it */ + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); + if (forwsw) { + if ((in = open (file, O_RDONLY)) == NOTOK) { + admonish (file, "unable to re-open"); + } else { + lseek (out, (off_t) 0, SEEK_END); + strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf)); + write (out, buf, strlen (buf)); + strncpy (buf, "\n------- Unsent Draft\n\n", sizeof(buf)); + write (out, buf, strlen (buf)); + cpydgst (in, out, file, "temporary file"); + close (in); + strncpy (buf, "\n------- End of Unsent Draft\n", sizeof(buf)); + write (out, buf, strlen (buf)); + if (rename (file, strncpy (buf, m_backup (file), sizeof(buf))) == NOTOK) + admonish (buf, "unable to rename %s to", file); + } + } + lseek (out, (off_t) 0, SEEK_SET); + dup2 (out, fileno (stdin)); + close (out); + /* create subject for error notification */ + snprintf (buf, sizeof(buf), "send failed on %s", + forwsw ? "enclosed draft" : file); + + execlp (mailproc, r1bindex (mailproc, '/'), getusername (), + "-subject", buf, NULL); + fprintf (stderr, "unable to exec "); + perror (mailproc); + _exit (-1); + + default: /* no waiting... */ + break; + } } static int tmp_fd (void) { - int fd; - char *tfile = NULL; + int fd; + char *tfile = NULL; - tfile = m_mktemp2(NULL, invo_name, &fd, NULL); - if (tfile == NULL) return NOTOK; - fchmod(fd, 0600); + tfile = m_mktemp2(NULL, invo_name, &fd, NULL); + if (tfile == NULL) return NOTOK; + fchmod(fd, 0600); - if (debugsw) - advise (NULL, "temporary file %s selected", tfile); - else - if (unlink (tfile) == NOTOK) - advise (tfile, "unable to remove"); + if (debugsw) + advise (NULL, "temporary file %s selected", tfile); + else + if (unlink (tfile) == NOTOK) + advise (tfile, "unable to remove"); - return fd; + return fd; } static void anno (int fd, struct stat *st) { - pid_t child_id; - sigset_t set, oset; - static char *cwd = NULL; - struct stat st2; - - if (altmsg && - (stat (altmsg, &st2) == NOTOK - || st->st_mtime != st2.st_mtime - || st->st_dev != st2.st_dev - || st->st_ino != st2.st_ino)) { - if (debugsw) - admonish (NULL, "$mhaltmsg mismatch"); - return; - } - - child_id = debugsw ? NOTOK : fork (); - switch (child_id) { - case NOTOK: /* oops */ - if (!debugsw) - advise (NULL, - "unable to fork, so doing annotations by hand..."); - if (cwd == NULL) - cwd = getcpy (pwd ()); - - case OK: - /* block a few signals */ - sigemptyset (&set); - sigaddset (&set, SIGHUP); - sigaddset (&set, SIGINT); - sigaddset (&set, SIGQUIT); - sigaddset (&set, SIGTERM); - SIGPROCMASK (SIG_BLOCK, &set, &oset); - - annoaux (fd); - if (child_id == OK) - _exit (0); - - /* reset the signal mask */ - SIGPROCMASK (SIG_SETMASK, &oset, &set); - - chdir (cwd); - break; - - default: /* no waiting... */ - close (fd); - break; - } + pid_t child_id; + sigset_t set, oset; + static char *cwd = NULL; + struct stat st2; + + if (altmsg && + (stat (altmsg, &st2) == NOTOK + || st->st_mtime != st2.st_mtime + || st->st_dev != st2.st_dev + || st->st_ino != st2.st_ino)) { + if (debugsw) + admonish (NULL, "$mhaltmsg mismatch"); + return; + } + + child_id = debugsw ? NOTOK : fork (); + switch (child_id) { + case NOTOK: /* oops */ + if (!debugsw) + advise (NULL, + "unable to fork, so doing annotations by hand..."); + if (cwd == NULL) + cwd = getcpy (pwd ()); + + case OK: + /* block a few signals */ + sigemptyset (&set); + sigaddset (&set, SIGHUP); + sigaddset (&set, SIGINT); + sigaddset (&set, SIGQUIT); + sigaddset (&set, SIGTERM); + SIGPROCMASK (SIG_BLOCK, &set, &oset); + + annoaux (fd); + if (child_id == OK) + _exit (0); + + /* reset the signal mask */ + SIGPROCMASK (SIG_SETMASK, &oset, &set); + + chdir (cwd); + break; + + default: /* no waiting... */ + close (fd); + break; + } } static void annoaux (int fd) { - int fd2, fd3, msgnum; - char *cp, *folder, *maildir; - char buffer[BUFSIZ], **ap; - FILE *fp; - struct msgs *mp; + int fd2, fd3, msgnum; + char *cp, *folder, *maildir; + char buffer[BUFSIZ], **ap; + FILE *fp; + struct msgs *mp; + + if ((folder = getenv ("mhfolder")) == NULL || *folder == 0) { + if (debugsw) + admonish (NULL, "$mhfolder not set"); + return; + } + maildir = m_maildir (folder); + if (chdir (maildir) == NOTOK) { + if (debugsw) + admonish (maildir, "unable to change directory to"); + return; + } + if (!(mp = folder_read (folder))) { + if (debugsw) + admonish (NULL, "unable to read folder %s", folder); + return; + } - if ((folder = getenv ("mhfolder")) == NULL || *folder == 0) { - if (debugsw) - admonish (NULL, "$mhfolder not set"); - return; - } - maildir = m_maildir (folder); - if (chdir (maildir) == NOTOK) { - if (debugsw) - admonish (maildir, "unable to change directory to"); - return; - } - if (!(mp = folder_read (folder))) { - if (debugsw) - admonish (NULL, "unable to read folder %s", folder); - return; - } + /* check for empty folder */ + if (mp->nummsg == 0) { + if (debugsw) + admonish (NULL, "no messages in %s", folder); + goto oops; + } - /* check for empty folder */ - if (mp->nummsg == 0) { - if (debugsw) - admonish (NULL, "no messages in %s", folder); - goto oops; - } + if ((cp = getenv ("mhmessages")) == NULL || *cp == 0) { + if (debugsw) + admonish (NULL, "$mhmessages not set"); + goto oops; + } + if (!debugsw /* MOBY HACK... */ + && pushsw + && (fd3 = open ("/dev/null", O_RDWR)) != NOTOK + && (fd2 = dup (fileno (stderr))) != NOTOK) { + dup2 (fd3, fileno (stderr)); + close (fd3); + } + else + fd2 = NOTOK; + for (ap = brkstring (cp = getcpy (cp), " ", NULL); *ap; ap++) + m_convert (mp, *ap); + free (cp); + if (fd2 != NOTOK) + dup2 (fd2, fileno (stderr)); + if (mp->numsel == 0) { + if (debugsw) + admonish (NULL, "no messages to annotate"); + goto oops; + } - if ((cp = getenv ("mhmessages")) == NULL || *cp == 0) { - if (debugsw) - admonish (NULL, "$mhmessages not set"); - goto oops; - } - if (!debugsw /* MOBY HACK... */ - && pushsw - && (fd3 = open ("/dev/null", O_RDWR)) != NOTOK - && (fd2 = dup (fileno (stderr))) != NOTOK) { - dup2 (fd3, fileno (stderr)); - close (fd3); - } - else - fd2 = NOTOK; - for (ap = brkstring (cp = getcpy (cp), " ", NULL); *ap; ap++) - m_convert (mp, *ap); - free (cp); - if (fd2 != NOTOK) - dup2 (fd2, fileno (stderr)); - if (mp->numsel == 0) { - if (debugsw) - admonish (NULL, "no messages to annotate"); - goto oops; - } + lseek (fd, (off_t) 0, SEEK_SET); + if ((fp = fdopen (fd, "r")) == NULL) { + if (debugsw) + admonish (NULL, "unable to fdopen annotation list"); + goto oops; + } + cp = NULL; + while (fgets (buffer, sizeof(buffer), fp) != NULL) + cp = add (buffer, cp); + fclose (fp); - lseek (fd, (off_t) 0, SEEK_SET); - if ((fp = fdopen (fd, "r")) == NULL) { if (debugsw) - admonish (NULL, "unable to fdopen annotation list"); - goto oops; - } - cp = NULL; - while (fgets (buffer, sizeof(buffer), fp) != NULL) - cp = add (buffer, cp); - fclose (fp); - - if (debugsw) - advise (NULL, "annotate%s with %s: \"%s\"", - inplace ? " inplace" : "", annotext, cp); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - if (debugsw) - advise (NULL, "annotate message %d", msgnum); - annotate (m_name (msgnum), annotext, cp, inplace, 1, -2, 0); + advise (NULL, "annotate%s with %s: \"%s\"", + inplace ? " inplace" : "", annotext, cp); + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + if (debugsw) + advise (NULL, "annotate message %d", msgnum); + annotate (m_name (msgnum), annotext, cp, inplace, 1, -2, 0); + } } - } - free (cp); + free (cp); oops: - folder_free (mp); /* free folder/message structure */ + folder_free (mp); /* free folder/message structure */ } static void armed_done (int status) { - longjmp (env, status ? status : NOTOK); + longjmp (env, status ? status : NOTOK); - exit (status); + exit (status); } diff --git a/uip/show.c b/uip/show.c index b5b48c5..eda19ca 100644 --- a/uip/show.c +++ b/uip/show.c @@ -1,4 +1,3 @@ - /* * show.c -- show/list messages * @@ -12,39 +11,39 @@ #include static struct swit switches[] = { -#define CHECKMIMESW 0 - { "checkmime", 0 }, -#define NOCHECKMIMESW 1 - { "nocheckmime", 0 }, -#define HEADSW 2 - { "header", 0 }, -#define NHEADSW 3 - { "noheader", 0 }, -#define FORMSW 4 - { "form formfile", 0 }, -#define PROGSW 5 - { "moreproc program", 0 }, -#define NPROGSW 6 - { "nomoreproc", 0 }, -#define LENSW 7 - { "length lines", 0 }, -#define WIDTHSW 8 - { "width columns", 0 }, -#define SHOWSW 9 - { "showproc program", 0 }, -#define SHOWMIMESW 10 - { "showmimeproc program", 0 }, -#define NSHOWSW 11 - { "noshowproc", 0 }, -#define DRFTSW 12 - { "draft", 0 }, -#define FILESW 13 - { "file file", -4 }, /* interface from showfile */ -#define VERSIONSW 14 - { "version", 0 }, -#define HELPSW 15 - { "help", 0 }, - { NULL, 0 } +#define CHECKMIMESW 0 + { "checkmime", 0 }, +#define NOCHECKMIMESW 1 + { "nocheckmime", 0 }, +#define HEADSW 2 + { "header", 0 }, +#define NHEADSW 3 + { "noheader", 0 }, +#define FORMSW 4 + { "form formfile", 0 }, +#define PROGSW 5 + { "moreproc program", 0 }, +#define NPROGSW 6 + { "nomoreproc", 0 }, +#define LENSW 7 + { "length lines", 0 }, +#define WIDTHSW 8 + { "width columns", 0 }, +#define SHOWSW 9 + { "showproc program", 0 }, +#define SHOWMIMESW 10 + { "showmimeproc program", 0 }, +#define NSHOWSW 11 + { "noshowproc", 0 }, +#define DRFTSW 12 + { "draft", 0 }, +#define FILESW 13 + { "file file", -4 }, /* interface from showfile */ +#define VERSIONSW 14 + { "version", 0 }, +#define HELPSW 15 + { "help", 0 }, + { NULL, 0 } }; /* @@ -55,311 +54,311 @@ static int is_nontext(char *); /* prototype from mhlsbr.c */ int mhl (int, char **); -#define SHOW 0 -#define NEXT 1 -#define PREV 2 +#define SHOW 0 +#define NEXT 1 +#define PREV 2 int main (int argc, char **argv) { - int draftsw = 0, headersw = 1, msgp = 0; - int nshow = 0, checkmime = 1, mime; - int vecp = 1, procp = 1, isdf = 0, mode = SHOW, msgnum; - char *cp, *maildir, *file = NULL, *folder = NULL, *proc; - char buf[BUFSIZ], **argp, **arguments; - char *msgs[MAXARGS], *vec[MAXARGS]; - struct msgs *mp = NULL; + int draftsw = 0, headersw = 1, msgp = 0; + int nshow = 0, checkmime = 1, mime; + int vecp = 1, procp = 1, isdf = 0, mode = SHOW, msgnum; + char *cp, *maildir, *file = NULL, *folder = NULL, *proc; + char buf[BUFSIZ], **argp, **arguments; + char *msgs[MAXARGS], *vec[MAXARGS]; + struct msgs *mp = NULL; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - if (!mh_strcasecmp (invo_name, "next")) { - mode = NEXT; - } else if (!mh_strcasecmp (invo_name, "prev")) { - mode = PREV; - } - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - case NPROGSW: - vec[vecp++] = --cp; - continue; - - case HELPSW: - snprintf (buf, sizeof(buf), - "%s [+folder] %s[switches] [switches for showproc]", - invo_name, mode == SHOW ? "[msgs] ": ""); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case DRFTSW: - if (file) - adios (NULL, "only one file at a time!"); - draftsw++; - if (mode == SHOW) - continue; -usage: - adios (NULL, - "usage: %s [+folder] [switches] [switches for showproc]", - invo_name); - case FILESW: - if (mode != SHOW) - goto usage; - if (draftsw || file) - adios (NULL, "only one file at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); - continue; - - case HEADSW: - headersw++; - continue; - case NHEADSW: - headersw = 0; - continue; - - case FORMSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = getcpy (etcpath(cp)); - continue; - - case PROGSW: - case LENSW: - case WIDTHSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; - continue; - - case SHOWSW: - if (!(showproc = *argp++) || *showproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nshow = 0; - continue; - case NSHOWSW: - nshow++; - continue; - - case SHOWMIMESW: - if (!(showmimeproc = *argp++) || *showmimeproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nshow = 0; - continue; - case CHECKMIMESW: - checkmime++; - continue; - case NOCHECKMIMESW: - checkmime = 0; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + if (!mh_strcasecmp (invo_name, "next")) { + mode = NEXT; + } else if (!mh_strcasecmp (invo_name, "prev")) { + mode = PREV; } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else { - if (mode != SHOW) - goto usage; - else - msgs[msgp++] = cp; + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + case NPROGSW: + vec[vecp++] = --cp; + continue; + + case HELPSW: + snprintf (buf, sizeof(buf), + "%s [+folder] %s[switches] [switches for showproc]", + invo_name, mode == SHOW ? "[msgs] ": ""); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DRFTSW: + if (file) + adios (NULL, "only one file at a time!"); + draftsw++; + if (mode == SHOW) + continue; +usage: + adios (NULL, + "usage: %s [+folder] [switches] [switches for showproc]", + invo_name); + case FILESW: + if (mode != SHOW) + goto usage; + if (draftsw || file) + adios (NULL, "only one file at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + file = path (cp, TFILE); + continue; + + case HEADSW: + headersw++; + continue; + case NHEADSW: + headersw = 0; + continue; + + case FORMSW: + vec[vecp++] = --cp; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + vec[vecp++] = getcpy (etcpath(cp)); + continue; + + case PROGSW: + case LENSW: + case WIDTHSW: + vec[vecp++] = --cp; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + vec[vecp++] = cp; + continue; + + case SHOWSW: + if (!(showproc = *argp++) || *showproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nshow = 0; + continue; + case NSHOWSW: + nshow++; + continue; + + case SHOWMIMESW: + if (!(showmimeproc = *argp++) || *showmimeproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nshow = 0; + continue; + case CHECKMIMESW: + checkmime++; + continue; + case NOCHECKMIMESW: + checkmime = 0; + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else { + if (mode != SHOW) + goto usage; + else + msgs[msgp++] = cp; + } } - } - procp = vecp; + procp = vecp; - if (!context_find ("path")) - free (path ("./", TFOLDER)); + if (!context_find ("path")) + free (path ("./", TFOLDER)); - if (draftsw || file) { - if (msgp) - adios (NULL, "only one file at a time!"); - vec[vecp++] = draftsw - ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf)) - : file; - goto go_to_it; - } + if (draftsw || file) { + if (msgp) + adios (NULL, "only one file at a time!"); + vec[vecp++] = draftsw + ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf)) + : file; + goto go_to_it; + } #ifdef WHATNOW - if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { - draftsw++; - vec[vecp++] = cp; - goto go_to_it; - } + if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { + draftsw++; + vec[vecp++] = cp; + goto go_to_it; + } #endif /* WHATNOW */ - if (!msgp) { - switch (mode) { - case NEXT: - msgs[msgp++] = "next"; - break; - case PREV: - msgs[msgp++] = "prev"; - break; - default: - msgs[msgp++] = "cur"; - break; + if (!msgp) { + switch (mode) { + case NEXT: + msgs[msgp++] = "next"; + break; + case PREV: + msgs[msgp++] = "prev"; + break; + default: + msgs[msgp++] = "cur"; + break; + } } - } - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) - done (1); + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgp; msgnum++) + if (!m_convert (mp, msgs[msgnum])) + done (1); - /* - * Set the SELECT_UNSEEN bit for all the SELECTED messages, - * since we will use that as a tag to know which messages - * to remove from the "unseen" sequence. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected(mp, msgnum)) - set_unseen (mp, msgnum); + /* + * Set the SELECT_UNSEEN bit for all the SELECTED messages, + * since we will use that as a tag to know which messages + * to remove from the "unseen" sequence. + */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected(mp, msgnum)) + set_unseen (mp, msgnum); - seq_setprev (mp); /* set the Previous-Sequence */ - seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ + seq_setprev (mp); /* set the Previous-Sequence */ + seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for show exec", MAXARGS - 2); + if (mp->numsel > MAXARGS - 2) + adios (NULL, "more than %d messages for show exec", MAXARGS - 2); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected(mp, msgnum)) - vec[vecp++] = getcpy (m_name (msgnum)); + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected(mp, msgnum)) + vec[vecp++] = getcpy (m_name (msgnum)); - seq_setcur (mp, mp->hghsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_replace (pfolder, folder); /* update current folder */ - context_save (); /* save the context file */ + seq_setcur (mp, mp->hghsel); /* update current message */ + seq_save (mp); /* synchronize sequences */ + context_replace (pfolder, folder); /* update current folder */ + context_save (); /* save the context file */ - if (headersw && vecp == 2) - printf ("(Message %s:%s)\n", folder, vec[1]); + if (headersw && vecp == 2) + printf ("(Message %s:%s)\n", folder, vec[1]); go_to_it: ; - fflush (stdout); - - vec[vecp] = NULL; - - /* - * Decide which "proc" to use - */ - mime = 0; - if (nshow) { - proc = catproc; - } else { - /* check if any messages are non-text MIME messages */ - if (checkmime && !getenv ("NOMHNPROC")) { - if (!draftsw && !file) { - /* loop through selected messages and check for MIME */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum) && is_nontext (m_name (msgnum))) { - mime = 1; - break; - } - } else { - /* check the file or draft for MIME */ - if (is_nontext (vec[vecp - 1])) - mime = 1; - } + fflush (stdout); + + vec[vecp] = NULL; + + /* + * Decide which "proc" to use + */ + mime = 0; + if (nshow) { + proc = catproc; + } else { + /* check if any messages are non-text MIME messages */ + if (checkmime && !getenv ("NOMHNPROC")) { + if (!draftsw && !file) { + /* loop through selected messages and check for MIME */ + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected (mp, msgnum) && is_nontext (m_name (msgnum))) { + mime = 1; + break; + } + } else { + /* check the file or draft for MIME */ + if (is_nontext (vec[vecp - 1])) + mime = 1; + } + } + + /* Set the "proc" */ + if (mime) + proc = showmimeproc; + else + proc = showproc; } - /* Set the "proc" */ - if (mime) - proc = showmimeproc; - else - proc = showproc; - } - - if (folder && !draftsw && !file) - m_putenv ("mhfolder", folder); - - /* - * For backward compatibility, if the "proc" is mhn, - * then add "-show" option. Add "-file" if showing - * file or draft. - */ - if (strcmp (r1bindex (proc, '/'), "mhn") == 0) { - if (draftsw || file) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vecp++; + if (folder && !draftsw && !file) + m_putenv ("mhfolder", folder); + + /* + * For backward compatibility, if the "proc" is mhn, + * then add "-show" option. Add "-file" if showing + * file or draft. + */ + if (strcmp (r1bindex (proc, '/'), "mhn") == 0) { + if (draftsw || file) { + vec[vecp] = vec[vecp - 1]; + vec[vecp - 1] = "-file"; + vecp++; + } + vec[vecp++] = "-show"; + vec[vecp] = NULL; } - vec[vecp++] = "-show"; - vec[vecp] = NULL; - } - - /* If the "proc" is "mhshow", add "-file" if showing file or draft. - */ - if (strcmp (r1bindex (proc, '/'), "mhshow") == 0 && (draftsw || file) ) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vec[++vecp] = NULL; - } - - /* - * If "proc" is mhl, then run it internally - * rather than exec'ing it. - */ - if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { - vec[0] = "mhl"; - mhl (vecp, vec); - done (0); - } - - /* - * If you are not using a nmh command as your "proc", then - * add the path to the message names. Currently, we are just - * checking for mhn here, since we've already taken care of mhl. - */ - if (!strcmp (r1bindex (proc, '/'), "mhl") - && !draftsw - && !file - && chdir (maildir = concat (m_maildir (""), "/", NULL)) != NOTOK) { - mp->foldpath = concat (mp->foldpath, "/", NULL); - cp = ssequal (maildir, mp->foldpath) - ? mp->foldpath + strlen (maildir) - : mp->foldpath; - for (msgnum = procp; msgnum < vecp; msgnum++) - vec[msgnum] = concat (cp, vec[msgnum], NULL); - } - - vec[0] = r1bindex (proc, '/'); - execvp (proc, vec); - adios (proc, "unable to exec"); - return 0; /* dead code to satisfy the compiler */ + + /* If the "proc" is "mhshow", add "-file" if showing file or draft. + */ + if (strcmp (r1bindex (proc, '/'), "mhshow") == 0 && (draftsw || file) ) { + vec[vecp] = vec[vecp - 1]; + vec[vecp - 1] = "-file"; + vec[++vecp] = NULL; + } + + /* + * If "proc" is mhl, then run it internally + * rather than exec'ing it. + */ + if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { + vec[0] = "mhl"; + mhl (vecp, vec); + done (0); + } + + /* + * If you are not using a nmh command as your "proc", then + * add the path to the message names. Currently, we are just + * checking for mhn here, since we've already taken care of mhl. + */ + if (!strcmp (r1bindex (proc, '/'), "mhl") + && !draftsw + && !file + && chdir (maildir = concat (m_maildir (""), "/", NULL)) != NOTOK) { + mp->foldpath = concat (mp->foldpath, "/", NULL); + cp = ssequal (maildir, mp->foldpath) + ? mp->foldpath + strlen (maildir) + : mp->foldpath; + for (msgnum = procp; msgnum < vecp; msgnum++) + vec[msgnum] = concat (cp, vec[msgnum], NULL); + } + + vec[0] = r1bindex (proc, '/'); + execvp (proc, vec); + adios (proc, "unable to exec"); + return 0; /* dead code to satisfy the compiler */ } /* @@ -368,167 +367,167 @@ go_to_it: ; static int is_nontext (char *msgnam) { - int result, state; - unsigned char *bp, *dp; - char *cp; - char buf[BUFSIZ], name[NAMESZ]; - FILE *fp; - - if ((fp = fopen (msgnam, "r")) == NULL) - return 0; - - for (state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - /* - * Check Content-Type field - */ - if (!mh_strcasecmp (name, TYPE_FIELD)) { - int passno; - char c; - - cp = add (buf, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); - cp = add (buf, cp); - } - bp = cp; - passno = 1; + int result, state; + unsigned char *bp, *dp; + char *cp; + char buf[BUFSIZ], name[NAMESZ]; + FILE *fp; + + if ((fp = fopen (msgnam, "r")) == NULL) + return 0; + + for (state = FLD;;) { + switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + /* + * Check Content-Type field + */ + if (!mh_strcasecmp (name, TYPE_FIELD)) { + int passno; + char c; + + cp = add (buf, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), fp); + cp = add (buf, cp); + } + bp = cp; + passno = 1; again: - for (; isspace (*bp); bp++) - continue; - if (*bp == '(') { - int i; - - for (bp++, i = 0;;) { - switch (*bp++) { - case '\0': + for (; isspace (*bp); bp++) + continue; + if (*bp == '(') { + int i; + + for (bp++, i = 0;;) { + switch (*bp++) { + case '\0': invalid: - result = 0; - goto out; - case '\\': - if (*bp++ == '\0') - goto invalid; - continue; - case '(': - i++; - /* and fall... */ - default: - continue; - case ')': - if (--i < 0) + result = 0; + goto out; + case '\\': + if (*bp++ == '\0') + goto invalid; + continue; + case '(': + i++; + /* and fall... */ + default: + continue; + case ')': + if (--i < 0) + break; + continue; + } + break; + } + } + if (passno == 2) { + if (*bp != '/') + goto invalid; + bp++; + passno = 3; + goto again; + } + for (dp = bp; istoken (*dp); dp++) + continue; + c = *dp; + *dp = '\0'; + if (!*bp) + goto invalid; + if (passno > 1) { + if ((result = (mh_strcasecmp (bp, "plain") != 0))) + goto out; + *dp = c; + for (dp++; isspace (*dp); dp++) + continue; + if (*dp) { + if ((result = !uprf (dp, "charset"))) + goto out; + dp += sizeof("charset") - 1; + while (isspace (*dp)) + dp++; + if (*dp++ != '=') + goto invalid; + while (isspace (*dp)) + dp++; + if (*dp == '"') { + if ((bp = strchr(++dp, '"'))) + *bp = '\0'; + } else { + for (bp = dp; *bp; bp++) + if (!istoken (*bp)) { + *bp = '\0'; + break; + } + } + } else { + /* Default character set */ + dp = "US-ASCII"; + } + /* Check the character set */ + result = !check_charset (dp, strlen (dp)); + } else { + if (!(result = (mh_strcasecmp (bp, "text") != 0))) { + *dp = c; + bp = dp; + passno = 2; + goto again; + } + } +out: + free (cp); + if (result) { + fclose (fp); + return result; + } break; - continue; } - break; - } - } - if (passno == 2) { - if (*bp != '/') - goto invalid; - bp++; - passno = 3; - goto again; - } - for (dp = bp; istoken (*dp); dp++) - continue; - c = *dp; - *dp = '\0'; - if (!*bp) - goto invalid; - if (passno > 1) { - if ((result = (mh_strcasecmp (bp, "plain") != 0))) - goto out; - *dp = c; - for (dp++; isspace (*dp); dp++) - continue; - if (*dp) { - if ((result = !uprf (dp, "charset"))) - goto out; - dp += sizeof("charset") - 1; - while (isspace (*dp)) - dp++; - if (*dp++ != '=') - goto invalid; - while (isspace (*dp)) - dp++; - if (*dp == '"') { - if ((bp = strchr(++dp, '"'))) - *bp = '\0'; - } else { - for (bp = dp; *bp; bp++) - if (!istoken (*bp)) { - *bp = '\0'; - break; + + /* + * Check Content-Transfer-Encoding field + */ + if (!mh_strcasecmp (name, ENCODING_FIELD)) { + cp = add (buf, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), fp); + cp = add (buf, cp); + } + for (bp = cp; isspace (*bp); bp++) + continue; + for (dp = bp; istoken (*dp); dp++) + continue; + *dp = '\0'; + result = (mh_strcasecmp (bp, "7bit") + && mh_strcasecmp (bp, "8bit") + && mh_strcasecmp (bp, "binary")); + + free (cp); + if (result) { + fclose (fp); + return result; } + break; } - } else { - /* Default character set */ - dp = "US-ASCII"; - } - /* Check the character set */ - result = !check_charset (dp, strlen (dp)); - } else { - if (!(result = (mh_strcasecmp (bp, "text") != 0))) { - *dp = c; - bp = dp; - passno = 2; - goto again; - } - } -out: - free (cp); - if (result) { - fclose (fp); - return result; - } - break; - } - - /* - * Check Content-Transfer-Encoding field - */ - if (!mh_strcasecmp (name, ENCODING_FIELD)) { - cp = add (buf, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), fp); - cp = add (buf, cp); - } - for (bp = cp; isspace (*bp); bp++) - continue; - for (dp = bp; istoken (*dp); dp++) - continue; - *dp = '\0'; - result = (mh_strcasecmp (bp, "7bit") - && mh_strcasecmp (bp, "8bit") - && mh_strcasecmp (bp, "binary")); - - free (cp); - if (result) { - fclose (fp); - return result; + + /* + * Just skip the rest of this header + * field and go to next one. + */ + while (state == FLDPLUS) + state = m_getfld (state, name, buf, sizeof(buf), fp); + break; + + /* + * We've passed the message header, + * so message is just text. + */ + default: + fclose (fp); + return 0; } - break; - } - - /* - * Just skip the rest of this header - * field and go to next one. - */ - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); - break; - - /* - * We've passed the message header, - * so message is just text. - */ - default: - fclose (fp); - return 0; } - } } diff --git a/uip/slocal.c b/uip/slocal.c index e6880fe..b82b5e2 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -1,4 +1,3 @@ - /* * slocal.c -- asynchronously filter and deliver new mail * @@ -10,7 +9,7 @@ /* * Under sendmail, users should add the line * - * "| /usr/local/nmh/lib/slocal" + * "| /usr/local/nmh/lib/slocal" * * to their $HOME/.forward file. * @@ -67,43 +66,43 @@ extern int initgroups(char*, int); #endif static struct swit switches[] = { -#define ADDRSW 0 - { "addr address", 0 }, -#define USERSW 1 - { "user name", 0 }, -#define FILESW 2 - { "file file", 0 }, -#define SENDERSW 3 - { "sender address", 0 }, -#define MAILBOXSW 4 - { "mailbox file", 0 }, -#define HOMESW 5 - { "home directory", -4 }, -#define INFOSW 6 - { "info data", 0 }, -#define MAILSW 7 - { "maildelivery file", 0 }, -#define VERBSW 8 - { "verbose", 0 }, -#define NVERBSW 9 - { "noverbose", 0 }, +#define ADDRSW 0 + { "addr address", 0 }, +#define USERSW 1 + { "user name", 0 }, +#define FILESW 2 + { "file file", 0 }, +#define SENDERSW 3 + { "sender address", 0 }, +#define MAILBOXSW 4 + { "mailbox file", 0 }, +#define HOMESW 5 + { "home directory", -4 }, +#define INFOSW 6 + { "info data", 0 }, +#define MAILSW 7 + { "maildelivery file", 0 }, +#define VERBSW 8 + { "verbose", 0 }, +#define NVERBSW 9 + { "noverbose", 0 }, #define SUPPRESSDUP 10 - { "suppressdup", 0 }, + { "suppressdup", 0 }, #define NSUPPRESSDUP 11 - { "nosuppressdup", 0 }, -#define DEBUGSW 12 - { "debug", 0 }, -#define VERSIONSW 13 - { "version", 0 }, -#define HELPSW 14 - { "help", 0 }, - { NULL, 0 } + { "nosuppressdup", 0 }, +#define DEBUGSW 12 + { "debug", 0 }, +#define VERSIONSW 13 + { "version", 0 }, +#define HELPSW 14 + { "help", 0 }, + { NULL, 0 } }; -static int globbed = 0; /* have we built "vars" table yet? */ -static int parsed = 0; /* have we built header field table yet */ -static int utmped = 0; /* have we scanned umtp(x) file yet */ -static int suppressdup = 0; /* are we suppressing duplicate messages? */ +static int globbed = 0; /* have we built "vars" table yet? */ +static int parsed = 0; /* have we built header field table yet */ +static int utmped = 0; /* have we scanned umtp(x) file yet */ +static int suppressdup = 0; /* are we suppressing duplicate messages? */ static int verbose = 0; static int debug = 0; @@ -113,30 +112,30 @@ static char *user = NULL; static char *info = NULL; static char *file = NULL; static char *sender = NULL; -static char *envelope = NULL; /* envelope information ("From " line) */ +static char *envelope = NULL; /* envelope information ("From " line) */ static char *mbox = NULL; static char *home = NULL; -static struct passwd *pw; /* passwd file entry */ +static struct passwd *pw; /* passwd file entry */ -static char ddate[BUFSIZ]; /* record the delivery date */ +static char ddate[BUFSIZ]; /* record the delivery date */ struct tws *now; static jmp_buf myctx; /* flags for pair->p_flags */ -#define P_NIL 0x00 -#define P_ADR 0x01 /* field is address */ -#define P_HID 0x02 /* special (fake) field */ -#define P_CHK 0x04 +#define P_NIL 0x00 +#define P_ADR 0x01 /* field is address */ +#define P_HID 0x02 /* special (fake) field */ +#define P_CHK 0x04 struct pair { - char *p_name; - char *p_value; - char p_flags; + char *p_name; + char *p_value; + char p_flags; }; -#define NVEC 100 +#define NVEC 100 /* * Lookup table for matching fields and patterns @@ -144,20 +143,20 @@ struct pair { * when the message is parsed. */ static struct pair hdrs[NVEC + 1] = { - { "source", NULL, P_HID }, - { "addr", NULL, P_HID }, - { "Return-Path", NULL, P_ADR }, - { "Reply-To", NULL, P_ADR }, - { "From", NULL, P_ADR }, - { "Sender", NULL, P_ADR }, - { "To", NULL, P_ADR }, - { "cc", NULL, P_ADR }, - { "Resent-Reply-To", NULL, P_ADR }, - { "Resent-From", NULL, P_ADR }, - { "Resent-Sender", NULL, P_ADR }, - { "Resent-To", NULL, P_ADR }, - { "Resent-cc", NULL, P_ADR }, - { NULL, NULL, 0 } + { "source", NULL, P_HID }, + { "addr", NULL, P_HID }, + { "Return-Path", NULL, P_ADR }, + { "Reply-To", NULL, P_ADR }, + { "From", NULL, P_ADR }, + { "Sender", NULL, P_ADR }, + { "To", NULL, P_ADR }, + { "cc", NULL, P_ADR }, + { "Resent-Reply-To", NULL, P_ADR }, + { "Resent-From", NULL, P_ADR }, + { "Resent-Sender", NULL, P_ADR }, + { "Resent-To", NULL, P_ADR }, + { "Resent-cc", NULL, P_ADR }, + { NULL, NULL, 0 } }; /* @@ -165,12 +164,12 @@ static struct pair hdrs[NVEC + 1] = { * before it is executed by the "pipe" or "qpipe" action. */ static struct pair vars[] = { - { "sender", NULL, P_NIL }, - { "address", NULL, P_NIL }, - { "size", NULL, P_NIL }, - { "reply-to", NULL, P_CHK }, - { "info", NULL, P_NIL }, - { NULL, NULL, 0 } + { "sender", NULL, P_NIL }, + { "address", NULL, P_NIL }, + { "size", NULL, P_NIL }, + { "reply-to", NULL, P_CHK }, + { "info", NULL, P_NIL }, + { NULL, NULL, 0 } }; extern char **environ; @@ -203,215 +202,219 @@ static char *trim (char *); int main (int argc, char **argv) { - int fd, status; - FILE *fp = stdin; - char *cp, *mdlvr = NULL, buf[BUFSIZ]; - char mailbox[BUFSIZ], tmpfil[BUFSIZ]; - char **argp, **arguments; + int fd, status; + FILE *fp = stdin; + char *cp, *mdlvr = NULL, buf[BUFSIZ]; + char mailbox[BUFSIZ], tmpfil[BUFSIZ]; + char **argp, **arguments; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (*argv, '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - /* Parse arguments */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), - "%s [switches] [address info sender]", invo_name); - print_help (buf, switches, 0); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ADDRSW: - if (!(addr = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case INFOSW: - if (!(info = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case USERSW: - if (!(user = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case FILESW: - if (!(file = *argp++) || *file == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case SENDERSW: - if (!(sender = *argp++))/* allow -xyz arguments */ - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case MAILBOXSW: - if (!(mbox = *argp++) || *mbox == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case HOMESW: - if (!(home = *argp++) || *home == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case MAILSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (mdlvr) - adios (NULL, "only one maildelivery file at a time!"); - mdlvr = cp; - continue; - - case VERBSW: - verbose++; - continue; - case NVERBSW: - verbose = 0; - continue; - - case SUPPRESSDUP: - suppressdup++; - continue; - case NSUPPRESSDUP: - suppressdup = 0; - continue; - case DEBUGSW: - debug++; - continue; - } - } + invo_name = r1bindex (*argv, '/'); + + /* foil search of user profile/context */ + if (context_foil (NULL) == -1) + done (1); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + /* Parse arguments */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), + "%s [switches] [address info sender]", invo_name); + print_help (buf, switches, 0); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case ADDRSW: + if (!(addr = *argp++))/* allow -xyz arguments */ + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case INFOSW: + if (!(info = *argp++))/* allow -xyz arguments */ + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case USERSW: + if (!(user = *argp++))/* allow -xyz arguments */ + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case FILESW: + if (!(file = *argp++) || *file == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case SENDERSW: + if (!(sender = *argp++))/* allow -xyz arguments */ + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case MAILBOXSW: + if (!(mbox = *argp++) || *mbox == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case HOMESW: + if (!(home = *argp++) || *home == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case MAILSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (mdlvr) + adios (NULL, "only one maildelivery file at a time!"); + mdlvr = cp; + continue; + + case VERBSW: + verbose++; + continue; + case NVERBSW: + verbose = 0; + continue; + + case SUPPRESSDUP: + suppressdup++; + continue; + case NSUPPRESSDUP: + suppressdup = 0; + continue; + case DEBUGSW: + debug++; + continue; + } + } - switch (argp - (argv + 1)) { - case 1: - addr = cp; - break; + switch (argp - (argv + 1)) { + case 1: + addr = cp; + break; - case 2: - info = cp; - break; + case 2: + info = cp; + break; - case 3: - sender = cp; - break; + case 3: + sender = cp; + break; + } } - } - - if (addr == NULL) - addr = getusername (); - if (user == NULL) - user = (cp = strchr(addr, '.')) ? ++cp : addr; - if ((pw = getpwnam (user)) == NULL) - adios (NULL, "no such local user as %s", user); - - if (chdir (pw->pw_dir) == -1) - chdir ("/"); - umask (0077); - - if (geteuid() == 0) { - setgid (pw->pw_gid); - initgroups (pw->pw_name, pw->pw_gid); - setuid (pw->pw_uid); - } - - if (info == NULL) - info = ""; - - setbuf (stdin, NULL); - - /* Record the delivery time */ - if ((now = dlocaltimenow ()) == NULL) - adios (NULL, "unable to ascertain local time"); - snprintf (ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow (0)); - - /* - * Copy the message to a temporary file - */ - if (file) { - int tempfd; - - /* getting message from file */ - if ((tempfd = open (file, O_RDONLY)) == -1) - adios (file, "unable to open"); - if (debug) - debug_printf ("retrieving message from file \"%s\"\n", file); - if ((fd = copy_message (tempfd, tmpfil, 1)) == -1) - adios (NULL, "unable to create temporary file"); - close (tempfd); - } else { - /* getting message from stdin */ + + if (addr == NULL) + addr = getusername (); + if (user == NULL) + user = (cp = strchr(addr, '.')) ? ++cp : addr; + if ((pw = getpwnam (user)) == NULL) + adios (NULL, "no such local user as %s", user); + + if (chdir (pw->pw_dir) == -1) + chdir ("/"); + umask (0077); + + if (geteuid() == 0) { + setgid (pw->pw_gid); + initgroups (pw->pw_name, pw->pw_gid); + setuid (pw->pw_uid); + } + + if (info == NULL) + info = ""; + + setbuf (stdin, NULL); + + /* Record the delivery time */ + if ((now = dlocaltimenow ()) == NULL) + adios (NULL, "unable to ascertain local time"); + snprintf (ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow (0)); + + /* + * Copy the message to a temporary file + */ + if (file) { + int tempfd; + + /* getting message from file */ + if ((tempfd = open (file, O_RDONLY)) == -1) + adios (file, "unable to open"); + if (debug) + debug_printf ("retrieving message from file \"%s\"\n", file); + if ((fd = copy_message (tempfd, tmpfil, 1)) == -1) + adios (NULL, "unable to create temporary file"); + close (tempfd); + } else { + /* getting message from stdin */ + if (debug) + debug_printf ("retrieving message from stdin\n"); + if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1) + adios (NULL, "unable to create temporary file"); + } + if (debug) - debug_printf ("retrieving message from stdin\n"); - if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1) - adios (NULL, "unable to create temporary file"); - } - - if (debug) - debug_printf ("temporary file=\"%s\"\n", tmpfil); - - /* Delete the temp file now or a copy of every single message passed through - slocal will be left in the /tmp directory until deleted manually! This - unlink() used to be under an 'else' of the 'if (debug)' above, but since - some people like to always run slocal with -debug and log the results, - the /tmp directory would get choked over time. Of course, now that we - always delete the temp file, the "temporary file=" message above is - somewhat pointless -- someone watching debug output wouldn't have a - chance to 'tail -f' or 'ln' the temp file before it's unlinked. The best - thing would be to delay this unlink() until later if debug == 1, but I'll - leave that for someone who cares about the temp-file-accessing - functionality (they'll have to watch out for cases where we adios()). */ - unlink (tmpfil); - - if (!(fp = fdopen (fd, "r+"))) - adios (NULL, "unable to access temporary file"); - - /* - * If no sender given, extract it - * from envelope information. */ - if (sender == NULL) - get_sender (envelope, &sender); - - if (mbox == NULL) { - snprintf (mailbox, sizeof(mailbox), "%s/%s", - mmdfldir[0] ? mmdfldir : pw->pw_dir, - mmdflfil[0] ? mmdflfil : pw->pw_name); - mbox = mailbox; - } - if (home == NULL) - home = pw->pw_dir; - - if (debug) { - debug_printf ("addr=\"%s\"\n", trim(addr)); - debug_printf ("user=\"%s\"\n", trim(user)); - debug_printf ("info=\"%s\"\n", trim(info)); - debug_printf ("sender=\"%s\"\n", trim(sender)); - debug_printf ("envelope=\"%s\"\n", envelope ? trim(envelope) : ""); - debug_printf ("mbox=\"%s\"\n", trim(mbox)); - debug_printf ("home=\"%s\"\n", trim(home)); - debug_printf ("ddate=\"%s\"\n", trim(ddate)); - debug_printf ("now=%02d:%02d\n\n", now->tw_hour, now->tw_min); - } - - /* deliver the message */ - status = localmail (fd, mdlvr); - - done (status != -1 ? RCV_MOK : RCV_MBX); - return 1; + debug_printf ("temporary file=\"%s\"\n", tmpfil); + + /* + * Delete the temp file now or a copy of every single message + * passed through slocal will be left in the /tmp directory until + * deleted manually! This unlink() used to be under an 'else' + * of the 'if (debug)' above, but since some people like to + * always run slocal with -debug and log the results, the /tmp + * directory would get choked over time. Of course, now that + * we always delete the temp file, the "temporary file=" message + * above is somewhat pointless -- someone watching debug output + * wouldn't have a chance to 'tail -f' or 'ln' the temp file + * before it's unlinked. The best thing would be to delay this + * unlink() until later if debug == 1, but I'll leave that for + * someone who cares about the temp-file-accessing functionality + * (they'll have to watch out for cases where we adios()). + */ + unlink (tmpfil); + + if (!(fp = fdopen (fd, "r+"))) + adios (NULL, "unable to access temporary file"); + + /* + * If no sender given, extract it + * from envelope information. */ + if (sender == NULL) + get_sender (envelope, &sender); + + if (mbox == NULL) { + snprintf (mailbox, sizeof(mailbox), "%s/%s", + mmdfldir[0] ? mmdfldir : pw->pw_dir, + mmdflfil[0] ? mmdflfil : pw->pw_name); + mbox = mailbox; + } + if (home == NULL) + home = pw->pw_dir; + + if (debug) { + debug_printf ("addr=\"%s\"\n", trim(addr)); + debug_printf ("user=\"%s\"\n", trim(user)); + debug_printf ("info=\"%s\"\n", trim(info)); + debug_printf ("sender=\"%s\"\n", trim(sender)); + debug_printf ("envelope=\"%s\"\n", envelope ? trim(envelope) : ""); + debug_printf ("mbox=\"%s\"\n", trim(mbox)); + debug_printf ("home=\"%s\"\n", trim(home)); + debug_printf ("ddate=\"%s\"\n", trim(ddate)); + debug_printf ("now=%02d:%02d\n\n", now->tw_hour, now->tw_min); + } + + /* deliver the message */ + status = localmail (fd, mdlvr); + + done (status != -1 ? RCV_MOK : RCV_MBX); + return 1; } @@ -422,32 +425,32 @@ main (int argc, char **argv) static int localmail (int fd, char *mdlvr) { - /* check if this message is a duplicate */ - if (suppressdup && - suppress_duplicates(fd, mdlvr ? mdlvr : ".maildelivery") == DONE) - return 0; + /* check if this message is a duplicate */ + if (suppressdup && + suppress_duplicates(fd, mdlvr ? mdlvr : ".maildelivery") == DONE) + return 0; - /* delivery according to personal Maildelivery file */ - if (usr_delivery (fd, mdlvr ? mdlvr : ".maildelivery", 0) != -1) - return 0; + /* delivery according to personal Maildelivery file */ + if (usr_delivery (fd, mdlvr ? mdlvr : ".maildelivery", 0) != -1) + return 0; - /* delivery according to global Maildelivery file */ - if (usr_delivery (fd, maildelivery, 1) != -1) - return 0; + /* delivery according to global Maildelivery file */ + if (usr_delivery (fd, maildelivery, 1) != -1) + return 0; - if (verbose) - verbose_printf ("(delivering to standard mail spool)\n"); + if (verbose) + verbose_printf ("(delivering to standard mail spool)\n"); - /* last resort - deliver to standard mail spool */ + /* last resort - deliver to standard mail spool */ #ifdef SLOCAL_MBOX - return usr_file (fd, mbox, MBOX_FORMAT); + return usr_file (fd, mbox, MBOX_FORMAT); #else - return usr_file (fd, mbox, MMDF_FORMAT); + return usr_file (fd, mbox, MMDF_FORMAT); #endif } -#define matches(a,b) (stringdex (b, a) >= 0) +#define matches(a,b) (stringdex (b, a) >= 0) /* * Parse the delivery file, and process incoming message. @@ -456,222 +459,222 @@ localmail (int fd, char *mdlvr) static int usr_delivery (int fd, char *delivery, int su) { - int i, accept, status=1, won, vecp, next; - char *field, *pattern, *action, *result, *string; - char buffer[BUFSIZ], tmpbuf[BUFSIZ]; - char *cp, *vec[NVEC]; - struct stat st; - struct pair *p; - FILE *fp; - - /* open the delivery file */ - if ((fp = fopen (delivery, "r")) == NULL) - return -1; - - /* check if delivery file has bad ownership or permissions */ - if (fstat (fileno (fp), &st) == -1 - || (st.st_uid != 0 && (su || st.st_uid != pw->pw_uid)) - || st.st_mode & (S_IWGRP|S_IWOTH)) { - if (verbose) { - verbose_printf ("WARNING: %s has bad ownership/modes (su=%d,uid=%d,owner=%d,mode=0%o)\n", - delivery, su, (int) pw->pw_uid, (int) st.st_uid, (int) st.st_mode); - } - return -1; - } - - won = 0; - next = 1; - - /* read and process delivery file */ - while (fgets (buffer, sizeof(buffer), fp)) { - /* skip comments and empty lines */ - if (*buffer == '#' || *buffer == '\n') - continue; - - /* zap trailing newline */ - if ((cp = strchr(buffer, '\n'))) - *cp = 0; - - /* split buffer into fields */ - vecp = split (buffer, vec); - - /* check for too few fields */ - if (vecp < 5) { - if (debug) - debug_printf ("WARNING: entry with only %d fields, skipping.\n", vecp); - continue; - } + int i, accept, status=1, won, vecp, next; + char *field, *pattern, *action, *result, *string; + char buffer[BUFSIZ], tmpbuf[BUFSIZ]; + char *cp, *vec[NVEC]; + struct stat st; + struct pair *p; + FILE *fp; + + /* open the delivery file */ + if ((fp = fopen (delivery, "r")) == NULL) + return -1; - if (debug) { - for (i = 0; vec[i]; i++) - debug_printf ("vec[%d]: \"%s\"\n", i, trim(vec[i])); + /* check if delivery file has bad ownership or permissions */ + if (fstat (fileno (fp), &st) == -1 + || (st.st_uid != 0 && (su || st.st_uid != pw->pw_uid)) + || st.st_mode & (S_IWGRP|S_IWOTH)) { + if (verbose) { + verbose_printf ("WARNING: %s has bad ownership/modes (su=%d,uid=%d,owner=%d,mode=0%o)\n", + delivery, su, (int) pw->pw_uid, (int) st.st_uid, (int) st.st_mode); + } + return -1; } - field = vec[0]; - pattern = vec[1]; - action = vec[2]; - result = vec[3]; - string = vec[4]; - - /* find out how to perform the action */ - switch (result[0]) { - case 'N': - case 'n': - /* - * If previous condition failed, don't - * do this - else fall through - */ - if (!next) - continue; /* else fall */ - - case '?': - /* - * If already delivered, skip this action. Else - * consider delivered if action is successful. - */ - if (won) - continue; /* else fall */ - - case 'A': - case 'a': - /* - * Take action, and consider delivered if - * action is successful. - */ - accept = 1; - break; + won = 0; + next = 1; - case 'R': - case 'r': - default: - /* - * Take action, but don't consider delivered, even - * if action is successful - */ - accept = 0; - break; - } + /* read and process delivery file */ + while (fgets (buffer, sizeof(buffer), fp)) { + /* skip comments and empty lines */ + if (*buffer == '#' || *buffer == '\n') + continue; - if (vecp > 5) { - if (!mh_strcasecmp (vec[5], "select")) { - if (logged_in () != -1) - continue; - if (vecp > 7 && timely (vec[6], vec[7]) == -1) - continue; - } - } + /* zap trailing newline */ + if ((cp = strchr(buffer, '\n'))) + *cp = 0; - /* check if the field matches */ - switch (*field) { - case '*': - /* always matches */ - break; + /* split buffer into fields */ + vecp = split (buffer, vec); - case 'd': - /* - * "default" matches only if the message hasn't - * been delivered yet. - */ - if (!mh_strcasecmp (field, "default")) { - if (won) + /* check for too few fields */ + if (vecp < 5) { + if (debug) + debug_printf ("WARNING: entry with only %d fields, skipping.\n", vecp); continue; - break; - } /* else fall */ - - default: - /* parse message and build lookup table */ - if (!parsed && parse (fd) == -1) { - fclose (fp); - return -1; } - /* - * find header field in lookup table, and - * see if the pattern matches. - */ - if ((p = lookup (hdrs, field)) && (p->p_value != NULL) - && matches (p->p_value, pattern)) { - next = 1; - } else { - next = 0; - continue; + + if (debug) { + for (i = 0; vec[i]; i++) + debug_printf ("vec[%d]: \"%s\"\n", i, trim(vec[i])); } - break; - } - /* find out the action to perform */ - switch (*action) { - case 'q': - /* deliver to quoted pipe */ - if (mh_strcasecmp (action, "qpipe")) - continue; /* else fall */ - case '^': - expand (tmpbuf, string, fd); - if (split (tmpbuf, vec) < 1) - continue; - status = usr_pipe (fd, tmpbuf, vec[0], vec, 0); - break; + field = vec[0]; + pattern = vec[1]; + action = vec[2]; + result = vec[3]; + string = vec[4]; + + /* find out how to perform the action */ + switch (result[0]) { + case 'N': + case 'n': + /* + * If previous condition failed, don't + * do this - else fall through + */ + if (!next) + continue; /* else fall */ + + case '?': + /* + * If already delivered, skip this action. Else + * consider delivered if action is successful. + */ + if (won) + continue; /* else fall */ + + case 'A': + case 'a': + /* + * Take action, and consider delivered if + * action is successful. + */ + accept = 1; + break; + + case 'R': + case 'r': + default: + /* + * Take action, but don't consider delivered, even + * if action is successful + */ + accept = 0; + break; + } - case 'p': - /* deliver to pipe */ - if (mh_strcasecmp (action, "pipe")) - continue; /* else fall */ - case '|': - vec[2] = "sh"; - vec[3] = "-c"; - expand (tmpbuf, string, fd); - vec[4] = tmpbuf; - vec[5] = NULL; - status = usr_pipe (fd, tmpbuf, "/bin/sh", vec + 2, 0); - break; + if (vecp > 5) { + if (!mh_strcasecmp (vec[5], "select")) { + if (logged_in () != -1) + continue; + if (vecp > 7 && timely (vec[6], vec[7]) == -1) + continue; + } + } - case 'f': - /* mbox format */ - if (!mh_strcasecmp (action, "file")) { - status = usr_file (fd, string, MBOX_FORMAT); - break; + /* check if the field matches */ + switch (*field) { + case '*': + /* always matches */ + break; + + case 'd': + /* + * "default" matches only if the message hasn't + * been delivered yet. + */ + if (!mh_strcasecmp (field, "default")) { + if (won) + continue; + break; + } /* else fall */ + + default: + /* parse message and build lookup table */ + if (!parsed && parse (fd) == -1) { + fclose (fp); + return -1; + } + /* + * find header field in lookup table, and + * see if the pattern matches. + */ + if ((p = lookup (hdrs, field)) && (p->p_value != NULL) + && matches (p->p_value, pattern)) { + next = 1; + } else { + next = 0; + continue; + } + break; } - /* deliver to nmh folder */ - else if (mh_strcasecmp (action, "folder")) - continue; /* else fall */ - case '+': - status = usr_folder (fd, string); - break; - case 'm': - /* mmdf format */ - if (!mh_strcasecmp (action, "mmdf")) { - status = usr_file (fd, string, MMDF_FORMAT); - break; + /* find out the action to perform */ + switch (*action) { + case 'q': + /* deliver to quoted pipe */ + if (mh_strcasecmp (action, "qpipe")) + continue; /* else fall */ + case '^': + expand (tmpbuf, string, fd); + if (split (tmpbuf, vec) < 1) + continue; + status = usr_pipe (fd, tmpbuf, vec[0], vec, 0); + break; + + case 'p': + /* deliver to pipe */ + if (mh_strcasecmp (action, "pipe")) + continue; /* else fall */ + case '|': + vec[2] = "sh"; + vec[3] = "-c"; + expand (tmpbuf, string, fd); + vec[4] = tmpbuf; + vec[5] = NULL; + status = usr_pipe (fd, tmpbuf, "/bin/sh", vec + 2, 0); + break; + + case 'f': + /* mbox format */ + if (!mh_strcasecmp (action, "file")) { + status = usr_file (fd, string, MBOX_FORMAT); + break; + } + /* deliver to nmh folder */ + else if (mh_strcasecmp (action, "folder")) + continue; /* else fall */ + case '+': + status = usr_folder (fd, string); + break; + + case 'm': + /* mmdf format */ + if (!mh_strcasecmp (action, "mmdf")) { + status = usr_file (fd, string, MMDF_FORMAT); + break; + } + /* mbox format */ + else if (mh_strcasecmp (action, "mbox")) + continue; /* else fall */ + + case '>': + /* mbox format */ + status = usr_file (fd, string, MBOX_FORMAT); + break; + + case 'd': + /* ignore message */ + if (mh_strcasecmp (action, "destroy")) + continue; + status = 0; + break; } - /* mbox format */ - else if (mh_strcasecmp (action, "mbox")) - continue; /* else fall */ - case '>': - /* mbox format */ - status = usr_file (fd, string, MBOX_FORMAT); - break; + if (status) next = 0; /* action failed, mark for 'N' result */ - case 'd': - /* ignore message */ - if (mh_strcasecmp (action, "destroy")) - continue; - status = 0; - break; + if (accept && status == 0) + won++; } - if (status) next = 0; /* action failed, mark for 'N' result */ - - if (accept && status == 0) - won++; - } - - fclose (fp); - return (won ? 0 : -1); + fclose (fp); + return (won ? 0 : -1); } -#define QUOTE '\\' +#define QUOTE '\\' /* * Split buffer into fields (delimited by whitespace or @@ -681,52 +684,52 @@ usr_delivery (int fd, char *delivery, int su) static int split (char *cp, char **vec) { - int i; - unsigned char *s; + int i; + unsigned char *s; - s = cp; + s = cp; - /* split into a maximum of NVEC fields */ - for (i = 0; i <= NVEC;) { - vec[i] = NULL; + /* split into a maximum of NVEC fields */ + for (i = 0; i <= NVEC;) { + vec[i] = NULL; - /* zap any whitespace and comma's */ - while (isspace (*s) || *s == ',') - *s++ = 0; - - /* end of buffer, time to leave */ - if (*s == 0) - break; - - /* get double quote text as a single field */ - if (*s == '"') { - for (vec[i++] = ++s; *s && *s != '"'; s++) { - /* - * Check for escaped double quote. We need - * to shift the string to remove slash. - */ - if (*s == QUOTE) { - if (*++s == '"') - strcpy (s - 1, s); - s--; + /* zap any whitespace and comma's */ + while (isspace (*s) || *s == ',') + *s++ = 0; + + /* end of buffer, time to leave */ + if (*s == 0) + break; + + /* get double quote text as a single field */ + if (*s == '"') { + for (vec[i++] = ++s; *s && *s != '"'; s++) { + /* + * Check for escaped double quote. We need + * to shift the string to remove slash. + */ + if (*s == QUOTE) { + if (*++s == '"') + strcpy (s - 1, s); + s--; + } + } + if (*s == '"') /* zap trailing double quote */ + *s++ = 0; + continue; } - } - if (*s == '"') /* zap trailing double quote */ - *s++ = 0; - continue; - } - if (*s == QUOTE && *++s != '"') - s--; - vec[i++] = s++; + if (*s == QUOTE && *++s != '"') + s--; + vec[i++] = s++; - /* move forward to next field delimiter */ - while (*s && !isspace (*s) && *s != ',') - s++; - } - vec[i] = NULL; + /* move forward to next field delimiter */ + while (*s && !isspace (*s) && *s != ',') + s++; + } + vec[i] = NULL; - return i; + return i; } @@ -738,115 +741,115 @@ split (char *cp, char **vec) static int parse (int fd) { - int i, state; - int fd1; - char *cp, *dp, *lp; - char name[NAMESZ], field[BUFSIZ]; - struct pair *p, *q; - FILE *in; - - if (parsed++) - return 0; - - /* get a new FILE pointer to message */ - if ((fd1 = dup (fd)) == -1) - return -1; - if ((in = fdopen (fd1, "r")) == NULL) { - close (fd1); - return -1; - } - rewind (in); - - /* add special entries to lookup table */ - if ((p = lookup (hdrs, "source"))) - p->p_value = getcpy (sender); - if ((p = lookup (hdrs, "addr"))) - p->p_value = getcpy (addr); - - /* - * Scan the headers of the message and build - * a lookup table. - */ - for (i = 0, state = FLD;;) { - switch (state = m_getfld (state, name, field, sizeof(field), in)) { - case FLD: - case FLDEOF: - case FLDPLUS: - lp = add (field, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, field, sizeof(field), in); - lp = add (field, lp); - } - for (p = hdrs; p->p_name; p++) { - if (!mh_strcasecmp (p->p_name, name)) { - if (!(p->p_flags & P_HID)) { - if ((cp = p->p_value)) { - if (p->p_flags & P_ADR) { - dp = cp + strlen (cp) - 1; - if (*dp == '\n') - *dp = 0; - cp = add (",\n\t", cp); - } else { - cp = add ("\t", cp); + int i, state; + int fd1; + char *cp, *dp, *lp; + char name[NAMESZ], field[BUFSIZ]; + struct pair *p, *q; + FILE *in; + + if (parsed++) + return 0; + + /* get a new FILE pointer to message */ + if ((fd1 = dup (fd)) == -1) + return -1; + if ((in = fdopen (fd1, "r")) == NULL) { + close (fd1); + return -1; + } + rewind (in); + + /* add special entries to lookup table */ + if ((p = lookup (hdrs, "source"))) + p->p_value = getcpy (sender); + if ((p = lookup (hdrs, "addr"))) + p->p_value = getcpy (addr); + + /* + * Scan the headers of the message and build + * a lookup table. + */ + for (i = 0, state = FLD;;) { + switch (state = m_getfld (state, name, field, sizeof(field), in)) { + case FLD: + case FLDEOF: + case FLDPLUS: + lp = add (field, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, field, sizeof(field), in); + lp = add (field, lp); } - } - p->p_value = add (lp, cp); - } - free (lp); - break; - } - } - if (p->p_name == NULL && i < NVEC) { - p->p_name = getcpy (name); - p->p_value = lp; - p->p_flags = P_NIL; - p++, i++; - p->p_name = NULL; + for (p = hdrs; p->p_name; p++) { + if (!mh_strcasecmp (p->p_name, name)) { + if (!(p->p_flags & P_HID)) { + if ((cp = p->p_value)) { + if (p->p_flags & P_ADR) { + dp = cp + strlen (cp) - 1; + if (*dp == '\n') + *dp = 0; + cp = add (",\n\t", cp); + } else { + cp = add ("\t", cp); + } + } + p->p_value = add (lp, cp); + } + free (lp); + break; + } + } + if (p->p_name == NULL && i < NVEC) { + p->p_name = getcpy (name); + p->p_value = lp; + p->p_flags = P_NIL; + p++, i++; + p->p_name = NULL; + } + if (state != FLDEOF) + continue; + break; + + case BODY: + case BODYEOF: + case FILEEOF: + break; + + case LENERR: + case FMTERR: + advise (NULL, "format error in message"); + break; + + default: + advise (NULL, "internal error in m_getfld"); + fclose (in); + return -1; } - if (state != FLDEOF) - continue; - break; - - case BODY: - case BODYEOF: - case FILEEOF: break; - - case LENERR: - case FMTERR: - advise (NULL, "format error in message"); - break; - - default: - advise (NULL, "internal error in m_getfld"); - fclose (in); - return -1; } - break; - } - fclose (in); - - if ((p = lookup (vars, "reply-to"))) { - if ((q = lookup (hdrs, "reply-to")) == NULL || q->p_value == NULL) - q = lookup (hdrs, "from"); - p->p_value = getcpy (q ? q->p_value : ""); - p->p_flags &= ~P_CHK; - if (debug) - debug_printf ("vars[%d]: name=\"%s\" value=\"%s\"\n", - p - vars, p->p_name, trim(p->p_value)); - } - if (debug) { - for (p = hdrs; p->p_name; p++) - debug_printf ("hdrs[%d]: name=\"%s\" value=\"%s\"\n", - p - hdrs, p->p_name, p->p_value ? trim(p->p_value) : ""); - } - - return 0; + fclose (in); + + if ((p = lookup (vars, "reply-to"))) { + if ((q = lookup (hdrs, "reply-to")) == NULL || q->p_value == NULL) + q = lookup (hdrs, "from"); + p->p_value = getcpy (q ? q->p_value : ""); + p->p_flags &= ~P_CHK; + if (debug) + debug_printf ("vars[%d]: name=\"%s\" value=\"%s\"\n", + p - vars, p->p_name, trim(p->p_value)); + } + if (debug) { + for (p = hdrs; p->p_name; p++) + debug_printf ("hdrs[%d]: name=\"%s\" value=\"%s\"\n", + p - hdrs, p->p_name, p->p_value ? trim(p->p_value) : ""); + } + + return 0; } -#define LPAREN '(' -#define RPAREN ')' +#define LPAREN '(' +#define RPAREN ')' /* * Expand any builtin variables such as $(sender), @@ -856,33 +859,33 @@ parse (int fd) static void expand (char *s1, char *s2, int fd) { - char c, *cp; - struct pair *p; + char c, *cp; + struct pair *p; - if (!globbed) - glob (fd); + if (!globbed) + glob (fd); - while ((c = *s2++)) { - if (c != '$' || *s2 != LPAREN) { - *s1++ = c; - } else { - for (cp = ++s2; *s2 && *s2 != RPAREN; s2++) - continue; - if (*s2 != RPAREN) { - s2 = --cp; - continue; - } - *s2++ = 0; - if ((p = lookup (vars, cp))) { - if (!parsed && (p->p_flags & P_CHK)) - parse (fd); - - strcpy (s1, p->p_value); - s1 += strlen (s1); - } + while ((c = *s2++)) { + if (c != '$' || *s2 != LPAREN) { + *s1++ = c; + } else { + for (cp = ++s2; *s2 && *s2 != RPAREN; s2++) + continue; + if (*s2 != RPAREN) { + s2 = --cp; + continue; + } + *s2++ = 0; + if ((p = lookup (vars, cp))) { + if (!parsed && (p->p_flags & P_CHK)) + parse (fd); + + strcpy (s1, p->p_value); + s1 += strlen (s1); + } + } } - } - *s1 = 0; + *s1 = 0; } @@ -896,30 +899,30 @@ expand (char *s1, char *s2, int fd) static void glob (int fd) { - char buffer[BUFSIZ]; - struct stat st; - struct pair *p; - - if (globbed++) - return; - - if ((p = lookup (vars, "sender"))) - p->p_value = getcpy (sender); - if ((p = lookup (vars, "address"))) - p->p_value = getcpy (addr); - if ((p = lookup (vars, "size"))) { - snprintf (buffer, sizeof(buffer), "%d", - fstat (fd, &st) != -1 ? (int) st.st_size : 0); - p->p_value = getcpy (buffer); - } - if ((p = lookup (vars, "info"))) - p->p_value = getcpy (info); - - if (debug) { - for (p = vars; p->p_name; p++) - debug_printf ("vars[%d]: name=\"%s\" value=\"%s\"\n", - p - vars, p->p_name, trim(p->p_value)); - } + char buffer[BUFSIZ]; + struct stat st; + struct pair *p; + + if (globbed++) + return; + + if ((p = lookup (vars, "sender"))) + p->p_value = getcpy (sender); + if ((p = lookup (vars, "address"))) + p->p_value = getcpy (addr); + if ((p = lookup (vars, "size"))) { + snprintf (buffer, sizeof(buffer), "%d", + fstat (fd, &st) != -1 ? (int) st.st_size : 0); + p->p_value = getcpy (buffer); + } + if ((p = lookup (vars, "info"))) + p->p_value = getcpy (info); + + if (debug) { + for (p = vars; p->p_name; p++) + debug_printf ("vars[%d]: name=\"%s\" value=\"%s\"\n", + p - vars, p->p_name, trim(p->p_value)); + } } @@ -931,11 +934,11 @@ glob (int fd) static struct pair * lookup (struct pair *pairs, char *key) { - for (; pairs->p_name; pairs++) - if (!mh_strcasecmp (pairs->p_name, key)) - return pairs; + for (; pairs->p_name; pairs++) + if (!mh_strcasecmp (pairs->p_name, key)) + return pairs; - return NULL; + return NULL; } @@ -948,81 +951,81 @@ lookup (struct pair *pairs, char *key) static int logged_in (void) { - struct utmp * utp; + struct utmp * utp; - if (utmped) - return utmped; + if (utmped) + return utmped; - setutent(); + setutent(); - while ((utp = getutent()) != NULL) { - if ( + while ((utp = getutent()) != NULL) { + if ( #ifdef HAVE_STRUCT_UTMP_UT_TYPE - utp->ut_type == USER_PROCESS - && + utp->ut_type == USER_PROCESS + && #endif - utp->ut_name[0] != 0 - && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { - if (debug) - continue; - endutent(); - return (utmped = DONE); - } - } - - endutent(); - return (utmped = NOTOK); + utp->ut_name[0] != 0 + && strncmp (user, utp->ut_name, sizeof(utp->ut_name)) == 0) { + if (debug) + continue; + endutent(); + return (utmped = DONE); + } + } + + endutent(); + return (utmped = NOTOK); } #else static int logged_in (void) { - struct utmp ut; - FILE *uf; - - if (utmped) - return utmped; - - if ((uf = fopen (UTMP_FILE, "r")) == NULL) - return NOTOK; - - while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) { - if (ut.ut_name[0] != 0 - && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { - if (debug) - continue; - fclose (uf); - return (utmped = DONE); + struct utmp ut; + FILE *uf; + + if (utmped) + return utmped; + + if ((uf = fopen (UTMP_FILE, "r")) == NULL) + return NOTOK; + + while (fread ((char *) &ut, sizeof(ut), 1, uf) == 1) { + if (ut.ut_name[0] != 0 + && strncmp (user, ut.ut_name, sizeof(ut.ut_name)) == 0) { + if (debug) + continue; + fclose (uf); + return (utmped = DONE); + } } - } - fclose (uf); - return (utmped = NOTOK); + fclose (uf); + return (utmped = NOTOK); } #endif -#define check(t,a,b) if (t < a || t > b) return -1 -#define cmpar(h1,m1,h2,m2) if (h1 < h2 || (h1 == h2 && m1 < m2)) return 0 +#define check(t,a,b) if (t < a || t > b) return -1 +#define cmpar(h1,m1,h2,m2) if (h1 < h2 || (h1 == h2 && m1 < m2)) return 0 static int timely (char *t1, char *t2) { - int t1hours, t1mins, t2hours, t2mins; + int t1hours, t1mins, t2hours, t2mins; - if (sscanf (t1, "%d:%d", &t1hours, &t1mins) != 2) - return -1; - check (t1hours, 0, 23); - check (t1mins, 0, 59); + if (sscanf (t1, "%d:%d", &t1hours, &t1mins) != 2) + return -1; + check (t1hours, 0, 23); + check (t1mins, 0, 59); - if (sscanf (t2, "%d:%d", &t2hours, &t2mins) != 2) - return -1; - check (t2hours, 0, 23); - check (t2mins, 0, 59); + if (sscanf (t2, "%d:%d", &t2hours, &t2mins) != 2) + return -1; + check (t2hours, 0, 23); + check (t2mins, 0, 59); - cmpar (now->tw_hour, now->tw_min, t1hours, t1mins); - cmpar (t2hours, t2mins, now->tw_hour, now->tw_min); + cmpar (now->tw_hour, now->tw_min, t1hours, t1mins); + cmpar (t2hours, t2mins, now->tw_hour, now->tw_min); - return -1; + return -1; } @@ -1033,47 +1036,47 @@ timely (char *t1, char *t2) static int usr_file (int fd, char *mailbox, int mbx_style) { - int md, mapping; - - if (verbose) - verbose_printf ("delivering to file \"%s\"", mailbox); + int md, mapping; - if (mbx_style == MBOX_FORMAT) { - if (verbose) - verbose_printf (" (mbox style)"); - mapping = 0; - } else { if (verbose) - verbose_printf (" (mmdf style)"); - mapping = 1; - } + verbose_printf ("delivering to file \"%s\"", mailbox); - /* open and lock the file */ - if ((md = mbx_open (mailbox, mbx_style, pw->pw_uid, pw->pw_gid, m_gmprot())) == -1) { - if (verbose) - adorn ("", "unable to open:"); - return -1; - } + if (mbx_style == MBOX_FORMAT) { + if (verbose) + verbose_printf (" (mbox style)"); + mapping = 0; + } else { + if (verbose) + verbose_printf (" (mmdf style)"); + mapping = 1; + } + + /* open and lock the file */ + if ((md = mbx_open (mailbox, mbx_style, pw->pw_uid, pw->pw_gid, m_gmprot())) == -1) { + if (verbose) + adorn ("", "unable to open:"); + return -1; + } + + lseek (fd, (off_t) 0, SEEK_SET); + + /* append message to file */ + if (mbx_copy (mailbox, mbx_style, md, fd, mapping, NULL, verbose) == -1) { + if (verbose) + adorn ("", "error writing to:"); + return -1; + } - lseek (fd, (off_t) 0, SEEK_SET); + /* close and unlock file */ + if (mbx_close (mailbox, md) == NOTOK) { + if (verbose) + adorn ("", "error closing:"); + return -1; + } - /* append message to file */ - if (mbx_copy (mailbox, mbx_style, md, fd, mapping, NULL, verbose) == -1) { if (verbose) - adorn ("", "error writing to:"); - return -1; - } - - /* close and unlock file */ - if (mbx_close (mailbox, md) == NOTOK) { - if (verbose) - adorn ("", "error closing:"); - return -1; - } - - if (verbose) - verbose_printf (", success.\n"); - return 0; + verbose_printf (", success.\n"); + return 0; } @@ -1084,38 +1087,38 @@ usr_file (int fd, char *mailbox, int mbx_style) static int usr_folder (int fd, char *string) { - int status; - char folder[BUFSIZ], *vec[3]; + int status; + char folder[BUFSIZ], *vec[3]; - /* get folder name ready */ - if (*string == '+') - strncpy(folder, string, sizeof(folder)); - else - snprintf(folder, sizeof(folder), "+%s", string); + /* get folder name ready */ + if (*string == '+') + strncpy(folder, string, sizeof(folder)); + else + snprintf(folder, sizeof(folder), "+%s", string); - if (verbose) - verbose_printf ("delivering to folder \"%s\"", folder + 1); + if (verbose) + verbose_printf ("delivering to folder \"%s\"", folder + 1); - vec[0] = "rcvstore"; - vec[1] = folder; - vec[2] = NULL; + vec[0] = "rcvstore"; + vec[1] = folder; + vec[2] = NULL; - /* use rcvstore to put message in folder */ - status = usr_pipe (fd, "rcvstore", rcvstoreproc, vec, 1); + /* use rcvstore to put message in folder */ + status = usr_pipe (fd, "rcvstore", rcvstoreproc, vec, 1); #if 0 - /* - * Currently, verbose status messages are handled by usr_pipe(). - */ - if (verbose) { - if (status == 0) - verbose_printf (", success.\n"); - else - verbose_printf (", failed.\n"); - } + /* + * Currently, verbose status messages are handled by usr_pipe(). + */ + if (verbose) { + if (status == 0) + verbose_printf (", success.\n"); + else + verbose_printf (", failed.\n"); + } #endif - return status; + return status; } /* @@ -1125,93 +1128,93 @@ usr_folder (int fd, char *string) static int usr_pipe (int fd, char *cmd, char *pgm, char **vec, int suppress) { - pid_t child_id; - int i, bytes, seconds, status; - struct stat st; - - if (verbose && !suppress) - verbose_printf ("delivering to pipe \"%s\"", cmd); - - lseek (fd, (off_t) 0, SEEK_SET); - - for (i = 0; (child_id = fork()) == -1 && i < 5; i++) - sleep (5); - - switch (child_id) { - case -1: - /* fork error */ - if (verbose) - adorn ("fork", "unable to"); - return -1; - - case 0: - /* child process */ - if (fd != 0) - dup2 (fd, 0); - freopen ("/dev/null", "w", stdout); - freopen ("/dev/null", "w", stderr); - if (fd != 3) - dup2 (fd, 3); - closefds (4); + pid_t child_id; + int i, bytes, seconds, status; + struct stat st; + + if (verbose && !suppress) + verbose_printf ("delivering to pipe \"%s\"", cmd); + + lseek (fd, (off_t) 0, SEEK_SET); + + for (i = 0; (child_id = fork()) == -1 && i < 5; i++) + sleep (5); + + switch (child_id) { + case -1: + /* fork error */ + if (verbose) + adorn ("fork", "unable to"); + return -1; + + case 0: + /* child process */ + if (fd != 0) + dup2 (fd, 0); + freopen ("/dev/null", "w", stdout); + freopen ("/dev/null", "w", stderr); + if (fd != 3) + dup2 (fd, 3); + closefds (4); #ifdef TIOCNOTTY - if ((fd = open ("/dev/tty", O_RDWR)) != -1) { - ioctl (fd, TIOCNOTTY, NULL); - close (fd); - } + if ((fd = open ("/dev/tty", O_RDWR)) != -1) { + ioctl (fd, TIOCNOTTY, NULL); + close (fd); + } #endif /* TIOCNOTTY */ - setpgid ((pid_t) 0, getpid ()); /* put in own process group */ - - *environ = NULL; - m_putenv ("USER", pw->pw_name); - m_putenv ("HOME", pw->pw_dir); - m_putenv ("SHELL", pw->pw_shell); - - execvp (pgm, vec); - _exit (-1); - - default: - /* parent process */ - if (!setjmp (myctx)) { - SIGNAL (SIGALRM, alrmser); - bytes = fstat (fd, &st) != -1 ? (int) st.st_size : 100; - - /* amount of time to wait depends on message size */ - if (bytes <= 100) { - /* give at least 5 minutes */ - seconds = 300; - } else if (bytes >= 90000) { - /* a half hour is long enough */ - seconds = 1800; - } else { - seconds = (bytes / 60) + 300; - } - alarm ((unsigned int) seconds); - status = pidwait (child_id, 0); - alarm (0); - - if (verbose) { - if (status == 0) - verbose_printf (", success.\n"); - else - if ((status & 0xff00) == 0xff00) - verbose_printf (", system error\n"); - else - pidstatus (status, stdout, ", failed"); - } - return (status == 0 ? 0 : -1); - } else { - /* - * Ruthlessly kill the child and anything - * else in its process group. - */ - KILLPG(child_id, SIGKILL); - if (verbose) - verbose_printf (", timed-out; terminated\n"); - return -1; - } - } + setpgid ((pid_t) 0, getpid ()); /* put in own process group */ + + *environ = NULL; + m_putenv ("USER", pw->pw_name); + m_putenv ("HOME", pw->pw_dir); + m_putenv ("SHELL", pw->pw_shell); + + execvp (pgm, vec); + _exit (-1); + + default: + /* parent process */ + if (!setjmp (myctx)) { + SIGNAL (SIGALRM, alrmser); + bytes = fstat (fd, &st) != -1 ? (int) st.st_size : 100; + + /* amount of time to wait depends on message size */ + if (bytes <= 100) { + /* give at least 5 minutes */ + seconds = 300; + } else if (bytes >= 90000) { + /* a half hour is long enough */ + seconds = 1800; + } else { + seconds = (bytes / 60) + 300; + } + alarm ((unsigned int) seconds); + status = pidwait (child_id, 0); + alarm (0); + + if (verbose) { + if (status == 0) + verbose_printf (", success.\n"); + else + if ((status & 0xff00) == 0xff00) + verbose_printf (", system error\n"); + else + pidstatus (status, stdout, ", failed"); + } + return (status == 0 ? 0 : -1); + } else { + /* + * Ruthlessly kill the child and anything + * else in its process group. + */ + KILLPG(child_id, SIGKILL); + if (verbose) + verbose_printf (", timed-out; terminated\n"); + return -1; + } + } } @@ -1219,10 +1222,10 @@ static RETSIGTYPE alrmser (int i) { #ifndef RELIABLE_SIGNALS - SIGNAL (SIGALRM, alrmser); + SIGNAL (SIGALRM, alrmser); #endif - longjmp (myctx, DONE); + longjmp (myctx, DONE); } @@ -1234,33 +1237,33 @@ alrmser (int i) static void get_sender (char *envelope, char **sender) { - int i; - unsigned char *cp; - unsigned char buffer[BUFSIZ]; - - if (envelope == NULL) { - *sender = getcpy (""); - return; - } - - i = strlen ("From "); - strncpy (buffer, envelope + i, sizeof(buffer)); - if ((cp = strchr(buffer, '\n'))) { + int i; + unsigned char *cp; + unsigned char buffer[BUFSIZ]; + + if (envelope == NULL) { + *sender = getcpy (""); + return; + } + + i = strlen ("From "); + strncpy (buffer, envelope + i, sizeof(buffer)); + if ((cp = strchr(buffer, '\n'))) { + *cp = 0; + cp -= 24; + if (cp < buffer) + cp = buffer; + } else { + cp = buffer; + } *cp = 0; - cp -= 24; - if (cp < buffer) - cp = buffer; - } else { - cp = buffer; - } - *cp = 0; - - for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--) - if (isspace (*cp)) - *cp = 0; - else - break; - *sender = getcpy (buffer); + + for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--) + if (isspace (*cp)) + *cp = 0; + else + break; + *sender = getcpy (buffer); } @@ -1273,138 +1276,138 @@ get_sender (char *envelope, char **sender) static int copy_message (int qd, char *tmpfil, int fold) { - int i, first = 1, fd1, fd2; - char buffer[BUFSIZ]; - FILE *qfp, *ffp; - char *tfile = NULL; - - tfile = m_mktemp2(NULL, invo_name, &fd1, NULL); - if (tfile == NULL) return -1; - fchmod(fd1, 0600); - strncpy (tmpfil, tfile, BUFSIZ); - - if (!fold) { - while ((i = read (qd, buffer, sizeof(buffer))) > 0) - if (write (fd1, buffer, i) != i) { + int i, first = 1, fd1, fd2; + char buffer[BUFSIZ]; + FILE *qfp, *ffp; + char *tfile = NULL; + + tfile = m_mktemp2(NULL, invo_name, &fd1, NULL); + if (tfile == NULL) return -1; + fchmod(fd1, 0600); + strncpy (tmpfil, tfile, BUFSIZ); + + if (!fold) { + while ((i = read (qd, buffer, sizeof(buffer))) > 0) + if (write (fd1, buffer, i) != i) { you_lose: + close (fd1); + unlink (tmpfil); + return -1; + } + if (i == -1) + goto you_lose; + lseek (fd1, (off_t) 0, SEEK_SET); + return fd1; + } + + /* dup the fd for incoming message */ + if ((fd2 = dup (qd)) == -1) { close (fd1); - unlink (tmpfil); return -1; - } - if (i == -1) - goto you_lose; - lseek (fd1, (off_t) 0, SEEK_SET); - return fd1; - } + } - /* dup the fd for incoming message */ - if ((fd2 = dup (qd)) == -1) { - close (fd1); - return -1; - } + /* now create a FILE pointer for it */ + if ((qfp = fdopen (fd2, "r")) == NULL) { + close (fd1); + close (fd2); + return -1; + } - /* now create a FILE pointer for it */ - if ((qfp = fdopen (fd2, "r")) == NULL) { - close (fd1); - close (fd2); - return -1; - } + /* dup the fd for temporary file */ + if ((fd2 = dup (fd1)) == -1) { + close (fd1); + fclose (qfp); + return -1; + } - /* dup the fd for temporary file */ - if ((fd2 = dup (fd1)) == -1) { - close (fd1); - fclose (qfp); - return -1; - } + /* now create a FILE pointer for it */ + if ((ffp = fdopen (fd2, "r+")) == NULL) { + close (fd1); + close (fd2); + fclose (qfp); + return -1; + } - /* now create a FILE pointer for it */ - if ((ffp = fdopen (fd2, "r+")) == NULL) { - close (fd1); - close (fd2); - fclose (qfp); - return -1; - } - - /* - * copy message into temporary file - * and massage the headers. Save - * a copy of the "From " line for later. - */ - i = strlen ("From "); - while (fgets (buffer, sizeof(buffer), qfp)) { - if (first) { - first = 0; - if (!strncmp (buffer, "From ", i)) { + /* + * copy message into temporary file + * and massage the headers. Save + * a copy of the "From " line for later. + */ + i = strlen ("From "); + while (fgets (buffer, sizeof(buffer), qfp)) { + if (first) { + first = 0; + if (!strncmp (buffer, "From ", i)) { #ifdef RPATHS - char *fp, *cp, *hp, *ep; + char *fp, *cp, *hp, *ep; #endif - /* get copy of envelope information ("From " line) */ - envelope = getcpy (buffer); + /* get copy of envelope information ("From " line) */ + envelope = getcpy (buffer); #if 0 - /* First go ahead and put "From " line in message */ - fputs (buffer, ffp); - if (ferror (ffp)) - goto fputs_error; + /* First go ahead and put "From " line in message */ + fputs (buffer, ffp); + if (ferror (ffp)) + goto fputs_error; #endif #ifdef RPATHS - /* - * Now create a "Return-Path:" line - * from the "From " line. - */ - hp = cp = strchr(fp = envelope + i, ' '); - while ((hp = strchr(++hp, 'r'))) - if (uprf (hp, "remote from")) { - hp = strrchr(hp, ' '); - break; - } - if (hp) { - /* return path for UUCP style addressing */ - ep = strchr(++hp, '\n'); - snprintf (buffer, sizeof(buffer), "Return-Path: %.*s!%.*s\n", - (int)(ep - hp), hp, (int)(cp - fp), fp); - } else { - /* return path for standard domain addressing */ - snprintf (buffer, sizeof(buffer), "Return-Path: %.*s\n", - (int)(cp - fp), fp); + /* + * Now create a "Return-Path:" line + * from the "From " line. + */ + hp = cp = strchr(fp = envelope + i, ' '); + while ((hp = strchr(++hp, 'r'))) + if (uprf (hp, "remote from")) { + hp = strrchr(hp, ' '); + break; + } + if (hp) { + /* return path for UUCP style addressing */ + ep = strchr(++hp, '\n'); + snprintf (buffer, sizeof(buffer), "Return-Path: %.*s!%.*s\n", + (int)(ep - hp), hp, (int)(cp - fp), fp); + } else { + /* return path for standard domain addressing */ + snprintf (buffer, sizeof(buffer), "Return-Path: %.*s\n", + (int)(cp - fp), fp); + } + + /* Add Return-Path header to message */ + fputs (buffer, ffp); + if (ferror (ffp)) + goto fputs_error; +#endif + /* Put the delivery date in message */ + fputs (ddate, ffp); + if (ferror (ffp)) + goto fputs_error; + + continue; + } } - /* Add Return-Path header to message */ fputs (buffer, ffp); if (ferror (ffp)) - goto fputs_error; -#endif - /* Put the delivery date in message */ - fputs (ddate, ffp); - if (ferror (ffp)) - goto fputs_error; + goto fputs_error; + } - continue; - } + fclose (ffp); + if (ferror (qfp)) { + close (fd1); + fclose (qfp); + return -1; } + fclose (qfp); + lseek (fd1, (off_t) 0, SEEK_SET); + return fd1; - fputs (buffer, ffp); - if (ferror (ffp)) - goto fputs_error; - } - fclose (ffp); - if (ferror (qfp)) { +fputs_error: close (fd1); + fclose (ffp); fclose (qfp); return -1; - } - fclose (qfp); - lseek (fd1, (off_t) 0, SEEK_SET); - return fd1; - - -fputs_error: - close (fd1); - fclose (ffp); - fclose (qfp); - return -1; } /* @@ -1414,35 +1417,35 @@ fputs_error: static char * trim (char *cp) { - char buffer[BUFSIZ*4]; - unsigned char *bp, *sp; + char buffer[BUFSIZ*4]; + unsigned char *bp, *sp; - if (cp == NULL) - return NULL; + if (cp == NULL) + return NULL; - /* copy string into temp buffer */ - strncpy (buffer, cp, sizeof(buffer)); - bp = buffer; + /* copy string into temp buffer */ + strncpy (buffer, cp, sizeof(buffer)); + bp = buffer; - /* skip over leading whitespace */ - while (isspace(*bp)) - bp++; + /* skip over leading whitespace */ + while (isspace(*bp)) + bp++; - /* start at the end and zap trailing whitespace */ - for (sp = bp + strlen(bp) - 1; sp >= bp; sp--) { - if (isspace(*sp)) - *sp = 0; - else - break; - } + /* start at the end and zap trailing whitespace */ + for (sp = bp + strlen(bp) - 1; sp >= bp; sp--) { + if (isspace(*sp)) + *sp = 0; + else + break; + } - /* replace remaining whitespace with spaces */ - for (sp = bp; *sp; sp++) - if (isspace(*sp)) - *sp = ' '; + /* replace remaining whitespace with spaces */ + for (sp = bp; *sp; sp++) + if (isspace(*sp)) + *sp = ' '; - /* now return a copy */ - return getcpy(bp); + /* now return a copy */ + return getcpy(bp); } /* @@ -1452,13 +1455,13 @@ trim (char *cp) static void verbose_printf (char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vfprintf (stdout, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf (stdout, fmt, ap); + va_end(ap); - fflush (stdout); /* now flush output */ + fflush (stdout); /* now flush output */ } @@ -1470,28 +1473,28 @@ verbose_printf (char *fmt, ...) static void adorn (char *what, char *fmt, ...) { - va_list ap; - int eindex; - char *s; - - eindex = errno; /* save the errno */ - fprintf (stdout, ", "); - - va_start(ap, fmt); - vfprintf (stdout, fmt, ap); - va_end(ap); - - if (what) { - if (*what) - fprintf (stdout, " %s: ", what); - if ((s = strerror (eindex))) - fprintf (stdout, "%s", s); - else - fprintf (stdout, "Error %d", eindex); - } + va_list ap; + int eindex; + char *s; + + eindex = errno; /* save the errno */ + fprintf (stdout, ", "); + + va_start(ap, fmt); + vfprintf (stdout, fmt, ap); + va_end(ap); + + if (what) { + if (*what) + fprintf (stdout, " %s: ", what); + if ((s = strerror (eindex))) + fprintf (stdout, "%s", s); + else + fprintf (stdout, "Error %d", eindex); + } - fputc ('\n', stdout); - fflush (stdout); + fputc ('\n', stdout); + fflush (stdout); } @@ -1502,11 +1505,11 @@ adorn (char *what, char *fmt, ...) static void debug_printf (char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vfprintf (stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf (stderr, fmt, ap); + va_end(ap); } @@ -1519,96 +1522,97 @@ debug_printf (char *fmt, ...) static int suppress_duplicates (int fd, char *file) { - int fd1, lockfd, state, result; - char *cp, buf[BUFSIZ], name[NAMESZ]; - datum key, value; - DBM *db; - FILE *in; - - if ((fd1 = dup (fd)) == -1) - return -1; - if (!(in = fdopen (fd1, "r"))) { - close (fd1); - return -1; - } - rewind (in); - - for (state = FLD;;) { - state = m_getfld (state, name, buf, sizeof(buf), in); - switch (state) { - case FLD: - case FLDPLUS: - case FLDEOF: - /* Search for the message ID */ - if (mh_strcasecmp (name, "Message-ID")) { - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), in); - continue; - } + int fd1, lockfd, state, result; + char *cp, buf[BUFSIZ], name[NAMESZ]; + datum key, value; + DBM *db; + FILE *in; - cp = add (buf, NULL); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); - cp = add (buf, cp); - } - key.dptr = trimcpy (cp); - key.dsize = strlen (key.dptr) + 1; - free (cp); - cp = key.dptr; - - if (!(db = dbm_open (file, O_RDWR | O_CREAT, 0600))) { - advise (file, "unable to perform dbm_open on"); - free (cp); - fclose (in); - return -1; - } - /* - * Since it is difficult to portable lock a ndbm file, - * we will open and lock the Maildelivery file instead. - * This will fail if your Maildelivery file doesn't - * exist. - */ - if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) { - advise (file, "unable to perform file locking on"); - free (cp); - fclose (in); - return -1; - } - value = dbm_fetch (db, key); - if (value.dptr) { - if (verbose) - verbose_printf ("Message-ID: %s\n already received on %s", - cp, value.dptr); - result = DONE; - } else { - value.dptr = ddate + sizeof("Delivery-Date:"); - value.dsize = strlen(value.dptr) + 1; - if (dbm_store (db, key, value, DBM_INSERT)) - advise (file, "possibly corrupt file"); - result = 0; - } + if ((fd1 = dup (fd)) == -1) + return -1; + if (!(in = fdopen (fd1, "r"))) { + close (fd1); + return -1; + } + rewind (in); + + for (state = FLD;;) { + state = m_getfld (state, name, buf, sizeof(buf), in); + switch (state) { + case FLD: + case FLDPLUS: + case FLDEOF: + /* Search for the message ID */ + if (mh_strcasecmp (name, "Message-ID")) { + while (state == FLDPLUS) + state = m_getfld (state, name, buf, sizeof(buf), in); + continue; + } - dbm_close (db); - lkclose(lockfd, file); - free (cp); - fclose (in); - return result; - break; + cp = add (buf, NULL); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), in); + cp = add (buf, cp); + } + key.dptr = trimcpy (cp); + key.dsize = strlen (key.dptr) + 1; + free (cp); + cp = key.dptr; + + if (!(db = dbm_open (file, O_RDWR | O_CREAT, 0600))) { + advise (file, "unable to perform dbm_open on"); + free (cp); + fclose (in); + return -1; + } + /* + * Since it is difficult to portable + * lock a ndbm file, we will open and + * lock the Maildelivery file instead. + * This will fail if your Maildelivery + * file doesn't exist. + */ + if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) { + advise (file, "unable to perform file locking on"); + free (cp); + fclose (in); + return -1; + } + value = dbm_fetch (db, key); + if (value.dptr) { + if (verbose) + verbose_printf ("Message-ID: %s\n already received on %s", + cp, value.dptr); + result = DONE; + } else { + value.dptr = ddate + sizeof("Delivery-Date:"); + value.dsize = strlen(value.dptr) + 1; + if (dbm_store (db, key, value, DBM_INSERT)) + advise (file, "possibly corrupt file"); + result = 0; + } - case BODY: - case BODYEOF: - case FILEEOF: - break; + dbm_close (db); + lkclose(lockfd, file); + free (cp); + fclose (in); + return result; + break; + + case BODY: + case BODYEOF: + case FILEEOF: + break; + + case LENERR: + case FMTERR: + default: + break; + } - case LENERR: - case FMTERR: - default: break; } - break; - } - - fclose (in); - return 0; + fclose (in); + return 0; } diff --git a/uip/sortm.c b/uip/sortm.c index cfad3d3..4b63bb6 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -1,4 +1,3 @@ - /* * sortm.c -- sort messages in a folder by date/time * @@ -12,41 +11,41 @@ #include static struct swit switches[] = { -#define DATESW 0 - { "datefield field", 0 }, -#define TEXTSW 1 - { "textfield field", 0 }, -#define NSUBJSW 2 - { "notextfield", 0 }, -#define SUBJSW 3 - { "subject", -3 }, /* backward-compatibility */ -#define LIMSW 4 - { "limit days", 0 }, -#define NLIMSW 5 - { "nolimit", 0 }, -#define VERBSW 6 - { "verbose", 0 }, -#define NVERBSW 7 - { "noverbose", 0 }, -#define VERSIONSW 8 - { "version", 0 }, -#define HELPSW 9 - { "help", 0 }, - { NULL, 0 } +#define DATESW 0 + { "datefield field", 0 }, +#define TEXTSW 1 + { "textfield field", 0 }, +#define NSUBJSW 2 + { "notextfield", 0 }, +#define SUBJSW 3 + { "subject", -3 }, /* backward-compatibility */ +#define LIMSW 4 + { "limit days", 0 }, +#define NLIMSW 5 + { "nolimit", 0 }, +#define VERBSW 6 + { "verbose", 0 }, +#define NVERBSW 7 + { "noverbose", 0 }, +#define VERSIONSW 8 + { "version", 0 }, +#define HELPSW 9 + { "help", 0 }, + { NULL, 0 } }; struct smsg { - int s_msg; - time_t s_clock; - char *s_subj; + int s_msg; + time_t s_clock; + char *s_subj; }; static struct smsg *smsgs; int nmsgs; -char *subjsort = (char *) 0; /* sort on subject if != 0 */ +char *subjsort = (char *) 0; /* sort on subject if != 0 */ unsigned long datelimit = 0; -int submajor = 0; /* if true, sort on subject-major */ +int submajor = 0; /* if true, sort on subject-major */ int verbose; /* This keeps compiler happy on calls to qsort */ @@ -67,252 +66,252 @@ static void rename_msgs (struct msgs *, struct smsg **); int main (int argc, char **argv) { - int i, msgnum; - unsigned char *cp; - char *maildir, *datesw = NULL; - char *folder = NULL, buf[BUFSIZ], **argp; - char **arguments; - struct msgs_array msgs = { 0, 0, NULL }; - struct msgs *mp; - struct smsg **dlist; + int i, msgnum; + unsigned char *cp; + char *maildir, *datesw = NULL; + char *folder = NULL, buf[BUFSIZ], **argp; + char **arguments; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs *mp; + struct smsg **dlist; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Parse arguments - */ - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case DATESW: - if (datesw) - adios (NULL, "only one date field at a time"); - if (!(datesw = *argp++) || *datesw == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case TEXTSW: - if (subjsort) - adios (NULL, "only one text field at a time"); - if (!(subjsort = *argp++) || *subjsort == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case SUBJSW: - subjsort = "subject"; - continue; - case NSUBJSW: - subjsort = (char *)0; - continue; - - case LIMSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - while (*cp == '0') - cp++; /* skip any leading zeros */ - if (!*cp) { /* hit end of string */ - submajor++; /* sort subject-major */ - continue; + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Parse arguments + */ + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", + invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DATESW: + if (datesw) + adios (NULL, "only one date field at a time"); + if (!(datesw = *argp++) || *datesw == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case TEXTSW: + if (subjsort) + adios (NULL, "only one text field at a time"); + if (!(subjsort = *argp++) || *subjsort == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case SUBJSW: + subjsort = "subject"; + continue; + case NSUBJSW: + subjsort = (char *)0; + continue; + + case LIMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + while (*cp == '0') + cp++; /* skip any leading zeros */ + if (!*cp) { /* hit end of string */ + submajor++; /* sort subject-major */ + continue; + } + if (!isdigit(*cp) || !(datelimit = atoi(cp))) + adios (NULL, "impossible limit %s", cp); + datelimit *= 60*60*24; + continue; + case NLIMSW: + submajor = 0; /* use date-major, but */ + datelimit = 0; /* use no limit */ + continue; + + case VERBSW: + verbose++; + continue; + case NVERBSW: + verbose = 0; + continue; + } } - if (!isdigit(*cp) || !(datelimit = atoi(cp))) - adios (NULL, "impossible limit %s", cp); - datelimit *= 60*60*24; - continue; - case NLIMSW: - submajor = 0; /* use date-major, but */ - datelimit = 0; /* use no limit */ - continue; - - case VERBSW: - verbose++; - continue; - case NVERBSW: - verbose = 0; - continue; - } + if (*cp == '+' || *cp == '@') { + if (folder) + adios (NULL, "only one folder at a time!"); + else + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); - } else - app_msgarg(&msgs, cp); - } - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (!msgs.size) - app_msgarg(&msgs, "all"); - if (!datesw) - datesw = "date"; - if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); - - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); - - /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); - - /* check for empty folder */ - if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); - - /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgs.size; msgnum++) - if (!m_convert (mp, msgs.msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous sequence */ - - if ((nmsgs = read_hdrs (mp, datesw)) <= 0) - adios (NULL, "no messages to sort"); - - /* - * sort a list of pointers to our "messages to be sorted". - */ - dlist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*dlist)); - for (i = 0; i < nmsgs; i++) - dlist[i] = &smsgs[i]; - dlist[nmsgs] = 0; - - if (verbose) { /* announce what we're doing */ - if (subjsort) - printf ("sorting by %s-major %s-minor\n", - submajor ? subjsort : datesw, - submajor ? datesw : subjsort); - else - printf ("sorting by datefield %s\n", datesw); - } - - /* first sort by date, or by subject-major, date-minor */ - qsort ((char *) dlist, nmsgs, sizeof(*dlist), - (qsort_comp) (submajor && subjsort ? txtsort : dsort)); - - /* - * if we're sorting on subject, we need another list - * in subject order, then a merge pass to collate the - * two sorts. - */ - if (!submajor && subjsort) { /* already date sorted */ - struct smsg **slist, **flist; - register struct smsg ***il, **fp, **dp; - - slist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*slist)); - memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); - qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); + + if (!context_find ("path")) + free (path ("./", TFOLDER)); + if (!msgs.size) + app_msgarg(&msgs, "all"); + if (!datesw) + datesw = "date"; + if (!folder) + folder = getfolder (1); + maildir = m_maildir (folder); + + if (chdir (maildir) == NOTOK) + adios (maildir, "unable to change directory to"); + + /* read folder and create message structure */ + if (!(mp = folder_read (folder))) + adios (NULL, "unable to read folder %s", folder); + + /* check for empty folder */ + if (mp->nummsg == 0) + adios (NULL, "no messages in %s", folder); + + /* parse all the message ranges/sequences and set SELECTED */ + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) + done (1); + seq_setprev (mp); /* set the previous sequence */ + + if ((nmsgs = read_hdrs (mp, datesw)) <= 0) + adios (NULL, "no messages to sort"); /* - * make an inversion list so we can quickly find - * the collection of messages with the same subj - * given a message number. + * sort a list of pointers to our "messages to be sorted". */ - il = (struct smsg ***) calloc (mp->hghsel+1, sizeof(*il)); - if (! il) - adios (NULL, "couldn't allocate msg list"); + dlist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*dlist)); for (i = 0; i < nmsgs; i++) - il[slist[i]->s_msg] = &slist[i]; + dlist[i] = &smsgs[i]; + dlist[nmsgs] = 0; + + if (verbose) { /* announce what we're doing */ + if (subjsort) + printf ("sorting by %s-major %s-minor\n", + submajor ? subjsort : datesw, + submajor ? datesw : subjsort); + else + printf ("sorting by datefield %s\n", datesw); + } + + /* first sort by date, or by subject-major, date-minor */ + qsort ((char *) dlist, nmsgs, sizeof(*dlist), + (qsort_comp) (submajor && subjsort ? txtsort : dsort)); + /* - * make up the final list, chronological but with - * all the same subjects grouped together. + * if we're sorting on subject, we need another list + * in subject order, then a merge pass to collate the + * two sorts. */ - flist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*flist)); - fp = flist; - for (dp = dlist; *dp;) { - register struct smsg **s = il[(*dp++)->s_msg]; - - /* see if we already did this guy */ - if (! s) - continue; - - *fp++ = *s++; - /* - * take the next message(s) if there is one, - * its subject isn't null and its subject - * is the same as this one and it's not too - * far away in time. - */ - while (*s && (*s)->s_subj[0] && - strcmp((*s)->s_subj, s[-1]->s_subj) == 0 && - (datelimit == 0 || - (*s)->s_clock - s[-1]->s_clock <= datelimit)) { - il[(*s)->s_msg] = 0; - *fp++ = *s++; - } + if (!submajor && subjsort) { /* already date sorted */ + struct smsg **slist, **flist; + register struct smsg ***il, **fp, **dp; + + slist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*slist)); + memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); + qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); + + /* + * make an inversion list so we can quickly find + * the collection of messages with the same subj + * given a message number. + */ + il = (struct smsg ***) calloc (mp->hghsel+1, sizeof(*il)); + if (! il) + adios (NULL, "couldn't allocate msg list"); + for (i = 0; i < nmsgs; i++) + il[slist[i]->s_msg] = &slist[i]; + /* + * make up the final list, chronological but with + * all the same subjects grouped together. + */ + flist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*flist)); + fp = flist; + for (dp = dlist; *dp;) { + register struct smsg **s = il[(*dp++)->s_msg]; + + /* see if we already did this guy */ + if (! s) + continue; + + *fp++ = *s++; + /* + * take the next message(s) if there is one, + * its subject isn't null and its subject + * is the same as this one and it's not too + * far away in time. + */ + while (*s && (*s)->s_subj[0] && + strcmp((*s)->s_subj, s[-1]->s_subj) == 0 && + (datelimit == 0 || + (*s)->s_clock - s[-1]->s_clock <= datelimit)) { + il[(*s)->s_msg] = 0; + *fp++ = *s++; + } + } + *fp = 0; + free (slist); + free (dlist); + dlist = flist; } - *fp = 0; - free (slist); - free (dlist); - dlist = flist; - } - - /* - * At this point, dlist is a sorted array of pointers to smsg structures, - * each of which contains a message number. - */ - - rename_msgs (mp, dlist); - - context_replace (pfolder, folder); /* update current folder */ - seq_save (mp); /* synchronize message sequences */ - context_save (); /* save the context file */ - folder_free (mp); /* free folder/message structure */ - done (0); - return 1; + + /* + * At this point, dlist is a sorted array of pointers to smsg + * structures, each of which contains a message number. + */ + + rename_msgs (mp, dlist); + + context_replace (pfolder, folder); /* update current folder */ + seq_save (mp); /* synchronize message sequences */ + context_save (); /* save the context file */ + folder_free (mp); /* free folder/message structure */ + done (0); + return 1; } static int read_hdrs (struct msgs *mp, char *datesw) { - int msgnum; - struct tws tb; - register struct smsg *s; - - twscopy (&tb, dlocaltimenow ()); - - smsgs = (struct smsg *) - calloc ((size_t) (mp->hghsel - mp->lowsel + 2), - sizeof(*smsgs)); - if (smsgs == NULL) - adios (NULL, "unable to allocate sort storage"); - - s = smsgs; - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected(mp, msgnum)) { - if (get_fields (datesw, msgnum, s)) { - s->s_msg = msgnum; - s++; - } + int msgnum; + struct tws tb; + register struct smsg *s; + + twscopy (&tb, dlocaltimenow ()); + + smsgs = (struct smsg *) + calloc ((size_t) (mp->hghsel - mp->lowsel + 2), + sizeof(*smsgs)); + if (smsgs == NULL) + adios (NULL, "unable to allocate sort storage"); + + s = smsgs; + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (is_selected(mp, msgnum)) { + if (get_fields (datesw, msgnum, s)) { + s->s_msg = msgnum; + s++; + } + } } - } - s->s_msg = 0; - return(s - smsgs); + s->s_msg = 0; + return(s - smsgs); } @@ -324,124 +323,124 @@ read_hdrs (struct msgs *mp, char *datesw) static int get_fields (char *datesw, int msg, struct smsg *smsg) { - register int state; - int compnum; - char *msgnam, buf[BUFSIZ], nam[NAMESZ]; - register struct tws *tw; - register char *datecomp = NULL, *subjcomp = NULL; - register FILE *in; - - if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) { - admonish (msgnam, "unable to read message"); - return (0); - } - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, nam, buf, sizeof(buf), in)) { - case FLD: - case FLDEOF: - case FLDPLUS: - compnum++; - if (!mh_strcasecmp (nam, datesw)) { - datecomp = add (buf, datecomp); - while (state == FLDPLUS) { - state = m_getfld (state, nam, buf, sizeof(buf), in); - datecomp = add (buf, datecomp); - } - if (!subjsort || subjcomp) - break; - } else if (subjsort && !mh_strcasecmp (nam, subjsort)) { - subjcomp = add (buf, subjcomp); - while (state == FLDPLUS) { - state = m_getfld (state, nam, buf, sizeof(buf), in); - subjcomp = add (buf, subjcomp); + register int state; + int compnum; + char *msgnam, buf[BUFSIZ], nam[NAMESZ]; + register struct tws *tw; + register char *datecomp = NULL, *subjcomp = NULL; + register FILE *in; + + if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) { + admonish (msgnam, "unable to read message"); + return (0); + } + for (compnum = 1, state = FLD;;) { + switch (state = m_getfld (state, nam, buf, sizeof(buf), in)) { + case FLD: + case FLDEOF: + case FLDPLUS: + compnum++; + if (!mh_strcasecmp (nam, datesw)) { + datecomp = add (buf, datecomp); + while (state == FLDPLUS) { + state = m_getfld (state, nam, buf, sizeof(buf), in); + datecomp = add (buf, datecomp); + } + if (!subjsort || subjcomp) + break; + } else if (subjsort && !mh_strcasecmp (nam, subjsort)) { + subjcomp = add (buf, subjcomp); + while (state == FLDPLUS) { + state = m_getfld (state, nam, buf, sizeof(buf), in); + subjcomp = add (buf, subjcomp); + } + if (datecomp) + break; + } else { + /* just flush this guy */ + while (state == FLDPLUS) + state = m_getfld (state, nam, buf, sizeof(buf), in); + } + continue; + + case BODY: + case BODYEOF: + case FILEEOF: + break; + + case LENERR: + case FMTERR: + if (state == LENERR || state == FMTERR) + admonish (NULL, "format error in message %d (header #%d)", + msg, compnum); + if (datecomp) + free (datecomp); + if (subjcomp) + free (subjcomp); + fclose (in); + return (0); + + default: + adios (NULL, "internal error -- you lose"); } - if (datecomp) - break; - } else { - /* just flush this guy */ - while (state == FLDPLUS) - state = m_getfld (state, nam, buf, sizeof(buf), in); - } - continue; - - case BODY: - case BODYEOF: - case FILEEOF: - break; - - case LENERR: - case FMTERR: - if (state == LENERR || state == FMTERR) - admonish (NULL, "format error in message %d (header #%d)", - msg, compnum); - if (datecomp) - free (datecomp); - if (subjcomp) - free (subjcomp); - fclose (in); - return (0); + break; + } - default: - adios (NULL, "internal error -- you lose"); + /* + * If no date component, then use the modification + * time of the file as its date + */ + if (!datecomp || (tw = dparsetime (datecomp)) == NULL) { + struct stat st; + + admonish (NULL, "can't parse %s field in message %d", datesw, msg); + fstat (fileno (in), &st); + smsg->s_clock = st.st_mtime; + } else { + smsg->s_clock = dmktime (tw); } - break; - } - - /* - * If no date component, then use the modification - * time of the file as its date - */ - if (!datecomp || (tw = dparsetime (datecomp)) == NULL) { - struct stat st; - - admonish (NULL, "can't parse %s field in message %d", datesw, msg); - fstat (fileno (in), &st); - smsg->s_clock = st.st_mtime; - } else { - smsg->s_clock = dmktime (tw); - } - - if (subjsort) { - if (subjcomp) { - /* - * try to make the subject "canonical": delete - * leading "re:", everything but letters & smash - * letters to lower case. - */ - register char *cp, *cp2; - register unsigned char c; - - cp = subjcomp; - cp2 = subjcomp; - if (strcmp (subjsort, "subject") == 0) { - while ((c = *cp)) { - if (! isspace(c)) { - if(uprf(cp, "re:")) - cp += 2; - else - break; - } - cp++; - } - } - while ((c = *cp++)) { - if (isalnum(c)) - *cp2++ = isupper(c) ? tolower(c) : c; - } + if (subjsort) { + if (subjcomp) { + /* + * try to make the subject "canonical": delete + * leading "re:", everything but letters & smash + * letters to lower case. + */ + register char *cp, *cp2; + register unsigned char c; + + cp = subjcomp; + cp2 = subjcomp; + if (strcmp (subjsort, "subject") == 0) { + while ((c = *cp)) { + if (! isspace(c)) { + if(uprf(cp, "re:")) + cp += 2; + else + break; + } + cp++; + } + } + + while ((c = *cp++)) { + if (isalnum(c)) + *cp2++ = isupper(c) ? tolower(c) : c; + } + + *cp2 = '\0'; + } + else + subjcomp = ""; - *cp2 = '\0'; + smsg->s_subj = subjcomp; } - else - subjcomp = ""; - - smsg->s_subj = subjcomp; - } - fclose (in); - if (datecomp) - free (datecomp); + fclose (in); + if (datecomp) + free (datecomp); - return (1); + return (1); } /* @@ -450,14 +449,14 @@ get_fields (char *datesw, int msg, struct smsg *smsg) static int dsort (struct smsg **a, struct smsg **b) { - if ((*a)->s_clock < (*b)->s_clock) - return (-1); - else if ((*a)->s_clock > (*b)->s_clock) - return (1); - else if ((*a)->s_msg < (*b)->s_msg) - return (-1); - else - return (1); + if ((*a)->s_clock < (*b)->s_clock) + return (-1); + else if ((*a)->s_clock > (*b)->s_clock) + return (1); + else if ((*a)->s_msg < (*b)->s_msg) + return (-1); + else + return (1); } /* @@ -466,124 +465,124 @@ dsort (struct smsg **a, struct smsg **b) static int subsort (struct smsg **a, struct smsg **b) { - register int i; + register int i; - if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) - return (i); + if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) + return (i); - return (dsort (a, b)); + return (dsort (a, b)); } static int txtsort (struct smsg **a, struct smsg **b) { - register int i; + register int i; - if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) - return (i); - else if ((*a)->s_msg < (*b)->s_msg) - return (-1); - else - return (1); + if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) + return (i); + else if ((*a)->s_msg < (*b)->s_msg) + return (-1); + else + return (1); } static void rename_chain (struct msgs *mp, struct smsg **mlist, int msg, int endmsg) { - int nxt, old, new; - char *newname, oldname[BUFSIZ]; - char newbuf[MAXPATHLEN + 1]; - - for (;;) { - nxt = mlist[msg] - smsgs; /* mlist[msg] is a ptr into smsgs */ - mlist[msg] = (struct smsg *)0; - old = smsgs[nxt].s_msg; - new = smsgs[msg].s_msg; - strncpy (oldname, m_name (old), sizeof(oldname)); - newname = m_name (new); - if (verbose) - printf ("message %d becomes message %d\n", old, new); - - (void)snprintf(oldname, sizeof (oldname), "%s/%d", mp->foldpath, old); - (void)snprintf(newbuf, sizeof (newbuf), "%s/%d", mp->foldpath, new); - ext_hook("ref-hook", oldname, newbuf); - - if (rename (oldname, newname) == NOTOK) - adios (newname, "unable to rename %s to", oldname); - - copy_msg_flags (mp, new, old); - if (mp->curmsg == old) - seq_setcur (mp, new); - - if (nxt == endmsg) - break; - - msg = nxt; - } -/* if (nxt != endmsg); */ -/* rename_chain (mp, mlist, nxt, endmsg); */ + int nxt, old, new; + char *newname, oldname[BUFSIZ]; + char newbuf[MAXPATHLEN + 1]; + + for (;;) { + nxt = mlist[msg] - smsgs; /* mlist[msg] is a ptr into smsgs */ + mlist[msg] = (struct smsg *)0; + old = smsgs[nxt].s_msg; + new = smsgs[msg].s_msg; + strncpy (oldname, m_name (old), sizeof(oldname)); + newname = m_name (new); + if (verbose) + printf ("message %d becomes message %d\n", old, new); + + (void)snprintf(oldname, sizeof (oldname), "%s/%d", mp->foldpath, old); + (void)snprintf(newbuf, sizeof (newbuf), "%s/%d", mp->foldpath, new); + ext_hook("ref-hook", oldname, newbuf); + + if (rename (oldname, newname) == NOTOK) + adios (newname, "unable to rename %s to", oldname); + + copy_msg_flags (mp, new, old); + if (mp->curmsg == old) + seq_setcur (mp, new); + + if (nxt == endmsg) + break; + + msg = nxt; + } +/* if (nxt != endmsg); */ +/* rename_chain (mp, mlist, nxt, endmsg); */ } static void rename_msgs (struct msgs *mp, struct smsg **mlist) { - int i, j, old, new; - seqset_t tmpset; - char f1[BUFSIZ], tmpfil[BUFSIZ]; - char newbuf[MAXPATHLEN + 1]; - struct smsg *sp; + int i, j, old, new; + seqset_t tmpset; + char f1[BUFSIZ], tmpfil[BUFSIZ]; + char newbuf[MAXPATHLEN + 1]; + struct smsg *sp; - strncpy (tmpfil, m_name (mp->hghmsg + 1), sizeof(tmpfil)); + strncpy (tmpfil, m_name (mp->hghmsg + 1), sizeof(tmpfil)); - for (i = 0; i < nmsgs; i++) { - if (! (sp = mlist[i])) - continue; /* did this one */ + for (i = 0; i < nmsgs; i++) { + if (! (sp = mlist[i])) + continue; /* did this one */ - j = sp - smsgs; - if (j == i) - continue; /* this one doesn't move */ + j = sp - smsgs; + if (j == i) + continue; /* this one doesn't move */ - /* - * the guy that was msg j is about to become msg i. - * rename 'j' to make a hole, then recursively rename - * guys to fill up the hole. - */ - old = smsgs[j].s_msg; - new = smsgs[i].s_msg; - strncpy (f1, m_name (old), sizeof(f1)); + /* + * the guy that was msg j is about to become msg i. + * rename 'j' to make a hole, then recursively rename + * guys to fill up the hole. + */ + old = smsgs[j].s_msg; + new = smsgs[i].s_msg; + strncpy (f1, m_name (old), sizeof(f1)); - if (verbose) - printf ("renaming message chain from %d to %d\n", old, new); + if (verbose) + printf ("renaming message chain from %d to %d\n", old, new); - /* - * Run the external hook to refile the old message as the - * temporary message number that is off of the end of the - * messages in the folder. - */ + /* + * Run the external hook to refile the old message as the + * temporary message number that is off of the end of the + * messages in the folder. + */ - (void)snprintf(f1, sizeof (f1), "%s/%d", mp->foldpath, old); - (void)snprintf(newbuf, sizeof (newbuf), "%s/%d", mp->foldpath, mp->hghmsg + 1); - ext_hook("ref-hook", f1, newbuf); + (void)snprintf(f1, sizeof (f1), "%s/%d", mp->foldpath, old); + (void)snprintf(newbuf, sizeof (newbuf), "%s/%d", mp->foldpath, mp->hghmsg + 1); + ext_hook("ref-hook", f1, newbuf); - if (rename (f1, tmpfil) == NOTOK) - adios (tmpfil, "unable to rename %s to ", f1); + if (rename (f1, tmpfil) == NOTOK) + adios (tmpfil, "unable to rename %s to ", f1); - get_msg_flags (mp, &tmpset, old); + get_msg_flags (mp, &tmpset, old); - rename_chain (mp, mlist, j, i); + rename_chain (mp, mlist, j, i); - /* - * Run the external hook to refile the temorary message number - * to the real place. - */ + /* + * Run the external hook to refile the temorary message number + * to the real place. + */ - (void)snprintf(f1, sizeof (f1), "%s/%d", mp->foldpath, new); - ext_hook("ref-hook", newbuf, f1); + (void)snprintf(f1, sizeof (f1), "%s/%d", mp->foldpath, new); + ext_hook("ref-hook", newbuf, f1); - if (rename (tmpfil, m_name(new)) == NOTOK) - adios (m_name(new), "unable to rename %s to", tmpfil); + if (rename (tmpfil, m_name(new)) == NOTOK) + adios (m_name(new), "unable to rename %s to", tmpfil); - set_msg_flags (mp, &tmpset, new); - mp->msgflags |= SEQMOD; - } + set_msg_flags (mp, &tmpset, new); + mp->msgflags |= SEQMOD; + } } diff --git a/uip/spost.c b/uip/spost.c index c7582ba..4d23fe5 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -1,4 +1,3 @@ - /* * spost.c -- feed messages to sendmail * @@ -19,156 +18,156 @@ #include #include -#define MAX_SM_FIELD 1476 /* < largest hdr field sendmail will accept */ -#define FCCS 10 /* max number of fccs allowed */ +#define MAX_SM_FIELD 1476 /* < largest hdr field sendmail will accept */ +#define FCCS 10 /* max number of fccs allowed */ struct swit switches[] = { -#define FILTSW 0 - { "filter filterfile", 0 }, -#define NFILTSW 1 - { "nofilter", 0 }, -#define FRMTSW 2 - { "format", 0 }, -#define NFRMTSW 3 - { "noformat", 0 }, -#define REMVSW 4 - { "remove", 0 }, -#define NREMVSW 5 - { "noremove", 0 }, -#define VERBSW 6 - { "verbose", 0 }, -#define NVERBSW 7 - { "noverbose", 0 }, -#define WATCSW 8 - { "watch", 0 }, -#define NWATCSW 9 - { "nowatch", 0 }, -#define BACKSW 10 - { "backup", 0 }, -#define NBACKSW 11 - { "nobackup", 0 }, -#define ALIASW 12 - { "alias aliasfile", 0 }, -#define NALIASW 13 - { "noalias", 0 }, -#define WIDTHSW 14 - { "width columns", 0 }, -#define VERSIONSW 15 - { "version", 0 }, -#define HELPSW 16 - { "help", 0 }, -#define DEBUGSW 17 - { "debug", -5 }, -#define DISTSW 18 - { "dist", -4 }, /* interface from dist */ -#define CHKSW 19 - { "check", -5 }, /* interface from whom */ -#define NCHKSW 20 - { "nocheck", -7 }, /* interface from whom */ -#define WHOMSW 21 - { "whom", -4 }, /* interface from whom */ -#define PUSHSW 22 /* fork to sendmail then exit */ - { "push", -4 }, -#define NPUSHSW 23 /* exec sendmail */ - { "nopush", -6 }, -#define LIBSW 24 - { "library directory", -7 }, -#define ANNOSW 25 - { "idanno number", -6 }, - { NULL, 0 } +#define FILTSW 0 + { "filter filterfile", 0 }, +#define NFILTSW 1 + { "nofilter", 0 }, +#define FRMTSW 2 + { "format", 0 }, +#define NFRMTSW 3 + { "noformat", 0 }, +#define REMVSW 4 + { "remove", 0 }, +#define NREMVSW 5 + { "noremove", 0 }, +#define VERBSW 6 + { "verbose", 0 }, +#define NVERBSW 7 + { "noverbose", 0 }, +#define WATCSW 8 + { "watch", 0 }, +#define NWATCSW 9 + { "nowatch", 0 }, +#define BACKSW 10 + { "backup", 0 }, +#define NBACKSW 11 + { "nobackup", 0 }, +#define ALIASW 12 + { "alias aliasfile", 0 }, +#define NALIASW 13 + { "noalias", 0 }, +#define WIDTHSW 14 + { "width columns", 0 }, +#define VERSIONSW 15 + { "version", 0 }, +#define HELPSW 16 + { "help", 0 }, +#define DEBUGSW 17 + { "debug", -5 }, +#define DISTSW 18 + { "dist", -4 }, /* interface from dist */ +#define CHKSW 19 + { "check", -5 }, /* interface from whom */ +#define NCHKSW 20 + { "nocheck", -7 }, /* interface from whom */ +#define WHOMSW 21 + { "whom", -4 }, /* interface from whom */ +#define PUSHSW 22 /* fork to sendmail then exit */ + { "push", -4 }, +#define NPUSHSW 23 /* exec sendmail */ + { "nopush", -6 }, +#define LIBSW 24 + { "library directory", -7 }, +#define ANNOSW 25 + { "idanno number", -6 }, + { NULL, 0 } }; /* flags for headers->flags */ -#define HNOP 0x0000 /* just used to keep .set around */ -#define HBAD 0x0001 /* bad header - don't let it through */ -#define HADR 0x0002 /* header has an address field */ -#define HSUB 0x0004 /* Subject: header */ -#define HTRY 0x0008 /* try to send to addrs on header */ -#define HBCC 0x0010 /* don't output this header */ -#define HMNG 0x0020 /* mung this header */ -#define HNGR 0x0040 /* no groups allowed in this header */ -#define HFCC 0x0080 /* FCC: type header */ -#define HNIL 0x0100 /* okay for this header not to have addrs */ -#define HIGN 0x0200 /* ignore this header */ +#define HNOP 0x0000 /* just used to keep .set around */ +#define HBAD 0x0001 /* bad header - don't let it through */ +#define HADR 0x0002 /* header has an address field */ +#define HSUB 0x0004 /* Subject: header */ +#define HTRY 0x0008 /* try to send to addrs on header */ +#define HBCC 0x0010 /* don't output this header */ +#define HMNG 0x0020 /* mung this header */ +#define HNGR 0x0040 /* no groups allowed in this header */ +#define HFCC 0x0080 /* FCC: type header */ +#define HNIL 0x0100 /* okay for this header not to have addrs */ +#define HIGN 0x0200 /* ignore this header */ /* flags for headers->set */ -#define MFRM 0x0001 /* we've seen a From: */ -#define MDAT 0x0002 /* we've seen a Date: */ -#define MRFM 0x0004 /* we've seen a Resent-From: */ -#define MVIS 0x0008 /* we've seen sighted addrs */ -#define MINV 0x0010 /* we've seen blind addrs */ -#define MRDT 0x0020 /* we've seen a Resent-Date: */ +#define MFRM 0x0001 /* we've seen a From: */ +#define MDAT 0x0002 /* we've seen a Date: */ +#define MRFM 0x0004 /* we've seen a Resent-From: */ +#define MVIS 0x0008 /* we've seen sighted addrs */ +#define MINV 0x0010 /* we've seen blind addrs */ +#define MRDT 0x0020 /* we've seen a Resent-Date: */ struct headers { - char *value; - unsigned int flags; - unsigned int set; + char *value; + unsigned int flags; + unsigned int set; }; static struct headers NHeaders[] = { - { "Return-Path", HBAD, 0 }, - { "Received", HBAD, 0 }, - { "Reply-To", HADR|HNGR, 0 }, - { "From", HADR|HNGR, MFRM }, - { "Sender", HADR|HBAD, 0 }, - { "Date", HNOP, MDAT }, - { "Subject", HSUB, 0 }, - { "To", HADR|HTRY, MVIS }, - { "cc", HADR|HTRY, MVIS }, - { "Bcc", HADR|HTRY|HBCC|HNIL, MINV }, - { "Message-Id", HBAD, 0 }, - { "Fcc", HFCC, 0 }, - { NULL, 0, 0 } + { "Return-Path", HBAD, 0 }, + { "Received", HBAD, 0 }, + { "Reply-To", HADR|HNGR, 0 }, + { "From", HADR|HNGR, MFRM }, + { "Sender", HADR|HBAD, 0 }, + { "Date", HNOP, MDAT }, + { "Subject", HSUB, 0 }, + { "To", HADR|HTRY, MVIS }, + { "cc", HADR|HTRY, MVIS }, + { "Bcc", HADR|HTRY|HBCC|HNIL, MINV }, + { "Message-Id", HBAD, 0 }, + { "Fcc", HFCC, 0 }, + { NULL, 0, 0 } }; static struct headers RHeaders[] = { - { "Resent-Reply-To", HADR|HNGR, 0 }, - { "Resent-From", HADR|HNGR, MRFM }, - { "Resent-Sender", HADR|HBAD, 0 }, - { "Resent-Date", HNOP, MRDT }, - { "Resent-Subject", HSUB, 0 }, - { "Resent-To", HADR|HTRY, MVIS }, - { "Resent-cc", HADR|HTRY, MVIS }, - { "Resent-Bcc", HADR|HTRY|HBCC, MINV }, - { "Resent-Message-Id", HBAD, 0 }, - { "Resent-Fcc", HFCC, 0 }, - { "Reply-To", HADR, 0 }, - { "Fcc", HIGN, 0 }, - { NULL, 0, 0 } + { "Resent-Reply-To", HADR|HNGR, 0 }, + { "Resent-From", HADR|HNGR, MRFM }, + { "Resent-Sender", HADR|HBAD, 0 }, + { "Resent-Date", HNOP, MRDT }, + { "Resent-Subject", HSUB, 0 }, + { "Resent-To", HADR|HTRY, MVIS }, + { "Resent-cc", HADR|HTRY, MVIS }, + { "Resent-Bcc", HADR|HTRY|HBCC, MINV }, + { "Resent-Message-Id", HBAD, 0 }, + { "Resent-Fcc", HFCC, 0 }, + { "Reply-To", HADR, 0 }, + { "Fcc", HIGN, 0 }, + { NULL, 0, 0 } }; -static short fccind = 0; /* index into fccfold[] */ +static short fccind = 0; /* index into fccfold[] */ -static int badmsg = 0; /* message has bad semantics */ -static int verbose = 0; /* spell it out */ -static int debug = 0; /* debugging post */ -static int rmflg = 1; /* remove temporary file when done */ -static int watch = 0; /* watch the delivery process */ -static int backflg = 0; /* rename input file as *.bak when done */ -static int whomflg = 0; /* if just checking addresses */ -static int pushflg = 0; /* if going to fork to sendmail */ -static int aliasflg = -1; /* if going to process aliases */ +static int badmsg = 0; /* message has bad semantics */ +static int verbose = 0; /* spell it out */ +static int debug = 0; /* debugging post */ +static int rmflg = 1; /* remove temporary file when done */ +static int watch = 0; /* watch the delivery process */ +static int backflg = 0; /* rename input file as *.bak when done */ +static int whomflg = 0; /* if just checking addresses */ +static int pushflg = 0; /* if going to fork to sendmail */ +static int aliasflg = -1; /* if going to process aliases */ static int outputlinelen=72; -static unsigned msgflags = 0; /* what we've seen */ +static unsigned msgflags = 0; /* what we've seen */ static enum { - normal, resent + normal, resent } msgstate = normal; static char tmpfil[] = "/tmp/pstXXXXXX"; -static char from[BUFSIZ]; /* my network address */ -static char signature[BUFSIZ]; /* my signature */ -static char *filter = NULL; /* the filter for BCC'ing */ -static char *subject = NULL; /* the subject field for BCC'ing */ -static char *fccfold[FCCS]; /* foldernames for FCC'ing */ +static char from[BUFSIZ]; /* my network address */ +static char signature[BUFSIZ]; /* my signature */ +static char *filter = NULL; /* the filter for BCC'ing */ +static char *subject = NULL; /* the subject field for BCC'ing */ +static char *fccfold[FCCS]; /* foldernames for FCC'ing */ -static struct headers *hdrtab; /* table for the message we're doing */ -static FILE *out; /* output (temp) file */ +static struct headers *hdrtab; /* table for the message we're doing */ +static FILE *out; /* output (temp) file */ extern char *sendmail; @@ -202,264 +201,264 @@ static void make_bcc_file (void); int main (int argc, char **argv) { - int state, i, pid, compnum; - char *cp, *msg = NULL, **argp, **arguments; - char *sargv[16], buf[BUFSIZ], name[NAMESZ]; - FILE *in; + int state, i, pid, compnum; + char *cp, *msg = NULL, **argp, **arguments; + char *sargv[16], buf[BUFSIZ], name[NAMESZ]; + FILE *in; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - mts_init (invo_name); - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case DEBUGSW: - debug++; - continue; - - case DISTSW: - msgstate = resent; - continue; - - case WHOMSW: - whomflg++; - continue; - - case FILTSW: - if (!(filter = *argp++) || *filter == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NFILTSW: - filter = NULL; - continue; - - case REMVSW: - rmflg++; - continue; - case NREMVSW: - rmflg = 0; - continue; - - case BACKSW: - backflg++; - continue; - case NBACKSW: - backflg = 0; - continue; - - case VERBSW: - verbose++; - continue; - case NVERBSW: - verbose = 0; - continue; - - case WATCSW: - watch++; - continue; - case NWATCSW: - watch = 0; - continue; - - case PUSHSW: - pushflg++; - continue; - case NPUSHSW: - pushflg = 0; - continue; - - case ALIASW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if (aliasflg < 0) - alias (AliasFile);/* load default aka's */ - aliasflg = 1; - if ((state = alias(cp)) != AK_OK) - adios (NULL, "aliasing error in file %s - %s", - cp, akerror(state) ); - continue; - case NALIASW: - aliasflg = 0; - continue; - - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - outputlinelen = atoi (cp); - if (outputlinelen <= 10) - outputlinelen = 72; - continue; - - case LIBSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - /* create a minimal context */ - if (context_foil (cp) == -1) - done(1); - continue; - - case ANNOSW: - /* -idanno switch ignored */ - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* foil search of user profile/context */ + if (context_foil (NULL) == -1) + done (1); + + mts_init (invo_name); + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DEBUGSW: + debug++; + continue; + + case DISTSW: + msgstate = resent; + continue; + + case WHOMSW: + whomflg++; + continue; + + case FILTSW: + if (!(filter = *argp++) || *filter == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NFILTSW: + filter = NULL; + continue; + + case REMVSW: + rmflg++; + continue; + case NREMVSW: + rmflg = 0; + continue; + + case BACKSW: + backflg++; + continue; + case NBACKSW: + backflg = 0; + continue; + + case VERBSW: + verbose++; + continue; + case NVERBSW: + verbose = 0; + continue; + + case WATCSW: + watch++; + continue; + case NWATCSW: + watch = 0; + continue; + + case PUSHSW: + pushflg++; + continue; + case NPUSHSW: + pushflg = 0; + continue; + + case ALIASW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if (aliasflg < 0) + alias (AliasFile);/* load default aka's */ + aliasflg = 1; + if ((state = alias(cp)) != AK_OK) + adios (NULL, "aliasing error in file %s - %s", + cp, akerror(state) ); + continue; + case NALIASW: + aliasflg = 0; + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + outputlinelen = atoi (cp); + if (outputlinelen <= 10) + outputlinelen = 72; + continue; + + case LIBSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + /* create a minimal context */ + if (context_foil (cp) == -1) + done(1); + continue; + + case ANNOSW: + /* -idanno switch ignored */ + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + } + } + if (msg) + adios (NULL, "only one message at a time!"); + else + msg = cp; } - if (msg) - adios (NULL, "only one message at a time!"); - else - msg = cp; - } - if (aliasflg < 0) - alias (AliasFile); /* load default aka's */ + if (aliasflg < 0) + alias (AliasFile); /* load default aka's */ - if (!msg) - adios (NULL, "usage: %s [switches] file", invo_name); + if (!msg) + adios (NULL, "usage: %s [switches] file", invo_name); - if ((in = fopen (msg, "r")) == NULL) - adios (msg, "unable to open"); + if ((in = fopen (msg, "r")) == NULL) + adios (msg, "unable to open"); - start_headers (); - if (debug) { - verbose++; - out = stdout; - } - else { + start_headers (); + if (debug) { + verbose++; + out = stdout; + } + else { #ifdef HAVE_MKSTEMP - if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL ) - adios (tmpfil, "unable to create"); + if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL ) + adios (tmpfil, "unable to create"); #else - mktemp (tmpfil); - if ((out = fopen (tmpfil, "w")) == NULL) - adios (tmpfil, "unable to create"); - chmod (tmpfil, 0600); + mktemp (tmpfil); + if ((out = fopen (tmpfil, "w")) == NULL) + adios (tmpfil, "unable to create"); + chmod (tmpfil, 0600); #endif - } - - hdrtab = (msgstate == normal) ? NHeaders : RHeaders; - - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { - case FLD: - compnum++; - putfmt (name, buf, out); - continue; - - case FLDPLUS: - compnum++; - cp = add (buf, cp); - while (state == FLDPLUS) { - state = m_getfld (state, name, buf, sizeof(buf), in); - cp = add (buf, cp); } - putfmt (name, cp, out); - free (cp); - continue; - case BODY: - finish_headers (out); - fprintf (out, "\n%s", buf); - if(whomflg == 0) - while (state == BODY) { - state = m_getfld (state, name, buf, sizeof(buf), in); - fputs (buf, out); - } - break; - - case FILEEOF: - finish_headers (out); + hdrtab = (msgstate == normal) ? NHeaders : RHeaders; + + for (compnum = 1, state = FLD;;) { + switch (state = m_getfld (state, name, buf, sizeof(buf), in)) { + case FLD: + compnum++; + putfmt (name, buf, out); + continue; + + case FLDPLUS: + compnum++; + cp = add (buf, cp); + while (state == FLDPLUS) { + state = m_getfld (state, name, buf, sizeof(buf), in); + cp = add (buf, cp); + } + putfmt (name, cp, out); + free (cp); + continue; + + case BODY: + finish_headers (out); + fprintf (out, "\n%s", buf); + if(whomflg == 0) + while (state == BODY) { + state = m_getfld (state, name, buf, sizeof(buf), in); + fputs (buf, out); + } + break; + + case FILEEOF: + finish_headers (out); + break; + + case LENERR: + case FMTERR: + adios (NULL, "message format error in component #%d", + compnum); + + default: + adios (NULL, "getfld() returned %d", state); + } break; + } - case LENERR: - case FMTERR: - adios (NULL, "message format error in component #%d", - compnum); - - default: - adios (NULL, "getfld() returned %d", state); + fclose (in); + if (backflg && !whomflg) { + strncpy (buf, m_backup (msg), sizeof(buf)); + if (rename (msg, buf) == NOTOK) + advise (buf, "unable to rename %s to", msg); } - break; - } - - fclose (in); - if (backflg && !whomflg) { - strncpy (buf, m_backup (msg), sizeof(buf)); - if (rename (msg, buf) == NOTOK) - advise (buf, "unable to rename %s to", msg); - } - - if (debug) { - done (0); - } - else - fclose (out); - file (tmpfil); - - /* - * re-open the temp file, unlink it and exec sendmail, giving it - * the msg temp file as std in. - */ - if ( freopen( tmpfil, "r", stdin) == NULL) - adios (tmpfil, "can't reopen for sendmail"); - if (rmflg) - unlink (tmpfil); - - argp = sargv; - *argp++ = "send-mail"; - *argp++ = "-m"; /* send to me too */ - *argp++ = "-t"; /* read msg for recipients */ - *argp++ = "-i"; /* don't stop on "." */ - if (whomflg) - *argp++ = "-bv"; - if (watch || verbose) - *argp++ = "-v"; - *argp = NULL; - - if (pushflg && !(watch || verbose)) { - /* fork to a child to run sendmail */ - for (i=0; (pid = vfork()) == NOTOK && i < 5; i++) - sleep(5); - switch (pid) { - case NOTOK: - fprintf (verbose ? stdout : stderr, "%s: can't fork to %s\n", - invo_name, sendmail); - exit(-1); - case OK: - /* we're the child .. */ - break; - default: - exit(0); + if (debug) { + done (0); } - } - execv ( sendmail, sargv); - adios ( sendmail, "can't exec"); - return 0; /* dead code to satisfy the compiler */ + else + fclose (out); + + file (tmpfil); + + /* + * re-open the temp file, unlink it and exec sendmail, giving it + * the msg temp file as std in. + */ + if ( freopen( tmpfil, "r", stdin) == NULL) + adios (tmpfil, "can't reopen for sendmail"); + if (rmflg) + unlink (tmpfil); + + argp = sargv; + *argp++ = "send-mail"; + *argp++ = "-m"; /* send to me too */ + *argp++ = "-t"; /* read msg for recipients */ + *argp++ = "-i"; /* don't stop on "." */ + if (whomflg) + *argp++ = "-bv"; + if (watch || verbose) + *argp++ = "-v"; + *argp = NULL; + + if (pushflg && !(watch || verbose)) { + /* fork to a child to run sendmail */ + for (i=0; (pid = vfork()) == NOTOK && i < 5; i++) + sleep(5); + switch (pid) { + case NOTOK: + fprintf (verbose ? stdout : stderr, "%s: can't fork to %s\n", + invo_name, sendmail); + exit(-1); + case OK: + /* we're the child .. */ + break; + default: + exit(0); + } + } + execv ( sendmail, sargv); + adios ( sendmail, "can't exec"); + return 0; /* dead code to satisfy the compiler */ } /* DRAFT GENERATION */ @@ -467,172 +466,186 @@ main (int argc, char **argv) static void putfmt (char *name, char *str, FILE *out) { - int i; - char *cp, *pp; - struct headers *hdr; - - while (*str == ' ' || *str == '\t') - str++; - - if ((i = get_header (name, hdrtab)) == NOTOK) { - fprintf (out, "%s: %s", name, str); - return; - } - - hdr = &hdrtab[i]; - if (hdr->flags & HIGN) - return; - if (hdr->flags & HBAD) { - advise (NULL, "illegal header line -- %s:", name); - badmsg++; - return; - } - msgflags |= hdr->set; - - if (hdr->flags & HSUB) - subject = subject ? add (str, add ("\t", subject)) : getcpy (str); - - if (hdr->flags & HFCC) { - if ((cp = strrchr(str, '\n'))) - *cp = 0; - for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) { - *cp++ = 0; - insert_fcc (hdr, pp); + int i; + char *cp, *pp; + struct headers *hdr; + + while (*str == ' ' || *str == '\t') + str++; + + if ((i = get_header (name, hdrtab)) == NOTOK) { + fprintf (out, "%s: %s", name, str); + return; + } + + hdr = &hdrtab[i]; + if (hdr->flags & HIGN) + return; + if (hdr->flags & HBAD) { + advise (NULL, "illegal header line -- %s:", name); + badmsg++; + return; + } + msgflags |= hdr->set; + + if (hdr->flags & HSUB) + subject = subject ? add (str, add ("\t", subject)) : getcpy (str); + + if (hdr->flags & HFCC) { + if ((cp = strrchr(str, '\n'))) + *cp = 0; + for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) { + *cp++ = 0; + insert_fcc (hdr, pp); + } + insert_fcc (hdr, pp); + return; } - insert_fcc (hdr, pp); - return; - } #ifdef notdef - if (hdr->flags & HBCC) { - insert_bcc(str); - return; - } -#endif /* notdef */ - - if (*str != '\n' && *str != '\0') { - if (aliasflg && hdr->flags & HTRY) { - /* this header contains address(es) that we have to do - * alias expansion on. Because of the saved state in - * getname we have to put all the addresses into a list. - * We then let putadr munch on that list, possibly - * expanding aliases. - */ - register struct mailname *f = 0; - register struct mailname *mp = 0; - - while ((cp = getname(str))) { - mp = getm( cp, NULL, 0, AD_HOST, NULL); - if (f == 0) { - f = mp; - mp->m_next = mp; + if (hdr->flags & HBCC) { + insert_bcc(str); + return; + } +#endif /* notdef */ + + if (*str != '\n' && *str != '\0') { + if (aliasflg && hdr->flags & HTRY) { + /* this header contains address(es) that we have to do + * alias expansion on. Because of the saved state in + * getname we have to put all the addresses into a list. + * We then let putadr munch on that list, possibly + * expanding aliases. + */ + register struct mailname *f = 0; + register struct mailname *mp = 0; + + while ((cp = getname(str))) { + mp = getm( cp, NULL, 0, AD_HOST, NULL); + if (f == 0) { + f = mp; + mp->m_next = mp; + } else { + mp->m_next = f->m_next; + f->m_next = mp; + f = mp; + } + } + f = mp->m_next; mp->m_next = 0; + putadr( name, f ); } else { - mp->m_next = f->m_next; - f->m_next = mp; - f = mp; + /* + * The author(s) of spost decided that alias + * substitution wasn't necessary for the non-HTRY + * headers. Unfortunately, one of those headers + * is "From:", and having alias substitution + * work on that is extremely useful for someone + * with a lot of POP3 email accounts or aliases. + * post supports aliasing of "From:"... + * + * Since "From:"-processing is incompletely + * implemented in this unsupported and + * undocumented spost backend, I'm not + * going to take the time to implement my new + * draft-From:-based email address masquerading. + * If I do ever implement it here, I'd almost + * certainly want to implement "From:" line + * alias processing as well. + * -- Dan Harkless + */ + fprintf (out, "%s: %s", name, str ); } - } - f = mp->m_next; mp->m_next = 0; - putadr( name, f ); - } else { - /* The author(s) of spost decided that alias substitution wasn't - necessary for the non-HTRY headers. Unfortunately, one of those - headers is "From:", and having alias substitution work on that is - extremely useful for someone with a lot of POP3 email accounts or - aliases. post supports aliasing of "From:"... - - Since "From:"-processing is incompletely implemented in this - unsupported and undocumented spost backend, I'm not going to take - the time to implement my new draft-From:-based email address - masquerading. If I do ever implement it here, I'd almost - certainly want to implement "From:" line alias processing as - well. -- Dan Harkless */ - fprintf (out, "%s: %s", name, str ); } - } } static void start_headers (void) { - char *cp; - char sigbuf[BUFSIZ]; + char *cp; + char sigbuf[BUFSIZ]; - strncpy(from, getusername(), sizeof(from)); + strncpy(from, getusername(), sizeof(from)); - if ((cp = getfullname ()) && *cp) { - strncpy (sigbuf, cp, sizeof(sigbuf)); - snprintf (signature, sizeof(signature), "%s <%s>", sigbuf, from); - } - else - snprintf (signature, sizeof(signature), "%s", from); + if ((cp = getfullname ()) && *cp) { + strncpy (sigbuf, cp, sizeof(sigbuf)); + snprintf (signature, sizeof(signature), "%s <%s>", sigbuf, from); + } else + snprintf (signature, sizeof(signature), "%s", from); } static void finish_headers (FILE *out) { - switch (msgstate) { - case normal: - if (!(msgflags & MDAT)) - fprintf (out, "Date: %s\n", dtimenow (0)); - - if (msgflags & MFRM) { - /* There was already a From: in the draft. Don't add one. */ - if (!draft_from_masquerading) - /* mts.conf didn't contain "masquerade:[...]draft_from[...]" - so we'll reveal the user's actual account@thismachine - address in a Sender: header (and use it as the envelope - From: later). */ - fprintf (out, "Sender: %s\n", from); - } - else - fprintf (out, "From: %s\n", signature); - + switch (msgstate) { + case normal: + if (!(msgflags & MDAT)) + fprintf (out, "Date: %s\n", dtimenow (0)); + + if (msgflags & MFRM) { + /* There was already a From: in the draft. Don't add one. */ + if (!draft_from_masquerading) + /* + * mts.conf didn't contain + * "masquerade:[...]draft_from[...]" + * so we'll reveal the user's + * actual account@thismachine + * address in a Sender: header + * (and use it as the envelope + * From: later). + */ + fprintf (out, "Sender: %s\n", from); + } else + fprintf (out, "From: %s\n", signature); + #ifdef notdef - if (!(msgflags & MVIS)) - fprintf (out, "Bcc: Blind Distribution List: ;\n"); -#endif /* notdef */ - break; - - case resent: - if (!(msgflags & MRDT)) - fprintf (out, "Resent-Date: %s\n", dtimenow(0)); - if (msgflags & MRFM) { - /* There was already a Resent-From: in draft. Don't add one. */ - if (!draft_from_masquerading) - /* mts.conf didn't contain "masquerade:[...]draft_from[...]" - so we'll reveal the user's actual account@thismachine - address in a Sender: header (and use it as the envelope - From: later). */ - fprintf (out, "Resent-Sender: %s\n", from); - } - else - /* Construct a Resent-From: header. */ - fprintf (out, "Resent-From: %s\n", signature); + if (!(msgflags & MVIS)) + fprintf (out, "Bcc: Blind Distribution List: ;\n"); +#endif /* notdef */ + break; + + case resent: + if (!(msgflags & MRDT)) + fprintf (out, "Resent-Date: %s\n", dtimenow(0)); + if (msgflags & MRFM) { + /* There was already a Resent-From: in draft. Don't add one. */ + if (!draft_from_masquerading) + /* + * mts.conf didn't contain + * "masquerade:[...]draft_from[...]" + * so we'll reveal the user's + * actual account@thismachine + * address in a Sender: header + * (and use it as the envelope + * From: later). + */ + fprintf (out, "Resent-Sender: %s\n", from); + } else + /* Construct a Resent-From: header. */ + fprintf (out, "Resent-From: %s\n", signature); #ifdef notdef - if (!(msgflags & MVIS)) - fprintf (out, "Resent-Bcc: Blind Re-Distribution List: ;\n"); -#endif /* notdef */ - break; - } - - if (badmsg) - adios (NULL, "re-format message and try again"); + if (!(msgflags & MVIS)) + fprintf (out, "Resent-Bcc: Blind Re-Distribution List: ;\n"); +#endif /* notdef */ + break; + } + + if (badmsg) + adios (NULL, "re-format message and try again"); } static int get_header (char *header, struct headers *table) { - struct headers *h; + struct headers *h; - for (h = table; h->value; h++) - if (!mh_strcasecmp (header, h->value)) - return (h - table); + for (h = table; h->value; h++) + if (!mh_strcasecmp (header, h->value)) + return (h - table); - return NOTOK; + return NOTOK; } @@ -644,96 +657,96 @@ get_header (char *header, struct headers *table) static void putadr (char *name, struct mailname *nl) { - register struct mailname *mp, *mp2; - register int linepos; - register char *cp; - int namelen; - - fprintf (out, "%s: ", name); - namelen = strlen(name) + 2; - linepos = namelen; - - for (mp = nl; mp; ) { - if (linepos > MAX_SM_FIELD) { - fprintf (out, "\n%s: ", name); - linepos = namelen; - } - if (mp->m_nohost) { - /* a local name - see if it's an alias */ - cp = akvalue(mp->m_mbox); - if (cp == mp->m_mbox) - /* wasn't an alias - use what the user typed */ - linepos = putone( mp->m_text, linepos, namelen ); - else - /* an alias - expand it */ - while ((cp = getname(cp))) { - if (linepos > MAX_SM_FIELD) { - fprintf (out, "\n%s: ", name); - linepos = namelen; - } - mp2 = getm( cp, NULL, 0, AD_HOST, NULL); - if (akvisible()) { - mp2->m_pers = getcpy(mp->m_mbox); - linepos = putone( adrformat(mp2), linepos, namelen ); - } else { - linepos = putone( mp2->m_text, linepos, namelen ); - } - mnfree( mp2 ); + register struct mailname *mp, *mp2; + register int linepos; + register char *cp; + int namelen; + + fprintf (out, "%s: ", name); + namelen = strlen(name) + 2; + linepos = namelen; + + for (mp = nl; mp; ) { + if (linepos > MAX_SM_FIELD) { + fprintf (out, "\n%s: ", name); + linepos = namelen; } - } else { - /* not a local name - use what the user typed */ - linepos = putone( mp->m_text, linepos, namelen ); + if (mp->m_nohost) { + /* a local name - see if it's an alias */ + cp = akvalue(mp->m_mbox); + if (cp == mp->m_mbox) + /* wasn't an alias - use what the user typed */ + linepos = putone( mp->m_text, linepos, namelen ); + else + /* an alias - expand it */ + while ((cp = getname(cp))) { + if (linepos > MAX_SM_FIELD) { + fprintf (out, "\n%s: ", name); + linepos = namelen; + } + mp2 = getm( cp, NULL, 0, AD_HOST, NULL); + if (akvisible()) { + mp2->m_pers = getcpy(mp->m_mbox); + linepos = putone( adrformat(mp2), linepos, namelen ); + } else { + linepos = putone( mp2->m_text, linepos, namelen ); + } + mnfree( mp2 ); + } + } else { + /* not a local name - use what the user typed */ + linepos = putone( mp->m_text, linepos, namelen ); + } + mp2 = mp; + mp = mp->m_next; + mnfree( mp2 ); } - mp2 = mp; - mp = mp->m_next; - mnfree( mp2 ); - } - putc( '\n', out ); + putc( '\n', out ); } static int putone (char *adr, int pos, int indent) { - register int len; - static int linepos; - - len = strlen( adr ); - if (pos == indent) - linepos = pos; - else if ( linepos+len > outputlinelen ) { - fprintf ( out, ",\n%*s", indent, ""); - linepos = indent; - pos += indent + 2; - } - else { - fputs( ", ", out ); - linepos += 2; - pos += 2; - } - fputs( adr, out ); - - linepos += len; - return (pos+len); + register int len; + static int linepos; + + len = strlen( adr ); + if (pos == indent) + linepos = pos; + else if ( linepos+len > outputlinelen ) { + fprintf ( out, ",\n%*s", indent, ""); + linepos = indent; + pos += indent + 2; + } + else { + fputs( ", ", out ); + linepos += 2; + pos += 2; + } + fputs( adr, out ); + + linepos += len; + return (pos+len); } static void insert_fcc (struct headers *hdr, unsigned char *pp) { - unsigned char *cp; - - for (cp = pp; isspace (*cp); cp++) - continue; - for (pp += strlen (pp) - 1; pp > cp && isspace (*pp); pp--) - continue; - if (pp >= cp) - *++pp = 0; - if (*cp == 0) - return; - - if (fccind >= FCCS) - adios (NULL, "too many %ss", hdr->value); - fccfold[fccind++] = getcpy (cp); + unsigned char *cp; + + for (cp = pp; isspace (*cp); cp++) + continue; + for (pp += strlen (pp) - 1; pp > cp && isspace (*pp); pp--) + continue; + if (pp >= cp) + *++pp = 0; + if (*cp == 0) + return; + + if (fccind >= FCCS) + adios (NULL, "too many %ss", hdr->value); + fccfold[fccind++] = getcpy (cp); } #if 0 @@ -742,138 +755,138 @@ insert_fcc (struct headers *hdr, unsigned char *pp) static void make_bcc_file (void) { - pid_t child_id; - int fd, i, status; - char *vec[6]; - FILE * in, *out; + pid_t child_id; + int fd, i, status; + char *vec[6]; + FILE * in, *out; #ifdef HAVE_MKSTEMP - fd = mkstemp(bccfil); - if (fd == -1 || (out = fdopen(fd, "w")) == NULL) - adios (bccfil, "unable to create"); + fd = mkstemp(bccfil); + if (fd == -1 || (out = fdopen(fd, "w")) == NULL) + adios (bccfil, "unable to create"); #else - mktemp (bccfil); - if ((out = fopen (bccfil, "w")) == NULL) - adios (bccfil, "unable to create"); + mktemp (bccfil); + if ((out = fopen (bccfil, "w")) == NULL) + adios (bccfil, "unable to create"); #endif - chmod (bccfil, 0600); - - fprintf (out, "Date: %s\n", dtimenow (0)); - if (msgflags & MFRM) { - /* There was already a From: in the draft. Don't add one. */ - if (!draft_from_masquerading) - /* mts.conf didn't contain "masquerade:[...]draft_from[...]" - so we'll reveal the user's actual account@thismachine - address in a Sender: header (and use it as the envelope - From: later). */ - fprintf (out, "Sender: %s\n", from); - } - else - /* Construct a From: header. */ - fprintf (out, "From: %s\n", signature); - if (subject) - fprintf (out, "Subject: %s", subject); - fprintf (out, "BCC:\n\n------- Blind-Carbon-Copy\n\n"); - fflush (out); - - if (filter == NULL) { - if ((fd = open (tmpfil, O_RDONLY)) == NOTOK) - adios (NULL, "unable to re-open"); - cpydgst (fd, fileno (out), tmpfil, bccfil); - close (fd); - } - else { - vec[0] = r1bindex (mhlproc, '/'); - - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - adios ("vfork", "unable to"); - - case OK: - dup2 (fileno (out), 1); - - i = 1; - vec[i++] = "-forward"; - vec[i++] = "-form"; - vec[i++] = filter; - vec[i++] = tmpfil; - vec[i] = NULL; - - execvp (mhlproc, vec); - adios (mhlproc, "unable to exec"); - - default: - if (status = pidwait(child_id, OK)) - admonish (NULL, "%s lost (status=0%o)", vec[0], status); - break; + chmod (bccfil, 0600); + + fprintf (out, "Date: %s\n", dtimenow (0)); + if (msgflags & MFRM) { + /* There was already a From: in the draft. Don't add one. */ + if (!draft_from_masquerading) + /* + * mts.conf didn't contain "masquerade:[...]draft_from[...]" + * so we'll reveal the user's actual account@thismachine + * address in a Sender: header (and use it as the envelope + * From: later). + */ + fprintf (out, "Sender: %s\n", from); + } else + /* Construct a From: header. */ + fprintf (out, "From: %s\n", signature); + if (subject) + fprintf (out, "Subject: %s", subject); + fprintf (out, "BCC:\n\n------- Blind-Carbon-Copy\n\n"); + fflush (out); + + if (filter == NULL) { + if ((fd = open (tmpfil, O_RDONLY)) == NOTOK) + adios (NULL, "unable to re-open"); + cpydgst (fd, fileno (out), tmpfil, bccfil); + close (fd); + } else { + vec[0] = r1bindex (mhlproc, '/'); + + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + adios ("vfork", "unable to"); + + case OK: + dup2 (fileno (out), 1); + + i = 1; + vec[i++] = "-forward"; + vec[i++] = "-form"; + vec[i++] = filter; + vec[i++] = tmpfil; + vec[i] = NULL; + + execvp (mhlproc, vec); + adios (mhlproc, "unable to exec"); + + default: + if (status = pidwait(child_id, OK)) + admonish (NULL, "%s lost (status=0%o)", vec[0], status); + break; + } } - } - fseek (out, 0L, SEEK_END); - fprintf (out, "\n------- End of Blind-Carbon-Copy\n"); - fclose (out); + fseek (out, 0L, SEEK_END); + fprintf (out, "\n------- End of Blind-Carbon-Copy\n"); + fclose (out); } -#endif /* if 0 */ +#endif /* if 0 */ /* FCC INTERACTION */ static void file (char *path) { - int i; + int i; - if (fccind == 0) - return; + if (fccind == 0) + return; - for (i = 0; i < fccind; i++) - if (whomflg) - printf ("Fcc: %s\n", fccfold[i]); - else - fcc (path, fccfold[i]); + for (i = 0; i < fccind; i++) + if (whomflg) + printf ("Fcc: %s\n", fccfold[i]); + else + fcc (path, fccfold[i]); } static void fcc (char *file, char *folder) { - pid_t child_id; - int i, status; - char fold[BUFSIZ]; - - if (verbose) - printf ("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", folder); - fflush (stdout); - - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - if (!verbose) - fprintf (stderr, " %sFcc %s: ", - msgstate == resent ? "Resent-" : "", folder); - fprintf (verbose ? stdout : stderr, "no forks, so not ok\n"); - break; - - case OK: - snprintf (fold, sizeof(fold), "%s%s", - *folder == '+' || *folder == '@' ? "" : "+", folder); - execlp (fileproc, r1bindex (fileproc, '/'), - "-link", "-file", file, fold, NULL); - _exit (-1); - - default: - if ((status = pidwait(child_id, OK))) { - if (!verbose) - fprintf (stderr, " %sFcc %s: ", - msgstate == resent ? "Resent-" : "", folder); - fprintf (verbose ? stdout : stderr, - " errored (0%o)\n", status); - } - } - - fflush (stdout); + pid_t child_id; + int i, status; + char fold[BUFSIZ]; + + if (verbose) + printf ("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", folder); + fflush (stdout); + + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + if (!verbose) + fprintf (stderr, " %sFcc %s: ", + msgstate == resent ? "Resent-" : "", folder); + fprintf (verbose ? stdout : stderr, "no forks, so not ok\n"); + break; + + case OK: + snprintf (fold, sizeof(fold), "%s%s", + *folder == '+' || *folder == '@' ? "" : "+", folder); + execlp (fileproc, r1bindex (fileproc, '/'), + "-link", "-file", file, fold, NULL); + _exit (-1); + + default: + if ((status = pidwait(child_id, OK))) { + if (!verbose) + fprintf (stderr, " %sFcc %s: ", + msgstate == resent ? "Resent-" : "", folder); + fprintf (verbose ? stdout : stderr, + " errored (0%o)\n", status); + } + } + + fflush (stdout); } @@ -886,12 +899,12 @@ fcc (char *file, char *folder) static void die (char *what, char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - advertise (what, NULL, fmt, ap); - va_end(ap); + va_start(ap, fmt); + advertise (what, NULL, fmt, ap); + va_end(ap); - done (1); + done (1); } #endif diff --git a/uip/termsbr.c b/uip/termsbr.c index 740d021..ce1420c 100644 --- a/uip/termsbr.c +++ b/uip/termsbr.c @@ -1,4 +1,3 @@ - /* * termsbr.c -- termcap support * @@ -37,7 +36,7 @@ #endif #if BUFSIZ<2048 -# define TXTSIZ 2048 +# define TXTSIZ 2048 #else # define TXTSIZ BUFSIZ #endif @@ -61,10 +60,10 @@ static long speedcode; static int initLI = 0; static int initCO = 0; -static int HC = 0; /* are we on a hardcopy terminal? */ -static int LI = 40; /* number of lines */ -static int CO = 80; /* number of colums */ -static char *CL = NULL; /* termcap string to clear screen */ +static int HC = 0; /* are we on a hardcopy terminal? */ +static int LI = 40; /* number of lines */ +static int CO = 80; /* number of colums */ +static char *CL = NULL; /* termcap string to clear screen */ static char *SE = NULL; /* termcap string to end standout mode */ static char *SO = NULL; /* termcap string to begin standout mode */ @@ -74,67 +73,67 @@ static char termcap[TXTSIZ]; static void read_termcap(void) { - char *bp, *cp; - char *term; + char *bp, *cp; + char *term; #ifndef TGETENT_ACCEPTS_NULL - char termbuf[TXTSIZ]; + char termbuf[TXTSIZ]; #endif #ifdef HAVE_TERMIOS_H - struct termios tio; + struct termios tio; #else # ifdef HAVE_TERMIO_H - struct termio tio; + struct termio tio; # else - struct sgttyb tio; + struct sgttyb tio; # endif #endif - static int inited = 0; + static int inited = 0; - if (inited++) - return; + if (inited++) + return; - if (!(term = getenv ("TERM"))) - return; + if (!(term = getenv ("TERM"))) + return; /* * If possible, we let tgetent allocate its own termcap buffer */ #ifdef TGETENT_ACCEPTS_NULL - if (tgetent (NULL, term) != TGETENT_SUCCESS) - return; + if (tgetent (NULL, term) != TGETENT_SUCCESS) + return; #else - if (tgetent (termbuf, term) != TGETENT_SUCCESS) - return; + if (tgetent (termbuf, term) != TGETENT_SUCCESS) + return; #endif #ifdef HAVE_TERMIOS_H - speedcode = cfgetospeed(&tio); + speedcode = cfgetospeed(&tio); #else # ifdef HAVE_TERMIO_H - speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ? tio.c_cflag & CBAUD : 0; + speedcode = ioctl(fileno(stdout), TCGETA, &tio) != NOTOK ? tio.c_cflag & CBAUD : 0; # else - speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ? tio.sg_ospeed : 0; + speedcode = ioctl(fileno(stdout), TIOCGETP, (char *) &tio) != NOTOK ? tio.sg_ospeed : 0; # endif #endif - HC = tgetflag ("hc"); - - if (!initCO && (CO = tgetnum ("co")) <= 0) - CO = 80; - if (!initLI && (LI = tgetnum ("li")) <= 0) - LI = 24; - - cp = termcap; - CL = tgetstr ("cl", &cp); - if ((bp = tgetstr ("pc", &cp))) - PC = *bp; - if (tgetnum ("sg") <= 0) { - SE = tgetstr ("se", &cp); - SO = tgetstr ("so", &cp); - } + HC = tgetflag ("hc"); + + if (!initCO && (CO = tgetnum ("co")) <= 0) + CO = 80; + if (!initLI && (LI = tgetnum ("li")) <= 0) + LI = 24; + + cp = termcap; + CL = tgetstr ("cl", &cp); + if ((bp = tgetstr ("pc", &cp))) + PC = *bp; + if (tgetnum ("sg") <= 0) { + SE = tgetstr ("se", &cp); + SO = tgetstr ("so", &cp); + } } @@ -142,18 +141,18 @@ int sc_width (void) { #ifdef TIOCGWINSZ - struct winsize win; - int width; - - if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK - && (width = win.ws_col) > 0) { - CO = width; - initCO++; - } else + struct winsize win; + int width; + + if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK + && (width = win.ws_col) > 0) { + CO = width; + initCO++; + } else #endif /* TIOCGWINSZ */ - read_termcap(); + read_termcap(); - return CO; + return CO; } @@ -161,40 +160,40 @@ int sc_length (void) { #ifdef TIOCGWINSZ - struct winsize win; + struct winsize win; - if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK - && (LI = win.ws_row) > 0) - initLI++; - else + if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK + && (LI = win.ws_row) > 0) + initLI++; + else #endif /* TIOCGWINSZ */ - read_termcap(); + read_termcap(); - return LI; + return LI; } static int outc (int c) { - return putchar(c); + return putchar(c); } void clear_screen (void) { - read_termcap (); + read_termcap (); - if (CL && speedcode) - tputs (CL, LI, outc); - else { - printf ("\f"); - if (speedcode) - printf ("\200"); - } + if (CL && speedcode) + tputs (CL, LI, outc); + else { + printf ("\f"); + if (speedcode) + printf ("\200"); + } - fflush (stdout); + fflush (stdout); } @@ -204,21 +203,21 @@ clear_screen (void) int SOprintf (char *fmt, ...) { - va_list ap; + va_list ap; - read_termcap (); - if (!(SO && SE)) - return NOTOK; + read_termcap (); + if (!(SO && SE)) + return NOTOK; - tputs (SO, 1, outc); + tputs (SO, 1, outc); - va_start(ap, fmt); - vprintf (fmt, ap); - va_end(ap); + va_start(ap, fmt); + vprintf (fmt, ap); + va_end(ap); - tputs (SE, 1, outc); + tputs (SE, 1, outc); - return OK; + return OK; } /* @@ -228,7 +227,6 @@ SOprintf (char *fmt, ...) int sc_hardcopy(void) { - read_termcap(); - return HC; + read_termcap(); + return HC; } - diff --git a/uip/viamail.c b/uip/viamail.c index aea746d..1d876cb 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -1,4 +1,3 @@ - /* * viamail.c -- send multiple files in a MIME message * @@ -23,38 +22,38 @@ #endif static struct swit switches[] = { -#define TOSW 0 - { "to mailpath", 0 }, -#define FROMSW 1 - { "from mailpath", 0 }, -#define SUBJECTSW 2 - { "subject subject", 0 }, -#define PARAMSW 3 - { "parameters arguments", 0 }, -#define DESCRIPTSW 4 - { "description text", 0 }, -#define COMMENTSW 5 - { "comment text", 0 }, -#define DELAYSW 6 - { "delay seconds", 0 }, -#define VERBSW 7 - { "verbose", 0 }, -#define NVERBSW 8 - { "noverbose", 0 }, -#define VERSIONSW 9 - { "version", 0 }, -#define HELPSW 10 - { "help", 0 }, -#define DEBUGSW 11 - { "debug", -5 }, - { NULL, 0 } +#define TOSW 0 + { "to mailpath", 0 }, +#define FROMSW 1 + { "from mailpath", 0 }, +#define SUBJECTSW 2 + { "subject subject", 0 }, +#define PARAMSW 3 + { "parameters arguments", 0 }, +#define DESCRIPTSW 4 + { "description text", 0 }, +#define COMMENTSW 5 + { "comment text", 0 }, +#define DELAYSW 6 + { "delay seconds", 0 }, +#define VERBSW 7 + { "verbose", 0 }, +#define NVERBSW 8 + { "noverbose", 0 }, +#define VERSIONSW 9 + { "version", 0 }, +#define HELPSW 10 + { "help", 0 }, +#define DEBUGSW 11 + { "debug", -5 }, + { NULL, 0 } }; extern int debugsw; extern int splitsw; extern int verbsw; -int ebcdicsw = 0; /* hack for linking purposes */ +int ebcdicsw = 0; /* hack for linking purposes */ /* mhmisc.c */ void set_endian (void); @@ -71,98 +70,99 @@ static int via_mail (char *, char *, char *, char *, char *, int, char *); int main (int argc, char **argv) { - int delay = 0; - char *f1 = NULL, *f2 = NULL, *f3 = NULL; - char *f4 = NULL, *f5 = NULL, *f7 = NULL; - char *cp, buf[BUFSIZ]; - char **argp, **arguments; + int delay = 0; + char *f1 = NULL, *f2 = NULL, *f3 = NULL; + char *f4 = NULL, *f5 = NULL, *f7 = NULL; + char *cp, buf[BUFSIZ]; + char **argp, **arguments; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); - - arguments = getarguments (invo_name, argc, argv, 0); - argp = arguments; + invo_name = r1bindex (argv[0], '/'); - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); + /* foil search of user profile/context */ + if (context_foil (NULL) == -1) done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case TOSW: - if (!(f1 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case SUBJECTSW: - if (!(f2 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case PARAMSW: - if (!(f3 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case DESCRIPTSW: - if (!(f4 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case COMMENTSW: - if (!(f5 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case DELAYSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - - /* - * If there is an error, just reset the delay parameter - * to -1. We will set a default delay later. - */ - if (sscanf (cp, "%d", &delay) != 1) - delay = -1; - continue; - case FROMSW: - if (!(f7 = *argp++)) - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case VERBSW: - verbsw = 1; - continue; - case NVERBSW: - verbsw = 0; - continue; - - case DEBUGSW: - debugsw = 1; - continue; - } + arguments = getarguments (invo_name, argc, argv, 0); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case TOSW: + if (!(f1 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case SUBJECTSW: + if (!(f2 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case PARAMSW: + if (!(f3 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case DESCRIPTSW: + if (!(f4 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case COMMENTSW: + if (!(f5 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case DELAYSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + + /* + * If there is an error, just reset the + * delay parameter to -1. We will set + * a default delay later. + */ + if (sscanf (cp, "%d", &delay) != 1) + delay = -1; + continue; + case FROMSW: + if (!(f7 = *argp++)) + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case VERBSW: + verbsw = 1; + continue; + case NVERBSW: + verbsw = 0; + continue; + + case DEBUGSW: + debugsw = 1; + continue; + } + } } - } - set_endian (); + set_endian (); - if (!f1) - adios (NULL, "missing -viamail \"mailpath\" switch"); + if (!f1) + adios (NULL, "missing -viamail \"mailpath\" switch"); - via_mail (f1, f2, f3, f4, f5, delay, f7); - return 0; /* dead code to satisfy the compiler */ + via_mail (f1, f2, f3, f4, f5, delay, f7); + return 0; /* dead code to satisfy the compiler */ } @@ -172,81 +172,81 @@ main (int argc, char **argv) static int via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw, - char *cmntsw, int delay, char *fromsw) + char *cmntsw, int delay, char *fromsw) { - int status, vecp = 1; - char tmpfil[BUFSIZ]; - char *vec[MAXARGS]; - struct stat st; - FILE *fp; - char *tfile = NULL; - - umask (~m_gmprot ()); - - tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) adios("viamail", "unable to create temporary file"); - chmod(tfile, 0600); - strncpy (tmpfil, tfile, sizeof(tmpfil)); - - if (!strchr(mailsw, '@')) - mailsw = concat (mailsw, "@", LocalName (), NULL); - fprintf (fp, "To: %s\n", mailsw); - - if (subjsw) - fprintf (fp, "Subject: %s\n", subjsw); - - if (fromsw) { - if (!strchr(fromsw, '@')) - fromsw = concat (fromsw, "@", LocalName (), NULL); - fprintf (fp, "From: %s\n", fromsw); - } - - fprintf (fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE); - fprintf (fp, "%s: application/octet-stream", TYPE_FIELD); - - if (parmsw) - fprintf (fp, "; %s", parmsw); - - if (cmntsw) - fprintf (fp, "\n\t(%s)", cmntsw); - - if (descsw) - fprintf (fp, "\n%s: %s", DESCR_FIELD, descsw); - - fprintf (fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64"); - - if (fflush (fp)) - adios (tmpfil, "error writing to"); - - writeBase64aux (stdin, fp); - if (fflush (fp)) - adios (tmpfil, "error writing to"); - - if (fstat (fileno (fp), &st) == NOTOK) - adios ("failed", "fstat of %s", tmpfil); - - if (delay < 0) - splitsw = 10; - else - splitsw = delay; - - status = 0; - vec[0] = r1bindex (postproc, '/'); - if (verbsw) - vec[vecp++] = "-verbose"; - - switch (sendsbr (vec, vecp, tmpfil, &st, 0, (char *)0, 0)) { - case DONE: - case NOTOK: - status++; - break; - case OK: - break; - } - - fclose (fp); - if (unlink (tmpfil) == -1) - advise (NULL, "unable to remove temp file %s", tmpfil); - done (status); - return 1; + int status, vecp = 1; + char tmpfil[BUFSIZ]; + char *vec[MAXARGS]; + struct stat st; + FILE *fp; + char *tfile = NULL; + + umask (~m_gmprot ()); + + tfile = m_mktemp2(NULL, invo_name, NULL, &fp); + if (tfile == NULL) adios("viamail", "unable to create temporary file"); + chmod(tfile, 0600); + strncpy (tmpfil, tfile, sizeof(tmpfil)); + + if (!strchr(mailsw, '@')) + mailsw = concat (mailsw, "@", LocalName (), NULL); + fprintf (fp, "To: %s\n", mailsw); + + if (subjsw) + fprintf (fp, "Subject: %s\n", subjsw); + + if (fromsw) { + if (!strchr(fromsw, '@')) + fromsw = concat (fromsw, "@", LocalName (), NULL); + fprintf (fp, "From: %s\n", fromsw); + } + + fprintf (fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE); + fprintf (fp, "%s: application/octet-stream", TYPE_FIELD); + + if (parmsw) + fprintf (fp, "; %s", parmsw); + + if (cmntsw) + fprintf (fp, "\n\t(%s)", cmntsw); + + if (descsw) + fprintf (fp, "\n%s: %s", DESCR_FIELD, descsw); + + fprintf (fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64"); + + if (fflush (fp)) + adios (tmpfil, "error writing to"); + + writeBase64aux (stdin, fp); + if (fflush (fp)) + adios (tmpfil, "error writing to"); + + if (fstat (fileno (fp), &st) == NOTOK) + adios ("failed", "fstat of %s", tmpfil); + + if (delay < 0) + splitsw = 10; + else + splitsw = delay; + + status = 0; + vec[0] = r1bindex (postproc, '/'); + if (verbsw) + vec[vecp++] = "-verbose"; + + switch (sendsbr (vec, vecp, tmpfil, &st, 0, (char *)0, 0)) { + case DONE: + case NOTOK: + status++; + break; + case OK: + break; + } + + fclose (fp); + if (unlink (tmpfil) == -1) + advise (NULL, "unable to remove temp file %s", tmpfil); + done (status); + return 1; } diff --git a/uip/whatnow.c b/uip/whatnow.c index d3fccfd..a6bb0f9 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -1,4 +1,3 @@ - /* * whatnow.c -- the nmh `WhatNow' shell * @@ -17,7 +16,7 @@ int main (int argc, char **argv) { #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - return WhatNow (argc, argv); + return WhatNow (argc, argv); } diff --git a/uip/whatnowproc.c b/uip/whatnowproc.c index 6bf4b36..44146d7 100644 --- a/uip/whatnowproc.c +++ b/uip/whatnowproc.c @@ -1,4 +1,3 @@ - /* * whatnowproc.c -- exec the "whatnowproc" * @@ -25,97 +24,97 @@ int WhatNow (int, char **); int what_now (char *ed, int nedit, int use, char *file, char *altmsg, int dist, - struct msgs *mp, char *text, int inplace, char *cwd) + struct msgs *mp, char *text, int inplace, char *cwd) { - int found, k, msgnum, vecp; - int len, buflen; - register char *bp; - char buffer[BUFSIZ], *vec[MAXARGS]; - - vecp = 0; - vec[vecp++] = r1bindex (whatnowproc, '/'); - vec[vecp] = NULL; - - m_putenv ("mhdraft", file); - if (mp) - m_putenv ("mhfolder", mp->foldpath); - else - unputenv ("mhfolder"); - if (altmsg) { - if (mp == NULL || *altmsg == '/' || cwd == NULL) - m_putenv ("mhaltmsg", altmsg); - else { - snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, altmsg); - m_putenv ("mhaltmsg", buffer); - } - } else { - unputenv ("mhaltmsg"); - } - if ((bp = getenv ("mhaltmsg")))/* XXX */ - m_putenv ("editalt", bp); - snprintf (buffer, sizeof(buffer), "%d", dist); - m_putenv ("mhdist", buffer); - if (nedit) { - unputenv ("mheditor"); - } else { - m_putenv ("mheditor", ed ? ed : (ed = context_find ("editor")) - ? ed : defaulteditor); - } - snprintf (buffer, sizeof(buffer), "%d", use); - m_putenv ("mhuse", buffer); - - unputenv ("mhmessages"); - unputenv ("mhannotate"); - unputenv ("mhinplace"); - - if (text && mp && !is_readonly(mp)) { - found = 0; - bp = buffer; - buflen = sizeof(buffer); - for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { - if (is_selected(mp, msgnum)) { - snprintf (bp, buflen, "%s%s", found ? " " : "", m_name (msgnum)); - len = strlen (bp); - bp += len; - buflen -= len; - for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++) - continue; - if (--k > msgnum) { - snprintf (bp, buflen, "-%s", m_name (k)); - len = strlen (bp); - bp += len; - buflen -= len; + int found, k, msgnum, vecp; + int len, buflen; + register char *bp; + char buffer[BUFSIZ], *vec[MAXARGS]; + + vecp = 0; + vec[vecp++] = r1bindex (whatnowproc, '/'); + vec[vecp] = NULL; + + m_putenv ("mhdraft", file); + if (mp) + m_putenv ("mhfolder", mp->foldpath); + else + unputenv ("mhfolder"); + if (altmsg) { + if (mp == NULL || *altmsg == '/' || cwd == NULL) + m_putenv ("mhaltmsg", altmsg); + else { + snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, altmsg); + m_putenv ("mhaltmsg", buffer); } - msgnum = k + 1; - found++; - } + } else { + unputenv ("mhaltmsg"); } - if (found) { - m_putenv ("mhmessages", buffer); - m_putenv ("mhannotate", text); - snprintf (buffer, sizeof(buffer), "%d", inplace); - m_putenv ("mhinplace", buffer); + if ((bp = getenv ("mhaltmsg")))/* XXX */ + m_putenv ("editalt", bp); + snprintf (buffer, sizeof(buffer), "%d", dist); + m_putenv ("mhdist", buffer); + if (nedit) { + unputenv ("mheditor"); + } else { + m_putenv ("mheditor", ed ? ed : (ed = context_find ("editor")) + ? ed : defaulteditor); + } + snprintf (buffer, sizeof(buffer), "%d", use); + m_putenv ("mhuse", buffer); + + unputenv ("mhmessages"); + unputenv ("mhannotate"); + unputenv ("mhinplace"); + + if (text && mp && !is_readonly(mp)) { + found = 0; + bp = buffer; + buflen = sizeof(buffer); + for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { + if (is_selected(mp, msgnum)) { + snprintf (bp, buflen, "%s%s", found ? " " : "", m_name (msgnum)); + len = strlen (bp); + bp += len; + buflen -= len; + for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++) + continue; + if (--k > msgnum) { + snprintf (bp, buflen, "-%s", m_name (k)); + len = strlen (bp); + bp += len; + buflen -= len; + } + msgnum = k + 1; + found++; + } + } + if (found) { + m_putenv ("mhmessages", buffer); + m_putenv ("mhannotate", text); + snprintf (buffer, sizeof(buffer), "%d", inplace); + m_putenv ("mhinplace", buffer); + } } - } - context_save (); /* save the context file */ - fflush (stdout); + context_save (); /* save the context file */ + fflush (stdout); - if (cwd) - chdir (cwd); + if (cwd) + chdir (cwd); - /* - * If the "whatnowproc" is the nmh command "whatnow", - * we run it internally, rather than exec'ing it. - */ - if (strcmp (vec[0], "whatnow") == 0) { - WhatNow (vecp, vec); - done (0); - } + /* + * If the "whatnowproc" is the nmh command "whatnow", + * we run it internally, rather than exec'ing it. + */ + if (strcmp (vec[0], "whatnow") == 0) { + WhatNow (vecp, vec); + done (0); + } - execvp (whatnowproc, vec); - fprintf (stderr, "unable to exec "); - perror (whatnowproc); + execvp (whatnowproc, vec); + fprintf (stderr, "unable to exec "); + perror (whatnowproc); - return 0; + return 0; } diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index f5f78d7..a41ee46 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -1,4 +1,3 @@ - /* * whatnowsbr.c -- the WhatNow shell * @@ -12,30 +11,30 @@ * * Several commands have been added at the whatnow prompt: * - * cd [ directory ] This option works just like the shell's - * cd command and lets the user change the - * directory from which attachments are - * taken so that long path names are not - * needed with every file. + * cd [ directory ] This option works just like the shell's + * cd command and lets the user change the + * directory from which attachments are + * taken so that long path names are not + * needed with every file. * - * ls [ ls-options ] This option works just like the normal - * ls command and exists to allow the user - * to verify file names in the directory. + * ls [ ls-options ] This option works just like the normal + * ls command and exists to allow the user + * to verify file names in the directory. * - * pwd This option works just like the normal - * pwd command and exists to allow the user - * to verify the directory. + * pwd This option works just like the normal + * pwd command and exists to allow the user + * to verify the directory. * - * attach files This option attaches the named files to - * the draft. + * attach files This option attaches the named files to + * the draft. * - * alist [-ln] This option lists the attachments on the - * draft. -l gets long listings, -n gets - * numbered listings. + * alist [-ln] This option lists the attachments on the + * draft. -l gets long listings, -n gets + * numbered listings. * - * detach files This option removes attachments from the - * detach -n numbers draft. This can be done by file name or - * by attachment number. + * detach files This option removes attachments from the + * detach -n numbers draft. This can be done by file name or + * by attachment number. */ #include @@ -45,64 +44,64 @@ #include static struct swit whatnowswitches[] = { -#define DFOLDSW 0 - { "draftfolder +folder", 0 }, -#define DMSGSW 1 - { "draftmessage msg", 0 }, -#define NDFLDSW 2 - { "nodraftfolder", 0 }, -#define EDITRSW 3 - { "editor editor", 0 }, -#define NEDITSW 4 - { "noedit", 0 }, -#define PRMPTSW 5 - { "prompt string", 4 }, -#define VERSIONSW 6 - { "version", 0 }, -#define HELPSW 7 - { "help", 0 }, -#define ATTACHSW 8 - { "attach header-field-name", 0 }, - { NULL, 0 } +#define DFOLDSW 0 + { "draftfolder +folder", 0 }, +#define DMSGSW 1 + { "draftmessage msg", 0 }, +#define NDFLDSW 2 + { "nodraftfolder", 0 }, +#define EDITRSW 3 + { "editor editor", 0 }, +#define NEDITSW 4 + { "noedit", 0 }, +#define PRMPTSW 5 + { "prompt string", 4 }, +#define VERSIONSW 6 + { "version", 0 }, +#define HELPSW 7 + { "help", 0 }, +#define ATTACHSW 8 + { "attach header-field-name", 0 }, + { NULL, 0 } }; /* * Options at the "whatnow" prompt */ static struct swit aleqs[] = { -#define EDITSW 0 - { "edit [ ]", 0 }, -#define REFILEOPT 1 - { "refile [] +folder", 0 }, -#define BUILDMIMESW 2 - { "mime []", 0 }, -#define DISPSW 3 - { "display []", 0 }, -#define LISTSW 4 - { "list []", 0 }, -#define SENDSW 5 - { "send []", 0 }, -#define PUSHSW 6 - { "push []", 0 }, -#define WHOMSW 7 - { "whom []", 0 }, -#define QUITSW 8 - { "quit [-delete]", 0 }, -#define DELETESW 9 - { "delete", 0 }, -#define CDCMDSW 10 - { "cd [directory]", 0 }, -#define PWDCMDSW 11 - { "pwd", 0 }, -#define LSCMDSW 12 - { "ls", 0 }, -#define ATTACHCMDSW 13 - { "attach", 0 }, -#define DETACHCMDSW 14 - { "detach [-n]", 2 }, -#define ALISTCMDSW 15 - { "alist [-ln] ", 2 }, - { NULL, 0 } +#define EDITSW 0 + { "edit [ ]", 0 }, +#define REFILEOPT 1 + { "refile [] +folder", 0 }, +#define BUILDMIMESW 2 + { "mime []", 0 }, +#define DISPSW 3 + { "display []", 0 }, +#define LISTSW 4 + { "list []", 0 }, +#define SENDSW 5 + { "send []", 0 }, +#define PUSHSW 6 + { "push []", 0 }, +#define WHOMSW 7 + { "whom []", 0 }, +#define QUITSW 8 + { "quit [-delete]", 0 }, +#define DELETESW 9 + { "delete", 0 }, +#define CDCMDSW 10 + { "cd [directory]", 0 }, +#define PWDCMDSW 11 + { "pwd", 0 }, +#define LSCMDSW 12 + { "ls", 0 }, +#define ATTACHCMDSW 13 + { "attach", 0 }, +#define DETACHCMDSW 14 + { "detach [-n]", 2 }, +#define ALISTCMDSW 15 + { "alist [-ln] ", 2 }, + { NULL, 0 } }; static char *myprompt = "\nWhat now? "; @@ -132,446 +131,458 @@ static int copyf (char *, char *); int WhatNow (int argc, char **argv) { - int isdf = 0, nedit = 0, use = 0; - char *cp, *dfolder = NULL, *dmsg = NULL; - char *ed = NULL, *drft = NULL, *msgnam = NULL; - char buf[BUFSIZ], prompt[BUFSIZ]; - char **argp, **arguments; - struct stat st; - char *attach = (char *)0; /* attachment header field name */ - char cwd[MAXPATHLEN + 1]; /* current working directory */ - char file[MAXPATHLEN + 1]; /* file name buffer */ - char shell[MAXPATHLEN + 1]; /* shell response buffer */ - FILE *f; /* read pointer for bgnd proc */ - char *l; /* set on -l to alist command */ - int n; /* set on -n to alist command */ - - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - /* - * Get the initial current working directory. - */ - - if (getcwd(cwd, sizeof (cwd)) == (char *)0) { - adios("getcwd", "could not get working directory"); - } - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, whatnowswitches)) { - case AMBIGSW: - ambigsw (cp, whatnowswitches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); + int isdf = 0, nedit = 0, use = 0; + char *cp, *dfolder = NULL, *dmsg = NULL; + char *ed = NULL, *drft = NULL, *msgnam = NULL; + char buf[BUFSIZ], prompt[BUFSIZ]; + char **argp, **arguments; + struct stat st; + char *attach = (char *)0; /* attachment header field name */ + char cwd[MAXPATHLEN + 1]; /* current working directory */ + char file[MAXPATHLEN + 1]; /* file name buffer */ + char shell[MAXPATHLEN + 1]; /* shell response buffer */ + FILE *f; /* read pointer for bgnd proc */ + char *l; /* set on -l to alist command */ + int n; /* set on -n to alist command */ + + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + /* + * Get the initial current working directory. + */ + + if (getcwd(cwd, sizeof (cwd)) == (char *)0) { + adios("getcwd", "could not get working directory"); + } - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name); - print_help (buf, whatnowswitches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, whatnowswitches)) { + case AMBIGSW: + ambigsw (cp, whatnowswitches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name); + print_help (buf, whatnowswitches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (dmsg) + adios (NULL, "only one draft message at a time!"); + if (!(dmsg = *argp++) || *dmsg == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios (NULL, "missing argument to %s", argp[-2]); + nedit = 0; + continue; + case NEDITSW: + nedit++; + continue; + + case PRMPTSW: + if (!(myprompt = *argp++) || *myprompt == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case ATTACHSW: + if (attach != (char *)0) + adios(NULL, "only one attachment header field name at a time!"); + if (!(attach = *argp++) || *attach == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + } + } + if (drft) + adios (NULL, "only one draft at a time!"); + else + drft = cp; + } + + if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0) + drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); + + msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL; - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: + if ((cp = getenv ("mhuse")) && *cp) + use = atoi (cp); + + if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) { + ed = NULL; nedit++; - continue; - - case PRMPTSW: - if (!(myprompt = *argp++) || *myprompt == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case ATTACHSW: - if (attach != (char *)0) - adios(NULL, "only one attachment header field name at a time!"); - if (!(attach = *argp++) || *attach == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - } - } - if (drft) - adios (NULL, "only one draft at a time!"); - else - drft = cp; - } - - if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0) - drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); - - msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL; - - if ((cp = getenv ("mhuse")) && *cp) - use = atoi (cp); - - if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) { - ed = NULL; - nedit++; - } - - /* start editing the draft, unless -noedit was given */ - if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0) - done (1); - - snprintf (prompt, sizeof(prompt), myprompt, invo_name); - for (;;) { - if (!(argp = getans (prompt, aleqs))) { - unlink (altmsglink); - done (1); } - switch (smatch (*argp, aleqs)) { - case DISPSW: - /* display the message being replied to, or distributed */ - if (msgnam) - showfile (++argp, msgnam); - else - advise (NULL, "no alternate message to display"); - break; - - case BUILDMIMESW: - /* Translate MIME composition file */ - buildfile (++argp, drft); - break; - - case EDITSW: - /* Call an editor on the draft file */ - if (*++argp) - ed = *argp++; - if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK) - done (1); - break; - - case LISTSW: - /* display the draft file */ - showfile (++argp, drft); - break; - - case WHOMSW: - /* Check to whom the draft would be sent */ - whomfile (++argp, drft); - break; - - case QUITSW: - /* Quit, and possibly delete the draft */ - if (*++argp && (*argp[0] == 'd' || - ((*argp)[0] == '-' && (*argp)[1] == 'd'))) { - removefile (drft); - } else { - if (stat (drft, &st) != NOTOK) - advise (NULL, "draft left on %s", drft); - } - done (1); - - case DELETESW: - /* Delete draft and exit */ - removefile (drft); - done (1); - - case PUSHSW: - /* Send draft in background */ - if (sendfile (++argp, drft, 1)) - done (1); - break; - case SENDSW: - /* Send draft */ - sendfile (++argp, drft, 0); - break; + /* start editing the draft, unless -noedit was given */ + if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0) + done (1); - case REFILEOPT: - /* Refile the draft */ - if (refile (++argp, drft) == 0) - done (0); - break; - - case CDCMDSW: - /* Change the working directory for attachments - * - * Run the directory through the user's shell so that - * we can take advantage of any syntax that the user - * is accustomed to. Read back the absolute path. - */ - - if (*(argp+1) == (char *)0) { - (void)sprintf(buf, "$SHELL -c \"cd;pwd\""); - } - else { - writesomecmd(buf, BUFSIZ, "cd", "pwd", argp); - } - if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { - fgets(cwd, sizeof (cwd), f); - - if (strchr(cwd, '\n') != (char *)0) - *strchr(cwd, '\n') = '\0'; - - pclose(f); - } - else { - advise("popen", "could not get directory"); - } - - break; - - case PWDCMDSW: - /* Print the working directory for attachments */ - printf("%s\n", cwd); - break; - - case LSCMDSW: - /* List files in the current attachment working directory - * - * Use the user's shell so that we can take advantage of any - * syntax that the user is accustomed to. - */ - writelscmd(buf, sizeof(buf), argp); - (void)system_in_dir(cwd, buf); - break; - - case ALISTCMDSW: - /* - * List attachments on current draft. Options are: - * - * -l long listing (full path names) - * -n numbers listing - */ - - if (attach == (char *)0) { - advise((char *)0, "can't list because no header field name was given."); - break; - } - - l = (char *)0; - n = 0; - - while (*++argp != (char *)0) { - if (strcmp(*argp, "-l") == 0) - l = "/"; - - else if (strcmp(*argp, "-n") == 0) - n = 1; - - else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) { - l = "/"; - n = 1; + snprintf (prompt, sizeof(prompt), myprompt, invo_name); + for (;;) { + if (!(argp = getans (prompt, aleqs))) { + unlink (altmsglink); + done (1); } + switch (smatch (*argp, aleqs)) { + case DISPSW: + /* display the message being replied to, or distributed */ + if (msgnam) + showfile (++argp, msgnam); + else + advise (NULL, "no alternate message to display"); + break; - else { - n = -1; - break; - } - } - - if (n == -1) - advise((char *)0, "usage is alist [-ln]."); - - else - annolist(drft, attach, l, n); - - break; - - case ATTACHCMDSW: - /* - * Attach files to current draft. - */ - - if (attach == (char *)0) { - advise((char *)0, "can't attach because no header field name was given."); - break; - } - - if (*(argp+1) == (char *)0) { - advise((char *)0, "attach command requires file argument(s)."); - break; - } - - /* - * Build a command line that causes the user's shell to list the file name - * arguments. This handles and wildcard expansion, tilde expansion, etc. - */ - writelscmd(buf, sizeof(buf), argp); - - /* - * Read back the response from the shell, which contains a number of lines - * with one file name per line. Remove off the newline. Determine whether - * we have an absolute or relative path name. Prepend the current working - * directory to relative path names. Add the attachment annotation to the - * draft. - */ - - if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { - while (fgets(shell, sizeof (shell), f) != (char *)0) { - *(strchr(shell, '\n')) = '\0'; - - if (*shell == '/') - (void)annotate(drft, attach, shell, 1, 0, -2, 1); - else { - (void)sprintf(file, "%s/%s", cwd, shell); - (void)annotate(drft, attach, file, 1, 0, -2, 1); - } - } + case BUILDMIMESW: + /* Translate MIME composition file */ + buildfile (++argp, drft); + break; - pclose(f); - } - else { - advise("popen", "could not get file from shell"); - } + case EDITSW: + /* Call an editor on the draft file */ + if (*++argp) + ed = *argp++; + if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK) + done (1); + break; + + case LISTSW: + /* display the draft file */ + showfile (++argp, drft); + break; - break; + case WHOMSW: + /* Check to whom the draft would be sent */ + whomfile (++argp, drft); + break; - case DETACHCMDSW: - /* - * Detach files from current draft. - */ + case QUITSW: + /* Quit, and possibly delete the draft */ + if (*++argp && (*argp[0] == 'd' || + ((*argp)[0] == '-' && (*argp)[1] == 'd'))) { + removefile (drft); + } else { + if (stat (drft, &st) != NOTOK) + advise (NULL, "draft left on %s", drft); + } + done (1); - if (attach == (char *)0) { - advise((char *)0, "can't detach because no header field name was given."); - break; - } + case DELETESW: + /* Delete draft and exit */ + removefile (drft); + done (1); - /* - * Scan the arguments for a -n. Mixed file names and numbers aren't allowed, - * so this catches a -n anywhere in the argument list. - */ + case PUSHSW: + /* Send draft in background */ + if (sendfile (++argp, drft, 1)) + done (1); + break; - for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) { - if (strcmp(*arguments, "-n") == 0) { - n = 1; + case SENDSW: + /* Send draft */ + sendfile (++argp, drft, 0); break; - } - } - - /* - * A -n was found so interpret the arguments as attachment numbers. - * Decrement any remaining argument number that is greater than the one - * just processed after processing each one so that the numbering stays - * correct. - */ - - if (n == 1) { - for (arguments = argp + 1; *arguments != (char *)0; arguments++) { - if (strcmp(*arguments, "-n") == 0) - continue; - - if (**arguments != '\0') { - n = atoi(*arguments); - (void)annotate(drft, attach, (char *)0, 1, 0, n, 1); - - for (argp = arguments + 1; *argp != (char *)0; argp++) { - if (atoi(*argp) > n) { - if (atoi(*argp) == 1) - *argp = ""; - else - (void)sprintf(*argp, "%d", atoi(*argp) - 1); - } + + case REFILEOPT: + /* Refile the draft */ + if (refile (++argp, drft) == 0) + done (0); + break; + + case CDCMDSW: + /* + * Change the working directory for attachments + * + * Run the directory through the user's shell + * so that we can take advantage of any syntax + * that the user is accustomed to. Read back + * the absolute path. + */ + + if (*(argp+1) == (char *)0) { + (void)sprintf(buf, "$SHELL -c \"cd;pwd\""); + } else { + writesomecmd(buf, BUFSIZ, "cd", "pwd", argp); } - } - } - } - - /* - * The arguments are interpreted as file names. Run them through the - * user's shell for wildcard expansion and other goodies. Do this from - * the current working directory if the argument is not an absolute path - * name (does not begin with a /). - * - * We feed all the file names to the shell at once, otherwise you can't - * provide a file name with a space in it. - */ - writelscmd(buf, sizeof(buf), argp); - if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { - while (fgets(shell, sizeof (shell), f) != (char *)0) { - *(strchr(shell, '\n')) = '\0'; - (void)annotate(drft, attach, shell, 1, 0, 0, 1); - } - pclose(f); - } else { - advise("popen", "could not get file from shell"); - } + if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { + fgets(cwd, sizeof (cwd), f); - break; + if (strchr(cwd, '\n') != (char *)0) + *strchr(cwd, '\n') = '\0'; - default: - /* Unknown command */ - advise (NULL, "say what?"); - break; + pclose(f); + } else { + advise("popen", "could not get directory"); + } + + break; + + case PWDCMDSW: + /* Print the working directory for attachments */ + printf("%s\n", cwd); + break; + + case LSCMDSW: + /* + * List files in the current attachment working + * directory + * + * Use the user's shell so that we can take + * advantage of any syntax that the user is + * accustomed to. + */ + writelscmd(buf, sizeof(buf), argp); + (void)system_in_dir(cwd, buf); + break; + + case ALISTCMDSW: + /* + * List attachments on current draft. Options are: + * + * -l long listing (full path names) + * -n numbers listing + */ + + if (attach == (char *)0) { + advise((char *)0, "can't list because no header field name was given."); + break; + } + + l = (char *)0; + n = 0; + + while (*++argp != (char *)0) { + if (strcmp(*argp, "-l") == 0) + l = "/"; + + else if (strcmp(*argp, "-n") == 0) + n = 1; + + else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) { + l = "/"; + n = 1; + } else { + n = -1; + break; + } + } + + if (n == -1) + advise((char *)0, "usage is alist [-ln]."); + + else + annolist(drft, attach, l, n); + + break; + + case ATTACHCMDSW: + /* + * Attach files to current draft. + */ + + if (attach == (char *)0) { + advise((char *)0, "can't attach because no header field name was given."); + break; + } + + if (*(argp+1) == (char *)0) { + advise((char *)0, "attach command requires file argument(s)."); + break; + } + + /* + * Build a command line that causes the user's + * shell to list the file name arguments. + * This handles and wildcard expansion, tilde + * expansion, etc. + */ + writelscmd(buf, sizeof(buf), argp); + + /* + * Read back the response from the shell, + * which contains a number of lines with one + * file name per line. Remove off the newline. + * Determine whether we have an absolute or + * relative path name. Prepend the current + * working directory to relative path names. + * Add the attachment annotation to the draft. + */ + + if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { + while (fgets(shell, sizeof (shell), f) != (char *)0) { + *(strchr(shell, '\n')) = '\0'; + + if (*shell == '/') + (void)annotate(drft, attach, shell, 1, 0, -2, 1); + else { + (void)sprintf(file, "%s/%s", cwd, shell); + (void)annotate(drft, attach, file, 1, 0, -2, 1); + } + } + + pclose(f); + } else { + advise("popen", "could not get file from shell"); + } + + break; + + case DETACHCMDSW: + /* + * Detach files from current draft. + */ + + if (attach == (char *)0) { + advise((char *)0, "can't detach because no header field name was given."); + break; + } + + /* + * Scan the arguments for a -n. Mixed file + * names and numbers aren't allowed, so this + * catches a -n anywhere in the argument list. + */ + + for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) { + if (strcmp(*arguments, "-n") == 0) { + n = 1; + break; + } + } + + /* + * A -n was found so interpret the arguments as + * attachment numbers. Decrement any remaining + * argument number that is greater than the one + * just processed after processing each one so + * that the numbering stays correct. + */ + + if (n == 1) { + for (arguments = argp + 1; *arguments != (char *)0; arguments++) { + if (strcmp(*arguments, "-n") == 0) + continue; + + if (**arguments != '\0') { + n = atoi(*arguments); + (void)annotate(drft, attach, (char *)0, 1, 0, n, 1); + + for (argp = arguments + 1; *argp != (char *)0; argp++) { + if (atoi(*argp) > n) { + if (atoi(*argp) == 1) + *argp = ""; + else + (void)sprintf(*argp, "%d", atoi(*argp) - 1); + } + } + } + } + } + + /* + * The arguments are interpreted as file names. + * Run them through the user's shell for wildcard + * expansion and other goodies. Do this from + * the current working directory if the argument + * is not an absolute path name (does not begin + * with a /). + * + * We feed all the file names to the shell at + * once, otherwise you can't provide a file name + * with a space in it. + */ + writelscmd(buf, sizeof(buf), argp); + if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) { + while (fgets(shell, sizeof (shell), f) != (char *)0) { + *(strchr(shell, '\n')) = '\0'; + (void)annotate(drft, attach, shell, 1, 0, 0, 1); + } + pclose(f); + } else { + advise("popen", "could not get file from shell"); + } + + break; + + default: + /* Unknown command */ + advise (NULL, "say what?"); + break; + } } - } - /*NOTREACHED*/ + /*NOTREACHED*/ } -/* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */ +/* + * Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; + * trailcmd". + */ static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp) { - char *cp; - /* Note that we do not quote -- the argp from the user - * is assumed to be quoted as they desire. (We can't treat - * it as pure literal as that would prevent them using ~, - * wildcards, etc.) The buffer produced by this function - * should be given to popen_in_dir() or system_in_dir() so - * that the current working directory is set correctly. - */ - int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd); - /* NB that some snprintf() return -1 on overflow rather than the - * new C99 mandated 'number of chars that would have been written' - */ - /* length checks here and inside the loop allow for the - * trailing ';', trailcmd, '"' and NUL - */ - int trailln = strlen(trailcmd) + 3; - if (ln < 0 || ln + trailln > bufsz) - adios((char *)0, "arguments too long"); - - cp = buf + ln; - - while (*++argp != (char *)0) { - ln = strlen(*argp); - /* +1 for leading space */ - if (ln + trailln + 1 > bufsz - (cp-buf)) - adios((char *)0, "arguments too long"); - *cp++ = ' '; - memcpy(cp, *argp, ln+1); - cp += ln; - } - if (*trailcmd) { - *cp++ = ';'; - strcpy(cp, trailcmd); - cp += trailln - 3; - } - *cp++ = '"'; - *cp = 0; + char *cp; + /* Note that we do not quote -- the argp from the user + * is assumed to be quoted as they desire. (We can't treat + * it as pure literal as that would prevent them using ~, + * wildcards, etc.) The buffer produced by this function + * should be given to popen_in_dir() or system_in_dir() so + * that the current working directory is set correctly. + */ + int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd); + /* NB that some snprintf() return -1 on overflow rather than the + * new C99 mandated 'number of chars that would have been written' + */ + /* length checks here and inside the loop allow for the + * trailing ';', trailcmd, '"' and NUL + */ + int trailln = strlen(trailcmd) + 3; + if (ln < 0 || ln + trailln > bufsz) + adios((char *)0, "arguments too long"); + + cp = buf + ln; + + while (*++argp != (char *)0) { + ln = strlen(*argp); + /* +1 for leading space */ + if (ln + trailln + 1 > bufsz - (cp-buf)) + adios((char *)0, "arguments too long"); + *cp++ = ' '; + memcpy(cp, *argp, ln+1); + cp += ln; + } + if (*trailcmd) { + *cp++ = ';'; + strcpy(cp, trailcmd); + cp += trailln - 3; + } + *cp++ = '"'; + *cp = 0; } /* @@ -581,7 +592,7 @@ writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp) static void writelscmd(char *buf, int bufsz, char **argp) { - writesomecmd(buf, bufsz, "ls", "", argp); + writesomecmd(buf, bufsz, "ls", "", argp); } /* Like system(), but run the command in directory dir. @@ -590,32 +601,32 @@ writelscmd(char *buf, int bufsz, char **argp) static int system_in_dir(const char *dir, const char *cmd) { - char olddir[BUFSIZ]; - int r; - if (getcwd(olddir, sizeof(olddir)) == 0) - adios("getcwd", "could not get working directory"); - if (chdir(dir) != 0) - adios("chdir", "could not change working directory"); - r = system(cmd); - if (chdir(olddir) != 0) - adios("chdir", "could not change working directory"); - return r; + char olddir[BUFSIZ]; + int r; + if (getcwd(olddir, sizeof(olddir)) == 0) + adios("getcwd", "could not get working directory"); + if (chdir(dir) != 0) + adios("chdir", "could not change working directory"); + r = system(cmd); + if (chdir(olddir) != 0) + adios("chdir", "could not change working directory"); + return r; } /* ditto for popen() */ static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type) { - char olddir[BUFSIZ]; - FILE *f; - if (getcwd(olddir, sizeof(olddir)) == 0) - adios("getcwd", "could not get working directory"); - if (chdir(dir) != 0) - adios("chdir", "could not change working directory"); - f = popen(cmd, type); - if (chdir(olddir) != 0) - adios("chdir", "could not change working directory"); - return f; + char olddir[BUFSIZ]; + FILE *f; + if (getcwd(olddir, sizeof(olddir)) == 0) + adios("getcwd", "could not get working directory"); + if (chdir(dir) != 0) + adios("chdir", "could not change working directory"); + f = popen(cmd, type); + if (chdir(olddir) != 0) + adios("chdir", "could not change working directory"); + return f; } @@ -623,167 +634,167 @@ popen_in_dir(const char *dir, const char *cmd, const char *type) * EDIT */ -static int reedit = 0; /* have we been here before? */ -static char *edsave = NULL; /* the editor we used previously */ +static int reedit = 0; /* have we been here before? */ +static char *edsave = NULL; /* the editor we used previously */ static int editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, - char *altmsg, char *cwd, int save_editor) + char *altmsg, char *cwd, int save_editor) { - int pid, status, vecp; - char altpath[BUFSIZ], linkpath[BUFSIZ]; - char *cp, *vec[MAXARGS]; - struct stat st; + int pid, status, vecp; + char altpath[BUFSIZ], linkpath[BUFSIZ]; + char *cp, *vec[MAXARGS]; + struct stat st; #ifdef HAVE_LSTAT - int slinked = 0; + int slinked = 0; #if 0 - int oumask; /* PJS: for setting permissions on symlinks. */ + int oumask; /* PJS: for setting permissions on symlinks. */ #endif #endif /* HAVE_LSTAT */ - /* Was there a previous edit session? */ - if (reedit) { - if (!*ed) { /* no explicit editor */ - *ed = edsave; /* so use the previous one */ - if ((cp = r1bindex (*ed, '/')) == NULL) - cp = *ed; - - /* unless we've specified it via "editor-next" */ - cp = concat (cp, "-next", NULL); - if ((cp = context_find (cp)) != NULL) - *ed = cp; + /* Was there a previous edit session? */ + if (reedit) { + if (!*ed) { /* no explicit editor */ + *ed = edsave; /* so use the previous one */ + if ((cp = r1bindex (*ed, '/')) == NULL) + cp = *ed; + + /* unless we've specified it via "editor-next" */ + cp = concat (cp, "-next", NULL); + if ((cp = context_find (cp)) != NULL) + *ed = cp; + } + } else { + /* set initial editor */ + if (*ed == NULL && (*ed = context_find ("editor")) == NULL) + *ed = defaulteditor; + } + + if (altmsg) { + if (mp == NULL || *altmsg == '/' || cwd == NULL) + strncpy (altpath, altmsg, sizeof(altpath)); + else + snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg); + if (cwd == NULL) + strncpy (linkpath, altmsglink, sizeof(linkpath)); + else + snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, altmsglink); } - } else { - /* set initial editor */ - if (*ed == NULL && (*ed = context_find ("editor")) == NULL) - *ed = defaulteditor; - } - - if (altmsg) { - if (mp == NULL || *altmsg == '/' || cwd == NULL) - strncpy (altpath, altmsg, sizeof(altpath)); - else - snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg); - if (cwd == NULL) - strncpy (linkpath, altmsglink, sizeof(linkpath)); - else - snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, altmsglink); - } - - if (altmsg) { - unlink (linkpath); + + if (altmsg) { + unlink (linkpath); #ifdef HAVE_LSTAT - if (link (altpath, linkpath) == NOTOK) { + if (link (altpath, linkpath) == NOTOK) { #if 0 - /* I don't think permission on symlinks matters /JLR */ - oumask = umask(0044); /* PJS: else symlinks are world 'r' */ + /* I don't think permission on symlinks matters /JLR */ + oumask = umask(0044); /* PJS: else symlinks are world 'r' */ #endif - symlink (altpath, linkpath); + symlink (altpath, linkpath); #if 0 - umask(oumask); /* PJS: else symlinks are world 'r' */ + umask(oumask); /* PJS: else symlinks are world 'r' */ #endif - slinked = 1; - } else { - slinked = 0; - } + slinked = 1; + } else { + slinked = 0; + } #else /* not HAVE_LSTAT */ - link (altpath, linkpath); + link (altpath, linkpath); #endif /* not HAVE_LSTAT */ - } - - context_save (); /* save the context file */ - fflush (stdout); - - switch (pid = vfork ()) { - case NOTOK: - advise ("fork", "unable to"); - status = NOTOK; - break; - - case OK: - if (cwd) - chdir (cwd); - if (altmsg) { - if (mp) - m_putenv ("mhfolder", mp->foldpath); - m_putenv ("editalt", altpath); - } - - vecp = 0; - vec[vecp++] = r1bindex (*ed, '/'); - if (arg) - while (*arg) - vec[vecp++] = *arg++; - vec[vecp++] = file; - vec[vecp] = NULL; - - execvp (*ed, vec); - fprintf (stderr, "unable to exec "); - perror (*ed); - _exit (-1); - - default: - if ((status = pidwait (pid, NOTOK))) { + } + + context_save (); /* save the context file */ + fflush (stdout); + + switch (pid = vfork ()) { + case NOTOK: + advise ("fork", "unable to"); + status = NOTOK; + break; + + case OK: + if (cwd) + chdir (cwd); + if (altmsg) { + if (mp) + m_putenv ("mhfolder", mp->foldpath); + m_putenv ("editalt", altpath); + } + + vecp = 0; + vec[vecp++] = r1bindex (*ed, '/'); + if (arg) + while (*arg) + vec[vecp++] = *arg++; + vec[vecp++] = file; + vec[vecp] = NULL; + + execvp (*ed, vec); + fprintf (stderr, "unable to exec "); + perror (*ed); + _exit (-1); + + default: + if ((status = pidwait (pid, NOTOK))) { #ifdef ATTVIBUG - if ((cp = r1bindex (*ed, '/')) - && strcmp (cp, "vi") == 0 - && (status & 0x00ff) == 0) - status = 0; - else { + if ((cp = r1bindex (*ed, '/')) + && strcmp (cp, "vi") == 0 + && (status & 0x00ff) == 0) + status = 0; + else { #endif - if (((status & 0xff00) != 0xff00) - && (!reedit || (status & 0x00ff))) { - if (!use && (status & 0xff00) && - (rename (file, cp = m_backup (file)) != NOTOK)) { - advise (NULL, "problems with edit--draft left in %s", cp); - } else { - advise (NULL, "problems with edit--%s preserved", file); - } - } - status = -2; /* maybe "reedit ? -2 : -1"? */ - break; + if (((status & 0xff00) != 0xff00) + && (!reedit || (status & 0x00ff))) { + if (!use && (status & 0xff00) && + (rename (file, cp = m_backup (file)) != NOTOK)) { + advise (NULL, "problems with edit--draft left in %s", cp); + } else { + advise (NULL, "problems with edit--%s preserved", file); + } + } + status = -2; /* maybe "reedit ? -2 : -1"? */ + break; #ifdef ATTVIBUG - } + } #endif - } + } - reedit++; + reedit++; #ifdef HAVE_LSTAT - if (altmsg - && mp - && !is_readonly(mp) - && (slinked - ? lstat (linkpath, &st) != NOTOK - && S_ISREG(st.st_mode) - && copyf (linkpath, altpath) == NOTOK - : stat (linkpath, &st) != NOTOK - && st.st_nlink == 1 - && (unlink (altpath) == NOTOK - || link (linkpath, altpath) == NOTOK))) - advise (linkpath, "unable to update %s from", altmsg); + if (altmsg + && mp + && !is_readonly(mp) + && (slinked + ? lstat (linkpath, &st) != NOTOK + && S_ISREG(st.st_mode) + && copyf (linkpath, altpath) == NOTOK + : stat (linkpath, &st) != NOTOK + && st.st_nlink == 1 + && (unlink (altpath) == NOTOK + || link (linkpath, altpath) == NOTOK))) + advise (linkpath, "unable to update %s from", altmsg); #else /* HAVE_LSTAT */ - if (altmsg - && mp - && !is_readonly(mp) - && stat (linkpath, &st) != NOTOK - && st.st_nlink == 1 - && (unlink (altpath) == NOTOK - || link (linkpath, altpath) == NOTOK)) - advise (linkpath, "unable to update %s from", altmsg); + if (altmsg + && mp + && !is_readonly(mp) + && stat (linkpath, &st) != NOTOK + && st.st_nlink == 1 + && (unlink (altpath) == NOTOK + || link (linkpath, altpath) == NOTOK)) + advise (linkpath, "unable to update %s from", altmsg); #endif /* HAVE_LSTAT */ - } + } - /* normally, we remember which editor we used */ - if (save_editor) - edsave = getcpy (*ed); + /* normally, we remember which editor we used */ + if (save_editor) + edsave = getcpy (*ed); - *ed = NULL; - if (altmsg) - unlink (linkpath); + *ed = NULL; + if (altmsg) + unlink (linkpath); - return status; + return status; } @@ -791,27 +802,27 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp, static int copyf (char *ifile, char *ofile) { - int i, in, out; - char buffer[BUFSIZ]; - - if ((in = open (ifile, O_RDONLY)) == NOTOK) - return NOTOK; - if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) { - admonish (ofile, "unable to open and truncate"); - close (in); - return NOTOK; - } - - while ((i = read (in, buffer, sizeof(buffer))) > OK) - if (write (out, buffer, i) != i) { - advise (ofile, "may have damaged"); - i = NOTOK; - break; + int i, in, out; + char buffer[BUFSIZ]; + + if ((in = open (ifile, O_RDONLY)) == NOTOK) + return NOTOK; + if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) { + admonish (ofile, "unable to open and truncate"); + close (in); + return NOTOK; } - close (in); - close (out); - return i; + while ((i = read (in, buffer, sizeof(buffer))) > OK) + if (write (out, buffer, i) != i) { + advise (ofile, "may have damaged"); + i = NOTOK; + break; + } + + close (in); + close (out); + return i; } #endif /* HAVE_LSTAT */ @@ -823,65 +834,65 @@ copyf (char *ifile, char *ofile) static int sendfile (char **arg, char *file, int pushsw) { - pid_t child_id; - int i, vecp; - char *cp, *sp, *vec[MAXARGS]; - - /* Translate MIME composition file, if necessary */ - if ((cp = context_find ("automimeproc")) - && (!strcmp (cp, "1")) - && !getenv ("NOMHNPROC") - && check_draft (file) - && (buildfile (NULL, file) == NOTOK)) - return 0; - - /* For backwards compatibility */ - if ((cp = context_find ("automhnproc")) - && !getenv ("NOMHNPROC") - && check_draft (file) - && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0))) - return 0; - - /* - * If the sendproc is the nmh command `send', then we call - * those routines directly rather than exec'ing the command. - */ - if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) { - cp = invo_name; - sendit (invo_name = sp, arg, file, pushsw); - invo_name = cp; - return 1; - } - - context_save (); /* save the context file */ - fflush (stdout); - - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - advise (NULL, "unable to fork, so sending directly..."); - case OK: - vecp = 0; - vec[vecp++] = invo_name; - if (pushsw) - vec[vecp++] = "-push"; - if (arg) - while (*arg) - vec[vecp++] = *arg++; - vec[vecp++] = file; - vec[vecp] = NULL; - - execvp (sendproc, vec); - fprintf (stderr, "unable to exec "); - perror (sendproc); - _exit (-1); - - default: - if (pidwait(child_id, OK) == 0) - done (0); - return 1; - } + pid_t child_id; + int i, vecp; + char *cp, *sp, *vec[MAXARGS]; + + /* Translate MIME composition file, if necessary */ + if ((cp = context_find ("automimeproc")) + && (!strcmp (cp, "1")) + && !getenv ("NOMHNPROC") + && check_draft (file) + && (buildfile (NULL, file) == NOTOK)) + return 0; + + /* For backwards compatibility */ + if ((cp = context_find ("automhnproc")) + && !getenv ("NOMHNPROC") + && check_draft (file) + && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0))) + return 0; + + /* + * If the sendproc is the nmh command `send', then we call + * those routines directly rather than exec'ing the command. + */ + if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) { + cp = invo_name; + sendit (invo_name = sp, arg, file, pushsw); + invo_name = cp; + return 1; + } + + context_save (); /* save the context file */ + fflush (stdout); + + for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + advise (NULL, "unable to fork, so sending directly..."); + case OK: + vecp = 0; + vec[vecp++] = invo_name; + if (pushsw) + vec[vecp++] = "-push"; + if (arg) + while (*arg) + vec[vecp++] = *arg++; + vec[vecp++] = file; + vec[vecp] = NULL; + + execvp (sendproc, vec); + fprintf (stderr, "unable to exec "); + perror (sendproc); + _exit (-1); + + default: + if (pidwait(child_id, OK) == 0) + done (0); + return 1; + } } @@ -892,36 +903,36 @@ sendfile (char **arg, char *file, int pushsw) static int buildfile (char **argp, char *file) { - int i; - char **args, *ed; - - ed = buildmimeproc; - - /* allocate space for arguments */ - i = 0; - if (argp) { - while (argp[i]) - i++; - } - args = (char **) mh_xmalloc((i + 2) * sizeof(char *)); - - /* - * For backward compatibility, we need to add -build - * if we are using mhn as buildmimeproc - */ - i = 0; - if (strcmp (r1bindex (ed, '/'), "mhn") == 0) - args[i++] = "-build"; - - /* copy any other arguments */ - while (argp && *argp) - args[i++] = *argp++; - args[i] = NULL; - - i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0); - free (args); - - return (i ? NOTOK : OK); + int i; + char **args, *ed; + + ed = buildmimeproc; + + /* allocate space for arguments */ + i = 0; + if (argp) { + while (argp[i]) + i++; + } + args = (char **) mh_xmalloc((i + 2) * sizeof(char *)); + + /* + * For backward compatibility, we need to add -build + * if we are using mhn as buildmimeproc + */ + i = 0; + if (strcmp (r1bindex (ed, '/'), "mhn") == 0) + args[i++] = "-build"; + + /* copy any other arguments */ + while (argp && *argp) + args[i++] = *argp++; + args[i] = NULL; + + i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0); + free (args); + + return (i ? NOTOK : OK); } @@ -932,135 +943,135 @@ buildfile (char **argp, char *file) static int check_draft (char *msgnam) { - int state; - char buf[BUFSIZ], name[NAMESZ]; - FILE *fp; - - if ((fp = fopen (msgnam, "r")) == NULL) - return 0; - for (state = FLD;;) - switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { - case FLD: - case FLDPLUS: - case FLDEOF: - /* - * If draft already contains any of the - * Content-XXX fields, then assume it already - * been converted. - */ - if (uprf (name, XXX_FIELD_PRF)) { - fclose (fp); - return 0; - } - while (state == FLDPLUS) - state = m_getfld (state, name, buf, sizeof(buf), fp); - break; - - case BODY: - do { - char *bp; - - for (bp = buf; *bp; bp++) - if (*bp != ' ' && *bp != '\t' && *bp != '\n') { - fclose (fp); - return 1; - } + int state; + char buf[BUFSIZ], name[NAMESZ]; + FILE *fp; - state = m_getfld (state, name, buf, sizeof(buf), fp); - } while (state == BODY); - /* and fall... */ - - default: - fclose (fp); + if ((fp = fopen (msgnam, "r")) == NULL) return 0; - } + for (state = FLD;;) + switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { + case FLD: + case FLDPLUS: + case FLDEOF: + /* + * If draft already contains any of the + * Content-XXX fields, then assume it already + * been converted. + */ + if (uprf (name, XXX_FIELD_PRF)) { + fclose (fp); + return 0; + } + while (state == FLDPLUS) + state = m_getfld (state, name, buf, sizeof(buf), fp); + break; + + case BODY: + do { + char *bp; + + for (bp = buf; *bp; bp++) + if (*bp != ' ' && *bp != '\t' && *bp != '\n') { + fclose (fp); + return 1; + } + + state = m_getfld (state, name, buf, sizeof(buf), fp); + } while (state == BODY); + /* and fall... */ + + default: + fclose (fp); + return 0; + } } static struct swit sendswitches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define DEBUGSW 1 - { "debug", -5 }, -#define FILTSW 2 - { "filter filterfile", 0 }, -#define NFILTSW 3 - { "nofilter", 0 }, -#define FRMTSW 4 - { "format", 0 }, -#define NFRMTSW 5 - { "noformat", 0 }, -#define FORWSW 6 - { "forward", 0 }, -#define NFORWSW 7 - { "noforward", 0 }, -#define MIMESW 8 - { "mime", 0 }, -#define NMIMESW 9 - { "nomime", 0 }, -#define MSGDSW 10 - { "msgid", 0 }, -#define NMSGDSW 11 - { "nomsgid", 0 }, -#define SPSHSW 12 - { "push", 0 }, -#define NSPSHSW 13 - { "nopush", 0 }, -#define SPLITSW 14 - { "split seconds", 0 }, -#define UNIQSW 15 - { "unique", -6 }, -#define NUNIQSW 16 - { "nounique", -8 }, -#define VERBSW 17 - { "verbose", 0 }, -#define NVERBSW 18 - { "noverbose", 0 }, -#define WATCSW 19 - { "watch", 0 }, -#define NWATCSW 20 - { "nowatch", 0 }, -#define WIDTHSW 21 - { "width columns", 0 }, -#define SVERSIONSW 22 - { "version", 0 }, -#define SHELPSW 23 - { "help", 0 }, -#define BITSTUFFSW 24 - { "dashstuffing", -12 }, -#define NBITSTUFFSW 25 - { "nodashstuffing", -14 }, -#define MAILSW 26 - { "mail", -4 }, -#define SAMLSW 27 - { "saml", -4 }, -#define SSNDSW 28 - { "send", -4 }, -#define SOMLSW 29 - { "soml", -4 }, -#define CLIESW 30 - { "client host", -6 }, -#define SERVSW 31 - { "server host", 6 }, -#define SNOOPSW 32 - { "snoop", -5 }, -#define SDRFSW 33 - { "draftfolder +folder", -6 }, -#define SDRMSW 34 - { "draftmessage msg", -6 }, -#define SNDRFSW 35 - { "nodraftfolder", -3 }, -#define SNDATTACHSW 39 - { "attach file", 6 }, +#define ALIASW 0 + { "alias aliasfile", 0 }, +#define DEBUGSW 1 + { "debug", -5 }, +#define FILTSW 2 + { "filter filterfile", 0 }, +#define NFILTSW 3 + { "nofilter", 0 }, +#define FRMTSW 4 + { "format", 0 }, +#define NFRMTSW 5 + { "noformat", 0 }, +#define FORWSW 6 + { "forward", 0 }, +#define NFORWSW 7 + { "noforward", 0 }, +#define MIMESW 8 + { "mime", 0 }, +#define NMIMESW 9 + { "nomime", 0 }, +#define MSGDSW 10 + { "msgid", 0 }, +#define NMSGDSW 11 + { "nomsgid", 0 }, +#define SPSHSW 12 + { "push", 0 }, +#define NSPSHSW 13 + { "nopush", 0 }, +#define SPLITSW 14 + { "split seconds", 0 }, +#define UNIQSW 15 + { "unique", -6 }, +#define NUNIQSW 16 + { "nounique", -8 }, +#define VERBSW 17 + { "verbose", 0 }, +#define NVERBSW 18 + { "noverbose", 0 }, +#define WATCSW 19 + { "watch", 0 }, +#define NWATCSW 20 + { "nowatch", 0 }, +#define WIDTHSW 21 + { "width columns", 0 }, +#define SVERSIONSW 22 + { "version", 0 }, +#define SHELPSW 23 + { "help", 0 }, +#define BITSTUFFSW 24 + { "dashstuffing", -12 }, +#define NBITSTUFFSW 25 + { "nodashstuffing", -14 }, +#define MAILSW 26 + { "mail", -4 }, +#define SAMLSW 27 + { "saml", -4 }, +#define SSNDSW 28 + { "send", -4 }, +#define SOMLSW 29 + { "soml", -4 }, +#define CLIESW 30 + { "client host", -6 }, +#define SERVSW 31 + { "server host", 6 }, +#define SNOOPSW 32 + { "snoop", -5 }, +#define SDRFSW 33 + { "draftfolder +folder", -6 }, +#define SDRMSW 34 + { "draftmessage msg", -6 }, +#define SNDRFSW 35 + { "nodraftfolder", -3 }, +#define SNDATTACHSW 39 + { "attach file", 6 }, #define SNDATTACHFORMAT 40 - { "attachformat", 7 }, -#define PORTSW 41 - { "port server-port-name/number", 4 }, - { NULL, 0 } + { "attachformat", 7 }, +#define PORTSW 41 + { "port server-port-name/number", 4 }, + { NULL, 0 } }; -extern int debugsw; /* from sendsbr.c */ +extern int debugsw; /* from sendsbr.c */ extern int forwsw; extern int inplace; extern int pushsw; @@ -1068,7 +1079,7 @@ extern int splitsw; extern int unique; extern int verbsw; -extern char *altmsg; /* .. */ +extern char *altmsg; /* .. */ extern char *annotext; extern char *distfile; @@ -1076,253 +1087,253 @@ extern char *distfile; static void sendit (char *sp, char **arg, char *file, int pushed) { - int vecp, n = 1; - char *cp, buf[BUFSIZ], **argp; - char **arguments, *vec[MAXARGS]; - struct stat st; - char *attach = (char *)0; /* attachment header field name */ - int attachformat = 0; /* mhbuild format specifier for - attachments */ - -#ifndef lint - int distsw = 0; + int vecp, n = 1; + char *cp, buf[BUFSIZ], **argp; + char **arguments, *vec[MAXARGS]; + struct stat st; + char *attach = (char *)0; /* attachment header field name */ + int attachformat = 0; /* mhbuild format specifier for + attachments */ + +#ifndef lint + int distsw = 0; #endif #ifdef UCI - FILE *fp; + FILE *fp; #endif - /* - * Make sure these are defined. In particular, we need - * vec[1] to be NULL, in case "arg" is NULL below. It - * doesn't matter what is the value of vec[0], but we - * set it to NULL, to help catch "off-by-one" errors. - */ - vec[0] = NULL; - vec[1] = NULL; - - /* - * Temporarily copy arg to vec, since the brkstring() call in - * getarguments() will wipe it out before it is merged in. - * Also, we skip the first element of vec, since getarguments() - * skips it. Then we count the number of arguments - * copied. The value of "n" will be one greater than - * this in order to simulate the standard argc/argv. - */ - if (arg) { - char **bp; - - copyip (arg, vec+1, MAXARGS-1); - bp = vec+1; - while (*bp++) - n++; - } - - /* - * Merge any arguments from command line (now in vec) - * and arguments from profile. - */ - arguments = getarguments (sp, n, vec, 1); - argp = arguments; - - debugsw = 0; - forwsw = 1; - inplace = 1; - unique = 0; - - altmsg = NULL; - annotext = NULL; - distfile = NULL; - - vecp = 1; /* we'll get the zero'th element later */ - vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, sendswitches)) { - case AMBIGSW: - ambigsw (cp, sendswitches); - return; - case UNKWNSW: - advise (NULL, "-%s unknown\n", cp); - return; - - case SHELPSW: - snprintf (buf, sizeof(buf), "%s [switches]", sp); - print_help (buf, sendswitches, 1); - return; - case SVERSIONSW: - print_version (invo_name); - return; - - case SPSHSW: - pushed++; - continue; - case NSPSHSW: - pushed = 0; - continue; - - case SPLITSW: - if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) { - advise (NULL, "missing argument to %s", argp[-2]); - return; - } - continue; - - case UNIQSW: - unique++; - continue; - case NUNIQSW: - unique = 0; - continue; - case FORWSW: - forwsw++; - continue; - case NFORWSW: - forwsw = 0; - continue; - - case VERBSW: - verbsw++; - vec[vecp++] = --cp; - continue; - case NVERBSW: - verbsw = 0; - vec[vecp++] = --cp; - continue; - - case DEBUGSW: - debugsw++; /* fall */ - case NFILTSW: - case FRMTSW: - case NFRMTSW: - case BITSTUFFSW: - case NBITSTUFFSW: - case MIMESW: - case NMIMESW: - case MSGDSW: - case NMSGDSW: - case WATCSW: - case NWATCSW: - case MAILSW: - case SAMLSW: - case SSNDSW: - case SOMLSW: - case SNOOPSW: - vec[vecp++] = --cp; - continue; - - case ALIASW: - case FILTSW: - case WIDTHSW: - case CLIESW: - case SERVSW: - case PORTSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') { - advise (NULL, "missing argument to %s", argp[-2]); - return; - } - vec[vecp++] = cp; - continue; - - case SDRFSW: - case SDRMSW: - if (!(cp = *argp++) || *cp == '-') { - advise (NULL, "missing argument to %s", argp[-2]); - return; - } - case SNDRFSW: - continue; - - case SNDATTACHSW: - if (!(attach = *argp++) || *attach == '-') { - advise (NULL, "missing argument to %s", argp[-2]); - return; - } - continue; - - case SNDATTACHFORMAT: - if (! *argp || **argp == '-') - adios (NULL, "missing argument to %s", argp[-1]); - else { - attachformat = atoi (*argp); - if (attachformat < 0 || - attachformat > ATTACHFORMATS - 1) { - advise (NULL, "unsupported attachformat %d", - attachformat); - continue; + /* + * Make sure these are defined. In particular, we need + * vec[1] to be NULL, in case "arg" is NULL below. It + * doesn't matter what is the value of vec[0], but we + * set it to NULL, to help catch "off-by-one" errors. + */ + vec[0] = NULL; + vec[1] = NULL; + + /* + * Temporarily copy arg to vec, since the brkstring() call in + * getarguments() will wipe it out before it is merged in. + * Also, we skip the first element of vec, since getarguments() + * skips it. Then we count the number of arguments + * copied. The value of "n" will be one greater than + * this in order to simulate the standard argc/argv. + */ + if (arg) { + char **bp; + + copyip (arg, vec+1, MAXARGS-1); + bp = vec+1; + while (*bp++) + n++; + } + + /* + * Merge any arguments from command line (now in vec) + * and arguments from profile. + */ + arguments = getarguments (sp, n, vec, 1); + argp = arguments; + + debugsw = 0; + forwsw = 1; + inplace = 1; + unique = 0; + + altmsg = NULL; + annotext = NULL; + distfile = NULL; + + vecp = 1; /* we'll get the zero'th element later */ + vec[vecp++] = "-library"; + vec[vecp++] = getcpy (m_maildir ("")); + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, sendswitches)) { + case AMBIGSW: + ambigsw (cp, sendswitches); + return; + case UNKWNSW: + advise (NULL, "-%s unknown\n", cp); + return; + + case SHELPSW: + snprintf (buf, sizeof(buf), "%s [switches]", sp); + print_help (buf, sendswitches, 1); + return; + case SVERSIONSW: + print_version (invo_name); + return; + + case SPSHSW: + pushed++; + continue; + case NSPSHSW: + pushed = 0; + continue; + + case SPLITSW: + if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) { + advise (NULL, "missing argument to %s", argp[-2]); + return; + } + continue; + + case UNIQSW: + unique++; + continue; + case NUNIQSW: + unique = 0; + continue; + case FORWSW: + forwsw++; + continue; + case NFORWSW: + forwsw = 0; + continue; + + case VERBSW: + verbsw++; + vec[vecp++] = --cp; + continue; + case NVERBSW: + verbsw = 0; + vec[vecp++] = --cp; + continue; + + case DEBUGSW: + debugsw++; /* fall */ + case NFILTSW: + case FRMTSW: + case NFRMTSW: + case BITSTUFFSW: + case NBITSTUFFSW: + case MIMESW: + case NMIMESW: + case MSGDSW: + case NMSGDSW: + case WATCSW: + case NWATCSW: + case MAILSW: + case SAMLSW: + case SSNDSW: + case SOMLSW: + case SNOOPSW: + vec[vecp++] = --cp; + continue; + + case ALIASW: + case FILTSW: + case WIDTHSW: + case CLIESW: + case SERVSW: + case PORTSW: + vec[vecp++] = --cp; + if (!(cp = *argp++) || *cp == '-') { + advise (NULL, "missing argument to %s", argp[-2]); + return; + } + vec[vecp++] = cp; + continue; + + case SDRFSW: + case SDRMSW: + if (!(cp = *argp++) || *cp == '-') { + advise (NULL, "missing argument to %s", argp[-2]); + return; + } + case SNDRFSW: + continue; + + case SNDATTACHSW: + if (!(attach = *argp++) || *attach == '-') { + advise (NULL, "missing argument to %s", argp[-2]); + return; + } + continue; + + case SNDATTACHFORMAT: + if (! *argp || **argp == '-') + adios (NULL, "missing argument to %s", argp[-1]); + else { + attachformat = atoi (*argp); + if (attachformat < 0 || + attachformat > ATTACHFORMATS - 1) { + advise (NULL, "unsupported attachformat %d", + attachformat); + continue; + } + } + ++argp; + continue; } - } - ++argp; - continue; - } + } + advise (NULL, "usage: %s [switches]", sp); + return; } - advise (NULL, "usage: %s [switches]", sp); - return; - } - - /* allow Aliasfile: profile entry */ - if ((cp = context_find ("Aliasfile"))) { - char **ap, *dp; - - dp = getcpy (cp); - for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) { - vec[vecp++] = "-alias"; - vec[vecp++] = *ap; + + /* allow Aliasfile: profile entry */ + if ((cp = context_find ("Aliasfile"))) { + char **ap, *dp; + + dp = getcpy (cp); + for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) { + vec[vecp++] = "-alias"; + vec[vecp++] = *ap; + } } - } - if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) - if ((cp = context_find ("signature")) && *cp) - m_putenv ("SIGNATURE", cp); + if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) + if ((cp = context_find ("signature")) && *cp) + m_putenv ("SIGNATURE", cp); #ifdef UCI - else { - snprintf (buf, sizeof(buf), "%s/.signature", mypath); - if ((fp = fopen (buf, "r")) != NULL - && fgets (buf, sizeof(buf), fp) != NULL) { - fclose (fp); - if (cp = strchr (buf, '\n')) - *cp = 0; - m_putenv ("SIGNATURE", buf); - } - } + else { + snprintf (buf, sizeof(buf), "%s/.signature", mypath); + if ((fp = fopen (buf, "r")) != NULL + && fgets (buf, sizeof(buf), fp) != NULL) { + fclose (fp); + if (cp = strchr (buf, '\n')) + *cp = 0; + m_putenv ("SIGNATURE", buf); + } + } #endif /* UCI */ - if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) - annotext = NULL; - if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0) - altmsg = NULL; - if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0)) - inplace = atoi (cp); + if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) + annotext = NULL; + if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0) + altmsg = NULL; + if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0)) + inplace = atoi (cp); - if ((cp = getenv ("mhdist")) - && *cp + if ((cp = getenv ("mhdist")) + && *cp #ifndef lint - && (distsw = atoi (cp)) + && (distsw = atoi (cp)) #endif /* not lint */ - && altmsg) { - vec[vecp++] = "-dist"; - distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL)); - if (link (altmsg, distfile) == NOTOK) - adios (distfile, "unable to link %s to", altmsg); - } else { - distfile = NULL; - } + && altmsg) { + vec[vecp++] = "-dist"; + distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL)); + if (link (altmsg, distfile) == NOTOK) + adios (distfile, "unable to link %s to", altmsg); + } else { + distfile = NULL; + } - if (altmsg == NULL || stat (altmsg, &st) == NOTOK) { - st.st_mtime = 0; - st.st_dev = 0; - st.st_ino = 0; - } - if ((pushsw = pushed)) - push (); + if (altmsg == NULL || stat (altmsg, &st) == NOTOK) { + st.st_mtime = 0; + st.st_dev = 0; + st.st_ino = 0; + } + if ((pushsw = pushed)) + push (); - vec[0] = r1bindex (postproc, '/'); - closefds (3); + vec[0] = r1bindex (postproc, '/'); + closefds (3); - if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK) - done (0); + if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK) + done (0); } /* @@ -1332,35 +1343,35 @@ sendit (char *sp, char **arg, char *file, int pushed) static int whomfile (char **arg, char *file) { - pid_t pid; - int vecp; - char *vec[MAXARGS]; - - context_save (); /* save the context file */ - fflush (stdout); - - switch (pid = vfork ()) { - case NOTOK: - advise ("fork", "unable to"); - return 1; - - case OK: - vecp = 0; - vec[vecp++] = r1bindex (whomproc, '/'); - vec[vecp++] = file; - if (arg) - while (*arg) - vec[vecp++] = *arg++; - vec[vecp] = NULL; - - execvp (whomproc, vec); - fprintf (stderr, "unable to exec "); - perror (whomproc); - _exit (-1); /* NOTREACHED */ - - default: - return (pidwait (pid, NOTOK) & 0377 ? 1 : 0); - } + pid_t pid; + int vecp; + char *vec[MAXARGS]; + + context_save (); /* save the context file */ + fflush (stdout); + + switch (pid = vfork ()) { + case NOTOK: + advise ("fork", "unable to"); + return 1; + + case OK: + vecp = 0; + vec[vecp++] = r1bindex (whomproc, '/'); + vec[vecp++] = file; + if (arg) + while (*arg) + vec[vecp++] = *arg++; + vec[vecp] = NULL; + + execvp (whomproc, vec); + fprintf (stderr, "unable to exec "); + perror (whomproc); + _exit (-1); /* NOTREACHED */ + + default: + return (pidwait (pid, NOTOK) & 0377 ? 1 : 0); + } } @@ -1371,8 +1382,8 @@ whomfile (char **arg, char *file) static int removefile (char *drft) { - if (unlink (drft) == NOTOK) - adios (drft, "unable to unlink"); + if (unlink (drft) == NOTOK) + adios (drft, "unable to unlink"); - return OK; + return OK; } diff --git a/uip/whom.c b/uip/whom.c index 1b1660f..b68e3ae 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -1,4 +1,3 @@ - /* * whom.c -- report to whom a message would be sent * @@ -12,183 +11,183 @@ #include static struct swit switches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define CHKSW 1 - { "check", 0 }, -#define NOCHKSW 2 - { "nocheck", 0 }, -#define DRAFTSW 3 - { "draft", 0 }, -#define DFOLDSW 4 - { "draftfolder +folder", 6 }, -#define DMSGSW 5 - { "draftmessage msg", 6 }, -#define NDFLDSW 6 - { "nodraftfolder", 0 }, -#define VERSIONSW 7 - { "version", 0 }, -#define HELPSW 8 - { "help", 0 }, -#define CLIESW 9 - { "client host", -6 }, -#define SERVSW 10 - { "server host", -6 }, -#define SNOOPSW 11 - { "snoop", -5 }, -#define PORTSW 15 - { "port server port name/number", 4 }, - { NULL, 0 } +#define ALIASW 0 + { "alias aliasfile", 0 }, +#define CHKSW 1 + { "check", 0 }, +#define NOCHKSW 2 + { "nocheck", 0 }, +#define DRAFTSW 3 + { "draft", 0 }, +#define DFOLDSW 4 + { "draftfolder +folder", 6 }, +#define DMSGSW 5 + { "draftmessage msg", 6 }, +#define NDFLDSW 6 + { "nodraftfolder", 0 }, +#define VERSIONSW 7 + { "version", 0 }, +#define HELPSW 8 + { "help", 0 }, +#define CLIESW 9 + { "client host", -6 }, +#define SERVSW 10 + { "server host", -6 }, +#define SNOOPSW 11 + { "snoop", -5 }, +#define PORTSW 15 + { "port server port name/number", 4 }, + { NULL, 0 } }; int main (int argc, char **argv) { - pid_t child_id; - int i, status, isdf = 0; - int distsw = 0, vecp = 0; - char *cp, *dfolder = NULL, *dmsg = NULL; - char *msg = NULL, **ap, **argp, backup[BUFSIZ]; - char buf[BUFSIZ], **arguments, *vec[MAXARGS]; + pid_t child_id; + int i, status, isdf = 0; + int distsw = 0, vecp = 0; + char *cp, *dfolder = NULL, *dmsg = NULL; + char *msg = NULL, **ap, **argp, backup[BUFSIZ]; + char buf[BUFSIZ], **arguments, *vec[MAXARGS]; #ifdef LOCALE - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - vec[vecp++] = invo_name; - vec[vecp++] = "-whom"; - vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case CHKSW: - case NOCHKSW: - case SNOOPSW: - vec[vecp++] = --cp; - continue; - - case DRAFTSW: - msg = draft; - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - - case ALIASW: - case CLIESW: - case SERVSW: - case PORTSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; - continue; - } + invo_name = r1bindex (argv[0], '/'); + + /* read user profile/context */ + context_read(); + + arguments = getarguments (invo_name, argc, argv, 1); + argp = arguments; + + vec[vecp++] = invo_name; + vec[vecp++] = "-whom"; + vec[vecp++] = "-library"; + vec[vecp++] = getcpy (m_maildir ("")); + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch (++cp, switches)) { + case AMBIGSW: + ambigsw (cp, switches); + done (1); + case UNKWNSW: + adios (NULL, "-%s unknown", cp); + + case HELPSW: + snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name); + print_help (buf, switches, 1); + done (1); + case VERSIONSW: + print_version(invo_name); + done (1); + + case CHKSW: + case NOCHKSW: + case SNOOPSW: + vec[vecp++] = --cp; + continue; + + case DRAFTSW: + msg = draft; + continue; + + case DFOLDSW: + if (dfolder) + adios (NULL, "only one draft folder at a time!"); + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, + *cp != '@' ? TFOLDER : TSUBCWF); + continue; + case DMSGSW: + if (dmsg) + adios (NULL, "only one draft message at a time!"); + if (!(dmsg = *argp++) || *dmsg == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + case NDFLDSW: + dfolder = NULL; + isdf = NOTOK; + continue; + + case ALIASW: + case CLIESW: + case SERVSW: + case PORTSW: + vec[vecp++] = --cp; + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + vec[vecp++] = cp; + continue; + } + } + if (msg) + adios (NULL, "only one draft at a time!"); + else + vec[vecp++] = msg = cp; + } + + /* allow Aliasfile: profile entry */ + if ((cp = context_find ("Aliasfile"))) { + char *dp = NULL; + + for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) { + vec[vecp++] = "-alias"; + vec[vecp++] = *ap; + } + } + + if (msg == NULL) { +#ifdef WHATNOW + if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0') +#endif /* WHATNOW */ + cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); + msg = vec[vecp++] = cp; } - if (msg) - adios (NULL, "only one draft at a time!"); - else - vec[vecp++] = msg = cp; - } - - /* allow Aliasfile: profile entry */ - if ((cp = context_find ("Aliasfile"))) { - char *dp = NULL; - - for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) { - vec[vecp++] = "-alias"; - vec[vecp++] = *ap; + if ((cp = getenv ("mhdist")) + && *cp + && (distsw = atoi (cp)) + && (cp = getenv ("mhaltmsg")) + && *cp) { + if (distout (msg, cp, backup) == NOTOK) + done (1); + vec[vecp++] = "-dist"; + distsw++; } - } - - if (msg == NULL) { -#ifdef WHATNOW - if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0') -#endif /* WHATNOW */ - cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); - msg = vec[vecp++] = cp; - } - if ((cp = getenv ("mhdist")) - && *cp - && (distsw = atoi (cp)) - && (cp = getenv ("mhaltmsg")) - && *cp) { - if (distout (msg, cp, backup) == NOTOK) - done (1); - vec[vecp++] = "-dist"; - distsw++; - } - vec[vecp] = NULL; - - closefds (3); - - if (distsw) { - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - } - - switch (distsw ? child_id : OK) { - case NOTOK: - advise (NULL, "unable to fork, so checking directly..."); - case OK: - execvp (postproc, vec); - fprintf (stderr, "unable to exec "); - perror (postproc); - _exit (-1); - - default: - SIGNAL (SIGHUP, SIG_IGN); - SIGNAL (SIGINT, SIG_IGN); - SIGNAL (SIGQUIT, SIG_IGN); - SIGNAL (SIGTERM, SIG_IGN); - - status = pidwait(child_id, OK); - - unlink (msg); - if (rename (backup, msg) == NOTOK) - adios (msg, "unable to rename %s to", backup); - done (status); - } - - return 0; /* dead code to satisfy the compiler */ + vec[vecp] = NULL; + + closefds (3); + + if (distsw) { + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + } + + switch (distsw ? child_id : OK) { + case NOTOK: + advise (NULL, "unable to fork, so checking directly..."); + case OK: + execvp (postproc, vec); + fprintf (stderr, "unable to exec "); + perror (postproc); + _exit (-1); + + default: + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); + + status = pidwait(child_id, OK); + + unlink (msg); + if (rename (backup, msg) == NOTOK) + adios (msg, "unable to rename %s to", backup); + done (status); + } + + return 0; /* dead code to satisfy the compiler */ } -- 1.7.10.4