rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | LICENSE

commit 4e33ec64402d7050d2ff788eb89ed5bd891a5be1
parent 7c6671458b78219b689b61d8e0fd736d45a9e549
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed,  2 May 2012 20:03:11 +0200

Drafts fixes and sequence cleanup + joinstr optimisation.

Diffstat:
bin/rpdrafts | 8++++----
bin/rprepl | 24+++++++-----------------
inc.c | 6++++--
llist.c | 23+++++++++++++++++++----
mark.c | 6+++---
5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/bin/rpdrafts b/bin/rpdrafts @@ -41,26 +41,26 @@ fi if [ $doedit -eq 0 ] && [ $dodelete -eq 0 ]; then - rpscan -m $dfolder "$@" + rpscan -m $dfolder -- "$@" exit $? fi if [ $dodelete -eq 1 ]; then - rprm -m $dfolder "$@" + rprm -m $dfolder -- "$@" exit $? fi if [ $doedit -eq 1 ]; then - id=`rpids -m $dfolder $* | awk -F' ' '{print $1}'` + id=`rpids -m $dfolder -- "$@" | awk -F' ' '{print $1}'` if [ $? -eq 1 ]; then echo "Please specify a valid message id." exit 1 fi - rpedit -m $dfolder $id + rpedit -m $dfolder -- $id exit $? fi diff --git a/bin/rprepl b/bin/rprepl @@ -1,21 +1,5 @@ #!/bin/sh -usage() { - echo "usage: `basename $1` [-h] msgid" -} - -if [ "$1" = "--" ]; -then - shift 1 -fi - -ids="$@" -if [ -z "$ids" ]; -then - usage $0 - exit 1 -fi - if [ ! -x $HOME/.rohrpost/tmpl/repl.sh ]; then echo "$HOME/.rohrpost/tmpl/repl.sh does not exist. Will" \ @@ -31,7 +15,13 @@ trap 'signalh' 3 6 9 15 dfolder=`rpcfg -v fold_drafts` -$HOME/.rohrpost/tmpl/repl.sh -- "$ids" > $tmpfile +$HOME/.rohrpost/tmpl/repl.sh "$@" > $tmpfile +if [ $? -gt 0 ]; +then + rm -f $tempfile + exit 1 +fi + mid=`rpadd -m $dfolder -f seen $tmpfile` signalh diff --git a/inc.c b/inc.c @@ -184,8 +184,10 @@ inc_mkunseen(imap_t *imap, char *folder) if (results != NULL) { str = llist_joinstr(results, " "); llist_free(results); - mark_set(marks, "unseen", str); - free(str); + if (str != NULL) { + mark_set(marks, "unseen", str); + free(str); + } mark_stop(marks); } } diff --git a/llist.c b/llist.c @@ -671,18 +671,33 @@ llist_splitargv(int argc, char *argv[]) char * llist_joinstr(llist_t *llist, char *sep) { - char *str, *tstr; + char *str, *tstr, *sstr; llistelem_t *elem; + int keylen, seplen, size; str = NULL; + seplen = strlen(sep); + size = 0; forllist(llist, elem) { + keylen = strlen(elem->key); if (str == NULL) { - str = smprintf("%s", elem->key); + str = memdup(elem->key, keylen+1); + size += keylen; } else { - tstr = smprintf("%s%s%s", str, sep, elem->key); - free(str); + /* + * Premature optimisation. + */ + sstr = mallocz(keylen + seplen + 1, 1); + memmove(sstr, sep, seplen); + memmove(&sstr[seplen], elem->key, keylen); + + keylen += seplen; + tstr = memdupcat(str, size, sstr, keylen+1); + free(sstr); str = tstr; + + size += keylen; } } diff --git a/mark.c b/mark.c @@ -92,8 +92,8 @@ mark_stop(mark_t *marks) llistelem_t * mark_set(mark_t *marks, char *seq, char *value) { - if (strcspn(seq, "[]:") != strlen(seq)) - die("'[]:' not allowed in sequence name."); + if (strcspn(seq, "[]") != strlen(seq)) + die("'[]' not allowed in sequence name."); return txtdb_set(marks, seq, value); } @@ -107,7 +107,7 @@ mark_internget(mark_t *marks, char *seq, int llist) char *cseq, *pbegin, *pend, *pstep, *ppend; lseq = strlen(seq); - if (strcspn(seq, "[]:") != lseq) { + if (strcspn(seq, "[]") != lseq) { elist = NULL; nargs = 0; //printf("Found a slicing sequence.\n");