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?

link|improve this question
Ben I rejected your suggested edit to Michael's answer because I thought adding significant amounts of code to somebody elses answer fell outside the scope of what edits should be for. Your code looked good though and you should go ahead and add an additional answer of your own and you can mention that the script is to go along with Michael's answer. – Caleb Aug 15 '11 at 12:59
feedback

3 Answers

up vote 4 down vote accepted

The formatting in the index is controlled by the index_format setting -- it's generated by mutt. The Date header isn't controlled by mutt, it's a header included with the message that just gets displayed. If it shows UTC time it's because the sending server decided to use UTC when generating the header. The only way to change it is to actually change the message itself, either when you receive it or when you view it.

Changing it as it comes in means adding a filter to your mail delivery agent, but it needs to be sophisticated enough to parse the existing Date header and rewrite it. It's almost certainly better to just have mutt reformat the message when you look at it. You can set the display_filter property to an executable file, and it will pipe any message you open through the executable before displaying it.

You'll need to write a program or shell script that reads each line of the message and replaces the one with the Date header, or find an existing script (there's one here that might work, although it doesn't seem like it should really be necessary to involve a temporary file)

link|improve this answer
feedback

Taking Gilles' advice, here's a version that uses a temp file and formail.

#!/bin/bash
TMPFILE=$(mktemp)

# save the message to a file
cat - >"$TMPFILE"
# extract the date header
DATE=$( formail -xDate: < "$TMPFILE" )
# convert to the current timezone (defined by TZ)
DATE=$( date -R -d "$DATE" )
# output the modified message
echo "Date: $DATE"
formail -fI Date < "$TMPFILE"
# clean up
rm -f "$TMPFILE"
link|improve this answer
feedback

I made a shell script as described at the end of Michael's answer that does the job for me:

#!/bin/bash
while IFS= read -r LINE; do
    if [[ "${LINE}" =~ ^Date:\ .* ]]; then
        DATE=${LINE#Date: }
        # convert to the current timezone (defined by TZ)
        DATE=$(date -d "${DATE}")
        printf '%s' "Date: ${DATE}"
    elif [[ -n $LINE ]]; then
      # We've reach the end of the headers, so stop parsing
      echo
      exec cat
    else
        printf '%s\n' "${LINE}"
    fi
done
link|improve this answer
1  
Parsing emails is pretty tricky. I recommend using a dedicated tool like formail (part of the procmail package) or reformail (part of maildrop) to extract the existing Date: header and put a new one in place. Take care of edge cases such as a missing or malformatted Date: header. – Gilles Aug 15 '11 at 16:29
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.