C++ 建立邮件客户端之收邮件(利用POP3)(二)

  • Post author:
  • Post category:其他

//发送命令,以此类推…

void SocketRM::GetUIDL()
{
	send(ServMail,"uidl\r\n",strlen("uidl\r\n"),0);
	recv(ServMail,(LPSTR)recvbuf,sizeof(recvbuf),0);
	//std::cout<<"Serve:"<<recvbuf;
	memset(recvbuf,0,20000);
	//std::cout<<"Serve:"<<std::endl;
};

//得到邮件头信息

void SocketRM::GetEmailInfo()
{
	//查看"某"个邮件的前1行
	std::cout<<"Which Email do you want?";
	std::string Choice;
	std::cin>>Choice;
	Order="top "+Choice+" 1\r\n";
	send(ServMail,Order.c_str(),strlen(Order.c_str()),0);
	
	recv(ServMail,(LPSTR)recvbuf,sizeof(recvbuf),0);
	//std::cout<<"Serve:"<<recvbuf;
	memset(recvbuf,0,20000);
	//std::cout<<"Serve:"<<std::endl;
	while(true)
	{
		//之所以要收取两次SOCKET的缓存区,是POP3中的retr命令
		//该命令会先从服务器中下载一个邮件信息——大小
		//然后会在下载邮件原文,所以要从服务器上下载两次,也就是要两次存入SOCKET缓存区
		//那么就需要recv()函数进行2次COPY.
		int val=recv(ServMail,(LPSTR)recvbuf,sizeof(recvbuf),0);
		std::cout<<recvbuf;
		bufStr+=recvbuf;
		memset(recvbuf,0,20000);
		//对于从服务器收到的邮件原文的数据:
		//对于最后的结尾,有:
		//recvbuf[val]=='\0',recvbuf[val-1]=='\n',recvbuf[val-2]=='\r',标志符
		if(recvbuf[val]=='\0')
			break;

	}
	bufStr=bufStr.c_str();
	
};

//End…


版权声明:本文为wsy526659583原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。