📄 pop3if.c
字号:
/*
*
* pop3if.c
*
* Part of the Myson Century CS620X demo program.
*
* Authors: LY Lin
*
* pop3if.c contains the callback functions of POP3 client routines.
*
* This program was developed using the Keil 8051 C uVision 2 system.
* The Keil compiler MUST be used if working with Myson Century supplied
* firmware.
*
* This program must be linked with the 620xlib.LIB library
* supplied by Myson Century in object module form.
*
* Note: Do not remove or rename any function in this file.
*/
#include "hpserver.h"
#include "netutil.h"
#include "pop3.h"
#include "net.h"
#include "ether.h"
#include "ip.h"
#include "tcp.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*The total messages in current mail box.*/
int total_messages=0;
int get_mail_count;
/************************************************************************
/* Callback function for POP3 Login *
/* Function Name : pop3_on_login *
/* *
/* Arguments : *
/* st_pop3 *pop3:Point to st_pop3 structure. *
/* *
/* Return : *
/* None. *
/* Comment : *
/* This function will be called when POP3 client longin to POP3*
/* server. *
/* Note:You may change it for APOP. *
/* *
/************************************************************************/
void pop3_on_login(st_pop3 *pop3)
{
TSOCK *socket;
socket=pop3->socket;
switch (pop3->status){
case POP3_LOGIN:
buff_instr(&socket->txb,"USER ");
buff_instr(&socket->txb,pop3->user_name);
buff_instr(&socket->txb,"\xd\xa");
pop3->status=POP3_LOGIN_USER;
break;
case POP3_LOGIN_USER:
buff_instr(&socket->txb,"PASS ");
buff_instr(&socket->txb,pop3->password);
buff_instr(&socket->txb,"\xd\xa");
pop3->status=POP3_LOGIN_PASS;
break;
}
}
/************************************************************************
/* Callback function for POP3 LIST Command *
/* Function Name : pop3_on_getting_mail_info *
/* *
/* Arguments : *
/* st_pop3 *pop3:Point to st_pop3 structure. *
/* char start_of_message_flag:Set if this is the start of *
/* message. *
/* char end_of_message_flag:Set if this is the end of message. *
/* *
/* Return : *
/* None. *
/* Comment : *
/* After we send LIST command to POP3 Server,the server return *
/* list data and this function be called. *
/* *
/* Related :char get_mail_info(st_pop3 *pop3,unsigned int seq_num); *
/************************************************************************/
void pop3_on_getting_mail_info(st_pop3 *pop3,char start_of_message_flag,char end_of_message_flag)
{
/*Line buffer*/
char buf[256];
char *tmp_ptr;
TSOCK *ts;
ts=pop3->socket;
if (start_of_message_flag)
total_messages=0;
/*Calculate total messages.*/
while ((buff_out_one_line(ts,buf,256))>0)
{
if (tmp_ptr=strchr(buf,' '))
{
*tmp_ptr=0;
for (tmp_ptr=buf;*tmp_ptr!=0,tmp_ptr++;)
{
if (!isdigit(*tmp_ptr))
break;
}
if (*tmp_ptr==0)
total_messages++;
}
}
/*Getting mail information have finish.*/
if (end_of_message_flag)
{
if (!total_messages)
{
/*Close POP3 client.*/
en_queue_quit_mail(pop3);
P1|=0x1;
printf("\nNo any mail");
}
else
{
P1&=0xFE;
en_queue_get_mail(pop3,1);/*Get mail .*/
get_mail_count=1;
}
}
}
/************************************************************************
/* Callback function for POP3 UIDL Command *
/* Function Name : pop3_on_getting_mail_uid *
/* *
/* Arguments : *
/* st_pop3 *pop3:Point to st_pop3 structure. *
/* char start_of_message_flag:Set if this is the start of *
/* message. *
/* char end_of_message_flag:Set if this is the end of message. *
/* *
/* Return : *
/* None. *
/* Comment : *
/* After we send UIDL command to POP3 Server,the server return *
/* Unique-ID data this function be called. *
/* *
/* Related :char en_queue_get_mail_uid(st_pop3 *pop3, *
/* unsigned int seq_num); *
/************************************************************************/
void pop3_on_getting_mail_uid(st_pop3 *pop3,char start_of_message_flag,char end_of_message_flag)
{
}
/************************************************************************
/* Callback function for POP3 RETR and TOP Command *
/* Function Name : pop3_on_getting_mail *
/* *
/* Arguments : *
/* st_pop3 *pop3:Point to st_pop3 structure. *
/* char start_of_message_flag:Set if this is the start of *
/* message. *
/* char end_of_message_flag:Set if this is the end of message. *
/* *
/* Return : *
/* None. *
/* Comment : *
/* After we send UIDL command to POP3 Server,the server return *
/* Unique-ID data this function be called. *
/* *
/* Related :char get_mail(st_pop3 *pop3,unsigned int seq_num); *
/* char en_queue_get_mail_topn(st_pop3 *pop3,unsigned *
/* int seq_num,unsigned int lines);*
/************************************************************************/
void pop3_on_getting_mail(st_pop3 *pop3,char start_of_message_flag,char end_of_message_flag)
{
char buf[256];
TSOCK *ts;
int out_size_tmp=0;
ts=pop3->socket;
/*The start of mail.*/
if (start_of_message_flag)
{
printf("\nMessage %d is :\n",pop3->curr_seq_num);
}
/*Read data from RX buffer and display in RS232*/
while (out_size_tmp=buff_out(&ts->rxb,buf,255))
{
buf[out_size_tmp]=0;
puts(buf);
}
if (get_mail_count<total_messages)
{
get_mail_count++;
en_queue_get_mail(pop3,get_mail_count);/*Get mail .*/
}
else
en_queue_quit_mail(pop3);
return ;
}
/************************************************************************
/* Callback function for POP3 Error *
/* Function Name : pop3_on_error *
/* *
/* Arguments : *
/* st_pop3 *pop3:Point to st_pop3 structure. *
/* *
/* Return : *
/* None. *
/* Comment : *
/* After an error occurred this function be called. *
/* *
/************************************************************************/
void pop3_on_error(st_pop3 *pop3)
{
char ret_val;
TSOCK *socket;
socket=pop3->socket;
printf("\nPOP3 Error Message is\n");
while (buff_out(&socket->rxb,&ret_val,1))
printf("%c",ret_val);
pop3_client_close(pop3);
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -