mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit d50bfcecbaae8740d3da1250dd4c0f2561392b18
parent 8d3fa82d8246a08d2c7899963ad7cf61b7a4563c
Author: Christian Neukirchen <chneukirchen@gmail.com>
Date:   Fri,  2 Sep 2016 23:52:14 +0200

Merge pull request #3 from escondida/profiles

Add $MBLAZE environment variable to set profile location
Diffstat:
contrib/mpeek | 2+-
man/mblaze.7 | 4++--
man/mcom.1 | 8++++++--
man/mgenmid.1 | 4++--
man/mseq.1 | 8++++++--
man/mshow.1 | 2+-
mcom | 19+++++++++++++------
mgenmid.c | 5+++--
mless | 8+++++++-
mscan.c | 2+-
mseq.c | 2+-
mshow.c | 2+-
seq.c | 16++++++++++++----
13 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/contrib/mpeek b/contrib/mpeek @@ -1,7 +1,7 @@ #!/bin/sh # mpeek - wrapper around mscan with a different seq -export MAILSEQ=$HOME/.mblaze/peek.seq +export MAILSEQ=${MBLAZE:-$HOME/.mblaze}/peek.seq if [ -t 0 ]; then mseq "$@" diff --git a/man/mblaze.7 b/man/mblaze.7 @@ -144,9 +144,9 @@ As usual with pipes, the sky is the limit. deals with messages (which are files), folders (which are Maildir folders), sequences (which are newline-separated lists of messages, possibly persisted on disk in -.Pa ~/.mblaze/seq ) , +.Pa ${MBLAZE:-$HOME/.mblaze}/seq ) , and the current message (kept as a symlink in -.Pa ~/.mblaze/cur ) . +.Pa ${MBLAZE:-$HOME/.mblaze}/cur ) . .Pp Messages in the persisted sequence can be referred to using special syntax as explained in diff --git a/man/mcom.1 b/man/mcom.1 @@ -47,17 +47,21 @@ Delete the draft and quit. .Bl -tag -width Ds .It Ev EDITOR Editor used to compose mail. +.It Ev MBLAZE +Directory containing mblaze configuration. +(Default: +.Pa $HOME/.mblaze ) .El .Sh FILES .Bl -tag -width Ds .It Pa snd.* Draft messages (kept in current directory) -.It Pa ~/.mblaze/headers +.It Pa ${MBLAZE:-$HOME/.mblaze}/headers Default headers for each mail. (Put your .Sq Li From\&: line there.) -.It Pa ~/.signature +.It Pa ${MBLAZE:-$HOME/.mblaze}/signature || ~/.signature Default signature. .El .Sh EXIT STATUS diff --git a/man/mgenmid.1 b/man/mgenmid.1 @@ -19,7 +19,7 @@ The fully qualified domain name is computed by: Using .Sq Li "FQDN:" from -.Pa "~/.mblaze/profile" +.Pa "${MBLAZE:-$HOME/.mblaze}/profile" (if set). .It Resolving the current hostname. @@ -27,7 +27,7 @@ Resolving the current hostname. Using the host part of the address in .Sq Li "Local-Mailbox:" from -.Pa "~/.mblaze/profile" +.Pa "${MBLAZE:-$HOME/.mblaze}/profile" (if set). .El .Pp diff --git a/man/mseq.1 b/man/mseq.1 @@ -68,10 +68,14 @@ and exit. .El .Sh ENVIRONMENT .Bl -tag -width Ds +.It Ev MBLAZE +Directory containing mblaze configuration. +(Default: +.Pa $HOME/.mblaze ) .It Ev MAILCUR Symbolic link referring to the current message. (Default: -.Pa ~/.mblaze/cur ) +.Pa ${MBLAZE:-$HOME/.mblaze}/cur ) .It Ev MAILDOT When set to a file name, overrides the current message. (Prefer using @@ -80,7 +84,7 @@ instead.) .It Ev MAILSEQ File were the sequence is stored. (Default: -.Pa ~/.mblaze/seq ) +.Pa ${MBLAZE:-$HOME/.mblaze}/seq ) .El .Sh EXIT STATUS .Ex -std diff --git a/man/mshow.1 b/man/mshow.1 @@ -99,7 +99,7 @@ parts, and re-encodes them into UTF-8 if necessary. .Pp Other filters can be specified in the file -.Pa ~/.mblaze/filter +.Pa ${MBLAZE:-$HOME/.mblaze}/filter in the format .D1 Ar type/subtype Ns Li \&: Ar command or diff --git a/mcom b/mcom @@ -18,7 +18,8 @@ msgdate() { mdate } -outbox=$(mhdr -h outbox ~/.mblaze/profile) +MBLAZE=${MBLAZE:-$HOME/.mblaze} +outbox=$(mhdr -h outbox "$MBLAZE/profile") if [ -z "$outbox" ]; then i=0 while [ -f "snd.$i" ]; do @@ -43,9 +44,9 @@ fi echo "Cc: " echo "Bcc: " echo "Subject: " - from=$(mhdr -h local-mailbox ~/.mblaze/profile) + from=$(mhdr -h local-mailbox "$MBLAZE/profile") [ "$from" ] && echo "From: $from" - cat ~/.mblaze/headers 2>/dev/null + cat "$MBLAZE/headers" 2>/dev/null msgid msgdate echo @@ -59,7 +60,7 @@ fi echo "Cc: $(mhdr -d -A -h to:cc: "$1" | commajoin)" echo "Bcc: " echo "Subject: Re: $(mscan -f '%S' "$1")" - cat ~/.mblaze/headers 2>/dev/null + cat "$MBLAZE/headers" 2>/dev/null mid=$(mhdr -h message-id "$1") if [ "$mid" ]; then echo -n "References:" @@ -77,9 +78,15 @@ fi echo esac - if [ -f ~/.signature ]; then + if [ -f "$MBLAZE/signature" ]; then + SIGNATURE="$MBLAZE/signature" + elif [ -f ~/.signature ]; then + SIGNATURE="$HOME/.signature" + fi + + if [ -n "$SIGNATURE" ]; then printf '%s\n' '-- ' - cat ~/.signature + cat "$SIGNATURE" fi } >$draft diff --git a/mgenmid.c b/mgenmid.c @@ -31,7 +31,7 @@ int main() char hostbuf[1024]; char *host = 0; - char *f = blaze822_home_file(".mblaze/profile"); + char *f = blaze822_home_file("profile"); struct message *config = blaze822(f); if (config) // try FQDN: first @@ -74,7 +74,8 @@ int main() if (!host) { fprintf(stderr, "mgenmid: failed to find a FQDN for the Message-ID.\n" - " Define 'FQDN:' or 'Local-Mailbox:' in ~/.mblaze/profile\n" + " Define 'FQDN:' or 'Local-Mailbox:' in" + " ${MBLAZE:-$HOME/.mblaze}/profile\n" " or add a FQDN to /etc/hosts.\n"); exit(1); } diff --git a/mless b/mless @@ -65,7 +65,13 @@ nl=" export MLESS_RAW=0 export MLESS_HTML=0 while :; do - [ -f $HOME/.mless ] && export LESSKEY=$HOME/.mless + if [ -f $MBLAZE/mless ]; then + export LESSKEY=$MBLAZE/mless + elif [ -f $HOME/.mblaze/mless ]; then + export LESSKEY=$HOME/.mblaze/mless + elif [ -f $HOME/.mless ]; then + export LESSKEY=$HOME/.mless + fi LESSOPEN="|$0 --filter %s" \ less -Ps"mless %f?m (message %i of %m).." -R \ "+:e $(mscan -n .)$nl" //scan $(mscan -n :) diff --git a/mscan.c b/mscan.c @@ -517,7 +517,7 @@ main(int argc, char *argv[]) if (cols <= 40) cols = 80; - char *f = blaze822_home_file(".mblaze/profile"); + char *f = blaze822_home_file("profile"); struct message *config = blaze822(f); if (config) { diff --git a/mseq.c b/mseq.c @@ -186,7 +186,7 @@ stdinmode() // XXX locking? seqfile = getenv("MAILSEQ"); if (!seqfile) - seqfile = blaze822_home_file(".mblaze/seq"); + seqfile = blaze822_home_file("seq"); snprintf(tmpfile, sizeof tmpfile, "%s-", seqfile); snprintf(oldfile, sizeof oldfile, "%s.old", seqfile); outfile = fopen(tmpfile, "w+"); diff --git a/mshow.c b/mshow.c @@ -728,7 +728,7 @@ main(int argc, char *argv[]) if (!(qflag || rflag)) { char *f = getenv("MAILFILTER"); if (!f) - f = blaze822_home_file(".mblaze/filter"); + f = blaze822_home_file("filter"); if (f) filters = blaze822(f); } diff --git a/seq.c b/seq.c @@ -21,6 +21,14 @@ blaze822_home_file(char *basename) { static char path[PATH_MAX]; static char *homedir; + static char *profile; + + if (!profile) + profile = getenv("MBLAZE"); + if (profile) { + snprintf(path, sizeof path, "%s/%s", profile, basename); + return path; + } if (!homedir) homedir = getenv("HOME"); @@ -34,7 +42,7 @@ blaze822_home_file(char *basename) if (!homedir) return "/dev/null/homeless"; - snprintf(path, sizeof path, "%s/%s", homedir, basename); + snprintf(path, sizeof path, "%s/.mblaze/%s", homedir, basename); return path; } @@ -49,7 +57,7 @@ blaze822_seq_open(char *file) if (!file) file = getenv("MAILSEQ"); if (!file) - file = blaze822_home_file(".mblaze/seq"); + file = blaze822_home_file("seq"); fd = open(file, O_RDONLY); if (!fd) return 0; @@ -138,7 +146,7 @@ blaze822_seq_cur(void) char *curlink = getenv("MAILCUR"); if (!curlink) - curlink = blaze822_home_file(".mblaze/cur"); + curlink = blaze822_home_file("cur"); int r = readlink(curlink, b, sizeof b - 1); if (r < 0) @@ -157,7 +165,7 @@ blaze822_seq_setcur(char *s) char curtmplink[PATH_MAX]; char *curlink = getenv("MAILCUR"); if (!curlink) - curlink = blaze822_home_file(".mblaze/cur"); + curlink = blaze822_home_file("cur"); if (snprintf(curtmplink, sizeof curtmplink, "%s-", curlink) >= PATH_MAX) return -1; // truncation