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