# SlowMail API — Pure PHP (no framework)

## Deploy in 4 steps

### 1. Create the database
Open **phpMyAdmin** on your school server, select your database,
click **SQL**, paste the contents of `api/install.sql`, and click **Go**.

### 2. Edit credentials
Open `api/db.php` and fill in your school's MySQL info:
```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'your_db_name');
define('DB_USER', 'your_db_user');
define('DB_PASS', 'your_db_password');
```

### 3. Upload files
Upload the entire folder to your school server via **FTP or cPanel File Manager**.
Example path: `public_html/slowmail-api/`

Your API will be at: `https://yourdomain.school.edu/slowmail-api/api/`

### 4. Add cron jobs in cPanel
Go to **cPanel → Cron Jobs** and add these two:

| Schedule | Command |
|----------|---------|
| Every day at 00:01 | `php /home/youraccount/public_html/slowmail-api/deliver.php` |
| Every day at 09:00 | `php /home/youraccount/public_html/slowmail-api/deliver.php` |

> If `php` doesn't work, try `/usr/local/bin/php`

---

## API Endpoints

All endpoints: `POST` or `GET` to `https://yourdomain/slowmail-api/api/index.php?route=...`

| Method | route= | Auth | Description |
|--------|--------|------|-------------|
| POST | auth/register | No | Register |
| POST | auth/login | No | Login → token |
| POST | auth/logout | Yes | Logout |
| GET  | auth/me | Yes | Current user |
| GET  | mailbox | Yes | Delivered letters |
| POST | letters/send | Yes | Send a letter |
| POST | letters/keep?id=N | Yes | Keep a letter |
| POST | letters/throw?id=N | Yes | Throw a letter |
| GET  | desk | Yes | Kept letters |
| GET  | outbox | Yes | Sent letters |
| GET  | users/search?q=xxx | Yes | Find users |

**Auth header:** `Authorization: Bearer YOUR_TOKEN`

## Test the API
Open your browser and go to:
`https://yourdomain/slowmail-api/api/index.php?route=auth/me`

You should see: `{"error":"Unauthorized"}` — that means it's working!
