Skip to content

Commit

Permalink
drop use of the deprecated PHP imap extension (php-imap) - see #472 and
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGoodwin committed Apr 1, 2024
1 parent 5826808 commit 81a1d45
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 80 deletions.
6 changes: 0 additions & 6 deletions INSTALL.TXT
Expand Up @@ -174,12 +174,6 @@ And if the webserver (PHP) needs to make network connections out to a database s
semanage boolean -m --on httpd_can_network_connect_db
````

If additionally, needing the webserver (PHP) to talk to an imap server, then you'll probably also need:

```bash
semanage boolean -m --on httpd_can_network_connect
````


5. Check settings, and create Admin user
----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -11,7 +11,7 @@ Homepage: http://postfixadmin.sourceforge.net

Package: postfixadmin
Architecture: all
Depends: debconf (>= 0.5), dbconfig-common, wwwconfig-common, apache2 | lighttpd | httpd, libapache2-mod-php | php-cgi | php-fpm | php, php-imap, php-mysql | php-mysqlnd | php-pgsql | php-sqlite3, php-mbstring, default-mysql-client | postgresql-client | mariadb-client, ${misc:Depends}
Depends: debconf (>= 0.5), dbconfig-common, wwwconfig-common, apache2 | lighttpd | httpd, libapache2-mod-php | php-cgi | php-fpm | php, php-mysql | php-mysqlnd | php-pgsql | php-sqlite3, php-mbstring, default-mysql-client | postgresql-client | mariadb-client, ${misc:Depends}
Recommends: postfix-mysql | postfix-pgsql, virtual-mysql-server | postgresql | sqlite3 (>= 3.12.0) | mariadb-server, zendframework, dovecot-core | courier-authlib-mysql | courier-authlib-postgresql, php-cli
Description: Virtual mail hosting interface for Postfix
Postfixadmin is a web interface to manage virtual users and domains
Expand Down
69 changes: 5 additions & 64 deletions model/MailboxHandler.php
Expand Up @@ -749,76 +749,17 @@ protected function mailbox_postdeletion()
*/
protected function create_mailbox_subfolders()
{
// no longer implemented; code relied on deprecated PHP imap extension.

$create_mailbox_subdirs = Config::read('create_mailbox_subdirs');
if (empty($create_mailbox_subdirs)) {
return true;
}

if (!function_exists('imap_open')) {
trigger_error('imap_open function not present; cannot create_mailbox_subdirs');
return false;
}

if (!is_array($create_mailbox_subdirs)) {
trigger_error('create_mailbox_subdirs must be an array', E_USER_ERROR);
return false;
}

$s_host = Config::read_string('create_mailbox_subdirs_host');
if (empty($s_host)) {
trigger_error('An IMAP/POP server host ($CONF["create_mailbox_subdirs_host"]) must be configured, if sub-folders are to be created', E_USER_ERROR);
return false;
}

$s_options='';

$create_mailbox_subdirs_hostoptions = Config::read('create_mailbox_subdirs_hostoptions');
if (!empty($create_mailbox_subdirs_hostoptions)) {
if (!is_array($create_mailbox_subdirs_hostoptions)) {
trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array', E_USER_ERROR);
return false;
}
foreach ($create_mailbox_subdirs_hostoptions as $o) {
$s_options.='/'.$o;
}
}

$s_port='';
if (Config::has('create_mailbox_subdirs_hostport')) {
$create_mailbox_subdirs_hostport = Config::read('create_mailbox_subdirs_hostport');
if (!empty($create_mailbox_subdirs_hostport)) {
$s_port = $create_mailbox_subdirs_hostport;
if (intval($s_port)!=$s_port) {
trigger_error('The $CONF["create_mailbox_subdirs_hostport"] parameter must be an integer', E_USER_ERROR);
return false;
}
$s_port=':'.$s_port;
}
}

$s='{'.$s_host.$s_port.$s_options.'}';

sleep(1); # give the mail triggering the mailbox creation a chance to do its job

$i=@imap_open($s, $this->id, $this->values['password']);
if (false==$i) {
error_log('Could not log into IMAP/POP server: ' . $this->id . ': ' . imap_last_error());
return false;
}

$s_prefix = Config::read_string('create_mailbox_subdirs_prefix');
foreach ($create_mailbox_subdirs as $f) {
$f='{'.$s_host.'}'.$s_prefix.$f;
$res=imap_createmailbox($i, $f);
if (!$res) {
error_log('Could not create IMAP folder $f: ' . $this->id . ': ' . imap_last_error());
@imap_close($i);
return false;
}
@imap_subscribe($i, $f);
}
// see https://github.com/postfixadmin/postfixadmin/issues/472
// see https://github.com/postfixadmin/postfixadmin/issues/812 etc
error_log(__FILE__ . ' WARNING : PostfixAdmin no longer supports the imap folder population via config parameters: create_mailbox_subdirs, create_mailbox_subdirs_host, create_mailbox_subdirs_hostport and create_mailbox_subdirs_hostoptions ');

@imap_close($i);
return true;
}

Expand Down
9 changes: 0 additions & 9 deletions public/setup.php
Expand Up @@ -573,7 +573,6 @@ function do_software_environment_check()
$f_session_start = function_exists("session_start");
$f_preg_match = function_exists("preg_match");
$f_mb_encode_mimeheader = function_exists("mb_encode_mimeheader");
$f_imap_open = function_exists("imap_open");

$file_local_config = realpath(__DIR__ . "/../config.local.php");

Expand Down Expand Up @@ -727,13 +726,5 @@ function do_software_environment_check()
}


// Imap functions
if ($f_imap_open) {
$info[] = "Optional - PHP IMAP functions - OK";
} else {
$warn[] = "Warning: Optional dependency - PHP 'imap' extension missing. Without this you may not be able to automate creation of sub-folders for new mailboxes";
}


return ['error' => $error, 'warn' => $warn, 'info' => $info];
}

0 comments on commit 81a1d45

Please sign in to comment.