mail.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 197 行

CPP
197
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * 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 Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#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 + =
减小字号Ctrl + -
显示快捷键?