On Sat, 10 Nov 2007, Matt wrote:

Is there anyway I can get Dovecot to update mtime on dovecot.index
everytime a user successfully checks there email?  Or perhaps there is
a better way to do what I want here.

I am working on a script that I want to check when the last time a
user checked there email account.  If a user has not checked it in say
6 months I want to automatically suspend the account through the MTA.
If they start checking it again I also want to automatically reinstate
it.  What I thought was a good way was to look at the mtime on
dovecot.index but a user can be checking there email daily but if they
do not receive a new message in say 6 months the mtime will date back
to 6 months still.  Ran into this with an email address used by a fax
machine.

So is there a better way with dovecot to determine this?  I am using
dovecot-1.0.rc29 right now.


[From an email I wrote in October]

You can do this (and many other things) through Post-Login Scripting:
http://wiki.dovecot.org/PostLoginScripting

See in particular “Last-login tracking”:
http://wiki.dovecot.org/PostLoginScripting#line-20


[...and for your situation:]

I think I'd avoid actually disabling the account through the MTA, especially if it's for security considerations and your accounts have shell access. But it wouldn't be that hard:


In dovecot.conf, set your IMAP login script as follows:

protocol imap {
# ...
mail_executable = /full/path/to/loginscript.sh


Then, use the attached loginscript.sh. (and chmod +x it)

Tested with 1.0.5 under Gentoo. The 'stat' and 'date' commands might need alteration depending on your particular flavor of O/S.

(I also realized after writing it that you probably meant to disable mail delivery, not IMAP access. But, it was a fun exercise.)

In that case, all you need in loginscript.sh is:

#!/bin/sh
touch $HOME/.dovecot-lastlogin
exec /usr/libexec/dovecot/imap

Then run a cron job to disable delivery through your MTA of choice.

Best,
Ben

Attachment: dovecot-login.sh
Description: Bourne shell script

Reply via email to