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