1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| strcpy(Rec_Buf,"STAT\r\n"); /* send stat command */
err=send(sock,Rec_Buf,strlen(Rec_Buf),0);
sprintf(File_Buf,"sent: %s", Rec_Buf);
write_file(LOG_FILE | SCREEN, File_Buf);
/*
* should receive +OK x y where x = number of messages
* and y is total octets. Note the buffers we have allocated
* would not be sufficient for a real pop client. They
* should be dynamically allocated here after checking the
* size of the waiting emails.
*/
err=recv(sock,Rec_Buf,BUF_LEN,0);
sprintf(File_Buf,"received: %s", Rec_Buf);
write_file(LOG_FILE | SCREEN, File_Buf);
if ( strstr(Rec_Buf,POP_ERR_MSG) != NULL ) /* check for errors */
pop_error();
/*
* Now we need to work out how many emails we have to retrieve
* and set up a loop to get them all.
*/
i=j=0;
while (i ) {
if (Rec_Buf[i] > '0' && Rec_Buf[i] ) {
while (Rec_Buf[i] != ' ') /* space is end of number */
{
tempbuf[j] = Rec_Buf[i];
j++;
i++;
}
num_flag=1;
tempbuf[j] = '\0';
}
i++;
}
i = atoi(tempbuf); /* number of emails */
/* Le problème doit venir du code ci dessus */
printf("There are %d message(s) waiting\r\n", i);
for( j=1; j<=i; j++)
{
sprintf(Rec_Buf, "RETR %d\r\n", j); /* add number */
printf("Retrieving message number %d\n", j);
err=send(sock,Rec_Buf,strlen(Rec_Buf),0);
sprintf(File_Buf,"sent: %s ",Rec_Buf);
write_file(LOG_FILE| SCREEN, File_Buf);
err=recv(sock,Rec_Buf,BUF_LEN,0); /* +OK message will follow */
sprintf(File_Buf,"received: %s ",Rec_Buf);
write_file(LOG_FILE| SCREEN, File_Buf);
if ( strstr(Rec_Buf,POP_ERR_MSG) != NULL ) /* check for errors */
pop_error();
err=recv(sock,Rec_Buf,BUF_LEN,0); /* retrieve the mail */
sprintf(File_Buf,"%s",Rec_Buf);
write_file(MAIL_FILE, File_Buf);
}
printf ("All done\n\n"); |
Partager