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

📄 rmail.c

📁 由3926个源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
      rnode = bflag[F_BANG] ? E_nodename : E_fdomain;
                              /* Use full domain address, if possible */
   else
      rnode = fromnode;

   uuser = ruser = fromuser;  /* User and requestor always the same
                                 for locally generated mail          */

/*--------------------------------------------------------------------*/
/*                       Generate a message-id                        */
/*--------------------------------------------------------------------*/

   sprintf(buf, "<%lx.%s@%s>", time( NULL ) , E_nodename, E_domain);
   PutHead("Message-ID:", buf, dataout , offset == 0 );
   PutHead(NULL, NULL, dataout , FALSE );

/*--------------------------------------------------------------------*/
/*                 Locate the To: or Resent-To: line                  */
/*--------------------------------------------------------------------*/

   tolen =    strlen( &to[offset] );

   do {
      if (fgets( buf, BUFSIZ, datain ) == NULL)  /* End of file?     */
         return NULL;         /* Yes --> Very bad, report error      */
      fputs(buf, dataout );
      if (*buf == '\n')       /* End of the header?                  */
         return NULL;         /* Yes --> Very bad, report error      */
      else if (equalni(received, buf, receivedlen))
         hops++;
   } while ( !equalni(&to[offset] , buf , tolen ));

   token = strpbrk( buf ," \t");

/*--------------------------------------------------------------------*/
/*                Proccess the rest of the addressees                 */
/*--------------------------------------------------------------------*/

   cclen =    strlen( &cc[offset] );
   bcclen =   strlen( &bcc[offset] );

   do {
      if (allocated == (*count+1))  /* Do we have room for addr?     */
      {
         allocated += allocated / 2;   /* Choose larger array size   */
         addrlist = realloc( addrlist ,
                             allocated * sizeof( *addrlist ));
         checkref(addrlist);  /* Verify the allocation worked        */
      } /* if */

      ExtractAddress( address, token, FALSE );  /* Get address itself*/
      if (!strlen(address))
      {
         printmsg(0,"Could not locate expected address in header");
         *count = 0;
         return NULL;
      } /* if */
      else {
         addrlist[*count] = newstr( address );
                              /* Save permanent copy of address      */
         checkref( addrlist[*count] ); /* Verify strdup worked       */
         printmsg(4,"address[%d]= \"%s\"",*count, address);
         *count += 1;         /* Flag we got the address             */
      } /* else */

      if (fgets( buf, BUFSIZ, datain ) == NULL) /* End of file?      */
         token = NULL;        /* Yes --> Odd, but no major problem   */
      else if (*buf == '\n')  /* End of the header?                  */
      {
         token = NULL;        /* Yes --> Exit loop                   */
         *header = FALSE;     /* Report to caller the header is done */
         blind = FALSE;       /* Denote not a blind header           */
      }
      else if (isspace(*buf)) /* Another address?                    */
         token = buf;         /* Yes --> Write it out                */
      else {                  /* No --> Determine what next header is*/
         blind = FALSE;       /* Assume not a blind header           */
         if (equalni(&cc[offset], buf, cclen))   /* Cc: header?       */
            token = strpbrk(buf," \t");
         else if (equalni(&bcc[offset], buf, bcclen))  /* Bcc: header?*/
         {
            token = strpbrk(buf ," \t");
            blind = TRUE;
         } /* if */
         else                 /* Unsupported header, exit loop       */
            token = NULL;
      } /* else */
      if ( ! blind )
         fputs(buf, dataout );
   } while (token != NULL );

/*--------------------------------------------------------------------*/
/*                   Return address list to caller                    */
/*--------------------------------------------------------------------*/

   return addrlist;

} /* Parse822 */

/*--------------------------------------------------------------------*/
/*    C o p y T e m p                                                 */
/*                                                                    */
/*    Copy the un-parsed parts of a message into the holding file     */
/*--------------------------------------------------------------------*/

static boolean CopyTemp( void )
{
   boolean header = TRUE;
   char buf[BUFSIZ];
   boolean newline = TRUE;

   while (fgets(buf, BUFSIZ, datain) != NULL)
   {
      if (header)
      {
         if (*buf == '\n')
            header = FALSE;
         else if (equalni(received, buf, receivedlen))
            hops++;
      }

      newline = buf[ strlen( buf ) - 1 ] == '\n';

      if (fputs(buf, dataout) == EOF)  /* I/O error?                 */
      {
         printerr(tempname);
         printmsg(0,"I/O error on \"%s\"", tempname);
         fclose(dataout);
         return FALSE;
      } /* if */
   } /* while */

   if (ferror(datain))        /* Clean end of file on input?         */
   {
      printerr(namein);
      Terminate(7);
   }

   if ( !newline )            /* Is the file terminated properly?    */
   {
      printmsg(0, "rmail: Improperly formed message, adding final newline!");
      fputc( '\n', dataout );
   }

   return header;
}  /* CopyTemp */

/*--------------------------------------------------------------------*/
/*    D a e m o n M a i l                                             */
/*                                                                    */
/*    Send text in a mailbag file to address(es) specified by address */
/*--------------------------------------------------------------------*/

static boolean DaemonMail( const char *subject,
                          char **address,
                          int count )
{
   char buf[BUFSIZ];
   char *logname;
   char *token;
   char *moi = NULL;
   struct UserTable *userp;
   char *header = "To:";
   char *cc     = "Cc:";
   boolean print = TRUE;

/*--------------------------------------------------------------------*/
/*                         Validate the input                         */
/*--------------------------------------------------------------------*/

   if ( count == 0 )
   {
      printmsg(0,"rmail: No addresseses to deliver to!");
      return FALSE;
   }

/*--------------------------------------------------------------------*/
/*                       Determine our user id                        */
/*--------------------------------------------------------------------*/

   logname = getenv( LOGNAME );
   if ( logname == NULL )
      logname = E_mailbox;

/*--------------------------------------------------------------------*/
/*              Get the name of the user, or make one up              */
/*--------------------------------------------------------------------*/

   userp = checkuser(logname);   /* Locate user id in host table     */

   if ( (userp != BADUSER) &&
        (userp->realname != NULL) &&
         !equal(userp->realname, EMPTY_GCOS ))
      moi = userp->realname;
   else if ( equali(logname, E_postmaster) || equali(logname, POSTMASTER))
      moi = "Postmaster";
   else if ( equali( logname, "uucp" ))
      moi = "Unix to Unix Copy";
   else
      moi = logname;          /* Dummy to ease formatting From: line  */

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

   fprintf(dataout,"%-10s by %s (%s %s);\n%-10s %s\n",
              "Received:",E_domain,compilep, compilev,
              " ", now );

/*--------------------------------------------------------------------*/
/*                       Generate a message-id                        */
/*--------------------------------------------------------------------*/

   sprintf(buf, "<%lx.%s@%s>", time( NULL ) , E_nodename, E_domain);
   PutHead("Message-ID:", buf, dataout , FALSE );
   PutHead(NULL, NULL, dataout , FALSE );

   PutHead("Date:", arpadate() , dataout, FALSE);

   if (bflag[F_BANG])
      sprintf(buf, "(%s) %s!%s", moi, E_nodename, logname );
   else {
      checkname( E_nodename );  /* Force loading of the E_fdomain name */
      sprintf(buf, "\"%s\" <%s@%s>", moi, logname , E_fdomain );
   }

   PutHead("From:", buf, dataout, FALSE );

   if (E_organization != NULL )
      PutHead("Organization:", E_organization, dataout, FALSE);

/*--------------------------------------------------------------------*/
/*                      Write the address out                         */
/*--------------------------------------------------------------------*/

   while( (count-- > 0) && print )
   {
      token = *address++;
      if ( *token == '-')  /* Option flag?                        */
      {
         if (token[1] == 'c')
         {
            header = cc;
            cc = "";
         }
         else if (token[1] == 'b')
            print = FALSE;
         else
            printmsg(0,"rmail: Invalid flag \"%s\" ignored!", token);
      } /* if ( token == '-') */
      else if ( print )
      {
         if (strpbrk(token,"!@") == nil(char))
         {
            if (bflag[F_BANG])
               sprintf(buf, "%s!%s", E_nodename, token );
            else
               sprintf(buf, "%s@%s", token , E_fdomain );
            token = buf;
         }

         PutHead(header , token, dataout, FALSE);
         header = "";         /* Continue same field by default      */
      }
   } /* while( (count-- > 0) && print ) */

/*--------------------------------------------------------------------*/
/*                     Handle the subject, if any                     */
/*--------------------------------------------------------------------*/

   if (subject != NULL)
      PutHead("Subject:", subject, dataout, FALSE);

   PutHead(NULL, "", dataout, FALSE);  /* Terminate the header line   */
   PutHead(NULL, "", dataout, FALSE);  /* Terminate the header file   */

/*--------------------------------------------------------------------*/
/*                          Return to caller                          */
/*--------------------------------------------------------------------*/

   uuser = ruser = strncpy(fromuser, logname, sizeof fromuser);
                              /* Define user for UUCP From line      */
   fromuser[ sizeof fromuser - 1 ] = '\0';
   rnode = bflag[F_BANG] ? E_nodename : E_fdomain;
                              /* Use full domain address, if possible */

   strcpy(fromnode, E_nodename);/* Declare as local system           */
   return TRUE;

} /*DaemonMail*/

/*--------------------------------------------------------------------*/
/*    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 (label == NULL )        /* Terminate call?                     */
   {                          /* Yes --> Reset Flag and return       */
      fputc('\n', stream);    /* Terminate the current line          */
      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 */

/*--------------------------------------------------------------------*/
/*    u s a g e                                                       */
/*                                                                    */
/*    Report how the program works                                    */
/*--------------------------------------------------------------------*/

 static void usage( void )
 {

   static char syntax[] =
      "Usage:\tRMAIL\t-t [-x debug] [-f | -F file]\n"
      "\t\t-w [-x debug] [-f | -F file] [-s subject] addr1 [-c] addr2  [-b] addr3 ...\n"
      "\t\t[-x debug] [-f | -F file] addr1 addr2 addr3 ...\n";

   puts( syntax );
   exit(99);
 }

⌨️ 快捷键说明

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