feat: add compat for gmail
All checks were successful
perso/offlineimap/pipeline/head This commit looks good

This commit is contained in:
Julien Cabillot
2026-03-18 21:03:08 -04:00
parent 7baa12cf52
commit 379ad22d7b
4 changed files with 42 additions and 6 deletions

View File

@@ -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"

View File

@@ -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"

18
offlineimaprc.gmail.tmpl Normal file
View File

@@ -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

View File

@@ -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