advisesink.cpp

来自「funambol windows mobile plugin source co」· C++ 代码 · 共 589 行 · 第 1/2 页

CPP
589
字号
/*
 * 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 "AdviseSink.h"
#include "base/Log.h"
#include "base/util/utils.h"
#include "base/startcmd.h"
#include "CheckNetwork.h"
#include "SyncMLTransport.h"

#include "aygshell.h"
#include "resource.h"
#include <Windows.h>

#define USES_IID_IMAPIAdviseSink
#include <cemapi.h>
#include "base/Log.h"
#include "processUtils.h"

bool fromFlagUpdate;
IMAPISession *    globalpSession;
IMessage *        globalpmsg    ;

/*
void stopSync() {

    HWND wnd = ::FindWindow(TEXT("funambolstartsync"), NULL);

    //-- send msg to startsync to stop
    if(wnd)
        ::SendMessage(wnd, WM_COMMAND, (WPARAM)10, NULL);

}
*/
/*
#define TIMER_DELAY 700

static HANDLE moduleHandle = 0;
static WNDCLASS wc;
static WNDCLASS wcMarshaller;
static HWND hMainWindow =NULL;
static HWND wnd = NULL;
long CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static SHMENUBARINFO dlgCommandBar;
static HWND hwndMarshaller = NULL;
long CALLBACK WndProcMarshaller(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static SBinary g_sbEntry;
static BOOL menubarVisible;


// create window holding the menubar, this is a child of Outlook window
extern "C" DWORD WINAPI createBubble(LPVOID lpv) {

    moduleHandle = GetModuleHandle(TEXT("syncmltransport.dll"));
    MSG msg;

    // Init Wnd class
    wc.style=CS_HREDRAW | CS_VREDRAW ;
    wc.lpfnWndProc=WndProc;
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hInstance=(HINSTANCE)moduleHandle;
    wc.hIcon=0;
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName=NULL;
    wc.lpszClassName=L"funambolDownloadMail2";

    if(!RegisterClass(&wc)) return false;



    hMainWindow = CreateWindow(
        //WS_EX_DLGMODALFRAME ,//| WS_EX_TOOLWINDOW, //| WS_EX_TOPMOST,
        //WS_BORDER,
        L"funambolDownloadMail2",
        NULL,//L"",
        NULL,
        0,0,
        0,0,
        0, //! parent
        NULL,
        (HINSTANCE)moduleHandle,
        NULL);


    if(!hMainWindow){
        return FALSE;
    };

    while(GetMessage(&msg,NULL,NULL,NULL))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

// create the window which receives messages from startsync
extern "C" DWORD WINAPI createMarshaller(LPVOID lpv) {

    LPCWSTR lpszClassName= L"funambolDownloadMail";
    moduleHandle = GetModuleHandle(TEXT("syncmltransport.dll"));
    MSG msg;

    // Init Wnd class
    wcMarshaller.style=CS_HREDRAW | CS_VREDRAW ;
    wcMarshaller.lpfnWndProc=WndProcMarshaller;
    wcMarshaller.cbClsExtra=0;
    wcMarshaller.cbWndExtra=0;
    wcMarshaller.hInstance=(HINSTANCE)moduleHandle;
    wcMarshaller.hIcon=0;
    wcMarshaller.hCursor=LoadCursor(NULL,IDC_ARROW);
    wcMarshaller.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wcMarshaller.lpszMenuName=NULL;
    wcMarshaller.lpszClassName=lpszClassName;

    if(!RegisterClass(&wcMarshaller)) return false;

    hwndMarshaller = CreateWindow(
        lpszClassName,
        NULL,
        NULL, //STYLE
        0,0,
        0,0,
        0, // no parent, this window should catch messages from startsync
        NULL,
        (HINSTANCE)moduleHandle,
        NULL);

    if(!hwndMarshaller){
        return FALSE;
    };
}

*/
CAdviseSink::CAdviseSink()
{
    LOG.debug("CAdviseSink created");
    globalpSession    =  NULL;
    globalpmsg        =  NULL;

};

CAdviseSink::~CAdviseSink()
{
    LOG.debug("CAdviseSink destroyed");
};


STDMETHODIMP CAdviseSink::QueryInterface(REFIID riid,  LPVOID * ppvObj) {

    LOG.debug("CAdviseSink QueryInterface");

    *ppvObj = 0;

    *ppvObj = (LPVOID)this;
    AddRef();
    return S_OK;

    return E_NOINTERFACE;

};

STDMETHODIMP_(ULONG) CAdviseSink::AddRef()
{
    cRef++;
    return cRef;
};

STDMETHODIMP_(ULONG) CAdviseSink::Release()
{
    if (cRef > 0) --cRef;
    return cRef;
};

wchar_t* convertIdToWideChar(SBinary sbEntry) {

    int len = sbEntry.cb;
    char* b64 = new char[((len/3+1)<<2) + 1];
    len = b64_encode(b64, sbEntry.lpb, len);
    b64[len] = 0;
    wchar_t* t = toWideChar(b64);
    wchar_t* ret = new wchar_t[wcslen(t) + 1 + 2];
    wsprintf(ret, TEXT("/%s"), t);

    // AAAAAG8TAAECAAAAAQAAA==
    delete [] b64; b64 = NULL;
    delete [] t; t = NULL;
    return ret;
}


enum {
    ePR_ENTRYID,
    ePR_MSG_STATUS,
    eNUM_COLS};

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

/*
* to understand if the message is marked to downlaod
* it returns 1 if the body link is selected
* it returns 2 if the attachment link is selected. not used
* it returns 0 if no status is the needed
*/
int isMarkedToDownload(SBinary sbEntry) {

    HRESULT           hr;
    IMAPISession *    pSession    =  NULL;
    ULONG             returned    =  0;
    IMessage *        pmsg        =  NULL;
    ULONG             messageStatus = (ULONG) 0x00000000;
    int ret = 0;

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

    hr = pSession->OpenEntry(sbEntry.cb,
        (ENTRYID*)sbEntry.lpb,
        NULL,
        MAPI_BEST_ACCESS,
        &returned,
        (IUnknown **) &pmsg);

    if(!pmsg){
        LOG.error("updateFlagMail: pmsg is null.");
        goto FuncExit;
    }

    SPropValue* msgprops = NULL;
    ULONG    cmsgValue =  0;

    hr = pmsg->GetProps ((LPSPropTagArray)&Columns, MAPI_UNICODE, &cmsgValue,
       &msgprops);

    if (msgprops[ePR_MSG_STATUS].ulPropTag == PR_MSG_STATUS) {
        messageStatus = msgprops[ePR_MSG_STATUS].Value.ul;
        if (messageStatus & MSGSTATUS_REMOTE_DOWNLOAD)
            ret = 1;
        // for attachments: not use now
        //else if (messageStatus & MSGSTATUS_REMOTE_DOWNLOAD_ATTACH) { //
        //    ret = 2; //
        //} //
    }

FuncExit:

    pmsg->Release();
    pSession->Release();
    return ret;
}


HRESULT updateFlagMail(SBinary sbEntry, int flagToUpdate) {

    HRESULT           hr;
    ULONG             returned    =  0;
    ULONG             messageStatus = (ULONG) 0x00000000;

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

    hr = globalpSession->OpenEntry(sbEntry.cb,
        (ENTRYID*)sbEntry.lpb,
        NULL,
        MAPI_BEST_ACCESS,
        &returned,
        (IUnknown **) &globalpmsg);

    if(!globalpmsg){
        LOG.error("updateFlagMail: pmsg is null.");
        goto FuncExit;

⌨️ 快捷键说明

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