- Toggle overriding-local-map via post-command-hook: while point is in the draft, a global-map-parented keymap shadows mode hotkeys (g, h, q, SPC, DEL) so any text can be typed; RET/C-c C-c send - Treat missing window as "at bottom" during first render and force point to the prompt after switch-to-buffer
emacs-mattermost
Emacs client for corporate Mattermost, inspired by the UX of telega.el.
Target Mattermost server version: 10.9.3.
Components
- Emacs Lisp package: UI, buffers, commands, keybindings.
- Rust bridge: Mattermost REST/WebSocket, session cache, online updates.
- Docker Compose: primary way to run the bridge.
- Web status UI: exposed by the bridge container.
Fixed decisions
- Bridge language: Rust.
- Main bridge runtime: Docker Compose, started separately from Emacs.
- Emacs connects to an already running bridge over localhost TCP JSON Lines.
- Mattermost server is the single source of truth; Emacs buffers are display-only.
- MVP message rendering: raw text, no Markdown.
- MVP starts with direct messages to self, channels come later.
- Multiserver support is architecturally planned, not implemented in MVP.
- All identifiers and stored state are server-scoped from the beginning.
- DM buffers must show server/team context to avoid confusion.
- Threads/replies are separate buffers by default, configurable via use-package.
gforces buffer refresh plus connection health check/recovery.- Typing indicators and reactions are out of MVP scope.
- Auth MVP: login/password plus saved session token or PAT.
- Token cache: plain file per server under the data dir, private file mode.
- Password may be read from Emacs
~/.authinfo; no strong protection in MVP. - Secrets must never appear in logs, protocol responses, or the web status UI.
- TLS verification stays enabled; internal CA is configured explicitly.
Build environment
Corporate network: no direct internet access, authenticated proxy.
- Cargo dependencies resolve through the Nexus mirror configured in
bridge/.cargo/config.toml. - Docker builder image:
nexus.local/rust:1.90-bookworm. - Docker runtime image:
nexus.local/ci/debian:bookworm-ca. - Host toolchain: Rust 1.94 (used to generate the lockfile).
- Workspace
rust-version: 1.90. - MSRV-aware resolution is enabled via
resolver.incompatible-rust-versions = "fallback", so cargo picks dependency versions compatible with Rust 1.90 automatically. Cargo.lockis committed and all builds use--locked.- The corporate CA bundle is copied into the build context by
scripts/docker-prepare-ca.shso cargo trustsnexus.local.
Do not hand-pin transitive dependency versions. If a dependency needs
updating, run cargo update, then scripts/dev-check.sh, then the Docker
build. The resolver handles MSRV compatibility.
bridge/rust-toolchain.toml pins the host toolchain only. It is deliberately
not copied into the Docker image; the image uses its preinstalled toolchain.
Repository layout
.
├── README.md
├── compose.yaml
├── docker/
│ ├── Dockerfile
│ ├── entrypoint.sh
│ └── certs/ generated CA bundle for the build context
├── docs/
├── scripts/
├── bridge/
│ ├── Cargo.toml
│ ├── Cargo.lock
│ ├── rust-toolchain.toml
│ ├── .cargo/config.toml
│ └── crates/
│ ├── mm-core/ domain types, ids, errors (no network)
│ ├── mm-client/ Mattermost REST/WebSocket client
│ ├── mm-store/ token and server-config storage
│ ├── mm-web/ web status UI
│ └── mm-bridge/ daemon: TCP JSONL, routing, app state
├── lisp/
└── tests/
Data directory
MM_DATA_DIR (default /data in Docker, ~/.local/share/emacs-mattermost
on the host):
<data_dir>/tokens/<server_id>.token bearer token, mode 0600, atomic write
<data_dir>/servers/<server_id>.json non-secret server config
server_id must match [A-Za-z0-9_-]+. This prevents path traversal and
keeps filenames predictable for future multiserver support.
Ports
127.0.0.1:8765 bridge TCP JSONL (Emacs connects here)
127.0.0.1:8766 web status UI (/ , /health , /status)
Both are bound to localhost only.
Quick start
Start the bridge:
./scripts/docker-up.sh
Check it:
./scripts/smoke-ping.sh
./scripts/smoke-web.sh
Status page: http://127.0.0.1:8766/
Stop:
./scripts/docker-down.sh
Local development without Docker:
./scripts/dev-check.sh # fmt check + cargo check/test --locked
cd bridge && cargo run -p mm-bridge
Protocol
One JSON object per line over TCP. See docs/protocol.md.
Implemented methods:
ping
status
Planned MVP methods:
connect
me
teams
open_self_dm
list_channels
get_history
send_post
reply_post
mark_read
Emacs package (planned)
(use-package mattermost
:load-path "~/Documents/emacs-mattermost/lisp"
:custom
(mattermost-bridge-host "127.0.0.1")
(mattermost-bridge-port 8765)
(mattermost-thread-display 'separate-buffer))
Buffer naming keeps server identity visible even in single-server MVP:
*Mattermost[work]/DM:self*
*Mattermost[work]/team:dev/channel:town-square*
*Mattermost[work]/team:dev/thread:post-id*
Development rules
- Work in small atomic steps; each step must leave the project buildable.
- Provide full file contents, not patches.
- Keep code files under 300 lines; split modules before they grow.
- Prefer automated fixes (
cargo fmt, MSRV-aware resolver) over manual edits. - Commit
Cargo.lockonly after a fully green build. - Keep this README and
docs/mvp-checklist.mdupdated. - Never log tokens, passwords, or auth headers.
Progress
See docs/mvp-checklist.md for the detailed checklist.
Current state: phases 0-3a complete (storage foundation). Next: phase 3b (REST client, auth, connect/me).
Verification
To verify the bridge works against your corporate Mattermost instance:
- Start the bridge:
./scripts/docker-up.sh - Connect and get a token:
./scripts/mm-cli.sh '{"id":"1","type":"request","method":"connect","params":{"server_id":"work","url":"https://mm.local","login_id":"user","password":"pass"}}' - Open self-DM channel:
./scripts/mm-cli.sh '{"id":"2","type":"request","method":"open_self_dm","params":{"server_id":"work"}}' - Send a message to yourself:
./scripts/mm-cli.sh '{"id":"3","type":"request","method":"send_post","params":{"server_id":"work","channel_id":"<ID_FROM_STEP_3>","message":"Test"}}' - Check history:
./scripts/mm-cli.sh '{"id":"4","type":"request","method":"get_history","params":{"server_id":"work","channel_id":"<ID_FROM_STEP_3>","limit":1}}'