1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* @author Thomas Müller <[email protected]> |
6
|
|
|
* |
7
|
|
|
* Mail |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
namespace OCA\Mail\Tests\Model; |
23
|
|
|
|
24
|
|
|
use Horde_Imap_Client_Data_Fetch; |
25
|
|
|
use Horde_Imap_Client_Fetch_Results; |
26
|
|
|
use Horde_Mime_Part; |
27
|
|
|
use OCA\Mail\Model\IMAPMessage; |
28
|
|
|
use Test\TestCase; |
29
|
|
|
|
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
|
|
|
|