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.

using mpd to upload music to your android

I own an android smartphone and I’m a mpd user.

Using mpddroid, sshdroid and ubunturemote app I found a way to upload playlists from my mpd to my android. This way you can use your mpd to organize music on your android

I’m using Ubuntu Remote Control to admin my NAS. Ubuntu Remote Control is actually not limited to Ubuntu. You can use it to control every very Linux machine. So far this is the only app I found which has wake on LAN functionality included. Another aspect of the app I like is the ability to define custom commands and bin icons to them.

You can find Ubuntu Remote Control here

Ubuntu Remote Control on google play store

For my scripts to work you also need sshdroid. sshdroid is app which alows you to connect via ssh on your android. Even it is (like mine) not rooted. You can find sshdroid here:

sshdroid on google play store

For sshdroid to work you need to enable login via ssh-keys.

So ssh on your nas and run:


ssh-copy-id “root@ -p 2222”

where is the IP of your android device. I configured “static” IP for my android via my router as I don’t know any other way to do that on an none rooted android. You can also use your router to find out the local IP of your device.

once you did that you can test the setup via:

ssh root@ -p 2222

if that works you can go on writing some scripts.

This scripts copys the current played track to your android device

# copy current played track on mpd to android device
# simple shortcut to copy files to an android device running sshdroid
# sshdroid needs to be configured with ssh-key authentification
# username is root
file=`mpc -f %file% | head -n 1`
scp -P 2222 “$path” root@
echo “finished transfering files to android device”

And Here is a script to copy a playlist to your android device


while read line
scp -P 2222 “$line” root@
done </var/lib/mpd/playlists/android.m3u

bookmarking with uzbl and org-capture

I found this in a russian e-mail list archive (I haven’t found it again)

I use this little trick to capture bookmarks from my uzbl-browser.

Just add:

@cbind <Ctrl>e = sh ’emacsclient “org-protocol://capture://\\@/\\@”‘

to your


Every time I find something useful on the web I just press <Ctrl>e in my uzbl-browser and the current URL is send to my emacs. In emacs I can now turn the URL in a task, note, whatever and refile it to one of my projects. This way the information (the link) i stored where I need it.

My current org-capture setup is based on the excellent guide by Bernt Hansen.

using org2blog to blog with

howto blog from your emacs org-mode using org2blog

setting up emacs for blogging with wordpress is pretty easy. There are some packages out there which could do that job. I chose org2blog.

installing org2blog

you can install org2blog from github

just do

cd ~/.emacs.d

git clone

Add the org2blog directory to your load path and then add

(setq load-path (cons “~/.emacs.d/org2blog/” load-path)) (require ‘org2blog-autoloads)

installing xml-rpc

org2blog requires xml-rpc. xml-rpc can be installed through the emacs package manager (until than I didn’t know anything about that).

to install xml-rpc just

M-x package-install xml-rpc

i had to add manually the load-path to xml-rpc.el in my .emacs

(setq load-path (cons “~/.emacs.d/elpa/xml-rpc-1.6.7/” load-path))

configuring org2blog

just add a few lines to your .emacs as described on the github-page

(setq org2blog/wp-blog-alist ‘((“wordpress” :url “” :username “username” :default-title “Hello World” :default-categories (“org2blog” “emacs”) :tags-as-categories nil)))

reload emacs to load the changes

now run

M-x eval-buffer

while in the .emacs buffer to load the changes

test your setup

now open a new org file.

to test org2blog you can now

M-x org2blog/wp-post-buffer

your post should now appear in your wordpress blog as a draft