Depend on console-tools; drop runit
[grml-scripts.git] / usr_bin / grml-mutt
1 #!/bin/sh
2 # Filename:      grml-mutt
3 # Purpose:       configuration script for mutt
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mit Jul 25 18:37:29 CEST 2007 [mika]
8 ################################################################################
9
10 PATH=${PATH:-'/bin/:/sbin/:/usr/local/bin:/usr/bin:/usr/sbin'}
11 PN=$(basename "$0")
12
13 if [ -r /etc/grml/script-functions ] ; then
14    . /etc/grml/script-functions
15    check4progs dialog mutt || echo "Warning - mutt is not available. Continuing anyway.">&2
16 fi
17
18 writemuttrc() {
19 cat > $MUTTRC << EOF
20 # Filename:      .muttrc
21 # Purpose:       configuration for mailclient mutt, created by 'grml-mutt'
22 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
23 # Bug-Reports:   see http://grml.org/bugs/
24 # License:       This file is licensed under the GPL v2.
25 # Latest change: Mit Jul 25 18:37:29 CEST 2007 [mika]
26 ################################################################################
27
28 # important variables - adjust them if necessary
29   set realname="$REALNAME"
30   set from="$MAILADDR"
31
32 # mailboxes
33   set pop_host="$POP3"
34 $POPDATA
35   mailboxes $IMAP
36 $IMAPDATA
37 # some default options:
38     set allow_8bit           # send data as it is.  no conversion.
39   unset arrow_cursor         #  Show current mail with an inverse bar.
40     set ascii_chars          # set: use ASCII characters to build the thread tree
41   unset autoedit             # call editor without prompting for To: and Subject:?
42     set auto_tag=yes         # the next operation applies to the tagged messages automatically
43   unset confirmappend        # set: prompt for confirmation on appending mail to folder
44     set confirmcreate        # set: prompt for confirmation on creation of folders
45     set copy                 # Always keep a copy of my mails!
46     set delete=ask-yes       # ask before deleting any messages
47     set edit_headers         # edit all headers lines in the editor
48     set editor=vim           # use Vim as the editor (Vi IMproved www.vim.org)
49     set folder=~/Mail        # directory with all mail folders
50   unset followup_to          # do not generate a Followup-To header
51     set force_name           # set: save outbound mail by username
52     set hidden_host          # do not use a hostname in the address - PROBLEMATIC!
53     set history=100          # number of input lines for prompts to remember
54     set include              # set: include mail as quoted text in replies
55   unset mark_old             # set: make distinction between New mail and Old mail.
56     set mime_forward=ask-yes # ask: attach message - or just quote it?
57   unset move                 # do not move read mails from mailbox to $mbox (was: "set hold")
58     set pager_context=1      # number of lines that overlap on paging
59 #   set pager_index_lines=0  # number of lines to see from the index
60     set pager_stop           # "next_page" won't jump to next message at end of messages
61     set postponed=+postponed # where save postponed messages?
62 #   set print_command="mp|lpr" # pipe message to "mp" for formattting - then on to "lpr"
63   unset prompt_after         # set: gives you a prompt when pager exits
64     set quote_regexp="^>"    # some people just use '>' - *sigh*
65     set read_inc=10          # '10': show count number for every tenth mail
66     set record=+outbox       # outbox / where to save outgoing mails
67     set recall=ask-yes       # do not prompt for recalling postponed mails with 'm'
68     set reply_to=ask-yes     # "reply":          set:  Use address in Reply-To?
69     set reverse_alias        # show the name of sender as set with my alias for him
70     set reverse_name         # reply as the user to whom the mail was sent to
71     set save_name            # set: save outbound mail to =username if it exists
72 #    set sendmail="/usr/bin/msmtp" # which sendmail program should be used?
73 #   set shell=zsh            # use the zsh for shell commands
74     set sort=threads         # sorting method - I definitely like "threads" best
75     set status_on_top        # set: present the status bar at top, ie before the index
76     set strict_threads       # set: use references: for threading only, ie do not
77                              # thread by subject or in-reply-to
78     set tilde                # show non-existant lines of text with a tilde at begin-of-line
79     set tmpdir="/tmp"        # directory where temporary files are to be placed
80     set to_chars="X+TCF"     # message flags: non-personal,personal,To:,Cc:,From:
81     set use_from             # 'set from=' requires a 'set use_from'!
82 #    set use_envelope_from   # when set, mutt will use $envelope_from_address as the envelope sender
83     set write_inc=10         # update number after each tenth read mail
84
85
86 # Options with a long value:
87 #   set alternates=...
88     set attribution="* %n <%a> [%(%y%m%d %H:%M)]:"              # how to cite the author
89     set reply_regexp="^((aw|antw.?|antwort|re|r e|r?f|sv):[ \t]*)*"
90
91 # Format Options
92     set forw_format="(forw) %s"
93     set index_format="%4C %Z %[!%y%m%d] %-17.17F (%3l) %s"
94     set pager_format="%S [%C/%T] %n (%l) %s"
95     set status_format="%v: %f (%s) [%M/%m] [N=%n,*=%t,new=%b]"
96
97 # Show the "text/plain" part *before* the "text/html" part:
98   alternative_order text/plain text/html
99   auto_view text/html
100
101 # KEY BINDINGS
102   bind index zt current-top
103   bind index zz current-middle
104   bind index zb current-bottom
105
106 # HEADER DISPLAY
107   ignore *
108   unignore from: date: subject: to: cc: reply-to:
109   unignore sender:
110   unignore priority: importance:
111   unignore organization organisation
112   unignore mail-followup-to:
113   unignore resent- x-resent
114 # unignore user-agent: x-agent: x-mailer: x-newsreader: x-mailing-list:
115 # unignore x-editor
116 # unignore message-id: newsgroups: posted-to: posted-and-mailed:
117 # unignore x-also-posted-to: x-newsgroups:
118 # unignore delivered-to x-envelope-to:
119 # unignore x-accept-language
120   unhdr_order *
121   hdr_order Sender: From From: Reply-To: Subject: Organization: Date: Message-Id: User-Agent: X-Editor: X-Mailer: X-Newsreader: X-Agent: To: Cc: Newsgroups: X-Resent Followup-To: Mail-Followup-To:
122 EOF
123 }
124
125 lightcolors() {
126 cat >> $MUTTRC << EOF
127
128 ## color setup
129
130 ## some misc stuff:
131   color normal     black      white
132   color error      red        white
133   color indicator  blue       green
134   color status     white      blue
135   color tree       blue       white
136   color hdrdefault red        white
137   color quoted     blue       white
138   color quoted1    green     white
139   color quoted2    magenta    white
140   color quoted3    cyan       white
141   color tilde      yellow     black
142   color signature  blue       white
143   color search     white      blue   # "search" - matches found with search within the internal pager.
144   color markers    red        black  # "markers" indicate a wrapped line when showing messages with looong lines.
145   color bold       green      black
146   color underline  yellow     black
147
148 ## index-colors:
149   uncolor index *
150
151 # mail from myself *and* to myself (TODO items):
152 #  color index black  brightyellow  '~p ~f prokop'
153
154 # Flagged Messages are important!
155   color index blue white ~N      # New
156   color index magenta default ~T # Tagged
157   color index blue black ~D      # Deleted Mails - use dark color as these are already "dealt with".
158   color index red default ~O     # old messages
159
160 # mail from important people (like myself ;-):
161 # color index white  red '~f prokop'
162
163 # Mails with no obvious addresses (empty To: and Cc: lines)
164    color index cyan white "! ~C ."
165
166 # "DONE mails" ie those I have already replied to.
167    color index blue white  '~Q'
168
169 # non-multipart mails which are tex/html almost always are spam:
170   color index brightmagenta white "~h 'Content-Type: text/html'"
171
172 # Sent to "Undisclosed Recipients":
173   color index white      magenta  '~C Undisclosed.*Recipients'
174
175 # When the Subject indicates a reply (with ":re" but without "Fwd"!)
176 # then there *must* be a reference to the previous message!
177 # So if there is neither an In-Reply-To nor a References line
178 # then it must have been sent with a crappy mailer....
179   color index yellow white "~s re: ! ~s fwd: ! ~x . ! ~h 'in-reply-to: '"
180
181 # No characters in body -> SPAM!
182   color index white white   "! ~b ."
183
184   color index brightred black ~F # Flagged
185
186 ## body-colors:
187
188 # highlight important keywords
189   color body  brightyellow black  "grml"
190
191 # URLs (General Internet addresses):
192   color body yellow red "(finger|ftp|http|news|telnet)://[^ >]*"
193   color body yellow red "<URL:[^ ]*>"
194 # web address without "http":
195   color body yellow red "www\\.[-.a-z0-9]+\\.[a-z][a-z][a-z]?([-_./~a-z0-9]+)?"
196
197 # HTTPS addresses:
198   color body yellow red "https://[^ >]*"
199
200 # FTP addresses:
201   color body yellow red "ftp://[^ ]*"
202
203 # HTTP addresses:
204   color body yellow red "[[:alnum:]][-+.#_[:alnum:]]*@[-+.[:alnum:]]*[[:alnum:]]"
205
206 # File names ("/path/file")
207 #  color body brightgreen white "\\~?\(/[-_.,a-zA-Z0-9{}äöüß]+\)+"
208   color body blue white "\\~?\(/[-_.,a-zA-Z0-9{}äöüß]+\)+"
209
210 # Path names ("/path/")
211   color body brightred   white "\(/[-_.a-zA-Z0-9]+\)+/"
212
213 # Variables  ("$HOME")
214   color body brightmagenta white "\\$[a-zA-Z][-_a-zA-Z]+"
215
216 # Attribution line:
217 # color body red white "^[*] .*:$"
218
219 ## abbreviations and "SCREAMING IN CAPS" in body:
220 # The following includes umlauts - but that's quite clunky.
221 # color body brightyellow  red "[A-ZÄÖÜ][-A-ZÄÖÜ]+[A-ZÄÖÜ][ .!?]?"
222
223 # "+USE_GNU_REGEX":
224 # When you use "+USE_GNU_REGEX" then you can also make use
225 # of "start of word" ("\<") and "end of word" ("\>"):
226   color body red  white    "\\<[-A-Z']{3,}\\>"
227
228 # *Emphasized*, /emphasized/, and _emphasized_ words:
229 # color body brightred      black   "[*/_]+ *[- &[:alnum:]]+ *[*/_]+"
230 # this would catch false positives of the kind _foo* and /bar_
231 # so we should choose matching pairs only:
232   color body brightred  white   "[*][-[:alnum:]]+[*]"
233   color body brightred  white     "/[-[:alnum:]]+/"
234   color body brightred  white     "_[-[:alnum:]]+_"
235
236 # Smileys:  :-)  ;-)  :-|  :-/  :-(
237   color body brightyellow white    "[;:]-[)/(|]"
238 # Grinning:  "grin" ([g]) and "big grin" ([bg]):
239   color body blue   red      "<[Gg]>"
240   color body blue   red      "<[Bb][Gg]>"
241
242 # Border Lines of length three or more.
243 # (Several Newsletters use border lines..)
244   color body green  white    "[-_=+~/\*]{3,}"
245
246 # Extensive use of exclamation and question marks:
247 # "!!!"  "???"
248   color body red    white    "[!?]{3,}"
249
250 # Percentages ("Save xx.x %!")
251   color body brightgreen white "[.0-9]+ ?%"
252
253 # Copyright (C) and Registered Trademark (r)
254   color body red white "[(][cr][)]"
255   color body red white "\\(c\\)"
256
257 # Year Numbers 1980-2002
258   color body blue white "19[89][0-9]"
259   color body blue white "200[012]"
260
261 # Phone Numbers:
262   color body blue white "1-[0-9]{3}[- ][-0-9]+ +ext.? [0-9]+"
263   color body blue white \
264 "(tele)?(cell|fax|fon|phone|tel)[.: ]+[+]?[- 0-9/()]{4,}[0-9]"
265
266 # RTFM!
267 # " man word"
268   color body white red "^ +[$]? *man \\w+"
269
270 # Lists
271 # bulleted list:
272 # * one
273 # * two
274 # * three
275 # dashed list:
276 # - one
277 # - two
278 # - three
279 # color body red          black "^ *[-*] +"
280 # this pattern yields many false positives as it
281 # spans lines for which there is no syntax language.
282 # this is easier with Vim's syntax coloring.
283   color body red white "^ *[-*] +"
284
285 # special IP host addresses:
286 # 192.x.x.x
287   color body white blue  "129.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
288   color body white blue  "193.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
289
290 # HTML tags
291   color body yellow       black "</?\w+>"
292
293 # Emphasis by interspersed spaces
294 # Example: E M P H A S I S
295   color body red white '\<\w( +\w\>)+'
296
297 # verbatim marks (#v+ till #v-)
298   color body yellow red  ^\#v[-+]
299
300   color attachment black white
301 EOF
302 }
303
304 dialog --stdout --title "$PN" --msgbox "Welcome to $PN!
305
306 This script will create a simple base
307 configuration for the mailclient mutt.
308
309 Report bugs, send wishes and feedback to the grml team:
310 http://www.grml.org/ - contact (at) grml.org
311 " 13 65
312
313 GETREALNAME=$(dialog --stdout --title "$PN" --inputbox "Your real name (eg 'John GRML User'):" 0 56) || exit 0
314 REALNAME=${GETREALNAME%/*}
315
316 GETMAILADDR=$(dialog --stdout --title "$PN" --inputbox "Your main mail address (eg 'joedoe@grml.org'):" 0 56) || exit 0
317 MAILADDR=${GETMAILADDR%/*}
318
319 askpop(){
320   GETPOPUSER=$(dialog --stdout --title "$PN" --inputbox "Enter username for POP3 account" 0 0)
321   POPUSER=${GETPOPUSER}
322
323   GETPOPPWD=$(dialog --stdout --title "$PN" --passwordbox "Enter password for POP3 account (typing hidden)" 0 0)
324   POPPWD=${GETPOPPWD}
325 }
326
327 ASKPOP=$(dialog --stdout --title "$PN" --yesno "Configure POP3?" 0 0)
328 retval=$?
329
330 case $retval in
331   0)
332      GETPOP3=$(dialog --stdout --title "$PN" --inputbox  "Your POP3 account (pop[s]://[user]@hostname[:port]):" 0 56 "pop://") || exit 0
333      POP3=${GETPOP3}
334      askpop && \
335 POPDATA="  set pop_user=\"$POPUSER\"
336   set pop_pass=\"$POPPWD\"
337 "
338      ;;
339 esac
340
341 askimap(){
342   GETIMAPUSER=$(dialog --stdout --title "$PN" --inputbox "Enter username for IMAP account" 0 0)
343   IMAPUSER=${GETIMAPUSER}
344
345   GETIMAPPWD=$(dialog --stdout --title "$PN" --passwordbox "Enter password for IMAP account (typing hidden)" 0 0)
346   IMAPPWD=${GETIMAPPWD}
347 }
348
349 ASKIMAP=$(dialog --stdout --title "$PN" --yesno "Configure IMAP?" 0 0)
350 retval=$?
351
352 case $retval in
353   0)
354      GETIMAP=$(dialog --stdout --title "$PN" --inputbox  "Your IMAP account (imap[s]://[user@]hostname[:port]/mailbox):" 0 65 "imap://") || exit 0
355      IMAP=${GETIMAP}
356      askimap && \
357 IMAPDATA="  set imap_user=\"$IMAPUSER\"
358   set imap_pass=\"$IMAPPWD\"
359 "
360      ;;
361 esac
362
363 GETCOLOR=$(dialog --stdout --title "$PN" \
364         --radiolist "Which color setup do you want to use?" 10 65 2 \
365           dark   "dark color setup (default)" on \
366           light  "light color setup" off)
367 retval=$?
368
369 case $retval in
370   0) COLOR=$GETCOLOR ;;
371   *) exit 1 ;;
372 esac
373
374 writecolors() {
375   if [ "$COLOR" = 'light' ] ; then
376     lightcolors
377   fi
378 }
379
380 GETMUTTRC=$(dialog --stdout --title "$PN" --inputbox "Choose a filename for this configuration:" 0 56 "$HOME/.muttrc") || exit 0
381 MUTTRC=${GETMUTTRC}
382
383 WRITEMUTTRC=$(dialog --stdout --title "$PN" --yesno "Write $MUTTRC?" 5 65)
384 retval=$?
385
386 case $retval in
387   0)
388     if [ -f "$MUTTRC" ] ; then
389       dialog --stdout --title "$PN" --yesno "$MUTTRC exists. Overwrite?" 5 65
390       retval=$?
391       case $retval in
392         0)
393           writemuttrc && writecolors && \
394           dialog --stdout --title "$PN" --msgbox "Writing $MUTTRC was successful." 7 65 || \
395           { dialog --stdout --title "$PN" --msgbox "Error $?: writing $MUTTRC failed." 7 65 ; exit 1 ; }
396           ;;
397       esac
398     else
399        writemuttrc && writecolors && \
400        dialog --stdout --title "$PN" --msgbox "Writing $MUTTRC was successfull." 7 65 || \
401        { dialog --stdout --title "$PN" --msgbox "Error $?: writing $MUTTRC failed." 7 65 ; exit 1 ; }
402     fi
403     ;;
404 esac
405
406 dialog --stdout --title "$PN" --msgbox "Thanks for using $PN!
407
408 More information on mutt:
409
410 Manuals: man 1 mutt
411          man 5 muttrc
412
413 Webpages:
414 www.mutt.org
415 wiki.mutt.org
416 www.spinnaker.de/mutt/
417 www.michael-prokop.at/mutt/
418
419 #######################################################
420
421 Report bugs, send wishes and feedback to the grml team:
422 http://www.grml.org/ - contact (at) grml.org
423 " 24 65
424
425 ## END OF FILE #################################################################