Files changed (8)
Binary file added.
+ char login_name[LOGIN_SIZE], message[BODY_SIZE]; // temporary variables for the corresponding parts of the mail
+/* Choose the action that will be taken and then send the message to the server and wait for response.
+ * There are two possible actions. Read all the mails and then delete them, or send an email to a specific
+ printf("Choose action (type \"read\" to read your mails, \"send\" to send a mail or \"exit\" to exit server)\n");
+ /* while user insists on giving as input a string that doesn't correspond to an action, we insist on waiting
+ printf("Choose action(type \"read\" to read your mails , \"send\" to send a mail or \"exit\" to exit server)\n");
+ write(socket, action, 4); // write at the socket so the server is aware of the action that has to be taken
+/* Send a mail to a specific user of the database. If this user doesn't exist then the program terminates without
+ char message[BODY_SIZE], receiver[LOGIN_SIZE]; // temprorary variable for the corresponding parts of the mail
+ printf("%s\n", message); // print out the server's response so the user is aware of how the things go
+ if(strncmp(message, "The receiver does not exist", strlen("The receiver does not exist") + 1) == 0)
+ // if we have reached this line, then the receiver exists and we continue normally the execution of the program
+ getchar(); // read the '\n' character from the previous input line in order to avoid problems with fgets()
+ write(socket, message, BODY_SIZE); // send it to the server in order to be added to the receiver's mail list
+ printf("%s user has received the mail\nbody = %s \n by %s\n\n", temp_mail->receiver.login, temp_mail->body, temp_mail->sender.login);
Binary file added.
+pthread_mutex_t send_mutex = PTHREAD_MUTEX_INITIALIZER; // intialization of mutex regarding the send operation
+int socket_initialization(struct sockaddr myname , int adrlen); // create, bind and listen to the socket
+void delete_mails( int user);//After sending the mailbox to the client we delete them from the database
+ for (i = 0; (strncmp(login, user_in_dbase[i].login, strlen(user_in_dbase[i].login) +1)!=0) && (i < TOT_USERS); i++)
+ return -1; // we need to send a message to inform the client that he/she failed, in case (s)he hasn't been found
+ for (i = 0; (strncmp(mail_receiver,user_in_dbase[i].login,strlen(user_in_dbase[i].login)+1)!=0) && (i < TOT_USERS); i++)
+ if(receiver < TOT_USERS) // if receiver < TOT_USERS then we have successfully found the user you were looking for
+ strncpy(sent_mail->sender.login, user_in_dbase[user].login, strlen(user_in_dbase[user].login) + 1);
+ strncpy(sent_mail->receiver.login, user_in_dbase[receiver].login, strlen(user_in_dbase[receiver].login) + 1);
+ // it's the part where we add a new mail at the head of the mail list. Because we update the common structures
+ int num_mails = 0; // keep the number of the mails so that the client knows how many mails are to be read
+ pthread_mutex_lock( &user_mutex[user] );// we use the mail list which can be changed by another thread so we
+ mailbox next_mail = user_in_dbase[user].mail_list; // temporary mail which holds the first mail of the list
+ free(user_in_dbase[user].mail_list); // free the allocated space for the mail which has just been read
+// A structure that contains the address binded to the socket. The length and format of the address depend on the address family of the socket.