Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpieters committed Jun 4, 2024
0 parents commit 9323f07
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IMAP_HOST=mail.example.com
SMTP_HOST=mail.example.com
IMAP_SSL=true
42 changes: 42 additions & 0 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create and publish a Docker image

on:
push:
tags:
- v*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
docker-compose.override.yml
.env
.env.*
!.env.example
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM caddy:2.8.4-alpine AS caddy

FROM php:8.3-fpm-alpine

RUN apk update && apk add supervisor

COPY --from=caddy /usr/bin/caddy /usr/bin/caddy

# Configure supervisor
RUN mkdir -p /etc/supervisor.d/
COPY ./docker/supervisord.ini /etc/supervisor.d/supervisord.ini

# Configure Caddy web server
COPY ./docker/Caddyfile /etc/caddy/Caddyfile

# Configure PHP-FPM
RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini

WORKDIR /src
COPY ./src /var/www/html

EXPOSE 80
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor.d/supervisord.ini"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Autodiscover

IMAP/SMTP autodiscover for email clients.
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
autodiscover:
build: .
ports:
- "8000:80"
env_file:
- .env
4 changes: 4 additions & 0 deletions docker/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:80 {
root * /var/www/html
php_fastcgi localhost:9000
}
16 changes: 16 additions & 0 deletions docker/supervisord.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[supervisord]
nodaemon=true

[program:caddy]
command=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
40 changes: 40 additions & 0 deletions src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

header('Content-Type: application/xml');
$raw = file_get_contents('php://input');
$imap_server = getenv('IMAP_HOST');
$imap_ssl = getenv('IMAP_SSL');
$smtp_server = getenv('SMTP_HOST');

$matches = array();
preg_match('/<EMailAddress>(.*)<\/EMailAddress>/', $raw, $matches);
?>
<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<Account>
<AccountType>email</AccountType>
<Action>settings</Action>
<Protocol>
<Type>IMAP</Type>
<Server><?= $imap_server ?></Server>
<Port>993</Port>
<DomainRequired>off</DomainRequired><?= (empty($matches)) ? "\n" : PHP_EOL . "<LoginName>" . $matches[1] . "</LoginName>" ?>
<SPA>on</SPA>
<SSL><?= $imap_ssl == true ? "on" : "off" ?></SSL>
<AuthRequired>on</AuthRequired>
</Protocol>
<Protocol>
<Type>SMTP</Type>
<Server><?= $smtp_server ?></Server>
<Port>587</Port>
<DomainRequired>off</DomainRequired><?= (empty($matches)) ? "\n" : PHP_EOL . "<LoginName>" . $matches[1] . "</LoginName>" ?>
<SPA>off</SPA>
<Encryption>off</Encryption>
<AuthRequired>on</AuthRequired>
<UsePOPAuth>off</UsePOPAuth>
<SMTPLast>off</SMTPLast>
</Protocol>
</Account>
</Response>
</Autodiscover>

0 comments on commit 9323f07

Please sign in to comment.