On Fri, 13 Apr 2007, Erik Kangas wrote:
I am looking for the easiest and most robust way to remove all user defined
keywords from a folder (which could be MIX or MBX).
Something like the following, inserted in mailutil, ought to do the trick.
No guarantees. This is just off the top of my head; I haven't actually
tested it. So you may have to do some debugging...
else if (!strcmp (cmd,"kwdzap")) {
if (!src || (*src == '{') || dst || merge || rwcopyp || kwcopyp)
printf (usage2,pgm,"kwdzap [-d[ebug]] [-v[erbose]] local_mailbox");
else if (source = mail_open (NIL,src,debugp ? OP_DEBUG : NIL)) {
STRING st;
size_t len;
char *flags;
char *dummymsg = "Date: Thu, 18 May 2006 00:00 -0700\r\nFrom: [EMAIL
PROTECTED]: dummy\r\n\r\ndummy\r\n";
/* count length of flags */
for (i = 0,len = 0; i < NUSERFLAGS; ++i)
if (source->user_flags[i]) len += strlen (source->user_flags[i]) + 1;
flags = (char *) fs_get (1 + len + 2);
s = flags; c = '('; /* initial delimiter */
for (i = 0; i < NUSERFLAGS; ++i) if (t = source->user_flags[i]) {
*s++ = c; /* write delimiter */
while (*t) *s++ = *t++; /* copy flag */
c = ' '; /* delimiter now space */
}
*s++ = ')'; /* trailing delimiter */
*s = '\0'; /* tie off flags */
/* remove keywords from all messages */
mail_flag (stream,"1:*",NIL);
/* What we are about to do here is incredibly evil and utterly
unsupported. Basically, we erase all the keywords from the
stream, then append a dummy message. The append will update
the uid_last and hopefully cause a rewite of mailbox metadata.
Note that nothing is prepared for this to happen, but with any
luck we can get away with it.
*/
for (i = 0; i < NUSERFLAGS; ++i)
if (source->user_flags[i]) fs_give ((void **) &source->user_flags[i]);
/* append dummy string to mailbox */
INIT (&st,mail_string,dummymsg,strlen (dummymsg));
if (mail_append (source,src,&st)) {
mail_setflag (dest,"*","\\Deleted");
mail_expunge (dest);
retcode = 0;
}
mail_close (source);
fs_give ((void **) &flags);
}
}
-- Mark --
http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.
_______________________________________________
Imap-uw mailing list
[EMAIL PROTECTED]
https://mailman1.u.washington.edu/mailman/listinfo/imap-uw