23
23
use Pydio \Access \Core \MetaStreamWrapper ;
24
24
use Pydio \Access \Core \Model \AJXP_Node ;
25
25
use Pydio \Access \Core \Model \UserSelection ;
26
+ use Pydio \Core \Http \Message \UserMessage ;
26
27
use Pydio \Core \Model \ContextInterface ;
27
28
28
29
use Pydio \Core \Services \LocalCache ;
@@ -78,7 +79,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
78
79
$ file = $ node ->getUrl ();
79
80
Controller::applyHook ("node.read " , array ($ node ));
80
81
81
- $ wrapperClassName = MetaStreamWrapper:: actualRepositoryWrapperClass ($ node );
82
+ $ wrapperIsImap = $ this -> wrapperIsImap ($ node );
82
83
83
84
$ mess = LocaleService::getMessages ();
84
85
switch ($ action ) {
@@ -88,7 +89,7 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
88
89
'decode_bodies ' => false ,
89
90
'decode_headers ' => 'UTF-8 '
90
91
);
91
- $ decoder = $ this ->getStructureDecoder ($ file , ( $ wrapperClassName == " imapAccessWrapper " ) );
92
+ $ decoder = $ this ->getStructureDecoder ($ file , $ wrapperIsImap );
92
93
$ xml = $ decoder ->getXML ($ decoder ->decode ($ params ));
93
94
$ doc = new \Pydio \Core \Http \Message \XMLDocMessage ($ xml );
94
95
if (function_exists ("imap_mime_header_decode " )) {
@@ -122,8 +123,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
122
123
'decode_bodies ' => true ,
123
124
'decode_headers ' => false
124
125
);
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 " ));
127
128
$ content = $ cache ->getData ();
128
129
} else {
129
130
$ content = file_get_contents ($ file );
@@ -153,8 +154,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
153
154
'decode_bodies ' => true ,
154
155
'decode_headers ' => false
155
156
);
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 " ));
158
159
$ content = $ cache ->getData ();
159
160
} else {
160
161
$ content = file_get_contents ($ file );
@@ -183,8 +184,8 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
183
184
'decode_bodies ' => true ,
184
185
'decode_headers ' => false
185
186
);
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 " ));
188
189
$ content = $ cache ->getData ();
189
190
} else {
190
191
$ content = file_get_contents ($ file );
@@ -210,12 +211,12 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn
210
211
if ($ fp !== false ) {
211
212
fwrite ($ fp , $ part ->body , strlen ($ part ->body ));
212
213
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 )));
214
215
} 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 ));
216
217
}
217
218
} 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 ));
219
220
}
220
221
break ;
221
222
@@ -233,13 +234,13 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
233
234
if ($ isParent ) return ;
234
235
$ currentNode = $ ajxpNode ->getUrl ();
235
236
$ metadata = $ ajxpNode ->metadata ;
236
- $ wrapperClassName = MetaStreamWrapper:: actualRepositoryWrapperClass ($ ajxpNode );
237
+ $ wrapperIsImap = $ this -> wrapperIsImap ($ ajxpNode );
237
238
238
239
$ 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 ))) {
240
241
$ noMail = false ;
241
242
}
242
- if ($ wrapperClassName == " imapAccessWrapper " && !$ metadata ["is_file " ]) {
243
+ if ($ wrapperIsImap && !$ metadata ["is_file " ]) {
243
244
$ metadata ["mimestring " ] = "Mailbox " ;
244
245
}
245
246
$ parsed = UrlUtils::mbParseUrl ($ currentNode );
@@ -250,8 +251,8 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
250
251
if (EmlParser::$ currentListingOnlyEmails === NULL ) {
251
252
EmlParser::$ currentListingOnlyEmails = true ;
252
253
}
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 " ));
255
256
$ realFile = $ cachedFile ->getId ();
256
257
if (!is_file ($ realFile )) {
257
258
$ cachedFile ->getData ();// trigger loading!
@@ -264,13 +265,23 @@ public function extractMimeHeaders(&$ajxpNode, $isParent = false)
264
265
$ data ["ajxp_mime " ] = "eml " ;
265
266
$ data ["mimestring " ] = "Email " ;
266
267
$ 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 )) {
268
269
$ metadata ["is_file " ] = false ;
269
270
$ metadata ["nodeName " ] = basename ($ currentNode )."#attachments " ;
270
271
}
271
272
$ ajxpNode ->metadata = $ metadata ;
272
273
}
273
274
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
+
274
285
/**
275
286
* @param $masterFile
276
287
* @param $targetFile
@@ -328,15 +339,13 @@ public function mimeExtractorCallback($masterFile, $targetFile)
328
339
public function lsPostProcess (\Psr \Http \Message \ServerRequestInterface $ requestInterface , \Psr \Http \Message \ResponseInterface &$ responseInterface )
329
340
{
330
341
if (!EmlParser::$ currentListingOnlyEmails ) {
331
- header ('Content-Type: text/xml; charset=UTF-8 ' );
332
- header ('Cache-Control: no-cache ' );
333
342
return $ responseInterface ;
334
343
}
335
344
336
345
$ 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"/>
338
348
<column messageId="editor.eml.2" attributeName="eml_to" sortType="String"/>
339
- <column messageId="editor.eml.3" attributeName="eml_subject" sortType="String"/>
340
349
<column messageId="editor.eml.4" attributeName="ajxp_modiftime" sortType="MyDate"/>
341
350
<column messageId="2" attributeName="filesize" sortType="NumberKo"/>
342
351
<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
363
372
}
364
373
$ index ++;
365
374
} else {
366
- $ text = $ child ->getAttribute ("eml_from " );
375
+ $ text = $ child ->getAttribute ("eml_subject " );
367
376
}
368
377
$ child ->setAttribute ("text " , $ text );
369
378
$ child ->setAttribute ("ajxp_modiftime " , $ child ->getAttribute ("eml_time " ));
@@ -377,7 +386,7 @@ public function lsPostProcess(\Psr\Http\Message\ServerRequestInterface $requestI
377
386
$ imported = $ dom ->importNode ($ insert ->documentElement , true );
378
387
$ dom ->documentElement ->appendChild ($ imported );
379
388
$ responseInterface = new \Zend \Diactoros \Response ();
380
- $ responseInterface = $ responseInterface ->withHeader ("ContentType " , "text/xml " );
389
+ $ responseInterface = $ responseInterface ->withHeader ("Content-Type " , "text/xml " );
381
390
$ responseInterface = $ responseInterface ->withHeader ("Cache-Control " , "no-cache " );
382
391
$ responseInterface ->getBody ()->write ($ dom ->saveXML ());
383
392
return $ responseInterface ;
@@ -394,7 +403,7 @@ public function getStructureDecoder($file, $cacheRemoteContent = false)
394
403
{
395
404
require_once ("Mail/mimeDecode.php " );
396
405
if ($ cacheRemoteContent ) {
397
- $ cache = LocalCache::getItem ( "eml_remote " , $ file , null , array (" EmlParser " , "computeCacheId " ));
406
+ $ cache = LocalCache::getItem ( "eml_remote " , $ file , null , array ($ this , "computeCacheId " ));
398
407
$ content = $ cache ->getData ();
399
408
} else {
400
409
$ content = file_get_contents ( $ file );
@@ -522,7 +531,7 @@ protected function _findAttachmentById($structure, $attachId)
522
531
* @param $mailPath
523
532
* @return string
524
533
*/
525
- public static function computeCacheId ($ mailPath )
534
+ public function computeCacheId ($ mailPath )
526
535
{
527
536
$ header = file_get_contents ($ mailPath ."#header " );
528
537
//$this->logDebug("Headers ", $header);
0 commit comments