Esempio n. 1
0
void nsEudoraAddress::BuildABCards( PRUint32 *pBytes, nsIAddrDatabase *pDb)
{
	CAliasEntry *	pEntry;
	PRInt32			max = m_alias.Count();
	PRInt32			i;
	nsVoidArray		emailList;
  nsVoidArray membersArray;// Remember group members.
  nsVoidArray groupsArray; // Remember groups.
	
	// First off, run through the list and build person cards - groups/lists have to be done later
	for (i = 0; i < max; i++) {
		pEntry = (CAliasEntry *) m_alias.ElementAt( i);
		ResolveEntries( pEntry->m_name, pEntry->m_list, emailList);		
    if (emailList.Count() > 1)
    {
      // Remember group members uniquely and add them to db later.
      RememberGroupMembers(membersArray, emailList);
      // Remember groups and add them to db later.
      groupsArray.AppendElement(pEntry);
    }
    else
      AddSingleCard( pEntry, emailList, pDb);

		emailList.Clear();

		if (pBytes) {
			// This isn't exact but it will get us close enough
			*pBytes += (pEntry->m_name.Length() + pEntry->m_notes.Length() + 10);
		}
	}

  // Make sure group members exists before adding groups.
  nsresult rv = AddGroupMembersAsCards(membersArray, pDb);
  if (NS_FAILED(rv))
    return;

  // Now add the lists/groups (now that all cards have been added).
  max = groupsArray.Count();
  for (i = 0; i < max; i++)
  {
    pEntry = (CAliasEntry *) groupsArray.ElementAt(i);
    ResolveEntries( pEntry->m_name, pEntry->m_list, emailList);
    AddSingleList(pEntry, emailList, pDb);
    emailList.Clear();
  }
}
void nsEudoraAddress::BuildABCards( PRUint32 *pBytes, nsIAddrDatabase *pDb)
{
  CAliasEntry *  pEntry;
  PRInt32      max = m_alias.Count();
  PRInt32      i;
  nsVoidArray    emailList;
  nsVoidArray membersArray;// Remember group members.
  nsVoidArray groupsArray; // Remember groups.

  // First off, run through the list and build person cards - groups/lists have to be done later
  for (i = 0; i < max; i++) {
    PRInt32   numResolved = 0;
    pEntry = (CAliasEntry *) m_alias.ElementAt( i);

    // PR_FALSE for 4th parameter tells ResolveEntries not to add resolved entries (avoids
    // duplicates as mailing lists are being resolved to other cards - the other cards that
    // are found have already been added and don't need to be added again).
    //
    // PR_FALSE for 5th parameter tells ResolveEntries that we're calling it - it's not being
    // called recursively by itself.
    ResolveEntries( pEntry->m_name, pEntry->m_list, emailList, PR_FALSE, PR_FALSE, numResolved);

    // Treat it as a group if there's more than one email address or if we
    // needed to resolve one or more aliases. We treat single aliases to
    // other aliases as a mailing list because there's no better equivalent.
    if ( (emailList.Count() > 1) || (numResolved > 0) )
    {
      // Remember group members uniquely and add them to db later.
      RememberGroupMembers(membersArray, emailList);
      // Remember groups and add them to db later.
      groupsArray.AppendElement(pEntry);
    }
    else
      AddSingleCard( pEntry, emailList, pDb);

    emailList.Clear();

    if (pBytes) {
      // This isn't exact but it will get us close enough
      *pBytes += (pEntry->m_name.Length() + pEntry->m_notes.Length() + 10);
    }
  }

  // Make sure group members exists before adding groups.
  nsresult rv = AddGroupMembersAsCards(membersArray, pDb);
  if (NS_FAILED(rv))
    return;

  // Now add the lists/groups (now that all cards have been added).
  max = groupsArray.Count();
  for (i = 0; i < max; i++)
  {
    PRInt32   numResolved = 0;
    pEntry = (CAliasEntry *) groupsArray.ElementAt(i);

    // PR_FALSE for 4th parameter tells ResolveEntries to add resolved entries so that we
    // can create the mailing list with references to all entries correctly.
    //
    // PR_FALSE for 5th parameter tells ResolveEntries that we're calling it - it's not being
    // called recursively by itself.
    ResolveEntries( pEntry->m_name, pEntry->m_list, emailList, PR_TRUE, PR_FALSE, numResolved);
    AddSingleList(pEntry, emailList, pDb);
    emailList.Clear();
  }
}