Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Mail spooler with zsh



    Hi all :)

    I'm writing a simple mail spooler to queue mail before sending
with msmtp. This MTA doesn't do queuing and I thought that it would
be a good idea to write the queuing part as a zsh script.

    More or less the script has the following structure:

    - Queue the new mail message
    - Try to send each queued mail
    - Remove from the queue any successfully sent message.

    The first part I'm implementing using the maildir algorithm, to
allow multiple instances of the queuer running in the same spool
directory, and here come the problems.

    The maildir algorightm needs some stat calls (this can be solved
using the zsh/stat module or simple '[[]]' tests) and a timeout test.
The timeout is to avoid block for a very long time in case the system
clock is set backwards. Well, I think that the timeout can be
implemented using $TMOUT, but in a script (non interactive of course)
there is no prompt and TMOUT doesn't seem (obviously) to work :(

    It has occurred to me that I can set up a counter and instead of
checking for time passed I check for number of failed 'stat' calls.
But for this to be successful even in the case of the clock been set
backward a lot of time, I need to use a finer-grain control:
nanoseconds. How in zsh can I obtain the nanoseconds as in 'date
+%N'? I want to avoid calling 'date' in every loop since 'print -P
%D{}' is a bit faster (in fact it is more than 10 times faster...).

    I could use 'safecat', I know, but I prefer to do all the script
using just builtin commands. Moreover, safecat has 24hour timer and
only seconds of resolution, and although I never set my clock back in
time, you never know... ;)

    Thanks in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



Messages sorted by: Reverse Date, Date, Thread, Author