dmc

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

commit d7b93f5da26b7d47a470a703473cade3964bab5e
parent 99651cc5e47e904d9ce8f1d7d99bbaeb74507fb4
Author: pancake@localhost.localdomain <unknown>
Date:   Wed, 28 Oct 2009 11:41:09 +0100

* chmod +x dmc dmc-tag
* Do not use empty loop conditionals in dmc
  - Some random fixes and minor code cleanup
  - Fix manpage. Add doc for -s and -H
  - Fix unitialized tagdb warnings
* Minor code cleanup in imap4 and pop3
Diffstat:
Makefile | 1+
dmc | 28+++++++++++++---------------
dmc-tag | 37++++++++++++++++++-------------------
dmc.1 | 5+++++
doc/design | 7+++++++
imap4.c | 14++++----------
pop3.c | 2+-
7 files changed, 49 insertions(+), 45 deletions(-)

diff --git a/Makefile b/Makefile @@ -17,6 +17,7 @@ dmc-pack: pack.o ${CC} ${LDFLAGS} pack.o -o dmc-pack install: + chmod +x dmc dmc-tag cp -f dmc.1 ${PREFIX}/share/man/man1 cp -f dmc ${PREFIX}/bin cp -f dmc-tag ${PREFIX}/bin diff --git a/dmc b/dmc @@ -110,7 +110,7 @@ function edit_message { fi ${EDITOR} ${OUT} if [ -z "`cat ${OUT}`" ]; then - echo "Aborted mail" + echo "Mail aborted" rm -f "${OUT}" else ln -fs "${OUT}" ~/.dmc/mail.last @@ -160,8 +160,7 @@ function pull_mails { echo "Pulling mails from account '${NAME}'" # This is pop3-only i=1 - while : ; do - [ "${LIMIT}" = "$i" ] && break + while [ ! "$LIMIT" = "$i" ] ; do 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 @@ -221,11 +220,9 @@ case "$1" in [ -z "`cat ~/.dmc/acc/$2`" ] && \ print_account_template "$2" > ~/.dmc/acc/$2 ${EDITOR} ~/.dmc/acc/$2 - # Remove account if empty if [ -z "`cat ~/.dmc/acc/$2`" ]; then - rm ~/.dmc/acc/$2 + rm -f ~/.dmc/acc/$2 else - # by default echo "The '$2' account is now the default" ln -fs ~/.dmc/acc/$2 ~/.dmc/acc.default fi @@ -234,8 +231,11 @@ case "$1" in fi ;; "-H"|"--header") - [ -z "$2" ] && break - grep -e : | grep -re "^$2:" | cut -d : -f 2- | sed 's, ,,' + if [ -z "$2" ]; then + echo "Usage: dmc -H [header] < mail" + else + grep -e : | grep -re "^$2:" | cut -d : -f 2- | sed 's, ,,' + fi ;; "-c"|"--cmd") if [ -z "$2" ]; then @@ -261,18 +261,16 @@ case "$1" in edit_message ;; "-A"|"--add-attachment") - while : ; do + while [ -n "$2" ] ; do + add_attachment $2 shift - [ -z "$1" ] && break - add_attachment $1 done ;; "-a"|"--addr") if [ -n "$2" ]; then - while : ; do + while [ -n "$2" ] ; do + grep -e "$2" ~/.dmc/addrbook shift - [ -z "$1" ] && break - grep -e "$1" ~/.dmc/addrbook done else ${EDITOR} ~/.dmc/addrbook @@ -285,10 +283,10 @@ case "$1" in echo ${HELP} echo " -e account edit account information" echo " -a name show addressbook email for contact" + echo " -A file add attachment to mail" echo " -c cmd run command for \$DMC_ACCOUNT or acc.default daemon" echo " -m addr subj create mail with default account" echo " -H header grep for header" - echo " -A file add attachment to mail" echo " -s file send email" echo " -v show version" echo " -h show this help message" diff --git a/dmc-tag b/dmc-tag @@ -19,33 +19,33 @@ cd ${DMCTAG_ROOT} function set_file { FILE=$1 if [ -e "${OLDPWD}/${FILE}" ]; then - if [ ! "`echo $FILE|cut -c 1`" = / ]; then + if [ ! "`echo ${FILE} | cut -c 1`" = / ]; then # autocomplete relative paths - FILE="$OLDPWD/$FILE" + FILE="${OLDPWD}/${FILE}" fi else - echo "Cannot find $FILE" + echo "Cannot find ${FILE}" exit 1 fi export FILE } # untag this file . this is highly suboptimal. in C will be much faster +# XXX: Only used with $FILE.. set_file is required function untag { - FILE=$1 - for TAG in * ; do - grep -v ${FILE} $TAG > $TAG.tmp + for TAG in `$0 -l` ; do + grep -v $1 $TAG > $TAG.tmp mv $TAG.tmp $TAG done } case "$1" in "-f") - cat * | sort | uniq + cat * 2> /dev/null | sort | uniq ;; "-m") # move cached files in from to - for a in * ; do + for a in `$0 -l` ; do sed -e "s,^$1,$2," $a > $a.tmp mv $a.tmp $a done @@ -54,7 +54,7 @@ case "$1" in # check/cleanup for missing files if [ -n "$2" ] ; then set_file "$2" - if [ -z "`cat * | grep $FILE`" ]; then + if [ -z "`cat * 2> /dev/null | grep $FILE`" ]; then rm -f "${FILE}" fi else @@ -71,25 +71,25 @@ case "$1" in if [ -z "$2" ]; then ls | cat else - shift - while [ -n "$1" ] ; do - if [ -e "${DMCTAG_ROOT}/$1" ]; then - cat ${DMCTAG_ROOT}/$1 + while [ -n "$2" ] ; do + if [ -e "${DMCTAG_ROOT}/$2" ]; then + cat ${DMCTAG_ROOT}/$2 else - echo "Cannot find tag $1" + echo "Cannot find tag $2" fi shift done fi ;; "-u") - untag $2 + set_file "$2" + untag ${FILE} ;; "-v") echo "dmc-tag-0.1 (c) 2009 pancake(at)nopcode(dot)org" ;; "") - echo "Usage: dmc-tag [-uhv] [-c [file ..]][-m dir dir] [[,-u] [file] [[tag ..]]]" + echo "Usage: dmc-tag [-uhv] [-c [file ..]] [-m dir dir] [[,-u] [file] [[tag ..]]]" ;; "-h") $0 @@ -114,9 +114,8 @@ case "$1" in # set tags for a file set_file "$1" untag "${FILE}" - shift - while [ -n "$1" ] ; do - echo "${FILE}" >> ${DMCTAG_ROOT}/$1 + while [ -n "$2" ] ; do + echo "${FILE}" >> ${DMCTAG_ROOT}/$2 shift done fi diff --git a/dmc.1 b/dmc.1 @@ -7,6 +7,7 @@ .Sh SYNOPSIS .Nm dmc .Op Fl h +.Op Fl H Ar header .Op Fl e Ar account .Op Fl a Ar name1 name2 .Op Fl m Ar addr subj @@ -27,6 +28,10 @@ Append file to the last mail edited with 'dmc -m' 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 H Ar header +Grep for given header +.It Fl s Ar file +Send file as mail .It Fl v Show version .It Fl h diff --git a/doc/design b/doc/design @@ -29,6 +29,13 @@ This tool parses a mail from stdin and extracts the attachments on separated files in the current directory. +sync +==== + +The sync process is done independently from the backend. + + + tags ==== diff --git a/imap4.c b/imap4.c @@ -34,26 +34,22 @@ reread: if (*word=='"') { strcpy(word, word+1); p = strchr(word, '"'); - if (p) { - *p=0; - } else { + if (!p) { str = word+strlen(word); *str = ' '; str++; *str = 0; goto reread; - } + } else *p=0; } } else { p = strchr(str, '"'); - if (p) { - *p=0; - } else { + if (!p) { *str = ' '; str++; *str = 0; goto reread; - } + } else *p = 0; } } return word; @@ -65,7 +61,6 @@ static void cleanup(int foo) { exit(0); } - static int ready() { struct pollfd fds[1]; fds[0].fd = ff; @@ -80,7 +75,6 @@ static int waitreply() { int line = 0; int ret, reply = -1; fflush(stdout); -// XXX ugly sleep hack while(lock || !ready()) { lock = 0; ret = read(ff, str, 1024); diff --git a/pop3.c b/pop3.c @@ -96,7 +96,7 @@ static int doword(char *word) { waitreply(); } else if (!strcmp(word, "head")) { - printf("TOP %d\n", atoi(getword())); + printf("TOP %d 50\n", atoi(getword())); waitreply(); } else if (!strcmp(word, "rm")) {