Ejemplo n.º 1
0
/**
	@param sFolder Folder to combine
	@param sPathname Path to combine (probably relative to sFolder)
	@param bAllowAbsoluteOverride true to allow sPathname to have an absolute path, false to make sure it's relative
	@return The combined path
*/
std::tstring ConcatPaths(const std::tstring& sFolder, const std::tstring& sPathname, bool bAllowAbsoluteOverride /* = true */)
{
	// Do we have a folder?
	if (sFolder.empty())
		// No, return the second part alone
		return sPathname;
	// Do we have a path?
	if (sPathname.empty())
		// No, return the first part alone
		return sFolder;

	// Allow overriding paths by using a drive letter and colon (c:) or a UNC path (\\)
	if (bAllowAbsoluteOverride)
		if ((sPathname.size() > 2) && (sPathname[1] == ':') || ((sPathname[0] == '\\') && (sPathname[1] == '\\')))
			return sPathname;

	std::tstring sRet = sFolder;

	// Make sure we have a slash at the end of the folder part
	CHAR c = sFolder[sFolder.size()-1];
	if ((c != '\\') && (c != '/'))
		sRet += _T("\\");

	// Make sure we don't have a slash at the beginning of the path part:
	c = sPathname[0];
	if ((c == '\\') || (c == '/'))
		// We do, jump over it
		sRet += sPathname.substr(1);
	else
		// Just add them
		sRet += sPathname;

	return sRet;
}
Ejemplo n.º 2
0
void ExtractEmail(IDispatchPtr spDispOutlook, IDispatchPtr spDispNameSpace, const std::tstring& subject, const std::tstring& folder)
{
    if(subject.empty())
        throw Workshare::ArgumentException(_T("subject"), _T("Blank subject specified for the search"));

    if(folder.empty())
        throw Workshare::ArgumentException(_T("folder"), _T("Invalid destination folder specified for saving of attachments"));

    if(-1 == _taccess(folder.c_str(), 0))
        throw Workshare::ArgumentException(_T("folder"), _T("Destination folder does not exist"));

    Outlook::_MailItemPtr spEmailItem = FindEmail(spDispOutlook, spDispNameSpace, subject);

    Outlook::AttachmentsPtr spAttachments = spEmailItem->Attachments;
    if(spAttachments == 0)
        throw Workshare::NullReferenceException(_T("Failed to get the attachments collection for the mail item"));

    long attachmentCount = spAttachments->Count;
    if(0 == attachmentCount)
        return;

    for(long index = 1; index <= attachmentCount; index++)
    {
        Outlook::AttachmentPtr spAttachment = spAttachments->Item(index);

        //we don't handle embedded documents
        Outlook::OlAttachmentType attachmentType = spAttachment->Type;
        if(Outlook::olOLE == attachmentType || Outlook::olEmbeddeditem == attachmentType)
            continue;

        std::tstring filename(folder);
        filename.append(_T("\\")).append((LPTSTR)spAttachment->FileName);

        std::tstring baseFilename = GetFilenameWithoutExtension(filename);
        std::tstring fileExtension = GetFileExtension(filename);
        int duplicate = 1;
        while(-1 != _taccess(filename.c_str(), 0))
        {
            duplicate++;
            std::tostringstream dupFilename;
            dupFilename << baseFilename << _T("(") << duplicate << _T(").") << fileExtension << std::ends;
            filename = dupFilename.str().c_str();
        }
        HRESULT hr = spAttachment->SaveAsFile(filename.c_str());
        if(FAILED(hr))
        {
            std::tostringstream errMsg;
            errMsg << _T("Failed to save attachment ") << (LPCTSTR)spAttachment->FileName << _T(" to ") << filename << std::ends;
            throw Workshare::Com::ComException(errMsg.str().c_str(), hr, spAttachment);
        }
    }
}
Ejemplo n.º 3
0
bool DBManager::init(std::tstring dbfile)
{
    std::tstring aofolder = AOManager::instance().getAOFolder();
    if (aofolder.empty())
    {
        LOG("DBManager::init: Not a valid AO folder.");
        return false;
    }

    if (dbfile.empty())
    {
        dbfile = _T("ItemAssistant.db");
    }

    bool dbfileExists = bfs::exists(bfs::tpath(dbfile));

    if (!m_db->Init(dbfile))
    {
        LOG("DBManager::init: Unable to " << (dbfileExists ? "open" : "create") << " database. [" << dbfile << "]");
        return false;
    }

    if (!dbfileExists)
    {
        createDBScheme();
    }

    unsigned int dbVersion = getDBVersion();
    if (dbVersion < CURRENT_DB_VERSION)
    {
        if (IDOK != MessageBox(NULL, _T("AO Item Assistant needs to update its database file to a newer version."),
                               _T("Question - AO Item Assistant++"), MB_OKCANCEL | MB_ICONQUESTION))
        {
            return false;
        }
        updateDBVersion(dbVersion);
    }
    else if (dbVersion > CURRENT_DB_VERSION)
    {
        MessageBox(NULL,
                   _T("AO Item Assistant has detected a too new version of its database file. You should upgrade the software to continue."),
                   _T("Error - AO Item Assistant++"), MB_OK | MB_ICONERROR);
        return false;
    }

    if (!syncLocalItemsDB(_T("aoitems.db"), aofolder))
    {
        MessageBox(NULL, _T("AO Item Assistant cannot start without a valid item database."),
                   _T("Error - AO Item Assistant++"), MB_OK | MB_ICONERROR);
        return false;
    }

    m_db->Exec(_T("ATTACH DATABASE \"aoitems.db\" AS aodb"));

    return true;
}
Ejemplo n.º 4
0
std::tstring GetEmailMessageId(IDispatchPtr spDispOutlook, IDispatchPtr spDispNameSpace, Workshare::Mail::Mapi::MapiSession& session, const std::tstring& subject)
{
    if(subject.empty())
        throw Workshare::ArgumentException(_T("subject"), _T("Blank subject specified for the search"));

    Outlook::_MailItemPtr spEmailItem = FindEmail(spDispOutlook, spDispNameSpace, subject);
    IMessagePtr spMessage = spEmailItem->MAPIOBJECT;
    if(spMessage == 0)
        throw Workshare::NullReferenceException(_T("Failed to retrieve MAPIOBJECT for Outlook MailItem"));

    Workshare::Mail::Mapi::MapiMailMessage message(spMessage, &session);
    return message.Id;
}
Ejemplo n.º 5
0
IDispatchPtr FindLinkedEmail(IDispatchPtr spDispOutlook, IDispatchPtr spDispNameSpace, Workshare::Mail::Mapi::MapiSession& session, const std::tstring& sMessageId)
{
   if(spDispOutlook == 0)
      throw Workshare::ArgumentNullException(_T("spDispOutlook"), _T("Outlook Application pointer is null."));

   if(spDispNameSpace == 0)
      throw Workshare::ArgumentNullException(_T("spDispNameSpace"), _T("MAPI NameSpace pointer is null."));

   if(sMessageId.empty())
      throw Workshare::ArgumentException(_T("sMessageId"), _T("The message ID of the email to find was not specified."));

   size_t pos = sMessageId.find(_T(';'));
   if(-1 == pos)
      throw Workshare::ArgumentException(_T("sMessageId"), _T("Invalid message ID (should be in format EntryId;SearchKey[;InternetId])"));

   std::tstring sEntryId = sMessageId.substr(0, pos);
   std::tstring sSearchKeyAndInternetId = sMessageId.substr(pos + 1);
   std::tstring sSearchKey;
   std::tstring sInternetId;

   pos = sSearchKeyAndInternetId.find(_T(';'));
   if(-1 != pos)
   {
      sSearchKey = sSearchKeyAndInternetId.substr(0, pos);
      sInternetId = sSearchKeyAndInternetId.substr(pos + 1);
   }
   else
      sSearchKey = sSearchKeyAndInternetId;

   Outlook::_ApplicationPtr spOutlook = spDispOutlook;
   Outlook::_NameSpacePtr spNameSpace = spDispNameSpace;
   IDispatchPtr spLinkedEmail;
   HRESULT hr = spNameSpace->raw_GetItemFromID(_bstr_t(sEntryId.c_str()), vtMissing, &spLinkedEmail);
   if(FAILED(hr))
   {
      std::tstring sStoreId;

      Workshare::Mail::Mapi::FindItemBySearchKey(session, sSearchKey, sEntryId, sStoreId);

      _variant_t vtStoreId(sStoreId.c_str());
      hr = spNameSpace->raw_GetItemFromID(_bstr_t(sEntryId.c_str()), vtStoreId, &spLinkedEmail);
      if(FAILED(hr))
         throw Workshare::Com::ComException(_T("Outlook failed to open email"), hr, spNameSpace);
         //If this fails we could create a function FindItemByInternetId(session, sInternetId, sEntryId, sStoreId);
   }
   return spLinkedEmail;
}
/*! Pluginページのメッセージ処理
	@param hwndDlg ダイアログボックスのWindow Handlw
	@param uMsg メッセージ
	@param wParam パラメータ1
	@param lParam パラメータ2
*/
INT_PTR CPropPlugin::DispatchEvent( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    NMHDR*		pNMHDR;
    int			idCtrl;

    WORD		wNotifyCode;
    WORD		wID;

    switch( uMsg ) {

    case WM_INITDIALOG:
        /* ダイアログデータの設定 Plugin */
        InitDialog( hwndDlg );
        SetData( hwndDlg );
        // Modified by KEITA for WIN64 2003.9.6
        ::SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );

        return TRUE;
    case WM_NOTIFY:
        idCtrl = (int)wParam;
        pNMHDR = (NMHDR*)lParam;
        switch( idCtrl ) {
        case IDC_PLUGINLIST:
            switch( pNMHDR->code ) {
            case LVN_ITEMCHANGED:
            {
                HWND hListView = ::GetDlgItem( hwndDlg, IDC_PLUGINLIST );
                int sel = ListView_GetNextItem( hListView, -1, LVNI_SELECTED );
                if( sel >= 0 ) {
                    CPlugin* plugin = CPluginManager::getInstance()->GetPlugin(sel);
                    if( plugin != NULL ) {
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Description ), to_tchar(plugin->m_sDescription.c_str()) );
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Author ), to_tchar(plugin->m_sAuthor.c_str()) );
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Version ), to_tchar(plugin->m_sVersion.c_str()) );
                    } else {
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Description ), _T("") );
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Author ), _T("") );
                        ::SetWindowText( ::GetDlgItem( hwndDlg, IDC_LABEL_PLUGIN_Version ), _T("") );
                    }
                    // 2010.08.21 明らかに使えないときはDisableにする
                    EPluginState state = m_Common.m_sPlugin.m_PluginTable[sel].m_state;
                    BOOL bEdit = (state != PLS_DELETED && state != PLS_NONE);
                    ::EnableWindow( ::GetDlgItem( hwndDlg, IDC_PLUGIN_Remove ), bEdit );
                    ::EnableWindow( ::GetDlgItem( hwndDlg, IDC_PLUGIN_OPTION ), state == PLS_LOADED && plugin && plugin->m_options.size() > 0 );
                    ::EnableWindow( ::GetDlgItem( hwndDlg, IDC_PLUGIN_README ),
                                    (state == PLS_INSTALLED || state == PLS_UPDATED || state == PLS_LOADED || state == PLS_DELETED)
                                    && !GetReadMeFile(to_tchar(m_Common.m_sPlugin.m_PluginTable[sel].m_szName)).empty());
                    ::EnableWindow(::GetDlgItem(hwndDlg, IDC_PLUGIN_URL), state == PLS_LOADED && plugin && plugin->m_sUrl.size() > 0);
                }
            }
            break;
            case NM_DBLCLK:
                // リストビューへのダブルクリックで「プラグイン設定」を呼び出す
                if (::IsWindowEnabled(::GetDlgItem( hwndDlg, IDC_PLUGIN_OPTION )))
                {
                    DispatchEvent( hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_PLUGIN_OPTION, BN_CLICKED), (LPARAM)::GetDlgItem( hwndDlg, IDC_PLUGIN_OPTION ) );
                }
                break;
            }
            break;
        default:
            switch( pNMHDR->code ) {
            case PSN_HELP:
                OnHelp( hwndDlg, IDD_PROP_PLUGIN );
                return TRUE;
            case PSN_KILLACTIVE:
                /* ダイアログデータの取得 Plugin */
                GetData( hwndDlg );
                return TRUE;
            case PSN_SETACTIVE:
                m_nPageNum = ID_PROPCOM_PAGENUM_PLUGIN;
                return TRUE;
            }
            break;
        }
        break;

    case WM_COMMAND:
        wNotifyCode = HIWORD(wParam);	/* 通知コード */
        wID = LOWORD(wParam);			/* 項目ID、 コントロールID、 またはアクセラレータID */

        switch( wNotifyCode ) {
        /* ボタン/チェックボックスがクリックされた */
        case BN_CLICKED:
            switch( wID ) {
            case IDC_PLUGIN_SearchNew:		// 新規プラグインを追加
                GetData( hwndDlg );
                CPluginManager::getInstance()->SearchNewPlugin( m_Common, hwndDlg );
                if( m_bTrayProc ) {
                    LoadPluginTemp(m_Common, *m_pcMenuDrawer);
                }
                SetData_LIST( hwndDlg );	//リストの再構築
                break;
            case IDC_PLUGIN_INST_ZIP:		// ZIPプラグインを追加
            {
                static std::tstring	sTrgDir;
                CDlgOpenFile	cDlgOpenFile;
                TCHAR			szPath[_MAX_PATH + 1];
                _tcscpy( szPath, (sTrgDir.empty() ? CPluginManager::getInstance()->GetBaseDir().c_str() : sTrgDir.c_str()));
                // ファイルオープンダイアログの初期化
                cDlgOpenFile.Create(
                    G_AppInstance(),
                    hwndDlg,
                    _T("*.zip"),
                    szPath
                );
                if( cDlgOpenFile.DoModal_GetOpenFileName( szPath ) ) {
                    GetData( hwndDlg );
                    CPluginManager::getInstance()->InstZipPlugin( m_Common, hwndDlg, szPath );
                    if( m_bTrayProc ) {
                        LoadPluginTemp(m_Common, *m_pcMenuDrawer);
                    }
                    SetData_LIST( hwndDlg );	//リストの再構築
                }
                // フォルダを記憶
                TCHAR	szFolder[_MAX_PATH + 1];
                TCHAR	szFname[_MAX_PATH + 1];
                SplitPath_FolderAndFile(szPath, szFolder, szFname);
                sTrgDir = szFolder;
            }
            break;
            case IDC_CHECK_PluginEnable:	// プラグインを有効にする
                EnablePluginPropInput( hwndDlg );
                break;
            case IDC_PLUGIN_Remove:			// プラグインを削除
            {
                HWND hListView = ::GetDlgItem( hwndDlg, IDC_PLUGINLIST );
                int sel = ListView_GetNextItem( hListView, -1, LVNI_SELECTED );
                if( sel >= 0 ) {

                    if( MYMESSAGEBOX( hwndDlg, MB_YESNO, GSTR_APPNAME, LS(STR_PROPCOMPLG_DELETE), m_Common.m_sPlugin.m_PluginTable[sel].m_szName ) == IDYES ) {
                        CPluginManager::getInstance()->UninstallPlugin( m_Common, sel );
                        SetData_LIST( hwndDlg );
                    }
                }
            }
            break;
            case IDC_PLUGIN_OPTION:		// プラグイン設定	// 2010/3/22 Uchi
            {
                HWND hListView = ::GetDlgItem( hwndDlg, IDC_PLUGINLIST );
                int sel = ListView_GetNextItem( hListView, -1, LVNI_SELECTED );
                if( sel >= 0 && m_Common.m_sPlugin.m_PluginTable[sel].m_state == PLS_LOADED ) {
                    // 2010.08.21 プラグイン名(フォルダ名)の同一性の確認
                    CPlugin* plugin = CPluginManager::getInstance()->GetPlugin(sel);
                    wstring sDirName = to_wchar(plugin->GetFolderName().c_str());
                    if( plugin && 0 == auto_stricmp(sDirName.c_str(), m_Common.m_sPlugin.m_PluginTable[sel].m_szName ) ) {
                        CDlgPluginOption cDlgPluginOption;
                        cDlgPluginOption.DoModal( ::GetModuleHandle(NULL), hwndDlg, this, sel );
                    } else {
                        WarningMessage( hwndDlg, LS(STR_PROPCOMPLG_ERR1) );
                    }
                }
            }
            break;
            case IDC_PLUGIN_OpenFolder:			// フォルダを開く
            {
                std::tstring sBaseDir = CPluginManager::getInstance()->GetBaseDir() + _T(".");
                if( ! IsDirectory(sBaseDir.c_str()) ) {
                    if( ::CreateDirectory(sBaseDir.c_str(), NULL) == 0 ) {
                        break;
                    }
                }
                ::ShellExecute( NULL, _T("open"), sBaseDir.c_str(), NULL, NULL, SW_SHOW );
            }
            break;
            case IDC_PLUGIN_README:		// ReadMe表示	// 2011/11/2 Uchi
            {
                HWND hListView = ::GetDlgItem( hwndDlg, IDC_PLUGINLIST );
                int sel = ListView_GetNextItem( hListView, -1, LVNI_SELECTED );
                std::tstring sName = to_tchar(m_Common.m_sPlugin.m_PluginTable[sel].m_szName);	// 個別フォルダ名
                std::tstring sReadMeName = GetReadMeFile(sName);
                if (!sReadMeName.empty()) {
                    if (!BrowseReadMe(sReadMeName)) {
                        WarningMessage( hwndDlg, LS(STR_PROPCOMPLG_ERR2) );
                    }
                } else {
                    WarningMessage( hwndDlg, LS(STR_PROPCOMPLG_ERR3) );
                }
            }
            break;
            case IDC_PLUGIN_URL:
            {
                HWND hListView = ::GetDlgItem(hwndDlg, IDC_PLUGINLIST);
                int sel = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
                if (sel >= 0) {
                    CPlugin* plugin = CPluginManager::getInstance()->GetPlugin(sel);
                    if (plugin != NULL) {
                        ::ShellExecute(NULL, _T("Open"), to_tchar(plugin->m_sUrl.c_str()), NULL, NULL, SW_SHOW);
                    }
                }
            }
            break;
            }
            break;
        case CBN_DROPDOWN:
            //switch( wID ){
            //default:
            //	break;
            //}
            break;	/* CBN_DROPDOWN */
        case EN_KILLFOCUS:
            //switch( wID ){
            //default:
            //	break;
            //}
            break;
        }

        break;	/* WM_COMMAND */
//@@@ 2001.02.04 Start by MIK: Popup Help
    case WM_HELP:
    {
        HELPINFO *p = (HELPINFO *)lParam;
        MyWinHelp( (HWND)p->hItemHandle, HELP_WM_HELP, (ULONG_PTR)(LPVOID)p_helpids );	// 2006.10.10 ryoji MyWinHelpに変更に変更
    }
    return TRUE;
    /*NOTREACHED*/
    //break;
//@@@ 2001.02.04 End

//@@@ 2001.12.22 Start by MIK: Context Menu Help
    //Context Menu
    case WM_CONTEXTMENU:
        MyWinHelp( hwndDlg, HELP_CONTEXTMENU, (ULONG_PTR)(LPVOID)p_helpids );	// 2006.10.10 ryoji MyWinHelpに変更に変更
        return TRUE;
//@@@ 2001.12.22 End

    }
    return FALSE;
}