Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
nsMsgAccount Class Reference

#include <nsMsgAccount.h>

Inheritance diagram for nsMsgAccount:
Inheritance graph
[legend]
Collaboration diagram for nsMsgAccount:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgAccount ()
virtual ~nsMsgAccount ()
void init ()
void addIdentity (in nsIMsgIdentity identity)
void removeIdentity (in nsIMsgIdentity identity)
void clearAllValues ()
wstring toString ()

Public Attributes

attribute string key
attribute nsIMsgIncomingServer incomingServer
readonly attribute nsISupportsArray identities
attribute nsIMsgIdentity defaultIdentity

Private Member Functions

nsresult getPrefService ()
nsresult createIncomingServer ()
nsresult createIdentities ()
nsresult addIdentityInternal (nsIMsgIdentity *identity)

Private Attributes

nsXPIDLCString m_accountKey
nsCOMPtr< nsIPrefBranchm_prefs
nsCOMPtr< nsIMsgIncomingServerm_incomingServer
nsCOMPtr< nsIMsgIdentitym_defaultIdentity
nsCOMPtr< nsISupportsArraym_identities

Detailed Description

Definition at line 42 of file nsMsgAccount.h.


Constructor & Destructor Documentation

Definition at line 59 of file nsMsgAccount.cpp.

{
}

Definition at line 63 of file nsMsgAccount.cpp.

{
}

Member Function Documentation

void nsIMsgAccount::addIdentity ( in nsIMsgIdentity  identity) [inherited]

Definition at line 309 of file nsMsgAccount.cpp.

{
  NS_ASSERTION(m_identities,"you never called Init()");
  if (!m_identities) return NS_ERROR_FAILURE;  

  return m_identities->AppendElement(identity);
}

Here is the caller graph for this function:

Definition at line 199 of file nsMsgAccount.cpp.

{
  NS_ASSERTION(!m_identities, "only call createIdentities() once!");
  if (m_identities) return NS_ERROR_FAILURE;

  NS_ENSURE_TRUE((const char*)m_accountKey, NS_ERROR_NOT_INITIALIZED);
  
  NS_NewISupportsArray(getter_AddRefs(m_identities));

  // get the pref
  // ex) mail.account.myaccount.identities = "joe-home,joe-work"
  nsCAutoString identitiesKeyPref("mail.account.");
  identitiesKeyPref.Append(m_accountKey);
  identitiesKeyPref.Append(".identities");
  
  nsXPIDLCString identityKey;
  nsresult rv;
  rv = getPrefService();
  if (NS_FAILED(rv)) return rv;
  
  rv = m_prefs->GetCharPref(identitiesKeyPref.get(), getter_Copies(identityKey));

  if (NS_FAILED(rv)) return rv;
  if (identityKey.IsEmpty())    // not an error if no identities, but 
    return NS_OK;               // nsCRT::strtok will be unhappy
  
#ifdef DEBUG_alecf
  printf("%s's identities: %s\n",
         (const char*)m_accountKey,
         (const char*)identityKey);
#endif
  
  // get the server from the account manager
  nsCOMPtr<nsIMsgAccountManager> accountManager = 
           do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  // const-casting because nsCRT::strtok whacks the string,
  // but safe because identityKey is a copy
  char* newStr;
  char* rest = identityKey.BeginWriting();
  char* token = nsCRT::strtok(rest, ",", &newStr);

  // temporaries used inside the loop
  nsCOMPtr<nsIMsgIdentity> identity;
  nsCAutoString key;

  // iterate through id1,id2, etc
  while (token) {
    key = token;
    key.StripWhitespace();
    
    // create the account
    rv = accountManager->GetIdentity(key.get(), getter_AddRefs(identity));
    if (NS_SUCCEEDED(rv)) {
      // ignore error from addIdentityInternal() - if it fails, it fails.
      rv = addIdentityInternal(identity);
      NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create identity");
    }

    // advance to next key, if any
    token = nsCRT::strtok(newStr, ",", &newStr);
  }
    
  return rv;
}

Here is the call graph for this function:

Definition at line 108 of file nsMsgAccount.cpp.

{
  if (!(const char*)m_accountKey) return NS_ERROR_NOT_INITIALIZED;
  // from here, load mail.account.myaccount.server
  // Load the incoming server
  //
  // ex) mail.account.myaccount.server = "myserver"

  nsresult rv = getPrefService();
  if (NS_FAILED(rv)) return rv;

  // get the "server" pref
  nsCAutoString serverKeyPref("mail.account.");
  serverKeyPref += m_accountKey;
  serverKeyPref += ".server";
  nsXPIDLCString serverKey;
  rv = m_prefs->GetCharPref(serverKeyPref.get(), getter_Copies(serverKey));
  if (NS_FAILED(rv)) return rv;
    
#ifdef DEBUG_alecf
  printf("\t%s's server: %s\n", (const char*)m_accountKey, (const char*)serverKey);
#endif

  // get the server from the account manager
  nsCOMPtr<nsIMsgAccountManager> accountManager = 
           do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
    
  nsCOMPtr<nsIMsgIncomingServer> server;
  rv = accountManager->GetIncomingServer(serverKey, getter_AddRefs(server));
  NS_ENSURE_SUCCESS(rv, rv);
  
  // store the server in this structure
  m_incomingServer = server;
  accountManager->NotifyServerLoaded(server);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 77 of file nsMsgAccount.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgAccount::init ( ) [inherited]
wstring nsIMsgAccount::toString ( ) [inherited]

Member Data Documentation

Definition at line 69 of file nsIMsgAccount.idl.

Definition at line 66 of file nsIMsgAccount.idl.

Definition at line 61 of file nsIMsgAccount.idl.

Definition at line 58 of file nsIMsgAccount.idl.

Definition at line 54 of file nsMsgAccount.h.

Definition at line 58 of file nsMsgAccount.h.

Definition at line 59 of file nsMsgAccount.h.

Definition at line 56 of file nsMsgAccount.h.

Definition at line 55 of file nsMsgAccount.h.


The documentation for this class was generated from the following files: