/home/csiway/public_html/admin/phpmailer/test/phpmailerTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
<?php
/**
 * PHPMailer - PHP email transport unit tests
 * Requires PHPUnit 3.3 or later.
 *
 * PHP version 5.0.0
 *
 * @package PHPMailer
 * @author Andy Prevost
 * @author Marcus Bointon <phpmailer@synchromedia.co.uk>
 * @copyright 2004 - 2009 Andy Prevost
 * @copyright 2010 Marcus Bointon
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */

require_once '../PHPMailerAutoload.php';

/**
 * PHPMailer - PHP email transport unit test class
 * Performs authentication tests
 */
class PHPMailerTest extends PHPUnit_Framework_TestCase
{
    
/**
     * Holds the default phpmailer instance.
     * @private
     * @var PHPMailer
     */
    
public $Mail;

    
/**
     * Holds the SMTP mail host.
     * @public
     * @var string
     */
    
public $Host '';

    
/**
     * Holds the change log.
     * @private
     * @var string[]
     */
    
public $ChangeLog = array();

    
/**
     * Holds the note log.
     * @private
     * @var string[]
     */
    
public $NoteLog = array();

    
/**
     * Default include path
     * @var string
     */
    
public $INCLUDE_DIR '../';

    
/**
     * PIDs of any processes we need to kill
     * @var array
     * @access private
     */
    
private $pids = array();

    
/**
     * Run before each test is started.
     */
    
public function setUp()
    {
        if (
file_exists('./testbootstrap.php')) {
            include 
'./testbootstrap.php'//Overrides go in here
        
}
        
$this->Mail = new PHPMailer;
        
$this->Mail->SMTPDebug 3//Full debug output
        
$this->Mail->Priority 3;
        
$this->Mail->Encoding '8bit';
        
$this->Mail->CharSet 'iso-8859-1';
        if (
array_key_exists('mail_from'$_REQUEST)) {
            
$this->Mail->From $_REQUEST['mail_from'];
        } else {
            
$this->Mail->From 'unit_test@phpmailer.example.com';
        }
        
$this->Mail->FromName 'Unit Tester';
        
$this->Mail->Sender '';
        
$this->Mail->Subject 'Unit Test';
        
$this->Mail->Body '';
        
$this->Mail->AltBody '';
        
$this->Mail->WordWrap 0;
        if (
array_key_exists('mail_host'$_REQUEST)) {
            
$this->Mail->Host $_REQUEST['mail_host'];
        } else {
            
$this->Mail->Host 'mail.example.com';
        }
        if (
array_key_exists('mail_port'$_REQUEST)) {
            
$this->Mail->Port $_REQUEST['mail_port'];
        } else {
            
$this->Mail->Port 25;
        }
        
$this->Mail->Helo 'localhost.localdomain';
        
$this->Mail->SMTPAuth false;
        
$this->Mail->Username '';
        
$this->Mail->Password '';
        
$this->Mail->PluginDir $this->INCLUDE_DIR;
        
$this->Mail->addReplyTo('no_reply@phpmailer.example.com''Reply Guy');
        
$this->Mail->Sender 'unit_test@phpmailer.example.com';
        if (
strlen($this->Mail->Host) > 0) {
            
$this->Mail->Mailer 'smtp';
        } else {
            
$this->Mail->Mailer 'mail';
        }
        if (
array_key_exists('mail_to'$_REQUEST)) {
            
$this->setAddress($_REQUEST['mail_to'], 'Test User''to');
        }
        if (
array_key_exists('mail_cc'$_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) {
            
$this->setAddress($_REQUEST['mail_cc'], 'Carbon User''cc');
        }
    }

    
/**
     * Run after each test is completed.
     */
    
public function tearDown()
    {
        
// Clean global variables
        
$this->Mail null;
        
$this->ChangeLog = array();
        
$this->NoteLog = array();

        foreach (
$this->pids as $pid) {
            
$p escapeshellarg($pid);
            
shell_exec("ps $p && kill -TERM $p");
        }
    }


    
/**
     * Build the body of the message in the appropriate format.
     *
     * @private
     * @return void
     */
    
public function buildBody()
    {
        
$this->checkChanges();

        
// Determine line endings for message
        
if ($this->Mail->ContentType == 'text/html' || strlen($this->Mail->AltBody) > 0) {
            
$eol "<br>\r\n";
            
$bullet_start '<li>';
            
$bullet_end "</li>\r\n";
            
$list_start "<ul>\r\n";
            
$list_end "</ul>\r\n";
        } else {
            
$eol "\r\n";
            
$bullet_start ' - ';
            
$bullet_end "\r\n";
            
$list_start '';
            
$list_end '';
        }

        
$ReportBody '';

        
$ReportBody .= '---------------------' $eol;
        
$ReportBody .= 'Unit Test Information' $eol;
        
$ReportBody .= '---------------------' $eol;
        
$ReportBody .= 'phpmailer version: ' $this->Mail->Version $eol;
        
$ReportBody .= 'Content Type: ' $this->Mail->ContentType $eol;
        
$ReportBody .= 'CharSet: ' $this->Mail->CharSet $eol;

        if (
strlen($this->Mail->Host) > 0) {
            
$ReportBody .= 'Host: ' $this->Mail->Host $eol;
        }

        
// If attachments then create an attachment list
        
$attachments $this->Mail->getAttachments();
        if (
count($attachments) > 0) {
            
$ReportBody .= 'Attachments:' $eol;
            
$ReportBody .= $list_start;
            foreach (
$attachments as $attachment) {
                
$ReportBody .= $bullet_start 'Name: ' $attachment[1] . ', ';
                
$ReportBody .= 'Encoding: ' $attachment[3] . ', ';
                
$ReportBody .= 'Type: ' $attachment[4] . $bullet_end;
            }
            
$ReportBody .= $list_end $eol;
        }

        
// If there are changes then list them
        
if (count($this->ChangeLog) > 0) {
            
$ReportBody .= 'Changes' $eol;
            
$ReportBody .= '-------' $eol;

            
$ReportBody .= $list_start;
            for (
$i 0$i count($this->ChangeLog); $i++) {
                
$ReportBody .= $bullet_start $this->ChangeLog[$i][0] . ' was changed to [' .
                    
$this->ChangeLog[$i][1] . ']' $bullet_end;
            }
            
$ReportBody .= $list_end $eol $eol;
        }

        
// If there are notes then list them
        
if (count($this->NoteLog) > 0) {
            
$ReportBody .= 'Notes' $eol;
            
$ReportBody .= '-----' $eol;

            
$ReportBody .= $list_start;
            for (
$i 0$i count($this->NoteLog); $i++) {
                
$ReportBody .= $bullet_start $this->NoteLog[$i] . $bullet_end;
            }
            
$ReportBody .= $list_end;
        }

        
// Re-attach the original body
        
$this->Mail->Body .= $eol $ReportBody;
    }

    
/**
     * Check which default settings have been changed for the report.
     * @private
     * @return void
     */
    
public function checkChanges()
    {
        if (
$this->Mail->Priority != 3) {
            
$this->addChange('Priority'$this->Mail->Priority);
        }
        if (
$this->Mail->Encoding != '8bit') {
            
$this->addChange('Encoding'$this->Mail->Encoding);
        }
        if (
$this->Mail->CharSet != 'iso-8859-1') {
            
$this->addChange('CharSet'$this->Mail->CharSet);
        }
        if (
$this->Mail->Sender != '') {
            
$this->addChange('Sender'$this->Mail->Sender);
        }
        if (
$this->Mail->WordWrap != 0) {
            
$this->addChange('WordWrap'$this->Mail->WordWrap);
        }
        if (
$this->Mail->Mailer != 'mail') {
            
$this->addChange('Mailer'$this->Mail->Mailer);
        }
        if (
$this->Mail->Port != 25) {
            
$this->addChange('Port'$this->Mail->Port);
        }
        if (
$this->Mail->Helo != 'localhost.localdomain') {
            
$this->addChange('Helo'$this->Mail->Helo);
        }
        if (
$this->Mail->SMTPAuth) {
            
$this->addChange('SMTPAuth''true');
        }
    }

    
/**
     * Add a changelog entry.
     * @access private
     * @param string $sName
     * @param string $sNewValue
     * @return void
     */
    
public function addChange($sName$sNewValue)
    {
        
$this->ChangeLog[] = array($sName$sNewValue);
    }

    
/**
     * Adds a simple note to the message.
     * @public
     * @param string $sValue
     * @return void
     */
    
public function addNote($sValue)
    {
        
$this->NoteLog[] = $sValue;
    }

    
/**
     * Adds all of the addresses
     * @access public
     * @param string $sAddress
     * @param string $sName
     * @param string $sType
     * @return boolean
     */
    
public function setAddress($sAddress$sName ''$sType 'to')
    {
        switch (
$sType) {
            case 
'to':
                return 
$this->Mail->addAddress($sAddress$sName);
            case 
'cc':
                return 
$this->Mail->addCC($sAddress$sName);
            case 
'bcc':
                return 
$this->Mail->addBCC($sAddress$sName);
        }
        return 
false;
    }

    
/**
     * Check that we have loaded default test params.
     * Pretty much everything will fail due to unset recipient if this is not done.
     */
    
public function testBootstrap()
    {
        
$this->assertTrue(
            
file_exists('./testbootstrap.php'),
            
'Test config params missing - copy testbootstrap.php to testbootstrap-dist.php and change as appropriate'
        
);
    }

    
/**
     * Test CRAM-MD5 authentication.
     * Needs a connection to a server that supports this auth mechanism, so commented out by default
     */
    
public function testAuthCRAMMD5()
    {
        
$this->Mail->Host 'hostname';
        
$this->Mail->Port 587;
        
$this->Mail->SMTPAuth true;
        
$this->Mail->SMTPSecure 'tls';
        
$this->Mail->AuthType 'CRAM-MD5';
        
$this->Mail->Username 'username';
        
$this->Mail->Password 'password';
        
$this->Mail->Body 'Test body';
        
$this->Mail->Subject .= ': Auth CRAM-MD5';
        
$this->Mail->From 'from@example.com';
        
$this->Mail->Sender 'from@example.com';
        
$this->Mail->clearAllRecipients();
        
$this->Mail->addAddress('user@example.com');
        
//$this->assertTrue($this->mail->send(), $this->mail->ErrorInfo);
    
}

    
/**
     * Test email address validation.
     * Test addresses obtained from http://isemail.info
     * Some failing cases commented out that are apparently up for debate!
     */
    
public function testValidate()
    {
        
$validaddresses = array(
            
'first@iana.org',
            
'first.last@iana.org',
            
'1234567890123456789012345678901234567890123456789012345678901234@iana.org',
            
'"first\"last"@iana.org',
            
'"first@last"@iana.org',
            
'"first\last"@iana.org',
            
'first.last@[12.34.56.78]',
            
'first.last@[IPv6:::12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]',
            
'first.last@[IPv6:::1111:2222:3333:4444:5555:6666]',
            
'first.last@[IPv6:1111:2222:3333::4444:5555:6666]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666::]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]',
            
'first.last@x23456789012345678901234567890123456789012345678901234567890123.iana.org',
            
'first.last@3com.com',
            
'first.last@123.iana.org',
            
'"first\last"@iana.org',
            
'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]',
            
'first.last@example.123',
            
'first.last@com',
            
'"Abc\@def"@iana.org',
            
'"Fred\ Bloggs"@iana.org',
            
'"Joe.\Blow"@iana.org',
            
'"Abc@def"@iana.org',
            
'"Fred Bloggs"@iana.org',
            
'user+mailbox@iana.org',
            
'customer/department=shipping@iana.org',
            
'$A12345@iana.org',
            
'!def!xyz%abc@iana.org',
            
'_somename@iana.org',
            
'dclo@us.ibm.com',
            
'peter.piper@iana.org',
            
'"Doug \"Ace\" L."@iana.org',
            
'test@iana.org',
            
'TEST@iana.org',
            
'1234567890@iana.org',
            
'test+test@iana.org',
            
'test-test@iana.org',
            
't*est@iana.org',
            
'+1~1+@iana.org',
            
'{_test_}@iana.org',
            
'"[[ test ]]"@iana.org',
            
'test.test@iana.org',
            
'"test.test"@iana.org',
            
'test."test"@iana.org',
            
'"test@test"@iana.org',
            
'test@123.123.123.x123',
            
'test@123.123.123.123',
            
'test@[123.123.123.123]',
            
'test@example.iana.org',
            
'test@example.example.iana.org',
            
'"test\test"@iana.org',
            
'test@example',
            
'"test\blah"@iana.org',
            
'"test\blah"@iana.org',
            
'"test\"blah"@iana.org',
            
'customer/department@iana.org',
            
'_Yosemite.Sam@iana.org',
            
'~@iana.org',
            
'"Austin@Powers"@iana.org',
            
'Ima.Fool@iana.org',
            
'"Ima.Fool"@iana.org',
            
'"Ima Fool"@iana.org',
            
'"first"."last"@iana.org',
            
'"first".middle."last"@iana.org',
            
'"first".last@iana.org',
            
'first."last"@iana.org',
            
'"first"."middle"."last"@iana.org',
            
'"first.middle"."last"@iana.org',
            
'"first.middle.last"@iana.org',
            
'"first..last"@iana.org',
            
'"first\"last"@iana.org',
            
'first."mid\dle"."last"@iana.org',
            
'"test blah"@iana.org',
            
'(foo)cal(bar)@(baz)iamcal.com(quux)',
            
'cal@iamcal(woo).(yay)com',
            
'cal(woo(yay)hoopla)@iamcal.com',
            
'cal(foo\@bar)@iamcal.com',
            
'cal(foo\)bar)@iamcal.com',
            
'first().last@iana.org',
            
'pete(his account)@silly.test(his host)',
            
'c@(Chris\'s host.)public.example',
            
'jdoe@machine(comment). example',
            
'1234 @ local(blah) .machine .example',
            
'first(abc.def).last@iana.org',
            
'first(a"bc.def).last@iana.org',
            
'first.(")middle.last(")@iana.org',
            
'first(abc\(def)@iana.org',
            
'first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com',
            
'a(a(b(c)d(e(f))g)h(i)j)@iana.org',
            
'name.lastname@domain.com',
            
'a@b',
            
'a@bar.com',
            
'aaa@[123.123.123.123]',
            
'a@bar',
            
'a-b@bar.com',
            
'+@b.c',
            
'+@b.com',
            
'a@b.co-foo.uk',
            
'"hello my name is"@stutter.com',
            
'"Test \"Fail\" Ing"@iana.org',
            
'valid@about.museum',
            
'shaitan@my-domain.thisisminekthx',
            
'foobar@192.168.0.1',
            
'"Joe\Blow"@iana.org',
            
'HM2Kinsists@(that comments are allowed)this.is.ok',
            
'user%uucp!path@berkeley.edu',
            
'first.last @iana.org',
            
'cdburgess+!#$%&\'*-/=?+_{}|~test@gmail.com',
            
'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]',
            
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]',
            
'first.last@[IPv6:::]',
            
'first.last@[IPv6:::b4]',
            
'first.last@[IPv6:::b3:b4]',
            
'first.last@[IPv6:a1::b4]',
            
'first.last@[IPv6:a1::]',
            
'first.last@[IPv6:a1:a2::]',
            
'first.last@[IPv6:0123:4567:89ab:cdef::]',
            
'first.last@[IPv6:0123:4567:89ab:CDEF::]',
            
'first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]',
            
'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]',
            
'first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]',
            
'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]',
            
'first.last@[IPv6:a1::11.22.33.44]',
            
'first.last@[IPv6:a1:a2::11.22.33.44]',
            
'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]',
            
'first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44]',
            
'first.last@[IPv6:a1::b2:11.22.33.44]',
            
'test@test.com',
            
'test@xn--example.com',
            
'test@example.com',
        );
        
$invalidaddresses = array(
            
'first.last@sub.do,com',
            
'first\@last@iana.org',
            
'123456789012345678901234567890123456789012345678901234567890' .
                
'@12345678901234567890123456789012345678901234 [...]',
            
'first.last',
            
'12345678901234567890123456789012345678901234567890123456789012345@iana.org',
            
'.first.last@iana.org',
            
'first.last.@iana.org',
            
'first..last@iana.org',
            
'"first"last"@iana.org',
            
'"""@iana.org',
            
'"\"@iana.org',
            
//'""@iana.org',
            
'first\@last@iana.org',
            
'first.last@',
            
'x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.' .
                
'x23456789.x23456789.x23456789.x23 [...]',
            
'first.last@[.12.34.56.78]',
            
'first.last@[12.34.56.789]',
            
'first.last@[::12.34.56.78]',
            
'first.last@[IPv5:::12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]',
            
'first.last@[IPv6:1111:2222::3333::4444:5555:6666]',
            
'first.last@[IPv6:1111:2222:333x::4444:5555]',
            
'first.last@[IPv6:1111:2222:33333::4444:5555]',
            
'first.last@-xample.com',
            
'first.last@exampl-.com',
            
'first.last@x234567890123456789012345678901234567890123456789012345678901234.iana.org',
            
'abc\@def@iana.org',
            
'abc\@iana.org',
            
'Doug\ \"Ace\"\ Lovell@iana.org',
            
'abc@def@iana.org',
            
'abc\@def@iana.org',
            
'abc\@iana.org',
            
'@iana.org',
            
'doug@',
            
'"qu@iana.org',
            
'ote"@iana.org',
            
'.dot@iana.org',
            
'dot.@iana.org',
            
'two..dot@iana.org',
            
'"Doug "Ace" L."@iana.org',
            
'Doug\ \"Ace\"\ L\.@iana.org',
            
'hello world@iana.org',
            
//'helloworld@iana .org',
            
'gatsby@f.sc.ot.t.f.i.tzg.era.l.d.',
            
'test.iana.org',
            
'test.@iana.org',
            
'test..test@iana.org',
            
'.test@iana.org',
            
'test@test@iana.org',
            
'test@@iana.org',
            
'-- test --@iana.org',
            
'[test]@iana.org',
            
'"test"test"@iana.org',
            
'()[]\;:,><@iana.org',
            
'test@.',
            
'test@example.',
            
'test@.org',
            
'test@12345678901234567890123456789012345678901234567890123456789012345678901234567890' .
                
'12345678901234567890 [...]',
            
'test@[123.123.123.123',
            
'test@123.123.123.123]',
            
'NotAnEmail',
            
'@NotAnEmail',
            
'"test"blah"@iana.org',
            
'.wooly@iana.org',
            
'wo..oly@iana.org',
            
'pootietang.@iana.org',
            
'.@iana.org',
            
'Ima Fool@iana.org',
            
'phil.h\@\@ck@haacked.com',
            
'foo@[\1.2.3.4]',
            
//'first."".last@iana.org',
            
'first\last@iana.org',
            
'Abc\@def@iana.org',
            
'Fred\ Bloggs@iana.org',
            
'Joe.\Blow@iana.org',
            
'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]',
            
'{^c\@**Dog^}@cartoon.com',
            
//'"foo"(yay)@(hoopla)[1.2.3.4]',
            
'cal(foo(bar)@iamcal.com',
            
'cal(foo)bar)@iamcal.com',
            
'cal(foo\)@iamcal.com',
            
'first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789' .
                
'01234567890123456789012 [...]',
            
'first(middle)last@iana.org',
            
'first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example' .
                
'(abc("def".ghi).mno). [...]',
            
'a(a(b(c)d(e(f))g)(h(i)j)@iana.org',
            
'.@',
            
'@bar.com',
            
'@@bar.com',
            
'aaa.com',
            
'aaa@.com',
            
'aaa@.123',
            
'aaa@[123.123.123.123]a',
            
'aaa@[123.123.123.333]',
            
'a@bar.com.',
            
'a@-b.com',
            
'a@b-.com',
            
'-@..com',
            
'-@a..com',
            
'invalid@about.museum-',
            
'test@...........com',
            
'"Unicode NULL' chr(0) . '"@char.com',
            
'Unicode NULL' chr(0) . '@char.com',
            
'first.last@[IPv6::]',
            
'first.last@[IPv6::::]',
            
'first.last@[IPv6::b4]',
            
'first.last@[IPv6::::b4]',
            
'first.last@[IPv6::b3:b4]',
            
'first.last@[IPv6::::b3:b4]',
            
'first.last@[IPv6:a1:::b4]',
            
'first.last@[IPv6:a1:]',
            
'first.last@[IPv6:a1:::]',
            
'first.last@[IPv6:a1:a2:]',
            
'first.last@[IPv6:a1:a2:::]',
            
'first.last@[IPv6::11.22.33.44]',
            
'first.last@[IPv6::::11.22.33.44]',
            
'first.last@[IPv6:a1:11.22.33.44]',
            
'first.last@[IPv6:a1:::11.22.33.44]',
            
'first.last@[IPv6:a1:a2:::11.22.33.44]',
            
'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx]',
            
'first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44]',
            
'first.last@[IPv6:a1::a4:b1::b4:11.22.33.44]',
            
'first.last@[IPv6:a1::11.22.33]',
            
'first.last@[IPv6:a1::11.22.33.44.55]',
            
'first.last@[IPv6:a1::b211.22.33.44]',
            
'first.last@[IPv6:a1::b2::11.22.33.44]',
            
'first.last@[IPv6:a1::b3:]',
            
'first.last@[IPv6::a2::b4]',
            
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]',
            
'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]',
            
'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]',
        );
        
// IDNs in Unicode and ASCII forms.
        
$unicodeaddresses = array(
            
'first.last@bücher.ch',
            
'first.last@кто.рф',
            
'first.last@phplíst.com',
        );
        
$asciiaddresses = array(
            
'first.last@xn--bcher-kva.ch',
            
'first.last@xn--j1ail.xn--p1ai',
            
'first.last@xn--phplst-6va.com',
        );
        
$goodfails = array();
        foreach (
array_merge($validaddresses$asciiaddresses) as $address) {
            if (!
PHPMailer::validateAddress($address)) {
                
$goodfails[] = $address;
            }
        }
        
$badpasses = array();
        foreach (
array_merge($invalidaddresses$unicodeaddresses) as $address) {
            if (
PHPMailer::validateAddress($address)) {
                
$badpasses[] = $address;
            }
        }
        
$err '';
        if (
count($goodfails) > 0) {
            
$err .= "Good addresses that failed validation:\n";
            
$err .= implode("\n"$goodfails);
        }
        if (
count($badpasses) > 0) {
            if (!empty(
$err)) {
                
$err .= "\n\n";
            }
            
$err .= "Bad addresses that passed validation:\n";
            
$err .= implode("\n"$badpasses);
        }
        
$this->assertEmpty($err$err);
        
//For coverage
        
$this->assertTrue(PHPMailer::validateAddress('test@example.com''auto'));
        
$this->assertFalse(PHPMailer::validateAddress('test@example.com.''auto'));
        
$this->assertTrue(PHPMailer::validateAddress('test@example.com''pcre'));
        
$this->assertFalse(PHPMailer::validateAddress('test@example.com.''pcre'));
        
$this->assertTrue(PHPMailer::validateAddress('test@example.com''pcre8'));
        
$this->assertFalse(PHPMailer::validateAddress('test@example.com.''pcre8'));
        
$this->assertTrue(PHPMailer::validateAddress('test@example.com''php'));
        
$this->assertFalse(PHPMailer::validateAddress('test@example.com.''php'));
        
$this->assertTrue(PHPMailer::validateAddress('test@example.com''noregex'));
        
$this->assertFalse(PHPMailer::validateAddress('bad''noregex'));
    }

    
/**
     * Word-wrap an ASCII message.
     */
    
public function testWordWrap()
    {
        
$this->Mail->WordWrap 40;
        
$my_body str_repeat(
            
'Here is the main body of this message.  It should ' .
            
'be quite a few lines.  It should be wrapped at ' .
            
'40 characters.  Make sure that it is. ',
            
10
        
);
        
$nBodyLen strlen($my_body);
        
$my_body .= "\n\nThis is the above body length: " $nBodyLen;

        
$this->Mail->Body $my_body;
        
$this->Mail->Subject .= ': Wordwrap';

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Word-wrap a multibyte message.
     */
    
public function testWordWrapMultibyte()
    {
        
$this->Mail->WordWrap 40;
        
$my_body str_repeat(
            
'飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 ' .
            
'飛飛兒樂 團光茫兒樂 團光茫飛兒樂 團光飛兒樂 團光茫飛兒樂 團光茫兒樂 團光茫 ' .
            
'飛兒樂 團光茫飛兒樂 團飛兒樂 團光茫光茫飛兒樂 團光茫. ',
            
10
        
);
        
$nBodyLen strlen($my_body);
        
$my_body .= "\n\nThis is the above body length: " $nBodyLen;

        
$this->Mail->Body $my_body;
        
$this->Mail->Subject .= ': Wordwrap multibyte';

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test low priority.
     */
    
public function testLowPriority()
    {
        
$this->Mail->Priority 5;
        
$this->Mail->Body 'Here is the main body.  There should be ' .
            
'a reply to address in this message.';
        
$this->Mail->Subject .= ': Low Priority';
        
$this->Mail->addReplyTo('nobody@nobody.com''Nobody (Unit Test)');

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple plain file attachment test.
     */
    
public function testMultiplePlainFileAttachment()
    {
        
$this->Mail->Body 'Here is the text body';
        
$this->Mail->Subject .= ': Plain + Multiple FileAttachments';

        if (!
$this->Mail->addAttachment('../examples/images/phpmailer.png')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        if (!
$this->Mail->addAttachment(__FILE__'test.txt')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple plain string attachment test.
     */
    
public function testPlainStringAttachment()
    {
        
$this->Mail->Body 'Here is the text body';
        
$this->Mail->Subject .= ': Plain + StringAttachment';

        
$sAttachment 'These characters are the content of the ' .
            
"string attachment.\nThis might be taken from a " .
            
'database or some other such thing. ';

        
$this->Mail->addStringAttachment($sAttachment'string_attach.txt');

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Plain quoted-printable message.
     */
    
public function testQuotedPrintable()
    {
        
$this->Mail->Body 'Here is the main body';
        
$this->Mail->Subject .= ': Plain + Quoted-printable';
        
$this->Mail->Encoding 'quoted-printable';

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
//Check that a quoted printable encode and decode results in the same as went in
        
$t file_get_contents(__FILE__); //Use this file as test content
        //Force line breaks to UNIX-style
        
$t str_replace(array("\r\n""\r"), "\n"$t);
        
$this->assertEquals(
            
$t,
            
quoted_printable_decode($this->Mail->encodeQP($t)),
            
'Quoted-Printable encoding round-trip failed'
        
);
        
$this->assertEquals(
            
$this->Mail->encodeQP($t),
            
$this->Mail->encodeQPphp($t),
            
'Quoted-Printable BC wrapper failed'
        
);
        
//Force line breaks to Windows-style
        
$t str_replace("\n""\r\n"$t);
        
$this->assertEquals(
            
$t,
            
quoted_printable_decode($this->Mail->encodeQP($t)),
            
'Quoted-Printable encoding round-trip failed (Windows line breaks)'
        
);
    }

    
/**
     * Send an HTML message.
     */
    
public function testHtml()
    {
        
$this->Mail->isHTML(true);
        
$this->Mail->Subject .= ": HTML only";

        
$this->Mail->Body = <<<EOT
<html>
    <head>
        <title>HTML email test</title>
    </head>
    <body>
        <h1>PHPMailer does HTML!</h1>
        <p>This is a <strong>test message</strong> written in HTML.<br>
        Go to <a href="https://github.com/PHPMailer/PHPMailer/">https://github.com/PHPMailer/PHPMailer/</a>
        for new versions of PHPMailer.</p>
        <p>Thank you!</p>
    </body>
</html>
EOT;
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$msg $this->Mail->getSentMIMEMessage();
        
$this->assertNotContains("\r\n\r\nMIME-Version:"$msg'Incorrect MIME headers');
    }

    
/**
     * Send a message containing ISO-8859-1 text.
     */
    
public function testHtmlIso8859()
    {
        
$this->Mail->isHTML(true);
        
$this->Mail->Subject .= ": ISO-8859-1 HTML";
        
$this->Mail->CharSet 'iso-8859-1';

        
//This file is in ISO-8859-1 charset
        //Needs to be external because this file is in UTF-8
        
$content file_get_contents('../examples/contents.html');
        
// This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded
        
$check base64_decode('6eju/OfF8ebf');
        
//Make sure it really is in ISO-8859-1!
        
$this->Mail->msgHTML(
            
mb_convert_encoding(
                
$content,
                
"ISO-8859-1",
                
mb_detect_encoding($content"UTF-8, ISO-8859-1, ISO-8859-15"true)
            ),
            
'../examples'
        
);
        
$this->buildBody();
        
$this->assertTrue(
            
strpos($this->Mail->Body$check) !== false,
            
'ISO message body does not contain expected text'
        
);
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Send a message containing multilingual UTF-8 text.
     */
    
public function testHtmlUtf8()
    {
        
$this->Mail->isHTML(true);
        
$this->Mail->Subject .= ": UTF-8 HTML";
        
$this->Mail->CharSet 'UTF-8';

        
$this->Mail->Body = <<<EOT
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>HTML email test</title>
    </head>
    <body>
        <p>Chinese text: 郵件內容為空</p>
        <p>Russian text: Пустое тело сообщения</p>
        <p>Armenian text: Հաղորդագրությունը դատարկ է</p>
        <p>Czech text: Prázdné tělo zprávy</p>
    </body>
</html>
EOT;
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$msg $this->Mail->getSentMIMEMessage();
        
$this->assertNotContains("\r\n\r\nMIME-Version:"$msg'Incorrect MIME headers');
    }

    
/**
     * Send a message containing multilingual UTF-8 text with an embedded image.
     */
    
public function testUtf8WithEmbeddedImage()
    {
        
$this->Mail->isHTML(true);
        
$this->Mail->Subject .= ": UTF-8 with embedded image";
        
$this->Mail->CharSet 'UTF-8';

        
$this->Mail->Body = <<<EOT
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>HTML email test</title>
    </head>
    <body>
        <p>Chinese text: 郵件內容為空</p>
        <p>Russian text: Пустое тело сообщения</p>
        <p>Armenian text: Հաղորդագրությունը դատարկ է</p>
        <p>Czech text: Prázdné tělo zprávy</p>
        Embedded Image: <img alt="phpmailer" src="cid:my-attach">
    </body>
</html>
EOT;
        
$this->Mail->addEmbeddedImage(
            
'../examples/images/phpmailer.png',
            
'my-attach',
            
'phpmailer.png',
            
'base64',
            
'image/png'
        
);
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Send a message containing multilingual UTF-8 text.
     */
    
public function testPlainUtf8()
    {
        
$this->Mail->isHTML(false);
        
$this->Mail->Subject .= ": UTF-8 plain text";
        
$this->Mail->CharSet 'UTF-8';

        
$this->Mail->Body = <<<EOT
Chinese text: 郵件內容為空
Russian text: Пустое тело сообщения
Armenian text: Հաղորդագրությունը դատարկ է
Czech text: Prázdné tělo zprávy
EOT;
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$msg $this->Mail->getSentMIMEMessage();
        
$this->assertNotContains("\r\n\r\nMIME-Version:"$msg'Incorrect MIME headers');
    }

    
/**
     * Test simple message builder and html2text converters
     */
    
public function testMsgHTML()
    {
        
$message file_get_contents('../examples/contentsutf8.html');
        
$this->Mail->CharSet 'utf-8';
        
$this->Mail->Body '';
        
$this->Mail->AltBody '';
        
//Uses internal HTML to text conversion
        
$this->Mail->msgHTML($message'../examples');
        
$this->Mail->Subject .= ': msgHTML';

        
$this->assertNotEmpty($this->Mail->Body'Body not set by msgHTML');
        
$this->assertNotEmpty($this->Mail->AltBody'AltBody not set by msgHTML');
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
//Again, using a custom HTML to text converter
        
$this->Mail->AltBody '';
        
$this->Mail->msgHTML($message'../examples', function ($html) {
            return 
strtoupper(strip_tags($html));
        });
        
$this->Mail->Subject .= ' + custom html2text';
        
$this->assertNotEmpty($this->Mail->AltBody'Custom AltBody not set by msgHTML');

        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple HTML and attachment test
     */
    
public function testHTMLAttachment()
    {
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->Subject .= ': HTML + Attachment';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addAttachment('../examples/images/phpmailer_mini.png''phpmailer_mini.png')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
//Make sure that trying to attach a nonexistent file fails
        
$this->assertFalse($this->Mail->addAttachment(__FILE__ md5(microtime()), 'nonexistent_file.txt'));

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test embedded image without a name
     */
    
public function testHTMLStringEmbedNoName()
    {
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->Subject .= ': HTML + unnamed embedded image';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addStringEmbeddedImage(
            
file_get_contents('../examples/images/phpmailer_mini.png'),
            
md5('phpmailer_mini.png').'@phpmailer.0',
            
''//intentionally empty name
            
'base64',
            
'image/png',
            
'inline')
        ) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple HTML and multiple attachment test
     */
    
public function testHTMLMultiAttachment()
    {
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->Subject .= ': HTML + multiple Attachment';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addAttachment('../examples/images/phpmailer_mini.png''phpmailer_mini.png')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        if (!
$this->Mail->addAttachment('../examples/images/phpmailer.png''phpmailer.png')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * An embedded attachment test.
     */
    
public function testEmbeddedImage()
    {
        
$this->Mail->Body 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
            
'Here is an image!';
        
$this->Mail->Subject .= ': Embedded Image';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addEmbeddedImage(
            
'../examples/images/phpmailer.png',
            
'my-attach',
            
'phpmailer.png',
            
'base64',
            
'image/png'
        
)
        ) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
//For code coverage
        
$this->Mail->addEmbeddedImage('thisfiledoesntexist''xyz'); //Non-existent file
        
$this->Mail->addEmbeddedImage(__FILE__'123'); //Missing name
    
}

    
/**
     * An embedded attachment test.
     */
    
public function testMultiEmbeddedImage()
    {
        
$this->Mail->Body 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
            
'Here is an image!</a>';
        
$this->Mail->Subject .= ': Embedded Image + Attachment';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addEmbeddedImage(
            
'../examples/images/phpmailer.png',
            
'my-attach',
            
'phpmailer.png',
            
'base64',
            
'image/png'
        
)
        ) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        if (!
$this->Mail->addAttachment(__FILE__'test.txt')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple multipart/alternative test.
     */
    
public function testAltBody()
    {
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->AltBody 'Here is the text body of this message.  ' .
            
'It should be quite a few lines.  It should be wrapped at the ' .
            
'40 characters.  Make sure that it is.';
        
$this->Mail->WordWrap 40;
        
$this->addNote('This is a mulipart alternative email');
        
$this->Mail->Subject .= ': AltBody + Word Wrap';

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Simple HTML and attachment test
     */
    
public function testAltBodyAttachment()
    {
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->AltBody 'This is the text part of the email.';
        
$this->Mail->Subject .= ': AltBody + Attachment';
        
$this->Mail->isHTML(true);

        if (!
$this->Mail->addAttachment(__FILE__'test_attach.txt')) {
            
$this->assertTrue(false$this->Mail->ErrorInfo);
            return;
        }

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        if (
is_writable('.')) {
            
file_put_contents('message.txt'$this->Mail->createHeader() . $this->Mail->createBody());
        } else {
            
$this->assertTrue(false'Could not write local file - check permissions');
        }
    }

    
/**
     * iCal event test.
     */
    
public function testIcal()
    {
        
//Standalone ICS tests
        
require_once '../extras/EasyPeasyICS.php';
        
$ICS = new EasyPeasyICS("PHPMailer test calendar");
        
$this->assertNotEmpty(
            
$ICS->addEvent(
                
strtotime('tomorrow 10:00 Europe/Paris'),
                
strtotime('tomorrow 11:00 Europe/Paris'),
                
'PHPMailer iCal test',
                
'A test of PHPMailer iCal support',
                
'https://github.com/PHPMailer/PHPMailer'
            
),
            
'Generated event string is empty'
        
);
        
$ICS->addEvent(
            
strtotime('tomorrow 10:00 Europe/Paris'),
            
strtotime('tomorrow 11:00 Europe/Paris'),
            
'PHPMailer iCal test',
            
'A test of PHPMailer iCal support',
            
'https://github.com/PHPMailer/PHPMailer'
        
);
        
$events $ICS->getEvents();
        
$this->assertEquals(2count($events), 'Event count mismatch');
        
$ICS->clearEvents();
        
$events $ICS->getEvents();
        
$this->assertEquals(0count($events), 'Event clearing failed');
        
$ICS->setName('test');
        
$this->assertEquals('test'$ICS->getName(), 'Setting ICS name failed');
        
$this->assertNotEmpty($ICS->render(false), 'Empty calendar');
        
//Need to test generated output but PHPUnit isn't playing nice
        //$rendered = $ICS->render();

        //Test sending an ICS
        
$this->Mail->Body 'This is the <strong>HTML</strong> part of the email.';
        
$this->Mail->AltBody 'This is the text part of the email.';
        
$this->Mail->Subject .= ': iCal';
        
$this->Mail->isHTML(true);
        
$this->buildBody();
        
$this->Mail->Ical $ICS->render(false);
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test sending multiple messages with separate connections.
     */
    
public function testMultipleSend()
    {
        
$this->Mail->Body 'Sending two messages without keepalive';
        
$this->buildBody();
        
$subject $this->Mail->Subject;

        
$this->Mail->Subject $subject ': SMTP 1';
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
$this->Mail->Subject $subject ': SMTP 2';
        
$this->Mail->Sender 'blah@example.com';
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test sending using SendMail.
     */
    
public function testSendmailSend()
    {
        
$this->Mail->Body 'Sending via sendmail';
        
$this->buildBody();
        
$subject $this->Mail->Subject;

        
$this->Mail->Subject $subject ': sendmail';
        
$this->Mail->isSendmail();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test sending using Qmail.
     */
    
public function testQmailSend()
    {
        
//Only run if we have qmail installed
        
if (file_exists('/var/qmail/bin/qmail-inject')) {
            
$this->Mail->Body 'Sending via qmail';
            
$this->BuildBody();
            
$subject $this->Mail->Subject;

            
$this->Mail->Subject $subject ': qmail';
            
$this->Mail->IsQmail();
            
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
        } else {
            
$this->markTestSkipped('Qmail is not installed');
        }
    }

    
/**
     * Test sending using PHP mail() function.
     */
    
public function testMailSend()
    {
        
$sendmail ini_get('sendmail_path');
        
//No path in sendmail_path
        
if (strpos($sendmail'/') === false) {
            
ini_set('sendmail_path''/usr/sbin/sendmail -t -i ');
        }
        
$this->Mail->Body 'Sending via mail()';
        
$this->buildBody();

        
$this->Mail->Subject $this->Mail->Subject ': mail()';
        
$this->Mail->isMail();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$msg $this->Mail->getSentMIMEMessage();
        
$this->assertNotContains("\r\n\r\nMIME-Version:"$msg'Incorrect MIME headers');
    }

    
/**
     * Test sending an empty body.
     */
    
public function testEmptyBody()
    {
        
$this->buildBody();
        
$this->Mail->Body '';
        
$this->Mail->Subject $this->Mail->Subject ': Empty Body';
        
$this->Mail->isMail();
        
$this->Mail->AllowEmpty true;
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$this->Mail->AllowEmpty false;
        
$this->assertFalse($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Test constructing a message that contains lines that are too long for RFC compliance.
     */
    
public function testLongBody()
    {
        
$oklen str_repeat(str_repeat('0'PHPMailer::MAX_LINE_LENGTH) . PHPMailer::CRLF10);
        
$badlen str_repeat(str_repeat('1'PHPMailer::MAX_LINE_LENGTH 1) . PHPMailer::CRLF2);

        
$this->Mail->Body "This message contains lines that are too long.".
            
PHPMailer::CRLF PHPMailer::CRLF $oklen $badlen $oklen;
        
$this->assertTrue(
            
PHPMailer::hasLineLongerThanMax($this->Mail->Body),
            
'Test content does not contain long lines!'
        
);
        
$this->buildBody();
        
$this->Mail->Encoding '8bit';
        
$this->Mail->preSend();
        
$message $this->Mail->getSentMIMEMessage();
        
$this->assertFalse(PHPMailer::hasLineLongerThanMax($message), 'Long line not corrected.');
        
$this->assertContains(
            
'Content-Transfer-Encoding: quoted-printable',
            
$message,
            
'Long line did not cause transfer encoding switch.'
        
);
    }

    
/**
     * Test constructing a message that does NOT contain lines that are too long for RFC compliance.
     */
    
public function testShortBody()
    {
        
$oklen str_repeat(str_repeat('0'PHPMailer::MAX_LINE_LENGTH) . PHPMailer::CRLF10);

        
$this->Mail->Body "This message does not contain lines that are too long.".
            
PHPMailer::CRLF PHPMailer::CRLF $oklen;
        
$this->assertFalse(
            
PHPMailer::hasLineLongerThanMax($this->Mail->Body),
            
'Test content contains long lines!'
        
);
        
$this->buildBody();
        
$this->Mail->Encoding '8bit';
        
$this->Mail->preSend();
        
$message $this->Mail->getSentMIMEMessage();
        
$this->assertFalse(PHPMailer::hasLineLongerThanMax($message), 'Long line not corrected.');
        
$this->assertNotContains(
            
'Content-Transfer-Encoding: quoted-printable',
            
$message,
            
'Short line caused transfer encoding switch.'
        
);
    }

    
/**
     * Test keepalive (sending multiple messages in a single connection).
     */
    
public function testSmtpKeepAlive()
    {
        
$this->Mail->Body 'SMTP keep-alive test.';
        
$this->buildBody();
        
$subject $this->Mail->Subject;

        
$this->Mail->SMTPKeepAlive true;
        
$this->Mail->Subject $subject ': SMTP keep-alive 1';
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
$this->Mail->Subject $subject ': SMTP keep-alive 2';
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$this->Mail->smtpClose();
    }

    
/**
     * Tests this denial of service attack:
     * @link http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
     */
    
public function testDenialOfServiceAttack()
    {
        
$this->Mail->Body 'This should no longer cause a denial of service.';
        
$this->buildBody();

        
$this->Mail->Subject substr(str_repeat('0123456789'100), 0998);
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
    }

    
/**
     * Tests this denial of service attack:
     * @link https://sourceforge.net/p/phpmailer/bugs/383/
     * According to the ticket, this should get stuck in a loop, though I can't make it happen.
     * @TODO No assertions in here - how can you assert for this?
     */
    
public function testDenialOfServiceAttack2()
    {
        
//Encoding name longer than 68 chars
        
$this->Mail->Encoding '1234567890123456789012345678901234567890123456789012345678901234567890';
        
//Call wrapText with a zero length value
        
$this->Mail->wrapText(str_repeat('This should no longer cause a denial of service. '30), 0);
    }

    
/**
     * Test error handling.
     */
    
public function testError()
    {
        
$this->Mail->Subject .= ': Error handling test - this should be sent ok';
        
$this->buildBody();
        
$this->Mail->clearAllRecipients(); // no addresses should cause an error
        
$this->assertTrue($this->Mail->isError() == false'Error found');
        
$this->assertTrue($this->Mail->send() == false'send succeeded');
        
$this->assertTrue($this->Mail->isError(), 'No error found');
        
$this->assertEquals('You must provide at least one recipient email address.'$this->Mail->ErrorInfo);
        
$this->Mail->addAddress($_REQUEST['mail_to']);
        
$this->assertTrue($this->Mail->send(), 'send failed');
    }

    
/**
     * Test addressing.
     */
    
public function testAddressing()
    {
        
$this->assertFalse($this->Mail->addAddress(''), 'Empty address accepted');
        
$this->assertFalse($this->Mail->addAddress('''Nobody'), 'Empty address with name accepted');
        
$this->assertFalse($this->Mail->addAddress('a@example..com'), 'Invalid address accepted');
        
$this->assertTrue($this->Mail->addAddress('a@example.com'), 'Addressing failed');
        
$this->assertFalse($this->Mail->addAddress('a@example.com'), 'Duplicate addressing failed');
        
$this->assertTrue($this->Mail->addCC('b@example.com'), 'CC addressing failed');
        
$this->assertFalse($this->Mail->addCC('b@example.com'), 'CC duplicate addressing failed');
        
$this->assertFalse($this->Mail->addCC('a@example.com'), 'CC duplicate addressing failed (2)');
        
$this->assertTrue($this->Mail->addBCC('c@example.com'), 'BCC addressing failed');
        
$this->assertFalse($this->Mail->addBCC('c@example.com'), 'BCC duplicate addressing failed');
        
$this->assertFalse($this->Mail->addBCC('a@example.com'), 'BCC duplicate addressing failed (2)');
        
$this->assertTrue($this->Mail->addReplyTo('a@example.com'), 'Replyto Addressing failed');
        
$this->assertFalse($this->Mail->addReplyTo('a@example..com'), 'Invalid Replyto address accepted');
        
$this->assertTrue($this->Mail->setFrom('a@example.com''some name'), 'setFrom failed');
        
$this->assertFalse($this->Mail->setFrom('a@example.com.''some name'), 'setFrom accepted invalid address');
        
$this->Mail->Sender '';
        
$this->Mail->setFrom('a@example.com''some name'true);
        
$this->assertEquals($this->Mail->Sender'a@example.com''setFrom failed to set sender');
        
$this->Mail->Sender '';
        
$this->Mail->setFrom('a@example.com''some name'false);
        
$this->assertEquals($this->Mail->Sender'''setFrom should not have set sender');
        
$this->Mail->clearCCs();
        
$this->Mail->clearBCCs();
        
$this->Mail->clearReplyTos();
    }

    
/**
     * Test RFC822 address splitting.
     */
    
public function testAddressSplitting()
    {
        
//Test built-in address parser
        
$this->assertCount(
            
2,
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com>, Jill User <jill@example.net>'
            
),
            
'Failed to recognise address list (IMAP parser)'
        
);
        
//Test simple address parser
        
$this->assertCount(
            
2,
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com>, Jill User <jill@example.net>',
                
false
            
),
            
'Failed to recognise address list'
        
);
        
//Test single address
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com>',
                
false
            
),
            
'Failed to recognise single address'
        
);
        
//Test quoted name IMAP
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'Tim "The Book" O\'Reilly <foo@example.com>'
            
),
            
'Failed to recognise quoted name (IMAP)'
        
);
        
//Test quoted name
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'Tim "The Book" O\'Reilly <foo@example.com>',
                
false
            
),
            
'Failed to recognise quoted name'
        
);
        
//Test single address IMAP
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com>'
            
),
            
'Failed to recognise single address (IMAP)'
        
);
        
//Test unnamed address
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'joe@example.com',
                
false
            
),
            
'Failed to recognise unnamed address'
        
);
        
//Test unnamed address IMAP
        
$this->assertNotEmpty(
            
$this->Mail->parseAddresses(
                
'joe@example.com'
            
),
            
'Failed to recognise unnamed address (IMAP)'
        
);
        
//Test invalid addresses
        
$this->assertEmpty(
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com.>, Jill User <jill.@example.net>'
            
),
            
'Failed to recognise invalid addresses (IMAP)'
        
);
        
//Test invalid addresses
        
$this->assertEmpty(
            
$this->Mail->parseAddresses(
                
'Joe User <joe@example.com.>, Jill User <jill.@example.net>',
                
false
            
),
            
'Failed to recognise invalid addresses'
        
);
    }

    
/**
     * Test address escaping.
     */
    
public function testAddressEscaping()
    {
        
$this->Mail->Subject .= ': Address escaping';
        
$this->Mail->clearAddresses();
        
$this->Mail->addAddress('foo@example.com''Tim "The Book" O\'Reilly');
        
$this->Mail->Body 'Test correct escaping of quotes in addresses.';
        
$this->buildBody();
        
$this->Mail->preSend();
        
$b $this->Mail->getSentMIMEMessage();
        
$this->assertTrue((strpos($b'To: "Tim \"The Book\" O\'Reilly" <foo@example.com>') !== false));
    }

    
/**
     * Test BCC-only addressing.
     */
    
public function testBCCAddressing()
    {
        
$this->Mail->Subject .= ': BCC-only addressing';
        
$this->buildBody();
        
$this->Mail->clearAllRecipients();
        
$this->assertTrue($this->Mail->addBCC('a@example.com'), 'BCC addressing failed');
        
$this->assertTrue($this->Mail->send(), 'send failed');
    }

    
/**
     * Encoding and charset tests.
     */
    
public function testEncodings()
    {
        
$this->Mail->CharSet 'iso-8859-1';
        
$this->assertEquals(
            
'=A1Hola!_Se=F1or!',
            
$this->Mail->encodeQ("\xa1Hola! Se\xf1or!"'text'),
            
'Q Encoding (text) failed'
        
);
        
$this->assertEquals(
            
'=A1Hola!_Se=F1or!',
            
$this->Mail->encodeQ("\xa1Hola! Se\xf1or!"'comment'),
            
'Q Encoding (comment) failed'
        
);
        
$this->assertEquals(
            
'=A1Hola!_Se=F1or!',
            
$this->Mail->encodeQ("\xa1Hola! Se\xf1or!"'phrase'),
            
'Q Encoding (phrase) failed'
        
);
        
$this->Mail->CharSet 'UTF-8';
        
$this->assertEquals(
            
'=C2=A1Hola!_Se=C3=B1or!',
            
$this->Mail->encodeQ("\xc2\xa1Hola! Se\xc3\xb1or!"'text'),
            
'Q Encoding (text) failed'
        
);
        
//Strings containing '=' are a special case
        
$this->assertEquals(
            
'Nov=C3=A1=3D',
            
$this->Mail->encodeQ("Nov\xc3\xa1="'text'),
            
'Q Encoding (text) failed 2'
        
);
    }

    
/**
     * Test base-64 encoding.
     */
    
public function testBase64()
    {
        
$this->Mail->Subject .= ': Base-64 encoding';
        
$this->Mail->Encoding 'base64';
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), 'Base64 encoding failed');
    }
    
/**
     * S/MIME Signing tests (self-signed).
     * @requires extension openssl
     */
    
public function testSigning()
    {
        
$this->Mail->Subject .= ': S/MIME signing';
        
$this->Mail->Body 'This message is S/MIME signed.';
        
$this->buildBody();

        
$dn = array(
            
'countryName' => 'UK',
            
'stateOrProvinceName' => 'Here',
            
'localityName' => 'There',
            
'organizationName' => 'PHP',
            
'organizationalUnitName' => 'PHPMailer',
            
'commonName' => 'PHPMailer Test',
            
'emailAddress' => 'phpmailer@example.com'
        
);
        
$keyconfig = array(
            
"digest_alg" => "sha256",
            
"private_key_bits" => 2048,
            
"private_key_type" => OPENSSL_KEYTYPE_RSA,
        );
        
$password 'password';
        
$certfile 'certfile.txt';
        
$keyfile 'keyfile.txt';

        
//Make a new key pair
        
$pk openssl_pkey_new($keyconfig);
        
//Create a certificate signing request
        
$csr openssl_csr_new($dn$pk);
        
//Create a self-signed cert
        
$cert openssl_csr_sign($csrnull$pk1);
        
//Save the cert
        
openssl_x509_export($cert$certout);
        
file_put_contents($certfile$certout);
        
//Save the key
        
openssl_pkey_export($pk$pkeyout$password);
        
file_put_contents($keyfile$pkeyout);

        
$this->Mail->sign(
            
$certfile,
            
$keyfile,
            
$password
        
);
        
$this->assertTrue($this->Mail->send(), 'S/MIME signing failed');

        
$msg $this->Mail->getSentMIMEMessage();
        
$this->assertNotContains("\r\n\r\nMIME-Version:"$msg'Incorrect MIME headers');
        
unlink($certfile);
        
unlink($keyfile);
    }

    
/**
     * S/MIME Signing tests using a CA chain cert.
     * To test that a generated message is signed correctly, save the message in a file
     * and use openssl along with the certs generated by this script:
     * `openssl smime -verify -in signed.eml -signer certfile.pem -CAfile cacertfile.pem`
     * @requires extension openssl
     */
    
public function testSigningWithCA()
    {
        
$this->Mail->Subject .= ': S/MIME signing with CA';
        
$this->Mail->Body 'This message is S/MIME signed with an extra CA cert.';
        
$this->buildBody();

        
$certprops = array(
            
'countryName' => 'UK',
            
'stateOrProvinceName' => 'Here',
            
'localityName' => 'There',
            
'organizationName' => 'PHP',
            
'organizationalUnitName' => 'PHPMailer',
            
'commonName' => 'PHPMailer Test',
            
'emailAddress' => 'phpmailer@example.com'
        
);
        
$cacertprops = array(
            
'countryName' => 'UK',
            
'stateOrProvinceName' => 'Here',
            
'localityName' => 'There',
            
'organizationName' => 'PHP',
            
'organizationalUnitName' => 'PHPMailer CA',
            
'commonName' => 'PHPMailer Test CA',
            
'emailAddress' => 'phpmailer@example.com'
        
);
        
$keyconfig = array(
            
"digest_alg" => "sha256",
            
"private_key_bits" => 2048,
            
"private_key_type" => OPENSSL_KEYTYPE_RSA,
        );
        
$password 'password';
        
$cacertfile 'cacertfile.pem';
        
$cakeyfile 'cakeyfile.pem';
        
$certfile 'certfile.pem';
        
$keyfile 'keyfile.pem';

        
//Create a CA cert
        //Make a new key pair
        
$capk openssl_pkey_new($keyconfig);
        
//Create a certificate signing request
        
$csr openssl_csr_new($cacertprops$capk);
        
//Create a self-signed cert
        
$cert openssl_csr_sign($csrnull$capk1);
        
//Save the CA cert
        
openssl_x509_export($cert$certout);
        
file_put_contents($cacertfile$certout);
        
//Save the CA key
        
openssl_pkey_export($capk$pkeyout$password);
        
file_put_contents($cakeyfile$pkeyout);

        
//Create a cert signed by our CA
        //Make a new key pair
        
$pk openssl_pkey_new($keyconfig);
        
//Create a certificate signing request
        
$csr openssl_csr_new($certprops$pk);
        
//Create a self-signed cert
        
$cert openssl_csr_sign($csr'file://' $cacertfile$capk1);
        
//Save the cert
        
openssl_x509_export($cert$certout);
        
file_put_contents($certfile$certout);
        
//Save the key
        
openssl_pkey_export($pk$pkeyout$password);
        
file_put_contents($keyfile$pkeyout);

        
$this->Mail->sign(
            
$certfile,
            
$keyfile,
            
$password,
            
$cacertfile
        
);
        
$this->assertTrue($this->Mail->send(), 'S/MIME signing with CA failed');
        
unlink($cacertfile);
        
unlink($cakeyfile);
        
unlink($certfile);
        
unlink($keyfile);
    }

    
/**
     * DKIM Signing tests.
     * @requires extension openssl
     */
    
public function testDKIM()
    {
        
$this->Mail->Subject .= ': DKIM signing';
        
$this->Mail->Body 'This message is DKIM signed.';
        
$this->buildBody();
        
$privatekeyfile 'dkim_private.key';
        
//Make a new key pair
        //(2048 bits is the recommended minimum key length -
        //gmail won't accept less than 1024 bits)
        
$pk openssl_pkey_new(
            array(
                
'private_key_bits' => 2048,
                
'private_key_type' => OPENSSL_KEYTYPE_RSA
            
)
        );
        
openssl_pkey_export_to_file($pk$privatekeyfile);
        
$this->Mail->DKIM_domain 'example.com';
        
$this->Mail->DKIM_private $privatekeyfile;
        
$this->Mail->DKIM_selector 'phpmailer';
        
$this->Mail->DKIM_passphrase ''//key is not encrypted
        
$this->assertTrue($this->Mail->send(), 'DKIM signed mail failed');
        
unlink($privatekeyfile);
    }

    
/**
     * Test line break reformatting.
     */
    
public function testLineBreaks()
    {
        
$unixsrc "hello\nWorld\nAgain\n";
        
$macsrc "hello\rWorld\rAgain\r";
        
$windowssrc "hello\r\nWorld\r\nAgain\r\n";
        
$mixedsrc "hello\nWorld\rAgain\r\n";
        
$target "hello\r\nWorld\r\nAgain\r\n";
        
$this->assertEquals($targetPHPMailer::normalizeBreaks($unixsrc), 'UNIX break reformatting failed');
        
$this->assertEquals($targetPHPMailer::normalizeBreaks($macsrc), 'Mac break reformatting failed');
        
$this->assertEquals($targetPHPMailer::normalizeBreaks($windowssrc), 'Windows break reformatting failed');
        
$this->assertEquals($targetPHPMailer::normalizeBreaks($mixedsrc), 'Mixed break reformatting failed');
    }

    
/**
     * Test line length detection
     */
    
public function testLineLength()
    {
        
$oklen str_repeat(str_repeat('0'PHPMailer::MAX_LINE_LENGTH)."\r\n"10);
        
$badlen str_repeat(str_repeat('1'PHPMailer::MAX_LINE_LENGTH 1) . "\r\n"2);
        
$this->assertTrue(PHPMailer::hasLineLongerThanMax($badlen), 'Long line not detected (only)');
        
$this->assertTrue(PHPMailer::hasLineLongerThanMax($oklen $badlen), 'Long line not detected (first)');
        
$this->assertTrue(PHPMailer::hasLineLongerThanMax($badlen $oklen), 'Long line not detected (last)');
        
$this->assertTrue(
            
PHPMailer::hasLineLongerThanMax($oklen $badlen $oklen),
            
'Long line not detected (middle)'
        
);
        
$this->assertFalse(PHPMailer::hasLineLongerThanMax($oklen), 'Long line false positive');
        
$this->Mail->isHTML(false);
        
$this->Mail->Subject .= ": Line length test";
        
$this->Mail->CharSet 'UTF-8';
        
$this->Mail->Encoding '8bit';
        
$this->Mail->Body $oklen $badlen $oklen $badlen;
        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$this->assertEquals('quoted-printable'$this->Mail->Encoding'Long line did not override transfer encoding');
    }

    
/**
     * Test setting and retrieving message ID.
     */
    
public function testMessageID()
    {
        
$this->Mail->Body 'Test message ID.';
        
$id md5(12345);
        
$this->Mail->MessageID $id;
        
$this->buildBody();
        
$this->Mail->preSend();
        
$lastid $this->Mail->getLastMessageID();
        
$this->assertEquals($lastid$id'Custom Message ID mismatch');
    }

    
/**
     * Miscellaneous calls to improve test coverage and some small tests.
     */
    
public function testMiscellaneous()
    {
        
$this->assertEquals('application/pdf'PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
        
$this->Mail->addCustomHeader('SomeHeader: Some Value');
        
$this->Mail->clearCustomHeaders();
        
$this->Mail->clearAttachments();
        
$this->Mail->isHTML(false);
        
$this->Mail->isSMTP();
        
$this->Mail->isMail();
        
$this->Mail->isSendmail();
        
$this->Mail->isQmail();
        
$this->Mail->setLanguage('fr');
        
$this->Mail->Sender '';
        
$this->Mail->createHeader();
        
$this->assertFalse($this->Mail->set('x''y'), 'Invalid property set succeeded');
        
$this->assertTrue($this->Mail->set('Timeout'11), 'Valid property set failed');
        
$this->assertTrue($this->Mail->set('AllowEmpty'null), 'Null property set failed');
        
$this->assertTrue($this->Mail->set('AllowEmpty'false), 'Valid property set of null property failed');
        
//Test pathinfo
        
$a '/mnt/files/飛兒樂 團光茫.mp3';
        
$q PHPMailer::mb_pathinfo($a);
        
$this->assertEquals($q['dirname'], '/mnt/files''UNIX dirname not matched');
        
$this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3''UNIX basename not matched');
        
$this->assertEquals($q['extension'], 'mp3''UNIX extension not matched');
        
$this->assertEquals($q['filename'], '飛兒樂 團光茫''UNIX filename not matched');
        
$this->assertEquals(
            
PHPMailer::mb_pathinfo($aPATHINFO_DIRNAME),
            
'/mnt/files',
            
'Dirname path element not matched'
        
);
        
$this->assertEquals(PHPMailer::mb_pathinfo($a'filename'), '飛兒樂 團光茫''Filename path element not matched');
        
$a 'c:\mnt\files\飛兒樂 團光茫.mp3';
        
$q PHPMailer::mb_pathinfo($a);
        
$this->assertEquals($q['dirname'], 'c:\mnt\files''Windows dirname not matched');
        
$this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3''Windows basename not matched');
        
$this->assertEquals($q['extension'], 'mp3''Windows extension not matched');
        
$this->assertEquals($q['filename'], '飛兒樂 團光茫''Windows filename not matched');
    }

    
/**
     * Use a fake POP3 server to test POP-before-SMTP auth.
     * With a known-good login
     */
    
public function testPopBeforeSmtpGood()
    {
        
//Start a fake POP server
        
$pid shell_exec('nohup ./runfakepopserver.sh >/dev/null 2>/dev/null & printf "%u" $!');
        
$this->pids[] = $pid;

        
sleep(2);
        
//Test a known-good login
        
$this->assertTrue(
            
POP3::popBeforeSmtp('localhost'110010'user''test'$this->Mail->SMTPDebug),
            
'POP before SMTP failed'
        
);
        
//Kill the fake server
        
shell_exec('kill -TERM '.escapeshellarg($pid));
        
sleep(2);
    }

    
/**
     * Use a fake POP3 server to test POP-before-SMTP auth.
     * With a known-bad login
     */
    
public function testPopBeforeSmtpBad()
    {
        
//Start a fake POP server on a different port
        //so we don't inadvertently connect to the previous instance
        
$pid shell_exec('nohup ./runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!');
        
$this->pids[] = $pid;

        
sleep(2);
        
//Test a known-bad login
        
$this->assertFalse(
            
POP3::popBeforeSmtp('localhost'110110'user''xxx'$this->Mail->SMTPDebug),
            
'POP before SMTP should have failed'
        
);
        
shell_exec('kill -TERM '.escapeshellarg($pid));
        
sleep(2);
    }

    
/**
     * Test SMTP host connections.
     * This test can take a long time, so run it last
     */
    
public function testSmtpConnect()
    {
        
$this->Mail->SMTPDebug 4//Show connection-level errors
        
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
        
$this->Mail->smtpClose();
        
$this->Mail->Host "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
        
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
        
$this->Mail->smtpClose();
        
$this->Mail->Host "localhost:12345;10.10.10.10:54321;" $_REQUEST['mail_host'];
        
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
        
$this->Mail->smtpClose();
        
$this->Mail->Host " localhost:12345 ; " $_REQUEST['mail_host'] . ' ';
        
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
        
$this->Mail->smtpClose();
        
$this->Mail->Host $_REQUEST['mail_host'];
        
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
        
$this->assertTrue(
            
$this->Mail->smtpConnect(array('ssl' => array('verify_depth' => 10))),
            
'SMTP connect with options failed'
        
);
    }

    
/**
     * Tests the Custom header getter
     */
    
public function testCustomHeaderGetter()
    {
        
$this->Mail->addCustomHeader('foo''bar');
        
$this->assertEquals(array(array('foo''bar')), $this->Mail->getCustomHeaders());

        
$this->Mail->addCustomHeader('foo''baz');
        
$this->assertEquals(array(
            array(
'foo''bar'),
            array(
'foo''baz')
        ), 
$this->Mail->getCustomHeaders());

        
$this->Mail->clearCustomHeaders();
        
$this->assertEmpty($this->Mail->getCustomHeaders());

        
$this->Mail->addCustomHeader('yux');
        
$this->assertEquals(array(array('yux')), $this->Mail->getCustomHeaders());

        
$this->Mail->addCustomHeader('Content-Type: application/json');
        
$this->assertEquals(array(
            array(
'yux'),
            array(
'Content-Type'' application/json')
        ), 
$this->Mail->getCustomHeaders());
    }

    
/**
     * Tests setting and retrieving ConfirmReadingTo address, also known as "read receipt" address.
     */
    
public function testConfirmReadingTo()
    {
        
$this->Mail->CharSet 'utf-8';
        
$this->buildBody();

        
$this->Mail->ConfirmReadingTo 'test@example..com';  //Invalid address
        
$this->assertFalse($this->Mail->send(), $this->Mail->ErrorInfo);

        
$this->Mail->ConfirmReadingTo ' test@example.com';  //Extra space to trim
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
        
$this->assertEquals(
            
'test@example.com',
            
$this->Mail->ConfirmReadingTo,
            
'Unexpected read receipt address');

        
$this->Mail->ConfirmReadingTo 'test@françois.ch';  //Address with IDN
        
if ($this->Mail->idnSupported()) {
            
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
            
$this->assertEquals(
                
'test@xn--franois-xxa.ch',
                
$this->Mail->ConfirmReadingTo,
                
'IDN address not converted to punycode');
        } else {
            
$this->assertFalse($this->Mail->send(), $this->Mail->ErrorInfo);
        }
    }

    
/**
     * Tests CharSet and Unicode -> ASCII conversions for addresses with IDN.
     */
    
public function testConvertEncoding()
    {
        if (!
$this->Mail->idnSupported()) {
            
$this->markTestSkipped('intl and/or mbstring extensions are not available');
        }

        
$this->Mail->clearAllRecipients();
        
$this->Mail->clearReplyTos();

        
// This file is UTF-8 encoded. Create a domain encoded in "iso-8859-1".
        
$domain '@' mb_convert_encoding('françois.ch''ISO-8859-1''UTF-8');
        
$this->Mail->addAddress('test' $domain);
        
$this->Mail->addCC('test+cc' $domain);
        
$this->Mail->addBCC('test+bcc' $domain);
        
$this->Mail->addReplyTo('test+replyto' $domain);

        
// Queued addresses are not returned by get*Addresses() before send() call.
        
$this->assertEmpty($this->Mail->getToAddresses(), 'Bad "to" recipients');
        
$this->assertEmpty($this->Mail->getCcAddresses(), 'Bad "cc" recipients');
        
$this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
        
$this->assertEmpty($this->Mail->getReplyToAddresses(), 'Bad "reply-to" recipients');

        
// Clear queued BCC recipient.
        
$this->Mail->clearBCCs();

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
// Addresses with IDN are returned by get*Addresses() after send() call.
        
$domain $this->Mail->punyencodeAddress($domain);
        
$this->assertEquals(
            array(array(
'test' $domain'')),
            
$this->Mail->getToAddresses(),
            
'Bad "to" recipients');
        
$this->assertEquals(
            array(array(
'test+cc' $domain'')),
            
$this->Mail->getCcAddresses(),
            
'Bad "cc" recipients');
        
$this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
        
$this->assertEquals(
            array(
'test+replyto' $domain => array('test+replyto' $domain'')),
            
$this->Mail->getReplyToAddresses(),
            
'Bad "reply-to" addresses');
    }

    
/**
     * Tests removal of duplicate recipients and reply-tos.
     */
    
public function testDuplicateIDNRemoved()
    {
        if (!
$this->Mail->idnSupported()) {
            
$this->markTestSkipped('intl and/or mbstring extensions are not available');
        }

        
$this->Mail->clearAllRecipients();
        
$this->Mail->clearReplyTos();

        
$this->Mail->CharSet 'utf-8';

        
$this->assertTrue($this->Mail->addAddress('test@françois.ch'));
        
$this->assertFalse($this->Mail->addAddress('test@françois.ch'));
        
$this->assertTrue($this->Mail->addAddress('test@FRANÇOIS.CH'));
        
$this->assertFalse($this->Mail->addAddress('test@FRANÇOIS.CH'));
        
$this->assertTrue($this->Mail->addAddress('test@xn--franois-xxa.ch'));
        
$this->assertFalse($this->Mail->addAddress('test@xn--franois-xxa.ch'));
        
$this->assertFalse($this->Mail->addAddress('test@XN--FRANOIS-XXA.CH'));

        
$this->assertTrue($this->Mail->addReplyTo('test+replyto@françois.ch'));
        
$this->assertFalse($this->Mail->addReplyTo('test+replyto@françois.ch'));
        
$this->assertTrue($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
        
$this->assertFalse($this->Mail->addReplyTo('test+replyto@FRANÇOIS.CH'));
        
$this->assertTrue($this->Mail->addReplyTo('test+replyto@xn--franois-xxa.ch'));
        
$this->assertFalse($this->Mail->addReplyTo('test+replyto@xn--franois-xxa.ch'));
        
$this->assertFalse($this->Mail->addReplyTo('test+replyto@XN--FRANOIS-XXA.CH'));

        
$this->buildBody();
        
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);

        
// There should be only one "To" address and one "Reply-To" address.
        
$this->assertEquals(
            
1,
            
count($this->Mail->getToAddresses()),
            
'Bad count of "to" recipients');
        
$this->assertEquals(
            
1,
            
count($this->Mail->getReplyToAddresses()),
            
'Bad count of "reply-to" addresses');
    }
}

/**
 * This is a sample form for setting appropriate test values through a browser
 * These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script
 * which is probably more useful if you run these tests a lot
 * <html>
 * <body>
 * <h3>phpmailer Unit Test</h3>
 * By entering a SMTP hostname it will automatically perform tests with SMTP.
 *
 * <form name="phpmailer_unit" action=__FILE__ method="get">
 * <input type="hidden" name="submitted" value="1"/>
 * From Address: <input type="text" size="50" name="mail_from" value="<?php echo get("mail_from"); ?>"/>
 * <br/>
 * To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/>
 * <br/>
 * Cc Address: <input type="text" size="50" name="mail_cc" value="<?php echo get("mail_cc"); ?>"/>
 * <br/>
 * SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/>
 * <p/>
 * <input type="submit" value="Run Test"/>
 *
 * </form>
 * </body>
 * </html>
 */