[Dovecot] Know when a Folder is Expunged or Deleted
Hi Timo and Everyone....
There is a way to know when a folder it's been deleted ? And if this folder is empty ?
Let's explain why...
I intercept the expunge function, to treat my files expunged, but when i expunge a folder, this function it's not called, and my emails don't get my treatment to be expunged.
Basically i need to do something like this:
It's empty ? No --> return OK but Dont Delete folder, because it's not empty. Yes --> Return OK and Delete the Folder to be expunged.
Tks !
On Mon, 2010-11-01 at 14:26 -0200, Alex Baule wrote:
I intercept the expunge function, to treat my files expunged, but when i expunge a folder, this function it's not called, and my emails don't get my treatment to be expunged.
Yeah.. Maybe some day I should change the mailbox deletion to work by sending expunge to all mails and then simply removing the empty mailbox. This is how it works with multi-dbox, but not with others.
Basically i need to do something like this:
It's empty ? No --> return OK but Dont Delete folder, because it's not empty. Yes --> Return OK and Delete the Folder to be expunged.
So you want to disallow deleting non-empty folders? Anyway, you need to hook into struct mailbox.delete. See quota_mailbox_delete() in quota plugin. box->opened=TRUE if it was a real selectable mailbox, while it's FALSE if it was simply a directory (Maildir++ has only selectable mailboxes).
Hi Timo....
I try to do what you said, but i can't delete a folder from maildir, because the box->opened it's allways true.
This is my hooked function...
static int emexis_mailbox_delete(struct mailbox *box) { union mailbox_module_context *zbox = EMEXIS_CONTEXT(box);
if (!box->opened) {
i_warning("Empty Folder...");
return zbox->super.delete(box);
}
i_warning("Full Folder...");
return -1;
}
Can i do that in "rename mailbox" function ? If Rename has .Trash in the name, i don't rename and return -1.
Another Question...
i Try too, don't let the user "move" one message from any folder to my "quarantine" folder, i intercept the copy function with a hook, but i only can do this, returning -1 in the copy function, but with -1 i will get a error message in the client like "Mailbox already exist" if i return 0 the source email is flaged as Trash and don't show anymore in the source folder... Can i do this, returning some value that works well and dont cause a client message ?
Tks Timo !
2010/11/2 Timo Sirainen tss@iki.fi
On Mon, 2010-11-01 at 14:26 -0200, Alex Baule wrote:
I intercept the expunge function, to treat my files expunged, but when i expunge a folder, this function it's not called, and my emails don't get my treatment to be expunged.
Yeah.. Maybe some day I should change the mailbox deletion to work by sending expunge to all mails and then simply removing the empty mailbox. This is how it works with multi-dbox, but not with others.
Basically i need to do something like this:
It's empty ? No --> return OK but Dont Delete folder, because it's not empty. Yes --> Return OK and Delete the Folder to be expunged.
So you want to disallow deleting non-empty folders? Anyway, you need to hook into struct mailbox.delete. See quota_mailbox_delete() in quota plugin. box->opened=TRUE if it was a real selectable mailbox, while it's FALSE if it was simply a directory (Maildir++ has only selectable mailboxes).
On Wed, 2010-11-03 at 09:38 -0200, Alex Baule wrote:
I try to do what you said, but i can't delete a folder from maildir, because the box->opened it's allways true.
It's supposed to be, yes.
if (!box->opened) { i_warning("Empty Folder...");
No, box->opened doesn't mean it's empty. It means it's not a mailbox at all. For example with mbox you could have:
~/mail/archive/ ~/mail/archive/2009
Now you would have "archive" directory which would show up as box->opened=FALSE, but "archive/2009" would be box->opened=TRUE, regardless of how many messages it has.
If you want to check if the mailbox is empty, you need to check for it manually with mailbox_status().
return zbox->super.delete(box); } i_warning("Full Folder..."); return -1;
}
Can i do that in "rename mailbox" function ? If Rename has .Trash in the name, i don't rename and return -1.
I'm not sure what you mean.. Yes, you can cancel a rename operation if you want to.
i Try too, don't let the user "move" one message from any folder to my "quarantine" folder, i intercept the copy function with a hook, but i only can do this, returning -1 in the copy function, but with -1 i will get a error message in the client like "Mailbox already exist" if i return 0 the source email is flaged as Trash and don't show anymore in the source folder... Can i do this, returning some value that works well and dont cause a client message ?
Use mail_storage_set_error() before returning -1.
Using the mail_storage_set_error() works well, i set my messages with this..!
I said use the rename, because to delete a folder call the rename function, ex(MyFolder --> Trash.MyFolder)
i will use the mailbox_status() in rename hook, because if i return -1, the Folder will remain unchanged, and don't be moved to Trash.
2010/11/3 Timo Sirainen tss@iki.fi
On Wed, 2010-11-03 at 09:38 -0200, Alex Baule wrote:
I try to do what you said, but i can't delete a folder from maildir, because the box->opened it's allways true.
It's supposed to be, yes.
if (!box->opened) { i_warning("Empty Folder...");
No, box->opened doesn't mean it's empty. It means it's not a mailbox at all. For example with mbox you could have:
~/mail/archive/ ~/mail/archive/2009
Now you would have "archive" directory which would show up as box->opened=FALSE, but "archive/2009" would be box->opened=TRUE, regardless of how many messages it has.
If you want to check if the mailbox is empty, you need to check for it manually with mailbox_status().
return zbox->super.delete(box); } i_warning("Full Folder..."); return -1;
}
Can i do that in "rename mailbox" function ? If Rename has .Trash in the name, i don't rename and return -1.
I'm not sure what you mean.. Yes, you can cancel a rename operation if you want to.
i Try too, don't let the user "move" one message from any folder to my "quarantine" folder, i intercept the copy function with a hook, but i only can do this, returning -1 in the copy function, but with -1 i will get a error message in the client like "Mailbox already exist" if i return 0 the source email is flaged as Trash and don't show anymore in the source folder... Can i do this, returning some value that works well and dont cause a client message ?
Use mail_storage_set_error() before returning -1.
On Wed, 2010-11-03 at 13:09 -0200, Alex Baule wrote:
I said use the rename, because to delete a folder call the rename function, ex(MyFolder --> Trash.MyFolder)
Oh, that. But remember that it's only Thunderbird that does this renaming. I'm not aware of any other client that does it, they just delete it immediately.
Ok, I will put the hook in delete function.
Tks Timo !
2010/11/3 Timo Sirainen tss@iki.fi
On Wed, 2010-11-03 at 13:09 -0200, Alex Baule wrote:
I said use the rename, because to delete a folder call the rename function, ex(MyFolder --> Trash.MyFolder)
Oh, that. But remember that it's only Thunderbird that does this renaming. I'm not aware of any other client that does it, they just delete it immediately.
participants (2)
-
Alex Baule
-
Timo Sirainen