DEBUG_FUNCTION void debug_verbose (expr_def *ptr) { if (ptr) debug_verbose (*ptr); else fprintf (stderr, "<nil>\n"); }
static int antispam_copy(struct mail_save_context *ctx, struct mail *mail) { struct mailbox_transaction_context *t = ctx->transaction; struct antispam_mailbox *asbox = ANTISPAM_CONTEXT(t->box); struct antispam_internal_context *ast = ANTISPAM_CONTEXT(t); int ret; bool src_trash, dst_trash; if (!ctx->dest_mail) { /* always need mail */ if (!ast->mail) ast->mail = mail_alloc(t, MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY, NULL); ctx->dest_mail = ast->mail; } i_assert(mail->box); asbox->save_hack = FALSE; asbox->movetype = MMT_UNINTERESTING; if (mailbox_is_unsure(t->box)) { mail_storage_set_error(t->box->storage, MAIL_ERROR_NOTPOSSIBLE, "Cannot copy to unsure folder"); return -1; } src_trash = mailbox_is_trash(mail->box); dst_trash = mailbox_is_trash(t->box); debug_verbose("mail copy: from trash: %d, to trash: %d\n", src_trash, dst_trash); if (!src_trash && !dst_trash) { bool src_spam = mailbox_is_spam(mail->box); bool dst_spam = mailbox_is_spam(t->box); bool src_unsu = mailbox_is_unsure(mail->box); debug_verbose("mail copy: src spam: %d, dst spam: %d," " src unsure: %d\n", src_spam, dst_spam, src_unsu); if ((src_spam || src_unsu) && !dst_spam) asbox->movetype = MMT_TO_CLEAN; else if ((!src_spam || src_unsu) && dst_spam) asbox->movetype = MMT_TO_SPAM; } if (asbox->module_ctx.super.copy(ctx, mail) < 0) return -1; /* * If copying used saving internally, we already have treated the mail */ if (asbox->save_hack || asbox->movetype == MMT_UNINTERESTING) ret = 0; else ret = backend->handle_mail(t, ast->backendctx, ctx->dest_mail, move_to_class(asbox->movetype)); /* * Both save_hack and movetype are only valid within a copy operation, * i.e. they are now invalid. Because, in theory, another operation * could be done after mailbox_open(), we need to reset the movetype * variable here. save_hack doesn't need to be reset because it is * only ever set within the save function and tested within this copy * function after being reset at the beginning of the copy, movetype * however is tested within the save_finish() function and a subsequent * save to the mailbox should not invoke the backend. */ asbox->movetype = MMT_APPEND; return ret; }