mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-17 15:01:26 +01:00
Mail collection
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* File: AttachmentCollection.php
|
||||
* Category: Collection
|
||||
* Author: M. Goldenbaum
|
||||
* Created: 16.03.18 03:13
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support;
|
||||
|
||||
/**
|
||||
* Class AttachmentCollection
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support
|
||||
*/
|
||||
class AttachmentCollection extends PaginatedCollection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* File: FlagCollection.php
|
||||
* Category: Collection
|
||||
* Author: M. Goldenbaum
|
||||
* Created: 21.07.18 23:10
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support;
|
||||
|
||||
/**
|
||||
* Class FlagCollection
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support
|
||||
*/
|
||||
class FlagCollection extends PaginatedCollection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* File: FolderCollection.php
|
||||
* Category: Collection
|
||||
* Author: M. Goldenbaum
|
||||
* Created: 18.03.18 02:21
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support;
|
||||
|
||||
/**
|
||||
* Class FolderCollection
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support
|
||||
*/
|
||||
class FolderCollection extends PaginatedCollection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* File: AttachmentMask.php
|
||||
* Category: Mask
|
||||
* Author: M.Goldenbaum
|
||||
* Created: 14.03.19 20:49
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support\Masks;
|
||||
|
||||
use Webklex\PHPIMAP\Attachment;
|
||||
|
||||
/**
|
||||
* Class AttachmentMask
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support\Masks
|
||||
*/
|
||||
class AttachmentMask extends Mask {
|
||||
|
||||
/** @var Attachment $parent */
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* Get the attachment content base64 encoded
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getContentBase64Encoded() {
|
||||
return base64_encode($this->parent->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an base64 image src string
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getImageSrc() {
|
||||
return 'data:'.$this->parent->content_type.';base64,'.$this->getContentBase64Encoded();
|
||||
}
|
||||
}
|
||||
137
htdocs/includes/webklex/php-imap/src/Support/Masks/Mask.php
Executable file
137
htdocs/includes/webklex/php-imap/src/Support/Masks/Mask.php
Executable file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* File: Mask.php
|
||||
* Category: Mask
|
||||
* Author: M.Goldenbaum
|
||||
* Created: 14.03.19 20:49
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support\Masks;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Webklex\PHPIMAP\Exceptions\MethodNotFoundException;
|
||||
|
||||
/**
|
||||
* Class Mask
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support\Masks
|
||||
*/
|
||||
class Mask {
|
||||
|
||||
/**
|
||||
* Available attributes
|
||||
*
|
||||
* @var array $attributes
|
||||
*/
|
||||
protected $attributes = [];
|
||||
|
||||
/**
|
||||
* Parent instance
|
||||
*
|
||||
* @var object $parent
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* Mask constructor.
|
||||
* @param $parent
|
||||
*/
|
||||
public function __construct($parent) {
|
||||
$this->parent = $parent;
|
||||
|
||||
if(method_exists($this->parent, 'getAttributes')){
|
||||
$this->attributes = array_merge($this->attributes, $this->parent->getAttributes());
|
||||
}
|
||||
|
||||
$this->boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot method made to be used by any custom mask
|
||||
*/
|
||||
protected function boot(){}
|
||||
|
||||
/**
|
||||
* Call dynamic attribute setter and getter methods and inherit the parent calls
|
||||
* @param string $method
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
* @throws MethodNotFoundException
|
||||
*/
|
||||
public function __call($method, $arguments) {
|
||||
if(strtolower(substr($method, 0, 3)) === 'get') {
|
||||
$name = Str::snake(substr($method, 3));
|
||||
|
||||
if(isset($this->attributes[$name])) {
|
||||
return $this->attributes[$name];
|
||||
}
|
||||
|
||||
}elseif (strtolower(substr($method, 0, 3)) === 'set') {
|
||||
$name = Str::snake(substr($method, 3));
|
||||
|
||||
if(isset($this->attributes[$name])) {
|
||||
$this->attributes[$name] = array_pop($arguments);
|
||||
|
||||
return $this->attributes[$name];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(method_exists($this->parent, $method) === true){
|
||||
return call_user_func_array([$this->parent, $method], $arguments);
|
||||
}
|
||||
|
||||
throw new MethodNotFoundException("Method ".self::class.'::'.$method.'() is not supported');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
$this->attributes[$name] = $value;
|
||||
|
||||
return $this->attributes[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __get($name) {
|
||||
if(isset($this->attributes[$name])) {
|
||||
return $this->attributes[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParent(){
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes(){
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*
|
||||
* File: MessageMask.php
|
||||
* Category: Mask
|
||||
* Author: M.Goldenbaum
|
||||
* Created: 14.03.19 20:49
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support\Masks;
|
||||
|
||||
use Webklex\PHPIMAP\Attachment;
|
||||
use Webklex\PHPIMAP\Message;
|
||||
|
||||
/**
|
||||
* Class MessageMask
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support\Masks
|
||||
*/
|
||||
class MessageMask extends Mask {
|
||||
|
||||
/** @var Message $parent */
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* Get the message html body
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getHtmlBody(){
|
||||
$bodies = $this->parent->getBodies();
|
||||
if (!isset($bodies['html'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(is_object($bodies['html']) && property_exists($bodies['html'], 'content')) {
|
||||
return $bodies['html']->content;
|
||||
}
|
||||
return $bodies['html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Message html body filtered by an optional callback
|
||||
* @param callable|bool $callback
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCustomHTMLBody($callback = false) {
|
||||
$body = $this->getHtmlBody();
|
||||
if($body === null) return null;
|
||||
|
||||
if ($callback !== false) {
|
||||
$aAttachment = $this->parent->getAttachments();
|
||||
$aAttachment->each(function($oAttachment) use(&$body, $callback) {
|
||||
/** @var Attachment $oAttachment */
|
||||
if(is_callable($callback)) {
|
||||
$body = $callback($body, $oAttachment);
|
||||
}elseif(is_string($callback)) {
|
||||
call_user_func($callback, [$body, $oAttachment]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Message html body with embedded base64 images
|
||||
* the resulting $body.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getHTMLBodyWithEmbeddedBase64Images() {
|
||||
return $this->getCustomHTMLBody(function($body, $oAttachment){
|
||||
/** @var Attachment $oAttachment */
|
||||
if ($oAttachment->id) {
|
||||
$body = str_replace('cid:'.$oAttachment->id, 'data:'.$oAttachment->getContentType().';base64, '.base64_encode($oAttachment->getContent()), $body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/*
|
||||
* File: MessageCollection.php
|
||||
* Category: Collection
|
||||
* Author: M. Goldenbaum
|
||||
* Created: 16.03.18 03:13
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support;
|
||||
|
||||
/**
|
||||
* Class MessageCollection
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support
|
||||
*/
|
||||
class MessageCollection extends PaginatedCollection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*
|
||||
* File: PaginatedCollection.php
|
||||
* Category: Collection
|
||||
* Author: M. Goldenbaum
|
||||
* Created: 16.03.18 03:13
|
||||
* Updated: -
|
||||
*
|
||||
* Description:
|
||||
* -
|
||||
*/
|
||||
|
||||
namespace Webklex\PHPIMAP\Support;
|
||||
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
|
||||
/**
|
||||
* Class PaginatedCollection
|
||||
*
|
||||
* @package Webklex\PHPIMAP\Support
|
||||
*/
|
||||
class PaginatedCollection extends Collection {
|
||||
|
||||
/**
|
||||
* Number of total entries
|
||||
*
|
||||
* @var int $total
|
||||
*/
|
||||
protected $total;
|
||||
|
||||
/**
|
||||
* Paginate the current collection.
|
||||
* @param int $per_page
|
||||
* @param int|null $page
|
||||
* @param string $page_name
|
||||
* @param boolean $prepaginated
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($per_page = 15, $page = null, $page_name = 'page', $prepaginated = false) {
|
||||
$page = $page ?: Paginator::resolveCurrentPage($page_name);
|
||||
|
||||
$total = $this->total ? $this->total : $this->count();
|
||||
|
||||
$results = !$prepaginated && $total ? $this->forPage($page, $per_page) : $this->all();
|
||||
|
||||
return $this->paginator($results, $total, $per_page, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
'pageName' => $page_name,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new length-aware paginator instance.
|
||||
* @param array $items
|
||||
* @param int $total
|
||||
* @param int $per_page
|
||||
* @param int|null $current_page
|
||||
* @param array $options
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
protected function paginator($items, $total, $per_page, $current_page, array $options) {
|
||||
return new LengthAwarePaginator($items, $total, $per_page, $current_page, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and set the total amount
|
||||
* @param null $total
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function total($total = null) {
|
||||
if($total === null) {
|
||||
return $this->total;
|
||||
}
|
||||
|
||||
return $this->total = $total;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user