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

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

-+-+-+-+-+-+-+-+ START OF PART 3 -+-+-+-+-+-+-+-+
X            was_underscore = FALSE;
X         `125
X         else
X         `123
X            if (!was_underscore)
X            `123
X               file_name`091path_offset + (j++)`093 = '_';
X               was_underscore = TRUE;
X            `125
X         `125
X      `125
X      file_name`091path_offset + j`093 = '\0';
X   `125
X
X   /* test if the file already exists */
X   j = strlen (file_name);
X   strcat (file_name, ".MSG");
X   i = 2;
X   while ((fp = fopen (file_name, "r")) != NULL)
X   `123
X      fclose (fp);
X      /* modify the filename */
X      file_name `091j`093 = '\0';
X      sprintf (tmp, "%1d", i++);
X      strcat (file_name, "_");
X      strcat (file_name, tmp);
X      strcat (file_name, ".MSG");
X   `125
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid build_bigmail_filename (char *file_name, char *directory_name,`032
X                             char *subject_buffer)
X
X`123
X   char  *key_str = "extract as: ";
X   int   i, key_str_len = strlen (key_str);
X
X   /* build the directory name */
X   strcpy (file_name, directory_name);
X
X   /* locate the string "extract as:" in the subject field; after that`032
X      there is the filename */
X
X   for (i = 0;`032
X        (i <= (strlen (subject_buffer) - key_str_len) &&`032
X         strncmp (subject_buffer + i, key_str, key_str_len));
X        i++);
X   if (i > (strlen (subject_buffer) - key_str_len))
X   `123
X      printf ("PLM$-W-NOMHFTUMSG, Illegal subject for a MHFTU message\n");
X      return;
X   `125
X
X   strcat (file_name, subject_buffer + i + key_str_len);
X                                          `032
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid build_sendmsg_filename (char *file_name)
X
X`123
X   sprintf (file_name, "SYS$SCRATCH:PLM$MAIL_%X%X.TMP", proc_pid (), time ()
V);
X                                          `032
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid tpuedit (char *input_file_name, char *output_file_name)
X
X`123
X   struct dsc$descriptor  in_file, out_file;
X   unsigned long          status;
X   unsigned long          cleanup_flags;
X   extern unsigned long   TPU$M_RESET_TERMINAL,
X                          TPU$M_DELETE_BUFFERS,
X                          TPU$M_DELETE_WINDOWS,
X                          TPU$M_DELETE_JOURNAL,
X                          TPU$M_DELETE_EXITH,
X                          TPU$M_EXECUTE_PROC,
X                          TPU$M_EXECUTE_FILE,
X                          TPU$M_PRUNE_CACHE,
X                          TPU$M_KILL_PROCESSES;    `032
X
X
X   in_file.dsc$w_length = strlen (input_file_name);
X   in_file.dsc$b_dtype = DSC$K_DTYPE_T;
X   in_file.dsc$b_class = DSC$K_CLASS_S;
X   in_file.dsc$a_pointer = input_file_name;
X
X   out_file.dsc$w_length = strlen (output_file_name);
X   out_file.dsc$b_dtype = DSC$K_DTYPE_T;
X   out_file.dsc$b_class = DSC$K_CLASS_S;
X   out_file.dsc$a_pointer = output_file_name;
X      `032
X   status = TPU$EDIT (&in_file, &out_file);
X   if (status != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X#if FALSE
X   cleanup_flags = TPU$M_RESET_TERMINAL `124`032
X                   TPU$M_DELETE_BUFFERS `124`032
X                   TPU$M_DELETE_JOURNAL `124`032
X                   TPU$M_DELETE_WINDOWS `124`032
X                   TPU$M_DELETE_EXITH `124  `032
X                   TPU$M_EXECUTE_PROC `124  `032
X                   TPU$M_EXECUTE_FILE `124  `032
X                   TPU$M_PRUNE_CACHE `124   `032
X                   TPU$M_KILL_PROCESSES; `032
X
X   tpu$cleanup (&cleanup_flags);
X#endif
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid mail_begin ()
X
X`123
X   int         status;
X   char        full_mail_file_name `091512`093;
X
X   if ((status = mail$mailfile_begin`032
X                    (&file_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   /* read the default mail directory */
X
X   user_context = 0;
X   if ((status = mail$user_begin
X                    (&user_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   if ((status = mail$user_get_info
X                    (&user_context,`032
X                     mail_null_list,`032
X                     user_get_def_dir_itmlst)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   strncpy (mail_file_directory, directory_buffer, directory_length);
X   mail_file_directory `091directory_length`093 = '\0';
X
X   if ((status = mail$user_end
X                    (&user_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   strcpy (full_mail_file_name, mail_file_directory);
X   strcat (full_mail_file_name, mail_file_name);
X   mailfile_open_in_itmlst`0910`093.buffer_length = strlen (full_mail_file_n
Vame);
X   mailfile_open_in_itmlst`0910`093.buffer_address = full_mail_file_name;
X
X   if ((status = mail$mailfile_open`032
X                    (&file_context,`032
X                     mailfile_open_in_itmlst,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   if ((status = mail$message_begin
X                    (&message_context,`032
X                     message_begin_in_itmlst,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xint create_folder_announce (unsigned long *dummy, struct dsc$descriptor *nam
Ve)
X
X`123
X   char  f_name `091256`093;
X
X   strncpy (f_name, name->dsc$a_pointer, name->dsc$w_length);
X   f_name `091name->dsc$w_length`093 = '\0';
X   printf ("PLM$MAIL-I-CREFOLDER, folder %s has been created\n", f_name);
X
X   return (SS$_NORMAL);
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid mail_end ()
X
X`123
X   unsigned long  status;
X   int            del_cnt = 0;
X   int            mov_cnt = 0;
X   int            tot_cnt = 0;
X   char           full_mail_file_name `091512`093;
X
X   AUTOSELECT     *autosel_ptr;
X   MSG_DSC        *msg_dsc_ptr;
X
X
X   /* delete marked messages */
X
X   printf
X      ("PLM$MAIL-I-DELMARK, collecting messages marked for deletion...\n");
X `032
X   autosel_ptr = autoselect_list;
X   while (autosel_ptr != NULL)
X   `123        `032
X      msg_dsc_ptr = autosel_ptr->msg_list_ptr;
X      while (msg_dsc_ptr != END_OF_MSG_LIST)
X      `123
X         tot_cnt++;
X         if (msg_dsc_ptr->deleted)
X         `123
X            del_cnt++;
X            msg_id = msg_dsc_ptr->id;
X            status = mail$message_delete
X                        (&message_context,`032
X                         message_sel_msg_in_itmlst,
X                         mail_null_list);
X            if (status != SS$_NORMAL)
X            `123
X#if FALSE
X               lib$signal (status);
X#endif
X               printf ("\n\n");
X            `125          `032
X         `125          `032
X         msg_dsc_ptr = msg_dsc_ptr->next;
X      `125
X      autosel_ptr = autosel_ptr->next;
X   `125
X
X   if (del_cnt == 1)
X      printf
X         ("PLM$MAIL-I-DELNUM, 1 message was marked for deletion\n");
X   else
X      printf
X         ("PLM$MAIL-I-DELNUM, %d messages were marked for deletion\n", del_c
Vnt);
X
X   /* move read messages to folder MAIL and reset the new mail message count
Ver`032
X      if folder is NEWMAIL */
X   if (!strcmp (folder_name, NEWMAIL_FOLDER))
X   `123
X      /* move the messages */
X
X      printf
X         ("PLM$MAIL-I-MOVMARK, collecting messages to be moved to folder %s.
V..\n",`032
X          OLDMAIL_FOLDER);
X `032
X      autosel_ptr = autoselect_list;
X      while (autosel_ptr != NULL)
X      `123        `032
X         msg_dsc_ptr = autosel_ptr->msg_list_ptr;
X         while (msg_dsc_ptr != END_OF_MSG_LIST)
X         `123
X            if ((!msg_dsc_ptr->deleted) &&`032
X                ((msg_dsc_ptr->read) `124`124 (msg_dsc_ptr->extracted)))
X            `123
X               mov_cnt++;
X               msg_id = msg_dsc_ptr->id;
X               strcpy (full_mail_file_name, mail_file_directory);
X               strcat (full_mail_file_name, mail_file_name);
X               message_move_itmlst`0911`093.buffer_length =`032
X                                               strlen (full_mail_file_name);
X               message_move_itmlst`0911`093.buffer_address = full_mail_file_
Vname;
X               message_move_itmlst`0912`093.buffer_length = strlen (OLDMAIL_
VFOLDER);
X               message_move_itmlst`0912`093.buffer_address = OLDMAIL_FOLDER;
X               status = mail$message_copy
X                           (&message_context,`032
X                            message_move_itmlst,
X                            mail_null_list);
X               if (status != SS$_NORMAL)
X               `123
X#if FALSE
X                  lib$signal (status);
X#endif
X                  printf ("\n\n");
X               `125          `032
X            `125          `032
X            msg_dsc_ptr = msg_dsc_ptr->next;
X         `125
X         autosel_ptr = autosel_ptr->next;
X      `125
X
X      if (mov_cnt == 1)
X         printf
X            ("PLM$MAIL-I-MOVNUM, 1 message moved to folder %s\n",`032
X             OLDMAIL_FOLDER);
X      else
X         printf
X            ("PLM$MAIL-I-MOVNUM, %d messages moved to folder %s\n",`032
X             mov_cnt, OLDMAIL_FOLDER);
X
X
X      /* reset the new mail messages counter */
X
X      new_msg_count = tot_cnt - del_cnt - mov_cnt;
X
X      user_context = 0;
X      if ((status = mail$user_begin
X                       (&user_context,`032
X                        mail_null_list,`032
X                        mail_null_list)) != SS$_NORMAL)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X      `125
X
X      if ((status = mail$user_set_info
X                       (&user_context,`032
X                        user_set_new_msg_count_itmlst,
X                        mail_null_list)) != SS$_NORMAL)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X      `125
X
X      if ((status = mail$user_end
X                       (&user_context,`032
X                        mail_null_list,`032
X                        mail_null_list)) != SS$_NORMAL)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X      `125
X   `125
X
X
X   if (new_msg_count == 1)
X      printf
X         ("PLM$MAIL-I-LEFTNUM, 1 message left in folder %s\n", folder_name);
X   else
X      printf ("PLM$MAIL-I-LEFTNUM, %d messages left in folder %s\n",`032
X              tot_cnt - del_cnt - mov_cnt, folder_name);
X
X
X   if (del_cnt `124`124 mov_cnt)
X   `123
X
X      if ((status = mail$mailfile_purge_waste
X                       (&file_context,`032
X                        mailfile_purge_in_itmlst,
X                        mail_null_list)) != SS$_NORMAL)
X      `123
X#if FALSE
X         lib$signal (status);
X#endif
X         printf ("\n\n");
X      `125
X   `125
X
X
X   if ((status = mail$message_end
X                    (&message_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   if ((status = mail$mailfile_close
X                    (&file_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   if ((status = mail$mailfile_end`032
X                    (&file_context,`032
X                     mail_null_list,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   return;
X`125
X
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid get_folders ()
X
X`123
X   int         status;
X   FOLDER_DSC  *f_dsc_tmp;
X
X   if ((status = mail$mailfile_info_file
X                    (&file_context,`032
X                     mailfile_info_in_itmlst,`032
X                     mail_null_list)) != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X
X   f_dsc_tmp = folder_list;
X   while (f_dsc_tmp != NULL)
X   `123
X      message_select_in_itmlst`0910`093.buffer_address = f_dsc_tmp->folder_n
Vame;
X      message_select_in_itmlst`0910`093.buffer_length =`032
X                                     strlen(f_dsc_tmp->folder_name);
X      message_select_out_itmlst`0910`093.buffer_address =`032
X                                     &(f_dsc_tmp->message_number);
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      f_dsc_tmp = f_dsc_tmp->next;
X   `125
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid select_messages (char *folder)
X
X`123
X   int            status;
X   int            num_of_messages, message_counter;
+-+-+-+-+-+-+-+-  END  OF PART 3 +-+-+-+-+-+-+-+-

