Save space in a Maildir by hard-linking identical message files

hardlinkmaildir

Obviously, the answer to the question in the title is yes. But I really want to know if I can do it without breaking anything.

I am using offlineimap to back up my Gmail account to a Maildir on my local computer. Since Gmail lets you easily assign multiple labels to your mail, my backup directory ends up with multiple copies of most of my mails. I would like to save space by replacing copies of the same message with hard links, using a script called hardlink. Could this possibly cause problems for applications using the Maildir, or could it cause applications to corrupt my mailboxes? Or would modification of any mail files simply break any hard links associated with that file, without affecting the previous version that was hard-linked elsewhere?

Best Answer

Hardlinking copies of the same message is done by several IMAP servers.

On the other hand, those IMAP servers expect hardlinks. Some other Maildir programs may not. But it should not cause any damage, other than breaking the link.


Could this possibly cause problems for applications using the Maildir

Unlikely.

or could it cause applications to corrupt my mailboxes?

There is nothing that can get corrupted in a Maildir -- except possibly header caches kept by some MUAs and/or IMAP servers, but a cache is something that can be thrown away.

Or would modification of any mail files simply break any hard links associated with that file, without affecting the previous version that was hard-linked elsewhere?

Depends on how the modification is made.

  • Truncate and overwrite: Works fine. Other directories have the updated message.
  • Write temporary file and rename: Works, but the link is broken and updates will not be visible in other folders (which have the old file).

Although I can't imagine why would offlineimap modify a message...