Skip to main content


Usando Procmail com Mutt


O Mutt é um MUA (Mail User Agent), ou seja, um cliente de e-mail utilizado para ler, escrever e gerenciar mensagens de e-mail. Ele é popular entre usuários de terminal devido à sua flexibilidade e suporte a diversos protocolos.


Para nossos exemplos vamos usar ele para enviar e receber emails. Vamos configurar o Mutt para trabalhar com o Procmail, que é um agente de entrega de e-mails (MDA) que pode ser usado para filtrar e organizar mensagens antes que o Mutt as acesse. Vamos começar instalando o procmail e então configurar o Postfix para usar ele:

# Instale o procmail:
$ sudo apt install -y procmail mutt emacs

# Edite o arquivo abaixo:
$ sudo vim /etc/postfix/main.cf

# Edite a variável abaixo (crie caso não exista):
mailbox_command = /usr/bin/procmail -m ~/.procmailrc

# Depois reinicie o postfix:
$ sudo systemctl restart postfix

Em mydestination, mude mail.ctos.com.br para ctos.com.br. O mesmo para o domínio zion.


O Procmail possui dois arquivos principais de configuração:

  • /etc/procmailrc
    Aqui ficam as regras que se aplicam para todos os usuários.

  • ~/.procmailrc
    Esse é um arquivo específico para que cada usuário possa ter sua própria configuração.


Crie ou edite o arquivo ~/.procmailrc para definir as regras de filtragem e armazenamento dos e-mails para cada usuário.

~/.procmailrc
### Set the correct shell and $PATH
SHELL=/bin/sh
PATH=/bin:/usr/bin:/usr/local/bin

### Default directory to save mailboxes for filtered messages
MAILDIR=$HOME
DEFAULT=$HOME/Mailbox

### Enable extended logging
LOGFILE=$HOME/procmail.log
VERBOSE=yes
LOGABSTRACT=all

Agora devemos configurar o Mutt para acessar os diretórios de e-mails organizados pelo Procmail. Edite o arquivo ~/.muttrc e adicione:

~/.muttrc
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# General
#

#set hostname=ctos.com.br # my DNS domain
#set hostname=zion.com.br # my DNS domain

set folder=~/mail # where i keep my mailboxes
set spoolfile="~/Mailbox" # where my new mail is located
set mbox="~/mail/Maildp" # where to store read messages
set record=+outbox # default location to save outgoing mail
set postponed=+postponed # mailbox to store postponed messages in

set alias_file=~/.mailaddr # where I keep my aliases
set sort_alias= alias
set reverse_alias=yes
#source $alias_file

set abort_unmodified=yes # automatically abort replies if I don't
set ascii_chars # use ASCII instead of ACS chars for threads
set autoedit # go to the editor right away when composing
set charset="UTF-8" # character set for your terminal
set noconfirmappend # don't ask me if i want to append to mailboxes
set copy=yes # always save a copy of outgoing messages
set delete=yes # purge deleted messages without asking
set edit_headers # let me edit the message header when composing
#set editor="ee +2,4"
#set editor="vi"
set editor="emacs -nw %s --eval '(setq make-backup-files nil)'"
set index_format="%4C %Z %{%m/%d} %-15.15F (%4c) %s" # format of the index
set help # show the help lines
set include # always include messages when replying
set indent_string="> " # how to quote replied text
set nomark_old # i don't care about whether a message is old
set mail_check=5 # how often to poll for new mail
set mime_forward # use message/rfc822 type to forward messages
set pager_index_lines=10 # how many index lines to show in the pager
set print_command="lpr-cups -Pnoc-jd"
set read_inc=25 # show progress when reading a mailbox
set write_inc=25 # show progress while writing mailboxes
set reply_to # always use reply-to if present
set reverse_name # use my address as it appears in the message
set nosave_empty # remove files when no messages are left
set sort=threads # primary sorting method
set sort_browser=alpha # how to sort files in the dir browser
set tilde # virtual lines to pad blank lines in the pager
set nouse_domain # don't qualify local addresses with $domain
set pgp_verify_sig=yes # don't automatically verify message signatures

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Color definitions
#
color normal white black
color header brightgreen black ^(From|Subject):
color hdrdefault green black

color header yellow default "^(From)"
color header cyan default "^(Subject)"

color quoted yellow black
color signature red black
color indicator brightyellow blue
color error brightred black
color status blue white
color tree magenta black # the thread tree in the index menu
color tilde magenta black
color message brightcyan black
color markers brightcyan black
color attachment brightmagenta black
color search black green # how to hilite search patterns in the pager


color body magenta black "(ftp|http)://[^ ]+" # point out URLs
color body magenta black [-a-z_0-9.]+@[-a-z_0-9.]+ # e-mail addresses
color underline brightgreen black

# attributes when using a mono terminal
mono header underline ^(From|Subject):
mono quoted bold

color quoted green default
#color quoted1 cyan default
color quoted1 green default
color quoted2 yellow default
color quoted3 red default
#color quoted4 brightred default

uncolor index * # unset all color index entries
color index green default ~N # New


set signature="~/.signature"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Key bindings
#
# maps:
# alias alias menu
# attach attachment menu
# browser directory browser
# compose compose menu
# index message index
# pgp pgp menu
# postpone postponed message recall menu
# generic generic keymap for all of the above
# editor line editor
# pager text viewer
#
bind generic "\e<" first-entry # emacs-like bindings for moving to top/bottom
bind generic \e> last-entry
bind generic { top-page
bind generic } bottom-page
bind generic \177 last-entry

macro index \cb |urlview\n # simulate the old browse-url function

macro index S s+spam\n
macro pager S s+spam\n

bind pager G bottom # just like vi and less
bind pager \C? previous-line

Agora devemos configurar o .emacs para que o uso do nosso Mutt fique mais confortável de se usar:

~/.emacs
(setq tab-width 4)
;(set-language-environment "Latin-1")
(prefer-coding-system 'utf-8)
(column-number-mode t)

; Emacs 24 update default changes
; http://www.emacswiki.org/emacs/AutoIndentation
(global-set-key (kbd "RET") 'electric-newline-and-maybe-indent)
(setq tab-always-indent nil)

; texto colorido
(global-font-lock-mode t)
; so' para facilitar
(global-set-key [S-up] '(lambda() (interactive) (scroll-up 1)))
(global-set-key [S-down] '(lambda() (interactive) (scroll-down 1)))
(global-set-key [home] 'beginning-of-line)
(global-set-key [S-home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-line)
(global-set-key [S-end] 'end-of-buffer)
(global-set-key [f12] 'ispell-region)

; para fazer com que as teclas backspace e delete funcionem como devem
; e nao da mesma maneira (delete funcionava como backspace)
(global-unset-key [?\C-h])
(global-set-key [?\C-h] 'delete-backward-char)
; delete nao esta' funcionando

(custom-set-faces)

(set-input-mode nil nil 1)
;Dicionario Portugues
;(setq ispell-local-dictionary-alist (quote (("portugues" "[A-Za-zàèìòùÀÈÌÒÙáéíóúÁÉÍÓÚãõÃÕâêîôûÂÊÎÔÛçÇ]" "[^A-Za-zàèìòùÀÈÌÒÙáéíóúÁÉÍÓÚãõÃÕâêîôûÂÊÎÔÛçÇ]" "---" nil ("-B" "-d" "pt_BR") "~tex" utf-8))))
(setq ispell-program-name "aspell")
(setq ispell-list-command "list")
; troca dicionario do ispell
(defvar br_dict t
"variavel dicionario")
(defun dict ()
"Troca o dicionario"
(interactive)
(if br_dict
(progn
(ispell-change-dictionary "pt_BR")
(setq br_dict nil))
(progn
(ispell-change-dictionary "english")
(setq br_dict t))))
(global-set-key [f11] 'dict)


; O Save and exit do hugo
(defun save-exit ()
"salva o arquivo e sai"
(interactive)
(basic-save-buffer)
(save-buffers-kill-emacs))
(global-set-key "\C-q" 'save-exit)


;Adiciona o modo Regemail
(add-to-list 'auto-mode-alist '("/tmp/mutt" . regemail-mode))

(autoload 'regemail-mode "regemail")

(put 'downcase-region 'disabled nil)