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