Example #1
0
/* Like all the other Complete methods this one is called after OnOpen
   has been called for all registered extensions.  FLAGS may have these
   values:

    0 - The open action has not been canceled.

    EEME_FAILED or EEME_COMPLETE_FAILED - both indicate that the
        open action has been canceled.  

    Note that this method may be called more than once for each OnOpen
    and may even occur without an OnOpen (i.e. while setting up a new
    extension).

    The same return values as for OnOpen may be used..
*/ 
STDMETHODIMP 
GpgolItemEvents::OnOpenComplete (LPEXCHEXTCALLBACK eecb, ULONG flags)
{
  HRESULT hr;
  
  log_debug ("%s:%s: received, flags=%#lx", SRCNAME, __func__, flags);

  /* If the message has been processed by us (i.e. in OnOpen), we now
     use our own display code.  */
  if (!flags && m_processed)
    {
      LPMDB mdb = NULL;
      LPMESSAGE message = NULL;
      HWND hwnd = NULL;

      if (FAILED (eecb->GetWindow (&hwnd)))
        hwnd = NULL;
      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
      if (hr != S_OK || !message) 
        log_error ("%s:%s: error getting message: hr=%#lx",
                   SRCNAME, __func__, hr);
      else
        {
          if (message_display_handler (message, hwnd))
            m_wasencrypted = true;
        }
      if (message)
        message->Release ();
      if (mdb)
        mdb->Release ();
    }
  
  return S_FALSE;
}
Example #2
0
BOOL CMapiApi::HandleContentsItem( ULONG oType, ULONG cb, LPENTRYID pEntry)
{
  if (oType == MAPI_MESSAGE) {
    LPMESSAGE pMsg;
    if (OpenEntry( cb, pEntry, (LPUNKNOWN *) &pMsg)) {
      LPSPropValue pVal;
      pVal = GetMapiProperty( pMsg, PR_SUBJECT);
      ReportStringProp( "PR_SUBJECT:", pVal);
      pVal = GetMapiProperty( pMsg, PR_DISPLAY_BCC);
      ReportStringProp( "PR_DISPLAY_BCC:", pVal);
      pVal = GetMapiProperty( pMsg, PR_DISPLAY_CC);
      ReportStringProp( "PR_DISPLAY_CC:", pVal);
      pVal = GetMapiProperty( pMsg, PR_DISPLAY_TO);
      ReportStringProp( "PR_DISPLAY_TO:", pVal);
      pVal = GetMapiProperty( pMsg, PR_MESSAGE_CLASS);
      ReportStringProp( "PR_MESSAGE_CLASS:", pVal);
      ListProperties( pMsg);
      pMsg->Release();
    }
    else {
      MAPI_TRACE0( "    Folder type - error opening\n");
    }
  }
  else
    MAPI_TRACE1( "    ObjectType: %ld\n", oType);

  return( TRUE);
}
Example #3
0
HRESULT AddMailW(LPMAPISESSION lpMAPISession,
	LPMAPIFOLDER lpFolder,
	LPWSTR szSubject, // PR_SUBJECT_W, PR_CONVERSATION_TOPIC
	LPWSTR szBody, // PR_BODY_W
	LPWSTR szRecipientName, // Recipient table
	BOOL bHighImportance, // PR_IMPORTANCE
	BOOL bReadReceipt, // PR_READ_RECEIPT_REQUESTED
	BOOL bSubmit,
	BOOL bDeleteAfterSubmit)
{
	if (!lpFolder) return MAPI_E_INVALID_PARAMETER;
	HRESULT hRes = S_OK;
	LPMESSAGE lpMessage = 0;

	// Create a message and set its properties
	hRes = lpFolder->CreateMessage(0,
		0,
		&lpMessage);
	if (SUCCEEDED(hRes))
	{
		// Since we know in advance which props we'll be setting, we can statically declare most of the structures involved and save expensive MAPIAllocateBuffer calls
		hRes = SetPropsW(lpMessage, szSubject, szBody, szRecipientName, bHighImportance, bReadReceipt, bSubmit, bDeleteAfterSubmit, KEEP_OPEN_READWRITE, lpMAPISession);
	}
	if (lpMessage) {
		lpMessage->Release();
		lpMessage = NULL;
	}
	return hRes;
}
nsresult nsOutlookMail::ImportAddresses(uint32_t *pCount, uint32_t *pTotal, const PRUnichar *pName, uint32_t id, nsIAddrDatabase *pDb, nsString& errors)
{
  if (id >= (uint32_t)(m_addressList.GetSize())) {
    IMPORT_LOG0("*** Bad address identifier, unable to import\n");
    return NS_ERROR_FAILURE;
  }

  uint32_t  dummyCount = 0;
  if (pCount)
    *pCount = 0;
  else
    pCount = &dummyCount;

  CMapiFolder *pFolder;
  if (id > 0) {
    int32_t idx = (int32_t) id;
    idx--;
    while (idx >= 0) {
      pFolder = m_addressList.GetItem(idx);
      if (pFolder->IsStore()) {
        OpenMessageStore(pFolder);
        break;
      }
      idx--;
    }
  }

  pFolder = m_addressList.GetItem(id);
  OpenMessageStore(pFolder);
  if (!m_lpMdb) {
    IMPORT_LOG1("*** Unable to obtain mapi message store for address book: %S\n", pName);
    return NS_ERROR_FAILURE;
  }

  if (pFolder->IsStore())
    return NS_OK;

  nsresult  rv;

  nsCOMPtr<nsIImportFieldMap>    pFieldMap;

  nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
  if (NS_SUCCEEDED(rv)) {
    rv = impSvc->CreateNewFieldMap(getter_AddRefs(pFieldMap));
  }

  CMapiFolderContents    contents(m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID());

  BOOL      done = FALSE;
  ULONG      cbEid;
  LPENTRYID    lpEid;
  ULONG      oType;
  LPMESSAGE    lpMsg;
  nsCString    type;
  LPSPropValue  pVal;
  nsString    subject;

  while (!done) {
    (*pCount)++;

    if (!contents.GetNext(&cbEid, &lpEid, &oType, &done)) {
      IMPORT_LOG1("*** Error iterating address book: %S\n", pName);
      return NS_ERROR_FAILURE;
    }

    if (pTotal && (*pTotal == 0))
      *pTotal = contents.GetCount();

    if (!done && (oType == MAPI_MESSAGE)) {
      if (!m_mapi.OpenMdbEntry(m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) {
        IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName);
        return NS_ERROR_FAILURE;
      }

      // Get the PR_MESSAGE_CLASS attribute,
      // ensure that it is IPM.Contact
      pVal = m_mapi.GetMapiProperty(lpMsg, PR_MESSAGE_CLASS);
      if (pVal) {
        type.Truncate();
        m_mapi.GetStringFromProp(pVal, type);
        if (type.EqualsLiteral("IPM.Contact")) {
          // This is a contact, add it to the address book!
          subject.Truncate();
          pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT);
          if (pVal)
            m_mapi.GetStringFromProp(pVal, subject);

          nsIMdbRow* newRow = nullptr;
          pDb->GetNewRow(&newRow);
          // FIXME: Check with Candice about releasing the newRow if it
          // isn't added to the database.  Candice's code in nsAddressBook
          // never releases it but that doesn't seem right to me!
          if (newRow) {
            if (BuildCard(subject.get(), pDb, newRow, lpMsg, pFieldMap)) {
              pDb->AddCardRowToDB(newRow);
            }
          }
        }
        else if (type.EqualsLiteral("IPM.DistList"))
        {
          // This is a list/group, add it to the address book!
          subject.Truncate();
          pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT);
          if (pVal)
            m_mapi.GetStringFromProp(pVal, subject);
          CreateList(subject.get(), pDb, lpMsg, pFieldMap);
        }
      }

      lpMsg->Release();
    }
  }

  rv = pDb->Commit(nsAddrDBCommitType::kLargeCommit);
  return rv;
}
Example #5
0
/* Update the crypto info icon.  */
static void
update_crypto_info (LPDISPATCH inspector)
{
  HRESULT hr;
  LPDISPATCH button;
  const char *tooltip = "";
  int iconrc = -1;

  button = get_button (inspector, "GpgOL_Inspector_Crypto_Info");
  if (!button)
    {
      log_error ("%s:%s: Crypto Info button not found", SRCNAME, __func__);
      return;
    }

  if (!is_inspector_in_composer_mode (inspector))
    {
      LPDISPATCH obj;
      LPUNKNOWN unknown;
      LPMESSAGE message = NULL;

      obj = get_oom_object (inspector, "get_CurrentItem");
      if (obj)
        {
          unknown = get_oom_iunknown (obj, "MAPIOBJECT");
          if (!unknown)
            log_error ("%s:%s: error getting MAPI object", SRCNAME, __func__);
          else
            {
              hr = unknown->QueryInterface (IID_IMessage, (void**)&message);
              if (hr != S_OK || !message)
                {
                  message = NULL;
                  log_error ("%s:%s: error getting IMESSAGE: hr=%#lx",
                             SRCNAME, __func__, hr);
                }
              unknown->Release ();
            }
          obj->Release ();
        }
      if (message)
        {
          int is_encrypted = 0;
          int is_signed = 0;
          
          switch (mapi_get_message_type (message))
            {
            case MSGTYPE_GPGOL_MULTIPART_ENCRYPTED:
            case MSGTYPE_GPGOL_OPAQUE_ENCRYPTED:
            case MSGTYPE_GPGOL_PGP_MESSAGE:
              is_encrypted = 1;
              if ( mapi_test_sig_status (message) )
                is_signed = 1;
              break;
            case MSGTYPE_GPGOL:
            case MSGTYPE_SMIME:
            case MSGTYPE_UNKNOWN:
              break;
            default:
              is_signed = 1;
              break;
            }
          
          if (is_signed && is_encrypted)
            {
              tooltip =  _("This is a signed and encrypted message.\n"
                           "Click for more information. ");
              iconrc = IDB_DECRYPT_VERIFY_16;
            }
          else if (is_signed)
            {
              tooltip =  _("This is a signed message.\n"
                           "Click for more information. ");
              iconrc = IDB_VERIFY_16;
            }
          else if (is_encrypted)
            {
              tooltip =  _("This is an encrypted message.\n"
                           "Click for more information. ");
              iconrc = IDB_DECRYPT_16;
            }
          
          message->Release ();
        }
    }

  put_oom_string (button, "TooltipText", tooltip);
  if (iconrc != -1)
    put_oom_icon (button, iconrc, 16);
  put_oom_bool (button, "Visible", (iconrc != -1));
  button->Release ();
}
Example #6
0
/* Called for a click on an inspector button.  BUTTON is the button
   object and TAG is the tag value (which is guaranteed not to be
   NULL).  INSTID is the instance ID of the button. */
void
proc_inspector_button_click (LPDISPATCH button, const char *tag, int instid)
{
  LPMESSAGE message;
  HWND hwnd = NULL; /* Fixme  */

  if (!tagcmp (tag, "GpgOL_Inspector_Encrypt"))
    {  
      toggle_button (button, tag, instid);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Sign"))
    {  
      toggle_button (button, tag, instid);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Verify")
           || !tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
    {
      LPDISPATCH inspector;

      message = get_message_from_button (instid, &inspector);
      if (message)
        {
          if (message_incoming_handler (message, hwnd, true))
            message_display_handler (message, inspector, hwnd);
          message->Release ();
        }
      if (inspector)
        {
          update_crypto_info (inspector);
          inspector->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-0"))
    {
      log_debug ("%s:%s: command Debug0 (showInfo) called\n",
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          message_show_info (message, hwnd);
          message->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-1"))
    {
      log_debug ("%s:%s: command Debug1 (not used) called\n",
                 SRCNAME, __func__);
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-2"))
    {
      log_debug ("%s:%s: command Debug2 (change message class) called", 
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          /* We sync here. */
          mapi_change_message_class (message, 1);
          message->Release ();
        }
    }
  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-3"))
    {
      log_debug ("%s:%s: command Debug3 (revert_message_class) called", 
                 SRCNAME, __func__);
      message = get_message_from_button (instid, NULL);
      if (message)
        {
          int rc = gpgol_message_revert (message, 1, 
                                         KEEP_OPEN_READWRITE|FORCE_SAVE);
          log_debug ("%s:%s: gpgol_message_revert returns %d\n", 
                     SRCNAME, __func__, rc);
          message->Release ();
        }
    }

}
Example #7
0
void SaveMsg2File(){
	ULONG cbStrSize = 0L;
	LPWSTR lpWideCharStr = NULL;
	wchar_t szPath[_MAX_PATH];
	// get temp file directory
	GetTempPath(_MAX_PATH, szPath);
#ifdef MAPI32_W
	wcscat_s(szPath, L"Correct.msg");
#else 
	wcscat_s(szPath, L"Garbage.msg");
#endif
	IStorage *pStorage = NULL;
	LPMSGSESS pMsgSession = NULL;
	LPMESSAGE pMessage = NULL;
	HRESULT hr = S_OK;

	//LPWSTR subject = L"テスト日本の";// L"ceshi测试12";
	//LPWSTR body = L"テスト日本のテスト日本の"; // L"lhy测试12";
	//LPWSTR receipt = L"*****@*****.**";

	LPWSTR subject = L"Η πολιτική αβεβαιότητα ανησυχεί τις αγορές";// L"ceshi测试12";
	LPWSTR body = L"Η πολιτική αβεβαιότητα ανησυχεί τις αγορές"; // L"lhy测试12";
	LPWSTR receipt = L"*****@*****.**";

	LPSTR subjectA = ConvertUnicode2Ansi(subject);
	LPSTR bodyA = ConvertUnicode2Ansi(body);
	LPSTR receiptA = ConvertUnicode2Ansi(receipt);
	//LPSTR subjectA = "ceshi测试12";
	//LPSTR bodyA = "lhy测试12";
	//LPSTR receiptA = "*****@*****.**";

	do{
		MAPIINIT_0 mapiInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
		hr = MAPIInitialize(&mapiInit);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		LPMALLOC pMalloc = MAPIGetDefaultMalloc();

		hr = StgCreateDocfile(szPath, STGM_READWRITE | STGM_TRANSACTED | STGM_CREATE, 0, &pStorage);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		
		hr = OpenIMsgSession(pMalloc, 0, &pMsgSession);
		DEFINE_IF_HR_NT_OK_BREAK(hr);
#ifdef MAPI32_W
		// lhy comment:if load exmapi32.dll, this function will failed with error code 0x80040106.
		hr = OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, MAPI_UNICODE, &pMessage); 
#else
		hr = OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0, &pMessage);
#endif
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		hr = WriteClassStg(pStorage, CLSID_MailMessage);
		DEFINE_IF_HR_NT_OK_BREAK(hr);
#ifdef MAPI32_W
		hr = SetPropsW(pMessage, subject, body, receipt, false, false, false, false, FORCE_SAVE);
#else 
		
		hr = SetPropsA(pMessage, subjectA, bodyA, receiptA, false, false, false, false, FORCE_SAVE);
#endif
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		hr = pStorage->Commit(STGC_DEFAULT);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

	} while (0);
	
	delete subjectA;
	delete bodyA;
	delete receiptA;
	if (pMessage){
		pMessage->Release();
		pMessage = NULL;
	}
	if (pStorage){
		pStorage->Release();
		pStorage = NULL;
	}
	if (pMsgSession){
		CloseIMsgSession(pMsgSession);
		pMsgSession = NULL;
	}
	MAPIUninitialize();
}