/** * Spam-Validation of given Params * see powermail/doc/SpamDetection for formula * * @param \In2code\Powermail\Domain\Model\Mail $mail * @return bool */ public function isValid($mail) { if (!$this->settings['spamshield.']['_enable']) { return $this->getIsValid(); } $spamFactor = $this->settings['spamshield.']['factor'] / 100; // Different checks to increase spam indicator $this->honeypodCheck($this->settings['spamshield.']['indicator.']['honeypod']); $this->linkCheck($mail, $this->settings['spamshield.']['indicator.']['link'], $this->settings['spamshield.']['indicator.']['linkLimit']); $this->nameCheck($mail, $this->settings['spamshield.']['indicator.']['name']); $this->sessionCheck($mail, $this->settings['spamshield.']['indicator.']['session']); $this->uniqueCheck($mail, $this->settings['spamshield.']['indicator.']['unique']); $this->blacklistStringCheck($mail, $this->settings['spamshield.']['indicator.']['blacklistString']); $this->blacklistIpCheck($this->settings['spamshield.']['indicator.']['blacklistIp']); // spam formula with asymptote 1 (100%) if ($this->spamIndicator > 0) { $thisSpamFactor = -1 / $this->spamIndicator + 1; } else { $thisSpamFactor = 0; } // Save Spam Factor in session for db storage $GLOBALS['TSFE']->fe_user->setKey('ses', 'powermail_spamfactor', $this->formatSpamFactor($thisSpamFactor)); $GLOBALS['TSFE']->storeSessionData(); // Spam debugging if ($this->settings['debug.']['spamshield']) { GeneralUtility::devLog('Spamshield (Spamfactor ' . $this->formatSpamFactor($thisSpamFactor) . ')', 'powermail', 0, $this->getMessages()); } // if spam if ($thisSpamFactor >= $spamFactor) { $this->addError('spam_details', $this->formatSpamFactor($thisSpamFactor)); $this->setIsValid(FALSE); // Send notification email to admin if (GeneralUtility::validEmail($this->settings['spamshield.']['email'])) { $subject = 'Spam in powermail form recognized'; $message = 'Possible spam in powermail form on page with PID ' . $GLOBALS['TSFE']->id; $message .= "\n\n"; $message .= 'Spamfactor of this mail: ' . $this->formatSpamFactor($thisSpamFactor) . "\n"; $message .= "\n\n"; $message .= 'Failed Spamchecks:' . "\n"; $message .= Div::viewPlainArray($this->getMessages()); $message .= "\n\n"; $message .= 'Given Form variables:' . "\n"; foreach ($mail->getAnswers() as $answer) { $message .= $answer->getField()->getTitle(); $message .= ': '; $message .= $answer->getValue(); $message .= "\n"; } $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $header .= 'From: powermail@' . GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . "\r\n"; GeneralUtility::plainMailEncoded($this->settings['spamshield.']['email'], $subject, $message, $header); } } return $this->getIsValid(); }