-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmb
executable file
·719 lines (690 loc) · 19.5 KB
/
mb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#!/bin/ksh
# mb [-nqv1] [folder [command...]] - thin REPL for mblaze(7)
# If invoked with -n, we display only new mail in whatever folder
# we're examining, which by default is your inbox as configured in
# ~/.mblaze/profile or in the envar INBOX. See the README.md file for
# more on configuration.
#
# If invoked with -q, we skip listing the folder and printing a usage
# summary at start (quiet start).
#
# Any additional arguments beyond the folder are interpreted as a command
# and executed immediately upon startup.
#
# If the -1 option is given, then we do not drop into the main loop
# and instead only execute whatever command was given as arguments and exit.
#
# Switch between new/cur sides of a Maildir w/the new/cur commands.
#
# The help system is based on hash-plus comments in this script, c.f
# the give_help function, below. References in the code/docs to
# mblaze commands look like mhdr(1).
#
# type "brief" at the prompt for a brief usage summary
# type "help" for one-line summaries on each command
# type "help <cmd>" for more detailed help on <cmd>
# hit ^\ for a brief status report on the current folder
# use ^C to interrupt something, you land back in the loop
#
# This script comes with a small Perl program, rl, which uses GNU
# ReadLine and handles history. For it to work you have to have the
# Term::ReadLine::Gnu Perl module installed on your system (pkg_add
# p5-Term-ReadLine-Gnu on OpenBSD).
alias my=typeset
# pirate version:
# alias me=typeset
SCRIPT=$0
OUR_CMDS=$(grep '#[+]' $SCRIPT | \
sed -e 's/^.*#[+] //' | \
awk '{ print $1 }' | sort -u)
OUR_CMDLIST=$(echo ${OUR_CMDS} | sed -e 's/ /,/g')
# query config in ~/.mblaze/profile with mhdr(1)
MBLAZE=${MBLAZE-$HOME/.mblaze}
profile="$MBLAZE/profile"
cfglook () {
mhdr -h $* | envsubst
}
basedir=$(cfglook MaildirBase $profile)
basedir=${basedir-$HOME/mail}
inbox_name=$(cfglook InboxName $profile)
[ -z "${inbox_name}" ] && inbox_name=INBOX
inbox=$(cfglook Inbox $profile)
[ -z "${inbox}" ] && inbox=${basedir}/${inbox_name}
editor_cmd=$(cfglook Editor $profile)
[ -z "${editor_cmd}" ] && editor_cmd=${EDITOR-${VISUAL-vi}}
EDITOR=${EDITOR-$editor_cmd}
mdopts=$(cfglook MdisplayOpts $profile)
synchost=$(cfglook SyncHost $profile)
synccmd=$(cfglook SyncCmd $profile)
[ -z "${synccmd}" ] && synccmd="rsync -azv"
syncrmt=$(cfglook SyncRemoteDir $profile)
[ -z "${syncrmt}" ] && syncrmt=$HOME
mairix=$(cfglook MairixCmd $profile)
[ -z "${mairix}" ] && mairix=mairix
index_opts=$(cfglook MairixIndexOpts $profile)
CMD=$(cfglook MBDefaultCmd $profile)
[ -z "$CMD" ] && CMD=minbox
shell_cmd=$(cfglook ShellEscapeCmd $profile)
[ -z "${shell_cmd}" ] && shell_cmd=${SHELL-/bin/sh}
rl_cmd=$(cfglook MBReadLineCmd $profile)
rl_from_profile=0
[ -n "${rl_cmd}" ] && rl_from_profile=1
[ -z "${rl_cmd}" ] && rl_cmd=rl
if [ $rl_from_profile -eq 0 ]; then
rl_hist=$(cfglook MBHistoryFile $profile)
[ -n "${rl_hist}" ] && rl_cmd="${rl_cmd} -F ${rl_hist}"
rl_maxhist=$(cfglook MBHistoryMax $profile)
[ -n "${rl_maxhist}" ] && rl_cmd="${rl_cmd} -X ${rl_maxhist}"
fi
rl_cmd="${rl_cmd} -C ${OUR_CMDLIST} -D ${basedir}"
quiet_start=$(cfglook MBStartQuiet $profile)
[ -z "${quiet_start}" ] && quiet_start=0
expert=$(cfglook MBExpert $profile)
[ -z "${expert}" ] && expert=0
# parse command-line args
VERBOSE=0
f=
only_one=0
args=$(getopt vnq1 $*)
if [ $? -ne 0 ]; then
echo usage: $(basename $SCRIPT) [-nqv1] [folder [cmd...]]
exit 1
fi
set -- $args
while [ $# -ne 0 ]; do
case "$1" in
-1) only_one=1; shift ;;
-n) CMD=mnewbox; shift ;;
-q) quiet_start=1; shift ;;
-v) VERBOSE=1; shift ;;
--) shift; break ;;
esac
done
if [ $# -gt 0 ]; then
f=$1
shift
[ $f = "-" ] && f=""
fi
# set FOLDER and CMD
[ -n "$f" ] && FOLDER=$f
[ -z "${FOLDER}" ] && FOLDER=${INBOX-$inbox_name}
new=
[ "${CMD}" = "mnewbox" ] && new='*'
verbose () {
if [ $VERBOSE -ne 0 ]; then
echo $@
fi
}
export FOLDER # for subprocesses
# common back-end to mcom/mfwd/mrep
tmux_send () {
my cmd args msgno fullcmd title
cmd=$1
shift
case ${cmd} in
mcom)
fullcmd="${cmd} $*"
title="compose"
;;
mfwd|mrep)
args=$(set_args $*)
msgno=$(tmux show-buffer)
title="reply"
[ ${cmd} = mfwd ] && title="fwd"
title="${title} ${msgno}"
fullcmd="${cmd} ${args} -- ${msgno}"
;;
esac
tmux new-window -n "[$title]" \
"echo ${fullcmd}; env EDITOR=$EDITOR ${fullcmd}; \
echo '[PRESS RETURN TO CLOSE]'; read"
}
# invoke the various names of mcom(1) in a new tmux window
reply () {
tmux_send mrep $*
}
send () {
tmux_send mcom $*
}
fwd () {
tmux_send mfwd $*
}
# rescan current folder and display the current sequence
rescan () {
my nothing afterargs
nothing=$1
shift
afterargs="$*"
[ -n "${CMD}" ] && {
typeset _cmd=${CMD}
if [ ${nothing} = inbox ]; then
FOLDER=${INBOX-$inbox_name}
elif [ ${nothing} = cd ]; then
[ -z "${afterargs}" ] && afterargs=${INBOX-$inbox_name}
FOLDER=${afterargs}
elif [ ${nothing} = dir ]; then
_cmd="env MB_PURTY=1 ${CMD}"
fi
echo ${_cmd} ${FOLDER}
${_cmd} ${FOLDER}
}
}
# deal with [msgno] [args...]
# if our first arg looks like a number, set msgno/tmux-buffer
# and shift it out.
# return what is left
set_args () {
my the_args
the_args="$*"
case ${the_args} in
[0-9]*)
set -- ${the_args}
tmux set-buffer $1
shift
the_args="$*"
;;
esac
echo ${the_args}
}
# like set_args but for the extract/mime/show cases msgno can be
# implicit, if first arg is numeric but within the range
# 1..$number_attachments of cur message, don't treat it as a msg#,
# treat it as attachment#
special_args () {
my the_args cur natt done=0
the_args="$*"
cur=$(tmux show-buffer)
while [ $# -gt 0 -a $done -eq 0 ]; do
case $1 in
[0-9]*)
if [ -n "${cur}" ]; then
natt=$(mshow -t ${cur} |tail -1 | \
awk -F: '{print $1}')
if [ $1 -gt $natt ]; then
tmux set-buffer $1
cur="$1"
fi
shift
# else it is an attachment#, leave args alone
else
tmux set-buffer $1
shift
the_args="$*"
cur="$1"
fi
;;
*)
done=1
;;
esac
done
echo "$the_args"
}
filter_args () {
my done=0
while [ $# -gt 0 -a $done -eq 0 ]; do
case $1 in
[0-9]*)
shift
;;
*)
done=1
;;
esac
done
echo "$*"
}
# search this script for hash-plus comments and display them in various ways
give_help () {
my cmds cmd
# get the list of commands for starters, alpha-sorted
cmds=$OUR_CMDS
case $1 in
help)
# if they give us a specific command find help for it
# otherwise, dump all the help summaries (first lines)
if [ -z "$2" ]; then
for cmd in ${cmds}; do
grep "#[+] $cmd " $SCRIPT | head -1 | \
sed -e 's/^.*#[+] //'
done
else
# print all the help for a specific command
grep "#[+] $2 " $SCRIPT | \
sed -e 's/^.*#[+] //' | head -1
grep "#[+] $2 " $SCRIPT | \
sed -e 1d -e "s/^.*#[+] $2 / /" | fmt
fi
;;
brief)
echo "commands/topics:"
echo ${cmds} | rs
echo "type msg# / sel msg# w/mouse in tmux and use . to see in new pane"
echo "use: brief for this short help again, help <topic> for longer help"
echo "sigs: ^\ (QUIT) = cur folder status, ^C (INT) = quit gracefully"
;;
man)
if [ -z "$2" ]; then
echo "man what?"
else
man $2
fi
;;
esac
}
usage () {
echo "usage: $*"
}
# handle one command and optional args
process_command () {
my nothing afterargs beforeargs cmd do_mscan tohost
nothing=$1
shift
afterargs="$*"
beforeargs=
cmd="mdisplay ${mdopts}"
do_mscan=
case ${nothing} in
reply|fwd|send) #+ reply [msgno] [mcom-opts] - reply to cur/given msg in new (tmux) window
#+ fwd [msgno] [mcom-opts] - forward message
#+ send [mcom-opts] - send new message, c.f. mcom(1)
${nothing} ${afterargs}
return
;;
mime|extract|headers|xcat|filter) #+ mime [msgno] - display mime structure
#+ extract [msgno] part# - extract given part of msgno
#+ extract if no msgno is given and part# is a valid
#+ extract attachment# for the current message, a
#+ extract single numeric arg is taken to be att#
#+ xcat [msgno] part# - like extract but dump to stdout
#+ headers [opts] [msgno] - dump headers of msg to stdout
#+ headers other options to mshow(1) can precede the
#+ headers optional msgno, so >headers -H will show
#+ headers all raw headers of the current message
#+ filter [opts] [msgno] cmd [...args] - filter part through cmd
#+ filter run a message part through a Unix filter and display
#+ filter the results on stdout (unless you redir in the cmd)
case ${nothing} in
mime)
cmd="mshow -t"
afterargs=$(special_args ${afterargs})
;;
extract)
cmd="mshow -x"
afterargs=$(special_args ${afterargs})
;;
xcat)
cmd="mshow -O"
afterargs=$(special_args ${afterargs})
;;
headers)
cmd="mshow -q"
beforeargs=$(special_args ${afterargs})
afterargs=""
;;
filter)
cmd="mshow -O"
beforeargs=$(special_args ${afterargs})
afterargs=""
do_mscan=$(filter_args ${beforeargs})
;;
esac
;;
mv|cp) #+ mv [msgno...] dest-folder - move msg to given folder
#+ mv if no messages are given the current msg is
#+ mv assumed. dest-folder can be a path relative to
#+ mv your MaildirBase config setting.
#+ mv If dest-folder does not end in /new or /cur it
#+ mv is assumed you meant /new.
#+ cp [msgno...] dest-folder - copy msg to given folder
#+ cp if no messages are given the current msg is
#+ cp assumed. dest-folder can be a path relative to
#+ cp your MaildirBase config setting.
#+ cp If dest-folder does not end in /new or /cur it
#+ cp is assumed you meant /new.
if [ "$nothing" = "cp" ]; then
cmd="mrefile -k"
else
cmd=mrefile
fi
afterargs=$(set_args ${afterargs})
[ -z "${afterargs}" ] && {
usage "${nothing} [msgno] dest-folder"
return
}
afterargs="${basedir}/${afterargs}"
do_mscan=mscan
;;
rm) #+ rm msgno [msgno...] - remove indicated messages
#+ rm we refuse to simply operate on the current
#+ rm message so you can't so easily delete it
if [ -z "${afterargs}" ]; then
give_help help rm
else
echo mrm ${afterargs}
mrm ${afterargs}
fi
return
;;
flag) #+ flag [options] msgs - foo
return
;;
inc) #+ inc [all|new] - incorporate new mail into cur (mark all read in folder)
#+ inc We use the minc(1) program from mblaze(7) to
#+ inc incorporate new mail in the current folder,
#+ inc which many MUAs call mark-all-as-read.
#+ inc If we were in "new" mode (c.f. the new/all
#+ inc commands) then we normall switch to "all"
#+ inc mode after running minc. If our optional
#+ inc argument is "new", then we stay in "new" mode
#+ inc instead. If our optional argument is "all"
#+ inc then instead of minc, we run the mincall
#+ inc script to incorporate all new mail in all
#+ inc folders.
if [ -z "${afterargs}" -o "${afterargs}" = new ]; then
echo minc ${FOLDER}
minc ${basedir}/${FOLDER} | mscan
if [ -n "${new}" -a -z "${afterargs}" ]; then
new=
CMD=minbox
elif [ "${afterargs}" = new ]; then
new='*'
CMD=mnewbox
fi
elif [ "${afterargs}" = all ]; then
mincall
else
usage "inc what?"
fi
return
;;
decrypt) #+ decrypt [msgno] - run mdecrypt on message
cmd=mdecrypt
afterargs=$(set_args ${afterargs})
;;
cat) #+ cat [msgno] - dump raw message to stdout
cmd=mshow
afterargs=$(set_args ${afterargs})
;;
red) #+ red [msgno] - re-deliver msgs by (re)filtering through fdm
#+ red pipes each message through: fdm -a stdin
cmd="mshow -nrH"
afterargs=$(set_args ${afterargs})
do_mscan="fdm -astdin fetch"
;;
save) #+ save [msgno] filename - save raw message to file
afterargs=$(set_args ${afterargs})
if [ -z "${afterargs}" ]; then
usage "${nothing} [msgno] filename"
return
fi
msgno=$(tmux show-buffer)
[ -z "${msgno}" ] && msgno=.
echo "mshow -nrH ${msgno} >${afterargs}"
mshow -nrH ${msgno} >${afterargs}
if [ -s ${afterargs} ]; then
echo saved to ${afterargs}
ls -l ${afterargs}
else
echo "save: ${afterargs} is empty!?"
fi
return
;;
quit) #+ quit - exit program
exit 0
;;
ls|cd|inbox|dir)
#+ ls [slice] - (re)list current folder
#+ ls if the optional slice is specified, only that slice of the
#+ ls folder (new or cur) will be displayed. if it is a positive
#+ ls number, that many from the front are displayed. if it is a
#+ ls negative number, that many from the end. if it is a range
#+ ls of numbers separated by a dash, e.g. 1-20, then that range
#+ ls of messages is displayed. the setting of a slice is sticky,
#+ ls meaning it is remembered and carries over to other commands
#+ ls like new and all.
#+ cd folder - switch to different folder
#+ inbox - switch to in-box and list
#+ dir - like ls but use msummary instead
case "${afterargs}" in
[0-9]*)
MB_HEAD=${afterargs}
export MB_HEAD
unset MB_TAIL MB_MID
;;
-[0-9]*)
MB_TAIL=${afterargs}
export MB_TAIL
unset MB_HEAD MB_MID
;;
[0-9]*-[0-9]*)
MB_MID=${afterargs}
export MB_MID
unset MB_HEAD MB_TAIL
;;
-)
unset MB_HEAD MB_TAIL MB_MID
afterargs=""
;;
esac
rescan ${nothing} ${afterargs}
return
;;
all|cur|new) #+ cur [slice] - switch from new to cur in the current Maildir
#+ cur the optional slice has the same syntax as for the ls
#+ cur command, so: cur -10 displays the last ten messages in cur
#+ all [slice] - alias for cur
#+ new [slice] - switch from cur to new in the current Maildir
#+ new the optional slice has the same syntax as for the ls
#+ new command, so: new -10 shows the last ten messages in new
if [ ${nothing} = "new" ]; then
CMD=mnewbox
new='*'
else
CMD=minbox
new=
fi
case "${afterargs}" in
[0-9]*)
MB_HEAD=${afterargs}
export MB_HEAD
unset MB_TAIL MB_MID
;;
-[0-9]*)
MB_TAIL=${afterargs}
export MB_TAIL
unset MB_HEAD MB_MID
;;
[0-9]*-[0-9]*)
MB_MID=${afterargs}
export MB_MID
unset MB_HEAD MB_TAIL
;;
-)
unset MB_HEAD MB_TAIL MB_MID
afterargs=""
;;
esac
rescan ${nothing} ${afterargs}
return
;;
spam|respam) #+ spam [msgno] - mark a message as spam
#+ respam [msgno] - remark a misclassified msg as spam
if [ -n "${afterargs}" ]; then
typeset spamcmd=mrespam
if [ "${nothing}" = respam ]; then
spamcmd="mrespam -R"
fi
echo ${spamcmd} ${afterargs}
${spamcmd} ${afterargs}
spamcmd=""
return
fi
cmd=mrespam
;;
unspam) #+ unspam [msgno] - run message through munspam
if [ -n "${afterargs}" ]; then
echo munspam ${afterargs}
munspam ${afterargs}
return
fi
cmd=munspam
;;
grep) #+ grep args... - run magrep args on current folder,
#+ grep displays results on stdout, no change to current seq.
#+ grep magrep cheat sheet: header:regexp find messages where
#+ grep header matches regexp, /:regexp find messages where
#+ grep body matches regexp. only one regexp-style arg is
#+ grep allowed, subsequent args are an optional message seq.
#+ grep by default the current msgseq is searched, c.f.
#+ grep magrep(1) et al.
magrep ${afterargs} | mthread | mscan
return
;;
restrict) #+ restrict args - like grep but sets current msgseq
#+ restrict sets the current msgseq to matching messages,
#+ restrict same syntax as the grep command
magrep ${afterargs} | mthread | mseq -S | mscan
return
;;
search) #+ search mairix-expr - run mairix on args and cd into Search
#+ search mairix dumps search results into a folder named Search
#+ search via hardlinks, by default it is overwritten every search
#+ search use -a to append results. mairix-expr cheat-sheet:
#+ search t:to c:cc f:from s:subj m:msgid b:body d:date1-date2
#+ search z:lowsize-hisize n:attachment F:flags
#+ search also can be combined e.g. tc:to+from bs:body+subj
#+ search a:addr is short for tcf:addr (to/cc/from)
${mairix} -H ${afterargs}
CMD=minbox
new=''
rescan cd Search
return
;;
find) #+ find mairix-expr - like search but dump excerpts to stdout
${mairix} -x ${afterargs}
return
;;
index) #+ index - run mairix (or whatever) to (re)index your mail
#+ index runs whatever indexer you have configured (def: mairix)
#+ index to (re)index your mail for search, default arg is -p.
#+ index the mailcheck script that comes with mb also can do
#+ index this automatically as mail is fetched.
echo ${mairix} ${index_opts}
${mairix} ${index_opts}
return
;;
dirs) #+ dirs - list Maildirs with new mail in them
mnewdirs | rs
return
;;
sync) #+ sync [host] - sync maildir to another host
#+ sync sync mail tree to another host; if no
#+ sync host is given, the default from your
#+ sync SyncHost preference is used.
tohost="${afterargs}"
[ -z "${tohost}" ] && tohost=${synchost}
echo ${synccmd} ${basedir} ${tohost}:${syncrmt}
${synccmd} ${basedir} ${tohost}:${syncrmt}
return
;;
help|brief|man) #+ help [cmd] - list commands and what they do
#+ brief [cmd] - print a brief usage summary/command list
#+ man [args] - use the system man(1) command on args
give_help ${nothing} ${afterargs}
return
;;
prompt)
#+ prompt - not actually a command, just doc :-)
#+ prompt the mb prompt has the following parts:
#+ prompt the name of the folder you are viewing,
#+ prompt a star if you are in new instead of cur,
#+ prompt and any slice you have restricted to via
#+ prompt e.g. the new, cur or ls commands and a
#+ prompt greater-than sign, e.g. INBOX*-10>
#+ prompt means you are in your inbox viewing
#+ prompt only the last ten messages in new
give_help help prompt
return
;;
[0-9]*) tmux set-buffer ${nothing}
;;
[a-zA-Z]*)
if [ -d ${basedir}/${nothing} ]; then
rescan cd ${nothing}
return
fi
usage "not recognized: ${nothing}"
give_help brief
return
;;
.) ;; #+ . - a single dot displays the current message
!*) #+ ! cmd ... - run a shell command
#+ ! this is an ancient unix tradition
nothing=$(echo ${nothing} | sed -e 's/^!//')
echo ${shell_cmd} -c "${nothing} ${afterargs}"
${shell_cmd} -c "${nothing} ${afterargs}"
return
;;
esac
msgno=$(tmux show-buffer)
if [ -n "${msgno}" ]; then
f=$(mpick ${msgno} 2>/dev/null)
verbose "[msgno: ${msgno} .. $f]"
if [ -n "$f" ]; then
if [ -n "${do_mscan}" ]; then
echo '>> '${cmd} ${beforeargs} ${msgno} ${afterargs}' | '${do_mscan}
${cmd} ${beforeargs} ${msgno} ${afterargs} | \
${do_mscan}
else
#echo '>> '${cmd} ${beforeargs} ${msgno} ${afterargs}
${cmd} ${beforeargs} ${msgno} ${afterargs}
fi
fi
fi
}
spew_status () {
echo ''
mlist -i ${basedir}/${FOLDER}
rm -f $MBLAZE/seq-
}
slice () {
if [ -n "$MB_HEAD" ]; then
echo +${MB_HEAD}
elif [ -n "$MB_TAIL" ]; then
echo ${MB_TAIL}
elif [ -n "$MB_MID" ]; then
echo :${MB_MID}
fi
}
msgno=
if [ $quiet_start -eq 0 ]; then
${CMD} ${FOLDER}
echo "folder: ${FOLDER}, cmd: ${CMD}, editor: ${EDITOR}"
fi
if [ $expert -eq 0 ]; then
give_help brief
fi
if [ $# -gt 0 ]; then
process_command $*
[ $only_one -ne 0 ] && exit 0
fi
trap 'spew_status; echo "("quit" or EOF to quit)"' QUIT INT
trap 'spew_status; echo "[TERM]"; quitting=1' TERM
verbose 'entering repl, rl_cmd=::'${rl_cmd}'::'
quitting=0
while [ $quitting -eq 0 ]; do
line=$(${rl_cmd} mb "${FOLDER}${new}$(slice)> ")
status=$?
verbose 'got a line: ::'${line}':: status=' $status
if [ $status -ne 0 ]; then
if [ $status -lt 100 ]; then
echo " [QUIT]"
quitting=1
fi
elif [ -n "${line}" ]; then
set -- $line
process_command $*
fi
done
exit 0