Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into patch-purge-days
Browse files Browse the repository at this point in the history
  • Loading branch information
helmo committed Apr 3, 2024
2 parents 78ff6b2 + f8a6a47 commit f2d94e8
Show file tree
Hide file tree
Showing 79 changed files with 1,746 additions and 709 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

[*.{css, inc, js, php, sh}]
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: tests

on: [push, pull_request, workflow_dispatch]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=-1, display_errors=On, zend.assertions=1
coverage: none
tools: cs2pr, phpcs

- name: Lint PHP files
run: find . -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

198 changes: 92 additions & 106 deletions ispconfig3_account/ispconfig3_account.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

class ispconfig3_account extends rcube_plugin
{
public $task = 'settings';
private $rcmail;
private $rc;

private $soap;
private $mail_user;
private $aliases;

const ISPCONFIG_PLUGINS = [ 'account', 'pass', 'fetchmail', 'forward', 'autoreply', 'filter', 'wblist', 'spam' ];

function init()
{
Expand All @@ -17,48 +23,48 @@ function init()
$this->load_config('config/config.inc.php');
}

$this->register_action('plugin.ispconfig3_account', array($this, 'init_html'));
$this->register_action('plugin.ispconfig3_account.show', array($this, 'init_html'));
$this->register_action('plugin.ispconfig3_account', [$this, 'init_html']);
$this->register_action('plugin.ispconfig3_account.show', [$this, 'init_html']);

$this->add_hook('settings_actions', array($this, 'settings_actions'));
$this->add_hook('template_object_identityform', array($this, 'template_object_identityform'));
$this->add_hook('settings_actions', [$this, 'settings_actions']);
if ($this->rcmail->config->get('identity_limit') === true) {
$this->add_hook('template_object_identityform', [$this, 'template_object_identityform']);
}

$this->include_script('account.js');
$this->include_stylesheet($this->local_skin_path() . '/account.css');

if (strpos($this->rcmail->action, 'plugin.ispconfig3_account') === 0 ||
($this->rcmail->config->get('identity_limit') === true &&
(strpos($this->rcmail->action, 'edit-identity') === 0 ||
strpos($this->rcmail->action, 'add-identity') === 0))) {
strpos($this->rcmail->action, 'add-identity') === 0 ||
strpos($this->rcmail->action, 'save-identity') === 0))) {

$this->soap = new SoapClient(null, array(
$this->soap = new SoapClient(null, [
'location' => $this->rcmail->config->get('soap_url') . 'index.php',
'uri' => $this->rcmail->config->get('soap_url'),
$this->rcmail->config->get('soap_validate_cert') ?:
'stream_context' => stream_context_create(
array('ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
))
));
'stream_context' => stream_context_create(['ssl' => [
'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true
]])
]);
}
}

/**
* Handler for settings_actions hook.
* Adds ispconfig3_account settings section into preferences.
*/
* Handler for settings_actions hook.
*
* Adds ispconfig3_account settings section into preferences.
*/
function settings_actions($args)
{
$args['actions'][] = array(
$args['actions'][] = [
'action' => 'plugin.ispconfig3_account',
'class' => 'account',
'label' => 'acc_acc',
'title' => 'acc_acc',
'domain' => 'ispconfig3_account',
);
];

return $args;
}
Expand All @@ -68,60 +74,48 @@ function init_html()
$this->api->output->set_pagetitle($this->gettext('acc_acc'));
if (rcmail::get_instance()->action == 'plugin.ispconfig3_account.show') {
// General account info
$this->api->output->add_handler('info', array($this, 'gen_form'));
$this->api->output->add_handler('sectionname_acc', array($this, 'prefs_section_name'));
$this->api->output->add_handler('info', [$this, 'gen_form']);
$this->api->output->add_handler('sectionname_acc', [$this, 'prefs_section_name']);
$this->api->output->send('ispconfig3_account.general');
}
else {
// Plugin overview
$this->api->output->add_handler('accountlist', array($this, 'accountlist'));
$this->api->output->add_handler('accountframe', array($this, 'accountframe'));
$this->api->output->add_handler('accountlist', [$this, 'accountlist']);
$this->api->output->add_handler('accountframe', [$this, 'accountframe']);
$this->api->output->send('ispconfig3_account.account');
}
}

/**
* Handler for identity_form hook.
*
* Replaces the text input field for an email address with a select dropdown (Identities -> Edit).
*/
function template_object_identityform($args)
{
if ($this->rcmail->config->get('identity_limit') === true) {
$emails = new html_select(array('name' => '_email', 'id' => 'rcmfd_email', 'class' => 'ff_email'));
try {
$session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass'));
$mail_user = $this->soap->mail_user_get($session_id, array('login' => $this->rcmail->user->data['username']));
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
if (empty($mail_user)) {
$mail_user = $this->soap->mail_user_get($session_id, array('email' => $this->rcmail->user->data['username']));
}

$alias = $this->soap->mail_alias_get($session_id, array('destination' => $mail_user[0]['email'], 'type' => 'alias', 'active' => 'y'));
$this->soap->logout($session_id);

$emails->add($mail_user[0]['email'], $mail_user[0]['email']);
for ($i = 0; $i < count($alias); $i++) {
$emails->add($alias[$i]['source'], $alias[$i]['source']);
}
}
catch (SoapFault $e) {
$error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage();
$this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error');
}
$emails = new html_select(['name' => '_email', 'id' => 'rcmfd_email', 'class' => 'ff_email']);

$email_pattern = '/<input type=\"text\" size=\"40\" id=\"rcmfd_email\" name=\"_email\" class=\"ff_email\"(?: value=\"(.*)\")?>/';
preg_match($email_pattern, $args['content'], $test);
$email = isset($test[1]) ? $test[1] : '';
$args['content'] = preg_replace($email_pattern, $emails->show($email), $args['content']);
$this->remoteGetUserAndAliases();
if ($this->mail_user) {
$emails->add($this->mail_user[0]['email'], $this->mail_user[0]['email']);
}
foreach ((array) $this->aliases as $alias) {
$emails->add($alias['source'], $alias['source']);
}

$email_pattern = '/<input type=\"text\" size=\"40\" id=\"rcmfd_email\" name=\"_email\" class=\"ff_email\"(?: value=\"(.*)\")?>/U';
preg_match($email_pattern, $args['content'], $test);
$email = $test[1] ?? '';
$args['content'] = preg_replace($email_pattern, $emails->show($email), $args['content']);

return $args;
}

function accountframe($attrib)
{
if (!$attrib['id'])
if (empty($attrib['id'])) {
$attrib['id'] = 'rcmaccountframe';
}

$attrib['name'] = $attrib['id'];

Expand All @@ -133,47 +127,25 @@ function accountframe($attrib)

function accountlist($attrib)
{
if (!$attrib['id'])
if (empty($attrib['id'])) {
$attrib['id'] = 'rcmaccountlist';

$sectionavail = array('general' => array('id' => 'general', 'section' => $this->gettext('acc_general')),
'pass' => array('id' => 'pass', 'section' => $this->gettext('acc_pass')),
'fetchmail' => array('id' => 'fetchmail', 'section' => $this->gettext('acc_fetchmail')),
'forward' => array('id' => 'forward', 'section' => $this->gettext('acc_forward')),
'autoreply' => array('id' => 'autoreply', 'section' => $this->gettext('acc_autoreply')),
'filter' => array('id' => 'filter', 'section' => $this->gettext('acc_filter')),
'wblist' => array('id' => 'wblist', 'section' => $this->gettext('acc_wblist')),
'spam' => array('id' => 'spam', 'section' => $this->gettext('acc_spam')));

$array = array('general');
$plugins = $this->rcmail->config->get('plugins');
$plugins = array_flip($plugins);
if (isset($plugins['ispconfig3_pass']))
$array[] = 'pass';
if (isset($plugins['ispconfig3_fetchmail']))
$array[] = 'fetchmail';
if (isset($plugins['ispconfig3_forward']))
$array[] = 'forward';
if (isset($plugins['ispconfig3_autoreply']))
$array[] = 'autoreply';
if (isset($plugins['ispconfig3_filter']))
$array[] = 'filter';
if (isset($plugins['ispconfig3_wblist']))
$array[] = 'wblist';
if (isset($plugins['ispconfig3_spam']))
$array[] = 'spam';

$blocks = $array;
if (isset($attrib['sections'])) {
$quotes_stripped = str_replace(array("'", '"'), '', $attrib['sections']);
$blocks = preg_split('/[\s,;]+/', $quotes_stripped);
}
$sections = array();
foreach ($blocks as $block) {
$sections[$block] = $sectionavail[$block];

$rc_plugins = $this->rcmail->config->get('plugins');
$rc_plugins = array_flip($rc_plugins);

$sections = [];
foreach ($this::ISPCONFIG_PLUGINS as $plugin) {
if (isset($rc_plugins['ispconfig3_' . $plugin])) {
if ($plugin == 'account') {
$plugin = 'general';
}

$sections[$plugin] = ['id' => $plugin, 'section' => $this->gettext('acc_' . $plugin)];
}
}

$out = $this->rc->table_output($attrib, $sections, array('section'), 'id');
$out = $this->rc->table_output($attrib, $sections, ['section'], 'id');
$this->rcmail->output->add_gui_object('accountlist', $attrib['id']);
$this->rcmail->output->include_script('list.js');

Expand All @@ -187,50 +159,64 @@ function prefs_section_name()

function gen_form()
{
$out = '<form class="propform"><fieldset><legend>' . $this->gettext('acc_general') . '</legend>' . "\n";
// General
$out = '<fieldset><legend>' . $this->gettext('acc_general') . '</legend>' . "\n";
$table = new html_table(['cols' => 2, 'cellpadding' => 3, 'class' => 'propform']);

$table = new html_table(array('cols' => 2, 'cellpadding' => 3, 'class' => 'propform'));
$table->add('title', rcube::Q($this->gettext('username')));
$table->add('', rcube::Q($this->rcmail->user->data['username']));

$table->add('title', rcube::Q($this->gettext('server')));
$table->add('', rcube::Q($this->rcmail->user->data['mail_host']));

$table->add('title', rcube::Q($this->gettext('acc_lastlogin')));
$table->add('', rcube::Q($this->rcmail->format_date($this->rcmail->user->data['last_login'])));

$identity = $this->rcmail->user->get_identity();
$table->add('title', rcube::Q($this->gettext('acc_defaultidentity')));
$table->add('', rcube::Q($identity['name'] . ' <' . $identity['email'] . '>'));

$out .= $table->show();
$out .= "</fieldset>\n";

// Linked email address(es)
$out .= '<fieldset><legend>' . $this->gettext('acc_alias') . '</legend>' . "\n";
$alias_table = new html_table(['id' => 'alias-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 1]);
$alias_table->add_header(['width' => '100%'], $this->gettext('mail'));

$alias_table = new html_table(array('id' => 'alias-table', 'class' => 'records-table', 'cellspacing' => '0', 'cols' => 1));
$alias_table->add_header(array('width' => '100%'), $this->gettext('mail'));
$this->remoteGetUserAndAliases();
if ($this->mail_user) {
$alias_table->add('', $this->mail_user[0]['email']);
}
foreach ((array) $this->aliases as $alias) {
$alias_table->add('', $alias['source']);
}

$out .= "<div id=\"alias-cont\">" . $alias_table->show() . "</div>\n";
$out .= "</fieldset>\n";

return $out;
}

private function remoteGetUserAndAliases()
{
try {
$session_id = $this->soap->login($this->rcmail->config->get('remote_soap_user'), $this->rcmail->config->get('remote_soap_pass'));
$mail_user = $this->soap->mail_user_get($session_id, array('login' => $this->rcmail->user->data['username']));
// Alternatively also search the email field, this can differ from the login field for legacy reasons.
if (empty($mail_user)) {
$mail_user = $this->soap->mail_user_get($session_id, array('email' => $this->rcmail->user->data['username']));

$this->mail_user = $this->soap->mail_user_get($session_id, ['login' => $this->rcmail->user->data['username']]);
// Alternatively also search the email field, this can differ from the login field for legacy reasons
if (empty($this->mail_user)) {
$this->mail_user = $this->soap->mail_user_get($session_id, ['email' => $this->rcmail->user->data['username']]);
}

$alias = $this->soap->mail_alias_get($session_id, array('destination' => $mail_user[0]['email'], 'type' => 'alias', 'active' => 'y'));
$this->soap->logout($session_id);
$this->aliases = $this->soap->mail_alias_get($session_id,
['destination' => $this->mail_user[0]['email'], 'type' => 'alias', 'active' => 'y']);

$alias_table->add('', $mail_user[0]['email']);
for ($i = 0; $i < count($alias); $i++) {
$alias_table->add('', $alias[$i]['source']);
}
$this->soap->logout($session_id);
}
catch (SoapFault $e) {
$error = $this->rc->text_exists($e->getMessage(), $this->ID) ? $this->gettext($e->getMessage()) : $e->getMessage();
$this->rcmail->output->command('display_message', 'Soap Error: ' . $error, 'error');
}

$out .= "<div id=\"alias-cont\">" . $alias_table->show() . "</div>\n";
$out .= "</fieldset></form>\n";

return $out;
}
}
14 changes: 14 additions & 0 deletions ispconfig3_account/localization/sk_SK.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$labels['acc_acc'] = 'Nastavenia e-mail účtu';
$labels['acc_alias'] = 'E-mail alias(y)';
$labels['acc_general'] = 'Informácie o e-mail účte používateľa';
$labels['acc_pass'] = 'Zmena hesla';
$labels['acc_forward'] = 'Preposielanie e-mailov';
$labels['acc_fetchmail'] = 'Preberanie e-mailov';
$labels['acc_autoreply'] = 'Automatická odpoveď';
$labels['acc_filter'] = 'Mailový filter';
$labels['acc_spam'] = 'Ochrana proti spamu';
$labels['acc_wblist'] = 'Čierna/Biela listina';
$labels['acc_lastlogin'] = 'Posledné prihlásenie';
$labels['acc_defaultidentity'] = 'Hlavný e-mail';
$labels['acc_noalias'] = 'Žiadne e-mail alias(y)';
13 changes: 13 additions & 0 deletions ispconfig3_account/localization/tr_TR.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
$labels['acc_acc'] = 'Hesap';
$labels['acc_alias'] = 'Bağlı E-Posta adres(ler)i';
$labels['acc_general'] = 'Genel';
$labels['acc_pass'] = 'Parola';
$labels['acc_forward'] = 'Yönlendirme';
$labels['acc_fetchmail'] = 'Mail Alma';
$labels['acc_autoreply'] = 'Otomatik Yanıt';
$labels['acc_filter'] = 'Posta Filtresi';
$labels['acc_wblist'] = 'Kara/Beyaz Liste';
$labels['acc_lastlogin'] = 'Son Giriş Zamanı';
$labels['acc_defaultidentity'] = 'Varsayılan Kimlik';
$labels['acc_noalias'] = 'Bağlı E-Posta adres(ler)i bulunamadı';
6 changes: 4 additions & 2 deletions ispconfig3_account/skins/classic/templates/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
<script type="text/javascript" src="/functions.js"></script>
</head>
<body class="iframe">

<div id="prefs-title" class="boxtitle">
<roundcube:object name="sectionname_acc" />
</div>

<div id="prefs-details" class="boxcontent">
<roundcube:object name="info" />
</div>
</body>
</html>

</body>
</html>
Loading

0 comments on commit f2d94e8

Please sign in to comment.