File indexing completed on 2024-06-23 05:18:37

0001 /*
0002     messagesender.h
0003 
0004     This file is part of KMail, the KDE mail client
0005     SPDX-FileCopyrightText: 2005 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <KMime/KMimeMessage>
0013 namespace MessageComposer
0014 {
0015 class MessageSender
0016 {
0017 protected:
0018     virtual ~MessageSender() = 0;
0019 
0020 public:
0021     enum SendMethod {
0022         SendDefault = -1,
0023         SendImmediate = true,
0024         SendLater = false,
0025     };
0026     enum SaveIn {
0027         SaveInNone,
0028         SaveInDrafts,
0029         SaveInTemplates,
0030         SaveInOutbox,
0031     };
0032     /**
0033        Send given message.
0034 
0035        The message is either queued (@p method == SendLater) or sent
0036        immediately (@p method = SendImmediate). The default behaviour,
0037        as selected with setSendImmediate(), can be overwritten with the
0038        parameter @p method.  The sender takes ownership of the given
0039        message on success, so DO NOT DELETE OR MODIFY the message
0040        further.
0041 
0042        @return true on success.
0043     */
0044     [[nodiscard]] bool send(const KMime::Message::Ptr &msg, SendMethod method = SendDefault)
0045     {
0046         return doSend(msg, method);
0047     }
0048 
0049     /**
0050        Start sending all queued messages.
0051 
0052        FIXME: what does success mean here, if it's only _start_ sending?
0053 
0054        Optionally a transport can be specified that will be used as the
0055        default transport.
0056 
0057        @return true on success.
0058     */
0059     [[nodiscard]] bool sendQueued(int transportId = -1)
0060     {
0061         return doSendQueued(transportId);
0062     }
0063 
0064 protected:
0065     [[nodiscard]] virtual bool doSend(const KMime::Message::Ptr &msg, short sendNow) = 0;
0066     [[nodiscard]] virtual bool doSendQueued(int transportId) = 0;
0067 };
0068 
0069 inline MessageSender::~MessageSender() = default;
0070 }