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

0001 /*
0002   SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
0003   SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net>
0004 
0005   SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "messagecomposer_export.h"
0011 
0012 #include <Akonadi/Item>
0013 #include <KMime/Headers>
0014 #include <KMime/KMimeMessage>
0015 
0016 namespace KIdentityManagementCore
0017 {
0018 class IdentityManager;
0019 }
0020 
0021 namespace KMime
0022 {
0023 class Message;
0024 }
0025 
0026 /**
0027  * Contains random helper methods when dealing with messages.
0028  * TODO: cleanup and organize, along with similar methods in messageviewer.
0029  */
0030 namespace MessageHelper
0031 {
0032 /** Initialize header fields. Should be called on new messages
0033     if they are not set manually. E.g. before composing. Calling
0034     of setAutomaticFields(), see below, is still required. */
0035 void MESSAGECOMPOSER_EXPORT initHeader(const KMime::Message::Ptr &message, const KIdentityManagementCore::IdentityManager *identMan, uint id = 0);
0036 
0037 /** Set the from, to, cc, bcc, encryption etc headers as specified in the
0038  * given identity. */
0039 void applyIdentity(const KMime::Message::Ptr &message, const KIdentityManagementCore::IdentityManager *identMan, uint id);
0040 
0041 /** Initialize headers fields according to the identity and the transport
0042    header of the given original message */
0043 void initFromMessage(const KMime::Message::Ptr &msg,
0044                      const KMime::Message::Ptr &orgiMsg,
0045                      KIdentityManagementCore::IdentityManager *,
0046                      uint id,
0047                      bool idHeaders = true);
0048 
0049 MESSAGECOMPOSER_EXPORT KMime::Types::AddrSpecList extractAddrSpecs(const KMime::Message::Ptr &msg, const QByteArray &header);
0050 
0051 /** Set fields that are either automatically set (Message-id)
0052     or that do not change from one message to another (MIME-Version).
0053     Call this method before sending *after* all changes to the message
0054     are done because this method does things different if there are
0055     attachments / multiple body parts. */
0056 void setAutomaticFields(const KMime::Message::Ptr &msg, bool isMultipart = false);
0057 }