diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/components/search/mdimporter | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mail/components/search/mdimporter')
-rw-r--r-- | comm/mail/components/search/mdimporter/English.lproj/InfoPlist.strings | bin | 0 -> 456 bytes | |||
-rw-r--r-- | comm/mail/components/search/mdimporter/English.lproj/schema.strings | bin | 0 -> 1276 bytes | |||
-rw-r--r-- | comm/mail/components/search/mdimporter/GetMetadataForFile.c | 76 | ||||
-rw-r--r-- | comm/mail/components/search/mdimporter/Info.plist | 53 | ||||
-rw-r--r-- | comm/mail/components/search/mdimporter/Makefile.in | 26 | ||||
-rw-r--r-- | comm/mail/components/search/mdimporter/main.c | 208 | ||||
-rw-r--r-- | comm/mail/components/search/mdimporter/moz.build | 22 | ||||
-rw-r--r-- | comm/mail/components/search/mdimporter/schema.xml | 32 |
8 files changed, 417 insertions, 0 deletions
diff --git a/comm/mail/components/search/mdimporter/English.lproj/InfoPlist.strings b/comm/mail/components/search/mdimporter/English.lproj/InfoPlist.strings Binary files differnew file mode 100644 index 0000000000..ca96e65b7e --- /dev/null +++ b/comm/mail/components/search/mdimporter/English.lproj/InfoPlist.strings diff --git a/comm/mail/components/search/mdimporter/English.lproj/schema.strings b/comm/mail/components/search/mdimporter/English.lproj/schema.strings Binary files differnew file mode 100644 index 0000000000..0f7b8d6297 --- /dev/null +++ b/comm/mail/components/search/mdimporter/English.lproj/schema.strings diff --git a/comm/mail/components/search/mdimporter/GetMetadataForFile.c b/comm/mail/components/search/mdimporter/GetMetadataForFile.c new file mode 100644 index 0000000000..cafb3f05ee --- /dev/null +++ b/comm/mail/components/search/mdimporter/GetMetadataForFile.c @@ -0,0 +1,76 @@ +/* -*- 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 <CoreFoundation/CoreFoundation.h> +#include <CoreServices/CoreServices.h> + +/* ----------------------------------------------------------------------------- + Get metadata attributes from file + + This function's job is to extract useful information from the .mozeml file + and return it as a dictionary + ----------------------------------------------------------------------------- + */ + +Boolean GetMetadataForFile(void* thisInterface, + CFMutableDictionaryRef attributes, + CFStringRef contentTypeUTI, CFStringRef pathToFile) { + /* Pull any available metadata from the file at the specified path */ + /* Return the attribute keys and attribute values in the dict */ + /* Return TRUE if successful, FALSE if there was no data provided */ + Boolean success; + CFURLRef fileURL = CFURLCreateWithFileSystemPath( + kCFAllocatorDefault, pathToFile, kCFURLPOSIXPathStyle, false); + CFReadStreamRef stream = + CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL); + CFReadStreamOpen(stream); + + CFErrorRef err = NULL; + CFPropertyListRef ticket = CFPropertyListCreateWithStream( + kCFAllocatorDefault, stream, + /*streamLength*/ 0, kCFPropertyListImmutable, NULL, &err); + if (err != NULL) { + CFStringRef errorString = CFErrorCopyDescription(err); + if (errorString != NULL) { + printf("failed creating property list from stream\n"); + printf("error = %s\n", (const char*)errorString); + } + CFRelease(err); + success = FALSE; + } else { + CFTypeRef value; + value = CFDictionaryGetValue(ticket, kMDItemTitle); + if (value) { + CFDictionarySetValue(attributes, kMDItemTitle, value); + } + value = CFDictionaryGetValue(ticket, kMDItemTextContent); + if (value) { + CFDictionarySetValue(attributes, kMDItemTextContent, value); + } + value = CFDictionaryGetValue(ticket, kMDItemDisplayName); + if (value) CFDictionarySetValue(attributes, kMDItemDisplayName, value); + + CFDateFormatterRef dateFormatter = CFDateFormatterCreate( + NULL, NULL, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle); + + value = CFDictionaryGetValue(ticket, kMDItemLastUsedDate); + + if (value && dateFormatter) { + printf("trying to parse date \n"); + CFDateRef curDate = + CFDateFormatterCreateDateFromString(NULL, dateFormatter, value, NULL); + printf("got cur date\n"); + if (curDate) + CFDictionarySetValue(attributes, kMDItemLastUsedDate, curDate); + } + success = TRUE; + } + // contents are kMDItemTextContent + + CFReadStreamClose(stream); + CFRelease(stream); + CFRelease(fileURL); + return success; +} diff --git a/comm/mail/components/search/mdimporter/Info.plist b/comm/mail/components/search/mdimporter/Info.plist new file mode 100644 index 0000000000..ccb2f3cd10 --- /dev/null +++ b/comm/mail/components/search/mdimporter/Info.plist @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleDocumentTypes</key> + <array> + <dict> + <key>CFBundleTypeOSTypes</key> + <array> + <string>TBMZ</string> + </array> + <key>CFBundleTypeRole</key> + <string>MDImporter</string> + <key>LSItemContentTypes</key> + <array> + <string>com.mozilla.thunderbird.mozeml</string> + </array> + </dict> + </array> + <key>CFBundleExecutable</key> + <string>thunderbird-mdimport</string> + <key>CFBundleIconFile</key> + <string>thunderbird-mdimport</string> + <key>CFBundleIdentifier</key> + <string>org.mozilla.MDImporter.Thunderbird</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>Thunderbird-MDImport</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>CFPlugInDynamicRegisterFunction</key> + <string></string> + <key>CFPlugInDynamicRegistration</key> + <string>NO</string> + <key>CFPlugInFactories</key> + <dict> + <key>37401ADE-1058-42DB-BBE5-F2AAB9D7C13E</key> + <string>MetadataImporterPluginFactory</string> + </dict> + <key>CFPlugInTypes</key> + <dict> + <key>8B08C4BF-415B-11D8-B3F9-0003936726FC</key> + <array> + <string>37401ADE-1058-42DB-BBE5-F2AAB9D7C13E</string> + </array> + </dict> + <key>CFPlugInUnloadFunction</key> + <string></string> +</dict> +</plist> diff --git a/comm/mail/components/search/mdimporter/Makefile.in b/comm/mail/components/search/mdimporter/Makefile.in new file mode 100644 index 0000000000..fbc6d27034 --- /dev/null +++ b/comm/mail/components/search/mdimporter/Makefile.in @@ -0,0 +1,26 @@ +# 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 directory is producing a framework as a target. The output of this +# framework will be located here. +FRAMEWORK_DIR := $(DIST)/package/thunderbird.mdimporter + +STRING_FILES := $(srcdir)/English.lproj/InfoPlist.strings $(srcdir)/English.lproj/schema.strings +STRING_DEST := $(FRAMEWORK_DIR)/Contents/Resources/English.lproj +INSTALL_TARGETS += STRING + +SCHEMA_FILES := $(srcdir)/schema.xml +SCHEMA_DEST := $(FRAMEWORK_DIR)/Contents/Resources +INSTALL_TARGETS += SCHEMA + +PLIST_FILES := $(srcdir)/Info.plist +PLIST_DEST := $(FRAMEWORK_DIR)/Contents +INSTALL_TARGETS += PLIST + +CFLAGS += -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) +# We don't need mozglue +WRAP_LDFLAGS := + +include $(topsrcdir)/config/rules.mk + diff --git a/comm/mail/components/search/mdimporter/main.c b/comm/mail/components/search/mdimporter/main.c new file mode 100644 index 0000000000..20afc65351 --- /dev/null +++ b/comm/mail/components/search/mdimporter/main.c @@ -0,0 +1,208 @@ +/* -*- 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/. */ + +//============================================================================== +// +// DO NO MODIFY THE CONTENT OF THIS FILE +// +// This file contains the generic CFPlug-in code necessary for TB Spotlight +// The actual importer is implemented in GetMetadataForFile.c +// +//============================================================================== + +#include <CoreFoundation/CoreFoundation.h> +#include <CoreFoundation/CFPlugInCOM.h> +#include <CoreServices/CoreServices.h> + +// ----------------------------------------------------------------------------- +// constants +// ----------------------------------------------------------------------------- + +#define PLUGIN_ID "37401ADE-1058-42DB-BBE5-F2AAB9D7C13E" + +// +// Below is the generic glue code for all plug-ins. +// +// You should not have to modify this code aside from changing +// names if you decide to change the names defined in the Info.plist +// + +// ----------------------------------------------------------------------------- +// typedefs +// ----------------------------------------------------------------------------- + +// The import function to be implemented in GetMetadataForFile.c +Boolean GetMetadataForFile(void* thisInterface, + CFMutableDictionaryRef attributes, + CFStringRef contentTypeUTI, CFStringRef pathToFile); + +// The layout for an instance of MetaDataImporterPlugIn +typedef struct __MetadataImporterPluginType { + MDImporterInterfaceStruct* conduitInterface; + CFUUIDRef factoryID; + UInt32 refCount; +} MetadataImporterPluginType; + +// ----------------------------------------------------------------------------- +// prototypes +// ----------------------------------------------------------------------------- +// Forward declaration for the IUnknown implementation. +// + +MetadataImporterPluginType* AllocMetadataImporterPluginType( + CFUUIDRef inFactoryID); +void DeallocMetadataImporterPluginType( + MetadataImporterPluginType* thisInstance); +HRESULT MetadataImporterQueryInterface(void* thisInstance, REFIID iid, + LPVOID* ppv); +void* MetadataImporterPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID); +ULONG MetadataImporterPluginAddRef(void* thisInstance); +ULONG MetadataImporterPluginRelease(void* thisInstance); +// ----------------------------------------------------------------------------- +// testInterfaceFtbl definition +// ----------------------------------------------------------------------------- +// The TestInterface function table. +// + +static MDImporterInterfaceStruct testInterfaceFtbl = { + NULL, MetadataImporterQueryInterface, MetadataImporterPluginAddRef, + MetadataImporterPluginRelease, GetMetadataForFile}; + +// ----------------------------------------------------------------------------- +// AllocMetadataImporterPluginType +// ----------------------------------------------------------------------------- +// Utility function that allocates a new instance. +// You can do some initial setup for the importer here if you wish +// like allocating globals etc... +// +MetadataImporterPluginType* AllocMetadataImporterPluginType( + CFUUIDRef inFactoryID) { + MetadataImporterPluginType* theNewInstance; + + theNewInstance = + (MetadataImporterPluginType*)malloc(sizeof(MetadataImporterPluginType)); + memset(theNewInstance, 0, sizeof(MetadataImporterPluginType)); + + /* Point to the function table */ + theNewInstance->conduitInterface = &testInterfaceFtbl; + + /* Retain and keep an open instance refcount for each factory. */ + theNewInstance->factoryID = CFRetain(inFactoryID); + CFPlugInAddInstanceForFactory(inFactoryID); + + /* This function returns the IUnknown interface so set the refCount to one. */ + theNewInstance->refCount = 1; + return theNewInstance; +} + +// ----------------------------------------------------------------------------- +// DeallocTBSpotlightMDImporterPluginType +// ----------------------------------------------------------------------------- +// Utility function that deallocates the instance when +// the refCount goes to zero. +// In the current implementation importer interfaces are never deallocated +// but implement this as this might change in the future +// +void DeallocMetadataImporterPluginType( + MetadataImporterPluginType* thisInstance) { + CFUUIDRef theFactoryID; + + theFactoryID = thisInstance->factoryID; + free(thisInstance); + if (theFactoryID) { + CFPlugInRemoveInstanceForFactory(theFactoryID); + CFRelease(theFactoryID); + } +} + +// ----------------------------------------------------------------------------- +// MetadataImporterQueryInterface +// ----------------------------------------------------------------------------- +// Implementation of the IUnknown QueryInterface function. +// +HRESULT MetadataImporterQueryInterface(void* thisInstance, REFIID iid, + LPVOID* ppv) { + CFUUIDRef interfaceID; + + interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid); + + if (CFEqual(interfaceID, kMDImporterInterfaceID)) { + /* If the Right interface was requested, bump the ref count, + * set the ppv parameter equal to the instance, and + * return good status. + */ + ((MetadataImporterPluginType*)thisInstance) + ->conduitInterface->AddRef(thisInstance); + *ppv = thisInstance; + CFRelease(interfaceID); + return S_OK; + } else { + if (CFEqual(interfaceID, IUnknownUUID)) { + /* If the IUnknown interface was requested, same as above. */ + ((MetadataImporterPluginType*)thisInstance) + ->conduitInterface->AddRef(thisInstance); + *ppv = thisInstance; + CFRelease(interfaceID); + return S_OK; + } else { + /* Requested interface unknown, bail with error. */ + *ppv = NULL; + CFRelease(interfaceID); + return E_NOINTERFACE; + } + } +} + +// ----------------------------------------------------------------------------- +// MetadataImporterPluginAddRef +// ----------------------------------------------------------------------------- +// Implementation of reference counting for this type. Whenever an interface +// is requested, bump the refCount for the instance. NOTE: returning the +// refcount is a convention but is not required so don't rely on it. +// +ULONG MetadataImporterPluginAddRef(void* thisInstance) { + ((MetadataImporterPluginType*)thisInstance)->refCount += 1; + return ((MetadataImporterPluginType*)thisInstance)->refCount; +} + +// ----------------------------------------------------------------------------- +// SampleCMPluginRelease +// ----------------------------------------------------------------------------- +// When an interface is released, decrement the refCount. +// If the refCount goes to zero, deallocate the instance. +// +ULONG MetadataImporterPluginRelease(void* thisInstance) { + ((MetadataImporterPluginType*)thisInstance)->refCount -= 1; + if (((MetadataImporterPluginType*)thisInstance)->refCount == 0) { + DeallocMetadataImporterPluginType( + (MetadataImporterPluginType*)thisInstance); + return 0; + } else { + return ((MetadataImporterPluginType*)thisInstance)->refCount; + } +} + +// ----------------------------------------------------------------------------- +// TBSpotlightMDImporterPluginFactory +// ----------------------------------------------------------------------------- +// Implementation of the factory function for this type. +// +void* MetadataImporterPluginFactory(CFAllocatorRef allocator, + CFUUIDRef typeID) { + MetadataImporterPluginType* result; + CFUUIDRef uuid; + + /* If correct type is being requested, allocate an + * instance of TestType and return the IUnknown interface. + */ + if (CFEqual(typeID, kMDImporterTypeID)) { + uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID)); + result = AllocMetadataImporterPluginType(uuid); + CFRelease(uuid); + return result; + } + /* If the requested type is incorrect, return NULL. */ + return NULL; +} diff --git a/comm/mail/components/search/mdimporter/moz.build b/comm/mail/components/search/mdimporter/moz.build new file mode 100644 index 0000000000..8bfc3e6c80 --- /dev/null +++ b/comm/mail/components/search/mdimporter/moz.build @@ -0,0 +1,22 @@ +# 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/. + +SOURCES = [ + "GetMetadataForFile.c", + "main.c", +] + +Program("thunderbird-mdimport") +# This directory is producing a framework as a target. The output of this +# framework will be located here. +FINAL_TARGET = "dist/package/thunderbird.mdimporter/Contents/MacOS" + +OS_LIBS += [ + "-framework CoreFoundation", + "-framework CoreServices", +] + +# We're also a bundle. +LDFLAGS += ["-bundle"] diff --git a/comm/mail/components/search/mdimporter/schema.xml b/comm/mail/components/search/mdimporter/schema.xml new file mode 100644 index 0000000000..f450209378 --- /dev/null +++ b/comm/mail/components/search/mdimporter/schema.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- 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/. --> + + +<schema version="1.0" xmlns="http://www.apple.com/metadata" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.apple.com/metadata file:///System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Resources/MetadataSchema.xsd"> + <note> + Start off by supporting the same attributes as Mail.importer + </note> + <attributes> + <attribute name="kMDItemAuthorEmailAddresses" multivalued="true" type="CFString"/> + <attribute name="kMDItemRecipientEmailAddresses" multivalued="true" type="CFString"/> + </attributes> + + <types> + <type name="com.mozilla.thunderbird.mozeml"> + <note> + The keys that this metadata importer handles. + </note> + <allattrs> + kMDItemAuthorEmailAddresses + kMDItemRecipientEmailAddresses + </allattrs> + <displayattrs> + </displayattrs> + </type> + </types> +</schema> + |