#include "mail.h"
int ac;
char **av;
int affbytecnt;
int affcnt;
int Daffbytecnt;
int Daffcnt;
char binmsg[] = "*** Message content is not printable: delete, write or save it to a file ***";
int changed;
char datestring[60];
char dbgfname[20];
FILE *dbgfp;
char dead[] = "/dead.letter";
int debug;
int delflg = 1;
int dflag = 0;
char *errlist[]= {
"",
"Unknown system",
"Problem with mailfile",
"Space problem",
"Unable to forward mail, check permissions and group",
"Syntax error",
"Forwarding loop",
"Invalid sender",
"Invalid recipient",
"Too many From lines",
"Invalid permissions",
"Cannot open mbox",
"Temporary file problem",
"Cannot create dead.letter",
"Unbounded forwarding",
"Cannot create lock file",
"No group id of 'mail'",
"Problem allocating memory",
"Could not fork",
"Cannot pipe",
"Must be owner to modify mailfile",
"Permission denied by /etc/mail/mailsurr file",
"Surrogate command failed"
};
int error = 0;
char *failsafe;
int file_size;
int flge = 0;
int flgE = 0;
int flgF = 0;
int flgf = 0;
int flgh = 0;
int flgm;
int flgp = 0;
int flgP = 0;
int flgr = 0;
int flgt = 0;
int flgT = 0;
int flgw = 0;
int fnuhdrtype = 0;
char forwmsg[] = " forwarded by %s\n";
char fromS[1024];
char fromU[1024];
char frwlmsg[] = " %s: Forwarding loop detected in %s's mailfile.\n";
char frwrd[] = "Forward to ";
char fwdFrom[1024];
int goerr = 0;
struct group *grpptr;
struct hdrlines hdrlines[H_CONT];
struct hdr header[] = {
"", FALSE,
"Auto-Forward-Count:", FALSE,
"Auto-Forwarded-From:", FALSE,
"Content-Length:", TRUE,
"Content-Type:", FALSE,
"Date:", TRUE,
"Default-Options:", FALSE,
"End-of-Header:", FALSE,
"From ", TRUE,
">From ", TRUE,
"From:", TRUE,
"MIME-Version:", FALSE,
"MTS-Message-ID:", FALSE,
"Message-Type:", FALSE,
"Message-Version:", FALSE,
"Message-Service:", TRUE,
"Received:", FALSE,
"Report-Version:", FALSE,
"Subject:", TRUE,
"To:", TRUE,
">To:", FALSE,
"Transport-Options:", FALSE,
"UA-Content-ID:", FALSE,
"Hold-Auto-Forwarded-From:", FALSE,
"Hold->To:", FALSE,
"Hold-Received:", FALSE,
"Continue:", FALSE,
"Name-Value:", FALSE,
};
char *help[] = {
"?\t\tprint this help message\n",
"#\t\tdisplay message number #\n",
"-\t\tprint previous\n",
"+\t\tnext (no delete)\n",
"! cmd\t\texecute cmd\n",
"<CR>\t\tnext (no delete)\n",
"a\t\tposition at and read newly arrived mail\n",
"d [#]\t\tdelete message # (default current message)\n",
"dp\t\tdelete current message and print the next\n",
"dq\t\tdelete current message and exit\n",
"h a\t\tdisplay all headers\n",
"h d\t\tdisplay headers of letters scheduled for deletion\n",
"h [#]\t\tdisplay headers around # (default current message)\n",
"m user \tmail (and delete) current message to user\n",
"n\t\tnext (no delete)\n",
"p\t\tprint (override any warnings of binary content)\n",
"P\t\toverride default 'brief' mode and display ALL header lines\n",
"q, ^D\t\tquit\n",
"r [args]\treply to (and delete) current letter via mail [args]\n",
"s [files]\tsave (and delete) current message (default mbox)\n",
"u [#]\t\tundelete message # (default current message)\n",
"w [files]\tsave (and delete) current message without header\n",
"x\t\texit without changing mail\n",
"y [files]\tsave (and delete) current message (default mbox)\n",
0
};
char *hmbox;
char *hmdead;
char *home;
time_t iop;
int interactive = 0;
int ismail = TRUE;
int deliverflag = FALSE;
int fromflag = FALSE;
int keepdbgfile;
struct let let[MAXLET];
char *lettmp;
char lfil[MAXFILENAME];
char line[LSIZE];
char *mailfile;
char mailcnfg[] = MAILCNFG;
char maildir[] = MAILDIR;
gid_t mailgrp;
char mailsave[] = SAVEDIR;
char *mailsurr = MAILSURR;
FILE *malf;
int maxerr = 0;
char mbox[] = "/mbox";
uid_t mf_uid;
gid_t mf_gid;
char *msgtype;
char my_name[1024];
char from_user[1024];
uid_t my_euid;
gid_t my_egid;
uid_t my_uid;
gid_t my_gid;
int nlet = 0;
int onlet = 0;
int optcnt = 0;
int orig_aff = 0;
int orig_dbglvl;
int orig_rcv = 0;
int orig_tcopy = 0;
struct passwd *pwd;
int pflg = 0;
int Pflg = 0;
char *program;
int rcvbytecnt;
int Drcvbytecnt;
char *recipname;
int replying = 0;
char RFC822datestring[60];
char Rpath[1024];
char rmtmsg[] = " remote from %s\n";
char rtrnmsg[] = "***** UNDELIVERABLE MAIL sent to %s, being returned by %s *****\n";
int sav_errno;
char savefile[MAXFILENAME];
void (*saveint)();
char *seldisp[] = {
"Cc:",
"Bcc:",
"Paper-",
"Phone:",
"Message-",
"Original-",
"Confirming-",
"Delivered-",
"Deliverable-",
"Not-",
"En-Route-To:",
0
};
int sending;
char m_sendto[1024];
jmp_buf sjbuf;
int surg_rc = 0;
int surr_len = 0;
char *SURRcmdstr = (char *)NULL;
FILE *SURRerrfile;
char *thissys;
FILE *tmpf;
mode_t umsave;
struct utsname utsn;
static struct utimbuf utims;
struct utimbuf *utimep = &utims;
char uval[1024];
int init()
{
utims.actime = utims.modtime = -1;
return (xsetenv(mailcnfg));
}