aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/abstract/MCAbstractMessagePart.cc
blob: 6939d060662629f752f40c66859d8b5f581a830b (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
#include "MCAbstractMessagePart.h"

#include "MCMessageHeader.h"

using namespace mailcore;

void AbstractMessagePart::init()
{
    mMainPart = NULL;
    mHeader = NULL;
}

AbstractMessagePart::AbstractMessagePart()
{
}

AbstractMessagePart::AbstractMessagePart(AbstractMessagePart * other)
{
    if (other->mainPart() != NULL) {
        setMainPart((AbstractPart *) other->mainPart()->copy()->autorelease());
    }
    if (other->mHeader != NULL) {
        setHeader((MessageHeader *) other->header()->copy()->autorelease());
    }
}

AbstractMessagePart::~AbstractMessagePart()
{
    MC_SAFE_RELEASE(mMainPart);
    MC_SAFE_RELEASE(mHeader);
}

String * AbstractMessagePart::description()
{
    String * result = String::string();
    result->appendUTF8Format("<%s:%p %s>", className(), this, mMainPart->description());
    return result;
}

#if 0
String * AbstractMessagePart::className()
{
    return MCSTR("AbstractMessagePart");
}
#endif

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

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

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

AbstractPart * AbstractMessagePart::mainPart()
{
    return mMainPart;
}

void AbstractMessagePart::setMainPart(AbstractPart * mainPart)
{
    MC_SAFE_REPLACE_RETAIN(AbstractPart, mMainPart, mainPart);
    applyMessage();
}

void AbstractMessagePart::applyMessage()
{
    if (mMainPart == NULL)
        return;
    
    mMainPart->setMessage(message());
}

void AbstractMessagePart::setMessage(AbstractMessage * message)
{
    AbstractPart::setMessage(message);
    applyMessage();
}