mirror of
https://github.com/itflow-org/itflow
synced 2026-03-16 18:54:51 +00:00
Migrated away from PHP Mail Parser to the new WebKlex PHP IMAP Mail Parser this will open the way to support OAUTH2 for Mail servers such as Microsoft 365 and Google Workspaces
This commit is contained in:
57
plugins/php-imap/examples/custom_attachment_mask.php
Normal file
57
plugins/php-imap/examples/custom_attachment_mask.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* File: custom_message_mask.php
|
||||
* Category: Example
|
||||
* Author: M.Goldenbaum
|
||||
* Created: 14.03.19 18:47
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
class CustomAttachmentMask extends \Webklex\PHPIMAP\Support\Masks\AttachmentMask {
|
||||
|
||||
/**
|
||||
* New custom method which can be called through a mask
|
||||
* @return string
|
||||
*/
|
||||
public function token(): string {
|
||||
return implode('-', [$this->id, $this->getMessage()->getUid(), $this->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom attachment saving method
|
||||
* @return bool
|
||||
*/
|
||||
public function custom_save(): bool {
|
||||
$path = "foo".DIRECTORY_SEPARATOR."bar".DIRECTORY_SEPARATOR;
|
||||
$filename = $this->token();
|
||||
|
||||
return file_put_contents($path.$filename, $this->getContent()) !== false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php');
|
||||
|
||||
/** @var \Webklex\PHPIMAP\Client $client */
|
||||
$client = $cm->account('default');
|
||||
$client->connect();
|
||||
$client->setDefaultAttachmentMask(CustomAttachmentMask::class);
|
||||
|
||||
/** @var \Webklex\PHPIMAP\Folder $folder */
|
||||
$folder = $client->getFolder('INBOX');
|
||||
|
||||
/** @var \Webklex\PHPIMAP\Message $message */
|
||||
$message = $folder->query()->limit(1)->get()->first();
|
||||
|
||||
/** @var \Webklex\PHPIMAP\Attachment $attachment */
|
||||
$attachment = $message->getAttachments()->first();
|
||||
|
||||
/** @var CustomAttachmentMask $masked_attachment */
|
||||
$masked_attachment = $attachment->mask();
|
||||
|
||||
echo 'Token for uid ['.$masked_attachment->getMessage()->getUid().']: '.$masked_attachment->token();
|
||||
|
||||
$masked_attachment->custom_save();
|
||||
Reference in New Issue
Block a user