Add flexible authentication: email or username can be optional

Key improvements:
- Either email OR username can be empty (but not both)
- Enhanced validation logic for authentication methods
- Improved error messages showing available auth methods
- More flexible IMAPConnection constructor with better defaults

Authentication options:
1. Email-only: SOURCE_EMAIL=user@domain.de, SOURCE_USERNAME=
2. Username-only: SOURCE_EMAIL=, SOURCE_USERNAME=username123
3. Both (fallback): Provide both for automatic fallback
4. Dual method: Username tried first, email as fallback

Configuration updates:
- Update .env.template with all four authentication examples
- Clarify requirements and optional nature of fields
- Add comprehensive authentication scenarios

Documentation updates:
- Expand README with four authentication options
- Add troubleshooting for different auth combinations
- Clarify flexible requirements (either email OR username required)

This makes the script compatible with even more email providers and hosting scenarios.
This commit is contained in:
Elmar Sönser 2025-09-24 14:21:06 +02:00
commit c8ca753c04
3 changed files with 77 additions and 21 deletions

View file

@ -17,12 +17,13 @@ SOURCE_IMAP_SERVER=wp123456.mail.server-he.de
SOURCE_IMAP_PORT=993
# SOURCE_EMAIL: Your source email address
# Required if SOURCE_USERNAME is empty, optional if username is provided
# Example: user@yourdomain.de
SOURCE_EMAIL=user@example-domain.de
# SOURCE_USERNAME: Login username (if different from email)
# SOURCE_USERNAME: Login username (alternative to email)
# Required if SOURCE_EMAIL is empty, optional if email is provided
# Some providers use separate username for login (e.g. hosteurope123, mail_user)
# Leave empty if login uses email address
# Host Europe: often uses email account name or specific username
SOURCE_USERNAME=
@ -47,12 +48,13 @@ DEST_IMAP_SERVER=mail.securehost.de
DEST_IMAP_PORT=993
# DEST_EMAIL: Your destination email address
# Required if DEST_USERNAME is empty, optional if username is provided
# Example: user@securehost.de
DEST_EMAIL=user@securehost.de
# DEST_USERNAME: Login username for destination (if different from email)
# DEST_USERNAME: Login username for destination (alternative to email)
# Required if DEST_EMAIL is empty, optional if email is provided
# Some hosting providers use separate username (e.g. user123, cpanel_user)
# Leave empty if login uses email address
# Securehost.de: typically uses email or specific username
DEST_USERNAME=
@ -129,16 +131,26 @@ TEMP_DOWNLOAD_DIR=./temp_emails
# AUTHENTICATION EXAMPLES
# ============================================================================
# Email-based login (most common):
# Option 1: Email-based login (most common):
# SOURCE_EMAIL=user@domain.de
# SOURCE_USERNAME=
# → Script tries: user@domain.de
# Username-based login:
# Option 2: Username-based login:
# SOURCE_EMAIL=user@domain.de
# SOURCE_USERNAME=mail_user123
# → Script tries: mail_user123, fallback to user@domain.de
# Option 3: Username-only (email optional):
# SOURCE_EMAIL=
# SOURCE_USERNAME=mail_user123
# → Script tries: mail_user123 only
# Option 4: Email-only (username optional):
# SOURCE_EMAIL=user@domain.de
# SOURCE_USERNAME=
# → Script tries: user@domain.de only
# Host Europe specific:
# SOURCE_USERNAME=email_account_name (from Host Europe KIS)
# SOURCE_USERNAME= (if using Easy-Mail-Login)