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