File indexing completed on 2024-05-19 05:17:43

0001 /*
0002     Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or modify it
0005     under the terms of the GNU Library General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or (at your
0007     option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful, but WITHOUT
0010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0012     License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to the
0016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017     02110-1301, USA.
0018 */
0019 
0020 #ifndef KIMAP2_MOVE_H_
0021 #define KIMAP2_MOVE_H_
0022 
0023 #include "kimap2_export.h"
0024 
0025 #include "job.h"
0026 #include "imapset.h"
0027 
0028 namespace KIMAP2 {
0029 
0030 class MoveJobPrivate;
0031 
0032 /**
0033  * Moves messages from current mailbox to another
0034  *
0035  * Note that move functionality is not specified in the base IMAP
0036  * protocol and is defined as an extension in RFC6851. That means
0037  * that the MoveJob can only be used when the server lists "MOVE"
0038  * in response to CAPABILITY command.
0039  *
0040  * Unlike the traditional emulation of moving messages, i.e. COPY + STORE + EXPUNGE,
0041  * MOVE guarantees the transaction to be atomic on the server.
0042  *
0043  * @since 5.4
0044  */
0045 class KIMAP2_EXPORT MoveJob : public Job
0046 {
0047     Q_OBJECT
0048     Q_DECLARE_PRIVATE(MoveJob)
0049 
0050     friend class SessionPrivate;
0051 
0052 public:
0053     explicit MoveJob(Session *session);
0054     virtual ~MoveJob();
0055 
0056     /**
0057      * Set the destination mailbox
0058      *
0059      * If the mailbox does not exist, the server should not create
0060      * it automatically and the job should fail.  Note, however,
0061      * that a conforming server may create the mailbox automatically.
0062      *
0063      * @param mailBox  the (unquoted) name of the mailbox where the
0064      *                 messages should be moved to
0065      */
0066     void setMailBox(const QString &mailbox);
0067     /**
0068      * The destination mailbox
0069      */
0070     QString mailBox() const;
0071 
0072     /**
0073      * Sets the messages to be moved,
0074      *
0075      * If sequence numbers are given, isUidBased() should be false.  If UIDs
0076      * are given, isUidBased() should be true.
0077      *
0078      * @param set  the sequence numbers or UIDs of the messages to be moved
0079      */
0080     void setSequenceSet(const ImapSet &set);
0081     /**
0082      * The messages that will be moved.
0083      *
0084      * isUidBased() can be used to check whether the ImapSet contains
0085      * sequence numbers or UIDs.
0086      *
0087      * @return  the sequence numbers or UIDs of the messages to be moved
0088      */
0089     ImapSet sequenceSet() const;
0090 
0091     /**
0092      * Set how the sequence set should be interpreted.
0093      *
0094      * @param uidBased  if @c true the argument to setSequenceSet will be
0095      *                  interpreted as UIDs, if @c false it will be interpreted
0096      *                  as sequence numbers
0097      */
0098     void setUidBased(bool uidBased);
0099     /**
0100      * How to interpret the sequence set.
0101      *
0102      * @return  if @c true the result of sequenceSet() should be
0103      *          interpreted as UIDs, if @c false it should be interpreted
0104      *          as sequence numbers
0105      */
0106     bool isUidBased() const;
0107 
0108     /**
0109      * The UIDs of the moved messages in the destination mailbox.
0110      *
0111      * This will be an empty set if no messages have been moved yet
0112      * or if the server does not support the UIDPLUS extension.
0113      */
0114     ImapSet resultingUids() const;
0115 
0116 protected:
0117     void doStart() Q_DECL_OVERRIDE;
0118     void handleResponse(const KIMAP2::Message &response) Q_DECL_OVERRIDE;
0119 };
0120 
0121 }
0122 #endif