Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ services:
image: roundcube/roundcubemail
environment:
ROUNDCUBEMAIL_DB_TYPE: sqlite
ROUNDCUBEMAIL_COMPOSER_PLUGINS: "texxasrulez/persistent_login"
ROUNDCUBEMAIL_PLUGINS: "show_additional_headers,persistent_login,autocreate_identity"
ROUNDCUBEMAIL_PLUGINS: "show_additional_headers,autocreate_identity,devel_autologon"
ROUNDCUBEMAIL_INSTALL_PLUGINS: 1
depends_on:
- mailserver
volumes:
- ./mail-testing-config/roundcube/config/roundcube_user_settings.inc.php:/var/roundcube/config/config.inc.php:ro
- ./mail-testing-config/roundcube/plugins/autocreate_identity:/var/www/html/plugins/autocreate_identity
- ./mail-testing-config/roundcube/plugins/devel_autologon:/var/www/html/plugins/devel_autologon
- roundcube:/var/www/html:rw
- roundcube_db:/var/roundcube/db:rw

smtpreal:
image: ghcr.io/docker-mailserver/docker-mailserver:latest
Expand Down
7 changes: 5 additions & 2 deletions devel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ services:
ODOO_USER_ID: 2
MAILGATE_SMTP_PORT: "13525"
MAILBOX_DOMAIN: *mailserver
MAILBOX_USER: admin
ADMIN_PASSWORD: admin
MAILBOX_USER: &mailbox_user admin
ADMIN_PASSWORD: &mailbox_password admin
SMTP_SERVICE_NAME: smtp

roundcube:
Expand All @@ -150,6 +150,9 @@ services:
ROUNDCUBEMAIL_DEFAULT_HOST: *mailserver
ROUNDCUBEMAIL_SMTP_SERVER: *mailserver
ROUNDCUBEMAIL_SMTP_PORT: 13525
MAILBOX_USER: *mailbox_user
MAILBOX_DOMAIN: *mailserver
ADMIN_PASSWORD: *mailbox_password

wdb:
image: docker.io/kozea/wdb
Expand Down
2 changes: 1 addition & 1 deletion mail-testing-config/docker-mailserver/user-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ try:
"-d", DB,
"-u", USER,
"-p", PASSWORD,
"--host", "odoo",
"--host", "gatekeeper",
"--port", "8069",
]
return_code = subprocess.run(cmd, stdin=sys.stdin.buffer).returncode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
// https://github.com/roundcube/roundcubemail-docker/blob/9fd84b3e4f7943c7b2046d0a443a39d1a702edf2/fpm/docker-entrypoint.sh#L177-#L188
$config['smtp_user'] = '';
$config['smtp_pass'] = '';

// Session lifetime of 30 days (in minutes).
$config['session_lifetime'] = 43200;
Original file line number Diff line number Diff line change
@@ -1,53 +1,108 @@
<?php

/**
* To and Cc addresses become identities when a message is opened.
* Reply and reply-all send as the first To address, or the first Cc
* address when To has none.
*/
class autocreate_identity extends rcube_plugin
{
public $task = 'mail';

function init()
public function init()
{
$this->add_hook('message_load', array($this, 'create_identity_from_message'));
$this->add_hook('message_load', [$this, 'create_identities']);
$this->add_hook('identity_select', [$this, 'select_reply_identity']);
}

function create_identity_from_message($args)
public function create_identities($args)
{
// Only process if we have headers and it's a message object
if (!isset($args['object']) || !isset($args['object']->headers)) {
$user = rcmail::get_instance()->user;
$headers = isset($args['object']->headers) ? $args['object']->headers : null;
if (!$user || !$headers) {
return $args;
}

$rcmail = rcmail::get_instance();
$user = $rcmail->user;

// Get existing identities
$existing_emails = array();
$known = [];
foreach ($user->list_identities() as $identity) {
$existing_emails[] = strtolower($identity['email']);
$known[strtolower($identity['email'])] = true;
}

// Get To and Cc addresses
$recipients = array();
if (!empty($args['object']->headers->to)) {
$recipients = array_merge($recipients, rcube_mime::decode_address_list($args['object']->headers->to));
foreach ($this->recipients($headers) as $recipient) {
$email = strtolower($recipient['email']);
if (isset($known[$email])) {
continue;
}

$inserted = $user->insert_identity([
'name' => $recipient['name'],
'email' => $recipient['email'],
'standard' => 0,
'signature' => '',
'html_signature' => 0,
]);
if ($inserted) {
$known[$email] = true;
}
}
if (!empty($args['object']->headers->cc)) {
$recipients = array_merge($recipients, rcube_mime::decode_address_list($args['object']->headers->cc));

return $args;
}

public function select_reply_identity($args)
{
$output = rcmail::get_instance()->output;
if (!$output || $output->get_env('compose_mode') !== 'reply' || empty($args['identities'])) {
return $args;
}

foreach ($recipients as $recipient) {
$email = $recipient['mailto'];
if (!in_array(strtolower($email), $existing_emails)) {
$user->insert_identity(array(
'name' => $recipient['name'] ?: '',
'email' => $email,
'standard' => 0,
'signature' => '',
'html_signature' => 0
));
$existing_emails[] = strtolower($email);
$headers = isset($args['message']->headers) ? $args['message']->headers : null;
if (!$headers) {
return $args;
}

$recipients = $this->recipients($headers);
if (!$recipients) {
return $args;
}

$target = strtolower($recipients[0]['email']);
foreach ($args['identities'] as $idx => $identity) {
$email = strtolower($identity['email_ascii'] ?? $identity['email']);
if ($email === $target) {
$args['selected'] = $idx;
return $args;
}
}

return $args;
}

/**
* To addresses first, then Cc. Entries without an address are skipped,
* so the first item is the reply sender.
*/
private function recipients($headers)
{
$recipients = [];
$charset = $headers->charset ?? null;

foreach (['to', 'cc'] as $header) {
if (empty($headers->$header)) {
continue;
}
foreach (rcube_mime::decode_address_list($headers->$header, null, true, $charset) as $address) {
$email = $address['mailto'] ?? '';
if (!str_contains($email, '@')) {
continue;
}
$recipients[] = [
'email' => $email,
'name' => (string) ($address['name'] ?? ''),
];
}
}

return $recipients;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Sign in to the local devel mailbox whenever Roundcube has no session.
*
* Adapted from Roundcube's sample autologon plugin. The sample only runs
* from 127.0.0.1 with ?_autologin=1 and fixed sample credentials, which
* never matches this container. Credentials default to the devel mailbox
* and can be overridden with MAILBOX_USER, MAILBOX_DOMAIN, and ADMIN_PASSWORD.
*/
class devel_autologon extends rcube_plugin
{
public $task = 'login';

public function init()
{
$this->add_hook('startup', [$this, 'startup']);
$this->add_hook('authenticate', [$this, 'authenticate']);
}

/**
* Turn an anonymous request into a login so the form is never shown.
* A live session, including logout, is left alone; the next request logs in.
*/
public function startup($args)
{
if (empty($_SESSION['user_id'])) {
$args['task'] = 'login';
$args['action'] = 'login';
}

return $args;
}

/**
* Supply the devel mailbox. valid skips the CSRF token the login form
* would have posted; cookiecheck is skipped because this request has
* not received a session cookie yet.
*/
public function authenticate($args)
{
$user = getenv('MAILBOX_USER') ?: 'admin';
$domain = getenv('MAILBOX_DOMAIN') ?: 'mailserver';
$password = getenv('ADMIN_PASSWORD') ?: 'admin';

$args['user'] = $user . '@' . $domain;
$args['pass'] = $password;
$args['cookiecheck'] = false;
$args['valid'] = true;

return $args;
}
}
Loading