1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* File: custom_message_mask.php |
4
|
|
|
* Category: Example |
5
|
|
|
* Author: M.Goldenbaum |
6
|
|
|
* Created: 14.03.19 18:47 |
7
|
|
|
* Updated: - |
8
|
|
|
* |
9
|
|
|
* Description: |
10
|
|
|
* - |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
class CustomAttachmentMask extends \Webklex\PHPIMAP\Support\Masks\AttachmentMask { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* New custom method which can be called through a mask |
17
|
|
|
* @return string |
18
|
|
|
*/ |
19
|
|
|
public function token(){ |
20
|
|
|
return implode('-', [$this->id, $this->getMessage()->getUid(), $this->name]); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Custom attachment saving method |
25
|
|
|
* @return bool |
26
|
|
|
*/ |
27
|
|
|
public function custom_save() { |
28
|
|
|
$path = storage_path('foo'); |
29
|
|
|
$filename = $this->token(); |
30
|
|
|
|
31
|
|
|
$path = substr($path, -1) == DIRECTORY_SEPARATOR ? $path : $path.DIRECTORY_SEPARATOR; |
32
|
|
|
|
33
|
|
|
return \Illuminate\Support\Facades\File::put($path.$filename, $this->getContent()) !== false; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** @var \Webklex\PHPIMAP\Client $oClient */ |
39
|
|
|
$oClient = \Webklex\IMAP\Facades\Client::account('default'); |
|
|
|
|
40
|
|
|
$oClient->connect(); |
41
|
|
|
$oClient->setDefaultAttachmentMask(CustomAttachmentMask::class); |
42
|
|
|
|
43
|
|
|
/** @var \Webklex\PHPIMAP\Folder $folder */ |
44
|
|
|
$folder = $oClient->getFolder('INBOX'); |
45
|
|
|
|
46
|
|
|
/** @var \Webklex\PHPIMAP\Message $message */ |
47
|
|
|
$message = $folder->query()->limit(1)->get()->first(); |
48
|
|
|
|
49
|
|
|
/** @var \Webklex\PHPIMAP\Attachment $attachment */ |
50
|
|
|
$attachment = $message->getAttachments()->first(); |
51
|
|
|
|
52
|
|
|
/** @var CustomAttachmentMask $masked_attachment */ |
53
|
|
|
$masked_attachment = $attachment->mask(); |
54
|
|
|
|
55
|
|
|
echo 'Token for uid ['.$masked_attachment->getMessage()->getUid().']: '.$masked_attachment->token(); |
56
|
|
|
|
57
|
|
|
$masked_attachment->custom_save(); |