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