ipurge evolution

Cyril Servant cyril.servant at atosorigin.com
Thu Mar 26 06:38:59 EDT 2009


Hello,

with ipurge, we can delete mails _sent_ n days ago (option -d). I'd like
to add an option (-u) in order to delete mails _received_ n days ago (I
use OFFSET_LAST_UPDATED).

An other thing I'd like to add is the "do nothing" mode (-n option) : in
this mode, display in stdout is unchanged, but no mail is deleted
(useful for tests).

Here is the patch for ipurge.c 2.3.14 :

80a81
> int udays = -1;
102a104
> int donothing = 0;
119c121
<   while ((option = getopt(argc, argv, "C:hxd:b:k:m:fsXi")) != EOF) {
---
>   while ((option = getopt(argc, argv, "C:hxd:b:k:m:fsXiu:n")) != EOF)
{
129a132,137
>     case 'u': {
>       if (optarg == 0) {
> 	usage(argv[0]);
>       }
>       udays = atoi(optarg) * 86400 /* nominal # of seconds in a 'day'
*/;
>     } break;
153a162,164
>     case 'n' : {
>       donothing = 1;
>     } break;
167,168c178,179
<   if ((days == -1 ) && (size == -1)) {
<     printf("One of these must be specified -d, -b -k, -m\n");
---
>   if ((days == -1 ) && (size == -1) && (udays == -1 )) {
>     printf("One of these must be specified -u, -d, -b, -k, -m\n");
173a185,187
>   if (donothing)
>     printf("warning : do nothing mode !\n");
> 
217,218c231,232
<   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("usage: %s [-n] [-f] [-s] [-C <alt_config>] [-x] [-X] [-i]
{-u days|-d days | -b bytes|-k Kbytes|-m Mbytes}\n\t[mboxpattern1 ...
[mboxpatternN]]\n", name);
>   printf("\tthere are no defaults and at least one of -u, -d, -b, -k,
-m\n\tmust be specified\n");
221a236
>   printf("\t -n do not really delete mails\n");
296a312
>   bit32 uptime;
300a317
>   uptime = ntohl(*((bit32 *)(buf + OFFSET_LAST_UPDATED)));
316a334,352
> 	  if (donothing)
> 	      return 0;
> 	  return 1;
>       } else {
> 	  if (!invertmatch) return 0;
> 	  deleteit(msgsize, stats);
> 	  if (donothing)
> 	      return 0;
> 	  return 1;
>       }
>     }
>     if (udays >= 0) {
>       my_time = time(0);
>       /*    printf("comparing %ld :: %ld\n", my_time, uptime); */
>       if (((my_time - (time_t) uptime)/86400) == (udays/86400)) {
> 	  if (invertmatch) return 0;
> 	  deleteit(msgsize, stats);
> 	  if (donothing)
> 	      return 0;
320a357,358
> 	  if (donothing)
> 	      return 0;
328a367,368
> 	  if (donothing)
> 	      return 0;
332a373,374
> 	  if (donothing)
> 	      return 0;
342a385,386
> 	  if (donothing)
> 	      return 0;
346a391,408
> 	  if (donothing)
> 	      return 0;
> 	  return 1;
>       }
>     }
>     if (udays >= 0) {
>       my_time = time(0);
>       /*    printf("comparing %ld :: %ld\n", my_time, uptime); */
>       if (!invertmatch && ((my_time - (time_t) uptime) > udays)) {
> 	  deleteit(msgsize, stats);
> 	  if (donothing)
> 	      return 0;
> 	  return 1;
>       }
>       if (invertmatch && ((my_time - (time_t) uptime) < udays)) {
> 	  deleteit(msgsize, stats);
> 	  if (donothing)
> 	      return 0;
353a416,417
> 	  if (donothing)
> 	      return 0;
357a422,423
> 	  if (donothing)
> 	      return 0;

-- 
Cyril Servant <cyril.servant at atosorigin.com>



More information about the Cyrus-devel mailing list