Webklex /
php-imap
| 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]); |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
The property
id does not exist on CustomAttachmentMask. Since you implemented __get, consider adding a @property annotation.
Loading history...
The method
getMessage() does not exist on CustomAttachmentMask. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 21 | } |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Custom attachment saving method |
||||
| 25 | * @return bool |
||||
| 26 | */ |
||||
| 27 | public function custom_save() { |
||||
| 28 | $path = "foo".DIRECTORY_SEPARATOR."bar".DIRECTORY_SEPARATOR; |
||||
| 29 | $filename = $this->token(); |
||||
| 30 | |||||
| 31 | return file_put_contents($path.$filename, $this->getContent()) !== false; |
||||
|
0 ignored issues
–
show
The method
getContent() does not exist on CustomAttachmentMask. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 32 | } |
||||
| 33 | |||||
| 34 | } |
||||
| 35 | |||||
| 36 | /** @var \Webklex\PHPIMAP\Client $client */ |
||||
| 37 | $cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php'); |
||||
| 38 | $client = $cm->account('default'); |
||||
| 39 | $client->connect(); |
||||
| 40 | $client->setDefaultAttachmentMask(CustomAttachmentMask::class); |
||||
| 41 | |||||
| 42 | /** @var \Webklex\PHPIMAP\Folder $folder */ |
||||
| 43 | $folder = $client->getFolder('INBOX'); |
||||
| 44 | |||||
| 45 | /** @var \Webklex\PHPIMAP\Message $message */ |
||||
| 46 | $message = $folder->query()->limit(1)->get()->first(); |
||||
| 47 | |||||
| 48 | /** @var \Webklex\PHPIMAP\Attachment $attachment */ |
||||
| 49 | $attachment = $message->getAttachments()->first(); |
||||
| 50 | |||||
| 51 | /** @var CustomAttachmentMask $masked_attachment */ |
||||
| 52 | $masked_attachment = $attachment->mask(); |
||||
| 53 | |||||
| 54 | echo 'Token for uid ['.$masked_attachment->getMessage()->getUid().']: '.$masked_attachment->token(); |
||||
| 55 | |||||
| 56 | $masked_attachment->custom_save(); |