Magento 1.8 – SpamAssassin Penalizes Transactional Emails (BASE64_LENGTH_79_INF)

emailmagento-1.8transactional-mail

I noticed that transactional emails from a Magento shop were often marked as spam. Apache SpamAssasin gives a 2.0 score from the BASE64_LENGTH_79_INF rule.

The rule explanation states:

According to http://en.wikipedia.org/wiki/Base64 , base 64 should only be 76 chars long, so these are out of format.

From the linked Wikipedia article:

MIME does not specify a fixed length for Base64-encoded lines, but it does specify a maximum line length of 76 characters. Additionally it specifies that any extra-alphabetic characters must be ignored by a compliant decoder, although most implementations use a CR/LF newline pair to delimit encoded lines.

So it looks like base64 encoded content is not broken into lines as expected. Did anybody encounter the same? What could cause this bad format?

Best Answer

In Zend Framework,magento/lib/Zend/Mime.php implements a const LINELENGTH = 72; but the constant is overwritten in app/code/core/Zend/Mime.php and set to 200. You can overwrite app/code/core/Zend/Mime.php using Magento's regular mechanisms and change the implementation of the encode method, replacing self::LINELENGTH with a different constant:

public static function encode($str, $encoding, $EOL = self::LINEEND)
{
    switch ($encoding) {
        case self::ENCODING_BASE64:
           // original: return self::encodeBase64($str, self::LINELENGTH, $EOL);
           return self::encodeBase64($str, 72, $EOL); // hardcoded value, just to emphasize the meaning

        case self::ENCODING_QUOTEDPRINTABLE:
            return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);

        default:
            /**
             * @todo 7Bit and 8Bit is currently handled the same way.
             */
            return $str;
    }
}

/Edit: initially I replaced self::LINELENGTH with Zend_Mime::LINELENGTH; this won't work because the autoloader will always load the Zend_Mime class from Magento core instead of the one from lib/Zend.

Related Topic