Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
nsSmtpService Class Reference

#include <nsSmtpService.h>

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

List of all members.

Public Member Functions

 nsSmtpService ()
virtual ~nsSmtpService ()
void SendMailMessage (in nsIFileSpec aFilePath, in string aRecipients, in nsIMsgIdentity aSenderIdentity, in string aPassword, in nsIUrlListener aUrlListener, in nsIMsgStatusFeedback aStatusListener, in nsIInterfaceRequestor aNotificationCallbacks, out nsIURI aURL, out nsIRequest aRequest)
void GetSmtpServerByIdentity (in nsIMsgIdentity aSenderIdentity, out nsISmtpServer aServer)
 Return the SMTP server that is associated with an identity.
nsISmtpServer createSmtpServer ()
 create a new SMTP server.
nsISmtpServer findServer (in string username, in string hostname)
 find the server with the given hostname.
nsISmtpServer getServerByKey (in string key)
 look up the server with the given key if the server does not exist, create it and add it to our list
void deleteSmtpServer (in nsISmtpServer server)
 delete the given server from the server list.
nsIURI newURI (in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI)
 Makes a URI object that is suitable for loading by this protocol, where the URI string is given as an UTF-8 string.
nsIChannel newChannel (in nsIURI aURI)
 Constructs a new channel from the given URI for this protocol handler.
boolean allowPort (in long port, in string scheme)
 Allows a protocol to override blacklisted ports.

Public Attributes

readonly attribute nsISupportsArray smtpServers
 A copy of the array of SMTP servers, as stored in the preferences.
attribute nsISmtpServer defaultServer
 The default server, across sessions of the app (eventually there will be a session default which does not persist past shutdown)
attribute nsISmtpServer sessionDefaultServer
 The "session default" server - this is never saved, and only used for the current session.
readonly attribute ACString scheme
 The scheme of this protocol (e.g., "file").
readonly attribute long defaultPort
 The default port is the port that this protocol normally uses.
readonly attribute unsigned long protocolFlags
 Returns the protocol specific flags (see flag definitions below).
const unsigned long URI_STD = 0
 standard full URI with authority component and concept of relative URIs (http, ftp, ...)
const unsigned long URI_NORELATIVE = (1<<0)
 no concept of relative URIs (about, javascript, finger, ...)
const unsigned long URI_NOAUTH = (1<<1)
 no authority component (file, ...)
const unsigned long ALLOWS_PROXY = (1<<2)
 This protocol handler can be proxied via a proxy (socks or http) (e.g., irc, smtp, http, etc.).
const unsigned long ALLOWS_PROXY_HTTP = (1<<3)
 This protocol handler can be proxied using a http proxy (e.g., http, ftp, etc.).

Protected Member Functions

nsresult loadSmtpServers ()

Private Member Functions

nsresult createKeyedServer (const char *key, nsISmtpServer **aResult=nsnull)
nsresult saveKeyList ()

Static Private Member Functions

static PRBool findServerByKey (nsISupports *element, void *aData)
static PRBool findServerByHostname (nsISupports *element, void *aData)

Private Attributes

nsCOMPtr< nsISupportsArraymSmtpServers
nsCOMPtr< nsISmtpServermDefaultSmtpServer
nsCOMPtr< nsISmtpServermSessionDefaultServer
nsCAutoString mServerKeyList
PRBool mSmtpServersLoaded

Detailed Description

Definition at line 55 of file nsSmtpService.h.


Constructor & Destructor Documentation

Definition at line 103 of file nsSmtpService.cpp.

Here is the call graph for this function:

Definition at line 109 of file nsSmtpService.cpp.

{
    // save the SMTP servers to disk

}

Member Function Documentation

boolean nsIProtocolHandler::allowPort ( in long  port,
in string  scheme 
) [inherited]

Allows a protocol to override blacklisted ports.

This method will be called when there is an attempt to connect to a port that is blacklisted. For example, for most protocols, port 25 (Simple Mail Transfer) is banned. When a URI containing this "known-to-do-bad-things" port number is encountered, this function will be called to ask if the protocol handler wants to override the ban.

nsresult nsSmtpService::createKeyedServer ( const char *  key,
nsISmtpServer **  aResult = nsnull 
) [private]

Definition at line 537 of file nsSmtpService.cpp.

{
    if (!key) return NS_ERROR_NULL_POINTER;
    
    nsresult rv;
    nsCOMPtr<nsISmtpServer> server = do_CreateInstance(NS_SMTPSERVER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) return rv;
    
    server->SetKey(key);
    mSmtpServers->AppendElement(server);

    if (mServerKeyList.IsEmpty())
        mServerKeyList = key;
    else {
        mServerKeyList.Append(',');
        mServerKeyList += key;
    }

    if (aResult) {
        *aResult = server;
        NS_IF_ADDREF(*aResult);
    }
    return NS_OK;
}

Here is the call graph for this function:

create a new SMTP server.

Use this instead of createInstance(), so that the SMTP Service can be aware of this server

delete the given server from the server list.

does nothing if the server does not exist

Parameters:
serverthe server to delete. Use findServer() if you only know the hostname
nsISmtpServer nsISmtpService::findServer ( in string  username,
in string  hostname 
) [inherited]

find the server with the given hostname.

Parameters:
hostnamethe hostname of the server
Returns:
null if no server is found
PRBool nsSmtpService::findServerByHostname ( nsISupports *  element,
void aData 
) [static, private]

Definition at line 788 of file nsSmtpService.cpp.

{
    nsresult rv;
    
    nsCOMPtr<nsISmtpServer> server = do_QueryInterface(element, &rv);
    if (NS_FAILED(rv)) return PR_TRUE;

    findServerByHostnameEntry *entry = (findServerByHostnameEntry*)aData;

    nsXPIDLCString hostname;
    rv = server->GetHostname(getter_Copies(hostname));
    if (NS_FAILED(rv)) return PR_TRUE;

   nsXPIDLCString username;
    rv = server->GetUsername(getter_Copies(username));
    if (NS_FAILED(rv)) return PR_TRUE;

    PRBool checkHostname = entry->hostname && PL_strcmp(entry->hostname, "");
    PRBool checkUsername = entry->username && PL_strcmp(entry->username, "");
    
    if ((!checkHostname || (PL_strcasecmp(entry->hostname, hostname)==0)) &&
        (!checkUsername || (PL_strcmp(entry->username, username)==0))) {
        entry->server = server;
        return PR_FALSE;        // stop when found
    }
    return PR_TRUE;
}

Here is the call graph for this function:

PRBool nsSmtpService::findServerByKey ( nsISupports *  element,
void aData 
) [static, private]

Definition at line 661 of file nsSmtpService.cpp.

{
    nsresult rv;
    nsCOMPtr<nsISmtpServer> server = do_QueryInterface(element, &rv);
    if (NS_FAILED(rv)) return PR_TRUE;
    
    findServerByKeyEntry *entry = (findServerByKeyEntry*) aData;

    nsXPIDLCString key;
    rv = server->GetKey(getter_Copies(key));
    if (NS_FAILED(rv)) return PR_TRUE;

    if (nsCRT::strcmp(key, entry->key)==0) {
        entry->server = server;
        return PR_FALSE;
    }
    
    return PR_TRUE;
}

Here is the call graph for this function:

look up the server with the given key if the server does not exist, create it and add it to our list

void nsISmtpService::GetSmtpServerByIdentity ( in nsIMsgIdentity  aSenderIdentity,
out nsISmtpServer  aServer 
) [inherited]

Return the SMTP server that is associated with an identity.

Check to see if we need to add pre-configured smtp servers. Following prefs are important to note in understanding the procedure here.

  1. pref("mailnews.append_preconfig_smtpservers.version", version number); This pref registers the current version in the user prefs file. A default value is stored in mailnews.js file. If a given vendor needs to add more preconfigured smtp servers, the default version number can be increased. Comparing version number from user's prefs file and the default one from mailnews.js, we can add new smtp servers and any other version level changes that need to be done.
  1. pref("mail.smtpservers.appendsmtpservers", <comma separated="" servers="" list>="">); This pref contains the list of pre-configured smp servers that ISP/Vendor wants to to add to the existing servers list.

Definition at line 384 of file nsSmtpService.cpp.

{
    if (mSmtpServersLoaded) return NS_OK;
    
    nsresult rv;
    nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
    if (NS_FAILED(rv)) return rv;
    nsCOMPtr<nsIPrefBranch> prefRootBranch;
    prefService->GetBranch(nsnull, getter_AddRefs(prefRootBranch));
    if (NS_FAILED(rv)) return rv;

    nsXPIDLCString tempServerList;
    nsXPIDLCString serverList;
    rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS, getter_Copies(tempServerList));

    //Get the pref in a tempServerList and then parse it to see if it has dupes.
    //if so remove the dupes and then create the serverList.
    if (!tempServerList.IsEmpty()) {

      // Tokenize the data and add each smtp server if it is not already there 
      // in the user's current smtp server list
      nsCStringArray servers;
      servers.ParseString(tempServerList.get(), SERVER_DELIMITER);
      nsCAutoString tempSmtpServer;
      for (PRInt32 i = 0; i < servers.Count(); i++)
      {
          if (servers.IndexOf(* (servers[i])) == i) {
            tempSmtpServer.Assign(* (servers[i]));
            tempSmtpServer.StripWhitespace();
            if (!serverList.IsEmpty())
              serverList += SERVER_DELIMITER;
            serverList += tempSmtpServer;
          }
      }
    }
    else {
      serverList = tempServerList;
    }

    // We need to check if we have any pre-configured smtp servers so that
    // those servers can be appended to the list. 
    nsXPIDLCString appendServerList;
    rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS_APPEND_SERVERS, getter_Copies(appendServerList));

    // Get the list of smtp servers (either from regular pref i.e, mail.smtpservers or
    // from preconfigured pref mail.smtpservers.appendsmtpservers) and create a keyed 
    // server list.
    if (!serverList.IsEmpty() || !appendServerList.IsEmpty()) {
      nsCOMPtr<nsIPrefBranch> defaultsPrefBranch;
      rv = prefService->GetDefaultBranch(MAIL_ROOT_PREF, getter_AddRefs(defaultsPrefBranch));
      NS_ENSURE_SUCCESS(rv,rv);

      nsCOMPtr<nsIPrefBranch> prefBranch;
      rv = prefService->GetBranch(MAIL_ROOT_PREF, getter_AddRefs(prefBranch));
      NS_ENSURE_SUCCESS(rv,rv);

      PRInt32 appendSmtpServersCurrentVersion=0;
      PRInt32 appendSmtpServersDefaultVersion=0;
      rv = prefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersCurrentVersion);
      NS_ENSURE_SUCCESS(rv,rv);

      rv = defaultsPrefBranch->GetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, &appendSmtpServersDefaultVersion);
      NS_ENSURE_SUCCESS(rv,rv);

      // Update the smtp server list if needed
      if ((appendSmtpServersCurrentVersion <= appendSmtpServersDefaultVersion)) {
        // If there are pre-configured servers, add them to the existing server list
        if (!appendServerList.IsEmpty()) {
          if (!serverList.IsEmpty()) {
            nsCStringArray existingSmtpServersArray;
            existingSmtpServersArray.ParseString(serverList.get(), SERVER_DELIMITER);

            // Tokenize the data and add each smtp server if it is not already there 
            // in the user's current smtp server list
            char *newSmtpServerStr;
            char *preConfigSmtpServersStr = ToNewCString(appendServerList);
  
            char *token = nsCRT::strtok(preConfigSmtpServersStr, SERVER_DELIMITER, &newSmtpServerStr);

            nsCAutoString newSmtpServer;
            while (token) {
              if (token && *token) {
                newSmtpServer.Assign(token);
                newSmtpServer.StripWhitespace();

                if (existingSmtpServersArray.IndexOf(newSmtpServer) == -1) {
                  serverList += ",";
                  serverList += newSmtpServer;
                }
              }
              token = nsCRT::strtok(newSmtpServerStr, SERVER_DELIMITER, &newSmtpServerStr);
            }
            PR_Free(preConfigSmtpServersStr);
          }
          else {
            serverList = appendServerList;
          }
          // Increase the version number so that updates will happen as and when needed
          rv = prefBranch->SetIntPref(APPEND_SERVERS_VERSION_PREF_NAME, appendSmtpServersCurrentVersion + 1);
        }
      }

      char *newStr;
      char *pref = nsCRT::strtok(serverList.BeginWriting(), ", ", &newStr);

      while (pref) {
        // fix for bug #96207
        // code above makes sure that no duplicate entries in mail.smtpservers find
        // their way to the mSmtpServers list.  But it doesn't check, if a server to be
        // added already is in mSmtpServers.  That can happen in mail has been sent before 
        // opening the settings (loading the list).
        // use GetServerByKey to check if the key (pref) is already in
        // in the list. If not it calls createKeyedServer directly.
        nsCOMPtr<nsISmtpServer> server;
        rv = GetServerByKey(pref, getter_AddRefs(server));
        NS_ASSERTION(NS_SUCCEEDED(rv), "GetServerByKey failed");
        pref = nsCRT::strtok(newStr, ", ", &newStr);
      }
    }

    saveKeyList();

    mSmtpServersLoaded = PR_TRUE;
    return NS_OK;
}

Here is the call graph for this function:

Constructs a new channel from the given URI for this protocol handler.

nsIURI nsIProtocolHandler::newURI ( in AUTF8String  aSpec,
in string  aOriginCharset,
in nsIURI  aBaseURI 
) [inherited]

Makes a URI object that is suitable for loading by this protocol, where the URI string is given as an UTF-8 string.

The caller may provide the charset from which the URI string originated, so that the URI string can be translated back to that charset (if necessary) before communicating with, for example, the origin server of the URI string. (Many servers do not support UTF-8 IRIs at the present time, so we must be careful about tracking the native charset of the origin server.)

Parameters:
aSpec- the URI string in UTF-8 encoding. depending on the protocol implementation, unicode character sequences may or may not be xx escaped.
aOriginCharset- the charset of the document from which this URI string originated. this corresponds to the charset that should be used when communicating this URI to an origin server, for example. if null, then UTF-8 encoding is assumed (i.e., no charset transformation from aSpec).
aBaseURI- if null, aSpec must specify an absolute URI. otherwise, aSpec may be resolved relative to aBaseURI, depending on the protocol. If the protocol has no concept of relative URI aBaseURI will simply be ignored.

Definition at line 527 of file nsSmtpService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsISmtpService::SendMailMessage ( in nsIFileSpec  aFilePath,
in string  aRecipients,
in nsIMsgIdentity  aSenderIdentity,
in string  aPassword,
in nsIUrlListener  aUrlListener,
in nsIMsgStatusFeedback  aStatusListener,
in nsIInterfaceRequestor  aNotificationCallbacks,
out nsIURI  aURL,
out nsIRequest  aRequest 
) [inherited]

Member Data Documentation

const unsigned long nsIProtocolHandler::ALLOWS_PROXY = (1<<2) [inherited]

This protocol handler can be proxied via a proxy (socks or http) (e.g., irc, smtp, http, etc.).

If the protocol supports transparent proxying, the handler should implement nsIProxiedProtocolHandler.

If it supports only HTTP proxying, then it need not support nsIProxiedProtocolHandler, but should instead set the ALLOWS_PROXY_HTTP flag (see below).

See also:
nsIProxiedProtocolHandler

Definition at line 148 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::ALLOWS_PROXY_HTTP = (1<<3) [inherited]

This protocol handler can be proxied using a http proxy (e.g., http, ftp, etc.).

nsIIOService::newChannelFromURI will feed URIs from this protocol handler to the HTTP protocol handler instead. This flag is ignored if ALLOWS_PROXY is not set.

Definition at line 156 of file nsIProtocolHandler.idl.

The default port is the port that this protocol normally uses.

If a port does not make sense for the protocol (e.g., "about:") then -1 will be returned.

Definition at line 61 of file nsIProtocolHandler.idl.

The default server, across sessions of the app (eventually there will be a session default which does not persist past shutdown)

Definition at line 98 of file nsISmtpService.idl.

Definition at line 87 of file nsSmtpService.h.

Definition at line 90 of file nsSmtpService.h.

Definition at line 88 of file nsSmtpService.h.

Definition at line 86 of file nsSmtpService.h.

Definition at line 92 of file nsSmtpService.h.

readonly attribute unsigned long nsIProtocolHandler::protocolFlags [inherited]

Returns the protocol specific flags (see flag definitions below).

Definition at line 66 of file nsIProtocolHandler.idl.

readonly attribute ACString nsIProtocolHandler::scheme [inherited]

The scheme of this protocol (e.g., "file").

Definition at line 54 of file nsIProtocolHandler.idl.

The "session default" server - this is never saved, and only used for the current session.

Always falls back to the default server unless explicitly set.

Definition at line 105 of file nsISmtpService.idl.

A copy of the array of SMTP servers, as stored in the preferences.

Definition at line 91 of file nsISmtpService.idl.

const unsigned long nsIProtocolHandler::URI_NOAUTH = (1<<1) [inherited]

no authority component (file, ...)

Definition at line 135 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::URI_NORELATIVE = (1<<0) [inherited]

no concept of relative URIs (about, javascript, finger, ...)

Definition at line 130 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::URI_STD = 0 [inherited]

standard full URI with authority component and concept of relative URIs (http, ftp, ...)

Definition at line 125 of file nsIProtocolHandler.idl.


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