Beispiel #1
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;
}
Beispiel #2
0
IDispatchPtr OpenEmail(IDispatchPtr spDispOutlook, IDispatchPtr spDispNameSpace, const std::tstring& entryId)
{
   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."));

   Outlook::_ApplicationPtr spOutlook = spDispOutlook;
   Outlook::_NameSpacePtr spNameSpace = spDispNameSpace;
   IDispatchPtr spMailItem;
   HRESULT hr = spNameSpace->raw_GetItemFromID(_bstr_t(entryId.c_str()), vtMissing, &spMailItem);
   if(FAILED(hr))
      throw Workshare::Com::ComException(_T("Outlook failed to open the email message"), hr, spNameSpace);

   return spMailItem;
}