| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class CustomAttachmentMask extends \Webklex\PHPIMAP\Support\Masks\AttachmentMask { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public function token(): string { |
| 20 |
return implode('-', [$this->id, $this->getMessage()->getUid(), $this->name]); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function custom_save(): bool { |
| 28 |
$path = "foo".DIRECTORY_SEPARATOR."bar".DIRECTORY_SEPARATOR; |
| 29 |
$filename = $this->token(); |
| 30 |
|
| 31 |
return file_put_contents($path.$filename, $this->getContent()) !== false; |
| 32 |
} |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
$cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php'); |
| 37 |
|
| 38 |
|
| 39 |
$client = $cm->account('default'); |
| 40 |
$client->connect(); |
| 41 |
$client->setDefaultAttachmentMask(CustomAttachmentMask::class); |
| 42 |
|
| 43 |
|
| 44 |
$folder = $client->getFolder('INBOX'); |
| 45 |
|
| 46 |
|
| 47 |
$message = $folder->query()->limit(1)->get()->first(); |
| 48 |
|
| 49 |
|
| 50 |
$attachment = $message->getAttachments()->first(); |
| 51 |
|
| 52 |
|
| 53 |
$masked_attachment = $attachment->mask(); |
| 54 |
|
| 55 |
echo 'Token for uid ['.$masked_attachment->getMessage()->getUid().']: '.$masked_attachment->token(); |
| 56 |
|
| 57 |
$masked_attachment->custom_save(); |