예제 #1
0
void nsAbIPCCard::SplitAddresses(PRBool isUnicode, LPTSTR homeAddress, LPTSTR workAddress)
{
  PRInt32 idx;
  nsAutoString homeAddressStr;
  nsAutoString workAddressStr;
  if (isUnicode)
  {
    homeAddressStr.Assign(homeAddress);
    workAddressStr.Assign(workAddress);
  }
  else
  {
    CONVERT_ASSIGNTO_UNICODE(homeAddressStr, homeAddress, PR_FALSE);
    CONVERT_ASSIGNTO_UNICODE(workAddressStr, workAddress, PR_FALSE);
  }
  nsAutoString addr1, addr2;
  if ((idx = homeAddressStr.Find( "\x0D\x0A")) != kNotFound)
  {
    homeAddressStr.Left(addr1, idx);
    homeAddressStr.Right( addr2, homeAddressStr.Length() - idx - 2);  // need to minus string lenght of CRLF.
    addr2.ReplaceSubstring(NS_LITERAL_STRING("\x0D\x0A").get(),NS_LITERAL_STRING(", ").get());

    SetHomeAddress(addr1.get());
    SetHomeAddress2(addr2.get());
  }
  else
    SetHomeAddress(homeAddressStr.get());
  if ((idx = workAddressStr.Find( "\x0D\x0A")) != kNotFound)
  {
    workAddressStr.Left(addr1, idx);
    workAddressStr.Right( addr2, workAddressStr.Length() - idx - 2);  // need to minus string lenght of CRLF.
    addr2.ReplaceSubstring(NS_LITERAL_STRING("\x0D\x0A").get(),NS_LITERAL_STRING(", ").get());

    SetWorkAddress(addr1.get());
    SetWorkAddress2(addr2.get());
  }
  else
    SetWorkAddress(workAddressStr.get());
}
nsresult nsAbOutlookCard::Init(const char *aUri)
{
    nsresult retCode = nsRDFResource::Init(aUri) ;
    
    NS_ENSURE_SUCCESS(retCode, retCode) ;
    nsCAutoString entry ;
    nsCAutoString stub ;

    mAbWinType = getAbWinType(kOutlookCardScheme, mURI.get(), stub, entry) ;
    if (mAbWinType == nsAbWinType_Unknown) {
        PRINTF(("Huge problem URI=%s.\n", mURI.get())) ;
        return NS_ERROR_INVALID_ARG ;
    }
    nsAbWinHelperGuard mapiAddBook (mAbWinType) ;

    if (!mapiAddBook->IsOK()) { return NS_ERROR_FAILURE ; }
    mMapiData->Assign(entry) ;
    nsStringArray unichars ;
    ULONG i = 0 ;

    if (mapiAddBook->GetPropertiesUString(*mMapiData, OutlookCardMAPIProps, index_LastProp, unichars)) {
        SetFirstName(*unichars[index_FirstName]);
        SetLastName(*unichars[index_LastName]);
        SetDisplayName(*unichars[index_DisplayName]);
        SetNickName(*unichars[index_NickName]);
        SetPrimaryEmail(*unichars[index_EmailAddress]);
        SetWorkPhone(*unichars[index_WorkPhoneNumber]);
        SetHomePhone(*unichars[index_HomePhoneNumber]);
        SetFaxNumber(*unichars[index_WorkFaxNumber]);
        SetPagerNumber(*unichars[index_PagerNumber]);
        SetCellularNumber(*unichars[index_MobileNumber]);
        SetHomeCity(*unichars[index_HomeCity]);
        SetHomeState(*unichars[index_HomeState]);
        SetHomeZipCode(*unichars[index_HomeZip]);
        SetHomeCountry(*unichars[index_HomeCountry]);
        SetWorkCity(*unichars[index_WorkCity]);
        SetWorkState(*unichars[index_WorkState]);
        SetWorkZipCode(*unichars[index_WorkZip]);
        SetWorkCountry(*unichars[index_WorkCountry]);
        SetJobTitle(*unichars[index_JobTitle]);
        SetDepartment(*unichars[index_Department]);
        SetCompany(*unichars[index_Company]);
        SetWebPage1(*unichars[index_WorkWebPage]);
        SetWebPage2(*unichars[index_HomeWebPage]);
        SetNotes(*unichars[index_Comments]);
    }
    ULONG cardType = 0 ;
    nsCAutoString normalChars ;
    
    if (mapiAddBook->GetPropertyLong(*mMapiData, PR_OBJECT_TYPE, cardType)) {
        SetIsMailList(cardType == MAPI_DISTLIST) ;
        if (cardType == MAPI_DISTLIST) {
            buildAbWinUri(kOutlookDirectoryScheme, mAbWinType, normalChars) ;
            normalChars.Append(entry) ;
            SetMailListURI(normalChars.get()) ;
        }
    }
    nsAutoString unichar ;
    nsAutoString unicharBis ;

    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_HOME_ADDRESS_STREET_W, unichar)) {
        splitString(unichar, unicharBis) ;
        SetHomeAddress(unichar) ;
        SetHomeAddress2(unicharBis) ;
    }
    if (mapiAddBook->GetPropertyUString(*mMapiData, PR_BUSINESS_ADDRESS_STREET_W, unichar)) {
        splitString(unichar, unicharBis) ;
        SetWorkAddress(unichar) ;
        SetWorkAddress2(unicharBis) ;
    }
    WORD year = 0 ;
    WORD month = 0 ;
    WORD day = 0 ;

    if (mapiAddBook->GetPropertyDate(*mMapiData, PR_BIRTHDAY, year, month, day)) {
        wordToUnicode(year, unichar);
        SetBirthYear(unichar);
        wordToUnicode(month, unichar);
        SetBirthMonth(unichar);
        wordToUnicode(day, unichar);
        SetBirthDay(unichar);
    }
    return retCode ;
}