Add $MBLAZE environment variable to set profile location

As a side benefit, all callers of blaze822_home_file need only pass
the filename, so the base directory is set in only one place.
pull/3/head
Ivy Foster 8 years ago
parent 8d3fa82d82
commit ca8cef1660

@ -87,10 +87,11 @@ EXAMPLES
As usual with pipes, the sky is the limit. As usual with pipes, the sky is the limit.
CONCEPTS CONCEPTS
mblaze deals with messages (which are files), folders (which are Maildir mblaze deals with messages (which are files), folders (which are
folders), sequences (which are newline-separated lists of messages, Maildir folders), sequences (which are newline-separated lists of
possibly persisted on disk in ~/.mblaze/seq), and the current message messages, possibly persisted on disk in
(kept as a symlink in ~/.mblaze/cur). ${MBLAZE:-$HOME/.mblaze}/seq), and the current message
(kept as a symlink in ${MBLAZE:-$HOME/.mblaze}/cur).
Messages in the persisted sequence can be referred to using special Messages in the persisted sequence can be referred to using special
syntax as explained in mmsg(7). syntax as explained in mmsg(7).

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# mpeek - wrapper around mscan with a different seq # 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 if [ -t 0 ]; then
mseq "$@" mseq "$@"

@ -144,9 +144,9 @@ As usual with pipes, the sky is the limit.
deals with messages (which are files), deals with messages (which are files),
folders (which are Maildir folders), folders (which are Maildir folders),
sequences (which are newline-separated lists of messages, possibly persisted on disk in 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 and the current message (kept as a symlink in
.Pa ~/.mblaze/cur ) . .Pa ${MBLAZE:-$HOME/.mblaze}/cur ) .
.Pp .Pp
Messages in the persisted sequence can be referred to using special Messages in the persisted sequence can be referred to using special
syntax as explained in syntax as explained in

@ -47,17 +47,21 @@ Delete the draft and quit.
.Bl -tag -width Ds .Bl -tag -width Ds
.It Ev EDITOR .It Ev EDITOR
Editor used to compose mail. Editor used to compose mail.
.It Ev MBLAZE
Directory containing mblaze configuration.
(Default:
.Pa $HOME/.mblaze)
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width Ds .Bl -tag -width Ds
.It Pa snd.* .It Pa snd.*
Draft messages (kept in current directory) Draft messages (kept in current directory)
.It Pa ~/.mblaze/headers .It Pa ${MBLAZE:-$HOME/.mblaze}/headers
Default headers for each mail. Default headers for each mail.
(Put your (Put your
.Sq Li From\&: .Sq Li From\&:
line there.) line there.)
.It Pa ~/.signature .It Pa ${MBLAZE:-$HOME/.mblaze}/signature || ~/.signature
Default signature. Default signature.
.El .El
.Sh EXIT STATUS .Sh EXIT STATUS

@ -19,7 +19,7 @@ The fully qualified domain name is computed by:
Using Using
.Sq Li "FQDN:" .Sq Li "FQDN:"
from from
.Pa "~/.mblaze/profile" .Pa "${MBLAZE:-$HOME/.mblaze}/profile"
(if set). (if set).
.It .It
Resolving the current hostname. Resolving the current hostname.
@ -27,7 +27,7 @@ Resolving the current hostname.
Using the host part of the address in Using the host part of the address in
.Sq Li "Local-Mailbox:" .Sq Li "Local-Mailbox:"
from from
.Pa "~/.mblaze/profile" .Pa "${MBLAZE:-$HOME/.mblaze}/profile"
(if set). (if set).
.El .El
.Pp .Pp

@ -68,10 +68,14 @@ and exit.
.El .El
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Bl -tag -width Ds .Bl -tag -width Ds
.It Ev MBLAZE
Directory containing mblaze configuration.
(Default:
.Pa $HOME/.mblaze)
.It Ev MAILCUR .It Ev MAILCUR
Symbolic link referring to the current message. Symbolic link referring to the current message.
(Default: (Default:
.Pa ~/.mblaze/cur ) .Pa ${MBLAZE:-$HOME/.mblaze}/cur )
.It Ev MAILDOT .It Ev MAILDOT
When set to a file name, overrides the current message. When set to a file name, overrides the current message.
(Prefer using (Prefer using
@ -80,7 +84,7 @@ instead.)
.It Ev MAILSEQ .It Ev MAILSEQ
File were the sequence is stored. File were the sequence is stored.
(Default: (Default:
.Pa ~/.mblaze/seq ) .Pa ${MBLAZE:-$HOME/.mblaze}/seq )
.El .El
.Sh EXIT STATUS .Sh EXIT STATUS
.Ex -std .Ex -std

@ -99,7 +99,7 @@ parts,
and re-encodes them into UTF-8 if necessary. and re-encodes them into UTF-8 if necessary.
.Pp .Pp
Other filters can be specified in the file Other filters can be specified in the file
.Pa ~/.mblaze/filter .Pa ${MBLAZE:-$HOME/.mblaze}/filter
in the format in the format
.D1 Ar type/subtype Ns Li \&: Ar command .D1 Ar type/subtype Ns Li \&: Ar command
or or

21
mcom

@ -18,7 +18,8 @@ msgdate() {
mdate mdate
} }
outbox=$(mhdr -h outbox ~/.mblaze/profile) MBLAZE=${MBLAZE:-$HOME/.mblaze}
outbox=$(mhdr -h outbox $MBLAZE/profile)
if [ -z "$outbox" ]; then if [ -z "$outbox" ]; then
i=0 i=0
while [ -f "snd.$i" ]; do while [ -f "snd.$i" ]; do
@ -43,9 +44,9 @@ fi
echo "Cc: " echo "Cc: "
echo "Bcc: " echo "Bcc: "
echo "Subject: " echo "Subject: "
from=$(mhdr -h local-mailbox ~/.mblaze/profile) from=$(mhdr -h local-mailbox $MBLAZE/profile)
[ "$from" ] && echo "From: $from" [ "$from" ] && echo "From: $from"
cat ~/.mblaze/headers 2>/dev/null cat $MBLAZE/headers 2>/dev/null
msgid msgid
msgdate msgdate
echo echo
@ -59,7 +60,7 @@ fi
echo "Cc: $(mhdr -d -A -h to:cc: "$1" | commajoin)" echo "Cc: $(mhdr -d -A -h to:cc: "$1" | commajoin)"
echo "Bcc: " echo "Bcc: "
echo "Subject: Re: $(mscan -f '%S' "$1")" 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") mid=$(mhdr -h message-id "$1")
if [ "$mid" ]; then if [ "$mid" ]; then
echo -n "References:" echo -n "References:"
@ -77,9 +78,17 @@ fi
echo echo
esac esac
if [ -f ~/.signature ]; then if [ -f $MBLAZE/signature ]; then
SIGNATURE=$MBLAZE/signature
elif [ -f $HOME/.mblaze/signature ]; then
SIGNATURE=$HOME/.mblaze/signature
elif [ -f ~/.signature ]; then
SIGNATURE=$HOME/.signature
fi
if [ ! -z $SIGNATURE ]; then
printf '%s\n' '-- ' printf '%s\n' '-- '
cat ~/.signature cat $SIGNATURE
fi fi
} >$draft } >$draft

@ -31,7 +31,7 @@ int main()
char hostbuf[1024]; char hostbuf[1024];
char *host = 0; char *host = 0;
char *f = blaze822_home_file(".mblaze/profile"); char *f = blaze822_home_file("profile");
struct message *config = blaze822(f); struct message *config = blaze822(f);
if (config) // try FQDN: first if (config) // try FQDN: first
@ -74,7 +74,8 @@ int main()
if (!host) { if (!host) {
fprintf(stderr, fprintf(stderr,
"mgenmid: failed to find a FQDN for the Message-ID.\n" "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"); " or add a FQDN to /etc/hosts.\n");
exit(1); exit(1);
} }

@ -65,7 +65,13 @@ nl="
export MLESS_RAW=0 export MLESS_RAW=0
export MLESS_HTML=0 export MLESS_HTML=0
while :; do 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" \ LESSOPEN="|$0 --filter %s" \
less -Ps"mless %f?m (message %i of %m).." -R \ less -Ps"mless %f?m (message %i of %m).." -R \
"+:e $(mscan -n .)$nl" //scan $(mscan -n :) "+:e $(mscan -n .)$nl" //scan $(mscan -n :)

@ -517,7 +517,7 @@ main(int argc, char *argv[])
if (cols <= 40) if (cols <= 40)
cols = 80; cols = 80;
char *f = blaze822_home_file(".mblaze/profile"); char *f = blaze822_home_file("profile");
struct message *config = blaze822(f); struct message *config = blaze822(f);
if (config) { if (config) {

@ -186,7 +186,7 @@ stdinmode()
// XXX locking? // XXX locking?
seqfile = getenv("MAILSEQ"); seqfile = getenv("MAILSEQ");
if (!seqfile) if (!seqfile)
seqfile = blaze822_home_file(".mblaze/seq"); seqfile = blaze822_home_file("seq");
snprintf(tmpfile, sizeof tmpfile, "%s-", seqfile); snprintf(tmpfile, sizeof tmpfile, "%s-", seqfile);
snprintf(oldfile, sizeof oldfile, "%s.old", seqfile); snprintf(oldfile, sizeof oldfile, "%s.old", seqfile);
outfile = fopen(tmpfile, "w+"); outfile = fopen(tmpfile, "w+");

@ -728,7 +728,7 @@ main(int argc, char *argv[])
if (!(qflag || rflag)) { if (!(qflag || rflag)) {
char *f = getenv("MAILFILTER"); char *f = getenv("MAILFILTER");
if (!f) if (!f)
f = blaze822_home_file(".mblaze/filter"); f = blaze822_home_file("filter");
if (f) if (f)
filters = blaze822(f); filters = blaze822(f);
} }

16
seq.c

@ -21,6 +21,14 @@ blaze822_home_file(char *basename)
{ {
static char path[PATH_MAX]; static char path[PATH_MAX];
static char *homedir; 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) if (!homedir)
homedir = getenv("HOME"); homedir = getenv("HOME");
@ -34,7 +42,7 @@ blaze822_home_file(char *basename)
if (!homedir) if (!homedir)
return "/dev/null/homeless"; return "/dev/null/homeless";
snprintf(path, sizeof path, "%s/%s", homedir, basename); snprintf(path, sizeof path, "%s/.mblaze/%s", homedir, basename);
return path; return path;
} }
@ -49,7 +57,7 @@ blaze822_seq_open(char *file)
if (!file) if (!file)
file = getenv("MAILSEQ"); file = getenv("MAILSEQ");
if (!file) if (!file)
file = blaze822_home_file(".mblaze/seq"); file = blaze822_home_file("seq");
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (!fd) if (!fd)
return 0; return 0;
@ -138,7 +146,7 @@ blaze822_seq_cur(void)
char *curlink = getenv("MAILCUR"); char *curlink = getenv("MAILCUR");
if (!curlink) if (!curlink)
curlink = blaze822_home_file(".mblaze/cur"); curlink = blaze822_home_file("cur");
int r = readlink(curlink, b, sizeof b - 1); int r = readlink(curlink, b, sizeof b - 1);
if (r < 0) if (r < 0)
@ -157,7 +165,7 @@ blaze822_seq_setcur(char *s)
char curtmplink[PATH_MAX]; char curtmplink[PATH_MAX];
char *curlink = getenv("MAILCUR"); char *curlink = getenv("MAILCUR");
if (!curlink) if (!curlink)
curlink = blaze822_home_file(".mblaze/cur"); curlink = blaze822_home_file("cur");
if (snprintf(curtmplink, sizeof curtmplink, "%s-", curlink) >= PATH_MAX) if (snprintf(curtmplink, sizeof curtmplink, "%s-", curlink) >= PATH_MAX)
return -1; // truncation return -1; // truncation

Loading…
Cancel
Save