- Fix fetching new emails with IMAP. This closes ticket #3512.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30479 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Bruno G. Albuquerque
2009-04-29 00:58:30 +00:00
parent dc80fc5244
commit 8562115dd7
@@ -112,6 +112,8 @@ class IMAP4Client : public BRemoteMailStorageProtocol {
#endif #endif
bool force_reselect; bool force_reselect;
int32 fLastExists;
}; };
class NoopWorker : public BHandler { class NoopWorker : public BHandler {
@@ -283,7 +285,7 @@ IMAP4Client::IMAP4Client(BMessage *settings, BMailChainRunner *run) : BRemoteMai
noop = new NoopWorker(this); noop = new NoopWorker(this);
runner->AddHandler(noop); runner->AddHandler(noop);
nooprunner = new BMessageRunner(BMessenger(noop,runner),new BMessage('impn'),10e6); nooprunner = new BMessageRunner(BMessenger(noop,runner),new BMessage('impn'),10000000);
if (to_dl.CountItems() > 0) if (to_dl.CountItems() > 0)
runner->GetMessages(&to_dl,-1); runner->GetMessages(&to_dl,-1);
@@ -682,6 +684,7 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa
BString trash; BString trash;
if (SendCommand("CLOSE") < B_OK) if (SendCommand("CLOSE") < B_OK)
return B_ERROR; return B_ERROR;
selected_mb = ""; selected_mb = "";
WasCommandOkay(trash); WasCommandOkay(trash);
} }
@@ -705,7 +708,7 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa
NestedString response; NestedString response;
if (GetResponse(tag,&response) < B_OK) if (GetResponse(tag,&response) < B_OK)
return B_ERROR; return B_ERROR;
if (tag == expected) if (tag == expected)
break; break;
@@ -718,6 +721,22 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa
if ((response.CountItems() > 1) && (strcasecmp(response[1](),"RECENT") == 0)) if ((response.CountItems() > 1) && (strcasecmp(response[1](),"RECENT") == 0))
recent = atoi(response[0]()); recent = atoi(response[0]());
} }
// Whenever the mailbox is updated, only EXISTS is sent so we have no
// RECENT information. In this case we check if the mailbox increased
// its size and, if so, trick ourselves into downloading the new
// messages.
//
// TODO(bga): The IMAPClient code is in bad need of rewriting. The
// code below is just a patch to get things working until I find the
// time and motivation to rewrite it.
if (new_exists >= 0 && info->exists >= 0 && recent < 0) {
// We have EXISTS but no RECENT.
if (new_exists > info->exists) {
// The mailbox increased its size.
recent = new_exists - info->exists;
}
}
if ((queue_new_messages) && (recent > 0)) { if ((queue_new_messages) && (recent > 0)) {
BString command = "FETCH "; BString command = "FETCH ";
@@ -749,8 +768,10 @@ status_t IMAP4Client::Select(const char *mb, bool reselect, bool queue_new_messa
} }
} }
info->exists = new_exists; if (new_exists >= 0)
info->next_uid = new_next_uid; info->exists = new_exists;
if (new_next_uid >= 0)
info->next_uid = new_next_uid;
selected_mb = real_mb; selected_mb = real_mb;
} }
@@ -803,8 +824,6 @@ class IMAP4PartialReader : public BPositionIO {
if (us->GetResponse(command,&response) != NOT_COMMAND_RESPONSE && command == cmd) if (us->GetResponse(command,&response) != NOT_COMMAND_RESPONSE && command == cmd)
return; return;
//response.PrintToStream();
us->WasCommandOkay(command); us->WasCommandOkay(command);
for (int32 i = 0; (i+1) < response[2].CountItems(); i++) { for (int32 i = 0; (i+1) < response[2].CountItems(); i++) {
if (strcmp(response[2][i](),part) == 0) { if (strcmp(response[2][i](),part) == 0) {
@@ -1000,6 +1019,7 @@ IMAP4Client::ReceiveLine(BString &out)
runner->ShowError("IMAP Timeout."); runner->ShowError("IMAP Timeout.");
return B_TIMED_OUT; return B_TIMED_OUT;
} }
PRINT(("S:%s\n",out.String())); PRINT(("S:%s\n",out.String()));
return len; return len;
} }