Index: imap/unexpunge.c =================================================================== RCS file: /cvs/src/cyrus/imap/unexpunge.c,v retrieving revision 1.10 diff -u -d -r1.10 unexpunge.c --- imap/unexpunge.c 4 Oct 2007 14:33:51 -0000 1.10 +++ imap/unexpunge.c 17 Jan 2008 13:47:12 -0000 @@ -87,6 +87,7 @@ { fprintf(stderr, "unexpunge [-C ] -l \n" + "unexpunge [-C ] -t time-interval [ -d ] [ -v ] mailbox\n" "unexpunge [-C ] -a [-d] [-v] \n" "unexpunge [-C ] -u [-d] [-v] ...\n"); exit(-1); @@ -96,6 +97,7 @@ MODE_UNKNOWN = -1, MODE_LIST, MODE_ALL, + MODE_TIME, MODE_UID }; @@ -432,12 +434,14 @@ const char *lockfailaction; struct msg *msgs; unsigned numrestored = 0; + time_t last_update, time_since = time(NULL); + int len, secs = 0; if ((geteuid()) == 0 && (become_cyrus() != 0)) { fatal("must run as the Cyrus user", EC_USAGE); } - while ((opt = getopt(argc, argv, "C:laudv")) != EOF) { + while ((opt = getopt(argc, argv, "C:laudt:v")) != EOF) { switch (opt) { case 'C': /* alt config file */ alt_config = optarg; @@ -453,6 +457,32 @@ mode = MODE_ALL; break; + case 't': + if (mode != MODE_UNKNOWN) usage(); + + mode = MODE_TIME; + secs = atoi(optarg); + len = strlen(optarg); + + if ((secs > 0) && (len > 1)) { + switch (optarg[len-1]) { + case 'm': + secs *= 60; + break; + case 'h': + secs *= (60*60); + break; + case 'd': + secs *= (24*60*60); + break; + case 'w': + secs *= (7*24*60*60); + break; + } + } + time_since = time(NULL) - secs; + break; + case 'u': if (mode != MODE_UNKNOWN) usage(); mode = MODE_UID; @@ -580,6 +610,10 @@ switch (mode) { case MODE_LIST: msgs[msgno].restore = 0; break; case MODE_ALL: msgs[msgno].restore = 1; break; + case MODE_TIME: + last_update = ntohl(*((bit32 *)(rec+OFFSET_LAST_UPDATED))); + msgs[msgno].restore = (last_update > time_since); + break; case MODE_UID: /* see if this UID is in our list */ msgs[msgno].restore = bsearch(&uid, uids, nuids, Index: man/unexpunge.8 =================================================================== RCS file: /cvs/src/cyrus/man/unexpunge.8,v retrieving revision 1.2 diff -u -d -r1.2 unexpunge.8 --- man/unexpunge.8 30 Nov 2006 17:11:23 -0000 1.2 +++ man/unexpunge.8 17 Jan 2008 13:47:12 -0000 @@ -56,6 +56,20 @@ .B \-C .I config-file ] +.B \-t time-interval +[ +.B \-d +] +[ +.B \-v +] +.I mailbox +.br +.B unexpunge +[ +.B \-C +.I config-file +] .B \-a [ .B \-d @@ -97,6 +111,10 @@ List the expunged messages in the specified mailbox which are available for restoration. .TP +.BI \-t " time-interval" +Unexpunge messages which were expunged in the last time-interval seconds. +(modifiers: m: minutes, h: hours, d: days, w: weeks). +.TP .B \-a Restore \fBall\fR of the expunged messages in the specified mailbox. .TP