From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 14-NOV-1990 06:05:13.51
To:	MRGATE::"ARISIA::EVERHART"
CC:	
Subj:	PLM$MAIL, part 4 of 10

Received:  by crdgw1.ge.com (5.57/GE 1.76)
	 id AA00628; Wed, 14 Nov 90 05:44:43 EST
Received: From ICNUCEVM.CNUCE.CNR.IT by CRVAX.SRI.COM with TCP; Wed, 14 NOV 90 01:35:15 PST
Received: from ITOPOLI.BITNET by ICNUCEVM.CNUCE.CNR.IT (IBM VM SMTP R1.2.2MX) with BSMTP id 0273; Wed, 14 Nov 90 10:32:04 MET
Date: Wed, 14 Nov 90 10:31 GMT+1
From: "P.L. Montessoro * CENS-CNR * +39-11-556.7013" <PIERLUCA%ITOPOLI.BITNET@ICNUCEVM.CNUCE.CNR.IT>
Subject: PLM$MAIL, part 4 of 10
To: info-vax@kl.sri.com
Message-Id: <04DBB9E7111F20028A@ITOPOLI.BITNET>
X-Envelope-To: info-vax@kl.sri.com
X-Vms-To: INFOVAX

-+-+-+-+-+-+-+-+ START OF PART 4 -+-+-+-+-+-+-+-+
X   AUTOSELECT     *autosel_ptr;
X   MSG_DSC        *msg_dsc_ptr, *last_msg_dsc_ptr = END_OF_MSG_LIST;
X   unsigned char  selected;
X
X
X   /* select the messages in the specified folder */
X
X   message_select_in_itmlst`0910`093.buffer_address = folder_name;
X   message_select_in_itmlst`0910`093.buffer_length = strlen(folder_name);
X   message_select_out_itmlst`0910`093.buffer_address = &(num_of_messages);
X  `032
X   if ((status = mail$message_select
X                    (&message_context,`032
X                     message_select_in_itmlst,`032
X                     message_select_out_itmlst)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   /* now select the messages */
X
X   for (message_counter = 0; message_counter < num_of_messages;`032
X        message_counter++)
X   `123
X      /* next message */
X      status = mail$message_get`032
X                  (&message_context,`032
X                   message_get_next_in_itmlst,`032
X                   message_get_next_out_itmlst);
X      if (status != MAIL$_MSGINFO)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X         break;
X      `125
X
X      /* create the message descriptor and get the from and subject fields *
V/
X
X      msg_dsc_ptr = (MSG_DSC *) malloc (sizeof (MSG_DSC));
X
X      status = mail$message_get`032
X                  (&message_context,`032
X                   message_get_fsd_in_itmlst,
X                   message_get_fsd_out_itmlst);
X      if (status != MAIL$_MSGINFO)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X      `125          `032
X      subj_buffer `091subj_length`093 = '\0';
X      from_buffer `091from_length`093 = '\0';
X      date_buffer `091date_length`093 = '\0';
X
X      if (subj_length == 0)
X      `123
X         strcpy (subj_buffer, "(no subject)");
X         subj_length = strlen ("(no subject)");
X      `125
X
X      msg_dsc_ptr->from = malloc (from_length + 1);
X      strcpy (msg_dsc_ptr->from, from_buffer);
X      msg_dsc_ptr->subject = malloc (subj_length + 1);
X      strcpy (msg_dsc_ptr->subject, subj_buffer);
X      msg_dsc_ptr->date = malloc (date_length + 1);
X      strcpy (msg_dsc_ptr->date, date_buffer);
X      msg_dsc_ptr->id = msg_id;
X      msg_dsc_ptr->read = FALSE;
X      msg_dsc_ptr->extracted = FALSE;
X      msg_dsc_ptr->deleted = FALSE;
X
X
X      /* visit the selection list to insert the message in the correct`032
X         group */
X
X      selected = FALSE;
X
X      autosel_ptr = autoselect_list;
X      while ((autosel_ptr != NULL) && (!selected))
X      `123
X         switch (autosel_ptr->key_code)
X         `123
X            case 'f':
X               /* search for the substring in the from field */
X
X               if (search_substring (msg_dsc_ptr->from, autosel_ptr->substri
Vng))
X               `123
X                  /* link the message descriptor to the list */
X                  if (autosel_ptr->msg_list_ptr == END_OF_MSG_LIST)
X                  `123
X                     msg_dsc_ptr->next = END_OF_MSG_LIST;
X                     msg_dsc_ptr->previous = BEG_OF_MSG_LIST;
X                     autosel_ptr->msg_list_ptr =
X                     autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                  `125
X                  else
X                  `123
X                     autosel_ptr->msg_list_last_ptr->next = msg_dsc_ptr;
X                     msg_dsc_ptr->previous = autosel_ptr->msg_list_last_ptr;
X                     msg_dsc_ptr->next = END_OF_MSG_LIST;
X                     autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                  `125
X                  autosel_ptr->selected_number++;
X                  selected = TRUE;
X               `125
X               break;
X
X            case 's':  /* user-defined subject substring */
X            case 'b':  /* bigmail messages */
X               /* search for the substring in the subject field */
X
X               if (search_substring (msg_dsc_ptr->subject,`032
X                                     autosel_ptr->substring))
X               `123
X                  /* link the message descriptor to the list */
X                  if (autosel_ptr->msg_list_ptr == END_OF_MSG_LIST)
X                  `123
X                     msg_dsc_ptr->next = END_OF_MSG_LIST;
X                     msg_dsc_ptr->previous = BEG_OF_MSG_LIST;
X                     autosel_ptr->msg_list_ptr =
X                     autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                  `125
X                  else
X                  `123
X                     autosel_ptr->msg_list_last_ptr->next = msg_dsc_ptr;
X                     msg_dsc_ptr->previous = autosel_ptr->msg_list_last_ptr;
X                     msg_dsc_ptr->next = END_OF_MSG_LIST;
X                     autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                  `125
X                  autosel_ptr->selected_number++;
X                  selected = TRUE;
X               `125
X               break;
X
X            case 'm':
X               /* scan the message and search for the substring in the`032
X                  records */
X
X               /* re-select current message (useful in case of more`032
X                  searches) */
X               status = mail$message_get`032
X                           (&message_context,`032
X                            message_sel_msg_in_itmlst,
X                            mail_null_list);
X               if (status != MAIL$_MSGINFO)
X               `123
X#if FALSE
X                  lib$signal (status);
X#endif
X                  printf ("\n\n");
X               `125          `032
X
X               do
X               `123
X                  /* get a record of the message */
X                  status = mail$message_get`032
X                              (&message_context,`032
X                               message_get_record_in_itmlst,`032
X                               message_get_record_out_itmlst);
X                  if ((status != MAIL$_MSGTEXT) &&`032
X                      (status != MAIL$_NOMOREREC))
X                  `123
X#if FALSE
X                     lib$signal (status);
X#endif
X                     printf ("\n\n");
X                     break;
X                  `125
X                  msg_buffer `091msg_length`093 = '\0';
X              `032
X                  if (search_substring (msg_buffer,
X                                        autosel_ptr->substring))
X                  `123
X                     /* link the message descriptor to the list */
X                     if (autosel_ptr->msg_list_ptr == END_OF_MSG_LIST)
X                     `123
X                        msg_dsc_ptr->next = END_OF_MSG_LIST;
X                        msg_dsc_ptr->previous = BEG_OF_MSG_LIST;
X                        autosel_ptr->msg_list_ptr =
X                        autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                     `125
X                     else
X                     `123
X                        autosel_ptr->msg_list_last_ptr->next = msg_dsc_ptr;
X                        msg_dsc_ptr->previous = autosel_ptr->msg_list_last_p
Vtr;
X                        msg_dsc_ptr->next = END_OF_MSG_LIST;
X                        autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X                     `125
X                     autosel_ptr->selected_number++;
X                     selected = TRUE;
X                     break;
X                  `125
X               `125  while (status != MAIL$_NOMOREREC);
X               break;
X
X            case '*':
X               /* just link the message descriptor to the list */
X               if (autosel_ptr->msg_list_ptr == END_OF_MSG_LIST)
X               `123
X                  msg_dsc_ptr->next = END_OF_MSG_LIST;
X                  msg_dsc_ptr->previous = BEG_OF_MSG_LIST;
X                  autosel_ptr->msg_list_ptr =
X                  autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X               `125
X               else
X               `123
X                  autosel_ptr->msg_list_last_ptr->next = msg_dsc_ptr;
X                  msg_dsc_ptr->previous = autosel_ptr->msg_list_last_ptr;
X                  msg_dsc_ptr->next = END_OF_MSG_LIST;
X                  autosel_ptr->msg_list_last_ptr = msg_dsc_ptr;
X               `125
X               autosel_ptr->selected_number++;
X               selected = TRUE;
X               break;
X
X         `125  /* end of switch */
X
X         autosel_ptr = autosel_ptr->next;
X
X      `125  /* end of while */
X
X   `125
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xunsigned char search_substring (char *string, char *substring)
X
X`123
X   int   i, cmp_len;
X
X   if ((cmp_len = strlen (substring)) > strlen (string))
X      return (FALSE);
X   for (i = 0; i <= strlen (string) - cmp_len; i++)
X   `123
X      if (!strncmp (string + i, substring, cmp_len))
X         return (TRUE);
X   `125
X   return (FALSE);
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid trim (char *string)
X
X`123
X   int   i, j, len;
X
X   len = strlen (string);
X
X   /* skip the blanks */
X   for (i = 0; (i < len) && ((string `091i`093 == ' ') `124`124 (string `091
Vi`093 == '\t')); i++);
X   /* copy up to the newline (coming from fgets) or null */
X   for (j = 0; (i < len) && (string `091i`093 != '\n') && (string `091i`093
V != '\0');`032
X        i++, j++)
X      string `091j`093 = string `091i`093;
X   /* go back to remove newline and blanks */
X   for (j-- ; (j >= 0) && ((string `091j`093 == '\n') `124`124 (string `091j
V`093 == ' ') `124`124`032
X        (string `091j`093 == '\t')); j--);
X      string `091j+1`093 = '\0';
X  `032
X   return;
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
Xunsigned char strcmpnocase (char *first, char *second)
X
X`123
X   int i, len;
X
X   len = strlen (first);
X
X   if (len != strlen (second))
X   `123
X      return (FALSE);
X   `125
X
X   for (i = 0; i < len; i++)
X   `123
X      if (toupper (first `091i`093) != toupper (second `091i`093))
X         return (FALSE);
X   `125
X
X   return (TRUE);
X
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
Xint  next_dst_offset;
X
Xunsigned char get_next_dst (char *dst_buffer, char *line_buffer,`032
X                            FILE *dis_file, char *dis_filename)
X
X`123
X   char ch;
X   int  i;
X
X   dst_buffer `0910`093 = '\0';
X   if (dis_filename `0910`093 != '\0')
X   `123
X      if (fscanf (dis_file, "%`091`094,`093", dst_buffer) == NULL) return (F
VALSE);
X      /* newlines in the string (coming from empty lines) ! */
X      for (i = 0; (i < strlen (dst_buffer)) &&`032
X                  (dst_buffer `091i`093 == ' ') `124`124 (dst_buffer `091i`0
V93 == '\t') `124`124`032
X                  (dst_buffer `091i`093 == '\n'); i++)
X         dst_buffer `091i`093 = ' ';
X      /* skip tabs and blanks */
X      do
X      `123
X         ch = fgetc (dis_file);
X      `125  while ((ch != EOF) &&`032
X                ((ch == ' ') `124`124 (ch == '\t') `124`124 (ch == '\n') `12
V4`124 (ch == ',')));
X      if (ch != EOF) ungetc (ch, dis_file);
X      trim (dst_buffer);
X   `125
X   else
X   `123
X      if (next_dst_offset >= strlen (line_buffer))  return (FALSE);
X      sscanf (line_buffer + next_dst_offset, "%`091`094,`093", dst_buffer);`
V032
X      next_dst_offset += strlen (dst_buffer) + 1;
X      /* skip tabs and blanks */
X      for ( ; (line_buffer `091next_dst_offset`093 == ' ') `124`124`032
X              (line_buffer `091next_dst_offset`093 == '\t') `124`124`032
X              (line_buffer `091next_dst_offset`093 == ','); next_dst_offset+
V+);
X      trim (dst_buffer);
X   `125
X   if (dst_buffer `0910`093 != '\0')
X   `123
X      return (TRUE);
X   `125
X   else
X   `123
X      return (FALSE);
X   `125
X`125
X
X
Xvoid init_get_next_dst ()
X
X`123
X   next_dst_offset = 0;
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
X/* command line interpreter.
X
X   Implemented commands (parameters are often optional):
X
X   h                           help
X   a                           to show automatic message selection
X   g <groupname>               to select a group
X   l <groupname>               to list the messages in a group
X   m <message id>              to select a message
X   t <message id>              to type a message
X   <message id>                to type a message
X   e <message id>/'*' <group>  to extract one/all (not deleted) message(s)
X   n                           to type next message
X   p                           to type previous message
X   d <message id>/'*'/'r'/'e'  to delete one/all/read/extracted message(s)
X   u <message id>/'*'/'r'/'e'  to undelete one/all/read/extracted message(s)
X   s <filename>                to send a message
X   f                           to forward the current message
X   r                           to reply to the current message
X   x/EOF                       to exit
X
X*/
X
X
Xvoid commands ()
X
X`123
X
X   int            par_offset;
X   char           comm_buffer `091512`093;
X   char           int_buffer `091512`093;
X   char           comm_key;
X   char           group_name `09164`093;
X   int            message_id;
X   int            line_cnt;
X   char           ch;
X   unsigned long  status;
X   char           filename `091132`093;
X   char           dis_filename `091132`093;
X   FILE           *fp;
X   FILE           *dis_fp;
X   int            i;
X   unsigned char  wild;
X   unsigned char  wild_code;
X   unsigned char  edit_flag;
X   MSG_DSC        *tmp_message;
X
X   AUTOSELECT     *tmp_autosel;
X   MSG_DSC        *msg_dsc_ptr;
X
X   AUTOSELECT     *curr_group;
X   MSG_DSC        *curr_message;
X
X
X   /* initialize curr_group and curr_message */
X
X   tmp_autosel = autoselect_list;
X   while (tmp_autosel != NULL)
X   `123
X      if (tmp_autosel->selected_number)
X         break;
X      tmp_autosel = tmp_autosel->next;
X   `125
X   if (tmp_autosel != NULL)
X   `123
X      curr_group = tmp_autosel;
+-+-+-+-+-+-+-+-  END  OF PART 4 +-+-+-+-+-+-+-+-

