1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailTnefWebclientPlugin; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Module extends \Aurora\System\Module\AbstractModule |
22: | { |
23: | |
24: | |
25: | |
26: | public $oApiFileCache = null; |
27: | |
28: | public function init() |
29: | { |
30: | $this->oApiFileCache = new \Aurora\System\Managers\Filecache(); |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | public static function getInstance() |
37: | { |
38: | return parent::getInstance(); |
39: | } |
40: | |
41: | |
42: | |
43: | |
44: | public static function Decorator() |
45: | { |
46: | return parent::Decorator(); |
47: | } |
48: | |
49: | |
50: | |
51: | |
52: | public function getModuleSettings() |
53: | { |
54: | return $this->oModuleSettings; |
55: | } |
56: | |
57: | public function ExpandFile($UserId, $Hash) |
58: | { |
59: | $mResult = array(); |
60: | |
61: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
62: | $aValues = \Aurora\System\Api::DecodeKeyValues($Hash); |
63: | $oMailDecorator = \Aurora\Modules\Mail\Module::Decorator(); |
64: | $aFiles = $oMailDecorator->SaveAttachmentsAsTempFiles($aValues['AccountID'], [$Hash]); |
65: | foreach ($aFiles as $sTempName => $sHash) { |
66: | if ($sHash === $Hash) { |
67: | $rResource = $this->oApiFileCache->getFile($sUUID, $sTempName); |
68: | $mResult = $this->expandTnefAttachment($sUUID, $rResource); |
69: | } |
70: | } |
71: | |
72: | return $mResult; |
73: | } |
74: | |
75: | private function expandTnefAttachment($sUUID, $rResource) |
76: | { |
77: | $mResult = array(); |
78: | |
79: | $attachment = new \TNEFDecoder\TNEFAttachment(); |
80: | if ($rResource) { |
81: | $attachment->decodeTnef(\stream_get_contents($rResource)); |
82: | $files = $attachment->getFiles(); |
83: | |
84: | foreach ($files as $file) { |
85: | $sFileName = $file->getName(); |
86: | |
87: | $sFileNameEncoding = mb_detect_encoding($sFileName, array("UTF-8", "SJIS")); |
88: | if ($sFileNameEncoding != "UTF-8") { |
89: | $sFileName = mb_convert_encoding($sFileName, "UTF-8", $sFileNameEncoding); |
90: | } |
91: | |
92: | $sTempName = md5(\microtime(true) . rand(1000, 9999)); |
93: | $rItemStream = fopen('php://memory', 'r+'); |
94: | fwrite($rItemStream, $file->getContent()); |
95: | rewind($rItemStream); |
96: | |
97: | if ($this->oApiFileCache->putFile($sUUID, $sTempName, $rItemStream, '', self::GetName())) { |
98: | $sFileName = str_replace("\0", '', $sFileName); |
99: | $mResult[] = \Aurora\System\Utils::GetClientFileResponse( |
100: | self::GetName(), |
101: | \Aurora\System\Api::getAuthenticatedUserId(), |
102: | $sFileName, |
103: | $sTempName, |
104: | strlen($file->getSize()) |
105: | ); |
106: | } |
107: | } |
108: | } |
109: | |
110: | return $mResult; |
111: | } |
112: | } |
113: | |