Back to index

lightning-sunbird  0.9+nobinonly
nsAbCardProperty.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsAbCardProperty.h"       
00041 #include "nsIServiceManager.h"
00042 #include "nsXPIDLString.h"
00043 #include "nsAbBaseCID.h"
00044 #include "nsCOMPtr.h"
00045 #include "nsReadableUtils.h"
00046 #include "nsUnicharUtils.h"
00047 #include "nsIPrefService.h"
00048 #include "nsIPrefBranch.h"
00049 #include "nsIAbDirectory.h"
00050 #include "plbase64.h"
00051 #include "nsIAddrBookSession.h"
00052 #include "nsIStringBundle.h"
00053 
00054 #include "nsIRDFResource.h"
00055 #include "nsIRDFService.h"
00056 #include "nsRDFCID.h"
00057 
00058 #include "nsEscape.h"
00059 #include "nsVCardObj.h"
00060 
00061 #include "mozITXTToHTMLConv.h"
00062 
00063 #define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst"
00064 
00065 const char sAddrbookProperties[] = "chrome://messenger/locale/addressbook/addressBook.properties";
00066 
00067 struct AppendItem;
00068 
00069 typedef nsresult (AppendCallback) (nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult);
00070 
00071 struct AppendItem {
00072   const char *mColumn;
00073   const char *mLabel;
00074   AppendCallback *mCallback;
00075 };
00076 
00077 nsresult AppendLine(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult);
00078 nsresult AppendLabel(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult);
00079 nsresult AppendCityStateZip(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult);
00080 
00081 static AppendItem NAME_ATTRS_ARRAY[] = { 
00082        {kDisplayNameColumn, "propertyDisplayName", AppendLabel},   
00083        {kNicknameColumn, "propertyNickname", AppendLabel},
00084        {kPriEmailColumn, "", AppendLine},       
00085        {k2ndEmailColumn, "", AppendLine},
00086   {kAimScreenNameColumn, "propertyScreenName", AppendLabel},
00087 };
00088 
00089 static AppendItem PHONE_ATTRS_ARRAY[] = { 
00090        {kWorkPhoneColumn, "propertyWork", AppendLabel},   
00091        {kHomePhoneColumn, "propertyHome", AppendLabel},
00092        {kFaxColumn, "propertyFax", AppendLabel},       
00093        {kPagerColumn, "propertyPager", AppendLabel},
00094        {kCellularColumn, "propertyCellular", AppendLabel}
00095 };
00096 
00097 static AppendItem HOME_ATTRS_ARRAY[] = { 
00098        {kHomeAddressColumn, "", AppendLine},   
00099        {kHomeAddress2Column, "", AppendLine},
00100        {kHomeCityColumn, "", AppendCityStateZip},       
00101        {kHomeCountryColumn, "", AppendLine},
00102        {kWebPage2Column, "", AppendLine}
00103 };
00104 
00105 static AppendItem WORK_ATTRS_ARRAY[] = { 
00106        {kJobTitleColumn, "", AppendLine},   
00107        {kDepartmentColumn, "", AppendLine},
00108        {kCompanyColumn, "", AppendLine},
00109        {kWorkAddressColumn, "", AppendLine},   
00110        {kWorkAddress2Column, "", AppendLine},
00111        {kWorkCityColumn, "", AppendCityStateZip},       
00112        {kWorkCountryColumn, "", AppendLine},
00113        {kWebPage1Column, "", AppendLine}
00114 };
00115 
00116 static AppendItem CUSTOM_ATTRS_ARRAY[] = { 
00117        {kCustom1Column, "propertyCustom1", AppendLabel},   
00118        {kCustom2Column, "propertyCustom2", AppendLabel},
00119        {kCustom3Column, "propertyCustom3", AppendLabel},       
00120        {kCustom4Column, "propertyCustom4", AppendLabel},
00121        {kNotesColumn, "", AppendLine}
00122 };
00123 
00124 nsAbCardProperty::nsAbCardProperty(void)
00125 {
00126   m_LastModDate = 0;
00127 
00128   m_PreferMailFormat = nsIAbPreferMailFormat::unknown;
00129   m_PopularityIndex = 0;
00130   m_AllowRemoteContent = PR_FALSE;
00131   m_IsMailList = PR_FALSE;
00132 }
00133 
00134 nsAbCardProperty::~nsAbCardProperty(void)
00135 {
00136 }
00137 
00138 NS_IMPL_ISUPPORTS1(nsAbCardProperty, nsIAbCard)
00139 
00140 
00141 
00142 nsresult nsAbCardProperty::GetCardTypeFromString(const char *aCardTypeStr, PRBool aEmptyIsTrue, PRBool *aValue)
00143 {
00144   NS_ENSURE_ARG_POINTER(aCardTypeStr);
00145   NS_ENSURE_ARG_POINTER(aValue);
00146 
00147   *aValue = PR_FALSE;
00148   nsXPIDLString cardType;
00149   nsresult rv = GetCardType(getter_Copies(cardType));
00150   NS_ENSURE_SUCCESS(rv,rv);
00151 
00152   *aValue = ((aEmptyIsTrue && cardType.IsEmpty()) || cardType.Equals(NS_ConvertASCIItoUCS2(aCardTypeStr)));
00153   return NS_OK;
00154 }
00155 
00156 NS_IMETHODIMP nsAbCardProperty::GetIsANormalCard(PRBool *aIsNormal)
00157 {
00158   return GetCardTypeFromString(AB_CARD_IS_NORMAL_CARD, PR_TRUE, aIsNormal);
00159 }
00160 
00161 NS_IMETHODIMP nsAbCardProperty::GetIsASpecialGroup(PRBool *aIsSpecailGroup)
00162 {
00163   return GetCardTypeFromString(AB_CARD_IS_AOL_GROUPS, PR_FALSE, aIsSpecailGroup);
00164 }
00165 
00166 NS_IMETHODIMP nsAbCardProperty::GetIsAnEmailAddress(PRBool *aIsEmailAddress)
00167 {
00168   return GetCardTypeFromString(AB_CARD_IS_AOL_ADDITIONAL_EMAIL, PR_FALSE, aIsEmailAddress);
00169 }
00170 
00171 nsresult nsAbCardProperty::GetAttributeName(PRUnichar **aName, nsString& value)
00172 {
00173   NS_ENSURE_ARG_POINTER(aName);
00174   *aName = ToNewUnicode(value);
00175   return (*aName) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00176 }
00177 
00178 nsresult nsAbCardProperty::SetAttributeName(const PRUnichar *aName, nsString& attribute)
00179 {
00180   if (aName)
00181     attribute = aName;
00182   return NS_OK;
00183 }
00184 
00185 NS_IMETHODIMP nsAbCardProperty::GetPopularityIndex(PRUint32 *aPopularityIndex)
00186 {
00187   *aPopularityIndex = m_PopularityIndex;
00188   return NS_OK;
00189 }
00190 
00191 NS_IMETHODIMP nsAbCardProperty::SetPopularityIndex(PRUint32 aPopularityIndex)
00192 {
00193   m_PopularityIndex = aPopularityIndex;
00194   return NS_OK;
00195 }
00196 
00197 NS_IMETHODIMP nsAbCardProperty::GetAllowRemoteContent(PRBool *aAllowRemoteContent)
00198 {
00199   *aAllowRemoteContent = m_AllowRemoteContent;
00200   return NS_OK;
00201 }
00202 
00203 NS_IMETHODIMP nsAbCardProperty::SetAllowRemoteContent(PRBool aAllowRemoteContent)
00204 {
00205   m_AllowRemoteContent = aAllowRemoteContent;
00206   return NS_OK;
00207 }
00208 
00209 NS_IMETHODIMP nsAbCardProperty::GetPreferMailFormat(PRUint32 *aFormat)
00210 {
00211   *aFormat = m_PreferMailFormat;   
00212   return NS_OK;
00213 }
00214 
00215 NS_IMETHODIMP nsAbCardProperty::SetPreferMailFormat(PRUint32 aFormat)
00216 {
00217   m_PreferMailFormat = aFormat;
00218   return NS_OK;
00219 }
00220 
00221 NS_IMETHODIMP nsAbCardProperty::GetIsMailList(PRBool *aIsMailList)
00222 {
00223     *aIsMailList = m_IsMailList;
00224     return NS_OK;
00225 }
00226 
00227 NS_IMETHODIMP nsAbCardProperty::SetIsMailList(PRBool aIsMailList)
00228 {
00229     m_IsMailList = aIsMailList;
00230     return NS_OK;
00231 }
00232 
00233 NS_IMETHODIMP nsAbCardProperty::GetMailListURI(char **aMailListURI)
00234 {
00235   if (aMailListURI)
00236   {
00237     *aMailListURI = ToNewCString(m_MailListURI);
00238     return (*aMailListURI) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00239   }
00240   else
00241     return NS_ERROR_NULL_POINTER;
00242 }
00243 
00244 NS_IMETHODIMP nsAbCardProperty::SetMailListURI(const char *aMailListURI)
00245 {
00246   if (aMailListURI)
00247   {
00248     m_MailListURI = aMailListURI;
00249     return NS_OK;
00250   }
00251   else
00252     return NS_ERROR_NULL_POINTER;
00253 }
00254 
00255 NS_IMETHODIMP nsAbCardProperty::GetCardValue(const char *attrname, PRUnichar **value)
00256 {
00257   NS_ENSURE_ARG_POINTER(attrname);
00258   NS_ENSURE_ARG_POINTER(value);
00259 
00260   nsresult rv = NS_OK;
00261 
00262   switch (attrname[0]) {
00263     case '_': // _AimScreenName
00264       rv = GetAimScreenName(value);
00265       break;
00266     case 'A':
00267       // AllowRemoteContent, AnniversaryYear, AnniversaryMonth, AnniversaryDay
00268       switch (attrname[11]) {
00269         case 'C':
00270         {
00271           PRBool allowRemoteContent = PR_FALSE;
00272           GetAllowRemoteContent(&allowRemoteContent);
00273           *value = allowRemoteContent ? ToNewUnicode(NS_LITERAL_STRING("true")) :
00274                      ToNewUnicode(NS_LITERAL_STRING("false"));
00275           break;
00276         }
00277         case 'Y':
00278           rv = GetAnniversaryYear(value);
00279           break;
00280         case 'M':
00281           rv = GetAnniversaryMonth(value);
00282           break;
00283         case 'D':
00284           rv = GetAnniversaryDay(value);
00285           break;
00286         default:
00287       rv = NS_ERROR_UNEXPECTED;
00288       break;
00289       }
00290       break;
00291     case 'B':
00292       // BirthYear, BirthMonth, BirthDay
00293       switch (attrname[5]) {
00294         case 'Y':
00295           rv = GetBirthYear(value);
00296           break;
00297         case 'M':
00298           rv = GetBirthMonth(value);
00299           break;
00300         case 'D':
00301           rv = GetBirthDay(value);
00302           break;
00303         default:
00304           rv = NS_ERROR_UNEXPECTED;
00305           break;
00306       }
00307       break;
00308     case 'C':
00309       switch (attrname[1]) {
00310         case 'o':
00311           rv = GetCompany(value);
00312           break;
00313         case 'a': // CardType, Category
00314           if (attrname[2] == 't')
00315             rv = GetCategory(value);
00316           else
00317             rv = GetCardType(value);
00318           break;
00319         case 'e':
00320           if (strlen(attrname) <= 14)
00321           rv = GetCellularNumber(value);
00322           else
00323             rv = GetCellularNumberType(value);
00324           break;
00325         case 'u':
00326           switch (attrname[6]) {
00327             case '1':
00328               rv = GetCustom1(value);
00329               break;
00330             case '2':
00331               rv = GetCustom2(value);
00332               break;
00333             case '3':
00334               rv = GetCustom3(value);
00335               break;
00336             case '4':
00337               rv = GetCustom4(value);
00338               break;
00339             default:
00340               rv = NS_ERROR_UNEXPECTED;
00341               break;
00342           }
00343           break;
00344         default:
00345           rv = NS_ERROR_UNEXPECTED;
00346           break;
00347       }
00348       break;
00349     case 'D':
00350       if (attrname[1] == 'i') 
00351         rv = GetDisplayName(value);
00352       else if (attrname[2] == 'f')
00353       {
00354         if ((attrname[7] == 'E'))
00355           rv = GetDefaultEmail(value);
00356         else
00357           rv = GetDefaultAddress(value);
00358       }
00359       else 
00360         rv = GetDepartment(value);
00361       break;
00362     case 'F':
00363       switch (attrname[1]) {
00364       case 'i':
00365         rv = GetFirstName(value);
00366         break;
00367       case 'a':
00368         if ((attrname[2] == 'x'))
00369           if (strlen(attrname) <= 9)
00370         rv = GetFaxNumber(value);
00371           else
00372             rv = GetFaxNumberType(value);
00373         else
00374           rv = GetFamilyName(value);
00375         break;
00376       default:
00377         rv = NS_ERROR_UNEXPECTED;
00378         break;
00379       }
00380       break;
00381     case 'H':
00382       switch (attrname[4]) {
00383         case 'A':
00384           if (attrname[11] == '\0')
00385             rv = GetHomeAddress(value);
00386           else 
00387             rv = GetHomeAddress2(value);
00388           break;
00389         case 'C':
00390           if (attrname[5] == 'i')
00391             rv = GetHomeCity(value);
00392           else 
00393             rv = GetHomeCountry(value);
00394           break;
00395         case 'P':
00396           if (strlen(attrname) <= 9)
00397           rv = GetHomePhone(value);
00398           else
00399             rv = GetHomePhoneType(value);
00400           break;
00401         case 'S':
00402           rv = GetHomeState(value);
00403           break;
00404         case 'Z':
00405           rv = GetHomeZipCode(value);
00406           break;
00407         default:
00408           rv = NS_ERROR_UNEXPECTED;
00409           break;
00410       }
00411       break;
00412     case 'J':
00413       rv = GetJobTitle(value);
00414       break;
00415     case 'L':
00416       if (attrname[1] == 'a') {
00417         if (attrname[4] == 'N') 
00418           rv = GetLastName(value);
00419         else {
00420           // XXX todo
00421           // fix me?  LDAP code gets here
00422           PRUint32 lastModifiedDate;
00423           rv = GetLastModifiedDate(&lastModifiedDate);
00424           *value = ToNewUnicode(NS_LITERAL_STRING("0Z")); 
00425         }
00426       }
00427       else
00428         rv = NS_ERROR_UNEXPECTED;
00429       break;
00430     case 'N':
00431       if (attrname[1] == 'o')
00432         rv = GetNotes(value);
00433       else 
00434         rv = GetNickName(value);
00435       break;
00436     case 'P':
00437       switch (attrname[2]) { 
00438         case 'e':
00439         {
00440           PRUint32 format;
00441           rv = GetPreferMailFormat(&format);
00442 
00443           switch (format) {
00444             case nsIAbPreferMailFormat::html:
00445               *value = ToNewUnicode(NS_LITERAL_STRING("html"));
00446               break;
00447             case nsIAbPreferMailFormat::plaintext:
00448               *value = ToNewUnicode(NS_LITERAL_STRING("plaintext"));
00449               break;
00450             case nsIAbPreferMailFormat::unknown:
00451             default :
00452               *value = ToNewUnicode(NS_LITERAL_STRING("unknown"));
00453               break;
00454           }
00455           break;
00456         }
00457         case 'g':
00458           if (strlen(attrname) <= 11)
00459           rv = GetPagerNumber(value);
00460           else
00461             rv = GetPagerNumberType(value);
00462           break;
00463         case 'i':
00464           rv = GetPrimaryEmail(value);
00465           break;
00466         case 'o':
00467           if (attrname[8] == 'L')
00468             rv = GetPhoneticLastName(value);
00469           else if (attrname[8] == 'F')
00470             rv = GetPhoneticFirstName(value);
00471           break;
00472         default:
00473           rv = NS_ERROR_UNEXPECTED;
00474           break;
00475       }
00476       break;
00477     case 'S':
00478       if (attrname[1] == 'e')
00479       rv = GetSecondEmail(value);
00480       else
00481         rv = GetSpouseName(value);
00482       break;
00483     case 'W': 
00484       if (attrname[1] == 'e') {
00485         if (attrname[7] == '1')
00486           rv = GetWebPage1(value);
00487         else 
00488           rv = GetWebPage2(value);
00489       }
00490       else {
00491         switch (attrname[4]) {
00492           case 'A':
00493             if (attrname[11] == '\0')
00494               rv = GetWorkAddress(value);
00495             else 
00496               rv = GetWorkAddress2(value);
00497             break;
00498           case 'C':
00499             if (attrname[5] == 'i')
00500               rv = GetWorkCity(value);
00501             else 
00502               rv = GetWorkCountry(value);
00503             break;
00504           case 'P':
00505             if (strlen(attrname) <= 9)
00506             rv = GetWorkPhone(value);
00507             else
00508               rv = GetWorkPhoneType(value);
00509             break;
00510           case 'S':
00511             rv = GetWorkState(value);
00512             break;
00513           case 'Z':
00514             rv = GetWorkZipCode(value);
00515             break;
00516           default:
00517             rv = NS_ERROR_UNEXPECTED;
00518             break;
00519         }
00520       }
00521       break;
00522     default:
00523       rv = NS_ERROR_UNEXPECTED;
00524       break;
00525   }
00526 
00527   // don't assert here, as failure is expected in certain cases
00528   // we call GetCardValue() from nsAbView::Init() to determine if the 
00529   // saved sortColumn is valid or not.
00530   return rv;
00531 }
00532 
00533 NS_IMETHODIMP nsAbCardProperty::SetCardValue(const char *attrname, const PRUnichar *value)
00534 {
00535   NS_ENSURE_ARG_POINTER(attrname);
00536   NS_ENSURE_ARG_POINTER(value);
00537 
00538   nsresult rv = NS_OK;
00539 
00540   switch (attrname[0]) {
00541     case '_': // _AimScreenName
00542       rv = SetAimScreenName(value);
00543       break;
00544     case 'A':
00545       // AllowRemoteContent, AnniversaryYear, AnniversaryMonth, AnniversaryDay
00546       switch (attrname[11]) {
00547         case 'C':
00548           SetAllowRemoteContent(value[0] == 't' || value[0] == 'T');
00549           break;
00550         case 'Y':
00551           rv = SetAnniversaryYear(value);
00552           break;
00553         case 'M':
00554           rv = SetAnniversaryMonth(value);
00555           break;
00556         case 'D':
00557           rv = SetAnniversaryDay(value);
00558           break;
00559         default:
00560           rv = NS_ERROR_UNEXPECTED;
00561           break;
00562       }
00563       break;
00564     case 'B':
00565       // BirthYear, BirthMonth, BirthDay
00566       switch (attrname[5]) {
00567         case 'Y':
00568           rv = SetBirthYear(value);
00569           break;
00570         case 'M':
00571           rv = SetBirthMonth(value);
00572           break;
00573         case 'D':
00574           rv = SetBirthDay(value);
00575           break;
00576         default:
00577           rv = NS_ERROR_UNEXPECTED;
00578           break;
00579       }
00580       break;
00581     case 'C':
00582       switch (attrname[1]) {
00583         case 'o':
00584           rv = SetCompany(value);
00585           break;
00586         case 'a': // CardType, Category
00587           if (attrname[2] == 't')
00588             rv = SetCategory(value);
00589           else
00590             rv = SetCardType(value);
00591           break;
00592         case 'e':
00593           if (strlen(attrname) <= 14)
00594           rv = SetCellularNumber(value);
00595           else
00596             rv = SetCellularNumberType(value);
00597           break;
00598         case 'u':
00599           switch (attrname[6]) {
00600             case '1':
00601               rv = SetCustom1(value);
00602               break;
00603             case '2':
00604               rv = SetCustom2(value);
00605               break;
00606             case '3':
00607               rv = SetCustom3(value);
00608               break;
00609             case '4':
00610               rv = SetCustom4(value);
00611               break;
00612             default:
00613               rv = NS_ERROR_UNEXPECTED;
00614               break;
00615           }
00616           break;
00617         default:
00618           rv = NS_ERROR_UNEXPECTED;
00619           break;
00620       }
00621       break;
00622     case 'D':
00623       if (attrname[1] == 'i') 
00624         rv = SetDisplayName(value);
00625       else if (attrname[2] == 'f')
00626       {
00627         if ((attrname[7] == 'E'))
00628           rv = SetDefaultEmail(value);
00629         else
00630           rv = SetDefaultAddress(value);
00631       }
00632       else 
00633         rv = SetDepartment(value);
00634       break;
00635     case 'F':
00636       switch (attrname[1]) {
00637       case 'i':
00638         rv = SetFirstName(value);
00639         break;
00640       case 'a':
00641         if ((attrname[2] == 'x'))
00642           if (strlen(attrname) <= 9)
00643         rv = SetFaxNumber(value);
00644           else
00645             rv = SetFaxNumberType(value);
00646         else
00647           rv = SetFamilyName(value);
00648         break;
00649       default:
00650         rv = NS_ERROR_UNEXPECTED;
00651         break;
00652       }
00653       break;
00654     case 'H':
00655       switch (attrname[4]) {
00656         case 'A':
00657           if (attrname[11] == '\0')
00658             rv = SetHomeAddress(value);
00659           else 
00660             rv = SetHomeAddress2(value);
00661           break;
00662         case 'C':
00663           if (attrname[5] == 'i')
00664             rv = SetHomeCity(value);
00665           else 
00666             rv = SetHomeCountry(value);
00667           break;
00668         case 'P':
00669           if (strlen(attrname) <= 9)
00670           rv = SetHomePhone(value);
00671           else
00672             rv = SetHomePhoneType(value);
00673           break;
00674         case 'S':
00675           rv = SetHomeState(value);
00676           break;
00677         case 'Z':
00678           rv = SetHomeZipCode(value);
00679           break;
00680         default:
00681           rv = NS_ERROR_UNEXPECTED;
00682           break;
00683       }
00684       break;
00685     case 'J':
00686       rv = SetJobTitle(value);
00687       break;
00688     case 'L':
00689       if (attrname[1] == 'a') {
00690         if (attrname[4] == 'N') 
00691           rv = SetLastName(value);
00692         else {
00693           // XXX todo 
00694           // fix me?  LDAP code gets here
00695           rv = SetLastModifiedDate(0);
00696         }
00697       }
00698       else
00699         rv = NS_ERROR_UNEXPECTED;
00700       break;
00701     case 'N':
00702       if (attrname[1] == 'o')
00703         rv = SetNotes(value);
00704       else 
00705         rv = SetNickName(value);
00706       break;
00707     case 'P':
00708       switch (attrname[2]) { 
00709         case 'e':
00710           switch (value[0]) {
00711             case 't':    // "true"
00712             case 'T':
00713               rv = SetPreferMailFormat(nsIAbPreferMailFormat::html);
00714               break;
00715             case 'f':    // "false"
00716             case 'F':
00717               rv = SetPreferMailFormat(nsIAbPreferMailFormat::plaintext);
00718               break;
00719             default:
00720               rv = SetPreferMailFormat(nsIAbPreferMailFormat::unknown);
00721               break;
00722           }
00723           break;
00724         case 'g':
00725           if (strlen(attrname) <= 11)
00726           rv = SetPagerNumber(value);
00727           else
00728             rv = SetPagerNumberType(value);
00729           break;
00730         case 'i':
00731           rv = SetPrimaryEmail(value);
00732           break;
00733         case 'o':
00734           if (attrname[8] == 'L')
00735             rv = SetPhoneticLastName(value);
00736           else if (attrname[8] == 'F')
00737             rv = SetPhoneticFirstName(value);
00738           break;
00739         default:
00740           rv = NS_ERROR_UNEXPECTED;
00741           break;
00742       }
00743       break;
00744     case 'S':
00745       if (attrname[1] == 'e')
00746       rv = SetSecondEmail(value);
00747       else
00748         rv = SetSpouseName(value);
00749       break;
00750     case 'W': 
00751       if (attrname[1] == 'e') {
00752         if (attrname[7] == '1')
00753           rv = SetWebPage1(value);
00754         else 
00755           rv = SetWebPage2(value);
00756       }
00757       else {
00758         switch (attrname[4]) {
00759           case 'A':
00760             if (attrname[11] == '\0')
00761               rv = SetWorkAddress(value);
00762             else 
00763               rv = SetWorkAddress2(value);
00764             break;
00765           case 'C':
00766             if (attrname[5] == 'i')
00767               rv = SetWorkCity(value);
00768             else 
00769               rv = SetWorkCountry(value);
00770             break;
00771           case 'P':
00772             if (strlen(attrname) <= 9)
00773             rv = SetWorkPhone(value);
00774             else
00775               rv = SetWorkPhoneType(value);
00776             break;
00777           case 'S':
00778             rv = SetWorkState(value);
00779             break;
00780           case 'Z':
00781             rv = SetWorkZipCode(value);
00782             break;
00783           default:
00784             rv = NS_ERROR_UNEXPECTED;
00785             break;
00786         }
00787       }
00788       break;
00789     default:
00790       rv = NS_ERROR_UNEXPECTED;
00791       break;
00792   }
00793 
00794   NS_ENSURE_SUCCESS(rv,rv);
00795   return rv;
00796 }
00797 
00798 NS_IMETHODIMP
00799 nsAbCardProperty::GetFirstName(PRUnichar * *aFirstName)
00800 { return GetAttributeName(aFirstName, m_FirstName); }
00801 
00802 NS_IMETHODIMP
00803 nsAbCardProperty::GetLastName(PRUnichar * *aLastName)
00804 { return GetAttributeName(aLastName, m_LastName); }
00805 
00806 NS_IMETHODIMP
00807 nsAbCardProperty::GetPhoneticFirstName(PRUnichar * *aPhoneticFirstName)
00808 { return GetAttributeName(aPhoneticFirstName, m_PhoneticFirstName); }
00809 
00810 NS_IMETHODIMP
00811 nsAbCardProperty::GetPhoneticLastName(PRUnichar * *aPhoneticLastName)
00812 { return GetAttributeName(aPhoneticLastName, m_PhoneticLastName); }
00813 
00814 NS_IMETHODIMP
00815 nsAbCardProperty::GetDisplayName(PRUnichar * *aDisplayName)
00816 { return GetAttributeName(aDisplayName, m_DisplayName); }
00817 
00818 NS_IMETHODIMP
00819 nsAbCardProperty::GetNickName(PRUnichar * *aNickName)
00820 { return GetAttributeName(aNickName, m_NickName); }
00821 
00822 NS_IMETHODIMP
00823 nsAbCardProperty::GetPrimaryEmail(PRUnichar * *aPrimaryEmail)
00824 { return GetAttributeName(aPrimaryEmail, m_PrimaryEmail); }
00825 
00826 NS_IMETHODIMP
00827 nsAbCardProperty::GetSecondEmail(PRUnichar * *aSecondEmail)
00828 { return GetAttributeName(aSecondEmail, m_SecondEmail); }
00829 
00830 NS_IMETHODIMP
00831 nsAbCardProperty::GetDefaultEmail(PRUnichar * *aDefaultEmail)
00832 { return GetAttributeName(aDefaultEmail, m_DefaultEmail); }
00833 
00834 NS_IMETHODIMP
00835 nsAbCardProperty::GetCardType(PRUnichar * *aCardType)
00836 { return GetAttributeName(aCardType, m_CardType); }
00837 
00838 NS_IMETHODIMP
00839 nsAbCardProperty::GetWorkPhone(PRUnichar * *aWorkPhone)
00840 { return GetAttributeName(aWorkPhone, m_WorkPhone); }
00841 
00842 NS_IMETHODIMP
00843 nsAbCardProperty::GetHomePhone(PRUnichar * *aHomePhone)
00844 { return GetAttributeName(aHomePhone, m_HomePhone); }
00845 
00846 NS_IMETHODIMP
00847 nsAbCardProperty::GetFaxNumber(PRUnichar * *aFaxNumber)
00848 { return GetAttributeName(aFaxNumber, m_FaxNumber); }
00849 
00850 NS_IMETHODIMP
00851 nsAbCardProperty::GetPagerNumber(PRUnichar * *aPagerNumber)
00852 { return GetAttributeName(aPagerNumber, m_PagerNumber); }
00853 
00854 NS_IMETHODIMP
00855 nsAbCardProperty::GetCellularNumber(PRUnichar * *aCellularNumber)
00856 { return GetAttributeName(aCellularNumber, m_CellularNumber); }
00857 
00858 NS_IMETHODIMP
00859 nsAbCardProperty::GetWorkPhoneType(PRUnichar * *aWorkPhoneType)
00860 { return GetAttributeName(aWorkPhoneType, m_WorkPhoneType); }
00861 
00862 NS_IMETHODIMP
00863 nsAbCardProperty::GetHomePhoneType(PRUnichar * *aHomePhoneType)
00864 { return GetAttributeName(aHomePhoneType, m_HomePhoneType); }
00865 
00866 NS_IMETHODIMP
00867 nsAbCardProperty::GetFaxNumberType(PRUnichar * *aFaxNumberType)
00868 { return GetAttributeName(aFaxNumberType, m_FaxNumberType); }
00869 
00870 NS_IMETHODIMP
00871 nsAbCardProperty::GetPagerNumberType(PRUnichar * *aPagerNumberType)
00872 { return GetAttributeName(aPagerNumberType, m_PagerNumberType); }
00873 
00874 NS_IMETHODIMP
00875 nsAbCardProperty::GetCellularNumberType(PRUnichar * *aCellularNumberType)
00876 { return GetAttributeName(aCellularNumberType, m_CellularNumberType); }
00877 
00878 NS_IMETHODIMP
00879 nsAbCardProperty::GetHomeAddress(PRUnichar * *aHomeAddress)
00880 { return GetAttributeName(aHomeAddress, m_HomeAddress); }
00881 
00882 NS_IMETHODIMP
00883 nsAbCardProperty::GetHomeAddress2(PRUnichar * *aHomeAddress2)
00884 { return GetAttributeName(aHomeAddress2, m_HomeAddress2); }
00885 
00886 NS_IMETHODIMP
00887 nsAbCardProperty::GetHomeCity(PRUnichar * *aHomeCity)
00888 { return GetAttributeName(aHomeCity, m_HomeCity); }
00889 
00890 NS_IMETHODIMP
00891 nsAbCardProperty::GetHomeState(PRUnichar * *aHomeState)
00892 { return GetAttributeName(aHomeState, m_HomeState); }
00893 
00894 NS_IMETHODIMP
00895 nsAbCardProperty::GetHomeZipCode(PRUnichar * *aHomeZipCode)
00896 { return GetAttributeName(aHomeZipCode, m_HomeZipCode); }
00897 
00898 NS_IMETHODIMP
00899 nsAbCardProperty::GetHomeCountry(PRUnichar * *aHomecountry)
00900 { return GetAttributeName(aHomecountry, m_HomeCountry); }
00901 
00902 NS_IMETHODIMP
00903 nsAbCardProperty::GetWorkAddress(PRUnichar * *aWorkAddress)
00904 { return GetAttributeName(aWorkAddress, m_WorkAddress); }
00905 
00906 NS_IMETHODIMP
00907 nsAbCardProperty::GetWorkAddress2(PRUnichar * *aWorkAddress2)
00908 { return GetAttributeName(aWorkAddress2, m_WorkAddress2); }
00909 
00910 NS_IMETHODIMP
00911 nsAbCardProperty::GetWorkCity(PRUnichar * *aWorkCity)
00912 { return GetAttributeName(aWorkCity, m_WorkCity); }
00913 
00914 NS_IMETHODIMP
00915 nsAbCardProperty::GetWorkState(PRUnichar * *aWorkState)
00916 { return GetAttributeName(aWorkState, m_WorkState); }
00917 
00918 NS_IMETHODIMP
00919 nsAbCardProperty::GetWorkZipCode(PRUnichar * *aWorkZipCode)
00920 { return GetAttributeName(aWorkZipCode, m_WorkZipCode); }
00921 
00922 NS_IMETHODIMP
00923 nsAbCardProperty::GetWorkCountry(PRUnichar * *aWorkCountry)
00924 { return GetAttributeName(aWorkCountry, m_WorkCountry); }
00925 
00926 NS_IMETHODIMP
00927 nsAbCardProperty::GetJobTitle(PRUnichar * *aJobTitle)
00928 { return GetAttributeName(aJobTitle, m_JobTitle); }
00929 
00930 NS_IMETHODIMP
00931 nsAbCardProperty::GetDepartment(PRUnichar * *aDepartment)
00932 { return GetAttributeName(aDepartment, m_Department); }
00933 
00934 NS_IMETHODIMP
00935 nsAbCardProperty::GetCompany(PRUnichar * *aCompany)
00936 { return GetAttributeName(aCompany, m_Company); }
00937 
00938 NS_IMETHODIMP
00939 nsAbCardProperty::GetAimScreenName(PRUnichar * *aAimScreenName)
00940 { return GetAttributeName(aAimScreenName, m_AimScreenName); }
00941 
00942 NS_IMETHODIMP
00943 nsAbCardProperty::GetAnniversaryYear(PRUnichar * *aAnniversaryYear)
00944 { return GetAttributeName(aAnniversaryYear, m_AnniversaryYear); }
00945 
00946 NS_IMETHODIMP
00947 nsAbCardProperty::GetAnniversaryMonth(PRUnichar * *aAnniversaryMonth)
00948 { return GetAttributeName(aAnniversaryMonth, m_AnniversaryMonth); }
00949 
00950 NS_IMETHODIMP
00951 nsAbCardProperty::GetAnniversaryDay(PRUnichar * *aAnniversaryDay)
00952 { return GetAttributeName(aAnniversaryDay, m_AnniversaryDay); }
00953 
00954 NS_IMETHODIMP
00955 nsAbCardProperty::GetSpouseName(PRUnichar * *aSpouseName)
00956 { return GetAttributeName(aSpouseName, m_SpouseName); }
00957 
00958 NS_IMETHODIMP
00959 nsAbCardProperty::GetFamilyName(PRUnichar * *aFamilyName)
00960 { return GetAttributeName(aFamilyName, m_FamilyName); }
00961 
00962 NS_IMETHODIMP
00963 nsAbCardProperty::GetDefaultAddress(PRUnichar * *aDefaultAddress)
00964 { return GetAttributeName(aDefaultAddress, m_DefaultAddress); }
00965 
00966 NS_IMETHODIMP
00967 nsAbCardProperty::GetCategory(PRUnichar * *aCategory)
00968 { return GetAttributeName(aCategory, m_Category); }
00969 
00970 NS_IMETHODIMP
00971 nsAbCardProperty::GetWebPage1(PRUnichar * *aWebPage1)
00972 { return GetAttributeName(aWebPage1, m_WebPage1); }
00973 
00974 NS_IMETHODIMP
00975 nsAbCardProperty::GetWebPage2(PRUnichar * *aWebPage2)
00976 { return GetAttributeName(aWebPage2, m_WebPage2); }
00977 
00978 NS_IMETHODIMP
00979 nsAbCardProperty::GetBirthYear(PRUnichar * *aBirthYear)
00980 { return GetAttributeName(aBirthYear, m_BirthYear); }
00981 
00982 NS_IMETHODIMP
00983 nsAbCardProperty::GetBirthMonth(PRUnichar * *aBirthMonth)
00984 { return GetAttributeName(aBirthMonth, m_BirthMonth); }
00985 
00986 NS_IMETHODIMP
00987 nsAbCardProperty::GetBirthDay(PRUnichar * *aBirthDay)
00988 { return GetAttributeName(aBirthDay, m_BirthDay); }
00989 
00990 NS_IMETHODIMP
00991 nsAbCardProperty::GetCustom1(PRUnichar * *aCustom1)
00992 { return GetAttributeName(aCustom1, m_Custom1); }
00993 
00994 NS_IMETHODIMP
00995 nsAbCardProperty::GetCustom2(PRUnichar * *aCustom2)
00996 { return GetAttributeName(aCustom2, m_Custom2); }
00997 
00998 NS_IMETHODIMP
00999 nsAbCardProperty::GetCustom3(PRUnichar * *aCustom3)
01000 { return GetAttributeName(aCustom3, m_Custom3); }
01001 
01002 NS_IMETHODIMP
01003 nsAbCardProperty::GetCustom4(PRUnichar * *aCustom4)
01004 { return GetAttributeName(aCustom4, m_Custom4); }
01005 
01006 NS_IMETHODIMP
01007 nsAbCardProperty::GetNotes(PRUnichar * *aNotes)
01008 { return GetAttributeName(aNotes, m_Note); }
01009 
01010 NS_IMETHODIMP
01011 nsAbCardProperty::GetLastModifiedDate(PRUint32 *aLastModifiedDate)
01012 { *aLastModifiedDate = m_LastModDate; return NS_OK; }
01013 
01014 NS_IMETHODIMP
01015 nsAbCardProperty::SetFirstName(const PRUnichar * aFirstName)
01016 { return SetAttributeName(aFirstName, m_FirstName); }
01017 
01018 NS_IMETHODIMP
01019 nsAbCardProperty::SetLastName(const PRUnichar * aLastName)
01020 { return SetAttributeName(aLastName, m_LastName); }
01021 
01022 NS_IMETHODIMP
01023 nsAbCardProperty::SetPhoneticLastName(const PRUnichar * aPhoneticLastName)
01024 { return SetAttributeName(aPhoneticLastName, m_PhoneticLastName); }
01025 
01026 NS_IMETHODIMP
01027 nsAbCardProperty::SetPhoneticFirstName(const PRUnichar * aPhoneticFirstName)
01028 { return SetAttributeName(aPhoneticFirstName, m_PhoneticFirstName); }
01029 
01030 NS_IMETHODIMP
01031 nsAbCardProperty::SetDisplayName(const PRUnichar * aDisplayName)
01032 { return SetAttributeName(aDisplayName, m_DisplayName); }
01033 
01034 NS_IMETHODIMP
01035 nsAbCardProperty::SetNickName(const PRUnichar * aNickName)
01036 { return SetAttributeName(aNickName, m_NickName); }
01037 
01038 NS_IMETHODIMP
01039 nsAbCardProperty::SetPrimaryEmail(const PRUnichar * aPrimaryEmail)
01040 { return SetAttributeName(aPrimaryEmail, m_PrimaryEmail); }
01041 
01042 NS_IMETHODIMP
01043 nsAbCardProperty::SetSecondEmail(const PRUnichar * aSecondEmail)
01044 { return SetAttributeName(aSecondEmail, m_SecondEmail); }
01045 
01046 NS_IMETHODIMP
01047 nsAbCardProperty::SetDefaultEmail(const PRUnichar * aDefaultEmail)
01048 { return SetAttributeName(aDefaultEmail, m_DefaultEmail); }
01049 
01050 NS_IMETHODIMP
01051 nsAbCardProperty::SetCardType(const PRUnichar * aCardType)
01052 { return SetAttributeName(aCardType, m_CardType); }
01053 
01054 NS_IMETHODIMP
01055 nsAbCardProperty::SetWorkPhone(const PRUnichar * aWorkPhone)
01056 { return SetAttributeName(aWorkPhone, m_WorkPhone); }
01057 
01058 NS_IMETHODIMP
01059 nsAbCardProperty::SetHomePhone(const PRUnichar * aHomePhone)
01060 { return SetAttributeName(aHomePhone, m_HomePhone); }
01061 
01062 NS_IMETHODIMP
01063 nsAbCardProperty::SetFaxNumber(const PRUnichar * aFaxNumber)
01064 { return SetAttributeName(aFaxNumber, m_FaxNumber); }
01065 
01066 NS_IMETHODIMP
01067 nsAbCardProperty::SetPagerNumber(const PRUnichar * aPagerNumber)
01068 { return SetAttributeName(aPagerNumber, m_PagerNumber); }
01069 
01070 NS_IMETHODIMP
01071 nsAbCardProperty::SetCellularNumber(const PRUnichar * aCellularNumber)
01072 { return SetAttributeName(aCellularNumber, m_CellularNumber); }
01073 
01074 NS_IMETHODIMP
01075 nsAbCardProperty::SetWorkPhoneType(const PRUnichar * aWorkPhoneType)
01076 { return SetAttributeName(aWorkPhoneType, m_WorkPhoneType); }
01077 
01078 NS_IMETHODIMP
01079 nsAbCardProperty::SetHomePhoneType(const PRUnichar * aHomePhoneType)
01080 { return SetAttributeName(aHomePhoneType, m_HomePhoneType); }
01081 
01082 NS_IMETHODIMP
01083 nsAbCardProperty::SetFaxNumberType(const PRUnichar * aFaxNumberType)
01084 { return SetAttributeName(aFaxNumberType, m_FaxNumberType); }
01085 
01086 NS_IMETHODIMP
01087 nsAbCardProperty::SetPagerNumberType(const PRUnichar * aPagerNumberType)
01088 { return SetAttributeName(aPagerNumberType, m_PagerNumberType); }
01089 
01090 NS_IMETHODIMP
01091 nsAbCardProperty::SetCellularNumberType(const PRUnichar * aCellularNumberType)
01092 { return SetAttributeName(aCellularNumberType, m_CellularNumberType); }
01093 
01094 NS_IMETHODIMP
01095 nsAbCardProperty::SetHomeAddress(const PRUnichar * aHomeAddress)
01096 { return SetAttributeName(aHomeAddress, m_HomeAddress); }
01097 
01098 NS_IMETHODIMP
01099 nsAbCardProperty::SetHomeAddress2(const PRUnichar * aHomeAddress2)
01100 { return SetAttributeName(aHomeAddress2, m_HomeAddress2); }
01101 
01102 NS_IMETHODIMP
01103 nsAbCardProperty::SetHomeCity(const PRUnichar * aHomeCity)
01104 { return SetAttributeName(aHomeCity, m_HomeCity); }
01105 
01106 NS_IMETHODIMP
01107 nsAbCardProperty::SetHomeState(const PRUnichar * aHomeState)
01108 { return SetAttributeName(aHomeState, m_HomeState); }
01109 
01110 NS_IMETHODIMP
01111 nsAbCardProperty::SetHomeZipCode(const PRUnichar * aHomeZipCode)
01112 { return SetAttributeName(aHomeZipCode, m_HomeZipCode); }
01113 
01114 NS_IMETHODIMP
01115 nsAbCardProperty::SetHomeCountry(const PRUnichar * aHomecountry)
01116 { return SetAttributeName(aHomecountry, m_HomeCountry); }
01117 
01118 NS_IMETHODIMP
01119 nsAbCardProperty::SetWorkAddress(const PRUnichar * aWorkAddress)
01120 { return SetAttributeName(aWorkAddress, m_WorkAddress); }
01121 
01122 NS_IMETHODIMP
01123 nsAbCardProperty::SetWorkAddress2(const PRUnichar * aWorkAddress2)
01124 { return SetAttributeName(aWorkAddress2, m_WorkAddress2); }
01125 
01126 NS_IMETHODIMP
01127 nsAbCardProperty::SetWorkCity(const PRUnichar * aWorkCity)
01128 { return SetAttributeName(aWorkCity, m_WorkCity); }
01129 
01130 NS_IMETHODIMP
01131 nsAbCardProperty::SetWorkState(const PRUnichar * aWorkState)
01132 { return SetAttributeName(aWorkState, m_WorkState); }
01133 
01134 NS_IMETHODIMP
01135 nsAbCardProperty::SetWorkZipCode(const PRUnichar * aWorkZipCode)
01136 { return SetAttributeName(aWorkZipCode, m_WorkZipCode); }
01137 
01138 NS_IMETHODIMP
01139 nsAbCardProperty::SetWorkCountry(const PRUnichar * aWorkCountry)
01140 { return SetAttributeName(aWorkCountry, m_WorkCountry); }
01141 
01142 NS_IMETHODIMP
01143 nsAbCardProperty::SetJobTitle(const PRUnichar * aJobTitle)
01144 { return SetAttributeName(aJobTitle, m_JobTitle); }
01145 
01146 NS_IMETHODIMP
01147 nsAbCardProperty::SetDepartment(const PRUnichar * aDepartment)
01148 { return SetAttributeName(aDepartment, m_Department); }
01149 
01150 NS_IMETHODIMP
01151 nsAbCardProperty::SetCompany(const PRUnichar * aCompany)
01152 { return SetAttributeName(aCompany, m_Company); }
01153 
01154 NS_IMETHODIMP
01155 nsAbCardProperty::SetAimScreenName(const PRUnichar *aAimScreenName)
01156 { return SetAttributeName(aAimScreenName, m_AimScreenName); }
01157 
01158 NS_IMETHODIMP
01159 nsAbCardProperty::SetAnniversaryYear(const PRUnichar * aAnniversaryYear)
01160 { return SetAttributeName(aAnniversaryYear, m_AnniversaryYear); }
01161 
01162 NS_IMETHODIMP
01163 nsAbCardProperty::SetAnniversaryMonth(const PRUnichar * aAnniversaryMonth)
01164 { return SetAttributeName(aAnniversaryMonth, m_AnniversaryMonth); }
01165 
01166 NS_IMETHODIMP
01167 nsAbCardProperty::SetAnniversaryDay(const PRUnichar * aAnniversaryDay)
01168 { return SetAttributeName(aAnniversaryDay, m_AnniversaryDay); }
01169 
01170 NS_IMETHODIMP
01171 nsAbCardProperty::SetSpouseName(const PRUnichar * aSpouseName)
01172 { return SetAttributeName(aSpouseName, m_SpouseName); }
01173 
01174 NS_IMETHODIMP
01175 nsAbCardProperty::SetFamilyName(const PRUnichar * aFamilyName)
01176 { return SetAttributeName(aFamilyName, m_FamilyName); }
01177 
01178 NS_IMETHODIMP
01179 nsAbCardProperty::SetDefaultAddress(const PRUnichar * aDefaultAddress)
01180 { return SetAttributeName(aDefaultAddress, m_DefaultAddress); }
01181 
01182 NS_IMETHODIMP
01183 nsAbCardProperty::SetCategory(const PRUnichar * aCategory)
01184 { return SetAttributeName(aCategory, m_Category); }
01185 
01186 NS_IMETHODIMP
01187 nsAbCardProperty::SetWebPage1(const PRUnichar * aWebPage1)
01188 { return SetAttributeName(aWebPage1, m_WebPage1); }
01189 
01190 NS_IMETHODIMP
01191 nsAbCardProperty::SetWebPage2(const PRUnichar * aWebPage2)
01192 { return SetAttributeName(aWebPage2, m_WebPage2); }
01193 
01194 NS_IMETHODIMP
01195 nsAbCardProperty::SetBirthYear(const PRUnichar * aBirthYear)
01196 { return SetAttributeName(aBirthYear, m_BirthYear); }
01197 
01198 NS_IMETHODIMP
01199 nsAbCardProperty::SetBirthMonth(const PRUnichar * aBirthMonth)
01200 { return SetAttributeName(aBirthMonth, m_BirthMonth); }
01201 
01202 NS_IMETHODIMP
01203 nsAbCardProperty::SetBirthDay(const PRUnichar * aBirthDay)
01204 { return SetAttributeName(aBirthDay, m_BirthDay); }
01205 
01206 NS_IMETHODIMP
01207 nsAbCardProperty::SetCustom1(const PRUnichar * aCustom1)
01208 { return SetAttributeName(aCustom1, m_Custom1); }
01209 
01210 NS_IMETHODIMP
01211 nsAbCardProperty::SetCustom2(const PRUnichar * aCustom2)
01212 { return SetAttributeName(aCustom2, m_Custom2); }
01213 
01214 NS_IMETHODIMP
01215 nsAbCardProperty::SetCustom3(const PRUnichar * aCustom3)
01216 { return SetAttributeName(aCustom3, m_Custom3); }
01217 
01218 NS_IMETHODIMP
01219 nsAbCardProperty::SetCustom4(const PRUnichar * aCustom4)
01220 { return SetAttributeName(aCustom4, m_Custom4); }
01221 
01222 NS_IMETHODIMP
01223 nsAbCardProperty::SetNotes(const PRUnichar * aNotes)
01224 { return SetAttributeName(aNotes, m_Note); }
01225 
01226 NS_IMETHODIMP
01227 nsAbCardProperty::SetLastModifiedDate(PRUint32 aLastModifiedDate)
01228 { return m_LastModDate = aLastModifiedDate; }
01229 
01230 NS_IMETHODIMP nsAbCardProperty::Copy(nsIAbCard* srcCard)
01231 {
01232        nsXPIDLString str;
01233        srcCard->GetFirstName(getter_Copies(str));
01234        SetFirstName(str);
01235 
01236        srcCard->GetLastName(getter_Copies(str));
01237        SetLastName(str);
01238        srcCard->GetPhoneticFirstName(getter_Copies(str));
01239        SetPhoneticFirstName(str);
01240        srcCard->GetPhoneticLastName(getter_Copies(str));
01241        SetPhoneticLastName(str);
01242        srcCard->GetDisplayName(getter_Copies(str));
01243        SetDisplayName(str);
01244        srcCard->GetNickName(getter_Copies(str));
01245        SetNickName(str);
01246        srcCard->GetPrimaryEmail(getter_Copies(str));
01247        SetPrimaryEmail(str);
01248        srcCard->GetSecondEmail(getter_Copies(str));
01249        SetSecondEmail(str);
01250   srcCard->GetDefaultEmail(getter_Copies(str));
01251   SetDefaultEmail(str);
01252   srcCard->GetCardType(getter_Copies(str));
01253   SetCardType(str);
01254 
01255        PRUint32 format;
01256        srcCard->GetPreferMailFormat(&format);
01257        SetPreferMailFormat(format);
01258 
01259        PRUint32 popularityIndex;
01260        srcCard->GetPopularityIndex(&popularityIndex);
01261        SetPopularityIndex(popularityIndex);
01262 
01263   PRBool allowRemoteContent = PR_FALSE;
01264   srcCard->GetAllowRemoteContent(&allowRemoteContent);
01265   SetAllowRemoteContent(allowRemoteContent);
01266 
01267        srcCard->GetWorkPhone(getter_Copies(str));
01268        SetWorkPhone(str);
01269        srcCard->GetHomePhone(getter_Copies(str));
01270        SetHomePhone(str);
01271        srcCard->GetFaxNumber(getter_Copies(str));
01272        SetFaxNumber(str);
01273        srcCard->GetPagerNumber(getter_Copies(str));
01274        SetPagerNumber(str);
01275        srcCard->GetCellularNumber(getter_Copies(str));
01276        SetCellularNumber(str);
01277   srcCard->GetWorkPhoneType(getter_Copies(str));
01278   SetWorkPhoneType(str);
01279   srcCard->GetHomePhoneType(getter_Copies(str));
01280   SetHomePhoneType(str);
01281   srcCard->GetFaxNumberType(getter_Copies(str));
01282   SetFaxNumberType(str);
01283   srcCard->GetPagerNumberType(getter_Copies(str));
01284   SetPagerNumberType(str);
01285   srcCard->GetCellularNumberType(getter_Copies(str));
01286   SetCellularNumberType(str);
01287        srcCard->GetHomeAddress(getter_Copies(str));
01288        SetHomeAddress(str);
01289        srcCard->GetHomeAddress2(getter_Copies(str));
01290        SetHomeAddress2(str);
01291        srcCard->GetHomeCity(getter_Copies(str));
01292        SetHomeCity(str);
01293        srcCard->GetHomeState(getter_Copies(str));
01294        SetHomeState(str);
01295        srcCard->GetHomeZipCode(getter_Copies(str));
01296        SetHomeZipCode(str);
01297        srcCard->GetHomeCountry(getter_Copies(str));
01298        SetHomeCountry(str);
01299        srcCard->GetWorkAddress(getter_Copies(str));
01300        SetWorkAddress(str);
01301        srcCard->GetWorkAddress2(getter_Copies(str));
01302        SetWorkAddress2(str);
01303        srcCard->GetWorkCity(getter_Copies(str));
01304        SetWorkCity(str);
01305        srcCard->GetWorkState(getter_Copies(str));
01306        SetWorkState(str);
01307        srcCard->GetWorkZipCode(getter_Copies(str));
01308        SetWorkZipCode(str);
01309        srcCard->GetWorkCountry(getter_Copies(str));
01310        SetWorkCountry(str);
01311        srcCard->GetJobTitle(getter_Copies(str));
01312        SetJobTitle(str);
01313        srcCard->GetDepartment(getter_Copies(str));
01314        SetDepartment(str);
01315        srcCard->GetCompany(getter_Copies(str));
01316        SetCompany(str);
01317   srcCard->GetAimScreenName(getter_Copies(str));
01318   SetAimScreenName(str);
01319 
01320   srcCard->GetAnniversaryYear(getter_Copies(str));
01321   SetAnniversaryYear(str);
01322   srcCard->GetAnniversaryMonth(getter_Copies(str));
01323   SetAnniversaryMonth(str);
01324   srcCard->GetAnniversaryDay(getter_Copies(str));
01325   SetAnniversaryDay(str);
01326   srcCard->GetSpouseName(getter_Copies(str));
01327   SetSpouseName(str);
01328   srcCard->GetFamilyName(getter_Copies(str));
01329   SetFamilyName(str);
01330   srcCard->GetDefaultAddress(getter_Copies(str));
01331   SetDefaultAddress(str);
01332   srcCard->GetCategory(getter_Copies(str));
01333   SetCategory(str);
01334 
01335        srcCard->GetWebPage1(getter_Copies(str));
01336        SetWebPage1(str);
01337        srcCard->GetWebPage2(getter_Copies(str));
01338        SetWebPage2(str);
01339        srcCard->GetBirthYear(getter_Copies(str));
01340        SetBirthYear(str);
01341        srcCard->GetBirthMonth(getter_Copies(str));
01342        SetBirthMonth(str);
01343        srcCard->GetBirthDay(getter_Copies(str));
01344        SetBirthDay(str);
01345        srcCard->GetCustom1(getter_Copies(str));
01346        SetCustom1(str);
01347        srcCard->GetCustom2(getter_Copies(str));
01348        SetCustom2(str);
01349        srcCard->GetCustom3(getter_Copies(str));
01350        SetCustom3(str);
01351        srcCard->GetCustom4(getter_Copies(str));
01352        SetCustom4(str);
01353        srcCard->GetNotes(getter_Copies(str));
01354        SetNotes(str);
01355 
01356        return NS_OK;
01357 }
01358 
01359 NS_IMETHODIMP nsAbCardProperty::EditCardToDatabase(const char *uri)
01360 {
01361        return NS_ERROR_NOT_IMPLEMENTED;
01362 }
01363 
01364 NS_IMETHODIMP nsAbCardProperty::Equals(nsIAbCard *card, PRBool *result)
01365 {
01366   *result = (card == this);
01367   return NS_OK;
01368 }
01369 
01370 static VObject* myAddPropValue(VObject *o, const char *propName, const PRUnichar *propValue, PRBool *aCardHasData)
01371 {
01372     if (aCardHasData)
01373         *aCardHasData = PR_TRUE;
01374     return addPropValue(o, propName, NS_ConvertUCS2toUTF8(propValue).get());
01375 }
01376 
01377 NS_IMETHODIMP nsAbCardProperty::ConvertToEscapedVCard(char **aResult)
01378 {
01379     nsXPIDLString str;
01380     PRBool vCardHasData = PR_FALSE;
01381     VObject* vObj = newVObject(VCCardProp);
01382     VObject* t;
01383     
01384     // [comment from 4.x]
01385     // Big flame coming....so Vobject is not designed at all to work with  an array of 
01386     // attribute values. It wants you to have all of the attributes easily available. You
01387     // cannot add one attribute at a time as you find them to the vobject. Why? Because
01388     // it creates a property for a particular type like phone number and then that property
01389     // has multiple values. This implementation is not pretty. I can hear my algos prof
01390     // yelling from here.....I have to do a linear search through my attributes array for
01391     // EACH vcard property we want to set. *sigh* One day I will have time to come back
01392     // to this function and remedy this O(m*n) function where n = # attribute values and
01393     // m = # of vcard properties....  
01394 
01395     (void)GetDisplayName(getter_Copies(str));
01396     if (!str.IsEmpty()) {
01397         myAddPropValue(vObj, VCFullNameProp, str.get(), &vCardHasData);
01398     }
01399     
01400     (void)GetLastName(getter_Copies(str));
01401     if (!str.IsEmpty()) {
01402         t = isAPropertyOf(vObj, VCNameProp);
01403         if (!t)
01404             t = addProp(vObj, VCNameProp);
01405         myAddPropValue(t, VCFamilyNameProp, str.get(), &vCardHasData);
01406     }
01407     
01408     (void)GetFirstName(getter_Copies(str));
01409     if (!str.IsEmpty()) {
01410         t = isAPropertyOf(vObj, VCNameProp);
01411         if (!t)
01412             t = addProp(vObj, VCNameProp);
01413         myAddPropValue(t, VCGivenNameProp, str.get(), &vCardHasData);
01414     }
01415 
01416     (void)GetCompany(getter_Copies(str));
01417     if (!str.IsEmpty())
01418     {
01419         t = isAPropertyOf(vObj, VCOrgProp);
01420         if (!t)
01421             t = addProp(vObj, VCOrgProp);
01422         myAddPropValue(t, VCOrgNameProp, str.get(), &vCardHasData);
01423     }
01424 
01425     (void)GetDepartment(getter_Copies(str));
01426     if (!str.IsEmpty())
01427     {
01428         t = isAPropertyOf(vObj, VCOrgProp);
01429         if (!t)
01430             t = addProp(vObj, VCOrgProp);
01431         myAddPropValue(t, VCOrgUnitProp, str.get(), &vCardHasData);
01432     }
01433  
01434     (void)GetWorkAddress2(getter_Copies(str));
01435     if (!str.IsEmpty())
01436     {
01437         t = isAPropertyOf(vObj, VCAdrProp);
01438         if  (!t)
01439             t = addProp(vObj, VCAdrProp);
01440         myAddPropValue(t, VCPostalBoxProp, str.get(), &vCardHasData);  
01441     }
01442 
01443     (void)GetWorkAddress(getter_Copies(str));
01444     if (!str.IsEmpty())
01445     {
01446         t = isAPropertyOf(vObj, VCAdrProp);
01447         if  (!t)
01448             t = addProp(vObj, VCAdrProp);
01449         myAddPropValue(t, VCStreetAddressProp, str.get(), &vCardHasData);
01450     }
01451 
01452     (void)GetWorkCity(getter_Copies(str));
01453     if (!str.IsEmpty())
01454     {
01455         t = isAPropertyOf(vObj, VCAdrProp);
01456         if  (!t)
01457             t = addProp(vObj, VCAdrProp);
01458         myAddPropValue(t, VCCityProp, str.get(), &vCardHasData);
01459     }
01460 
01461     (void)GetWorkState(getter_Copies(str));
01462     if (!str.IsEmpty())
01463     {
01464         t = isAPropertyOf(vObj, VCAdrProp);
01465         if  (!t)
01466             t = addProp(vObj, VCAdrProp);
01467         myAddPropValue(t, VCRegionProp, str.get(), &vCardHasData);
01468     }
01469 
01470     (void)GetWorkZipCode(getter_Copies(str));
01471     if (!str.IsEmpty())
01472     {
01473         t = isAPropertyOf(vObj, VCAdrProp);
01474         if  (!t)
01475             t = addProp(vObj, VCAdrProp);
01476         myAddPropValue(t, VCPostalCodeProp, str.get(), &vCardHasData);
01477     }
01478 
01479     (void)GetWorkCountry(getter_Copies(str));
01480     if (!str.IsEmpty())
01481     {
01482         t = isAPropertyOf(vObj, VCAdrProp);
01483         if  (!t)
01484             t = addProp(vObj, VCAdrProp);
01485         myAddPropValue(t, VCCountryNameProp, str.get(), &vCardHasData);
01486     }
01487     else
01488     {
01489         // only add this if VCAdrProp already exists
01490         t = isAPropertyOf(vObj, VCAdrProp);
01491         if (t)
01492         {
01493             addProp(t, VCDomesticProp);
01494         }
01495     }
01496 
01497     (void)GetPrimaryEmail(getter_Copies(str));
01498     if (!str.IsEmpty())
01499     {
01500         t = myAddPropValue(vObj, VCEmailAddressProp, str.get(), &vCardHasData);  
01501         addProp(t, VCInternetProp);
01502     }
01503  
01504     (void)GetJobTitle(getter_Copies(str));
01505     if (!str.IsEmpty())
01506     {
01507         myAddPropValue(vObj, VCTitleProp, str.get(), &vCardHasData);
01508     }
01509 
01510     (void)GetWorkPhone(getter_Copies(str));
01511     if (!str.IsEmpty())
01512     {
01513         t = myAddPropValue(vObj, VCTelephoneProp, str.get(), &vCardHasData);
01514         addProp(t, VCWorkProp);
01515     }
01516 
01517     (void)GetFaxNumber(getter_Copies(str));
01518     if (!str.IsEmpty())
01519     {
01520         t = myAddPropValue(vObj, VCTelephoneProp, str.get(), &vCardHasData);
01521         addProp(t, VCFaxProp);
01522     }
01523 
01524     (void)GetPagerNumber(getter_Copies(str));
01525     if (!str.IsEmpty())
01526     {
01527         t = myAddPropValue(vObj, VCTelephoneProp, str.get(), &vCardHasData);
01528         addProp(t, VCPagerProp);
01529     }
01530     
01531     (void)GetHomePhone(getter_Copies(str));
01532     if (!str.IsEmpty())
01533     {
01534         t = myAddPropValue(vObj, VCTelephoneProp, str.get(), &vCardHasData);
01535         addProp(t, VCHomeProp);
01536     }
01537 
01538     (void)GetCellularNumber(getter_Copies(str));
01539     if (!str.IsEmpty())
01540     {
01541         t = myAddPropValue(vObj, VCTelephoneProp, str.get(), &vCardHasData);
01542         addProp(t, VCCellularProp);
01543     }
01544 
01545     (void)GetNotes(getter_Copies(str));
01546     if (!str.IsEmpty())
01547     {
01548         myAddPropValue(vObj, VCNoteProp, str.get(), &vCardHasData);
01549     }
01550     
01551     PRUint32 format;
01552     (void)GetPreferMailFormat(&format);
01553     if (format == nsIAbPreferMailFormat::html) {
01554         myAddPropValue(vObj, VCUseHTML, NS_LITERAL_STRING("TRUE").get(), &vCardHasData);
01555     }
01556     else if (format == nsIAbPreferMailFormat::plaintext) {
01557         myAddPropValue(vObj, VCUseHTML, NS_LITERAL_STRING("FALSE").get(), &vCardHasData);
01558     }
01559 
01560     (void)GetWebPage1(getter_Copies(str));
01561     if (!str.IsEmpty())
01562     {
01563         myAddPropValue(vObj, VCURLProp, str.get(), &vCardHasData);
01564     }
01565     
01566     myAddPropValue(vObj, VCVersionProp, NS_LITERAL_STRING("2.1").get(), nsnull);
01567 
01568     if (!vCardHasData) {
01569         *aResult = PL_strdup("");
01570         return NS_OK;
01571     }
01572 
01573     int len = 0;
01574     char *vCard = writeMemVObject(0, &len, vObj);
01575     if (vObj)
01576         cleanVObject(vObj);
01577 
01578     *aResult = nsEscape(vCard, url_Path);
01579     return (*aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
01580 }
01581 
01582 NS_IMETHODIMP nsAbCardProperty::ConvertToBase64EncodedXML(char **result)
01583 {
01584   nsresult rv;
01585   nsString xmlStr;
01586 
01587   xmlStr.AppendLiteral("<?xml version=\"1.0\"?>\n"
01588                        "<?xml-stylesheet type=\"text/css\" href=\"chrome://messenger/content/addressbook/print.css\"?>\n"
01589                        "<directory>\n");
01590 
01591   // Get Address Book string and set it as title of XML document
01592   nsCOMPtr<nsIStringBundle> bundle;
01593   nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
01594   if (NS_SUCCEEDED(rv)) {
01595     rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
01596     if (NS_SUCCEEDED(rv)) {
01597       nsXPIDLString addrBook;
01598       rv = bundle->GetStringFromName(NS_LITERAL_STRING("addressBook").get(), getter_Copies(addrBook));
01599       if (NS_SUCCEEDED(rv)) {
01600         xmlStr.AppendLiteral("<title xmlns=\"http://www.w3.org/1999/xhtml\">");
01601         xmlStr.Append(addrBook);
01602         xmlStr.AppendLiteral("</title>\n");
01603       }
01604     }
01605   }
01606 
01607   nsXPIDLString xmlSubstr;
01608   rv = ConvertToXMLPrintData(getter_Copies(xmlSubstr));
01609   NS_ENSURE_SUCCESS(rv,rv);
01610 
01611   xmlStr.Append(xmlSubstr);
01612   xmlStr.AppendLiteral("</directory>\n");
01613 
01614   *result = PL_Base64Encode(NS_ConvertUCS2toUTF8(xmlStr).get(), 0, nsnull);
01615   return (*result ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
01616 }
01617 
01618 NS_IMETHODIMP nsAbCardProperty::ConvertToXMLPrintData(PRUnichar **aXMLSubstr)
01619 {
01620   NS_ENSURE_ARG_POINTER(aXMLSubstr);
01621 
01622   nsresult rv;
01623   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
01624   NS_ENSURE_SUCCESS(rv,rv);
01625   
01626   PRInt32 generatedNameFormat;
01627   rv = prefBranch->GetIntPref(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, &generatedNameFormat);
01628   NS_ENSURE_SUCCESS(rv, rv);
01629   
01630   nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
01631   NS_ENSURE_SUCCESS(rv,rv);
01632   
01633   nsXPIDLString generatedName;
01634   rv = abSession->GenerateNameFromCard(this, generatedNameFormat, getter_Copies(generatedName));
01635   NS_ENSURE_SUCCESS(rv,rv);
01636   
01637   nsCOMPtr<mozITXTToHTMLConv> conv = do_CreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &rv);
01638   NS_ENSURE_SUCCESS(rv,rv);
01639 
01640   nsString xmlStr;
01641   xmlStr.SetCapacity(4096); // to reduce allocations. should be enough for most cards
01642   xmlStr.AssignLiteral("<GeneratedName>\n");
01643 
01644   nsCOMPtr<nsIStringBundle> bundle;
01645 
01646   nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
01647   NS_ENSURE_SUCCESS(rv,rv);
01648 
01649   rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
01650   NS_ENSURE_SUCCESS(rv,rv); 
01651   
01652   nsXPIDLString heading;
01653   rv = bundle->GetStringFromName(NS_LITERAL_STRING("headingCardFor").get(), getter_Copies(heading));
01654   NS_ENSURE_SUCCESS(rv, rv);
01655 
01656   xmlStr.Append(heading);
01657   xmlStr.Append(PRUnichar(' '));
01658 
01659   // use ScanTXT to convert < > & to safe values.
01660   nsXPIDLString safeText;
01661   if (!generatedName.IsEmpty()) {
01662     rv = conv->ScanTXT(generatedName, mozITXTToHTMLConv::kEntities , getter_Copies(safeText));
01663     NS_ENSURE_SUCCESS(rv,rv);
01664   }
01665 
01666   if (safeText.IsEmpty()) {
01667     nsXPIDLString primaryEmail;
01668     rv = GetCardValue(kPriEmailColumn, getter_Copies(primaryEmail));
01669     NS_ENSURE_SUCCESS(rv,rv);
01670 
01671     // use ScanTXT to convert < > & to safe values.
01672     rv = conv->ScanTXT(primaryEmail, mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
01673     NS_ENSURE_SUCCESS(rv,rv);
01674   }
01675   xmlStr.Append(safeText);
01676           
01677   xmlStr.AppendLiteral("</GeneratedName>\n"
01678                        "<table><tr><td>");
01679 
01680   rv = AppendSection(NAME_ATTRS_ARRAY, sizeof(NAME_ATTRS_ARRAY)/sizeof(AppendItem), EmptyString(), conv, xmlStr);
01681 
01682   xmlStr.AppendLiteral("</td></tr><tr><td>");
01683 
01684   rv = AppendSection(PHONE_ATTRS_ARRAY, sizeof(PHONE_ATTRS_ARRAY)/sizeof(AppendItem), NS_LITERAL_STRING("headingPhone"), conv, xmlStr);
01685 
01686   if (!m_IsMailList) {
01687     rv = AppendSection(CUSTOM_ATTRS_ARRAY, sizeof(CUSTOM_ATTRS_ARRAY)/sizeof(AppendItem), NS_LITERAL_STRING("headingOther"), conv, xmlStr);
01688   }
01689   else {
01690     rv = AppendSection(CUSTOM_ATTRS_ARRAY, sizeof(CUSTOM_ATTRS_ARRAY)/sizeof(AppendItem), NS_LITERAL_STRING("headingDescription"),
01691          conv, xmlStr);
01692     
01693     xmlStr.AppendLiteral("<section><sectiontitle>");
01694 
01695     rv = bundle->GetStringFromName(NS_LITERAL_STRING("headingAddresses").get(), getter_Copies(heading));
01696     NS_ENSURE_SUCCESS(rv, rv);
01697 
01698     xmlStr.Append(heading);
01699     xmlStr.AppendLiteral("</sectiontitle>");
01700 
01701     nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
01702     NS_ENSURE_SUCCESS(rv,rv);
01703       
01704     nsCOMPtr <nsIRDFResource> resource;
01705     rv = rdfService->GetResource(m_MailListURI, getter_AddRefs(resource));
01706     NS_ENSURE_SUCCESS(rv,rv);
01707     
01708     nsCOMPtr <nsIAbDirectory> mailList = do_QueryInterface(resource, &rv);
01709     NS_ENSURE_SUCCESS(rv,rv);
01710     
01711     nsCOMPtr<nsISupportsArray> addresses;
01712     rv = mailList->GetAddressLists(getter_AddRefs(addresses));
01713     if (addresses) {
01714       PRUint32 total = 0;
01715       addresses->Count(&total);                       
01716       if (total) {
01717         PRUint32 i;
01718         nsXPIDLString displayName;
01719         nsXPIDLString primaryEmail;
01720         for (i = 0; i < total; i++) {
01721           nsCOMPtr <nsIAbCard> listCard = do_QueryElementAt(addresses, i, &rv);
01722           NS_ENSURE_SUCCESS(rv,rv);
01723 
01724           xmlStr.AppendLiteral("<PrimaryEmail>\n");
01725 
01726           rv = listCard->GetDisplayName(getter_Copies(displayName));
01727           NS_ENSURE_SUCCESS(rv,rv);
01728 
01729           // use ScanTXT to convert < > & to safe values.
01730           nsXPIDLString safeText;
01731           rv = conv->ScanTXT(displayName, mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
01732           NS_ENSURE_SUCCESS(rv,rv);
01733           xmlStr.Append(safeText);
01734 
01735           xmlStr.AppendLiteral(" &lt;");
01736           
01737           rv = listCard->GetPrimaryEmail(getter_Copies(primaryEmail));
01738           NS_ENSURE_SUCCESS(rv,rv);
01739 
01740           // use ScanTXT to convert < > & to safe values.
01741           rv = conv->ScanTXT(primaryEmail, mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
01742           NS_ENSURE_SUCCESS(rv,rv);
01743           xmlStr.Append(safeText);
01744 
01745           xmlStr.AppendLiteral("&gt;</PrimaryEmail>\n");
01746         }
01747       }
01748     }
01749     xmlStr.AppendLiteral("</section>");
01750   }
01751 
01752   xmlStr.AppendLiteral("</td><td>");
01753 
01754   rv = AppendSection(HOME_ATTRS_ARRAY, sizeof(HOME_ATTRS_ARRAY)/sizeof(AppendItem), NS_LITERAL_STRING("headingHome"), conv, xmlStr);
01755   rv = AppendSection(WORK_ATTRS_ARRAY, sizeof(WORK_ATTRS_ARRAY)/sizeof(AppendItem), NS_LITERAL_STRING("headingWork"), conv, xmlStr);
01756   
01757   xmlStr.AppendLiteral("</td></tr></table>");
01758 
01759   *aXMLSubstr = ToNewUnicode(xmlStr);
01760 
01761   return NS_OK;
01762 }
01763 
01764 nsresult nsAbCardProperty::AppendData(const char *aAttrName, mozITXTToHTMLConv *aConv, nsString &aResult)
01765 {
01766   nsXPIDLString attrValue;
01767   nsresult rv = GetCardValue(aAttrName, getter_Copies(attrValue));
01768   NS_ENSURE_SUCCESS(rv,rv);
01769 
01770   if (attrValue.IsEmpty())
01771     return NS_OK;
01772 
01773   nsAutoString attrNameStr;
01774   attrNameStr.AssignWithConversion(aAttrName);
01775   
01776   aResult.Append(PRUnichar('<'));
01777   aResult.Append(attrNameStr);
01778   aResult.Append(PRUnichar('>'));
01779   
01780   // use ScanTXT to convert < > & to safe values.
01781   nsXPIDLString safeText;
01782   rv = aConv->ScanTXT(attrValue, mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
01783   NS_ENSURE_SUCCESS(rv,rv);
01784   aResult.Append(safeText);
01785 
01786   aResult.AppendLiteral("</");
01787   aResult.Append(attrNameStr);
01788   aResult.Append(PRUnichar('>'));
01789 
01790   return NS_OK;
01791 }
01792 
01793 nsresult nsAbCardProperty::AppendSection(AppendItem *aArray, PRInt16 aCount, const nsAFlatString& aHeading,
01794                                          mozITXTToHTMLConv *aConv, nsString &aResult)
01795 {
01796   nsresult rv;
01797 
01798   aResult.AppendLiteral("<section>");
01799 
01800   nsXPIDLString attrValue;
01801   PRBool sectionIsEmpty = PR_TRUE;
01802 
01803   PRInt16 i = 0;
01804   for (i=0;i<aCount;i++) {
01805     rv = GetCardValue(aArray[i].mColumn, getter_Copies(attrValue));
01806     NS_ENSURE_SUCCESS(rv,rv);
01807     sectionIsEmpty &= attrValue.IsEmpty();
01808   }
01809 
01810   if (!sectionIsEmpty && !aHeading.IsEmpty()) {
01811     nsCOMPtr<nsIStringBundle> bundle;
01812 
01813     nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
01814     NS_ENSURE_SUCCESS(rv,rv);
01815 
01816     rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
01817     NS_ENSURE_SUCCESS(rv,rv); 
01818   
01819     nsXPIDLString heading;
01820     rv = bundle->GetStringFromName(aHeading.get(), getter_Copies(heading));
01821     NS_ENSURE_SUCCESS(rv, rv);
01822 
01823     aResult.AppendLiteral("<sectiontitle>");
01824     aResult.Append(heading);
01825     aResult.AppendLiteral("</sectiontitle>");
01826   }
01827 
01828   for (i=0;i<aCount;i++) {
01829          rv = aArray[i].mCallback(this, &aArray[i], aConv, aResult);
01830     NS_ASSERTION(NS_SUCCEEDED(rv), "append callback failed");
01831   }
01832 
01833   aResult.AppendLiteral("</section>");
01834 
01835   return NS_OK;
01836 }
01837 
01838 nsresult AppendLine(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult)
01839 {
01840   nsXPIDLString attrValue;
01841   nsresult rv = aCard->GetCardValue(aItem->mColumn, getter_Copies(attrValue));
01842   NS_ENSURE_SUCCESS(rv,rv);
01843 
01844   if (attrValue.IsEmpty())
01845     return NS_OK; 
01846 
01847   nsAutoString attrNameStr;
01848   attrNameStr.AssignWithConversion(aItem->mColumn);
01849   
01850   aResult.Append(PRUnichar('<'));
01851   aResult.Append(attrNameStr);
01852   aResult.Append(PRUnichar('>'));
01853   
01854   // use ScanTXT to convert < > & to safe values.
01855   nsXPIDLString safeText;
01856   rv = aConv->ScanTXT(attrValue, mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
01857   NS_ENSURE_SUCCESS(rv,rv);
01858   aResult.Append(safeText);
01859 
01860   aResult.AppendLiteral("</");
01861   aResult.Append(attrNameStr);
01862   aResult.Append(PRUnichar('>'));
01863 
01864   return NS_OK;
01865 }
01866 
01867 nsresult AppendLabel(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult)
01868 {
01869   nsresult rv;
01870   
01871   nsCOMPtr<nsIStringBundle> bundle;
01872 
01873   nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
01874   NS_ENSURE_SUCCESS(rv,rv);
01875 
01876   rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
01877   NS_ENSURE_SUCCESS(rv,rv); 
01878   
01879   nsXPIDLString label;
01880   
01881   nsXPIDLString attrValue;
01882 
01883   rv = aCard->GetCardValue(aItem->mColumn, getter_Copies(attrValue));
01884   NS_ENSURE_SUCCESS(rv,rv);
01885 
01886   if (attrValue.IsEmpty())
01887     return NS_OK;
01888 
01889   rv = bundle->GetStringFromName(NS_ConvertASCIItoUCS2(aItem->mLabel).get(), getter_Copies(label));
01890   NS_ENSURE_SUCCESS(rv, rv);
01891 
01892   aResult.AppendLiteral("<labelrow><label>");
01893 
01894   aResult.Append(label);
01895   aResult.AppendLiteral(": </label>");
01896 
01897   rv = AppendLine(aCard, aItem, aConv, aResult);
01898   NS_ENSURE_SUCCESS(rv,rv);
01899 
01900   aResult.AppendLiteral("</labelrow>");
01901   
01902   return NS_OK;
01903 }
01904 
01905 nsresult AppendCityStateZip(nsAbCardProperty *aCard, AppendItem *aItem, mozITXTToHTMLConv *aConv, nsString &aResult) 
01906 {
01907   nsresult rv;
01908   AppendItem item;
01909   const char *stateCol, *zipCol;
01910 
01911   if (strcmp(aItem->mColumn, kHomeCityColumn) == 0) {
01912     stateCol = kHomeStateColumn;
01913     zipCol = kHomeZipCodeColumn;
01914   }
01915   else {
01916     stateCol = kWorkStateColumn;
01917     zipCol = kWorkZipCodeColumn;
01918   }
01919 
01920   nsAutoString cityResult, stateResult, zipResult;
01921 
01922   rv = AppendLine(aCard, aItem, aConv, cityResult);
01923   NS_ENSURE_SUCCESS(rv,rv);
01924   
01925   item.mColumn = stateCol;
01926   item.mLabel = "";
01927 
01928   rv = AppendLine(aCard, &item, aConv, stateResult);
01929   NS_ENSURE_SUCCESS(rv,rv);
01930 
01931   item.mColumn = zipCol;
01932 
01933   rv = AppendLine(aCard, &item, aConv, zipResult);
01934   NS_ENSURE_SUCCESS(rv,rv);
01935 
01936   nsXPIDLString formattedString;
01937 
01938   nsCOMPtr<nsIStringBundle> bundle;
01939 
01940   nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
01941   NS_ENSURE_SUCCESS(rv,rv);
01942 
01943   rv = stringBundleService->CreateBundle(sAddrbookProperties, getter_AddRefs(bundle));
01944   NS_ENSURE_SUCCESS(rv,rv); 
01945 
01946   if (!cityResult.IsEmpty() && !stateResult.IsEmpty() && !zipResult.IsEmpty()) {
01947     const PRUnichar *formatStrings[3] = { cityResult.get(), stateResult.get(), zipResult.get() };
01948     rv = bundle->FormatStringFromName(NS_LITERAL_STRING("cityAndStateAndZip").get(), formatStrings, 3, getter_Copies(formattedString));
01949     NS_ENSURE_SUCCESS(rv,rv);
01950   }
01951   else if (!cityResult.IsEmpty() && !stateResult.IsEmpty() && zipResult.IsEmpty()) {
01952     const PRUnichar *formatStrings[2] = { cityResult.get(), stateResult.get() };
01953     rv = bundle->FormatStringFromName(NS_LITERAL_STRING("cityAndStateNoZip").get(), formatStrings, 2, getter_Copies(formattedString));
01954     NS_ENSURE_SUCCESS(rv,rv);
01955   }
01956   else if ((!cityResult.IsEmpty() && stateResult.IsEmpty() && !zipResult.IsEmpty()) ||
01957           (cityResult.IsEmpty() && !stateResult.IsEmpty() && !zipResult.IsEmpty())) {
01958     const PRUnichar *formatStrings[2] = { cityResult.IsEmpty() ? stateResult.get() : cityResult.get(), zipResult.get() };
01959     rv = bundle->FormatStringFromName(NS_LITERAL_STRING("cityOrStateAndZip").get(), formatStrings, 2, getter_Copies(formattedString));
01960     NS_ENSURE_SUCCESS(rv,rv);
01961   }
01962   else {
01963     if (!cityResult.IsEmpty()) 
01964       formattedString = cityResult;
01965     else if (!stateResult.IsEmpty()) 
01966       formattedString = stateResult;
01967     else 
01968       formattedString = zipResult;
01969   }
01970 
01971   aResult.Append(formattedString);
01972 
01973   return NS_OK;
01974 }