mailProcessor.class.php (2.9 kb) added by Enforcer x
Description: Code using the append function
<?php
class mailProcessor
{
function parse($hostname, $username, $password)
{
// Create a new IMAP transport object by specifying the server name.
try
{
$mailImap = new ezcMailImapTransport($hostname);
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
// Authenticate to the IMAP server.
try
{
$mailImap->authenticate($username, $passwd);
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
// Determine mail folder 'achive'.
try
{
$mailFolderAchive = str_replace('/', $mailImap->getHierarchyDelimiter(), MAIL_FOLDER_ARCHIVE.'/'.date('Y').'/'.date('m'));
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
// Check if mail folder 'achive' exists.
$mailFolderArchiveCheck = $this->__ezcMailFolderCheck($mailImap, $mailFolderAchive);
if($mailFolderArchiveCheck === false)
{
// Create archive mail folder.
try
{
$mailImap->createMailbox($mailFolderAchive);
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
$mailFolderArchiveCheck = $this->__ezcMailFolderCheck($mailImap, $mailFolderAchive);
}
if($mailFolderArchiveCheck !== true && $mailFolderArchiveCheck !== false)
{
$mailProcessErrorMessageForView[] = $mailFolderArchiveCheck;
}
// Only process mails if mail folder 'achive' exists.
if($mailFolderArchiveCheck === true)
{
ezcMailCharsetConverter::setConvertMethod(array('MailAccountsController', '__convertToUTF8Iconv')); // override ezc own function of convertToUTF8Iconv()
$mailParser = new ezcMailParser(); // create a new mail parser object
// Select the mailbox 'INBOX'.
try
{
$mailImap->selectMailbox('INBOX');
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
// Move processed mail to archive mail folder.
try
{
$mailImap->append($mailFolderAchive, $mail->generate(), array('SEEN'));
}
catch(Exception $exception)
{
echo 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
}
}
function __ezcMailFolderCheck(&$mailImap, $mailFolderName = null)
{
$returnValue = false;
// Check if mail folder exists.
try
{
foreach($mailImap->listMailboxes() as $mailFolder)
{
if($mailFolder == $mailFolderName)
{
$returnValue = true;
break;
}
}
}
catch(Exception $exception)
{
$this->CoreLogOperations->save($returnValue = 'Caught exception at line '.__LINE__.': '.$exception->getMessage());
}
return $returnValue;
}
}
?>