mirror of
https://github.com/retailcrm/Fetch.git
synced 2025-02-11 12:39:26 +03:00
Fixed PHPDoc & PSR Coding Standards
This commit is contained in:
parent
baaae55c0c
commit
755d50a064
@ -24,14 +24,14 @@ class Attachment
|
||||
/**
|
||||
* This is the structure object for the piece of the message body that the attachment is located it.
|
||||
*
|
||||
* @var stdClass
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $structure;
|
||||
|
||||
/**
|
||||
* This is the unique identifier for the message this attachment belongs to.
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var int
|
||||
*/
|
||||
protected $messageId;
|
||||
|
||||
@ -45,14 +45,14 @@ class Attachment
|
||||
/**
|
||||
* This is the id pointing to the section of the message body that contains the attachment.
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var int
|
||||
*/
|
||||
protected $partId;
|
||||
|
||||
/**
|
||||
* This is the attachments filename.
|
||||
*
|
||||
* @var unknown_type
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
@ -68,7 +68,7 @@ class Attachment
|
||||
* only populated if the getData() function is called and should not be directly used.
|
||||
*
|
||||
* @internal
|
||||
* @var unknown_type
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
@ -77,8 +77,8 @@ class Attachment
|
||||
* attachment is located at, and the identifier for that body part. As a general rule you should not be creating
|
||||
* instances of this yourself, but rather should get them from an ImapMessage class.
|
||||
*
|
||||
* @param ImapMessage $message
|
||||
* @param stdClass $structure
|
||||
* @param Message $message
|
||||
* @param \stdClass $structure
|
||||
* @param string $partIdentifier
|
||||
*/
|
||||
public function __construct(Message $message, $structure, $partIdentifier = null)
|
||||
@ -92,8 +92,7 @@ class Attachment
|
||||
|
||||
$parameters = Message::getParametersFromStructure($structure);
|
||||
|
||||
if(isset($parameters['filename']))
|
||||
{
|
||||
if (isset($parameters['filename'])) {
|
||||
$this->filename = $parameters['filename'];
|
||||
} elseif (isset($parameters['name'])) {
|
||||
$this->filename = $parameters['name'];
|
||||
@ -113,12 +112,11 @@ class Attachment
|
||||
* This function returns the data of the attachment. Combined with getMimeType() it can be used to directly output
|
||||
* data to a browser.
|
||||
*
|
||||
* @return binary
|
||||
* @return string
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if(!isset($this->data))
|
||||
{
|
||||
if (!isset($this->data)) {
|
||||
$messageBody = isset($this->partId) ?
|
||||
imap_fetchbody($this->imapStream, $this->messageId, $this->partId, FT_UID)
|
||||
: imap_body($this->imapStream, $this->messageId, FT_UID);
|
||||
@ -126,6 +124,7 @@ class Attachment
|
||||
$messageBody = Message::decode($messageBody, $this->encoding);
|
||||
$this->data = $messageBody;
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
@ -163,6 +162,7 @@ class Attachment
|
||||
* This function saves the attachment to the passed directory, keeping the original name of the file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function saveToDirectory($path)
|
||||
{
|
||||
@ -177,13 +177,13 @@ class Attachment
|
||||
/**
|
||||
* This function saves the attachment to the exact specified location.
|
||||
*
|
||||
* @param path $path
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function saveAs($path)
|
||||
{
|
||||
$dirname = dirname($path);
|
||||
if(file_exists($path))
|
||||
{
|
||||
if (file_exists($path)) {
|
||||
if (!is_writable($path))
|
||||
return false;
|
||||
} elseif (!is_dir($dirname) || !is_writable($dirname)) {
|
||||
@ -195,6 +195,7 @@ class Attachment
|
||||
|
||||
$results = fwrite($filePointer, $this->getData());
|
||||
fclose($filePointer);
|
||||
|
||||
return is_numeric($results);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class Message
|
||||
/**
|
||||
* This is the connection/mailbox class that the email came from.
|
||||
*
|
||||
* @var Imap
|
||||
* @var Server
|
||||
*/
|
||||
protected $imapConnection;
|
||||
|
||||
@ -45,21 +45,21 @@ class Message
|
||||
/**
|
||||
* This as an object which contains header information for the message.
|
||||
*
|
||||
* @var stdClass
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $headers;
|
||||
|
||||
/**
|
||||
* This is an object which contains various status messages and other information about the message.
|
||||
*
|
||||
* @var stdClass
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $messageOverview;
|
||||
|
||||
/**
|
||||
* This is an object which contains information about the structure of the message body.
|
||||
*
|
||||
* @var stdClass
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $structure;
|
||||
|
||||
@ -76,7 +76,7 @@ class Message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static protected $flagTypes = array('recent', 'flagged', 'answered', 'deleted', 'seen', 'draft');
|
||||
protected static $flagTypes = array('recent', 'flagged', 'answered', 'deleted', 'seen', 'draft');
|
||||
|
||||
/**
|
||||
* This holds the plantext email message.
|
||||
@ -120,6 +120,13 @@ class Message
|
||||
*/
|
||||
protected $from;
|
||||
|
||||
/**
|
||||
* This is an array of arrays that contain information about the addresses the email was cc'd to.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* This is an array of arrays that contain information about the addresses the email was cc'd to.
|
||||
*
|
||||
@ -137,7 +144,7 @@ class Message
|
||||
/**
|
||||
* This is an array of ImapAttachments retrieved from the message.
|
||||
*
|
||||
* @var array
|
||||
* @var Attachment[]
|
||||
*/
|
||||
protected $attachments = array();
|
||||
|
||||
@ -146,7 +153,7 @@ class Message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static public $charset = 'UTF-8//TRANSLIT';
|
||||
public static $charset = 'UTF-8//TRANSLIT';
|
||||
|
||||
/**
|
||||
* This constructor takes in the uid for the message and the Imap class representing the mailbox the
|
||||
@ -154,7 +161,7 @@ class Message
|
||||
* through the apprioriate Imap functions.
|
||||
*
|
||||
* @param int $messageUniqueId
|
||||
* @param Imap $mailbox
|
||||
* @param Server $mailbox
|
||||
*/
|
||||
public function __construct($messageUniqueId, Server $mailbox)
|
||||
{
|
||||
@ -183,8 +190,6 @@ class Message
|
||||
foreach (self::$flagTypes as $flag)
|
||||
$this->status[$flag] = ($messageOverview->$flag == 1);
|
||||
|
||||
|
||||
|
||||
/* Next load in all of the header information */
|
||||
|
||||
$headers = $this->getHeaders();
|
||||
@ -202,8 +207,7 @@ class Message
|
||||
|
||||
$structure = $this->getStructure();
|
||||
|
||||
if(!isset($structure->parts))
|
||||
{
|
||||
if (!isset($structure->parts)) {
|
||||
// not multipart
|
||||
$this->processStructure($structure);
|
||||
} else {
|
||||
@ -219,16 +223,16 @@ class Message
|
||||
* results are only retrieved from the server once unless passed true as a parameter.
|
||||
*
|
||||
* @param bool $forceReload
|
||||
* @return stdClass
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getOverview($forceReload = false)
|
||||
{
|
||||
if($forceReload || !isset($this->messageOverview))
|
||||
{
|
||||
if ($forceReload || !isset($this->messageOverview)) {
|
||||
// returns an array, and since we just want one message we can grab the only result
|
||||
$results = imap_fetch_overview($this->imapStream, $this->uid, FT_UID);
|
||||
$this->messageOverview = array_shift($results);
|
||||
}
|
||||
|
||||
return $this->messageOverview;
|
||||
}
|
||||
|
||||
@ -238,12 +242,11 @@ class Message
|
||||
* once unless passed true as a parameter.
|
||||
*
|
||||
* @param bool $forceReload
|
||||
* @return stdClass
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getHeaders($forceReload = false)
|
||||
{
|
||||
if($forceReload || !isset($this->headers))
|
||||
{
|
||||
if ($forceReload || !isset($this->headers)) {
|
||||
// raw headers (since imap_headerinfo doesn't use the unique id)
|
||||
$rawHeaders = imap_fetchheader($this->imapStream, $this->uid, FT_UID);
|
||||
|
||||
@ -264,14 +267,15 @@ class Message
|
||||
* returned by imap_fetchstructure. The results are only retrieved from the server once unless passed true as a
|
||||
* parameter.
|
||||
*
|
||||
* @return stdClass
|
||||
* @param bool $forceReload
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getStructure($forceReload = false)
|
||||
{
|
||||
if($forceReload || !isset($this->structure))
|
||||
{
|
||||
if ($forceReload || !isset($this->structure)) {
|
||||
$this->structure = imap_fetchstructure($this->imapStream, $this->uid, FT_UID);
|
||||
}
|
||||
|
||||
return $this->structure;
|
||||
}
|
||||
|
||||
@ -286,25 +290,25 @@ class Message
|
||||
*/
|
||||
public function getMessageBody($html = false)
|
||||
{
|
||||
if($html)
|
||||
{
|
||||
if(!isset($this->htmlMessage) && isset($this->plaintextMessage))
|
||||
{
|
||||
if ($html) {
|
||||
if (!isset($this->htmlMessage) && isset($this->plaintextMessage)) {
|
||||
$output = nl2br($this->plaintextMessage);
|
||||
|
||||
return $output;
|
||||
|
||||
} elseif (isset($this->htmlMessage)) {
|
||||
return $this->htmlMessage;
|
||||
}
|
||||
} else {
|
||||
if(!isset($this->plaintextMessage) && isset($this->htmlMessage))
|
||||
{
|
||||
if (!isset($this->plaintextMessage) && isset($this->htmlMessage)) {
|
||||
$output = strip_tags($this->htmlMessage);
|
||||
|
||||
return $output;
|
||||
} elseif (isset($this->plaintextMessage)) {
|
||||
return $this->plaintextMessage;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -324,16 +328,14 @@ class Message
|
||||
return false;
|
||||
|
||||
|
||||
if(!$asString)
|
||||
{
|
||||
if (!$asString) {
|
||||
if ($type == 'from')
|
||||
return $this->from[0];
|
||||
|
||||
return $this->$type;
|
||||
} else {
|
||||
$outputString = '';
|
||||
foreach($this->$type as $address)
|
||||
{
|
||||
foreach ($this->$type as $address) {
|
||||
if (isset($set))
|
||||
$outputString .= ', ';
|
||||
if (!isset($set))
|
||||
@ -343,6 +345,7 @@ class Message
|
||||
$address['name'] . ' <' . $address['address'] . '>'
|
||||
: $address['address'];
|
||||
}
|
||||
|
||||
return $outputString;
|
||||
}
|
||||
}
|
||||
@ -381,7 +384,7 @@ class Message
|
||||
/**
|
||||
* This function returns Imap this message came from.
|
||||
*
|
||||
* @return Imap
|
||||
* @return Server
|
||||
*/
|
||||
public function getImapBox()
|
||||
{
|
||||
@ -392,7 +395,7 @@ class Message
|
||||
* This function takes in a structure and identifier and processes that part of the message. If that portion of the
|
||||
* message has its own subparts, those are recursively processed using this function.
|
||||
*
|
||||
* @param stdClass $structure
|
||||
* @param \stdClass $structure
|
||||
* @param string $partIdentifier
|
||||
* @todoa process attachments.
|
||||
*/
|
||||
@ -400,8 +403,7 @@ class Message
|
||||
{
|
||||
$parameters = self::getParametersFromStructure($structure);
|
||||
|
||||
if(isset($parameters['name']) || isset($parameters['filename']))
|
||||
{
|
||||
if (isset($parameters['name']) || isset($parameters['filename'])) {
|
||||
$attachment = new Attachment($this, $structure, $partIdentifier);
|
||||
$this->attachments[] = $attachment;
|
||||
} elseif ($structure->type == 0 || $structure->type == 1) {
|
||||
@ -415,10 +417,8 @@ class Message
|
||||
if ($parameters['charset'] !== self::$charset)
|
||||
$messageBody = iconv($parameters['charset'], self::$charset, $messageBody);
|
||||
|
||||
if(strtolower($structure->subtype) == 'plain' || $structure->type == 1)
|
||||
{
|
||||
if(isset($this->plaintextMessage))
|
||||
{
|
||||
if (strtolower($structure->subtype) == 'plain' || $structure->type == 1) {
|
||||
if (isset($this->plaintextMessage)) {
|
||||
$this->plaintextMessage .= PHP_EOL . PHP_EOL;
|
||||
} else {
|
||||
$this->plaintextMessage = '';
|
||||
@ -427,8 +427,7 @@ class Message
|
||||
$this->plaintextMessage .= trim($messageBody);
|
||||
} else {
|
||||
|
||||
if(isset($this->htmlMessage))
|
||||
{
|
||||
if (isset($this->htmlMessage)) {
|
||||
$this->htmlMessage .= '<br><br>';
|
||||
} else {
|
||||
$this->htmlMessage = '';
|
||||
@ -440,8 +439,7 @@ class Message
|
||||
|
||||
if (isset($structure->parts)) { // multipart: iterate through each part
|
||||
|
||||
foreach ($structure->parts as $partIndex => $part)
|
||||
{
|
||||
foreach ($structure->parts as $partIndex => $part) {
|
||||
$partId = $partIndex + 1;
|
||||
|
||||
if (isset($partIdentifier))
|
||||
@ -459,13 +457,12 @@ class Message
|
||||
* @param int|string $encoding
|
||||
* @return string
|
||||
*/
|
||||
static public function decode($data, $encoding)
|
||||
public static function decode($data, $encoding)
|
||||
{
|
||||
if (!is_numeric($encoding))
|
||||
$encoding = strtolower($encoding);
|
||||
|
||||
switch($encoding)
|
||||
{
|
||||
switch ($encoding) {
|
||||
case 'quoted-printable':
|
||||
case 4:
|
||||
return quoted_printable_decode($data);
|
||||
@ -485,10 +482,9 @@ class Message
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
static public function typeIdToString($id)
|
||||
{
|
||||
switch($id)
|
||||
public static function typeIdToString($id)
|
||||
{
|
||||
switch ($id) {
|
||||
case 0:
|
||||
return 'text';
|
||||
|
||||
@ -519,10 +515,10 @@ class Message
|
||||
/**
|
||||
* Takes in a section structure and returns its parameters as an associative array.
|
||||
*
|
||||
* @param stdClass $structure
|
||||
* @param \stdClass $structure
|
||||
* @return array
|
||||
*/
|
||||
static function getParametersFromStructure($structure)
|
||||
public static function getParametersFromStructure($structure)
|
||||
{
|
||||
$parameters = array();
|
||||
if (isset($structure->parameters))
|
||||
@ -547,14 +543,14 @@ class Message
|
||||
{
|
||||
$outputAddresses = array();
|
||||
if (is_array($addresses))
|
||||
foreach($addresses as $address)
|
||||
{
|
||||
foreach ($addresses as $address) {
|
||||
$currentAddress = array();
|
||||
$currentAddress['address'] = $address->mailbox . '@' . $address->host;
|
||||
if (isset($address->personal))
|
||||
$currentAddress['name'] = $address->personal;
|
||||
$outputAddresses[] = $currentAddress;
|
||||
}
|
||||
|
||||
return $outputAddresses;
|
||||
}
|
||||
|
||||
@ -573,7 +569,7 @@ class Message
|
||||
* is returned, unless
|
||||
*
|
||||
* @param null|string $filename
|
||||
* @return array|bool|ImapAttachments
|
||||
* @return array|bool|Attachment[]
|
||||
*/
|
||||
public function getAttachments($filename = null)
|
||||
{
|
||||
@ -584,8 +580,7 @@ class Message
|
||||
return $this->attachments;
|
||||
|
||||
$results = array();
|
||||
foreach($this->attachments as $attachment)
|
||||
{
|
||||
foreach ($this->attachments as $attachment) {
|
||||
if ($attachment->getFileName() == $filename)
|
||||
$results[] = $attachment;
|
||||
}
|
||||
@ -619,6 +614,7 @@ class Message
|
||||
*
|
||||
* @param string $flag Flagged, Answered, Deleted, Seen, Draft
|
||||
* @param bool $enable
|
||||
* @throws \InvalidArgumentException
|
||||
* @return bool
|
||||
*/
|
||||
public function setFlag($flag, $enable = true)
|
||||
@ -628,8 +624,7 @@ class Message
|
||||
|
||||
$flag = '\\' . ucfirst($flag);
|
||||
|
||||
if($enable)
|
||||
{
|
||||
if ($enable) {
|
||||
return imap_setflag_full($this->imapStream, $this->uid, $flag, ST_UID);
|
||||
} else {
|
||||
return imap_clearflag_full($this->imapStream, $this->uid, $flag, ST_UID);
|
||||
|
@ -25,14 +25,14 @@ class Server
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
static $sslEnable = true;
|
||||
public static $sslEnable = true;
|
||||
|
||||
/**
|
||||
* These are the flags that depend on ssl support being compiled into imap.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $sslFlags = array('ssl', 'validate-cert', 'novalidate-cert', 'tls', 'notls');
|
||||
public static $sslFlags = array('ssl', 'validate-cert', 'novalidate-cert', 'tls', 'notls');
|
||||
|
||||
/**
|
||||
* This is used to prevent the class from putting up conflicting tags. Both directions- key to value, value to key-
|
||||
@ -40,7 +40,7 @@ class Server
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $exclusiveFlags = array('validate-cert' => 'novalidate-cert', 'tls' => 'notls');
|
||||
public static $exclusiveFlags = array('validate-cert' => 'novalidate-cert', 'tls' => 'notls');
|
||||
|
||||
/**
|
||||
* This is the domain or server path the class is connecting to.
|
||||
@ -155,8 +155,7 @@ class Server
|
||||
public function setMailBox($mailbox = '')
|
||||
{
|
||||
$this->mailbox = $mailbox;
|
||||
if(isset($this->imapStream))
|
||||
{
|
||||
if (isset($this->imapStream)) {
|
||||
$this->setImapStream();
|
||||
}
|
||||
}
|
||||
@ -179,8 +178,7 @@ class Server
|
||||
if (!self::$sslEnable && in_array($flag, self::$sslFlags))
|
||||
return;
|
||||
|
||||
if(isset(self::$exclusiveFlags[$flag]))
|
||||
{
|
||||
if (isset(self::$exclusiveFlags[$flag])) {
|
||||
$kill = $flag;
|
||||
} elseif ($index = array_search($flag, self::$exclusiveFlags)) {
|
||||
$kill = $index;
|
||||
@ -189,10 +187,8 @@ class Server
|
||||
if (isset($kill) && isset($this->flags[$kill]))
|
||||
unset($this->flags[$kill]);
|
||||
|
||||
if(isset($value) && $value !== true)
|
||||
{
|
||||
if($value == false)
|
||||
{
|
||||
if (isset($value) && $value !== true) {
|
||||
if ($value == false) {
|
||||
unset($this->flags[$flag]);
|
||||
} else {
|
||||
$this->flags[] = $flag . '=' . $value;
|
||||
@ -206,11 +202,12 @@ class Server
|
||||
* This funtion is used to set various options for connecting to the server.
|
||||
*
|
||||
* @param int $bitmask
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setOptions($bitmask = 0)
|
||||
{
|
||||
if (!is_numeric($bitmask))
|
||||
throw new ImapException();
|
||||
throw new \Exception();
|
||||
|
||||
$this->options = $bitmask;
|
||||
}
|
||||
@ -274,8 +271,7 @@ class Server
|
||||
*/
|
||||
protected function setImapStream()
|
||||
{
|
||||
if(isset($this->imapStream))
|
||||
{
|
||||
if (isset($this->imapStream)) {
|
||||
if (!imap_reopen($this->imapStream, $this->getServerString(), $this->options, 1))
|
||||
throw new \RuntimeException(imap_last_error());
|
||||
} else {
|
||||
@ -311,12 +307,10 @@ class Server
|
||||
*/
|
||||
public function search($criteria = 'ALL', $limit = null)
|
||||
{
|
||||
if($results = imap_search($this->getImapStream(), $criteria, SE_UID))
|
||||
{
|
||||
if ($results = imap_search($this->getImapStream(), $criteria, SE_UID)) {
|
||||
if (isset($limit) && count($results) > $limit)
|
||||
$results = array_slice($results, 0, $limit);
|
||||
|
||||
$stream = $this->getImapStream();
|
||||
$messages = array();
|
||||
|
||||
foreach ($results as $messageId)
|
||||
@ -343,7 +337,7 @@ class Server
|
||||
* Returns the emails in the current mailbox as an array of ImapMessage objects.
|
||||
*
|
||||
* @param null|int $limit
|
||||
* @return array
|
||||
* @return Message[]
|
||||
*/
|
||||
public function getMessages($limit = null)
|
||||
{
|
||||
@ -357,8 +351,7 @@ class Server
|
||||
|
||||
$stream = $this->getImapStream();
|
||||
$messages = array();
|
||||
for($i = 1; $i <= $numMessages; $i++)
|
||||
{
|
||||
for ($i = 1; $i <= $numMessages; $i++) {
|
||||
$uid = imap_uid($stream, $i);
|
||||
$messages[] = new Message($uid, $this);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user