Mercurial > dovecot > core-2.2
changeset 22088:1e5a91e481ec
mail-crypt: Re-encrypt mails when copying/moving
Otherwise the mail cannot be opened after moving
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Thu, 04 May 2017 09:14:17 +0300 |
parents | 508ead937228 |
children | d13ea491ecc4 |
files | src/plugins/mail-crypt/mail-crypt-plugin.c |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/mail-crypt/mail-crypt-plugin.c Wed May 24 22:31:59 2017 +0300 +++ b/src/plugins/mail-crypt/mail-crypt-plugin.c Thu May 04 09:14:17 2017 +0300 @@ -332,6 +332,16 @@ return 0; } +static int +mail_crypt_mailbox_copy(struct mail_save_context *ctx, struct mail *mail) +{ + struct mail_crypt_mailbox *mbox = MAIL_CRYPT_CONTEXT(ctx->transaction->box); + + if (ctx->transaction->box != mail->box) + return mail_storage_copy(ctx, mail); + return mbox->module_ctx.super.copy(ctx, mail); +} + static void mail_crypt_mailbox_close(struct mailbox *box) { struct mail_crypt_mailbox *mbox = MAIL_CRYPT_CONTEXT(box); @@ -356,6 +366,13 @@ mbox = p_new(box->pool, struct mail_crypt_mailbox, 1); mbox->module_ctx.super = *v; box->vlast = &mbox->module_ctx.super; + /* if global keys are used, re-encrypting on copy/move + is not necessary, so do not attempt to do it. + + with per-folder keys, emails must be re-encrypted + when moving to another folder */ + if (muser->global_keys.public_key == NULL) + v->copy = mail_crypt_mailbox_copy; v->close = mail_crypt_mailbox_close; MODULE_CONTEXT_SET(box, mail_crypt_storage_module, mbox);