1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
18: {
19:
20: private $_encoder;
21:
22:
23: private $_paramEncoder;
24:
25:
26: private $_grammar;
27:
28:
29: private $_charset;
30:
31: 32: 33: 34: 35: 36: 37:
38: public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, Swift_Mime_Grammar $grammar, $charset = null)
39: {
40: $this->_encoder = $encoder;
41: $this->_paramEncoder = $paramEncoder;
42: $this->_grammar = $grammar;
43: $this->_charset = $charset;
44: }
45:
46: 47: 48: 49: 50: 51:
52: public function createMailboxHeader($name, $addresses = null)
53: {
54: $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder, $this->_grammar);
55: if (isset($addresses)) {
56: $header->setFieldBodyModel($addresses);
57: }
58: $this->_setHeaderCharset($header);
59:
60: return $header;
61: }
62:
63: 64: 65: 66: 67: 68:
69: public function createDateHeader($name, $timestamp = null)
70: {
71: $header = new Swift_Mime_Headers_DateHeader($name, $this->_grammar);
72: if (isset($timestamp)) {
73: $header->setFieldBodyModel($timestamp);
74: }
75: $this->_setHeaderCharset($header);
76:
77: return $header;
78: }
79:
80: 81: 82: 83: 84: 85:
86: public function createTextHeader($name, $value = null)
87: {
88: $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder, $this->_grammar);
89: if (isset($value)) {
90: $header->setFieldBodyModel($value);
91: }
92: $this->_setHeaderCharset($header);
93:
94: return $header;
95: }
96:
97: 98: 99: 100: 101: 102: 103:
104: public function createParameterizedHeader($name, $value = null,
105: $params = array())
106: {
107: $header = new Swift_Mime_Headers_ParameterizedHeader($name,
108: $this->_encoder, (strtolower($name) == 'content-disposition')
109: ? $this->_paramEncoder
110: : null,
111: $this->_grammar
112: );
113: if (isset($value)) {
114: $header->setFieldBodyModel($value);
115: }
116: foreach ($params as $k => $v) {
117: $header->setParameter($k, $v);
118: }
119: $this->_setHeaderCharset($header);
120:
121: return $header;
122: }
123:
124: 125: 126: 127: 128: 129:
130: public function createIdHeader($name, $ids = null)
131: {
132: $header = new Swift_Mime_Headers_IdentificationHeader($name, $this->_grammar);
133: if (isset($ids)) {
134: $header->setFieldBodyModel($ids);
135: }
136: $this->_setHeaderCharset($header);
137:
138: return $header;
139: }
140:
141: 142: 143: 144: 145: 146:
147: public function createPathHeader($name, $path = null)
148: {
149: $header = new Swift_Mime_Headers_PathHeader($name, $this->_grammar);
150: if (isset($path)) {
151: $header->setFieldBodyModel($path);
152: }
153: $this->_setHeaderCharset($header);
154:
155: return $header;
156: }
157:
158: 159: 160: 161:
162: public function charsetChanged($charset)
163: {
164: $this->_charset = $charset;
165: $this->_encoder->charsetChanged($charset);
166: $this->_paramEncoder->charsetChanged($charset);
167: }
168:
169:
170:
171:
172: private function _setHeaderCharset(Swift_Mime_Header $header)
173: {
174: if (isset($this->_charset)) {
175: $header->setCharset($this->_charset);
176: }
177: }
178: }
179: