|
12 | 12 | use Laminas\Mail\AddressList;
|
13 | 13 | use Laminas\Mail\Exception;
|
14 | 14 | use Laminas\Mail\Header;
|
| 15 | +use Laminas\Mail\Header\GenericHeader; |
15 | 16 | use Laminas\Mail\Headers;
|
16 | 17 | use Laminas\Mail\Message;
|
17 | 18 | use Laminas\Mime\Message as MimeMessage;
|
@@ -873,4 +874,116 @@ public function testSecondCodeInjectionInFromHeader()
|
873 | 874 | $message->setFrom('user@xenial(tmp1 -be ${run{${substr{0}{1}{$spool_directory}}usr${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}touch${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}test}} tmp2)', 'Sender\'s name');
|
874 | 875 | // @codingStandardsIgnoreEnd
|
875 | 876 | }
|
| 877 | + |
| 878 | + public function testMessageSubjectFromString() |
| 879 | + { |
| 880 | + $rawMessage = 'Subject: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 881 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?='; |
| 882 | + $mail = Message::fromString($rawMessage); |
| 883 | + |
| 884 | + self::assertContains( |
| 885 | + 'Subject: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 886 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 887 | + $mail->toString() |
| 888 | + ); |
| 889 | + } |
| 890 | + |
| 891 | + public function testMessageSubjectSetSubject() |
| 892 | + { |
| 893 | + $mail = new Message(); |
| 894 | + $mail->setSubject('Non “ascii” characters like accented vowels òàùèéì'); |
| 895 | + |
| 896 | + self::assertContains( |
| 897 | + 'Subject: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 898 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 899 | + $mail->toString() |
| 900 | + ); |
| 901 | + } |
| 902 | + |
| 903 | + public function testCorrectHeaderEncodingAddHeader() |
| 904 | + { |
| 905 | + $mail = new Message(); |
| 906 | + $header = new GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì'); |
| 907 | + $mail->getHeaders()->addHeader($header); |
| 908 | + |
| 909 | + self::assertContains( |
| 910 | + 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 911 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 912 | + $mail->toString() |
| 913 | + ); |
| 914 | + } |
| 915 | + |
| 916 | + public function testCorrectHeaderEncodingSetHeaders() |
| 917 | + { |
| 918 | + $mail = new Message(); |
| 919 | + $header = new GenericHeader('X-Test', 'Non “ascii” characters like accented vowels òàùèéì'); |
| 920 | + $headers = new Headers(); |
| 921 | + $headers->addHeader($header); |
| 922 | + $mail->setHeaders($headers); |
| 923 | + |
| 924 | + self::assertContains( |
| 925 | + 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 926 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 927 | + $mail->toString() |
| 928 | + ); |
| 929 | + } |
| 930 | + |
| 931 | + public function testCorrectHeaderEncodingFromString() |
| 932 | + { |
| 933 | + $mail = new Message(); |
| 934 | + $str = 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 935 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?='; |
| 936 | + $header = GenericHeader::fromString($str); |
| 937 | + $mail->getHeaders()->addHeader($header); |
| 938 | + |
| 939 | + self::assertContains( |
| 940 | + 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 941 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 942 | + $mail->toString() |
| 943 | + ); |
| 944 | + } |
| 945 | + |
| 946 | + public function testCorrectHeaderEncodingFromStringAndSetHeaders() |
| 947 | + { |
| 948 | + $mail = new Message(); |
| 949 | + $str = 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 950 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?='; |
| 951 | + |
| 952 | + $header = GenericHeader::fromString($str); |
| 953 | + $headers = new Headers(); |
| 954 | + $headers->addHeader($header); |
| 955 | + $mail->setHeaders($headers); |
| 956 | + |
| 957 | + self::assertContains( |
| 958 | + 'X-Test: =?UTF-8?Q?Non=20=E2=80=9Cascii=E2=80=9D=20characters=20like=20accented=20?=' . "\r\n" |
| 959 | + . ' =?UTF-8?Q?vowels=20=C3=B2=C3=A0=C3=B9=C3=A8=C3=A9=C3=AC?=' . "\r\n", |
| 960 | + $mail->toString() |
| 961 | + ); |
| 962 | + } |
| 963 | + |
| 964 | + public function testMessageSubjectEncodingWhenEncodingSetAfterTheSubject() |
| 965 | + { |
| 966 | + $mail = new Message(); |
| 967 | + $mail->setSubject('hello world'); |
| 968 | + $mail->setEncoding('UTF-8'); |
| 969 | + |
| 970 | + self::assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); |
| 971 | + self::assertSame( |
| 972 | + 'Subject: =?UTF-8?Q?hello=20world?=', |
| 973 | + $mail->getHeaders()->get('subject')->toString() |
| 974 | + ); |
| 975 | + } |
| 976 | + |
| 977 | + public function testMessageSubjectEncodingWhenEcodingSetBeforeTheSubject() |
| 978 | + { |
| 979 | + $mail = new Message(); |
| 980 | + $mail->setEncoding('UTF-8'); |
| 981 | + $mail->setSubject('hello world'); |
| 982 | + |
| 983 | + self::assertSame('UTF-8', $mail->getHeaders()->get('subject')->getEncoding()); |
| 984 | + self::assertSame( |
| 985 | + 'Subject: =?UTF-8?Q?hello=20world?=', |
| 986 | + $mail->getHeaders()->get('subject')->toString() |
| 987 | + ); |
| 988 | + } |
876 | 989 | }
|
0 commit comments