File indexing completed on 2024-05-12 05:17:15

0001 /*
0002     SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kimap_export.h"
0010 
0011 #include "imapset.h"
0012 #include "job.h"
0013 
0014 namespace KIMAP
0015 {
0016 class MoveJobPrivate;
0017 
0018 /**
0019  * Moves messages from current mailbox to another
0020  *
0021  * Note that move functionality is not specified in the base IMAP
0022  * protocol and is defined as an extension in RFC6851. That means
0023  * that the MoveJob can only be used when the server lists "MOVE"
0024  * in response to CAPABILITY command.
0025  *
0026  * Unlike the traditional emulation of moving messages, i.e. COPY + STORE + EXPUNGE,
0027  * MOVE guarantees the transaction to be atomic on the server.
0028  *
0029  * @since 5.4
0030  */
0031 class KIMAP_EXPORT MoveJob : public Job
0032 {
0033     Q_OBJECT
0034     Q_DECLARE_PRIVATE(MoveJob)
0035 
0036     friend class SessionPrivate;
0037 
0038 public:
0039     explicit MoveJob(Session *session);
0040     ~MoveJob() override;
0041 
0042     /**
0043      * Set the destination mailbox
0044      *
0045      * If the mailbox does not exist, the server should not create
0046      * it automatically and the job should fail.  Note, however,
0047      * that a conforming server may create the mailbox automatically.
0048      *
0049      * @param mailBox  the (unquoted) name of the mailbox where the
0050      *                 messages should be moved to
0051      */
0052     void setMailBox(const QString &mailbox);
0053     /**
0054      * The destination mailbox
0055      */
0056     [[nodiscard]] QString mailBox() const;
0057 
0058     /**
0059      * Sets the messages to be moved,
0060      *
0061      * If sequence numbers are given, isUidBased() should be false.  If UIDs
0062      * are given, isUidBased() should be true.
0063      *
0064      * @param set  the sequence numbers or UIDs of the messages to be moved
0065      */
0066     void setSequenceSet(const ImapSet &set);
0067     /**
0068      * The messages that will be moved.
0069      *
0070      * isUidBased() can be used to check whether the ImapSet contains
0071      * sequence numbers or UIDs.
0072      *
0073      * @return  the sequence numbers or UIDs of the messages to be moved
0074      */
0075     [[nodiscard]] ImapSet sequenceSet() const;
0076 
0077     /**
0078      * Set how the sequence set should be interpreted.
0079      *
0080      * @param uidBased  if @c true the argument to setSequenceSet will be
0081      *                  interpreted as UIDs, if @c false it will be interpreted
0082      *                  as sequence numbers
0083      */
0084     void setUidBased(bool uidBased);
0085     /**
0086      * How to interpret the sequence set.
0087      *
0088      * @return  if @c true the result of sequenceSet() should be
0089      *          interpreted as UIDs, if @c false it should be interpreted
0090      *          as sequence numbers
0091      */
0092     [[nodiscard]] bool isUidBased() const;
0093 
0094     /**
0095      * The UIDs of the moved messages in the destination mailbox.
0096      *
0097      * This will be an empty set if no messages have been moved yet
0098      * or if the server does not support the UIDPLUS extension.
0099      */
0100     [[nodiscard]] ImapSet resultingUids() const;
0101 
0102 protected:
0103     void doStart() override;
0104     void handleResponse(const Response &response) override;
0105 };
0106 
0107 }