2 /* -*- mode: C++; c-file-style: "gnu" -*-
3 Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
4 Copyright (c) 2009 Andras Mantia <andras@kdab.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef KMAIL_MESSAGE_HELPER_H
22 #define KMAIL_MESSAGE_HELPER_H
24 #include <messagecore/messagestatus.h>
25 #include "messagecomposer_export.h"
27 #include <kmime/kmime_headers.h>
28 #include <kmime/kmime_message.h>
29 #include <akonadi/item.h>
31 #include <Nepomuk/Tag>
33 namespace KPIMIdentities
{
34 class IdentityManager
;
42 * Contains random helper methods when dealing with messages.
43 * TODO: cleanup and organize, along with similar methods in messageviewer.
45 namespace MessageHelper
{
47 /** Initialize header fields. Should be called on new messages
48 if they are not set manually. E.g. before composing. Calling
49 of setAutomaticFields(), see below, is still required. */
50 void MESSAGECOMPOSER_EXPORT
initHeader( const KMime::Message::Ptr
&message
, const KPIMIdentities::IdentityManager
* identMan
, uint id
= 0 );
52 /** Set the from, to, cc, bcc, encrytion etc headers as specified in the
54 void MESSAGECOMPOSER_EXPORT
applyIdentity( const KMime::Message::Ptr
&message
, const KPIMIdentities::IdentityManager
* identMan
, uint id
);
56 /** Initialize headers fields according to the identity and the transport
57 header of the given original message */
58 void MESSAGECOMPOSER_EXPORT
initFromMessage(const KMime::Message::Ptr
&msg
, const KMime::Message::Ptr
&orgiMsg
, KPIMIdentities::IdentityManager
*, bool idHeaders
= true);
60 KMime::Types::AddrSpecList MESSAGECOMPOSER_EXPORT
extractAddrSpecs( const KMime::Message::Ptr
&msg
, const QByteArray
&header
);
62 /** Check for prefixes @p prefixRegExps in #subject(). If none
63 is found, @p newPrefix + ' ' is prepended to the subject and the
64 resulting string is returned. If @p replace is true, any
65 sequence of whitespace-delimited prefixes at the beginning of
66 #subject() is replaced by @p newPrefix
68 QString MESSAGECOMPOSER_EXPORT
cleanSubject( const KMime::Message::Ptr
&msg
, const QStringList
&prefixRegExps
, bool replace
,
69 const QString
&newPrefix
);
71 /** Return this mails subject, with all "forward" and "reply"
73 QString MESSAGECOMPOSER_EXPORT
cleanSubject( const KMime::Message::Ptr
&msg
);
75 /** Return this mails subject, formatted for "forward" mails */
76 QString MESSAGECOMPOSER_EXPORT
forwardSubject( const KMime::Message::Ptr
&msg
);
78 /** Return this mails subject, formatted for "reply" mails */
79 QString MESSAGECOMPOSER_EXPORT
replySubject( const KMime::Message::Ptr
&msg
);
80 /** Check for prefixes @p prefixRegExps in @p str. If none
81 is found, @p newPrefix + ' ' is prepended to @p str and the
82 resulting string is returned. If @p replace is true, any
83 sequence of whitespace-delimited prefixes at the beginning of
84 @p str is replaced by @p newPrefix.
86 QString MESSAGECOMPOSER_EXPORT
replacePrefixes( const QString
& str
,
87 const QStringList
& prefixRegExps
,
89 const QString
& newPrefix
);
91 /** Set fields that are either automatically set (Message-id)
92 or that do not change from one message to another (MIME-Version).
93 Call this method before sending *after* all changes to the message
94 are done because this method does things different if there are
95 attachments / multiple body parts. */
96 void MESSAGECOMPOSER_EXPORT
setAutomaticFields( const KMime::Message::Ptr
&msg
, bool isMultipart
=false );
98 /** Creates reference string for reply to messages.
99 * reference = original first reference + original last reference + original msg-id
101 QByteArray MESSAGECOMPOSER_EXPORT
getRefStr( const KMime::Message::Ptr
&msg
);
103 QString MESSAGECOMPOSER_EXPORT
msgId( const KMime::Message::Ptr
&msg
);
106 QString MESSAGECOMPOSER_EXPORT
ccStrip( const KMime::Message::Ptr
&msg
);
107 QString MESSAGECOMPOSER_EXPORT
toStrip( const KMime::Message::Ptr
&msg
);
108 QString MESSAGECOMPOSER_EXPORT
fromStrip( const KMime::Message::Ptr
&msg
);
110 /** Returns @p str with all "forward" and "reply" prefixes stripped off.
112 QString MESSAGECOMPOSER_EXPORT
stripOffPrefixes( const QString
& str
);
115 * Skip leading keyword if keyword has given character at it's end
116 * (e.g. ':' or ',') and skip the then following blanks (if any) too.
117 * If keywordFound is specified it will be true if a keyword was skipped
118 * and false otherwise. */
119 QString MESSAGECOMPOSER_EXPORT
skipKeyword( const QString
& str
, QChar sepChar
= QLatin1Char( ':' ),
120 bool *keywordFound
= 0 );
122 QList
<Nepomuk::Tag
> tagList(const Akonadi::Item
&msg
);
123 void setTagList( const Akonadi::Item
&msg
, const QList
<Nepomuk::Tag
> &tags
);
125 void link( const KMime::Message::Ptr
&msg
, const Akonadi::Item
& item
,const KPIM::MessageStatus
& aStatus
);