PSR SE2a4 2022/2023 G6 : Différence entre versions
De Wiki d'activités IMA
Ligne 20 : | Ligne 20 : | ||
Réécriture du code<br/> | Réécriture du code<br/> | ||
Création code Maildir/tmp -> réception message (MTAext.c)<br/> | Création code Maildir/tmp -> réception message (MTAext.c)<br/> | ||
+ | <pre> | ||
+ | int processing_mail(struct smtp_state *state) { | ||
+ | LOG_D("Processing mail..."); | ||
+ | |||
+ | // TODO: Generate a unique identifier for this mail | ||
+ | // https://stackoverflow.com/questions/51053568/generating-a-random-uuid-in-c | ||
+ | |||
+ | uuid_t binuuid;// Unique ID in binary | ||
+ | uuid_generate_random(binuuid); | ||
+ | char *uuid = malloc(37);//Nb of characters for unique id | ||
+ | uuid_unparse_lower(binuuid, uuid);//lettre minuscule | ||
+ | |||
+ | LOG_D("Mail UUID %s", uuid); | ||
+ | char tmp_path[256]; | ||
+ | sprintf(tmp_path, "/root/Maildir/tmp/%s", uuid); | ||
+ | LOG_D("Writing mails at %s", tmp_path); | ||
+ | |||
+ | FILE *fptr; | ||
+ | fptr = fopen(tmp_path, "w"); | ||
+ | |||
+ | if(fptr == NULL){ | ||
+ | LOG_E("Couldn't open Maildir tmp"); | ||
+ | exit(1); | ||
+ | } | ||
+ | |||
+ | fprintf(fptr, "From: %s\r\n", state->sender); | ||
+ | fprintf(fptr, "To: %s\r\n", state->recipient); | ||
+ | fprintf(fptr, "%s\r\n", state->body); // TODO: change to data | ||
+ | fclose(fptr); | ||
+ | |||
+ | char new_path[256]; | ||
+ | sprintf(new_path, "/root/Maildir/new/%s", uuid); | ||
+ | LOG_D("Move mails at %s", new_path); | ||
+ | |||
+ | rename(tmp_path, new_path); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
Test code MTAext.c : vérification<br/> | Test code MTAext.c : vérification<br/> | ||
-> compilation/execution de réception de mails (envoyeur, receveur, corps de mail, UUID)<br/> | -> compilation/execution de réception de mails (envoyeur, receveur, corps de mail, UUID)<br/> |
Version du 17 mars 2023 à 10:55
Infrastructure
Le serveur est disponible sur `yamaha.germond.org` (193.48.57.161), le DNS est hébergé sur mon (bastien) infrastructure[1]
[1]
03/02/2023
Création VM : yamaha (IP : 193.48.57.161)
Lancement de la VM
Ouverture du projet beta
Découverte STMPin
10/02/2023
Réécriture du code
Création code Maildir/tmp -> réception message (MTAext.c)
int processing_mail(struct smtp_state *state) { LOG_D("Processing mail..."); // TODO: Generate a unique identifier for this mail // https://stackoverflow.com/questions/51053568/generating-a-random-uuid-in-c uuid_t binuuid;// Unique ID in binary uuid_generate_random(binuuid); char *uuid = malloc(37);//Nb of characters for unique id uuid_unparse_lower(binuuid, uuid);//lettre minuscule LOG_D("Mail UUID %s", uuid); char tmp_path[256]; sprintf(tmp_path, "/root/Maildir/tmp/%s", uuid); LOG_D("Writing mails at %s", tmp_path); FILE *fptr; fptr = fopen(tmp_path, "w"); if(fptr == NULL){ LOG_E("Couldn't open Maildir tmp"); exit(1); } fprintf(fptr, "From: %s\r\n", state->sender); fprintf(fptr, "To: %s\r\n", state->recipient); fprintf(fptr, "%s\r\n", state->body); // TODO: change to data fclose(fptr); char new_path[256]; sprintf(new_path, "/root/Maildir/new/%s", uuid); LOG_D("Move mails at %s", new_path); rename(tmp_path, new_path); return 0; }
Test code MTAext.c : vérification
-> compilation/execution de réception de mails (envoyeur, receveur, corps de mail, UUID)