Ejemplo n.º 1
0
   boost::shared_ptr<ACLPermission> 
   ACLManager::GetPermissionForFolder(__int64 iAccountID, boost::shared_ptr<IMAPFolder> pFolder)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Input:
   // iAccountID - The account which wants access to the folder
   // pFolder    - The folder the account wants access to
   //---------------------------------------------------------------------------()
   {
      if (pFolder->GetAccountID() == iAccountID)
      {
         // Folder is owned by requester. Full access.
         boost::shared_ptr<ACLPermission> pFullPermissions = boost::shared_ptr<ACLPermission>(new ACLPermission);
         pFullPermissions->GrantAll();
         return pFullPermissions;         
      }


      boost::shared_ptr<IMAPFolders> pPublicFolders = Configuration::Instance()->GetIMAPConfiguration()->GetPublicFolders();

      // The user is trying to access a public folder. Determine the permissions for this one.
      // We have a list containing Folder A and Folder B1. Since not all folders may have permissions
      // we need to locate a parent folder in the structure which has a permission and then
      // inherit that one.
      
      boost::shared_ptr<IMAPFolder> pCheckFolder = pFolder;

      int maxRecursions = 250;
      while (pCheckFolder && maxRecursions > 0)
      {
         maxRecursions--;

         // Check if permissions is set for this folder. If it is, we need to check
         // if we have permissions to it.
         boost::shared_ptr<ACLPermissions> pPermissions = pCheckFolder->GetPermissions();

         if (pPermissions && pPermissions->GetCount() > 0)
         {
            // We found permissions for this folder. Locate the permission for the given user.
            boost::shared_ptr<ACLPermission> pPermission = _GetPermissionForAccount(pPermissions, iAccountID);

            return pPermission;
         }

         // Locate parent folder.
         __int64 iParentFolderID = pCheckFolder->GetParentFolderID();

         pCheckFolder = pPublicFolders->GetItemByDBIDRecursive(iParentFolderID);
      }

      boost::shared_ptr<ACLPermission> pNoPermission;
      return pNoPermission;

   }
   bool 
   PersistentFetchAccount::SaveObject(boost::shared_ptr<FetchAccount> pFA)
   {
      SQLStatement oStatement;
      oStatement.SetTable("hm_fetchaccounts");

      bool bNewObject = pFA->GetID() == 0;

      oStatement.AddColumnInt64("faaccountid", pFA->GetAccountID());
      oStatement.AddColumn("faactive", pFA->GetActive() ? 1 : 0);
      oStatement.AddColumn("faaccountname", pFA->GetName());
      oStatement.AddColumn("faserveraddress", pFA->GetServerAddress());
      oStatement.AddColumn("faserverport", pFA->GetPort());
      oStatement.AddColumn("faservertype", pFA->GetServerType());
      oStatement.AddColumn("fausername", pFA->GetUsername());
      oStatement.AddColumn("fapassword", Crypt::Instance()->EnCrypt(pFA->GetPassword(), Crypt::ETBlowFish));
      oStatement.AddColumn("faminutes", pFA->GetMinutesBetweenTry());
      oStatement.AddColumn("fadaystokeep", pFA->GetDaysToKeep());
      oStatement.AddColumn("fanexttry", Time::GetCurrentDateTime());
      oStatement.AddColumn("faprocessmimerecipients", pFA->GetProcessMIMERecipients());
      oStatement.AddColumn("faprocessmimedate", pFA->GetProcessMIMEDate());
      oStatement.AddColumn("fausessl", pFA->GetUseSSL());
      oStatement.AddColumn("fauseantispam", pFA->GetUseAntiSpam());
      oStatement.AddColumn("fauseantivirus", pFA->GetUseAntiVirus());
      oStatement.AddColumn("faenablerouterecipients", pFA->GetEnableRouteRecipients());

      if (bNewObject)
      {
         oStatement.SetStatementType(SQLStatement::STInsert);
         oStatement.SetIdentityColumn("faid");

         oStatement.AddColumn("falocked", 0);
      }
      else
      {
         String sWhere;
         sWhere.Format(_T("faid = %I64d"), pFA->GetID());

         oStatement.SetStatementType(SQLStatement::STUpdate);
         oStatement.SetWhereClause(sWhere);
      }

      // Save and fetch ID
      __int64 iDBID = 0;
      bool bRetVal = Application::Instance()->GetDBManager()->Execute(oStatement, bNewObject ? &iDBID : 0);
      if (bRetVal && bNewObject)
         pFA->SetID((int) iDBID);

      return bRetVal;
   }
   bool 
   PersistentMessageMetaData::SaveObject(boost::shared_ptr<MessageMetaData> metaData)
   {
      SQLStatement statement;
      statement.SetTable("hm_message_metadata");
      statement.SetStatementType(SQLStatement::STInsert);
      statement.SetIdentityColumn("metadata_id");
      statement.AddColumn("metadata_accountid", metaData->GetAccountID());
      statement.AddColumn("metadata_folderid", metaData->GetFolderID());
      statement.AddColumnInt64("metadata_messageid", metaData->GetMessageID());
      statement.AddColumnDate("metadata_dateutc", metaData->GetDate());
      statement.AddColumn("metadata_from", metaData->GetFrom(), 100);
      statement.AddColumn("metadata_subject", metaData->GetSubject(), 100);
      statement.AddColumn("metadata_to", metaData->GetTo(), 100);
      statement.AddColumn("metadata_cc", metaData->GetCC(), 100);

      // Save and fetch ID
      __int64 iDBID = 0;
      bool bRetVal = Application::Instance()->GetDBManager()->Execute(statement, &iDBID);
      metaData->SetID((int) iDBID);

      return bRetVal;
   }
Ejemplo n.º 4
0
   bool 
   MessageUtilities::CopyToIMAPFolder(boost::shared_ptr<Message> pMessage, int iDestinationFolderID)
   {
      // Check if the destination folder exists
      boost::shared_ptr<IMAPFolders> pFolders = HM::IMAPFolderContainer::Instance()->GetFoldersForAccount(pMessage->GetAccountID());
      boost::shared_ptr<IMAPFolder> pFolder = pFolders->GetItemByDBIDRecursive(iDestinationFolderID);

      if (!pFolder)
         return false;

      // Check which account this message belongs to.
      boost::shared_ptr<const Account> pAccount = CacheContainer::Instance()->GetAccount(pMessage->GetAccountID());
      if (!pAccount)
         return false;

      boost::shared_ptr<Message> pNewMessage = PersistentMessage::CopyToIMAPFolder(pAccount, pMessage, pFolder);
      if (!pNewMessage)
         return false;

      PersistentMessage::SaveObject(pNewMessage);

      pFolder->GetMessages()->AddItem(pNewMessage);

      boost::shared_ptr<ChangeNotification> pNotification = 
         boost::shared_ptr<ChangeNotification>(new ChangeNotification(pNewMessage->GetAccountID(), pNewMessage->GetFolderID(), ChangeNotification::NotificationMessageAdded));

      Application::Instance()->GetNotificationServer()->SendNotification(pNotification);

      return true;
   }
Ejemplo n.º 5
0
   void
   SMTPDeliverer::DeliverMessage(boost::shared_ptr<Message> pMessage)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Submits the next message in the database. 
   //---------------------------------------------------------------------------()
   {
      LOG_DEBUG("Delivering message...");

      if (!pMessage)
      {
         ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4217, "SMTPDeliverer::DeliverMessage()", "The message to deliver was not given.");
         return;
      }

      // Fetch the message ID before we delete the message and it's reset.
      __int64 messageID = pMessage->GetID();

      String sSendersIP;
      RuleResult globalRuleResult;
      if (!_PreprocessMessage(pMessage, sSendersIP, globalRuleResult))
      {
         // Message delivery was aborted during preprocessing.
         return;
      }

      vector<String> saErrorMessages;

      // Perform deliver to local recipients.
      LocalDelivery localDeliverer(sSendersIP, pMessage, globalRuleResult);
      bool messageReused = localDeliverer.Perform(saErrorMessages);

      bool messageRescheduled = false;
      if (pMessage->GetRecipients()->GetCount() > 0)
      {
         // Perform deliveries to external recipients.
         ExternalDelivery externalDeliverer(sSendersIP, pMessage, globalRuleResult);
         messageRescheduled = externalDeliverer.Perform(saErrorMessages);
      }

      // If an error has occurred, now is the time to send an error
      // message back to the author of the email message.
      if (saErrorMessages.size() > 0)
         _SubmitErrorLog(pMessage, saErrorMessages);

      // Unless the message has been re-used, or has been rescheduled for
      // later delivery, we should delete it now.
      bool deleteMessageNow = !messageReused && !messageRescheduled;
      if (deleteMessageNow)
      {
         // Check that we haven't reused this message before we delete it.
         if (pMessage->GetAccountID() > 0)
         {
            String errorMessage;
            errorMessage.Format(_T("Attempting to delete message %I64d even though it's been delivered to user account %I64d ."), messageID, pMessage->GetAccountID());
            ErrorManager::Instance()->ReportError(ErrorManager::High, 5208, "SMTPDeliverer::DeliverMessage", errorMessage);
            return;
         }

         PersistentMessage::DeleteObject(pMessage);   
      }

      String logText;
      logText.Format(_T("SMTPDeliverer - Message %I64d: Message delivery thread completed."), messageID);
      LOG_APPLICATION(logText);

      return;   
   }
Ejemplo n.º 6
0
   bool 
   ACLManager::SetACL(boost::shared_ptr<IMAPFolder> pFolder, const String& sIdentifier, const String &sPermissions)
   {
      boost::shared_ptr<const Account> pAccount = CacheContainer::Instance()->GetAccount(sIdentifier);
      boost::shared_ptr<Group> pGroup;

      if (!pAccount)
      {
         // No account was found. Check if it's a group.
         boost::shared_ptr<Group> pGroup = Configuration::Instance()->GetIMAPConfiguration()->GetGroups()->GetItemByName(sIdentifier);

         if (!pGroup)
         {
            // Identifier was not found.
            return false;
         }
      }

      if (pAccount && pAccount->GetID() == pFolder->GetAccountID())
      {
         // Should we ever come here? A user should not be able to modify
         // his own right on his own folder.
         assert(0);       
         return false;
      }

      boost::shared_ptr<ACLPermissions> pFolderPermissions = pFolder->GetPermissions();
      
      boost::shared_ptr<ACLPermission> pPermission;
      
      if (pAccount)
         pPermission = pFolderPermissions->GetPermissionForAccount(pAccount->GetID());
      else
         pPermission = pFolderPermissions->GetPermissionForGroup(pGroup->GetID());

      if (!pPermission)
      {
         pPermission = boost::shared_ptr<ACLPermission>(new ACLPermission);

         pPermission->SetShareFolderID(pFolder->GetID());

         if (pAccount)
         {
            pPermission->SetPermissionType(ACLPermission::PTUser);
            pPermission->SetPermissionAccountID(pAccount->GetID());
         }
         else if (pGroup)
         {
            pPermission->SetPermissionType(ACLPermission::PTGroup);
            pPermission->SetPermissionGroupID(pGroup->GetID());
         }
         else
            return false;

      }

      pPermission->AppendPermissions(sPermissions);

      if (!PersistentACLPermission::SaveObject(pPermission))
         return false;
      
      return true;
   }