summaryrefslogtreecommitdiff
path: root/kolabformat/kolabobject.h
blob: 9bb376207f4278530fc152e607d6795064fcff49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (C) 2012  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef KOLABOBJECT_H
#define KOLABOBJECT_H

#include <kolab_export.h>

#include <libkolab_config.h>

#ifdef HAVE_TAG_H
#include <akonadi/item.h>
#include <akonadi/tag.h>
#include <akonadi/relation.h>
#endif
#include <kabc/addressee.h>
#include <kabc/contactgroup.h>
#include <kcalcore/incidence.h>
#include <kcalcore/event.h>
#include <kcalcore/journal.h>
#include <kcalcore/todo.h>
#include <kmime/kmime_message.h>

#include "kolabdefinitions.h"

namespace Kolab {

class Freebusy;


KOLAB_EXPORT KCalCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStringList &attachments);

struct KOLAB_EXPORT RelationMember {
    QString messageId;
    QString subject;
    QString date;
    QList<QByteArray> mailbox;
    QString user;
    qint64 uid;
    QString gid;
};
KOLAB_EXPORT RelationMember parseMemberUrl(const QString &url);
KOLAB_EXPORT QString generateMemberUrl(const RelationMember &url);

/**
 * Class to read Kolab Mime files
 * 
 * It implements the Kolab specifics of Mime message handling.
 * This class is not reusable and only meant to read a single object.
 * Parse the mime message and then call the correct getter, based on the type
 * 
 */
class KOLAB_EXPORT KolabObjectReader {
public:
    KolabObjectReader();
    explicit KolabObjectReader(const KMime::Message::Ptr &msg);
    ~KolabObjectReader();
    
    ObjectType parseMimeMessage(const KMime::Message::Ptr &msg);

    /**
     * Set to override the autodetected object type, before parsing the message.
     */
    void setObjectType(ObjectType);
    
    /**
     * Set to override the autodetected version, before parsing the message.
     */
    void setVersion(Version);
    
    /**
     * Returns the Object type of the parsed kolab object.
     */
    ObjectType getType() const;
    /**
     * Returns the kolab-format version of the parsed kolab object.
     */
    Version getVersion() const;
    
    /**
     * Getter to get the retrieved object.
     * Only the correct one will return a valid object.
     * 
     * Use getType() to determine the correct one to call.
     */
    KCalCore::Event::Ptr getEvent() const;
    KCalCore::Todo::Ptr getTodo() const;
    KCalCore::Journal::Ptr getJournal() const;
    KCalCore::Incidence::Ptr getIncidence() const;
    KABC::Addressee getContact() const;
    KABC::ContactGroup getDistlist() const;
    KMime::Message::Ptr getNote() const;
    QStringList getDictionary(QString &lang) const;
    Freebusy getFreebusy() const;
#ifdef HAVE_TAG_H
    bool isTag() const;
    Akonadi::Tag getTag() const;
    bool isRelation() const;
    Akonadi::Relation getRelation() const;
    QStringList getTagMembers() const;
#endif

private:
    //@cond PRIVATE
    class Private;
    Private *const d;
    //@endcond
};

/**
 * Class to write Kolab Mime files
 * 
 */
class KOLAB_EXPORT KolabObjectWriter {
public:

    static KMime::Message::Ptr writeEvent(const KCalCore::Event::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString());
    static KMime::Message::Ptr writeTodo(const KCalCore::Todo::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString());
    static KMime::Message::Ptr writeJournal(const KCalCore::Journal::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString());
    static KMime::Message::Ptr writeIncidence(const KCalCore::Incidence::Ptr &, Version v = KolabV3, const QString &productId = QString(),const QString &tz = QString());
    static KMime::Message::Ptr writeContact(const KABC::Addressee &, Version v = KolabV3, const QString &productId = QString());
    static KMime::Message::Ptr writeDistlist(const KABC::ContactGroup &, Version v = KolabV3, const QString &productId = QString());
    static KMime::Message::Ptr writeNote(const KMime::Message::Ptr &, Version v = KolabV3, const QString &productId = QString());
    static KMime::Message::Ptr writeDictionary(const QStringList &, const QString &lang, Version v = KolabV3, const QString &productId = QString());
    static KMime::Message::Ptr writeFreebusy(const Kolab::Freebusy &, Version v = KolabV3, const QString &productId = QString());
#ifdef HAVE_TAG_H
    static KMime::Message::Ptr writeRelation(const Akonadi::Relation &, Version v = KolabV3, const QString &productId = QString());
    static KMime::Message::Ptr writeTag(const Akonadi::Tag &, const QStringList &items, Version v = KolabV3, const QString &productId = QString());
#endif
    
};

} //Namespace

#endif // KOLABOBJECT_H