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:
johnnyq
2024-06-12 15:39:52 -04:00
parent d64a7ce31e
commit 779527cf6a
218 changed files with 14781 additions and 2722 deletions

View 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();

View File

@@ -0,0 +1,51 @@
<?php
/*
* File: custom_message_mask.php
* Category: Example
* Author: M.Goldenbaum
* Created: 14.03.19 18:47
* Updated: -
*
* Description:
* -
*/
class CustomMessageMask extends \Webklex\PHPIMAP\Support\Masks\MessageMask {
/**
* New custom method which can be called through a mask
* @return string
*/
public function token(): string {
return implode('-', [$this->message_id, $this->uid, $this->message_no]);
}
/**
* Get number of message attachments
* @return integer
*/
public function getAttachmentCount(): int {
return $this->getAttachments()->count();
}
}
$cm = new \Webklex\PHPIMAP\ClientManager('path/to/config/imap.php');
/** @var \Webklex\PHPIMAP\Client $client */
$client = $cm->account('default');
$client->connect();
/** @var \Webklex\PHPIMAP\Folder $folder */
$folder = $client->getFolder('INBOX');
/** @var \Webklex\PHPIMAP\Message $message */
$message = $folder->query()->limit(1)->get()->first();
/** @var CustomMessageMask $masked_message */
$masked_message = $message->mask(CustomMessageMask::class);
echo 'Token for uid [' . $masked_message->uid . ']: ' . $masked_message->token() . ' @atms:' . $masked_message->getAttachmentCount();
$masked_message->setFlag('seen');

View File

@@ -0,0 +1,42 @@
<?php
/*
* File: folder_structure.blade.php
* Category: View
* Author: M.Goldenbaum
* Created: 15.09.18 19:53
* Updated: -
*
* Description:
* -
*/
/**
* @var \Webklex\PHPIMAP\Support\FolderCollection $paginator
* @var \Webklex\PHPIMAP\Folder $folder
*/
?>
<table>
<thead>
<tr>
<th>Folder</th>
<th>Unread messages</th>
</tr>
</thead>
<tbody>
<?php if($paginator->count() > 0): ?>
<?php foreach($paginator as $folder): ?>
<tr>
<td><?php echo $folder->name; ?></td>
<td><?php echo $folder->search()->unseen()->setFetchBody(false)->count(); ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4">No folders found</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php echo $paginator->links(); ?>

View File

@@ -0,0 +1,46 @@
<?php
/*
* File: message_table.blade.php
* Category: View
* Author: M.Goldenbaum
* Created: 15.09.18 19:53
* Updated: -
*
* Description:
* -
*/
/**
* @var \Webklex\PHPIMAP\Support\FolderCollection $paginator
* @var \Webklex\PHPIMAP\Message $message
*/
?>
<table>
<thead>
<tr>
<th>UID</th>
<th>Subject</th>
<th>From</th>
<th>Attachments</th>
</tr>
</thead>
<tbody>
<?php if($paginator->count() > 0): ?>
<?php foreach($paginator as $message): ?>
<tr>
<td><?php echo $message->getUid(); ?></td>
<td><?php echo $message->getSubject(); ?></td>
<td><?php echo $message->getFrom()[0]->mail; ?></td>
<td><?php echo $message->getAttachments()->count() > 0 ? 'yes' : 'no'; ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4">No messages found</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<?php echo $paginator->links(); ?>