1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\VObject\Parser; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse 6*a1a3b679SAndreas Boehler Sabre\VObject\Reader; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerclass QuotedPrintableTest extends \PHPUnit_Framework_TestCase { 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehler function testReadQuotedPrintableSimple() { 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aach=65n\r\nEND:VCARD"; 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler $result = Reader::read($data); 15*a1a3b679SAndreas Boehler 16*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Component', $result); 17*a1a3b679SAndreas Boehler $this->assertEquals('VCARD', $result->name); 18*a1a3b679SAndreas Boehler $this->assertEquals(1, count($result->children())); 19*a1a3b679SAndreas Boehler $this->assertEquals("Aachen", $this->getPropertyValue($result->label)); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler } 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler function testReadQuotedPrintableNewlineSoft() { 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aa=\r\n ch=\r\n en\r\nEND:VCARD"; 26*a1a3b679SAndreas Boehler $result = Reader::read($data); 27*a1a3b679SAndreas Boehler 28*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Component', $result); 29*a1a3b679SAndreas Boehler $this->assertEquals('VCARD', $result->name); 30*a1a3b679SAndreas Boehler $this->assertEquals(1, count($result->children())); 31*a1a3b679SAndreas Boehler $this->assertEquals("Aachen", $this->getPropertyValue($result->label)); 32*a1a3b679SAndreas Boehler 33*a1a3b679SAndreas Boehler } 34*a1a3b679SAndreas Boehler 35*a1a3b679SAndreas Boehler function testReadQuotedPrintableNewlineHard() { 36*a1a3b679SAndreas Boehler 37*a1a3b679SAndreas Boehler $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\n Germany\r\nEND:VCARD"; 38*a1a3b679SAndreas Boehler $result = Reader::read($data); 39*a1a3b679SAndreas Boehler 40*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Component', $result); 41*a1a3b679SAndreas Boehler $this->assertEquals('VCARD', $result->name); 42*a1a3b679SAndreas Boehler $this->assertEquals(1, count($result->children())); 43*a1a3b679SAndreas Boehler $this->assertEquals("Aachen\r\nGermany", $this->getPropertyValue($result->label)); 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler 46*a1a3b679SAndreas Boehler } 47*a1a3b679SAndreas Boehler 48*a1a3b679SAndreas Boehler function testReadQuotedPrintableCompatibilityMS() { 49*a1a3b679SAndreas Boehler 50*a1a3b679SAndreas Boehler $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\nDeutschland:okay\r\nEND:VCARD"; 51*a1a3b679SAndreas Boehler $result = Reader::read($data, Reader::OPTION_FORGIVING); 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler $this->assertInstanceOf('Sabre\\VObject\\Component', $result); 54*a1a3b679SAndreas Boehler $this->assertEquals('VCARD', $result->name); 55*a1a3b679SAndreas Boehler $this->assertEquals(1, count($result->children())); 56*a1a3b679SAndreas Boehler $this->assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->label)); 57*a1a3b679SAndreas Boehler 58*a1a3b679SAndreas Boehler } 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler function testReadQuotesPrintableCompoundValues() { 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler $data = <<<VCF 63*a1a3b679SAndreas BoehlerBEGIN:VCARD 64*a1a3b679SAndreas BoehlerVERSION:2.1 65*a1a3b679SAndreas BoehlerN:Doe;John;;; 66*a1a3b679SAndreas BoehlerFN:John Doe 67*a1a3b679SAndreas BoehlerADR;WORK;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;M=C3=BCnster = 68*a1a3b679SAndreas BoehlerStr. 1;M=C3=BCnster;;48143;Deutschland 69*a1a3b679SAndreas BoehlerEND:VCARD 70*a1a3b679SAndreas BoehlerVCF; 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler $result = Reader::read($data, Reader::OPTION_FORGIVING); 73*a1a3b679SAndreas Boehler $this->assertEquals(array( 74*a1a3b679SAndreas Boehler '','','Münster Str. 1','Münster','','48143','Deutschland' 75*a1a3b679SAndreas Boehler ), $result->ADR->getParts()); 76*a1a3b679SAndreas Boehler 77*a1a3b679SAndreas Boehler 78*a1a3b679SAndreas Boehler } 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler private function getPropertyValue(\Sabre\VObject\Property $property) { 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler return (string)$property; 83*a1a3b679SAndreas Boehler 84*a1a3b679SAndreas Boehler /* 85*a1a3b679SAndreas Boehler $param = $property['encoding']; 86*a1a3b679SAndreas Boehler if ($param !== null) { 87*a1a3b679SAndreas Boehler $encoding = strtoupper((string)$param); 88*a1a3b679SAndreas Boehler if ($encoding === 'QUOTED-PRINTABLE') { 89*a1a3b679SAndreas Boehler $value = quoted_printable_decode($value); 90*a1a3b679SAndreas Boehler } else { 91*a1a3b679SAndreas Boehler throw new Exception(); 92*a1a3b679SAndreas Boehler } 93*a1a3b679SAndreas Boehler } 94*a1a3b679SAndreas Boehler 95*a1a3b679SAndreas Boehler $param = $property['charset']; 96*a1a3b679SAndreas Boehler if ($param !== null) { 97*a1a3b679SAndreas Boehler $charset = strtoupper((string)$param); 98*a1a3b679SAndreas Boehler if ($charset !== 'UTF-8') { 99*a1a3b679SAndreas Boehler $value = mb_convert_encoding($value, 'UTF-8', $charset); 100*a1a3b679SAndreas Boehler } 101*a1a3b679SAndreas Boehler } else { 102*a1a3b679SAndreas Boehler $value = StringUtil::convertToUTF8($value); 103*a1a3b679SAndreas Boehler } 104*a1a3b679SAndreas Boehler 105*a1a3b679SAndreas Boehler return $value; 106*a1a3b679SAndreas Boehler */ 107*a1a3b679SAndreas Boehler } 108*a1a3b679SAndreas Boehler} 109