1 | <?php |
||
30 | class ImapMessageTest extends TestCase { |
||
31 | |||
32 | public function testNoFrom() { |
||
33 | $data = new Horde_Imap_Client_Data_Fetch(); |
||
34 | $m = new IMAPMessage(null, 'INBOX', 123, $data); |
||
35 | |||
36 | $this->assertNull($m->getFrom()); |
||
37 | $this->assertNull($m->getFromEmail()); |
||
38 | } |
||
39 | |||
40 | public function testGetReplyCcList() { |
||
41 | $data = new Horde_Imap_Client_Data_Fetch(); |
||
42 | $data->setEnvelope(array( |
||
43 | 'to' => '[email protected], [email protected], [email protected]', |
||
44 | 'cc' => '[email protected], [email protected], [email protected]' |
||
45 | )); |
||
46 | $message = new IMAPMessage(null, 'INBOX', 123, $data); |
||
47 | |||
48 | $cc = $message->getReplyCcList('[email protected]'); |
||
49 | $this->assertTrue(is_array($cc)); |
||
50 | $this->assertEquals(3, count($cc)); |
||
51 | $cc = array_map(function($item) { |
||
52 | return $item['email']; |
||
53 | }, $cc); |
||
54 | |||
55 | $this->assertContains('[email protected]', $cc); |
||
56 | $this->assertContains('[email protected]', $cc); |
||
57 | $this->assertContains('[email protected]', $cc); |
||
58 | } |
||
59 | |||
60 | public function testIconvHtmlMessage() { |
||
61 | $conn = $this->getMockBuilder('Horde_Imap_Client_Socket') |
||
62 | ->disableOriginalConstructor() |
||
63 | ->setMethods(['fetch']) |
||
64 | ->getMock(); |
||
65 | |||
66 | $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') |
||
67 | ->disableOriginalConstructor() |
||
68 | ->getMock(); |
||
69 | $request = $this->getMockBuilder('\OCP\IRequest') |
||
70 | ->disableOriginalConstructor() |
||
71 | ->getMock(); |
||
72 | |||
73 | //linkToRoute 'mail.proxy.proxy' |
||
74 | $urlGenerator->expects($this->any()) |
||
75 | ->method('linkToRoute') |
||
76 | ->will($this->returnCallback(function ($url) { |
||
77 | return "https://docs.example.com/server/go.php?to=$url"; |
||
78 | })); |
||
79 | $htmlService = new \OCA\Mail\Service\Html($urlGenerator, $request); |
||
80 | |||
81 | // mock first fetch |
||
82 | $firstFetch = new Horde_Imap_Client_Data_Fetch(); |
||
83 | $firstPart = Horde_Mime_Part::parseMessage(file_get_contents(__DIR__ . '/../data/mail-message-123.txt'), ['level' => 1]); |
||
84 | $firstFetch->setStructure($firstPart); |
||
85 | $firstFetch->setBodyPart(1, $firstPart->getPart(1)->getContents()); |
||
86 | $firstFetch->setBodyPart(2, $firstPart->getPart(2)->getContents()); |
||
87 | $firstResult = new Horde_Imap_Client_Fetch_Results(); |
||
88 | $firstResult[123] = $firstFetch; |
||
89 | $conn->expects($this->any()) |
||
90 | ->method('fetch') |
||
91 | ->willReturn($firstResult); |
||
92 | |||
93 | |||
94 | $message = new IMAPMessage($conn, 'INBOX', 123, null, true, $htmlService); |
||
95 | $htmlBody = $message->getHtmlBody(0, 0, 123, function() {return null;}); |
||
96 | $this->assertTrue(strlen($htmlBody) > 1000); |
||
97 | |||
98 | $plainTextBody = $message->getPlainBody(); |
||
99 | $this->assertTrue(strlen($plainTextBody) > 1000); |
||
100 | } |
||
101 | } |
||
102 | |||
103 |