You are here

function PHPMailer::EncodeQ in SMTP Authentication Support 5

Same name and namespace in other branches
  1. 7.2 smtp.phpmailer.inc \PHPMailer::EncodeQ()
  2. 7 smtp.phpmailer.inc \PHPMailer::EncodeQ()

Encode string to q encoding. @access private

Return value

string

1 call to PHPMailer::EncodeQ()
PHPMailer::EncodeHeader in ./smtp.module
Encode a header string to best of Q, B, quoted or none. @access private

File

./smtp.module, line 1687
Enables drupal to send email directly to an SMTP server using authentication. Uses the PHPMailer class by Brent R. Matzelle.

Class

PHPMailer
PHPMailer - PHP email transport class @package PHPMailer @author Brent R. Matzelle @copyright 2001 - 2003 Brent R. Matzelle

Code

function EncodeQ($str, $position = "text") {

  // There should not be any EOL in the string
  $encoded = preg_replace("[\r\n]", "", $str);
  switch (strtolower($position)) {
    case "phrase":
      $encoded = preg_replace("/([^A-Za-z0-9!*+\\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
      break;
    case "comment":
      $encoded = preg_replace("/([\\(\\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
    case "text":
    default:

      // Replace every high ascii, control =, ? and _ characters
      $encoded = preg_replace('/([\\000-\\011\\013\\014\\016-\\037\\075\\077\\137\\177-\\377])/e', "'='.sprintf('%02X', ord('\\1'))", $encoded);
      break;
  }

  // Replace every spaces to _ (more readable than =20)
  $encoded = str_replace(" ", "_", $encoded);
  return $encoded;
}