summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/mime/cthandlers/glue
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--comm/mailnews/mime/cthandlers/glue/mimexpcom.cpp119
-rw-r--r--comm/mailnews/mime/cthandlers/glue/mimexpcom.h92
-rw-r--r--comm/mailnews/mime/cthandlers/glue/moz.build17
-rw-r--r--comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp55
-rw-r--r--comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.h46
5 files changed, 329 insertions, 0 deletions
diff --git a/comm/mailnews/mime/cthandlers/glue/mimexpcom.cpp b/comm/mailnews/mime/cthandlers/glue/mimexpcom.cpp
new file mode 100644
index 0000000000..626dc043a4
--- /dev/null
+++ b/comm/mailnews/mime/cthandlers/glue/mimexpcom.cpp
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsIMimeObjectClassAccess.h"
+#include "nsCOMPtr.h"
+#include "nsComponentManagerUtils.h"
+
+// {403B0540-B7C3-11d2-B35E-525400E2D63A}
+#define NS_MIME_OBJECT_CLASS_ACCESS_CID \
+ { \
+ 0x403b0540, 0xb7c3, 0x11d2, { \
+ 0xb3, 0x5e, 0x52, 0x54, 0x0, 0xe2, 0xd6, 0x3a \
+ } \
+ }
+static NS_DEFINE_CID(kMimeObjectClassAccessCID,
+ NS_MIME_OBJECT_CLASS_ACCESS_CID);
+
+/*
+ * These calls are necessary to expose the object class hierarchy
+ * to externally developed content type handlers.
+ */
+extern "C" void* COM_GetmimeInlineTextClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) objAccess->GetmimeInlineTextClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" void* COM_GetmimeLeafClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) objAccess->GetmimeLeafClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" void* COM_GetmimeObjectClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) objAccess->GetmimeObjectClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" void* COM_GetmimeContainerClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) objAccess->GetmimeContainerClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" void* COM_GetmimeMultipartClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) objAccess->GetmimeMultipartClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" void* COM_GetmimeMultipartSignedClass(void) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess)
+ objAccess->GetmimeMultipartSignedClass(&ptr);
+
+ return ptr;
+}
+
+extern "C" int COM_MimeObject_write(void* mimeObject, char* data,
+ int32_t length, bool user_visible_p) {
+ int32_t rc = -1;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess) {
+ if (NS_SUCCEEDED(objAccess->MimeObjectWrite(mimeObject, data, length,
+ user_visible_p)))
+ rc = length;
+ else
+ rc = -1;
+ }
+
+ return rc;
+}
+
+extern "C" void* COM_MimeCreate(char* content_type, void* hdrs, void* opts) {
+ void* ptr = NULL;
+
+ nsresult res;
+ nsCOMPtr<nsIMimeObjectClassAccess> objAccess =
+ do_CreateInstance(kMimeObjectClassAccessCID, &res);
+ if (NS_SUCCEEDED(res) && objAccess)
+ objAccess->MimeCreate(content_type, hdrs, opts, &ptr);
+
+ return ptr;
+}
diff --git a/comm/mailnews/mime/cthandlers/glue/mimexpcom.h b/comm/mailnews/mime/cthandlers/glue/mimexpcom.h
new file mode 100644
index 0000000000..343c7d0dc7
--- /dev/null
+++ b/comm/mailnews/mime/cthandlers/glue/mimexpcom.h
@@ -0,0 +1,92 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This is the definitions for the Content Type Handler plugins to
+ * access internals of libmime via XP-COM calls
+ */
+#ifndef _MIMEXPCOM_H_
+#define _MIMEXPCOM_H_
+
+/*
+ This header exposes functions that are necessary to access the
+ object hierarchy for the mime chart. The class hierarchy is:
+
+ MimeObject (abstract)
+ |
+ |--- MimeContainer (abstract)
+ | |
+ | |--- MimeMultipart (abstract)
+ | | |
+ | | |--- MimeMultipartMixed
+ | | |
+ | | |--- MimeMultipartDigest
+ | | |
+ | | |--- MimeMultipartParallel
+ | | |
+ | | |--- MimeMultipartAlternative
+ | | |
+ | | |--- MimeMultipartRelated
+ | | |
+ | | |--- MimeMultipartAppleDouble
+ | | |
+ | | |--- MimeSunAttachment
+ | | |
+ | | |--- MimeMultipartSigned (abstract)
+ | | |
+ | | |--- MimeMultipartSigned
+ | |
+ | |--- MimeXlateed (abstract)
+ | | |
+ | | |--- MimeXlateed
+ | |
+ | |--- MimeMessage
+ | |
+ | |--- MimeUntypedText
+ |
+ |--- MimeLeaf (abstract)
+ | |
+ | |--- MimeInlineText (abstract)
+ | | |
+ | | |--- MimeInlineTextPlain
+ | | |
+ | | |--- MimeInlineTextHTML
+ | | |
+ | | |--- MimeInlineTextRichtext
+ | | | |
+ | | | |--- MimeInlineTextEnriched
+ | | |
+ | | |--- MimeInlineTextVCard
+ | |
+ | |--- MimeInlineImage
+ | |
+ | |--- MimeExternalObject
+ |
+ |--- MimeExternalBody
+ */
+
+/*
+ * These functions are exposed by libmime to be used by content type
+ * handler plugins for processing stream data.
+ */
+/*
+ * This is the write call for outputting processed stream data.
+ */
+extern "C" int COM_MimeObject_write(void* mimeObject, const char* data,
+ int32_t length, bool user_visible_p);
+/*
+ * The following group of calls expose the pointers for the object
+ * system within libmime.
+ */
+extern "C" void* COM_GetmimeInlineTextClass(void);
+extern "C" void* COM_GetmimeLeafClass(void);
+extern "C" void* COM_GetmimeObjectClass(void);
+extern "C" void* COM_GetmimeContainerClass(void);
+extern "C" void* COM_GetmimeMultipartClass(void);
+extern "C" void* COM_GetmimeMultipartSignedClass(void);
+
+extern "C" void* COM_MimeCreate(char* content_type, void* hdrs, void* opts);
+
+#endif /* _MIMEXPCOM_H_ */
diff --git a/comm/mailnews/mime/cthandlers/glue/moz.build b/comm/mailnews/mime/cthandlers/glue/moz.build
new file mode 100644
index 0000000000..4955981f3d
--- /dev/null
+++ b/comm/mailnews/mime/cthandlers/glue/moz.build
@@ -0,0 +1,17 @@
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+EXPORTS += [
+ "nsMimeContentTypeHandler.h",
+]
+
+SOURCES += [
+ "mimexpcom.cpp",
+ "nsMimeContentTypeHandler.cpp",
+]
+
+FINAL_LIBRARY = "mail"
+
+Library("mimecthglue_s")
diff --git a/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp b/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp
new file mode 100644
index 0000000000..ace9c64d8c
--- /dev/null
+++ b/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.cpp
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include "nscore.h"
+#include "plstr.h"
+#include "nsMimeContentTypeHandler.h"
+
+/*
+ * The following macros actually implement addref, release and
+ * query interface for our component.
+ */
+NS_IMPL_ISUPPORTS(nsMimeContentTypeHandler, nsIMimeContentTypeHandler)
+
+/*
+ * nsIMimeEmitter definitions....
+ */
+nsMimeContentTypeHandler::nsMimeContentTypeHandler(
+ const char* aMimeType, MCTHCreateCTHClass callback) {
+ NS_ASSERTION(
+ aMimeType,
+ "nsMimeContentTypeHandler should be initialized with non-null mime type");
+ NS_ASSERTION(
+ callback,
+ "nsMimeContentTypeHandler should be initialized with non-null callback");
+ mimeType = PL_strdup(aMimeType);
+ realCreateContentTypeHandlerClass = callback;
+}
+
+nsMimeContentTypeHandler::~nsMimeContentTypeHandler(void) {
+ if (mimeType) {
+ free(mimeType);
+ mimeType = 0;
+ }
+ realCreateContentTypeHandlerClass = 0;
+}
+
+// Get the content type if necessary
+nsresult nsMimeContentTypeHandler::GetContentType(char** contentType) {
+ *contentType = PL_strdup(mimeType);
+ return NS_OK;
+}
+
+// Set the output stream for processed data.
+nsresult nsMimeContentTypeHandler::CreateContentTypeHandlerClass(
+ const char* content_type, contentTypeHandlerInitStruct* initStruct,
+ MimeObjectClass** objClass) {
+ *objClass = realCreateContentTypeHandlerClass(content_type, initStruct);
+ if (!*objClass)
+ return NS_ERROR_OUT_OF_MEMORY; /* we couldn't allocate the object */
+ else
+ return NS_OK;
+}
diff --git a/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.h b/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.h
new file mode 100644
index 0000000000..2974e98f17
--- /dev/null
+++ b/comm/mailnews/mime/cthandlers/glue/nsMimeContentTypeHandler.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This interface is implemented by content type handlers that will be
+ * called upon by libmime to process various attachments types. The primary
+ * purpose of these handlers will be to represent the attached data in a
+ * viewable HTML format that is useful for the user
+ *
+ * Note: These will all register by their content type prefixed by the
+ * following: mimecth:text/vcard
+ *
+ * libmime will then use the XPCOM Component Manager to
+ * locate the appropriate Content Type handler
+ */
+#ifndef nsMimeContentTypeHandler_h_
+#define nsMimeContentTypeHandler_h_
+
+#include "mozilla/Attributes.h"
+#include "nsIMimeContentTypeHandler.h"
+
+typedef MimeObjectClass* (*MCTHCreateCTHClass)(
+ const char* content_type, contentTypeHandlerInitStruct* initStruct);
+
+class nsMimeContentTypeHandler : public nsIMimeContentTypeHandler {
+ public:
+ nsMimeContentTypeHandler(const char* aMimeType, MCTHCreateCTHClass callback);
+
+ /* this macro defines QueryInterface, AddRef and Release for this class */
+ NS_DECL_ISUPPORTS
+
+ NS_IMETHOD GetContentType(char** contentType) override;
+
+ NS_IMETHOD CreateContentTypeHandlerClass(
+ const char* content_type, contentTypeHandlerInitStruct* initStruct,
+ MimeObjectClass** objClass) override;
+
+ private:
+ virtual ~nsMimeContentTypeHandler();
+ char* mimeType;
+ MCTHCreateCTHClass realCreateContentTypeHandlerClass;
+};
+
+#endif /* nsMimeContentTypeHandler_h_ */