📄 mailsend.c
字号:
/*--------------------------------------------------------------------*/
/* P r o m p t _ I n p u t */
/* */
/* Prompt for mail entry interactively. */
/*--------------------------------------------------------------------*/
static void Prompt_Input( char *tmailbag,
FILE *fmailbag,
char *subject,
const int current_msg)
{
char buf[LSIZE];
printf("\nEnter message. Enter ~? for help. End input with %s\n",
bflag[ F_DOT ] ? "a period (.)" :
"end-of-file (Control-Z)");
for ( ; ; )
{
if (Console_fgets(buf, LSIZE, "? "))
{
if (bflag[F_DOT] && equal(buf,".\n"))
break;
else if (Subcommand( buf, fmailbag, tmailbag, subject, current_msg) )
continue; /*Don't write line out if subcommand */
} /* if */
else
break; /* Exit loop if end of file */
if (fputs(buf, fmailbag) == EOF )
{
printerr( tmailbag );
panic();
} /* if (fputs(buf, fmailbag) == EOF ) */
if (buf[strlen(buf)-1] != '\n')
fputc('\n', fmailbag);
} /* for */
} /* Prompt_Input */
/*--------------------------------------------------------------------*/
/* S u b c o m m a n d */
/* */
/* Handle tilde (~) subcommands for Interactive mail */
/*--------------------------------------------------------------------*/
static boolean Subcommand( char *buf,
FILE *fmailbag,
char *tmailbag,
char *subject,
const int current_msg)
{
int message;
char fname[FILENAME_MAX];
char *token;
FILE *stream;
if(*buf == '~') /* Handle mail subcommands pdm */
{
switch(buf[1])
{
/*--------------------------------------------------------------------*/
/* Treat as normal data line */
/*--------------------------------------------------------------------*/
case '~':
memmove( buf, buf + 1, strlen( buf + 1 ));
return FALSE; // Treat as normal line
/*--------------------------------------------------------------------*/
/* Put signature file into current message */
/*--------------------------------------------------------------------*/
case 'a':
case 'A':
Append_Signature(fmailbag, isupper( buf[1] ));
fputs("(continue)\n", stdout);
break;
/*--------------------------------------------------------------------*/
/* Edit outgoing message */
/*--------------------------------------------------------------------*/
case 'v': /* UNIX allows 'v'isual editor */
case 'e':
/* invoke editor with current msg */
fclose(fmailbag);
Invoke(E_editor, tmailbag);
fmailbag = FOPEN(tmailbag, "a",TEXT_MODE);
fputs("(continue)\n", stdout);
break;
/*--------------------------------------------------------------------*/
/* Include any letter in this message */
/*--------------------------------------------------------------------*/
case 'f':
case 'F':
case 'i':
case 'I':
case 'm':
case 'M':
if (fmailbox == NULL)
puts("Mailbox not accessible!");
else {
int *item_list;
int next_item = PushItemList( &item_list );
boolean first_pass = TRUE;
token = GetString( &buf[2] );
if (SelectItems( &token, current_msg, LETTER_OP ))
while( Get_Operand( &message, &token, LETTER_OP, first_pass))
{
CopyMsg( message , fmailbag,
islower(buf[1]) ? fromheader : noseperator ,
tolower(buf[1]) != 'f');
fprintf(stdout, "Message %d included\n", message + 1);
first_pass = FALSE;
} /* while */
PopItemList( item_list, next_item );
} /* else */
break;
/*--------------------------------------------------------------------*/
/* Print current message */
/*--------------------------------------------------------------------*/
case 'p':
case 'P':
fclose(fmailbag);
Sub_Pager(tmailbag, islower(buf[1]) );
fmailbag = FOPEN(tmailbag, "a",TEXT_MODE);
fputs("(continue)\n", stdout);
break;
/*--------------------------------------------------------------------*/
/* Include a file */
/*--------------------------------------------------------------------*/
case 'r':
token = strtok( &buf[2], " \t\n");
if ( token == NULL )
{
printf("Need a file name for this command!\n");
break;
}
strcpy( fname, token );
if ( expand_path( fname, NULL, E_homedir , NULL) == NULL )
break;
stream = FOPEN( fname, "r",TEXT_MODE);
if (stream == NULL )
{
printerr(fname);
break;
}
else while( fgets( buf, LSIZE, stream ))
{
fputs( buf, fmailbag);
if ferror( fmailbag )
{
printerr( tmailbag);
break;
} /* if */
} /* else while */
if (ferror( stream ) )
{
printerr( fname );
clearerr( stream );
} /* if */
fclose( stream );
fputs("(continue)\n", stdout);
break;
/*--------------------------------------------------------------------*/
/* Change mail subject */
/*--------------------------------------------------------------------*/
case 's':
token = GetString( &buf[2] );
if ( token != NULL )
{
strcpy( subject, token );
}
else
printf("No new subject, command ignored\n");
printf("Subject: %s\n",subject);
break;
/*--------------------------------------------------------------------*/
/* Help */
/*--------------------------------------------------------------------*/
case '?':
{
mkfilename(fname, E_confdir, "tilde.hlp");
Sub_Pager( fname, TRUE );
break;
}
/*--------------------------------------------------------------------*/
/* A subshell */
/*--------------------------------------------------------------------*/
case '!':
token = strtok( &buf[2], "\n");
subshell( token );
break;
/*--------------------------------------------------------------------*/
/* Pipe mail through a filter */
/*--------------------------------------------------------------------*/
case '|':
fclose( fmailbag );
filter( tmailbag, &buf[2] );
fmailbag = FOPEN(tmailbag, "a",TEXT_MODE);
fputs("(continue)\n", stdout);
break;
/*--------------------------------------------------------------------*/
/* Invalid command */
/*--------------------------------------------------------------------*/
default:
fputs("Unknown mail subcommand, ~? for help.\n",
stdout);
break;
} /* switch */
return TRUE;
} /* if */
else
return FALSE; /* It wasn't a sub-command */
} /*SubCommand*/
/*--------------------------------------------------------------------*/
/* f i l t e r */
/* */
/* Filter the next of an outgoing program into the output mail */
/*--------------------------------------------------------------------*/
static void filter( char *tmailbag, char *command)
{
char pipename[FILENAME_MAX];
struct stat statbuf;
int result = 0;
command = GetString( command );
if ( command == NULL )
{
printf("No command given for filter");
return;
}
/*--------------------------------------------------------------------*/
/* Set up our standard input and standard output for the command */
/*--------------------------------------------------------------------*/
mktempname(pipename, "TMP");
/*--------------------------------------------------------------------*/
/* Run the command */
/*--------------------------------------------------------------------*/
result = executeCommand( command, tmailbag, pipename, TRUE, TRUE );
if (result == -1) /* Did spawn fail? */
; /* No operation */
else if( stat( pipename, &statbuf) <0 ) /* Create output? */
{
printf(0,"Cannot determine status of output %s",pipename);
printerr( pipename );
}
else if( statbuf.st_size == 0 ) /* Anything in the file? */
printf("Output file %s is empty!\n", pipename);
else { /* Good output, replace input file */
remove( tmailbag );
if (rename( pipename, tmailbag ))
printerr( pipename );
} /* else */
/*--------------------------------------------------------------------*/
/* Clean up and return to caller */
/*--------------------------------------------------------------------*/
remove( pipename );
} /* filter */
/*--------------------------------------------------------------------*/
/* G e t S t r i n g */
/* */
/* Get non-whitespace in a string */
/*--------------------------------------------------------------------*/
static char *GetString( char *input)
{
char *end;
/*--------------------------------------------------------------------*/
/* Look for first data in string */
/*--------------------------------------------------------------------*/
while( *input && !isgraph( *input ))
input++ ;
/*--------------------------------------------------------------------*/
/* If no input or all blanks, return NULL to denote empty string */
/*--------------------------------------------------------------------*/
if (*input == '\0')
return NULL ;
/*--------------------------------------------------------------------*/
/* Delete whitespace from end of string */
/*--------------------------------------------------------------------*/
end = input + strlen( input ) - 1;
while (!isgraph(*end))
end--;
end[1] = '\0';
/*--------------------------------------------------------------------*/
/* Return beginning of string to caller */
/*--------------------------------------------------------------------*/
return input;
} /* GetString */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -