feat: add setup.sh with Poke login SDK token automation

This commit is contained in:
0xK
2026-03-24 09:43:44 +01:00
parent 9fe13e5e97
commit 45f75d9e12
2 changed files with 183 additions and 2 deletions
Executable → Regular
+36 -2
View File
@@ -13,10 +13,44 @@ An MCP server that bridges IMAP/SMTP email accounts to [Poke](https://poke.com).
## Quick Start
### Automated setup (recommended)
```bash
git clone https://github.com/kacperkwapisz/poke-mail.git
cd poke-mail
```
If you haven't logged into Poke yet, do that first — it lets `setup.sh` pick up your token automatically:
```bash
npx poke login
```
Then run the setup script:
```bash
bash setup.sh
```
`setup.sh` will:
1. Create a Python virtualenv and install dependencies
2. Detect your Poke API key from `poke login` credentials (or prompt you to paste one)
3. Copy `config.example.yml``config.yml` and inject the API key automatically
4. Generate a random `MCP_API_KEY` and write it to `.env`
5. Ensure the `poke` npm package is installed globally
After setup, open `config.yml` and fill in your email account credentials, then start the server:
```bash
./start.sh
```
### AI coding agent setup
Copy this prompt into your AI coding agent (Claude Code, Cursor, etc.):
```text
Set up poke-mail (https://github.com/kacperkwapisz/poke-mail) for me — clone the repo, create a Python virtualenv named .venv, install requirements.txt, copy config.example.yml to config.yml, then help me configure config.yml — you can guide me on which IMAP/SMTP host and port to use for my email provider (iCloud, Gmail, Outlook, etc.) and what username format to use, but do NOT type or suggest passwords or API keys, tell me to enter those myself outside of this terminal and confirm when done — then generate a random 32+ character MCP_API_KEY, save it to a .env file as MCP_API_KEY=<the-key>, install the poke npm package globally, run poke login so I can authenticate, and run start.sh to start the server and tunnel it to Poke.
Set up poke-mail (https://github.com/kacperkwapisz/poke-mail) for me — clone the repo, run 'npx poke login' so I can authenticate with Poke (wait for me to confirm), then run 'bash setup.sh' which will automatically wire up my Poke API key, generate an MCP_API_KEY, and set up the virtualenv — then help me configure config.yml with my email credentials (guide me on IMAP/SMTP host and port for my provider but do NOT type passwords or secrets — tell me to enter those myself and confirm when done) — then run start.sh to start the server and tunnel it to Poke.
```
To start the server again later:
@@ -33,7 +67,7 @@ To start the server again later:
cp config.example.yml config.yml
```
Edit `config.yml` with your email credentials:
Edit `config.yml` with your email credentials and Poke API key (from [poke.com/settings/advanced](https://poke.com/settings/advanced)):
```yaml
webhook_url: https://poke.com/api/v1/inbound/api-message
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env bash
# setup.sh — one-time setup for poke-mail
# Automates token creation via the Poke login SDK so you don't have to
# copy/paste API keys manually.
set -euo pipefail
cd "$(dirname "$0")"
echo ""
echo " poke-mail setup"
echo " ────────────────────────────────────────"
echo ""
# ── 1. Python virtualenv ────────────────────────────────────────────────────
if [ ! -d .venv ]; then
echo "Creating Python virtualenv (.venv)..."
python3 -m venv .venv
fi
source .venv/bin/activate
echo "Installing Python dependencies..."
pip install -q -r requirements.txt
echo " ✓ Python dependencies installed"
echo ""
# ── 2. Poke API key (poke_api_key for config.yml) ────────────────────────────
# The 'poke' npm package stores credentials at:
# ~/.config/poke/credentials.json → { "token": "..." }
# when the user runs: npx poke login
POKE_CREDENTIALS_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/poke/credentials.json"
POKE_API_KEY_VALUE=""
if [ -f "$POKE_CREDENTIALS_FILE" ]; then
# Try to extract .token with python (avoids jq dependency)
POKE_API_KEY_VALUE=$(python3 -c "
import json, sys
try:
data = json.load(open('$POKE_CREDENTIALS_FILE'))
print(data.get('token', ''))
except Exception:
print('')
" 2>/dev/null || true)
fi
if [ -n "$POKE_API_KEY_VALUE" ]; then
echo " ✓ Found Poke credentials from 'poke login'"
else
echo " Poke API key not found via 'poke login'."
echo ""
echo " Option 1 (recommended): Run the following, then re-run this script:"
echo " npx poke login"
echo ""
echo " Option 2: Paste your API key from https://poke.com/settings/advanced"
echo ""
printf " Poke API key (leave blank to set later): "
read -r POKE_API_KEY_VALUE
POKE_API_KEY_VALUE=$(echo "$POKE_API_KEY_VALUE" | tr -d '[:space:]')
fi
echo ""
# ── 3. config.yml ────────────────────────────────────────────────────────────
if [ ! -f config.yml ]; then
echo "Copying config.example.yml → config.yml..."
cp config.example.yml config.yml
echo " ✓ config.yml created"
else
echo " ✓ config.yml already exists — skipping copy"
fi
# Inject poke_api_key into config.yml if we have one
if [ -n "$POKE_API_KEY_VALUE" ]; then
# Replace the placeholder value in-place (handles both quoted forms)
python3 - <<EOF
import re
with open('config.yml', 'r') as f:
content = f.read()
# Replace poke_api_key: "your-api-key-here" or poke_api_key: your-api-key-here
pattern = r'(poke_api_key:\s*)[^\n]+'
replacement = r'\g<1>"${POKE_API_KEY_VALUE}"'
new_content = re.sub(pattern, replacement, content)
with open('config.yml', 'w') as f:
f.write(new_content)
print(' ✓ poke_api_key written to config.yml')
EOF
else
echo " ⚠ poke_api_key not set — edit config.yml manually before running start.sh"
fi
echo ""
# ── 4. MCP_API_KEY (.env) ────────────────────────────────────────────────────
if [ -f .env ] && grep -q 'MCP_API_KEY=' .env && ! grep -q 'MCP_API_KEY=your-secret-key-here' .env; then
echo " ✓ .env already has MCP_API_KEY — skipping"
else
echo "Generating MCP_API_KEY..."
RANDOM_KEY=$(python3 -c "
import secrets, string
alphabet = string.ascii_letters + string.digits
print(''.join(secrets.choice(alphabet) for _ in range(48)))
")
if [ -f .env ]; then
# Update existing file
python3 - <<PYEOF
import re
with open('.env', 'r') as f:
content = f.read()
new_content = re.sub(r'MCP_API_KEY=.*', 'MCP_API_KEY=${RANDOM_KEY}', content)
if 'MCP_API_KEY=' not in new_content:
new_content += '\nMCP_API_KEY=${RANDOM_KEY}\n'
with open('.env', 'w') as f:
f.write(new_content)
PYEOF
else
echo "MCP_API_KEY=${RANDOM_KEY}" > .env
fi
echo " ✓ MCP_API_KEY generated and saved to .env"
fi
echo ""
# ── 5. Poke npm package ───────────────────────────────────────────────────────
if ! command -v poke &>/dev/null; then
echo "Installing the 'poke' npm package globally..."
npm install -g poke
echo " ✓ poke installed"
else
echo " ✓ poke CLI already installed ($(poke --version 2>/dev/null || echo 'version unknown'))"
fi
echo ""
# ── Done ─────────────────────────────────────────────────────────────────────
echo " ────────────────────────────────────────"
echo " Setup complete!"
echo ""
if [ -z "$POKE_API_KEY_VALUE" ]; then
echo " Next steps:"
echo " 1. Run 'npx poke login' or add your Poke API key to config.yml"
echo " 2. Fill in your email credentials in config.yml"
echo " 3. Run ./start.sh"
else
echo " Next steps:"
echo " 1. Fill in your email credentials in config.yml"
echo " 2. Run ./start.sh"
fi
echo ""