BP_Reply_By_Email_Parser::validate_headers PHP Method

validate_headers() public static method

Checks email headers for auto-submitted / auto-replies.
public static validate_headers ( array $headers = [], integer $i ) : mixed
$headers array The email headers to check
$i integer The current email message number
return mixed Array of email headers. False if no headers or if the email is junk.
    public static function validate_headers($headers = array(), $i = 0)
    {
        // No headers? Return false
        if (empty($headers)) {
            bp_rbe_log('Message #' . $i . ': error - no headers found');
            return false;
        }
        // 'X-AutoReply' header check
        if (!empty($headers['X-Autoreply']) && $headers['X-Autoreply'] == 'yes') {
            bp_rbe_log('Message #' . $i . ': error - this is an autoreply message, so stop now!');
            return false;
        }
        // 'Precedence' header check
        // Test to see if our email is an out of office automated reply or mailing list email
        // See http://en.wikipedia.org/wiki/Email#Header_fields
        if (!empty($headers['Precedence'])) {
            switch ($headers['Precedence']) {
                case 'bulk':
                case 'junk':
                case 'list':
                    bp_rbe_log('Message #' . $i . ': error - this is some type of bulk / junk / mailing list email, so stop now!');
                    return false;
                    break;
            }
        }
        // 'Auto-Submitted' header check
        // See https://tools.ietf.org/html/rfc3834#section-5
        if (!empty($headers['Auto-Submitted'])) {
            switch (strtolower($headers['Auto-Submitted'])) {
                case 'auto-replied':
                case 'auto-generated':
                    bp_rbe_log('Message #' . $i . ': error - this is an auto-reply using the "Auto-Submitted" header, so stop now!');
                    return false;
                    break;
            }
        }
        // 'X-Auto-Response-Suppress' header check
        // used in MS Exchange mail servers
        // See http://msdn.microsoft.com/en-us/library/ee219609%28v=EXCHG.80%29.aspx
        if (!empty($headers['X-Auto-Response-Suppress'])) {
            switch ($headers['X-Auto-Response-Suppress']) {
                // non-standard value, but seems to be in use
                case 'All':
                    // these are official values
                // these are official values
                case 'OOF':
                case 'AutoReply':
                    bp_rbe_log('Message #' . $i . ': error - this is auto-reply from MS Exchange, so stop now!');
                    return false;
                    break;
            }
        }
        // 'X-FC-MachineGenerated' header check
        // used in FirstClass mail servers
        if (!empty($headers['X-FC-MachineGenerated'])) {
            bp_rbe_log('Message #' . $i . ': error - this is an auto-reply from FirstClass mail, so stop now!');
            return false;
        }
        // Envelope Sender check
        // See http://qmail.3va.net/qdp/bounce.html
        // See http://wiki.dovecot.org/LDA/Sieve
        if (!empty($headers['Return-Path'])) {
            $return_path = strtolower(self::get_header($headers, 'Return-Path'));
            if (strpos($return_path, 'mailer-daemon') === 0 || strpos($return_path, 'owner-') === 0 || empty($return_path)) {
                bp_rbe_log('Message #' . $i . ': error - this is a mailer-daemon message of some sort, so stop now!');
                return false;
            }
        }
        // @todo Perhaps implement more auto-reply checks from these links:
        // https://github.com/opennorth/multi_mail/wiki/Detecting-autoresponders
        // http://www.hackvalue.nl/en/article/19/the%20art%20of%20autoresponders%20(part%202)
        // http://stackoverflow.com/questions/6317714/apache-camel-mail-to-identify-auto-generated-messages/6383675#6383675
        // http://wiki.exim.org/EximAutoReply#Router-1
        // Want to do more checks? Here's the filter!
        return apply_filters('bp_rbe_parse_email_headers', $headers);
    }