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/Mime/HeaderFactory.php';
12
//@require 'Swift/Mime/HeaderEncoder.php';
13
//@require 'Swift/Encoder.php';
14
//@require 'Swift/Mime/Headers/MailboxHeader.php';
15
//@require 'Swift/Mime/Headers/DateHeader.php';
16
//@require 'Swift/Mime/Headers/UnstructuredHeader.php';
17
//@require 'Swift/Mime/Headers/ParameterizedHeader.php';
18
//@require 'Swift/Mime/Headers/IdentificationHeader.php';
19
//@require 'Swift/Mime/Headers/PathHeader.php';
20
 
21
/**
22
 * Creates MIME headers.
23
 * @package Swift
24
 * @subpackage Mime
25
 * @author Chris Corbyn
26
 */
27
class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
28
{
29
 
30
  /** The HeaderEncoder used by these headers */
31
  private $_encoder;
32
 
33
  /** The Encoder used by parameters */
34
  private $_paramEncoder;
35
 
36
  /** The charset of created Headers */
37
  private $_charset;
38
 
39
  /**
40
   * Creates a new SimpleHeaderFactory using $encoder and $paramEncoder.
41
   * @param Swift_Mime_HeaderEncoder $encoder
42
   * @param Swift_Encoder $paramEncoder
43
   * @param string $charset
44
   */
45
  public function __construct(Swift_Mime_HeaderEncoder $encoder,
46
    Swift_Encoder $paramEncoder, $charset = null)
47
  {
48
    $this->_encoder = $encoder;
49
    $this->_paramEncoder = $paramEncoder;
50
    $this->_charset = $charset;
51
  }
52
 
53
  /**
54
   * Create a new Mailbox Header with a list of $addresses.
55
   * @param string $name
56
   * @param array|string $addresses
57
   * @return Swift_Mime_Header
58
   */
59
  public function createMailboxHeader($name, $addresses = null)
60
  {
61
    $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder);
62
    if (isset($addresses))
63
    {
64
      $header->setFieldBodyModel($addresses);
65
    }
66
    $this->_setHeaderCharset($header);
67
    return $header;
68
  }
69
 
70
  /**
71
   * Create a new Date header using $timestamp (UNIX time).
72
   * @param string $name
73
   * @param int $timestamp
74
   * @return Swift_Mime_Header
75
   */
76
  public function createDateHeader($name, $timestamp = null)
77
  {
78
    $header = new Swift_Mime_Headers_DateHeader($name);
79
    if (isset($timestamp))
80
    {
81
      $header->setFieldBodyModel($timestamp);
82
    }
83
    $this->_setHeaderCharset($header);
84
    return $header;
85
  }
86
 
87
  /**
88
   * Create a new basic text header with $name and $value.
89
   * @param string $name
90
   * @param string $value
91
   * @return Swift_Mime_Header
92
   */
93
  public function createTextHeader($name, $value = null)
94
  {
95
    $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder);
96
    if (isset($value))
97
    {
98
      $header->setFieldBodyModel($value);
99
    }
100
    $this->_setHeaderCharset($header);
101
    return $header;
102
  }
103
 
104
  /**
105
   * Create a new ParameterizedHeader with $name, $value and $params.
106
   * @param string $name
107
   * @param string $value
108
   * @param array $params
109
   * @return Swift_Mime_ParameterizedHeader
110
   */
111
  public function createParameterizedHeader($name, $value = null,
112
    $params = array())
113
  {
114
    $header = new Swift_Mime_Headers_ParameterizedHeader($name,
115
      $this->_encoder, (strtolower($name) == 'content-disposition')
116
        ? $this->_paramEncoder
117
        : null
118
      );
119
    if (isset($value))
120
    {
121
      $header->setFieldBodyModel($value);
122
    }
123
    foreach ($params as $k => $v)
124
    {
125
      $header->setParameter($k, $v);
126
    }
127
    $this->_setHeaderCharset($header);
128
    return $header;
129
  }
130
 
131
  /**
132
   * Create a new ID header for Message-ID or Content-ID.
133
   * @param string $name
134
   * @param string|array $ids
135
   * @return Swift_Mime_Header
136
   */
137
  public function createIdHeader($name, $ids = null)
138
  {
139
    $header = new Swift_Mime_Headers_IdentificationHeader($name);
140
    if (isset($ids))
141
    {
142
      $header->setFieldBodyModel($ids);
143
    }
144
    $this->_setHeaderCharset($header);
145
    return $header;
146
  }
147
 
148
  /**
149
   * Create a new Path header with an address (path) in it.
150
   * @param string $name
151
   * @param string $path
152
   * @return Swift_Mime_Header
153
   */
154
  public function createPathHeader($name, $path = null)
155
  {
156
    $header = new Swift_Mime_Headers_PathHeader($name);
157
    if (isset($path))
158
    {
159
      $header->setFieldBodyModel($path);
160
    }
161
    $this->_setHeaderCharset($header);
162
    return $header;
163
  }
164
 
165
  /**
166
   * Notify this observer that the entity's charset has changed.
167
   * @param string $charset
168
   */
169
  public function charsetChanged($charset)
170
  {
171
    $this->_charset = $charset;
172
    $this->_encoder->charsetChanged($charset);
173
    $this->_paramEncoder->charsetChanged($charset);
174
  }
175
 
176
  // -- Private methods
177
 
178
  /** Apply the charset to the Header */
179
  private function _setHeaderCharset(Swift_Mime_Header $header)
180
  {
181
    if (isset($this->_charset))
182
    {
183
      $header->setCharset($this->_charset);
184
    }
185
  }
186
 
187
}