Bash – How to configure mutt to display the date header in the local time zone in the pager

bashconfigurationemailmuttshell-script

When I view a message in the pager mutt displays the time in the Date header in UTC rather than my local time zone. The index view displays the local time correctly. I found this old mailing list post that describes how to get the local time to display in the status bar at the bottom of the screen, but this still doesn't "fix" the time in the Date header at the top of the screen. Is there any way to get the pager to convert the Date header time to local time?

Best Answer

In your .muttrc add the following line:

set display_filter="exec sed -r \"s/^Date:\\s*(([F-Wa-u]{3},\\s*)?[[:digit:]]{1,2}\\s+[A-Sa-y]{3}\\s+[[:digit:]]{4}\\s+[[:digit:]]{1,2}:[[:digit:]]{1,2}(:[[:digit:]]{1,2})?\\s+[+-][[:digit:]]{4})/date +'Date: %a, %d %b %Y %H:%M:%S %z' -d '\\1'/e\""

This will change the Date: header in the message (for display only) to your local timezone if the header contained a valid RFC formatted date. If the provided date format was incorrect (we are dealing with untrusted user input after all) it will be preserved. To combat a possible attempt to inject the shell code through the header the sed pattern implements a whitelist based on RFC 5322 (this RFC defines the format of the Date: field).

Note that mutt limits the command line to be no more than 255 character long, hence I optimised the original sed command that had stricter whitelist to fit into 255 bytes. If you plan to do other things with the message, then the full sed command you can put in a script is:

sed -r "s/^Date:\s*(((Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s*)?[[:digit:]]{1,2}\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+[[:digit:]]{4}\s+[[:digit:]]{1,2}:[[:digit:]]{1,2}(:[[:digit:]]{1,2})?\s+[+-][[:digit:]]{4})/date +'Date: %a, %d %b %Y %H:%M:%S %z' -d '\1'/e"
Related Question