📄 mailbox.cpp
字号:
delete szID;
}
void CMailbox::FinishReceivingID()
{
int i = m_arrayExcerpt.GetSize();
while( i-- )
{
if( !m_arrayExcerpt[i]->m_intOrder )
{
Change( COLUMN_MAIL );
delete m_arrayExcerpt[i];
m_arrayExcerpt.RemoveAt(i);
}
}
SendListRequest();
}
void CMailbox::SendListRequest()
{
int i = m_arrayExcerpt.GetSize();
while( i-- )
{
if( m_arrayExcerpt[i]->m_intSize == 0 )
{
SetState( Send( "LIST\r\n", 6 ) ?
MBOX_WF_LIST_RESPONSE : MBOX_CANNOT_SEND );
return;
}
}
SendInitialTopRequest();
}
void CMailbox::SendBurstWriteSenseRequest()
{
if( m_tServerSupportsBurstWrites.IsSet() )
{
SendUidlRequest();
}
else
{
SetState( Send( "NOOP\r\nNOOP\r\n", 12 ) ?
MBOX_WF_FIRST_NOOP : MBOX_CANNOT_SEND );
}
}
void CMailbox::SendUidlRequest()
{
for( int i = 0; i < m_arrayExcerpt.GetSize(); ++i )
{
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 ];
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_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;
while( true )
{
int iSent = CAsyncSocket::Send
(
(const char*) lpBuf + iSentTotal,
nBufLen - iSentTotal
);
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
{
return m_strLog;
}
void CMailbox::AppendToLog( const CString& strLog )
{
if( m_bLog )
{
m_strLog += strLog;
}
}
BOOL CMailbox::IsDisabled() const
{
return (m_dwFlags & MBF_PASSIVE)!=0;
}
CString CMailbox::GetPassword()
{
if ( (m_dwFlags & MBF_ASK_PASS) == 0)
{
return m_strPass;
}
return ""; // ask password? what if minimized?
}
int CMailbox::GetExtraLines()
{
if (m_nExtraLines == 255)
return 0;
return m_nExtraLines;
}
BOOL CMailbox::UpdateUnreadStatus()
{
BOOL bWasUnread = (m_nUnread > 0);
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;
BOOL bUnread = (m_nUnread > 0);
return (TRUE);//(bWasUnread != bUnread);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -