Example #1
0
void process_client(int client_fd)
{
    int nread = 0;
    int i;
    int n_receivers;
    char times [SHORT_STRING];
    char buffer[BUF_SIZE];
    char user[SHORT_STRING];
    char sender[SHORT_STRING];
    char subject[NORMAL_SIZE];
    char body[BUF_SIZE];
    char index[SHORT_STRING];
    char receiver[SHORT_STRING];

    char waste[100];

    nread = read(client_fd, buffer, BUF_SIZE-1);
    fflush(stdout);
    buffer[nread] = '\0';

    if(strcmp(buffer, "inbox") == 0){
        nread = read(client_fd, user, SHORT_STRING-1);
        fflush(stdout);
        user[nread] = '\0';
        check_inbox(user, client_fd);

    } else if(strcmp(buffer, "cmail") == 0){
        printf("ENTROU NA FUNÇAO CMAIL\n");

        nread = read(client_fd, user, SHORT_STRING-1);
        fflush(stdout);
        user[nread] = '\0';
        printf("user-> %s\n", user);

        nread=read(client_fd, times,SHORT_STRING-1);
        fflush(stdout);
        times[nread-1]='\0';
        n_receivers = atoi(times);
        printf("n_receivers->%d\n", n_receivers);

        nread=read(client_fd,subject, NORMAL_SIZE-1);
        fflush(stdout);
        subject[nread]=0;
        printf("SUBJECT-> %s\n", subject);

        nread=read(client_fd,body, BUF_SIZE-1);
        fflush(stdout);
        body[nread]=0;
        printf("BODY-> %s\n", body);

        for(i = 0; i < n_receivers; i++){
            nread = read(client_fd, receiver, SHORT_STRING-1);
            fflush(stdout);
            receiver[nread] = '\0';
            printf("user->%s subject->%s body->%s receiver-> %s\n", user, subject, body, receiver);
            inserir_email(user, receiver, subject, body, client_fd);
        }
    } else if(strcmp(buffer, "omail") == 0){
        nread = read(client_fd, user, SHORT_STRING-1);
        fflush(stdout);
        user[nread] = '\0';

        nread = read(client_fd, index, SHORT_STRING-1);
        fflush(stdout);
        index[nread] = '\0';

        open_email(user, atoi(index), client_fd);
    } else if(strcmp(buffer, "dmail") == 0){
        nread = read(client_fd, user, SHORT_STRING-1);
        fflush(stdout);
        user[nread] = '\0';
        nread = read(client_fd, index, SHORT_STRING-1);
        fflush(stdout);
        index[nread] = '\0';

        delete_email(user, atoi(index), client_fd);
    } else {
        printf("Wrong key word\n");
    }

    /*write(client_fd,buffer,1+strlen(buffer));
    fflush(stdin);*/


    fflush(stdout);
    close(client_fd);
}
Example #2
0
void send_email2(void)
{
    char s[81],scratch[81],log[81];
    int f, i;
    long len,len2;
    char *b;
    long thetime,dat;
    int len3;
    mailrec m,m1;
    userrec ur;
    messagerec msg;
    struct date dt;
    struct time tm;
    char *month[] = {"Bug","Jan","Feb","Mar","Apr","May","Jun",
		     "Jul","Aug","Sep","Oct","Nov","Dec"};

    m.touser=user_to_num;

    time(&thetime);

    len=(unsigned) strlen(buffer);
    len2=len;
    b=((char *)malloc(len+1024));
    len=0;
    sprintf(log,"þ Incoming mail for %s from %s (%s)\n",fido_to_user,fido_from_user,origi_node);
    write_log(log);
    sprintf(s,"%s (%s)",fido_from_user,origi_node);
    addline(b,s,&len);

    /* Get date/time of Email creation. */
    /* Ditto the \015 for the time/date string. */

    strncpy(scratch,fido_date_line,20);
    scratch[20]='\0';

    /* Build the date - cumbersome, but it needs to be done */
	/* Build tblock as we go along so we can have a pretty date */
	scratch[2] = '\0';	/* make day a string */
	dt.da_day = atoi(scratch);
	for (i=1;i<13;i++)
	if (strncmpi(month[i],&scratch[3],3) == 0)
	{
	    dt.da_mon = i;
	    break;
        }
	scratch[9] = '\0';	/* make year a string */
    dt.da_year = atoi(&scratch[7]);
    if (dt.da_year>90)
        dt.da_year += 1900;
    else
        dt.da_year += 2000;
	scratch[13] = '\0'; /* make hour a string */
	tm.ti_hour = atoi(&scratch[11]);
	scratch[16] = '\0'; /* make minute a string */
	tm.ti_min = atoi(&scratch[14]);
	scratch[19] = '\0'; /* make second a string */
	tm.ti_sec = atoi(&scratch[17]);
	tm.ti_hund = 0;
	dat = dostounix(&dt,&tm);
	strncpy(scratch,ctime(&(time_t)dat),24);
	scratch[24]='\0';
    strcat(scratch,"\r\n");
    strcpy(s,scratch);
    addline(b,s,&len);

    strcat(b,buffer);
    len += len2;
    len=(unsigned) strlen(b);

    if (b[len-1]!=26)
        b[len++]=26;

    m.msg.storage_type=2;
    msg.stored_as=0L;
    msg.storage_type=2;
    savefile(b,len,&msg,"EMAIL");
    m.msg=msg;

    i=0;
    strcpy(m.title,fido_title);
//    i=strlen(m.title);
//    m.title[i+1]=net_num;
//    m.title[i+2]=0;
    m.title[80]=net_num;
    m.title[81]=0;
//    i=0;
    read_user(user_to_num,&ur);
    ++ur.waiting;
    write_user(user_to_num,&ur);
    lock_status();
    save_status();

    m.anony=i;
    m.fromsys=atoi(wwiv_node);
    m.fromuser=0;
    m.tosys=0;
    m.status=status_new_net;
    time((long *)&(m.daten));

    f=open_email(1);
    len3=(int) filelength(f)/sizeof(mailrec);
    if (len3==0)
	i=0;
    else
    {
        i=len3-1;
        sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
        sh_read(f,(void *)&m1,sizeof(mailrec));
        while ((i>0) && (m1.tosys==0) && (m1.touser==0))
        {
            --i;
            sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
	    sh_read(f,(void *)&m1,sizeof(mailrec));
	}
        if ((m1.tosys) || (m1.touser))
            ++i;
    }
    sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
    sh_write(f,(void *)&m,sizeof(mailrec));
    sh_close(f);

    free(buffer);
}