95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Email Configuration Plugin
|
|
* Opens external email config interface with signed authentication
|
|
*/
|
|
class email_config extends rcube_plugin
|
|
{
|
|
public $task = 'settings|mail';
|
|
private $secret_key = 'SHARED_SECRET_KEY_987654321';
|
|
private $config_url = 'http://localhost:3009';
|
|
|
|
function init()
|
|
{
|
|
// Register actions
|
|
$this->register_action('plugin.email_config', array($this, 'email_config_init'));
|
|
$this->register_action('plugin.email_config_generate_url', array($this, 'generate_signed_url'));
|
|
|
|
// Add button to toolbar in mail view
|
|
if ($this->rcmail->task == 'mail') {
|
|
$this->add_button(array(
|
|
'command' => 'email_config_open',
|
|
'label' => 'Email Config',
|
|
'title' => 'Configure auto-reply and forwarding',
|
|
'type' => 'link',
|
|
'class' => 'button email-config',
|
|
), 'toolbar');
|
|
|
|
$this->include_script('email_config.js');
|
|
}
|
|
|
|
// Add to settings menu
|
|
if ($this->rcmail->task == 'settings') {
|
|
$this->add_hook('settings_actions', array($this, 'settings_actions'));
|
|
}
|
|
}
|
|
|
|
function settings_actions($args)
|
|
{
|
|
$args['actions'][] = array(
|
|
'action' => 'plugin.email_config',
|
|
'class' => 'email-config',
|
|
'label' => 'Email Configuration',
|
|
'title' => 'Configure email rules',
|
|
);
|
|
return $args;
|
|
}
|
|
|
|
function email_config_init()
|
|
{
|
|
$this->register_handler('plugin.body', array($this, 'email_config_form'));
|
|
$this->rcmail->output->set_pagetitle('Email Configuration');
|
|
$this->rcmail->output->send('plugin');
|
|
}
|
|
|
|
function email_config_form()
|
|
{
|
|
$email = $this->rcmail->user->get_username();
|
|
$url = $this->generate_url($email);
|
|
|
|
$out = html::div(array('class' => 'box'),
|
|
html::p(null, 'Manage your email configuration including out-of-office auto-replies and forwarding rules.') .
|
|
html::p(null,
|
|
html::a(array(
|
|
'href' => $url,
|
|
'target' => '_blank',
|
|
'class' => 'button mainaction',
|
|
), 'Open Email Configuration')
|
|
)
|
|
);
|
|
|
|
return $out;
|
|
}
|
|
|
|
function generate_signed_url()
|
|
{
|
|
$email = $this->rcmail->user->get_username();
|
|
$url = $this->generate_url($email);
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode(array('success' => true, 'url' => $url));
|
|
exit;
|
|
}
|
|
|
|
private function generate_url($email)
|
|
{
|
|
$expires = time() + 3600; // 1 hour validity
|
|
$data = $email . '|' . $expires;
|
|
$signature = hash_hmac('sha256', $data, $this->secret_key);
|
|
|
|
return $this->config_url . '/?email=' . urlencode($email)
|
|
. '&expires=' . $expires
|
|
. '&signature=' . $signature;
|
|
}
|
|
}
|