亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pop3.cpp

?? 郵件內容呼,郵件內容提取至尋呼機上,數據庫操作,郵件內容提取
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/*
Module : POP3.CPP
Purpose: Implementation for a MFC class encapsulation of the POP3 protocol
Created: PJN / 04-05-1998
History: PJN / 27-06-1998 1) Fixed a potential buffer overflow problem in Delete
                          and Retrieve functions when a large message number was
                          specified.
                          2) Improve the ReadResponse code by a) passing the 
                          readability check onto the scoket class and b) Sleeping
                          for 100 ms prior to looping around waiting for new 
                          response data
                          3) Classes are now fully Unicode compliant. Unicode
                          build configurations are also now included.
                          4) Now supports the TOP POP3 command which can be
                          issued using the GetHeader function.

         PJN / 04-01-1999 1) Properly UNICODE enabled the code

         PJN / 22-02-1999 1) Improved the reading of responses back from the server by implementing
                          a growable receive buffer
                          2) timeout is now 60 seconds when building for debug
                          3) Code now yields its time slice while waiting for a timeout
                          4) Made most functions virtual to help end user usage

         PJN / 25-03-1999 1) Fixed memory leak in the CPop3Connection::ReadReturnResponse function.
                          2) Now sleeps for 250 ms instead of yielding the time slice. This helps 
                          reduce CPU usage when waiting for data to arrive in the socket

         PJN / 15-06-1999 1) Added functions to return the message body, header or a particular
                          header field of a message
                          2) Tidied up some of the TRACE messages which the code generates

         PJN / 16-06-1999 1) Fixed a bug in the GetHeaderItem function which was causing a header
                          item which appeared at the begining of the header fields to fail to be 
                          parsed incorrectly.

         PJN / 27-06-1999 1) Fixed a bug in the GetHeaderItem function when a header spanned 
                          multiple lines as is allowed by RFC 822

         PJN / 29-06-1999 1) Another improvement to GetHeaderItem. When will it end <g>. Originally 
                          this was reported as a bug but upon further investigation it turns out that
                          the message which was causing the problems had embedded tabs in the header. 
                          This is discouraged by the RFC which refers to mail headers (RFC 822). 
                          The code has been enhanced to handle this case. Thanks to Chris Bishop 
                          for spotting this.
                          2) Fix for a bug in GetHeaderItem where I accidently was using "=" instead of
                          "==". Thanks to Angelini Fabio for spotting this.

         PJN / 05-07-1999 1) Addition of the following functions:

                          i)   CPop3Message::GetReplyTo
                          ii)  CPop3Message::GetRawBody      
                          iii) CPop3Message::GetSubject                 
	                        iv)  CPop3Message::GetFrom                    
	                        v)   CPop3Message::GetDate                    

                          2) GetHeaderItem function now uses case insensitive searching
                          3) GetHeaderItem now allows you to search for the "n'th" header of a specified type

         PJN / 24-08-99   1) Fixed a bug whereby the function GetHeader was sometimes failing when it
                          was called when the message was retrieved using the "TOP" command.
                             

Copyright (c) 1998 - 1999 by PJ Naughter.  
All rights reserved.

*/

//////////////// Includes ////////////////////////////////////////////
#include "stdafx.h"
#include <afxpriv.h>
#include "pop3.h"



//////////////// Macros //////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



//////////////// Implementation //////////////////////////////////////
CPop3Message::CPop3Message()
{
  m_pszMessage = NULL;
}

CPop3Message::~CPop3Message()
{
  if (m_pszMessage)
  {
    delete[] m_pszMessage;
	m_pszMessage = NULL;
  }
}

CString CPop3Message::GetHeaderItem(const CString& sName, int nItem) const
{
  //Value which will be returned by this function
  CString sField;

  //Get the message header (add an extra "\r\n" at the
  //begining to aid in the parsing)  
	CString sHeader(_T("\r\n"));
  sHeader += GetHeader();
  CString sUpCaseHeader(sHeader);
  sUpCaseHeader.MakeUpper();

  CString sUpCaseName(sName);
  sUpCaseName.MakeUpper();

  //Find the specified line in the header
  CString sFind(CString(_T("\r\n")) + sUpCaseName + _T(":"));
  int nFindLength = sFind.GetLength();
  int nFindStart = sUpCaseHeader.Find(sFind);
  int nFind = nFindStart;
	for (int i=0; i<nItem; i++) 
  {
    //Get ready for the next loop around
    sUpCaseHeader = sUpCaseHeader.Right(sUpCaseHeader.GetLength() - nFind - nFindLength);
    nFind = sUpCaseHeader.Find(sFind);
    
		if (nFind == -1)
			return _T(""); //Not found
    else
      nFindStart += (nFind + nFindLength);
	}

  if (nFindStart != -1)
    nFindStart += (3 + sName.GetLength());
  if (nFindStart != -1)
  {
    BOOL bFoundEnd = FALSE;
    int i = nFindStart;
    int nLength = sHeader.GetLength();
    do
    {
      //Examine the current 3 characters
      TCHAR c1 = _T('\0');
      if (i < nLength)
        c1 = sHeader[i];
      TCHAR c2 = _T('\0');
      if (i < (nLength-1))
        c2 = sHeader[i+1];
      TCHAR c3 = _T('\0');
      if (i < (nLength-2))
        c3 = sHeader[i+2];

      //Have we found the terminator
      if ((c1 == _T('\0')) ||
          ((c1 == _T('\r')) && (c2 == _T('\n')) && (c3 != _T(' ')) && c3 != _T('\t')))
      {
        bFoundEnd = TRUE;
      }
      else
      {
        //Move onto the next character  
        ++i;
      }
    }
    while (!bFoundEnd);
    sField = sHeader.Mid(nFindStart, i - nFindStart);

    //Remove any embedded "\r\n" sequences from the field
    int nEOL = sField.Find(_T("\r\n"));
    while (nEOL != -1)
    {
      sField = sField.Left(nEOL) + sField.Right(sField.GetLength() - nEOL - 2);
      nEOL = sField.Find(_T("\r\n"));
    }

    //Replace any embedded "\t" sequences with spaces
    int nTab = sField.Find(_T('\t'));
    while (nTab != -1)
    {
      sField = sField.Left(nTab) + _T(' ') + sField.Right(sField.GetLength() - nTab - 1);
      nTab = sField.Find(_T('\t'));
    }

    //Remove any leading or trailing white space from the Field Body
    sField.TrimLeft();
    sField.TrimRight();
  }

	return sField;
}

CString CPop3Message::GetHeader() const
{
  //Value which will be returned by this function
  CString sHeader;

  //Find the divider between the header and body
	CString sMessage(m_pszMessage);
  int nFind = sMessage.Find(_T("\r\n\r\n"));
  if (nFind != -1)
    sHeader = sMessage.Left(nFind);
  else
  {
    //No divider, then assume all the text is the header
    sHeader = sMessage;
  }

  return sHeader;
}

LPCSTR CPop3Message::GetRawBody() const
{
	char* pszStartBody = strstr(GetMessageText(), "\r\n\r\n");
	if (pszStartBody == NULL) 
    return NULL;
	else 
    return pszStartBody + 4;
}

CString CPop3Message::GetBody() const
{
  CString sBody;
  LPCSTR pszBody = GetRawBody();
  if (pszBody)
    sBody = pszBody;
  return sBody;
}

CString CPop3Message::GetReplyTo() const
{
	CString sRet = GetHeaderItem("Reply-To");
  if (sRet.IsEmpty())
  {
    sRet = GetFrom();
    if (sRet.IsEmpty())
    {
      sRet = GetHeaderItem(_T("Sender"));
      if (sRet.IsEmpty())
        sRet = GetHeaderItem(_T("Return-Path"));
    }
  }
	return sRet;
}

CPop3Socket::CPop3Socket()
{
  m_hSocket = INVALID_SOCKET; //default to an invalid scoket descriptor
}

CPop3Socket::~CPop3Socket()
{
  Close();
}

BOOL CPop3Socket::Create()
{
  m_hSocket = socket(AF_INET, SOCK_STREAM, 0);
  return (m_hSocket != INVALID_SOCKET);
}

BOOL CPop3Socket::Connect(LPCTSTR pszHostAddress, int nPort)
{
	//For correct operation of the T2A macro, see MFC Tech Note 59
	USES_CONVERSION;

  //must have been created first
  ASSERT(m_hSocket != INVALID_SOCKET);
  
	//Determine if the address is in dotted notation
	SOCKADDR_IN sockAddr;
	ZeroMemory(&sockAddr, sizeof(sockAddr));
	sockAddr.sin_family = AF_INET;
	sockAddr.sin_port = htons((u_short)nPort);
  char* pszAsciiHostAddress = T2A((LPTSTR) pszHostAddress);
	sockAddr.sin_addr.s_addr = inet_addr(pszAsciiHostAddress);

	//If the address is not dotted notation, then do a DNS 
	//lookup of it.
	if (sockAddr.sin_addr.s_addr == INADDR_NONE)
	{
		LPHOSTENT lphost;
		lphost = gethostbyname(pszAsciiHostAddress);
		if (lphost != NULL)
			sockAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
		else
		{
			WSASetLastError(WSAEINVAL); 
			return FALSE;
		}
	}

	//Call the protected version which takes an address 
	//in the form of a standard C style struct.
	return Connect((SOCKADDR*)&sockAddr, sizeof(sockAddr));
}

BOOL CPop3Socket::Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen)
{
	return (connect(m_hSocket, lpSockAddr, nSockAddrLen) != SOCKET_ERROR);
}

BOOL CPop3Socket::Send(LPCSTR pszBuf, int nBuf)
{
  //must have been created first
  ASSERT(m_hSocket != INVALID_SOCKET);

  return (send(m_hSocket, pszBuf, nBuf, 0) != SOCKET_ERROR);
}

int CPop3Socket::Receive(LPSTR pszBuf, int nBuf)
{
  //must have been created first
  ASSERT(m_hSocket != INVALID_SOCKET);

  return recv(m_hSocket, pszBuf, nBuf, 0); 
}

void CPop3Socket::Close()
{
	if (m_hSocket != INVALID_SOCKET)
	{
		VERIFY(SOCKET_ERROR != closesocket(m_hSocket));
		m_hSocket = INVALID_SOCKET;
	}
}

BOOL CPop3Socket::IsReadible(BOOL& bReadible)
{
  timeval timeout = {0, 0};
  fd_set fds;
  FD_ZERO(&fds);
  FD_SET(m_hSocket, &fds);
  int nStatus = select(0, &fds, NULL, NULL, &timeout);
  if (nStatus == SOCKET_ERROR)
  {
    return FALSE;
  }
  else
  {
    bReadible = !(nStatus == 0);
    return TRUE;
  }
}






CPop3Connection::CPop3Connection()
{
  m_nNumberOfMails = 0;
  m_bListRetrieved = FALSE;
  m_bStatRetrieved = FALSE;
  m_bUIDLRetrieved = FALSE;
  m_msgSizes.RemoveAll();
  m_bConnected = FALSE;
#ifdef _DEBUG
  m_dwTimeout = 60000; //default timeout of 60 seconds when debugging
#else
  m_dwTimeout = 2000;  //default timeout of 2 seconds for normal release code
#endif
}

CPop3Connection::~CPop3Connection()
{
  if (m_bConnected)
    Disconnect();
}

BOOL CPop3Connection::Connect(LPCTSTR pszHostName, LPCTSTR pszUser, LPCTSTR pszPassword, int nPort)
{
	//For correct operation of the T2A macro, see MFC Tech Note 59
	USES_CONVERSION;

  //Create the socket
  if (!m_Pop.Create())
  {
    TRACE(_T("Failed to create client socket, GetLastError:%d\n"), GetLastError());
    return FALSE;
  }

  //Connect to the POP3 Host
  if (!m_Pop.Connect(pszHostName, nPort))
  {
    TRACE(_T("Could not connect to the POP3 mailbox, GetLastError:%d\n"), GetLastError());
    return FALSE;
  }
  else
  {
    //We're now connected !!
    m_bConnected = TRUE;

    //check the response
    if (!ReadCommandResponse())
    {
      TRACE(_T("Failed while connected to read a command response from the POP3 server\n"));
      Disconnect();
      return FALSE;
    }

    //Send the POP3 username and check the response
    char sBuf[128];
    char* pszAsciiUser = T2A((LPTSTR) pszUser);
    ASSERT(strlen(pszAsciiUser) < 100); 
    sprintf(sBuf, "USER %s\r\n", pszAsciiUser);
    int nCmdLength = strlen(sBuf);
    if (!m_Pop.Send(sBuf, nCmdLength))
    {
      TRACE(_T("Failed to send the USER command to the POP3 server\n"));
      Disconnect();
      return FALSE;
    }
    if (!ReadCommandResponse())
    {
      TRACE(_T("Failed while connected to read a USER command response from the POP3 server\n"));
      Disconnect();
      return FALSE;
    } 

    //Send the POP3 password and check the response
    char* pszAsciiPassword = T2A((LPTSTR) pszPassword);
    ASSERT(strlen(pszAsciiPassword) < 100);
    sprintf(sBuf, "PASS %s\r\n", pszAsciiPassword);
    nCmdLength = strlen(sBuf);
    if (!m_Pop.Send(sBuf, nCmdLength))
    {
      TRACE(_T("Failed to send the PASS command to the POP3 server\n"));
      Disconnect();
      return FALSE;
    }
    if (!ReadCommandResponse())
    {
      TRACE(_T("Failed while connected to read a PASS command response from the POP3 server\n"));
      Disconnect();
      return FALSE;
    }
    
    return TRUE;
  }
}

BOOL CPop3Connection::Disconnect()
{          
  BOOL bSuccess = FALSE;      

  //disconnect from the POP3 server if connected 
  if (m_bConnected)
  {
    char sBuf[10];
    strcpy(sBuf, "QUIT\r\n");
    int nCmdLength = strlen(sBuf);
    if (!m_Pop.Send(sBuf, nCmdLength))
      TRACE(_T("Failed to send the QUIT command to the POP3 server\n"));

    //Check the reponse
    bSuccess = ReadCommandResponse();

    //Reset all the state variables
    m_bConnected = FALSE;
    m_bListRetrieved = FALSE;
    m_bStatRetrieved = FALSE;
    m_bUIDLRetrieved = FALSE;
  }
  else
    TRACE(_T("CPop3Connection, Already disconnected\n"));
 
  //free up our socket
  m_Pop.Close();
 
  return bSuccess;
}

BOOL CPop3Connection::Delete(int nMsg)
{
  //Must be connected to perform a delete
  ASSERT(m_bConnected);

  //if we haven't executed the LIST command then do it now
  if (!m_bListRetrieved)
    List();

  //Send the DELE command along with the message ID
	char sBuf[20];
 	sprintf(sBuf, "DELE %d\r\n", nMsg);
  int nCmdLength = strlen(sBuf);
	if (!m_Pop.Send(sBuf, nCmdLength))
  {
    TRACE(_T("Failed to send the DELE command to the POP3 server\n"));
    return FALSE;
  }

	return ReadCommandResponse();
}

BOOL CPop3Connection::Statistics(int& nNumberOfMails, int& nTotalMailSize)
{
  //Must be connected to perform a "STAT"
  ASSERT(m_bConnected);

  //Send the STAT command
	char sBuf[10];
 	strcpy(sBuf, "STAT\r\n");
  int nCmdLength = strlen(sBuf);
	if (!m_Pop.Send(sBuf, nCmdLength))
  {
    TRACE(_T("Failed to send the STAT command to the POP3 server\n"));
    return FALSE;
  }

	return ReadStatResponse(nNumberOfMails, nTotalMailSize);
}

BOOL CPop3Connection::GetMessageSize(int nMsg, DWORD& dwSize)
{
  BOOL bSuccess = TRUE;

  //if we haven't executed the LIST command then do it now
  if (!m_bListRetrieved)
    bSuccess = List();

  //nMsg must be in the correct range
  ASSERT((nMsg > 0) && (nMsg <= m_msgSizes.GetSize()));

  //retrieve the size from the message size array
  dwSize = m_msgSizes.GetAt(nMsg - 1);

  return bSuccess;
}

BOOL CPop3Connection::GetMessageID(int nMsg, CString& sID)
{
  BOOL bSuccess = TRUE;

  //if we haven't executed the UIDL command then do it now
  if (!m_bUIDLRetrieved)
    bSuccess = UIDL();

  //nMsg must be in the correct range
  ASSERT((nMsg > 0) && (nMsg <= m_msgIDs.GetSize()));

  //retrieve the size from the message size array
  sID = m_msgIDs.GetAt(nMsg - 1);

  return bSuccess;
}

BOOL CPop3Connection::List()
{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久看人人爽人人| 日一区二区三区| 亚洲成年人影院| 国产一区二区电影| 欧洲精品视频在线观看| 久久久精品国产免费观看同学| 亚洲日本在线a| 国产精品一区二区91| 欧美日韩精品一二三区| 亚洲九九爱视频| 成人黄色大片在线观看| 久久婷婷综合激情| 六月丁香婷婷色狠狠久久| 欧美色图天堂网| 1024亚洲合集| 99热精品一区二区| 中文字幕不卡在线观看| 国产九色精品成人porny| 日韩欧美国产综合一区| 午夜精品成人在线| 欧美亚洲自拍偷拍| 一区二区三区四区在线播放| 成人免费不卡视频| 国产精品天干天干在观线 | 日韩一区二区影院| 亚洲国产综合在线| 欧亚洲嫩模精品一区三区| 国产精品高潮呻吟久久| 成人免费高清在线| 欧美激情中文字幕| jlzzjlzz国产精品久久| 中文字幕一区三区| 色婷婷av一区| 一区二区三区色| 欧美日韩一区国产| 图片区日韩欧美亚洲| 欧美精品九九99久久| 午夜免费久久看| 欧美一区二区三区免费| 久久99精品国产.久久久久| 精品剧情v国产在线观看在线| 精品亚洲porn| 国产日韩精品一区| 91在线观看污| 亚洲视频在线观看一区| 色老汉一区二区三区| 午夜视频一区二区| 欧美一区二区不卡视频| 精品一区二区综合| 欧美韩日一区二区三区四区| 成人精品在线视频观看| 一区二区三区中文在线观看| 欧美视频一区二区三区四区| 日本成人在线看| 亚洲国产精华液网站w| 一本大道久久a久久综合婷婷| 亚洲成人在线观看视频| 欧美精品一区二区在线观看| 成人理论电影网| 亚洲成在人线在线播放| 精品国产污网站| 91麻豆蜜桃一区二区三区| 视频一区免费在线观看| 久久精品男人天堂av| 在线观看一区日韩| 国模大尺度一区二区三区| 亚洲精品视频自拍| 欧美精品一区二区精品网| 91原创在线视频| 久99久精品视频免费观看| 最新热久久免费视频| 欧美一区二区三区小说| 成人午夜av影视| 日本色综合中文字幕| 国产精品高潮呻吟| 欧美电影免费观看高清完整版 | 在线观看av一区二区| 韩国精品免费视频| 玉足女爽爽91| 中文字幕不卡在线播放| 欧美一区二区啪啪| 欧美视频一二三区| 成人h版在线观看| 精品在线一区二区三区| 亚洲国产精品视频| **欧美大码日韩| 欧美极品xxx| 日韩欧美一级二级三级| 91成人在线免费观看| 国产99精品视频| 久久国产三级精品| 五月天久久比比资源色| 亚洲欧美成人一区二区三区| 久久久91精品国产一区二区精品 | 精品福利av导航| 欧美人伦禁忌dvd放荡欲情| 成人午夜视频在线| 韩国av一区二区三区在线观看| 视频一区在线视频| 亚洲第一狼人社区| 亚洲国产一二三| 艳妇臀荡乳欲伦亚洲一区| 亚洲天堂av老司机| 中文字幕综合网| 亚洲欧洲成人自拍| 欧美高清在线精品一区| 久久精品人人做人人综合| 精品久久久久久久久久久久久久久 | 亚洲私人影院在线观看| 国产欧美日韩不卡免费| 亚洲精品一区二区三区在线观看 | 久久国产精品露脸对白| 蜜臀av亚洲一区中文字幕| 天堂午夜影视日韩欧美一区二区| 亚洲精品日韩专区silk| 亚洲色图在线播放| 亚洲老妇xxxxxx| 亚洲综合色区另类av| 亚洲黄网站在线观看| 一区二区三区不卡视频在线观看 | 国产精品美女久久久久av爽李琼| 久久久噜噜噜久久中文字幕色伊伊 | 国产欧美一区二区三区沐欲| 久久你懂得1024| 欧美激情一二三区| 亚洲欧美偷拍卡通变态| 亚洲伊人色欲综合网| 视频一区二区三区中文字幕| 日韩经典中文字幕一区| 狠狠色丁香九九婷婷综合五月| 国产精品一级片| 99精品在线免费| 欧美日韩高清一区| 日韩视频免费观看高清完整版| 日韩欧美成人激情| 国产午夜精品久久久久久免费视 | www.在线欧美| 欧洲人成人精品| 6080午夜不卡| 国产女人18毛片水真多成人如厕| 国产精品美女久久久久aⅴ| 亚洲精品免费视频| 美女网站视频久久| 国产精品一区二区无线| 色嗨嗨av一区二区三区| 9191精品国产综合久久久久久 | 日韩欧美一区在线观看| 久久精品男人的天堂| 一区二区三区四区不卡在线| 日韩高清电影一区| 成人理论电影网| 精品视频在线免费观看| 久久久亚洲欧洲日产国码αv| 亚洲日本va午夜在线影院| 蜜桃免费网站一区二区三区| 成人午夜在线视频| 欧美日韩不卡一区| 国产女人水真多18毛片18精品视频| 伊人色综合久久天天| 国产精品一区二区在线观看网站| 在线观看亚洲a| 国产亚洲一区二区三区在线观看| 亚洲午夜免费视频| 成人app软件下载大全免费| 91精品国产综合久久香蕉麻豆 | 久久综合久久99| 亚洲六月丁香色婷婷综合久久 | 丝袜诱惑制服诱惑色一区在线观看| 国产不卡视频在线观看| 日韩视频免费直播| 亚洲成人资源网| 91浏览器打开| 国产精品国产三级国产普通话蜜臀| 美腿丝袜在线亚洲一区| 欧美三级电影精品| 亚洲日本在线观看| 成人丝袜高跟foot| 久久综合精品国产一区二区三区| 婷婷成人激情在线网| 在线影视一区二区三区| 国产精品久久久久四虎| 国产精品1024久久| 久久综合九色欧美综合狠狠| 麻豆精品一区二区av白丝在线| 欧美日韩美少妇| 亚洲国产日韩综合久久精品| 色94色欧美sute亚洲线路一ni| 国产精品日韩成人| 成人爱爱电影网址| 中文字幕精品三区| 国产91丝袜在线播放| 久久免费电影网| 国产一区二区不卡| 久久久亚洲高清| 成人免费视频caoporn| 欧美韩国日本不卡| 成人涩涩免费视频| 国产三级精品在线| a在线欧美一区| 怡红院av一区二区三区|