📄 mail.c
字号:
/*--------------------------------------------------------------------*/
/* m a i l . c */
/* */
/* Mailer User-Agent (UA) */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by */
/* the UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: mail.c 1.8 1993/09/23 03:26:51 ahd Exp $
*
* Revision history:
* $Log: mail.c $
* Revision 1.8 1993/09/23 03:26:51 ahd
* Use current version variables for Visual C++ under Windows NT
*
* Revision 1.7 1993/09/20 04:39:51 ahd
* OS/2 2.x support
*
* Revision 1.6 1993/07/31 16:26:01 ahd
* Changes in support of Robert Denny's Windows support
*
* Revision 1.5 1993/07/24 03:40:55 ahd
* Change description of "-" command, previous command.
*
* version 1.0 Stuart Lynne
* version 1.5 Samuel Lam <skl@van-bc.UUCP> August/87
*
* version 1.6 Drew Derbyshire May/89
* Support for single user aliases, -u option for reading
* alternate mailboxes, parsing addresses via external routine,
* parsing Resent- fields, suppressing Received: fields,
* automatic positioning to next message. ahd
* 23 Sep 89 Version 1.07a
* Support lists in aliases ahd
*
* 29 Sep 89 Version 1.07b
* Add prompting for subject in outgoing mail. ahd
* 01 Oct 89 Add additional function prototypes to catch bad calls ahd
* 02 Oct 89 Alter large strings/structures to use malloc()/free() ahd
* 12 Oct 89 Version 1.07d
* Correct free() of line in Send_Mail
* 12 Dec 89 Version 1.07g
* Various spelling corrections
* 18 Mar 90 Version 1.07i
* Add ~user support for save/write command
* Add ignore list for user
* Shorten lines printed by aborting from a print command ahd
* 30 Apr 90 Add autoedit support for sending mail ahd
* 2 May 90 Add support for options= flags ahd
* 3 May 90 Split selected subroutines into maillib.c ahd
* 4 May 90 Add 'save' option. ahd
* 8 May 90 Add 'pager' option ahd
* 10 May 90 Add 'purge' option ahd
* 13 May 90 Alter logging so that no numbers are printed on console ahd
* Additions for unofficial version 1.07k, Philip David Meese June 1990
* 16 June 90
* -added mail command: Copy current (without delete) pdm
* -altered calls to Collect_Mail to support mail subcmds pdm
* -added handling of '+' to indicate "relative to home
* directory" for BSD like mail users. pdm
* 12 Feb 91 rewrite parser a for more BSD like syntax
*/
static const char rcsid[] =
"$Id: mail.c 1.8 1993/09/23 03:26:51 ahd Exp $";
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <ctype.h>
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <dos.h>
#include <direct.h>
#ifdef _Windows
#include <windows.h>
#include <alloc.h>
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "address.h"
#include "alias.h" /* ahd */
#include "dater.h"
#include "expath.h"
#include "getopt.h"
#include "hlib.h"
#include "mail.h"
#include "mailblib.h"
#include "maillib.h" /* ahd */
#include "mailsend.h"
#include "mlib.h"
#include "pushpop.h"
#include "stater.h"
#include "timestmp.h"
#if defined(_Windows)
#include "winutil.h"
#endif
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
#ifdef _Windows
unsigned _stklen = 10 * 1024;
unsigned _heaplen = 30 * 1024;
#endif
currentfile();
static char *tmailbox;
static char mfilename[FILENAME_MAX];
int letternum = 0;
static boolean useto = FALSE;
FILE *fmailbox;
#define MAXLETTERS 100
static int maxletters = MAXLETTERS;
struct ldesc *letters;
/*--------------------------------------------------------------------*/
/* Local procedure names */
/*--------------------------------------------------------------------*/
static void Cleanup(void);
static void Interactive_Mail( const boolean PrintOnly,
const boolean postoffice );
static void IncludeNew( const char *target, const char *user);
static void PrintSubject(int msgnum, int letternum);
static void UpdateMailbox(int letternum, boolean postoffice);
static int CreateBox(FILE *rmailbox,
FILE *fmailbox,
const char *tmailbox);
static void usage( void );
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
static char *replytolist[] = { "Resent-Reply-To:",
"Resent-From:",
"Reply-To:",
"From:",
NULL };
static char *fromlist[] = { "Resent-From:",
"From:",
NULL};
static char *tolist[] = { "Resent-To:",
"To:",
NULL};
static char *subjectlist[] = { "Resent-Subject:",
"Subject:",
NULL };
static char *datelist[] = { "Resent-Date:",
"Date:" ,
NULL} ;
/*--------------------------------------------------------------------*/
/* Information on existing mailbox */
/*--------------------------------------------------------------------*/
static long mboxsize = 0;
static time_t mboxage = 0;
/*--------------------------------------------------------------------*/
/* Command parsing table */
/*--------------------------------------------------------------------*/
#define NUMERIC_CMD "9999"
#define EMPTY_CMD ""
static struct CommandTable {
char *sym;
ACTION verb;
unsigned int bits;
char *help;
} table[] = {
{ EMPTY_CMD, M_EMPTY, NODISPLAY | NO_OPERANDS | AUTOPRINT ,
NULL},
{ "!", M_SYSTEM, STRING_OP,
"Execute DOS command"},
{ "+", M_DOWN, KEWSHORT_OP | AUTOPRINT,
"Alias for next"},
{ "-", M_UP, KEWSHORT_OP | AUTOPRINT,
"Alias for previous"},
{ "?", M_FASTHELP, NO_OPERANDS,
"Print this help"},
{ "alias", M_ALIAS, TOKEN_OP,
"Print user alias"},
{ "copy", M_COPY, LETTER_OP | FILE_OP ,
"Copy item to file"},
{ "delete", M_DELETE, LETTER_OP | POSITION | AUTOPRINT ,
"Delete mail item"},
{ "debug", M_DEBUG, KEWSHORT_OP,
"Enable debug output"},
{ "dquit", M_DELETEQ, LETTER_OP ,
"Delete then quit"},
{ "exit", M_EXIT, NO_OPERANDS,
"Exit without updating mailbox"},
{ "forward", M_FORWARD, LETTER_OP | USER_OP,
"Resend item to others"},
{ "go", M_GOTO, LETTER_OP | AUTOPRINT ,
"Go to item"},
{ "Headers", M_HEADERS, LETTER_OP | POSITION ,
"Print specified item summary"},
{ "headers", M_HEADERS, NO_OPERANDS,
"Print all item summaries"},
{ "help", M_HELP, NO_OPERANDS,
"Print long help text"},
{ "mail", M_MAIL, USER_OP,
"Compose and send mail"},
{ "next", M_DOWN, KEWSHORT_OP | AUTOPRINT ,
"Move to next item"},
{"print", M_EXTPRINT, LETTER_OP | POSITION ,
"Print item (condensed)"},
{"Print", M_INTPRINT, LETTER_OP | POSITION ,
"Print item (condensed)"},
{"previous", M_UP, KEWSHORT_OP | AUTOPRINT ,
"Move to previous item"},
{"quit", M_QUIT, NO_OPERANDS,
"Update mailbox, exit"},
{"reply", M_REPLY, LETTER_OP | POSITION ,
"Reply to sender of item"},
{"save", M_SAVE, LETTER_OP | FILE_OP | POSITION | AUTOPRINT ,
"Copy item, delete"},
{"set", M_SET, STRING_OP,
"Print/set boolean options"},
{"status", M_STATUS, NO_OPERANDS,
"Report version/status info"},
{"type", M_EXTTYPE, LETTER_OP | POSITION,
"Print item with all headers"},
{"Type", M_INTTYPE, LETTER_OP | POSITION,
"Print item with all headers"},
{"undelete", M_UNDELETE, LETTER_OP | POSITION | AUTOPRINT ,
"Rescue item after save/delete"},
{"write", M_WRITE, LETTER_OP | FILE_OP | POSITION | AUTOPRINT ,
"Copy item w/o header, delete"},
{"xit", M_EXIT, NO_OPERANDS,
"alias for exit"},
{ NUMERIC_CMD, M_GOTO, NODISPLAY | KEWSHORT_OP | AUTOPRINT ,
NULL} ,
{ NULL, M_INVALID, NODISPLAY | STRING_OP,
NULL }
} ;
/*--------------------------------------------------------------------*/
/* m a i n */
/* */
/* Main program */
/*--------------------------------------------------------------------*/
void main(int argc, char **argv)
{
boolean PrintOnly = FALSE;
boolean postoffice = TRUE;
boolean readmail = FALSE;
boolean sendmail = FALSE;
int option;
char *subject = NULL;
#if defined(__CORE__)
copywrong = strdup(copyright);
checkref(copywrong);
#endif
banner( argv );
if (!configure( B_MUA ))
exit(1); /* system configuration failed */
if (!InitRouter())
exit(1); /* system configuration failed */
tmailbox = mktempname(NULL, "TMP");
PushDir(".");
/*--------------------------------------------------------------------*/
/* get mailbox file name */
/*--------------------------------------------------------------------*/
strcpy( mfilename, E_mailbox );
if ( strchr( mfilename ,'.' ) == NULL )
mfilename[8] = '\0'; /* Prevent OS/2 filename length
overrun */
if ( bflag[ F_MULTITASK ] )
{
if (expand_path( mfilename, E_homedir, E_homedir, E_mailext ) == NULL )
panic();
}
else
mkmailbox(mfilename, E_mailbox );
/*--------------------------------------------------------------------*/
/* parse arguments */
/*--------------------------------------------------------------------*/
while ((option = getopt(argc, argv, "f:ps:tu:x:")) != EOF)
{
char oname[FILENAME_MAX];
switch (option)
{
case 'f':
readmail = TRUE;
strcpy( mfilename, optarg );
if (expand_path( mfilename, NULL, E_homedir, E_mailext ) == NULL )
usage();
/*--------------------------------------------------------------------*/
/* This next one is a little tricky ... If we log outgoing */
/* mail, we copy the name of the outgoing mail file into a */
/* temporary buffer, and expand the name of the file to include */
/* the path name. If this name is the same as the current */
/* file, flip-flip the useto flag which says use the To: */
/* related fields when scanning headers, not the From: related */
/* fields. */
/*--------------------------------------------------------------------*/
if (( E_filesent != NULL ) &&
(expand_path( strcpy( oname, E_filesent) ,
E_homedir, E_homedir , E_mailext ) != NULL ) &&
equali( oname , mfilename ))
/* Our outgoing filename? */
useto = ! useto; /* Yes --> Automatically switch */
postoffice = FALSE;
break;
case 'p':
readmail = TRUE;
PrintOnly = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -