
#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<errno.h>
#include<pthread.h>

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


/*
int mail_grsend( char *, char *, char *, char *, char *);
*/


int mail_grsend_t(mail_data_t *);



/* --- MAIL GRSEND (user, host,data,subject)--- */
int mail_grsend( char * iserver,
                 char * ifrom,
                 char * ircptto,
                 char * icc,
                 char * idata,
                 char * isubject,
                 char * bccadd,
                 char * pri 
                 )
{
pthread_t pt_t;
int tret;

errno = 0;
tret = 0;

mail_data_t * mdd;
if((mdd = (mail_data_t *)malloc(sizeof(mail_data_t)))==NULL){exit(1);}
mail_malloc(mdd);

mdd->iserver  = safe_memcpy(mdd->iserver, iserver, BUF_MAX);
mdd->ifrom    = safe_memcpy(mdd->ifrom, ifrom, BUF_MAX);
mdd->ircptto  = safe_memcpy(mdd->ircptto, ircptto, BUF_MAX);
mdd->icc      = safe_memcpy(mdd->icc, icc, BUF_MAX);
mdd->bccadd   = safe_memcpy(mdd->bccadd, bccadd, BUF_MAX);
mdd->pri      = safe_memcpy(mdd->pri, pri, BUF_MAX);
mdd->idata    = safe_memcpy(mdd->idata, idata, BUF_MAX);

mdd->isubject = safe_sprintf(mdd->isubject, BUF_MAX, "Subject: %s", isubject);

/* --- ボディー処理 EUC-JP -> JIS --- */
mdd->idata = safe_ujtoj(mdd->idata);

// thread 分岐　分岐先でデタッチ
if((tret = pthread_create( &pt_t, NULL, (void *)mail_grsend_t, mdd)) != 0){
   fprintf(stderr,"life_logi.c life_logi(): pthread_create %d\n", tret);
   }

// ここには戻らない。
return 0;
}






