高分求pop3收邮件的程序源代码,要求能收附件

sor 2003-07-06 03:37:24
求pop3收邮件的程序源代码,要求能收附件
jgszz@163.com
...全文
38 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
howtotell 2003-07-06
  • 打赏
  • 举报
回复
CSocket mailsock;
CString m_MailMsg;
HWND hwnd;

CString OnMailConnect(DWORD m_dwSize)
{

char* buf;
CString strbuf;
DWORD dwRead=0;
while(dwRead<m_dwSize)
{
buf=new char[2048];
memset(buf,0,2048);
UINT rec=mailsock.Receive(buf,2048,0);
dwRead+=rec;
strbuf+=buf;
delete buf;
}
return strbuf;
}





UINT mailThread(LPVOID pParam)
{
CString handMsg;
CString sendMsg;
mailsock.Create();
mailsock.Connect("pop.163.net",110);
m_MailMsg+=OnMailConnect(1);

::SetWindowText(hwnd,m_MailMsg);

sendMsg="user *****\r\n";//*****这里填入你的帐户
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
m_MailMsg+=sendMsg;
m_MailMsg+=OnMailConnect(1);

::SetWindowText(hwnd,m_MailMsg);

sendMsg="pass *****\r\n";//****这里填入你的密码
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
m_MailMsg+=sendMsg;
m_MailMsg+=OnMailConnect(1);

::SetWindowText(hwnd,m_MailMsg);

sendMsg="stat\r\n";
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
CString statMsg=OnMailConnect(1);
m_MailMsg+=sendMsg;
m_MailMsg+=statMsg;

::SetWindowText(hwnd,m_MailMsg);

statMsg.Delete(0,4);
int dashpos=statMsg.Find(" ");
statMsg.Delete(dashpos,statMsg.GetLength()-dashpos);
statMsg.Replace("\r\n","");

int mailCount=atoi(statMsg);

for(int i=1;i<mailCount+1;i++)
{
sendMsg.Format("list %d\r\n",i);
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
CString recMsg=OnMailConnect(1);
m_MailMsg+=sendMsg;
m_MailMsg+=recMsg;

::SetWindowText(hwnd,m_MailMsg);

recMsg.Delete(0,4);
int recCounter=recMsg.Find(" ");
recMsg.Delete(0,recCounter);
recMsg.Replace("\r\n","");
DWORD mailsize=atoi(recMsg);

sendMsg.Format("retr %d\r\n",i);
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
CString mailContent=OnMailConnect(mailsize);
m_MailMsg+=sendMsg;
m_MailMsg+=recMsg;
::SetWindowText(hwnd,m_MailMsg);

CString sub=mailContent;
int subPos=sub.Find("Subject:");
sub.Delete(0,subPos);
subPos=sub.Find("\r\n");
CString strSubject=sub.Left(subPos);

strSubject.Replace("Subject:","");
strSubject.Replace("\\",".");
strSubject.Replace("/",".");
strSubject.Replace(":",".");
strSubject.Replace("*",".");
strSubject.Replace("?",".");
strSubject.Replace("\"",".");
strSubject.Replace("<",".");
strSubject.Replace(">",".");
strSubject.Replace("|",".");

CString fname;
fname.Format("c:\\%s(%d).eml",strSubject,i);
CFile fp;
fp.Open(fname,CFile::modeCreate|CFile::modeWrite);
fp.Write(mailContent,mailContent.GetLength());
fp.Close();

sendMsg.Format("dele %d\r\n",i);
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
recMsg=OnMailConnect(1);
m_MailMsg+=sendMsg;
m_MailMsg+=recMsg;
::SetWindowText(hwnd,m_MailMsg);
}
sendMsg="quit\r\n";
mailsock.Send(sendMsg,sendMsg.GetLength(),0);
CString recMsg=OnMailConnect(1);
m_MailMsg+=sendMsg;
m_MailMsg+=recMsg;
::SetWindowText(hwnd,m_MailMsg);
mailsock.Close();
return 0;
}



void CMailDlg::OnRec()
{
hwnd=GetDlgItem(IDC_EDIT_MAIL)->GetSafeHwnd();
AfxBeginThread(mailThread,NULL,THREAD_PRIORITY_IDLE);
}

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧