How to use isync and the dovecot mail server to read your Gmail in Emacs efficiently

I have been using using Sacha Chua’s how to on using offlineimap and dovecot several times. But when I bought my latest notebook I wasn’t able to get offlineimap up and running. I’m currently using mbsync. Which is much faster and easier to configure.

I’m using ArchLinux but you should be able to adapt this guide on any other Linux distribution.

Install and configure isync

yaourt -S isync

The isync configuration file is named .mbsyncrc

edit ~/.mbsyncrc
IMAPAccount gmail
# Address to connect to
#Pass ***************
# To store the password in an encrypted file use PassCmd instead of Pass
#PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg"
# Use SSL
UseIMAPS yes
# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.
CertificateFile /etc/ssl/certs/ca-certificates.crt
#CertificateFile ~/.cert/
#CertificateFile ~/.cert/Equifax_Secure_CA.pem

IMAPStore gmail-remote
Account gmail

MaildirStore gmail-local
# The trailing "/" is important
Path ~/mail/
Inbox ~/mail/Inbox

Channel gmail
Master :gmail-remote:
Slave :gmail-local:
# Exclude everything under the internal [Gmail] folder, except the interesting folders
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"
# Or include everything
#Patterns *
# Automatically create missing mailboxes, both locally and on the server
Create Both
# Save the synchronization state files in the relevant directory
SyncState *

Edit the password and you are done.

Create the folders for your mail

mkdir -p ~/mail/Inbox

Install and configure dovecot

Install dovecot

pacman -S dovecot

Edit the main configuration file for dovecot

edit /etc/dovecot/dovecot.conf and set these lines:

protocols = imap

listen = *, ::

edit /etc/dovecot/conf.d/10-auth.conf and set these lines:

auth_mechanisms = plain

passdb {
args = /etc/dovecot/passwd
driver = passwd-file

!include auth-system.conf.ext

edit /etc/dovecot/conf.d/10-mail.conf and set these lines:

mail_location = maildir:/home/me/mail/Inbox/

namespace inbox {

inbox = yes


start dovecot

systemctl start dovecot
systemctl enable dovecot

initial sync

start the initial sync


mbsync -a

and look at output and wait. Isync is faster than offlineimap but the initial sync will still take some time.

create a cronjob for syncing

fcrontab -e

@ 10 /usr/bin/mbsync -a

configure gnus

edit ~/.gnus

(setq gnus-select-method
'(nnimap "Mail"
(nnimap-address "localhost")
(nnimap-stream network)
(nnimap-authenticator login)
(nnir-search-engine imap)))

(setq user-mail-address “”)
(setq gnus-ignored-from-addresses “”)

; set gmail smtp
(setq message-send-mail-function ‘smtpmail-send-it
smtpmail-starttls-credentials ‘((“” 587 nil nil))
smtpmail-auth-credentials ‘((“” 587 “” nil))
smtpmail-default-smtp-server “”
smtpmail-smtp-server “”
smtpmail-smtp-service 587)
;      smtpmail-local-domain “”)

and you are done.

access your emails in gnus

This is from Sacha Chuas blog:

Start Emacs. Start Gnus with M-x gnus. If you don’t see the INBOX group, press ^ (gnus-group-enter-server-mode), open nnimap:Mail, move your cursor to the INBOX, and either press RET to go into the group or press u (gnus-browse-unsubscribe-current-group) to toggle the subscription status until you’re subscribed to the group.

Have fun!

daemon like scan2pdf with OCR in Linux

I spend some time rewriting my scanner script.

My script has now these feaures:

  • autocrop
  • OCR via cuneiform
  • daemon like behavior
  • play a sound when script is finished
  • add TODO entry in my orgmode

To get the script running under Ubuntu 12.10 you need some packages:

apt-get install cuneiform sane-utils imagemagick exactimage


Now you need to find the name of you scanner by running

scanimage -L

In my case it is pixma:04A9173A_8447DA

You also need to create a folder to store your pdfs

mkdir $HOME/scans

Now you need to save the script somewhere

nano $HOME/




while :


date=`date +%F-%H-%M-%S`

#scan image

scanimage –device-name $scan_device –format tiff –resolution 150 –mode Gray –button-controlled=yes >/tmp/scan.tiff

# crop image

convert /tmp/scan.tiff -crop `convert /tmp/scan.tiff -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format ‘%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]’ info:` +repage /tmp/scan_crop.tiff

# create one-page pdf
#tiff2pdf -o /home/me/test.pdf -p A4 -F -f /home/me/test_crop.tiff


cuneiform -l ger -f hocr -o /tmp/scan_ocr.hocr /tmp/scan_crop.tiff

# combine *.hocr and *.tiff to pdf file

hocr2pdf -i “/tmp/scan_crop.tiff” -s -o “$path$date.pdf” < “/tmp/scan_ocr.hocr”

# add TODO entry for org-file

echo “* TODO sort [[file:$path$date.pdf]] :scans:” >> $org_file

aplay $sound



and make it executable by


chmod +x $HOME/


Now you can run the script with




The script waits for you to press the scan button and starts the process when pressed. After the image is scanned and processed it will give you a feedback by playing a sound.


You might need to change the path to the sound file you may also don’t want to use the orgmode integration.