⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailsend.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------*/
/*    m a i l s e n d . c                                             */
/*                                                                    */
/*    Subroutines for sending mail for UUPC/extended                  */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*       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: mailsend.c 1.6 1993/10/04 03:57:20 ahd Exp $
 *
 *    Revision history:
 *    $Log: mailsend.c $
 * Revision 1.6  1993/10/04  03:57:20  ahd
 * Clarify error message
 *
 * Revision 1.5  1993/08/02  03:24:59  ahd
 * Further changes in support of Robert Denny's Windows 3.x support
 *
 * Revision 1.4  1993/07/31  16:26:01  ahd
 * Changes in support of Robert Denny's Windows support
 *
 */

/*--------------------------------------------------------------------*/
/*                        System include files                        */
/*--------------------------------------------------------------------*/

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

/*--------------------------------------------------------------------*/
/*                    UUPC/extended include files                     */
/*--------------------------------------------------------------------*/

#include "lib.h"

#include "arpadate.h"
#include "expath.h"
#include "execute.h"
#include "hlib.h"
#include "mlib.h"
#include "alias.h"
#include "mail.h"
#include "maillib.h"
#include "mailblib.h"
#include "mailsend.h"
#include "safeio.h"
#include "address.h"

/*--------------------------------------------------------------------*/
/*                     Local function prototypes                      */
/*--------------------------------------------------------------------*/

 static char *ExplodeAlias(char *header ,
                      const char *alias,
                      FILE *stream,
                      const boolean resent);


 static void PutHead( const char *label,
                      const char *operand,
                      FILE *stream,
                      const boolean resent);

 static boolean Append_Signature(FILE *mailbag,
                     const boolean alternate);

 static void Prompt_Input( char *tmailbag,
                          FILE *fmailbag,
                           char *subject,
                          const int current);

 static boolean Subcommand( char *buf,
                           FILE *fmailbag,
                           char *tmailbag,
                           char *subject,
                           const int current_msg);

 static void CopyOut( const char* input);

 static void filter( char *tmailbag, char *command);

 static char *GetString( char *input);

currentfile();                /* Define current file for panic()     */

/*--------------------------------------------------------------------*/
/*    E x p l o d e A l i a s                                         */
/*                                                                    */
/*    Resolves an alias, exploding it into a list if needed.          */
/*--------------------------------------------------------------------*/

 static char *ExplodeAlias(char *header ,
                      const char *alias,
                      FILE *stream,
                      const boolean resent)
{
   char *fullname;
   char buffer[LSIZE];

   if ((alias == NULL) || (strlen(alias) == 0))
   {
      printmsg(0,"ExplodeAlias: NULL or empty string for argument");
      panic();
   }

   fullname = AliasByNick(alias);

   printmsg(4,"Processing alias '%s', result '%s'", alias,
      (fullname == NULL) ? alias : fullname);

   if (fullname == NULL)            /* No alias found for user?     */
   {                                /* No --> Try node lookup       */
      char user[MAXADDR];
      char node[MAXADDR];
      char path[MAXADDR];
      char bucket[MAXADDR];

      ExtractAddress(bucket, (char *) alias, FALSE);
      user_at_node(bucket, path, node, user);
      fullname = AliasByAddr( node, user);

      if (fullname == NULL)         /* Did we come up empty?         */
      {
         char *hisuser, *hisnode;

         hisuser = strtok( bucket, "@");
         hisnode = strtok( NULL, "@");
         if ((*bucket != '@') &&
             equal(hisuser, user ) && (hisnode != NULL) &&
             equal(hisnode, node ) && (strchr( node, '.') == NULL))
         {
            if (equal(hisnode, E_nodename))
               strcpy(node, E_fdomain);
            else {
               strcat(node,".");
               strcat(node,E_localdomain);
            }

            ExtractAddress(path, (char *) alias, TRUE);
            if (strlen( path ) == 0)
               sprintf(buffer,"%s@%s", hisuser, node );
            else
               sprintf(buffer,"\"%s\" <%s@%s>", path, hisuser, node);
            fullname = buffer;
         }
         else
            fullname = (char *) alias; /* Use original information      */
      }
   }
   else {
      ExtractAddress(buffer,fullname,TRUE);
      if (strlen(buffer) == 0)      /* A list of users?              */
      {                             /* Yes --> Do recursive call     */
         char *current = buffer;    /* Current token being processed */
         char *next = NULL;         /* Next token to process         */

         strcpy(buffer,fullname);

         do {
            current = strtok(current,",\t "); /* Get next alias to process */
            next    = strtok(NULL,"");    /* Also save rest of list        */
            header  = ExplodeAlias( header , current, stream, resent);
                                          /* Get alias, including sub-list */
            current  = next;
         } while ( next != NULL );        /* Until no more tokens exist    */

         return header;                   /* Have written header, return   */

      } /* if */
   } /* else */

   if (strpbrk(fullname,"!@") == nil(char))
   {
      sprintf(buffer,"%s@%s", fullname , E_fdomain);
                              /* Local address                    */
      fullname = buffer;      /* Write out the formatted address  */
   }

   PutHead(header, fullname, stream, resent);
                              /* Remote address                   */
   return "";                 /* Make header empty string for
                                 next caller                      */
} /* ExplodeAlias */

/*--------------------------------------------------------------------*/
/*    A p p e n d _ S i g n a t u r e                                 */
/*                                                                    */
/*    Append the signature file to the specified mailbag file         */
/*                                                                    */
/*    [Broke this code out from Send_Mail to support the ~a mail      */
/*    subcommand]                                                     */
/*                                                                    */
/*    Returns:  0 on success, 1 if signature file not found           */
/*--------------------------------------------------------------------*/

static boolean Append_Signature(FILE *mailbag_fp ,
                     const boolean alternate)
{
   FILE *sigfp;
   char *sig;
   char sigfile[FILENAME_MAX];
   char buf[BUFSIZ];

   sig = alternate ? E_altsignature : E_signature;

   if(sig != nil(char)) {
      mkfilename(sigfile, E_homedir, sig);
      printmsg(4, "Append_Signature: signature file %s", sigfile);
      if ((sigfp = FOPEN(sigfile, "r",TEXT_MODE)) != nil(FILE)) {
         fputs("-- \n", mailbag_fp);
         while (fgets(buf, BUFSIZ, sigfp) != nil(char))
            fputs(buf, mailbag_fp);
         fclose(sigfp);
         return(0);
      }
      else {
         printmsg(0, "Signature file \"%s\" doesn't exist!\n", sigfile);
         return(1);
      }
   }
   return(0);
}  /* Append_Signature */

/*--------------------------------------------------------------------*/
/*    S e n d _ M a i l                                               */
/*                                                                    */
/*    Send text in a mailbag file to address(es) specified by line.   */
/*--------------------------------------------------------------------*/

boolean Send_Mail(FILE *datain,
               int argc,
               char *argv[],
               char *subject,
               const boolean resent)
{
   int argx = 0;
   char buf[LSIZE];
   char *header    = "To:";
   char *CcHeader  = "Cc:";
   char *BccHeader = "Bcc:";
   char *pipename  = mktempname(NULL, "TMP");
   FILE *stream = FOPEN(pipename , "w",TEXT_MODE);
   int status;

/*--------------------------------------------------------------------*/
/*                     Verify our workfile opened                     */
/*--------------------------------------------------------------------*/

   if ( stream == NULL )
   {
      printerr(pipename);
      free(pipename);
      return FALSE;
   }

/*--------------------------------------------------------------------*/
/*    Add the boilerplate the front:                                  */
/*                                                                    */
/*       Date, From, Organization, and Reply-To                       */
/*--------------------------------------------------------------------*/

   PutHead("Date:", arpadate() , stream, resent);

   if (bflag[F_BANG])
      sprintf(buf, "(%s) %s!%s", E_name, E_fdomain, E_mailbox );
   else
      sprintf(buf, "\"%s\" <%s@%s>", E_name, E_mailbox, E_fdomain );
   PutHead("From:", buf, stream , resent);

   if (E_organization != NULL )
      PutHead("Organization:", E_organization, stream, resent );

   if (E_replyto != NULL )
   {
      if (strpbrk(E_replyto,"!@") == nil(char))
         sprintf(buf,"\"%s\" <%s@%s>", E_name, E_replyto , E_fdomain);
      else
         sprintf(buf,"\"%s\" <%s>", E_name, E_replyto);
      PutHead("Reply-To:", buf, stream, resent );
   }

/*--------------------------------------------------------------------*/
/*                      Write the addressees out                      */
/*--------------------------------------------------------------------*/

   for (argx = 0 ; argx < argc; argx++ )
   {
      if (equal(argv[argx],"-c"))
      {
         header = CcHeader;
         CcHeader = "";
      } /* if */
      else if (equal(argv[argx],"-b"))
      {
         header = BccHeader;
         CcHeader = BccHeader = "";
      } /* if else */
      else
         header = ExplodeAlias( header , argv[argx], stream, resent);
   } /* for */

/*--------------------------------------------------------------------*/
/*                  Prompt for carbon copies, if any                  */
/*--------------------------------------------------------------------*/

   if ( bflag[F_ASKCC] && Is_Console(stdin) &&
        Console_fgets(buf,LSIZE,"Cc: "))
   {
      char *current = buf;
      header = CcHeader;
      CcHeader = "";
      printmsg(4,"CC buffer: %s",current);

      while ((current != NULL) &&
             (current = strtok(current,",\t\n ")) != NULL)
      {
         char *next  =  strtok(NULL,"");
         if (equal(current,"-b"))
         {
            header = BccHeader;
            CcHeader = BccHeader = "";
         } /* if */
         else
            header = ExplodeAlias( header, current, stream, resent);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -