/* void addIdentity (in nsIMsgIdentity identity); */ NS_IMETHODIMP nsMsgAccount::AddIdentity(nsIMsgIdentity *identity) { NS_ENSURE_ARG_POINTER(identity); // hack hack - need to add this to the list of identities. // for now just treat this as a Setxxx accessor // when this is actually implemented, don't refcount the default identity nsCString key; nsresult rv = identity->GetKey(key); if (NS_SUCCEEDED(rv)) { nsCString identityList; m_prefs->GetCharPref("identities", getter_Copies(identityList)); nsCAutoString newIdentityList(identityList); nsCAutoString testKey; // temporary to strip whitespace bool foundIdentity = false; // if the input identity is found if (!identityList.IsEmpty()) { char *newStr = identityList.BeginWriting(); char *token = NS_strtok(",", &newStr); // look for the identity key that we're adding while (token) { testKey = token; testKey.StripWhitespace(); if (testKey.Equals(key)) foundIdentity = true; token = NS_strtok(",", &newStr); } } // if it didn't already exist, append it if (!foundIdentity) { if (newIdentityList.IsEmpty()) newIdentityList = key; else { newIdentityList.Append(','); newIdentityList.Append(key); } } m_prefs->SetCharPref("identities", newIdentityList.get()); } // now add it to the in-memory list rv = addIdentityInternal(identity); if (!m_defaultIdentity) SetDefaultIdentity(identity); return rv; }
/* void addIdentity (in nsIMsgIdentity identity); */ NS_IMETHODIMP nsMsgAccount::AddIdentity(nsIMsgIdentity *identity) { // hack hack - need to add this to the list of identities. // for now just treat this as a Setxxx accessor // when this is actually implemented, don't refcount the default identity nsresult rv; nsXPIDLCString key; rv = identity->GetKey(getter_Copies(key)); if (NS_SUCCEEDED(rv)) { nsCAutoString identitiesKeyPref("mail.account."); identitiesKeyPref.Append(m_accountKey); identitiesKeyPref.Append(".identities"); nsXPIDLCString identityList; m_prefs->GetCharPref(identitiesKeyPref.get(), getter_Copies(identityList)); nsCAutoString newIdentityList(identityList); nsCAutoString testKey; // temporary to strip whitespace PRBool foundIdentity = PR_FALSE; // if the input identity is found // nsCRT::strtok will be unhappy with an empty string if (!identityList.IsEmpty()) { // const-casting because nsCRT::strtok whacks the string, // but safe because identityList is a copy char *newStr; char *rest = identityList.BeginWriting(); char *token = nsCRT::strtok(rest, ",", &newStr); // look for the identity key that we're adding while (token) { testKey = token; testKey.StripWhitespace(); if (testKey.Equals(key)) foundIdentity = PR_TRUE; token = nsCRT::strtok(newStr, ",", &newStr); } } // if it didn't already exist, append it if (!foundIdentity) { if (newIdentityList.IsEmpty()) newIdentityList = key; else { newIdentityList.Append(','); newIdentityList.Append(key); } } m_prefs->SetCharPref(identitiesKeyPref.get(), newIdentityList.get()); } // now add it to the in-memory list rv = addIdentityInternal(identity); if (!m_defaultIdentity) SetDefaultIdentity(identity); return rv; }