index_formatตัวแปรนี้
set index_format='mfdate "%[%s]" "%4C %Z %[!%b %d %Y] %-17.17F (%3l) %s" |'
พร้อมกับการแก้ไขนี้mfdate.cนำเสนอในคำตอบนี้โดยผู้ใช้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;
}
ทำงานได้อย่างถูกต้องสำหรับฉันในmutt 1.6.1และตามที่คุณเห็นไม่มีปัญหากับการ%ลงชื่อเข้าใช้ในเรื่องถ้านี่คือสิ่งที่เป็นปัญหาจริงเกี่ยวกับ:
นี่เป็นเวอร์ชั่น "เพิ่งเริ่มต้น" เพราะหลังจากดูคำถามเดิมของคุณอย่างถี่ถ้วนฉันไม่แน่ใจว่านี่คือสิ่งที่คุณต้องการหรือไม่ อย่างไรก็ตามหากนี่คือสิ่งที่คุณต้องการแจ้งให้เราทราบและเราจะคิดวิธีทำให้ดีขึ้น
แก้ไข :
นอกจากนี้ยังสามารถทำงานร่วมกับสิ่งที่คุณต้องการ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;
}

แก้ไข :
ให้ฉันอธิบายวิธีการทำงาน:
mfdateใช้เวลา 2 ข้อโต้แย้ง:
"%[%s]"
และ:
"%%Z %%{%%Y %%b %%e %%H:%%M} %%?X?(%%X)& ? %%-22.22F %%.100s %%> %%5c"
อาร์กิวเมนต์แรกเป็นเพียงtime of the messageตามที่อธิบายไว้ใน
index_formatเอกสารประกอบใน.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
ในกรณีนี้fmtจะถูกแทนที่ด้วย%sเพราะเป็น%sวิธีการที่อธิบายไว้ในThe
number of seconds since the Epoch man strftimeอาร์กิวเมนต์แรกถูกนำมาใช้เพื่อคำนวณว่าเก่าข้อความและป้ายชื่ออะไร: old, recentหรือtodayมันควรจะมี
อาร์กิวเมนต์ที่สองคือส่วนที่เหลือของindex_format
ตัวแปร มันใช้mfdateสำหรับการพิมพ์เท่านั้น แต่มีการเพิ่มพิเศษ%เมื่อสิ้นสุดprintfเพราะตามที่ระบุไว้ในคู่มือ mutt :
สตริงที่ส่งคืนจะถูกใช้สำหรับการแสดงผล หากสตริงที่ส่งคืนลงท้ายด้วย% มันจะถูกส่งผ่านฟอร์แมตเตอร์เป็นครั้งที่สอง
ทุกคน%เป็นสองเท่านี่เพราะเราต้องการที่จะผ่านตัวอักษรที่สองการจัดรูปแบบทำโดย%mutt