nsmailwinintegration.cpp
来自「现在很火的邮件客户端软件thunderbird的源码」· C++ 代码 · 共 483 行 · 第 1/2 页
CPP
483 行
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Thunderbird Windows Integration. * * The Initial Developer of the Original Code is * Scott MacGregor <mscott@mozilla.org>. * Portions created by the Initial Developer are Copyright (C) 2006 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#include "nsMailWinIntegration.h"#include "nsIServiceManager.h"#include "nsICategoryManager.h"#include "nsCRT.h"#include "nsIStringBundle.h"#include "nsNativeCharsetUtils.h"#include "nsIPrefService.h"#ifndef __MINGW32__#include "nsIMapiSupport.h"#endif#include "shlobj.h"#include <mbstring.h>#define MOZ_CLIENT_MAIL_KEY "Software\\Clients\\Mail"#define MOZ_CLIENT_NEWS_KEY "Software\\Clients\\News"#ifndef MAX_BUF#define MAX_BUF 4096#endif#define REG_FAILED(val) \ (val != ERROR_SUCCESS)NS_IMPL_ISUPPORTS1(nsWindowsShellService, nsIShellService)static nsresultOpenUserKeyForReading(HKEY aStartKey, const char* aKeyName, HKEY* aKey){ DWORD result = ::RegOpenKeyEx(aStartKey, aKeyName, 0, KEY_READ, aKey); switch (result) { case ERROR_SUCCESS: break; case ERROR_ACCESS_DENIED: return NS_ERROR_FILE_ACCESS_DENIED; case ERROR_FILE_NOT_FOUND: if (aStartKey == HKEY_LOCAL_MACHINE) { // prevent infinite recursion on the second pass through here if // ::RegOpenKeyEx fails in the all-users case. return NS_ERROR_NOT_AVAILABLE; } return OpenUserKeyForReading(HKEY_LOCAL_MACHINE, aKeyName, aKey); } return NS_OK;}static nsresultOpenKeyForWriting(const char* aKeyName, HKEY* aKey, PRBool aForAllUsers, PRBool aCreate){ nsresult rv = NS_OK; HKEY rootKey = aForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; DWORD result = ::RegOpenKeyEx(rootKey, aKeyName, 0, KEY_READ | KEY_WRITE, aKey); switch (result) { case ERROR_SUCCESS: break; case ERROR_ACCESS_DENIED: return NS_ERROR_FILE_ACCESS_DENIED; case ERROR_FILE_NOT_FOUND: if (aCreate) result = ::RegCreateKey(HKEY_LOCAL_MACHINE, aKeyName, aKey); rv = NS_ERROR_FILE_NOT_FOUND; break; } return rv;}///////////////////////////////////////////////////////////////////////////////// Default Mail Registry Settings///////////////////////////////////////////////////////////////////////////////typedef enum { NO_SUBSTITUTION = 0x00, PATH_SUBSTITUTION = 0x01, APPNAME_SUBSTITUTION = 0x02, MAPIDLLPATH_SUBSTITUTION = 0x04, USE_FOR_DEFAULT_TEST = 0x08} SettingFlags;#define CLS "SOFTWARE\\Classes\\"#define MAILCLIENTS "SOFTWARE\\Clients\\Mail\\"#define NEWSCLIENTS "SOFTWARE\\Clients\\News\\"#define DI "\\DefaultIcon"#define CLS_EML "ThunderbirdEML"#define SOP "\\shell\\open\\command"#define EXE "thunderbird.exe"#define VAL_URL_ICON "%APPPATH%,0"#define VAL_FILE_ICON "%APPPATH%,1"#define VAL_OPEN "%APPPATH% \"%1\""#define VAL_OPEN_WITH_URL "%APPPATH% -url \"%1\""#define MAKE_KEY_NAME1(PREFIX, MID) \ PREFIX MID#define MAKE_KEY_NAME2(PREFIX, MID, SUFFIX) \ PREFIX MID SUFFIXstatic SETTING gMailSettings[] = { // File Extensions { MAKE_KEY_NAME1(CLS, ".eml"), "", "", NO_SUBSTITUTION }, { MAKE_KEY_NAME2(CLS, CLS_EML, DI), "", VAL_FILE_ICON, PATH_SUBSTITUTION }, { MAKE_KEY_NAME2(CLS, CLS_EML, SOP), "", VAL_OPEN, PATH_SUBSTITUTION}, // Protocol Handlers { MAKE_KEY_NAME2(CLS, "mailto", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION}, // we use the following key for our default mail app test so don't set the NON_ESSENTIAL flag { MAKE_KEY_NAME2(CLS, "mailto", SOP), "", "%APPPATH% -compose \"%1\"", PATH_SUBSTITUTION | USE_FOR_DEFAULT_TEST}, // Windows XP Start Menu { MAKE_KEY_NAME1(MAILCLIENTS, "%APPNAME%"), "DLLPath", "%MAPIDLLPATH%", MAPIDLLPATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%", DI), "", "%APPPATH%,0", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%", SOP), "", "%APPPATH% -mail", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME1(MAILCLIENTS, "%APPNAME%\\shell\\properties\\command"), "", "%APPPATH% -options", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%\\Protocols\\mailto", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION}, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%\\Protocols\\mailto", SOP), "", "%APPPATH% -compose \"%1\"", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%\\.eml", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION}, { MAKE_KEY_NAME2(MAILCLIENTS, "%APPNAME%\\.eml", SOP), "", VAL_OPEN, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION } // These values must be set by hand, since they contain localized strings. // shell\properties (default) REG_SZ Firefox &Options};static SETTING gNewsSettings[] = { // Protocol Handlers { MAKE_KEY_NAME2(CLS, "news", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION}, { MAKE_KEY_NAME2(CLS, "news", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | USE_FOR_DEFAULT_TEST}, { MAKE_KEY_NAME2(CLS, "nntp", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION}, { MAKE_KEY_NAME2(CLS, "nntp", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | USE_FOR_DEFAULT_TEST}, { MAKE_KEY_NAME2(CLS, "snews", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION}, { MAKE_KEY_NAME2(CLS, "snews", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION}, // Client Keys { MAKE_KEY_NAME1(NEWSCLIENTS, "%APPNAME%"), "DLLPath", "%MAPIDLLPATH%", MAPIDLLPATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%", DI), "", "%APPPATH%,0", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%", SOP), "", "%APPPATH% -mail", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\news", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION}, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\news", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\nntp", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION}, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\nntp", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\snews", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION | APPNAME_SUBSTITUTION}, { MAKE_KEY_NAME2(NEWSCLIENTS, "%APPNAME%\\Protocols\\snews", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | APPNAME_SUBSTITUTION }};static SETTING gFeedSettings[] = { // Protocol Handlers { MAKE_KEY_NAME2(CLS, "feed", DI), "", VAL_URL_ICON, PATH_SUBSTITUTION}, { MAKE_KEY_NAME2(CLS, "feed", SOP), "", "%APPPATH% -mail \"%1\"", PATH_SUBSTITUTION | USE_FOR_DEFAULT_TEST},};nsWindowsShellService::nsWindowsShellService():mCheckedThisSession(PR_FALSE){ nsresult rv; // fill in mAppPath char buf[MAX_BUF]; ::GetModuleFileName(NULL, buf, sizeof(buf)); ::GetShortPathName(buf, buf, sizeof(buf)); ToUpperCase(mAppPath = buf); mMapiDLLPath = mAppPath; // remove the process name from the string (thunderbird.exe) char* pathSep = (char *) _mbsrchr((const unsigned char *) mAppPath.get(), '\\'); if (pathSep) mMapiDLLPath.Truncate(pathSep - mAppPath.get() + 1); // now append mozMapi32.dll mMapiDLLPath += "mozMapi32.dll"; nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIStringBundle> bundle, brandBundle; rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties", getter_AddRefs(brandBundle)); if (NS_SUCCEEDED(rv)) { brandBundle->GetStringFromName(NS_LITERAL_STRING("brandFullName").get(), getter_Copies(mBrandFullName)); brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(mBrandShortName)); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?