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

📄 mail.c

📁 由3926个源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
         break;

      case 'u':                  /* Read alternate mailbox?       */
         readmail = TRUE;
         mkmailbox(mfilename, optarg);
         postoffice = FALSE;
         break;

      case 'x':
         debuglevel = atoi(optarg);
         break;

      case 's':
         sendmail = TRUE;
         subject = optarg;
         break;

      case 't':
         readmail = TRUE;
         useto = ! useto;
         break;

      case '?':
         usage();

      } /* switch */

   } /* while */

/*--------------------------------------------------------------------*/
/*                        Check for conflicts                         */
/*--------------------------------------------------------------------*/

   sendmail |= (optind != argc);

   if ( sendmail && readmail )
   {
      puts("Conflicting options specified");
      usage();
   }

   if ((optind == argc) && sendmail)
   {
      puts("Missing addresses for sending mail");
      usage();
   }

/*--------------------------------------------------------------------*/
/*        We have the options, now decide how to process them         */
/*--------------------------------------------------------------------*/

   if (sendmail)
   {
      argc -= optind;

      if ( subject != NULL )
      {

         argv    = &argv[optind-2];
         argv[0] = "-s";
         argv[1] = subject;

         Collect_Mail(stdin, argc+2 , argv , -1, FALSE);
      } /* if ( subject != NULL ) */
      else {
         Collect_Mail(stdin, argc, &argv[optind], -1, FALSE);

#ifdef _Windows
         atexit ( CloseEasyWin );
#endif
      }

   } /* if (sendmail) */
   else  {
      if ( postoffice && bflag[ F_MULTITASK ] )
         IncludeNew( mfilename, E_mailbox);
      Interactive_Mail( PrintOnly , postoffice );
   }

   Cleanup();
   PopDir();
   exit(0);

} /*main*/

/*--------------------------------------------------------------------*/
/*    C l e a n u p                                                   */
/*                                                                    */
/*    Remove temporary files when exiting                             */
/*--------------------------------------------------------------------*/

void Cleanup()
{

   printmsg(2,"Deleting temporary mailbox %s", tmailbox);

   if ( fmailbox != NULL )
   {
      fclose(fmailbox);
      fmailbox = NULL;
   }

   unlink(tmailbox);

} /*Cleanup*/


/*--------------------------------------------------------------------*/
/*    I n t e r a c t i v e _ M a i l                                 */
/*                                                                    */
/*    main procedure for reading mail                                 */
/*--------------------------------------------------------------------*/

static void Interactive_Mail( const boolean PrintOnly,
                              const boolean postoffice )
{
   char resp[LSIZE];
   int current = 0;                                               /* ahd   */
   boolean done      = FALSE;                                     /* ahd   */
   boolean modified;
   FILE *rmailbox;

/*--------------------------------------------------------------------*/
/*               Open real and temporary mailbox files                */
/*--------------------------------------------------------------------*/

   if ((rmailbox = FOPEN(mfilename, "r",TEXT_MODE)) == nil(FILE)) {
      printf("No mail in %s\n", mfilename);
      return;
   }

   mboxage = stater( mfilename, &mboxsize );
                              /* Remember mailbox information        */

   if ((fmailbox = FOPEN(tmailbox, "w", BINARY_MODE)) == nil(FILE)) {
      printerr(tmailbox);
      return;
   }

   letters = calloc(maxletters,sizeof(letters[0]));
   checkref(letters);

/*--------------------------------------------------------------------*/
/*                 Copy real mailbox to temporary one                 */
/*--------------------------------------------------------------------*/

   setvbuf(rmailbox, NULL, _IOFBF, 8192);
   setvbuf(fmailbox, NULL, _IOFBF, 8192);

   letternum = CreateBox(rmailbox, fmailbox, tmailbox);

   fclose(rmailbox);
   fclose(fmailbox);

   rmailbox = fmailbox = NULL;

   if (letternum < 1)            /* Did we find any mail in the box? */
   {                             /* No --> Return to caller          */
      if (letternum == 0)
         printf("No mail in %s\n", mfilename);
      return;
   }

/*--------------------------------------------------------------------*/
/*        Shrink mailbox status array to what we actually need        */
/*--------------------------------------------------------------------*/

   letters = realloc( letters, (letternum + 1) *  sizeof(letters[0]));
   checkref(letters);

   fmailbox = FOPEN(tmailbox, "r", BINARY_MODE);

   if (fmailbox == NULL)
   {
      printerr(tmailbox);
      panic();
   } /* if */
   setvbuf(fmailbox, NULL, _IOFBF, 8192);

   modified = postoffice && (!PrintOnly);

   if (PrintOnly) {
      int j = 0;
      while (j < letternum)
      {
         Pager(j, TRUE, noreceived, !j );
         j++ ;
      }
      return;
   }

   PrintSubject(-1,letternum); /* print all subjects */

/*--------------------------------------------------------------------*/
/*               Determine first letter in to prompt at               */
/*--------------------------------------------------------------------*/

      if (letternum == 0)
         current = -1;
      else
         current = 0;

/*--------------------------------------------------------------------*/
/*            Begin main command loop for reading the mail            */
/*--------------------------------------------------------------------*/

   if (!bflag[F_EXPERT])
      printf("Enter \"?\" for short help or \"help\" for long help.\n");

#ifdef _Windows
   atexit ( CloseEasyWin );
#endif

   while( ! done )
   {
      char *command, *operand;
      int integer;
      boolean first_pass = TRUE;
      int previous = current;
      struct CommandTable *cmd_ptr = table;
      boolean success = TRUE;
      boolean crlf    = FALSE;      /* crlf after delete command?    */

      printf("%d%s",current + 1,
               (letters[current].status == M_DELETED) ? "*" : " ");
      if (!Console_fgets(resp, LSIZE, "? ")) /* End of file?         */
      {
         done = TRUE;
         continue;            /* Yes --> Exit loop                   */
      }
      PageReset();

/*--------------------------------------------------------------------*/
/*                     Locate command to execute                      */
/*--------------------------------------------------------------------*/

      integer = strlen( resp );
      if (integer && ( resp[ integer - 1 ] == '\n'))
         resp[ integer - 1 ] = '\0';   /* Trim newline, if any       */

      operand = command = strtok( resp, WHITESPACE );
      if ( command == NULL )
         command = EMPTY_CMD;
      else if (Numeric(command))
         command = NUMERIC_CMD;

      while( cmd_ptr->sym != NULL)
      {
         if (equaln(command, cmd_ptr->sym, strlen(command)))
            break;            /* Exit if we have a hit               */
         cmd_ptr++;           /* Examine next command                */
      } /* while */

/*--------------------------------------------------------------------*/
/*     Get rest of command line, and trim leading spaces from it      */
/*--------------------------------------------------------------------*/

      if (!equal(command, NUMERIC_CMD) && (operand != NULL))
      {
         operand = strtok( NULL , "");
                              /* Save rest of string for later       */
         if ( operand != NULL )
         {
            while( isspace( *operand ))
               operand++ ;

            if (*operand == '\0')
               operand = NULL ;
         } /* if */
      }

/*--------------------------------------------------------------------*/
/*        Parse items to be selected from mailbox for command         */
/*--------------------------------------------------------------------*/

      if (cmd_ptr->bits & (LETTER_OP) )
         success = SelectItems( &operand, current, cmd_ptr->bits);

/*--------------------------------------------------------------------*/
/*                  Process the operands in the list                  */
/*--------------------------------------------------------------------*/

      while( success &&
             Get_Operand( &integer, &operand, cmd_ptr->bits, first_pass) )
      {
         switch( cmd_ptr->verb )
         {
            case M_ALIAS:
               ShowAlias( operand );
               break;

            case M_COPY:
               success = SaveItem( integer,
                         FALSE,        /* Do not delete */
                         seperators,   /* Do save headers */
                         (operand == NULL) ? "PRN" : operand ,
                         cmd_ptr->verb );
               break;

            case M_DEBUG:
               debuglevel = integer;
               printmsg(0,"Debug set to %d",debuglevel);
               break;

            case M_DELETEQ:
               done = TRUE;
            case M_DELETE:
               if (letters[integer].status < M_DELETED)
               {
                  letters[integer].status = M_DELETED;
                  if ( ! crlf )
                     printf("Deleting item(s) %d",integer + 1 );
                  else
                     printf(" %d",integer + 1 );
                  crlf  = modified = TRUE;
               }
               break;

            case M_DOWN:
               current = Position( 0 , integer , current );
               break;

            case M_EMPTY:
               if ( bflag[F_DOSKEY] && !bflag[F_EXPERT] )
               {
                  printf("DOSKEY active, empty line ignored\n");
                  PrintSubject( current , letternum );
                  success = FALSE;
               }
               else if (letters[current].status == M_UNREAD)
                  success = Pager( current , TRUE, noreceived, first_pass);
               else
                  current = Position( 0 , 1 , current );
               break;

            case M_EXIT:
               modified = FALSE;
               done     = TRUE;
               break;

            case M_EXTPRINT:
               success = Pager( integer , TRUE, noreceived, first_pass);
               break;

            case M_EXTTYPE:
               success = Pager( integer , TRUE, noseperator, first_pass);
               break;

            case M_FASTHELP:
            {
               size_t subscript = 0;
#ifndef _Windows
               size_t column    = 0;
#endif
               fputs("Valid commands are:\n",stdout);
               while( table[subscript].sym != NULL)
               {
                  if ( !(table[subscript].bits & NODISPLAY ))
                  {
#ifdef _Windows
                     fputc( '\n' , stdout );
#else
                     fputc( ( column++ % 2 ) ? ' ' : '\n' , stdout );
#endif
                     printf("%-9s%-30s",table[subscript].sym,
                                       table[subscript].help );
                  } /* if */
                  subscript ++;

⌨️ 快捷键说明

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