|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Javanile\Imap2\Tests; |
| 4 | + |
| 5 | +use Javanile\Imap2\Connection; |
| 6 | +use Javanile\Imap2\Functions; |
| 7 | +use PHPUnit\Framework\Error\Warning; |
| 8 | + |
| 9 | +class BodyStructureTest extends ImapTestCase |
| 10 | +{ |
| 11 | + public function testFetchStructure() |
| 12 | + { |
| 13 | + $imap1 = imap_open($this->mailbox, $this->username, $this->password); |
| 14 | + $imap2 = imap2_open($this->mailbox, $this->username, $this->accessToken, OP_XOAUTH2); |
| 15 | + |
| 16 | + /* |
| 17 | + $messages = imap_fetch_overview($imap1, '1:5'); |
| 18 | + $this->assertCount(5, $messages); |
| 19 | +
|
| 20 | + $inputs = [ |
| 21 | + 0 => [], |
| 22 | + FT_UID => [], |
| 23 | + ]; |
| 24 | +
|
| 25 | + foreach ($messages as $message) { |
| 26 | + $inputs[0][] = $message->msgno; |
| 27 | + $inputs[FT_UID][] = $message->uid; |
| 28 | + } |
| 29 | +
|
| 30 | + foreach ($inputs as $flags => $messageNums) { |
| 31 | + foreach ($messageNums as $messageNum) { |
| 32 | + #var_dump($messageNum, $flags); |
| 33 | + $structure1 = imap_fetchstructure($imap1, $messageNum, $flags); |
| 34 | + $structure2 = imap2_fetchstructure($imap2, $messageNum, $flags); |
| 35 | + #file_put_contents('t1.json', json_encode($structure1, JSON_PRETTY_PRINT)); |
| 36 | + #file_put_contents('t2.json', json_encode($structure2, JSON_PRETTY_PRINT)); |
| 37 | + $this->assertEquals($structure1, $structure2); |
| 38 | + } |
| 39 | + } |
| 40 | + */ |
| 41 | + $emlFiles = [ |
| 42 | + #'embedded_email.eml', |
| 43 | + #'embedded_email_without_content_disposition.eml', |
| 44 | + #'four_nested_emails.eml' |
| 45 | + #'multiple_nested_attachments.eml' |
| 46 | + 'email_with_image.eml' |
| 47 | + ]; |
| 48 | + foreach ($emlFiles as $file) { |
| 49 | + $message = file_get_contents('tests/fixtures/'.$file); |
| 50 | + $mailbox1 = uniqid('test_'); |
| 51 | + $mailbox2 = uniqid('test_'); |
| 52 | + imap_createmailbox($imap1, $this->mailbox.$mailbox1); |
| 53 | + imap2_createmailbox($imap2, $this->mailbox.$mailbox2); |
| 54 | + imap_append($imap1, $this->mailbox.$mailbox1, $message); |
| 55 | + imap2_append($imap2, $this->mailbox.$mailbox2, $message); |
| 56 | + imap_reopen($imap1, $this->mailbox.$mailbox1); |
| 57 | + imap2_reopen($imap2, $this->mailbox.$mailbox2); |
| 58 | + $structure2 = imap2_fetchstructure($imap2, 1); |
| 59 | + $structure1 = imap_fetchstructure($imap1, 1); |
| 60 | + $headerInfo2 = imap2_headerinfo($imap2, 1); |
| 61 | + $headerInfo1 = imap_headerinfo($imap1, 1); |
| 62 | + #file_put_contents('t1.json', json_encode($structure1, JSON_PRETTY_PRINT)); |
| 63 | + #file_put_contents('t2.json', json_encode($structure2, JSON_PRETTY_PRINT)); |
| 64 | + #die(); |
| 65 | + $this->assertEquals($structure1, $structure2); |
| 66 | + $headerInfo1->Unseen = $headerInfo2->Unseen; |
| 67 | + $this->assertEquals($headerInfo1, $headerInfo2); |
| 68 | + } |
| 69 | + |
| 70 | + imap_close($imap1); |
| 71 | + imap2_close($imap2); |
| 72 | + } |
| 73 | +} |
0 commit comments