| version 1.1, 2002/10/21 13:37:08 |
version 1.2, 2002/10/21 17:01:25 |
| Line 571 int* pop3_getmailsizelist(void) |
|
| Line 571 int* pop3_getmailsizelist(void) |
|
| return(nSizeList); |
return(nSizeList); |
| } |
} |
| |
|
| int pop3_getmail(int nMessageNo, int nMessageSize, |
int pop3_getmail(int nMessageNo, int nMessageSize, struct pop3_mail *mail) |
| struct pop3_mail * sNewMail) |
|
| { |
{ |
| /*static struct pop3_mail sNewMail; *//* Our mail structure */ |
/*static struct pop3_mail mail; *//* Our mail structure */ |
| int nBytesRecv,nBytesSend; /* Returns from send() & recv() */ |
int nBytesRecv,nBytesSend; /* Returns from send() & recv() */ |
| int nLength; /* String length */ |
int nLength; /* String length */ |
| char* nRetrMsg; /* RETR message to send */ |
char* nRetrMsg; /* RETR message to send */ |
| Line 724 int pop3_getmail(int nMessageNo, int nMe |
|
| Line 723 int pop3_getmail(int nMessageNo, int nMe |
|
| #endif /* __POP3_DEBUG */ |
#endif /* __POP3_DEBUG */ |
| |
|
| /* Set each header in the pop3_mail structure to be NULL */ |
/* Set each header in the pop3_mail structure to be NULL */ |
| sNewMail->zTo=0; |
mail->zTo=0; |
| sNewMail->zCc=0; |
mail->zCc=0; |
| sNewMail->zBcc=0; |
mail->zBcc=0; |
| sNewMail->zReplyTo=0; |
mail->zReplyTo=0; |
| sNewMail->zSubject=0; |
mail->zSubject=0; |
| sNewMail->zMessageId=0; |
mail->zMessageId=0; |
| sNewMail->zFrom=0; |
mail->zFrom=0; |
| sNewMail->zSender=0; |
mail->zSender=0; |
| sNewMail->zDate=0; |
mail->zDate=0; |
| sNewMail->zBody=0; |
mail->zBody=0; |
| sNewMail->zContent=0; |
mail->zContent=0; |
| sNewMail->zEncoding=0; |
mail->zEncoding=0; |
| sNewMail->zInReplyTo=0; |
mail->zInReplyTo=0; |
| |
|
| /* Now parse the message headers into the pop3_mail struct */ |
/* Now parse the message headers into the pop3_mail struct */ |
| /* Get the following headers: |
/* Get the following headers: |
| Line 758 Body: - This is actually the whole messa |
|
| Line 757 Body: - This is actually the whole messa |
|
| /* Properly terminate the buffer */ |
/* Properly terminate the buffer */ |
| nMsgBuf=strcat(nMsgBuf,"\0"); |
nMsgBuf=strcat(nMsgBuf,"\0"); |
| |
|
| extract_header(&sNewMail->zTo,nMsgBuf,"\nTo:"); |
extract_header(&mail->zTo,nMsgBuf,"\nTo:"); |
| extract_header(&sNewMail->zCc,nMsgBuf,"\nCc:"); |
extract_header(&mail->zCc,nMsgBuf,"\nCc:"); |
| extract_header(&sNewMail->zBcc,nMsgBuf,"\nBcc:"); |
extract_header(&mail->zBcc,nMsgBuf,"\nBcc:"); |
| extract_header(&sNewMail->zReplyTo,nMsgBuf,"\nReply-To:"); |
extract_header(&mail->zReplyTo,nMsgBuf,"\nReply-To:"); |
| extract_header(&sNewMail->zSubject,nMsgBuf,"\nSubject:"); |
extract_header(&mail->zSubject,nMsgBuf,"\nSubject:"); |
| extract_header(&sNewMail->zMessageId,nMsgBuf,"\nMessage-ID:"); |
extract_header(&mail->zMessageId,nMsgBuf,"\nMessage-ID:"); |
| extract_header(&sNewMail->zFrom,nMsgBuf,"\nFrom:"); |
extract_header(&mail->zFrom,nMsgBuf,"\nFrom:"); |
| extract_header(&sNewMail->zSender,nMsgBuf,"\nSender:"); |
extract_header(&mail->zSender,nMsgBuf,"\nSender:"); |
| extract_header(&sNewMail->zDate,nMsgBuf,"\nDate:"); |
extract_header(&mail->zDate,nMsgBuf,"\nDate:"); |
| extract_header(&sNewMail->zContent,nMsgBuf,"\nContent-Type:"); |
extract_header(&mail->zContent,nMsgBuf,"\nContent-Type:"); |
| extract_header(&sNewMail->zEncoding,nMsgBuf,"\nContent-Transfer-Encoding:"); |
extract_header(&mail->zEncoding,nMsgBuf,"\nContent-Transfer-Encoding:"); |
| extract_header(&sNewMail->zInReplyTo,nMsgBuf,"\nIn-Reply-To:"); |
extract_header(&mail->zInReplyTo,nMsgBuf,"\nIn-Reply-To:"); |
| |
|
| sNewMail->zBody=nMsgBuf; |
mail->zBody=nMsgBuf; |
| |
|
| /* For debugging purposes, print out the headers */ |
/* For debugging purposes, print out the headers */ |
| #ifdef __POP3_DEBUG |
#ifdef __POP3_DEBUG |
| printf("libpop3: pop3_getmail: To=%s\n",sNewMail->zTo); |
printf("libpop3: pop3_getmail: To=%s\n",mail->zTo); |
| printf("libpop3: pop3_getmail: Cc=%s\n",sNewMail->zCc); |
printf("libpop3: pop3_getmail: Cc=%s\n",mail->zCc); |
| printf("libpop3: pop3_getmail: Bcc=%s\n",sNewMail->zBcc); |
printf("libpop3: pop3_getmail: Bcc=%s\n",mail->zBcc); |
| printf("libpop3: pop3_getmail: ReplyTo=%s\n",sNewMail->zReplyTo); |
printf("libpop3: pop3_getmail: ReplyTo=%s\n",mail->zReplyTo); |
| printf("libpop3: pop3_getmail: Subject=%s\n",sNewMail->zSubject); |
printf("libpop3: pop3_getmail: Subject=%s\n",mail->zSubject); |
| printf("libpop3: pop3_getmail: MessageID=%s\n",sNewMail->zMessageId); |
printf("libpop3: pop3_getmail: MessageID=%s\n",mail->zMessageId); |
| printf("libpop3: pop3_getmail: From=%s\n",sNewMail->zFrom); |
printf("libpop3: pop3_getmail: From=%s\n",mail->zFrom); |
| printf("libpop3: pop3_getmail: Sender=%s\n",sNewMail->zSender); |
printf("libpop3: pop3_getmail: Sender=%s\n",mail->zSender); |
| printf("libpop3: pop3_getmail: Date=%s\n",sNewMail->zDate); |
printf("libpop3: pop3_getmail: Date=%s\n",mail->zDate); |
| printf("libpop3: pop3_getmail: Content-Type=%s\n",sNewMail->zContent); |
printf("libpop3: pop3_getmail: Content-Type=%s\n",mail->zContent); |
| printf("libpop3: pop3_getmail: Content-Transfer-Encoding=%s\n", |
printf("libpop3: pop3_getmail: Content-Transfer-Encoding=%s\n", |
| sNewMail->zEncoding); |
mail->zEncoding); |
| printf("libpop3: pop3_getmail: In-Reply-To=%s\n",sNewMail->zInReplyTo); |
printf("libpop3: pop3_getmail: In-Reply-To=%s\n",mail->zInReplyTo); |
| #endif /* __POP3_DEBUG */ |
#endif /* __POP3_DEBUG */ |
| |
|
| /* Return the completed message */ |
/* Return the completed message */ |
| /* return(sNewMail); */ |
/* return(mail); */ |
| return POP3_OK; /* Nepto [21/10/2002] */ |
return POP3_OK; /* Nepto [21/10/2002] */ |
| } |
} |
| |
|
| |
/* |
| |
* Free the data from the mail structure |
| |
*/ |
| |
void pop3_freemail(struct pop3_mail *mail) |
| |
{ |
| |
if(mail->zTo!=0) |
| |
free(mail->zTo); |
| |
|
| |
if(mail->zCc!=0) |
| |
free(mail->zCc); |
| |
|
| |
if(mail->zBcc!=0) |
| |
free(mail->zBcc); |
| |
|
| |
if(mail->zReplyTo!=0) |
| |
free(mail->zReplyTo); |
| |
|
| |
if(mail->zSubject!=0) |
| |
free(mail->zSubject); |
| |
|
| |
if(mail->zBody!=0) |
| |
free(mail->zBody); |
| |
|
| |
if(mail->zMessageId!=0) |
| |
free(mail->zMessageId); |
| |
|
| |
if(mail->zFrom!=0) |
| |
free(mail->zFrom); |
| |
|
| |
if(mail->zSender!=0) |
| |
free(mail->zSender); |
| |
|
| |
if(mail->zDate!=0) |
| |
free(mail->zDate); |
| |
|
| |
if(mail->zContent!=0) |
| |
free(mail->zContent); |
| |
|
| |
if(mail->zEncoding!=0) |
| |
free(mail->zEncoding); |
| |
|
| |
if(mail->zInReplyTo!=0) |
| |
free(mail->zInReplyTo); |
| |
|
| |
if(mail->zHeaders!=0) |
| |
free(mail->zHeaders); |
| |
} |
| |
|
| int pop3_deletemail(int nMessageNo) |
int pop3_deletemail(int nMessageNo) |
| { |
{ |
| /* Delete the mail with the DELE command */ |
/* Delete the mail with the DELE command */ |
| Line 1131 char *strstrcase(const char *cs, const c |
|
| Line 1178 char *strstrcase(const char *cs, const c |
|
| return(NULL); |
return(NULL); |
| } |
} |
| |
|
| |
#if defined(SELF) || defined(SELFTEST) || defined(SELF_SMTP) |
| |
|
| |
#include <stdio.h> |
| |
|
| |
int main(int argc, char *argv[]) |
| |
{ |
| |
register int port = POP3_PORT; |
| |
char *server = "localhost"; |
| |
|
| |
int nMailCount=0; /* Number of mails on server */ |
| |
int nMailSize=0; /* Size of first email in bytes */ |
| |
|
| |
if (argc < 3) { |
| |
fprintf(stderr, "Usage: %s <username> <password>" |
| |
" [ <smpt_server> [ <port> ]]\n", argv[0]); |
| |
return 1; |
| |
} |
| |
if (argc > 3) { |
| |
server = argv[3]; |
| |
} |
| |
if (argc > 4) { |
| |
port = atoi(argv[4]); |
| |
if (port == 0) |
| |
port = POP3_PORT; |
| |
} |
| |
|
| |
printf("Connecting to server\n"); |
| |
|
| |
if (pop3_connect(server, port) != 0) { |
| |
printf("Error: Could not connect to server\n"); |
| |
return(1); |
| |
} |
| |
|
| |
printf("Logging in\n"); |
| |
|
| |
if (pop3_login("frodo", "gandalf") != 0) { |
| |
printf("Error: Could not login to server\n"); |
| |
/* Attempt to disconnect */ |
| |
pop3_disconnect(); |
| |
return 1; |
| |
} |
| |
|
| |
printf("Logged in\nGetting number of mails\n"); |
| |
|
| |
nMailCount = pop3_getmailcount(); |
| |
|
| |
if (nMailCount < 0) { |
| |
printf("Error: Could not get mail count\n"); |
| |
/* Attempt to disconnect */ |
| |
pop3_disconnect(); |
| |
return(1); |
| |
} |
| |
|
| |
printf("There are %i messages on the server %s:%d\n", |
| |
nMailCount, server, port); |
| |
|
| |
if (nMailCount == 0) { |
| |
printf("No mail to download\n"); |
| |
} else { |
| |
struct pop3_mail sMailMessage; /* The mail we download */ |
| |
|
| |
/* Get mail 1 */ |
| |
nMailSize = pop3_getmailsize(1); |
| |
|
| |
if (pop3_getmail(1, nMailSize, &sMailMessage)) { |
| |
printf("Error: Could not get mail no. 1\n"); |
| |
/* Attempt to disconnect */ |
| |
pop3_disconnect(); |
| |
return(1); |
| |
} |
| |
|
| |
/* Print some headers */ |
| |
|
| |
printf("To: %s\n",sMailMessage.zTo); |
| |
printf("From: %s\n",sMailMessage.zFrom); |
| |
printf("Subject: %s\n",sMailMessage.zSubject); |
| |
|
| |
pop3_freemail(&sMailMessage); |
| |
|
| |
/* Disconnect from the server */ |
| |
printf("Disconnecting from server\n"); |
| |
} |
| |
|
| |
pop3_disconnect(); |
| |
return 0; |
| |
} |
| |
|
| |
#endif |
| |
|