email rename regex

License (Code):CC0
License (Text):CC-BY
Tags:RegEx

When you export emails from Thunderbird, it generates .eml files which have a pretty unusable name for me:

Re: Happy Birthday - Full Name <email@example.com> - YYYY-MM-DD HHMM.eml

The problem with those names are that a lot of those files in a folder are going to be sorted by subject, which does not even work with the Re: in front of some emails.

I renamed all those emails to a more sensible format:

YYYYMMDD-HHMM-Full Name <email@example.com>-Re: Happy Birthday.eml

This rename command does the trick:

rename 's#(.*?)([^/]*) - ([^/]*) - (\d{4})-(\d{2})-(\d{2}) (\d{4})\.eml#$1$4$5$6-$7-$3-$2.eml#'