dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit b8ba25f5da77abeb6b1333cc22985520ac9e1e30
parent ae3a3219aa3c4e1e6657f29db9aba67060f7a37c
Author: pancake@localhost.localdomain <unknown>
Date:   Tue, 20 Oct 2009 02:05:51 +0200

* Complete and install manpage
* Fix the daemon start function
  - Pretty unstable and ugly implementation, but works
* Implement 'dmc pull'
  - Handles of ${LIMIT} in ~/.dmc/acc.default
* sleepy start and stop commands
* Fix -c command
  - No need to quote the command in a single argument. Uses $@
  - No arguments results in an interactive shell against the
    current account
  - No support for multiple accounts
* Fix \x00 issue related to the seek on stderr filedescriptor
  - Mails are correctly stored now
Diffstat:
FAQ | 4++--
Makefile | 1+
dmc | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
dmc.1 | 47++++++++++++++++++++++++++++++++++++++++++++++-
pop3.c | 5++++-
5 files changed, 108 insertions(+), 13 deletions(-)

diff --git a/FAQ b/FAQ @@ -51,14 +51,14 @@ situations and be a guide for the TODO points. cat mail.txt | dmc-pack file1.zip file2.zip > mail.eml - * Are mbox and Maildir supported? No, not yet. Implementation proposals are welcome - * How can I get the headers of a mail? + dmc -c cat 1 + * And the body? TODO: diff --git a/Makefile b/Makefile @@ -14,6 +14,7 @@ dmc-imap4: imap4.o ${CC} ${LDFLAGS} imap4.o -o dmc-imap4 install: + cp -f dmc.1 ${PREFIX}/share/man/man1 cp -f dmc ${PREFIX}/bin cp -f dmc-smtp ${PREFIX}/bin cp -f dmc-pop3 ${PREFIX}/bin diff --git a/dmc b/dmc @@ -29,12 +29,38 @@ function acc_daemon { rm -f ${INPUT} mkfifo ${INPUT} + mkfifo ${FIFO} echo login ${USER} ${PASS} > ${INPUT} & - (while : ; do cat ${INPUT} ; done) | \ + (while : ; do cat ${INPUT} 2> /dev/null ; done) | \ ./dmc-${PROTOCOL} $FIFO 2> ${OUTPUT} | $NETCMD > $FIFO rm -f ${INPUT} } +function dmc_cmd { +# while not 0x00 is found...sleep 1 + #:> ~/.dmc/tmp/${NAME}.output + # XXX this is going to fail and lock + OUT=~/.dmc/tmp/${NAME}.output + :> ${OUT} + echo "$@" > ~/.dmc/tmp/${NAME}.input + # XXX ultraugly way to check for eof + osize=0 + while : ; do + size=`du -hs ${OUT}|awk '{print $1}'` + if [ "$size" = "0" ]; then + sleep 1 + else + if [ "$size" = "$osize" ]; then + break + else + sleep 1 + osize=$size + fi + fi + done + cat ${OUT} +} + function start_account_daemons { i=0 for a in ~/.dmc/acc/* ; do @@ -62,7 +88,6 @@ function print_account_template { } function edit_message { - . ~/.dmc/acc.default OUTDIR=~/.dmc/box/${NAME}/out mkdir -p ${OUTDIR} OUT="`mktemp ${OUTDIR}/mail.XXXXXX`" @@ -127,12 +152,26 @@ function send_message { function pull_mails { echo "Pulling mails from account '${NAME}'" - echo " TODO: Not implemented" + # This is pop3-only + i=1 + while : ; do + [ "${LIMIT}" = "$i" ] && break + dmc -c cat $i > ~/.dmc/box/${NAME}/in/$i.eml + if [ -n "`head -n 3 ~/.dmc/box/${NAME}/in/$i.eml | grep ERR`" ]; then + rm ~/.dmc/box/${NAME}/in/$i.eml + break + else + size=`du -hs ~/.dmc/box/${NAME}/in/$i.eml | awk '{print \$1}'` + echo "got $i $size" + fi + i=$(($i+1)) + done } case "$1" in "start") start_account_daemons + sleep 1 ;; "stop") for a in ~/.dmc/tmp/*.input ; do @@ -140,6 +179,10 @@ case "$1" in echo exit > $a rm -f ~/.dmc/tmp/$a done + sleep 1 + pkill cat + rm -f ~/.dmc/tmp/* + pkill dmc ;; "push") for a in ~/.dmc/acc/* ; do @@ -189,13 +232,16 @@ case "$1" in grep -e : | grep -re "^$2:" | cut -d : -f 2- | sed 's, ,,' ;; "-c"|"--cmd") - if [ -z "$1" ]; then - echo "Argument required" - exit 1 + if [ -z "$2" ]; then + while : ; do + printf "> " + read A + dmc_cmd "$A" + done + else + shift + dmc_cmd "$@" fi - # XXX this is going to fail and lock - echo "$2" > ~/.dmc/tmp/${NAME}/.input - tail -f ~/.dmc/tmp/${NAME}/.output ;; "-s"|"--send") for a in $* ; do diff --git a/dmc.1 b/dmc.1 @@ -1 +1,46 @@ -TODO +.Dd Oct 20, 2009 +.Dt DMC 1 +.Os +.Sh NAME +.Nm dmc +.Nd dynamic mail client +.Sh SYNOPSIS +.Nm dmc +.Op Fl h +.Op Fl e Ar account +.Op Fl a Ar name1 name2 +.Op Fl m Ar addr subj +.Op Fl A Ar file +.Op Fl s Ar msg +.Op actionmsg +.Sh DESCRIPTION +dmc is a minimalistic mail client for *nix +.Sh OPTIONS +.Bl -tag -width Fl +.It Fl e Ar account-name +Edit or create with $EDITOR the given account. List all accounts if no argument passed. +.It Fl a Ar name +Grep for name in ~/.dmc/addrbook +.It Fl A Ar file +Append file to the last mail edited with 'dmc -m' +.It Fl m Ar addr subj +Create new e-mail for sending using $EDITOR from the ~/.dmc/acc.default account +.It Fl c Ar command +Run dmc-pop3/dmc-imap4 shell command +.It Fl v +Show version +.It Fl h +Show help message +.It Ar start +Start a mail daemon for each configured account +.It Ar stop +Stop all running dmc mail daemons +.It Ar pull +Retrieve ${LIMIT} mails of configured accounts +.It Ar push +Send all mails in outbox +.Sh FILES +~/.dmc/signature +.Sh AUTHORS +.Pp +pancake <@nopcode.org> diff --git a/pop3.c b/pop3.c @@ -64,7 +64,10 @@ static int waitreply() { fprintf(stderr, "%s\n", str); } fflush(stderr); - write(2, "\x00", 1); // end of output + /* stderr lseek works on pipes :D */ + lseek(2, 0, 0); + //if (*str) + // write(2, "\x00", 1); // end of output return reply; }