Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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
 
11
//@require 'Swift/Encoder.php';
12
 
13
/**
14
 * Handles Base 64 Encoding in Swift Mailer.
15
 * @package Swift
16
 * @subpackage Encoder
17
 * @author Chris Corbyn
18
 */
19
class Swift_Encoder_Base64Encoder implements Swift_Encoder
20
{
21
 
22
  /**
23
   * Takes an unencoded string and produces a Base64 encoded string from it.
24
   * Base64 encoded strings have a maximum line length of 76 characters.
25
   * If the first line needs to be shorter, indicate the difference with
26
   * $firstLineOffset.
27
   * @param string $string to encode
28
   * @param int $firstLineOffset
29
   * @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
30
   * @return string
31
   */
32
  public function encodeString($string, $firstLineOffset = 0,
33
    $maxLineLength = 0)
34
  {
35
    if (0 >= $maxLineLength || 76 < $maxLineLength)
36
    {
37
      $maxLineLength = 76;
38
    }
39
 
40
    $encodedString = base64_encode($string);
41
    $firstLine = '';
42
 
43
    if (0 != $firstLineOffset)
44
    {
45
      $firstLine = substr(
46
        $encodedString, 0, $maxLineLength - $firstLineOffset
47
        ) . "\r\n";
48
      $encodedString = substr(
49
        $encodedString, $maxLineLength - $firstLineOffset
50
        );
51
    }
52
 
53
    return $firstLine . trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
54
  }
55
 
56
  /**
57
   * Does nothing.
58
   */
59
  public function charsetChanged($charset)
60
  {
61
  }
62
 
63
}