From:	SMTP%"vmsserv@kcl.ac.uk" 18-SEP-1995 14:25:47.95
To:	everhart@star.zko.dec.com
CC:	
Subj:	MMENCODE.1-OF-2

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
$!
$! This archive created:
$!  Name : MMENCODE
$!  By   : Andy Harper <udaa055@bay.cc.kcl.ac.uk>
$!  Date : 16-AUG-1994 18:04:05.00
$!  Using: VMS_SHARE 8.5-1, (C) 1993 Andy Harper, Kings College London UK
$!
$! Credit is due to these people for their original ideas:
$!    James Gray, Michael Bednarek 
$!
$! To unpack this archive:
$!+   Ensure that all parts are present, (2 at about 60 Blocks each).
$!+   Append all parts together to form one larger file.
$!    Minimum of VMS 4.4 (VAX) / OpenVMS 1.0 (Alpha) is required.
$!    Remove the headers of the first part, up to `cut here' line.
$!    Execute file as a command procedure.
$!
$! The following file(s) will be created after unpacking:
$!       1. [.MMENCODE]CODES.C;2
$!       2. [.MMENCODE]CONFIG.H;1
$!       3. [.MMENCODE]MMENCODE.C;3
$!       4. [.MMENCODE]MMENCODE.HLP;1
$!       5. [.MMENCODE]MMENCODE.README;1
$!       6. [.MMENCODE]READ_MIME.COM;2
$!
$ set="set"
$ set symbol/scope=(nolocal,noglobal)
$ f="SYS$SCRATCH:."+f$getjpi("","PID")+";"
$ if f$trnlnm("SHARE_UNPACK") .nes. "" then $ -
 f=f$parse("SHARE_UNPACK_TEMP",f)
$ e="write sys$error  ""%UNPACK"", "
$ w="write sys$output ""%UNPACK"", "
$ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
$ if f$getsyi("CPU") .gt. 127 then $ goto start
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$unpack:subroutine!P1=file,P2=chksum,P3=attrib,P4=size,P5=fileno,P6=filetotal
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'"
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped"
$ delete 'f'*
$ exit
$dirok:
$ x=f$search(P1)
$ if x .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped"
$ delete 'f'*
$ exit
$file_absent:
$ w "-I-UNPACK, Unpacking ", P5, " of ", P6, " - ", P1, " - ", P4, " Blocks"
$ n=P1
$ if P3 .nes. "" then $ n=f
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT/NOJOURNAL 'f'/OUT='n'
PROCEDURE GetHex(s,p)LOCAL x1,x2;x1:=INDEX(t,SUBSTR(s,p,1))-1;x2:=INDEX(t,
SUBSTR(s,p+1,1))-1;RETURN 16*x1+x2;ENDPROCEDURE;PROCEDURE SkipPartsep LOCAL m;
LOOP m:=MARK(NONE);EXITIF m=END_OF(CURRENT_BUFFER);DELETE(m);EXITIF INDEX(
ERASE_LINE,"-+-+-+-+-+-+-+-+")=1;ENDLOOP;ENDPROCEDURE;
PROCEDURE ProcessLine LOCAL c,s,l,b,n,p;s := ERASE_LINE;EDIT(s,TRIM);c :=
 SUBSTR(s,1,1);s := s-c;IF c = "X" THEN SPLIT_LINE; ENDIF;MOVE_HORIZONTAL(-1);
l := LENGTH(s);p := 1;LOOP EXITIF p > l;c := SUBSTR(s,p,1);p := p+1;
CASE c FROM ' ' TO '`' ['\']: b:=GetHex(s,p); n:=GetHex(s,p+2); p:=p+4;
 COPY_TEXT( SUBSTR(CURRENT_LINE,CURRENT_OFFSET-b+1,n));['&']: b:=GetHex(s,p);
 n:=GetHex(s,p+2); p:=p+4; COPY_TEXT(ASCII(n)*b);['`']: COPY_TEXT(ASCII(GetHex(
s,p))); p:=p+2;[INRANGE,OUTRANGE]: COPY_TEXT(c);ENDCASE;ENDLOOP;ENDPROCEDURE;
PROCEDURE Decode(b)LOCAL m;POSITION(BEGINNING_OF(b));LOOP m:=MARK(NONE);
EXITIF m=END_OF(b);DELETE(m);IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=
1 THEN SkipPartSep;ELSE ProcessLine;MOVE_HORIZONTAL(1);ENDIF;ENDLOOP;
ENDPROCEDURE;SET(FACILITY_NAME,"UNPACK");SET(SUCCESS,OFF);SET(INFORMATIONAL,
OFF);t:="0123456789ABCDEF";f:=GET_INFO(COMMAND_LINE,"file_name");o:=
CREATE_BUFFER(f,f);Decode(o);WRITE_FILE(o,GET_INFO(COMMAND_LINE,"output_file"))
;QUIT;
$ if p3 .eqs. "" then $ goto dl
$ open/write fdl &f
$ write fdl "RECORD"
$ write fdl P3
$ close fdl
$ w "-I-CONVRFM, Converting record format to ", P3
$ convert/fdl='f' 'f'-1 'f'
$ fa=f$getdvi(f$parse(f),"ALLDEVNAM")
$ Pa=f$getdvi(f$parse(P1),"ALLDEVNAM")
$ if fa .eqs. Pa then $ rename &f 'f$parse(P1)'
$ if fa .nes. Pa then $ copy &f 'f$parse(P1)'
$dl: delete 'f'*
$ checksum 'P1'
$ if checksum$checksum .nes. P2 then $ -
  e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ exit
$ endsubroutine
$start:
$!
$ create 'f'
X/*
XCopyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
X
XPermission to use, copy, modify, and distribute this material`20
Xfor any purpose and without fee is hereby granted, provided`20
Xthat the above copyright notice and this permission\1B08
Xappear in all copies, and that the name of Bellcore not be`20
Xused in advertising or publicity pertaining to this`20
Xmaterial without the specific, prior written permission`20
Xof an authorized representative of Bellcore.  BELLCORE`20
XMAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY`20
XOF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",`20
XWITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
X*/
X#include <stdio.h>
X#include <ctype.h>
X#include "config.h"
X
Xextern char *index();
Xstatic char basis_64`5B`5D =
X   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
X
Xstatic char index_64`5B128`5D = `7B
X    -1,-1,\0606\0D0D\1A1A
X    -1,-1,\0606\0D0D\1A1A
X    -1,-1,\0606\0D0D\1A0A62\0D0C3,
X    52,53,54,55, 56,57,58,59, 60,61,-1,-1, \0706\0D06
X    -1, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
X    15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,\0606
X    -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
X    41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
X`7D;
X
X#define char64(c)  (((c) < 0 `7C`7C (c) > 127) ? -1 : index_64`5B(c)`5D)
X
X/*
Xchar64(c)
Xchar c;
X`7B
X    char *s = (\0B06) index(basis_64, c);
X    if (s) return(s-basis_64);
X    return(-1);
X`7D
X*/
X
X/* the following gets a character, but fakes it properly into two chars if the
Vre's a newline \4509 */
Xstatic int InNewline=0;
X
Xint nextcharin(infile, PortableNewlines)
XFILE *infile;
Xint PortableNewlines;
X`7B
X    int c;
X
X#ifndef NEWLINE_CHAR
X    return(getc(infile));
X#else
X    if (!PortableNewlines) return(getc(infile));
X    if (InNewline) `7B
X        InNewline = 0;
X        return(10); /* LF */
X    `7D
X    c = getc(infile);
X    if (c == NEWLINE_CHAR) `7B
X        InNewline = 1;
X        return(13); /* CR */
X    `7D
X    return(c);
X#endif
X`7D
X
Xto64(infile, out\0906PortableNewlines)`20
XFILE *infile, *outfile;
Xint PortableNewlines;
X`7B
X    int c1, c2, c3, ct=0;
X    InNewline = 0; /* always reset it */
X    while ((c1 = nextcharin(infile, PortableNewlines)) != EOF) `7B
X        c2 = nextcharin(infile, PortableNewlines);
X        if (c2 == EOF) `7B
X            output64chunk(c1, 0, 0, 2, outfile);
X        `7D else `7B
X            c3 = nextcharin(infile, PortableNewlines);
X            if (c3 == EOF) `7B
X        \0808output64chunk(c1, c2, 0, 1, outfile);
X            `7D else `7B
X        \0808output64chunk(c1, c2, c3, 0, outfile);
X            `7D
X        `7D
X        ct += 4;
X        if (ct > 71) `7B
X            putc('`5Cn', outfile);
X            ct = 0;
X        `7D
X    `7D
X    if (ct) putc('`5Cn', outfile);
X    fflush(outfile);
X`7D
X
Xoutput64chunk(c1, c2, c3, pads, outfile)
XFILE *outfile;
X`7B
X    putc(basis_64`5Bc1>>2`5D, outfile);
X    putc(basis_64`5B((c1 `26 0x3)<< 4) `7C ((c2 `26 0xF0) >> 4)`5D, outfile);
V
X    if (pads == 2) `7B
X        putc('=', outfile);
X        putc('=', outfile);
X    `7D else if (pads) `7B
X        putc(basis_64`5B((c2 `26 0xF) << 2) `7C ((c3 `26 0xC0) >>6)`5D, outfil
Ve);
X        putc('=', outfile);
X    `7D else `7B
X        putc(basis_64`5B((c2 `26 0xF) << 2) `7C ((c3 `26 0xC0) >>6)`5D, outfil
Ve);
X        putc(basis_64`5Bc3 `26 0x3F`5D, outfile);
X    `7D
X`7D
X
XPendingBoundary(s, \0C07ie\0C0AyCt)
Xchar *s;
Xchar **Boundaries;
Xint *BoundaryCt;
X`7B
X    int i, len;
X
X    if (s`5B0`5D != '-' `7C`7C s`5B1\0F08) return(0);
X
X
X    for (i=0; i < *BoundaryCt; ++i) `7B
X`09len = strlen(Boundaries`5Bi`5D);
X        if (!strncmp(s, Boundaries`5Bi`5D, len)) `7B
X            if (s`5Blen`5D == '-' `26`26 s`5Blen+1\1308) *BoundaryCt = i;
X            return(1);
X        `7D
X    `7D
X    return(0);
X`7D
X
X/* If we're in portable newline mode, we have to convert CRLF to the`20
X    local newline convention on output */
X
Xstatic int CRpending = 0;
X
X#ifdef NEWLINE_CHAR
Xalmostputc(c, outfile, PortableNewlines)
Xint c;
XFILE *outfile;
Xint PortableNewlines;
X`7B
X    if (CRpending) `7B
X        if (c == 10) `7B
X            putc(NEWLINE_CHAR, outfile);
X            CRpending = 0;
X        `7D else `7B
X            putc(13, outfile);
X`09    if (c != 13) `7B
X            `09putc(c, outfile);
X`09`09CRpending = 0;
X`09    `7D
X        `7D
X    `7D else `7B
X        if (PortableNewlines `26`26 c == 13) `7B
X            CRpending = 1;
X        `7D else `7B
X            putc(c, outfile);
X        `7D
X    `7D
X`7D
X#else
Xalmostputc(c, outfile, PortableNewlines)
Xint c;
XFILE *outfile;
Xint PortableNewlines;
X`7B
X    putc(c, outfile);
X`7D
X#endif
X
Xfrom64(infile, out\0906boundaries\0C09yct, PortableNewlines)`20
XFILE *infile, *outfile;
Xchar **boundaries;
Xint *boundaryct;
Xint PortableNewlines;
X`7B
X    int c1, c2, c3, c4;
X    int newline = 1, DataDone = 0;
X
X    /* always reinitialize */
X    CRpending = 0;
X    while ((c1 = getc(infile)) != EOF) `7B
X        if (isspace(c1)) `7B
X            if (c1 == '`5Cn') `7B
X        \0808newline = 1;
X            `7D else `7B
X        \0808newline = 0;
X            `7D
X            continue;
X        `7D
X        if (newline `26`26 boundaries &0226 c1 == '-') `7B
X            char Buf`5B200`5D;
X            /* a dash is NOT base 64, so all bets are off if NOT a boundary */
V
X            ungetc(c1, infile);
X            fgets(Buf, sizeof(Buf), infile);
X            if (boundaries
X        \0808 `26`26 (Buf`5B0`5D == '-')
X        \0808 `26`26 (Buf`5B1`5D == '-')
X        \0808 `26`26 PendingBoundary(Buf, b\0E06ies\0C09yct)) `7B
X        \0808return;
X            `7D
X            fprintf(stderr, "Ignoring unrecognized boundary line: %s`5Cn", Buf
V);
X            continue;
X        `7D
X        if (DataDone) continue;
X        newline = 0;
X        do `7B
X            c2 = getc(infile);
X        `7D while (c2 != EOF `26`26 isspace(c2));
X        do `7B
X            c3 = getc(infile);
X        `7D while (c3 != EOF `26`26 isspace(c3));
X        do `7B
X            c4 = getc(infile);
X        `7D while (c4 != EOF `26`26 isspace(c4));
X        if (c2 == EOF `7C`7C c3\0D0C4\1A07) `7B
X            fprintf(stderr, "Warning: base64 decoder saw premature EOF!`5Cn");
V
X            return;
X        `7D
X        if (c1 == '=' `7C`7C c2\0D07) `7B
X            DataDone=1;
X            continue;
X        `7D
X        c1 = char64(c1);
X        c2 = char64(c2);
X        almostputc(((c1<<2) `7C ((c2`260x30)>>4)), outfile, PortableNewlines);
V
X        if (c3 == '=') `7B
X            DataDone = 1;
X        `7D else `7B
X            c3 = char64(c3);
X            almostputc((((c2`260XF) << 4) `7C ((c3`260x3C) >> 2)), outfile, Po
VrtableNewlines);
X            if (c4 == '=') `7B
X        \0808DataDone = 1;
X            `7D else `7B
X        \0808c4 = char64(c4);
X        \0808almostputc((((c3`260x03) <<6) `7C c4), outfile, PortableNewlines)
V;
X            `7D
X        `7D
X    `7D
X    if (CRpending) putc(13, outfile); /* Don't drop a lone trailing char 13 */
V
X`7D
X
Xstatic char basis_hex`5B`5D = "0123456789ABCDEF";
Xstatic char index_hex`5B128`5D = `7B
X    -1,-1,\0606\0D0D\1A1A
X    -1,-1,\0606\0D0D\1A1A
X    -1,-1,\0606\0D0D\1A1A
X     0, 1, 2, 3,  4, 5, 6, 7,  8, 9,-1,-1, \0706\0D06
X    -1,10,11,12, 13,14,15,-1, -1,-1,\0606\0D0D
X    -1,-1,\0606\0D0D\1A1A
X    -1,10,11,12, 13,14,15,-1, -1,-1,\0606\0D0D
X    -1,-1,\0606\0D0D\1A19
X`7D;
X
X/* The following version generated complaints on Solaris. */
X/* #define hexchar(c)  (((c) < 0 `7C`7C (c) > 127) ? -1 : index_hex`5B(c)`5D)
V  */
X/*  Since we're no longer ever calling it with anything signed, this should wo
Vrk: */
X#define hexchar(c)  (((c) > 127) ? -1 : index_hex`5B(c)`5D)
X
X/*
Xhexchar(c)
Xchar c;
X`7B
X    char *s;
X    if (islower(c)) c = toupper(c);
X    s = (char *) index(basis_hex, c);
X    if (s) return(s-basis_hex);
X    return(-1);
X`7D
X*/
X
Xtoqp(infile, outfile)`20
XFILE *infile, *outfile;
X`7B
X    int c, ct=0, prevc=255;
X    while ((c = getc(infile)) != EOF) `7B
X        if ((c < 32 `26`26 (c != '`5Cn' &0226 \0D07t'))
X             `7C`7C (c == '=')
X             `7C`7C (c >= 127)
X             /* Following line is to avoid single periods alone on lines,
X        \0807which messes up some dumb smtp implementations, sigh... */
X             `7C`7C (ct == 0 `26`26 c == '.')) `7B
X            putc('=', outfile);
X            putc(basis_hex`5Bc>>4`5D, outfile);
X            putc(basis_hex`5Bc`260xF`5D, outfile);
X            ct += 3;
X            prevc = 'A'; /* close enough */
X        `7D else if (c == '`5Cn') `7B
X            if (prevc == ' ' `7C`7C \100A`5Ct') `7B
X        \0808putc('=', outfile); /* soft `26 hard lines */
X        \0808putc(c, outfile);
X            `7D
X            putc(c, outfile);
X            ct = 0;
X            prevc = c;
X        `7D else `7B
X            if (c == 'F' `26`26 prev\1006`5Cn') `7B
X        \0808/* HORRIBLE but clever hack suggested by MTR for sendmail-avoidan
Vce */
X        \0808c = getc(infile);
X        \0808if (c == 'r') `7B
X        \0808    c = getc(infile);
X        \0808    if (c == 'o') `7B
X        \0808\1008c = getc(infile);
X        \0808\1008if (c == 'm') `7B
X        \0808\100Cc = getc(infile);
X        \0808\100Cif (c == ' ') `7B
X        \0808\1010/* This is the case we are looking for */
X        \0808\1010fputs("=46rom", outfile);
X        \0808\1010ct += 6;
X        \0808\100C`7D else `7B
X        \0808\1010fputs("From", outfile);
X        \0808\1010ct += 4;
X        \0808\100C`7D
X        \0808\1008`7D else `7B
X        \0808\100Cfputs("Fro", outfile);
X        \0808\100Cct += 3;
X        \0808\1008`7D
X        \0808    `7D else `7B
X        \0808\1008fputs("Fr", outfile);
X        \0808\1008ct += 2;
X        \0808    `7D
X        \0808`7D else `7B
X        \0808    putc('F', outfile);
X        \0808    ++ct;
X        \0808`7D
X        \0808ungetc(c, infile);
X        \0808prevc = 'x'; /* close enough -- printable */
X            `7D else `7B /* END horrible hack */
X        \0808putc(c, outfile);
X        \0808++ct;
X        \0808prevc = c;
X            `7D
X        `7D
X        if (ct > 72) `7B
X            putc('=', outfile);
X            putc('`5Cn', outfile);
X            ct = 0;
X            prevc = '`5Cn';
X        `7D
X    `7D
X    if (ct) `7B
X        putc('=', outfile);
X        putc('`5Cn', outfile);
X    `7D
X`7D
X
Xfromqp(infile, out\0906boundaries\0C09yct)`20
XFILE *infile, *outfile;
Xchar **boundaries;
Xint *boundaryct;
X`7B
X    unsigned int c1, c2;
X    int sawnewline = 1, need\110A0;
X    /* The neednewline hack is necessary because the ne\2606leading into`20
X      a multipart boundary is part of the\1809, not the data */
X
X    while ((c1 = getc(infile)) != EOF) `7B
X        if (sawnewline `26`26 boundaries &0226 (c1 == '-')) `7B
X            char Buf`5B200`5D;
X            unsigned char *s;
X
X            ungetc(c1, infile);
X            fgets(Buf, sizeof(Buf), infile);
X            if (boundaries
X        \0808 `26`26 (Buf`5B0`5D == '-')
X        \0808 `26`26 (Buf`5B1`5D == '-')
X        \0808 `26`26 PendingBoundary(Buf, b\0E06ies\0C09yct)) `7B
X        \0808return;
X            `7D
X            /* Not a boundary, now we must treat THIS line as q-p, sigh */
X            if (neednewline) `7B
X        \0808putc('`5Cn', outfile);
X        \0808neednewline = 0;
X            `7D
X            for (s=(unsigned char *) Buf; *s; ++s) `7B
X        \0808if (*s == '=') `7B
X        \0808    if (!*++s) break;
X        \0808    if (*s == '`5Cn') `7B
X        \0808\1008/* ignore it */
X        \0808\1008sawnewline = 1;
X        \0808    `7D else `7B
X        \0808\1008c1 = hexchar(*s);
X        \0808\1008if (!*++s) break;
X        \0808\1008c2 = hexchar(*s);
X        \0808\1008putc(c1<<4 `7C c2, outfile);
X        \0808    `7D
X        \0808`7D else `7B
X#ifdef MSDOS
X        \0808    if (*s == '`5Cn')
X        \0808\1008putc('`5Cr', outfile);`09/* insert CR for binary-mode write
V */
X#endif
X        \0808    putc(*s, outfile);
X        \0808`7D
X            `7D
X        `7D else `7B
X            if (neednewline) `7B
X        \0808putc('`5Cn', outfile);
X        \0808neednewline = 0;
X            `7D
X            if (c1 == '=') `7B
X        \0808sawnewline = 0;
X        \0808c1 = getc(infile);
X        \0808if (c1 == '`5Cn') `7B
X        \0808    /* ignore it */
X        \0808    sawnewline = 1;
X        \0808`7D else `7B
X        \0808    c2 = getc(infile);
X        \0808    c1 = hexchar(c1);
X        \0808    c2 = hexchar(c2);
X        \0808    putc(c1<<4 `7C c2, outfile);
X        \0808    if (c2 == '`5Cn') sawnewline = 1;
X        \0808`7D
X            `7D else `7B
X        \0808if (c1 == '`5Cn') `7B
X        \0808    sawnewline = 1;
X        \0808    neednewline = 1;
X        \0808`7D else `7B
X        \0808    sawnewline = 0;
X        \0808    putc(c1, outfile);
X        \0808`7D
X            `7D
X        `7D
X    `7D
X    if (neednewline) `7B
X        putc('`5Cn', outfile);
X        neednewline = 0;
X    `7D   `20
X`7D
$ call unpack [.MMENCODE]CODES.C;2 272434905 "" 27 1 6
$!
$ create 'f'
X/*
XCopyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
X
XPermission to use, copy, modify, and distribute this material`20
Xfor any purpose and without fee is hereby granted, provided`20
Xthat the above copyright notice and this permission\1B08
Xappear in all copies, and that the name of Bellcore not be`20
Xused in advertising or publicity pertaining to this`20
Xmaterial without the specific, prior written permission`20
Xof an authorized representative of Bellcore.  BELLCORE`20
XMAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY`20
XOF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",`20
XWITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
X*/
X
X/* This is the top-level configuration file for the metamail distribution. */
V
X/* If your compiler does not automatically do so, you may wish to`20
X      add a #define here that \1106s your system type, e.g.
X      #define LINUX
X      #define SYSV`20
X      #define MSDOS
X      #define AMIGA
X*/
X
X#ifdef AIX
X#define SYSV
X#endif
X#ifdef _AIX
X#define SYSV
X#endif
X
X#ifdef __svr4__
X#ifndef SYSV
X/* Stupid Solaris 2.0 machines define __svr4__ but not SYSV */
X#define SYSV
X#endif
X#endif
X
X#ifdef LINUX
X#define SYSV /* Linux is SysV */
X#endif
X
X#ifdef SVR3
X#ifndef SYSV
X/* Stupid SGI machines define SVR3 but not SYSV */
X#define SYSV
X#endif
X#endif
X
X#ifdef __MSDOS__`09/* Defined if using Borland C compiler? */
X#ifndef BORLAND
X#define BORLAND`09`09/* Make sur\1609 gets \2A06d */
X#endif
X#ifndef MSDOS
X#define MSDOS   /* A common symbol we can use for all DOS compilers */
X#endif
X#endif
X
X#ifdef _MSC_VER`09`09/* Using Microsoft C compiler */
X#ifndef MICROSOFT
X#define MICROSOFT`09/* Make sur\170B gets \2D06d */
X#endif
X#ifndef MSDOS
X#define MSDOS   /* A common symbol we can use for all DOS compilers */
X#endif
X#endif
X
X/* NOTE:  The RESET_PROGRAM resets the terminal to a "normal" state`20
X   If you comment out the definition, all will be well except that metamail's
V
X   -R switch won't work, and metamail-called programs might be more likely
X   to screw up your terminal state */
X
X#ifdef SYSV
X#define RESET_PROGRAM "tput clear"
X#else
X#ifdef __BSD_4_4__
X#define RESET_PROGRAM "/usr/bin/reset"
X#else
X#define RESET_PROGRAM "/usr/ucb/reset"
X#endif
X#endif
X
X#ifdef __hpux
X/* Basically SYSV */
X#define SYSV
X#define NO_RLIMITS 1
X/* I've gotten conflicting reports about the best way to rese\1606terminal`20
X  state under hpux.  I'm now using "/usr/bin/reset" as the default, but there
V`20
X  have been two other suggestions as well.  Your mileage may vary! -- NSB */
X#undef RESET_PROGRAM
X#define RESET_PROGRAM "/usr/bin/reset"
X/* #define RESET_PROGRAM "tput clear" */
X/* #define RESET_PROGRAM "/bin/reset" */
X/* #define RESET_PROGRAM "/usr/ucb/reset" */
X#endif
X
X#ifdef NeXT
X#undef RESET_PROGRAM
X#define RESET_PROGRAM "/usr/ucb/reset"
X#endif
X
X#ifdef SYSV
X#define killpg(a, b) kill(-(a), (b))
X#define bcopy(a, b, c) memcpy(b, a, c)
X#define bzero(a, b) memset(a, 0, b)
X#define bcmp memcmp
X#define index strchr
X#define rindex strrchr
X#define initstate srand
X#define random rand
X#define NO_RLIMITS 1
X#define sigtype void
X#endif
X
X/* Solaris, at least, has better versions of some functions */
X#ifdef __svr4__
X#define bcopy(a, b, c) memmove(b, a, c)
X#define initstate srand48
X#define random lrand48
X#endif
X
X/* This constant should define the ASCII code for newlines on systems where`20
X   the newline convention is other than CRLF.  On UNIX, it is `5EJ, ASCII 10.
V`20
X    Here we define it as '`5Cn' which should be right on MOST systems... */
X#define NEWLINE_CHAR '`5Cn'
X
X#ifdef MSDOS
X#undef NEWLINE_CHAR /* DOS uses CRLF */
X#undef RESET_PROGRAM
X#include <string.h>
X#define index  strchr
X#define rindex strrchr
X#define popen  fopen
X#define pclose fclose
X#define NO_RLIMITS 1
X#endif
X
X#ifdef AMIGA
X#undef RESET_PROGRAM
X#define index  strchr
X#define rindex strrchr
X#define NO_RLIMITS 1
X#define DEFAULT_SPLIT_SIZE 95000
X#endif
X
X/* The following defines the default size at which long
X    messages will be split into multiple \2509of type
X    "message/partial" by the mailto and splitmail commands,
X    at least. */
X#ifndef DEFAULT_SPLIT_SIZE
X#define DEFAULT_SPLIT_SIZE 250000
X#endif
X
X#ifndef sigtype
X#ifdef NeXT
X#define sigtype void
X#else
X#define sigtype int
X#endif
X#endif
X
X#ifdef MSDOS
X#define PATH_SEPARATOR ';'
X#ifndef STDPATH
X#define STDPATH ".`5C`5Cmailcap;\0A09"
X#endif
X#else
X#ifdef AMIGA
X#define PATH_SEPARATOR ' '
X#ifndef STDPATH
X#define STDPATH "uulib:mailcap"
X#endif
X#else
X#define PATH_SEPARATOR ':'
X#ifndef STDPATH
X#define STDPATH "/.mailcap:/usr/local/etc/\170D\110D\1E0D\2B08\300Epublic/lib
V\4808"
X#endif
X#endif
X#endif
X
X/* The following can be set to a directory or colon-separated list of`20
X  directories that will be prepended to the user's search path before`20
X  executing any mailcap-derived commands.`20
X
X  It should be set to NULL if there are no directories to prepend. `20
X*/
X
X#define AUXPATH NULL
$ call unpack [.MMENCODE]CONFIG.H;1 1278233841 "" 11 2 6
$!
$ create 'f'
X/*
XCopyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
X
XPermission to use, copy, modify, and distribute this material`20
Xfor any purpose and without fee is hereby granted, provided`20
Xthat the above copyright notice and this permission\1B08
Xappear in all copies, and that the name of Bellcore not be`20
Xused in advertising or publicity pertaining to this`20
Xmaterial without the specific, prior written permission`20
Xof an authorized representative of Bellcore.  BELLCORE`20
XMAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY`20
XOF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",`20
XWITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
X*/
X#include <stdio.h>
X#include "config.h"
X#ifdef MSDOS
X#include <fcntl.h>
X#endif
X
X#define BASE64 1
X#define QP 2 /* quoted-printable */
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X`7B
X    int encode = 1, which = BASE64, i, portablenewlines = 0;
X    FILE *fp = stdin;
X    FILE *fpo = stdout;
X
X    for (i=1; i<argc; ++i) `7B
X        if (argv`5Bi`5D`5B0`5D == '-') `7B
X`09    switch (argv`5Bi`5D`5B1`5D) `7B
X`09`09case 'o':
X`09`09    if (++i >= argc) `7B
X`09`09`09fprintf(stderr, "mimencode: -o requires a file name.`5Cn");
X`09`09`09exit(-1);
X`09`09    `7D
X`09`09    fpo = fopen(argv`5Bi`5D, "w");
X`09`09    if (!fpo) `7B
X`09`09`09perror(argv`5Bi`5D);
X`09`09`09exit(-1);
X`09`09    `7D
X`09`09    break;
X        \0808case 'u':
X        \0808    encode = 0;
X        \0808    break;
X        \0808case 'q':
X        \0808    which = QP;
X        \0808    break;
X        \0808case 'p':
X        \0808    portablenewlines = 1;
X        \0808    break;
X        \0808case 'b':
X        \0808    which = BASE64;
X        \0808    break;
X`09`09default:
X        \0808    fprintf(stderr,
X        \0808\1007"Usage: mmencode `5B-u`5D `5B-q`5D `5B-b`5D `5B-p`5D `5B-o o
Vutputfile`5D `5Bfile name`5D`5Cn");
X        \0808    exit(-1);
X            `7D
X        `7D else `7B
X#ifdef MSDOS
X            if (encode)
X        \0808fp = fopen(argv`5Bi`5D, "rb");
X            else
X            `7B
X        \0808fp = fopen(argv`5Bi`5D, "rt");
X        \0808setmode(fileno(fpo), O_BINARY);
X            `7D /* else */
X#else
X            fp = fopen(argv`5Bi`5D, "r");
X#endif /* MSDOS */
X            if (!fp) `7B
X        \0808perror(argv`5Bi`5D);
X        \0808exit(-1);
X            `7D
X        `7D
X    `7D
X#ifdef MSDOS
X    if (fp == stdin) setmode(fileno(fp), O_BINARY);
X#endif /* MSDOS */
X    if (which == BASE64) `7B
X        if (encode) `7B
X            to64(fp, fpo, portablenewlines);
X        `7D else `7B
X            from64(fp,fpo, (char **) NULL, (int *) 0, portablenewlines);
X        `7D
X    `7D else `7B
X        if (encode) toqp(fp, fpo); else from\160A, NULL, 0);
X    `7D
X#ifdef VMS
X    return(1);
X#else
X    return(0);
X#endif
X`7D
X
$ call unpack [.MMENCODE]MMENCODE.C;3 1919841453 "" 6 3 6
$!
$ create 'f'
X! MMENCODE help file
X!`09Andy harper, 16-AUG-1994, Kings College London
X1 MMENCODE
XEncodes/Decodes a file to and from MIME format using either the BASE-64 or
XQUOTED-PRINTABLE format.
X
XFormat:
X   $ MMENCODE `5Boptions`5D `5B-o output`5D input
X2 Description
XDocuments of any type can be sent via electronic mail if encoded using the
XMIME conventions (MIME = Multimedia Internet Mail Extensions). The sender
Xencodes the file using MIME and the recipient de\2E06it. Often the mail
Xclient will contain facilities for automatic decoding of MIME message. VMS
XMAIL does not and a certain amount of manual decoding is required.
X
XMMENCODE will:
X
X   o Encode a file into MIME format for mailing to someone else
X   o Decode mail received from someone else back to its original format
X
XOnly the encoding types of BASE64 and QUOTED-PRINTABLE are recognized.
XOther encoding types cannot be handled by MMENCODE.
X2 Examples
X   $ MMENCODE -b -o TEST.B64\0906DAT
X        Encodes the file TEST.DAT into\170FB64, using the BASE64
X        encoding format.
X
X   $ MMENCODE -q -o TEST.QPR\0906DAT
X        Encodes the file TEST.DAT into\170FQPR, using the QUOTED-
X        PRINTABLE encoding format.
X  `20
X   $ MMENCODE -u -b -o TEST.DAT\0906B64
X        Decodes the file TEST.B64 from the BASE64 format back to its
X        original form in TEST.DAT.
X
X   $ MMENCODE -u -q -o TEST.DAT\0906QPR
X        Decodes the file TEST.QPR from the QUOTED-PRINTABLE format back
X        to its original form in TEST.DAT.
X2 Parameters
XThe parameters to MMENCODE define the input file, which is required, an
Xoptional output file, and various encoding options. The general form of the
Xcommand is:
X
X   $ MMENCODE `5Boptions`5D input
X
XWithout options, MMENCODE assumes:
X   * Output to the standard o\1706(SYS$OUTPUT)
X   * Encoding of input file
X   * QUOTED-PRINTABLE encoding type
X
X3 Options
X  -o file   Specify the output file.
X
X  -b        Specify BASE64 encoding type
X
X  -q        Specify QUOTED-PRINTABLE encoding type (the default)
X
X  -u        Specify decode rather than encode
X2 READ_MIME
XREAD_MIME is a simple interactive procedure designed to ease the use of
XMMENCODE for DECODING files. It will prompt for the input/output\2B06 and
Xthe encoding type, and then run MMENCODE with the appropriate options.
X
XFormat:
X
X  $ READ_MIME `5Binput`5D `5Bout\09061/2`5D
X
XPrompts are issued for any missing parameters. The third \1609
Xspecifies the encoding type - 1=BASE64, 2=QUOTED-PRINTABLE.
X2 Usage_Notes
XFiles to be decoded are received in the form of `60attachments' to a normal
Xmail message. Each attachment can be in a variety of formats and is
Xprefixed by a set of headers. These\0F08 should be removed before
Xrunning them through the MMENCODE utility. Just pass the data portion of
Xthe encoded attachment to MMENCODE. This may entail extracting the whole
Xmessage into a file and then editing it to remove the extraneous headers.
X
XNote that MMENCODE can only deal with a small subset of the possible
Xencoding formats. However, BASE64 and QUOTED-PRINTABLE and commonly used.
$ call unpack [.MMENCODE]MMENCODE.HLP;1 980307653 "" 7 4 6
$!
$ create 'f'
XFrom:`09MX%"MX-List@WKUVX1.WKU.EDU"  9-MAR-1994 23:10:36.76
XTo:`09UDAA055
XCC:`09
XSubj:`09External Mime encoding/de\0906
X
XReturn-Path: <List-Mgr@WKUVX1.WKU.EDU>
XReceived: from wkuvx1.wku.edu by bay.cc.kcl.ac.uk (MX V3.3 VAX) with SMTP; Wed
V,
X          09 Mar 1994 22:51:21 EST
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
================== RFC 822 Headers ==================
Received: from newt.kcl.ac.uk by mail2.digital.com; (5.65 EXP 4/12/95 for V3.2/1.0/WV)
	id AA23213; Mon, 18 Sep 1995 11:02:49 -0700
Received: from kcl.ac.uk by newt.kcl.ac.uk with SMTP (PP) 
          id <03176-0@newt.kcl.ac.uk>; Mon, 18 Sep 1995 19:02:27 +0100
Received: by bay.cc.kcl.ac.uk (MX V4.1 AXP) id 326;
          Mon, 18 Sep 1995 19:03:09 GMT
Date: Mon, 18 Sep 1995 19:03:10 GMT
From: Kings College London File Server <vmsserv@kcl.ac.uk>
To: everhart@star.zko.dec.com
Message-Id: <00996981.DC7782EA.326@bay.cc.kcl.ac.uk>
Subject: MMENCODE.1-OF-2
