Skip to content

Commit

Permalink
Readded: Mailboxes quota information (info are retrieved by parsing m…
Browse files Browse the repository at this point in the history
…aildirsize file)
  • Loading branch information
nuxwin committed Apr 7, 2017
1 parent fb225d4 commit ea39cec
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Expand Up @@ -12,6 +12,9 @@ BACKEND
DISTRIBUTION
Fixed: Make sure that sendmail* packages are pre-uninstalled

FRONTEND
Readded: Mailboxes quota information (info are retrieved by parsing maildirsize file)

LISTENERS
Updated: Add Referrer-Policy header to 40_apache2_security_headers.pl listener file

Expand Down
2 changes: 1 addition & 1 deletion configs/debian/frontend/php-fpm.conf
Expand Up @@ -23,7 +23,7 @@ pm.max_requests = {FRONTEND_FCGI_MAX_REQUEST}
chdir = /
security.limit_extensions = .php .php3 .php4 .php5 .php7 .pht .phtml
env[TMPDIR] = {WEB_DIR}/data/tmp
php_admin_value[open_basedir] = {HOME_DIR}/:{CONF_DIR}/:{PEAR_DIR}/:{DISTRO_OPENSSL_CNF}:{DISTRO_CA_BUNDLE}:{RKHUNTER_LOG}:{CHKROOTKIT_LOG}{OTHER_ROOTKIT_LOG}:/proc/:/bin/df:/bin/mount:/dev/random:/dev/urandom
php_admin_value[open_basedir] = {HOME_DIR}/:{CONF_DIR}/:{PEAR_DIR}/:{MTA_VIRTUAL_MAIL_DIR}/:{DISTRO_OPENSSL_CNF}:{DISTRO_CA_BUNDLE}:{RKHUNTER_LOG}:{CHKROOTKIT_LOG}{OTHER_ROOTKIT_LOG}:/proc/:/bin/df:/bin/mount:/dev/random:/dev/urandom
php_value[max_execution_time] = 120
php_value[max_input_time] = 600
php_value[memory_limit] = 256M
Expand Down
7 changes: 6 additions & 1 deletion engine/PerlLib/Package/FrontEnd/Installer.pm
Expand Up @@ -45,6 +45,7 @@ use Net::LibIDN qw/ idn_to_ascii idn_to_unicode /;
use Package::FrontEnd;
use Servers::httpd;
use Servers::named;
use Servers::mta;
use version;
use parent 'Common::SingletonClass';

Expand Down Expand Up @@ -809,6 +810,9 @@ sub _addMasterWebUser
}

$rs = iMSCP::SystemUser->new( username => $userName )->addToGroup( $main::imscpConfig{'IMSCP_GROUP'} );
$rs = iMSCP::SystemUser->new( username => $userName )->addToGroup(
Servers::mta->factory()->{'config'}->{'MTA_MAILBOX_GID_NAME'}
);
$rs ||= iMSCP::SystemUser->new( username => $self->{'config'}->{'HTTPD_USER'} )->addToGroup( $groupName );
$rs ||= $self->{'eventManager'}->trigger( 'afterHttpdAddUser' );
}
Expand Down Expand Up @@ -932,12 +936,13 @@ sub _buildPhpConfig
FRONTEND_GROUP => $group,
FRONTEND_USER => $user,
HOME_DIR => $main::imscpConfig{'GUI_ROOT_DIR'},
MTA_VIRTUAL_MAIL_DIR => Servers::mta->factory()->{'config'}->{'MTA_VIRTUAL_MAIL_DIR'},
PEAR_DIR => $self->{'phpConfig'}->{'PHP_PEAR_DIR'},
OTHER_ROOTKIT_LOG => $main::imscpConfig{'OTHER_ROOTKIT_LOG'} ne ''
? ":$main::imscpConfig{'OTHER_ROOTKIT_LOG'}" : '',
RKHUNTER_LOG => $main::imscpConfig{'RKHUNTER_LOG'},
TIMEZONE => main::setupGetQuestion( 'TIMEZONE' ),
WEB_DIR => $main::imscpConfig{'GUI_ROOT_DIR'},
WEB_DIR => $main::imscpConfig{'GUI_ROOT_DIR'}
},
{
destination => "/usr/local/etc/imscp_panel/php-fpm.conf",
Expand Down
33 changes: 33 additions & 0 deletions gui/library/Functions/Client.php
Expand Up @@ -520,3 +520,36 @@ function send_alias_order_email($aliasName)

return true;
}

/**
* Get mailbox quota info from the given maildirsize file
*
* @param string $maildirsizeFilePath
* @return array|bool Array containing IMAP quota info on success, FALSE on failure
*/
function getMailboxQuotaInfo($maildirsizeFilePath)
{
if (!@is_readable($maildirsizeFilePath)) {
return false;
}

$fh = @fopen($maildirsizeFilePath, 'r');
if (!$fh) {
return false;
}

$info = array(
'MAILBOX_QUOTA' => $quota = substr(rtrim(fgets($fh)), 0, -1),
'MAILBOX_SIZE' => 0,
'MAILBOX_MSGS' => 0
);

while (($line = fgets($fh)) !== false) {
list($msgsize, $msgcount) = preg_split('/\s+/', $line);
$info['MAILBOX_SIZE'] += $msgsize;
$info['MAILBOX_MSGS'] += $msgcount;
}

fclose($fh);
return $info;
}
52 changes: 35 additions & 17 deletions gui/public/client/mail_accounts.php
Expand Up @@ -135,6 +135,10 @@ function _client_generateMailAccountsList($tpl, $mainDmnId)


$dmnProps = get_domain_default_props($_SESSION['user_id']);

$postfixConfig = new iMSCP_Config_Handler_File(
utils_normalizePath(iMSCP_Registry::get('config')->CONF_DIR . '/postfix/postfix.data')
);

while ($row = $stmt->fetchRow(PDO::FETCH_ASSOC)) {
list($mailDelete, $mailDeleteScript, $mailEdit, $mailEditScript) = _client_generateUserMailAction(
Expand All @@ -155,23 +159,37 @@ function _client_generateMailAccountsList($tpl, $mainDmnId)
$mailType .= '<br>';
}

if((strpos($row['mail_type'], '_mail') !== false)) {
list($user, $domain) = explode('@', $row['mail_addr']);
$info = getMailboxQuotaInfo(utils_normalizePath(
$postfixConfig['MTA_VIRTUAL_MAIL_DIR'] . "/$domain/$user/maildirsize"
));

if($info !== FALSE) {
$mailQuotaInfo = tr(
'%s / %s of %s total available',
bytesHuman($info['MAILBOX_SIZE'], NULL, 0),
bytesHuman($info['MAILBOX_QUOTA'], NULL, 0),
($dmnProps['mail_quota'] > 0) ? bytesHuman($dmnProps['mail_quota'], NULL, 0) : tr('Unlimited')
);
} else {
$mailQuotaInfo = tr('Unknown');
}
} else {
$mailQuotaInfo = tr('N/A');
}

$tpl->assign(array(
'MAIL_ADDR' => tohtml(decode_idna($mailAddr)),
'MAIL_TYPE' => $mailType,
'MAIL_QUOTA_ASSIGMENT' => (is_null($row['quota']))
? tr('N/A')
: tohtml(tr('%s of %s',
bytesHuman($row['quota'], NULL, 0),
($dmnProps['mail_quota'] == 0)
? tr('Unlimited') : tr('%s total available', bytesHuman($dmnProps['mail_quota'], NULL, 0))
)),
'MAIL_STATUS' => translate_dmn_status($row['status']),
'MAIL_DELETE' => $mailDelete,
'MAIL_DELETE_SCRIPT' => $mailDeleteScript,
'MAIL_EDIT' => $mailEdit,
'MAIL_EDIT_SCRIPT' => $mailEditScript,
'DEL_ITEM' => $row['mail_id'],
'DISABLED_DEL_ITEM' => ($row['status'] != 'ok') ? ' disabled' : ''
'MAIL_ADDR' => tohtml(decode_idna($mailAddr)),
'MAIL_TYPE' => $mailType,
'MAIL_QUOTA_INFO' => tohtml($mailQuotaInfo),
'MAIL_STATUS' => translate_dmn_status($row['status']),
'MAIL_DELETE' => $mailDelete,
'MAIL_DELETE_SCRIPT' => $mailDeleteScript,
'MAIL_EDIT' => $mailEdit,
'MAIL_EDIT_SCRIPT' => $mailEditScript,
'DEL_ITEM' => $row['mail_id'],
'DISABLED_DEL_ITEM' => ($row['status'] != 'ok') ? ' disabled' : ''
));

_client_generateUserMailAutoRespond($tpl, $row['mail_id'], $row['status'], $row['mail_auto_respond']);
Expand Down Expand Up @@ -251,7 +269,7 @@ function client_generatePage($tpl)
'TR_PAGE_TITLE' => tr('Client / Email / Overview'),
'TR_MAIL' => tr('Mail'),
'TR_TYPE' => tr('Type'),
'TR_QUOTA_ASSIGNMENT' => tr('Quota assignment'),
'TR_QUOTA_INFO' => tr('Quota info'),
'TR_STATUS' => tr('Status'),
'TR_ACTIONS' => tr('Actions'),
'TR_AUTORESPOND' => tr('Auto responder'),
Expand Down
4 changes: 2 additions & 2 deletions gui/themes/default/client/mail_accounts.tpl
Expand Up @@ -64,7 +64,7 @@
<tr>
<th>{TR_MAIL}</th>
<th>{TR_TYPE}</th>
<th>{TR_QUOTA_ASSIGNMENT}</th>
<th>{TR_QUOTA_INFO}</th>
<th>{TR_STATUS}</th>
<th>{TR_ACTIONS}</th>
<th style="width:21px"><label><input type="checkbox"/></label></th>
Expand Down Expand Up @@ -92,7 +92,7 @@
<!-- EDP: auto_respond_item -->
</td>
<td>{MAIL_TYPE}</td>
<td>{MAIL_QUOTA_ASSIGMENT}</td>
<td>{MAIL_QUOTA_INFO}</td>
<td>{MAIL_STATUS}</td>
<td>
<a href="{MAIL_EDIT_SCRIPT}" title="{MAIL_EDIT}" class="icon i_edit">{MAIL_EDIT}</a>
Expand Down

0 comments on commit ea39cec

Please sign in to comment.