Merge branch 'maint/7.0'
[ninja.git] / application / vendor / swiftmailer / classes / Swift / Mime / ContentEncoder / QpContentEncoder.php
blob3beeb635efbb530f81eff5ded7fb8b33f073d087
1 <?php
3 /*
4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
11 //@require 'Swift/Mime/ContentEncoder.php';
12 //@require 'Swift/Encoder/QpEncoder.php';
13 //@require 'Swift/InputByteStrean.php';
14 //@require 'Swift/OutputByteStream.php';
15 //@require 'Swift/CharacterStream.php';
17 /**
18 * Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer.
19 * @package Swift
20 * @subpackage Mime
21 * @author Chris Corbyn
23 class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
24 implements Swift_Mime_ContentEncoder
27 /**
28 * Creates a new QpContentEncoder for the given CharacterStream.
29 * @param Swift_CharacterStream $charStream to use for reading characters
30 * @param Swift_StreamFilter $filter if canonicalization should occur
32 public function __construct(Swift_CharacterStream $charStream,
33 Swift_StreamFilter $filter = null)
35 parent::__construct($charStream, $filter);
38 /**
39 * Encode stream $in to stream $out.
40 * QP encoded strings have a maximum line length of 76 characters.
41 * If the first line needs to be shorter, indicate the difference with
42 * $firstLineOffset.
43 * @param Swift_OutputByteStream $os output stream
44 * @param Swift_InputByteStream $is input stream
45 * @param int $firstLineOffset
46 * @param int $maxLineLength
48 public function encodeByteStream(
49 Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
50 $maxLineLength = 0)
52 if ($maxLineLength > 76 || $maxLineLength <= 0)
54 $maxLineLength = 76;
57 $thisLineLength = $maxLineLength - $firstLineOffset;
59 $this->_charStream->flushContents();
60 $this->_charStream->importByteStream($os);
62 $currentLine = '';
63 $prepend = '';
64 $size=$lineLen=0;
66 while (false !== $bytes = $this->_nextSequence())
68 //If we're filtering the input
69 if (isset($this->_filter))
71 //If we can't filter because we need more bytes
72 while ($this->_filter->shouldBuffer($bytes))
74 //Then collect bytes into the buffer
75 if (false === $moreBytes = $this->_nextSequence(1))
77 break;
80 foreach ($moreBytes as $b)
82 $bytes[] = $b;
85 //And filter them
86 $bytes = $this->_filter->filter($bytes);
89 $enc = $this->_encodeByteSequence($bytes, $size);
90 if ($currentLine && $lineLen+$size >= $thisLineLength)
92 $is->write($prepend . $this->_standardize($currentLine));
93 $currentLine = '';
94 $prepend = "=\r\n";
95 $thisLineLength = $maxLineLength;
96 $lineLen=0;
98 $lineLen+=$size;
99 $currentLine .= $enc;
101 if (strlen($currentLine))
103 $is->write($prepend . $this->_standardize($currentLine));
108 * Get the name of this encoding scheme.
109 * Returns the string 'quoted-printable'.
110 * @return string
112 public function getName()
114 return 'quoted-printable';