Reintroduce Webklex IMAP for ticket processing as PHP-IMAP is no longer being developed. This is optional for now and considered beta can be found in cron/ticket_email_parser.php

This commit is contained in:
johnnyq
2025-09-10 14:27:46 -04:00
parent 981fb9585d
commit ce7d84aa2f
2035 changed files with 174115 additions and 0 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(); ?>