From 7f0477179e516f1f5f97140374016965c60e6fb6 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 8 Jan 2002 03:19:10 +0000 Subject: [PATCH] fix for #2660, #36760, #54527 and #104987. fix addressbook printing, it's been broken a long time. r/sr=bienvenu --- mailnews/addrbook/public/nsIAbCard.idl | 3 + mailnews/addrbook/public/nsIAddbookUrl.idl | 26 +- mailnews/addrbook/public/nsIAddressBook.idl | 2 - .../addrbook/resources/content/addressbook.js | 44 +- .../resources/content/addressbook.xul | 2 + mailnews/addrbook/resources/content/print.css | 79 +++ .../resources/locale/en-US/abMainWindow.dtd | 2 +- mailnews/addrbook/src/nsAbCardProperty.cpp | 150 ++++- mailnews/addrbook/src/nsAbCardProperty.h | 3 + .../addrbook/src/nsAddbookProtocolHandler.cpp | 616 ++++-------------- .../addrbook/src/nsAddbookProtocolHandler.h | 38 +- mailnews/addrbook/src/nsAddbookUrl.cpp | 202 +----- mailnews/addrbook/src/nsAddbookUrl.h | 18 +- mailnews/addrbook/src/nsAddressBook.cpp | 27 - .../base/resources/content/msgPrintEngine.js | 4 + mailnews/base/src/nsMsgPrintEngine.cpp | 27 +- mailnews/base/util/nsMsgMailNewsUrl.cpp | 1 + mailnews/base/util/nsMsgUtils.cpp | 6 +- mailnews/jar.mn | 1 + 19 files changed, 431 insertions(+), 820 deletions(-) create mode 100644 mailnews/addrbook/resources/content/print.css diff --git a/mailnews/addrbook/public/nsIAbCard.idl b/mailnews/addrbook/public/nsIAbCard.idl index a015a883ce3..fcc1bb7b55f 100644 --- a/mailnews/addrbook/public/nsIAbCard.idl +++ b/mailnews/addrbook/public/nsIAbCard.idl @@ -110,4 +110,7 @@ interface nsIAbCard : nsISupports { void editCardToDatabase(in string uri); boolean equals(in nsIAbCard card); + + string convertToBase64EncodedXML(); + wstring convertToXMLData(); }; diff --git a/mailnews/addrbook/public/nsIAddbookUrl.idl b/mailnews/addrbook/public/nsIAddbookUrl.idl index 5c1685a97ea..31e1a61cb09 100644 --- a/mailnews/addrbook/public/nsIAddbookUrl.idl +++ b/mailnews/addrbook/public/nsIAddbookUrl.idl @@ -36,35 +36,15 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIURI.idl" -#include "nsIAbCard.idl" [scriptable, uuid(6EB9D874-01AA-11d4-8FBE-000064657374)] - interface nsIAddbookUrlOperation { - const long InvalidUrl = 0; - const long PrintIndividual = 1; - const long PrintAddressBook = 2; - const long ImportCards = 3; - const long ImportMailingLists = 4; - const long ExportCards = 5; - const long AddToAddressBook = 6; - const long ExportTitle = 7; - const long ImportTitle = 8; + const long InvalidUrl = 0; + const long PrintAddressBook = 1; }; [uuid(ee1d5cc3-5f8c-43f3-b1b8-8d2ea67ce2d8)] interface nsIAddbookUrl : nsIURI { - - /////////////////////////////////////////////////////////////////////////////// - // Addbook parse specific getters - // Not sure if this will be used by the outside world, but if it is, at - // least its here - /////////////////////////////////////////////////////////////////////////////// - - // So what does the user want to do with this particular URL - long GetAddbookOperation(); - nsIAbCard GetAbCard(); - - + readonly attribute long addbookOperation; }; diff --git a/mailnews/addrbook/public/nsIAddressBook.idl b/mailnews/addrbook/public/nsIAddressBook.idl index e6083acba4d..f0109d42dd0 100644 --- a/mailnews/addrbook/public/nsIAddressBook.idl +++ b/mailnews/addrbook/public/nsIAddressBook.idl @@ -51,8 +51,6 @@ interface nsIAddressBook : nsISupports { void newAddressBook(in nsIRDFCompositeDataSource db, in unsigned long prefCount,[array, size_is(prefCount)] in string prefName, [array, size_is(prefCount)] in wstring prefValue); void deleteAddressBooks(in nsIRDFCompositeDataSource db, in nsISupportsArray parentDir, in nsIDOMNodeList node); - void printCard(); - void printAddressbook(); void setDocShellWindow(in nsIDOMWindowInternal win); void exportAddressBook(in nsIAbDirectory aDirectory); void convertLDIFtoMAB(in nsIFileSpec fileSpec, in boolean migrating, in nsIAddrDatabase db, in boolean bStoreLocAsHome, in boolean bImportingComm4x); diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js index 80554c503d0..c040ed5af63 100644 --- a/mailnews/addrbook/resources/content/addressbook.js +++ b/mailnews/addrbook/resources/content/addressbook.js @@ -270,19 +270,18 @@ function AbPrintCard() if (!uri) return; - var escapedDirName = escape(addressbook.getAbDatabaseFromURI(uri).directoryName); - var statusFeedback; statusFeedback = Components.classes["@mozilla.org/messenger/statusfeedback;1"].createInstance(); statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); var selectionArray = new Array(numSelected); + var totalCard = 0; for(var i = 0; i < numSelected; i++) { var card = selectedItems[i]; - var printCardUrl = CreatePrintCardUrl(escapedDirName, card); + var printCardUrl = CreatePrintCardUrl(card); if (printCardUrl) { selectionArray[totalCard++] = printCardUrl; @@ -297,26 +296,37 @@ function AbPrintCard() return; } -function CreatePrintCardUrl(escapedDirName, card) +function CreatePrintCardUrl(card) { - var url = ""; - - var email = card.primaryEmail; - if (email) { - url = "addbook:printone?email=" + email + "&folder=" + escapedDirName; - } + var url = "data:text/xml;base64," + card.convertToBase64EncodedXML(); return url; } function AbPrintAddressBook() { - dump("print address book \n"); - try { - addressbook.PrintAddressbook(); - } - catch (ex) { - dump("failed to print address book\n"); - } + var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook); + var uri = GetAbViewURI(); + if (!uri) + return; + + var statusFeedback; + statusFeedback = Components.classes["@mozilla.org/messenger/statusfeedback;1"].createInstance(); + statusFeedback = statusFeedback.QueryInterface(Components.interfaces.nsIMsgStatusFeedback); + + /* + turn "moz-abmdbdirectory://abook.mab" into + "addbook://moz-abmdbdirectory/abook.mab?action=print" + */ + + var abURIArr = uri.split("://"); + var printUrl = "addbook://" + abURIArr[0] + "/" + abURIArr[1] + "?action=print" + + printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", + "", + "chrome,dialog=no,all", + 1, [printUrl], statusFeedback); + + return; } function AbExport() diff --git a/mailnews/addrbook/resources/content/addressbook.xul b/mailnews/addrbook/resources/content/addressbook.xul index c70028b6908..b205da7c566 100644 --- a/mailnews/addrbook/resources/content/addressbook.xul +++ b/mailnews/addrbook/resources/content/addressbook.xul @@ -77,6 +77,7 @@ Contributor(s): + @@ -135,6 +136,7 @@ Contributor(s): + diff --git a/mailnews/addrbook/resources/content/print.css b/mailnews/addrbook/resources/content/print.css new file mode 100644 index 00000000000..39dfe1c7998 --- /dev/null +++ b/mailnews/addrbook/resources/content/print.css @@ -0,0 +1,79 @@ +/* ***** 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 mozilla addressbook + * + * The Initial Developer of the Original Code is + * Seth Spitzer + * Portions created by the Initial Developer are Copyright (C) 2002 + * 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 ***** */ +directory {display:table;} +abcard {display:table-row;} +abcard *{display:table-cell; padding:5px;} +GeneratedName {display:block; font-weight:bold;} +FirstName {display:block;} +LastName {display:block;} +DisplayName {display:block;} +NickName {display:block;} +PrimaryEmail {display:block;} +SecondEmail {display:block;} +PreferMailFormat {display:none;} +WorkPhone {display:block;} +HomePhone {display:block;} +FaxNumber {display:block;} +PagerNumber {display:block;} +CellularNumber {display:block;} +HomeAddress {display:block;} +HomeAddress2 {display:block;} +HomeCity {display:block;} +HomeState {display:block;} +HomeZipCode {display:block;} +HomeCountry {display:block;} +WorkAddress {display:block;} +WorkAddress2 {display:block;} +WorkCity {display:block;} +WorkState {display:block;} +WorkZipCode {display:block;} +WorkCountry {display:block;} +JobTitle {display:block;} +Department {display:block;} +Company {display:block;} +WebPage1 {display:block;} +WebPage2 {display:block;} +BirthYear {display:block;} +BirthMonth {display:block;} +BirthDay {display:block;} +Custom1 {display:block;} +Custom2 {display:block;} +Custom3 {display:block;} +Custom4 {display:block;} +Notes {display:block;} +ListName {display:block;} +ListNickName {display:block;} +ListDescription {display:block;} diff --git a/mailnews/addrbook/resources/locale/en-US/abMainWindow.dtd b/mailnews/addrbook/resources/locale/en-US/abMainWindow.dtd index bb40a0702cb..4a5e6687d74 100644 --- a/mailnews/addrbook/resources/locale/en-US/abMainWindow.dtd +++ b/mailnews/addrbook/resources/locale/en-US/abMainWindow.dtd @@ -45,7 +45,7 @@ Rights Reserved. - + diff --git a/mailnews/addrbook/src/nsAbCardProperty.cpp b/mailnews/addrbook/src/nsAbCardProperty.cpp index a1211db8b9e..a4b6aac8836 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbCardProperty.cpp @@ -38,20 +38,73 @@ * ***** END LICENSE BLOCK ***** */ #include "nsAbCardProperty.h" -#include "nsIRDFService.h" #include "nsIServiceManager.h" -#include "nsRDFCID.h" #include "nsXPIDLString.h" #include "nsAbBaseCID.h" #include "prmem.h" #include "prlog.h" #include "prprf.h" -#include "rdf.h" #include "nsCOMPtr.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" #include "nsIPref.h" #include "nsIAbDirectory.h" +#include "plbase64.h" +#include "nsIAddrBookSession.h" + +#define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst" + +#define LIST_ATTRS_COUNT 4 + +static const char *LIST_ARRTS_ARRAY[] = { + kMailListName, + kMailListNickName, + kMailListDescription, + kMailListTotalAddresses +}; + +#define CARD_ATTRS_COUNT 37 + +// XXX todo what about _AimScreenName, or other generic columns? +static const char *CARD_ATTRS_ARRAY[] = { + kFirstNameColumn, + kLastNameColumn, + kDisplayNameColumn, + kNicknameColumn, + kPriEmailColumn, + k2ndEmailColumn, + kPreferMailFormatColumn, + kWorkPhoneColumn, + kHomePhoneColumn, + kFaxColumn, + kPagerColumn, + kCellularColumn, + kHomeAddressColumn, + kHomeAddress2Column, + kHomeCityColumn, + kHomeStateColumn, + kHomeZipCodeColumn, + kHomeCountryColumn, + kWorkAddressColumn, + kWorkAddress2Column, + kWorkCityColumn, + kWorkStateColumn, + kWorkZipCodeColumn, + kWorkCountryColumn, + kJobTitleColumn, + kDepartmentColumn, + kCompanyColumn, + kWebPage1Column, + kWebPage2Column, + kBirthYearColumn, + kBirthMonthColumn, + kBirthDayColumn, + kCustom1Column, + kCustom2Column, + kCustom3Column, + kCustom4Column, + kNotesColumn +}; nsAbCardProperty::nsAbCardProperty(void) { @@ -943,3 +996,94 @@ NS_IMETHODIMP nsAbCardProperty::Equals(nsIAbCard *card, PRBool *result) *result = (card == this); return NS_OK; } + +NS_IMETHODIMP nsAbCardProperty::ConvertToBase64EncodedXML(char **result) +{ + nsresult rv; + nsString xmlStr; + + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + + nsXPIDLString xmlSubstr; + rv = ConvertToXMLData(getter_Copies(xmlSubstr)); + NS_ENSURE_SUCCESS(rv,rv); + + xmlStr.Append(xmlSubstr.get()); + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + + *result = PL_Base64Encode(NS_ConvertUCS2toUTF8(xmlStr).get(), 0, nsnull); + if (!*result) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} + +NS_IMETHODIMP nsAbCardProperty::ConvertToXMLData(PRUnichar **aXMLSubstr) +{ + NS_ENSURE_ARG_POINTER(aXMLSubstr); + + nsresult rv; + nsString xmlStr; + + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + // get the generated name + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr prefBranch; + rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); + NS_ENSURE_SUCCESS(rv,rv); + + PRInt32 generatedNameFormat; + rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &generatedNameFormat); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + nsXPIDLString generatedName; + rv = abSession->GenerateNameFromCard(this, generatedNameFormat, getter_Copies(generatedName)); + NS_ENSURE_SUCCESS(rv,rv); + + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + xmlStr.Append(generatedName.get()); + xmlStr.Append(NS_LITERAL_STRING("\n").get()); + + PRUint32 i; + for (i=0;i\n").get()); + + *aXMLSubstr = ToNewUnicode(xmlStr); + return NS_OK; +} + +nsresult nsAbCardProperty::AppendData(const char *attrName, nsString &result) +{ + nsXPIDLString attrValue; + nsresult rv = GetCardValue(attrName, getter_Copies(attrValue)); + NS_ENSURE_SUCCESS(rv,rv); + + if (attrValue.IsEmpty()) + return NS_OK; + + nsAutoString attrNameStr; + attrNameStr.AssignWithConversion(attrName); + + result.Append(NS_LITERAL_STRING("<").get()); + result.Append(attrNameStr.get()); + result.Append(NS_LITERAL_STRING(">").get()); + + result.Append(attrValue.get()); + + result.Append(NS_LITERAL_STRING("").get()); + + return NS_OK; +} diff --git a/mailnews/addrbook/src/nsAbCardProperty.h b/mailnews/addrbook/src/nsAbCardProperty.h index bde79ca808b..b854cc28ba4 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.h +++ b/mailnews/addrbook/src/nsAbCardProperty.h @@ -110,6 +110,9 @@ protected: PRBool m_IsMailList; char* m_MailListURI; + +private: + nsresult AppendData(const char *attrName, nsString &result); }; #endif diff --git a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp index ad7a33f83c4..0752c02900a 100644 --- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp +++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp @@ -49,7 +49,6 @@ #include "nsAddbookProtocolHandler.h" #include "nsIFileSpec.h" #include "nsCOMPtr.h" -#include "nsIMsgIdentity.h" #include "nsAbBaseCID.h" #include "nsNetUtil.h" #include "nsIStringStream.h" @@ -64,18 +63,14 @@ #include "nsIPrefService.h" #include "nsIPrefBranch.h" -extern const char *kWorkAddressBook; - nsAddbookProtocolHandler::nsAddbookProtocolHandler() { NS_INIT_REFCNT(); - mReportColumns = nsnull; + mAddbookOperation = nsIAddbookUrlOperation::InvalidUrl; } nsAddbookProtocolHandler::~nsAddbookProtocolHandler() { - PR_FREEIF(mReportColumns); - mReportColumns = nsnull; } NS_IMPL_ISUPPORTS1(nsAddbookProtocolHandler, nsIProtocolHandler); @@ -103,20 +98,18 @@ NS_IMETHODIMP nsAddbookProtocolHandler::GetProtocolFlags(PRUint32 *aUritype) NS_IMETHODIMP nsAddbookProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, nsIURI **_retval) { - // get a new addrbook url nsresult rv = NS_OK; - nsCOMPtr addbookUrl = do_CreateInstance(NS_ADDBOOKURL_CONTRACTID, &rv); + nsCOMPtr addbookUrl = do_CreateInstance(NS_ADDBOOKURL_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv,rv); - if (NS_SUCCEEDED(rv)) - { - rv = addbookUrl->SetSpec(aSpec); - if (NS_SUCCEEDED(rv)) - { - rv = addbookUrl->QueryInterface(NS_GET_IID(nsIURI), (void **) _retval); - } - } + rv = addbookUrl->SetSpec(aSpec); + NS_ENSURE_SUCCESS(rv,rv); - return rv; + nsCOMPtr uri = do_QueryInterface(addbookUrl, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + NS_IF_ADDREF(*_retval = uri); + return NS_OK; } NS_IMETHODIMP @@ -127,9 +120,8 @@ nsAddbookProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_r return NS_OK; } -NS_IMETHODIMP -nsAddbookProtocolHandler::GenerateHTMLOutputChannel( const char *aHtmlOutput, - PRInt32 aHtmlOutputSize, +nsresult +nsAddbookProtocolHandler::GenerateXMLOutputChannel( nsString &aOutput, nsIAddbookUrl *addbookUrl, nsIURI *aURI, nsIChannel **_retval) @@ -138,16 +130,13 @@ nsAddbookProtocolHandler::GenerateHTMLOutputChannel( const char *aHtmlOutput, nsIChannel *channel; nsCOMPtr inStr; nsCOMPtr s; - - if (!aHtmlOutput) - return NS_ERROR_FAILURE; - rv = NS_NewStringInputStream(getter_AddRefs(s), NS_ConvertASCIItoUCS2(aHtmlOutput)); + rv = NS_NewStringInputStream(getter_AddRefs(s), aOutput); NS_ENSURE_SUCCESS(rv, rv); inStr = do_QueryInterface(s, &rv); NS_ENSURE_SUCCESS(rv, rv); - rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/html", aHtmlOutputSize); + rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/xml", aOutput.Length()); NS_ENSURE_SUCCESS(rv, rv); *_retval = channel; @@ -157,502 +146,139 @@ nsAddbookProtocolHandler::GenerateHTMLOutputChannel( const char *aHtmlOutput, NS_IMETHODIMP nsAddbookProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval) { - nsresult rv = NS_OK; - char *outBuf = nsnull; + nsresult rv; + + nsCOMPtr addbookUrl = do_QueryInterface(aURI, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + rv = addbookUrl->GetAddbookOperation(&mAddbookOperation); + NS_ENSURE_SUCCESS(rv,rv); - // - // Ok, now that we are here, we need to figure out what oprations we - // are going to perform...create a stream of buffered data if necessary - // or launch the UI dialog window and go from there. - // - mAddbookOperation = nsIAddbookUrlOperation::InvalidUrl; - nsCOMPtr addbookUrl = do_QueryInterface(aURI); - if (!addbookUrl) - return NS_ERROR_ABORT; + if (mAddbookOperation == nsIAddbookUrlOperation::InvalidUrl) { + nsString errorString; + errorString.Append(NS_LITERAL_STRING("Unsupported format/operation requested for ").get()); + nsXPIDLCString spec; + rv = aURI->GetSpec(getter_Copies(spec)); + NS_ENSURE_SUCCESS(rv,rv); - // - // Ok, first, lets see what we need to do here and then call the appropriate - // method to handle the operation - // - addbookUrl->GetAddbookOperation(&mAddbookOperation); - switch (mAddbookOperation) - { - case nsIAddbookUrlOperation::PrintIndividual: - case nsIAddbookUrlOperation::PrintAddressBook: - rv = GeneratePrintOutput(addbookUrl, &outBuf); - if ((NS_FAILED(rv) || (!outBuf))) - { - const char *eMsg = "Unsupported format/operation requested for \"addbook:\" URL."; - PRInt32 eSize = nsCRT::strlen(eMsg); - rv = GenerateHTMLOutputChannel(eMsg, eSize, addbookUrl, aURI, _retval); - break; - } - else - { - rv = GenerateHTMLOutputChannel(outBuf, nsCRT::strlen(outBuf), addbookUrl, aURI, _retval); - PR_FREEIF(outBuf); - } - break; - - case nsIAddbookUrlOperation::ImportCards: - case nsIAddbookUrlOperation::ImportMailingLists: - case nsIAddbookUrlOperation::ExportCards: - case nsIAddbookUrlOperation::AddToAddressBook: - case nsIAddbookUrlOperation::ExportTitle: - case nsIAddbookUrlOperation::ImportTitle: - case nsIAddbookUrlOperation::InvalidUrl: - default: - const char *eMsg = "Unsupported format/operation requested for \"addbook:\" URL."; - PRInt32 eSize = nsCRT::strlen(eMsg); - - rv = GenerateHTMLOutputChannel(eMsg, eSize, addbookUrl, aURI, _retval); - break; + errorString.AppendWithConversion(spec.get()); + rv = GenerateXMLOutputChannel(errorString, addbookUrl, aURI, _retval); + NS_ENSURE_SUCCESS(rv,rv); + return NS_OK; } - - return rv; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::OpenAB(char *aAbName, nsIAddrDatabase **aDatabase) -{ - if (!aDatabase) - return NS_ERROR_FAILURE; - - nsresult rv = NS_OK; - nsFileSpec* dbPath = nsnull; - - nsCOMPtr abSession = - do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv); - if(NS_SUCCEEDED(rv)) - abSession->GetUserProfileDirectory(&dbPath); - - if (dbPath) - { - if (!aAbName) - (*dbPath) += kPersonalAddressbook; - else - (*dbPath) += aAbName; - - nsCOMPtr addrDBFactory = - do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv); - - if (NS_SUCCEEDED(rv) && addrDBFactory) - rv = addrDBFactory->Open(dbPath, PR_TRUE, aDatabase, PR_TRUE); - - delete dbPath; - } - else - rv = NS_ERROR_FAILURE; - - return rv; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::AddIndividualUserAttribPair(nsString &aString, const char *aColumn, nsIAbCard *aCard) -{ - PRUnichar *aName = nsnull; - - if (NS_SUCCEEDED(aCard->GetCardValue(aColumn, &aName)) && (aName) && (*aName)) - { - aString.Append(NS_LITERAL_STRING("")); - - aString.Append(NS_LITERAL_STRING("")); - // RICHIE - Should really convert this to some string bundled thing? - aString.AppendWithConversion(aColumn); - aString.Append(NS_LITERAL_STRING("")); - - aString.Append(NS_LITERAL_STRING("")); - aString.Append(aName); - aString.Append(NS_LITERAL_STRING("")); - - aString.Append(NS_LITERAL_STRING("")); + + nsString output; + rv = GeneratePrintOutput(addbookUrl, output); + if (NS_FAILED(rv)) { + output.Assign(NS_LITERAL_STRING("failed to print. url=").get()); + nsXPIDLCString spec; + rv = aURI->GetSpec(getter_Copies(spec)); + NS_ENSURE_SUCCESS(rv,rv); + output.AppendWithConversion(spec.get()); } - + + rv = GenerateXMLOutputChannel(output, addbookUrl, aURI, _retval); + NS_ENSURE_SUCCESS(rv,rv); return NS_OK; } -NS_IMETHODIMP -nsAddbookProtocolHandler::FindPossibleAbName(nsIAbCard *aCard, - PRUnichar **retName) -{ - nsresult rv = NS_ERROR_FAILURE; - - nsCOMPtr dbaCard(do_QueryInterface(aCard, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - - NS_ASSERTION(0, "fix me, FindPossibleAbName"); - return rv; -} - -NS_IMETHODIMP +nsresult nsAddbookProtocolHandler::GeneratePrintOutput(nsIAddbookUrl *addbookUrl, - char **outBuf) + nsString &aOutput) { - nsresult rv = NS_OK; - nsString workBuffer; - nsIAddrDatabase *aDatabase = nsnull; - - if (!outBuf) - return NS_ERROR_OUT_OF_MEMORY; + NS_ENSURE_ARG_POINTER(addbookUrl); - // Get the address book entry - nsCOMPtr resource = nsnull; - nsCOMPtr directory = nsnull; - nsIAbCard *urlArgCard; - PRUnichar *workEmail = nsnull; - char *charEmail = nsnull; - PRUnichar *workAb = nsnull; - char *charAb = nsnull; - char *abFileName = nsnull; - - rv = NS_OK; - // Get the RDF service... - nsCOMPtr rdfService(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv)); - if (NS_FAILED(rv)) - goto EarlyExit; - - // Get the AB card that has all of the URL arguments - rv = addbookUrl->GetAbCard(&urlArgCard); - if (NS_FAILED(rv)) - goto EarlyExit; - - // Get the email of interest if this is for a specific email message - if (mAddbookOperation == nsIAddbookUrlOperation::PrintIndividual) - { - rv = urlArgCard->GetCardValue(kPriEmailColumn, &workEmail); - if ( (NS_FAILED(rv)) || (!workEmail) || (!*workEmail)) - goto EarlyExit; - - // Make it a char * - charEmail = ToNewCString(nsDependentString(workEmail)); - if (!charEmail) - goto EarlyExit; - } - - // Ok, we need to see if a particular address book was passed in on the - // URL string. If not, then we will use the default, but if there was one - // specified, we need to do a prefs lookup and get the file name of interest - // The pref format is: user_pref("ldap_2.servers.Richie.filename", "abook-1.mab"); - // - rv = FindPossibleAbName(urlArgCard, &workAb); - if ( (NS_SUCCEEDED(rv)) && (workAb) && (*workAb)) - { - // Make it a char * - charAb = ToNewCString(nsDependentString(workAb)); - if (!charAb) - goto EarlyExit; - - nsCOMPtr pPref(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv) || !pPref) - goto EarlyExit; - - nsCString prefId("ldap_2.servers."); - prefId.Append(charAb); - prefId.Append(".filename"); - - rv = pPref->CopyCharPref(prefId.get(), &abFileName); - if (NS_FAILED(rv)) - abFileName = nsnull; - } - - // Now, open the database...for now, make it the default - rv = OpenAB(abFileName, &aDatabase); - NS_ENSURE_SUCCESS(rv, rv); - - // RICHIE - this works for any address book...not sure why - rv = rdfService->GetResource(kPersonalAddressbookUri, getter_AddRefs(resource)); - if (NS_FAILED(rv)) - goto EarlyExit; - - // query interface - directory = do_QueryInterface(resource, &rv); - if (NS_FAILED(rv)) - goto EarlyExit; - - // Ok, this is the place where we need to generate output for either a single entry - // or the entire table... - // - if (mAddbookOperation == nsIAddbookUrlOperation::PrintIndividual) - rv = BuildSingleHTML(aDatabase, directory, charEmail, workBuffer); - else - rv = BuildAllHTML(aDatabase, directory, workBuffer); - - *outBuf = ToNewUTF8String(workBuffer); - -EarlyExit: - // Database is open...make sure to close it - if (aDatabase) - { - aDatabase->Close(PR_TRUE); - // aDatabase->RemoveListener(??? listeners are hanging...I think); - } - NS_IF_RELEASE(aDatabase); - - NS_IF_RELEASE(urlArgCard); - PR_FREEIF(charEmail); - PR_FREEIF(charAb); - PR_FREEIF(abFileName); - return rv; -} - -#define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst" - -NS_IMETHODIMP -nsAddbookProtocolHandler::BuildSingleHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory, - char *charEmail, nsString &workBuffer) -{ - PRUnichar *aName = nsnull; - nsCOMPtr workCard; - - if (NS_FAILED(InitPrintColumns())) - return NS_ERROR_FAILURE; - - nsresult rv = aDatabase->GetCardFromAttribute(directory, kPriEmailColumn, charEmail, PR_TRUE /* caseInsensitive */, getter_AddRefs(workCard)); - NS_ENSURE_SUCCESS(rv, rv); - if (!workCard) - return NS_ERROR_FAILURE; - - // Ok, build a little HTML for output... - workBuffer.Append(NS_LITERAL_STRING("")); - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(NS_LITERAL_STRING("")); - - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr prefBranch; - rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - NS_ENSURE_SUCCESS(rv,rv); - - PRInt32 format; - rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &format); + nsXPIDLCString pathStr; + nsresult rv = addbookUrl->GetPath(getter_Copies(pathStr)); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv); + nsCOMPtr rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv); + NS_ENSURE_SUCCESS(rv,rv); + + /* turn + "//moz-abmdbdirectory/abook.mab?action=print" + into "moz-abmdbdirectory://abook.mab" + */ + nsCAutoString uri; + uri.Assign(pathStr.get()); + + /* step 1: + turn "//moz-abmdbdirectory/abook.mab?action=print" + into "moz-abmdbdirectory/abook.mab?action=print" + */ + if (uri[0] != '/' && uri[1] != '/') + return NS_ERROR_UNEXPECTED; + + uri.Cut(0,2); + + /* step 2: + turn "moz-abmdbdirectory/abook.mab?action=print" + into "moz-abmdbdirectory/abook.mab" + */ + PRInt32 pos = uri.Find("?action=print"); + if (pos == kNotFound) + return NS_ERROR_UNEXPECTED; + + uri.Truncate(pos); + + /* step 2: + turn "moz-abmdbdirectory/abook.mab" + into "moz-abmdbdirectory://abook.mab" + */ + pos = uri.Find("/"); + if (pos == kNotFound) + return NS_ERROR_UNEXPECTED; + + uri.InsertWithConversion(PRUnichar('/'), pos); + uri.InsertWithConversion(PRUnichar(':'), pos); + + nsCOMPtr resource; + rv = rdfService->GetResource(uri.get(), getter_AddRefs(resource)); NS_ENSURE_SUCCESS(rv,rv); - if (NS_SUCCEEDED(abSession->GenerateNameFromCard(workCard, format, &aName)) && (aName)) - { - workBuffer.Append(NS_LITERAL_STRING("")); - } + nsCOMPtr directory = do_QueryInterface(resource, &rv); + NS_ENSURE_SUCCESS(rv,rv); - for (PRInt32 i=0; i")); - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(NS_LITERAL_STRING("")); - return rv; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::BuildAllHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory, - nsString &workBuffer) -{ - nsresult rv = NS_OK; - - if (NS_FAILED(InitPrintColumns())) - return NS_ERROR_FAILURE; - - nsIEnumerator *cardEnum = nsnull; - rv = aDatabase->EnumerateCards(directory, &cardEnum); - NS_ENSURE_SUCCESS(rv, rv); - if (!cardEnum) - return NS_ERROR_FAILURE; - - InitPrintColumns(); - - // Ok, we make 2 passes at this enumerator. The first is to - // check the columns that we should output and the second is - // to actually generate the output - // - nsCOMPtr obj = nsnull; - cardEnum->First(); - do - { - if (NS_FAILED(cardEnum->CurrentItem(getter_AddRefs(obj)))) - break; - else - { - nsCOMPtr card; - card = do_QueryInterface(obj, &rv); - if ( NS_SUCCEEDED(rv) && (card) ) - { - CheckColumnValidity(card); - } - } - - } while (NS_SUCCEEDED(cardEnum->Next())); - - // Now, we need to generate some fun output! - // - // Ok, build a little HTML for output... - workBuffer.Append(NS_LITERAL_STRING("")); - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(aName); - workBuffer.Append(NS_LITERAL_STRING("
")); - - GenerateColumnHeadings(workBuffer); - - cardEnum->First(); - do - { - if (NS_FAILED(cardEnum->CurrentItem(getter_AddRefs(obj)))) - break; - else - { - nsCOMPtr card; - card = do_QueryInterface(obj, &rv); - if ( NS_SUCCEEDED(rv) && (card) ) - { - GenerateRowForCard(workBuffer, card); - } - } - - } while (NS_SUCCEEDED(cardEnum->Next())); - - delete cardEnum; - - // Finish up and get out! - // - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(NS_LITERAL_STRING("
")); - workBuffer.Append(NS_LITERAL_STRING("")); - return rv; -} - -PRBool -ValidColumn(nsIAbCard *aCard, const char *aColumn) -{ - PRUnichar *aName = nsnull; - - if (NS_SUCCEEDED(aCard->GetCardValue(aColumn, &aName)) && (aName) && (*aName)) - return PR_TRUE; - else - return PR_FALSE; + return NS_OK; } nsresult -TackOnColumn(nsIAbCard *aCard, const char *aColumn, nsString &aString) +nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory, + nsString &aOutput) { - PRUnichar *aName = nsnull; + NS_ENSURE_ARG_POINTER(aDirectory); - aString.Append(NS_LITERAL_STRING("")); + nsresult rv; + nsCOMPtr cardsEnumerator; + nsCOMPtr card; - if (NS_SUCCEEDED(aCard->GetCardValue(aColumn, &aName)) && (aName) && (*aName)) + aOutput.Append(NS_LITERAL_STRING("\n").get()); + aOutput.Append(NS_LITERAL_STRING("\n").get()); + aOutput.Append(NS_LITERAL_STRING("\n").get()); + + rv = aDirectory->GetChildCards(getter_AddRefs(cardsEnumerator)); + if (NS_SUCCEEDED(rv) && cardsEnumerator) { - aString.Append(aName); - } - - aString.Append(NS_LITERAL_STRING("")); - return NS_OK; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::CheckColumnValidity(nsIAbCard *aCard) -{ - for (PRInt32 i=0; i")); - - for (PRInt32 i=0; i item; + for (rv = cardsEnumerator->First(); NS_SUCCEEDED(rv); rv = cardsEnumerator->Next()) { - aString.Append(NS_LITERAL_STRING("")); - aString.Append(NS_LITERAL_STRING("")); - // RICHIE - Should really convert this to some string bundled thing? - aString.AppendWithConversion(mReportColumns[i].abField); - aString.Append(NS_LITERAL_STRING("")); - aString.Append(NS_LITERAL_STRING("")); + rv = cardsEnumerator->CurrentItem(getter_AddRefs(item)); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr card = do_QueryInterface(item); + nsXPIDLString xmlSubstr; + + rv = card->ConvertToXMLData(getter_Copies(xmlSubstr)); + NS_ENSURE_SUCCESS(rv,rv); + + aOutput.Append(xmlSubstr.get()); + } } } - aString.Append(NS_LITERAL_STRING("")); - return NS_OK; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::GenerateRowForCard(nsString &aString, - nsIAbCard *aCard) -{ - aString.Append(NS_LITERAL_STRING("")); - - for (PRInt32 i=0; i")); - return NS_OK; -} - -NS_IMETHODIMP -nsAddbookProtocolHandler::InitPrintColumns() -{ - if (!mReportColumns) - { - mReportColumns = (reportColumnStruct *) PR_Malloc(sizeof(reportColumnStruct) * kMaxReportColumns); - if (mReportColumns == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - mReportColumns[0].abField = kFirstNameColumn; - mReportColumns[1].abField = kLastNameColumn; - mReportColumns[2].abField = kDisplayNameColumn; - mReportColumns[3].abField = kNicknameColumn; - mReportColumns[4].abField = kPriEmailColumn; - mReportColumns[5].abField = k2ndEmailColumn; - mReportColumns[6].abField = kPreferMailFormatColumn; - mReportColumns[7].abField = kWorkPhoneColumn; - mReportColumns[8].abField = kHomePhoneColumn; - mReportColumns[9].abField = kFaxColumn; - mReportColumns[10].abField = kPagerColumn; - mReportColumns[11].abField = kCellularColumn; - mReportColumns[12].abField = kHomeAddressColumn; - mReportColumns[13].abField = kHomeAddress2Column; - mReportColumns[14].abField = kHomeCityColumn; - mReportColumns[15].abField = kHomeStateColumn; - mReportColumns[16].abField = kHomeZipCodeColumn; - mReportColumns[17].abField = kHomeCountryColumn; - mReportColumns[18].abField = kWorkAddressColumn; - mReportColumns[19].abField = kWorkAddress2Column; - mReportColumns[20].abField = kWorkCityColumn; - mReportColumns[21].abField = kWorkStateColumn; - mReportColumns[22].abField = kWorkZipCodeColumn; - mReportColumns[23].abField = kWorkCountryColumn; - mReportColumns[24].abField = kJobTitleColumn; - mReportColumns[25].abField = kDepartmentColumn; - mReportColumns[26].abField = kCompanyColumn; - mReportColumns[27].abField = kWebPage1Column; - mReportColumns[28].abField = kWebPage2Column; - mReportColumns[29].abField = kBirthYearColumn; - mReportColumns[30].abField = kBirthMonthColumn; - mReportColumns[31].abField = kBirthDayColumn; - mReportColumns[32].abField = kCustom1Column; - mReportColumns[33].abField = kCustom2Column; - mReportColumns[34].abField = kCustom3Column; - mReportColumns[35].abField = kCustom4Column; - mReportColumns[36].abField = kNotesColumn; - mReportColumns[37].abField = kLastModifiedDateColumn; - mReportColumns[38].abField = nsnull; - } - - for (PRInt32 i=0; i\n").get()); return NS_OK; } diff --git a/mailnews/addrbook/src/nsAddbookProtocolHandler.h b/mailnews/addrbook/src/nsAddbookProtocolHandler.h index 821bcecd850..1cdec62ff02 100644 --- a/mailnews/addrbook/src/nsAddbookProtocolHandler.h +++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.h @@ -46,13 +46,6 @@ #include "nsIAddbookUrl.h" #include "nsIAddrDatabase.h" -typedef struct { - const char *abField; - PRBool includeIt; -} reportColumnStruct; - -#define kMaxReportColumns 39 - class nsAddbookProtocolHandler : public nsIProtocolHandler { public: @@ -67,37 +60,18 @@ public: NS_DECL_NSIPROTOCOLHANDLER private: - // Output Generation calls to create the HTML output - NS_METHOD GenerateHTMLOutputChannel(const char *aHtmlOutput, - PRInt32 aHtmlOutputSize, + nsresult GenerateXMLOutputChannel(nsString &aOutput, nsIAddbookUrl *addbookUrl, nsIURI *aURI, nsIChannel **_retval); - NS_METHOD GeneratePrintOutput(nsIAddbookUrl *addbookUrl, - char **outBuf); - NS_METHOD BuildSingleHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory, - char *charEmail, nsString &workBuffer); + nsresult GeneratePrintOutput(nsIAddbookUrl *addbookUrl, + nsString &aOutput); - NS_METHOD BuildAllHTML(nsIAddrDatabase *aDatabase, nsIAbDirectory *directory, - nsString &workBuffer); + nsresult BuildDirectoryXML(nsIAbDirectory *aDirectory, + nsString &aOutput); - NS_METHOD AddIndividualUserAttribPair(nsString &aString, const char *aColumn, nsIAbCard *workCard); - - // Database access calls... - NS_METHOD OpenAB(char *aAbName, nsIAddrDatabase **aDatabase); - NS_METHOD FindPossibleAbName(nsIAbCard *aCard, - PRUnichar **retName); - - NS_METHOD CheckColumnValidity(nsIAbCard *aCard); - NS_METHOD GenerateRowForCard(nsString &aString, - nsIAbCard *aCard); - NS_METHOD GenerateColumnHeadings(nsString &aString); - NS_METHOD InitPrintColumns(); - - // Member vars... - PRInt32 mAddbookOperation; - reportColumnStruct *mReportColumns; + PRInt32 mAddbookOperation; }; #endif /* nsAddbookProtocolHandler_h___ */ diff --git a/mailnews/addrbook/src/nsAddbookUrl.cpp b/mailnews/addrbook/src/nsAddbookUrl.cpp index fb097182268..765e7baa94e 100644 --- a/mailnews/addrbook/src/nsAddbookUrl.cpp +++ b/mailnews/addrbook/src/nsAddbookUrl.cpp @@ -43,8 +43,6 @@ #include "nsAbBaseCID.h" #include "nsEscape.h" -const char *kWorkAddressBook = "AddbookWorkAddressBook"; - ///////////////////////////////////////////////////////////////////////////////////// // addbook url definition ///////////////////////////////////////////////////////////////////////////////////// @@ -53,7 +51,6 @@ nsAddbookUrl::nsAddbookUrl() NS_INIT_ISUPPORTS(); m_baseURL = do_CreateInstance(NS_SIMPLEURI_CONTRACTID); - mAbCardProperty = do_CreateInstance(NS_ABCARDPROPERTY_CONTRACTID); mOperationType = nsIAddbookUrlOperation::InvalidUrl; } @@ -62,91 +59,7 @@ nsAddbookUrl::~nsAddbookUrl() { } -NS_IMPL_ISUPPORTS1(nsAddbookUrl, nsIURI) - -// -// This will do the parsing for a single address book entry print operation. -// In this case, you will have address book folder and email: -// -// addbook:add?vcard=begin%3Avcard%0Afn%3ARichard%20Pizzarro%0Aemail%3Binternet%3Arhp%40netscape.com%0Aend%3Avcard%0A -// -NS_IMETHODIMP -nsAddbookUrl::CrackAddURL(const char *searchPart) -{ - return NS_OK; -} - -// -// This will do the parsing for a single address book entry print operation. -// In this case, you will have address book folder and email: -// -// addbook:printall?folder=Netscape%20Address%20Book -// addbook:printall?email=rhp@netscape.com&folder=Netscape%20Address%20Book -// -NS_IMETHODIMP -nsAddbookUrl::CrackPrintURL(const char *searchPart, PRInt32 aOperation) -{ - nsCString emailAddr; - nsCString folderName; - - char *rest = NS_CONST_CAST(char*, searchPart); - - // okay, first, free up all of our old search part state..... - CleanupAddbookState(); - - // Start past the '?'... - if (rest && *rest == '?') - rest++; - - if (rest) - { - char *token = nsCRT::strtok(rest, "&", &rest); - while (token && *token) - { - char *value = 0; - char *eq = PL_strchr(token, '='); - if (eq) - { - value = eq+1; - *eq = 0; - } - - switch (nsCRT::ToUpper(*token)) - { - case 'E': - if (!nsCRT::strcasecmp (token, "email")) - emailAddr = value; - break; - case 'F': - if (!nsCRT::strcasecmp (token, "folder")) - folderName = value; - break; - } // end of switch statement... - - if (eq) - *eq = '='; // put it back - token = nsCRT::strtok(rest, "&", &rest); - } // while we still have part of the url to parse... - } // if rest && *rest - - // Now unescape any fields that need escaped... - if (emailAddr.IsEmpty() && (aOperation == nsIAddbookUrlOperation::PrintIndividual)) - return NS_ERROR_FAILURE; - - if (!emailAddr.IsEmpty()) - { - nsUnescape(NS_CONST_CAST(char*, emailAddr.get())); - mAbCardProperty->SetCardValue(kPriEmailColumn, NS_ConvertASCIItoUCS2(emailAddr).get()); - } - - if (!folderName.IsEmpty()) - { - nsUnescape(NS_CONST_CAST(char*, folderName.get())); - mAbCardProperty->SetCardValue(kWorkAddressBook, NS_ConvertASCIItoUCS2(folderName).get()); - } - - return NS_OK; -} +NS_IMPL_ISUPPORTS2(nsAddbookUrl, nsIAddbookUrl, nsIURI) NS_IMETHODIMP nsAddbookUrl::SetSpec(const char * aSpec) @@ -155,105 +68,19 @@ nsAddbookUrl::SetSpec(const char * aSpec) return ParseUrl(); } -nsresult nsAddbookUrl::CleanupAddbookState() -{ - PRUnichar *tString = nsnull; - - mAbCardProperty->SetCardValue(kFirstNameColumn, tString); - mAbCardProperty->SetCardValue(kLastNameColumn, tString); - mAbCardProperty->SetCardValue(kDisplayNameColumn, tString); - mAbCardProperty->SetCardValue(kNicknameColumn, tString); - mAbCardProperty->SetCardValue(kPriEmailColumn, tString); - mAbCardProperty->SetCardValue(k2ndEmailColumn, tString); - mAbCardProperty->SetCardValue(kPreferMailFormatColumn, tString); - mAbCardProperty->SetCardValue(kWorkPhoneColumn, tString); - mAbCardProperty->SetCardValue(kHomePhoneColumn, tString); - mAbCardProperty->SetCardValue(kFaxColumn, tString); - mAbCardProperty->SetCardValue(kPagerColumn, tString); - mAbCardProperty->SetCardValue(kCellularColumn, tString); - mAbCardProperty->SetCardValue(kHomeAddressColumn, tString); - mAbCardProperty->SetCardValue(kHomeAddress2Column, tString); - mAbCardProperty->SetCardValue(kHomeCityColumn, tString); - mAbCardProperty->SetCardValue(kHomeStateColumn, tString); - mAbCardProperty->SetCardValue(kHomeZipCodeColumn, tString); - mAbCardProperty->SetCardValue(kHomeCountryColumn, tString); - mAbCardProperty->SetCardValue(kWorkAddressColumn, tString); - mAbCardProperty->SetCardValue(kWorkAddress2Column, tString); - mAbCardProperty->SetCardValue(kWorkCityColumn, tString); - mAbCardProperty->SetCardValue(kWorkStateColumn, tString); - mAbCardProperty->SetCardValue(kWorkZipCodeColumn, tString); - mAbCardProperty->SetCardValue(kWorkCountryColumn, tString); - mAbCardProperty->SetCardValue(kJobTitleColumn, tString); - mAbCardProperty->SetCardValue(kDepartmentColumn, tString); - mAbCardProperty->SetCardValue(kCompanyColumn, tString); - mAbCardProperty->SetCardValue(kWebPage1Column, tString); - mAbCardProperty->SetCardValue(kWebPage2Column, tString); - mAbCardProperty->SetCardValue(kBirthYearColumn, tString); - mAbCardProperty->SetCardValue(kBirthMonthColumn, tString); - mAbCardProperty->SetCardValue(kBirthDayColumn, tString); - mAbCardProperty->SetCardValue(kCustom1Column, tString); - mAbCardProperty->SetCardValue(kCustom2Column, tString); - mAbCardProperty->SetCardValue(kCustom3Column, tString); - mAbCardProperty->SetCardValue(kCustom4Column, tString); - mAbCardProperty->SetCardValue(kNotesColumn, tString); - mAbCardProperty->SetCardValue(kLastModifiedDateColumn, tString); - return NS_OK; -} - nsresult nsAddbookUrl::ParseUrl() { - nsresult rv = NS_OK; - nsCAutoString searchPart; + nsresult rv; - // we can get the path from the simple url..... - nsXPIDLCString aPath; - m_baseURL->GetPath(getter_Copies(aPath)); - if (aPath) - mOperationPart.Assign(aPath); + nsXPIDLCString pathStr; + rv = m_baseURL->GetPath(getter_Copies(pathStr)); + NS_ENSURE_SUCCESS(rv,rv); - PRInt32 startOfSearchPart = mOperationPart.FindChar('?'); - if (startOfSearchPart > 0) - { - // now parse out the search field... - PRUint32 numExtraChars = mOperationPart.Right(searchPart, - mOperationPart.Length() - - startOfSearchPart); - if (!searchPart.IsEmpty()) - { - // now we need to strip off the search part from the - // to part.... - mOperationPart.Cut(startOfSearchPart, numExtraChars); - } - } - else if (!mOperationPart.IsEmpty()) - { - nsUnescape(NS_CONST_CAST(char*, mOperationPart.get())); - } - - ToLowerCase(mOperationPart); - // Now, figure out what we are supposed to be doing? - if (!nsCRT::strcmp(mOperationPart.get(), "printone")) - { - mOperationType = nsIAddbookUrlOperation::PrintIndividual; - rv = CrackPrintURL(searchPart.get(), mOperationType); - } - else if (!nsCRT::strcmp(mOperationPart.get(), "printall")) - { + if (PL_strstr(pathStr.get(), "?action=print")) mOperationType = nsIAddbookUrlOperation::PrintAddressBook; - rv = CrackPrintURL(searchPart.get(), mOperationType); - } - else if (!nsCRT::strcmp(mOperationPart.get(), "add")) - { - mOperationType = nsIAddbookUrlOperation::AddToAddressBook; - rv = CrackAddURL(searchPart.get()); - } else mOperationType = nsIAddbookUrlOperation::InvalidUrl; - - if (NS_FAILED(rv)) - mOperationType = nsIAddbookUrlOperation::InvalidUrl; - - return rv; + return NS_OK; } //////////////////////////////////////////////////////////////////////////////////// @@ -375,18 +202,3 @@ nsAddbookUrl::GetAddbookOperation(PRInt32 *_retval) *_retval = mOperationType; return NS_OK; } - -NS_IMETHODIMP -nsAddbookUrl::GetAbCard(nsIAbCard **aAbCard) -{ - if (!mAbCardProperty) - return NS_ERROR_FAILURE; - - nsCOMPtr tCard = do_QueryInterface(mAbCardProperty); - if (!tCard) - return NS_ERROR_FAILURE; - - *aAbCard = tCard; - NS_ADDREF(*aAbCard); - return NS_OK; -} diff --git a/mailnews/addrbook/src/nsAddbookUrl.h b/mailnews/addrbook/src/nsAddbookUrl.h index e7a5c196b67..191d493bf71 100644 --- a/mailnews/addrbook/src/nsAddbookUrl.h +++ b/mailnews/addrbook/src/nsAddbookUrl.h @@ -38,15 +38,9 @@ #ifndef nsAddbookUrl_h__ #define nsAddbookUrl_h__ -#include "nsISmtpUrl.h" #include "nsIURI.h" -#include "nsIFileSpec.h" -#include "nsIMsgIdentity.h" #include "nsCOMPtr.h" -#include "nsISmtpServer.h" #include "nsIAddbookUrl.h" -#include "nsAbCardProperty.h" -#include "nsIAbCard.h" class nsAddbookUrl : public nsIAddbookUrl { @@ -59,20 +53,10 @@ public: virtual ~nsAddbookUrl(); protected: - nsresult CleanupAddbookState(); - - nsresult ParseUrl(); // This gets the ball rolling... - - NS_METHOD CrackAddURL(const char *searchPart); - NS_METHOD CrackPrintURL(const char *searchPart, PRInt32 aOperation); - NS_METHOD GetAbCardProperty(nsAbCardProperty **aAbCardProp); - - nsCString mOperationPart; // string name of operation requested + nsresult ParseUrl(); PRInt32 mOperationType; // the internal ID for the operation nsCOMPtr m_baseURL; // the base URL for the object - nsCOMPtr mAbCardProperty; // Hold all parsed user info here - }; #endif // nsAddbookUrl_h__ diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 1df65478bff..9ebcf132c90 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -247,33 +247,6 @@ nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, } -NS_IMETHODIMP nsAddressBook::PrintCard() -{ - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr viewer; - - if (!mDocShell) { - return NS_ERROR_FAILURE; - } - - mDocShell->GetContentViewer(getter_AddRefs(viewer)); - - if (viewer) - { - nsCOMPtr viewerFile = do_QueryInterface(viewer); - if (viewerFile) { - rv = viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); - } - } - - return rv; -} - -NS_IMETHODIMP nsAddressBook::PrintAddressbook() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsAddressBook::SetDocShellWindow(nsIDOMWindowInternal *aWin) { NS_PRECONDITION(aWin != nsnull, "null ptr"); diff --git a/mailnews/base/resources/content/msgPrintEngine.js b/mailnews/base/resources/content/msgPrintEngine.js index 418a664cce4..f945c2bbeb6 100644 --- a/mailnews/base/resources/content/msgPrintEngine.js +++ b/mailnews/base/resources/content/msgPrintEngine.js @@ -87,6 +87,10 @@ function StopUrls() function PrintEnginePrint() { + // XXX fix me + // instead of moving this offscreen (which doesn't work) + // and the user can close it from the task bar + // we should hide the window var left = screen.width + 50; var top = screen.height + 50; printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", diff --git a/mailnews/base/src/nsMsgPrintEngine.cpp b/mailnews/base/src/nsMsgPrintEngine.cpp index f8342182574..cf34c92c176 100644 --- a/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mailnews/base/src/nsMsgPrintEngine.cpp @@ -256,7 +256,7 @@ NS_IMETHODIMP nsMsgPrintEngine::StartPrintOperation() { // Load the about:blank on the tail end... - nsresult rv = AddPrintURI((const PRUnichar*)NS_LITERAL_STRING("about:blank").get()); + nsresult rv = AddPrintURI(NS_LITERAL_STRING("about:blank").get()); if (NS_FAILED(rv)) return rv; return StartNextPrintOperation(); } @@ -304,18 +304,37 @@ nsMsgPrintEngine::SetStatusFeedback(nsIMsgStatusFeedback *aFeedback) return NS_OK; } +#define DATA_URL_PREFIX "data:" +#define DATA_URL_PREFIX_LEN 5 + +#define ADDBOOK_URL_PREFIX "addbook:" +#define ADDBOOK_URL_PREFIX_LEN 8 + NS_IMETHODIMP nsMsgPrintEngine::FireThatLoadOperation(nsString *uri) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; char *tString = ToNewCString(*uri); if (!tString) return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr messageService; - rv = GetMessageServiceFromURI(tString, getter_AddRefs(messageService)); - + + // if this is a data: url, skip it, because + // we've already got something we can print + // and we know it is not a message. + // + // if this an about:blank url, skip it, because + // + // if this is an addbook: url, skip it, because + // we know that isn't a message. + if (PL_strncmp(tString, DATA_URL_PREFIX, DATA_URL_PREFIX_LEN) && + PL_strncmp(tString, ADDBOOK_URL_PREFIX, ADDBOOK_URL_PREFIX_LEN) && + PL_strcmp(tString, "about:blank")) { + rv = GetMessageServiceFromURI(tString, getter_AddRefs(messageService)); + } + if (NS_SUCCEEDED(rv) && messageService) { nsCOMPtr webShell(do_QueryInterface(mDocShell)); diff --git a/mailnews/base/util/nsMsgMailNewsUrl.cpp b/mailnews/base/util/nsMsgMailNewsUrl.cpp index 7efcbc0cb56..343e374689b 100644 --- a/mailnews/base/util/nsMsgMailNewsUrl.cpp +++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp @@ -710,3 +710,4 @@ NS_IMETHODIMP nsMsgMailNewsUrl:: GetMemCacheEntry(nsICacheEntryDescriptor **memC return rv; } + diff --git a/mailnews/base/util/nsMsgUtils.cpp b/mailnews/base/util/nsMsgUtils.cpp index 014962ad0f2..a3d7602756a 100644 --- a/mailnews/base/util/nsMsgUtils.cpp +++ b/mailnews/base/util/nsMsgUtils.cpp @@ -82,18 +82,16 @@ nsresult GetMessageServiceContractIDForURI(const char *uri, nsCString &contractI nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **aMessageService) { - - nsCAutoString contractID; nsresult rv; + nsCAutoString contractID; rv = GetMessageServiceContractIDForURI(uri, contractID); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr msgService = do_GetService(contractID.get(), &rv); NS_ENSURE_SUCCESS(rv,rv); - *aMessageService = msgService; - NS_IF_ADDREF(*aMessageService); + NS_IF_ADDREF(*aMessageService = msgService); return rv; } diff --git a/mailnews/jar.mn b/mailnews/jar.mn index 9acba1bad3a..e153338bef7 100644 --- a/mailnews/jar.mn +++ b/mailnews/jar.mn @@ -30,6 +30,7 @@ messenger.jar: content/messenger/addressbook/abEditListDialog.xul (addrbook/resources/content/abEditListDialog.xul) content/messenger/addressbook/addressbook-panel.xul (addrbook/resources/content/addressbook-panel.xul) content/messenger/addressbook/addressbook-panel.js (addrbook/resources/content/addressbook-panel.js) + content/messenger/addressbook/print.css (addrbook/resources/content/print.css) content/messenger/AccountManager.xul (base/prefs/resources/content/AccountManager.xul) content/messenger/AccountManager.js (base/prefs/resources/content/AccountManager.js) content/messenger/am-main.xul (base/prefs/resources/content/am-main.xul)