⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailclient2server.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        EXIT_ON_FAILED (hr);

        body = toMultibyte(buffer);
        delete [] buffer;

        if (!body) {
            LOG.error("null body for message %s", msg.getSubject());
            delete mcd; mcd = 0;
            goto FuncExit;
        }

        bodyPart.setContent(body);
        msg.setBody(bodyPart);
        delete [] body;

        // Set attachments ----------------------------------------------------
        if (msgprops[ePR_HASATTACH].ulPropTag == PR_HASATTACH) {
            attachCount = msgprops[ePR_HASATTACH].Value.ul;
            GetAttachments(pmsg, mcd);
        }

        // Message Id ---------------------------------------------------------
        char *msgId = NULL;
        if (msgprops[ePR_CUSTOM_MESSAGE_ID].ulPropTag == PR_CUSTOM_MESSAGE_ID) {
            msgId = toMultibyte(msgprops[ePR_CUSTOM_MESSAGE_ID].Value.lpszW);
            if (!msgId) {
                LOG.error("completeObject: error retrieving messageId from POOM");
            }
        }
        else {
            msgId = createMessageID(mcd->getEntryId());
            id = toWideChar(msgId);
            if (id) {
                // Set message id in POOM
                rgprops[cProps].ulPropTag = PR_CUSTOM_MESSAGE_ID;
                rgprops[cProps].Value.lpszW  = id;
                ++cProps;

                rgprops[cProps].ulPropTag = PR_LAST_MODIFICATION_TIME;
                rgprops[cProps].Value.ft  = ft;
                ++cProps;

            }
            else {
                LOG.error("completeObject: error converting message id: %s", id);
            }

        }
        // Set message id in outgoing message
        msg.setMessageId(msgId);
        delete [] msgId;

        // Other headers --------------------------------------------------------
        if (msgprops[ePR_CUSTOM_MESSAGE_HEADER].ulPropTag ==
            PR_CUSTOM_MESSAGE_HEADER) {
            hdrs = toMultibyte(msgprops[ePR_CUSTOM_MESSAGE_HEADER].Value.lpszW);
            if (hdrs) {
                msg.setHeaders(hdrs);
                //delete [] hdrs;
            }
            else {
                LOG.error("completeObject: error retrieving headers.");
            }
        }

        if (cProps > 0) {
            HRESULT hhr = pmsg->SetProps(cProps, rgprops, NULL);
            int k = 0;
        }
    }

FuncExit:
    if (id) { delete [] id; id = NULL; }
    if (hdrs) {delete [] hdrs; hdrs = NULL; }
    return mcd;
}

IMAPISession* MailClient2Server::logOn() {

    IMAPISession *    pSession    =  NULL;
    HRESULT hr;
    // First log on to the store.
    hr = MAPILogonEx (NULL, NULL, NULL, NULL, &pSession);

    if (hr == S_OK)
        return pSession;
    else
        return NULL;

}

void MailClient2Server::logOff(IMAPISession* pSession) {
    if (pSession)
        RELEASE_OBJ (pSession);
}

MailClientData* MailClient2Server::getFirstItem(BOOL keyOnly) {
    LOG.debug("Enter into getFirstItem function");
    allTot = 0;
    mailAll = -2;
    elementIndex = -2;

    for (int i = 0; i < folderNumber; i++) {
        allTot += entryListArray[i].cValues;
    }

    // send nr of mails from client, slow-sync, set -1 to wParam to signal that these are items from client
    if(HwndFunctions::wnd)
        SendMessage(HwndFunctions::wnd, ID_MYMSG_TOTAL_ITEMS, SOURCE_MAIL, (LPARAM)allTot);

    if (allTot == 0) {
        LOG.debug("Exiting from getFirstItem function. No more item");
        return NULL;
    }

    if (allTot > 0) {
        mailAll++;       // from -2 -> -1
        elementIndex++;  // from -2 -> -1
    }
    arrayIndex = 0;
    LOG.debug("Exiting from getFirstItem function");
    return getNextItem(keyOnly);

}

MailClientData* MailClient2Server::getNextItem(BOOL keyOnly) {

    LOG.debug("Enter into getNextItem function");

    IMAPISession *    pSession    = NULL;
    HRESULT           hr          = NULL;
    IMessage*         pmsg        = NULL;
    ULONG             returned    = 0;
    int               tot         = 0;

    if (allTot == 0) {
        LOG.debug("Exiting from getNextItem function. No more item");
        return NULL;
    }
    MailClientData* mailClientData = NULL;

    mailAll++;
    elementIndex++;
    if (arrayIndex == folderNumber)
        return NULL;
      // if the current folder has no updated items, increments arrayIndex immediately

    if (entryListArray[arrayIndex].cValues == 0) {
        for (int k = 0; (k < folderNumber && arrayIndex < folderNumber); k++) {
            if (entryListArray[arrayIndex].cValues == 0)
                arrayIndex++;
             else
                break;
        }
    }
    pSession = logOn();

    if (pSession == NULL)
        goto FuncExit;

    if (mailAll < allTot) {

        hr = pSession->OpenEntry(entryListArray[arrayIndex].lpbin[elementIndex].cb,
            (ENTRYID*)entryListArray[arrayIndex].lpbin[elementIndex].lpb,
            NULL,
            MAPI_BEST_ACCESS,
            &returned,
            (IUnknown **) &pmsg);
        EXIT_ON_FAILED (hr);
        ASSERT (pmsg);

        mailClientData = completeObject(pmsg, folderToSync[arrayIndex], FALSE, keyOnly);

        if ((unsigned long)elementIndex == entryListArray[arrayIndex].cValues -1) {
            arrayIndex++;
            elementIndex = -1;
        }

    }

    logOff(pSession);

FuncExit:
    LOG.debug("Exiting from getNextItem function");
    return mailClientData;
}

MailClientData* MailClient2Server::getFirstNewItem() {

    LOG.debug("Enter into getFirstNewItem function");
    allTot = 0;
    mailNew = -2;       // from -2 -> -1
    elementIndex = -2;  // from -2 -> -1

    for (int i = 0; i < folderNumber; i++) {
        allTot += newMessagesArray[i].cValues;
    }

    if (allTot == 0) {
        LOG.debug("Exiting from getFirstNewItem function. No more item");
        return NULL;
    }

    if (allTot > 0) {
        mailNew++;       // from -2 -> -1
        elementIndex++;  // from -2 -> -1
    }
    arrayIndex = 0;

    LOG.debug("Exiting from getFirstNewItem function");
    return getNextNewItem();

}

MailClientData* MailClient2Server::getNextNewItem() {

    LOG.debug("Enter into getNextNewItem function");
    IMAPISession *    pSession    = NULL;
    HRESULT           hr          = NULL;
    IMessage*         pmsg        = NULL;
    ULONG             returned    = 0;
    MailClientData*   mailClientData = NULL;

    if (allTot == 0) {
        LOG.debug("Exiting from getNextNewItem function. No more item");
        return NULL;
    }

    mailNew++;
    elementIndex++;

     if (arrayIndex == folderNumber)
        return NULL;
     // if the current folder has no updated items, increments arrayIndex immediately
    if (newMessagesArray[arrayIndex].cValues == 0) {
        for (int k = 0; (k < folderNumber && arrayIndex < folderNumber); k++) {
            if (newMessagesArray[arrayIndex].cValues == 0)
                arrayIndex++;
            else
                break;
        }
    }

    pSession = logOn();

    if (pSession == NULL)
        goto FuncExit;

    if (mailNew < allTot) {

        hr = pSession->OpenEntry(newMessagesArray[arrayIndex].lpbin[elementIndex].cb,
            (ENTRYID*)newMessagesArray[arrayIndex].lpbin[elementIndex].lpb,
            NULL,
            MAPI_BEST_ACCESS,
            &returned,
            (IUnknown **) &pmsg);
        EXIT_ON_FAILED (hr);
        ASSERT (pmsg);

        mailClientData = completeObject(pmsg, folderToSync[arrayIndex], FALSE);

        if ((unsigned long)elementIndex == newMessagesArray[arrayIndex].cValues -1) {
            arrayIndex++;
            elementIndex = -1;
        }
    }

    logOff(pSession);

FuncExit:
    LOG.debug("Exiting from getNextNewItem function");
    return mailClientData;
}


MailClientData* MailClient2Server::getFirstUpdatedItem() {

    LOG.debug("Enter into getFirstUpdatedItem function");
    allTot = 0;
    mailUpdated = -2;       // from -2 -> -1
    elementIndex = -2;  // from -2 -> -1

    for (int i = 0; i < folderNumber; i++) {
        allTot += updatedMessagesArray[i].cValues;
    }

    if (allTot == 0) {
        LOG.debug("Exiting from getFirstUpdatedItem function. No more item");
        return NULL;
    }

    if (allTot > 0) {
        mailUpdated++;       // from -2 -> -1
        elementIndex++;  // from -2 -> -1
    }
    arrayIndex = 0;

    LOG.debug("Exiting from getFirstUpdatedItem function");
    return getNextUpdatedItem();

}

MailClientData* MailClient2Server::getNextUpdatedItem() {

    LOG.debug("Enter into getNextUpdatedItem function");
    IMAPISession *    pSession    = NULL;
    HRESULT           hr          = NULL;
    IMessage*         pmsg        = NULL;
    ULONG             returned    = 0;
    MailClientData*   mailClientData = NULL;

    if (allTot == 0) {
        LOG.debug("Exiting from getNextUpdatedItem function. No more item");
        return NULL;
    }

    mailUpdated++;
    elementIndex++;

     if (arrayIndex == folderNumber)
        return NULL;
    // if the current folder has no updated items, increments arrayIndex immediately
    if (updatedMessagesArray[arrayIndex].cValues == 0) {
        for (int k = 0; (k < folderNumber && arrayIndex < folderNumber); k++) {
            if (updatedMessagesArray[arrayIndex].cValues == 0)
                arrayIndex++;
            else
                break;
        }
    }
    pSession = logOn();

    if (pSession == NULL)
        goto FuncExit;

    if (mailUpdated < allTot) {

        hr = pSession->OpenEntry(updatedMessagesArray[arrayIndex].lpbin[elementIndex].cb,
            (ENTRYID*)updatedMessagesArray[arrayIndex].lpbin[elementIndex].lpb,
            NULL,
            MAPI_BEST_ACCESS,
            &returned,
            (IUnknown **) &pmsg);
        EXIT_ON_FAILED (hr);
        ASSERT (pmsg);

        //
        // The updated parameter
        //
        mailClientData = completeObject(pmsg, folderToSync[arrayIndex], TRUE);

        if ((unsigned long)elementIndex == updatedMessagesArray[arrayIndex].cValues -1) {
            arrayIndex++;
            elementIndex = -1;
        }
    }

    logOff(pSession);

FuncExit:
    LOG.debug("Exiting from getNextUpdatedItem function");
    return mailClientData;
}

MailClientData* MailClient2Server::getFirstDeletedItem() {

    LOG.debug("Enter into getFirstDeletedItem function");
    allTot = 0;
    mailDeleted  = -2;  // from -2 -> -1
    elementIndex = -2;  // from -2 -> -1

    for (int i = 0; i < folderNumber; i++) {
        allTot += deletedMessagesArray[i]->size();
    }

    if (allTot == 0) {
        LOG.debug("Exiting from getFirstDeletedItem function. No more item");
        return NULL;
    }

    if (allTot > 0) {
        mailDeleted++;       // from -2 -> -1
        elementIndex++;  // from -2 -> -1
    }
    arrayIndex = 0;

    LOG.debug("Exiting from getFirstDeletedItem function");
    return getNextDeletedItem();

}

MailClientData* MailClient2Server::getNextDeletedItem() {

    LOG.debug("Enter into getNextDeletedItem function");

    if (allTot == 0) {
        LOG.debug("Exiting from getNextDeletedItem function. No more item");
        return NULL;
    }

    MailClientData* mailClientData = NULL;
    wchar_t* r = NULL;
    mailDeleted++;
    elementIndex++;

    // if arrayIndex is the same as folder number we are at the end of the array
    if (arrayIndex == folderNumber)
        return NULL;

    // if the current folder has no deleted items, increments arrayIndex immediately
    if (deletedMessagesArray[arrayIndex]->size() == 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -