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

📄 mailserver2client.cpp

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

    ASSERT(rgprops);
    ASSERT(rgprops[0].ulPropTag == PR_IPM_OUTBOX_ENTRYID);

    hr = pStore->OpenEntry (rgprops[0].Value.bin.cb,
                            (LPENTRYID)rgprops[0].Value.bin.lpb,
                            NULL,
                            MAPI_MODIFY,
                            NULL,
                            (IUnknown **) &pfldrOutbox);

    EXIT_ON_FAILED(hr);

    hr = pfldrOutbox->GetContentsTable(0, &pContentsTable);
    EXIT_ON_FAILED(hr);

    hr = pContentsTable->SetColumns((LPSPropTagArray)&Columns, 0);
    EXIT_ON_FAILED(hr);

    // iterate message one by one (each time only read 1)
    while(!FAILED(hr = pContentsTable->QueryRows(1, 0, &pRows))) {
        // this is the end of the content table
        if(pRows->cRows == 0) break;

        // check this Row
        aRow = pRows->aRow[0];

        // Correctly returned?
        if ((&aRow.lpProps[ePR_ENTRYID])->ulPropTag == PR_ENTRYID
            && (&aRow.lpProps[ePR_CUSTOM_MESSAGE_ID])->ulPropTag == PR_CUSTOM_MESSAGE_ID) {

            // Is CUSTOM_MESSAGE_ID found?
            wchar_t* mm = (&aRow.lpProps[ePR_CUSTOM_MESSAGE_ID])->Value.lpszW;

            // the message-id there is in the client has the O/AABBCC....
            // the message-id sent by server could have only AABBCC...

            if (wcsstr(mm, msgID) != 0) {

                wchar_t* entryId = convertBinaryToWChar(aRow.lpProps[ePR_ENTRYID].Value.bin, 'O');
                char* eid = NULL;
                size_t len = decodeEntryId(entryId, &eid);
                if(!eid){
                    LOG.error("messageExistInOubox_deleteIt: error decoding entryId");
                    return false;
                }

                ENTRYLIST entryList;

                entryList.cValues = 0;
                MAPIAllocateBuffer(sizeof(SBinary), (LPVOID*)&(entryList.lpbin));
                entryList.lpbin[entryList.cValues].cb = len;
                MAPIAllocateBuffer(len, (LPVOID*)&(entryList.lpbin[entryList.cValues].lpb) );
                memmove(entryList.lpbin[entryList.cValues].lpb, eid, len);
                entryList.cValues++;

                delete [] eid;
                delete [] entryId;

                hr = pfldrOutbox->DeleteMessages (&entryList, 0, NULL, 0);
                EXIT_ON_FAILED (hr);
                bFound = true;

                break;
            }
        } // if

        // Free pRows for each row
        FreeProws(pRows);
        pRows = NULL;
    } // while

FuncExit:
    if(pRows) {
        // Free each element in the pRows buffer
        FreeProws(pRows);
        pRows = NULL;
    }
    RELEASE_OBJ(pContentsTable);

    if (msgID)  {
        delete [] msgID; msgID = NULL;
    }

    return bFound;
}


wchar_t* MailServer2Client::doesMessageExist (IN const char* msgid, LPMAPIFOLDER pfldrInbox, wchar_t folder) {

    if (msgid == NULL)
        return false;

    wchar_t* msgID = toWideChar(msgid);
    HRESULT hr = S_OK;
    wchar_t* ret = NULL;
    SBinary    sbEntry = {0};
    LPMAPITABLE pContentsTable = NULL;
    LPSRowSet pRows = NULL;
    SRow aRow = {0};

    enum {
        ePR_ENTRYID,            // 0
        ePR_CUSTOM_MESSAGE_ID,            // 2
        NUM_COLS                // number of columns (put it to the end)
    };

    // These tags represent the message information we would like to pick up
    SizedSPropTagArray(NUM_COLS, Columns) =
    {
        NUM_COLS,
        PR_ENTRYID,
        PR_CUSTOM_MESSAGE_ID
    };

    hr = pfldrInbox->GetContentsTable(0, &pContentsTable);
    EXIT_ON_FAILED(hr);

    hr = pContentsTable->SetColumns((LPSPropTagArray)&Columns, 0);
    EXIT_ON_FAILED(hr);

    // iterate message one by one (each time only read 1)
    while(!FAILED(hr = pContentsTable->QueryRows(1, 0, &pRows))) {
        // this is the end of the content table
        if(pRows->cRows == 0) break;

        // check this Row
        aRow = pRows->aRow[0];

        // Correctly returned?
        if ((&aRow.lpProps[ePR_ENTRYID])->ulPropTag == PR_ENTRYID
            && (&aRow.lpProps[ePR_CUSTOM_MESSAGE_ID])->ulPropTag == PR_CUSTOM_MESSAGE_ID) {

            // Is CUSTOM_MESSAGE_ID found?
            wchar_t* mm = aRow.lpProps[ePR_CUSTOM_MESSAGE_ID].Value.lpszW;
            if (wcscmp(mm, msgID) == 0) {
                ret = convertBinaryToWChar(aRow.lpProps[ePR_ENTRYID].Value.bin, folder);
                break;
            }
        } // if

        // Free pRows for each row
        FreeProws(pRows);
        pRows = NULL;
    } // while

FuncExit:
    if(pRows) {
        // Free each element in the pRows buffer
        FreeProws(pRows);
        pRows = NULL;
    }
    RELEASE_OBJ(pContentsTable);

    if (msgID)  {
        delete [] msgID; msgID = NULL;
    }

    return ret;
}



HRESULT SetReplyTo(LPMAPISESSION lpSession, IMessage* lpMessage, LPSTR pszReplyTo)
{

    HRESULT hRes = S_OK;
    LPADRLIST lpAddrList = NULL;
    LPADRBOOK lpAddrBook = NULL;
    SPropValue pspvReply[2];
    LPFLATENTRYLIST lpReplyEntryList = NULL;
    LPFLATENTRY lpReplyEntry = NULL;
    int cValues = 2;
    ULONG i = 0;

    // Allocate an address list structure.
    int cb = CbNewADRLIST(1);

    hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpAddrList);
    if (FAILED(hRes)) goto Cleanup;

    ZeroMemory(lpAddrList, cb);

    hRes = MAPIAllocateBuffer(
        cValues * sizeof(SPropValue),
        (LPVOID FAR *)&lpAddrList->aEntries[0].rgPropVals);
    if (FAILED(hRes)) goto Cleanup;

    // Open the address book to resolve Reply To recipient.
    hRes = lpSession->OpenAddressBook(0, NULL, 0, &lpAddrBook);
    if (FAILED(hRes)) goto Cleanup;

    // Set up address list structure.
    lpAddrList->cEntries = 1;
    lpAddrList->aEntries[0].rgPropVals[0].ulPropTag = PR_DISPLAY_NAME;
    lpAddrList->aEntries[0].rgPropVals[0].Value.lpszA = pszReplyTo;

    lpAddrList->aEntries[0].rgPropVals[1].ulPropTag = PR_RECIPIENT_TYPE;
    lpAddrList->aEntries[0].rgPropVals[1].Value.l = MAPI_TO;
    lpAddrList->aEntries[0].cValues = cValues;

    // Resolve name.
    hRes = lpAddrBook->ResolveName(0, 0, NULL, lpAddrList);
    if (FAILED(hRes)) goto Cleanup;

    // Get the Entry ID.
    for (i = 0; i < lpAddrList->aEntries[0].cValues; i++)
    {
        if (lpAddrList->aEntries[0].rgPropVals[i].ulPropTag == PR_ENTRYID)
        {
            // Allocate a new FLATENTRY structure for
            // the PR_REPLY_RECIPIENT_ENTRIES property.
            cb = CbNewFLATENTRY(
                   lpAddrList->aEntries[0].rgPropVals[i].Value.bin.cb);
            hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpReplyEntry);
            if (FAILED(hRes)) goto Cleanup;
            ZeroMemory((VOID *)lpReplyEntry, cb);

            // Copy the bits of the Entry ID into the FLATENTRY structure.
            CopyMemory(lpReplyEntry->abEntry,
                       lpAddrList->aEntries[0].rgPropVals[i].Value.bin.lpb,
                       lpAddrList->aEntries[0].rgPropVals[i].Value.bin.cb);
            lpReplyEntry->cb = lpAddrList->
                                 aEntries[0].rgPropVals[i].Value.bin.cb;

            // Allocate a new FLATENTRYLIST structure.
            // This is what is stored in PR_REPLY_RECIPIENT_ENTRIES.
            cb = CbNewFLATENTRYLIST(cb);
            hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpReplyEntryList);
            if (FAILED(hRes)) goto Cleanup;
            ZeroMemory((VOID *)lpReplyEntryList, cb);

            // Copy the bits of the FLATENTRY into the FLATENTRYLIST.
            lpReplyEntryList->cEntries  = 1;
            lpReplyEntryList->cbEntries = CbFLATENTRY(lpReplyEntry);
            CopyMemory(lpReplyEntryList->abEntries,
                       lpReplyEntry, CbFLATENTRY(lpReplyEntry));

            // Force exit from the loop.
            i = lpAddrList->aEntries[0].cValues;
        }
    }

    // Set PR_REPLY_RECIPIENT_NAMES.
    pspvReply[0].ulPropTag = PR_REPLY_RECIPIENT_NAMES;
    pspvReply[0].Value.lpszA = pszReplyTo;

    // Set PR_REPLY_RECIPIENT_ENTRIES.
    pspvReply[1].ulPropTag = PR_REPLY_RECIPIENT_ENTRIES;
    // Allocate memory in the lpb to hold the FLATENTRYLIST
    hRes = MAPIAllocateBuffer(CbFLATENTRYLIST(lpReplyEntryList),
                              (LPVOID *)&pspvReply[1].Value.bin.lpb);
    // Copy the memory into the SPropValue.
    CopyMemory(pspvReply[1].Value.bin.lpb,
               lpReplyEntryList,
               CbFLATENTRYLIST(lpReplyEntryList));
    pspvReply[1].Value.bin.cb = CbFLATENTRYLIST(lpReplyEntryList);

    // Set the properties.
    hRes = lpMessage->SetProps(2,
                               pspvReply,
                               NULL);

Cleanup:
    if (lpReplyEntry) MAPIFreeBuffer(lpReplyEntry);
    if (lpReplyEntryList) MAPIFreeBuffer(lpReplyEntryList);
    //if (lpAddrList) FreePadrlist(lpAddrList);
    if (lpAddrBook) lpAddrBook->Release();
    return hRes;
}

char* getMessageID(IMessage* pmsg, MailClientData* m) {

    SPropValue* msgprops = NULL;
    ULONG    cmsgValue =  0;
    char* id = NULL;
    HRESULT hr = pmsg->GetProps ((LPSPropTagArray)&Columns, MAPI_UNICODE, &cmsgValue,
       &msgprops);
    EXIT_ON_FAILED (hr);

    if ( !msgprops ) {
        LOG.error("getMessageID: can't get message props.");
        goto FuncExit;
    }

    if (msgprops[ePR_ENTRYID].ulPropTag != PR_ENTRYID) {
        LOG.error("getMessageID: entry id not found.");
        goto FuncExit;
    }
    const wchar_t* folder = m->getParent();
    wchar_t f = folder ? folder[0] : 'O'; // set default O if folder is null;
    id = convertBinaryToChar(msgprops[ePR_ENTRYID].Value.bin, f);

FuncExit:
    return id;
}

/*
* This add partial attachments to the mail if any.
* Currently this function is not used. It must be used in addition to the flag messageStatus
*
* if (m->getEmailData()->getIsMailPartial()) {
*    if (m->getEmailData()->getRemainingAttachNumber() > 0) { // there is any attach to be downloaded
*        messageStatus = messageStatus | MSGSTATUS_PENDING_ATTACHMENTS;
*    }
*    if (m->getEmailData()->getRemainingBodySize() > 0) { // there is any body to be downloaded
*        messageStatus = messageStatus | MSGSTATUS_HEADERONLY;
*        if (m->getEmailData()->getRemainingAttachNumber() == 0) {
*            messageStatus = messageStatus | MSGSTATUS_PARTIAL;
*        }
*    }
* }
*/

HRESULT MailServer2Client::AddPartialAttachments(LPMESSAGE pmsg, MailClientData* m)
{
    LOG.debug("Enter into AddAttachment function");
	HRESULT hr = S_OK;
    BodyPart* bodyPart = NULL;


    wchar_t* filename    = toWideChar("download all message");

    SPropValue  prop[3];
	IAttach*    pAttachment = NULL;
	ULONG       ulAttachmentNum = 0;
	FILE*       fileAttach = NULL;;

    memset(prop, 0, sizeof(prop));

    hr = pmsg->CreateAttach(NULL, 0, &ulAttachmentNum, &pAttachment);
	EXIT_ON_FAILED(hr);

	// Set the initial properties on the attachment
    // no data actually there yet
    /*
	prop[0].ulPropTag = PR_ATTACH_METHOD;
	prop[0].Value.ul = ATTACH_BY_VALUE;

	prop[1].ulPropTag = PR_ATTACH_DATA_BIN;
    */
    prop[0].ulPropTag = PR_ATTACH_FILENAME;
	prop[0].Value.LPSZ = filename;

    prop[1].ulPropTag    =   PR_ATTACH_SIZE;
    prop[1].Value.ul     =   5000;

    prop[2].ulPropTag    =   PR_MSG_STATUS;
    prop[2].Value.ul     =   MSGSTATUS_HEADERONLY;


    hr = pAttachment->SetProps(3, prop, NULL);
	EXIT_ON_FAILED(hr);



FuncExit:
    LOG.debug("Exiting from AddAttachment function");
    return hr;
}

/*
 HRESULT AddTnefData(IAddrBook* pAddrBook, IMessage* pSourceMsg, IMessage* pTargetMsg, unsigned long ulTnefFlags, SPropTagArray* pExcludeProps)
 {
   // we need at least IAddrBook and the source IMessage


   int i;
   DWORD num;
   WORD wKeyVal=rand();
   HRESULT hr;
   ULONG ulPropTag, ulCount;
   BYTE MIME_OID[]={0x2A,0x86,0x48,0x86,0xF7,0x14,0x03,0x0A,0x04};
   enum {ePR_ENTRYID, NUM_COLS};
   static SizedSPropTagArray(NUM_COLS, Pr

⌨️ 快捷键说明

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