rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsCOMTypeInfo<nsIURL>::GetIID(), getter_AddRefs(url));
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), getter_AddRefs(url));
nsMsgAccountManager::Convert4XUri(const char *old_uri, const char *default_folder_name, char **new_uri){  nsresult rv;  *new_uri = nsnull;  if (!old_uri) {    return NS_ERROR_NULL_POINTER;  }   // if the old_uri is "", don't attempt any conversion  if (PL_strlen(old_uri) == 0) {	*new_uri = PR_smprintf("");        return NS_OK;  }#ifdef DEBUG_ACCOUNTMANAGER  printf("old 4.x folder uri = >%s<\n", old_uri);#endif /* DEBUG_ACCOUNTMANAGER */  if (PL_strncasecmp(IMAP_SCHEMA,old_uri,IMAP_SCHEMA_LENGTH) == 0) {	nsCOMPtr <nsIURL> url;	nsXPIDLCString hostname;	nsXPIDLCString username;	rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsCOMTypeInfo<nsIURL>::GetIID(), getter_AddRefs(url));        if (NS_FAILED(rv)) return rv;        rv = url->SetSpec(old_uri);        if (NS_FAILED(rv)) return rv;        rv = url->GetHost(getter_Copies(hostname));        if (NS_FAILED(rv)) return rv;        rv = url->GetPreHost(getter_Copies(username));  	if (NS_FAILED(rv)) return rv;	// in 4.x, mac and windows stored the URI as IMAP://<hostname> 	// if the URI was the default folder on the server.	// If it wasn't the default folder, they would have stored it as	if (!username || (PL_strlen((const char *)username) == 0)) {		char *imap_username = nsnull;		char *prefname = nsnull;		prefname = PR_smprintf("mail.imap.server.%s.userName", (const char *)hostname);		if (!prefname) return NS_ERROR_FAILURE;		rv = m_prefs->CopyCharPref(prefname, &imap_username);		PR_FREEIF(prefname);		if (NS_FAILED(rv) || !imap_username || !*imap_username) {			*new_uri = PR_smprintf("");			return NS_ERROR_FAILURE;		}		else {			// new_uri = imap://<username>@<hostname>/<folder name>#ifdef DEBUG_ACCOUNTMANAGER			printf("new_uri = %s/%s@%s/%s\n",IMAP_SCHEMA, imap_username, (const char *)hostname, default_folder_name);#endif /* DEBUG_ACCOUNTMANAGER */			*new_uri = PR_smprintf("%s/%s@%s/%s",IMAP_SCHEMA, imap_username, (const char *)hostname, default_folder_name);			return NS_OK;      		}        }        else {		// IMAP uri's began with "IMAP:/".  we need that to be "imap:/"#ifdef DEBUG_ACCOUNTMANAGER		printf("new_uri = %s%s\n",IMAP_SCHEMA,old_uri+IMAP_SCHEMA_LENGTH);#endif /* DEBUG_ACCOUNTMANAGER */		*new_uri = PR_smprintf("%s%s",IMAP_SCHEMA,old_uri+IMAP_SCHEMA_LENGTH);		return NS_OK;	}  }  char *usernameAtHostname = nsnull;  nsCOMPtr <nsIFileSpec> mail_dir;  char *mail_directory_value = nsnull;  rv = m_prefs->GetFilePref(PREF_PREMIGRATION_MAIL_DIRECTORY, getter_AddRefs(mail_dir));  if (NS_SUCCEEDED(rv)) {	rv = mail_dir->GetUnixStyleFilePath(&mail_directory_value);  }  if (NS_FAILED(rv) || !mail_directory_value || (PL_strlen(mail_directory_value) == 0)) {#ifdef DEBUG_ACCOUNTMANAGER    printf("%s was not set, attempting to use %s instead.\n",PREF_PREMIGRATION_MAIL_DIRECTORY,PREF_MAIL_DIRECTORY);#endif    PR_FREEIF(mail_directory_value);    rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mail_dir));    if (NS_SUCCEEDED(rv)) {	rv = mail_dir->GetUnixStyleFilePath(&mail_directory_value);    }     if (NS_FAILED(rv) || !mail_directory_value || (PL_strlen(mail_directory_value) == 0)) {      NS_ASSERTION(0,"failed to get a base value for the mail.directory");      return NS_ERROR_UNEXPECTED;    }  }  PRInt32 oldMailType;  rv = m_prefs->GetIntPref(PREF_4X_MAIL_SERVER_TYPE, &oldMailType);  if (NS_FAILED(rv)) return rv;  if (oldMailType == POP_4X_MAIL_TYPE) {    char *pop_username = nsnull;    char *pop_hostname = nsnull;    rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &pop_username);    if (NS_FAILED(rv)) return rv;    rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_POP_SERVER, &pop_hostname);    if (NS_FAILED(rv)) return rv;    usernameAtHostname = PR_smprintf("%s@%s",pop_username, pop_hostname);    PR_FREEIF(pop_username);    PR_FREEIF(pop_hostname);  }  else if (oldMailType == IMAP_4X_MAIL_TYPE) {    usernameAtHostname = PR_smprintf("%s@%s",LOCAL_MAIL_FAKE_USER_NAME,LOCAL_MAIL_FAKE_HOST_NAME);  }  else if (oldMailType == MOVEMAIL_4X_MAIL_TYPE) {    printf("sorry, movemail migration not supported yet.\n");    NS_ASSERTION(0, "movemail migration not supported yet.");    return NS_ERROR_FAILURE;  }  else {#ifdef DEBUG_ACCOUNTMANAGER    printf("Unrecognized server type %d\n", oldMailType);#endif    return NS_ERROR_UNEXPECTED;  }  // mail_directory_value is already in UNIX style at this point...  if (PL_strncasecmp(MAILBOX_SCHEMA,old_uri,MAILBOX_SCHEMA_LENGTH) == 0) {#ifdef DEBUG_ACCOUNTMANAGER	printf("turn %s into %s/%s/(%s - %s)\n",old_uri,MAILBOX_SCHEMA,usernameAtHostname,old_uri + MAILBOX_SCHEMA_LENGTH,mail_directory_value);#endif	// the extra -1 is because in 4.x, we had this:	// mailbox:<PATH> instead of mailbox:/<PATH> 	*new_uri = PR_smprintf("%s/%s/%s",MAILBOX_SCHEMA,usernameAtHostname,old_uri + MAILBOX_SCHEMA_LENGTH + PL_strlen(mail_directory_value) -1);   }  else {#ifdef DEBUG_ACCOUNTMANAGER    printf("turn %s into %s/%s/(%s - %s)\n",old_uri,MAILBOX_SCHEMA,usernameAtHostname,old_uri,mail_directory_value);#endif    *new_uri = PR_smprintf("%s/%s/%s",MAILBOX_SCHEMA,usernameAtHostname,old_uri + PL_strlen(mail_directory_value));  }  if (!*new_uri) {#ifdef DEBUG_ACCOUNTMANAGER    printf("failed to convert 4.x uri: %s\n", old_uri);#endif    NS_ASSERTION(0,"uri conversion code not complete");    return NS_ERROR_FAILURE;  }  PR_FREEIF(usernameAtHostname);  PR_FREEIF(mail_directory_value);  return NS_OK;}