Process bounces not working when executed in the command line (phplist 3.3.3)

Hello, support.

I am having a problem when trying to process bounces in the command line. As follows:

/******
root@MyHost:/var/www/html/lists# /usr/bin/php /var/www/html/lists/admin/index.php -pprocessbounces -c/var/www/html/lists/config/config.php
phpList - phpList version 3.3.3 © 2000-2018 phpList Ltd, https://www.phplist.com
phpList version 3.3.3 © 2000-2018 phpList Ltd, https://www.phplist.comphpList - Cannot open mailbox file Can’t open mailbox bounces: no such mailbox
phpList - Download failed, exiting
******/
In my config.php, I have:
$bounce_protocol = ‘mbox’;
$bounce_mailbox = ‘bounces’; # bounces is a symbolic link

And it works ok when I run “process bounces” on the user interface. It just doesn’t work when I run it in the command line, even when ran by the root user.

Operating System:
NAME=“Ubuntu”
VERSION=“14.04.5 LTS, Trusty Tahr”

The security of the /var/mail/bounces file:

ownership: bounces:www-data
privileges: 660

PHP 5.5.9-1ubuntu4.25

Thanks for your attention;
Rafael

Where exactly is this file “bounces”, and how do you expect php to find it?

Hi, Duncan.

‘bounces’ is ‘/var/mail/bounces’ and it is soft linked to ‘/var/www/bounces’.

I tried to replace ‘bounces’ with both ‘/var/mail/bounces’ and ‘/var/www/bounces’ but the result is the same: “Cannot open mailbox file Can’t open mailbox bounces: no such mailbox”

Thank you. Regards.

@Rafael.Quiterio It might be explained by the value of HOME environment variable. See https://www.webmasterworld.com/php/3738080.htm

Ok, I understand. But my php knowlege is nul, so I have to ask: where in the code (file and function) should I add the putenv statement? And, by the way, what should the HOME’s value be? I tried to set it in the OS Shell to ‘/var/www’ but the problem remains the same.

Thank you.
Rafael

@Rafael.Quiterio You can add it to the end of the config.php file. The value for HOME should be the directory containing the bounces file. You could try the soft link or the real file to see which works.

Just to test it, the following imap_open() works, or at least finds the file, but without the putenv() the imap_open() fails

putenv('HOME=/home/dcameron/phplist');
var_dump(imap_open('bounces.mbox', '', ''));

But I don’t really understand why the file is found when accessed through the browser unless HOME is defined already.

It’s intriguing, but it does!
image

I tried your code like this:

<?php putenv('HOME=/var/mail'); var_dump(imap_open('bounces', '', '')); putenv('HOME=/var/www'); var_dump(imap_open('bounces', '', '')); ?>

and the result is:

root@MyHost:~# /usr/bin/php teste.php
PHP Warning: imap_open(): Couldn’t open stream bounces in /home/asi/teste.php on line 3
bool(false)
PHP Warning: imap_open(): Couldn’t open stream bounces in /home/asi/teste.php on line 5
bool(false)
PHP Notice: Unknown: Can’t open mailbox bounces: no such mailbox (errflg=2) in Unknown on line 0
PHP Notice: Unknown: Can’t open mailbox bounces: no such mailbox (errflg=2) in Unknown on line 0

By the way, my $HOME variable is preset to my home directory, which I believe is the default behaviour.

@Rafael.Quiterio You could try dumping all the environment variables to see what HOME is when phplist is run by the web server. Also, the web server is usually run as www-data so you could run the command line as that user

sudo -u www-data ...

But otherwise I don’t really have any more ideas.

Ok, I will try that.

Many thanks.

Hi;

In fact, if I do this:

export HOME=/var/www; /usr/bin/sudo -u www-data /usr/bin/php /var/www/html/lists/admin/index.php -p processbounces -c/var/www/html/lists/config/config.php

It Works:

phpList - phpList version 3.3.3 (c) 2000-2018 phpList Ltd, https://www.phplist.com
phpList version 3.3.3 (c) 2000-2018 phpList Ltd, https://www.phplist.comphpList - 0 bounces to fetch from the mailbox
phpList - reprocessing
phpList - 4 bounces to reprocess
phpList - 4 out of 4 processed
phpList - Identifying consecutive bounces
phpList - Nothing to do
phpList - total of 0 subscribers processed

So, by now, I placed this in www-data’s crontab.

I still did not realize how to dump the env variables, but I will keep searching. Then, maybe I come back to give you feedback.

Thank you very much for all the help.