Esempio n. 1
0
/***********************************************************************************
 **
 ** MailRecovery::GhostBuster
 ***********************************************************************************/
OP_STATUS MailRecovery::GhostBuster()
{
    Store* store = g_m2_engine->GetStore();
    // we can only run this if we have loaded all messages!
    if (!store->HasFinishedLoading())
        return OpStatus::OK;

    OpString8 indexes_with_ghosts;
    OpStringC8 log_heading("Ghostbuster");
    OpStatus::Ignore(DesktopFileLogger::Log(m_recovery_log,log_heading,"Started"));
    INT32 num_ghosts = 0;
    Index* current;
    // go through all indexes
    for (INT32 it = -1; (current = g_m2_engine->GetIndexer()->GetRange(0, IndexTypes::LAST, it)) != NULL; )
    {
        OpINT32Vector message_ids;

        if (OpStatus::IsError(current->PreFetch()) || OpStatus::IsError(current->GetAllMessages(message_ids)))
            continue;

        // go through all messages in all indexes
        for (UINT32 nb = 0; nb < message_ids.GetCount(); nb++)
        {
            INT32 message_id = message_ids.Get(nb);
            // check if the message really exists in store
            if (!store->MessageAvailable(message_id))
            {
                // we have a ghost, a message that doesn't exist in store, but exists in an index
                current->RemoveMessage(message_id);
                num_ghosts++;
                indexes_with_ghosts.AppendFormat(" %d",current->GetId());
            }
        }
    }
    OpStatus::Ignore(store->CommitData());
    OpString8 log_text;
    OpStatus::Ignore(log_text.AppendFormat("Finished: Deleted %d ghosts from the following indexes:%s", num_ghosts, indexes_with_ghosts.CStr()));
    OpStatus::Ignore(DesktopFileLogger::Log(m_recovery_log,log_heading,log_text));
    return OpStatus::OK;
}