This index_format variable
set index_format='mfdate "%[%s]" "%4C %Z %[!%b %d %Y] %-17.17F (%3l) %s" |'
together with this modified mfdate.c presented in this answer by user hop:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define DAY (time_t)86400
#define YEAR (time_t)31556926
int main(int argc, const char *argv[]) {
time_t current_time;
time_t message_time;
const char *old = "old";
char *recent = "recent";
char *today = "today";
const char *format;
current_time = time(NULL);
if (argc != 3) {
printf("Usage: %s format\n", argv[0]);
return EXIT_FAILURE;
}
format = argv[2];
message_time = atoi(argv[1]);
if ((message_time/YEAR) < (current_time/YEAR)) {
printf("%s,%s", old, format);
} else if ((message_time/DAY) < (current_time/DAY)) {
printf("%s,%s", recent, format);
} else {
printf("%s,%s", today, format);
}
return EXIT_SUCCESS;
}
works correctly for me in mutt 1.6.1 and as you see there are no problems with % sign in the subject, if this
is what the real problem was about:
This is the initial "just working" version because after taking a closer look at your original question I am
not sure if this is what you want. However, if this is what you want let me know and we'll think how to make it better.
EDIT:
It can also work with your preferred index_format:
set index_format='mfdate "%[%s]" "%%Z %%{%%Y %%b %%e %%H:%%M} %%?X?(%%X)& ? %%-22.22F %%.100s %%> %%5c" |'
mfdate.c:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define DAY (time_t)86400
#define YEAR (time_t)31556926
int main(int argc, const char *argv[]) {
time_t current_time;
time_t message_time;
const char *old = "old";
char *recent = "recent";
char *today = "today";
const char *format;
current_time = time(NULL);
if (argc != 3) {
printf("Usage: %s format\n", argv[0]);
return EXIT_FAILURE;
}
format = argv[2];
message_time = atoi(argv[1]);
if ((message_time/YEAR) < (current_time/YEAR)) {
printf("%s,%s%%", old, format);
} else if ((message_time/DAY) < (current_time/DAY)) {
printf("%s,%s%%", recent, format);
} else {
printf("%s,%s%%", today, format);
}
return 0;
}

EDIT:
Let me explain how it works:
The mfdate takes 2 arguments:
"%[%s]"
and:
"%%Z %%{%%Y %%b %%e %%H:%%M} %%?X?(%%X)& ? %%-22.22F %%.100s %%> %%5c"
The first argument is only time of the message, as described in
index_format documentation in .muttrc:
# %[fmt] the date and time of the message is converted to the local
# time zone, and ``fmt'' is expanded by the library function
# ``strftime''; a leading bang disables locales
In this case fmt is replaced with %s, because as %s means The
number of seconds since the Epoch as explained in man strftime. The
first argument is used to compute how old the message is and what
label: old, recent or today it should have.
The second argument is the remaining part of the index_format
variable. It's used in mfdate only for printing but an extra % is
added at the end of printf because as it says in mutt manual:
The string returned will be used for display. If the returned string
ends in %, it will be passed through the formatter a second time.
Every % is doubled here because we want to pass a literal % to the
second formatting done by mutt.