File indexing completed on 2024-09-22 04:50:04

0001 /*
0002  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #pragma once
0009 
0010 #include "mailcommon/searchpattern.h"
0011 #include "mailcommon_export.h"
0012 
0013 #include <Akonadi/Collection>
0014 #include <Akonadi/Item>
0015 
0016 namespace MailCommon
0017 {
0018 /**
0019  * @short A helper class for the filtering process
0020  *
0021  * The item context is used to pass the item together with meta data
0022  * through the filter chain.
0023  * This allows to 'record' all actions that shall be taken and execute them
0024  * at the end of the filter chain.
0025  */
0026 class MAILCOMMON_EXPORT ItemContext
0027 {
0028 public:
0029     /**
0030      * Creates an item context for the given @p item.
0031      * @p requestedPart the part requested for the item (Envelope, Header or CompleteMessage)
0032      */
0033     ItemContext(const Akonadi::Item &item, bool needsFullPayload);
0034 
0035     /**
0036      * Returns the item of the context.
0037      */
0038     Akonadi::Item &item();
0039 
0040     /**
0041      * Sets the target collection the item should be moved to.
0042      */
0043     void setMoveTargetCollection(const Akonadi::Collection &collection);
0044 
0045     /**
0046      * Returns the target collection the item should be moved to, or an invalid
0047      * collection if the item should not be moved at all.
0048      */
0049     [[nodiscard]] Akonadi::Collection moveTargetCollection() const;
0050 
0051     /**
0052      * Marks that the item's payload has been changed and needs to be written back.
0053      */
0054     void setNeedsPayloadStore();
0055 
0056     /**
0057      * Returns whether the item's payload needs to be written back.
0058      */
0059     [[nodiscard]] bool needsPayloadStore() const;
0060 
0061     /**
0062      * Marks that the item's flags has been changed and needs to be written back.
0063      */
0064     void setNeedsFlagStore();
0065 
0066     /**
0067      * Returns whether the item's flags needs to be written back.
0068      */
0069     [[nodiscard]] bool needsFlagStore() const;
0070 
0071     /** Returns true if the full payload was requested for the item or not.
0072      * Full payload is needed to change the headers or the body */
0073     [[nodiscard]] bool needsFullPayload() const;
0074 
0075     void setDeleteItem();
0076     [[nodiscard]] bool deleteItem() const;
0077 
0078 private:
0079     enum ItemContextAction { None = 0, PlayloadStore = 1, FlagStore = 2, DeleteItem = 4, FullPayload = 8 };
0080     Q_DECLARE_FLAGS(ItemContextActions, ItemContextAction)
0081 
0082     Akonadi::Item mItem;
0083     Akonadi::Collection mMoveTargetCollection;
0084     ItemContextActions mItemContextAction;
0085 };
0086 }