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

📄 mail.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#include "stdafx.h"
#include <mapidefs.h>
#include <mapicode.h>
#include <mapitags.h>
#include <mapix.h>
#include <mapiutil.h>
#include <cemapi.h>
#include "mail.h"
#define EXIT_ON_FAILED(_hr)   \
      if (FAILED(_hr))  {  \
        goto FuncExit; \
      }

#ifndef RELEASE_OBJ
#define RELEASE_OBJ(s) \
  if (s != NULL)   \
  {          \
    s->Release();  \
    s = NULL;    \
  }
#endif //RELEASE_OBJ

enum {
    ePR_ENTRYID,
    ePR_DISPLAY_NAME,
    ePR_CE_UNIQUE_STORE_ID,
    NUM_COLS
    };

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

/*
* It always return a valid GUID. At the beginning it look for the existing one created in the prorammatically
* creation of the account. If non exists, maybe because the user deleted the old and created a new one manually,
* the procedure set a new GUID and return it to delete the account properly.
* the same GUID is {A3D64F8C-1BDC-4ac6-92A4-4D85213F96CD}.
* In the same way there is a similar procedure written in account.cpp to always modify the account.
* If the account was generated manually, this same guid is inserted.
*/

wchar_t* getFunambolGUID() {

    HRESULT           hr;
    IMAPISession *    pSession    =  NULL;
    IMAPITable*       pTable      =  NULL;
    SRowSet*          psrs        =  NULL;
    IMsgStore*        pStore      =  NULL;
    BOOL accountFound             =  FALSE;
    wchar_t* ret                  =  NULL;

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

    // Get the message stores table
    hr = pSession->GetMsgStoresTable (MAPI_UNICODE, &pTable);
    EXIT_ON_FAILED (hr);

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

    while (1) {
        // Get a row
        hr = pTable->QueryRows (1, 0, &psrs);
        EXIT_ON_FAILED (hr);

        // Did we hit the end of the table?
        if (psrs->cRows != 1) {
          break;
        }

        if (psrs->aRow[0].lpProps[ePR_DISPLAY_NAME].ulPropTag == PR_DISPLAY_NAME) {

            wchar_t* displayName = psrs->aRow[0].lpProps[ePR_DISPLAY_NAME].Value.lpszW;
            //MessageBox (NULL, displayName, TEXT ("Debug eVC"), MB_SETFOREGROUND |MB_OK);

            if (wcscmp(displayName, TEXT("Funambol")) == 0) {
                accountFound = TRUE;
                // Now we got the GUID
                LPGUID pGuid = NULL;

                ret = new wchar_t[64];
                memset(ret, 0, 64*sizeof(wchar_t));

                if (psrs->aRow[0].lpProps[ePR_CE_UNIQUE_STORE_ID].ulPropTag == PR_CE_UNIQUE_STORE_ID) {
                    //MessageBox (NULL, TEXT("GUID ok"), TEXT ("Debug eVC"), MB_SETFOREGROUND |MB_OK);
                    pGuid = psrs->aRow[0].lpProps[ePR_CE_UNIQUE_STORE_ID].Value.lpguid;

                }
                else {
                    //MessageBox (NULL, TEXT("GUID NULL"), TEXT ("Debug eVC"), MB_SETFOREGROUND |MB_OK);

                        // Open this message store
                    hr = pSession->OpenMsgStore (NULL,
                                   psrs->aRow[0].lpProps[0].Value.bin.cb,
                                  (ENTRYID *) psrs->aRow[0].lpProps[0].Value.
                                   bin.lpb, NULL, 0, &pStore);

                    SPropValue rgprops[1] = {0};
                    ULONG    cProps   = 0;

                    rgprops[cProps].ulPropTag = PR_CE_UNIQUE_STORE_ID;

                    pGuid = new GUID();
                    pGuid->Data1 = 0xA3D64F8C;
                    pGuid->Data2 = 0x1BDC;
                    pGuid->Data3 = 0x4ac6;
                    pGuid->Data4[0] = (char)0x92;
                    pGuid->Data4[1] = (char)0xA4;
                    pGuid->Data4[2] = (char)0x4D;
                    pGuid->Data4[3] = (char)0x85;
                    pGuid->Data4[4] = (char)0x21;
                    pGuid->Data4[5] = (char)0x3F;
                    pGuid->Data4[6] = (char)0x96;
                    pGuid->Data4[7] = (char)0xCD;

                    rgprops[cProps].Value.lpguid = pGuid;
                    ++cProps;

                    hr = pStore->SetProps(cProps, rgprops, NULL);

                }
                wsprintf(ret,
                    TEXT("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
                    pGuid->Data1, pGuid->Data2, pGuid->Data3,
                    pGuid->Data4[0], pGuid->Data4[1],
                    pGuid->Data4[2], pGuid->Data4[3],
                    pGuid->Data4[4], pGuid->Data4[5],
                    pGuid->Data4[6], pGuid->Data4[7]);
                    //MessageBox (NULL, ret, TEXT ("Debug eVC"), MB_SETFOREGROUND |MB_OK);

            }
        }

        FreeProws   (psrs);
        psrs    =  NULL;
        RELEASE_OBJ (pStore);
        if (accountFound) {
            break;
        }
    }

FuncExit:

    FreeProws   (psrs);

    RELEASE_OBJ (pStore);
    RELEASE_OBJ (pTable);
    RELEASE_OBJ (pSession);

    return ret;
}


⌨️ 快捷键说明

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