1<?php 2// use no mbstring help here 3require_once DOKU_INC.'inc/init.php'; 4 5class mail_isvalid extends DokuWikiTest { 6 7 8 function test1(){ 9 $tests = array(); 10 11 // our own tests 12 $tests[] = array('bugs@php.net',true); 13 $tests[] = array('~someone@somewhere.com',true); 14 $tests[] = array('no+body.here@somewhere.com.au',true); 15 $tests[] = array('username+tag@domain.com',true); // FS#1447 16 $tests[] = array("rfc2822+allthesechars_#*!'`/-={}are.legal@somewhere.com.au",true); 17 $tests[] = array('_foo@test.com',true); // FS#1049 18 $tests[] = array('bugs@php.net1',true); // new ICAN rulez seem to allow this 19 $tests[] = array('.bugs@php.net1',false); 20 $tests[] = array('bu..gs@php.net',false); 21 $tests[] = array('bugs@php..net',false); 22 $tests[] = array('bugs@.php.net',false); 23 $tests[] = array('bugs@php.net.',false); 24 $tests[] = array('bu(g)s@php.net1',false); 25 $tests[] = array('bu[g]s@php.net1',false); 26 $tests[] = array('somebody@somewhere.museum',true); 27 $tests[] = array('somebody@somewhere.travel',true); 28 $tests[] = array('root@[2010:fb:fdac::311:2101]',true); 29 $tests[] = array('test@example', true); // we allow local addresses 30 31 // tests from http://code.google.com/p/php-email-address-validation/ below 32 33 $tests[] = array('test@example.com', true); 34 $tests[] = array('TEST@example.com', true); 35 $tests[] = array('1234567890@example.com', true); 36 $tests[] = array('test+test@example.com', true); 37 $tests[] = array('test-test@example.com', true); 38 $tests[] = array('t*est@example.com', true); 39 $tests[] = array('+1~1+@example.com', true); 40 $tests[] = array('{_test_}@example.com', true); 41 $tests[] = array('"[[ test ]]"@example.com', true); 42 $tests[] = array('test.test@example.com', true); 43 $tests[] = array('test."test"@example.com', true); 44 $tests[] = array('"test@test"@example.com', true); 45 $tests[] = array('test@123.123.123.123', true); 46 $tests[] = array('test@[123.123.123.123]', true); 47 $tests[] = array('test@example.example.com', true); 48 $tests[] = array('test@example.example.example.com', true); 49 50 $tests[] = array('test.example.com', false); 51 $tests[] = array('test.@example.com', false); 52 $tests[] = array('test..test@example.com', false); 53 $tests[] = array('.test@example.com', false); 54 $tests[] = array('test@test@example.com', false); 55 $tests[] = array('test@@example.com', false); 56 $tests[] = array('-- test --@example.com', false); // No spaces allowed in local part 57 $tests[] = array('[test]@example.com', false); // Square brackets only allowed within quotes 58 $tests[] = array('"test\test"@example.com', false); // Quotes cannot contain backslash 59 $tests[] = array('"test"test"@example.com', false); // Quotes cannot be nested 60 $tests[] = array('()[]\;:,<>@example.com', false); // Disallowed Characters 61 $tests[] = array('test@.', false); 62 $tests[] = array('test@example.', false); 63 $tests[] = array('test@.org', false); 64 $tests[] = array('12345678901234567890123456789012345678901234567890123456789012345@example.com', false); // 64 characters is maximum length for local part. This is 65. 65 $tests[] = array('test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com', false); // 255 characters is maximum length for domain. This is 256. 66 $tests[] = array('test@[123.123.123.123', false); 67 $tests[] = array('test@123.123.123.123]', false); 68 69 70 foreach($tests as $test){ 71 $info = 'Testing '.$test[0]; 72 73 if($test[1]){ 74 $this->assertTrue((bool) mail_isvalid($test[0]), $info); 75 }else{ 76 $this->assertFalse((bool) mail_isvalid($test[0]), $info); 77 } 78 } 79 } 80 81} 82//Setup VIM: ex: et ts=4 : 83