Example #1
0
NS_IMETHODIMP nsAbView::ClearView()
{
  mDirectory = nsnull;
  mAbViewListener = nsnull;
  if (mTree)
    mTree->SetView(nsnull);
  mTree = nsnull;
  mTreeSelection = nsnull;

  if (mInitialized)
  {
    nsresult rv;
    mInitialized = false;
    nsCOMPtr<nsIPrefBranch2> pbi(do_GetService(NS_PREFSERVICE_CONTRACTID,
                                               &rv));
    NS_ENSURE_SUCCESS(rv,rv);

    rv = pbi->RemoveObserver(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, this);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
                                                   &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = abManager->RemoveAddressBookListener(this);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  PRInt32 i = mCards.Count();
  while(i-- > 0)
    NS_ASSERTION(NS_SUCCEEDED(RemoveCardAt(i)), "remove card failed\n");

  return NS_OK;
}
Example #2
0
nsresult nsAbView::Initialize()
{
  if (mInitialized)
    return NS_OK;

  mInitialized = true;

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = abManager->AddAddressBookListener(this, nsIAbListener::all);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIPrefBranch2> pbi(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = pbi->AddObserver(PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST, this, false);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!mABBundle)
  {
    nsCOMPtr<nsIStringBundleService> stringBundleService =
      do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); 
    NS_ENSURE_SUCCESS(rv, rv);

    rv = stringBundleService->CreateBundle("chrome://messenger/locale/addressbook/addressBook.properties", getter_AddRefs(mABBundle));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return SetGeneratedNameFormatFromPrefs();
}
Example #3
0
NS_IMETHODIMP
nsAbOSXDirFactory::GetDirectories(const nsAString &aDirName,
                                  const nsACString &aURI,
                                  const nsACString &aPrefName,
                                  nsISimpleEnumerator **aDirectories)
{
  NS_ENSURE_ARG_POINTER(aDirectories);
  
  *aDirectories = nsnull;

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX "/"),
                               getter_AddRefs(directory));
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCOMPtr<nsIAbOSXDirectory> osxDirectory(do_QueryInterface(directory, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = osxDirectory->AssertChildNodes();
  NS_ENSURE_SUCCESS(rv, rv);
  
  return NS_NewSingletonEnumerator(aDirectories, osxDirectory);
}
nsresult    
nsAddbookProtocolHandler::GeneratePrintOutput(nsIAddbookUrl *addbookUrl, 
                                              nsString &aOutput)
{
  NS_ENSURE_ARG_POINTER(addbookUrl);

  nsAutoCString uri;
  nsresult rv = addbookUrl->GetPath(uri);
  NS_ENSURE_SUCCESS(rv,rv);

  /* turn
   "//moz-abmdbdirectory/abook.mab?action=print"
   into "moz-abmdbdirectory://abook.mab"
  */

  /* 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"
   */
  int32_t pos = uri.Find("?action=print");
	if (pos == -1)
    return NS_ERROR_UNEXPECTED;

  uri.SetLength(pos);

  /* step 2:  
   turn "moz-abmdbdirectory/abook.mab"
   into "moz-abmdbdirectory://abook.mab"
   */
  pos = uri.FindChar('/');
  if (pos == -1)
    return NS_ERROR_UNEXPECTED;

  uri.Insert('/', pos);
  uri.Insert(':', pos);

  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = BuildDirectoryXML(directory, aOutput);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
Example #5
0
NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsISimpleEnumerator** result)
{
    nsresult rv;

    // when offline, we need to get the child cards for the local, replicated mdb directory
    PRBool offline;
    nsCOMPtr <nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv,rv);
    rv = ioService->GetOffline(&offline);
    NS_ENSURE_SUCCESS(rv,rv);

    if (offline) {
        nsCString fileName;
        rv = GetReplicationFileName(fileName);
        NS_ENSURE_SUCCESS(rv,rv);

        // if there is no fileName, bail out now.
        if (fileName.IsEmpty())
            return NS_OK;

        // perform the same query, but on the local directory
        nsCAutoString localDirectoryURI(NS_LITERAL_CSTRING(kMDBDirectoryRoot));
        localDirectoryURI.Append(fileName);
        if (mIsQueryURI)
        {
            localDirectoryURI.AppendLiteral("?");
            localDirectoryURI.Append(mQueryString);
        }

        nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
                                         &rv));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr <nsIAbDirectory> directory;
        rv = abManager->GetDirectory(localDirectoryURI,
                                     getter_AddRefs(directory));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = directory->GetChildCards(result);
    }
    else {
        // Start the search
        rv = StartSearch();
        NS_ENSURE_SUCCESS(rv, rv);

        rv = NS_NewEmptyEnumerator(result);
    }

    NS_ENSURE_SUCCESS(rv,rv);
    return rv;
}
NS_IMETHODIMP
nsAbLDAPDirFactory::GetDirectories(const nsAString &aDirName,
                                   const nsACString &aURI,
                                   const nsACString &aPrefName,
                                   nsISimpleEnumerator **aDirectories)
{
  NS_ENSURE_ARG_POINTER(aDirectories);

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  if (Substring(aURI, 0, 5).EqualsLiteral("ldap:") ||
      Substring(aURI, 0, 6).EqualsLiteral("ldaps:")) {
    /*
     * If the URI starts with ldap: or ldaps:
     * then this directory is an LDAP directory.
     *
     * We don't want to use the ldap:// or ldaps:// URI 
     * as the URI because the ldap:// or ldaps:// URI 
     * will contain the hostname, basedn, port, etc.
     * so if those attributes changed, we'll run into the
     * the same problem that we hit with changing username / hostname
     * for mail servers.  To solve this problem, we add an extra
     * level of indirection.  The URI that we generate
     * (the bridge URI) will be moz-abldapdirectory://<prefName>
     * and when we need the hostname, basedn, port, etc,
     * we'll use the <prefName> to get the necessary prefs.
     * note, <prefName> does not change.
     */
    nsAutoCString bridgeURI;
    bridgeURI = NS_LITERAL_CSTRING(kLDAPDirectoryRoot);
    bridgeURI += aPrefName;
    rv = abManager->GetDirectory(bridgeURI, getter_AddRefs(directory));
  }
  else {
    rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
  }
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_NewSingletonEnumerator(aDirectories, directory);
}
/**
 * Returns the first card found with a given property name/value pair. This
 * returns an already addrefed pointer to the card if the card is found.
 */
already_AddRefed<nsIAbCard>
nsAbAddressCollector::GetCardFromProperty(const char *aName,
                                          const nsACString &aValue,
                                          nsIAbDirectory **aDirectory)
{
  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, nullptr);

  nsCOMPtr<nsISimpleEnumerator> enumerator;
  rv = abManager->GetDirectories(getter_AddRefs(enumerator));
  NS_ENSURE_SUCCESS(rv, nullptr);

  bool hasMore;
  nsCOMPtr<nsISupports> supports;
  nsCOMPtr<nsIAbDirectory> directory;
  nsCOMPtr<nsIAbCard> result;
  while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore)
  {
    rv = enumerator->GetNext(getter_AddRefs(supports));
    NS_ENSURE_SUCCESS(rv, nullptr);

    directory = do_QueryInterface(supports, &rv);
    if (NS_FAILED(rv))
      continue;

    // Some implementations may return NS_ERROR_NOT_IMPLEMENTED here,
    // so just catch the value and continue.
    if (NS_FAILED(directory->GetCardFromProperty(aName, aValue, true,
                                                 getter_AddRefs(result))))
      continue;

    if (result)
    {
      if (aDirectory)
        directory.forget(aDirectory);
      return result.forget();
    }
  }
  return nullptr;
}
nsresult nsAbPalmHotSync::KeepCurrentStateAsPrevious()
{
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_OK;

    nsCAutoString previousLeafName(mFileName);
    previousLeafName += PREVIOUS_EXTENSION;

    if(!mPreviousABFile) 
    {
      nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
      if (NS_FAILED(rv))
        return rv;

      rv = abManager->GetUserProfileDirectory(getter_AddRefs(mPreviousABFile));
      if (NS_SUCCEEDED(rv))
      {
        mPreviousABFile->AppendNative(previousLeafName);
        if (NS_FAILED(rv))
          return rv;
      }
    }

    PRBool bExists=PR_FALSE;
    mABFile->Exists(&bExists);
    if(bExists) 
    {
        mPreviousABFile->Exists(&bExists);
        if(bExists)
            rv = mPreviousABFile->Remove(PR_FALSE);
        nsCOMPtr<nsIFile> parent;
        rv = mABFile->GetParent(getter_AddRefs(parent));
        if (NS_SUCCEEDED(rv))
            rv = mABFile->CopyToNative(parent, previousLeafName);
    }        
    return rv;
}
// Performs the necessary changes to set up the collector for the specified
// collected address book.
void
nsAbAddressCollector::SetUpAbFromPrefs(nsIPrefBranch *aPrefBranch)
{
  nsCString abURI;
  aPrefBranch->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK,
                           getter_Copies(abURI));

  if (abURI.IsEmpty())
    abURI.AssignLiteral(kPersonalAddressbookUri);

  if (abURI == mABURI)
    return;

  mDirectory = nullptr;
  mABURI = abURI;

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS_VOID(rv);

  rv = abManager->GetDirectory(mABURI, getter_AddRefs(mDirectory));
  NS_ENSURE_SUCCESS_VOID(rv);

  bool readOnly;
  rv = mDirectory->GetReadOnly(&readOnly);
  NS_ENSURE_SUCCESS_VOID(rv);

  // If the directory is read-only, we can't write to it, so just blank it out
  // here, and warn because we shouldn't hit this (UI is wrong).
  if (readOnly)
  {
    NS_ERROR("Address Collection book preferences is set to a read-only book. "
             "Address collection will not take place.");
    mDirectory = nullptr;
  }
}
nsresult nsAbPalmHotSync::OpenABDBForHotSync(PRBool aCreate)
{
    if(!mInitialized) 
        return NS_ERROR_NOT_INITIALIZED;

    // if already open
    if(mDBOpen && mABDB && mDirectory)
        return NS_OK;

    if(mFileName.IsEmpty())
        return NS_ERROR_FILE_INVALID_PATH;

    nsresult rv;
    nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
    if (NS_FAILED(rv))
      return rv;

    rv = abManager->GetUserProfileDirectory(getter_AddRefs(mABFile));
    if (NS_FAILED(rv))
      return rv;

    mABFile->AppendNative(mFileName);

    nsCOMPtr<nsIAddrDatabase> addrDBFactory = 
             do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
    if(NS_FAILED(rv)) 
    {
        return rv;
    }
    
    rv = addrDBFactory->Open(mABFile, aCreate, PR_TRUE, getter_AddRefs(mABDB));
    NS_ENSURE_SUCCESS(rv, rv);
    mDBOpen = PR_TRUE;  // Moz AB DB is now Open

    return rv;
}
// Get the list of Address Books for the currently logged in user profile
STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount,
                                       lpnsMozABDesc * aABList, long ** aABCatIndexList, BOOL ** aDirFlagsList)
{
    if (!aABListCount || !aABList || !aABCatIndexList ||!aDirFlagsList)
        return E_FAIL;
    *aABListCount = 0;

    nsresult rv;
    nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
    if (NS_FAILED(rv))
        return E_FAIL;

    nsCOMPtr<nsISimpleEnumerator> subDirectories;
    if (NS_SUCCEEDED(abManager->GetDirectories(getter_AddRefs(subDirectories))) &&
            subDirectories)
    {
        // Get the total number of addrbook.
        PRInt16 count=0;
        nsCOMPtr<nsISupports> item;
        PRBool hasMore;
        while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
        {
            if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item))))
            {
                nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(item, &rv));
                if (NS_SUCCEEDED(rv))
                {
                    nsCAutoString fileName;
                    rv = directory->GetFileName(fileName);
                    if(NS_FAILED(rv))
                        continue;
                    PRInt32 dirType;
                    rv = directory->GetDirType(&dirType);
                    if(NS_FAILED(rv))
                        continue;

                    PRBool disableThisAB;
                    rv = directory->GetBoolValue("disablePalmSync",
                                                 PR_FALSE, &disableThisAB);
                    if (NS_FAILED(rv))
                        continue;

                    // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
                    if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) &&
                                          strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
                            (dirType != kPABDirectory && dirType != kMAPIDirectory))
                        continue;
                }
            }
            count++;
        }

        if (!count)
            return E_FAIL;  // should not happen but just in case.

        lpnsMozABDesc serverDescList = (lpnsMozABDesc) CoTaskMemAlloc(sizeof(nsMozABDesc) * count);
        BOOL *dirFlagsList = (BOOL *) CoTaskMemAlloc(sizeof(BOOL) * count);
        long *catIndexList = (long *) CoTaskMemAlloc(sizeof(long) * count);

        *aABListCount = count;
        *aABList = serverDescList;
        *aDirFlagsList = dirFlagsList;
        *aABCatIndexList = catIndexList;

        // reset enumerator
        if (NS_FAILED(abManager->GetDirectories(getter_AddRefs(subDirectories))))
            return E_FAIL;

        // For each valid addrbook collect info.
        while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
        {
            if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item))))
            {
                nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(item, &rv));
                if (NS_SUCCEEDED(rv))
                {
                    // We don't have to skip mailing list since there's no mailing lists at the top level.
                    nsCAutoString fileName;
                    nsCAutoString uri;
                    nsString description;
                    PRUint32 palmSyncTimeStamp;
                    PRInt32 dirType, palmCategoryIndex;

                    rv = directory->GetDescription(description);
                    if(NS_FAILED(rv)) return E_FAIL;
                    rv = directory->GetFileName(fileName);
                    if(NS_FAILED(rv)) return E_FAIL;
                    rv = directory->GetURI(uri);
                    if(NS_FAILED(rv)) return E_FAIL;
                    rv = directory->GetDirType(&dirType);
                    if(NS_FAILED(rv)) return E_FAIL;
                    rv = directory->GetIntValue("PalmCategoryId", -1, &palmCategoryIndex);
                    if (NS_FAILED(rv)) return E_FAIL;
                    rv = directory->GetIntValue("PalmSyncTimeStamp", 0,
                                                (PRInt32*)&palmSyncTimeStamp);
                    if (NS_FAILED(rv)) return E_FAIL;

                    PRBool disableThisAB;
                    rv = directory->GetBoolValue("disablePalmSync", PR_FALSE, &disableThisAB);
                    if (NS_FAILED(rv)) return E_FAIL;

                    // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's
                    if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) &&
                                          strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
                            (dirType != kPABDirectory && dirType != kMAPIDirectory))
                    {
                        continue;
                    }

                    if(aIsUnicode)
                    {
                        // convert uri to Unicode
                        nsAutoString abUrl;
                        rv = ConvertToUnicode("UTF-8", uri, abUrl);
                        if (NS_FAILED(rv))
                            break;
                        // add to the list
                        CopyUnicodeString(&(serverDescList->lpszABName), description);
                        CopyUnicodeString(&(serverDescList->lpszABUrl), abUrl);
                    }
                    else {
                        // we need to convert uri to Unicode and then to ASCII
                        nsAutoString abUUrl;

                        rv = ConvertToUnicode("UTF-8", uri, abUUrl);
                        if (NS_FAILED(rv))
                            break;

                        CopyCString(&(serverDescList->lpszABName),
                                    NS_ConvertUTF16toUTF8(description));
                        CopyCString(&(serverDescList->lpszABUrl),
                                    NS_ConvertUTF16toUTF8(abUUrl));
                    }
                    serverDescList++;

                    PRUint32 dirFlag = 0;
                    if (palmSyncTimeStamp <= 0)
                        dirFlag |= kFirstTimeSyncDirFlag;
                    // was this the pab?
                    nsCAutoString prefName;
                    rv = directory->GetDirPrefId(prefName);
                    if (NS_FAILED(rv))
                        break;

                    if (prefName.Equals("ldap_2.servers.pab"))
                        dirFlag |= kIsPabDirFlag;
                    *dirFlagsList = (BOOL) dirFlag;
                    dirFlagsList++;

                    *catIndexList = palmCategoryIndex;
                    catIndexList++;
                }
            }
        }

        // assign member variables to the beginning of the list
        serverDescList = *aABList;
        dirFlagsList = *aDirFlagsList;
        catIndexList = *aABCatIndexList;

        if(NS_FAILED(rv))
            return E_FAIL;
    }
    return S_OK;
}
nsresult nsAbPalmHotSync::GetABInterface()
{
  // Use GetChildNodes() call here.
  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return E_FAIL;

  nsString description;
  nsCString fileName, uri, prefName;
  PRUint32 palmSyncTimeStamp;
  PRInt32 dirType, palmCategoryIndex;
  nsCOMPtr<nsISimpleEnumerator> subDirectories;
  if (NS_FAILED(abManager->GetDirectories(getter_AddRefs(subDirectories))) || !subDirectories)
    return E_FAIL;

  // Check each valid addrbook.
  nsCOMPtr<nsISupports> item;
  nsCOMPtr<nsIAbDirectory> directory;
  PRBool hasMore;
  while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore)
  {
    if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item))))
    {
      directory = do_QueryInterface(item, &rv);
      if (NS_SUCCEEDED(rv))
      {
        // TODO: may need to skip mailing list?? but maybe not since there's no mailing list on the top level.

        rv = directory->GetDescription(description);
        if(NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetFileName(fileName);
        if(NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetURI(uri);
        if(NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetDirType(&dirType);
        if(NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetDirPrefId(prefName);
        if (NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetIntValue("PalmCategoryId", -1, &palmCategoryIndex);
        if (NS_FAILED(rv)) return E_FAIL;
        rv = directory->GetIntValue("PalmSyncTimeStamp", 0,
                                    (PRInt32*)&palmSyncTimeStamp);
        if (NS_FAILED(rv)) return E_FAIL;

        // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension).
        if (((fileName.Length() > kABFileName_PreviousSuffixLen) && 
            strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) ||
            (dirType != kPABDirectory && dirType != kMAPIDirectory))
          continue;

        // If Palm category is already assigned to AB then just check that (ie, was synced before).
        if((palmCategoryIndex > -1) && (mPalmCategoryIndex == palmCategoryIndex))
          break;

        // If Palm category is not already assigned check the AB name (ie, never
        // synced before). Note that Palm category name is only 15 chars max.
        if (description.Length() > 15 && mAbName.Length() <= 15)
          description.Cut(15, description.Length()-15);

        // check for matching AB+Category, and special case personal address book
        // to match "Personal" category.
        if(description == mAbName || 
            (prefName.Equals("ldap_2.servers.pab", nsCaseInsensitiveCStringComparator())
             && mAbName.LowerCaseEqualsLiteral("personal")))
          break;
        directory = nsnull;
      }
    }
  }

  // If not found return error.
  if(!directory)
    return NS_ERROR_FILE_NOT_FOUND;

  mDirectory = directory;
  mFileName = fileName;
  mUri = uri;
  mDescription = description;
  mDirType = dirType;
  mPalmSyncTimeStamp = palmSyncTimeStamp;

  return NS_OK;
}
Example #13
0
NS_IMETHODIMP nsSpamSettings::Initialize(nsIMsgIncomingServer *aServer)
{
  NS_ENSURE_ARG_POINTER(aServer);
  nsresult rv;
  PRInt32 spamLevel;
  rv = aServer->GetIntValue("spamLevel", &spamLevel);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetLevel(spamLevel);
  NS_ENSURE_SUCCESS(rv, rv);

  bool moveOnSpam;
  rv = aServer->GetBoolValue("moveOnSpam", &moveOnSpam);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetMoveOnSpam(moveOnSpam);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 moveTargetMode;
  rv = aServer->GetIntValue("moveTargetMode", &moveTargetMode);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetMoveTargetMode(moveTargetMode);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString spamActionTargetAccount;
  rv = aServer->GetCharValue("spamActionTargetAccount", spamActionTargetAccount);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetActionTargetAccount(spamActionTargetAccount.get());
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString spamActionTargetFolder;
  rv = aServer->GetCharValue("spamActionTargetFolder", spamActionTargetFolder);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetActionTargetFolder(spamActionTargetFolder.get());
  NS_ENSURE_SUCCESS(rv, rv);

  bool useWhiteList;
  rv = aServer->GetBoolValue("useWhiteList", &useWhiteList);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetUseWhiteList(useWhiteList);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString whiteListAbURI;
  rv = aServer->GetCharValue("whiteListAbURI", whiteListAbURI);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetWhiteListAbURI(whiteListAbURI.get());
  NS_ENSURE_SUCCESS(rv, rv);

  bool purgeSpam;
  rv = aServer->GetBoolValue("purgeSpam", &purgeSpam);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetPurge(purgeSpam);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 purgeSpamInterval;
  rv = aServer->GetIntValue("purgeSpamInterval", &purgeSpamInterval);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetPurgeInterval(purgeSpamInterval);
  NS_ENSURE_SUCCESS(rv, rv);

  bool useServerFilter;
  rv = aServer->GetBoolValue("useServerFilter", &useServerFilter);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetUseServerFilter(useServerFilter);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString serverFilterName;
  rv = aServer->GetCharValue("serverFilterName", serverFilterName);
  if (NS_SUCCEEDED(rv))
    SetServerFilterName(serverFilterName);
  PRInt32 serverFilterTrustFlags = 0;
  rv = aServer->GetIntValue("serverFilterTrustFlags", &serverFilterTrustFlags);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = SetServerFilterTrustFlags(serverFilterTrustFlags);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  if (prefBranch)
    prefBranch->GetCharPref("mail.trusteddomains",
                            getter_Copies(mTrustedMailDomains));

  mWhiteListDirArray.Clear();
  if (!mWhiteListAbURI.IsEmpty())
  {
    nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsTArray<nsCString> whiteListArray;
    ParseString(mWhiteListAbURI, ' ', whiteListArray);

    for (PRUint32 index = 0; index < whiteListArray.Length(); index++)
    {
      nsCOMPtr<nsIAbDirectory> directory;
      rv = abManager->GetDirectory(whiteListArray[index],
                                   getter_AddRefs(directory));
      NS_ENSURE_SUCCESS(rv, rv);

      if (directory)
        mWhiteListDirArray.AppendObject(directory);
    }
  }

  // the next two preferences affect whether we try to whitelist our own
  // address or domain. Spammers send emails with spoofed from address matching
  // either the email address of the recipient, or the recipient's domain,
  // hoping to get whitelisted.
  //
  // The terms to describe this get wrapped up in chains of negatives. A full
  // definition of the boolean inhibitWhiteListingIdentityUser is "Suppress address
  // book whitelisting if the sender matches an identity's email address"

  rv = aServer->GetBoolValue("inhibitWhiteListingIdentityUser",
                             &mInhibitWhiteListingIdentityUser);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = aServer->GetBoolValue("inhibitWhiteListingIdentityDomain",
                             &mInhibitWhiteListingIdentityDomain);
  NS_ENSURE_SUCCESS(rv, rv);

  // collect lists of identity users if needed
  if (mInhibitWhiteListingIdentityDomain || mInhibitWhiteListingIdentityUser)
  {
    nsCOMPtr<nsIMsgAccountManager>
      accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIMsgAccount> account;
    rv = accountManager->FindAccountForServer(aServer, getter_AddRefs(account));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCAutoString accountKey;
    if (account) 
      account->GetKey(accountKey);

    // Loop through all accounts, adding emails from this account, as well as
    // from any accounts that defer to this account.
    mEmails.Clear();
    nsCOMPtr<nsISupportsArray> accounts;
    rv = accountManager->GetAccounts(getter_AddRefs(accounts));
    NS_ENSURE_SUCCESS(rv, rv);
    PRUint32 accountCount = 0;
    if (account && accounts) // no sense scanning accounts if we've nothing to match
      accounts->Count(&accountCount);

    for (PRUint32 i = 0; i < accountCount; i++)
    {
      nsCOMPtr<nsIMsgAccount> loopAccount(do_QueryElementAt(accounts, i));
      if (!loopAccount)
        continue;
      nsCAutoString loopAccountKey;
      loopAccount->GetKey(loopAccountKey);
      nsCOMPtr<nsIMsgIncomingServer> loopServer;
      loopAccount->GetIncomingServer(getter_AddRefs(loopServer));
      nsCAutoString deferredToAccountKey;
      if (loopServer)
        loopServer->GetCharValue("deferred_to_account", deferredToAccountKey);

      // Add the emails for any account that defers to this one, or for the
      // account itself.
      if (accountKey.Equals(deferredToAccountKey) || accountKey.Equals(loopAccountKey))
      {
        nsCOMPtr<nsISupportsArray> identities;
        loopAccount->GetIdentities(getter_AddRefs(identities));
        if (!identities)
          continue;
        PRUint32 identityCount = 0;
        identities->Count(&identityCount);
        for (PRUint32 j = 0; j < identityCount; ++j)
        {
          nsCOMPtr<nsIMsgIdentity> identity(do_QueryElementAt(identities, j));
          if (!identity)
            continue;
          nsCAutoString email;
          identity->GetEmail(email);
          if (!email.IsEmpty())
            mEmails.AppendElement(email);
        }
      }
    }
  }

  return UpdateJunkFolderState();
}
Example #14
0
NS_IMETHODIMP nsAbView::GetSelectedAddresses(nsIArray **_retval)
{
  NS_ENSURE_ARG_POINTER(_retval);

  nsresult rv;
  nsCOMPtr<nsIMutableArray> selectedCards = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = GetSelectedCards(selectedCards);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIMutableArray> addresses = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  PRUint32 count;
  selectedCards->GetLength(&count);

  for (PRUint32 i = 0; i < count; i++) {
    nsCOMPtr<nsIAbCard> card(do_QueryElementAt(selectedCards, i, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    bool isMailList;
    card->GetIsMailList(&isMailList);
    nsAutoString primaryEmail;
    if (isMailList) {
      nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
                                                     &rv));
      NS_ENSURE_SUCCESS(rv, rv);

      nsCString mailListURI;
      rv = card->GetMailListURI(getter_Copies(mailListURI));
      NS_ENSURE_SUCCESS(rv, rv);

      nsCOMPtr<nsIAbDirectory> mailList;
      rv = abManager->GetDirectory(mailListURI, getter_AddRefs(mailList));
      NS_ENSURE_SUCCESS(rv, rv);

      nsCOMPtr<nsIMutableArray> mailListAddresses;
      rv = mailList->GetAddressLists(getter_AddRefs(mailListAddresses));
      NS_ENSURE_SUCCESS(rv,rv);

      PRUint32 mailListCount = 0;
      mailListAddresses->GetLength(&mailListCount);	

      for (PRUint32 j = 0; j < mailListCount; j++) {
        nsCOMPtr<nsIAbCard> mailListCard = do_QueryElementAt(mailListAddresses, j, &rv);
        NS_ENSURE_SUCCESS(rv,rv);

        rv = mailListCard->GetPrimaryEmail(primaryEmail);
        NS_ENSURE_SUCCESS(rv,rv);

        if (!primaryEmail.IsEmpty()) {
          nsCOMPtr<nsISupportsString> supportsEmail(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
          supportsEmail->SetData(primaryEmail);
          addresses->AppendElement(supportsEmail, false);
        }
      }
    }
    else {
      rv = card->GetPrimaryEmail(primaryEmail);
      NS_ENSURE_SUCCESS(rv,rv);

      if (!primaryEmail.IsEmpty()) {
        nsCOMPtr<nsISupportsString> supportsEmail(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
        supportsEmail->SetData(primaryEmail);
        addresses->AppendElement(supportsEmail, false);
      }
    }    
  }

  NS_IF_ADDREF(*_retval = addresses);

  return NS_OK;
}