[PATCH] Use INTERNALDATE for ipurge (was: ipurge to use -d as receive date and not sent date)

Henrique de Moraes Holschuh hmh at debian.org
Tue Oct 14 12:14:47 EDT 2003


Please try the attached patch.

It switches default behaviour to least-surprise (INTERNALDATE), adds
-X to get the old behaviour, and enhances ipurge by adding -i to invert
match logic.

On Tue, 14 Oct 2003, Carsten Hoeger wrote:
> On Tue, Oct 14, Rob Siemborski wrote:
> > If a patch was supplied to make this be handled by a command-line option,
> > we'd probably take it (it shouldn't be that much work).
> 
> Yes.
> It's quite simple, but I don't want to do it without asking.
> I'll submit it if it is ready.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
-------------- next part --------------
Index: ipurge.c
===================================================================
RCS file: /home/cvs/debian/cyrus21-imapd/imap/ipurge.c,v
retrieving revision 1.8
diff -u -r1.8 ipurge.c
--- ipurge.c	22 Apr 2003 21:15:03 -0000	1.8
+++ ipurge.c	14 Oct 2003 16:06:24 -0000
@@ -82,6 +82,8 @@
 int exact = -1;
 int pattern = -1;
 int skipflagged = 0;
+int datemode = OFFSET_INTERNALDATE;
+int invertmatch = 0;
 
 /* for statistical purposes */
 typedef struct mbox_stats_s {
@@ -114,7 +116,7 @@
     usage(argv[0]);
   }
 
-  while ((option = getopt(argc, argv, "C:hxd:b:k:m:fs")) != EOF) {
+  while ((option = getopt(argc, argv, "C:hxd:b:k:m:fsXi")) != EOF) {
     switch (option) {
     case 'C': /* alt config file */
       alt_config = optarg;
@@ -152,6 +154,12 @@
     case 's' : {
       skipflagged = 1;
     } break;
+    case 'X' : {
+      datemode = OFFSET_SENTDATE;
+    } break;
+    case 'i' : {
+      invertmatch = 1;
+    } break;
     case 'h':
     default: usage(argv[0]);
     }
@@ -195,12 +203,14 @@
 
 int
 usage(char *name) {
-  printf("usage: %s [-f] [-s] [-C <alt_config>] [-x] {-d days &| -b bytes|-k Kbytes|-m Mbytes}\n\t[mboxpattern1 ... [mboxpatternN]]\n", name);
+  printf("usage: %s [-f] [-s] [-C <alt_config>] [-x] [-X] [-i] {-d days | -b bytes|-k Kbytes|-m Mbytes}\n\t[mboxpattern1 ... [mboxpatternN]]\n", name);
   printf("\tthere are no defaults and at least one of -d, -b, -k, -m\n\tmust be specified\n");
   printf("\tif no mboxpattern is given %s works on all mailboxes\n", name);
   printf("\t -x specifies an exact match for days or size\n");
   printf("\t -f force also to delete mail below user.* and INBOX.*\n");
   printf("\t -s skip over messages that are flagged.\n");
+  printf("\t -X use Date: header instead of delivery time for date matches.\n");
+  printf("\t -i invert match logic: -x means not equal, date is for newer, size is for smaller.\n");
   exit(0);
 }
 
@@ -270,7 +280,7 @@
   bit32 msgsize;
   bit32 flagged;
 
-  senttime = ntohl(*((bit32 *)(buf + OFFSET_SENTDATE)));
+  senttime = ntohl(*((bit32 *)(buf + datemode)));
   msgsize = ntohl(*((bit32 *)(buf + OFFSET_SIZE)));
   flagged = ntohl(*((bit32 *)(buf + OFFSET_SYSTEM_FLAGS))) & FLAG_FLAGGED;
 
@@ -285,6 +295,11 @@
       my_time = time(0);
       /*    printf("comparing %ld :: %ld\n", my_time, the_record->sentdate); */
       if (((my_time - (time_t) senttime)/86400) == (days/86400)) {
+	  if (invertmatch) return 0;
+	  deleteit(msgsize, stats);
+	  return 1;
+      } else {
+	  if (!invertmatch) return 0;
 	  deleteit(msgsize, stats);
 	  return 1;
       }
@@ -292,6 +307,11 @@
     if (size >= 0) {
       /* check size */
       if (msgsize == size) {
+	  if (invertmatch) return 0;
+	  deleteit(msgsize, stats);
+	  return 1;
+      } else {
+	  if (!invertmatch) return 0;
 	  deleteit(msgsize, stats);
 	  return 1;
       }
@@ -301,14 +321,22 @@
     if (days >= 0) {
       my_time = time(0);
       /*    printf("comparing %ld :: %ld\n", my_time, the_record->sentdate); */
-      if ((my_time - (time_t) senttime) > days) {
+      if (!invertmatch && ((my_time - (time_t) senttime) > days)) {
+	  deleteit(msgsize, stats);
+	  return 1;
+      }
+      if (invertmatch && ((my_time - (time_t) senttime) < days)) {
 	  deleteit(msgsize, stats);
 	  return 1;
       }
     }
     if (size >= 0) {
       /* check size */
-      if (msgsize > size) {
+      if (!invertmatch && (msgsize > size)) {
+	  deleteit(msgsize, stats);
+	  return 1;
+      }
+      if (invertmatch && (msgsize < size)) {
 	  deleteit(msgsize, stats);
 	  return 1;
       }


More information about the Info-cyrus mailing list