📄 天丽鸟mail.cpp
字号:
else if(strstr(tmp, "quoted-printable"))
ctransfer = 2;
else if(strstr(tmp, "8bit"))
ctransfer = 2;
else if(strstr(tmp, "7bit"))
ctransfer = 0;
else
ctransfer = 0;
}
if(tmp = strstr(eachline, "boundary"))
{
char temp[256];
BOOL first = FALSE;
int j = 0;
memset(temp, 0, 256);
strcpy(temp, tmp + 9);
memset(boundary, 0, 256);
for(int i = 0; i < strlen(temp); i++)
{
if(temp[i] == '"')
{
if(!first)
{
first = TRUE;
continue;
}
else
break;
}
else if(first == TRUE)
{
boundary[j] = temp[i];
j++;
}
}
}
if(strstr(eachline, "Subject:"))
{
char temsub[256];
memset(temsub, 0, 256);
DecodeSub(temsub, eachline);
if(strlen(temsub) > m_maxSubject)
strncpy(subject, temsub, m_maxSubject);
else
strcpy(subject, temsub);
// else
// strcpy(subject, "主题超长,请上网接收");
}
if(strstr(eachline, "From:"))
{
int i;
char *tmp;
tmp = strstr(eachline, "<");
if(tmp == NULL)
{
strcpy(letterfrom, eachline + 5);
}
else
{
for(i = 0; i < strlen(tmp); i++)
{
if(tmp[i] == '>')
{
tmp[i] = 0;
break;
}
}
strcpy(letterfrom, tmp + 1);
}
}
}
//处理邮件体
while(TRUE)
{
if(beforeptr[0] == '\0')
break;
ptr = strstr(beforeptr, "\r\n");
if(!ptr)
return TRUE;
memset(eachline, '\0', 256);
nTmplen = ptr - beforeptr;
if(nTmplen >= 256)
nTmplen = 255;
strncpy(eachline, beforeptr, nTmplen);
if(isbody && ctype == 1)
{
char tmp1[256];
char tmp2[256];
char *t1;
char *t2;
memset(tmp1, 0, 256);
memset(tmp2, 0, 256);
strcpy(tmp1, eachline);
strcpy(tmp2, boundary);
t1 = strlwr(tmp1);
t2 = strlwr(tmp2);
if(strstr(tmp1, tmp2))
break;
}
beforeptr = ptr + 2;
if(eachline == NULL)
return TRUE;
if(ctype == 1 && isbody)
{
if(ctransfer == 0)
{
memset(buffer, '\0', sizeof(buffer));
strcpy(buffer, eachline);
}
else if(ctransfer == 1)
{
memset(buffer, '\0', sizeof(buffer));
DecodeBase64(buffer, eachline);
}
else if(ctransfer == 2)
{
memset(buffer, 0, sizeof(buffer));
DecodeQP(buffer, eachline);
}
if(strlen(tempcontent) + strlen(buffer) < m_maxContent)
{
if(buffer[0] == '\0')
strcat(tempcontent, " ");
else
strcat(tempcontent, buffer);
}
}
else if(ctype == 2)
{
isbody = FALSE;
continue;
}
else if(ctype == 4)
break;
else
{
if(eachline[0] == '-' && eachline[1] == '-')
{
isbody = FALSE;
continue;
}
if(strstr(eachline, "Content-Type"))
{
char *tmp = strlwr(eachline);
if(strstr(tmp, "text/plain"))
ctype = 1;
else if(strstr(tmp, "text/html"))
ctype = 2;
else if(strstr(tmp, "multipart/"))
{
ctype = 3;
}
else ctype = 4;
continue;
}
if(strstr(eachline, "Content-Transfer-Encoding"))
{
char *tmp = strlwr(eachline);
if(strstr(tmp, "base64"))
ctransfer = 1;
else if(strstr(tmp, "quoted-printable"))
ctransfer = 2;
else if(strstr(tmp, "8bit"))
ctransfer = 2;
else if(strstr(tmp, "7bit"))
ctransfer = 0;
else
ctransfer = 0;
continue;
}
if(tmp = strstr(eachline, "boundary"))
{
char temp[256];
BOOL first = FALSE;
int j = 0;
memset(temp, 0, 256);
strcpy(temp, tmp + 9);
memset(boundary, 0, 256);
for(int i = 0; i < strlen(temp); i++)
{
if(temp[i] == '"')
{
if(!first)
{
first = TRUE;
continue;
}
else
break;
}
else if(first == TRUE)
{
boundary[j] = temp[i];
j++;
}
}
}
if(eachline[0] == 0)
{
isbody = TRUE;
continue;
}
}
}
int i = 0;
int j = 0;
BOOL findfirst = FALSE;
for(i = 0; i < strlen(tempcontent); i++)
{
if((tempcontent[i] & 0x80) != 0)
{
if(findfirst == TRUE)
{
content[j] = tempcontent[i - 1];
j++;
content[j] = tempcontent[i];
j++;
findfirst = FALSE;
}
else
{
findfirst = TRUE;
}
}
else
{
content[j] = tempcontent[i];
j++;
findfirst = FALSE;
}
}
char strInfo[1024];
char info[512];
memset(strInfo, 0, 1024);
memset(info, 0, 512);
memset(attach, 0, 32);
if(haveattach)
strcpy(attach, "有附件");
sprintf(strInfo, "from:%s to:%s subject:%s attach: %s content:%s",letterfrom,letterto,subject,attach, content);
if(strlen(strInfo) >= 512)
{
strncpy(info, strInfo, 511);
}
else
strcpy(info, strInfo);
//ydy change
try{
if((m_accountinfo.szUid[0] == '\0') || (m_accountinfo.m_station[0] == '\0'))
return FALSE;
if(!m_mailinfo.InsertInfo((char*)m_accountinfo.szUid,m_switchinfo.m_mailservice,m_accountinfo.m_station,m_switchinfo.m_zone,info))
return FALSE;
}
catch (CException* e)
{
e->Delete();
return FALSE;
}
if(haveattach)
strcat(content, "<有附件>");
else
strcat(content, "<无附件>");
return TRUE;
}
}
BOOL Mail::GetOneMail()
{
BOOL bDecode;
switch(m_nState)
{
case STATE_DISCONNECT:
if(!m_pop3.Connect(m_strServer,m_strUser,m_strPass))
{
return FALSE;
}
if (!m_pop3.Statistics(m_nTotalMails,m_nTotalSize))
{
m_nState = STATE_FREE;
return FALSE;
}
if(m_nTotalMails > 0)
{
m_nState = STATE_CONNECT;
m_nCurrentMail = 1;
}
else
m_nState = STATE_FREE;
break;
case STATE_CONNECT:
DWORD m_size;
memset(content, 0, 512);
memset(subject, 0, 128);
memset(letterfrom, 0, 64);
memset(letterto, 0, 64);
if(!m_pop3.GetMessageSize(m_nCurrentMail, m_size))
{
m_nState = STATE_FREE;
return FALSE;
}
if(m_size >= 3*1024)
{
if (!m_pop3.GetMessageTop(m_nCurrentMail, 150, m_message))
{
m_nState = STATE_FREE;
return FALSE;
}
}
else
{
if (!m_pop3.Retrieve(m_nCurrentMail,m_message))
{
m_nState = STATE_FREE;
return FALSE;
}
}
bDecode = DecodeLetter(m_message.m_pszMessage);
if (!m_pop3.Delete(m_nCurrentMail))
{
m_nState = STATE_FREE;
return FALSE;
}
m_nCurrentMail++;
if(m_nCurrentMail > m_nTotalMails || m_nCurrentMail > 10)
{
m_nState = STATE_FREE;
}
return bDecode;
// break;
case STATE_FREE:
m_pop3.Disconnect();
m_nState = STATE_DISCONNECT;
return FALSE;
// break;
}
return FALSE;
}
UINT ReceiveMail(LPVOID pParam)
{
g_bExited = FALSE;
SReceiveMailParam* pMailParam = (SReceiveMailParam*)pParam;
HWND hwnd = pMailParam->hwnd;
Mail* pMail = pMailParam->pMail;
while(!g_bTerminate)
{
Sleep(100);
if(!pMail->GetOneMail())
continue;
::SendMessage(hwnd,UM_SHOW,MAIL_GET,(LPARAM)pMail);
}
g_bExited = TRUE;
Sleep(100);
::PostMessage(hwnd,WM_CLOSE,0,0);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -