1<?php
2
3/**
4 * SquirrelMail Test Plugin
5 *
6 * This page tests the decodeHeader function.
7 *
8 * @copyright 2006-2021 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id: decodeheader.php 14885 2021-02-05 19:19:32Z pdontthink $
11 * @package plugins
12 * @subpackage test
13 */
14
15define('SM_PATH', '../../');
16include_once(SM_PATH . 'include/validate.php');
17include_once(SM_PATH . 'functions/mime.php');
18
19global $oTemplate, $color;
20
21displayPageHeader($color, 'none');
22
23
24$header = array("< &  \xC3",                   // plain text
25                '=?iso-8859-1?Q?=3C_&__=C3?=', // Q encoding
26                '=?iso-8859-1?B?PCAmICDD?=',   // B encoding
27                '=?utf-8?Q?=3C_&__=C3=80?=',   // Q encoding other charset
28                '=?utf-8?B?PCAmICDDgA==?=',    // B encoding other charset
29);
30
31
32if (sqGetGlobalVar('lossy', $lossy, SQ_GET)) {
33    if ($lossy) {
34        $lossy_encoding = true;
35    } else {
36        if ($default_charset == 'utf-8')
37            $default_charset = 'iso-8859-1';
38        $lossy_encoding = false;
39    }
40}
41
42
43echo "<strong>decodeHeader() Test:</strong>\n";
44
45
46if ($default_charset == 'utf-8' || $lossy_encoding) {
47    echo '<p><a href="decodeheader.php?lossy=0">Test with lossy_encoding OFF</a></p>';
48} else {
49    echo '<p><a href="decodeheader.php?lossy=1">Test with lossy_encoding ON</a></p>';
50}
51
52
53echo '<p>Default charset: ' . $default_charset . "<br />\n"
54   . 'Lossy_encoding: ' . ($lossy_encoding ? 'true' : 'false') . '</p>';
55
56
57echo '<p>The results of this test depend on your current language (translation) selection (see Options==>Display Preferences) (and the character set it employs) and your $lossy_encoding setting (see config/config.php or conf.pl ==> 10 ==> 5).</p>';
58
59
60echo '<pre>';
61
62
63echo "(MDN) 000:\n html chars are not encoded,\n space is not encoded,\n 8bit chars are unmodified\n";
64foreach ($header as $test) {
65    echo htmlentities(decodeHeader($test, false, false, false));
66    echo "\n";
67}
68echo "--------\n";
69
70
71echo "(compose) 001:\n html chars are not encoded,\n space is not encoded,\n 8bit chars may be converted or not (depends on \$lossy_encoding and \$default_charset)\n";
72foreach ($header as $test) {
73    echo htmlentities(decodeHeader($test, false, false, true));
74    echo "\n";
75}
76echo "--------\n";
77
78
79echo "010\n";
80foreach ($header as $test) {
81    echo htmlentities(decodeHeader($test, false, true, false));
82    echo "\n";
83}
84echo "--------\n";
85
86
87echo "011\n";
88foreach ($header as $test) {
89    echo htmlentities(decodeHeader($test, false, true, true));
90    echo "\n";
91}
92echo "--------\n";
93
94
95echo "(download) 100\n";
96foreach ($header as $test) {
97    echo htmlentities(decodeHeader($test, true, false, false));
98    echo "\n";
99}
100echo "--------\n";
101
102
103echo "101\n";
104foreach ($header as $test) {
105    echo htmlentities(decodeHeader($test, true, false, true));
106    echo "\n";
107}
108echo "--------\n";
109
110
111echo "(default) 110\n";
112foreach ($header as $test) {
113    echo htmlentities(decodeHeader($test, true, true, false));
114    echo "\n";
115}
116echo "--------\n";
117
118
119echo "111\n";
120foreach ($header as $test) {
121    echo htmlentities(decodeHeader($test, true, true, true));
122    echo "\n";
123}
124echo "--------\n";
125
126
127echo '</pre></body></html>';
128
129
130