aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/async/imap/MCIMAPMessageRenderingOperation.cc
blob: 8240b4bbe0947e99b8f2ea528023a4c4ad3e45e4 (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
//
//  MCIMAPMessageRenderingOperation.cc
//  mailcore2
//
//  Created by Paul Young on 27/06/2013.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#include "MCIMAPMessageRenderingOperation.h"

#include "MCIMAPSession.h"
#include "MCIMAPAsyncConnection.h"

using namespace mailcore;

IMAPMessageRenderingOperation::IMAPMessageRenderingOperation()
{
    mMessage = NULL;
    mRenderingType = IMAPMessageRenderingTypePlainTextBody;
    mResult = NULL;
}

IMAPMessageRenderingOperation::~IMAPMessageRenderingOperation()
{
    MC_SAFE_RELEASE(mMessage);
    MC_SAFE_RELEASE(mResult);
}

void IMAPMessageRenderingOperation::setRenderingType(IMAPMessageRenderingType type)
{
    mRenderingType = type;
}

IMAPMessageRenderingType IMAPMessageRenderingOperation::renderingType()
{
    return mRenderingType;
}

void IMAPMessageRenderingOperation::setMessage(IMAPMessage * message)
{
    MC_SAFE_REPLACE_COPY(IMAPMessage, mMessage, message);
}

IMAPMessage * IMAPMessageRenderingOperation::message()
{
    return mMessage;
}

String * IMAPMessageRenderingOperation::result()
{
    return mResult;
}

void IMAPMessageRenderingOperation::main()
{
    ErrorCode error;
    
    if (mRenderingType == IMAPMessageRenderingTypeHTML) {
        mResult = session()->session()->htmlRendering(mMessage, folder(), &error);
    }
    else if (mRenderingType == IMAPMessageRenderingTypeHTMLBody) {
        mResult = session()->session()->htmlBodyRendering(mMessage, folder(), &error);
    }
    else if (mRenderingType == IMAPMessageRenderingTypePlainText) {
        mResult = session()->session()->plainTextRendering(mMessage, folder(), &error);
    }
    else if (mRenderingType == IMAPMessageRenderingTypePlainTextBody) {
        mResult = session()->session()->plainTextBodyRendering(mMessage, folder(), &error);
    }
    
    MC_SAFE_RETAIN(mResult);
    setError(error);
}