Difference between pages "Clang" and "Package:Mutt"

(Difference between pages)
m (Install LLVM and its Frontends)
 
(Mutt postfix setup)
 
Line 1: Line 1:
==Introduction==
+
Mutt is a popular mail reader for Linux systems. This page is being created as a good place for people to place their mutt configurations to share with others. These configuration settings go in the user's <tt>~/.muttrc</tt> file.
LLVM can be used as an alternative to GNU's compiler, GCC. The main benefit of using LLVM compilers instead of GCC is their lower memory usage, faster compile time and better diagnostics. There are some Benchmarks on the [http://clang.llvm.org/features.html#performance Clang] and [http://www.phoronix.com/scan.php?page=article&item=llvm3_gcc_open64 Phoronix] homepages.
+
  
It may happen that some programs do not compile (like glibc) because they depend on GCC-specific language extensions [http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html] (this is why the whole BSD code can be compiled with LLVM but some GNU code cannot) or segfault after successful compilation with LLVM (like xorg-server) but after following this guide, the system will still be able to compile packages with gcc. So if something goes wrong, it can be switched back to gcc for the particular package by uncommenting lines in /etc/make.conf and the bug should be reported.
+
== Essential Mutt ==
  
LLVM's C/C++ frontends clang and clang++ version 3.0 are stable enough to be self-hosting [http://blog.llvm.org/2010/02/clang-successfully-self-hosts.html] and compile Boost [http://blog.llvm.org/2010/05/clang-builds-boost.html], Qt [http://labs.qt.nokia.com/2010/10/29/compiling-qt-with-clang/], LibreOffice [http://wiki.documentfoundation.org/Development/Building_LibreOffice_with_Clang], FreeBSD [http://wiki.freebsd.org/BuildingFreeBSDWithClang], some parts of the Linux kernel [http://lwn.net/Articles/411654/] and more.
+
<pre>
 +
set pager_stop
 +
</pre>
  
Further, using LLVM 3.0 and up, there is a third way to compile with LLVM: the dragonegg package creates a gcc-plugin, that uses LLVM's optimizers but parses the code and creates binaries with gcc, which means that everything that compiles and works with gcc should work with dragonegg also. This plugin can be enabled by using a single CFLAG. Since LLVM 3.0 the old llvm-gcc package is deprecated and replaced by dragonegg, so it will disappear from portage with llvm version 2.9.
+
This turns off the default behavior of mutt where hitting space to scroll will automatically move to the next message when the end of the current message is reached. This is very annoying when scrolling in long emails like cron jobs, and the line above sets this behavior to off.
  
==LLVM Frontends==
+
== angry_vincent's .muttrc ==
To be able to compile some sourcecode of a specific language, LLVM needs an appropriate frontend. There are clang, llvm-gcc and dragonegg in portage.
+
  
The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.
+
<pre>
 +
# General config
 +
# ---------------
  
llvm-gcc is a modified version of gcc that compiles C/ObjC programs into native objects, LLVM bitcode or LLVM assembly language, depending upon the options. As written in the previous section, dragonegg replaced llvm-gcc in version 3.0.
+
set folder=~/Mail   # mail folder
 +
set alias_file=~/.mail_aliases    # alises file
 +
set arrow_cursor   # cursor is '->'
 +
set attribution="%d, %n wrote:"    # beginning of mail answer
 +
set copy=yes   # save mail copies
 +
set edit_headers   # edit mail header
 +
set editor="vim"                               # editor
 +
set folder_format="%t%N %-30.30f %8s"                        # folder list look
 +
set index_format="%4C %Z %{%b %d} %-31.31F %N (%4c) %s"      # mail list look
 +
set mailcap_path="~/.mailcap"                               # path to .mailcap
 +
set menu_scroll # scroll list by one line
 +
set mail_check=5 # mail check interval
 +
set pager_stop # at the end of mail do not move to next message
 +
set postponed=+drafts # postponed mails
 +
set print=ask-yes # ask before print
 +
set print_command=lpr # print command
 +
set record=+sent # where to save sent mails
 +
set signature="~/.signature" # signature file
 +
set visual=vim                  # editor caled by  ~v
  
So after installing llvm, clang and dragonegg, you will be able to choose between gcc and llvm whenever you like or use them both at the same time.
+
# mail sort
 +
set sort=threads
 +
set sort_aux=reverse-date-received
 +
set sort_browser=reverse-date
 +
ignore *    # ignore headers so the mail body is not overloaded
 +
unignore        from: subject to cc mail-followup-to \
 +
                date x-mailer x-url user-agent reply-to  # fieids i like to see in mail body
  
== Install LLVM and its Frontends ==
+
# Colors
Simply emerge the packages on ~arch systems. On arch systems you have to unmask some packages first. dragonegg requires gcc's ''lto'' USE-flag to be set and works with gcc 4.5 and gcc 4.6.
+
color index brightcyan black ~N
<console>
+
color index brightyellow black ~F
###i## emerge llvm clang dragonegg
+
color index black green ~T
</console>
+
color index brightred black ~D
Note, that for clang++ the C++ headers search path is hardcoded to the active gcc profile.
+
mono index bold ~N
If you change the active gcc profile, or update gcc to a new version, you will have to remerge clang to update the search path.
+
mono index bold ~F
 +
mono index bold ~T
 +
mono index bold ~D
  
To use dragonegg, run gcc as usual, with an extra command line argument <tt>-fplugin=/usr/lib/llvm/dragonegg.so</tt>
+
# Highlights inside the body of a message.
If you change the active gcc profile, or update gcc to a new version, you will have to remerge dragonegg to update the plugin.
+
  
After the installation, check which CPUs are supported by using the command
+
# URLs
<console>
+
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
###i## llvm-as < /dev/null | llc -mcpu=help
+
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
</console>
+
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
and then add the following lines to <code>/etc/make.conf</code> (uncommenting the lines you need) to enable compilation via LLVM, adapting the march-option according to the previous command:
+
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
  
in <code>/etc/portage/make.conf</code>:
+
# email addresses
{{File
+
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
|/etc/portage/make.conf|<pre>
+
mono body bold "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
# LLVM
+
#CC="/usr/bin/clang"
+
#CXX="/usr/bin/clang++"
+
  
# llvm-gcc for C++ code and fortran
+
# header
# llvm-gcc is deprecated and only used with LLVM 2.9
+
color header green black "^from:"
#CC="/usr/bin/llvm-gcc"
+
color header green black "^to:"
#CXX="/usr/bin/llvm-g++"
+
color header green black "^cc:"
#CPP="/usr/bin/llvm-cpp"
+
color header green black "^date:"
#F77="/usr/bin/llvm-gfortran"
+
color header yellow black "^newsgroups:"
 +
color header yellow black "^reply-to:"
 +
color header brightcyan black "^subject:"
 +
color header red black "^x-spam-rule:"
 +
color header green black "^x-mailer:"
 +
color header yellow black "^message-id:"
 +
color header yellow black "^Organization:"
 +
color header yellow black "^Organisation:"
 +
color header yellow black "^User-Agent:"
 +
color header yellow black "^message-id: .*pine"
 +
color header yellow black "^X-Fnord:"
 +
color header yellow black "^X-WebTV-Stationery:"
 +
color header yellow black "^X-Message-Flag:"
 +
color header yellow black "^X-Spam-Status:"
 +
color header yellow black "^X-SpamProbe:"
 +
color header red black "^X-SpamProbe: SPAM"
  
# Flags for clang: Insert your arch here instead of k8 and have a look at the manpage of clang for flag descriptions.
+
# Coloring quoted text - coloring the first 7 levels:
# Some gcc flags like -pipe and -pthread also work, though they might be ignored by clang.
+
color quoted cyan black
#CFLAGS="-march=k8 -O2"
+
color quoted1 yellow black</pre>
  
# Flags for dragonegg; just use all the gcc flags you like and append -fplugin=/path/to/dragonegg.so
+
== Interesting Color Options ==
#CFLAGS="-march=k8 -O2 -fplugin=/usr/lib64/llvm/dragonegg.so"
+
</pre>}}
+
  
{{Note}} Have a look at clang's manpages for additional information. If you get errors that your compiler cannot produce code, you should check your flags, e.g. don't use <tt>-O4 -flto -S</tt> or stuff like that; the examples above will work.
+
http://github.com/altercation/mutt-colors-solarized
  
== Using clang with portage ==
+
== golodhrim's mutt config ==
  
Although Gentoo package tree is not designed to be used with compiler other than GCC, clang can be enforced on most of the packages through ''CC'' and ''CXX'' variables.
+
First I split up my muttconfig in several subfiles under <tt>~/.mutt</tt>. The resulting files will be:
  
Please note, however, that many of Gentoo packages still don't build with clang and a few don't work correctly after being built. That's why we suggest using ''/etc/portage/env'' file to enable the use of clang per-package.
+
* ~/.mutt/account_hooks
 +
* ~/.mutt/colors
 +
* ~/.mutt/folder_hooks
 +
* ~/.mutt/gpg
 +
* ~/.mutt/lists
 +
* ~/.mutt/macros
 +
* ~/.mutt/mutt-alias
 +
* ~/.mutt/muttrc
 +
* ~/.mutt/sidebar
 +
* ~/.secret/.passwd.gpg
  
In order to do that, first create a new environment override to use:
+
=== ~/.mutt/account_hooks ===
 +
<pre>
 +
#-------------------------------------------------------------------------     
 +
#
 +
# Account Hooks
 +
#-------------------------------------------------------------------------
 +
account-hook . 'unset imap_user imap_pass'
 +
account-hook 'imap://user@imaphost/' "set imap_user=user imap_pass=$my_pass1 "
 +
</pre>
  
in ''<code>/etc/portage/env/clang</code>'':
+
=== ~/.mutt/colors ===
<console>
+
<pre>
###i## nano /etc/portage/env/clang
+
#-------------------------------------------------------------------------     
CC=clang
+
# Set colors
CXX=clang++
+
#-------------------------------------------------------------------------
</console>
+
color  attachment  brightmagenta      default
 +
color  error      brightred          default
 +
color  hdrdefault  red                default
 +
color  indicator  brightyellow        red
 +
color  markers    brightcyan          default
 +
color  message    brightcyan          default
 +
color  normal      default            default
 +
color  quoted      brightblue          default
 +
color  search      default            green
 +
color  signature  red                default
 +
color  status      yellow              blue
 +
color  tilde      magenta            default
 +
color  tree        magenta            default
 +
</pre>
  
Then you can enable use of clang for packages using ''[[:/etc/portage/env|/etc/portage/package.env]]'' file:
+
=== ~/.mutt/folder_hooks ===
in ''<code>/etc/portage/package.env</code>'':  
+
<pre>
<console>
+
#--------------------------------------------------------------------------   
###i## nano /etc/portage/package.env
+
#
app-foo/bar clang
+
# Folders, mailboxes and folder hooks
app-bar/baz clang
+
#--------------------------------------------------------------------------
</console>
+
# Setup for imap-user in account_hooks
 +
set folder="imap://user@imaphost/"
 +
mailboxes =INBOX =INBOX/Archives =INBOX/Drafts =INBOX/Sent =INBOX/Trash
 +
folder-hook 'imap://user@imaphost/' " \
 +
    set folder=imap://user@imaphost/ \
 +
        postponed=+INBOX/Drafts \
 +
        record=+INBOX/Sent \
 +
        smtp_url=smtp://user@smtphost \
 +
        smtp_pass=$my_pass1 \
 +
        #signature=~/.sig/pr.txt \
 +
        from='Name Familyname <name@host> ' \
 +
        realname='Realname' \
 +
        pgp_sign_as='PGP-signature' \
 +
        spoolfile='imap://user@imaphost/' "
 +
</pre>
  
If you want to use clang by default you can and need to specify some core packages. Here is small list of core packages that are currently failing on clang, but not that could be outdated:
+
=== ~/.mutt/gpg ===
 +
<pre>
 +
# vim:syn=muttrc                                                               
 +
##
  
You need to add ''<code>/etc/portage/env/gcc</code>'':
+
set smime_decrypt_use_default_key=yes
<console>
+
###i## nano /etc/portage/env/gcc
+
CC=gcc
+
CXX=g++
+
</console>
+
  
in addition, it is recommend to add compiler flags there:
+
# Decode application/pgp attachments like so:
<console>
+
set pgp_decode_command="/usr/bin/gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
###i## nano /etc/portage/env/gcc
+
CFLAGS="-O2 -march=native -mtune=native -pipe"
+
CXXFLAGS="-O2 -march=native -mtune=native -pipe"
+
LDFLAGS="-Wl,--as-needed"
+
#You can disable gold link here
+
#EXTRA_ECONF="--enable-gold=default"
+
</console>
+
  
And in ''<code>/etc/portage/package.env</code>'':
+
# And use this to verify pgp signatures:
<console>
+
set pgp_verify_command="/usr/bin/gpg --no-verbose --batch --output - --verify %s %f"
###i## nano /etc/portage/package.env
+
#---------------CORE PACKAGES TO BUILD WITH GCC:
+
sys-apps/which gcc
+
sys-fs/reiserfsprogs gcc
+
sys-libs/ncurses gcc
+
sys-libs/zlib gcc
+
sys-apps/busybox gcc
+
sys-fs/e2fsprogs gcc
+
sys-devel/binutils gcc
+
sys-libs/glibc gcc
+
sys-devel/dragonegg gcc
+
dev-libs/openssl gcc
+
sys-boot/grub gcc
+
#---------------USER PACKAGES TO BUILD WITH GCC:
+
sys-apps/pacman gcc
+
www-client/firefox gcc
+
x11-libs/cairo gcc
+
media-libs/mesa gcc
+
</console>
+
  
If you have {{Package|app-portage/flaggie}} installed, you can modify ''<code>/etc/portage/package.env</code>'' by running the following:
+
# How to decrypt pgp encrypted messages:
<console>
+
set pgp_decrypt_command="/usr/bin/gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
###i## flaggie app-foo/bar app-bar/baz +clang
+
</console>
+
  
== Enabling link-time optimizations ==
+
# How to pgp sign a message:
 +
set pgp_sign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
  
The ''link-time optimization'' feature defers optimizing the resulting executables to linking phase. This can result in better optimization of packages but is unsupported in Gentoo, and many packages simply fail to build.
+
# How to pgp clearsign a message:
 +
set pgp_clearsign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
  
When using LTO, clang compiles units into LLVM byte-code rather than machine code. In order to support linking such object files, the [[gold]] linker must be installed and set as the default linker, as it does support plugins.
+
# Import a pgp key from a message into my public keyring as follows:
 +
set pgp_import_command="/usr/bin/gpg --no-verbose --import -v %f"
  
Similarly, ''ar'' needs plugin support as well. Sadly, binutils ar doesn't support passing '--plugin'' option before the actual command. Thus, we need to create a wrapper for it:
+
# Use this to export a key from my public keyring:
 +
set pgp_export_command="/usr/bin/gpg --no-verbose --export --armor %r"
  
in ''<code>/usr/local/bin/clang-ar</code>'':
+
# Verify key information (from the key selection menu):
<console>
+
set pgp_verify_key_command="/usr/bin/gpg --verbose --batch --fingerprint --check-sigs %r"
###i## nano /usr/local/bin/clang-ar
+
#!/bin/sh
+
firstarg=${1}
+
shift
+
  
exec /usr/bin/ar "${firstarg}" --plugin /usr/lib/llvm/LLVMgold.so "${@}"
+
# List my public keyring like so:
</console>
+
set pgp_list_pubring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-keys %r"  
  
If that's done, you can create a new environment override profile for LTO-enabled clang:
+
# List my private keyring like so:
 +
set pgp_list_secring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-secret-keys %r"
  
in ''<code>/etc/portage/env/clang-lt</code>'':
+
# Automatically sign outgoing messages
<console>
+
set pgp_autosign=yes
CC='clang'
+
CXX='clang++'
+
CFLAGS="${CFLAGS} -O4"
+
CXXFLAGS="${CXXFLAGS} -O4"
+
LDFLAGS="${LDFLAGS} -O4 -Wl,-plugin,/usr/lib/llvm/LLVMgold.so"
+
AR='/usr/local/bin/clang-ar'
+
RANLIB=':'
+
NM='nm --plugin /usr/lib64/llvm/LLVMgold.so'
+
</console>
+
  
Note that the link-time optimizations were indirectly enabled here via ''-O4''. If you don't want to enable other optimizations enforced by ''-O3'', please use ''-flto'' instead. You need to also pass optimization flags when linking because that's where clang needs them.
+
# Timeout (in seconds) for cached passphrases:
 +
set pgp_timeout=1800
  
You may also need to adjust the libdir path to plugin. Newer (live) versions of clang add `-plugin` when linking automatically, so `-Wl,-plugin`… is no longer necessary.
+
# Text to show before a good signature:
 +
set pgp_good_sign="^gpg: Good signature from"
 +
</pre>
  
== Using clang with distcc ==
+
=== ~/.mutt/lists ===
 +
<pre>
 +
#-------------------------------------------------------------------------     
 +
# Mailinglist Subscriptions
 +
#-------------------------------------------------------------------------
 +
# Syntax:
 +
# subscribe mailinglist@domain.com
 +
</pre>
  
In order to use clang on distcc client, additional symlinks have to be created in ''<code>/usr/lib*/distcc/bin</code>'':
+
=== ~/.mutt/macros ===
 +
<pre>
 +
# Macros to toggle the sidebar visibility                                     
 +
macro index b '<enter-command>toggle sidebar_visible<enter><refresh>'
 +
macro pager b '<enter-command>toggle sidebar_visible<enter><redraw-screen>'
 +
 
 +
# abook query
 +
macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
 +
macro generic,index,pager \Cb "abook" "launch abook"
 +
</pre>
 +
 
 +
=== ~/.mutt/alias ===
 +
multiple lines like
 +
<pre>
 +
alias nick Realname <email@host.tld>
 +
</pre>
 +
 
 +
=== ~/.mutt/muttrc ===
 +
<pre>
 +
# Some minimal Mutt settings, Gentoo-style.  These reflect the Gentoo
 +
# predilection for maildir folders.
 +
#
 +
# Please don't add settings to this file to change other user
 +
# preferences (such as colors), since those can be hard for a user to
 +
# undo if their preference doesn't match yours!  For example, it is
 +
# *impossible* currently in mutt to remove color settings from objects
 +
# other than the index.
 +
 
 +
#-------------------------------------------------------------------------
 +
# Process the password file first
 +
#-------------------------------------------------------------------------
 +
set my_tmp=`gpg -o ~/.secret/.tmp -d ~/.secret/.passwd.gpg`                   
 +
set my_pass1=`awk '/user:/ {print $2}' ~/.secret/.tmp`
 +
set my_del=`rm -f ~/.secret/.tmp`
 +
 +
#-------------------------------------------------------------------------
 +
# Further customisations
 +
#-------------------------------------------------------------------------
 +
set smart_wrap = yes
 +
set sort = 'threads'
 +
set sort_aux = 'last-date-received'
 +
set imap_check_subscribed
 +
 
 +
ignore "Authentication-Results:"
 +
ignore "DoaminKey-Signature:"
 +
ignore "DKIM-Signature:"
 +
hdr_order Date From To Cc
 +
 
 +
#-------------------------------------------------------------------------
 +
# Configuration variables
 +
#-------------------------------------------------------------------------
 +
set abort_nosubject=yes
 +
set abort_unmodified=yes
 +
set query_command="abook --mutt-query '%s'"
 +
set alias_file="~/.mutt/mutt-alias"
 +
set alias_format="%4n %t %a %r"
 +
source $alias_file
 +
set assumed_charset="utf-8"
 +
set attach_charset="utf-8"
 +
set charset="utf-8"
 +
set date_format=""
 +
set edit_headers=yes
 +
set editor='vim + -c "set textwidth=72" -c "set wrap" -c "set nocp" -c "?^$"        '
 +
set folder="~/.offlineimap"
 +
set forward_quote=yes
 +
set header_cache=~/.mutt/cache/headers
 +
set message_cachedir=~/.mutt/cache/bodies
 +
set certificate_file=~/.mutt/certificates
 +
set help=yes
 +
set imap_idle=yes
 +
set imap_peek=yes
 +
set imap_servernoise=no
 +
set include=yes
 +
set mail_check=60
 +
set mbox_type=Maildir
 +
set menu_move_off=no
 +
set menu_scroll=no
 +
set mime_forward=ask-no
 +
set pager_context=2
 +
set pager_stop=yes
 +
set postponed="~/.mutt/mail/postponed"
 +
set realname="Martin 'golodhrim' Scholz"
 +
set record="~/.mutt/mail/sent"
 +
set reply_regexp="^(re([\[0-9\]+])*|betr):[ \t]*"
 +
#set reply_to=yes
 +
set tilde=yes
 +
 
 +
#--------------------------------------------------------------------------
 +
# muttprint for printing
 +
#--------------------------------------------------------------------------
 +
set print_command="muttprint"
 +
 
 +
#--------------------------------------------------------------------------
 +
# Automatically process html mails
 +
#--------------------------------------------------------------------------
 +
auto_view text/html
 +
 
 +
#--------------------------------------------------------------------------
 +
# Other configuration files
 +
#--------------------------------------------------------------------------
 +
source ~/.mutt/account_hooks
 +
source ~/.mutt/folder_hooks
 +
source ~/.mutt/colors
 +
source ~/.mutt/sidebar
 +
source ~/.mutt/gpg
 +
source ~/.mutt/macros
 +
source ~/.mutt/lists
 +
</pre>
 +
 
 +
=== ~/.mutt/sidebar ===
 +
<pre>
 +
#--------------------------------------------------------------------------   
 +
# Sidebar configuration
 +
#--------------------------------------------------------------------------
 +
set sidebar_width=30
 +
set sidebar_visible=yes
 +
set sidebar_delim='|'
 +
color sidebar_new yellow default
 +
 
 +
#--------------------------------------------------------------------------
 +
# Sidebar keys
 +
#--------------------------------------------------------------------------
 +
bind index \CP sidebar-prev
 +
bind index \CN sidebar-next
 +
bind index \CO sidebar-open
 +
bind pager \CP sidebar-prev
 +
bind pager \CN sidebar-next
 +
bind pager \CO sidebar-open
 +
</pre>
 +
 
 +
=== ~/.secret/.passwd.gpg ===
 +
For this file follow the next steps:
 +
* Step 1:
 +
Create a folder <tt>~/.secret</tt> and inside a file <tt>.passwd</tt> and enter the following into it:
 +
<pre>
 +
user1:    passwd1
 +
user2:    passwd2
 +
</pre>
 +
where user1 and user2 are your identifiers for the accounts you added in account_hooks and folder_hooks and at the start of muttrc.
 +
* Step 2:
 +
Now encrypt the file with your gpg-key, if you don't have one execute <tt>gpg --gen-key</tt> and create one first. After that don't forget to delete your unencrypted passwordstorage.
 +
<pre>
 +
$ gpg -r 0x<Your-ID-fingerprint> -o .passwd.gpg --encrypt .passwd
 +
$ rm -f .passwd
 +
</pre>
 +
=== Mutt postfix setup ===
 +
Postfix is another popular and powerful mail transfer agent which somehow easier to configure than sendmail. Let's start a quick postfix mail transfer setup that will work with mutt. Set <tt>sasl,berkdb</tt> USE flags to <tt>mail-mta/potsfix</tt> and <tt>mail-client/mutt</tt>
 
<console>
 
<console>
###i## ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang
+
# ##i##echo "mail-mta/postfix berkdb sasl" >> /etc/portage/package.use/mail
###i## ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang++
+
# ##i##echo "mail-client/mutt berkdb sasl" >> /etc/portage/package.use/mail
 +
# ##i##emerge -uN1 mutt postfix
 +
</console>
 +
Edit <tt>/etc/postfix/main.cf</tt> and add the following lines:
 +
<pre>
 +
relayhost = smtp.gmail.com:587
 +
smtp_use_tls = yes
 +
smtp_sasl_auth_enable = yes
 +
smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd
 +
smtp_sasl_security_options = noanonymous
 +
</pre>
 +
Create and edit above mentioned authorization file <tt>gmail_passwd</tt>
 +
<console>
 +
# ##i##touch /etc/postfix/gmail_passwd
 +
# ##i##echo "smtp.gmail.com:587 my.name@gmail.com:password" >> /etc/postfix/gmail_passwd
 +
</console>
 +
Where <my.name> is gmail account and passwd is account password.
 +
Convert <tt>gmail_passwd</tt> into Berkeley DB format, secure the file and finaly restart the postfix daemon
 +
<console>
 +
# ##i##postmap /etc/postfix/gmail_passwd
 +
# ##i##chown root:postfix /etc/postfix/gmail_passwd*
 +
# ##i##chmod 0640 /etc/postfix/gmail_passwd*
 +
# ##i##/etc/init.d/postfix restart
 
</console>
 
</console>
 
{{GLW|src=http://wiki.gentoo.org/wiki/Clang}}
 
  
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 +
[[Category:Featured]]

Revision as of 04:23, May 10, 2013

Mutt is a popular mail reader for Linux systems. This page is being created as a good place for people to place their mutt configurations to share with others. These configuration settings go in the user's ~/.muttrc file.

Essential Mutt

set pager_stop

This turns off the default behavior of mutt where hitting space to scroll will automatically move to the next message when the end of the current message is reached. This is very annoying when scrolling in long emails like cron jobs, and the line above sets this behavior to off.

angry_vincent's .muttrc

# General config
# ---------------

set folder=~/Mail		   # mail folder
set alias_file=~/.mail_aliases     # alises file
set arrow_cursor		   # cursor is '->'
set attribution="%d, %n wrote:"    # beginning of mail answer
set copy=yes			   # save mail copies
set edit_headers		   # edit mail header
set editor="vim"		                              # editor
set folder_format="%t%N %-30.30f %8s"                         # folder list look
set index_format="%4C %Z %{%b %d} %-31.31F %N (%4c) %s"       # mail list look 
set mailcap_path="~/.mailcap"	                              # path to .mailcap
set menu_scroll			# scroll list by one line
set mail_check=5		# mail check interval
set pager_stop 			# at the end of mail do not move to next message 
set postponed=+drafts		# postponed mails
set print=ask-yes		# ask before print
set print_command=lpr		# print command
set record=+sent		# where to save sent mails 
set signature="~/.signature"	# signature file
set visual=vim                  # editor caled by  ~v

# mail sort
set sort=threads
set sort_aux=reverse-date-received
set sort_browser=reverse-date
ignore *     # ignore headers so the mail body is not overloaded
unignore        from: subject to cc mail-followup-to \
                date x-mailer x-url user-agent reply-to   # fieids i like to see in mail body

# Colors
color index brightcyan black ~N
color index brightyellow black ~F
color index black green ~T
color index brightred black ~D
mono index bold ~N
mono index bold ~F
mono index bold ~T
mono index bold ~D

# Highlights inside the body of a message.

# URLs
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"

# email addresses
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
mono body bold "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"

# header
color header green black "^from:"
color header green black "^to:"
color header green black "^cc:"
color header green black "^date:"
color header yellow black "^newsgroups:"
color header yellow black "^reply-to:"
color header brightcyan black "^subject:"
color header red black "^x-spam-rule:"
color header green black "^x-mailer:"
color header yellow black "^message-id:"
color header yellow black "^Organization:"
color header yellow black "^Organisation:"
color header yellow black "^User-Agent:"
color header yellow black "^message-id: .*pine"
color header yellow black "^X-Fnord:"
color header yellow black "^X-WebTV-Stationery:"
color header yellow black "^X-Message-Flag:"
color header yellow black "^X-Spam-Status:"
color header yellow black "^X-SpamProbe:"
color header red black "^X-SpamProbe: SPAM"

# Coloring quoted text - coloring the first 7 levels:
color quoted cyan black
color quoted1 yellow black

Interesting Color Options

http://github.com/altercation/mutt-colors-solarized

golodhrim's mutt config

First I split up my muttconfig in several subfiles under ~/.mutt. The resulting files will be:

  • ~/.mutt/account_hooks
  • ~/.mutt/colors
  • ~/.mutt/folder_hooks
  • ~/.mutt/gpg
  • ~/.mutt/lists
  • ~/.mutt/macros
  • ~/.mutt/mutt-alias
  • ~/.mutt/muttrc
  • ~/.mutt/sidebar
  • ~/.secret/.passwd.gpg

~/.mutt/account_hooks

#-------------------------------------------------------------------------      
#
# Account Hooks
#-------------------------------------------------------------------------
account-hook . 'unset imap_user imap_pass'
account-hook 'imap://user@imaphost/' "set imap_user=user imap_pass=$my_pass1 "

~/.mutt/colors

#-------------------------------------------------------------------------      
# Set colors
#-------------------------------------------------------------------------
color   attachment  brightmagenta       default
color   error       brightred           default
color   hdrdefault  red                 default
color   indicator   brightyellow        red
color   markers     brightcyan          default
color   message     brightcyan          default
color   normal      default             default
color   quoted      brightblue          default
color   search      default             green
color   signature   red                 default
color   status      yellow              blue
color   tilde       magenta             default
color   tree        magenta             default

~/.mutt/folder_hooks

#--------------------------------------------------------------------------     
#
# Folders, mailboxes and folder hooks
#--------------------------------------------------------------------------
# Setup for imap-user in account_hooks
set folder="imap://user@imaphost/"
mailboxes =INBOX =INBOX/Archives =INBOX/Drafts =INBOX/Sent =INBOX/Trash
folder-hook 'imap://user@imaphost/' " \
    set folder=imap://user@imaphost/ \
        postponed=+INBOX/Drafts \
        record=+INBOX/Sent \
        smtp_url=smtp://user@smtphost \
        smtp_pass=$my_pass1 \
        #signature=~/.sig/pr.txt \
        from='Name Familyname <name@host> ' \
        realname='Realname' \
        pgp_sign_as='PGP-signature' \
        spoolfile='imap://user@imaphost/' "

~/.mutt/gpg

# vim:syn=muttrc                                                                
##

set smime_decrypt_use_default_key=yes

# Decode application/pgp attachments like so:
set pgp_decode_command="/usr/bin/gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"

# And use this to verify pgp signatures:
set pgp_verify_command="/usr/bin/gpg --no-verbose --batch --output - --verify %s %f"

# How to decrypt pgp encrypted messages:
set pgp_decrypt_command="/usr/bin/gpg --passphrase-fd 0 --no-verbose --batch --output - %f"

# How to pgp sign a message:
set pgp_sign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"

# How to pgp clearsign a message:
set pgp_clearsign_command="/usr/bin/gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"

# Import a pgp key from a message into my public keyring as follows:
set pgp_import_command="/usr/bin/gpg --no-verbose --import -v %f"

# Use this to export a key from my public keyring:
set pgp_export_command="/usr/bin/gpg --no-verbose --export --armor %r"

# Verify key information (from the key selection menu):
set pgp_verify_key_command="/usr/bin/gpg --verbose --batch --fingerprint --check-sigs %r"

# List my public keyring like so:
set pgp_list_pubring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-keys %r" 

# List my private keyring like so:
set pgp_list_secring_command="/usr/bin/gpg --no-verbose --batch --with-colons --list-secret-keys %r" 

# Automatically sign outgoing messages
set pgp_autosign=yes

# Timeout (in seconds) for cached passphrases:
set pgp_timeout=1800

# Text to show before a good signature:
set pgp_good_sign="^gpg: Good signature from"

~/.mutt/lists

#-------------------------------------------------------------------------      
# Mailinglist Subscriptions
#-------------------------------------------------------------------------
# Syntax:
# subscribe mailinglist@domain.com

~/.mutt/macros

# Macros to toggle the sidebar visibility                                       
macro index b '<enter-command>toggle sidebar_visible<enter><refresh>'
macro pager b '<enter-command>toggle sidebar_visible<enter><redraw-screen>'

# abook query
macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
macro generic,index,pager \Cb "abook" "launch abook"

~/.mutt/alias

multiple lines like

alias nick Realname <email@host.tld>

~/.mutt/muttrc

# Some minimal Mutt settings, Gentoo-style.  These reflect the Gentoo
# predilection for maildir folders.
#
# Please don't add settings to this file to change other user
# preferences (such as colors), since those can be hard for a user to
# undo if their preference doesn't match yours!  For example, it is
# *impossible* currently in mutt to remove color settings from objects
# other than the index.

#-------------------------------------------------------------------------
# Process the password file first
#-------------------------------------------------------------------------
set my_tmp=`gpg -o ~/.secret/.tmp -d ~/.secret/.passwd.gpg`                     
set my_pass1=`awk '/user:/ {print $2}' ~/.secret/.tmp`
set my_del=`rm -f ~/.secret/.tmp`
 
#-------------------------------------------------------------------------
# Further customisations
#-------------------------------------------------------------------------
set smart_wrap = yes
set sort = 'threads'
set sort_aux = 'last-date-received'
set imap_check_subscribed

ignore "Authentication-Results:"
ignore "DoaminKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc

#-------------------------------------------------------------------------
# Configuration variables
#-------------------------------------------------------------------------
set abort_nosubject=yes
set abort_unmodified=yes
set query_command="abook --mutt-query '%s'"
set alias_file="~/.mutt/mutt-alias"
set alias_format="%4n %t %a %r"
source $alias_file
set assumed_charset="utf-8"
set attach_charset="utf-8"
set charset="utf-8"
set date_format=""
set edit_headers=yes
set editor='vim + -c "set textwidth=72" -c "set wrap" -c "set nocp" -c "?^$"        '
set folder="~/.offlineimap"
set forward_quote=yes
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set help=yes
set imap_idle=yes
set imap_peek=yes
set imap_servernoise=no
set include=yes
set mail_check=60
set mbox_type=Maildir
set menu_move_off=no
set menu_scroll=no
set mime_forward=ask-no
set pager_context=2
set pager_stop=yes
set postponed="~/.mutt/mail/postponed"
set realname="Martin 'golodhrim' Scholz"
set record="~/.mutt/mail/sent"
set reply_regexp="^(re([\[0-9\]+])*|betr):[ \t]*"
#set reply_to=yes
set tilde=yes

#--------------------------------------------------------------------------
# muttprint for printing
#--------------------------------------------------------------------------
set print_command="muttprint"

#--------------------------------------------------------------------------
# Automatically process html mails
#--------------------------------------------------------------------------
auto_view text/html

#--------------------------------------------------------------------------
# Other configuration files
#--------------------------------------------------------------------------
source ~/.mutt/account_hooks
source ~/.mutt/folder_hooks
source ~/.mutt/colors
source ~/.mutt/sidebar
source ~/.mutt/gpg
source ~/.mutt/macros
source ~/.mutt/lists 

~/.mutt/sidebar

#--------------------------------------------------------------------------     
# Sidebar configuration
#--------------------------------------------------------------------------
set sidebar_width=30
set sidebar_visible=yes
set sidebar_delim='|'
color sidebar_new yellow default

#--------------------------------------------------------------------------
# Sidebar keys
#--------------------------------------------------------------------------
bind index \CP sidebar-prev
bind index \CN sidebar-next
bind index \CO sidebar-open
bind pager \CP sidebar-prev
bind pager \CN sidebar-next
bind pager \CO sidebar-open

~/.secret/.passwd.gpg

For this file follow the next steps:

  • Step 1:

Create a folder ~/.secret and inside a file .passwd and enter the following into it:

user1:    passwd1
user2:    passwd2

where user1 and user2 are your identifiers for the accounts you added in account_hooks and folder_hooks and at the start of muttrc.

  • Step 2:

Now encrypt the file with your gpg-key, if you don't have one execute gpg --gen-key and create one first. After that don't forget to delete your unencrypted passwordstorage.

$ gpg -r 0x<Your-ID-fingerprint> -o .passwd.gpg --encrypt .passwd
$ rm -f .passwd

Mutt postfix setup

Postfix is another popular and powerful mail transfer agent which somehow easier to configure than sendmail. Let's start a quick postfix mail transfer setup that will work with mutt. Set sasl,berkdb USE flags to mail-mta/potsfix and mail-client/mutt

# echo "mail-mta/postfix berkdb sasl" >> /etc/portage/package.use/mail
# echo "mail-client/mutt berkdb sasl" >> /etc/portage/package.use/mail
# emerge -uN1 mutt postfix

Edit /etc/postfix/main.cf and add the following lines:

relayhost = smtp.gmail.com:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd
smtp_sasl_security_options = noanonymous

Create and edit above mentioned authorization file gmail_passwd

# touch /etc/postfix/gmail_passwd
# echo "smtp.gmail.com:587 my.name@gmail.com:password" >> /etc/postfix/gmail_passwd

Where <my.name> is gmail account and passwd is account password. Convert gmail_passwd into Berkeley DB format, secure the file and finaly restart the postfix daemon

# postmap /etc/postfix/gmail_passwd
# chown root:postfix /etc/postfix/gmail_passwd*
# chmod 0640 /etc/postfix/gmail_passwd*
# /etc/init.d/postfix restart