?? mailbox.cpp
字號:
{
m_arrayExcerpt[i]->m_intOrder = 0;
}
if( m_tServerSupportsUIDL )
{
SetState( Send( "UIDL\r\n", 6 ) ?
MBOX_WF_UIDL_RESPONSE : MBOX_CANNOT_SEND );
}
else
{
m_intOrder = 0;
SendTopExRequest();
}
}
void CMailbox::SendTopExRequest()
{
char szPacket[80];
sprintf( szPacket, "TOP %d %d\r\n", ++m_intOrder, GetExtraLines() );
// TRACE1( "\nsend: %s", szPacket );
SetState( Send( szPacket, strlen( szPacket ) ) ?
MBOX_WF_TOPEX_RESPONSE : MBOX_CANNOT_SEND );
}
void CMailbox::SendTopFRequest()
{
char szPacket[80];
strcpy( szPacket, "TOP 1 0\r\n" );
SetState( Send( szPacket, strlen( szPacket ) ) ?
MBOX_WF_TOPF_RESPONSE : MBOX_CANNOT_SEND );
}
bool CMailbox::SendTopRequest( unsigned uIndex )
{
char szPacket[ 16 ];
sprintf( szPacket, "TOP %d %d\r\n",
m_arrayExcerpt[ m_aIndices[ uIndex ] ]->m_intOrder, GetExtraLines() );
return Send( szPacket, strlen( szPacket ) );
}
void CMailbox::SendTopRequest()
{
if( m_aIndices.GetSize() > 0 )
{
if( m_tServerSupportsBurstWrites )
{
return;
}
else
{
SendTopRequest( 0 );
}
}
else
{
SendInitialTopRequest();
}
}
void CMailbox::SendInitialTopRequest()
{
m_aIndices.RemoveAll();
int i = m_arrayExcerpt.GetSize();
while( i-- )
{
if( !m_arrayExcerpt[i]->m_bitFilled )
{
m_aIndices.Add( i );
}
}
if( m_aIndices.GetSize() == 0 )
{
SendInitialRetrRequest();
}
else
{
if( m_tServerSupportsBurstWrites )
{
for( int i = 0; i < m_aIndices.GetSize(); ++i )
{
if( !SendTopRequest( i ) )
{
if( i == 0 )
{
SetState( MBOX_CANNOT_SEND );
}
else
{
// outbound buffer is full
// stop sending for now -- truncate the array
m_aIndices.RemoveAt( i, m_aIndices.GetSize() - i );
}
}
}
}
else
{
SendTopRequest( 0 );
}
SetState( MBOX_WF_TOP_RESPONSE );
}
}
void CMailbox::SendRetrRequest( unsigned uIndex )
{
char szPacket[ 16 ];
if (m_dwFlags & MBF_NO_RETR)
sprintf( szPacket, "TOP %d 100\r\n", m_arrayExcerpt[ m_aIndices[ uIndex ] ]->m_intOrder );
else
sprintf( szPacket, "RETR %d\r\n", m_arrayExcerpt[ m_aIndices[ uIndex ] ]->m_intOrder );
SetState( Send( szPacket, strlen( szPacket ) ) ?
MBOX_WF_RETR_RESPONSE : MBOX_CANNOT_SEND );
}
void CMailbox::SendRetrRequest()
{
if( m_aIndices.GetSize() > 0 )
{
if( m_tServerSupportsBurstWrites )
{
return;
}
else
{
SendRetrRequest( 0 );
}
}
else
{
SendInitialDeleRequest();
}
}
void CMailbox::SendInitialRetrRequest()
{
m_aIndices.RemoveAll();
int i = m_arrayExcerpt.GetSize();
while( i-- )
{
if( m_arrayExcerpt[i]->m_bitDownloadData ||
m_arrayExcerpt[i]->m_bitPreviewData)
{
m_aIndices.Add( i );
}
}
if( m_aIndices.GetSize() == 0 )
{
SendInitialDeleRequest();
}
else
{
if( m_tServerSupportsBurstWrites )
{
for( int i = 0; i < m_aIndices.GetSize(); ++i )
{
SendRetrRequest( i );
}
}
else
{
SendRetrRequest( 0 );
}
}
}
//
// DELE
//
void CMailbox::SendInitialDeleRequest()
{
m_aIndices.RemoveAll();
// we traverse in the reverse order, so that when we remove
// Excerpts from an array, other indices remain the same
int i = m_arrayExcerpt.GetSize();
while( i-- )
{
if( !m_arrayExcerpt[i]->m_bitProtected && m_arrayExcerpt[i]->m_bitRemoveFromServer )
{
m_aIndices.Add( i );
}
}
if( m_aIndices.GetSize() == 0 )
{
SendQuitRequest( MBOX_CHECKED );
}
else
{
if( m_tServerSupportsBurstWrites )
{
for( int i = 0; i < m_aIndices.GetSize(); ++i )
{
SendDeleRequest( i );
}
}
else
{
SendDeleRequest( 0 );
}
}
}
void CMailbox::SendDeleRequest( unsigned uIndex )
{
char szPacket[16];
sprintf( szPacket, "DELE %d\r\n", m_arrayExcerpt[ m_aIndices[ uIndex ] ]->m_intOrder );
SetState( Send( szPacket, strlen( szPacket ) ) ?
MBOX_WF_DELE_RESPONSE : MBOX_CANNOT_SEND );
}
void CMailbox::SendDeleRequest()
{
if( m_aIndices.GetSize() > 0 )
{
if( m_tServerSupportsBurstWrites )
{
return;
}
else
{
SendDeleRequest( 0 );
}
}
else
{
SendQuitRequest( MBOX_CHECKED );
}
}
//
// QUIT
//
void CMailbox::SendQuitRequest( int intState )
{
SetState( Send( "QUIT\r\n", 6 ) ?
intState : MBOX_CANNOT_SEND );
}
void CMailbox::CancelPendingJobs()
{
if( m_hResolveJob )
{
WSACancelAsyncRequest( m_hResolveJob );
m_hResolveJob = 0;
}
if( m_pResolveBuffer )
{
delete m_pResolveBuffer;
m_pResolveBuffer = NULL;
}
m_arrayPacket.RemoveAll();
m_aIndices.RemoveAll();
}
bool CMailbox::Send( const void* lpBuf, int nBufLen )
{
int iSentTotal = 0;
/// Do not send too many requests to avoid choke, which sometimes happens
time_t t;
time(&t);
if (t-m_nStatTime <2)
m_nStatCur++;
else
{
m_nStatTime = (int)t;
if (m_nStatCur>m_nStatMax)
m_nStatMax = m_nStatCur;
m_nStatCur = 0;
}
while( true )
{
int iSent = 0;
#ifdef USE_SSL
if (m_pSSL)
iSent = m_SSL.WriteString((const char*) lpBuf + iSentTotal, nBufLen - iSentTotal);
else
#endif
iSent = CAsyncSocket::Send
(
(const char*) lpBuf + iSentTotal,
nBufLen - iSentTotal
);
if ((m_pSSL && m_nStatCur > 40) || (m_nStatCur >=150) )
{
Sleep(250);
m_nStatCur = 0;
m_nStatTime = 0;
}
if( iSent == SOCKET_ERROR )
{
if( iSentTotal > 0 )
{
AppendToLog( "Sent: " );
AppendToLog( CString( (char*) lpBuf, iSentTotal ) );
}
return false;
}
else
{
iSentTotal += iSent;
if( iSentTotal == nBufLen )
{
AppendToLog( "Sent: " );
if( ( nBufLen > 4 )
&& ((char*) lpBuf)[0] == 'P'
&& ((char*) lpBuf)[1] == 'A'
&& ((char*) lpBuf)[2] == 'S'
&& ((char*) lpBuf)[3] == 'S'
)
{
AppendToLog( "PASS ********\r\n" );
}
else
{
AppendToLog( CString( (char*) lpBuf, iSentTotal ) );
}
return true;
}
Sleep( 1 );
}
}
}
void CMailbox::OnClose( int /*nErrorCode*/ )
{
if( !STATE_FINAL( m_intState ) )
{
if( m_intState == MBOX_WF_USER_RESPONSE )
{
// not sure about this, but this can be a reason for "1st check" bug
//if (!m_tServerSupportsAPOP.IsSet() || m_tServerSupportsAPOP)
{
m_tServerSupportsAPOP = false;
Check();
}
}
else
{
if( m_intState == MBOX_WF_FIRST_NOOP )
{
// pop3.freenet.de cannot handle "NOOP<CRLF>NOOP<CRLF>" !!!
// it drops the connection, maybe it crashes or something..
m_tServerSupportsBurstWrites = false;
Check();
}
else if( m_intState == MBOX_WF_APOP_RESPONSE && !m_tServerSupportsAPOP.IsSet() )
{
m_tServerSupportsAPOP = false;
Check();
}
else
{
SetState( MBOX_CONNECTION_WAS_LOST );
}
}
}
}
const CString& CMailbox::GetGreeting() const
{
return m_sServerGreeting;
}
unsigned CMailbox::GetIPAddress() const
{
return m_ulongIP;
}
const Tristate& CMailbox::GetAPOPSupported() const
{
return m_tServerSupportsAPOP;
}
const Tristate& CMailbox::GetUIDLSupported() const
{
return m_tServerSupportsUIDL;
}
const Tristate& CMailbox::GetBurstWritesSupported() const
{
return m_tServerSupportsBurstWrites;
}
void CMailbox::WatchDogTimedOut()
{
if( m_intState == MBOX_WF_SECOND_NOOP )
{
m_tServerSupportsBurstWrites = false;
// at this point, we may get into a deadlock situation
// because the command sequence may have been violated by
// a delay
// SendUidlRequest();
Check();
}
}
bool CMailbox::IsLoggingEnabled() const
{
return m_bLog;
}
void CMailbox::EnableLogging( bool bValue )
{
if( !bValue )
{
m_strLog.Empty();
}
m_bLog = bValue;
}
const CString& CMailbox::GetLogString() const
{
static CString s;
s.Format(_T("%d\n\n"), m_nStatMax);
s += m_strLog;
return s;
//return m_strLog;
}
void CMailbox::AppendToLog( const CString& strLog )
{
if( m_bLog )
{
m_strLog += strLog;
TRACE(_T("\n==========log======"));
TRACE(strLog);
TRACE(_T("\n"));
}
}
BOOL CMailbox::IsDisabled() const
{
return (m_dwFlags & MBF_PASSIVE)!=0;
}
CString CMailbox::GetPassword()
{
if (!m_strPass.IsEmpty()) // entered or saved
return m_strPass;
if ( m_dwFlags & MBF_ASK_PASS)
{
DPassword dlg(FALSE, m_strAlias);
if (dlg.DoModal() == IDOK)
{
m_strPass = dlg.m_sPassword;
return m_strPass;
}
}
return ""; // ask password? what if minimized?
}
int CMailbox::GetExtraLines()
{
if (m_nExtraLines == 255)
return 0;
return m_nExtraLines;
}
BOOL CMailbox::UpdateUnreadStatus()
{
int nNew = 0;
for (int m=0; m<m_arrayExcerpt.GetSize(); m++)
{
if (m_arrayExcerpt[m] &&
!m_arrayExcerpt[m]->WasRead())
nNew++;
}
if (m_nUnread == nNew)
return FALSE;
m_nUnread = nNew;
return (TRUE);//(bWasUnread != bUnread);
}
CMailBoxClip::CMailBoxClip() : CClipBoard(_T("MAGIC_MAILBOX"))
{
}
CMailBoxClip::~CMailBoxClip()
{
Cleanup();
}
void CMailBoxClip::Cleanup()
{
for (int i=0; i<m_aData.GetSize(); i++)
delete m_aData[i];
m_aData.RemoveAll();
}
BOOL CMailBoxClip::SaveData(CMailbox** pData, int nCount)
{
Cleanup();
for (int i=0; i<nCount; i++, pData++)
m_aData.Add(*pData);
int nRet = CopyToClipboard();
m_aData.RemoveAll(); // clean up - do not delete objects!
return nRet;
}
CMailbox** CMailBoxClip::GetData(int& nCount)
{
Cleanup();
m_aData.RemoveAll();
if (!PasteFromClipboard())
return NULL;
nCount = m_aData.GetSize();
return (CMailbox**)m_aData.GetData();
}
BOOL CMailBoxClip::Serialize(CArchive& ar)
{
BYTE bVer = 1;
if (ar.IsStoring())
{
ar << bVer;
BYTE bC = (BYTE)m_aData.GetSize();
ar << bC;
m_aData.Serialize(ar);
}
else
{
BYTE b = 0;
ar >> b;
if (b>bVer || b==0)
return FALSE;
ar >> b;
m_aData.Serialize(ar);
if (m_aData.GetSize()!=b)
return FALSE;
}
return TRUE;
}
void CMailbox::OnSSLEvent(int nEv)
{
switch (nEv)
{
case 1:
OnConnect(0);
break;
case 2:
if (m_SSL.GetData(NULL, 0))
OnReceive(0);
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -