diff --git a/Dockerfile b/Dockerfile index 934af95..aec0537 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apk add --no-cache offlineimap openssl && \ # Force SECLEVEL=1 in imaplib2 to allow connecting to servers with weak DH keys (DH_KEY_TOO_SMALL) # This is required because OpenSSL 3.x in Alpine 3.23 defaults to SECLEVEL=2 sed -i 's/ctx = ssl.SSLContext(ssl_version)/ctx = ssl.SSLContext(ssl_version)\n ctx.set_ciphers("DEFAULT:@SECLEVEL=1")/' /usr/lib/python3.*/site-packages/imaplib2/imaplib2.py -COPY --chown=offlineimap offlineimaprc /home/offlineimap/.offlineimaprc +COPY --chown=offlineimap offlineimaprc.*.tmpl /home/offlineimap/ # Add Tini #ENV "TINI_VERSION" "v0.16.1" diff --git a/entrypoint.sh b/entrypoint.sh index 3044ddf..15d9d15 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,9 +2,27 @@ set -o pipefail -o nounset -o errexit -# Récupère le fingerprint SHA1 du certificat fourni par le serveur -IMAP_CERT="$(echo | (openssl s_client -connect "${IMAP_SRV}:993" 2>/dev/null || true) | openssl x509 -fingerprint -sha1 -noout | cut -d'=' -f2 | sed 's/://g')" +CONFIG_FILE="/home/offlineimap/.offlineimaprc" -sed -i'' "s/XXX_REPLACE_USER_XXX/${IMAP_USER}/g;s/XXX_REPLACE_PASS_XXX/${IMAP_PASS}/g;s/XXX_REPLACE_SRV_XXX/${IMAP_SRV}/g;s/XXX_REPLACE_FINGERPRINT_XXX/${IMAP_CERT}/g" "/home/offlineimap/.offlineimaprc" +if [ -n "${GMAIL_USER:-}" ]; then + echo "Using Gmail configuration mode..." + cp "/home/offlineimap/offlineimaprc.gmail.tmpl" "$CONFIG_FILE" + + # Gmail IMAP server + IMAP_SRV="imap.gmail.com" + + # Récupère le fingerprint SHA1 du certificat + IMAP_CERT="$(echo | (openssl s_client -connect "${IMAP_SRV}:993" 2>/dev/null || true) | openssl x509 -fingerprint -sha1 -noout | cut -d'=' -f2 | sed 's/://g')" + + sed -i "s|XXX_REPLACE_USER_XXX|${GMAIL_USER}|g;s|XXX_REPLACE_PASS_XXX|${GMAIL_PASS}|g;s|XXX_REPLACE_FINGERPRINT_XXX|${IMAP_CERT:-}|g" "$CONFIG_FILE" +else + echo "Using standard IMAP configuration mode..." + cp "/home/offlineimap/offlineimaprc.imap.tmpl" "$CONFIG_FILE" + + # Récupère le fingerprint SHA1 du certificat fourni par le serveur + IMAP_CERT="$(echo | (openssl s_client -connect "${IMAP_SRV}:993" 2>/dev/null || true) | openssl x509 -fingerprint -sha1 -noout | cut -d'=' -f2 | sed 's/://g')" + + sed -i "s|XXX_REPLACE_USER_XXX|${IMAP_USER}|g;s|XXX_REPLACE_PASS_XXX|${IMAP_PASS}|g;s|XXX_REPLACE_SRV_XXX|${IMAP_SRV}|g;s|XXX_REPLACE_FINGERPRINT_XXX|${IMAP_CERT:-}|g" "$CONFIG_FILE" +fi -exec offlineimap -c "/home/offlineimap/.offlineimaprc" +exec offlineimap -c "$CONFIG_FILE" diff --git a/offlineimaprc.gmail.tmpl b/offlineimaprc.gmail.tmpl new file mode 100644 index 0000000..42507ec --- /dev/null +++ b/offlineimaprc.gmail.tmpl @@ -0,0 +1,18 @@ +[general] +accounts = main + +[Account main] +localrepository = main-local +remoterepository = main-remote +synclabels = yes + +[Repository main-local] +type = GmailMaildir +localfolders = /dump + +[Repository main-remote] +type = Gmail +remoteuser = XXX_REPLACE_USER_XXX +remotepass = XXX_REPLACE_PASS_XXX +cert_fingerprint = XXX_REPLACE_FINGERPRINT_XXX +readonly = true diff --git a/offlineimaprc b/offlineimaprc.imap.tmpl similarity index 96% rename from offlineimaprc rename to offlineimaprc.imap.tmpl index eab71c4..b0afec4 100644 --- a/offlineimaprc +++ b/offlineimaprc.imap.tmpl @@ -17,4 +17,4 @@ remotepass = XXX_REPLACE_PASS_XXX remotehost = XXX_REPLACE_SRV_XXX cert_fingerprint = XXX_REPLACE_FINGERPRINT_XXX ssl_version = tls1_2 -readonly=true +readonly = true