hur.st's bl.aagh

BSD, Ruby, Rust, Rambling

IMSErious

Execute commands in response to Internet Message Store Events

[rust] [dovecot] [email]

IMSErious is a tiny Rust web service that makes up part of my email infrastructure.

It responds to Open-Exchange IMSE messages from the Dovecot email server by executing commands. In my case, I use it to trigger fdm – a mail retrieval agent.

This is one of those things that would have been about ten times smaller if I’d written it in Ruby or Python, but I wanted an excuse to play with axum, Tokio’s new web framework, and also as a production service for my internal network I wanted it to be as lightweight and as reasonably secure as I could make it.

It’s currently eating 6MB of memory and has consumed just over 4 seconds of CPU time in the past three weeks, so I guess I did OK there.

It supports TLS, including timed certificate reloads so it just automatically slurps up refreshed ones, and structured logging using Tracing with a variety of formatting options, including JSON.

Here it is doing its job.

OpenSMTPd receives a message from the freebsd-questions mailing list:

15:47:13 eda-mgt smtpd[29463]: 90859f1e3714857c smtp connected address=[2610:1c1:1:606c::19:2] host=mx2.freebsd.org
15:47:14 eda-mgt smtpd[29463]: 90859f1e3714857c smtp tls ciphers=TLSv1.3:TLS_AES_256_GCM_SHA384:256
15:47:15 eda-mgt smtpd[29463]: 90859f1e3714857c smtp message msgid=19038a7b size=7344 nrcpt=1 proto=ESMTP
15:47:15 eda-mgt smtpd[29463]: 90859f1e3714857c smtp envelope evpid=19038a7b8efb6051 from=<freebsd-questions...>

The message is delivered locally to Dovecot via Local Mail Transfer Protocol.

15:47:15 eda-mgt dovecot[45188]: lmtp(85091): Connect from local
15:47:15 eda-mgt dovecot[45188]: lmtp(freaky)<85091><+...>: msgid=<...>: saved mail to INBOX
15:47:15 eda-mgt dovecot[45188]: lmtp(85091): Disconnect from local: Logged out (state=READY)
15:47:15 eda-mgt smtpd[29463]: 90859f1fb404d89a mda delivery evpid=19038a7b8efb6051 from=<freebsd-questions...> ... stat=Delivered
15:47:15 eda-mgt smtpd[29463]: 90859f1e3714857c smtp disconnected reason=quit

IMSErious receives a MessageNew event from Dovecot and triggers fdm after a configured 5 second debounce delay:

15:47:15 voi imserious[93699]: notify: remote_addr=10.0.0.3:56562 event=MessageNew user=freaky
15:47:20 voi imserious[93699]: execute: spawn event=MessageNew user=freaky prog=/usr/local/bin/sudo
15:47:21 eda-mgt dovecot[45188]: imap-login: Login: user=<freaky>, ...
15:47:22 eda-mgt dovecot[45188]: imap(freaky)<88467><...>: Disconnected: Logged out ...
15:47:22 voi imserious[93699]: execute: complete elapsed_ms=1394 rc=0 event=MessageNew user=freaky prog=/usr/local/bin/sudo