Disable deleting messages (EBM)

Jelle

New Member
Hi,

How can I save messages that contains a specific keyword using the Email Box Monitor feature?
And how to disable the function that deletes the messages related to the application? I'd like to keep the messages in my inbox.
 
How can I save messages that contains a specific keyword using the Email Box Monitor feature?
Save them where exactly?

And how to disable the function that deletes the messages related to the application? I'd like to keep the messages in my inbox.
You can't do this, as part of having mailwizz navigate through messages easier, we need to remove the ones we already processed.
 
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.
 
@Jelle - Take a look in /apps/common/models/EmailBoxMonitor.php specifically in the "_processRemoteContents" method, that is where mailwizz connects to the remote server, downloads, and processes the messages.
From command line, when you call the "/usr/bin/php -q .... apps/console/console.php email-box-monitor-handler" it actually calls the file /apps/console/commands/EmailBoxMonitorHandlerCommand.php which then calls the above EmailBoxMonitor file.
So if i where you, i would simply duplicate /apps/common/models/EmailBoxMonitor.php into my own file:
PHP:
<?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);
     }
}
Then i would also duplicate EmailBoxMonitorHandlerCommand and make it use the new class i just created:
PHP:
<?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;
    }
}

Then you would call the command from command line like:
"/usr/bin/php -q .... apps/console/console.php myemailboxmonitorhandler"

So to recap, when you run from command line the command:
"/usr/bin/php -q .... apps/console/console.php myemailboxmonitorhandler"
It will load your custom created file/class MyEmailBoxMonitorHandlerCommand which in turn will load your custom created model file/class MyEmailBoxMonitor which has a custom method called _processRemoteContents where you can do all your logging and then simply call the parent class implementation to let mailwizz do it's usual work.

The above should put you on right track and keep the changes safe for upgrades.
While i don't recommend doing this, you asked for a way to do it, there it is :)
 
upload_2019-11-18_14-8-58.png

Thanks!

I changed:
'deleteMessages' => true,
To
'deleteMessages' => false,
That disables deleting the messages from the email box monitor.

=========================================================

But is the email box monitor days back hardcoded? I thought that you could change these settings from the user interface:

$options = Yii::app()->options;
$processLimit = (int)$options->get('system.cron.process_email_box_monitors.emails_at_once', 500);
$processDaysBack = (int)$options->get('system.cron.process_email_box_monitors.days_back', 3);

upload_2019-11-18_14-11-25.png
 
Back
Top