📄 mailsend.c
字号:
current = next;
} /* while */
} /* If Console_fgets() */
/*--------------------------------------------------------------------*/
/* Handle the subject, if any */
/*--------------------------------------------------------------------*/
if (subject != NULL)
PutHead("Subject:",subject, stream, resent);
PutHead(NULL, "", stream, resent); /* Terminate the header file */
/*--------------------------------------------------------------------*/
/* Copy the body of the message */
/*--------------------------------------------------------------------*/
while (fgets(buf, LSIZE, datain) != nil(char))
{
int result = fputs(buf, stream );
if (result == EOF)
{
printerr( pipename );
panic();
} /* if */
if (buf[strlen(buf)-1] != '\n')
fputc('\n', stream);
} /* while */
if (!feof(datain))
{
printerr("Send_Mail:");
panic();
} /* if */
if (datain != stdin)
fclose(datain);
/*--------------------------------------------------------------------*/
/* Append user's primary signature file, if autosign option on */
/*--------------------------------------------------------------------*/
if ( bflag[F_AUTOSIGN] )
Append_Signature(stream, FALSE);
fclose(stream);
/*--------------------------------------------------------------------*/
/* Invoke the mail delivery program */
/*--------------------------------------------------------------------*/
sprintf(buf, "-t -f %s", pipename);
status = execute(RMAIL, buf, NULL, NULL, TRUE, FALSE );
if ( status < 0 )
{
printerr( RMAIL );
printmsg(0,"Unable to execute rmail; mail not delivered.");
}
else if ( status > 0 )
printmsg(0,
"rmail returned non-zero status; delivery may be incomplete.");
/*--------------------------------------------------------------------*/
/* Log a copy of the mail for the sender */
/*--------------------------------------------------------------------*/
if (bflag[F_SAVERESENT] || ! resent)
CopyOut(pipename);
/*--------------------------------------------------------------------*/
/* Clean up and return to caller */
/*--------------------------------------------------------------------*/
remove(pipename);
free(pipename);
return (status == 0 );
} /*Send_Mail*/
/*--------------------------------------------------------------------*/
/* C o p y O u t */
/* */
/* Save copy of outgoing mail, if desired */
/*--------------------------------------------------------------------*/
static void CopyOut( const char* input)
{
FILE *datain;
FILE *dataout;
char buf[BUFSIZ];
char outbox[FILENAME_MAX];
if (E_filesent == NULL)
return;
strcpy( outbox, E_filesent);
expand_path( outbox, E_homedir, E_homedir, E_mailext );
datain = FOPEN( input, "r",TEXT_MODE);
if (datain == NULL )
{
printerr(input);
panic();
} /* if */
dataout = FOPEN( outbox, "a",TEXT_MODE);
if (dataout == NULL )
{
printerr( outbox );
panic();
} /* if */
fputs(MESSAGESEP,dataout);
while (fgets(buf, BUFSIZ, datain) != nil(char))
{
int result = fputs(buf, dataout);
if (result == EOF)
{
printerr( outbox );
panic();
} /* if */
} /* while */
if (!feof(datain))
{
printerr(input);
panic();
} /* if */
fclose(datain);
fclose(dataout);
} /* CopyOut */
/*--------------------------------------------------------------------*/
/* P u t H e a d */
/* */
/* Write one line of an RFC-822 header */
/*--------------------------------------------------------------------*/
static void PutHead( const char *label,
const char *operand,
FILE *stream,
const boolean resent)
{
static boolean terminate = TRUE;
/* If previous line was terminated */
if (label == NULL ) /* Terminate call? */
{ /* Yes --> Reset Flag and return */
fputc('\n', stream); /* Terminate the current line */
if (!resent)
fputc('\n', stream); /* Terminate the header file */
terminate = TRUE;
return;
} /* if */
if (strlen(label)) /* First line of a header? */
{
if (!terminate) /* Terminate previous line? */
fputc('\n', stream);
if (resent)
fprintf(stream,"Resent-%s %s",label, operand);
else
fprintf(stream,"%-10s %s",label, operand);
terminate = FALSE; /* Flag that we did not end file */
} /* if */
else /* Continuing line */
fprintf(stream,",\n%-10s %s",label, operand);
} /* PutHead */
/*--------------------------------------------------------------------*/
/* C o l l e c t _ M a i l */
/* */
/* Create mailbox file for delivery */
/*--------------------------------------------------------------------*/
boolean Collect_Mail(FILE *stream,
int argc,
char **argv,
const int current_msg,
const boolean reply)
{
boolean editonly = FALSE;
char Subuffer[LSIZE];
char *subject = NULL;
char *tmailbag;
int c; /* Really a 'char', but who cares? */
boolean done = FALSE;
FILE *fmailbag;
/*--------------------------------------------------------------------*/
/* Determine if we are running interactively; if not, just */
/* pass the input stream to Send_Mail for processing */
/*--------------------------------------------------------------------*/
if (!Is_Console(stream))
{
if ( equal(argv[0], "-s" ) )
return Send_Mail( stream, argc-2, argv+2, argv[1], FALSE);
else
return Send_Mail( stream , argc , argv, NULL , FALSE);
} /* if */
/*--------------------------------------------------------------------*/
/* We are running interactively; create a determine the name of */
/* our work file to be. */
/*--------------------------------------------------------------------*/
*Subuffer = '\0'; /* Assume no subject */
tmailbag = mktempname( NULL, "TXT");
/*--------------------------------------------------------------------*/
/* Determine if we should go straight into the editor */
/*--------------------------------------------------------------------*/
editonly = bflag[F_AUTOEDIT] && (E_editor != NULL);
if ( equal(argv[0],"-s")) /* Any subject specified? */
{
strcpy( Subuffer , argv[1] ); /* Save the subject for later */
argv += 2; /* Skip over it in argument list */
argc -= 2; /* Giving us fewer args left */
}
else { /* No --> Prompt for one */
if(Console_fgets(Subuffer,LSIZE,"Subject: "))
{
if (Subuffer[strlen(Subuffer) - 1 ] == '\n')
Subuffer[strlen(Subuffer)-1] = '\0'; /* End the subject */
} /* If Console_fgets() */
} /* if ( equal(argv[0],"-s")) */
/*--------------------------------------------------------------------*/
/* Copy a message from the original input to temporary file */
/*--------------------------------------------------------------------*/
fmailbag = FOPEN(tmailbag, "w",TEXT_MODE);
if (fmailbag == NULL )
{
printerr( tmailbag );
panic();
}
/*--------------------------------------------------------------------*/
/* Include incoming message if requested */
/*--------------------------------------------------------------------*/
if ( bflag[F_AUTOINCLUDE] && reply)
{
CopyMsg(current_msg, fmailbag, fromheader , TRUE);
fprintf(stdout, "Message %d Included\n", current_msg+1);
} /* if ( bflag[F_AUTOINCLUDE] && reply) */
/*--------------------------------------------------------------------*/
/* Edit the file if requested */
/*--------------------------------------------------------------------*/
if (editonly) /* Enter editor immediately? ahd */
{ /* Yes --> Go to it */
fclose(fmailbag);
Invoke(E_editor, tmailbag);
} /* if */
else { /* No --> prompt for data ahd */
Prompt_Input( tmailbag , fmailbag , Subuffer, current_msg );
fclose(fmailbag);
} /*else */
do {
fputs("\nAbort, Continue, Edit, List, or Send? ",stdout);
c = Get_One(); /* adaptation for QuickC */ /* pdm */
switch (tolower( c ))
{
case 'c':
puts("Continue");
fmailbag = FOPEN(tmailbag, "a",TEXT_MODE);
Prompt_Input( tmailbag , fmailbag , Subuffer, current_msg );
#if defined(_Windows)
//
// Prompt_Input() comes back with EOF on stdin!
//
rewind(stdin);
#endif
fclose(fmailbag);
break;
case 'l':
puts("List");
Sub_Pager(tmailbag, islower(c) );
break;
case 's':
puts("Send");
fmailbag = FOPEN(tmailbag, "r",TEXT_MODE);
if (fmailbag == NULL )
{
printerr(tmailbag);
panic();
}
if ( strlen( Subuffer ))
subject = Subuffer;
Send_Mail(fmailbag, argc, argv, subject, FALSE);
done = TRUE;
break;
case 'e':
puts("Edit");
Invoke(E_editor, tmailbag);
break;
case 'a':
fputs("Abort\nAre you sure? ", stdout);
safeflush();
c = Get_One(); /* for QuickC */ /* pdm */
switch (tolower(c)) { /* unravel these two calls */
case 'y':
puts("Yes");
done = TRUE;
break;
default:
puts("No");
} /*switch*/
break;
default:
puts("\n\aEnter A, C, E, L, or S.");
safeflush();
done = FALSE;
} /*switch*/
} while (!done);
remove(tmailbag);
free(tmailbag);
return TRUE;
} /*Collect_Mail*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -