Merge remote-tracking branch 'origin/main' into fix/issue-5-watcher-uid-tracking
This commit is contained in:
@@ -265,6 +265,15 @@ def resolve_account(accounts: list[dict], account_id: str) -> dict:
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# RFC 2971 IMAP ID — required by some providers (e.g. netease 163.com / 126.com / yeah.net)
|
||||||
|
# which reject clients that don't identify themselves after login.
|
||||||
|
_IMAP_CLIENT_ID = {
|
||||||
|
"name": "poke-mail",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"vendor": "Poke Interactions",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_imap_client(account: dict) -> IMAPClient:
|
def get_imap_client(account: dict) -> IMAPClient:
|
||||||
port = account["imap_port"]
|
port = account["imap_port"]
|
||||||
use_ssl = port == 993
|
use_ssl = port == 993
|
||||||
@@ -272,6 +281,13 @@ def get_imap_client(account: dict) -> IMAPClient:
|
|||||||
if not use_ssl:
|
if not use_ssl:
|
||||||
client.starttls()
|
client.starttls()
|
||||||
client.login(account["imap_username"], account["imap_password"])
|
client.login(account["imap_username"], account["imap_password"])
|
||||||
|
# Send IMAP ID if the server supports it. Non-fatal: not all servers do,
|
||||||
|
# and we never want this to break an otherwise-working login.
|
||||||
|
try:
|
||||||
|
if client.has_capability("ID"):
|
||||||
|
client.id_(_IMAP_CLIENT_ID)
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug("IMAP ID command failed for %s: %s", account.get("id"), e)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -207,10 +207,23 @@ PYEOF
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 4. MCP_API_KEY — generate once and persist to .env
|
# ── Load .env early so POKE_TUNNEL is visible to the MCP_API_KEY logic below ──
|
||||||
if [ ! -f .env ] \
|
if [ -f .env ]; then
|
||||||
|
set -a
|
||||||
|
source .env
|
||||||
|
set +a
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tunnel-mode detection must happen BEFORE the MCP_API_KEY block: in tunnel
|
||||||
|
# mode (POKE_TUNNEL=1, the default) the local server runs unauthenticated and
|
||||||
|
# the tunnel handles auth, so we must NOT generate a key — doing so previously
|
||||||
|
# overwrote user-supplied keys and broke working setups (issue #9).
|
||||||
|
POKE_TUNNEL="${POKE_TUNNEL:-1}"
|
||||||
|
|
||||||
|
# 4. MCP_API_KEY — generate once and persist to .env (skipped in tunnel mode)
|
||||||
|
if [ "${POKE_TUNNEL}" != "1" ] && { [ ! -f .env ] \
|
||||||
|| grep -Eq '^[[:space:]]*MCP_API_KEY=your-secret-key-here' .env 2>/dev/null \
|
|| grep -Eq '^[[:space:]]*MCP_API_KEY=your-secret-key-here' .env 2>/dev/null \
|
||||||
|| ! grep -Eq '^[[:space:]]*MCP_API_KEY=.+' .env 2>/dev/null; then
|
|| ! grep -Eq '^[[:space:]]*MCP_API_KEY=.+' .env 2>/dev/null; }; then
|
||||||
RANDOM_KEY=$(python3 -c "
|
RANDOM_KEY=$(python3 -c "
|
||||||
import secrets, string
|
import secrets, string
|
||||||
alphabet = string.ascii_letters + string.digits
|
alphabet = string.ascii_letters + string.digits
|
||||||
@@ -233,18 +246,13 @@ PYEOF
|
|||||||
fi
|
fi
|
||||||
echo " ✓ MCP_API_KEY generated and saved to .env"
|
echo " ✓ MCP_API_KEY generated and saved to .env"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
# Re-source so the freshly generated key is visible to the rest of the script
|
||||||
|
|
||||||
# ── Load .env ─────────────────────────────────────────────────────────────────
|
|
||||||
if [ -f .env ]; then
|
|
||||||
set -a
|
set -a
|
||||||
source .env
|
source .env
|
||||||
set +a
|
set +a
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Tunnel-mode detection ─────────────────────────────────────────────────────
|
# ── Tunnel-mode enforcement ───────────────────────────────────────────────────
|
||||||
POKE_TUNNEL="${POKE_TUNNEL:-1}"
|
|
||||||
|
|
||||||
if [ "${POKE_TUNNEL}" != "1" ]; then
|
if [ "${POKE_TUNNEL}" != "1" ]; then
|
||||||
: "${MCP_API_KEY:?MCP_API_KEY is not set — add it to .env or export it}"
|
: "${MCP_API_KEY:?MCP_API_KEY is not set — add it to .env or export it}"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user