aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--example/mac/macExample/macExample/MCTMsgViewController.m1
-rw-r--r--src/core/abstract/MCAbstractMessage.cc12
-rw-r--r--src/core/abstract/MCAbstractMessage.h3
-rw-r--r--src/core/renderer/MCHTMLRenderer.cc80
-rw-r--r--src/core/renderer/MCHTMLRenderer.h3
-rw-r--r--src/core/rfc822/MCMessageBuilder.h2
-rw-r--r--src/objc/abstract/MCOAbstractMessage.h3
-rw-r--r--src/objc/abstract/MCOAbstractMessage.mm10
8 files changed, 98 insertions, 16 deletions
diff --git a/example/mac/macExample/macExample/MCTMsgViewController.m b/example/mac/macExample/macExample/MCTMsgViewController.m
index 6af399b5..adfa009c 100644
--- a/example/mac/macExample/macExample/MCTMsgViewController.m
+++ b/example/mac/macExample/macExample/MCTMsgViewController.m
@@ -30,6 +30,7 @@
- (void) setMessage:(MCOIMAPMessage *)message
{
NSLog(@"set message : %@", message);
+ NSLog(@"set attachments: %@ %@", [message attachments], [message htmlInlineAttachments]);
for(MCOOperation * op in _ops) {
[op cancel];
}
diff --git a/src/core/abstract/MCAbstractMessage.cc b/src/core/abstract/MCAbstractMessage.cc
index b7d9b9af..a7e73992 100644
--- a/src/core/abstract/MCAbstractMessage.cc
+++ b/src/core/abstract/MCAbstractMessage.cc
@@ -1,6 +1,7 @@
#include "MCAbstractMessage.h"
#include "MCMessageHeader.h"
+#include "MCHTMLRenderer.h"
using namespace mailcore;
@@ -68,3 +69,14 @@ AbstractPart * AbstractMessage::partForUniqueID(String * uniqueID)
MCAssert(0);
return NULL;
}
+
+Array * AbstractMessage::attachments()
+{
+ return HTMLRenderer::attachmentsForMessage(this);
+}
+
+Array * AbstractMessage::htmlInlineAttachments()
+{
+ return HTMLRenderer::htmlInlineAttachmentsForMessage(this);
+}
+
diff --git a/src/core/abstract/MCAbstractMessage.h b/src/core/abstract/MCAbstractMessage.h
index 657ddaa5..49c4805b 100644
--- a/src/core/abstract/MCAbstractMessage.h
+++ b/src/core/abstract/MCAbstractMessage.h
@@ -21,6 +21,9 @@ namespace mailcore {
virtual AbstractPart * partForContentID(String * contentID);
virtual AbstractPart * partForUniqueID(String * uniqueID);
+ virtual Array * attachments();
+ virtual Array * htmlInlineAttachments();
+
public: //subclass behavior
AbstractMessage(AbstractMessage * other);
virtual String * description();
diff --git a/src/core/renderer/MCHTMLRenderer.cc b/src/core/renderer/MCHTMLRenderer.cc
index a4cd13d4..b0fd24ef 100644
--- a/src/core/renderer/MCHTMLRenderer.cc
+++ b/src/core/renderer/MCHTMLRenderer.cc
@@ -16,6 +16,11 @@
using namespace mailcore;
+class HTMLRendererIMAPDummyCallback : public HTMLRendererIMAPCallback {
+public:
+ virtual Data * dataForIMAPPart(String * folder, IMAPPart * part) { return Data::data(); }
+};
+
enum {
RENDER_STATE_NONE,
RENDER_STATE_HAD_ATTACHMENT,
@@ -34,6 +39,8 @@ struct htmlRendererContext {
bool hasMixedTextAndAttachments;
bool firstAttachment;
bool hasTextPart;
+ Array * relatedAttachments;
+ Array * attachments;
};
class DefaultTemplateCallback : public Object, public HTMLRendererTemplateCallback {
@@ -50,7 +57,9 @@ static String * renderTemplate(String * templateContent, HashMap * values);
static String * htmlForAbstractMessage(String * folder, AbstractMessage * message,
HTMLRendererIMAPCallback * dataCallback,
- HTMLRendererTemplateCallback * htmlCallback);
+ HTMLRendererTemplateCallback * htmlCallback,
+ Array * attachments,
+ Array * relatedAttachments);
static bool isTextPart(AbstractPart * part, htmlRendererContext * context)
{
@@ -142,7 +151,9 @@ static bool messagePartContainsMimeType(AbstractMessagePart * part, String * mim
static String * htmlForAbstractMessage(String * folder, AbstractMessage * message,
HTMLRendererIMAPCallback * dataCallback,
- HTMLRendererTemplateCallback * htmlCallback)
+ HTMLRendererTemplateCallback * htmlCallback,
+ Array * attachments,
+ Array * relatedAttachments)
{
AbstractPart * mainPart = NULL;
@@ -162,6 +173,8 @@ static String * htmlForAbstractMessage(String * folder, AbstractMessage * messag
htmlRendererContext context;
context.dataCallback = dataCallback;
context.htmlCallback = htmlCallback;
+ context.relatedAttachments = relatedAttachments;
+ context.attachments = attachments;
context.firstRendered = 0;
context.folder = folder;
context.state = RENDER_STATE_NONE;
@@ -172,6 +185,8 @@ static String * htmlForAbstractMessage(String * folder, AbstractMessage * messag
context.hasTextPart = false;
htmlForAbstractPart(mainPart, &context);
+ context.relatedAttachments = NULL;
+ context.attachments = NULL;
context.hasMixedTextAndAttachments = (context.state == RENDER_STATE_HAD_ATTACHMENT_THEN_TEXT);
context.pass = 1;
context.firstAttachment = false;
@@ -194,13 +209,13 @@ static String * htmlForAbstractMessage(String * folder, AbstractMessage * messag
return result;
}
-String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererContext * context);
-String * htmlForAbstractMessagePart(AbstractMessagePart * part, htmlRendererContext * context);
-String * htmlForAbstractMultipartRelated(AbstractMultipart * part, htmlRendererContext * context);
-String * htmlForAbstractMultipartMixed(AbstractMultipart * part, htmlRendererContext * context);
-String * htmlForAbstractMultipartAlternative(AbstractMultipart * part, htmlRendererContext * context);
+static String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererContext * context);
+static String * htmlForAbstractMessagePart(AbstractMessagePart * part, htmlRendererContext * context);
+static String * htmlForAbstractMultipartRelated(AbstractMultipart * part, htmlRendererContext * context);
+static String * htmlForAbstractMultipartMixed(AbstractMultipart * part, htmlRendererContext * context);
+static String * htmlForAbstractMultipartAlternative(AbstractMultipart * part, htmlRendererContext * context);
-String * htmlForAbstractPart(AbstractPart * part, htmlRendererContext * context)
+static String * htmlForAbstractPart(AbstractPart * part, htmlRendererContext * context)
{
switch (part->partType()) {
case PartTypeSingle:
@@ -219,7 +234,7 @@ String * htmlForAbstractPart(AbstractPart * part, htmlRendererContext * context)
return NULL;
}
-String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererContext * context)
+static String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererContext * context)
{
String * mimeType = NULL;
if (part->mimeType() != NULL) {
@@ -324,11 +339,15 @@ String * htmlForAbstractSinglePart(AbstractPart * part, htmlRendererContext * co
result->appendString(separatorString);
result->appendString(content);
+ if (context->attachments != NULL) {
+ context->attachments->addObject(part);
+ }
+
return result;
}
}
-String * htmlForAbstractMessagePart(AbstractMessagePart * part, htmlRendererContext * context)
+static String * htmlForAbstractMessagePart(AbstractMessagePart * part, htmlRendererContext * context)
{
if (context->pass == 0) {
return NULL;
@@ -357,7 +376,7 @@ String * htmlForAbstractMultipartAlternative(AbstractMultipart * part, htmlRende
return htmlForAbstractPart(preferredAlternative, context);
}
-String * htmlForAbstractMultipartMixed(AbstractMultipart * part, htmlRendererContext * context)
+static String * htmlForAbstractMultipartMixed(AbstractMultipart * part, htmlRendererContext * context)
{
String * result = String::string();
for(unsigned int i = 0 ; i < part->parts()->count() ; i ++) {
@@ -373,7 +392,7 @@ String * htmlForAbstractMultipartMixed(AbstractMultipart * part, htmlRendererCon
return result;
}
-String * htmlForAbstractMultipartRelated(AbstractMultipart * part, htmlRendererContext * context)
+static String * htmlForAbstractMultipartRelated(AbstractMultipart * part, htmlRendererContext * context)
{
if (part->parts()->count() == 0) {
if (context->pass == 0) {
@@ -384,11 +403,18 @@ String * htmlForAbstractMultipartRelated(AbstractMultipart * part, htmlRendererC
}
}
+ // root of the multipart/related.
AbstractPart * subpart = (AbstractPart *) part->parts()->objectAtIndex(0);
+ if (context->relatedAttachments != NULL) {
+ for(unsigned int i = 1 ; i < part->parts()->count() ; i ++) {
+ AbstractPart * otherSubpart = (AbstractPart *) part->parts()->objectAtIndex(i);
+ context->relatedAttachments->addObject(otherSubpart);
+ }
+ }
return htmlForAbstractPart(subpart, context);
}
-void fillTemplateDictionaryFromMCHashMap(ctemplate::TemplateDictionary * dict, HashMap * mcHashMap)
+static void fillTemplateDictionaryFromMCHashMap(ctemplate::TemplateDictionary * dict, HashMap * mcHashMap)
{
Array * keys = mcHashMap->allKeys();
@@ -424,7 +450,7 @@ void fillTemplateDictionaryFromMCHashMap(ctemplate::TemplateDictionary * dict, H
}
}
-String * renderTemplate(String * templateContent, HashMap * values)
+static String * renderTemplate(String * templateContent, HashMap * values)
{
ctemplate::TemplateDictionary dict("template dict");
std::string output;
@@ -445,7 +471,7 @@ String * renderTemplate(String * templateContent, HashMap * values)
String * HTMLRenderer::htmlForRFC822Message(MessageParser * message,
HTMLRendererTemplateCallback * htmlCallback)
{
- return htmlForAbstractMessage(NULL, message, NULL, htmlCallback);
+ return htmlForAbstractMessage(NULL, message, NULL, htmlCallback, NULL, NULL);
}
String * HTMLRenderer::htmlForIMAPMessage(String * folder,
@@ -453,5 +479,27 @@ String * HTMLRenderer::htmlForIMAPMessage(String * folder,
HTMLRendererIMAPCallback * dataCallback,
HTMLRendererTemplateCallback * htmlCallback)
{
- return htmlForAbstractMessage(folder, message, dataCallback, htmlCallback);
+ return htmlForAbstractMessage(folder, message, dataCallback, htmlCallback, NULL, NULL);
+}
+
+Array * HTMLRenderer::attachmentsForMessage(AbstractMessage * message)
+{
+ Array * attachments = Array::array();
+ HTMLRendererIMAPCallback * dataCallback = new HTMLRendererIMAPDummyCallback();
+ String * ignoredResult = htmlForAbstractMessage(NULL, message, dataCallback, NULL, attachments, NULL);
+ delete dataCallback;
+ dataCallback = NULL;
+ (void) ignoredResult; // remove unused variable warning.
+ return attachments;
+}
+
+Array * HTMLRenderer::htmlInlineAttachmentsForMessage(AbstractMessage * message)
+{
+ Array * htmlInlineAttachments = Array::array();
+ HTMLRendererIMAPCallback * dataCallback = new HTMLRendererIMAPDummyCallback();
+ String * ignoredResult = htmlForAbstractMessage(NULL, message, dataCallback, NULL, NULL, htmlInlineAttachments);
+ delete dataCallback;
+ dataCallback = NULL;
+ (void) ignoredResult; // remove unused variable warning.
+ return htmlInlineAttachments;
}
diff --git a/src/core/renderer/MCHTMLRenderer.h b/src/core/renderer/MCHTMLRenderer.h
index 513da73d..2a36a9f6 100644
--- a/src/core/renderer/MCHTMLRenderer.h
+++ b/src/core/renderer/MCHTMLRenderer.h
@@ -30,6 +30,9 @@ namespace mailcore {
IMAPMessage * message,
HTMLRendererIMAPCallback * dataCallback,
HTMLRendererTemplateCallback * htmlCallback);
+
+ static Array * attachmentsForMessage(AbstractMessage * message);
+ static Array * htmlInlineAttachmentsForMessage(AbstractMessage * message);
};
};
diff --git a/src/core/rfc822/MCMessageBuilder.h b/src/core/rfc822/MCMessageBuilder.h
index 0da545d9..63f325d3 100644
--- a/src/core/rfc822/MCMessageBuilder.h
+++ b/src/core/rfc822/MCMessageBuilder.h
@@ -28,6 +28,8 @@ namespace mailcore {
virtual void addAttachment(Attachment * attachment);
// attachments (usually images) that are included in HTML.
+ // a Content-ID should be assigned to these part to be able to reference
+ // them in the HTML using a cid: URL.
virtual void setRelatedAttachments(Array * /* Attachment */ attachments);
virtual Array * /* Attachment */ relatedAttachments();
virtual void addRelatedAttachment(Attachment * attachment);
diff --git a/src/objc/abstract/MCOAbstractMessage.h b/src/objc/abstract/MCOAbstractMessage.h
index ea5df770..aa47d15a 100644
--- a/src/objc/abstract/MCOAbstractMessage.h
+++ b/src/objc/abstract/MCOAbstractMessage.h
@@ -26,6 +26,9 @@
// Returns the part with the given unique identifier.
- (MCOAbstractPart *) partForUniqueID:(NSString *)uniqueID;
+- (NSArray *) attachments;
+- (NSArray *) htmlInlineAttachments;
+
@end
#endif
diff --git a/src/objc/abstract/MCOAbstractMessage.mm b/src/objc/abstract/MCOAbstractMessage.mm
index 4a9e131b..6fedcc8a 100644
--- a/src/objc/abstract/MCOAbstractMessage.mm
+++ b/src/objc/abstract/MCOAbstractMessage.mm
@@ -61,4 +61,14 @@ MCO_OBJC_SYNTHESIZE(MessageHeader, setHeader, header)
return MCO_TO_OBJC(MCO_NATIVE_INSTANCE->partForUniqueID([uniqueID mco_mcString]));
}
+- (NSArray *) attachments
+{
+ return MCO_OBJC_BRIDGE_GET(attachments);
+}
+
+- (NSArray *) htmlInlineAttachments
+{
+ return MCO_OBJC_BRIDGE_GET(htmlInlineAttachments);
+}
+
@end