[Dovecot] Bash script to mark all mail read in Maildir + Dovecot

Andrew Oakley andrew at aoakley.com
Mon Jan 12 12:06:08 EET 2009


Following several responses from this list (thanks all for your
comments), I've revised the script.

Notably, the script now copes with mail which has been moved to a
/cur/ folder without being read. It does still ignore a few edge-case
exceptions, in particular I'm not sure whether it copes in all
situations with the "a" status on unread mail (which Thunderbird seems
to add), but for my purposes it does the job.

I will be keeping the latest version updated with bugfixes at:

http://www.aoakley.com/articles/2009-01-11-markallread.php

...and would welcome more suggestions and new features. One of the
first things that needs adding is variables to allow the maildir path
and folder prefix to be configured.

#!/bin/bash
# markallread by Andrew Oakley www.aoakley.com Public Domain 2009-01-11
# A script to mark all maildir mail as read, including folders
# Assumptions:
# * Your maildir folder is ~/.maildir
# * Folders use Dovecot IMAP . prefix eg. ~/.maildir/.foldername
# * Folder names do not contain spaces

# Loop through ~/.maildir/.foldername/new/ folders
# This also does the ~/.maildir Inbox since it matches ~/.maildir/./new/
for i in `ls -1 ~/.maildir/.*/new/*`
do
  # Move from /new/ to /cur/
  # Also add status "seen" to message by appending :2,S to filename
  # as per http://cr.yp.to/proto/maildir.html
  mv $i `echo $i | sed -r "s/^(.*)\/new\/(.*)$/\1\/cur\/\2:2,S/"`
done

# Loop through ~/.maildir/.foldername/cur/ folders
# Required in case new mail has been moved to a cur dir without reading
# Note how these already have :2, at the end of the filename
for i in `ls -1 ~/.maildir/.*/cur/*:2, 2>/dev/null`
do
  # Add status "seen" to message by appending S to filename
  mv $i `echo $i | sed -r "s/^(.*)$/\1S/"`
done

-- 
Andrew Oakley www.aoakley.com


More information about the dovecot mailing list