Save them where exactly?How can I save messages that contains a specific keyword using the Email Box Monitor feature?
You can't do this, as part of having mailwizz navigate through messages easier, we need to remove the ones we already processed.And how to disable the function that deletes the messages related to the application? I'd like to keep the messages in my inbox.
I'd like to save the responses that contains the specific value from the EBM in a seperate folder something like /tmp/emails/, with the message body + sender + receiver.
<?php
class MyEmailBoxMonitor extends EmailBoxMonitor
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
protected function _processRemoteContents(array $params = array())
{
// do your logging here, dump $params, has lots of data.
// when done, let mailwizz do it's original set of work
return parent::_processRemoteContents($params);
}
}
<?php
class MyEmailBoxMonitorHandlerCommand extends EmailBoxMonitorHandlerCommand
{
/**
* @return $this
* @throws CException
*/
protected function processWithPcntl()
{
// get all servers
$servers = MyEmailBoxMonitor::model()->findAll(array(
'condition' => 't.status = :status',
'params' => array(':status' => MyEmailBoxMonitor::STATUS_ACTIVE),
));
// close the external connections
$this->setExternalConnectionsActive(false);
// split into x server chuncks
$chunkSize = (int)Yii::app()->options->get('system.cron.process_email_box_monitors.pcntl_processes', 10);
$serverChunks = array_chunk($servers, $chunkSize);
unset($servers);
foreach ($serverChunks as $servers) {
$childs = array();
foreach ($servers as $server) {
$pid = pcntl_fork();
if($pid == -1) {
continue;
}
// Parent
if ($pid) {
$childs[] = $pid;
}
// child
if (!$pid) {
try {
$this->stdout(sprintf('Started processing server ID %d.', $server->server_id));
$server->processRemoteContents(array(
'logger' => $this->verbose ? array($this, 'stdout') : null,
));
$this->stdout(sprintf('Finished processing server ID %d.', $server->server_id));
} catch (Exception $e) {
$this->stdout(__LINE__ . ': ' . $e->getMessage());
Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
}
Yii::app()->end();
}
}
while (count($childs) > 0) {
foreach ($childs as $key => $pid) {
$res = pcntl_waitpid($pid, $status, WNOHANG);
if($res == -1 || $res > 0) {
unset($childs[$key]);
}
}
sleep(1);
}
}
return $this;
}
/**
* @return $this
*/
protected function processWithoutPcntl()
{
// get all servers
$servers = MyEmailBoxMonitor::model()->findAll(array(
'condition' => 't.status = :status',
'params' => array(':status' => MyEmailBoxMonitor::STATUS_ACTIVE),
));
foreach ($servers as $server) {
try {
$this->stdout(sprintf('Started processing server ID %d.', $server->server_id));
$server->processRemoteContents(array(
'logger' => $this->verbose ? array($this, 'stdout') : null,
));
$this->stdout(sprintf('Finished processing server ID %d.', $server->server_id));
} catch (Exception $e) {
$this->stdout(__LINE__ . ': ' . $e->getMessage());
Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
}
}
return $this;
}
}