

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<pthread.h>

#include"zither.h"
#include<almemsys/almemsys.h>



int send_rcptto(mail_data_t * dt, int buf_len)
{
int stat;
char * rcpadd;
int count, incount;
char * data;
data = "RCPT TO: ";
count = 0;
incount = 0;
stat = 0;

if((rcpadd = (char *)calloc(buf_len, sizeof(char)))==NULL){exit(1);}

incount = char_count(dt->rcptto, ','); 

for(count = 0; (count <= incount) && (count <= 20) && (stat != -1); count++){
   char_get(dt->rcptto, rcpadd, ',', count);

   dt->swap2 = safe_sprintf(dt->swap2, BUF_MAX, "%s%s\r\n",data, rcpadd);

   #ifdef MAIL_RCPTTO
   printf("MAIL_RCPTTO: sendrcptto(): SEND RCPTTO: %s\n", dt->swap2);
   #endif

   if(0 > (socket_send(dt->sk, dt->swap2, 7))){
      fprintf(stderr,"send_rcptto(): err\n");
      stat = -1;
      }
   else{
      dt->swap2 = safe_fdcat(dt->sk, dt->swap2, &stat, BUF_MAX, MAIL_INTERVAL);

      #ifdef MAIL_RCPTTO
      printf("MAIL_RCPTTO: sendrcptto(): STAT RCPTTO: %s\n", dt->swap2);
      #endif
      }

   #ifdef MAIL_RCPTTO
   printf("MAIL_RCPTTO: send_rcptto(): rcpadd=<%s> stat=<%d>\n", rcpadd, stat);
   #endif
   free(rcpadd);
   if((rcpadd = (char *)calloc(buf_len, sizeof(char)))==NULL){exit(1);}
   }

free(rcpadd);

return(stat);
}




