Exemplo n.º 1
0
STDMETHODIMP InterfaceUtilities::GetMailServer(BSTR EMailAddress, BSTR *MailServer)
{
   try
   {
      HM::String sDomainName;
      HM::String sEMail(EMailAddress);
   
      sDomainName = HM::StringParser::ExtractDomain (EMailAddress);
   
      std::vector<HM::String> saDomainNames;
   
      HM::DNSResolver oDNSResolver;
      oDNSResolver.GetEmailServers(sDomainName, saDomainNames);
   
      HM::String sMailServer = "";
      for (unsigned int i = 0; i < saDomainNames.size(); i++)
      {
         if (!sMailServer.IsEmpty())
            sMailServer += ",";
   
         sMailServer += saDomainNames[i];
      }
   
      *MailServer = sMailServer.AllocSysString();
   
      return S_OK;
   }
   catch (...)
   {
      return COMError::GenerateGenericMessage();
   }
}
Exemplo n.º 2
0
STDMETHODIMP InterfaceMessage::AddRecipient(BSTR bstrName, BSTR bstrAddress)
{
   try
   {
      if (!m_pObject)
         return GetAccessDenied();

      // Add this recipent to the actual email.
      HM::String sAddress(bstrAddress);
      HM::String sName (bstrName);
   
      bool recipientOK = false;
      HM::RecipientParser recipientParser;
      recipientParser.CreateMessageRecipientList(sAddress, m_pObject->GetRecipients(), recipientOK);
   
      // Add this recipient to the mime message.
      HM::String sThisAddress = "\"" + sName + "\"" + " <" + sAddress + ">";
      HM::String sTo = _GetMessageData()->GetTo();
   
      if (!sTo.IsEmpty())
         sTo += ",";
   
      sTo += sThisAddress;
   
      _GetMessageData()->SetTo(sTo);
      
   
      return S_OK;
   }
   catch (...)
   {
      return COMError::GenerateGenericMessage();
   }
}
STDMETHODIMP InterfaceApplication::Connect()
{
    try
    {
        HM::String sErrorMessage = HM::Application::Instance()->GetLastErrorMessage();
        if (!sErrorMessage.IsEmpty())
            return COMError::GenerateError(sErrorMessage);

        return S_OK;
    }
    catch (...)
    {
        return COMError::GenerateGenericMessage();
    }
}
STDMETHODIMP InterfaceApplication::Reinitialize()
{
    try
    {
        if (!authentication_->GetIsServerAdmin())
            return authentication_->GetAccessDenied();

        HM::String sErrorMessage = HM::Application::Instance()->Reinitialize();
        if (!sErrorMessage.IsEmpty())
            return COMError::GenerateError(sErrorMessage);

        return S_OK;
    }
    catch (...)
    {
        return COMError::GenerateGenericMessage();
    }
}
Exemplo n.º 5
0
STDMETHODIMP InterfaceMessage::Save()
{
   try
   {
      if (!m_pObject)
         return GetAccessDenied();

      // Check that the message has a valid date header.
      HM::String sDate = _GetMessageData()->GetSentTime();
      if (sDate.IsEmpty())
      {
         // Date was not specified. Specify it now.
         sDate = HM::Time::GetCurrentMimeDate();
         _GetMessageData()->SetSentTime(sDate);
      }
   
      shared_ptr<const HM::Account> account;
   
      if (m_pObject->GetAccountID() > 0)
      {
         account = HM::CacheContainer::Instance()->GetAccount(m_pObject->GetAccountID());
      }
   
      // Save the message to disk.
      const HM::String fileName = HM::PersistentMessage::GetFileName(account, m_pObject);
   
      if (!_GetMessageData()->Write(fileName))
      {
         return COMError::GenerateError("Unable to write to message file.");
      }
   
      // A message can be in a number of different states:
      // Case 1) New message which should be delivered -> Save in file and add to database
      // Case 2) New message which should be added to an existing IMAP folder -> Update message file and save to database// 
      // case 3) Existing message which is being delivered. -> Only update the message fil
      // Case 4) Existing message in IMAP folder which should just be re-saved -> Update message file
   
      HM::Message::State state = m_pObject->GetState();
   
      switch (state)
      {
      case HM::Message::Created:
         {
            // Handle new message. It can either be Case 1 or Case 2. If the message is already
            // connected to an account, it means that it should be stored in a specific IMAP folder
            if (m_pObject->GetFolderID() == 0 && m_pObject->GetAccountID() == 0)
            {
               // Case 1: The message should be delivered. Change the state to delivering
               m_pObject->SetState(HM::Message::Delivering);
   
               if (!HM::PersistentMessage::SaveObject(m_pObject))
               {
                  return COMError::GenerateError("Message could not be saved in database.");
               }
   
               HM::Application::Instance()->SubmitPendingEmail();
            }  
            else
            {
               // Case 2. It's a new message but it should be added to an existing IMAP folder.
               m_pObject->SetState(HM::Message::Delivered);
               return _SaveNewMessageToIMAPFolder();
            }
   
            break;
         }
      case HM::Message::Delivering:
         {
            // Handle message which is being delivered. Saving in database will be taken
            // care about by the delivery process. Since the file has already been updated
            // on disk, there's not more for us to do here.
            break;
         }
      case HM::Message::Delivered:
         {
            // The message has already been delivered. It's placed inside an account mailbox.
            // All we need to do is to update it in the database.
            if (!HM::PersistentMessage::SaveObject(m_pObject))
               return S_FALSE;
   
            break;
         }
      default:
         {
            // Unhandled case.
            return COMError::GenerateError("The message could not be saevd. It is in an unknown state.");
         }
      }
      
      return S_OK;
   }
   catch (...)
   {
      return COMError::GenerateGenericMessage();
   }
}