コード例 #1
0
ファイル: SPF.cpp プロジェクト: Bill48105/hmailserver
   SPF::Result
   SPF::Test(const String &sSenderIP, const String &sSenderEmail, String &sExplanation)
   {
      USES_CONVERSION;
      String sDomain = StringParser::ExtractDomain(sSenderEmail);

      int family;
      if (sSenderIP.Find(_T(":")) > 0)
         family=AF_INET6;
      else
         family=AF_INET;

      // Convert the IP address from a dotted string
      // to a binary form. We use the SPF library to
      // do this.

      char BinaryIP[16];
      if (SPFStringToAddr(T2A(sSenderIP),family,BinaryIP)==NULL)
         return Neutral;

      String sSPFBestGuess = IniFileSettings::Instance()->GetSPFDefaultPolicy();
      String sSPFBestGuessA = IniFileSettings::Instance()->GetSPFDefaultPolicyA();

      int result1 = SPFSetBestGuess(T2A(sSPFBestGuess), T2A(sSPFBestGuessA)); // policy, policy if only A

      if (result1 != 0)
      {
          LOG_DEBUG("SPFDefaultPolicy NOT Set OK. Invalid SPF string specified?");
      }
      else
      {
          LOG_DEBUG("Set OK. SPFDefaultPolicy: " + sSPFBestGuess + " SPFDefaultPolicyA: " + sSPFBestGuessA);
      }
          
      
      String sPolicyOverride = IniFileSettings::Instance()->GetSPFPolicyOverride();
      LOG_DEBUG("SPFPolicyOverride Set: " + sPolicyOverride);

      const char* explain;
      int result=SPFQuery(family,BinaryIP,T2A(sSenderEmail),T2A(sPolicyOverride),NULL,NULL,&explain); // ipv4/6, binIP, sender, policy over-ride, HELO, explaination

      if (explain != NULL)
      {
         sExplanation = explain;
         SPFFree(explain);
         LOG_DEBUG("SPF Explaination: " + sExplanation);
      }

      if (result == SPF_Fail)
      {
         // FAIL
         return Fail;
      }
      else if (result == SPF_Pass)
      {
         return Pass;
      }

      return Neutral;
   }
コード例 #2
0
ファイル: SPF.cpp プロジェクト: AimaTeam-hehai/hmailserver
   SPF::Result
   SPF::Test(const String &sSenderIP, const String &sSenderEmail, String &sExplanation)
   {
      USES_CONVERSION;
      String sDomain = StringParser::ExtractDomain(sSenderEmail);

      int family;
      if (sSenderIP.Find(_T(":")) > 0)
         family=AF_INET6;
      else
         family=AF_INET;

      // Convert the IP address from a dotted string
      // to a binary form. We use the SPF library to
      // do this.

      char BinaryIP[16];
      if (SPFStringToAddr(T2A(sSenderIP),family,BinaryIP)==NULL)
         return Neutral;

      const char* explain;
      int result=SPFQuery(family,BinaryIP,T2A(sSenderEmail),NULL,NULL,NULL,&explain);

      if (explain != NULL)
      {
         sExplanation = explain;
         SPFFree(explain);
      }

      if (result == SPF_Fail)
      {
         // FAIL
         return Fail;
      }
      else if (result == SPF_Pass)
      {
         return Pass;
      }

      return Neutral;
   }