Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 08ba517

Browse files
committed
Fix Imap & EML plugins - Warning php7 requires Mail_mimeDecode 1.5.6 - Fix #1282
1 parent cec749a commit 08ba517

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

core/src/plugins/access.imap/ImapAccessDriver.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,35 @@ public function performChecks()
7171
}
7272
}
7373

74+
/**
75+
* @param $st1
76+
* @param $st2
77+
* @return int
78+
*/
7479
public static function inverseSort($st1, $st2)
7580
{
7681
return strnatcasecmp($st2, $st1);
7782
}
7883

84+
/**
85+
* @param $st1
86+
* @param $st2
87+
* @return int
88+
*/
7989
public static function sortInboxFirst($st1, $st2)
8090
{
8191
if($st1 == "INBOX") return -1;
8292
if($st2 == "INBOX") return 1;
8393
return strcmp($st1, $st2);
8494
}
8595

96+
/**
97+
* @param ServerRequestInterface $request
98+
* @param ResponseInterface $response
99+
* @throws PydioException
100+
* @throws \Exception
101+
* @throws \Pydio\Access\Core\Exception\FileNotWriteableException
102+
*/
86103
public function switchAction(ServerRequestInterface &$request, ResponseInterface &$response)
87104
{
88105
if ($request->getAttribute("action") == "ls") {

core/src/plugins/access.imap/ImapAccessWrapper.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
namespace Pydio\Access\Driver\StreamProvider\Imap;
2222

23-
use EmlParser;
23+
use Pydio\Editor\EML\EmlParser;
2424
use Pydio\Access\Core\IAjxpWrapper;
2525
use Pydio\Access\Core\Model\AJXP_Node;
2626

@@ -133,7 +133,6 @@ public function stream_open($path, $mode, $options, &$opened_path)
133133
$attachmentId = array_pop($ar);
134134
$this->currentAttachmentData = array("realPath" => $mailPath, "attachmentId" => $attachmentId);
135135
// EXTRACT ATTACHMENT AND RETURN
136-
require_once AJXP_INSTALL_PATH."/plugins/editor.eml/class.EmlParser.php";
137136
$emlParser = new EmlParser("", "");
138137
$attachMeta = array();
139138
$this->data = $emlParser->getAttachmentBody(
@@ -212,7 +211,6 @@ public function stream_read($count)
212211
if (empty($this->data)) {
213212
Logger::debug(__CLASS__,__FUNCTION__,"Attachement", $this->currentAttachmentData);
214213
// EXTRACT ATTACHMENT AND RETURN
215-
require_once AJXP_INSTALL_PATH."/plugins/editor.eml/class.EmlParser.php";
216214
$emlParser = new EmlParser("", "");
217215
$attachMeta = array();
218216
$this->data = $emlParser->getAttachmentBody(
@@ -309,7 +307,6 @@ public function dir_opendir($path, $options)
309307
self::$currentCount = count($this->mailboxes);
310308
$this->pos = $this->dir - 1;
311309
} else if ($this->fragment == "attachments") {
312-
require_once AJXP_INSTALL_PATH.'/plugins/editor.eml/class.EmlParser.php';
313310
$parser = new EmlParser("", "");
314311
$ar = explode("#", $path);
315312
$path = array_shift($ar);// remove fragment

core/src/plugins/editor.eml/EmlParser.php

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Pydio\Access\Core\MetaStreamWrapper;
2424
use Pydio\Access\Core\Model\AJXP_Node;
2525
use Pydio\Access\Core\Model\UserSelection;
26+
use Pydio\Core\Http\Message\UserMessage;
2627
use Pydio\Core\Model\ContextInterface;
2728

2829
use Pydio\Core\Services\LocalCache;
@@ -78,7 +79,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
7879
$file = $node->getUrl();
7980
Controller::applyHook("node.read", array($node));
8081

81-
$wrapperClassName = MetaStreamWrapper::actualRepositoryWrapperClass($node);
82+
$wrapperIsImap = $this->wrapperIsImap($node);
8283

8384
$mess = LocaleService::getMessages();
8485
switch ($action) {
@@ -88,7 +89,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
8889
'decode_bodies' => false,
8990
'decode_headers' => 'UTF-8'
9091
);
91-
$decoder = $this->getStructureDecoder($file, ($wrapperClassName == "imapAccessWrapper"));
92+
$decoder = $this->getStructureDecoder($file, $wrapperIsImap);
9293
$xml = $decoder->getXML($decoder->decode($params));
9394
$doc = new \Pydio\Core\Http\Message\XMLDocMessage($xml);
9495
if (function_exists("imap_mime_header_decode")) {
@@ -122,8 +123,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
122123
'decode_bodies' => true,
123124
'decode_headers' => false
124125
);
125-
if ($wrapperClassName == "imapAccessWrapper") {
126-
$cache = LocalCache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
126+
if ($wrapperIsImap) {
127+
$cache = LocalCache::getItem("eml_remote", $file, null, array($this, "computeCacheId"));
127128
$content = $cache->getData();
128129
} else {
129130
$content = file_get_contents($file);
@@ -153,8 +154,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
153154
'decode_bodies' => true,
154155
'decode_headers' => false
155156
);
156-
if ($wrapperClassName == "imapAccessWrapper") {
157-
$cache = LocalCache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
157+
if ($wrapperIsImap) {
158+
$cache = LocalCache::getItem("eml_remote", $file, null, array($this, "computeCacheId"));
158159
$content = $cache->getData();
159160
} else {
160161
$content = file_get_contents($file);
@@ -183,8 +184,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
183184
'decode_bodies' => true,
184185
'decode_headers' => false
185186
);
186-
if ($wrapperClassName == "imapAccessWrapper") {
187-
$cache = LocalCache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
187+
if ($wrapperIsImap) {
188+
$cache = LocalCache::getItem("eml_remote", $file, null, array($this, "computeCacheId"));
188189
$content = $cache->getData();
189190
} else {
190191
$content = file_get_contents($file);
@@ -210,12 +211,12 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
210211
if ($fp !== false) {
211212
fwrite($fp, $part->body, strlen($part->body));
212213
fclose($fp);
213-
$x->addChunk(new \Pydio\Core\Http\Message\UserMessage(sprintf($mess["editor.eml.7"], $part->d_parameters["filename"], $destRep)));
214+
$x->addChunk(new UserMessage(sprintf($mess["editor.eml.7"], $part->d_parameters["filename"], $destRep)));
214215
} else {
215-
$x->addChunk(new \Pydio\Core\Http\Message\UserMessage($mess["editor.eml.8"], LOG_LEVEL_ERROR));
216+
$x->addChunk(new UserMessage($mess["editor.eml.8"], LOG_LEVEL_ERROR));
216217
}
217218
} else {
218-
$x->addChunk(new \Pydio\Core\Http\Message\UserMessage($mess["editor.eml.9"], LOG_LEVEL_ERROR));
219+
$x->addChunk(new UserMessage($mess["editor.eml.9"], LOG_LEVEL_ERROR));
219220
}
220221
break;
221222

@@ -233,13 +234,13 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
233234
if($isParent) return;
234235
$currentNode = $ajxpNode->getUrl();
235236
$metadata = $ajxpNode->metadata;
236-
$wrapperClassName = MetaStreamWrapper::actualRepositoryWrapperClass($ajxpNode);
237+
$wrapperIsImap = $this->wrapperIsImap($ajxpNode);
237238

238239
$noMail = true;
239-
if ($metadata["is_file"] && ($wrapperClassName == "imapAccessWrapper" || preg_match("/\.eml$/i",$currentNode))) {
240+
if ($metadata["is_file"] && ($wrapperIsImap || preg_match("/\.eml$/i",$currentNode))) {
240241
$noMail = false;
241242
}
242-
if ($wrapperClassName == "imapAccessWrapper" && !$metadata["is_file"]) {
243+
if ($wrapperIsImap && !$metadata["is_file"]) {
243244
$metadata["mimestring"] = "Mailbox";
244245
}
245246
$parsed = UrlUtils::mbParseUrl($currentNode);
@@ -250,8 +251,8 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
250251
if (EmlParser::$currentListingOnlyEmails === NULL) {
251252
EmlParser::$currentListingOnlyEmails = true;
252253
}
253-
if ($wrapperClassName == "imapAccessWrapper") {
254-
$cachedFile = LocalCache::getItem("eml_remote", $currentNode, null, array("EmlParser", "computeCacheId"));
254+
if ($wrapperIsImap) {
255+
$cachedFile = LocalCache::getItem("eml_remote", $currentNode, null, array($this, "computeCacheId"));
255256
$realFile = $cachedFile->getId();
256257
if (!is_file($realFile)) {
257258
$cachedFile->getData();// trigger loading!
@@ -264,13 +265,23 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
264265
$data["ajxp_mime"] = "eml";
265266
$data["mimestring"] = "Email";
266267
$metadata = array_merge($metadata, $data);
267-
if ($wrapperClassName == "imapAccessWrapper" && $metadata["eml_attachments"]!= "0" && (strpos($_SERVER["HTTP_USER_AGENT"], "ajaxplorer-ios") !== false)) {
268+
if ($wrapperIsImap && $metadata["eml_attachments"]!= "0" && (strpos($_SERVER["HTTP_USER_AGENT"], "ajaxplorer-ios") !== false)) {
268269
$metadata["is_file"] = false;
269270
$metadata["nodeName"] = basename($currentNode)."#attachments";
270271
}
271272
$ajxpNode->metadata = $metadata;
272273
}
273274

275+
/**
276+
* @param AJXP_Node $node
277+
* @return bool
278+
*/
279+
protected function wrapperIsImap($node){
280+
$refClassName = "Pydio\\Access\\Driver\\StreamProvider\\Imap\\ImapAccessWrapper";
281+
$wrapperClassName = MetaStreamWrapper::actualRepositoryWrapperClass($node);
282+
return $wrapperClassName === $refClassName;
283+
}
284+
274285
/**
275286
* @param $masterFile
276287
* @param $targetFile
@@ -328,15 +339,13 @@ public function mimeExtractorCallback($masterFile, $targetFile)
328339
public function lsPostProcess(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
329340
{
330341
if (!EmlParser::$currentListingOnlyEmails) {
331-
header('Content-Type: text/xml; charset=UTF-8');
332-
header('Cache-Control: no-cache');
333342
return $responseInterface;
334343
}
335344

336345
$config = '<columns template_name="eml.list">
337-
<column messageId="editor.eml.1" attributeName="ajxp_label" sortType="String"/>
346+
<column messageId="editor.eml.2" attributeName="ajxp_label" sortType="String"/>
347+
<column messageId="editor.eml.1" attributeName="eml_from" sortType="String"/>
338348
<column messageId="editor.eml.2" attributeName="eml_to" sortType="String"/>
339-
<column messageId="editor.eml.3" attributeName="eml_subject" sortType="String"/>
340349
<column messageId="editor.eml.4" attributeName="ajxp_modiftime" sortType="MyDate"/>
341350
<column messageId="2" attributeName="filesize" sortType="NumberKo"/>
342351
<column messageId="editor.eml.5" attributeName="eml_attachments" sortType="Number" modifier="EmlViewer.prototype.attachmentCellRenderer" fixedWidth="30"/>
@@ -363,7 +372,7 @@ public function lsPostProcess(\Psr\Http\Message\ServerRequestInterface $requestI
363372
}
364373
$index ++;
365374
} else {
366-
$text = $child->getAttribute("eml_from");
375+
$text = $child->getAttribute("eml_subject");
367376
}
368377
$child->setAttribute("text", $text);
369378
$child->setAttribute("ajxp_modiftime", $child->getAttribute("eml_time"));
@@ -377,7 +386,7 @@ public function lsPostProcess(\Psr\Http\Message\ServerRequestInterface $requestI
377386
$imported = $dom->importNode($insert->documentElement, true);
378387
$dom->documentElement->appendChild($imported);
379388
$responseInterface = new \Zend\Diactoros\Response();
380-
$responseInterface = $responseInterface->withHeader("ContentType", "text/xml");
389+
$responseInterface = $responseInterface->withHeader("Content-Type", "text/xml");
381390
$responseInterface = $responseInterface->withHeader("Cache-Control", "no-cache");
382391
$responseInterface->getBody()->write($dom->saveXML());
383392
return $responseInterface;
@@ -394,7 +403,7 @@ public function getStructureDecoder($file, $cacheRemoteContent = false)
394403
{
395404
require_once ("Mail/mimeDecode.php");
396405
if ($cacheRemoteContent) {
397-
$cache = LocalCache::getItem ( "eml_remote", $file , null, array("EmlParser", "computeCacheId"));
406+
$cache = LocalCache::getItem ( "eml_remote", $file , null, array($this, "computeCacheId"));
398407
$content = $cache->getData ();
399408
} else {
400409
$content = file_get_contents ( $file );
@@ -522,7 +531,7 @@ protected function _findAttachmentById($structure, $attachId)
522531
* @param $mailPath
523532
* @return string
524533
*/
525-
public static function computeCacheId($mailPath)
534+
public function computeCacheId($mailPath)
526535
{
527536
$header = file_get_contents($mailPath."#header");
528537
//$this->logDebug("Headers ", $header);

0 commit comments

Comments
 (0)