Fixed bug 22129 -- lack of recieve mail functionality; it turns out that we didn't handle actual message size different that the server returned message size well; we have to check for dot_fix, assumed_end and pause for more data to end incorporate complete message download; turned on auth login so we have a little security; generate X-UIDL header if needed; better cache of server capability; r=rhp

This commit is contained in:
jefft%netscape.com 2000-01-17 17:32:07 +00:00
Родитель a1b89b2a67
Коммит 9249bb4233
3 изменённых файлов: 117 добавлений и 123 удалений

Просмотреть файл

@ -648,8 +648,8 @@ nsresult nsPop3Protocol::LoadUrl(nsIURI* aURL, nsISupports * /* aConsumer */)
} }
// m_pop3ConData->next_state = POP3_READ_PASSWORD; // m_pop3ConData->next_state = POP3_READ_PASSWORD;
m_pop3ConData->next_state = POP3_WAIT_FOR_START_OF_CONNECTION_RESPONSE; m_pop3ConData->next_state = POP3_START_CONNECT;
m_pop3ConData->next_state_after_response = POP3_SEND_USERNAME; m_pop3ConData->next_state_after_response = POP3_FINISH_CONNECT;
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
return nsMsgProtocol::LoadUrl(aURL); return nsMsgProtocol::LoadUrl(aURL);
else else
@ -1116,19 +1116,6 @@ nsPop3Protocol::GetStat()
} }
} }
/*
#ifdef POP_ALWAYS_USE_UIDL_FOR_DUPLICATES
if (net_uidl_command_unimplemented && net_xtnd_xlst_command_unimplemented && net_top_command_unimplemented)
#else
if ((net_uidl_command_unimplemented && net_xtnd_xlst_command_unimplemented && net_top_command_unimplemented) ||
(!m_pop3ConData->only_uidl && !m_pop3ConData->leave_on_server &&
(m_pop3ConData->size_limit < 0 || net_top_command_unimplemented)))
#endif */
/* We don't need message size or uidl info; go directly to getting
messages. */
/* m_pop3ConData->next_state = POP3_GET_MSG;
else */ /* Fix bug 51262 where pop messages kept on server are re-downloaded after unchecking keep on server */
m_pop3ConData->next_state = POP3_SEND_LIST; m_pop3ConData->next_state = POP3_SEND_LIST;
return 0; return 0;
} }
@ -1447,12 +1434,16 @@ PRInt32 nsPop3Protocol::GetFakeUidlTop(nsIInputStream* inputStream,
*/ */
PRInt32 nsPop3Protocol::SendXtndXlstMsgid() PRInt32 nsPop3Protocol::SendXtndXlstMsgid()
{ {
if (!(m_pop3ConData->capability_flags & POP3_HAS_XTND_XLST)) if ((m_pop3ConData->capability_flags & POP3_HAS_XTND_XLST) ||
return StartUseTopForFakeUidl(); (m_pop3ConData->capability_flags & POP3_XTND_XLST_UNDEFINED))
{
m_pop3ConData->next_state_after_response = POP3_GET_XTND_XLST_MSGID; m_pop3ConData->next_state_after_response = POP3_GET_XTND_XLST_MSGID;
m_pop3ConData->pause_for_read = PR_TRUE; m_pop3ConData->pause_for_read = PR_TRUE;
return SendData(m_url, "XTND XLST Message-Id" CRLF); return SendData(m_url, "XTND XLST Message-Id" CRLF);
} }
else
return StartUseTopForFakeUidl();
}
/* km /* km
@ -1478,14 +1469,21 @@ nsPop3Protocol::GetXtndXlstMsgid(nsIInputStream* inputStream,
* but it's alright since command_succeeded * but it's alright since command_succeeded
* will remain constant * will remain constant
*/ */
if(!m_pop3ConData->command_succeeded) { if (m_pop3ConData->capability_flags & POP3_XTND_XLST_UNDEFINED)
m_pop3ConData->capability_flags &= ~POP3_XTND_XLST_UNDEFINED; m_pop3ConData->capability_flags &= ~POP3_XTND_XLST_UNDEFINED;
if(!m_pop3ConData->command_succeeded) {
m_pop3ConData->capability_flags &= ~POP3_HAS_XTND_XLST; m_pop3ConData->capability_flags &= ~POP3_HAS_XTND_XLST;
m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags); m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
m_pop3ConData->next_state = POP3_START_USE_TOP_FOR_FAKE_UIDL; m_pop3ConData->next_state = POP3_START_USE_TOP_FOR_FAKE_UIDL;
m_pop3ConData->pause_for_read = PR_FALSE; m_pop3ConData->pause_for_read = PR_FALSE;
return(0); return(0);
} }
else
{
m_pop3ConData->capability_flags |= POP3_HAS_XTND_XLST;
m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
}
PRBool pauseForMoreData = PR_FALSE; PRBool pauseForMoreData = PR_FALSE;
line = m_lineStreamBuffer->ReadNextLine(inputStream, ln, pauseForMoreData); line = m_lineStreamBuffer->ReadNextLine(inputStream, ln, pauseForMoreData);
@ -1541,13 +1539,16 @@ nsPop3Protocol::GetXtndXlstMsgid(nsIInputStream* inputStream,
PRInt32 nsPop3Protocol::SendUidlList() PRInt32 nsPop3Protocol::SendUidlList()
{ {
if (!(m_pop3ConData->capability_flags & POP3_HAS_XTND_XLST)) if ((m_pop3ConData->capability_flags & POP3_HAS_UIDL) ||
return SendXtndXlstMsgid(); (m_pop3ConData->capability_flags & POP3_UIDL_UNDEFINED))
{
m_pop3ConData->next_state_after_response = POP3_GET_UIDL_LIST; m_pop3ConData->next_state_after_response = POP3_GET_UIDL_LIST;
m_pop3ConData->pause_for_read = PR_TRUE; m_pop3ConData->pause_for_read = PR_TRUE;
return SendData(m_url,"UIDL" CRLF); return SendData(m_url,"UIDL" CRLF);
} }
else
return SendXtndXlstMsgid();
}
PRInt32 nsPop3Protocol::GetUidlList(nsIInputStream* inputStream, PRInt32 nsPop3Protocol::GetUidlList(nsIInputStream* inputStream,
@ -1562,42 +1563,21 @@ PRInt32 nsPop3Protocol::GetUidlList(nsIInputStream* inputStream,
* but it's alright since command_succeeded * but it's alright since command_succeeded
* will remain constant * will remain constant
*/ */
if(!m_pop3ConData->command_succeeded) { if (m_pop3ConData->capability_flags & POP3_UIDL_UNDEFINED)
m_pop3ConData->capability_flags &= ~POP3_UIDL_UNDEFINED;
if(!m_pop3ConData->command_succeeded)
{
m_pop3ConData->next_state = POP3_SEND_XTND_XLST_MSGID; m_pop3ConData->next_state = POP3_SEND_XTND_XLST_MSGID;
m_pop3ConData->pause_for_read = PR_FALSE; m_pop3ConData->pause_for_read = PR_FALSE;
m_pop3ConData->capability_flags &= ~POP3_HAS_UIDL; m_pop3ConData->capability_flags &= ~POP3_HAS_UIDL;
m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags); m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
return(0); return(0);
}
#if 0 /* this if block shows what UIDL used to do in this case */ else
/* UIDL doesn't work so we can't retrieve the message later, and we {
* can't play games notating how to keep it on the server. Therefore m_pop3ConData->capability_flags |= POP3_HAS_UIDL;
* just go download the whole thing, and warn the user. m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
*/
char *host, *fmt, *buf;
net_uidl_command_unimplemented = PR_TRUE;
fmt = XP_GetString( XP_THE_POP3_SERVER_DOES_NOT_SUPPORT_UIDL_ETC );
host = NET_ParseURL(ce->URL_s->address, GET_HOST_PART);
PR_ASSERT(host);
if (!host)
host = "(null)";
buf = PR_smprintf (fmt, host);
if (!buf)
return MK_OUT_OF_MEMORY;
FE_Alert (ce->window_id, buf);
PR_Free (buf);
/* Free up the msg_info structure, as we use its presence later to
decide if we can do UIDL-based games. */
net_pop3_free_msg_info(ce);
m_pop3ConData->next_state = POP3_GET_MSG;
return(0);
#endif /* 0 */
} }
PRBool pauseForMoreData = PR_FALSE; PRBool pauseForMoreData = PR_FALSE;
@ -1815,7 +1795,8 @@ nsPop3Protocol::GetMsg()
m_pop3ConData->next_state = POP3_GET_MSG; m_pop3ConData->next_state = POP3_GET_MSG;
} else if ((c != TOO_BIG) && (m_pop3ConData->size_limit > 0) && } else if ((c != TOO_BIG) && (m_pop3ConData->size_limit > 0) &&
(info->size > m_pop3ConData->size_limit) && (info->size > m_pop3ConData->size_limit) &&
!(m_pop3ConData->capability_flags & POP3_HAS_TOP) && (m_pop3ConData->capability_flags & POP3_TOP_UNDEFINED
|| (m_pop3ConData->capability_flags & POP3_HAS_TOP)) &&
(m_pop3ConData->only_uidl == NULL)) { (m_pop3ConData->only_uidl == NULL)) {
/* message is too big */ /* message is too big */
m_pop3ConData->truncating_cur_msg = PR_TRUE; m_pop3ConData->truncating_cur_msg = PR_TRUE;
@ -1876,10 +1857,8 @@ nsPop3Protocol::GetMsg()
PRInt32 PRInt32
nsPop3Protocol::SendTop() nsPop3Protocol::SendTop()
{ {
PR_ASSERT(!(m_pop3ConData->capability_flags & (POP3_HAS_UIDL | POP3_HAS_XTND_XLST | char * cmd = PR_smprintf( "TOP %ld 20" CRLF,
POP3_HAS_TOP))); m_pop3ConData->last_accessed_msg+1);
char * cmd = PR_smprintf( "TOP %ld 20" CRLF, m_pop3ConData->last_accessed_msg+1);
PRInt32 status = -1; PRInt32 status = -1;
if (cmd) if (cmd)
{ {
@ -2122,15 +2101,22 @@ nsPop3Protocol::RetrResponse(nsIInputStream* inputStream,
m_bytesInMsgReceived += buffer_size; m_bytesInMsgReceived += buffer_size;
m_totalBytesReceived += buffer_size; m_totalBytesReceived += buffer_size;
// *** jefft in case of the message size that server tells us is different
// from the actual message size
if (pauseForMoreData && m_pop3ConData->dot_fix &&
m_pop3ConData->assumed_end)
{
status =
m_nsIPop3Sink->IncorporateComplete(m_pop3ConData->msg_closure);
m_pop3ConData->msg_closure = 0;
}
if (!m_pop3ConData->msg_closure) if (!m_pop3ConData->msg_closure)
/* meaning _handle_line read ".\r\n" at end-of-msg */ /* meaning _handle_line read ".\r\n" at end-of-msg */
{ {
m_pop3ConData->pause_for_read = PR_FALSE; m_pop3ConData->pause_for_read = PR_FALSE;
if (m_pop3ConData->truncating_cur_msg || if (m_pop3ConData->truncating_cur_msg ||
(m_pop3ConData->leave_on_server && m_pop3ConData->leave_on_server )
!(m_pop3ConData->capability_flags & (POP3_HAS_UIDL |
POP3_HAS_XTND_XLST |
POP3_HAS_TOP))))
{ {
/* We've retrieved all or part of this message, but we want to /* We've retrieved all or part of this message, but we want to
keep it on the server. Go on to the next message. */ keep it on the server. Go on to the next message. */
@ -2162,6 +2148,16 @@ nsPop3Protocol::RetrResponse(nsIInputStream* inputStream,
PRInt32 PRInt32
nsPop3Protocol::TopResponse(nsIInputStream* inputStream, PRUint32 length) nsPop3Protocol::TopResponse(nsIInputStream* inputStream, PRUint32 length)
{ {
if (m_pop3ConData->capability_flags & POP3_TOP_UNDEFINED)
{
m_pop3ConData->capability_flags &= ~POP3_TOP_UNDEFINED;
if (m_pop3ConData->command_succeeded)
m_pop3ConData->capability_flags |= POP3_HAS_TOP;
else
m_pop3ConData->capability_flags &= ~POP3_HAS_TOP;
m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
}
if(m_pop3ConData->cur_msg_size == -1 && /* first line after TOP command sent */ if(m_pop3ConData->cur_msg_size == -1 && /* first line after TOP command sent */
!m_pop3ConData->command_succeeded) /* and TOP command failed */ !m_pop3ConData->command_succeeded) /* and TOP command failed */
{ {
@ -2172,11 +2168,13 @@ nsPop3Protocol::TopResponse(nsIInputStream* inputStream, PRUint32 length)
Oops. #### */ Oops. #### */
PRBool prefBool = PR_FALSE; PRBool prefBool = PR_FALSE;
m_pop3ConData->capability_flags &= ~POP3_HAS_TOP; #if 0
m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags); m_pop3Server->SetPop3CapabilityFlags(m_pop3ConData->capability_flags);
m_pop3ConData->truncating_cur_msg = PR_FALSE; m_pop3ConData->truncating_cur_msg = PR_FALSE;
#endif
PRUnichar * statusTemplate = LocalGetStringByID(POP3_SERVER_DOES_NOT_SUPPORT_THE_TOP_COMMAND); PRUnichar * statusTemplate =
LocalGetStringByID(POP3_SERVER_DOES_NOT_SUPPORT_THE_TOP_COMMAND);
if (statusTemplate) if (statusTemplate)
{ {
nsXPIDLCString hostName; nsXPIDLCString hostName;
@ -2194,7 +2192,8 @@ nsPop3Protocol::TopResponse(nsIInputStream* inputStream, PRUint32 length)
m_pop3Server->GetAuthLogin(&prefBool); m_pop3Server->GetAuthLogin(&prefBool);
if (prefBool && (POP3_XSENDER_UNDEFINED & m_pop3ConData->capability_flags || if (prefBool &&
(POP3_XSENDER_UNDEFINED & m_pop3ConData->capability_flags ||
POP3_HAS_XSENDER & m_pop3ConData->capability_flags)) POP3_HAS_XSENDER & m_pop3ConData->capability_flags))
m_pop3ConData->next_state = POP3_SEND_XSENDER; m_pop3ConData->next_state = POP3_SEND_XSENDER;
else else
@ -2515,9 +2514,9 @@ nsresult nsPop3Protocol::ProcessProtocolState(nsIURI * url, nsIInputStream * aIn
PRBool prefBool = PR_FALSE; PRBool prefBool = PR_FALSE;
m_pop3ConData->pause_for_read = PR_FALSE; m_pop3ConData->pause_for_read = PR_FALSE;
m_pop3ConData->next_state = POP3_SEND_USERNAME; // m_pop3ConData->next_state = POP3_SEND_USERNAME;
// m_pop3ConData->next_state = m_pop3ConData->next_state =
// POP3_WAIT_FOR_START_OF_CONNECTION_RESPONSE; POP3_WAIT_FOR_START_OF_CONNECTION_RESPONSE;
m_pop3Server->GetAuthLogin(&prefBool); m_pop3Server->GetAuthLogin(&prefBool);
@ -2744,11 +2743,6 @@ nsresult nsPop3Protocol::ProcessProtocolState(nsIURI * url, nsIInputStream * aIn
case POP3_INTERRUPTED: case POP3_INTERRUPTED:
SendData(mailnewsurl, "QUIT" CRLF); SendData(mailnewsurl, "QUIT" CRLF);
#if 0
/*
nnet_graceful_shutdown(ce->socket, PR_FALSE);
*/ /* make sure QUIT get send before closing down the socket */
#endif
m_pop3ConData->pause_for_read = PR_FALSE; m_pop3ConData->pause_for_read = PR_FALSE;
m_pop3ConData->next_state = POP3_ERROR_DONE; m_pop3ConData->next_state = POP3_ERROR_DONE;
break; break;
@ -2813,14 +2807,7 @@ nsresult nsPop3Protocol::ProcessProtocolState(nsIURI * url, nsIInputStream * aIn
if (server) if (server)
server->SetServerBusy(PR_FALSE); // the server is now busy server->SetServerBusy(PR_FALSE); // the server is now busy
} }
#if 0 // mscott - i believe this can be removed now
if (m_pop3ConData->graph_progress_bytes_p) {
/* Only destroy it if we have initialized it. */
FE_GraphProgressDestroy(ce->window_id, ce->URL_s,
m_pop3ConData->cur_msg_size,
m_totalBytesReceived);
}
#endif
CloseSocket(); CloseSocket();
return NS_OK; return NS_OK;
break; break;

Просмотреть файл

@ -87,51 +87,51 @@ enum Pop3CapabilityEnum {
enum Pop3StatesEnum { enum Pop3StatesEnum {
POP3_READ_PASSWORD, // 0 POP3_READ_PASSWORD, // 0
//
POP3_START_CONNECT, POP3_START_CONNECT, // 1
POP3_FINISH_CONNECT, POP3_FINISH_CONNECT, // 2
POP3_WAIT_FOR_RESPONSE, POP3_WAIT_FOR_RESPONSE, // 3
POP3_WAIT_FOR_START_OF_CONNECTION_RESPONSE, POP3_WAIT_FOR_START_OF_CONNECTION_RESPONSE, // 4
POP3_SEND_USERNAME, // 5 POP3_SEND_USERNAME, // 5
POP3_SEND_PASSWORD, POP3_SEND_PASSWORD, // 6
POP3_SEND_STAT, POP3_SEND_STAT, // 7
POP3_GET_STAT, POP3_GET_STAT, // 8
POP3_SEND_LIST, POP3_SEND_LIST, // 9
POP3_GET_LIST, // 10 POP3_GET_LIST, // 10
POP3_SEND_UIDL_LIST, POP3_SEND_UIDL_LIST, // 11
POP3_GET_UIDL_LIST, POP3_GET_UIDL_LIST, // 12
POP3_SEND_XTND_XLST_MSGID, POP3_SEND_XTND_XLST_MSGID, // 13
POP3_GET_XTND_XLST_MSGID, POP3_GET_XTND_XLST_MSGID, // 14
POP3_GET_MSG, // 15 POP3_GET_MSG, // 15
POP3_SEND_TOP, POP3_SEND_TOP, // 16
POP3_TOP_RESPONSE, POP3_TOP_RESPONSE, // 17
POP3_SEND_RETR, POP3_SEND_RETR, // 18
POP3_RETR_RESPONSE, POP3_RETR_RESPONSE, // 19
POP3_SEND_DELE, // 20 POP3_SEND_DELE, // 20
POP3_DELE_RESPONSE, POP3_DELE_RESPONSE, // 21
POP3_SEND_QUIT, POP3_SEND_QUIT, // 22
POP3_DONE, POP3_DONE, // 23
POP3_ERROR_DONE, POP3_ERROR_DONE, // 24
POP3_FREE, // 25 POP3_FREE, // 25
/* The following 3 states support the use of the 'TOP' command instead of UIDL /* The following 3 states support the use of the 'TOP' command instead of UIDL
for leaving mail on the pop server -km */ for leaving mail on the pop server -km */
POP3_START_USE_TOP_FOR_FAKE_UIDL, POP3_START_USE_TOP_FOR_FAKE_UIDL, // 26
POP3_SEND_FAKE_UIDL_TOP, POP3_SEND_FAKE_UIDL_TOP, // 27
POP3_GET_FAKE_UIDL_TOP, POP3_GET_FAKE_UIDL_TOP, // 28
POP3_SEND_AUTH, POP3_SEND_AUTH, // 29
POP3_AUTH_RESPONSE, // 25 POP3_AUTH_RESPONSE, // 30
POP3_AUTH_LOGIN, POP3_AUTH_LOGIN, // 31
POP3_AUTH_LOGIN_RESPONSE, POP3_AUTH_LOGIN_RESPONSE, // 32
POP3_SEND_XSENDER, POP3_SEND_XSENDER, // 33
POP3_XSENDER_RESPONSE, POP3_XSENDER_RESPONSE, // 34
POP3_SEND_GURL, // 30 POP3_SEND_GURL, // 35
POP3_GURL_RESPONSE, POP3_GURL_RESPONSE, // 36
#ifdef POP_ALWAYS_USE_UIDL_FOR_DUPLICATES #ifdef POP_ALWAYS_USE_UIDL_FOR_DUPLICATES
POP3_QUIT_RESPONSE, POP3_QUIT_RESPONSE,
#endif #endif

Просмотреть файл

@ -226,6 +226,13 @@ nsPop3Sink::IncorporateBegin(const char* uidlString,
char *dummyEnvelope = GetDummyEnvelope(); char *dummyEnvelope = GetDummyEnvelope();
WriteLineToMailbox(dummyEnvelope); WriteLineToMailbox(dummyEnvelope);
if (uidlString)
{
nsCAutoString uidlCString = "X-UIDL: ";
uidlCString += uidlString;
uidlCString += MSG_LINEBREAK;
WriteLineToMailbox(uidlCString);
}
WriteLineToMailbox("X-Mozilla-Status: 8000" MSG_LINEBREAK); WriteLineToMailbox("X-Mozilla-Status: 8000" MSG_LINEBREAK);
WriteLineToMailbox("X-Mozilla-Status2: 00000000" MSG_LINEBREAK); WriteLineToMailbox("X-Mozilla-Status2: 00000000" MSG_LINEBREAK);