aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/abstract/MCOAbstractMessageRendererCallback.mm
blob: 392f0747307a81f33b25b7886b0f54515bc723ee (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
//  MCOAbstractMessageRendererCallback.cpp
//  mailcore2
//
//  Created by DINH Viêt Hoà on 3/23/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#include "MCOAbstractMessageRendererCallback.h"

#import "MCOHTMLRendererDelegate.h"
#import "MCOHTMLRendererIMAPDelegate.h"
#import "MCOUtils.h"

using namespace mailcore;

MCOAbstractMessageRendererCallback::MCOAbstractMessageRendererCallback(MCOAbstractMessage * message, id <MCOHTMLRendererDelegate> rendererDelegate,
                                   id <MCOHTMLRendererIMAPDelegate> rendererIMAPDelegate)
{
    mMessage = message;
    mRendererDelegate = rendererDelegate;
    mIMAPDelegate = rendererIMAPDelegate;
}

bool MCOAbstractMessageRendererCallback::canPreviewPart(AbstractPart * part)
{
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:canPreviewPart:)]) {
        return [mRendererDelegate MCOAbstractMessage:mMessage canPreviewPart:MCO_TO_OBJC(part)];
    }
    return HTMLRendererTemplateCallback::canPreviewPart(part);
}

bool MCOAbstractMessageRendererCallback::shouldShowPart(AbstractPart * part)
{
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:shouldShowPart:)]) {
        return [mRendererDelegate MCOAbstractMessage:mMessage shouldShowPart:MCO_TO_OBJC(part)];
    }
    return HTMLRendererTemplateCallback::shouldShowPart(part);
}

HashMap * MCOAbstractMessageRendererCallback::templateValuesForHeader(MessageHeader * header)
{
    HashMap * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateValuesForHeader:)]) {
        result = MCO_FROM_OBJC(HashMap, [mRendererDelegate MCOAbstractMessage:mMessage templateValuesForHeader:MCO_TO_OBJC(header)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateValuesForHeader(header);
    }
    return result;
}

HashMap * MCOAbstractMessageRendererCallback::templateValuesForPart(AbstractPart * part)
{
    HashMap * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateValuesForPart:)]) {
        result = MCO_FROM_OBJC(HashMap, [mRendererDelegate MCOAbstractMessage:mMessage templateValuesForPart:MCO_TO_OBJC(part)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateValuesForPart(part);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForMainHeader(MessageHeader * header)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateForMainHeader:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage templateForMainHeader:MCO_TO_OBJC(header)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForMainHeader(header);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForImage(AbstractPart * part)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateForImage:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage templateForImage:MCO_TO_OBJC(part)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForImage(part);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForAttachment(AbstractPart * part)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateForAttachment:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage templateForAttachment:MCO_TO_OBJC(part)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForAttachment(part);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForMessage(AbstractMessage * message)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage_templateForMessage:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage_templateForMessage:mMessage]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForMessage(message);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForEmbeddedMessage(AbstractMessagePart * part)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateForEmbeddedMessage:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage templateForEmbeddedMessage:MCO_TO_OBJC(part)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForEmbeddedMessage(part);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForEmbeddedMessageHeader(MessageHeader * header)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:templateForEmbeddedMessageHeader:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage templateForEmbeddedMessageHeader:MCO_TO_OBJC(header)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForEmbeddedMessageHeader(header);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::templateForAttachmentSeparator()
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage_templateForAttachmentSeparator:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage_templateForAttachmentSeparator:mMessage]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::templateForAttachmentSeparator();
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::cleanHTMLForPart(String * html)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:cleanHTMLForPart:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage cleanHTMLForPart:MCO_TO_OBJC(html)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::cleanHTMLForPart(html);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::filterHTMLForPart(String * html)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:filterHTMLForPart:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage filterHTMLForPart:MCO_TO_OBJC(html)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::filterHTMLForPart(html);
    }
    return result;
}

String * MCOAbstractMessageRendererCallback::filterHTMLForMessage(String * html)
{
    String * result = NULL;
    if ([mRendererDelegate respondsToSelector:@selector(MCOAbstractMessage:filterHTMLForMessage:)]) {
        result = MCO_FROM_OBJC(String, [mRendererDelegate MCOAbstractMessage:mMessage filterHTMLForMessage:MCO_TO_OBJC(html)]);
    }
    if (result == NULL) {
        result = HTMLRendererTemplateCallback::filterHTMLForMessage(html);
    }
    return result;
}

Data * MCOAbstractMessageRendererCallback::dataForIMAPPart(String * folder, IMAPPart * part)
{
    Data * result = NULL;
    if ([mIMAPDelegate respondsToSelector:@selector(MCOAbstractMessage:dataForIMAPPart:folder:)]) {
        result = [[mIMAPDelegate MCOAbstractMessage:mMessage dataForIMAPPart:MCO_TO_OBJC(part) folder:MCO_TO_OBJC(folder)] mco_mcData];
    }
    return result;
}

void MCOAbstractMessageRendererCallback::prefetchAttachmentIMAPPart(String * folder, IMAPPart * part)
{
    if ([mIMAPDelegate respondsToSelector:@selector(MCOAbstractMessage:prefetchAttachmentIMAPPart:folder:)]) {
        [mIMAPDelegate MCOAbstractMessage:mMessage prefetchAttachmentIMAPPart:MCO_TO_OBJC(part) folder:MCO_TO_OBJC(folder)];
    }
}

void MCOAbstractMessageRendererCallback::prefetchImageIMAPPart(String * folder, IMAPPart * part)
{
    if ([mIMAPDelegate respondsToSelector:@selector(MCOAbstractMessage:prefetchImageIMAPPart:folder:)]) {
        [mIMAPDelegate MCOAbstractMessage:mMessage prefetchImageIMAPPart:MCO_TO_OBJC(part) folder:MCO_TO_OBJC(folder)];
    }
}