Skip to content

Commit 739b1a0

Browse files
committedSep 15, 2022
Merge remote-tracking branch 'origin/test'
2 parents addf5a1 + 18b4f10 commit 739b1a0

11 files changed

+170
-9
lines changed
 

Diff for: ‎CHANGELOG.md

+17-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
9+
10+
## [v0.1.9](https://github.com/javanile/php-imap2/compare/0.1.9...0.1.8) - 2022-09-15
11+
12+
### Changed
13+
14+
- Updated imap2_last_error message ([#3](https://github.com/javanile/php-imap2/issues/3))
15+
16+
### Fixed
17+
18+
- Fixed imap2_fetchmime unexpected behaviour ([#10](https://github.com/javanile/php-imap2/issues/10))
19+
20+
21+
822
## [v0.1.8](https://github.com/javanile/php-imap2/compare/0.1.8...0.1.7) - 2022-09-05
923

1024
### Changed
@@ -20,9 +34,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2034
## [v0.1.7](https://github.com/javanile/php-imap2/compare/0.1.7...0.1.0) - 2022-01-01
2135

2236
### Changed
23-
24-
- Documentation amends ([#3](https://github.com/javanile/php-imap2/issues/3))
37+
38+
- Documentation amends ([#3](https://github.com/javanile/php-imap2/issues/3))
2539

2640
### Fixed
2741

28-
- Documentation amends ([#3](https://github.com/javanile/php-imap2/issues/3))
42+
- Generic imap2_open bugs ([#3](https://github.com/javanile/php-imap2/issues/3))

Diff for: ‎Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ test-num-msg:
107107
test-reopen:
108108
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testReopen
109109

110+
test-fetch-mime:
111+
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testFetchMime
112+
110113
test-ping:
111114
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testPing
112115

@@ -116,6 +119,9 @@ test-get-mailboxes:
116119
test-delete-mailbox:
117120
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testDeleteMailbox
118121

122+
test-body-structure:
123+
@docker-compose run --rm phpunit tests --filter BodyStructureTest::testFetchStructure
124+
119125
test-timeout:
120126
@docker-compose run --rm phpunit tests --filter XoauthTest::testTimeout
121127

Diff for: ‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Scope: https://mail.google.com/
3838

3939
## Sandbox
4040

41-
- Demo #1 - <https://phpsandbox.io/e/x/zwauf>
41+
- Gmail Demo - <https://phpsandbox.io/e/x/zwauf?layout=EditorPreview&defaultPath=%2F&theme=dark&showExplorer=no&openedFiles=>
42+
- Outlook Demo - **COMING SOON**
4243

4344
## Other links
4445

Diff for: ‎bootstrap.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,11 @@ function imap_fetchmime($imap, $messageNum, $section, $flags = 0)
10301030
if (!function_exists('imap2_fetchmime')) {
10311031
function imap2_fetchmime($imap, $messageNum, $section, $flags = 0)
10321032
{
1033-
return Message::fetchBody($imap, $messageNum, $section, $flags);
1033+
if (IMAP2_RETROFIT_MODE && is_resource($imap) && get_resource_type($imap) == 'imap') {
1034+
return imap_fetchmime($imap, $messageNum, $section, $flags);
1035+
}
1036+
1037+
return Message::fetchMime($imap, $messageNum, $section, $flags);
10341038
}
10351039
}
10361040

Diff for: ‎docs/google-playground.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<head>
2+
<meta http-equiv="refresh" content="5; URL=https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=https%3A%2F%2Fmail.google.com%2F&access_type=offline&flowName=GeneralOAuthFlow" />
3+
</head>
4+
<body>
5+
<p>If you are not redirected in five seconds, <a href="https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=https%3A%2F%2Fmail.google.com%2F&access_type=offline&flowName=GeneralOAuthFlow">click here</a>.</p>
6+
</body>

Diff for: ‎src/BodyStructure.php

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ protected static function extractPart($item)
9090
$parameters = [];
9191

9292
if (!is_array($item[2])) {
93-
var_dump($item);
94-
9593
return $parameters;
9694
}
9795

Diff for: ‎src/HeaderInfo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HeaderInfo
1616

1717
public static function fromMessage($message, $defaultHost)
1818
{
19-
#file_put_contents('t3.json', json_encode($message, JSON_PRETTY_PRINT));
19+
file_put_contents('t3.json', json_encode($message, JSON_PRETTY_PRINT));
2020

2121
$to = Functions::writeAddressFromEnvelope($message->envelope[5]);
2222
$cc = Functions::writeAddressFromEnvelope($message->envelope[6]);

Diff for: ‎src/Message.php

+31
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ public static function fetchBody($imap, $messageNum, $section, $flags = 0)
145145
return $messages[$messageNum]->body;
146146
}
147147

148+
public static function fetchMime($imap, $messageNum, $section, $flags = 0)
149+
{
150+
if (!is_a($imap, Connection::class)) {
151+
return Errors::invalidImapConnection(debug_backtrace(), 1, false);
152+
}
153+
154+
if ($messageNum <= 0) {
155+
trigger_error(Errors::badMessageNumber(debug_backtrace(), 1), E_USER_WARNING);
156+
157+
return false;
158+
}
159+
160+
$client = $imap->getClient();
161+
#$client->setDebug(true);
162+
163+
$isUid = boolval($flags & FT_UID);
164+
165+
$sectionKey = $section.'.MIME';
166+
$messages = $client->fetch($imap->getMailboxName(), $messageNum, $isUid, ['BODY['.$sectionKey.']']);
167+
168+
if (empty($messages)) {
169+
return "";
170+
}
171+
172+
if ($section && isset($messages[$messageNum]->bodypart[$sectionKey])) {
173+
return $messages[$messageNum]->bodypart[$sectionKey];
174+
}
175+
176+
return $messages[$messageNum]->body;
177+
}
178+
148179
public static function saveBody($imap, $file, $messageNum, $section = "", $flags = 0)
149180
{
150181
if (is_a($imap, Connection::class)) {

Diff for: ‎src/Roundcube/ImapClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4124,7 +4124,7 @@ public static function escape($string, $force_quotes=false)
41244124
*/
41254125
public function setDebug($debug, $handler = null)
41264126
{
4127-
$this->debug = $debug;
4127+
$this->debug = $debug;
41284128
$this->debug_handler = $handler;
41294129
}
41304130

Diff for: ‎tests/BodyStructureTest.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

Diff for: ‎tests/CompatibilityTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,34 @@ public function testNumMsg()
647647
imap2_close($imap2);
648648
}
649649

650+
public function testFetchMime()
651+
{
652+
$imap1 = imap_open($this->mailbox, $this->username, $this->password);
653+
$imap2 = imap2_open($this->mailbox, $this->username, $this->accessToken, OP_XOAUTH2);
654+
655+
$messageNums = [1];
656+
$sections = [null, '', 0, 1, '1', 9999];
657+
658+
$flags = [
659+
0,
660+
#FT_UID,
661+
#FT_PEEK,
662+
FT_INTERNAL,
663+
];
664+
foreach ($flags as $flag) {
665+
foreach ($sections as $section) {
666+
foreach ($messageNums as $messageNum) {
667+
$fetchMime1 = imap_fetchmime($imap1, $messageNum, $section, $flag);
668+
$fetchMime2 = imap2_fetchmime($imap2, $messageNum, $section, $flag);
669+
$this->assertEquals($fetchMime1, $fetchMime2);
670+
}
671+
}
672+
}
673+
674+
imap_close($imap1);
675+
imap2_close($imap2);
676+
}
677+
650678
public function testReopen()
651679
{
652680
$imap1 = imap_open($this->mailbox, $this->username, $this->password);

0 commit comments

Comments
 (0)
Please sign in to comment.