static void smtp_conn_eventcb(struct bufferevent *bev, short events, void* args) { bufferevent_free(bev); struct email* email = (struct email*) args; #ifdef DEV print_emails(email); #endif delete_email(email); }
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); }