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 ae52f8373b902cb8098bb8c7c54c88ff8f9805f9
parent f81014735b68a607ffcabad14a8eda51a34c1383
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 23 Dec 2012 09:34:07 +0100

Removing the old formatting command kludge and fixing rpflag.

Diffstat:
Makefile | 16+++++-----------
bin/rpedit | 2+-
bin/rpfinc | 4----
bin/rpflag | 16++++++++++++++++
bin/rpflagu | 4----
bin/rpfscan | 4----
bin/rpfscanp | 4----
bin/rpfview | 4----
bin/rpfviewp | 4----
bin/rpfwd | 4++--
bin/rpinc | 16++++++++++++++++
bin/rpnews | 2+-
bin/rpnextp | 4----
bin/rppopu | 4----
bin/rpprevp | 4----
bin/rpscan | 16++++++++++++++++
bin/rpscanp | 4----
bin/rpscanu | 4----
bin/rpscanup | 4----
bin/rpsyncmail | 2+-
bin/rptailf | 2+-
bin/rpview | 16++++++++++++++++
bin/rpviewp | 4----
bin/rpviewu | 4----
bin/rpviewup | 4----
flag.c | 56++++++++++++++++++++++++++++++++++----------------------
inc.c | 2+-
rohrpost.c | 61+++++++++++++++++++++++++++++++++++++------------------------
28 files changed, 147 insertions(+), 124 deletions(-)

diff --git a/Makefile b/Makefile @@ -32,6 +32,7 @@ ${NAME}: ${OBJ} clean: @echo cleaning @rm -f ${NAME} ${OBJ} ${NAME}-${VERSION}.tar.gz + @rm -f bin/${NAME} @find bin -type l -exec rm {} \; dist: clean @@ -53,18 +54,11 @@ bin: ${NAME} @mkdir -p ./bin @cp ${NAME} bin @cd bin; \ - for i in `./${NAME} -l`; \ + for i in `./${NAME} -i`; \ do \ - [ ! -L $$i ] && ln -s ${NAME} $$i; \ + ln -sf ${NAME} $$i; \ done; true -binclean: - @echo cleaning up symlinks in ./bin - @cd bin;\ - find . -lname ${NAME} | xargs rm; \ - [ -e ${NAME} ] && rm ${NAME}; \ - true; - install: all bin @echo installing executable files to ${DESTDIR}${PREFIX}/bin @mkdir -p ${DESTDIR}${PREFIX}/bin @@ -78,13 +72,13 @@ install: all bin cp $$i ${DESTDIR}${PREFIX}/bin; \ chmod 755 ${DESTDIR}${PREFIX}/bin/$$i; \ else \ - ln -fs ${DESTDIR}${PREFIX}/bin/${NAME} \ + ln -sf ${DESTDIR}${PREFIX}/bin/${NAME} \ ${DESTDIR}${PREFIX}/bin/$$i; \ fi \ done; \ true; -uninstall: binclean +uninstall: clean @echo removing executable files from ${DESTDIR}${PREFIX}/bin @cd bin; \ for i in `ls -1`; \ diff --git a/bin/rpedit b/bin/rpedit @@ -58,7 +58,7 @@ then mid=$(rpadd -m $folder -f seen $tmpfile) if [ $? -eq 0 ]; then - rpfscan -m $folder $mid + PAGER= rpscan -m $folder $mid fi else echo "Nothing changed. Aborting." diff --git a/bin/rpfinc b/bin/rpfinc @@ -1,4 +0,0 @@ -#!/bin/sh - -rpinc "$@" | $(rpcfg -b)/tmpl/inc.sh - diff --git a/bin/rpflag b/bin/rpflag @@ -0,0 +1,16 @@ +#!/bin/sh + +TMPL="$(rpcfg -b)/tmpl/flag.sh" + +if [ -t 1 -a -x "$TMPL" ]; +then + if [ -n "$PAGER" ]; + then + rohrpost rpflag "$@" | $TMPL | eval $PAGER + else + rohrpost rpflag "$@" | $TMPL + fi +else + rohrpost rpflag "$@" +fi + diff --git a/bin/rpflagu b/bin/rpflagu @@ -1,4 +0,0 @@ -#!/bin/sh - -rpflag -s "seen" unseen - diff --git a/bin/rpfscan b/bin/rpfscan @@ -1,4 +0,0 @@ -#!/bin/sh - -rpscan "$@" | $(rpcfg -b)/tmpl/scan.sh - diff --git a/bin/rpfscanp b/bin/rpfscanp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpfscan "$@" | eval $PAGER - diff --git a/bin/rpfview b/bin/rpfview @@ -1,4 +0,0 @@ -#!/bin/sh - -rpview "$@" | $(rpcfg -b)/tmpl/view.sh - diff --git a/bin/rpfviewp b/bin/rpfviewp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpfview "$@" | eval $PAGER - diff --git a/bin/rpfwd b/bin/rpfwd @@ -1,6 +1,6 @@ #!/bin/sh -BASE="$(cfg -b)" +BASE="$(rpcfg -b)" usage() { printf "usage. %s [-h] msgids\n" "$(basename $1)" 2>&1 @@ -25,7 +25,7 @@ then exit 1 fi -tmpfile=`mktemp` +tmpfile=$(mktemp) signalh() { rm -f $tmpfile } diff --git a/bin/rpinc b/bin/rpinc @@ -0,0 +1,16 @@ +#!/bin/sh + +TMPL="$(rpcfg -b)/tmpl/inc.sh" + +if [ -t 1 -a -x "$TMPL" ]; +then + if [ -n "$PAGER" ]; + then + rohrpost rpinc "$@" | $TMPL | eval $PAGER + else + rohrpost rpinc "$@" | $TMPL + fi +else + rohrpost rpinc "$@" +fi + diff --git a/bin/rpnews b/bin/rpnews @@ -4,7 +4,7 @@ args="$*" echo $args if [ -z "$args" ]; then - args="unseen" + args="u" fi rpscan $args | $(rpcfg -b)/tmpl/news.sh \ diff --git a/bin/rpnextp b/bin/rpnextp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpnext | eval $PAGER - diff --git a/bin/rppopu b/bin/rppopu @@ -1,4 +0,0 @@ -#!/bin/sh - -rppop unseen - diff --git a/bin/rpprevp b/bin/rpprevp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpprev | eval $PAGER - diff --git a/bin/rpscan b/bin/rpscan @@ -0,0 +1,16 @@ +#!/bin/sh + +TMPL="$(rpcfg -b)/tmpl/scan.sh" + +if [ -t 1 -a -x "$TMPL" ]; +then + if [ -n "$PAGER" ]; + then + rohrpost rpscan "$@" | $TMPL | eval $PAGER + else + rohrpost rpscan "$@" | $TMPL + fi +else + rohrpost rpscan "$@" +fi + diff --git a/bin/rpscanp b/bin/rpscanp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpscan "$@" | eval $PAGER - diff --git a/bin/rpscanu b/bin/rpscanu @@ -1,4 +0,0 @@ -#!/bin/sh - -rpfscan unseen - diff --git a/bin/rpscanup b/bin/rpscanup @@ -1,4 +0,0 @@ -#!/bin/sh - -rpscanu "$@" | eval $PAGER - diff --git a/bin/rpsyncmail b/bin/rpsyncmail @@ -12,6 +12,6 @@ else fi date -rpfinc -nu +PAGER= rpinc -nu echo diff --git a/bin/rptailf b/bin/rptailf @@ -14,7 +14,7 @@ do if [ $num -gt 0 ]; then - rpfview -m $folder unseen + PAGER= rpview -m $folder u fi sleep 60 done diff --git a/bin/rpview b/bin/rpview @@ -0,0 +1,16 @@ +#!/bin/sh + +TMPL="$(rpcfg -b)/tmpl/view.sh" + +if [ -t 1 -a -x "$TMPL" ]; +then + if [ -n "$PAGER" ]; + then + rohrpost rpview "$@" | $TMPL | eval $PAGER + else + rohrpost rpview "$@" | $TMPL + fi +else + rohrpost rpview "$@" +fi + diff --git a/bin/rpviewp b/bin/rpviewp @@ -1,4 +0,0 @@ -#!/bin/sh - -rpview "$@" | eval $PAGER - diff --git a/bin/rpviewu b/bin/rpviewu @@ -1,4 +0,0 @@ -#!/bin/sh - -rpfview "$@" unseen - diff --git a/bin/rpviewup b/bin/rpviewup @@ -1,4 +0,0 @@ -#!/bin/sh - -rpviewu "$@" | eval $PAGER - diff --git a/flag.c b/flag.c @@ -76,7 +76,7 @@ flagsyntax(void) void flagusage(void) { - die("usage: %s [-fht] [-c cfg] [-m folder] [[-s|-d] flag] [msgs]\n" + die("usage: %s [-fhu] [-c cfg] [-m folder] [[-s|-d] flag] [msgs]\n" "Use -f for displaying the flag syntax.\n", argv0); } @@ -94,7 +94,7 @@ flagmain(int argc, char *argv[]) BEQUIET = 0x01, DOSET = 0x02, DODELETE = 0x04, - TABSEP = 0x08, + SETSEEN = 0x08, NOARGS = 0x10 }; @@ -123,14 +123,14 @@ flagmain(int argc, char *argv[]) case 's': status |= DOSET; break; - case 't': - status |= TABSEP; + case 'u': + status |= SETSEEN; break; default: flagusage(); } ARGEND; - if (argc < 1) + if (argc < 1 && !(status & SETSEEN)) flagusage(); if (status & DOSET || status & DODELETE) { @@ -140,7 +140,7 @@ flagmain(int argc, char *argv[]) argc--; argv = &argv[1]; } - if (argc < 1) + if (argc < 1 && !(status & SETSEEN)) flagusage(); cfg = config_init(cfgn); @@ -154,6 +154,22 @@ flagmain(int argc, char *argv[]) } config_free(cfg); + if (status & SETSEEN) { + if (argc == 0) { + argc = 1; + argv = (char *[]){ "unseen", NULL }; + } + + flagl = flag_sanitize("seen"); + if (flagl == NULL) + flagsyntax(); + status |= DOSET; + } + + ids = imap_argv2ids(cfgn, selected, argc, argv); + if (ids == NULL) + die("No msgids selected. Aborting.\n"); + imap = imap_new(netspec, user, pass); free(user); free(pass); @@ -164,15 +180,12 @@ flagmain(int argc, char *argv[]) if (imap_select(imap, selected)) imap_die(imap, "imap_select"); - ids = imap_argv2ids(cfgn, selected, argc, argv); - if (ids == NULL) - die("No msgids selected. Aborting.\n"); - user = imap_ids2str(ids); - if (flagl != NULL) + if (flagl != NULL) { pass = llist_joinstr(flagl, " "); - else + } else { pass = NULL; + } if (status & DOSET) { if (imap_setflags(imap, ids, flagl)) @@ -191,38 +204,37 @@ flagmain(int argc, char *argv[]) pass, user, selected); } } else { + free(user); + flagrl = imap_getflags(imap, ids); if (flagrl == NULL) imap_die(imap, "imap_getflags"); - if (!(status & TABSEP)) - printf("%8s%30s\n", "id", "flags"); + printf("ID\tFlags\n"); + forllist(flagrl, elem) { flagel = (llist_t *)elem->data; user = llist_joinstr((llist_t *)flagel->last->data, " "); if (user == NULL) user = memdup("", 1); - if (status & TABSEP) { - printf("%s\t%s\n", (char *)flagel->first->data, - user); - } else { - printf("%8s%30s\n", - (char *)flagel->first->data, user); - } + printf("%s\t%s\n", (char *)flagel->first->data, user); free(user); + user = NULL; } llist_efree(flagrl); } if (flagl != NULL) llist_free(flagl); - free(user); + if (user != NULL) + free(user); if (pass != NULL) free(pass); free(selected); imap_close(imap); imap_free(imap); + return 0; } diff --git a/inc.c b/inc.c @@ -196,7 +196,7 @@ inc_mkunseen(imap_t *imap, char *cfgn, char *folder) str = llist_joinstr(results, " "); llist_free(results); if (str != NULL) { - mark_set(marks, "unseen", str); + mark_set(marks, "u", str); free(str); } mark_stop(marks); diff --git a/rohrpost.c b/rohrpost.c @@ -37,35 +37,42 @@ char *argv0; void usage(void) { - die("usage: %s [-hl] cmd [args] [range]\n", argv0); + die("usage: %s [-hil] cmd [args] [range]\n", argv0); } struct command { char *cmd; + int flags; int (*main)(int, char **); }; +/* The flag whether to output it on the -i(nstall) request. */ +enum { + DONTINSTALL = 0x00, + DOINSTALL = 0x01 +}; + struct command cmds[] = { - {"rpadd", addmain}, - {"rpcfg", configmain}, - {"rpcp", copymain}, - {"rpcap", capabilitymain}, - {"rpflag", flagmain}, - {"rpfold", foldermain}, - {"rpids", idsmain}, - {"rpmv", movemain}, - {"rppart", partmain}, - {"rppick", pickmain}, - {"rpscan", scanmain}, - {"rpsieve", sievemain}, - {"rpstats", statsmain}, - {"rputil", utilmain}, - {"rpcur", curmain}, - {"rpinc", incmain}, - {"rpmark", markmain}, - {"rprm", removemain}, - {"rpsel", selectmain}, - {"rpview", viewmain}, + {"rpadd", DOINSTALL, addmain}, + {"rpcfg", DOINSTALL, configmain}, + {"rpcp", DOINSTALL, copymain}, + {"rpcap", DOINSTALL, capabilitymain}, + {"rpflag", DONTINSTALL, flagmain}, + {"rpfold", DOINSTALL, foldermain}, + {"rpids", DOINSTALL, idsmain}, + {"rpmv", DOINSTALL, movemain}, + {"rppart", DOINSTALL, partmain}, + {"rppick", DOINSTALL, pickmain}, + {"rpscan", DONTINSTALL, scanmain}, + {"rpsieve", DOINSTALL, sievemain}, + {"rpstats", DOINSTALL, statsmain}, + {"rputil", DOINSTALL, utilmain}, + {"rpcur", DOINSTALL, curmain}, + {"rpinc", DONTINSTALL, incmain}, + {"rpmark", DOINSTALL, markmain}, + {"rprm", DOINSTALL, removemain}, + {"rpsel", DOINSTALL, selectmain}, + {"rpview", DONTINSTALL, viewmain}, }; int @@ -76,21 +83,27 @@ main(int argc, char *argv[]) for (i = 0; i < nelem(cmds); i++) { lsl = strrchr(argv[0], '/'); - if (lsl == NULL) + if (lsl == NULL) { lsl = argv[0]; - else + } else { lsl++; + } if (!strcmp(lsl, cmds[i].cmd)) return cmds[i].main(argc, argv); } ARGBEGIN { + case 'i': + for (i = 0; i < nelem(cmds); i++) { + if (cmds[i].flags & DOINSTALL) + printf("%s\n", cmds[i].cmd); + } + return 0; case 'l': for (i = 0; i < nelem(cmds); i++) printf("%s\n", cmds[i].cmd); return 0; - case 'h': default: usage(); } ARGEND;