summarylogtreecommitdiffstats
path: root/ats.date_conditional.patch
blob: c2011e154386cf5a532285c08511bd7777a80227 (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
Allows you to construct format expressions based on relative dates.

This adds conditionality features to mutt's date-formatting operators,
so that you can build conditions based on whether the date in question
is less than or grater than some amount in the past.

Example: %?[1y?less than one year&greater than one year?
Example: %?[3d?less than three days&greater than three days?

This is particularly useful in concert with nested_if.  For example,
this expression:
    %<[1y?%<[1w?%<[1d?%[ %H:%M]&%[%a %d]>&%[%b %d]>&%[%y%m%d]>

means to show the YYMMDD date for messages older than one year, the "mon
dd" date for messages from one week to one year, the "day dd" date for
messages from 1 to 7 days old, and the HH:MM time for messages under one
day old.

diff -r e2b6d94be38e hdrline.c
--- a/hdrline.c	Mon Jan 03 13:24:23 2011 -0600
+++ b/hdrline.c	Mon Jan 03 13:24:27 2011 -0600
@@ -341,6 +341,53 @@
 	const char *cp;
 	struct tm *tm; 
 	time_t T;
+	int i = 0, invert = 0;
+
+	if (optional && (op == '[' || op == '(')) {
+	  char *is;
+	  T = time(NULL);
+	  T -= (op == '(') ? hdr->received : hdr->date_sent;
+
+	  is = (char *)prefix;
+	  if( *is == '>' ) {
+	    invert = 1;
+	    ++is;
+	  }
+
+	  while( *is && *is != '?' ) {
+	    int t = strtol (is, &is, 10);
+	    switch (*(is++)) {
+	      case '?':
+		break;
+	      case 'y':
+		t *= 365 * 24 * 60 * 60;
+		break;
+	      case 'M':
+		t *= 30 * 24 * 60 * 60;
+		break;
+	      case 'w':
+		t *= 7 * 24 * 60 * 60;
+		break;
+	      case 'd':
+		t *= 24 * 60 * 60;
+		break;
+	      case 'h':
+		t *= 60 * 60;
+		break;
+	      case 'm':
+		t *= 60;
+		break;
+	    }
+	    i += t;
+	  }
+
+	  if (i < 0)
+	    i *= -1;
+
+	  if( (T > i || T < -1*i) ^ invert )
+	    optional = 0;
+	  break;
+	}
 
 	p = dest;
 
@@ -364,6 +411,7 @@
 	  {
 	    cp++;
 	    if ((*cp == 'Z' || *cp == 'z') && (op == 'd' || op == '{'))
+	    /* brace balancer: } */
 	    {
 	      if (len >= 5)
 	      {
diff -r e2b6d94be38e muttlib.c
--- a/muttlib.c	Mon Jan 03 13:24:23 2011 -0600
+++ b/muttlib.c	Mon Jan 03 13:24:27 2011 -0600
@@ -1239,7 +1239,16 @@
       if (*src == '?')
       {
 	flags |= M_FORMAT_OPTIONAL;
+	ch = *(++src); /* save the character to switch on */
 	src++;
+	cp = prefix;
+	count = 0;
+	while (count < sizeof (prefix) && *src != '?')
+	{
+	  *cp++ = *src++;
+	  count++;
+	}
+	*cp = 0;
       }
       else
       {
@@ -1255,12 +1264,13 @@
 	  count++;
 	}
 	*cp = 0;
+
+        if (!*src)
+	  break; /* bad format */
+
+        ch = *src++; /* save the character to switch on */
       }
 
-      if (!*src)
-	break; /* bad format */
-
-      ch = *src++; /* save the character to switch on */
 
       if (flags & M_FORMAT_OPTIONAL)
       {