aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/abstract/MCAbstractMessage.cpp
blob: 1d1d7efc3ab0384b7747ad67a8ae75b4943c45eb (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
#include "MCAbstractMessage.h"

#include "MCMessageHeader.h"
#include "MCHTMLRenderer.h"

using namespace mailcore;

AbstractMessage::AbstractMessage()
{
    init();
}

AbstractMessage::AbstractMessage(AbstractMessage * other)
{
    init();
    mHeader = (MessageHeader *) MC_SAFE_COPY(other->mHeader);
}

void AbstractMessage::init()
{
    mHeader = NULL;
}

AbstractMessage::~AbstractMessage()
{
    MC_SAFE_RELEASE(mHeader);
}

String * AbstractMessage::description()
{
    if (mHeader != NULL) {
        String * result = String::string();
        result->appendUTF8Format("<%s:%p\n", className()->UTF8Characters(), this);
        result->appendString(mHeader->description());
        result->appendUTF8Characters(">");
        return result;
    }
    else {
        return Object::description();
    }
}

Object * AbstractMessage::copy()
{
    return new AbstractMessage(this);
}

MessageHeader * AbstractMessage::header()
{
    if (mHeader == NULL) {
        mHeader = new MessageHeader();
    }
    return mHeader;
}

void AbstractMessage::setHeader(MessageHeader * header)
{
    MC_SAFE_REPLACE_RETAIN(MessageHeader, mHeader, header);
}

AbstractPart * AbstractMessage::partForContentID(String * contentID)
{
    MCAssert(0);
    return NULL;
}

AbstractPart * AbstractMessage::partForUniqueID(String * uniqueID)
{
    MCAssert(0);
    return NULL;
}

Array * AbstractMessage::attachments()
{
    return HTMLRenderer::attachmentsForMessage(this);
}

Array * AbstractMessage::htmlInlineAttachments()
{
    return HTMLRenderer::htmlInlineAttachmentsForMessage(this);
}

Array * AbstractMessage::requiredPartsForRendering()
{
    return HTMLRenderer::requiredPartsForRendering(this);
}

HashMap * AbstractMessage::serializable()
{
    HashMap * result = Object::serializable();
    if (header() != NULL) {
        result->setObjectForKey(MCSTR("header"), mHeader->serializable());
    }
    return result;
}

void AbstractMessage::importSerializable(HashMap * hashmap)
{
    setHeader((MessageHeader *) Object::objectWithSerializable((HashMap *) hashmap->objectForKey(MCSTR("header"))));
}