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

📄 mailblib.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

/*--------------------------------------------------------------------*/
/*               Determine if we can reply to the mail                */
/*--------------------------------------------------------------------*/

   if (!RetrieveLine(letters[current].replyto, addr, LSIZE))
   {
      printf("Cannot determine return address\n");
      return FALSE;
   }

/*--------------------------------------------------------------------*/
/*                  Get the incoming subject, if any                  */
/*--------------------------------------------------------------------*/

   if (RetrieveLine(letters[current].subject, line, LSIZE))
   {
      register char  *sp = line;

      while (!isspace(*sp))     /* Skip "Subject:"      */
         sp++;
      while (isspace(*sp))      /* Skip leading whitespace */
         sp++;
      Largv[Largc++] = "-s";

      if (!equalni(sp,"Re:",3))
         strcat(subject,"Re: ");
      strcat(subject,sp);
      Largv[Largc++] = subject;
   }

/*--------------------------------------------------------------------*/
/*                   Get the extract return address                   */
/*--------------------------------------------------------------------*/

   column = addr;
   while (!isspace(*column) && strlen(column))
      column++;

   BuildAddress(line,column);      /* Build standard "To:" addr  */
   printf("Replying to %s\n", line);

/*--------------------------------------------------------------------*/
/*                    Format the outgoing address                     */
/*--------------------------------------------------------------------*/

   Largv[Largc++] = line;

   if (letters[current].status < M_ANSWERED)
      letters[current].status = M_ANSWERED;

   return Collect_Mail(stdin, Largc, Largv, current, TRUE);

} /* Reply */


/*--------------------------------------------------------------------*/
/*    F o r w a r d I t e m                                           */
/*                                                                    */
/*    Forward (resend) mail to another address                        */
/*--------------------------------------------------------------------*/

boolean ForwardItem( const int item , const char *string )
{
   FILE *stream;
   char  *Largv[MAXADDRS];
   char buf[LSIZE];
   char tmailbag[FILENAME_MAX];
   int   Largc;
   boolean success;

/*--------------------------------------------------------------------*/
/*              copy current message to a temporary file              */
/*--------------------------------------------------------------------*/

   mktempname(tmailbag, "TMP");
   stream = FOPEN(tmailbag, "w",TEXT_MODE);
   if (stream == NULL )
   {
      printerr(tmailbag);
      return FALSE;
   } /* if */

   CopyMsg(item, stream, noreceived,FALSE);

   fclose(stream);

/*--------------------------------------------------------------------*/
/*               mail the content of the temporary file               */
/*--------------------------------------------------------------------*/

   stream = FOPEN(tmailbag, "r",TEXT_MODE);
   if (stream == NULL )
   {
      printerr(tmailbag);
      panic();
   }

   strcpy( buf , string );
   Largc = getargs( buf , Largv );
   success = Send_Mail(stream, Largc , Largv, NULL, TRUE);

/*--------------------------------------------------------------------*/
/*                   Clean up and return to caller                    */
/*--------------------------------------------------------------------*/

   if (letters[item].status < (int) M_FORWARDED)
      letters[item].status = (int) M_FORWARDED;
   remove(tmailbag);

   return success;
} /* ForwardItem */


/*--------------------------------------------------------------------*/
/*    s u b s h e l l                                                 */
/*                                                                    */
/*    Invoke inferior command processor                               */
/*--------------------------------------------------------------------*/

void subshell( char *command )
{
#if defined(_Windows)
   char buf[128];
   //
   // Here we simply use the Windows DOSPRMPT.PIF and fire off
   // an ASYNCHRONOUS DOS box. Under 286 mode, this will be
   // synchronous. But who in the hell cares!
   //
   sprintf(buf, "dosprmpt.pif %s", command);
   WinExec(buf, SW_SHOWMAXIMIZED);
#else
   if ( command == NULL )
   {
      static char *new_prompt = NULL;

      char *exit_prompt =  "PROMPT=Enter EXIT to return to MAIL$_";
      char *old_prompt;

      if ( new_prompt == NULL )
      {
         old_prompt = getenv( "PROMPT" );
         if ( old_prompt == NULL )
            old_prompt = "$p$g";

         new_prompt = malloc( strlen( old_prompt ) + strlen( exit_prompt ) + 1);
         checkref( new_prompt );

         strcpy( new_prompt , exit_prompt );
         strcat( new_prompt, old_prompt );

         if (putenv( new_prompt ) )
         {
            printmsg(0,"Prompt update failed ...");
            printerr("putenv");
         } /* if (putenv( new_prompt ) ) */

      } /* if ( new_prompt == NULL ) */

      system( getenv( "COMSPEC" ) );
   } /* if */
   else
      system ( command );
#endif
} /* subshell */

/*--------------------------------------------------------------------*/
/*    S e l e c t I t e m s                                           */
/*                                                                    */
/*    Select mail items to be processed by the current command        */
/*--------------------------------------------------------------------*/

boolean SelectItems( char **input, int current , int bits)
{
   char *next_token = *input;
   char *token = NULL;
   char trailing[LSIZE];      /* for saving trailing part of line    */
   int item;
   boolean hit = FALSE;

/*--------------------------------------------------------------------*/
/*                 Reset all mail items to unselected                 */
/*--------------------------------------------------------------------*/

   next_item = 0;

/*--------------------------------------------------------------------*/
/*            If no operands, return the current mail item            */
/*--------------------------------------------------------------------*/

   if ( *input == NULL )
   {
      SetItem( current+1 );
      return SetTrailing( input , bits );
   }

/*--------------------------------------------------------------------*/
/*             Select all items if the user requested so              */
/*--------------------------------------------------------------------*/

   strcpy( trailing , next_token );
   token = strtok( next_token , WHITESPACE );
   if (equal(token,"*"))      /* Select all items?                   */
   {
      *input = strtok( NULL , "" );

      for ( item = 1; item <= letternum; item++)
         SetItem( item );

      return SetTrailing( input , bits );
   } /* if */

/*--------------------------------------------------------------------*/
/*   If the first token begins with a slash (/), scan for items       */
/*   with the subject.                                                */
/*--------------------------------------------------------------------*/

   if ( *token == '/' )
      return SearchSubject( token, input, trailing, bits);

/*--------------------------------------------------------------------*/
/*          Scan the line until we hit a non-numeric operand          */
/*--------------------------------------------------------------------*/

   while ( token != NULL)
   {
      boolean success = TRUE;
      next_token = strtok( NULL , "");
                              /* Remember next of line for next pass */

      if (Numeric( token ))
         hit = success = SetItem( atoi(token) );
      else if (equal( token, "$"))
         hit = success = SetItem( letternum );
      else if (equal( token, "."))
         hit = success = SetItem( current + 1 );
      else if (strpbrk(token,"@!") != NULL ) /* User id?             */
         break;                  /* Yes --> Exit loop gracefully     */
      else if (isdigit(*token) || (*token == '$') || (*token == '.'))
                                 /* Is it start-end combination?     */
      {                          /* Yes --> Handle it                */
         char *start, *end ;
         int  istart, iend;
         start = strtok( token , "-");
         end   = strtok( NULL , "");

         if (equal(start,"$"))
            istart = letternum;
         else if (equal(start,"."))
            istart = current + 1 ;
         else if (!Numeric( start ))
         {
            printf("%s: Operand is not numeric\n", start );
            return FALSE;
         } /* if */
         else
            istart = atoi( start );

         if ( (end == NULL) )
         {
            printf("Missing end of item range\n" );
            return FALSE;
         } /* if */

         if (equal(end,"$"))
            iend = letternum;
         else if (equal(end,"."))
            iend = current + 1 ;
         else if (!Numeric( end ))
         {
            printf("%s: Operand is not numeric\n", end );
            return FALSE;
         } /* if */
         else
            iend = atoi( end );

         if ( iend < istart)
         {
            printf("Ending item (%d) is less than starting item (%d)\n",
                   iend , istart );
            return FALSE;
         } /* if */

         for ( item = istart; (item <= iend) && success; item++ )
            hit = success = SetItem ( item );

      } /* else */
      else
         break ;

      if ( !success )
         return FALSE;

      if ( next_token != NULL )
      {
         strcpy( trailing , next_token );
                              /* Save current line so we can back up */
         token = strtok( next_token, WHITESPACE );
      }
      else
         token = NULL;
   } /* while */

/*--------------------------------------------------------------------*/
/*   Determine if we have a user id to search for.  This is harder    */
/*   than the above search for subject lines, because the user id     */
/*   doesn't have to have a special delimiter; thus, we do our        */
/*   best to discard other types of items and assume a user id        */
/*   only if we don't know what it is.                                */
/*--------------------------------------------------------------------*/

   if ( ! hit )
   {
      if ( (bits & (FILE_OP | USER_OP)) == 0x0000)
      {
         *input = next_token;
         return SearchUser( token, input, bits);
      }
      else if ((bits & USER_OP) == 0x0000)
      {
         if ((strpbrk(token,"@%!") != NULL) || (next_token != NULL))
         {
            *input = next_token;
            return SearchUser( token, input, bits);
         }
      }
   } /* if (! hit) */

/*--------------------------------------------------------------------*/
/*      Handle trailing operands when user selected items by number   */
/*--------------------------------------------------------------------*/

   if ( token != NULL )
   {
      if (!hit)               /* Any numeric operands?               */
         SetItem( current+1 );   /* No --> Set current as default    */
      strcpy( *input, trailing );
   }
   else
      *input = NULL ;

   return SetTrailing( input , bits );

} /* SelectItems */


/*--------------------------------------------------------------------*/
/*    S e a r c h S u j e c t                                         */
/*                                                                    */
/*    Search for mail items to select by the subject                  */
/*--------------------------------------------------------------------*/

static boolean SearchSubject( char *token,
                              char **input,
                              char *trailing,
                              const int bits)
{
   char line[LSIZE];
   int item;
   char *next_token;
   boolean hit = FALSE;

   token = strtok(trailing,"/");    /* Get subject to search      */
   if ( token == NULL )
   {
      printf("Missing subject to search for\n");
      return FALSE;
   }
   token = strlwr(token);  /* Case insensitive search             */
   next_token = strtok(NULL,"");
                           /* Get rest of line                    */
   for ( item = 1; item <= letternum; item++)

⌨️ 快捷键说明

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