📄 mhn.c
字号:
/* mhn.c - multi-media MH */#ifndef lintstatic char ident[] = "@(#)$Id: mhn.c,v 2.35 1993/10/26 22:17:44 jromine Exp $";#endif /* lint */#include "../h/mh.h"#include <ctype.h>#include <errno.h>#include <setjmp.h>#include <signal.h>#include <stdio.h>#include "../zotnet/mts.h"#include <sys/types.h>#include <sys/stat.h>#ifdef BSD42#include <sys/wait.h>#endif#ifdef LOCALE#include <locale.h>#endif/* */static struct swit switches[] = {#define AUTOSW 0 "auto", 0,#define NAUTOSW 1 "noauto", 0,#define CACHESW 2 "cache", 0,#define NCACHESW 3 "nocache", 0,#define CHECKSW 4 "check", 0,#define NCHECKSW 5 "nocheck", 0,#define DEBUGSW 6 "debug", -5, #define EBCDICSW 7 "ebcdicsafe", 0,#define NEBCDICSW 8 "noebcdicsafe", 0,#define FILESW 9 /* interface from show */ "file file", 0,#define FORMSW 10 "form formfile", 4,#define HEADSW 11 "headers", 0,#define NHEADSW 12 "noheaders", 0,#define LISTSW 13 "list", 0,#define NLISTSW 14 "nolist", 0,#define PARTSW 15 "part number", 0,#define PAUSESW 16 "pause", 0,#define NPAUSESW 17 "nopause", 0,#define RCACHESW 18 "rcache policy", 0,#define SIZESW 19 "realsize", 0,#define NSIZESW 20 "norealsize", 0,#define RFC934SW 21 "rfc934mode", 0,#define NRFC934SW 22 "norfc934mode", 0,#define SERIALSW 23 "serialonly", 0,#define NSERIALSW 24 "noserialonly", 0,#define SHOWSW 25 "show", 0,#define NSHOWSW 26 "noshow", 0,#define STORESW 27 "store", 0,#define NSTORESW 28 "nostore", 0,#define TYPESW 29 "type content", 0,#define VERBSW 30 "verbose", 0,#define NVERBSW 31 "noverbose", 0,#define WCACHESW 32 "wcache policy", 0, #define HELPSW 33 "help", 4,#define PROGSW 34 "moreproc program", -4,#define NPROGSW 35 "nomoreproc", -3,#define LENSW 36 "length lines", -4,#define WIDSW 37 "width columns", -4,#define VIAMSW 38 "viamail mailpath", -7,#define VIASSW 39 "viasubj subject", -7,#define VIAPSW 40 "viaparm arguments", -7,#define VIADSW 41 "viadesc text", -7,#define VIACSW 42 "viacmnt text", -7,#define VIAZSW 43 "viadelay seconds", -8,#define VIAFSW 44 "viafrom mailpath", -7, NULL, 0};/* */#define NPARTS 50#define NTYPES 20static struct swit caches[] = {#define CACHE_NEVER 0 "never", 0,#define CACHE_PRIVATE 1 "private", 0,#define CACHE_PUBLIC 2 "public", 0,#define CACHE_ASK 3 "ask", 0, NULL, 0};static int autosw = 0;static int cachesw = 0;static int checksw = 0; int debugsw = 0;static int ebcdicsw = 0;static char *formsw = NULLCP;static int headsw = 1;static int listsw = 0;static int nolist = 0;static int nomore = 0;static int npart = 0;static char *parts[NPARTS + 1];static int pausesw = 1;static char *progsw = NULLCP;static int rcachesw = CACHE_ASK;static int rfc934sw = 1;static int serialsw = 0;static int showsw = 0;static int sizesw = 1;static int storesw = 0;static int ntype = 0;static char *types[NTYPES + 1]; int verbosw = 0;static int wcachesw = CACHE_ASK;static int endian = 0;static char *mm_charset = NULL;static int xpid = 0;static int userrs = 0;static char *cache_public;static char *cache_private;static int cwdlen;static char *cwd;static char *dir;static char *errs = NULL;static char *tmp;extern int errno;#ifndef BSD44extern int sys_nerr;extern char *sys_errlist[];#endifoff_t lseek ();time_t time ();/* */#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"static void build_comp ();typedef struct CTinfo { char *ci_type; char *ci_subtype;#define NPARMS 10 char *ci_attrs[NPARMS + 2]; char *ci_values[NPARMS]; char *ci_comment; char *ci_magic;} CTInfo, *CI;#define NULLCI ((CI) 0)static int get_ctinfo ();static int get_comment ();typedef struct Content { char *c_partno; /* within multipart content */ char *c_vrsn; /* Body-Version: */ char *c_ctline; /* Content-Type: */ CTInfo c_ctinfo; int c_type; /* internal form */#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 int c_subtype; /* filled-in by c_ctinitfnx */ caddr_t c_ctparams; /* .. */ caddr_t c_ctextern; /* .. */ char *c_showproc; /* default, if not in profile */ char *c_termproc; /* for charset madness... */ char *c_storeproc; /* overrides profile entry, if any */ int (*c_ctinitfnx) (); /* parse content */ int (*c_ctlistfnx) (); /* list content */ int (*c_ctshowfnx) (); /* show content */ int (*c_ctstorefnx) (); /* store content */ int (*c_ctfreefnx) (); /* free content-specific structures */ char *c_celine; /* Content-Transfer-Encoding: */ int c_encoding; /* internal form */#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 */ caddr_t c_ceparams; /* filled-in by encoding initfnx */ int (*c_ceopenfnx) (); /* get a stream to decoded contents */ int (*c_ceclosefnx) (); /* release stream */ int (*c_celistfnx) (); /* list decoding info */ unsigned long (*c_cesizefnx) (); /* size of decoded contents */ int (*c_cefreefnx) (); /* free encoding-specific structures */ char *c_id; /* Content-ID: */ char *c_descr; /* Content-Description: */ int c_digested; /* Content-MD5: */ unsigned char c_digest[16]; /* .. */ FILE *c_fp; /* read contents (stream) */ char *c_file; /* read contents (file) */ int c_unlink; /* remove file when done? */ int c_umask; /* associated umask */ long c_begin; /* where content starts in file */ long c_end; /* .. ends */ int c_pid; /* process doing display */ char *c_storage; /* write contents (file) */ int c_rfc934; /* rfc934 compatibility */} Content, *CT;#define NULLCT ((CT) 0)static CT get_content ();static int list_content (), show_content (), store_content ();static int cache_content ();static int user_content (), compose_content (), output_content ();static void free_content (), flush_errors (), set_id ();#if defined(__STDC__) && defined(VSPRINTF)static void content_error (char *, register CT, char *, ...);#elsestatic void content_error ();#endifstatic int init_encoding (), type_ok (), copy_some_headers (), set_endian ();static int make_intermediates ();static int find_cache (), find_cache_aux (), find_cache_aux2 ();static int write7Bit (), writeQuoted (), writeBase64 (), writeBase64aux ();static int writeDigest (), readDigest ();static int via_mail (), via_post (), pidcheck ();static CT *cts = NULL;#define quitser pipeserstatic TYPESIG pipeser ();static char *fgetstr ();/* *//* ARGSUSED */main (argc, argv)int argc;char **argv;{ int f6 = 0, msgp = 0, msgnum, *icachesw; char *cp, *f1 = NULL, *f2 = NULL, *f3 = NULL, *f4 = NULL, *f5 = NULL, *f7 = NULL, *file = NULL, *folder = NULL, *maildir, buf[100], **ap, **argp, *arguments[MAXARGS], *msgs[MAXARGS]; struct msgs *mp; register CT ct, *ctp; FILE *fp;#ifdef LOCALE setlocale(LC_ALL, "");#endif invo_name = r1bindex (argv[0], '/'); if (argv[1] && uprf (argv[1], "-via")) m_foil (NULLCP); if ((cp = m_find (invo_name)) != NULL) { ap = brkstring (cp = getcpy (cp), " ", "\n"); ap = copyip (ap, arguments); } else ap = arguments; (void) copyip (argv + 1, ap); argp = arguments;/* */ while (cp = *argp++) { if (*cp == '-') switch (smatch (++cp, switches)) { case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: adios (NULLCP, "-%s unknown", cp); case HELPSW: (void) sprintf (buf, "%s [+folder] [msgs] [switches]", invo_name); help (buf, switches); done (1); case AUTOSW: autosw++; continue; case NAUTOSW: autosw = 0; continue; case CACHESW: cachesw++; continue; case NCACHESW: cachesw = 0; continue; case RCACHESW: icachesw = &rcachesw; goto do_cache; case WCACHESW: icachesw = &wcachesw;do_cache: ; if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); switch (*icachesw = smatch (cp, caches)) { case AMBIGSW: ambigsw (cp, caches); done (1); case UNKWNSW: adios (NULLCP, "%s unknown", cp); default: break; } continue; case CHECKSW: checksw++; continue; case NCHECKSW: checksw = 0; continue; case DEBUGSW: debugsw++; continue; case EBCDICSW: ebcdicsw++; continue; case NEBCDICSW: ebcdicsw = 0; continue; case FORMSW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); if (formsw) free (formsw); formsw = getcpy (libpath (cp)); continue; case HEADSW: headsw++; continue; case NHEADSW: headsw = 0; continue; case LISTSW: listsw++; continue; case NLISTSW: listsw = 0; continue; case PARTSW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); if (npart >= NPARTS) adios (NULLCP, "too many parts (starting with %s), %d max", cp, NPARTS); parts[npart++] = cp; continue; case PAUSESW: pausesw++; continue; case NPAUSESW: pausesw = 0; continue; case RFC934SW: rfc934sw++; continue; case NRFC934SW: rfc934sw = 0; continue; case SERIALSW: serialsw++; continue; case NSERIALSW: serialsw = 0; continue; case SHOWSW: showsw++; continue; case NSHOWSW: showsw = 0; continue; case SIZESW: sizesw++; continue; case NSIZESW: sizesw = 0; continue; case STORESW: storesw++; continue; case NSTORESW: storesw = 0; continue; case TYPESW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); if (ntype >= NTYPES) adios (NULLCP, "too many types (starting with %s), %d max", cp, NTYPES); types[ntype++] = cp; continue; case VERBSW: verbosw++; continue; case NVERBSW: verbosw = 0; continue; case PROGSW: if (!(progsw = *argp++) || *progsw == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case NPROGSW: nomore++; continue; case LENSW: case WIDSW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case FILESW: if (!(cp = *argp++) || (*cp == '-' && cp[1])) adios (NULLCP, "missing argument to %s", argp[-2]); file = *cp == '-' ? cp : path (cp, TFILE); continue; case VIAMSW: if (!(f1 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; case VIASSW: if (!(f2 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; case VIAPSW: if (!(f3 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; case VIADSW: if (!(f4 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; case VIACSW: if (!(f5 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; case VIAZSW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); if (sscanf (cp, "%d", &f6) != 1 || f6 < 0) f6 = 300; continue; case VIAFSW: if (!(f7 = *argp++)) adios (NULLCP, "missing argument to %s", argp[-2]); continue; } if (*cp == '+' || *cp == '@') { if (folder) adios (NULLCP, "only one folder at a time!"); else folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); } else msgs[msgp++] = cp; } parts[npart] = NULL, types[ntype] = NULL; if (!formsw) formsw = getcpy (libpath ("mhl.headers")); set_endian ();/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -