📄 mailblib.c
字号:
/*--------------------------------------------------------------------*/
/* m a i l b l i b . c */
/* */
/* Support routines for UUPC/extended mail user agent */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* 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: mailblib.c 1.4 1993/09/20 04:41:54 ahd Exp $
*
* Revision history:
* $Log: mailblib.c $
* Revision 1.4 1993/09/20 04:41:54 ahd
* OS/2 2.x support
*
* Revision 1.3 1993/07/31 16:26:01 ahd
* Changes in support of Robert Denny's Windows support
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#if defined(_Windows)
#include <windows.h>
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "address.h"
#include "mail.h"
#include "maillib.h"
#include "mailblib.h"
#include "mailsend.h"
#include "hlib.h"
#include "alias.h"
#include "expath.h"
/*--------------------------------------------------------------------*/
/* Variables global to file */
/*--------------------------------------------------------------------*/
static int *item_list = NULL;
static size_t next_item;
currentfile();
/*--------------------------------------------------------------------*/
/* Internal function prototypes */
/*--------------------------------------------------------------------*/
static boolean SearchUser( char *token , char **input, const int bits);
static boolean SearchSubject( char *token,
char **input,
char *trailing,
const int bits);
/*--------------------------------------------------------------------*/
/* Externally known functions */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* S h o w A l i a s */
/* */
/* Print the expansion of an alias */
/*--------------------------------------------------------------------*/
void ShowAlias( const char *alias)
{
char *fullname = AliasByNick( alias );
static int level = 0;
int column = level * 2;
if ( alias == NULL )
{
printf("Missing operand\n");
return;
}
/*--------------------------------------------------------------------*/
/* Indent nested calls */
/*--------------------------------------------------------------------*/
while(column-- > 0 )
putchar(' ');
/*--------------------------------------------------------------------*/
/* Show the alias, breaking it down recursively if need be */
/*--------------------------------------------------------------------*/
if (fullname == NULL)
{
char user[MAXADDR];
char path[MAXADDR];
char node[MAXADDR];
printf("No alias defined for \"%s\"\n",alias);
column = level * 2 + 2;
while(column-- > 0 )
putchar(' ');
user_at_node(alias, path, node, user);
/* Reduce address to basics */
printf("(%s@%s via %s)\n", user, node, path);
}
else {
printf("%s is aliased to %s\n", alias, fullname);
if (*fullname == '"')
{
if ( debuglevel > 1)
{
char user[MAXADDR];
char path[MAXADDR];
char node[MAXADDR];
ExtractAddress(user,fullname, FALSE);
user_at_node(user,path,node,user);
/* Reduce address to basics */
column = level * 2 + 2;
while(column-- > 0 )
putchar(' ');
printf("(%s@%s via %s)\n", user, node, path);
}
}
else {
char buf[LSIZE];
strcpy( buf, fullname );
fullname = strtok( buf , WHITESPACE "," );
while (fullname != NULL )
{
char *save = strtok( NULL , "");
level++; /* Bump up a level for recursive calls */
ShowAlias(fullname);
level--; /* Restore indent level */
fullname = strtok( save , " ," );
} /* while */
} /* else */
} /* else */
} /* ShowAlias */
/*--------------------------------------------------------------------*/
/* S a v e I t e m */
/* */
/* Save an item in another mailbox */
/*--------------------------------------------------------------------*/
boolean SaveItem( const int item,
const boolean delete,
const copyopt headers,
char *fname,
const ACTION verb)
{
char filename[FILENAME_MAX];
char *s = "?";
FILE *stream;
if (fname == NULL)
fname = "~/mbox";
/*--------------------------------------------------------------------*/
/* Build the file name */
/*--------------------------------------------------------------------*/
switch (*fname)
{
case '=': /* relative to home directory? */
printf("Syntax is obsolete ... use \"~/%s\"", fname + 1 );
mkfilename(filename, E_homedir, ++fname);
break;
case '+': /* Relative to mail directory? */
mkmailbox(filename, ++fname);
break;
default:
case '~': /* Relative to home directory? */
strcpy( filename , fname );
if (expand_path( filename , NULL, E_homedir, E_mailext ) == NULL)
return FALSE;
break;
} /* end switch */
/*--------------------------------------------------------------------*/
/* Announce our action based on the verb */
/*--------------------------------------------------------------------*/
switch( verb )
{
case M_COPY:
s = "Copying";
break;
case M_SAVE:
s = "Saving";
break;
case M_WRITE:
s = "Writing";
break;
} /* switch */
printf("%s item %d to %s\n", s , item + 1, filename );
/*--------------------------------------------------------------------*/
/* Open the mailox to save to */
/*--------------------------------------------------------------------*/
if ((stream = FOPEN(filename, "a",TEXT_MODE)) == nil(FILE))
{
printf("Cannot append to %s\n", filename);
return FALSE;
} /* if */
CopyMsg(item, stream, headers, FALSE);
fclose(stream);
/*--------------------------------------------------------------------*/
/* Delete the message if required */
/*--------------------------------------------------------------------*/
if (letters[item].status < M_DELETED)
letters[item].status = delete ? M_DELETED : M_SAVED;
return TRUE;
} /* SaveItem */
/*--------------------------------------------------------------------*/
/* P o s i t i o n */
/* */
/* Makes reasonable choice of next letter to examine */
/*--------------------------------------------------------------------*/
int Position(int absolute, int relative, int start)
{
int current = start;
/*--------------------------------------------------------------------*/
/* Explicitly position the letter */
/*--------------------------------------------------------------------*/
if ( absolute )
{
current = absolute ;
if (( current <= letternum ) && (current > 0))
return current - 1;
else if ( current >= letternum )
printf("Item %d does not exist, last item in mailbox is %d\n",
current , letternum);
else
printf("Cannot backup beyond top of mailbox\n");
return start;
} /* if */
/*--------------------------------------------------------------------*/
/* Position the pionter relative to current item */
/*--------------------------------------------------------------------*/
if ( relative )
{
int move ;
move = (relative > 0) ? 1 : -1;
if ( (current + move) == letternum )
{
printf("At end of mailbox\n");
return current;
}
while ( relative )
{
current += move;
if ( current >= letternum )
{
printf("Item %d does not exist, last item in mailbox is %d\n",
current+relative, letternum);
return start;
}
else if ( current < 0 )
{
printf("Cannot backup beyond top of mailbox\n");
return start;
}
else if (letters[current].status != M_DELETED)
relative -= move;
} /* while */
return current;
} /* if */
/*--------------------------------------------------------------------*/
/* Implicitly position the letter */
/*--------------------------------------------------------------------*/
while (current < letternum)
{
if (letters[current].status != M_DELETED)
return current;
else
++current;
} /* while */
current = start;
while (current-- > 0)
if (letters[current].status != M_DELETED)
return current;
printf("At end of mailbox\n");
return start;
} /* Position */
/*--------------------------------------------------------------------*/
/* D e l i v e r M a i l */
/* */
/* Compose interactive outgoing mail */
/*--------------------------------------------------------------------*/
boolean DeliverMail( char *addresses , int item)
{
char *Largv[MAXADDRS];
int Largc;
Largc = getargs(addresses , Largv );
return Collect_Mail(stdin, Largc , Largv, item , FALSE);
} /* DeliverMail */
/*--------------------------------------------------------------------*/
/* R e p l y */
/* */
/* Reply to incoming mail */
/*--------------------------------------------------------------------*/
boolean Reply( const int current )
{
char *Largv[MAXADDRS];
char subject[LSIZE];
char addr[LSIZE];
char line[LSIZE];
char *column;
int Largc = 0;
subject[0] = '\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -