PageRenderTime 77ms CodeModel.GetById 36ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

/app/protected/extensions/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php

https://bitbucket.org/rkcbabu/zurmo
PHP | 68 lines | 31 code | 7 blank | 30 comment | 0 complexity | 743520c8c3d9c4905ed5e1f5849b04a6 MD5 | raw file
 1<?php
 2
 3/*
 4 * This file is part of SwiftMailer.
 5 * (c) 2004-2009 Chris Corbyn
 6 *
 7 * For the full copyright and license information, please view the LICENSE
 8 * file that was distributed with this source code.
 9 */
10
11require_once dirname(__FILE__) . '/../HeaderEncoder.php';
12require_once dirname(__FILE__) . '/../../Encoder/QpEncoder.php';
13require_once dirname(__FILE__) . '/../../CharacterStream.php';
14
15/**
16 * Handles Quoted Printable (Q) Header Encoding in Swift Mailer.
17 * @package Swift
18 * @subpackage Mime
19 * @author Chris Corbyn
20 */
21class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder
22  implements Swift_Mime_HeaderEncoder
23{
24
25  /**
26   * Creates a new QpHeaderEncoder for the given CharacterStream.
27   * @param Swift_CharacterStream $charStream to use for reading characters
28   */
29  public function __construct(Swift_CharacterStream $charStream)
30  {
31    parent::__construct($charStream);
32    // Reset the safeMap
33    $this->_safeMap=array();
34    foreach (array_merge(
35      range(0x61, 0x7A), range(0x41, 0x5A),
36      range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
37      ) as $byte)
38    {
39      $this->_safeMap[$byte] = chr($byte);
40    }
41  }
42
43  /**
44   * Get the name of this encoding scheme.
45   * Returns the string 'Q'.
46   * @return string
47   */
48  public function getName()
49  {
50    return 'Q';
51  }
52
53  /**
54   * Takes an unencoded string and produces a Q encoded string from it.
55   * @param string $string to encode
56   * @param int $firstLineOffset, optional
57   * @param int $maxLineLength, optional, 0 indicates the default of 76 chars
58   * @return string
59   */
60  public function encodeString($string, $firstLineOffset = 0,
61    $maxLineLength = 0)
62  {
63    return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
64      parent::encodeString($string, $firstLineOffset, $maxLineLength)
65      );
66  }
67
68}