1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailTnefWebclientPlugin; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | class Module extends \Aurora\System\Module\AbstractModule |
20: | { |
21: | |
22: | |
23: | |
24: | public $oApiFileCache = null; |
25: | |
26: | public function init() |
27: | { |
28: | $this->oApiFileCache = new \Aurora\System\Managers\Filecache(); |
29: | } |
30: | |
31: | public function ExpandFile($UserId, $Hash) |
32: | { |
33: | $mResult = array(); |
34: | |
35: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
36: | $aValues = \Aurora\System\Api::DecodeKeyValues($Hash); |
37: | $oMailDecorator = \Aurora\Modules\Mail\Module::Decorator(); |
38: | $aFiles = $oMailDecorator->SaveAttachmentsAsTempFiles($aValues['AccountID'], [$Hash]); |
39: | foreach ($aFiles as $sTempName => $sHash) { |
40: | if ($sHash === $Hash) { |
41: | $rResource = $this->oApiFileCache->getFile($sUUID, $sTempName); |
42: | $mResult = $this->expandTnefAttachment($sUUID, $rResource); |
43: | } |
44: | } |
45: | |
46: | return $mResult; |
47: | } |
48: | |
49: | private function expandTnefAttachment($sUUID, $rResource) |
50: | { |
51: | $mResult = array(); |
52: | |
53: | $oTNEF = new Classes\TNEF(); |
54: | if ($oTNEF && $rResource) { |
55: | $aData = $oTNEF->Decode(\stream_get_contents($rResource)); |
56: | if (is_array($aData)) { |
57: | foreach ($aData as $aItem) { |
58: | if (is_array($aItem) && isset($aItem['name'], $aItem['stream'])) { |
59: | $sFileName = \MailSo\Base\Utils::Utf8Clear(basename($aItem['name'])); |
60: | |
61: | $sTempName = md5(\microtime(true).rand(1000, 9999)); |
62: | $rItemStream = fopen('php://memory', 'r+'); |
63: | fwrite($rItemStream, $aItem['stream']); |
64: | rewind($rItemStream); |
65: | if ($this->oApiFileCache->putFile($sUUID, $sTempName, $rItemStream, '', self::GetName())) { |
66: | $sFileName = str_replace("\0", '', $sFileName); |
67: | $mResult[] = \Aurora\System\Utils::GetClientFileResponse( |
68: | self::GetName(), |
69: | \Aurora\System\Api::getAuthenticatedUserId(), |
70: | $sFileName, |
71: | $sTempName, |
72: | strlen($aItem['stream']) |
73: | ); |
74: | } |
75: | } |
76: | } |
77: | } |
78: | } |
79: | |
80: | return $mResult; |
81: | } |
82: | } |
83: | |