@@ -142,8 +142,6 @@ bootstrap_root="${bootstrap_file:A:h:h}"
142142 # global variable for mutt options
143143 vars+=(muttflags)
144144
145- autoload colors; colors
146-
147145 # which command to use when creating dirs
148146 mkdir=" ` command -v mkdir` -m 700 -p"
149147
@@ -170,8 +168,6 @@ bootstrap_root="${bootstrap_file:A:h:h}"
170168
171169 # own mblaze workdir and init empty sequence
172170 export MBLAZE=" $MAILDIRS /cache/mblaze"
173- mkdir -p " ${MBLAZE} "
174- touch ${MBLAZE} /seq
175171
176172 PATH=" $WORKDIR /bin:$PATH "
177173
@@ -239,51 +235,25 @@ bootstrap_root="${bootstrap_file:A:h:h}"
239235}
240236
241237# binary programs recognition
242- check_bin () {
243- # required programs
244- for req in pinentry fetchmail gpg msmtp; do
238+ check_required_bins () {
239+ for req in " $@ " ; do
245240 isfound $req
246241 { test $? ! = 0 } && {
247242 error " Cannot find $req . Please install it."
248243 exit 1
249244 }
250245 done
246+ }
251247
252- # make sure a gnupg dir exists
248+ ensure_gnupg_dir () {
253249 { test -r $HOME /.gnupg/pubring.gpg } || {
254250 ${=mkdir} $HOME /.gnupg
255251 touch $HOME /.gnupg/pubring.gpg
256252 touch $HOME /.gnupg/secring.gpg
257253 }
254+ }
258255
259- # which find command to use
260- case $OS in
261- GNU) find=" find -O3" ;;
262- MAC) find=" gfind -O3" ;;
263- * ) find=" find"
264- esac
265-
266- # which wipe command to use
267- if isfound wipe; then
268- rm=" wipe -f -s -q -R /dev/urandom"
269- elif isfound srm; then
270- rm=" srm -m"
271- else
272- rm=" rm -f"
273- fi
274- func " Rm binary: $rm "
275-
276- # which mutt binary to use
277- if isfound mutt; then
278- mutt_exec=mutt
279- elif isfound neomutt; then
280- mutt_exec=neomutt
281- fi
282- pgpewrap=" ${WORKDIR} /bin/gpgewrap"
283- dotlock=" ${WORKDIR} /bin/dotlock"
284-
285- func " Mutt binary: $mutt_exec "
286- func " Notmuch binary: ` command -v notmuch` "
256+ check_keyring () {
287257 func " Keyring set: $JARO_KEYRING "
288258 if [[ " $JARO_KEYRING " == " " ]]; then
289259 # check for pass, else fallback
@@ -324,6 +294,79 @@ check_bin() {
324294 GNOMEKEY=1 ;;
325295 esac
326296 fi
297+ }
298+
299+ ensure_mutt () {
300+ if isfound mutt; then
301+ mutt_exec=mutt
302+ elif isfound neomutt; then
303+ mutt_exec=neomutt
304+ else
305+ error " Cannot find mutt or neomutt. Please install one."
306+ exit 1
307+ fi
308+ func " Mutt binary: $mutt_exec "
309+ }
310+
311+ mblaze_ensure () {
312+ export MBLAZE=${MBLAZE:- " $MAILDIRS /cache/mblaze" }
313+ mkdir -p " ${MBLAZE} "
314+ touch " ${MBLAZE} /seq"
315+ }
316+
317+ check_bin () {
318+ local cmd=" ${1:- $subcommand } "
319+
320+ # which find command to use
321+ case $OS in
322+ GNU) find=" find -O3" ;;
323+ MAC) find=" gfind -O3" ;;
324+ * ) find=" find"
325+ esac
326+
327+ # which wipe command to use
328+ if isfound wipe; then
329+ rm=" wipe -f -s -q -R /dev/urandom"
330+ elif isfound srm; then
331+ rm=" srm -m"
332+ else
333+ rm=" rm -f"
334+ fi
335+ func " Rm binary: $rm "
336+
337+ pgpewrap=" ${WORKDIR} /bin/gpgewrap"
338+ dotlock=" ${WORKDIR} /bin/dotlock"
339+
340+ case " $cmd " in
341+ fetch)
342+ check_required_bins pinentry fetchmail gpg
343+ ensure_gnupg_dir
344+ check_keyring
345+ ;;
346+ send|smtp)
347+ check_required_bins pinentry gpg msmtp
348+ ensure_gnupg_dir
349+ check_keyring
350+ ;;
351+ peek|open|compose|__empty|__unknown:* )
352+ ensure_mutt
353+ [[ " $cmd " = " peek" ]] && {
354+ check_required_bins pinentry gpg
355+ ensure_gnupg_dir
356+ check_keyring
357+ }
358+ ;;
359+ passwd|askpass)
360+ check_required_bins pinentry gpg
361+ ensure_gnupg_dir
362+ check_keyring
363+ ;;
364+ init|wizard)
365+ check_required_bins pinentry gpg
366+ ensure_gnupg_dir
367+ check_keyring
368+ ;;
369+ esac
327370
328371 return 0
329372}
0 commit comments