From 5fc07ae0c7c13d11747adb7a5388cdd468ca61c0 Mon Sep 17 00:00:00 2001 From: Liam Noonan Date: Sun, 1 Nov 2026 22:55:37 +0000 Subject: [PATCH 1/4] [FIX] mailgate: Set host to gatekeeper Align with new doodba layout. --- mail-testing-config/docker-mailserver/user-patches.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mail-testing-config/docker-mailserver/user-patches.sh b/mail-testing-config/docker-mailserver/user-patches.sh index 462e0dd..db02607 100755 --- a/mail-testing-config/docker-mailserver/user-patches.sh +++ b/mail-testing-config/docker-mailserver/user-patches.sh @@ -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 From b81ffc9cb85f4212f1d9d60bf5852b73c58bbc24 Mon Sep 17 00:00:00 2001 From: Liam Noonan Date: Sun, 1 Nov 2026 23:03:43 +0000 Subject: [PATCH 2/4] [FIX] roundcube: Get rid of texasrulez/persistent_login It seems texasrulez has abandoned this plugin, so I am dropping it. To fill that gap I upped the settion time and had AI create an autologin plugin based on the sample one in the Roundcube repo. https://github.com/roundcube/roundcubemail/blob/master/plugins/autologon/autologon.php It's insecure, of course, but I don't care as this is only used for local dev. Later we'll use it for testing, but even there it will not need to be very secure. Traefik basic auth will suffice. Lastly, I added ROUNDCUBEMAIL_INSTALL_PLUGINS. It seemed to be working just fine without, but it is in the docs and I don't want to think about it any more, so there it is. --- common.yaml | 5 +- devel.yaml | 7 ++- .../config/roundcube_user_settings.inc.php | 3 ++ .../devel_autologon/devel_autologon.php | 53 +++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 mail-testing-config/roundcube/plugins/devel_autologon/devel_autologon.php diff --git a/common.yaml b/common.yaml index 8a41e22..754ac41 100644 --- a/common.yaml +++ b/common.yaml @@ -90,13 +90,14 @@ 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 diff --git a/devel.yaml b/devel.yaml index 6d7709b..c30a904 100644 --- a/devel.yaml +++ b/devel.yaml @@ -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: @@ -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 diff --git a/mail-testing-config/roundcube/config/roundcube_user_settings.inc.php b/mail-testing-config/roundcube/config/roundcube_user_settings.inc.php index 6f418a3..19c23b2 100644 --- a/mail-testing-config/roundcube/config/roundcube_user_settings.inc.php +++ b/mail-testing-config/roundcube/config/roundcube_user_settings.inc.php @@ -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; diff --git a/mail-testing-config/roundcube/plugins/devel_autologon/devel_autologon.php b/mail-testing-config/roundcube/plugins/devel_autologon/devel_autologon.php new file mode 100644 index 0000000..318dbed --- /dev/null +++ b/mail-testing-config/roundcube/plugins/devel_autologon/devel_autologon.php @@ -0,0 +1,53 @@ +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; + } +} From 9c04adfedd9d15f2fbbce364cd9772b7297b3640 Mon Sep 17 00:00:00 2001 From: Liam Noonan Date: Sun, 1 Nov 2026 23:22:05 +0000 Subject: [PATCH 3/4] [IMP] roundcube: Get rid of persistent DB Seemed like it might be nice at first, but I would I didn't really like it. Better to start fresh every time. --- common.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/common.yaml b/common.yaml index 754ac41..53caffa 100644 --- a/common.yaml +++ b/common.yaml @@ -99,7 +99,6 @@ services: - ./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 From 81d74c081ced41a5d8c09a014480ab0c2ac7010f Mon Sep 17 00:00:00 2001 From: Liam Noonan Date: Sun, 1 Nov 2026 23:26:11 +0000 Subject: [PATCH 4/4] [IMP] roundcube: rewrite autocreate_identity plugin The originar was written by gemini code assist and did its job ok, but did not auto pick the first To or Cc address as the reply sender. I do not care much for PHP and this is just a test tool, so this is just the result of just letting Cursor Grok 4.7 High do its thing. I hope I do not have to come back here and ponder the folly of the above statement at a later date. :) --- .../autocreate_identity.php | 111 +++++++++++++----- 1 file changed, 83 insertions(+), 28 deletions(-) diff --git a/mail-testing-config/roundcube/plugins/autocreate_identity/autocreate_identity.php b/mail-testing-config/roundcube/plugins/autocreate_identity/autocreate_identity.php index 59c07a1..98caf39 100644 --- a/mail-testing-config/roundcube/plugins/autocreate_identity/autocreate_identity.php +++ b/mail-testing-config/roundcube/plugins/autocreate_identity/autocreate_identity.php @@ -1,53 +1,108 @@ 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; + } }