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

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

-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
X                             char *subject_buffer, unsigned long message_id)
V;
Xvoid build_bigmail_filename (char *file_name, char *directory_name,`032
X                             char *subject_buffer);
Xvoid build_sendmsg_filename (char *file_name);
Xunsigned long proc_pid ();       `032
Xvoid proc_trnlnm (char *logical_name);
Xvoid read_site ();
Xvoid mail_begin ();
Xvoid mail_end ();
Xvoid select_messages (char *folder);
Xvoid tpuedit (char *input_file, char *output_file);
Xunsigned char search_substring (char *string, char *substring);
Xvoid trim (char *string);
Xunsigned char strcmpnocase (char *first, char *second);
Xunsigned char get_next_dst (char *dst_buffer, char *line_buffer,`032
X                            FILE *dis_file, char *dis_filename);
Xvoid init_get_next_dst ();
Xvoid commands ();
X
X`012
X/***************************************************************************
V***/
X
X
XITMLST mail_null_list`091`093 =`032
X`123
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST mailfile_open_in_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_MAILFILE_NAME, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST mailfile_info_in_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MAILFILE_FOLDER_ROUTINE, create_folder_list, 0`125,
X   `1234, MAIL$_MAILFILE_USER_DATA, &dummy, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST mailfile_purge_in_itmlst`091`093 =`032
X`123                                             `032
X   `1230, MAIL$_MAILFILE_RECLAIM, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_begin_in_itmlst`091`093 =`032
X`123                                          `032
X   `1234, MAIL$_MESSAGE_FILE_CTX, &file_context, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_select_in_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_MESSAGE_FOLDER, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_select_out_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MESSAGE_SELECTED, &dummy, &dummy_length`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_sel_msg_in_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MESSAGE_ID, &msg_id, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_fsd_in_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MESSAGE_ID, &msg_id, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_fsd_out_itmlst`091`093 =`032
X`123
X   `123255, MAIL$_MESSAGE_FROM, from_buffer, &from_length`125,
X   `123255, MAIL$_MESSAGE_SUBJECT, subj_buffer, &subj_length`125,
X   `123255, MAIL$_MESSAGE_DATE, date_buffer, &date_length`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_record_in_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_MESSAGE_CONTINUE, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_record_out_itmlst`091`093 =`032
X`123
X   `123255, MAIL$_MESSAGE_RECORD, msg_buffer, &msg_length`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_next_in_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_MESSAGE_NEXT, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_get_next_out_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MESSAGE_CURRENT_ID, &msg_id, &id_length`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_send_address_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_SEND_USERNAME, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_send_filename_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_SEND_FILENAME, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_send_bodypart_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_SEND_RECORD, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_send_attribute_itmlst`091`093 =`032
X`123
X   `1230, MAIL$_SEND_SUBJECT, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST user_set_new_msg_count_itmlst`091`093 =`032
X`123
X   `1232, MAIL$_USER_SET_NEW_MESSAGES, &new_msg_count, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST user_get_def_dir_itmlst`091`093 =`032
X`123
X   `123255, MAIL$_USER_FULL_DIRECTORY, directory_buffer, &directory_length`1
V25,
X   `123 0, 0, 0, 0 `125
X`125;
X
XITMLST message_move_itmlst`091`093 =`032
X`123
X   `1234, MAIL$_MESSAGE_ID, &msg_id, 0`125,
X   `1230, MAIL$_MESSAGE_DEFAULT_NAME, 0, 0`125,
X   `1230, MAIL$_MESSAGE_FOLDER, 0, 0`125,
X   `1234, MAIL$_MESSAGE_FOLDER_ACTION, create_folder_announce, 0`125,
X   `1234, MAIL$_MESSAGE_USER_DATA, &dummy, 0`125,
X   `1230, MAIL$_MESSAGE_DELETE, 0, 0`125,
X   `123 0, 0, 0, 0 `125
X`125;
X
X`012
X/***************************************************************************
V***/
X
X
X#define  LOGICAL_NAME_TABLE      "LNM$PROCESS_TABLE"
X
Xvoid proc_trnlnm (char *logical_name)
X
X`123
X   struct
X   `123
X      unsigned short  len;
X      unsigned char   d_type;
X      unsigned char   d_class;
X      char            *ln_ptr;
X   `125  ln_dsc;
X   struct
X   `123
X      unsigned short  len;
X      unsigned char   d_type;
X      unsigned char   d_class;
X      char            *tab_ptr;
X   `125  tab_dsc;
X   unsigned long  status;
X   unsigned short len;
X   struct
X   `123
X      unsigned short  len;
X      unsigned short  item;
X      char            *buff_add;
X      unsigned long   *ret_len_add;
X      unsigned long   cork;
X   `125  tn_dsc;
X
X
X   ln_dsc.len = strlen (logical_name);
X   ln_dsc.d_type = DSC$K_DTYPE_T;
X   ln_dsc.d_class = DSC$K_CLASS_S;
X   ln_dsc.ln_ptr = logical_name;
X
X   tab_dsc.len = strlen (LOGICAL_NAME_TABLE);
X   tab_dsc.d_type = DSC$K_DTYPE_T;
X   tab_dsc.d_class = DSC$K_CLASS_S;
X   tab_dsc.tab_ptr = LOGICAL_NAME_TABLE;
X
X   tn_dsc.cork = 0;
X   tn_dsc.buff_add = return_string;
X   tn_dsc.ret_len_add = &len;
X   tn_dsc.len = 127;
X   tn_dsc.item = LNM$_STRING;
X
X   status = sys$trnlnm ((unsigned long) 0, &tab_dsc, &ln_dsc,`032
X                        (unsigned char) 0, &tn_dsc);
X
X   if (status != SS$_NORMAL)
X   `123                                      `032
X      return_string `0910`093 = '\0';
X   `125
X   else
X   `123
X      /* terminate the string */
X      return_string `091len`093 = '\0';
X   `125
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xunsigned long  proc_pid ()
X
X`123
X   unsigned long  status;
X   unsigned short len;
X   unsigned long  pid;
X   struct
X   `123
X      unsigned short  len;
X      unsigned short  item;
X      unsigned long   *buff_add;
X      unsigned long   *ret_len_add;
X      unsigned long   cork;
X   `125  proc_pid_dsc;
X
X
X   proc_pid_dsc.cork = 0;
X   proc_pid_dsc.buff_add = &pid;
X   proc_pid_dsc.ret_len_add = &len;
X   proc_pid_dsc.len = 4;
X   proc_pid_dsc.item = JPI$_PID;
X
X   status = sys$getjpiw ((unsigned long) 0, (unsigned long) 0,
X                         (unsigned long) 0, &proc_pid_dsc, (unsigned long) 0
V,
X                         (unsigned long) 0, (unsigned long) 0);
X
X   if (status != SS$_NORMAL)
X   `123
X#if FALSE
X      lib$signal (status);
X#endif
X      printf ("\n\n");
X   `125
X
X   return (pid);
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid read_site ()
X
X`123
X   FILE           *cfg_file;
X   char           key, tmp_buffer `091512`093;
X   AUTOSELECT     *tmp_autosel, *last_tmp_autosel = (AUTOSELECT *) NULL;
X   char           *str_add, *end_str_add;
X   char           default_extract_dir `091512`093; `032
X   char           default_bigmail_extract_dir `091512`093;
X
X
X   if ((cfg_file = fopen (CONFIG_FILE, "r")) == NULL)
X   `123
X      printf ("PLM$MAIL-F-NOCFGFILE, configuration file not found\n");
X      exit (SS$_NORMAL);
X   `125
X
X   fscanf (cfg_file, "%s", mail_file_name);
X   strcat (mail_file_name, MAIL_FILE_EXTENSION);
X   fscanf (cfg_file, "%s", folder_name);
X   fscanf (cfg_file, "%s", default_extract_dir);
X   fscanf (cfg_file, "%s", default_bigmail_extract_dir);
X
X   /* create the default bigmail entry */
X   tmp_autosel = (AUTOSELECT *) malloc (sizeof (AUTOSELECT));
X   tmp_autosel->msg_list_ptr = END_OF_MSG_LIST;
X   tmp_autosel->msg_list_last_ptr = BEG_OF_MSG_LIST;
X   tmp_autosel->group_name = BIGMAIL_GROUP_NAM;
X   tmp_autosel->selected_number = 0;
X   tmp_autosel->key_code = 'b';
X   tmp_autosel->substring = BIGMAIL_STRING;
X   tmp_autosel->default_subdir = malloc`032
X                                    (strlen (default_bigmail_extract_dir) +
V 1);
X   strcpy (tmp_autosel->default_subdir, default_bigmail_extract_dir);
X   last_tmp_autosel = autoselect_list = tmp_autosel;
X   tmp_autosel->previous =`032
X   tmp_autosel->next = (AUTOSELECT *) NULL;
X
X   READ_A_LINE:
X   while (fgets (tmp_buffer, 511, cfg_file) != NULL)
X   `123                 `032
X      /* trim the string */
X      trim (tmp_buffer);
X
X      if (tmp_buffer `0910`093 == '\0')
X      `123
X         /* OOPS! empty line */
X         goto READ_A_LINE;
X      `125
X
X      /* create the message descriptor */
X      tmp_autosel = (AUTOSELECT *) malloc (sizeof (AUTOSELECT));
X      tmp_autosel->msg_list_ptr = END_OF_MSG_LIST;
X      tmp_autosel->msg_list_last_ptr = BEG_OF_MSG_LIST;
X
X      /* get the key code */
X      key = tolower (tmp_buffer `0910`093);
X      if ((key != 'f') && (key != 's') && (key != 'm'))
X      `123
X         printf`032
X            ("PLM$MAIL-F-INVCFGITM, Error found in configuration file\n");
X         exit (SS$_NORMAL);
X      `125
X
X      tmp_autosel->key_code = key;
X
X      /* get the substring */
X      if ((str_add = strchr (tmp_buffer + 1, '"')) == 0)
X      `123
X         printf`032
X            ("PLM$MAIL-F-INVCFGITM, Error found in configuration file\n");
X         exit (SS$_NORMAL);
X      `125
X
X      if ((end_str_add = strchr (str_add + 1, '"')) == 0)
X      `123
X         printf`032
X            ("PLM$MAIL-F-INVCFGITM, Error found in configuration file\n");
X         exit (SS$_NORMAL);
X      `125
X
X      /* copy the substring and remove the '"'s */
X      tmp_autosel->substring = malloc (end_str_add - str_add);
X      strncpy (tmp_autosel->substring, str_add + 1, end_str_add - str_add -
V 1);
X      tmp_autosel->substring `091end_str_add - str_add - 1`093 = '\0';
X
X      /* get the default directory */
X      for (str_add = end_str_add + 1;`032
X           (*str_add == ' ') `124`124 (*str_add == '\t'); str_add++);
X
X      if ((end_str_add = strchr (str_add, '`093')) == 0)
X      `123
X         printf`032
X            ("PLM$MAIL-F-INVCFGITM, Error found in configuration file\n");
X         exit (SS$_NORMAL);
X      `125
X        `032
X      tmp_autosel->default_subdir = malloc (end_str_add - str_add + 2);
X      strncpy (tmp_autosel->default_subdir, str_add, end_str_add - str_add +
V 1);
X      tmp_autosel->default_subdir `091end_str_add - str_add + 1`093 = '\0';
X
X      /* get the group name */
X      for (str_add = end_str_add + 1;`032
X           (*str_add == ' ') `124`124 (*str_add == '\t'); str_add++);
X      for (end_str_add = str_add + 1;`032
X           (*end_str_add != ' ') && (*end_str_add != '\t') &&`032
X           (end_str_add != '\0');`032
X          end_str_add++);
X
X      tmp_autosel->group_name = malloc (end_str_add - str_add + 2);
X      strncpy (tmp_autosel->group_name, str_add, end_str_add - str_add + 1);
X      tmp_autosel->group_name `091end_str_add - str_add + 1`093 = '\0';
X
X      tmp_autosel->selected_number = 0;
X
X      tmp_autosel->next = (AUTOSELECT *) NULL;
X      tmp_autosel->previous = last_tmp_autosel;
X      last_tmp_autosel->next = tmp_autosel;
X      last_tmp_autosel = tmp_autosel;
X   `125
X
X   fclose (cfg_file);
X
X   /* create the default entry for remaining messages */
X   tmp_autosel = (AUTOSELECT *) malloc (sizeof (AUTOSELECT));
X   tmp_autosel->msg_list_ptr = END_OF_MSG_LIST;
X   tmp_autosel->msg_list_last_ptr = BEG_OF_MSG_LIST;
X   tmp_autosel->group_name = "OTHERS";
X   tmp_autosel->selected_number = 0;
X   tmp_autosel->key_code = '*';
X   tmp_autosel->substring = (char *) NULL;
X   tmp_autosel->default_subdir = malloc (strlen (default_extract_dir) + 1);
X   strcpy (tmp_autosel->default_subdir, default_extract_dir);
X   tmp_autosel->next = (AUTOSELECT *) NULL;
X   tmp_autosel->previous = last_tmp_autosel;
X   last_tmp_autosel->next = tmp_autosel;
X   autoselect_list_tail = tmp_autosel;
X
X   return;
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xint create_folder_list (unsigned long *dummy, struct dsc$descriptor *name)
X
X`123
X   FOLDER_DSC  *dsc_ptr;
X
X   if (name->dsc$w_length)
X   `123
X      dsc_ptr = (FOLDER_DSC *) malloc (sizeof (FOLDER_DSC));
X      if (folder_list == NULL)
X      `123
X         folder_list = dsc_ptr;
X         dsc_ptr->next = (FOLDER_DSC *) NULL;
X      `125
X      else
X      `123
X         last_folder->next = dsc_ptr;
X         dsc_ptr->next = (FOLDER_DSC *) NULL;
X      `125
X      last_folder = dsc_ptr;
X      dsc_ptr->folder_name = malloc (name->dsc$w_length + 1);
X      strncpy (dsc_ptr->folder_name, name->dsc$a_pointer, name->dsc$w_length
V);
X      dsc_ptr->folder_name`091name->dsc$w_length`093 = '\0';
X   `125
X   return (SS$_NORMAL);
X`125
X
X`012
X/***************************************************************************
V***/
X
X
Xvoid build_message_filename (char *file_name, char *directory_name,`032
X                             char *subject_buffer, unsigned long message_id)
X`123
X   int            i, j, path_offset;
X   FILE           *fp;
X   char           tmp `0918`093;`032
X   unsigned char  was_underscore;
X
X   strcpy (file_name, directory_name);
X   if (subject_buffer `0910`093 == '\0')
X   `123
X      strcat (file_name, "no_subject");
X   `125
X   else
X   `123
X      was_underscore = TRUE;  /* no trailing underscores */
X      for (i = 0, j = 0, path_offset = strlen (file_name);`032
X           (i < strlen (subject_buffer)) && (j < 36);`032
X           i++)
X      `123
X         if (((subject_buffer`091i`093 >= 'A') && (subject_buffer`091i`093 <
V= 'Z')) `124`124`032
X             ((subject_buffer`091i`093 >= 'a') && (subject_buffer`091i`093 <
V= 'z')) `124`124`032
X             ((subject_buffer`091i`093 >= '0') && (subject_buffer`091i`093 <
V= '9')) `124`124
X              (subject_buffer`091i`093 == '-') `124`124 (subject_buffer`091i
V`093 == '$'))
X         `123
X            file_name`091path_offset + (j++)`093 = subject_buffer`091i`093;
+-+-+-+-+-+-+-+-  END  OF PART 2 +-+-+-+-+-+-+-+-

