|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace ZBateson\MailMimeParser\Header\Part; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Abstract base class representing a single part of a parsed header. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Zaahid Bateson |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class HeaderPart |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string the value of the part |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $value; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the part's value. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string the value of the part |
|
25
|
|
|
*/ |
|
26
|
13 |
|
public function getValue() |
|
27
|
|
|
{ |
|
28
|
13 |
|
return $this->value; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns the value of the part (which is a string). |
|
33
|
|
|
* |
|
34
|
|
|
* @return string the value |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function __toString() |
|
37
|
|
|
{ |
|
38
|
2 |
|
return $this->value; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns true if spaces before this part should be ignored. True is only |
|
43
|
|
|
* returned for MimeLiterals if the part begins with a mime-encoded string, |
|
44
|
|
|
* Tokens if the Token's value is a single space, and for CommentParts. |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function ignoreSpacesBefore() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return false; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns true if spaces after this part should be ignored. True is only |
|
55
|
|
|
* returned for MimeLiterals if the part ends with a mime-encoded string |
|
56
|
|
|
* Tokens if the Token's value is a single space, and for CommentParts. |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function ignoreSpacesAfter() |
|
61
|
|
|
{ |
|
62
|
1 |
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Ensures the encoding of the passed string is set to UTF-8. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $str |
|
69
|
|
|
* @return string utf-8 string |
|
70
|
|
|
*/ |
|
71
|
18 |
|
protected function convertEncoding($str) |
|
72
|
|
|
{ |
|
73
|
18 |
|
if (!mb_check_encoding($str, 'UTF-8')) { |
|
74
|
|
|
return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); |
|
75
|
|
|
} |
|
76
|
18 |
|
return $str; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|