summaryrefslogtreecommitdiff
blob: 0927aac8a0f05740c86ca2f1214b5369eafff5dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
Index: hdrline.c
===================================================================
--- hdrline.c	(revision 802)
+++ hdrline.c	(working copy)
@@ -302,11 +302,11 @@
   case '(':
   case '<':
 
-    /* preprocess $date_format to handle %Z */
+    /* preprocess $date_format to handle %Z and %Q,%q */
     {
       const char *cp;
-      struct tm *tm;
-      time_t T;
+      struct tm *tm, *TM;
+      time_t t, T;
 
       p = dest;
 
@@ -318,6 +318,28 @@
       else
         do_locales = 1;
 
+      if (do_locales && Locale)
+        setlocale (LC_TIME, Locale);
+
+      tm = alloca(sizeof(struct tm));
+      if (op == '[' || op == 'D')
+        tm = localtime_r (&hdr->date_sent, tm);
+      else if (op == '(')
+        tm = localtime_r (&hdr->received, tm);
+      else if (op == '<') {
+        T = time (NULL);
+        tm = localtime_r (&T, tm);
+      }
+      else {
+        /* restore sender's time zone */
+        T = hdr->date_sent;
+        if (hdr->zoccident)
+          T -= (hdr->zhours * 3600 + hdr->zminutes * 60);
+        else
+          T += (hdr->zhours * 3600 + hdr->zminutes * 60);
+        tm = gmtime_r (&T, tm);
+      }
+
       len = destlen - 1;
       while (len > 0 && (((op == 'd' || op == 'D') && *cp) ||
                          (op == '{' && *cp != '}') ||
@@ -335,6 +357,43 @@
             }
             else
               break;            /* not enough space left */
+          } else if (*cp == 'Q' || *cp == 'q') {
+            t = mktime (tm);
+            T = time (NULL);
+            TM = localtime (&T);
+            
+            if (len < 6)
+              break;            /* not enough space left */
+
+            /* figure out what the date format should be:
+             * if the message is in the future: treat as if it were in
+             * the past
+             * if the message was within the last 12 hours: "%k:%M "
+             * if the message was within the last 7 days: "%a-%d"
+             * if the message was within the last 12 months: "%d-%b"
+             * if the message is older than a year: "%b-%y"
+             */
+
+            if (t > T) /* future: reverse */
+              t -= 2 * (t - T);
+
+            if (t > T - 43200) { /* 12 hours */
+              sprintf (p, "%s", "%H:%M ");
+              p += 1;
+              len -= 1;
+            }
+            else if (t >= T - 518400) { /* 6 days */
+              sprintf (p, "%s", "%a-%d");
+            }
+            else if (((TM->tm_year - tm->tm_year) * 12 + TM->tm_mon) -
+                       tm->tm_mon < 12) { /* last 11 months */
+              sprintf (p, "%s", "%d-%b");
+            }
+            else { /* older than a year */
+              sprintf (p, "%s", "%b-%y");
+            }
+            p += 5;
+            len -= 5;
           }
           else {
             if (len >= 2) {
@@ -354,27 +413,6 @@
       }
       *p = 0;
 
-      if (do_locales && Locale)
-        setlocale (LC_TIME, Locale);
-
-      if (op == '[' || op == 'D')
-        tm = localtime (&hdr->date_sent);
-      else if (op == '(')
-        tm = localtime (&hdr->received);
-      else if (op == '<') {
-        T = time (NULL);
-        tm = localtime (&T);
-      }
-      else {
-        /* restore sender's time zone */
-        T = hdr->date_sent;
-        if (hdr->zoccident)
-          T -= (hdr->zhours * 3600 + hdr->zminutes * 60);
-        else
-          T += (hdr->zhours * 3600 + hdr->zminutes * 60);
-        tm = gmtime (&T);
-      }
-
       strftime (buf2, sizeof (buf2), dest, tm);
 
       if (do_locales)
@@ -751,3 +789,4 @@
   mutt_FormatString (dest, destlen, s, hdr_format_str, (unsigned long) &hfi,
                      flags);
 }
+/* vim:set expandtab sw=2 ts=2: */