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