#include <string.h>
#include <ctype.h>

#include "extern.h"

mlwrite()
     {
	  int iz,i;
	  char tostn[9];
     /* ﾒｰﾙ ｶﾞｲﾀﾞﾝｽ ｿｳｼﾝ */ 

	  if ( ! strcmp(hiscall,guestid) )
		 { strcpy(ssent,"\n: ゲストのかたは、SYSOP 宛だけにメールを出すことができます");
		   rsout();
		   strcpy(ynsent,"\nSYSOP にメールを出しますか？\n");
		   if ( y_or_n() )  return(0);
		   strcpy(tocall,sysop);
		   exewrite(); return(0);
		  }

      if ( ! exp_flg )
         { strcpy(ssent,": 宛先のＩＤをどうぞ");
           strcat(ssent,"  ( , や ; で区切って10人までに差し出し可)\n");
 /*   strcat(ssent,"  ｺｰﾙ･ｻｲﾝの後に # をつけると VAP-NET BBS へも転送 "); */
           strcat(ssent,"  (ｷｬﾝｾﾙは cr ﾉﾐ)\nID =>");
         }
	  else
		 { strcpy(ssent,"ｶﾝﾏで区切って10人まで ");
           strcpy(ssent,"ID =>");
		 }
      rsout();
                
      /* tocall ｼﾞｭｼﾝ */
 
      rsin(0);
                
      if (rsent[0] == '\n')
        {strcpy(ssent,"\n: キャンセルされました\n");
         if ( exp_flg ) strcpy(ssent,"--- ｷｬﾝｾﾙ\n");
         rsout();
         return(0);     }
 
      if ( strlen(rsent) > 79 )  *(rsent + 79) = NULL;
      strcpy(tocall,rsent);

      iz = 0; i = -1;
      while(1)
      { 
		char *chp;
        int j = 0;

        while(1)
        { i++;
          chp = (tocall + i);
          if ( *chp == '\n' || *chp == NULL || *chp == 0x2c || *chp == 0x3b )
             break;
          if ( j < 8 ) { *(tostn + j) = *chp; j++; }
        }

        for ( ; j < 8 ; j++ ) { *(tostn + j) = ' '; }
        *(tostn + 8) = NULL;

		if ( ! strcmp(tostn,guestid) )
		 { printf("\nゲスト宛にメールを出すことはできません\n");
		   rsout();
		   return(0);
         }
		
		fpw = fopen(PASSWORD,"r");
		if ( fpw == NULL )
		   { strcpy(ssent,"\nメールを出すことができません\n");
			 rsout();
			 return(0);
		   }

		 while(1)
		   { if ( feof(fpw) )
				{ sprintf(ssent,"\nこのIDは登録されていません %s\n",tostn);
				  rsout();
				  fclose(fpw);
				  return(0);
				}
			 fgets(fbuff,255,fpw);
			 if ( strncmp(tostn,fbuff,8) ) continue;
			 fclose(fpw); break;
		   }
        fclose(fpw);

		iz++;
        if ( *chp == '\n' || *chp == NULL || iz > 9 ) break;
        }
      
      exewrite();

      return(0);
     }
        

