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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@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 Session;
0017 struct Message;
0018 class CopyJobPrivate;
0019 
0020 /**
0021  * Copies one or more messages to another mailbox.
0022  *
0023  * This job can only be run when the session is in the selected state.
0024  *
0025  * If the server supports ACLs, the user will need the
0026  * Acl::Insert right on the target mailbox.
0027  * In order to preserve message flags, the user may also need
0028  * some combination of Acl::DeleteMessage,
0029  * Acl::KeepSeen and Acl::Write on the
0030  * target mailbox.
0031  */
0032 class KIMAP_EXPORT CopyJob : public Job
0033 {
0034     Q_OBJECT
0035     Q_DECLARE_PRIVATE(CopyJob)
0036 
0037     friend class SessionPrivate;
0038 
0039 public:
0040     explicit CopyJob(Session *session);
0041     ~CopyJob() override;
0042 
0043     /**
0044      * Sets the destination mailbox.
0045      *
0046      * If the mailbox does not exist, the server should not create
0047      * it automatically and the job should fail.  Note, however,
0048      * that a conforming server may create the mailbox automatically.
0049      *
0050      * @param mailBox  the (unquoted) name of the mailbox where the
0051      *                 messages should be copied to
0052      */
0053     void setMailBox(const QString &mailBox);
0054     /**
0055      * The destination mailbox
0056      */
0057     [[nodiscard]] QString mailBox() const;
0058 
0059     /**
0060      * Sets the messages to be copied
0061      *
0062      * If sequence numbers are given, isUidBased() should be false.  If UIDs
0063      * are given, isUidBased() should be true.
0064      *
0065      * RFC 3501 is unclear as to what should happen if invalid sequence numbers
0066      * are passed.  If non-existent UIDs are passed, they will be ignored.
0067      *
0068      * @param set  the sequence numbers or UIDs of the messages to be copied
0069      */
0070     void setSequenceSet(const ImapSet &set);
0071     /**
0072      * The messages that will be copied.
0073      *
0074      * isUidBased() can be used to check whether the ImapSet contains
0075      * sequence numbers or UIDs.
0076      *
0077      * @return  the sequence numbers or UIDs of the messages to be copied
0078      */
0079     [[nodiscard]] ImapSet sequenceSet() const;
0080 
0081     /**
0082      * Set how the sequence set should be interpreted.
0083      *
0084      * @param uidBased  if @c true the argument to setSequenceSet will be
0085      *                  interpreted as UIDs, if @c false it will be interpreted
0086      *                  as sequence numbers
0087      */
0088     void setUidBased(bool uidBased);
0089     /**
0090      * How to interpret the sequence set.
0091      *
0092      * @return  if @c true the result of sequenceSet() should be
0093      *          interpreted as UIDs, if @c false it should be interpreted
0094      *          as sequence numbers
0095      */
0096     [[nodiscard]] bool isUidBased() const;
0097 
0098     /**
0099      * The UIDs of the new copies of the messages
0100      *
0101      * This will be an empty set if no messages have been copied yet
0102      * or if the server does not support the UIDPLUS extension.
0103      */
0104     [[nodiscard]] ImapSet resultingUids() const;
0105 
0106 protected:
0107     void doStart() override;
0108     void handleResponse(const Response &response) override;
0109 };
0110 
0111 }